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

[BUGFIX release] Remove unintentional duplication from ember-testing bundle #20726

Merged
merged 1 commit into from
Aug 5, 2024
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
67 changes: 45 additions & 22 deletions rollup.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,18 @@ const testDependencies = ['qunit', 'vite'];

export default [
esmConfig(),
legacyBundleConfig('./broccoli/amd-compat-entrypoints/ember.debug.js', 'ember.debug.js', true),
legacyBundleConfig('./broccoli/amd-compat-entrypoints/ember.debug.js', 'ember.prod.js', false),
legacyBundleConfig(
'./broccoli/amd-compat-entrypoints/ember-testing.js',
'ember-testing.js',
true
),
legacyBundleConfig('./broccoli/amd-compat-entrypoints/ember.debug.js', 'ember.debug.js', {
isDeveloping: true,
}),
legacyBundleConfig('./broccoli/amd-compat-entrypoints/ember.debug.js', 'ember.prod.js', {
isDeveloping: false,
}),
legacyBundleConfig('./broccoli/amd-compat-entrypoints/ember-testing.js', 'ember-testing.js', {
isDeveloping: true,
isExternal(source) {
return !source.startsWith('ember-testing');
},
}),
templateCompilerConfig(),
];

Expand Down Expand Up @@ -57,7 +62,7 @@ function esmConfig() {
}),
resolveTS(),
version(),
resolvePackages(exposedDependencies(), hiddenDependencies()),
resolvePackages({ ...exposedDependencies(), ...hiddenDependencies() }),
pruneEmptyBundles(),
],
};
Expand All @@ -67,7 +72,7 @@ function renameEntrypoints(entrypoints, fn) {
return Object.fromEntries(Object.entries(entrypoints).map(([k, v]) => [fn(k), v]));
}

function legacyBundleConfig(input, output, isDeveloping) {
function legacyBundleConfig(input, output, { isDeveloping, isExternal }) {
let babelConfig = { ...sharedBabelConfig };

babelConfig.plugins = [...babelConfig.plugins, buildDebugMacroPlugin(isDeveloping)];
Expand All @@ -87,6 +92,12 @@ function legacyBundleConfig(input, output, isDeveloping) {
// modules and hands them to our classic AMD loader. All of those modules
// need the __esModule marker too.
freeze: false,

globals: (id) => {
return `require('${id}')`;
},

interop: 'esModule',
},
plugins: [
amdDefineSupport(),
Expand All @@ -99,7 +110,7 @@ function legacyBundleConfig(input, output, isDeveloping) {
}),
resolveTS(),
version(),
resolvePackages(exposedDependencies(), hiddenDependencies()),
resolvePackages({ ...exposedDependencies(), ...hiddenDependencies() }, isExternal),
licenseAndLoader(),
],
};
Expand Down Expand Up @@ -272,7 +283,7 @@ function resolveTS() {
};
}

export function resolvePackages(...depsList) {
export function resolvePackages(deps, isExternal) {
return {
enforce: 'pre',
name: 'resolve-packages',
Expand All @@ -289,10 +300,12 @@ export function resolvePackages(...depsList) {
return { external: true, id: pkgName };
}

for (let deps of depsList) {
if (deps[source]) {
return deps[source];
}
if (isExternal?.(source)) {
return { external: true, id: source };
}

if (deps[source]) {
return deps[source];
}

let candidateStem = resolve(projectRoot, 'packages', source);
Expand Down Expand Up @@ -419,19 +432,29 @@ function templateCompilerConfig() {
// need to be discovered from ember.debug.js instead when running in the
// browser, and stubbed to ember-template-compiler.js in node.
const externals = {
'@ember/template-compilation': `{ __registerTemplateCompiler(){} }`,
'@ember/template-compilation': `{
__esModule: true,
__registerTemplateCompiler(){},
}`,
ember: `{
get ENV() { return require('@ember/-internals/environment').ENV },
get FEATURES() { return require('@ember/canary-features').FEATURES },
get VERSION() { return require('ember/version').default },
__esModule: true,
default: {
get ENV() { return require('@ember/-internals/environment').ENV },
get FEATURES() { return require('@ember/canary-features').FEATURES },
get VERSION() { return require('ember/version').default },
},
}`,
'@ember/-internals/glimmer': `{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

are these stubs that don't matter / aren't used in the actual output?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They're used in the ember-template-compiler.js bundle. Which has always done wonky things so that it will share the main ember implementations of things if you load it into the browser, but bring its own copies of some of the things and stub the others if you load it by itself in node.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The node tests accurately reflect the things that older versions of ember-cli-htmlbars actually expect the ember-template-compiler.js bundle to do.

__esModule: true,
}`,
'@ember/application': `{
__esModule: true,
}`,
'@ember/-internals/glimmer': `{ template: undefined }`,
'@ember/application': `undefined`,
};
let config = legacyBundleConfig(
'./broccoli/amd-compat-entrypoints/ember-template-compiler.js',
'ember-template-compiler.js',
true
{ isDeveloping: true }
);
config.plugins.unshift({
enforce: 'pre',
Expand Down
2 changes: 1 addition & 1 deletion vite.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export default defineConfig(({ mode }) => {
extensions: ['.js', '.ts'],
configFile: resolve(dirname(fileURLToPath(import.meta.url)), './babel.test.config.mjs'),
}),
resolvePackages(exposedDependencies(), hiddenDependencies()),
resolvePackages({ ...exposedDependencies(), ...hiddenDependencies() }),
viteResolverBug(),
version(),
],
Expand Down