@saasak/tool-env 1.2.2 → 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 CHANGED
@@ -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...]");
@@ -294,6 +295,7 @@ async function runCommand() {
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
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@saasak/tool-env",
3
3
  "license": "MIT",
4
- "version": "1.2.2",
4
+ "version": "1.3.0",
5
5
  "author": "dev@saasak.studio",
6
6
  "description": "A small util to manage environment variables for your monorepo",
7
7
  "keywords": [
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
  /**
@@ -288,6 +290,7 @@ export function loadEnvJson(options = {}) {
288
290
  secret: secretParam,
289
291
  envPath = ".env.json",
290
292
  cwd = process.cwd(),
293
+ expose = false
291
294
  } = options;
292
295
 
293
296
  const secret = resolveSecret(secretParam);
@@ -341,7 +344,13 @@ export function loadEnvJson(options = {}) {
341
344
  const currentPackageName = findNearestPackageName(cwd, scope);
342
345
 
343
346
  // Return env for current package (with fallback to root)
344
- return allEnvs[currentPackageName] || allEnvs.root || {};
347
+ const finalEnv = allEnvs[currentPackageName] || allEnvs.root || {};
348
+
349
+ return expose ? {
350
+ ...finalEnv,
351
+ WRENV_TARGET: resolvedTarget,
352
+ WRENV_SECRET: secret
353
+ } : finalEnv;
345
354
  }
346
355
 
347
356
  /**
@@ -369,6 +378,7 @@ export function load(options = {}) {
369
378
  envPath,
370
379
  cwd = process.cwd(),
371
380
  applyToProcess = true,
381
+ expose = false
372
382
  } = options;
373
383
 
374
384
  // Resolve target first to determine if we're in dev mode
@@ -380,6 +390,7 @@ export function load(options = {}) {
380
390
  targetEnv: resolvedTarget,
381
391
  envPath,
382
392
  cwd,
393
+ expose
383
394
  });
384
395
 
385
396
  // Load .env.local overrides only in dev mode (security: prevent local overrides in production)
@@ -398,10 +409,12 @@ export function load(options = {}) {
398
409
  }
399
410
 
400
411
  // - Reserved vars (WRENV_*, TARGET_*) are never injected
401
- // - NODE_ENV is only injected if not already set
402
- for (const key of RESERVED_ENV_VARS) {
403
- delete finalConfig[key];
412
+ if (!expose) {
413
+ for (const key of RESERVED_ENV_VARS) {
414
+ delete finalConfig[key];
415
+ }
404
416
  }
417
+ // - NODE_ENV is only injected if not already set
405
418
  if (process.env.NODE_ENV) {
406
419
  delete finalConfig.NODE_ENV;
407
420
  }