@embroider/compat 3.4.5 → 3.4.6-unstable.2afc470

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.
@@ -177,7 +177,7 @@ class CompatAppBuilder {
177
177
  // For TS, we defer to ember-cli-babel, and the setting for
178
178
  // "enableTypescriptTransform" can be set with and without
179
179
  // ember-cli-typescript
180
- return ['.wasm', '.mjs', '.js', '.json', '.ts', '.hbs', '.hbs.js'];
180
+ return ['.wasm', '.mjs', '.js', '.json', '.ts', '.hbs', '.hbs.js', '.gjs', '.gts'];
181
181
  }
182
182
  *emberEntrypoints(htmlTreePath) {
183
183
  let classicEntrypoints = [
@@ -233,10 +233,6 @@ class CompatAppBuilder {
233
233
  resolverConfig(engines) {
234
234
  let renamePackages = Object.assign({}, ...this.allActiveAddons.map(dep => dep.meta['renamed-packages']));
235
235
  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
236
  let options = {
241
237
  staticHelpers: this.options.staticHelpers,
242
238
  staticModifiers: this.options.staticModifiers,
@@ -245,7 +241,6 @@ class CompatAppBuilder {
245
241
  };
246
242
  let config = {
247
243
  // this part is the base ModuleResolverOptions as required by @embroider/core
248
- activeAddons,
249
244
  renameModules,
250
245
  renamePackages,
251
246
  resolvableExtensions: this.resolvableExtensions(),
@@ -257,14 +252,16 @@ class CompatAppBuilder {
257
252
  root: (0, fs_extra_1.realpathSync)(index === 0 ? this.root : appFiles.engine.package.root),
258
253
  fastbootFiles: appFiles.fastbootFiles,
259
254
  activeAddons: [...appFiles.engine.addons]
260
- .map(a => ({
261
- name: a.name,
262
- root: a.root,
255
+ .map(([addon, canResolveFromFile]) => ({
256
+ name: addon.name,
257
+ root: addon.root,
258
+ canResolveFromFile,
263
259
  }))
264
260
  // the traditional order is the order in which addons will run, such
265
261
  // that the last one wins. Our resolver's order is the order to
266
262
  // search, so first one wins.
267
263
  .reverse(),
264
+ isLazy: appFiles.engine.package.isLazyEngine(),
268
265
  })),
269
266
  amdCompatibility: this.options.amdCompatibility,
270
267
  // this is the additional stufff that @embroider/compat adds on top to do
@@ -317,35 +314,11 @@ class CompatAppBuilder {
317
314
  source: `loader.makeDefaultExport=false;`,
318
315
  });
319
316
  }
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
317
  return result;
345
318
  }
346
319
  impliedAddonAssets(type, { engine }) {
347
320
  let result = [];
348
- for (let addon of (0, sortBy_1.default)(Array.from(engine.addons), this.scriptPriority.bind(this))) {
321
+ for (let addon of (0, sortBy_1.default)(Array.from(engine.addons.keys()), this.scriptPriority.bind(this))) {
349
322
  let implicitScripts = addon.meta[type];
350
323
  if (implicitScripts) {
351
324
  let styles = [];
@@ -368,7 +341,7 @@ class CompatAppBuilder {
368
341
  }
369
342
  return result;
370
343
  }
371
- babelConfig(resolverConfig) {
344
+ async babelConfig(resolverConfig) {
372
345
  let babel = (0, cloneDeep_1.default)(this.compatApp.babelConfig());
373
346
  if (!babel.plugins) {
374
347
  babel.plugins = [];
@@ -378,7 +351,10 @@ class CompatAppBuilder {
378
351
  babel.plugins.push(require.resolve('@babel/plugin-syntax-dynamic-import'));
379
352
  // https://github.com/webpack/webpack/issues/12154
380
353
  babel.plugins.push(require.resolve('./rename-require-plugin'));
381
- babel.plugins.push([require.resolve('babel-plugin-ember-template-compilation'), this.etcOptions(resolverConfig)]);
354
+ babel.plugins.push([
355
+ require.resolve('babel-plugin-ember-template-compilation'),
356
+ await this.etcOptions(resolverConfig),
357
+ ]);
382
358
  // this is @embroider/macros configured for full stage3 resolution
383
359
  babel.plugins.push(...this.compatApp.macrosConfig.babelPluginConfig());
384
360
  let colocationOptions = {
@@ -454,7 +430,7 @@ class CompatAppBuilder {
454
430
  }
455
431
  }
456
432
  html.insertStyleLink(html.styles, `assets/${this.origAppPackage.name}.css`);
457
- const parentEngine = appFiles.find(e => !e.engine.parent);
433
+ const parentEngine = appFiles.find(e => e.engine.isApp);
458
434
  let vendorJS = this.implicitScriptsAsset(prepared, parentEngine, emberENV);
459
435
  if (vendorJS) {
460
436
  html.insertScriptTag(html.implicitScripts, vendorJS.relativePath);
@@ -477,10 +453,8 @@ class CompatAppBuilder {
477
453
  // Test-related assets happen below this point
478
454
  let testJS = this.testJSEntrypoint(appFiles, prepared);
479
455
  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
- }
456
+ // virtual test-support.js
457
+ html.insertScriptTag(html.implicitTestScripts, '@embroider/core/test-support.js');
484
458
  let implicitTestStylesAsset = this.implicitTestStylesAsset(prepared, parentEngine);
485
459
  if (implicitTestStylesAsset) {
486
460
  html.insertStyleLink(html.implicitTestStyles, implicitTestStylesAsset.relativePath);
@@ -509,17 +483,6 @@ class CompatAppBuilder {
509
483
  }
510
484
  return asset;
511
485
  }
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
486
  implicitTestStylesAsset(prepared, application) {
524
487
  let asset = prepared.get('assets/test-support.css');
525
488
  if (!asset) {
@@ -540,22 +503,31 @@ class CompatAppBuilder {
540
503
  if (!child.isEngine()) {
541
504
  this.findActiveAddons(child, engine, true);
542
505
  }
543
- engine.addons.add(child);
506
+ let canResolveFrom;
507
+ if (pkg === this.appPackageWithMovedDeps) {
508
+ // we want canResolveFrom to always be a rewritten package path, and our
509
+ // app's package is not rewritten yet here.
510
+ canResolveFrom = (0, path_1.resolve)(this.root, 'package.json');
511
+ }
512
+ else {
513
+ // whereas our addons are already moved
514
+ canResolveFrom = (0, path_1.resolve)(pkg.root, 'package.json');
515
+ }
516
+ engine.addons.set(child, canResolveFrom);
544
517
  }
545
518
  // ensure addons are applied in the correct order, if set (via @embroider/compat/v1-addon)
546
519
  if (!isChild) {
547
- engine.addons = new Set([...engine.addons].sort((a, b) => {
520
+ engine.addons = new Map([...engine.addons].sort(([a], [b]) => {
548
521
  return (a.meta['order-index'] || 0) - (b.meta['order-index'] || 0);
549
522
  }));
550
523
  }
551
524
  }
552
- partitionEngines(appJSPath) {
525
+ partitionEngines() {
553
526
  let queue = [
554
527
  {
555
528
  package: this.appPackageWithMovedDeps,
556
- addons: new Set(),
557
- parent: undefined,
558
- sourcePath: appJSPath,
529
+ addons: new Map(),
530
+ isApp: true,
559
531
  modulePrefix: this.modulePrefix(),
560
532
  appRelativePath: '.',
561
533
  },
@@ -568,14 +540,13 @@ class CompatAppBuilder {
568
540
  break;
569
541
  }
570
542
  this.findActiveAddons(current.package, current);
571
- for (let addon of current.addons) {
543
+ for (let addon of current.addons.keys()) {
572
544
  if (addon.isEngine() && !seenEngines.has(addon)) {
573
545
  seenEngines.add(addon);
574
546
  queue.push({
575
547
  package: addon,
576
- addons: new Set(),
577
- parent: current,
578
- sourcePath: addon.root,
548
+ addons: new Map(),
549
+ isApp: !current,
579
550
  modulePrefix: addon.name,
580
551
  appRelativePath: (0, core_1.explicitRelative)(this.root, addon.root),
581
552
  });
@@ -601,8 +572,8 @@ class CompatAppBuilder {
601
572
  updateAppJS(appJSPath) {
602
573
  var _a;
603
574
  if (!this.engines) {
604
- this.engines = this.partitionEngines(appJSPath).map(engine => {
605
- if (engine.sourcePath === appJSPath) {
575
+ this.engines = this.partitionEngines().map(engine => {
576
+ if (engine.isApp) {
606
577
  // this is the app. We have more to do for the app than for other
607
578
  // engines.
608
579
  let fastbootSync;
@@ -624,7 +595,7 @@ class CompatAppBuilder {
624
595
  // their files, not doing any actual copying or building.
625
596
  return {
626
597
  engine,
627
- appSync: new sync_dir_1.SyncDir(engine.sourcePath, undefined),
598
+ appSync: new sync_dir_1.SyncDir(engine.package.root, undefined),
628
599
  // AFAIK, we've never supported a fastboot overlay directory in an
629
600
  // engine. But if we do need that, it would go here.
630
601
  fastbootSync: undefined,
@@ -841,8 +812,9 @@ class CompatAppBuilder {
841
812
  (0, fs_extra_1.writeFileSync)((0, path_2.join)(this.root, 'package.json'), JSON.stringify(pkg, null, 2), 'utf8');
842
813
  let resolverConfig = this.resolverConfig(appFiles);
843
814
  this.addResolverConfig(resolverConfig);
844
- let babelConfig = this.babelConfig(resolverConfig);
815
+ let babelConfig = await this.babelConfig(resolverConfig);
845
816
  this.addBabelConfig(babelConfig);
817
+ (0, fs_extra_1.writeFileSync)((0, path_2.join)(this.root, 'macros-config.json'), JSON.stringify(this.compatApp.macrosConfig.babelPluginConfig()[0], null, 2));
846
818
  }
847
819
  combinePackageJSON(meta) {
848
820
  let pkgLayers = [this.origAppPackage.packageJSON];
@@ -855,7 +827,7 @@ class CompatAppBuilder {
855
827
  pkgLayers.push({ keywords: ['ember-addon'], 'ember-addon': meta });
856
828
  return combinePackageJSON(...pkgLayers);
857
829
  }
858
- etcOptions(resolverConfig) {
830
+ async etcOptions(resolverConfig) {
859
831
  let transforms = this.compatApp.htmlbarsPlugins;
860
832
  let { plugins: macroPlugins, setConfig } = node_1.MacrosConfig.transforms();
861
833
  setConfig(this.compatApp.macrosConfig);
@@ -872,7 +844,7 @@ class CompatAppBuilder {
872
844
  transforms.push([require.resolve('./resolver-transform'), opts]);
873
845
  }
874
846
  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'));
847
+ let resolution = await resolver.nodeResolve('ember-source/vendor/ember/ember-template-compiler', (0, path_1.resolve)(this.root, 'package.json'));
876
848
  if (resolution.type !== 'real') {
877
849
  throw new Error(`bug: unable to resolve ember-template-compiler from ${this.root}`);
878
850
  }
@@ -1014,7 +986,7 @@ class CompatAppBuilder {
1014
986
  let styles = [];
1015
987
  // only import styles from engines with a parent (this excludeds the parent application) as their styles
1016
988
  // will be inserted via a direct <link> tag.
1017
- if (appFiles.engine.parent && appFiles.engine.package.isLazyEngine()) {
989
+ if (!appFiles.engine.isApp && appFiles.engine.package.isLazyEngine()) {
1018
990
  let implicitStyles = this.impliedAssets('implicit-styles', appFiles);
1019
991
  for (let style of implicitStyles) {
1020
992
  styles.push({
@@ -1061,10 +1033,16 @@ class CompatAppBuilder {
1061
1033
  let [fastboot, nonFastboot] = (0, partition_1.default)(excludeDotFiles((0, flatten_1.default)(requiredAppFiles)), file => appFiles.isFastbootOnly.get(file));
1062
1034
  let amdModules = nonFastboot.map(file => this.importPaths(appFiles, file));
1063
1035
  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 };
1036
+ let params = {
1037
+ amdModules,
1038
+ fastbootOnlyAmdModules,
1039
+ lazyRoutes,
1040
+ lazyEngines,
1041
+ eagerModules,
1042
+ styles,
1043
+ // this is a backward-compatibility feature: addons can force inclusion of modules.
1044
+ defineModulesFrom: './-embroider-implicit-modules.js',
1045
+ };
1068
1046
  if (entryParams) {
1069
1047
  Object.assign(params, entryParams);
1070
1048
  }
@@ -1116,9 +1094,6 @@ class CompatAppBuilder {
1116
1094
  (0, core_1.explicitRelative)((0, path_2.dirname)(myName), this.topAppJSAsset(appFiles, prepared).relativePath),
1117
1095
  ];
1118
1096
  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
1097
  for (let relativePath of engine.tests) {
1123
1098
  amdModules.push(this.importPaths(engine, relativePath));
1124
1099
  }
@@ -1126,6 +1101,8 @@ class CompatAppBuilder {
1126
1101
  amdModules,
1127
1102
  eagerModules,
1128
1103
  testSuffix: true,
1104
+ // this is a backward-compatibility feature: addons can force inclusion of test support modules.
1105
+ defineModulesFrom: './-embroider-implicit-test-modules.js',
1129
1106
  });
1130
1107
  asset = {
1131
1108
  kind: 'in-memory',
@@ -1197,6 +1174,15 @@ let d = w.define;
1197
1174
  }
1198
1175
  {{/if}}
1199
1176
 
1177
+ {{#if defineModulesFrom ~}}
1178
+ import implicitModules from "{{js-string-escape defineModulesFrom}}";
1179
+
1180
+ for(const [name, module] of Object.entries(implicitModules)) {
1181
+ d(name, function() { return module });
1182
+ }
1183
+ {{/if}}
1184
+
1185
+
1200
1186
  {{#each eagerModules as |eagerModule| ~}}
1201
1187
  i("{{js-string-escape eagerModule}}");
1202
1188
  {{/each}}
@@ -1207,9 +1193,17 @@ let d = w.define;
1207
1193
 
1208
1194
  {{#if fastbootOnlyAmdModules}}
1209
1195
  if (macroCondition(getGlobalConfig().fastboot?.isRunning)) {
1196
+ let fastbootModules = {};
1197
+
1210
1198
  {{#each fastbootOnlyAmdModules as |amdModule| ~}}
1211
- d("{{js-string-escape amdModule.runtime}}", function(){ return i("{{js-string-escape amdModule.buildtime}}");});
1199
+ fastbootModules["{{js-string-escape amdModule.runtime}}"] = import("{{js-string-escape amdModule.buildtime}}");
1212
1200
  {{/each}}
1201
+
1202
+ const resolvedValues = await Promise.all(Object.values(fastbootModules));
1203
+
1204
+ Object.keys(fastbootModules).forEach((k, i) => {
1205
+ d(k, function(){ return resolvedValues[i];});
1206
+ })
1213
1207
  }
1214
1208
  {{/if}}
1215
1209