@williamthorsen/nmr 0.18.0 → 0.18.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -3,13 +3,18 @@
3
3
  Context-aware script runner for PNPM monorepos. Ships an `nmr` (node-monorepo run) binary that provides centralized, consistent script execution across workspace packages and the monorepo root.
4
4
 
5
5
  <!-- section:release-notes -->
6
- ## Release notes — v0.18.0 (2026-07-13)
6
+ ## Release notes — v0.18.1 (2026-07-14)
7
7
 
8
8
  ### 🐛 Bug fixes
9
9
 
10
- - Remove the attw check and the nmr-attw binary (#469)
10
+ - Fix the stale build cache, the unshipped rimraf dependency, and the aborting root clean (#471)
11
11
 
12
- Fixes an issue where a repo using nmr's default scripts could not pass `check:strict` without installing `@arethetypeswrong/cli` and conforming to inflexible requirements of questionable value. The `attw` check is removed.
12
+ Fixes the following issues:
13
+ - `nmr clean` failed with a missing-command error in any project that had not separately installed `rimraf`, a tool nmr neither declared nor shipped.
14
+ - If run from a monorepo root, `nmr clean` cleaned one package and then aborted, leaving every other package untouched. Only repos that build nmr from source were affected.
15
+ - If run from a monorepo root, `nmr clean` ignored a package's own `clean` script.
16
+ - `nmr compile` skipped the build for a package whose output had been deleted, because the sources were unchanged. The package compiled to an empty output directory with no error and no warning, and could be published as an empty tarball.
17
+ - `nmr compile` reported missing output and recompiled on every run for a package whose sources emit nothing, such as a source tree of only declaration files.
13
18
  <!-- /section:release-notes -->
14
19
 
15
20
  ## Installation
@@ -144,7 +149,7 @@ These scripts are available out of the box. Repo-wide config (tier 2) and per-pa
144
149
  | `build` | `compile` |
145
150
  | `check` | `typecheck`, `fmt:check`, `lint:check`, `test` |
146
151
  | `check:strict` | `typecheck`, `fmt:check`, `lint:strict`, `test:coverage` |
147
- | `clean` | `pnpm exec rimraf dist/*` |
152
+ | `clean` | `nmr-clean` |
148
153
  | `compile` | `nmr-compile` |
149
154
  | `fix` | `lint`, `fmt` |
150
155
  | `fix:check` | `fmt:check`, `lint:check` |
@@ -179,7 +184,7 @@ A package gets this variant automatically when it contains a `vitest.integration
179
184
  | ------- | --------------------------------- |
180
185
  | `build` | `pnpm --recursive exec nmr build` |
181
186
  | `ci` | `build`, `check:strict` |
182
- | `clean` | `pnpm --recursive exec nmr clean` |
187
+ | `clean` | `nmr-clean` |
183
188
 
184
189
  #### Check and quality
185
190
 
@@ -341,9 +346,17 @@ nmr sync-pnpm-version
341
346
 
342
347
  ## Standalone utilities
343
348
 
349
+ ### `nmr-clean`
350
+
351
+ Remove a package's build output (`dist`) and its `nmr-compile` cache entry, leaving no state behind for the next build to skip on. 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.
352
+
353
+ ```bash
354
+ nmr-clean
355
+ ```
356
+
344
357
  ### `nmr-compile`
345
358
 
346
- Compile a single package's `src` tree to `dist/esm` with the TypeScript compiler API, emitting `.js` and `.d.ts` in one pass. 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. The build is skipped when no input has changed (a content-and-path hash is cached under `node_modules/.cache/nmr-compile/`, outside the published output). This is the default `compile` script — run it from a package directory.
359
+ Compile a single package's `src` tree to `dist/esm` with the TypeScript compiler API, emitting `.js` and `.d.ts` in one pass. 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. The build is skipped when no input has changed and the previous output is still on disk (a content-and-path hash 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.
347
360
 
348
361
  `typescript` is a peer dependency (`>=5.7.0`, required for `rewriteRelativeImportExtensions`); the consuming repo provides it. Relative imports in source must carry explicit `.ts` extensions for them to be rewritten.
349
362
 
@@ -0,0 +1,11 @@
1
+ #!/usr/bin/env node
2
+ try {
3
+ await import('../dist/esm/cli-clean.js');
4
+ } catch (error) {
5
+ if (error.code === 'ERR_MODULE_NOT_FOUND') {
6
+ process.stderr.write('nmr-clean: build output not found — run `pnpm run build` first\n');
7
+ } else {
8
+ process.stderr.write(`nmr-clean: failed to load: ${error.message}\n`);
9
+ }
10
+ process.exit(1);
11
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,9 @@
1
+ import { reportError } from '@williamthorsen/nmr-core';
2
+ import { runClean } from "./commands/clean.js";
3
+ try {
4
+ await runClean(process.cwd());
5
+ }
6
+ catch (error) {
7
+ reportError(error instanceof Error ? error.message : String(error));
8
+ process.exitCode = 1;
9
+ }
@@ -1,5 +1,5 @@
1
1
  import { createHash } from 'node:crypto';
2
- import { existsSync, readFileSync, writeFileSync } from 'node:fs';
2
+ import { existsSync, readdirSync, readFileSync, writeFileSync } from 'node:fs';
3
3
  import { mkdir, readFile, writeFile } from 'node:fs/promises';
4
4
  import path from 'node:path';
5
5
  import { glob } from 'glob';
@@ -24,7 +24,7 @@ export async function buildPackage(packageDir, options = {}) {
24
24
  ignore: options.ignore ?? DEFAULT_IGNORE,
25
25
  });
26
26
  const dependencies = ['package.json', ...resolveTsconfigChain(packageDir)];
27
- const { changed, currentHash } = await detectBuildChanges(packageDir, [...entryPoints, ...dependencies], emitConfig, cachePath);
27
+ const { changed, currentHash } = await detectBuildChanges(packageDir, [...entryPoints, ...dependencies], emitConfig, cachePath, hasExpectedBuildOutput(packageDir, outdir, entryPoints));
28
28
  if (!changed) {
29
29
  return;
30
30
  }
@@ -199,17 +199,29 @@ function findNearestNodeModulesHost(startDir) {
199
199
  }
200
200
  return current;
201
201
  }
202
- async function detectBuildChanges(packageDir, files, emitConfig, cachePath) {
202
+ async function detectBuildChanges(packageDir, files, emitConfig, cachePath, outputPresent) {
203
203
  const packageName = path.basename(packageDir);
204
204
  const previousHash = existsSync(cachePath) ? readFileSync(cachePath, 'utf8') : undefined;
205
205
  const currentHash = await computeBuildHash(packageDir, files, emitConfig);
206
206
  if (previousHash === currentHash) {
207
- console.info(`${SKIPPED_ICON} ${packageName}: No changes detected. Skipping build.`);
208
- return { changed: false, currentHash };
207
+ if (outputPresent) {
208
+ console.info(`${SKIPPED_ICON} ${packageName}: No changes detected. Skipping build.`);
209
+ return { changed: false, currentHash };
210
+ }
211
+ console.info(`${PACKAGE_ICON} ${packageName}: Build output is missing. Rebuilding.`);
212
+ return { changed: true, currentHash };
209
213
  }
210
214
  console.info(`${PACKAGE_ICON} ${packageName}: Changes detected.`);
211
215
  return { changed: true, currentHash };
212
216
  }
217
+ function hasExpectedBuildOutput(packageDir, outdir, entryPoints) {
218
+ const emitsOutput = entryPoints.some((entry) => !entry.endsWith('.d.ts'));
219
+ if (!emitsOutput) {
220
+ return true;
221
+ }
222
+ const outputDir = path.resolve(packageDir, outdir);
223
+ return existsSync(outputDir) && readdirSync(outputDir).length > 0;
224
+ }
213
225
  async function writeBuildCache(cachePath, hash) {
214
226
  await mkdir(path.dirname(cachePath), { recursive: true });
215
227
  await writeFile(cachePath, hash);
@@ -0,0 +1,2 @@
1
+ export declare function cleanPackage(packageDir: string): Promise<void>;
2
+ export declare function runClean(cwd?: string): Promise<void>;
@@ -0,0 +1,52 @@
1
+ import { rm } from 'node:fs/promises';
2
+ import path from 'node:path';
3
+ import { loadConfig } from "../config.js";
4
+ import { findContainingPackageDir, findMonorepoRoot, getWorkspacePackageDirs } from "../context.js";
5
+ import { applyDevBin, buildWorkspaceRegistry, hasIntegrationTestConfig, resolveScript } from "../resolver.js";
6
+ import { runCommand } from "../runner.js";
7
+ import { resolveBuildCachePath } from "./build.js";
8
+ const CLEAN_ICON = '🧹';
9
+ const CLEAN_COMMAND = 'clean';
10
+ const BUILT_IN_CLEAN = 'nmr-clean';
11
+ const OUTPUT_ROOT = 'dist';
12
+ export async function cleanPackage(packageDir) {
13
+ await rm(path.resolve(packageDir, OUTPUT_ROOT), { recursive: true, force: true });
14
+ await rm(resolveBuildCachePath(packageDir), { force: true });
15
+ console.info(`${CLEAN_ICON} ${path.basename(packageDir)}: Removed build output and cache.`);
16
+ }
17
+ export async function runClean(cwd = process.cwd()) {
18
+ let monorepoRoot;
19
+ try {
20
+ monorepoRoot = findMonorepoRoot(cwd);
21
+ }
22
+ catch {
23
+ await cleanPackage(cwd);
24
+ return;
25
+ }
26
+ const workspacePackageDirs = getWorkspacePackageDirs(monorepoRoot);
27
+ const packageDir = findContainingPackageDir(cwd, workspacePackageDirs);
28
+ if (packageDir !== undefined) {
29
+ await cleanPackage(packageDir);
30
+ return;
31
+ }
32
+ await sweepWorkspace(monorepoRoot, workspacePackageDirs);
33
+ }
34
+ async function sweepWorkspace(monorepoRoot, workspacePackageDirs) {
35
+ const config = await loadConfig(monorepoRoot);
36
+ for (const packageDir of workspacePackageDirs) {
37
+ const registry = buildWorkspaceRegistry(config, hasIntegrationTestConfig(packageDir));
38
+ const resolved = resolveScript(CLEAN_COMMAND, registry, packageDir, false);
39
+ if (resolved === undefined || resolved.command === '') {
40
+ continue;
41
+ }
42
+ if (resolved.command === BUILT_IN_CLEAN) {
43
+ await cleanPackage(packageDir);
44
+ continue;
45
+ }
46
+ const command = applyDevBin(resolved.command, config.devBin, monorepoRoot);
47
+ const exitCode = runCommand(command, packageDir);
48
+ if (exitCode !== 0) {
49
+ throw new Error(`nmr-clean: \`${command}\` failed in ${path.basename(packageDir)} with exit code ${exitCode}.`);
50
+ }
51
+ }
52
+ }
@@ -2,7 +2,7 @@ export const commonWorkspaceScripts = {
2
2
  build: ['compile'],
3
3
  check: ['typecheck', 'fmt:check', 'lint:check', 'test'],
4
4
  'check:strict': ['typecheck', 'fmt:check', 'lint:strict', 'test:coverage'],
5
- clean: 'pnpm exec rimraf dist/*',
5
+ clean: 'nmr-clean',
6
6
  compile: 'nmr-compile',
7
7
  fix: ['lint', 'fmt'],
8
8
  'fix:check': ['fmt:check', 'lint:check'],
@@ -35,7 +35,7 @@ export const rootScripts = {
35
35
  'check:agent-files': 'nmr-sync-agent-files --check',
36
36
  'check:strict': ['typecheck', 'fmt:check', 'lint:strict', 'test:coverage', 'check:agent-files'],
37
37
  ci: ['build', 'check:strict', 'audit'],
38
- clean: 'pnpm --recursive exec nmr clean',
38
+ clean: 'nmr-clean',
39
39
  fix: ['lint', 'fmt'],
40
40
  'fix:check': ['fmt:check', 'lint:check'],
41
41
  fmt: 'sh -c \'prettier --list-different --write "${@:-.}"\' --',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@williamthorsen/nmr",
3
- "version": "0.18.0",
3
+ "version": "0.18.1",
4
4
  "private": false,
5
5
  "description": "Context-aware script runner for PNPM monorepos",
6
6
  "keywords": [
@@ -38,6 +38,7 @@
38
38
  "bin": {
39
39
  "ensure-prepublish-hooks": "bin/ensure-prepublish-hooks.js",
40
40
  "nmr": "bin/nmr.js",
41
+ "nmr-clean": "bin/nmr-clean.js",
41
42
  "nmr-compile": "bin/nmr-compile.js",
42
43
  "nmr-report-overrides": "bin/nmr-report-overrides.js",
43
44
  "nmr-sync-agent-files": "bin/nmr-sync-agent-files.js",