@lockfile-affected/core 0.1.2 → 0.1.4
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 +65 -31
- package/dist/affected/find-affected-packages.d.ts +19 -0
- package/dist/affected/find-affected-packages.d.ts.map +1 -0
- package/dist/affected/find-affected-packages.js +20 -0
- package/dist/affected/find-affected-packages.js.map +1 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -1
- package/dist/lockfile/detect-lockfile.d.ts +12 -0
- package/dist/lockfile/detect-lockfile.d.ts.map +1 -0
- package/dist/lockfile/detect-lockfile.js +24 -0
- package/dist/lockfile/detect-lockfile.js.map +1 -0
- package/dist/workspace/load-workspace-manifests.d.ts +7 -0
- package/dist/workspace/load-workspace-manifests.d.ts.map +1 -0
- package/dist/workspace/load-workspace-manifests.js +49 -0
- package/dist/workspace/load-workspace-manifests.js.map +1 -0
- package/package.json +2 -1
package/README.md
CHANGED
|
@@ -1,9 +1,6 @@
|
|
|
1
1
|
# @lockfile-affected/core
|
|
2
2
|
|
|
3
|
-
|
|
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,11 +8,58 @@ 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
|
-
### `
|
|
13
|
+
### `findAffectedPackages(options)` — high-level entry point
|
|
14
|
+
|
|
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.
|
|
18
|
+
|
|
19
|
+
```ts
|
|
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
|
+
```
|
|
32
|
+
|
|
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 } from '...';
|
|
40
|
+
|
|
41
|
+
const { format, path } = await detectLockfile(process.cwd(), [
|
|
42
|
+
pnpmLockfileParser,
|
|
43
|
+
npmLockfileParser,
|
|
44
|
+
]);
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
### `loadWorkspaceManifests(dir)`
|
|
17
48
|
|
|
18
|
-
|
|
49
|
+
Recursively walks `dir` and returns all valid `package.json` manifests,
|
|
50
|
+
skipping `node_modules` and malformed files.
|
|
51
|
+
|
|
52
|
+
```ts
|
|
53
|
+
import { loadWorkspaceManifests } from '@lockfile-affected/core';
|
|
54
|
+
|
|
55
|
+
const manifests = await loadWorkspaceManifests(process.cwd());
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
## Low-level API
|
|
59
|
+
|
|
60
|
+
These primitives are useful for building custom pipelines.
|
|
61
|
+
|
|
62
|
+
### `diffLockfileSnapshots(before, after)`
|
|
19
63
|
|
|
20
64
|
```ts
|
|
21
65
|
import { diffLockfileSnapshots } from '@lockfile-affected/core';
|
|
@@ -28,32 +72,15 @@ const diff = diffLockfileSnapshots(snapshotBefore, snapshotAfter);
|
|
|
28
72
|
|
|
29
73
|
### `resolveAffectedPackages(diff, workspaceGraph, filter?)`
|
|
30
74
|
|
|
31
|
-
Returns the names of workspace packages that depend on any package in the diff.
|
|
32
|
-
|
|
33
75
|
```ts
|
|
34
76
|
import { resolveAffectedPackages, ALL_DEPENDENCY_TYPES } from '@lockfile-affected/core';
|
|
35
77
|
|
|
36
78
|
const affected = resolveAffectedPackages(diff, workspaceGraph, ALL_DEPENDENCY_TYPES);
|
|
37
|
-
//
|
|
38
|
-
```
|
|
39
|
-
|
|
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.
|
|
43
|
-
|
|
44
|
-
```ts
|
|
45
|
-
type DependencyFilter = {
|
|
46
|
-
dependencies?: boolean;
|
|
47
|
-
devDependencies?: boolean;
|
|
48
|
-
peerDependencies?: boolean;
|
|
49
|
-
optionalDependencies?: boolean;
|
|
50
|
-
};
|
|
79
|
+
// ReadonlySet<string> of affected package names
|
|
51
80
|
```
|
|
52
81
|
|
|
53
82
|
### `buildWorkspaceGraph(manifests)`
|
|
54
83
|
|
|
55
|
-
Builds a workspace graph from an array of parsed `package.json` objects.
|
|
56
|
-
|
|
57
84
|
```ts
|
|
58
85
|
import { buildWorkspaceGraph } from '@lockfile-affected/core';
|
|
59
86
|
|
|
@@ -64,12 +91,11 @@ const graph = buildWorkspaceGraph(manifests);
|
|
|
64
91
|
## Types
|
|
65
92
|
|
|
66
93
|
```ts
|
|
67
|
-
type
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
changed: ReadonlyMap<string, { from: string; to: string }>;
|
|
94
|
+
type DependencyFilter = {
|
|
95
|
+
dependencies?: boolean;
|
|
96
|
+
devDependencies?: boolean;
|
|
97
|
+
peerDependencies?: boolean;
|
|
98
|
+
optionalDependencies?: boolean;
|
|
73
99
|
};
|
|
74
100
|
|
|
75
101
|
type LockfileParser = {
|
|
@@ -77,6 +103,14 @@ type LockfileParser = {
|
|
|
77
103
|
lockfileNames: readonly string[];
|
|
78
104
|
parse: (content: string) => Promise<LockfileSnapshot>;
|
|
79
105
|
};
|
|
106
|
+
|
|
107
|
+
type LockfileSnapshot = ReadonlyMap<string, string>;
|
|
108
|
+
|
|
109
|
+
type LockfileDiff = {
|
|
110
|
+
added: ReadonlyMap<string, string>;
|
|
111
|
+
removed: ReadonlyMap<string, string>;
|
|
112
|
+
changed: ReadonlyMap<string, { from: string; to: string }>;
|
|
113
|
+
};
|
|
80
114
|
```
|
|
81
115
|
|
|
82
116
|
## Related packages
|
|
@@ -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,EAAwB,KAAK,gBAAgB,EAAE,KAAK,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAMxG,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,EAAE,oBAAoB,EAA8C,MAAM,sBAAsB,CAAC;AACxG,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
|
package/dist/index.d.ts.map
CHANGED
|
@@ -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,12 @@
|
|
|
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
|
+
export declare function detectLockfile(dir: string, parsers: readonly LockfileParser[]): Promise<DetectedLockfile>;
|
|
12
|
+
//# 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;;;;GAIG;AACH,wBAAsB,cAAc,CAClC,GAAG,EAAE,MAAM,EACX,OAAO,EAAE,SAAS,cAAc,EAAE,GACjC,OAAO,CAAC,gBAAgB,CAAC,CAe3B"}
|
|
@@ -0,0 +1,24 @@
|
|
|
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
|
+
export async function detectLockfile(dir, parsers) {
|
|
9
|
+
for (const parser of parsers) {
|
|
10
|
+
for (const filename of parser.lockfileNames) {
|
|
11
|
+
const fullPath = join(dir, filename);
|
|
12
|
+
try {
|
|
13
|
+
await access(fullPath);
|
|
14
|
+
return { path: fullPath, format: parser.format };
|
|
15
|
+
}
|
|
16
|
+
catch {
|
|
17
|
+
// not found, try next
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
const allNames = parsers.flatMap((p) => p.lockfileNames);
|
|
22
|
+
throw new Error(`No lockfile found in ${dir}. Expected one of: ${allNames.join(', ')}`);
|
|
23
|
+
}
|
|
24
|
+
//# 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;;;;GAIG;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,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lockfile-affected/core",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.4",
|
|
4
4
|
"description": "Core diff engine and affected package resolver",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"engines": {
|
|
@@ -24,6 +24,7 @@
|
|
|
24
24
|
"devDependencies": {
|
|
25
25
|
"vitest": "*",
|
|
26
26
|
"@vitest/coverage-v8": "*",
|
|
27
|
+
"@types/node": "*",
|
|
27
28
|
"typescript": "*"
|
|
28
29
|
},
|
|
29
30
|
"scripts": {
|