Skip to content

Commit

Permalink
fix(turbopack): add no-op resolveAbsolutePath to browser runtime
Browse files Browse the repository at this point in the history
  • Loading branch information
ForsakenHarmony committed Jun 20, 2024
1 parent 3bca6e8 commit 1a084c1
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,7 @@ function instantiateModule(id: ModuleId, source: SourceInfo): Module {
w: loadWebAssembly.bind(null, sourceInfo),
u: loadWebAssemblyModule.bind(null, sourceInfo),
g: globalThis,
P: resolveAbsolutePath,
U: relativeURL,
k: refresh,
R: createResolvePathFromModule(r),
Expand All @@ -386,6 +387,17 @@ function instantiateModule(id: ModuleId, source: SourceInfo): Module {
return module;
}

/**
* no-op for browser
* @param modulePath
*/
function resolveAbsolutePath(modulePath?: string): string {
if (modulePath) {
return modulePath;
}
return "/ROOT/";
}

/**
* NOTE(alexkirsz) Webpack has a "module execution" interception hook that
* Next.js' React Refresh runtime hooks into to add module context to the
Expand Down
2 changes: 0 additions & 2 deletions crates/turbopack-ecmascript-runtime/js/src/nodejs/runtime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,8 @@ function stringifySourceInfo(source: SourceInfo): string {

type ExternalRequire = (id: ModuleId) => Exports | EsmNamespaceObject;
type ExternalImport = (id: ModuleId) => Promise<Exports | EsmNamespaceObject>;
type ResolveAbsolutePath = (modulePath?: string) => string;

interface TurbopackNodeBuildContext extends TurbopackBaseContext {
P: ResolveAbsolutePath;
R: ResolvePathFromModule;
x: ExternalRequire;
y: ExternalImport;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ type AsyncModule = (
hasAwait: boolean
) => void;

type ResolveAbsolutePath = (modulePath?: string) => string;

interface TurbopackBaseContext {
a: AsyncModule;
e: Module["exports"];
Expand All @@ -71,6 +73,7 @@ interface TurbopackBaseContext {
w: LoadWebAssembly;
u: LoadWebAssemblyModule;
g: typeof globalThis;
P: ResolveAbsolutePath;
U: RelativeURL;
__dirname: string;
}

0 comments on commit 1a084c1

Please sign in to comment.