@embroider/compat 3.4.7 → 3.4.8-unstable.80f442d

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);
@@ -467,24 +443,17 @@ class CompatAppBuilder {
467
443
  html.insertScriptTag(html.implicitScripts, script, { tag: 'fastboot-script' });
468
444
  }
469
445
  }
470
- let implicitStyles = this.implicitStylesAsset(prepared, parentEngine);
471
- if (implicitStyles) {
472
- html.insertStyleLink(html.implicitStyles, implicitStyles.relativePath);
473
- }
446
+ // virtual vendor.css entrypoint
447
+ html.insertStyleLink(html.implicitStyles, '@embroider/core/vendor.css');
474
448
  if (!asset.fileAsset.includeTests) {
475
449
  return;
476
450
  }
477
451
  // Test-related assets happen below this point
478
452
  let testJS = this.testJSEntrypoint(appFiles, prepared);
479
453
  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
- }
454
+ // virtual test-support.js
455
+ html.insertScriptTag(html.implicitTestScripts, '@embroider/core/test-support.js');
456
+ html.insertStyleLink(html.implicitTestStyles, '@embroider/core/test-support.css');
488
457
  }
489
458
  implicitScriptsAsset(prepared, application, emberENV) {
490
459
  let asset = prepared.get('assets/vendor.js');
@@ -497,40 +466,6 @@ class CompatAppBuilder {
497
466
  }
498
467
  return asset;
499
468
  }
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
469
  // recurse to find all active addons that don't cross an engine boundary.
535
470
  // Inner engines themselves will be returned, but not those engines' children.
536
471
  // The output set's insertion order is the proper ember-cli compatible
@@ -540,22 +475,31 @@ class CompatAppBuilder {
540
475
  if (!child.isEngine()) {
541
476
  this.findActiveAddons(child, engine, true);
542
477
  }
543
- engine.addons.add(child);
478
+ let canResolveFrom;
479
+ if (pkg === this.appPackageWithMovedDeps) {
480
+ // we want canResolveFrom to always be a rewritten package path, and our
481
+ // app's package is not rewritten yet here.
482
+ canResolveFrom = (0, path_1.resolve)(this.root, 'package.json');
483
+ }
484
+ else {
485
+ // whereas our addons are already moved
486
+ canResolveFrom = (0, path_1.resolve)(pkg.root, 'package.json');
487
+ }
488
+ engine.addons.set(child, canResolveFrom);
544
489
  }
545
490
  // ensure addons are applied in the correct order, if set (via @embroider/compat/v1-addon)
