@lockfile-affected/core 0.1.3 → 0.2.2

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 ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 split
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,9 +1,6 @@
1
1
  # @lockfile-affected/core
2
2
 
3
- Pure diff engine and affected-package resolver for `lockfile-affected`.
4
-
5
- This package contains all domain logic with no I/O. It is format-agnostic —
6
- lockfile parsers live in separate adapter packages.
3
+ Diff engine, affected-package resolver, and programmatic API for `lockfile-affected`.
7
4
 
8
5
  ## Installation
9
6
 
@@ -11,48 +8,79 @@ lockfile parsers live in separate adapter packages.
11
8
  npm install @lockfile-affected/core
12
9
  ```
13
10
 
14
- ## API
11
+ ## Programmatic API
15
12
 
16
- ### `diffLockfileSnapshots(before, after)`
13
+ ### `findAffectedPackages(options)` - high-level entry point
17
14
 
18
- Compares two lockfile snapshots and returns what changed.
15
+ Parses two lockfile snapshots, diffs them, loads workspace manifests from disk,
16
+ and returns the names of affected packages. This is the primary API for
17
+ programmatic use.
19
18
 
20
19
  ```ts
21
- import { diffLockfileSnapshots } from '@lockfile-affected/core';
20
+ import { findAffectedPackages } from '@lockfile-affected/core';
21
+ import { pnpmLockfileParser } from '@lockfile-affected/lockfile-pnpm';
22
+
23
+ const affected = await findAffectedPackages({
24
+ beforeContent: fs.readFileSync('pnpm-lock.yaml.old', 'utf-8'),
25
+ afterContent: fs.readFileSync('pnpm-lock.yaml', 'utf-8'),
26
+ parser: pnpmLockfileParser,
27
+ workspaceRoot: process.cwd(),
28
+ // filter: { dependencies: true, devDependencies: true } - optional
29
+ });
30
+ // ReadonlySet<string> of affected package names
31
+ ```
22
32
 
23
- const diff = diffLockfileSnapshots(snapshotBefore, snapshotAfter);
24
- // diff.added — Map<name, newVersion>
25
- // diff.removed Map<name, oldVersion>
26
- // diff.changed — Map<name, { from, to }>
33
+ ### `detectLockfile(dir, parsers)`
34
+
35
+ Finds the first known lockfile in `dir` by checking each parser's `lockfileNames`.
36
+
37
+ ```ts
38
+ import { detectLockfile } from '@lockfile-affected/core';
39
+ import { pnpmLockfileParser, npmLockfileParser, yarnLockfileParser } from '...';
40
+
41
+ const { format, path } = await detectLockfile(process.cwd(), [
42
+ pnpmLockfileParser,
43
+ npmLockfileParser,
44
+ yarnLockfileParser,
45
+ ]);
27
46
  ```
28
47
 
29
- ### `resolveAffectedPackages(diff, workspaceGraph, filter?)`
48
+ ### `loadWorkspaceManifests(dir)`
30
49
 
31
- Returns the names of workspace packages that depend on any package in the diff.
50
+ Recursively walks `dir` and returns all valid `package.json` manifests,
51
+ skipping `node_modules` and malformed files.
32
52
 
33
53
  ```ts
34
- import { resolveAffectedPackages, ALL_DEPENDENCY_TYPES } from '@lockfile-affected/core';
54
+ import { loadWorkspaceManifests } from '@lockfile-affected/core';
35
55
 
36
- const affected = resolveAffectedPackages(diff, workspaceGraph, ALL_DEPENDENCY_TYPES);
37
- // Set<string> of affected package names
56
+ const manifests = await loadWorkspaceManifests(process.cwd());
38
57
  ```
39
58
 
40
- The optional `filter` is a `DependencyFilter` controlling which dependency types
41
- are considered. Omitting a field (or setting it to `false`) excludes that type.
42
- When omitted entirely, all types are included.
59
+ ## Low-level API
60
+
61
+ These primitives are useful for building custom pipelines.
62
+
63
+ ### `diffLockfileSnapshots(before, after)`
43
64
 
44
65
  ```ts
