@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/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@embroider/core",
|
3
|
-
"version": "3.1.4-unstable.
|
3
|
+
"version": "3.1.4-unstable.7407f3a",
|
4
4
|
"private": false,
|
5
5
|
"description": "A build system for EmberJS applications.",
|
6
6
|
"repository": {
|
@@ -23,8 +23,8 @@
|
|
23
23
|
"@babel/core": "^7.14.5",
|
24
24
|
"@babel/parser": "^7.14.5",
|
25
25
|
"@babel/traverse": "^7.14.5",
|
26
|
-
"@embroider/macros": "1.12.4-unstable.
|
27
|
-
"@embroider/shared-internals": "2.2.4-unstable.
|
26
|
+
"@embroider/macros": "1.12.4-unstable.7407f3a",
|
27
|
+
"@embroider/shared-internals": "2.2.4-unstable.7407f3a",
|
28
28
|
"assert-never": "^1.2.1",
|
29
29
|
"babel-plugin-ember-template-compilation": "^2.1.1",
|
30
30
|
"broccoli-node-api": "^1.7.0",
|
package/src/index.d.ts
CHANGED
@@ -8,6 +8,7 @@ export { default as WaitForTrees, OutputPaths } from './wait-for-trees';
|
|
8
8
|
export { compile as jsHandlebarsCompile } from './js-handlebars';
|
9
9
|
export { todo, unsupported, warn, debug, expectWarning, throwOnWarnings } from './messages';
|
10
10
|
export { Resolver, Options as ResolverOptions, ModuleRequest, Resolution, ResolverFunction, SyncResolverFunction, } from './module-resolver';
|
11
|
+
export { ResolverLoader } from './resolver-loader';
|
11
12
|
export { virtualContent } from './virtual-content';
|
12
13
|
export type { Engine } from './app-files';
|
13
14
|
export * from '@embroider/shared-internals';
|
package/src/index.js
CHANGED
@@ -17,7 +17,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
17
17
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
18
18
|
};
|
19
19
|
Object.defineProperty(exports, "__esModule", { value: true });
|
20
|
-
exports.virtualContent = exports.Resolver = exports.throwOnWarnings = exports.expectWarning = exports.debug = exports.warn = exports.unsupported = exports.todo = exports.jsHandlebarsCompile = exports.WaitForTrees = exports.toBroccoliPlugin = exports.optionsWithDefaults = exports.HTMLEntrypoint = exports.getPackagerCacheDir = exports.getAppMeta = exports.applyVariantToBabelConfig = void 0;
|
20
|
+
exports.virtualContent = exports.ResolverLoader = exports.Resolver = exports.throwOnWarnings = exports.expectWarning = exports.debug = exports.warn = exports.unsupported = exports.todo = exports.jsHandlebarsCompile = exports.WaitForTrees = exports.toBroccoliPlugin = exports.optionsWithDefaults = exports.HTMLEntrypoint = exports.getPackagerCacheDir = exports.getAppMeta = exports.applyVariantToBabelConfig = void 0;
|
21
21
|
var packager_1 = require("./packager");
|
22
22
|
Object.defineProperty(exports, "applyVariantToBabelConfig", { enumerable: true, get: function () { return packager_1.applyVariantToBabelConfig; } });
|
23
23
|
Object.defineProperty(exports, "getAppMeta", { enumerable: true, get: function () { return packager_1.getAppMeta; } });
|
@@ -41,6 +41,8 @@ Object.defineProperty(exports, "expectWarning", { enumerable: true, get: functio
|
|
41
41
|
Object.defineProperty(exports, "throwOnWarnings", { enumerable: true, get: function () { return messages_1.throwOnWarnings; } });
|
42
42
|
var module_resolver_1 = require("./module-resolver");
|
43
43
|
Object.defineProperty(exports, "Resolver", { enumerable: true, get: function () { return module_resolver_1.Resolver; } });
|
44
|
+
var resolver_loader_1 = require("./resolver-loader");
|
45
|
+
Object.defineProperty(exports, "ResolverLoader", { enumerable: true, get: function () { return resolver_loader_1.ResolverLoader; } });
|
44
46
|
var virtual_content_1 = require("./virtual-content");
|
45
47
|
Object.defineProperty(exports, "virtualContent", { enumerable: true, get: function () { return virtual_content_1.virtualContent; } });
|
46
48
|
// this is reexported because we already make users manage a peerDep from some
|
package/src/index.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA,uCAOoB;AAHlB,qHAAA,yBAAyB,OAAA;AACzB,sGAAA,UAAU,OAAA;AACV,+GAAA,mBAAmB,OAAA;AAErB,qDAAkE;AAAzD,iHAAA,cAAc,OAAA;AAGvB,qCAAoE;AAAvC,8GAAA,mBAAmB,OAAA;AAChD,2DAAmE;AAA1D,uIAAA,OAAO,OAAoB;AACpC,mDAAwE;AAA/D,+HAAA,OAAO,OAAgB;AAChC,iDAAiE;AAAxD,oHAAA,OAAO,OAAuB;AACvC,uCAA4F;AAAnF,gGAAA,IAAI,OAAA;AAAE,uGAAA,WAAW,OAAA;AAAE,gGAAA,IAAI,OAAA;AAAE,iGAAA,KAAK,OAAA;AAAE,yGAAA,aAAa,OAAA;AAAE,2GAAA,eAAe,OAAA;AACvE,qDAO2B;AANzB,2GAAA,QAAQ,OAAA;AAOV,qDAAmD;AAA1C,iHAAA,cAAc,OAAA;AAGvB,8EAA8E;AAC9E,+DAA+D;AAC/D,8DAA4C","sourcesContent":["export {\n Packager,\n PackagerConstructor,\n Variant,\n applyVariantToBabelConfig,\n getAppMeta,\n getPackagerCacheDir,\n} from './packager';\nexport { HTMLEntrypoint, BundleSummary } from './html-entrypoint';\nexport { default as Stage } from './stage';\nexport { Asset, EmberAsset, ImplicitAssetPaths } from './asset';\nexport { default as Options, optionsWithDefaults } from './options';\nexport { default as toBroccoliPlugin } from './to-broccoli-plugin';\nexport { default as WaitForTrees, OutputPaths } from './wait-for-trees';\nexport { compile as jsHandlebarsCompile } from './js-handlebars';\nexport { todo, unsupported, warn, debug, expectWarning, throwOnWarnings } from './messages';\nexport {\n Resolver,\n Options as ResolverOptions,\n ModuleRequest,\n Resolution,\n ResolverFunction,\n SyncResolverFunction,\n} from './module-resolver';\nexport { virtualContent } from './virtual-content';\nexport type { Engine } from './app-files';\n\n// this is reexported because we already make users manage a peerDep from some\n// other packages (like embroider/webpack and @embroider/compat\nexport * from '@embroider/shared-internals';\n"]}
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA,uCAOoB;AAHlB,qHAAA,yBAAyB,OAAA;AACzB,sGAAA,UAAU,OAAA;AACV,+GAAA,mBAAmB,OAAA;AAErB,qDAAkE;AAAzD,iHAAA,cAAc,OAAA;AAGvB,qCAAoE;AAAvC,8GAAA,mBAAmB,OAAA;AAChD,2DAAmE;AAA1D,uIAAA,OAAO,OAAoB;AACpC,mDAAwE;AAA/D,+HAAA,OAAO,OAAgB;AAChC,iDAAiE;AAAxD,oHAAA,OAAO,OAAuB;AACvC,uCAA4F;AAAnF,gGAAA,IAAI,OAAA;AAAE,uGAAA,WAAW,OAAA;AAAE,gGAAA,IAAI,OAAA;AAAE,iGAAA,KAAK,OAAA;AAAE,yGAAA,aAAa,OAAA;AAAE,2GAAA,eAAe,OAAA;AACvE,qDAO2B;AANzB,2GAAA,QAAQ,OAAA;AAOV,qDAAmD;AAA1C,iHAAA,cAAc,OAAA;AACvB,qDAAmD;AAA1C,iHAAA,cAAc,OAAA;AAGvB,8EAA8E;AAC9E,+DAA+D;AAC/D,8DAA4C","sourcesContent":["export {\n Packager,\n PackagerConstructor,\n Variant,\n applyVariantToBabelConfig,\n getAppMeta,\n getPackagerCacheDir,\n} from './packager';\nexport { HTMLEntrypoint, BundleSummary } from './html-entrypoint';\nexport { default as Stage } from './stage';\nexport { Asset, EmberAsset, ImplicitAssetPaths } from './asset';\nexport { default as Options, optionsWithDefaults } from './options';\nexport { default as toBroccoliPlugin } from './to-broccoli-plugin';\nexport { default as WaitForTrees, OutputPaths } from './wait-for-trees';\nexport { compile as jsHandlebarsCompile } from './js-handlebars';\nexport { todo, unsupported, warn, debug, expectWarning, throwOnWarnings } from './messages';\nexport {\n Resolver,\n Options as ResolverOptions,\n ModuleRequest,\n Resolution,\n ResolverFunction,\n SyncResolverFunction,\n} from './module-resolver';\nexport { ResolverLoader } from './resolver-loader';\nexport { virtualContent } from './virtual-content';\nexport type { Engine } from './app-files';\n\n// this is reexported because we already make users manage a peerDep from some\n// other packages (like embroider/webpack and @embroider/compat\nexport * from '@embroider/shared-internals';\n"]}
|
package/src/module-resolver.d.ts
CHANGED
@@ -1,4 +1,5 @@
|
|
1
|
-
import { Package } from '@embroider/shared-internals';
|
1
|
+
import { Package, RewrittenPackageCache } from '@embroider/shared-internals';
|
2
|
+
import UserOptions from './options';
|
2
3
|
export interface Options {
|
3
4
|
renamePackages: {
|
4
5
|
[fromName: string]: string;
|
@@ -14,6 +15,7 @@ export interface Options {
|
|
14
15
|
engines: EngineConfig[];
|
15
16
|
modulePrefix: string;
|
16
17
|
podModulePrefix?: string;
|
18
|
+
amdCompatibility: Required<UserOptions['amdCompatibility']>;
|
17
19
|
}
|
18
20
|
interface EngineConfig {
|
19
21
|
packageName: string;
|
@@ -30,12 +32,14 @@ interface EngineConfig {
|
|
30
32
|
root: string;
|
31
33
|
}
|
32
34
|
export interface ModuleRequest {
|
33
|
-
specifier: string;
|
34
|
-
fromFile: string;
|
35
|
-
isVirtual: boolean;
|
35
|
+
readonly specifier: string;
|
36
|
+
readonly fromFile: string;
|
37
|
+
readonly isVirtual: boolean;
|
38
|
+
readonly meta: Record<string, unknown> | undefined;
|
36
39
|
alias(newSpecifier: string): this;
|
37
40
|
rehome(newFromFile: string): this;
|
38
41
|
virtualize(virtualFilename: string): this;
|
42
|
+
withMeta(meta: Record<string, any> | undefined): this;
|
39
43
|
}
|
40
44
|
export type Resolution<T = unknown, E = unknown> = {
|
41
45
|
type: 'found';
|
@@ -47,7 +51,7 @@ export type Resolution<T = unknown, E = unknown> = {
|
|
47
51
|
export type ResolverFunction<R extends ModuleRequest = ModuleRequest, Res extends Resolution = Resolution> = (request: R) => Promise<Res>;
|
48
52
|
export type SyncResolverFunction<R extends ModuleRequest = ModuleRequest, Res extends Resolution = Resolution> = (request: R) => Res;
|
49
53
|
export declare class Resolver {
|
50
|
-
|
54
|
+
readonly options: Options;
|
51
55
|
constructor(options: Options);
|
52
56
|
beforeResolve<R extends ModuleRequest>(request: R): R;
|
53
57
|
resolve<Req extends ModuleRequest, Res extends Resolution>(request: Req, defaultResolve: ResolverFunction<Req, Res>): Promise<Res>;
|
@@ -64,11 +68,11 @@ export declare class Resolver {
|
|
64
68
|
type: 'not_found';
|
65
69
|
err: Error;
|
66
70
|
};
|
67
|
-
|
68
|
-
owningPackage(fromFile: string): Package | undefined;
|
71
|
+
get packageCache(): RewrittenPackageCache;
|
69
72
|
private logicalPackage;
|
70
73
|
private generateFastbootSwitch;
|
71
74
|
private handleFastbootSwitch;
|
75
|
+
private handleImplicitModules;
|
72
76
|
private handleGlobalsCompat;
|
73
77
|
private resolveHelper;
|
74
78
|
private resolveComponent;
|
@@ -85,6 +89,7 @@ export declare class Resolver {
|
|
85
89
|
private handleRenaming;
|
86
90
|
private resolveWithinPackage;
|
87
91
|
private preHandleExternal;
|
92
|
+
private external;
|
88
93
|
fallbackResolve<R extends ModuleRequest>(request: R): R;
|
89
94
|
private getEntryFromMergeMap;
|
90
95
|
private withResolvableExtensions;
|
package/src/module-resolver.js
CHANGED
@@ -43,24 +43,28 @@ function logTransition(reason, before, after = before) {
|
|
43
43
|
}
|
44
44
|
const compatPattern = /#embroider_compat\/(?<type>[^\/]+)\/(?<rest>.*)/;
|
45
45
|
class NodeModuleRequest {
|
46
|
-
constructor(specifier, fromFile, isVirtual
|
46
|
+
constructor(specifier, fromFile, isVirtual, meta) {
|
47
47
|
this.specifier = specifier;
|
48
48
|
this.fromFile = fromFile;
|
49
49
|
this.isVirtual = isVirtual;
|
50
|
+
this.meta = meta;
|
50
51
|
}
|
51
52
|
alias(specifier) {
|
52
|
-
return new NodeModuleRequest(specifier, this.fromFile);
|
53
|
+
return new NodeModuleRequest(specifier, this.fromFile, false, this.meta);
|
53
54
|
}
|
54
55
|
rehome(fromFile) {
|
55
56
|
if (this.fromFile === fromFile) {
|
56
57
|
return this;
|
57
58
|
}
|
58
59
|
else {
|
59
|
-
return new NodeModuleRequest(this.specifier, fromFile);
|
60
|
+
return new NodeModuleRequest(this.specifier, fromFile, false, this.meta);
|
60
61
|
}
|
61
62
|
}
|
62
63
|
virtualize(filename) {
|
63
|
-
return new NodeModuleRequest(filename, this.fromFile, true);
|
64
|
+
return new NodeModuleRequest(filename, this.fromFile, true, this.meta);
|
65
|
+
}
|
66
|
+
withMeta(meta) {
|
67
|
+
return new NodeModuleRequest(this.specifier, this.fromFile, this.isVirtual, meta);
|
64
68
|
}
|
65
69
|
}
|
66
70
|
class Resolver {
|
@@ -77,6 +81,7 @@ class Resolver {
|
|
77
81
|
}
|
78
82
|
request = this.handleFastbootSwitch(request);
|
79
83
|
request = this.handleGlobalsCompat(request);
|
84
|
+
request = this.handleImplicitModules(request);
|
80
85
|
request = this.handleRenaming(request);
|
81
86
|
// we expect the specifier to be app relative at this point - must be after handleRenaming
|
82
87
|
request = this.generateFastbootSwitch(request);
|
@@ -144,13 +149,13 @@ class Resolver {
|
|
144
149
|
// top. This is a convenience method for calling resolveSync with the
|
145
150
|
// defaultResolve already configured to be "do the normal node thing".
|
146
151
|
nodeResolve(specifier, fromFile) {
|
147
|
-
let resolution = this.resolveSync(new NodeModuleRequest(specifier, fromFile), request => {
|
152
|
+
let resolution = this.resolveSync(new NodeModuleRequest(specifier, fromFile, false, undefined), request => {
|
148
153
|
if (request.isVirtual) {
|
149
154
|
return {
|
150
155
|
type: 'found',
|
151
156
|
result: {
|
152
157
|
type: 'virtual',
|
153
|
-
content: (0, virtual_content_1.virtualContent)(request.specifier),
|
158
|
+
content: (0, virtual_content_1.virtualContent)(request.specifier, this),
|
154
159
|
filename: request.specifier,
|
155
160
|
},
|
156
161
|
};
|
@@ -181,9 +186,6 @@ class Resolver {
|
|
181
186
|
get packageCache() {
|
182
187
|
return shared_internals_2.RewrittenPackageCache.shared('embroider', this.options.appRoot);
|
183
188
|
}
|
184
|
-
owningPackage(fromFile) {
|
185
|
-
return this.packageCache.ownerOfFile(fromFile);
|
186
|
-
}
|
187
189
|
logicalPackage(owningPackage, file) {
|
188
190
|
let logicalLocation = this.reverseSearchAppTree(owningPackage, file);
|
189
191
|
if (logicalLocation) {
|
@@ -196,7 +198,7 @@ class Resolver {
|
|
196
198
|
return owningPackage;
|
197
199
|
}
|
198
200
|
generateFastbootSwitch(request) {
|
199
|
-
let pkg = this.
|
201
|
+
let pkg = this.packageCache.ownerOfFile(request.fromFile);
|
200
202
|
if (!pkg) {
|
201
203
|
return request;
|
202
204
|
}
|
@@ -246,7 +248,7 @@ class Resolver {
|
|
246
248
|
if (!section) {
|
247
249
|
return logTransition('non-special import in fastboot switch', request);
|
248
250
|
}
|
249
|
-
let pkg = this.
|
251
|
+
let pkg = this.packageCache.ownerOfFile(match.filename);
|
250
252
|
if (pkg) {
|
251
253
|
let rel = (0, shared_internals_2.explicitRelative)(pkg.root, match.filename);
|
252
254
|
let engineConfig = this.engineConfig(pkg.name);
|
@@ -275,13 +277,31 @@ class Resolver {
|
|
275
277
|
}
|
276
278
|
return logTransition('failed to match in fastboot switch', request);
|
277
279
|
}
|
280
|
+
handleImplicitModules(request) {
|
281
|
+
let im = (0, virtual_content_1.decodeImplicitModules)(request.specifier);
|
282
|
+
if (!im) {
|
283
|
+
return request;
|
284
|
+
}
|
285
|
+
let pkg = this.packageCache.ownerOfFile(request.fromFile);
|
286
|
+
if (!(pkg === null || pkg === void 0 ? void 0 : pkg.isV2Ember())) {
|
287
|
+
throw new Error(`bug: found implicit modules import in non-ember package at ${request.fromFile}`);
|
288
|
+
}
|
289
|
+
let packageName = (0, shared_internals_1.packageName)(im.fromFile);
|
290
|
+
if (packageName) {
|
291
|
+
let dep = this.packageCache.resolve(packageName, pkg);
|
292
|
+
return logTransition(`dep's implicit modules`, request, request.virtualize((0, path_1.resolve)(dep.root, `-embroider-${im.type}.js`)));
|
293
|
+
}
|
294
|
+
else {
|
295
|
+
return logTransition(`own implicit modules`, request, request.virtualize((0, path_1.resolve)(pkg.root, `-embroider-${im.type}.js`)));
|
296
|
+
}
|
297
|
+
}
|
278
298
|
handleGlobalsCompat(request) {
|
279
299
|
let match = compatPattern.exec(request.specifier);
|
280
300
|
if (!match) {
|
281
301
|
return request;
|
282
302
|
}
|
283
303
|
let { type, rest } = match.groups;
|
284
|
-
let fromPkg = this.
|
304
|
+
let fromPkg = this.packageCache.ownerOfFile(request.fromFile);
|
285
305
|
if (!(fromPkg === null || fromPkg === void 0 ? void 0 : fromPkg.isV2Ember())) {
|
286
306
|
return request;
|
287
307
|
}
|
@@ -502,7 +522,10 @@ class Resolver {
|
|
502
522
|
return owningEngine;
|
503
523
|
}
|
504
524
|
handleRewrittenPackages(request) {
|
505
|
-
|
525
|
+
if (request.isVirtual) {
|
526
|
+
return request;
|
527
|
+
}
|
528
|
+
let requestingPkg = this.packageCache.ownerOfFile(request.fromFile);
|
506
529
|
if (!requestingPkg) {
|
507
530
|
return request;
|
508
531
|
}
|
@@ -539,7 +562,7 @@ class Resolver {
|
|
539
562
|
else if (originalRequestingPkg) {
|
540
563
|
// in this case, the requesting package is moved but its destination is
|
541
564
|
// not, so we need to rehome the request back to the original location.
|
542
|
-
return logTransition('outbound request from moved package', request, request.rehome((0, path_1.resolve)(originalRequestingPkg.root,
|
565
|
+
return logTransition('outbound request from moved package', request, request.withMeta({ wasMovedTo: request.fromFile }).rehome((0, path_1.resolve)(originalRequestingPkg.root, 'package.json')));
|
543
566
|
}
|
544
567
|
return request;
|
545
568
|
}
|
@@ -551,7 +574,7 @@ class Resolver {
|
|
551
574
|
if (!packageName) {
|
552
575
|
return request;
|
553
576
|
}
|
554
|
-
let pkg = this.
|
577
|
+
let pkg = this.packageCache.ownerOfFile(request.fromFile);
|
555
578
|
if (!pkg || !pkg.isV2Ember()) {
|
556
579
|
return request;
|
557
580
|
}
|
@@ -603,7 +626,7 @@ class Resolver {
|
|
603
626
|
return request;
|
604
627
|
}
|
605
628
|
let { specifier, fromFile } = request;
|
606
|
-
let pkg = this.
|
629
|
+
let pkg = this.packageCache.ownerOfFile(fromFile);
|
607
630
|
if (!pkg || !pkg.isV2Ember()) {
|
608
631
|
return request;
|
609
632
|
}
|
@@ -625,7 +648,7 @@ class Resolver {
|
|
625
648
|
let packageRelativeSpecifier = (0, shared_internals_2.explicitRelative)(pkg.root, absoluteSpecifier);
|
626
649
|
if (isExplicitlyExternal(packageRelativeSpecifier, pkg)) {
|
627
650
|
let publicSpecifier = absoluteSpecifier.replace(pkg.root, pkg.name);
|
628
|
-
return external('beforeResolve', request, publicSpecifier);
|
651
|
+
return this.external('beforeResolve', request, publicSpecifier);
|
629
652
|
}
|
630
653
|
// if the requesting file is in an addon's app-js, the relative request
|
631
654
|
// should really be understood as a request for a module in the containing
|
@@ -639,10 +662,10 @@ class Resolver {
|
|
639
662
|
// absolute package imports can also be explicitly external based on their
|
640
663
|
// full specifier name
|
641
664
|
if (isExplicitlyExternal(specifier, pkg)) {
|
642
|
-
return external('beforeResolve', request, specifier);
|
665
|
+
return this.external('beforeResolve', request, specifier);
|
643
666
|
}
|
644
667
|
if (shared_internals_1.emberVirtualPackages.has(packageName) && !pkg.hasDependency(packageName)) {
|
645
|
-
return external('beforeResolve emberVirtualPackages', request, specifier);
|
668
|
+
return this.external('beforeResolve emberVirtualPackages', request, specifier);
|
646
669
|
}
|
647
670
|
if (shared_internals_1.emberVirtualPeerDeps.has(packageName) && !pkg.hasDependency(packageName)) {
|
648
671
|
// addons (whether auto-upgraded or not) may use the app's
|
@@ -663,7 +686,7 @@ class Resolver {
|
|
663
686
|
if (!dep.isEmberPackage()) {
|
664
687
|
// classic ember addons can only import non-ember dependencies if they
|
665
688
|
// have ember-auto-import.
|
666
|
-
return external('v1 package without auto-import', request, specifier);
|
689
|
+
return this.external('v1 package without auto-import', request, specifier);
|
667
690
|
}
|
668
691
|
}
|
669
692
|
catch (err) {
|
@@ -682,7 +705,40 @@ class Resolver {
|
|
682
705
|
}
|
683
706
|
return request;
|
684
707
|
}
|
708
|
+
external(label, request, specifier) {
|
709
|
+
if (this.options.amdCompatibility === 'cjs') {
|
710
|
+
let filename = (0, virtual_content_1.virtualExternalCJSModule)(specifier);
|
711
|
+
return logTransition(label, request, request.virtualize(filename));
|
712
|
+
}
|
713
|
+
else if (this.options.amdCompatibility) {
|
714
|
+
let entry = this.options.amdCompatibility.es.find(entry => entry[0] === specifier || entry[0] + '/index' === specifier);
|
715
|
+
if (!entry && request.specifier === 'require') {
|
716
|
+
entry = ['require', ['default', 'has']];
|
717
|
+
}
|
718
|
+
if (!entry) {
|
719
|
+
throw new Error(`A module tried to resolve "${request.specifier}" and didn't find it (${label}).
|
720
|
+
|
721
|
+
- Maybe a dependency declaration is missing?
|
722
|
+
- Remember that v1 addons can only import non-Ember-addon NPM dependencies if they include ember-auto-import in their dependencies.
|
723
|
+
- If this dependency is available in the AMD loader (because someone manually called "define()" for it), you can configure a shim like:
|
724
|
+
|
725
|
+
amdCompatibility: {
|
726
|
+
es: [
|
727
|
+
["${request.specifier}", ["default", "yourNamedExportsGoHere"]],
|
728
|
+
]
|
729
|
+
}
|
730
|
+
|
731
|
+
`);
|
732
|
+
}
|
733
|
+
let filename = (0, virtual_content_1.virtualExternalESModule)(specifier, entry[1]);
|
734
|
+
return logTransition(label, request, request.virtualize(filename));
|
735
|
+
}
|
736
|
+
else {
|
737
|
+
throw new Error(`Embroider's amdCompatibility option is disabled, but something tried to use it to access "${request.specifier}"`);
|
738
|
+
}
|
739
|
+
}
|
685
740
|
fallbackResolve(request) {
|
741
|
+
var _a;
|
686
742
|
let { specifier, fromFile } = request;
|
687
743
|
if (compatPattern.test(specifier)) {
|
688
744
|
// Some kinds of compat requests get rewritten into other things
|
@@ -700,7 +756,7 @@ class Resolver {
|
|
700
756
|
// here.
|
701
757
|
return request;
|
702
758
|
}
|
703
|
-
let pkg = this.
|
759
|
+
let pkg = this.packageCache.ownerOfFile(fromFile);
|
704
760
|
if (!pkg) {
|
705
761
|
return logTransition('no identifiable owningPackage', request);
|
706
762
|
}
|
@@ -710,7 +766,10 @@ class Resolver {
|
|
710
766
|
// isV2Ember()
|
711
767
|
let movedPkg = this.packageCache.maybeMoved(pkg);
|
712
768
|
if (movedPkg !== pkg) {
|
713
|
-
|
769
|
+
if (!((_a = request.meta) === null || _a === void 0 ? void 0 : _a.wasMovedTo)) {
|
770
|
+
throw new Error(`bug: embroider resolver's meta is not propagating`);
|
771
|
+
}
|
772
|
+
fromFile = request.meta.wasMovedTo;
|
714
773
|
pkg = movedPkg;
|
715
774
|
}
|
716
775
|
if (!pkg.isV2Ember()) {
|
@@ -732,22 +791,6 @@ class Resolver {
|
|
732
791
|
}
|
733
792
|
}
|
734
793
|
else {
|
735
|
-
if (pkg.meta['auto-upgraded'] && (0, path_1.dirname)(request.fromFile) === pkg.root) {
|
736
|
-
let otherRoot = this.options.activeAddons[pkg.name];
|
737
|
-
if (otherRoot && otherRoot !== pkg.root) {
|
738
|
-
// This provides some backward-compatibility with the way things
|
739
|
-
// would have resolved in earlier embroider versions, where the
|
740
|
-
// final fallback was always the activeAddons. These requests now
|
741
|
-
// end up getting converted to relative requests inside a particular
|
742
|
-
// moved package, which is why we need to handle them here.
|
743
|
-
//
|
744
|
-
// TODO: We shouldn't need this if we generate notional per-package
|
745
|
-
// entrypoints that pull in all the implicit-modules, so that the
|
746
|
-
// imports for implicit-modules happen in places with normal
|
747
|
-
// dependency resolvability.
|
748
|
-
return logTransition('fallbackResolve: relative path falling through to activeAddons', request, request.rehome((0, path_1.resolve)(otherRoot, 'package.json')));
|
749
|
-
}
|
750
|
-
}
|
751
794
|
// nothing else to do for relative imports
|
752
795
|
return logTransition('fallbackResolve: relative failure', request);
|
753
796
|
}
|
@@ -779,14 +822,14 @@ class Resolver {
|
|
779
822
|
// runtime. Native v2 packages can only get this behavior in the
|
780
823
|
// isExplicitlyExternal case above because they need to explicitly ask for
|
781
824
|
// externals.
|
782
|
-
return external('v1 catch-all fallback', request, specifier);
|
825
|
+
return this.external('v1 catch-all fallback', request, specifier);
|
783
826
|
}
|
784
827
|
else {
|
785
828
|
// native v2 packages don't automatically externalize *everything* the way
|
786
829
|
// auto-upgraded packages do, but they still externalize known and approved
|
787
830
|
// ember virtual packages (like @ember/component)
|
788
831
|
if (shared_internals_1.emberVirtualPackages.has(packageName)) {
|
789
|
-
return external('emberVirtualPackages', request, specifier);
|
832
|
+
return this.external('emberVirtualPackages', request, specifier);
|
790
833
|
}
|
791
834
|
}
|
792
835
|
// this is falling through with the original specifier which was
|
@@ -858,7 +901,7 @@ class Resolver {
|
|
858
901
|
// check if this file is resolvable as a global component, and if so return
|
859
902
|
// its dasherized name
|
860
903
|
reverseComponentLookup(filename) {
|
861
|
-
const owningPackage = this.
|
904
|
+
const owningPackage = this.packageCache.ownerOfFile(filename);
|
862
905
|
if (!(owningPackage === null || owningPackage === void 0 ? void 0 : owningPackage.isV2Ember())) {
|
863
906
|
return;
|
864
907
|
}
|
@@ -921,8 +964,4 @@ function reliablyResolvable(pkg, packageName) {
|
|
921
964
|
function appImportInAppTree(inPackage, inLogicalPackage, importedPackageName) {
|
922
965
|
return inPackage !== inLogicalPackage && importedPackageName === inLogicalPackage.name;
|
923
966
|
}
|
924
|
-
function external(label, request, specifier) {
|
925
|
-
let filename = (0, virtual_content_1.virtualExternalModule)(specifier);
|
926
|
-
return logTransition(label, request, request.virtualize(filename));
|
927
|
-
}
|
928
967
|
//# sourceMappingURL=module-resolver.js.map
|