@embroider/core 3.1.4-unstable.5fd7c48 → 3.1.4-unstable.7407f3a
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 +3 -3
- package/src/index.d.ts +1 -0
- package/src/index.js +3 -1
- package/src/index.js.map +1 -1
- package/src/module-resolver.d.ts +12 -7
- package/src/module-resolver.js +84 -45
- package/src/module-resolver.js.map +1 -1
- package/src/options.d.ts +3 -0
- package/src/options.js +1 -1
- package/src/options.js.map +1 -1
- package/src/resolver-loader.d.ts +8 -0
- package/src/resolver-loader.js +48 -0
- package/src/resolver-loader.js.map +1 -0
- package/src/virtual-content.d.ts +8 -2
- package/src/virtual-content.js +183 -24
- package/src/virtual-content.js.map +1 -1
package/src/virtual-content.js
CHANGED
@@ -1,17 +1,23 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.decodeFastbootSwitch = exports.fastbootSwitch = exports.virtualPairComponent = exports.
|
3
|
+
exports.decodeImplicitModules = exports.decodeFastbootSwitch = exports.fastbootSwitch = exports.virtualPairComponent = exports.virtualExternalCJSModule = exports.virtualExternalESModule = exports.virtualContent = void 0;
|
4
4
|
const path_1 = require("path");
|
5
5
|
const _1 = require(".");
|
6
6
|
const js_handlebars_1 = require("./js-handlebars");
|
7
|
-
const
|
7
|
+
const externalESPrefix = '/@embroider/ext-es/';
|
8
|
+
const externalCJSPrefix = '/@embroider/ext-cjs/';
|
8
9
|
// Given a filename that was passed to your ModuleRequest's `virtualize()`,
|
9
10
|
// this produces the corresponding contents. It's a static, stateless function
|
10
11
|
// because we recognize that that process that did resolution might not be the
|
11
12
|
// same one that loads the content.
|
12
|
-
function virtualContent(filename) {
|
13
|
-
|
14
|
-
|
13
|
+
function virtualContent(filename, resolver) {
|
14
|
+
let cjsExtern = decodeVirtualExternalCJSModule(filename);
|
15
|
+
if (cjsExtern) {
|
16
|
+
return renderCJSExternalShim(cjsExtern);
|
17
|
+
}
|
18
|
+
let extern = decodeVirtualExternalESModule(filename);
|
19
|
+
if (extern) {
|
20
|
+
return renderESExternalShim(extern);
|
15
21
|
}
|
16
22
|
let match = decodeVirtualPairComponent(filename);
|
17
23
|
if (match) {
|
@@ -21,31 +27,37 @@ function virtualContent(filename) {
|
|
21
27
|
if (fb) {
|
22
28
|
return fastbootSwitchTemplate(fb);
|
23
29
|
}
|
30
|
+
let im = decodeImplicitModules(filename);
|
31
|
+
if (im) {
|
32
|
+
return renderImplicitModules(im, resolver);
|
33
|
+
}
|
24
34
|
throw new Error(`not an @embroider/core virtual file: ${filename}`);
|
25
35
|
}
|
26
36
|
exports.virtualContent = virtualContent;
|
27
|
-
const
|
37
|
+
const externalESShim = (0, js_handlebars_1.compile)(`
|
28
38
|
{{#if (eq moduleName "require")}}
|
29
39
|
const m = window.requirejs;
|
40
|
+
export default m;
|
41
|
+
const has = m.has;
|
42
|
+
export { has }
|
30
43
|
{{else}}
|
31
44
|
const m = window.require("{{{js-string-escape moduleName}}}");
|
45
|
+
{{#if default}}
|
46
|
+
export default m.default;
|
47
|
+
{{/if}}
|
48
|
+
{{#if names}}
|
49
|
+
const { {{#each names as |name|}}{{name}}, {{/each}} } = m;
|
50
|
+
export { {{#each names as |name|}}{{name}}, {{/each}} }
|
51
|
+
{{/if}}
|
32
52
|
{{/if}}
|
33
|
-
{{!-
|
34
|
-
There are plenty of hand-written AMD defines floating around
|
35
|
-
that lack this, and they will break when other build systems
|
36
|
-
encounter them.
|
37
|
-
|
38
|
-
As far as I can tell, Ember's loader was already treating this
|
39
|
-
case as a module, so in theory we aren't breaking anything by
|
40
|
-
marking it as such when other packagers come looking.
|
41
|
-
|
42
|
-
todo: get review on this part.
|
43
|
-
-}}
|
44
|
-
if (m.default && !m.__esModule) {
|
45
|
-
m.__esModule = true;
|
46
|
-
}
|
47
|
-
module.exports = m;
|
48
53
|
`);
|
54
|
+
function renderESExternalShim({ moduleName, exports }) {
|
55
|
+
return externalESShim({
|
56
|
+
moduleName,
|
57
|
+
default: exports.includes('default'),
|
58
|
+
names: exports.filter(n => n !== 'default'),
|
59
|
+
});
|
60
|
+
}
|
49
61
|
const pairedComponentShim = (0, js_handlebars_1.compile)(`
|
50
62
|
import { setComponentTemplate } from "@ember/component";
|
51
63
|
import template from "{{{js-string-escape relativeHBSModule}}}";
|
@@ -57,10 +69,36 @@ import templateOnlyComponent from "@ember/component/template-only";
|
|
57
69
|
export default setComponentTemplate(template, templateOnlyComponent(undefined, "{{{js-string-escape debugName}}}"));
|
58
70
|
{{/if}}
|
59
71
|
`);
|
60
|
-
function
|
61
|
-
|
72
|
+
function virtualExternalESModule(specifier, exports) {
|
73
|
+
if (exports) {
|
74
|
+
return externalESPrefix + specifier + `?exports=${exports.join(',')}`;
|
75
|
+
}
|
76
|
+
else {
|
77
|
+
return externalESPrefix + specifier;
|
78
|
+
}
|
79
|
+
}
|
80
|
+
exports.virtualExternalESModule = virtualExternalESModule;
|
81
|
+
function virtualExternalCJSModule(specifier) {
|
82
|
+
return externalCJSPrefix + specifier;
|
83
|
+
}
|
84
|
+
exports.virtualExternalCJSModule = virtualExternalCJSModule;
|
85
|
+
function decodeVirtualExternalESModule(filename) {
|
86
|
+
if (filename.startsWith(externalESPrefix)) {
|
87
|
+
let exports = [];
|
88
|
+
let url = new URL(filename.slice(externalESPrefix.length), 'http://example.com');
|
89
|
+
let nameString = url.searchParams.get('exports');
|
90
|
+
if (nameString) {
|
91
|
+
exports = nameString.split(',');
|
92
|
+
}
|
93
|
+
let moduleName = url.pathname.slice(1);
|
94
|
+
return { moduleName, exports };
|
95
|
+
}
|
96
|
+
}
|
97
|
+
function decodeVirtualExternalCJSModule(filename) {
|
98
|
+
if (filename.startsWith(externalCJSPrefix)) {
|
99
|
+
return { moduleName: filename.slice(externalCJSPrefix.length) };
|
100
|
+
}
|
62
101
|
}
|
63
|
-
exports.virtualExternalModule = virtualExternalModule;
|
64
102
|
const pairComponentMarker = '/embroider-pair-component';
|
65
103
|
const pairComponentPattern = /^(?<hbsModule>.*)\/(?<jsModule>[^\/]*)\/embroider-pair-component$/;
|
66
104
|
function virtualPairComponent(hbsModule, jsModule) {
|
@@ -128,4 +166,125 @@ export default mod.default;
|
|
128
166
|
export const {{name}} = mod.{{name}};
|
129
167
|
{{/each}}
|
130
168
|
`);
|
169
|
+
const implicitModulesPattern = /(?<filename>.*)[\\/]-embroider-implicit-(?<test>test-)?modules\.js$/;
|
170
|
+
function decodeImplicitModules(filename) {
|
171
|
+
let m = implicitModulesPattern.exec(filename);
|
172
|
+
if (m) {
|
173
|
+
return {
|
174
|
+
type: m.groups.test ? 'implicit-test-modules' : 'implicit-modules',
|
175
|
+
fromFile: m.groups.filename,
|
176
|
+
};
|
177
|
+
}
|
178
|
+
}
|
179
|
+
exports.decodeImplicitModules = decodeImplicitModules;
|
180
|
+
function renderImplicitModules({ type, fromFile, }, resolver) {
|
181
|
+
let resolvableExtensionsPattern = (0, _1.extensionsPattern)(resolver.options.resolvableExtensions);
|
182
|
+
const pkg = resolver.packageCache.ownerOfFile(fromFile);
|
183
|
+
if (!(pkg === null || pkg === void 0 ? void 0 : pkg.isV2Ember())) {
|
184
|
+
throw new Error(`bug: saw special implicit modules import in non-ember package at ${fromFile}`);
|
185
|
+
}
|
186
|
+
let lazyModules = [];
|
187
|
+
let eagerModules = [];
|
188
|
+
let deps = pkg.dependencies.sort(orderAddons);
|
189
|
+
for (let dep of deps) {
|
190
|
+
// anything that isn't a v2 ember package by this point is not an active
|
191
|
+
// addon.
|
192
|
+
if (!dep.isV2Addon()) {
|
193
|
+
continue;
|
194
|
+
}
|
195
|
+
// we ignore peerDependencies here because classic ember-cli ignores
|
196
|
+
// peerDependencies here, and we're implementing the implicit-modules
|
197
|
+
// backward-comptibility feature.
|
198
|
+
if (pkg.categorizeDependency(dep.name) === 'peerDependencies') {
|
199
|
+
continue;
|
200
|
+
}
|
201
|
+
let implicitModules = dep.meta[type];
|
202
|
+
if (implicitModules) {
|
203
|
+
let renamedModules = inverseRenamedModules(dep.meta, resolvableExtensionsPattern);
|
204
|
+
for (let name of implicitModules) {
|
205
|
+
let packageName = dep.name;
|
206
|
+
let renamedMeta = dep.meta['renamed-packages'];
|
207
|
+
if (renamedMeta) {
|
208
|
+
Object.entries(renamedMeta).forEach(([key, value]) => {
|
209
|
+
if (value === dep.name) {
|
210
|
+
packageName = key;
|
211
|
+
}
|
212
|
+
});
|
213
|
+
}
|
214
|
+
let runtime = (0, path_1.join)(packageName, name).replace(resolvableExtensionsPattern, '');
|
215
|
+
let runtimeRenameLookup = runtime.split('\\').join('/');
|
216
|
+
if (renamedModules && renamedModules[runtimeRenameLookup]) {
|
217
|
+
runtime = renamedModules[runtimeRenameLookup];
|
218
|
+
}
|
219
|
+
runtime = runtime.split(path_1.sep).join('/');
|
220
|
+
lazyModules.push({
|
221
|
+
runtime,
|
222
|
+
buildtime: path_1.posix.join(packageName, name),
|
223
|
+
});
|
224
|
+
}
|
225
|
+
}
|
226
|
+
// we don't recurse across an engine boundary. Engines import their own
|
227
|
+
// implicit-modules.
|
228
|
+
if (!dep.isEngine()) {
|
229
|
+
eagerModules.push(path_1.posix.join(dep.name, `-embroider-${type}.js`));
|
230
|
+
}
|
231
|
+
}
|
232
|
+
return implicitModulesTemplate({ lazyModules, eagerModules });
|
233
|
+
}
|
234
|
+
const implicitModulesTemplate = (0, js_handlebars_1.compile)(`
|
235
|
+
import { importSync as i } from '@embroider/macros';
|
236
|
+
let d = window.define;
|
237
|
+
{{#each lazyModules as |module|}}
|
238
|
+
d("{{js-string-escape module.runtime}}", function(){ return i("{{js-string-escape module.buildtime}}");});
|
239
|
+
{{/each}}
|
240
|
+
{{#each eagerModules as |module|}}
|
241
|
+
import "{{js-string-escape module}}";
|
242
|
+
{{/each}}
|
243
|
+
`);
|
244
|
+
// meta['renamed-modules'] has mapping from classic filename to real filename.
|
245
|
+
// This takes that and converts it to the inverst mapping from real import path
|
246
|
+
// to classic import path.
|
247
|
+
function inverseRenamedModules(meta, extensions) {
|
248
|
+
let renamed = meta['renamed-modules'];
|
249
|
+
if (renamed) {
|
250
|
+
let inverted = {};
|
251
|
+
for (let [classic, real] of Object.entries(renamed)) {
|
252
|
+
inverted[real.replace(extensions, '')] = classic.replace(extensions, '');
|
253
|
+
}
|
254
|
+
return inverted;
|
255
|
+
}
|
256
|
+
}
|
257
|
+
function orderAddons(depA, depB) {
|
258
|
+
let depAIdx = 0;
|
259
|
+
let depBIdx = 0;
|
260
|
+
if (depA && depA.meta && depA.isV2Addon()) {
|
261
|
+
depAIdx = depA.meta['order-index'] || 0;
|
262
|
+
}
|
263
|
+
if (depB && depB.meta && depB.isV2Addon()) {
|
264
|
+
depBIdx = depB.meta['order-index'] || 0;
|
265
|
+
}
|
266
|
+
return depAIdx - depBIdx;
|
267
|
+
}
|
268
|
+
const renderCJSExternalShim = (0, js_handlebars_1.compile)(`
|
269
|
+
{{#if (eq moduleName "require")}}
|
270
|
+
const m = window.requirejs;
|
271
|
+
{{else}}
|
272
|
+
const m = window.require("{{{js-string-escape moduleName}}}");
|
273
|
+
{{/if}}
|
274
|
+
{{!-
|
275
|
+
There are plenty of hand-written AMD defines floating around
|
276
|
+
that lack this, and they will break when other build systems
|
277
|
+
encounter them.
|
278
|
+
|
279
|
+
As far as I can tell, Ember's loader was already treating this
|
280
|
+
case as a module, so in theory we aren't breaking anything by
|
281
|
+
marking it as such when other packagers come looking.
|
282
|
+
|
283
|
+
todo: get review on this part.
|
284
|
+
-}}
|
285
|
+
if (m.default && !m.__esModule) {
|
286
|
+
m.__esModule = true;
|
287
|
+
}
|
288
|
+
module.exports = m;
|
289
|
+
`);
|
131
290
|
//# sourceMappingURL=virtual-content.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"virtual-content.js","sourceRoot":"","sources":["virtual-content.ts"],"names":[],"mappings":";;;AAAA,+BAAkD;AAClD,wBAAqC;AACrC,mDAA0C;AAE1C,MAAM,cAAc,GAAG,uBAAuB,CAAC;AAE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KAAK,EAAE;QACT,IAAI,KAAK,GAAG,MAAA,MAAA,MAAA,KAAK,CAAC,MAAM,0CAAE,KAAK,0CAAE,KAAK,CAAC,GAAG,CAAC,mCAAI,EAAE,CAAC;QAClD,OAAO;YACL,KAAK,EAAE,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC,IAAI,KAAK,SAAS,CAAC;YAC/C,gBAAgB,EAAE,KAAK,CAAC,QAAQ,CAAC,SAAS,CAAC;YAC3C,QAAQ,EAAE,KAAK,CAAC,MAAO,CAAC,QAAQ;SACjC,CAAC;KACH;AACH,CAAC;AAVD,oDAUC;AAED,MAAM,sBAAsB,GAAG,IAAA,uBAAO,EAAC;;;;;;;;;;;;;;CActC,CAAuE,CAAC","sourcesContent":["import { dirname, basename, resolve } from 'path';\nimport { explicitRelative } from '.';\nimport { compile } from './js-handlebars';\n\nconst externalPrefix = '/@embroider/external/';\n\n// Given a filename that was passed to your ModuleRequest's `virtualize()`,\n// this produces the corresponding contents. It's a static, stateless function\n// because we recognize that that process that did resolution might not be the\n// same one that loads the content.\nexport function virtualContent(filename: string): string {\n if (filename.startsWith(externalPrefix)) {\n return externalShim({ moduleName: filename.slice(externalPrefix.length) });\n }\n let match = decodeVirtualPairComponent(filename);\n if (match) {\n return pairedComponentShim(match);\n }\n\n let fb = decodeFastbootSwitch(filename);\n if (fb) {\n return fastbootSwitchTemplate(fb);\n }\n\n throw new Error(`not an @embroider/core virtual file: ${filename}`);\n}\n\nconst externalShim = compile(`\n{{#if (eq moduleName \"require\")}}\nconst m = window.requirejs;\n{{else}}\nconst m = window.require(\"{{{js-string-escape moduleName}}}\");\n{{/if}}\n{{!-\n There are plenty of hand-written AMD defines floating around\n that lack this, and they will break when other build systems\n encounter them.\n\n As far as I can tell, Ember's loader was already treating this\n case as a module, so in theory we aren't breaking anything by\n marking it as such when other packagers come looking.\n\n todo: get review on this part.\n-}}\nif (m.default && !m.__esModule) {\n m.__esModule = true;\n}\nmodule.exports = m;\n`) as (params: { moduleName: string }) => string;\n\nconst pairedComponentShim = compile(`\nimport { setComponentTemplate } from \"@ember/component\";\nimport template from \"{{{js-string-escape relativeHBSModule}}}\";\n{{#if relativeJSModule}}\nimport component from \"{{{js-string-escape relativeJSModule}}}\";\nexport default setComponentTemplate(template, component);\n{{else}}\nimport templateOnlyComponent from \"@ember/component/template-only\";\nexport default setComponentTemplate(template, templateOnlyComponent(undefined, \"{{{js-string-escape debugName}}}\"));\n{{/if}}\n`) as (params: { relativeHBSModule: string; relativeJSModule: string | null; debugName: string }) => string;\n\nexport function virtualExternalModule(specifier: string): string {\n return externalPrefix + specifier;\n}\n\nconst pairComponentMarker = '/embroider-pair-component';\nconst pairComponentPattern = /^(?<hbsModule>.*)\\/(?<jsModule>[^\\/]*)\\/embroider-pair-component$/;\n\nexport function virtualPairComponent(hbsModule: string, jsModule: string | null): string {\n let relativeJSModule = '';\n if (jsModule) {\n // The '/j/' here represents the relativeJSModule itself that we're about to\n // use to create the complete filename. It's there to get the right number\n // of `..` in our relative path.\n relativeJSModule = explicitRelative(hbsModule + '/j/', jsModule);\n }\n return `${hbsModule}/${encodeURIComponent(relativeJSModule)}${pairComponentMarker}`;\n}\n\nfunction decodeVirtualPairComponent(\n filename: string\n): { relativeHBSModule: string; relativeJSModule: string | null; debugName: string } | null {\n let match = pairComponentPattern.exec(filename);\n if (!match) {\n return null;\n }\n let { hbsModule, jsModule } = match.groups! as { hbsModule: string; jsModule: string };\n // target our real hbs module from our virtual module\n let relativeHBSModule = explicitRelative(dirname(filename), hbsModule);\n return {\n relativeHBSModule,\n relativeJSModule: decodeURIComponent(jsModule) || null,\n debugName: basename(relativeHBSModule).replace(/\\.(js|hbs)$/, ''),\n };\n}\n\nconst fastbootSwitchSuffix = '/embroider_fastboot_switch';\nconst fastbootSwitchPattern = /(?<original>.+)\\/embroider_fastboot_switch(?:\\?names=(?<names>.+))?$/;\nexport function fastbootSwitch(specifier: string, fromFile: string, names: Set<string>): string {\n let filename = `${resolve(dirname(fromFile), specifier)}${fastbootSwitchSuffix}`;\n if (names.size > 0) {\n return `${filename}?names=${[...names].join(',')}`;\n } else {\n return filename;\n }\n}\n\nexport function decodeFastbootSwitch(filename: string) {\n let match = fastbootSwitchPattern.exec(filename);\n if (match) {\n let names = match.groups?.names?.split(',') ?? [];\n return {\n names: names.filter(name => name !== 'default'),\n hasDefaultExport: names.includes('default'),\n filename: match.groups!.original,\n };\n }\n}\n\nconst fastbootSwitchTemplate = compile(`\nimport { macroCondition, getGlobalConfig, importSync } from '@embroider/macros';\nlet mod;\nif (macroCondition(getGlobalConfig().fastboot?.isRunning)){\n mod = importSync('./fastboot');\n} else {\n mod = importSync('./browser');\n}\n{{#if hasDefaultExport}}\nexport default mod.default;\n{{/if}}\n{{#each names as |name|}}\nexport const {{name}} = mod.{{name}};\n{{/each}}\n`) as (params: { names: string[]; hasDefaultExport: boolean }) => string;\n"]}
|
1
|
+
{"version":3,"file":"virtual-content.js","sourceRoot":"","sources":["virtual-content.ts"],"names":[],"mappings":";;;AAAA,+BAAoE;AACpE,wBAAyF;AACzF,mDAA0C;AAE1C,MAAM,gBAAgB,GAAG,qBAAqB,CAAC;AAC/C,MAAM,iBAAiB,GAAG,sBAAsB,CAAC;AAEjD,2EAA2E;AAC3E,8EAA8E;AAC9E,8EAA8E;AAC9E,mCAAmC;AACnC,SAAgB,cAAc,CAAC,QAAgB,EAAE,QAAkB;IACjE,IAAI,SAAS,GAAG,8BAA8B,CAAC,QAAQ,CAAC,CAAC;IACzD,IAAI,SAAS,EAAE;QACb,OAAO,qBAAqB,CAAC,SAAS,CAAC,CAAC;KACzC;IAED,IAAI,MAAM,GAAG,6BAA6B,CAAC,QAAQ,CAAC,CAAC;IACrD,IAAI,MAAM,EAAE;QACV,OAAO,oBAAoB,CAAC,MAAM,CAAC,CAAC;KACrC;IACD,IAAI,KAAK,GAAG,0BAA0B,CAAC,QAAQ,CAAC,CAAC;IACjD,IAAI,KAAK,EAAE;QACT,OAAO,mBAAmB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AG,IAAI,CAAC,IAAI,CAAC,aAAa,CAAC,IAAI,CAAC,CAAC;KACzC;IACD,IAAI,IAAI,IAAI,IAAI,CAAC,IAAI,IAAI,IAAI,CAAC,SAAS,EAAE,EAAE;QACzC,OAAO,GAAG,IAAI,CAAC,IAAI,CAAC,aAAa,CAAC,IAAI,CAAC,CAAC;KACzC;IAED,OAAO,OAAO,GAAG,OAAO,CAAC;AAC3B,CAAC;AAED,MAAM,qBAAqB,GAAG,IAAA,uBAAO,EAAC;;;;;;;;;;;;;;;;;;;;;CAqBrC,CAA+C,CAAC","sourcesContent":["import { dirname, basename, resolve, posix, sep, join } from 'path';\nimport { Resolver, explicitRelative, extensionsPattern, AddonPackage, Package } from '.';\nimport { compile } from './js-handlebars';\n\nconst externalESPrefix = '/@embroider/ext-es/';\nconst externalCJSPrefix = '/@embroider/ext-cjs/';\n\n// Given a filename that was passed to your ModuleRequest's `virtualize()`,\n// this produces the corresponding contents. It's a static, stateless function\n// because we recognize that that process that did resolution might not be the\n// same one that loads the content.\nexport function virtualContent(filename: string, resolver: Resolver): string {\n let cjsExtern = decodeVirtualExternalCJSModule(filename);\n if (cjsExtern) {\n return renderCJSExternalShim(cjsExtern);\n }\n\n let extern = decodeVirtualExternalESModule(filename);\n if (extern) {\n return renderESExternalShim(extern);\n }\n let match = decodeVirtualPairComponent(filename);\n if (match) {\n return pairedComponentShim(match);\n }\n\n let fb = decodeFastbootSwitch(filename);\n if (fb) {\n return fastbootSwitchTemplate(fb);\n }\n\n let im = decodeImplicitModules(filename);\n if (im) {\n return renderImplicitModules(im, resolver);\n }\n\n throw new Error(`not an @embroider/core virtual file: ${filename}`);\n}\n\nconst externalESShim = compile(`\n{{#if (eq moduleName \"require\")}}\nconst m = window.requirejs;\nexport default m;\nconst has = m.has;\nexport { has }\n{{else}}\nconst m = window.require(\"{{{js-string-escape moduleName}}}\");\n{{#if default}}\nexport default m.default;\n{{/if}}\n{{#if names}}\nconst { {{#each names as |name|}}{{name}}, {{/each}} } = m;\nexport { {{#each names as |name|}}{{name}}, {{/each}} }\n{{/if}}\n{{/if}}\n`) as (params: { moduleName: string; default: boolean; names: string[] }) => string;\n\nfunction renderESExternalShim({ moduleName, exports }: { moduleName: string; exports: string[] }): string {\n return externalESShim({\n moduleName,\n default: exports.includes('default'),\n names: exports.filter(n => n !== 'default'),\n });\n}\n\nconst pairedComponentShim = compile(`\nimport { setComponentTemplate } from \"@ember/component\";\nimport template from \"{{{js-string-escape relativeHBSModule}}}\";\n{{#if relativeJSModule}}\nimport component from \"{{{js-string-escape relativeJSModule}}}\";\nexport default setComponentTemplate(template, component);\n{{else}}\nimport templateOnlyComponent from \"@ember/component/template-only\";\nexport default setComponentTemplate(template, templateOnlyComponent(undefined, \"{{{js-string-escape debugName}}}\"));\n{{/if}}\n`) as (params: { relativeHBSModule: string; relativeJSModule: string | null; debugName: string }) => string;\n\nexport function virtualExternalESModule(specifier: string, exports: string[] | undefined): string {\n if (exports) {\n return externalESPrefix + specifier + `?exports=${exports.join(',')}`;\n } else {\n return externalESPrefix + specifier;\n }\n}\n\nexport function virtualExternalCJSModule(specifier: string): string {\n return externalCJSPrefix + specifier;\n}\n\nfunction decodeVirtualExternalESModule(filename: string): { moduleName: string; exports: string[] } | undefined {\n if (filename.startsWith(externalESPrefix)) {\n let exports: string[] = [];\n let url = new URL(filename.slice(externalESPrefix.length), 'http://example.com');\n let nameString = url.searchParams.get('exports');\n if (nameString) {\n exports = nameString.split(',');\n }\n let moduleName = url.pathname.slice(1);\n return { moduleName, exports };\n }\n}\n\nfunction decodeVirtualExternalCJSModule(filename: string) {\n if (filename.startsWith(externalCJSPrefix)) {\n return { moduleName: filename.slice(externalCJSPrefix.length) };\n }\n}\n\nconst pairComponentMarker = '/embroider-pair-component';\nconst pairComponentPattern = /^(?<hbsModule>.*)\\/(?<jsModule>[^\\/]*)\\/embroider-pair-component$/;\n\nexport function virtualPairComponent(hbsModule: string, jsModule: string | null): string {\n let relativeJSModule = '';\n if (jsModule) {\n // The '/j/' here represents the relativeJSModule itself that we're about to\n // use to create the complete filename. It's there to get the right number\n // of `..` in our relative path.\n relativeJSModule = explicitRelative(hbsModule + '/j/', jsModule);\n }\n return `${hbsModule}/${encodeURIComponent(relativeJSModule)}${pairComponentMarker}`;\n}\n\nfunction decodeVirtualPairComponent(\n filename: string\n): { relativeHBSModule: string; relativeJSModule: string | null; debugName: string } | null {\n let match = pairComponentPattern.exec(filename);\n if (!match) {\n return null;\n }\n let { hbsModule, jsModule } = match.groups! as { hbsModule: string; jsModule: string };\n // target our real hbs module from our virtual module\n let relativeHBSModule = explicitRelative(dirname(filename), hbsModule);\n return {\n relativeHBSModule,\n relativeJSModule: decodeURIComponent(jsModule) || null,\n debugName: basename(relativeHBSModule).replace(/\\.(js|hbs)$/, ''),\n };\n}\n\nconst fastbootSwitchSuffix = '/embroider_fastboot_switch';\nconst fastbootSwitchPattern = /(?<original>.+)\\/embroider_fastboot_switch(?:\\?names=(?<names>.+))?$/;\nexport function fastbootSwitch(specifier: string, fromFile: string, names: Set<string>): string {\n let filename = `${resolve(dirname(fromFile), specifier)}${fastbootSwitchSuffix}`;\n if (names.size > 0) {\n return `${filename}?names=${[...names].join(',')}`;\n } else {\n return filename;\n }\n}\n\nexport function decodeFastbootSwitch(filename: string) {\n let match = fastbootSwitchPattern.exec(filename);\n if (match) {\n let names = match.groups?.names?.split(',') ?? [];\n return {\n names: names.filter(name => name !== 'default'),\n hasDefaultExport: names.includes('default'),\n filename: match.groups!.original,\n };\n }\n}\n\nconst fastbootSwitchTemplate = compile(`\nimport { macroCondition, getGlobalConfig, importSync } from '@embroider/macros';\nlet mod;\nif (macroCondition(getGlobalConfig().fastboot?.isRunning)){\n mod = importSync('./fastboot');\n} else {\n mod = importSync('./browser');\n}\n{{#if hasDefaultExport}}\nexport default mod.default;\n{{/if}}\n{{#each names as |name|}}\nexport const {{name}} = mod.{{name}};\n{{/each}}\n`) as (params: { names: string[]; hasDefaultExport: boolean }) => string;\n\nconst implicitModulesPattern = /(?<filename>.*)[\\\\/]-embroider-implicit-(?<test>test-)?modules\\.js$/;\n\nexport function decodeImplicitModules(\n filename: string\n): { type: 'implicit-modules' | 'implicit-test-modules'; fromFile: string } | undefined {\n let m = implicitModulesPattern.exec(filename);\n if (m) {\n return {\n type: m.groups!.test ? 'implicit-test-modules' : 'implicit-modules',\n fromFile: m.groups!.filename,\n };\n }\n}\n\nfunction renderImplicitModules(\n {\n type,\n fromFile,\n }: {\n type: 'implicit-modules' | 'implicit-test-modules';\n fromFile: string;\n },\n resolver: Resolver\n): string {\n let resolvableExtensionsPattern = extensionsPattern(resolver.options.resolvableExtensions);\n\n const pkg = resolver.packageCache.ownerOfFile(fromFile);\n if (!pkg?.isV2Ember()) {\n throw new Error(`bug: saw special implicit modules import in non-ember package at ${fromFile}`);\n }\n\n let lazyModules: { runtime: string; buildtime: string }[] = [];\n let eagerModules: string[] = [];\n\n let deps = pkg.dependencies.sort(orderAddons);\n\n for (let dep of deps) {\n // anything that isn't a v2 ember package by this point is not an active\n // addon.\n if (!dep.isV2Addon()) {\n continue;\n }\n\n // we ignore peerDependencies here because classic ember-cli ignores\n // peerDependencies here, and we're implementing the implicit-modules\n // backward-comptibility feature.\n if (pkg.categorizeDependency(dep.name) === 'peerDependencies') {\n continue;\n }\n\n let implicitModules = dep.meta[type];\n if (implicitModules) {\n let renamedModules = inverseRenamedModules(dep.meta, resolvableExtensionsPattern);\n for (let name of implicitModules) {\n let packageName = dep.name;\n\n let renamedMeta = dep.meta['renamed-packages'];\n if (renamedMeta) {\n Object.entries(renamedMeta).forEach(([key, value]) => {\n if (value === dep.name) {\n packageName = key;\n }\n });\n }\n\n let runtime = join(packageName, name).replace(resolvableExtensionsPattern, '');\n let runtimeRenameLookup = runtime.split('\\\\').join('/');\n if (renamedModules && renamedModules[runtimeRenameLookup]) {\n runtime = renamedModules[runtimeRenameLookup];\n }\n runtime = runtime.split(sep).join('/');\n lazyModules.push({\n runtime,\n buildtime: posix.join(packageName, name),\n });\n }\n }\n // we don't recurse across an engine boundary. Engines import their own\n // implicit-modules.\n if (!dep.isEngine()) {\n eagerModules.push(posix.join(dep.name, `-embroider-${type}.js`));\n }\n }\n return implicitModulesTemplate({ lazyModules, eagerModules });\n}\n\nconst implicitModulesTemplate = compile(`\nimport { importSync as i } from '@embroider/macros';\nlet d = window.define;\n{{#each lazyModules as |module|}}\nd(\"{{js-string-escape module.runtime}}\", function(){ return i(\"{{js-string-escape module.buildtime}}\");});\n{{/each}}\n{{#each eagerModules as |module|}}\nimport \"{{js-string-escape module}}\";\n{{/each}}\n`) as (params: { eagerModules: string[]; lazyModules: { runtime: string; buildtime: string }[] }) => string;\n\n// meta['renamed-modules'] has mapping from classic filename to real filename.\n// This takes that and converts it to the inverst mapping from real import path\n// to classic import path.\nfunction inverseRenamedModules(meta: AddonPackage['meta'], extensions: RegExp) {\n let renamed = meta['renamed-modules'];\n if (renamed) {\n let inverted = {} as { [name: string]: string };\n for (let [classic, real] of Object.entries(renamed)) {\n inverted[real.replace(extensions, '')] = classic.replace(extensions, '');\n }\n return inverted;\n }\n}\n\nfunction orderAddons(depA: Package, depB: Package): number {\n let depAIdx = 0;\n let depBIdx = 0;\n\n if (depA && depA.meta && depA.isV2Addon()) {\n depAIdx = depA.meta['order-index'] || 0;\n }\n if (depB && depB.meta && depB.isV2Addon()) {\n depBIdx = depB.meta['order-index'] || 0;\n }\n\n return depAIdx - depBIdx;\n}\n\nconst renderCJSExternalShim = compile(`\n{{#if (eq moduleName \"require\")}}\nconst m = window.requirejs;\n{{else}}\nconst m = window.require(\"{{{js-string-escape moduleName}}}\");\n{{/if}}\n{{!-\n There are plenty of hand-written AMD defines floating around\n that lack this, and they will break when other build systems\n encounter them.\n\n As far as I can tell, Ember's loader was already treating this\n case as a module, so in theory we aren't breaking anything by\n marking it as such when other packagers come looking.\n\n todo: get review on this part.\n-}}\nif (m.default && !m.__esModule) {\n m.__esModule = true;\n}\nmodule.exports = m;\n`) as (params: { moduleName: string }) => string;\n"]}
|