@embroider/compat 3.4.7 → 3.4.8-unstable.649e0eb

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"));
@@ -83,22 +82,6 @@ class CompatAppBuilder {
83
82
  }
84
83
  extractAssets(treePaths) {
85
84
  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
85
  // ember-cli traditionally outputs a dummy testem.js file to prevent
103
86
  // spurious errors when running tests under "ember s".
104
87
  if (this.compatApp.shouldBuildTests) {
@@ -177,7 +160,7 @@ class CompatAppBuilder {
177
160
  // For TS, we defer to ember-cli-babel, and the setting for
178
161
  // "enableTypescriptTransform" can be set with and without
179
162
  // ember-cli-typescript
180
- return ['.wasm', '.mjs', '.js', '.json', '.ts', '.hbs', '.hbs.js'];
163
+ return ['.wasm', '.mjs', '.js', '.json', '.ts', '.hbs', '.hbs.js', '.gjs', '.gts'];
181
164
  }
182
165
  *emberEntrypoints(htmlTreePath) {
183
166
  let classicEntrypoints = [
@@ -233,10 +216,6 @@ class CompatAppBuilder {
233
216
  resolverConfig(engines) {
234
217
  let renamePackages = Object.assign({}, ...this.allActiveAddons.map(dep => dep.meta['renamed-packages']));
235
218
  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
219
  let options = {
241
220
  staticHelpers: this.options.staticHelpers,
242
221
  staticModifiers: this.options.staticModifiers,
@@ -245,7 +224,6 @@ class CompatAppBuilder {
245
224
  };
246
225
  let config = {
247
226
  // this part is the base ModuleResolverOptions as required by @embroider/core
248
- activeAddons,
249
227
  renameModules,
250
228
  renamePackages,
251
229
  resolvableExtensions: this.resolvableExtensions(),
@@ -257,14 +235,16 @@ class CompatAppBuilder {
257
235
  root: (0, fs_extra_1.realpathSync)(index === 0 ? this.root : appFiles.engine.package.root),
258
236
  fastbootFiles: appFiles.fastbootFiles,
259
237
  activeAddons: [...appFiles.engine.addons]
260
- .map(a => ({
261
- name: a.name,
262
- root: a.root,
238
+ .map(([addon, canResolveFromFile]) => ({
239
+ name: addon.name,
240
+ root: addon.root,
241
+ canResolveFromFile,
263
242
  }))
264
243
  // the traditional order is the order in which addons will run, such
265
244
  // that the last one wins. Our resolver's order is the order to
266
245
  // search, so first one wins.
267
246
  .reverse(),
247
+ isLazy: appFiles.engine.package.isLazyEngine(),
268
248
  })),
269
249
  amdCompatibility: this.options.amdCompatibility,
270
250
  // this is the additional stufff that @embroider/compat adds on top to do
@@ -317,35 +297,11 @@ class CompatAppBuilder {
317
297
  source: `loader.makeDefaultExport=false;`,
318
298
  });
319
299
  }
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
300
  return result;
345
301
  }
346
302
  impliedAddonAssets(type, { engine }) {
347
303
  let result = [];
348
- for (let addon of (0, sortBy_1.default)(Array.from(engine.addons), this.scriptPriority.bind(this))) {
304
+ for (let addon of (0, sortBy_1.default)(Array.from(engine.addons.keys()), this.scriptPriority.bind(this))) {
349
305
  let implicitScripts = addon.meta[type];
350
306
  if (implicitScripts) {
351
307
  let styles = [];
@@ -368,7 +324,7 @@ class CompatAppBuilder {
368
324
  }
369
325
  return result;
370
326
  }
371
- babelConfig(resolverConfig) {
327
+ async babelConfig(resolverConfig) {
372
328
  let babel = (0, cloneDeep_1.default)(this.compatApp.babelConfig());
373
329
  if (!babel.plugins) {
374
330
  babel.plugins = [];
@@ -378,7 +334,10 @@ class CompatAppBuilder {
378
334
  babel.plugins.push(require.resolve('@babel/plugin-syntax-dynamic-import'));
379
335
  // https://github.com/webpack/webpack/issues/12154
380
336
  babel.plugins.push(require.resolve('./rename-require-plugin'));
381
- babel.plugins.push([require.resolve('babel-plugin-ember-template-compilation'), this.etcOptions(resolverConfig)]);
337
+ babel.plugins.push([
338
+ require.resolve('babel-plugin-ember-template-compilation'),
339
+ await this.etcOptions(resolverConfig),
340
+ ]);
382
341
  // this is @embroider/macros configured for full stage3 resolution
383
342
  babel.plugins.push(...this.compatApp.macrosConfig.babelPluginConfig());
384
343
  let colocationOptions = {
@@ -454,7 +413,7 @@ class CompatAppBuilder {
454
413
  }
455
414
  }
456
415
  html.insertStyleLink(html.styles, `assets/${this.origAppPackage.name}.css`);
457
- const parentEngine = appFiles.find(e => !e.engine.parent);
416
+ const parentEngine = appFiles.find(e => e.engine.isApp);
458
417
  let vendorJS = this.implicitScriptsAsset(prepared, parentEngine, emberENV);
459
418
  if (vendorJS) {
460
419
  html.insertScriptTag(html.implicitScripts, vendorJS.relativePath);
@@ -467,24 +426,17 @@ class CompatAppBuilder {
467
426
  html.insertScriptTag(html.implicitScripts, script, { tag: 'fastboot-script' });
468
427
  }
469
428
  }
470
- let implicitStyles = this.implicitStylesAsset(prepared, parentEngine);
471
- if (implicitStyles) {
472
- html.insertStyleLink(html.implicitStyles, implicitStyles.relativePath);
473
- }
429
+ // virtual vendor.css entrypoint
430
+ html.insertStyleLink(html.implicitStyles, '@embroider/core/vendor.css');
474
431
  if (!asset.fileAsset.includeTests) {
475
432
  return;
476
433
  }
477
434
  // Test-related assets happen below this point
478
435
  let testJS = this.testJSEntrypoint(appFiles, prepared);
479
436
  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
- }
437
+ // virtual test-support.js
438
+ html.insertScriptTag(html.implicitTestScripts, '@embroider/core/test-support.js');
439
+ html.insertStyleLink(html.implicitTestStyles, '@embroider/core/test-support.css');
488
440
  }
489
441
  implicitScriptsAsset(prepared, application, emberENV) {
490
442
  let asset = prepared.get('assets/vendor.js');
@@ -497,40 +449,6 @@ class CompatAppBuilder {
497
449
  }
498
450
  return asset;
499
451
  }
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
452
  // recurse to find all active addons that don't cross an engine boundary.
535
453
  // Inner engines themselves will be returned, but not those engines' children.
536
454
  // The output set's insertion order is the proper ember-cli compatible
@@ -540,22 +458,31 @@ class CompatAppBuilder {
540
458
  if (!child.isEngine()) {
541
459
  this.findActiveAddons(child, engine, true);
542
460
  }
543
- engine.addons.add(child);
461
+ let canResolveFrom;
462
+ if (pkg === this.appPackageWithMovedDeps) {
463
+ // we want canResolveFrom to always be a rewritten package path, and our
464
+ // app's package is not rewritten yet here.
465
+ canResolveFrom = (0, path_1.resolve)(this.root, 'package.json');
466
+ }
467
+ else {
468
+ // whereas our addons are already moved
469
+ canResolveFrom = (0, path_1.resolve)(pkg.root, 'package.json');
470
+ }
471
+ engine.addons.set(child, canResolveFrom);
544
472
  }
545
473
  // ensure addons are applied in the correct order, if set (via @embroider/compat/v1-addon)
546
474
  if (!isChild) {
547
- engine.addons = new Set([...engine.addons].sort((a, b) => {
475
+ engine.addons = new Map([...engine.addons].sort(([a], [b]) => {
548
476
  return (a.meta['order-index'] || 0) - (b.meta['order-index'] || 0);
549
477
  }));
550
478
  }
551
479
  }
552
- partitionEngines(appJSPath) {
480
+ partitionEngines() {
553
481
  let queue = [
554
482
  {
555
483
  package: this.appPackageWithMovedDeps,
556
- addons: new Set(),
557
- parent: undefined,
558
- sourcePath: appJSPath,
484
+ addons: new Map(),
485
+ isApp: true,
559
486
  modulePrefix: this.modulePrefix(),
560
487
  appRelativePath: '.',
561
488
  },
@@ -568,14 +495,13 @@ class CompatAppBuilder {
568
495
  break;
569
496
  }
570
497
  this.findActiveAddons(current.package, current);
571
- for (let addon of current.addons) {
498
+ for (let addon of current.addons.keys()) {
572
499
  if (addon.isEngine() && !seenEngines.has(addon)) {
573
500
  seenEngines.add(addon);
574
501
  queue.push({
575
502
  package: addon,
576
- addons: new Set(),
577
- parent: current,
578
- sourcePath: addon.root,
503
+ addons: new Map(),
504
+ isApp: !current,
579
505
  modulePrefix: addon.name,
580
506
  appRelativePath: (0, core_1.explicitRelative)(this.root, addon.root),
581
507
  });
@@ -601,8 +527,8 @@ class CompatAppBuilder {
601
527
  updateAppJS(appJSPath) {
602
528
  var _a;
603
529
  if (!this.engines) {
604
- this.engines = this.partitionEngines(appJSPath).map(engine => {
605
- if (engine.sourcePath === appJSPath) {
530
+ this.engines = this.partitionEngines().map(engine => {
531
+ if (engine.isApp) {
606
532
  // this is the app. We have more to do for the app than for other
607
533
  // engines.
608
534
  let fastbootSync;
@@ -624,7 +550,7 @@ class CompatAppBuilder {
624
550
  // their files, not doing any actual copying or building.
625
551
  return {
626
552
  engine,
627
- appSync: new sync_dir_1.SyncDir(engine.sourcePath, undefined),
553
+ appSync: new sync_dir_1.SyncDir(engine.package.root, undefined),
628
554
  // AFAIK, we've never supported a fastboot overlay directory in an
629
555
  // engine. But if we do need that, it would go here.
630
556
  fastbootSync: undefined,
@@ -764,19 +690,18 @@ class CompatAppBuilder {
764
690
  gatherAssets(inputPaths) {
765
691
  // first gather all the assets out of addons
766
692
  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
- }
693
+ let pkg = this.allActiveAddons.find(pkg => pkg.name === '@embroider/synthesized-styles');
694
+ if (pkg === null || pkg === void 0 ? void 0 : pkg.meta['public-assets']) {
695
+ for (let [filename, appRelativeURL] of Object.entries(pkg.meta['public-assets'] || {})) {
696
+ let sourcePath = (0, path_1.resolve)(pkg.root, filename);
697
+ let stats = (0, fs_extra_1.statSync)(sourcePath);
698
+ assets.push({
699
+ kind: 'on-disk',
700
+ sourcePath,
701
+ relativePath: appRelativeURL,
702
+ mtime: stats.mtimeMs,
703
+ size: stats.size,
704
+ });
780
705
  }
781
706
  }
782
707
  if (this.activeFastboot) {
@@ -841,8 +766,9 @@ class CompatAppBuilder {
841
766
  (0, fs_extra_1.writeFileSync)((0, path_2.join)(this.root, 'package.json'), JSON.stringify(pkg, null, 2), 'utf8');
842
767
  let resolverConfig = this.resolverConfig(appFiles);
843
768
  this.addResolverConfig(resolverConfig);
844
- let babelConfig = this.babelConfig(resolverConfig);
769
+ let babelConfig = await this.babelConfig(resolverConfig);
845
770
  this.addBabelConfig(babelConfig);
771
+ (0, fs_extra_1.writeFileSync)((0, path_2.join)(this.root, 'macros-config.json'), JSON.stringify(this.compatApp.macrosConfig.babelPluginConfig()[0], null, 2));
846
772
  }
847
773
  combinePackageJSON(meta) {
848
774
  let pkgLayers = [this.origAppPackage.packageJSON];
@@ -855,7 +781,7 @@ class CompatAppBuilder {
855
781
  pkgLayers.push({ keywords: ['ember-addon'], 'ember-addon': meta });
856
782
  return combinePackageJSON(...pkgLayers);
857
783
  }
858
- etcOptions(resolverConfig) {
784
+ async etcOptions(resolverConfig) {
859
785
  let transforms = this.compatApp.htmlbarsPlugins;
860
786
  let { plugins: macroPlugins, setConfig } = node_1.MacrosConfig.transforms();
861
787
  setConfig(this.compatApp.macrosConfig);
@@ -872,7 +798,7 @@ class CompatAppBuilder {
872
798
  transforms.push([require.resolve('./resolver-transform'), opts]);
873
799
  }
874
800
  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'));
801
+ let resolution = await resolver.nodeResolve('ember-source/vendor/ember/ember-template-compiler', (0, path_1.resolve)(this.root, 'package.json'));
876
802
  if (resolution.type !== 'real') {
877
803
  throw new Error(`bug: unable to resolve ember-template-compiler from ${this.root}`);
878
804
  }
@@ -1014,7 +940,7 @@ class CompatAppBuilder {
1014
940
  let styles = [];
1015
941
  // only import styles from engines with a parent (this excludeds the parent application) as their styles
1016
942
  // will be inserted via a direct <link> tag.
1017
- if (appFiles.engine.parent && appFiles.engine.package.isLazyEngine()) {
943
+ if (!appFiles.engine.isApp && appFiles.engine.package.isLazyEngine()) {
1018
944
  let implicitStyles = this.impliedAssets('implicit-styles', appFiles);
1019
945
  for (let style of implicitStyles) {
1020
946
  styles.push({
@@ -1061,10 +987,16 @@ class CompatAppBuilder {
1061
987
  let [fastboot, nonFastboot] = (0, partition_1.default)(excludeDotFiles((0, flatten_1.default)(requiredAppFiles)), file => appFiles.isFastbootOnly.get(file));
1062
988
  let amdModules = nonFastboot.map(file => this.importPaths(appFiles, file));
1063
989
  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 };
990
+ let params = {
991
+ amdModules,
992
+ fastbootOnlyAmdModules,
993
+ lazyRoutes,
994
+ lazyEngines,
995
+ eagerModules,
996
+ styles,
997
+ // this is a backward-compatibility feature: addons can force inclusion of modules.
998
+ defineModulesFrom: './-embroider-implicit-modules.js',
999
+ };
1068
1000
  if (entryParams) {
1069
1001
  Object.assign(params, entryParams);
1070
1002
  }
@@ -1116,9 +1048,6 @@ class CompatAppBuilder {
1116
1048
  (0, core_1.explicitRelative)((0, path_2.dirname)(myName), this.topAppJSAsset(appFiles, prepared).relativePath),
1117
1049
  ];
1118
1050
  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
1051
  for (let relativePath of engine.tests) {
1123
1052
  amdModules.push(this.importPaths(engine, relativePath));
1124
1053
  }
@@ -1126,6 +1055,8 @@ class CompatAppBuilder {
1126
1055
  amdModules,
1127
1056
  eagerModules,
1128
1057
  testSuffix: true,
1058
+ // this is a backward-compatibility feature: addons can force inclusion of test support modules.
1059
+ defineModulesFrom: './-embroider-implicit-test-modules.js',
1129
1060
  });
1130
1061
  asset = {
1131
1062
  kind: 'in-memory',
@@ -1197,6 +1128,15 @@ let d = w.define;
1197
1128
  }
1198
1129
  {{/if}}
1199
1130
 
1131
+ {{#if defineModulesFrom ~}}
1132
+ import implicitModules from "{{js-string-escape defineModulesFrom}}";
1133
+
1134
+ for(const [name, module] of Object.entries(implicitModules)) {
1135
+ d(name, function() { return module });
1136
+ }
1137
+ {{/if}}
1138
+
1139
+
1200
1140
  {{#each eagerModules as |eagerModule| ~}}
1201
1141
  i("{{js-string-escape eagerModule}}");
1202
1142
  {{/each}}
@@ -1207,9 +1147,17 @@ let d = w.define;
1207
1147
 
1208
1148
  {{#if fastbootOnlyAmdModules}}
1209
1149
  if (macroCondition(getGlobalConfig().fastboot?.isRunning)) {
1150
+ let fastbootModules = {};
1151
+
1210
1152
  {{#each fastbootOnlyAmdModules as |amdModule| ~}}
1211
- d("{{js-string-escape amdModule.runtime}}", function(){ return i("{{js-string-escape amdModule.buildtime}}");});
1153
+ fastbootModules["{{js-string-escape amdModule.runtime}}"] = import("{{js-string-escape amdModule.buildtime}}");
1212
1154
  {{/each}}
1155
+
1156
+ const resolvedValues = await Promise.all(Object.values(fastbootModules));
1157
+
1158
+ Object.keys(fastbootModules).forEach((k, i) => {
1159
+ d(k, function(){ return resolvedValues[i];});
1160
+ })
1213
1161
  }
1214
1162
  {{/if}}
1215
1163