atomically 2.0.3 → 2.0.5
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/.nyc_output/06ea27ff-9d6e-44e2-b922-121687bc5661.json +1 -0
- package/.nyc_output/58e93f70-472d-449b-ac6b-4e640c0aeb02.json +1 -0
- package/.nyc_output/a4a404bb-72b9-43f0-be83-3d2a65aaec5a.json +1 -0
- package/.nyc_output/c18f7e70-50ab-4df7-afb5-2c2e27792296.json +1 -0
- package/.nyc_output/d1b8239a-6e10-4482-af38-f54b9a5f29ee.json +1 -0
- package/.nyc_output/processinfo/06ea27ff-9d6e-44e2-b922-121687bc5661.json +1 -0
- package/.nyc_output/processinfo/58e93f70-472d-449b-ac6b-4e640c0aeb02.json +1 -0
- package/.nyc_output/processinfo/a4a404bb-72b9-43f0-be83-3d2a65aaec5a.json +1 -0
- package/.nyc_output/processinfo/c18f7e70-50ab-4df7-afb5-2c2e27792296.json +1 -0
- package/.nyc_output/processinfo/d1b8239a-6e10-4482-af38-f54b9a5f29ee.json +1 -0
- package/.nyc_output/processinfo/index.json +1 -0
- package/dist/constants.d.ts +2 -2
- package/dist/constants.js +4 -5
- package/dist/index.d.ts +1 -2
- package/dist/index.js +25 -21
- package/dist/types.d.ts +0 -1
- package/dist/utils/lang.d.ts +2 -2
- package/dist/utils/scheduler.d.ts +1 -1
- package/dist/utils/temp.d.ts +1 -1
- package/dist/utils/temp.js +1 -1
- package/package.json +9 -8
- package/.editorconfig +0 -10
- package/src/constants.ts +0 -39
- package/src/index.ts +0 -331
- package/src/types.ts +0 -37
- package/src/utils/lang.ts +0 -34
- package/src/utils/scheduler.ts +0 -62
- package/src/utils/temp.ts +0 -102
- package/tasks/benchmark.js +0 -76
- package/test/basic.cjs +0 -508
- package/test/concurrency.cjs +0 -151
- package/test/integration.cjs +0 -289
- package/tsconfig.json +0 -3
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"parent":"58e93f70-472d-449b-ac6b-4e640c0aeb02","pid":36955,"argv":["/Users/fabio/.nvm/versions/node/v18.19.0/bin/node","/Users/fabio/Code/fabiospampinato/atomically/test/basic.cjs"],"execArgv":[],"cwd":"/Users/fabio/Code/fabiospampinato/atomically","time":1761513266816,"ppid":36954,"coverageFilename":"/Users/fabio/Code/fabiospampinato/atomically/.nyc_output/06ea27ff-9d6e-44e2-b922-121687bc5661.json","externalId":"test/basic.cjs","uuid":"06ea27ff-9d6e-44e2-b922-121687bc5661","files":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"parent":null,"pid":36954,"argv":["/Users/fabio/.nvm/versions/node/v18.19.0/bin/node","/Users/fabio/Code/fabiospampinato/atomically/node_modules/.bin/tap","--no-check-coverage","--no-coverage-report"],"execArgv":[],"cwd":"/Users/fabio/Code/fabiospampinato/atomically","time":1761513266396,"ppid":36923,"coverageFilename":"/Users/fabio/Code/fabiospampinato/atomically/.nyc_output/58e93f70-472d-449b-ac6b-4e640c0aeb02.json","externalId":"","uuid":"58e93f70-472d-449b-ac6b-4e640c0aeb02","files":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"parent":"58e93f70-472d-449b-ac6b-4e640c0aeb02","pid":36957,"argv":["/Users/fabio/.nvm/versions/node/v18.19.0/bin/node","/Users/fabio/Code/fabiospampinato/atomically/test/integration.cjs"],"execArgv":[],"cwd":"/Users/fabio/Code/fabiospampinato/atomically","time":1761513266816,"ppid":36954,"coverageFilename":"/Users/fabio/Code/fabiospampinato/atomically/.nyc_output/a4a404bb-72b9-43f0-be83-3d2a65aaec5a.json","externalId":"test/integration.cjs","uuid":"a4a404bb-72b9-43f0-be83-3d2a65aaec5a","files":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"parent":"58e93f70-472d-449b-ac6b-4e640c0aeb02","pid":36958,"argv":["/Users/fabio/.nvm/versions/node/v18.19.0/bin/node","/Users/fabio/Code/fabiospampinato/atomically/test/atomically.cjs"],"execArgv":[],"cwd":"/Users/fabio/Code/fabiospampinato/atomically","time":1761513266816,"ppid":36954,"coverageFilename":"/Users/fabio/Code/fabiospampinato/atomically/.nyc_output/c18f7e70-50ab-4df7-afb5-2c2e27792296.json","externalId":"test/atomically.cjs","uuid":"c18f7e70-50ab-4df7-afb5-2c2e27792296","files":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"parent":"58e93f70-472d-449b-ac6b-4e640c0aeb02","pid":36956,"argv":["/Users/fabio/.nvm/versions/node/v18.19.0/bin/node","/Users/fabio/Code/fabiospampinato/atomically/test/concurrency.cjs"],"execArgv":[],"cwd":"/Users/fabio/Code/fabiospampinato/atomically","time":1761513266816,"ppid":36954,"coverageFilename":"/Users/fabio/Code/fabiospampinato/atomically/.nyc_output/d1b8239a-6e10-4482-af38-f54b9a5f29ee.json","externalId":"test/concurrency.cjs","uuid":"d1b8239a-6e10-4482-af38-f54b9a5f29ee","files":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"processes":{"06ea27ff-9d6e-44e2-b922-121687bc5661":{"parent":"58e93f70-472d-449b-ac6b-4e640c0aeb02","externalId":"test/basic.cjs","children":[]},"58e93f70-472d-449b-ac6b-4e640c0aeb02":{"parent":null,"children":["06ea27ff-9d6e-44e2-b922-121687bc5661","a4a404bb-72b9-43f0-be83-3d2a65aaec5a","c18f7e70-50ab-4df7-afb5-2c2e27792296","d1b8239a-6e10-4482-af38-f54b9a5f29ee"]},"a4a404bb-72b9-43f0-be83-3d2a65aaec5a":{"parent":"58e93f70-472d-449b-ac6b-4e640c0aeb02","externalId":"test/integration.cjs","children":[]},"c18f7e70-50ab-4df7-afb5-2c2e27792296":{"parent":"58e93f70-472d-449b-ac6b-4e640c0aeb02","externalId":"test/atomically.cjs","children":[]},"d1b8239a-6e10-4482-af38-f54b9a5f29ee":{"parent":"58e93f70-472d-449b-ac6b-4e640c0aeb02","externalId":"test/concurrency.cjs","children":[]}},"files":{},"externalIds":{"test/basic.cjs":{"root":"06ea27ff-9d6e-44e2-b922-121687bc5661","children":[]},"test/integration.cjs":{"root":"a4a404bb-72b9-43f0-be83-3d2a65aaec5a","children":[]},"test/atomically.cjs":{"root":"c18f7e70-50ab-4df7-afb5-2c2e27792296","children":[]},"test/concurrency.cjs":{"root":"d1b8239a-6e10-4482-af38-f54b9a5f29ee","children":[]}}}
|
package/dist/constants.d.ts
CHANGED
|
@@ -5,11 +5,11 @@ declare const DEFAULT_READ_OPTIONS: {};
|
|
|
5
5
|
declare const DEFAULT_WRITE_OPTIONS: {};
|
|
6
6
|
declare const DEFAULT_USER_UID: number;
|
|
7
7
|
declare const DEFAULT_USER_GID: number;
|
|
8
|
+
declare const DEFAULT_INTERVAL_ASYNC = 200;
|
|
8
9
|
declare const DEFAULT_TIMEOUT_ASYNC = 7500;
|
|
9
10
|
declare const DEFAULT_TIMEOUT_SYNC = 1000;
|
|
10
11
|
declare const IS_POSIX: boolean;
|
|
11
12
|
declare const IS_USER_ROOT: boolean;
|
|
12
13
|
declare const LIMIT_BASENAME_LENGTH = 128;
|
|
13
|
-
declare const LIMIT_FILES_DESCRIPTORS = 10000;
|
|
14
14
|
declare const NOOP: () => void;
|
|
15
|
-
export { DEFAULT_ENCODING, DEFAULT_FILE_MODE, DEFAULT_FOLDER_MODE, DEFAULT_READ_OPTIONS, DEFAULT_WRITE_OPTIONS, DEFAULT_USER_UID, DEFAULT_USER_GID, DEFAULT_TIMEOUT_ASYNC, DEFAULT_TIMEOUT_SYNC, IS_POSIX, IS_USER_ROOT, LIMIT_BASENAME_LENGTH,
|
|
15
|
+
export { DEFAULT_ENCODING, DEFAULT_FILE_MODE, DEFAULT_FOLDER_MODE, DEFAULT_READ_OPTIONS, DEFAULT_WRITE_OPTIONS, DEFAULT_USER_UID, DEFAULT_USER_GID, DEFAULT_INTERVAL_ASYNC, DEFAULT_TIMEOUT_ASYNC, DEFAULT_TIMEOUT_SYNC, IS_POSIX, IS_USER_ROOT, LIMIT_BASENAME_LENGTH, NOOP };
|
package/dist/constants.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
/* IMPORT */
|
|
2
|
-
import os from 'node:os';
|
|
3
2
|
import process from 'node:process';
|
|
4
3
|
/* MAIN */
|
|
5
4
|
const DEFAULT_ENCODING = 'utf8';
|
|
@@ -7,14 +6,14 @@ const DEFAULT_FILE_MODE = 0o666;
|
|
|
7
6
|
const DEFAULT_FOLDER_MODE = 0o777;
|
|
8
7
|
const DEFAULT_READ_OPTIONS = {};
|
|
9
8
|
const DEFAULT_WRITE_OPTIONS = {};
|
|
10
|
-
const DEFAULT_USER_UID =
|
|
11
|
-
const DEFAULT_USER_GID =
|
|
9
|
+
const DEFAULT_USER_UID = process.geteuid ? process.geteuid() : -1;
|
|
10
|
+
const DEFAULT_USER_GID = process.getegid ? process.getegid() : -1;
|
|
11
|
+
const DEFAULT_INTERVAL_ASYNC = 200;
|
|
12
12
|
const DEFAULT_TIMEOUT_ASYNC = 7500;
|
|
13
13
|
const DEFAULT_TIMEOUT_SYNC = 1000;
|
|
14
14
|
const IS_POSIX = !!process.getuid;
|
|
15
15
|
const IS_USER_ROOT = process.getuid ? !process.getuid() : false;
|
|
16
16
|
const LIMIT_BASENAME_LENGTH = 128; //TODO: Fetch the real limit from the filesystem //TODO: Fetch the whole-path length limit too
|
|
17
|
-
const LIMIT_FILES_DESCRIPTORS = 10000; //TODO: Fetch the real limit from the filesystem
|
|
18
17
|
const NOOP = () => { };
|
|
19
18
|
/* EXPORT */
|
|
20
|
-
export { DEFAULT_ENCODING, DEFAULT_FILE_MODE, DEFAULT_FOLDER_MODE, DEFAULT_READ_OPTIONS, DEFAULT_WRITE_OPTIONS, DEFAULT_USER_UID, DEFAULT_USER_GID, DEFAULT_TIMEOUT_ASYNC, DEFAULT_TIMEOUT_SYNC, IS_POSIX, IS_USER_ROOT, LIMIT_BASENAME_LENGTH,
|
|
19
|
+
export { DEFAULT_ENCODING, DEFAULT_FILE_MODE, DEFAULT_FOLDER_MODE, DEFAULT_READ_OPTIONS, DEFAULT_WRITE_OPTIONS, DEFAULT_USER_UID, DEFAULT_USER_GID, DEFAULT_INTERVAL_ASYNC, DEFAULT_TIMEOUT_ASYNC, DEFAULT_TIMEOUT_SYNC, IS_POSIX, IS_USER_ROOT, LIMIT_BASENAME_LENGTH, NOOP };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
import type { Callback, Data, Encoding, Path, ReadOptions, WriteOptions } from './types';
|
|
1
|
+
import type { Callback, Data, Encoding, Path, ReadOptions, WriteOptions } from './types.js';
|
|
3
2
|
declare function readFile(filePath: Path, options: Encoding | ReadOptions & {
|
|
4
3
|
encoding: string;
|
|
5
4
|
}): Promise<string>;
|
package/dist/index.js
CHANGED
|
@@ -1,21 +1,23 @@
|
|
|
1
1
|
/* IMPORT */
|
|
2
2
|
import path from 'node:path';
|
|
3
3
|
import fs from 'stubborn-fs';
|
|
4
|
-
import { DEFAULT_ENCODING, DEFAULT_FILE_MODE, DEFAULT_FOLDER_MODE, DEFAULT_READ_OPTIONS, DEFAULT_WRITE_OPTIONS, DEFAULT_USER_UID, DEFAULT_USER_GID, DEFAULT_TIMEOUT_ASYNC, DEFAULT_TIMEOUT_SYNC, IS_POSIX } from './constants.js';
|
|
4
|
+
import { DEFAULT_ENCODING, DEFAULT_FILE_MODE, DEFAULT_FOLDER_MODE, DEFAULT_READ_OPTIONS, DEFAULT_WRITE_OPTIONS, DEFAULT_USER_UID, DEFAULT_USER_GID, DEFAULT_INTERVAL_ASYNC, DEFAULT_TIMEOUT_ASYNC, DEFAULT_TIMEOUT_SYNC, IS_POSIX } from './constants.js';
|
|
5
5
|
import { isException, isFunction, isString, isUndefined } from './utils/lang.js';
|
|
6
6
|
import Scheduler from './utils/scheduler.js';
|
|
7
7
|
import Temp from './utils/temp.js';
|
|
8
8
|
function readFile(filePath, options = DEFAULT_READ_OPTIONS) {
|
|
9
9
|
if (isString(options))
|
|
10
10
|
return readFile(filePath, { encoding: options });
|
|
11
|
-
const timeout =
|
|
12
|
-
|
|
11
|
+
const timeout = options.timeout ?? DEFAULT_TIMEOUT_ASYNC;
|
|
12
|
+
const retryOptions = { timeout, interval: DEFAULT_INTERVAL_ASYNC };
|
|
13
|
+
return fs.retry.readFile(retryOptions)(filePath, options);
|
|
13
14
|
}
|
|
14
15
|
function readFileSync(filePath, options = DEFAULT_READ_OPTIONS) {
|
|
15
16
|
if (isString(options))
|
|
16
17
|
return readFileSync(filePath, { encoding: options });
|
|
17
|
-
const timeout =
|
|
18
|
-
|
|
18
|
+
const timeout = options.timeout ?? DEFAULT_TIMEOUT_SYNC;
|
|
19
|
+
const retryOptions = { timeout };
|
|
20
|
+
return fs.retry.readFileSync(retryOptions)(filePath, options);
|
|
19
21
|
}
|
|
20
22
|
function writeFile(filePath, data, options, callback) {
|
|
21
23
|
if (isFunction(options))
|
|
@@ -28,7 +30,8 @@ function writeFile(filePath, data, options, callback) {
|
|
|
28
30
|
async function writeFileAsync(filePath, data, options = DEFAULT_WRITE_OPTIONS) {
|
|
29
31
|
if (isString(options))
|
|
30
32
|
return writeFileAsync(filePath, data, { encoding: options });
|
|
31
|
-
const timeout =
|
|
33
|
+
const timeout = options.timeout ?? DEFAULT_TIMEOUT_ASYNC;
|
|
34
|
+
const retryOptions = { timeout, interval: DEFAULT_INTERVAL_ASYNC };
|
|
32
35
|
let schedulerCustomDisposer = null;
|
|
33
36
|
let schedulerDisposer = null;
|
|
34
37
|
let tempDisposer = null;
|
|
@@ -63,25 +66,25 @@ async function writeFileAsync(filePath, data, options = DEFAULT_WRITE_OPTIONS) {
|
|
|
63
66
|
recursive: true
|
|
64
67
|
});
|
|
65
68
|
}
|
|
66
|
-
fd = await fs.retry.open(
|
|
69
|
+
fd = await fs.retry.open(retryOptions)(tempPath, 'w', options.mode || DEFAULT_FILE_MODE);
|
|
67
70
|
if (options.tmpCreated) {
|
|
68
71
|
options.tmpCreated(tempPath);
|
|
69
72
|
}
|
|
70
73
|
if (isString(data)) {
|
|
71
|
-
await fs.retry.write(
|
|
74
|
+
await fs.retry.write(retryOptions)(fd, data, 0, options.encoding || DEFAULT_ENCODING);
|
|
72
75
|
}
|
|
73
76
|
else if (!isUndefined(data)) {
|
|
74
|
-
await fs.retry.write(
|
|
77
|
+
await fs.retry.write(retryOptions)(fd, data, 0, data.length, 0);
|
|
75
78
|
}
|
|
76
79
|
if (options.fsync !== false) {
|
|
77
80
|
if (options.fsyncWait !== false) {
|
|
78
|
-
await fs.retry.fsync(
|
|
81
|
+
await fs.retry.fsync(retryOptions)(fd);
|
|
79
82
|
}
|
|
80
83
|
else {
|
|
81
84
|
fs.attempt.fsync(fd);
|
|
82
85
|
}
|
|
83
86
|
}
|
|
84
|
-
await fs.retry.close(
|
|
87
|
+
await fs.retry.close(retryOptions)(fd);
|
|
85
88
|
fd = null;
|
|
86
89
|
if (options.chown && (options.chown.uid !== DEFAULT_USER_UID || options.chown.gid !== DEFAULT_USER_GID)) {
|
|
87
90
|
await fs.attempt.chown(tempPath, options.chown.uid, options.chown.gid);
|
|
@@ -90,14 +93,14 @@ async function writeFileAsync(filePath, data, options = DEFAULT_WRITE_OPTIONS) {
|
|
|
90
93
|
await fs.attempt.chmod(tempPath, options.mode);
|
|
91
94
|
}
|
|
92
95
|
try {
|
|
93
|
-
await fs.retry.rename(
|
|
96
|
+
await fs.retry.rename(retryOptions)(tempPath, filePath);
|
|
94
97
|
}
|
|
95
98
|
catch (error) {
|
|
96
99
|
if (!isException(error))
|
|
97
100
|
throw error;
|
|
98
101
|
if (error.code !== 'ENAMETOOLONG')
|
|
99
102
|
throw error;
|
|
100
|
-
await fs.retry.rename(
|
|
103
|
+
await fs.retry.rename(retryOptions)(tempPath, Temp.truncate(filePath));
|
|
101
104
|
}
|
|
102
105
|
tempDisposer();
|
|
103
106
|
tempPath = null;
|
|
@@ -116,7 +119,8 @@ async function writeFileAsync(filePath, data, options = DEFAULT_WRITE_OPTIONS) {
|
|
|
116
119
|
function writeFileSync(filePath, data, options = DEFAULT_WRITE_OPTIONS) {
|
|
117
120
|
if (isString(options))
|
|
118
121
|
return writeFileSync(filePath, data, { encoding: options });
|
|
119
|
-
const timeout =
|
|
122
|
+
const timeout = options.timeout ?? DEFAULT_TIMEOUT_SYNC;
|
|
123
|
+
const retryOptions = { timeout };
|
|
120
124
|
let tempDisposer = null;
|
|
121
125
|
let tempPath = null;
|
|
122
126
|
let fd = null;
|
|
@@ -146,25 +150,25 @@ function writeFileSync(filePath, data, options = DEFAULT_WRITE_OPTIONS) {
|
|
|
146
150
|
recursive: true
|
|
147
151
|
});
|
|
148
152
|
}
|
|
149
|
-
fd = fs.retry.openSync(
|
|
153
|
+
fd = fs.retry.openSync(retryOptions)(tempPath, 'w', options.mode || DEFAULT_FILE_MODE);
|
|
150
154
|
if (options.tmpCreated) {
|
|
151
155
|
options.tmpCreated(tempPath);
|
|
152
156
|
}
|
|
153
157
|
if (isString(data)) {
|
|
154
|
-
fs.retry.writeSync(
|
|
158
|
+
fs.retry.writeSync(retryOptions)(fd, data, 0, options.encoding || DEFAULT_ENCODING);
|
|
155
159
|
}
|
|
156
160
|
else if (!isUndefined(data)) {
|
|
157
|
-
fs.retry.writeSync(
|
|
161
|
+
fs.retry.writeSync(retryOptions)(fd, data, 0, data.length, 0);
|
|
158
162
|
}
|
|
159
163
|
if (options.fsync !== false) {
|
|
160
164
|
if (options.fsyncWait !== false) {
|
|
161
|
-
fs.retry.fsyncSync(
|
|
165
|
+
fs.retry.fsyncSync(retryOptions)(fd);
|
|
162
166
|
}
|
|
163
167
|
else {
|
|
164
168
|
fs.attempt.fsync(fd);
|
|
165
169
|
}
|
|
166
170
|
}
|
|
167
|
-
fs.retry.closeSync(
|
|
171
|
+
fs.retry.closeSync(retryOptions)(fd);
|
|
168
172
|
fd = null;
|
|
169
173
|
if (options.chown && (options.chown.uid !== DEFAULT_USER_UID || options.chown.gid !== DEFAULT_USER_GID)) {
|
|
170
174
|
fs.attempt.chownSync(tempPath, options.chown.uid, options.chown.gid);
|
|
@@ -173,14 +177,14 @@ function writeFileSync(filePath, data, options = DEFAULT_WRITE_OPTIONS) {
|
|
|
173
177
|
fs.attempt.chmodSync(tempPath, options.mode);
|
|
174
178
|
}
|
|
175
179
|
try {
|
|
176
|
-
fs.retry.renameSync(
|
|
180
|
+
fs.retry.renameSync(retryOptions)(tempPath, filePath);
|
|
177
181
|
}
|
|
178
182
|
catch (error) {
|
|
179
183
|
if (!isException(error))
|
|
180
184
|
throw error;
|
|
181
185
|
if (error.code !== 'ENAMETOOLONG')
|
|
182
186
|
throw error;
|
|
183
|
-
fs.retry.renameSync(
|
|
187
|
+
fs.retry.renameSync(retryOptions)(tempPath, Temp.truncate(filePath));
|
|
184
188
|
}
|
|
185
189
|
tempDisposer();
|
|
186
190
|
tempPath = null;
|
package/dist/types.d.ts
CHANGED
package/dist/utils/lang.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
declare const isException: (value: unknown) => value is
|
|
1
|
+
import type { Exception } from '../types.js';
|
|
2
|
+
declare const isException: (value: unknown) => value is Exception;
|
|
3
3
|
declare const isFunction: (value: unknown) => value is Function;
|
|
4
4
|
declare const isString: (value: unknown) => value is string;
|
|
5
5
|
declare const isUndefined: (value: unknown) => value is undefined;
|
package/dist/utils/temp.d.ts
CHANGED
package/dist/utils/temp.js
CHANGED
|
@@ -7,7 +7,7 @@ import { LIMIT_BASENAME_LENGTH } from '../constants.js';
|
|
|
7
7
|
//TODO: Maybe publish this as a standalone package
|
|
8
8
|
const Temp = {
|
|
9
9
|
/* VARIABLES */
|
|
10
|
-
store: {},
|
|
10
|
+
store: {}, // filePath => purge
|
|
11
11
|
/* API */
|
|
12
12
|
create: (filePath) => {
|
|
13
13
|
const randomness = `000000${Math.floor(Math.random() * 16777215).toString(16)}`.slice(-6); // 6 random-enough hex characters
|
package/package.json
CHANGED
|
@@ -2,7 +2,8 @@
|
|
|
2
2
|
"name": "atomically",
|
|
3
3
|
"repository": "github:fabiospampinato/atomically",
|
|
4
4
|
"description": "Read and write files atomically and reliably.",
|
|
5
|
-
"
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"version": "2.0.5",
|
|
6
7
|
"type": "module",
|
|
7
8
|
"main": "dist/index.js",
|
|
8
9
|
"exports": "./dist/index.js",
|
|
@@ -26,16 +27,16 @@
|
|
|
26
27
|
"reliable"
|
|
27
28
|
],
|
|
28
29
|
"dependencies": {
|
|
29
|
-
"stubborn-fs": "^
|
|
30
|
-
"when-exit": "^2.1.
|
|
30
|
+
"stubborn-fs": "^2.0.0",
|
|
31
|
+
"when-exit": "^2.1.4"
|
|
31
32
|
},
|
|
32
33
|
"devDependencies": {
|
|
33
|
-
"@types/node": "^
|
|
34
|
-
"esbuild": "^0.18.
|
|
34
|
+
"@types/node": "^18.19.130",
|
|
35
|
+
"esbuild": "^0.18.20",
|
|
35
36
|
"require-inject": "^1.4.4",
|
|
36
37
|
"tap": "^16.3.8",
|
|
37
|
-
"tsex": "^
|
|
38
|
-
"typescript": "^5.
|
|
39
|
-
"write-file-atomic": "^
|
|
38
|
+
"tsex": "^4.0.2",
|
|
39
|
+
"typescript": "^5.9.3",
|
|
40
|
+
"write-file-atomic": "^7.0.0"
|
|
40
41
|
}
|
|
41
42
|
}
|
package/.editorconfig
DELETED
package/src/constants.ts
DELETED
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
/* IMPORT */
|
|
3
|
-
|
|
4
|
-
import os from 'node:os';
|
|
5
|
-
import process from 'node:process';
|
|
6
|
-
|
|
7
|
-
/* MAIN */
|
|
8
|
-
|
|
9
|
-
const DEFAULT_ENCODING = 'utf8';
|
|
10
|
-
|
|
11
|
-
const DEFAULT_FILE_MODE = 0o666;
|
|
12
|
-
|
|
13
|
-
const DEFAULT_FOLDER_MODE = 0o777;
|
|
14
|
-
|
|
15
|
-
const DEFAULT_READ_OPTIONS = {};
|
|
16
|
-
|
|
17
|
-
const DEFAULT_WRITE_OPTIONS = {};
|
|
18
|
-
|
|
19
|
-
const DEFAULT_USER_UID = os.userInfo ().uid;
|
|
20
|
-
|
|
21
|
-
const DEFAULT_USER_GID = os.userInfo ().gid;
|
|
22
|
-
|
|
23
|
-
const DEFAULT_TIMEOUT_ASYNC = 7500;
|
|
24
|
-
|
|
25
|
-
const DEFAULT_TIMEOUT_SYNC = 1000;
|
|
26
|
-
|
|
27
|
-
const IS_POSIX = !!process.getuid;
|
|
28
|
-
|
|
29
|
-
const IS_USER_ROOT = process.getuid ? !process.getuid () : false;
|
|
30
|
-
|
|
31
|
-
const LIMIT_BASENAME_LENGTH = 128; //TODO: Fetch the real limit from the filesystem //TODO: Fetch the whole-path length limit too
|
|
32
|
-
|
|
33
|
-
const LIMIT_FILES_DESCRIPTORS = 10_000; //TODO: Fetch the real limit from the filesystem
|
|
34
|
-
|
|
35
|
-
const NOOP = () => {};
|
|
36
|
-
|
|
37
|
-
/* EXPORT */
|
|
38
|
-
|
|
39
|
-
export {DEFAULT_ENCODING, DEFAULT_FILE_MODE, DEFAULT_FOLDER_MODE, DEFAULT_READ_OPTIONS, DEFAULT_WRITE_OPTIONS, DEFAULT_USER_UID, DEFAULT_USER_GID, DEFAULT_TIMEOUT_ASYNC, DEFAULT_TIMEOUT_SYNC, IS_POSIX, IS_USER_ROOT, LIMIT_BASENAME_LENGTH, LIMIT_FILES_DESCRIPTORS, NOOP};
|