@vltpkg/cli-sdk 0.0.0-9 → 1.0.0-rc.10
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/dist/esm/commands/bugs.d.ts +18 -0
- package/dist/esm/commands/bugs.d.ts.map +1 -0
- package/dist/esm/commands/bugs.js +164 -0
- package/dist/esm/commands/bugs.js.map +1 -0
- package/dist/esm/commands/build.d.ts +25 -0
- package/dist/esm/commands/build.d.ts.map +1 -0
- package/dist/esm/commands/build.js +102 -0
- package/dist/esm/commands/build.js.map +1 -0
- package/dist/esm/commands/cache.d.ts +18 -0
- package/dist/esm/commands/cache.d.ts.map +1 -1
- package/dist/esm/commands/cache.js +48 -2
- package/dist/esm/commands/cache.js.map +1 -1
- package/dist/esm/commands/ci.d.ts +11 -0
- package/dist/esm/commands/ci.d.ts.map +1 -0
- package/dist/esm/commands/ci.js +32 -0
- package/dist/esm/commands/ci.js.map +1 -0
- package/dist/esm/commands/config.d.ts +3 -2
- package/dist/esm/commands/config.d.ts.map +1 -1
- package/dist/esm/commands/config.js +372 -101
- package/dist/esm/commands/config.js.map +1 -1
- package/dist/esm/commands/docs.d.ts +18 -0
- package/dist/esm/commands/docs.d.ts.map +1 -0
- package/dist/esm/commands/docs.js +154 -0
- package/dist/esm/commands/docs.js.map +1 -0
- package/dist/esm/commands/exec-cache.d.ts +49 -0
- package/dist/esm/commands/exec-cache.d.ts.map +1 -0
- package/dist/esm/commands/exec-cache.js +146 -0
- package/dist/esm/commands/exec-cache.js.map +1 -0
- package/dist/esm/commands/exec-local.d.ts +1 -0
- package/dist/esm/commands/exec-local.d.ts.map +1 -1
- package/dist/esm/commands/exec-local.js +2 -0
- package/dist/esm/commands/exec-local.js.map +1 -1
- package/dist/esm/commands/exec.d.ts +6 -1
- package/dist/esm/commands/exec.d.ts.map +1 -1
- package/dist/esm/commands/exec.js +79 -5
- package/dist/esm/commands/exec.js.map +1 -1
- package/dist/esm/commands/help.d.ts +1 -1
- package/dist/esm/commands/help.d.ts.map +1 -1
- package/dist/esm/commands/help.js +32 -3
- package/dist/esm/commands/help.js.map +1 -1
- package/dist/esm/commands/init.d.ts +3 -3
- package/dist/esm/commands/init.d.ts.map +1 -1
- package/dist/esm/commands/init.js +95 -9
- package/dist/esm/commands/init.js.map +1 -1
- package/dist/esm/commands/install/reporter.d.ts +3 -2
- package/dist/esm/commands/install/reporter.d.ts.map +1 -1
- package/dist/esm/commands/install/reporter.js +42 -15
- package/dist/esm/commands/install/reporter.js.map +1 -1
- package/dist/esm/commands/install.d.ts +21 -3
- package/dist/esm/commands/install.d.ts.map +1 -1
- package/dist/esm/commands/install.js +29 -4
- package/dist/esm/commands/install.js.map +1 -1
- package/dist/esm/commands/list.d.ts +2 -2
- package/dist/esm/commands/list.d.ts.map +1 -1
- package/dist/esm/commands/list.js +149 -49
- package/dist/esm/commands/list.js.map +1 -1
- package/dist/esm/commands/pack.d.ts +32 -0
- package/dist/esm/commands/pack.d.ts.map +1 -0
- package/dist/esm/commands/pack.js +147 -0
- package/dist/esm/commands/pack.js.map +1 -0
- package/dist/esm/commands/pkg.d.ts +1 -2
- package/dist/esm/commands/pkg.d.ts.map +1 -1
- package/dist/esm/commands/pkg.js +123 -38
- package/dist/esm/commands/pkg.js.map +1 -1
- package/dist/esm/commands/publish.d.ts +22 -0
- package/dist/esm/commands/publish.d.ts.map +1 -0
- package/dist/esm/commands/publish.js +245 -0
- package/dist/esm/commands/publish.js.map +1 -0
- package/dist/esm/commands/query.d.ts +2 -3
- package/dist/esm/commands/query.d.ts.map +1 -1
- package/dist/esm/commands/query.js +132 -38
- package/dist/esm/commands/query.js.map +1 -1
- package/dist/esm/commands/run-exec.d.ts +1 -0
- package/dist/esm/commands/run-exec.d.ts.map +1 -1
- package/dist/esm/commands/run-exec.js +1 -0
- package/dist/esm/commands/run-exec.js.map +1 -1
- package/dist/esm/commands/run.d.ts +1 -0
- package/dist/esm/commands/run.d.ts.map +1 -1
- package/dist/esm/commands/run.js +13 -16
- package/dist/esm/commands/run.js.map +1 -1
- package/dist/esm/commands/serve.d.ts +14 -0
- package/dist/esm/commands/serve.d.ts.map +1 -0
- package/dist/esm/commands/serve.js +103 -0
- package/dist/esm/commands/serve.js.map +1 -0
- package/dist/esm/commands/uninstall.d.ts +8 -2
- package/dist/esm/commands/uninstall.d.ts.map +1 -1
- package/dist/esm/commands/uninstall.js +10 -5
- package/dist/esm/commands/uninstall.js.map +1 -1
- package/dist/esm/commands/update.d.ts +14 -0
- package/dist/esm/commands/update.d.ts.map +1 -0
- package/dist/esm/commands/update.js +41 -0
- package/dist/esm/commands/update.js.map +1 -0
- package/dist/esm/commands/version.d.ts +26 -0
- package/dist/esm/commands/version.d.ts.map +1 -0
- package/dist/esm/commands/version.js +226 -0
- package/dist/esm/commands/version.js.map +1 -0
- package/dist/esm/config/definition.d.ts +119 -15
- package/dist/esm/config/definition.d.ts.map +1 -1
- package/dist/esm/config/definition.js +186 -37
- package/dist/esm/config/definition.js.map +1 -1
- package/dist/esm/config/index.d.ts +41 -37
- package/dist/esm/config/index.d.ts.map +1 -1
- package/dist/esm/config/index.js +109 -172
- package/dist/esm/config/index.js.map +1 -1
- package/dist/esm/config/merge.d.ts +3 -1
- package/dist/esm/config/merge.d.ts.map +1 -1
- package/dist/esm/config/merge.js +11 -6
- package/dist/esm/config/merge.js.map +1 -1
- package/dist/esm/custom-help.d.ts +9 -0
- package/dist/esm/custom-help.d.ts.map +1 -0
- package/dist/esm/custom-help.js +400 -0
- package/dist/esm/custom-help.js.map +1 -0
- package/dist/esm/exec-command.d.ts +33 -14
- package/dist/esm/exec-command.d.ts.map +1 -1
- package/dist/esm/exec-command.js +213 -64
- package/dist/esm/exec-command.js.map +1 -1
- package/dist/esm/index.d.ts +1 -14
- package/dist/esm/index.d.ts.map +1 -1
- package/dist/esm/index.js +45 -19
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/load-command.d.ts +16 -0
- package/dist/esm/load-command.d.ts.map +1 -0
- package/dist/esm/load-command.js +21 -0
- package/dist/esm/load-command.js.map +1 -0
- package/dist/esm/output.d.ts +6 -11
- package/dist/esm/output.d.ts.map +1 -1
- package/dist/esm/output.js +64 -27
- package/dist/esm/output.js.map +1 -1
- package/dist/esm/pack-tarball.d.ts +22 -0
- package/dist/esm/pack-tarball.d.ts.map +1 -0
- package/dist/esm/pack-tarball.js +249 -0
- package/dist/esm/pack-tarball.js.map +1 -0
- package/dist/esm/parse-add-remove-args.d.ts +9 -2
- package/dist/esm/parse-add-remove-args.d.ts.map +1 -1
- package/dist/esm/parse-add-remove-args.js +43 -10
- package/dist/esm/parse-add-remove-args.js.map +1 -1
- package/dist/esm/print-err.d.ts +9 -2
- package/dist/esm/print-err.d.ts.map +1 -1
- package/dist/esm/print-err.js +130 -46
- package/dist/esm/print-err.js.map +1 -1
- package/dist/esm/query-host-contexts.d.ts +16 -0
- package/dist/esm/query-host-contexts.d.ts.map +1 -0
- package/dist/esm/query-host-contexts.js +135 -0
- package/dist/esm/query-host-contexts.js.map +1 -0
- package/dist/esm/start-gui.d.ts +1 -0
- package/dist/esm/start-gui.d.ts.map +1 -1
- package/dist/esm/start-gui.js +28 -8
- package/dist/esm/start-gui.js.map +1 -1
- package/dist/esm/view.d.ts +2 -3
- package/dist/esm/view.d.ts.map +1 -1
- package/dist/esm/view.js +1 -1
- package/dist/esm/view.js.map +1 -1
- package/package.json +55 -41
- package/dist/esm/commands/gui.d.ts +0 -6
- package/dist/esm/commands/gui.d.ts.map +0 -1
- package/dist/esm/commands/gui.js +0 -13
- package/dist/esm/commands/gui.js.map +0 -1
|
@@ -1,12 +1,27 @@
|
|
|
1
|
-
import { joinDepIDTuple } from '@vltpkg/dep-id';
|
|
2
1
|
import { asDependency } from '@vltpkg/graph';
|
|
2
|
+
import { joinDepIDTuple } from '@vltpkg/dep-id';
|
|
3
3
|
import { Spec } from '@vltpkg/spec';
|
|
4
4
|
const rootDepID = joinDepIDTuple(['file', '.']);
|
|
5
|
+
/**
|
|
6
|
+
* Compute a DepID for the current working directory relative to the project
|
|
7
|
+
* root. Returns the root DepID if cwd is the project root, otherwise returns
|
|
8
|
+
* the computed DepID.
|
|
9
|
+
*/
|
|
10
|
+
const getCwdDepID = (scurry) => {
|
|
11
|
+
const cwd = process.cwd();
|
|
12
|
+
const relPath = scurry.relativePosix(cwd);
|
|
13
|
+
// If cwd is the project root or outside it, return root DepID
|
|
14
|
+
if (!relPath || relPath.startsWith('..')) {
|
|
15
|
+
return rootDepID;
|
|
16
|
+
}
|
|
17
|
+
// Return a DepID for the nested folder (posix-style path)
|
|
18
|
+
return joinDepIDTuple(['file', relPath.split('\\').join('/')]);
|
|
19
|
+
};
|
|
5
20
|
/**
|
|
6
21
|
* Get the list of importers that are currently selected
|
|
7
22
|
* in {@link WorkspaceTypes}.
|
|
8
23
|
*/
|
|
9
|
-
const
|
|
24
|
+
const getWorkspaceImporters = (opts, monorepo) => {
|
|
10
25
|
const res = new Set();
|
|
11
26
|
// collects DepID references to any selected workspace
|
|
12
27
|
if (monorepo) {
|
|
@@ -14,10 +29,6 @@ const getImporters = (opts, monorepo) => {
|
|
|
14
29
|
res.add(ws.id);
|
|
15
30
|
}
|
|
16
31
|
}
|
|
17
|
-
// if no references were found, default behavior is to point to project root
|
|
18
|
-
if (!res.size) {
|
|
19
|
-
res.add(rootDepID);
|
|
20
|
-
}
|
|
21
32
|
return res;
|
|
22
33
|
};
|
|
23
34
|
const getType = (opts) => opts['save-prod'] ? 'prod'
|
|
@@ -34,36 +45,58 @@ class AddImportersDependenciesMapImpl extends Map {
|
|
|
34
45
|
class RemoveImportersDependenciesMapImpl extends Map {
|
|
35
46
|
modifiedDependencies = false;
|
|
36
47
|
}
|
|
37
|
-
|
|
48
|
+
/**
|
|
49
|
+
* Parses the positional arguments into {@link AddImportersDependenciesMap}.
|
|
50
|
+
*/
|
|
51
|
+
export const parseAddArgs = (config, scurry, monorepo) => {
|
|
38
52
|
const add = new AddImportersDependenciesMapImpl();
|
|
39
53
|
const items = config.positionals;
|
|
40
54
|
const type = getType(config.values);
|
|
41
|
-
const importers =
|
|
55
|
+
const importers = getWorkspaceImporters(config.values, monorepo);
|
|
42
56
|
const newDependencies = new Map();
|
|
43
57
|
const specOptions = config.options;
|
|
44
58
|
// nameless spec definitions will need to use their full
|
|
45
59
|
// stringified spec result instead of their name in order
|
|
46
60
|
// to have an unique key name in the resulting Map
|
|
47
61
|
const getName = (s) => s.name === '(unknown)' ? s.spec : s.name;
|
|
62
|
+
// parses each positional argument into a Spec and
|
|
63
|
+
// adds it to the new dependencies Map
|
|
48
64
|
for (const item of items) {
|
|
49
65
|
const spec = Spec.parseArgs(item, specOptions);
|
|
50
66
|
newDependencies.set(getName(spec), asDependency({ spec, type }));
|
|
51
67
|
add.modifiedDependencies = true;
|
|
52
68
|
}
|
|
69
|
+
// assigns the new dependencies to each selected workspace importer
|
|
53
70
|
for (const importer of importers) {
|
|
54
71
|
add.set(importer, newDependencies);
|
|
55
72
|
}
|
|
73
|
+
// if no workspaces were selected, default to the cwd importer which
|
|
74
|
+
// can be either the root or a nested folder in case the user is installing
|
|
75
|
+
// from a subfolder that is also a file: type dependency
|
|
76
|
+
if (!importers.size) {
|
|
77
|
+
const cwdDepID = getCwdDepID(scurry);
|
|
78
|
+
add.set(cwdDepID, newDependencies);
|
|
79
|
+
}
|
|
56
80
|
return {
|
|
57
81
|
add,
|
|
58
82
|
};
|
|
59
83
|
};
|
|
60
|
-
|
|
84
|
+
/**
|
|
85
|
+
* Parses the positional arguments into {@link RemoveImportersDependenciesMap}.
|
|
86
|
+
*/
|
|
87
|
+
export const parseRemoveArgs = (config, scurry, monorepo) => {
|
|
61
88
|
const remove = new RemoveImportersDependenciesMapImpl();
|
|
62
|
-
const importers =
|
|
89
|
+
const importers = getWorkspaceImporters(config.values, monorepo);
|
|
63
90
|
for (const importer of importers) {
|
|
64
91
|
remove.set(importer, new Set(config.positionals));
|
|
65
92
|
remove.modifiedDependencies = true;
|
|
66
93
|
}
|
|
94
|
+
// if no workspaces were selected, default to the cwd importer
|
|
95
|
+
if (!importers.size) {
|
|
96
|
+
const cwdDepID = getCwdDepID(scurry);
|
|
97
|
+
remove.set(cwdDepID, new Set(config.positionals));
|
|
98
|
+
remove.modifiedDependencies = true;
|
|
99
|
+
}
|
|
67
100
|
return {
|
|
68
101
|
remove,
|
|
69
102
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parse-add-remove-args.js","sourceRoot":"","sources":["../../src/parse-add-remove-args.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"parse-add-remove-args.js","sourceRoot":"","sources":["../../src/parse-add-remove-args.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAA;AAC5C,OAAO,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAA;AAC/C,OAAO,EAAE,IAAI,EAAE,MAAM,cAAc,CAAA;AAiCnC,MAAM,SAAS,GAAG,cAAc,CAAC,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC,CAAA;AAE/C;;;;GAIG;AACH,MAAM,WAAW,GAAG,CAAC,MAAkB,EAAS,EAAE;IAChD,MAAM,GAAG,GAAG,OAAO,CAAC,GAAG,EAAE,CAAA;IACzB,MAAM,OAAO,GAAG,MAAM,CAAC,aAAa,CAAC,GAAG,CAAC,CAAA;IACzC,8DAA8D;IAC9D,IAAI,CAAC,OAAO,IAAI,OAAO,CAAC,UAAU,CAAC,IAAI,CAAC,EAAE,CAAC;QACzC,OAAO,SAAS,CAAA;IAClB,CAAC;IACD,0DAA0D;IAC1D,OAAO,cAAc,CAAC,CAAC,MAAM,EAAE,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAA;AAChE,CAAC,CAAA;AAED;;;GAGG;AACH,MAAM,qBAAqB,GAAG,CAC5B,IAAoB,EACpB,QAAmB,EACP,EAAE;IACd,MAAM,GAAG,GAAG,IAAI,GAA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SAAS,EAAE,CAAC;QACjC,MAAM,CAAC,GAAG,CAAC,QAAQ,EAAE,IAAI,GAAG,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC,CAAA;QACjD,MAAM,CAAC,oBAAoB,GAAG,IAAI,CAAA;IACpC,CAAC;IAED,8DAA8D;IAC9D,IAAI,CAAC,SAAS,CAAC,IAAI,EAAE,CAAC;QACpB,MAAM,QAAQ,GAAG,WAAW,CAAC,MAAM,CAAC,CAAA;QACpC,MAAM,CAAC,GAAG,CAAC,QAAQ,EAAE,IAAI,GAAG,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC,CAAA;QACjD,MAAM,CAAC,oBAAoB,GAAG,IAAI,CAAA;IACpC,CAAC;IAED,OAAO;QACL,MAAM;KACP,CAAA;AACH,CAAC,CAAA","sourcesContent":["import { asDependency } from '@vltpkg/graph'\nimport { joinDepIDTuple } from '@vltpkg/dep-id'\nimport { Spec } from '@vltpkg/spec'\nimport type { PathScurry } from 'path-scurry'\nimport type { DepID } from '@vltpkg/dep-id'\nimport type {\n AddImportersDependenciesMap,\n Dependency,\n RemoveImportersDependenciesMap,\n} from '@vltpkg/graph'\nimport type { SpecOptions } from '@vltpkg/spec'\nimport type { DependencySaveType } from '@vltpkg/types'\nimport type { Monorepo } from '@vltpkg/workspaces'\nimport type { LoadedConfig } from './config/index.ts'\n\nexport type ParsedAddArgs = {\n add: AddImportersDependenciesMap\n}\n\nexport type ParsedRemoveArgs = {\n remove: RemoveImportersDependenciesMap\n}\n\nexport type SaveTypes = {\n 'save-dev'?: boolean\n 'save-optional'?: boolean\n 'save-peer'?: boolean\n 'save-prod'?: boolean\n}\n\nexport type WorkspaceTypes = {\n workspace?: string[]\n 'workspace-group'?: string[]\n}\n\nconst rootDepID = joinDepIDTuple(['file', '.'])\n\n/**\n * Compute a DepID for the current working directory relative to the project\n * root. Returns the root DepID if cwd is the project root, otherwise returns\n * the computed DepID.\n */\nconst getCwdDepID = (scurry: PathScurry): DepID => {\n const cwd = process.cwd()\n const relPath = scurry.relativePosix(cwd)\n // If cwd is the project root or outside it, return root DepID\n if (!relPath || relPath.startsWith('..')) {\n return rootDepID\n }\n // Return a DepID for the nested folder (posix-style path)\n return joinDepIDTuple(['file', relPath.split('\\\\').join('/')])\n}\n\n/**\n * Get the list of importers that are currently selected\n * in {@link WorkspaceTypes}.\n */\nconst getWorkspaceImporters = (\n opts: WorkspaceTypes,\n monorepo?: Monorepo,\n): Set<DepID> => {\n const res = new Set<DepID>()\n\n // collects DepID references to any selected workspace\n if (monorepo) {\n for (const ws of monorepo.filter(opts)) {\n res.add(ws.id)\n }\n }\n\n return res\n}\n\nconst getType = (opts: SaveTypes): DependencySaveType =>\n opts['save-prod'] ? 'prod'\n : opts['save-dev'] ? 'dev'\n : opts['save-peer'] ?\n opts['save-optional'] ?\n 'peerOptional'\n : 'peer'\n : opts['save-optional'] ? 'optional'\n : 'implicit'\n\nclass AddImportersDependenciesMapImpl\n extends Map\n implements AddImportersDependenciesMap\n{\n modifiedDependencies = false\n}\n\nclass RemoveImportersDependenciesMapImpl\n extends Map\n implements RemoveImportersDependenciesMap\n{\n modifiedDependencies = false\n}\n\n/**\n * Parses the positional arguments into {@link AddImportersDependenciesMap}.\n */\nexport const parseAddArgs = (\n config: LoadedConfig,\n scurry: PathScurry,\n monorepo?: Monorepo,\n): ParsedAddArgs => {\n const add: AddImportersDependenciesMap =\n new AddImportersDependenciesMapImpl()\n const items = config.positionals\n const type = getType(config.values)\n const importers = getWorkspaceImporters(config.values, monorepo)\n const newDependencies = new Map<string, Dependency>()\n const specOptions: SpecOptions = config.options\n\n // nameless spec definitions will need to use their full\n // stringified spec result instead of their name in order\n // to have an unique key name in the resulting Map\n const getName = (s: Spec): string =>\n s.name === '(unknown)' ? s.spec : s.name\n\n // parses each positional argument into a Spec and\n // adds it to the new dependencies Map\n for (const item of items) {\n const spec = Spec.parseArgs(item, specOptions)\n newDependencies.set(getName(spec), asDependency({ spec, type }))\n add.modifiedDependencies = true\n }\n\n // assigns the new dependencies to each selected workspace importer\n for (const importer of importers) {\n add.set(importer, newDependencies)\n }\n\n // if no workspaces were selected, default to the cwd importer which\n // can be either the root or a nested folder in case the user is installing\n // from a subfolder that is also a file: type dependency\n if (!importers.size) {\n const cwdDepID = getCwdDepID(scurry)\n add.set(cwdDepID, newDependencies)\n }\n\n return {\n add,\n }\n}\n\n/**\n * Parses the positional arguments into {@link RemoveImportersDependenciesMap}.\n */\nexport const parseRemoveArgs = (\n config: LoadedConfig,\n scurry: PathScurry,\n monorepo?: Monorepo,\n): ParsedRemoveArgs => {\n const remove: RemoveImportersDependenciesMap =\n new RemoveImportersDependenciesMapImpl()\n const importers = getWorkspaceImporters(config.values, monorepo)\n\n for (const importer of importers) {\n remove.set(importer, new Set(config.positionals))\n remove.modifiedDependencies = true\n }\n\n // if no workspaces were selected, default to the cwd importer\n if (!importers.size) {\n const cwdDepID = getCwdDepID(scurry)\n remove.set(cwdDepID, new Set(config.positionals))\n remove.modifiedDependencies = true\n }\n\n return {\n remove,\n }\n}\n"]}
|
package/dist/esm/print-err.d.ts
CHANGED
|
@@ -1,7 +1,14 @@
|
|
|
1
|
-
import type { CommandUsage } from './index.ts';
|
|
2
1
|
import type { InspectOptions } from 'node:util';
|
|
2
|
+
import type { CommandUsage } from './index.ts';
|
|
3
|
+
export declare const formatOptions: {
|
|
4
|
+
readonly depth: number;
|
|
5
|
+
readonly maxArrayLength: number;
|
|
6
|
+
readonly maxStringLength: number;
|
|
7
|
+
};
|
|
3
8
|
export type ErrorFormatOptions = InspectOptions & {
|
|
4
9
|
maxLines?: number;
|
|
5
10
|
};
|
|
6
|
-
export
|
|
11
|
+
export type Formatter = (arg: unknown, options?: ErrorFormatOptions) => string;
|
|
12
|
+
export declare const indent: (lines: string, num?: number) => string;
|
|
13
|
+
export declare const printErr: (e: unknown, usage: CommandUsage, stderr: (...a: string[]) => void, baseOpts?: ErrorFormatOptions) => void;
|
|
7
14
|
//# sourceMappingURL=print-err.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"print-err.d.ts","sourceRoot":"","sources":["../../src/print-err.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"print-err.d.ts","sourceRoot":"","sources":["../../src/print-err.ts"],"names":[],"mappings":"AASA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,WAAW,CAAA;AAE/C,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,YAAY,CAAA;AAE9C,eAAO,MAAM,aAAa;;;;CAIS,CAAA;AAEnC,MAAM,MAAM,kBAAkB,GAAG,cAAc,GAAG;IAChD,QAAQ,CAAC,EAAE,MAAM,CAAA;CAClB,CAAA;AAED,MAAM,MAAM,SAAS,GAAG,CACtB,GAAG,EAAE,OAAO,EACZ,OAAO,CAAC,EAAE,kBAAkB,KACzB,MAAM,CAAA;AAWX,eAAO,MAAM,MAAM,UAAW,MAAM,yBAIrB,CAAA;AAoBf,eAAO,MAAM,QAAQ,MAChB,OAAO,SACH,YAAY,UACX,CAAC,GAAG,CAAC,EAAE,MAAM,EAAE,KAAK,IAAI,aACrB,kBAAkB,SAwC9B,CAAA"}
|
package/dist/esm/print-err.js
CHANGED
|
@@ -1,21 +1,45 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { splitDepID } from '@vltpkg/dep-id';
|
|
2
|
+
import { parseError } from '@vltpkg/output/error';
|
|
3
|
+
import { isErrorWithCause, isObject } from '@vltpkg/types';
|
|
4
|
+
import { XDG } from '@vltpkg/xdg';
|
|
5
|
+
import { isGraphRunError } from 'graph-run';
|
|
6
|
+
import { mkdirSync, writeFileSync } from 'node:fs';
|
|
7
|
+
import { join } from 'node:path';
|
|
2
8
|
import { formatWithOptions } from 'node:util';
|
|
3
|
-
const
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
lines.shift();
|
|
8
|
-
}
|
|
9
|
-
return lines.map(l => l.trim()).join('\n');
|
|
10
|
-
}
|
|
9
|
+
export const formatOptions = {
|
|
10
|
+
depth: Infinity,
|
|
11
|
+
maxArrayLength: Infinity,
|
|
12
|
+
maxStringLength: Infinity,
|
|
11
13
|
};
|
|
12
|
-
const
|
|
14
|
+
const isNonEmptyString = (v) => !!v && typeof v === 'string';
|
|
15
|
+
const formatURL = (v, format) => v instanceof URL ? v.toString() : /* c8 ignore next */ format(v);
|
|
16
|
+
const formatArray = (v, format, joiner = ', ') => Array.isArray(v) ? v.join(joiner) : /* c8 ignore next */ format(v);
|
|
17
|
+
export const indent = (lines, num = 2) => lines
|
|
13
18
|
.split('\n')
|
|
14
19
|
.map(l => ' '.repeat(num) + l)
|
|
15
20
|
.join('\n');
|
|
16
|
-
|
|
21
|
+
const writeErrorLog = (e, format) => {
|
|
22
|
+
try {
|
|
23
|
+
const dir = new XDG('vlt/error-logs').data();
|
|
24
|
+
const file = join(dir, `error-${process.pid}.log`);
|
|
25
|
+
mkdirSync(dir, { recursive: true });
|
|
26
|
+
writeFileSync(file, format(e, {
|
|
27
|
+
colors: false,
|
|
28
|
+
maxLines: Infinity,
|
|
29
|
+
}));
|
|
30
|
+
return file;
|
|
31
|
+
}
|
|
32
|
+
catch {
|
|
33
|
+
return null;
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
export const printErr = (e, usage, stderr, baseOpts) => {
|
|
17
37
|
const format = (arg, opts) => {
|
|
18
|
-
const { maxLines = 200, ...rest } = {
|
|
38
|
+
const { maxLines = 200, ...rest } = {
|
|
39
|
+
...formatOptions,
|
|
40
|
+
...baseOpts,
|
|
41
|
+
...opts,
|
|
42
|
+
};
|
|
19
43
|
const lines = formatWithOptions(rest, arg).split('\n');
|
|
20
44
|
const totalLines = lines.length;
|
|
21
45
|
if (totalLines > maxLines) {
|
|
@@ -24,42 +48,70 @@ export const printErr = (err, usage, stderr, baseOpts) => {
|
|
|
24
48
|
}
|
|
25
49
|
return lines.join('\n');
|
|
26
50
|
};
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
51
|
+
const err = parseError(e);
|
|
52
|
+
const knownError = printCode(err, usage, stderr, format);
|
|
53
|
+
const fileWritten = !knownError || knownError.file ? writeErrorLog(e, format) : null;
|
|
54
|
+
// We could not write an error log and its not a know error,
|
|
55
|
+
// so we print the entire formatted value.
|
|
56
|
+
if (!fileWritten && !knownError) {
|
|
57
|
+
return stderr(format(e));
|
|
32
58
|
}
|
|
33
|
-
|
|
34
|
-
// properties. Just print the standard error properties as best we can.
|
|
35
|
-
if (err instanceof Error) {
|
|
59
|
+
if (err && !knownError) {
|
|
36
60
|
stderr(`${err.name}: ${err.message}`);
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
61
|
+
}
|
|
62
|
+
if (fileWritten) {
|
|
63
|
+
stderr('');
|
|
64
|
+
stderr(`Full details written to: ${fileWritten}`);
|
|
65
|
+
}
|
|
66
|
+
if (!knownError || knownError.bug) {
|
|
67
|
+
stderr('');
|
|
68
|
+
stderr('Open an issue with the full error details at:');
|
|
69
|
+
stderr(indent('https://github.com/vltpkg/vltpkg/issues/new'));
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
const printCode = (err, usage, stderr, format) => {
|
|
73
|
+
if (!err)
|
|
74
|
+
return;
|
|
75
|
+
switch (err.cause?.code) {
|
|
76
|
+
case 'GRAPHRUN_TRAVERSAL': {
|
|
77
|
+
if (!isGraphRunError(err))
|
|
78
|
+
break;
|
|
79
|
+
const { node, path, cause } = err.cause;
|
|
80
|
+
stderr(`Graph traversal failure at: ${splitDepID(node.id).join(' ')}`);
|
|
81
|
+
if (Array.isArray(path) && path.length) {
|
|
82
|
+
stderr(indent(`Path: ${path.map(n => n.id).join(',')}`));
|
|
41
83
|
}
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
84
|
+
if (isErrorWithCause(cause) &&
|
|
85
|
+
isObject(cause.cause) &&
|
|
86
|
+
'command' in cause.cause &&
|
|
87
|
+
'stdout' in cause.cause &&
|
|
88
|
+
'stderr' in cause.cause &&
|
|
89
|
+
'status' in cause.cause &&
|
|
90
|
+
'signal' in cause.cause &&
|
|
91
|
+
'cwd' in cause.cause) {
|
|
92
|
+
const { command, args, cwd, stdout: cmdStdout, stderr: cmdStderr, status, signal, } = cause.cause;
|
|
93
|
+
stderr(`Command: ${command}`);
|
|
94
|
+
if (args && Array.isArray(args) && args.length) {
|
|
95
|
+
stderr(`Args: ${args.map(a => JSON.stringify(a)).join(', ')}`);
|
|
45
96
|
}
|
|
97
|
+
stderr(`Cwd: ${cwd}`);
|
|
98
|
+
if (cmdStderr || cmdStdout) {
|
|
99
|
+
stderr('');
|
|
100
|
+
if (isNonEmptyString(cmdStderr)) {
|
|
101
|
+
stderr(cmdStderr);
|
|
102
|
+
}
|
|
103
|
+
if (isNonEmptyString(cmdStdout)) {
|
|
104
|
+
stderr(cmdStdout);
|
|
105
|
+
}
|
|
106
|
+
stderr('');
|
|
107
|
+
}
|
|
108
|
+
if (signal !== null)
|
|
109
|
+
stderr(`Signal: ${format(signal)}`);
|
|
110
|
+
if (status !== null)
|
|
111
|
+
stderr(`Status: ${format(status)}`);
|
|
46
112
|
}
|
|
47
|
-
|
|
48
|
-
stderr(indent(format(err.cause)));
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
const stack = trimStack(err);
|
|
52
|
-
if (stack) {
|
|
53
|
-
stderr(`Stack:`);
|
|
54
|
-
stderr(indent(format(stack)));
|
|
113
|
+
return { file: true };
|
|
55
114
|
}
|
|
56
|
-
return;
|
|
57
|
-
}
|
|
58
|
-
// We don't know what this is, just print it.
|
|
59
|
-
stderr(`Unknown Error:`, format(err));
|
|
60
|
-
};
|
|
61
|
-
const print = (err, usage, stderr, format) => {
|
|
62
|
-
switch (err.cause.code) {
|
|
63
115
|
case 'EUSAGE': {
|
|
64
116
|
const { found, validOptions } = err.cause;
|
|
65
117
|
stderr(usage().usage());
|
|
@@ -68,15 +120,15 @@ const print = (err, usage, stderr, format) => {
|
|
|
68
120
|
stderr(indent(`Found: ${format(found)}`));
|
|
69
121
|
}
|
|
70
122
|
if (validOptions) {
|
|
71
|
-
stderr(indent(`Valid options: ${
|
|
123
|
+
stderr(indent(`Valid options: ${formatArray(validOptions, format)}`));
|
|
72
124
|
}
|
|
73
|
-
return
|
|
125
|
+
return {};
|
|
74
126
|
}
|
|
75
127
|
case 'ERESOLVE': {
|
|
76
128
|
const { url, from, response, spec } = err.cause;
|
|
77
129
|
stderr(`Resolve Error: ${err.message}`);
|
|
78
130
|
if (url) {
|
|
79
|
-
stderr(indent(`While fetching: ${url}`));
|
|
131
|
+
stderr(indent(`While fetching: ${formatURL(url, format)}`));
|
|
80
132
|
}
|
|
81
133
|
if (spec) {
|
|
82
134
|
stderr(indent(`To satisfy: ${format(spec)}`));
|
|
@@ -87,7 +139,39 @@ const print = (err, usage, stderr, format) => {
|
|
|
87
139
|
if (response) {
|
|
88
140
|
stderr(indent(`Response: ${format(response)}`));
|
|
89
141
|
}
|
|
90
|
-
return true;
|
|
142
|
+
return { file: true };
|
|
143
|
+
}
|
|
144
|
+
case 'EREQUEST': {
|
|
145
|
+
const { url, method } = err.cause;
|
|
146
|
+
const { code, syscall } = err.cause.cause ?? {};
|
|
147
|
+
stderr(`Request Error: ${err.message}`);
|
|
148
|
+
if (code) {
|
|
149
|
+
stderr(indent(`Code: ${format(code)}`));
|
|
150
|
+
}
|
|
151
|
+
if (syscall) {
|
|
152
|
+
stderr(indent(`Syscall: ${format(syscall)}`));
|
|
153
|
+
}
|
|
154
|
+
if (url) {
|
|
155
|
+
stderr(indent(`URL: ${formatURL(url, format)}`));
|
|
156
|
+
}
|
|
157
|
+
if (method) {
|
|
158
|
+
stderr(indent(`Method: ${format(method)}`));
|
|
159
|
+
}
|
|
160
|
+
return { file: true };
|
|
161
|
+
}
|
|
162
|
+
case 'ECONFIG': {
|
|
163
|
+
const { found, wanted, validOptions } = err.cause;
|
|
164
|
+
stderr(`Config Error: ${err.message}`);
|
|
165
|
+
if (found) {
|
|
166
|
+
stderr(indent(`Found: ${format(found)}`));
|
|
167
|
+
}
|
|
168
|
+
if (wanted) {
|
|
169
|
+
stderr(indent(`Wanted: ${format(wanted)}`));
|
|
170
|
+
}
|
|
171
|
+
if (validOptions) {
|
|
172
|
+
stderr(indent(`Valid Options: ${format(validOptions)}`));
|
|
173
|
+
}
|
|
174
|
+
return {};
|
|
91
175
|
}
|
|
92
176
|
}
|
|
93
177
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"print-err.js","sourceRoot":"","sources":["../../src/print-err.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAA;AAIrD,OAAO,EAAE,iBAAiB,EAAE,MAAM,WAAW,CAAA;AAW7C,MAAM,SAAS,GAAG,CAAC,GAAU,EAAE,EAAE;IAC/B,IAAI,GAAG,CAAC,KAAK,EAAE,CAAC;QACd,MAAM,KAAK,GAAG,GAAG,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,CAAA;QAC1C,IAAI,KAAK,CAAC,CAAC,CAAC,KAAK,GAAG,GAAG,CAAC,IAAI,KAAK,GAAG,CAAC,OAAO,EAAE,EAAE,CAAC;YAC/C,KAAK,CAAC,KAAK,EAAE,CAAA;QACf,CAAC;QACD,OAAO,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;IAC5C,CAAC;AACH,CAAC,CAAA;AAED,MAAM,MAAM,GAAG,CAAC,KAAa,EAAE,GAAG,GAAG,CAAC,EAAE,EAAE,CACxC,KAAK;KACF,KAAK,CAAC,IAAI,CAAC;KACX,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;KAC7B,IAAI,CAAC,IAAI,CAAC,CAAA;AAEf,MAAM,CAAC,MAA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3C,CAAC;YACD,IAAI,YAAY,EAAE,CAAC;gBACjB,MAAM,CACJ,MAAM,CAAC,kBAAkB,MAAM,CAAC,YAAY,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,EAAE,CAAC,CAC5D,CAAA;YACH,CAAC;YACD,OAAO,IAAI,CAAA;QACb,CAAC;QAED,KAAK,UAAU,CAAC,CAAC,CAAC;YAChB,MAAM,EAAE,GAAG,EAAE,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE,GAAG,GAAG,CAAC,KAAK,CAAA;YAC/C,MAAM,CAAC,kBAAkB,GAAG,CAAC,OAAO,EAAE,CAAC,CAAA;YACvC,IAAI,GAAG,EAAE,CAAC;gBACR,MAAM,CAAC,MAAM,CAAC,mBAAmB,GAAG,EAAE,CAAC,CAAC,CAAA;YAC1C,CAAC;YACD,IAAI,IAAI,EAAE,CAAC;gBACT,MAAM,CAAC,MAAM,CAAC,eAAe,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,CAAA;YAC/C,CAAC;YACD,IAAI,IAAI,EAAE,CAAC;gBACT,MAAM,CAAC,MAAM,CAAC,SAAS,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,CAAA;YACzC,CAAC;YACD,IAAI,QAAQ,EAAE,CAAC;gBACb,MAAM,CAAC,MAAM,CAAC,aAAa,MAAM,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,CAAA;YACjD,CAAC;YACD,OAAO,IAAI,CAAA;QACb,CAAC;IACH,CAAC;AACH,CAAC,CAAA","sourcesContent":["import { isErrorWithCode } from '@vltpkg/error-cause'\nimport type { ErrorWithCode } from '@vltpkg/error-cause'\nimport type { CommandUsage } from './index.ts'\nimport type { InspectOptions } from 'node:util'\nimport { formatWithOptions } from 'node:util'\n\nexport type ErrorFormatOptions = InspectOptions & {\n maxLines?: number\n}\n\ntype Formatter = (\n arg: unknown,\n options?: ErrorFormatOptions,\n) => string\n\nconst trimStack = (err: Error) => {\n if (err.stack) {\n const lines = err.stack.trim().split('\\n')\n if (lines[0] === `${err.name}: ${err.message}`) {\n lines.shift()\n }\n return lines.map(l => l.trim()).join('\\n')\n }\n}\n\nconst indent = (lines: string, num = 2) =>\n lines\n .split('\\n')\n .map(l => ' '.repeat(num) + l)\n .join('\\n')\n\nexport const printErr = (\n err: unknown,\n usage: CommandUsage,\n stderr: (...a: string[]) => void,\n baseOpts?: ErrorFormatOptions,\n) => {\n const format: Formatter = (arg: unknown, opts) => {\n const { maxLines = 200, ...rest } = { ...baseOpts, ...opts }\n const lines = formatWithOptions(rest, arg).split('\\n')\n const totalLines = lines.length\n if (totalLines > maxLines) {\n lines.length = maxLines\n lines.push(`... ${totalLines - maxLines} lines hidden ...`)\n }\n return lines.join('\\n')\n }\n\n // This is an error with a cause, check if it we know about its\n // code and try to print it. If it did not print then fallback\n // to the next option.\n if (isErrorWithCode(err) && print(err, usage, stderr, format)) {\n return\n }\n\n // We have a real but we dont know anything special about its\n // properties. Just print the standard error properties as best we can.\n if (err instanceof Error) {\n stderr(`${err.name}: ${err.message}`)\n if ('cause' in err) {\n stderr(`Cause:`)\n if (err.cause instanceof Error) {\n stderr(indent(format(err.cause)))\n } else if (err.cause && typeof err.cause === 'object') {\n for (const key in err.cause) {\n stderr(\n indent(\n `${key}: ${format((err.cause as Record<string, unknown>)[key])}`,\n ),\n )\n }\n } else {\n stderr(indent(format(err.cause)))\n }\n }\n const stack = trimStack(err)\n if (stack) {\n stderr(`Stack:`)\n stderr(indent(format(stack)))\n }\n return\n }\n\n // We don't know what this is, just print it.\n stderr(`Unknown Error:`, format(err))\n}\n\nconst print = (\n err: ErrorWithCode,\n usage: CommandUsage,\n stderr: (...a: string[]) => void,\n format: Formatter,\n) => {\n switch (err.cause.code) {\n case 'EUSAGE': {\n const { found, validOptions } = err.cause\n stderr(usage().usage())\n stderr(`Usage Error: ${err.message}`)\n if (found) {\n stderr(indent(`Found: ${format(found)}`))\n }\n if (validOptions) {\n stderr(\n indent(`Valid options: ${format(validOptions.join(', '))}`),\n )\n }\n return true\n }\n\n case 'ERESOLVE': {\n const { url, from, response, spec } = err.cause\n stderr(`Resolve Error: ${err.message}`)\n if (url) {\n stderr(indent(`While fetching: ${url}`))\n }\n if (spec) {\n stderr(indent(`To satisfy: ${format(spec)}`))\n }\n if (from) {\n stderr(indent(`From: ${format(from)}`))\n }\n if (response) {\n stderr(indent(`Response: ${format(response)}`))\n }\n return true\n }\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"print-err.js","sourceRoot":"","sources":["../../src/print-err.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAA;AAG3C,OAAO,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAA;AACjD,OAAO,EAAE,gBAAgB,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAA;AAC1D,OAAO,EAAE,GAAG,EAAE,MAAM,aAAa,CAAA;AACjC,OAAO,EAAE,eAAe,EAAE,MAAM,WAAW,CAAA;AAC3C,OAAO,EAAE,SAAS,EAAE,aAAa,EAAE,MAAM,SAAS,CAAA;AAClD,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;AAEhC,OAAO,EAAE,iBAAiB,EAAE,MAAM,WAAW,CAAA;AAG7C,MAAM,CAAC,MAAM,aAAa,GAAG;IAC3B,KAAK,EAAE,QAAQ;IACf,cAAc,EAAE,QAAQ;IACxB,eAAe,EAAE,QAAQ;CACQ,CAAA;AAWnC,MAAM,gBAAgB,GAAG,CAAC,CAAU,EAAe,EAAE,CACnD,CAAC,CAAC,CAAC,IAAI,OAAO,CAAC,KAAK,QAAQ,CAAA;AAE9B,MAAM,SAAS,GAAG,CAAC,CAAU,EAAE,MAAiB,EAAE,EAAE,CAClD,CAAC,YAAY,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,QAAQ,EAAE,CAAC,CAAC,CAAC,oBAAoB,CAAC,MAAM,CAAC,CAAC,CAAC,CAAA;AAElE,MAAM,WAAW,GAAG,C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,CAAA;YAC7C,CAAC;YACD,IAAI,YAAY,EAAE,CAAC;gBACjB,MAAM,CAAC,MAAM,CAAC,kBAAkB,MAAM,CAAC,YAAY,CAAC,EAAE,CAAC,CAAC,CAAA;YAC1D,CAAC;YACD,OAAO,EAAE,CAAA;QACX,CAAC;IACH,CAAC;AACH,CAAC,CAAA","sourcesContent":["import { splitDepID } from '@vltpkg/dep-id'\nimport type { Node } from '@vltpkg/graph'\nimport type { ParsedError } from '@vltpkg/output/error'\nimport { parseError } from '@vltpkg/output/error'\nimport { isErrorWithCause, isObject } from '@vltpkg/types'\nimport { XDG } from '@vltpkg/xdg'\nimport { isGraphRunError } from 'graph-run'\nimport { mkdirSync, writeFileSync } from 'node:fs'\nimport { join } from 'node:path'\nimport type { InspectOptions } from 'node:util'\nimport { formatWithOptions } from 'node:util'\nimport type { CommandUsage } from './index.ts'\n\nexport const formatOptions = {\n depth: Infinity,\n maxArrayLength: Infinity,\n maxStringLength: Infinity,\n} as const satisfies InspectOptions\n\nexport type ErrorFormatOptions = InspectOptions & {\n maxLines?: number\n}\n\nexport type Formatter = (\n arg: unknown,\n options?: ErrorFormatOptions,\n) => string\n\nconst isNonEmptyString = (v: unknown): v is string =>\n !!v && typeof v === 'string'\n\nconst formatURL = (v: unknown, format: Formatter) =>\n v instanceof URL ? v.toString() : /* c8 ignore next */ format(v)\n\nconst formatArray = (v: unknown, format: Formatter, joiner = ', ') =>\n Array.isArray(v) ? v.join(joiner) : /* c8 ignore next */ format(v)\n\nexport const indent = (lines: string, num = 2) =>\n lines\n .split('\\n')\n .map(l => ' '.repeat(num) + l)\n .join('\\n')\n\nconst writeErrorLog = (e: unknown, format: Formatter) => {\n try {\n const dir = new XDG('vlt/error-logs').data()\n const file = join(dir, `error-${process.pid}.log`)\n mkdirSync(dir, { recursive: true })\n writeFileSync(\n file,\n format(e, {\n colors: false,\n maxLines: Infinity,\n }),\n )\n return file\n } catch {\n return null\n }\n}\n\nexport const printErr = (\n e: unknown,\n usage: CommandUsage,\n stderr: (...a: string[]) => void,\n baseOpts?: ErrorFormatOptions,\n) => {\n const format: Formatter = (arg: unknown, opts) => {\n const { maxLines = 200, ...rest } = {\n ...formatOptions,\n ...baseOpts,\n ...opts,\n }\n const lines = formatWithOptions(rest, arg).split('\\n')\n const totalLines = lines.length\n if (totalLines > maxLines) {\n lines.length = maxLines\n lines.push(`... ${totalLines - maxLines} lines hidden ...`)\n }\n return lines.join('\\n')\n }\n\n const err = parseError(e)\n const knownError = printCode(err, usage, stderr, format)\n const fileWritten =\n !knownError || knownError.file ? writeErrorLog(e, format) : null\n\n // We could not write an error log and its not a know error,\n // so we print the entire formatted value.\n if (!fileWritten && !knownError) {\n return stderr(format(e))\n }\n\n if (err && !knownError) {\n stderr(`${err.name}: ${err.message}`)\n }\n if (fileWritten) {\n stderr('')\n stderr(`Full details written to: ${fileWritten}`)\n }\n if (!knownError || knownError.bug) {\n stderr('')\n stderr('Open an issue with the full error details at:')\n stderr(indent('https://github.com/vltpkg/vltpkg/issues/new'))\n }\n}\n\nconst printCode = (\n err: ParsedError | null,\n usage: CommandUsage,\n stderr: (...a: string[]) => void,\n format: Formatter,\n): void | { bug?: boolean; file?: boolean } => {\n if (!err) return\n\n switch (err.cause?.code) {\n case 'GRAPHRUN_TRAVERSAL': {\n if (!isGraphRunError<Node>(err)) break\n const { node, path, cause } = err.cause\n stderr(\n `Graph traversal failure at: ${splitDepID(node.id).join(' ')}`,\n )\n if (Array.isArray(path) && path.length) {\n stderr(indent(`Path: ${path.map(n => n.id).join(',')}`))\n }\n if (\n isErrorWithCause(cause) &&\n isObject(cause.cause) &&\n 'command' in cause.cause &&\n 'stdout' in cause.cause &&\n 'stderr' in cause.cause &&\n 'status' in cause.cause &&\n 'signal' in cause.cause &&\n 'cwd' in cause.cause\n ) {\n const {\n command,\n args,\n cwd,\n stdout: cmdStdout,\n stderr: cmdStderr,\n status,\n signal,\n } = cause.cause\n stderr(`Command: ${command}`)\n if (args && Array.isArray(args) && args.length) {\n stderr(\n `Args: ${args.map(a => JSON.stringify(a)).join(', ')}`,\n )\n }\n stderr(`Cwd: ${cwd}`)\n\n if (cmdStderr || cmdStdout) {\n stderr('')\n if (isNonEmptyString(cmdStderr)) {\n stderr(cmdStderr)\n }\n if (isNonEmptyString(cmdStdout)) {\n stderr(cmdStdout)\n }\n stderr('')\n }\n\n if (signal !== null) stderr(`Signal: ${format(signal)}`)\n if (status !== null) stderr(`Status: ${format(status)}`)\n }\n return { file: true }\n }\n\n case 'EUSAGE': {\n const { found, validOptions } = err.cause\n stderr(usage().usage())\n stderr(`Usage Error: ${err.message}`)\n if (found) {\n stderr(indent(`Found: ${format(found)}`))\n }\n if (validOptions) {\n stderr(\n indent(\n `Valid options: ${formatArray(validOptions, format)}`,\n ),\n )\n }\n return {}\n }\n\n case 'ERESOLVE': {\n const { url, from, response, spec } = err.cause\n stderr(`Resolve Error: ${err.message}`)\n if (url) {\n stderr(indent(`While fetching: ${formatURL(url, format)}`))\n }\n if (spec) {\n stderr(indent(`To satisfy: ${format(spec)}`))\n }\n if (from) {\n stderr(indent(`From: ${format(from)}`))\n }\n if (response) {\n stderr(indent(`Response: ${format(response)}`))\n }\n return { file: true }\n }\n\n case 'EREQUEST': {\n const { url, method } = err.cause\n const { code, syscall } = err.cause.cause ?? {}\n stderr(`Request Error: ${err.message}`)\n if (code) {\n stderr(indent(`Code: ${format(code)}`))\n }\n if (syscall) {\n stderr(indent(`Syscall: ${format(syscall)}`))\n }\n if (url) {\n stderr(indent(`URL: ${formatURL(url, format)}`))\n }\n if (method) {\n stderr(indent(`Method: ${format(method)}`))\n }\n return { file: true }\n }\n\n case 'ECONFIG': {\n const { found, wanted, validOptions } = err.cause\n stderr(`Config Error: ${err.message}`)\n if (found) {\n stderr(indent(`Found: ${format(found)}`))\n }\n if (wanted) {\n stderr(indent(`Wanted: ${format(wanted)}`))\n }\n if (validOptions) {\n stderr(indent(`Valid Options: ${format(validOptions)}`))\n }\n return {}\n }\n }\n}\n"]}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { SecurityArchive } from '@vltpkg/security-archive';
|
|
2
|
+
import type { EdgeLike, NodeLike } from '@vltpkg/types';
|
|
3
|
+
import type { LoadedConfig } from './config/index.ts';
|
|
4
|
+
export type HostContextsMapResult = {
|
|
5
|
+
initialEdges: EdgeLike[];
|
|
6
|
+
initialNodes: NodeLike[];
|
|
7
|
+
edges: EdgeLike[];
|
|
8
|
+
nodes: NodeLike[];
|
|
9
|
+
securityArchive: SecurityArchive;
|
|
10
|
+
};
|
|
11
|
+
/**
|
|
12
|
+
* Creates a Map of host context functions that can be used by the :host
|
|
13
|
+
* pseudo selector to dynamically load graphs from different sources.
|
|
14
|
+
*/
|
|
15
|
+
export declare const createHostContextsMap: (conf: LoadedConfig) => Promise<Map<string, () => Promise<HostContextsMapResult>>>;
|
|
16
|
+
//# sourceMappingURL=query-host-contexts.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"query-host-contexts.d.ts","sourceRoot":"","sources":["../../src/query-host-contexts.ts"],"names":[],"mappings":"AAQA,OAAO,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAA;AAG1D,OAAO,KAAK,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAA;AACvD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAA;AAErD,MAAM,MAAM,qBAAqB,GAAG;IAClC,YAAY,EAAE,QAAQ,EAAE,CAAA;IACxB,YAAY,EAAE,QAAQ,EAAE,CAAA;IACxB,KAAK,EAAE,QAAQ,EAAE,CAAA;IACjB,KAAK,EAAE,QAAQ,EAAE,CAAA;IACjB,eAAe,EAAE,eAAe,CAAA;CACjC,CAAA;AA8CD;;;GAGG;AACH,eAAO,MAAM,qBAAqB,SAC1B,YAAY,KACjB,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,MAAM,OAAO,CAAC,qBAAqB,CAAC,CAAC,CAiH3D,CAAA"}
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
import { homedir } from 'node:os';
|
|
2
|
+
import { parse, posix } from 'node:path';
|
|
3
|
+
import { getProjectData, readProjectFolders, reloadConfig, } from '@vltpkg/server';
|
|
4
|
+
import { actual, createVirtualRoot } from '@vltpkg/graph';
|
|
5
|
+
import { SecurityArchive } from '@vltpkg/security-archive';
|
|
6
|
+
import { error } from '@vltpkg/error-cause';
|
|
7
|
+
// In restricted environments (like locked-down Codespaces),
|
|
8
|
+
// homedir() might fail. Fall back to parent directory.
|
|
9
|
+
let foundHome;
|
|
10
|
+
try {
|
|
11
|
+
foundHome = posix.format(parse(homedir()));
|
|
12
|
+
/* c8 ignore next 3 */
|
|
13
|
+
}
|
|
14
|
+
catch { }
|
|
15
|
+
const home = foundHome ?? posix.dirname(posix.format(parse(process.cwd())));
|
|
16
|
+
/**
|
|
17
|
+
* Generates possible project keys for a given folder.
|
|
18
|
+
*/
|
|
19
|
+
const getPossibleProjectKeys = (folder, scurry) => {
|
|
20
|
+
const relativePath = posix.relative(scurry.cwd.fullpathPosix(), folder.fullpathPosix());
|
|
21
|
+
const absolutePath = folder.fullpathPosix();
|
|
22
|
+
const homeRelativePath = posix.relative(scurry.resolvePosix(home), folder.fullpathPosix());
|
|
23
|
+
const dotRelativeKey = relativePath === '' ? 'file:.' : `file:./${relativePath}`;
|
|
24
|
+
const relativeKey = `file:${relativePath}`;
|
|
25
|
+
const absoluteKey = `file:${absolutePath}`;
|
|
26
|
+
const homeRelativeKey = `file:~/${homeRelativePath}`;
|
|
27
|
+
const keys = [
|
|
28
|
+
relativeKey,
|
|
29
|
+
dotRelativeKey,
|
|
30
|
+
absoluteKey,
|
|
31
|
+
homeRelativeKey,
|
|
32
|
+
`${relativeKey}/`,
|
|
33
|
+
`${dotRelativeKey}/`,
|
|
34
|
+
`${absoluteKey}/`,
|
|
35
|
+
`${homeRelativeKey}/`,
|
|
36
|
+
];
|
|
37
|
+
return new Set(keys);
|
|
38
|
+
};
|
|
39
|
+
/**
|
|
40
|
+
* Creates a Map of host context functions that can be used by the :host
|
|
41
|
+
* pseudo selector to dynamically load graphs from different sources.
|
|
42
|
+
*/
|
|
43
|
+
export const createHostContextsMap = async (conf) => {
|
|
44
|
+
const hostContexts = new Map();
|
|
45
|
+
// Read all project folders from the configured paths
|
|
46
|
+
const { scurry } = conf.options;
|
|
47
|
+
const projectFolders = await readProjectFolders({
|
|
48
|
+
scurry,
|
|
49
|
+
userDefinedProjectPaths: conf.options['dashboard-root'] ?? [],
|
|
50
|
+
});
|
|
51
|
+
for (const folder of projectFolders) {
|
|
52
|
+
const retrieveProjectGraph = async () => {
|
|
53
|
+
const initialEdges = [];
|
|
54
|
+
const initialNodes = [];
|
|
55
|
+
const config = await reloadConfig(folder.fullpath());
|
|
56
|
+
// load each individual graph
|
|
57
|
+
const graph = actual.load({
|
|
58
|
+
...config.options,
|
|
59
|
+
projectRoot: folder.fullpath(),
|
|
60
|
+
skipLoadingNodesOnModifiersChange: false,
|
|
61
|
+
});
|
|
62
|
+
initialEdges.push(...graph.edges);
|
|
63
|
+
initialNodes.push(...graph.nodes.values());
|
|
64
|
+
// Initialize security archive with all loaded nodes
|
|
65
|
+
const securityArchive = await SecurityArchive.start({
|
|
66
|
+
nodes: initialNodes,
|
|
67
|
+
});
|
|
68
|
+
return {
|
|
69
|
+
initialEdges,
|
|
70
|
+
initialNodes,
|
|
71
|
+
edges: [],
|
|
72
|
+
nodes: [graph.mainImporter],
|
|
73
|
+
securityArchive,
|
|
74
|
+
};
|
|
75
|
+
};
|
|
76
|
+
// add multiple keys for each project folder
|
|
77
|
+
for (const path of getPossibleProjectKeys(folder, scurry)) {
|
|
78
|
+
if (!hostContexts.has(path)) {
|
|
79
|
+
hostContexts.set(path, retrieveProjectGraph);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
// Define local context - loads graphs from all projects in user's project paths
|
|
84
|
+
hostContexts.set('local', async () => {
|
|
85
|
+
// Load graphs from each project folder
|
|
86
|
+
const initialEdges = [];
|
|
87
|
+
const initialNodes = [];
|
|
88
|
+
const mainImporters = [];
|
|
89
|
+
for (const folder of projectFolders) {
|
|
90
|
+
try {
|
|
91
|
+
const config = await reloadConfig(folder.fullpath());
|
|
92
|
+
const projectInfo = getProjectData({
|
|
93
|
+
packageJson: config.options.packageJson,
|
|
94
|
+
scurry: config.options.scurry,
|
|
95
|
+
}, folder);
|
|
96
|
+
// only include projects that are vlt-installed
|
|
97
|
+
if (!projectInfo.vltInstalled) {
|
|
98
|
+
continue;
|
|
99
|
+
}
|
|
100
|
+
// load each individual graph
|
|
101
|
+
const graph = actual.load({
|
|
102
|
+
...config.options,
|
|
103
|
+
projectRoot: folder.fullpath(),
|
|
104
|
+
skipLoadingNodesOnModifiersChange: false,
|
|
105
|
+
});
|
|
106
|
+
initialEdges.push(...graph.edges);
|
|
107
|
+
initialNodes.push(...graph.nodes.values());
|
|
108
|
+
mainImporters.push(graph.mainImporter);
|
|
109
|
+
}
|
|
110
|
+
catch (_error) {
|
|
111
|
+
// Skip projects that fail to load
|
|
112
|
+
// This might happen for projects without proper package.json
|
|
113
|
+
// or other loading issues
|
|
114
|
+
continue;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
// Initialize security archive with all loaded nodes
|
|
118
|
+
const securityArchive = await SecurityArchive.start({
|
|
119
|
+
nodes: initialNodes,
|
|
120
|
+
});
|
|
121
|
+
const virtualRoot = createVirtualRoot('local', conf.options, mainImporters);
|
|
122
|
+
if (!virtualRoot) {
|
|
123
|
+
throw error('Failed to create virtual root for local context');
|
|
124
|
+
}
|
|
125
|
+
return {
|
|
126
|
+
initialEdges,
|
|
127
|
+
initialNodes,
|
|
128
|
+
edges: [],
|
|
129
|
+
nodes: [virtualRoot],
|
|
130
|
+
securityArchive,
|
|
131
|
+
};
|
|
132
|
+
});
|
|
133
|
+
return hostContexts;
|
|
134
|
+
};
|
|
135
|
+
//# sourceMappingURL=query-host-contexts.js.map
|
|
@@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AC,WAAW,CAAC,YAAY,EAAE,CAAC;oBAC9B,SAAQ;gBACV,CAAC;gBAED,6BAA6B;gBAC7B,MAAM,KAAK,GAAG,MAAM,CAAC,IAAI,CAAC;oBACxB,GAAG,MAAM,CAAC,OAAO;oBACjB,WAAW,EAAE,MAAM,CAAC,QAAQ,EAAE;oBAC9B,iCAAiC,EAAE,KAAK;iBACzC,CAAC,CAAA;gBACF,YAAY,CAAC,IAAI,CAAC,GAAG,KAAK,CAAC,KAAK,CAAC,CAAA;gBACjC,YAAY,CAAC,IAAI,CAAC,GAAG,KAAK,CAAC,KAAK,CAAC,MAAM,EAAE,CAAC,CAAA;gBAC1C,aAAa,CAAC,IAAI,CAAC,KAAK,CAAC,YAAY,CAAC,CAAA;YACxC,CAAC;YAAC,OAAO,MAAM,EAAE,CAAC;gBAChB,kCAAkC;gBAClC,6DAA6D;gBAC7D,0BAA0B;gBAC1B,SAAQ;YACV,CAAC;QACH,CAAC;QAED,oDAAoD;QACpD,MAAM,eAAe,GAAG,MAAM,eAAe,CAAC,KAAK,CAAC;YAClD,KAAK,EAAE,YAAY;SACpB,CAAC,CAAA;QAEF,MAAM,WAAW,GAAG,iBAAiB,CACnC,OAAO,EACP,IAAI,CAAC,OAAO,EACZ,aAAa,CACd,CAAA;QAED,IAAI,CAAC,WAAW,EAAE,CAAC;YACjB,MAAM,KAAK,CAAC,iDAAiD,CAAC,CAAA;QAChE,CAAC;QAED,OAAO;YACL,YAAY;YACZ,YAAY;YACZ,KAAK,EAAE,EAAE;YACT,KAAK,EAAE,CAAC,WAAW,CAAC;YACpB,eAAe;SAChB,CAAA;IACH,CAAC,CAAC,CAAA;IAEF,OAAO,YAAY,CAAA;AACrB,CAAC,CAAA","sourcesContent":["import { homedir } from 'node:os'\nimport { parse, posix } from 'node:path'\nimport {\n getProjectData,\n readProjectFolders,\n reloadConfig,\n} from '@vltpkg/server'\nimport { actual, createVirtualRoot } from '@vltpkg/graph'\nimport { SecurityArchive } from '@vltpkg/security-archive'\nimport { error } from '@vltpkg/error-cause'\nimport type { PathBase, PathScurry } from 'path-scurry'\nimport type { EdgeLike, NodeLike } from '@vltpkg/types'\nimport type { LoadedConfig } from './config/index.ts'\n\nexport type HostContextsMapResult = {\n initialEdges: EdgeLike[]\n initialNodes: NodeLike[]\n edges: EdgeLike[]\n nodes: NodeLike[]\n securityArchive: SecurityArchive\n}\n\n// In restricted environments (like locked-down Codespaces),\n// homedir() might fail. Fall back to parent directory.\nlet foundHome\ntry {\n foundHome = posix.format(parse(homedir()))\n /* c8 ignore next 3 */\n} catch {}\nconst home =\n foundHome ?? posix.dirname(posix.format(parse(process.cwd())))\n\n/**\n * Generates possible project keys for a given folder.\n */\nconst getPossibleProjectKeys = (\n folder: PathBase,\n scurry: PathScurry,\n): Set<string> => {\n const relativePath = posix.relative(\n scurry.cwd.fullpathPosix(),\n folder.fullpathPosix(),\n )\n const absolutePath = folder.fullpathPosix()\n const homeRelativePath = posix.relative(\n scurry.resolvePosix(home),\n folder.fullpathPosix(),\n )\n const dotRelativeKey =\n relativePath === '' ? 'file:.' : `file:./${relativePath}`\n const relativeKey = `file:${relativePath}`\n const absoluteKey = `file:${absolutePath}`\n const homeRelativeKey = `file:~/${homeRelativePath}`\n const keys = [\n relativeKey,\n dotRelativeKey,\n absoluteKey,\n homeRelativeKey,\n `${relativeKey}/`,\n `${dotRelativeKey}/`,\n `${absoluteKey}/`,\n `${homeRelativeKey}/`,\n ]\n return new Set(keys)\n}\n\n/**\n * Creates a Map of host context functions that can be used by the :host\n * pseudo selector to dynamically load graphs from different sources.\n */\nexport const createHostContextsMap = async (\n conf: LoadedConfig,\n): Promise<Map<string, () => Promise<HostContextsMapResult>>> => {\n const hostContexts = new Map<\n string,\n () => Promise<HostContextsMapResult>\n >()\n // Read all project folders from the configured paths\n const { scurry } = conf.options\n const projectFolders = await readProjectFolders({\n scurry,\n userDefinedProjectPaths: conf.options['dashboard-root'] ?? [],\n })\n\n for (const folder of projectFolders) {\n const retrieveProjectGraph = async () => {\n const initialEdges: EdgeLike[] = []\n const initialNodes: NodeLike[] = []\n const config = await reloadConfig(folder.fullpath())\n\n // load each individual graph\n const graph = actual.load({\n ...config.options,\n projectRoot: folder.fullpath(),\n skipLoadingNodesOnModifiersChange: false,\n })\n initialEdges.push(...graph.edges)\n initialNodes.push(...graph.nodes.values())\n\n // Initialize security archive with all loaded nodes\n const securityArchive = await SecurityArchive.start({\n nodes: initialNodes,\n })\n\n return {\n initialEdges,\n initialNodes,\n edges: [],\n nodes: [graph.mainImporter],\n securityArchive,\n }\n }\n\n // add multiple keys for each project folder\n for (const path of getPossibleProjectKeys(folder, scurry)) {\n if (!hostContexts.has(path)) {\n hostContexts.set(path, retrieveProjectGraph)\n }\n }\n }\n\n // Define local context - loads graphs from all projects in user's project paths\n hostContexts.set('local', async () => {\n // Load graphs from each project folder\n const initialEdges: EdgeLike[] = []\n const initialNodes: NodeLike[] = []\n const mainImporters: NodeLike[] = []\n for (const folder of projectFolders) {\n try {\n const config = await reloadConfig(folder.fullpath())\n const projectInfo = getProjectData(\n {\n packageJson: config.options.packageJson,\n scurry: config.options.scurry,\n },\n folder,\n )\n\n // only include projects that are vlt-installed\n if (!projectInfo.vltInstalled) {\n continue\n }\n\n // load each individual graph\n const graph = actual.load({\n ...config.options,\n projectRoot: folder.fullpath(),\n skipLoadingNodesOnModifiersChange: false,\n })\n initialEdges.push(...graph.edges)\n initialNodes.push(...graph.nodes.values())\n mainImporters.push(graph.mainImporter)\n } catch (_error) {\n // Skip projects that fail to load\n // This might happen for projects without proper package.json\n // or other loading issues\n continue\n }\n }\n\n // Initialize security archive with all loaded nodes\n const securityArchive = await SecurityArchive.start({\n nodes: initialNodes,\n })\n\n const virtualRoot = createVirtualRoot(\n 'local',\n conf.options,\n mainImporters,\n )\n\n if (!virtualRoot) {\n throw error('Failed to create virtual root for local context')\n }\n\n return {\n initialEdges,\n initialNodes,\n edges: [],\n nodes: [virtualRoot],\n securityArchive,\n }\n })\n\n return hostContexts\n}\n"]}
|
package/dist/esm/start-gui.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"start-gui.d.ts","sourceRoot":"","sources":["../../src/start-gui.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"start-gui.d.ts","sourceRoot":"","sources":["../../src/start-gui.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AAC7C,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAA;AAGrD,eAAO,MAAM,uBAAuB,YAAmB;IACrD,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB,aAAa,CAAC,EAAE,MAAM,CAAA;IACtB,WAAW,EAAE,MAAM,CAAA;IACnB,MAAM,EAAE,UAAU,CAAA;CACnB,oBAcA,CAAA;AAaD,eAAO,MAAM,QAAQ,SACb,YAAY,kBACF,MAAM,gDA0CvB,CAAA"}
|