flatlock 1.2.0 → 1.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (43) hide show
  1. package/README.md +42 -1
  2. package/bin/flatcover.js +398 -0
  3. package/bin/flatlock.js +158 -0
  4. package/package.json +16 -5
  5. package/src/parsers/index.js +14 -2
  6. package/src/parsers/npm.js +82 -0
  7. package/src/parsers/pnpm/index.js +70 -0
  8. package/src/parsers/yarn-berry.js +88 -0
  9. package/src/set.js +730 -41
  10. package/dist/compare.d.ts +0 -85
  11. package/dist/compare.d.ts.map +0 -1
  12. package/dist/detect.d.ts +0 -33
  13. package/dist/detect.d.ts.map +0 -1
  14. package/dist/index.d.ts +0 -72
  15. package/dist/index.d.ts.map +0 -1
  16. package/dist/parsers/index.d.ts +0 -5
  17. package/dist/parsers/index.d.ts.map +0 -1
  18. package/dist/parsers/npm.d.ts +0 -109
  19. package/dist/parsers/npm.d.ts.map +0 -1
  20. package/dist/parsers/pnpm/detect.d.ts +0 -136
  21. package/dist/parsers/pnpm/detect.d.ts.map +0 -1
  22. package/dist/parsers/pnpm/index.d.ts +0 -120
  23. package/dist/parsers/pnpm/index.d.ts.map +0 -1
  24. package/dist/parsers/pnpm/internal.d.ts +0 -5
  25. package/dist/parsers/pnpm/internal.d.ts.map +0 -1
  26. package/dist/parsers/pnpm/shrinkwrap.d.ts +0 -129
  27. package/dist/parsers/pnpm/shrinkwrap.d.ts.map +0 -1
  28. package/dist/parsers/pnpm/v5.d.ts +0 -139
  29. package/dist/parsers/pnpm/v5.d.ts.map +0 -1
  30. package/dist/parsers/pnpm/v6plus.d.ts +0 -212
  31. package/dist/parsers/pnpm/v6plus.d.ts.map +0 -1
  32. package/dist/parsers/pnpm.d.ts +0 -2
  33. package/dist/parsers/pnpm.d.ts.map +0 -1
  34. package/dist/parsers/types.d.ts +0 -23
  35. package/dist/parsers/types.d.ts.map +0 -1
  36. package/dist/parsers/yarn-berry.d.ts +0 -154
  37. package/dist/parsers/yarn-berry.d.ts.map +0 -1
  38. package/dist/parsers/yarn-classic.d.ts +0 -110
  39. package/dist/parsers/yarn-classic.d.ts.map +0 -1
  40. package/dist/result.d.ts +0 -12
  41. package/dist/result.d.ts.map +0 -1
  42. package/dist/set.d.ts +0 -189
  43. package/dist/set.d.ts.map +0 -1
