@williamthorsen/nmr-core 0.13.1 → 0.13.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.
- package/.meta/changelog.json +44 -0
- package/CHANGELOG.md +15 -0
- package/dist/esm/cache-store.d.ts +10 -6
- package/dist/esm/cache-store.js +7 -30
- package/dist/esm/workspace.js +2 -11
- package/package.json +6 -6
package/.meta/changelog.json
CHANGED
|
@@ -1,4 +1,48 @@
|
|
|
1
1
|
[
|
|
2
|
+
{
|
|
3
|
+
"version": "0.13.2",
|
|
4
|
+
"date": "2026-10-08",
|
|
5
|
+
"sections": [
|
|
6
|
+
{
|
|
7
|
+
"title": "🏗️ Internal features",
|
|
8
|
+
"audience": "dev",
|
|
9
|
+
"items": [
|
|
10
|
+
{
|
|
11
|
+
"description": "Adds an optional `stopAtDir` to `CacheDirRef`, which limits the upward search by `resolveCacheDir` for a `node_modules` to that directory, inclusive, and makes resolution throw when it is not the scope directory or one of its ancestors. (#969)",
|
|
12
|
+
"hash": "39d2c16c19382e68080c05b2ca4db191aa5dac89",
|
|
13
|
+
"entry": 1
|
|
14
|
+
}
|
|
15
|
+
]
|
|
16
|
+
},
|
|
17
|
+
{
|
|
18
|
+
"title": "♻️ Refactoring",
|
|
19
|
+
"audience": "dev",
|
|
20
|
+
"items": [
|
|
21
|
+
{
|
|
22
|
+
"description": "Replaces the hand-written atomic cache write and directory walks in `nmr-core` and `nmr` with `writeAtomic` and `findDirectoryChainMatch` from `@williamthorsen/toolbelt.filesystem`, which both packages now declare in `dependencies`. (#966)",
|
|
23
|
+
"hash": "0177be3ace33150a7ac67725dd539fb0ee63b833",
|
|
24
|
+
"entry": 1
|
|
25
|
+
}
|
|
26
|
+
]
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
"title": "🧪 Tests",
|
|
30
|
+
"audience": "dev",
|
|
31
|
+
"items": [
|
|
32
|
+
{
|
|
33
|
+
"description": "Replaces the hand-rolled `try`/`catch` in nmr-core's `expectParseError` test helper with `captureError`, which fails the test when parsing does not throw. (#964)",
|
|
34
|
+
"hash": "38cc179b4116bcd5aba8371b17b0816150c9e9a3",
|
|
35
|
+
"entry": 5
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
"description": "Stops the tests in `cache-store.unit.test.ts` from writing and removing cache entries in an ancestor's `node_modules` outside their temp trees, which also made the fallback test fail, and adds a test that a scope below `stopAtDir` does not hoist past it. (#969)",
|
|
39
|
+
"hash": "39d2c16c19382e68080c05b2ca4db191aa5dac89",
|
|
40
|
+
"entry": 2
|
|
41
|
+
}
|
|
42
|
+
]
|
|
43
|
+
}
|
|
44
|
+
]
|
|
45
|
+
},
|
|
2
46
|
{
|
|
3
47
|
"version": "0.13.1",
|
|
4
48
|
"date": "2026-10-01",
|
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,21 @@
|
|
|
2
2
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
|
|
5
|
+
## 0.13.2 — 2026-10-08
|
|
6
|
+
|
|
7
|
+
### 🏗️ Internal features
|
|
8
|
+
|
|
9
|
+
- Adds an optional `stopAtDir` to `CacheDirRef`, which limits the upward search by `resolveCacheDir` for a `node_modules` to that directory, inclusive, and makes resolution throw when it is not the scope directory or one of its ancestors. (#969)
|
|
10
|
+
|
|
11
|
+
### ♻️ Refactoring
|
|
12
|
+
|
|
13
|
+
- Replaces the hand-written atomic cache write and directory walks in `nmr-core` and `nmr` with `writeAtomic` and `findDirectoryChainMatch` from `@williamthorsen/toolbelt.filesystem`, which both packages now declare in `dependencies`. (#966)
|
|
14
|
+
|
|
15
|
+
### 🧪 Tests
|
|
16
|
+
|
|
17
|
+
- Replaces the hand-rolled `try`/`catch` in nmr-core's `expectParseError` test helper with `captureError`, which fails the test when parsing does not throw. (#964)
|
|
18
|
+
- Stops the tests in `cache-store.unit.test.ts` from writing and removing cache entries in an ancestor's `node_modules` outside their temp trees, which also made the fallback test fail, and adds a test that a scope below `stopAtDir` does not hoist past it. (#969)
|
|
19
|
+
|
|
5
20
|
## 0.13.1 — 2026-10-01
|
|
6
21
|
|
|
7
22
|
### ♻️ Refactoring
|
|
@@ -4,6 +4,11 @@ export interface CacheDirRef {
|
|
|
4
4
|
tool: string;
|
|
5
5
|
/** The directory that the cache serves; its nearest `node_modules` ancestor contains the cache. */
|
|
6
6
|
scopeDir: string;
|
|
7
|
+
/**
|
|
8
|
+
* Bounds the search for a `node_modules` ancestor, inclusive. Must be the scope directory or one of its ancestors;
|
|
9
|
+
* resolution throws otherwise.
|
|
10
|
+
*/
|
|
11
|
+
stopAtDir?: string;
|
|
7
12
|
}
|
|
8
13
|
/** Locates a single entry within a tool's cache directory. */
|
|
9
14
|
export interface CacheEntryRef extends CacheDirRef {
|
|
@@ -36,8 +41,8 @@ export declare function removeCacheEntry(entryPath: string): Promise<void>;
|
|
|
36
41
|
* Resolves the absolute path of a tool's cache directory. The conventional `node_modules/.cache/{tool}/` home is
|
|
37
42
|
* git-ignored and outside any `files` convention, so an entry is never included in a published tarball. The home
|
|
38
43
|
* is the nearest enclosing directory that already has a `node_modules`: the scope's own when it has one, otherwise
|
|
39
|
-
* a hoisted ancestor, such as the workspace root for a zero-dependency package. The
|
|
40
|
-
* `node_modules` solely to store the cache.
|
|
44
|
+
* a hoisted ancestor, such as the workspace root for a zero-dependency package. The search does not go above
|
|
45
|
+
* `stopAtDir` when one is given. The function never materializes a `node_modules` solely to store the cache.
|
|
41
46
|
*/
|
|
42
47
|
export declare function resolveCacheDir(ref: CacheDirRef): string;
|
|
43
48
|
/**
|
|
@@ -47,9 +52,8 @@ export declare function resolveCacheDir(ref: CacheDirRef): string;
|
|
|
47
52
|
*/
|
|
48
53
|
export declare function resolveCacheEntryPath(ref: CacheEntryRef): string;
|
|
49
54
|
/**
|
|
50
|
-
* Writes an entry, creating the cache directory as needed
|
|
51
|
-
*
|
|
52
|
-
*
|
|
53
|
-
* not worth failing over catches it.
|
|
55
|
+
* Writes an entry atomically, creating the cache directory as needed, so that a concurrent reader sees either the
|
|
56
|
+
* previous entry or the new one and never a half-written file. Throws when the write cannot be completed; a caller
|
|
57
|
+
* for whom a failed cache write is not worth failing over catches it.
|
|
54
58
|
*/
|
|
55
59
|
export declare function writeCacheEntry(entryPath: string, content: string): Promise<void>;
|
package/dist/esm/cache-store.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import { createHash
|
|
2
|
-
import {
|
|
3
|
-
import { mkdir, readFile, rename, rm, unlink, writeFile } from 'node:fs/promises';
|
|
1
|
+
import { createHash } from 'node:crypto';
|
|
2
|
+
import { readFile, rm } from 'node:fs/promises';
|
|
4
3
|
import path from 'node:path';
|
|
4
|
+
import { findDirectoryChainMatch } from '@williamthorsen/toolbelt.filesystem';
|
|
5
|
+
import { writeAtomic } from '@williamthorsen/toolbelt.filesystem/candidate';
|
|
5
6
|
const DIGEST_LENGTH = 8;
|
|
6
7
|
export async function readCacheEntry(entryPath) {
|
|
7
8
|
try {
|
|
@@ -33,7 +34,8 @@ export async function removeCacheEntry(entryPath) {
|
|
|
33
34
|
}
|
|
34
35
|
export function resolveCacheDir(ref) {
|
|
35
36
|
const absoluteScopeDir = path.resolve(ref.scopeDir);
|
|
36
|
-
const
|
|
37
|
+
const stopAtDir = ref.stopAtDir === undefined ? undefined : path.resolve(ref.stopAtDir);
|
|
38
|
+
const home = findDirectoryChainMatch(absoluteScopeDir, ['node_modules'], { stopAtDir })?.dir ?? absoluteScopeDir;
|
|
37
39
|
return path.join(home, 'node_modules', '.cache', ref.tool);
|
|
38
40
|
}
|
|
39
41
|
export function resolveCacheEntryPath(ref) {
|
|
@@ -45,30 +47,5 @@ export function resolveCacheEntryPath(ref) {
|
|
|
45
47
|
return path.join(resolveCacheDir(ref), `${ref.slug}-${digest}${ref.extension}`);
|
|
46
48
|
}
|
|
47
49
|
export async function writeCacheEntry(entryPath, content) {
|
|
48
|
-
await
|
|
49
|
-
const temporaryPath = `${entryPath}.${randomUUID()}.tmp`;
|
|
50
|
-
try {
|
|
51
|
-
await writeFile(temporaryPath, content);
|
|
52
|
-
await rename(temporaryPath, entryPath);
|
|
53
|
-
}
|
|
54
|
-
catch (error) {
|
|
55
|
-
try {
|
|
56
|
-
await unlink(temporaryPath);
|
|
57
|
-
}
|
|
58
|
-
catch {
|
|
59
|
-
}
|
|
60
|
-
throw error;
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
function findNearestNodeModulesHost(startDir) {
|
|
64
|
-
let current = startDir;
|
|
65
|
-
let parent = path.dirname(current);
|
|
66
|
-
while (!existsSync(path.join(current, 'node_modules'))) {
|
|
67
|
-
if (parent === current) {
|
|
68
|
-
return undefined;
|
|
69
|
-
}
|
|
70
|
-
current = parent;
|
|
71
|
-
parent = path.dirname(current);
|
|
72
|
-
}
|
|
73
|
-
return current;
|
|
50
|
+
await writeAtomic(entryPath, content);
|
|
74
51
|
}
|
package/dist/esm/workspace.js
CHANGED
|
@@ -1,21 +1,12 @@
|
|
|
1
1
|
import { existsSync, readFileSync } from 'node:fs';
|
|
2
2
|
import path from 'node:path';
|
|
3
|
+
import { findDirectoryChainMatch } from '@williamthorsen/toolbelt.filesystem';
|
|
3
4
|
import { parse } from 'yaml';
|
|
4
5
|
import { matchPackageDirs, resolvePackageDirs, splitWorkspacePatterns } from "./helpers/workspace-patterns.js";
|
|
5
6
|
const PACKAGE_MANIFEST = 'package.json';
|
|
6
7
|
const WORKSPACE_MANIFEST = 'pnpm-workspace.yaml';
|
|
7
8
|
export function findMonorepoRoot(startDir) {
|
|
8
|
-
|
|
9
|
-
for (;;) {
|
|
10
|
-
if (isMonorepoRoot(dir)) {
|
|
11
|
-
return dir;
|
|
12
|
-
}
|
|
13
|
-
const parent = path.dirname(dir);
|
|
14
|
-
if (parent === dir) {
|
|
15
|
-
return undefined;
|
|
16
|
-
}
|
|
17
|
-
dir = parent;
|
|
18
|
-
}
|
|
9
|
+
return findDirectoryChainMatch(startDir ?? process.cwd(), [WORKSPACE_MANIFEST])?.dir;
|
|
19
10
|
}
|
|
20
11
|
export function isMonorepoRoot(dir) {
|
|
21
12
|
return existsSync(path.join(dir, WORKSPACE_MANIFEST));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@williamthorsen/nmr-core",
|
|
3
|
-
"version": "0.13.
|
|
3
|
+
"version": "0.13.2",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "Shared utilities for node-monorepo-tools packages",
|
|
6
6
|
"keywords": [
|
|
@@ -39,15 +39,15 @@
|
|
|
39
39
|
"dist"
|
|
40
40
|
],
|
|
41
41
|
"dependencies": {
|
|
42
|
-
"@williamthorsen/toolbelt.errors": "0.8.
|
|
43
|
-
"@williamthorsen/toolbelt.
|
|
42
|
+
"@williamthorsen/toolbelt.errors": "0.8.2",
|
|
43
|
+
"@williamthorsen/toolbelt.filesystem": "0.9.2",
|
|
44
|
+
"@williamthorsen/toolbelt.terminal": "0.2.1",
|
|
44
45
|
"diff": "9.0.0",
|
|
45
46
|
"yaml": "2.9.1"
|
|
46
47
|
},
|
|
47
48
|
"devDependencies": {
|
|
48
|
-
"@williamthorsen/toolbelt.
|
|
49
|
-
"@williamthorsen/toolbelt.
|
|
50
|
-
"@williamthorsen/toolbelt.vitest": "0.10.1",
|
|
49
|
+
"@williamthorsen/toolbelt.testing": "0.6.2",
|
|
50
|
+
"@williamthorsen/toolbelt.vitest": "0.10.2",
|
|
51
51
|
"vitest": "4.1.11"
|
|
52
52
|
},
|
|
53
53
|
"engines": {
|