Skip to content

Commit

Permalink
try fix edge
Browse files Browse the repository at this point in the history
  • Loading branch information
arlyon authored and mischnic committed Nov 6, 2024
1 parent 9ba7cf7 commit 82d0136
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ export default class EvalSourceMapDevToolPlugin {
{
requestShortener: runtimeTemplate.requestShortener,
chunkGraph,
hashFunction: compilation.outputOptions.hashFunction,
hashFunction: compilation.outputOptions.hashFunction!,
}
)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,51 +7,52 @@
/// If a fn requires node.js specific behavior, it should be placed in `node-external-utils` instead.

async function externalImport(id: ModuleId) {
let raw;
let raw
try {
raw = await import(id);
raw = await import(id)
} catch (err) {
// TODO(alexkirsz) This can happen when a client-side module tries to load
// an external module we don't provide a shim for (e.g. querystring, url).
// For now, we fail semi-silently, but in the future this should be a
// compilation error.
throw new Error(`Failed to load external module ${id}: ${err}`);
throw new Error(`Failed to load external module ${id}: ${err}`)
}

if (raw && raw.__esModule && raw.default && "default" in raw.default) {
return interopEsm(raw.default, createNS(raw), true);
if (raw && raw.__esModule && raw.default && 'default' in raw.default) {
return interopEsm(raw.default, createNS(raw), true)
}

return raw;
return raw
}

function externalRequire(
id: ModuleId,
thunk: () => any,
esm: boolean = false
): Exports | EsmNamespaceObject {
let raw;
let raw
try {
raw = require(id);
raw = thunk()
} catch (err) {
// TODO(alexkirsz) This can happen when a client-side module tries to load
// an external module we don't provide a shim for (e.g. querystring, url).
// For now, we fail semi-silently, but in the future this should be a
// compilation error.
throw new Error(`Failed to load external module ${id}: ${err}`);
throw new Error(`Failed to load external module ${id}: ${err}`)
}

if (!esm || raw.__esModule) {
return raw;
return raw
}

return interopEsm(raw, createNS(raw), true);
return interopEsm(raw, createNS(raw), true)
}

externalRequire.resolve = (
id: string,
options?: {
paths?: string[];
paths?: string[]
}
) => {
return require.resolve(id, options);
};
return require.resolve(id, options)
}
Original file line number Diff line number Diff line change
Expand Up @@ -121,10 +121,16 @@ impl SinglePatternMapping {
}),
Self::External(request, ExternalType::CommonJs) => Expr::Call(CallExpr {
callee: Callee::Expr(quote_expr!("__turbopack_external_require__")),
args: vec![ExprOrSpread {
spread: None,
expr: request.as_str().into(),
}],
args: vec![
ExprOrSpread {
spread: None,
expr: request.as_str().into(),
},
ExprOrSpread {
spread: None,
expr: quote_expr!("() => require($arg)"),
},
],
span: DUMMY_SP,
..Default::default()
}),
Expand Down Expand Up @@ -170,7 +176,7 @@ impl SinglePatternMapping {
args: vec![ExprOrSpread {
spread: None,
expr: quote_expr!(
"() => __turbopack_external_require__($arg, true)",
"() => __turbopack_external_require__($arg, () => require($arg), true)",
arg: Expr = key_expr.into_owned()
),
}],
Expand All @@ -184,7 +190,7 @@ impl SinglePatternMapping {
args: vec![ExprOrSpread {
spread: None,
expr: quote_expr!(
"() => __turbopack_external_require__($arg, true)",
"() => __turbopack_external_require__($arg, () => require($arg), true)",
arg: Expr = key_expr.into_owned()
),
}],
Expand Down

0 comments on commit 82d0136

Please sign in to comment.