summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDamien George <damien@micropython.org>2024-05-02 16:29:39 +1000
committerDamien George <damien@micropython.org>2024-05-06 13:53:58 +1000
commit9681a66c6b79a5f4721c74b756256336c47c9879 (patch)
tree04ff49064d1c9e2d27f3f8670a3b15f53b62da55
parenta521df27dc483c5376ef7e348aa9fbbd0c4e67a9 (diff)
webassembly/api: Fix importing micropython.mjs module from node REPL.
Fixes issue #14363. Signed-off-by: Damien George <damien@micropython.org>
-rw-r--r--ports/webassembly/api.js19
1 files changed, 11 insertions, 8 deletions
diff --git a/ports/webassembly/api.js b/ports/webassembly/api.js
index 2be82e890..f3245451e 100644
--- a/ports/webassembly/api.js
+++ b/ports/webassembly/api.js
@@ -262,7 +262,7 @@ if (
typeof process.versions === "object" &&
typeof process.versions.node === "string"
) {
- // Check if this module is ron from the command line.
+ // Check if this module is run from the command line via `node micropython.mjs`.
//
// See https://stackoverflow.com/questions/6398196/detect-if-called-through-require-or-directly-by-command-line/66309132#66309132
//
@@ -270,14 +270,17 @@ if (
// - `resolve()` is used to handle symlinks
// - `includes()` is used to handle cases where the file extension was omitted when passed to node
- const path = await import("path");
- const url = await import("url");
+ if (process.argv.length > 1) {
+ const path = await import("path");
+ const url = await import("url");
- const pathToThisFile = path.resolve(url.fileURLToPath(import.meta.url));
- const pathPassedToNode = path.resolve(process.argv[1]);
- const isThisFileBeingRunViaCLI = pathToThisFile.includes(pathPassedToNode);
+ const pathToThisFile = path.resolve(url.fileURLToPath(import.meta.url));
+ const pathPassedToNode = path.resolve(process.argv[1]);
+ const isThisFileBeingRunViaCLI =
+ pathToThisFile.includes(pathPassedToNode);
- if (isThisFileBeingRunViaCLI) {
- runCLI();
+ if (isThisFileBeingRunViaCLI) {
+ runCLI();
+ }
}
}