@embroider/compat 3.4.8-unstable.fad2387 → 3.4.8

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