@williamthorsen/nmr-core 0.12.0 → 0.13.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/.meta/changelog.json +37 -0
- package/CHANGELOG.md +30 -0
- package/README.md +37 -18
- package/dist/esm/helpers/workspace-patterns.d.ts +33 -0
- package/dist/esm/helpers/workspace-patterns.js +36 -0
- package/dist/esm/index.d.ts +2 -2
- package/dist/esm/index.js +1 -1
- package/dist/esm/terminal.d.ts +2 -2
- package/dist/esm/terminal.js +1 -1
- package/dist/esm/workspace.d.ts +68 -0
- package/dist/esm/workspace.js +111 -0
- package/package.json +9 -3
package/.meta/changelog.json
CHANGED
|
@@ -1,4 +1,41 @@
|
|
|
1
1
|
[
|
|
2
|
+
{
|
|
3
|
+
"version": "0.13.0",
|
|
4
|
+
"date": "2026-09-22",
|
|
5
|
+
"sections": [
|
|
6
|
+
{
|
|
7
|
+
"title": "🎉 Features",
|
|
8
|
+
"audience": "all",
|
|
9
|
+
"items": [
|
|
10
|
+
{
|
|
11
|
+
"description": "Hoist the pnpm-workspace resolver into nmr-core as a total API (#864)",
|
|
12
|
+
"body": "- Adds a `./workspace` subpath export to `@williamthorsen/nmr-core`, whose `resolveWorkspace` returns a pnpm workspace's package directories, or the cause of an empty result, as a value rather than as a thrown error.\n- Reports a `pnpm-workspace.yaml` that the YAML parser rejects under a cause of its own, `unreadable-manifest`, so `nmr -R build` names the syntax error and its remedy in place of failing with the parser's own error.\n- Removes `diagnoseEmptyWorkspace` and `EmptyWorkspaceDiagnosis` from `@williamthorsen/nmr/workspace`, since `resolveWorkspace` reports the same cause in one call.\n\nMigration: Replace each `diagnoseEmptyWorkspace` call with `resolveWorkspace`, which reports the cause on the empty result it already returns, and rename the `no-manifest` cause to `no-package`. `EmptyWorkspaceCause` also gains `unreadable-manifest`, so an exhaustive switch over it stops compiling until it handles the new member; every other export of `@williamthorsen/nmr/workspace` keeps its signature and its `UserError` throws.",
|
|
13
|
+
"breaking": true,
|
|
14
|
+
"migration": "Replace each `diagnoseEmptyWorkspace` call with `resolveWorkspace`, which reports the cause on the empty result it already returns, and rename the `no-manifest` cause to `no-package`. `EmptyWorkspaceCause` also gains `unreadable-manifest`, so an exhaustive switch over it stops compiling until it handles the new member; every other export of `@williamthorsen/nmr/workspace` keeps its signature and its `UserError` throws.",
|
|
15
|
+
"hash": "3196b84c9d5f037ead0e98ee8547fe71e80fb5c6"
|
|
16
|
+
},
|
|
17
|
+
{
|
|
18
|
+
"description": "Adopt the shared workspace resolver in release-kit, honoring exclusions (#865)",
|
|
19
|
+
"body": "- 🚨 **Breaking:** Narrows `no-pattern` in `@williamthorsen/nmr-core`'s `EmptyWorkspaceCause`, moving an absent or empty `packages` list onto `no-packages-list` and a value that is not a list of strings onto `unreadable-packages`.\n- Stops `release-kit` from tagging, publishing, and label-syncing a package that a `!` entry in `pnpm-workspace.yaml` excludes, which its previous `glob`-based resolution could not remove from the match.\n- Replaces the release of the root package alone with a failure naming the condition that emptied the workspace, when `pnpm-workspace.yaml` does not hold valid YAML or declares a workspace that does not resolve to a package.\n- Replaces the `no-pattern` remedy that `nmr` printed for a `pnpm-workspace.yaml` declaring no `packages` list, and for one declaring a `packages` value that is not a list of strings.\n- Raises `engines.node` to `>=24.16.0` in `@williamthorsen/nmr-core` and `@williamthorsen/release-kit`, because Node 24.0 through 24.15 ignores the `followSymlinks` option that the workspace matcher passes to `globSync` and drops a symlinked package directory from the resolution without reporting it.\n\nMigration: Add a `no-packages-list` arm and an `unreadable-packages` arm to any `switch` that covers `EmptyWorkspaceCause` exhaustively. `no-pattern` now names only a list that the resolver read in full and whose entries all failed to become a positive pattern, so move the handling of an absent `packages` key, an empty list, and a value that is not a list of strings out of the `no-pattern` arm into the two new ones. Route `no-packages-list` to single-package behavior rather than to a failure path: pnpm resolves such a manifest to the root package alone.",
|
|
20
|
+
"breaking": true,
|
|
21
|
+
"migration": "Add a `no-packages-list` arm and an `unreadable-packages` arm to any `switch` that covers `EmptyWorkspaceCause` exhaustively. `no-pattern` now names only a list that the resolver read in full and whose entries all failed to become a positive pattern, so move the handling of an absent `packages` key, an empty list, and a value that is not a list of strings out of the `no-pattern` arm into the two new ones. Route `no-packages-list` to single-package behavior rather than to a failure path: pnpm resolves such a manifest to the root package alone.",
|
|
22
|
+
"hash": "b1126866159402b8f027a9b82f2a19591a6e9e1b"
|
|
23
|
+
}
|
|
24
|
+
]
|
|
25
|
+
},
|
|
26
|
+
{
|
|
27
|
+
"title": "🐛 Bug fixes",
|
|
28
|
+
"audience": "all",
|
|
29
|
+
"items": [
|
|
30
|
+
{
|
|
31
|
+
"description": "Truncate release-kit commit subjects by display column (#840)",
|
|
32
|
+
"body": "- Fixes the issue that the `release-kit` prepare report cut a commit subject at 69 UTF-16 code units instead of at display columns, so a subject of CJK characters printed about twice the intended 72-column width and a cut inside an emoji left a broken character that a terminal drew as a replacement glyph.\n- Replaces the `...` marker on a truncated subject with `…`, the default of the width-aware truncation that now does the cutting.\n- Exports `truncateToWidth` and `measureWidth` from `@williamthorsen/nmr-core`, which measure and cut text by display width without splitting a grapheme cluster.",
|
|
33
|
+
"hash": "f75d9b4abd9fbda264d5dd40ca5b7abb64f5a3f3"
|
|
34
|
+
}
|
|
35
|
+
]
|
|
36
|
+
}
|
|
37
|
+
]
|
|
38
|
+
},
|
|
2
39
|
{
|
|
3
40
|
"version": "0.12.0",
|
|
4
41
|
"date": "2026-09-18",
|
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,36 @@
|
|
|
2
2
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
|
|
5
|
+
## 0.13.0 — 2026-09-22
|
|
6
|
+
|
|
7
|
+
### 🎉 Features
|
|
8
|
+
|
|
9
|
+
- 🚨 **Breaking:** Hoist the pnpm-workspace resolver into nmr-core as a total API (#864)
|
|
10
|
+
|
|
11
|
+
- Adds a `./workspace` subpath export to `@williamthorsen/nmr-core`, whose `resolveWorkspace` returns a pnpm workspace's package directories, or the cause of an empty result, as a value rather than as a thrown error.
|
|
12
|
+
- Reports a `pnpm-workspace.yaml` that the YAML parser rejects under a cause of its own, `unreadable-manifest`, so `nmr -R build` names the syntax error and its remedy in place of failing with the parser's own error.
|
|
13
|
+
- Removes `diagnoseEmptyWorkspace` and `EmptyWorkspaceDiagnosis` from `@williamthorsen/nmr/workspace`, since `resolveWorkspace` reports the same cause in one call.
|
|
14
|
+
|
|
15
|
+
Migration: Replace each `diagnoseEmptyWorkspace` call with `resolveWorkspace`, which reports the cause on the empty result it already returns, and rename the `no-manifest` cause to `no-package`. `EmptyWorkspaceCause` also gains `unreadable-manifest`, so an exhaustive switch over it stops compiling until it handles the new member; every other export of `@williamthorsen/nmr/workspace` keeps its signature and its `UserError` throws.
|
|
16
|
+
|
|
17
|
+
- 🚨 **Breaking:** Adopt the shared workspace resolver in release-kit, honoring exclusions (#865)
|
|
18
|
+
|
|
19
|
+
- 🚨 **Breaking:** Narrows `no-pattern` in `@williamthorsen/nmr-core`'s `EmptyWorkspaceCause`, moving an absent or empty `packages` list onto `no-packages-list` and a value that is not a list of strings onto `unreadable-packages`.
|
|
20
|
+
- Stops `release-kit` from tagging, publishing, and label-syncing a package that a `!` entry in `pnpm-workspace.yaml` excludes, which its previous `glob`-based resolution could not remove from the match.
|
|
21
|
+
- Replaces the release of the root package alone with a failure naming the condition that emptied the workspace, when `pnpm-workspace.yaml` does not hold valid YAML or declares a workspace that does not resolve to a package.
|
|
22
|
+
- Replaces the `no-pattern` remedy that `nmr` printed for a `pnpm-workspace.yaml` declaring no `packages` list, and for one declaring a `packages` value that is not a list of strings.
|
|
23
|
+
- Raises `engines.node` to `>=24.16.0` in `@williamthorsen/nmr-core` and `@williamthorsen/release-kit`, because Node 24.0 through 24.15 ignores the `followSymlinks` option that the workspace matcher passes to `globSync` and drops a symlinked package directory from the resolution without reporting it.
|
|
24
|
+
|
|
25
|
+
Migration: Add a `no-packages-list` arm and an `unreadable-packages` arm to any `switch` that covers `EmptyWorkspaceCause` exhaustively. `no-pattern` now names only a list that the resolver read in full and whose entries all failed to become a positive pattern, so move the handling of an absent `packages` key, an empty list, and a value that is not a list of strings out of the `no-pattern` arm into the two new ones. Route `no-packages-list` to single-package behavior rather than to a failure path: pnpm resolves such a manifest to the root package alone.
|
|
26
|
+
|
|
27
|
+
### 🐛 Bug fixes
|
|
28
|
+
|
|
29
|
+
- Truncate release-kit commit subjects by display column (#840)
|
|
30
|
+
|
|
31
|
+
- Fixes the issue that the `release-kit` prepare report cut a commit subject at 69 UTF-16 code units instead of at display columns, so a subject of CJK characters printed about twice the intended 72-column width and a cut inside an emoji left a broken character that a terminal drew as a replacement glyph.
|
|
32
|
+
- Replaces the `...` marker on a truncated subject with `…`, the default of the width-aware truncation that now does the cutting.
|
|
33
|
+
- Exports `truncateToWidth` and `measureWidth` from `@williamthorsen/nmr-core`, which measure and cut text by display width without splitting a grapheme cluster.
|
|
34
|
+
|
|
5
35
|
## 0.12.0 — 2026-09-18
|
|
6
36
|
|
|
7
37
|
### 🎉 Features
|
package/README.md
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
<!-- readme-type: library -->
|
|
2
|
+
|
|
1
3
|
# @williamthorsen/nmr-core
|
|
2
4
|
|
|
3
5
|
Shared utilities for node-monorepo-tools packages.
|
|
@@ -5,28 +7,35 @@ Shared utilities for node-monorepo-tools packages.
|
|
|
5
7
|
This package serves as the shared library foundation for the monorepo. For the nmr CLI tool, see [`@williamthorsen/nmr`](../nmr).
|
|
6
8
|
|
|
7
9
|
<!-- section:release-notes -->
|
|
8
|
-
## Release notes — v0.
|
|
10
|
+
## Release notes — v0.13.0 (2026-09-22)
|
|
9
11
|
|
|
10
12
|
### 🎉 Features
|
|
11
13
|
|
|
12
|
-
-
|
|
14
|
+
- 🚨 **Breaking:** Hoist the pnpm-workspace resolver into nmr-core as a total API (#864)
|
|
15
|
+
|
|
16
|
+
- Adds a `./workspace` subpath export to `@williamthorsen/nmr-core`, whose `resolveWorkspace` returns a pnpm workspace's package directories, or the cause of an empty result, as a value rather than as a thrown error.
|
|
17
|
+
- Reports a `pnpm-workspace.yaml` that the YAML parser rejects under a cause of its own, `unreadable-manifest`, so `nmr -R build` names the syntax error and its remedy in place of failing with the parser's own error.
|
|
18
|
+
- Removes `diagnoseEmptyWorkspace` and `EmptyWorkspaceDiagnosis` from `@williamthorsen/nmr/workspace`, since `resolveWorkspace` reports the same cause in one call.
|
|
19
|
+
|
|
20
|
+
Migration: Replace each `diagnoseEmptyWorkspace` call with `resolveWorkspace`, which reports the cause on the empty result it already returns, and rename the `no-manifest` cause to `no-package`. `EmptyWorkspaceCause` also gains `unreadable-manifest`, so an exhaustive switch over it stops compiling until it handles the new member; every other export of `@williamthorsen/nmr/workspace` keeps its signature and its `UserError` throws.
|
|
21
|
+
|
|
22
|
+
- 🚨 **Breaking:** Adopt the shared workspace resolver in release-kit, honoring exclusions (#865)
|
|
13
23
|
|
|
14
|
-
-
|
|
15
|
-
-
|
|
16
|
-
-
|
|
17
|
-
-
|
|
24
|
+
- 🚨 **Breaking:** Narrows `no-pattern` in `@williamthorsen/nmr-core`'s `EmptyWorkspaceCause`, moving an absent or empty `packages` list onto `no-packages-list` and a value that is not a list of strings onto `unreadable-packages`.
|
|
25
|
+
- Stops `release-kit` from tagging, publishing, and label-syncing a package that a `!` entry in `pnpm-workspace.yaml` excludes, which its previous `glob`-based resolution could not remove from the match.
|
|
26
|
+
- Replaces the release of the root package alone with a failure naming the condition that emptied the workspace, when `pnpm-workspace.yaml` does not hold valid YAML or declares a workspace that does not resolve to a package.
|
|
27
|
+
- Replaces the `no-pattern` remedy that `nmr` printed for a `pnpm-workspace.yaml` declaring no `packages` list, and for one declaring a `packages` value that is not a list of strings.
|
|
28
|
+
- Raises `engines.node` to `>=24.16.0` in `@williamthorsen/nmr-core` and `@williamthorsen/release-kit`, because Node 24.0 through 24.15 ignores the `followSymlinks` option that the workspace matcher passes to `globSync` and drops a symlinked package directory from the resolution without reporting it.
|
|
18
29
|
|
|
19
|
-
-
|
|
30
|
+
Migration: Add a `no-packages-list` arm and an `unreadable-packages` arm to any `switch` that covers `EmptyWorkspaceCause` exhaustively. `no-pattern` now names only a list that the resolver read in full and whose entries all failed to become a positive pattern, so move the handling of an absent `packages` key, an empty list, and a value that is not a list of strings out of the `no-pattern` arm into the two new ones. Route `no-packages-list` to single-package behavior rather than to a failure path: pnpm resolves such a manifest to the root package alone.
|
|
20
31
|
|
|
21
|
-
|
|
22
|
-
- Changes the emoji in rich output so that none has a different meaning from the one that it has in `nmr`: warnings from ⚠️ to 🟠, skips from ⏭️ to ⏩, the errors of `show-tag-prefixes` from ⛔ to ❌, and the tag marker from 🏷️ to 🔖.
|
|
23
|
-
- Adds a required `style` parameter to `formatValidateOverridesResult`, which the package root exports.
|
|
32
|
+
### 🐛 Bug fixes
|
|
24
33
|
|
|
25
|
-
-
|
|
34
|
+
- Truncate release-kit commit subjects by display column (#840)
|
|
26
35
|
|
|
27
|
-
-
|
|
28
|
-
-
|
|
29
|
-
-
|
|
36
|
+
- Fixes the issue that the `release-kit` prepare report cut a commit subject at 69 UTF-16 code units instead of at display columns, so a subject of CJK characters printed about twice the intended 72-column width and a cut inside an emoji left a broken character that a terminal drew as a replacement glyph.
|
|
37
|
+
- Replaces the `...` marker on a truncated subject with `…`, the default of the width-aware truncation that now does the cutting.
|
|
38
|
+
- Exports `truncateToWidth` and `measureWidth` from `@williamthorsen/nmr-core`, which measure and cut text by display width without splitting a grapheme cluster.
|
|
30
39
|
<!-- /section:release-notes -->
|
|
31
40
|
|
|
32
41
|
## Installation
|
|
@@ -37,12 +46,22 @@ Requires Node.js 24 or later.
|
|
|
37
46
|
pnpm add -D @williamthorsen/nmr-core
|
|
38
47
|
```
|
|
39
48
|
|
|
49
|
+
## Workspace introspection
|
|
50
|
+
|
|
51
|
+
The `./workspace` entry publishes the pnpm-workspace lookups that nmr and release-kit share. Every one of them
|
|
52
|
+
is total: it returns a value rather than throwing, so each CLI keeps its own error boundary.
|
|
53
|
+
[Workspace introspection](../nmr/docs/workspace.md) documents what each lookup returns and where it diverges
|
|
54
|
+
from pnpm.
|
|
55
|
+
|
|
56
|
+
The entry stays out of the root export, which keeps `yaml` out of the module closure of every other importer,
|
|
57
|
+
the build bootstrap's included.
|
|
58
|
+
|
|
40
59
|
## The `nmr-source` export condition
|
|
41
60
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
61
|
+
Both entries declare an `nmr-source` export condition resolving to their TypeScript source. It exists for one
|
|
62
|
+
caller: the compiler that builds this package. That compiler imports this package, so on a tree with no build
|
|
63
|
+
output it has to reach the source, which is what the condition gives it.
|
|
45
64
|
|
|
46
65
|
Nothing else should pass `--conditions nmr-source`. The published package ships `dist` alone, so the condition
|
|
47
66
|
resolves to a file that is not in the tarball and fails with `ERR_MODULE_NOT_FOUND`. Resolution without the flag
|
|
48
|
-
is unaffected: an unmatched condition is skipped, and
|
|
67
|
+
is unaffected: an unmatched condition is skipped, and each entry resolves to the build output as it always has.
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The manifest patterns a declared `packages` list resolves to, split by what each entry asks of the matcher.
|
|
3
|
+
*
|
|
4
|
+
* Held as manifest patterns rather than as the entries themselves, so a caller re-matching a subset spends the
|
|
5
|
+
* same rewriting a full resolution does.
|
|
6
|
+
*/
|
|
7
|
+
export interface WorkspacePatternSplit {
|
|
8
|
+
excludedPatterns: string[];
|
|
9
|
+
includedPatterns: string[];
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Matches manifest patterns against a monorepo root, returning the absolute directories that hold a matched
|
|
13
|
+
* manifest, sorted and free of duplicates.
|
|
14
|
+
*
|
|
15
|
+
* Takes the exclusion set as an argument of its own, so a caller diagnosing an empty resolution can re-match
|
|
16
|
+
* the positive patterns alone and learn whether the exclusions are what emptied it.
|
|
17
|
+
*/
|
|
18
|
+
export declare function matchPackageDirs(monorepoRoot: string, includedPatterns: readonly string[], excludedPatterns: readonly string[]): string[];
|
|
19
|
+
/**
|
|
20
|
+
* Resolves pnpm workspace patterns to absolute package directories.
|
|
21
|
+
*
|
|
22
|
+
* Applies pnpm's algorithm: every pattern is rewritten to match a manifest, `!`-prefixed patterns become
|
|
23
|
+
* exclusions, and the matcher decides the rest. Exclusions filter the entire positive match set
|
|
24
|
+
* irrespective of declaration order.
|
|
25
|
+
*/
|
|
26
|
+
export declare function resolvePackageDirs(monorepoRoot: string, patterns: readonly string[]): string[];
|
|
27
|
+
/**
|
|
28
|
+
* Splits a declared `packages` list into the manifest patterns the matcher includes and the ones it excludes.
|
|
29
|
+
*
|
|
30
|
+
* The sole reader of what counts as a positive pattern, shared by a resolution and by a diagnosis of its empty
|
|
31
|
+
* result: two readers classifying entries separately could disagree about which condition a manifest is in.
|
|
32
|
+
*/
|
|
33
|
+
export declare function splitWorkspacePatterns(patterns: readonly string[]): WorkspacePatternSplit;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { globSync } from 'node:fs';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
const MANIFEST = 'package.json';
|
|
4
|
+
const ALWAYS_EXCLUDED = ['**/node_modules/**'];
|
|
5
|
+
export function matchPackageDirs(monorepoRoot, includedPatterns, excludedPatterns) {
|
|
6
|
+
const options = {
|
|
7
|
+
cwd: monorepoRoot,
|
|
8
|
+
exclude: [...excludedPatterns, ...ALWAYS_EXCLUDED],
|
|
9
|
+
followSymlinks: true,
|
|
10
|
+
};
|
|
11
|
+
const matches = globSync([...includedPatterns], options);
|
|
12
|
+
const dirs = matches.map((match) => path.dirname(path.resolve(monorepoRoot, match)));
|
|
13
|
+
return [...new Set(dirs)].toSorted();
|
|
14
|
+
}
|
|
15
|
+
export function resolvePackageDirs(monorepoRoot, patterns) {
|
|
16
|
+
const { excludedPatterns, includedPatterns } = splitWorkspacePatterns(patterns);
|
|
17
|
+
if (includedPatterns.length === 0) {
|
|
18
|
+
return [];
|
|
19
|
+
}
|
|
20
|
+
return matchPackageDirs(monorepoRoot, includedPatterns, excludedPatterns);
|
|
21
|
+
}
|
|
22
|
+
export function splitWorkspacePatterns(patterns) {
|
|
23
|
+
const includedPatterns = [];
|
|
24
|
+
const excludedPatterns = [];
|
|
25
|
+
for (const pattern of patterns) {
|
|
26
|
+
if (pattern.trim() === '')
|
|
27
|
+
continue;
|
|
28
|
+
const isNegated = pattern.startsWith('!');
|
|
29
|
+
const target = isNegated ? excludedPatterns : includedPatterns;
|
|
30
|
+
target.push(buildManifestPattern(isNegated ? pattern.slice(1) : pattern));
|
|
31
|
+
}
|
|
32
|
+
return { excludedPatterns, includedPatterns };
|
|
33
|
+
}
|
|
34
|
+
function buildManifestPattern(pattern) {
|
|
35
|
+
return `${pattern.replace(/\/?$/, '')}/${MANIFEST}`;
|
|
36
|
+
}
|
package/dist/esm/index.d.ts
CHANGED
|
@@ -9,7 +9,7 @@ export { hashWorkingTree, readHeadSha } from './hashWorkingTree.js';
|
|
|
9
9
|
export type { FlagDefinition, FlagSchema, ParseArgsOptions, ParsedArgs, ParsedFlags, ParseErrorKind, } from './parseArgs.js';
|
|
10
10
|
export { parseArgs, parseArgsOrExit, ParseError } from './parseArgs.js';
|
|
11
11
|
export { readPackageVersion } from './readPackageVersion.js';
|
|
12
|
-
export type { GlyphSet, InvalidOutputStyle, OutputStyle, ResolveStreamStylesOptions, StatusGlyphName, StreamStyleResolution, StreamStyles, } from './terminal.js';
|
|
13
|
-
export { defineGlyphSet, describeInvalidOutputStyle, formatErrorLine, formatGlyphLine, formatStatusLine, measureGlyphColumn, printError, printSkip, printStep, printSuccess, reportError, reportWriteResult, resolveStreamStyles, STATUS_GLYPHS, wrapToWidth, } from './terminal.js';
|
|
12
|
+
export type { GlyphSet, InvalidOutputStyle, OutputStyle, ResolveStreamStylesOptions, StatusGlyphName, StreamStyleResolution, StreamStyles, TruncateToWidthOptions, } from './terminal.js';
|
|
13
|
+
export { defineGlyphSet, describeInvalidOutputStyle, formatErrorLine, formatGlyphLine, formatStatusLine, measureGlyphColumn, measureWidth, printError, printSkip, printStep, printSuccess, reportError, reportWriteResult, resolveStreamStyles, STATUS_GLYPHS, truncateToWidth, wrapToWidth, } from './terminal.js';
|
|
14
14
|
export type { WriteOutcome, WriteResult } from './writeFileWithCheck.js';
|
|
15
15
|
export { writeFileWithCheck } from './writeFileWithCheck.js';
|
package/dist/esm/index.js
CHANGED
|
@@ -6,5 +6,5 @@ export { hasErrnoCode } from "./hasErrnoCode.js";
|
|
|
6
6
|
export { hashWorkingTree, readHeadSha } from "./hashWorkingTree.js";
|
|
7
7
|
export { parseArgs, parseArgsOrExit, ParseError } from "./parseArgs.js";
|
|
8
8
|
export { readPackageVersion } from "./readPackageVersion.js";
|
|
9
|
-
export { defineGlyphSet, describeInvalidOutputStyle, formatErrorLine, formatGlyphLine, formatStatusLine, measureGlyphColumn, printError, printSkip, printStep, printSuccess, reportError, reportWriteResult, resolveStreamStyles, STATUS_GLYPHS, wrapToWidth, } from "./terminal.js";
|
|
9
|
+
export { defineGlyphSet, describeInvalidOutputStyle, formatErrorLine, formatGlyphLine, formatStatusLine, measureGlyphColumn, measureWidth, printError, printSkip, printStep, printSuccess, reportError, reportWriteResult, resolveStreamStyles, STATUS_GLYPHS, truncateToWidth, wrapToWidth, } from "./terminal.js";
|
|
10
10
|
export { writeFileWithCheck } from "./writeFileWithCheck.js";
|
package/dist/esm/terminal.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import type { Writable } from 'node:stream';
|
|
2
2
|
import { type GlyphSet, type InvalidOutputStyle, type OutputStyle, type StatusGlyphName } from '@williamthorsen/toolbelt.terminal/candidate';
|
|
3
3
|
import type { WriteResult } from './writeFileWithCheck.js';
|
|
4
|
-
export type { GlyphSet, InvalidOutputStyle, OutputStyle, StatusGlyphName, } from '@williamthorsen/toolbelt.terminal/candidate';
|
|
5
|
-
export { defineGlyphSet, describeInvalidOutputStyle, measureGlyphColumn, STATUS_GLYPHS, wrapToWidth, } from '@williamthorsen/toolbelt.terminal/candidate';
|
|
4
|
+
export type { GlyphSet, InvalidOutputStyle, OutputStyle, StatusGlyphName, TruncateToWidthOptions, } from '@williamthorsen/toolbelt.terminal/candidate';
|
|
5
|
+
export { defineGlyphSet, describeInvalidOutputStyle, measureGlyphColumn, measureWidth, STATUS_GLYPHS, truncateToWidth, wrapToWidth, } from '@williamthorsen/toolbelt.terminal/candidate';
|
|
6
6
|
export interface ResolveStreamStylesOptions {
|
|
7
7
|
/** Raw arguments in which to find `flag`; read only when `flag` is given. */
|
|
8
8
|
readonly argv?: readonly string[] | undefined;
|
package/dist/esm/terminal.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import process from 'node:process';
|
|
2
2
|
import { detectOutputStyle, measureGlyphColumn, resolveOutputStyle, STATUS_GLYPHS, } from '@williamthorsen/toolbelt.terminal/candidate';
|
|
3
|
-
export { defineGlyphSet, describeInvalidOutputStyle, measureGlyphColumn, STATUS_GLYPHS, wrapToWidth, } from '@williamthorsen/toolbelt.terminal/candidate';
|
|
3
|
+
export { defineGlyphSet, describeInvalidOutputStyle, measureGlyphColumn, measureWidth, STATUS_GLYPHS, truncateToWidth, wrapToWidth, } from '@williamthorsen/toolbelt.terminal/candidate';
|
|
4
4
|
export function formatErrorLine(message) {
|
|
5
5
|
return `Error: ${message}`;
|
|
6
6
|
}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
/** Which of six conditions left a workspace resolving to no package directory. */
|
|
2
|
+
export type EmptyWorkspaceCause = 'all-excluded' | 'no-package' | 'no-packages-list' | 'no-pattern' | 'unreadable-manifest' | 'unreadable-packages';
|
|
3
|
+
/**
|
|
4
|
+
* What resolving a directory's workspace patterns produced: the directory declares no workspace, it resolves
|
|
5
|
+
* to a set of package directories, or it resolves to none and the cause says which condition emptied it.
|
|
6
|
+
*
|
|
7
|
+
* The declared patterns travel with the last two because a message composed from one quotes them back to the
|
|
8
|
+
* reader. They are empty under `unreadable-manifest`, the one cause whose manifest declares nothing the reader
|
|
9
|
+
* can see.
|
|
10
|
+
*/
|
|
11
|
+
export type WorkspaceResolution = {
|
|
12
|
+
kind: 'empty';
|
|
13
|
+
cause: EmptyWorkspaceCause;
|
|
14
|
+
patterns: string[];
|
|
15
|
+
} | {
|
|
16
|
+
kind: 'not-a-workspace';
|
|
17
|
+
} | {
|
|
18
|
+
kind: 'packages';
|
|
19
|
+
packageDirs: string[];
|
|
20
|
+
patterns: string[];
|
|
21
|
+
};
|
|
22
|
+
/**
|
|
23
|
+
* Finds the monorepo root by walking up from `startDir`, defaulting to `process.cwd()`, until it reaches a
|
|
24
|
+
* directory holding `pnpm-workspace.yaml`.
|
|
25
|
+
*
|
|
26
|
+
* Returns nothing where the walk runs out of parent directories, which a CLI turns into whichever failure its
|
|
27
|
+
* own error boundary calls for.
|
|
28
|
+
*/
|
|
29
|
+
export declare function findMonorepoRoot(startDir?: string): string | undefined;
|
|
30
|
+
/** Reports whether a directory is the monorepo root, which the workspace manifest's presence marks. */
|
|
31
|
+
export declare function isMonorepoRoot(dir: string): boolean;
|
|
32
|
+
/**
|
|
33
|
+
* Reads the `overrides` block from the monorepo root's `pnpm-workspace.yaml`, the site pnpm reads an override
|
|
34
|
+
* from.
|
|
35
|
+
*
|
|
36
|
+
* Returns nothing when the manifest is missing, unreadable, unparseable, or declares no block, and drops an
|
|
37
|
+
* entry whose value is not a string.
|
|
38
|
+
*/
|
|
39
|
+
export declare function readWorkspaceOverrides(monorepoRoot: string): Record<string, string> | undefined;
|
|
40
|
+
/**
|
|
41
|
+
* Reads the manifest `name` each of the given package directories declares, which is what a `-F` pattern
|
|
42
|
+
* matches.
|
|
43
|
+
*
|
|
44
|
+
* A directory whose manifest is missing, unparseable, or nameless contributes nothing. The sweep runs for a
|
|
45
|
+
* diagnostic's sake, so one malformed manifest elsewhere in the workspace must not replace the diagnostic the
|
|
46
|
+
* reader asked for with a failure of its own.
|
|
47
|
+
*/
|
|
48
|
+
export declare function readWorkspacePackageNames(packageDirs: readonly string[]): string[];
|
|
49
|
+
/**
|
|
50
|
+
* Resolves the workspace a directory declares, applying pnpm's pattern semantics — including `!`-prefixed
|
|
51
|
+
* exclusions — and reporting which condition left the result empty.
|
|
52
|
+
*
|
|
53
|
+
* Reaches the filesystem a second time for `all-excluded` alone, re-matching the positive patterns without the
|
|
54
|
+
* exclusion set. That runs only where a resolution has already come back empty.
|
|
55
|
+
*
|
|
56
|
+
* Three causes separate what a manifest declares from what the reader could make of it, because one remedy
|
|
57
|
+
* does not answer them all. `no-packages-list` is a manifest declaring nothing, an absent `packages` key or an
|
|
58
|
+
* empty list, which pnpm resolves to the root package alone; `unreadable-packages` is a `packages` value that
|
|
59
|
+
* is not a list of strings, which declares something the reader refused; and `no-pattern` is a list whose
|
|
60
|
+
* entries all fail to become a positive pattern, `!` entries and entries YAML emptied. A caller treating an
|
|
61
|
+
* empty resolution as a failure needs the first held apart from the other two, and a caller composing a
|
|
62
|
+
* message needs all three.
|
|
63
|
+
*
|
|
64
|
+
* A manifest that the reader cannot parse at all is `unreadable-manifest`. It declares whatever it declares,
|
|
65
|
+
* and the remedy the pattern causes share — declare a positive pattern — repairs nothing for a reader who has
|
|
66
|
+
* one and a syntax error above it.
|
|
67
|
+
*/
|
|
68
|
+
export declare function resolveWorkspace(monorepoRoot: string): WorkspaceResolution;
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import { existsSync, readFileSync } from 'node:fs';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import { parse } from 'yaml';
|
|
4
|
+
import { matchPackageDirs, resolvePackageDirs, splitWorkspacePatterns } from "./helpers/workspace-patterns.js";
|
|
5
|
+
const PACKAGE_MANIFEST = 'package.json';
|
|
6
|
+
const WORKSPACE_MANIFEST = 'pnpm-workspace.yaml';
|
|
7
|
+
export function findMonorepoRoot(startDir) {
|
|
8
|
+
let dir = path.resolve(startDir ?? process.cwd());
|
|
9
|
+
for (;;) {
|
|
10
|
+
if (isMonorepoRoot(dir)) {
|
|
11
|
+
return dir;
|
|
12
|
+
}
|
|
13
|
+
const parent = path.dirname(dir);
|
|
14
|
+
if (parent === dir) {
|
|
15
|
+
return undefined;
|
|
16
|
+
}
|
|
17
|
+
dir = parent;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
export function isMonorepoRoot(dir) {
|
|
21
|
+
return existsSync(path.join(dir, WORKSPACE_MANIFEST));
|
|
22
|
+
}
|
|
23
|
+
export function readWorkspaceOverrides(monorepoRoot) {
|
|
24
|
+
const manifestRead = readWorkspaceManifest(monorepoRoot);
|
|
25
|
+
if (manifestRead.kind !== 'parsed' || !isObject(manifestRead.value)) {
|
|
26
|
+
return undefined;
|
|
27
|
+
}
|
|
28
|
+
const overrides = manifestRead.value['overrides'];
|
|
29
|
+
return isObject(overrides) ? readStringValues(overrides) : undefined;
|
|
30
|
+
}
|
|
31
|
+
export function readWorkspacePackageNames(packageDirs) {
|
|
32
|
+
const names = [];
|
|
33
|
+
for (const dir of packageDirs) {
|
|
34
|
+
let parsedManifest;
|
|
35
|
+
try {
|
|
36
|
+
parsedManifest = JSON.parse(readFileSync(path.join(dir, PACKAGE_MANIFEST), 'utf8'));
|
|
37
|
+
}
|
|
38
|
+
catch {
|
|
39
|
+
continue;
|
|
40
|
+
}
|
|
41
|
+
if (isObject(parsedManifest) && typeof parsedManifest['name'] === 'string') {
|
|
42
|
+
names.push(parsedManifest['name']);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
return names;
|
|
46
|
+
}
|
|
47
|
+
export function resolveWorkspace(monorepoRoot) {
|
|
48
|
+
const manifestRead = readWorkspaceManifest(monorepoRoot);
|
|
49
|
+
if (manifestRead.kind === 'absent') {
|
|
50
|
+
return { kind: 'not-a-workspace' };
|
|
51
|
+
}
|
|
52
|
+
if (manifestRead.kind === 'unreadable') {
|
|
53
|
+
return { cause: 'unreadable-manifest', kind: 'empty', patterns: [] };
|
|
54
|
+
}
|
|
55
|
+
const packagesRead = readDeclaredPackages(manifestRead.value);
|
|
56
|
+
if (packagesRead.kind !== 'patterns') {
|
|
57
|
+
const cause = packagesRead.kind === 'absent' ? 'no-packages-list' : 'unreadable-packages';
|
|
58
|
+
return { cause, kind: 'empty', patterns: [] };
|
|
59
|
+
}
|
|
60
|
+
const { patterns } = packagesRead;
|
|
61
|
+
const packageDirs = resolvePackageDirs(monorepoRoot, patterns);
|
|
62
|
+
if (packageDirs.length > 0) {
|
|
63
|
+
return { kind: 'packages', packageDirs, patterns };
|
|
64
|
+
}
|
|
65
|
+
return { cause: diagnoseEmptyCause(monorepoRoot, patterns), kind: 'empty', patterns };
|
|
66
|
+
}
|
|
67
|
+
function diagnoseEmptyCause(monorepoRoot, patterns) {
|
|
68
|
+
const { excludedPatterns, includedPatterns } = splitWorkspacePatterns(patterns);
|
|
69
|
+
if (includedPatterns.length === 0) {
|
|
70
|
+
return 'no-pattern';
|
|
71
|
+
}
|
|
72
|
+
if (excludedPatterns.length > 0 && matchPackageDirs(monorepoRoot, includedPatterns, []).length > 0) {
|
|
73
|
+
return 'all-excluded';
|
|
74
|
+
}
|
|
75
|
+
return 'no-package';
|
|
76
|
+
}
|
|
77
|
+
function readDeclaredPackages(parsedManifest) {
|
|
78
|
+
if (!isObject(parsedManifest))
|
|
79
|
+
return { kind: 'absent' };
|
|
80
|
+
const packages = parsedManifest['packages'];
|
|
81
|
+
if (packages === undefined || packages === null)
|
|
82
|
+
return { kind: 'absent' };
|
|
83
|
+
if (!Array.isArray(packages))
|
|
84
|
+
return { kind: 'unreadable' };
|
|
85
|
+
if (!packages.every((entry) => typeof entry === 'string'))
|
|
86
|
+
return { kind: 'unreadable' };
|
|
87
|
+
return packages.length === 0 ? { kind: 'absent' } : { kind: 'patterns', patterns: packages };
|
|
88
|
+
}
|
|
89
|
+
function isObject(value) {
|
|
90
|
+
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
91
|
+
}
|
|
92
|
+
function readStringValues(record) {
|
|
93
|
+
const result = {};
|
|
94
|
+
for (const [key, value] of Object.entries(record)) {
|
|
95
|
+
if (typeof value === 'string')
|
|
96
|
+
result[key] = value;
|
|
97
|
+
}
|
|
98
|
+
return result;
|
|
99
|
+
}
|
|
100
|
+
function readWorkspaceManifest(monorepoRoot) {
|
|
101
|
+
const workspaceFile = path.join(monorepoRoot, WORKSPACE_MANIFEST);
|
|
102
|
+
if (!existsSync(workspaceFile)) {
|
|
103
|
+
return { kind: 'absent' };
|
|
104
|
+
}
|
|
105
|
+
try {
|
|
106
|
+
return { kind: 'parsed', value: parse(readFileSync(workspaceFile, 'utf8')) };
|
|
107
|
+
}
|
|
108
|
+
catch {
|
|
109
|
+
return { kind: 'unreadable' };
|
|
110
|
+
}
|
|
111
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@williamthorsen/nmr-core",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.13.0",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "Shared utilities for node-monorepo-tools packages",
|
|
6
6
|
"keywords": [
|
|
@@ -26,6 +26,11 @@
|
|
|
26
26
|
"nmr-source": "./src/index.ts",
|
|
27
27
|
"types": "./dist/esm/index.d.ts",
|
|
28
28
|
"default": "./dist/esm/index.js"
|
|
29
|
+
},
|
|
30
|
+
"./workspace": {
|
|
31
|
+
"nmr-source": "./src/workspace.ts",
|
|
32
|
+
"types": "./dist/esm/workspace.d.ts",
|
|
33
|
+
"default": "./dist/esm/workspace.js"
|
|
29
34
|
}
|
|
30
35
|
},
|
|
31
36
|
"files": [
|
|
@@ -35,7 +40,8 @@
|
|
|
35
40
|
],
|
|
36
41
|
"dependencies": {
|
|
37
42
|
"@williamthorsen/toolbelt.errors": "0.8.1",
|
|
38
|
-
"@williamthorsen/toolbelt.terminal": "0.2.0"
|
|
43
|
+
"@williamthorsen/toolbelt.terminal": "0.2.0",
|
|
44
|
+
"yaml": "2.9.1"
|
|
39
45
|
},
|
|
40
46
|
"devDependencies": {
|
|
41
47
|
"@williamthorsen/toolbelt.filesystem": "0.9.1",
|
|
@@ -44,7 +50,7 @@
|
|
|
44
50
|
"vitest": "4.1.11"
|
|
45
51
|
},
|
|
46
52
|
"engines": {
|
|
47
|
-
"node": ">=24"
|
|
53
|
+
"node": ">=24.16.0"
|
|
48
54
|
},
|
|
49
55
|
"publishConfig": {
|
|
50
56
|
"access": "public"
|