@zenfs/devel 0.1.0 → 1.0.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.
- package/dist/bin/make-index.js +37 -74
- package/dist/bin/node-compat.d.ts +2 -0
- package/dist/bin/node-compat.js +337 -0
- package/dist/bin/zci.js +33 -44
- package/dist/bin/zenfs-test.js +45 -78
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/make_index.d.ts +20 -0
- package/dist/make_index.js +49 -0
- package/dist/node_compat/analysis.d.ts +53 -0
- package/dist/node_compat/analysis.js +60 -0
- package/dist/node_compat/changelog.d.ts +25 -0
- package/dist/node_compat/changelog.js +60 -0
- package/dist/node_compat/commits.d.ts +26 -0
- package/dist/node_compat/commits.js +66 -0
- package/dist/node_compat/config.d.ts +6 -0
- package/dist/node_compat/config.js +18 -0
- package/dist/node_compat/docs.d.ts +58 -0
- package/dist/node_compat/docs.js +213 -0
- package/dist/node_compat/git.d.ts +22 -0
- package/dist/node_compat/git.js +74 -0
- package/dist/node_compat/index.d.ts +10 -0
- package/dist/node_compat/index.js +11 -0
- package/dist/node_compat/node.d.ts +42 -0
- package/dist/node_compat/node.js +84 -0
- package/dist/node_compat/output.d.ts +29 -0
- package/dist/node_compat/output.js +95 -0
- package/dist/node_compat/pr.d.ts +59 -0
- package/dist/node_compat/pr.js +125 -0
- package/dist/node_compat/state.d.ts +18 -0
- package/dist/node_compat/state.js +12 -0
- package/dist/node_compat/versions.d.ts +5 -0
- package/dist/node_compat/versions.js +13 -0
- package/dist/node_compat/zenfs.d.ts +3 -0
- package/dist/node_compat/zenfs.js +108 -0
- package/package.json +7 -2
package/dist/bin/make-index.js
CHANGED
|
@@ -1,44 +1,24 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
// SPDX-License-Identifier: LGPL-3.0-or-later
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
const
|
|
18
|
-
|
|
19
|
-
console.log(`make-index <path> [...options]
|
|
20
|
-
|
|
21
|
-
path: The path to create a listing for
|
|
22
|
-
|
|
23
|
-
options:
|
|
24
|
-
-h, --help Outputs this help message
|
|
25
|
-
-q, --quiet The command will not generate any output, including error messages.
|
|
26
|
-
--verbose Output verbose messages
|
|
27
|
-
--xdev Force crossing device/FS boundaries
|
|
28
|
-
-o, --output <path> Path to the output file. Defaults to listing.
|
|
29
|
-
-i, --ignore <pattern> Ignores files which match the glob <pattern>. Can be passed multiple times.
|
|
30
|
-
`);
|
|
31
|
-
process.exit();
|
|
32
|
-
}
|
|
33
|
-
if (options.quiet && options.verbose) {
|
|
34
|
-
console.log('Can not use both --verbose and --quiet.');
|
|
35
|
-
process.exit();
|
|
36
|
-
}
|
|
3
|
+
import { Command, Option } from 'commander';
|
|
4
|
+
import { constants as c, writeFileSync } from 'node:fs';
|
|
5
|
+
import { resolve } from 'node:path/posix';
|
|
6
|
+
import { styleText } from 'node:util';
|
|
7
|
+
import makeIndex from '../make_index.js';
|
|
8
|
+
const cli = new Command('make-index')
|
|
9
|
+
.description('Creates an index of a directory, for use with backends like Fetch')
|
|
10
|
+
.argument('[path]', 'The path to create a listing for', '.')
|
|
11
|
+
.option('-o, --output <path>', 'Path to the output file', 'index.json')
|
|
12
|
+
.option('-i, --ignore <pattern...>', 'Ignore files which match the glob pattern; can be passed multiple times', [])
|
|
13
|
+
.option('--xdev', 'Force crossing device/FS boundaries')
|
|
14
|
+
.addOption(new Option('-q, --quiet', "Don't output anything, including errors").conflicts('verbose'))
|
|
15
|
+
.option('--verbose', 'Output verbose messages')
|
|
16
|
+
.parse();
|
|
17
|
+
const options = cli.opts();
|
|
18
|
+
const [root] = cli.processedArgs;
|
|
37
19
|
function fixSlash(path) {
|
|
38
20
|
return path.replaceAll('\\', '/');
|
|
39
21
|
}
|
|
40
|
-
const resolvedRoot = root || '.';
|
|
41
|
-
const entries = new Map();
|
|
42
22
|
const typeMap = {
|
|
43
23
|
file: 'green',
|
|
44
24
|
' dir': 'blue',
|
|
@@ -60,51 +40,34 @@ function getTypeText(stats) {
|
|
|
60
40
|
return 'file';
|
|
61
41
|
case c.S_IFDIR:
|
|
62
42
|
return ' dir';
|
|
43
|
+
case c.S_IFLNK:
|
|
44
|
+
return ' sym';
|
|
63
45
|
default:
|
|
64
46
|
throw new Error(`Unknown file type: 0o${(stats.mode & c.S_IFMT).toString(8)}`);
|
|
65
47
|
}
|
|
66
48
|
}
|
|
67
|
-
const
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
49
|
+
const index = makeIndex(root, {
|
|
50
|
+
ignore: options.ignore,
|
|
51
|
+
xdev: options.xdev,
|
|
52
|
+
onWarning(message) {
|
|
53
|
+
console.warn(styleText('yellowBright', message));
|
|
54
|
+
},
|
|
55
|
+
onError(path, error) {
|
|
56
|
+
if (!options.quiet)
|
|
57
|
+
console.log(`${styleText('red', 'fail')} ${path}: ${error.message}`);
|
|
58
|
+
},
|
|
59
|
+
onEntry(path, stats) {
|
|
60
|
+
if (!options.verbose)
|
|
73
61
|
return;
|
|
74
|
-
}
|
|
75
|
-
const stats = lstatSync(path);
|
|
76
|
-
if (!seenDevs.size)
|
|
77
|
-
seenDevs.add(stats.dev);
|
|
78
|
-
else if (!seenDevs.has(stats.dev))
|
|
79
|
-
if (options.xdev) {
|
|
80
|
-
console.warn(`${styleText('yellowBright', `--xdev: Adding entries from device ${stats.dev} (${path}). You may get duplicate inos which MUST be de-duplicated manually.`)}`);
|
|
81
|
-
seenDevs.add(stats.dev);
|
|
82
|
-
}
|
|
83
|
-
else {
|
|
84
|
-
console.warn(`${styleText('yellowBright', `Ignoring ${path} because it crosses a device boundary`)}`);
|
|
85
|
-
return;
|
|
86
|
-
}
|
|
87
62
|
const type = getTypeText(stats);
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
if (
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
}
|
|
96
|
-
catch (e) {
|
|
97
|
-
if (!options.quiet) {
|
|
98
|
-
console.log(`${styleText('red', 'fail')} ${path}: ${e instanceof Error ? e.message : String(e)}`);
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
computeEntries(resolvedRoot);
|
|
63
|
+
console.log(`${styleText(typeMap[type] || 'white', type)} ${path}`);
|
|
64
|
+
},
|
|
65
|
+
onIgnore(path) {
|
|
66
|
+
if (!options.quiet)
|
|
67
|
+
console.log(`${styleText('yellow', 'skip')} ${path}`);
|
|
68
|
+
},
|
|
69
|
+
});
|
|
103
70
|
if (!options.quiet) {
|
|
104
71
|
console.log('Generated listing for ' + fixSlash(resolve(root)));
|
|
105
72
|
}
|
|
106
|
-
const index = {
|
|
107
|
-
version: 1,
|
|
108
|
-
entries: Object.fromEntries(entries),
|
|
109
|
-
};
|
|
110
73
|
writeFileSync(options.output, JSON.stringify(index));
|
|
@@ -0,0 +1,337 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// SPDX-License-Identifier: LGPL-3.0-or-later
|
|
3
|
+
import { Argument, Command, Option } from 'commander';
|
|
4
|
+
import { existsSync } from 'node:fs';
|
|
5
|
+
import { text } from 'node:stream/consumers';
|
|
6
|
+
import { styleText } from 'node:util';
|
|
7
|
+
import { configPath, saveRepo, savedRepo } from '../node_compat/config.js';
|
|
8
|
+
import * as core from '../node_compat/index.js';
|
|
9
|
+
import { displayPath, formatMark, pad, parseIntegers, parseList, parsePositiveInteger, parseRegex, printFields, printPRTable, semverStyles, statusStyles, } from '../node_compat/output.js';
|
|
10
|
+
const statuses = Object.keys(statusStyles);
|
|
11
|
+
const semvers = Object.keys(semverStyles);
|
|
12
|
+
const tags = ['native', 'internal', 'docs', 'test', 'windows', 'perf', 'stability', 'deprecation', 'revert', 'backport'];
|
|
13
|
+
const kinds = ['module', 'class', 'member', 'constant'];
|
|
14
|
+
const cli = new Command('node-compat')
|
|
15
|
+
.description('Tracks Node.js `fs:` pull requests and API changes against @zenfs/core, using only a local clone of the Node.js repository')
|
|
16
|
+
.addOption(new Option('--node <dir>', 'Node.js clone (default: the saved clone)').env('NODE_REPO'))
|
|
17
|
+
.option('--persist', 'Save --node or $NODE_REPO as the default clone')
|
|
18
|
+
.option('--ref <ref>', 'Ref to read from (default: upstream of main, or HEAD)')
|
|
19
|
+
.option('--state <file>', 'Marks file', core.defaultMarksPath)
|
|
20
|
+
.addHelpText('after', `\nThe first clone used is saved to ${displayPath(configPath)}.`);
|
|
21
|
+
const sinceOption = new Option('--since <version>', 'Released in this version or later, or unreleased').default('18');
|
|
22
|
+
/**
|
|
23
|
+
* Loads the Node.js clone and marks, saving the clone if it is the first one used.
|
|
24
|
+
*/
|
|
25
|
+
function load(createMarks = false) {
|
|
26
|
+
const options = cli.opts();
|
|
27
|
+
const saved = savedRepo();
|
|
28
|
+
const repo = options.node
|
|
29
|
+
?? saved
|
|
30
|
+
?? cli.error(`error: No Node.js clone given. Use --node <dir> or set NODE_REPO; it will be saved to ${displayPath(configPath)}.`);
|
|
31
|
+
const marks = createMarks || existsSync(options.state) ? core.openMarks(options.state) : new Map();
|
|
32
|
+
let node;
|
|
33
|
+
try {
|
|
34
|
+
node = new core.NodeRepository({ repo, ref: options.ref });
|
|
35
|
+
}
|
|
36
|
+
catch (error) {
|
|
37
|
+
return cli.error(`error: ${error instanceof Error ? error.message : String(error)}`);
|
|
38
|
+
}
|
|
39
|
+
if (node.path != saved && (!saved || options.persist)) {
|
|
40
|
+
saveRepo(node.path);
|
|
41
|
+
console.error(styleText('dim', `Saved ${displayPath(node.path)} as the Node.js clone in ${displayPath(configPath)}\n`));
|
|
42
|
+
}
|
|
43
|
+
return { node, marks, analysis: new core.Analysis(node, marks) };
|
|
44
|
+
}
|
|
45
|
+
function sinceFilter(node, since) {
|
|
46
|
+
return { since, landedSince: node.releaseDate(since) };
|
|
47
|
+
}
|
|
48
|
+
cli.command('summary', { isDefault: true })
|
|
49
|
+
.description('Overview of PRs, API coverage, and pending features')
|
|
50
|
+
.addOption(sinceOption)
|
|
51
|
+
.action(({ since }) => {
|
|
52
|
+
const { node, analysis, marks } = load();
|
|
53
|
+
const prs = analysis.filterPRs(sinceFilter(node, since));
|
|
54
|
+
const counts = {};
|
|
55
|
+
for (const { pr, status } of prs) {
|
|
56
|
+
const group = (counts[pr.semver] ??= { pending: 0, auto: 0, resolved: 0, ignored: 0 });
|
|
57
|
+
group[status]++;
|
|
58
|
+
}
|
|
59
|
+
const apis = [...analysis.apis.values()];
|
|
60
|
+
const present = apis.filter(status => status.present).length;
|
|
61
|
+
const missing = apis.filter(status => !status.present && !status.mark);
|
|
62
|
+
const pending = analysis.filterPRs({ status: ['pending'], semver: ['major', 'minor', 'unreleased'] }, prs).sort(core.byNewest);
|
|
63
|
+
const repoInfo = `(${node.hash.slice(0, 10)}, ${node.date.toISOString().slice(0, 10)}, latest release ${node.latest?.version})`;
|
|
64
|
+
console.log(styleText('bold', 'Node.js'.padEnd(9)), `${displayPath(node.path)} @ ${node.ref}`, styleText('dim', repoInfo));
|
|
65
|
+
console.log(styleText('bold', 'ZenFS'.padEnd(9)), core.zenfs.version);
|
|
66
|
+
console.log(styleText('bold', 'Marks'.padEnd(9)), `${marks.size} in ${displayPath(cli.opts().state)}\n`);
|
|
67
|
+
console.log(styleText('bold', `PRs since ${since}`), styleText('dim', `(${prs.length})`));
|
|
68
|
+
for (const semver of semvers) {
|
|
69
|
+
const group = counts[semver];
|
|
70
|
+
if (!group)
|
|
71
|
+
continue;
|
|
72
|
+
const total = Object.values(group).reduce((sum, count) => sum + count, 0);
|
|
73
|
+
const breakdown = statuses
|
|
74
|
+
.filter(status => group[status])
|
|
75
|
+
.map(status => styleText(statusStyles[status], `${group[status]} ${status}`))
|
|
76
|
+
.join(', ');
|
|
77
|
+
console.log(' ', pad(styleText(semverStyles[semver], semver), 11), String(total).padStart(4), ' ', breakdown);
|
|
78
|
+
}
|
|
79
|
+
console.log(styleText('bold', '\nAPIs'), styleText('dim', `(${apis.length} documented)`));
|
|
80
|
+
console.log(` ${present} present (${Math.floor((present / apis.length) * 100)}%), ${missing.length} missing and unmarked`);
|
|
81
|
+
if (missing.length)
|
|
82
|
+
console.log(styleText('red', ' ' + missing.map(({ api }) => api.id).join(', ')));
|
|
83
|
+
if (pending.length) {
|
|
84
|
+
console.log(styleText('bold', '\nPending features'), styleText('dim', `(${pending.length})`));
|
|
85
|
+
printPRTable(pending.slice(0, 15));
|
|
86
|
+
if (pending.length > 15)
|
|
87
|
+
console.log(styleText('dim', ` … ${pending.length - 15} more`));
|
|
88
|
+
}
|
|
89
|
+
});
|
|
90
|
+
cli.command('prs')
|
|
91
|
+
.alias('list')
|
|
92
|
+
.description('List fs PRs')
|
|
93
|
+
.optionsGroup('Filters:')
|
|
94
|
+
.addOption(sinceOption)
|
|
95
|
+
.option('-k, --semver <list>', `Any of: ${semvers.join(', ')}`, parseList(semvers))
|
|
96
|
+
.option('-s, --status <list>', `Any of: ${statuses.join(', ')} (auto: every API the PR added exists in ZenFS)`, parseList(statuses))
|
|
97
|
+
.option('-l, --line <list>', 'Released in all of these release lines', parseIntegers)
|
|
98
|
+
.option('-t, --tag <list>', `Has all of these tags: ${tags.join(', ')}`, parseList(tags))
|
|
99
|
+
.option('-x, --exclude <list>', "Doesn't have any of these tags", parseList(tags))
|
|
100
|
+
.option('-g, --grep <regex>', 'Matches the title or commit messages (case-insensitive)', parseRegex)
|
|
101
|
+
.option('-u, --unreleased', 'Only PRs not in any release')
|
|
102
|
+
.option('-a, --all', 'Drop the default filters')
|
|
103
|
+
.optionsGroup('Output:')
|
|
104
|
+
.option('-n, --limit <n>', 'Show at most n PRs', parsePositiveInteger)
|
|
105
|
+
.option('--ids', 'Print only IDs')
|
|
106
|
+
.option('--exit-code', 'Exit with 1 if any PRs are listed')
|
|
107
|
+
.addHelpText('after', `
|
|
108
|
+
By default only pending features are listed: --status pending --semver major,minor,unreleased.
|
|
109
|
+
Passing a filter replaces its default; --all drops the defaults.
|
|
110
|
+
|
|
111
|
+
Example: node-compat prs -t windows --ids | node-compat ignore - -m Windows`)
|
|
112
|
+
.action(options => {
|
|
113
|
+
const { node, analysis } = load();
|
|
114
|
+
const defaulted = [];
|
|
115
|
+
const filter = {
|
|
116
|
+
...sinceFilter(node, options.since),
|
|
117
|
+
semver: options.semver,
|
|
118
|
+
status: options.status,
|
|
119
|
+
lines: options.line,
|
|
120
|
+
tags: [...(options.tag ?? []), ...(options.exclude ?? []).map(tag => '!' + tag)],
|
|
121
|
+
grep: options.grep,
|
|
122
|
+
unreleased: options.unreleased,
|
|
123
|
+
};
|
|
124
|
+
if (!options.all) {
|
|
125
|
+
if (!filter.status) {
|
|
126
|
+
filter.status = ['pending'];
|
|
127
|
+
defaulted.push('--status pending');
|
|
128
|
+
}
|
|
129
|
+
if (!filter.semver && !filter.unreleased) {
|
|
130
|
+
filter.semver = ['major', 'minor', 'unreleased'];
|
|
131
|
+
defaulted.push('--semver major,minor,unreleased');
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
const matched = analysis.filterPRs(filter).sort(core.byNewest);
|
|
135
|
+
const rows = matched.slice(0, options.limit);
|
|
136
|
+
if (options.ids) {
|
|
137
|
+
for (const { pr } of rows)
|
|
138
|
+
console.log(pr.number);
|
|
139
|
+
}
|
|
140
|
+
else {
|
|
141
|
+
printPRTable(rows);
|
|
142
|
+
const shown = rows.length < matched.length ? `${rows.length} of ${matched.length} matching` : `${matched.length}`;
|
|
143
|
+
const notes = [`since ${options.since}`, ...defaulted];
|
|
144
|
+
const hint = defaulted.length ? '. Use --all to drop defaults.' : '';
|
|
145
|
+
console.log(styleText('dim', `\n${shown} PRs (of ${analysis.prs.size}; ${notes.join(', ')})${hint}`));
|
|
146
|
+
}
|
|
147
|
+
if (options.exitCode && rows.length)
|
|
148
|
+
process.exitCode = 1;
|
|
149
|
+
});
|
|
150
|
+
cli.command('apis')
|
|
151
|
+
.description('Compare the documented fs API surface with ZenFS; by default only unmarked APIs that ZenFS is missing are listed')
|
|
152
|
+
.optionsGroup('Filters:')
|
|
153
|
+
.option('-a, --all', 'List every documented API')
|
|
154
|
+
.option('-g, --grep <regex>', 'Matches the API ID (case-insensitive)', parseRegex)
|
|
155
|
+
.option('--owner <name>', 'fs, fsPromises, or a class such as FileHandle')
|
|
156
|
+
.option('--kind <list>', `Any of: ${kinds.join(', ')}`, parseList(kinds))
|
|
157
|
+
.addOption(sinceOption)
|
|
158
|
+
.optionsGroup('Output:')
|
|
159
|
+
.option('--ids', 'Print only IDs')
|
|
160
|
+
.option('--exit-code', 'Exit with 1 if any APIs are listed')
|
|
161
|
+
.action(options => {
|
|
162
|
+
const { node, analysis } = load();
|
|
163
|
+
const owner = options.owner?.toLowerCase();
|
|
164
|
+
const rows = [...analysis.apis.values()].filter(({ api, present, mark }) => {
|
|
165
|
+
if (!options.all && (present || mark))
|
|
166
|
+
return false;
|
|
167
|
+
if (options.kind && !options.kind.includes(api.kind))
|
|
168
|
+
return false;
|
|
169
|
+
if (owner && api.owner.toLowerCase() != owner)
|
|
170
|
+
return false;
|
|
171
|
+
if (options.grep && !options.grep.test(api.id))
|
|
172
|
+
return false;
|
|
173
|
+
return true;
|
|
174
|
+
});
|
|
175
|
+
if (options.ids) {
|
|
176
|
+
for (const { api } of rows)
|
|
177
|
+
console.log(api.id);
|
|
178
|
+
}
|
|
179
|
+
else {
|
|
180
|
+
const idWidth = Math.max(10, ...rows.map(({ api }) => api.id.length));
|
|
181
|
+
const pendingPRs = new Set(analysis.filterPRs({ ...sinceFilter(node, options.since), status: ['pending'] }).map(({ pr }) => pr.number));
|
|
182
|
+
for (const { api, present, mark } of rows) {
|
|
183
|
+
const pending = api.changes.filter(change => change.pr && pendingPRs.has(change.pr)).length;
|
|
184
|
+
const notes = [
|
|
185
|
+
api.deprecated.length ? styleText('yellow', 'deprecated') : '',
|
|
186
|
+
api.stability == 1 ? styleText('magenta', 'experimental') : '',
|
|
187
|
+
pending ? styleText('yellow', `${pending} pending change${pending == 1 ? '' : 's'}`) : '',
|
|
188
|
+
formatMark(mark),
|
|
189
|
+
];
|
|
190
|
+
console.log(present ? styleText('green', '✓') : styleText('red', '✗'), pad(api.id, idWidth), pad(styleText('dim', api.added.join(', ') || '-'), 18), notes.filter(Boolean).join(' '));
|
|
191
|
+
}
|
|
192
|
+
const present = [...analysis.apis.values()].filter(status => status.present).length;
|
|
193
|
+
const hint = options.all ? '' : ' Use --all to list every API.';
|
|
194
|
+
console.log(styleText('dim', `\n${rows.length} listed; ZenFS has ${present} of ${analysis.apis.size} documented APIs.${hint}`));
|
|
195
|
+
}
|
|
196
|
+
if (options.exitCode && rows.length)
|
|
197
|
+
process.exitCode = 1;
|
|
198
|
+
});
|
|
199
|
+
function showPR({ node, analysis }, pr) {
|
|
200
|
+
const status = analysis.prs.get(pr.number);
|
|
201
|
+
const apiState = (id) => {
|
|
202
|
+
const api = analysis.apis.get(id);
|
|
203
|
+
if (!api)
|
|
204
|
+
return styleText('dim', id);
|
|
205
|
+
return (api.present ? styleText('green', '✓ ') : styleText('red', '✗ ')) + id + (api.mark ? ' ' + formatMark(api.mark) : '');
|
|
206
|
+
};
|
|
207
|
+
console.log(styleText('bold', `#${pr.number} ${pr.subsystems.join(',')}: ${pr.title}`));
|
|
208
|
+
console.log(styleText('dim', pr.url) + '\n');
|
|
209
|
+
printFields([
|
|
210
|
+
['Author', pr.author],
|
|
211
|
+
['Semver', styleText(semverStyles[pr.semver], pr.semver)],
|
|
212
|
+
['Status', styleText(statusStyles[status.status], status.status) + (status.mark ? ' ' + formatMark(status.mark).replace(/^\S+/, '') : '')],
|
|
213
|
+
[
|
|
214
|
+
'Released',
|
|
215
|
+
pr.releases.map(release => `${release.version} ${styleText('dim', `(${release.date})`)}`).join(', ') || styleText('blue', 'unreleased'),
|
|
216
|
+
],
|
|
217
|
+
[
|
|
218
|
+
'Landed',
|
|
219
|
+
pr.commits.length
|
|
220
|
+
? `${pr.commits[0].date.slice(0, 10)} on ${node.ref} (${pr.commits.map(commit => commit.hash.slice(0, 10)).join(', ')})`
|
|
221
|
+
: styleText('dim', `not on ${node.ref} (release branches only)`),
|
|
222
|
+
],
|
|
223
|
+
['Areas', pr.areas.join(' ')],
|
|
224
|
+
['Tags', pr.tags.join(', ')],
|
|
225
|
+
['Added', pr.apis.added.map(apiState).join(', ')],
|
|
226
|
+
['Removed', pr.apis.removed.join(', ')],
|
|
227
|
+
['Changed', pr.apis.changed.map(apiState).join(', ')],
|
|
228
|
+
]);
|
|
229
|
+
for (const id of pr.apis.changed) {
|
|
230
|
+
const api = node.apis.get(id);
|
|
231
|
+
for (const change of api?.changes.filter(change => change.pr == pr.number) ?? []) {
|
|
232
|
+
console.log(styleText('dim', `\n${id} (${change.versions.join(', ')}):`), change.description);
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
for (const commit of pr.commits) {
|
|
236
|
+
const body = commit.body
|
|
237
|
+
.split('\n')
|
|
238
|
+
.filter(line => !/^(PR-URL|Reviewed-By|Signed-off-by|Co-authored-by|Acked-By):/i.test(line))
|
|
239
|
+
.join('\n')
|
|
240
|
+
.trim();
|
|
241
|
+
console.log(styleText('dim', `\ncommit ${commit.hash}`));
|
|
242
|
+
console.log(commit.subject + (body ? '\n\n' + body.replace(/^/gm, ' ') : ''));
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
function showApi({ analysis }, api) {
|
|
246
|
+
const status = analysis.apis.get(api.id);
|
|
247
|
+
console.log(styleText('bold', api.id), styleText('dim', `(${api.kind}, ${api.section})`) + '\n');
|
|
248
|
+
printFields([
|
|
249
|
+
['Signature', api.signatures.join('\n ')],
|
|
250
|
+
['Added', api.added.join(', ')],
|
|
251
|
+
['Deprecated', api.deprecated.join(', ')],
|
|
252
|
+
['Stability', api.stability === undefined ? '' : String(api.stability)],
|
|
253
|
+
['ZenFS', status.present ? styleText('green', 'present') : styleText('red', 'missing')],
|
|
254
|
+
['Mark', formatMark(status.mark)],
|
|
255
|
+
]);
|
|
256
|
+
if (!api.changes.length)
|
|
257
|
+
return;
|
|
258
|
+
console.log(styleText('bold', '\nChanges'));
|
|
259
|
+
for (const change of api.changes) {
|
|
260
|
+
const pr = change.pr ? analysis.prs.get(change.pr) : undefined;
|
|
261
|
+
const tracked = pr ? styleText(statusStyles[pr.status], pr.status) : styleText('dim', 'untracked');
|
|
262
|
+
console.log(` ${pad(change.versions.join(', '), 24)} ${pad(change.pr ? '#' + change.pr : '', 7)} ${pad(tracked, 9)} ${change.description}`);
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
cli.command('show')
|
|
266
|
+
.description('Details for PRs or APIs')
|
|
267
|
+
.argument('<ids...>', 'PR numbers (12345, #12345, or URLs) or API IDs (fs.glob, FileHandle#readLines)')
|
|
268
|
+
.action(ids => {
|
|
269
|
+
const context = load();
|
|
270
|
+
for (const [index, input] of ids.entries()) {
|
|
271
|
+
const resolved = context.node.resolve(input) ?? cli.error(`error: Unknown PR or API "${input}"`);
|
|
272
|
+
if (index)
|
|
273
|
+
console.log('\n' + styleText('dim', '─'.repeat(40)) + '\n');
|
|
274
|
+
if (resolved.pr)
|
|
275
|
+
showPR(context, resolved.pr);
|
|
276
|
+
else if (resolved.api)
|
|
277
|
+
showApi(context, resolved.api);
|
|
278
|
+
}
|
|
279
|
+
});
|
|
280
|
+
/**
|
|
281
|
+
* Applies or removes a mark, reading IDs from stdin for `-`.
|
|
282
|
+
*/
|
|
283
|
+
async function mark(status, inputs, note) {
|
|
284
|
+
const { node, marks } = load(!!status);
|
|
285
|
+
const stdin = inputs.includes('-') ? (await text(process.stdin)).split(/\s+/).filter(Boolean) : [];
|
|
286
|
+
const ids = inputs.flatMap(input => (input == '-' ? stdin : [input]));
|
|
287
|
+
const targets = [];
|
|
288
|
+
for (const input of ids) {
|
|
289
|
+
const resolved = node.resolveAll(input);
|
|
290
|
+
if (!resolved.length && marks.has(input))
|
|
291
|
+
resolved.push({ key: input });
|
|
292
|
+
if (!resolved.length)
|
|
293
|
+
console.error(styleText('yellow', 'skipped:'), `unknown PR or API "${input}"`);
|
|
294
|
+
targets.push(...resolved);
|
|
295
|
+
}
|
|
296
|
+
let changed = 0;
|
|
297
|
+
for (const { key, pr } of targets) {
|
|
298
|
+
if (status)
|
|
299
|
+
marks.set(key, core.createMark(status, note));
|
|
300
|
+
else if (!marks.delete(key))
|
|
301
|
+
continue;
|
|
302
|
+
changed++;
|
|
303
|
+
if (targets.length <= 20) {
|
|
304
|
+
console.log(status ? styleText(statusStyles[status], status.padEnd(8)) : styleText('dim', 'unmarked'), pr ? `${key} ${pr.title}` : key);
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
console.log(styleText('dim', `${changed} mark${changed == 1 ? '' : 's'} updated in ${displayPath(cli.opts().state)}`));
|
|
308
|
+
}
|
|
309
|
+
const idsArg = new Argument('<ids...>', 'PR numbers (12345, #12345, or URLs) or API IDs, which may contain * wildcards; `-` reads IDs from stdin');
|
|
310
|
+
cli.command('resolve')
|
|
311
|
+
.description('Mark PRs or APIs as resolved')
|
|
312
|
+
.addArgument(idsArg)
|
|
313
|
+
.option('-m, --message <note>', 'Attach a note to the mark')
|
|
314
|
+
.action((ids, { message }) => mark('resolved', ids, message));
|
|
315
|
+
cli.command('ignore')
|
|
316
|
+
.description('Mark PRs or APIs as not applicable to ZenFS')
|
|
317
|
+
.addArgument(idsArg)
|
|
318
|
+
.option('-m, --message <note>', 'Attach a note to the mark')
|
|
319
|
+
.action((ids, { message }) => mark('ignored', ids, message));
|
|
320
|
+
cli.command('unmark')
|
|
321
|
+
.description('Remove marks')
|
|
322
|
+
.addArgument(idsArg)
|
|
323
|
+
.action(ids => mark(undefined, ids));
|
|
324
|
+
cli.command('marks')
|
|
325
|
+
.description('List marks')
|
|
326
|
+
.action(() => {
|
|
327
|
+
const { node, marks } = load();
|
|
328
|
+
const entries = [...marks].sort(([left], [right]) => left.localeCompare(right, 'en', { numeric: true }));
|
|
329
|
+
if (!entries.length)
|
|
330
|
+
return console.log(styleText('dim', `No marks in ${displayPath(cli.opts().state)}`));
|
|
331
|
+
const width = Math.max(...entries.map(([key]) => key.length));
|
|
332
|
+
for (const [key, { status, date, note }] of entries) {
|
|
333
|
+
const pr = key.startsWith('#') ? node.prs.get(Number(key.slice(1))) : undefined;
|
|
334
|
+
console.log(pad(key, width), pad(styleText(statusStyles[status], status), 8), styleText('dim', date), pr?.title ?? '', note ? styleText('dim', `— ${note}`) : '');
|
|
335
|
+
}
|
|
336
|
+
});
|
|
337
|
+
await cli.parseAsync();
|
package/dist/bin/zci.js
CHANGED
|
@@ -1,51 +1,40 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
// SPDX-License-Identifier: LGPL-3.0-or-later
|
|
3
|
+
import { Command } from 'commander';
|
|
3
4
|
import { spawnSync } from 'node:child_process';
|
|
4
|
-
import { parseArgs } from 'node:util';
|
|
5
5
|
import * as ci from '../ci.js';
|
|
6
|
-
const
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
if (options.help || !subcommand) {
|
|
13
|
-
console.log(`Usage:
|
|
14
|
-
zci [-h | --help] Show this help message
|
|
15
|
-
zci init Create checks in a queued state
|
|
16
|
-
zci cleanup Mark all remaining checks are completed with a neutral status
|
|
17
|
-
zci run <name> <cmd> Run a command and use its exit code as the completion status
|
|
18
|
-
zci list List checks`);
|
|
19
|
-
process.exit();
|
|
20
|
-
}
|
|
21
|
-
switch (subcommand) {
|
|
22
|
-
case 'init':
|
|
23
|
-
for (const [id, name] of Object.entries(ci.checkNames)) {
|
|
24
|
-
await ci.createCheck(id, name);
|
|
25
|
-
}
|
|
26
|
-
break;
|
|
27
|
-
case 'list': {
|
|
28
|
-
const max = Math.max(...Object.keys(ci.checkNames).map(id => id.length)) + 1;
|
|
29
|
-
for (const [id, name] of Object.entries(ci.checkNames)) {
|
|
30
|
-
console.log(id.padEnd(max), name);
|
|
31
|
-
}
|
|
32
|
-
break;
|
|
6
|
+
const zci = new Command('zci').description('Manages GitHub check runs for CI').enablePositionalOptions();
|
|
7
|
+
zci.command('init')
|
|
8
|
+
.description('Create checks in a queued state')
|
|
9
|
+
.action(async () => {
|
|
10
|
+
for (const [id, name] of Object.entries(ci.checkNames)) {
|
|
11
|
+
await ci.createCheck(id, name);
|
|
33
12
|
}
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
13
|
+
});
|
|
14
|
+
zci.command('list')
|
|
15
|
+
.description('List checks')
|
|
16
|
+
.action(() => {
|
|
17
|
+
const max = Math.max(...Object.keys(ci.checkNames).map(id => id.length)) + 1;
|
|
18
|
+
for (const [id, name] of Object.entries(ci.checkNames)) {
|
|
19
|
+
console.log(id.padEnd(max), name);
|
|
41
20
|
}
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
21
|
+
});
|
|
22
|
+
zci.command('run')
|
|
23
|
+
.description('Run a command and use its exit code as the completion status')
|
|
24
|
+
.argument('<name>', 'Check to report to')
|
|
25
|
+
.argument('<command...>', 'Command to run')
|
|
26
|
+
.passThroughOptions()
|
|
27
|
+
.action(async (name, command) => {
|
|
28
|
+
await ci.startCheck(name);
|
|
29
|
+
const { status } = spawnSync(command.join(' '), { shell: true, stdio: 'inherit' });
|
|
30
|
+
await ci.completeCheck(name, status ? 'failure' : 'success');
|
|
31
|
+
process.exit(status);
|
|
32
|
+
});
|
|
33
|
+
zci.command('cleanup')
|
|
34
|
+
.description('Mark all remaining checks as completed with a neutral status')
|
|
35
|
+
.action(async () => {
|
|
36
|
+
for (const id of Object.keys(ci.checkNames)) {
|
|
37
|
+
await ci.completeCheck(id, 'neutral');
|
|
47
38
|
}
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
process.exit(1);
|
|
51
|
-
}
|
|
39
|
+
});
|
|
40
|
+
await zci.parseAsync();
|