@vltpkg/cli-js 1.5.0 → 1.6.0
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/{access-QPX4QXV4.js → access-AJ654YKY.js} +8 -8
- package/{bugs-TLOECXEM.js → bugs-N73DVYHD.js} +23 -19
- package/{build-IQOS3LKO.js → build-VZ3EZKMM.js} +49 -14
- package/{cache-O5IBYYSB.js → cache-VROEWG2C.js} +16 -13
- package/cache-unzip-src-unzip.js +23 -4
- package/{chunk-7UWRR6EE.js → chunk-22LZBDEC.js} +1 -1
- package/{chunk-4UH3KMTD.js → chunk-36UIE654.js} +252 -448
- package/{chunk-43EJ4Q42.js → chunk-3JIN46K5.js} +1 -1
- package/{chunk-35EG6T3J.js → chunk-44AWMA4F.js} +21 -9
- package/chunk-4E65BBTM.js +77 -0
- package/{chunk-5KW6AOTT.js → chunk-4GMNWW4C.js} +1 -1
- package/{chunk-LUVDMEW4.js → chunk-6D3QAFNZ.js} +1 -1
- package/{chunk-6W5XMVIZ.js → chunk-75HGJVNG.js} +7 -7
- package/{chunk-UZ6ICZE3.js → chunk-7M2VTFLP.js} +12 -1
- package/{chunk-XCSNI6AO.js → chunk-ANW36H4T.js} +4 -4
- package/{chunk-6LZM3I4Q.js → chunk-BF5DRGRZ.js} +25 -4
- package/chunk-BH5CVXNY.js +115 -0
- package/{chunk-F7NPYSI2.js → chunk-CAV7FKWQ.js} +2 -2
- package/{chunk-MYX4JCIJ.js → chunk-CYK6I4M6.js} +1 -1
- package/chunk-DXED4ARV.js +436 -0
- package/chunk-E74WGW5C.js +49 -0
- package/{chunk-CMLDLZZ3.js → chunk-EFHOWRKU.js} +56 -0
- package/{chunk-IFEZ6BFV.js → chunk-EMTGRCSE.js} +2 -2
- package/{chunk-4TSHLSRK.js → chunk-EYGOEAJM.js} +1 -1
- package/{chunk-2U4PVHP4.js → chunk-F5LZMLAQ.js} +123 -40
- package/{chunk-Z5D5KODU.js → chunk-FXD3IV2S.js} +4 -2
- package/chunk-GCTREKA4.js +115 -0
- package/{chunk-G3FZ2ZJK.js → chunk-GEQFMH5M.js} +1 -1
- package/{chunk-CS6AYPY5.js → chunk-GZVI75KX.js} +6 -13
- package/{chunk-CW56EJIL.js → chunk-HT6FS4VB.js} +1 -1
- package/{chunk-LH7J5BDU.js → chunk-IXAMCWIT.js} +3 -3
- package/{chunk-ARE7FKDG.js → chunk-JCNI6ZHH.js} +5 -5
- package/chunk-JV5XR5JQ.js +349 -0
- package/{chunk-IJUVVD7E.js → chunk-KD5ZK72K.js} +1 -1
- package/{chunk-WHWPAYZY.js → chunk-KVWGMSPW.js} +26 -6
- package/{chunk-VR7NRWAD.js → chunk-LCLRP64K.js} +8 -8
- package/{chunk-X6JKMIOU.js → chunk-LGQVZTYR.js} +4 -36
- package/{chunk-XCQCYB6G.js → chunk-LP3ORD3D.js} +142 -16
- package/chunk-MCDLJZXT.js +82 -0
- package/{chunk-ISAMD2FE.js → chunk-N6HV7JWC.js} +1 -1
- package/chunk-O6MQ7NN6.js +1155 -0
- package/{chunk-3S3W7QEM.js → chunk-PC2HOBAQ.js} +3 -3
- package/{chunk-GUP55DM6.js → chunk-RBQO54TG.js} +2 -2
- package/{chunk-C6ZVVEFV.js → chunk-TQQO2F56.js} +4 -3
- package/{chunk-XD5KUDXX.js → chunk-TWDSXQPN.js} +10 -8
- package/{chunk-T5EP7QEF.js → chunk-VLVMLSIF.js} +2 -2
- package/{chunk-SMXXFQPI.js → chunk-YTDABXPD.js} +3 -3
- package/{ci-ESVUMOZO.js → ci-3BVMVQIT.js} +21 -17
- package/cli-package.json +3 -1
- package/{config-ZVVLFKR7.js → config-2KQV7N5A.js} +12 -11
- package/{config-TMB2X6DW.js → config-EKHBW6I5.js} +10 -9
- package/{create-BLTNKSBQ.js → create-QVHNOIV3.js} +28 -24
- package/{deprecate-VA6PGHYL.js → deprecate-E254QBH6.js} +12 -12
- package/{dist-tag-OYJREFO2.js → dist-tag-SITRFD7O.js} +8 -8
- package/{docs-6OC3OQNM.js → docs-IDL2P7CA.js} +23 -19
- package/{exec-AZPGFVRY.js → exec-7BK2W2WL.js} +28 -24
- package/{exec-cache-D75UY2WI.js → exec-cache-VY46L7DR.js} +24 -20
- package/{exec-local-E2JKB4X4.js → exec-local-D7R5T3DF.js} +22 -18
- package/{help-UPW77X5N.js → help-RMRIEJQL.js} +5 -4
- package/{init-SNO6QL7C.js → init-BGW4HJ6V.js} +13 -12
- package/{install-TEJM2YVX.js → install-U5GATZ2N.js} +108 -52
- package/{list-NHCC2RNB.js → list-3VG4M2XL.js} +29 -22
- package/{login-XNZXCGFD.js → login-PHQWI6S6.js} +14 -13
- package/{logout-YCM7O36Q.js → logout-DJCOGRFF.js} +8 -8
- package/{outdated-4LA7N63W.js → outdated-JH3O6R3Y.js} +18 -17
- package/{pack-RC4CZSWF.js → pack-U5W5YWHK.js} +15 -14
- package/package.json +1 -1
- package/{ping-RLVAZGDL.js → ping-EKX43AOW.js} +8 -8
- package/{pkg-FED5C6TP.js → pkg-SW5GMERT.js} +15 -14
- package/{profile-DJZNLQPG.js → profile-UGDRDMQ6.js} +8 -8
- package/{publish-54AMVMTQ.js → publish-HTWKK3NN.js} +24 -20
- package/{query-ZQLMSJ7O.js → query-YE3FUVGG.js} +29 -22
- package/{registry-6HKQYSZX.js → registry-ZGGWVLBM.js} +5 -5
- package/registry-client-src-revalidate.js +41 -11
- package/{repo-ITA4BLZ4.js → repo-WDOCU6SE.js} +23 -19
- package/{reporter-UYVR2WMB.js → reporter-N5PAXB26.js} +61 -15
- package/{run-TP2HTJRN.js → run-IPARVIIQ.js} +22 -18
- package/{run-exec-UGCC53DV.js → run-exec-C4RTREEW.js} +22 -18
- package/security-archive-src-update-expired.js +24 -5
- package/{setup-XPAM5U3Z.js → setup-SYYUEHZL.js} +206 -27
- package/{skills-YD2TB2VD.js → skills-KA2VR5Q5.js} +41 -56
- package/{skills-LR6GXW3X.js → skills-UBBMSBDQ.js} +24 -21
- package/{src-34D4DOOH.js → src-FUSTSM4J.js} +25 -19
- package/{src-H6DFCAPH.js → src-QO5G2S4O.js} +6 -4
- package/{src-LHDC4NJO.js → src-W2VQULRG.js} +2 -2
- package/{token-OF63PFTQ.js → token-UQNABECH.js} +10 -9
- package/{uninstall-B54FQ5KQ.js → uninstall-FHBJ3OUV.js} +53 -17
- package/{unpublish-CSHIGMDQ.js → unpublish-APJTEUBA.js} +8 -8
- package/{update-HS4VJ5ZG.js → update-NWZTL4S7.js} +19 -17
- package/{version-L7S3DHUS.js → version-EMKKTL77.js} +14 -13
- package/{view-NWKKWFVA.js → view-BUUI33RV.js} +12 -12
- package/vlr.js +1 -1
- package/vlrx.js +1 -1
- package/vlt.js +1 -1
- package/vlx.js +1 -1
- package/vlxl.js +1 -1
- package/{whoami-65K35VGW.js → whoami-F6BSXGQ2.js} +8 -8
- package/chunk-T2VBCUF5.js +0 -77
|
@@ -11,12 +11,17 @@ import {createRequire as _vlt_createRequire} from "node:module";
|
|
|
11
11
|
var require = _vlt_createRequire(import.meta.filename);
|
|
12
12
|
import {
|
|
13
13
|
PackageInfoClient
|
|
14
|
-
} from "./chunk-
|
|
14
|
+
} from "./chunk-LCLRP64K.js";
|
|
15
15
|
import {
|
|
16
16
|
Monorepo,
|
|
17
17
|
PackageJson,
|
|
18
|
-
PathScurry
|
|
19
|
-
|
|
18
|
+
PathScurry,
|
|
19
|
+
workspaceCache
|
|
20
|
+
} from "./chunk-TQQO2F56.js";
|
|
21
|
+
import {
|
|
22
|
+
ensureGlobalProject,
|
|
23
|
+
globalCommands
|
|
24
|
+
} from "./chunk-MCDLJZXT.js";
|
|
20
25
|
import {
|
|
21
26
|
commands,
|
|
22
27
|
defaultValues,
|
|
@@ -25,19 +30,20 @@ import {
|
|
|
25
30
|
isRecordField,
|
|
26
31
|
recordFields,
|
|
27
32
|
storeLinkers
|
|
28
|
-
} from "./chunk-
|
|
33
|
+
} from "./chunk-EFHOWRKU.js";
|
|
29
34
|
import {
|
|
30
35
|
resetCaches
|
|
31
|
-
} from "./chunk-
|
|
36
|
+
} from "./chunk-CAV7FKWQ.js";
|
|
32
37
|
import {
|
|
33
38
|
find,
|
|
34
39
|
load,
|
|
35
40
|
reload,
|
|
36
|
-
save
|
|
41
|
+
save,
|
|
42
|
+
unload
|
|
37
43
|
} from "./chunk-HTOTG4TS.js";
|
|
38
44
|
import {
|
|
39
45
|
storeRoot
|
|
40
|
-
} from "./chunk-
|
|
46
|
+
} from "./chunk-4GMNWW4C.js";
|
|
41
47
|
import {
|
|
42
48
|
cloneAvailable
|
|
43
49
|
} from "./chunk-6IF3RJND.js";
|
|
@@ -51,14 +57,15 @@ import {
|
|
|
51
57
|
getOptions,
|
|
52
58
|
isObject,
|
|
53
59
|
isRecordStringString
|
|
54
|
-
} from "./chunk-
|
|
60
|
+
} from "./chunk-BF5DRGRZ.js";
|
|
55
61
|
import {
|
|
56
62
|
error
|
|
57
63
|
} from "./chunk-WZWDS3W4.js";
|
|
58
64
|
|
|
59
65
|
// ../../src/cli-sdk/src/config/index.ts
|
|
60
66
|
import { readFile, rm, writeFile } from "node:fs/promises";
|
|
61
|
-
import {
|
|
67
|
+
import { homedir } from "node:os";
|
|
68
|
+
import { dirname, isAbsolute, resolve } from "node:path";
|
|
62
69
|
|
|
63
70
|
// ../../src/cli-sdk/src/config/merge.ts
|
|
64
71
|
var merge = (base, add) => Object.fromEntries(
|
|
@@ -252,6 +259,7 @@ var recordsToPairs = (obj) => {
|
|
|
252
259
|
};
|
|
253
260
|
var kRecord = /* @__PURE__ */ Symbol("parsed key=value record");
|
|
254
261
|
var envKey = (k) => `VLT_${k.replace(/[^a-zA-Z0-9]+/g, "_").toUpperCase()}`;
|
|
262
|
+
var expandHome = (p) => p.replace(/^~(?=$|[\\/])/, homedir());
|
|
255
263
|
var kParentEnv = "__VLT_INTERNAL_EXPLICIT";
|
|
256
264
|
var parentEnv = () => {
|
|
257
265
|
try {
|
|
@@ -292,7 +300,9 @@ var Config = class _Config {
|
|
|
292
300
|
if (this.#options) return this.#options;
|
|
293
301
|
const scurry = new PathScurry(this.projectRoot);
|
|
294
302
|
const packageJson = new PackageJson();
|
|
295
|
-
const asRecords = pairsToRecords(
|
|
303
|
+
const { path: _, ...asRecords } = pairsToRecords(
|
|
304
|
+
this.parse().values
|
|
305
|
+
);
|
|
296
306
|
const extras = {
|
|
297
307
|
projectRoot: this.projectRoot,
|
|
298
308
|
signal: this.#abort.signal,
|
|
@@ -350,6 +360,7 @@ var Config = class _Config {
|
|
|
350
360
|
this.projectRoot = projectRoot;
|
|
351
361
|
this.#options = void 0;
|
|
352
362
|
resetCaches();
|
|
363
|
+
workspaceCache.clear();
|
|
353
364
|
}
|
|
354
365
|
// memoized options() getter value
|
|
355
366
|
#options;
|
|
@@ -376,6 +387,28 @@ var Config = class _Config {
|
|
|
376
387
|
* `~/projects/xyz`, then the highest dir it will check is `~/projects`
|
|
377
388
|
*/
|
|
378
389
|
projectRoot;
|
|
390
|
+
/**
|
|
391
|
+
* Global project root, set when `--global` switched to it.
|
|
392
|
+
*/
|
|
393
|
+
globalRoot;
|
|
394
|
+
/**
|
|
395
|
+
* `--global-bin-dir` from cli, env or user config, set with
|
|
396
|
+
* `globalRoot`.
|
|
397
|
+
*/
|
|
398
|
+
globalBinDir;
|
|
399
|
+
// the global project of the `setup` wizard, not switched to
|
|
400
|
+
#setupGlobal;
|
|
401
|
+
/**
|
|
402
|
+
* The global project (`--global-dir`, `--global-bin-dir`: cli > env >
|
|
403
|
+
* user config, never a project `vlt.json`): the one switched to by
|
|
404
|
+
* `--global`, or the one `vlt setup` offers PATH setup for.
|
|
405
|
+
*/
|
|
406
|
+
globalProject() {
|
|
407
|
+
if (this.globalRoot) {
|
|
408
|
+
return { root: this.globalRoot, binDir: this.globalBinDir };
|
|
409
|
+
}
|
|
410
|
+
return this.#setupGlobal;
|
|
411
|
+
}
|
|
379
412
|
/**
|
|
380
413
|
* `Record<alias, canonical name>` to dereference command aliases.
|
|
381
414
|
*/
|
|
@@ -399,6 +432,10 @@ var Config = class _Config {
|
|
|
399
432
|
const badLinker = process.env.VLT_STORE_LINKER;
|
|
400
433
|
const fixLinker = badLinker !== void 0 && !storeLinkers.includes(badLinker);
|
|
401
434
|
if (fixLinker) process.env.VLT_STORE_LINKER = "unpack";
|
|
435
|
+
const noModifyPath = process.env.VLT_NO_MODIFY_PATH;
|
|
436
|
+
if (noModifyPath !== void 0) {
|
|
437
|
+
process.env.VLT_NO_MODIFY_PATH = noModifyPath === "" || noModifyPath === "0" ? "0" : "1";
|
|
438
|
+
}
|
|
402
439
|
const envKeys = Object.keys(defaultValues).filter(
|
|
403
440
|
(k) => process.env[envKey(k)] !== void 0
|
|
404
441
|
);
|
|
@@ -447,7 +484,20 @@ var Config = class _Config {
|
|
|
447
484
|
if (cmdOrFallback !== "config") {
|
|
448
485
|
assertSpecAliases(pairsToRecords(p.values));
|
|
449
486
|
}
|
|
487
|
+
const binDirKey = envKey("global-bin-dir");
|
|
488
|
+
const keepBinDir = !this.globalRoot && !cliKeys.includes("global-bin-dir");
|
|
489
|
+
const binDirEnv = process.env[binDirKey];
|
|
450
490
|
this.jack.writeEnv(p);
|
|
491
|
+
delete process.env[envKey("global")];
|
|
492
|
+
if (this.globalRoot) {
|
|
493
|
+
process.env[envKey("global-dir")] = this.globalRoot;
|
|
494
|
+
if (this.globalBinDir)
|
|
495
|
+
process.env[binDirKey] = this.globalBinDir;
|
|
496
|
+
else delete process.env[binDirKey];
|
|
497
|
+
} else if (keepBinDir) {
|
|
498
|
+
if (binDirEnv === void 0) delete process.env[binDirKey];
|
|
499
|
+
else process.env[binDirKey] = binDirEnv;
|
|
500
|
+
}
|
|
451
501
|
process.env[kParentEnv] = JSON.stringify({
|
|
452
502
|
explicit,
|
|
453
503
|
env: Object.fromEntries(
|
|
@@ -724,13 +774,89 @@ var Config = class _Config {
|
|
|
724
774
|
/**
|
|
725
775
|
* Find the local config file and load both it and the user-level config in
|
|
726
776
|
* the XDG config home.
|
|
777
|
+
*
|
|
778
|
+
* When `args` select a `--global` command, the global project is used
|
|
779
|
+
* instead of the current one.
|
|
727
780
|
*/
|
|
728
|
-
async loadConfigFile() {
|
|
781
|
+
async loadConfigFile(args) {
|
|
729
782
|
await this.#maybeLoadConfigFile("user");
|
|
783
|
+
const g = args && this.#globalProject(args);
|
|
784
|
+
if (g?.switch) {
|
|
785
|
+
const { root } = g;
|
|
786
|
+
try {
|
|
787
|
+
ensureGlobalProject(root);
|
|
788
|
+
} catch (cause) {
|
|
789
|
+
throw error("Could not create the global project", {
|
|
790
|
+
code: "ECONFIG",
|
|
791
|
+
found: root,
|
|
792
|
+
cause
|
|
793
|
+
});
|
|
794
|
+
}
|
|
795
|
+
this.globalBinDir = g.binDir;
|
|
796
|
+
unload("project");
|
|
797
|
+
this.globalRoot = this.projectRoot = root;
|
|
798
|
+
} else if (g) {
|
|
799
|
+
this.#setupGlobal = { root: g.root, binDir: g.binDir };
|
|
800
|
+
}
|
|
730
801
|
this.projectRoot = dirname(find("project", this.projectRoot));
|
|
731
802
|
await this.#maybeLoadConfigFile("project");
|
|
732
803
|
return this;
|
|
733
804
|
}
|
|
805
|
+
// global project if `args` run a global command with --global, or
|
|
806
|
+
// `setup`. cli > env > user config, project config is not loaded yet.
|
|
807
|
+
// `switch`: use it as the project (not for the setup wizard)
|
|
808
|
+
#globalProject(args) {
|
|
809
|
+
const { values, positionals } = this.jack.parseRaw(args);
|
|
810
|
+
const cmd = getCommand(positionals[0]);
|
|
811
|
+
if (values.help || !cmd) return;
|
|
812
|
+
const setup = cmd === "setup";
|
|
813
|
+
if (!setup && !globalCommands.has(cmd)) return;
|
|
814
|
+
if (!setup) {
|
|
815
|
+
const env = process.env[envKey("global")];
|
|
816
|
+
const global = values.global ?? (env !== void 0 ? env === "1" : this.#defaults().global === true);
|
|
817
|
+
if (!global) return;
|
|
818
|
+
}
|
|
819
|
+
return {
|
|
820
|
+
root: this.#globalDir(values["global-dir"]),
|
|
821
|
+
binDir: this.#globalBinDir(args),
|
|
822
|
+
switch: !setup || values.path === true
|
|
823
|
+
};
|
|
824
|
+
}
|
|
825
|
+
#globalDir(cli) {
|
|
826
|
+
const dir = cli || process.env[envKey("global-dir")];
|
|
827
|
+
if (dir) return resolve(expandHome(dir));
|
|
828
|
+
const user = expandHome(
|
|
829
|
+
String(
|
|
830
|
+
this.#defaults()["global-dir"] || defaultValues["global-dir"]
|
|
831
|
+
)
|
|
832
|
+
);
|
|
833
|
+
if (!isAbsolute(user)) {
|
|
834
|
+
throw error("global-dir in the user config must be absolute", {
|
|
835
|
+
code: "ECONFIG",
|
|
836
|
+
found: user
|
|
837
|
+
});
|
|
838
|
+
}
|
|
839
|
+
return resolve(user);
|
|
840
|
+
}
|
|
841
|
+
// cli > env > user config, like `#globalProject`
|
|
842
|
+
#globalBinDir(args) {
|
|
843
|
+
const { values } = this.jack.parseRaw(args);
|
|
844
|
+
const dir = values["global-bin-dir"] || process.env[envKey("global-bin-dir")];
|
|
845
|
+
if (dir) return resolve(expandHome(dir));
|
|
846
|
+
const user = this.#defaults()["global-bin-dir"];
|
|
847
|
+
if (typeof user !== "string" || !user) return;
|
|
848
|
+
const p = expandHome(user);
|
|
849
|
+
if (!isAbsolute(p)) {
|
|
850
|
+
throw error(
|
|
851
|
+
"global-bin-dir in the user config must be absolute",
|
|
852
|
+
{
|
|
853
|
+
code: "ECONFIG",
|
|
854
|
+
found: p
|
|
855
|
+
}
|
|
856
|
+
);
|
|
857
|
+
}
|
|
858
|
+
return resolve(p);
|
|
859
|
+
}
|
|
734
860
|
/**
|
|
735
861
|
* Clear cached config values to force re-reading from updated files.
|
|
736
862
|
* @internal
|
|
@@ -748,9 +874,9 @@ var Config = class _Config {
|
|
|
748
874
|
this.values = void 0;
|
|
749
875
|
this.positionals = void 0;
|
|
750
876
|
this.command = void 0;
|
|
751
|
-
const { unload } = await import("./src-JC3ZUYWO.js");
|
|
752
|
-
|
|
753
|
-
|
|
877
|
+
const { unload: unload2 } = await import("./src-JC3ZUYWO.js");
|
|
878
|
+
unload2("user");
|
|
879
|
+
unload2("project");
|
|
754
880
|
await this.#maybeLoadConfigFile("user");
|
|
755
881
|
await this.#maybeLoadConfigFile("project");
|
|
756
882
|
this.parse(this.#originalArgs);
|
|
@@ -763,10 +889,10 @@ var Config = class _Config {
|
|
|
763
889
|
* Load the configuration and return a Promise to a
|
|
764
890
|
* {@link Config} object
|
|
765
891
|
*/
|
|
766
|
-
static async load(projectRoot = process.cwd(), argv = process.argv, reload2 = false) {
|
|
892
|
+
static async load(projectRoot = process.cwd(), argv = process.argv, reload2 = false, allowGlobal = true) {
|
|
767
893
|
if (this.#loaded && !reload2) return this.#loaded;
|
|
768
894
|
const a = new _Config(definition, projectRoot);
|
|
769
|
-
const b = await a.loadConfigFile();
|
|
895
|
+
const b = await a.loadConfigFile(allowGlobal ? argv : void 0);
|
|
770
896
|
this.#loaded = b.parse(argv);
|
|
771
897
|
return this.#loaded;
|
|
772
898
|
}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
var global = globalThis;
|
|
2
|
+
import {Buffer} from "node:buffer";
|
|
3
|
+
import {setTimeout as _vlt_setTimeout,clearTimeout as _vlt_clearTimeout,setImmediate as _vlt_setImmediate,clearImmediate as _vlt_clearImmediate,setInterval as _vlt_setInterval,clearInterval as _vlt_clearInterval} from "node:timers";
|
|
4
|
+
globalThis.setTimeout = _vlt_setTimeout;
|
|
5
|
+
globalThis.clearTimeout = _vlt_clearTimeout;
|
|
6
|
+
globalThis.setImmediate = _vlt_setImmediate;
|
|
7
|
+
globalThis.clearImmediate = _vlt_clearImmediate;
|
|
8
|
+
globalThis.setInterval = _vlt_setInterval;
|
|
9
|
+
globalThis.clearInterval = _vlt_clearInterval;
|
|
10
|
+
import {createRequire as _vlt_createRequire} from "node:module";
|
|
11
|
+
var require = _vlt_createRequire(import.meta.filename);
|
|
12
|
+
import {
|
|
13
|
+
error
|
|
14
|
+
} from "./chunk-WZWDS3W4.js";
|
|
15
|
+
|
|
16
|
+
// ../../src/cli-sdk/src/global-project.ts
|
|
17
|
+
import { mkdirSync, writeFileSync } from "node:fs";
|
|
18
|
+
import { isAbsolute, relative, resolve, sep } from "node:path";
|
|
19
|
+
var globalCommands = /* @__PURE__ */ new Set([
|
|
20
|
+
"install",
|
|
21
|
+
"uninstall",
|
|
22
|
+
"list",
|
|
23
|
+
"query",
|
|
24
|
+
"build"
|
|
25
|
+
]);
|
|
26
|
+
var globalWorkspacesDir = "packages";
|
|
27
|
+
var globalBinDir = (root) => resolve(root, "bin");
|
|
28
|
+
var samePath = (a, b) => {
|
|
29
|
+
const norm = (p) => {
|
|
30
|
+
const r = resolve(p);
|
|
31
|
+
return process.platform === "win32" ? r.toLowerCase() : r;
|
|
32
|
+
};
|
|
33
|
+
return norm(a) === norm(b);
|
|
34
|
+
};
|
|
35
|
+
var isInside = (dir, path) => {
|
|
36
|
+
const rel = relative(dir, path);
|
|
37
|
+
return !!rel && !isAbsolute(rel) && rel.split(sep)[0] !== "..";
|
|
38
|
+
};
|
|
39
|
+
var validName = /^(?:@[a-z0-9][\w.~-]*\/)?[a-z0-9~][\w.~-]*$/i;
|
|
40
|
+
var assertGlobalName = (name) => {
|
|
41
|
+
if (!validName.test(name)) {
|
|
42
|
+
throw error("Invalid package name", {
|
|
43
|
+
code: "EUSAGE",
|
|
44
|
+
found: name
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
var globalWorkspaceName = (name) => {
|
|
49
|
+
assertGlobalName(name);
|
|
50
|
+
return `${name}-ws`;
|
|
51
|
+
};
|
|
52
|
+
var globalWorkspacePath = (name) => `${globalWorkspacesDir}/${globalWorkspaceName(name).replace("/", "+")}`;
|
|
53
|
+
var writeIfMissing = (file, data) => {
|
|
54
|
+
try {
|
|
55
|
+
writeFileSync(file, JSON.stringify(data, null, 2) + "\n", {
|
|
56
|
+
flag: "wx"
|
|
57
|
+
});
|
|
58
|
+
} catch (er) {
|
|
59
|
+
if (er.code !== "EEXIST") throw er;
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
var ensureGlobalProject = (root) => {
|
|
63
|
+
mkdirSync(resolve(root, globalWorkspacesDir), { recursive: true });
|
|
64
|
+
writeIfMissing(resolve(root, "package.json"), {
|
|
65
|
+
name: "vlt-global",
|
|
66
|
+
private: true
|
|
67
|
+
});
|
|
68
|
+
writeIfMissing(resolve(root, "vlt.json"), {
|
|
69
|
+
workspaces: `${globalWorkspacesDir}/*`
|
|
70
|
+
});
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
export {
|
|
74
|
+
globalCommands,
|
|
75
|
+
globalWorkspacesDir,
|
|
76
|
+
globalBinDir,
|
|
77
|
+
samePath,
|
|
78
|
+
isInside,
|
|
79
|
+
globalWorkspaceName,
|
|
80
|
+
globalWorkspacePath,
|
|
81
|
+
ensureGlobalProject
|
|
82
|
+
};
|