@embroider/core 3.1.2 → 3.1.3-unstable.326562b
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 +11 -11
- package/src/module-resolver.js +3 -13
- package/src/module-resolver.js.map +1 -1
- package/LICENSE +0 -21
- package/src/app-differ.d.ts +0 -11
- package/src/app-differ.js +0 -178
- package/src/app-differ.js.map +0 -1
- package/src/app.d.ts +0 -94
- package/src/app.js +0 -1177
- package/src/app.js.map +0 -1
- package/src/build-stage.d.ts +0 -27
- package/src/build-stage.js +0 -67
- package/src/build-stage.js.map +0 -1
- package/src/engine-mangler.d.ts +0 -2
- package/src/engine-mangler.js +0 -8
- package/src/engine-mangler.js.map +0 -1
- package/src/multi-tree-diff.d.ts +0 -28
- package/src/multi-tree-diff.js +0 -140
- package/src/multi-tree-diff.js.map +0 -1
- package/src/output-tree.d.ts +0 -2
- package/src/output-tree.js +0 -25
- package/src/output-tree.js.map +0 -1
- package/src/rename-require-plugin.d.ts +0 -1
- package/src/rename-require-plugin.js +0 -15
- package/src/rename-require-plugin.js.map +0 -1
package/src/app.js
DELETED
@@ -1,1177 +0,0 @@
|
|
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
|
-
});
|
18
|
-
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
19
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
20
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
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;
|
22
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
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
|
-
};
|
31
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
32
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
33
|
-
};
|
34
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
35
|
-
exports.AppBuilder = exports.addCachablePlugin = exports.CACHE_BUSTING_PLUGIN = exports.excludeDotFiles = void 0;
|
36
|
-
const shared_internals_1 = require("@embroider/shared-internals");
|
37
|
-
const js_handlebars_1 = require("./js-handlebars");
|
38
|
-
const resolve_1 = __importDefault(require("resolve"));
|
39
|
-
const typescript_memoize_1 = require("typescript-memoize");
|
40
|
-
const fs_extra_1 = require("fs-extra");
|
41
|
-
const path_1 = require("path");
|
42
|
-
const messages_1 = require("./messages");
|
43
|
-
const sortBy_1 = __importDefault(require("lodash/sortBy"));
|
44
|
-
const flatten_1 = __importDefault(require("lodash/flatten"));
|
45
|
-
const app_differ_1 = __importDefault(require("./app-differ"));
|
46
|
-
const ember_html_1 = require("./ember-html");
|
47
|
-
const assert_never_1 = __importDefault(require("assert-never"));
|
48
|
-
const fast_sourcemap_concat_1 = __importDefault(require("fast-sourcemap-concat"));
|
49
|
-
const node_1 = require("@embroider/macros/src/node");
|
50
|
-
const portable_babel_config_1 = require("./portable-babel-config");
|
51
|
-
const engine_mangler_1 = require("./engine-mangler");
|
52
|
-
const app_files_1 = require("./app-files");
|
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 portable_1 = require("./portable");
|
57
|
-
const escape_string_regexp_1 = __importDefault(require("escape-string-regexp"));
|
58
|
-
function excludeDotFiles(files) {
|
59
|
-
return files.filter(file => !file.startsWith('.') && !file.includes('/.'));
|
60
|
-
}
|
61
|
-
exports.excludeDotFiles = excludeDotFiles;
|
62
|
-
exports.CACHE_BUSTING_PLUGIN = {
|
63
|
-
path: require.resolve('@embroider/shared-internals/src/babel-plugin-cache-busting.js'),
|
64
|
-
version: (0, fs_extra_1.readJSONSync)(`${__dirname}/../package.json`).version,
|
65
|
-
};
|
66
|
-
function addCachablePlugin(babelConfig) {
|
67
|
-
if (Array.isArray(babelConfig.plugins) && babelConfig.plugins.length > 0) {
|
68
|
-
const plugins = Object.create(null);
|
69
|
-
plugins[exports.CACHE_BUSTING_PLUGIN.path] = exports.CACHE_BUSTING_PLUGIN.version;
|
70
|
-
for (const plugin of babelConfig.plugins) {
|
71
|
-
let absolutePathToPlugin;
|
72
|
-
if (Array.isArray(plugin) && typeof plugin[0] === 'string') {
|
73
|
-
absolutePathToPlugin = plugin[0];
|
74
|
-
}
|
75
|
-
else if (typeof plugin === 'string') {
|
76
|
-
absolutePathToPlugin = plugin;
|
77
|
-
}
|
78
|
-
else {
|
79
|
-
throw new Error(`[Embroider] a babel plugin without an absolute path was from: ${plugin}`);
|
80
|
-
}
|
81
|
-
plugins[absolutePathToPlugin] = (0, portable_1.maybeNodeModuleVersion)(absolutePathToPlugin);
|
82
|
-
}
|
83
|
-
babelConfig.plugins.push([
|
84
|
-
exports.CACHE_BUSTING_PLUGIN.path,
|
85
|
-
{
|
86
|
-
plugins,
|
87
|
-
},
|
88
|
-
]);
|
89
|
-
}
|
90
|
-
}
|
91
|
-
exports.addCachablePlugin = addCachablePlugin;
|
92
|
-
class ParsedEmberAsset {
|
93
|
-
constructor(asset) {
|
94
|
-
this.kind = 'parsed-ember';
|
95
|
-
this.fileAsset = asset;
|
96
|
-
this.html = new ember_html_1.PreparedEmberHTML(asset);
|
97
|
-
this.relativePath = asset.relativePath;
|
98
|
-
}
|
99
|
-
validFor(other) {
|
100
|
-
return this.fileAsset.mtime === other.mtime && this.fileAsset.size === other.size;
|
101
|
-
}
|
102
|
-
}
|
103
|
-
class BuiltEmberAsset {
|
104
|
-
constructor(asset) {
|
105
|
-
this.kind = 'built-ember';
|
106
|
-
this.parsedAsset = asset;
|
107
|
-
this.source = asset.html.dom.serialize();
|
108
|
-
this.relativePath = asset.relativePath;
|
109
|
-
}
|
110
|
-
}
|
111
|
-
class ConcatenatedAsset {
|
112
|
-
constructor(relativePath, sources, resolvableExtensions) {
|
113
|
-
this.relativePath = relativePath;
|
114
|
-
this.sources = sources;
|
115
|
-
this.resolvableExtensions = resolvableExtensions;
|
116
|
-
this.kind = 'concatenated-asset';
|
117
|
-
}
|
118
|
-
get sourcemapPath() {
|
119
|
-
return this.relativePath.replace(this.resolvableExtensions, '') + '.map';
|
120
|
-
}
|
121
|
-
}
|
122
|
-
class AppBuilder {
|
123
|
-
constructor(root, app, adapter, options, macrosConfig) {
|
124
|
-
this.root = root;
|
125
|
-
this.app = app;
|
126
|
-
this.adapter = adapter;
|
127
|
-
this.options = options;
|
128
|
-
this.macrosConfig = macrosConfig;
|
129
|
-
// for each relativePath, an Asset we have already emitted
|
130
|
-
this.assets = new Map();
|
131
|
-
// this uses globalConfig because it's a way for packages to ask "is
|
132
|
-
// Embroider doing this build?". So it's necessarily global, not scoped to
|
133
|
-
// any subgraph of dependencies.
|
134
|
-
macrosConfig.setGlobalConfig(__filename, `@embroider/core`, {
|
135
|
-
// this is hard-coded to true because it literally means "embroider is
|
136
|
-
// building this Ember app". You can see non-true when using the Embroider
|
137
|
-
// macros in a classic build.
|
138
|
-
active: true,
|
139
|
-
});
|
140
|
-
}
|
141
|
-
scriptPriority(pkg) {
|
142
|
-
switch (pkg.name) {
|
143
|
-
case 'loader.js':
|
144
|
-
return 0;
|
145
|
-
case 'ember-source':
|
146
|
-
return 10;
|
147
|
-
default:
|
148
|
-
return 1000;
|
149
|
-
}
|
150
|
-
}
|
151
|
-
get resolvableExtensionsPattern() {
|
152
|
-
return (0, shared_internals_1.extensionsPattern)(this.adapter.resolvableExtensions());
|
153
|
-
}
|
154
|
-
impliedAssets(type, engine, emberENV) {
|
155
|
-
let result = this.impliedAddonAssets(type, engine).map((sourcePath) => {
|
156
|
-
let stats = (0, fs_extra_1.statSync)(sourcePath);
|
157
|
-
return {
|
158
|
-
kind: 'on-disk',
|
159
|
-
relativePath: (0, shared_internals_1.explicitRelative)(this.root, sourcePath),
|
160
|
-
sourcePath,
|
161
|
-
mtime: stats.mtimeMs,
|
162
|
-
size: stats.size,
|
163
|
-
};
|
164
|
-
});
|
165
|
-
if (type === 'implicit-scripts') {
|
166
|
-
result.unshift({
|
167
|
-
kind: 'in-memory',
|
168
|
-
relativePath: '_testing_prefix_.js',
|
169
|
-
source: `var runningTests=false;`,
|
170
|
-
});
|
171
|
-
result.unshift({
|
172
|
-
kind: 'in-memory',
|
173
|
-
relativePath: '_ember_env_.js',
|
174
|
-
source: `window.EmberENV={ ...(window.EmberENV || {}), ...${JSON.stringify(emberENV, null, 2)} };`,
|
175
|
-
});
|
176
|
-
result.push({
|
177
|
-
kind: 'in-memory',
|
178
|
-
relativePath: '_loader_.js',
|
179
|
-
source: `loader.makeDefaultExport=false;`,
|
180
|
-
});
|
181
|
-
}
|
182
|
-
if (type === 'implicit-test-scripts') {
|
183
|
-
// this is the traditional test-support-suffix.js
|
184
|
-
result.push({
|
185
|
-
kind: 'in-memory',
|
186
|
-
relativePath: '_testing_suffix_.js',
|
187
|
-
source: `
|
188
|
-
var runningTests=true;
|
189
|
-
if (typeof Testem !== 'undefined' && (typeof QUnit !== 'undefined' || typeof Mocha !== 'undefined')) {
|
190
|
-
Testem.hookIntoTestFramework();
|
191
|
-
}`,
|
192
|
-
});
|
193
|
-
// whether or not anybody was actually using @embroider/macros
|
194
|
-
// explicitly as an addon, we ensure its test-support file is always
|
195
|
-
// present.
|
196
|
-
if (!result.find(s => s.kind === 'on-disk' && s.sourcePath.endsWith('embroider-macros-test-support.js'))) {
|
197
|
-
result.unshift({
|
198
|
-
kind: 'on-disk',
|
199
|
-
sourcePath: require.resolve('@embroider/macros/src/vendor/embroider-macros-test-support'),
|
200
|
-
mtime: 0,
|
201
|
-
size: 0,
|
202
|
-
relativePath: 'embroider-macros-test-support.js',
|
203
|
-
});
|
204
|
-
}
|
205
|
-
}
|
206
|
-
return result;
|
207
|
-
}
|
208
|
-
impliedAddonAssets(type, engine) {
|
209
|
-
let result = [];
|
210
|
-
for (let addon of (0, sortBy_1.default)(Array.from(engine.addons), this.scriptPriority.bind(this))) {
|
211
|
-
let implicitScripts = addon.meta[type];
|
212
|
-
if (implicitScripts) {
|
213
|
-
let styles = [];
|
214
|
-
let options = { basedir: addon.root };
|
215
|
-
for (let mod of implicitScripts) {
|
216
|
-
if (type === 'implicit-styles') {
|
217
|
-
// exclude engines because they will handle their own css importation
|
218
|
-
if (!addon.isLazyEngine()) {
|
219
|
-
styles.push(resolve_1.default.sync(mod, options));
|
220
|
-
}
|
221
|
-
}
|
222
|
-
else {
|
223
|
-
result.push(resolve_1.default.sync(mod, options));
|
224
|
-
}
|
225
|
-
}
|
226
|
-
if (styles.length) {
|
227
|
-
result = [...styles, ...result];
|
228
|
-
}
|
229
|
-
}
|
230
|
-
}
|
231
|
-
return result;
|
232
|
-
}
|
233
|
-
// unlike our full config, this one just needs to know how to parse all the
|
234
|
-
// syntax our app can contain.
|
235
|
-
babelParserConfig() {
|
236
|
-
let babel = (0, cloneDeep_1.default)(this.adapter.babelConfig());
|
237
|
-
if (!babel.plugins) {
|
238
|
-
babel.plugins = [];
|
239
|
-
}
|
240
|
-
// Our stage3 code is always allowed to use dynamic import. We may emit it
|
241
|
-
// ourself when splitting routes.
|
242
|
-
babel.plugins.push(require.resolve('@babel/plugin-syntax-dynamic-import'));
|
243
|
-
return babel;
|
244
|
-
}
|
245
|
-
babelConfig(resolverConfig) {
|
246
|
-
let babel = (0, cloneDeep_1.default)(this.adapter.babelConfig());
|
247
|
-
if (!babel.plugins) {
|
248
|
-
babel.plugins = [];
|
249
|
-
}
|
250
|
-
// Our stage3 code is always allowed to use dynamic import. We may emit it
|
251
|
-
// ourself when splitting routes.
|
252
|
-
babel.plugins.push(require.resolve('@babel/plugin-syntax-dynamic-import'));
|
253
|
-
// https://github.com/webpack/webpack/issues/12154
|
254
|
-
babel.plugins.push(require.resolve('./rename-require-plugin'));
|
255
|
-
babel.plugins.push([require.resolve('babel-plugin-ember-template-compilation'), this.etcOptions(resolverConfig)]);
|
256
|
-
// this is @embroider/macros configured for full stage3 resolution
|
257
|
-
babel.plugins.push(...this.macrosConfig.babelPluginConfig());
|
258
|
-
let colocationOptions = {
|
259
|
-
appRoot: this.root,
|
260
|
-
// This extra weirdness is a compromise in favor of build performance.
|
261
|
-
//
|
262
|
-
// 1. When auto-upgrading an addon from v1 to v2, we definitely want to
|
263
|
-
// run any custom AST transforms in stage1.
|
264
|
-
//
|
265
|
-
// 2. In general case, AST transforms are allowed to manipulate Javascript
|
266
|
-
// scope. This means that running transforms -- even when we're doing
|
267
|
-
// source-to-source compilation that emits handlebars and not wire
|
268
|
-
// format -- implies changing .hbs files into .js files.
|
269
|
-
//
|
270
|
-
// 3. So stage1 may need to rewrite .hbs to .hbs.js (to avoid colliding
|
271
|
-
// with an existing co-located .js file).
|
272
|
-
//
|
273
|
-
// 4. But stage1 doesn't necessarily want to run babel over the
|
274
|
-
// corresponding JS file. Most of the time, that's just an
|
275
|
-
// unnecessarily expensive second parse. (We only run it in stage1 to
|
276
|
-
// eliminate an addon's custom babel plugins, and many addons don't
|
277
|
-
// have any.)
|
278
|
-
//
|
279
|
-
// 5. Therefore, the work of template-colocation gets defered until here,
|
280
|
-
// and it may see co-located templates named `.hbs.js` instead of the
|
281
|
-
// usual `.hbs.
|
282
|
-
templateExtensions: ['.hbs', '.hbs.js'],
|
283
|
-
// All of the above only applies to auto-upgraded packages that were
|
284
|
-
// authored in v1. V2 packages don't get any of this complexity, they're
|
285
|
-
// supposed to take care of colocating their own templates explicitly.
|
286
|
-
packageGuard: true,
|
287
|
-
};
|
288
|
-
babel.plugins.push([
|
289
|
-
require.resolve('@embroider/shared-internals/src/template-colocation-plugin'),
|
290
|
-
colocationOptions,
|
291
|
-
]);
|
292
|
-
for (let p of this.adapter.jsPlugins(resolverConfig)) {
|
293
|
-
babel.plugins.push(p);
|
294
|
-
}
|
295
|
-
// we can use globally shared babel runtime by default
|
296
|
-
babel.plugins.push([
|
297
|
-
require.resolve('@babel/plugin-transform-runtime'),
|
298
|
-
{ absoluteRuntime: __dirname, useESModules: true, regenerator: false },
|
299
|
-
]);
|
300
|
-
const portable = (0, portable_babel_config_1.makePortable)(babel, { basedir: this.root }, this.portableHints);
|
301
|
-
addCachablePlugin(portable.config);
|
302
|
-
return portable;
|
303
|
-
}
|
304
|
-
insertEmberApp(asset, appFiles, prepared, emberENV) {
|
305
|
-
let html = asset.html;
|
306
|
-
if (this.fastbootConfig) {
|
307
|
-
// ignore scripts like ember-cli-livereload.js which are not really associated with
|
308
|
-
// "the app".
|
309
|
-
let ignoreScripts = html.dom.window.document.querySelectorAll('script');
|
310
|
-
ignoreScripts.forEach(script => {
|
311
|
-
script.setAttribute('data-fastboot-ignore', '');
|
312
|
-
});
|
313
|
-
}
|
314
|
-
// our tests entrypoint already includes a correct module dependency on the
|
315
|
-
// app, so we only insert the app when we're not inserting tests
|
316
|
-
if (!asset.fileAsset.includeTests) {
|
317
|
-
let appJS = this.topAppJSAsset(appFiles, prepared);
|
318
|
-
html.insertScriptTag(html.javascript, appJS.relativePath, { type: 'module' });
|
319
|
-
}
|
320
|
-
if (this.fastbootConfig) {
|
321
|
-
// any extra fastboot app files get inserted into our html.javascript
|
322
|
-
// section, after the app has been inserted.
|
323
|
-
for (let script of this.fastbootConfig.extraAppFiles) {
|
324
|
-
html.insertScriptTag(html.javascript, script, { tag: 'fastboot-script' });
|
325
|
-
}
|
326
|
-
}
|
327
|
-
html.insertStyleLink(html.styles, `assets/${this.app.name}.css`);
|
328
|
-
const parentEngine = appFiles.find(e => !e.parent);
|
329
|
-
let vendorJS = this.implicitScriptsAsset(prepared, parentEngine, emberENV);
|
330
|
-
if (vendorJS) {
|
331
|
-
html.insertScriptTag(html.implicitScripts, vendorJS.relativePath);
|
332
|
-
}
|
333
|
-
if (this.fastbootConfig) {
|
334
|
-
// any extra fastboot vendor files get inserted into our
|
335
|
-
// html.implicitScripts section, after the regular implicit script
|
336
|
-
// (vendor.js) have been inserted.
|
337
|
-
for (let script of this.fastbootConfig.extraVendorFiles) {
|
338
|
-
html.insertScriptTag(html.implicitScripts, script, { tag: 'fastboot-script' });
|
339
|
-
}
|
340
|
-
}
|
341
|
-
let implicitStyles = this.implicitStylesAsset(prepared, parentEngine);
|
342
|
-
if (implicitStyles) {
|
343
|
-
html.insertStyleLink(html.implicitStyles, implicitStyles.relativePath);
|
344
|
-
}
|
345
|
-
if (!asset.fileAsset.includeTests) {
|
346
|
-
return;
|
347
|
-
}
|
348
|
-
// Test-related assets happen below this point
|
349
|
-
let testJS = this.testJSEntrypoint(appFiles, prepared);
|
350
|
-
html.insertScriptTag(html.testJavascript, testJS.relativePath, { type: 'module' });
|
351
|
-
let implicitTestScriptsAsset = this.implicitTestScriptsAsset(prepared, parentEngine);
|
352
|
-
if (implicitTestScriptsAsset) {
|
353
|
-
html.insertScriptTag(html.implicitTestScripts, implicitTestScriptsAsset.relativePath);
|
354
|
-
}
|
355
|
-
let implicitTestStylesAsset = this.implicitTestStylesAsset(prepared, parentEngine);
|
356
|
-
if (implicitTestStylesAsset) {
|
357
|
-
html.insertStyleLink(html.implicitTestStyles, implicitTestStylesAsset.relativePath);
|
358
|
-
}
|
359
|
-
}
|
360
|
-
implicitScriptsAsset(prepared, application, emberENV) {
|
361
|
-
let asset = prepared.get('assets/vendor.js');
|
362
|
-
if (!asset) {
|
363
|
-
let implicitScripts = this.impliedAssets('implicit-scripts', application, emberENV);
|
364
|
-
if (implicitScripts.length > 0) {
|
365
|
-
asset = new ConcatenatedAsset('assets/vendor.js', implicitScripts, this.resolvableExtensionsPattern);
|
366
|
-
prepared.set(asset.relativePath, asset);
|
367
|
-
}
|
368
|
-
}
|
369
|
-
return asset;
|
370
|
-
}
|
371
|
-
implicitStylesAsset(prepared, application) {
|
372
|
-
let asset = prepared.get('assets/vendor.css');
|
373
|
-
if (!asset) {
|
374
|
-
let implicitStyles = this.impliedAssets('implicit-styles', application);
|
375
|
-
if (implicitStyles.length > 0) {
|
376
|
-
// we reverse because we want the synthetic vendor style at the top
|
377
|
-
asset = new ConcatenatedAsset('assets/vendor.css', implicitStyles.reverse(), this.resolvableExtensionsPattern);
|
378
|
-
prepared.set(asset.relativePath, asset);
|
379
|
-
}
|
380
|
-
}
|
381
|
-
return asset;
|
382
|
-
}
|
383
|
-
implicitTestScriptsAsset(prepared, application) {
|
384
|
-
let testSupportJS = prepared.get('assets/test-support.js');
|
385
|
-
if (!testSupportJS) {
|
386
|
-
let implicitTestScripts = this.impliedAssets('implicit-test-scripts', application);
|
387
|
-
if (implicitTestScripts.length > 0) {
|
388
|
-
testSupportJS = new ConcatenatedAsset('assets/test-support.js', implicitTestScripts, this.resolvableExtensionsPattern);
|
389
|
-
prepared.set(testSupportJS.relativePath, testSupportJS);
|
390
|
-
}
|
391
|
-
}
|
392
|
-
return testSupportJS;
|
393
|
-
}
|
394
|
-
implicitTestStylesAsset(prepared, application) {
|
395
|
-
let asset = prepared.get('assets/test-support.css');
|
396
|
-
if (!asset) {
|
397
|
-
let implicitTestStyles = this.impliedAssets('implicit-test-styles', application);
|
398
|
-
if (implicitTestStyles.length > 0) {
|
399
|
-
asset = new ConcatenatedAsset('assets/test-support.css', implicitTestStyles, this.resolvableExtensionsPattern);
|
400
|
-
prepared.set(asset.relativePath, asset);
|
401
|
-
}
|
402
|
-
}
|
403
|
-
return asset;
|
404
|
-
}
|
405
|
-
// recurse to find all active addons that don't cross an engine boundary.
|
406
|
-
// Inner engines themselves will be returned, but not those engines' children.
|
407
|
-
// The output set's insertion order is the proper ember-cli compatible
|
408
|
-
// ordering of the addons.
|
409
|
-
findActiveAddons(pkg, engine, isChild = false) {
|
410
|
-
for (let child of this.adapter.activeAddonChildren(pkg)) {
|
411
|
-
if (!child.isEngine()) {
|
412
|
-
this.findActiveAddons(child, engine, true);
|
413
|
-
}
|
414
|
-
engine.addons.add(child);
|
415
|
-
}
|
416
|
-
// ensure addons are applied in the correct order, if set (via @embroider/compat/v1-addon)
|
417
|
-
if (!isChild) {
|
418
|
-
engine.addons = new Set([...engine.addons].sort((a, b) => {
|
419
|
-
return (a.meta['order-index'] || 0) - (b.meta['order-index'] || 0);
|
420
|
-
}));
|
421
|
-
}
|
422
|
-
}
|
423
|
-
partitionEngines(appJSPath) {
|
424
|
-
let queue = [
|
425
|
-
{
|
426
|
-
package: this.app,
|
427
|
-
addons: new Set(),
|
428
|
-
parent: undefined,
|
429
|
-
sourcePath: appJSPath,
|
430
|
-
destPath: this.root,
|
431
|
-
modulePrefix: this.modulePrefix,
|
432
|
-
appRelativePath: '.',
|
433
|
-
},
|
434
|
-
];
|
435
|
-
let done = [];
|
436
|
-
let seenEngines = new Set();
|
437
|
-
while (true) {
|
438
|
-
let current = queue.shift();
|
439
|
-
if (!current) {
|
440
|
-
break;
|
441
|
-
}
|
442
|
-
this.findActiveAddons(current.package, current);
|
443
|
-
for (let addon of current.addons) {
|
444
|
-
if (addon.isEngine() && !seenEngines.has(addon)) {
|
445
|
-
seenEngines.add(addon);
|
446
|
-
queue.push({
|
447
|
-
package: addon,
|
448
|
-
addons: new Set(),
|
449
|
-
parent: current,
|
450
|
-
sourcePath: (0, engine_mangler_1.mangledEngineRoot)(addon),
|
451
|
-
destPath: addon.root,
|
452
|
-
modulePrefix: addon.name,
|
453
|
-
appRelativePath: (0, shared_internals_1.explicitRelative)(this.root, addon.root),
|
454
|
-
});
|
455
|
-
}
|
456
|
-
}
|
457
|
-
done.push(current);
|
458
|
-
}
|
459
|
-
return done;
|
460
|
-
}
|
461
|
-
get activeFastboot() {
|
462
|
-
return this.adapter.activeAddonChildren(this.app).find(a => a.name === 'ember-cli-fastboot');
|
463
|
-
}
|
464
|
-
get fastbootConfig() {
|
465
|
-
if (this.activeFastboot) {
|
466
|
-
// this is relying on work done in stage1 by @embroider/compat/src/compat-adapters/ember-cli-fastboot.ts
|
467
|
-
let packageJSON = (0, fs_extra_1.readJSONSync)((0, path_1.join)(this.activeFastboot.root, '_fastboot_', 'package.json'));
|
468
|
-
let { extraAppFiles, extraVendorFiles } = packageJSON['embroider-fastboot'];
|
469
|
-
delete packageJSON['embroider-fastboot'];
|
470
|
-
extraVendorFiles.push('assets/embroider_macros_fastboot_init.js');
|
471
|
-
return { packageJSON, extraAppFiles, extraVendorFiles };
|
472
|
-
}
|
473
|
-
}
|
474
|
-
updateAppJS(inputPaths) {
|
475
|
-
let appJSPath = this.adapter.appJSSrcDir(inputPaths);
|
476
|
-
if (!this.appDiffers) {
|
477
|
-
let engines = this.partitionEngines(appJSPath);
|
478
|
-
this.appDiffers = engines.map(engine => {
|
479
|
-
let differ;
|
480
|
-
if (this.activeFastboot) {
|
481
|
-
differ = new app_differ_1.default(engine.destPath, engine.sourcePath, [...engine.addons], true, this.adapter.fastbootJSSrcDir(inputPaths), this.babelParserConfig());
|
482
|
-
}
|
483
|
-
else {
|
484
|
-
differ = new app_differ_1.default(engine.destPath, engine.sourcePath, [...engine.addons]);
|
485
|
-
}
|
486
|
-
return {
|
487
|
-
differ,
|
488
|
-
engine,
|
489
|
-
};
|
490
|
-
});
|
491
|
-
}
|
492
|
-
// this is in reverse order because we need deeper engines to update before
|
493
|
-
// their parents, because they aren't really valid packages until they
|
494
|
-
// update, and their parents will go looking for their own `app-js` content.
|
495
|
-
this.appDiffers
|
496
|
-
.slice()
|
497
|
-
.reverse()
|
498
|
-
.forEach(a => a.differ.update());
|
499
|
-
return this.appDiffers.map(a => {
|
500
|
-
return {
|
501
|
-
...a.engine,
|
502
|
-
appFiles: new app_files_1.AppFiles(a.differ, this.resolvableExtensionsPattern, this.adapter.podModulePrefix()),
|
503
|
-
};
|
504
|
-
});
|
505
|
-
}
|
506
|
-
prepareAsset(asset, appFiles, prepared, emberENV) {
|
507
|
-
if (asset.kind === 'ember') {
|
508
|
-
let prior = this.assets.get(asset.relativePath);
|
509
|
-
let parsed;
|
510
|
-
if (prior && prior.kind === 'built-ember' && prior.parsedAsset.validFor(asset)) {
|
511
|
-
// we can reuse the parsed html
|
512
|
-
parsed = prior.parsedAsset;
|
513
|
-
parsed.html.clear();
|
514
|
-
}
|
515
|
-
else {
|
516
|
-
parsed = new ParsedEmberAsset(asset);
|
517
|
-
}
|
518
|
-
this.insertEmberApp(parsed, appFiles, prepared, emberENV);
|
519
|
-
prepared.set(asset.relativePath, new BuiltEmberAsset(parsed));
|
520
|
-
}
|
521
|
-
else {
|
522
|
-
prepared.set(asset.relativePath, asset);
|
523
|
-
}
|
524
|
-
}
|
525
|
-
prepareAssets(requestedAssets, appFiles, emberENV) {
|
526
|
-
let prepared = new Map();
|
527
|
-
for (let asset of requestedAssets) {
|
528
|
-
this.prepareAsset(asset, appFiles, prepared, emberENV);
|
529
|
-
}
|
530
|
-
return prepared;
|
531
|
-
}
|
532
|
-
assetIsValid(asset, prior) {
|
533
|
-
if (!prior) {
|
534
|
-
return false;
|
535
|
-
}
|
536
|
-
switch (asset.kind) {
|
537
|
-
case 'on-disk':
|
538
|
-
return prior.kind === 'on-disk' && prior.size === asset.size && prior.mtime === asset.mtime;
|
539
|
-
case 'in-memory':
|
540
|
-
return prior.kind === 'in-memory' && stringOrBufferEqual(prior.source, asset.source);
|
541
|
-
case 'built-ember':
|
542
|
-
return prior.kind === 'built-ember' && prior.source === asset.source;
|
543
|
-
case 'concatenated-asset':
|
544
|
-
return (prior.kind === 'concatenated-asset' &&
|
545
|
-
prior.sources.length === asset.sources.length &&
|
546
|
-
prior.sources.every((priorFile, index) => {
|
547
|
-
let newFile = asset.sources[index];
|
548
|
-
return this.assetIsValid(newFile, priorFile);
|
549
|
-
}));
|
550
|
-
}
|
551
|
-
}
|
552
|
-
updateOnDiskAsset(asset) {
|
553
|
-
let destination = (0, path_1.join)(this.root, asset.relativePath);
|
554
|
-
(0, fs_extra_1.ensureDirSync)((0, path_1.dirname)(destination));
|
555
|
-
(0, fs_extra_1.copySync)(asset.sourcePath, destination, { dereference: true });
|
556
|
-
}
|
557
|
-
updateInMemoryAsset(asset) {
|
558
|
-
let destination = (0, path_1.join)(this.root, asset.relativePath);
|
559
|
-
(0, fs_extra_1.ensureDirSync)((0, path_1.dirname)(destination));
|
560
|
-
(0, fs_extra_1.writeFileSync)(destination, asset.source, 'utf8');
|
561
|
-
}
|
562
|
-
updateBuiltEmberAsset(asset) {
|
563
|
-
let destination = (0, path_1.join)(this.root, asset.relativePath);
|
564
|
-
(0, fs_extra_1.ensureDirSync)((0, path_1.dirname)(destination));
|
565
|
-
(0, fs_extra_1.writeFileSync)(destination, asset.source, 'utf8');
|
566
|
-
}
|
567
|
-
async updateConcatenatedAsset(asset) {
|
568
|
-
let concat = new fast_sourcemap_concat_1.default({
|
569
|
-
outputFile: (0, path_1.join)(this.root, asset.relativePath),
|
570
|
-
mapCommentType: asset.relativePath.endsWith('.js') ? 'line' : 'block',
|
571
|
-
baseDir: this.root,
|
572
|
-
});
|
573
|
-
if (process.env.EMBROIDER_CONCAT_STATS) {
|
574
|
-
let MeasureConcat = (await Promise.resolve().then(() => __importStar(require('./measure-concat')))).default;
|
575
|
-
concat = new MeasureConcat(asset.relativePath, concat, this.root);
|
576
|
-
}
|
577
|
-
for (let source of asset.sources) {
|
578
|
-
switch (source.kind) {
|
579
|
-
case 'on-disk':
|
580
|
-
concat.addFile((0, shared_internals_1.explicitRelative)(this.root, source.sourcePath));
|
581
|
-
break;
|
582
|
-
case 'in-memory':
|
583
|
-
if (typeof source.source !== 'string') {
|
584
|
-
throw new Error(`attempted to concatenated a Buffer-backed in-memory asset`);
|
585
|
-
}
|
586
|
-
concat.addSpace(source.source);
|
587
|
-
break;
|
588
|
-
default:
|
589
|
-
(0, assert_never_1.default)(source);
|
590
|
-
}
|
591
|
-
}
|
592
|
-
await concat.end();
|
593
|
-
}
|
594
|
-
async updateAssets(requestedAssets, appFiles, emberENV) {
|
595
|
-
let assets = this.prepareAssets(requestedAssets, appFiles, emberENV);
|
596
|
-
for (let asset of assets.values()) {
|
597
|
-
if (this.assetIsValid(asset, this.assets.get(asset.relativePath))) {
|
598
|
-
continue;
|
599
|
-
}
|
600
|
-
(0, messages_1.debug)('rebuilding %s', asset.relativePath);
|
601
|
-
switch (asset.kind) {
|
602
|
-
case 'on-disk':
|
603
|
-
this.updateOnDiskAsset(asset);
|
604
|
-
break;
|
605
|
-
case 'in-memory':
|
606
|
-
this.updateInMemoryAsset(asset);
|
607
|
-
break;
|
608
|
-
case 'built-ember':
|
609
|
-
this.updateBuiltEmberAsset(asset);
|
610
|
-
break;
|
611
|
-
case 'concatenated-asset':
|
612
|
-
await this.updateConcatenatedAsset(asset);
|
613
|
-
break;
|
614
|
-
default:
|
615
|
-
(0, assert_never_1.default)(asset);
|
616
|
-
}
|
617
|
-
}
|
618
|
-
for (let oldAsset of this.assets.values()) {
|
619
|
-
if (!assets.has(oldAsset.relativePath)) {
|
620
|
-
(0, fs_extra_1.unlinkSync)((0, path_1.join)(this.root, oldAsset.relativePath));
|
621
|
-
}
|
622
|
-
}
|
623
|
-
this.assets = assets;
|
624
|
-
return [...assets.values()];
|
625
|
-
}
|
626
|
-
gatherAssets(inputPaths) {
|
627
|
-
// first gather all the assets out of addons
|
628
|
-
let assets = [];
|
629
|
-
for (let pkg of this.adapter.allActiveAddons) {
|
630
|
-
if (pkg.meta['public-assets']) {
|
631
|
-
for (let [filename, appRelativeURL] of Object.entries(pkg.meta['public-assets'] || {})) {
|
632
|
-
let sourcePath = (0, path_1.resolve)(pkg.root, filename);
|
633
|
-
let stats = (0, fs_extra_1.statSync)(sourcePath);
|
634
|
-
assets.push({
|
635
|
-
kind: 'on-disk',
|
636
|
-
sourcePath,
|
637
|
-
relativePath: appRelativeURL,
|
638
|
-
mtime: stats.mtimeMs,
|
639
|
-
size: stats.size,
|
640
|
-
});
|
641
|
-
}
|
642
|
-
}
|
643
|
-
}
|
644
|
-
if (this.activeFastboot) {
|
645
|
-
const source = `
|
646
|
-
(function(){
|
647
|
-
var key = '_embroider_macros_runtime_config';
|
648
|
-
if (!window[key]){ window[key] = [];}
|
649
|
-
window[key].push(function(m) {
|
650
|
-
m.setGlobalConfig('fastboot', Object.assign({}, m.getGlobalConfig().fastboot, { isRunning: true }));
|
651
|
-
});
|
652
|
-
}())`;
|
653
|
-
assets.push({
|
654
|
-
kind: 'in-memory',
|
655
|
-
source,
|
656
|
-
relativePath: 'assets/embroider_macros_fastboot_init.js',
|
657
|
-
});
|
658
|
-
}
|
659
|
-
// and finally tack on the ones from our app itself
|
660
|
-
return assets.concat(this.adapter.assets(inputPaths));
|
661
|
-
}
|
662
|
-
async build(inputPaths) {
|
663
|
-
if (this.adapter.env !== 'production') {
|
664
|
-
this.macrosConfig.enablePackageDevelopment(this.root);
|
665
|
-
this.macrosConfig.enableRuntimeMode();
|
666
|
-
}
|
667
|
-
for (let pkgRoot of this.adapter.developingAddons()) {
|
668
|
-
this.macrosConfig.enablePackageDevelopment(pkgRoot);
|
669
|
-
}
|
670
|
-
// on the first build, we lock down the macros config. on subsequent builds,
|
671
|
-
// this doesn't do anything anyway because it's idempotent.
|
672
|
-
this.macrosConfig.finalize();
|
673
|
-
let appFiles = this.updateAppJS(inputPaths);
|
674
|
-
let emberENV = this.adapter.emberENV();
|
675
|
-
let assets = this.gatherAssets(inputPaths);
|
676
|
-
let finalAssets = await this.updateAssets(assets, appFiles, emberENV);
|
677
|
-
let assetPaths = assets.map(asset => asset.relativePath);
|
678
|
-
if (this.activeFastboot) {
|
679
|
-
// when using fastboot, our own package.json needs to be in the output so fastboot can read it.
|
680
|
-
assetPaths.push('package.json');
|
681
|
-
}
|
682
|
-
for (let asset of finalAssets) {
|
683
|
-
// our concatenated assets all have map files that ride along. Here we're
|
684
|
-
// telling the final stage packager to be sure and serve the map files
|
685
|
-
// too.
|
686
|
-
if (asset.kind === 'concatenated-asset') {
|
687
|
-
assetPaths.push(asset.sourcemapPath);
|
688
|
-
}
|
689
|
-
}
|
690
|
-
let meta = {
|
691
|
-
type: 'app',
|
692
|
-
version: 2,
|
693
|
-
assets: assetPaths,
|
694
|
-
babel: {
|
695
|
-
filename: '_babel_config_.js',
|
696
|
-
isParallelSafe: true,
|
697
|
-
majorVersion: this.adapter.babelMajorVersion(),
|
698
|
-
fileFilter: '_babel_filter_.js',
|
699
|
-
},
|
700
|
-
'root-url': this.adapter.rootURL(),
|
701
|
-
};
|
702
|
-
if (!this.adapter.strictV2Format()) {
|
703
|
-
meta['auto-upgraded'] = true;
|
704
|
-
}
|
705
|
-
let pkg = this.combinePackageJSON(meta);
|
706
|
-
(0, fs_extra_1.writeFileSync)((0, path_1.join)(this.root, 'package.json'), JSON.stringify(pkg, null, 2), 'utf8');
|
707
|
-
let resolverConfig = this.adapter.resolverConfig(appFiles);
|
708
|
-
this.addResolverConfig(resolverConfig);
|
709
|
-
let babelConfig = this.babelConfig(resolverConfig);
|
710
|
-
this.addBabelConfig(babelConfig);
|
711
|
-
}
|
712
|
-
combinePackageJSON(meta) {
|
713
|
-
let pkgLayers = [this.app.packageJSON];
|
714
|
-
let fastbootConfig = this.fastbootConfig;
|
715
|
-
if (fastbootConfig) {
|
716
|
-
// fastboot-specific package.json output is allowed to add to our original package.json
|
717
|
-
pkgLayers.push(fastbootConfig.packageJSON);
|
718
|
-
}
|
719
|
-
// but our own new v2 app metadata takes precedence over both
|
720
|
-
pkgLayers.push({ keywords: ['ember-addon'], 'ember-addon': meta });
|
721
|
-
return combinePackageJSON(...pkgLayers);
|
722
|
-
}
|
723
|
-
etcOptions(resolverConfig) {
|
724
|
-
let transforms = this.adapter.htmlbarsPlugins();
|
725
|
-
let { plugins: macroPlugins, setConfig } = node_1.MacrosConfig.transforms();
|
726
|
-
setConfig(this.macrosConfig);
|
727
|
-
for (let macroPlugin of macroPlugins) {
|
728
|
-
transforms.push(macroPlugin);
|
729
|
-
}
|
730
|
-
for (let t of this.adapter.hbsTransforms(resolverConfig)) {
|
731
|
-
transforms.push(t);
|
732
|
-
}
|
733
|
-
return {
|
734
|
-
transforms,
|
735
|
-
compilerPath: resolve_1.default.sync(this.adapter.templateCompilerPath(), { basedir: this.root }),
|
736
|
-
enableLegacyModules: ['ember-cli-htmlbars', 'ember-cli-htmlbars-inline-precompile', 'htmlbars-inline-precompile'],
|
737
|
-
};
|
738
|
-
}
|
739
|
-
get portableHints() {
|
740
|
-
return this.options.pluginHints.map(hint => {
|
741
|
-
let cursor = (0, path_1.join)(this.app.root, 'package.json');
|
742
|
-
for (let i = 0; i < hint.resolve.length; i++) {
|
743
|
-
let target = hint.resolve[i];
|
744
|
-
if (i < hint.resolve.length - 1) {
|
745
|
-
target = (0, path_1.join)(target, 'package.json');
|
746
|
-
}
|
747
|
-
cursor = resolve_1.default.sync(target, { basedir: (0, path_1.dirname)(cursor) });
|
748
|
-
}
|
749
|
-
return {
|
750
|
-
requireFile: cursor,
|
751
|
-
useMethod: hint.useMethod,
|
752
|
-
packageVersion: (0, portable_1.maybeNodeModuleVersion)(cursor),
|
753
|
-
};
|
754
|
-
});
|
755
|
-
}
|
756
|
-
addBabelConfig(pconfig) {
|
757
|
-
if (!pconfig.isParallelSafe) {
|
758
|
-
(0, messages_1.warn)('Your build is slower because some babel plugins are non-serializable');
|
759
|
-
}
|
760
|
-
(0, fs_extra_1.writeFileSync)((0, path_1.join)(this.root, '_babel_config_.js'), `module.exports = ${JSON.stringify(pconfig.config, null, 2)}`, 'utf8');
|
761
|
-
(0, fs_extra_1.writeFileSync)((0, path_1.join)(this.root, '_babel_filter_.js'), babelFilterTemplate({ skipBabel: this.options.skipBabel, appRoot: this.root }), 'utf8');
|
762
|
-
}
|
763
|
-
addResolverConfig(config) {
|
764
|
-
(0, fs_extra_1.outputJSONSync)((0, path_1.join)(this.root, '.embroider', 'resolver.json'), config);
|
765
|
-
}
|
766
|
-
shouldSplitRoute(routeName) {
|
767
|
-
return (!this.options.splitAtRoutes ||
|
768
|
-
this.options.splitAtRoutes.find(pattern => {
|
769
|
-
if (typeof pattern === 'string') {
|
770
|
-
return pattern === routeName;
|
771
|
-
}
|
772
|
-
else {
|
773
|
-
return pattern.test(routeName);
|
774
|
-
}
|
775
|
-
}));
|
776
|
-
}
|
777
|
-
splitRoute(routeName, files, addToParent, addLazyBundle) {
|
778
|
-
let shouldSplit = routeName && this.shouldSplitRoute(routeName);
|
779
|
-
let ownFiles = [];
|
780
|
-
let ownNames = new Set();
|
781
|
-
if (files.template) {
|
782
|
-
if (shouldSplit) {
|
783
|
-
ownFiles.push(files.template);
|
784
|
-
ownNames.add(routeName);
|
785
|
-
}
|
786
|
-
else {
|
787
|
-
addToParent(routeName, files.template);
|
788
|
-
}
|
789
|
-
}
|
790
|
-
if (files.controller) {
|
791
|
-
if (shouldSplit) {
|
792
|
-
ownFiles.push(files.controller);
|
793
|
-
ownNames.add(routeName);
|
794
|
-
}
|
795
|
-
else {
|
796
|
-
addToParent(routeName, files.controller);
|
797
|
-
}
|
798
|
-
}
|
799
|
-
if (files.route) {
|
800
|
-
if (shouldSplit) {
|
801
|
-
ownFiles.push(files.route);
|
802
|
-
ownNames.add(routeName);
|
803
|
-
}
|
804
|
-
else {
|
805
|
-
addToParent(routeName, files.route);
|
806
|
-
}
|
807
|
-
}
|
808
|
-
for (let [childName, childFiles] of files.children) {
|
809
|
-
this.splitRoute(`${routeName}.${childName}`, childFiles, (childRouteName, childFile) => {
|
810
|
-
// this is our child calling "addToParent"
|
811
|
-
if (shouldSplit) {
|
812
|
-
ownFiles.push(childFile);
|
813
|
-
ownNames.add(childRouteName);
|
814
|
-
}
|
815
|
-
else {
|
816
|
-
addToParent(childRouteName, childFile);
|
817
|
-
}
|
818
|
-
}, (routeNames, files) => {
|
819
|
-
addLazyBundle(routeNames, files);
|
820
|
-
});
|
821
|
-
}
|
822
|
-
if (ownFiles.length > 0) {
|
823
|
-
addLazyBundle([...ownNames], ownFiles);
|
824
|
-
}
|
825
|
-
}
|
826
|
-
topAppJSAsset(engines, prepared) {
|
827
|
-
let [app, ...childEngines] = engines;
|
828
|
-
let relativePath = `assets/${this.app.name}.js`;
|
829
|
-
return this.appJSAsset(relativePath, app, childEngines, prepared, {
|
830
|
-
autoRun: this.adapter.autoRun(),
|
831
|
-
appBoot: !this.adapter.autoRun() ? this.adapter.appBoot() : '',
|
832
|
-
mainModule: (0, shared_internals_1.explicitRelative)((0, path_1.dirname)(relativePath), this.adapter.mainModule()),
|
833
|
-
appConfig: this.adapter.mainModuleConfig(),
|
834
|
-
});
|
835
|
-
}
|
836
|
-
get staticAppPathsPattern() {
|
837
|
-
if (this.options.staticAppPaths.length > 0) {
|
838
|
-
return new RegExp('^(?:' + this.options.staticAppPaths.map(staticAppPath => (0, escape_string_regexp_1.default)(staticAppPath)).join('|') + ')(?:$|/)');
|
839
|
-
}
|
840
|
-
}
|
841
|
-
requiredOtherFiles(appFiles) {
|
842
|
-
let pattern = this.staticAppPathsPattern;
|
843
|
-
if (pattern) {
|
844
|
-
return appFiles.otherAppFiles.filter(f => {
|
845
|
-
return !pattern.test(f);
|
846
|
-
});
|
847
|
-
}
|
848
|
-
else {
|
849
|
-
return appFiles.otherAppFiles;
|
850
|
-
}
|
851
|
-
}
|
852
|
-
appJSAsset(relativePath, engine, childEngines, prepared, entryParams) {
|
853
|
-
let { appFiles } = engine;
|
854
|
-
let cached = prepared.get(relativePath);
|
855
|
-
if (cached) {
|
856
|
-
return cached;
|
857
|
-
}
|
858
|
-
let eagerModules = [];
|
859
|
-
let requiredAppFiles = [this.requiredOtherFiles(appFiles)];
|
860
|
-
if (!this.options.staticComponents) {
|
861
|
-
requiredAppFiles.push(appFiles.components);
|
862
|
-
}
|
863
|
-
if (!this.options.staticHelpers) {
|
864
|
-
requiredAppFiles.push(appFiles.helpers);
|
865
|
-
}
|
866
|
-
if (!this.options.staticModifiers) {
|
867
|
-
requiredAppFiles.push(appFiles.modifiers);
|
868
|
-
}
|
869
|
-
let styles = [];
|
870
|
-
// only import styles from engines with a parent (this excludeds the parent application) as their styles
|
871
|
-
// will be inserted via a direct <link> tag.
|
872
|
-
if (engine.parent && engine.package.isLazyEngine()) {
|
873
|
-
let implicitStyles = this.impliedAssets('implicit-styles', engine);
|
874
|
-
for (let style of implicitStyles) {
|
875
|
-
styles.push({
|
876
|
-
path: (0, shared_internals_1.explicitRelative)('assets/_engine_', style.relativePath),
|
877
|
-
});
|
878
|
-
}
|
879
|
-
let engineMeta = engine.package.meta;
|
880
|
-
if (engineMeta && engineMeta['implicit-styles']) {
|
881
|
-
for (let style of engineMeta['implicit-styles']) {
|
882
|
-
styles.push({
|
883
|
-
path: (0, shared_internals_1.explicitRelative)((0, path_1.dirname)(relativePath), (0, path_1.join)(engine.appRelativePath, style)),
|
884
|
-
});
|
885
|
-
}
|
886
|
-
}
|
887
|
-
}
|
888
|
-
let lazyEngines = [];
|
889
|
-
for (let childEngine of childEngines) {
|
890
|
-
let asset = this.appJSAsset(`assets/_engine_/${encodeURIComponent(childEngine.package.name)}.js`, childEngine, [], prepared);
|
891
|
-
if (childEngine.package.isLazyEngine()) {
|
892
|
-
lazyEngines.push({
|
893
|
-
names: [childEngine.package.name],
|
894
|
-
path: (0, shared_internals_1.explicitRelative)((0, path_1.dirname)(relativePath), asset.relativePath),
|
895
|
-
});
|
896
|
-
}
|
897
|
-
else {
|
898
|
-
eagerModules.push((0, shared_internals_1.explicitRelative)((0, path_1.dirname)(relativePath), asset.relativePath));
|
899
|
-
}
|
900
|
-
}
|
901
|
-
let lazyRoutes = [];
|
902
|
-
for (let [routeName, routeFiles] of appFiles.routeFiles.children) {
|
903
|
-
this.splitRoute(routeName, routeFiles, (_, filename) => {
|
904
|
-
requiredAppFiles.push([filename]);
|
905
|
-
}, (routeNames, files) => {
|
906
|
-
let routeEntrypoint = `assets/_route_/${encodeURIComponent(routeNames[0])}.js`;
|
907
|
-
if (!prepared.has(routeEntrypoint)) {
|
908
|
-
prepared.set(routeEntrypoint, this.routeEntrypoint(engine, routeEntrypoint, files));
|
909
|
-
}
|
910
|
-
lazyRoutes.push({
|
911
|
-
names: routeNames,
|
912
|
-
path: this.importPaths(engine, routeEntrypoint).buildtime,
|
913
|
-
});
|
914
|
-
});
|
915
|
-
}
|
916
|
-
let [fastboot, nonFastboot] = (0, partition_1.default)(excludeDotFiles((0, flatten_1.default)(requiredAppFiles)), file => appFiles.isFastbootOnly.get(file));
|
917
|
-
let amdModules = nonFastboot.map(file => this.importPaths(engine, file));
|
918
|
-
let fastbootOnlyAmdModules = fastboot.map(file => this.importPaths(engine, file));
|
919
|
-
// this is a backward-compatibility feature: addons can force inclusion of
|
920
|
-
// modules.
|
921
|
-
this.gatherImplicitModules('implicit-modules', engine, amdModules);
|
922
|
-
let params = { amdModules, fastbootOnlyAmdModules, lazyRoutes, lazyEngines, eagerModules, styles };
|
923
|
-
if (entryParams) {
|
924
|
-
Object.assign(params, entryParams);
|
925
|
-
}
|
926
|
-
let source = entryTemplate(params);
|
927
|
-
let asset = {
|
928
|
-
kind: 'in-memory',
|
929
|
-
source,
|
930
|
-
relativePath,
|
931
|
-
};
|
932
|
-
prepared.set(relativePath, asset);
|
933
|
-
return asset;
|
934
|
-
}
|
935
|
-
get modulePrefix() {
|
936
|
-
return this.adapter.modulePrefix();
|
937
|
-
}
|
938
|
-
importPaths(engine, engineRelativePath) {
|
939
|
-
let noHBS = engineRelativePath.replace(this.resolvableExtensionsPattern, '').replace(/\.hbs$/, '');
|
940
|
-
return {
|
941
|
-
runtime: `${engine.modulePrefix}/${noHBS}`,
|
942
|
-
buildtime: path_1.posix.join(engine.package.name, engineRelativePath),
|
943
|
-
};
|
944
|
-
}
|
945
|
-
routeEntrypoint(engine, relativePath, files) {
|
946
|
-
let [fastboot, nonFastboot] = (0, partition_1.default)(files, file => engine.appFiles.isFastbootOnly.get(file));
|
947
|
-
let asset = {
|
948
|
-
kind: 'in-memory',
|
949
|
-
source: routeEntryTemplate({
|
950
|
-
files: nonFastboot.map(f => this.importPaths(engine, f)),
|
951
|
-
fastbootOnlyFiles: fastboot.map(f => this.importPaths(engine, f)),
|
952
|
-
}),
|
953
|
-
relativePath,
|
954
|
-
};
|
955
|
-
return asset;
|
956
|
-
}
|
957
|
-
testJSEntrypoint(engines, prepared) {
|
958
|
-
let asset = prepared.get(`assets/test.js`);
|
959
|
-
if (asset) {
|
960
|
-
return asset;
|
961
|
-
}
|
962
|
-
// We're only building tests from the first engine (the app). This is the
|
963
|
-
// normal thing to do -- tests from engines don't automatically roll up into
|
964
|
-
// the app.
|
965
|
-
let engine = engines[0];
|
966
|
-
const myName = 'assets/test.js';
|
967
|
-
// tests necessarily also include the app. This is where we account for
|
968
|
-
// that. The classic solution was to always include the app's separate
|
969
|
-
// script tag in the tests HTML, but that isn't as easy for final stage
|
970
|
-
// packagers to understand. It's better to express it here as a direct
|
971
|
-
// module dependency.
|
972
|
-
let eagerModules = [
|
973
|
-
(0, shared_internals_1.explicitRelative)((0, path_1.dirname)(myName), this.topAppJSAsset(engines, prepared).relativePath),
|
974
|
-
];
|
975
|
-
let amdModules = [];
|
976
|
-
// this is a backward-compatibility feature: addons can force inclusion of
|
977
|
-
// test support modules.
|
978
|
-
this.gatherImplicitModules('implicit-test-modules', engine, amdModules);
|
979
|
-
let { appFiles } = engine;
|
980
|
-
for (let relativePath of appFiles.tests) {
|
981
|
-
amdModules.push(this.importPaths(engine, relativePath));
|
982
|
-
}
|
983
|
-
let source = entryTemplate({
|
984
|
-
amdModules,
|
985
|
-
eagerModules,
|
986
|
-
testSuffix: true,
|
987
|
-
});
|
988
|
-
asset = {
|
989
|
-
kind: 'in-memory',
|
990
|
-
source,
|
991
|
-
relativePath: myName,
|
992
|
-
};
|
993
|
-
prepared.set(asset.relativePath, asset);
|
994
|
-
return asset;
|
995
|
-
}
|
996
|
-
gatherImplicitModules(section, engine, lazyModules) {
|
997
|
-
for (let addon of engine.addons) {
|
998
|
-
let implicitModules = addon.meta[section];
|
999
|
-
if (implicitModules) {
|
1000
|
-
let renamedModules = inverseRenamedModules(addon.meta, this.resolvableExtensionsPattern);
|
1001
|
-
for (let name of implicitModules) {
|
1002
|
-
let packageName = addon.name;
|
1003
|
-
if (addon.isV2Addon()) {
|
1004
|
-
let renamedMeta = addon.meta['renamed-packages'];
|
1005
|
-
if (renamedMeta) {
|
1006
|
-
Object.entries(renamedMeta).forEach(([key, value]) => {
|
1007
|
-
if (value === addon.name) {
|
1008
|
-
packageName = key;
|
1009
|
-
}
|
1010
|
-
});
|
1011
|
-
}
|
1012
|
-
}
|
1013
|
-
let runtime = (0, path_1.join)(packageName, name).replace(this.resolvableExtensionsPattern, '');
|
1014
|
-
let runtimeRenameLookup = runtime.split('\\').join('/');
|
1015
|
-
if (renamedModules && renamedModules[runtimeRenameLookup]) {
|
1016
|
-
runtime = renamedModules[runtimeRenameLookup];
|
1017
|
-
}
|
1018
|
-
runtime = runtime.split(path_1.sep).join('/');
|
1019
|
-
lazyModules.push({
|
1020
|
-
runtime,
|
1021
|
-
buildtime: path_1.posix.join(packageName, name),
|
1022
|
-
});
|
1023
|
-
}
|
1024
|
-
}
|
1025
|
-
}
|
1026
|
-
}
|
1027
|
-
}
|
1028
|
-
__decorate([
|
1029
|
-
(0, typescript_memoize_1.Memoize)()
|
1030
|
-
], AppBuilder.prototype, "resolvableExtensionsPattern", null);
|
1031
|
-
__decorate([
|
1032
|
-
(0, typescript_memoize_1.Memoize)()
|
1033
|
-
], AppBuilder.prototype, "babelParserConfig", null);
|
1034
|
-
__decorate([
|
1035
|
-
(0, typescript_memoize_1.Memoize)()
|
1036
|
-
], AppBuilder.prototype, "babelConfig", null);
|
1037
|
-
__decorate([
|
1038
|
-
(0, typescript_memoize_1.Memoize)()
|
1039
|
-
], AppBuilder.prototype, "activeFastboot", null);
|
1040
|
-
__decorate([
|
1041
|
-
(0, typescript_memoize_1.Memoize)()
|
1042
|
-
], AppBuilder.prototype, "fastbootConfig", null);
|
1043
|
-
__decorate([
|
1044
|
-
(0, typescript_memoize_1.Memoize)()
|
1045
|
-
], AppBuilder.prototype, "portableHints", null);
|
1046
|
-
__decorate([
|
1047
|
-
(0, typescript_memoize_1.Memoize)()
|
1048
|
-
], AppBuilder.prototype, "staticAppPathsPattern", null);
|
1049
|
-
__decorate([
|
1050
|
-
(0, typescript_memoize_1.Memoize)()
|
1051
|
-
], AppBuilder.prototype, "modulePrefix", null);
|
1052
|
-
exports.AppBuilder = AppBuilder;
|
1053
|
-
const entryTemplate = (0, js_handlebars_1.compile)(`
|
1054
|
-
import { importSync as i, macroCondition, getGlobalConfig } from '@embroider/macros';
|
1055
|
-
let w = window;
|
1056
|
-
let d = w.define;
|
1057
|
-
|
1058
|
-
{{#if styles}}
|
1059
|
-
if (macroCondition(!getGlobalConfig().fastboot?.isRunning)) {
|
1060
|
-
{{#each styles as |stylePath| ~}}
|
1061
|
-
i("{{js-string-escape stylePath.path}}");
|
1062
|
-
{{/each}}
|
1063
|
-
}
|
1064
|
-
{{/if}}
|
1065
|
-
|
1066
|
-
{{#each amdModules as |amdModule| ~}}
|
1067
|
-
d("{{js-string-escape amdModule.runtime}}", function(){ return i("{{js-string-escape amdModule.buildtime}}");});
|
1068
|
-
{{/each}}
|
1069
|
-
|
1070
|
-
{{#if fastbootOnlyAmdModules}}
|
1071
|
-
if (macroCondition(getGlobalConfig().fastboot?.isRunning)) {
|
1072
|
-
{{#each fastbootOnlyAmdModules as |amdModule| ~}}
|
1073
|
-
d("{{js-string-escape amdModule.runtime}}", function(){ return i("{{js-string-escape amdModule.buildtime}}");});
|
1074
|
-
{{/each}}
|
1075
|
-
}
|
1076
|
-
{{/if}}
|
1077
|
-
|
1078
|
-
{{#each eagerModules as |eagerModule| ~}}
|
1079
|
-
i("{{js-string-escape eagerModule}}");
|
1080
|
-
{{/each}}
|
1081
|
-
|
1082
|
-
{{#if lazyRoutes}}
|
1083
|
-
w._embroiderRouteBundles_ = [
|
1084
|
-
{{#each lazyRoutes as |route|}}
|
1085
|
-
{
|
1086
|
-
names: {{{json-stringify route.names}}},
|
1087
|
-
load: function() {
|
1088
|
-
return import("{{js-string-escape route.path}}");
|
1089
|
-
}
|
1090
|
-
},
|
1091
|
-
{{/each}}
|
1092
|
-
]
|
1093
|
-
{{/if}}
|
1094
|
-
|
1095
|
-
{{#if lazyEngines}}
|
1096
|
-
w._embroiderEngineBundles_ = [
|
1097
|
-
{{#each lazyEngines as |engine|}}
|
1098
|
-
{
|
1099
|
-
names: {{{json-stringify engine.names}}},
|
1100
|
-
load: function() {
|
1101
|
-
return import("{{js-string-escape engine.path}}");
|
1102
|
-
}
|
1103
|
-
},
|
1104
|
-
{{/each}}
|
1105
|
-
]
|
1106
|
-
{{/if}}
|
1107
|
-
|
1108
|
-
{{#if autoRun ~}}
|
1109
|
-
if (!runningTests) {
|
1110
|
-
i("{{js-string-escape mainModule}}").default.create({{{json-stringify appConfig}}});
|
1111
|
-
}
|
1112
|
-
{{else if appBoot ~}}
|
1113
|
-
{{{ appBoot }}}
|
1114
|
-
{{/if}}
|
1115
|
-
|
1116
|
-
{{#if testSuffix ~}}
|
1117
|
-
{{!- TODO: both of these suffixes should get dynamically generated so they incorporate
|
1118
|
-
any content-for added by addons. -}}
|
1119
|
-
|
1120
|
-
|
1121
|
-
{{!- this is the traditional tests-suffix.js -}}
|
1122
|
-
i('../tests/test-helper');
|
1123
|
-
EmberENV.TESTS_FILE_LOADED = true;
|
1124
|
-
{{/if}}
|
1125
|
-
`);
|
1126
|
-
const routeEntryTemplate = (0, js_handlebars_1.compile)(`
|
1127
|
-
import { importSync as i } from '@embroider/macros';
|
1128
|
-
let d = window.define;
|
1129
|
-
{{#each files as |amdModule| ~}}
|
1130
|
-
d("{{js-string-escape amdModule.runtime}}", function(){ return i("{{js-string-escape amdModule.buildtime}}");});
|
1131
|
-
{{/each}}
|
1132
|
-
{{#if fastbootOnlyFiles}}
|
1133
|
-
import { macroCondition, getGlobalConfig } from '@embroider/macros';
|
1134
|
-
if (macroCondition(getGlobalConfig().fastboot?.isRunning)) {
|
1135
|
-
{{#each fastbootOnlyFiles as |amdModule| ~}}
|
1136
|
-
d("{{js-string-escape amdModule.runtime}}", function(){ return i("{{js-string-escape amdModule.buildtime}}");});
|
1137
|
-
{{/each}}
|
1138
|
-
}
|
1139
|
-
{{/if}}
|
1140
|
-
`);
|
1141
|
-
function stringOrBufferEqual(a, b) {
|
1142
|
-
if (typeof a === 'string' && typeof b === 'string') {
|
1143
|
-
return a === b;
|
1144
|
-
}
|
1145
|
-
if (a instanceof Buffer && b instanceof Buffer) {
|
1146
|
-
return Buffer.compare(a, b) === 0;
|
1147
|
-
}
|
1148
|
-
return false;
|
1149
|
-
}
|
1150
|
-
const babelFilterTemplate = (0, js_handlebars_1.compile)(`
|
1151
|
-
const { babelFilter } = require(${JSON.stringify(require.resolve('./index.js'))});
|
1152
|
-
module.exports = babelFilter({{{json-stringify skipBabel}}}, "{{{js-string-escape appRoot}}}");
|
1153
|
-
`);
|
1154
|
-
// meta['renamed-modules'] has mapping from classic filename to real filename.
|
1155
|
-
// This takes that and converts it to the inverst mapping from real import path
|
1156
|
-
// to classic import path.
|
1157
|
-
function inverseRenamedModules(meta, extensions) {
|
1158
|
-
let renamed = meta['renamed-modules'];
|
1159
|
-
if (renamed) {
|
1160
|
-
let inverted = {};
|
1161
|
-
for (let [classic, real] of Object.entries(renamed)) {
|
1162
|
-
inverted[real.replace(extensions, '')] = classic.replace(extensions, '');
|
1163
|
-
}
|
1164
|
-
return inverted;
|
1165
|
-
}
|
1166
|
-
}
|
1167
|
-
function combinePackageJSON(...layers) {
|
1168
|
-
function custom(objValue, srcValue, key, _object, _source, stack) {
|
1169
|
-
if (key === 'keywords' && stack.size === 0) {
|
1170
|
-
if (Array.isArray(objValue)) {
|
1171
|
-
return objValue.concat(srcValue);
|
1172
|
-
}
|
1173
|
-
}
|
1174
|
-
}
|
1175
|
-
return (0, mergeWith_1.default)({}, ...layers, custom);
|
1176
|
-
}
|
1177
|
-
//# sourceMappingURL=app.js.map
|