Skip to content

Commit

Permalink
feat(new app-boot): an app-boot.js file boots the app instead of the …
Browse files Browse the repository at this point in the history
…entrypoint
  • Loading branch information
BlueCutOfficial committed Jun 13, 2024
1 parent 966c541 commit dd59d9e
Show file tree
Hide file tree
Showing 23 changed files with 192 additions and 88 deletions.
6 changes: 0 additions & 6 deletions packages/core/src/virtual-entrypoint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -240,12 +240,6 @@ w._embroiderEngineBundles_ = [
{{/each}}
]
{{/if}}
{{#if autoRun ~}}
i("./app").default.create(environment.APP);
{{else if appBoot ~}}
{{ appBoot }}
{{/if}}
`) as (params: {
amdModules: { runtime: string; buildtime: string }[];
fastbootOnlyAmdModules?: { runtime: string; buildtime: string }[];
Expand Down
4 changes: 4 additions & 0 deletions tests/addon-template/tests/dummy/app/app-boot.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import Application from './app';
import environment from './config/environment';

Application.create(environment.APP);
2 changes: 2 additions & 0 deletions tests/addon-template/tests/dummy/app/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import Resolver from 'ember-resolver';
import loadInitializers from 'ember-load-initializers';
import config from 'dummy/config/environment';

import '@embroider/core/entrypoint';

export default class App extends Application {
modulePrefix = config.modulePrefix;
podModulePrefix = config.podModulePrefix;
Expand Down
2 changes: 1 addition & 1 deletion tests/addon-template/tests/dummy/app/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
{{content-for "body"}}

<script src="/@embroider/core/vendor.js"></script>
<script src="/@embroider/core/entrypoint" type="module"></script>
<script src="/app-boot.js" type="module"></script>

{{content-for "body-footer"}}
</body>
Expand Down
2 changes: 1 addition & 1 deletion tests/addon-template/tests/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
<script src="/testem.js" integrity="" data-embroider-ignore></script>
<script src="/@embroider/core/vendor.js"></script>
<script src="/@embroider/core/test-support.js"></script>
<script src="/@embroider/core/entrypoint" type="module"></script>
<script src="/app-boot.js" type="module"></script>
<script src="/@embroider/core/test-entrypoint" type="module"></script>

{{content-for "body-footer"}}
Expand Down
4 changes: 4 additions & 0 deletions tests/app-template/app/app-boot.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import Application from './app';
import environment from './config/environment';

Application.create(environment.APP);
2 changes: 2 additions & 0 deletions tests/app-template/app/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import Resolver from 'ember-resolver';
import loadInitializers from 'ember-load-initializers';
import config from './config/environment';

import '@embroider/core/entrypoint';

export default class App extends Application {
modulePrefix = config.modulePrefix;
podModulePrefix = config.podModulePrefix;
Expand Down
2 changes: 1 addition & 1 deletion tests/app-template/app/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
{{content-for "body"}}

<script src="/@embroider/core/vendor.js"></script>
<script src="/@embroider/core/entrypoint" type="module"></script>
<script src="/app-boot.js" type="module"></script>

{{content-for "body-footer"}}
</body>
Expand Down
2 changes: 1 addition & 1 deletion tests/app-template/tests/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
<script src="/testem.js" integrity="" data-embroider-ignore></script>
<script src="/@embroider/core/vendor.js"></script>
<script src="/@embroider/core/test-support.js"></script>
<script src="/@embroider/core/entrypoint" type="module"></script>
<script src="/app-boot.js" type="module"></script>
<script src="/@embroider/core/test-entrypoint" type="module"></script>

{{content-for "body-footer"}} {{content-for "test-body-footer"}}
Expand Down
12 changes: 12 additions & 0 deletions tests/fixtures/macro-sample-addon-classic/tests/dummy/app/app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import Application from '@ember/application';
import Resolver from 'ember-resolver';
import loadInitializers from 'ember-load-initializers';
import config from 'dummy/config/environment';

export default class App extends Application {
modulePrefix = config.modulePrefix;
podModulePrefix = config.podModulePrefix;
Resolver = Resolver;
}

loadInitializers(App, config.modulePrefix);
12 changes: 12 additions & 0 deletions tests/fixtures/macro-test-classic/app/app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import Application from '@ember/application';
import Resolver from 'ember-resolver';
import loadInitializers from 'ember-load-initializers';
import config from './config/environment';

export default class App extends Application {
modulePrefix = config.modulePrefix;
podModulePrefix = config.podModulePrefix;
Resolver = Resolver;
}

loadInitializers(App, config.modulePrefix);
2 changes: 1 addition & 1 deletion tests/fixtures/macro-test/tests/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
<script src="{{rootURL}}apple.js"></script>
<script src="{{rootURL}}ordered.js"></script>
<script src="/@embroider/core/test-support.js"></script>
<script src="/@embroider/core/entrypoint" type="module"></script>
<script src="/app-boot.js" type="module"></script>
<script src="/@embroider/core/test-entrypoint" type="module"></script>

{{content-for "body-footer"}}
Expand Down
2 changes: 1 addition & 1 deletion tests/scenarios/compat-addon-classic-features-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ appScenarios
{{content-for "custom"}}
<script src="/@embroider/core/vendor.js"></script>
<script src="/@embroider/core/entrypoint" type="module"></script>
<script src="/app-boot.js" type="module"></script>
{{content-for "body-footer"}}
</body>
Expand Down
2 changes: 1 addition & 1 deletion tests/scenarios/compat-app-html-attributes-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ appScenarios

// <script ... src=".../vendor.js"> => <script ... src=".../vendor.js" data-original-filename="vendor.js">
indexHtml = indexHtml.replace('vendor.js">', 'vendor.js" data-original-filename="vendor.js">');
indexHtml = indexHtml.replace('entrypoint" ', 'entrypoint" data-original-filename="entrypoint" ');
indexHtml = indexHtml.replace('/app-boot.js" ', '/app-boot.js" data-original-filename="entrypoint" ');

// <script ... => <script defer ...
indexHtml = indexHtml.replace(/<script /g, '<script defer ');
Expand Down
6 changes: 5 additions & 1 deletion tests/scenarios/compat-exclude-dot-files-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,11 @@ appScenarios
// but not be picked up in the entrypoint
expectAudit
.module('./node_modules/.embroider/rewritten-app/index.html')
.resolves('/@embroider/core/entrypoint')
.resolves('/app-boot.js')
.toModule()
.resolves('./app')
.toModule()
.resolves('@embroider/core/entrypoint')
.toModule()
.withContents(content => {
assert.notOk(/app-template\/\.foobar/.test(content), '.foobar is not in the entrypoint');
Expand Down
6 changes: 5 additions & 1 deletion tests/scenarios/compat-renaming-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,11 @@ appScenarios
test('renamed modules keep their classic runtime name when used as implicit-modules', function () {
expectAudit
.module('./node_modules/.embroider/rewritten-app/index.html')
.resolves('/@embroider/core/entrypoint')
.resolves('/app-boot.js')
.toModule()
.resolves('./app')
.toModule()
.resolves('@embroider/core/entrypoint')
.toModule()
.resolves('./-embroider-implicit-modules.js')
.toModule()
Expand Down
8 changes: 7 additions & 1 deletion tests/scenarios/compat-route-split-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,13 @@ function checkContents(
fn: (contents: string) => void,
entrypointFile?: string | RegExp
) {
let resolved = expectAudit.module('./index.html').resolves('/@embroider/core/entrypoint');
let resolved = expectAudit
.module('./index.html')
.resolves('/app-boot.js')
.toModule()
.resolves(/\/app\.[jt]s.*/)
.toModule()
.resolves(/.*\/-embroider-entrypoint.js/);

if (entrypointFile) {
resolved = resolved.toModule().resolves(entrypointFile);
Expand Down
66 changes: 55 additions & 11 deletions tests/scenarios/compat-stage2-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,11 @@ stage2Scenarios
// check that the app trees with in repo addon are combined correctly
expectAudit
.module('./node_modules/.embroider/rewritten-app/index.html')
.resolves('/@embroider/core/entrypoint')
.resolves('/app-boot.js')
.toModule()
.resolves('./app')
.toModule()
.resolves('@embroider/core/entrypoint')
.toModule()
.resolves('./service/in-repo.js')
.to('./node_modules/dep-b/lib/in-repo-c/_app_/service/in-repo.js');
Expand All @@ -141,7 +145,11 @@ stage2Scenarios
// secondary in-repo-addon was correctly detected and activated
expectAudit
.module('./node_modules/.embroider/rewritten-app/index.html')
.resolves('/@embroider/core/entrypoint')
.resolves('/app-boot.js')
.toModule()
.resolves('./app')
.toModule()
.resolves('@embroider/core/entrypoint')
.toModule()
.resolves('./services/secondary.js')
.to('./lib/secondary-in-repo-addon/_app_/services/secondary.js');
Expand Down Expand Up @@ -207,7 +215,11 @@ stage2Scenarios
test('verifies that the correct lexigraphically sorted addons win', function () {
let expectModule = expectAudit
.module('./node_modules/.embroider/rewritten-app/index.html')
.resolves('/@embroider/core/entrypoint')
.resolves('/app-boot.js')
.toModule()
.resolves('./app')
.toModule()
.resolves('@embroider/core/entrypoint')
.toModule();
expectModule.resolves('./service/in-repo.js').to('./lib/in-repo-b/_app_/service/in-repo.js');
expectModule.resolves('./service/addon.js').to('./node_modules/dep-b/_app_/service/addon.js');
Expand All @@ -217,7 +229,11 @@ stage2Scenarios
test('addons declared as dependencies should win over devDependencies', function () {
expectAudit
.module('./node_modules/.embroider/rewritten-app/index.html')
.resolves('/@embroider/core/entrypoint')
.resolves('/app-boot.js')
.toModule()
.resolves('./app')
.toModule()
.resolves('@embroider/core/entrypoint')
.toModule()
.resolves('./service/dep-wins-over-dev.js')
.to('./node_modules/dep-b/_app_/service/dep-wins-over-dev.js');
Expand All @@ -226,7 +242,11 @@ stage2Scenarios
test('in repo addons declared win over dependencies', function () {
expectAudit
.module('./node_modules/.embroider/rewritten-app/index.html')
.resolves('/@embroider/core/entrypoint')
.resolves('/app-boot.js')
.toModule()
.resolves('./app')
.toModule()
.resolves('@embroider/core/entrypoint')
.toModule()
.resolves('./service/in-repo-over-deps.js')
.to('./lib/in-repo-a/_app_/service/in-repo-over-deps.js');
Expand All @@ -235,7 +255,11 @@ stage2Scenarios
test('ordering with before specified', function () {
expectAudit
.module('./node_modules/.embroider/rewritten-app/index.html')
.resolves('/@embroider/core/entrypoint')
.resolves('/app-boot.js')
.toModule()
.resolves('./app')
.toModule()
.resolves('@embroider/core/entrypoint')
.toModule()
.resolves('./service/test-before.js')
.to('./node_modules/dev-d/_app_/service/test-before.js');
Expand All @@ -244,7 +268,11 @@ stage2Scenarios
test('ordering with after specified', function () {
expectAudit
.module('./node_modules/.embroider/rewritten-app/index.html')
.resolves('/@embroider/core/entrypoint')
.resolves('/app-boot.js')
.toModule()
.resolves('./app')
.toModule()
.resolves('@embroider/core/entrypoint')
.toModule()
.resolves('./service/test-after.js')
.to('./node_modules/dev-b/_app_/service/test-after.js');
Expand Down Expand Up @@ -673,7 +701,11 @@ stage2Scenarios
test('non-static other paths are included in the entrypoint', function (assert) {
expectAudit
.module('./node_modules/.embroider/rewritten-app/index.html')
.resolves('/@embroider/core/entrypoint')
.resolves('/app-boot.js')
.toModule()
.resolves('./app')
.toModule()
.resolves('@embroider/core/entrypoint')
.toModule()
.withContents(contents => {
const result = /import \* as (\w+) from "\.\/non-static-dir\/another-library.js";/.exec(contents);
Expand All @@ -697,7 +729,11 @@ stage2Scenarios
test('static other paths are not included in the entrypoint', function () {
expectAudit
.module('./node_modules/.embroider/rewritten-app/index.html')
.resolves('/@embroider/core/entrypoint')
.resolves('/app-boot.js')
.toModule()
.resolves('./app')
.toModule()
.resolves('@embroider/core/entrypoint')
.toModule()
.withContents(content => {
return !/\.\/static-dir\/my-library\.js"/.test(content);
Expand All @@ -707,7 +743,11 @@ stage2Scenarios
test('top-level static other paths are not included in the entrypoint', function () {
expectAudit
.module('./node_modules/.embroider/rewritten-app/index.html')
.resolves('/@embroider/core/entrypoint')
.resolves('/app-boot.js')
.toModule()
.resolves('./app')
.toModule()
.resolves('@embroider/core/entrypoint')
.toModule()
.withContents(content => {
return !content.includes('./top-level-static.js');
Expand All @@ -717,7 +757,11 @@ stage2Scenarios
test('staticAppPaths do not match partial path segments', function () {
expectAudit
.module('./node_modules/.embroider/rewritten-app/index.html')
.resolves('/@embroider/core/entrypoint')
.resolves('/app-boot.js')
.toModule()
.resolves('./app')
.toModule()
.resolves('@embroider/core/entrypoint')
.toModule()
.withContents(content => {
return content.includes('./static-dir-not-really/something.js');
Expand Down
Loading

0 comments on commit dd59d9e

Please sign in to comment.