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