Skip to content

Commit

Permalink
Merge pull request #1170 from embroider-build/updates-for-local-impor…
Browse files Browse the repository at this point in the history
…ts-batman-syntax

Ensure self-references within a dummy apps work for `@` resolution.
  • Loading branch information
ef4 authored Apr 7, 2022
2 parents 810b4bb + 1a09641 commit 5976a37
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 3 deletions.
13 changes: 10 additions & 3 deletions packages/compat/src/resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -467,7 +467,9 @@ export default class CompatResolver implements Resolver {
if (renamed) {
packageName = renamed;
}
return this._tryHelper(parts[1], from, cache.resolve(packageName, cache.ownerOfFile(from)!));
let owner = cache.ownerOfFile(from)!;
let targetPackage = owner.name === packageName ? owner : cache.resolve(packageName, owner);
return this._tryHelper(parts[1], from, targetPackage);
} else {
return this._tryHelper(path, from, this.appPackage);
}
Expand Down Expand Up @@ -501,7 +503,9 @@ export default class CompatResolver implements Resolver {
if (renamed) {
packageName = renamed;
}
return this._tryModifier(parts[1], from, cache.resolve(packageName, cache.ownerOfFile(from)!));
let owner = cache.ownerOfFile(from)!;
let targetPackage = owner.name === packageName ? owner : cache.resolve(packageName, owner);
return this._tryModifier(parts[1], from, targetPackage);
} else {
return this._tryModifier(path, from, this.appPackage);
}
Expand Down Expand Up @@ -540,7 +544,10 @@ export default class CompatResolver implements Resolver {
if (renamed) {
packageName = renamed;
}
return this._tryComponent(parts[1], from, withRuleLookup, cache.resolve(packageName, cache.ownerOfFile(from)!));
let owner = cache.ownerOfFile(from)!;
let targetPackage = owner.name === packageName ? owner : cache.resolve(packageName, owner);

return this._tryComponent(parts[1], from, withRuleLookup, targetPackage);
} else {
return this._tryComponent(path, from, withRuleLookup, this.appPackage);
}
Expand Down
32 changes: 32 additions & 0 deletions packages/compat/tests/resolver.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -648,6 +648,38 @@ describe('compat-resolver', function () {
},
]);
});
test('angle bracket invocation of component with @ syntax', function () {
let findDependencies = configure(
{
staticComponents: true,
},
{ plugins: { ast: [emberHolyFuturisticNamespacingBatmanTransform] } }
);
givenFile('node_modules/my-addon/package.json', `{ "name": "my-addon"}`);
givenFile('node_modules/my-addon/components/thing.js');
expect(findDependencies('templates/application.hbs', `<MyAddon$Thing />`)).toEqual([
{
path: '../node_modules/my-addon/components/thing.js',
runtimeName: 'my-addon/components/thing',
},
]);
});
test('angle bracket invocation of component with @ syntax - self reference inside node_modules', function () {
let findDependencies = configure(
{
staticComponents: true,
},
{ plugins: { ast: [emberHolyFuturisticNamespacingBatmanTransform] } }
);
givenFile('node_modules/my-addon/package.json', `{ "name": "my-addon"}`);
givenFile('node_modules/my-addon/components/thing.js');
expect(findDependencies('node_modules/my-addon/components/foo.hbs', `<MyAddon$Thing />`)).toEqual([
{
path: './thing.js',
runtimeName: 'my-addon/components/thing',
},
]);
});
test('helper with @ syntax', function () {
let findDependencies = configure(
{
Expand Down

0 comments on commit 5976a37

Please sign in to comment.