@sanity/cli 3.59.2-canary.33 → 3.59.2-corel-presentation-lcapi.562

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 (48) hide show
  1. package/lib/_chunks-cjs/cli.js +34360 -26058
  2. package/lib/_chunks-cjs/cli.js.map +1 -1
  3. package/lib/_chunks-cjs/cliWorker.js.map +1 -1
  4. package/lib/_chunks-cjs/generateAction.js.map +1 -1
  5. package/lib/_chunks-cjs/getCliConfig.js +1 -1
  6. package/lib/_chunks-cjs/getCliConfig.js.map +1 -1
  7. package/lib/_chunks-cjs/journeyConfig.js.map +1 -1
  8. package/lib/_chunks-cjs/loadEnv.js +200 -202
  9. package/lib/_chunks-cjs/loadEnv.js.map +1 -1
  10. package/lib/index.d.mts +37 -1
  11. package/lib/index.d.ts +37 -1
  12. package/lib/index.esm.js +223 -224
  13. package/lib/index.esm.js.map +1 -1
  14. package/lib/index.js.map +1 -1
  15. package/lib/index.mjs +223 -224
  16. package/lib/index.mjs.map +1 -1
  17. package/lib/workers/getCliConfig.js.map +1 -1
  18. package/lib/workers/typegenGenerate.js.map +1 -1
  19. package/package.json +17 -19
  20. package/src/CommandRunner.ts +1 -2
  21. package/src/actions/init-project/{bootstrapTemplate.ts → bootstrapLocalTemplate.ts} +8 -21
  22. package/src/actions/init-project/bootstrapRemoteTemplate.ts +118 -0
  23. package/src/actions/init-project/git.ts +2 -2
  24. package/src/actions/init-project/initProject.ts +158 -146
  25. package/src/actions/init-project/readPackageJson.ts +18 -0
  26. package/src/actions/init-project/templates/nextjs/index.ts +16 -0
  27. package/src/actions/init-project/templates/nextjs/schemaTypes/blog.ts +2 -2
  28. package/src/actions/init-project/updateInitialTemplateMetadata.ts +24 -0
  29. package/src/actions/login/login.ts +2 -3
  30. package/src/actions/versions/findSanityModuleVersions.ts +0 -1
  31. package/src/commands/index.ts +2 -2
  32. package/src/commands/init/initCommand.ts +7 -67
  33. package/src/commands/learn/learnCommand.ts +20 -0
  34. package/src/commands/logout/logoutCommand.ts +1 -1
  35. package/src/outputters/cliOutputter.ts +21 -8
  36. package/src/studioDependencies.ts +1 -1
  37. package/src/types.ts +41 -1
  38. package/src/util/frameworkPort.ts +63 -0
  39. package/src/util/generateCommandsDocumentation.ts +7 -4
  40. package/src/util/getCliConfig.ts +1 -1
  41. package/src/util/getProviderName.ts +9 -0
  42. package/src/util/remoteTemplate.ts +320 -0
  43. package/templates/get-started/plugins/sanity-plugin-tutorial/GetStartedTutorial.tsx +4 -4
  44. package/src/actions/init-plugin/initPlugin.ts +0 -119
  45. package/src/actions/init-plugin/pluginTemplates.ts +0 -38
  46. package/src/actions/init-project/reconfigureV2Project.ts +0 -446
  47. package/src/commands/upgrade/upgradeCommand.ts +0 -38
  48. package/src/commands/upgrade/upgradeDependencies.ts +0 -289
package/lib/index.esm.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { createClient } from "@sanity/client";
2
- import fs$1 from "node:fs";
3
- import path$1 from "node:path";
2
+ import fs from "node:fs";
3
+ import path from "node:path";
4
4
  import debugIt from "debug";
5
5
  import require$$0 from "fs";
6
6
  import require$$1 from "path";
@@ -16,15 +16,15 @@ function getCliConfigSync(cwd) {
16
16
  return getSanityCliConfig(cwd) || getSanityJsonConfig(cwd);
17
17
  }
