Skip to content

Commit

Permalink
feat(new app-boot): move custom app boot responsibility from .embroid…
Browse files Browse the repository at this point in the history
…er/ember-app-boot.js to the new app-boot.js file
  • Loading branch information
BlueCutOfficial committed Jun 13, 2024
1 parent dd59d9e commit 60779b4
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 19 deletions.
18 changes: 1 addition & 17 deletions packages/core/src/virtual-entrypoint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,10 @@ import type { Resolver } from './module-resolver';
import type { CompatResolverOptions } from '../../compat/src/resolver-transform';
import { flatten, partition } from 'lodash';
import { join } from 'path';
import { extensionsPattern, locateEmbroiderWorkingDir } from '@embroider/shared-internals';
import { extensionsPattern } from '@embroider/shared-internals';
import walkSync from 'walk-sync';
import type { V2AddonPackage } from '@embroider/shared-internals/src/package';
import { encodePublicRouteEntrypoint } from './virtual-route-entrypoint';
import { readFileSync } from 'fs-extra';
import escapeRegExp from 'escape-string-regexp';

const entrypointPattern = /(?<filename>.*)[\\/]-embroider-entrypoint.js/;
Expand Down Expand Up @@ -146,19 +145,6 @@ export function renderEntrypoint(
defineModulesFrom: './-embroider-implicit-modules.js',
};

// for the top-level entry template we need to pass extra params to the template
// this is new, it used to be passed into the appJS function instead
if (isApp) {
const appBoot = readFileSync(join(locateEmbroiderWorkingDir(resolver.options.appRoot), 'ember-app-boot.js'), {
encoding: 'utf-8',
});

Object.assign(params, {
autoRun: resolver.options.autoRun,
appBoot,
});
}

return {
src: entryTemplate(params),
watches: [],
Expand Down Expand Up @@ -245,8 +231,6 @@ w._embroiderEngineBundles_ = [
fastbootOnlyAmdModules?: { runtime: string; buildtime: string }[];
defineModulesFrom?: string;
eagerModules?: string[];
autoRun?: boolean;
appBoot?: string;
lazyRoutes?: { names: string[]; path: string }[];
lazyEngines?: { names: string[]; path: string }[];
styles?: { path: string }[];
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { module, test } from 'qunit';

module('Acceptance | Custom app boot', function () {
test('ensure app boot up is happening from custom app-boot', function (assert) {
assert.equal(window.LoadedFromClassicCustomAppBoot, true, `expected: 'This addon to inject custom app-boot`);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ import { module, test } from 'qunit';

module('Acceptance | Custom app boot', function () {
test('ensure app boot up is happening from custom app-boot', function (assert) {
assert.equal(window.LoadedFromCustomAppBoot, true, `expected: 'This addon to inject custom app-boot`);
assert.equal(window.LoadedFromCustomAppBoot, true, `expected: 'This dummy app to inject custom app-boot to inject custom app-boot`);
});
});
5 changes: 5 additions & 0 deletions tests/fixtures/macro-sample-addon/tests/dummy/app/app-boot.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import Application from './app';
import environment from './config/environment';

window.LoadedFromCustomAppBoot = true;
Application.create(environment.APP);
2 changes: 1 addition & 1 deletion tests/scenarios/macro-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ function dummyAppScenarioSetup(project: Project) {
'if (!runningTests) {',
" require('{{MODULE_PREFIX}}/" + appSuffix + "')['default'].create({{CONFIG_APP}});",
'}',
'window.LoadedFromCustomAppBoot = true',
'window.LoadedFromClassicCustomAppBoot = true',
]
.join('')
.replace(/\{\{MODULE_PREFIX\}\}/g, prefix)
Expand Down

0 comments on commit 60779b4

Please sign in to comment.