@zenfs/core 0.5.6 → 0.5.7
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/browser.min.js +3 -3
- package/dist/browser.min.js.map +3 -3
- package/dist/emulation/async.d.ts +1 -1
- package/dist/emulation/async.js +24 -19
- package/dist/emulation/promises.d.ts +4 -4
- package/dist/emulation/promises.js +10 -7
- package/dist/emulation/sync.js +2 -0
- package/package.json +6 -4
- package/scripts/build.js +82 -0
- package/scripts/make-index.js +4 -6
|
@@ -104,7 +104,7 @@ export declare function readFile(filename: PathLike, cb: TwoArgCallback<Uint8Arr
|
|
|
104
104
|
export declare function readFile(filename: PathLike, options: {
|
|
105
105
|
flag?: string;
|
|
106
106
|
}, callback?: TwoArgCallback<Uint8Array>): void;
|
|
107
|
-
export declare function readFile(filename: PathLike,
|
|
107
|
+
export declare function readFile(filename: PathLike, options: {
|
|
108
108
|
encoding: BufferEncoding;
|
|
109
109
|
flag?: string;
|
|
110
110
|
} | BufferEncoding, cb: TwoArgCallback<string>): void;
|
package/dist/emulation/async.js
CHANGED
|
@@ -47,9 +47,9 @@ export function lstat(path, options, callback = nop) {
|
|
|
47
47
|
.catch(callback);
|
|
48
48
|
}
|
|
49
49
|
lstat;
|
|
50
|
-
export function truncate(path,
|
|
51
|
-
cb = typeof
|
|
52
|
-
const len = typeof
|
|
50
|
+
export function truncate(path, cbLen = 0, cb = nop) {
|
|
51
|
+
cb = typeof cbLen === 'function' ? cbLen : cb;
|
|
52
|
+
const len = typeof cbLen === 'number' ? cbLen : 0;
|
|
53
53
|
promises
|
|
54
54
|
.truncate(path, len)
|
|
55
55
|
.then(() => cb())
|
|
@@ -68,9 +68,9 @@ export function unlink(path, cb = nop) {
|
|
|
68
68
|
.catch(cb);
|
|
69
69
|
}
|
|
70
70
|
unlink;
|
|
71
|
-
export function open(path, flag,
|
|
72
|
-
const mode = normalizeMode(
|
|
73
|
-
cb = typeof
|
|
71
|
+
export function open(path, flag, cbMode, cb = nop) {
|
|
72
|
+
const mode = normalizeMode(cbMode, 0o644);
|
|
73
|
+
cb = typeof cbMode === 'function' ? cbMode : cb;
|
|
74
74
|
promises
|
|
75
75
|
.open(path, flag, mode)
|
|
76
76
|
.then(handle => cb(null, handle.fd))
|
|
@@ -85,17 +85,20 @@ export function readFile(filename, options, cb = nop) {
|
|
|
85
85
|
.catch(cb);
|
|
86
86
|
}
|
|
87
87
|
readFile;
|
|
88
|
-
export function writeFile(filename, data,
|
|
89
|
-
cb = typeof
|
|
88
|
+
export function writeFile(filename, data, cbEncOpts, cb = nop) {
|
|
89
|
+
cb = typeof cbEncOpts === 'function' ? cbEncOpts : cb;
|
|
90
90
|
promises
|
|
91
|
-
.writeFile(filename, data, typeof
|
|
91
|
+
.writeFile(filename, data, typeof cbEncOpts != 'function' ? cbEncOpts : null)
|
|
92
92
|
.then(() => cb(null))
|
|
93
93
|
.catch(cb);
|
|
94
94
|
}
|
|
95
95
|
writeFile;
|
|
96
|
-
export function appendFile(filename, data,
|
|
97
|
-
cb = typeof
|
|
98
|
-
promises
|
|
96
|
+
export function appendFile(filename, data, cbEncOpts, cb = nop) {
|
|
97
|
+
cb = typeof cbEncOpts === 'function' ? cbEncOpts : cb;
|
|
98
|
+
promises
|
|
99
|
+
.appendFile(filename, data, typeof cbEncOpts === 'function' ? null : cbEncOpts)
|
|
100
|
+
.then(() => cb())
|
|
101
|
+
.catch(cb);
|
|
99
102
|
}
|
|
100
103
|
appendFile;
|
|
101
104
|
export function fstat(fd, options, cb = nop) {
|
|
@@ -416,16 +419,16 @@ export function realpath(path, arg2, cb = nop) {
|
|
|
416
419
|
.catch(cb);
|
|
417
420
|
}
|
|
418
421
|
realpath;
|
|
419
|
-
export function access(path,
|
|
420
|
-
const mode = typeof
|
|
421
|
-
cb = typeof
|
|
422
|
+
export function access(path, cbMode, cb = nop) {
|
|
423
|
+
const mode = typeof cbMode === 'number' ? cbMode : R_OK;
|
|
424
|
+
cb = typeof cbMode === 'function' ? cbMode : cb;
|
|
422
425
|
promises
|
|
423
|
-
.access(path, typeof
|
|
426
|
+
.access(path, typeof cbMode === 'function' ? null : cbMode)
|
|
424
427
|
.then(() => cb())
|
|
425
428
|
.catch(cb);
|
|
426
429
|
}
|
|
427
430
|
access;
|
|
428
|
-
export function watchFile(filename,
|
|
431
|
+
export function watchFile(filename, optsListener, listener = nop) {
|
|
429
432
|
throw ApiError.With('ENOTSUP', filename, 'watchFile');
|
|
430
433
|
}
|
|
431
434
|
watchFile;
|
|
@@ -458,7 +461,7 @@ export function rm(path, options, callback = nop) {
|
|
|
458
461
|
callback = typeof options === 'function' ? options : callback;
|
|
459
462
|
promises
|
|
460
463
|
.rm(path, typeof options === 'function' ? null : options)
|
|
461
|
-
.then(
|
|
464
|
+
.then(() => callback(null))
|
|
462
465
|
.catch(callback);
|
|
463
466
|
}
|
|
464
467
|
rm;
|
|
@@ -474,7 +477,7 @@ export function copyFile(src, dest, flags, callback) {
|
|
|
474
477
|
callback = typeof flags === 'function' ? flags : callback;
|
|
475
478
|
promises
|
|
476
479
|
.copyFile(src, dest, typeof flags === 'function' ? null : flags)
|
|
477
|
-
.then(
|
|
480
|
+
.then(() => callback(null))
|
|
478
481
|
.catch(callback);
|
|
479
482
|
}
|
|
480
483
|
copyFile;
|
|
@@ -518,7 +521,9 @@ export function statfs(path, options, callback = nop) {
|
|
|
518
521
|
.catch(callback);
|
|
519
522
|
}
|
|
520
523
|
statfs;
|
|
524
|
+
/* eslint-disable @typescript-eslint/no-unused-vars */
|
|
521
525
|
export function openAsBlob(path, options) {
|
|
522
526
|
throw ApiError.With('ENOTSUP', path, 'openAsBlob');
|
|
523
527
|
}
|
|
524
528
|
openAsBlob;
|
|
529
|
+
/* eslint-enable @typescript-eslint/no-unused-vars */
|
|
@@ -147,6 +147,10 @@ export declare class FileHandle implements promises.FileHandle {
|
|
|
147
147
|
* If `flag` is not supplied, the default of `'w'` is used.
|
|
148
148
|
*/
|
|
149
149
|
writeFile(data: string | Uint8Array, _options?: Node.WriteFileOptions): Promise<void>;
|
|
150
|
+
/**
|
|
151
|
+
* Asynchronous close(2) - close a `FileHandle`.
|
|
152
|
+
*/
|
|
153
|
+
close(): Promise<void>;
|
|
150
154
|
/**
|
|
151
155
|
* See `fs.writev` promisified version.
|
|
152
156
|
* @todo Implement
|
|
@@ -157,10 +161,6 @@ export declare class FileHandle implements promises.FileHandle {
|
|
|
157
161
|
* @todo Implement
|
|
158
162
|
*/
|
|
159
163
|
readv(buffers: readonly NodeJS.ArrayBufferView[], position?: number): Promise<Node.ReadVResult>;
|
|
160
|
-
/**
|
|
161
|
-
* Asynchronous close(2) - close a `FileHandle`.
|
|
162
|
-
*/
|
|
163
|
-
close(): Promise<void>;
|
|
164
164
|
createReadStream(options?: CreateReadStreamOptions): Node.ReadStream;
|
|
165
165
|
createWriteStream(options?: CreateWriteStreamOptions): Node.WriteStream;
|
|
166
166
|
}
|
|
@@ -184,6 +184,14 @@ export class FileHandle {
|
|
|
184
184
|
const encodedData = typeof data == 'string' ? Buffer.from(data, options.encoding) : data;
|
|
185
185
|
await this.file.write(encodedData, 0, encodedData.length, 0);
|
|
186
186
|
}
|
|
187
|
+
/**
|
|
188
|
+
* Asynchronous close(2) - close a `FileHandle`.
|
|
189
|
+
*/
|
|
190
|
+
async close() {
|
|
191
|
+
await this.file.close();
|
|
192
|
+
fdMap.delete(this.fd);
|
|
193
|
+
}
|
|
194
|
+
/* eslint-disable @typescript-eslint/no-unused-vars */
|
|
187
195
|
/**
|
|
188
196
|
* See `fs.writev` promisified version.
|
|
189
197
|
* @todo Implement
|
|
@@ -198,13 +206,6 @@ export class FileHandle {
|
|
|
198
206
|
readv(buffers, position) {
|
|
199
207
|
throw ApiError.With('ENOTSUP', this.path, 'FileHandle.readv');
|
|
200
208
|
}
|
|
201
|
-
/**
|
|
202
|
-
* Asynchronous close(2) - close a `FileHandle`.
|
|
203
|
-
*/
|
|
204
|
-
async close() {
|
|
205
|
-
await this.file.close();
|
|
206
|
-
fdMap.delete(this.fd);
|
|
207
|
-
}
|
|
208
209
|
createReadStream(options) {
|
|
209
210
|
throw ApiError.With('ENOTSUP', this.path, 'createReadStream');
|
|
210
211
|
}
|
|
@@ -659,6 +660,7 @@ export async function access(path, mode = F_OK) {
|
|
|
659
660
|
}
|
|
660
661
|
}
|
|
661
662
|
access;
|
|
663
|
+
/* eslint-disable @typescript-eslint/no-unused-vars */
|
|
662
664
|
/**
|
|
663
665
|
* @todo Implement
|
|
664
666
|
*/
|
|
@@ -691,3 +693,4 @@ cp;
|
|
|
691
693
|
export async function statfs(path, opts) {
|
|
692
694
|
throw ApiError.With('ENOTSUP', path, 'statfs');
|
|
693
695
|
}
|
|
696
|
+
/* eslint-enable @typescript-eslint/no-unused-vars */
|
package/dist/emulation/sync.js
CHANGED
|
@@ -540,6 +540,7 @@ export function accessSync(path, mode = 0o600) {
|
|
|
540
540
|
}
|
|
541
541
|
}
|
|
542
542
|
accessSync;
|
|
543
|
+
/* eslint-disable @typescript-eslint/no-unused-vars */
|
|
543
544
|
/**
|
|
544
545
|
* @todo Implement
|
|
545
546
|
*/
|
|
@@ -589,3 +590,4 @@ cpSync;
|
|
|
589
590
|
export function statfsSync(path, options) {
|
|
590
591
|
throw ApiError.With('ENOTSUP', path, 'statfsSync');
|
|
591
592
|
}
|
|
593
|
+
/* eslint-enable @typescript-eslint/no-unused-vars */
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zenfs/core",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.7",
|
|
4
4
|
"description": "A filesystem in your browser",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist",
|
|
@@ -10,7 +10,8 @@
|
|
|
10
10
|
"storage"
|
|
11
11
|
],
|
|
12
12
|
"bin": {
|
|
13
|
-
"make-index": "scripts/make-index.js"
|
|
13
|
+
"make-index": "scripts/make-index.js",
|
|
14
|
+
"build": "scripts/build.js"
|
|
14
15
|
},
|
|
15
16
|
"type": "module",
|
|
16
17
|
"homepage": "https://github.com/zen-fs/core",
|
|
@@ -45,9 +46,9 @@
|
|
|
45
46
|
"format:check": "prettier --check .",
|
|
46
47
|
"lint": "eslint src tests && tsc -p tsconfig.json --noEmit",
|
|
47
48
|
"test": "cross-env NODE_OPTIONS=--experimental-vm-modules npx jest",
|
|
48
|
-
"build": "node scripts/build.js",
|
|
49
|
+
"build": "node scripts/build.js --globalName=ZenFS src/index.ts",
|
|
49
50
|
"build:docs": "typedoc --out docs --name ZenFS src/index.ts",
|
|
50
|
-
"dev": "
|
|
51
|
+
"dev": "npm run build -- --watch",
|
|
51
52
|
"prepublishOnly": "npm run build"
|
|
52
53
|
},
|
|
53
54
|
"dependencies": {
|
|
@@ -58,6 +59,7 @@
|
|
|
58
59
|
"readable-stream": "^4.5.2"
|
|
59
60
|
},
|
|
60
61
|
"devDependencies": {
|
|
62
|
+
"@fal-works/esbuild-plugin-global-externals": "^2.1.2",
|
|
61
63
|
"@jest/globals": "^29.5.0",
|
|
62
64
|
"@types/jest": "^29.5.1",
|
|
63
65
|
"@typescript-eslint/eslint-plugin": "^5.55.0",
|
package/scripts/build.js
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { build, context } from 'esbuild';
|
|
2
|
+
import { execSync } from 'node:child_process';
|
|
3
|
+
import { parseArgs } from 'node:util';
|
|
4
|
+
import { rmSync } from 'node:fs';
|
|
5
|
+
import { globalExternals } from '@fal-works/esbuild-plugin-global-externals';
|
|
6
|
+
|
|
7
|
+
let buildCount = 0;
|
|
8
|
+
|
|
9
|
+
const {
|
|
10
|
+
values: { watch, keep, quiet, globalName },
|
|
11
|
+
positionals: entryPoints,
|
|
12
|
+
} = parseArgs({
|
|
13
|
+
options: {
|
|
14
|
+
watch: { short: 'w', type: 'boolean', default: false },
|
|
15
|
+
keep: { short: 'k', type: 'boolean', default: false },
|
|
16
|
+
quiet: { short: 'q', type: 'boolean', default: false },
|
|
17
|
+
globalName: { type: 'string' },
|
|
18
|
+
},
|
|
19
|
+
allowPositionals: true,
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
async function exportsOf(name) {
|
|
23
|
+
try {
|
|
24
|
+
return Object.keys(await import(name)).filter(key => key != 'default');
|
|
25
|
+
} catch (e) {
|
|
26
|
+
return [];
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function start() {
|
|
31
|
+
if (!keep) {
|
|
32
|
+
rmSync('dist', { force: true, recursive: true });
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
if (watch && !quiet) {
|
|
36
|
+
console.log(`------------ Building #${++buildCount}`);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
execSync('npx tsc -p tsconfig.json', { stdio: 'inherit' });
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const config = {
|
|
43
|
+
entryPoints,
|
|
44
|
+
target: 'esnext',
|
|
45
|
+
globalName,
|
|
46
|
+
outfile: 'dist/browser.min.js',
|
|
47
|
+
sourcemap: true,
|
|
48
|
+
keepNames: true,
|
|
49
|
+
bundle: true,
|
|
50
|
+
minify: true,
|
|
51
|
+
platform: 'browser',
|
|
52
|
+
plugins: [
|
|
53
|
+
globalExternals({
|
|
54
|
+
'@zenfs/core': {
|
|
55
|
+
varName: 'ZenFS',
|
|
56
|
+
namedExports: await exportsOf('@zenfs/core'),
|
|
57
|
+
},
|
|
58
|
+
}),
|
|
59
|
+
{
|
|
60
|
+
name: 'tsc+counter',
|
|
61
|
+
setup({ onStart, onEnd }) {
|
|
62
|
+
onStart(start);
|
|
63
|
+
|
|
64
|
+
if (watch && !quiet) {
|
|
65
|
+
onEnd(() => {
|
|
66
|
+
console.log(`--------------- Built #${buildCount}`);
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
},
|
|
70
|
+
},
|
|
71
|
+
],
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
if (watch) {
|
|
75
|
+
if (!quiet) {
|
|
76
|
+
console.log('Watching for changes...');
|
|
77
|
+
}
|
|
78
|
+
const ctx = await context(config);
|
|
79
|
+
await ctx.watch();
|
|
80
|
+
} else {
|
|
81
|
+
await build(config);
|
|
82
|
+
}
|
package/scripts/make-index.js
CHANGED
|
@@ -5,10 +5,7 @@ import { join } from 'path/posix';
|
|
|
5
5
|
import { resolve } from 'path';
|
|
6
6
|
import { minimatch } from 'minimatch';
|
|
7
7
|
|
|
8
|
-
const {
|
|
9
|
-
values: options,
|
|
10
|
-
positionals: [root],
|
|
11
|
-
} = parseArgs({
|
|
8
|
+
const { values: options, positionals } = parseArgs({
|
|
12
9
|
options: {
|
|
13
10
|
help: { short: 'h', type: 'boolean', default: false },
|
|
14
11
|
ignore: { short: 'i', type: 'string', multiple: true, default: [] },
|
|
@@ -17,9 +14,10 @@ const {
|
|
|
17
14
|
verbose: { type: 'boolean', default: false },
|
|
18
15
|
},
|
|
19
16
|
allowPositionals: true,
|
|
20
|
-
strict: true,
|
|
21
17
|
});
|
|
22
18
|
|
|
19
|
+
const root = positionals.at(-1) == 'make-index' ? '.' : positionals.at(-1);
|
|
20
|
+
|
|
23
21
|
if (options.help) {
|
|
24
22
|
console.log(`make-index <path> [...options]
|
|
25
23
|
path: The path to create a listing for
|
|
@@ -76,7 +74,7 @@ function makeListing(path, seen = new Set()) {
|
|
|
76
74
|
return null;
|
|
77
75
|
}
|
|
78
76
|
|
|
79
|
-
|
|
77
|
+
const entries = {};
|
|
80
78
|
for (const file of readdirSync(path)) {
|
|
81
79
|
const full = join(path, file);
|
|
82
80
|
if (options.ignore.some(pattern => minimatch(full, pattern))) {
|