18
18
  function getSanityJsonConfig(cwd) {
19
- const configPath = path$1.join(cwd, "sanity.json");
20
- return fs$1.existsSync(configPath) ? {
19
+ const configPath = path.join(cwd, "sanity.json");
20
+ return fs.existsSync(configPath) ? {
21
21
  config: loadJsonConfig(configPath),
22
22
  path: configPath,
23
23
  version: 2
24
24
  } : null;
25
25
  }
26
26
  function getSanityCliConfig(cwd) {
27
- const jsConfigPath = path$1.join(cwd, "sanity.cli.js"), tsConfigPath = path$1.join(cwd, "sanity.cli.ts"), [js, ts] = [fs$1.existsSync(jsConfigPath), fs$1.existsSync(tsConfigPath)];
27
+ const jsConfigPath = path.join(cwd, "sanity.cli.js"), tsConfigPath = path.join(cwd, "sanity.cli.ts"), [js, ts] = [fs.existsSync(jsConfigPath), fs.existsSync(tsConfigPath)];
28
28
  return !js && !ts ? null : !js && ts ? {
29
29
  config: importConfig(tsConfigPath),
30
30
  path: tsConfigPath,
@@ -37,7 +37,7 @@ function getSanityCliConfig(cwd) {
37
37
  }
38
38
  function loadJsonConfig(filePath) {
39
39
  try {
40
- const content = fs$1.readFileSync(filePath, "utf8");
40
+ const content = fs.readFileSync(filePath, "utf8");
41
41
  return JSON.parse(content);
42
42
  } catch (err) {
43
43
  return console.error(`Error reading "${filePath}": ${err.message}`), null;
@@ -45,10 +45,10 @@ function loadJsonConfig(filePath) {
45
45
  }
46
46
  function importConfig(filePath) {
47
47
  try {
48
- const config2 = dynamicRequire(filePath);
49
- if (config2 === null || typeof config2 != "object")
48
+ const config = dynamicRequire(filePath);
49
+ if (config === null || typeof config != "object")
50
50
  throw new Error("Module export is not a configuration object");
51
- return "default" in config2 ? config2.default : config2;
51
+ return "default" in config ? config.default : config;
52
52
  } catch (err) {
53
53
  return err.code === "MODULE_NOT_FOUND" && err.message.includes("sanity/cli") || console.error(`Error reading "${filePath}": ${err.message}`), null;
54
54
  }
@@ -67,27 +67,27 @@ ${err.message}`);
67
67
  }
68
68
  function hasStudioConfig(basePath) {
69
69
  return [
70
- fileExists(path$1.join(basePath, "sanity.config.js")),
71
- fileExists(path$1.join(basePath, "sanity.config.ts")),
70
+ fileExists(path.join(basePath, "sanity.config.js")),
71
+ fileExists(path.join(basePath, "sanity.config.ts")),
72
72
  isSanityV2StudioRoot(basePath)
73
73
  ].some(Boolean);
74
74
  }
75
75
  function resolveProjectRoot(basePath, iterations = 0) {
76
76
  if (hasStudioConfig(basePath))
77
77
  return basePath;
78
- const parentDir = path$1.resolve(basePath, "..");
78
+ const parentDir = path.resolve(basePath, "..");
79
79
  return parentDir === basePath || iterations > 30 ? !1 : resolveProjectRoot(parentDir, iterations + 1);
80
80
  }
81
81
  function isSanityV2StudioRoot(basePath) {
82
82
  try {
83
- const content = fs$1.readFileSync(path$1.join(basePath, "sanity.json"), "utf8"), isRoot = !!JSON.parse(content)?.root;
83
+ const content = fs.readFileSync(path.join(basePath, "sanity.json"), "utf8"), isRoot = !!JSON.parse(content)?.root;
84
84
  return isRoot && debug("Found Sanity v2 studio root at %s", basePath), isRoot;
85
85
  } catch {
86
86
  return !1;
87
87
  }
88
88
  }
89
89
  function fileExists(filePath) {
90
- return fs$1.existsSync(filePath);
90
+ return fs.existsSync(filePath);
91
91
  }
92
92
  function getCliClient(options = {}) {
93
93
  if (typeof process != "object")
@@ -103,10 +103,10 @@ function getCliClient(options = {}) {
103
103
  } = options;
104
104
  if (projectId && dataset)
105
105
  return createClient({ projectId, dataset, apiVersion, useCdn, token });
106
- const rootDir = resolveRootDir(cwd), { config: config2 } = getCliConfigSync(rootDir) || {};
107
- if (!config2)
106
+ const rootDir = resolveRootDir(cwd), { config } = getCliConfigSync(rootDir) || {};
107
+ if (!config)
108
108
  throw new Error("Unable to resolve CLI configuration");
109
- const apiConfig = config2?.api || {};
109
+ const apiConfig = config?.api || {};
110
110
  if (!apiConfig.projectId || !apiConfig.dataset)
111
111
  throw new Error("Unable to resolve project ID/dataset from CLI configuration");
112
112
  return createClient({
@@ -119,13 +119,13 @@ function getCliClient(options = {}) {
119
119
  }
120
120
  getCliClient.__internal__getToken = () => {
121
121
  };
122
- function defineCliConfig(config2) {
123
- return config2;
122
+ function defineCliConfig(config) {
123
+ return config;
124
124
  }
125
- function createCliConfig(config2) {
126
- return config2;
125
+ function createCliConfig(config) {
126
+ return config;
127
127
  }
128
- var main$1 = { exports: {} }, name = "dotenv", version$1 = "16.4.5", description = "Loads environment variables from .env file", main = "lib/main.js", types = "lib/main.d.ts", exports = {
128
+ var main$2 = { exports: {} }, name = "dotenv", version = "16.4.7", description = "Loads environment variables from .env file", main$1 = "lib/main.js", types = "lib/main.d.ts", exports = {
129
129
  ".": {
130
130
  types: "./lib/main.d.ts",
131
131
  require: "./lib/main.js",
@@ -141,10 +141,9 @@ var main$1 = { exports: {} }, name = "dotenv", version$1 = "16.4.5", description
141
141
  }, scripts = {
142
142
  "dts-check": "tsc --project tests/types/tsconfig.json",
143
143
  lint: "standard",
144
- "lint-readme": "standard-markdown",
145
144
  pretest: "npm run lint && npm run dts-check",
146
- test: "tap tests/*.js --100 -Rspec",
147
- "test:coverage": "tap --coverage-report=lcov",
145
+ test: "tap run --allow-empty-coverage --disable-coverage --timeout=60000",
146
+ "test:coverage": "tap run --show-full-coverage --timeout=60000 --coverage-report=lcov",
148
147
  prerelease: "npm test",
149
148
  release: "standard-version"
150
149
  }, repository = {
@@ -159,15 +158,12 @@ var main$1 = { exports: {} }, name = "dotenv", version$1 = "16.4.5", description
159
158
  "config",
160
159
  "settings"
161
160
  ], readmeFilename = "README.md", license = "BSD-2-Clause", devDependencies = {
162
- "@definitelytyped/dtslint": "^0.0.133",
163
161
  "@types/node": "^18.11.3",
164
- decache: "^4.6.1",
162
+ decache: "^4.6.2",
165
163
  sinon: "^14.0.1",
166
164
  standard: "^17.0.0",
167
- "standard-markdown": "^7.1.0",
168
165
  "standard-version": "^9.5.0",
169
- tap: "^16.3.0",
170
- tar: "^6.1.11",
166
+ tap: "^19.2.0",
171
167
  typescript: "^4.8.4"
172
168
  }, engines = {
173
169
  node: ">=12"
@@ -175,9 +171,9 @@ var main$1 = { exports: {} }, name = "dotenv", version$1 = "16.4.5", description
175
171
  fs: !1
176
172
  }, require$$4 = {
177
173
  name,
178
- version: version$1,
174
+ version,
179
175
  description,
180
- main,
176
+ main: main$1,
181
177
  types,
182
178
  exports,
183
179
  scripts,
@@ -189,214 +185,217 @@ var main$1 = { exports: {} }, name = "dotenv", version$1 = "16.4.5", description
189
185
  devDependencies,
190
186
  engines,
191
187
  browser
192
- };
193
- const fs = require$$0, path = require$$1, os = require$$2, crypto = require$$3, packageJson = require$$4, version = packageJson.version, LINE = /(?:^|^)\s*(?:export\s+)?([\w.-]+)(?:\s*=\s*?|:\s+?)(\s*'(?:\\'|[^'])*'|\s*"(?:\\"|[^"])*"|\s*`(?:\\`|[^`])*`|[^#\r\n]+)?\s*(?:#.*)?(?:$|$)/mg;
194
- function parse(src) {
195
- const obj = {};
196
- let lines = src.toString();
197
- lines = lines.replace(/\r\n?/mg, `
188
+ }, hasRequiredMain$1;
189
+ function requireMain$1() {
190
+ if (hasRequiredMain$1) return main$2.exports;
191
+ hasRequiredMain$1 = 1;
192
+ const fs2 = require$$0, path2 = require$$1, os = require$$2, crypto = require$$3, version2 = require$$4.version, LINE = /(?:^|^)\s*(?:export\s+)?([\w.-]+)(?:\s*=\s*?|:\s+?)(\s*'(?:\\'|[^'])*'|\s*"(?:\\"|[^"])*"|\s*`(?:\\`|[^`])*`|[^#\r\n]+)?\s*(?:#.*)?(?:$|$)/mg;
193
+ function parse(src) {
194
+ const obj = {};
195
+ let lines = src.toString();
196
+ lines = lines.replace(/\r\n?/mg, `
198
197
  `);
199
- let match;
200
- for (; (match = LINE.exec(lines)) != null; ) {
201
- const key = match[1];
202
- let value = match[2] || "";
203
- value = value.trim();
204
- const maybeQuote = value[0];
205
- value = value.replace(/^(['"`])([\s\S]*)\1$/mg, "$2"), maybeQuote === '"' && (value = value.replace(/\\n/g, `
198
+ let match;
199
+ for (; (match = LINE.exec(lines)) != null; ) {
200
+ const key = match[1];
201
+ let value = match[2] || "";
202
+ value = value.trim();
203
+ const maybeQuote = value[0];
204
+ value = value.replace(/^(['"`])([\s\S]*)\1$/mg, "$2"), maybeQuote === '"' && (value = value.replace(/\\n/g, `
206
205
  `), value = value.replace(/\\r/g, "\r")), obj[key] = value;
206
+ }
207
+ return obj;
207
208
  }
208
- return obj;
209
- }
210
- function _parseVault(options) {
211
- const vaultPath = _vaultPath(options), result = DotenvModule.configDotenv({ path: vaultPath });
212
- if (!result.parsed) {
213
- const err = new Error(`MISSING_DATA: Cannot parse ${vaultPath} for an unknown reason`);
214
- throw err.code = "MISSING_DATA", err;
209
+ function _parseVault(options) {
210
+ const vaultPath = _vaultPath(options), result = DotenvModule.configDotenv({ path: vaultPath });
211
+ if (!result.parsed) {
212
+ const err = new Error(`MISSING_DATA: Cannot parse ${vaultPath} for an unknown reason`);
213
+ throw err.code = "MISSING_DATA", err;
214
+ }
215
+ const keys = _dotenvKey(options).split(","), length = keys.length;
216
+ let decrypted;
217
+ for (let i = 0; i < length; i++)
218
+ try {
219
+ const key = keys[i].trim(), attrs = _instructions(result, key);
220
+ decrypted = DotenvModule.decrypt(attrs.ciphertext, attrs.key);
221
+ break;
222
+ } catch (error) {
223
+ if (i + 1 >= length)
224
+ throw error;
225
+ }
226
+ return DotenvModule.parse(decrypted);
227
+ }
228
+ function _log(message) {
229
+ console.log(`[dotenv@${version2}][INFO] ${message}`);
215
230
  }
216
- const keys = _dotenvKey(options).split(","), length = keys.length;
217
- let decrypted;
218
- for (let i = 0; i < length; i++)
231
+ function _warn(message) {
232
+ console.log(`[dotenv@${version2}][WARN] ${message}`);
233
+ }
234
+ function _debug(message) {
235
+ console.log(`[dotenv@${version2}][DEBUG] ${message}`);
236
+ }
237
+ function _dotenvKey(options) {
238
+ return options && options.DOTENV_KEY && options.DOTENV_KEY.length > 0 ? options.DOTENV_KEY : process.env.DOTENV_KEY && process.env.DOTENV_KEY.length > 0 ? process.env.DOTENV_KEY : "";
239
+ }
240
+ function _instructions(result, dotenvKey) {
241
+ let uri;
219
242
  try {
220
- const key = keys[i].trim(), attrs = _instructions(result, key);
221
- decrypted = DotenvModule.decrypt(attrs.ciphertext, attrs.key);
222
- break;
243
+ uri = new URL(dotenvKey);
223
244
  } catch (error) {
224
- if (i + 1 >= length)
225
- throw error;
245
+ if (error.code === "ERR_INVALID_URL") {
246
+ const err = new Error("INVALID_DOTENV_KEY: Wrong format. Must be in valid uri format like dotenv://:key_1234@dotenvx.com/vault/.env.vault?environment=development");
247
+ throw err.code = "INVALID_DOTENV_KEY", err;
248
+ }
249
+ throw error;
226
250
  }
227
- return DotenvModule.parse(decrypted);
228
- }
229
- function _log(message) {
230
- console.log(`[dotenv@${version}][INFO] ${message}`);
231
- }
232
- function _warn(message) {
233
- console.log(`[dotenv@${version}][WARN] ${message}`);
234
- }
235
- function _debug(message) {
236
- console.log(`[dotenv@${version}][DEBUG] ${message}`);
237
- }
238
- function _dotenvKey(options) {
239
- return options && options.DOTENV_KEY && options.DOTENV_KEY.length > 0 ? options.DOTENV_KEY : process.env.DOTENV_KEY && process.env.DOTENV_KEY.length > 0 ? process.env.DOTENV_KEY : "";
240
- }
241
- function _instructions(result, dotenvKey) {
242
- let uri;
243
- try {
244
- uri = new URL(dotenvKey);
245
- } catch (error) {
246
- if (error.code === "ERR_INVALID_URL") {
247
- const err = new Error("INVALID_DOTENV_KEY: Wrong format. Must be in valid uri format like dotenv://:key_1234@dotenvx.com/vault/.env.vault?environment=development");
251
+ const key = uri.password;
252
+ if (!key) {
253
+ const err = new Error("INVALID_DOTENV_KEY: Missing key part");
248
254
  throw err.code = "INVALID_DOTENV_KEY", err;
249
255
  }
250
- throw error;
256
+ const environment = uri.searchParams.get("environment");
257
+ if (!environment) {
258
+ const err = new Error("INVALID_DOTENV_KEY: Missing environment part");
259
+ throw err.code = "INVALID_DOTENV_KEY", err;
260
+ }
261
+ const environmentKey = `DOTENV_VAULT_${environment.toUpperCase()}`, ciphertext = result.parsed[environmentKey];
262
+ if (!ciphertext) {
263
+ const err = new Error(`NOT_FOUND_DOTENV_ENVIRONMENT: Cannot locate environment ${environmentKey} in your .env.vault file.`);
264
+ throw err.code = "NOT_FOUND_DOTENV_ENVIRONMENT", err;
265
+ }
266
+ return { ciphertext, key };
251
267
  }
252
- const key = uri.password;
253
- if (!key) {
254
- const err = new Error("INVALID_DOTENV_KEY: Missing key part");
255
- throw err.code = "INVALID_DOTENV_KEY", err;
268
+ function _vaultPath(options) {
269
+ let possibleVaultPath = null;
270
+ if (options && options.path && options.path.length > 0)
271
+ if (Array.isArray(options.path))
272
+ for (const filepath of options.path)
273
+ fs2.existsSync(filepath) && (possibleVaultPath = filepath.endsWith(".vault") ? filepath : `${filepath}.vault`);
274
+ else
275
+ possibleVaultPath = options.path.endsWith(".vault") ? options.path : `${options.path}.vault`;
276
+ else
277
+ possibleVaultPath = path2.resolve(process.cwd(), ".env.vault");
278
+ return fs2.existsSync(possibleVaultPath) ? possibleVaultPath : null;
256
279
  }
257
- const environment = uri.searchParams.get("environment");
258
- if (!environment) {
259
- const err = new Error("INVALID_DOTENV_KEY: Missing environment part");
260
- throw err.code = "INVALID_DOTENV_KEY", err;
280
+ function _resolveHome(envPath) {
281
+ return envPath[0] === "~" ? path2.join(os.homedir(), envPath.slice(1)) : envPath;
261
282
  }
262
- const environmentKey = `DOTENV_VAULT_${environment.toUpperCase()}`, ciphertext = result.parsed[environmentKey];
263
- if (!ciphertext) {
264
- const err = new Error(`NOT_FOUND_DOTENV_ENVIRONMENT: Cannot locate environment ${environmentKey} in your .env.vault file.`);
265
- throw err.code = "NOT_FOUND_DOTENV_ENVIRONMENT", err;
283
+ function _configVault(options) {
284
+ _log("Loading env from encrypted .env.vault");
285
+ const parsed = DotenvModule._parseVault(options);
286
+ let processEnv = process.env;
287
+ return options && options.processEnv != null && (processEnv = options.processEnv), DotenvModule.populate(processEnv, parsed, options), { parsed };
266
288
  }
267
- return { ciphertext, key };
268
- }
269
- function _vaultPath(options) {
270
- let possibleVaultPath = null;
271
- if (options && options.path && options.path.length > 0)
272
- if (Array.isArray(options.path))
273
- for (const filepath of options.path)
274
- fs.existsSync(filepath) && (possibleVaultPath = filepath.endsWith(".vault") ? filepath : `${filepath}.vault`);
275
- else
276
- possibleVaultPath = options.path.endsWith(".vault") ? options.path : `${options.path}.vault`;
277
- else
278
- possibleVaultPath = path.resolve(process.cwd(), ".env.vault");
279
- return fs.existsSync(possibleVaultPath) ? possibleVaultPath : null;
280
- }
281
- function _resolveHome(envPath) {
282
- return envPath[0] === "~" ? path.join(os.homedir(), envPath.slice(1)) : envPath;
283
- }
284
- function _configVault(options) {
285
- _log("Loading env from encrypted .env.vault");
286
- const parsed = DotenvModule._parseVault(options);
287
- let processEnv = process.env;
288
- return options && options.processEnv != null && (processEnv = options.processEnv), DotenvModule.populate(processEnv, parsed, options), { parsed };
289
- }
290
- function configDotenv(options) {
291
- const dotenvPath = path.resolve(process.cwd(), ".env");
292
- let encoding = "utf8";
293
- const debug2 = !!(options && options.debug);
294
- options && options.encoding ? encoding = options.encoding : debug2 && _debug("No encoding is specified. UTF-8 is used by default");
295
- let optionPaths = [dotenvPath];
296
- if (options && options.path)
297
- if (!Array.isArray(options.path))
298
- optionPaths = [_resolveHome(options.path)];
299
- else {
300
- optionPaths = [];
301
- for (const filepath of options.path)
302
- optionPaths.push(_resolveHome(filepath));
303
- }
304
- let lastError;
305
- const parsedAll = {};
306
- for (const path2 of optionPaths)
289
+ function configDotenv(options) {
290
+ const dotenvPath = path2.resolve(process.cwd(), ".env");
291
+ let encoding = "utf8";
292
+ const debug2 = !!(options && options.debug);
293
+ options && options.encoding ? encoding = options.encoding : debug2 && _debug("No encoding is specified. UTF-8 is used by default");
294
+ let optionPaths = [dotenvPath];
295
+ if (options && options.path)
296
+ if (!Array.isArray(options.path))
297
+ optionPaths = [_resolveHome(options.path)];
298
+ else {
299
+ optionPaths = [];
300
+ for (const filepath of options.path)
301
+ optionPaths.push(_resolveHome(filepath));
302
+ }
303
+ let lastError;
304
+ const parsedAll = {};
305
+ for (const path3 of optionPaths)
306
+ try {
307
+ const parsed = DotenvModule.parse(fs2.readFileSync(path3, { encoding }));
308
+ DotenvModule.populate(parsedAll, parsed, options);
309
+ } catch (e) {
310
+ debug2 && _debug(`Failed to load ${path3} ${e.message}`), lastError = e;
311
+ }
312
+ let processEnv = process.env;
313
+ return options && options.processEnv != null && (processEnv = options.processEnv), DotenvModule.populate(processEnv, parsedAll, options), lastError ? { parsed: parsedAll, error: lastError } : { parsed: parsedAll };
314
+ }
315
+ function config(options) {
316
+ if (_dotenvKey(options).length === 0)
317
+ return DotenvModule.configDotenv(options);
318
+ const vaultPath = _vaultPath(options);
319
+ return vaultPath ? DotenvModule._configVault(options) : (_warn(`You set DOTENV_KEY but you are missing a .env.vault file at ${vaultPath}. Did you forget to build it?`), DotenvModule.configDotenv(options));
320
+ }
321
+ function decrypt(encrypted, keyStr) {
322
+ const key = Buffer.from(keyStr.slice(-64), "hex");
323
+ let ciphertext = Buffer.from(encrypted, "base64");
324
+ const nonce = ciphertext.subarray(0, 12), authTag = ciphertext.subarray(-16);
325
+ ciphertext = ciphertext.subarray(12, -16);
307
326
  try {
308
- const parsed = DotenvModule.parse(fs.readFileSync(path2, { encoding }));
309
- DotenvModule.populate(parsedAll, parsed, options);
310
- } catch (e) {
311
- debug2 && _debug(`Failed to load ${path2} ${e.message}`), lastError = e;
327
+ const aesgcm = crypto.createDecipheriv("aes-256-gcm", key, nonce);
328
+ return aesgcm.setAuthTag(authTag), `${aesgcm.update(ciphertext)}${aesgcm.final()}`;
329
+ } catch (error) {
330
+ const isRange = error instanceof RangeError, invalidKeyLength = error.message === "Invalid key length", decryptionFailed = error.message === "Unsupported state or unable to authenticate data";
331
+ if (isRange || invalidKeyLength) {
332
+ const err = new Error("INVALID_DOTENV_KEY: It must be 64 characters long (or more)");
333
+ throw err.code = "INVALID_DOTENV_KEY", err;
334
+ } else if (decryptionFailed) {
335
+ const err = new Error("DECRYPTION_FAILED: Please check your DOTENV_KEY");
336
+ throw err.code = "DECRYPTION_FAILED", err;
337
+ } else
338
+ throw error;
312
339
  }
313
- let processEnv = process.env;
314
- return options && options.processEnv != null && (processEnv = options.processEnv), DotenvModule.populate(processEnv, parsedAll, options), lastError ? { parsed: parsedAll, error: lastError } : { parsed: parsedAll };
315
- }
316
- function config(options) {
317
- if (_dotenvKey(options).length === 0)
318
- return DotenvModule.configDotenv(options);
319
- const vaultPath = _vaultPath(options);
320
- return vaultPath ? DotenvModule._configVault(options) : (_warn(`You set DOTENV_KEY but you are missing a .env.vault file at ${vaultPath}. Did you forget to build it?`), DotenvModule.configDotenv(options));
321
- }
322
- function decrypt(encrypted, keyStr) {
323
- const key = Buffer.from(keyStr.slice(-64), "hex");
324
- let ciphertext = Buffer.from(encrypted, "base64");
325
- const nonce = ciphertext.subarray(0, 12), authTag = ciphertext.subarray(-16);
326
- ciphertext = ciphertext.subarray(12, -16);
327
- try {
328
- const aesgcm = crypto.createDecipheriv("aes-256-gcm", key, nonce);
329
- return aesgcm.setAuthTag(authTag), `${aesgcm.update(ciphertext)}${aesgcm.final()}`;
330
- } catch (error) {
331
- const isRange = error instanceof RangeError, invalidKeyLength = error.message === "Invalid key length", decryptionFailed = error.message === "Unsupported state or unable to authenticate data";
332
- if (isRange || invalidKeyLength) {
333
- const err = new Error("INVALID_DOTENV_KEY: It must be 64 characters long (or more)");
334
- throw err.code = "INVALID_DOTENV_KEY", err;
335
- } else if (decryptionFailed) {
336
- const err = new Error("DECRYPTION_FAILED: Please check your DOTENV_KEY");
337
- throw err.code = "DECRYPTION_FAILED", err;
338
- } else
339
- throw error;
340
340
  }
341
- }
342
- function populate(processEnv, parsed, options = {}) {
343
- const debug2 = !!(options && options.debug), override = !!(options && options.override);
344
- if (typeof parsed != "object") {
345
- const err = new Error("OBJECT_REQUIRED: Please check the processEnv argument being passed to populate");
346
- throw err.code = "OBJECT_REQUIRED", err;
341
+ function populate(processEnv, parsed, options = {}) {
342
+ const debug2 = !!(options && options.debug), override = !!(options && options.override);
343
+ if (typeof parsed != "object") {
344
+ const err = new Error("OBJECT_REQUIRED: Please check the processEnv argument being passed to populate");
345
+ throw err.code = "OBJECT_REQUIRED", err;
346
+ }
347
+ for (const key of Object.keys(parsed))
348
+ Object.prototype.hasOwnProperty.call(processEnv, key) ? (override === !0 && (processEnv[key] = parsed[key]), debug2 && _debug(override === !0 ? `"${key}" is already defined and WAS overwritten` : `"${key}" is already defined and was NOT overwritten`)) : processEnv[key] = parsed[key];
347
349
  }
348
- for (const key of Object.keys(parsed))
349
- Object.prototype.hasOwnProperty.call(processEnv, key) ? (override === !0 && (processEnv[key] = parsed[key]), debug2 && _debug(override === !0 ? `"${key}" is already defined and WAS overwritten` : `"${key}" is already defined and was NOT overwritten`)) : processEnv[key] = parsed[key];
350
- }
351
- const DotenvModule = {
352
- configDotenv,
353
- _configVault,
354
- _parseVault,
355
- config,
356
- decrypt,
357
- parse,
358
- populate
359
- };
360
- main$1.exports.configDotenv = DotenvModule.configDotenv;
361
- main$1.exports._configVault = DotenvModule._configVault;
362
- main$1.exports._parseVault = DotenvModule._parseVault;
363
- main$1.exports.config = DotenvModule.config;
364
- main$1.exports.decrypt = DotenvModule.decrypt;
365
- var parse_1 = main$1.exports.parse = DotenvModule.parse;
366
- main$1.exports.populate = DotenvModule.populate;
367
- main$1.exports = DotenvModule;
368
- function _interpolate(envValue, environment, config2) {
369
- const matches = envValue.match(/(.?\${*[\w]*(?::-[\w/]*)?}*)/g) || [];
370
- return matches.reduce(function(newEnv, match, index) {
371
- const parts = /(.?)\${*([\w]*(?::-[\w/]*)?)?}*/g.exec(match);
372
- if (!parts || parts.length === 0)
373
- return newEnv;
374
- const prefix = parts[1];
375
- let value, replacePart;
376
- if (prefix === "\\")
377
- replacePart = parts[0], value = replacePart.replace("\\$", "$");
378
- else {
379
- const keyParts = parts[2].split(":-"), key = keyParts[0];
380
- if (replacePart = parts[0].substring(prefix.length), value = Object.prototype.hasOwnProperty.call(environment, key) ? environment[key] : config2.parsed[key] || keyParts[1] || "", keyParts.length > 1 && value) {
381
- const replaceNested = matches[index + 1];
382
- matches[index + 1] = "", newEnv = newEnv.replace(replaceNested, "");
350
+ const DotenvModule = {
351
+ configDotenv,
352
+ _configVault,
353
+ _parseVault,
354
+ config,
355
+ decrypt,
356
+ parse,
357
+ populate
358
+ };
359
+ return main$2.exports.configDotenv = DotenvModule.configDotenv, main$2.exports._configVault = DotenvModule._configVault, main$2.exports._parseVault = DotenvModule._parseVault, main$2.exports.config = DotenvModule.config, main$2.exports.decrypt = DotenvModule.decrypt, main$2.exports.parse = DotenvModule.parse, main$2.exports.populate = DotenvModule.populate, main$2.exports = DotenvModule, main$2.exports;
360
+ }
361
+ var mainExports$1 = requireMain$1(), main = {}, hasRequiredMain;
362
+ function requireMain() {
363
+ if (hasRequiredMain) return main;
364
+ hasRequiredMain = 1;
365
+ function _interpolate(envValue, environment, config) {
366
+ const matches = envValue.match(/(.?\${*[\w]*(?::-[\w/]*)?}*)/g) || [];
367
+ return matches.reduce(function(newEnv, match, index) {
368
+ const parts = /(.?)\${*([\w]*(?::-[\w/]*)?)?}*/g.exec(match);
369
+ if (!parts || parts.length === 0)
370
+ return newEnv;
371
+ const prefix = parts[1];
372
+ let value, replacePart;
373
+ if (prefix === "\\")
374
+ replacePart = parts[0], value = replacePart.replace("\\$", "$");
375
+ else {
376
+ const keyParts = parts[2].split(":-"), key = keyParts[0];
377
+ if (replacePart = parts[0].substring(prefix.length), value = Object.prototype.hasOwnProperty.call(environment, key) ? environment[key] : config.parsed[key] || keyParts[1] || "", keyParts.length > 1 && value) {
378
+ const replaceNested = matches[index + 1];
379
+ matches[index + 1] = "", newEnv = newEnv.replace(replaceNested, "");
380
+ }
381
+ value = _interpolate(value, environment, config);
383
382
  }
384
- value = _interpolate(value, environment, config2);
383
+ return newEnv.replace(replacePart, value);
384
+ }, envValue);
385
+ }
386
+ function expand(config) {
387
+ const environment = config.ignoreProcessEnv ? {} : process.env;
388
+ for (const configKey in config.parsed) {
389
+ const value = Object.prototype.hasOwnProperty.call(environment, configKey) ? environment[configKey] : config.parsed[configKey];
390
+ config.parsed[configKey] = _interpolate(value, environment, config);
385
391
  }
386
- return newEnv.replace(replacePart, value);
387
- }, envValue);
388
- }
389
- function expand(config2) {
390
- const environment = config2.ignoreProcessEnv ? {} : process.env;
391
- for (const configKey in config2.parsed) {
392
- const value = Object.prototype.hasOwnProperty.call(environment, configKey) ? environment[configKey] : config2.parsed[configKey];
393
- config2.parsed[configKey] = _interpolate(value, environment, config2);
392
+ for (const processKey in config.parsed)
393
+ environment[processKey] = config.parsed[processKey];
394
+ return config;
394
395
  }
395
- for (const processKey in config2.parsed)
396
- environment[processKey] = config2.parsed[processKey];
397
- return config2;
396
+ return main.expand = expand, main;
398
397
  }
399
- var expand_1 = expand;
398
+ var mainExports = requireMain();
400
399
  function loadEnv(mode, envDir, prefixes = ["VITE_"]) {
401
400
  if (mode === "local")
402
401
  throw new Error(
@@ -416,12 +415,12 @@ function loadEnv(mode, envDir, prefixes = ["VITE_"]) {
416
415
  const envPath = lookupFile(envDir, [file], {
417
416
  rootDir: envDir
418
417
  });
419
- return envPath ? Object.entries(parse_1(fs$1.readFileSync(envPath))) : [];
418
+ return envPath ? Object.entries(mainExports$1.parse(fs.readFileSync(envPath))) : [];
420
419
  })
421
420
  );
422
421
  parsed.NODE_ENV && process.env.VITE_USER_NODE_ENV === void 0 && (process.env.VITE_USER_NODE_ENV = parsed.NODE_ENV), parsed.BROWSER && process.env.BROWSER === void 0 && (process.env.BROWSER = parsed.BROWSER), parsed.BROWSER_ARGS && process.env.BROWSER_ARGS === void 0 && (process.env.BROWSER_ARGS = parsed.BROWSER_ARGS);
423
422
  try {
424
- expand_1({ parsed });
423
+ mainExports.expand({ parsed });
425
424
  } catch (e) {
426
425
  throw e.message.includes("split") ? new Error("dotenv-expand failed to expand env vars. Maybe you need to escape `$`?") : e;
427
426
  }
@@ -433,11 +432,11 @@ function loadEnv(mode, envDir, prefixes = ["VITE_"]) {
433
432
  }
434
433
  function lookupFile(dir, formats, options) {
435
434
  for (const format of formats) {
436
- const fullPath = path$1.join(dir, format);
437
- if (fs$1.existsSync(fullPath) && fs$1.statSync(fullPath).isFile())
435
+ const fullPath = path.join(dir, format);
436
+ if (fs.existsSync(fullPath) && fs.statSync(fullPath).isFile())
438
437
  return fullPath;
439
438
  }
440
- const parentDir = path$1.dirname(dir);
439
+ const parentDir = path.dirname(dir);
441
440
  if (parentDir !== dir && (!options?.rootDir || parentDir.startsWith(options?.rootDir)))
442
441
  return lookupFile(parentDir, formats, options);
443
442
  }