@embroider/core
Advanced tools
Comparing version 3.4.15-unstable.e9544fc to 3.4.15
{ | ||
"name": "@embroider/core", | ||
"version": "3.4.15-unstable.e9544fc", | ||
"version": "3.4.15", | ||
"private": false, | ||
@@ -30,3 +30,2 @@ "description": "A build system for EmberJS applications.", | ||
"debug": "^4.3.2", | ||
"escape-string-regexp": "^4.0.0", | ||
"fast-sourcemap-concat": "^2.1.1", | ||
@@ -42,8 +41,6 @@ "filesize": "^10.0.7", | ||
"resolve-package-path": "^4.0.1", | ||
"resolve.exports": "^2.0.2", | ||
"typescript-memoize": "^1.0.1", | ||
"walk-sync": "^3.0.0", | ||
"@embroider/macros": "1.16.6-unstable.e9544fc", | ||
"@embroider/shared-internals": "2.6.3-unstable.e9544fc", | ||
"@embroider/reverse-exports": "0.1.1-unstable.e9544fc" | ||
"@embroider/macros": "1.16.6", | ||
"@embroider/shared-internals": "2.6.3" | ||
}, | ||
@@ -57,4 +54,4 @@ "devDependencies": { | ||
"@types/fs-extra": "^9.0.12", | ||
"@types/jsdom": "^16.2.11", | ||
"@types/js-string-escape": "^1.0.0", | ||
"@types/jsdom": "^16.2.11", | ||
"@types/lodash": "^4.14.170", | ||
@@ -66,3 +63,3 @@ "@types/node": "^15.12.2", | ||
"tmp": "^0.1.0", | ||
"typescript": "^5.4.5", | ||
"typescript": "^5.1.6", | ||
"@embroider/sample-transforms": "0.0.0", | ||
@@ -69,0 +66,0 @@ "@embroider/test-support": "0.36.0" |
@@ -23,3 +23,3 @@ import type { Package, AddonPackage } from '@embroider/shared-internals'; | ||
}; | ||
constructor(engine: Engine, appFiles: Set<string>, fastbootFiles: Set<string>, resolvableExtensions: RegExp, staticAppPathsPattern: RegExp | undefined, podModulePrefix?: string); | ||
constructor(engine: Engine, appFiles: Set<string>, fastbootFiles: Set<string>, resolvableExtensions: RegExp, podModulePrefix?: string); | ||
private handleClassicRouteFile; | ||
@@ -31,6 +31,7 @@ private handlePodsRouteFile; | ||
package: Package; | ||
addons: Map<AddonPackage, string>; | ||
isApp: boolean; | ||
addons: Set<AddonPackage>; | ||
parent: Engine | undefined; | ||
sourcePath: string; | ||
modulePrefix: string; | ||
appRelativePath: string; | ||
} |
@@ -6,3 +6,3 @@ "use strict"; | ||
class AppFiles { | ||
constructor(engine, appFiles, fastbootFiles, resolvableExtensions, staticAppPathsPattern, podModulePrefix) { | ||
constructor(engine, appFiles, fastbootFiles, resolvableExtensions, podModulePrefix) { | ||
this.engine = engine; | ||
@@ -25,3 +25,3 @@ let tests = []; | ||
} | ||
for (let addon of engine.addons.keys()) { | ||
for (let addon of engine.addons) { | ||
let appJS = addon.meta['app-js']; | ||
@@ -59,21 +59,9 @@ if (appJS) { | ||
if (relativePath.startsWith('components/')) { | ||
// hbs files are not resolvable when they're used via co-location with | ||
// an associated js file because it's the js that is resolvable. | ||
// hbs files are resolvable, but not when they're used via co-location. | ||
// An hbs file is used via colocation when it's inside the components | ||
// directory, and also not named "template.hbs" (because that is an | ||
// older pattern used with pods-like layouts). | ||
let isHbs = relativePath.endsWith('.hbs'); | ||
if (!isHbs || relativePath.endsWith('/template.hbs')) { | ||
if (!relativePath.endsWith('.hbs') || relativePath.endsWith('/template.hbs')) { | ||
components.push(relativePath); | ||
} | ||
else if (isHbs) { | ||
// template-only components will be compiled as js files during the | ||
// build process, so we push a virtual path to js in the list of files | ||
// because the resolver will be able to recognize a template-only and | ||
// give a correct answer in the end. | ||
let jsPath = relativePath.replace(/\.hbs$/, '.js'); | ||
if (!combinedFiles.has(jsPath)) { | ||
components.push(jsPath); | ||
} | ||
} | ||
continue; | ||
@@ -97,10 +85,3 @@ } | ||
} | ||
if (staticAppPathsPattern) { | ||
if (!staticAppPathsPattern.test(relativePath)) { | ||
otherAppFiles.push(relativePath); | ||
} | ||
} | ||
else { | ||
otherAppFiles.push(relativePath); | ||
} | ||
otherAppFiles.push(relativePath); | ||
} | ||
@@ -107,0 +88,0 @@ this.tests = tests; |
export { Packager, PackagerConstructor, Variant, applyVariantToBabelConfig, getAppMeta, getPackagerCacheDir, } from './packager'; | ||
export { HTMLEntrypoint, BundleSummary } from './html-entrypoint'; | ||
export { default as Stage } from './stage'; | ||
export { Asset, EmberAsset, ImplicitAssetPaths } from './asset'; | ||
export { default as Options, optionsWithDefaults } from './options'; | ||
@@ -9,3 +10,3 @@ export { default as toBroccoliPlugin } from './to-broccoli-plugin'; | ||
export { todo, unsupported, warn, debug, expectWarning, throwOnWarnings } from './messages'; | ||
export { Resolver, Options as ResolverOptions, ModuleRequest, Resolution } from './module-resolver'; | ||
export { Resolver, Options as ResolverOptions, ModuleRequest, Resolution, ResolverFunction, SyncResolverFunction, } from './module-resolver'; | ||
export { ResolverLoader } from './resolver-loader'; | ||
@@ -12,0 +13,0 @@ export { virtualContent } from './virtual-content'; |
@@ -11,2 +11,5 @@ import type { Package } from '@embroider/shared-internals'; | ||
}; | ||
activeAddons: { | ||
[packageName: string]: string; | ||
}; | ||
resolvableExtensions: string[]; | ||
@@ -16,9 +19,6 @@ appRoot: string; | ||
modulePrefix: string; | ||
splitAtRoutes?: (RegExp | string)[]; | ||
podModulePrefix?: string; | ||
amdCompatibility: Required<UserOptions['amdCompatibility']>; | ||
autoRun: boolean; | ||
staticAppPaths: string[]; | ||
} | ||
export interface EngineConfig { | ||
interface EngineConfig { | ||
packageName: string; | ||
@@ -28,3 +28,2 @@ activeAddons: { | ||
root: string; | ||
canResolveFromFile: string; | ||
}[]; | ||
@@ -38,5 +37,4 @@ fastbootFiles: { | ||
root: string; | ||
isLazy: boolean; | ||
} | ||
export interface ModuleRequest<Res extends Resolution = Resolution> { | ||
export interface ModuleRequest { | ||
readonly specifier: string; | ||
@@ -46,5 +44,2 @@ readonly fromFile: string; | ||
readonly meta: Record<string, unknown> | undefined; | ||
readonly debugType: string; | ||
readonly isNotFound: boolean; | ||
readonly resolvedTo: Res | undefined; | ||
alias(newSpecifier: string): this; | ||
@@ -54,24 +49,20 @@ rehome(newFromFile: string): this; | ||
withMeta(meta: Record<string, any> | undefined): this; | ||
notFound(): this; | ||
defaultResolve(): Promise<Res>; | ||
resolveTo(resolution: Res): this; | ||
} | ||
export type Resolution<T = unknown, E = unknown> = { | ||
type: 'found'; | ||
filename: string; | ||
isVirtual: boolean; | ||
result: T; | ||
} | { | ||
type: 'ignored'; | ||
result: T; | ||
} | { | ||
type: 'not_found'; | ||
err: E; | ||
}; | ||
export type ResolverFunction<R extends ModuleRequest = ModuleRequest, Res extends Resolution = Resolution> = (request: R) => Promise<Res>; | ||
export type SyncResolverFunction<R extends ModuleRequest = ModuleRequest, Res extends Resolution = Resolution> = (request: R) => Res; | ||
export declare class Resolver { | ||
readonly options: Options; | ||
constructor(options: Options); | ||
private beforeResolve; | ||
resolve<ResolveResolution extends Resolution>(request: ModuleRequest<ResolveResolution>): Promise<ResolveResolution>; | ||
nodeResolve(specifier: string, fromFile: string): Promise<{ | ||
beforeResolve<R extends ModuleRequest>(request: R): R; | ||
resolve<Req extends ModuleRequest, Res extends Resolution>(request: Req, defaultResolve: ResolverFunction<Req, Res>): Promise<Res>; | ||
resolveSync<Req extends ModuleRequest, Res extends Resolution>(request: Req, defaultResolve: SyncResolverFunction<Req, Res>): Res; | ||
private internalResolve; | ||
nodeResolve(specifier: string, fromFile: string): { | ||
type: 'virtual'; | ||
@@ -86,3 +77,3 @@ filename: string; | ||
err: Error; | ||
}>; | ||
}; | ||
get packageCache(): RewrittenPackageCache; | ||
@@ -93,9 +84,3 @@ private logicalPackage; | ||
private handleImplicitModules; | ||
private handleEntrypoint; | ||
private handleTestEntrypoint; | ||
private handleRouteEntrypoint; | ||
private handleImplicitTestScripts; | ||
private handleTestSupportStyles; | ||
private handleGlobalsCompat; | ||
private handleVendorStyles; | ||
private resolveHelper; | ||
@@ -114,8 +99,6 @@ private resolveComponent; | ||
private handleRenaming; | ||
private handleVendor; | ||
private resolveWithinMovedPackage; | ||
private preHandleExternal; | ||
private locateActiveAddon; | ||
private external; | ||
private fallbackResolve; | ||
fallbackResolve<R extends ModuleRequest>(request: R): R; | ||
private getEntryFromMergeMap; | ||
@@ -128,1 +111,2 @@ private withResolvableExtensions; | ||
} | ||
export {}; |
@@ -18,4 +18,3 @@ "use strict"; | ||
const assert_never_1 = __importDefault(require("assert-never")); | ||
const reverse_exports_1 = __importDefault(require("@embroider/reverse-exports")); | ||
const resolve_exports_1 = require("resolve.exports"); | ||
const resolve_1 = __importDefault(require("resolve")); | ||
const virtual_content_1 = require("./virtual-content"); | ||
@@ -25,45 +24,49 @@ const typescript_memoize_1 = require("typescript-memoize"); | ||
const fs_1 = require("fs"); | ||
const node_resolve_1 = require("./node-resolve"); | ||
const virtual_route_entrypoint_1 = require("./virtual-route-entrypoint"); | ||
const debug = (0, debug_1.default)('embroider:resolver'); | ||
// Using a formatter makes this work lazy so nothing happens when we aren't | ||
// logging. It is unfortunate that formatters are a globally mutable config and | ||
// you can only use single character names, but oh well. | ||
debug_1.default.formatters.p = (s) => { | ||
let cwd = process.cwd(); | ||
if (s.startsWith(cwd)) { | ||
return s.slice(cwd.length + 1); | ||
} | ||
return s; | ||
}; | ||
function logTransition(reason, before, after = before) { | ||
if (after.isVirtual) { | ||
debug(`[%s:virtualized] %s because %s\n in %p`, before.debugType, before.specifier, reason, before.fromFile); | ||
debug(`virtualized %s in %s because %s`, before.specifier, before.fromFile, reason); | ||
} | ||
else if (after.resolvedTo) { | ||
debug(`[%s:resolvedTo] %s because %s\n in %p`, before.debugType, before.specifier, reason, before.fromFile); | ||
} | ||
else if (before.specifier !== after.specifier) { | ||
if (before.fromFile !== after.fromFile) { | ||
debug(`[%s:aliased and rehomed] %s to %s\n because %s\n from %p\n to %p`, before.debugType, before.specifier, after.specifier, reason, before.fromFile, after.fromFile); | ||
debug(`aliased and rehomed: %s to %s, from %s to %s because %s`, before.specifier, after.specifier, before.fromFile, after.fromFile, reason); | ||
} | ||
else { | ||
debug(`[%s:aliased] %s to %s\n because %s`, before.debugType, before.specifier, after.specifier, reason); | ||
debug(`aliased: %s to %s in %s because`, before.specifier, after.specifier, before.fromFile, reason); | ||
} | ||
} | ||
else if (before.fromFile !== after.fromFile) { | ||
debug(`[%s:rehomed] %s, because %s\n from %p\n to %p`, before.debugType, before.specifier, reason, before.fromFile, after.fromFile); | ||
debug(`rehomed: %s from %s to %s because`, before.specifier, before.fromFile, after.fromFile, reason); | ||
} | ||
else if (after.isNotFound) { | ||
debug(`[%s:not-found] %s because %s\n in %p`, before.debugType, before.specifier, reason, before.fromFile); | ||
} | ||
else { | ||
debug(`[%s:unchanged] %s because %s\n in %p`, before.debugType, before.specifier, reason, before.fromFile); | ||
debug(`unchanged: %s in %s because %s`, before.specifier, before.fromFile, reason); | ||
} | ||
return after; | ||
} | ||
function isTerminal(request) { | ||
return request.isVirtual || request.isNotFound || Boolean(request.resolvedTo); | ||
const compatPattern = /#embroider_compat\/(?<type>[^\/]+)\/(?<rest>.*)/; | ||
class NodeModuleRequest { | ||
constructor(specifier, fromFile, isVirtual, meta) { | ||
this.specifier = specifier; | ||
this.fromFile = fromFile; | ||
this.isVirtual = isVirtual; | ||
this.meta = meta; | ||
} | ||
alias(specifier) { | ||
return new NodeModuleRequest(specifier, this.fromFile, false, this.meta); | ||
} | ||
rehome(fromFile) { | ||
if (this.fromFile === fromFile) { | ||
return this; | ||
} | ||
else { | ||
return new NodeModuleRequest(this.specifier, fromFile, false, this.meta); | ||
} | ||
} | ||
virtualize(filename) { | ||
return new NodeModuleRequest(filename, this.fromFile, true, this.meta); | ||
} | ||
withMeta(meta) { | ||
return new NodeModuleRequest(this.specifier, this.fromFile, this.isVirtual, meta); | ||
} | ||
} | ||
const compatPattern = /@embroider\/virtual\/(?<type>[^\/]+)\/(?<rest>.*)/; | ||
class Resolver { | ||
@@ -73,3 +76,3 @@ constructor(options) { | ||
} | ||
async beforeResolve(request) { | ||
beforeResolve(request) { | ||
if (request.specifier === '@embroider/macros') { | ||
@@ -82,16 +85,6 @@ // the macros package is always handled directly within babel (not | ||
} | ||
if (request.specifier === 'require') { | ||
return this.external('early require', request, request.specifier); | ||
} | ||
request = this.handleFastbootSwitch(request); | ||
request = await this.handleGlobalsCompat(request); | ||
request = this.handleGlobalsCompat(request); | ||
request = this.handleImplicitModules(request); | ||
request = this.handleImplicitTestScripts(request); | ||
request = this.handleVendorStyles(request); | ||
request = this.handleTestSupportStyles(request); | ||
request = this.handleEntrypoint(request); | ||
request = this.handleTestEntrypoint(request); | ||
request = this.handleRouteEntrypoint(request); | ||
request = this.handleRenaming(request); | ||
request = this.handleVendor(request); | ||
// we expect the specifier to be app relative at this point - must be after handleRenaming | ||
@@ -110,11 +103,32 @@ request = this.generateFastbootSwitch(request); | ||
// rules. | ||
async resolve(request) { | ||
request = await this.beforeResolve(request); | ||
if (request.resolvedTo) { | ||
return request.resolvedTo; | ||
// | ||
// Depending on the plugin architecture you're working in, it may be easier to | ||
// call beforeResolve and fallbackResolve directly, in which case matching the | ||
// details of the recursion to what this method does are your responsibility. | ||
async resolve(request, defaultResolve) { | ||
let gen = this.internalResolve(request, defaultResolve); | ||
let out = gen.next(); | ||
while (!out.done) { | ||
out = gen.next(await out.value); | ||
} | ||
let resolution = await request.defaultResolve(); | ||
return out.value; | ||
} | ||
// synchronous alternative to resolve() above. Because our own internals are | ||
// all synchronous, you can use this if your defaultResolve function is | ||
// synchronous. | ||
resolveSync(request, defaultResolve) { | ||
let gen = this.internalResolve(request, defaultResolve); | ||
let out = gen.next(); | ||
while (!out.done) { | ||
out = gen.next(out.value); | ||
} | ||
return out.value; | ||
} | ||
// Our core implementation is a generator so it can power both resolve() and | ||
// resolveSync() | ||
*internalResolve(request, defaultResolve) { | ||
request = this.beforeResolve(request); | ||
let resolution = yield defaultResolve(request); | ||
switch (resolution.type) { | ||
case 'found': | ||
case 'ignored': | ||
return resolution; | ||
@@ -126,3 +140,3 @@ case 'not_found': | ||
} | ||
let nextRequest = await this.fallbackResolve(request); | ||
let nextRequest = this.fallbackResolve(request); | ||
if (nextRequest === request) { | ||
@@ -132,15 +146,12 @@ // no additional fallback is available. | ||
} | ||
if (nextRequest.resolvedTo) { | ||
return nextRequest.resolvedTo; | ||
} | ||
if (nextRequest.fromFile === request.fromFile && nextRequest.specifier === request.specifier) { | ||
throw new Error('Bug Discovered! New request is not === original request but has the same fromFile and specifier. This will likely create a loop.'); | ||
} | ||
if (nextRequest.isVirtual || nextRequest.isNotFound) { | ||
// virtual and NotFound requests are terminal, there is no more | ||
// beforeResolve or fallbackResolve around them. The defaultResolve is | ||
// expected to know how to implement them. | ||
return nextRequest.defaultResolve(); | ||
if (nextRequest.isVirtual) { | ||
// virtual requests are terminal, there is no more beforeResolve or | ||
// fallbackResolve around them. The defaultResolve is expected to know how | ||
// to implement them. | ||
return yield defaultResolve(nextRequest); | ||
} | ||
return this.resolve(nextRequest); | ||
return yield* this.internalResolve(nextRequest, defaultResolve); | ||
} | ||
@@ -150,4 +161,36 @@ // Use standard NodeJS resolving, with our required compatibility rules on | ||
// defaultResolve already configured to be "do the normal node thing". | ||
async nodeResolve(specifier, fromFile) { | ||
return (0, node_resolve_1.nodeResolve)(this, specifier, fromFile); | ||
nodeResolve(specifier, fromFile) { | ||
let resolution = this.resolveSync(new NodeModuleRequest(specifier, fromFile, false, undefined), request => { | ||
if (request.isVirtual) { | ||
return { | ||
type: 'found', | ||
result: { | ||
type: 'virtual', | ||
content: (0, virtual_content_1.virtualContent)(request.specifier, this), | ||
filename: request.specifier, | ||
}, | ||
}; | ||
} | ||
try { | ||
let filename = resolve_1.default.sync(request.specifier, { | ||
basedir: (0, path_1.dirname)(request.fromFile), | ||
extensions: this.options.resolvableExtensions, | ||
}); | ||
return { type: 'found', result: { type: 'real', filename } }; | ||
} | ||
catch (err) { | ||
if (err.code !== 'MODULE_NOT_FOUND') { | ||
throw err; | ||
} | ||
return { type: 'not_found', err }; | ||
} | ||
}); | ||
switch (resolution.type) { | ||
case 'not_found': | ||
return resolution; | ||
case 'found': | ||
return resolution.result; | ||
default: | ||
throw (0, assert_never_1.default)(resolution); | ||
} | ||
} | ||
@@ -169,5 +212,2 @@ get packageCache() { | ||
generateFastbootSwitch(request) { | ||
if (isTerminal(request)) { | ||
return request; | ||
} | ||
let pkg = this.packageCache.ownerOfFile(request.fromFile); | ||
@@ -190,5 +230,3 @@ if (!pkg) { | ||
if (fastbootFile.shadowedFilename) { | ||
let { names } = (0, describe_exports_1.describeExports)((0, fs_1.readFileSync)((0, path_1.resolve)(pkg.root, fastbootFile.shadowedFilename), 'utf8'), { | ||
configFile: false, | ||
}); | ||
let { names } = (0, describe_exports_1.describeExports)((0, fs_1.readFileSync)((0, path_1.resolve)(pkg.root, fastbootFile.shadowedFilename), 'utf8'), {}); | ||
let switchFile = (0, virtual_content_1.fastbootSwitch)(candidate, (0, path_1.resolve)(pkg.root, 'package.json'), names); | ||
@@ -212,5 +250,2 @@ if (switchFile === request.fromFile) { | ||
var _a; | ||
if (isTerminal(request)) { | ||
return request; | ||
} | ||
let match = (0, virtual_content_1.decodeFastbootSwitch)(request.fromFile); | ||
@@ -254,3 +289,3 @@ if (!match) { | ||
if ((entry === null || entry === void 0 ? void 0 : entry.type) === 'both') { | ||
return logTransition('matched addon entry', request, request.alias(entry[section].specifier).rehome(entry[section].fromFile)); | ||
return logTransition('matched addon entry', request, request.alias(entry[section].localPath).rehome((0, path_1.resolve)(entry[section].packageRoot, 'package.json'))); | ||
} | ||
@@ -261,5 +296,2 @@ } | ||
handleImplicitModules(request) { | ||
if (isTerminal(request)) { | ||
return request; | ||
} | ||
let im = (0, virtual_content_1.decodeImplicitModules)(request.specifier); | ||
@@ -282,99 +314,3 @@ if (!im) { | ||
} | ||
handleEntrypoint(request) { | ||
if (isTerminal(request)) { | ||
return request; | ||
} | ||
//TODO move the extra forwardslash handling out into the vite plugin | ||
const candidates = ['@embroider/core/entrypoint', '/@embroider/core/entrypoint', './@embroider/core/entrypoint']; | ||
if (!candidates.some(c => request.specifier.startsWith(c + '/') || request.specifier === c)) { | ||
return request; | ||
} | ||
const result = /\.?\/?@embroider\/core\/entrypoint(?:\/(?<packageName>.*))?/.exec(request.specifier); | ||
if (!result) { | ||
// TODO make a better error | ||
throw new Error('entrypoint does not match pattern' + request.specifier); | ||
} | ||
const { packageName } = result.groups; | ||
const requestingPkg = this.packageCache.ownerOfFile(request.fromFile); | ||
if (!(requestingPkg === null || requestingPkg === void 0 ? void 0 : requestingPkg.isV2Ember())) { | ||
throw new Error(`bug: found entrypoint import in non-ember package at ${request.fromFile}`); | ||
} | ||
let pkg; | ||
if (packageName) { | ||
pkg = this.packageCache.resolve(packageName, requestingPkg); | ||
} | ||
else { | ||
pkg = requestingPkg; | ||
} | ||
return logTransition('entrypoint', request, request.virtualize((0, path_1.resolve)(pkg.root, '-embroider-entrypoint.js'))); | ||
} | ||
handleTestEntrypoint(request) { | ||
if (isTerminal(request)) { | ||
return request; | ||
} | ||
//TODO move the extra forwardslash handling out into the vite plugin | ||
const candidates = [ | ||
'@embroider/core/test-entrypoint', | ||
'/@embroider/core/test-entrypoint', | ||
'./@embroider/core/test-entrypoint', | ||
]; | ||
if (!candidates.some(c => request.specifier === c)) { | ||
return request; | ||
} | ||
const pkg = this.packageCache.ownerOfFile(request.fromFile); | ||
if (!(pkg === null || pkg === void 0 ? void 0 : pkg.isV2Ember()) || !pkg.isV2App()) { | ||
throw new Error(`bug: found test entrypoint import from somewhere other than the top-level app engine: ${request.fromFile}`); | ||
} | ||
return logTransition('test-entrypoint', request, request.virtualize((0, path_1.resolve)(pkg.root, '-embroider-test-entrypoint.js'))); | ||
} | ||
handleRouteEntrypoint(request) { | ||
if (isTerminal(request)) { | ||
return request; | ||
} | ||
let routeName = (0, virtual_route_entrypoint_1.decodePublicRouteEntrypoint)(request.specifier); | ||
if (!routeName) { | ||
return request; | ||
} | ||
let pkg = this.packageCache.ownerOfFile(request.fromFile); | ||
if (!(pkg === null || pkg === void 0 ? void 0 : pkg.isV2Ember())) { | ||
throw new Error(`bug: found entrypoint import in non-ember package at ${request.fromFile}`); | ||
} | ||
return logTransition('route entrypoint', request, request.virtualize((0, virtual_route_entrypoint_1.encodeRouteEntrypoint)(pkg.root, routeName))); | ||
} | ||
handleImplicitTestScripts(request) { | ||
//TODO move the extra forwardslash handling out into the vite plugin | ||
const candidates = [ | ||
'@embroider/core/test-support.js', | ||
'/@embroider/core/test-support.js', | ||
'./@embroider/core/test-support.js', | ||
]; | ||
if (!candidates.includes(request.specifier)) { | ||
return request; | ||
} | ||
let pkg = this.packageCache.ownerOfFile(request.fromFile); | ||
if ((pkg === null || pkg === void 0 ? void 0 : pkg.root) !== this.options.engines[0].root) { | ||
throw new Error(`bug: found an import of ${request.specifier} in ${request.fromFile}, but this is not the top-level Ember app. The top-level Ember app is the only one that has support for @embroider/core/test-support.js. If you think something should be fixed in Embroider, please open an issue on https://github.com/embroider-build/embroider/issues.`); | ||
} | ||
return logTransition('test-support', request, request.virtualize((0, path_1.resolve)(pkg.root, '-embroider-test-support.js'))); | ||
} | ||
handleTestSupportStyles(request) { | ||
//TODO move the extra forwardslash handling out into the vite plugin | ||
const candidates = [ | ||
'@embroider/core/test-support.css', | ||
'/@embroider/core/test-support.css', | ||
'./@embroider/core/test-support.css', | ||
]; | ||
if (!candidates.includes(request.specifier)) { | ||
return request; | ||
} | ||
let pkg = this.packageCache.ownerOfFile(request.fromFile); | ||
if ((pkg === null || pkg === void 0 ? void 0 : pkg.root) !== this.options.engines[0].root) { | ||
throw new Error(`bug: found an import of ${request.specifier} in ${request.fromFile}, but this is not the top-level Ember app. The top-level Ember app is the only one that has support for @embroider/core/test-support.css. If you think something should be fixed in Embroider, please open an issue on https://github.com/embroider-build/embroider/issues.`); | ||
} | ||
return logTransition('test-support-styles', request, request.virtualize((0, path_1.resolve)(pkg.root, '-embroider-test-support-styles.css'))); | ||
} | ||
async handleGlobalsCompat(request) { | ||
if (isTerminal(request)) { | ||
return request; | ||
} | ||
handleGlobalsCompat(request) { | ||
let match = compatPattern.exec(request.specifier); | ||
@@ -400,17 +336,5 @@ if (!match) { | ||
default: | ||
throw new Error(`bug: unexepected @embroider/virtual specifier: ${request.specifier}`); | ||
throw new Error(`bug: unexepected #embroider_compat specifier: ${request.specifier}`); | ||
} | ||
} | ||
handleVendorStyles(request) { | ||
//TODO move the extra forwardslash handling out into the vite plugin | ||
const candidates = ['@embroider/core/vendor.css', '/@embroider/core/vendor.css', './@embroider/core/vendor.css']; | ||
if (!candidates.includes(request.specifier)) { | ||
return request; | ||
} | ||
let pkg = this.packageCache.ownerOfFile(request.fromFile); | ||
if (!pkg || !this.options.engines.some(e => e.root === (pkg === null || pkg === void 0 ? void 0 : pkg.root))) { | ||
throw new Error(`bug: found an import of ${request.specifier} in ${request.fromFile}, but this is not the top-level Ember app or Engine. The top-level Ember app is the only one that has support for @embroider/core/vendor.css. If you think something should be fixed in Embroider, please open an issue on https://github.com/embroider-build/embroider/issues.`); | ||
} | ||
return logTransition('vendor-styles', request, request.virtualize((0, path_1.resolve)(pkg.root, '-embroider-vendor-styles.css'))); | ||
} | ||
resolveHelper(path, inEngine, request) { | ||
@@ -420,3 +344,3 @@ let target = this.parseGlobalPath(path, inEngine); | ||
} | ||
async resolveComponent(path, inEngine, request) { | ||
resolveComponent(path, inEngine, request) { | ||
let target = this.parseGlobalPath(path, inEngine); | ||
@@ -427,8 +351,5 @@ let hbsModule = null; | ||
for (let candidate of this.componentTemplateCandidates(target.packageName)) { | ||
let candidateSpecifier = `${target.packageName}${candidate.prefix}${target.memberName}${candidate.suffix}`; | ||
let resolution = await this.resolve(request.alias(candidateSpecifier).rehome(target.from).withMeta({ | ||
runtimeFallback: false, | ||
})); | ||
if (resolution.type === 'found') { | ||
hbsModule = resolution; | ||
let resolution = this.nodeResolve(`${target.packageName}${candidate.prefix}${target.memberName}${candidate.suffix}`, target.from); | ||
if (resolution.type === 'real') { | ||
hbsModule = resolution.filename; | ||
break; | ||
@@ -439,14 +360,8 @@ } | ||
for (let candidate of this.componentJSCandidates(target.packageName)) { | ||
let candidateSpecifier = `${target.packageName}${candidate.prefix}${target.memberName}${candidate.suffix}`; | ||
let resolution = await this.resolve(request.alias(candidateSpecifier).rehome(target.from).withMeta({ | ||
runtimeFallback: false, | ||
})); | ||
if (resolution.type === 'ignored') { | ||
return logTransition(`resolving to ignored component`, request, request.resolveTo(resolution)); | ||
} | ||
let resolution = this.nodeResolve(`${target.packageName}${candidate.prefix}${target.memberName}${candidate.suffix}`, target.from); | ||
// .hbs is a resolvable extension for us, so we need to exclude it here. | ||
// It matches as a priority lower than .js, so finding an .hbs means | ||
// there's definitely not a .js. | ||
if (resolution.type === 'found' && !resolution.filename.endsWith('.hbs')) { | ||
jsModule = resolution; | ||
if (resolution.type === 'real' && !resolution.filename.endsWith('.hbs')) { | ||
jsModule = resolution.filename; | ||
break; | ||
@@ -456,6 +371,6 @@ } | ||
if (hbsModule) { | ||
return logTransition(`resolveComponent found legacy HBS`, request, request.virtualize((0, virtual_content_1.virtualPairComponent)(hbsModule.filename, jsModule === null || jsModule === void 0 ? void 0 : jsModule.filename))); | ||
return logTransition(`resolveComponent found legacy HBS`, request, request.virtualize((0, virtual_content_1.virtualPairComponent)(hbsModule, jsModule))); | ||
} | ||
else if (jsModule) { | ||
return logTransition(`resolving to resolveComponent found only JS`, request, request.resolveTo(jsModule)); | ||
return logTransition(`resolveComponent found only JS`, request, request.alias(jsModule).rehome(target.from)); | ||
} | ||
@@ -466,3 +381,3 @@ else { | ||
} | ||
async resolveHelperOrComponent(path, inEngine, request) { | ||
resolveHelperOrComponent(path, inEngine, request) { | ||
// resolveHelper just rewrites our request to one that should target the | ||
@@ -472,10 +387,5 @@ // component, so here to resolve the ambiguity we need to actually resolve | ||
let helperCandidate = this.resolveHelper(path, inEngine, request); | ||
let helperMatch = await this.resolve(request.alias(helperCandidate.specifier).rehome(helperCandidate.fromFile).withMeta({ | ||
runtimeFallback: false, | ||
})); | ||
// for the case of 'ignored' that means that esbuild found this helper in an external | ||
// package so it should be considered found in this case and we should not look for a | ||
// component with this name | ||
if (helperMatch.type === 'found' || helperMatch.type === 'ignored') { | ||
return logTransition('resolve to ambiguous case matched a helper', request, request.resolveTo(helperMatch)); | ||
let helperMatch = this.nodeResolve(helperCandidate.specifier, helperCandidate.fromFile); | ||
if (helperMatch.type === 'real') { | ||
return logTransition('ambiguous case matched a helper', request, helperCandidate); | ||
} | ||
@@ -485,3 +395,3 @@ // unlike resolveHelper, resolveComponent already does pre-resolution in | ||
// colocation.≥ | ||
let componentMatch = await this.resolveComponent(path, inEngine, request); | ||
let componentMatch = this.resolveComponent(path, inEngine, request); | ||
if (componentMatch !== request) { | ||
@@ -511,3 +421,2 @@ return logTransition('ambiguous case matched a cmoponent', request, componentMatch); | ||
yield { prefix: '/components/', suffix: '' }; | ||
yield { prefix: '/components/', suffix: '/index' }; | ||
yield { prefix: '/components/', suffix: '/component' }; | ||
@@ -531,6 +440,6 @@ let pods = this.podPrefix(inPackageName); | ||
if (parts.length > 1 && parts[0].length > 0) { | ||
return { packageName: parts[0], memberName: parts[1], from: (0, path_1.resolve)(inEngine.root, 'package.json') }; | ||
return { packageName: parts[0], memberName: parts[1], from: (0, path_1.resolve)(inEngine.root, 'pacakge.json') }; | ||
} | ||
else { | ||
return { packageName: inEngine.packageName, memberName: path, from: (0, path_1.resolve)(inEngine.root, 'package.json') }; | ||
return { packageName: inEngine.packageName, memberName: path, from: (0, path_1.resolve)(inEngine.root, 'pacakge.json') }; | ||
} | ||
@@ -567,4 +476,4 @@ } | ||
'app-js': { | ||
specifier: (0, reverse_exports_1.default)(addon.packageJSON, inAddonName), | ||
fromFile: addonConfig.canResolveFromFile, | ||
localPath: inAddonName, | ||
packageRoot: addon.root, | ||
fromPackageName: addon.name, | ||
@@ -582,4 +491,4 @@ }, | ||
'app-js': { | ||
specifier: (0, reverse_exports_1.default)(addon.packageJSON, inAddonName), | ||
fromFile: addonConfig.canResolveFromFile, | ||
localPath: inAddonName, | ||
packageRoot: addon.root, | ||
fromPackageName: addon.name, | ||
@@ -608,4 +517,4 @@ }, | ||
'fastboot-js': { | ||
specifier: (0, reverse_exports_1.default)(addon.packageJSON, inAddonName), | ||
fromFile: addonConfig.canResolveFromFile, | ||
localPath: inAddonName, | ||
packageRoot: addon.root, | ||
fromPackageName: addon.name, | ||
@@ -623,4 +532,4 @@ }, | ||
'fastboot-js': { | ||
specifier: (0, reverse_exports_1.default)(addon.packageJSON, inAddonName), | ||
fromFile: addonConfig.canResolveFromFile, | ||
localPath: inAddonName, | ||
packageRoot: addon.root, | ||
fromPackageName: addon.name, | ||
@@ -647,3 +556,3 @@ }, | ||
handleRewrittenPackages(request) { | ||
if (isTerminal(request)) { | ||
if (request.isVirtual) { | ||
return request; | ||
@@ -667,2 +576,6 @@ } | ||
catch (err) { | ||
// this is not the place to report resolution failures. If the thing | ||
// doesn't resolve, we're just not interested in redirecting it for | ||
// backward-compat, that's all. The rest of the system will take care of | ||
// reporting a failure to resolve (or handling it a different way) | ||
if (err.code !== 'MODULE_NOT_FOUND') { | ||
@@ -683,17 +596,5 @@ throw err; | ||
else if (originalRequestingPkg !== requestingPkg) { | ||
if (targetPkg) { | ||
// in this case, the requesting package is moved but its destination is | ||
// not, so we need to rehome the request back to the original location. | ||
return logTransition('outbound request from moved package', request, request | ||
// setting meta here because if this fails, we want the fallback | ||
// logic to revert our rehome and continue from the *moved* package. | ||
.withMeta({ originalFromFile: request.fromFile }) | ||
.rehome((0, path_1.resolve)(originalRequestingPkg.root, 'package.json'))); | ||
} | ||
else { | ||
// requesting package was moved and we failed to find its target. We | ||
// can't let that accidentally succeed in the defaultResolve because we | ||
// could escape the moved package system. | ||
return logTransition('missing outbound request from moved package', request, request.notFound()); | ||
} | ||
// in this case, the requesting package is moved but its destination is | ||
// not, so we need to rehome the request back to the original location. | ||
return logTransition('outbound request from moved package', request, request.withMeta({ wasMovedTo: request.fromFile }).rehome((0, path_1.resolve)(originalRequestingPkg.root, 'package.json'))); | ||
} | ||
@@ -703,3 +604,3 @@ return request; | ||
handleRenaming(request) { | ||
if (isTerminal(request)) { | ||
if (request.isVirtual) { | ||
return request; | ||
@@ -737,52 +638,11 @@ } | ||
} | ||
if (pkg.name === packageName) { | ||
// we found a self-import | ||
if (pkg.meta['auto-upgraded']) { | ||
// auto-upgraded packages always get automatically adjusted. They never | ||
// supported fancy package.json exports features so this direct mapping | ||
// to the root is always right. | ||
// "my-app/foo" -> "./foo" from app's package.json | ||
// "my-addon/foo" -> "my-addon/foo" from a package that's guaranteed to be able to resolve my-addon | ||
let owningEngine = this.owningEngine(pkg); | ||
let addonConfig = owningEngine.activeAddons.find(a => a.root === pkg.root); | ||
if (addonConfig) { | ||
return logTransition(`v1 addon self-import`, request, request.rehome(addonConfig.canResolveFromFile)); | ||
} | ||
else { | ||
let selfImportPath = request.specifier === pkg.name ? './' : request.specifier.replace(pkg.name, '.'); | ||
return logTransition(`v1 app self-import`, request, request.alias(selfImportPath).rehome((0, path_1.resolve)(pkg.root, 'package.json'))); | ||
} | ||
} | ||
else { | ||
// v2 packages are supposed to use package.json `exports` to enable | ||
// self-imports, but not all build tools actually follow the spec. This | ||
// is a workaround for badly behaved packagers. | ||
// | ||
// Known upstream bugs this works around: | ||
// - https://github.com/vitejs/vite/issues/9731 | ||
if (pkg.packageJSON.exports) { | ||
let found = (0, resolve_exports_1.exports)(pkg.packageJSON, request.specifier, { | ||
browser: true, | ||
conditions: ['default', 'imports'], | ||
}); | ||
if (found === null || found === void 0 ? void 0 : found[0]) { | ||
return logTransition(`v2 self-import with package.json exports`, request, request.alias(found === null || found === void 0 ? void 0 : found[0]).rehome((0, path_1.resolve)(pkg.root, 'package.json'))); | ||
} | ||
} | ||
} | ||
if (pkg.meta['auto-upgraded'] && pkg.name === packageName) { | ||
// we found a self-import, resolve it for them. Only auto-upgraded | ||
// packages get this help, v2 packages are natively supposed to make their | ||
// own modules resolvable, and we want to push them all to do that | ||
// correctly. | ||
return logTransition(`v1 self-import`, request, request.alias(request.specifier.replace(pkg.name, '.')).rehome((0, path_1.resolve)(pkg.root, 'package.json'))); | ||
} | ||
return request; | ||
} | ||
handleVendor(request) { | ||
//TODO move the extra forwardslash handling out into the vite plugin | ||
const candidates = ['@embroider/core/vendor.js', '/@embroider/core/vendor.js', './@embroider/core/vendor.js']; | ||
if (!candidates.includes(request.specifier)) { | ||
return request; | ||
} | ||
let pkg = this.packageCache.ownerOfFile(request.fromFile); | ||
if ((pkg === null || pkg === void 0 ? void 0 : pkg.root) !== this.options.engines[0].root) { | ||
throw new Error(`bug: found an import of ${request.specifier} in ${request.fromFile}, but this is not the top-level Ember app. The top-level Ember app is the only one that has support for @embroider/core/vendor.js. If you think something should be fixed in Embroider, please open an issue on https://github.com/embroider-build/embroider/issues.`); | ||
} | ||
return logTransition('vendor', request, request.virtualize((0, path_1.resolve)(pkg.root, '-embroider-vendor.js'))); | ||
} | ||
resolveWithinMovedPackage(request, pkg) { | ||
@@ -793,3 +653,2 @@ let levels = ['..']; | ||
} | ||
let originalFromFile = request.fromFile; | ||
let newRequest = request.rehome((0, path_1.resolve)(pkg.root, ...levels, 'moved-package-target.js')); | ||
@@ -799,8 +658,8 @@ if (newRequest === request) { | ||
} | ||
// setting meta because if this fails, we want the fallback to pick up back | ||
// in the original requesting package. | ||
return newRequest.withMeta({ originalFromFile }); | ||
return newRequest.withMeta({ | ||
resolvedWithinPackage: pkg.root, | ||
}); | ||
} | ||
preHandleExternal(request) { | ||
if (isTerminal(request)) { | ||
if (request.isVirtual) { | ||
return request; | ||
@@ -838,11 +697,3 @@ } | ||
if (logicalLocation) { | ||
return logTransition('beforeResolve: relative import in app-js', request, request | ||
.alias('./' + path_1.posix.join((0, path_1.dirname)(logicalLocation.inAppName), request.specifier)) | ||
// it's important that we're rehoming this to the root of the engine | ||
// (which we know really exists), and not to a subdir like | ||
// logicalLocation.inAppName (which might not physically exist), | ||
// because some environments (including node's require.resolve) will | ||
// refuse to do resolution from a notional path that doesn't | ||
// physically exist. | ||
.rehome((0, path_1.resolve)(logicalLocation.owningEngine.root, 'package.json'))); | ||
return logTransition('beforeResolve: relative import in app-js', request, request.rehome((0, path_1.resolve)(logicalLocation.owningEngine.root, logicalLocation.inAppName))); | ||
} | ||
@@ -862,7 +713,7 @@ return request; | ||
// emberVirtualPeerDeps, like "@glimmer/component" etc. | ||
let addon = this.locateActiveAddon(packageName); | ||
if (!addon) { | ||
throw new Error(`${pkg.name} is trying to import the emberVirtualPeerDep "${packageName}", but it seems to be missing`); | ||
if (!this.options.activeAddons[packageName]) { | ||
throw new Error(`${pkg.name} is trying to import the app's ${packageName} package, but it seems to be missing`); | ||
} | ||
return logTransition(`emberVirtualPeerDeps`, request, request.rehome(addon.canResolveFromFile)); | ||
let newHome = (0, path_1.resolve)(this.packageCache.maybeMoved(this.packageCache.get(this.options.appRoot)).root, 'package.json'); | ||
return logTransition(`emberVirtualPeerDeps in v2 addon`, request, request.rehome(newHome)); | ||
} | ||
@@ -876,3 +727,3 @@ // if this file is part of an addon's app-js, it's really the logical | ||
let dep = this.packageCache.resolve(packageName, logicalPackage); | ||
if (!dep.isEmberAddon()) { | ||
if (!dep.isEmberPackage()) { | ||
// classic ember addons can only import non-ember dependencies if they | ||
@@ -890,25 +741,11 @@ // have ember-auto-import. | ||
// assertions on what native v2 addons can import | ||
if (!pkg.needsLooseResolving() && | ||
!appImportInAppTree(pkg, logicalPackage, packageName) && | ||
!reliablyResolvable(pkg, packageName)) { | ||
throw new Error(`${pkg.name} is trying to import from ${packageName} but that is not one of its explicit dependencies`); | ||
if (!pkg.meta['auto-upgraded']) { | ||
if (!pkg.meta['auto-upgraded'] && | ||
!appImportInAppTree(pkg, logicalPackage, packageName) && | ||
!reliablyResolvable(pkg, packageName)) { | ||
throw new Error(`${pkg.name} is trying to import from ${packageName} but that is not one of its explicit dependencies`); | ||
} | ||
} | ||
return request; | ||
} | ||
locateActiveAddon(packageName) { | ||
if (packageName === this.options.modulePrefix) { | ||
// the app itself is something that addon's can classically resolve if they know it's name. | ||
return { | ||
root: this.options.appRoot, | ||
canResolveFromFile: (0, path_1.resolve)(this.packageCache.maybeMoved(this.packageCache.get(this.options.appRoot)).root, 'package.json'), | ||
}; | ||
} | ||
for (let engine of this.options.engines) { | ||
for (let addon of engine.activeAddons) { | ||
if (addon.name === packageName) { | ||
return addon; | ||
} | ||
} | ||
} | ||
} | ||
external(label, request, specifier) { | ||
@@ -925,3 +762,3 @@ if (this.options.amdCompatibility === 'cjs') { | ||
if (!entry) { | ||
throw new Error(`[${request.debugType}] A module tried to resolve "${request.specifier}" and didn't find it (${label}). | ||
throw new Error(`A module tried to resolve "${request.specifier}" and didn't find it (${label}). | ||
@@ -947,7 +784,4 @@ - Maybe a dependency declaration is missing? | ||
} | ||
async fallbackResolve(request) { | ||
fallbackResolve(request) { | ||
var _a, _b, _c; | ||
if (request.isVirtual) { | ||
throw new Error('Build tool bug detected! Fallback resolve should never see a virtual request. It is expected that the defaultResolve for your bundler has already resolved this request'); | ||
} | ||
if (request.specifier === '@embroider/macros') { | ||
@@ -960,5 +794,6 @@ // the macros package is always handled directly within babel (not | ||
} | ||
if (compatPattern.test(request.specifier)) { | ||
let { specifier, fromFile } = request; | ||
if (compatPattern.test(specifier)) { | ||
// Some kinds of compat requests get rewritten into other things | ||
// deterministically. For example, "@embroider/virtual/helpers/whatever" | ||
// deterministically. For example, "#embroider_compat/helpers/whatever" | ||
// means only "the-current-engine/helpers/whatever", and if that doesn't | ||
@@ -968,5 +803,5 @@ // actually exist it's that path that will show up as a missing import. | ||
// But others have an ambiguous meaning. For example, | ||
// @embroider/virtual/components/whatever can mean several different | ||
// #embroider_compat/components/whatever can mean several different | ||
// things. If we're unable to find any of them, the actual | ||
// "@embroider/virtual" request will fall through all the way to here. | ||
// "#embroider_compat" request will fall through all the way to here. | ||
// | ||
@@ -978,16 +813,22 @@ // In that case, we don't want to externalize that failure. We know it's | ||
} | ||
let pkg = this.packageCache.ownerOfFile(request.fromFile); | ||
if (fromFile.endsWith('moved-package-target.js')) { | ||
if (!((_a = request.meta) === null || _a === void 0 ? void 0 : _a.resolvedWithinPackage)) { | ||
throw new Error(`bug: embroider resolver's meta is not propagating`); | ||
} | ||
fromFile = (0, path_1.resolve)((_b = request.meta) === null || _b === void 0 ? void 0 : _b.resolvedWithinPackage, 'package.json'); | ||
} | ||
let pkg = this.packageCache.ownerOfFile(fromFile); | ||
if (!pkg) { | ||
return logTransition('no identifiable owningPackage', request); | ||
} | ||
// meta.originalFromFile gets set when we want to try to rehome a request | ||
// but then come back to the original location here in the fallback when the | ||
// rehomed request fails | ||
// if we rehomed this request to its un-rewritten location in order to try | ||
// to do the defaultResolve from there, now we refer back to the rewritten | ||
// location because that's what we want to use when asking things like | ||
// isV2Ember() | ||
let movedPkg = this.packageCache.maybeMoved(pkg); | ||
if (movedPkg !== pkg) { | ||
let originalFromFile = (_a = request.meta) === null || _a === void 0 ? void 0 : _a.originalFromFile; | ||
if (typeof originalFromFile !== 'string') { | ||
if (!((_c = request.meta) === null || _c === void 0 ? void 0 : _c.wasMovedTo)) { | ||
throw new Error(`bug: embroider resolver's meta is not propagating`); | ||
} | ||
request = request.rehome(originalFromFile); | ||
fromFile = request.meta.wasMovedTo; | ||
pkg = movedPkg; | ||
@@ -998,3 +839,3 @@ } | ||
} | ||
let packageName = (0, shared_internals_1.packageName)(request.specifier); | ||
let packageName = (0, shared_internals_1.packageName)(specifier); | ||
if (!packageName) { | ||
@@ -1006,3 +847,3 @@ // this is a relative import | ||
// means we may need to satisfy the request via app tree merging. | ||
let appJSMatch = await this.searchAppTree(request, withinEngine, (0, shared_internals_2.explicitRelative)(pkg.root, (0, path_1.resolve)((0, path_1.dirname)(request.fromFile), request.specifier))); | ||
let appJSMatch = this.searchAppTree(request, withinEngine, (0, shared_internals_2.explicitRelative)(pkg.root, (0, path_1.resolve)((0, path_1.dirname)(fromFile), specifier))); | ||
if (appJSMatch) { | ||
@@ -1021,12 +862,9 @@ return logTransition('fallbackResolve: relative appJsMatch', request, appJSMatch); | ||
// auto-upgraded packages can fall back to the set of known active addons | ||
if (pkg.needsLooseResolving()) { | ||
let addon = this.locateActiveAddon(packageName); | ||
if (addon) { | ||
const rehomed = request.rehome(addon.canResolveFromFile); | ||
if (rehomed !== request) { | ||
return logTransition(`activeAddons`, request, rehomed); | ||
} | ||
if (pkg.meta['auto-upgraded'] && this.options.activeAddons[packageName]) { | ||
const rehomed = this.resolveWithinMovedPackage(request, this.packageCache.get(this.options.activeAddons[packageName])); | ||
if (rehomed !== request) { | ||
return logTransition(`activeAddons`, request, rehomed); | ||
} | ||
} | ||
let logicalLocation = this.reverseSearchAppTree(pkg, request.fromFile); | ||
let logicalLocation = this.reverseSearchAppTree(pkg, fromFile); | ||
if (logicalLocation) { | ||
@@ -1037,13 +875,7 @@ // the requesting file is in an addon's appTree. We didn't succeed in | ||
// app. | ||
return logTransition('fallbackResolve: retry from logical home of app-js file', request, | ||
// it might look more precise to rehome into logicalLocation.inAppName | ||
// rather than package.json. But that logical location may not actually | ||
// exist, and some systems (including node's require.resolve) will be | ||
// mad about trying to resolve from notional paths that don't really | ||
// exist. | ||
request.rehome((0, path_1.resolve)(logicalLocation.owningEngine.root, 'package.json'))); | ||
return logTransition('fallbackResolve: retry from logical home of app-js file', request, request.rehome((0, path_1.resolve)(logicalLocation.owningEngine.root, logicalLocation.inAppName))); | ||
} | ||
let targetingEngine = this.engineConfig(packageName); | ||
if (targetingEngine) { | ||
let appJSMatch = await this.searchAppTree(request, targetingEngine, request.specifier.replace(packageName, '.')); | ||
let appJSMatch = this.searchAppTree(request, targetingEngine, specifier.replace(packageName, '.')); | ||
if (appJSMatch) { | ||
@@ -1053,3 +885,3 @@ return logTransition('fallbackResolve: non-relative appJsMatch', request, appJSMatch); | ||
} | ||
if (pkg.needsLooseResolving() && ((_c = (_b = request.meta) === null || _b === void 0 ? void 0 : _b.runtimeFallback) !== null && _c !== void 0 ? _c : true)) { | ||
if (pkg.meta['auto-upgraded']) { | ||
// auto-upgraded packages can fall back to attempting to find dependencies at | ||
@@ -1059,3 +891,3 @@ // runtime. Native v2 packages can only get this behavior in the | ||
// externals. | ||
return this.external('v1 catch-all fallback', request, request.specifier); | ||
return this.external('v1 catch-all fallback', request, specifier); | ||
} | ||
@@ -1067,3 +899,3 @@ else { | ||
if (shared_internals_1.emberVirtualPackages.has(packageName)) { | ||
return this.external('emberVirtualPackages', request, request.specifier); | ||
return this.external('emberVirtualPackages', request, specifier); | ||
} | ||
@@ -1095,3 +927,3 @@ } | ||
} | ||
async searchAppTree(request, engine, inEngineSpecifier) { | ||
searchAppTree(request, engine, inEngineSpecifier) { | ||
let matched = this.getEntryFromMergeMap(inEngineSpecifier, engine.root); | ||
@@ -1102,13 +934,15 @@ switch (matched === null || matched === void 0 ? void 0 : matched.entry.type) { | ||
case 'app-only': | ||
return request.alias(matched.entry['app-js'].specifier).rehome(matched.entry['app-js'].fromFile); | ||
return request | ||
.alias(matched.entry['app-js'].localPath) | ||
.rehome((0, path_1.resolve)(matched.entry['app-js'].packageRoot, 'package.json')); | ||
case 'fastboot-only': | ||
return request.alias(matched.entry['fastboot-js'].specifier).rehome(matched.entry['fastboot-js'].fromFile); | ||
return request | ||
.alias(matched.entry['fastboot-js'].localPath) | ||
.rehome((0, path_1.resolve)(matched.entry['fastboot-js'].packageRoot, 'package.json')); | ||
case 'both': | ||
let foundAppJS = await this.resolve(request.alias(matched.entry['app-js'].specifier).rehome(matched.entry['app-js'].fromFile).withMeta({ | ||
runtimeFallback: false, | ||
})); | ||
if (foundAppJS.type !== 'found') { | ||
let foundAppJS = this.nodeResolve(matched.entry['app-js'].localPath, (0, path_1.resolve)(matched.entry['app-js'].packageRoot, 'package.json')); | ||
if (foundAppJS.type !== 'real') { | ||
throw new Error(`${matched.entry['app-js'].fromPackageName} declared ${inEngineSpecifier} in packageJSON.ember-addon.app-js, but that module does not exist`); | ||
} | ||
let { names } = (0, describe_exports_1.describeExports)((0, fs_1.readFileSync)(foundAppJS.filename, 'utf8'), { configFile: false }); | ||
let { names } = (0, describe_exports_1.describeExports)((0, fs_1.readFileSync)(foundAppJS.filename, 'utf8'), {}); | ||
return request.virtualize((0, virtual_content_1.fastbootSwitch)(matched.matched, (0, path_1.resolve)(engine.root, 'package.json'), names)); | ||
@@ -1115,0 +949,0 @@ } |
import type { Resolver } from '.'; | ||
export interface VirtualContentResult { | ||
src: string; | ||
watches: string[]; | ||
} | ||
export declare function virtualContent(filename: string, resolver: Resolver): VirtualContentResult; | ||
export declare function virtualContent(filename: string, resolver: Resolver): string; | ||
export declare function virtualExternalESModule(specifier: string, exports: string[] | undefined): string; | ||
export declare function virtualExternalCJSModule(specifier: string): string; | ||
export declare function virtualPairComponent(hbsModule: string, jsModule: string | undefined): string; | ||
export declare function virtualPairComponent(hbsModule: string, jsModule: string | null): string; | ||
export declare function fastbootSwitch(specifier: string, fromFile: string, names: Set<string>): string; | ||
@@ -11,0 +7,0 @@ export declare function decodeFastbootSwitch(filename: string): { |
@@ -13,9 +13,2 @@ "use strict"; | ||
const js_handlebars_1 = require("./js-handlebars"); | ||
const virtual_test_support_1 = require("./virtual-test-support"); | ||
const virtual_test_support_styles_1 = require("./virtual-test-support-styles"); | ||
const virtual_vendor_1 = require("./virtual-vendor"); | ||
const virtual_vendor_styles_1 = require("./virtual-vendor-styles"); | ||
const virtual_entrypoint_1 = require("./virtual-entrypoint"); | ||
const virtual_test_entrypoint_1 = require("./virtual-test-entrypoint"); | ||
const virtual_route_entrypoint_1 = require("./virtual-route-entrypoint"); | ||
const externalESPrefix = '/@embroider/ext-es/'; | ||
@@ -32,14 +25,2 @@ const externalCJSPrefix = '/@embroider/ext-cjs/'; | ||
} | ||
let entrypoint = (0, virtual_entrypoint_1.decodeEntrypoint)(filename); | ||
if (entrypoint) { | ||
return (0, virtual_entrypoint_1.renderEntrypoint)(resolver, entrypoint); | ||
} | ||
let testEntrypoint = (0, virtual_test_entrypoint_1.decodeTestEntrypoint)(filename); | ||
if (testEntrypoint) { | ||
return (0, virtual_test_entrypoint_1.renderTestEntrypoint)(resolver, testEntrypoint); | ||
} | ||
let routeEntrypoint = (0, virtual_route_entrypoint_1.decodeRouteEntrypoint)(filename); | ||
if (routeEntrypoint) { | ||
return (0, virtual_route_entrypoint_1.renderRouteEntrypoint)(resolver, routeEntrypoint); | ||
} | ||
let extern = decodeVirtualExternalESModule(filename); | ||
@@ -55,3 +36,3 @@ if (extern) { | ||
if (fb) { | ||
return renderFastbootSwitchTemplate(fb); | ||
return fastbootSwitchTemplate(fb); | ||
} | ||
@@ -62,18 +43,2 @@ let im = decodeImplicitModules(filename); | ||
} | ||
let isVendor = (0, virtual_vendor_1.decodeVirtualVendor)(filename); | ||
if (isVendor) { | ||
return (0, virtual_vendor_1.renderVendor)(filename, resolver); | ||
} | ||
let isImplicitTestScripts = (0, virtual_test_support_1.decodeImplicitTestScripts)(filename); | ||
if (isImplicitTestScripts) { | ||
return (0, virtual_test_support_1.renderImplicitTestScripts)(filename, resolver); | ||
} | ||
let isVendorStyles = (0, virtual_vendor_styles_1.decodeVirtualVendorStyles)(filename); | ||
if (isVendorStyles) { | ||
return (0, virtual_vendor_styles_1.renderVendorStyles)(filename, resolver); | ||
} | ||
let isTestSupportStyles = (0, virtual_test_support_styles_1.decodeTestSupportStyles)(filename); | ||
if (isTestSupportStyles) { | ||
return (0, virtual_test_support_styles_1.renderTestSupportStyles)(filename, resolver); | ||
} | ||
throw new Error(`not an @embroider/core virtual file: ${filename}`); | ||
@@ -98,19 +63,10 @@ } | ||
`); | ||
function renderESExternalShim({ moduleName, exports, }) { | ||
return { | ||
src: externalESShim({ | ||
moduleName, | ||
default: exports.includes('default'), | ||
names: exports.filter(n => n !== 'default'), | ||
}), | ||
watches: [], | ||
}; | ||
function renderESExternalShim({ moduleName, exports }) { | ||
return externalESShim({ | ||
moduleName, | ||
default: exports.includes('default'), | ||
names: exports.filter(n => n !== 'default'), | ||
}); | ||
} | ||
function pairedComponentShim(params) { | ||
return { | ||
src: pairedComponentShimTemplate(params), | ||
watches: [], | ||
}; | ||
} | ||
const pairedComponentShimTemplate = (0, js_handlebars_1.compile)(` | ||
const pairedComponentShim = (0, js_handlebars_1.compile)(` | ||
import { setComponentTemplate } from "@ember/component"; | ||
@@ -128,3 +84,3 @@ import template from "{{{js-string-escape relativeHBSModule}}}"; | ||
if (exports) { | ||
return externalESPrefix + specifier + `/exports=${exports.join(',')}`; | ||
return externalESPrefix + specifier + `?exports=${exports.join(',')}`; | ||
} | ||
@@ -141,8 +97,8 @@ else { | ||
let exports = []; | ||
let components = filename.split('/exports='); | ||
let nameString = components[1]; | ||
let url = new URL(filename.slice(externalESPrefix.length), 'http://example.com'); | ||
let nameString = url.searchParams.get('exports'); | ||
if (nameString) { | ||
exports = nameString.split(','); | ||
} | ||
let moduleName = components[0].slice(externalESPrefix.length); | ||
let moduleName = url.pathname.slice(1); | ||
return { moduleName, exports }; | ||
@@ -210,8 +166,2 @@ } | ||
} | ||
function renderFastbootSwitchTemplate(params) { | ||
return { | ||
src: fastbootSwitchTemplate(params), | ||
watches: [], | ||
}; | ||
} | ||
const fastbootSwitchTemplate = (0, js_handlebars_1.compile)(` | ||
@@ -252,4 +202,4 @@ import { macroCondition, getGlobalConfig, importSync } from '@embroider/macros'; | ||
} | ||
let ownModules = []; | ||
let dependencyModules = []; | ||
let lazyModules = []; | ||
let eagerModules = []; | ||
let deps = pkg.dependencies.sort(orderAddons); | ||
@@ -287,3 +237,3 @@ for (let dep of deps) { | ||
runtime = runtime.split(path_1.sep).join('/'); | ||
ownModules.push({ | ||
lazyModules.push({ | ||
runtime, | ||
@@ -297,28 +247,16 @@ buildtime: path_1.posix.join(packageName, name), | ||
if (!dep.isEngine()) { | ||
dependencyModules.push(path_1.posix.join(dep.name, `-embroider-${type}.js`)); | ||
eagerModules.push(path_1.posix.join(dep.name, `-embroider-${type}.js`)); | ||
} | ||
} | ||
return { src: implicitModulesTemplate({ ownModules, dependencyModules }), watches: [] }; | ||
return implicitModulesTemplate({ lazyModules, eagerModules }); | ||
} | ||
const implicitModulesTemplate = (0, js_handlebars_1.compile)(` | ||
{{#each dependencyModules as |module index|}} | ||
import dep{{index}} from "{{js-string-escape module}}"; | ||
import { importSync as i } from '@embroider/macros'; | ||
let d = window.define; | ||
{{#each lazyModules as |module|}} | ||
d("{{js-string-escape module.runtime}}", function(){ return i("{{js-string-escape module.buildtime}}");}); | ||
{{/each}} | ||
{{#each ownModules as |module index|}} | ||
import * as own{{index}} from "{{js-string-escape module.buildtime}}"; | ||
{{#each eagerModules as |module|}} | ||
import "{{js-string-escape module}}"; | ||
{{/each}} | ||
export default Object.assign({}, | ||
{{#each dependencyModules as |module index|}} | ||
dep{{index}}, | ||
{{/each}} | ||
{ | ||
{{#each ownModules as |module index|}} | ||
"{{js-string-escape module.runtime}}": own{{index}}, | ||
{{/each}} | ||
} | ||
); | ||
`); | ||
@@ -349,39 +287,24 @@ // meta['renamed-modules'] has mapping from classic filename to real filename. | ||
} | ||
function renderCJSExternalShim(params) { | ||
return { | ||
src: renderCJSExternalShimTemplate(params), | ||
watches: [], | ||
}; | ||
} | ||
const renderCJSExternalShimTemplate = (0, js_handlebars_1.compile)(` | ||
module.exports = new Proxy({}, { | ||
get(target, prop) { | ||
const renderCJSExternalShim = (0, js_handlebars_1.compile)(` | ||
{{#if (eq moduleName "require")}} | ||
const m = window.requirejs; | ||
{{else}} | ||
const m = window.require("{{{js-string-escape moduleName}}}"); | ||
{{/if}} | ||
{{!- | ||
There are plenty of hand-written AMD defines floating around | ||
that lack this, and they will break when other build systems | ||
encounter them. | ||
{{!- our proxy always presents as ES module so that we can intercept "get('default')" -}} | ||
if (prop === '__esModule') { | ||
return true; | ||
} | ||
As far as I can tell, Ember's loader was already treating this | ||
case as a module, so in theory we aren't breaking anything by | ||
marking it as such when other packagers come looking. | ||
{{#if (eq moduleName "require")}} | ||
const m = window.requirejs; | ||
{{else}} | ||
const m = window.require("{{{js-string-escape moduleName}}}"); | ||
{{/if}} | ||
{{!- | ||
There are plenty of hand-written AMD defines floating around | ||
that lack an __esModule declaration. | ||
As far as I can tell, Ember's loader was already treating the Boolean(m.default)===true | ||
case as a module, so in theory we aren't breaking anything by | ||
treating it as such when other packagers come looking. | ||
-}} | ||
if (prop === 'default' && !m.__esModule && !m.default) { | ||
return m; | ||
} | ||
return m[prop]; | ||
} | ||
}); | ||
todo: get review on this part. | ||
-}} | ||
if (m.default && !m.__esModule) { | ||
m.__esModule = true; | ||
} | ||
module.exports = m; | ||
`); | ||
//# sourceMappingURL=virtual-content.js.map |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
24
1
12
17
23
163
362092
65
3191
+ Added@embroider/macros@1.16.6(transitive)
+ Added@embroider/shared-internals@2.6.3(transitive)
+ Addedis-core-module@2.16.0(transitive)
+ Addedjson-stable-stringify@1.2.0(transitive)
- Removedescape-string-regexp@^4.0.0
- Removedresolve.exports@^2.0.2
- Removed@embroider/macros@1.16.6-unstable.e9544fc(transitive)
- Removed@embroider/reverse-exports@0.1.1-unstable.e9544fc(transitive)
- Removed@embroider/shared-internals@2.6.3-unstable.e9544fc(transitive)
- Removedescape-string-regexp@4.0.0(transitive)
- Removedis-core-module@2.16.1(transitive)
- Removedjson-stable-stringify@1.2.1(transitive)
- Removedresolve.exports@2.0.3(transitive)
Updated@embroider/macros@1.16.6