From c404a2544980afc76f88f22d6fcc17b0f40608ea Mon Sep 17 00:00:00 2001 From: Marine Dunstetter Date: Tue, 25 Jun 2024 10:57:55 +0200 Subject: [PATCH 1/5] feat (new app-boot): the entry point exports the amdModules, which are then define in app.js --- packages/core/src/virtual-entrypoint.ts | 7 +- tests/addon-template/tests/dummy/app/app.js | 10 ++- tests/app-template/app/app.js | 10 ++- tests/scenarios/compat-stage2-test.ts | 64 +++++++------------ .../compat-template-colocation-test.ts | 36 ++++------- tests/ts-app-template/app/app.ts | 12 +++- 6 files changed, 69 insertions(+), 70 deletions(-) diff --git a/packages/core/src/virtual-entrypoint.ts b/packages/core/src/virtual-entrypoint.ts index 528805497..e363ddda4 100644 --- a/packages/core/src/virtual-entrypoint.ts +++ b/packages/core/src/virtual-entrypoint.ts @@ -181,7 +181,6 @@ import environment from './config/environment'; {{#each amdModules as |amdModule index| ~}} import * as amdModule{{index}} from "{{js-string-escape amdModule.buildtime}}" - d("{{js-string-escape amdModule.runtime}}", function(){ return amdModule{{index}}; }); {{/each}} {{#if fastbootOnlyAmdModules}} @@ -226,6 +225,12 @@ w._embroiderEngineBundles_ = [ {{/each}} ] {{/if}} + +export default { + {{#each amdModules as |amdModule index| ~}} + "{{js-string-escape amdModule.runtime}}": amdModule{{index}}, + {{/each}} +}; `) as (params: { amdModules: { runtime: string; buildtime: string }[]; fastbootOnlyAmdModules?: { runtime: string; buildtime: string }[]; diff --git a/tests/addon-template/tests/dummy/app/app.js b/tests/addon-template/tests/dummy/app/app.js index e77e56b09..ebada6316 100644 --- a/tests/addon-template/tests/dummy/app/app.js +++ b/tests/addon-template/tests/dummy/app/app.js @@ -1,9 +1,17 @@ import Application from '@ember/application'; +import '@embroider/core/entrypoint'; +import coreModules from '@embroider/core/entrypoint'; import Resolver from 'ember-resolver'; import loadInitializers from 'ember-load-initializers'; import config from 'dummy/config/environment'; -import '@embroider/core/entrypoint'; +let d = window.define; + +for (const [name, module] of Object.entries(coreModules)) { + d(name, function () { + return module; + }); +} export default class App extends Application { modulePrefix = config.modulePrefix; diff --git a/tests/app-template/app/app.js b/tests/app-template/app/app.js index c025a955b..f9fb59da4 100644 --- a/tests/app-template/app/app.js +++ b/tests/app-template/app/app.js @@ -1,9 +1,17 @@ import Application from '@ember/application'; +import '@embroider/core/entrypoint'; +import coreModules from '@embroider/core/entrypoint'; import Resolver from 'ember-resolver'; import loadInitializers from 'ember-load-initializers'; import config from './config/environment'; -import '@embroider/core/entrypoint'; +let d = window.define; + +for (const [name, module] of Object.entries(coreModules)) { + d(name, function () { + return module; + }); +} export default class App extends Application { modulePrefix = config.modulePrefix; diff --git a/tests/scenarios/compat-stage2-test.ts b/tests/scenarios/compat-stage2-test.ts index d5bba4cda..8f079fa41 100644 --- a/tests/scenarios/compat-stage2-test.ts +++ b/tests/scenarios/compat-stage2-test.ts @@ -246,33 +246,24 @@ stage2Scenarios expectModule.withContents(contents => { const result = /import \* as (\w+) from ".*in-repo-b\/_app_\/service\/in-repo.js.*/.exec(contents) ?? []; const [, amdModule] = result; - assert.codeContains( - contents, - `d("my-app/service/in-repo", function () { - return ${amdModule}; - });` + assert.ok( + contents.includes(`"my-app/service/in-repo": ${amdModule}`), + 'expected module is in the export list' ); return true; }, 'module imports from the correct place'); expectModule.withContents(contents => { const result = /import \* as (\w+) from ".*dep-b\/_app_\/service\/addon.js.*/.exec(contents) ?? []; const [, amdModule] = result; - assert.codeContains( - contents, - `d("my-app/service/addon", function () { - return ${amdModule}; - });` - ); + assert.ok(contents.includes(`"my-app/service/addon": ${amdModule}`), 'expected module is in the export list'); return true; }, 'module imports from the correct place'); expectModule.withContents(contents => { const result = /import \* as (\w+) from ".*dev-c\/_app_\/service\/dev-addon.js.*/.exec(contents) ?? []; const [, amdModule] = result; - assert.codeContains( - contents, - `d("my-app/service/dev-addon", function () { - return ${amdModule}; - });` + assert.ok( + contents.includes(`"my-app/service/dev-addon": ${amdModule}`), + 'expected module is in the export list' ); return true; }, 'module imports from the correct place'); @@ -283,11 +274,9 @@ stage2Scenarios const result = /import \* as (\w+) from ".*dep-b\/_app_\/service\/dep-wins-over-dev.js.*/.exec(contents) ?? []; const [, amdModule] = result; - assert.codeContains( - contents, - `d("my-app/service/dep-wins-over-dev", function () { - return ${amdModule}; - });` + assert.ok( + contents.includes(`"my-app/service/dep-wins-over-dev": ${amdModule}`), + 'expected module is in the export list' ); return true; }); @@ -298,11 +287,9 @@ stage2Scenarios const result = /import \* as (\w+) from ".*in-repo-a\/_app_\/service\/in-repo-over-deps.js.*/.exec(contents) ?? []; const [, amdModule] = result; - assert.codeContains( - contents, - `d("my-app/service/in-repo-over-deps", function () { - return ${amdModule}; - });` + assert.ok( + contents.includes(`"my-app/service/in-repo-over-deps": ${amdModule}`), + 'expected module is in the export list' ); return true; }); @@ -312,11 +299,9 @@ stage2Scenarios resolveEntryPoint(expectAudit).withContents(contents => { const result = /import \* as (\w+) from ".*dev-d\/_app_\/service\/test-before.js.*/.exec(contents) ?? []; const [, amdModule] = result; - assert.codeContains( - contents, - `d("my-app/service/test-before", function () { - return ${amdModule}; - });` + assert.ok( + contents.includes(`"my-app/service/test-before": ${amdModule}`), + 'expected module is in the export list' ); return true; }); @@ -326,11 +311,9 @@ stage2Scenarios resolveEntryPoint(expectAudit).withContents(contents => { const result = /import \* as (\w+) from ".*dev-b\/_app_\/service\/test-after.js.*/.exec(contents) ?? []; const [, amdModule] = result; - assert.codeContains( - contents, - `d("my-app/service/test-after", function () { - return ${amdModule}; - });` + assert.ok( + contents.includes(`"my-app/service/test-after": ${amdModule}`), + 'expected module is in the export list' ); return true; }); @@ -845,12 +828,9 @@ stage2Scenarios } const [, amdModule] = result; - - assert.codeContains( - contents, - `d("my-app/non-static-dir/another-library", function () { - return ${amdModule}; - });` + assert.ok( + contents.includes(`"my-app/non-static-dir/another-library": ${amdModule}`), + 'expected module is in the export list' ); return true; }); diff --git a/tests/scenarios/compat-template-colocation-test.ts b/tests/scenarios/compat-template-colocation-test.ts index fe10732aa..773ea561c 100644 --- a/tests/scenarios/compat-template-colocation-test.ts +++ b/tests/scenarios/compat-template-colocation-test.ts @@ -183,12 +183,9 @@ scenarios } const [, amdModule] = result; - - assert.codeContains( - contents, - `d("my-app/components/has-colocated-template", function () { - return ${amdModule}; - });` + assert.ok( + contents.includes(`"my-app/components/has-colocated-template": ${amdModule}`), + 'expected module is in the export list' ); }); }); @@ -395,12 +392,9 @@ appScenarios } const [, podComponentAmd] = result; - - assert.codeContains( - content, - `d("my-app/components/pod-component/component", function () { - return ${podComponentAmd}; - });` + assert.ok( + content.includes(`"my-app/components/pod-component/component": ${podComponentAmd}`), + 'expected module is in the export list' ); result = /import \* as (\w+) from "\/components\/pod-component\/template\.hbs.*"/.exec(content); @@ -410,12 +404,9 @@ appScenarios } const [, podComponentTemplateAmd] = result; - - assert.codeContains( - content, - `d("my-app/components/pod-component/template", function () { - return ${podComponentTemplateAmd}; - });` + assert.ok( + content.includes(`"my-app/components/pod-component/template": ${podComponentTemplateAmd}`), + 'expected module is in the export list' ); result = /import \* as (\w+) from "\/components\/template-only\/template\.hbs.*"/.exec(content); @@ -425,12 +416,9 @@ appScenarios } const [, templateOnlyAmd] = result; - - assert.codeContains( - content, - `d("my-app/components/template-only/template", function () { - return ${templateOnlyAmd}; - });` + assert.ok( + content.includes(`"my-app/components/template-only/template": ${templateOnlyAmd}`), + 'expected module is in the export list' ); return true; diff --git a/tests/ts-app-template/app/app.ts b/tests/ts-app-template/app/app.ts index aeb3eb262..667543e2c 100644 --- a/tests/ts-app-template/app/app.ts +++ b/tests/ts-app-template/app/app.ts @@ -1,9 +1,19 @@ import Application from '@ember/application'; +import '@embroider/core/entrypoint'; +// @ts-ignore +import coreModules from '@embroider/core/entrypoint'; import Resolver from 'ember-resolver'; import loadInitializers from 'ember-load-initializers'; import config from 'ts-app-template/config/environment'; -import '@embroider/core/entrypoint'; +// @ts-ignore +let d = window.define; + +for (const [name, module] of Object.entries(coreModules)) { + d(name, function () { + return module; + }); +} export default class App extends Application { modulePrefix = config.modulePrefix; From 27b8fe740c11e657af43b73a1bca84dfeb5c1d02 Mon Sep 17 00:00:00 2001 From: Marine Dunstetter Date: Tue, 25 Jun 2024 16:06:24 +0200 Subject: [PATCH 2/5] feat (new app-boot): the entry point exports the implicitModules, which are then define in app.js --- packages/core/src/virtual-entrypoint.ts | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/packages/core/src/virtual-entrypoint.ts b/packages/core/src/virtual-entrypoint.ts index e363ddda4..3d74dcc6e 100644 --- a/packages/core/src/virtual-entrypoint.ts +++ b/packages/core/src/virtual-entrypoint.ts @@ -168,13 +168,8 @@ import environment from './config/environment'; {{#if defineModulesFrom ~}} import implicitModules from "{{js-string-escape defineModulesFrom}}"; - - for(const [name, module] of Object.entries(implicitModules)) { - d(name, function() { return module }); - } {{/if}} - {{#each eagerModules as |eagerModule| ~}} import "{{js-string-escape eagerModule}}"; {{/each}} @@ -226,11 +221,15 @@ w._embroiderEngineBundles_ = [ ] {{/if}} -export default { - {{#each amdModules as |amdModule index| ~}} - "{{js-string-escape amdModule.runtime}}": amdModule{{index}}, - {{/each}} -}; +export default Object.assign( + {}, + { + {{#each amdModules as |amdModule index| ~}} + "{{js-string-escape amdModule.runtime}}": amdModule{{index}}, + {{/each}} + }, + implicitModules +); `) as (params: { amdModules: { runtime: string; buildtime: string }[]; fastbootOnlyAmdModules?: { runtime: string; buildtime: string }[]; From 1c787efdbd2864cb0a99e9fc96026d9179db62de Mon Sep 17 00:00:00 2001 From: Marine Dunstetter Date: Wed, 26 Jun 2024 11:03:13 +0200 Subject: [PATCH 3/5] feat (new app-boot): the entry point exports the fastbootOnlyModules, which are then define in app.js, d is no longer needed in the virtual entry template --- packages/core/src/virtual-entrypoint.ts | 8 +++++--- tests/addon-template/tests/dummy/app/app.js | 5 ++--- tests/app-template/app/app.js | 5 ++--- tests/ts-app-template/app/app.ts | 5 ++--- 4 files changed, 11 insertions(+), 12 deletions(-) diff --git a/packages/core/src/virtual-entrypoint.ts b/packages/core/src/virtual-entrypoint.ts index 3d74dcc6e..989e06e29 100644 --- a/packages/core/src/virtual-entrypoint.ts +++ b/packages/core/src/virtual-entrypoint.ts @@ -154,7 +154,6 @@ export function renderEntrypoint( const entryTemplate = compile(` import { importSync as i, macroCondition, getGlobalConfig } from '@embroider/macros'; let w = window; -let d = w.define; import environment from './config/environment'; @@ -178,6 +177,8 @@ import environment from './config/environment'; import * as amdModule{{index}} from "{{js-string-escape amdModule.buildtime}}" {{/each}} +let exportFastbootModules = {}; + {{#if fastbootOnlyAmdModules}} if (macroCondition(getGlobalConfig().fastboot?.isRunning)) { let fastbootModules = {}; @@ -189,7 +190,7 @@ import environment from './config/environment'; const resolvedValues = await Promise.all(Object.values(fastbootModules)); Object.keys(fastbootModules).forEach((k, i) => { - d(k, function(){ return resolvedValues[i];}); + exportFasbootModules[k] = resolvedValues[i]; }) } {{/if}} @@ -223,12 +224,13 @@ w._embroiderEngineBundles_ = [ export default Object.assign( {}, + implicitModules, { {{#each amdModules as |amdModule index| ~}} "{{js-string-escape amdModule.runtime}}": amdModule{{index}}, {{/each}} }, - implicitModules + exportFastbootModules ); `) as (params: { amdModules: { runtime: string; buildtime: string }[]; diff --git a/tests/addon-template/tests/dummy/app/app.js b/tests/addon-template/tests/dummy/app/app.js index ebada6316..0856d883b 100644 --- a/tests/addon-template/tests/dummy/app/app.js +++ b/tests/addon-template/tests/dummy/app/app.js @@ -1,13 +1,12 @@ import Application from '@ember/application'; -import '@embroider/core/entrypoint'; -import coreModules from '@embroider/core/entrypoint'; +import compatModules from '@embroider/core/entrypoint'; import Resolver from 'ember-resolver'; import loadInitializers from 'ember-load-initializers'; import config from 'dummy/config/environment'; let d = window.define; -for (const [name, module] of Object.entries(coreModules)) { +for (const [name, module] of Object.entries(compatModules)) { d(name, function () { return module; }); diff --git a/tests/app-template/app/app.js b/tests/app-template/app/app.js index f9fb59da4..9f0c04383 100644 --- a/tests/app-template/app/app.js +++ b/tests/app-template/app/app.js @@ -1,13 +1,12 @@ import Application from '@ember/application'; -import '@embroider/core/entrypoint'; -import coreModules from '@embroider/core/entrypoint'; +import compatModules from '@embroider/core/entrypoint'; import Resolver from 'ember-resolver'; import loadInitializers from 'ember-load-initializers'; import config from './config/environment'; let d = window.define; -for (const [name, module] of Object.entries(coreModules)) { +for (const [name, module] of Object.entries(compatModules)) { d(name, function () { return module; }); diff --git a/tests/ts-app-template/app/app.ts b/tests/ts-app-template/app/app.ts index 667543e2c..df50bd33b 100644 --- a/tests/ts-app-template/app/app.ts +++ b/tests/ts-app-template/app/app.ts @@ -1,7 +1,6 @@ import Application from '@ember/application'; -import '@embroider/core/entrypoint'; // @ts-ignore -import coreModules from '@embroider/core/entrypoint'; +import compatModules from '@embroider/core/entrypoint'; import Resolver from 'ember-resolver'; import loadInitializers from 'ember-load-initializers'; import config from 'ts-app-template/config/environment'; @@ -9,7 +8,7 @@ import config from 'ts-app-template/config/environment'; // @ts-ignore let d = window.define; -for (const [name, module] of Object.entries(coreModules)) { +for (const [name, module] of Object.entries(compatModules)) { d(name, function () { return module; }); From ced381af0cde20fb4c99c6c284f4e12b9fb890b7 Mon Sep 17 00:00:00 2001 From: Marine Dunstetter Date: Wed, 26 Jun 2024 11:28:13 +0200 Subject: [PATCH 4/5] feat (new app-boot): fix the typescript errors --- tests/ts-app-template/app/app.ts | 2 -- tests/ts-app-template/types/global.d.ts | 6 ++++++ tests/ts-app-template/types/ts-app-template/entry.d.ts | 1 + 3 files changed, 7 insertions(+), 2 deletions(-) create mode 100644 tests/ts-app-template/types/ts-app-template/entry.d.ts diff --git a/tests/ts-app-template/app/app.ts b/tests/ts-app-template/app/app.ts index df50bd33b..dc71d8aac 100644 --- a/tests/ts-app-template/app/app.ts +++ b/tests/ts-app-template/app/app.ts @@ -1,11 +1,9 @@ import Application from '@ember/application'; -// @ts-ignore import compatModules from '@embroider/core/entrypoint'; import Resolver from 'ember-resolver'; import loadInitializers from 'ember-load-initializers'; import config from 'ts-app-template/config/environment'; -// @ts-ignore let d = window.define; for (const [name, module] of Object.entries(compatModules)) { diff --git a/tests/ts-app-template/types/global.d.ts b/tests/ts-app-template/types/global.d.ts index 2c531e29a..84a68b049 100644 --- a/tests/ts-app-template/types/global.d.ts +++ b/tests/ts-app-template/types/global.d.ts @@ -1 +1,7 @@ import '@glint/environment-ember-loose'; + +declare global { + interface Window { + define: any; + } +} diff --git a/tests/ts-app-template/types/ts-app-template/entry.d.ts b/tests/ts-app-template/types/ts-app-template/entry.d.ts new file mode 100644 index 000000000..0aa0610dd --- /dev/null +++ b/tests/ts-app-template/types/ts-app-template/entry.d.ts @@ -0,0 +1 @@ +declare module '@embroider/core/entrypoint'; From 6c4314c9022e79c5f059cd46d34f226d5c188982 Mon Sep 17 00:00:00 2001 From: Marine Dunstetter Date: Wed, 26 Jun 2024 16:59:12 +0200 Subject: [PATCH 5/5] feat (new app-boot): cleanup virtual entrypoint template --- packages/core/src/virtual-entrypoint.ts | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/packages/core/src/virtual-entrypoint.ts b/packages/core/src/virtual-entrypoint.ts index 989e06e29..257e6b7a1 100644 --- a/packages/core/src/virtual-entrypoint.ts +++ b/packages/core/src/virtual-entrypoint.ts @@ -152,8 +152,7 @@ export function renderEntrypoint( } const entryTemplate = compile(` -import { importSync as i, macroCondition, getGlobalConfig } from '@embroider/macros'; -let w = window; +import { macroCondition, getGlobalConfig } from '@embroider/macros'; import environment from './config/environment'; @@ -197,7 +196,7 @@ let exportFastbootModules = {}; {{#if lazyRoutes}} -w._embroiderRouteBundles_ = [ +window._embroiderRouteBundles_ = [ {{#each lazyRoutes as |route|}} { names: {{json-stringify route.names}}, @@ -210,7 +209,7 @@ w._embroiderRouteBundles_ = [ {{/if}} {{#if lazyEngines}} -w._embroiderEngineBundles_ = [ +window._embroiderEngineBundles_ = [ {{#each lazyEngines as |engine|}} { names: {{json-stringify engine.names}},