@williamthorsen/nmr 0.38.0 → 0.40.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 +212 -4
- package/.readyup/kits/default.js +124 -104
- package/.readyup/manifest.json +12 -7
- package/CHANGELOG.md +108 -0
- package/README.md +41 -47
- package/agents/README.md +8 -8
- package/agents/guidance/rulebooks/nmr.md +8 -8
- package/bin/ensure-prepublish-hooks.js +1 -1
- package/bin/nmr-clean.js +1 -1
- package/bin/nmr-compile.js +1 -1
- package/bin/nmr-fmt.js +1 -1
- package/bin/nmr-report-catalog.js +1 -1
- package/bin/nmr-report-overrides.js +1 -1
- package/bin/nmr-taze.js +1 -1
- package/bin/nmr.js +1 -1
- package/dist/esm/UserError.d.ts +1 -2
- package/dist/esm/check-cache.d.ts +61 -63
- package/dist/esm/check-cache.js +24 -24
- package/dist/esm/cli-ensure-prepublish-hooks.js +4 -4
- package/dist/esm/commands/build-output.d.ts +37 -38
- package/dist/esm/commands/build-output.js +9 -9
- package/dist/esm/commands/build.d.ts +13 -14
- package/dist/esm/commands/build.js +67 -65
- package/dist/esm/commands/clean.d.ts +6 -6
- package/dist/esm/commands/clean.js +11 -11
- package/dist/esm/commands/ensure-prepublish-hooks.d.ts +7 -7
- package/dist/esm/commands/ensure-prepublish-hooks.js +41 -41
- package/dist/esm/commands/fmt.d.ts +8 -8
- package/dist/esm/commands/fmt.js +33 -33
- package/dist/esm/commands/report-catalog.d.ts +5 -7
- package/dist/esm/commands/report-catalog.js +10 -8
- package/dist/esm/commands/report-overrides.d.ts +0 -2
- package/dist/esm/commands/report-overrides.js +8 -8
- package/dist/esm/commands/taze.d.ts +9 -8
- package/dist/esm/config.d.ts +5 -5
- package/dist/esm/config.js +27 -27
- package/dist/esm/context.d.ts +1 -2
- package/dist/esm/context.js +8 -8
- package/dist/esm/default-scripts.d.ts +5 -6
- package/dist/esm/defineConfig.d.ts +1 -1
- package/dist/esm/git-ignored-paths.d.ts +9 -0
- package/dist/esm/git-ignored-paths.js +10 -0
- package/dist/esm/glyphs.d.ts +3 -3
- package/dist/esm/help.d.ts +4 -4
- package/dist/esm/help.js +21 -21
- package/dist/esm/helpers/clampToBytes.d.ts +4 -5
- package/dist/esm/helpers/clampToBytes.js +3 -3
- package/dist/esm/helpers/config-path.d.ts +0 -2
- package/dist/esm/helpers/createBoundedBuffer.d.ts +3 -3
- package/dist/esm/helpers/createBoundedBuffer.js +2 -2
- package/dist/esm/helpers/deriveExcerpt.d.ts +4 -5
- package/dist/esm/helpers/duration.d.ts +10 -11
- package/dist/esm/helpers/duration.js +7 -7
- package/dist/esm/helpers/filter-selection.d.ts +19 -19
- package/dist/esm/helpers/filter-selection.js +12 -12
- package/dist/esm/helpers/findClosestName.d.ts +1 -1
- package/dist/esm/helpers/findClosestName.js +15 -15
- package/dist/esm/helpers/hook-name.d.ts +2 -5
- package/dist/esm/helpers/package-json.d.ts +11 -10
- package/dist/esm/helpers/package-json.js +26 -25
- package/dist/esm/helpers/readStringValues.d.ts +2 -3
- package/dist/esm/helpers/reportClosing.d.ts +8 -9
- package/dist/esm/helpers/transcript.d.ts +15 -15
- package/dist/esm/helpers/transcript.js +14 -14
- package/dist/esm/helpers/type-guards.d.ts +1 -0
- package/dist/esm/output-style.d.ts +12 -13
- package/dist/esm/prettier.d.ts +2 -2
- package/dist/esm/prettier.js +5 -5
- package/dist/esm/recording.d.ts +25 -20
- package/dist/esm/recording.js +28 -21
- package/dist/esm/replay-assembly.d.ts +10 -10
- package/dist/esm/report-format.d.ts +15 -20
- package/dist/esm/report-format.js +7 -7
- package/dist/esm/reportCliFailure.d.ts +2 -3
- package/dist/esm/resolve-scripts.d.ts +4 -5
- package/dist/esm/resolveBinStyles.d.ts +4 -5
- package/dist/esm/resolveBinStyles.js +3 -3
- package/dist/esm/resolver.d.ts +16 -20
- package/dist/esm/resolver.js +15 -15
- package/dist/esm/runCli.d.ts +6 -6
- package/dist/esm/runCli.js +261 -195
- package/dist/esm/runner.d.ts +20 -20
- package/dist/esm/runner.js +18 -18
- package/dist/esm/steps.d.ts +51 -38
- package/dist/esm/steps.js +32 -27
- package/dist/esm/taze.d.ts +1 -1
- package/dist/esm/tests.d.ts +23 -18
- package/dist/esm/tests.js +21 -9
- package/dist/esm/tiers.d.ts +28 -24
- package/dist/esm/tiers.js +13 -9
- package/dist/esm/types.d.ts +5 -5
- package/dist/esm/verbosity.d.ts +23 -21
- package/dist/esm/verbosity.js +7 -7
- package/dist/esm/verdict.d.ts +39 -32
- package/dist/esm/verdict.js +63 -50
- package/dist/esm/vitest-source-resolution.d.ts +11 -11
- package/dist/esm/vitest-source-resolution.js +49 -47
- package/dist/esm/vitest.d.ts +27 -26
- package/dist/esm/vitest.js +90 -33
- package/dist/esm/workspace.d.ts +6 -22
- package/dist/esm/workspace.js +9 -67
- package/docs/check-cache.md +57 -57
- package/docs/prettier.md +10 -10
- package/docs/reporting.md +48 -44
- package/docs/scripts.md +29 -29
- package/docs/upgrades.md +18 -18
- package/docs/utilities.md +13 -13
- package/docs/vitest.md +68 -66
- package/docs/workspace.md +27 -4
- package/package.json +6 -6
- package/dist/esm/helpers/workspace-patterns.d.ts +0 -8
- package/dist/esm/helpers/workspace-patterns.js +0 -29
package/docs/scripts.md
CHANGED
|
@@ -16,49 +16,49 @@ Given the `build` command for a package that defines its own build script:
|
|
|
16
16
|
| 2 | `.config/nmr.config.ts` | _(not set)_ | — |
|
|
17
17
|
| 3 | `package.json` scripts | `"tsx custom-build.ts"` | ✓ |
|
|
18
18
|
|
|
19
|
-
If
|
|
19
|
+
If the package does not declare its own override, the highest-tier value that is set wins. Set a script to `""` in `package.json` to skip it for that package.
|
|
20
20
|
|
|
21
|
-
> **Tip:** If
|
|
21
|
+
> **Tip:** If a repo uses `eslint-plugin-package-json/valid-scripts`, that rule flags empty strings as invalid. Use `":"` (the POSIX null command) instead: nmr treats it as a regular override that exits successfully and does nothing.
|
|
22
22
|
|
|
23
|
-
A `package.json` entry that re-invokes the command it is declared
|
|
23
|
+
A `package.json` entry that re-invokes the command under which it is declared is never honored. Honoring `"build": "nmr build"` would spawn a shell running `nmr build` in the same directory, reaching the same entry again without bound, so nmr discards the entry and resolves the command from the tier below. An entry that contains only the self-reference, trailing arguments included, is discarded in silence: It does not declare any step that nmr would lose. Because discarding an entry that chains anything else onto it (`"build": "nmr build && rdy compile"`, or `"build": "rdy compile && nmr build"`) would lose those steps, nmr rejects the invocation instead, naming the file, the key, and where the steps belong. For an ordinary command that is a `<command>:pre` or `<command>:post` script: `"build:pre": "rdy verify"` and `"build:post": "rdy compile"` wrap nmr's own `build` rather than replacing it. For a hook entry it is the entry itself, since nmr does not wrap a `:pre` or `:post` script in any hooks of its own: `"build:post": "nmr build:post && rdy compile"` becomes `"build:post": "rdy compile"`.
|
|
24
24
|
|
|
25
|
-
|
|
25
|
+
nmr recognizes the re-invocation wherever it appears in the entry, on the grammar that [the shelled-nmr line](#script-values) uses, and a segment containing `-F` or `-R` is not one: It hands the command to other scopes rather than back to this one. Nor is `-w` from inside a package, which targets the root's registry and the root's `package.json`. A filter that selects the declaring package is the hole in that exemption: `nmr -F own-pkg build` in `own-pkg`'s own `build` re-enters without bound, and nmr does not recognize it.
|
|
26
26
|
|
|
27
27
|
### Script values
|
|
28
28
|
|
|
29
|
-
A script value is a string or an array of steps. Only the built-in defaults and `.config/nmr.config.ts`
|
|
29
|
+
A script value is a string or an array of steps. Only the built-in defaults and `.config/nmr.config.ts` can contain an array; a `package.json` script must be a string, and any other value is rejected when the scripts are read. Arrays expand to chained `nmr` sub-invocations:
|
|
30
30
|
|
|
31
31
|
```ts
|
|
32
32
|
// "fix": ["lint", "fmt"]
|
|
33
33
|
// expands to: nmr lint && nmr fmt
|
|
34
34
|
```
|
|
35
35
|
|
|
36
|
-
Each array element is a command name, optionally preceded by nmr's own flags, split on whitespace
|
|
36
|
+
Each array element is a command name, optionally preceded by nmr's own flags, split on whitespace: `-R test` runs the element in every package, the way `nmr -R test` does. An element containing a quoted argument or shell syntax is rejected when the config loads: Name that command as a script of its own and reference the name.
|
|
37
37
|
|
|
38
38
|
#### Where trailing arguments go
|
|
39
39
|
|
|
40
|
-
|
|
40
|
+
nmr passes trailing arguments to every step of a composite, so `nmr fix --dry-run` runs `nmr lint --dry-run`, then `nmr fmt --dry-run`. A step whose work the arguments cannot narrow declines them by taking the long form of an element, and runs unnarrowed:
|
|
41
41
|
|
|
42
42
|
```ts
|
|
43
43
|
// "ci": [{ run: "build", shouldDeclineArguments: true }, "check:strict"]
|
|
44
44
|
// nmr ci src/foo.ts -> nmr build && nmr check:strict src/foo.ts
|
|
45
45
|
```
|
|
46
46
|
|
|
47
|
-
`{ run }` is the bare string element with room for the declaration; `shouldDeclineArguments` defaults to `false`, and an element that accepts is written as the string. Decline
|
|
47
|
+
`{ run }` is the bare string element with room for the declaration; `shouldDeclineArguments` defaults to `false`, and an element that accepts is written as the string. Decline when the step is a prerequisite against which the narrowed steps run, or when the tool that it invokes would be misled: `tsgo --noEmit foo.ts` abandons the tsconfig, which is why every default `typecheck` step declines. A leaf tool that merely ignores what it is handed is not a reason to decline: nmr forwards, and the tool decides.
|
|
48
48
|
|
|
49
|
-
|
|
49
|
+
When every step of a command declines them, nmr rejects the invocation and runs nothing, rather than running the whole command unnarrowed. That is what `nmr typecheck src/foo.ts` gets at the root, whose two steps both decline.
|
|
50
50
|
|
|
51
|
-
Two kinds of step are not declarable. A string script is one command handed to a leaf tool, so it always receives the arguments
|
|
51
|
+
Two kinds of step are not declarable. A string script is one command handed to a leaf tool, so it always receives the arguments. That is why `nmr typecheck src/foo.ts` inside a package still runs `tsgo`, whereas the root rejects it. A `:pre` or `:post` hook never receives them, the arguments having been placed before the hooks wrap the chain.
|
|
52
52
|
|
|
53
|
-
|
|
53
|
+
nmr also does not serve any part of an invocation with trailing arguments from the [check-result cache](check-cache.md#check-result-cache), including the steps that decline them.
|
|
54
54
|
|
|
55
|
-
A string value is spawned through a shell as one command
|
|
55
|
+
A string value is spawned through a shell as one command. An `nmr` invocation inside it is invisible to the process above: A quiet failure prints the output of the whole nested subtree rather than that of the failing step, and a loud run relays the nested tree through a forwarding pipe. nmr writes one line to stderr, in every verbosity, when a command resolves to a step that runs nmr through a shell.
|
|
56
56
|
|
|
57
|
-
The line names the declaration it is an edit
|
|
57
|
+
The line names the declaration to which it is an edit (the file, the field, and the key), and its remedy follows from that site. In a `.config/nmr.config.ts` entry, keep the nmr steps as a step list and move anything else to a `<command>:pre` or `<command>:post` script: A step-list element can name only an nmr command, because nmr composes it into `nmr <element>`. A `package.json` entry has to go, since `package.json` cannot declare a step list: Delete it outright when it restates what nmr already runs for that command, and move the steps that it adds to a `<command>:pre` or `<command>:post` script when they are the package's own. When the registry does not define that command, both apply: Name the command in `.config/nmr.config.ts`, and put the package-specific steps in a hook. The pair is named rather than `:post` alone because an entry's extra steps may run on either side of the chain: `rdy verify && nmr compile` puts them first. A hook is the exception at both tiers: nmr does not wrap a `:pre` or `:post` script in any hooks of its own. Move a hook's other steps to a script of their own, and name that script in the step list.
|
|
58
58
|
|
|
59
|
-
nmr recognizes `nmr` in command position: at the start of a step, after an unquoted `&&`, `||`, `;`, `|`, or a newline, past any leading `NAME=value` assignments, and behind `npx`, `bunx`, or an `exec`, `dlx`, or `x` subcommand of `npm`, `pnpm`, `yarn`, or `bun`. This line reports a boundary rather than enforcing a rule
|
|
59
|
+
nmr recognizes `nmr` in command position: at the start of a step, after an unquoted `&&`, `||`, `;`, `|`, or a newline, past any leading `NAME=value` assignments, and behind `npx`, `bunx`, or an `exec`, `dlx`, or `x` subcommand of `npm`, `pnpm`, `yarn`, or `bun`. This line reports a boundary rather than enforcing a rule: It covers a step that nmr runs as written, and only the reporting of the nested run is degraded. The line is also partial in three ways: a value-taking flag standing immediately before the program name hides it (`npx -p foo nmr`), a launcher outside that set goes unreported, and a `devBin` substitution that introduces `nmr` itself is not reported, the line being an edit to a declaration rather than to a substitution.
|
|
60
60
|
|
|
61
|
-
A [self-referential `package.json` entry](#three-tier-override-system) is the shape nmr cannot run as written, and it is rejected rather than reported. The same recognition finds it, so the same residuals apply
|
|
61
|
+
A [self-referential `package.json` entry](#three-tier-override-system) is the shape that nmr cannot run as written, and it is rejected rather than reported. The same recognition finds it, so the same residuals apply: What goes unrecognized there re-enters nmr without bound, which hangs rather than passing quietly.
|
|
62
62
|
|
|
63
63
|
## Pre and post hooks
|
|
64
64
|
|
|
@@ -66,8 +66,8 @@ The wrap rule and a repo-wide example are in the [README](../README.md#pre-and-p
|
|
|
66
66
|
|
|
67
67
|
Behaviors worth knowing:
|
|
68
68
|
|
|
69
|
-
- **Silent when absent**:
|
|
70
|
-
- **Skip overrides apply to hooks**: A hook value of `""` or `":"` is treated the same as not defining the hook,
|
|
69
|
+
- **Silent when absent**: A missing hook does not produce any error or output.
|
|
70
|
+
- **Skip overrides apply to hooks**: A hook value of `""` or `":"` is treated the same as not defining the hook, without a console message.
|
|
71
71
|
- **Skipping the main command skips its hooks**: When `X` is overridden to `""` or `":"`, neither `X:pre` nor `X:post` fires.
|
|
72
72
|
- **Recursion guard**: Direct invocation of a hook (e.g. `nmr build:pre`) is treated as a leaf operation. It does not itself attempt to resolve `build:pre:pre` or `build:pre:post`.
|
|
73
73
|
- **Passthrough args attach only to the main command**: `nmr X --flag value` runs hooks without `--flag value`.
|
|
@@ -102,11 +102,11 @@ A minimal `.config/nmr.config.ts` is in the [README](../README.md#configuration)
|
|
|
102
102
|
|
|
103
103
|
All fields are optional. [Script values](#script-values) describes `ScriptValue` and its step form, and both types are exported from `@williamthorsen/nmr/config`.
|
|
104
104
|
|
|
105
|
-
Each field belongs to exactly one tier, and a config
|
|
105
|
+
Each field belongs to exactly one tier, and nmr loads from a config only the fields that its tier honors: `build` in a package config, the other five in the monorepo-root config. Declaring a field at the wrong tier fails with a message naming it and where it goes, as does a key that nmr does not recognize at all: A typo cannot degrade into a setting that silently applies nowhere.
|
|
106
106
|
|
|
107
107
|
### Package-level configuration
|
|
108
108
|
|
|
109
|
-
A package may
|
|
109
|
+
A package may have its own `.config/nmr.config.ts`, which `nmr-compile` reads from the package that it is compiling. This tier honors `build` alone; declaring `workspaceScripts`, `rootScripts`, or `devBin` there fails with a message naming them, rather than being quietly ignored: Those belong in the monorepo-root config, and a package that appeared to set them would otherwise build on settings that nothing applied. The monorepo-root config has the mirror restriction: `build` there fails the same way, since only a package's own config affects the compile.
|
|
110
110
|
|
|
111
111
|
```ts
|
|
112
112
|
// packages/my-package/.config/nmr.config.ts
|
|
@@ -117,13 +117,13 @@ export default defineConfig({
|
|
|
117
117
|
});
|
|
118
118
|
```
|
|
119
119
|
|
|
120
|
-
`extraIgnorePatterns` adds to the build's [default ignore set](utilities.md#nmr-compile) rather than replacing it, so declaring a pattern cannot
|
|
120
|
+
`extraIgnorePatterns` adds to the build's [default ignore set](utilities.md#nmr-compile) rather than replacing it, so declaring a pattern cannot make a package publish its own tests. The programmatic `buildPackage` option of the same name behaves identically; its bare `ignorePatterns` is the one that replaces.
|
|
121
121
|
|
|
122
|
-
> **Building nmr from source:**
|
|
122
|
+
> **Building nmr from source:** A config file that has to load while nmr itself is being built (before its `dist` exists) must use the type-only form, `import type { NmrConfig } from '@williamthorsen/nmr/config'` with `satisfies NmrConfig`, which does not produce a runtime import. `defineConfig` is unavailable at that moment, because it resolves through nmr's build output. Every other config, including every consumer's, imports nmr from an installed tarball that contains `dist`, and can use `defineConfig` freely.
|
|
123
123
|
|
|
124
|
-
### `devBin
|
|
124
|
+
### `devBin`: source-repo binary substitution
|
|
125
125
|
|
|
126
|
-
|
|
126
|
+
During development of a CLI tool inside the monorepo, the published binary may not reflect the latest source changes. `devBin` maps a binary name to a replacement command that runs from source:
|
|
127
127
|
|
|
128
128
|
```ts
|
|
129
129
|
export default defineConfig({
|
|
@@ -137,23 +137,23 @@ When nmr resolves a command whose first token matches a `devBin` key, it replace
|
|
|
137
137
|
|
|
138
138
|
For example, if a workspace script resolves to `my-cli --verbose`, nmr rewrites it to `tsx /absolute/path/to/packages/my-cli/src/cli.ts --verbose`.
|
|
139
139
|
|
|
140
|
-
> **Note:** Path resolution uses a heuristic:
|
|
140
|
+
> **Note:** Path resolution uses a heuristic: Any non-flag token containing `/` is treated as a relative path. This works well for typical dev-tool commands but may incorrectly resolve URL-like values or glob patterns. Flags using `--flag=value` syntax are not resolved; use the spaced form `--flag value` for paths that need resolution.
|
|
141
141
|
|
|
142
142
|
## Default commands
|
|
143
143
|
|
|
144
|
-
`nmr --help` lists every default command and the shell command it resolves
|
|
144
|
+
`nmr --help` lists every default command and the shell command to which it resolves. Repo-wide config (tier 2) and per-package overrides (tier 3) can add to or replace any of them. What the listing does not show is below.
|
|
145
145
|
|
|
146
146
|
### Build and CI
|
|
147
147
|
|
|
148
|
-
`ci` is what a code-quality workflow runs; it leaves out the audit, which belongs in a workflow of its own. `prepush` is what a developer runs before pushing: both gates, audit first. The audit takes seconds and `ci` takes minutes, so a vulnerability
|
|
148
|
+
`ci` is what a code-quality workflow runs; it leaves out the audit, which belongs in a workflow of its own. `prepush` is what a developer runs before pushing: both gates, audit first. The audit takes seconds and `ci` takes minutes, so a vulnerability is reported before the long gate runs. Because `prepush` composes `ci` rather than restating its stages, a stage added to `ci` runs in `prepush` too.
|
|
149
149
|
|
|
150
|
-
The audit
|
|
150
|
+
The audit needs network access. Without network access, `ci` is the gate that still runs.
|
|
151
151
|
|
|
152
|
-
Neither is bound to a git hook. `prepush` is named for when
|
|
152
|
+
Neither is bound to a git hook. `prepush` is named for when a developer runs it, not for a hook that nmr installs.
|
|
153
153
|
|
|
154
154
|
### Check and quality
|
|
155
155
|
|
|
156
|
-
Neither gate computes coverage: Instrumentation multiplies the wall time of the run they exist to keep short. Coverage is [`test:coverage`](vitest.md#test-selections), run as a step of its own; a repo that wants it inside the gate [overrides](#configuration) `check:strict`.
|
|
156
|
+
Neither gate computes coverage: Instrumentation multiplies the wall time of the run that they exist to keep short. Coverage is [`test:coverage`](vitest.md#test-selections), run as a step of its own; a repo that wants it inside the gate [overrides](#configuration) `check:strict`.
|
|
157
157
|
|
|
158
158
|
### Lint
|
|
159
159
|
|
package/docs/upgrades.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
What `nmr upgrade` covers from each scope, how to declare the upgrade policy and its ceilings, and the subcommands and binary that the upgrade chains run.
|
|
4
4
|
|
|
5
|
-
`nmr upgrade` reports the dependency upgrades available to
|
|
5
|
+
`nmr upgrade` reports the dependency upgrades available to the repo. What it covers depends on where it runs:
|
|
6
6
|
|
|
7
7
|
| Invocation | Covers | Catalogs |
|
|
8
8
|
| ---------------------------- | ------------------------------------------- | -------- |
|
|
@@ -11,17 +11,17 @@ What `nmr upgrade` covers from each scope, how to declare the upgrade policy and
|
|
|
11
11
|
| `nmr -F <package> upgrade` | that package, from anywhere | no |
|
|
12
12
|
| `nmr root:upgrade` | the root `package.json` | yes |
|
|
13
13
|
|
|
14
|
-
A [pnpm catalog](https://pnpm.io/catalogs) is declared in `pnpm-workspace.yaml`, and the upgrade tool reads that file only when it
|
|
14
|
+
A [pnpm catalog](https://pnpm.io/catalogs) is declared in `pnpm-workspace.yaml`, and the upgrade tool reads that file only when it is in the working directory, irrespective of `--recursive`, which is why `root:upgrade` covers every catalog too. A package-scoped invocation therefore cannot see a dependency declared by the catalog, and a package whose dependencies are all catalogued would otherwise report itself up to date. It runs [`report-catalog`](#report-catalog) first instead, which names each catalogued dependency and the root from which a covering pass runs.
|
|
15
15
|
|
|
16
16
|
Both root-scoped invocations precede their report with any active override, which pnpm declares in `pnpm-workspace.yaml`. An override pins a transitive dependency, so an upgrade masked by one never appears in the report.
|
|
17
17
|
|
|
18
|
-
A `pnpm.overrides` block left in the root `package.json` fails the command instead. pnpm
|
|
18
|
+
A `pnpm.overrides` block left in the root `package.json` fails the command instead. Because pnpm does not read any setting from that field as of pnpm 11, the block pins nothing, while the upgrade tool keeps its own list of dependency fields and goes on rewriting the versions in it under `--write`: a block that looks maintained and governs nothing. Failing ahead of the tool keeps that write from happening, on `root:upgrade` as much as on `upgrade`. nmr supports pnpm 11 and later.
|
|
19
19
|
|
|
20
|
-
The upgrade tool ([taze](https://github.com/antfu-collective/taze))
|
|
20
|
+
The upgrade tool ([taze](https://github.com/antfu-collective/taze)) is installed with nmr, so a consuming repo does not declare any dependency on it. Everything after the command name is passed through, including the range mode:
|
|
21
21
|
|
|
22
22
|
```bash
|
|
23
|
-
nmr upgrade # minor and patch upgrades, regardless of the range each dependency declares
|
|
24
|
-
nmr upgrade major # major upgrades, for dependencies
|
|
23
|
+
nmr upgrade # minor and patch upgrades, regardless of the range that each dependency declares
|
|
24
|
+
nmr upgrade major # major upgrades, for dependencies without a per-package ceiling
|
|
25
25
|
nmr upgrade --write # apply the proposals to package.json
|
|
26
26
|
```
|
|
27
27
|
|
|
@@ -34,26 +34,26 @@ import { defineConfig } from '@williamthorsen/nmr/taze';
|
|
|
34
34
|
|
|
35
35
|
export default defineConfig({
|
|
36
36
|
packageMode: {
|
|
37
|
-
// Hold @types/node at the Node major
|
|
37
|
+
// Hold @types/node at the Node major that the `engines` floor requires.
|
|
38
38
|
'@types/node': 'minor',
|
|
39
39
|
},
|
|
40
40
|
});
|
|
41
41
|
```
|
|
42
42
|
|
|
43
|
-
`defineConfig` supplies nmr's shared upgrade policy
|
|
43
|
+
`defineConfig` supplies nmr's shared upgrade policy, so a repo's config contains only what is specific to that repo. The policy is a seven-day quarantine on brand-new releases and the pair of settings that report a dependency pinned to an exact version: Locked dependencies are included, and the range searched is `minor`. Any setting that a repo's config declares wins over nmr's default. Passing `undefined` clears a default rather than falling back to it; that is how a config hands the quarantine policy back to `pnpm-workspace.yaml`'s `minimumReleaseAge`. `mode` is the exception: The upgrade tool has a default of its own for it, and clearing nmr's leaves the tool without a valid range to search. Name a mode instead.
|
|
44
44
|
|
|
45
|
-
Everything the [taze configuration](https://github.com/antfu-collective/taze#config-file) accepts is accepted here, with five exceptions that
|
|
45
|
+
Everything the [taze configuration](https://github.com/antfu-collective/taze#config-file) accepts is accepted here, with five exceptions that the upgrade tool does not read from any config file at all: `concurrency`, `githubActions`, `ignoreOtherWorkspaces`, `nodeVersion`, and `requestTimeout`. The tool's CLI writes a default for each of them over whatever the config declares ([taze#317](https://github.com/antfu-collective/taze/issues/317)), so the command line is the only place they can be set. nmr's ReadyUp kit warns when a repo's config declares one, and [request timeout](#request-timeout) below shows how to set it instead.
|
|
46
46
|
|
|
47
|
-
> **Note:**
|
|
47
|
+
> **Note:** Only this file activates nmr's upgrade policy. A repo without one gets neither the release quarantine nor the settings that report a dependency pinned to an exact version, and `nmr upgrade` reports nothing in a repo using pnpm's `savePrefix: ''`. nmr's ReadyUp kit warns when the file is missing.
|
|
48
48
|
|
|
49
|
-
Two consequences of the `minor` range mode the policy
|
|
49
|
+
Two consequences of the `minor` range mode declared by the policy:
|
|
50
50
|
|
|
51
|
-
- A `packageMode` entry is honored only by the pass whose mode matches it, or by a `default` pass; every other pass drops that dependency rather than narrowing it. Under the policy's `minor` mode, a `patch` ceiling hides its dependency until
|
|
51
|
+
- A `packageMode` entry is honored only by the pass whose mode matches it, or by a `default` pass; every other pass drops that dependency rather than narrowing it. Under the policy's `minor` mode, a `patch` ceiling hides its dependency until a developer runs `nmr upgrade patch`, and a `minor` ceiling hides it from `nmr upgrade major`.
|
|
52
52
|
- A `~` range is searched as `^`, so minor upgrades are proposed for it and `--write` applies them under the original `~`. To hold one dependency to patches, give it a `packageMode` entry of `patch` and read it from `nmr upgrade patch`; to hold the whole repo there, declare `mode: 'patch'`.
|
|
53
53
|
|
|
54
54
|
## Request timeout
|
|
55
55
|
|
|
56
|
-
Every `upgrade` script
|
|
56
|
+
Every `upgrade` script calls the upgrade tool with a 30-second request timeout, in place of the tool's own 5 seconds.
|
|
57
57
|
|
|
58
58
|
Five seconds is too tight for a registry that proxies npm. The tool fetches a full packument whenever the resolved registry is not `registry.npmjs.org`, and a large one runs to tens of megabytes; the budget covers the whole retry chain rather than a single attempt, so one slow response ends the run with `Timeout requesting "<package>"`. The symptom is an upgrade pass that succeeds or fails according to how warm the tool's cache happens to be.
|
|
59
59
|
|
|
@@ -83,7 +83,7 @@ These commands are available as `nmr` subcommands and as standalone `nmr-`-prefi
|
|
|
83
83
|
|
|
84
84
|
### `report-catalog`
|
|
85
85
|
|
|
86
|
-
Report the dependencies the current package takes from a [pnpm catalog](https://pnpm.io/catalogs), which a package-scoped `upgrade` cannot
|
|
86
|
+
Report the dependencies that the current package takes from a [pnpm catalog](https://pnpm.io/catalogs), which a package-scoped `upgrade` cannot read (see [dependency upgrades](#dependency-upgrades) for why). Each line names the dependency, its `catalog:` specifier, and the monorepo root from which a covering pass runs. The workspace `upgrade` script runs it automatically, so a repo does not need to wire it up. The subcommand belongs to the workspace registry and runs from a package directory. The `nmr-report-catalog` bin reports nothing when run from the monorepo root, because a root-scoped pass reads the catalog itself.
|
|
87
87
|
|
|
88
88
|
```bash
|
|
89
89
|
nmr report-catalog
|
|
@@ -91,9 +91,9 @@ nmr report-catalog
|
|
|
91
91
|
|
|
92
92
|
### `report-overrides`
|
|
93
93
|
|
|
94
|
-
Report any active pnpm override, declared in the root `pnpm-workspace.yaml`, reminding developers of overrides that may need cleanup. The root `upgrade` script runs it automatically, so
|
|
94
|
+
Report any active pnpm override, declared in the root `pnpm-workspace.yaml`, reminding developers of overrides that may need cleanup. The root `upgrade` script runs it automatically, so a repo does not need to wire it up. Invoking it directly is useful for a one-off report.
|
|
95
95
|
|
|
96
|
-
A `pnpm.overrides` block in the root `package.json` fails the command,
|
|
96
|
+
A `pnpm.overrides` block in the root `package.json` fails the command, which names every entry that the block contains and where to move it; see [dependency upgrades](#dependency-upgrades) for why the block is inert. `pnpx codemod run pnpm-v10-to-v11` performs the move.
|
|
97
97
|
|
|
98
98
|
```bash
|
|
99
99
|
nmr report-overrides
|
|
@@ -101,9 +101,9 @@ nmr report-overrides
|
|
|
101
101
|
|
|
102
102
|
## `nmr-taze`
|
|
103
103
|
|
|
104
|
-
Run the [taze](https://github.com/antfu-collective/taze) dependency-upgrade tool, forwarding every argument to it untouched and adding one of its own: a 30-second request timeout, unless the invocation already
|
|
104
|
+
Run the [taze](https://github.com/antfu-collective/taze) dependency-upgrade tool, forwarding every argument to it untouched and adding one of its own: a 30-second request timeout, unless the invocation already includes one. Every `upgrade` chain ends with it, `root:upgrade` included; see [dependency upgrades](#dependency-upgrades) for the workflow, and [request timeout](#request-timeout) for why the timeout is set here.
|
|
105
105
|
|
|
106
|
-
Under pnpm's isolated `node_modules`, a transitive package's binary is absent from the consuming repo's `node_modules/.bin`, so a repo that depends on nmr cannot run `taze` directly. `nmr-taze` can, because nmr is a direct dependency, and it resolves the tool from the tree nmr controls.
|
|
106
|
+
Under pnpm's isolated `node_modules`, a transitive package's binary is absent from the consuming repo's `node_modules/.bin`, so a repo that depends on nmr cannot run `taze` directly. `nmr-taze` can, because nmr is a direct dependency, and it resolves the tool from the tree that nmr controls.
|
|
107
107
|
|
|
108
108
|
```bash
|
|
109
109
|
nmr-taze --recursive
|
package/docs/utilities.md
CHANGED
|
@@ -4,7 +4,7 @@ The binaries behind nmr's default `clean`, `compile`, and `fmt` commands, and a
|
|
|
4
4
|
|
|
5
5
|
## `nmr-clean`
|
|
6
6
|
|
|
7
|
-
Remove a package's build output (`dist`) and its `nmr-compile` cache entry,
|
|
7
|
+
Remove a package's build output (`dist`) and its `nmr-compile` cache entry, so that the next build cannot skip on leftover state. Run from a package directory, it cleans that package; run from the monorepo root, it sweeps every workspace package in a single pass, running each package's resolved `clean`, so a package that overrides `clean`, in `.config/nmr.config.ts` or in its own `package.json`, gets its own command rather than the sweep. Removal is idempotent: Cleaning an unbuilt package is a silent no-op. This is the default `clean` script at both levels.
|
|
8
8
|
|
|
9
9
|
```bash
|
|
10
10
|
nmr-clean
|
|
@@ -12,17 +12,17 @@ nmr-clean
|
|
|
12
12
|
|
|
13
13
|
## `nmr-compile`
|
|
14
14
|
|
|
15
|
-
Compile a single package's `src` tree to `dist/esm` with the TypeScript compiler API, emitting `.js` from one program and `.d.ts` from a second that reuses it. The package's own `removeComments` governs the `.js` emit; the declarations emit forces it off, so `.d.ts` files
|
|
15
|
+
Compile a single package's `src` tree to `dist/esm` with the TypeScript compiler API, emitting `.js` from one program and `.d.ts` from a second that reuses it. The package's own `removeComments` governs the `.js` emit; the declarations emit forces it off, so `.d.ts` files keep their doc comments either way. Because the compiler parses each source file, every relative import form (static, re-export, dynamic `import()`, and bare side-effect) is rewritten from `.ts` to `.js` in both outputs, and `.ts` occurrences inside strings and comments are left intact. tsconfig `paths` aliases are resolved to runnable relative `.js` specifiers in both outputs, sourced from the package's tsconfig. An aliased import whose target resolves outside the package's `src/` and is not resolvable without the alias mapping fails the build with a diagnostic, rather than being emitted verbatim to produce output that fails at runtime. The build is skipped when every input is unchanged and the previous output is still on disk (the key is cached under `node_modules/.cache/nmr-compile/`, outside the published output). Deleting the output by any means (`nmr clean`, `rm -rf dist`, `git clean`) therefore forces a rebuild rather than a skip. This is the default `compile` script; run it from a package directory.
|
|
16
16
|
|
|
17
|
-
**What it compiles.** Entry points are `src/**/*.ts` less the directories that
|
|
17
|
+
**What it compiles.** Entry points are `src/**/*.ts` less the directories that contain test scaffolding rather than published code: `__fixtures__/`, `__mocks__/`, `__tests__/`, and `test-utils/`. Add to that list per package with [`build.extraIgnorePatterns`](scripts.md#package-level-configuration). Ignoring a directory drops it as an _entry point_, not from the emit: The compiler still emits whatever the surviving entry points import, so a helper that production code uses is still compiled and the compiler never emits a dangling specifier in its importer. This list is deliberately not the Vitest [coverage exclusions](vitest.md#what-the-config-excludes): Helpers live in `test-utils/` precisely so that they stay covered.
|
|
18
18
|
|
|
19
|
-
**The build owns its output directory.** Every rebuild replaces `dist/esm` wholesale, so the directory
|
|
19
|
+
**The build owns its output directory.** Every rebuild replaces `dist/esm` wholesale, so the directory contains exactly the current emit: A source that was deleted, or that a widened ignore set now covers, leaves nothing behind. Assets therefore belong outside the output directory, or in a `build:post` hook, which composes correctly because it runs after the output is published. Because a bare `nmr compile` does not run any hook, assets that a `build:post` step copies in are absent until a full `nmr build` restores them. An `outdir` that does not resolve inside the package is rejected rather than replaced.
|
|
20
20
|
|
|
21
|
-
**The replacement is atomic.** The emit is buffered in memory, written to a staging directory beside the output directory, and swapped into place by rename. A build that fails for any reason -- a malformed tsconfig, an unresolvable alias, a full disk -- therefore leaves the previous output exactly as it was. `dist/esm` is never observed mid-write:
|
|
21
|
+
**The replacement is atomic.** The emit is buffered in memory, written to a staging directory beside the output directory, and swapped into place by rename. A build that fails for any reason -- a malformed tsconfig, an unresolvable alias, a full disk -- therefore leaves the previous output exactly as it was. `dist/esm` is never observed mid-write: It contains the previous build or the new one, and is absent only between the two renames. This matters most when the package being rebuilt supplies a binary that other packages in the same recursive build invoke.
|
|
22
22
|
|
|
23
|
-
**What busts the cache.** The key folds each input's content and path, the emit options, the resolved TypeScript version, and a fingerprint of the nmr running the build -- its own build digest in a workspace checkout, its package version otherwise. Upgrading nmr in a consuming repo therefore rebuilds every package nmr compiles, and an edit to nmr's own build sources rebuilds each sibling once nmr itself has been rebuilt. A build of nmr's own package folds the version rather than the digest, which is the cache entry that build is about to write.
|
|
23
|
+
**What busts the cache.** The key folds each input's content and path, the emit options, the resolved TypeScript version, and a fingerprint of the nmr running the build -- its own build digest in a workspace checkout, its package version otherwise. Upgrading nmr in a consuming repo therefore rebuilds every package that nmr compiles, and an edit to nmr's own build sources rebuilds each sibling once nmr itself has been rebuilt. A build of nmr's own package folds the version rather than the digest, which is the cache entry that this build is about to write.
|
|
24
24
|
|
|
25
|
-
`typescript` is a peer dependency (`>=5.7.0 <7`); the consuming repo provides it. The floor is what `rewriteRelativeImportExtensions` requires; the ceiling
|
|
25
|
+
`typescript` is a peer dependency (`>=5.7.0 <7`); the consuming repo provides it. The floor is what `rewriteRelativeImportExtensions` requires; the ceiling exists because TypeScript 7 does not include a compiler API: Its root export is a version constant, so `nmr-compile` cannot run on it. Relative imports in source must use explicit `.ts` extensions for them to be rewritten.
|
|
26
26
|
|
|
27
27
|
```bash
|
|
28
28
|
nmr-compile
|
|
@@ -30,11 +30,11 @@ nmr-compile
|
|
|
30
30
|
|
|
31
31
|
## `nmr-fmt`
|
|
32
32
|
|
|
33
|
-
Format, or check the formatting of, the files git reports for the working directory. Exactly one of `--check` and `--write` is required; a bare invocation prints usage and exits non-zero rather than defaulting to a mutation. `--write` also lists the files it rewrote. This is what `fmt` and `fmt:check` resolve to, in both registries.
|
|
33
|
+
Format, or check the formatting of, the files that git reports for the working directory. Exactly one of `--check` and `--write` is required; a bare invocation prints usage and exits non-zero rather than defaulting to a mutation. `--write` also lists the files that it rewrote. This is what `fmt` and `fmt:check` resolve to, in both registries.
|
|
34
34
|
|
|
35
|
-
`prettier` is an optional peer dependency (`>=3.9.5 <4`); the consuming repo provides it, and it is resolved through the module graph rather than from `PATH`, so the copy that runs is the one the repo declares and not whichever `prettier` happens to come first. A repository's formatter has to be the one its editor and pre-commit hook also run, which is why nmr takes it from the consumer instead of bundling a copy. It is optional because a repo can use nmr purely as a script runner; one that formats without a resolvable Prettier gets a message naming the package and the range.
|
|
35
|
+
`prettier` is an optional peer dependency (`>=3.9.5 <4`); the consuming repo provides it, and it is resolved through the module graph rather than from `PATH`, so the copy that runs is the one that the repo declares and not whichever `prettier` happens to come first. A repository's formatter has to be the one that its editor and pre-commit hook also run, which is why nmr takes it from the consumer instead of bundling a copy. It is optional because a repo can use nmr purely as a script runner; one that formats without a resolvable Prettier gets a message naming the package and the range.
|
|
36
36
|
|
|
37
|
-
The floor is a currency policy, not a capability boundary.
|
|
37
|
+
The floor is a currency policy, not a capability boundary. The design requires `--ignore-path` to honour every flag rather than only the last, so that a repository-root ignore file passed alongside a package-level one is not silently dropped. Prettier has done that since 3.0.0, while 2.x honoured only the final flag. The floor is at the current release because every consuming repo tracks it; lowering it to `>=3.0.0` would not affect correctness.
|
|
38
38
|
|
|
39
39
|
```bash
|
|
40
40
|
nmr-fmt --check
|
|
@@ -43,11 +43,11 @@ nmr-fmt --write packages/nmr
|
|
|
43
43
|
|
|
44
44
|
### File selection
|
|
45
45
|
|
|
46
|
-
`fmt` and `fmt:check` format the files git reports: tracked files, plus untracked files git does not ignore. Prettier reads `.gitignore` and `.prettierignore` from the working directory alone, so a pattern in `packages/<pkg>/.gitignore` never
|
|
46
|
+
`fmt` and `fmt:check` format the files that git reports: tracked files, plus untracked files that git does not ignore. Prettier reads `.gitignore` and `.prettierignore` from the working directory alone, so a pattern in `packages/<pkg>/.gitignore` never applies to a run started at the monorepo root. Because git knows the whole hierarchy, including `.git/info/exclude` and `core.excludesFile`, and every `.prettierignore` in the tree is discovered from the repository root, package-level exclusions apply from any directory as well.
|
|
47
47
|
|
|
48
|
-
A file git ignores is never formatted, even when named directly.
|
|
48
|
+
A file that git ignores is never formatted, even when named directly. Because trailing arguments are git pathspecs rather than Prettier flags, `nmr fmt:check packages/nmr` narrows the run, while an unrecognized option and a pathspec that does not match any formattable file both fail it. Running outside a git repository fails rather than reporting a clean run.
|
|
49
49
|
|
|
50
|
-
|
|
50
|
+
`nmr-fmt` drops paths that the index names but the filesystem does not have (a file deleted but not yet staged), and submodule gitlinks, before calling Prettier.
|
|
51
51
|
|
|
52
52
|
## `ensure-prepublish-hooks`
|
|
53
53
|
|