@embroider/compat 3.8.1-unstable.fc482ba → 3.8.1

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.
Files changed (97) hide show
  1. package/package.json +17 -15
  2. package/src/audit/babel-visitor.js +1 -7
  3. package/src/audit/babel-visitor.js.map +1 -1
  4. package/src/audit/build.js.map +1 -1
  5. package/src/audit/options.d.ts +1 -2
  6. package/src/audit/options.js.map +1 -1
  7. package/src/audit-cli.d.ts +2 -0
  8. package/src/audit-cli.js +150 -0
  9. package/src/audit-cli.js.map +1 -0
  10. package/src/audit.d.ts +57 -7
  11. package/src/audit.js +301 -101
  12. package/src/audit.js.map +1 -1
  13. package/src/babel-plugin-adjust-imports.js +18 -19
  14. package/src/babel-plugin-adjust-imports.js.map +1 -1
  15. package/src/compat-adapters/@ember-data/debug.d.ts +6 -0
  16. package/src/compat-adapters/@ember-data/debug.js +22 -0
  17. package/src/compat-adapters/@ember-data/debug.js.map +1 -0
  18. package/src/compat-adapters/@ember-data/store.d.ts +5 -1
  19. package/src/compat-adapters/@ember-data/store.js +15 -3
  20. package/src/compat-adapters/@ember-data/store.js.map +1 -1
  21. package/src/compat-adapters/active-model-adapter.d.ts +1 -1
  22. package/src/compat-adapters/ember-asset-loader.d.ts +1 -1
  23. package/src/compat-adapters/ember-cli-addon-docs.d.ts +1 -1
  24. package/src/compat-adapters/ember-cli-fastboot.js +1 -0
  25. package/src/compat-adapters/ember-cli-fastboot.js.map +1 -1
  26. package/src/compat-adapters/ember-cli-mirage.js +1 -0
  27. package/src/compat-adapters/ember-cli-mirage.js.map +1 -1
  28. package/src/compat-adapters/ember-decorators.d.ts +1 -1
  29. package/src/compat-adapters/ember-macro-helpers.d.ts +4 -0
  30. package/src/compat-adapters/{ember-fetch.js → ember-macro-helpers.js} +4 -5
  31. package/src/compat-adapters/ember-macro-helpers.js.map +1 -0
  32. package/src/compat-adapters/ember-percy.d.ts +1 -1
  33. package/src/compat-adapters/ember-scroll-modifiers.d.ts +1 -1
  34. package/src/compat-adapters/ember-source.d.ts +6 -3
  35. package/src/compat-adapters/ember-source.js +41 -26
  36. package/src/compat-adapters/ember-source.js.map +1 -1
  37. package/src/compat-adapters/ember-test-selectors.d.ts +1 -1
  38. package/src/compat-addons.js +1 -1
  39. package/src/compat-addons.js.map +1 -1
  40. package/src/compat-app-builder.d.ts +64 -9
  41. package/src/compat-app-builder.js +1272 -110
  42. package/src/compat-app-builder.js.map +1 -1
  43. package/src/compat-app.d.ts +22 -4
  44. package/src/compat-app.js +218 -77
  45. package/src/compat-app.js.map +1 -1
  46. package/src/default-pipeline.d.ts +5 -4
  47. package/src/default-pipeline.js +46 -21
  48. package/src/default-pipeline.js.map +1 -1
  49. package/src/dependency-rules.d.ts +0 -1
  50. package/src/dependency-rules.js +11 -19
  51. package/src/dependency-rules.js.map +1 -1
  52. package/src/detect-babel-plugins.d.ts +0 -1
  53. package/src/detect-babel-plugins.js +0 -14
  54. package/src/detect-babel-plugins.js.map +1 -1
  55. package/src/index.d.ts +2 -2
  56. package/src/index.js +4 -3
  57. package/src/index.js.map +1 -1
  58. package/src/options.d.ts +40 -3
  59. package/src/options.js +11 -3
  60. package/src/options.js.map +1 -1
  61. package/src/rename-require-plugin.d.ts +1 -0
  62. package/src/rename-require-plugin.js +15 -0
  63. package/src/rename-require-plugin.js.map +1 -0
  64. package/src/resolver-transform.js +15 -56
  65. package/src/resolver-transform.js.map +1 -1
  66. package/src/standalone-addon-build.js +15 -6
  67. package/src/standalone-addon-build.js.map +1 -1
  68. package/src/sync-dir.d.ts +8 -0
  69. package/src/sync-dir.js +68 -0
  70. package/src/sync-dir.js.map +1 -0
  71. package/src/template-tag-codemod.d.ts +13 -0
  72. package/src/template-tag-codemod.js +302 -0
  73. package/src/template-tag-codemod.js.map +1 -0
  74. package/src/v1-appboot.d.ts +14 -0
  75. package/src/v1-appboot.js +47 -0
  76. package/src/v1-appboot.js.map +1 -0
  77. package/src/v1-config.d.ts +8 -0
  78. package/src/v1-config.js +51 -1
  79. package/src/v1-config.js.map +1 -1
  80. package/babel.js +0 -1
  81. package/src/babel.d.ts +0 -17
  82. package/src/babel.js +0 -146
  83. package/src/babel.js.map +0 -1
  84. package/src/compat-adapters/ember-fetch.d.ts +0 -5
  85. package/src/compat-adapters/ember-fetch.js.map +0 -1
  86. package/src/compat-adapters/ember-resolver.d.ts +0 -4
  87. package/src/compat-adapters/ember-resolver.js +0 -21
  88. package/src/compat-adapters/ember-resolver.js.map +0 -1
  89. package/src/content-for-config.d.ts +0 -11
  90. package/src/content-for-config.js +0 -66
  91. package/src/content-for-config.js.map +0 -1
  92. package/src/http-audit.d.ts +0 -13
  93. package/src/http-audit.js +0 -60
  94. package/src/http-audit.js.map +0 -1
  95. package/src/module-visitor.d.ts +0 -52
  96. package/src/module-visitor.js +0 -285
  97. package/src/module-visitor.js.map +0 -1
@@ -1,40 +1,82 @@
1
1
  "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
2
18
  var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
19
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
20
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
21
  else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
22
  return c > 3 && r && Object.defineProperty(target, key, r), r;
7
23
  };
24
+ var __importStar = (this && this.__importStar) || function (mod) {
25
+ if (mod && mod.__esModule) return mod;
26
+ var result = {};
27
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
28
+ __setModuleDefault(result, mod);
29
+ return result;
30
+ };
8
31
  var __importDefault = (this && this.__importDefault) || function (mod) {
9
32
  return (mod && mod.__esModule) ? mod : { "default": mod };
10
33
  };
11
34
  Object.defineProperty(exports, "__esModule", { value: true });
12
35
  exports.CompatAppBuilder = void 0;
13
36
  const core_1 = require("@embroider/core");
37
+ const walk_sync_1 = __importDefault(require("walk-sync"));
38
+ const path_1 = require("path");
14
39
  const dependency_rules_1 = require("./dependency-rules");
40
+ const flatMap_1 = __importDefault(require("lodash/flatMap"));
41
+ const sortBy_1 = __importDefault(require("lodash/sortBy"));
42
+ const flatten_1 = __importDefault(require("lodash/flatten"));
43
+ const partition_1 = __importDefault(require("lodash/partition"));
44
+ const mergeWith_1 = __importDefault(require("lodash/mergeWith"));
45
+ const cloneDeep_1 = __importDefault(require("lodash/cloneDeep"));
46
+ const resolve_1 = require("resolve");
47
+ const bind_decorator_1 = __importDefault(require("bind-decorator"));
15
48
  const fs_extra_1 = require("fs-extra");
49
+ const ember_html_1 = require("@embroider/core/src/ember-html");
50
+ const portable_babel_config_1 = require("@embroider/core/src/portable-babel-config");
51
+ const app_files_1 = require("@embroider/core/src/app-files");
16
52
  const portable_1 = require("@embroider/core/src/portable");
53
+ const assert_never_1 = __importDefault(require("assert-never"));
17
54
  const typescript_memoize_1 = require("typescript-memoize");
18
- const path_1 = require("path");
19
- const resolve_1 = __importDefault(require("resolve"));
55
+ const path_2 = require("path");
56
+ const resolve_2 = __importDefault(require("resolve"));
20
57
  const fs_extra_2 = require("fs-extra");
21
58
  const node_1 = require("@embroider/macros/src/node");
22
- const module_resolver_options_1 = require("@embroider/core/src/module-resolver-options");
59
+ const fast_sourcemap_concat_1 = __importDefault(require("fast-sourcemap-concat"));
60
+ const escape_string_regexp_1 = __importDefault(require("escape-string-regexp"));
61
+ const sync_dir_1 = require("./sync-dir");
23
62
  // This exists during the actual broccoli build step. As opposed to CompatApp,
24
63
  // which also exists during pipeline-construction time.
