Skip to content

Commit

Permalink
refactor: use imporr/require in debug logs
Browse files Browse the repository at this point in the history
  • Loading branch information
pi0 committed Jul 2, 2024
1 parent 50b1b3a commit 934a5bb
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
7 changes: 6 additions & 1 deletion src/eval.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,12 @@ export function evalModule(
);
} else {
try {
debug(ctx, "[native]", evalOptions.async ? "[esm]" : "[cjs]", filename);
debug(
ctx,
"[native]",
evalOptions.async ? "[import]" : "[require]",
filename,
);
return nativeImportOrRequire(ctx, filename, evalOptions.async);
} catch (error: any) {
debug(ctx, "Native require error:", error);
Expand Down
10 changes: 8 additions & 2 deletions src/require.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,17 @@ export function jitiRequire(
// Experimental Bun support
if (ctx.opts.experimentalBun && !ctx.opts.transformOptions) {
try {
debug(ctx, "[bun]", "[native]", id);
id = jitiResolve(ctx, id, opts);
if (!id && opts.try) {
return undefined;
}
debug(
ctx,
"[bun]",
"[native]",
opts.async && ctx.nativeImport ? "[import]" : "[require]",
id,
);
if (opts.async && ctx.nativeImport) {
return ctx.nativeImport(id).then((m: any) => {
if (ctx.opts.moduleCache === false) {
Expand Down Expand Up @@ -82,7 +88,7 @@ export function jitiRequire(

// Force native modules
if (ctx.isNativeRe.test(filename)) {
debug(ctx, "[native]", opts.async ? "[esm]" : "[cjs]", filename);
debug(ctx, "[native]", opts.async ? "[import]" : "[require]", filename);
return nativeImportOrRequire(ctx, id, opts.async);
}

Expand Down
2 changes: 2 additions & 0 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ const debugMap = {
false: yellow("false"),
"[esm]": blue("[esm]"),
"[cjs]": green("[cjs]"),
"[import]": blue("[import]"),
"[require]": green("[require]"),
"[native]": cyan("[native]"),
"[transpile]": yellow("[transpile]"),
"[fallback]": red("[fallback]"),
Expand Down

0 comments on commit 934a5bb

Please sign in to comment.