@sanity/cli 3.60.0 → 3.61.1-manifests.18
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/xdg-open +1066 -0
- package/lib/_chunks-cjs/cli.js +21967 -20861
- package/lib/_chunks-cjs/cli.js.map +1 -1
- package/lib/_chunks-cjs/loadEnv.js +196 -194
- package/lib/_chunks-cjs/loadEnv.js.map +1 -1
- package/lib/index.esm.js +219 -216
- package/lib/index.esm.js.map +1 -1
- package/lib/index.mjs +219 -216
- package/lib/index.mjs.map +1 -1
- package/package.json +7 -7
- package/src/commands/index.ts +2 -0
- package/src/commands/learn/learnCommand.ts +20 -0
package/lib/index.esm.js
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
import { createClient } from "@sanity/client";
|
2
|
-
import fs
|
3
|
-
import 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
|
20
|
-
return fs
|
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
|
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
|
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
|
49
|
-
if (
|
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
|
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
|
71
|
-
fileExists(path
|
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
|
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
|
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
|
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
|
107
|
-
if (!
|
106
|
+
const rootDir = resolveRootDir(cwd), { config } = getCliConfigSync(rootDir) || {};
|
107
|
+
if (!config)
|
108
108
|
throw new Error("Unable to resolve CLI configuration");
|
109
|
-
const apiConfig =
|
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(
|
123
|
-
return
|
122
|
+
function defineCliConfig(config) {
|
123
|
+
return config;
|
124
124
|
}
|
125
|
-
function createCliConfig(
|
126
|
-
return
|
125
|
+
function createCliConfig(config) {
|
126
|
+
return config;
|
127
127
|
}
|
128
|
-
var main$
|
128
|
+
var main$2 = { exports: {} }, name = "dotenv", version = "16.4.5", 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",
|
@@ -175,9 +175,9 @@ var main$1 = { exports: {} }, name = "dotenv", version$1 = "16.4.5", description
|
|
175
175
|
fs: !1
|
176
176
|
}, require$$4 = {
|
177
177
|
name,
|
178
|
-
version
|
178
|
+
version,
|
179
179
|
description,
|
180
|
-
main,
|
180
|
+
main: main$1,
|
181
181
|
types,
|
182
182
|
exports,
|
183
183
|
scripts,
|
@@ -189,214 +189,217 @@ var main$1 = { exports: {} }, name = "dotenv", version$1 = "16.4.5", description
|
|
189
189
|
devDependencies,
|
190
190
|
engines,
|
191
191
|
browser
|
192
|
-
};
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
192
|
+
}, hasRequiredMain$1;
|
193
|
+
function requireMain$1() {
|
194
|
+
if (hasRequiredMain$1) return main$2.exports;
|
195
|
+
hasRequiredMain$1 = 1;
|
196
|
+
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;
|
197
|
+
function parse(src) {
|
198
|
+
const obj = {};
|
199
|
+
let lines = src.toString();
|
200
|
+
lines = lines.replace(/\r\n?/mg, `
|
198
201
|
`);
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
202
|
+
let match;
|
203
|
+
for (; (match = LINE.exec(lines)) != null; ) {
|
204
|
+
const key = match[1];
|
205
|
+
let value = match[2] || "";
|
206
|
+
value = value.trim();
|
207
|
+
const maybeQuote = value[0];
|
208
|
+
value = value.replace(/^(['"`])([\s\S]*)\1$/mg, "$2"), maybeQuote === '"' && (value = value.replace(/\\n/g, `
|
206
209
|
`), value = value.replace(/\\r/g, "\r")), obj[key] = value;
|
210
|
+
}
|
211
|
+
return obj;
|
207
212
|
}
|
208
|
-
|
209
|
-
}
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
213
|
+
function _parseVault(options) {
|
214
|
+
const vaultPath = _vaultPath(options), result = DotenvModule.configDotenv({ path: vaultPath });
|
215
|
+
if (!result.parsed) {
|
216
|
+
const err = new Error(`MISSING_DATA: Cannot parse ${vaultPath} for an unknown reason`);
|
217
|
+
throw err.code = "MISSING_DATA", err;
|
218
|
+
}
|
219
|
+
const keys = _dotenvKey(options).split(","), length = keys.length;
|
220
|
+
let decrypted;
|
221
|
+
for (let i = 0; i < length; i++)
|
222
|
+
try {
|
223
|
+
const key = keys[i].trim(), attrs = _instructions(result, key);
|
224
|
+
decrypted = DotenvModule.decrypt(attrs.ciphertext, attrs.key);
|
225
|
+
break;
|
226
|
+
} catch (error) {
|
227
|
+
if (i + 1 >= length)
|
228
|
+
throw error;
|
229
|
+
}
|
230
|
+
return DotenvModule.parse(decrypted);
|
231
|
+
}
|
232
|
+
function _log(message) {
|
233
|
+
console.log(`[dotenv@${version2}][INFO] ${message}`);
|
215
234
|
}
|
216
|
-
|
217
|
-
|
218
|
-
|
235
|
+
function _warn(message) {
|
236
|
+
console.log(`[dotenv@${version2}][WARN] ${message}`);
|
237
|
+
}
|
238
|
+
function _debug(message) {
|
239
|
+
console.log(`[dotenv@${version2}][DEBUG] ${message}`);
|
240
|
+
}
|
241
|
+
function _dotenvKey(options) {
|
242
|
+
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 : "";
|
243
|
+
}
|
244
|
+
function _instructions(result, dotenvKey) {
|
245
|
+
let uri;
|
219
246
|
try {
|
220
|
-
|
221
|
-
decrypted = DotenvModule.decrypt(attrs.ciphertext, attrs.key);
|
222
|
-
break;
|
247
|
+
uri = new URL(dotenvKey);
|
223
248
|
} catch (error) {
|
224
|
-
if (
|
225
|
-
|
249
|
+
if (error.code === "ERR_INVALID_URL") {
|
250
|
+
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
|
+
throw err.code = "INVALID_DOTENV_KEY", err;
|
252
|
+
}
|
253
|
+
throw error;
|
226
254
|
}
|
227
|
-
|
228
|
-
|
229
|
-
|
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");
|
255
|
+
const key = uri.password;
|
256
|
+
if (!key) {
|
257
|
+
const err = new Error("INVALID_DOTENV_KEY: Missing key part");
|
248
258
|
throw err.code = "INVALID_DOTENV_KEY", err;
|
249
259
|
}
|
250
|
-
|
260
|
+
const environment = uri.searchParams.get("environment");
|
261
|
+
if (!environment) {
|
262
|
+
const err = new Error("INVALID_DOTENV_KEY: Missing environment part");
|
263
|
+
throw err.code = "INVALID_DOTENV_KEY", err;
|
264
|
+
}
|
265
|
+
const environmentKey = `DOTENV_VAULT_${environment.toUpperCase()}`, ciphertext = result.parsed[environmentKey];
|
266
|
+
if (!ciphertext) {
|
267
|
+
const err = new Error(`NOT_FOUND_DOTENV_ENVIRONMENT: Cannot locate environment ${environmentKey} in your .env.vault file.`);
|
268
|
+
throw err.code = "NOT_FOUND_DOTENV_ENVIRONMENT", err;
|
269
|
+
}
|
270
|
+
return { ciphertext, key };
|
251
271
|
}
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
272
|
+
function _vaultPath(options) {
|
273
|
+
let possibleVaultPath = null;
|
274
|
+
if (options && options.path && options.path.length > 0)
|
275
|
+
if (Array.isArray(options.path))
|
276
|
+
for (const filepath of options.path)
|
277
|
+
fs2.existsSync(filepath) && (possibleVaultPath = filepath.endsWith(".vault") ? filepath : `${filepath}.vault`);
|
278
|
+
else
|
279
|
+
possibleVaultPath = options.path.endsWith(".vault") ? options.path : `${options.path}.vault`;
|
280
|
+
else
|
281
|
+
possibleVaultPath = path2.resolve(process.cwd(), ".env.vault");
|
282
|
+
return fs2.existsSync(possibleVaultPath) ? possibleVaultPath : null;
|
256
283
|
}
|
257
|
-
|
258
|
-
|
259
|
-
const err = new Error("INVALID_DOTENV_KEY: Missing environment part");
|
260
|
-
throw err.code = "INVALID_DOTENV_KEY", err;
|
284
|
+
function _resolveHome(envPath) {
|
285
|
+
return envPath[0] === "~" ? path2.join(os.homedir(), envPath.slice(1)) : envPath;
|
261
286
|
}
|
262
|
-
|
263
|
-
|
264
|
-
const
|
265
|
-
|
287
|
+
function _configVault(options) {
|
288
|
+
_log("Loading env from encrypted .env.vault");
|
289
|
+
const parsed = DotenvModule._parseVault(options);
|
290
|
+
let processEnv = process.env;
|
291
|
+
return options && options.processEnv != null && (processEnv = options.processEnv), DotenvModule.populate(processEnv, parsed, options), { parsed };
|
266
292
|
}
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
}
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
}
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
let lastError;
|
305
|
-
const parsedAll = {};
|
306
|
-
for (const path2 of optionPaths)
|
293
|
+
function configDotenv(options) {
|
294
|
+
const dotenvPath = path2.resolve(process.cwd(), ".env");
|
295
|
+
let encoding = "utf8";
|
296
|
+
const debug2 = !!(options && options.debug);
|
297
|
+
options && options.encoding ? encoding = options.encoding : debug2 && _debug("No encoding is specified. UTF-8 is used by default");
|
298
|
+
let optionPaths = [dotenvPath];
|
299
|
+
if (options && options.path)
|
300
|
+
if (!Array.isArray(options.path))
|
301
|
+
optionPaths = [_resolveHome(options.path)];
|
302
|
+
else {
|
303
|
+
optionPaths = [];
|
304
|
+
for (const filepath of options.path)
|
305
|
+
optionPaths.push(_resolveHome(filepath));
|
306
|
+
}
|
307
|
+
let lastError;
|
308
|
+
const parsedAll = {};
|
309
|
+
for (const path3 of optionPaths)
|
310
|
+
try {
|
311
|
+
const parsed = DotenvModule.parse(fs2.readFileSync(path3, { encoding }));
|
312
|
+
DotenvModule.populate(parsedAll, parsed, options);
|
313
|
+
} catch (e) {
|
314
|
+
debug2 && _debug(`Failed to load ${path3} ${e.message}`), lastError = e;
|
315
|
+
}
|
316
|
+
let processEnv = process.env;
|
317
|
+
return options && options.processEnv != null && (processEnv = options.processEnv), DotenvModule.populate(processEnv, parsedAll, options), lastError ? { parsed: parsedAll, error: lastError } : { parsed: parsedAll };
|
318
|
+
}
|
319
|
+
function config(options) {
|
320
|
+
if (_dotenvKey(options).length === 0)
|
321
|
+
return DotenvModule.configDotenv(options);
|
322
|
+
const vaultPath = _vaultPath(options);
|
323
|
+
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));
|
324
|
+
}
|
325
|
+
function decrypt(encrypted, keyStr) {
|
326
|
+
const key = Buffer.from(keyStr.slice(-64), "hex");
|
327
|
+
let ciphertext = Buffer.from(encrypted, "base64");
|
328
|
+
const nonce = ciphertext.subarray(0, 12), authTag = ciphertext.subarray(-16);
|
329
|
+
ciphertext = ciphertext.subarray(12, -16);
|
307
330
|
try {
|
308
|
-
const
|
309
|
-
|
310
|
-
} catch (
|
311
|
-
|
331
|
+
const aesgcm = crypto.createDecipheriv("aes-256-gcm", key, nonce);
|
332
|
+
return aesgcm.setAuthTag(authTag), `${aesgcm.update(ciphertext)}${aesgcm.final()}`;
|
333
|
+
} catch (error) {
|
334
|
+
const isRange = error instanceof RangeError, invalidKeyLength = error.message === "Invalid key length", decryptionFailed = error.message === "Unsupported state or unable to authenticate data";
|
335
|
+
if (isRange || invalidKeyLength) {
|
336
|
+
const err = new Error("INVALID_DOTENV_KEY: It must be 64 characters long (or more)");
|
337
|
+
throw err.code = "INVALID_DOTENV_KEY", err;
|
338
|
+
} else if (decryptionFailed) {
|
339
|
+
const err = new Error("DECRYPTION_FAILED: Please check your DOTENV_KEY");
|
340
|
+
throw err.code = "DECRYPTION_FAILED", err;
|
341
|
+
} else
|
342
|
+
throw error;
|
312
343
|
}
|
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
344
|
}
|
341
|
-
}
|
342
|
-
|
343
|
-
|
344
|
-
|
345
|
-
|
346
|
-
|
345
|
+
function populate(processEnv, parsed, options = {}) {
|
346
|
+
const debug2 = !!(options && options.debug), override = !!(options && options.override);
|
347
|
+
if (typeof parsed != "object") {
|
348
|
+
const err = new Error("OBJECT_REQUIRED: Please check the processEnv argument being passed to populate");
|
349
|
+
throw err.code = "OBJECT_REQUIRED", err;
|
350
|
+
}
|
351
|
+
for (const key of Object.keys(parsed))
|
352
|
+
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
353
|
}
|
348
|
-
|
349
|
-
|
350
|
-
|
351
|
-
|
352
|
-
|
353
|
-
|
354
|
-
|
355
|
-
|
356
|
-
|
357
|
-
parse,
|
358
|
-
|
359
|
-
};
|
360
|
-
|
361
|
-
|
362
|
-
|
363
|
-
|
364
|
-
|
365
|
-
|
366
|
-
|
367
|
-
|
368
|
-
|
369
|
-
|
370
|
-
|
371
|
-
|
372
|
-
|
373
|
-
|
374
|
-
|
375
|
-
|
376
|
-
|
377
|
-
|
378
|
-
|
379
|
-
|
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, "");
|
354
|
+
const DotenvModule = {
|
355
|
+
configDotenv,
|
356
|
+
_configVault,
|
357
|
+
_parseVault,
|
358
|
+
config,
|
359
|
+
decrypt,
|
360
|
+
parse,
|
361
|
+
populate
|
362
|
+
};
|
363
|
+
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;
|
364
|
+
}
|
365
|
+
var mainExports$1 = requireMain$1(), main = {}, hasRequiredMain;
|
366
|
+
function requireMain() {
|
367
|
+
if (hasRequiredMain) return main;
|
368
|
+
hasRequiredMain = 1;
|
369
|
+
function _interpolate(envValue, environment, config) {
|
370
|
+
const matches = envValue.match(/(.?\${*[\w]*(?::-[\w/]*)?}*)/g) || [];
|
371
|
+
return matches.reduce(function(newEnv, match, index) {
|
372
|
+
const parts = /(.?)\${*([\w]*(?::-[\w/]*)?)?}*/g.exec(match);
|
373
|
+
if (!parts || parts.length === 0)
|
374
|
+
return newEnv;
|
375
|
+
const prefix = parts[1];
|
376
|
+
let value, replacePart;
|
377
|
+
if (prefix === "\\")
|
378
|
+
replacePart = parts[0], value = replacePart.replace("\\$", "$");
|
379
|
+
else {
|
380
|
+
const keyParts = parts[2].split(":-"), key = keyParts[0];
|
381
|
+
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) {
|
382
|
+
const replaceNested = matches[index + 1];
|
383
|
+
matches[index + 1] = "", newEnv = newEnv.replace(replaceNested, "");
|
384
|
+
}
|
385
|
+
value = _interpolate(value, environment, config);
|
383
386
|
}
|
384
|
-
|
387
|
+
return newEnv.replace(replacePart, value);
|
388
|
+
}, envValue);
|
389
|
+
}
|
390
|
+
function expand(config) {
|
391
|
+
const environment = config.ignoreProcessEnv ? {} : process.env;
|
392
|
+
for (const configKey in config.parsed) {
|
393
|
+
const value = Object.prototype.hasOwnProperty.call(environment, configKey) ? environment[configKey] : config.parsed[configKey];
|
394
|
+
config.parsed[configKey] = _interpolate(value, environment, config);
|
385
395
|
}
|
386
|
-
|
387
|
-
|
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);
|
396
|
+
for (const processKey in config.parsed)
|
397
|
+
environment[processKey] = config.parsed[processKey];
|
398
|
+
return config;
|
394
399
|
}
|
395
|
-
|
396
|
-
environment[processKey] = config2.parsed[processKey];
|
397
|
-
return config2;
|
400
|
+
return main.expand = expand, main;
|
398
401
|
}
|
399
|
-
var
|
402
|
+
var mainExports = requireMain();
|
400
403
|
function loadEnv(mode, envDir, prefixes = ["VITE_"]) {
|
401
404
|
if (mode === "local")
|
402
405
|
throw new Error(
|
@@ -416,12 +419,12 @@ function loadEnv(mode, envDir, prefixes = ["VITE_"]) {
|
|
416
419
|
const envPath = lookupFile(envDir, [file], {
|
417
420
|
rootDir: envDir
|
418
421
|
});
|
419
|
-
return envPath ? Object.entries(
|
422
|
+
return envPath ? Object.entries(mainExports$1.parse(fs.readFileSync(envPath))) : [];
|
420
423
|
})
|
421
424
|
);
|
422
425
|
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
426
|
try {
|
424
|
-
|
427
|
+
mainExports.expand({ parsed });
|
425
428
|
} catch (e) {
|
426
429
|
throw e.message.includes("split") ? new Error("dotenv-expand failed to expand env vars. Maybe you need to escape `$`?") : e;
|
427
430
|
}
|
@@ -433,11 +436,11 @@ function loadEnv(mode, envDir, prefixes = ["VITE_"]) {
|
|
433
436
|
}
|
434
437
|
function lookupFile(dir, formats, options) {
|
435
438
|
for (const format of formats) {
|
436
|
-
const fullPath = path
|
437
|
-
if (fs
|
439
|
+
const fullPath = path.join(dir, format);
|
440
|
+
if (fs.existsSync(fullPath) && fs.statSync(fullPath).isFile())
|
438
441
|
return fullPath;
|
439
442
|
}
|
440
|
-
const parentDir = path
|
443
|
+
const parentDir = path.dirname(dir);
|
441
444
|
if (parentDir !== dir && (!options?.rootDir || parentDir.startsWith(options?.rootDir)))
|
442
445
|
return lookupFile(parentDir, formats, options);
|
443
446
|
}
|