@vltpkg/graph 0.0.0-3 → 0.0.0-30
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/README.md +148 -12
- package/dist/esm/actual/load.d.ts +44 -3
- package/dist/esm/actual/load.d.ts.map +1 -1
- package/dist/esm/actual/load.js +123 -73
- package/dist/esm/actual/load.js.map +1 -1
- package/dist/esm/browser.d.ts +8 -4
- package/dist/esm/browser.d.ts.map +1 -1
- package/dist/esm/browser.js +6 -2
- package/dist/esm/browser.js.map +1 -1
- package/dist/esm/dependencies.d.ts +14 -5
- package/dist/esm/dependencies.d.ts.map +1 -1
- package/dist/esm/dependencies.js +67 -2
- package/dist/esm/dependencies.js.map +1 -1
- package/dist/esm/diff.d.ts +5 -0
- package/dist/esm/diff.d.ts.map +1 -1
- package/dist/esm/diff.js +13 -0
- package/dist/esm/diff.js.map +1 -1
- package/dist/esm/edge.d.ts +2 -3
- package/dist/esm/edge.d.ts.map +1 -1
- package/dist/esm/edge.js +1 -1
- package/dist/esm/edge.js.map +1 -1
- package/dist/esm/graph.d.ts +22 -12
- package/dist/esm/graph.d.ts.map +1 -1
- package/dist/esm/graph.js +122 -23
- package/dist/esm/graph.js.map +1 -1
- package/dist/esm/ideal/add-nodes.d.ts +6 -1
- package/dist/esm/ideal/add-nodes.d.ts.map +1 -1
- package/dist/esm/ideal/add-nodes.js +9 -4
- package/dist/esm/ideal/add-nodes.js.map +1 -1
- package/dist/esm/ideal/append-nodes.d.ts +9 -1
- package/dist/esm/ideal/append-nodes.d.ts.map +1 -1
- package/dist/esm/ideal/append-nodes.js +155 -31
- package/dist/esm/ideal/append-nodes.js.map +1 -1
- package/dist/esm/ideal/build-ideal-from-starting-graph.d.ts.map +1 -1
- package/dist/esm/ideal/build-ideal-from-starting-graph.js +9 -5
- package/dist/esm/ideal/build-ideal-from-starting-graph.js.map +1 -1
- package/dist/esm/ideal/build.d.ts +4 -0
- package/dist/esm/ideal/build.d.ts.map +1 -1
- package/dist/esm/ideal/build.js +2 -0
- package/dist/esm/ideal/build.js.map +1 -1
- package/dist/esm/ideal/get-importer-specs.d.ts +3 -2
- package/dist/esm/ideal/get-importer-specs.d.ts.map +1 -1
- package/dist/esm/ideal/get-importer-specs.js +7 -5
- package/dist/esm/ideal/get-importer-specs.js.map +1 -1
- package/dist/esm/index.d.ts +6 -4
- package/dist/esm/index.d.ts.map +1 -1
- package/dist/esm/index.js +3 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/install.d.ts +4 -5
- package/dist/esm/install.d.ts.map +1 -1
- package/dist/esm/install.js +143 -23
- package/dist/esm/install.js.map +1 -1
- package/dist/esm/lockfile/load-edges.d.ts +8 -1
- package/dist/esm/lockfile/load-edges.d.ts.map +1 -1
- package/dist/esm/lockfile/load-edges.js +79 -15
- package/dist/esm/lockfile/load-edges.js.map +1 -1
- package/dist/esm/lockfile/load-nodes.d.ts +3 -2
- package/dist/esm/lockfile/load-nodes.d.ts.map +1 -1
- package/dist/esm/lockfile/load-nodes.js +64 -11
- package/dist/esm/lockfile/load-nodes.js.map +1 -1
- package/dist/esm/lockfile/load.d.ts +18 -5
- package/dist/esm/lockfile/load.d.ts.map +1 -1
- package/dist/esm/lockfile/load.js +51 -22
- package/dist/esm/lockfile/load.js.map +1 -1
- package/dist/esm/lockfile/save.d.ts +8 -3
- package/dist/esm/lockfile/save.d.ts.map +1 -1
- package/dist/esm/lockfile/save.js +30 -12
- package/dist/esm/lockfile/save.js.map +1 -1
- package/dist/esm/lockfile/types.d.ts +17 -4
- package/dist/esm/lockfile/types.d.ts.map +1 -1
- package/dist/esm/lockfile/types.js.map +1 -1
- package/dist/esm/modifiers.d.ts +189 -0
- package/dist/esm/modifiers.d.ts.map +1 -0
- package/dist/esm/modifiers.js +330 -0
- package/dist/esm/modifiers.js.map +1 -0
- package/dist/esm/node.d.ts +54 -5
- package/dist/esm/node.d.ts.map +1 -1
- package/dist/esm/node.js +77 -2
- package/dist/esm/node.js.map +1 -1
- package/dist/esm/reify/add-edge.d.ts +1 -1
- package/dist/esm/reify/add-edge.d.ts.map +1 -1
- package/dist/esm/reify/add-edge.js +36 -14
- package/dist/esm/reify/add-edge.js.map +1 -1
- package/dist/esm/reify/add-nodes.d.ts.map +1 -1
- package/dist/esm/reify/add-nodes.js +4 -2
- package/dist/esm/reify/add-nodes.js.map +1 -1
- package/dist/esm/reify/bin-paths.d.ts +1 -1
- package/dist/esm/reify/bin-paths.d.ts.map +1 -1
- package/dist/esm/reify/bin-paths.js.map +1 -1
- package/dist/esm/reify/build.js +6 -3
- package/dist/esm/reify/build.js.map +1 -1
- package/dist/esm/reify/calculate-save-value.d.ts +3 -0
- package/dist/esm/reify/calculate-save-value.d.ts.map +1 -0
- package/dist/esm/reify/calculate-save-value.js +45 -0
- package/dist/esm/reify/calculate-save-value.js.map +1 -0
- package/dist/esm/reify/delete-edge.js +1 -1
- package/dist/esm/reify/delete-edge.js.map +1 -1
- package/dist/esm/reify/delete-nodes.d.ts.map +1 -1
- package/dist/esm/reify/delete-nodes.js +4 -0
- package/dist/esm/reify/delete-nodes.js.map +1 -1
- package/dist/esm/reify/index.d.ts +2 -0
- package/dist/esm/reify/index.d.ts.map +1 -1
- package/dist/esm/reify/index.js +20 -2
- package/dist/esm/reify/index.js.map +1 -1
- package/dist/esm/reify/internal-hoist.d.ts +9 -0
- package/dist/esm/reify/internal-hoist.d.ts.map +1 -0
- package/dist/esm/reify/internal-hoist.js +121 -0
- package/dist/esm/reify/internal-hoist.js.map +1 -0
- package/dist/esm/reify/update-importers-package-json.d.ts +1 -1
- package/dist/esm/reify/update-importers-package-json.d.ts.map +1 -1
- package/dist/esm/reify/update-importers-package-json.js +35 -12
- package/dist/esm/reify/update-importers-package-json.js.map +1 -1
- package/dist/esm/remove-optional-subgraph.js +1 -1
- package/dist/esm/remove-optional-subgraph.js.map +1 -1
- package/dist/esm/resolve-save-type.d.ts +6 -0
- package/dist/esm/resolve-save-type.d.ts.map +1 -0
- package/dist/esm/resolve-save-type.js +5 -0
- package/dist/esm/resolve-save-type.js.map +1 -0
- package/dist/esm/stringify-node.d.ts +1 -1
- package/dist/esm/stringify-node.d.ts.map +1 -1
- package/dist/esm/stringify-node.js.map +1 -1
- package/dist/esm/transfer-data/load.d.ts +44 -0
- package/dist/esm/transfer-data/load.d.ts.map +1 -0
- package/dist/esm/transfer-data/load.js +176 -0
- package/dist/esm/transfer-data/load.js.map +1 -0
- package/dist/esm/uninstall.d.ts +3 -5
- package/dist/esm/uninstall.d.ts.map +1 -1
- package/dist/esm/uninstall.js +0 -3
- package/dist/esm/uninstall.js.map +1 -1
- package/dist/esm/update.d.ts +11 -0
- package/dist/esm/update.d.ts.map +1 -0
- package/dist/esm/update.js +49 -0
- package/dist/esm/update.js.map +1 -0
- package/dist/esm/virtual-root.d.ts +16 -0
- package/dist/esm/virtual-root.d.ts.map +1 -0
- package/dist/esm/virtual-root.js +78 -0
- package/dist/esm/virtual-root.js.map +1 -0
- package/dist/esm/visualization/human-readable-output.d.ts +4 -5
- package/dist/esm/visualization/human-readable-output.d.ts.map +1 -1
- package/dist/esm/visualization/human-readable-output.js +51 -24
- package/dist/esm/visualization/human-readable-output.js.map +1 -1
- package/dist/esm/visualization/json-output.d.ts +7 -3
- package/dist/esm/visualization/json-output.d.ts.map +1 -1
- package/dist/esm/visualization/json-output.js +35 -12
- package/dist/esm/visualization/json-output.js.map +1 -1
- package/dist/esm/visualization/mermaid-output.d.ts +7 -1
- package/dist/esm/visualization/mermaid-output.d.ts.map +1 -1
- package/dist/esm/visualization/mermaid-output.js +64 -9
- package/dist/esm/visualization/mermaid-output.js.map +1 -1
- package/dist/esm/visualization/object-like-output.d.ts +1 -1
- package/dist/esm/visualization/object-like-output.d.ts.map +1 -1
- package/dist/esm/visualization/object-like-output.js.map +1 -1
- package/package.json +29 -25
- package/dist/esm/types.d.ts +0 -39
- package/dist/esm/types.d.ts.map +0 -1
- package/dist/esm/types.js +0 -2
- package/dist/esm/types.js.map +0 -1
|
@@ -17,40 +17,69 @@ export const loadHidden = (options) => {
|
|
|
17
17
|
return loadObject(options, loadLockfile(projectRoot, 'node_modules/.vlt-lock.json'));
|
|
18
18
|
};
|
|
19
19
|
export const loadObject = (options, lockfileData) => {
|
|
20
|
-
const { mainManifest, scurry } = options;
|
|
20
|
+
const { mainManifest, modifiers, scurry, skipLoadingNodesOnModifiersChange, } = options;
|
|
21
21
|
const packageJson = options.packageJson ?? new PackageJson();
|
|
22
22
|
const monorepo = options.monorepo ??
|
|
23
23
|
Monorepo.maybeLoad(options.projectRoot, { packageJson, scurry });
|
|
24
|
-
const { 'scope-registries': scopeRegistries, registry, registries, 'git-hosts': gitHosts, 'git-host-archives': gitHostArchives,
|
|
25
|
-
//
|
|
26
|
-
} = lockfileData.options || {};
|
|
24
|
+
const { catalog = {}, catalogs = {}, modifiers: modifiersLockfileConfig, 'scope-registries': scopeRegistries, registry, registries, 'git-hosts': gitHosts, 'git-host-archives': gitHostArchives, } = lockfileData.options ?? {};
|
|
25
|
+
// Optimize options merging - only create new objects when needed
|
|
27
26
|
const mergedOptions = {
|
|
28
27
|
...options,
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
28
|
+
catalog,
|
|
29
|
+
catalogs,
|
|
30
|
+
'scope-registries': scopeRegistries ?
|
|
31
|
+
{ ...options['scope-registries'], ...scopeRegistries }
|
|
32
|
+
: options['scope-registries'],
|
|
33
33
|
registry: registry ?? options.registry,
|
|
34
|
-
registries:
|
|
35
|
-
...options.registries,
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
...options['git-host-archives'],
|
|
44
|
-
...gitHostArchives,
|
|
45
|
-
},
|
|
34
|
+
registries: registries ?
|
|
35
|
+
{ ...options.registries, ...registries }
|
|
36
|
+
: options.registries,
|
|
37
|
+
'git-hosts': gitHosts ?
|
|
38
|
+
{ ...options['git-hosts'], ...gitHosts }
|
|
39
|
+
: options['git-hosts'],
|
|
40
|
+
'git-host-archives': gitHostArchives ?
|
|
41
|
+
{ ...options['git-host-archives'], ...gitHostArchives }
|
|
42
|
+
: options['git-host-archives'],
|
|
46
43
|
};
|
|
47
44
|
const graph = new Graph({
|
|
48
45
|
...mergedOptions,
|
|
49
46
|
mainManifest,
|
|
50
47
|
monorepo,
|
|
51
48
|
});
|
|
52
|
-
|
|
53
|
-
|
|
49
|
+
// When using the skipLoadingNodesOnModifiersChange option, we should skip loading
|
|
50
|
+
// dependencies in case the modifiers have changed since we'll need to
|
|
51
|
+
// recalculate the graph - useful for refreshing an ideal graph when
|
|
52
|
+
// modifiers are swapped.
|
|
53
|
+
// Optimize modifier comparison - avoid JSON.stringify for simple cases
|
|
54
|
+
let modifiersChanged = false;
|
|
55
|
+
if (skipLoadingNodesOnModifiersChange) {
|
|
56
|
+
const lockfileConfig = modifiersLockfileConfig ?? {};
|
|
57
|
+
const optionsConfig = modifiers?.config ?? {};
|
|
58
|
+
// Quick check for obvious differences
|
|
59
|
+
const lockfileKeys = Object.keys(lockfileConfig);
|
|
60
|
+
const optionsKeys = Object.keys(optionsConfig);
|
|
61
|
+
if (lockfileKeys.length !== optionsKeys.length) {
|
|
62
|
+
modifiersChanged = true;
|
|
63
|
+
}
|
|
64
|
+
else {
|
|
65
|
+
// Only use JSON.stringify if we need deep comparison
|
|
66
|
+
const lockfileModifiers = JSON.stringify(lockfileConfig);
|
|
67
|
+
const optionsModifiers = JSON.stringify(optionsConfig);
|
|
68
|
+
modifiersChanged = lockfileModifiers !== optionsModifiers;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
const shouldLoadDependencies = !(skipLoadingNodesOnModifiersChange && modifiersChanged);
|
|
72
|
+
if (shouldLoadDependencies) {
|
|
73
|
+
loadNodes(graph, lockfileData.nodes, mergedOptions, options.actual);
|
|
74
|
+
loadEdges(graph, lockfileData.edges, mergedOptions);
|
|
75
|
+
}
|
|
76
|
+
// hydrate missing node-level registry data
|
|
77
|
+
for (const node of graph.nodes.values()) {
|
|
78
|
+
const [firstEdge] = node.edgesIn;
|
|
79
|
+
if (firstEdge?.spec.registry) {
|
|
80
|
+
node.registry = firstEdge.spec.registry;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
54
83
|
return graph;
|
|
55
84
|
};
|
|
56
85
|
//# sourceMappingURL=load.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"load.js","sourceRoot":"","sources":["../../../src/lockfile/load.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAA;
|
|
1
|
+
{"version":3,"file":"load.js","sourceRoot":"","sources":["../../../src/lockfile/load.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAA;AAClD,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAA;AAC7C,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAA;AACtC,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AACnC,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAA;AAC3C,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAA;AAC3C,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAA;AA0CnC,MAAM,YAAY,GAAG,CAAC,WAAmB,EAAE,YAAoB,EAAE,EAAE,CACjE,IAAI,CAAC,KAAK,CACR,YAAY,CAAC,OAAO,CAAC,WAAW,EAAE,YAAY,CAAC,EAAE;IAC/C,QAAQ,EAAE,MAAM;CACjB,CAAC,CACa,CAAA;AAEnB,MAAM,CAAC,MAAM,IAAI,GAAG,CAAC,OAAoB,EAAS,EAAE;IAClD,MAAM,EAAE,WAAW,EAAE,GAAG,OAAO,CAAA;IAC/B,OAAO,UAAU,CACf,OAAO,EACP,YAAY,CAAC,WAAW,EAAE,eAAe,CAAC,CAC3C,CAAA;AACH,CAAC,CAAA;AAED,MAAM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AAI,sBAAsB,EAAE,CAAC;QAC3B,SAAS,CACP,KAAK,EACL,YAAY,CAAC,KAAK,EAClB,aAAa,EACb,OAAO,CAAC,MAAM,CACf,CAAA;QACD,SAAS,CAAC,KAAK,EAAE,YAAY,CAAC,KAAK,EAAE,aAAa,CAAC,CAAA;IACrD,CAAC;IAED,2CAA2C;IAC3C,KAAK,MAAM,IAAI,IAAI,KAAK,CAAC,KAAK,CAAC,MAAM,EAAE,EAAE,CAAC;QACxC,MAAM,CAAC,SAAS,CAAC,GAAG,IAAI,CAAC,OAAO,CAAA;QAChC,IAAI,SAAS,EAAE,IAAI,CAAC,QAAQ,EAAE,CAAC;YAC7B,IAAI,CAAC,QAAQ,GAAG,SAAS,CAAC,IAAI,CAAC,QAAQ,CAAA;QACzC,CAAC;IACH,CAAC;IAED,OAAO,KAAK,CAAA;AACd,CAAC,CAAA","sourcesContent":["import { PackageJson } from '@vltpkg/package-json'\nimport { Monorepo } from '@vltpkg/workspaces'\nimport { readFileSync } from 'node:fs'\nimport { resolve } from 'node:path'\nimport { loadEdges } from './load-edges.ts'\nimport { loadNodes } from './load-nodes.ts'\nimport { Graph } from '../graph.ts'\nimport type { PathScurry } from 'path-scurry'\nimport type { NormalizedManifest } from '@vltpkg/types'\nimport type { SpecOptions } from '@vltpkg/spec'\nimport type { LockfileData } from './types.ts'\nimport type { GraphModifier } from '../modifiers.ts'\n\nexport type LoadOptions = SpecOptions & {\n /**\n * An optional {@link Graph} object to hydrate extra data from.\n */\n actual?: Graph\n /**\n * The project root dirname.\n */\n projectRoot: string\n /**\n * The project root manifest.\n */\n mainManifest: NormalizedManifest\n /**\n * The graph modifiers helper object.\n */\n modifiers?: GraphModifier\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 * Load only importers into the graph if the modifiers have changed.\n */\n skipLoadingNodesOnModifiersChange?: boolean\n}\n\nconst loadLockfile = (projectRoot: string, lockfilePath: string) =>\n JSON.parse(\n readFileSync(resolve(projectRoot, lockfilePath), {\n encoding: 'utf8',\n }),\n ) as LockfileData\n\nexport const load = (options: LoadOptions): Graph => {\n const { projectRoot } = options\n return loadObject(\n options,\n loadLockfile(projectRoot, 'vlt-lock.json'),\n )\n}\n\nexport const loadHidden = (options: LoadOptions): Graph => {\n const { projectRoot } = options\n return loadObject(\n options,\n loadLockfile(projectRoot, 'node_modules/.vlt-lock.json'),\n )\n}\n\nexport const loadObject = (\n options: LoadOptions,\n lockfileData: Omit<LockfileData, 'options' | 'lockfileVersion'> &\n Partial<Pick<LockfileData, 'options' | 'lockfileVersion'>>,\n) => {\n const {\n mainManifest,\n modifiers,\n scurry,\n skipLoadingNodesOnModifiersChange,\n } = options\n const packageJson = options.packageJson ?? new PackageJson()\n const monorepo =\n options.monorepo ??\n Monorepo.maybeLoad(options.projectRoot, { packageJson, scurry })\n const {\n catalog = {},\n catalogs = {},\n modifiers: modifiersLockfileConfig,\n 'scope-registries': scopeRegistries,\n registry,\n registries,\n 'git-hosts': gitHosts,\n 'git-host-archives': gitHostArchives,\n } = lockfileData.options ?? {}\n\n // Optimize options merging - only create new objects when needed\n const mergedOptions = {\n ...options,\n catalog,\n catalogs,\n 'scope-registries':\n scopeRegistries ?\n { ...options['scope-registries'], ...scopeRegistries }\n : options['scope-registries'],\n registry: registry ?? options.registry,\n registries:\n registries ?\n { ...options.registries, ...registries }\n : options.registries,\n 'git-hosts':\n gitHosts ?\n { ...options['git-hosts'], ...gitHosts }\n : options['git-hosts'],\n 'git-host-archives':\n gitHostArchives ?\n { ...options['git-host-archives'], ...gitHostArchives }\n : options['git-host-archives'],\n }\n const graph = new Graph({\n ...mergedOptions,\n mainManifest,\n monorepo,\n })\n\n // When using the skipLoadingNodesOnModifiersChange option, we should skip loading\n // dependencies in case the modifiers have changed since we'll need to\n // recalculate the graph - useful for refreshing an ideal graph when\n // modifiers are swapped.\n\n // Optimize modifier comparison - avoid JSON.stringify for simple cases\n let modifiersChanged = false\n if (skipLoadingNodesOnModifiersChange) {\n const lockfileConfig = modifiersLockfileConfig ?? {}\n const optionsConfig = modifiers?.config ?? {}\n\n // Quick check for obvious differences\n const lockfileKeys = Object.keys(lockfileConfig)\n const optionsKeys = Object.keys(optionsConfig)\n\n if (lockfileKeys.length !== optionsKeys.length) {\n modifiersChanged = true\n } else {\n // Only use JSON.stringify if we need deep comparison\n const lockfileModifiers = JSON.stringify(lockfileConfig)\n const optionsModifiers = JSON.stringify(optionsConfig)\n modifiersChanged = lockfileModifiers !== optionsModifiers\n }\n }\n const shouldLoadDependencies = !(\n skipLoadingNodesOnModifiersChange && modifiersChanged\n )\n if (shouldLoadDependencies) {\n loadNodes(\n graph,\n lockfileData.nodes,\n mergedOptions,\n options.actual,\n )\n loadEdges(graph, lockfileData.edges, mergedOptions)\n }\n\n // hydrate missing node-level registry data\n for (const node of graph.nodes.values()) {\n const [firstEdge] = node.edgesIn\n if (firstEdge?.spec.registry) {\n node.registry = firstEdge.spec.registry\n }\n }\n\n return graph\n}\n"]}
|
|
@@ -1,18 +1,23 @@
|
|
|
1
1
|
import type { SpecOptions } from '@vltpkg/spec';
|
|
2
2
|
import type { Graph } from '../graph.ts';
|
|
3
3
|
import type { LockfileData } from './types.ts';
|
|
4
|
+
import type { GraphModifier } from '../modifiers.ts';
|
|
4
5
|
export type SaveOptions = SpecOptions & {
|
|
5
6
|
/**
|
|
6
7
|
* The graph to be stored in the lockfile.
|
|
7
8
|
*/
|
|
8
9
|
graph: Graph;
|
|
10
|
+
/**
|
|
11
|
+
* The graph modifiers helper object.
|
|
12
|
+
*/
|
|
13
|
+
modifiers?: GraphModifier;
|
|
9
14
|
/**
|
|
10
15
|
* Should it save manifest data in the lockfile?
|
|
11
16
|
*/
|
|
12
17
|
saveManifests?: boolean;
|
|
13
18
|
};
|
|
14
|
-
export declare const lockfileData: ({ graph, "git-hosts": gitHosts, "git-host-archives": gitHostArchives, registry, registries, saveManifests, "scope-registries": scopeRegistries, }: SaveOptions) => LockfileData;
|
|
19
|
+
export declare const lockfileData: ({ graph, catalog, catalogs, "git-hosts": gitHosts, "git-host-archives": gitHostArchives, modifiers, registry, registries, saveManifests, "scope-registries": scopeRegistries, "jsr-registries": jsrRegistries, }: SaveOptions) => LockfileData;
|
|
15
20
|
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;
|
|
21
|
+
export declare const save: (options: Omit<SaveOptions, "saveManifests">) => void;
|
|
22
|
+
export declare const saveHidden: (options: Omit<SaveOptions, "saveManifests">) => void;
|
|
18
23
|
//# sourceMappingURL=save.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"save.d.ts","sourceRoot":"","sources":["../../../src/lockfile/save.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"save.d.ts","sourceRoot":"","sources":["../../../src/lockfile/save.ts"],"names":[],"mappings":"AAgBA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,cAAc,CAAA;AAE/C,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,aAAa,CAAA;AAExC,OAAO,KAAK,EACV,YAAY,EAMb,MAAM,YAAY,CAAA;AACnB,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAA;AAEpD,MAAM,MAAM,WAAW,GAAG,WAAW,GAAG;IACtC;;OAEG;IACH,KAAK,EAAE,KAAK,CAAA;IACZ;;OAEG;IACH,SAAS,CAAC,EAAE,aAAa,CAAA;IACzB;;OAEG;IACH,aAAa,CAAC,EAAE,OAAO,CAAA;CACxB,CAAA;AA8FD,eAAO,MAAM,YAAY,qNAYtB,WAAW,KAAG,YAyDhB,CAAA;AAeD,eAAO,MAAM,QAAQ,SACb,YAAY,YACR,MAAM,8BAEf,IAIF,CAAA;AAED,eAAO,MAAM,IAAI,YACN,IAAI,CAAC,WAAW,EAAE,eAAe,CAAC,KAC1C,IAKF,CAAA;AAED,eAAO,MAAM,UAAU,YACZ,IAAI,CAAC,WAAW,EAAE,eAAe,CAAC,KAC1C,IASF,CAAA"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { expandNormalizedManifestSymbols, isRecordStringString, } from '@vltpkg/types';
|
|
2
|
+
import { defaultGitHostArchives, defaultGitHosts, defaultJsrRegistries, defaultRegistries, defaultRegistry, defaultScopeRegistries, } from '@vltpkg/spec';
|
|
2
3
|
import { mkdirSync, writeFileSync } from 'node:fs';
|
|
3
4
|
import { dirname, resolve } from 'node:path';
|
|
4
5
|
import { getFlagNumFromNode } from "./types.js";
|
|
@@ -13,11 +14,7 @@ const formatNodes = (nodes, saveManifests, registry) => {
|
|
|
13
14
|
const customRegistry = node.resolved && registry && !node.resolved.startsWith(registry);
|
|
14
15
|
const resolved = customRegistry ? node.resolved : undefined;
|
|
15
16
|
// if it's in a location other than the default, stash that
|
|
16
|
-
const location =
|
|
17
|
-
node.location.endsWith('/node_modules/.vlt/' +
|
|
18
|
-
node.id +
|
|
19
|
-
'/node_modules/' +
|
|
20
|
-
node.name)) ?
|
|
17
|
+
const location = node.id.startsWith('file') || node.inVltStore() ?
|
|
21
18
|
undefined
|
|
22
19
|
: node.location;
|
|
23
20
|
const flags = getFlagNumFromNode(node);
|
|
@@ -31,8 +28,15 @@ const formatNodes = (nodes, saveManifests, registry) => {
|
|
|
31
28
|
if (location) {
|
|
32
29
|
lockfileNode[4] = location;
|
|
33
30
|
}
|
|
34
|
-
if (saveManifests) {
|
|
35
|
-
lockfileNode[5] = node.manifest;
|
|
31
|
+
if (saveManifests && node.manifest) {
|
|
32
|
+
lockfileNode[5] = expandNormalizedManifestSymbols(node.manifest);
|
|
33
|
+
if (node.confused && node.rawManifest) {
|
|
34
|
+
lockfileNode[6] = expandNormalizedManifestSymbols(node.rawManifest);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
// Always save platform data for optional dependencies if available
|
|
38
|
+
if (node.optional && node.platform) {
|
|
39
|
+
lockfileNode[7] = node.platform;
|
|
36
40
|
}
|
|
37
41
|
res[node.id] = lockfileNode;
|
|
38
42
|
}
|
|
@@ -51,7 +55,6 @@ Number(b.from.importer) - Number(a.from.importer) ||
|
|
|
51
55
|
`${edge.from.id} ${edge.spec.name}`,
|
|
52
56
|
`${edge.type} ${edge.spec.bareSpec || '*'} ${edge.to?.id ?? 'MISSING'}`,
|
|
53
57
|
]));
|
|
54
|
-
const isRecordStringString = (registries) => !(!registries || typeof registries === 'string');
|
|
55
58
|
const removeDefaultItems = (defaultItems, items) => {
|
|
56
59
|
const res = {};
|
|
57
60
|
for (const [key, value] of Object.entries(items)) {
|
|
@@ -61,25 +64,40 @@ const removeDefaultItems = (defaultItems, items) => {
|
|
|
61
64
|
}
|
|
62
65
|
return res;
|
|
63
66
|
};
|
|
64
|
-
export const lockfileData = ({ graph, 'git-hosts': gitHosts, 'git-host-archives': gitHostArchives, registry, registries, saveManifests, 'scope-registries': scopeRegistries, }) => {
|
|
67
|
+
export const lockfileData = ({ graph, catalog, catalogs, 'git-hosts': gitHosts, 'git-host-archives': gitHostArchives, modifiers, registry, registries, saveManifests, 'scope-registries': scopeRegistries, 'jsr-registries': jsrRegistries, }) => {
|
|
65
68
|
const cleanGitHosts = isRecordStringString(gitHosts) ?
|
|
66
69
|
removeDefaultItems(defaultGitHosts, gitHosts)
|
|
67
70
|
: undefined;
|
|
68
71
|
const cleanGitHostArchives = isRecordStringString(gitHostArchives) ?
|
|
69
72
|
removeDefaultItems(defaultGitHostArchives, gitHostArchives)
|
|
70
73
|
: undefined;
|
|
74
|
+
const cleanModifiers = modifiers && isRecordStringString(modifiers.config) ?
|
|
75
|
+
modifiers.config
|
|
76
|
+
: undefined;
|
|
71
77
|
const cleanRegistries = isRecordStringString(registries) ?
|
|
72
78
|
removeDefaultItems(defaultRegistries, registries)
|
|
73
79
|
: undefined;
|
|
74
80
|
const cleanScopeRegistries = isRecordStringString(scopeRegistries) ?
|
|
75
81
|
removeDefaultItems(defaultScopeRegistries, scopeRegistries)
|
|
76
82
|
: undefined;
|
|
83
|
+
const cleanJsrRegistries = isRecordStringString(jsrRegistries) ?
|
|
84
|
+
removeDefaultItems(defaultJsrRegistries, jsrRegistries)
|
|
85
|
+
: undefined;
|
|
77
86
|
const hasItems = (clean) => clean && Object.keys(clean).length;
|
|
78
87
|
return {
|
|
88
|
+
lockfileVersion: 0,
|
|
79
89
|
options: {
|
|
90
|
+
...(hasItems(cleanModifiers) ?
|
|
91
|
+
{ modifiers: cleanModifiers }
|
|
92
|
+
: {}),
|
|
93
|
+
...(hasItems(catalog) ? { catalog } : {}),
|
|
94
|
+
...(hasItems(catalogs) ? { catalogs } : {}),
|
|
80
95
|
...(hasItems(cleanScopeRegistries) ?
|
|
81
96
|
{ 'scope-registries': cleanScopeRegistries }
|
|
82
97
|
: undefined),
|
|
98
|
+
...(hasItems(cleanJsrRegistries) ?
|
|
99
|
+
{ 'jsr-registries': cleanJsrRegistries }
|
|
100
|
+
: undefined),
|
|
83
101
|
...(registry !== undefined && registry !== defaultRegistry ?
|
|
84
102
|
{ registry }
|
|
85
103
|
: undefined),
|
|
@@ -116,13 +134,13 @@ export const save = (options) => {
|
|
|
116
134
|
const { graph } = options;
|
|
117
135
|
const data = lockfileData({ ...options, saveManifests: false });
|
|
118
136
|
const fileName = resolve(graph.projectRoot, 'vlt-lock.json');
|
|
119
|
-
|
|
137
|
+
saveData(data, fileName, false);
|
|
120
138
|
};
|
|
121
139
|
export const saveHidden = (options) => {
|
|
122
140
|
const { graph } = options;
|
|
123
141
|
const data = lockfileData({ ...options, saveManifests: true });
|
|
124
142
|
const fileName = resolve(graph.projectRoot, 'node_modules/.vlt-lock.json');
|
|
125
143
|
mkdirSync(dirname(fileName), { recursive: true });
|
|
126
|
-
|
|
144
|
+
saveData(data, fileName, true);
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,MAAM,IAAI,GAAG,CAAC,OAAoB,EAAE,EAAE;IAC3C,MAAM,EAAE,KAAK,EAAE,GAAG,OAAO,CAAA;IACzB,MAAM,IAAI,GAAG,YAAY,CAAC,EAAE,GAAG,OAAO,EAAE,aAAa,EAAE,KAAK,EAAE,CAAC,CAAA;IAC/D,MAAM,QAAQ,GAAG,OAAO,CAAC,KAAK,CAAC,WAAW,EAAE,eAAe,CAAC,CAAA;IAC5D,OAAO,QAAQ,CAAC,IAAI,EAAE,QAAQ,EAAE,KAAK,CAAC,CAAA;AACxC,CAAC,CAAA;AAED,MAAM,CAAC,MAAM,UAAU,GAAG,CAAC,OAAoB,EAAE,EAAE;IACjD,MAAM,EAAE,KAAK,EAAE,GAAG,OAAO,CAAA;IACzB,MAAM,IAAI,GAAG,YAAY,CAAC,EAAE,GAAG,OAAO,EAAE,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 type { DepID } from '@vltpkg/dep-id'\nimport {\n defaultRegistry,\n defaultRegistries,\n defaultGitHosts,\n defaultGitHostArchives,\n defaultScopeRegistries,\n} from '@vltpkg/spec'\nimport type { SpecOptions } from '@vltpkg/spec'\nimport { mkdirSync, writeFileSync } from 'node:fs'\nimport { dirname, resolve } from 'node:path'\nimport type { Edge } from '../edge.ts'\nimport type { Graph } from '../graph.ts'\nimport type { Node } from '../node.ts'\nimport { getFlagNumFromNode } from './types.ts'\nimport type {\n LockfileData,\n LockfileEdgeKey,\n LockfileEdges,\n LockfileEdgeValue,\n LockfileNode,\n} from './types.ts'\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"]}
|
|
1
|
+
{"version":3,"file":"save.js","sourceRoot":"","sources":["../../../src/lockfile/save.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,+BAA+B,EAC/B,oBAAoB,GACrB,MAAM,eAAe,CAAA;AACtB,OAAO,EACL,sBAAsB,EACtB,eAAe,EACf,oBAAoB,EACpB,iBAAiB,EACjB,eAAe,EACf,sBAAsB,GACvB,MAAM,cAAc,CAAA;AACrB,OAAO,EAAE,SAAS,EAAE,aAAa,EAAE,MAAM,SAAS,CAAA;AAClD,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AAC5C,OAAO,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAA;AA+B/C,MAAM,WAAW,GAAG,CAClB,KAAqB,EACrB,aAAuB,EACvB,QAAiB,EACjB,EAAE;IACF,gEAAgE;IAChE,mEAAmE;IACnE,MAAM,GAAG,GAAW,CAAC,GAAG,KAAK,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAA;IAC7D,2DAA2D;IAC3D,MAAM,YAAY,GAAW,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EA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,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC,CAAA;IAC1C,MAAM,OAAO,GAAG,aAAa,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,WAAW,CAAC,IAAI,CAAC,CAAA;IACxD,aAAa,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAA;AAClC,CAAC,CAAA;AAED,MAAM,CAAC,MAAM,IAAI,GAAG,CAClB,OAA2C,EACrC,EAAE;IACR,MAAM,EAAE,KAAK,EAAE,GAAG,OAAO,CAAA;IACzB,MAAM,IAAI,GAAG,YAAY,CAAC,EAAE,GAAG,OAAO,EAAE,aAAa,EAAE,KAAK,EAAE,CAAC,CAAA;IAC/D,MAAM,QAAQ,GAAG,OAAO,CAAC,KAAK,CAAC,WAAW,EAAE,eAAe,CAAC,CAAA;IAC5D,QAAQ,CAAC,IAAI,EAAE,QAAQ,EAAE,KAAK,CAAC,CAAA;AACjC,CAAC,CAAA;AAED,MAAM,CAAC,MAAM,UAAU,GAAG,CACxB,OAA2C,EACrC,EAAE;IACR,MAAM,EAAE,KAAK,EAAE,GAAG,OAAO,CAAA;IACzB,MAAM,IAAI,GAAG,YAAY,CAAC,EAAE,GAAG,OAAO,EAAE,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,QAAQ,CAAC,IAAI,EAAE,QAAQ,EAAE,IAAI,CAAC,CAAA;AAChC,CAAC,CAAA","sourcesContent":["import {\n expandNormalizedManifestSymbols,\n isRecordStringString,\n} from '@vltpkg/types'\nimport {\n defaultGitHostArchives,\n defaultGitHosts,\n defaultJsrRegistries,\n defaultRegistries,\n defaultRegistry,\n defaultScopeRegistries,\n} from '@vltpkg/spec'\nimport { mkdirSync, writeFileSync } from 'node:fs'\nimport { dirname, resolve } from 'node:path'\nimport { getFlagNumFromNode } from './types.ts'\nimport type { DepID } from '@vltpkg/dep-id'\nimport type { SpecOptions } from '@vltpkg/spec'\nimport type { Edge } from '../edge.ts'\nimport type { Graph } from '../graph.ts'\nimport type { Node } from '../node.ts'\nimport type {\n LockfileData,\n LockfileEdgeKey,\n LockfileEdges,\n LockfileEdgeValue,\n LockfileNode,\n LockfilePlatform,\n} from './types.ts'\nimport type { GraphModifier } from '../modifiers.ts'\n\nexport type SaveOptions = SpecOptions & {\n /**\n * The graph to be stored in the lockfile.\n */\n graph: Graph\n /**\n * The graph modifiers helper object.\n */\n modifiers?: GraphModifier\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 node.id.startsWith('file') || node.inVltStore() ?\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 && node.manifest) {\n lockfileNode[5] = expandNormalizedManifestSymbols(node.manifest)\n\n if (node.confused && node.rawManifest) {\n lockfileNode[6] = expandNormalizedManifestSymbols(\n node.rawManifest,\n )\n }\n }\n\n // Always save platform data for optional dependencies if available\n if (node.optional && node.platform) {\n lockfileNode[7] = node.platform as LockfilePlatform\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 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 catalog,\n catalogs,\n 'git-hosts': gitHosts,\n 'git-host-archives': gitHostArchives,\n modifiers,\n registry,\n registries,\n saveManifests,\n 'scope-registries': scopeRegistries,\n 'jsr-registries': jsrRegistries,\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 cleanModifiers =\n modifiers && isRecordStringString(modifiers.config) ?\n modifiers.config\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 cleanJsrRegistries =\n isRecordStringString(jsrRegistries) ?\n removeDefaultItems(defaultJsrRegistries, jsrRegistries)\n : undefined\n const hasItems = (clean: Record<string, unknown> | undefined) =>\n clean && Object.keys(clean).length\n return {\n lockfileVersion: 0,\n options: {\n ...(hasItems(cleanModifiers) ?\n { modifiers: cleanModifiers }\n : {}),\n ...(hasItems(catalog) ? { catalog } : {}),\n ...(hasItems(catalogs) ? { catalogs } : {}),\n ...(hasItems(cleanScopeRegistries) ?\n { 'scope-registries': cleanScopeRegistries }\n : undefined),\n ...(hasItems(cleanJsrRegistries) ?\n { 'jsr-registries': cleanJsrRegistries }\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): void => {\n const json = JSON.stringify(data, null, 2)\n const content = saveManifests ? json : extraFormat(json)\n writeFileSync(fileName, content)\n}\n\nexport const save = (\n options: Omit<SaveOptions, 'saveManifests'>,\n): void => {\n const { graph } = options\n const data = lockfileData({ ...options, saveManifests: false })\n const fileName = resolve(graph.projectRoot, 'vlt-lock.json')\n saveData(data, fileName, false)\n}\n\nexport const saveHidden = (\n options: Omit<SaveOptions, 'saveManifests'>,\n): void => {\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 saveData(data, fileName, true)\n}\n"]}
|
|
@@ -1,6 +1,14 @@
|
|
|
1
1
|
import type { DepID } from '@vltpkg/dep-id';
|
|
2
2
|
import type { Spec, SpecOptions } from '@vltpkg/spec';
|
|
3
|
-
import type { Integrity,
|
|
3
|
+
import type { Integrity, NormalizedManifest, DependencyTypeShort } from '@vltpkg/types';
|
|
4
|
+
/**
|
|
5
|
+
* Platform requirements for a lockfile node
|
|
6
|
+
*/
|
|
7
|
+
export type LockfilePlatform = {
|
|
8
|
+
engines?: Record<string, string>;
|
|
9
|
+
os?: string[] | string;
|
|
10
|
+
cpu?: string[] | string;
|
|
11
|
+
};
|
|
4
12
|
/**
|
|
5
13
|
* This is the main type definition for the contents of the
|
|
6
14
|
* `vlt-lock.json` file.
|
|
@@ -9,14 +17,17 @@ import type { Integrity, Manifest, DependencyTypeShort } from '@vltpkg/types';
|
|
|
9
17
|
* a {@link Graph} representing a previous install.
|
|
10
18
|
*/
|
|
11
19
|
export type LockfileData = {
|
|
12
|
-
|
|
20
|
+
lockfileVersion: number;
|
|
21
|
+
options: SpecOptions & {
|
|
22
|
+
modifiers?: Record<string, string> | undefined;
|
|
23
|
+
};
|
|
13
24
|
nodes: Record<DepID, LockfileNode>;
|
|
14
25
|
edges: LockfileEdges;
|
|
15
26
|
};
|
|
16
27
|
export declare const getFlagNumFromNode: (node: {
|
|
17
28
|
optional?: boolean;
|
|
18
29
|
dev?: boolean;
|
|
19
|
-
}) =>
|
|
30
|
+
}) => 1 | 0 | 2 | 3;
|
|
20
31
|
export declare const getBooleanFlagsFromNum: (flags: LockfileNodeFlags) => {
|
|
21
32
|
dev: boolean;
|
|
22
33
|
optional: boolean;
|
|
@@ -38,7 +49,9 @@ export type LockfileNode = [
|
|
|
38
49
|
integrity?: Integrity | null,
|
|
39
50
|
resolved?: string | null,
|
|
40
51
|
location?: string | null,
|
|
41
|
-
manifest?:
|
|
52
|
+
manifest?: NormalizedManifest | null,
|
|
53
|
+
rawManifest?: NormalizedManifest | null,
|
|
54
|
+
platform?: LockfilePlatform | null
|
|
42
55
|
];
|
|
43
56
|
/**
|
|
44
57
|
* Lockfile edges are stored as a record object where the key
|
|
@@ -1 +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,EACV,SAAS,EACT,
|
|
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,EACV,SAAS,EACT,kBAAkB,EAClB,mBAAmB,EACpB,MAAM,eAAe,CAAA;AAGtB;;GAEG;AACH,MAAM,MAAM,gBAAgB,GAAG;IAC7B,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;IAChC,EAAE,CAAC,EAAE,MAAM,EAAE,GAAG,MAAM,CAAA;IACtB,GAAG,CAAC,EAAE,MAAM,EAAE,GAAG,MAAM,CAAA;CACxB,CAAA;AAED;;;;;;GAMG;AACH,MAAM,MAAM,YAAY,GAAG;IACzB,eAAe,EAAE,MAAM,CAAA;IACvB,OAAO,EAAE,WAAW,GAAG;QACrB,SAAS,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,SAAS,CAAA;KAC/C,CAAA;IACD,KAAK,EAAE,MAAM,CAAC,KAAK,EAAE,YAAY,CAAC,CAAA;IAClC,KAAK,EAAE,aAAa,CAAA;CACrB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ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/lockfile/types.ts"],"names":[],"mappings":"AAkCA,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 {\n Integrity,\n NormalizedManifest,\n DependencyTypeShort,\n} from '@vltpkg/types'\nimport type { Graph } from '../graph.ts'\n\n/**\n * Platform requirements for a lockfile node\n */\nexport type LockfilePlatform = {\n engines?: Record<string, string>\n os?: string[] | string\n cpu?: string[] | string\n}\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 lockfileVersion: number\n options: SpecOptions & {\n modifiers?: Record<string, string> | undefined\n }\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?: NormalizedManifest | null,\n rawManifest?: NormalizedManifest | null,\n platform?: LockfilePlatform | 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,189 @@
|
|
|
1
|
+
import { Spec } from '@vltpkg/spec';
|
|
2
|
+
import type { ModifierBreadcrumb, ModifierInteractiveBreadcrumb } from '@vltpkg/dss-breadcrumb';
|
|
3
|
+
import type { SpecOptions } from '@vltpkg/spec';
|
|
4
|
+
import type { NormalizedManifest } from '@vltpkg/types';
|
|
5
|
+
import type { Edge } from './edge.ts';
|
|
6
|
+
import type { Node } from './node.ts';
|
|
7
|
+
import type { Dependency } from './dependencies.ts';
|
|
8
|
+
/**
|
|
9
|
+
* Loaded modifiers configuration as described in the `vlt.json` file.
|
|
10
|
+
*/
|
|
11
|
+
export type GraphModifierLoadedConfig = {
|
|
12
|
+
modifiers: GraphModifierConfigObject;
|
|
13
|
+
};
|
|
14
|
+
/**
|
|
15
|
+
* Type definition for the modifiers configuration object
|
|
16
|
+
*/
|
|
17
|
+
export type GraphModifierConfigObject = Record<string, string>;
|
|
18
|
+
/**
|
|
19
|
+
* Info needed to define a graph modifier.
|
|
20
|
+
*/
|
|
21
|
+
export type BaseModifierEntry = {
|
|
22
|
+
type: 'edge' | 'node';
|
|
23
|
+
query: string;
|
|
24
|
+
breadcrumb: ModifierBreadcrumb;
|
|
25
|
+
value: string | NormalizedManifest;
|
|
26
|
+
refs: Set<{
|
|
27
|
+
name: string;
|
|
28
|
+
from: Node;
|
|
29
|
+
}>;
|
|
30
|
+
};
|
|
31
|
+
/**
|
|
32
|
+
* Extra info to define specifically a graph edge modifier.
|
|
33
|
+
*/
|
|
34
|
+
export type EdgeModifierEntry = BaseModifierEntry & {
|
|
35
|
+
type: 'edge';
|
|
36
|
+
spec: Spec;
|
|
37
|
+
value: string;
|
|
38
|
+
};
|
|
39
|
+
/**
|
|
40
|
+
* Extra info to define the graph node modifier.
|
|
41
|
+
*/
|
|
42
|
+
export type NodeModifierEntry = BaseModifierEntry & {
|
|
43
|
+
type: 'node';
|
|
44
|
+
manifest: NormalizedManifest;
|
|
45
|
+
};
|
|
46
|
+
/**
|
|
47
|
+
* A graph modifier entry, which can be either an edge or a node modifier.
|
|
48
|
+
*/
|
|
49
|
+
export type ModifierEntry = EdgeModifierEntry | NodeModifierEntry;
|
|
50
|
+
/**
|
|
51
|
+
* An object to track modifiers that have matched an initial part of the
|
|
52
|
+
* breadcrumb. It holds pointers to both nodes and edges matched in the
|
|
53
|
+
* current traversed graph on top of the modifier info and the breadcrumb
|
|
54
|
+
* state that is used to track the current state of the parsing.
|
|
55
|
+
*/
|
|
56
|
+
export type ModifierActiveEntry = {
|
|
57
|
+
/**
|
|
58
|
+
* The modifier this active entry is working with.
|
|
59
|
+
*/
|
|
60
|
+
modifier: ModifierEntry;
|
|
61
|
+
/**
|
|
62
|
+
* The breadcrumb that is used to track the current state of the parsing.
|
|
63
|
+
*/
|
|
64
|
+
interactiveBreadcrumb: ModifierInteractiveBreadcrumb;
|
|
65
|
+
/**
|
|
66
|
+
* The first node to be affected by this modifier.
|
|
67
|
+
*/
|
|
68
|
+
originalFrom: Node;
|
|
69
|
+
/**
|
|
70
|
+
* The original edge that is being replaced with this entry.
|
|
71
|
+
*/
|
|
72
|
+
originalEdge?: Edge;
|
|
73
|
+
/**
|
|
74
|
+
* The modified edge that is being used to replace the original edge.
|
|
75
|
+
*/
|
|
76
|
+
modifiedEdge?: Edge;
|
|
77
|
+
};
|
|
78
|
+
/**
|
|
79
|
+
* Class representing loaded modifiers configuration for a project.
|
|
80
|
+
*
|
|
81
|
+
* Instances of this class can be used as a helper to modify the graph
|
|
82
|
+
* during the graph build ideal traversal time.
|
|
83
|
+
*
|
|
84
|
+
* ```
|
|
85
|
+
* const modifier = new GraphModifier(options)
|
|
86
|
+
* modifier.load(options)
|
|
87
|
+
* ```
|
|
88
|
+
*
|
|
89
|
+
* The `tryImporter` method can be used to register the initial importer
|
|
90
|
+
* node along with any modifier that includes an importer selector, e.g:
|
|
91
|
+
* `modifier.tryImporter(graph.mainImporter)`
|
|
92
|
+
*
|
|
93
|
+
* When traversing the graph, use the `tryNewDependency` method to check
|
|
94
|
+
* if a given dependency spec to the current traversed node has matching
|
|
95
|
+
* registered modifiers, e.g:
|
|
96
|
+
* `const entries = modifier.tryNewDependency(fromNode, depSpec)`
|
|
97
|
+
*
|
|
98
|
+
* Use `updateActiveEntry` to update a given active modifier entry state
|
|
99
|
+
* with the current node of the graph being traversed. e.g:
|
|
100
|
+
* ```
|
|
101
|
+
* for (const entry of entries)
|
|
102
|
+
* modifier.updateActiveEntry(fromNode, entry)
|
|
103
|
+
* ```
|
|
104
|
+
*/
|
|
105
|
+
export declare class GraphModifier {
|
|
106
|
+
#private;
|
|
107
|
+
/**
|
|
108
|
+
* A set of currently active modifiers, which are being parsed.
|
|
109
|
+
*/
|
|
110
|
+
activeModifiers: Set<ModifierActiveEntry>;
|
|
111
|
+
/** A set of all modifier string values loaded from vlt.json */
|
|
112
|
+
modifierNames: Set<string>;
|
|
113
|
+
constructor(options: SpecOptions);
|
|
114
|
+
/**
|
|
115
|
+
* Load the modifiers definitions from vlt.json,
|
|
116
|
+
* converting the result into a GraphModifierConfigObject
|
|
117
|
+
*/
|
|
118
|
+
get config(): GraphModifierConfigObject;
|
|
119
|
+
/**
|
|
120
|
+
* Loads the modifiers defined in `vlt.json` into memory.
|
|
121
|
+
*/
|
|
122
|
+
load(options: SpecOptions): void;
|
|
123
|
+
/**
|
|
124
|
+
* Try matching the provided node against the top-level selectors. In case
|
|
125
|
+
* a match is found it will also register the active entry modifier and
|
|
126
|
+
* update the active entry to the current importer node.
|
|
127
|
+
*/
|
|
128
|
+
tryImporter(importer: Node): void;
|
|
129
|
+
/**
|
|
130
|
+
* Try matching the provided node and spec to the current
|
|
131
|
+
* active parsing modifier entries along with possible starting-level
|
|
132
|
+
* modifiers.
|
|
133
|
+
*
|
|
134
|
+
* Any entries in which the breachcrumb have already reached its last
|
|
135
|
+
* element will be prioritized, along with checking for specificity,
|
|
136
|
+
* the complete entry with the highest specificity will be returned or just
|
|
137
|
+
* the entry with the highest specificity if no complete entry is found.
|
|
138
|
+
* Returns `undefined` if no matching entry is found.
|
|
139
|
+
*
|
|
140
|
+
* This method works with the assumption that it's going to be called
|
|
141
|
+
* during a graph traversal, such that any ascendent has been checked
|
|
142
|
+
* and the active modifier entry state has been updated in the previous
|
|
143
|
+
* iteration.
|
|
144
|
+
*/
|
|
145
|
+
tryNewDependency(from: Node, spec: Spec): ModifierActiveEntry | undefined;
|
|
146
|
+
/**
|
|
147
|
+
* Returns the set of {@link ModifierActiveEntry} instances that matches
|
|
148
|
+
* the provided {@link Dependency} specs for a given node.
|
|
149
|
+
*
|
|
150
|
+
* This method is mostly a helper to {@link GraphModifier.tryNewDependency}
|
|
151
|
+
* that handles the registered modifiers traversal lookup.
|
|
152
|
+
*/
|
|
153
|
+
tryDependencies(from: Node, dependencies: Dependency[] | Edge[]): Map<string, ModifierActiveEntry>;
|
|
154
|
+
/**
|
|
155
|
+
* Updates an active entry state keeping track of items in the multi-level
|
|
156
|
+
* active entries map. If the current breadcrumb state shows there's no more
|
|
157
|
+
* items left, then we deregister the modifier.
|
|
158
|
+
*/
|
|
159
|
+
updateActiveEntry(from: Node, active: ModifierActiveEntry): void;
|
|
160
|
+
/**
|
|
161
|
+
* Creates a new active modifier.
|
|
162
|
+
*/
|
|
163
|
+
newModifier(from: Node, modifier: ModifierEntry): ModifierActiveEntry;
|
|
164
|
+
/**
|
|
165
|
+
* Removes a previously registered modifier from the active entries.
|
|
166
|
+
*/
|
|
167
|
+
deregisterModifier(modifier: ModifierEntry): void;
|
|
168
|
+
/**
|
|
169
|
+
* Operates in previously registered nodes and edges in order to put
|
|
170
|
+
* back in place any of the original edges that were referenced to in
|
|
171
|
+
* active (ongoing) breadcrumb parsing entries that were never completed.
|
|
172
|
+
*
|
|
173
|
+
* This method can be used to easily rollback any pending operations
|
|
174
|
+
* once the graph traversal is done.
|
|
175
|
+
*/
|
|
176
|
+
rollbackActiveEntries(): void;
|
|
177
|
+
/**
|
|
178
|
+
* Convenience method to instantiate and load in one call.
|
|
179
|
+
* Returns undefined if the project does not have a vlt.json file,
|
|
180
|
+
* otherwise returns the loaded Modifiers instance.
|
|
181
|
+
*/
|
|
182
|
+
static maybeLoad(options: SpecOptions): GraphModifier | undefined;
|
|
183
|
+
/**
|
|
184
|
+
* Convenience method to instantiate and load in one call.
|
|
185
|
+
* Throws if called on a directory that does not have a vlt.json file.
|
|
186
|
+
*/
|
|
187
|
+
static load(options: SpecOptions): GraphModifier;
|
|
188
|
+
}
|
|
189
|
+
//# sourceMappingURL=modifiers.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"modifiers.d.ts","sourceRoot":"","sources":["../../src/modifiers.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,IAAI,EAAE,MAAM,cAAc,CAAA;AAOnC,OAAO,KAAK,EACV,kBAAkB,EAClB,6BAA6B,EAC9B,MAAM,wBAAwB,CAAA;AAC/B,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,cAAc,CAAA;AAC/C,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAA;AACvD,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;AACrC,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;AACrC,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAA;AAEnD;;GAEG;AACH,MAAM,MAAM,yBAAyB,GAAG;IACtC,SAAS,EAAE,yBAAyB,CAAA;CACrC,CAAA;AAED;;GAEG;AAEH,MAAM,MAAM,yBAAyB,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;AAE9D;;GAEG;AACH,MAAM,MAAM,iBAAiB,GAAG;IAC9B,IAAI,EAAE,MAAM,GAAG,MAAM,CAAA;IACrB,KAAK,EAAE,MAAM,CAAA;IACb,UAAU,EAAE,kBAAkB,CAAA;IAC9B,KAAK,EAAE,MAAM,GAAG,kBAAkB,CAAA;IAClC,IAAI,EAAE,GAAG,CAAC;QACR,IAAI,EAAE,MAAM,CAAA;QACZ,IAAI,EAAE,IAAI,CAAA;KACX,CAAC,CAAA;CACH,CAAA;AAED;;GAEG;AACH,MAAM,MAAM,iBAAiB,GAAG,iBAAiB,GAAG;IAClD,IAAI,EA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