Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

reinstate logic around parsing of invokes packageRules #1352

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions packages/compat/src/resolver-transform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@ export default function makeResolverTransform({ resolver, patchHelpersBug }: Opt
let scopeStack = new ScopeStack();
let emittedAMDDeps: Set<string> = new Set();

const invokeDependencies = resolver.enter(filename);
for (let packageRuleInvokeDependency of invokeDependencies) {
emitAMD(packageRuleInvokeDependency.hbsModule);
emitAMD(packageRuleInvokeDependency.jsModule);
}

// The first time we insert a component as a lexical binding
// - if there's no JS-scope collision with the name, we're going to bind the existing name
// - in this case, any subsequent invocations of the same component just got automatically fixed too
Expand Down
11 changes: 10 additions & 1 deletion packages/compat/src/resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,16 @@ export default class CompatResolver {
this.auditHandler = (globalThis as any).embroider_audit;
}
}

enter(moduleName: string) {
let rules = this.findComponentRules(moduleName);
let deps: ComponentResolution[];
if (rules?.dependsOnComponents) {
deps = rules.dependsOnComponents.map(snippet => this.resolveComponentSnippet(snippet, rules!, moduleName));
} else {
deps = [];
}
return deps;
}
private findComponentRules(absPath: string): PreprocessedComponentRule | undefined {
let rules = this.rules.components.get(absPath);
if (rules) {
Expand Down
24 changes: 15 additions & 9 deletions packages/compat/tests/resolver.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2318,7 +2318,7 @@ describe('compat-resolver', function () {
);
});

test.skip('respects invokes rule on a component', function () {
test('respects invokes rule on a component', function () {
let packageRules: PackageRules[] = [
{
package: 'the-test-package',
Expand All @@ -2335,16 +2335,18 @@ describe('compat-resolver', function () {
givenFile('components/alpha.js');

expect(transform('templates/components/form-builder.hbs', `{{component this.which}}`)).toEqualCode(`
import "../../components/alpha.js";
import "./components/alpha.hbs";
import alpha0 from "../../components/alpha.js";
import alpha from "./alpha.hbs";
import { precompileTemplate } from "@ember/template-compilation";
window.define("the-app/templates/components/alpha", () => alpha);
window.define("the-app/components/alpha", () => alpha0);
export default precompileTemplate("{{component this.which}}", {
moduleName: "my-app/templates/components/form-builder.hbs"
});
`);
});

test.skip('respects invokes rule on a non-component app template', function () {
test('respects invokes rule on a non-component app template', function () {
let packageRules: PackageRules[] = [
{
package: 'the-test-package',
Expand All @@ -2361,16 +2363,18 @@ describe('compat-resolver', function () {
givenFile('components/alpha.js');

expect(transform('templates/index.hbs', `{{component this.which}}`)).toEqualCode(`
import "../../components/alpha.js";
import "./components/alpha.hbs";
import alpha0 from "../components/alpha.js";
import alpha from "./components/alpha.hbs";
import { precompileTemplate } from "@ember/template-compilation";
window.define("the-app/templates/components/alpha", () => alpha);
window.define("the-app/components/alpha", () => alpha0);
export default precompileTemplate("{{component this.which}}", {
moduleName: "my-app/templates/index.hbs"
});
`);
});

test.skip('respects invokes rule on a non-component addon template', function () {
test('respects invokes rule on a non-component addon template', function () {
let packageRules: PackageRules[] = [
{
package: 'my-addon',
Expand All @@ -2388,9 +2392,11 @@ describe('compat-resolver', function () {
givenFile('components/alpha.js');

expect(transform('node_modules/my-addon/templates/index.hbs', `{{component this.which}}`)).toEqualCode(`
import "../../components/alpha.js";
import "./components/alpha.hbs";
import alpha0 from "../../../components/alpha.js";
import alpha from "../../../templates/components/alpha.hbs";
import { precompileTemplate } from "@ember/template-compilation";
window.define("the-app/templates/components/alpha", () => alpha);
window.define("the-app/components/alpha", () => alpha0);
export default precompileTemplate("{{component this.which}}", {
moduleName: "my-app/node_modules/my-addon/templates/index.hbs"
});
Expand Down