25
64
  class CompatAppBuilder {
26
- constructor(origAppPackage, appPackageWithMovedDeps, options, compatApp, configTree, contentForTree, synthVendor, synthStyles) {
65
+ constructor(root, origAppPackage, appPackageWithMovedDeps, options, compatApp, configTree, synthVendor, synthStyles) {
66
+ this.root = root;
27
67
  this.origAppPackage = origAppPackage;
28
68
  this.appPackageWithMovedDeps = appPackageWithMovedDeps;
29
69
  this.options = options;
30
70
  this.compatApp = compatApp;
31
71
  this.configTree = configTree;
32
- this.contentForTree = contentForTree;
33
72
  this.synthVendor = synthVendor;
34
73
  this.synthStyles = synthStyles;
74
+ // for each relativePath, an Asset we have already emitted
75
+ this.assets = new Map();
35
76
  this.staticComponents = false;
36
77
  this.staticHelpers = false;
37
78
  this.staticModifiers = false;
79
+ this.firstBuild = true;
38
80
  // staticInvokables always wins when configured
39
81
  if (typeof options.staticInvokables !== 'undefined') {
40
82
  if (typeof options.staticComponents !== 'undefined' ||
@@ -60,57 +102,827 @@ class CompatAppBuilder {
60
102
  this.staticModifiers = options.staticModifiers;
61
103
  }
62
104
  }
105
+ fastbootJSSrcDir() {
106
+ let target = (0, path_2.join)(this.compatApp.root, 'fastboot');
107
+ if ((0, fs_extra_2.pathExistsSync)(target)) {
108
+ return target;
109
+ }
110
+ }
111
+ extractAssets(treePaths) {
112
+ let assets = [];
113
+ // Everything in our traditional public tree is an on-disk asset
114
+ if (treePaths.publicTree) {
115
+ walk_sync_1.default
116
+ .entries(treePaths.publicTree, {
117
+ directories: false,
118
+ })
119
+ .forEach(entry => {
120
+ assets.push({
121
+ kind: 'on-disk',
122
+ relativePath: entry.relativePath,
123
+ sourcePath: entry.fullPath,
124
+ mtime: entry.mtime, // https://github.com/joliss/node-walk-sync/pull/38
125
+ size: entry.size,
126
+ });
127
+ });
128
+ }
129
+ // ember-cli traditionally outputs a dummy testem.js file to prevent
130
+ // spurious errors when running tests under "ember s".
131
+ if (this.compatApp.shouldBuildTests) {
132
+ let testemAsset = this.findTestemAsset();
133
+ if (testemAsset) {
134
+ assets.push(testemAsset);
135
+ }
136
+ }
137
+ for (let asset of this.emberEntrypoints(treePaths.htmlTree)) {
138
+ assets.push(asset);
139
+ }
140
+ return assets;
141
+ }
142
+ findTestemAsset() {
143
+ let sourcePath;
144
+ try {
145
+ sourcePath = (0, resolve_1.sync)('ember-cli/lib/broccoli/testem.js', { basedir: this.root });
146
+ }
147
+ catch (err) { }
148
+ if (sourcePath) {
149
+ let stat = (0, fs_extra_1.statSync)(sourcePath);
150
+ return {
151
+ kind: 'on-disk',
152
+ relativePath: 'testem.js',
153
+ sourcePath,
154
+ mtime: stat.mtime.getTime(),
155
+ size: stat.size,
156
+ };
157
+ }
158
+ }
159
+ activeAddonChildren(pkg) {
160
+ let result = pkg.dependencies.filter(this.isActiveAddon).filter(
161
+ // When looking for child addons, we want to ignore 'peerDependencies' of
162
+ // a given package, to align with how ember-cli resolves addons. So here
163
+ // we only include dependencies that are definitely active due to one of
164
+ // the other sections.
165
+ addon => pkg.categorizeDependency(addon.name) !== 'peerDependencies');
166
+ if (pkg === this.appPackageWithMovedDeps) {
167
+ let extras = [this.synthVendor, this.synthStyles].filter(this.isActiveAddon);
168
+ result = [...result, ...extras];
169
+ }
170
+ return result.sort(this.orderAddons);
171
+ }
172
+ get allActiveAddons() {
173
+ let result = this.appPackageWithMovedDeps.findDescendants(this.isActiveAddon);
174
+ let extras = [this.synthVendor, this.synthStyles].filter(this.isActiveAddon);
175
+ let extraDescendants = (0, flatMap_1.default)(extras, dep => dep.findDescendants(this.isActiveAddon));
176
+ result = [...result, ...extras, ...extraDescendants];
177
+ return result.sort(this.orderAddons);
178
+ }
179
+ isActiveAddon(pkg) {
180
+ // stage1 already took care of converting everything that's actually active
181
+ // into v2 addons. If it's not a v2 addon, we don't want it.
182
+ //
183
+ // We can encounter v1 addons here when there is inactive stuff floating
184
+ // around in the node_modules that accidentally satisfy something like an
185
+ // optional peer dep.
186
+ return pkg.isV2Addon();
187
+ }
188
+ orderAddons(depA, depB) {
189
+ let depAIdx = 0;
190
+ let depBIdx = 0;
191
+ if (depA && depA.meta && depA.isV2Addon()) {
192
+ depAIdx = depA.meta['order-index'] || 0;
193
+ }
194
+ if (depB && depB.meta && depB.isV2Addon()) {
195
+ depBIdx = depB.meta['order-index'] || 0;
196
+ }
197
+ return depAIdx - depBIdx;
198
+ }
199
+ resolvableExtensions() {
200
+ // webpack's default is ['.wasm', '.mjs', '.js', '.json']. Keeping that
201
+ // subset in that order is sensible, since many third-party libraries will
202
+ // expect it to work that way.
203
+ //
204
+ // For TS, we defer to ember-cli-babel, and the setting for
205
+ // "enableTypescriptTransform" can be set with and without
206
+ // ember-cli-typescript
207
+ return ['.wasm', '.mjs', '.js', '.json', '.ts', '.hbs', '.hbs.js'];
208
+ }
209
+ *emberEntrypoints(htmlTreePath) {
210
+ let classicEntrypoints = [
211
+ { entrypoint: 'index.html', includeTests: false },
212
+ { entrypoint: 'tests/index.html', includeTests: true },
213
+ ];
214
+ if (!this.compatApp.shouldBuildTests) {
215
+ classicEntrypoints.pop();
216
+ }
217
+ for (let { entrypoint, includeTests } of classicEntrypoints) {
218
+ let sourcePath = (0, path_2.join)(htmlTreePath, entrypoint);
219
+ let stats = (0, fs_extra_1.statSync)(sourcePath);
220
+ let asset = {
221
+ kind: 'ember',
222
+ relativePath: entrypoint,
223
+ includeTests,
224
+ sourcePath,
225
+ mtime: stats.mtime.getTime(),
226
+ size: stats.size,
227
+ rootURL: this.rootURL(),
228
+ prepare: (dom) => {
229
+ let scripts = [...dom.window.document.querySelectorAll('script')];
230
+ let styles = [...dom.window.document.querySelectorAll('link[rel*="stylesheet"]')];
231
+ return {
232
+ javascript: this.compatApp.findAppScript(scripts, entrypoint),
233
+ styles: this.compatApp.findAppStyles(styles, entrypoint),
234
+ implicitScripts: this.compatApp.findVendorScript(scripts, entrypoint),
235
+ implicitStyles: this.compatApp.findVendorStyles(styles, entrypoint),
236
+ testJavascript: this.compatApp.findTestScript(scripts),
237
+ implicitTestScripts: this.compatApp.findTestSupportScript(scripts),
238
+ implicitTestStyles: this.compatApp.findTestSupportStyles(styles),
239
+ };
240
+ },
241
+ };
242
+ yield asset;
243
+ }
244
+ }
63
245
  modulePrefix() {
64
246
  return this.configTree.readConfig().modulePrefix;
65
247
  }
66
248
  podModulePrefix() {
67
249
  return this.configTree.readConfig().podModulePrefix;
68
250
  }
69
- get resolverConfig() {
70
- return (0, module_resolver_options_1.buildResolverOptions)({
71
- appPackage: this.appPackageWithMovedDeps,
251
+ rootURL() {
252
+ return this.configTree.readConfig().rootURL;
253
+ }
254
+ activeRules() {
255
+ return (0, dependency_rules_1.activePackageRules)(this.options.packageRules.concat(defaultAddonPackageRules()), [
256
+ { name: this.origAppPackage.name, version: this.origAppPackage.version, root: this.root },
257
+ ...this.allActiveAddons.filter(p => p.meta['auto-upgraded']),
258
+ ]);
259
+ }
260
+ resolverConfig(engines) {
261
+ let renamePackages = Object.assign({}, ...this.allActiveAddons.map(dep => dep.meta['renamed-packages']));
262
+ let renameModules = Object.assign({}, ...this.allActiveAddons.map(dep => dep.meta['renamed-modules']));
263
+ let activeAddons = {};
264
+ for (let addon of this.allActiveAddons) {
265
+ activeAddons[addon.name] = addon.root;
266
+ }
267
+ let options = {
268
+ staticHelpers: this.staticHelpers,
269
+ staticModifiers: this.staticModifiers,
270
+ staticComponents: this.staticComponents,
271
+ allowUnsafeDynamicComponents: this.options.allowUnsafeDynamicComponents,
272
+ };
273
+ let config = {
274
+ // this part is the base ModuleResolverOptions as required by @embroider/core
275
+ activeAddons,
276
+ renameModules,
277
+ renamePackages,
278
+ resolvableExtensions: this.resolvableExtensions(),
279
+ appRoot: this.origAppPackage.root,
280
+ engines: engines.map((appFiles, index) => ({
281
+ packageName: appFiles.engine.package.name,
282
+ // first engine is the app, which has been relocated to this.root
283
+ // we need to use the real path here because webpack requests always use the real path i.e. follow symlinks
284
+ root: (0, fs_extra_1.realpathSync)(index === 0 ? this.root : appFiles.engine.package.root),
285
+ fastbootFiles: appFiles.fastbootFiles,
286
+ activeAddons: [...appFiles.engine.addons]
287
+ .map(a => ({
288
+ name: a.name,
289
+ root: a.root,
290
+ }))
291
+ // the traditional order is the order in which addons will run, such
292
+ // that the last one wins. Our resolver's order is the order to
293
+ // search, so first one wins.
294
+ .reverse(),
295
+ })),
296
+ amdCompatibility: this.options.amdCompatibility,
297
+ // this is the additional stufff that @embroider/compat adds on top to do
298
+ // global template resolving
72
299
  modulePrefix: this.modulePrefix(),
73
300
  podModulePrefix: this.podModulePrefix(),
74
- splitAtRoutes: this.options.splitAtRoutes,
75
- staticAppPaths: this.options.staticAppPaths,
76
- extraDeps: new Map([[this.appPackageWithMovedDeps.root, [this.synthVendor, this.synthStyles]]]),
77
- extend: (options, allActiveAddons) => {
78
- options.activePackageRules = (0, dependency_rules_1.activePackageRules)(this.options.packageRules.concat(defaultAddonPackageRules()), [
79
- { name: this.origAppPackage.name, version: this.origAppPackage.version, root: this.origAppPackage.root },
80
- ...allActiveAddons.filter(p => p.meta['auto-upgraded']),
81
- ]);
82
- options.options = {
83
- staticHelpers: this.staticHelpers,
84
- staticModifiers: this.staticModifiers,
85
- staticComponents: this.staticComponents,
86
- allowUnsafeDynamicComponents: this.options.allowUnsafeDynamicComponents,
301
+ activePackageRules: this.activeRules(),
302
+ options,
303
+ };
304
+ return config;
305
+ }
306
+ scriptPriority(pkg) {
307
+ switch (pkg.name) {
308
+ case 'loader.js':
309
+ return 0;
310
+ case 'ember-source':
311
+ return 10;
312
+ default:
313
+ return 1000;
314
+ }
315
+ }
316
+ get resolvableExtensionsPattern() {
317
+ return (0, core_1.extensionsPattern)(this.resolvableExtensions());
318
+ }
319
+ impliedAssets(type, engine, emberENV) {
320
+ let result = this.impliedAddonAssets(type, engine).map((sourcePath) => {
321
+ let stats = (0, fs_extra_1.statSync)(sourcePath);
322
+ return {
323
+ kind: 'on-disk',
324
+ relativePath: (0, core_1.explicitRelative)(this.root, sourcePath),
325
+ sourcePath,
326
+ mtime: stats.mtimeMs,
327
+ size: stats.size,
328
+ };
329
+ });
330
+ if (type === 'implicit-scripts') {
331
+ result.unshift({
332
+ kind: 'in-memory',
333
+ relativePath: '_testing_prefix_.js',
334
+ source: `var runningTests=false;`,
335
+ });
336
+ result.unshift({
337
+ kind: 'in-memory',
338
+ relativePath: '_ember_env_.js',
339
+ source: `window.EmberENV={ ...(window.EmberENV || {}), ...${JSON.stringify(emberENV, null, 2)} };`,
340
+ });
341
+ result.push({
342
+ kind: 'in-memory',
343
+ relativePath: '_loader_.js',
344
+ source: `loader.makeDefaultExport=false;`,
345
+ });
346
+ }
347
+ if (type === 'implicit-test-scripts') {
348
+ // this is the traditional test-support-suffix.js
349
+ result.push({
350
+ kind: 'in-memory',
351
+ relativePath: '_testing_suffix_.js',
352
+ source: `
353
+ var runningTests=true;
354
+ if (typeof Testem !== 'undefined' && (typeof QUnit !== 'undefined' || typeof Mocha !== 'undefined')) {
355
+ Testem.hookIntoTestFramework();
356
+ }`,
357
+ });
358
+ // whether or not anybody was actually using @embroider/macros
359
+ // explicitly as an addon, we ensure its test-support file is always
360
+ // present.
361
+ if (!result.find(s => s.kind === 'on-disk' && s.sourcePath.endsWith('embroider-macros-test-support.js'))) {
362
+ result.unshift({
363
+ kind: 'on-disk',
364
+ sourcePath: require.resolve('@embroider/macros/src/vendor/embroider-macros-test-support'),
365
+ mtime: 0,
366
+ size: 0,
367
+ relativePath: 'embroider-macros-test-support.js',
368
+ });
369
+ }
370
+ }
371
+ return result;
372
+ }
373
+ impliedAddonAssets(type, { engine }) {
374
+ let result = [];
375
+ for (let addon of (0, sortBy_1.default)(Array.from(engine.addons), this.scriptPriority.bind(this))) {
376
+ let implicitScripts = addon.meta[type];
377
+ if (implicitScripts) {
378
+ let styles = [];
379
+ let options = { basedir: addon.root };
380
+ for (let mod of implicitScripts) {
381
+ if (type === 'implicit-styles') {
382
+ // exclude engines because they will handle their own css importation
383
+ if (!addon.isLazyEngine()) {
384
+ styles.push(resolve_2.default.sync(mod, options));
385
+ }
386
+ }
387
+ else {
388
+ result.push(resolve_2.default.sync(mod, options));
389
+ }
390
+ }
391
+ if (styles.length) {
392
+ result = [...styles, ...result];
393
+ }
394
+ }
395
+ }
396
+ return result;
397
+ }
398
+ babelConfig(resolverConfig) {
399
+ let babel = (0, cloneDeep_1.default)(this.compatApp.babelConfig());
400
+ if (!babel.plugins) {
401
+ babel.plugins = [];
402
+ }
403
+ // Our stage3 code is always allowed to use dynamic import. We may emit it
404
+ // ourself when splitting routes.
405
+ babel.plugins.push(require.resolve('@babel/plugin-syntax-dynamic-import'));
406
+ // https://github.com/webpack/webpack/issues/12154
407
+ babel.plugins.push(require.resolve('./rename-require-plugin'));
408
+ babel.plugins.push([require.resolve('babel-plugin-ember-template-compilation'), this.etcOptions(resolverConfig)]);
409
+ // this is @embroider/macros configured for full stage3 resolution
410
+ babel.plugins.push(...this.compatApp.macrosConfig.babelPluginConfig());
411
+ let colocationOptions = {
412
+ appRoot: this.origAppPackage.root,
413
+ // This extra weirdness is a compromise in favor of build performance.
414
+ //
415
+ // 1. When auto-upgrading an addon from v1 to v2, we definitely want to
416
+ // run any custom AST transforms in stage1.
417
+ //
418
+ // 2. In general case, AST transforms are allowed to manipulate Javascript
419
+ // scope. This means that running transforms -- even when we're doing
420
+ // source-to-source compilation that emits handlebars and not wire
421
+ // format -- implies changing .hbs files into .js files.
422
+ //
423
+ // 3. So stage1 may need to rewrite .hbs to .hbs.js (to avoid colliding
424
+ // with an existing co-located .js file).
425
+ //
426
+ // 4. But stage1 doesn't necessarily want to run babel over the
427
+ // corresponding JS file. Most of the time, that's just an
428
+ // unnecessarily expensive second parse. (We only run it in stage1 to
429
+ // eliminate an addon's custom babel plugins, and many addons don't
430
+ // have any.)
431
+ //
432
+ // 5. Therefore, the work of template-colocation gets defered until here,
433
+ // and it may see co-located templates named `.hbs.js` instead of the
434
+ // usual `.hbs.
435
+ templateExtensions: ['.hbs', '.hbs.js'],
436
+ // All of the above only applies to auto-upgraded packages that were
437
+ // authored in v1. V2 packages don't get any of this complexity, they're
438
+ // supposed to take care of colocating their own templates explicitly.
439
+ packageGuard: true,
440
+ };
441
+ babel.plugins.push([core_1.templateColocationPluginPath, colocationOptions]);
442
+ babel.plugins.push([
443
+ require.resolve('./babel-plugin-adjust-imports'),
444
+ (() => {
445
+ let pluginConfig = {
446
+ appRoot: resolverConfig.appRoot,
87
447
  };
88
- return options;
448
+ return pluginConfig;
449
+ })(),
450
+ ]);
451
+ // we can use globally shared babel runtime by default
452
+ babel.plugins.push([
453
+ require.resolve('@babel/plugin-transform-runtime'),
454
+ { absoluteRuntime: __dirname, useESModules: true, regenerator: false },
455
+ ]);
456
+ const portable = (0, portable_babel_config_1.makePortable)(babel, { basedir: this.root }, this.portableHints);
457
+ addCachablePlugin(portable.config);
458
+ return portable;
459
+ }
460
+ insertEmberApp(asset, appFiles, prepared, emberENV) {
461
+ let html = asset.html;
462
+ if (this.fastbootConfig) {
463
+ // ignore scripts like ember-cli-livereload.js which are not really associated with
464
+ // "the app".
465
+ let ignoreScripts = html.dom.window.document.querySelectorAll('script');
466
+ ignoreScripts.forEach(script => {
467
+ script.setAttribute('data-fastboot-ignore', '');
468
+ });
469
+ }
470
+ // our tests entrypoint already includes a correct module dependency on the
471
+ // app, so we only insert the app when we're not inserting tests
472
+ if (!asset.fileAsset.includeTests) {
473
+ let appJS = this.topAppJSAsset(appFiles, prepared);
474
+ html.insertScriptTag(html.javascript, appJS.relativePath, { type: 'module' });
475
+ }
476
+ if (this.fastbootConfig) {
477
+ // any extra fastboot app files get inserted into our html.javascript
478
+ // section, after the app has been inserted.
479
+ for (let script of this.fastbootConfig.extraAppFiles) {
480
+ html.insertScriptTag(html.javascript, script, { tag: 'fastboot-script' });
481
+ }
482
+ }
483
+ html.insertStyleLink(html.styles, `assets/${this.origAppPackage.name}.css`);
484
+ const parentEngine = appFiles.find(e => !e.engine.parent);
485
+ let vendorJS = this.implicitScriptsAsset(prepared, parentEngine, emberENV);
486
+ if (vendorJS) {
487
+ html.insertScriptTag(html.implicitScripts, vendorJS.relativePath);
488
+ }
489
+ if (this.fastbootConfig) {
490
+ // any extra fastboot vendor files get inserted into our
491
+ // html.implicitScripts section, after the regular implicit script
492
+ // (vendor.js) have been inserted.
493
+ for (let script of this.fastbootConfig.extraVendorFiles) {
494
+ html.insertScriptTag(html.implicitScripts, script, { tag: 'fastboot-script' });
495
+ }
496
+ }
497
+ let implicitStyles = this.implicitStylesAsset(prepared, parentEngine);
498
+ if (implicitStyles) {
499
+ html.insertStyleLink(html.implicitStyles, implicitStyles.relativePath);
500
+ }
501
+ if (!asset.fileAsset.includeTests) {
502
+ return;
503
+ }
504
+ // Test-related assets happen below this point
505
+ let testJS = this.testJSEntrypoint(appFiles, prepared);
506
+ html.insertScriptTag(html.testJavascript, testJS.relativePath, { type: 'module' });
507
+ let implicitTestScriptsAsset = this.implicitTestScriptsAsset(prepared, parentEngine);
508
+ if (implicitTestScriptsAsset) {
509
+ html.insertScriptTag(html.implicitTestScripts, implicitTestScriptsAsset.relativePath);
510
+ }
511
+ let implicitTestStylesAsset = this.implicitTestStylesAsset(prepared, parentEngine);
512
+ if (implicitTestStylesAsset) {
513
+ html.insertStyleLink(html.implicitTestStyles, implicitTestStylesAsset.relativePath);
514
+ }
515
+ }
516
+ implicitScriptsAsset(prepared, application, emberENV) {
517
+ let asset = prepared.get('assets/vendor.js');
518
+ if (!asset) {
519
+ let implicitScripts = this.impliedAssets('implicit-scripts', application, emberENV);
520
+ if (implicitScripts.length > 0) {
521
+ asset = new ConcatenatedAsset('assets/vendor.js', implicitScripts, this.resolvableExtensionsPattern);
522
+ prepared.set(asset.relativePath, asset);
523
+ }
524
+ }
525
+ return asset;
526
+ }
527
+ implicitStylesAsset(prepared, application) {
528
+ let asset = prepared.get('assets/vendor.css');
529
+ if (!asset) {
530
+ let implicitStyles = this.impliedAssets('implicit-styles', application);
531
+ if (implicitStyles.length > 0) {
532
+ // we reverse because we want the synthetic vendor style at the top
533
+ asset = new ConcatenatedAsset('assets/vendor.css', implicitStyles.reverse(), this.resolvableExtensionsPattern);
534
+ prepared.set(asset.relativePath, asset);
535
+ }
536
+ }
537
+ return asset;
538
+ }
539
+ implicitTestScriptsAsset(prepared, application) {
540
+ let testSupportJS = prepared.get('assets/test-support.js');
541
+ if (!testSupportJS) {
542
+ let implicitTestScripts = this.impliedAssets('implicit-test-scripts', application);
543
+ if (implicitTestScripts.length > 0) {
544
+ testSupportJS = new ConcatenatedAsset('assets/test-support.js', implicitTestScripts, this.resolvableExtensionsPattern);
545
+ prepared.set(testSupportJS.relativePath, testSupportJS);
546
+ }
547
+ }
548
+ return testSupportJS;
549
+ }
550
+ implicitTestStylesAsset(prepared, application) {
551
+ let asset = prepared.get('assets/test-support.css');
552
+ if (!asset) {
553
+ let implicitTestStyles = this.impliedAssets('implicit-test-styles', application);
554
+ if (implicitTestStyles.length > 0) {
555
+ asset = new ConcatenatedAsset('assets/test-support.css', implicitTestStyles, this.resolvableExtensionsPattern);
556
+ prepared.set(asset.relativePath, asset);
557
+ }
558
+ }
559
+ return asset;
560
+ }
561
+ // recurse to find all active addons that don't cross an engine boundary.
562
+ // Inner engines themselves will be returned, but not those engines' children.
563
+ // The output set's insertion order is the proper ember-cli compatible
564
+ // ordering of the addons.
565
+ findActiveAddons(pkg, engine, isChild = false) {
566
+ for (let child of this.activeAddonChildren(pkg)) {
567
+ if (!child.isEngine()) {
568
+ this.findActiveAddons(child, engine, true);
569
+ }
570
+ engine.addons.add(child);
571
+ }
572
+ // ensure addons are applied in the correct order, if set (via @embroider/compat/v1-addon)
573
+ if (!isChild) {
574
+ engine.addons = new Set([...engine.addons].sort((a, b) => {
575
+ return (a.meta['order-index'] || 0) - (b.meta['order-index'] || 0);
576
+ }));
577
+ }
578
+ }
579
+ partitionEngines(appJSPath) {
580
+ let queue = [
581
+ {
582
+ package: this.appPackageWithMovedDeps,
583
+ addons: new Set(),
584
+ parent: undefined,
585
+ sourcePath: appJSPath,
586
+ modulePrefix: this.modulePrefix(),
587
+ appRelativePath: '.',
89
588
  },
589
+ ];
590
+ let done = [];
591
+ let seenEngines = new Set();
592
+ while (true) {
593
+ let current = queue.shift();
594
+ if (!current) {
595
+ break;
596
+ }
597
+ this.findActiveAddons(current.package, current);
598
+ for (let addon of current.addons) {
599
+ if (addon.isEngine() && !seenEngines.has(addon)) {
600
+ seenEngines.add(addon);
601
+ queue.push({
602
+ package: addon,
603
+ addons: new Set(),
604
+ parent: current,
605
+ sourcePath: addon.root,
606
+ modulePrefix: addon.name,
607
+ appRelativePath: (0, core_1.explicitRelative)(this.root, addon.root),
608
+ });
609
+ }
610
+ }
611
+ done.push(current);
612
+ }
613
+ return done;
614
+ }
615
+ get activeFastboot() {
616
+ return this.activeAddonChildren(this.appPackageWithMovedDeps).find(a => a.name === 'ember-cli-fastboot');
617
+ }
618
+ emberVersion() {
619
+ let pkg = this.activeAddonChildren(this.appPackageWithMovedDeps).find(a => a.name === 'ember-source');
620
+ if (!pkg) {
621
+ throw new Error('no ember version!');
622
+ }
623
+ return pkg.version;
624
+ }
625
+ get fastbootConfig() {
626
+ if (this.activeFastboot) {
627
+ // this is relying on work done in stage1 by @embroider/compat/src/compat-adapters/ember-cli-fastboot.ts
628
+ let packageJSON = (0, fs_extra_1.readJSONSync)((0, path_2.join)(this.activeFastboot.root, '_fastboot_', 'package.json'));
629
+ let { extraAppFiles, extraVendorFiles } = packageJSON['embroider-fastboot'];
630
+ delete packageJSON['embroider-fastboot'];
631
+ extraVendorFiles.push('assets/embroider_macros_fastboot_init.js');
632
+ return { packageJSON, extraAppFiles, extraVendorFiles };
633
+ }
634
+ }
635
+ updateAppJS(appJSPath) {
636
+ var _a;
637
+ if (!this.engines) {
638
+ this.engines = this.partitionEngines(appJSPath).map(engine => {
639
+ if (engine.sourcePath === appJSPath) {
640
+ // this is the app. We have more to do for the app than for other
641
+ // engines.
642
+ let fastbootSync;
643
+ if (this.activeFastboot) {
644
+ let fastbootDir = this.fastbootJSSrcDir();
645
+ if (fastbootDir) {
646
+ fastbootSync = new sync_dir_1.SyncDir(fastbootDir, (0, path_1.resolve)(this.root, '_fastboot_'));
647
+ }
648
+ }
649
+ return {
650
+ engine,
651
+ appSync: new sync_dir_1.SyncDir(appJSPath, this.root),
652
+ fastbootSync,
653
+ };
654
+ }
655
+ else {
656
+ // this is not the app, so it's some other engine. Engines are already
657
+ // built by stage1 like all other addons, so we only need to observe
658
+ // their files, not doing any actual copying or building.
659
+ return {
660
+ engine,
661
+ appSync: new sync_dir_1.SyncDir(engine.sourcePath, undefined),
662
+ // AFAIK, we've never supported a fastboot overlay directory in an
663
+ // engine. But if we do need that, it would go here.
664
+ fastbootSync: undefined,
665
+ };
666
+ }
667
+ });
668
+ }
669
+ for (let engine of this.engines) {
670
+ engine.appSync.update();
671
+ (_a = engine.fastbootSync) === null || _a === void 0 ? void 0 : _a.update();
672
+ }
673
+ return this.engines.map(({ engine, appSync, fastbootSync }) => {
674
+ var _a;
675
+ return new app_files_1.AppFiles(engine, appSync.files, (_a = fastbootSync === null || fastbootSync === void 0 ? void 0 : fastbootSync.files) !== null && _a !== void 0 ? _a : new Set(), this.resolvableExtensionsPattern, this.podModulePrefix());
676
+ });
677
+ }
678
+ prepareAsset(asset, appFiles, prepared, emberENV) {
679
+ if (asset.kind === 'ember') {
680
+ let prior = this.assets.get(asset.relativePath);
681
+ let parsed;
682
+ if (prior && prior.kind === 'built-ember' && prior.parsedAsset.validFor(asset)) {
683
+ // we can reuse the parsed html
684
+ parsed = prior.parsedAsset;
685
+ parsed.html.clear();
686
+ }
687
+ else {
688
+ parsed = new ParsedEmberAsset(asset);
689
+ }
690
+ this.insertEmberApp(parsed, appFiles, prepared, emberENV);
691
+ prepared.set(asset.relativePath, new BuiltEmberAsset(parsed));
692
+ }
693
+ else {
694
+ prepared.set(asset.relativePath, asset);
695
+ }
696
+ }
697
+ prepareAssets(requestedAssets, appFiles, emberENV) {
698
+ let prepared = new Map();
699
+ for (let asset of requestedAssets) {
700
+ this.prepareAsset(asset, appFiles, prepared, emberENV);
701
+ }
702
+ return prepared;
703
+ }
704
+ assetIsValid(asset, prior) {
705
+ if (!prior) {
706
+ return false;
707
+ }
708
+ switch (asset.kind) {
709
+ case 'on-disk':
710
+ return prior.kind === 'on-disk' && prior.size === asset.size && prior.mtime === asset.mtime;
711
+ case 'in-memory':
712
+ return prior.kind === 'in-memory' && stringOrBufferEqual(prior.source, asset.source);
713
+ case 'built-ember':
714
+ return prior.kind === 'built-ember' && prior.source === asset.source;
715
+ case 'concatenated-asset':
716
+ return (prior.kind === 'concatenated-asset' &&
717
+ prior.sources.length === asset.sources.length &&
718
+ prior.sources.every((priorFile, index) => {
719
+ let newFile = asset.sources[index];
720
+ return this.assetIsValid(newFile, priorFile);
721
+ }));
722
+ }
723
+ }
724
+ updateOnDiskAsset(asset) {
725
+ let destination = (0, path_2.join)(this.root, asset.relativePath);
726
+ (0, fs_extra_2.ensureDirSync)((0, path_2.dirname)(destination));
727
+ (0, fs_extra_2.copySync)(asset.sourcePath, destination, { dereference: true });
728
+ }
729
+ updateInMemoryAsset(asset) {
730
+ let destination = (0, path_2.join)(this.root, asset.relativePath);
731
+ (0, fs_extra_2.ensureDirSync)((0, path_2.dirname)(destination));
732
+ (0, fs_extra_1.writeFileSync)(destination, asset.source, 'utf8');
733
+ }
734
+ updateBuiltEmberAsset(asset) {
735
+ let destination = (0, path_2.join)(this.root, asset.relativePath);
736
+ (0, fs_extra_2.ensureDirSync)((0, path_2.dirname)(destination));
737
+ (0, fs_extra_1.writeFileSync)(destination, asset.source, 'utf8');
738
+ }
739
+ async updateConcatenatedAsset(asset) {
740
+ let concat = new fast_sourcemap_concat_1.default({
741
+ outputFile: (0, path_2.join)(this.root, asset.relativePath),
742
+ mapCommentType: asset.relativePath.endsWith('.js') ? 'line' : 'block',
743
+ baseDir: this.root,
744
+ });
745
+ if (process.env.EMBROIDER_CONCAT_STATS) {
746
+ let MeasureConcat = (await Promise.resolve().then(() => __importStar(require('@embroider/core/src/measure-concat')))).default;
747
+ concat = new MeasureConcat(asset.relativePath, concat, this.root);
748
+ }
749
+ for (let source of asset.sources) {
750
+ switch (source.kind) {
751
+ case 'on-disk':
752
+ concat.addFile((0, core_1.explicitRelative)(this.root, source.sourcePath));
753
+ break;
754
+ case 'in-memory':
755
+ if (typeof source.source !== 'string') {
756
+ throw new Error(`attempted to concatenated a Buffer-backed in-memory asset`);
757
+ }
758
+ concat.addSpace(source.source);
759
+ break;
760
+ default:
761
+ (0, assert_never_1.default)(source);
762
+ }
763
+ }
764
+ await concat.end();
765
+ }
766
+ async updateAssets(requestedAssets, appFiles, emberENV) {
767
+ let assets = this.prepareAssets(requestedAssets, appFiles, emberENV);
768
+ for (let asset of assets.values()) {
769
+ if (this.assetIsValid(asset, this.assets.get(asset.relativePath))) {
770
+ continue;
771
+ }
772
+ (0, core_1.debug)('rebuilding %s', asset.relativePath);
773
+ switch (asset.kind) {
774
+ case 'on-disk':
775
+ this.updateOnDiskAsset(asset);
776
+ break;
777
+ case 'in-memory':
778
+ this.updateInMemoryAsset(asset);
779
+ break;
780
+ case 'built-ember':
781
+ this.updateBuiltEmberAsset(asset);
782
+ break;
783
+ case 'concatenated-asset':
784
+ await this.updateConcatenatedAsset(asset);
785
+ break;
786
+ default:
787
+ (0, assert_never_1.default)(asset);
788
+ }
789
+ }
790
+ for (let oldAsset of this.assets.values()) {
791
+ if (!assets.has(oldAsset.relativePath)) {
792
+ (0, fs_extra_1.unlinkSync)((0, path_2.join)(this.root, oldAsset.relativePath));
793
+ }
794
+ }
795
+ this.assets = assets;
796
+ return [...assets.values()];
797
+ }
798
+ gatherAssets(inputPaths) {
799
+ // first gather all the assets out of addons
800
+ let assets = [];
801
+ for (let pkg of this.allActiveAddons) {
802
+ if (pkg.meta['public-assets']) {
803
+ for (let [filename, appRelativeURL] of Object.entries(pkg.meta['public-assets'] || {})) {
804
+ let sourcePath = (0, path_1.resolve)(pkg.root, filename);
805
+ let stats = (0, fs_extra_1.statSync)(sourcePath);
806
+ assets.push({
807
+ kind: 'on-disk',
808
+ sourcePath,
809
+ relativePath: appRelativeURL,
810
+ mtime: stats.mtimeMs,
811
+ size: stats.size,
812
+ });
813
+ }
814
+ }
815
+ }
816
+ if (this.activeFastboot) {
817
+ const source = `
818
+ (function(){
819
+ var key = '_embroider_macros_runtime_config';
820
+ if (!window[key]){ window[key] = [];}
821
+ window[key].push(function(m) {
822
+ m.setGlobalConfig('fastboot', Object.assign({}, m.getGlobalConfig().fastboot, { isRunning: true }));
90
823
  });
824
+ }())`;
825
+ assets.push({
826
+ kind: 'in-memory',
827
+ source,
828
+ relativePath: 'assets/embroider_macros_fastboot_init.js',
829
+ });
830
+ }
831
+ // and finally tack on the ones from our app itself
832
+ return assets.concat(this.extractAssets(inputPaths));
91
833
  }
92
- async build() {
834
+ async build(inputPaths) {
93
835
  // on the first build, we lock down the macros config. on subsequent builds,
94
836
  // this doesn't do anything anyway because it's idempotent.
95
837
  this.compatApp.macrosConfig.finalize();
96
- let resolverConfig = this.resolverConfig;
97
- let config = this.configTree.readConfig();
98
- let contentForConfig = this.contentForTree.readContents();
838
+ // on first build, clear the output directory completely
839
+ if (this.firstBuild) {
840
+ (0, fs_extra_1.rmSync)(this.root, { recursive: true, force: true });
841
+ this.firstBuild = false;
842
+ }
843
+ let appFiles = this.updateAppJS(inputPaths.appJS);
844
+ let emberENV = this.configTree.readConfig().EmberENV;
845
+ let assets = this.gatherAssets(inputPaths);
846
+ let finalAssets = await this.updateAssets(assets, appFiles, emberENV);
847
+ let assetPaths = assets.map(asset => asset.relativePath);
848
+ if (this.activeFastboot) {
849
+ // when using fastboot, our own package.json needs to be in the output so fastboot can read it.
850
+ assetPaths.push('package.json');
851
+ }
852
+ for (let asset of finalAssets) {
853
+ // our concatenated assets all have map files that ride along. Here we're
854
+ // telling the final stage packager to be sure and serve the map files
855
+ // too.
856
+ if (asset.kind === 'concatenated-asset') {
857
+ assetPaths.push(asset.sourcemapPath);
858
+ }
859
+ }
860
+ let meta = {
861
+ type: 'app',
862
+ version: 2,
863
+ assets: assetPaths,
864
+ babel: {
865
+ filename: '_babel_config_.js',
866
+ isParallelSafe: true, // TODO
867
+ majorVersion: this.compatApp.babelMajorVersion(),
868
+ fileFilter: '_babel_filter_.js',
869
+ },
870
+ 'root-url': this.rootURL(),
871
+ };
872
+ // all compat apps are auto-upgraded, there's no v2 app format here
873
+ meta['auto-upgraded'] = true;
874
+ let pkg = this.combinePackageJSON(meta);
875
+ (0, fs_extra_1.writeFileSync)((0, path_2.join)(this.root, 'package.json'), JSON.stringify(pkg, null, 2), 'utf8');
876
+ let resolverConfig = this.resolverConfig(appFiles);
99
877
  this.addResolverConfig(resolverConfig);
100
- this.addContentForConfig(contentForConfig);
101
- this.addEmberEnvConfig(config.EmberENV);
102
- this.outputAppBootError(config.modulePrefix, config.APP, contentForConfig);
103
- this.addBabelCompat();
878
+ let babelConfig = this.babelConfig(resolverConfig);
879
+ this.addBabelConfig(babelConfig);
880
+ }
881
+ combinePackageJSON(meta) {
882
+ let pkgLayers = [this.origAppPackage.packageJSON];
883
+ let fastbootConfig = this.fastbootConfig;
884
+ if (fastbootConfig) {
885
+ // fastboot-specific package.json output is allowed to add to our original package.json
886
+ pkgLayers.push(fastbootConfig.packageJSON);
887
+ }
888
+ // but our own new v2 app metadata takes precedence over both
889
+ pkgLayers.push({ keywords: ['ember-addon'], 'ember-addon': meta });
890
+ return combinePackageJSON(...pkgLayers);
891
+ }
892
+ etcOptions(resolverConfig) {
893
+ let transforms = this.compatApp.htmlbarsPlugins;
894
+ let { plugins: macroPlugins, setConfig } = node_1.MacrosConfig.transforms();
895
+ setConfig(this.compatApp.macrosConfig);
896
+ for (let macroPlugin of macroPlugins) {
897
+ transforms.push(macroPlugin);
898
+ }
899
+ if (this.staticComponents || this.staticHelpers || this.staticModifiers || globalThis.embroider_audit) {
900
+ let opts = {
901
+ appRoot: resolverConfig.appRoot,
902
+ emberVersion: this.emberVersion(),
903
+ };
904
+ transforms.push([require.resolve('./resolver-transform'), opts]);
905
+ }
906
+ let resolver = new core_1.Resolver(resolverConfig);
907
+ let resolution = resolver.nodeResolve('ember-source/dist/ember-template-compiler', (0, path_1.resolve)(this.root, 'package.json'));
908
+ if (resolution.type !== 'real') {
909
+ throw new Error(`bug: unable to resolve ember-template-compiler from ${this.root}`);
910
+ }
911
+ return {
912
+ transforms,
913
+ compilerPath: resolution.filename,
914
+ enableLegacyModules: ['ember-cli-htmlbars', 'ember-cli-htmlbars-inline-precompile', 'htmlbars-inline-precompile'],
915
+ };
104
916
  }
105
917
  get portableHints() {
106
918
  return this.options.pluginHints.map(hint => {
107
- let cursor = (0, path_1.join)(this.origAppPackage.root, 'package.json');
919
+ let cursor = (0, path_2.join)(this.origAppPackage.root, 'package.json');
108
920
  for (let i = 0; i < hint.resolve.length; i++) {
109
921
  let target = hint.resolve[i];
110
922
  if (i < hint.resolve.length - 1) {
111
- target = (0, path_1.join)(target, 'package.json');
923
+ target = (0, path_2.join)(target, 'package.json');
112
924
  }
113
- cursor = resolve_1.default.sync(target, { basedir: (0, path_1.dirname)(cursor) });
925
+ cursor = resolve_2.default.sync(target, { basedir: (0, path_2.dirname)(cursor) });
114
926
  }
115
927
  return {
116
928
  requireFile: cursor,
@@ -119,109 +931,459 @@ class CompatAppBuilder {
119
931
  };
120
932
  });
121
933
  }
122
- addBabelCompat() {
123
- let plugins = this.compatApp.extraBabelPlugins();
124
- let templateTransforms = this.compatApp.htmlbarsPlugins;
125
- let babelMacros = this.compatApp.macrosConfig.babelPluginConfig();
126
- let { plugins: templateMacros, setConfig } = node_1.MacrosConfig.transforms();
127
- setConfig(this.compatApp.macrosConfig);
128
- let config = {
129
- plugins,
130
- templateTransforms,
131
- babelMacros,
132
- templateMacros: templateMacros,
133
- };
134
- let portableConfig = new portable_1.Portable({ hints: this.portableHints }).dehydrate(config);
135
- if (!portableConfig.isParallelSafe) {
136
- throw new Error(`non-serializble babel plugins or AST transforms found in your app`);
934
+ addBabelConfig(pconfig) {
935
+ if (!pconfig.isParallelSafe) {
936
+ (0, core_1.warn)('Your build is slower because some babel plugins are non-serializable');
137
937
  }
138
- (0, fs_extra_1.writeFileSync)((0, path_1.join)((0, core_1.locateEmbroiderWorkingDir)(this.compatApp.root), '_babel_compat_.js'), `
139
- const { Portable } = require('@embroider/core/src/portable');
140
- module.exports = new Portable().hydrate(${JSON.stringify(portableConfig.value, null, 2)});
141
- `, 'utf8');
938
+ (0, fs_extra_1.writeFileSync)((0, path_2.join)(this.root, '_babel_config_.js'), `module.exports = ${JSON.stringify(pconfig.config, null, 2)}`, 'utf8');
939
+ (0, fs_extra_1.writeFileSync)((0, path_2.join)(this.root, '_babel_filter_.js'), babelFilterTemplate({ skipBabel: this.options.skipBabel, appRoot: this.origAppPackage.root }), 'utf8');
142
940
  }
143
941
  addResolverConfig(config) {
144
- (0, fs_extra_1.outputJSONSync)((0, path_1.join)((0, core_1.locateEmbroiderWorkingDir)(this.compatApp.root), 'resolver.json'), config, { spaces: 2 });
942
+ (0, fs_extra_1.outputJSONSync)((0, path_2.join)((0, core_1.locateEmbroiderWorkingDir)(this.compatApp.root), 'resolver.json'), config, { spaces: 2 });
145
943
  }
146
- addContentForConfig(contentForConfig) {
147
- (0, fs_extra_1.outputJSONSync)((0, path_1.join)((0, core_1.locateEmbroiderWorkingDir)(this.compatApp.root), 'content-for.json'), contentForConfig, {
148
- spaces: 2,
149
- });
150
- // In addition to outputting content-for.json, we also want to check if content-for 'config-module' has a custom content.
151
- // If so, it means some classic addons used to provide this custom content, which is no longer supported.
152
- // Developers can deactivate this check (and the subsequent warning) with useAddonConfigModule
153
- if (this.compatApp.options.useAddonConfigModule) {
154
- let modulePrefix = this.configTree.readConfig().modulePrefix;
155
- // This is the default script provided by https://github.com/ember-cli/ember-cli/blob/master/lib/utilities/ember-app-utils.js#L84
156
- // When storeConfigInMeta is true, this content is always present in the config-module key of content-for.json
157
- const defaultConfigModule = `var prefix = '${modulePrefix}';\ntry {\n var metaName = prefix + '/config/environment';\n var rawConfig = document.querySelector('meta[name=\"' + metaName + '\"]').getAttribute('content');\n var config = JSON.parse(decodeURIComponent(rawConfig));\n\n var exports = { 'default': config };\n\n Object.defineProperty(exports, '__esModule', { value: true });\n\n return exports;\n}\ncatch(err) {\n throw new Error('Could not read config from meta tag with name \"' + metaName + '\".');\n}\n`.replace(/\s/g, '');
158
- const configModule = contentForConfig['/index.html']['config-module'];
159
- const diff = configModule.replace(/\s/g, '').replace(defaultConfigModule, '');
160
- if (diff.length) {
161
- throw new Error(`
162
- Your app uses at least one classic addon that provides content-for 'config-module'. This is no longer supported.
163
- With Embroider, you have full control over the config module, so classic addons no longer need to modify it under the hood.
164
- The following code is included via content-for 'config-module':
165
-
166
- ${configModule}
167
-
168
- 1. If you want to keep the same behavior, add it to the app/environment.js.
169
- 2. Once app/environment.js has the content you need, remove the present error by setting "useAddonConfigModule" to false in the build options.
170
- `);
944
+ shouldSplitRoute(routeName) {
945
+ return (!this.options.splitAtRoutes ||
946
+ this.options.splitAtRoutes.find(pattern => {
947
+ if (typeof pattern === 'string') {
948
+ return pattern === routeName;
949
+ }
950
+ else {
951
+ return pattern.test(routeName);
952
+ }
953
+ }));
954
+ }
955
+ splitRoute(routeName, files, addToParent, addLazyBundle) {
956
+ let shouldSplit = routeName && this.shouldSplitRoute(routeName);
957
+ let ownFiles = [];
958
+ let ownNames = new Set();
959
+ if (files.template) {
960
+ if (shouldSplit) {
961
+ ownFiles.push(files.template);
962
+ ownNames.add(routeName);
963
+ }
964
+ else {
965
+ addToParent(routeName, files.template);
966
+ }
967
+ }
968
+ if (files.controller) {
969
+ if (shouldSplit) {
970
+ ownFiles.push(files.controller);
971
+ ownNames.add(routeName);
972
+ }
973
+ else {
974
+ addToParent(routeName, files.controller);
171
975
  }
172
976
  }
977
+ if (files.route) {
978
+ if (shouldSplit) {
979
+ ownFiles.push(files.route);
980
+ ownNames.add(routeName);
981
+ }
982
+ else {
983
+ addToParent(routeName, files.route);
984
+ }
985
+ }
986
+ for (let [childName, childFiles] of files.children) {
987
+ this.splitRoute(`${routeName}.${childName}`, childFiles, (childRouteName, childFile) => {
988
+ // this is our child calling "addToParent"
989
+ if (shouldSplit) {
990
+ ownFiles.push(childFile);
991
+ ownNames.add(childRouteName);
992
+ }
993
+ else {
994
+ addToParent(childRouteName, childFile);
995
+ }
996
+ }, (routeNames, files) => {
997
+ addLazyBundle(routeNames, files);
998
+ });
999
+ }
1000
+ if (ownFiles.length > 0) {
1001
+ addLazyBundle([...ownNames], ownFiles);
1002
+ }
173
1003
  }
174
- addEmberEnvConfig(emberEnvConfig) {
175
- (0, fs_extra_1.outputJSONSync)((0, path_1.join)((0, core_1.locateEmbroiderWorkingDir)(this.compatApp.root), 'ember-env.json'), emberEnvConfig, {
176
- spaces: 2,
1004
+ topAppJSAsset(engines, prepared) {
1005
+ let [app, ...childEngines] = engines;
1006
+ let relativePath = `assets/${this.origAppPackage.name}.js`;
1007
+ return this.appJSAsset(relativePath, app, childEngines, prepared, {
1008
+ autoRun: this.compatApp.autoRun,
1009
+ appBoot: !this.compatApp.autoRun ? this.compatApp.appBoot.readAppBoot() : '',
1010
+ mainModule: (0, core_1.explicitRelative)((0, path_2.dirname)(relativePath), 'app'),
1011
+ appConfig: this.configTree.readConfig().APP,
177
1012
  });
178
1013
  }
179
- // Classic addons providing custom content-for "app-boot" is no longer supported.
180
- // The purpose of this error message is to help developers to move the classic addons code.
181
- // Developers can deactivate it with useAddonAppBoot build option.
182
- outputAppBootError(modulePrefix, appConfig, contentForConfig) {
183
- if (!this.compatApp.options.useAddonAppBoot) {
184
- return;
1014
+ get staticAppPathsPattern() {
1015
+ if (this.options.staticAppPaths.length > 0) {
1016
+ return new RegExp('^(?:' + this.options.staticAppPaths.map(staticAppPath => (0, escape_string_regexp_1.default)(staticAppPath)).join('|') + ')(?:$|/)');
185
1017
  }
186
- // This is the default script provided by
187
- // https://github.com/ember-cli/ember-cli/blob/master/lib/utilities/ember-app-utils.js#L103
188
- const defaultAppBoot = `
189
- if (!runningTests) {
190
- require("${modulePrefix}/app")["default"].create(${JSON.stringify(appConfig || {})});
191
- }
192
- `.replace(/\s/g, '');
193
- const appBoot = contentForConfig['/index.html']['app-boot'];
194
- const diff = appBoot.replace(/\s/g, '').replace(defaultAppBoot, '');
195
- if (diff.length) {
196
- throw new Error(`
197
- Your app uses at least one classic addon that provides content-for 'app-boot'. This is no longer supported.
198
- With Embroider, you have full control over the app-boot script, so classic addons no longer need to modify it under the hood.
199
- The following code is used for your app boot:
200
-
201
- ${appBoot}
202
-
203
- 1. If you want to keep the same behavior, copy and paste it to the app-boot script included in app/index.html.
204
- 2. Once app/index.html has the content you need, remove the present error by setting "useAddonAppBoot" to false in the build options.
205
- `);
1018
+ }
1019
+ requiredOtherFiles(appFiles) {
1020
+ let pattern = this.staticAppPathsPattern;
1021
+ if (pattern) {
1022
+ return appFiles.otherAppFiles.filter(f => {
1023
+ return !pattern.test(f);
1024
+ });
1025
+ }
1026
+ else {
1027
+ return appFiles.otherAppFiles;
206
1028
  }
207
1029
  }
1030
+ appJSAsset(relativePath, appFiles, childEngines, prepared, entryParams) {
1031
+ let cached = prepared.get(relativePath);
1032
+ if (cached) {
1033
+ return cached;
1034
+ }
1035
+ let eagerModules = [];
1036
+ let requiredAppFiles = [this.requiredOtherFiles(appFiles)];
1037
+ if (!this.staticComponents) {
1038
+ requiredAppFiles.push(appFiles.components);
1039
+ }
1040
+ if (!this.staticHelpers) {
1041
+ requiredAppFiles.push(appFiles.helpers);
1042
+ }
1043
+ if (!this.staticModifiers) {
1044
+ requiredAppFiles.push(appFiles.modifiers);
1045
+ }
1046
+ let styles = [];
1047
+ // only import styles from engines with a parent (this excludeds the parent application) as their styles
1048
+ // will be inserted via a direct <link> tag.
1049
+ if (appFiles.engine.parent && appFiles.engine.package.isLazyEngine()) {
1050
+ let implicitStyles = this.impliedAssets('implicit-styles', appFiles);
1051
+ for (let style of implicitStyles) {
1052
+ styles.push({
1053
+ path: (0, core_1.explicitRelative)('assets/_engine_', style.relativePath),
1054
+ });
1055
+ }
1056
+ let engineMeta = appFiles.engine.package.meta;
1057
+ if (engineMeta && engineMeta['implicit-styles']) {
1058
+ for (let style of engineMeta['implicit-styles']) {
1059
+ styles.push({
1060
+ path: (0, core_1.explicitRelative)((0, path_2.dirname)(relativePath), (0, path_2.join)(appFiles.engine.appRelativePath, style)),
1061
+ });
1062
+ }
1063
+ }
1064
+ }
1065
+ let lazyEngines = [];
1066
+ for (let childEngine of childEngines) {
1067
+ let asset = this.appJSAsset(`assets/_engine_/${encodeURIComponent(childEngine.engine.package.name)}.js`, childEngine, [], prepared);
1068
+ if (childEngine.engine.package.isLazyEngine()) {
1069
+ lazyEngines.push({
1070
+ names: [childEngine.engine.package.name],
1071
+ path: (0, core_1.explicitRelative)((0, path_2.dirname)(relativePath), asset.relativePath),
1072
+ });
1073
+ }
1074
+ else {
1075
+ eagerModules.push((0, core_1.explicitRelative)((0, path_2.dirname)(relativePath), asset.relativePath));
1076
+ }
1077
+ }
1078
+ let lazyRoutes = [];
1079
+ for (let [routeName, routeFiles] of appFiles.routeFiles.children) {
1080
+ this.splitRoute(routeName, routeFiles, (_, filename) => {
1081
+ requiredAppFiles.push([filename]);
1082
+ }, (routeNames, files) => {
1083
+ let routeEntrypoint = `assets/_route_/${encodeURIComponent(routeNames[0])}.js`;
1084
+ if (!prepared.has(routeEntrypoint)) {
1085
+ prepared.set(routeEntrypoint, this.routeEntrypoint(appFiles, routeEntrypoint, files));
1086
+ }
1087
+ lazyRoutes.push({
1088
+ names: routeNames,
1089
+ path: this.importPaths(appFiles, routeEntrypoint).buildtime,
1090
+ });
1091
+ });
1092
+ }
1093
+ let [fastboot, nonFastboot] = (0, partition_1.default)(excludeDotFiles((0, flatten_1.default)(requiredAppFiles)), file => appFiles.isFastbootOnly.get(file));
1094
+ let amdModules = nonFastboot.map(file => this.importPaths(appFiles, file));
1095
+ let fastbootOnlyAmdModules = fastboot.map(file => this.importPaths(appFiles, file));
1096
+ // this is a backward-compatibility feature: addons can force inclusion of
1097
+ // modules.
1098
+ eagerModules.push('./-embroider-implicit-modules.js');
1099
+ let params = { amdModules, fastbootOnlyAmdModules, lazyRoutes, lazyEngines, eagerModules, styles };
1100
+ if (entryParams) {
1101
+ Object.assign(params, entryParams);
1102
+ }
1103
+ let source = entryTemplate(params);
1104
+ let asset = {
1105
+ kind: 'in-memory',
1106
+ source,
1107
+ relativePath,
1108
+ };
1109
+ prepared.set(relativePath, asset);
1110
+ return asset;
1111
+ }
1112
+ importPaths({ engine }, engineRelativePath) {
1113
+ let noHBS = engineRelativePath.replace(this.resolvableExtensionsPattern, '').replace(/\.hbs$/, '');
1114
+ return {
1115
+ runtime: `${engine.modulePrefix}/${noHBS}`,
1116
+ buildtime: path_1.posix.join(engine.package.name, engineRelativePath),
1117
+ };
1118
+ }
1119
+ routeEntrypoint(appFiles, relativePath, files) {
1120
+ let [fastboot, nonFastboot] = (0, partition_1.default)(files, file => appFiles.isFastbootOnly.get(file));
1121
+ let asset = {
1122
+ kind: 'in-memory',
1123
+ source: routeEntryTemplate({
1124
+ files: nonFastboot.map(f => this.importPaths(appFiles, f)),
1125
+ fastbootOnlyFiles: fastboot.map(f => this.importPaths(appFiles, f)),
1126
+ }),
1127
+ relativePath,
1128
+ };
1129
+ return asset;
1130
+ }
1131
+ testJSEntrypoint(appFiles, prepared) {
1132
+ let asset = prepared.get(`assets/test.js`);
1133
+ if (asset) {
1134
+ return asset;
1135
+ }
1136
+ // We're only building tests from the first engine (the app). This is the
1137
+ // normal thing to do -- tests from engines don't automatically roll up into
1138
+ // the app.
1139
+ let engine = appFiles[0];
1140
+ const myName = 'assets/test.js';
1141
+ // tests necessarily also include the app. This is where we account for
1142
+ // that. The classic solution was to always include the app's separate
1143
+ // script tag in the tests HTML, but that isn't as easy for final stage
1144
+ // packagers to understand. It's better to express it here as a direct
1145
+ // module dependency.
1146
+ let eagerModules = [
1147
+ 'ember-testing',
1148
+ (0, core_1.explicitRelative)((0, path_2.dirname)(myName), this.topAppJSAsset(appFiles, prepared).relativePath),
1149
+ ];
1150
+ let amdModules = [];
1151
+ // this is a backward-compatibility feature: addons can force inclusion of
1152
+ // test support modules.
1153
+ eagerModules.push('./-embroider-implicit-test-modules.js');
1154
+ for (let relativePath of engine.tests) {
1155
+ amdModules.push(this.importPaths(engine, relativePath));
1156
+ }
1157
+ let source = entryTemplate({
1158
+ amdModules,
1159
+ eagerModules,
1160
+ testSuffix: true,
1161
+ });
1162
+ asset = {
1163
+ kind: 'in-memory',
1164
+ source,
1165
+ relativePath: myName,
1166
+ };
1167
+ prepared.set(asset.relativePath, asset);
1168
+ return asset;
1169
+ }
208
1170
  }
209
1171
  exports.CompatAppBuilder = CompatAppBuilder;
210
1172
  __decorate([
211
1173
  (0, typescript_memoize_1.Memoize)()
212
- ], CompatAppBuilder.prototype, "resolverConfig", null);
1174
+ ], CompatAppBuilder.prototype, "fastbootJSSrcDir", null);
1175
+ __decorate([
1176
+ (0, typescript_memoize_1.Memoize)()
1177
+ ], CompatAppBuilder.prototype, "findTestemAsset", null);
1178
+ __decorate([
1179
+ (0, typescript_memoize_1.Memoize)()
1180
+ ], CompatAppBuilder.prototype, "allActiveAddons", null);
1181
+ __decorate([
1182
+ bind_decorator_1.default
1183
+ ], CompatAppBuilder.prototype, "isActiveAddon", null);
1184
+ __decorate([
1185
+ bind_decorator_1.default
1186
+ ], CompatAppBuilder.prototype, "orderAddons", null);
1187
+ __decorate([
1188
+ (0, typescript_memoize_1.Memoize)()
1189
+ ], CompatAppBuilder.prototype, "activeRules", null);
1190
+ __decorate([
1191
+ (0, typescript_memoize_1.Memoize)()
1192
+ ], CompatAppBuilder.prototype, "resolvableExtensionsPattern", null);
1193
+ __decorate([
1194
+ (0, typescript_memoize_1.Memoize)()
1195
+ ], CompatAppBuilder.prototype, "babelConfig", null);
1196
+ __decorate([
1197
+ (0, typescript_memoize_1.Memoize)()
1198
+ ], CompatAppBuilder.prototype, "activeFastboot", null);
1199
+ __decorate([
1200
+ (0, typescript_memoize_1.Memoize)()
1201
+ ], CompatAppBuilder.prototype, "fastbootConfig", null);
213
1202
  __decorate([
214
1203
  (0, typescript_memoize_1.Memoize)()
215
1204
  ], CompatAppBuilder.prototype, "portableHints", null);
1205
+ __decorate([
1206
+ (0, typescript_memoize_1.Memoize)()
1207
+ ], CompatAppBuilder.prototype, "staticAppPathsPattern", null);
216
1208
  function defaultAddonPackageRules() {
217
- return (0, fs_extra_2.readdirSync)((0, path_1.join)(__dirname, 'addon-dependency-rules'))
1209
+ return (0, fs_extra_2.readdirSync)((0, path_2.join)(__dirname, 'addon-dependency-rules'))
218
1210
  .map(filename => {
219
1211
  if (filename.endsWith('.js')) {
220
1212
  // eslint-disable-next-line @typescript-eslint/no-require-imports
221
- return require((0, path_1.join)(__dirname, 'addon-dependency-rules', filename)).default;
1213
+ return require((0, path_2.join)(__dirname, 'addon-dependency-rules', filename)).default;
222
1214
  }
223
1215
  })
224
1216
  .filter(Boolean)
225
1217
  .reduce((a, b) => a.concat(b), []);
226
1218
  }
1219
+ const entryTemplate = (0, core_1.jsHandlebarsCompile)(`
1220
+ import { importSync as i, macroCondition, getGlobalConfig } from '@embroider/macros';
1221
+ let w = window;
1222
+ let d = w.define;
1223
+
1224
+ {{#if styles}}
1225
+ if (macroCondition(!getGlobalConfig().fastboot?.isRunning)) {
1226
+ {{#each styles as |stylePath| ~}}
1227
+ i("{{js-string-escape stylePath.path}}");
1228
+ {{/each}}
1229
+ }
1230
+ {{/if}}
1231
+
1232
+ {{#each eagerModules as |eagerModule| ~}}
1233
+ i("{{js-string-escape eagerModule}}");
1234
+ {{/each}}
1235
+
1236
+ {{#each amdModules as |amdModule| ~}}
1237
+ d("{{js-string-escape amdModule.runtime}}", function(){ return i("{{js-string-escape amdModule.buildtime}}");});
1238
+ {{/each}}
1239
+
1240
+ {{#if fastbootOnlyAmdModules}}
1241
+ if (macroCondition(getGlobalConfig().fastboot?.isRunning)) {
1242
+ {{#each fastbootOnlyAmdModules as |amdModule| ~}}
1243
+ d("{{js-string-escape amdModule.runtime}}", function(){ return i("{{js-string-escape amdModule.buildtime}}");});
1244
+ {{/each}}
1245
+ }
1246
+ {{/if}}
1247
+
1248
+
1249
+ {{#if lazyRoutes}}
1250
+ w._embroiderRouteBundles_ = [
1251
+ {{#each lazyRoutes as |route|}}
1252
+ {
1253
+ names: {{json-stringify route.names}},
1254
+ load: function() {
1255
+ return import("{{js-string-escape route.path}}");
1256
+ }
1257
+ },
1258
+ {{/each}}
1259
+ ]
1260
+ {{/if}}
1261
+
1262
+ {{#if lazyEngines}}
1263
+ w._embroiderEngineBundles_ = [
1264
+ {{#each lazyEngines as |engine|}}
1265
+ {
1266
+ names: {{json-stringify engine.names}},
1267
+ load: function() {
1268
+ return import("{{js-string-escape engine.path}}");
1269
+ }
1270
+ },
1271
+ {{/each}}
1272
+ ]
1273
+ {{/if}}
1274
+
1275
+ {{#if autoRun ~}}
1276
+ if (!runningTests) {
1277
+ i("{{js-string-escape mainModule}}").default.create({{json-stringify appConfig}});
1278
+ }
1279
+ {{else if appBoot ~}}
1280
+ {{ appBoot }}
1281
+ {{/if}}
1282
+
1283
+ {{#if testSuffix ~}}
1284
+ {{!- TODO: both of these suffixes should get dynamically generated so they incorporate
1285
+ any content-for added by addons. -}}
1286
+
1287
+
1288
+ {{!- this is the traditional tests-suffix.js -}}
1289
+ i('../tests/test-helper');
1290
+ EmberENV.TESTS_FILE_LOADED = true;
1291
+ {{/if}}
1292
+ `);
1293
+ const routeEntryTemplate = (0, core_1.jsHandlebarsCompile)(`
1294
+ import { importSync as i } from '@embroider/macros';
1295
+ let d = window.define;
1296
+ {{#each files as |amdModule| ~}}
1297
+ d("{{js-string-escape amdModule.runtime}}", function(){ return i("{{js-string-escape amdModule.buildtime}}");});
1298
+ {{/each}}
1299
+ {{#if fastbootOnlyFiles}}
1300
+ import { macroCondition, getGlobalConfig } from '@embroider/macros';
1301
+ if (macroCondition(getGlobalConfig().fastboot?.isRunning)) {
1302
+ {{#each fastbootOnlyFiles as |amdModule| ~}}
1303
+ d("{{js-string-escape amdModule.runtime}}", function(){ return i("{{js-string-escape amdModule.buildtime}}");});
1304
+ {{/each}}
1305
+ }
1306
+ {{/if}}
1307
+ `);
1308
+ function stringOrBufferEqual(a, b) {
1309
+ if (typeof a === 'string' && typeof b === 'string') {
1310
+ return a === b;
1311
+ }
1312
+ if (a instanceof Buffer && b instanceof Buffer) {
1313
+ return Buffer.compare(a, b) === 0;
1314
+ }
1315
+ return false;
1316
+ }
1317
+ const babelFilterTemplate = (0, core_1.jsHandlebarsCompile)(`
1318
+ const { babelFilter } = require(${JSON.stringify(require.resolve('@embroider/core'))});
1319
+ module.exports = babelFilter({{json-stringify skipBabel}}, "{{js-string-escape appRoot}}");
1320
+ `);
1321
+ function combinePackageJSON(...layers) {
1322
+ function custom(objValue, srcValue, key, _object, _source, stack) {
1323
+ if (key === 'keywords' && stack.size === 0) {
1324
+ if (Array.isArray(objValue)) {
1325
+ return objValue.concat(srcValue);
1326
+ }
1327
+ }
1328
+ }
1329
+ return (0, mergeWith_1.default)({}, ...layers, custom);
1330
+ }
1331
+ function addCachablePlugin(babelConfig) {
1332
+ if (Array.isArray(babelConfig.plugins) && babelConfig.plugins.length > 0) {
1333
+ const plugins = Object.create(null);
1334
+ plugins[core_1.cacheBustingPluginPath] = core_1.cacheBustingPluginVersion;
1335
+ for (const plugin of babelConfig.plugins) {
1336
+ let absolutePathToPlugin;
1337
+ if (Array.isArray(plugin) && typeof plugin[0] === 'string') {
1338
+ absolutePathToPlugin = plugin[0];
1339
+ }
1340
+ else if (typeof plugin === 'string') {
1341
+ absolutePathToPlugin = plugin;
1342
+ }
1343
+ else {
1344
+ throw new Error(`[Embroider] a babel plugin without an absolute path was from: ${plugin}`);
1345
+ }
1346
+ plugins[absolutePathToPlugin] = (0, portable_1.maybeNodeModuleVersion)(absolutePathToPlugin);
1347
+ }
1348
+ babelConfig.plugins.push([
1349
+ core_1.cacheBustingPluginPath,
1350
+ {
1351
+ plugins,
1352
+ },
1353
+ ]);
1354
+ }
1355
+ }
1356
+ function excludeDotFiles(files) {
1357
+ return files.filter(file => !file.startsWith('.') && !file.includes('/.'));
1358
+ }
1359
+ class ParsedEmberAsset {
1360
+ constructor(asset) {
1361
+ this.kind = 'parsed-ember';
1362
+ this.fileAsset = asset;
1363
+ this.html = new ember_html_1.PreparedEmberHTML(asset);
1364
+ this.relativePath = asset.relativePath;
1365
+ }
1366
+ validFor(other) {
1367
+ return this.fileAsset.mtime === other.mtime && this.fileAsset.size === other.size;
1368
+ }
1369
+ }
1370
+ class BuiltEmberAsset {
1371
+ constructor(asset) {
1372
+ this.kind = 'built-ember';
1373
+ this.parsedAsset = asset;
1374
+ this.source = asset.html.dom.serialize();
1375
+ this.relativePath = asset.relativePath;
1376
+ }
1377
+ }
1378
+ class ConcatenatedAsset {
1379
+ constructor(relativePath, sources, resolvableExtensions) {
1380
+ this.relativePath = relativePath;
1381
+ this.sources = sources;
1382
+ this.resolvableExtensions = resolvableExtensions;
1383
+ this.kind = 'concatenated-asset';
1384
+ }
1385
+ get sourcemapPath() {
1386
+ return this.relativePath.replace(this.resolvableExtensions, '') + '.map';
1387
+ }
1388
+ }
227
1389
  //# sourceMappingURL=compat-app-builder.js.map