@embroider/compat 3.5.1-unstable.c8b5bd4 → 3.5.1-unstable.d7336b2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@embroider/compat",
3
- "version": "3.5.1-unstable.c8b5bd4",
3
+ "version": "3.5.1-unstable.d7336b2",
4
4
  "private": false,
5
5
  "description": "Backward compatibility layer for the Embroider build system.",
6
6
  "repository": {
@@ -30,7 +30,7 @@
30
30
  "@babel/preset-env": "^7.14.5",
31
31
  "@babel/runtime": "^7.18.6",
32
32
  "@babel/traverse": "^7.14.5",
33
- "@embroider/macros": "1.16.2-unstable.c8b5bd4",
33
+ "@embroider/macros": "1.16.2-unstable.d7336b2",
34
34
  "@types/babel__code-frame": "^7.0.2",
35
35
  "@types/yargs": "^17.0.3",
36
36
  "assert-never": "^1.1.0",
@@ -66,7 +66,7 @@
66
66
  "yargs": "^17.0.1"
67
67
  },
68
68
  "devDependencies": {
69
- "@embroider/core": "3.4.10-unstable.c8b5bd4",
69
+ "@embroider/core": "3.4.10-unstable.d7336b2",
70
70
  "@embroider/sample-transforms": "workspace:*",
71
71
  "@embroider/test-support": "workspace:*",
72
72
  "@glimmer/syntax": "^0.84.3",
@@ -91,7 +91,7 @@
91
91
  "typescript": "^5.4.5"
92
92
  },
93
93
  "peerDependencies": {
94
- "@embroider/core": "3.4.10-unstable.c8b5bd4"
94
+ "@embroider/core": "3.4.10-unstable.d7336b2"
95
95
  },
