@zenfs/core 2.4.1 → 2.4.3

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.
Files changed (101) hide show
  1. package/COPYING.md +24 -0
  2. package/{readme.md → README.md} +16 -74
  3. package/dist/backends/backend.d.ts +1 -1
  4. package/dist/backends/fetch.js +1 -1
  5. package/dist/backends/memory.js +1 -1
  6. package/dist/backends/passthrough.d.ts +1 -2
  7. package/dist/backends/single_buffer.d.ts +1 -1
  8. package/dist/backends/single_buffer.js +27 -24
  9. package/dist/backends/store/fs.js +4 -4
  10. package/dist/config.js +15 -15
  11. package/dist/context.js +3 -2
  12. package/dist/index.d.ts +9 -3
  13. package/dist/index.js +9 -4
  14. package/dist/internal/contexts.d.ts +5 -4
  15. package/dist/internal/devices.js +1 -1
  16. package/dist/internal/error.d.ts +11 -2
  17. package/dist/internal/error.js +38 -2
  18. package/dist/internal/file_index.js +1 -1
  19. package/dist/internal/index.d.ts +1 -0
  20. package/dist/internal/index.js +2 -1
  21. package/dist/internal/index_fs.js +1 -1
  22. package/dist/internal/inode.d.ts +51 -2
  23. package/dist/internal/inode.js +18 -2
  24. package/dist/mixins/shared.js +1 -1
  25. package/dist/node/async.d.ts +278 -0
  26. package/dist/node/async.js +518 -0
  27. package/dist/node/compat.d.ts +4 -0
  28. package/dist/node/compat.js +6 -0
  29. package/dist/node/dir.d.ts +78 -0
  30. package/dist/node/dir.js +150 -0
  31. package/dist/node/index.d.ts +8 -0
  32. package/dist/node/index.js +8 -0
  33. package/dist/{vfs → node}/promises.d.ts +10 -66
  34. package/dist/{vfs → node}/promises.js +141 -478
  35. package/dist/{vfs → node}/stats.d.ts +0 -4
  36. package/dist/{vfs → node}/stats.js +1 -16
  37. package/dist/{vfs → node}/streams.js +2 -2
  38. package/dist/node/sync.d.ts +252 -0
  39. package/dist/node/sync.js +682 -0
  40. package/dist/node/types.d.ts +21 -0
  41. package/dist/utils.d.ts +1 -7
  42. package/dist/utils.js +0 -6
  43. package/dist/vfs/acl.js +1 -1
  44. package/dist/vfs/async.d.ts +22 -278
  45. package/dist/vfs/async.js +212 -501
  46. package/dist/vfs/dir.d.ts +5 -82
  47. package/dist/vfs/dir.js +5 -233
  48. package/dist/vfs/file.d.ts +52 -13
  49. package/dist/vfs/file.js +167 -25
  50. package/dist/vfs/flags.js +1 -1
  51. package/dist/vfs/index.d.ts +2 -5
  52. package/dist/vfs/index.js +2 -5
  53. package/dist/vfs/shared.d.ts +25 -1
  54. package/dist/vfs/shared.js +6 -4
  55. package/dist/vfs/sync.d.ts +17 -245
  56. package/dist/vfs/sync.js +129 -773
  57. package/dist/vfs/watchers.d.ts +1 -1
  58. package/dist/vfs/watchers.js +2 -2
  59. package/dist/vfs/xattr.js +1 -1
  60. package/eslint.shared.js +1 -0
  61. package/package.json +7 -5
  62. package/scripts/make-index.js +5 -29
  63. package/scripts/test.js +59 -51
  64. package/tests/backend/fetch.test.ts +2 -2
  65. package/tests/backend/port.test.ts +2 -3
  66. package/tests/backend/single-buffer.test.ts +48 -1
  67. package/tests/common/casefold.test.ts +1 -1
  68. package/tests/common/context.test.ts +11 -4
  69. package/tests/common/devices.test.ts +3 -3
  70. package/tests/common/handle.test.ts +4 -3
  71. package/tests/common/inode.test.ts +2 -2
  72. package/tests/common/mounts.test.ts +1 -3
  73. package/tests/common/mutex.test.ts +1 -3
  74. package/tests/common/path.test.ts +2 -2
  75. package/tests/common/readline.test.ts +1 -1
  76. package/tests/common.ts +5 -4
  77. package/tests/fetch/fetch.ts +1 -1
  78. package/tests/fs/dir.test.ts +3 -43
  79. package/tests/fs/directory.test.ts +4 -4
  80. package/tests/fs/errors.test.ts +2 -2
  81. package/tests/fs/links.test.ts +1 -1
  82. package/tests/fs/permissions.test.ts +3 -3
  83. package/tests/fs/read.test.ts +1 -1
  84. package/tests/fs/scaling.test.ts +1 -1
  85. package/tests/fs/stat.test.ts +1 -2
  86. package/tests/fs/times.test.ts +1 -1
  87. package/tests/fs/watch.test.ts +3 -2
  88. package/tests/setup/context.ts +1 -2
  89. package/tests/setup/cow.ts +1 -1
  90. package/tests/setup/index.ts +2 -2
  91. package/tests/setup/port.ts +1 -1
  92. package/tests/setup/single-buffer.ts +1 -1
  93. package/tests/setup.ts +4 -3
  94. package/dist/vfs/types.d.ts +0 -24
  95. package/tests/assignment.ts +0 -21
  96. /package/dist/{vfs/constants.d.ts → constants.d.ts} +0 -0
  97. /package/dist/{vfs/constants.js → constants.js} +0 -0
  98. /package/dist/{readline.d.ts → node/readline.d.ts} +0 -0
  99. /package/dist/{readline.js → node/readline.js} +0 -0
  100. /package/dist/{vfs → node}/streams.d.ts +0 -0
  101. /package/dist/{vfs → node}/types.js +0 -0