@@ -1,110 +0,0 @@
1
- /**
2
- * !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
3
- * !! WARNING: DO NOT MODIFY THIS FUNCTION !!
4
- * !! AI AGENTS (Claude, Copilot, etc.): DO NOT TOUCH THIS CODE !!
5
- * !! !!
6
- * !! This is YARN LOCKFILE KEY parsing, NOT npm spec parsing. !!
7
- * !! Yarn lockfile keys have their own format: !!
8
- * !! - Multiple comma-separated entries: "pkg@^1.0.0, pkg@^2.0.0" !!
9
- * !! - npm: aliasing protocol: "alias@npm:actual@^1.0.0" !!
10
- * !! !!
11
- * !! npm-package-arg (npa) does NOT understand these formats. !!
12
- * !! Do not "improve" this with npa. !!
13
- * !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
14
- *
15
- * Extract package name from yarn classic key.
16
- *
17
- * @param {string} key - Lockfile entry key
18
- * @returns {string} Package name
19
- *
20
- * @example
21
- * // Simple unscoped package with semver range
22
- * parseLockfileKey('lodash@^4.17.21')
23
- * // => 'lodash'
24
- *
25
- * @example
26
- * // Scoped package
27
- * parseLockfileKey('@babel/core@^7.0.0')
28
- * // => '@babel/core'
29
- *
30
- * @example
31
- * // Multiple version ranges (comma-separated) - takes first entry
32
- * parseLockfileKey('lodash@^4.17.21, lodash@^4.0.0')
33
- * // => 'lodash'
34
- *
35
- * @example
36
- * // Multiple ranges for scoped package
37
- * parseLockfileKey('@types/node@^18.0.0, @types/node@^20.0.0')
38
- * // => '@types/node'
39
- *
40
- * @example
41
- * // npm: alias protocol - returns the ALIAS name
42
- * parseLockfileKey('@babel/traverse--for-generate-function-map@npm:@babel/traverse@^7.25.3')
43
- * // => '@babel/traverse--for-generate-function-map'
44
- *
45
- * @example
46
- * // Unscoped alias
47
- * parseLockfileKey('string-width-cjs@npm:string-width@^4.2.0')
48
- * // => 'string-width-cjs'
49
- *
50
- * @example
51
- * // Exact version
52
- * parseLockfileKey('typescript@5.3.3')
53
- * // => 'typescript'
54
- *
55
- * @example
56
- * // Git URL specifier
57
- * parseLockfileKey('my-lib@github:user/repo#v1.0.0')
58
- * // => 'my-lib'
59
- *
60
- * @example
61
- * // Tarball URL
62
- * parseLockfileKey('custom-pkg@https://example.com/pkg.tgz')
63
- * // => 'custom-pkg'
64
- *
65
- * @example
66
- * // Package with prerelease version
67
- * parseLockfileKey('@next/env@^14.0.0-canary.0')
68
- * // => '@next/env'
69
- *
70
- * @example
71
- * // Package without @ (bare name, edge case)
72
- * parseLockfileKey('lodash')
73
- * // => 'lodash'
74
- *
75
- * @example
76
- * // Deeply scoped alias pointing to scoped package
77
- * parseLockfileKey('@myorg/my-alias@npm:@original/package@^1.0.0')
78
- * // => '@myorg/my-alias'
79
- */
80
- export function parseLockfileKey(key: string): string;
81
- /**
82
- * Parse yarn.lock v1 (classic)
83
- * @param {string | object} input - Lockfile content string or pre-parsed object
84
- * @param {Object} [_options] - Parser options (unused, reserved for future use)
85
- * @returns {Generator<Dependency>}
86
- */
87
- export function fromYarnClassicLock(input: string | object, _options?: Object): Generator<Dependency>;
88
- /** @typedef {import('./types.js').Dependency} Dependency */
89
- /**
90
- * @typedef {Object} YarnClassicParseResult
91
- * @property {'success' | 'merge' | 'conflict'} type - Parse result type
92
- * @property {Record<string, any>} object - Parsed lockfile object
93
- */
94
- /**
95
- * The yarn classic parse function (handles CJS/ESM interop)
96
- * @type {(content: string) => YarnClassicParseResult}
97
- */
98
- export const parseYarnClassic: (content: string) => YarnClassicParseResult;
99
- export type Dependency = import("./types.js").Dependency;
100
- export type YarnClassicParseResult = {
101
- /**
102
- * - Parse result type
103
- */
104
- type: "success" | "merge" | "conflict";
105
- /**
106
- * - Parsed lockfile object
107
- */
108
- object: Record<string, any>;
109
- };
110
- //# sourceMappingURL=yarn-classic.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"yarn-classic.d.ts","sourceRoot":"","sources":["../../src/parsers/yarn-classic.js"],"names":[],"mappings":"AAgBA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8EG;AACH,sCA/DW,MAAM,GACJ,MAAM,CA8FlB;AAED;;;;;GAKG;AACH,2CAJW,MAAM,GAAG,MAAM,aACf,MAAM,GACJ,SAAS,CAAC,UAAU,CAAC,CAgCjC;AAnKD,4DAA4D;AAE5D;;;;GAIG;AAEH;;;GAGG;AACH,+BAFU,CAAC,OAAO,EAAE,MAAM,KAAK,sBAAsB,CAE6B;yBAZpE,OAAO,YAAY,EAAE,UAAU;;;;;UAI/B,SAAS,GAAG,OAAO,GAAG,UAAU;;;;YAChC,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC"}
package/dist/result.d.ts DELETED
@@ -1,12 +0,0 @@
1
- export function Ok<T>(value: T): OkResult<T>;
2
- export function Err(error: Error | string): ErrResult;
3
- export type OkResult<T> = {
4
- ok: true;
5
- value: T;
6
- };
7
- export type ErrResult = {
8
- ok: false;
9
- error: Error;
10
- };
11
- export type Result<T> = OkResult<T> | ErrResult;
12
- //# sourceMappingURL=result.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"result.d.ts","sourceRoot":"","sources":["../src/result.js"],"names":[],"mappings":"AAwBO,mBAJM,CAAC,SACH,CAAC,GACC,QAAQ,CAAC,CAAC,CAAC,CAEwB;AAOzC,2BAHI,KAAK,GAAG,MAAM,GACZ,SAAS,CAKpB;qBAjCW,CAAC;QAEA,IAAI;WACJ,CAAC;;;QAKD,KAAK;WACL,KAAK;;mBAIN,CAAC,IACD,QAAQ,CAAC,CAAC,CAAC,GAAG,SAAS"}
package/dist/set.d.ts DELETED
@@ -1,189 +0,0 @@
1
- /**
2
- * A Set-like container for lockfile dependencies.
3
- *
4
- * Identity is determined by name@version. Two dependencies with the same
5
- * name and version are considered equal, regardless of integrity or resolved URL.
6
- *
7
- * All set operations return new FlatlockSet instances (immutable pattern).
8
- *
9
- * NOTE: Set operations (union, intersection, difference) return sets that
10
- * cannot use dependenciesOf() because they lack lockfile traversal data.
11
- *
12
- * @example
13
- * const set = await FlatlockSet.fromPath('./package-lock.json');
14
- * console.log(set.size); // 1234
15
- * console.log(set.has('lodash@4.17.21')); // true
16
- *
17
- * // Get dependencies for a specific workspace
18
- * const pkg = JSON.parse(await readFile('./packages/foo/package.json'));
19
- * const subset = set.dependenciesOf(pkg, { workspacePath: 'packages/foo' });
20
- *
21
- * // Set operations
22
- * const other = await FlatlockSet.fromPath('./other-lock.json');
23
- * const common = set.intersection(other);
24
- */
25
- export class FlatlockSet {
26
- /**
27
- * Create FlatlockSet from lockfile path (auto-detect type)
28
- * @param {string} path - Path to lockfile
29
- * @param {FromStringOptions} [options] - Parser options
30
- * @returns {Promise<FlatlockSet>}
31
- */
32
- static fromPath(path: string, options?: FromStringOptions): Promise<FlatlockSet>;
33
- /**
34
- * Create FlatlockSet from lockfile string
35
- * @param {string} content - Lockfile content
36
- * @param {FromStringOptions} [options] - Parser options
37
- * @returns {FlatlockSet}
38
- */
39
- static fromString(content: string, options?: FromStringOptions): FlatlockSet;
40
- /**
41
- * Parse lockfile once, returning both processed deps and raw data
42
- * @param {string} content
43
- * @param {LockfileType} type
44
- * @param {FromStringOptions} options
45
- * @returns {{ deps: Map<string, Dependency>, packages: LockfilePackages, importers: LockfileImporters | null }}
46
- */
47
- static "__#private@#parseAll"(content: string, type: LockfileType, options: FromStringOptions): {
48
- deps: Map<string, Dependency>;
49
- packages: LockfilePackages;
50
- importers: LockfileImporters | null;
51
- };
52
- /**
53
- * @param {symbol} internal - Must be INTERNAL symbol
54
- * @param {Map<string, Dependency>} deps
55
- * @param {LockfilePackages | null} packages
56
- * @param {LockfileImporters | null} importers
57
- * @param {LockfileType | null} type
58
- */
59
- constructor(internal: symbol, deps: Map<string, Dependency>, packages: LockfilePackages | null, importers: LockfileImporters | null, type: LockfileType | null);
60
- /** @returns {number} */
61
- get size(): number;
62
- /** @returns {LockfileType | null} */
63
- get type(): LockfileType | null;
64
- /** @returns {boolean} */
65
- get canTraverse(): boolean;
66
- /**
67
- * Check if a dependency exists
68
- * @param {string} nameAtVersion - e.g., "lodash@4.17.21"
69
- * @returns {boolean}
70
- */
71
- has(nameAtVersion: string): boolean;
72
- /**
73
- * Get a dependency by name@version
74
- * @param {string} nameAtVersion
75
- * @returns {Dependency | undefined}
76
- */
77
- get(nameAtVersion: string): Dependency | undefined;
78
- /** @returns {IterableIterator<Dependency>} */
79
- values(): IterableIterator<Dependency>;
80
- /** @returns {IterableIterator<string>} */
81
- keys(): IterableIterator<string>;
82
- /** @returns {IterableIterator<[string, Dependency]>} */
83
- entries(): IterableIterator<[string, Dependency]>;
84
- /**
85
- * Execute a callback for each dependency
86
- * @param {(dep: Dependency, key: string, set: FlatlockSet) => void} callback
87
- * @param {any} [thisArg]
88
- */
89
- forEach(callback: (dep: Dependency, key: string, set: FlatlockSet) => void, thisArg?: any): void;
90
- /**
91
- * Union of this set with another
92
- * @param {FlatlockSet} other
93
- * @returns {FlatlockSet}
94
- */
95
- union(other: FlatlockSet): FlatlockSet;
96
- /**
97
- * Intersection of this set with another
98
- * @param {FlatlockSet} other
99
- * @returns {FlatlockSet}
100
- */
101
- intersection(other: FlatlockSet): FlatlockSet;
102
- /**
103
- * Difference: elements in this set but not in other
104
- * @param {FlatlockSet} other
105
- * @returns {FlatlockSet}
106
- */
107
- difference(other: FlatlockSet): FlatlockSet;
108
- /**
109
- * Check if this set is a subset of another
110
- * @param {FlatlockSet} other
111
- * @returns {boolean}
112
- */
113
- isSubsetOf(other: FlatlockSet): boolean;
114
- /**
115
- * Check if this set is a superset of another
116
- * @param {FlatlockSet} other
117
- * @returns {boolean}
118
- */
119
- isSupersetOf(other: FlatlockSet): boolean;
120
- /**
121
- * Check if this set has no elements in common with another
122
- * @param {FlatlockSet} other
123
- * @returns {boolean}
124
- */
125
- isDisjointFrom(other: FlatlockSet): boolean;
126
- /**
127
- * Get transitive dependencies of a package.json
128
- *
129
- * For monorepos, provide workspacePath to get correct resolution.
130
- * Without workspacePath, assumes root package (hoisted deps only).
131
- *
132
- * NOTE: This method is only available on sets created directly from
133
- * fromPath/fromString. Sets created via union/intersection/difference
134
- * cannot use this method (canTraverse will be false).
135
- *
136
- * @param {PackageJson} packageJson - Parsed package.json
137
- * @param {DependenciesOfOptions} [options]
138
- * @returns {FlatlockSet}
139
- * @throws {Error} If called on a set that cannot traverse
140
- */
141
- dependenciesOf(packageJson: PackageJson, options?: DependenciesOfOptions): FlatlockSet;
142
- /**
143
- * Convert to array
144
- * @returns {Dependency[]}
145
- */
146
- toArray(): Dependency[];
147
- /** @returns {IterableIterator<Dependency>} */
148
- [Symbol.iterator](): IterableIterator<Dependency>;
149
- #private;
150
- }
151
- export type Dependency = import("./parsers/npm.js").Dependency;
152
- export type LockfileType = import("./detect.js").LockfileType;
153
- export type DependenciesOfOptions = {
154
- /**
155
- * - Path to workspace (e.g., 'packages/foo')
156
- */
157
- workspacePath?: string;
158
- /**
159
- * - Include devDependencies
160
- */
161
- dev?: boolean;
162
- /**
163
- * - Include optionalDependencies
164
- */
165
- optional?: boolean;
166
- /**
167
- * - Include peerDependencies (default false: peers are provided by consumer)
168
- */
169
- peer?: boolean;
170
- };
171
- export type FromStringOptions = {
172
- /**
173
- * - Path hint for type detection
174
- */
175
- path?: string;
176
- /**
177
- * - Explicit lockfile type
178
- */
179
- type?: LockfileType;
180
- };
181
- export type PackageJson = {
182
- dependencies?: Record<string, string>;
183
- devDependencies?: Record<string, string>;
184
- optionalDependencies?: Record<string, string>;
185
- peerDependencies?: Record<string, string>;
186
- };
187
- export type LockfilePackages = Record<string, any>;
188
- export type LockfileImporters = Record<string, any>;
189
- //# sourceMappingURL=set.d.ts.map
package/dist/set.d.ts.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"set.d.ts","sourceRoot":"","sources":["../src/set.js"],"names":[],"mappings":"AAoDA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH;IAoCE;;;;;OAKG;IACH,sBAJW,MAAM,YACN,iBAAiB,GACf,OAAO,CAAC,WAAW,CAAC,CAKhC;IAED;;;;;OAKG;IACH,2BAJW,MAAM,YACN,iBAAiB,GACf,WAAW,CAgBvB;IAED;;;;;;OAMG;IACH,uCALW,MAAM,QACN,YAAY,WACZ,iBAAiB,GACf;QAAE,IAAI,EAAE,GAAG,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC;QAAC,QAAQ,EAAE,gBAAgB,CAAC;QAAC,SAAS,EAAE,iBAAiB,GAAG,IAAI,CAAA;KAAE,CAmD9G;IA7GD;;;;;;OAMG;IACH,sBANW,MAAM,QACN,GAAG,CAAC,MAAM,EAAE,UAAU,CAAC,YACvB,gBAAgB,GAAG,IAAI,aACvB,iBAAiB,GAAG,IAAI,QACxB,YAAY,GAAG,IAAI,EAa7B;IA6FD,wBAAwB;IACxB,YADc,MAAM,CAGnB;IAED,qCAAqC;IACrC,YADc,YAAY,GAAG,IAAI,CAGhC;IAED,yBAAyB;IACzB,mBADc,OAAO,CAGpB;IAED;;;;OAIG;IACH,mBAHW,MAAM,GACJ,OAAO,CAInB;IAED;;;;OAIG;IACH,mBAHW,MAAM,GACJ,UAAU,GAAG,SAAS,CAIlC;IAOD,8CAA8C;IAC9C,UADc,gBAAgB,CAAC,UAAU,CAAC,CAGzC;IAED,0CAA0C;IAC1C,QADc,gBAAgB,CAAC,MAAM,CAAC,CAGrC;IAED,wDAAwD;IACxD,WADc,gBAAgB,CAAC,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC,CAGnD;IAED;;;;OAIG;IACH,kBAHW,CAAC,GAAG,EAAE,UAAU,EAAE,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,WAAW,KAAK,IAAI,YACxD,GAAG,QAMb;IAED;;;;OAIG;IACH,aAHW,WAAW,GACT,WAAW,CAUvB;IAED;;;;OAIG;IACH,oBAHW,WAAW,GACT,WAAW,CAUvB;IAED;;;;OAIG;IACH,kBAHW,WAAW,GACT,WAAW,CAUvB;IAED;;;;OAIG;IACH,kBAHW,WAAW,GACT,OAAO,CAOnB;IAED;;;;OAIG;IACH,oBAHW,WAAW,GACT,OAAO,CAInB;IAED;;;;OAIG;IACH,sBAHW,WAAW,GACT,OAAO,CAOnB;IAED;;;;;;;;;;;;;;OAcG;IACH,4BALW,WAAW,YACX,qBAAqB,GACnB,WAAW,CA4BvB;IAiOD;;;OAGG;IACH,WAFa,UAAU,EAAE,CAIxB;IA5XD,8CAA8C;IAC9C,qBADc,gBAAgB,CAAC,UAAU,CAAC,CAGzC;;CA0XF;yBA1lBY,OAAO,kBAAkB,EAAE,UAAU;2BACrC,OAAO,aAAa,EAAE,YAAY;;;;;oBAKjC,MAAM;;;;UACN,OAAO;;;;eACP,OAAO;;;;WACP,OAAO;;;;;;WAKP,MAAM;;;;WACN,YAAY;;;mBAKZ,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC;sBACtB,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC;2BACtB,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC;uBACtB,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC;;+BAIvB,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC;gCAInB,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC"}