@willbooster/wb 16.0.1 → 16.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/dotenv.js +5 -1
- package/bin/index.js +4 -0
- package/bin/runArgs.d.ts +2 -0
- package/bin/runArgs.js +100 -0
- package/dist/index.js +35 -35
- package/package.json +1 -1
package/bin/dotenv.js
CHANGED
|
@@ -9,8 +9,12 @@ const shutdownSignals = new Set(['SIGINT', 'SIGTERM', 'SIGQUIT']);
|
|
|
9
9
|
|
|
10
10
|
export function runDotenvCommand(args) {
|
|
11
11
|
const { command } = parseDotenvArgs(args);
|
|
12
|
+
runCommandWithEnvironment(command, 'wb dotenv -- <command> [args...]');
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
function runCommandWithEnvironment(command, usage) {
|
|
12
16
|
if (command.length === 0) {
|
|
13
|
-
console.error(
|
|
17
|
+
console.error(`Usage: ${usage}`);
|
|
14
18
|
process.exit(1);
|
|
15
19
|
}
|
|
16
20
|
|
package/bin/index.js
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
|
+
import { protectRunScriptArgs } from './runArgs.js';
|
|
4
|
+
|
|
5
|
+
protectRunScriptArgs(process.argv);
|
|
6
|
+
|
|
3
7
|
if (process.argv[2] === 'dotenv') {
|
|
4
8
|
const { runDotenvCommand } = await import('./dotenv.js');
|
|
5
9
|
await runDotenvCommand(process.argv.slice(3));
|
package/bin/runArgs.d.ts
ADDED
package/bin/runArgs.js
ADDED
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
const booleanOptionNames = new Set([
|
|
2
|
+
'auto-cascade-env',
|
|
3
|
+
'cascade-node-env',
|
|
4
|
+
'dry-run',
|
|
5
|
+
'dry',
|
|
6
|
+
'd',
|
|
7
|
+
'help',
|
|
8
|
+
'h',
|
|
9
|
+
'include-root-env',
|
|
10
|
+
'quiet-env',
|
|
11
|
+
'verbose',
|
|
12
|
+
'v',
|
|
13
|
+
'version',
|
|
14
|
+
]);
|
|
15
|
+
const valueOptionNames = new Set(['cascade-env', 'check-env', 'env', 'working-dir', 'w']);
|
|
16
|
+
const boundaryMarkerEnvName = 'WB_INTERNAL_RUN_BOUNDARY_MARKER';
|
|
17
|
+
|
|
18
|
+
export function protectRunScriptArgs(argv) {
|
|
19
|
+
const runIndex = findTopLevelRunIndex(argv);
|
|
20
|
+
if (runIndex === -1) return;
|
|
21
|
+
|
|
22
|
+
const scriptIndex = findRunScriptIndex(argv, runIndex + 1);
|
|
23
|
+
if (scriptIndex === undefined || argv[scriptIndex - 1] === '--') return;
|
|
24
|
+
|
|
25
|
+
const existingMarker = process.env[boundaryMarkerEnvName];
|
|
26
|
+
if (argv[scriptIndex + 1] === '--') {
|
|
27
|
+
if (existingMarker && argv[scriptIndex + 2] === existingMarker) return;
|
|
28
|
+
delete process.env[boundaryMarkerEnvName];
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
let marker;
|
|
33
|
+
do marker = `__WB_RUN_SCRIPT_ARGS_${randomUUID()}__`;
|
|
34
|
+
while (argv.includes(marker));
|
|
35
|
+
process.env[boundaryMarkerEnvName] = marker;
|
|
36
|
+
argv.splice(scriptIndex + 1, 0, '--', marker);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export function getRunScriptArgs(argv) {
|
|
40
|
+
const runIndex = findTopLevelRunIndex(argv);
|
|
41
|
+
if (runIndex === -1) return [];
|
|
42
|
+
const scriptIndex = findRunScriptIndex(argv, runIndex + 1);
|
|
43
|
+
if (scriptIndex === undefined) return [];
|
|
44
|
+
|
|
45
|
+
const args = argv.slice(scriptIndex);
|
|
46
|
+
const marker = process.env[boundaryMarkerEnvName];
|
|
47
|
+
if (marker && args[1] === '--' && args[2] === marker) args.splice(1, 2);
|
|
48
|
+
delete process.env[boundaryMarkerEnvName];
|
|
49
|
+
return args;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
function findTopLevelRunIndex(argv) {
|
|
53
|
+
for (let index = 2; index < argv.length; ) {
|
|
54
|
+
const consumed = countOptionTokens(argv, index);
|
|
55
|
+
if (consumed === 0) return argv[index] === 'run' ? index : -1;
|
|
56
|
+
index += consumed;
|
|
57
|
+
}
|
|
58
|
+
return -1;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
function findRunScriptIndex(argv, startIndex) {
|
|
62
|
+
for (let index = startIndex; index < argv.length; ) {
|
|
63
|
+
if (argv[index] === '--') return argv[index + 1] === undefined ? undefined : index + 1;
|
|
64
|
+
const consumed = countOptionTokens(argv, index);
|
|
65
|
+
if (consumed === 0) return index;
|
|
66
|
+
index += consumed;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
function countOptionTokens(argv, index) {
|
|
71
|
+
const arg = argv[index];
|
|
72
|
+
if (!arg?.startsWith('-') || arg === '-') return 0;
|
|
73
|
+
if (arg.startsWith('--')) {
|
|
74
|
+
const optionText = arg.slice(2);
|
|
75
|
+
const equalsIndex = optionText.indexOf('=');
|
|
76
|
+
const rawName = equalsIndex === -1 ? optionText : optionText.slice(0, equalsIndex);
|
|
77
|
+
const name = rawName.startsWith('no-') ? rawName.slice(3) : rawName;
|
|
78
|
+
if (booleanOptionNames.has(name)) {
|
|
79
|
+
return equalsIndex === -1 && isBooleanLiteral(argv[index + 1]) ? 2 : 1;
|
|
80
|
+
}
|
|
81
|
+
if (!valueOptionNames.has(name)) return 0;
|
|
82
|
+
return equalsIndex === -1 ? 2 : 1;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
const shortOptions = arg.slice(1);
|
|
86
|
+
if (/^[dhv]=(false|true)$/.test(shortOptions)) return 1;
|
|
87
|
+
if (/^[dhv]$/.test(shortOptions) && isBooleanLiteral(argv[index + 1])) return 2;
|
|
88
|
+
for (let optionIndex = 0; optionIndex < shortOptions.length; optionIndex++) {
|
|
89
|
+
const name = shortOptions[optionIndex];
|
|
90
|
+
if (booleanOptionNames.has(name)) continue;
|
|
91
|
+
if (valueOptionNames.has(name)) return optionIndex + 1 < shortOptions.length ? 1 : 2;
|
|
92
|
+
return 0;
|
|
93
|
+
}
|
|
94
|
+
return 1;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
function isBooleanLiteral(value) {
|
|
98
|
+
return value === 'false' || value === 'true';
|
|
99
|
+
}
|
|
100
|
+
import { randomUUID } from 'node:crypto';
|