@embroider/compat 3.4.5 → 3.4.6-unstable.35f9ecd

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
@@ -345,7 +342,7 @@ class CompatAppBuilder {
345
342
  }
346
343
  impliedAddonAssets(type, { engine }) {
347
344
  let result = [];
348
- for (let addon of (0, sortBy_1.default)(Array.from(engine.addons), this.scriptPriority.bind(this))) {
345
+ for (let addon of (0, sortBy_1.default)(Array.from(engine.addons.keys()), this.scriptPriority.bind(this))) {
349
346
  let implicitScripts = addon.meta[type];
350
347
  if (implicitScripts) {
351
348
  let styles = [];
@@ -368,7 +365,7 @@ class CompatAppBuilder {
368
365
  }
369
366
  return result;
370
367
  }
371
- babelConfig(resolverConfig) {
368
+ async babelConfig(resolverConfig) {
372
369
  let babel = (0, cloneDeep_1.default)(this.compatApp.babelConfig());
373
370
  if (!babel.plugins) {
374
371
  babel.plugins = [];
@@ -378,7 +375,10 @@ class CompatAppBuilder {
378
375
  babel.plugins.push(require.resolve('@babel/plugin-syntax-dynamic-import'));
379
376
  // https://github.com/webpack/webpack/issues/12154
380
377
  babel.plugins.push(require.resolve('./rename-require-plugin'));
381
- babel.plugins.push([require.resolve('babel-plugin-ember-template-compilation'), this.etcOptions(resolverConfig)]);
378
+ babel.plugins.push([
379
+ require.resolve('babel-plugin-ember-template-compilation'),
380
+ await this.etcOptions(resolverConfig),
381
+ ]);
382
382
  // this is @embroider/macros configured for full stage3 resolution
383
383
  babel.plugins.push(...this.compatApp.macrosConfig.babelPluginConfig());
384
384
  let colocationOptions = {
@@ -454,7 +454,7 @@ class CompatAppBuilder {
454
454
  }
455
455
  }
456
456
  html.insertStyleLink(html.styles, `assets/${this.origAppPackage.name}.css`);
457
- const parentEngine = appFiles.find(e => !e.engine.parent);
457
+ const parentEngine = appFiles.find(e => e.engine.isApp);
458
458
  let vendorJS = this.implicitScriptsAsset(prepared, parentEngine, emberENV);
459
459
  if (vendorJS) {
460
460
  html.insertScriptTag(html.implicitScripts, vendorJS.relativePath);
@@ -540,22 +540,31 @@ class CompatAppBuilder {
540
540
  if (!child.isEngine()) {
541
541
  this.findActiveAddons(child, engine, true);
542
542
  }
543
- engine.addons.add(child);
543
+ let canResolveFrom;
544
+ if (pkg === this.appPackageWithMovedDeps) {
545
+ // we want canResolveFrom to always be a rewritten package path, and our
546
+ // app's package is not rewritten yet here.
547
+ canResolveFrom = (0, path_1.resolve)(this.root, 'package.json');
548
+ }
549
+ else {
550
+ // whereas our addons are already moved
551
+ canResolveFrom = (0, path_1.resolve)(pkg.root, 'package.json');
552
+ }
553
+ engine.addons.set(child, canResolveFrom);
544
554
  }
545
555
  // ensure addons are applied in the correct order, if set (via @embroider/compat/v1-addon)
546
556
  if (!isChild) {
547
- engine.addons = new Set([...engine.addons].sort((a, b) => {
557
+ engine.addons = new Map([...engine.addons].sort(([a], [b]) => {
548
558
  return (a.meta['order-index'] || 0) - (b.meta['order-index'] || 0);
549
559
  }));
550
560
  }
551
561
  }
552
- partitionEngines(appJSPath) {
562
+ partitionEngines() {
553
563
  let queue = [
554
564
  {
555
565
  package: this.appPackageWithMovedDeps,
556
- addons: new Set(),
557
- parent: undefined,
558
- sourcePath: appJSPath,
566
+ addons: new Map(),
567
+ isApp: true,
559
568
  modulePrefix: this.modulePrefix(),
560
569
  appRelativePath: '.',
561
570
  },
@@ -568,14 +577,13 @@ class CompatAppBuilder {
568
577
  break;
569
578
  }
570
579
  this.findActiveAddons(current.package, current);
571
- for (let addon of current.addons) {
580
+ for (let addon of current.addons.keys()) {
572
581
  if (addon.isEngine() && !seenEngines.has(addon)) {
573
582
  seenEngines.add(addon);
574
583
  queue.push({
575
584
  package: addon,
576
- addons: new Set(),
577
- parent: current,
578
- sourcePath: addon.root,
585
+ addons: new Map(),
586
+ isApp: !current,
579
587
  modulePrefix: addon.name,
580
588
  appRelativePath: (0, core_1.explicitRelative)(this.root, addon.root),
581
589
  });
@@ -601,8 +609,8 @@ class CompatAppBuilder {
601
609
  updateAppJS(appJSPath) {
602
610
  var _a;
603
611
  if (!this.engines) {
604
- this.engines = this.partitionEngines(appJSPath).map(engine => {
605
- if (engine.sourcePath === appJSPath) {
612
+ this.engines = this.partitionEngines().map(engine => {
613
+ if (engine.isApp) {
606
614
  // this is the app. We have more to do for the app than for other
607
615
  // engines.
608
616
  let fastbootSync;
@@ -624,7 +632,7 @@ class CompatAppBuilder {
624
632
  // their files, not doing any actual copying or building.
625
633
  return {
626
634
  engine,
627
- appSync: new sync_dir_1.SyncDir(engine.sourcePath, undefined),
635
+ appSync: new sync_dir_1.SyncDir(engine.package.root, undefined),
628
636
  // AFAIK, we've never supported a fastboot overlay directory in an
629
637
  // engine. But if we do need that, it would go here.
630
638
  fastbootSync: undefined,
@@ -841,8 +849,9 @@ class CompatAppBuilder {
841
849
  (0, fs_extra_1.writeFileSync)((0, path_2.join)(this.root, 'package.json'), JSON.stringify(pkg, null, 2), 'utf8');
842
850
  let resolverConfig = this.resolverConfig(appFiles);
843
851
  this.addResolverConfig(resolverConfig);
844
- let babelConfig = this.babelConfig(resolverConfig);
852
+ let babelConfig = await this.babelConfig(resolverConfig);
845
853
  this.addBabelConfig(babelConfig);
854
+ (0, fs_extra_1.writeFileSync)((0, path_2.join)(this.root, 'macros-config.json'), JSON.stringify(this.compatApp.macrosConfig.babelPluginConfig()[0], null, 2));
846
855
  }
847
856
  combinePackageJSON(meta) {
848
857
  let pkgLayers = [this.origAppPackage.packageJSON];
@@ -855,7 +864,7 @@ class CompatAppBuilder {
855
864
  pkgLayers.push({ keywords: ['ember-addon'], 'ember-addon': meta });
856
865
  return combinePackageJSON(...pkgLayers);
857
866
  }
858
- etcOptions(resolverConfig) {
867
+ async etcOptions(resolverConfig) {
859
868
  let transforms = this.compatApp.htmlbarsPlugins;
860
869
  let { plugins: macroPlugins, setConfig } = node_1.MacrosConfig.transforms();
861
870
  setConfig(this.compatApp.macrosConfig);
@@ -872,7 +881,7 @@ class CompatAppBuilder {
872
881
  transforms.push([require.resolve('./resolver-transform'), opts]);
873
882
  }
874
883
  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'));
884
+ let resolution = await resolver.nodeResolve('ember-source/vendor/ember/ember-template-compiler', (0, path_1.resolve)(this.root, 'package.json'));
876
885
  if (resolution.type !== 'real') {
877
886
  throw new Error(`bug: unable to resolve ember-template-compiler from ${this.root}`);
878
887
  }
@@ -1014,7 +1023,7 @@ class CompatAppBuilder {
1014
1023
  let styles = [];
1015
1024
  // only import styles from engines with a parent (this excludeds the parent application) as their styles
1016
1025
  // will be inserted via a direct <link> tag.
1017
- if (appFiles.engine.parent && appFiles.engine.package.isLazyEngine()) {
1026
+ if (!appFiles.engine.isApp && appFiles.engine.package.isLazyEngine()) {
1018
1027
  let implicitStyles = this.impliedAssets('implicit-styles', appFiles);
1019
1028
  for (let style of implicitStyles) {
1020
1029
  styles.push({
@@ -1061,10 +1070,16 @@ class CompatAppBuilder {
1061
1070
  let [fastboot, nonFastboot] = (0, partition_1.default)(excludeDotFiles((0, flatten_1.default)(requiredAppFiles)), file => appFiles.isFastbootOnly.get(file));
1062
1071
  let amdModules = nonFastboot.map(file => this.importPaths(appFiles, file));
1063
1072
  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 };
1073
+ let params = {
1074
+ amdModules,
1075
+ fastbootOnlyAmdModules,
1076
+ lazyRoutes,
1077
+ lazyEngines,
1078
+ eagerModules,
1079
+ styles,
1080
+ // this is a backward-compatibility feature: addons can force inclusion of modules.
1081
+ defineModulesFrom: './-embroider-implicit-modules.js',
1082
+ };
1068
1083
  if (entryParams) {
1069
1084
  Object.assign(params, entryParams);
1070
1085
  }
@@ -1116,9 +1131,6 @@ class CompatAppBuilder {
1116
1131
  (0, core_1.explicitRelative)((0, path_2.dirname)(myName), this.topAppJSAsset(appFiles, prepared).relativePath),
1117
1132
  ];
1118
1133
  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
1134
  for (let relativePath of engine.tests) {
1123
1135
  amdModules.push(this.importPaths(engine, relativePath));
1124
1136
  }
@@ -1126,6 +1138,8 @@ class CompatAppBuilder {
1126
1138
  amdModules,
1127
1139
  eagerModules,
1128
1140
  testSuffix: true,
1141
+ // this is a backward-compatibility feature: addons can force inclusion of test support modules.
1142
+ defineModulesFrom: './-embroider-implicit-test-modules.js',
1129
1143
  });
1130
1144
  asset = {
1131
1145
  kind: 'in-memory',
@@ -1197,6 +1211,15 @@ let d = w.define;
1197
1211
  }
1198
1212
  {{/if}}
1199
1213
 
1214
+ {{#if defineModulesFrom ~}}
1215
+ import implicitModules from "{{js-string-escape defineModulesFrom}}";
1216
+
1217
+ for(const [name, module] of Object.entries(implicitModules)) {
1218
+ d(name, function() { return module });
1219
+ }
1220
+ {{/if}}
1221
+
1222
+
1200
1223
  {{#each eagerModules as |eagerModule| ~}}
1201
1224
  i("{{js-string-escape eagerModule}}");
1202
1225
  {{/each}}
@@ -1207,9 +1230,17 @@ let d = w.define;
1207
1230
 
1208
1231
  {{#if fastbootOnlyAmdModules}}
1209
1232
  if (macroCondition(getGlobalConfig().fastboot?.isRunning)) {
1233
+ let fastbootModules = {};
1234
+
1210
1235
  {{#each fastbootOnlyAmdModules as |amdModule| ~}}
1211
- d("{{js-string-escape amdModule.runtime}}", function(){ return i("{{js-string-escape amdModule.buildtime}}");});
1236
+ fastbootModules["{{js-string-escape amdModule.runtime}}"] = import("{{js-string-escape amdModule.buildtime}}");
1212
1237
  {{/each}}
1238
+
1239
+ const resolvedValues = await Promise.all(Object.values(fastbootModules));
1240
+
1241
+ Object.keys(fastbootModules).forEach((k, i) => {
1242
+ d(k, function(){ return resolvedValues[i];});
1243
+ })
1213
1244
  }
1214
1245
  {{/if}}
1215
1246