-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
1 changed file
with
36 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
// This polyfill of the WinterCG CLI API proposal is highly likely to have breaking changes in the future! | ||
// https://github.com/CanadaHonk/proposal-cli-api | ||
|
||
// Implemented: | ||
// - args | ||
|
||
|
||
const NAMESPACE = 'CLI'; | ||
|
||
if (typeof process !== 'undefined') { | ||
// Node or Node-compatible runtime (Bun): | ||
// process.argv already excludes arguments used by the runtime, | ||
// but still has the runtime binary path and script path. | ||
|
||
const { argv } = process; | ||
globalThis[NAMESPACE] = { | ||
args: argv.slice(2) | ||
}; | ||
} else if (typeof Deno !== 'undefined') { | ||
// Deno: | ||
// Deno.args is already as specified. | ||
|
||
const { args } = Deno; | ||
globalThis[NAMESPACE] = { | ||
args | ||
}; | ||
} else { | ||
// Unknown runtime: | ||
// Warn and create mock API. | ||
|
||
console.warn('[cli-api-polyfill] Unknown runtime!'); | ||
|
||
globalThis[NAMESPACE] = { | ||
args: [] | ||
}; | ||
} |