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