@williamthorsen/nmr 0.54.0 → 0.54.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/.meta/changelog.json +32 -0
- package/.readyup/kits/default.js +10 -10
- package/.readyup/manifest.json +18 -18
- package/CHANGELOG.md +9 -0
- package/README.md +6 -3
- package/bin/ensure-prepublish-hooks.js +6 -2
- package/bin/nmr-actionlint.js +6 -2
- package/bin/nmr-clean.js +6 -2
- package/bin/nmr-compile.js +6 -2
- package/bin/nmr-fmt.js +6 -2
- package/bin/nmr-report-catalog.js +6 -2
- package/bin/nmr-report-overrides.js +6 -2
- package/bin/nmr-taze.js +6 -2
- package/bin/nmr-vitest.js +6 -2
- package/bin/nmr.js +6 -2
- package/dist/esm/child-process.js +1 -1
- package/dist/esm/cli-actionlint.js +2 -3
- package/dist/esm/cli-build.js +2 -3
- package/dist/esm/cli-clean.js +2 -3
- package/dist/esm/cli-ensure-prepublish-hooks.js +2 -3
- package/dist/esm/cli-fmt.js +8 -1
- package/dist/esm/cli-report-catalog.js +2 -3
- package/dist/esm/cli-report-overrides.js +2 -3
- package/dist/esm/cli-taze.js +2 -3
- package/dist/esm/cli-vitest.js +8 -1
- package/dist/esm/cli.js +2 -2
- package/dist/esm/commands/actionlint.js +2 -1
- package/dist/esm/commands/build.js +9 -6
- package/dist/esm/commands/clean.js +2 -2
- package/dist/esm/commands/compiler.js +3 -3
- package/dist/esm/commands/ensure-prepublish-hooks.js +10 -3
- package/dist/esm/commands/node-pin.js +1 -1
- package/dist/esm/commands/report-overrides.js +1 -2
- package/dist/esm/commands/rewrite-specifiers.js +3 -2
- package/dist/esm/commands/tsconfig-chain.js +4 -3
- package/dist/esm/commands/workflow-tools.js +10 -8
- package/dist/esm/config-check-cache.js +1 -1
- package/dist/esm/config-validation.js +1 -1
- package/dist/esm/config.js +1 -1
- package/dist/esm/crossing-diagnostics.js +1 -2
- package/dist/esm/delegation-target.d.ts +5 -4
- package/dist/esm/delegation-target.js +15 -0
- package/dist/esm/entry-chain.js +1 -1
- package/dist/esm/helpers/deriveExcerpt.js +1 -1
- package/dist/esm/helpers/duration.js +1 -1
- package/dist/esm/helpers/package-json.js +1 -1
- package/dist/esm/machine-lock.js +1 -1
- package/dist/esm/pass-manifest.js +2 -3
- package/dist/esm/remote-host-session.js +2 -2
- package/dist/esm/resolveBinStyles.js +1 -2
- package/dist/esm/user-config.js +1 -1
- package/dist/esm/vitest-source-resolution.js +1 -1
- package/dist/esm/workspace.js +1 -1
- package/docs/delegate.md +7 -5
- package/package.json +4 -4
- package/dist/esm/UserError.d.ts +0 -8
- package/dist/esm/UserError.js +0 -6
- package/dist/esm/reportCliFailure.d.ts +0 -9
- package/dist/esm/reportCliFailure.js +0 -11
|
@@ -2,7 +2,8 @@ import { createHash } from 'node:crypto';
|
|
|
2
2
|
import { existsSync } from 'node:fs';
|
|
3
3
|
import { readFile, rename, rm } from 'node:fs/promises';
|
|
4
4
|
import path from 'node:path';
|
|
5
|
-
import { formatGlyphLine, readCacheEntry, startTimer, STATUS_GLYPHS, writeCacheEntry, } from '@williamthorsen/nmr-core';
|
|
5
|
+
import { formatGlyphLine, readCacheEntry, startTimer, STATUS_GLYPHS, UserError, writeCacheEntry, } from '@williamthorsen/nmr-core';
|
|
6
|
+
import { describeError } from '@williamthorsen/toolbelt.errors';
|
|
6
7
|
import { glob } from 'glob';
|
|
7
8
|
import { NMR_GLYPHS } from "../glyphs.js";
|
|
8
9
|
import { resolveConfigPath } from "../helpers/config-path.js";
|
|
@@ -91,7 +92,7 @@ async function emitPackage(packageDir, entryPoints, outdir) {
|
|
|
91
92
|
}
|
|
92
93
|
function assertEmitSucceeded(result) {
|
|
93
94
|
if (result.emitSkipped) {
|
|
94
|
-
throw new
|
|
95
|
+
throw new UserError(`nmr-compile: emit failed.\n${formatDiagnostics(result.diagnostics)}`);
|
|
95
96
|
}
|
|
96
97
|
}
|
|
97
98
|
function createCachingCompilerHost(compilerOptions) {
|
|
@@ -126,7 +127,7 @@ function resolveEmitDir(packageDir, outdir) {
|
|
|
126
127
|
if (relativePathFromPackage === '' ||
|
|
127
128
|
relativePathFromPackage.startsWith('..') ||
|
|
128
129
|
path.isAbsolute(relativePathFromPackage)) {
|
|
129
|
-
throw new
|
|
130
|
+
throw new UserError(`nmr-compile: refusing to build into '${outdir}', which does not resolve inside the package. ` +
|
|
130
131
|
'The build replaces its output directory on each emit, so the directory must be below the package root.');
|
|
131
132
|
}
|
|
132
133
|
return resolvedDir;
|
|
@@ -143,7 +144,9 @@ async function swapIntoPlace(emitDir, scratchDirs) {
|
|
|
143
144
|
if (hadPreviousOutput && !existsSync(emitDir)) {
|
|
144
145
|
await rename(scratchDirs.previousDir, emitDir);
|
|
145
146
|
}
|
|
146
|
-
throw error
|
|
147
|
+
throw new UserError(`nmr-compile: failed to move the built output into ${emitDir}: ${describeError(error)}`, {
|
|
148
|
+
cause: error,
|
|
149
|
+
});
|
|
147
150
|
}
|
|
148
151
|
await discardScratchDirs(scratchDirs);
|
|
149
152
|
}
|
|
@@ -152,11 +155,11 @@ function synthesizeCompilerOptions(packageDir, outdir) {
|
|
|
152
155
|
const configPath = path.join(packageDir, 'tsconfig.json');
|
|
153
156
|
const configFile = ts.readConfigFile(configPath, (fileName) => ts.sys.readFile(fileName));
|
|
154
157
|
if (configFile.error) {
|
|
155
|
-
throw new
|
|
158
|
+
throw new UserError(`nmr-compile: failed to read ${configPath}.\n${formatDiagnostics([configFile.error])}`);
|
|
156
159
|
}
|
|
157
160
|
const parsedConfig = ts.parseJsonConfigFileContent(configFile.config, ts.sys, packageDir);
|
|
158
161
|
if (parsedConfig.errors.length > 0) {
|
|
159
|
-
throw new
|
|
162
|
+
throw new UserError(`nmr-compile: failed to parse ${configPath}.\n${formatDiagnostics(parsedConfig.errors)}`);
|
|
160
163
|
}
|
|
161
164
|
const resolvedOutDir = path.resolve(packageDir, outdir);
|
|
162
165
|
return {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { rm } from 'node:fs/promises';
|
|
2
2
|
import path from 'node:path';
|
|
3
|
-
import { formatGlyphLine } from '@williamthorsen/nmr-core';
|
|
3
|
+
import { formatGlyphLine, UserError } from '@williamthorsen/nmr-core';
|
|
4
4
|
import { removeCheckCache } from "../check-cache-entries.js";
|
|
5
5
|
import { loadRootConfig } from "../config.js";
|
|
6
6
|
import { findContainingPackageDir } from "../context.js";
|
|
@@ -71,7 +71,7 @@ async function sweepWorkspace(monorepoRoot, workspacePackageDirs, style) {
|
|
|
71
71
|
channels: { stderr: resolveChannel(process.stderr, false), stdout: resolveChannel(process.stdout, false) },
|
|
72
72
|
});
|
|
73
73
|
if (exitCode !== 0) {
|
|
74
|
-
throw new
|
|
74
|
+
throw new UserError(`nmr-clean: \`${command}\` failed in ${path.basename(packageDir)} with exit code ${exitCode}.`);
|
|
75
75
|
}
|
|
76
76
|
cleanedCount++;
|
|
77
77
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { hasErrnoCode } from '@williamthorsen/nmr-core';
|
|
1
|
+
import { hasErrnoCode, UserError } from '@williamthorsen/nmr-core';
|
|
2
2
|
const MINIMUM_TYPESCRIPT_MAJOR = 5;
|
|
3
3
|
const MINIMUM_TYPESCRIPT_MINOR = 7;
|
|
4
4
|
const UNSUPPORTED_TYPESCRIPT_MAJOR = 7;
|
|
@@ -14,7 +14,7 @@ export function assertSupportedTypeScript() {
|
|
|
14
14
|
const minor = minorPart === undefined ? 0 : Number(minorPart);
|
|
15
15
|
const tooOld = major < MINIMUM_TYPESCRIPT_MAJOR || (major === MINIMUM_TYPESCRIPT_MAJOR && minor < MINIMUM_TYPESCRIPT_MINOR);
|
|
16
16
|
if (tooOld || major >= UNSUPPORTED_TYPESCRIPT_MAJOR) {
|
|
17
|
-
throw new
|
|
17
|
+
throw new UserError(`nmr-compile requires TypeScript ${SUPPORTED_TYPESCRIPT_RANGE}, but found ` +
|
|
18
18
|
`${typeof version === 'string' ? version : 'a version without the compiler API'}. ${INSTALL_TYPESCRIPT_GUIDANCE}`);
|
|
19
19
|
}
|
|
20
20
|
}
|
|
@@ -38,7 +38,7 @@ export async function loadCompiler(loadTypeScript = importTypeScript) {
|
|
|
38
38
|
}
|
|
39
39
|
catch (error) {
|
|
40
40
|
if (hasErrnoCode(error, 'ERR_MODULE_NOT_FOUND') && error.message.includes("'typescript'")) {
|
|
41
|
-
throw new
|
|
41
|
+
throw new UserError(`nmr-compile requires TypeScript ${SUPPORTED_TYPESCRIPT_RANGE}, but 'typescript' could not be resolved. ` +
|
|
42
42
|
INSTALL_TYPESCRIPT_GUIDANCE, { cause: error });
|
|
43
43
|
}
|
|
44
44
|
throw error;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { readFileSync, writeFileSync } from 'node:fs';
|
|
2
2
|
import path from 'node:path';
|
|
3
|
-
import { STATUS_GLYPHS } from '@williamthorsen/nmr-core';
|
|
3
|
+
import { STATUS_GLYPHS, UserError } from '@williamthorsen/nmr-core';
|
|
4
|
+
import { describeError } from '@williamthorsen/toolbelt.errors';
|
|
4
5
|
import { readPackageJson } from "../helpers/package-json.js";
|
|
5
6
|
import { reportClosing } from "../helpers/reportClosing.js";
|
|
6
7
|
import { isObject } from "../helpers/type-guards.js";
|
|
@@ -75,9 +76,15 @@ export function reportPrepublishHooks(result, hookCommand, style) {
|
|
|
75
76
|
function addPrepublishOnly(packageDir, command) {
|
|
76
77
|
const filePath = path.join(packageDir, 'package.json');
|
|
77
78
|
const rawText = readFileSync(filePath, 'utf8');
|
|
78
|
-
|
|
79
|
+
let parsedManifest;
|
|
80
|
+
try {
|
|
81
|
+
parsedManifest = JSON.parse(rawText);
|
|
82
|
+
}
|
|
83
|
+
catch (error) {
|
|
84
|
+
throw new UserError(`Invalid package.json in ${packageDir}: ${describeError(error)}`, { cause: error });
|
|
85
|
+
}
|
|
79
86
|
if (!isObject(parsedManifest)) {
|
|
80
|
-
throw new
|
|
87
|
+
throw new UserError(`Invalid package.json in ${packageDir}: expected an object`);
|
|
81
88
|
}
|
|
82
89
|
const scripts = isObject(parsedManifest['scripts']) ? parsedManifest['scripts'] : {};
|
|
83
90
|
scripts['prepublishOnly'] = command;
|
|
@@ -7,7 +7,7 @@ import { NMR_GLYPHS } from "../glyphs.js";
|
|
|
7
7
|
import { isObject } from "../helpers/type-guards.js";
|
|
8
8
|
export const NODE_RELEASE_INDEX_URL = 'https://nodejs.org/dist/index.json';
|
|
9
9
|
const TOOL_VERSIONS_FILE = '.tool-versions';
|
|
10
|
-
const SOAK_MS = 2 * 24 * 60 * 60 *
|
|
10
|
+
const SOAK_MS = 2 * 24 * 60 * 60 * 1000;
|
|
11
11
|
const FETCH_TIMEOUT_MS = 10_000;
|
|
12
12
|
const NODEJS_ENTRY_PATTERN = /^[ \t]*nodejs[ \t]+([^\s#]+)/m;
|
|
13
13
|
const PLAIN_VERSION_PATTERN = /^\d+\.\d+\.\d+$/;
|
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import { formatGlyphLine } from '@williamthorsen/nmr-core';
|
|
1
|
+
import { formatGlyphLine, UserError } from '@williamthorsen/nmr-core';
|
|
2
2
|
import { NMR_GLYPHS } from "../glyphs.js";
|
|
3
3
|
import { getPnpmOverrides, readPackageJson } from "../helpers/package-json.js";
|
|
4
4
|
import { reportClosing } from "../helpers/reportClosing.js";
|
|
5
|
-
import { UserError } from "../UserError.js";
|
|
6
5
|
import { readWorkspaceOverrides } from "../workspace.js";
|
|
7
6
|
export function reportOverrides(monorepoRoot, style) {
|
|
8
7
|
const declaredOverrides = listEntries(readWorkspaceOverrides(monorepoRoot));
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import path from 'node:path';
|
|
2
|
+
import { UserError } from '@williamthorsen/nmr-core';
|
|
2
3
|
import { getCompiler } from "./compiler.js";
|
|
3
4
|
const TS_EXTENSIONS = ['.ts', '.tsx'];
|
|
4
5
|
const JS_EXTENSION = '.js';
|
|
@@ -88,7 +89,7 @@ function resolveSpecifierReplacement(specifier, sourceContainingFile, compilerOp
|
|
|
88
89
|
const ts = getCompiler();
|
|
89
90
|
const resolvedModule = ts.resolveModuleName(specifier, sourceContainingFile, compilerOptions, ts.sys).resolvedModule;
|
|
90
91
|
if (!resolvedModule) {
|
|
91
|
-
throw new
|
|
92
|
+
throw new UserError(`nmr-compile: could not resolve aliased import '${specifier}' from ${sourceContainingFile}. ` +
|
|
92
93
|
`Verify the tsconfig 'paths' mapping and that the target file exists.`);
|
|
93
94
|
}
|
|
94
95
|
if (!isWithin(sourceRoot, resolvedModule.resolvedFileName)) {
|
|
@@ -97,7 +98,7 @@ function resolveSpecifierReplacement(specifier, sourceContainingFile, compilerOp
|
|
|
97
98
|
if (bareResolvedModule) {
|
|
98
99
|
return undefined;
|
|
99
100
|
}
|
|
100
|
-
throw new
|
|
101
|
+
throw new UserError(`nmr-compile: aliased import '${specifier}' from ${sourceContainingFile} resolves to ` +
|
|
101
102
|
`${resolvedModule.resolvedFileName}, outside the package source root ${sourceRoot}, and does not resolve ` +
|
|
102
103
|
`the way Node will at runtime, which ignores tsconfig 'paths', 'baseUrl', and 'rootDirs'. The ` +
|
|
103
104
|
`emitted specifier would fail at runtime; re-anchor the alias inside the package.`);
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import path from 'node:path';
|
|
2
|
+
import { UserError } from '@williamthorsen/nmr-core';
|
|
2
3
|
import { formatDiagnostics, getCompiler } from "./compiler.js";
|
|
3
4
|
import { isRelativeSpecifier } from "./rewrite-specifiers.js";
|
|
4
5
|
export function resolveTsconfigChain(packageDir, configFileName = 'tsconfig.json') {
|
|
@@ -14,7 +15,7 @@ export function resolveTsconfigChain(packageDir, configFileName = 'tsconfig.json
|
|
|
14
15
|
resolvedChain.push(normalizedPath);
|
|
15
16
|
const configFile = ts.readConfigFile(normalizedPath, (fileName) => ts.sys.readFile(fileName));
|
|
16
17
|
if (configFile.error) {
|
|
17
|
-
throw new
|
|
18
|
+
throw new UserError(`nmr-compile: failed to read ${normalizedPath}.\n${formatDiagnostics([configFile.error])}`);
|
|
18
19
|
}
|
|
19
20
|
for (const entry of normalizeExtendsField(configFile.config)) {
|
|
20
21
|
walk(resolveExtendsTarget(entry, normalizedPath));
|
|
@@ -47,12 +48,12 @@ function resolveExtendsTarget(extendsEntry, fromConfigPath) {
|
|
|
47
48
|
if (ts.sys.fileExists(withJsonExtension)) {
|
|
48
49
|
return withJsonExtension;
|
|
49
50
|
}
|
|
50
|
-
throw new
|
|
51
|
+
throw new UserError(`nmr-compile: ${fromConfigPath} extends '${extendsEntry}', which does not exist.`);
|
|
51
52
|
}
|
|
52
53
|
const resolvedPath = resolvePackageSpecifier(extendsEntry, fromConfigPath) ??
|
|
53
54
|
resolvePackageSpecifier(`${extendsEntry}/tsconfig.json`, fromConfigPath);
|
|
54
55
|
if (resolvedPath === undefined) {
|
|
55
|
-
throw new
|
|
56
|
+
throw new UserError(`nmr-compile: ${fromConfigPath} extends '${extendsEntry}', which does not resolve to a file.`);
|
|
56
57
|
}
|
|
57
58
|
return resolvedPath;
|
|
58
59
|
}
|
|
@@ -3,8 +3,8 @@ import { createHash } from 'node:crypto';
|
|
|
3
3
|
import fs from 'node:fs';
|
|
4
4
|
import path from 'node:path';
|
|
5
5
|
import process from 'node:process';
|
|
6
|
+
import { UserError } from '@williamthorsen/nmr-core';
|
|
6
7
|
import { describeError } from '@williamthorsen/toolbelt.errors';
|
|
7
|
-
import { UserError } from "../UserError.js";
|
|
8
8
|
const SUPPORTED_PLATFORMS = ['darwin-arm64', 'darwin-x64', 'linux-arm64', 'linux-x64'];
|
|
9
9
|
const DOWNLOAD_TIMEOUT_MS = 60_000;
|
|
10
10
|
const ACTIONLINT_RELEASE = 'https://github.com/rhysd/actionlint/releases/download/v1.7.12';
|
|
@@ -71,7 +71,7 @@ export async function ensureTool(tool, options) {
|
|
|
71
71
|
const archive = await download(asset.url, options.fetch ?? globalThis.fetch);
|
|
72
72
|
const actualSha256 = createHash('sha256').update(archive).digest('hex');
|
|
73
73
|
if (actualSha256 !== asset.sha256) {
|
|
74
|
-
throw new
|
|
74
|
+
throw new UserError(`Checksum mismatch for ${asset.url}: expected sha256 ${asset.sha256}, got ${actualSha256}`);
|
|
75
75
|
}
|
|
76
76
|
const archivePath = path.join(scratchDir, 'archive.tar.gz');
|
|
77
77
|
fs.writeFileSync(archivePath, archive);
|
|
@@ -103,7 +103,7 @@ function createCacheRoot(cacheRoot) {
|
|
|
103
103
|
fs.mkdirSync(cacheRoot, { recursive: true });
|
|
104
104
|
}
|
|
105
105
|
catch (error) {
|
|
106
|
-
throw new
|
|
106
|
+
throw new UserError(`Cannot create the tool cache at ${cacheRoot}: ${describeError(error)}`, { cause: error });
|
|
107
107
|
}
|
|
108
108
|
}
|
|
109
109
|
async function download(url, fetchImpl) {
|
|
@@ -112,20 +112,20 @@ async function download(url, fetchImpl) {
|
|
|
112
112
|
response = await fetchImpl(url, { signal: AbortSignal.timeout(DOWNLOAD_TIMEOUT_MS) });
|
|
113
113
|
}
|
|
114
114
|
catch (error) {
|
|
115
|
-
throw new
|
|
115
|
+
throw new UserError(`Cannot download ${url}: ${describeError(error)}`, { cause: error });
|
|
116
116
|
}
|
|
117
117
|
if (!response.ok) {
|
|
118
|
-
throw new
|
|
118
|
+
throw new UserError(`Cannot download ${url}: HTTP ${response.status}`);
|
|
119
119
|
}
|
|
120
120
|
return Buffer.from(await response.arrayBuffer());
|
|
121
121
|
}
|
|
122
122
|
function extractMember(archivePath, extractDir, member) {
|
|
123
123
|
const result = spawnSync('tar', ['-xzf', archivePath, '-C', extractDir, member], { encoding: 'utf8' });
|
|
124
124
|
if (result.error !== undefined) {
|
|
125
|
-
throw new
|
|
125
|
+
throw new UserError(`Cannot run tar to extract ${member}: ${result.error.message}`, { cause: result.error });
|
|
126
126
|
}
|
|
127
127
|
if (result.status !== 0) {
|
|
128
|
-
throw new
|
|
128
|
+
throw new UserError(`tar could not extract ${member} from ${archivePath}: ${result.stderr.trim()}`);
|
|
129
129
|
}
|
|
130
130
|
}
|
|
131
131
|
function publishStage(stageDir, targetDir, binaryPath) {
|
|
@@ -134,7 +134,9 @@ function publishStage(stageDir, targetDir, binaryPath) {
|
|
|
134
134
|
}
|
|
135
135
|
catch (error) {
|
|
136
136
|
if (!fs.existsSync(binaryPath)) {
|
|
137
|
-
throw error
|
|
137
|
+
throw new UserError(`Cannot move the downloaded tool into ${targetDir}: ${describeError(error)}`, {
|
|
138
|
+
cause: error,
|
|
139
|
+
});
|
|
138
140
|
}
|
|
139
141
|
}
|
|
140
142
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
+
import { UserError } from '@williamthorsen/nmr-core';
|
|
1
2
|
import { findClosestName } from "./helpers/findClosestName.js";
|
|
2
3
|
import { isHookName } from "./helpers/hook-name.js";
|
|
3
4
|
import { buildRootRegistry, buildWorkspaceRegistry, readPackageJsonScripts } from "./resolver.js";
|
|
4
|
-
import { UserError } from "./UserError.js";
|
|
5
5
|
import { getWorkspacePackageDirs, isMonorepoRoot } from "./workspace.js";
|
|
6
6
|
export function assertResolvableCheckCacheCommands(config, configPath, baseDir) {
|
|
7
7
|
const { checkCache } = config;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
+
import { UserError } from '@williamthorsen/nmr-core';
|
|
1
2
|
import { assertResolvableCheckCacheCommands } from "./config-check-cache.js";
|
|
2
3
|
import { isObject, isStringRecord } from "./helpers/type-guards.js";
|
|
3
4
|
import { findUnexpressibleToken } from "./steps.js";
|
|
4
|
-
import { UserError } from "./UserError.js";
|
|
5
5
|
import { formatVerbosityRejection, isCommandVerbosity } from "./verbosity.js";
|
|
6
6
|
export const CONFIG_TIERS = {
|
|
7
7
|
root: {
|
package/dist/esm/config.js
CHANGED
|
@@ -8,6 +8,7 @@ var __rewriteRelativeImportExtension = (this && this.__rewriteRelativeImportExte
|
|
|
8
8
|
};
|
|
9
9
|
import { existsSync } from 'node:fs';
|
|
10
10
|
import { pathToFileURL } from 'node:url';
|
|
11
|
+
import { UserError } from '@williamthorsen/nmr-core';
|
|
11
12
|
import { CONFIG_TIERS, validateConfig } from "./config-validation.js";
|
|
12
13
|
import { resolveConfigPath } from "./helpers/config-path.js";
|
|
13
14
|
import { escapeControlCharacters } from "./helpers/escapeControlCharacters.js";
|
|
@@ -16,7 +17,6 @@ import { isObject } from "./helpers/type-guards.js";
|
|
|
16
17
|
import { getDefaultRootScripts, getDefaultWorkspaceScripts } from "./resolve-scripts.js";
|
|
17
18
|
import { describeScript } from "./resolver.js";
|
|
18
19
|
import { readSelfReference, readStepListSelfReference } from "./steps.js";
|
|
19
|
-
import { UserError } from "./UserError.js";
|
|
20
20
|
const SCRIPT_FIELDS = [
|
|
21
21
|
{ field: 'rootScripts', scope: 'root' },
|
|
22
22
|
{ field: 'workspaceScripts', scope: 'workspaceRegistry' },
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import path from 'node:path';
|
|
2
|
-
import { STATUS_GLYPHS } from '@williamthorsen/nmr-core';
|
|
2
|
+
import { STATUS_GLYPHS, UserError } from '@williamthorsen/nmr-core';
|
|
3
3
|
import { resolveConfigPath } from "./helpers/config-path.js";
|
|
4
4
|
import { escapeControlCharacters } from "./helpers/escapeControlCharacters.js";
|
|
5
5
|
import { isHookName } from "./helpers/hook-name.js";
|
|
@@ -7,7 +7,6 @@ import { resolvePackageJsonPath } from "./helpers/package-json.js";
|
|
|
7
7
|
import { hasRunnableHook } from "./hooks.js";
|
|
8
8
|
import { expandScript, findChainedSelfReference, readPackageJsonScripts, } from "./resolver.js";
|
|
9
9
|
import { findNmrCrossing, readSoleNmrCommand, renderChain } from "./steps.js";
|
|
10
|
-
import { UserError } from "./UserError.js";
|
|
11
10
|
const CROSSING_CONSEQUENCE = "so nmr handles the nested run's output as a tool's.";
|
|
12
11
|
export function assertNoSelfReference(options) {
|
|
13
12
|
const { anchorDir, command, isReading, isWorkspaceRoot, monorepoRoot, registry } = options;
|
|
@@ -27,10 +27,11 @@ export type DelegationTarget = {
|
|
|
27
27
|
* 2. `--delegate-to` runs it on the hosts that it names, and `--delegate` on `NMR_DELEGATE`'s, or else the user
|
|
28
28
|
* config's.
|
|
29
29
|
* 3. A repo config declaring `delegate: false` runs it here.
|
|
30
|
-
* 4. `
|
|
31
|
-
* 5. `NMR_DELEGATE`
|
|
32
|
-
* 6.
|
|
33
|
-
* 7.
|
|
30
|
+
* 4. A package install hook, which `npm_lifecycle_event` names, runs it here.
|
|
31
|
+
* 5. `NMR_DELEGATE` naming hosts runs it on them.
|
|
32
|
+
* 6. `NMR_DELEGATE` set without a host runs it here, which is how a step keeps to where its parent runs.
|
|
33
|
+
* 7. The user config's `when` matching runs it on the config's hosts, unless `CI` is set or the invocation fans out.
|
|
34
|
+
* 8. Otherwise, it runs here.
|
|
34
35
|
*
|
|
35
36
|
* A command that rewrites the tree, or that runs until it is stopped, cannot be delegated, and neither can `--log`,
|
|
36
37
|
* which reads this machine's recordings. Asked for by a flag, such an invocation is refused; asked for by the
|
|
@@ -16,6 +16,9 @@ export async function resolveDelegationTarget(options) {
|
|
|
16
16
|
if (isRepoOptedOut) {
|
|
17
17
|
return { kind: 'local' };
|
|
18
18
|
}
|
|
19
|
+
if (isInstallHook(env)) {
|
|
20
|
+
return { kind: 'local' };
|
|
21
|
+
}
|
|
19
22
|
if (envHosts !== undefined) {
|
|
20
23
|
return isDelegable ? { kind: 'remote', hosts: envHosts, source: 'env' } : { kind: 'local' };
|
|
21
24
|
}
|
|
@@ -33,6 +36,15 @@ export async function resolveDelegationTarget(options) {
|
|
|
33
36
|
return { kind: 'remote', hosts: delegate.hosts, source: 'config', configPath: loaded.path, when: delegate.when };
|
|
34
37
|
}
|
|
35
38
|
const DEFAULT_USER_CONFIG_PATH = '~/.config/nmr/config.ts';
|
|
39
|
+
const INSTALL_HOOKS = new Set([
|
|
40
|
+
'dependencies',
|
|
41
|
+
'install',
|
|
42
|
+
'postinstall',
|
|
43
|
+
'postprepare',
|
|
44
|
+
'preinstall',
|
|
45
|
+
'prepare',
|
|
46
|
+
'preprepare',
|
|
47
|
+
]);
|
|
36
48
|
const NON_DELEGABLE_BASE_COMMANDS = ['build', 'clean', 'compile', 'fix', 'fmt', 'lint', 'test:watch', 'upgrade'];
|
|
37
49
|
const NON_DELEGABLE_COMMANDS = new Set([
|
|
38
50
|
...NON_DELEGABLE_BASE_COMMANDS,
|
|
@@ -41,6 +53,9 @@ const NON_DELEGABLE_COMMANDS = new Set([
|
|
|
41
53
|
function hasValue(value) {
|
|
42
54
|
return value !== undefined && value !== '';
|
|
43
55
|
}
|
|
56
|
+
function isInstallHook(env) {
|
|
57
|
+
return INSTALL_HOOKS.has(env['npm_lifecycle_event'] ?? '');
|
|
58
|
+
}
|
|
44
59
|
function parseHostList(value) {
|
|
45
60
|
const names = value.split(',').map((host) => host.trim());
|
|
46
61
|
const [first, ...rest] = new Set(names.filter((host) => host !== ''));
|
package/dist/esm/entry-chain.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { realpathSync } from 'node:fs';
|
|
2
2
|
import path from 'node:path';
|
|
3
|
+
import { UserError } from '@williamthorsen/nmr-core';
|
|
3
4
|
import { isObject } from "./helpers/type-guards.js";
|
|
4
|
-
import { UserError } from "./UserError.js";
|
|
5
5
|
export const ENTRY_CHAIN_ENV_VAR = 'NMR_ENTRY_CHAIN';
|
|
6
6
|
export function enterChain(options) {
|
|
7
7
|
const { anchorDir, command, env, monorepoRoot } = options;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { clampToBytes } from "./clampToBytes.js";
|
|
2
2
|
import { cleanTranscript } from "./transcript.js";
|
|
3
3
|
const MAX_BLOCK_LINES = 8;
|
|
4
|
-
export const MAX_EXCERPT_BYTES =
|
|
4
|
+
export const MAX_EXCERPT_BYTES = 2048;
|
|
5
5
|
const NON_RULE_CHARACTER = /[^-=_~*+.|:#]/u;
|
|
6
6
|
export function deriveExcerpt(transcript) {
|
|
7
7
|
const lines = cleanTranscript(transcript).split('\n');
|
|
@@ -17,7 +17,7 @@ export function formatSaving(durationMs) {
|
|
|
17
17
|
return `saved ~${formatDuration(durationMs)}`;
|
|
18
18
|
}
|
|
19
19
|
const MILLISECONDS_PER_MINUTE = 60_000;
|
|
20
|
-
const MILLISECONDS_PER_SECOND =
|
|
20
|
+
const MILLISECONDS_PER_SECOND = 1000;
|
|
21
21
|
const MINUTES_PER_HOUR = 60;
|
|
22
22
|
const SECONDS_PER_MINUTE = 60;
|
|
23
23
|
function joinUnits(major, minor, minorUnit) {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { readFileSync } from 'node:fs';
|
|
2
2
|
import path from 'node:path';
|
|
3
|
+
import { UserError } from '@williamthorsen/nmr-core';
|
|
3
4
|
import { describeError } from '@williamthorsen/toolbelt.errors';
|
|
4
|
-
import { UserError } from "../UserError.js";
|
|
5
5
|
import { isMonorepoRoot } from "../workspace.js";
|
|
6
6
|
import { CONFIG_RELATIVE_PATH } from "./config-path.js";
|
|
7
7
|
import { readStringValues } from "./readStringValues.js";
|
package/dist/esm/machine-lock.js
CHANGED
|
@@ -28,7 +28,7 @@ export const LOCK_DIR_ENV_VAR = 'NMR_LOCK_DIR';
|
|
|
28
28
|
export const LOCK_FILE = 'heavy.lock';
|
|
29
29
|
export const LOCK_TOKEN_ENV_VAR = 'NMR_MACHINE_LOCK_TOKEN';
|
|
30
30
|
export const NO_LOCK_ENV_VAR = 'NMR_NO_LOCK';
|
|
31
|
-
export const POLL_INTERVAL_MS =
|
|
31
|
+
export const POLL_INTERVAL_MS = 1000;
|
|
32
32
|
export const STALE_AFTER_MS = 60_000;
|
|
33
33
|
export async function acquireMachineLock(options) {
|
|
34
34
|
const { command, dir, env, stderr } = options;
|
|
@@ -49,7 +49,7 @@ export async function writePassManifestEntry(options) {
|
|
|
49
49
|
writeDebugNote(`could not report ${command} to the delegating machine: ${describeError(error)}`, env, stderr);
|
|
50
50
|
}
|
|
51
51
|
}
|
|
52
|
-
const MAX_MANIFEST_ENTRIES =
|
|
52
|
+
const MAX_MANIFEST_ENTRIES = 1000;
|
|
53
53
|
function findRejection(entry, options) {
|
|
54
54
|
if (!isPassManifestEntry(entry)) {
|
|
55
55
|
return 'the entry is malformed';
|
|
@@ -84,6 +84,5 @@ function isRelativeScope(scope) {
|
|
|
84
84
|
if (scope === '.') {
|
|
85
85
|
return true;
|
|
86
86
|
}
|
|
87
|
-
return
|
|
88
|
-
scope.split('/').every((segment) => segment !== '' && segment !== '.' && segment !== '..'));
|
|
87
|
+
return !path.posix.isAbsolute(scope) && scope.split('/').every((segment) => !['', '.', '..'].includes(segment));
|
|
89
88
|
}
|
|
@@ -8,12 +8,12 @@ export function runHostSession(params) {
|
|
|
8
8
|
const LOCK_PATH = params.lockPath;
|
|
9
9
|
const RECLAIM_GUARD_PATH = `${params.lockPath}.reclaim`;
|
|
10
10
|
const HEARTBEAT_INTERVAL_MS = 10_000;
|
|
11
|
-
const POLL_INTERVAL_MS =
|
|
11
|
+
const POLL_INTERVAL_MS = 1000;
|
|
12
12
|
const RECLAIM_GUARD_STALE_AFTER_MS = 10_000;
|
|
13
13
|
const OUTPUT_LIMIT_BYTES = 65_536;
|
|
14
14
|
const COMMAND_NOT_FOUND_EXIT_CODE = 127;
|
|
15
15
|
const DELEGATION_FAILURE_EXIT_CODE = 255;
|
|
16
|
-
const STOP_GRACE_MS =
|
|
16
|
+
const STOP_GRACE_MS = 5000;
|
|
17
17
|
const NODE_MODULES_DIR = path.join(params.rootDir, 'node_modules');
|
|
18
18
|
const BINS_RECORD_PATH = path.join(NODE_MODULES_DIR, '.nmr-delegate-bins');
|
|
19
19
|
const token = crypto.randomUUID();
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import process from 'node:process';
|
|
2
|
-
import { describeInvalidOutputStyle } from '@williamthorsen/nmr-core';
|
|
2
|
+
import { describeInvalidOutputStyle, UserError } from '@williamthorsen/nmr-core';
|
|
3
3
|
import { resolveOutputStyles } from "./output-style.js";
|
|
4
|
-
import { UserError } from "./UserError.js";
|
|
5
4
|
export function resolveBinStyles() {
|
|
6
5
|
const { invalid: invalidStyle, styles } = resolveOutputStyles({
|
|
7
6
|
env: process.env,
|
package/dist/esm/user-config.js
CHANGED
|
@@ -9,9 +9,9 @@ var __rewriteRelativeImportExtension = (this && this.__rewriteRelativeImportExte
|
|
|
9
9
|
import { existsSync } from 'node:fs';
|
|
10
10
|
import path from 'node:path';
|
|
11
11
|
import { pathToFileURL } from 'node:url';
|
|
12
|
+
import { UserError } from '@williamthorsen/nmr-core';
|
|
12
13
|
import { assertRecognizedKeys } from "./config-validation.js";
|
|
13
14
|
import { isObject } from "./helpers/type-guards.js";
|
|
14
|
-
import { UserError } from "./UserError.js";
|
|
15
15
|
export const DELEGATE_WHEN_VALUES = ['agent', 'always'];
|
|
16
16
|
export function formatDisplayPath(filePath, env) {
|
|
17
17
|
const home = env['HOME'];
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { existsSync, readFileSync, realpathSync, statSync } from 'node:fs';
|
|
2
2
|
import { isBuiltin } from 'node:module';
|
|
3
3
|
import path from 'node:path';
|
|
4
|
+
import { UserError } from '@williamthorsen/nmr-core';
|
|
4
5
|
import { findDirectoryChainMatch } from '@williamthorsen/toolbelt.filesystem';
|
|
5
6
|
import { parsePackageJson } from "./helpers/package-json.js";
|
|
6
7
|
import { isObject } from "./helpers/type-guards.js";
|
|
7
|
-
import { UserError } from "./UserError.js";
|
|
8
8
|
const SHARED_CONDITIONS = ['module', 'import', 'development', 'default'];
|
|
9
9
|
const CLIENT_CONDITION = 'browser';
|
|
10
10
|
const SERVER_CONDITION = 'node';
|
package/dist/esm/workspace.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { findMonorepoRoot as findMonorepoRootOrNothing, resolveWorkspace } from '@williamthorsen/nmr-core/workspace';
|
|
2
|
-
import { UserError } from "./UserError.js";
|
|
3
2
|
const WORKSPACE_MANIFEST = 'pnpm-workspace.yaml';
|
|
4
3
|
export { isMonorepoRoot, readWorkspaceOverrides, readWorkspacePackageNames, resolveWorkspace, } from '@williamthorsen/nmr-core/workspace';
|
|
4
|
+
import { UserError } from '@williamthorsen/nmr-core';
|
|
5
5
|
export function findMonorepoRoot(startDir) {
|
|
6
6
|
const monorepoRoot = findMonorepoRootOrNothing(startDir);
|
|
7
7
|
if (monorepoRoot === undefined) {
|
package/docs/delegate.md
CHANGED
|
@@ -46,13 +46,15 @@ The first rule that applies decides where a command runs:
|
|
|
46
46
|
| 1 | `--no-delegate` | Here |
|
|
47
47
|
| 2 | `--delegate` or `--delegate-to` | On a host; a command that cannot be delegated, or a tree that cannot be snapshotted, is refused |
|
|
48
48
|
| 3 | The repo config declares `delegate: false` | Here |
|
|
49
|
-
| 4 | `
|
|
50
|
-
| 5 | `NMR_DELEGATE`
|
|
51
|
-
| 6 |
|
|
52
|
-
| 7 |
|
|
49
|
+
| 4 | `npm_lifecycle_event` names a package install hook, such as `postinstall` | Here |
|
|
50
|
+
| 5 | `NMR_DELEGATE` names hosts | On a host; a command that cannot be delegated runs here, and a tree that cannot be snapshotted, here with one line |
|
|
51
|
+
| 6 | `NMR_DELEGATE` is set but does not name a host | Here |
|
|
52
|
+
| 7 | The user config's `when` matches, `CI` is unset, and the invocation is not `-F` or `-R` | On a host, as for rule 5; here with one line when no host answers |
|
|
53
|
+
| 8 | Otherwise | Here |
|
|
53
54
|
|
|
54
|
-
- **A step and a `-F` or `-R` child run where their parent runs.** nmr gives every process that it starts an empty `NMR_DELEGATE`, which rule
|
|
55
|
+
- **A step and a `-F` or `-R` child run where their parent runs.** nmr gives every process that it starts an empty `NMR_DELEGATE`, which rule 6 reads as "here"; the run on a host already passes `--no-delegate`, so a host does not apply its own user config. A git hook that an agent's command starts is an agent run.
|
|
55
56
|
- **A repo whose checks must run on the machine that has the tree** declares `delegate: false` in `.config/nmr.config.ts`, the only value that the repo config accepts for the key. It outranks `NMR_DELEGATE` and the user config, but not a flag.
|
|
57
|
+
- **A command in a package install hook runs here unless a flag asks otherwise.** During `pnpm add`, a hook such as `postinstall` sees a manifest that its lockfile does not match yet, and the host's frozen install of that tree fails. A command in any other `package.json` script, such as `test`, delegates as usual.
|
|
56
58
|
- **`NMR_DEBUG=1` names what sent a command to a host**, such as `delegating ci per ~/.config/nmr/config.ts (when: agent)`, `per NMR_DELEGATE`, or `per --delegate-to`.
|
|
57
59
|
|
|
58
60
|
### Choosing among several hosts
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@williamthorsen/nmr",
|
|
3
|
-
"version": "0.54.
|
|
3
|
+
"version": "0.54.1",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "Context-aware script runner for pnpm monorepos",
|
|
6
6
|
"keywords": [
|
|
@@ -79,7 +79,7 @@
|
|
|
79
79
|
"!docs/*.v*.md"
|
|
80
80
|
],
|
|
81
81
|
"dependencies": {
|
|
82
|
-
"@williamthorsen/nmr-core": "0.
|
|
82
|
+
"@williamthorsen/nmr-core": "0.15.0",
|
|
83
83
|
"@williamthorsen/toolbelt.errors": "0.9.0",
|
|
84
84
|
"@williamthorsen/toolbelt.filesystem": "0.10.0",
|
|
85
85
|
"glob": "14.0.3",
|
|
@@ -92,11 +92,11 @@
|
|
|
92
92
|
"@williamthorsen/toolbelt.testing": "0.8.0",
|
|
93
93
|
"@williamthorsen/toolbelt.vitest": "0.13.1",
|
|
94
94
|
"esbuild": "0.28.2",
|
|
95
|
-
"readyup": "0.
|
|
95
|
+
"readyup": "0.45.0",
|
|
96
96
|
"tinyglobby": "0.2.17",
|
|
97
97
|
"typescript": "6.0.3",
|
|
98
98
|
"vite": "8.3.5",
|
|
99
|
-
"vitest": "5.0
|
|
99
|
+
"vitest": "5.1.0",
|
|
100
100
|
"yaml": "2.9.1"
|
|
101
101
|
},
|
|
102
102
|
"peerDependencies": {
|
package/dist/esm/UserError.d.ts
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* A failure in what the user declared -- a config file, a `package.json` -- rather than a fault in nmr.
|
|
3
|
-
*
|
|
4
|
-
* The CLI boundary prints one of these as its message alone.
|
|
5
|
-
*/
|
|
6
|
-
export declare class UserError extends Error {
|
|
7
|
-
constructor(message: string);
|
|
8
|
-
}
|
package/dist/esm/UserError.js
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import type { Writable } from 'node:stream';
|
|
2
|
-
/**
|
|
3
|
-
* Writes a failure to the CLI's error stream: as its message alone when the user's own declaration caused it,
|
|
4
|
-
* and with its stack otherwise.
|
|
5
|
-
*
|
|
6
|
-
* A stack records where nmr noticed a problem, which says nothing about the file that a user has to edit; for
|
|
7
|
-
* nmr's own fault it is where a report has to start.
|
|
8
|
-
*/
|
|
9
|
-
export declare function reportCliFailure(error: unknown, stderr: Writable): void;
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { reportError } from '@williamthorsen/nmr-core';
|
|
2
|
-
import { describeError, isError } from '@williamthorsen/toolbelt.errors';
|
|
3
|
-
import { UserError } from "./UserError.js";
|
|
4
|
-
export function reportCliFailure(error, stderr) {
|
|
5
|
-
if (error instanceof UserError) {
|
|
6
|
-
reportError(error.message, stderr);
|
|
7
|
-
return;
|
|
8
|
-
}
|
|
9
|
-
const detail = isError(error) && error.stack !== undefined ? error.stack : describeError(error);
|
|
10
|
-
stderr.write(`${detail}\n`);
|
|
11
|
-
}
|