@williamthorsen/nmr 2.2.0 → 2.2.2

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.
@@ -1,4 +1,54 @@
1
1
  [
2
+ {
3
+ "version": "2.2.2",
4
+ "date": "2026-11-14",
5
+ "sections": [
6
+ {
7
+ "title": "♻️ Refactoring",
8
+ "audience": "dev",
9
+ "items": [
10
+ {
11
+ "description": "Moves the unexported helpers in `nmr`'s source modules into a trailing region of each module, sorted alphabetically, so that each module leads with its exports. (#1345)",
12
+ "hash": "80000b47998deb1d42a585f9a675a98045afb880",
13
+ "entry": 1
14
+ }
15
+ ]
16
+ },
17
+ {
18
+ "title": "🧪 Tests",
19
+ "audience": "dev",
20
+ "items": [
21
+ {
22
+ "description": "Moves the module-level helpers in `nmr`'s test files below the `describe` blocks, into a sorted `Helpers` region, so that each file leads with its tests. (#1345)",
23
+ "hash": "80000b47998deb1d42a585f9a675a98045afb880",
24
+ "entry": 2
25
+ },
26
+ {
27
+ "description": "Fixes the issue that `removeStaleCheckouts.unit.test.ts` failed intermittently with `ENOENT` when the detached `rm` deleted the moved checkout after the test listed the directory, by checking the inode only of the entries that still exist. (#1352)",
28
+ "hash": "18c12fa0b8eec0583f9bf4b3f321bb57516feb1c",
29
+ "entry": 1
30
+ }
31
+ ]
32
+ }
33
+ ]
34
+ },
35
+ {
36
+ "version": "2.2.1",
37
+ "date": "2026-11-13",
38
+ "sections": [
39
+ {
40
+ "title": "🐛 Bug fixes",
41
+ "audience": "all",
42
+ "items": [
43
+ {
44
+ "description": "Fixes the issue that a delegated `nmr` run on a host whose Node comes from a version manager's shims ran on the Node chosen before the checkout, rather than the one pinned by the snapshot, on the first delegation from a clone and the first after a repo changed its pin. (#1337)",
45
+ "hash": "eb9f33c1b5cc919e00f7d33927899c48dbe7c3f7",
46
+ "entry": 1
47
+ }
48
+ ]
49
+ }
50
+ ]
51
+ },
2
52
  {
3
53
  "version": "2.2.0",
4
54
  "date": "2026-11-12",
@@ -1,6 +1,6 @@
1
1
  /** @noformat -- @generated. Do not edit. Compiled by rdy. */
2
2
  /* eslint-disable */
3
- export const __readyupVersion = "0.46.1";
3
+ export const __readyupVersion = "0.46.2";
4
4
  import { createRequire as __rdyCreateRequire } from 'node:module';
5
5
  const require = __rdyCreateRequire(import.meta.url);
6
6
 
@@ -7382,12 +7382,12 @@ import { isRecord, listTrackedFiles } from "readyup/check-utils";
7382
7382
  import { globSync } from "node:fs";
7383
7383
  import { basename, join, sep } from "node:path";
7384
7384
 
7385
- // ../../node_modules/.pnpm/@williamthorsen+toolbelt.errors@0.10.0/node_modules/@williamthorsen/toolbelt.errors/dist/esm/4-release/isError.js
7385
+ // ../../node_modules/.pnpm/@williamthorsen+toolbelt.errors@0.10.1/node_modules/@williamthorsen/toolbelt.errors/dist/esm/4-release/isError.js
7386
7386
  function isError(error) {
7387
7387
  return error instanceof Error || Object.prototype.toString.call(error) === "[object Error]";
7388
7388
  }
7389
7389
 
7390
- // ../../node_modules/.pnpm/@williamthorsen+toolbelt.errors@0.10.0/node_modules/@williamthorsen/toolbelt.errors/dist/esm/4-release/describeError.js
7390
+ // ../../node_modules/.pnpm/@williamthorsen+toolbelt.errors@0.10.1/node_modules/@williamthorsen/toolbelt.errors/dist/esm/4-release/describeError.js
7391
7391
  function describeError(error) {
7392
7392
  try {
7393
7393
  if (isError(error) && typeof error.message === "string" && error.message !== "") {
@@ -8161,11 +8161,11 @@ function formatMalformedScript(dir, key, value) {
8161
8161
  return `${rejection} A step list belongs in \`${CONFIG_RELATIVE_PATH}\` under \`${field}\`.`;
8162
8162
  }
8163
8163
 
8164
- // ../../node_modules/.pnpm/@williamthorsen+toolbelt.cli@0.8.2/node_modules/@williamthorsen/toolbelt.cli/dist/esm/3-candidate/parseArgs.js
8164
+ // ../../node_modules/.pnpm/@williamthorsen+toolbelt.cli@0.10.0/node_modules/@williamthorsen/toolbelt.cli/dist/esm/3-candidate/parseArgs.js
8165
8165
  import path6 from "node:path";
8166
8166
  import process2 from "node:process";
8167
8167
 
8168
- // ../../node_modules/.pnpm/@williamthorsen+toolbelt.cli@0.8.2/node_modules/@williamthorsen/toolbelt.cli/dist/esm/3-candidate/UsageError.js
8168
+ // ../../node_modules/.pnpm/@williamthorsen+toolbelt.cli@0.10.0/node_modules/@williamthorsen/toolbelt.cli/dist/esm/3-candidate/UsageError.js
8169
8169
  var UsageError = class extends Error {
8170
8170
  constructor(message, options) {
8171
8171
  super(message, options);
@@ -8173,7 +8173,7 @@ var UsageError = class extends Error {
8173
8173
  }
8174
8174
  };
8175
8175
 
8176
- // ../../node_modules/.pnpm/@williamthorsen+toolbelt.cli@0.8.2/node_modules/@williamthorsen/toolbelt.cli/dist/esm/3-candidate/ParseError.js
8176
+ // ../../node_modules/.pnpm/@williamthorsen+toolbelt.cli@0.10.0/node_modules/@williamthorsen/toolbelt.cli/dist/esm/3-candidate/ParseError.js
8177
8177
  var ParseError = class extends UsageError {
8178
8178
  kind;
8179
8179
  token;
@@ -8185,12 +8185,12 @@ var ParseError = class extends UsageError {
8185
8185
  }
8186
8186
  };
8187
8187
 
8188
- // ../../node_modules/.pnpm/@williamthorsen+toolbelt.cli@0.8.2/node_modules/@williamthorsen/toolbelt.cli/dist/esm/3-candidate/resolveLongName.js
8188
+ // ../../node_modules/.pnpm/@williamthorsen+toolbelt.cli@0.10.0/node_modules/@williamthorsen/toolbelt.cli/dist/esm/3-candidate/resolveLongName.js
8189
8189
  function resolveLongName(key, definition) {
8190
8190
  return definition.long ?? key.replaceAll(/[A-Z]/g, (capital) => `-${capital.toLowerCase()}`);
8191
8191
  }
8192
8192
 
8193
- // ../../node_modules/.pnpm/@williamthorsen+toolbelt.cli@0.8.2/node_modules/@williamthorsen/toolbelt.cli/dist/esm/3-candidate/tokenizeArgs.js
8193
+ // ../../node_modules/.pnpm/@williamthorsen+toolbelt.cli@0.10.0/node_modules/@williamthorsen/toolbelt.cli/dist/esm/3-candidate/tokenizeArgs.js
8194
8194
  import { parseArgs as nodeParseArgs } from "node:util";
8195
8195
  function tokenizeArgs(argv, schema, extraBooleans = []) {
8196
8196
  const nodeOptions = {};
@@ -8220,7 +8220,7 @@ function findFlagEntry(flagsByName, token) {
8220
8220
  return entry.definition.short === token.rawName.slice(1) ? entry : void 0;
8221
8221
  }
8222
8222
 
8223
- // ../../node_modules/.pnpm/@williamthorsen+toolbelt.cli@0.8.2/node_modules/@williamthorsen/toolbelt.cli/dist/esm/3-candidate/validateSpec.js
8223
+ // ../../node_modules/.pnpm/@williamthorsen+toolbelt.cli@0.10.0/node_modules/@williamthorsen/toolbelt.cli/dist/esm/3-candidate/validateSpec.js
8224
8224
  var CAMEL_CASE_KEY = /^[a-z][a-z0-9]*(?:[A-Z][a-z0-9]+)*$/;
8225
8225
  function validateSpec(spec) {
8226
8226
  validateFlags(spec.flags ?? {});
@@ -8301,7 +8301,7 @@ function validateOperands(operands) {
8301
8301
  }
8302
8302
  }
8303
8303
 
8304
- // ../../node_modules/.pnpm/@williamthorsen+toolbelt.cli@0.8.2/node_modules/@williamthorsen/toolbelt.cli/dist/esm/3-candidate/parseArgs.js
8304
+ // ../../node_modules/.pnpm/@williamthorsen+toolbelt.cli@0.10.0/node_modules/@williamthorsen/toolbelt.cli/dist/esm/3-candidate/parseArgs.js
8305
8305
  function parseArgs(argv, spec, options = {}) {
8306
8306
  validateSpec(spec);
8307
8307
  return parseValidatedArgs(argv, spec, options);
@@ -8632,16 +8632,6 @@ function readNmrTarget(tokens) {
8632
8632
  function describeScript(script) {
8633
8633
  return typeof script === "string" ? script : `[${script.map(describeElement).join(", ")}]`;
8634
8634
  }
8635
- function describeElement(element) {
8636
- if (typeof element === "string") {
8637
- return element;
8638
- }
8639
- const notes = [
8640
- ...element.shouldRunInBackground === true ? ["background"] : [],
8641
- ...element.shouldDeclineArguments === true ? ["no args"] : []
8642
- ];
8643
- return notes.length === 0 ? element.run : `${element.run} (${notes.join(", ")})`;
8644
- }
8645
8635
  function readPackageJsonScripts(packageDir) {
8646
8636
  const file = resolvePackageJsonPath(packageDir);
8647
8637
  let rawText;
@@ -8671,6 +8661,16 @@ function buildRootRegistry(config, monorepoRoot) {
8671
8661
  ...config.rootScripts
8672
8662
  };
8673
8663
  }
8664
+ function describeElement(element) {
8665
+ if (typeof element === "string") {
8666
+ return element;
8667
+ }
8668
+ const notes = [
8669
+ ...element.shouldRunInBackground === true ? ["background"] : [],
8670
+ ...element.shouldDeclineArguments === true ? ["no args"] : []
8671
+ ];
8672
+ return notes.length === 0 ? element.run : `${element.run} (${notes.join(", ")})`;
8673
+ }
8674
8674
 
8675
8675
  // src/assertResolvableCommandLists.ts
8676
8676
  function assertResolvableCommandLists(config, configPath, baseDir) {
@@ -8838,6 +8838,11 @@ function formatKeyList(keys, prefix) {
8838
8838
  function isOptionalBoolean(value) {
8839
8839
  return value === void 0 || typeof value === "boolean";
8840
8840
  }
8841
+ function isScriptElement(value) {
8842
+ if (typeof value === "string") return true;
8843
+ if (!isRecord2(value) || typeof value["run"] !== "string") return false;
8844
+ return isOptionalBoolean(value["shouldDeclineArguments"]) && isOptionalBoolean(value["shouldRunInBackground"]);
8845
+ }
8841
8846
  function isScriptRecord(value) {
8842
8847
  if (!isRecord2(value)) return false;
8843
8848
  for (const v of Object.values(value)) {
@@ -8846,11 +8851,6 @@ function isScriptRecord(value) {
8846
8851
  }
8847
8852
  return true;
8848
8853
  }
8849
- function isScriptElement(value) {
8850
- if (typeof value === "string") return true;
8851
- if (!isRecord2(value) || typeof value["run"] !== "string") return false;
8852
- return isOptionalBoolean(value["shouldDeclineArguments"]) && isOptionalBoolean(value["shouldRunInBackground"]);
8853
- }
8854
8854
  function isStringArray(value) {
8855
8855
  return Array.isArray(value) && value.every((item) => typeof item === "string");
8856
8856
  }
@@ -8953,6 +8953,19 @@ function validateOutputField(value, configPath) {
8953
8953
  }
8954
8954
  return config;
8955
8955
  }
8956
+ function validateScriptField(value, fieldName, configPath) {
8957
+ if (!Object.hasOwn(value, fieldName) || value[fieldName] === void 0) {
8958
+ return void 0;
8959
+ }
8960
+ const scripts = value[fieldName];
8961
+ if (!isScriptRecord(scripts)) {
8962
+ throw new UserError(
8963
+ `Invalid nmr config at ${configPath}: \`${fieldName}\` must be a Record<string, string | element[]>, where an element is a command string or \`{ run: string, shouldDeclineArguments?: boolean, shouldRunInBackground?: boolean }\``
8964
+ );
8965
+ }
8966
+ assertValidElements(scripts, fieldName, configPath);
8967
+ return scripts;
8968
+ }
8956
8969
  function validateSelfHostedRunnerField(value, configPath) {
8957
8970
  const selfHostedRunner = value["selfHostedRunner"];
8958
8971
  if (selfHostedRunner === void 0) {
@@ -8970,19 +8983,6 @@ function validateSelfHostedRunnerField(value, configPath) {
8970
8983
  }
8971
8984
  return { exempt };
8972
8985
  }
8973
- function validateScriptField(value, fieldName, configPath) {
8974
- if (!Object.hasOwn(value, fieldName) || value[fieldName] === void 0) {
8975
- return void 0;
8976
- }
8977
- const scripts = value[fieldName];
8978
- if (!isScriptRecord(scripts)) {
8979
- throw new UserError(
8980
- `Invalid nmr config at ${configPath}: \`${fieldName}\` must be a Record<string, string | element[]>, where an element is a command string or \`{ run: string, shouldDeclineArguments?: boolean, shouldRunInBackground?: boolean }\``
8981
- );
8982
- }
8983
- assertValidElements(scripts, fieldName, configPath);
8984
- return scripts;
8985
- }
8986
8986
 
8987
8987
  // src/helpers/escapeControlCharacters.ts
8988
8988
  var NAMED_ESCAPES = /* @__PURE__ */ new Map([
@@ -9662,7 +9662,7 @@ function hasSupportedStrictLintVersion() {
9662
9662
  });
9663
9663
  }
9664
9664
  function getMinVersion() {
9665
- const pickedFields = { "version": "2.2.0" };
9665
+ const pickedFields = { "version": "2.2.2" };
9666
9666
  if (typeof pickedFields["version"] !== "string") {
9667
9667
  throw new TypeError("nmr/package.json: 'version' must be a string");
9668
9668
  }
@@ -3,17 +3,17 @@
3
3
  "kits": [
4
4
  {
5
5
  "bundledDependencies": {
6
- "@williamthorsen/toolbelt.arrays": "6.5.0",
7
- "@williamthorsen/toolbelt.cli": "0.8.2",
8
- "@williamthorsen/toolbelt.datetime": "4.1.3",
9
- "@williamthorsen/toolbelt.errors": "0.10.0",
10
- "@williamthorsen/toolbelt.filesystem": "0.10.2",
11
- "@williamthorsen/toolbelt.guards": "4.2.2",
12
- "@williamthorsen/toolbelt.numbers": "8.0.0",
13
- "@williamthorsen/toolbelt.objects": "4.4.2",
14
- "@williamthorsen/toolbelt.packaging": "0.7.2",
6
+ "@williamthorsen/toolbelt.arrays": "6.5.2",
7
+ "@williamthorsen/toolbelt.cli": "0.10.0",
8
+ "@williamthorsen/toolbelt.datetime": "4.1.5",
9
+ "@williamthorsen/toolbelt.errors": "0.10.1",
10
+ "@williamthorsen/toolbelt.filesystem": "0.11.0",
11
+ "@williamthorsen/toolbelt.guards": "4.2.3",
12
+ "@williamthorsen/toolbelt.numbers": "8.0.2",
13
+ "@williamthorsen/toolbelt.objects": "4.4.3",
14
+ "@williamthorsen/toolbelt.packaging": "0.8.0",
15
15
  "@williamthorsen/toolbelt.sets": "3.1.1",
16
- "@williamthorsen/toolbelt.strings": "8.2.3",
16
+ "@williamthorsen/toolbelt.strings": "9.0.0",
17
17
  "@williamthorsen/toolbelt.terminal": "0.3.1",
18
18
  "ansi-regex": "6.6.0",
19
19
  "ansi-styles": "6.2.3, 7.0.0",
@@ -31,7 +31,7 @@
31
31
  "checklist": "nmr",
32
32
  "checks": [
33
33
  "@williamthorsen/nmr in devDependencies",
34
- "@williamthorsen/nmr >= 2.2.0",
34
+ "@williamthorsen/nmr >= 2.2.2",
35
35
  "pnpm-workspace.yaml exists",
36
36
  "catalogued dependencies use catalog:",
37
37
  "package.json has packageManager field",
@@ -235,7 +235,7 @@
235
235
  "path": "lib/workspace-build.ts"
236
236
  },
237
237
  {
238
- "hash": "7015d006",
238
+ "hash": "c1260e70",
239
239
  "kind": "inline",
240
240
  "path": "../package.json",
241
241
  "paths": [
@@ -253,7 +253,7 @@
253
253
  "path": "../src/commands/ensure-prepublish-hooks.ts"
254
254
  },
255
255
  {
256
- "hash": "8c3aa404",
256
+ "hash": "4ab792b6",
257
257
  "kind": "module",
258
258
  "path": "../src/config-validation.ts"
259
259
  },
@@ -323,7 +323,7 @@
323
323
  "path": "../src/resolve-scripts.ts"
324
324
  },
325
325
  {
326
- "hash": "0112952e",
326
+ "hash": "3e3aff50",
327
327
  "kind": "module",
328
328
  "path": "../src/resolver.ts"
329
329
  },
@@ -360,10 +360,10 @@
360
360
  ],
361
361
  "name": "default",
362
362
  "path": "kits/default.js",
363
- "readyupVersion": "0.46.1",
363
+ "readyupVersion": "0.46.2",
364
364
  "source": "kits/default.ts",
365
365
  "sourceHash": "9fd61bf4",
366
- "targetHash": "177bd0ca"
366
+ "targetHash": "9d07e5f2"
367
367
  }
368
368
  ]
369
369
  }
package/CHANGELOG.md CHANGED
@@ -2,6 +2,23 @@
2
2
 
3
3
  All notable changes to this project will be documented in this file.
4
4
 
5
+ ## 2.2.2 — 2026-11-14
6
+
7
+ ### ♻️ Refactoring
8
+
9
+ - Moves the unexported helpers in `nmr`'s source modules into a trailing region of each module, sorted alphabetically, so that each module leads with its exports. (#1345)
10
+
11
+ ### 🧪 Tests
12
+
13
+ - Moves the module-level helpers in `nmr`'s test files below the `describe` blocks, into a sorted `Helpers` region, so that each file leads with its tests. (#1345)
14
+ - Fixes the issue that `removeStaleCheckouts.unit.test.ts` failed intermittently with `ENOENT` when the detached `rm` deleted the moved checkout after the test listed the directory, by checking the inode only of the entries that still exist. (#1352)
15
+
16
+ ## 2.2.1 — 2026-11-13
17
+
18
+ ### 🐛 Bug fixes
19
+
20
+ - Fixes the issue that a delegated `nmr` run on a host whose Node comes from a version manager's shims ran on the Node chosen before the checkout, rather than the one pinned by the snapshot, on the first delegation from a clone and the first after a repo changed its pin. (#1337)
21
+
5
22
  ## 2.2.0 — 2026-11-12
6
23
 
7
24
  ### 🎉 Features
package/README.md CHANGED
@@ -4,14 +4,7 @@
4
4
 
5
5
  Context-aware script runner for pnpm monorepos. Includes an `nmr` (node-monorepo run) binary that provides centralized, consistent script execution across workspace packages and the monorepo root.
6
6
 
7
- <!-- section:release-notes -->
8
- ## Release notes — v2.2.0 (2026-11-12)
9
-
10
- ### 🎉 Features
11
-
12
- - Makes each `nmr` delegation remove, before it pushes, the host's other checkouts that have gone unused for longer than the new user-config key `delegate.removeCheckoutsAfterDays` allows (7 days by default, `false` to keep them), while keeping any checkout whose lock has a live holder. (#1317)
13
- - Adds to the failure message of a delegation step that fails with `No space left on device` whether the host's filesystem ran out of inodes or of space. (#1317)
14
- <!-- /section:release-notes -->
7
+ <!-- section:release-notes --><!-- /section:release-notes -->
15
8
 
16
9
  ## Installation
17
10
 
@@ -57,6 +57,31 @@ export async function computeBuildHash(packageDir, files, emitConfig, toolchain)
57
57
  hash.update(toolchain.fingerprint);
58
58
  return hash.digest('hex');
59
59
  }
60
+ export async function recordUnchangedBuild(packageDir, digest, env) {
61
+ const savedMs = await readEmitDuration(packageDir, digest);
62
+ await writeStatedOutcome(env, { kind: 'build-unchanged', ...(savedMs !== undefined && { savedMs }) });
63
+ return savedMs;
64
+ }
65
+ function assertEmitSucceeded(result) {
66
+ if (result.emitSkipped) {
67
+ throw new UserError(`emit failed.\n${formatDiagnostics(result.diagnostics)}`);
68
+ }
69
+ }
70
+ function createCachingCompilerHost(compilerOptions) {
71
+ const ts = getCompiler();
72
+ const host = ts.createCompilerHost(compilerOptions);
73
+ const parsedFiles = new Map();
74
+ const readSourceFile = host.getSourceFile.bind(host);
75
+ host.getSourceFile = (fileName, languageVersionOrOptions, onError, shouldCreateNewSourceFile) => {
76
+ if (parsedFiles.has(fileName)) {
77
+ return parsedFiles.get(fileName);
78
+ }
79
+ const sourceFile = readSourceFile(fileName, languageVersionOrOptions, onError, shouldCreateNewSourceFile);
80
+ parsedFiles.set(fileName, sourceFile);
81
+ return sourceFile;
82
+ };
83
+ return host;
84
+ }
60
85
  async function emitPackage(packageDir, entryPoints, outdir) {
61
86
  const ts = getCompiler();
62
87
  const compilerOptions = synthesizeCompilerOptions(packageDir, outdir);
@@ -79,26 +104,6 @@ async function emitPackage(packageDir, entryPoints, outdir) {
79
104
  }
80
105
  return publishOutput(emitDir, stagedFiles);
81
106
  }
82
- function assertEmitSucceeded(result) {
83
- if (result.emitSkipped) {
84
- throw new UserError(`emit failed.\n${formatDiagnostics(result.diagnostics)}`);
85
- }
86
- }
87
- function createCachingCompilerHost(compilerOptions) {
88
- const ts = getCompiler();
89
- const host = ts.createCompilerHost(compilerOptions);
90
- const parsedFiles = new Map();
91
- const readSourceFile = host.getSourceFile.bind(host);
92
- host.getSourceFile = (fileName, languageVersionOrOptions, onError, shouldCreateNewSourceFile) => {
93
- if (parsedFiles.has(fileName)) {
94
- return parsedFiles.get(fileName);
95
- }
96
- const sourceFile = readSourceFile(fileName, languageVersionOrOptions, onError, shouldCreateNewSourceFile);
97
- parsedFiles.set(fileName, sourceFile);
98
- return sourceFile;
99
- };
100
- return host;
101
- }
102
107
  function resolveEmitDir(packageDir, outdir) {
103
108
  const resolvedDir = path.resolve(packageDir, outdir);
104
109
  const relativePathFromPackage = path.relative(packageDir, resolvedDir);
@@ -144,8 +149,3 @@ async function detectBuildChanges(packageDir, files, emitConfig, toolchain, cach
144
149
  }
145
150
  return { reason: isOutputPresent ? 'unchanged' : 'output-missing', currentHash };
146
151
  }
147
- export async function recordUnchangedBuild(packageDir, digest, env) {
148
- const savedMs = await readEmitDuration(packageDir, digest);
149
- await writeStatedOutcome(env, { kind: 'build-unchanged', ...(savedMs !== undefined && { savedMs }) });
150
- return savedMs;
151
- }
@@ -46,6 +46,68 @@ export async function runFmt(argv, cwd = process.cwd(), env = process.env) {
46
46
  });
47
47
  return runCli(argv, command, { name: NMR_FMT_BIN, stdout: process.stdout, stderr: process.stderr, baseDir: cwd });
48
48
  }
49
+ export function runPrettier(options) {
50
+ const { cacheLocation, cliPath, configPath, mode, files, ignorePaths, cwd, budgetBytes = ARGUMENT_BUDGET_BYTES, spawn = spawnInherited, } = options;
51
+ const prettierArgs = [
52
+ cliPath,
53
+ ...(configPath === undefined ? [] : ['--config', configPath]),
54
+ '--ignore-unknown',
55
+ ...ignorePaths.flatMap((ignorePath) => ['--ignore-path', ignorePath]),
56
+ ...(cacheLocation === undefined
57
+ ? []
58
+ : ['--cache', '--cache-strategy', 'content', '--cache-location', cacheLocation]),
59
+ ...MODE_ARGS[mode],
60
+ '--',
61
+ ];
62
+ let firstFailureStatus = 0;
63
+ for (const batch of batchWithinBudget(files, budgetBytes)) {
64
+ const result = spawn(process.execPath, [...prettierArgs, ...batch], { cwd });
65
+ if (result.error) {
66
+ reportError(NMR_FMT_BIN, `could not run \`${PRETTIER_PACKAGE}\` (${result.error.message}).`);
67
+ return 1;
68
+ }
69
+ const status = resolveInheritedExitCode(result);
70
+ if (status !== 0 && firstFailureStatus === 0) {
71
+ firstFailureStatus = status;
72
+ }
73
+ }
74
+ return firstFailureStatus;
75
+ }
76
+ function batchWithinBudget(files, budgetBytes) {
77
+ const batches = [];
78
+ let batch = [];
79
+ let sizeBytes = 0;
80
+ for (const file of files) {
81
+ const costBytes = Buffer.byteLength(file) + 1;
82
+ if (batch.length > 0 && sizeBytes + costBytes > budgetBytes) {
83
+ batches.push(batch);
84
+ batch = [];
85
+ sizeBytes = 0;
86
+ }
87
+ batch.push(file);
88
+ sizeBytes += costBytes;
89
+ }
90
+ if (batch.length > 0)
91
+ batches.push(batch);
92
+ return batches;
93
+ }
94
+ async function findRepositoryConfig(manifestPath, cwd) {
95
+ try {
96
+ const prettier = createRequire(manifestPath)(PRETTIER_PACKAGE);
97
+ const resolveConfigFile = isRecord(prettier) ? prettier['resolveConfigFile'] : undefined;
98
+ if (typeof resolveConfigFile !== 'function') {
99
+ return {
100
+ ok: false,
101
+ error: `\`${PRETTIER_PACKAGE}\` at ${path.dirname(manifestPath)} does not export \`resolveConfigFile\`.`,
102
+ };
103
+ }
104
+ const configFile = await Reflect.apply(resolveConfigFile, undefined, [path.join(cwd, 'placeholder')]);
105
+ return { ok: true, found: configFile !== null };
106
+ }
107
+ catch (error) {
108
+ return { ok: false, error: `could not search for a Prettier config: ${describeError(error)}` };
109
+ }
110
+ }
49
111
  async function formatFiles(request, cwd, env) {
50
112
  const resolvedTargets = resolveFormatTargets(cwd, request.pathspecs);
51
113
  if (!resolvedTargets.ok) {
@@ -133,65 +195,3 @@ function resolvePrettierCli(cwd) {
133
195
  }
134
196
  return { ok: true, cliPath, manifestPath };
135
197
  }
136
- async function findRepositoryConfig(manifestPath, cwd) {
137
- try {
138
- const prettier = createRequire(manifestPath)(PRETTIER_PACKAGE);
139
- const resolveConfigFile = isRecord(prettier) ? prettier['resolveConfigFile'] : undefined;
140
- if (typeof resolveConfigFile !== 'function') {
141
- return {
142
- ok: false,
143
- error: `\`${PRETTIER_PACKAGE}\` at ${path.dirname(manifestPath)} does not export \`resolveConfigFile\`.`,
144
- };
145
- }
146
- const configFile = await Reflect.apply(resolveConfigFile, undefined, [path.join(cwd, 'placeholder')]);
147
- return { ok: true, found: configFile !== null };
148
- }
149
- catch (error) {
150
- return { ok: false, error: `could not search for a Prettier config: ${describeError(error)}` };
151
- }
152
- }
153
- export function runPrettier(options) {
154
- const { cacheLocation, cliPath, configPath, mode, files, ignorePaths, cwd, budgetBytes = ARGUMENT_BUDGET_BYTES, spawn = spawnInherited, } = options;
155
- const prettierArgs = [
156
- cliPath,
157
- ...(configPath === undefined ? [] : ['--config', configPath]),
158
- '--ignore-unknown',
159
- ...ignorePaths.flatMap((ignorePath) => ['--ignore-path', ignorePath]),
160
- ...(cacheLocation === undefined
161
- ? []
162
- : ['--cache', '--cache-strategy', 'content', '--cache-location', cacheLocation]),
163
- ...MODE_ARGS[mode],
164
- '--',
165
- ];
166
- let firstFailureStatus = 0;
167
- for (const batch of batchWithinBudget(files, budgetBytes)) {
168
- const result = spawn(process.execPath, [...prettierArgs, ...batch], { cwd });
169
- if (result.error) {
170
- reportError(NMR_FMT_BIN, `could not run \`${PRETTIER_PACKAGE}\` (${result.error.message}).`);
171
- return 1;
172
- }
173
- const status = resolveInheritedExitCode(result);
174
- if (status !== 0 && firstFailureStatus === 0) {
175
- firstFailureStatus = status;
176
- }
177
- }
178
- return firstFailureStatus;
179
- }
180
- function batchWithinBudget(files, budgetBytes) {
181
- const batches = [];
182
- let batch = [];
183
- let sizeBytes = 0;
184
- for (const file of files) {
185
- const costBytes = Buffer.byteLength(file) + 1;
186
- if (batch.length > 0 && sizeBytes + costBytes > budgetBytes) {
187
- batches.push(batch);
188
- batch = [];
189
- sizeBytes = 0;
190
- }
191
- batch.push(file);
192
- sizeBytes += costBytes;
193
- }
194
- if (batch.length > 0)
195
- batches.push(batch);
196
- return batches;
197
- }
@@ -143,6 +143,9 @@ function findNodePin(content) {
143
143
  function isMissingFileError(error) {
144
144
  return isRecord(error) && error['code'] === 'ENOENT';
145
145
  }
146
+ function parseVersion(version) {
147
+ return version.split('.').map(Number);
148
+ }
146
149
  async function requestNodeBuildDefinition(version) {
147
150
  const response = await fetch(`${NODE_BUILD_DEFINITION_URL}${version}`, {
148
151
  method: 'HEAD',
@@ -154,6 +157,3 @@ async function requestNodeBuildDefinition(version) {
154
157
  throw new Error(`HTTP ${response.status}`);
155
158
  return true;
156
159
  }
157
- function parseVersion(version) {
158
- return version.split('.').map(Number);
159
- }
@@ -29,6 +29,12 @@ function composeComplementFilter(key, earlierKeys) {
29
29
  function convertGlobToRegexBody(glob) {
30
30
  return glob.replaceAll(/[.+?^${}()|[\]\\]/g, String.raw `\$&`).replaceAll(/\*+/g, '.*?');
31
31
  }
32
+ function isPlainObject(value) {
33
+ if (typeof value !== 'object' || value === null)
34
+ return false;
35
+ const prototype = Object.getPrototypeOf(value);
36
+ return prototype === Object.prototype || prototype === null;
37
+ }
32
38
  function validatePackageMaturityPeriod(value) {
33
39
  if (value === undefined)
34
40
  return [];
@@ -51,9 +57,3 @@ function validatePackageMaturityPeriod(value) {
51
57
  return [key, days];
52
58
  });
53
59
  }
54
- function isPlainObject(value) {
55
- if (typeof value !== 'object' || value === null)
56
- return false;
57
- const prototype = Object.getPrototypeOf(value);
58
- return prototype === Object.prototype || prototype === null;
59
- }
@@ -63,9 +63,9 @@ function classifyListedFile(cwd, file) {
63
63
  return { kind: 'failed', error: `could not stat ${file}: ${describeError(error)}` };
64
64
  }
65
65
  }
66
- function splitNulSeparated(output) {
67
- return output.split('\0').filter((entry) => entry !== '');
68
- }
69
66
  function dedupe(items) {
70
67
  return [...new Set(items)];
71
68
  }
69
+ function splitNulSeparated(output) {
70
+ return output.split('\0').filter((entry) => entry !== '');
71
+ }