sandbox 2.0.0-alpha5 → 2.0.1
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/LICENSE +18 -12
- package/README.md +18 -93
- package/bin/sandbox.mjs +3 -0
- package/dist/ansi-styles-B57ln_zO.mjs +168 -0
- package/dist/ansi-styles-B57ln_zO.mjs.map +1 -0
- package/dist/app-rsOUZPpL.mjs +14168 -0
- package/dist/app-rsOUZPpL.mjs.map +1 -0
- package/dist/chunk-btbCw1m3.mjs +52 -0
- package/dist/cli-cursor-Dab4mDU2.mjs +348 -0
- package/dist/cli-cursor-Dab4mDU2.mjs.map +1 -0
- package/dist/cli-truncate-DMIDACmY.mjs +124 -0
- package/dist/cli-truncate-DMIDACmY.mjs.map +1 -0
- package/dist/index.d.mts +10 -0
- package/dist/index.mjs +17 -0
- package/dist/index.mjs.map +1 -0
- package/dist/log-update-txb7Or7B.mjs +223 -0
- package/dist/log-update-txb7Or7B.mjs.map +1 -0
- package/dist/pty-server-linux-x86_64 +0 -0
- package/dist/sandbox.d.mts +1 -0
- package/dist/sandbox.mjs +647 -0
- package/dist/sandbox.mjs.map +1 -0
- package/dist/string-width-D78SVDLD.mjs +85 -0
- package/dist/string-width-D78SVDLD.mjs.map +1 -0
- package/dist/token-Bwtve9Y6.mjs +51 -0
- package/dist/token-Bwtve9Y6.mjs.map +1 -0
- package/dist/token-error-C0CafU2G.mjs +43 -0
- package/dist/token-error-C0CafU2G.mjs.map +1 -0
- package/dist/token-util-BpWskZEO.mjs +357 -0
- package/dist/token-util-BpWskZEO.mjs.map +1 -0
- package/dist/token-util-CRAtcwBI.mjs +6 -0
- package/dist/wrap-ansi-CEi7ZT5i.mjs +5 -0
- package/dist/wrap-ansi-DoQ74EEn.mjs +130 -0
- package/dist/wrap-ansi-DoQ74EEn.mjs.map +1 -0
- package/package.json +52 -31
- package/index.js +0 -29
- package/install.js +0 -5
- package/platform-target.js +0 -217
package/dist/sandbox.mjs
ADDED
|
@@ -0,0 +1,647 @@
|
|
|
1
|
+
import { i as __require, s as __toESM, t as __commonJS } from "./chunk-btbCw1m3.mjs";
|
|
2
|
+
import { n as StyledError, r as require_cjs, t as app } from "./app-rsOUZPpL.mjs";
|
|
3
|
+
import "./string-width-D78SVDLD.mjs";
|
|
4
|
+
import "./cli-cursor-Dab4mDU2.mjs";
|
|
5
|
+
import "./token-error-C0CafU2G.mjs";
|
|
6
|
+
|
|
7
|
+
//#region ../../node_modules/.pnpm/dotenv@16.5.0/node_modules/dotenv/package.json
|
|
8
|
+
var require_package$1 = /* @__PURE__ */ __commonJS({ "../../node_modules/.pnpm/dotenv@16.5.0/node_modules/dotenv/package.json": ((exports, module) => {
|
|
9
|
+
module.exports = {
|
|
10
|
+
"name": "dotenv",
|
|
11
|
+
"version": "16.5.0",
|
|
12
|
+
"description": "Loads environment variables from .env file",
|
|
13
|
+
"main": "lib/main.js",
|
|
14
|
+
"types": "lib/main.d.ts",
|
|
15
|
+
"exports": {
|
|
16
|
+
".": {
|
|
17
|
+
"types": "./lib/main.d.ts",
|
|
18
|
+
"require": "./lib/main.js",
|
|
19
|
+
"default": "./lib/main.js"
|
|
20
|
+
},
|
|
21
|
+
"./config": "./config.js",
|
|
22
|
+
"./config.js": "./config.js",
|
|
23
|
+
"./lib/env-options": "./lib/env-options.js",
|
|
24
|
+
"./lib/env-options.js": "./lib/env-options.js",
|
|
25
|
+
"./lib/cli-options": "./lib/cli-options.js",
|
|
26
|
+
"./lib/cli-options.js": "./lib/cli-options.js",
|
|
27
|
+
"./package.json": "./package.json"
|
|
28
|
+
},
|
|
29
|
+
"scripts": {
|
|
30
|
+
"dts-check": "tsc --project tests/types/tsconfig.json",
|
|
31
|
+
"lint": "standard",
|
|
32
|
+
"pretest": "npm run lint && npm run dts-check",
|
|
33
|
+
"test": "tap run --allow-empty-coverage --disable-coverage --timeout=60000",
|
|
34
|
+
"test:coverage": "tap run --show-full-coverage --timeout=60000 --coverage-report=lcov",
|
|
35
|
+
"prerelease": "npm test",
|
|
36
|
+
"release": "standard-version"
|
|
37
|
+
},
|
|
38
|
+
"repository": {
|
|
39
|
+
"type": "git",
|
|
40
|
+
"url": "git://github.com/motdotla/dotenv.git"
|
|
41
|
+
},
|
|
42
|
+
"homepage": "https://github.com/motdotla/dotenv#readme",
|
|
43
|
+
"funding": "https://dotenvx.com",
|
|
44
|
+
"keywords": [
|
|
45
|
+
"dotenv",
|
|
46
|
+
"env",
|
|
47
|
+
".env",
|
|
48
|
+
"environment",
|
|
49
|
+
"variables",
|
|
50
|
+
"config",
|
|
51
|
+
"settings"
|
|
52
|
+
],
|
|
53
|
+
"readmeFilename": "README.md",
|
|
54
|
+
"license": "BSD-2-Clause",
|
|
55
|
+
"devDependencies": {
|
|
56
|
+
"@types/node": "^18.11.3",
|
|
57
|
+
"decache": "^4.6.2",
|
|
58
|
+
"sinon": "^14.0.1",
|
|
59
|
+
"standard": "^17.0.0",
|
|
60
|
+
"standard-version": "^9.5.0",
|
|
61
|
+
"tap": "^19.2.0",
|
|
62
|
+
"typescript": "^4.8.4"
|
|
63
|
+
},
|
|
64
|
+
"engines": { "node": ">=12" },
|
|
65
|
+
"browser": { "fs": false }
|
|
66
|
+
};
|
|
67
|
+
}) });
|
|
68
|
+
|
|
69
|
+
//#endregion
|
|
70
|
+
//#region ../../node_modules/.pnpm/dotenv@16.5.0/node_modules/dotenv/lib/main.js
|
|
71
|
+
var require_main = /* @__PURE__ */ __commonJS({ "../../node_modules/.pnpm/dotenv@16.5.0/node_modules/dotenv/lib/main.js": ((exports, module) => {
|
|
72
|
+
const fs$1 = __require("fs");
|
|
73
|
+
const path = __require("path");
|
|
74
|
+
const os = __require("os");
|
|
75
|
+
const crypto = __require("crypto");
|
|
76
|
+
const version$1 = require_package$1().version;
|
|
77
|
+
const LINE = /(?:^|^)\s*(?:export\s+)?([\w.-]+)(?:\s*=\s*?|:\s+?)(\s*'(?:\\'|[^'])*'|\s*"(?:\\"|[^"])*"|\s*`(?:\\`|[^`])*`|[^#\r\n]+)?\s*(?:#.*)?(?:$|$)/gm;
|
|
78
|
+
function parse$1(src) {
|
|
79
|
+
const obj = {};
|
|
80
|
+
let lines = src.toString();
|
|
81
|
+
lines = lines.replace(/\r\n?/gm, "\n");
|
|
82
|
+
let match;
|
|
83
|
+
while ((match = LINE.exec(lines)) != null) {
|
|
84
|
+
const key = match[1];
|
|
85
|
+
let value = match[2] || "";
|
|
86
|
+
value = value.trim();
|
|
87
|
+
const maybeQuote = value[0];
|
|
88
|
+
value = value.replace(/^(['"`])([\s\S]*)\1$/gm, "$2");
|
|
89
|
+
if (maybeQuote === "\"") {
|
|
90
|
+
value = value.replace(/\\n/g, "\n");
|
|
91
|
+
value = value.replace(/\\r/g, "\r");
|
|
92
|
+
}
|
|
93
|
+
obj[key] = value;
|
|
94
|
+
}
|
|
95
|
+
return obj;
|
|
96
|
+
}
|
|
97
|
+
function _parseVault(options) {
|
|
98
|
+
const vaultPath = _vaultPath(options);
|
|
99
|
+
const result = DotenvModule.configDotenv({ path: vaultPath });
|
|
100
|
+
if (!result.parsed) {
|
|
101
|
+
const err = /* @__PURE__ */ new Error(`MISSING_DATA: Cannot parse ${vaultPath} for an unknown reason`);
|
|
102
|
+
err.code = "MISSING_DATA";
|
|
103
|
+
throw err;
|
|
104
|
+
}
|
|
105
|
+
const keys = _dotenvKey(options).split(",");
|
|
106
|
+
const length = keys.length;
|
|
107
|
+
let decrypted;
|
|
108
|
+
for (let i = 0; i < length; i++) try {
|
|
109
|
+
const attrs = _instructions(result, keys[i].trim());
|
|
110
|
+
decrypted = DotenvModule.decrypt(attrs.ciphertext, attrs.key);
|
|
111
|
+
break;
|
|
112
|
+
} catch (error) {
|
|
113
|
+
if (i + 1 >= length) throw error;
|
|
114
|
+
}
|
|
115
|
+
return DotenvModule.parse(decrypted);
|
|
116
|
+
}
|
|
117
|
+
function _warn(message) {
|
|
118
|
+
console.log(`[dotenv@${version$1}][WARN] ${message}`);
|
|
119
|
+
}
|
|
120
|
+
function _debug(message) {
|
|
121
|
+
console.log(`[dotenv@${version$1}][DEBUG] ${message}`);
|
|
122
|
+
}
|
|
123
|
+
function _dotenvKey(options) {
|
|
124
|
+
if (options && options.DOTENV_KEY && options.DOTENV_KEY.length > 0) return options.DOTENV_KEY;
|
|
125
|
+
if (process.env.DOTENV_KEY && process.env.DOTENV_KEY.length > 0) return process.env.DOTENV_KEY;
|
|
126
|
+
return "";
|
|
127
|
+
}
|
|
128
|
+
function _instructions(result, dotenvKey) {
|
|
129
|
+
let uri;
|
|
130
|
+
try {
|
|
131
|
+
uri = new URL(dotenvKey);
|
|
132
|
+
} catch (error) {
|
|
133
|
+
if (error.code === "ERR_INVALID_URL") {
|
|
134
|
+
const err = /* @__PURE__ */ new Error("INVALID_DOTENV_KEY: Wrong format. Must be in valid uri format like dotenv://:key_1234@dotenvx.com/vault/.env.vault?environment=development");
|
|
135
|
+
err.code = "INVALID_DOTENV_KEY";
|
|
136
|
+
throw err;
|
|
137
|
+
}
|
|
138
|
+
throw error;
|
|
139
|
+
}
|
|
140
|
+
const key = uri.password;
|
|
141
|
+
if (!key) {
|
|
142
|
+
const err = /* @__PURE__ */ new Error("INVALID_DOTENV_KEY: Missing key part");
|
|
143
|
+
err.code = "INVALID_DOTENV_KEY";
|
|
144
|
+
throw err;
|
|
145
|
+
}
|
|
146
|
+
const environment = uri.searchParams.get("environment");
|
|
147
|
+
if (!environment) {
|
|
148
|
+
const err = /* @__PURE__ */ new Error("INVALID_DOTENV_KEY: Missing environment part");
|
|
149
|
+
err.code = "INVALID_DOTENV_KEY";
|
|
150
|
+
throw err;
|
|
151
|
+
}
|
|
152
|
+
const environmentKey = `DOTENV_VAULT_${environment.toUpperCase()}`;
|
|
153
|
+
const ciphertext = result.parsed[environmentKey];
|
|
154
|
+
if (!ciphertext) {
|
|
155
|
+
const err = /* @__PURE__ */ new Error(`NOT_FOUND_DOTENV_ENVIRONMENT: Cannot locate environment ${environmentKey} in your .env.vault file.`);
|
|
156
|
+
err.code = "NOT_FOUND_DOTENV_ENVIRONMENT";
|
|
157
|
+
throw err;
|
|
158
|
+
}
|
|
159
|
+
return {
|
|
160
|
+
ciphertext,
|
|
161
|
+
key
|
|
162
|
+
};
|
|
163
|
+
}
|
|
164
|
+
function _vaultPath(options) {
|
|
165
|
+
let possibleVaultPath = null;
|
|
166
|
+
if (options && options.path && options.path.length > 0) if (Array.isArray(options.path)) {
|
|
167
|
+
for (const filepath of options.path) if (fs$1.existsSync(filepath)) possibleVaultPath = filepath.endsWith(".vault") ? filepath : `${filepath}.vault`;
|
|
168
|
+
} else possibleVaultPath = options.path.endsWith(".vault") ? options.path : `${options.path}.vault`;
|
|
169
|
+
else possibleVaultPath = path.resolve(process.cwd(), ".env.vault");
|
|
170
|
+
if (fs$1.existsSync(possibleVaultPath)) return possibleVaultPath;
|
|
171
|
+
return null;
|
|
172
|
+
}
|
|
173
|
+
function _resolveHome(envPath) {
|
|
174
|
+
return envPath[0] === "~" ? path.join(os.homedir(), envPath.slice(1)) : envPath;
|
|
175
|
+
}
|
|
176
|
+
function _configVault(options) {
|
|
177
|
+
if (Boolean(options && options.debug)) _debug("Loading env from encrypted .env.vault");
|
|
178
|
+
const parsed = DotenvModule._parseVault(options);
|
|
179
|
+
let processEnv = process.env;
|
|
180
|
+
if (options && options.processEnv != null) processEnv = options.processEnv;
|
|
181
|
+
DotenvModule.populate(processEnv, parsed, options);
|
|
182
|
+
return { parsed };
|
|
183
|
+
}
|
|
184
|
+
function configDotenv(options) {
|
|
185
|
+
const dotenvPath = path.resolve(process.cwd(), ".env");
|
|
186
|
+
let encoding = "utf8";
|
|
187
|
+
const debug$1 = Boolean(options && options.debug);
|
|
188
|
+
if (options && options.encoding) encoding = options.encoding;
|
|
189
|
+
else if (debug$1) _debug("No encoding is specified. UTF-8 is used by default");
|
|
190
|
+
let optionPaths = [dotenvPath];
|
|
191
|
+
if (options && options.path) if (!Array.isArray(options.path)) optionPaths = [_resolveHome(options.path)];
|
|
192
|
+
else {
|
|
193
|
+
optionPaths = [];
|
|
194
|
+
for (const filepath of options.path) optionPaths.push(_resolveHome(filepath));
|
|
195
|
+
}
|
|
196
|
+
let lastError;
|
|
197
|
+
const parsedAll = {};
|
|
198
|
+
for (const path$1 of optionPaths) try {
|
|
199
|
+
const parsed = DotenvModule.parse(fs$1.readFileSync(path$1, { encoding }));
|
|
200
|
+
DotenvModule.populate(parsedAll, parsed, options);
|
|
201
|
+
} catch (e) {
|
|
202
|
+
if (debug$1) _debug(`Failed to load ${path$1} ${e.message}`);
|
|
203
|
+
lastError = e;
|
|
204
|
+
}
|
|
205
|
+
let processEnv = process.env;
|
|
206
|
+
if (options && options.processEnv != null) processEnv = options.processEnv;
|
|
207
|
+
DotenvModule.populate(processEnv, parsedAll, options);
|
|
208
|
+
if (lastError) return {
|
|
209
|
+
parsed: parsedAll,
|
|
210
|
+
error: lastError
|
|
211
|
+
};
|
|
212
|
+
else return { parsed: parsedAll };
|
|
213
|
+
}
|
|
214
|
+
function config$1(options) {
|
|
215
|
+
if (_dotenvKey(options).length === 0) return DotenvModule.configDotenv(options);
|
|
216
|
+
const vaultPath = _vaultPath(options);
|
|
217
|
+
if (!vaultPath) {
|
|
218
|
+
_warn(`You set DOTENV_KEY but you are missing a .env.vault file at ${vaultPath}. Did you forget to build it?`);
|
|
219
|
+
return DotenvModule.configDotenv(options);
|
|
220
|
+
}
|
|
221
|
+
return DotenvModule._configVault(options);
|
|
222
|
+
}
|
|
223
|
+
function decrypt(encrypted, keyStr) {
|
|
224
|
+
const key = Buffer.from(keyStr.slice(-64), "hex");
|
|
225
|
+
let ciphertext = Buffer.from(encrypted, "base64");
|
|
226
|
+
const nonce = ciphertext.subarray(0, 12);
|
|
227
|
+
const authTag = ciphertext.subarray(-16);
|
|
228
|
+
ciphertext = ciphertext.subarray(12, -16);
|
|
229
|
+
try {
|
|
230
|
+
const aesgcm = crypto.createDecipheriv("aes-256-gcm", key, nonce);
|
|
231
|
+
aesgcm.setAuthTag(authTag);
|
|
232
|
+
return `${aesgcm.update(ciphertext)}${aesgcm.final()}`;
|
|
233
|
+
} catch (error) {
|
|
234
|
+
const isRange = error instanceof RangeError;
|
|
235
|
+
const invalidKeyLength = error.message === "Invalid key length";
|
|
236
|
+
const decryptionFailed = error.message === "Unsupported state or unable to authenticate data";
|
|
237
|
+
if (isRange || invalidKeyLength) {
|
|
238
|
+
const err = /* @__PURE__ */ new Error("INVALID_DOTENV_KEY: It must be 64 characters long (or more)");
|
|
239
|
+
err.code = "INVALID_DOTENV_KEY";
|
|
240
|
+
throw err;
|
|
241
|
+
} else if (decryptionFailed) {
|
|
242
|
+
const err = /* @__PURE__ */ new Error("DECRYPTION_FAILED: Please check your DOTENV_KEY");
|
|
243
|
+
err.code = "DECRYPTION_FAILED";
|
|
244
|
+
throw err;
|
|
245
|
+
} else throw error;
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
function populate(processEnv, parsed, options = {}) {
|
|
249
|
+
const debug$1 = Boolean(options && options.debug);
|
|
250
|
+
const override = Boolean(options && options.override);
|
|
251
|
+
if (typeof parsed !== "object") {
|
|
252
|
+
const err = /* @__PURE__ */ new Error("OBJECT_REQUIRED: Please check the processEnv argument being passed to populate");
|
|
253
|
+
err.code = "OBJECT_REQUIRED";
|
|
254
|
+
throw err;
|
|
255
|
+
}
|
|
256
|
+
for (const key of Object.keys(parsed)) if (Object.prototype.hasOwnProperty.call(processEnv, key)) {
|
|
257
|
+
if (override === true) processEnv[key] = parsed[key];
|
|
258
|
+
if (debug$1) if (override === true) _debug(`"${key}" is already defined and WAS overwritten`);
|
|
259
|
+
else _debug(`"${key}" is already defined and was NOT overwritten`);
|
|
260
|
+
} else processEnv[key] = parsed[key];
|
|
261
|
+
}
|
|
262
|
+
const DotenvModule = {
|
|
263
|
+
configDotenv,
|
|
264
|
+
_configVault,
|
|
265
|
+
_parseVault,
|
|
266
|
+
config: config$1,
|
|
267
|
+
decrypt,
|
|
268
|
+
parse: parse$1,
|
|
269
|
+
populate
|
|
270
|
+
};
|
|
271
|
+
module.exports.configDotenv = DotenvModule.configDotenv;
|
|
272
|
+
module.exports._configVault = DotenvModule._configVault;
|
|
273
|
+
module.exports._parseVault = DotenvModule._parseVault;
|
|
274
|
+
module.exports.config = DotenvModule.config;
|
|
275
|
+
module.exports.decrypt = DotenvModule.decrypt;
|
|
276
|
+
module.exports.parse = DotenvModule.parse;
|
|
277
|
+
module.exports.populate = DotenvModule.populate;
|
|
278
|
+
module.exports = DotenvModule;
|
|
279
|
+
}) });
|
|
280
|
+
|
|
281
|
+
//#endregion
|
|
282
|
+
//#region ../../node_modules/.pnpm/dotenv-flow@4.1.0/node_modules/dotenv-flow/package.json
|
|
283
|
+
var require_package = /* @__PURE__ */ __commonJS({ "../../node_modules/.pnpm/dotenv-flow@4.1.0/node_modules/dotenv-flow/package.json": ((exports, module) => {
|
|
284
|
+
module.exports = {
|
|
285
|
+
"name": "dotenv-flow",
|
|
286
|
+
"version": "4.1.0",
|
|
287
|
+
"description": "Loads environment variables from `.env.[development|test|production][.local]` files",
|
|
288
|
+
"keywords": [
|
|
289
|
+
"dotenv",
|
|
290
|
+
"node_env",
|
|
291
|
+
"development",
|
|
292
|
+
"test",
|
|
293
|
+
"production",
|
|
294
|
+
"local",
|
|
295
|
+
"env",
|
|
296
|
+
"environment",
|
|
297
|
+
"variables"
|
|
298
|
+
],
|
|
299
|
+
"homepage": "https://github.com/kerimdzhanov/dotenv-flow#readme",
|
|
300
|
+
"repository": {
|
|
301
|
+
"type": "git",
|
|
302
|
+
"url": "git+https://github.com/kerimdzhanov/dotenv-flow.git"
|
|
303
|
+
},
|
|
304
|
+
"bugs": { "url": "https://github.com/kerimdzhanov/dotenv-flow/issues" },
|
|
305
|
+
"main": "lib/dotenv-flow.js",
|
|
306
|
+
"types": "lib/dotenv-flow.d.ts",
|
|
307
|
+
"exports": {
|
|
308
|
+
".": "./lib/dotenv-flow.js",
|
|
309
|
+
"./config": {
|
|
310
|
+
"require": "./config.js",
|
|
311
|
+
"node": "./config.js"
|
|
312
|
+
},
|
|
313
|
+
"./package.json": "./package.json"
|
|
314
|
+
},
|
|
315
|
+
"files": [
|
|
316
|
+
"lib/cli-options.js",
|
|
317
|
+
"lib/dotenv-flow.d.ts",
|
|
318
|
+
"lib/env-options.js",
|
|
319
|
+
"config.d.ts",
|
|
320
|
+
"config.js"
|
|
321
|
+
],
|
|
322
|
+
"dependencies": { "dotenv": "^16.0.0" },
|
|
323
|
+
"devDependencies": {
|
|
324
|
+
"@types/node": "^20.6.2",
|
|
325
|
+
"chai": "^4.3.7",
|
|
326
|
+
"conventional-changelog-cli": "^2.0.35",
|
|
327
|
+
"mocha": "^10.2.0",
|
|
328
|
+
"sinon": "^15.2.0",
|
|
329
|
+
"sinon-chai": "^3.7.0",
|
|
330
|
+
"tmp": "^0.2.1",
|
|
331
|
+
"typescript": "^5.2.2"
|
|
332
|
+
},
|
|
333
|
+
"engines": { "node": ">= 12.0.0" },
|
|
334
|
+
"scripts": {
|
|
335
|
+
"test": "yarn run test:unit && yarn run test:integration && yarn run test:types",
|
|
336
|
+
"test:unit": "mocha -r mocha.conf.js test/unit/*.spec.js",
|
|
337
|
+
"test:integration": "mocha -r mocha.conf.js test/integration/*.spec.{m,}js",
|
|
338
|
+
"test:types": "tsc",
|
|
339
|
+
"changelog": "conventional-changelog -p angular -i CHANGELOG.md -s"
|
|
340
|
+
},
|
|
341
|
+
"author": "Dan Kerimdzhanov",
|
|
342
|
+
"license": "MIT"
|
|
343
|
+
};
|
|
344
|
+
}) });
|
|
345
|
+
|
|
346
|
+
//#endregion
|
|
347
|
+
//#region ../../node_modules/.pnpm/dotenv-flow@4.1.0/node_modules/dotenv-flow/lib/dotenv-flow.js
|
|
348
|
+
var require_dotenv_flow = /* @__PURE__ */ __commonJS({ "../../node_modules/.pnpm/dotenv-flow@4.1.0/node_modules/dotenv-flow/lib/dotenv-flow.js": ((exports, module) => {
|
|
349
|
+
const fs = __require("fs");
|
|
350
|
+
const p = __require("path");
|
|
351
|
+
const dotenv$1 = require_main();
|
|
352
|
+
const { version } = require_package();
|
|
353
|
+
const DEFAULT_PATTERN = ".env[.node_env][.local]";
|
|
354
|
+
const LOCAL_PLACEHOLDER_REGEX = /\[(\W*\blocal\b\W*)]/g;
|
|
355
|
+
const NODE_ENV_PLACEHOLDER_REGEX = /\[(\W*\b)node_env(\b\W*)]/g;
|
|
356
|
+
/**
|
|
357
|
+
* Compose a filename from a given `patten`.
|
|
358
|
+
*
|
|
359
|
+
* @param {string} pattern
|
|
360
|
+
* @param {object} [options]
|
|
361
|
+
* @param {boolean} [options.local]
|
|
362
|
+
* @param {string} [options.node_env]
|
|
363
|
+
* @return {string} filename
|
|
364
|
+
*/
|
|
365
|
+
function composeFilename(pattern, options) {
|
|
366
|
+
let filename = pattern;
|
|
367
|
+
filename = filename.replace(LOCAL_PLACEHOLDER_REGEX, options && options.local ? "$1" : "");
|
|
368
|
+
filename = filename.replace(NODE_ENV_PLACEHOLDER_REGEX, options && options.node_env ? `$1${options.node_env}$2` : "");
|
|
369
|
+
return filename;
|
|
370
|
+
}
|
|
371
|
+
/**
|
|
372
|
+
* Returns a list of existing `.env*` filenames depending on the given `options`.
|
|
373
|
+
*
|
|
374
|
+
* The resulting list is ordered by the env files'
|
|
375
|
+
* variables overwriting priority from lowest to highest.
|
|
376
|
+
*
|
|
377
|
+
* This can also be referenced as "env files' environment cascade"
|
|
378
|
+
* or "order of ascending priority."
|
|
379
|
+
*
|
|
380
|
+
* ⚠️ Note that the `.env.local` file is not listed for "test" environment,
|
|
381
|
+
* since normally you expect tests to produce the same results for everyone.
|
|
382
|
+
*
|
|
383
|
+
* @param {object} [options] - `.env*` files listing options
|
|
384
|
+
* @param {string} [options.node_env] - node environment (development/test/production/etc.)
|
|
385
|
+
* @param {string} [options.path] - path to the working directory (default: `process.cwd()`)
|
|
386
|
+
* @param {string} [options.pattern] - `.env*` files' naming convention pattern
|
|
387
|
+
* (default: ".env[.node_env][.local]")
|
|
388
|
+
* @param {boolean} [options.debug] - turn on debug messages
|
|
389
|
+
* @return {string[]}
|
|
390
|
+
*/
|
|
391
|
+
function listFiles(options = {}) {
|
|
392
|
+
options.debug && debug("listing effective `.env*` files…");
|
|
393
|
+
const { node_env, path: path$1 = process.cwd(), pattern = DEFAULT_PATTERN } = options;
|
|
394
|
+
const hasLocalPlaceholder = LOCAL_PLACEHOLDER_REGEX.test(pattern);
|
|
395
|
+
const filenames = {};
|
|
396
|
+
if (pattern === DEFAULT_PATTERN) filenames[".env.defaults"] = ".env.defaults";
|
|
397
|
+
filenames[".env"] = composeFilename(pattern);
|
|
398
|
+
if (hasLocalPlaceholder) {
|
|
399
|
+
const envlocal = composeFilename(pattern, { local: true });
|
|
400
|
+
if (node_env !== "test") filenames[".env.local"] = envlocal;
|
|
401
|
+
else if (options.debug && fs.existsSync(p.resolve(path$1, envlocal))) debug("[!] note that `%s` is being skipped for \"test\" environment", envlocal);
|
|
402
|
+
}
|
|
403
|
+
if (node_env && NODE_ENV_PLACEHOLDER_REGEX.test(pattern)) {
|
|
404
|
+
filenames[".env.node_env"] = composeFilename(pattern, { node_env });
|
|
405
|
+
if (hasLocalPlaceholder) filenames[".env.node_env.local"] = composeFilename(pattern, {
|
|
406
|
+
node_env,
|
|
407
|
+
local: true
|
|
408
|
+
});
|
|
409
|
+
}
|
|
410
|
+
return [
|
|
411
|
+
".env.defaults",
|
|
412
|
+
".env",
|
|
413
|
+
".env.local",
|
|
414
|
+
".env.node_env",
|
|
415
|
+
".env.node_env.local"
|
|
416
|
+
].reduce((list, basename) => {
|
|
417
|
+
if (!filenames[basename]) return list;
|
|
418
|
+
const filename = p.resolve(path$1, filenames[basename]);
|
|
419
|
+
if (fs.existsSync(filename)) {
|
|
420
|
+
options.debug && debug(">> %s", filename);
|
|
421
|
+
list.push(filename);
|
|
422
|
+
}
|
|
423
|
+
return list;
|
|
424
|
+
}, []);
|
|
425
|
+
}
|
|
426
|
+
/**
|
|
427
|
+
* Parses a given file or a list of files.
|
|
428
|
+
*
|
|
429
|
+
* When a list of filenames is given, the files will be parsed and merged in the same order as given.
|
|
430
|
+
*
|
|
431
|
+
* @param {string|string[]} filenames - filename or a list of filenames to parse and merge
|
|
432
|
+
* @param {{ encoding?: string, debug?: boolean }} [options] - parse options
|
|
433
|
+
* @return {Object<string, string>} the resulting map of `{ env_var: value }` as an object
|
|
434
|
+
*/
|
|
435
|
+
function parse(filenames, options = {}) {
|
|
436
|
+
if (typeof filenames === "string") {
|
|
437
|
+
options.debug && debug("parsing \"%s\"…", filenames);
|
|
438
|
+
const parsed = dotenv$1.parse(fs.readFileSync(filenames, options.encoding && { encoding: options.encoding }));
|
|
439
|
+
if (options.debug) Object.keys(parsed).forEach((varname) => debug(">> %s", varname));
|
|
440
|
+
return parsed;
|
|
441
|
+
}
|
|
442
|
+
return filenames.reduce((result, filename) => {
|
|
443
|
+
const parsed = parse(filename, options);
|
|
444
|
+
if (options.debug) Object.keys(parsed).filter((varname) => result.hasOwnProperty(varname)).forEach((varname) => debug("`%s` is being overwritten by merge from \"%s\"", varname, filename));
|
|
445
|
+
return Object.assign(result, parsed);
|
|
446
|
+
}, {});
|
|
447
|
+
}
|
|
448
|
+
/**
|
|
449
|
+
* Parses variables defined in given file(s) and assigns them to `process.env`.
|
|
450
|
+
*
|
|
451
|
+
* Variables that are already defined in `process.env` will not be overwritten,
|
|
452
|
+
* thus giving a higher priority to environment variables predefined by the shell.
|
|
453
|
+
*
|
|
454
|
+
* If the loading is successful, an object with `parsed` property is returned.
|
|
455
|
+
* The `parsed` property contains parsed variables' `key => value` pairs merged in order using
|
|
456
|
+
* the "overwrite merge" strategy.
|
|
457
|
+
*
|
|
458
|
+
* If parsing fails for any of the given files, `process.env` is being left untouched,
|
|
459
|
+
* and an object with `error` property is returned.
|
|
460
|
+
* The `error` property, if present, references to the occurred error.
|
|
461
|
+
*
|
|
462
|
+
* @param {string|string[]} filenames - filename or a list of filenames to parse and merge
|
|
463
|
+
* @param {object} [options] - file loading options
|
|
464
|
+
* @param {string} [options.encoding="utf8"] - encoding of `.env*` files
|
|
465
|
+
* @param {boolean} [options.debug=false] - turn on debug messages
|
|
466
|
+
* @param {boolean} [options.silent=false] - suppress console errors and warnings
|
|
467
|
+
* @return {{ error: Error } | { parsed: Object<string, string> }}
|
|
468
|
+
*/
|
|
469
|
+
function load(filenames, options = {}) {
|
|
470
|
+
try {
|
|
471
|
+
const parsed = parse(filenames, {
|
|
472
|
+
encoding: options.encoding,
|
|
473
|
+
debug: options.debug
|
|
474
|
+
});
|
|
475
|
+
options.debug && debug("safe-merging parsed environment variables into `process.env`…");
|
|
476
|
+
for (const varname of Object.keys(parsed)) if (!process.env.hasOwnProperty(varname)) {
|
|
477
|
+
options.debug && debug(">> process.env.%s", varname);
|
|
478
|
+
process.env[varname] = parsed[varname];
|
|
479
|
+
} else if (options.debug && process.env[varname] !== parsed[varname]) debug("environment variable `%s` is predefined and not being overwritten", varname);
|
|
480
|
+
return { parsed };
|
|
481
|
+
} catch (error) {
|
|
482
|
+
return failure(error, options);
|
|
483
|
+
}
|
|
484
|
+
}
|
|
485
|
+
/**
|
|
486
|
+
* Unload variables defined in a given file(s) from `process.env`.
|
|
487
|
+
*
|
|
488
|
+
* This function can gracefully resolve the following issue:
|
|
489
|
+
*
|
|
490
|
+
* In some cases, the original "dotenv" library can be used by one of the dependent npm modules.
|
|
491
|
+
* It causes calling the original `dotenv.config()` that loads the `.env` file from your project before you can call `dotenv-flow.config()`.
|
|
492
|
+
* Such cases break `.env*` files priority because the previously loaded environment variables are treated as shell-defined thus having a higher priority.
|
|
493
|
+
*
|
|
494
|
+
* Unloading the previously loaded `.env` file can be activated when using the `dotenv-flow.config()` with the `purge_dotenv` option set to `true`.
|
|
495
|
+
*
|
|
496
|
+
* @param {string|string[]} filenames - filename or a list of filenames to unload
|
|
497
|
+
* @param {object} [options] - `fs.readFileSync` options
|
|
498
|
+
*/
|
|
499
|
+
function unload(filenames, options = {}) {
|
|
500
|
+
const parsed = parse(filenames, options);
|
|
501
|
+
Object.keys(parsed).forEach((key) => {
|
|
502
|
+
if (process.env[key] === parsed[key]) delete process.env[key];
|
|
503
|
+
});
|
|
504
|
+
}
|
|
505
|
+
/**
|
|
506
|
+
* Returns effective (computed) `node_env`.
|
|
507
|
+
*
|
|
508
|
+
* @param {object} [options]
|
|
509
|
+
* @param {string} [options.node_env]
|
|
510
|
+
* @param {string} [options.default_node_env]
|
|
511
|
+
* @param {boolean} [options.debug]
|
|
512
|
+
* @return {string|undefined} node_env
|
|
513
|
+
*/
|
|
514
|
+
function getEffectiveNodeEnv(options = {}) {
|
|
515
|
+
if (options.node_env) {
|
|
516
|
+
options.debug && debug(`operating in "${options.node_env}" environment (set by \`options.node_env\`)`);
|
|
517
|
+
return options.node_env;
|
|
518
|
+
}
|
|
519
|
+
if (process.env.NODE_ENV) {
|
|
520
|
+
options.debug && debug(`operating in "${process.env.NODE_ENV}" environment (as per \`process.env.NODE_ENV\`)`);
|
|
521
|
+
return process.env.NODE_ENV;
|
|
522
|
+
}
|
|
523
|
+
if (options.default_node_env) {
|
|
524
|
+
options.debug && debug(`operating in "${options.default_node_env}" environment (taken from \`options.default_node_env\`)`);
|
|
525
|
+
return options.default_node_env;
|
|
526
|
+
}
|
|
527
|
+
options.debug && debug("operating in \"no environment\" mode (no environment-related options are set)");
|
|
528
|
+
}
|
|
529
|
+
const CONFIG_OPTION_KEYS = [
|
|
530
|
+
"node_env",
|
|
531
|
+
"default_node_env",
|
|
532
|
+
"path",
|
|
533
|
+
"pattern",
|
|
534
|
+
"files",
|
|
535
|
+
"encoding",
|
|
536
|
+
"purge_dotenv",
|
|
537
|
+
"silent"
|
|
538
|
+
];
|
|
539
|
+
/**
|
|
540
|
+
* "dotenv-flow" initialization function (API entry point).
|
|
541
|
+
*
|
|
542
|
+
* Allows configuring dotenv-flow programmatically.
|
|
543
|
+
*
|
|
544
|
+
* @param {object} [options] - configuration options
|
|
545
|
+
* @param {string} [options.node_env=process.env.NODE_ENV] - node environment (development/test/production/etc.)
|
|
546
|
+
* @param {string} [options.default_node_env] - the default node environment
|
|
547
|
+
* @param {string} [options.path=process.cwd()] - path to `.env*` files directory
|
|
548
|
+
* @param {string} [options.pattern=".env[.node_env][.local]"] - `.env*` files' naming convention pattern
|
|
549
|
+
* @param {string[]} [options.files] - an explicit list of `.env*` files to load (note that `options.[default_]node_env` and `options.pattern` are ignored in this case)
|
|
550
|
+
* @param {string} [options.encoding="utf8"] - encoding of `.env*` files
|
|
551
|
+
* @param {boolean} [options.purge_dotenv=false] - perform the `.env` file {@link unload}
|
|
552
|
+
* @param {boolean} [options.debug=false] - turn on detailed logging to help debug why certain variables are not being set as you expect
|
|
553
|
+
* @param {boolean} [options.silent=false] - suppress all kinds of warnings including ".env*" files' loading errors
|
|
554
|
+
* @return {{ parsed?: object, error?: Error }} with a `parsed` key containing the loaded content or an `error` key with an error that is occurred
|
|
555
|
+
*/
|
|
556
|
+
function config(options = {}) {
|
|
557
|
+
if (options.debug) {
|
|
558
|
+
debug("initializing…");
|
|
559
|
+
CONFIG_OPTION_KEYS.filter((key) => key in options).forEach((key) => debug(`| options.${key} =`, options[key]));
|
|
560
|
+
}
|
|
561
|
+
const { path: path$1 = process.cwd(), pattern = DEFAULT_PATTERN } = options;
|
|
562
|
+
if (options.purge_dotenv) {
|
|
563
|
+
options.debug && debug("`options.purge_dotenv` is enabled, unloading potentially pre-loaded `.env`…");
|
|
564
|
+
const dotenvFile = p.resolve(path$1, ".env");
|
|
565
|
+
try {
|
|
566
|
+
fs.existsSync(dotenvFile) && unload(dotenvFile, { encoding: options.encoding });
|
|
567
|
+
} catch (error) {
|
|
568
|
+
!options.silent && warn("unloading failed: ", error);
|
|
569
|
+
}
|
|
570
|
+
}
|
|
571
|
+
try {
|
|
572
|
+
let filenames;
|
|
573
|
+
if (options.files) {
|
|
574
|
+
options.debug && debug("using explicit list of `.env*` files: %s…", options.files.join(", "));
|
|
575
|
+
filenames = options.files.reduce((list, basename) => {
|
|
576
|
+
const filename = p.resolve(path$1, basename);
|
|
577
|
+
if (fs.existsSync(filename)) list.push(filename);
|
|
578
|
+
else if (options.debug) debug(">> %s does not exist, skipping…", filename);
|
|
579
|
+
return list;
|
|
580
|
+
}, []);
|
|
581
|
+
} else {
|
|
582
|
+
const node_env = getEffectiveNodeEnv(options);
|
|
583
|
+
filenames = listFiles({
|
|
584
|
+
node_env,
|
|
585
|
+
path: path$1,
|
|
586
|
+
pattern,
|
|
587
|
+
debug: options.debug
|
|
588
|
+
});
|
|
589
|
+
if (filenames.length === 0) {
|
|
590
|
+
const _pattern = node_env ? pattern.replace(NODE_ENV_PLACEHOLDER_REGEX, `[$1${node_env}$2]`) : pattern;
|
|
591
|
+
return failure(/* @__PURE__ */ new Error(`no ".env*" files matching pattern "${_pattern}" in "${path$1}" dir`), options);
|
|
592
|
+
}
|
|
593
|
+
}
|
|
594
|
+
const result = load(filenames, {
|
|
595
|
+
encoding: options.encoding,
|
|
596
|
+
debug: options.debug,
|
|
597
|
+
silent: options.silent
|
|
598
|
+
});
|
|
599
|
+
options.debug && debug("initialization completed.");
|
|
600
|
+
return result;
|
|
601
|
+
} catch (error) {
|
|
602
|
+
return failure(error, options);
|
|
603
|
+
}
|
|
604
|
+
}
|
|
605
|
+
function failure(error, options) {
|
|
606
|
+
if (!options.silent) warn(`".env*" files loading failed: ${error.message || error}`);
|
|
607
|
+
return { error };
|
|
608
|
+
}
|
|
609
|
+
function warn(message, error) {
|
|
610
|
+
if (error) message += ": %s";
|
|
611
|
+
console.warn(`[dotenv-flow@${version}]: ${message}`, error);
|
|
612
|
+
}
|
|
613
|
+
function debug(message, ...values) {
|
|
614
|
+
console.debug(`[dotenv-flow@${version}]: ${message}`, ...values);
|
|
615
|
+
}
|
|
616
|
+
module.exports = {
|
|
617
|
+
DEFAULT_PATTERN,
|
|
618
|
+
listFiles,
|
|
619
|
+
parse,
|
|
620
|
+
load,
|
|
621
|
+
unload,
|
|
622
|
+
config
|
|
623
|
+
};
|
|
624
|
+
}) });
|
|
625
|
+
|
|
626
|
+
//#endregion
|
|
627
|
+
//#region src/sandbox.ts
|
|
628
|
+
var import_cjs = require_cjs();
|
|
629
|
+
var import_dotenv_flow = /* @__PURE__ */ __toESM(require_dotenv_flow());
|
|
630
|
+
import_dotenv_flow.default.config({ silent: true });
|
|
631
|
+
async function main() {
|
|
632
|
+
try {
|
|
633
|
+
await (0, import_cjs.run)(app(), process.argv.slice(2));
|
|
634
|
+
} catch (e) {
|
|
635
|
+
if (e instanceof StyledError) {
|
|
636
|
+
console.error(e.message);
|
|
637
|
+
process.exit(1);
|
|
638
|
+
}
|
|
639
|
+
console.error(e);
|
|
640
|
+
process.exit(1);
|
|
641
|
+
}
|
|
642
|
+
}
|
|
643
|
+
main();
|
|
644
|
+
|
|
645
|
+
//#endregion
|
|
646
|
+
export { };
|
|
647
|
+
//# sourceMappingURL=sandbox.mjs.map
|