@zenfs/core 1.3.6 → 1.4.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/dist/backends/memory.d.ts +4 -4
- package/dist/backends/memory.js +4 -4
- package/dist/backends/overlay.d.ts +5 -2
- package/dist/backends/overlay.js +7 -10
- package/dist/backends/port/fs.js +1 -4
- package/dist/config.js +4 -8
- package/dist/context.d.ts +32 -0
- package/dist/context.js +23 -0
- package/dist/credentials.d.ts +5 -5
- package/dist/credentials.js +10 -6
- package/dist/emulation/async.d.ts +90 -89
- package/dist/emulation/async.js +76 -75
- package/dist/emulation/dir.d.ts +3 -1
- package/dist/emulation/dir.js +6 -7
- package/dist/emulation/index.d.ts +1 -1
- package/dist/emulation/index.js +1 -1
- package/dist/emulation/promises.d.ts +50 -48
- package/dist/emulation/promises.js +78 -77
- package/dist/emulation/shared.d.ts +35 -8
- package/dist/emulation/shared.js +37 -11
- package/dist/emulation/sync.d.ts +63 -62
- package/dist/emulation/sync.js +72 -73
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/stats.d.ts +2 -1
- package/dist/stats.js +5 -4
- package/package.json +3 -5
- package/scripts/test.js +78 -17
- package/tests/assignment.ts +1 -1
- package/tests/common/context.test.ts +19 -0
- package/tests/{devices.test.ts → common/devices.test.ts} +3 -3
- package/tests/{handle.test.ts → common/handle.test.ts} +1 -1
- package/tests/common/mounts.test.ts +36 -0
- package/tests/{mutex.test.ts → common/mutex.test.ts} +3 -3
- package/tests/common/path.test.ts +34 -0
- package/tests/common.ts +4 -3
- package/tests/fs/dir.test.ts +11 -11
- package/tests/fs/directory.test.ts +17 -17
- package/tests/fs/errors.test.ts +29 -39
- package/tests/fs/watch.test.ts +2 -2
- package/tests/setup/context.ts +9 -0
- package/tests/setup/cow+fetch.ts +1 -1
- package/tests/setup/memory.ts +1 -1
- package/tests/{setup/common.ts → setup.ts} +6 -5
- package/src/backends/backend.ts +0 -161
- package/src/backends/fetch.ts +0 -180
- package/src/backends/file_index.ts +0 -206
- package/src/backends/memory.ts +0 -45
- package/src/backends/overlay.ts +0 -560
- package/src/backends/port/fs.ts +0 -329
- package/src/backends/port/readme.md +0 -54
- package/src/backends/port/rpc.ts +0 -167
- package/src/backends/readme.md +0 -3
- package/src/backends/store/fs.ts +0 -667
- package/src/backends/store/readme.md +0 -9
- package/src/backends/store/simple.ts +0 -154
- package/src/backends/store/store.ts +0 -189
- package/src/config.ts +0 -227
- package/src/credentials.ts +0 -49
- package/src/devices.ts +0 -521
- package/src/emulation/async.ts +0 -834
- package/src/emulation/cache.ts +0 -86
- package/src/emulation/config.ts +0 -21
- package/src/emulation/constants.ts +0 -182
- package/src/emulation/dir.ts +0 -138
- package/src/emulation/index.ts +0 -8
- package/src/emulation/path.ts +0 -440
- package/src/emulation/promises.ts +0 -1140
- package/src/emulation/shared.ts +0 -172
- package/src/emulation/streams.ts +0 -34
- package/src/emulation/sync.ts +0 -863
- package/src/emulation/watchers.ts +0 -194
- package/src/error.ts +0 -307
- package/src/file.ts +0 -631
- package/src/filesystem.ts +0 -174
- package/src/index.ts +0 -35
- package/src/inode.ts +0 -128
- package/src/mixins/async.ts +0 -230
- package/src/mixins/index.ts +0 -5
- package/src/mixins/mutexed.ts +0 -257
- package/src/mixins/readonly.ts +0 -96
- package/src/mixins/shared.ts +0 -25
- package/src/mixins/sync.ts +0 -58
- package/src/polyfills.ts +0 -21
- package/src/stats.ts +0 -405
- package/src/utils.ts +0 -276
- package/tests/mounts.test.ts +0 -18
- package/tests/path.test.ts +0 -34
package/src/mixins/mutexed.ts
DELETED
|
@@ -1,257 +0,0 @@
|
|
|
1
|
-
import { ErrnoError } from '../error.js';
|
|
2
|
-
import type { File } from '../file.js';
|
|
3
|
-
import type { FileSystem, FileSystemMetadata } from '../filesystem.js';
|
|
4
|
-
import '../polyfills.js';
|
|
5
|
-
import type { Stats } from '../stats.js';
|
|
6
|
-
import type { Concrete } from '../utils.js';
|
|
7
|
-
|
|
8
|
-
export class MutexLock {
|
|
9
|
-
protected current = Promise.withResolvers<void>();
|
|
10
|
-
|
|
11
|
-
protected _isLocked: boolean = true;
|
|
12
|
-
public get isLocked(): boolean {
|
|
13
|
-
return this._isLocked;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
public constructor(protected readonly previous?: MutexLock) {}
|
|
17
|
-
|
|
18
|
-
public async done(): Promise<void> {
|
|
19
|
-
await this.previous?.done();
|
|
20
|
-
await this.current.promise;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
public unlock(): void {
|
|
24
|
-
this.current.resolve();
|
|
25
|
-
this._isLocked = false;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
public [Symbol.dispose](): void {
|
|
29
|
-
this.unlock();
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
/**
|
|
34
|
-
* @hidden
|
|
35
|
-
*/
|
|
36
|
-
export class _MutexedFS<T extends FileSystem> implements FileSystem {
|
|
37
|
-
/**
|
|
38
|
-
* @internal
|
|
39
|
-
*/
|
|
40
|
-
public _fs!: T;
|
|
41
|
-
|
|
42
|
-
public async ready(): Promise<void> {
|
|
43
|
-
return await this._fs.ready();
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
public metadata(): FileSystemMetadata {
|
|
47
|
-
return this._fs.metadata();
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
/**
|
|
51
|
-
* The current locks
|
|
52
|
-
*/
|
|
53
|
-
private currentLock?: MutexLock;
|
|
54
|
-
|
|
55
|
-
/**
|
|
56
|
-
* Adds a lock for a path
|
|
57
|
-
*/
|
|
58
|
-
protected addLock(): MutexLock {
|
|
59
|
-
const lock = new MutexLock(this.currentLock);
|
|
60
|
-
this.currentLock = lock;
|
|
61
|
-
return lock;
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
/**
|
|
65
|
-
* Locks `path` asynchronously.
|
|
66
|
-
* If the path is currently locked, waits for it to be unlocked.
|
|
67
|
-
* @internal
|
|
68
|
-
*/
|
|
69
|
-
public async lock(path: string, syscall: string): Promise<MutexLock> {
|
|
70
|
-
const previous = this.currentLock;
|
|
71
|
-
const lock = this.addLock();
|
|
72
|
-
const stack = new Error().stack;
|
|
73
|
-
setTimeout(() => {
|
|
74
|
-
if (lock.isLocked) {
|
|
75
|
-
const error = ErrnoError.With('EDEADLK', path, syscall);
|
|
76
|
-
error.stack += stack?.slice('Error'.length);
|
|
77
|
-
throw error;
|
|
78
|
-
}
|
|
79
|
-
}, 5000);
|
|
80
|
-
await previous?.done();
|
|
81
|
-
return lock;
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
/**
|
|
85
|
-
* Locks `path` asynchronously.
|
|
86
|
-
* If the path is currently locked, an error will be thrown
|
|
87
|
-
* @internal
|
|
88
|
-
*/
|
|
89
|
-
public lockSync(path: string, syscall: string): MutexLock {
|
|
90
|
-
if (this.currentLock?.isLocked) {
|
|
91
|
-
throw ErrnoError.With('EBUSY', path, syscall);
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
return this.addLock();
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
/**
|
|
98
|
-
* Whether `path` is locked
|
|
99
|
-
* @internal
|
|
100
|
-
*/
|
|
101
|
-
public get isLocked(): boolean {
|
|
102
|
-
return !!this.currentLock?.isLocked;
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
/* eslint-disable @typescript-eslint/no-unused-vars */
|
|
106
|
-
public async rename(oldPath: string, newPath: string): Promise<void> {
|
|
107
|
-
using _ = await this.lock(oldPath, 'rename');
|
|
108
|
-
await this._fs.rename(oldPath, newPath);
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
public renameSync(oldPath: string, newPath: string): void {
|
|
112
|
-
using _ = this.lockSync(oldPath, 'rename');
|
|
113
|
-
return this._fs.renameSync(oldPath, newPath);
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
public async stat(path: string): Promise<Stats> {
|
|
117
|
-
using _ = await this.lock(path, 'stat');
|
|
118
|
-
return await this._fs.stat(path);
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
public statSync(path: string): Stats {
|
|
122
|
-
using _ = this.lockSync(path, 'stat');
|
|
123
|
-
return this._fs.statSync(path);
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
public async openFile(path: string, flag: string): Promise<File> {
|
|
127
|
-
using _ = await this.lock(path, 'openFile');
|
|
128
|
-
const file = await this._fs.openFile(path, flag);
|
|
129
|
-
file.fs = this;
|
|
130
|
-
return file;
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
public openFileSync(path: string, flag: string): File {
|
|
134
|
-
using _ = this.lockSync(path, 'openFile');
|
|
135
|
-
const file = this._fs.openFileSync(path, flag);
|
|
136
|
-
file.fs = this;
|
|
137
|
-
return file;
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
public async createFile(path: string, flag: string, mode: number): Promise<File> {
|
|
141
|
-
using _ = await this.lock(path, 'createFile');
|
|
142
|
-
const file = await this._fs.createFile(path, flag, mode);
|
|
143
|
-
file.fs = this;
|
|
144
|
-
return file;
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
public createFileSync(path: string, flag: string, mode: number): File {
|
|
148
|
-
using _ = this.lockSync(path, 'createFile');
|
|
149
|
-
const file = this._fs.createFileSync(path, flag, mode);
|
|
150
|
-
file.fs = this;
|
|
151
|
-
return file;
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
public async unlink(path: string): Promise<void> {
|
|
155
|
-
using _ = await this.lock(path, 'unlink');
|
|
156
|
-
await this._fs.unlink(path);
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
public unlinkSync(path: string): void {
|
|
160
|
-
using _ = this.lockSync(path, 'unlink');
|
|
161
|
-
return this._fs.unlinkSync(path);
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
public async rmdir(path: string): Promise<void> {
|
|
165
|
-
using _ = await this.lock(path, 'rmdir');
|
|
166
|
-
await this._fs.rmdir(path);
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
public rmdirSync(path: string): void {
|
|
170
|
-
using _ = this.lockSync(path, 'rmdir');
|
|
171
|
-
return this._fs.rmdirSync(path);
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
public async mkdir(path: string, mode: number): Promise<void> {
|
|
175
|
-
using _ = await this.lock(path, 'mkdir');
|
|
176
|
-
await this._fs.mkdir(path, mode);
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
public mkdirSync(path: string, mode: number): void {
|
|
180
|
-
using _ = this.lockSync(path, 'mkdir');
|
|
181
|
-
return this._fs.mkdirSync(path, mode);
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
public async readdir(path: string): Promise<string[]> {
|
|
185
|
-
using _ = await this.lock(path, 'readdir');
|
|
186
|
-
return await this._fs.readdir(path);
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
public readdirSync(path: string): string[] {
|
|
190
|
-
using _ = this.lockSync(path, 'readdir');
|
|
191
|
-
return this._fs.readdirSync(path);
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
public async exists(path: string): Promise<boolean> {
|
|
195
|
-
using _ = await this.lock(path, 'exists');
|
|
196
|
-
return await this._fs.exists(path);
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
public existsSync(path: string): boolean {
|
|
200
|
-
using _ = this.lockSync(path, 'exists');
|
|
201
|
-
return this._fs.existsSync(path);
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
public async link(srcpath: string, dstpath: string): Promise<void> {
|
|
205
|
-
using _ = await this.lock(srcpath, 'link');
|
|
206
|
-
await this._fs.link(srcpath, dstpath);
|
|
207
|
-
}
|
|
208
|
-
|
|
209
|
-
public linkSync(srcpath: string, dstpath: string): void {
|
|
210
|
-
using _ = this.lockSync(srcpath, 'link');
|
|
211
|
-
return this._fs.linkSync(srcpath, dstpath);
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
public async sync(path: string, data: Uint8Array, stats: Readonly<Stats>): Promise<void> {
|
|
215
|
-
using _ = await this.lock(path, 'sync');
|
|
216
|
-
await this._fs.sync(path, data, stats);
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
public syncSync(path: string, data: Uint8Array, stats: Readonly<Stats>): void {
|
|
220
|
-
using _ = this.lockSync(path, 'sync');
|
|
221
|
-
return this._fs.syncSync(path, data, stats);
|
|
222
|
-
}
|
|
223
|
-
/* eslint-enable @typescript-eslint/no-unused-vars */
|
|
224
|
-
}
|
|
225
|
-
|
|
226
|
-
/**
|
|
227
|
-
* This serializes access to an underlying async filesystem.
|
|
228
|
-
* For example, on an OverlayFS instance with an async lower
|
|
229
|
-
* directory operations like rename and rmdir may involve multiple
|
|
230
|
-
* requests involving both the upper and lower file systems -- they
|
|
231
|
-
* are not executed in a single atomic step. OverlayFS uses this
|
|
232
|
-
* to avoid having to reason about the correctness of
|
|
233
|
-
* multiple requests interleaving.
|
|
234
|
-
*
|
|
235
|
-
* @privateRemarks
|
|
236
|
-
* Instead of extending the passed class, `MutexedFS` stores it internally.
|
|
237
|
-
* This is to avoid a deadlock caused when a method calls another one
|
|
238
|
-
* The problem is discussed extensively in [#78](https://github.com/zen-fs/core/issues/78)
|
|
239
|
-
* Instead of extending `FileSystem`,
|
|
240
|
-
* `MutexedFS` implements it in order to make sure all of the methods are passed through
|
|
241
|
-
*
|
|
242
|
-
* @todo Change `using _` to `using void` pending https://github.com/tc39/proposal-discard-binding
|
|
243
|
-
* @internal
|
|
244
|
-
*/
|
|
245
|
-
export function Mutexed<const T extends Concrete<typeof FileSystem>>(
|
|
246
|
-
FS: T
|
|
247
|
-
): typeof _MutexedFS<InstanceType<T>> & {
|
|
248
|
-
new (...args: ConstructorParameters<T>): _MutexedFS<InstanceType<T>>;
|
|
249
|
-
} {
|
|
250
|
-
class MutexedFS extends _MutexedFS<InstanceType<T>> {
|
|
251
|
-
public constructor(...args: ConstructorParameters<T>) {
|
|
252
|
-
super();
|
|
253
|
-
this._fs = new FS(...args) as InstanceType<T>;
|
|
254
|
-
}
|
|
255
|
-
}
|
|
256
|
-
return MutexedFS;
|
|
257
|
-
}
|
package/src/mixins/readonly.ts
DELETED
|
@@ -1,96 +0,0 @@
|
|
|
1
|
-
import { Errno, ErrnoError } from '../error.js';
|
|
2
|
-
import type { File } from '../file.js';
|
|
3
|
-
import type { FileSystem, FileSystemMetadata } from '../filesystem.js';
|
|
4
|
-
import type { Stats } from '../stats.js';
|
|
5
|
-
import type { Mixin } from './shared.js';
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Implements the non-readonly methods to throw `EROFS`
|
|
9
|
-
*/
|
|
10
|
-
/* eslint-disable @typescript-eslint/require-await */
|
|
11
|
-
export function Readonly<T extends typeof FileSystem>(
|
|
12
|
-
FS: T
|
|
13
|
-
): Mixin<
|
|
14
|
-
T,
|
|
15
|
-
{
|
|
16
|
-
metadata(): FileSystemMetadata;
|
|
17
|
-
rename(oldPath: string, newPath: string): Promise<void>;
|
|
18
|
-
renameSync(oldPath: string, newPath: string): void;
|
|
19
|
-
createFile(path: string, flag: string, mode: number): Promise<File>;
|
|
20
|
-
createFileSync(path: string, flag: string, mode: number): File;
|
|
21
|
-
unlink(path: string): Promise<void>;
|
|
22
|
-
unlinkSync(path: string): void;
|
|
23
|
-
rmdir(path: string): Promise<void>;
|
|
24
|
-
rmdirSync(path: string): void;
|
|
25
|
-
mkdir(path: string, mode: number): Promise<void>;
|
|
26
|
-
mkdirSync(path: string, mode: number): void;
|
|
27
|
-
link(srcpath: string, dstpath: string): Promise<void>;
|
|
28
|
-
linkSync(srcpath: string, dstpath: string): void;
|
|
29
|
-
sync(path: string, data: Uint8Array, stats: Readonly<Stats>): Promise<void>;
|
|
30
|
-
syncSync(path: string, data: Uint8Array, stats: Readonly<Stats>): void;
|
|
31
|
-
}
|
|
32
|
-
> {
|
|
33
|
-
abstract class ReadonlyFS extends FS {
|
|
34
|
-
public metadata(): FileSystemMetadata {
|
|
35
|
-
return { ...super.metadata(), readonly: true };
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
public async rename(): Promise<void> {
|
|
39
|
-
throw new ErrnoError(Errno.EROFS);
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
public renameSync(): void {
|
|
43
|
-
throw new ErrnoError(Errno.EROFS);
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
public async createFile(): Promise<File> {
|
|
47
|
-
throw new ErrnoError(Errno.EROFS);
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
public createFileSync(): File {
|
|
51
|
-
throw new ErrnoError(Errno.EROFS);
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
public async unlink(): Promise<void> {
|
|
55
|
-
throw new ErrnoError(Errno.EROFS);
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
public unlinkSync(): void {
|
|
59
|
-
throw new ErrnoError(Errno.EROFS);
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
public async rmdir(): Promise<void> {
|
|
63
|
-
throw new ErrnoError(Errno.EROFS);
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
public rmdirSync(): void {
|
|
67
|
-
throw new ErrnoError(Errno.EROFS);
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
public async mkdir(): Promise<void> {
|
|
71
|
-
throw new ErrnoError(Errno.EROFS);
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
public mkdirSync(): void {
|
|
75
|
-
throw new ErrnoError(Errno.EROFS);
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
public async link(): Promise<void> {
|
|
79
|
-
throw new ErrnoError(Errno.EROFS);
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
public linkSync(): void {
|
|
83
|
-
throw new ErrnoError(Errno.EROFS);
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
public async sync(): Promise<void> {
|
|
87
|
-
throw new ErrnoError(Errno.EROFS);
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
public syncSync(): void {
|
|
91
|
-
throw new ErrnoError(Errno.EROFS);
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
return ReadonlyFS;
|
|
95
|
-
}
|
|
96
|
-
/* eslint-enable @typescript-eslint/require-await */
|
package/src/mixins/shared.ts
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
2
|
-
/*
|
|
3
|
-
Code shared by various mixins
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
import type { ExtractProperties } from 'utilium';
|
|
7
|
-
import type { FileSystem } from '../filesystem.js';
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* `TBase` with `TMixin` mixed-in.
|
|
11
|
-
* @internal
|
|
12
|
-
*/
|
|
13
|
-
export type Mixin<TBase extends typeof FileSystem, TMixin> = (abstract new (...args: any[]) => TMixin) & TBase;
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* Asynchronous `FileSystem` methods. This is a convenience type.
|
|
17
|
-
* @internal
|
|
18
|
-
*/
|
|
19
|
-
export type AsyncFSMethods = ExtractProperties<FileSystem, (...args: any[]) => Promise<unknown>>;
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* Concrete `FileSystem`. This is a convenience type.
|
|
23
|
-
* @internal
|
|
24
|
-
*/
|
|
25
|
-
export type ConcreteFS = ExtractProperties<FileSystem, any>;
|
package/src/mixins/sync.ts
DELETED
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
import type { File } from '../file.js';
|
|
2
|
-
import type { FileSystem } from '../filesystem.js';
|
|
3
|
-
import type { Stats } from '../stats.js';
|
|
4
|
-
import type { Mixin, AsyncFSMethods } from './shared.js';
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Implements the asynchronous API in terms of the synchronous API.
|
|
8
|
-
*/
|
|
9
|
-
/* eslint-disable @typescript-eslint/require-await */
|
|
10
|
-
export function Sync<T extends typeof FileSystem>(FS: T): Mixin<T, AsyncFSMethods> {
|
|
11
|
-
abstract class SyncFS extends FS implements AsyncFSMethods {
|
|
12
|
-
public async exists(path: string): Promise<boolean> {
|
|
13
|
-
return this.existsSync(path);
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
public async rename(oldPath: string, newPath: string): Promise<void> {
|
|
17
|
-
return this.renameSync(oldPath, newPath);
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
public async stat(path: string): Promise<Stats> {
|
|
21
|
-
return this.statSync(path);
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
public async createFile(path: string, flag: string, mode: number): Promise<File> {
|
|
25
|
-
return this.createFileSync(path, flag, mode);
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
public async openFile(path: string, flag: string): Promise<File> {
|
|
29
|
-
return this.openFileSync(path, flag);
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
public async unlink(path: string): Promise<void> {
|
|
33
|
-
return this.unlinkSync(path);
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
public async rmdir(path: string): Promise<void> {
|
|
37
|
-
return this.rmdirSync(path);
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
public async mkdir(path: string, mode: number): Promise<void> {
|
|
41
|
-
return this.mkdirSync(path, mode);
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
public async readdir(path: string): Promise<string[]> {
|
|
45
|
-
return this.readdirSync(path);
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
public async link(srcpath: string, dstpath: string): Promise<void> {
|
|
49
|
-
return this.linkSync(srcpath, dstpath);
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
public async sync(path: string, data: Uint8Array, stats: Readonly<Stats>): Promise<void> {
|
|
53
|
-
return this.syncSync(path, data, stats);
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
return SyncFS;
|
|
57
|
-
}
|
|
58
|
-
/* eslint-enable @typescript-eslint/require-await */
|
package/src/polyfills.ts
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
// eslint-disable-next-line @typescript-eslint/unbound-method
|
|
2
|
-
Promise.withResolvers ??= function <T>(): PromiseWithResolvers<T> {
|
|
3
|
-
let _resolve: ((value: T | PromiseLike<T>) => void) | undefined,
|
|
4
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
5
|
-
_reject: ((reason?: any) => void) | undefined;
|
|
6
|
-
const promise = new Promise<T>((resolve, reject) => {
|
|
7
|
-
_resolve = resolve;
|
|
8
|
-
_reject = reject;
|
|
9
|
-
});
|
|
10
|
-
return { promise, resolve: _resolve!, reject: _reject! };
|
|
11
|
-
};
|
|
12
|
-
|
|
13
|
-
/*
|
|
14
|
-
A polyfill for when these symbols are undefined.
|
|
15
|
-
For some reason, NodeJS does not polyfill them in a VM context.
|
|
16
|
-
Since jest uses a VM context for ESM, these need to be here.
|
|
17
|
-
*/
|
|
18
|
-
// @ts-expect-error 2540
|
|
19
|
-
Symbol['dispose'] ??= Symbol('Symbol.dispose');
|
|
20
|
-
// @ts-expect-error 2540
|
|
21
|
-
Symbol['asyncDispose'] ??= Symbol('Symbol.asyncDispose');
|