546
491
  if (!isChild) {
547
- engine.addons = new Set([...engine.addons].sort((a, b) => {
492
+ engine.addons = new Map([...engine.addons].sort(([a], [b]) => {
548
493
  return (a.meta['order-index'] || 0) - (b.meta['order-index'] || 0);
549
494
  }));
550
495
  }
551
496
  }
552
- partitionEngines(appJSPath) {
497
+ partitionEngines() {
553
498
  let queue = [
554
499
  {
555
500
  package: this.appPackageWithMovedDeps,
556
- addons: new Set(),
557
- parent: undefined,
558
- sourcePath: appJSPath,
501
+ addons: new Map(),
502
+ isApp: true,
559
503
  modulePrefix: this.modulePrefix(),
560
504
  appRelativePath: '.',
561
505
  },
@@ -568,14 +512,13 @@ class CompatAppBuilder {
568
512
  break;
569
513
  }
570
514
  this.findActiveAddons(current.package, current);
571
- for (let addon of current.addons) {
515
+ for (let addon of current.addons.keys()) {
572
516
  if (addon.isEngine() && !seenEngines.has(addon)) {
573
517
  seenEngines.add(addon);
574
518
  queue.push({
575
519
  package: addon,
576
- addons: new Set(),
577
- parent: current,
578
- sourcePath: addon.root,
520
+ addons: new Map(),
521
+ isApp: !current,
579
522
  modulePrefix: addon.name,
580
523
  appRelativePath: (0, core_1.explicitRelative)(this.root, addon.root),
581
524
  });
@@ -601,8 +544,8 @@ class CompatAppBuilder {
601
544
  updateAppJS(appJSPath) {
602
545
  var _a;
603
546
  if (!this.engines) {
604
- this.engines = this.partitionEngines(appJSPath).map(engine => {
605
- if (engine.sourcePath === appJSPath) {
547
+ this.engines = this.partitionEngines().map(engine => {
548
+ if (engine.isApp) {
606
549
  // this is the app. We have more to do for the app than for other
607
550
  // engines.
608
551
  let fastbootSync;
@@ -624,7 +567,7 @@ class CompatAppBuilder {
624
567
  // their files, not doing any actual copying or building.
625
568
  return {
626
569
  engine,
627
- appSync: new sync_dir_1.SyncDir(engine.sourcePath, undefined),
570
+ appSync: new sync_dir_1.SyncDir(engine.package.root, undefined),
628
571
  // AFAIK, we've never supported a fastboot overlay directory in an
629
572
  // engine. But if we do need that, it would go here.
630
573
  fastbootSync: undefined,
@@ -841,8 +784,9 @@ class CompatAppBuilder {
841
784
  (0, fs_extra_1.writeFileSync)((0, path_2.join)(this.root, 'package.json'), JSON.stringify(pkg, null, 2), 'utf8');
842
785
  let resolverConfig = this.resolverConfig(appFiles);
843
786
  this.addResolverConfig(resolverConfig);
844
- let babelConfig = this.babelConfig(resolverConfig);
787
+ let babelConfig = await this.babelConfig(resolverConfig);
845
788
  this.addBabelConfig(babelConfig);
789
+ (0, fs_extra_1.writeFileSync)((0, path_2.join)(this.root, 'macros-config.json'), JSON.stringify(this.compatApp.macrosConfig.babelPluginConfig()[0], null, 2));
846
790
  }
847
791
  combinePackageJSON(meta) {
848
792
  let pkgLayers = [this.origAppPackage.packageJSON];
@@ -855,7 +799,7 @@ class CompatAppBuilder {
855
799
  pkgLayers.push({ keywords: ['ember-addon'], 'ember-addon': meta });
856
800
  return combinePackageJSON(...pkgLayers);
857
801
  }
858
- etcOptions(resolverConfig) {
802
+ async etcOptions(resolverConfig) {
859
803
  let transforms = this.compatApp.htmlbarsPlugins;
860
804
  let { plugins: macroPlugins, setConfig } = node_1.MacrosConfig.transforms();
861
805
  setConfig(this.compatApp.macrosConfig);
@@ -872,7 +816,7 @@ class CompatAppBuilder {
872
816
  transforms.push([require.resolve('./resolver-transform'), opts]);
873
817
  }
874
818
  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'));
819
+ let resolution = await resolver.nodeResolve('ember-source/vendor/ember/ember-template-compiler', (0, path_1.resolve)(this.root, 'package.json'));
876
820
  if (resolution.type !== 'real') {
877
821
  throw new Error(`bug: unable to resolve ember-template-compiler from ${this.root}`);
878
822
  }
@@ -1014,7 +958,7 @@ class CompatAppBuilder {
1014
958
  let styles = [];
1015
959
  // only import styles from engines with a parent (this excludeds the parent application) as their styles
1016
960
  // will be inserted via a direct <link> tag.
1017
- if (appFiles.engine.parent && appFiles.engine.package.isLazyEngine()) {
961
+ if (!appFiles.engine.isApp && appFiles.engine.package.isLazyEngine()) {
1018
962
  let implicitStyles = this.impliedAssets('implicit-styles', appFiles);
1019
963
  for (let style of implicitStyles) {
1020
964
  styles.push({
@@ -1061,10 +1005,16 @@ class CompatAppBuilder {
1061
1005
  let [fastboot, nonFastboot] = (0, partition_1.default)(excludeDotFiles((0, flatten_1.default)(requiredAppFiles)), file => appFiles.isFastbootOnly.get(file));
1062
1006
  let amdModules = nonFastboot.map(file => this.importPaths(appFiles, file));
1063
1007
  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 };
1008
+ let params = {
1009
+ amdModules,
1010
+ fastbootOnlyAmdModules,
1011
+ lazyRoutes,
1012
+ lazyEngines,
1013
+ eagerModules,
1014
+ styles,
1015
+ // this is a backward-compatibility feature: addons can force inclusion of modules.
1016
+ defineModulesFrom: './-embroider-implicit-modules.js',
1017
+ };
1068
1018
  if (entryParams) {
1069
1019
  Object.assign(params, entryParams);
1070
1020
  }
@@ -1116,9 +1066,6 @@ class CompatAppBuilder {
1116
1066
  (0, core_1.explicitRelative)((0, path_2.dirname)(myName), this.topAppJSAsset(appFiles, prepared).relativePath),
1117
1067
  ];
1118
1068
  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
1069
  for (let relativePath of engine.tests) {
1123
1070
  amdModules.push(this.importPaths(engine, relativePath));
1124
1071
  }
@@ -1126,6 +1073,8 @@ class CompatAppBuilder {
1126
1073
  amdModules,
1127
1074
  eagerModules,
1128
1075
  testSuffix: true,
1076
+ // this is a backward-compatibility feature: addons can force inclusion of test support modules.
1077
+ defineModulesFrom: './-embroider-implicit-test-modules.js',
1129
1078
  });
1130
1079
  asset = {
1131
1080
  kind: 'in-memory',
@@ -1197,6 +1146,15 @@ let d = w.define;
1197
1146
  }
1198
1147
  {{/if}}
1199
1148
 
1149
+ {{#if defineModulesFrom ~}}
1150
+ import implicitModules from "{{js-string-escape defineModulesFrom}}";
1151
+
1152
+ for(const [name, module] of Object.entries(implicitModules)) {
1153
+ d(name, function() { return module });
1154
+ }
1155
+ {{/if}}
1156
+
1157
+
1200
1158
  {{#each eagerModules as |eagerModule| ~}}
1201
1159
  i("{{js-string-escape eagerModule}}");
1202
1160
  {{/each}}
@@ -1207,9 +1165,17 @@ let d = w.define;
1207
1165
 
1208
1166
  {{#if fastbootOnlyAmdModules}}
1209
1167
  if (macroCondition(getGlobalConfig().fastboot?.isRunning)) {
1168
+ let fastbootModules = {};
1169
+
1210
1170
  {{#each fastbootOnlyAmdModules as |amdModule| ~}}
1211
- d("{{js-string-escape amdModule.runtime}}", function(){ return i("{{js-string-escape amdModule.buildtime}}");});
1171
+ fastbootModules["{{js-string-escape amdModule.runtime}}"] = import("{{js-string-escape amdModule.buildtime}}");
1212
1172
  {{/each}}
1173
+
1174
+ const resolvedValues = await Promise.all(Object.values(fastbootModules));
1175
+
1176
+ Object.keys(fastbootModules).forEach((k, i) => {
1177
+ d(k, function(){ return resolvedValues[i];});
1178
+ })
1213
1179
  }
1214
1180
  {{/if}}
1215
1181