Skip to content

Commit 9681a66

Browse files
committed
webassembly/api: Fix importing micropython.mjs module from node REPL.
Fixes issue micropython#14363. Signed-off-by: Damien George <[email protected]>
1 parent a521df2 commit 9681a66

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

ports/webassembly/api.js

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -262,22 +262,25 @@ if (
262262
typeof process.versions === "object" &&
263263
typeof process.versions.node === "string"
264264
) {
265-
// Check if this module is ron from the command line.
265+
// Check if this module is run from the command line via `node micropython.mjs`.
266266
//
267267
// See https://stackoverflow.com/questions/6398196/detect-if-called-through-require-or-directly-by-command-line/66309132#66309132
268268
//
269269
// Note:
270270
// - `resolve()` is used to handle symlinks
271271
// - `includes()` is used to handle cases where the file extension was omitted when passed to node
272272

273-
const path = await import("path");
274-
const url = await import("url");
273+
if (process.argv.length > 1) {
274+
const path = await import("path");
275+
const url = await import("url");
275276

276-
const pathToThisFile = path.resolve(url.fileURLToPath(import.meta.url));
277-
const pathPassedToNode = path.resolve(process.argv[1]);
278-
const isThisFileBeingRunViaCLI = pathToThisFile.includes(pathPassedToNode);
277+
const pathToThisFile = path.resolve(url.fileURLToPath(import.meta.url));
278+
const pathPassedToNode = path.resolve(process.argv[1]);
279+
const isThisFileBeingRunViaCLI =
280+
pathToThisFile.includes(pathPassedToNode);
279281

280-
if (isThisFileBeingRunViaCLI) {
281-
runCLI();
282+
if (isThisFileBeingRunViaCLI) {
283+
runCLI();
284+
}
282285
}
283286
}

0 commit comments

Comments
 (0)