Skip to content

Commit

Permalink
Polyfill: Initial demo
Browse files Browse the repository at this point in the history
Closes #10.
  • Loading branch information
CanadaHonk committed Feb 7, 2024
1 parent 2751c3c commit ad91e4c
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions polyfill.js
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: []
};
}

0 comments on commit ad91e4c

Please sign in to comment.