@codeworksh/cli 0.0.1-dev.20260918042316 → 0.0.1-dev.20260922135856

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 (64) hide show
  1. package/README.md +51 -0
  2. package/add-D7X5BuCv.mjs +81 -0
  3. package/add-D7X5BuCv.mjs.map +1 -0
  4. package/{catalog-Cv1zoZ5S.mjs → catalog-DL8yWdvI.mjs} +2 -2
  5. package/{catalog-Cv1zoZ5S.mjs.map → catalog-DL8yWdvI.mjs.map} +1 -1
  6. package/check-M9CqztTk.mjs +47 -0
  7. package/check-M9CqztTk.mjs.map +1 -0
  8. package/commonjs-CiyyOsS6.mjs +160 -0
  9. package/commonjs-CiyyOsS6.mjs.map +1 -0
  10. package/definitions-ClJIBYEm.mjs +3348 -0
  11. package/definitions-ClJIBYEm.mjs.map +1 -0
  12. package/entries-DBdy6ahj.mjs +48 -0
  13. package/entries-DBdy6ahj.mjs.map +1 -0
  14. package/{error-zJGKAF4a.mjs → error-DTXBm1nO.mjs} +2348 -1841
  15. package/error-DTXBm1nO.mjs.map +1 -0
  16. package/{generate-DdscbX3w.mjs → generate-C5NElYXe.mjs} +3 -3
  17. package/{generate-DdscbX3w.mjs.map → generate-C5NElYXe.mjs.map} +1 -1
  18. package/{harness-BBTdWdhx.mjs → harness-DQxbts5f.mjs} +2 -2
  19. package/{harness-BBTdWdhx.mjs.map → harness-DQxbts5f.mjs.map} +1 -1
  20. package/index.mjs +16 -6
  21. package/index.mjs.map +1 -1
  22. package/install-CJEnZ9dx.mjs +53 -0
  23. package/install-CJEnZ9dx.mjs.map +1 -0
  24. package/lib-5d-Jmuz2.mjs +16078 -0
  25. package/lib-5d-Jmuz2.mjs.map +1 -0
  26. package/lib-CVW4jqJ3.mjs +37659 -0
  27. package/lib-CVW4jqJ3.mjs.map +1 -0
  28. package/lib-HXZBVLKt.mjs +846 -0
  29. package/lib-HXZBVLKt.mjs.map +1 -0
  30. package/lib-vrwKjvzk.mjs +10868 -0
  31. package/lib-vrwKjvzk.mjs.map +1 -0
  32. package/link-D8V3E5iZ.mjs +40 -0
  33. package/link-D8V3E5iZ.mjs.map +1 -0
  34. package/{list-C6BrwuV-.mjs → list-BMUDpLRf.mjs} +4 -4
  35. package/{list-C6BrwuV-.mjs.map → list-BMUDpLRf.mjs.map} +1 -1
  36. package/list-DS9BJ3dD.mjs +76 -0
  37. package/list-DS9BJ3dD.mjs.map +1 -0
  38. package/p-map-LZ99xLhZ.mjs +116 -0
  39. package/p-map-LZ99xLhZ.mjs.map +1 -0
  40. package/package.json +11 -8
  41. package/{providers-fO-GJuXn.mjs → providers-DT5BfXJV.mjs} +4 -4
  42. package/{providers-fO-GJuXn.mjs.map → providers-DT5BfXJV.mjs.map} +1 -1
  43. package/reload-2GZ_8UBW.mjs +26 -0
  44. package/reload-2GZ_8UBW.mjs.map +1 -0
  45. package/remove-t8FHVGC0.mjs +36 -0
  46. package/remove-t8FHVGC0.mjs.map +1 -0
  47. package/{run-CgPOJ-wJ.mjs → run-CP7aAfkf.mjs} +11 -8
  48. package/run-CP7aAfkf.mjs.map +1 -0
  49. package/{runtime-DuL-GGrx.mjs → runtime-CDSh4qOj.mjs} +108 -1
  50. package/runtime-CDSh4qOj.mjs.map +1 -0
  51. package/{serve-Du6luqoi.mjs → serve-DewC8gvV.mjs} +19 -6
  52. package/serve-DewC8gvV.mjs.map +1 -0
  53. package/settings-Bn2pmQXX.mjs +215 -0
  54. package/settings-Bn2pmQXX.mjs.map +1 -0
  55. package/type-defs-xvRvQI4T.mjs +538 -0
  56. package/type-defs-xvRvQI4T.mjs.map +1 -0
  57. package/update-CLfU-oh7.mjs +44 -0
  58. package/update-CLfU-oh7.mjs.map +1 -0
  59. package/valid-BXe5q7ao.mjs +354 -0
  60. package/valid-BXe5q7ao.mjs.map +1 -0
  61. package/error-zJGKAF4a.mjs.map +0 -1
  62. package/run-CgPOJ-wJ.mjs.map +0 -1
  63. package/runtime-DuL-GGrx.mjs.map +0 -1
  64. package/serve-Du6luqoi.mjs.map +0 -1
