@embroider/core 3.1.4-unstable.4f3826d → 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 +4 -4
- package/src/app-files.js +2 -2
- package/src/app-files.js.map +1 -1
- 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 +104 -59
- 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,10 +23,10 @@
|
|
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
|
-
"babel-plugin-ember-template-compilation": "^2.
|
29
|
+
"babel-plugin-ember-template-compilation": "^2.1.1",
|
30
30
|
"broccoli-node-api": "^1.7.0",
|
31
31
|
"broccoli-persistent-filter": "^3.1.2",
|
32
32
|
"broccoli-plugin": "^4.0.7",
|
package/src/app-files.js
CHANGED
@@ -75,8 +75,8 @@ class AppFiles {
|
|
75
75
|
modifiers.push(relativePath);
|
76
76
|
continue;
|
77
77
|
}
|
78
|
-
if (this.
|
79
|
-
|
78
|
+
if ((podModulePrefix !== undefined && this.handlePodsRouteFile(relativePath, podModulePrefix)) ||
|
79
|
+
this.handleClassicRouteFile(relativePath)) {
|
80
80
|
continue;
|
81
81
|
}
|
82
82
|
otherAppFiles.push(relativePath);
|
package/src/app-files.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"app-files.js","sourceRoot":"","sources":["app-files.ts"],"names":[],"mappings":";;;AAAA,+BAA2B;AAU3B,MAAa,QAAQ;IAUnB,YACW,MAAc,EACvB,QAAqB,EACrB,aAA0B,EAC1B,oBAA4B,EAC5B,eAAwB;QAJf,WAAM,GAAN,MAAM,CAAQ;QAMvB,IAAI,KAAK,GAAa,EAAE,CAAC;QACzB,IAAI,UAAU,GAAa,EAAE,CAAC;QAC9B,IAAI,OAAO,GAAa,EAAE,CAAC;QAC3B,IAAI,SAAS,GAAa,EAAE,CAAC;QAC7B,IAAI,aAAa,GAAa,EAAE,CAAC;QACjC,IAAI,CAAC,QAAQ,GAAG,EAAE,QAAQ,EAAE,IAAI,GAAG,EAAE,EAAE,CAAC;QAExC,IAAI,aAAa,GAAG,IAAI,GAAG,EAAU,CAAC;QACtC,IAAI,wBAAwB,GAAG,IAAI,GAAG,EAAU,CAAC;QACjD,IAAI,cAAc,GAAG,IAAI,GAAG,EAAmB,CAAC;QAEhD,KAAK,IAAI,CAAC,IAAI,QAAQ,EAAE;YACtB,aAAa,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;YACrB,wBAAwB,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;SACjC;QACD,KAAK,IAAI,CAAC,IAAI,aAAa,EAAE;YAC3B,aAAa,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;SACtB;QAED,KAAK,IAAI,KAAK,IAAI,MAAM,CAAC,MAAM,EAAE;YAC/B,IAAI,KAAK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, AddonPackage } from '@embroider/shared-internals';\n\nexport interface RouteFiles {\n route?: string;\n template?: string;\n controller?: string;\n children: Map<string, RouteFiles>;\n}\n\nexport class AppFiles {\n readonly tests: ReadonlyArray<string>;\n readonly components: ReadonlyArray<string>;\n readonly helpers: ReadonlyArray<string>;\n readonly modifiers: ReadonlyArray<string>;\n private perRoute: RouteFiles;\n readonly otherAppFiles: ReadonlyArray<string>;\n readonly isFastbootOnly: Map<string, boolean>;\n readonly fastbootFiles: { [appName: string]: { localFilename: string; shadowedFilename: string | undefined } };\n\n constructor(\n readonly engine: Engine,\n appFiles: Set<string>,\n fastbootFiles: Set<string>,\n resolvableExtensions: RegExp,\n podModulePrefix?: string\n ) {\n let tests: string[] = [];\n let components: string[] = [];\n let helpers: string[] = [];\n let modifiers: string[] = [];\n let otherAppFiles: string[] = [];\n this.perRoute = { children: new Map() };\n\n let combinedFiles = new Set<string>();\n let combinedNonFastbootFiles = new Set<string>();\n let isFastbootOnly = new Map<string, boolean>();\n\n for (let f of appFiles) {\n combinedFiles.add(f);\n combinedNonFastbootFiles.add(f);\n }\n for (let f of fastbootFiles) {\n combinedFiles.add(f);\n }\n\n for (let addon of engine.addons) {\n let appJS = addon.meta['app-js'];\n if (appJS) {\n for (let filename of Object.keys(appJS)) {\n filename = filename.replace(/^\\.\\//, '');\n combinedFiles.add(filename);\n combinedNonFastbootFiles.add(filename);\n }\n }\n\n let fastbootJS = addon.meta['fastboot-js'];\n if (fastbootJS) {\n for (let filename of Object.keys(fastbootJS)) {\n filename = filename.replace(/^\\.\\//, '');\n combinedFiles.add(filename);\n }\n }\n }\n\n for (let relativePath of combinedFiles) {\n isFastbootOnly.set(relativePath, !combinedNonFastbootFiles.has(relativePath));\n relativePath = relativePath.split(sep).join('/');\n if (!resolvableExtensions.test(relativePath)) {\n continue;\n }\n\n if (/\\.d\\.ts$/.test(relativePath)) {\n // .d.ts files are technically \"*.ts\" files but aren't really and we\n // don't want to include them when we crawl through the app.\n continue;\n }\n\n if (relativePath.startsWith('tests/')) {\n tests.push(relativePath);\n continue;\n }\n\n if (relativePath.startsWith('components/')) {\n // hbs files are resolvable, but not when they're used via co-location.\n // An hbs file is used via colocation when it's inside the components\n // directory, and also not named \"template.hbs\" (because that is an\n // older pattern used with pods-like layouts).\n if (!relativePath.endsWith('.hbs') || relativePath.endsWith('/template.hbs')) {\n components.push(relativePath);\n }\n continue;\n }\n\n if (relativePath.startsWith('templates/components/')) {\n components.push(relativePath);\n continue;\n }\n\n if (relativePath.startsWith('helpers/')) {\n helpers.push(relativePath);\n continue;\n }\n\n if (relativePath.startsWith('modifiers/')) {\n modifiers.push(relativePath);\n continue;\n }\n\n if (\n this.handleClassicRouteFile(relativePath) ||\n (podModulePrefix !== undefined && this.handlePodsRouteFile(relativePath, podModulePrefix))\n ) {\n continue;\n }\n\n otherAppFiles.push(relativePath);\n }\n this.tests = tests;\n this.components = components;\n this.helpers = helpers;\n this.modifiers = modifiers;\n this.otherAppFiles = otherAppFiles;\n this.isFastbootOnly = isFastbootOnly;\n\n // this deliberately only describes the app's fastboot files. Not the full\n // merge from all the addons. This is because they need different handling\n // in the module resolver -- addon fastboot files can always be a\n // fallbackResolve, because if the app happens to define the same name\n // (whether fastboot-specific or just browser) that wins over the addon.\n // Whereas if the app itself defines a fastbot-specific version of a file,\n // that must take precedence over the *normal* resolution, and must be\n // implemented in beforeResolve.\n this.fastbootFiles = Object.fromEntries(\n [...fastbootFiles].map(name => [\n `./${name}`,\n {\n localFilename: `./_fastboot_/${name}`,\n shadowedFilename: appFiles.has(name) ? `./${name}` : undefined,\n },\n ])\n );\n }\n\n private handleClassicRouteFile(relativePath: string): boolean {\n let [prefix, ...rest] = relativePath.replace(/\\.\\w{1,3}$/, '').split('/');\n if (!['controllers', 'templates', 'routes'].includes(prefix)) {\n return false;\n }\n let type = prefix.slice(0, -1) as 'controller' | 'template' | 'route';\n let cursor = this.perRoute;\n for (let part of rest) {\n let child = cursor.children.get(part);\n if (child) {\n cursor = child;\n } else {\n let newEntry = { children: new Map() };\n cursor.children.set(part, newEntry);\n cursor = newEntry;\n }\n }\n cursor[type] = relativePath;\n return true;\n }\n\n private handlePodsRouteFile(relativePath: string, podModulePrefix: string): boolean {\n let parts = relativePath.replace(/\\.\\w{1,3}$/, '').split('/');\n let type = parts.pop();\n if (!type || !['controller', 'template', 'route'].includes(type)) {\n return false;\n }\n let podParts = podModulePrefix.split('/');\n // The first part of podModulePrefix is the app's package name\n podParts.shift();\n\n for (let podPart of podParts) {\n if (parts.shift() !== podPart) {\n return false;\n }\n }\n\n let cursor = this.perRoute;\n for (let part of parts) {\n let child = cursor.children.get(part);\n if (child) {\n cursor = child;\n } else {\n let newEntry = { children: new Map() };\n cursor.children.set(part, newEntry);\n cursor = newEntry;\n }\n }\n cursor[type as 'controller' | 'template' | 'route'] = relativePath;\n return true;\n }\n\n get routeFiles(): Readonly<RouteFiles> {\n return this.perRoute;\n }\n}\n\nexport interface Engine {\n // the engine's own package\n package: Package;\n // the set of active addons in the engine\n addons: Set<AddonPackage>;\n // the parent engine, if any\n parent: Engine | undefined;\n // where the engine's own V2 code comes from\n sourcePath: string;\n // runtime name for the engine's own module namespace\n modulePrefix: string;\n // this is destPath but relative to the app itself\n appRelativePath: string;\n}\n"]}
|
1
|
+
{"version":3,"file":"app-files.js","sourceRoot":"","sources":["app-files.ts"],"names":[],"mappings":";;;AAAA,+BAA2B;AAU3B,MAAa,QAAQ;IAUnB,YACW,MAAc,EACvB,QAAqB,EACrB,aAA0B,EAC1B,oBAA4B,EAC5B,eAAwB;QAJf,WAAM,GAAN,MAAM,CAAQ;QAMvB,IAAI,KAAK,GAAa,EAAE,CAAC;QACzB,IAAI,UAAU,GAAa,EAAE,CAAC;QAC9B,IAAI,OAAO,GAAa,EAAE,CAAC;QAC3B,IAAI,SAAS,GAAa,EAAE,CAAC;QAC7B,IAAI,aAAa,GAAa,EAAE,CAAC;QACjC,IAAI,CAAC,QAAQ,GAAG,EAAE,QAAQ,EAAE,IAAI,GA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,CAAC,IAAI,CAAC,CAAC;YACtC,IAAI,KAAK,EAAE;gBACT,MAAM,GAAG,KAAK,CAAC;aAChB;iBAAM;gBACL,IAAI,QAAQ,GAAG,EAAE,QAAQ,EAAE,IAAI,GAAG,EAAE,EAAE,CAAC;gBACvC,MAAM,CAAC,QAAQ,CAAC,GAAG,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC;gBACpC,MAAM,GAAG,QAAQ,CAAC;aACnB;SACF;QACD,MAAM,CAAC,IAA2C,CAAC,GAAG,YAAY,CAAC;QACnE,OAAO,IAAI,CAAC;IACd,CAAC;IAED,IAAI,UAAU;QACZ,OAAO,IAAI,CAAC,QAAQ,CAAC;IACvB,CAAC;CACF;AA7LD,4BA6LC","sourcesContent":["import { sep } from 'path';\nimport { Package, AddonPackage } from '@embroider/shared-internals';\n\nexport interface RouteFiles {\n route?: string;\n template?: string;\n controller?: string;\n children: Map<string, RouteFiles>;\n}\n\nexport class AppFiles {\n readonly tests: ReadonlyArray<string>;\n readonly components: ReadonlyArray<string>;\n readonly helpers: ReadonlyArray<string>;\n readonly modifiers: ReadonlyArray<string>;\n private perRoute: RouteFiles;\n readonly otherAppFiles: ReadonlyArray<string>;\n readonly isFastbootOnly: Map<string, boolean>;\n readonly fastbootFiles: { [appName: string]: { localFilename: string; shadowedFilename: string | undefined } };\n\n constructor(\n readonly engine: Engine,\n appFiles: Set<string>,\n fastbootFiles: Set<string>,\n resolvableExtensions: RegExp,\n podModulePrefix?: string\n ) {\n let tests: string[] = [];\n let components: string[] = [];\n let helpers: string[] = [];\n let modifiers: string[] = [];\n let otherAppFiles: string[] = [];\n this.perRoute = { children: new Map() };\n\n let combinedFiles = new Set<string>();\n let combinedNonFastbootFiles = new Set<string>();\n let isFastbootOnly = new Map<string, boolean>();\n\n for (let f of appFiles) {\n combinedFiles.add(f);\n combinedNonFastbootFiles.add(f);\n }\n for (let f of fastbootFiles) {\n combinedFiles.add(f);\n }\n\n for (let addon of engine.addons) {\n let appJS = addon.meta['app-js'];\n if (appJS) {\n for (let filename of Object.keys(appJS)) {\n filename = filename.replace(/^\\.\\//, '');\n combinedFiles.add(filename);\n combinedNonFastbootFiles.add(filename);\n }\n }\n\n let fastbootJS = addon.meta['fastboot-js'];\n if (fastbootJS) {\n for (let filename of Object.keys(fastbootJS)) {\n filename = filename.replace(/^\\.\\//, '');\n combinedFiles.add(filename);\n }\n }\n }\n\n for (let relativePath of combinedFiles) {\n isFastbootOnly.set(relativePath, !combinedNonFastbootFiles.has(relativePath));\n relativePath = relativePath.split(sep).join('/');\n if (!resolvableExtensions.test(relativePath)) {\n continue;\n }\n\n if (/\\.d\\.ts$/.test(relativePath)) {\n // .d.ts files are technically \"*.ts\" files but aren't really and we\n // don't want to include them when we crawl through the app.\n continue;\n }\n\n if (relativePath.startsWith('tests/')) {\n tests.push(relativePath);\n continue;\n }\n\n if (relativePath.startsWith('components/')) {\n // hbs files are resolvable, but not when they're used via co-location.\n // An hbs file is used via colocation when it's inside the components\n // directory, and also not named \"template.hbs\" (because that is an\n // older pattern used with pods-like layouts).\n if (!relativePath.endsWith('.hbs') || relativePath.endsWith('/template.hbs')) {\n components.push(relativePath);\n }\n continue;\n }\n\n if (relativePath.startsWith('templates/components/')) {\n components.push(relativePath);\n continue;\n }\n\n if (relativePath.startsWith('helpers/')) {\n helpers.push(relativePath);\n continue;\n }\n\n if (relativePath.startsWith('modifiers/')) {\n modifiers.push(relativePath);\n continue;\n }\n\n if (\n (podModulePrefix !== undefined && this.handlePodsRouteFile(relativePath, podModulePrefix)) ||\n this.handleClassicRouteFile(relativePath)\n ) {\n continue;\n }\n\n otherAppFiles.push(relativePath);\n }\n this.tests = tests;\n this.components = components;\n this.helpers = helpers;\n this.modifiers = modifiers;\n this.otherAppFiles = otherAppFiles;\n this.isFastbootOnly = isFastbootOnly;\n\n // this deliberately only describes the app's fastboot files. Not the full\n // merge from all the addons. This is because they need different handling\n // in the module resolver -- addon fastboot files can always be a\n // fallbackResolve, because if the app happens to define the same name\n // (whether fastboot-specific or just browser) that wins over the addon.\n // Whereas if the app itself defines a fastbot-specific version of a file,\n // that must take precedence over the *normal* resolution, and must be\n // implemented in beforeResolve.\n this.fastbootFiles = Object.fromEntries(\n [...fastbootFiles].map(name => [\n `./${name}`,\n {\n localFilename: `./_fastboot_/${name}`,\n shadowedFilename: appFiles.has(name) ? `./${name}` : undefined,\n },\n ])\n );\n }\n\n private handleClassicRouteFile(relativePath: string): boolean {\n let [prefix, ...rest] = relativePath.replace(/\\.\\w{1,3}$/, '').split('/');\n if (!['controllers', 'templates', 'routes'].includes(prefix)) {\n return false;\n }\n let type = prefix.slice(0, -1) as 'controller' | 'template' | 'route';\n let cursor = this.perRoute;\n for (let part of rest) {\n let child = cursor.children.get(part);\n if (child) {\n cursor = child;\n } else {\n let newEntry = { children: new Map() };\n cursor.children.set(part, newEntry);\n cursor = newEntry;\n }\n }\n cursor[type] = relativePath;\n return true;\n }\n\n private handlePodsRouteFile(relativePath: string, podModulePrefix: string): boolean {\n let parts = relativePath.replace(/\\.\\w{1,3}$/, '').split('/');\n let type = parts.pop();\n if (!type || !['controller', 'template', 'route'].includes(type)) {\n return false;\n }\n let podParts = podModulePrefix.split('/');\n // The first part of podModulePrefix is the app's package name\n podParts.shift();\n\n for (let podPart of podParts) {\n if (parts.shift() !== podPart) {\n return false;\n }\n }\n\n let cursor = this.perRoute;\n for (let part of parts) {\n let child = cursor.children.get(part);\n if (child) {\n cursor = child;\n } else {\n let newEntry = { children: new Map() };\n cursor.children.set(part, newEntry);\n cursor = newEntry;\n }\n }\n cursor[type as 'controller' | 'template' | 'route'] = relativePath;\n return true;\n }\n\n get routeFiles(): Readonly<RouteFiles> {\n return this.perRoute;\n }\n}\n\nexport interface Engine {\n // the engine's own package\n package: Package;\n // the set of active addons in the engine\n addons: Set<AddonPackage>;\n // the parent engine, if any\n parent: Engine | undefined;\n // where the engine's own V2 code comes from\n sourcePath: string;\n // runtime name for the engine's own module namespace\n modulePrefix: string;\n // this is destPath but relative to the app itself\n appRelativePath: string;\n}\n"]}
|
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,25 +574,31 @@ class Resolver {
|
|
551
574
|
if (!packageName) {
|
552
575
|
return request;
|
553
576
|
}
|
554
|
-
|
555
|
-
|
556
|
-
|
557
|
-
|
558
|
-
|
559
|
-
|
577
|
+
let pkg = this.packageCache.ownerOfFile(request.fromFile);
|
578
|
+
if (!pkg || !pkg.isV2Ember()) {
|
579
|
+
return request;
|
580
|
+
}
|
581
|
+
// real deps take precedence over renaming rules. That is, a package like
|
582
|
+
// ember-source might provide backburner via module renaming, but if you
|
583
|
+
// have an explicit dependency on backburner you should still get that real
|
584
|
+
// copy.
|
585
|
+
if (!pkg.hasDependency(packageName)) {
|
586
|
+
for (let [candidate, replacement] of Object.entries(this.options.renameModules)) {
|
587
|
+
if (candidate === request.specifier) {
|
560
588
|
return logTransition(`renameModules`, request, request.alias(replacement));
|
561
589
|
}
|
562
|
-
|
563
|
-
|
590
|
+
for (let extension of this.options.resolvableExtensions) {
|
591
|
+
if (candidate === request.specifier + '/index' + extension) {
|
592
|
+
return logTransition(`renameModules`, request, request.alias(replacement));
|
593
|
+
}
|
594
|
+
if (candidate === request.specifier + extension) {
|
595
|
+
return logTransition(`renameModules`, request, request.alias(replacement));
|
596
|
+
}
|
564
597
|
}
|
565
598
|
}
|
566
|
-
|
567
|
-
|
568
|
-
|
569
|
-
}
|
570
|
-
let pkg = this.owningPackage(request.fromFile);
|
571
|
-
if (!pkg || !pkg.isV2Ember()) {
|
572
|
-
return request;
|
599
|
+
if (this.options.renamePackages[packageName]) {
|
600
|
+
return logTransition(`renamePackages`, request, request.alias(request.specifier.replace(packageName, this.options.renamePackages[packageName])));
|
601
|
+
}
|
573
602
|
}
|
574
603
|
if (pkg.meta['auto-upgraded'] && pkg.name === packageName) {
|
575
604
|
// we found a self-import, resolve it for them. Only auto-upgraded
|
@@ -597,7 +626,7 @@ class Resolver {
|
|
597
626
|
return request;
|
598
627
|
}
|
599
628
|
let { specifier, fromFile } = request;
|
600
|
-
let pkg = this.
|
629
|
+
let pkg = this.packageCache.ownerOfFile(fromFile);
|
601
630
|
if (!pkg || !pkg.isV2Ember()) {
|
602
631
|
return request;
|
603
632
|
}
|
@@ -619,7 +648,7 @@ class Resolver {
|
|
619
648
|
let packageRelativeSpecifier = (0, shared_internals_2.explicitRelative)(pkg.root, absoluteSpecifier);
|
620
649
|
if (isExplicitlyExternal(packageRelativeSpecifier, pkg)) {
|
621
650
|
let publicSpecifier = absoluteSpecifier.replace(pkg.root, pkg.name);
|
622
|
-
return external('beforeResolve', request, publicSpecifier);
|
651
|
+
return this.external('beforeResolve', request, publicSpecifier);
|
623
652
|
}
|
624
653
|
// if the requesting file is in an addon's app-js, the relative request
|
625
654
|
// should really be understood as a request for a module in the containing
|
@@ -633,10 +662,10 @@ class Resolver {
|
|
633
662
|
// absolute package imports can also be explicitly external based on their
|
634
663
|
// full specifier name
|
635
664
|
if (isExplicitlyExternal(specifier, pkg)) {
|
636
|
-
return external('beforeResolve', request, specifier);
|
665
|
+
return this.external('beforeResolve', request, specifier);
|
637
666
|
}
|
638
667
|
if (shared_internals_1.emberVirtualPackages.has(packageName) && !pkg.hasDependency(packageName)) {
|
639
|
-
return external('beforeResolve emberVirtualPackages', request, specifier);
|
668
|
+
return this.external('beforeResolve emberVirtualPackages', request, specifier);
|
640
669
|
}
|
641
670
|
if (shared_internals_1.emberVirtualPeerDeps.has(packageName) && !pkg.hasDependency(packageName)) {
|
642
671
|
// addons (whether auto-upgraded or not) may use the app's
|
@@ -657,7 +686,7 @@ class Resolver {
|
|
657
686
|
if (!dep.isEmberPackage()) {
|
658
687
|
// classic ember addons can only import non-ember dependencies if they
|
659
688
|
// have ember-auto-import.
|
660
|
-
return external('v1 package without auto-import', request, specifier);
|
689
|
+
return this.external('v1 package without auto-import', request, specifier);
|
661
690
|
}
|
662
691
|
}
|
663
692
|
catch (err) {
|
@@ -676,7 +705,40 @@ class Resolver {
|
|
676
705
|
}
|
677
706
|
return request;
|
678
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
|
+
}
|
679
740
|
fallbackResolve(request) {
|
741
|
+
var _a;
|
680
742
|
let { specifier, fromFile } = request;
|
681
743
|
if (compatPattern.test(specifier)) {
|
682
744
|
// Some kinds of compat requests get rewritten into other things
|
@@ -694,7 +756,7 @@ class Resolver {
|
|
694
756
|
// here.
|
695
757
|
return request;
|
696
758
|
}
|
697
|
-
let pkg = this.
|
759
|
+
let pkg = this.packageCache.ownerOfFile(fromFile);
|
698
760
|
if (!pkg) {
|
699
761
|
return logTransition('no identifiable owningPackage', request);
|
700
762
|
}
|
@@ -704,7 +766,10 @@ class Resolver {
|
|
704
766
|
// isV2Ember()
|
705
767
|
let movedPkg = this.packageCache.maybeMoved(pkg);
|
706
768
|
if (movedPkg !== pkg) {
|
707
|
-
|
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;
|
708
773
|
pkg = movedPkg;
|
709
774
|
}
|
710
775
|
if (!pkg.isV2Ember()) {
|
@@ -726,22 +791,6 @@ class Resolver {
|
|
726
791
|
}
|
727
792
|
}
|
728
793
|
else {
|
729
|
-
if (pkg.meta['auto-upgraded'] && (0, path_1.dirname)(request.fromFile) === pkg.root) {
|
730
|
-
let otherRoot = this.options.activeAddons[pkg.name];
|
731
|
-
if (otherRoot && otherRoot !== pkg.root) {
|
732
|
-
// This provides some backward-compatibility with the way things
|
733
|
-
// would have resolved in earlier embroider versions, where the
|
734
|
-
// final fallback was always the activeAddons. These requests now
|
735
|
-
// end up getting converted to relative requests inside a particular
|
736
|
-
// moved package, which is why we need to handle them here.
|
737
|
-
//
|
738
|
-
// TODO: We shouldn't need this if we generate notional per-package
|
739
|
-
// entrypoints that pull in all the implicit-modules, so that the
|
740
|
-
// imports for implicit-modules happen in places with normal
|
741
|
-
// dependency resolvability.
|
742
|
-
return logTransition('fallbackResolve: relative path falling through to activeAddons', request, request.rehome((0, path_1.resolve)(otherRoot, 'package.json')));
|
743
|
-
}
|
744
|
-
}
|
745
794
|
// nothing else to do for relative imports
|
746
795
|
return logTransition('fallbackResolve: relative failure', request);
|
747
796
|
}
|
@@ -773,14 +822,14 @@ class Resolver {
|
|
773
822
|
// runtime. Native v2 packages can only get this behavior in the
|
774
823
|
// isExplicitlyExternal case above because they need to explicitly ask for
|
775
824
|
// externals.
|
776
|
-
return external('v1 catch-all fallback', request, specifier);
|
825
|
+
return this.external('v1 catch-all fallback', request, specifier);
|
777
826
|
}
|
778
827
|
else {
|
779
828
|
// native v2 packages don't automatically externalize *everything* the way
|
780
829
|
// auto-upgraded packages do, but they still externalize known and approved
|
781
830
|
// ember virtual packages (like @ember/component)
|
782
831
|
if (shared_internals_1.emberVirtualPackages.has(packageName)) {
|
783
|
-
return external('emberVirtualPackages', request, specifier);
|
832
|
+
return this.external('emberVirtualPackages', request, specifier);
|
784
833
|
}
|
785
834
|
}
|
786
835
|
// this is falling through with the original specifier which was
|
@@ -852,7 +901,7 @@ class Resolver {
|
|
852
901
|
// check if this file is resolvable as a global component, and if so return
|
853
902
|
// its dasherized name
|
854
903
|
reverseComponentLookup(filename) {
|
855
|
-
const owningPackage = this.
|
904
|
+
const owningPackage = this.packageCache.ownerOfFile(filename);
|
856
905
|
if (!(owningPackage === null || owningPackage === void 0 ? void 0 : owningPackage.isV2Ember())) {
|
857
906
|
return;
|
858
907
|
}
|
@@ -915,8 +964,4 @@ function reliablyResolvable(pkg, packageName) {
|
|
915
964
|
function appImportInAppTree(inPackage, inLogicalPackage, importedPackageName) {
|
916
965
|
return inPackage !== inLogicalPackage && importedPackageName === inLogicalPackage.name;
|
917
966
|
}
|
918
|
-
function external(label, request, specifier) {
|
919
|
-
let filename = (0, virtual_content_1.virtualExternalModule)(specifier);
|
920
|
-
return logTransition(label, request, request.virtualize(filename));
|
921
|
-
}
|
922
967
|
//# sourceMappingURL=module-resolver.js.map
|