45
- type DependencyFilter = {
46
- dependencies?: boolean;
47
- devDependencies?: boolean;
48
- peerDependencies?: boolean;
49
- optionalDependencies?: boolean;
50
- };
66
+ import { diffLockfileSnapshots } from '@lockfile-affected/core';
67
+
68
+ const diff = diffLockfileSnapshots(snapshotBefore, snapshotAfter);
69
+ // diff.added - Map<name, newVersion>
70
+ // diff.removed - Map<name, oldVersion>
71
+ // diff.changed - Map<name, { from, to }>
51
72
  ```
52
73
 
53
- ### `buildWorkspaceGraph(manifests)`
74
+ ### `resolveAffectedPackages(diff, workspaceGraph, filter?)`
75
+
76
+ ```ts
77
+ import { resolveAffectedPackages, ALL_DEPENDENCY_TYPES } from '@lockfile-affected/core';
54
78
 
55
- Builds a workspace graph from an array of parsed `package.json` objects.
79
+ const affected = resolveAffectedPackages(diff, workspaceGraph, ALL_DEPENDENCY_TYPES);
80
+ // ReadonlySet<string> of affected package names
81
+ ```
82
+
83
+ ### `buildWorkspaceGraph(manifests)`
56
84
 
57
85
  ```ts
58
86
  import { buildWorkspaceGraph } from '@lockfile-affected/core';
@@ -64,12 +92,11 @@ const graph = buildWorkspaceGraph(manifests);
64
92
  ## Types
65
93
 
66
94
  ```ts
67
- type LockfileSnapshot = ReadonlyMap<string, string>;
68
-
69
- type LockfileDiff = {
70
- added: ReadonlyMap<string, string>;
71
- removed: ReadonlyMap<string, string>;
72
- changed: ReadonlyMap<string, { from: string; to: string }>;
95
+ type DependencyFilter = {
96
+ dependencies?: boolean;
97
+ devDependencies?: boolean;
98
+ peerDependencies?: boolean;
99
+ optionalDependencies?: boolean;
73
100
  };
74
101
 
75
102
  type LockfileParser = {
@@ -77,11 +104,15 @@ type LockfileParser = {
77
104
  lockfileNames: readonly string[];
78
105
  parse: (content: string) => Promise<LockfileSnapshot>;
79
106
  };
80
- ```
81
107
 
