varlock 0.2.1 → 0.2.3
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/README.md +2 -0
- package/dist/auto-load.js +8 -8
- package/dist/chunk-2YPKUF3A.js +18 -0
- package/dist/{chunk-7SH6C6WJ.js.map → chunk-2YPKUF3A.js.map} +1 -1
- package/dist/{chunk-RZT65DRA.js → chunk-35SAMS66.js} +4 -4
- package/dist/{chunk-RZT65DRA.js.map → chunk-35SAMS66.js.map} +1 -1
- package/dist/{chunk-XN24GZXQ.js → chunk-6PEHRAEP.js} +3 -8
- package/dist/{chunk-XN24GZXQ.js.map → chunk-6PEHRAEP.js.map} +1 -1
- package/dist/{chunk-ZLM3MCYF.js → chunk-BXR2RIO6.js} +6 -6
- package/dist/{chunk-ZLM3MCYF.js.map → chunk-BXR2RIO6.js.map} +1 -1
- package/dist/{chunk-NA4YDM42.js → chunk-HTF7NU5C.js} +10 -9
- package/dist/chunk-HTF7NU5C.js.map +1 -0
- package/dist/{chunk-NDWB3TT5.js → chunk-ISSW6NKZ.js} +9 -4
- package/dist/chunk-ISSW6NKZ.js.map +1 -0
- package/dist/{chunk-FGMXIEFA.js → chunk-MIBOBKI4.js} +3 -3
- package/dist/{chunk-FGMXIEFA.js.map → chunk-MIBOBKI4.js.map} +1 -1
- package/dist/chunk-OY5U5WTF.js +10829 -0
- package/dist/chunk-OY5U5WTF.js.map +1 -0
- package/dist/chunk-PESTWPBG.js +307 -0
- package/dist/chunk-PESTWPBG.js.map +1 -0
- package/dist/{chunk-H5IG4ZVM.js → chunk-Q3C4VKFT.js} +6 -6
- package/dist/chunk-Q3C4VKFT.js.map +1 -0
- package/dist/chunk-QZ6HBRJC.js +97 -0
- package/dist/chunk-QZ6HBRJC.js.map +1 -0
- package/dist/{chunk-FUDH2TTI.js → chunk-TVFOIGJP.js} +3 -3
- package/dist/{chunk-FUDH2TTI.js.map → chunk-TVFOIGJP.js.map} +1 -1
- package/dist/{chunk-5IMCRQTM.js → chunk-TYIS6T2T.js} +4 -4
- package/dist/{chunk-5IMCRQTM.js.map → chunk-TYIS6T2T.js.map} +1 -1
- package/dist/chunk-UDXNNRWI.js +1386 -0
- package/dist/chunk-UDXNNRWI.js.map +1 -0
- package/dist/{chunk-HPNRKYVF.js → chunk-UIOEEWG5.js} +4 -4
- package/dist/{chunk-HPNRKYVF.js.map → chunk-UIOEEWG5.js.map} +1 -1
- package/dist/{chunk-MSRPV5WH.js → chunk-WAMBVZL2.js} +4 -4
- package/dist/{chunk-MSRPV5WH.js.map → chunk-WAMBVZL2.js.map} +1 -1
- package/dist/chunk-YIXN7TC7.js +1532 -0
- package/dist/chunk-YIXN7TC7.js.map +1 -0
- package/dist/{chunk-NSY7JMFV.js → chunk-ZXJ4CEDK.js} +4 -4
- package/dist/{chunk-NSY7JMFV.js.map → chunk-ZXJ4CEDK.js.map} +1 -1
- package/dist/cli/cli-executable.js +20 -21
- package/dist/cli/cli-executable.js.map +1 -1
- package/dist/dotenv-compat.js +8 -8
- package/dist/{env-graph-BZwrHQbb.d.ts → env-graph-DIcuAiYh.d.ts} +9 -2
- package/dist/help.command-MLH2WA5Y.js +5 -0
- package/dist/{help.command-B7VWA53B.js.map → help.command-MLH2WA5Y.js.map} +1 -1
- package/dist/index.d.ts +2 -3
- package/dist/index.js +10 -9
- package/dist/index.js.map +1 -1
- package/dist/init.command-RAYBZ66R.js +9 -0
- package/dist/{init.command-GNLFBWYF.js.map → init.command-RAYBZ66R.js.map} +1 -1
- package/dist/lib/exec-sync-varlock.js +2 -2
- package/dist/load.command-KOSPGLV6.js +9 -0
- package/dist/{load.command-WR5QCE6M.js.map → load.command-KOSPGLV6.js.map} +1 -1
- package/dist/plugin-lib.d.ts +2 -3
- package/dist/plugin-lib.js +2 -1
- package/dist/run.command-BOBQIELJ.js +10 -0
- package/dist/{run.command-GXQTDDDP.js.map → run.command-BOBQIELJ.js.map} +1 -1
- package/dist/runtime/env.d.ts +1 -2
- package/dist/runtime/env.js +3 -3
- package/dist/runtime/patch-console.js +4 -4
- package/dist/runtime/patch-response.js +4 -4
- package/dist/runtime/patch-server-response.js +4 -4
- package/dist/telemetry.command-SFEMMU3U.js +9 -0
- package/dist/{telemetry.command-ZFW55RLH.js.map → telemetry.command-SFEMMU3U.js.map} +1 -1
- package/package.json +35 -22
- package/dist/chunk-33ROL4J5.js +0 -1013
- package/dist/chunk-33ROL4J5.js.map +0 -1
- package/dist/chunk-4CRDKWAU.js +0 -1281
- package/dist/chunk-4CRDKWAU.js.map +0 -1
- package/dist/chunk-7SH6C6WJ.js +0 -18
- package/dist/chunk-H5IG4ZVM.js.map +0 -1
- package/dist/chunk-NA4YDM42.js.map +0 -1
- package/dist/chunk-NDWB3TT5.js.map +0 -1
- package/dist/chunk-NHA2P5AV.js +0 -135
- package/dist/chunk-NHA2P5AV.js.map +0 -1
- package/dist/chunk-OKNWYS57.js +0 -4061
- package/dist/chunk-OKNWYS57.js.map +0 -1
- package/dist/en-US-TSGNDI2P.js +0 -22
- package/dist/en-US-TSGNDI2P.js.map +0 -1
- package/dist/help.command-B7VWA53B.js +0 -5
- package/dist/init.command-GNLFBWYF.js +0 -8
- package/dist/ja-JP-UBPCQAAD.js +0 -22
- package/dist/ja-JP-UBPCQAAD.js.map +0 -1
- package/dist/load.command-WR5QCE6M.js +0 -8
- package/dist/run.command-GXQTDDDP.js +0 -9
- package/dist/telemetry.command-ZFW55RLH.js +0 -8
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/cli/commands/load.command.ts"],"names":[],"mappings":";;;;;;AAUO,IAAM,cAAc,MAAA,CAAO;AAAA,EAChC,IAAA,EAAM,MAAA;AAAA,EACN,WAAA,EAAa,iDAAA;AAAA,EACb,IAAA,EAAM;AAAA,IACJ,MAAA,EAAQ;AAAA,MACN,IAAA,EAAM,MAAA;AAAA,MACN,KAAA,EAAO,GAAA;AAAA,MACP,SAAS,CAAC,QAAA,EAAU,MAAA,EAAQ,KAA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AAmB,MAAM,CAAA,CAAE,CAAA;AAAA,EAC7C;AAIF,CAAA,EA1EmE,WAAA","file":"chunk-NA4YDM42.js","sourcesContent":["import { define } from 'gunshi';\nimport _ from '@env-spec/utils/my-dash';\n\nimport { loadVarlockEnvGraph } from '../../lib/load-graph';\nimport { getItemSummary } from '../../lib/formatting';\nimport { checkForConfigErrors, checkForSchemaErrors } from '../helpers/error-checks';\nimport { type TypedGunshiCommandFn } from '../helpers/gunshi-type-utils';\nimport path from 'node:path';\nimport { FileBasedDataSource } from '../../env-graph';\n\nexport const commandSpec = define({\n name: 'load',\n description: 'Load env according to schema and resolve values',\n args: {\n format: {\n type: 'enum',\n short: 'f',\n choices: ['pretty', 'json', 'env', 'json-full', 'json-full-compact'],\n description: 'Format of output',\n default: 'pretty',\n },\n compact: {\n type: 'boolean',\n description: 'Use compact format (for json-full: no indentation, for env: skip undefined values)',\n },\n 'show-all': {\n type: 'boolean',\n description: 'When load is failing, show all items rather than only failing items',\n },\n env: {\n type: 'string',\n description: 'Set the environment (e.g., production, development, etc) - will be overridden by @currentEnv in the schema if present',\n },\n path: {\n type: 'string',\n short: 'p',\n description: 'Path to a specific .env file or directory (with trailing slash) to use as the entry point',\n },\n },\n examples: `\nLoads and validates environment variables according to your .env files, and prints the results.\nUseful for debugging locally, and in CI to print out a summary of env vars.\n\nExamples:\n varlock load # Load and validate with pretty output\n varlock load --format json # Output in JSON format\n varlock load --show-all # Show all items when validation fails\n varlock load --path .env.prod # Load from a specific .env file\n varlock load --env production # Load for a specific environment (⚠️ ignored if using @currentEnv!)\n`.trim(),\n});\n\n\nexport const commandFn: TypedGunshiCommandFn<typeof commandSpec> = async (ctx) => {\n const { format, compact, 'show-all': showAll } = ctx.values;\n\n const envGraph = await loadVarlockEnvGraph({\n currentEnvFallback: ctx.values.env,\n entryFilePath: ctx.values.path,\n });\n checkForSchemaErrors(envGraph);\n\n if (!envGraph.rootDataSource) throw new Error('expected root data source to be set');\n\n await envGraph.resolveEnvValues();\n\n // ideally we could be smarter about generating types without needing to resolve values\n // but for now the decorators are all resolved as part of the general resolution process\n const generateTypesDecs = envGraph.getRootDecFns('generateTypes');\n for (const generateTypesDec of generateTypesDecs) {\n const typeGenSettings = await generateTypesDec.resolve();\n\n // we skip generating types if `@generateTypes` was not in the main file\n // unless the `executeWhenImported` flag is set\n if (generateTypesDec.dataSource.isImport && !typeGenSettings.obj.executeWhenImported) continue;\n\n if (!typeGenSettings.obj.lang) throw new Error('@generateTypes - must set `lang` arg');\n if (typeGenSettings.obj.lang !== 'ts') throw new Error(`@generateTypes - unsupported language: ${typeGenSettings.obj.lang}`);\n if (!typeGenSettings.obj.path) throw new Error('@generateTypes - must set `path` arg');\n if (!_.isString(typeGenSettings.obj.path)) throw new Error('@generateTypes - `path` arg must be a string');\n\n const outputPath = generateTypesDec.dataSource instanceof FileBasedDataSource\n ? path.resolve(generateTypesDec.dataSource.fullPath, '..', typeGenSettings.obj.path)\n : typeGenSettings.obj.path;\n\n await envGraph.generateTypes(typeGenSettings.obj.lang, outputPath);\n }\n\n checkForConfigErrors(envGraph, { showAll });\n\n if (format === 'pretty') {\n for (const itemKey in envGraph.configSchema) {\n const item = envGraph.configSchema[itemKey];\n console.log(getItemSummary(item));\n }\n } else if (format === 'json') {\n console.log(JSON.stringify(envGraph.getResolvedEnvObject(), null, 2));\n } else if (format === 'json-full' || format === 'json-full-compact') {\n const indent = format === 'json-full-compact' || compact ? 0 : 2;\n console.log(JSON.stringify(envGraph.getSerializedGraph(), null, indent));\n } else if (format === 'env') {\n const resolvedEnv = envGraph.getResolvedEnvObject();\n const skipUndefined = compact === true;\n\n for (const key in resolvedEnv) {\n const value = resolvedEnv[key];\n\n if (value === undefined && skipUndefined) {\n continue;\n }\n\n let strValue: string;\n if (value === undefined) {\n strValue = '';\n } else if (typeof value === 'string') {\n strValue = `\"${value.replaceAll('\"', '\\\\\"').replaceAll('\\n', '\\\\n')}\"`;\n } else {\n strValue = JSON.stringify(value);\n }\n console.log(`${key}=${strValue}`);\n }\n } else {\n throw new Error(`Unknown format: ${format}`);\n }\n\n // const resolvedEnv = envGraph.getResolvedEnvObject();\n // console.log(resolvedEnv);\n};\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/cli/helpers/error-checks.ts","../src/lib/load-graph.ts"],"names":[],"mappings":";;;;AAQA,SAAS,yBAAyB,GAAA,EAAY;AAC5C,EAAA,IAAI,EAAE,GAAA,YAAe,YAAA,CAAA,IAAiB,CAAC,IAAI,QAAA,EAAU;AACrD,EAAA,MAAM,SAAS,GAAA,CAAI,QAAA;AACnB,EAAA,MAAM,UAAA,GAAa;AAAA,IACjB,MAAA,CAAO,OAAA;AAAA,IACP,CAAA,EAAG,aAAA,CAAM,IAAA,CAAK,GAAA,CAAI,OAAO,MAAA,CAAO,SAAA,GAAY,CAAC,CAAC,CAAC,CAAA,EAAG,aAAA,CAAM,GAAA,CAAI,GAAG,CAAC,CAAA;AAAA,GAClE,CAAE,KAAK,IAAI,CAAA;AAEX,EAAA,OAAA,CAAQ,IAAI,EAAE,CAAA;AACd,EAAA,OAAA,CAAQ,GAAA,CAAI,CAAA,UAAA,EAAM,MAAA,CAAO,EAAE,CAAA,CAAA,EAAI,OAAO,UAAU,CAAA,CAAA,EAAI,MAAA,CAAO,SAAS,CAAA,CAAE,CAAA;AACtE,EAAA,OAAA,CAAQ,IAAI,UAAU,CAAA;AACxB;AAXS,MAAA,CAAA,wBAAA,EAAA,0BAAA,CAAA;AAaF,SAAS,qBAAqB,QAAA,EAAoB;AAEvD,EAAA,KAAA,MAAW,MAAA,IAAU,SAAS,iBAAA,EAAmB;AAK/C,IAAA,IAAI,OAAO,YAAA,EAAc;AACvB,MAAA,OAAA,CAAQ,GAAA,CAAI,CAAA,0CAAA,EAAsC,MAAA,CAAO,KAAK;AAAA,CAAI,CAAA;AAElE,MAAA,OAAA,CAAQ,GAAA,CAAI,MAAA,CAAO,YAAA,CAAa,OAAO,CAAA;AACvC,MAAA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AAC,CAAA;AAAA,MACpC,CAAC,CAAA;AAAA,IACH;AAEA,IAAA,MAAM,IAAI,eAAA,EAAgB;AAAA,EAC5B;AACF;AA3CgB,MAAA,CAAA,oBAAA,EAAA,sBAAA,CAAA;;;AChEhB,eAAsB,oBAAoB,IAAA,EAGvC;AACD,EAAA,MAAM,QAAA,GAAW,MAAM,YAAA,CAAa;AAAA,IAClC,GAAG,IAAA;AAAA,IACH,SAAA,gCAAkB,EAAA,KAAO;AAAA,IAEzB,CAAA,EAFW,WAAA;AAAA,GAGZ,CAAA;AAED,EAAA,OAAO,QAAA;AACT;AAZsB,MAAA,CAAA,mBAAA,EAAA,qBAAA,CAAA","file":"chunk-NDWB3TT5.js","sourcesContent":["import ansis from 'ansis';\nimport { gracefulExit } from 'exit-hook';\nimport _ from '@env-spec/utils/my-dash';\nimport { EnvGraph, ConfigItem } from '../../env-graph';\nimport { getItemSummary, joinAndCompact } from '../../lib/formatting';\nimport { VarlockError } from '../../env-graph/lib/errors';\n\n\nfunction showErrorLocationDetails(err: Error) {\n if (!(err instanceof VarlockError) || !err.location) return;\n const errLoc = err.location;\n const errPreview = [\n errLoc.lineStr,\n `${ansis.gray('-'.repeat(errLoc.colNumber - 1))}${ansis.red('^')}`,\n ].join('\\n');\n\n console.log('');\n console.log(`📂 ${errLoc.id}:${errLoc.lineNumber}:${errLoc.colNumber}`);\n console.log(errPreview);\n}\n\nexport function checkForSchemaErrors(envGraph: EnvGraph) {\n // first we check for loading/parse errors - some cases we may want to let it fail silently?\n for (const source of envGraph.sortedDataSources) {\n // do we care about loading errors from disabled sources?\n // if (source.disabled) continue;\n\n // TODO: use a formatting helper to show the error - which will include location/stack/etc appropriately\n if (source.loadingError) {\n console.log(`🚨 Error encountered while loading ${source.label}\\n`);\n\n console.log(source.loadingError.message);\n showErrorLocationDetails(source.loadingError);\n return gracefulExit(1);\n }\n // TODO: unify this with the above!\n if (source.schemaErrors.length) {\n console.log(`🚨 Error(s) encountered in ${source.label}`);\n\n for (const schemaErr of source.schemaErrors) {\n console.log(`- ${schemaErr.message}`);\n showErrorLocationDetails(schemaErr);\n }\n return gracefulExit(1);\n }\n }\n\n // now we check for any schema errors - where something about how things are wired up is invalid\n // NOTE - we should not have run any resolution yet\n // TODO: make sure we are calling this before attempting to resolve values\n // const failingItems = _.filter(_.values(envGraph.configSchema), (item) => item.validationState === 'error');\n // if (failingItems.length > 0) {\n // throw new CliExitError('Schema is currently invalid');\n // }\n}\n\n\nexport class InvalidEnvError extends Error {\n constructor() {\n super('Resolved config/env did not pass validation');\n }\n getFormattedOutput() {\n return `\\n💥 ${ansis.red(this.message)} 💥\\n`;\n }\n}\n\nexport function checkForConfigErrors(envGraph: EnvGraph, opts?: {\n showAll?: boolean\n}) {\n // check for root decorator \"execution\"\n for (const source of envGraph.sortedDataSources) {\n if (source.resolutionErrors.length) {\n console.log(`🚨 Root decorator error(s) in ${source.label}`);\n\n for (const err of source.resolutionErrors) {\n console.log(`- ${err.message}`);\n showErrorLocationDetails(err);\n }\n }\n }\n\n\n\n const failingItems = _.filter(_.values(envGraph.configSchema), (item: ConfigItem) => item.validationState === 'error');\n\n // TODO: use service.isValid?\n if (failingItems.length > 0) {\n console.error(`\\n🚨 🚨 🚨 ${ansis.bold.underline('Configuration is currently invalid ')} 🚨 🚨 🚨\\n`);\n console.error('Invalid items:\\n');\n\n _.each(failingItems, (item: ConfigItem) => {\n console.error(getItemSummary(item));\n console.error();\n });\n if (opts?.showAll) {\n console.error();\n console.error(joinAndCompact([\n 'Valid items:',\n ansis.italic.gray('(remove `--show-all` flag to hide)'),\n ]));\n console.error();\n const validItems = _.filter(_.values(envGraph.configSchema), (i: ConfigItem) => !!i.isValid);\n _.each(validItems, (item: ConfigItem) => {\n console.error(getItemSummary(item));\n });\n }\n\n throw new InvalidEnvError();\n }\n}\n","import { loadEnvGraph } from '../env-graph';\n\nexport async function loadVarlockEnvGraph(opts?: {\n currentEnvFallback?: string,\n entryFilePath?: string,\n}) {\n const envGraph = await loadEnvGraph({\n ...opts,\n afterInit: async (_g) => {\n // TODO: register varlock resolver\n },\n });\n\n return envGraph;\n}\n"]}
|
package/dist/chunk-NHA2P5AV.js
DELETED
|
@@ -1,135 +0,0 @@
|
|
|
1
|
-
import { define } from './chunk-33ROL4J5.js';
|
|
2
|
-
import { loadVarlockEnvGraph, checkForSchemaErrors, checkForConfigErrors } from './chunk-NDWB3TT5.js';
|
|
3
|
-
import { gracefulExit } from './chunk-OKNWYS57.js';
|
|
4
|
-
import { resetRedactionMap, redactSensitiveConfig } from './chunk-MSRPV5WH.js';
|
|
5
|
-
import { __name } from './chunk-XN24GZXQ.js';
|
|
6
|
-
import { execa } from 'execa';
|
|
7
|
-
import which from 'which';
|
|
8
|
-
|
|
9
|
-
var commandSpec = define({
|
|
10
|
-
name: "run",
|
|
11
|
-
description: "Run a command with your environment variables injected",
|
|
12
|
-
args: {
|
|
13
|
-
// watch: {
|
|
14
|
-
// type: 'boolean',
|
|
15
|
-
// short: 'w',
|
|
16
|
-
// description: 'Watch mode',
|
|
17
|
-
// },
|
|
18
|
-
"no-redact-stdout": {
|
|
19
|
-
type: "boolean",
|
|
20
|
-
description: "Disable stdout/stderr redaction to preserve TTY detection for interactive tools"
|
|
21
|
-
},
|
|
22
|
-
path: {
|
|
23
|
-
type: "string",
|
|
24
|
-
short: "p",
|
|
25
|
-
description: "Path to a specific .env file or directory (with trailing slash) to use as the entry point"
|
|
26
|
-
}
|
|
27
|
-
},
|
|
28
|
-
examples: `
|
|
29
|
-
Executes a command in a child process, injecting your resolved and validated environment
|
|
30
|
-
variables from your .env files. Useful when a code-level integration is not possible.
|
|
31
|
-
|
|
32
|
-
Examples:
|
|
33
|
-
varlock run -- node app.js # Run a Node.js application
|
|
34
|
-
varlock run -- python script.py # Run a Python script
|
|
35
|
-
varlock run -- sh -c 'echo $MY_VAR' # Use shell expansion for env vars
|
|
36
|
-
varlock run --no-redact-stdout -- psql # Preserve TTY for interactive tools
|
|
37
|
-
varlock run --path .env.prod -- node app.js # Use a specific .env file
|
|
38
|
-
varlock run --path ./config/ -- node app.js # Use a specific directory
|
|
39
|
-
|
|
40
|
-
\u{1F4CD} Important: Use -- to separate varlock options from your command
|
|
41
|
-
|
|
42
|
-
\u{1F4A1} Tip: For shell expansion of env vars, use: sh -c 'your command here'
|
|
43
|
-
\u{1F4A1} Tip: Use --no-redact-stdout for interactive tools (psql, claude, etc.)
|
|
44
|
-
`.trim()
|
|
45
|
-
});
|
|
46
|
-
var commandProcess;
|
|
47
|
-
var childCommandKilledFromRestart = false;
|
|
48
|
-
var commandFn = /* @__PURE__ */ __name(async (ctx) => {
|
|
49
|
-
const argv = process.argv.slice(2);
|
|
50
|
-
let restCommandArgs = [];
|
|
51
|
-
if (argv.includes("--")) {
|
|
52
|
-
const doubleDashIndex = argv.indexOf("--");
|
|
53
|
-
restCommandArgs = argv.slice(doubleDashIndex + 1);
|
|
54
|
-
} else {
|
|
55
|
-
throw new Error("No command to run! Your command should look like `varlock run -- <your-command>`");
|
|
56
|
-
}
|
|
57
|
-
const commandToRunAsArgs = restCommandArgs;
|
|
58
|
-
const commandToRunStr = restCommandArgs.join(" ");
|
|
59
|
-
const rawCommand = commandToRunAsArgs[0];
|
|
60
|
-
const commandArgsOnly = commandToRunAsArgs.slice(1);
|
|
61
|
-
const pathAwareCommand = which.sync(rawCommand, { nothrow: true });
|
|
62
|
-
const envGraph = await loadVarlockEnvGraph({
|
|
63
|
-
entryFilePath: ctx.values.path
|
|
64
|
-
});
|
|
65
|
-
checkForSchemaErrors(envGraph);
|
|
66
|
-
await envGraph.resolveEnvValues();
|
|
67
|
-
checkForConfigErrors(envGraph);
|
|
68
|
-
const resolvedEnv = envGraph.getResolvedEnvObject();
|
|
69
|
-
const serializedGraph = envGraph.getSerializedGraph();
|
|
70
|
-
const fullInjectedEnv = {
|
|
71
|
-
...process.env,
|
|
72
|
-
...resolvedEnv,
|
|
73
|
-
__VARLOCK_RUN: "1",
|
|
74
|
-
// flag for a child process to detect it is runnign via `varlock run`
|
|
75
|
-
__VARLOCK_ENV: JSON.stringify(serializedGraph)
|
|
76
|
-
};
|
|
77
|
-
const redactLogs = serializedGraph.settings?.redactLogs ?? true;
|
|
78
|
-
const noRedactStdout = ctx.values["no-redact-stdout"] ?? false;
|
|
79
|
-
if (redactLogs) {
|
|
80
|
-
resetRedactionMap(serializedGraph);
|
|
81
|
-
}
|
|
82
|
-
if (noRedactStdout) {
|
|
83
|
-
commandProcess = execa(pathAwareCommand || rawCommand, commandArgsOnly, {
|
|
84
|
-
stdio: "inherit",
|
|
85
|
-
env: fullInjectedEnv
|
|
86
|
-
});
|
|
87
|
-
} else {
|
|
88
|
-
const writeRedacted = /* @__PURE__ */ __name((stream, chunk) => {
|
|
89
|
-
const str = chunk.toString();
|
|
90
|
-
stream.write(redactLogs ? redactSensitiveConfig(str) : str);
|
|
91
|
-
}, "writeRedacted");
|
|
92
|
-
commandProcess = execa(pathAwareCommand || rawCommand, commandArgsOnly, {
|
|
93
|
-
stdin: "inherit",
|
|
94
|
-
stdout: "pipe",
|
|
95
|
-
stderr: "pipe",
|
|
96
|
-
env: fullInjectedEnv
|
|
97
|
-
});
|
|
98
|
-
commandProcess.stdout?.on("data", (chunk) => writeRedacted(process.stdout, chunk));
|
|
99
|
-
commandProcess.stderr?.on("data", (chunk) => writeRedacted(process.stderr, chunk));
|
|
100
|
-
}
|
|
101
|
-
{
|
|
102
|
-
process.on("exit", (_code, _signal) => {
|
|
103
|
-
commandProcess?.kill(9);
|
|
104
|
-
});
|
|
105
|
-
["SIGTERM", "SIGINT"].forEach((signal) => {
|
|
106
|
-
process.on(signal, () => {
|
|
107
|
-
commandProcess?.kill(9);
|
|
108
|
-
gracefulExit(1);
|
|
109
|
-
});
|
|
110
|
-
});
|
|
111
|
-
}
|
|
112
|
-
let exitCode;
|
|
113
|
-
try {
|
|
114
|
-
const commandResult = await commandProcess;
|
|
115
|
-
exitCode = commandResult.exitCode;
|
|
116
|
-
} catch (error) {
|
|
117
|
-
if (error.signal === "SIGINT" && childCommandKilledFromRestart) ;
|
|
118
|
-
if (error.signal === "SIGINT" || error.signal === "SIGKILL") {
|
|
119
|
-
gracefulExit(1);
|
|
120
|
-
} else {
|
|
121
|
-
console.log(error.message);
|
|
122
|
-
console.log(`command [${commandToRunStr}] failed`);
|
|
123
|
-
console.log("try running the same command without dmno");
|
|
124
|
-
console.log("if you get a different result, dmno may be the problem...");
|
|
125
|
-
}
|
|
126
|
-
exitCode = error.exitCode || 1;
|
|
127
|
-
}
|
|
128
|
-
{
|
|
129
|
-
return gracefulExit(exitCode);
|
|
130
|
-
}
|
|
131
|
-
}, "commandFn");
|
|
132
|
-
|
|
133
|
-
export { commandFn, commandSpec };
|
|
134
|
-
//# sourceMappingURL=chunk-NHA2P5AV.js.map
|
|
135
|
-
//# sourceMappingURL=chunk-NHA2P5AV.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/cli/commands/run.command.ts"],"names":[],"mappings":";;;;;;;;AAWO,IAAM,cAAc,MAAA,CAAO;AAAA,EAChC,IAAA,EAAM,KAAA;AAAA,EACN,WAAA,EAAa,wDAAA;AAAA,EACb,IAAA,EAAM;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAMJ,kBAAA,EAAoB;AAAA,MAClB,IAAA,EAAM,SAAA;AAAA,MACN,WAAA,EAAa;AAAA,KACf;AAAA,IACA,IAAA,EAAM;AAAA,MACJ,IAAA,EAAM,QAAA;AAAA,MACN,KAAA,EAAO,GAAA;AAAA,MACP,WAAA,EAAa;AAAA;AACf,GACF;AAAA,EACA,QAAA,EAAU;AAAA;AAAA;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;AAAA;;AAAA;AAAA;AAAA,EAAA,CAAA,CAgBR,IAAA;AACJ,CAAC;AAED,IAAI,cAAA;AACJ,IAAI,6BAAA,GAAgC,KAAA;AAG7B,IAAM,SAAA,iCAA6D,GAAA,KAAQ;AAEhF,EAAA,MAAM,IAAA,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KAAiB;AAM/C,MAAA,cAAA,EAAgB,KAAK,CAAC,CAAA;AAAA,IACxB,CAAC,CAAA;AAED,IAAA,CAAC,SAAA,EAAW,QAAQ,CAAA,CAAE,OAAA,CAAQ,CAAC,MAAA,KAAW;AACxC,MAAA,OAAA,CAAQ,EAAA,CAAG,QAAQ,MAAM;AAEvB,QAAA,cAAA,EAAgB,KAAK,CAAC,CAAA;AACtB,QAAA,YAAA,CAAa,CAAC,CAAA;AAAA,MAChB,CAAC,CAAA;AAAA,IACH,CAAC,CAAA;AAAA,EAEH;AAGA,EAAA,IAAI,QAAA;AACJ,EAAA,IAAI;AACF,IAAA,MAAM,gBAAgB,MAAM,cAAA;AAC5B,IAAA,QAAA,GAAW,aAAA,CAAc,QAAA;AAAA,EAC3B,SAAS,KAAA,EAAO;AAEd,IAAA,IAAK,KAAA,CAAc,MAAA,KAAW,QAAA,IAAY,6BAAA,EAA+B;AAOzE,IAAA,IAAK,KAAA,CAAc,MAAA,KAAW,QAAA,IAAa,KAAA,CAAc,WAAW,SAAA,EAAW;AAC7E,MAAA,YAAA,CAAa,CAAC,CAAA;AAAA,IAChB,CAAA,MAAO;AACL,MAAA,OAAA,CAAQ,GAAA,CAAK,MAAgB,OAAO,CAAA;AACpC,MAAA,OAAA,CAAQ,GAAA,CAAI,CAAA,SAAA,EAAY,eAAe,CAAA,QAAA,CAAU,CAAA;AACjD,MAAA,OAAA,CAAQ,IAAI,2CAA2C,CAAA;AACvD,MAAA,OAAA,CAAQ,IAAI,2DAA2D,CAAA;AAAA,IAEzE;AACA,IAAA,QAAA,GAAY,MAAc,QAAA,IAAY,CAAA;AAAA,EACxC;AAYA,EAAqB;AACnB,IAAA,OAAO,aAAa,QAAQ,CAAA;AAAA,EAC9B;AAGF,CAAA,EA/ImE,WAAA","file":"chunk-NHA2P5AV.js","sourcesContent":["import { execa, type ResultPromise } from 'execa';\nimport which from 'which';\nimport { define } from 'gunshi';\nimport { gracefulExit } from 'exit-hook';\n\nimport { loadVarlockEnvGraph } from '../../lib/load-graph';\nimport { checkForConfigErrors, checkForSchemaErrors } from '../helpers/error-checks';\nimport { type TypedGunshiCommandFn } from '../helpers/gunshi-type-utils';\nimport { resetRedactionMap, redactSensitiveConfig } from '../../runtime/env';\n\n\nexport const commandSpec = define({\n name: 'run',\n description: 'Run a command with your environment variables injected',\n args: {\n // watch: {\n // type: 'boolean',\n // short: 'w',\n // description: 'Watch mode',\n // },\n 'no-redact-stdout': {\n type: 'boolean',\n description: 'Disable stdout/stderr redaction to preserve TTY detection for interactive tools',\n },\n path: {\n type: 'string',\n short: 'p',\n description: 'Path to a specific .env file or directory (with trailing slash) to use as the entry point',\n },\n },\n examples: `\nExecutes a command in a child process, injecting your resolved and validated environment\nvariables from your .env files. Useful when a code-level integration is not possible.\n\nExamples:\n varlock run -- node app.js # Run a Node.js application\n varlock run -- python script.py # Run a Python script\n varlock run -- sh -c 'echo $MY_VAR' # Use shell expansion for env vars\n varlock run --no-redact-stdout -- psql # Preserve TTY for interactive tools\n varlock run --path .env.prod -- node app.js # Use a specific .env file\n varlock run --path ./config/ -- node app.js # Use a specific directory\n\n📍 Important: Use -- to separate varlock options from your command\n\n💡 Tip: For shell expansion of env vars, use: sh -c 'your command here'\n💡 Tip: Use --no-redact-stdout for interactive tools (psql, claude, etc.)\n `.trim(),\n});\n\nlet commandProcess: ResultPromise | undefined;\nlet childCommandKilledFromRestart = false;\nconst isWatchModeRestart = false; // TODO: re-enable watch mode\n\nexport const commandFn: TypedGunshiCommandFn<typeof commandSpec> = async (ctx) => {\n // if \"--\" is present, split the args into our command and the rest, which will be another external command\n const argv = process.argv.slice(2);\n let restCommandArgs: Array<string> = [];\n if (argv.includes('--')) {\n const doubleDashIndex = argv.indexOf('--');\n restCommandArgs = argv.slice(doubleDashIndex + 1);\n } else {\n throw new Error('No command to run! Your command should look like `varlock run -- <your-command>`');\n }\n const commandToRunAsArgs = restCommandArgs;\n const commandToRunStr = restCommandArgs.join(' ');\n\n const rawCommand = commandToRunAsArgs[0];\n const commandArgsOnly = commandToRunAsArgs.slice(1);\n const pathAwareCommand = which.sync(rawCommand, { nothrow: true });\n\n // const isWatchEnabled = ctx.values.watch;\n const isWatchEnabled = false;\n\n // console.log('running command', pathAwareCommand || rawCommand, commandArgsOnly);\n\n\n const envGraph = await loadVarlockEnvGraph({\n entryFilePath: ctx.values.path,\n });\n checkForSchemaErrors(envGraph);\n await envGraph.resolveEnvValues();\n checkForConfigErrors(envGraph);\n\n // will fail above if there are any errors\n\n const resolvedEnv = envGraph.getResolvedEnvObject();\n const serializedGraph = envGraph.getSerializedGraph();\n // console.log(resolvedEnv);\n\n // needs more thought here\n const fullInjectedEnv = {\n ...process.env,\n ...resolvedEnv,\n __VARLOCK_RUN: '1', // flag for a child process to detect it is runnign via `varlock run`\n __VARLOCK_ENV: JSON.stringify(serializedGraph),\n };\n\n const redactLogs = serializedGraph.settings?.redactLogs ?? true;\n const noRedactStdout = ctx.values['no-redact-stdout'] ?? false;\n\n // Initialize the redaction map if redaction is enabled\n if (redactLogs) {\n resetRedactionMap(serializedGraph);\n }\n\n // When --no-redact-stdout is set, use stdio: 'inherit' to preserve TTY detection\n // Otherwise, pipe stdout/stderr through redaction\n if (noRedactStdout) {\n commandProcess = execa(pathAwareCommand || rawCommand, commandArgsOnly, {\n stdio: 'inherit',\n env: fullInjectedEnv,\n });\n } else {\n // Helper to redact and write output\n const writeRedacted = (stream: NodeJS.WriteStream, chunk: Buffer | string) => {\n const str = chunk.toString();\n stream.write(redactLogs ? redactSensitiveConfig(str) : str);\n };\n\n commandProcess = execa(pathAwareCommand || rawCommand, commandArgsOnly, {\n stdin: 'inherit',\n stdout: 'pipe',\n stderr: 'pipe',\n env: fullInjectedEnv,\n });\n\n // Pipe stdout and stderr through redaction\n commandProcess.stdout?.on('data', (chunk) => writeRedacted(process.stdout, chunk));\n commandProcess.stderr?.on('data', (chunk) => writeRedacted(process.stderr, chunk));\n }\n // console.log('PARENT PID = ', process.pid);\n // console.log('CHILD PID = ', commandProcess.pid);\n\n // if first run, we need to attach some extra exit handling\n if (!isWatchModeRestart) {\n // try to make sure we shut down cleanly and kill the child process\n process.on('exit', (_code: any, _signal: any) => {\n // if (childCommandKilledFromRestart) {\n // childCommandKilledFromRestart = false;\n // return;\n // }\n // console.log('exit!', code, signal);\n commandProcess?.kill(9);\n });\n\n ['SIGTERM', 'SIGINT'].forEach((signal) => {\n process.on(signal, () => {\n // console.log('SIGNAL = ', signal);\n commandProcess?.kill(9);\n gracefulExit(1);\n });\n });\n // TODO: handle other signals?\n }\n\n\n let exitCode: any; // TODO: fix this any\n try {\n const commandResult = await commandProcess;\n exitCode = commandResult.exitCode;\n } catch (error) {\n // console.log('child command error!', error);\n if ((error as any).signal === 'SIGINT' && childCommandKilledFromRestart) {\n // console.log('child command failed due to being killed form restart');\n childCommandKilledFromRestart = false;\n return;\n }\n\n // console.log('child command result error', error);\n if ((error as any).signal === 'SIGINT' || (error as any).signal === 'SIGKILL') {\n gracefulExit(1);\n } else {\n console.log((error as Error).message);\n console.log(`command [${commandToRunStr}] failed`);\n console.log('try running the same command without dmno');\n console.log('if you get a different result, dmno may be the problem...');\n // console.log(`Please report issue here: <${REPORT_ISSUE_LINK}>`);\n }\n exitCode = (error as any).exitCode || 1;\n }\n\n if (isWatchEnabled) {\n if (!childCommandKilledFromRestart) {\n if (exitCode === 0) {\n console.log('\\n✅ command completed successfully');\n } else {\n console.log(`\\n💥 command failed - exit code = ${exitCode}`);\n }\n }\n }\n\n if (!isWatchEnabled) {\n return gracefulExit(exitCode);\n } else {\n console.log('... watching for changes ...');\n }\n};\n"]}
|