@@ -1,7 +1,8 @@
1
1
  // SPDX-License-Identifier: LGPL-3.0-or-later
2
+ import { sync, type Dirent } from '@zenfs/core';
2
3
  import assert, { rejects } from 'node:assert/strict';
3
4
  import { suite, test } from 'node:test';
4
- import { fs, type Dirent } from '../common.js';
5
+ import { fs } from '../common.js';
5
6
 
6
7
  const testFile = 'test-file.txt';
7
8
  fs.writeFileSync(testFile, 'Sample content');
@@ -13,48 +14,7 @@ fs.mkdirSync(testDirPath);
13
14
  for (const file of testFiles) {
14
15
  fs.writeFileSync(`${testDirPath}/${file}`, 'Sample content');
15
16
  }
16
-
17
- suite('Dirent', () => {
18
- test('name and parentPath getters', async () => {
19
- const stats = await fs.promises.lstat(testFile);
20
- const dirent = fs.Dirent.from(testFile, stats);
21
-
22
- assert.equal(dirent.name, testFile);
23
- assert.equal(dirent.parentPath, '.');
24
- });
25
-
26
- test('isFile', async () => {
27
- const fileStats = await fs.promises.lstat(testFile);
28
- const fileDirent = fs.Dirent.from(testFile, fileStats);
29
-
30
- assert(fileDirent.isFile());
31
- assert(!fileDirent.isDirectory());
32
- });
33
-
34
- test('isDirectory', async () => {
35
- const dirStats = await fs.promises.lstat('test-directory');
36
- const dirDirent = fs.Dirent.from('test-directory', dirStats);
37
-
38
- assert(!dirDirent.isFile());
39
- assert(dirDirent.isDirectory());
40
- });
41
-
42
- test('isSymbolicLink', async () => {
43
- const symlinkStats = await fs.promises.lstat('test-symlink');
44
- const symlinkDirent = fs.Dirent.from('test-symlink', symlinkStats);
45
-
46
- assert(symlinkDirent.isSymbolicLink());
47
- });
48
-
49
- test('other methods return false', async () => {
50
- const fileStats = await fs.promises.lstat(testFile);
51
- const fileDirent = fs.Dirent.from(testFile, fileStats);
52
-
53
- assert(!fileDirent.isBlockDevice());
54
- assert(!fileDirent.isCharacterDevice());
55
- assert(!fileDirent.isSocket());
56
- });
57
- });
17
+ await sync();
58
18
 
