@saasak/tool-env 1.2.1 → 1.3.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/index.js +4 -2
- package/package.json +1 -1
- package/src/core.js +20 -12
package/bin/index.js
CHANGED
|
@@ -21,7 +21,7 @@ const __root = process.cwd();
|
|
|
21
21
|
|
|
22
22
|
const command = args._[0] || "write";
|
|
23
23
|
|
|
24
|
-
const secret = resolveSecret(args.secret);
|
|
24
|
+
const secret = resolveSecret(args.secret ? `file://${args.secret}` : '');
|
|
25
25
|
|
|
26
26
|
const envPath = args.env || ".env.json";
|
|
27
27
|
const envFile = path.resolve(__root, envPath);
|
|
@@ -280,6 +280,7 @@ async function addCommand() {
|
|
|
280
280
|
async function runCommand() {
|
|
281
281
|
const commandParts = args["--"] || [];
|
|
282
282
|
const [cmd, ...cmdArgs] = commandParts;
|
|
283
|
+
const expose = !!args.expose
|
|
283
284
|
|
|
284
285
|
if (!cmd) {
|
|
285
286
|
console.error("Usage: wrenv run [options] -- <command> [args...]");
|
|
@@ -290,10 +291,11 @@ async function runCommand() {
|
|
|
290
291
|
let envVars = {};
|
|
291
292
|
try {
|
|
292
293
|
envVars = load({
|
|
293
|
-
secret:
|
|
294
|
+
secret: secret,
|
|
294
295
|
targetEnv: args.target,
|
|
295
296
|
envPath: args.env,
|
|
296
297
|
applyToProcess: false,
|
|
298
|
+
expose
|
|
297
299
|
});
|
|
298
300
|
} catch (error) {
|
|
299
301
|
console.error(`wrenv: ${error.message}`);
|
package/package.json
CHANGED
package/src/core.js
CHANGED
|
@@ -16,6 +16,7 @@ import { findMonorepoPackages } from "./utils-pkg.js";
|
|
|
16
16
|
* @property {string} [envPath] - Path to env.json file (default: '.env.json')
|
|
17
17
|
* @property {string} [cwd] - Working directory (default: process.cwd())
|
|
18
18
|
* @property {boolean} [applyToProcess] - Whether to apply to process.env (default: true)
|
|
19
|
+
* @property {boolean} [expose] - wether to expose the secret or not
|
|
19
20
|
*/
|
|
20
21
|
|
|
21
22
|
/**
|
|
@@ -24,6 +25,7 @@ import { findMonorepoPackages } from "./utils-pkg.js";
|
|
|
24
25
|
* @property {string} [targetEnv] - Target environment
|
|
25
26
|
* @property {string} [envPath] - Path to env.json file (default: '.env.json')
|
|
26
27
|
* @property {string} [cwd] - Working directory (default: process.cwd())
|
|
28
|
+
* @property {boolean} [expose] - wether to expose the secret or not
|
|
27
29
|
*/
|
|
28
30
|
|
|
29
31
|
/**
|
|
@@ -153,18 +155,13 @@ export function resolveSecret(secretParam) {
|
|
|
153
155
|
}
|
|
154
156
|
}
|
|
155
157
|
|
|
156
|
-
if (!secretParam)
|
|
157
|
-
return getDefault();
|
|
158
|
-
|
|
159
158
|
if (secretParam === "stdin")
|
|
160
159
|
return getFromStream(0);
|
|
161
160
|
|
|
162
|
-
if (secretParam.startsWith("file://"))
|
|
161
|
+
if ((secretParam || '').startsWith("file://"))
|
|
163
162
|
return getFromStream(secretParam.slice(7));
|
|
164
163
|
|
|
165
|
-
return
|
|
166
|
-
? getFromStream(secretParam)
|
|
167
|
-
: getDefault(secretParam); // Treat as literal if not a file
|
|
164
|
+
return getDefault(secretParam)
|
|
168
165
|
}
|
|
169
166
|
|
|
170
167
|
/**
|
|
@@ -289,10 +286,11 @@ function findMonorepoRoot(cwd, envPath) {
|
|
|
289
286
|
*/
|
|
290
287
|
export function loadEnvJson(options = {}) {
|
|
291
288
|
const {
|
|
292
|
-
secret: secretParam,
|
|
293
289
|
targetEnv: targetParam,
|
|
290
|
+
secret: secretParam,
|
|
294
291
|
envPath = ".env.json",
|
|
295
292
|
cwd = process.cwd(),
|
|
293
|
+
expose = false
|
|
296
294
|
} = options;
|
|
297
295
|
|
|
298
296
|
const secret = resolveSecret(secretParam);
|
|
@@ -346,7 +344,13 @@ export function loadEnvJson(options = {}) {
|
|
|
346
344
|
const currentPackageName = findNearestPackageName(cwd, scope);
|
|
347
345
|
|
|
348
346
|
// Return env for current package (with fallback to root)
|
|
349
|
-
|
|
347
|
+
const finalEnv = allEnvs[currentPackageName] || allEnvs.root || {};
|
|
348
|
+
|
|
349
|
+
return expose ? {
|
|
350
|
+
...finalEnv,
|
|
351
|
+
WRENV_TARGET: resolvedTarget,
|
|
352
|
+
WRENV_SECRET: secret
|
|
353
|
+
} : finalEnv;
|
|
350
354
|
}
|
|
351
355
|
|
|
352
356
|
/**
|
|
@@ -374,6 +378,7 @@ export function load(options = {}) {
|
|
|
374
378
|
envPath,
|
|
375
379
|
cwd = process.cwd(),
|
|
376
380
|
applyToProcess = true,
|
|
381
|
+
expose = false
|
|
377
382
|
} = options;
|
|
378
383
|
|
|
379
384
|
// Resolve target first to determine if we're in dev mode
|
|
@@ -385,6 +390,7 @@ export function load(options = {}) {
|
|
|
385
390
|
targetEnv: resolvedTarget,
|
|
386
391
|
envPath,
|
|
387
392
|
cwd,
|
|
393
|
+
expose
|
|
388
394
|
});
|
|
389
395
|
|
|
390
396
|
// Load .env.local overrides only in dev mode (security: prevent local overrides in production)
|
|
@@ -403,10 +409,12 @@ export function load(options = {}) {
|
|
|
403
409
|
}
|
|
404
410
|
|
|
405
411
|
// - Reserved vars (WRENV_*, TARGET_*) are never injected
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
412
|
+
if (!expose) {
|
|
413
|
+
for (const key of RESERVED_ENV_VARS) {
|
|
414
|
+
delete finalConfig[key];
|
|
415
|
+
}
|
|
409
416
|
}
|
|
417
|
+
// - NODE_ENV is only injected if not already set
|
|
410
418
|
if (process.env.NODE_ENV) {
|
|
411
419
|
delete finalConfig.NODE_ENV;
|
|
412
420
|
}
|