@@ -0,0 +1,846 @@
1
+ import { St as __require, yt as __commonJSMin } from "./error-DTXBm1nO.mjs";
2
+ import { n as require_lib$1, t as require_commonjs } from "./commonjs-CiyyOsS6.mjs";
3
+ import { p as require_lib$2, s as require_ini, t as require_lib$3 } from "./lib-vrwKjvzk.mjs";
4
+ import { n as require_umask, r as require_nopt, t as require_type_defs } from "./type-defs-xvRvQI4T.mjs";
5
+ //#region ../../node_modules/.pnpm/@npmcli+config@11.0.1/node_modules/@npmcli/config/lib/nerf-dart.js
6
+ var require_nerf_dart = /* @__PURE__ */ __commonJSMin(((exports, module) => {
7
+ const { URL } = __require("node:url");
8
+ /**
9
+ * Maps a URL to an identifier.
10
+ *
11
+ * Name courtesy schiffertronix media LLC, a New Jersey corporation
12
+ *
13
+ * @param {String} uri The URL to be nerfed.
14
+ *
15
+ * @returns {String} A nerfed URL.
16
+ */
17
+ module.exports = (url) => {
18
+ const parsed = new URL(url);
19
+ const from = `${parsed.protocol}//${parsed.host}${parsed.pathname}`;
20
+ const rel = new URL(".", from);
21
+ return `//${rel.host}${rel.pathname}`;
22
+ };
23
+ }));
24
+ //#endregion
25
+ //#region ../../node_modules/.pnpm/@npmcli+config@11.0.1/node_modules/@npmcli/config/lib/env-replace.js
26
+ var require_env_replace = /* @__PURE__ */ __commonJSMin(((exports, module) => {
27
+ const envExpr = /(?<!\\)(\\*)\$\{([^${}?]+)(\?)?\}/g;
28
+ module.exports = (f, env) => f.replace(envExpr, (orig, esc, name, modifier) => {
29
+ const fallback = modifier === "?" ? "" : `$\{${name}}`;
30
+ const val = env[name] !== void 0 ? env[name] : fallback;
31
+ if (esc.length % 2) return orig.slice((esc.length + 1) / 2);
32
+ return esc.slice(esc.length / 2) + val;
33
+ });
34
+ }));
35
+ //#endregion
36
+ //#region ../../node_modules/.pnpm/@npmcli+config@11.0.1/node_modules/@npmcli/config/lib/parse-field.js
37
+ var require_parse_field = /* @__PURE__ */ __commonJSMin(((exports, module) => {
38
+ const typeDefs = require_type_defs();
39
+ const envReplace = require_env_replace();
40
+ const { resolve: resolve$1 } = __require("node:path");
41
+ const { parse: umaskParse } = require_umask();
42
+ const parseField = (f, key, opts, listElement = false) => {
43
+ if (typeof f !== "string" && !Array.isArray(f)) return f;
44
+ const { platform, types, home, env } = opts;
45
+ const typeList = new Set([].concat(types[key]));
46
+ const isPath = typeList.has(typeDefs.path.type);
47
+ const isBool = typeList.has(typeDefs.Boolean.type);
48
+ const isString = isPath || typeList.has(typeDefs.String.type);
49
+ const isUmask = typeList.has(typeDefs.Umask.type);
50
+ const isNumber = typeList.has(typeDefs.Number.type);
51
+ const isList = !listElement && typeList.has(Array);
52
+ const isDate = typeList.has(typeDefs.Date.type);
53
+ if (Array.isArray(f)) return !isList ? f : f.map((field) => parseField(field, key, opts, true));
54
+ f = f.trim();
55
+ if (isList) return parseField(f.split("\n\n"), key, opts);
56
+ if (isBool && !isString && f === "") return true;
57
+ if (!isString && !isPath && !isNumber) switch (f) {
58
+ case "true": return true;
59
+ case "false": return false;
60
+ case "null": return null;
61
+ case "undefined": return;
62
+ }
63
+ f = envReplace(f, env);
64
+ if (isDate) return new Date(f);
65
+ if (isPath) {
66
+ if ((platform === "win32" ? /^~(\/|\\)/ : /^~\//).test(f) && home) f = resolve$1(home, f.slice(2));
67
+ else f = resolve$1(f);
68
+ }
69
+ if (isUmask) try {
70
+ return umaskParse(f);
71
+ } catch (er) {
72
+ return f;
73
+ }
74
+ if (isNumber && !isNaN(f)) f = +f;
75
+ return f;
76
+ };
77
+ module.exports = parseField;
78
+ }));
79
+ //#endregion
80
+ //#region ../../node_modules/.pnpm/@npmcli+config@11.0.1/node_modules/@npmcli/config/lib/set-envs.js
81
+ var require_set_envs = /* @__PURE__ */ __commonJSMin(((exports, module) => {
82
+ const envKey = (key, val) => {
83
+ return !/^[/@_]/.test(key) && typeof envVal(val) === "string" && `npm_config_${key.replace(/-/g, "_").toLowerCase()}`;
84
+ };
85
+ const envVal = (val) => Array.isArray(val) ? val.map((v) => envVal(v)).join("\n\n") : val === null || val === void 0 || val === false ? "" : typeof val === "object" ? null : String(val);
86
+ const sameConfigValue = (def, val) => !Array.isArray(val) || !Array.isArray(def) ? def === val : sameArrayValue(def, val);
87
+ const sameArrayValue = (def, val) => {
88
+ if (def.length !== val.length) return false;
89
+ for (let i = 0; i < def.length; i++)
90
+ /* istanbul ignore next - there are no array configs where the default
91
+ * is not an empty array, so this loop is a no-op, but it's the correct
92
+ * thing to do if we ever DO add a config like that. */
93
+ if (def[i] !== val[i]) return false;
94
+ return true;
95
+ };
96
+ const setEnv = (env, rawKey, rawVal) => {
97
+ const val = envVal(rawVal);
98
+ const key = envKey(rawKey, val);
99
+ if (key && val !== null) env[key] = val;
100
+ };
101
+ const setEnvs = (config) => {
102
+ const { env, defaults, definitions, list: [cliConf, envConf] } = config;
103
+ env.INIT_CWD = process.cwd();
104
+ const cliSet = new Set(Object.keys(cliConf));
105
+ const envSet = new Set(Object.keys(envConf));
106
+ for (const key in cliConf) {
107
+ const { deprecated, envExport = true } = definitions[key] || {};
108
+ if (deprecated || envExport === false) continue;
109
+ if (sameConfigValue(defaults[key], cliConf[key])) {
110
+ if (!sameConfigValue(envConf[key], cliConf[key])) setEnv(env, key, cliConf[key]);
111
+ } else if (!(envSet.has(key) && !cliSet.has(key))) setEnv(env, key, cliConf[key]);
112
+ }
113
+ env.HOME = config.home;
114
+ env.npm_config_global_prefix = config.globalPrefix;
115
+ env.npm_config_local_prefix = config.localPrefix;
116
+ if (cliConf.editor) env.EDITOR = cliConf.editor;
117
+ if (cliConf["node-options"]) env.NODE_OPTIONS = cliConf["node-options"];
118
+ env.npm_config_node_gyp = cliConf["node-gyp"];
119
+ env.npm_config_npm_version = cliConf["npm-version"] || "unknown";
120
+ env.npm_execpath = config.npmBin;
121
+ env.NODE = env.npm_node_execpath = config.execPath;
122
+ };
123
+ module.exports = setEnvs;
124
+ }));
125
+ //#endregion
126
+ //#region ../../node_modules/.pnpm/@npmcli+config@11.0.1/node_modules/@npmcli/config/lib/errors.js
127
+ var require_errors = /* @__PURE__ */ __commonJSMin(((exports, module) => {
128
+ var ErrInvalidAuth = class extends Error {
129
+ constructor(problems) {
130
+ let message = "Invalid auth configuration found: ";
131
+ message += problems.map((problem) => {
132
+ // istanbul ignore else
133
+ if (problem.action === "delete") return `\`${problem.key}\` is not allowed in ${problem.where} config`;
134
+ else if (problem.action === "rename") return `\`${problem.from}\` must be renamed to \`${problem.to}\` in ${problem.where} config`;
135
+ }).join(", ");
136
+ message += "\nPlease run `npm config fix` to repair your configuration.`";
137
+ super(message);
138
+ this.code = "ERR_INVALID_AUTH";
139
+ this.problems = problems;
140
+ }
141
+ };
142
+ module.exports = { ErrInvalidAuth };
143
+ }));
144
+ //#endregion
145
+ //#region ../../node_modules/.pnpm/@npmcli+config@11.0.1/node_modules/@npmcli/config/lib/type-description.js
146
+ var require_type_description = /* @__PURE__ */ __commonJSMin(((exports, module) => {
147
+ const typeDefs = require_type_defs();
148
+ const typeDescription = (t) => {
149
+ if (!t || typeof t !== "function" && typeof t !== "object") return t;
150
+ if (Array.isArray(t)) return t.map((t) => typeDescription(t));
151
+ for (const { type, description } of Object.values(typeDefs)) if (type === t) return description || type;
152
+ return t;
153
+ };
154
+ module.exports = (t) => [].concat(typeDescription(t)).filter((t) => t !== void 0);
155
+ }));
156
+ //#endregion
157
+ //#region ../../node_modules/.pnpm/@npmcli+config@11.0.1/node_modules/@npmcli/config/lib/index.js
158
+ var require_lib = /* @__PURE__ */ __commonJSMin(((exports, module) => {
159
+ const { walkUp } = require_commonjs();
160
+ const ini = require_ini();
161
+ const nopt = require_nopt();
162
+ const { log, time } = require_lib$2();
163
+ const { resolve, dirname, join } = __require("node:path");
164
+ const { homedir } = __require("node:os");
165
+ const { readFile, writeFile, chmod, unlink, stat, mkdir } = __require("node:fs/promises");
166
+ const internalEnv = [
167
+ "npm-version",
168
+ "global-prefix",
169
+ "local-prefix"
170
+ ];
171
+ const fileExists = (...p) => stat(resolve(...p)).then((st) => st.isFile()).catch(() => false);
172
+ const dirExists = (...p) => stat(resolve(...p)).then((st) => st.isDirectory()).catch(() => false);
173
+ const hasOwnProperty = (obj, key) => Object.prototype.hasOwnProperty.call(obj, key);
174
+ const typeDefs = require_type_defs();
175
+ const nerfDart = require_nerf_dart();
176
+ const envReplace = require_env_replace();
177
+ const parseField = require_parse_field();
178
+ const setEnvs = require_set_envs();
179
+ const confFileTypes = /* @__PURE__ */ new Set([
180
+ "global",
181
+ "user",
182
+ "project"
183
+ ]);
184
+ const confTypes = /* @__PURE__ */ new Set([
185
+ "default",
186
+ "builtin",
187
+ ...confFileTypes,
188
+ "env",
189
+ "cli"
190
+ ]);
191
+ var Config = class {
192
+ #loaded = false;
193
+ #flatten;
194
+ #flatOptions = null;
195
+ #warnings = [];
196
+ #unknownConfigs = [];
197
+ static get typeDefs() {
198
+ return typeDefs;
199
+ }
200
+ constructor({ definitions, shorthands, flatten, nerfDarts = [], npmPath, env = process.env, argv = process.argv, platform = process.platform, execPath = process.execPath, cwd = process.cwd(), excludeNpmCwd = false, warn = true }) {
201
+ this.nerfDarts = nerfDarts;
202
+ this.definitions = definitions;
203
+ const { types, defaults, deprecated } = getTypesFromDefinitions(definitions);
204
+ this.deprecated = deprecated;
205
+ this.#flatten = flatten;
206
+ this.types = types;
207
+ this.shorthands = shorthands;
208
+ this.defaults = defaults;
209
+ this.npmPath = npmPath;
210
+ this.npmBin = join(this.npmPath, "bin/npm-cli.js");
211
+ this.argv = argv;
212
+ this.env = env;
213
+ this.execPath = execPath;
214
+ this.platform = platform;
215
+ this.cwd = cwd;
216
+ this.excludeNpmCwd = excludeNpmCwd;
217
+ this.globalPrefix = null;
218
+ this.localPrefix = null;
219
+ this.localPackage = null;
220
+ this.home = null;
221
+ const wheres = [...confTypes];
222
+ this.data = /* @__PURE__ */ new Map();
223
+ let parent = null;
224
+ for (const where of wheres) this.data.set(where, parent = new ConfigData(parent));
225
+ this.data.set = () => {
226
+ throw new Error("cannot change internal config data structure");
227
+ };
228
+ this.data.delete = () => {
229
+ throw new Error("cannot change internal config data structure");
230
+ };
231
+ this.sources = /* @__PURE__ */ new Map([]);
232
+ for (const { data } of this.data.values()) this.list.unshift(data);
233
+ this.#loaded = false;
234
+ this.warn = warn;
235
+ }
236
+ get list() {
237
+ const list = [];
238
+ for (const { data } of this.data.values()) list.unshift(data);
239
+ return list;
240
+ }
241
+ get loaded() {
242
+ return this.#loaded;
243
+ }
244
+ get prefix() {
245
+ return this.#get("global") ? this.globalPrefix : this.localPrefix;
246
+ }
247
+ find(key) {
248
+ if (!this.loaded) throw new Error("call config.load() before reading values");
249
+ const entries = [...this.data.entries()];
250
+ for (let i = entries.length - 1; i > -1; i--) {
251
+ const [where, { data }] = entries[i];
252
+ if (hasOwnProperty(data, key)) return where;
253
+ }
254
+ return null;
255
+ }
256
+ get(key, where) {
257
+ if (!this.loaded) throw new Error("call config.load() before reading values");
258
+ return this.#get(key, where);
259
+ }
260
+ #get(key, where = null) {
261
+ if (where !== null && !confTypes.has(where)) throw new Error("invalid config location param: " + where);
262
+ const { data } = this.data.get(where || "cli");
263
+ return where === null || hasOwnProperty(data, key) ? data[key] : void 0;
264
+ }
265
+ set(key, val, where = "cli") {
266
+ if (!this.loaded) throw new Error("call config.load() before setting values");
267
+ if (!confTypes.has(where)) throw new Error("invalid config location param: " + where);
268
+ this.#checkDeprecated(key);
269
+ const { data, raw } = this.data.get(where);
270
+ data[key] = val;
271
+ if ([
272
+ "global",
273
+ "user",
274
+ "project"
275
+ ].includes(where)) raw[key] = val;
276
+ this.data.get(where)[_valid] = null;
277
+ this.#flatOptions = null;
278
+ }
279
+ get flat() {
280
+ if (this.#flatOptions) return this.#flatOptions;
281
+ const timeEnd = time.start("config:load:flatten");
282
+ this.#flatOptions = {};
283
+ for (const { data } of this.data.values()) this.#flatten(data, this.#flatOptions);
284
+ this.#flatOptions.nodeBin = this.execPath;
285
+ this.#flatOptions.npmBin = this.npmBin;
286
+ timeEnd();
287
+ return this.#flatOptions;
288
+ }
289
+ delete(key, where = "cli") {
290
+ if (!this.loaded) throw new Error("call config.load() before deleting values");
291
+ if (!confTypes.has(where)) throw new Error("invalid config location param: " + where);
292
+ const { data, raw } = this.data.get(where);
293
+ delete data[key];
294
+ if ([
295
+ "global",
296
+ "user",
297
+ "project"
298
+ ].includes(where)) delete raw[key];
299
+ }
300
+ async load() {
301
+ if (this.loaded) throw new Error("attempting to load npm config multiple times");
302
+ this.loadDefaults();
303
+ await this.loadBuiltinConfig();
304
+ this.loadCLI();
305
+ this.loadEnv();
306
+ await this.loadProjectConfig();
307
+ await this.loadUserConfig();
308
+ await this.loadGlobalConfig();
309
+ this.#loaded = true;
310
+ this.globalPrefix = this.get("prefix");
311
+ this.setEnvs();
312
+ }
313
+ loadDefaults() {
314
+ this.loadGlobalPrefix();
315
+ this.loadHome();
316
+ const defaultsObject = {
317
+ ...this.defaults,
318
+ prefix: this.globalPrefix
319
+ };
320
+ try {
321
+ defaultsObject["npm-version"] = __require(join(this.npmPath, "package.json")).version;
322
+ } catch {}
323
+ this.#loadObject(defaultsObject, "default", "default values");
324
+ const { data } = this.data.get("default");
325
+ Object.defineProperty(data, "globalconfig", {
326
+ get: () => resolve(this.#get("prefix"), "etc/npmrc"),
327
+ set(value) {
328
+ Object.defineProperty(data, "globalconfig", {
329
+ value,
330
+ configurable: true,
331
+ writable: true,
332
+ enumerable: true
333
+ });
334
+ },
335
+ configurable: true,
336
+ enumerable: true
337
+ });
338
+ Object.defineProperty(data, "global-ignore-file", {
339
+ get: () => resolve(this.#get("prefix"), "etc/npmignore"),
340
+ set(value) {
341
+ Object.defineProperty(data, "global-ignore-file", {
342
+ value,
343
+ configurable: true,
344
+ writable: true,
345
+ enumerable: true
346
+ });
347
+ },
348
+ configurable: true,
349
+ enumerable: true
350
+ });
351
+ }
352
+ loadHome() {
353
+ this.home = this.env.HOME || homedir();
354
+ }
355
+ loadGlobalPrefix() {
356
+ if (this.globalPrefix) throw new Error("cannot load default global prefix more than once");
357
+ if (this.env.PREFIX) this.globalPrefix = this.env.PREFIX;
358
+ else if (this.platform === "win32") this.globalPrefix = dirname(this.execPath);
359
+ else {
360
+ this.globalPrefix = dirname(dirname(this.execPath));
361
+ if (this.env.DESTDIR) this.globalPrefix = join(this.env.DESTDIR, this.globalPrefix);
362
+ }
363
+ }
364
+ loadEnv() {
365
+ const conf = Object.create(null);
366
+ for (const [envKey, envVal] of Object.entries(this.env)) {
367
+ if (!/^npm_config_/i.test(envKey) || envVal === "") continue;
368
+ let key = envKey.slice(11);
369
+ if (!key.startsWith("//")) key = key.replace(/(?!^)_/g, "-").toLowerCase();
370
+ conf[key] = envVal;
371
+ }
372
+ this.#loadObject(conf, "env", "environment");
373
+ }
374
+ loadCLI() {
375
+ for (const s of Object.keys(this.shorthands)) if (s.length > 1 && this.argv.includes(`-${s}`)) throw Object.assign(/* @__PURE__ */ new Error(`-${s} is not a valid single-hyphen cli flag. Did you mean --${s}?`), { code: "EUNKNOWNCONFIG" });
376
+ nopt.invalidHandler = (k, val, type) => this.invalidHandler(k, val, type, "command line options", "cli");
377
+ nopt.unknownHandler = (k, next) => this.unknownHandler(k, next);
378
+ nopt.abbrevHandler = this.abbrevHandler;
379
+ const conf = nopt(this.types, this.shorthands, this.argv);
380
+ nopt.invalidHandler = null;
381
+ nopt.unknownHandler = null;
382
+ this.parsedArgv = conf.argv;
383
+ delete conf.argv;
384
+ this.#loadObject(conf, "cli", "command line options");
385
+ }
386
+ get valid() {
387
+ for (const [where, { valid }] of this.data.entries()) if (valid === false || valid === null && !this.validate(where)) return false;
388
+ return true;
389
+ }
390
+ validate(where) {
391
+ if (!where) {
392
+ let valid = true;
393
+ const authProblems = [];
394
+ for (const entryWhere of this.data.keys()) {
395
+ if (entryWhere === "default" || entryWhere === "builtin" || entryWhere === "cli") continue;
396
+ const ret = this.validate(entryWhere);
397
+ valid = valid && ret;
398
+ if ([
399
+ "global",
400
+ "user",
401
+ "project"
402
+ ].includes(entryWhere)) {
403
+ for (const key of ["_authtoken", "-authtoken"]) if (this.get(key, entryWhere)) authProblems.push({
404
+ action: "delete",
405
+ key,
406
+ where: entryWhere
407
+ });
408
+ const nerfedReg = nerfDart(this.get("registry"));
409
+ for (const key of [
410
+ "_auth",
411
+ "_authToken",
412
+ "username",
413
+ "_password"
414
+ ]) if (this.get(key, entryWhere)) {
415
+ if (key === "username" && !this.get("_password", entryWhere)) authProblems.push({
416
+ action: "delete",
417
+ key,
418
+ where: entryWhere
419
+ });
420
+ else if (key === "_password" && !this.get("username", entryWhere)) authProblems.push({
421
+ action: "delete",
422
+ key,
423
+ where: entryWhere
424
+ });
425
+ else authProblems.push({
426
+ action: "rename",
427
+ from: key,
428
+ to: `${nerfedReg}:${key}`,
429
+ where: entryWhere
430
+ });
431
+ }
432
+ if (this.get("email", entryWhere)) authProblems.push({
433
+ action: "rename",
434
+ from: "email",
435
+ to: `${nerfedReg}:email`,
436
+ where: entryWhere
437
+ });
438
+ for (const key of ["certfile", "keyfile"]) if (this.get(key, entryWhere)) {
439
+ const pair = key === "certfile" ? "keyfile" : "certfile";
440
+ if (!this.get(pair, entryWhere)) authProblems.push({
441
+ action: "delete",
442
+ key,
443
+ where: entryWhere
444
+ });
445
+ else authProblems.push({
446
+ action: "rename",
447
+ from: key,
448
+ to: `${nerfedReg}:${key}`,
449
+ where: entryWhere
450
+ });
451
+ }
452
+ }
453
+ }
454
+ if (authProblems.length) {
455
+ const { ErrInvalidAuth } = require_errors();
456
+ throw new ErrInvalidAuth(authProblems);
457
+ }
458
+ return valid;
459
+ } else {
460
+ const obj = this.data.get(where);
461
+ obj[_valid] = true;
462
+ nopt.invalidHandler = (k, val, type) => this.invalidHandler(k, val, type, obj.source, where);
463
+ nopt.clean(obj.data, this.types, typeDefs);
464
+ nopt.invalidHandler = null;
465
+ return obj[_valid];
466
+ }
467
+ }
468
+ repair(problems) {
469
+ if (!problems) try {
470
+ this.validate();
471
+ } catch (err) {
472
+ // istanbul ignore next
473
+ if (err.code !== "ERR_INVALID_AUTH") throw err;
474
+ problems = err.problems;
475
+ } finally {
476
+ if (!problems) problems = [];
477
+ }
478
+ for (const problem of problems)
479
+ // istanbul ignore else
480
+ if (problem.action === "delete") this.delete(problem.key, problem.where);
481
+ else if (problem.action === "rename") {
482
+ if (this.find(problem.to) !== null) this.delete(problem.from, problem.where);
483
+ else {
484
+ const raw = this.data.get(problem.where).raw?.[problem.from];
485
+ const calculated = this.get(problem.from, problem.where);
486
+ this.set(problem.to, raw || calculated, problem.where);
487
+ this.delete(problem.from, problem.where);
488
+ }
489
+ }
490
+ }
491
+ isDefault(key) {
492
+ const [defaultType, ...types] = [...confTypes];
493
+ const defaultData = this.data.get(defaultType).data;
494
+ return hasOwnProperty(defaultData, key) && types.every((type) => {
495
+ const typeData = this.data.get(type).data;
496
+ return !hasOwnProperty(typeData, key);
497
+ });
498
+ }
499
+ invalidHandler(k, val, type, source, where) {
500
+ const typeDescription = require_type_description();
501
+ log.warn("invalid config", k + "=" + JSON.stringify(val), `set in ${source}`);
502
+ this.data.get(where)[_valid] = false;
503
+ if (Array.isArray(type)) {
504
+ if (type.includes(typeDefs.url.type)) type = typeDefs.url.type;
505
+ else if (type.includes(typeDefs.path.type)) type = typeDefs.path.type;
506
+ }
507
+ const typeDesc = typeDescription(type);
508
+ const mustBe = typeDesc.filter((m) => m !== void 0 && m !== Array);
509
+ const msg = "Must be" + this.#getOneOfKeywords(mustBe, typeDesc);
510
+ const desc = mustBe.length === 1 ? mustBe[0] : [...new Set(mustBe.map((n) => typeof n === "string" ? n : JSON.stringify(n)))].join(", ");
511
+ log.warn("invalid config", msg, desc);
512
+ }
513
+ abbrevHandler(short, long) {
514
+ throw Object.assign(/* @__PURE__ */ new Error(`Invalid abbreviated flag "--${short}". Did you mean "--${long}"?`), { code: "EUNKNOWNCONFIG" });
515
+ }
516
+ unknownHandler(key, next) {
517
+ if (next) this.queueWarning(`unknown:${next}`, `"${next}" is being parsed as a normal command line argument.`);
518
+ }
519
+ #getOneOfKeywords(mustBe, typeDesc) {
520
+ let keyword;
521
+ if (mustBe.length === 1 && typeDesc.includes(Array)) keyword = " one or more";
522
+ else if (mustBe.length > 1 && typeDesc.includes(Array)) keyword = " one or more of:";
523
+ else if (mustBe.length > 1) keyword = " one of:";
524
+ else keyword = "";
525
+ return keyword;
526
+ }
527
+ #loadObject(obj, where, source, er = null) {
528
+ const conf = this.data.get(where);
529
+ if (conf.source) {
530
+ const m = `double-loading "${where}" configs from ${source}, previously loaded from ${conf.source}`;
531
+ throw new Error(m);
532
+ }
533
+ if (this.sources.has(source)) {
534
+ const m = `double-loading config "${source}" as "${where}", previously loaded as "${this.sources.get(source)}"`;
535
+ throw new Error(m);
536
+ }
537
+ conf.source = source;
538
+ this.sources.set(source, where);
539
+ if (er) {
540
+ conf.loadError = er;
541
+ if (er.code !== "ENOENT") log.verbose("config", `error loading ${where} config`, er);
542
+ } else {
543
+ conf.raw = obj;
544
+ outer: for (const [key, value] of Object.entries(obj)) {
545
+ const k = envReplace(key, this.env);
546
+ const v = this.parseField(value, k);
547
+ if (where !== "default") {
548
+ this.#checkDeprecated(k);
549
+ if (this.definitions[key]?.exclusive) {
550
+ for (const exclusive of this.definitions[key].exclusive) if (!this.isDefault(exclusive)) {
551
+ if (where === "env") {
552
+ const cliData = this.data.get("cli").data;
553
+ if (Object.hasOwn(cliData, exclusive)) continue outer;
554
+ }
555
+ throw new TypeError(`--${key} cannot be provided when using --${exclusive}`);
556
+ }
557
+ }
558
+ }
559
+ if (where !== "default" || key === "npm-version") this.checkUnknown(where, key, source);
560
+ conf.data[k] = v;
561
+ }
562
+ }
563
+ }
564
+ checkUnknown(where, key, source = null) {
565
+ if (this.definitions[key]) return;
566
+ if (internalEnv.includes(key)) return;
567
+ const scoped = key.includes(":");
568
+ let baseKey = null;
569
+ if (scoped) {
570
+ baseKey = key.split(":").pop();
571
+ if (this.definitions[baseKey] || this.nerfDarts.includes(baseKey)) return;
572
+ }
573
+ const entry = {
574
+ where,
575
+ key,
576
+ baseKey,
577
+ source: source ?? this.data.get(where)?.source ?? null
578
+ };
579
+ this.#unknownConfigs.push(entry);
580
+ if (where === "publishConfig") {
581
+ const hint = " See `npm help npmrc` for supported config options.";
582
+ const msg = scoped ? `Unknown ${where} config "${baseKey}" (${key}). This will stop working in the next major version of npm.${hint}` : `Unknown ${where} config "${key}". This will stop working in the next major version of npm.${hint}`;
583
+ this.queueWarning(scoped ? baseKey : key, msg);
584
+ return;
585
+ }
586
+ if (where === "env") {
587
+ const hint = " See `npm help npmrc` for supported config options.";
588
+ const msg = scoped ? `Unknown ${where} config "${baseKey}" (${key}). This will error in a future major version of npm.${hint}` : `Unknown ${where} config "${key}". This will error in a future major version of npm.${hint}`;
589
+ this.queueWarning(scoped ? baseKey : key, msg);
590
+ }
591
+ }
592
+ getUnknownConfigs(where) {
593
+ if (where) return this.#unknownConfigs.filter((u) => u.where === where);
594
+ return this.#unknownConfigs.filter((u) => u.where !== "env" && u.where !== "publishConfig");
595
+ }
596
+ #checkDeprecated(key) {
597
+ if (this.deprecated[key]) log.warn("config", key, this.deprecated[key]);
598
+ }
599
+ parseField(f, key, listElement = false) {
600
+ return parseField(f, key, this, listElement);
601
+ }
602
+ async #loadFile(file, type) {
603
+ log.silly("config", `load:file:${file}`);
604
+ await readFile(file, "utf8").then((data) => {
605
+ const parsedConfig = ini.parse(data);
606
+ if (type === "project" && parsedConfig.prefix) log.error("config", `prefix cannot be changed from project config: ${file}.`);
607
+ return this.#loadObject(parsedConfig, type, file);
608
+ }, (er) => this.#loadObject(null, type, file, er));
609
+ }
610
+ loadBuiltinConfig() {
611
+ return this.#loadFile(resolve(this.npmPath, "npmrc"), "builtin");
612
+ }
613
+ async loadProjectConfig() {
614
+ await this.loadLocalPrefix();
615
+ if (this.localPackage == null) this.localPackage = await fileExists(this.localPrefix, "package.json");
616
+ if (this.#get("global") === true || this.#get("location") === "global") {
617
+ this.data.get("project").source = "(global mode enabled, ignored)";
618
+ this.sources.set(this.data.get("project").source, "project");
619
+ return;
620
+ }
621
+ const projectFile = resolve(this.localPrefix, ".npmrc");
622
+ if (projectFile !== this.#get("userconfig")) return this.#loadFile(projectFile, "project");
623
+ else {
624
+ this.data.get("project").source = "(same as \"user\" config, ignored)";
625
+ this.sources.set(this.data.get("project").source, "project");
626
+ }
627
+ }
628
+ async loadLocalPrefix() {
629
+ const cliPrefix = this.#get("prefix", "cli");
630
+ if (cliPrefix) {
631
+ this.localPrefix = cliPrefix;
632
+ return;
633
+ }
634
+ const cliWorkspaces = this.#get("workspaces", "cli");
635
+ const isGlobal = this.#get("global") || this.#get("location") === "global";
636
+ for (const p of walkUp(this.cwd)) {
637
+ if (this.excludeNpmCwd && p === this.npmPath) break;
638
+ const hasPackageJson = await fileExists(p, "package.json");
639
+ if (!this.localPrefix && (hasPackageJson || await dirExists(p, "node_modules"))) {
640
+ this.localPrefix = p;
641
+ this.localPackage = hasPackageJson;
642
+ if (cliWorkspaces === false || isGlobal) return;
643
+ continue;
644
+ }
645
+ if (this.localPrefix && hasPackageJson) {
646
+ const { content: pkg } = await require_lib$3().normalize(p).catch(() => ({ content: {} }));
647
+ if (!pkg?.workspaces) continue;
648
+ const workspaces = await require_lib$1()({
649
+ cwd: p,
650
+ pkg
651
+ });
652
+ for (const w of workspaces.values()) if (w === this.localPrefix) {
653
+ if (await fileExists(this.localPrefix, ".npmrc")) log.warn("config", `ignoring workspace config at ${this.localPrefix}/.npmrc`);
654
+ const { data } = this.data.get("default");
655
+ data.workspace = [this.localPrefix];
656
+ this.localPrefix = p;
657
+ this.localPackage = hasPackageJson;
658
+ log.info("config", `found workspace root at ${this.localPrefix}`);
659
+ return;
660
+ }
661
+ }
662
+ }
663
+ if (!this.localPrefix) this.localPrefix = this.cwd;
664
+ }
665
+ loadUserConfig() {
666
+ return this.#loadFile(this.#get("userconfig"), "user");
667
+ }
668
+ loadGlobalConfig() {
669
+ return this.#loadFile(this.#get("globalconfig"), "global");
670
+ }
671
+ async save(where) {
672
+ if (!this.loaded) throw new Error("call config.load() before saving");
673
+ if (!confFileTypes.has(where)) throw new Error("invalid config location param: " + where);
674
+ const conf = this.data.get(where);
675
+ conf[_loadError] = null;
676
+ if (where === "user") {}
677
+ const iniData = ini.stringify(conf.raw).trim() + "\n";
678
+ if (!iniData.trim()) {
679
+ await unlink(conf.source).catch(() => {});
680
+ return;
681
+ }
682
+ const dir = dirname(conf.source);
683
+ await mkdir(dir, { recursive: true });
684
+ await writeFile(conf.source, iniData, "utf8");
685
+ const mode = where === "user" ? 384 : 438;
686
+ await chmod(conf.source, mode);
687
+ }
688
+ clearCredentialsByURI(uri, level = "user") {
689
+ const nerfed = nerfDart(uri);
690
+ if (nerfDart(this.get("registry")) === nerfed) {
691
+ this.delete(`-authtoken`, level);
692
+ this.delete(`_authToken`, level);
693
+ this.delete(`_authtoken`, level);
694
+ this.delete(`_auth`, level);
695
+ this.delete(`_password`, level);
696
+ this.delete(`username`, level);
697
+ }
698
+ this.delete(`${nerfed}:_authToken`, level);
699
+ this.delete(`${nerfed}:_auth`, level);
700
+ this.delete(`${nerfed}:_password`, level);
701
+ this.delete(`${nerfed}:username`, level);
702
+ this.delete(`${nerfed}:email`, level);
703
+ this.delete(`${nerfed}:certfile`, level);
704
+ this.delete(`${nerfed}:keyfile`, level);
705
+ }
706
+ setCredentialsByURI(uri, { token, username, password, certfile, keyfile }) {
707
+ const nerfed = nerfDart(uri);
708
+ this.delete(`${nerfed}:always-auth`, "user");
709
+ if (certfile && keyfile) {
710
+ this.set(`${nerfed}:certfile`, certfile, "user");
711
+ this.set(`${nerfed}:keyfile`, keyfile, "user");
712
+ }
713
+ if (token) {
714
+ this.set(`${nerfed}:_authToken`, token, "user");
715
+ this.delete(`${nerfed}:_password`, "user");
716
+ this.delete(`${nerfed}:username`, "user");
717
+ } else if (username || password) {
718
+ if (!username) throw new Error("must include username");
719
+ if (!password) throw new Error("must include password");
720
+ this.delete(`${nerfed}:_authToken`, "user");
721
+ this.set(`${nerfed}:username`, username, "user");
722
+ const encoded = Buffer.from(password, "utf8").toString("base64");
723
+ this.set(`${nerfed}:_password`, encoded, "user");
724
+ } else if (!certfile || !keyfile) throw new Error("No credentials to set.");
725
+ }
726
+ getCredentialsByURI(uri) {
727
+ const nerfed = nerfDart(uri);
728
+ const creds = {};
729
+ const email = this.get(`${nerfed}:email`) || this.get("email");
730
+ if (email) creds.email = email;
731
+ const certfileReg = this.get(`${nerfed}:certfile`);
732
+ const keyfileReg = this.get(`${nerfed}:keyfile`);
733
+ if (certfileReg && keyfileReg) {
734
+ creds.certfile = certfileReg;
735
+ creds.keyfile = keyfileReg;
736
+ }
737
+ const tokenReg = this.get(`${nerfed}:_authToken`);
738
+ if (tokenReg) {
739
+ creds.token = tokenReg;
740
+ return creds;
741
+ }
742
+ const userReg = this.get(`${nerfed}:username`);
743
+ const passReg = this.get(`${nerfed}:_password`);
744
+ if (userReg && passReg) {
745
+ creds.username = userReg;
746
+ creds.password = Buffer.from(passReg, "base64").toString("utf8");
747
+ const auth = `${creds.username}:${creds.password}`;
748
+ creds.auth = Buffer.from(auth, "utf8").toString("base64");
749
+ return creds;
750
+ }
751
+ const authReg = this.get(`${nerfed}:_auth`);
752
+ if (authReg) {
753
+ const authSplit = Buffer.from(authReg, "base64").toString("utf8").split(":");
754
+ creds.username = authSplit.shift();
755
+ creds.password = authSplit.join(":");
756
+ creds.auth = authReg;
757
+ return creds;
758
+ }
759
+ return creds;
760
+ }
761
+ setEnvs() {
762
+ setEnvs(this);
763
+ }
764
+ removeWarning(key) {
765
+ this.#warnings = this.#warnings.filter((w) => w.type !== key);
766
+ }
767
+ getUnknownPositionals() {
768
+ return this.#warnings.filter((w) => w.type.startsWith("unknown:")).map((w) => w.type.slice(8));
769
+ }
770
+ removeUnknownPositional(value) {
771
+ this.removeWarning(`unknown:${value}`);
772
+ }
773
+ queueWarning(type, ...args) {
774
+ if (!this.warn) this.#warnings.push({
775
+ type,
776
+ args
777
+ });
778
+ else log.warn(...args);
779
+ }
780
+ logWarnings() {
781
+ for (const warning of this.#warnings) log.warn(...warning.args);
782
+ this.#warnings = [];
783
+ }
784
+ };
785
+ const _loadError = Symbol("loadError");
786
+ const _valid = Symbol("valid");
787
+ var ConfigData = class {
788
+ #data;
789
+ #source = null;
790
+ #raw = null;
791
+ constructor(parent) {
792
+ this.#data = Object.create(parent && parent.data);
793
+ this.#raw = {};
794
+ this[_valid] = true;
795
+ }
796
+ get data() {
797
+ return this.#data;
798
+ }
799
+ get valid() {
800
+ return this[_valid];
801
+ }
802
+ set source(s) {
803
+ if (this.#source) throw new Error("cannot set ConfigData source more than once");
804
+ this.#source = s;
805
+ }
806
+ get source() {
807
+ return this.#source;
808
+ }
809
+ set loadError(e) {
810
+ if (this[_loadError] || Object.keys(this.#raw).length) throw new Error("cannot set ConfigData loadError after load");
811
+ this[_loadError] = e;
812
+ }
813
+ get loadError() {
814
+ return this[_loadError];
815
+ }
816
+ set raw(r) {
817
+ if (Object.keys(this.#raw).length || this[_loadError]) throw new Error("cannot set ConfigData raw after load");
818
+ this.#raw = r;
819
+ }
820
+ get raw() {
821
+ return this.#raw;
822
+ }
823
+ };
824
+ const getTypesFromDefinitions = (definitions) => {
825
+ const types = {};
826
+ const defaults = {};
827
+ const deprecated = {};
828
+ for (const [key, def] of Object.entries(definitions)) {
829
+ defaults[key] = def.default;
830
+ types[key] = def.type;
831
+ if (def.deprecated) deprecated[key] = def.deprecated.trim().replace(/\n +/, "\n");
832
+ }
833
+ return {
834
+ types,
835
+ defaults,
836
+ deprecated
837
+ };
838
+ };
839
+ module.exports = Config;
840
+ module.exports.getTypesFromDefinitions = getTypesFromDefinitions;
841
+ }));
842
+ //#endregion
843
+ export default require_lib();
844
+ export {};
845
+
846
+ //# sourceMappingURL=lib-HXZBVLKt.mjs.map