File tree 1 file changed +11
-8
lines changed
1 file changed +11
-8
lines changed Original file line number Diff line number Diff line change @@ -262,22 +262,25 @@ if (
262
262
typeof process . versions === "object" &&
263
263
typeof process . versions . node === "string"
264
264
) {
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` .
266
266
//
267
267
// See https://stackoverflow.com/questions/6398196/detect-if-called-through-require-or-directly-by-command-line/66309132#66309132
268
268
//
269
269
// Note:
270
270
// - `resolve()` is used to handle symlinks
271
271
// - `includes()` is used to handle cases where the file extension was omitted when passed to node
272
272
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" ) ;
275
276
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 ) ;
279
281
280
- if ( isThisFileBeingRunViaCLI ) {
281
- runCLI ( ) ;
282
+ if ( isThisFileBeingRunViaCLI ) {
283
+ runCLI ( ) ;
284
+ }
282
285
}
283
286
}
You can’t perform that action at this time.
0 commit comments