@embroider/compat 3.4.8 → 3.4.9-unstable.ea895c2

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.
@@ -34,7 +34,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
34
34
  Object.defineProperty(exports, "__esModule", { value: true });
35
35
  exports.CompatAppBuilder = void 0;
36
36
  const core_1 = require("@embroider/core");
37
- const walk_sync_1 = __importDefault(require("walk-sync"));
38
37
  const path_1 = require("path");
39
38
  const dependency_rules_1 = require("./dependency-rules");
40
39
  const flatMap_1 = __importDefault(require("lodash/flatMap"));
@@ -62,13 +61,14 @@ const sync_dir_1 = require("./sync-dir");
62
61
  // This exists during the actual broccoli build step. As opposed to CompatApp,
63
62
  // which also exists during pipeline-construction time.
64
63
  class CompatAppBuilder {
65
- constructor(root, origAppPackage, appPackageWithMovedDeps, options, compatApp, configTree, synthVendor, synthStyles) {
64
+ constructor(root, origAppPackage, appPackageWithMovedDeps, options, compatApp, configTree, contentForTree, synthVendor, synthStyles) {
66
65
  this.root = root;
67
66
  this.origAppPackage = origAppPackage;
68
67
  this.appPackageWithMovedDeps = appPackageWithMovedDeps;
69
68
  this.options = options;
70
69
  this.compatApp = compatApp;
71
70
  this.configTree = configTree;
71
+ this.contentForTree = contentForTree;
72
72
  this.synthVendor = synthVendor;
73
73
  this.synthStyles = synthStyles;
74
74
  // for each relativePath, an Asset we have already emitted
@@ -83,22 +83,6 @@ class CompatAppBuilder {
83
83
  }
84
84
  extractAssets(treePaths) {
85
85
  let assets = [];
86
- // Everything in our traditional public tree is an on-disk asset
87
- if (treePaths.publicTree) {
88
- walk_sync_1.default
89
- .entries(treePaths.publicTree, {
90
- directories: false,
91
- })
92
- .forEach(entry => {
93
- assets.push({
94
- kind: 'on-disk',
95
- relativePath: entry.relativePath,
96
- sourcePath: entry.fullPath,
97
- mtime: entry.mtime,
98
- size: entry.size,
99
- });
100
- });
101
- }
102
86
  // ember-cli traditionally outputs a dummy testem.js file to prevent
103
87
  // spurious errors when running tests under "ember s".
104
88
  if (this.compatApp.shouldBuildTests) {
@@ -177,7 +161,7 @@ class CompatAppBuilder {
177
161
  // For TS, we defer to ember-cli-babel, and the setting for
178
162
  // "enableTypescriptTransform" can be set with and without
179
163
  // ember-cli-typescript
180
- return ['.wasm', '.mjs', '.js', '.json', '.ts', '.hbs', '.hbs.js'];
164
+ return ['.wasm', '.mjs', '.js', '.json', '.ts', '.hbs', '.hbs.js', '.gjs', '.gts'];
181
165
  }
182
166
  *emberEntrypoints(htmlTreePath) {
183
167
  let classicEntrypoints = [
@@ -233,10 +217,6 @@ class CompatAppBuilder {
233
217
  resolverConfig(engines) {
234
218
  let renamePackages = Object.assign({}, ...this.allActiveAddons.map(dep => dep.meta['renamed-packages']));
235
219
  let renameModules = Object.assign({}, ...this.allActiveAddons.map(dep => dep.meta['renamed-modules']));
236
- let activeAddons = {};
237
- for (let addon of this.allActiveAddons) {
238
- activeAddons[addon.name] = addon.root;
239
- }
240
220
  let options = {
241
221
  staticHelpers: this.options.staticHelpers,
242
222
  staticModifiers: this.options.staticModifiers,
@@ -245,7 +225,6 @@ class CompatAppBuilder {
245
225
  };
246
226
  let config = {
247
227
  // this part is the base ModuleResolverOptions as required by @embroider/core
248
- activeAddons,
249
228
  renameModules,
250
229
  renamePackages,
251
230
  resolvableExtensions: this.resolvableExtensions(),
@@ -257,14 +236,16 @@ class CompatAppBuilder {
257
236
  root: (0, fs_extra_1.realpathSync)(index === 0 ? this.root : appFiles.engine.package.root),
258
237
  fastbootFiles: appFiles.fastbootFiles,
259
238
  activeAddons: [...appFiles.engine.addons]
260
- .map(a => ({
261
- name: a.name,
262
- root: a.root,
239
+ .map(([addon, canResolveFromFile]) => ({
240
+ name: addon.name,
241
+ root: addon.root,
242
+ canResolveFromFile,
263
243
  }))
264
244
  // the traditional order is the order in which addons will run, such
265
245
  // that the last one wins. Our resolver's order is the order to
266
246
  // search, so first one wins.
267
247
  .reverse(),
248
+ isLazy: appFiles.engine.package.isLazyEngine(),
268
249
  })),
269
250
  amdCompatibility: this.options.amdCompatibility,
270
251
  // this is the additional stufff that @embroider/compat adds on top to do
@@ -317,35 +298,11 @@ class CompatAppBuilder {
317
298
  source: `loader.makeDefaultExport=false;`,
318
299
  });
319
300
  }
320
- if (type === 'implicit-test-scripts') {
321
- // this is the traditional test-support-suffix.js
322
- result.push({
323
- kind: 'in-memory',
324
- relativePath: '_testing_suffix_.js',
325
- source: `
326
- var runningTests=true;
327
- if (typeof Testem !== 'undefined' && (typeof QUnit !== 'undefined' || typeof Mocha !== 'undefined')) {
328
- Testem.hookIntoTestFramework();
329
- }`,
330
- });
331
- // whether or not anybody was actually using @embroider/macros
332
- // explicitly as an addon, we ensure its test-support file is always
333
- // present.
334
- if (!result.find(s => s.kind === 'on-disk' && s.sourcePath.endsWith('embroider-macros-test-support.js'))) {
335
- result.unshift({
336
- kind: 'on-disk',
337
- sourcePath: require.resolve('@embroider/macros/src/vendor/embroider-macros-test-support'),
338
- mtime: 0,
339
- size: 0,
340
- relativePath: 'embroider-macros-test-support.js',
341
- });
342
- }
343
- }
344
301
  return result;
345
302
  }
346
303
  impliedAddonAssets(type, { engine }) {
347
304
  let result = [];
348
- for (let addon of (0, sortBy_1.default)(Array.from(engine.addons), this.scriptPriority.bind(this))) {
305
+ for (let addon of (0, sortBy_1.default)(Array.from(engine.addons.keys()), this.scriptPriority.bind(this))) {
349
306
  let implicitScripts = addon.meta[type];
350
307
  if (implicitScripts) {
351
308
  let styles = [];
@@ -368,7 +325,7 @@ class CompatAppBuilder {
368
325
  }
369
326
  return result;
370
327
  }
371
- babelConfig(resolverConfig) {
328
+ async babelConfig(resolverConfig) {
372
329
  let babel = (0, cloneDeep_1.default)(this.compatApp.babelConfig());
373
330
  if (!babel.plugins) {
374
331
  babel.plugins = [];
@@ -378,7 +335,10 @@ class CompatAppBuilder {
378
335
  babel.plugins.push(require.resolve('@babel/plugin-syntax-dynamic-import'));
379
336
  // https://github.com/webpack/webpack/issues/12154
380
337
  babel.plugins.push(require.resolve('./rename-require-plugin'));
381
- babel.plugins.push([require.resolve('babel-plugin-ember-template-compilation'), this.etcOptions(resolverConfig)]);
338
+ babel.plugins.push([
339
+ require.resolve('babel-plugin-ember-template-compilation'),
340
+ await this.etcOptions(resolverConfig),
341
+ ]);
382
342
  // this is @embroider/macros configured for full stage3 resolution
383
343
  babel.plugins.push(...this.compatApp.macrosConfig.babelPluginConfig());
384
344
  let colocationOptions = {
@@ -454,7 +414,7 @@ class CompatAppBuilder {
454
414
  }
455
415
  }
456
416
  html.insertStyleLink(html.styles, `assets/${this.origAppPackage.name}.css`);
457
- const parentEngine = appFiles.find(e => !e.engine.parent);
417
+ const parentEngine = appFiles.find(e => e.engine.isApp);
458
418
  let vendorJS = this.implicitScriptsAsset(prepared, parentEngine, emberENV);
459
419
  if (vendorJS) {
460
420
  html.insertScriptTag(html.implicitScripts, vendorJS.relativePath);
@@ -467,24 +427,17 @@ class CompatAppBuilder {
467
427
  html.insertScriptTag(html.implicitScripts, script, { tag: 'fastboot-script' });
468
428
  }
469
429
  }
470
- let implicitStyles = this.implicitStylesAsset(prepared, parentEngine);
471
- if (implicitStyles) {
472
- html.insertStyleLink(html.implicitStyles, implicitStyles.relativePath);
473
- }
430
+ // virtual vendor.css entrypoint
431
+ html.insertStyleLink(html.implicitStyles, '@embroider/core/vendor.css');
474
432
  if (!asset.fileAsset.includeTests) {
475
433
  return;
476
434
  }
477
435
  // Test-related assets happen below this point
478
436
  let testJS = this.testJSEntrypoint(appFiles, prepared);
479
437
  html.insertScriptTag(html.testJavascript, testJS.relativePath, { type: 'module' });
480
- let implicitTestScriptsAsset = this.implicitTestScriptsAsset(prepared, parentEngine);
481
- if (implicitTestScriptsAsset) {
482
- html.insertScriptTag(html.implicitTestScripts, implicitTestScriptsAsset.relativePath);
483
- }
484
- let implicitTestStylesAsset = this.implicitTestStylesAsset(prepared, parentEngine);
485
- if (implicitTestStylesAsset) {
486
- html.insertStyleLink(html.implicitTestStyles, implicitTestStylesAsset.relativePath);
487
- }
438
+ // virtual test-support.js
439
+ html.insertScriptTag(html.implicitTestScripts, '@embroider/core/test-support.js');
440
+ html.insertStyleLink(html.implicitTestStyles, '@embroider/core/test-support.css');
488
441
  }
489
442
  implicitScriptsAsset(prepared, application, emberENV) {
490
443
  let asset = prepared.get('assets/vendor.js');
@@ -497,40 +450,6 @@ class CompatAppBuilder {
497
450
  }
498
451
  return asset;
499
452
  }
500
- implicitStylesAsset(prepared, application) {
501
- let asset = prepared.get('assets/vendor.css');
502
- if (!asset) {
503
- let implicitStyles = this.impliedAssets('implicit-styles', application);
504
- if (implicitStyles.length > 0) {
505
- // we reverse because we want the synthetic vendor style at the top
506
- asset = new ConcatenatedAsset('assets/vendor.css', implicitStyles.reverse(), this.resolvableExtensionsPattern);
507
- prepared.set(asset.relativePath, asset);
508
- }
509
- }
510
- return asset;
511
- }
512
- implicitTestScriptsAsset(prepared, application) {
513
- let testSupportJS = prepared.get('assets/test-support.js');
514
- if (!testSupportJS) {
515
- let implicitTestScripts = this.impliedAssets('implicit-test-scripts', application);
516
- if (implicitTestScripts.length > 0) {
517
- testSupportJS = new ConcatenatedAsset('assets/test-support.js', implicitTestScripts, this.resolvableExtensionsPattern);
518
- prepared.set(testSupportJS.relativePath, testSupportJS);
519
- }
520
- }
521
- return testSupportJS;
522
- }
523
- implicitTestStylesAsset(prepared, application) {
524
- let asset = prepared.get('assets/test-support.css');
525
- if (!asset) {
526
- let implicitTestStyles = this.impliedAssets('implicit-test-styles', application);
527
- if (implicitTestStyles.length > 0) {
528
- asset = new ConcatenatedAsset('assets/test-support.css', implicitTestStyles, this.resolvableExtensionsPattern);
529
- prepared.set(asset.relativePath, asset);
530
- }
531
- }
532
- return asset;
533
- }
534
453
  // recurse to find all active addons that don't cross an engine boundary.
535
454
  // Inner engines themselves will be returned, but not those engines' children.
536
455
  // The output set's insertion order is the proper ember-cli compatible
@@ -540,22 +459,31 @@ class CompatAppBuilder {
540
459
  if (!child.isEngine()) {
541
460
  this.findActiveAddons(child, engine, true);
542
461
  }
543
- engine.addons.add(child);
462
+ let canResolveFrom;
463
+ if (pkg === this.appPackageWithMovedDeps) {
464
+ // we want canResolveFrom to always be a rewritten package path, and our
465
+ // app's package is not rewritten yet here.
466
+ canResolveFrom = (0, path_1.resolve)(this.root, 'package.json');
467
+ }
468
+ else {
469
+ // whereas our addons are already moved
470
+ canResolveFrom = (0, path_1.resolve)(pkg.root, 'package.json');
471
+ }
472
+ engine.addons.set(child, canResolveFrom);
544
473
  }
545
474
  // ensure addons are applied in the correct order, if set (via @embroider/compat/v1-addon)
546
475
  if (!isChild) {
547
- engine.addons = new Set([...engine.addons].sort((a, b) => {
476
+ engine.addons = new Map([...engine.addons].sort(([a], [b]) => {
548
477
  return (a.meta['order-index'] || 0) - (b.meta['order-index'] || 0);
549
478
  }));
550
479
  }
551
480
  }
552
- partitionEngines(appJSPath) {
481
+ partitionEngines() {
553
482
  let queue = [
554
483
  {
555
484
  package: this.appPackageWithMovedDeps,
556
- addons: new Set(),
557
- parent: undefined,
558
- sourcePath: appJSPath,
485
+ addons: new Map(),
486
+ isApp: true,
559
487
  modulePrefix: this.modulePrefix(),
560
488
  appRelativePath: '.',
561
489
  },
@@ -568,14 +496,13 @@ class CompatAppBuilder {
568
496
  break;
569
497
  }
570
498
  this.findActiveAddons(current.package, current);
571
- for (let addon of current.addons) {
499
+ for (let addon of current.addons.keys()) {
572
500
  if (addon.isEngine() && !seenEngines.has(addon)) {
573
501
  seenEngines.add(addon);
574
502
  queue.push({
575
503
  package: addon,
576
- addons: new Set(),
577
- parent: current,
578
- sourcePath: addon.root,
504
+ addons: new Map(),
505
+ isApp: !current,
579
506
  modulePrefix: addon.name,
580
507
  appRelativePath: (0, core_1.explicitRelative)(this.root, addon.root),
581
508
  });
@@ -601,8 +528,8 @@ class CompatAppBuilder {
601
528
  updateAppJS(appJSPath) {
602
529
  var _a;
603
530
  if (!this.engines) {
604
- this.engines = this.partitionEngines(appJSPath).map(engine => {
605
- if (engine.sourcePath === appJSPath) {
531
+ this.engines = this.partitionEngines().map(engine => {
532
+ if (engine.isApp) {
606
533
  // this is the app. We have more to do for the app than for other
607
534
  // engines.
608
535
  let fastbootSync;
@@ -624,7 +551,7 @@ class CompatAppBuilder {
624
551
  // their files, not doing any actual copying or building.
625
552
  return {
626
553
  engine,
627
- appSync: new sync_dir_1.SyncDir(engine.sourcePath, undefined),
554
+ appSync: new sync_dir_1.SyncDir(engine.package.root, undefined),
628
555
  // AFAIK, we've never supported a fastboot overlay directory in an
629
556
  // engine. But if we do need that, it would go here.
630
557
  fastbootSync: undefined,
@@ -764,21 +691,6 @@ class CompatAppBuilder {
764
691
  gatherAssets(inputPaths) {
765
692
  // first gather all the assets out of addons
766
693
  let assets = [];
767
- for (let pkg of this.allActiveAddons) {
768
- if (pkg.meta['public-assets']) {
769
- for (let [filename, appRelativeURL] of Object.entries(pkg.meta['public-assets'] || {})) {
770
- let sourcePath = (0, path_1.resolve)(pkg.root, filename);
771
- let stats = (0, fs_extra_1.statSync)(sourcePath);
772
- assets.push({
773
- kind: 'on-disk',
774
- sourcePath,
775
- relativePath: appRelativeURL,
776
- mtime: stats.mtimeMs,
777
- size: stats.size,
778
- });
779
- }
780
- }
781
- }
782
694
  if (this.activeFastboot) {
783
695
  const source = `
784
696
  (function(){
@@ -841,8 +753,10 @@ class CompatAppBuilder {
841
753
  (0, fs_extra_1.writeFileSync)((0, path_2.join)(this.root, 'package.json'), JSON.stringify(pkg, null, 2), 'utf8');
842
754
  let resolverConfig = this.resolverConfig(appFiles);
843
755
  this.addResolverConfig(resolverConfig);
844
- let babelConfig = this.babelConfig(resolverConfig);
756
+ this.addContentForConfig(this.contentForTree.readContents());
757
+ let babelConfig = await this.babelConfig(resolverConfig);
845
758
  this.addBabelConfig(babelConfig);
759
+ (0, fs_extra_1.writeFileSync)((0, path_2.join)(this.root, 'macros-config.json'), JSON.stringify(this.compatApp.macrosConfig.babelPluginConfig()[0], null, 2));
846
760
  }
847
761
  combinePackageJSON(meta) {
848
762
  let pkgLayers = [this.origAppPackage.packageJSON];
@@ -855,7 +769,7 @@ class CompatAppBuilder {
855
769
  pkgLayers.push({ keywords: ['ember-addon'], 'ember-addon': meta });
856
770
  return combinePackageJSON(...pkgLayers);
857
771
  }
858
- etcOptions(resolverConfig) {
772
+ async etcOptions(resolverConfig) {
859
773
  let transforms = this.compatApp.htmlbarsPlugins;
860
774
  let { plugins: macroPlugins, setConfig } = node_1.MacrosConfig.transforms();
861
775
  setConfig(this.compatApp.macrosConfig);
@@ -872,7 +786,7 @@ class CompatAppBuilder {
872
786
  transforms.push([require.resolve('./resolver-transform'), opts]);
873
787
  }
874
788
  let resolver = new core_1.Resolver(resolverConfig);
875
- let resolution = resolver.nodeResolve('ember-source/vendor/ember/ember-template-compiler', (0, path_1.resolve)(this.root, 'package.json'));
789
+ let resolution = await resolver.nodeResolve('ember-source/vendor/ember/ember-template-compiler', (0, path_1.resolve)(this.root, 'package.json'));
876
790
  if (resolution.type !== 'real') {
877
791
  throw new Error(`bug: unable to resolve ember-template-compiler from ${this.root}`);
878
792
  }
@@ -909,6 +823,11 @@ class CompatAppBuilder {
909
823
  addResolverConfig(config) {
910
824
  (0, fs_extra_1.outputJSONSync)((0, path_2.join)((0, core_1.locateEmbroiderWorkingDir)(this.compatApp.root), 'resolver.json'), config, { spaces: 2 });
911
825
  }
826
+ addContentForConfig(contentForConfig) {
827
+ (0, fs_extra_1.outputJSONSync)((0, path_2.join)((0, core_1.locateEmbroiderWorkingDir)(this.compatApp.root), 'content-for.json'), contentForConfig, {
828
+ spaces: 2,
829
+ });
830
+ }
912
831
  shouldSplitRoute(routeName) {
913
832
  return (!this.options.splitAtRoutes ||
914
833
  this.options.splitAtRoutes.find(pattern => {
@@ -1014,7 +933,7 @@ class CompatAppBuilder {
1014
933
  let styles = [];
1015
934
  // only import styles from engines with a parent (this excludeds the parent application) as their styles
1016
935
  // will be inserted via a direct <link> tag.
1017
- if (appFiles.engine.parent && appFiles.engine.package.isLazyEngine()) {
936
+ if (!appFiles.engine.isApp && appFiles.engine.package.isLazyEngine()) {
1018
937
  let implicitStyles = this.impliedAssets('implicit-styles', appFiles);
1019
938
  for (let style of implicitStyles) {
1020
939
  styles.push({
@@ -1061,10 +980,16 @@ class CompatAppBuilder {
1061
980
  let [fastboot, nonFastboot] = (0, partition_1.default)(excludeDotFiles((0, flatten_1.default)(requiredAppFiles)), file => appFiles.isFastbootOnly.get(file));
1062
981
  let amdModules = nonFastboot.map(file => this.importPaths(appFiles, file));
1063
982
  let fastbootOnlyAmdModules = fastboot.map(file => this.importPaths(appFiles, file));
1064
- // this is a backward-compatibility feature: addons can force inclusion of
1065
- // modules.
1066
- eagerModules.push('./-embroider-implicit-modules.js');
1067
- let params = { amdModules, fastbootOnlyAmdModules, lazyRoutes, lazyEngines, eagerModules, styles };
983
+ let params = {
984
+ amdModules,
985
+ fastbootOnlyAmdModules,
986
+ lazyRoutes,
987
+ lazyEngines,
988
+ eagerModules,
989
+ styles,
990
+ // this is a backward-compatibility feature: addons can force inclusion of modules.
991
+ defineModulesFrom: './-embroider-implicit-modules.js',
992
+ };
1068
993
  if (entryParams) {
1069
994
  Object.assign(params, entryParams);
1070
995
  }
@@ -1116,9 +1041,6 @@ class CompatAppBuilder {
1116
1041
  (0, core_1.explicitRelative)((0, path_2.dirname)(myName), this.topAppJSAsset(appFiles, prepared).relativePath),
1117
1042
  ];
1118
1043
  let amdModules = [];
1119
- // this is a backward-compatibility feature: addons can force inclusion of
1120
- // test support modules.
1121
- eagerModules.push('./-embroider-implicit-test-modules.js');
1122
1044
  for (let relativePath of engine.tests) {
1123
1045
  amdModules.push(this.importPaths(engine, relativePath));
1124
1046
  }
@@ -1126,6 +1048,8 @@ class CompatAppBuilder {
1126
1048
  amdModules,
1127
1049
  eagerModules,
1128
1050
  testSuffix: true,
1051
+ // this is a backward-compatibility feature: addons can force inclusion of test support modules.
1052
+ defineModulesFrom: './-embroider-implicit-test-modules.js',
1129
1053
  });
1130
1054
  asset = {
1131
1055
  kind: 'in-memory',
@@ -1197,6 +1121,15 @@ let d = w.define;
1197
1121
  }
1198
1122
  {{/if}}
1199
1123
 
1124
+ {{#if defineModulesFrom ~}}
1125
+ import implicitModules from "{{js-string-escape defineModulesFrom}}";
1126
+
1127
+ for(const [name, module] of Object.entries(implicitModules)) {
1128
+ d(name, function() { return module });
1129
+ }
1130
+ {{/if}}
1131
+
1132
+
1200
1133
  {{#each eagerModules as |eagerModule| ~}}
1201
1134
  i("{{js-string-escape eagerModule}}");
1202
1135
  {{/each}}
@@ -1207,9 +1140,17 @@ let d = w.define;
1207
1140
 
1208
1141
  {{#if fastbootOnlyAmdModules}}
1209
1142
  if (macroCondition(getGlobalConfig().fastboot?.isRunning)) {
1143
+ let fastbootModules = {};
1144
+
1210
1145
  {{#each fastbootOnlyAmdModules as |amdModule| ~}}
1211
- d("{{js-string-escape amdModule.runtime}}", function(){ return i("{{js-string-escape amdModule.buildtime}}");});
1146
+ fastbootModules["{{js-string-escape amdModule.runtime}}"] = import("{{js-string-escape amdModule.buildtime}}");
1212
1147
  {{/each}}
1148
+
1149
+ const resolvedValues = await Promise.all(Object.values(fastbootModules));
1150
+
1151
+ Object.keys(fastbootModules).forEach((k, i) => {
1152
+ d(k, function(){ return resolvedValues[i];});
1153
+ })
1213
1154
  }
1214
1155
  {{/if}}
1215
1156