varlock 0.0.12 → 0.0.14

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.
Files changed (58) hide show
  1. package/dist/auto-load.js +3 -3
  2. package/dist/{chunk-23GW4X5J.js → chunk-4QTFFYV6.js} +16 -5
  3. package/dist/chunk-4QTFFYV6.js.map +1 -0
  4. package/dist/{chunk-POJECYSY.js → chunk-7JMYT62X.js} +3 -3
  5. package/dist/chunk-7JMYT62X.js.map +1 -0
  6. package/dist/{chunk-UPKIHHPE.js → chunk-C5BEZMSO.js} +2 -2
  7. package/dist/{chunk-UPKIHHPE.js.map → chunk-C5BEZMSO.js.map} +1 -1
  8. package/dist/{chunk-MHDV65DI.js → chunk-EQQCW3OI.js} +98 -66
  9. package/dist/chunk-EQQCW3OI.js.map +1 -0
  10. package/dist/{chunk-NXAXPMO5.js → chunk-FCVBOYES.js} +484 -244
  11. package/dist/chunk-FCVBOYES.js.map +1 -0
  12. package/dist/{chunk-2GR4YQFJ.js → chunk-HGJF2DUO.js} +4 -5
  13. package/dist/chunk-HGJF2DUO.js.map +1 -0
  14. package/dist/{chunk-LBVGWRPL.js → chunk-J5SIYSJV.js} +4 -4
  15. package/dist/{chunk-LBVGWRPL.js.map → chunk-J5SIYSJV.js.map} +1 -1
  16. package/dist/{chunk-52FLZJCQ.js → chunk-OJFTFBQG.js} +5 -24
  17. package/dist/chunk-OJFTFBQG.js.map +1 -0
  18. package/dist/{chunk-IBMSAOL6.js → chunk-QCKADJNV.js} +21 -15
  19. package/dist/chunk-QCKADJNV.js.map +1 -0
  20. package/dist/{chunk-AMAUWR7O.js → chunk-UPOIK25P.js} +4 -4
  21. package/dist/{chunk-AMAUWR7O.js.map → chunk-UPOIK25P.js.map} +1 -1
  22. package/dist/{chunk-TWKAUCTT.js → chunk-ZYL5D2UA.js} +4 -4
  23. package/dist/{chunk-TWKAUCTT.js.map → chunk-ZYL5D2UA.js.map} +1 -1
  24. package/dist/cli/cli-executable.js +14 -15
  25. package/dist/cli/cli-executable.js.map +1 -1
  26. package/dist/dotenv-compat.js +3 -3
  27. package/dist/{env-DxiD5Ylz.d.ts → env-DLUhFCnC.d.ts} +97 -63
  28. package/dist/index.d.ts +2 -3
  29. package/dist/index.js +4 -6
  30. package/dist/index.js.map +1 -1
  31. package/dist/init.command-VK4OGIYP.js +8 -0
  32. package/dist/{init.command-ZSH7NCV7.js.map → init.command-VK4OGIYP.js.map} +1 -1
  33. package/dist/load.command-N7FMBREX.js +8 -0
  34. package/dist/{load.command-U2GASZRB.js.map → load.command-N7FMBREX.js.map} +1 -1
  35. package/dist/login.command-GQCJY4NK.js +8 -0
  36. package/dist/{login.command-2WG4GZV4.js.map → login.command-GQCJY4NK.js.map} +1 -1
  37. package/dist/run.command-LYY2M5AP.js +8 -0
  38. package/dist/{run.command-IETNJ6UU.js.map → run.command-LYY2M5AP.js.map} +1 -1
  39. package/dist/runtime/env.d.ts +1 -1
  40. package/dist/runtime/patch-console.js +1 -1
  41. package/dist/runtime/patch-server-response.js +1 -1
  42. package/dist/telemetry.command-QTEDXKIG.js +8 -0
  43. package/dist/{telemetry.command-US72HXMS.js.map → telemetry.command-QTEDXKIG.js.map} +1 -1
  44. package/package.json +2 -2
  45. package/dist/chunk-23GW4X5J.js.map +0 -1
  46. package/dist/chunk-2GR4YQFJ.js.map +0 -1
  47. package/dist/chunk-52FLZJCQ.js.map +0 -1
  48. package/dist/chunk-IBMSAOL6.js.map +0 -1
  49. package/dist/chunk-MHDV65DI.js.map +0 -1
  50. package/dist/chunk-NXAXPMO5.js.map +0 -1
  51. package/dist/chunk-POJECYSY.js.map +0 -1
  52. package/dist/chunk-Y2EGAWAH.js +0 -17
  53. package/dist/chunk-Y2EGAWAH.js.map +0 -1
  54. package/dist/init.command-ZSH7NCV7.js +0 -9
  55. package/dist/load.command-U2GASZRB.js +0 -9
  56. package/dist/login.command-2WG4GZV4.js +0 -8
  57. package/dist/run.command-IETNJ6UU.js +0 -9
  58. package/dist/telemetry.command-US72HXMS.js +0 -8
package/dist/auto-load.js CHANGED
@@ -1,7 +1,7 @@
1
- import './chunk-TWKAUCTT.js';
2
- import './chunk-UPKIHHPE.js';
1
+ import './chunk-ZYL5D2UA.js';
2
+ import './chunk-C5BEZMSO.js';
3
3
  import './chunk-OM3JCP4E.js';
4
- import './chunk-POJECYSY.js';
4
+ import './chunk-7JMYT62X.js';
5
5
  import './chunk-2SPIWTVE.js';
6
6
  import './chunk-FGMXIEFA.js';
7
7
  import './chunk-XN24GZXQ.js';
@@ -1,9 +1,9 @@
1
- import { ansis_default, gracefulExit, my_dash_default, getItemSummary, joinAndCompact } from './chunk-NXAXPMO5.js';
1
+ import { ansis_default, gracefulExit, my_dash_default, getItemSummary, joinAndCompact, loadEnvGraph } from './chunk-FCVBOYES.js';
2
2
  import { __name } from './chunk-XN24GZXQ.js';
3
3
 
4
4
  // src/cli/helpers/error-checks.ts