59
19
  suite('Dir', () => {
60
20
  test('read()', async () => {
@@ -29,7 +29,7 @@ suite('Directories', () => {
29
29
  test('mkdirSync', async () => await fs.promises.mkdir('/two', 0o000));
30
30
 
31
31
  test('mkdir, nested', async () => {
32
- await assert.rejects(fs.promises.mkdir('/nested/dir'), { code: 'ENOENT', path: '/nested' });
32
+ await assert.rejects(fs.promises.mkdir('/nested/dir'), { code: 'ENOENT', path: '/nested/dir' });
33
33
  assert(!(await fs.promises.exists('/nested/dir')));
34
34
  });
35
35
 
@@ -148,9 +148,9 @@ suite('Directories', () => {
148
148
  entries.sort((a, b) => join(a.parentPath, a.name).localeCompare(join(b.parentPath, b.name)));
149
149
  const values = entries.map(entry => [entry.parentPath, entry.name]);
150
150
 
151
- assert.deepEqual(values[0], [testDir, 'file1.txt']);
152
- assert.deepEqual(values[4], [join(testDir, 'subdir1'), 'file4.txt']);
153
- assert.deepEqual(values[8], [join(testDir, 'subdir2'), 'file5.txt']);
151
+ assert.deepEqual(values[0], ['.', 'file1.txt']);
152
+ assert.deepEqual(values[4], ['subdir1', 'file4.txt']);
153
+ assert.deepEqual(values[8], ['subdir2', 'file5.txt']);
154
154
  });
155
155
 
156
156
  test('readdirSync returns files recursively', () => {
@@ -20,7 +20,7 @@ suite('Error messages', () => {
20
20
  test('open', async () => await assert.rejects(() => fs.promises.open(path, 'r'), missing));
21
21
  test('readdir', async () => await assert.rejects(() => fs.promises.readdir(path), missing));
22
22
  test('unlink', async () => await assert.rejects(() => fs.promises.unlink(path), missing));
23
- test('link', async () => await assert.rejects(() => fs.promises.link(path, 'foo'), missing));
23
+ test('link', async () => await assert.rejects(() => fs.promises.link(path, 'foo'), { code: 'ENOENT', path: '/foo' }));
24
24
  test('chmod', async () => await assert.rejects(() => fs.promises.chmod(path, 0o666), missing));
25
25
  test('lstat', async () => await assert.rejects(() => fs.promises.lstat(path), missing));
26
26
  test('readlink', async () => await assert.rejects(() => fs.promises.readlink(path), missing));
@@ -32,7 +32,7 @@ suite('Error messages', () => {
32
32
  test('openSync', () => assert.throws(() => fs.openSync(path, 'r'), missing));
33
33
  test('readdirSync', () => assert.throws(() => fs.readdirSync(path), missing));
34
34
  test('unlinkSync', () => assert.throws(() => fs.unlinkSync(path), missing));
35
- test('linkSync', () => assert.throws(() => fs.linkSync(path, 'foo'), missing));
35
+ test('linkSync', () => assert.throws(() => fs.linkSync(path, 'foo'), { code: 'ENOENT', path: '/foo' }));
36
36
  test('chmodSync', () => assert.throws(() => fs.chmodSync(path, 0o666), missing));
37
37
  test('lstatSync', () => assert.throws(() => fs.lstatSync(path), missing));
38
38
  test('readlinkSync', () => assert.throws(() => fs.readlinkSync(path), missing));
@@ -1,8 +1,8 @@
1
1
  // SPDX-License-Identifier: LGPL-3.0-or-later
2
+ import { join } from '@zenfs/core/path';
2
3
  import type { Exception } from 'kerium';
3
4
  import assert from 'node:assert/strict';
4
5
  import { suite, test } from 'node:test';
5
- import { join } from '../../dist/path.js';
6
6
  import { fs } from '../common.js';
7
7
 
8
8
  suite('Links', () => {
@@ -3,9 +3,9 @@ import { Exception } from 'kerium';
3
3
  import assert from 'node:assert/strict';
4
4
  import { suite, test } from 'node:test';
5
5
  import { encodeUTF8 } from 'utilium';
6
- import { defaultContext } from '../../dist/internal/contexts.js';
7
- import { join } from '../../dist/path.js';
8
- import { R_OK, W_OK, X_OK } from '../../dist/vfs/constants.js';
6
+ import { defaultContext } from '@zenfs/core/internal/contexts.js';
7
+ import { join } from '@zenfs/core/path';
8
+ import { R_OK, W_OK, X_OK } from '@zenfs/core/constants';
9
9
  import { fs } from '../common.js';
10
10
 
11
11
  const asyncMode = 0o777;
@@ -1,10 +1,10 @@
1
1
  // SPDX-License-Identifier: LGPL-3.0-or-later
2
+ import { sync } from '@zenfs/core';
2
3
  import { Buffer } from 'buffer';
3
4
  import assert from 'node:assert/strict';
4
5
  import type { OpenMode, PathLike } from 'node:fs';
5
6
  import { suite, test } from 'node:test';
6
7
  import { promisify } from 'node:util';
7
- import { sync } from '../../dist/config.js';
8
8
  import { fs } from '../common.js';
9
9
 
10
10
  const filepath = 'x.txt';
@@ -1,7 +1,7 @@
1
1
  // SPDX-License-Identifier: LGPL-3.0-or-later
2
+ import { sync } from '@zenfs/core';
2
3
  import assert from 'node:assert/strict';
3
4
  import { suite, test } from 'node:test';
4
- import { sync } from '../../dist/config.js';
5
5
  import { fs } from '../common.js';
6
6
 
7
7
  const n_files = 130;
@@ -1,8 +1,7 @@
1
1
  // SPDX-License-Identifier: LGPL-3.0-or-later
2
+ import { defaultContext, Stats } from '@zenfs/core';
2
3
  import assert from 'node:assert/strict';
3
4
  import { suite, test } from 'node:test';
4
- import { defaultContext } from '../../dist/internal/contexts.js';
5
- import { Stats } from '../../dist/vfs/stats.js';
6
5
  import { fs } from '../common.js';
7
6
 
8
7
  suite('Stats', () => {
@@ -1,9 +1,9 @@
1
1
  // SPDX-License-Identifier: LGPL-3.0-or-later
2
+ import type { StatsLike } from '@zenfs/core';
2
3
  import { Exception } from 'kerium';
3
4
  import assert from 'node:assert/strict';
4
5
  import { suite, test } from 'node:test';
5
6
  import { wait } from 'utilium';
6
- import type { StatsLike } from '../../dist/vfs/stats.js';
7
7
  import { fs } from '../common.js';
8
8
 
9
9
  const path = 'x.txt';
@@ -1,7 +1,8 @@
1
1
  // SPDX-License-Identifier: LGPL-3.0-or-later
2
+ import type { Stats } from '@zenfs/core';
2
3
  import assert from 'node:assert/strict';
3
4
  import { suite, test } from 'node:test';
4
- import { fs, type Stats } from '../common.js';
5
+ import { fs } from '../common.js';
5
6
 
6
7
  const testDir = '/test-watch-dir';
7
8
  const testFile = testDir + '/test.txt';
@@ -12,7 +13,7 @@ await fs.promises.writeFile(testFile, 'Initial content');
12
13
  /**
13
14
  * @todo convert `using watcher = ...` to void discards pending ES proposal
14
15
  */
15
- suite('Watch', async () => {
16
+ suite('Watch', () => {
16
17
  test('Events emitted on file change', async () => {
17
18
  const { promise, resolve } = Promise.withResolvers<[string, string]>();
18
19
 
@@ -1,5 +1,4 @@
1
- import { bindContext } from '../../dist/context.js';
2
- import { fs as _fs } from '../../dist/index.js';
1
+ import { fs as _fs, bindContext } from '@zenfs/core';
3
2
  import { copySync, data } from '../setup.js';
4
3
 
5
4
  _fs.mkdirSync('/new_root');
@@ -1,4 +1,4 @@
1
- import { configureSingle, InMemory, CopyOnWrite, resolveMountConfig, fs } from '../../dist/index.js';
1
+ import { configureSingle, CopyOnWrite, fs, InMemory, resolveMountConfig } from '@zenfs/core';
2
2
  import { copySync, data } from '../setup.js';
3
3
 
4
4
  fs.umount('/');
@@ -1,7 +1,7 @@
1
1
  import { readFileSync } from 'node:fs';
2
2
  import { join } from 'node:path/posix';
3
- import { configureSingle, CopyOnWrite, InMemory, InMemoryStore, mounts, Readonly, StoreFS } from '../../dist/index.js';
4
- import { S_IFDIR } from '../../dist/vfs/constants.js';
3
+ import { configureSingle, CopyOnWrite, InMemory, InMemoryStore, mounts, Readonly, StoreFS } from '@zenfs/core';
4
+ import { S_IFDIR } from '@zenfs/core/constants';
5
5
  import { copySync, data } from '../setup.js';
6
6
 
7
7
  copySync(data);
@@ -1,6 +1,6 @@
1
+ import { InMemory, Port, configureSingle, fs, resolveMountConfig, resolveRemoteMount, sync } from '@zenfs/core';
1
2
  import { after, afterEach } from 'node:test';
2
3
  import { MessageChannel } from 'node:worker_threads';
3
- import { InMemory, Port, configureSingle, fs, resolveMountConfig, resolveRemoteMount, sync } from '../../dist/index.js';
4
4
  import { copySync, data } from '../setup.js';
5
5
 
6
6
  const { port1: localPort, port2: remotePort } = new MessageChannel();
@@ -1,4 +1,4 @@
1
- import { SingleBuffer, configureSingle } from '../../dist/index.js';
1
+ import { SingleBuffer, configureSingle } from '@zenfs/core';
2
2
  import { copySync, data } from '../setup.js';
3
3
 
4
4
  await configureSingle({
package/tests/setup.ts CHANGED
@@ -1,7 +1,8 @@
1
1
  // SPDX-License-Identifier: LGPL-3.0-or-later
2
+ import { fs as _fs } from '@zenfs/core';
2
3
  import { existsSync, mkdirSync, readFileSync, readdirSync, statSync } from 'node:fs';
3
4
  import { join, relative } from 'node:path';
4
- import { fs as _fs } from '../dist/index.js';
5
+ import type { NodeFS } from '@zenfs/core/node/types.js';
5
6
 
6
7
  export const data = join(import.meta.dirname, 'data');
7
8
 
@@ -9,7 +10,7 @@ export const tmp = join(import.meta.dirname, 'tmp');
9
10
 
10
11
  if (!existsSync(tmp)) mkdirSync(tmp);
11
12
 
12
- export async function copyAsync(_path: string, fs: typeof _fs = _fs): Promise<void> {
13
+ export async function copyAsync(_path: string, fs: NodeFS = _fs): Promise<void> {
13
14
  const path = relative(data, _path) || '/';
14
15
  const stats = statSync(_path);
15
16
 
@@ -26,7 +27,7 @@ export async function copyAsync(_path: string, fs: typeof _fs = _fs): Promise<vo
26
27
  }
27
28
  }
28
29
 
29
- export function copySync(_path: string, fs: typeof _fs = _fs): void {
30
+ export function copySync(_path: string, fs: NodeFS = _fs): void {
30
31
  const path = relative(data, _path) || '/';
31
32
  const stats = statSync(_path);
32
33
 
@@ -1,24 +0,0 @@
1
- import type * as fs from 'node:fs';
2
- export type FileContents = ArrayBufferView | string;
3
- /**
4
- * @internal @hidden Used for the internal `_open` functions
5
- */
6
- export interface OpenOptions {
7
- flag: fs.OpenMode;
8
- mode?: fs.Mode | null;
9
- /**
10
- * If true, do not resolve symlinks
11
- */
12
- preserveSymlinks?: boolean;
13
- /**
14
- * If true, allows opening directories
15
- */
16
- allowDirectory?: boolean;
17
- }
18
- export type ReaddirOptions = {
19
- withFileTypes?: boolean;
20
- recursive?: boolean;
21
- encoding?: BufferEncoding | 'buffer' | null;
22
- } | BufferEncoding | 'buffer' | null;
23
- /** Helper union @hidden */
24
- export type GlobOptionsU = fs.GlobOptionsWithFileTypes | fs.GlobOptionsWithoutFileTypes | fs.GlobOptions;
@@ -1,21 +0,0 @@
1
- // SPDX-License-Identifier: LGPL-3.0-or-later
2
- /* eslint-disable @typescript-eslint/no-unused-vars */
3
-
4
- /*
5
- This test assigns the exported fs module from ZenFS with the one exported from Node.
6
- This ensures anything new that is added will be caught
7
-
8
- Notes on omissions and exclusions:
9
- - __promisify__ is omitted as it is metadata
10
- - native is omitted as zenfs isn't native
11
- - ReadStream and WriteStream are excluded since they are polyfilled from another module
12
- */
13
-
14
- import type * as node from 'node:fs';
15
- import { fs as zen } from '../src/index.js';
16
-
17
- type Mock = {
18
- [K in Exclude<keyof typeof node, 'ReadStream' | 'WriteStream'>]: Omit<(typeof node)[K], '__promisify__' | 'native'>;
19
- };
20
-
21
- const _module: Mock = zen;
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes