@better-fs-tools/node 0.1.0 → 0.2.0
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 +31 -26
- package/dist/create-node-fs-tools.d.ts +21 -6
- package/dist/create-node-fs-tools.js +3 -1
- package/dist/create-node-write-tools.d.ts +1 -1
- package/dist/create-node-write-tools.js +1 -1
- package/dist/filesystem.js +2 -2
- package/dist/index.d.ts +1 -1
- package/dist/policy.d.ts +5 -1
- package/dist/policy.js +1 -1
- package/dist/write.js +4 -5
- package/package.json +5 -5
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# @better-fs-tools/node
|
|
2
2
|
|
|
3
|
-
The Node filesystem for Better FS Tools, a SHA-256 digest, `createNodeReadTool()`, the zero-config local read tool, and `createNodeFsTools()`, which adds `edit
|
|
3
|
+
The Node filesystem for Better FS Tools, a SHA-256 digest, `createNodeReadTool()`, the zero-config local read tool, and `createNodeFsTools()`, which adds `edit` and `write` over the same filesystem, and a read store, `apply_patch`, and `bash` when you ask for them. It works on Node 24 or later, and on Bun.
|
|
4
4
|
|
|
5
5
|
## Install
|
|
6
6
|
|
|
@@ -31,16 +31,18 @@ export const docsOnly = createNodeReadTool({
|
|
|
31
31
|
});
|
|
32
32
|
```
|
|
33
33
|
|
|
34
|
-
All four tools, with one read store, so `edit` and `write` need a read first:
|
|
34
|
+
All four tools, with one read store, so `edit` and `write` need a read first. The store and `apply_patch` are opt-in:
|
|
35
35
|
|
|
36
36
|
```ts
|
|
37
37
|
import { createNodeFsTools } from "@better-fs-tools/node";
|
|
38
|
-
import { textOf } from "@better-fs-tools/read";
|
|
38
|
+
import { memoryStore, textOf } from "@better-fs-tools/read";
|
|
39
39
|
import { protectPaths } from "@better-fs-tools/write";
|
|
40
40
|
|
|
41
41
|
// read, edit, write, and apply_patch over one nodeFileSystem rooted at
|
|
42
42
|
// process.cwd(), with one read store, one SHA-256 digest, and one lock manager.
|
|
43
|
+
// The read store and apply_patch are opt-in.
|
|
43
44
|
const tools = createNodeFsTools({
|
|
45
|
+
state: memoryStore(),
|
|
44
46
|
edit: { authorize: protectPaths() },
|
|
45
47
|
write: { authorize: protectPaths() },
|
|
46
48
|
applyPatch: { authorize: protectPaths() },
|
|
@@ -62,29 +64,29 @@ export async function afterShell(path: string): Promise<boolean> {
|
|
|
62
64
|
|
|
63
65
|
## Contents
|
|
64
66
|
|
|
65
|
-
| Export | Use
|
|
66
|
-
| -------------------------------------------------------------------------------------------- |
|
|
67
|
-
| `createNodeReadTool(options?)` | `createReadTool()` from `@better-fs-tools/read` with Node defaults. `fs` defaults to `nodeFileSystem` rooted at `process.cwd()`. `digest` defaults to `nodeDigest()`. Pass `digest: null` to turn observations off. Every other option goes to the core.
|
|
68
|
-
| `createNodeFsTools(options?)` | `createFsTools()` from `@better-fs-tools/write` over one `nodeFileSystem`, with `nodeDigest()`: `read`, `edit`,
|
|
69
|
-
| `createNodeEditTool(deps?)`, `createNodeWriteTool(deps?)`, `createNodeApplyPatchTool(deps?)` | One write tool each. `fs` defaults to `nodeFileSystem` rooted at `process.cwd()`, `digest` to `nodeDigest()`. `state` stays `null`, so
|
|
70
|
-
| `createNodeBashTool(deps?)` | The local `bash` tool. See [Bash tool](#bash-tool)
|
|
71
|
-
| `nodeCommandRunner(options?)` | The command runner that `createNodeBashTool()` uses: `bash -c` in its own process group. POSIX only
|
|
72
|
-
| `nodeFileSystem(options)` | A `WritableFileSystem` over Node file descriptors
|
|
73
|
-
| `nodeDigest()` | SHA-256 over `node:crypto`. Values look like `sha256:<hex>`, the same as `sha256Digest()` from `@better-fs-tools/read`.
|
|
67
|
+
| Export | Use |
|
|
68
|
+
| -------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
69
|
+
| `createNodeReadTool(options?)` | `createReadTool()` from `@better-fs-tools/read` with Node defaults. `fs` defaults to `nodeFileSystem` rooted at `process.cwd()`. `digest` defaults to `nodeDigest()`. Pass `digest: null` to turn observations off. Every other option goes to the core. |
|
|
70
|
+
| `createNodeFsTools(options?)` | `createFsTools()` from `@better-fs-tools/write` over one `nodeFileSystem`, with `nodeDigest()`: `read`, `edit`, and `write` share one digest, one `memoryLocks()`, and one clock. Options: `cwd`, `allowedRoots` (default `[cwd]`), `denyRoots`, `symlinks`, `hardLinks`, `newFileMode`, `newDirectoryMode`, `state` (default `null`, so read-before-write is off; `memoryStore()` turns it on), `digest`, `locks`, `clock`, per-tool options under `read`, `edit`, and `write`, `applyPatch`, and `bash`. `apply_patch` is off unless `applyPatch` is `true` or an options object. Bash is off unless `bash` is `true` or an options object. The result also has `applyPatch` and `bash` (`null` when off), `fs`, `state`, `digest`, `locks`, `clock`, and `invalidate(path, call?)`, which returns an `InvalidateOutcome`. The Node filesystem is fixed, so `call` is not needed. An unknown option key, or `fs`, `state`, `digest`, `locks`, or `clock` inside a per-tool object (`digest` or `clock` inside `bash`), throws `TypeError` |
|
|
71
|
+
| `createNodeEditTool(deps?)`, `createNodeWriteTool(deps?)`, `createNodeApplyPatchTool(deps?)` | One write tool each. `fs` defaults to `nodeFileSystem` rooted at `process.cwd()`, `digest` to `nodeDigest()`. `state` stays `null`, so read-before-write is off |
|
|
72
|
+
| `createNodeBashTool(deps?)` | The local `bash` tool. See [Bash tool](#bash-tool) |
|
|
73
|
+
| `nodeCommandRunner(options?)` | The command runner that `createNodeBashTool()` uses: `bash -c` in its own process group. POSIX only |
|
|
74
|
+
| `nodeFileSystem(options)` | A `WritableFileSystem` over Node file descriptors |
|
|
75
|
+
| `nodeDigest()` | SHA-256 over `node:crypto`. Values look like `sha256:<hex>`, the same as `sha256Digest()` from `@better-fs-tools/read`. |
|
|
74
76
|
|
|
75
77
|
`nodeFileSystem` options. The first six are the shared `FileSystemRootOptions` from `@better-fs-tools/fs`. The filesystem also exposes the resolved `cwd`, `allowedRoots`, `denyRoots`, `symlinks`, and `identity`:
|
|
76
78
|
|
|
77
|
-
| Option | Default | Meaning
|
|
78
|
-
| ------------------ | ----------------------- |
|
|
79
|
-
| `allowedRoots` | required | At least one root. A path outside every root gives `OUTSIDE_ALLOWED_ROOTS`.
|
|
80
|
-
| `cwd` | `process.cwd()` | Base for relative paths. A relative `cwd` resolves against `process.cwd()`
|
|
81
|
-
| `denyRoots` | none | Refused as `DANGEROUS_PATH`, in addition to `/dev`, `/proc`, and `/sys`
|
|
82
|
-
| `symlinks` | `"follow-within-roots"` | `"reject"` refuses every symlink
|
|
83
|
-
| `identity` | `"required"` | The only value: Node always reports device and inode
|
|
84
|
-
| `id` | `"node"` | Appears in `result.file.backend`
|
|
85
|
-
| `hardLinks` | `"
|
|
86
|
-
| `newFileMode` | `0o666` less the umask | Mode of a new file. A mode you set is exact: the umask does not apply to it
|
|
87
|
-
| `newDirectoryMode` | `0o777` less the umask | Mode of a directory that `createParents` makes. A mode you set is exact
|
|
79
|
+
| Option | Default | Meaning |
|
|
80
|
+
| ------------------ | ----------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
81
|
+
| `allowedRoots` | required | At least one root. A path outside every root gives `OUTSIDE_ALLOWED_ROOTS`. |
|
|
82
|
+
| `cwd` | `process.cwd()` | Base for relative paths. A relative `cwd` resolves against `process.cwd()` |
|
|
83
|
+
| `denyRoots` | none | Refused as `DANGEROUS_PATH`, in addition to `/dev`, `/proc`, and `/sys` |
|
|
84
|
+
| `symlinks` | `"follow-within-roots"` | `"reject"` refuses every symlink |
|
|
85
|
+
| `identity` | `"required"` | The only value: Node always reports device and inode |
|
|
86
|
+
| `id` | `"node"` | Appears in `result.file.backend` |
|
|
87
|
+
| `hardLinks` | `"in-place"` | A replace of a file with more than one hard link. `"in-place"` writes through the link, not atomically. `"refuse"` fails with reason `denied`. A file with one link is always replaced by temp file and rename |
|
|
88
|
+
| `newFileMode` | `0o666` less the umask | Mode of a new file. A mode you set is exact: the umask does not apply to it |
|
|
89
|
+
| `newDirectoryMode` | `0o777` less the umask | Mode of a directory that `createParents` makes. A mode you set is exact |
|
|
88
90
|
|
|
89
91
|
## How it opens a file
|
|
90
92
|
|
|
@@ -96,7 +98,7 @@ export async function afterShell(path: string): Promise<boolean> {
|
|
|
96
98
|
|
|
97
99
|
A write goes to a `0o600` temp file next to the target. The bytes are written and synced, and the file gets the old mode or the new-file mode. Publishing takes an in-process lock for the real path and checks the precondition against a fresh `lstat`. A create is published with `link()`, so a concurrent creator makes it fail with `exists`. A replace is published with `rename()`. Any failure removes the temp file and the directories the write created. The version token is the read identity: device, inode, size, and both change times. `EROFS` gives `read-only`, and `ENOSPC` and `EDQUOT` give `no-space`.
|
|
98
100
|
|
|
99
|
-
`writeCapabilities` is `{
|
|
101
|
+
`writeCapabilities` is `{ compareAndSwap: true }`. A replace is atomic and keeps the mode, and `stage()` and `remove()` exist. Some of this holds with limits:
|
|
100
102
|
|
|
101
103
|
- `compareAndSwap` holds inside one process only. The lock orders writes inside one process. Another process can still change the file between the final check and the rename, and that change is then lost.
|
|
102
104
|
- A replace keeps the permission bits only. The owner, the group, extended attributes, and ACLs are not kept, because `rename()` publishes a new file owned by the writing user.
|
|
@@ -110,12 +112,15 @@ A write goes to a `0o600` temp file next to the target. The bytes are written an
|
|
|
110
112
|
```ts
|
|
111
113
|
import { createNodeFsTools, nodeCommandRunner } from "@better-fs-tools/node";
|
|
112
114
|
import type { NodeFsToolsWithBash } from "@better-fs-tools/node";
|
|
115
|
+
import { memoryStore } from "@better-fs-tools/read";
|
|
113
116
|
|
|
114
|
-
// bash is created only because `bash` is set.
|
|
115
|
-
// package.json need a read first, since a command may have
|
|
117
|
+
// bash is created only because `bash` is set. With a read store, the hook makes
|
|
118
|
+
// the next edit of package.json need a read first, since a command may have
|
|
119
|
+
// changed it.
|
|
116
120
|
let tools: NodeFsToolsWithBash | undefined;
|
|
117
121
|
tools = createNodeFsTools({
|
|
118
122
|
cwd: "/srv/project",
|
|
123
|
+
state: memoryStore(),
|
|
119
124
|
bash: {
|
|
120
125
|
runner: nodeCommandRunner({ cwd: "/srv/project", shell: "/bin/bash" }),
|
|
121
126
|
afterRun: [
|
|
@@ -15,12 +15,13 @@ export interface CreateNodeFsToolsOptions<THost = undefined> {
|
|
|
15
15
|
readonly allowedRoots?: readonly string[];
|
|
16
16
|
readonly denyRoots?: readonly string[];
|
|
17
17
|
readonly symlinks?: SymlinkPolicy;
|
|
18
|
+
/** Default "in-place". "refuse" fails a replace of a file with more than one hard link. */
|
|
18
19
|
readonly hardLinks?: "refuse" | "in-place";
|
|
19
20
|
/** Mode of a new file, exactly. Default 0o666 less the process umask. */
|
|
20
21
|
readonly newFileMode?: number;
|
|
21
22
|
/** Mode of a directory that createParents makes, exactly. Default 0o777 less the umask. */
|
|
22
23
|
readonly newDirectoryMode?: number;
|
|
23
|
-
/** Default
|
|
24
|
+
/** Default null: no read-before-write. A store, for example memoryStore(), turns it on. */
|
|
24
25
|
readonly state?: ReadStateStore | null;
|
|
25
26
|
/** Default nodeDigest(). */
|
|
26
27
|
readonly digest?: Digest;
|
|
@@ -31,7 +32,8 @@ export interface CreateNodeFsToolsOptions<THost = undefined> {
|
|
|
31
32
|
readonly read?: Omit<Partial<ReadToolDeps<THost>>, FsToolsSharedKey>;
|
|
32
33
|
readonly edit?: Omit<Partial<EditToolDeps<THost>>, FsToolsSharedKey>;
|
|
33
34
|
readonly write?: Omit<Partial<WriteToolDeps<THost>>, FsToolsSharedKey>;
|
|
34
|
-
|
|
35
|
+
/** `true` or an options object adds an apply_patch tool. Off by default. */
|
|
36
|
+
readonly applyPatch?: boolean | Omit<Partial<ApplyPatchToolDeps<THost>>, FsToolsSharedKey>;
|
|
35
37
|
/**
|
|
36
38
|
* `true` or an options object adds a bash tool. Off by default. The runner
|
|
37
39
|
* defaults to nodeCommandRunner({ cwd }), and env to
|
|
@@ -44,7 +46,8 @@ export interface NodeFsTools<THost = undefined> {
|
|
|
44
46
|
readonly read: ReadTool<THost>;
|
|
45
47
|
readonly edit: EditTool<THost>;
|
|
46
48
|
readonly write: WriteTool<THost>;
|
|
47
|
-
|
|
49
|
+
/** null unless options.applyPatch is true or an object. */
|
|
50
|
+
readonly applyPatch: ApplyPatchTool<THost> | null;
|
|
48
51
|
/** null unless options.bash is set. Runs in cwd. It does not share the read state: see invalidate. */
|
|
49
52
|
readonly bash: BashTool<THost> | null;
|
|
50
53
|
readonly fs: NodeFileSystem;
|
|
@@ -62,14 +65,26 @@ export interface NodeFsTools<THost = undefined> {
|
|
|
62
65
|
export interface NodeFsToolsWithBash<THost = undefined> extends NodeFsTools<THost> {
|
|
63
66
|
readonly bash: BashTool<THost>;
|
|
64
67
|
}
|
|
68
|
+
/** The result when options.applyPatch is true or an object: applyPatch is there. */
|
|
69
|
+
export interface NodeFsToolsWithApplyPatch<THost = undefined> extends NodeFsTools<THost> {
|
|
70
|
+
readonly applyPatch: ApplyPatchTool<THost>;
|
|
71
|
+
}
|
|
65
72
|
/**
|
|
66
|
-
* Creates read, edit,
|
|
67
|
-
*
|
|
68
|
-
* `
|
|
73
|
+
* Creates read, edit, and write tools over one local filesystem. They share
|
|
74
|
+
* one digest, lock manager, and clock, and the read store when `state` is
|
|
75
|
+
* given. With `applyPatch`, adds an apply_patch tool. With `bash`, adds a bash
|
|
76
|
+
* tool in the same cwd. The allowed roots do not limit
|
|
69
77
|
* what a bash command touches. To make the next edit after a command need a
|
|
70
78
|
* read, call invalidate(path) from a bash afterRun hook.
|
|
71
79
|
*/
|
|
80
|
+
export declare function createNodeFsTools<THost = undefined>(options: CreateNodeFsToolsOptions<THost> & {
|
|
81
|
+
readonly bash: true | NodeFsToolsBashOptions<THost>;
|
|
82
|
+
readonly applyPatch: true | Omit<Partial<ApplyPatchToolDeps<THost>>, FsToolsSharedKey>;
|
|
83
|
+
}): NodeFsToolsWithBash<THost> & NodeFsToolsWithApplyPatch<THost>;
|
|
72
84
|
export declare function createNodeFsTools<THost = undefined>(options: CreateNodeFsToolsOptions<THost> & {
|
|
73
85
|
readonly bash: true | NodeFsToolsBashOptions<THost>;
|
|
74
86
|
}): NodeFsToolsWithBash<THost>;
|
|
87
|
+
export declare function createNodeFsTools<THost = undefined>(options: CreateNodeFsToolsOptions<THost> & {
|
|
88
|
+
readonly applyPatch: true | Omit<Partial<ApplyPatchToolDeps<THost>>, FsToolsSharedKey>;
|
|
89
|
+
}): NodeFsToolsWithApplyPatch<THost>;
|
|
75
90
|
export declare function createNodeFsTools<THost = undefined>(options?: CreateNodeFsToolsOptions<THost>): NodeFsTools<THost>;
|
|
@@ -77,7 +77,9 @@ function checkOptions(options) {
|
|
|
77
77
|
}
|
|
78
78
|
for (const [tool, keys] of Object.entries(BUNDLE_SHARED_KEYS_BY_TOOL)) {
|
|
79
79
|
const part = options[tool];
|
|
80
|
-
if (part === undefined
|
|
80
|
+
if (part === undefined)
|
|
81
|
+
continue;
|
|
82
|
+
if ((tool === "bash" || tool === "applyPatch") && typeof part === "boolean")
|
|
81
83
|
continue;
|
|
82
84
|
if (part === null || typeof part !== "object" || Array.isArray(part)) {
|
|
83
85
|
throw new TypeError(`createNodeFsTools ${tool} options must be an object`);
|
|
@@ -10,7 +10,7 @@ export type CreateNodeApplyPatchToolOptions<THost = undefined> = Partial<ApplyPa
|
|
|
10
10
|
* Creates an edit tool for local files. `fs` defaults to nodeFileSystem rooted
|
|
11
11
|
* at process.cwd(). `digest` defaults to nodeDigest(); pass `digest: null` to
|
|
12
12
|
* turn it off. Read-before-write is off unless you pass a `state`; use
|
|
13
|
-
* createNodeFsTools() for a store shared with read.
|
|
13
|
+
* createNodeFsTools({ state }) for a store shared with read.
|
|
14
14
|
*/
|
|
15
15
|
export declare function createNodeEditTool<THost = undefined>(deps?: CreateNodeEditToolOptions<THost>): EditTool<THost>;
|
|
16
16
|
/** Creates a write tool for local files, with the same defaults as createNodeEditTool. */
|
|
@@ -5,7 +5,7 @@ import { nodeFileSystem } from "./filesystem.js";
|
|
|
5
5
|
* Creates an edit tool for local files. `fs` defaults to nodeFileSystem rooted
|
|
6
6
|
* at process.cwd(). `digest` defaults to nodeDigest(); pass `digest: null` to
|
|
7
7
|
* turn it off. Read-before-write is off unless you pass a `state`; use
|
|
8
|
-
* createNodeFsTools() for a store shared with read.
|
|
8
|
+
* createNodeFsTools({ state }) for a store shared with read.
|
|
9
9
|
*/
|
|
10
10
|
export function createNodeEditTool(deps = {}) {
|
|
11
11
|
checkDeps(deps, "edit");
|
package/dist/filesystem.js
CHANGED
|
@@ -26,8 +26,8 @@ export function nodeFileSystem(options) {
|
|
|
26
26
|
denyRoots: Object.freeze([...config.denyRoots]),
|
|
27
27
|
symlinks: config.symlinks,
|
|
28
28
|
identity: "required",
|
|
29
|
-
capabilities: Object.freeze({
|
|
30
|
-
writeCapabilities: Object.freeze({
|
|
29
|
+
capabilities: Object.freeze({ identity: true }),
|
|
30
|
+
writeCapabilities: Object.freeze({ compareAndSwap: true }),
|
|
31
31
|
paths: posixPaths,
|
|
32
32
|
stat: (path, callOptions = {}) => nodeStat(context, path, callOptions),
|
|
33
33
|
write: writes.write,
|
package/dist/index.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ export { nodeCommandRunner } from "./command-runner.ts";
|
|
|
2
2
|
export type { NodeCommandRunnerOptions } from "./command-runner.ts";
|
|
3
3
|
export { createNodeBashTool } from "./create-node-bash-tool.ts";
|
|
4
4
|
export { createNodeFsTools } from "./create-node-fs-tools.ts";
|
|
5
|
-
export type { CreateNodeFsToolsOptions, NodeFsTools, NodeFsToolsBashOptions, NodeFsToolsWithBash, } from "./create-node-fs-tools.ts";
|
|
5
|
+
export type { CreateNodeFsToolsOptions, NodeFsTools, NodeFsToolsBashOptions, NodeFsToolsWithApplyPatch, NodeFsToolsWithBash, } from "./create-node-fs-tools.ts";
|
|
6
6
|
export { createNodeReadTool } from "./create-node-read-tool.ts";
|
|
7
7
|
export type { CreateNodeReadToolOptions } from "./create-node-read-tool.ts";
|
|
8
8
|
export { createNodeApplyPatchTool, createNodeEditTool, createNodeWriteTool, } from "./create-node-write-tools.ts";
|
package/dist/policy.d.ts
CHANGED
|
@@ -8,7 +8,11 @@ import type { FileSystemError, FileSystemRootOptions, SymlinkPolicy } from "@bet
|
|
|
8
8
|
* defaults to "node".
|
|
9
9
|
*/
|
|
10
10
|
export interface NodeFileSystemOptions extends FileSystemRootOptions<SymlinkPolicy, "required"> {
|
|
11
|
-
/**
|
|
11
|
+
/**
|
|
12
|
+
* How to replace a file with more than one hard link. Default "in-place":
|
|
13
|
+
* truncate and write through the link, which is not atomic. "refuse" fails
|
|
14
|
+
* with denied. A file with one link is always replaced by temp file and rename.
|
|
15
|
+
*/
|
|
12
16
|
readonly hardLinks?: "refuse" | "in-place";
|
|
13
17
|
/**
|
|
14
18
|
* Mode of a new file, exactly: the umask does not apply to a mode you set.
|
package/dist/policy.js
CHANGED
|
@@ -70,7 +70,7 @@ function resolveOptions(options) {
|
|
|
70
70
|
if (symlinks !== "follow-within-roots" && symlinks !== "reject") {
|
|
71
71
|
throw new TypeError('symlinks must be "follow-within-roots" or "reject"');
|
|
72
72
|
}
|
|
73
|
-
const hardLinks = options.hardLinks ?? "
|
|
73
|
+
const hardLinks = options.hardLinks ?? "in-place";
|
|
74
74
|
if (hardLinks !== "refuse" && hardLinks !== "in-place") {
|
|
75
75
|
throw new TypeError('hardLinks must be "refuse" or "in-place"');
|
|
76
76
|
}
|
package/dist/write.js
CHANGED
|
@@ -132,7 +132,7 @@ export function nodeWrites(context, io = NODE_WRITE_IO) {
|
|
|
132
132
|
await syncDirectory(path.dirname(target.resolvedPath));
|
|
133
133
|
const stats = await temp.handle.stat({ bigint: true }).catch(() => null);
|
|
134
134
|
await temp.handle.close().catch(() => { });
|
|
135
|
-
return { ok: true, file: mutated(target, stats, createdDirectories
|
|
135
|
+
return { ok: true, file: mutated(target, stats, createdDirectories) };
|
|
136
136
|
});
|
|
137
137
|
settled = true;
|
|
138
138
|
if (!outcome.ok)
|
|
@@ -182,7 +182,7 @@ export function nodeWrites(context, io = NODE_WRITE_IO) {
|
|
|
182
182
|
await handle.writeFile(bytes);
|
|
183
183
|
await handle.sync();
|
|
184
184
|
const after = await handle.stat({ bigint: true });
|
|
185
|
-
return { ok: true, file: mutated(target, after, []
|
|
185
|
+
return { ok: true, file: mutated(target, after, []) };
|
|
186
186
|
}
|
|
187
187
|
catch (error) {
|
|
188
188
|
return fail(mapMutationError(error, "publish", target));
|
|
@@ -265,7 +265,7 @@ export function nodeWrites(context, io = NODE_WRITE_IO) {
|
|
|
265
265
|
return fail(mapMutationError(error, "remove", target));
|
|
266
266
|
}
|
|
267
267
|
await syncDirectory(path.dirname(target.resolvedPath));
|
|
268
|
-
return { ok: true, file: mutated(target, null, []
|
|
268
|
+
return { ok: true, file: mutated(target, null, []) };
|
|
269
269
|
});
|
|
270
270
|
};
|
|
271
271
|
return { write, stage, remove };
|
|
@@ -281,7 +281,7 @@ function preconditionConflict(current, options) {
|
|
|
281
281
|
}
|
|
282
282
|
return null;
|
|
283
283
|
}
|
|
284
|
-
function mutated(target, stats, createdDirectories
|
|
284
|
+
function mutated(target, stats, createdDirectories) {
|
|
285
285
|
const version = stats === null ? null : nodeIdentity(stats);
|
|
286
286
|
return {
|
|
287
287
|
...target,
|
|
@@ -289,7 +289,6 @@ function mutated(target, stats, createdDirectories, atomic) {
|
|
|
289
289
|
identity: version,
|
|
290
290
|
size: stats === null ? null : Number(stats.size),
|
|
291
291
|
createdDirectories,
|
|
292
|
-
atomic,
|
|
293
292
|
};
|
|
294
293
|
}
|
|
295
294
|
const TEMP_NAME_MAX_CHARS = 48;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@better-fs-tools/node",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "The Node filesystem, a SHA-256 digest, a bash runner, and the zero-config read, edit, write, apply_patch, and bash tools for Node and Bun.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -29,10 +29,10 @@
|
|
|
29
29
|
"access": "public"
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {
|
|
32
|
-
"@better-fs-tools/fs": "^0.
|
|
33
|
-
"@better-fs-tools/read": "^0.
|
|
34
|
-
"@better-fs-tools/shell": "^0.
|
|
35
|
-
"@better-fs-tools/write": "^0.
|
|
32
|
+
"@better-fs-tools/fs": "^0.2.0",
|
|
33
|
+
"@better-fs-tools/read": "^0.2.0",
|
|
34
|
+
"@better-fs-tools/shell": "^0.2.0",
|
|
35
|
+
"@better-fs-tools/write": "^0.2.0"
|
|
36
36
|
},
|
|
37
37
|
"engines": {
|
|
38
38
|
"node": ">=24"
|