Skip to content

Commit

Permalink
Fix implicit-modules in v2 addons
Browse files Browse the repository at this point in the history
Fixes #1514

The bug was introduced in #1536 when we refactored how implicit-modules get included.

A v2 addon with a v1 addon dependency would miss including implicit-modules for that v1 addon.

This code needed to explicitly ask for the moved copy of a dependency, in case the dependency had moved.
  • Loading branch information
ef4 committed Jul 25, 2023
1 parent 5da719c commit be76613
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 3 deletions.
2 changes: 2 additions & 0 deletions packages/core/src/virtual-content.ts
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,8 @@ function renderImplicitModules(
let deps = pkg.dependencies.sort(orderAddons);

for (let dep of deps) {
dep = resolver.packageCache.maybeMoved(dep);

// anything that isn't a v2 ember package by this point is not an active
// addon.
if (!dep.isV2Addon()) {
Expand Down
40 changes: 37 additions & 3 deletions tests/scenarios/core-resolver-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { PreparedApp, Project, Scenarios } from 'scenario-tester';
import { CompatResolverOptions } from '@embroider/compat/src/resolver-transform';
import { ExpectAuditResults } from '@embroider/test-support/audit-assertions';
import { installAuditAssertions } from '@embroider/test-support/audit-assertions';
import { baseAddon } from './scenarios';

const { module: Qmodule, test } = QUnit;

Expand Down Expand Up @@ -38,6 +39,10 @@ Scenarios.fromProject(() => new Project())
},
});

let v1Addon = baseAddon();
v1Addon.name = 'a-v1-addon';
app.addDependency(v1Addon);

// this is just an empty fixture package, it's the presence of a dependency
// named ember-auto-import that tells us that the app was allowed to import
// deps from npm.
Expand All @@ -58,12 +63,12 @@ Scenarios.fromProject(() => new Project())
let configure: (opts?: ConfigureOpts) => Promise<void>;
let app: PreparedApp;

function addonPackageJSON(addonMeta?: Partial<AddonMeta>) {
function addonPackageJSON(name = 'my-addon', addonMeta?: Partial<AddonMeta>) {
return JSON.stringify(
(() => {
let meta: AddonMeta = { type: 'addon', version: 2, 'auto-upgraded': true, ...(addonMeta ?? {}) };
return {
name: 'my-addon',
name,
keywords: ['ember-addon'],
'ember-addon': meta,
};
Expand Down Expand Up @@ -100,6 +105,10 @@ Scenarios.fromProject(() => new Project())
name: 'my-addon',
root: resolve(app.dir, 'node_modules', 'my-addon'),
},
{
name: 'a-v1-addon',
root: resolve(app.dir, 'node_modules', 'a-v1-addon'),
},
],
},
],
Expand Down Expand Up @@ -129,7 +138,7 @@ Scenarios.fromProject(() => new Project())
module.exports = function(filename) { return true }
`,
'node_modules/.embroider/resolver.json': JSON.stringify(resolverOptions),
'node_modules/my-addon/package.json': addonPackageJSON(opts?.addonMeta),
'node_modules/my-addon/package.json': addonPackageJSON('my-addon', opts?.addonMeta),
});

expectAudit = await assert.audit({ app: app.dir, 'reuse-build': true });
Expand Down Expand Up @@ -791,6 +800,31 @@ Scenarios.fromProject(() => new Project())
.resolves('inner-dep')
.to('./node_modules/my-addon/node_modules/inner-dep/index.js');
});

test('implicit modules in moved dependencies', async function () {
let index: RewrittenPackageIndex = {
packages: {
[resolve(app.dir, 'node_modules/a-v1-addon')]: 'a-v1-addon.1234',
},
extraResolutions: {},
};
givenFiles({
'node_modules/.embroider/rewritten-packages/index.json': JSON.stringify(index),
'node_modules/.embroider/rewritten-packages/a-v1-addon.1234/_app_/components/i-am-implicit.js': ``,
'node_modules/.embroider/rewritten-packages/a-v1-addon.1234/package.json': addonPackageJSON('a-v1-addon', {
'implicit-modules': ['./_app_/components/i-am-implicit.js'],
}),
'app.js': `import "./-embroider-implicit-modules.js"`,
});

await configure({});

expectAudit
.module('./app.js')
.resolves('./-embroider-implicit-modules.js')
.toModule()
.resolves('a-v1-addon/-embroider-implicit-modules.js');
});
});
});
});

0 comments on commit be76613

Please sign in to comment.