@williamthorsen/nmr-core 0.9.3 → 0.10.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.
@@ -10,6 +10,7 @@ export interface CacheEntryRef extends CacheDirRef {
10
10
  export declare function readCacheEntry(entryPath: string): Promise<string | undefined>;
11
11
  export declare function readJsonCacheEntry<T>(entryPath: string, isValidEntry: (value: unknown) => value is T): Promise<T | undefined>;
12
12
  export declare function removeCacheDir(ref: CacheDirRef): Promise<void>;
13
+ export declare function removeCacheEntry(entryPath: string): Promise<void>;
13
14
  export declare function resolveCacheDir(ref: CacheDirRef): string;
14
15
  export declare function resolveCacheEntryPath(ref: CacheEntryRef): string;
15
16
  export declare function writeCacheEntry(entryPath: string, content: string): Promise<void>;
@@ -28,6 +28,9 @@ export async function readJsonCacheEntry(entryPath, isValidEntry) {
28
28
  export async function removeCacheDir(ref) {
29
29
  await rm(resolveCacheDir(ref), { force: true, recursive: true });
30
30
  }
31
+ export async function removeCacheEntry(entryPath) {
32
+ await rm(entryPath, { force: true });
33
+ }
31
34
  export function resolveCacheDir(ref) {
32
35
  const absoluteScopeDir = path.resolve(ref.scopeDir);
33
36
  const home = findNearestNodeModulesHost(absoluteScopeDir) ?? absoluteScopeDir;
@@ -0,0 +1,3 @@
1
+ export declare function hasErrnoCode(error: unknown, code: string): error is Error & {
2
+ code: string;
3
+ };
@@ -0,0 +1,4 @@
1
+ import { isError } from '@williamthorsen/toolbelt.errors';
2
+ export function hasErrnoCode(error, code) {
3
+ return isError(error) && 'code' in error && error.code === code;
4
+ }
@@ -2,7 +2,9 @@ import { spawnSync } from 'node:child_process';
2
2
  import { createHash } from 'node:crypto';
3
3
  import { existsSync, lstatSync, readFileSync, readlinkSync } from 'node:fs';
4
4
  import path from 'node:path';
5
+ import { describeError } from '@williamthorsen/toolbelt.errors';
5
6
  import { GIT_OUTPUT_LIMIT } from "./gitOutputLimit.js";
7
+ import { hasErrnoCode } from "./hasErrnoCode.js";
6
8
  const HASH_FORMAT = 'nmr-working-tree-v1';
7
9
  const PRECEDING_FIELD_COUNTS = {
8
10
  1: 8,
@@ -101,9 +103,6 @@ function collectChangedPaths(statusOutput) {
101
103
  }
102
104
  return { ok: true, paths };
103
105
  }
104
- function describeError(error) {
105
- return error instanceof Error ? error.message : String(error);
106
- }
107
106
  function digestBuffer(buffer) {
108
107
  return createHash('sha256').update(buffer).digest('hex');
109
108
  }
@@ -114,7 +113,7 @@ function digestPathContent(toplevel, relativePath) {
114
113
  stats = lstatSync(absolutePath);
115
114
  }
116
115
  catch (error) {
117
- if (isErrorWithCode(error, 'ENOENT')) {
116
+ if (hasErrnoCode(error, 'ENOENT')) {
118
117
  return { ok: true, kind: 'absent', digest: '' };
119
118
  }
120
119
  return { ok: false, reason: `could not stat ${relativePath}: ${describeError(error)}` };
@@ -147,9 +146,6 @@ function extractPath(record, precedingFieldCount) {
147
146
  const extracted = record.slice(index);
148
147
  return extracted === '' ? undefined : extracted;
149
148
  }
150
- function isErrorWithCode(error, code) {
151
- return error instanceof Error && 'code' in error && error.code === code;
152
- }
153
149
  function runGit(args, cwd) {
154
150
  const result = spawnSync('git', args, { cwd, encoding: 'utf8', maxBuffer: GIT_OUTPUT_LIMIT });
155
151
  if (result.error) {
@@ -1,8 +1,9 @@
1
1
  export declare const PACKAGE_NAME = "@williamthorsen/nmr-core";
2
2
  export type { CacheDirRef, CacheEntryRef } from './cache-store.js';
3
- export { readCacheEntry, readJsonCacheEntry, removeCacheDir, resolveCacheDir, resolveCacheEntryPath, writeCacheEntry, } from './cache-store.js';
3
+ export { readCacheEntry, readJsonCacheEntry, removeCacheDir, removeCacheEntry, resolveCacheDir, resolveCacheEntryPath, writeCacheEntry, } from './cache-store.js';
4
4
  export { findPackageRoot } from './findPackageRoot.js';
5
5
  export { GIT_OUTPUT_LIMIT } from './gitOutputLimit.js';
6
+ export { hasErrnoCode } from './hasErrnoCode.js';
6
7
  export type { WorkingTreeHashResult } from './hashWorkingTree.js';
7
8
  export { hashWorkingTree, readHeadSha } from './hashWorkingTree.js';
8
9
  export type { FlagDefinition, FlagSchema, ParseArgsOptions, ParsedArgs, ParsedFlags, ParseErrorKind, } from './parseArgs.js';
package/dist/esm/index.js CHANGED
@@ -1,7 +1,8 @@
1
1
  export const PACKAGE_NAME = '@williamthorsen/nmr-core';
2
- export { readCacheEntry, readJsonCacheEntry, removeCacheDir, resolveCacheDir, resolveCacheEntryPath, writeCacheEntry, } from "./cache-store.js";
2
+ export { readCacheEntry, readJsonCacheEntry, removeCacheDir, removeCacheEntry, resolveCacheDir, resolveCacheEntryPath, writeCacheEntry, } from "./cache-store.js";
3
3
  export { findPackageRoot } from "./findPackageRoot.js";
4
4
  export { GIT_OUTPUT_LIMIT } from "./gitOutputLimit.js";
5
+ export { hasErrnoCode } from "./hasErrnoCode.js";
5
6
  export { hashWorkingTree, readHeadSha } from "./hashWorkingTree.js";
6
7
  export { parseArgs, parseArgsOrExit, ParseError } from "./parseArgs.js";
7
8
  export { readPackageVersion } from "./readPackageVersion.js";
@@ -1,5 +1,6 @@
1
1
  import { existsSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs';
2
2
  import { dirname } from 'node:path';
3
+ import { describeError } from '@williamthorsen/toolbelt.errors';
3
4
  function normalizeTrailingWhitespace(content) {
4
5
  return content
5
6
  .split('\n')
@@ -18,7 +19,7 @@ export function writeFileWithCheck(filePath, content, options) {
18
19
  }
19
20
  }
20
21
  catch (error) {
21
- const message = error instanceof Error ? error.message : String(error);
22
+ const message = describeError(error);
22
23
  return { filePath, outcome: 'skipped', error: message };
23
24
  }
24
25
  return { filePath, outcome: 'skipped' };
@@ -31,14 +32,14 @@ export function writeFileWithCheck(filePath, content, options) {
31
32
  mkdirSync(dirname(filePath), { recursive: true });
32
33
  }
33
34
  catch (error) {
34
- const message = error instanceof Error ? error.message : String(error);
35
+ const message = describeError(error);
35
36
  return { filePath, outcome: 'failed', error: message };
36
37
  }
37
38
  try {
38
39
  writeFileSync(filePath, content, 'utf8');
39
40
  }
40
41
  catch (error) {
41
- const message = error instanceof Error ? error.message : String(error);
42
+ const message = describeError(error);
42
43
  return { filePath, outcome: 'failed', error: message };
43
44
  }
44
45
  return { filePath, outcome };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@williamthorsen/nmr-core",
3
- "version": "0.9.3",
3
+ "version": "0.10.1",
4
4
  "private": false,
5
5
  "description": "Shared utilities for node-monorepo-tools packages",
6
6
  "keywords": [
@@ -19,6 +19,7 @@
19
19
  },
20
20
  "license": "ISC",
21
21
  "author": "William Thorsen <william@thorsen.dev> (https://github.com/williamthorsen)",
22
+ "sideEffects": false,
22
23
  "type": "module",
23
24
  "exports": {
24
25
  ".": {
@@ -30,6 +31,13 @@
30
31
  "files": [
31
32
  "dist"
32
33
  ],
34
+ "dependencies": {
35
+ "@williamthorsen/toolbelt.errors": "0.5.0"
36
+ },
37
+ "devDependencies": {
38
+ "@williamthorsen/toolbelt.testing": "0.3.0",
39
+ "@williamthorsen/toolbelt.vitest": "0.4.0"
40
+ },
33
41
  "engines": {
34
42
  "node": ">=24"
35
43
  },