@willbooster/wb 13.28.8 → 14.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 +53 -1
- package/dist/index.js +16 -16
- package/package.json +15 -14
package/bin/dotenv.js
CHANGED
|
@@ -68,10 +68,13 @@ export function runDotenvCommand(args) {
|
|
|
68
68
|
}
|
|
69
69
|
|
|
70
70
|
function readAndApplyEnvironmentVariables(cwd) {
|
|
71
|
-
const
|
|
71
|
+
const dotenvVars = {
|
|
72
72
|
...readEnvFile(path.join(cwd, '.env')),
|
|
73
73
|
...(process.env.WB_ENV ? readEnvFile(path.join(cwd, `.env.${process.env.WB_ENV}`)) : {}),
|
|
74
74
|
};
|
|
75
|
+
// fnox.toml is the committed, encrypted equivalent of .env files; local .env files still win
|
|
76
|
+
// over it. Mirrors src/commands/dotenv.ts for this startup fast path.
|
|
77
|
+
const parsed = { ...readFnoxEnvironmentVariables(cwd, process.env.WB_ENV, dotenvVars), ...dotenvVars };
|
|
75
78
|
const envVars = expand({ parsed, processEnv: {} }).parsed ?? parsed;
|
|
76
79
|
for (const [key, value] of Object.entries(envVars)) {
|
|
77
80
|
if (!(key in process.env)) {
|
|
@@ -80,6 +83,55 @@ function readAndApplyEnvironmentVariables(cwd) {
|
|
|
80
83
|
}
|
|
81
84
|
}
|
|
82
85
|
|
|
86
|
+
// Mirrors readFnoxEnvironmentVariables in @willbooster/shared-lib-node for this startup fast path.
|
|
87
|
+
function readFnoxEnvironmentVariables(cwd, cascade, currentEnvVars) {
|
|
88
|
+
if (!hasProjectFnoxConfig(cwd)) return {};
|
|
89
|
+
|
|
90
|
+
// `--if-missing error`: fnox otherwise exits 0 and silently omits secrets it fails to resolve.
|
|
91
|
+
// `--non-interactive`: prompts or browser auth flows would hang forever because stdin is ignored.
|
|
92
|
+
const args = ['export', '--format', 'json', '--no-color', '--if-missing', 'error', '--non-interactive'];
|
|
93
|
+
if (cascade) {
|
|
94
|
+
args.push('--profile', cascade);
|
|
95
|
+
}
|
|
96
|
+
const result = childProcess.spawnSync('fnox', args, {
|
|
97
|
+
cwd,
|
|
98
|
+
encoding: 'utf8',
|
|
99
|
+
stdio: ['ignore', 'pipe', 'pipe'],
|
|
100
|
+
});
|
|
101
|
+
if (result.error || result.status !== 0 || !result.stdout?.trim()) {
|
|
102
|
+
console.warn(
|
|
103
|
+
`Failed to read fnox secrets: ${result.error?.message || result.stderr?.trim() || `fnox exited with status ${result.status}`}`
|
|
104
|
+
);
|
|
105
|
+
return {};
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
let parsed;
|
|
109
|
+
try {
|
|
110
|
+
parsed = JSON.parse(result.stdout);
|
|
111
|
+
} catch {
|
|
112
|
+
return {};
|
|
113
|
+
}
|
|
114
|
+
const secrets = parsed?.secrets;
|
|
115
|
+
if (!secrets || typeof secrets !== 'object' || Array.isArray(secrets)) return {};
|
|
116
|
+
|
|
117
|
+
const envVars = {};
|
|
118
|
+
for (const [key, value] of Object.entries(secrets)) {
|
|
119
|
+
if (typeof value !== 'string' || key in currentEnvVars || key in process.env) continue;
|
|
120
|
+
envVars[key] = value;
|
|
121
|
+
}
|
|
122
|
+
return envVars;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
function hasProjectFnoxConfig(cwd) {
|
|
126
|
+
for (let currentPath = path.resolve(cwd); ; currentPath = path.dirname(currentPath)) {
|
|
127
|
+
if (fs.existsSync(path.join(currentPath, 'fnox.toml'))) {
|
|
128
|
+
return true;
|
|
129
|
+
}
|
|
130
|
+
const parentPath = path.dirname(currentPath);
|
|
131
|
+
if (parentPath === currentPath) return false;
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
|
|
83
135
|
function readEnvFile(filePath) {
|
|
84
136
|
return config({ path: path.resolve(filePath), processEnv: {}, quiet: true }).parsed ?? {};
|
|
85
137
|
}
|