5
5
  function checkForSchemaErrors(envGraph) {
6
- for (const source of envGraph.dataSources) {
6
+ for (const source of envGraph.sortedDataSources) {
7
7
  if (source.loadingError) {
8
8
  console.log(`\u{1F6A8} Error encountered while loading ${source.label}`);
9
9
  console.log(source.loadingError.message);
@@ -64,6 +64,17 @@ function checkForConfigErrors(envGraph, opts) {
64
64
  }
65
65
  __name(checkForConfigErrors, "checkForConfigErrors");
66
66
 
67
- export { InvalidEnvError, checkForConfigErrors, checkForSchemaErrors };
68
- //# sourceMappingURL=chunk-23GW4X5J.js.map
69
- //# sourceMappingURL=chunk-23GW4X5J.js.map
67
+ // src/lib/load-graph.ts
68
+ async function loadVarlockEnvGraph(opts) {
69
+ const envGraph = await loadEnvGraph({
70
+ ...opts,
71
+ afterInit: /* @__PURE__ */ __name(async (_g) => {
72
+ }, "afterInit")
73
+ });
74
+ return envGraph;
75
+ }
76
+ __name(loadVarlockEnvGraph, "loadVarlockEnvGraph");
77
+
78
+ export { InvalidEnvError, checkForConfigErrors, checkForSchemaErrors, loadVarlockEnvGraph };
79
+ //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AAA,CAAQ,GAAA,EAAI;AACZ,MAAA,MAAM,UAAA,GAAa,eAAA,CAAE,MAAA,CAAO,eAAA,CAAE,MAAA,CAAO,QAAA,CAAS,YAAY,CAAA,EAAG,CAAC,CAAA,KAAkB,CAAC,CAAC,EAAE,OAAO,CAAA;AAC3F,MAAA,eAAA,CAAE,IAAA,CAAK,UAAA,EAAY,CAAC,IAAA,KAAqB;AACvC,QAAA,OAAA,CAAQ,GAAA,CAAI,cAAA,CAAe,IAAI,CAAC,CAAA;AAAA,MAClC,CAAC,CAAA;AAAA,IACH;AAEA,IAAA,MAAM,IAAI,eAAA,EAAgB;AAAA,EAC5B;AACF;AA7BgB,MAAA,CAAA,oBAAA,EAAA,sBAAA,CAAA;;;ACvDhB,eAAsB,oBAAoB,IAAA,EAEvC;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;AAXsB,MAAA,CAAA,mBAAA,EAAA,qBAAA,CAAA","file":"chunk-4QTFFYV6.js","sourcesContent":["import ansis from 'ansis';\nimport { EnvGraph, ConfigItem, EnvSourceParseError } from '../../../env-graph';\nimport _ from '@env-spec/utils/my-dash';\nimport { getItemSummary, joinAndCompact } from '../../lib/formatting';\nimport { gracefulExit } from 'exit-hook';\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 // console.log(source);\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 console.log(source.loadingError.message);\n\n // Check if the error has a location property (like EnvSourceParseError)\n if ('location' in source.loadingError) {\n console.log((source.loadingError as EnvSourceParseError).location);\n\n const errLoc = (source.loadingError as EnvSourceParseError).location;\n\n const errPreview = [\n errLoc.lineStr,\n `${ansis.gray('-'.repeat(errLoc.colNumber - 1))}${ansis.red('^')}`,\n ].join('\\n');\n\n console.log('Error parsing .env file');\n console.log(` ${errLoc.path}:${errLoc.lineNumber}:${errLoc.colNumber}`);\n console.log(errPreview);\n }\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\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 const failingItems = _.filter(_.values(envGraph.configSchema), (item: ConfigItem) => item.validationState === 'error');\n\n // TODO: use service.isValid?\n if (failingItems.length > 0) {\n console.log(`\\n🚨 🚨 🚨 ${ansis.bold.underline('Configuration is currently invalid ')} 🚨 🚨 🚨\\n`);\n console.log('Invalid items:\\n');\n\n _.each(failingItems, (item: ConfigItem) => {\n console.log(getItemSummary(item));\n console.log();\n });\n if (opts?.showAll) {\n console.log();\n console.log(joinAndCompact([\n 'Valid items:',\n ansis.italic.gray('(remove `--show-all` flag to hide)'),\n ]));\n console.log();\n const validItems = _.filter(_.values(envGraph.configSchema), (i: ConfigItem) => !!i.isValid);\n _.each(validItems, (item: ConfigItem) => {\n console.log(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}) {\n const envGraph = await loadEnvGraph({\n ...opts,\n afterInit: async (_g) => {\n // TODO: register varlock resolver\n },\n });\n\n return envGraph;\n}\n"]}
@@ -19,7 +19,7 @@ function patchGlobalServerResponse(opts) {
19
19
  ServerResponse.prototype.write = /* @__PURE__ */ __name(function varlockPatchedServerResponseWrite(...args) {
20
20
  const rawChunk = args[0];
21
21
  const contentType = this.getHeader("content-type")?.toString() || "";
22
- let runScan = contentType.startsWith("text/") || contentType.startsWith("application/json");
22
+ let runScan = contentType.startsWith("text/") || contentType.startsWith("application/json") || !contentType && typeof rawChunk === "string";
23
23
  const reqUrl = this.req.url;
24
24
  if (runScan && reqUrl && opts?.ignoreUrlPatterns?.some((pattern) => pattern.test(reqUrl))) {
25
25
  runScan = false;
@@ -88,5 +88,5 @@ function patchGlobalServerResponse(opts) {
88
88
  __name(patchGlobalServerResponse, "patchGlobalServerResponse");
89
89
 
90
90
  export { patchGlobalServerResponse };
91
- //# sourceMappingURL=chunk-POJECYSY.js.map
92
- //# sourceMappingURL=chunk-POJECYSY.js.map
91
+ //# sourceMappingURL=chunk-7JMYT62X.js.map
92
+ //# sourceMappingURL=chunk-7JMYT62X.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/runtime/patch-server-response.ts"],"names":[],"mappings":";;;;;AAUA,IAAM,UAAA,GAAa,mBAAA;AACZ,SAAS,0BAA0B,IAAA,EAGvC;AACD,EAAA,KAAA,CAAM,6CAAmC,CAAA;AACzC,EAAA,IAAI,MAAA,CAAO,wBAAA,CAAyB,cAAA,CAAe,SAAA,EAAW,UAAU,CAAA,EAAG;AACzE,IAAA,KAAA,CAAM,mBAAmB,CAAA;AACzB,IAAA;AAAA,EACF;AACA,EAAA,IAAI,eAAA,CAAgB,iBAAiB,KAAA,EAAO;AAC1C,IAAA,KAAA,CAAM,wBAAwB,CAAA;AAC9B,IAAA;AAAA,EACF;AAEA,EAAA,MAAA,CAAO,eAAe,cAAA,CAAe,SAAA,EAAW,YAAY,EAAE,KAAA,EAAO,MAAM,CAAA;AAE3E,EAAA,MAAM,mBAAA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A,CAAK,CAAC,CAAA,GAAI,OAAA,CAAQ,MAAA,CAAO,QAAQ,CAAA;AAAA,UACnC,CAAA,MAAA,IAAW,cAAc,MAAA,EAAQ,CAQjC,MAAO;AACL,YAAA,MAAM,IAAI,KAAA,CAAM,CAAA,qCAAA,EAAwC,SAAS,CAAA,CAAE,CAAA;AAAA,UACrE;AAAA,QACF,CAAA,MAAO;AACL,UAAA,MAAM,GAAA;AAAA,QACR;AAAA,MACF;AAAA,IACF;AAGA,IAAA,OAAO,mBAAA,CAAoB,KAAA,CAAM,IAAA,EAAM,IAAI,CAAA;AAAA,EAC7C,CAAA,EAnGiC,mCAAA,CAAA;AAsGjC,EAAA,MAAM,iBAAA,GAAoB,eAAe,SAAA,CAAU,GAAA;AAEnD,EAAA,cAAA,CAAe,SAAA,CAAU,GAAA,mBAAM,MAAA,CAAA,SAAS,wBAAA,CAAA,GAA4B,IAAA,EAAM;AAExE,IAAA,MAAM,QAAA,GAAW,KAAK,CAAC,CAAA;AAEvB,IAAA,IAAI,QAAA,IAAY,OAAO,QAAA,KAAa,QAAA,EAAU;AAE5C,MAAA,YAAA,CAAa,QAAA,EAAU,EAAE,MAAA,EAAQ,4BAAA,EAA8B,CAAA;AAAA,IACjE;AAEA,IAAA,OAAO,iBAAA,CAAkB,KAAA,CAAM,IAAA,EAAM,IAAI,CAAA;AAAA,EAC3C,CAAA,EAV+B,0BAAA,CAAA;AAWjC;AAtIgB,MAAA,CAAA,yBAAA,EAAA,2BAAA,CAAA","file":"chunk-7JMYT62X.js","sourcesContent":["/*\n This patches the global ServerResponse object to scan for secret leaks - currently used for next.js and remix\n*/\n\nimport zlib from 'node:zlib';\nimport { ServerResponse } from 'node:http';\nimport { redactSensitiveConfig, scanForLeaks, varlockSettings } from './env';\nimport { debug } from './lib/debug';\n\n// NOTE - previously was using a symbol but got weird because of multiple builds and contexts...\nconst patchedKey = '_patchedByVarlock';\nexport function patchGlobalServerResponse(opts?: {\n ignoreUrlPatterns?: Array<RegExp>,\n redactInsteadOfThrow?: boolean,\n}) {\n debug('⚡️ PATCHING global ServerResponse');\n if (Object.getOwnPropertyDescriptor(ServerResponse.prototype, patchedKey)) {\n debug('> already patched');\n return;\n }\n if (varlockSettings.preventLeaks === false) {\n debug('> disabled by settings');\n return;\n }\n\n Object.defineProperty(ServerResponse.prototype, patchedKey, { value: true });\n\n const serverResponseWrite = ServerResponse.prototype.write;\n\n // @ts-ignore\n ServerResponse.prototype.write = function varlockPatchedServerResponseWrite(...args) {\n // TODO: do we want to filter out some requests here? maybe based on the file type?\n\n const rawChunk = args[0];\n // console.log('⚡️ patched ServerResponse.write', rawChunk);\n\n // for now, we only scan rendered html... may need to change this though for server components?\n // so we bail if it looks like this response does not contain html\n const contentType = this.getHeader('content-type')?.toString() || '';\n // console.log('patched ServerResponse.write', contentType);\n let runScan = (\n contentType.startsWith('text/')\n || contentType.startsWith('application/json')\n || (!contentType && typeof rawChunk === 'string')\n // || contentType.startsWith('application/javascript')\n );\n\n const reqUrl = (this as any).req.url;\n // console.log('> scan ServerResponse.write', contentType, reqUrl);\n if (runScan && reqUrl && opts?.ignoreUrlPatterns?.some((pattern) => pattern.test(reqUrl))) {\n runScan = false;\n }\n\n // we want to run the scanner on text/html and text/x-component (server actions)\n // TODO: anything else?\n if (!runScan) {\n // @ts-ignore\n return serverResponseWrite.apply(this, args);\n }\n\n // have to deal with compressed data, which is awkward but possible\n const compressionType = this.getHeader('Content-Encoding');\n let chunkStr;\n let chunkType: 'string' | 'encoded' | 'gzip' | null = null;\n if (typeof rawChunk === 'string') {\n chunkType = 'string';\n chunkStr = rawChunk;\n } else if (!compressionType) {\n chunkType = 'encoded';\n const decoder = new TextDecoder();\n chunkStr = decoder.decode(rawChunk);\n } else if (compressionType === 'gzip') {\n chunkType = 'gzip';\n // first chunk of data contains only compression headers\n if (!(this as any)._zlibChunks) {\n // (this as any)._zlibHeadersChunk = rawChunk;\n (this as any)._zlibChunks = [rawChunk];\n } else {\n // TODO: figure out how we can unzip one chunk at a time instead of storing everything\n (this as any)._zlibChunks?.push(rawChunk);\n try {\n const unzippedChunk = zlib.unzipSync(Buffer.concat((this as any)._zlibChunks || []), {\n flush: zlib.constants.Z_SYNC_FLUSH,\n finishFlush: zlib.constants.Z_SYNC_FLUSH,\n });\n const fullUnzippedData = unzippedChunk.toString('utf-8');\n chunkStr = fullUnzippedData.substring((this as any)._lastChunkEndIndex || 0);\n (this as any)._lastChunkEndIndex = fullUnzippedData.length;\n } catch (err) {\n // console.log('error unzipping chunk', err);\n }\n }\n }\n // TODO: we may want to support other compression schemes? but currently only used in nextjs which is using gzip\n if (chunkStr) {\n // console.log('scanning!', chunkStr.substring(0, 1000));\n\n\n try {\n scanForLeaks(chunkStr, { method: 'patched ServerResponse.write', file: (this as any).req.url });\n } catch (err) {\n // console.log('found secret in chunk', chunkType, chunkStr);\n // console.log(this)\n if (opts?.redactInsteadOfThrow) {\n chunkStr = redactSensitiveConfig(chunkStr);\n if (chunkType === 'string') {\n args[0] = chunkStr;\n } else if (chunkType === 'encoded') {\n const encoder = new TextEncoder();\n args[0] = encoder.encode(chunkStr);\n } else if (chunkType === 'gzip') {\n // currently unable to scrub gzip chunks\n // this works sometimes, but othertimes causes decoding error\n // we'll need to pass through chunks from a new gzip stream, because we don't have access to the underlying one\n // args[0] = zlib.gzipSync(chunkStr, {\n // flush: zlib.constants.Z_SYNC_FLUSH,\n // finishFlush: zlib.constants.Z_SYNC_FLUSH,\n // });\n } else {\n throw new Error(`unable to scrub - unknown chunk type ${chunkType}`);\n }\n } else {\n throw err;\n }\n }\n }\n\n // @ts-ignore\n return serverResponseWrite.apply(this, args);\n };\n\n // calling `res.json()` in the api routes on pages router calls `res.end` without called `res.write`\n const serverResponseEnd = ServerResponse.prototype.end;\n // @ts-ignore\n ServerResponse.prototype.end = function patchedServerResponseEnd(...args) {\n // console.log('⚡️ patched ServerResponse.end');\n const endChunk = args[0];\n // this just needs to work (so far) for nextjs sending json bodies, so does not need to handle all cases...\n if (endChunk && typeof endChunk === 'string') {\n // TODO: currently this throws the error and then things just hang... do we want to try to return an error type response instead?\n scanForLeaks(endChunk, { method: 'patched ServerResponse.end' });\n }\n // @ts-ignore\n return serverResponseEnd.apply(this, args);\n };\n}\n\n"]}
@@ -40,5 +40,5 @@ function unpatchGlobalConsole() {
40
40
  __name(unpatchGlobalConsole, "unpatchGlobalConsole");
41
41
 
42
42
  export { patchGlobalConsole, unpatchGlobalConsole };
43
- //# sourceMappingURL=chunk-UPKIHHPE.js.map
44
- //# sourceMappingURL=chunk-UPKIHHPE.js.map
43
+ //# sourceMappingURL=chunk-C5BEZMSO.js.map
44
+ //# sourceMappingURL=chunk-C5BEZMSO.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/runtime/patch-console.ts"],"names":[],"mappings":";;;;AAWO,SAAS,kBAAA,GAAqB;AACnC,EAAA,KAAA,CAAM,8CAAoC,CAAA;AAC1C,EAAA,IAAK,OAAA,CAAQ,IAAY,iBAAA,EAAmB;AAC1C,IAAA,KAAA,CAAM,mBAAmB,CAAA;AACzB,IAAA;AAAA,EACF;AACA,EAAA,IAAI,eAAA,CAAgB,eAAe,KAAA,EAAO;AACxC,IAAA,KAAA,CAAM,wBAAwB,CAAA;AAC9B,IAAA;AAAA,EACF;AAQA,EAAA,MAAM,qBAAA,GAAwB,MAAA,CAAO,qBAAA,CAAsB,UAAA,CAAW,OAAO,CAAA,CAAE,IAAA,CAAK,CAAC,CAAA,KAAM,CAAA,CAAE,WAAA,KAAgB,iBAAiB,CAAA;AAG9H,EAAC,UAAA,CAAmB,4BAAA,KAAiC,UAAA,CAAW,OAAA,CAAQ,qBAAqB,CAAA;AAE7F,EAAA,UAAA,CAAW,OAAA,CAAQ,qBAAqB,CAAA,GAAI,WAAY;AACtD,IAAC,UAAA,CAAmB,4BAAA,CAA6B,KAAA,CAAM,IAAA,EAAM;AAAA,MAC3D,UAAU,CAAC,CAAA;AAAA,MACX,qBAAA,CAAsB,SAAA,CAAU,CAAC,CAAC,CAAA;AAAA,MAClC,UAAU,CAAC;AAAA,KACZ,CAAA;AAAA,EACH,CAAA;AAOA,EAAA,KAAA,MAAW,aAAA,IAAiB,CAAC,OAAA,EAAS,OAAA,EAAS,QAAQ,KAAA,EAAO,MAAA,EAAQ,MAAA,EAAQ,OAAO,CAAA,EAAG;AAEtF,IAAA,MAAM,iBAAA,GAAoB,UAAA,CAAW,OAAA,CAAQ,aAAa,CAAA;AAE1D,IAAA,MAAM,4BAAY,MAAA,CAAA,WAAY;AAE5B,MAAA,iBAAA,CAAkB,KAAA,CAAM,MAAM,KAAA,CAAM,IAAA,CAAK,SAAS,CAAA,CAAE,GAAA,CAAI,qBAAqB,CAAC,CAAA;AAAA,IAChF,CAAA,EAHkB,WAAA,CAAA;AAIlB,IAAA,SAAA,CAAU,iBAAA,GAAoB,IAAA;AAG9B,IAAA,UAAA,CAAW,OAAA,CAAQ,aAAa,CAAA,GAAI,SAAA;AAAA,EACtC;AACF;AAhDgB,MAAA,CAAA,kBAAA,EAAA,oBAAA,CAAA;AAuDT,SAAS,oBAAA,GAAuB;AAErC,EAAA,IAAI,CAAE,WAAmB,4BAAA,EAA8B;AAEvD,EAAA,MAAM,qBAAA,GAAwB,MAAA,CAAO,qBAAA,CAAsB,UAAA,CAAW,OAAO,CAAA,CAAE,IAAA,CAAK,CAAC,CAAA,KAAM,CAAA,CAAE,WAAA,KAAgB,iBAAiB,CAAA;AAE9H,EAAA,UAAA,CAAW,OAAA,CAAQ,qBAAqB,CAAA,GAAK,UAAA,CAAmB,4BAAA;AAChE,EAAA,OAAQ,UAAA,CAAmB,4BAAA;AAC7B;AARgB,MAAA,CAAA,oBAAA,EAAA,sBAAA,CAAA","file":"chunk-UPKIHHPE.js","sourcesContent":["/* eslint-disable func-names, no-console, prefer-rest-params */\n\nimport { redactSensitiveConfig, varlockSettings } from './env';\nimport { debug } from './lib/debug';\n\n\n/**\n * patches global console methods to redact sensitive config\n *\n * NOTE - this may not be 100% foolproof depending on the platform\n * */\nexport function patchGlobalConsole() {\n debug('⚡️ PATCHING global console methods');\n if ((console.log as any)._varlockPatchedFn) {\n debug('> already patched');\n return;\n }\n if (varlockSettings.redactLogs === false) {\n debug('> disabled by settings');\n return;\n }\n\n // our method of patching involves replacing an internal node method which may not be called if console.log itself has also been patched\n // for example AWS lambdas patches this to write the logs to a file which then is pushed to the rest of their system\n\n // so first we'll just patch the internal method do deal with normal stdout/stderr logs -------------------------------------\n\n // we need the internal symbol name to access the internal method\n const kWriteToConsoleSymbol = Object.getOwnPropertySymbols(globalThis.console).find((s) => s.description === 'kWriteToConsole');\n\n // @ts-ignore\n (globalThis as any)._varlockOrigWriteToConsoleFn ||= globalThis.console[kWriteToConsoleSymbol];\n // @ts-ignore\n globalThis.console[kWriteToConsoleSymbol] = function () {\n (globalThis as any)._varlockOrigWriteToConsoleFn.apply(this, [\n arguments[0],\n redactSensitiveConfig(arguments[1]),\n arguments[2],\n ]);\n };\n\n // and now we'll wrap console.log (and the other methods) if it looks like they have been patched already ------------------\n // NOTE - this will not fully redact from everything since we can't safely reach deep into objects\n // ideally we would only turn this when the above method does not work, but it's not trivial to detect when it that is the case\n // so we'll turn it on all the time for now...\n\n for (const logMethodName of ['trace', 'debug', 'info', 'log', 'info', 'warn', 'error']) {\n // @ts-ignore\n const originalLogMethod = globalThis.console[logMethodName];\n\n const patchedFn = function () {\n // @ts-ignore\n originalLogMethod.apply(this, Array.from(arguments).map(redactSensitiveConfig));\n };\n patchedFn._varlockPatchedFn = true;\n\n // @ts-ignore\n globalThis.console[logMethodName] = patchedFn;\n }\n}\n\n/**\n * restore's original global console methods to stop redacting secrets\n *\n * (only needed during local development when switching settings on/off in a process that does not reload)\n * */\nexport function unpatchGlobalConsole() {\n // we'll only care about the normal case where console.log has NOT been patched by something else... (see above)\n if (!(globalThis as any)._varlockOrigWriteToConsoleFn) return;\n\n const kWriteToConsoleSymbol = Object.getOwnPropertySymbols(globalThis.console).find((s) => s.description === 'kWriteToConsole');\n // @ts-ignore\n globalThis.console[kWriteToConsoleSymbol] = (globalThis as any)._varlockOrigWriteToConsoleFn;\n delete (globalThis as any)._varlockOrigWriteToConsoleFn;\n}\n\n// ---\n\n// patchGlobalConsole();\n"]}
1
+ {"version":3,"sources":["../src/runtime/patch-console.ts"],"names":[],"mappings":";;;;AAWO,SAAS,kBAAA,GAAqB;AACnC,EAAA,KAAA,CAAM,8CAAoC,CAAA;AAC1C,EAAA,IAAK,OAAA,CAAQ,IAAY,iBAAA,EAAmB;AAC1C,IAAA,KAAA,CAAM,mBAAmB,CAAA;AACzB,IAAA;AAAA,EACF;AACA,EAAA,IAAI,eAAA,CAAgB,eAAe,KAAA,EAAO;AACxC,IAAA,KAAA,CAAM,wBAAwB,CAAA;AAC9B,IAAA;AAAA,EACF;AAQA,EAAA,MAAM,qBAAA,GAAwB,MAAA,CAAO,qBAAA,CAAsB,UAAA,CAAW,OAAO,CAAA,CAAE,IAAA,CAAK,CAAC,CAAA,KAAM,CAAA,CAAE,WAAA,KAAgB,iBAAiB,CAAA;AAG9H,EAAC,UAAA,CAAmB,4BAAA,KAAiC,UAAA,CAAW,OAAA,CAAQ,qBAAqB,CAAA;AAE7F,EAAA,UAAA,CAAW,OAAA,CAAQ,qBAAqB,CAAA,GAAI,WAAY;AACtD,IAAC,UAAA,CAAmB,4BAAA,CAA6B,KAAA,CAAM,IAAA,EAAM;AAAA,MAC3D,UAAU,CAAC,CAAA;AAAA,MACX,qBAAA,CAAsB,SAAA,CAAU,CAAC,CAAC,CAAA;AAAA,MAClC,UAAU,CAAC;AAAA,KACZ,CAAA;AAAA,EACH,CAAA;AAOA,EAAA,KAAA,MAAW,aAAA,IAAiB,CAAC,OAAA,EAAS,OAAA,EAAS,QAAQ,KAAA,EAAO,MAAA,EAAQ,MAAA,EAAQ,OAAO,CAAA,EAAG;AAEtF,IAAA,MAAM,iBAAA,GAAoB,UAAA,CAAW,OAAA,CAAQ,aAAa,CAAA;AAE1D,IAAA,MAAM,4BAAY,MAAA,CAAA,WAAY;AAE5B,MAAA,iBAAA,CAAkB,KAAA,CAAM,MAAM,KAAA,CAAM,IAAA,CAAK,SAAS,CAAA,CAAE,GAAA,CAAI,qBAAqB,CAAC,CAAA;AAAA,IAChF,CAAA,EAHkB,WAAA,CAAA;AAIlB,IAAA,SAAA,CAAU,iBAAA,GAAoB,IAAA;AAG9B,IAAA,UAAA,CAAW,OAAA,CAAQ,aAAa,CAAA,GAAI,SAAA;AAAA,EACtC;AACF;AAhDgB,MAAA,CAAA,kBAAA,EAAA,oBAAA,CAAA;AAuDT,SAAS,oBAAA,GAAuB;AAErC,EAAA,IAAI,CAAE,WAAmB,4BAAA,EAA8B;AAEvD,EAAA,MAAM,qBAAA,GAAwB,MAAA,CAAO,qBAAA,CAAsB,UAAA,CAAW,OAAO,CAAA,CAAE,IAAA,CAAK,CAAC,CAAA,KAAM,CAAA,CAAE,WAAA,KAAgB,iBAAiB,CAAA;AAE9H,EAAA,UAAA,CAAW,OAAA,CAAQ,qBAAqB,CAAA,GAAK,UAAA,CAAmB,4BAAA;AAChE,EAAA,OAAQ,UAAA,CAAmB,4BAAA;AAC7B;AARgB,MAAA,CAAA,oBAAA,EAAA,sBAAA,CAAA","file":"chunk-C5BEZMSO.js","sourcesContent":["/* eslint-disable func-names, no-console, prefer-rest-params */\n\nimport { redactSensitiveConfig, varlockSettings } from './env';\nimport { debug } from './lib/debug';\n\n\n/**\n * patches global console methods to redact sensitive config\n *\n * NOTE - this may not be 100% foolproof depending on the platform\n * */\nexport function patchGlobalConsole() {\n debug('⚡️ PATCHING global console methods');\n if ((console.log as any)._varlockPatchedFn) {\n debug('> already patched');\n return;\n }\n if (varlockSettings.redactLogs === false) {\n debug('> disabled by settings');\n return;\n }\n\n // our method of patching involves replacing an internal node method which may not be called if console.log itself has also been patched\n // for example AWS lambdas patches this to write the logs to a file which then is pushed to the rest of their system\n\n // so first we'll just patch the internal method do deal with normal stdout/stderr logs -------------------------------------\n\n // we need the internal symbol name to access the internal method\n const kWriteToConsoleSymbol = Object.getOwnPropertySymbols(globalThis.console).find((s) => s.description === 'kWriteToConsole');\n\n // @ts-ignore\n (globalThis as any)._varlockOrigWriteToConsoleFn ||= globalThis.console[kWriteToConsoleSymbol];\n // @ts-ignore\n globalThis.console[kWriteToConsoleSymbol] = function () {\n (globalThis as any)._varlockOrigWriteToConsoleFn.apply(this, [\n arguments[0],\n redactSensitiveConfig(arguments[1]),\n arguments[2],\n ]);\n };\n\n // and now we'll wrap console.log (and the other methods) if it looks like they have been patched already ------------------\n // NOTE - this will not fully redact from everything since we can't safely reach deep into objects\n // ideally we would only turn this when the above method does not work, but it's not trivial to detect when it that is the case\n // so we'll turn it on all the time for now...\n\n for (const logMethodName of ['trace', 'debug', 'info', 'log', 'info', 'warn', 'error']) {\n // @ts-ignore\n const originalLogMethod = globalThis.console[logMethodName];\n\n const patchedFn = function () {\n // @ts-ignore\n originalLogMethod.apply(this, Array.from(arguments).map(redactSensitiveConfig));\n };\n patchedFn._varlockPatchedFn = true;\n\n // @ts-ignore\n globalThis.console[logMethodName] = patchedFn;\n }\n}\n\n/**\n * restore's original global console methods to stop redacting secrets\n *\n * (only needed during local development when switching settings on/off in a process that does not reload)\n * */\nexport function unpatchGlobalConsole() {\n // we'll only care about the normal case where console.log has NOT been patched by something else... (see above)\n if (!(globalThis as any)._varlockOrigWriteToConsoleFn) return;\n\n const kWriteToConsoleSymbol = Object.getOwnPropertySymbols(globalThis.console).find((s) => s.description === 'kWriteToConsole');\n // @ts-ignore\n globalThis.console[kWriteToConsoleSymbol] = (globalThis as any)._varlockOrigWriteToConsoleFn;\n delete (globalThis as any)._varlockOrigWriteToConsoleFn;\n}\n"]}
@@ -1,10 +1,9 @@
1
- import { detectJsPackageManager, logLines, fmt, pathExists, installJsDependency } from './chunk-52FLZJCQ.js';
1
+ import { detectJsPackageManager, logLines, fmt, installJsDependency } from './chunk-OJFTFBQG.js';
2
2
  import { define } from './chunk-33ROL4J5.js';
3
- import { loadVarlockEnvGraph } from './chunk-Y2EGAWAH.js';
4
- import { StaticValueResolver, DotEnvFileDataSource, gracefulExit, checkIsFileGitIgnored, ansis_default } from './chunk-NXAXPMO5.js';
3
+ import { tryCatch, gracefulExit, checkIsFileGitIgnored, ansis_default, pathExists } from './chunk-FCVBOYES.js';
5
4
  import { __commonJS, __name, __toESM } from './chunk-XN24GZXQ.js';
6
- import path from 'path';
7
- import fs2 from 'fs/promises';
5
+ import path2 from 'path';
6
+ import fs3 from 'fs/promises';
8
7
  import 'util';
9
8
  import y2, { stdin, stdout } from 'process';
10
9
  import O from 'readline';
@@ -940,55 +939,70 @@ function inferSchemaUpdates(file) {
940
939
  }
941
940
  }
942
941
  __name(inferSchemaUpdates, "inferSchemaUpdates");
943
- function ensureAllItemsExist(envGraph, schemaFile) {
942
+ function ensureAllItemsExist(schemaFile, otherFiles) {
944
943
  const addedItemKeys = [];
945
- for (const itemKey in envGraph.configSchema) {
946
- const item = envGraph.configSchema[itemKey];
947
- const itemInSchema = schemaFile.configItems.find((i) => i.key === itemKey);
948
- if (!itemInSchema) {
944
+ for (const otherFile of otherFiles) {
945
+ for (const item of otherFile.parsedFile.configItems) {
946
+ const itemInSchema = schemaFile.configItems.find((i) => i.key === item.key);
947
+ if (itemInSchema) continue;
949
948
  if (addedItemKeys.length === 0) {
950
949
  envSpecUpdater.injectFromStr(schemaFile, [
951
950
  "",
952
951
  "# items added to schema by `varlock init`",
953
- "# that were missing in example, but detected in other env files",
952
+ "# that were missing in example, but detected in other .env files",
954
953
  "# PLEASE REVIEW THESE!",
955
954
  "# ---",
956
955
  ""
957
956
  ].join("\n"), { location: "end" });
958
957
  }
959
- addedItemKeys.push(itemKey);
960
- envSpecUpdater.injectFromStr(schemaFile, [`${itemKey}=`].join("\n"));
961
- const itemValue = item.valueResolver instanceof StaticValueResolver && item.valueResolver.staticValue || "";
962
- inferItemDecorators(schemaFile, itemKey, String(itemValue));
958
+ addedItemKeys.push(item.key);
959
+ envSpecUpdater.injectFromStr(schemaFile, `${item.key}=`);
960
+ const itemValue = item.value instanceof ParsedEnvSpecStaticValue && item.value.value?.toString() || "";
961
+ inferItemDecorators(schemaFile, item.key, String(itemValue));
963
962
  }
964
963
  }
965
964
  }
966
965
  __name(ensureAllItemsExist, "ensureAllItemsExist");
967
- async function detectRedundantValues(envGraph, opts = {}) {
968
- const schema = envGraph.schemaDataSource;
969
- if (!schema) return {};
966
+ async function detectRedundantValues(schemaFile, otherFiles, opts = {}) {
970
967
  const redundantItemsBySourcePath = {};
971
- const schemaValues = schema.getStaticValues();
972
- for (const source of envGraph.dataSources) {
973
- if (source === schema) continue;
974
- if (source.type === "example") continue;
975
- if (!(source instanceof DotEnvFileDataSource) || !source.parsedFile) continue;
976
- const sourceValues = source.getStaticValues();
977
- for (const [key, value] of Object.entries(sourceValues)) {
978
- if (schemaValues[key] !== value) continue;
979
- redundantItemsBySourcePath[source.fullPath] ||= [];
980
- redundantItemsBySourcePath[source.fullPath].push(key);
968
+ const schemaValues = schemaFile.toSimpleObj();
969
+ for (const otherFile of Object.values(otherFiles)) {
970
+ if (otherFile.fileName.startsWith(".env.schema") || otherFile.fileName.startsWith(".env.example") || otherFile.fileName.startsWith(".env.sample") || otherFile.fileName.startsWith(".env.default")) continue;
971
+ const otherFileValues = otherFile.parsedFile.toSimpleObj();
972
+ for (const itemKey in otherFileValues) {
973
+ if (!(itemKey in schemaValues)) continue;
974
+ if (otherFileValues[itemKey] !== schemaValues[itemKey]) continue;
975
+ redundantItemsBySourcePath[otherFile.fullPath] ||= [];
976
+ redundantItemsBySourcePath[otherFile.fullPath].push(itemKey);
981
977
  if (opts.delete) {
982
- envSpecUpdater.deleteItem(source.parsedFile, key);
978
+ envSpecUpdater.deleteItem(otherFile.parsedFile, itemKey);
983
979
  }
984
980
  }
985
981
  if (opts.delete) {
986
- await fs2.writeFile(source.fullPath, source.parsedFile.toString(), "utf8");
982
+ await fs3.writeFile(otherFile.fullPath, otherFile.parsedFile.toString(), "utf8");
987
983
  }
988
984
  }
989
985
  return redundantItemsBySourcePath;
990
986
  }
991
987
  __name(detectRedundantValues, "detectRedundantValues");
988
+ var SKIP_FILE_TYPES = [".md", ".d.ts"];
989
+ async function findEnvFiles(opts) {
990
+ const cwd = opts?.cwd || process.cwd();
991
+ const envFiles = [];
992
+ const filesWithinDir = await fs3.readdir(cwd);
993
+ for (const fileName of filesWithinDir) {
994
+ if (fileName === ".env" || fileName.startsWith(".env.")) {
995
+ let skip = false;
996
+ for (const fileType of SKIP_FILE_TYPES) {
997
+ if (fileName.endsWith(fileType)) skip = true;
998
+ }
999
+ if (skip) continue;
1000
+ envFiles.push(path2.join(cwd, fileName));
1001
+ }
1002
+ }
1003
+ return envFiles;
1004
+ }
1005
+ __name(findEnvFiles, "findEnvFiles");
992
1006
 
993
1007
  // src/cli/commands/init.command.ts
994
1008
  var commandSpec = define({
@@ -999,10 +1013,28 @@ var commandSpec = define({
999
1013
  var commandFn = /* @__PURE__ */ __name(async (ctx) => {
1000
1014
  const jsPackageManager = detectJsPackageManager();
1001
1015
  console.log("\u{1F9D9} Hello and welcome to Varlock \u{1F512}\u{1F525}\u2728");
1002
- let envGraph = await loadVarlockEnvGraph();
1003
- const existingSchemaFile = envGraph.dataSources.find((dataSource) => {
1004
- return dataSource.type === "schema";
1005
- });
1016
+ const envFilePaths = await findEnvFiles();
1017
+ const parsedEnvFiles = {};
1018
+ for (const filePath of envFilePaths) {
1019
+ const fileContents = await fs3.readFile(filePath, "utf-8");
1020
+ const fileName = path2.basename(filePath);
1021
+ const parsedFile = await tryCatch(async () => parseEnvSpecDotEnvFile(fileContents), () => {
1022
+ logLines([
1023
+ "",
1024
+ `Unable to parse ${fmt.filePath(filePath)}`,
1025
+ "This file will be skipped."
1026
+ ]);
1027
+ });
1028
+ if (!parsedFile) {
1029
+ continue;
1030
+ }
1031
+ parsedEnvFiles[fileName] = {
1032
+ fileName,
1033
+ fullPath: filePath,
1034
+ parsedFile
1035
+ };
1036
+ }
1037
+ const existingSchemaFile = parsedEnvFiles[".env.schema"];
1006
1038
  if (existingSchemaFile) {
1007
1039
  logLines([
1008
1040
  `It looks like you already have a ${fmt.fileName(".env.schema")} file \u{1F389}`,
@@ -1011,45 +1043,45 @@ var commandFn = /* @__PURE__ */ __name(async (ctx) => {
1011
1043
  "See more docs at https://varlock.dev/guides/schema"
1012
1044
  ]);
1013
1045
  } else {
1014
- let exampleFileToConvert = null;
1015
- const allExampleFiles = envGraph.dataSources.filter((dataSource) => {
1016
- return dataSource instanceof DotEnvFileDataSource && dataSource.type === "example";
1046
+ const allExampleFileNames = Object.keys(parsedEnvFiles).filter((fileName) => {
1047
+ return fileName.startsWith(".env.example") || fileName.startsWith(".env.sample");
1017
1048
  });
1018
- if (allExampleFiles.length === 1) {
1019
- exampleFileToConvert = allExampleFiles[0];
1020
- } else if (allExampleFiles.length > 1) {
1049
+ let exampleFileToConvert;
1050
+ if (allExampleFileNames.length === 1) {
1051
+ exampleFileToConvert = parsedEnvFiles[allExampleFileNames[0]];
1052
+ } else if (allExampleFileNames.length > 1) {
1021
1053
  console.log("");
1022
1054
  const selectedExample = await ve({
1023
1055
  message: `We detected more than one example .env file. Which one should we use to create your new ${fmt.fileName(".env.schema")}?`,
1024
- options: allExampleFiles.map((file) => ({
1025
- label: file.fileName,
1026
- value: file
1056
+ options: allExampleFileNames.map((fileName) => ({
1057
+ label: fileName,
1058
+ value: parsedEnvFiles[fileName]
1027
1059
  }))
1028
1060
  });
1029
1061
  if (pD(selectedExample)) return gracefulExit(0);
1030
1062
  exampleFileToConvert = selectedExample;
1031
1063
  }
1032
- const parsedEnvFile = exampleFileToConvert?.parsedFile || parseEnvSpecDotEnvFile("");
1033
- if (!parsedEnvFile) throw new Error("No parsed .env file found");
1034
- envSpecUpdater.ensureHeader(parsedEnvFile, [
1064
+ const parsedEnvSchemaFile = exampleFileToConvert?.parsedFile || parseEnvSpecDotEnvFile("");
1065
+ if (!parsedEnvSchemaFile) throw new Error("expected parsed .env example file");
1066
+ envSpecUpdater.ensureHeader(parsedEnvSchemaFile, [
1035
1067
  "This env file uses @env-spec - see https://varlock.dev/env-spec for more info",
1036
1068
  ""
1037
1069
  // TODO: add env spec version? real links?
1038
1070
  ].join("\n"));
1039
- envSpecUpdater.setRootDecorator(parsedEnvFile, "defaultRequired", "false", { explicitTrue: true });
1040
- envSpecUpdater.setRootDecorator(parsedEnvFile, "defaultSensitive", "false", { explicitTrue: true });
1041
- envSpecUpdater.setRootDecorator(parsedEnvFile, "generateTypes", "lang=ts, path=env.d.ts", { bareFnArgs: true });
1042
- envSpecUpdater.injectFromStr(parsedEnvFile, [
1071
+ envSpecUpdater.setRootDecorator(parsedEnvSchemaFile, "defaultRequired", "infer", { explicitTrue: true });
1072
+ envSpecUpdater.setRootDecorator(parsedEnvSchemaFile, "defaultSensitive", "false", { explicitTrue: true });
1073
+ envSpecUpdater.setRootDecorator(parsedEnvSchemaFile, "generateTypes", "lang=ts, path=env.d.ts", { bareFnArgs: true });
1074
+ envSpecUpdater.injectFromStr(parsedEnvSchemaFile, [
1043
1075
  "",
1044
1076
  "# example env variable injected by `varlock init` \u26A0\uFE0F DELETE THIS ITEM! \u26A0\uFE0F",
1045
1077
  '# @required @sensitive @example="example value"',
1046
1078
  'EXAMPLE_ITEM="delete me!"',
1047
1079
  ""
1048
1080
  ].join("\n"), { location: "after_header" });
1049
- inferSchemaUpdates(parsedEnvFile);
1050
- ensureAllItemsExist(envGraph, parsedEnvFile);
1051
- const schemaFilePath = path.join(process.cwd(), ".env.schema");
1052
- await fs2.writeFile(schemaFilePath, parsedEnvFile.toString());
1081
+ inferSchemaUpdates(parsedEnvSchemaFile);
1082
+ ensureAllItemsExist(parsedEnvSchemaFile, Object.values(parsedEnvFiles));
1083
+ const schemaFilePath = path2.join(process.cwd(), ".env.schema");
1084
+ await fs3.writeFile(schemaFilePath, parsedEnvSchemaFile.toString());
1053
1085
  if (exampleFileToConvert) {
1054
1086
  logLines([
1055
1087
  "",
@@ -1065,7 +1097,7 @@ var commandFn = /* @__PURE__ */ __name(async (ctx) => {
1065
1097
  }
1066
1098
  if (await checkIsFileGitIgnored(schemaFilePath)) {
1067
1099
  logLines([ansis_default.dim(`(and updated ${fmt.fileName(".gitignore")} to ensure it will be tracked by git)`)]);
1068
- await fs2.appendFile(".gitignore", "\n!.env.schema");
1100
+ await fs3.appendFile(".gitignore", "\n!.env.schema");
1069
1101
  }
1070
1102
  logLines([
1071
1103
  "",
@@ -1084,8 +1116,8 @@ var commandFn = /* @__PURE__ */ __name(async (ctx) => {
1084
1116
  message: `Have you reviewed and updated your new ${fmt.fileName(".env.schema")} file?`
1085
1117
  });
1086
1118
  if (pD(confirmReviewed)) return gracefulExit(0);
1087
- envGraph = await loadVarlockEnvGraph();
1088
- if (envGraph.configSchema.EXAMPLE_ITEM) {
1119
+ const reloadedSchemaFile = await parseEnvSpecDotEnvFile(await fs3.readFile(schemaFilePath, "utf-8"));
1120
+ if (reloadedSchemaFile.configItems.find((i) => i.key === "EXAMPLE_ITEM")) {
1089
1121
  logLines([
1090
1122
  "",
1091
1123
  ansis_default.bold(`\u{1F6A8} Really? ${ansis_default.red("You didn't remove the EXAMPLE_ITEM!")}`),
@@ -1098,20 +1130,20 @@ var commandFn = /* @__PURE__ */ __name(async (ctx) => {
1098
1130
  });
1099
1131
  if (pD(confirmDeleteExample)) return gracefulExit(0);
1100
1132
  if (confirmDeleteExample) {
1101
- await fs2.unlink(exampleFileToConvert.fullPath);
1133
+ await fs3.unlink(exampleFileToConvert.fullPath);
1102
1134
  }
1103
1135
  }
1104
- const defaultsFile = envGraph.dataSources.find((dataSource) => {
1105
- return dataSource instanceof DotEnvFileDataSource && dataSource.type === "defaults";
1136
+ const defaultsFile = Object.values(parsedEnvFiles).find((f) => {
1137
+ return f.fileName.startsWith(".env.default");
1106
1138
  });
1107
1139
  if (defaultsFile) {
1108
1140
  logLines([
1109
1141
  "",
1110
1142
  `\u{1F6A7} We detected a ${fmt.fileName(defaultsFile.fileName)} file in your project`,
1111
- `You should migrate these default values into ${fmt.fileName(".env.schema")} and delete ${fmt.fileName(defaultsFile.fileName)}`
1143
+ `You should migrate these default values into ${fmt.fileName(".env.schema")} and delete it.`
1112
1144
  ]);
1113
1145
  }
1114
- const redundantInfo = await detectRedundantValues(envGraph);
1146
+ const redundantInfo = await detectRedundantValues(parsedEnvSchemaFile, parsedEnvFiles);
1115
1147
  if (Object.keys(redundantInfo).length > 0) {
1116
1148
  logLines([
1117
1149
  "",
@@ -1126,7 +1158,7 @@ var commandFn = /* @__PURE__ */ __name(async (ctx) => {
1126
1158
  });
1127
1159
  if (pD(confirmDeleteRedundant)) return gracefulExit(0);
1128
1160
  if (confirmDeleteRedundant) {
1129
- await detectRedundantValues(envGraph, { delete: true });
1161
+ await detectRedundantValues(parsedEnvSchemaFile, parsedEnvFiles, { delete: true });
1130
1162
  }
1131
1163
  }
1132
1164
  logLines([
@@ -1140,7 +1172,7 @@ var commandFn = /* @__PURE__ */ __name(async (ctx) => {
1140
1172
  ""
1141
1173
  ]);
1142
1174
  }
1143
- if (jsPackageManager && await pathExists(path.join(process.cwd(), "package.json"))) {
1175
+ if (jsPackageManager && await pathExists(path2.join(process.cwd(), "package.json"))) {
1144
1176
  const installResult = installJsDependency({
1145
1177
  packageManager: jsPackageManager.name,
1146
1178
  packageName: "varlock"
@@ -1155,5 +1187,5 @@ var commandFn = /* @__PURE__ */ __name(async (ctx) => {
1155
1187
  }, "commandFn");
1156
1188
 
1157
1189
  export { commandFn, commandSpec };
1158
- //# sourceMappingURL=chunk-MHDV65DI.js.map
1159
- //# sourceMappingURL=chunk-MHDV65DI.js.map
1190
+ //# sourceMappingURL=chunk-EQQCW3OI.js.map
1191
+ //# sourceMappingURL=chunk-EQQCW3OI.js.map