@vltpkg/graph 0.0.0-0.1730239248325
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +15 -0
- package/README.md +33 -0
- package/dist/esm/actual/load.d.ts +54 -0
- package/dist/esm/actual/load.d.ts.map +1 -0
- package/dist/esm/actual/load.js +243 -0
- package/dist/esm/actual/load.js.map +1 -0
- package/dist/esm/browser.d.ts +9 -0
- package/dist/esm/browser.d.ts.map +1 -0
- package/dist/esm/browser.js +11 -0
- package/dist/esm/browser.js.map +1 -0
- package/dist/esm/dependencies.d.ts +69 -0
- package/dist/esm/dependencies.d.ts.map +1 -0
- package/dist/esm/dependencies.js +71 -0
- package/dist/esm/dependencies.js.map +1 -0
- package/dist/esm/diff.d.ts +49 -0
- package/dist/esm/diff.d.ts.map +1 -0
- package/dist/esm/diff.js +123 -0
- package/dist/esm/diff.js.map +1 -0
- package/dist/esm/edge.d.ts +41 -0
- package/dist/esm/edge.d.ts.map +1 -0
- package/dist/esm/edge.js +66 -0
- package/dist/esm/edge.js.map +1 -0
- package/dist/esm/graph.d.ts +123 -0
- package/dist/esm/graph.d.ts.map +1 -0
- package/dist/esm/graph.js +301 -0
- package/dist/esm/graph.js.map +1 -0
- package/dist/esm/ideal/add-nodes.d.ts +19 -0
- package/dist/esm/ideal/add-nodes.d.ts.map +1 -0
- package/dist/esm/ideal/add-nodes.js +28 -0
- package/dist/esm/ideal/add-nodes.js.map +1 -0
- package/dist/esm/ideal/append-nodes.d.ts +9 -0
- package/dist/esm/ideal/append-nodes.d.ts.map +1 -0
- package/dist/esm/ideal/append-nodes.js +121 -0
- package/dist/esm/ideal/append-nodes.js.map +1 -0
- package/dist/esm/ideal/build-ideal-from-starting-graph.d.ts +15 -0
- package/dist/esm/ideal/build-ideal-from-starting-graph.d.ts.map +1 -0
- package/dist/esm/ideal/build-ideal-from-starting-graph.js +28 -0
- package/dist/esm/ideal/build-ideal-from-starting-graph.js.map +1 -0
- package/dist/esm/ideal/build.d.ts +32 -0
- package/dist/esm/ideal/build.d.ts.map +1 -0
- package/dist/esm/ideal/build.js +42 -0
- package/dist/esm/ideal/build.js.map +1 -0
- package/dist/esm/ideal/get-importer-specs.d.ts +13 -0
- package/dist/esm/ideal/get-importer-specs.d.ts.map +1 -0
- package/dist/esm/ideal/get-importer-specs.js +76 -0
- package/dist/esm/ideal/get-importer-specs.js.map +1 -0
- package/dist/esm/ideal/remove-nodes.d.ts +7 -0
- package/dist/esm/ideal/remove-nodes.d.ts.map +1 -0
- package/dist/esm/ideal/remove-nodes.js +19 -0
- package/dist/esm/ideal/remove-nodes.js.map +1 -0
- package/dist/esm/ideal/remove-satisfied-specs.d.ts +8 -0
- package/dist/esm/ideal/remove-satisfied-specs.d.ts.map +1 -0
- package/dist/esm/ideal/remove-satisfied-specs.js +35 -0
- package/dist/esm/ideal/remove-satisfied-specs.js.map +1 -0
- package/dist/esm/ideal/types.d.ts +35 -0
- package/dist/esm/ideal/types.d.ts.map +1 -0
- package/dist/esm/ideal/types.js +2 -0
- package/dist/esm/ideal/types.js.map +1 -0
- package/dist/esm/index.d.ts +31 -0
- package/dist/esm/index.d.ts.map +1 -0
- package/dist/esm/index.js +26 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/lockfile/load-edges.d.ts +5 -0
- package/dist/esm/lockfile/load-edges.d.ts.map +1 -0
- package/dist/esm/lockfile/load-edges.js +40 -0
- package/dist/esm/lockfile/load-edges.js.map +1 -0
- package/dist/esm/lockfile/load-nodes.d.ts +4 -0
- package/dist/esm/lockfile/load-nodes.d.ts.map +1 -0
- package/dist/esm/lockfile/load-nodes.js +28 -0
- package/dist/esm/lockfile/load-nodes.js.map +1 -0
- package/dist/esm/lockfile/load.d.ts +33 -0
- package/dist/esm/lockfile/load.d.ts.map +1 -0
- package/dist/esm/lockfile/load.js +53 -0
- package/dist/esm/lockfile/load.js.map +1 -0
- package/dist/esm/lockfile/save.d.ts +18 -0
- package/dist/esm/lockfile/save.d.ts.map +1 -0
- package/dist/esm/lockfile/save.js +128 -0
- package/dist/esm/lockfile/save.js.map +1 -0
- package/dist/esm/lockfile/types.d.ts +60 -0
- package/dist/esm/lockfile/types.d.ts.map +1 -0
- package/dist/esm/lockfile/types.js +13 -0
- package/dist/esm/lockfile/types.js.map +1 -0
- package/dist/esm/node.d.ts +144 -0
- package/dist/esm/node.d.ts.map +1 -0
- package/dist/esm/node.js +266 -0
- package/dist/esm/node.js.map +1 -0
- package/dist/esm/non-empty-list.d.ts +3 -0
- package/dist/esm/non-empty-list.d.ts.map +1 -0
- package/dist/esm/non-empty-list.js +3 -0
- package/dist/esm/non-empty-list.js.map +1 -0
- package/dist/esm/package.json +3 -0
- package/dist/esm/reify/add-edge.d.ts +11 -0
- package/dist/esm/reify/add-edge.d.ts.map +1 -0
- package/dist/esm/reify/add-edge.js +43 -0
- package/dist/esm/reify/add-edge.js.map +1 -0
- package/dist/esm/reify/add-edges.d.ts +6 -0
- package/dist/esm/reify/add-edges.d.ts.map +1 -0
- package/dist/esm/reify/add-edges.js +13 -0
- package/dist/esm/reify/add-edges.js.map +1 -0
- package/dist/esm/reify/add-nodes.d.ts +7 -0
- package/dist/esm/reify/add-nodes.d.ts.map +1 -0
- package/dist/esm/reify/add-nodes.js +37 -0
- package/dist/esm/reify/add-nodes.js.map +1 -0
- package/dist/esm/reify/bin-paths.d.ts +4 -0
- package/dist/esm/reify/bin-paths.d.ts.map +1 -0
- package/dist/esm/reify/bin-paths.js +23 -0
- package/dist/esm/reify/bin-paths.js.map +1 -0
- package/dist/esm/reify/build.d.ts +5 -0
- package/dist/esm/reify/build.d.ts.map +1 -0
- package/dist/esm/reify/build.js +90 -0
- package/dist/esm/reify/build.js.map +1 -0
- package/dist/esm/reify/delete-edge.d.ts +5 -0
- package/dist/esm/reify/delete-edge.d.ts.map +1 -0
- package/dist/esm/reify/delete-edge.js +29 -0
- package/dist/esm/reify/delete-edge.js.map +1 -0
- package/dist/esm/reify/delete-edges.d.ts +5 -0
- package/dist/esm/reify/delete-edges.d.ts.map +1 -0
- package/dist/esm/reify/delete-edges.js +14 -0
- package/dist/esm/reify/delete-edges.js.map +1 -0
- package/dist/esm/reify/delete-nodes.d.ts +5 -0
- package/dist/esm/reify/delete-nodes.d.ts.map +1 -0
- package/dist/esm/reify/delete-nodes.js +12 -0
- package/dist/esm/reify/delete-nodes.js.map +1 -0
- package/dist/esm/reify/index.d.ts +16 -0
- package/dist/esm/reify/index.d.ts.map +1 -0
- package/dist/esm/reify/index.js +85 -0
- package/dist/esm/reify/index.js.map +1 -0
- package/dist/esm/reify/optional-fail.d.ts +16 -0
- package/dist/esm/reify/optional-fail.d.ts.map +1 -0
- package/dist/esm/reify/optional-fail.js +16 -0
- package/dist/esm/reify/optional-fail.js.map +1 -0
- package/dist/esm/reify/rollback.d.ts +5 -0
- package/dist/esm/reify/rollback.d.ts.map +1 -0
- package/dist/esm/reify/rollback.js +24 -0
- package/dist/esm/reify/rollback.js.map +1 -0
- package/dist/esm/reify/update-importers-package-json.d.ts +36 -0
- package/dist/esm/reify/update-importers-package-json.d.ts.map +1 -0
- package/dist/esm/reify/update-importers-package-json.js +95 -0
- package/dist/esm/reify/update-importers-package-json.js.map +1 -0
- package/dist/esm/remove-optional-subgraph.d.ts +34 -0
- package/dist/esm/remove-optional-subgraph.d.ts.map +1 -0
- package/dist/esm/remove-optional-subgraph.js +48 -0
- package/dist/esm/remove-optional-subgraph.js.map +1 -0
- package/dist/esm/stringify-node.d.ts +3 -0
- package/dist/esm/stringify-node.d.ts.map +1 -0
- package/dist/esm/stringify-node.js +24 -0
- package/dist/esm/stringify-node.js.map +1 -0
- package/dist/esm/types.d.ts +39 -0
- package/dist/esm/types.d.ts.map +1 -0
- package/dist/esm/types.js +2 -0
- package/dist/esm/types.js.map +1 -0
- package/dist/esm/visualization/human-readable-output.d.ts +25 -0
- package/dist/esm/visualization/human-readable-output.d.ts.map +1 -0
- package/dist/esm/visualization/human-readable-output.js +132 -0
- package/dist/esm/visualization/human-readable-output.js.map +1 -0
- package/dist/esm/visualization/json-output.d.ts +37 -0
- package/dist/esm/visualization/json-output.d.ts.map +1 -0
- package/dist/esm/visualization/json-output.js +28 -0
- package/dist/esm/visualization/json-output.js.map +1 -0
- package/dist/esm/visualization/mermaid-output.d.ts +11 -0
- package/dist/esm/visualization/mermaid-output.d.ts.map +1 -0
- package/dist/esm/visualization/mermaid-output.js +68 -0
- package/dist/esm/visualization/mermaid-output.js.map +1 -0
- package/dist/esm/visualization/object-like-output.d.ts +3 -0
- package/dist/esm/visualization/object-like-output.d.ts.map +1 -0
- package/dist/esm/visualization/object-like-output.js +49 -0
- package/dist/esm/visualization/object-like-output.js.map +1 -0
- package/package.json +86 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"load.js","sourceRoot":"","sources":["../../../src/lockfile/load.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAA;AAElD,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAA;AAE7C,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAA;AACtC,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AAEnC,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAA;AAC3C,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAA;AAC3C,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAA;AA0BnC,MAAM,CAAC,MAAM,IAAI,GAAG,CAAC,OAAoB,EAAS,EAAE;IAClD,MAAM,EAAE,WAAW,EAAE,GAAG,OAAO,CAAA;IAC/B,OAAO,UAAU,CACf,OAAO,EACP,IAAI,CAAC,KAAK,CACR,YAAY,CAAC,OAAO,CAAC,WAAW,EAAE,eAAe,CAAC,EAAE;QAClD,QAAQ,EAAE,MAAM;KACjB,CAAC,CACH,CACF,CAAA;AACH,CAAC,CAAA;AAED,MAAM,CAAC,MAAM,UAAU,GAAG,C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B,YAAY;QACZ,QAAQ;KACT,CAAC,CAAA;IAEF,SAAS,CAAC,KAAK,EAAE,YAAY,CAAC,KAAK,CAAC,CAAA;IACpC,SAAS,CAAC,KAAK,EAAE,YAAY,CAAC,KAAK,EAAE,aAAa,CAAC,CAAA;IAEnD,OAAO,KAAK,CAAA;AACd,CAAC,CAAA","sourcesContent":["import { PackageJson } from '@vltpkg/package-json'\nimport { Manifest } from '@vltpkg/types'\nimport { Monorepo } from '@vltpkg/workspaces'\nimport type { SpecOptions } from '@vltpkg/spec'\nimport { readFileSync } from 'node:fs'\nimport { resolve } from 'node:path'\nimport { PathScurry } from 'path-scurry'\nimport { loadEdges } from './load-edges.js'\nimport { loadNodes } from './load-nodes.js'\nimport { Graph } from '../graph.js'\nimport type { LockfileData } from './types.js'\n\nexport type LoadOptions = SpecOptions & {\n /**\n * The project root dirname.\n */\n projectRoot: string\n /**\n * The project root manifest.\n */\n mainManifest: Manifest\n /**\n * A {@link Monorepo} object, for managing workspaces\n */\n monorepo?: Monorepo\n /**\n * A {@link PackageJson} object, for sharing manifest caches\n */\n packageJson?: PackageJson\n /**\n * A {@link PathScurry} object, for use in globs\n */\n scurry?: PathScurry\n}\n\nexport const load = (options: LoadOptions): Graph => {\n const { projectRoot } = options\n return loadObject(\n options,\n JSON.parse(\n readFileSync(resolve(projectRoot, 'vlt-lock.json'), {\n encoding: 'utf8',\n }),\n ),\n )\n}\n\nexport const loadHidden = (options: LoadOptions): Graph => {\n const { projectRoot } = options\n return loadObject(\n options,\n JSON.parse(\n readFileSync(\n resolve(projectRoot, 'node_modules/.vlt-lock.json'),\n { encoding: 'utf8' },\n ),\n ),\n )\n}\n\nexport const loadObject = (\n options: LoadOptions,\n lockfileData: LockfileData,\n) => {\n const { mainManifest, scurry } = options\n const packageJson = options.packageJson ?? new PackageJson()\n const monorepo =\n options.monorepo ??\n Monorepo.maybeLoad(options.projectRoot, { packageJson, scurry })\n const {\n 'scope-registries': scopeRegistries,\n registry,\n registries,\n 'git-hosts': gitHosts,\n 'git-host-archives': gitHostArchives,\n } = lockfileData.options\n const mergedOptions = {\n ...options,\n 'scope-registries': {\n ...options['scope-registries'],\n ...scopeRegistries,\n },\n registry: registry ?? options.registry,\n registries: {\n ...options.registries,\n ...registries,\n },\n 'git-hosts': {\n ...options['git-hosts'],\n ...gitHosts,\n },\n 'git-host-archives': {\n ...options['git-host-archives'],\n ...gitHostArchives,\n },\n }\n const graph = new Graph({\n ...mergedOptions,\n mainManifest,\n monorepo,\n })\n\n loadNodes(graph, lockfileData.nodes)\n loadEdges(graph, lockfileData.edges, mergedOptions)\n\n return graph\n}\n"]}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { SpecOptions } from '@vltpkg/spec';
|
|
2
|
+
import { type Graph } from '../graph.js';
|
|
3
|
+
import { LockfileData } from './types.js';
|
|
4
|
+
export type SaveOptions = SpecOptions & {
|
|
5
|
+
/**
|
|
6
|
+
* The graph to be stored in the lockfile.
|
|
7
|
+
*/
|
|
8
|
+
graph: Graph;
|
|
9
|
+
/**
|
|
10
|
+
* Should it save manifest data in the lockfile?
|
|
11
|
+
*/
|
|
12
|
+
saveManifests?: boolean;
|
|
13
|
+
};
|
|
14
|
+
export declare const lockfileData: ({ graph, "git-hosts": gitHosts, "git-host-archives": gitHostArchives, registry, registries, saveManifests, "scope-registries": scopeRegistries, }: SaveOptions) => LockfileData;
|
|
15
|
+
export declare const saveData: (data: LockfileData, fileName: string, saveManifests?: boolean) => void;
|
|
16
|
+
export declare const save: (options: SaveOptions) => void;
|
|
17
|
+
export declare const saveHidden: (options: SaveOptions) => void;
|
|
18
|
+
//# sourceMappingURL=save.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"save.d.ts","sourceRoot":"","sources":["../../../src/lockfile/save.ts"],"names":[],"mappings":"AACA,OAAO,EAML,WAAW,EACZ,MAAM,cAAc,CAAA;AAIrB,OAAO,EAAE,KAAK,KAAK,EAAE,MAAM,aAAa,CAAA;AAExC,OAAO,EAEL,YAAY,EAKb,MAAM,YAAY,CAAA;AAEnB,MAAM,MAAM,WAAW,GAAG,WAAW,GAAG;IACtC;;OAEG;IACH,KAAK,EAAE,KAAK,CAAA;IACZ;;OAEG;IACH,aAAa,CAAC,EAAE,OAAO,CAAA;CACxB,CAAA;AAgGD,eAAO,MAAM,YAAY,sJAQtB,WAAW,KAAG,YAwChB,CAAA;AAeD,eAAO,MAAM,QAAQ,SACb,YAAY,YACR,MAAM,kCAMjB,CAAA;AAED,eAAO,MAAM,IAAI,YAAa,WAAW,SAKxC,CAAA;AAED,eAAO,MAAM,UAAU,YAAa,WAAW,SAS9C,CAAA"}
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
import { defaultRegistry, defaultRegistries, defaultGitHosts, defaultGitHostArchives, defaultScopeRegistries, } from '@vltpkg/spec';
|
|
2
|
+
import { mkdirSync, writeFileSync } from 'node:fs';
|
|
3
|
+
import { dirname, resolve } from 'node:path';
|
|
4
|
+
import { getFlagNumFromNode, } from './types.js';
|
|
5
|
+
const formatNodes = (nodes, saveManifests, registry) => {
|
|
6
|
+
// we do not store importers in the lockfile, though we do store
|
|
7
|
+
// their edges. when we load, we always read workspaces/main fresh.
|
|
8
|
+
const arr = [...nodes].filter(node => !node.importer);
|
|
9
|
+
// nodes are sorted in order to have a deterministic result
|
|
10
|
+
const orderedNodes = arr.sort((a, b) => a.id.localeCompare(b.id, 'en'));
|
|
11
|
+
const res = {};
|
|
12
|
+
for (const node of orderedNodes) {
|
|
13
|
+
const customRegistry = node.resolved && registry && !node.resolved.startsWith(registry);
|
|
14
|
+
const resolved = customRegistry ? node.resolved : undefined;
|
|
15
|
+
// if it's in a location other than the default, stash that
|
|
16
|
+
const location = (node.id.startsWith('file') ||
|
|
17
|
+
node.location.endsWith('/node_modules/.vlt/' +
|
|
18
|
+
node.id +
|
|
19
|
+
'/node_modules/' +
|
|
20
|
+
node.name)) ?
|
|
21
|
+
undefined
|
|
22
|
+
: node.location;
|
|
23
|
+
const flags = getFlagNumFromNode(node);
|
|
24
|
+
const lockfileNode = [flags, node.name];
|
|
25
|
+
if (node.integrity) {
|
|
26
|
+
lockfileNode[2] = node.integrity;
|
|
27
|
+
}
|
|
28
|
+
if (resolved) {
|
|
29
|
+
lockfileNode[3] = resolved;
|
|
30
|
+
}
|
|
31
|
+
if (location) {
|
|
32
|
+
lockfileNode[4] = location;
|
|
33
|
+
}
|
|
34
|
+
if (saveManifests) {
|
|
35
|
+
lockfileNode[5] = node.manifest;
|
|
36
|
+
}
|
|
37
|
+
res[node.id] = lockfileNode;
|
|
38
|
+
}
|
|
39
|
+
return res;
|
|
40
|
+
};
|
|
41
|
+
const formatEdges = (edges) => Object.fromEntries([...edges]
|
|
42
|
+
.sort((a, b) =>
|
|
43
|
+
/* c8 ignore start - nondeterminstic and annoying to test */
|
|
44
|
+
// sort importers to the top, then alphabetically by
|
|
45
|
+
// id, type, target
|
|
46
|
+
Number(b.from.importer) - Number(a.from.importer) ||
|
|
47
|
+
a.from.id.localeCompare(b.from.id, 'en') ||
|
|
48
|
+
a.type.localeCompare(b.type, 'en') ||
|
|
49
|
+
(a.to?.id ?? '').localeCompare(b.to?.id ?? ''))
|
|
50
|
+
.map((edge) => [
|
|
51
|
+
`${edge.from.id} ${edge.spec.name}`,
|
|
52
|
+
`${edge.type} ${edge.spec.bareSpec || '*'} ${edge.to?.id ?? 'MISSING'}`,
|
|
53
|
+
]));
|
|
54
|
+
const isRecordStringString = (registries) => !(!registries || typeof registries === 'string');
|
|
55
|
+
const removeDefaultItems = (defaultItems, items) => {
|
|
56
|
+
const res = {};
|
|
57
|
+
for (const [key, value] of Object.entries(items)) {
|
|
58
|
+
if (!defaultItems[key] || defaultItems[key] !== value) {
|
|
59
|
+
res[key] = value;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
return res;
|
|
63
|
+
};
|
|
64
|
+
export const lockfileData = ({ graph, 'git-hosts': gitHosts, 'git-host-archives': gitHostArchives, registry, registries, saveManifests, 'scope-registries': scopeRegistries, }) => {
|
|
65
|
+
const cleanGitHosts = isRecordStringString(gitHosts) ?
|
|
66
|
+
removeDefaultItems(defaultGitHosts, gitHosts)
|
|
67
|
+
: undefined;
|
|
68
|
+
const cleanGitHostArchives = isRecordStringString(gitHostArchives) ?
|
|
69
|
+
removeDefaultItems(defaultGitHostArchives, gitHostArchives)
|
|
70
|
+
: undefined;
|
|
71
|
+
const cleanRegistries = isRecordStringString(registries) ?
|
|
72
|
+
removeDefaultItems(defaultRegistries, registries)
|
|
73
|
+
: undefined;
|
|
74
|
+
const cleanScopeRegistries = isRecordStringString(scopeRegistries) ?
|
|
75
|
+
removeDefaultItems(defaultScopeRegistries, scopeRegistries)
|
|
76
|
+
: undefined;
|
|
77
|
+
const hasItems = (clean) => clean && Object.keys(clean).length;
|
|
78
|
+
return {
|
|
79
|
+
options: {
|
|
80
|
+
...(hasItems(cleanScopeRegistries) ?
|
|
81
|
+
{ 'scope-registries': cleanScopeRegistries }
|
|
82
|
+
: undefined),
|
|
83
|
+
...(registry !== undefined && registry !== defaultRegistry ?
|
|
84
|
+
{ registry }
|
|
85
|
+
: undefined),
|
|
86
|
+
...(hasItems(registries) ?
|
|
87
|
+
{ registries: cleanRegistries }
|
|
88
|
+
: undefined),
|
|
89
|
+
...(hasItems(cleanGitHosts) ?
|
|
90
|
+
{ 'git-hosts': cleanGitHosts }
|
|
91
|
+
: undefined),
|
|
92
|
+
...(hasItems(cleanGitHostArchives) ?
|
|
93
|
+
{ 'git-host-archives': cleanGitHostArchives }
|
|
94
|
+
: undefined),
|
|
95
|
+
},
|
|
96
|
+
nodes: formatNodes(graph.nodes.values(), saveManifests, registry),
|
|
97
|
+
edges: formatEdges(graph.edges),
|
|
98
|
+
};
|
|
99
|
+
};
|
|
100
|
+
// renders each node / edge as a single line entry
|
|
101
|
+
const extraFormat = (jsonString) => {
|
|
102
|
+
const str = `${jsonString}\n`;
|
|
103
|
+
const [init, ...parts] = str.split(' "nodes": {');
|
|
104
|
+
const res = [init];
|
|
105
|
+
for (const part of parts) {
|
|
106
|
+
res.push(part.replaceAll('\n ', '').replaceAll('\n ]', ']'));
|
|
107
|
+
}
|
|
108
|
+
return res.join(' "nodes": {');
|
|
109
|
+
};
|
|
110
|
+
export const saveData = (data, fileName, saveManifests = false) => {
|
|
111
|
+
const json = JSON.stringify(data, null, 2);
|
|
112
|
+
const content = saveManifests ? json : extraFormat(json);
|
|
113
|
+
writeFileSync(fileName, content);
|
|
114
|
+
};
|
|
115
|
+
export const save = (options) => {
|
|
116
|
+
const { graph } = options;
|
|
117
|
+
const data = lockfileData({ ...options, saveManifests: false });
|
|
118
|
+
const fileName = resolve(graph.projectRoot, 'vlt-lock.json');
|
|
119
|
+
return saveData(data, fileName, false);
|
|
120
|
+
};
|
|
121
|
+
export const saveHidden = (options) => {
|
|
122
|
+
const { graph } = options;
|
|
123
|
+
const data = lockfileData({ ...options, saveManifests: true });
|
|
124
|
+
const fileName = resolve(graph.projectRoot, 'node_modules/.vlt-lock.json');
|
|
125
|
+
mkdirSync(dirname(fileName), { recursive: true });
|
|
126
|
+
return saveData(data, fileName, true);
|
|
127
|
+
};
|
|
128
|
+
//# sourceMappingURL=save.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"save.js","sourceRoot":"","sources":["../../../src/lockfile/save.ts"],"names":[],"mappings":"AACA,OAAO,EACL,eAAe,EACf,iBAAiB,EACjB,eAAe,EACf,sBAAsB,EACtB,sBAAsB,GAEvB,MAAM,cAAc,CAAA;AACrB,OAAO,EAAE,SAAS,EAAE,aAAa,EAAE,MAAM,SAAS,CAAA;AAClD,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AAI5C,OAAO,EACL,kBAAkB,GAMnB,MAAM,YAAY,CAAA;AAanB,MAAM,WAAW,GAAG,CAClB,KAAqB,EACrB,aAAuB,EACvB,QAAiB,EACjB,EAAE;IACF,gEAAgE;IAChE,mEAAmE;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AAE,aAAa,EAAE,IAAI,EAAE,CAAC,CAAA;IAC9D,MAAM,QAAQ,GAAG,OAAO,CACtB,KAAK,CAAC,WAAW,EACjB,6BAA6B,CAC9B,CAAA;IACD,SAAS,CAAC,OAAO,CAAC,QAAQ,CAAC,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAA;IACjD,OAAO,QAAQ,CAAC,IAAI,EAAE,QAAQ,EAAE,IAAI,CAAC,CAAA;AACvC,CAAC,CAAA","sourcesContent":["import { DepID } from '@vltpkg/dep-id'\nimport {\n defaultRegistry,\n defaultRegistries,\n defaultGitHosts,\n defaultGitHostArchives,\n defaultScopeRegistries,\n SpecOptions,\n} from '@vltpkg/spec'\nimport { mkdirSync, writeFileSync } from 'node:fs'\nimport { dirname, resolve } from 'node:path'\nimport { type Edge } from '../edge.js'\nimport { type Graph } from '../graph.js'\nimport { type Node } from '../node.js'\nimport {\n getFlagNumFromNode,\n LockfileData,\n LockfileEdgeKey,\n LockfileEdges,\n LockfileEdgeValue,\n LockfileNode,\n} from './types.js'\n\nexport type SaveOptions = SpecOptions & {\n /**\n * The graph to be stored in the lockfile.\n */\n graph: Graph\n /**\n * Should it save manifest data in the lockfile?\n */\n saveManifests?: boolean\n}\n\nconst formatNodes = (\n nodes: Iterable<Node>,\n saveManifests?: boolean,\n registry?: string,\n) => {\n // we do not store importers in the lockfile, though we do store\n // their edges. when we load, we always read workspaces/main fresh.\n const arr: Node[] = [...nodes].filter(node => !node.importer)\n // nodes are sorted in order to have a deterministic result\n const orderedNodes: Node[] = arr.sort((a, b) =>\n a.id.localeCompare(b.id, 'en'),\n )\n\n const res: Record<DepID, LockfileNode> = {}\n for (const node of orderedNodes) {\n const customRegistry =\n node.resolved && registry && !node.resolved.startsWith(registry)\n const resolved = customRegistry ? node.resolved : undefined\n // if it's in a location other than the default, stash that\n const location =\n (\n node.id.startsWith('file') ||\n node.location.endsWith(\n '/node_modules/.vlt/' +\n node.id +\n '/node_modules/' +\n node.name,\n )\n ) ?\n undefined\n : node.location\n\n const flags = getFlagNumFromNode(node)\n const lockfileNode: LockfileNode = [flags, node.name]\n\n if (node.integrity) {\n lockfileNode[2] = node.integrity\n }\n\n if (resolved) {\n lockfileNode[3] = resolved\n }\n\n if (location) {\n lockfileNode[4] = location\n }\n\n if (saveManifests) {\n lockfileNode[5] = node.manifest\n }\n\n res[node.id] = lockfileNode\n }\n return res\n}\n\nconst formatEdges = (edges: Set<Edge>): LockfileEdges =>\n Object.fromEntries(\n [...edges]\n .sort(\n (a, b) =>\n /* c8 ignore start - nondeterminstic and annoying to test */\n // sort importers to the top, then alphabetically by\n // id, type, target\n Number(b.from.importer) - Number(a.from.importer) ||\n a.from.id.localeCompare(b.from.id, 'en') ||\n a.type.localeCompare(b.type, 'en') ||\n (a.to?.id ?? '').localeCompare(b.to?.id ?? ''),\n /* c8 ignore stop */\n )\n .map((edge): [LockfileEdgeKey, LockfileEdgeValue] => [\n `${edge.from.id} ${edge.spec.name}`,\n `${edge.type} ${edge.spec.bareSpec || '*'} ${edge.to?.id ?? 'MISSING'}`,\n ]),\n )\n\nconst isRecordStringString = (\n registries: unknown,\n): registries is Record<string, string> =>\n !(!registries || typeof registries === 'string')\n\nconst removeDefaultItems = (\n defaultItems: Record<string, string>,\n items: Record<string, string>,\n) => {\n const res: Record<string, string> = {}\n for (const [key, value] of Object.entries(items)) {\n if (!defaultItems[key] || defaultItems[key] !== value) {\n res[key] = value\n }\n }\n return res\n}\n\nexport const lockfileData = ({\n graph,\n 'git-hosts': gitHosts,\n 'git-host-archives': gitHostArchives,\n registry,\n registries,\n saveManifests,\n 'scope-registries': scopeRegistries,\n}: SaveOptions): LockfileData => {\n const cleanGitHosts =\n isRecordStringString(gitHosts) ?\n removeDefaultItems(defaultGitHosts, gitHosts)\n : undefined\n const cleanGitHostArchives =\n isRecordStringString(gitHostArchives) ?\n removeDefaultItems(defaultGitHostArchives, gitHostArchives)\n : undefined\n const cleanRegistries =\n isRecordStringString(registries) ?\n removeDefaultItems(defaultRegistries, registries)\n : undefined\n const cleanScopeRegistries =\n isRecordStringString(scopeRegistries) ?\n removeDefaultItems(defaultScopeRegistries, scopeRegistries)\n : undefined\n const hasItems = (clean: Record<string, string> | undefined) =>\n clean && Object.keys(clean).length\n return {\n options: {\n ...(hasItems(cleanScopeRegistries) ?\n { 'scope-registries': cleanScopeRegistries }\n : undefined),\n ...(registry !== undefined && registry !== defaultRegistry ?\n { registry }\n : undefined),\n ...(hasItems(registries) ?\n { registries: cleanRegistries }\n : undefined),\n ...(hasItems(cleanGitHosts) ?\n { 'git-hosts': cleanGitHosts }\n : undefined),\n ...(hasItems(cleanGitHostArchives) ?\n { 'git-host-archives': cleanGitHostArchives }\n : undefined),\n },\n nodes: formatNodes(graph.nodes.values(), saveManifests, registry),\n edges: formatEdges(graph.edges),\n }\n}\n\n// renders each node / edge as a single line entry\nconst extraFormat = (jsonString: string) => {\n const str = `${jsonString}\\n`\n const [init, ...parts] = str.split(' \"nodes\": {')\n const res = [init]\n for (const part of parts) {\n res.push(\n part.replaceAll('\\n ', '').replaceAll('\\n ]', ']'),\n )\n }\n return res.join(' \"nodes\": {')\n}\n\nexport const saveData = (\n data: LockfileData,\n fileName: string,\n saveManifests = false,\n) => {\n const json = JSON.stringify(data, null, 2)\n const content = saveManifests ? json : extraFormat(json)\n writeFileSync(fileName, content)\n}\n\nexport const save = (options: SaveOptions) => {\n const { graph } = options\n const data = lockfileData({ ...options, saveManifests: false })\n const fileName = resolve(graph.projectRoot, 'vlt-lock.json')\n return saveData(data, fileName, false)\n}\n\nexport const saveHidden = (options: SaveOptions) => {\n const { graph } = options\n const data = lockfileData({ ...options, saveManifests: true })\n const fileName = resolve(\n graph.projectRoot,\n 'node_modules/.vlt-lock.json',\n )\n mkdirSync(dirname(fileName), { recursive: true })\n return saveData(data, fileName, true)\n}\n"]}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import type { DepID } from '@vltpkg/dep-id';
|
|
2
|
+
import type { Spec, SpecOptions } from '@vltpkg/spec';
|
|
3
|
+
import type { Integrity, Manifest } from '@vltpkg/types';
|
|
4
|
+
import type { DependencyTypeShort } from '../dependencies.js';
|
|
5
|
+
/**
|
|
6
|
+
* This is the main type definition for the contents of the
|
|
7
|
+
* `vlt-lock.json` file.
|
|
8
|
+
*
|
|
9
|
+
* The nodes and edges information from the lockfile are used to reconstruct
|
|
10
|
+
* a {@link Graph} representing a previous install.
|
|
11
|
+
*/
|
|
12
|
+
export type LockfileData = {
|
|
13
|
+
options: SpecOptions;
|
|
14
|
+
nodes: Record<DepID, LockfileNode>;
|
|
15
|
+
edges: LockfileEdges;
|
|
16
|
+
};
|
|
17
|
+
export declare const getFlagNumFromNode: (node: {
|
|
18
|
+
optional?: boolean;
|
|
19
|
+
dev?: boolean;
|
|
20
|
+
}) => 0 | 1 | 2 | 3;
|
|
21
|
+
export declare const getBooleanFlagsFromNum: (flags: LockfileNodeFlags) => {
|
|
22
|
+
dev: boolean;
|
|
23
|
+
optional: boolean;
|
|
24
|
+
};
|
|
25
|
+
export declare const LockfileNodeFlagNone = 0;
|
|
26
|
+
export declare const LockfileNodeFlagOptional = 1;
|
|
27
|
+
export declare const LockfileNodeFlagDev = 2;
|
|
28
|
+
export declare const LockfileNodeFlagDevOptional = 3;
|
|
29
|
+
/**
|
|
30
|
+
* Bit flags indicating whether a node is optional and/or dev.
|
|
31
|
+
*/
|
|
32
|
+
export type LockfileNodeFlags = 0 | 1 | 2 | 3;
|
|
33
|
+
/**
|
|
34
|
+
* Lockfile representation of a node from the install graph.
|
|
35
|
+
*/
|
|
36
|
+
export type LockfileNode = [
|
|
37
|
+
flags: LockfileNodeFlags,
|
|
38
|
+
name?: string | null,
|
|
39
|
+
integrity?: Integrity | null,
|
|
40
|
+
resolved?: string | null,
|
|
41
|
+
location?: string | null,
|
|
42
|
+
manifest?: Manifest | null
|
|
43
|
+
];
|
|
44
|
+
/**
|
|
45
|
+
* Lockfile edges are stored as a record object where the key
|
|
46
|
+
* is `${from.id} ${spec.name}` and the value is
|
|
47
|
+
* `${type} ${spec.bareSpec} ${to.id | 'MISSING'}`
|
|
48
|
+
*
|
|
49
|
+
* Storing them in a record like this means that we are guaranteed to
|
|
50
|
+
* never end up with duplicates, and a standard `JSON.stringify()`
|
|
51
|
+
* will nicely print them out one line per edge.
|
|
52
|
+
*/
|
|
53
|
+
export type LockfileEdges = {
|
|
54
|
+
[key: LockfileEdgeKey]: LockfileEdgeValue;
|
|
55
|
+
};
|
|
56
|
+
/** `${from} ${dep name}` */
|
|
57
|
+
export type LockfileEdgeKey = `${DepID} ${string}`;
|
|
58
|
+
/** `${type} ${spec} ${to}` */
|
|
59
|
+
export type LockfileEdgeValue = `${DependencyTypeShort} ${Spec['bareSpec']} ${DepID | 'MISSING'}`;
|
|
60
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/lockfile/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAA;AAC3C,OAAO,KAAK,EAAE,IAAI,EAAE,WAAW,EAAE,MAAM,cAAc,CAAA;AACrD,OAAO,KAAK,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAA;AACxD,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAA;AAE7D;;;;;;GAMG;AACH,MAAM,MAAM,YAAY,GAAG;IACzB,OAAO,EAAE,WAAW,CAAA;IACpB,KAAK,EAAE,MAAM,CAAC,KAAK,EAAE,YAAY,CAAC,CAAA;IAClC,KAAK,EAAE,aAAa,CAAA;CACrB,CAAA;AAED,eAAO,MAAM,kBAAkB,SAAU;IACvC,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB,GAAG,CAAC,EAAE,OAAO,CAAA;CACd,kBAIuB,CAAA;AAExB,eAAO,MAAM,sBAAsB,UAAW,iBAAiB;;;CAG7D,CAAA;AAEF,eAAO,MAAM,oBAAoB,IAAI,CAAA;AACrC,eAAO,MAAM,wBAAwB,IAAI,CAAA;AACzC,eAAO,MAAM,mBAAmB,IAAI,CAAA;AACpC,eAAO,MAAM,2BAA2B,IAAI,CAAA;AAE5C;;GAEG;AACH,MAAM,MAAM,iBAAiB,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,CAAA;AAE7C;;GAEG;AACH,MAAM,MAAM,YAAY,GAAG;IACzB,KAAK,EAAE,iBAAiB;IACxB,IAAI,CAAC,EAAE,MAAM,GAAG,IAAI;IACpB,SAAS,CAAC,EAAE,SAAS,GAAG,IAAI;IAC5B,QAAQ,CAAC,EAAE,MAAM,GAAG,IAAI;IACxB,QAAQ,CAAC,EAAE,MAAM,GAAG,IAAI;IACxB,QAAQ,CAAC,EAAE,QAAQ,GAAG,IAAI;CAC3B,CAAA;AAED;;;;;;;;GAQG;AACH,MAAM,MAAM,aAAa,GAAG;IAC1B,CAAC,GAAG,EAAE,eAAe,GAAG,iBAAiB,CAAA;CAC1C,CAAA;AAED,4BAA4B;AAC5B,MAAM,MAAM,eAAe,GAAG,GAAG,KAAK,IAAI,MAAM,EAAE,CAAA;AAElD,8BAA8B;AAC9B,MAAM,MAAM,iBAAiB,GAC3B,GAAG,mBAAmB,IAAI,IAAI,CAAC,UAAU,CAAC,IAAI,KAAK,GAAG,SAAS,EAAE,CAAA"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export const getFlagNumFromNode = (node) => node.optional && node.dev ? LockfileNodeFlagDevOptional
|
|
2
|
+
: node.optional ? LockfileNodeFlagOptional
|
|
3
|
+
: node.dev ? LockfileNodeFlagDev
|
|
4
|
+
: LockfileNodeFlagNone;
|
|
5
|
+
export const getBooleanFlagsFromNum = (flags) => ({
|
|
6
|
+
dev: !!(flags & LockfileNodeFlagDev),
|
|
7
|
+
optional: !!(flags & LockfileNodeFlagOptional),
|
|
8
|
+
});
|
|
9
|
+
export const LockfileNodeFlagNone = 0;
|
|
10
|
+
export const LockfileNodeFlagOptional = 1;
|
|
11
|
+
export const LockfileNodeFlagDev = 2;
|
|
12
|
+
export const LockfileNodeFlagDevOptional = 3;
|
|
13
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/lockfile/types.ts"],"names":[],"mappings":"AAkBA,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAAC,IAGlC,EAAE,EAAE,CACH,IAAI,CAAC,QAAQ,IAAI,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,2BAA2B;IACvD,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC,wBAAwB;QAC1C,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,mBAAmB;YAChC,CAAC,CAAC,oBAAoB,CAAA;AAExB,MAAM,CAAC,MAAM,sBAAsB,GAAG,CAAC,KAAwB,EAAE,EAAE,CAAC,CAAC;IACnE,GAAG,EAAE,CAAC,CAAC,CAAC,KAAK,GAAG,mBAAmB,CAAC;IACpC,QAAQ,EAAE,CAAC,CAAC,CAAC,KAAK,GAAG,wBAAwB,CAAC;CAC/C,CAAC,CAAA;AAEF,MAAM,CAAC,MAAM,oBAAoB,GAAG,CAAC,CAAA;AACrC,MAAM,CAAC,MAAM,wBAAwB,GAAG,CAAC,CAAA;AACzC,MAAM,CAAC,MAAM,mBAAmB,GAAG,CAAC,CAAA;AACpC,MAAM,CAAC,MAAM,2BAA2B,GAAG,CAAC,CAAA","sourcesContent":["import type { DepID } from '@vltpkg/dep-id'\nimport type { Spec, SpecOptions } from '@vltpkg/spec'\nimport type { Integrity, Manifest } from '@vltpkg/types'\nimport type { DependencyTypeShort } from '../dependencies.js'\n\n/**\n * This is the main type definition for the contents of the\n * `vlt-lock.json` file.\n *\n * The nodes and edges information from the lockfile are used to reconstruct\n * a {@link Graph} representing a previous install.\n */\nexport type LockfileData = {\n options: SpecOptions\n nodes: Record<DepID, LockfileNode>\n edges: LockfileEdges\n}\n\nexport const getFlagNumFromNode = (node: {\n optional?: boolean\n dev?: boolean\n}) =>\n node.optional && node.dev ? LockfileNodeFlagDevOptional\n : node.optional ? LockfileNodeFlagOptional\n : node.dev ? LockfileNodeFlagDev\n : LockfileNodeFlagNone\n\nexport const getBooleanFlagsFromNum = (flags: LockfileNodeFlags) => ({\n dev: !!(flags & LockfileNodeFlagDev),\n optional: !!(flags & LockfileNodeFlagOptional),\n})\n\nexport const LockfileNodeFlagNone = 0\nexport const LockfileNodeFlagOptional = 1\nexport const LockfileNodeFlagDev = 2\nexport const LockfileNodeFlagDevOptional = 3\n\n/**\n * Bit flags indicating whether a node is optional and/or dev.\n */\nexport type LockfileNodeFlags = 0 | 1 | 2 | 3\n\n/**\n * Lockfile representation of a node from the install graph.\n */\nexport type LockfileNode = [\n flags: LockfileNodeFlags,\n name?: string | null,\n integrity?: Integrity | null,\n resolved?: string | null,\n location?: string | null,\n manifest?: Manifest | null,\n]\n\n/**\n * Lockfile edges are stored as a record object where the key\n * is `${from.id} ${spec.name}` and the value is\n * `${type} ${spec.bareSpec} ${to.id | 'MISSING'}`\n *\n * Storing them in a record like this means that we are guaranteed to\n * never end up with duplicates, and a standard `JSON.stringify()`\n * will nicely print them out one line per edge.\n */\nexport type LockfileEdges = {\n [key: LockfileEdgeKey]: LockfileEdgeValue\n}\n\n/** `${from} ${dep name}` */\nexport type LockfileEdgeKey = `${DepID} ${string}`\n\n/** `${type} ${spec} ${to}` */\nexport type LockfileEdgeValue =\n `${DependencyTypeShort} ${Spec['bareSpec']} ${DepID | 'MISSING'}`\n"]}
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
import { DepID } from '@vltpkg/dep-id';
|
|
2
|
+
import { Spec, SpecOptions } from '@vltpkg/spec';
|
|
3
|
+
import { Integrity, Manifest } from '@vltpkg/types';
|
|
4
|
+
import { DependencyTypeShort } from './dependencies.js';
|
|
5
|
+
import { Edge } from './edge.js';
|
|
6
|
+
import { GraphLike, NodeLike } from './types.js';
|
|
7
|
+
export type NodeOptions = SpecOptions & {
|
|
8
|
+
projectRoot: string;
|
|
9
|
+
graph: GraphLike;
|
|
10
|
+
};
|
|
11
|
+
export declare class Node implements NodeLike {
|
|
12
|
+
#private;
|
|
13
|
+
get [Symbol.toStringTag](): string;
|
|
14
|
+
/**
|
|
15
|
+
* True if a node is only reachable via optional or peerOptional edges from
|
|
16
|
+
* any importer.
|
|
17
|
+
*
|
|
18
|
+
* Setting this to false, if previously set to true, will also unset
|
|
19
|
+
* the flag on any optional-flagged non-optional dependencies.
|
|
20
|
+
*/
|
|
21
|
+
get optional(): boolean;
|
|
22
|
+
set optional(optional: boolean);
|
|
23
|
+
isOptional(): this is Node & {
|
|
24
|
+
optional: true;
|
|
25
|
+
};
|
|
26
|
+
/**
|
|
27
|
+
* True if a node is only reachable via dev edges from any importer.
|
|
28
|
+
*
|
|
29
|
+
* Setting this to false, if previously set to true, will also unset
|
|
30
|
+
* the flag on any dev-flagged non-dev dependencies.
|
|
31
|
+
*/
|
|
32
|
+
get dev(): boolean;
|
|
33
|
+
set dev(dev: boolean);
|
|
34
|
+
isDev(): this is Node & {
|
|
35
|
+
dev: true;
|
|
36
|
+
};
|
|
37
|
+
/**
|
|
38
|
+
* List of edges coming into this node.
|
|
39
|
+
*/
|
|
40
|
+
edgesIn: Set<Edge>;
|
|
41
|
+
/**
|
|
42
|
+
* List of edges from this node into other nodes. This usually represents
|
|
43
|
+
* that the connected node is a direct dependency of this node.
|
|
44
|
+
*/
|
|
45
|
+
edgesOut: Map<string, Edge>;
|
|
46
|
+
/**
|
|
47
|
+
* A reference to the {@link DepID} this node represents in the graph.
|
|
48
|
+
*/
|
|
49
|
+
id: DepID;
|
|
50
|
+
/**
|
|
51
|
+
* True if this node is an importer node.
|
|
52
|
+
*/
|
|
53
|
+
importer: boolean;
|
|
54
|
+
/**
|
|
55
|
+
* True if this node is the project root node.
|
|
56
|
+
*/
|
|
57
|
+
mainImporter: boolean;
|
|
58
|
+
/**
|
|
59
|
+
* A reference to the graph this node is a part of.
|
|
60
|
+
*/
|
|
61
|
+
graph: GraphLike;
|
|
62
|
+
/**
|
|
63
|
+
* The manifest integrity value.
|
|
64
|
+
*/
|
|
65
|
+
integrity?: Integrity;
|
|
66
|
+
/**
|
|
67
|
+
* The manifest this node represents in the graph.
|
|
68
|
+
*/
|
|
69
|
+
manifest?: Manifest;
|
|
70
|
+
/**
|
|
71
|
+
* Project where this node resides
|
|
72
|
+
*/
|
|
73
|
+
projectRoot: string;
|
|
74
|
+
/**
|
|
75
|
+
* For registry nodes, this is the registry we fetched them from.
|
|
76
|
+
* Needed because their un-prefixed dependencies need to come from
|
|
77
|
+
* the same registry, if it's not the default.
|
|
78
|
+
*/
|
|
79
|
+
registry?: string;
|
|
80
|
+
get name(): string;
|
|
81
|
+
/**
|
|
82
|
+
* The location of the node_modules folder where this node's edgesOut
|
|
83
|
+
* should be linked into. For nodes in the store, this is the parent
|
|
84
|
+
* directory, since they're extracted into a node_modules folder
|
|
85
|
+
* side by side with links to their deps. For nodes outside of the store
|
|
86
|
+
* (ie, importers and arbitrary link deps) this is the node_modules folder
|
|
87
|
+
* directly inside the node's directory.
|
|
88
|
+
*/
|
|
89
|
+
get nodeModules(): string;
|
|
90
|
+
/**
|
|
91
|
+
* The version of the package represented by this node, this is usually
|
|
92
|
+
* equivalent to `manifest.version` but in a few ways it may differ such as
|
|
93
|
+
* nodes loaded from a lockfile that lacks a loaded manifest.
|
|
94
|
+
* This field should be used to retrieve package versions instead.
|
|
95
|
+
*/
|
|
96
|
+
version?: string;
|
|
97
|
+
/**
|
|
98
|
+
* An address {@link PackageInfoClient} may use to extract this package.
|
|
99
|
+
*/
|
|
100
|
+
resolved?: string;
|
|
101
|
+
/**
|
|
102
|
+
* The file system location for this node.
|
|
103
|
+
*/
|
|
104
|
+
get location(): string;
|
|
105
|
+
set location(location: string);
|
|
106
|
+
constructor(options: NodeOptions, id?: DepID, manifest?: Manifest, spec?: Spec, name?: string, version?: string);
|
|
107
|
+
/**
|
|
108
|
+
* return true if this node is located in the vlt store
|
|
109
|
+
* memoized the first time it's called, since the store location
|
|
110
|
+
* doesn't change within the context of a single operation.
|
|
111
|
+
*/
|
|
112
|
+
inVltStore(): boolean;
|
|
113
|
+
equals(other: Node): boolean;
|
|
114
|
+
/**
|
|
115
|
+
* Sets the node as an importer along with its location.
|
|
116
|
+
*/
|
|
117
|
+
setImporterLocation(location: string): void;
|
|
118
|
+
/**
|
|
119
|
+
* Sets the appropriate resolve / integrity value for this node.
|
|
120
|
+
* Note that other places might also set these values, like for
|
|
121
|
+
* example the lockfile that might have already have this info.
|
|
122
|
+
*/
|
|
123
|
+
setResolved(): void;
|
|
124
|
+
setDefaultLocation(): void;
|
|
125
|
+
/**
|
|
126
|
+
* Add an edge from this node connecting it to a direct dependency.
|
|
127
|
+
*/
|
|
128
|
+
addEdgesTo(type: DependencyTypeShort, spec: Spec, node?: Node): Edge;
|
|
129
|
+
toJSON(): {
|
|
130
|
+
id: DepID;
|
|
131
|
+
name: string;
|
|
132
|
+
version: string | undefined;
|
|
133
|
+
location: string;
|
|
134
|
+
importer: boolean;
|
|
135
|
+
manifest: Manifest | undefined;
|
|
136
|
+
projectRoot: string;
|
|
137
|
+
integrity: `sha512-${string}` | undefined;
|
|
138
|
+
resolved: string | undefined;
|
|
139
|
+
dev: boolean;
|
|
140
|
+
optional: boolean;
|
|
141
|
+
};
|
|
142
|
+
toString(): string;
|
|
143
|
+
}
|
|
144
|
+
//# sourceMappingURL=node.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"node.d.ts","sourceRoot":"","sources":["../../src/node.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,EAKN,MAAM,gBAAgB,CAAA;AAEvB,OAAO,EAAE,IAAI,EAAE,WAAW,EAAE,MAAM,cAAc,CAAA;AAChD,OAAO,EAAE,SAAS,EAAE,QAAQ,E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