@antongolub/lockfile 0.0.0-snapshot.41 → 0.0.0-snapshot.42

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 CHANGED
@@ -165,6 +165,7 @@ export interface TSnapshotIndex {
165
165
  name: string
166
166
  version: string
167
167
  entry: TEntry
168
+ depth: number // the lowest level where the dep@ver first time occurs
168
169
  }>
169
170
  prod: Set<TEntry>
170
171
  getEntryId ({name, version}: TEntry): string
@@ -183,6 +184,36 @@ export interface TSnapshotIndex {
183
184
  * pkg.json `resolutions` and `overrides` directives are completely ignored for now
184
185
  * pkg aliases are not _fully_ supported yet [#2](https://github.com/antongolub/lockfile/issues/2#issuecomment-1786613893)
185
186
 
187
+ ### Snippets
188
+ Extracts all deps by depth:
189
+ ```ts
190
+ const getDepsByDepth = (idx: TSnapshotIndex, depth = 0) => Object.values(idx.tree)
191
+ .filter(({depth: d}) => d === depth)
192
+ .map(({entry}) => entry)
193
+ ```
194
+
195
+ Get the longest dep chain:
196
+ ```ts
197
+ const getLongestChain = (): TEntry[] => {
198
+ let max = 0
199
+ let chain: TEntry[] = []
200
+
201
+ for (const e of Object.values(idx.tree)) {
202
+ if (e.depth > max) {
203
+ max = e.depth
204
+ chain = [...e.parents, e.entry]
205
+ }
206
+ }
207
+ return chain
208
+ }
209
+
210
+ constole.log(
211
+ getLongestChain()
212
+ .map((e) => idx.getEntryId(e))
213
+ .join(' -> ')
214
+ )
215
+ ```
216
+
186
217
  ### Inspired by
187
218
  * [synp](https://github.com/imsnif/synp)
188
219
  * [snyk-nodejs-lockfile-parser](https://github.com/snyk/nodejs-lockfile-parser)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@antongolub/lockfile",
3
- "version": "0.0.0-snapshot.41",
3
+ "version": "0.0.0-snapshot.42",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -49,9 +49,9 @@
49
49
  },
50
50
  "scripts": {
51
51
  "build": "concurrently 'npm:build:*'",
52
- "build:bin": "node ./src/scripts/build.mjs --entry='./src/main/ts/cli.ts' --no-bundle",
53
- "build:esm": "node ./src/scripts/build.mjs --entry='./src/main/ts/index.ts'",
54
- "build:cjs": "yarn run build:esm -- --cjs",
52
+ "build:bin": "node ./src/scripts/build.mjs --entry='./src/main/ts/cli.ts' --bundle=none",
53
+ "build:vendor": "node ./src/scripts/build.mjs --entry='./src/main/ts/vendor.ts' --bundle=all --format='cjs,esm'",
54
+ "build:index": "node ./src/scripts/build.mjs --entry='./src/main/ts/index.ts' --bundle=src --format='cjs,esm' --external='./src/main/ts/vendor,node:*' --map='../../src/main/ts/vendor:./vendor,../src/main/ts/vendor:./vendor'",
55
55
  "build:dts": "tsc --emitDeclarationOnly --skipLibCheck --outDir target/dts",
56
56
  "test": "yarn test:unit",
57
57
  "test:unit": "c8 -r lcov -r text -o target/coverage -x src/scripts -x src/test uvu -r tsm -i helpers 'src/test/ts/'",
@@ -219,7 +219,8 @@ var walk = (ctx) => {
219
219
  name: entry.name,
220
220
  version: entry.version,
221
221
  entry,
222
- parents
222
+ parents,
223
+ depth
223
224
  };
224
225
  if ((_a = root.dependencies) == null ? void 0 : _a[chunks[1]]) {
225
226
  idx.prod.add(entry);
@@ -682,7 +683,7 @@ var preformat3 = (idx) => {
682
683
  var format3 = (snapshot) => JSON.stringify(preformat3(analyze(snapshot)), null, 2);
683
684
 
684
685
  // src/main/ts/formats/yarn-classic.ts
685
- var import_js_yaml = require("js-yaml");
686
+ var import_vendor = require("./vendor.cjs");
686
687
  var kvEntryPattern = /^(\s+)"?([^"]+)"?\s"?([^"]+)"?$/;
687
688
  var version4 = "yarn-classic";
688
689
  var check4 = (value) => value.includes("# yarn lockfile v1");
@@ -701,7 +702,7 @@ var preparse = (value) => {
701
702
  }
702
703
  return line;
703
704
  }, "").join("\n");
704
- return (0, import_js_yaml.load)(_value);
705
+ return (0, import_vendor.yamlLoad)(_value);
705
706
  };
706
707
  var parse3 = (value, ...pkgs) => {
707
708
  const manifest = JSON.parse(pkgs[0]);
@@ -787,7 +788,7 @@ var preformat4 = (idx) => {
787
788
  };
788
789
  var format4 = (snapshot) => {
789
790
  const lf = preformat4({ snapshot });
790
- const lines = (0, import_js_yaml.dump)(lf, {
791
+ const lines = (0, import_vendor.yamlDump)(lf, {
791
792
  quotingType: '"',
792
793
  flowLevel: -1,
793
794
  lineWidth: -1,
@@ -835,7 +836,7 @@ var formatResolution3 = ({ type, id, name = "", registry = "https://registry.yar
835
836
  };
836
837
 
837
838
  // src/main/ts/formats/yarn-berry.ts
838
- var import_js_yaml2 = require("js-yaml");
839
+ var import_vendor2 = require("./vendor.cjs");
839
840
  var version5 = "yarn-berry";
840
841
  var check5 = (value) => value.includes(`
841
842
  __metadata:
@@ -847,7 +848,7 @@ var parse4 = (lockfile, ...pkgs) => {
847
848
  return [manifest2.name, manifest2];
848
849
  }));
849
850
  const snapshot = {};
850
- const raw = (0, import_js_yaml2.load)(lockfile);
851
+ const raw = (0, import_vendor2.yamlLoad)(lockfile);
851
852
  delete raw.__metadata;
852
853
  Object.entries(raw).forEach((value) => {
853
854
  var _a, _b;
@@ -958,7 +959,7 @@ var format5 = (snapshot, { __metadata = {
958
959
  version: 5,
959
960
  cacheKey: 8
960
961
  } } = {}) => {
961
- const lines = (0, import_js_yaml2.dump)(__spreadValues({
962
+ const lines = (0, import_vendor2.yamlDump)(__spreadValues({
962
963
  __metadata
963
964
  }, preformat5({ snapshot }, { __metadata })), {
964
965
  quotingType: '"',