vouchington-tooling 0.78.0 → 0.78.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/dist/dependency-license-policy/assert-command.d.mts +2 -0
- package/dist/dependency-license-policy/assert-command.mjs +10 -0
- package/dist/dependency-license-policy/collect.d.mts +8 -1
- package/dist/dependency-license-policy/collect.mjs +14 -12
- package/dist/dependency-license-policy/resolve-unknown-licenses.d.mts +9 -0
- package/dist/dependency-license-policy/resolve-unknown-licenses.mjs +93 -0
- package/dist/dependency-license-policy/workspace.d.mts +17 -7
- package/dist/dependency-license-policy/workspace.mjs +18 -7
- package/package.json +2 -2
- package/scripts/__pycache__/run_bounded_process.cpython-314.pyc +0 -0
- package/scripts/__pycache__/run_bounded_process.cpython-312.pyc +0 -0
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
function commandFailureOutput(result) {
|
|
2
|
+
return result.stderr.trim() || result.stdout.trim();
|
|
3
|
+
}
|
|
4
|
+
export function assertCommandSucceeded(label, result) {
|
|
5
|
+
if (result.error)
|
|
6
|
+
throw result.error;
|
|
7
|
+
if (result.status !== 0) {
|
|
8
|
+
throw new Error(`${label} exited with status ${String(result.status)}: ${commandFailureOutput(result)}`);
|
|
9
|
+
}
|
|
10
|
+
}
|
|
@@ -6,5 +6,12 @@ export interface CollectPnpmLicenseReportOptions {
|
|
|
6
6
|
readonly prepareWorkspace?: (repoRoot: string, lockfileSource: string, workspaceSource: string) => PnpmLicenseAuditWorkspace;
|
|
7
7
|
readonly readFile?: (path: string, encoding: 'utf8') => string;
|
|
8
8
|
}
|
|
9
|
-
/**
|
|
9
|
+
/**
|
|
10
|
+
* Collects licenses for every platform represented in a pnpm lockfile.
|
|
11
|
+
*
|
|
12
|
+
* Only the current platform is fetched, because fetching every platform binary can exceed the disk
|
|
13
|
+
* quota of a temporary directory. The workspace then switches to the all-platform configuration so
|
|
14
|
+
* `pnpm licenses list` reports the full package set. pnpm reports packages missing from the store
|
|
15
|
+
* as `Unknown`, and those are resolved from the registry with `pnpm view`.
|
|
16
|
+
*/
|
|
10
17
|
export declare function collectPnpmLicenseReport(repoRoot: string, options?: CollectPnpmLicenseReportOptions): Promise<PnpmLicenseReport>;
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import { readFileSync } from 'node:fs';
|
|
2
2
|
import { join } from 'node:path';
|
|
3
|
+
import { assertCommandSucceeded } from "./assert-command.mjs";
|
|
3
4
|
import { withAuditSignalCleanup } from "./audit-signals.mjs";
|
|
4
5
|
import { ensurePrivateLicenseAuditStore } from "./audit-store.mjs";
|
|
5
6
|
import { executePnpm } from "./execute-pnpm.mjs";
|
|
6
7
|
import { parsePnpmLicenseReport } from "./report.mjs";
|
|
8
|
+
import { resolveUnknownLicenses } from "./resolve-unknown-licenses.mjs";
|
|
7
9
|
import { preparePnpmLicenseAuditWorkspace } from "./workspace.mjs";
|
|
8
10
|
const DEFAULT_OPTIONS = {
|
|
9
11
|
ensureStore: ensurePrivateLicenseAuditStore,
|
|
@@ -11,17 +13,14 @@ const DEFAULT_OPTIONS = {
|
|
|
11
13
|
prepareWorkspace: preparePnpmLicenseAuditWorkspace,
|
|
12
14
|
readFile: readFileSync,
|
|
13
15
|
};
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
/** Collects licenses for every platform represented in a pnpm lockfile. */
|
|
16
|
+
/**
|
|
17
|
+
* Collects licenses for every platform represented in a pnpm lockfile.
|
|
18
|
+
*
|
|
19
|
+
* Only the current platform is fetched, because fetching every platform binary can exceed the disk
|
|
20
|
+
* quota of a temporary directory. The workspace then switches to the all-platform configuration so
|
|
21
|
+
* `pnpm licenses list` reports the full package set. pnpm reports packages missing from the store
|
|
22
|
+
* as `Unknown`, and those are resolved from the registry with `pnpm view`.
|
|
23
|
+
*/
|
|
25
24
|
export async function collectPnpmLicenseReport(repoRoot, options = {}) {
|
|
26
25
|
const { ensureStore, execute, prepareWorkspace, readFile } = { ...DEFAULT_OPTIONS, ...options };
|
|
27
26
|
const auditWorkspace = prepareWorkspace(repoRoot, readFile(join(repoRoot, 'pnpm-lock.yaml'), 'utf8'), readFile(join(repoRoot, 'pnpm-workspace.yaml'), 'utf8'));
|
|
@@ -32,15 +31,18 @@ export async function collectPnpmLicenseReport(repoRoot, options = {}) {
|
|
|
32
31
|
const commandOptions = { cwd: auditWorkspace.cwd, encoding: 'utf8', signal };
|
|
33
32
|
const fetchResult = await execute('pnpm', [storeConfig, 'fetch', '--ignore-scripts'], commandOptions);
|
|
34
33
|
assertCommandSucceeded('pnpm fetch', fetchResult);
|
|
34
|
+
auditWorkspace.useListingWorkspace();
|
|
35
35
|
const result = await execute('pnpm', [storeConfig, 'licenses', 'list', '--json'], commandOptions);
|
|
36
36
|
assertCommandSucceeded('pnpm licenses list --json', result);
|
|
37
|
+
let report;
|
|
37
38
|
try {
|
|
38
|
-
|
|
39
|
+
report = parsePnpmLicenseReport(JSON.parse(result.stdout));
|
|
39
40
|
}
|
|
40
41
|
catch (error) {
|
|
41
42
|
throw new Error(`pnpm licenses list --json produced unparseable output: ${String(error)}`, {
|
|
42
43
|
cause: error,
|
|
43
44
|
});
|
|
44
45
|
}
|
|
46
|
+
return resolveUnknownLicenses(report, execute, commandOptions);
|
|
45
47
|
});
|
|
46
48
|
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { PnpmExecutor, PnpmLicenseReport } from './types.mts';
|
|
2
|
+
type CommandOptions = Parameters<PnpmExecutor>[2];
|
|
3
|
+
/**
|
|
4
|
+
* Resolves `Unknown` entries from the registry manifest. pnpm reports every package missing from the
|
|
5
|
+
* store, such as off-platform optional packages, as `Unknown`, so each is looked up with
|
|
6
|
+
* `pnpm view`. Entries whose manifest has no usable license stay `Unknown`.
|
|
7
|
+
*/
|
|
8
|
+
export declare function resolveUnknownLicenses(report: PnpmLicenseReport, execute: PnpmExecutor, options: CommandOptions): Promise<PnpmLicenseReport>;
|
|
9
|
+
export {};
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import { assertCommandSucceeded } from "./assert-command.mjs";
|
|
2
|
+
const UNKNOWN_LICENSE = 'Unknown';
|
|
3
|
+
const VIEW_CONCURRENCY = 8;
|
|
4
|
+
// A blank or literal `Unknown` manifest license identifies nothing, so the entry stays Unknown.
|
|
5
|
+
function usableLicense(license) {
|
|
6
|
+
if (typeof license !== 'string')
|
|
7
|
+
return undefined;
|
|
8
|
+
const trimmed = license.trim();
|
|
9
|
+
return trimmed === '' || trimmed === UNKNOWN_LICENSE ? undefined : trimmed;
|
|
10
|
+
}
|
|
11
|
+
/** Reads the license from `pnpm view <spec> license --json` output, or undefined if unusable. */
|
|
12
|
+
function parseViewedLicense(stdout) {
|
|
13
|
+
if (stdout.trim() === '')
|
|
14
|
+
return undefined;
|
|
15
|
+
const value = JSON.parse(stdout);
|
|
16
|
+
if (typeof value === 'object' && value !== null && !Array.isArray(value)) {
|
|
17
|
+
return usableLicense(value.type);
|
|
18
|
+
}
|
|
19
|
+
return usableLicense(value);
|
|
20
|
+
}
|
|
21
|
+
async function viewLicense(execute, spec, options) {
|
|
22
|
+
const label = `pnpm view ${spec} license --json`;
|
|
23
|
+
const result = await execute('pnpm', ['view', spec, 'license', '--json'], options);
|
|
24
|
+
assertCommandSucceeded(label, result);
|
|
25
|
+
try {
|
|
26
|
+
return parseViewedLicense(result.stdout);
|
|
27
|
+
}
|
|
28
|
+
catch (error) {
|
|
29
|
+
throw new Error(`${label} produced unparseable output: ${String(error)}`, { cause: error });
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
async function runPool(items, worker) {
|
|
33
|
+
let next = 0;
|
|
34
|
+
let failed = false;
|
|
35
|
+
const lane = async () => {
|
|
36
|
+
while (!failed && next < items.length) {
|
|
37
|
+
const item = items[next++];
|
|
38
|
+
try {
|
|
39
|
+
await worker(item);
|
|
40
|
+
}
|
|
41
|
+
catch (error) {
|
|
42
|
+
failed = true;
|
|
43
|
+
throw error;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
await Promise.all(Array.from({ length: Math.min(VIEW_CONCURRENCY, items.length) }, lane));
|
|
48
|
+
}
|
|
49
|
+
function addToGroup(report, license, name, version) {
|
|
50
|
+
const group = (report[license] ??= []);
|
|
51
|
+
const index = group.findIndex((entry) => entry.name === name);
|
|
52
|
+
const existing = group[index];
|
|
53
|
+
if (existing)
|
|
54
|
+
group[index] = { name, versions: [...(existing.versions ?? []), version] };
|
|
55
|
+
else
|
|
56
|
+
group.push({ name, versions: [version] });
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Resolves `Unknown` entries from the registry manifest. pnpm reports every package missing from the
|
|
60
|
+
* store, such as off-platform optional packages, as `Unknown`, so each is looked up with
|
|
61
|
+
* `pnpm view`. Entries whose manifest has no usable license stay `Unknown`.
|
|
62
|
+
*/
|
|
63
|
+
export async function resolveUnknownLicenses(report, execute, options) {
|
|
64
|
+
const unknown = report[UNKNOWN_LICENSE];
|
|
65
|
+
if (!unknown)
|
|
66
|
+
return report;
|
|
67
|
+
const targets = unknown.flatMap((entry) => (entry.versions ?? []).map((version) => ({ name: entry.name, version })));
|
|
68
|
+
const resolved = new Map();
|
|
69
|
+
await runPool(targets, async ({ name, version }) => {
|
|
70
|
+
const license = await viewLicense(execute, `${name}@${version}`, options);
|
|
71
|
+
if (license !== undefined)
|
|
72
|
+
resolved.set(`${name}@${version}`, license);
|
|
73
|
+
});
|
|
74
|
+
const remaining = [];
|
|
75
|
+
for (const entry of unknown) {
|
|
76
|
+
const stillUnknown = (entry.versions ?? []).filter((version) => {
|
|
77
|
+
const license = resolved.get(`${entry.name}@${version}`);
|
|
78
|
+
if (license === undefined)
|
|
79
|
+
return true;
|
|
80
|
+
addToGroup(report, license, entry.name, version);
|
|
81
|
+
return false;
|
|
82
|
+
});
|
|
83
|
+
if (stillUnknown.length > 0)
|
|
84
|
+
remaining.push({ name: entry.name, versions: stillUnknown });
|
|
85
|
+
else if (!entry.versions?.length)
|
|
86
|
+
remaining.push(entry);
|
|
87
|
+
}
|
|
88
|
+
if (remaining.length > 0)
|
|
89
|
+
report[UNKNOWN_LICENSE] = remaining;
|
|
90
|
+
else
|
|
91
|
+
delete report[UNKNOWN_LICENSE];
|
|
92
|
+
return report;
|
|
93
|
+
}
|
|
@@ -2,19 +2,29 @@ import { type LicenseAuditWorkspaceOptions } from './audit-directory.mts';
|
|
|
2
2
|
export interface PnpmLicenseAuditWorkspace {
|
|
3
3
|
readonly cleanup: () => void;
|
|
4
4
|
readonly cwd: string;
|
|
5
|
+
/** Rewrites `pnpm-workspace.yaml` to support every platform in the lockfile, for listing. */
|
|
6
|
+
readonly useListingWorkspace: () => void;
|
|
5
7
|
}
|
|
6
|
-
/** The rendered
|
|
8
|
+
/** The rendered audit files: one lockfile and the `pnpm-workspace.yaml` for each audit phase. */
|
|
7
9
|
export interface PnpmLicenseAuditFiles {
|
|
10
|
+
/** Supports only the current platform, so `pnpm fetch` stays within the disk quota. */
|
|
11
|
+
readonly fetchWorkspace: string;
|
|
8
12
|
readonly lockfile: string;
|
|
9
|
-
|
|
13
|
+
/** Supports every platform in the lockfile, so `pnpm licenses list` reports every package. */
|
|
14
|
+
readonly listingWorkspace: string;
|
|
10
15
|
}
|
|
11
16
|
/**
|
|
12
|
-
* Renders the audit copies of `pnpm-lock.yaml` and `pnpm-workspace.yaml`
|
|
13
|
-
* every package in the lockfile, including optional ones that don't match the host.
|
|
17
|
+
* Renders the audit copies of `pnpm-lock.yaml` and the two `pnpm-workspace.yaml` variants.
|
|
14
18
|
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
19
|
+
* Fetching every platform binary in a lockfile can need several times the disk of the current
|
|
20
|
+
* platform alone and exceed the quota of the temporary directory. The fetch workspace therefore
|
|
21
|
+
* supports only the `current` platform. pnpm reports every package missing from the store as
|
|
22
|
+
* Unknown, so the listing workspace supports every `os`, `cpu`, and `libc` in the lockfile and
|
|
23
|
+
* `pnpm licenses list` covers the whole graph, with off-platform licenses resolved from the
|
|
24
|
+
* registry afterwards.
|
|
25
|
+
*
|
|
26
|
+
* The lockfile drops every `engines` constraint because pnpm 12's `fetch` ignores `force` and skips
|
|
27
|
+
* an optional package whose `engines` exclude the running Node.js.
|
|
18
28
|
*/
|
|
19
29
|
export declare function renderPnpmLicenseAuditFiles(lockfileSource: string, workspaceSource: string, paths: {
|
|
20
30
|
lockfile: string;
|
|
@@ -48,12 +48,17 @@ function collectSupportedArchitectures(packages, lockfilePath) {
|
|
|
48
48
|
return supportedArchitectures;
|
|
49
49
|
}
|
|
50
50
|
/**
|
|
51
|
-
* Renders the audit copies of `pnpm-lock.yaml` and `pnpm-workspace.yaml`
|
|
52
|
-
* every package in the lockfile, including optional ones that don't match the host.
|
|
51
|
+
* Renders the audit copies of `pnpm-lock.yaml` and the two `pnpm-workspace.yaml` variants.
|
|
53
52
|
*
|
|
54
|
-
*
|
|
55
|
-
*
|
|
56
|
-
*
|
|
53
|
+
* Fetching every platform binary in a lockfile can need several times the disk of the current
|
|
54
|
+
* platform alone and exceed the quota of the temporary directory. The fetch workspace therefore
|
|
55
|
+
* supports only the `current` platform. pnpm reports every package missing from the store as
|
|
56
|
+
* Unknown, so the listing workspace supports every `os`, `cpu`, and `libc` in the lockfile and
|
|
57
|
+
* `pnpm licenses list` covers the whole graph, with off-platform licenses resolved from the
|
|
58
|
+
* registry afterwards.
|
|
59
|
+
*
|
|
60
|
+
* The lockfile drops every `engines` constraint because pnpm 12's `fetch` ignores `force` and skips
|
|
61
|
+
* an optional package whose `engines` exclude the running Node.js.
|
|
57
62
|
*/
|
|
58
63
|
export function renderPnpmLicenseAuditFiles(lockfileSource, workspaceSource, paths) {
|
|
59
64
|
const lockfileDocument = parseYamlDocument(lockfileSource, paths.lockfile);
|
|
@@ -67,9 +72,11 @@ export function renderPnpmLicenseAuditFiles(lockfileSource, workspaceSource, pat
|
|
|
67
72
|
for (const { value } of packageNodes.items)
|
|
68
73
|
if (isMap(value))
|
|
69
74
|
value.delete('engines');
|
|
75
|
+
const current = { cpu: ['current'], libc: ['current'], os: ['current'] };
|
|
70
76
|
return {
|
|
77
|
+
fetchWorkspace: stringifyYaml({ ...workspace, packages: [], supportedArchitectures: current }),
|
|
71
78
|
lockfile: lockfileDocument.toString({ lineWidth: 0 }),
|
|
72
|
-
|
|
79
|
+
listingWorkspace: stringifyYaml({ ...workspace, packages: [], supportedArchitectures }),
|
|
73
80
|
};
|
|
74
81
|
}
|
|
75
82
|
export function licenseAuditParentDirectory(directory) {
|
|
@@ -79,6 +86,8 @@ export function preparePnpmLicenseAuditWorkspace(repoRoot, lockfileSource, works
|
|
|
79
86
|
const directory = licenseAuditParentDirectory(options.directory);
|
|
80
87
|
reclaimStaleLicenseAuditDirectories(directory, options);
|
|
81
88
|
const auditRoot = mkdtempSync(join(directory, LICENSE_AUDIT_DIRECTORY_PREFIX));
|
|
89
|
+
const workspaceFile = join(auditRoot, 'pnpm-workspace.yaml');
|
|
90
|
+
let listingWorkspace = '';
|
|
82
91
|
try {
|
|
83
92
|
writeAuditPid(auditRoot, options.pid);
|
|
84
93
|
copyFileSync(join(repoRoot, 'package.json'), join(auditRoot, 'package.json'));
|
|
@@ -90,7 +99,8 @@ export function preparePnpmLicenseAuditWorkspace(repoRoot, lockfileSource, works
|
|
|
90
99
|
workspace: join(repoRoot, 'pnpm-workspace.yaml'),
|
|
91
100
|
});
|
|
92
101
|
writeFileSync(join(auditRoot, 'pnpm-lock.yaml'), files.lockfile, 'utf8');
|
|
93
|
-
writeFileSync(
|
|
102
|
+
writeFileSync(workspaceFile, files.fetchWorkspace, 'utf8');
|
|
103
|
+
listingWorkspace = files.listingWorkspace;
|
|
94
104
|
}
|
|
95
105
|
catch (error) {
|
|
96
106
|
removeAuditDirectory(auditRoot);
|
|
@@ -99,5 +109,6 @@ export function preparePnpmLicenseAuditWorkspace(repoRoot, lockfileSource, works
|
|
|
99
109
|
return {
|
|
100
110
|
cwd: auditRoot,
|
|
101
111
|
cleanup: () => removeAuditDirectory(auditRoot),
|
|
112
|
+
useListingWorkspace: () => writeFileSync(workspaceFile, listingWorkspace, 'utf8'),
|
|
102
113
|
};
|
|
103
114
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vouchington-tooling",
|
|
3
|
-
"version": "0.78.
|
|
3
|
+
"version": "0.78.2",
|
|
4
4
|
"description": "Vouchington CLI and extractable tooling libraries.",
|
|
5
5
|
"homepage": "https://github.com/vouchington/vouchington-tooling/tree/main/packages/vouchington-tooling#readme",
|
|
6
6
|
"bugs": {
|
|
@@ -499,7 +499,7 @@
|
|
|
499
499
|
"dependencies": {
|
|
500
500
|
"@types/mdast": "4.0.4",
|
|
501
501
|
"@types/unist": "3.0.3",
|
|
502
|
-
"@typescript-eslint/parser": "^8.
|
|
502
|
+
"@typescript-eslint/parser": "^8.72.0",
|
|
503
503
|
"agent-blackboard": "^0.7.0",
|
|
504
504
|
"coverage-check": "0.18.0",
|
|
505
505
|
"csv-parse": "7.0.3",
|
|
Binary file
|
|
Binary file
|