Skip to content

Commit

Permalink
Remove unintentional duplication from ember-testing bundle
Browse files Browse the repository at this point in the history
(cherry picked from commit cb17142)
  • Loading branch information
ef4 authored and kategengler committed Aug 6, 2024
1 parent bd90fd0 commit 2fcbcc5
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 23 deletions.
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': `{
__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

0 comments on commit 2fcbcc5

Please sign in to comment.