@helderberto/release 0.0.0-stage → 0.1.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/LICENSE +21 -0
- package/README.md +24 -2
- package/dist/bump-version.d.ts +9 -0
- package/dist/bump-version.js +25 -0
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +11 -0
- package/dist/commits.d.ts +14 -0
- package/dist/commits.js +27 -0
- package/dist/constants.d.ts +23 -0
- package/dist/constants.js +23 -0
- package/dist/context.d.ts +9 -0
- package/dist/context.js +1 -0
- package/dist/cut.d.ts +10 -0
- package/dist/cut.js +47 -0
- package/dist/draft-changelog.d.ts +9 -0
- package/dist/draft-changelog.js +47 -0
- package/dist/draft.d.ts +2 -0
- package/dist/draft.js +48 -0
- package/dist/git.d.ts +21 -0
- package/dist/git.js +26 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.js +5 -0
- package/dist/main.d.ts +10 -0
- package/dist/main.js +68 -0
- package/dist/next-release.d.ts +10 -0
- package/dist/next-release.js +44 -0
- package/dist/package-json.d.ts +8 -0
- package/dist/package-json.js +34 -0
- package/dist/publish.d.ts +2 -0
- package/dist/publish.js +65 -0
- package/dist/runner.d.ts +8 -0
- package/dist/runner.js +25 -0
- package/dist/tags.d.ts +5 -0
- package/dist/tags.js +3 -0
- package/dist/types.d.ts +8 -0
- package/dist/types.js +1 -0
- package/dist/workspace.d.ts +17 -0
- package/dist/workspace.js +85 -0
- package/package.json +34 -3
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Helder Berto
|
|
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,3 +1,25 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @helderberto/release
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
[](https://www.npmjs.com/package/@helderberto/release)
|
|
4
|
+
|
|
5
|
+
Release CLI for npm and pnpm projects, single-package or monorepo: draft the changelog from commits, edit it, then cut and publish.
|
|
6
|
+
|
|
7
|
+
## Install
|
|
8
|
+
|
|
9
|
+
```sh
|
|
10
|
+
npm install -D @helderberto/release
|
|
11
|
+
npm pkg set scripts.release=release
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
`package.json` needs a `repository` URL, for the changelog links.
|
|
15
|
+
|
|
16
|
+
## Use
|
|
17
|
+
|
|
18
|
+
1. `npm run release -- draft` writes commits since the last release under `## [Unreleased]` in `CHANGELOG.md`: `feat` under Added, `fix` under Fixed, anything that isn't a Conventional Commit under Changed.
|
|
19
|
+
2. Edit the entries by hand and commit.
|
|
20
|
+
3. `npm run release -- cut` picks the next version from the entries per Keep a Changelog and SemVer, moves them under it, bumps `package.json`, commits and tags.
|
|
21
|
+
4. `npm run release -- publish` publishes what isn't on npm yet. In a pnpm workspace it packs with pnpm, resolving `workspace:` and `catalog:` versions, and publishes the tarball with npm.
|
|
22
|
+
|
|
23
|
+
Every command takes `--dry-run`. In a monorepo, `--package <name>` limits a command to one package. `publish --otp <code>` passes a one-time password to npm.
|
|
24
|
+
|
|
25
|
+
Tags are `vX.Y.Z` in a single-package repo and `<name>@x.y.z` in a monorepo. In GitHub Actions, `cut` writes the releases to `GITHUB_OUTPUT` for a later step to create GitHub releases; [this repo's `release.yml`](https://github.com/helderberto/coding-standards/blob/main/.github/workflows/release.yml) shows how, with npm trusted publishing.
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { Bump } from './types.ts';
|
|
2
|
+
export declare function bumpOf({ sections, breaking, }: {
|
|
3
|
+
sections: readonly string[];
|
|
4
|
+
breaking: boolean;
|
|
5
|
+
}): Bump | null;
|
|
6
|
+
export declare function bumpVersion({ current, bump }: {
|
|
7
|
+
current: string;
|
|
8
|
+
bump: Bump;
|
|
9
|
+
}): string;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { BUMPS, SECTION_BUMPS } from './constants.js';
|
|
2
|
+
function isSection(name) {
|
|
3
|
+
return Object.hasOwn(SECTION_BUMPS, name);
|
|
4
|
+
}
|
|
5
|
+
export function bumpOf({ sections, breaking, }) {
|
|
6
|
+
if (breaking) {
|
|
7
|
+
return 'major';
|
|
8
|
+
}
|
|
9
|
+
const bumps = sections.filter(isSection).map((name) => SECTION_BUMPS[name]);
|
|
10
|
+
return BUMPS.find((bump) => bumps.includes(bump)) ?? null;
|
|
11
|
+
}
|
|
12
|
+
export function bumpVersion({ current, bump }) {
|
|
13
|
+
const match = /^(\d+)\.(\d+)\.(\d+)$/.exec(current);
|
|
14
|
+
if (!match) {
|
|
15
|
+
throw new Error(`${current} is not a x.y.z version`);
|
|
16
|
+
}
|
|
17
|
+
const [major = 0, minor = 0, patch = 0] = match.slice(1).map(Number);
|
|
18
|
+
if (bump === 'major' && major > 0) {
|
|
19
|
+
return `${major + 1}.0.0`;
|
|
20
|
+
}
|
|
21
|
+
if (bump === 'patch') {
|
|
22
|
+
return `${major}.${minor}.${patch + 1}`;
|
|
23
|
+
}
|
|
24
|
+
return `${major}.${minor + 1}.0`;
|
|
25
|
+
}
|
package/dist/cli.d.ts
ADDED
package/dist/cli.js
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { main } from './main.js';
|
|
3
|
+
import { run } from './runner.js';
|
|
4
|
+
process.exitCode = await main({
|
|
5
|
+
argv: process.argv.slice(2),
|
|
6
|
+
env: process.env,
|
|
7
|
+
root: process.cwd(),
|
|
8
|
+
run,
|
|
9
|
+
log: console.log,
|
|
10
|
+
date: new Date().toISOString().slice(0, 10),
|
|
11
|
+
});
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export interface Commit {
|
|
2
|
+
readonly type: string;
|
|
3
|
+
readonly breaking: boolean;
|
|
4
|
+
readonly description: string;
|
|
5
|
+
}
|
|
6
|
+
export interface Entry {
|
|
7
|
+
readonly section: string;
|
|
8
|
+
readonly line: string;
|
|
9
|
+
}
|
|
10
|
+
export declare function parseCommit({ subject, body }: {
|
|
11
|
+
subject: string;
|
|
12
|
+
body: string;
|
|
13
|
+
}): Commit | null;
|
|
14
|
+
export declare function entryOf({ type, breaking, description }: Commit): Entry | null;
|
package/dist/commits.js
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { BREAKING_MARK, COMMIT_SECTIONS } from './constants.js';
|
|
2
|
+
const SUBJECT = /^(\w+)(?:\([^)]*\))?(!)?: (.+)$/;
|
|
3
|
+
const BREAKING_FOOTER = /^BREAKING[ -]CHANGE: /m;
|
|
4
|
+
const BREAKING_SECTION = 'Changed';
|
|
5
|
+
const UNTYPED_SECTION = 'Changed';
|
|
6
|
+
const MERGE = /^Merge /;
|
|
7
|
+
function isCommitType(type) {
|
|
8
|
+
return Object.hasOwn(COMMIT_SECTIONS, type);
|
|
9
|
+
}
|
|
10
|
+
export function parseCommit({ subject, body }) {
|
|
11
|
+
if (MERGE.test(subject)) {
|
|
12
|
+
return null;
|
|
13
|
+
}
|
|
14
|
+
const match = SUBJECT.exec(subject);
|
|
15
|
+
if (!match) {
|
|
16
|
+
return { type: '', breaking: BREAKING_FOOTER.test(body), description: subject };
|
|
17
|
+
}
|
|
18
|
+
const [, type = '', bang, description = ''] = match;
|
|
19
|
+
return { type, breaking: bang === '!' || BREAKING_FOOTER.test(body), description };
|
|
20
|
+
}
|
|
21
|
+
export function entryOf({ type, breaking, description }) {
|
|
22
|
+
const section = isCommitType(type) ? COMMIT_SECTIONS[type] : type === '' ? UNTYPED_SECTION : null;
|
|
23
|
+
if (breaking) {
|
|
24
|
+
return { section: section ?? BREAKING_SECTION, line: `- ${BREAKING_MARK} ${description}` };
|
|
25
|
+
}
|
|
26
|
+
return section === null ? null : { section, line: `- ${description}` };
|
|
27
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
export declare const BUMPS: readonly ['major', 'minor', 'patch'];
|
|
2
|
+
export declare const SECTION_BUMPS: {
|
|
3
|
+
readonly Removed: 'major';
|
|
4
|
+
readonly Added: 'minor';
|
|
5
|
+
readonly Changed: 'minor';
|
|
6
|
+
readonly Deprecated: 'minor';
|
|
7
|
+
readonly Fixed: 'patch';
|
|
8
|
+
readonly Security: 'patch';
|
|
9
|
+
};
|
|
10
|
+
export declare const SECTIONS: string[];
|
|
11
|
+
export declare const UNRELEASED: RegExp;
|
|
12
|
+
export declare const COMMIT_SECTIONS: {
|
|
13
|
+
readonly feat: 'Added';
|
|
14
|
+
readonly fix: 'Fixed';
|
|
15
|
+
readonly perf: 'Changed';
|
|
16
|
+
readonly revert: 'Changed';
|
|
17
|
+
};
|
|
18
|
+
export declare const BREAKING_MARK = "**Breaking:**";
|
|
19
|
+
export declare const MISSING_UNRELEASED = "CHANGELOG.md needs a ## [Unreleased] section and an [unreleased]: link";
|
|
20
|
+
export declare const PACKAGE_MANAGERS: {
|
|
21
|
+
readonly npm: 'npm';
|
|
22
|
+
readonly pnpm: 'pnpm';
|
|
23
|
+
};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
export const BUMPS = ['major', 'minor', 'patch'];
|
|
2
|
+
export const SECTION_BUMPS = {
|
|
3
|
+
Removed: 'major',
|
|
4
|
+
Added: 'minor',
|
|
5
|
+
Changed: 'minor',
|
|
6
|
+
Deprecated: 'minor',
|
|
7
|
+
Fixed: 'patch',
|
|
8
|
+
Security: 'patch',
|
|
9
|
+
};
|
|
10
|
+
export const SECTIONS = ['Added', 'Changed', 'Deprecated', 'Removed', 'Fixed', 'Security'];
|
|
11
|
+
export const UNRELEASED = /## \[Unreleased\]\n([\s\S]*?)(?=\n## \[|\n\[unreleased\]:)/i;
|
|
12
|
+
export const COMMIT_SECTIONS = {
|
|
13
|
+
feat: 'Added',
|
|
14
|
+
fix: 'Fixed',
|
|
15
|
+
perf: 'Changed',
|
|
16
|
+
revert: 'Changed',
|
|
17
|
+
};
|
|
18
|
+
export const BREAKING_MARK = '**Breaking:**';
|
|
19
|
+
export const MISSING_UNRELEASED = 'CHANGELOG.md needs a ## [Unreleased] section and an [unreleased]: link';
|
|
20
|
+
export const PACKAGE_MANAGERS = {
|
|
21
|
+
npm: 'npm',
|
|
22
|
+
pnpm: 'pnpm',
|
|
23
|
+
};
|
package/dist/context.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/cut.d.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { Context } from './context.ts';
|
|
2
|
+
export interface Cut {
|
|
3
|
+
readonly name: string;
|
|
4
|
+
readonly version: string;
|
|
5
|
+
readonly tag: string;
|
|
6
|
+
readonly notes: string;
|
|
7
|
+
}
|
|
8
|
+
export declare function cut(context: Context & {
|
|
9
|
+
date: string;
|
|
10
|
+
}): Promise<Cut[]>;
|
package/dist/cut.js
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { readFile, writeFile } from 'node:fs/promises';
|
|
2
|
+
import { join } from 'node:path';
|
|
3
|
+
import { commitRelease } from './git.js';
|
|
4
|
+
import { nextRelease } from './next-release.js';
|
|
5
|
+
import { readManifest } from './package-json.js';
|
|
6
|
+
import { tagFormat } from './tags.js';
|
|
7
|
+
import { findPackages } from './workspace.js';
|
|
8
|
+
async function cutPackage({ context, monorepo, pkg }) {
|
|
9
|
+
const { root, run, log, dryRun, date } = context;
|
|
10
|
+
const changelogPath = join(pkg.dir, 'CHANGELOG.md');
|
|
11
|
+
const changelog = await readFile(changelogPath, 'utf8').catch(() => null);
|
|
12
|
+
if (changelog === null) {
|
|
13
|
+
log(`${pkg.name}: no CHANGELOG.md`);
|
|
14
|
+
return null;
|
|
15
|
+
}
|
|
16
|
+
const tagOf = tagFormat({ monorepo, name: pkg.name });
|
|
17
|
+
const release = nextRelease({ changelog, current: pkg.version, date, tagOf });
|
|
18
|
+
if (release === null) {
|
|
19
|
+
log(`${pkg.name}: nothing under [Unreleased]`);
|
|
20
|
+
return null;
|
|
21
|
+
}
|
|
22
|
+
const tag = tagOf(release.version);
|
|
23
|
+
const result = { name: pkg.name, version: release.version, tag, notes: release.notes };
|
|
24
|
+
if (dryRun) {
|
|
25
|
+
log(`${pkg.name}: would release ${tag}`);
|
|
26
|
+
return result;
|
|
27
|
+
}
|
|
28
|
+
const manifestPath = join(pkg.dir, 'package.json');
|
|
29
|
+
const manifest = await readManifest(pkg.dir);
|
|
30
|
+
await writeFile(changelogPath, release.changelog);
|
|
31
|
+
await writeFile(manifestPath, `${JSON.stringify({ ...manifest, version: release.version }, null, 2)}\n`);
|
|
32
|
+
await commitRelease({ run, cwd: root, files: [changelogPath, manifestPath], tag });
|
|
33
|
+
log(`${pkg.name}: released ${tag}`);
|
|
34
|
+
return result;
|
|
35
|
+
}
|
|
36
|
+
export async function cut(context) {
|
|
37
|
+
const { monorepo, packages } = await findPackages({
|
|
38
|
+
root: context.root,
|
|
39
|
+
name: context.packageName,
|
|
40
|
+
});
|
|
41
|
+
// Each release commits and tags, so packages run one after another.
|
|
42
|
+
return packages.reduce(async (previous, pkg) => {
|
|
43
|
+
const cuts = await previous;
|
|
44
|
+
const result = await cutPackage({ context, monorepo, pkg });
|
|
45
|
+
return result === null ? cuts : [...cuts, result];
|
|
46
|
+
}, Promise.resolve([]));
|
|
47
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { Entry } from './commits.ts';
|
|
2
|
+
export declare function draftChangelog({ changelog, entries, }: {
|
|
3
|
+
changelog: string;
|
|
4
|
+
entries: readonly Entry[];
|
|
5
|
+
}): string;
|
|
6
|
+
export declare function newChangelog({ name, repo }: {
|
|
7
|
+
name: string;
|
|
8
|
+
repo: string;
|
|
9
|
+
}): string;
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { MISSING_UNRELEASED, SECTIONS, UNRELEASED } from './constants.js';
|
|
2
|
+
function parseSections(body) {
|
|
3
|
+
const [prefix = '', ...rest] = body.split(/^### /m);
|
|
4
|
+
const sections = rest.map((part) => {
|
|
5
|
+
const [name = '', ...lines] = part.split('\n');
|
|
6
|
+
return { name: name.trim(), content: lines.join('\n').trim() };
|
|
7
|
+
});
|
|
8
|
+
return { prefix: prefix.trim(), sections };
|
|
9
|
+
}
|
|
10
|
+
function addEntry(sections, entry) {
|
|
11
|
+
const existing = sections.find((section) => section.name === entry.section);
|
|
12
|
+
if (!existing) {
|
|
13
|
+
return [...sections, { name: entry.section, content: entry.line }];
|
|
14
|
+
}
|
|
15
|
+
return sections.map((section) => section === existing
|
|
16
|
+
? { name: section.name, content: [section.content, entry.line].filter(Boolean).join('\n') }
|
|
17
|
+
: section);
|
|
18
|
+
}
|
|
19
|
+
function rank(name) {
|
|
20
|
+
const index = SECTIONS.indexOf(name);
|
|
21
|
+
return index === -1 ? SECTIONS.length : index;
|
|
22
|
+
}
|
|
23
|
+
export function draftChangelog({ changelog, entries, }) {
|
|
24
|
+
const unreleased = UNRELEASED.exec(changelog);
|
|
25
|
+
if (!unreleased) {
|
|
26
|
+
throw new Error(MISSING_UNRELEASED);
|
|
27
|
+
}
|
|
28
|
+
const body = unreleased[1] ?? '';
|
|
29
|
+
const parsed = parseSections(body);
|
|
30
|
+
const sections = entries.reduce((all, entry) => all.some((section) => section.content.split('\n').includes(entry.line))
|
|
31
|
+
? all
|
|
32
|
+
: addEntry(all, entry), parsed.sections);
|
|
33
|
+
const blocks = [
|
|
34
|
+
parsed.prefix,
|
|
35
|
+
...sections
|
|
36
|
+
.toSorted((a, b) => rank(a.name) - rank(b.name))
|
|
37
|
+
.map(({ name, content }) => [`### ${name}`, content].filter(Boolean).join('\n\n')),
|
|
38
|
+
].filter(Boolean);
|
|
39
|
+
const drafted = blocks.length === 0 ? '' : `\n${blocks.join('\n\n')}\n`;
|
|
40
|
+
return changelog.replace(unreleased[0], `## [Unreleased]\n${drafted}`);
|
|
41
|
+
}
|
|
42
|
+
export function newChangelog({ name, repo }) {
|
|
43
|
+
return (`# Changelog\n\nAll notable changes to ${name} are documented in this file.\n\n` +
|
|
44
|
+
'The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),\n' +
|
|
45
|
+
'and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).\n\n' +
|
|
46
|
+
`## [Unreleased]\n\n[unreleased]: ${repo}/commits/main\n`);
|
|
47
|
+
}
|
package/dist/draft.d.ts
ADDED
package/dist/draft.js
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { readFile, writeFile } from 'node:fs/promises';
|
|
2
|
+
import { join } from 'node:path';
|
|
3
|
+
import { entryOf, parseCommit } from './commits.js';
|
|
4
|
+
import { draftChangelog, newChangelog } from './draft-changelog.js';
|
|
5
|
+
import { commitsSince, tagExists } from './git.js';
|
|
6
|
+
import { readManifest, repoUrl } from './package-json.js';
|
|
7
|
+
import { tagFormat } from './tags.js';
|
|
8
|
+
import { findPackages } from './workspace.js';
|
|
9
|
+
async function repoOf({ root, pkg }) {
|
|
10
|
+
const repo = repoUrl(await readManifest(pkg.dir)) ?? repoUrl(await readManifest(root));
|
|
11
|
+
if (repo === null) {
|
|
12
|
+
throw new Error(`${pkg.name}: set "repository" in package.json to link the changelog`);
|
|
13
|
+
}
|
|
14
|
+
return repo;
|
|
15
|
+
}
|
|
16
|
+
async function changelogOf({ root, pkg }) {
|
|
17
|
+
const existing = await readFile(join(pkg.dir, 'CHANGELOG.md'), 'utf8').catch(() => null);
|
|
18
|
+
return existing ?? newChangelog({ name: pkg.name, repo: await repoOf({ root, pkg }) });
|
|
19
|
+
}
|
|
20
|
+
async function entriesOf({ context, pkg, from, }) {
|
|
21
|
+
const commits = await commitsSince({ run: context.run, cwd: context.root, from, path: pkg.path });
|
|
22
|
+
return commits.flatMap((raw) => {
|
|
23
|
+
const commit = parseCommit(raw);
|
|
24
|
+
const entry = commit === null ? null : entryOf(commit);
|
|
25
|
+
return entry === null ? [] : [entry];
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
export async function draft(context) {
|
|
29
|
+
const { root, run, log, dryRun, packageName } = context;
|
|
30
|
+
const { monorepo, packages } = await findPackages({ root, name: packageName });
|
|
31
|
+
for (const pkg of packages) {
|
|
32
|
+
const tag = tagFormat({ monorepo, name: pkg.name })(pkg.version);
|
|
33
|
+
const from = (await tagExists({ run, cwd: root, tag })) ? tag : null;
|
|
34
|
+
const entries = await entriesOf({ context, pkg, from });
|
|
35
|
+
if (entries.length === 0) {
|
|
36
|
+
log(`${pkg.name}: no changes since ${from ?? 'the first commit'}`);
|
|
37
|
+
continue;
|
|
38
|
+
}
|
|
39
|
+
const drafted = draftChangelog({ changelog: await changelogOf({ root, pkg }), entries });
|
|
40
|
+
const path = join(pkg.path, 'CHANGELOG.md');
|
|
41
|
+
if (dryRun) {
|
|
42
|
+
log(`${pkg.name}: would write ${path}\n${drafted}`);
|
|
43
|
+
continue;
|
|
44
|
+
}
|
|
45
|
+
await writeFile(join(pkg.dir, 'CHANGELOG.md'), drafted);
|
|
46
|
+
log(`${pkg.name}: drafted ${entries.length} ${entries.length === 1 ? 'entry' : 'entries'} in ${path}`);
|
|
47
|
+
}
|
|
48
|
+
}
|
package/dist/git.d.ts
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { Run } from './runner.ts';
|
|
2
|
+
interface GitOptions {
|
|
3
|
+
readonly run: Run;
|
|
4
|
+
readonly cwd: string;
|
|
5
|
+
}
|
|
6
|
+
export interface RawCommit {
|
|
7
|
+
readonly subject: string;
|
|
8
|
+
readonly body: string;
|
|
9
|
+
}
|
|
10
|
+
export declare function tagExists({ tag, ...options }: GitOptions & {
|
|
11
|
+
tag: string;
|
|
12
|
+
}): Promise<boolean>;
|
|
13
|
+
export declare function commitsSince({ from, path, ...options }: GitOptions & {
|
|
14
|
+
from: string | null;
|
|
15
|
+
path: string;
|
|
16
|
+
}): Promise<RawCommit[]>;
|
|
17
|
+
export declare function commitRelease({ files, tag, ...options }: GitOptions & {
|
|
18
|
+
files: readonly string[];
|
|
19
|
+
tag: string;
|
|
20
|
+
}): Promise<void>;
|
|
21
|
+
export {};
|
package/dist/git.js
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
const FIELD = '\x1f';
|
|
2
|
+
const RECORD = '\x1e';
|
|
3
|
+
function git({ run, cwd }, args) {
|
|
4
|
+
return run({ cmd: 'git', args, cwd });
|
|
5
|
+
}
|
|
6
|
+
export async function tagExists({ tag, ...options }) {
|
|
7
|
+
const tags = await git(options, ['tag', '--list', tag]);
|
|
8
|
+
return tags.split('\n').includes(tag);
|
|
9
|
+
}
|
|
10
|
+
export async function commitsSince({ from, path, ...options }) {
|
|
11
|
+
const range = from === null ? [] : [`${from}..HEAD`];
|
|
12
|
+
const log = await git(options, ['log', '--format=%s%x1f%b%x1e', ...range, '--', path]);
|
|
13
|
+
return log
|
|
14
|
+
.split(RECORD)
|
|
15
|
+
.map((record) => record.trim())
|
|
16
|
+
.filter(Boolean)
|
|
17
|
+
.map((record) => {
|
|
18
|
+
const [subject = '', body = ''] = record.split(FIELD);
|
|
19
|
+
return { subject: subject.trim(), body: body.trim() };
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
export async function commitRelease({ files, tag, ...options }) {
|
|
23
|
+
await git(options, ['add', '--', ...files]);
|
|
24
|
+
await git(options, ['commit', '--message', `chore(release): ${tag}`]);
|
|
25
|
+
await git(options, ['tag', tag]);
|
|
26
|
+
}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export { cut } from './cut.ts';
|
|
2
|
+
export type { Cut } from './cut.ts';
|
|
3
|
+
export { draft } from './draft.ts';
|
|
4
|
+
export { main } from './main.ts';
|
|
5
|
+
export type { MainOptions } from './main.ts';
|
|
6
|
+
export { publish } from './publish.ts';
|
|
7
|
+
export { run } from './runner.ts';
|
|
8
|
+
export type { Command, Run } from './runner.ts';
|
package/dist/index.js
ADDED
package/dist/main.d.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { Run } from './runner.ts';
|
|
2
|
+
export interface MainOptions {
|
|
3
|
+
readonly argv: readonly string[];
|
|
4
|
+
readonly env: Readonly<Record<string, string | undefined>>;
|
|
5
|
+
readonly root: string;
|
|
6
|
+
readonly run: Run;
|
|
7
|
+
readonly log: (line: string) => void;
|
|
8
|
+
readonly date: string;
|
|
9
|
+
}
|
|
10
|
+
export declare function main(options: MainOptions): Promise<number>;
|
package/dist/main.js
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { appendFile, mkdtemp, writeFile } from 'node:fs/promises';
|
|
2
|
+
import { tmpdir } from 'node:os';
|
|
3
|
+
import { join } from 'node:path';
|
|
4
|
+
import { parseArgs } from 'node:util';
|
|
5
|
+
import { cut } from './cut.js';
|
|
6
|
+
import { draft } from './draft.js';
|
|
7
|
+
import { publish } from './publish.js';
|
|
8
|
+
const USAGE = 'Usage: release <draft|cut|publish> [--package <name>] [--dry-run] [--otp <code>]';
|
|
9
|
+
async function toGitHubOutput({ output, cuts }) {
|
|
10
|
+
const dir = await mkdtemp(join(tmpdir(), 'release-notes-'));
|
|
11
|
+
const releases = await Promise.all(cuts.map(async ({ name, version, tag, notes }) => {
|
|
12
|
+
const notesFile = join(dir, `${tag.replace(/[^\w.-]/g, '-')}.md`);
|
|
13
|
+
await writeFile(notesFile, `${notes}\n`);
|
|
14
|
+
return { name, version, tag, notesFile };
|
|
15
|
+
}));
|
|
16
|
+
await appendFile(output, `releases=${JSON.stringify(releases)}\n`);
|
|
17
|
+
}
|
|
18
|
+
async function dispatch({ command, context, options, }) {
|
|
19
|
+
if (command === 'draft') {
|
|
20
|
+
await draft(context);
|
|
21
|
+
return true;
|
|
22
|
+
}
|
|
23
|
+
if (command === 'publish') {
|
|
24
|
+
await publish(context);
|
|
25
|
+
return true;
|
|
26
|
+
}
|
|
27
|
+
if (command !== 'cut') {
|
|
28
|
+
return false;
|
|
29
|
+
}
|
|
30
|
+
const cuts = await cut({ ...context, date: options.date });
|
|
31
|
+
const output = options.env['GITHUB_OUTPUT'];
|
|
32
|
+
if (output && !context.dryRun) {
|
|
33
|
+
await toGitHubOutput({ output, cuts });
|
|
34
|
+
}
|
|
35
|
+
return true;
|
|
36
|
+
}
|
|
37
|
+
export async function main(options) {
|
|
38
|
+
const { argv, root, run, log } = options;
|
|
39
|
+
try {
|
|
40
|
+
const { positionals, values } = parseArgs({
|
|
41
|
+
args: [...argv],
|
|
42
|
+
allowPositionals: true,
|
|
43
|
+
options: {
|
|
44
|
+
package: { type: 'string' },
|
|
45
|
+
'dry-run': { type: 'boolean', default: false },
|
|
46
|
+
otp: { type: 'string' },
|
|
47
|
+
},
|
|
48
|
+
});
|
|
49
|
+
const context = {
|
|
50
|
+
root,
|
|
51
|
+
run,
|
|
52
|
+
log,
|
|
53
|
+
dryRun: values['dry-run'],
|
|
54
|
+
packageName: values.package,
|
|
55
|
+
otp: values.otp,
|
|
56
|
+
};
|
|
57
|
+
const known = positionals.length === 1 && (await dispatch({ command: positionals[0], context, options }));
|
|
58
|
+
if (!known) {
|
|
59
|
+
log(USAGE);
|
|
60
|
+
return 1;
|
|
61
|
+
}
|
|
62
|
+
return 0;
|
|
63
|
+
}
|
|
64
|
+
catch (error) {
|
|
65
|
+
log(error instanceof Error ? error.message : String(error));
|
|
66
|
+
return 1;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { Release } from './types.ts';
|
|
2
|
+
type TagOf = (version: string) => string;
|
|
3
|
+
export declare function sectionsWithEntries(body: string): string[];
|
|
4
|
+
export declare function nextRelease({ changelog, current, date, tagOf, }: {
|
|
5
|
+
changelog: string;
|
|
6
|
+
current: string;
|
|
7
|
+
date: string;
|
|
8
|
+
tagOf: TagOf;
|
|
9
|
+
}): Release | null;
|
|
10
|
+
export {};
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { bumpOf, bumpVersion } from './bump-version.js';
|
|
2
|
+
import { BREAKING_MARK, MISSING_UNRELEASED, UNRELEASED } from './constants.js';
|
|
3
|
+
const UNRELEASED_LINK = /^\[(unreleased)\]: (\S+?)\/(?:commits|compare)\/\S+$/im;
|
|
4
|
+
const RELEASED = /^## \[\d+\.\d+\.\d+\]/m;
|
|
5
|
+
export function sectionsWithEntries(body) {
|
|
6
|
+
return body
|
|
7
|
+
.split(/^### /m)
|
|
8
|
+
.slice(1)
|
|
9
|
+
.filter((section) => /^- /m.test(section))
|
|
10
|
+
.map((section) => (section.split('\n')[0] ?? '').trim());
|
|
11
|
+
}
|
|
12
|
+
function releaseLink({ repo, previous, next, tagOf, }) {
|
|
13
|
+
if (previous === null) {
|
|
14
|
+
return `${repo}/releases/tag/${encodeURIComponent(tagOf(next))}`;
|
|
15
|
+
}
|
|
16
|
+
return `${repo}/compare/${tagOf(previous)}...${tagOf(next)}`;
|
|
17
|
+
}
|
|
18
|
+
export function nextRelease({ changelog, current, date, tagOf, }) {
|
|
19
|
+
const unreleased = UNRELEASED.exec(changelog);
|
|
20
|
+
const link = UNRELEASED_LINK.exec(changelog);
|
|
21
|
+
if (!unreleased || !link) {
|
|
22
|
+
throw new Error(MISSING_UNRELEASED);
|
|
23
|
+
}
|
|
24
|
+
const body = (unreleased[1] ?? '').trim();
|
|
25
|
+
const bump = bumpOf({
|
|
26
|
+
sections: sectionsWithEntries(body),
|
|
27
|
+
breaking: body.includes(BREAKING_MARK),
|
|
28
|
+
});
|
|
29
|
+
if (bump === null) {
|
|
30
|
+
return null;
|
|
31
|
+
}
|
|
32
|
+
const version = bumpVersion({ current, bump });
|
|
33
|
+
const [, label, repo = ''] = link;
|
|
34
|
+
const previous = RELEASED.test(changelog) ? current : null;
|
|
35
|
+
const links = `[${label}]: ${repo}/compare/${tagOf(version)}...HEAD\n` +
|
|
36
|
+
`[${version}]: ${releaseLink({ repo, previous, next: version, tagOf })}`;
|
|
37
|
+
return {
|
|
38
|
+
version,
|
|
39
|
+
notes: body,
|
|
40
|
+
changelog: changelog
|
|
41
|
+
.replace(unreleased[0], `## [Unreleased]\n\n## [${version}] - ${date}\n\n${body}\n`)
|
|
42
|
+
.replace(link[0], links),
|
|
43
|
+
};
|
|
44
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export type Manifest = Readonly<Record<string, unknown>>;
|
|
2
|
+
export declare function readManifest(dir: string): Promise<Manifest>;
|
|
3
|
+
export declare function stringField({ manifest, key }: {
|
|
4
|
+
manifest: Manifest;
|
|
5
|
+
key: string;
|
|
6
|
+
}): string | null;
|
|
7
|
+
export declare function stringList(value: unknown): string[];
|
|
8
|
+
export declare function repoUrl(manifest: Manifest): string | null;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { readFile } from 'node:fs/promises';
|
|
2
|
+
import { join } from 'node:path';
|
|
3
|
+
function isManifest(value) {
|
|
4
|
+
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
5
|
+
}
|
|
6
|
+
export async function readManifest(dir) {
|
|
7
|
+
const value = JSON.parse(await readFile(join(dir, 'package.json'), 'utf8'));
|
|
8
|
+
if (!isManifest(value)) {
|
|
9
|
+
throw new Error(`${join(dir, 'package.json')} is not an object`);
|
|
10
|
+
}
|
|
11
|
+
return value;
|
|
12
|
+
}
|
|
13
|
+
export function stringField({ manifest, key }) {
|
|
14
|
+
const value = manifest[key];
|
|
15
|
+
return typeof value === 'string' ? value : null;
|
|
16
|
+
}
|
|
17
|
+
export function stringList(value) {
|
|
18
|
+
if (isManifest(value)) {
|
|
19
|
+
return stringList(value['packages']);
|
|
20
|
+
}
|
|
21
|
+
return Array.isArray(value) ? value.filter((item) => typeof item === 'string') : [];
|
|
22
|
+
}
|
|
23
|
+
export function repoUrl(manifest) {
|
|
24
|
+
const repository = manifest['repository'];
|
|
25
|
+
const url = isManifest(repository) ? repository['url'] : repository;
|
|
26
|
+
if (typeof url !== 'string') {
|
|
27
|
+
return null;
|
|
28
|
+
}
|
|
29
|
+
const shorthand = /^(?:github:)?([\w.-]+\/[\w.-]+)$/.exec(url);
|
|
30
|
+
if (shorthand) {
|
|
31
|
+
return `https://github.com/${shorthand[1]}`;
|
|
32
|
+
}
|
|
33
|
+
return url.replace(/^git\+/, '').replace(/\.git$/, '');
|
|
34
|
+
}
|
package/dist/publish.js
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { mkdtemp, readdir, rm } from 'node:fs/promises';
|
|
2
|
+
import { tmpdir } from 'node:os';
|
|
3
|
+
import { join } from 'node:path';
|
|
4
|
+
import { PACKAGE_MANAGERS } from './constants.js';
|
|
5
|
+
import { findPackages, packageManagerOf } from './workspace.js';
|
|
6
|
+
async function isPublished({ run, pkg }) {
|
|
7
|
+
const spec = `${pkg.name}@${pkg.version}`;
|
|
8
|
+
const found = await run({ cmd: 'npm', args: ['view', spec, 'version'], cwd: pkg.dir }).catch(() => '');
|
|
9
|
+
return found.trim() === pkg.version;
|
|
10
|
+
}
|
|
11
|
+
function publishArgs({ context, target }) {
|
|
12
|
+
const otp = context.otp === undefined ? [] : [`--otp=${context.otp}`];
|
|
13
|
+
return ['publish', ...target, ...(context.dryRun ? ['--dry-run'] : []), ...otp];
|
|
14
|
+
}
|
|
15
|
+
// pnpm pack resolves workspace: and catalog: versions; npm publish keeps trusted publishing.
|
|
16
|
+
async function publishPacked({ context, pkg }) {
|
|
17
|
+
const destination = await mkdtemp(join(tmpdir(), 'release-pack-'));
|
|
18
|
+
try {
|
|
19
|
+
await context.run({
|
|
20
|
+
cmd: 'pnpm',
|
|
21
|
+
args: ['pack', '--pack-destination', destination],
|
|
22
|
+
cwd: pkg.dir,
|
|
23
|
+
});
|
|
24
|
+
const tarball = (await readdir(destination)).find((file) => file.endsWith('.tgz'));
|
|
25
|
+
if (tarball === undefined) {
|
|
26
|
+
throw new Error(`${pkg.name}: pnpm pack wrote no tarball`);
|
|
27
|
+
}
|
|
28
|
+
await context.run({
|
|
29
|
+
cmd: 'npm',
|
|
30
|
+
args: publishArgs({ context, target: [join(destination, tarball)] }),
|
|
31
|
+
cwd: pkg.dir,
|
|
32
|
+
interactive: true,
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
finally {
|
|
36
|
+
await rm(destination, { recursive: true, force: true });
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
export async function publish(context) {
|
|
40
|
+
const { root, run, log, dryRun, packageName } = context;
|
|
41
|
+
const { packages } = await findPackages({ root, name: packageName });
|
|
42
|
+
const packageManager = await packageManagerOf(root);
|
|
43
|
+
for (const pkg of packages) {
|
|
44
|
+
if (pkg.private) {
|
|
45
|
+
log(`${pkg.name}: private, not published`);
|
|
46
|
+
continue;
|
|
47
|
+
}
|
|
48
|
+
if (await isPublished({ run, pkg })) {
|
|
49
|
+
log(`${pkg.name}: ${pkg.version} is already published`);
|
|
50
|
+
continue;
|
|
51
|
+
}
|
|
52
|
+
if (packageManager === PACKAGE_MANAGERS.pnpm) {
|
|
53
|
+
await publishPacked({ context, pkg });
|
|
54
|
+
}
|
|
55
|
+
else {
|
|
56
|
+
await run({
|
|
57
|
+
cmd: 'npm',
|
|
58
|
+
args: publishArgs({ context, target: [] }),
|
|
59
|
+
cwd: pkg.dir,
|
|
60
|
+
interactive: true,
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
log(`${pkg.name}: ${dryRun ? 'would publish' : 'published'} ${pkg.version}`);
|
|
64
|
+
}
|
|
65
|
+
}
|
package/dist/runner.d.ts
ADDED
package/dist/runner.js
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { execFile, spawn } from 'node:child_process';
|
|
2
|
+
import { promisify } from 'node:util';
|
|
3
|
+
const execFileAsync = promisify(execFile);
|
|
4
|
+
function runInTerminal({ cmd, args, cwd }) {
|
|
5
|
+
return new Promise((resolve, reject) => {
|
|
6
|
+
spawn(cmd, [...args], { cwd, stdio: 'inherit' })
|
|
7
|
+
.on('error', reject)
|
|
8
|
+
.on('exit', (code) => {
|
|
9
|
+
if (code === 0) {
|
|
10
|
+
resolve('');
|
|
11
|
+
}
|
|
12
|
+
else {
|
|
13
|
+
reject(new Error(`${cmd} ${args.join(' ')} exited with ${code}`));
|
|
14
|
+
}
|
|
15
|
+
});
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
export const run = async (command) => {
|
|
19
|
+
if (command.interactive === true) {
|
|
20
|
+
return runInTerminal(command);
|
|
21
|
+
}
|
|
22
|
+
const { cmd, args, cwd } = command;
|
|
23
|
+
const { stdout } = await execFileAsync(cmd, [...args], { cwd, maxBuffer: 64 * 1024 * 1024 });
|
|
24
|
+
return stdout;
|
|
25
|
+
};
|
package/dist/tags.d.ts
ADDED
package/dist/tags.js
ADDED
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { BUMPS, PACKAGE_MANAGERS } from './constants.ts';
|
|
2
|
+
export type Bump = (typeof BUMPS)[number];
|
|
3
|
+
export type PackageManager = (typeof PACKAGE_MANAGERS)[keyof typeof PACKAGE_MANAGERS];
|
|
4
|
+
export interface Release {
|
|
5
|
+
readonly version: string;
|
|
6
|
+
readonly notes: string;
|
|
7
|
+
readonly changelog: string;
|
|
8
|
+
}
|
package/dist/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { PackageManager } from './types.ts';
|
|
2
|
+
export interface Package {
|
|
3
|
+
readonly name: string;
|
|
4
|
+
readonly version: string;
|
|
5
|
+
readonly dir: string;
|
|
6
|
+
readonly path: string;
|
|
7
|
+
readonly private: boolean;
|
|
8
|
+
}
|
|
9
|
+
export interface Workspace {
|
|
10
|
+
readonly monorepo: boolean;
|
|
11
|
+
readonly packages: readonly Package[];
|
|
12
|
+
}
|
|
13
|
+
export declare function packageManagerOf(root: string): Promise<PackageManager>;
|
|
14
|
+
export declare function findPackages({ root, name, }: {
|
|
15
|
+
root: string;
|
|
16
|
+
name?: string;
|
|
17
|
+
}): Promise<Workspace>;
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { access, readdir, readFile } from 'node:fs/promises';
|
|
2
|
+
import { join, relative } from 'node:path';
|
|
3
|
+
import { PACKAGE_MANAGERS } from './constants.js';
|
|
4
|
+
import { readManifest, stringField, stringList } from './package-json.js';
|
|
5
|
+
const UNSUPPORTED_LOCKFILES = ['yarn.lock', 'bun.lock', 'bun.lockb'];
|
|
6
|
+
async function exists(path) {
|
|
7
|
+
return access(path).then(() => true, () => false);
|
|
8
|
+
}
|
|
9
|
+
export async function packageManagerOf(root) {
|
|
10
|
+
if (await exists(join(root, 'pnpm-lock.yaml'))) {
|
|
11
|
+
return PACKAGE_MANAGERS.pnpm;
|
|
12
|
+
}
|
|
13
|
+
for (const lockfile of UNSUPPORTED_LOCKFILES) {
|
|
14
|
+
if (await exists(join(root, lockfile))) {
|
|
15
|
+
throw new Error(`${lockfile}: only npm and pnpm are supported`);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
return PACKAGE_MANAGERS.npm;
|
|
19
|
+
}
|
|
20
|
+
function pnpmPatterns(yaml) {
|
|
21
|
+
const block = /^packages:\n((?:[ \t]+-.*\n?)+)/m.exec(yaml)?.[1] ?? '';
|
|
22
|
+
return block
|
|
23
|
+
.split('\n')
|
|
24
|
+
.map((line) => line.replace(/^\s*-\s*/, '').replace(/^['"]|['"]$/g, ''))
|
|
25
|
+
.filter(Boolean);
|
|
26
|
+
}
|
|
27
|
+
async function workspacePatterns(root) {
|
|
28
|
+
const pnpmWorkspace = join(root, 'pnpm-workspace.yaml');
|
|
29
|
+
if (await exists(pnpmWorkspace)) {
|
|
30
|
+
return pnpmPatterns(await readFile(pnpmWorkspace, 'utf8'));
|
|
31
|
+
}
|
|
32
|
+
const patterns = stringList((await readManifest(root))['workspaces']);
|
|
33
|
+
return patterns.length === 0 ? null : patterns;
|
|
34
|
+
}
|
|
35
|
+
async function expand({ root, pattern }) {
|
|
36
|
+
if (pattern.includes('**') || /\*./.test(pattern)) {
|
|
37
|
+
throw new Error(`${pattern}: only "dir" and "dir/*" workspace patterns are supported`);
|
|
38
|
+
}
|
|
39
|
+
if (!pattern.endsWith('/*')) {
|
|
40
|
+
return [join(root, pattern)];
|
|
41
|
+
}
|
|
42
|
+
const parent = join(root, pattern.slice(0, -2));
|
|
43
|
+
const entries = await readdir(parent, { withFileTypes: true });
|
|
44
|
+
return entries
|
|
45
|
+
.filter((entry) => entry.isDirectory())
|
|
46
|
+
.map((entry) => join(parent, entry.name))
|
|
47
|
+
.toSorted();
|
|
48
|
+
}
|
|
49
|
+
async function packageAt({ root, dir }) {
|
|
50
|
+
const manifest = await readManifest(dir);
|
|
51
|
+
return {
|
|
52
|
+
name: stringField({ manifest, key: 'name' }) ?? relative(root, dir),
|
|
53
|
+
version: stringField({ manifest, key: 'version' }) ?? '0.0.0',
|
|
54
|
+
dir,
|
|
55
|
+
path: relative(root, dir) || '.',
|
|
56
|
+
private: manifest['private'] === true,
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
async function allPackages(root) {
|
|
60
|
+
const patterns = await workspacePatterns(root);
|
|
61
|
+
if (patterns === null) {
|
|
62
|
+
return { monorepo: false, packages: [await packageAt({ root, dir: root })] };
|
|
63
|
+
}
|
|
64
|
+
const included = patterns.filter((pattern) => !pattern.startsWith('!'));
|
|
65
|
+
const excluded = patterns
|
|
66
|
+
.filter((pattern) => pattern.startsWith('!'))
|
|
67
|
+
.map((pattern) => join(root, pattern.slice(1)));
|
|
68
|
+
const dirs = (await Promise.all(included.map((pattern) => expand({ root, pattern })))).flat();
|
|
69
|
+
const candidates = dirs.filter((dir) => !excluded.includes(dir));
|
|
70
|
+
const hasManifest = await Promise.all(candidates.map((dir) => exists(join(dir, 'package.json'))));
|
|
71
|
+
const withManifest = candidates.filter((_, index) => hasManifest[index]);
|
|
72
|
+
const packages = await Promise.all(withManifest.map((dir) => packageAt({ root, dir })));
|
|
73
|
+
return { monorepo: true, packages };
|
|
74
|
+
}
|
|
75
|
+
export async function findPackages({ root, name, }) {
|
|
76
|
+
const workspace = await allPackages(root);
|
|
77
|
+
if (name === undefined) {
|
|
78
|
+
return workspace;
|
|
79
|
+
}
|
|
80
|
+
const packages = workspace.packages.filter((pkg) => pkg.name === name);
|
|
81
|
+
if (packages.length === 0) {
|
|
82
|
+
throw new Error(`No package named ${name}`);
|
|
83
|
+
}
|
|
84
|
+
return { monorepo: workspace.monorepo, packages };
|
|
85
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,37 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@helderberto/release",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "0.1.1",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "git+https://github.com/helderberto/coding-standards.git",
|
|
9
|
+
"directory": "packages/release"
|
|
10
|
+
},
|
|
11
|
+
"bin": {
|
|
12
|
+
"release": "./dist/cli.js"
|
|
13
|
+
},
|
|
14
|
+
"exports": {
|
|
15
|
+
".": {
|
|
16
|
+
"types": "./dist/index.d.ts",
|
|
17
|
+
"default": "./dist/index.js"
|
|
18
|
+
}
|
|
19
|
+
},
|
|
20
|
+
"files": [
|
|
21
|
+
"dist"
|
|
22
|
+
],
|
|
23
|
+
"devDependencies": {
|
|
24
|
+
"@helderberto/tsconfig": "0.1.1",
|
|
25
|
+
"@types/node": "26.6.11"
|
|
26
|
+
},
|
|
27
|
+
"engines": {
|
|
28
|
+
"node": ">=22"
|
|
29
|
+
},
|
|
30
|
+
"publishConfig": {
|
|
31
|
+
"access": "public"
|
|
32
|
+
},
|
|
33
|
+
"scripts": {
|
|
34
|
+
"build": "tsc -p tsconfig.build.json",
|
|
35
|
+
"typecheck": "tsc"
|
|
36
|
+
}
|
|
6
37
|
}
|