From d92f5a818cc7a5450d5a84041b45db03dbd0a52e Mon Sep 17 00:00:00 2001 From: Guilherme Rodrigues Date: Sun, 8 Mar 2020 18:18:29 -0300 Subject: [PATCH] Fix deno argv handling --- dist/index.js | 5 ++++- mod.js | 5 ++++- src/node.ts | 8 +++++++- 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/dist/index.js b/dist/index.js index 6926123..6e77518 100644 --- a/dist/index.js +++ b/dist/index.js @@ -281,7 +281,10 @@ class Option { } const deno = typeof window !== 'undefined' && window.Deno; -const processArgs = deno ? ['deno'].concat(Deno.args) : process.argv; +const denoScriptPath = deno && typeof window !== 'undefined' && window.location.pathname; +// Adds deno executable and script path to processArgs as "compatibility" layer for node +// See https://github.com/cacjs/cac/issues/69 +const processArgs = deno ? ['deno', denoScriptPath].concat(Deno.args) : process.argv; const platformInfo = deno ? `${Deno.build.os}-${Deno.build.arch} deno-${Deno.version.deno}` : `${process.platform}-${process.arch} node-${process.version}`; diff --git a/mod.js b/mod.js index 645466e..64bb35e 100644 --- a/mod.js +++ b/mod.js @@ -704,7 +704,10 @@ class Option { } const deno = typeof window !== 'undefined' && window.Deno; -const processArgs = deno ? ['deno'].concat(Deno.args) : process.argv; +const denoScriptPath = deno && typeof window !== 'undefined' && window.location.pathname; +// Adds deno executable and script path to processArgs as "compatibility" layer for node +// See https://github.com/cacjs/cac/issues/69 +const processArgs = deno ? ['deno', denoScriptPath].concat(Deno.args) : process.argv; const platformInfo = deno ? `${Deno.build.os}-${Deno.build.arch} deno-${Deno.version.deno}` : `${process.platform}-${process.arch} node-${process.version}`; diff --git a/src/node.ts b/src/node.ts index 7cd4117..6f0824c 100644 --- a/src/node.ts +++ b/src/node.ts @@ -2,8 +2,14 @@ declare let window: any declare let Deno: any const deno = typeof window !== 'undefined' && window.Deno +const denoScriptPath = + deno && typeof window !== 'undefined' && window.location.pathname -export const processArgs = deno ? ['deno'].concat(Deno.args) : process.argv +// Adds deno executable and script path to processArgs as "compatibility" layer for node +// See https://github.com/cacjs/cac/issues/69 +export const processArgs = deno + ? ['deno', denoScriptPath].concat(Deno.args) + : process.argv export const platformInfo = deno ? `${Deno.build.os}-${Deno.build.arch} deno-${Deno.version.deno}`