82
- ## Related packages
108
+ type LockfileSnapshot = ReadonlyMap<string, string>;
109
+
110
+ type LockfileDiff = {
111
+ added: ReadonlyMap<string, string>;
112
+ removed: ReadonlyMap<string, string>;
113
+ changed: ReadonlyMap<string, { from: string; to: string }>;
114
+ };
115
+ ```
83
116
 
84
- - [`lockfile-affected`](https://www.npmjs.com/package/lockfile-affected) CLI
85
- - [`@lockfile-affected/lockfile-pnpm`](https://www.npmjs.com/package/@lockfile-affected/lockfile-pnpm) — pnpm adapter
86
- - [`@lockfile-affected/lockfile-npm`](https://www.npmjs.com/package/@lockfile-affected/lockfile-npm) — npm adapter
87
- - [`@lockfile-affected/lockfile-yarn`](https://www.npmjs.com/package/@lockfile-affected/lockfile-yarn) — yarn adapter
117
+ For Git-based and CI usage patterns, see the CLI guide:
118
+ `https://github.com/split/lockfile-affected/tree/main/packages/cli#readme`.
@@ -0,0 +1,19 @@
1
+ import { type DependencyFilter, type LockfileParser } from '../types/lockfile.js';
2
+ export type FindAffectedOptions = {
3
+ /** Raw content of the "before" lockfile snapshot */
4
+ readonly beforeContent: string;
5
+ /** Raw content of the "after" lockfile snapshot */
6
+ readonly afterContent: string;
7
+ /** Parser for the lockfile format */
8
+ readonly parser: LockfileParser;
9
+ /** Root directory to search for workspace package.json files */
10
+ readonly workspaceRoot: string;
11
+ /** Which dependency types to consider. When omitted, all types are included. */
12
+ readonly filter?: DependencyFilter;
13
+ };
14
+ /**
15
+ * High-level entry point: parses two lockfile snapshots, diffs them,
16
+ * and returns the names of workspace packages affected by the changes.
17
+ */
18
+ export declare function findAffectedPackages(options: FindAffectedOptions): Promise<ReadonlySet<string>>;
19
+ //# sourceMappingURL=find-affected-packages.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"find-affected-packages.d.ts","sourceRoot":"","sources":["../../src/affected/find-affected-packages.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,gBAAgB,EACrB,KAAK,cAAc,EACpB,MAAM,sBAAsB,CAAC;AAM9B,MAAM,MAAM,mBAAmB,GAAG;IAChC,oDAAoD;IACpD,QAAQ,CAAC,aAAa,EAAE,MAAM,CAAC;IAC/B,mDAAmD;IACnD,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;IAC9B,qCAAqC;IACrC,QAAQ,CAAC,MAAM,EAAE,cAAc,CAAC;IAChC,gEAAgE;IAChE,QAAQ,CAAC,aAAa,EAAE,MAAM,CAAC;IAC/B,gFAAgF;IAChF,QAAQ,CAAC,MAAM,CAAC,EAAE,gBAAgB,CAAC;CACpC,CAAC;AAEF;;;GAGG;AACH,wBAAsB,oBAAoB,CACxC,OAAO,EAAE,mBAAmB,GAC3B,OAAO,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC,CAU9B"}
@@ -0,0 +1,20 @@
1
+ import { ALL_DEPENDENCY_TYPES, } from '../types/lockfile.js';
2
+ import { diffLockfileSnapshots } from '../diff/diff-lockfile-snapshots.js';
3
+ import { resolveAffectedPackages } from './resolve-affected-packages.js';
4
+ import { buildWorkspaceGraph } from '../workspace/build-workspace-graph.js';
5
+ import { loadWorkspaceManifests } from '../workspace/load-workspace-manifests.js';
6
+ /**
7
+ * High-level entry point: parses two lockfile snapshots, diffs them,
8
+ * and returns the names of workspace packages affected by the changes.
9
+ */
10
+ export async function findAffectedPackages(options) {
11
+ const [snapshotBefore, snapshotAfter, manifests] = await Promise.all([
12
+ options.parser.parse(options.beforeContent),
13
+ options.parser.parse(options.afterContent),
14
+ loadWorkspaceManifests(options.workspaceRoot),
15
+ ]);
16
+ const diff = diffLockfileSnapshots(snapshotBefore, snapshotAfter);
17
+ const workspaceGraph = buildWorkspaceGraph(manifests);
18
+ return resolveAffectedPackages(diff, workspaceGraph, options.filter ?? ALL_DEPENDENCY_TYPES);
19
+ }
20
+ //# sourceMappingURL=find-affected-packages.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"find-affected-packages.js","sourceRoot":"","sources":["../../src/affected/find-affected-packages.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,oBAAoB,GAGrB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAE,qBAAqB,EAAE,MAAM,oCAAoC,CAAC;AAC3E,OAAO,EAAE,uBAAuB,EAAE,MAAM,gCAAgC,CAAC;AACzE,OAAO,EAAE,mBAAmB,EAAE,MAAM,uCAAuC,CAAC;AAC5E,OAAO,EAAE,sBAAsB,EAAE,MAAM,0CAA0C,CAAC;AAelF;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,oBAAoB,CACxC,OAA4B;IAE5B,MAAM,CAAC,cAAc,EAAE,aAAa,EAAE,SAAS,CAAC,GAAG,MAAM,OAAO,CAAC,GAAG,CAAC;QACnE,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,OAAO,CAAC,aAAa,CAAC;QAC3C,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,OAAO,CAAC,YAAY,CAAC;QAC1C,sBAAsB,CAAC,OAAO,CAAC,aAAa,CAAC;KAC9C,CAAC,CAAC;IAEH,MAAM,IAAI,GAAG,qBAAqB,CAAC,cAAc,EAAE,aAAa,CAAC,CAAC;IAClE,MAAM,cAAc,GAAG,mBAAmB,CAAC,SAAS,CAAC,CAAC;IACtD,OAAO,uBAAuB,CAAC,IAAI,EAAE,cAAc,EAAE,OAAO,CAAC,MAAM,IAAI,oBAAoB,CAAC,CAAC;AAC/F,CAAC"}
package/dist/index.d.ts CHANGED
@@ -2,6 +2,11 @@ export type { DependencyFilter, DependencyGroups, LockfileDiff, LockfileParser,
2
2
  export { ALL_DEPENDENCY_TYPES } from './types/lockfile.js';
3
3
  export { diffLockfileSnapshots } from './diff/diff-lockfile-snapshots.js';
4
4
  export { resolveAffectedPackages } from './affected/resolve-affected-packages.js';
5
+ export { findAffectedPackages } from './affected/find-affected-packages.js';
6
+ export type { FindAffectedOptions } from './affected/find-affected-packages.js';
5
7
  export { buildWorkspaceGraph } from './workspace/build-workspace-graph.js';
6
8
  export type { PackageManifest } from './workspace/build-workspace-graph.js';
9
+ export { loadWorkspaceManifests } from './workspace/load-workspace-manifests.js';
10
+ export { detectLockfile } from './lockfile/detect-lockfile.js';
11
+ export type { DetectedLockfile } from './lockfile/detect-lockfile.js';
7
12
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EACV,gBAAgB,EAChB,gBAAgB,EAChB,YAAY,EACZ,cAAc,EACd,gBAAgB,EAChB,cAAc,EACd,gBAAgB,GACjB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,oBAAoB,EAAE,MAAM,qBAAqB,CAAC;AAC3D,OAAO,EAAE,qBAAqB,EAAE,MAAM,mCAAmC,CAAC;AAC1E,OAAO,EAAE,uBAAuB,EAAE,MAAM,yCAAyC,CAAC;AAClF,OAAO,EAAE,mBAAmB,EAAE,MAAM,sCAAsC,CAAC;AAC3E,YAAY,EAAE,eAAe,EAAE,MAAM,sCAAsC,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EACV,gBAAgB,EAChB,gBAAgB,EAChB,YAAY,EACZ,cAAc,EACd,gBAAgB,EAChB,cAAc,EACd,gBAAgB,GACjB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,oBAAoB,EAAE,MAAM,qBAAqB,CAAC;AAC3D,OAAO,EAAE,qBAAqB,EAAE,MAAM,mCAAmC,CAAC;AAC1E,OAAO,EAAE,uBAAuB,EAAE,MAAM,yCAAyC,CAAC;AAClF,OAAO,EAAE,oBAAoB,EAAE,MAAM,sCAAsC,CAAC;AAC5E,YAAY,EAAE,mBAAmB,EAAE,MAAM,sCAAsC,CAAC;AAChF,OAAO,EAAE,mBAAmB,EAAE,MAAM,sCAAsC,CAAC;AAC3E,YAAY,EAAE,eAAe,EAAE,MAAM,sCAAsC,CAAC;AAC5E,OAAO,EAAE,sBAAsB,EAAE,MAAM,yCAAyC,CAAC;AACjF,OAAO,EAAE,cAAc,EAAE,MAAM,+BAA+B,CAAC;AAC/D,YAAY,EAAE,gBAAgB,EAAE,MAAM,+BAA+B,CAAC"}
package/dist/index.js CHANGED
@@ -1,5 +1,8 @@
1
1
  export { ALL_DEPENDENCY_TYPES } from './types/lockfile.js';
2
2
  export { diffLockfileSnapshots } from './diff/diff-lockfile-snapshots.js';
3
3
  export { resolveAffectedPackages } from './affected/resolve-affected-packages.js';
4
+ export { findAffectedPackages } from './affected/find-affected-packages.js';
4
5
  export { buildWorkspaceGraph } from './workspace/build-workspace-graph.js';
6
+ export { loadWorkspaceManifests } from './workspace/load-workspace-manifests.js';
7
+ export { detectLockfile } from './lockfile/detect-lockfile.js';
5
8
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AASA,OAAO,EAAE,oBAAoB,EAAE,MAAM,qBAAqB,CAAC;AAC3D,OAAO,EAAE,qBAAqB,EAAE,MAAM,mCAAmC,CAAC;AAC1E,OAAO,EAAE,uBAAuB,EAAE,MAAM,yCAAyC,CAAC;AAClF,OAAO,EAAE,mBAAmB,EAAE,MAAM,sCAAsC,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AASA,OAAO,EAAE,oBAAoB,EAAE,MAAM,qBAAqB,CAAC;AAC3D,OAAO,EAAE,qBAAqB,EAAE,MAAM,mCAAmC,CAAC;AAC1E,OAAO,EAAE,uBAAuB,EAAE,MAAM,yCAAyC,CAAC;AAClF,OAAO,EAAE,oBAAoB,EAAE,MAAM,sCAAsC,CAAC;AAE5E,OAAO,EAAE,mBAAmB,EAAE,MAAM,sCAAsC,CAAC;AAE3E,OAAO,EAAE,sBAAsB,EAAE,MAAM,yCAAyC,CAAC;AACjF,OAAO,EAAE,cAAc,EAAE,MAAM,+BAA+B,CAAC"}
@@ -0,0 +1,14 @@
1
+ import type { LockfileParser } from '../types/lockfile.js';
2
+ export type DetectedLockfile = {
3
+ readonly path: string;
4
+ readonly format: string;
5
+ };
6
+ /**
7
+ * Finds the first known lockfile in `dir` by checking each parser's `lockfileNames`.
8
+ * Returns the absolute path and the format name from the matching parser.
9
+ * Throws if no lockfile is found.
10
+ *
11
+ * Supports: pnpm, npm, yarn, and bun lockfile formats.
12
+ */
13
+ export declare function detectLockfile(dir: string, parsers: readonly LockfileParser[]): Promise<DetectedLockfile>;
14
+ //# sourceMappingURL=detect-lockfile.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"detect-lockfile.d.ts","sourceRoot":"","sources":["../../src/lockfile/detect-lockfile.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAE3D,MAAM,MAAM,gBAAgB,GAAG;IAC7B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;CACzB,CAAC;AAEF;;;;;;GAMG;AACH,wBAAsB,cAAc,CAClC,GAAG,EAAE,MAAM,EACX,OAAO,EAAE,SAAS,cAAc,EAAE,GACjC,OAAO,CAAC,gBAAgB,CAAC,CAe3B"}
@@ -0,0 +1,26 @@
1
+ import { access } from 'node:fs/promises';
2
+ import { join } from 'node:path';
3
+ /**
4
+ * Finds the first known lockfile in `dir` by checking each parser's `lockfileNames`.
5
+ * Returns the absolute path and the format name from the matching parser.
6
+ * Throws if no lockfile is found.
7
+ *
8
+ * Supports: pnpm, npm, yarn, and bun lockfile formats.
9
+ */
10
+ export async function detectLockfile(dir, parsers) {
11
+ for (const parser of parsers) {
12
+ for (const filename of parser.lockfileNames) {
13
+ const fullPath = join(dir, filename);
14
+ try {
15
+ await access(fullPath);
16
+ return { path: fullPath, format: parser.format };
17
+ }
18
+ catch {
19
+ // not found, try next
20
+ }
21
+ }
22
+ }
23
+ const allNames = parsers.flatMap((p) => p.lockfileNames);
24
+ throw new Error(`No lockfile found in ${dir}. Expected one of: ${allNames.join(', ')}`);
25
+ }
26
+ //# sourceMappingURL=detect-lockfile.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"detect-lockfile.js","sourceRoot":"","sources":["../../src/lockfile/detect-lockfile.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAC1C,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAQjC;;;;;;GAMG;AACH,MAAM,CAAC,KAAK,UAAU,cAAc,CAClC,GAAW,EACX,OAAkC;IAElC,KAAK,MAAM,MAAM,IAAI,OAAO,EAAE,CAAC;QAC7B,KAAK,MAAM,QAAQ,IAAI,MAAM,CAAC,aAAa,EAAE,CAAC;YAC5C,MAAM,QAAQ,GAAG,IAAI,CAAC,GAAG,EAAE,QAAQ,CAAC,CAAC;YACrC,IAAI,CAAC;gBACH,MAAM,MAAM,CAAC,QAAQ,CAAC,CAAC;gBACvB,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,CAAC;YACnD,CAAC;YAAC,MAAM,CAAC;gBACP,sBAAsB;YACxB,CAAC;QACH,CAAC;IACH,CAAC;IAED,MAAM,QAAQ,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,aAAa,CAAC,CAAC;IACzD,MAAM,IAAI,KAAK,CAAC,wBAAwB,GAAG,sBAAsB,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;AAC1F,CAAC"}
@@ -0,0 +1,7 @@
1
+ import type { PackageManifest } from './build-workspace-graph.js';
2
+ /**
3
+ * Recursively walks `dir` and returns all valid package.json manifests found,
4
+ * skipping `node_modules` directories and malformed files.
5
+ */
6
+ export declare function loadWorkspaceManifests(dir: string): Promise<PackageManifest[]>;
7
+ //# sourceMappingURL=load-workspace-manifests.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"load-workspace-manifests.d.ts","sourceRoot":"","sources":["../../src/workspace/load-workspace-manifests.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAC;AAElE;;;GAGG;AACH,wBAAsB,sBAAsB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,eAAe,EAAE,CAAC,CAIpF"}
@@ -0,0 +1,49 @@
1
+ import { readdir, readFile } from 'node:fs/promises';
2
+ import { join } from 'node:path';
3
+ /**
4
+ * Recursively walks `dir` and returns all valid package.json manifests found,
5
+ * skipping `node_modules` directories and malformed files.
6
+ */
7
+ export async function loadWorkspaceManifests(dir) {
8
+ const manifests = [];
9
+ await collectManifests(dir, manifests);
10
+ return manifests;
11
+ }
12
+ async function collectManifests(dir, manifests) {
13
+ let entries;
14
+ try {
15
+ entries = await readdir(dir, { withFileTypes: true });
16
+ }
17
+ catch {
18
+ return;
19
+ }
20
+ for (const entry of entries) {
21
+ if (entry.name === 'node_modules')
22
+ continue;
23
+ const fullPath = join(dir, entry.name);
24
+ if (entry.isDirectory()) {
25
+ await collectManifests(fullPath, manifests);
26
+ }
27
+ else if (entry.isFile() && entry.name === 'package.json') {
28
+ try {
29
+ const content = await readFile(fullPath, 'utf-8');
30
+ const parsed = JSON.parse(content);
31
+ if (isPackageManifest(parsed)) {
32
+ manifests.push(parsed);
33
+ }
34
+ }
35
+ catch {
36
+ // skip malformed package.json files
37
+ }
38
+ }
39
+ }
40
+ }
41
+ function isPackageManifest(value) {
42
+ if (typeof value !== 'object' || value === null)
43
+ return false;
44
+ const obj = value;
45
+ if ('name' in obj && typeof obj['name'] !== 'string')
46
+ return false;
47
+ return true;
48
+ }
49
+ //# sourceMappingURL=load-workspace-manifests.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"load-workspace-manifests.js","sourceRoot":"","sources":["../../src/workspace/load-workspace-manifests.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AACrD,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAGjC;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,sBAAsB,CAAC,GAAW;IACtD,MAAM,SAAS,GAAsB,EAAE,CAAC;IACxC,MAAM,gBAAgB,CAAC,GAAG,EAAE,SAAS,CAAC,CAAC;IACvC,OAAO,SAAS,CAAC;AACnB,CAAC;AAED,KAAK,UAAU,gBAAgB,CAAC,GAAW,EAAE,SAA4B;IACvE,IAAI,OAAO,CAAC;IACZ,IAAI,CAAC;QACH,OAAO,GAAG,MAAM,OAAO,CAAC,GAAG,EAAE,EAAE,aAAa,EAAE,IAAI,EAAE,CAAC,CAAC;IACxD,CAAC;IAAC,MAAM,CAAC;QACP,OAAO;IACT,CAAC;IAED,KAAK,MAAM,KAAK,IAAI,OAAO,EAAE,CAAC;QAC5B,IAAI,KAAK,CAAC,IAAI,KAAK,cAAc;YAAE,SAAS;QAE5C,MAAM,QAAQ,GAAG,IAAI,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,CAAC,CAAC;QAEvC,IAAI,KAAK,CAAC,WAAW,EAAE,EAAE,CAAC;YACxB,MAAM,gBAAgB,CAAC,QAAQ,EAAE,SAAS,CAAC,CAAC;QAC9C,CAAC;aAAM,IAAI,KAAK,CAAC,MAAM,EAAE,IAAI,KAAK,CAAC,IAAI,KAAK,cAAc,EAAE,CAAC;YAC3D,IAAI,CAAC;gBACH,MAAM,OAAO,GAAG,MAAM,QAAQ,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;gBAClD,MAAM,MAAM,GAAY,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;gBAC5C,IAAI,iBAAiB,CAAC,MAAM,CAAC,EAAE,CAAC;oBAC9B,SAAS,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;gBACzB,CAAC;YACH,CAAC;YAAC,MAAM,CAAC;gBACP,oCAAoC;YACtC,CAAC;QACH,CAAC;IACH,CAAC;AACH,CAAC;AAED,SAAS,iBAAiB,CAAC,KAAc;IACvC,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI;QAAE,OAAO,KAAK,CAAC;IAC9D,MAAM,GAAG,GAAG,KAAgC,CAAC;IAC7C,IAAI,MAAM,IAAI,GAAG,IAAI,OAAO,GAAG,CAAC,MAAM,CAAC,KAAK,QAAQ;QAAE,OAAO,KAAK,CAAC;IACnE,OAAO,IAAI,CAAC;AACd,CAAC"}
package/package.json CHANGED
@@ -1,7 +1,12 @@
1
1
  {
2
2
  "name": "@lockfile-affected/core",
3
- "version": "0.1.3",
3
+ "version": "0.2.2",
4
4
  "description": "Core diff engine and affected package resolver",
5
+ "license": "MIT",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "https://github.com/split/lockfile-affected"
9
+ },
5
10
  "type": "module",
6
11
  "engines": {
7
12
  "node": ">=18"
@@ -11,7 +16,8 @@
11
16
  "README.md"
12
17
  ],
13
18
  "publishConfig": {
14
- "access": "public"
19
+ "access": "public",
20
+ "provenance": true
15
21
  },
16
22
  "main": "./dist/index.js",
17
23
  "types": "./dist/index.d.ts",
@@ -24,6 +30,7 @@
24
30
  "devDependencies": {
25
31
  "vitest": "*",
26
32
  "@vitest/coverage-v8": "*",
33
+ "@types/node": "*",
27
34
  "typescript": "*"
28
35
  },
29
36
  "scripts": {