@minimalstuff/tooling 0.8.2 → 0.9.1
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 +4 -0
- package/dist/cli/index.mjs +218 -7
- package/package.json +4 -6
package/README.md
CHANGED
|
@@ -26,6 +26,10 @@ pnpm dlx @minimalstuff/tooling@latest
|
|
|
26
26
|
|
|
27
27
|
The CLI asks which tools to set up (EditorConfig, OXC, Knip), offers VS Code settings when OXC is selected, and asks for presets (`react`, `adonisjs`, `vitest`) pre-selected from your dependencies. It asks before overwriting a file and only adds the `package.json` scripts that are missing. It then installs the packages once as devDependencies with the detected package manager. See the [CLI reference](docs/cli.md) for details.
|
|
28
28
|
|
|
29
|
+
### Block releases that ship a patched or linked `@minimalstuff/*` package
|
|
30
|
+
|
|
31
|
+
`pnpm exec tooling check-release` reads `pnpm-lock.yaml` and exits with code 1 when a `@minimalstuff/*` package is patched (`pnpm patch`) or linked from outside the repository (`link:`, `file:`). It never prompts, so it runs in CI. The reusable workflow `.github/workflows/release.yml` runs it before cutting a release. See the [CLI reference](docs/cli.md#check-release).
|
|
32
|
+
|
|
29
33
|
### Manually
|
|
30
34
|
|
|
31
35
|
```bash
|
package/dist/cli/index.mjs
CHANGED
|
@@ -1,12 +1,210 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { cancel, confirm, intro, isCancel, log, multiselect, outro } from "@clack/prompts";
|
|
3
3
|
import color from "picocolors";
|
|
4
|
+
import { basename, dirname, isAbsolute, join, relative, resolve, sep } from "node:path";
|
|
5
|
+
import { mkdir, readFile, readdir, writeFile } from "node:fs/promises";
|
|
6
|
+
import { parseAllDocuments } from "yaml";
|
|
4
7
|
import { detectPackageManager, installPackage } from "@antfu/install-pkg";
|
|
5
8
|
import { existsSync } from "node:fs";
|
|
6
|
-
import { basename, dirname, join } from "node:path";
|
|
7
|
-
import { mkdir, readFile, readdir, writeFile } from "node:fs/promises";
|
|
8
9
|
import { parse, printParseErrorCode } from "jsonc-parser";
|
|
9
10
|
import { fileURLToPath } from "node:url";
|
|
11
|
+
// src/check_release/constants.ts
|
|
12
|
+
const CHECK_RELEASE_SUBCOMMAND = "check-release";
|
|
13
|
+
const LOCKFILE_NAME = "pnpm-lock.yaml";
|
|
14
|
+
const MINIMALSTUFF_SCOPE_PREFIX = "@minimalstuff/";
|
|
15
|
+
// src/check_release/extract_package_name.ts
|
|
16
|
+
const OVERRIDE_PARENT_SEPARATOR = ">";
|
|
17
|
+
/**
|
|
18
|
+
* Returns the package name of a lockfile key such as `@scope/name@1.0.0`,
|
|
19
|
+
* `@scope/name@^1` or `parent>@scope/name`.
|
|
20
|
+
*/
|
|
21
|
+
function extractPackageName(key) {
|
|
22
|
+
const target = key.slice(key.lastIndexOf(OVERRIDE_PARENT_SEPARATOR) + 1);
|
|
23
|
+
const versionSeparatorIndex = target.indexOf("@", 1);
|
|
24
|
+
if (versionSeparatorIndex === -1) return target;
|
|
25
|
+
return target.slice(0, versionSeparatorIndex);
|
|
26
|
+
}
|
|
27
|
+
// src/check_release/is_record.ts
|
|
28
|
+
function isRecord(value) {
|
|
29
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
30
|
+
}
|
|
31
|
+
// src/check_release/is_unpublished_specifier.ts
|
|
32
|
+
const LINK_PREFIX$1 = "link:";
|
|
33
|
+
const PARENT_SEGMENT = "..";
|
|
34
|
+
const REGISTRY_VERSION_PATTERN = /^\d/;
|
|
35
|
+
function isInsideRepository(linkSpecifier, repositoryRoot, baseDirectory) {
|
|
36
|
+
const target = resolve(baseDirectory, linkSpecifier.slice(5));
|
|
37
|
+
const pathFromRoot = relative(repositoryRoot, target);
|
|
38
|
+
return !(pathFromRoot === PARENT_SEGMENT || pathFromRoot.startsWith(PARENT_SEGMENT + sep) || isAbsolute(pathFromRoot));
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Only a registry version (starting with a digit, possibly followed by a
|
|
42
|
+
* peer or patch suffix) and a `link:` inside the repository (an internal
|
|
43
|
+
* workspace) are releasable. Anything else (`file:`, `link:` outside, git,
|
|
44
|
+
* tarball URL, `github:`) is not.
|
|
45
|
+
*/
|
|
46
|
+
function isUnpublishedSpecifier(specifier, repositoryRoot, baseDirectory) {
|
|
47
|
+
if (REGISTRY_VERSION_PATTERN.test(specifier)) return false;
|
|
48
|
+
if (!specifier.startsWith(LINK_PREFIX$1)) return true;
|
|
49
|
+
return !isInsideRepository(specifier, repositoryRoot, baseDirectory);
|
|
50
|
+
}
|
|
51
|
+
// src/check_release/is_unpublished_override.ts
|
|
52
|
+
const LINK_PREFIX = "link:";
|
|
53
|
+
const ALLOWED_PROTOCOLS = ["npm:", "workspace:"];
|
|
54
|
+
const PROTOCOL_SEPARATOR = ":";
|
|
55
|
+
/**
|
|
56
|
+
* Override values are user-written specifiers, so ranges are legitimate: only
|
|
57
|
+
* a protocol other than `npm:` and `workspace:` is a problem, and a `link:`
|
|
58
|
+
* inside the repository stays allowed.
|
|
59
|
+
*/
|
|
60
|
+
function isUnpublishedOverride(value, repositoryRoot) {
|
|
61
|
+
if (!value.includes(PROTOCOL_SEPARATOR)) return false;
|
|
62
|
+
if (ALLOWED_PROTOCOLS.some((protocol) => value.startsWith(protocol))) return false;
|
|
63
|
+
if (!value.startsWith(LINK_PREFIX)) return true;
|
|
64
|
+
return isUnpublishedSpecifier(value, repositoryRoot, repositoryRoot);
|
|
65
|
+
}
|
|
66
|
+
// src/check_release/release_finding.ts
|
|
67
|
+
const RELEASE_FINDING_KIND = {
|
|
68
|
+
patch: "patch",
|
|
69
|
+
localDependency: "local dependency",
|
|
70
|
+
override: "override"
|
|
71
|
+
};
|
|
72
|
+
// src/check_release/find_release_findings.ts
|
|
73
|
+
const DEPENDENCY_FIELDS = [
|
|
74
|
+
"dependencies",
|
|
75
|
+
"devDependencies",
|
|
76
|
+
"optionalDependencies"
|
|
77
|
+
];
|
|
78
|
+
const PATCH_HINT = "upstream the change, release the lib, bump it, then remove the patch";
|
|
79
|
+
const LOCAL_HINT = "release the lib and depend on a published version";
|
|
80
|
+
function isMinimalstuffPackage(packageName) {
|
|
81
|
+
return packageName.startsWith(MINIMALSTUFF_SCOPE_PREFIX);
|
|
82
|
+
}
|
|
83
|
+
function findPatchFindings(document) {
|
|
84
|
+
const patchedDependencies = document["patchedDependencies"];
|
|
85
|
+
if (!isRecord(patchedDependencies)) return [];
|
|
86
|
+
return Object.keys(patchedDependencies).map(extractPackageName).filter(isMinimalstuffPackage).map((packageName) => ({
|
|
87
|
+
kind: RELEASE_FINDING_KIND.patch,
|
|
88
|
+
packageName,
|
|
89
|
+
location: "patchedDependencies",
|
|
90
|
+
hint: PATCH_HINT
|
|
91
|
+
}));
|
|
92
|
+
}
|
|
93
|
+
function findOverrideFindings(document, repositoryRoot) {
|
|
94
|
+
const overrides = document["overrides"];
|
|
95
|
+
if (!isRecord(overrides)) return [];
|
|
96
|
+
return Object.entries(overrides).filter(([key, value]) => {
|
|
97
|
+
if (!isMinimalstuffPackage(extractPackageName(key))) return false;
|
|
98
|
+
if (typeof value !== "string") return false;
|
|
99
|
+
return isUnpublishedOverride(value, repositoryRoot);
|
|
100
|
+
}).map(([key]) => ({
|
|
101
|
+
kind: RELEASE_FINDING_KIND.override,
|
|
102
|
+
packageName: extractPackageName(key),
|
|
103
|
+
location: "overrides",
|
|
104
|
+
hint: LOCAL_HINT
|
|
105
|
+
}));
|
|
106
|
+
}
|
|
107
|
+
function readInstalledVersion(entry) {
|
|
108
|
+
if (!isRecord(entry)) return void 0;
|
|
109
|
+
const version = entry["version"];
|
|
110
|
+
return typeof version === "string" ? version : void 0;
|
|
111
|
+
}
|
|
112
|
+
function findImporterFindings(importerPath, importer, repositoryRoot) {
|
|
113
|
+
if (!isRecord(importer)) return [];
|
|
114
|
+
const importerDirectory = resolve(repositoryRoot, importerPath);
|
|
115
|
+
return DEPENDENCY_FIELDS.flatMap((field) => {
|
|
116
|
+
const dependencies = importer[field];
|
|
117
|
+
if (!isRecord(dependencies)) return [];
|
|
118
|
+
return Object.entries(dependencies).filter(([packageName, entry]) => {
|
|
119
|
+
if (!isMinimalstuffPackage(packageName)) return false;
|
|
120
|
+
const version = readInstalledVersion(entry);
|
|
121
|
+
if (version === void 0) return false;
|
|
122
|
+
return isUnpublishedSpecifier(version, repositoryRoot, importerDirectory);
|
|
123
|
+
}).map(([packageName]) => ({
|
|
124
|
+
kind: RELEASE_FINDING_KIND.localDependency,
|
|
125
|
+
packageName,
|
|
126
|
+
location: `importer "${importerPath}" (${field})`,
|
|
127
|
+
hint: LOCAL_HINT
|
|
128
|
+
}));
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
function findLocalDependencyFindings(document, repositoryRoot) {
|
|
132
|
+
const importers = document["importers"];
|
|
133
|
+
if (!isRecord(importers)) return [];
|
|
134
|
+
return Object.entries(importers).flatMap(([importerPath, importer]) => findImporterFindings(importerPath, importer, repositoryRoot));
|
|
135
|
+
}
|
|
136
|
+
function findReleaseFindings(documents, repositoryRoot) {
|
|
137
|
+
return documents.filter(isRecord).flatMap((document) => [
|
|
138
|
+
...findPatchFindings(document),
|
|
139
|
+
...findLocalDependencyFindings(document, repositoryRoot),
|
|
140
|
+
...findOverrideFindings(document, repositoryRoot)
|
|
141
|
+
]);
|
|
142
|
+
}
|
|
143
|
+
// src/check_release/format_release_findings.ts
|
|
144
|
+
function formatReleaseFinding(finding) {
|
|
145
|
+
return `${finding.kind}: ${finding.packageName} (${finding.location}). Fix: ${finding.hint}.`;
|
|
146
|
+
}
|
|
147
|
+
function formatSummary(findingCount) {
|
|
148
|
+
return `${findingCount} ${findingCount === 1 ? "finding" : "findings"}: a release must not ship with patched or locally linked @minimalstuff/* packages.`;
|
|
149
|
+
}
|
|
150
|
+
// src/check_release/release_check_error.ts
|
|
151
|
+
var ReleaseCheckError = class extends Error {
|
|
152
|
+
code;
|
|
153
|
+
constructor(code, message) {
|
|
154
|
+
super(message);
|
|
155
|
+
this.name = "ReleaseCheckError";
|
|
156
|
+
this.code = code;
|
|
157
|
+
}
|
|
158
|
+
};
|
|
159
|
+
const E_LOCKFILE_MISSING = "E_LOCKFILE_MISSING";
|
|
160
|
+
const E_LOCKFILE_UNREADABLE = "E_LOCKFILE_UNREADABLE";
|
|
161
|
+
const E_LOCKFILE_INVALID = "E_LOCKFILE_INVALID";
|
|
162
|
+
// src/check_release/parse_lockfile.ts
|
|
163
|
+
/**
|
|
164
|
+
* Parses every YAML document of a pnpm lockfile: pnpm 12 writes an env
|
|
165
|
+
* document before the main one.
|
|
166
|
+
*/
|
|
167
|
+
function parseLockfile(raw, fileName) {
|
|
168
|
+
const documents = parseAllDocuments(raw);
|
|
169
|
+
const firstError = documents.flatMap((document) => document.errors)[0];
|
|
170
|
+
if (firstError) throw new ReleaseCheckError(E_LOCKFILE_INVALID, `${fileName} is not valid YAML: ${firstError.message}`);
|
|
171
|
+
const parsed = documents.map((document) => document.toJS());
|
|
172
|
+
if (!parsed.some((document) => isRecord(document) && "lockfileVersion" in document)) throw new ReleaseCheckError(E_LOCKFILE_INVALID, `${fileName} has no lockfileVersion: it is not a pnpm lockfile`);
|
|
173
|
+
return parsed;
|
|
174
|
+
}
|
|
175
|
+
// src/check_release/read_lockfile.ts
|
|
176
|
+
function isMissingFileError(error) {
|
|
177
|
+
return error instanceof Error && "code" in error && error.code === "ENOENT";
|
|
178
|
+
}
|
|
179
|
+
async function readLockfileText(directory) {
|
|
180
|
+
try {
|
|
181
|
+
return await readFile(join(directory, LOCKFILE_NAME), "utf8");
|
|
182
|
+
} catch (error) {
|
|
183
|
+
if (isMissingFileError(error)) throw new ReleaseCheckError(E_LOCKFILE_MISSING, `No ${LOCKFILE_NAME} found in ${directory}: check-release only supports pnpm projects`);
|
|
184
|
+
const reason = error instanceof Error ? error.message : String(error);
|
|
185
|
+
throw new ReleaseCheckError(E_LOCKFILE_UNREADABLE, `Cannot read ${LOCKFILE_NAME}: ${reason}`);
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
async function readLockfile(directory) {
|
|
189
|
+
return parseLockfile(await readLockfileText(directory), LOCKFILE_NAME);
|
|
190
|
+
}
|
|
191
|
+
// src/check_release/run_check_release.ts
|
|
192
|
+
async function runCheckRelease(directory) {
|
|
193
|
+
try {
|
|
194
|
+
const findings = findReleaseFindings(await readLockfile(directory), directory);
|
|
195
|
+
if (findings.length === 0) {
|
|
196
|
+
console.log(color.green("check-release: no patched or linked @minimalstuff/* package."));
|
|
197
|
+
return 0;
|
|
198
|
+
}
|
|
199
|
+
for (const finding of findings) console.error(color.red(formatReleaseFinding(finding)));
|
|
200
|
+
console.error(formatSummary(findings.length));
|
|
201
|
+
return 1;
|
|
202
|
+
} catch (error) {
|
|
203
|
+
if (!(error instanceof ReleaseCheckError)) throw error;
|
|
204
|
+
console.error(color.red(`check-release: ${error.message}`));
|
|
205
|
+
return 2;
|
|
206
|
+
}
|
|
207
|
+
}
|
|
10
208
|
// src/cli/install_dev_packages.ts
|
|
11
209
|
const DEFAULT_AGENT = "npm";
|
|
12
210
|
const PNPM_WORKSPACE_FILE = "pnpm-workspace.yaml";
|
|
@@ -556,9 +754,22 @@ async function main() {
|
|
|
556
754
|
await installDevPackages(listDevPackages(result), cwd);
|
|
557
755
|
log.success("All done.");
|
|
558
756
|
}
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
757
|
+
function runSetup() {
|
|
758
|
+
main().catch((error) => {
|
|
759
|
+
log.error(error instanceof Error ? error.message : String(error));
|
|
760
|
+
log.info("Files written before the error are kept.");
|
|
761
|
+
process.exit(FAILURE_EXIT_CODE);
|
|
762
|
+
});
|
|
763
|
+
}
|
|
764
|
+
async function runCheckReleaseCommand() {
|
|
765
|
+
process.exitCode = await runCheckRelease(process.cwd());
|
|
766
|
+
}
|
|
767
|
+
function exitWithUnknownSubcommand(subcommand) {
|
|
768
|
+
console.error(`Unknown subcommand "${subcommand}". Valid subcommands: ${CHECK_RELEASE_SUBCOMMAND}. Run without argument for the interactive setup.`);
|
|
769
|
+
process.exit(2);
|
|
770
|
+
}
|
|
771
|
+
const subcommand = process.argv[2];
|
|
772
|
+
if (subcommand === void 0) runSetup();
|
|
773
|
+
else if (subcommand === "check-release") await runCheckReleaseCommand();
|
|
774
|
+
else exitWithUnknownSubcommand(subcommand);
|
|
564
775
|
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@minimalstuff/tooling",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.9.1",
|
|
4
4
|
"description": "Shared tooling configs: EditorConfig, OXC (oxlint + oxfmt), Knip",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"editorconfig",
|
|
@@ -45,7 +45,8 @@
|
|
|
45
45
|
"@antfu/install-pkg": "^2.1.0",
|
|
46
46
|
"@clack/prompts": "^1.8.1",
|
|
47
47
|
"jsonc-parser": "^3.3.1",
|
|
48
|
-
"picocolors": "^1.1.1"
|
|
48
|
+
"picocolors": "^1.1.1",
|
|
49
|
+
"yaml": "^2.9.1"
|
|
49
50
|
},
|
|
50
51
|
"devDependencies": {
|
|
51
52
|
"@adonisjs/eslint-plugin": "^2.2.2",
|
|
@@ -88,9 +89,6 @@
|
|
|
88
89
|
"node": ">=26"
|
|
89
90
|
},
|
|
90
91
|
"release-it": {
|
|
91
|
-
"hooks": {
|
|
92
|
-
"before:init": "pnpm checks"
|
|
93
|
-
},
|
|
94
92
|
"git": {
|
|
95
93
|
"requireCleanWorkingDir": true,
|
|
96
94
|
"requireUpstream": true,
|
|
@@ -126,6 +124,6 @@
|
|
|
126
124
|
"build": "tsdown",
|
|
127
125
|
"checks": "pnpm typecheck && pnpm lint && pnpm format:check && pnpm knip && pnpm test && pnpm build",
|
|
128
126
|
"release": "release-it",
|
|
129
|
-
"release:next": "release-it --preRelease=next --plugins.@release-it/keep-a-changelog.keepUnreleased"
|
|
127
|
+
"release:next": "release-it --preRelease=next --plugins.@release-it/keep-a-changelog.keepUnreleased=true"
|
|
130
128
|
}
|
|
131
129
|
}
|