diff --git a/packages/core/src/index.ts b/packages/core/src/index.ts index ef8d1c435..9ddfd3707 100644 --- a/packages/core/src/index.ts +++ b/packages/core/src/index.ts @@ -12,7 +12,8 @@ export { default as Options, optionsWithDefaults } from './options'; export { default as WaitForTrees, OutputPaths } from './wait-for-trees'; export { compile as jsHandlebarsCompile } from './js-handlebars'; export { todo, unsupported, warn, debug, expectWarning, throwOnWarnings } from './messages'; -export { Resolver, ModuleRequest, Resolution } from './module-resolver'; +export { Resolver } from './module-resolver'; +export type { ModuleRequest, Resolution } from './module-request'; export type { Options as ResolverOptions } from './module-resolver-options'; export { ResolverLoader } from './resolver-loader'; export { virtualContent } from './virtual-content'; diff --git a/packages/core/src/module-request.ts b/packages/core/src/module-request.ts new file mode 100644 index 000000000..a40192355 --- /dev/null +++ b/packages/core/src/module-request.ts @@ -0,0 +1,33 @@ +// This is generic because different build systems have different ways of +// representing a found module, and we just pass those values through. +export type Resolution = + | { type: 'found'; filename: string; isVirtual: boolean; result: T } + + // used for requests that are special and don't represent real files that + // embroider can possibly do anything custom with. + // + // the motivating use case for introducing this is Vite's depscan which marks + // almost everything as "external" as a way to tell esbuild to stop traversing + // once it has been seen the first time. + | { type: 'ignored'; result: T } + + // the important thing about this Resolution is that embroider should do its + // fallback behaviors here. + | { type: 'not_found'; err: E }; + +export interface ModuleRequest { + readonly specifier: string; + readonly fromFile: string; + readonly isVirtual: boolean; + readonly meta: Record | undefined; + readonly debugType: string; + readonly isNotFound: boolean; + readonly resolvedTo: Res | undefined; + alias(newSpecifier: string): this; + rehome(newFromFile: string): this; + virtualize(virtualFilename: string): this; + withMeta(meta: Record | undefined): this; + notFound(): this; + defaultResolve(): Promise; + resolveTo(resolution: Res): this; +} diff --git a/packages/core/src/module-resolver.ts b/packages/core/src/module-resolver.ts index 534c1e19a..6845a3e49 100644 --- a/packages/core/src/module-resolver.ts +++ b/packages/core/src/module-resolver.ts @@ -21,6 +21,7 @@ import { nodeResolve } from './node-resolve'; import { decodePublicRouteEntrypoint, encodeRouteEntrypoint } from './virtual-route-entrypoint'; import type { Options, EngineConfig } from './module-resolver-options'; import { satisfies } from 'semver'; +import type { ModuleRequest, Resolution } from './module-request'; const debug = makeDebug('embroider:resolver'); @@ -110,40 +111,6 @@ type MergeMap = Map[^\/]+)\/(?.*)/; -export interface ModuleRequest { - readonly specifier: string; - readonly fromFile: string; - readonly isVirtual: boolean; - readonly meta: Record | undefined; - readonly debugType: string; - readonly isNotFound: boolean; - readonly resolvedTo: Res | undefined; - alias(newSpecifier: string): this; - rehome(newFromFile: string): this; - virtualize(virtualFilename: string): this; - withMeta(meta: Record | undefined): this; - notFound(): this; - defaultResolve(): Promise; - resolveTo(resolution: Res): this; -} - -// This is generic because different build systems have different ways of -// representing a found module, and we just pass those values through. -export type Resolution = - | { type: 'found'; filename: string; isVirtual: boolean; result: T } - - // used for requests that are special and don't represent real files that - // embroider can possibly do anything custom with. - // - // the motivating use case for introducing this is Vite's depscan which marks - // almost everything as "external" as a way to tell esbuild to stop traversing - // once it has been seen the first time. - | { type: 'ignored'; result: T } - - // the important thing about this Resolution is that embroider should do its - // fallback behaviors here. - | { type: 'not_found'; err: E }; - export class Resolver { constructor(readonly options: Options) {} diff --git a/packages/core/src/node-resolve.ts b/packages/core/src/node-resolve.ts index 8d6590cf0..427828942 100644 --- a/packages/core/src/node-resolve.ts +++ b/packages/core/src/node-resolve.ts @@ -4,7 +4,8 @@ import { explicitRelative } from '@embroider/shared-internals'; import assertNever from 'assert-never'; // these would be circular, but they're type-only so it's fine -import type { ModuleRequest, Resolution, Resolver } from './module-resolver'; +import type { ModuleRequest, Resolution } from './module-request'; +import type { Resolver } from './module-resolver'; export class NodeModuleRequest implements ModuleRequest { constructor(