96
96
  "engines": {
97
97
  "node": "12.* || 14.* || >= 16"
@@ -19,6 +19,7 @@ export declare class CompatAppBuilder {
19
19
  constructor(root: string, origAppPackage: Package, appPackageWithMovedDeps: Package, options: Required<Options>, compatApp: CompatApp, configTree: V1Config, contentForTree: ContentForConfig, synthVendor: Package, synthStyles: Package);
20
20
  private fastbootJSSrcDir;
21
21
  private extractAssets;
22
+ private findTestemAsset;
22
23
  private activeAddonChildren;
23
24
  private get allActiveAddons();
24
25
  private isActiveAddon;
@@ -30,7 +31,10 @@ export declare class CompatAppBuilder {
30
31
  private rootURL;
31
32
  private activeRules;
32
33
  private resolverConfig;
34
+ private scriptPriority;
33
35
  private get resolvableExtensionsPattern();
36
+ private impliedAssets;
37
+ private impliedAddonAssets;
34
38
  private babelConfig;
35
39
  private insertEmberApp;
36
40
  private findActiveAddons;
@@ -39,13 +43,13 @@ export declare class CompatAppBuilder {
39
43
  private get fastbootConfig();
40
44
  private engines;
41
45
  private updateAppJS;
42
- private get staticAppPathsPattern();
43
46
  private prepareAsset;
44
47
  private prepareAssets;
45
48
  private assetIsValid;
46
49
  private updateOnDiskAsset;
47
50
  private updateInMemoryAsset;
48
51
  private updateBuiltEmberAsset;
52
+ private updateConcatenatedAsset;
49
53
  private updateAssets;
50
54
  private gatherAssets;
51
55
  private firstBuild;
@@ -57,8 +61,14 @@ export declare class CompatAppBuilder {
57
61
  private addResolverConfig;
58
62
  private addContentForConfig;
59
63
  private addEmberEnvConfig;
60
- private addAppBoot;
64
+ private shouldSplitRoute;
65
+ private splitRoute;
66
+ private topAppJSAsset;
67
+ private get staticAppPathsPattern();
68
+ private requiredOtherFiles;
69
+ private appJSAsset;
61
70
  private importPaths;
71
+ private routeEntrypoint;
62
72
  private testJSEntrypoint;
63
73
  }
64
74
  interface TreeNames {
@@ -1,10 +1,33 @@
1
1
  "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
2
18
  var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
19
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
20
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
21
  else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
22
  return c > 3 && r && Object.defineProperty(target, key, r), r;
7
23
  };
24
+ var __importStar = (this && this.__importStar) || function (mod) {
25
+ if (mod && mod.__esModule) return mod;
26
+ var result = {};
27
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
28
+ __setModuleDefault(result, mod);
29
+ return result;
30
+ };
8
31
  var __importDefault = (this && this.__importDefault) || function (mod) {
9
32
  return (mod && mod.__esModule) ? mod : { "default": mod };
10
33
  };
@@ -14,8 +37,12 @@ const core_1 = require("@embroider/core");
14
37
  const path_1 = require("path");
15
38
  const dependency_rules_1 = require("./dependency-rules");
16
39
  const flatMap_1 = __importDefault(require("lodash/flatMap"));
40
+ const sortBy_1 = __importDefault(require("lodash/sortBy"));
41
+ const flatten_1 = __importDefault(require("lodash/flatten"));
42
+ const partition_1 = __importDefault(require("lodash/partition"));
17
43
  const mergeWith_1 = __importDefault(require("lodash/mergeWith"));
18
44
  const cloneDeep_1 = __importDefault(require("lodash/cloneDeep"));
45
+ const resolve_1 = require("resolve");
19
46
  const bind_decorator_1 = __importDefault(require("bind-decorator"));
20
47
  const fs_extra_1 = require("fs-extra");
21
48
  const ember_html_1 = require("@embroider/core/src/ember-html");
@@ -25,9 +52,10 @@ const portable_1 = require("@embroider/core/src/portable");
25
52
  const assert_never_1 = __importDefault(require("assert-never"));
26
53
  const typescript_memoize_1 = require("typescript-memoize");
27
54
  const path_2 = require("path");
28
- const resolve_1 = __importDefault(require("resolve"));
55
+ const resolve_2 = __importDefault(require("resolve"));
29
56
  const fs_extra_2 = require("fs-extra");
30
57
  const node_1 = require("@embroider/macros/src/node");
58
+ const fast_sourcemap_concat_1 = __importDefault(require("fast-sourcemap-concat"));
31
59
  const escape_string_regexp_1 = __importDefault(require("escape-string-regexp"));
32
60
  const sync_dir_1 = require("./sync-dir");
33
61
  // This exists during the actual broccoli build step. As opposed to CompatApp,
@@ -55,11 +83,36 @@ class CompatAppBuilder {
55
83
  }
56
84
  extractAssets(treePaths) {
57
85
  let assets = [];
86
+ // ember-cli traditionally outputs a dummy testem.js file to prevent
87
+ // spurious errors when running tests under "ember s".
88
+ if (this.compatApp.shouldBuildTests) {
89
+ let testemAsset = this.findTestemAsset();
90
+ if (testemAsset) {
91
+ assets.push(testemAsset);
92
+ }
93
+ }
58
94
  for (let asset of this.emberEntrypoints(treePaths.htmlTree)) {
59
95
  assets.push(asset);
60
96
  }
61
97
  return assets;
62
98
  }
99
+ findTestemAsset() {
100
+ let sourcePath;
101
+ try {
102
+ sourcePath = (0, resolve_1.sync)('ember-cli/lib/broccoli/testem.js', { basedir: this.root });
103
+ }
104
+ catch (err) { }
105
+ if (sourcePath) {
106
+ let stat = (0, fs_extra_1.statSync)(sourcePath);
107
+ return {
108
+ kind: 'on-disk',
109
+ relativePath: 'testem.js',
110
+ sourcePath,
111
+ mtime: stat.mtime.getTime(),
112
+ size: stat.size,
113
+ };
114
+ }
115
+ }
63
116
  activeAddonChildren(pkg) {
64
117
  let result = pkg.dependencies.filter(this.isActiveAddon).filter(
65
118
  // When looking for child addons, we want to ignore 'peerDependencies' of
@@ -195,18 +248,63 @@ class CompatAppBuilder {
195
248
  // this is the additional stufff that @embroider/compat adds on top to do
196
249
  // global template resolving
197
250
  modulePrefix: this.modulePrefix(),
198
- splitAtRoutes: this.options.splitAtRoutes,
199
251
  podModulePrefix: this.podModulePrefix(),
200
252
  activePackageRules: this.activeRules(),
201
253
  options,
202
- autoRun: this.compatApp.autoRun,
203
- staticAppPaths: this.options.staticAppPaths,
204
254
  };
205
255
  return config;
206
256
  }
257
+ scriptPriority(pkg) {
258
+ switch (pkg.name) {
259
+ case 'loader.js':
260
+ return 0;
261
+ case 'ember-source':
262
+ return 10;
263
+ default:
264
+ return 1000;
265
+ }
266
+ }
207
267
  get resolvableExtensionsPattern() {
208
268
  return (0, core_1.extensionsPattern)(this.resolvableExtensions());
209
269
  }
270
+ impliedAssets(type, engine) {
271
+ let result = this.impliedAddonAssets(type, engine).map((sourcePath) => {
272
+ let stats = (0, fs_extra_1.statSync)(sourcePath);
273
+ return {
274
+ kind: 'on-disk',
275
+ relativePath: (0, core_1.explicitRelative)(this.root, sourcePath),
276
+ sourcePath,
277
+ mtime: stats.mtimeMs,
278
+ size: stats.size,
279
+ };
280
+ });
281
+ return result;
282
+ }
283
+ impliedAddonAssets(type, { engine }) {
284
+ let result = [];
285
+ for (let addon of (0, sortBy_1.default)(Array.from(engine.addons.keys()), this.scriptPriority.bind(this))) {
286
+ let implicitScripts = addon.meta[type];
287
+ if (implicitScripts) {
288
+ let styles = [];
289
+ let options = { basedir: addon.root };
290
+ for (let mod of implicitScripts) {
291
+ if (type === 'implicit-styles') {
292
+ // exclude engines because they will handle their own css importation
293
+ if (!addon.isLazyEngine()) {
294
+ styles.push(resolve_2.default.sync(mod, options));
295
+ }
296
+ }
297
+ else {
298
+ result.push(resolve_2.default.sync(mod, options));
299
+ }
300
+ }
301
+ if (styles.length) {
302
+ result = [...styles, ...result];
303
+ }
304
+ }
305
+ }
306
+ return result;
307
+ }
210
308
  async babelConfig(resolverConfig) {
211
309
  let babel = (0, cloneDeep_1.default)(this.compatApp.babelConfig());
212
310
  if (!babel.plugins) {
@@ -285,7 +383,8 @@ class CompatAppBuilder {
285
383
  // our tests entrypoint already includes a correct module dependency on the
286
384
  // app, so we only insert the app when we're not inserting tests
287
385
  if (!asset.fileAsset.includeTests) {
288
- html.insertScriptTag(html.javascript, '@embroider/core/entrypoint', { type: 'module' });
386
+ let appJS = this.topAppJSAsset(appFiles, prepared);
387
+ html.insertScriptTag(html.javascript, appJS.relativePath, { type: 'module' });
289
388
  }
290
389
  if (this.fastbootConfig) {
291
390
  // any extra fastboot app files get inserted into our html.javascript
@@ -425,14 +524,9 @@ class CompatAppBuilder {
425
524
  }
426
525
  return this.engines.map(({ engine, appSync, fastbootSync }) => {
427
526
  var _a;
428
- return new app_files_1.AppFiles(engine, appSync.files, (_a = fastbootSync === null || fastbootSync === void 0 ? void 0 : fastbootSync.files) !== null && _a !== void 0 ? _a : new Set(), this.resolvableExtensionsPattern, this.staticAppPathsPattern, this.podModulePrefix());
527
+ return new app_files_1.AppFiles(engine, appSync.files, (_a = fastbootSync === null || fastbootSync === void 0 ? void 0 : fastbootSync.files) !== null && _a !== void 0 ? _a : new Set(), this.resolvableExtensionsPattern, this.podModulePrefix());
429
528
  });
430
529
  }
431
- get staticAppPathsPattern() {
432
- if (this.options.staticAppPaths.length > 0) {
433
- return new RegExp('^(?:' + this.options.staticAppPaths.map(staticAppPath => (0, escape_string_regexp_1.default)(staticAppPath)).join('|') + ')(?:$|/)');
434
- }
435
- }
436
530
  prepareAsset(asset, appFiles, prepared) {
437
531
  if (asset.kind === 'ember') {
438
532
  let prior = this.assets.get(asset.relativePath);
@@ -470,6 +564,13 @@ class CompatAppBuilder {
470
564
  return prior.kind === 'in-memory' && stringOrBufferEqual(prior.source, asset.source);
471
565
  case 'built-ember':
472
566
  return prior.kind === 'built-ember' && prior.source === asset.source;
567
+ case 'concatenated-asset':
568
+ return (prior.kind === 'concatenated-asset' &&
569
+ prior.sources.length === asset.sources.length &&
570
+ prior.sources.every((priorFile, index) => {
571
+ let newFile = asset.sources[index];
572
+ return this.assetIsValid(newFile, priorFile);
573
+ }));
473
574
  }
474
575
  }
475
576
  updateOnDiskAsset(asset) {
@@ -487,6 +588,33 @@ class CompatAppBuilder {
487
588
  (0, fs_extra_2.ensureDirSync)((0, path_2.dirname)(destination));
488
589
  (0, fs_extra_1.writeFileSync)(destination, asset.source, 'utf8');
489
590
  }
591
+ async updateConcatenatedAsset(asset) {
592
+ let concat = new fast_sourcemap_concat_1.default({
593
+ outputFile: (0, path_2.join)(this.root, asset.relativePath),
594
+ mapCommentType: asset.relativePath.endsWith('.js') ? 'line' : 'block',
595
+ baseDir: this.root,
596
+ });
597
+ if (process.env.EMBROIDER_CONCAT_STATS) {
598
+ let MeasureConcat = (await Promise.resolve().then(() => __importStar(require('@embroider/core/src/measure-concat')))).default;
599
+ concat = new MeasureConcat(asset.relativePath, concat, this.root);
600
+ }
601
+ for (let source of asset.sources) {
602
+ switch (source.kind) {
603
+ case 'on-disk':
604
+ concat.addFile((0, core_1.explicitRelative)(this.root, source.sourcePath));
605
+ break;
606
+ case 'in-memory':
607
+ if (typeof source.source !== 'string') {
608
+ throw new Error(`attempted to concatenated a Buffer-backed in-memory asset`);
609
+ }
610
+ concat.addSpace(source.source);
611
+ break;
612
+ default:
613
+ (0, assert_never_1.default)(source);
614
+ }
615
+ }
616
+ await concat.end();
617
+ }
490
618
  async updateAssets(requestedAssets, appFiles) {
491
619
  let assets = this.prepareAssets(requestedAssets, appFiles);
492
620
  for (let asset of assets.values()) {
@@ -504,6 +632,9 @@ class CompatAppBuilder {
504
632
  case 'built-ember':
505
633
  this.updateBuiltEmberAsset(asset);
506
634
  break;
635
+ case 'concatenated-asset':
636
+ await this.updateConcatenatedAsset(asset);
637
+ break;
507
638
  default:
508
639
  (0, assert_never_1.default)(asset);
509
640
  }
@@ -514,6 +645,7 @@ class CompatAppBuilder {
514
645
  }
515
646
  }
516
647
  this.assets = assets;
648
+ return [...assets.values()];
517
649
  }
518
650
  gatherAssets(inputPaths) {
519
651
  // first gather all the assets out of addons
@@ -547,12 +679,20 @@ class CompatAppBuilder {
547
679
  }
548
680
  let appFiles = this.updateAppJS(inputPaths.appJS);
549
681
  let assets = this.gatherAssets(inputPaths);
550
- await this.updateAssets(assets, appFiles);
682
+ let finalAssets = await this.updateAssets(assets, appFiles);
551
683
  let assetPaths = assets.map(asset => asset.relativePath);
552
684
  if (this.activeFastboot) {
553
685
  // when using fastboot, our own package.json needs to be in the output so fastboot can read it.
554
686
  assetPaths.push('package.json');
555
687
  }
688
+ for (let asset of finalAssets) {
689
+ // our concatenated assets all have map files that ride along. Here we're
690
+ // telling the final stage packager to be sure and serve the map files
691
+ // too.
692
+ if (asset.kind === 'concatenated-asset') {
693
+ assetPaths.push(asset.sourcemapPath);
694
+ }
695
+ }
556
696
  let meta = {
557
697
  type: 'app',
558
698
  version: 2,
@@ -573,7 +713,6 @@ class CompatAppBuilder {
573
713
  this.addResolverConfig(resolverConfig);
574
714
  this.addContentForConfig(this.contentForTree.readContents());
575
715
  this.addEmberEnvConfig(this.configTree.readConfig().EmberENV);
576
- this.addAppBoot(this.compatApp.appBoot.readAppBoot());
577
716
  let babelConfig = await this.babelConfig(resolverConfig);
578
717
  this.addBabelConfig(babelConfig);
579
718
  (0, fs_extra_1.writeFileSync)((0, path_2.join)(this.root, 'macros-config.json'), JSON.stringify(this.compatApp.macrosConfig.babelPluginConfig()[0], null, 2));
@@ -624,7 +763,7 @@ class CompatAppBuilder {
624
763
  if (i < hint.resolve.length - 1) {
625
764
  target = (0, path_2.join)(target, 'package.json');
626
765
  }
627
- cursor = resolve_1.default.sync(target, { basedir: (0, path_2.dirname)(cursor) });
766
+ cursor = resolve_2.default.sync(target, { basedir: (0, path_2.dirname)(cursor) });
628
767
  }
629
768
  return {
630
769
  requireFile: cursor,
@@ -653,8 +792,179 @@ class CompatAppBuilder {
653
792
  spaces: 2,
654
793
  });
655
794
  }
656
- addAppBoot(appBoot) {
657
- (0, fs_extra_1.writeFileSync)((0, path_2.join)((0, core_1.locateEmbroiderWorkingDir)(this.compatApp.root), 'ember-app-boot.js'), appBoot !== null && appBoot !== void 0 ? appBoot : '');
795
+ shouldSplitRoute(routeName) {
796
+ return (!this.options.splitAtRoutes ||
797
+ this.options.splitAtRoutes.find(pattern => {
798
+ if (typeof pattern === 'string') {
799
+ return pattern === routeName;
800
+ }
801
+ else {
802
+ return pattern.test(routeName);
803
+ }
804
+ }));
805
+ }
806
+ splitRoute(routeName, files, addToParent, addLazyBundle) {
807
+ let shouldSplit = routeName && this.shouldSplitRoute(routeName);
808
+ let ownFiles = [];
809
+ let ownNames = new Set();
810
+ if (files.template) {
811
+ if (shouldSplit) {
812
+ ownFiles.push(files.template);
813
+ ownNames.add(routeName);
814
+ }
815
+ else {
816
+ addToParent(routeName, files.template);
817
+ }
818
+ }
819
+ if (files.controller) {
820
+ if (shouldSplit) {
821
+ ownFiles.push(files.controller);
822
+ ownNames.add(routeName);
823
+ }
824
+ else {
825
+ addToParent(routeName, files.controller);
826
+ }
827
+ }
828
+ if (files.route) {
829
+ if (shouldSplit) {
830
+ ownFiles.push(files.route);
831
+ ownNames.add(routeName);
832
+ }
833
+ else {
834
+ addToParent(routeName, files.route);
835
+ }
836
+ }
837
+ for (let [childName, childFiles] of files.children) {
838
+ this.splitRoute(`${routeName}.${childName}`, childFiles, (childRouteName, childFile) => {
839
+ // this is our child calling "addToParent"
840
+ if (shouldSplit) {
841
+ ownFiles.push(childFile);
842
+ ownNames.add(childRouteName);
843
+ }
844
+ else {
845
+ addToParent(childRouteName, childFile);
846
+ }
847
+ }, (routeNames, files) => {
848
+ addLazyBundle(routeNames, files);
849
+ });
850
+ }
851
+ if (ownFiles.length > 0) {
852
+ addLazyBundle([...ownNames], ownFiles);
853
+ }
854
+ }
855
+ topAppJSAsset(engines, prepared) {
856
+ let [app, ...childEngines] = engines;
857
+ let relativePath = `assets/${this.origAppPackage.name}.js`;
858
+ return this.appJSAsset(relativePath, app, childEngines, prepared, {
859
+ autoRun: this.compatApp.autoRun,
860
+ appBoot: !this.compatApp.autoRun ? this.compatApp.appBoot.readAppBoot() : '',
861
+ mainModule: (0, core_1.explicitRelative)((0, path_2.dirname)(relativePath), 'app'),
862
+ appConfig: this.configTree.readConfig().APP,
863
+ });
864
+ }
865
+ get staticAppPathsPattern() {
866
+ if (this.options.staticAppPaths.length > 0) {
867
+ return new RegExp('^(?:' + this.options.staticAppPaths.map(staticAppPath => (0, escape_string_regexp_1.default)(staticAppPath)).join('|') + ')(?:$|/)');
868
+ }
869
+ }
870
+ requiredOtherFiles(appFiles) {
871
+ let pattern = this.staticAppPathsPattern;
872
+ if (pattern) {
873
+ return appFiles.otherAppFiles.filter(f => {
874
+ return !pattern.test(f);
875
+ });
876
+ }
877
+ else {
878
+ return appFiles.otherAppFiles;
879
+ }
880
+ }
881
+ appJSAsset(relativePath, appFiles, childEngines, prepared, entryParams) {
882
+ let cached = prepared.get(relativePath);
883
+ if (cached) {
884
+ return cached;
885
+ }
886
+ let eagerModules = [];
887
+ let requiredAppFiles = [this.requiredOtherFiles(appFiles)];
888
+ if (!this.options.staticComponents) {
889
+ requiredAppFiles.push(appFiles.components);
890
+ }
891
+ if (!this.options.staticHelpers) {
892
+ requiredAppFiles.push(appFiles.helpers);
893
+ }
894
+ if (!this.options.staticModifiers) {
895
+ requiredAppFiles.push(appFiles.modifiers);
896
+ }
897
+ let styles = [];
898
+ // only import styles from engines with a parent (this excludeds the parent application) as their styles
899
+ // will be inserted via a direct <link> tag.
900
+ if (!appFiles.engine.isApp && appFiles.engine.package.isLazyEngine()) {
901
+ let implicitStyles = this.impliedAssets('implicit-styles', appFiles);
902
+ for (let style of implicitStyles) {
903
+ styles.push({
904
+ path: (0, core_1.explicitRelative)('assets/_engine_', style.relativePath),
905
+ });
906
+ }
907
+ let engineMeta = appFiles.engine.package.meta;
908
+ if (engineMeta && engineMeta['implicit-styles']) {
909
+ for (let style of engineMeta['implicit-styles']) {
910
+ styles.push({
911
+ path: (0, core_1.explicitRelative)((0, path_2.dirname)(relativePath), (0, path_2.join)(appFiles.engine.appRelativePath, style)),
912
+ });
913
+ }
914
+ }
915
+ }
916
+ let lazyEngines = [];
917
+ for (let childEngine of childEngines) {
918
+ let asset = this.appJSAsset(`assets/_engine_/${encodeURIComponent(childEngine.engine.package.name)}.js`, childEngine, [], prepared);
919
+ if (childEngine.engine.package.isLazyEngine()) {
920
+ lazyEngines.push({
921
+ names: [childEngine.engine.package.name],
922
+ path: (0, core_1.explicitRelative)((0, path_2.dirname)(relativePath), asset.relativePath),
923
+ });
924
+ }
925
+ else {
926
+ eagerModules.push((0, core_1.explicitRelative)((0, path_2.dirname)(relativePath), asset.relativePath));
927
+ }
928
+ }
929
+ let lazyRoutes = [];
930
+ for (let [routeName, routeFiles] of appFiles.routeFiles.children) {
931
+ this.splitRoute(routeName, routeFiles, (_, filename) => {
932
+ requiredAppFiles.push([filename]);
933
+ }, (routeNames, files) => {
934
+ let routeEntrypoint = `assets/_route_/${encodeURIComponent(routeNames[0])}.js`;
935
+ if (!prepared.has(routeEntrypoint)) {
936
+ prepared.set(routeEntrypoint, this.routeEntrypoint(appFiles, routeEntrypoint, files));
937
+ }
938
+ lazyRoutes.push({
939
+ names: routeNames,
940
+ path: this.importPaths(appFiles, routeEntrypoint).buildtime,
941
+ });
942
+ });
943
+ }
944
+ let [fastboot, nonFastboot] = (0, partition_1.default)(excludeDotFiles((0, flatten_1.default)(requiredAppFiles)), file => appFiles.isFastbootOnly.get(file));
945
+ let amdModules = nonFastboot.map(file => this.importPaths(appFiles, file));
946
+ let fastbootOnlyAmdModules = fastboot.map(file => this.importPaths(appFiles, file));
947
+ let params = {
948
+ amdModules,
949
+ fastbootOnlyAmdModules,
950
+ lazyRoutes,
951
+ lazyEngines,
952
+ eagerModules,
953
+ styles,
954
+ // this is a backward-compatibility feature: addons can force inclusion of modules.
955
+ defineModulesFrom: './-embroider-implicit-modules.js',
956
+ };
957
+ if (entryParams) {
958
+ Object.assign(params, entryParams);
959
+ }
960
+ let source = entryTemplate(params);
961
+ let asset = {
962
+ kind: 'in-memory',
963
+ source,
964
+ relativePath,
965
+ };
966
+ prepared.set(relativePath, asset);
967
+ return asset;
658
968
  }
659
969
  importPaths({ engine }, engineRelativePath) {
660
970
  let noHBS = engineRelativePath.replace(this.resolvableExtensionsPattern, '').replace(/\.hbs$/, '');
@@ -663,6 +973,18 @@ class CompatAppBuilder {
663
973
  buildtime: path_1.posix.join(engine.package.name, engineRelativePath),
664
974
  };
665
975
  }
976
+ routeEntrypoint(appFiles, relativePath, files) {
977
+ let [fastboot, nonFastboot] = (0, partition_1.default)(files, file => appFiles.isFastbootOnly.get(file));
978
+ let asset = {
979
+ kind: 'in-memory',
980
+ source: routeEntryTemplate({
981
+ files: nonFastboot.map(f => this.importPaths(appFiles, f)),
982
+ fastbootOnlyFiles: fastboot.map(f => this.importPaths(appFiles, f)),
983
+ }),
984
+ relativePath,
985
+ };
986
+ return asset;
987
+ }
666
988
  testJSEntrypoint(appFiles, prepared) {
667
989
  let asset = prepared.get(`assets/test.js`);
668
990
  if (asset) {
@@ -673,12 +995,22 @@ class CompatAppBuilder {
673
995
  // the app.
674
996
  let engine = appFiles[0];
675
997
  const myName = 'assets/test.js';
998
+ // tests necessarily also include the app. This is where we account for
999
+ // that. The classic solution was to always include the app's separate
1000
+ // script tag in the tests HTML, but that isn't as easy for final stage
1001
+ // packagers to understand. It's better to express it here as a direct
1002
+ // module dependency.
1003
+ let eagerModules = [
1004
+ 'ember-testing',
1005
+ (0, core_1.explicitRelative)((0, path_2.dirname)(myName), this.topAppJSAsset(appFiles, prepared).relativePath),
1006
+ ];
676
1007
  let amdModules = [];
677
1008
  for (let relativePath of engine.tests) {
678
1009
  amdModules.push(this.importPaths(engine, relativePath));
679
1010
  }
680
1011
  let source = entryTemplate({
681
1012
  amdModules,
1013
+ eagerModules,
682
1014
  testSuffix: true,
683
1015
  // this is a backward-compatibility feature: addons can force inclusion of test support modules.
684
1016
  defineModulesFrom: './-embroider-implicit-test-modules.js',
@@ -696,6 +1028,9 @@ exports.CompatAppBuilder = CompatAppBuilder;
696
1028
  __decorate([
697
1029
  (0, typescript_memoize_1.Memoize)()
698
1030
  ], CompatAppBuilder.prototype, "fastbootJSSrcDir", null);
1031
+ __decorate([
1032
+ (0, typescript_memoize_1.Memoize)()
1033
+ ], CompatAppBuilder.prototype, "findTestemAsset", null);
699
1034
  __decorate([
700
1035
  (0, typescript_memoize_1.Memoize)()
701
1036
  ], CompatAppBuilder.prototype, "allActiveAddons", null);
@@ -722,10 +1057,10 @@ __decorate([
722
1057
  ], CompatAppBuilder.prototype, "fastbootConfig", null);
723
1058
  __decorate([
724
1059
  (0, typescript_memoize_1.Memoize)()
725
- ], CompatAppBuilder.prototype, "staticAppPathsPattern", null);
1060
+ ], CompatAppBuilder.prototype, "portableHints", null);
726
1061
  __decorate([
727
1062
  (0, typescript_memoize_1.Memoize)()
728
- ], CompatAppBuilder.prototype, "portableHints", null);
1063
+ ], CompatAppBuilder.prototype, "staticAppPathsPattern", null);
729
1064
  function defaultAddonPackageRules() {
730
1065
  return (0, fs_extra_2.readdirSync)((0, path_2.join)(__dirname, 'addon-dependency-rules'))
731
1066
  .map(filename => {
@@ -759,8 +1094,9 @@ let d = w.define;
759
1094
  {{/if}}
760
1095
 
761
1096
 
762
- import "ember-testing";
763
- import "@embroider/core/entrypoint";
1097
+ {{#each eagerModules as |eagerModule| ~}}
1098
+ i("{{js-string-escape eagerModule}}");
1099
+ {{/each}}
764
1100
 
765
1101
  {{#each amdModules as |amdModule| ~}}
766
1102
  d("{{js-string-escape amdModule.runtime}}", function(){ return i("{{js-string-escape amdModule.buildtime}}");});
@@ -827,6 +1163,21 @@ if (!runningTests) {
827
1163
  EmberENV.TESTS_FILE_LOADED = true;
828
1164
  {{/if}}
829
1165
  `);
1166
+ const routeEntryTemplate = (0, core_1.jsHandlebarsCompile)(`
1167
+ import { importSync as i } from '@embroider/macros';
1168
+ let d = window.define;
1169
+ {{#each files as |amdModule| ~}}
1170
+ d("{{js-string-escape amdModule.runtime}}", function(){ return i("{{js-string-escape amdModule.buildtime}}");});
1171
+ {{/each}}
1172
+ {{#if fastbootOnlyFiles}}
1173
+ import { macroCondition, getGlobalConfig } from '@embroider/macros';
1174
+ if (macroCondition(getGlobalConfig().fastboot?.isRunning)) {
1175
+ {{#each fastbootOnlyFiles as |amdModule| ~}}
1176
+ d("{{js-string-escape amdModule.runtime}}", function(){ return i("{{js-string-escape amdModule.buildtime}}");});
1177
+ {{/each}}
1178
+ }
1179
+ {{/if}}
1180
+ `);
830
1181
  function stringOrBufferEqual(a, b) {
831
1182
  if (typeof a === 'string' && typeof b === 'string') {
832
1183
  return a === b;
@@ -875,6 +1226,9 @@ function addCachablePlugin(babelConfig) {
875
1226
  ]);
876
1227
  }
877
1228
  }
1229
+ function excludeDotFiles(files) {
1230
+ return files.filter(file => !file.startsWith('.') && !file.includes('/.'));
1231
+ }
878
1232
  class ParsedEmberAsset {
879
1233
  constructor(asset) {
880
1234
  this.kind = 'parsed-ember';
@@ -894,4 +1248,15 @@ class BuiltEmberAsset {
894
1248
  this.relativePath = asset.relativePath;
895
1249
  }
896
1250
  }
1251
+ class ConcatenatedAsset {
1252
+ constructor(relativePath, sources, resolvableExtensions) {
1253
+ this.relativePath = relativePath;
1254
+ this.sources = sources;
1255
+ this.resolvableExtensions = resolvableExtensions;
1256
+ this.kind = 'concatenated-asset';
1257
+ }
1258
+ get sourcemapPath() {
1259
+ return this.relativePath.replace(this.resolvableExtensions, '') + '.map';
1260
+ }
1261
+ }
897
1262
  //# sourceMappingURL=compat-app-builder.js.map