Commit 9681a66c authored by Damien George's avatar Damien George

webassembly/api: Fix importing micropython.mjs module from node REPL.

Fixes issue #14363.
Signed-off-by: default avatarDamien George <damien@micropython.org>
parent a521df27
...@@ -262,7 +262,7 @@ if ( ...@@ -262,7 +262,7 @@ if (
typeof process.versions === "object" && typeof process.versions === "object" &&
typeof process.versions.node === "string" 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 // See https://stackoverflow.com/questions/6398196/detect-if-called-through-require-or-directly-by-command-line/66309132#66309132
// //
...@@ -270,14 +270,17 @@ if ( ...@@ -270,14 +270,17 @@ if (
// - `resolve()` is used to handle symlinks // - `resolve()` is used to handle symlinks
// - `includes()` is used to handle cases where the file extension was omitted when passed to node // - `includes()` is used to handle cases where the file extension was omitted when passed to node
const path = await import("path"); if (process.argv.length > 1) {
const url = await import("url"); const path = await import("path");
const url = await import("url");
const pathToThisFile = path.resolve(url.fileURLToPath(import.meta.url)); const pathToThisFile = path.resolve(url.fileURLToPath(import.meta.url));
const pathPassedToNode = path.resolve(process.argv[1]); const pathPassedToNode = path.resolve(process.argv[1]);
const isThisFileBeingRunViaCLI = pathToThisFile.includes(pathPassedToNode); const isThisFileBeingRunViaCLI =
pathToThisFile.includes(pathPassedToNode);
if (isThisFileBeingRunViaCLI) { if (isThisFileBeingRunViaCLI) {
runCLI(); runCLI();
}
} }
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment