@zenfs/core 1.2.0 → 1.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.
- package/dist/config.d.ts +13 -4
- package/dist/config.js +2 -1
- package/dist/emulation/cache.d.ts +14 -2
- package/dist/emulation/cache.js +25 -0
- package/dist/emulation/config.d.ts +10 -0
- package/dist/emulation/config.js +10 -0
- package/dist/emulation/promises.js +24 -13
- package/dist/emulation/shared.d.ts +0 -6
- package/dist/emulation/shared.js +0 -6
- package/dist/emulation/sync.js +13 -12
- package/dist/file.d.ts +1 -1
- package/dist/file.js +6 -3
- package/package.json +1 -1
- package/readme.md +1 -1
- package/scripts/test.js +5 -0
- package/src/config.ts +17 -5
- package/src/emulation/cache.ts +32 -3
- package/src/emulation/config.ts +11 -0
- package/src/emulation/promises.ts +25 -13
- package/src/emulation/shared.ts +0 -7
- package/src/emulation/sync.ts +13 -12
- package/src/file.ts +4 -3
- package/tests/common.ts +1 -11
- package/tests/fs/appendFile.test.ts +3 -3
- package/tests/fs/dir.test.ts +7 -7
- package/tests/fs/directory.test.ts +8 -8
- package/tests/fs/errors.test.ts +1 -1
- package/tests/fs/links.test.ts +4 -4
- package/tests/fs/open.test.ts +3 -3
- package/tests/fs/permissions.test.ts +5 -5
- package/tests/fs/read.test.ts +5 -5
- package/tests/fs/readFile.test.ts +2 -2
- package/tests/fs/rename.test.ts +5 -5
- package/tests/fs/stat.test.ts +1 -1
- package/tests/fs/streams.test.ts +19 -19
- package/tests/fs/times.test.ts +6 -6
- package/tests/fs/truncate.test.ts +1 -1
- package/tests/fs/watch.test.ts +10 -10
- package/tests/fs/write.test.ts +5 -5
- package/tests/fs/writeFile.test.ts +5 -5
- package/tests/handle.test.ts +2 -2
- package/tests/mutex.test.ts +1 -1
- package/tests/port/channel.test.ts +3 -3
- package/tests/port/config.test.ts +4 -5
- package/tests/port/config.worker.js +5 -0
- package/tests/port/remote.test.ts +4 -5
- package/tests/port/remote.worker.js +5 -0
- package/tests/port/timeout.test.ts +4 -4
- package/tests/setup/common.ts +1 -1
- package/tests/setup/cow+fetch.ts +1 -1
- package/tests/port/config.worker.ts +0 -5
- package/tests/port/remote.worker.ts +0 -5
package/tests/fs/watch.test.ts
CHANGED
|
@@ -14,8 +14,8 @@ await fs.promises.writeFile(testFile, 'Initial content');
|
|
|
14
14
|
suite('Watch Features', () => {
|
|
15
15
|
test('fs.watch should emit events on file change', async () => {
|
|
16
16
|
using watcher = fs.watch(testFile, (eventType, filename) => {
|
|
17
|
-
assert(eventType
|
|
18
|
-
assert(filename
|
|
17
|
+
assert.strictEqual(eventType, 'change');
|
|
18
|
+
assert.strictEqual(filename, 'test.txt');
|
|
19
19
|
});
|
|
20
20
|
|
|
21
21
|
// Modify the file to trigger the event
|
|
@@ -24,8 +24,8 @@ suite('Watch Features', () => {
|
|
|
24
24
|
|
|
25
25
|
test('fs.watch should emit events on file rename (delete)', async () => {
|
|
26
26
|
using watcher = fs.watch(testFile, (eventType, filename) => {
|
|
27
|
-
assert(eventType
|
|
28
|
-
assert(filename
|
|
27
|
+
assert.strictEqual(eventType, 'rename');
|
|
28
|
+
assert.strictEqual(filename, 'test.txt');
|
|
29
29
|
});
|
|
30
30
|
|
|
31
31
|
// Delete the file to trigger the event
|
|
@@ -63,8 +63,8 @@ suite('Watch Features', () => {
|
|
|
63
63
|
|
|
64
64
|
test('fs.watch should work with directories', async () => {
|
|
65
65
|
using watcher = fs.watch(testDir, (eventType, filename) => {
|
|
66
|
-
assert(eventType
|
|
67
|
-
assert(filename
|
|
66
|
+
assert.strictEqual(eventType, 'change');
|
|
67
|
+
assert.strictEqual(filename, 'newFile.txt');
|
|
68
68
|
});
|
|
69
69
|
|
|
70
70
|
await fs.promises.writeFile(`${testDir}/newFile.txt`, 'Content');
|
|
@@ -77,8 +77,8 @@ suite('Watch Features', () => {
|
|
|
77
77
|
await fs.promises.writeFile(oldFile, 'Some content');
|
|
78
78
|
|
|
79
79
|
using watcher = fs.watch(testDir, (eventType, filename) => {
|
|
80
|
-
assert(eventType
|
|
81
|
-
assert(filename
|
|
80
|
+
assert.strictEqual(eventType, 'rename');
|
|
81
|
+
assert.strictEqual(filename, 'oldFile.txt');
|
|
82
82
|
});
|
|
83
83
|
|
|
84
84
|
// Rename the file to trigger the event
|
|
@@ -91,8 +91,8 @@ suite('Watch Features', () => {
|
|
|
91
91
|
await fs.promises.writeFile(tempFile, 'Temporary content');
|
|
92
92
|
|
|
93
93
|
using watcher = fs.watch(tempFile, (eventType, filename) => {
|
|
94
|
-
assert(eventType
|
|
95
|
-
assert(filename
|
|
94
|
+
assert.strictEqual(eventType, 'rename');
|
|
95
|
+
assert.strictEqual(filename, 'tempFile.txt');
|
|
96
96
|
});
|
|
97
97
|
|
|
98
98
|
await fs.promises.unlink(tempFile);
|
package/tests/fs/write.test.ts
CHANGED
|
@@ -10,11 +10,11 @@ suite('write', () => {
|
|
|
10
10
|
const handle = await fs.promises.open(fn, 'w', 0o644);
|
|
11
11
|
await handle.write('', 0, 'utf8');
|
|
12
12
|
const { bytesWritten } = await handle.write(expected, 0, 'utf8');
|
|
13
|
-
assert(bytesWritten
|
|
13
|
+
assert.strictEqual(bytesWritten, Buffer.from(expected).length);
|
|
14
14
|
await handle.close();
|
|
15
15
|
|
|
16
16
|
const data = await fs.promises.readFile(fn, 'utf8');
|
|
17
|
-
assert(data
|
|
17
|
+
assert.strictEqual(data, expected);
|
|
18
18
|
|
|
19
19
|
await fs.promises.unlink(fn);
|
|
20
20
|
});
|
|
@@ -27,7 +27,7 @@ suite('write', () => {
|
|
|
27
27
|
|
|
28
28
|
const written = await handle.write(expected, 0, expected.length, null);
|
|
29
29
|
|
|
30
|
-
assert(expected.length
|
|
30
|
+
assert.strictEqual(expected.length, written.bytesWritten);
|
|
31
31
|
|
|
32
32
|
await handle.close();
|
|
33
33
|
|
|
@@ -43,13 +43,13 @@ suite('writeSync', () => {
|
|
|
43
43
|
const fd = fs.openSync(fn, 'w');
|
|
44
44
|
|
|
45
45
|
let written = fs.writeSync(fd, '');
|
|
46
|
-
assert(written
|
|
46
|
+
assert.strictEqual(written, 0);
|
|
47
47
|
|
|
48
48
|
fs.writeSync(fd, 'foo');
|
|
49
49
|
|
|
50
50
|
const data = Buffer.from('bár');
|
|
51
51
|
written = fs.writeSync(fd, data, 0, data.length);
|
|
52
|
-
assert(written
|
|
52
|
+
assert.strictEqual(written, 4);
|
|
53
53
|
|
|
54
54
|
fs.closeSync(fd);
|
|
55
55
|
|
|
@@ -10,7 +10,7 @@ suite('writeFile', () => {
|
|
|
10
10
|
const filename = 'test.txt';
|
|
11
11
|
await fs.promises.writeFile(filename, s);
|
|
12
12
|
const data = await fs.promises.readFile(filename);
|
|
13
|
-
assert(data.length
|
|
13
|
+
assert.strictEqual(data.length, Buffer.from(s).length);
|
|
14
14
|
await fs.promises.unlink(filename);
|
|
15
15
|
});
|
|
16
16
|
|
|
@@ -20,7 +20,7 @@ suite('writeFile', () => {
|
|
|
20
20
|
|
|
21
21
|
await fs.promises.writeFile(filename, expected);
|
|
22
22
|
const actual = await fs.promises.readFile(filename);
|
|
23
|
-
assert(actual.length
|
|
23
|
+
assert.strictEqual(actual.length, expected.length);
|
|
24
24
|
|
|
25
25
|
await fs.promises.unlink(filename);
|
|
26
26
|
});
|
|
@@ -35,7 +35,7 @@ suite('writeFile', () => {
|
|
|
35
35
|
await fs.promises.writeFile(filePath, buffer);
|
|
36
36
|
|
|
37
37
|
const read = await fs.promises.readFile(filePath, 'base64');
|
|
38
|
-
assert(read
|
|
38
|
+
assert.strictEqual(read, data);
|
|
39
39
|
});
|
|
40
40
|
});
|
|
41
41
|
|
|
@@ -47,7 +47,7 @@ suite('File Writing with Custom Mode', () => {
|
|
|
47
47
|
fs.writeFileSync(file, '123', { mode });
|
|
48
48
|
|
|
49
49
|
const content = fs.readFileSync(file, 'utf8');
|
|
50
|
-
assert(content
|
|
50
|
+
assert.strictEqual(content, '123');
|
|
51
51
|
assert((fs.statSync(file).mode & 0o777) === mode);
|
|
52
52
|
|
|
53
53
|
fs.unlinkSync(file);
|
|
@@ -60,7 +60,7 @@ suite('File Writing with Custom Mode', () => {
|
|
|
60
60
|
fs.appendFileSync(file, 'abc', { mode });
|
|
61
61
|
|
|
62
62
|
const content = fs.readFileSync(file, { encoding: 'utf8' });
|
|
63
|
-
assert(content
|
|
63
|
+
assert.strictEqual(content, 'abc');
|
|
64
64
|
|
|
65
65
|
assert((fs.statSync(file).mode & 0o777) === mode);
|
|
66
66
|
|
package/tests/handle.test.ts
CHANGED
|
@@ -50,8 +50,8 @@ await suite('FileHandle', () => {
|
|
|
50
50
|
test('chown', async () => {
|
|
51
51
|
await handle.chown(1234, 5678);
|
|
52
52
|
const stats = await handle.stat();
|
|
53
|
-
assert(stats.uid
|
|
54
|
-
assert(stats.gid
|
|
53
|
+
assert.equal(stats.uid, 1234);
|
|
54
|
+
assert.equal(stats.gid, 5678);
|
|
55
55
|
});
|
|
56
56
|
|
|
57
57
|
test('close', async () => {
|
package/tests/mutex.test.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import assert from 'node:assert';
|
|
2
2
|
import { suite, test } from 'node:test';
|
|
3
3
|
import { MessageChannel } from 'node:worker_threads';
|
|
4
|
-
import { Port, attachFS } from '../../
|
|
5
|
-
import type { StoreFS } from '../../
|
|
6
|
-
import { InMemory, configureSingle, fs, resolveMountConfig, type InMemoryStore } from '../../
|
|
4
|
+
import { Port, attachFS } from '../../dist/backends/port/fs.js';
|
|
5
|
+
import type { StoreFS } from '../../dist/index.js';
|
|
6
|
+
import { InMemory, configureSingle, fs, resolveMountConfig, type InMemoryStore } from '../../dist/index.js';
|
|
7
7
|
|
|
8
8
|
const { port1, port2 } = new MessageChannel(),
|
|
9
9
|
content = 'FS is in a port';
|
|
@@ -2,14 +2,13 @@ import assert from 'node:assert';
|
|
|
2
2
|
import { dirname } from 'node:path';
|
|
3
3
|
import { suite, test } from 'node:test';
|
|
4
4
|
import { fileURLToPath } from 'node:url';
|
|
5
|
-
import
|
|
6
|
-
import { Port } from '../../
|
|
7
|
-
import { configureSingle, fs } from '../../
|
|
8
|
-
import { createTSWorker } from '../common.js';
|
|
5
|
+
import { Worker } from 'node:worker_threads';
|
|
6
|
+
import { Port } from '../../dist/backends/port/fs.js';
|
|
7
|
+
import { configureSingle, fs } from '../../dist/index.js';
|
|
9
8
|
|
|
10
9
|
const dir = dirname(fileURLToPath(import.meta.url));
|
|
11
10
|
|
|
12
|
-
const port
|
|
11
|
+
const port = new Worker(dir + '/config.worker.js');
|
|
13
12
|
|
|
14
13
|
await suite('Remote FS with resolveRemoteMount', () => {
|
|
15
14
|
const content = 'FS is in a port';
|
|
@@ -2,14 +2,13 @@ import assert from 'node:assert';
|
|
|
2
2
|
import { dirname } from 'node:path';
|
|
3
3
|
import { suite, test } from 'node:test';
|
|
4
4
|
import { fileURLToPath } from 'node:url';
|
|
5
|
-
import
|
|
6
|
-
import { Port } from '../../
|
|
7
|
-
import { configureSingle, fs } from '../../
|
|
8
|
-
import { createTSWorker } from '../common.js';
|
|
5
|
+
import { Worker } from 'node:worker_threads';
|
|
6
|
+
import { Port } from '../../dist/backends/port/fs.js';
|
|
7
|
+
import { configureSingle, fs } from '../../dist/index.js';
|
|
9
8
|
|
|
10
9
|
const dir = dirname(fileURLToPath(import.meta.url));
|
|
11
10
|
|
|
12
|
-
const port
|
|
11
|
+
const port = new Worker(dir + '/remote.worker.js');
|
|
13
12
|
|
|
14
13
|
await suite('Remote FS', () => {
|
|
15
14
|
const content = 'FS is in a port';
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import assert from 'node:assert';
|
|
2
2
|
import { suite, test } from 'node:test';
|
|
3
3
|
import { MessageChannel } from 'node:worker_threads';
|
|
4
|
-
import { Port } from '../../
|
|
5
|
-
import { ErrnoError, InMemory, configure, configureSingle, fs } from '../../
|
|
4
|
+
import { Port } from '../../dist/backends/port/fs.js';
|
|
5
|
+
import { ErrnoError, InMemory, configure, configureSingle, fs } from '../../dist/index.js';
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
8
|
* Tests a mis-configured PortFS using a MessageChannel
|
|
@@ -26,7 +26,7 @@ await suite('Timeout', { timeout: 1000 }, () => {
|
|
|
26
26
|
error = e;
|
|
27
27
|
}
|
|
28
28
|
assert(error! instanceof ErrnoError);
|
|
29
|
-
assert(error.code
|
|
29
|
+
assert.strictEqual(error.code, 'EIO');
|
|
30
30
|
assert(error.message.includes('RPC Failed'));
|
|
31
31
|
});
|
|
32
32
|
|
|
@@ -40,7 +40,7 @@ await suite('Timeout', { timeout: 1000 }, () => {
|
|
|
40
40
|
error = e;
|
|
41
41
|
}
|
|
42
42
|
assert(error! instanceof ErrnoError);
|
|
43
|
-
assert(error.code
|
|
43
|
+
assert.strictEqual(error.code, 'EIO');
|
|
44
44
|
assert(error.message.includes('RPC Failed'));
|
|
45
45
|
});
|
|
46
46
|
});
|
package/tests/setup/common.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { join, relative } from 'node:path';
|
|
2
2
|
import { statSync, readFileSync, readdirSync, existsSync, mkdirSync } from 'node:fs';
|
|
3
|
-
import { fs } from '../../
|
|
3
|
+
import { fs } from '../../dist/index.js';
|
|
4
4
|
|
|
5
5
|
export const data = join(import.meta.dirname, '../data');
|
|
6
6
|
|
package/tests/setup/cow+fetch.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { execSync } from 'node:child_process';
|
|
|
2
2
|
import { readFileSync } from 'node:fs';
|
|
3
3
|
import { createServer } from 'node:http';
|
|
4
4
|
import { join } from 'node:path';
|
|
5
|
-
import { configureSingle, Fetch, InMemory, Overlay } from '../../
|
|
5
|
+
import { configureSingle, Fetch, InMemory, Overlay } from '../../dist/index.js';
|
|
6
6
|
import { data, tmp } from './common.js';
|
|
7
7
|
|
|
8
8
|
const port = 26514,
|