@cordisjs/fs 1.3.7 → 2.0.0-rc.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/README.md +0 -4
- package/lib/error.d.ts +13 -0
- package/lib/index.d.ts +61 -21
- package/lib/index.js +215 -65
- package/lib/watcher.d.ts +45 -0
- package/package.json +29 -21
- package/lib/constants.d.ts +0 -56
- package/lib/constants.js +0 -219
- package/lib/promises.d.ts +0 -90
- package/lib/promises.js +0 -325
package/README.md
CHANGED
package/lib/error.d.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export declare class FsError extends Error {
|
|
2
|
+
code: FsError.Code;
|
|
3
|
+
url: URL;
|
|
4
|
+
name: string;
|
|
5
|
+
constructor(code: FsError.Code, url: URL, message: string);
|
|
6
|
+
}
|
|
7
|
+
export declare namespace FsError {
|
|
8
|
+
type Code =
|
|
9
|
+
/** No provider is mounted for the location. */
|
|
10
|
+
'NoProvider'
|
|
11
|
+
/** The provider of the location does not implement the operation. */
|
|
12
|
+
| 'NotSupported';
|
|
13
|
+
}
|
package/lib/index.d.ts
CHANGED
|
@@ -1,24 +1,64 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
|
|
5
|
-
export
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
isFile(): boolean;
|
|
11
|
-
isDirectory(): boolean;
|
|
1
|
+
import { Context, Service } from 'cordis';
|
|
2
|
+
import { Awaitable } from 'cosmokit';
|
|
3
|
+
import { Watcher, WatchOptions } from './watcher.ts';
|
|
4
|
+
export * from './error.ts';
|
|
5
|
+
export * from './watcher.ts';
|
|
6
|
+
declare module 'cordis' {
|
|
7
|
+
interface Context {
|
|
8
|
+
fs: Fs;
|
|
9
|
+
}
|
|
12
10
|
}
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
11
|
+
/**
|
|
12
|
+
* The file system service, which forwards each operation to the provider
|
|
13
|
+
* mounted at its location.
|
|
14
|
+
*/
|
|
15
|
+
export declare class Fs extends Service {
|
|
16
|
+
private _mounts;
|
|
17
|
+
/** the connection that serves each watch, if any */
|
|
18
|
+
private _watchers;
|
|
19
|
+
constructor(ctx: Context);
|
|
20
|
+
/**
|
|
21
|
+
* Mount a provider at a scheme, such as `s3:`, or at a URL, such as
|
|
22
|
+
* `file:///`. A location goes to the provider of the longest prefix that
|
|
23
|
+
* contains it. The mount ends with the calling fiber.
|
|
24
|
+
*
|
|
25
|
+
* Every watch follows the routing: a change of the mounts moves it to the
|
|
26
|
+
* provider its location goes to, and a watch without a provider is resumed
|
|
27
|
+
* once one is mounted. Changes while a watch has no provider are not reported.
|
|
28
|
+
*/
|
|
29
|
+
mount(prefix: string | URL, provider: FsProvider): import("cordis").Disposable<Promise<void>>;
|
|
30
|
+
/** Resolve a URL reference against `ctx.baseUrl`. */
|
|
31
|
+
resolve(path: string | URL): URL;
|
|
32
|
+
private _match;
|
|
33
|
+
private _route;
|
|
34
|
+
private _connect;
|
|
35
|
+
private _disconnect;
|
|
36
|
+
private _reroute;
|
|
37
|
+
/** Watch a file or a directory. The watch ends with the calling fiber. */
|
|
38
|
+
watch(path: string | URL, options?: WatchOptions): Watcher;
|
|
19
39
|
}
|
|
20
|
-
export
|
|
21
|
-
|
|
22
|
-
|
|
40
|
+
export interface FsProvider {
|
|
41
|
+
/**
|
|
42
|
+
* Start serving `watcher`, and return a function that disposes it. The
|
|
43
|
+
* provider reports through `watcher.emit()`, with a `ready` once the initial
|
|
44
|
+
* scan is done, and reports nothing once the returned function is called.
|
|
45
|
+
*/
|
|
46
|
+
watch?(watcher: Watcher): () => Awaitable<void>;
|
|
23
47
|
}
|
|
24
|
-
export
|
|
48
|
+
export interface BaseFs extends FsProvider {
|
|
49
|
+
}
|
|
50
|
+
/** A provider that mounts itself, at `config.mount` or at its static `mount`. */
|
|
51
|
+
export declare abstract class BaseFs {
|
|
52
|
+
ctx: Context;
|
|
53
|
+
static inject: string[];
|
|
54
|
+
/** The default mount point of the subclass. */
|
|
55
|
+
static mount?: string;
|
|
56
|
+
constructor(ctx: Context, config?: BaseFs.Config);
|
|
57
|
+
}
|
|
58
|
+
export declare namespace BaseFs {
|
|
59
|
+
interface Config {
|
|
60
|
+
/** a scheme such as `s3:`, or a URL such as `file:///` */
|
|
61
|
+
mount?: string;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
export default Fs;
|
package/lib/index.js
CHANGED
|
@@ -1,81 +1,231 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __create = Object.create;
|
|
3
1
|
var __defProp = Object.defineProperty;
|
|
4
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
2
|
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
3
|
+
|
|
4
|
+
// src/index.ts
|
|
5
|
+
import { Service } from "cordis";
|
|
6
|
+
|
|
7
|
+
// src/error.ts
|
|
8
|
+
var FsError = class extends Error {
|
|
9
|
+
constructor(code, url, message) {
|
|
10
|
+
super(message);
|
|
11
|
+
this.code = code;
|
|
12
|
+
this.url = url;
|
|
18
13
|
}
|
|
19
|
-
|
|
14
|
+
code;
|
|
15
|
+
url;
|
|
16
|
+
static {
|
|
17
|
+
__name(this, "FsError");
|
|
18
|
+
}
|
|
19
|
+
name = "FsError";
|
|
20
20
|
};
|
|
21
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
22
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
23
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
24
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
25
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
26
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
27
|
-
mod
|
|
28
|
-
));
|
|
29
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
30
21
|
|
|
31
|
-
// src/
|
|
32
|
-
var
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
constructor(handle) {
|
|
46
|
-
this.handle = handle;
|
|
47
|
-
this.name = handle.name;
|
|
22
|
+
// src/watcher.ts
|
|
23
|
+
var Watcher = class {
|
|
24
|
+
/** `connect` starts serving the watch, and returns a function that disposes it. */
|
|
25
|
+
constructor(ctx, url, options, connect) {
|
|
26
|
+
this.ctx = ctx;
|
|
27
|
+
this.url = url;
|
|
28
|
+
this.options = options;
|
|
29
|
+
this.dispose = ctx.effect(() => {
|
|
30
|
+
const disconnect = connect(this);
|
|
31
|
+
return () => {
|
|
32
|
+
this._closed = true;
|
|
33
|
+
return disconnect();
|
|
34
|
+
};
|
|
35
|
+
}, "ctx.fs.watch()");
|
|
48
36
|
}
|
|
37
|
+
ctx;
|
|
38
|
+
url;
|
|
39
|
+
options;
|
|
49
40
|
static {
|
|
50
|
-
__name(this, "
|
|
41
|
+
__name(this, "Watcher");
|
|
51
42
|
}
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
43
|
+
_hooks = { change: /* @__PURE__ */ new Set(), ready: /* @__PURE__ */ new Set(), error: /* @__PURE__ */ new Set() };
|
|
44
|
+
_ready = false;
|
|
45
|
+
_closed = false;
|
|
46
|
+
/** Ends the watch. */
|
|
47
|
+
dispose;
|
|
48
|
+
/** Adds a listener, and returns a function that removes it. */
|
|
49
|
+
on(name, listener) {
|
|
50
|
+
const hooks = this._hooks[name];
|
|
51
|
+
const hook = { listener };
|
|
52
|
+
hooks.add(hook);
|
|
53
|
+
if (name === "ready" && this._ready) {
|
|
54
|
+
queueMicrotask(() => {
|
|
55
|
+
if (!hook.removed) this._call(listener, []);
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
return () => {
|
|
59
|
+
hook.removed = true;
|
|
60
|
+
hooks.delete(hook);
|
|
61
|
+
};
|
|
55
62
|
}
|
|
56
|
-
|
|
57
|
-
|
|
63
|
+
/**
|
|
64
|
+
* Reports an event, as the provider that serves the watch does. Only the
|
|
65
|
+
* first `ready` is dispatched, so a provider that takes over the watch does
|
|
66
|
+
* not report it again.
|
|
67
|
+
*/
|
|
68
|
+
emit(name, ...args) {
|
|
69
|
+
if (this._closed) return;
|
|
70
|
+
if (name === "error") return this._error(args[0]);
|
|
71
|
+
if (name === "ready") {
|
|
72
|
+
if (this._ready) return;
|
|
73
|
+
this._ready = true;
|
|
74
|
+
}
|
|
75
|
+
this._dispatch(name, args);
|
|
76
|
+
}
|
|
77
|
+
// An event reaches the hooks taken when it is dispatched.
|
|
78
|
+
_dispatch(name, args) {
|
|
79
|
+
for (const hook of [...this._hooks[name]]) {
|
|
80
|
+
if (!hook.removed) this._call(hook.listener, args);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
_call(listener, args) {
|
|
84
|
+
(async () => listener(...args))().catch((error) => this._error(error));
|
|
85
|
+
}
|
|
86
|
+
_error(error) {
|
|
87
|
+
if (this._closed) return;
|
|
88
|
+
const hooks = this._hooks.error;
|
|
89
|
+
if (!hooks.size) return this.ctx.logger.warn(error);
|
|
90
|
+
for (const hook of [...hooks]) {
|
|
91
|
+
if (hook.removed) continue;
|
|
92
|
+
(async () => hook.listener(error))().catch((error2) => this.ctx.logger.warn(error2));
|
|
93
|
+
}
|
|
58
94
|
}
|
|
59
95
|
};
|
|
60
|
-
|
|
96
|
+
|
|
97
|
+
// src/index.ts
|
|
98
|
+
function normalizePrefix(prefix) {
|
|
99
|
+
if (typeof prefix === "string" && /^[a-zA-Z][a-zA-Z\d+.-]*:$/.test(prefix)) {
|
|
100
|
+
return prefix.toLowerCase();
|
|
101
|
+
}
|
|
102
|
+
const { href } = new URL(prefix);
|
|
103
|
+
return href.endsWith("/") ? href : href + "/";
|
|
104
|
+
}
|
|
105
|
+
__name(normalizePrefix, "normalizePrefix");
|
|
106
|
+
var Fs = class extends Service {
|
|
61
107
|
static {
|
|
62
|
-
__name(this, "
|
|
108
|
+
__name(this, "Fs");
|
|
63
109
|
}
|
|
64
|
-
|
|
65
|
-
|
|
110
|
+
_mounts = /* @__PURE__ */ new Map();
|
|
111
|
+
/** the connection that serves each watch, if any */
|
|
112
|
+
_watchers = /* @__PURE__ */ new Map();
|
|
113
|
+
constructor(ctx) {
|
|
114
|
+
super(ctx, "fs");
|
|
66
115
|
}
|
|
67
|
-
|
|
116
|
+
/**
|
|
117
|
+
* Mount a provider at a scheme, such as `s3:`, or at a URL, such as
|
|
118
|
+
* `file:///`. A location goes to the provider of the longest prefix that
|
|
119
|
+
* contains it. The mount ends with the calling fiber.
|
|
120
|
+
*
|
|
121
|
+
* Every watch follows the routing: a change of the mounts moves it to the
|
|
122
|
+
* provider its location goes to, and a watch without a provider is resumed
|
|
123
|
+
* once one is mounted. Changes while a watch has no provider are not reported.
|
|
124
|
+
*/
|
|
125
|
+
mount(prefix, provider) {
|
|
126
|
+
const key = normalizePrefix(prefix);
|
|
127
|
+
return this.ctx.effect(() => {
|
|
128
|
+
if (this._mounts.has(key)) {
|
|
129
|
+
throw new Error(`a provider is already mounted at ${key}`);
|
|
130
|
+
}
|
|
131
|
+
this._mounts.set(key, { prefix: key, provider });
|
|
132
|
+
this._reroute();
|
|
133
|
+
return () => {
|
|
134
|
+
this._mounts.delete(key);
|
|
135
|
+
return this._reroute();
|
|
136
|
+
};
|
|
137
|
+
}, "ctx.fs.mount()");
|
|
138
|
+
}
|
|
139
|
+
/** Resolve a URL reference against `ctx.baseUrl`. */
|
|
140
|
+
resolve(path) {
|
|
141
|
+
if (path instanceof URL) return path;
|
|
142
|
+
const base = this.ctx.baseUrl;
|
|
143
|
+
if (!base && !URL.canParse(path)) {
|
|
144
|
+
throw new TypeError(`cannot resolve the relative reference ${JSON.stringify(path)} without ctx.baseUrl`);
|
|
145
|
+
}
|
|
146
|
+
return new URL(path, base);
|
|
147
|
+
}
|
|
148
|
+
_match(url) {
|
|
149
|
+
let result;
|
|
150
|
+
for (const mount of this._mounts.values()) {
|
|
151
|
+
const matches = mount.prefix.endsWith(":") ? url.protocol === mount.prefix : url.href.startsWith(mount.prefix) || url.href + "/" === mount.prefix;
|
|
152
|
+
if (matches && (!result || mount.prefix.length > result.prefix.length)) result = mount;
|
|
153
|
+
}
|
|
154
|
+
return result;
|
|
155
|
+
}
|
|
156
|
+
_route(url) {
|
|
157
|
+
const mount = this._match(url);
|
|
158
|
+
if (!mount) throw new FsError("NoProvider", url, `no provider is mounted for ${url.href}`);
|
|
159
|
+
return mount;
|
|
160
|
+
}
|
|
161
|
+
_connect(watcher, mount) {
|
|
162
|
+
const { provider, prefix } = mount;
|
|
163
|
+
if (!provider.watch) {
|
|
164
|
+
throw new FsError("NotSupported", watcher.url, `the provider mounted at ${prefix} does not support watch()`);
|
|
165
|
+
}
|
|
166
|
+
const dispose = provider.watch(watcher);
|
|
167
|
+
this._watchers.set(watcher, { mount, dispose });
|
|
168
|
+
}
|
|
169
|
+
// The provider watch is disposed at once, and reports no more events.
|
|
170
|
+
async _disconnect(watcher) {
|
|
171
|
+
const connection = this._watchers.get(watcher);
|
|
172
|
+
if (!connection) return;
|
|
173
|
+
this._watchers.set(watcher, void 0);
|
|
174
|
+
await connection.dispose();
|
|
175
|
+
}
|
|
176
|
+
_reroute() {
|
|
177
|
+
const stops = [];
|
|
178
|
+
for (const [watcher, connection] of this._watchers) {
|
|
179
|
+
const mount = this._match(watcher.url);
|
|
180
|
+
if (mount === connection?.mount) continue;
|
|
181
|
+
stops.push(this._disconnect(watcher).catch((error) => watcher.emit("error", error)));
|
|
182
|
+
if (!mount) {
|
|
183
|
+
this.ctx.logger.debug("watch of %s is suspended without a provider", watcher.url.href);
|
|
184
|
+
continue;
|
|
185
|
+
}
|
|
186
|
+
try {
|
|
187
|
+
this._connect(watcher, mount);
|
|
188
|
+
} catch (error) {
|
|
189
|
+
watcher.emit("error", error);
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
return Promise.all(stops).then(() => {
|
|
193
|
+
});
|
|
194
|
+
}
|
|
195
|
+
/** Watch a file or a directory. The watch ends with the calling fiber. */
|
|
196
|
+
watch(path, options = {}) {
|
|
197
|
+
const url = this.resolve(path);
|
|
198
|
+
const mount = this._route(url);
|
|
199
|
+
return new Watcher(this.ctx, url, options, (watcher) => {
|
|
200
|
+
this._connect(watcher, mount);
|
|
201
|
+
return async () => {
|
|
202
|
+
const connection = this._watchers.get(watcher);
|
|
203
|
+
this._watchers.delete(watcher);
|
|
204
|
+
await connection?.dispose();
|
|
205
|
+
};
|
|
206
|
+
});
|
|
68
207
|
}
|
|
69
208
|
};
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
209
|
+
var BaseFs = class {
|
|
210
|
+
constructor(ctx, config = {}) {
|
|
211
|
+
this.ctx = ctx;
|
|
212
|
+
const mount = config.mount ?? new.target.mount;
|
|
213
|
+
if (!mount) throw new TypeError("expected a mount point in the config");
|
|
214
|
+
ctx.fs.mount(mount, this);
|
|
215
|
+
}
|
|
216
|
+
ctx;
|
|
217
|
+
static {
|
|
218
|
+
__name(this, "BaseFs");
|
|
219
|
+
}
|
|
220
|
+
static inject = ["fs"];
|
|
221
|
+
/** The default mount point of the subclass. */
|
|
222
|
+
static mount;
|
|
223
|
+
};
|
|
224
|
+
var index_default = Fs;
|
|
225
|
+
export {
|
|
226
|
+
BaseFs,
|
|
227
|
+
Fs,
|
|
228
|
+
FsError,
|
|
229
|
+
Watcher,
|
|
230
|
+
index_default as default
|
|
231
|
+
};
|
package/lib/watcher.d.ts
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { Context } from 'cordis';
|
|
2
|
+
import { Awaitable } from 'cosmokit';
|
|
3
|
+
export type WatchFilter = string[] | ((path: string, isDirectory: boolean) => boolean);
|
|
4
|
+
export interface WatchOptions {
|
|
5
|
+
/**
|
|
6
|
+
* Decides which entries below a watched directory are kept.
|
|
7
|
+
*/
|
|
8
|
+
filter?: WatchFilter;
|
|
9
|
+
}
|
|
10
|
+
export interface WatchEvents {
|
|
11
|
+
/** A file at or below the watched location is modified. */
|
|
12
|
+
change(url: URL): Awaitable<void>;
|
|
13
|
+
/** The initial scan is done. A listener added afterwards is called at once. */
|
|
14
|
+
ready(): Awaitable<void>;
|
|
15
|
+
/** An error is logged as a warning without a listener. */
|
|
16
|
+
error(error: unknown): Awaitable<void>;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* A watch on a location, which ends with the calling fiber. The provider that
|
|
20
|
+
* the location is routed to reports its events, and another provider takes
|
|
21
|
+
* over when the routing changes.
|
|
22
|
+
*/
|
|
23
|
+
export declare class Watcher {
|
|
24
|
+
private ctx;
|
|
25
|
+
url: URL;
|
|
26
|
+
options: WatchOptions;
|
|
27
|
+
private _hooks;
|
|
28
|
+
private _ready;
|
|
29
|
+
private _closed;
|
|
30
|
+
/** Ends the watch. */
|
|
31
|
+
dispose: () => Promise<void>;
|
|
32
|
+
/** `connect` starts serving the watch, and returns a function that disposes it. */
|
|
33
|
+
constructor(ctx: Context, url: URL, options: WatchOptions, connect: (watcher: Watcher) => () => Promise<void>);
|
|
34
|
+
/** Adds a listener, and returns a function that removes it. */
|
|
35
|
+
on<K extends keyof WatchEvents>(name: K, listener: WatchEvents[K]): () => void;
|
|
36
|
+
/**
|
|
37
|
+
* Reports an event, as the provider that serves the watch does. Only the
|
|
38
|
+
* first `ready` is dispatched, so a provider that takes over the watch does
|
|
39
|
+
* not report it again.
|
|
40
|
+
*/
|
|
41
|
+
emit<K extends keyof WatchEvents>(name: K, ...args: Parameters<WatchEvents[K]>): void;
|
|
42
|
+
private _dispatch;
|
|
43
|
+
private _call;
|
|
44
|
+
private _error;
|
|
45
|
+
}
|
package/package.json
CHANGED
|
@@ -1,38 +1,46 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cordisjs/fs",
|
|
3
|
-
"
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
"
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
"./promises": "./lib/promises.js",
|
|
10
|
-
"./src/*": "./src/*",
|
|
11
|
-
"./package.json": "./package.json"
|
|
12
|
-
},
|
|
3
|
+
"description": "File system service for Cordis",
|
|
4
|
+
"version": "2.0.0-rc.0",
|
|
5
|
+
"sideEffects": false,
|
|
6
|
+
"type": "module",
|
|
7
|
+
"main": "lib/index.js",
|
|
8
|
+
"types": "lib/index.d.ts",
|
|
13
9
|
"files": [
|
|
14
10
|
"lib"
|
|
15
11
|
],
|
|
12
|
+
"author": "Shigma <shigma10826@gmail.com>",
|
|
16
13
|
"license": "MIT",
|
|
17
14
|
"repository": {
|
|
18
15
|
"type": "git",
|
|
19
|
-
"url": "git+https://github.com/cordiverse/
|
|
16
|
+
"url": "git+https://github.com/cordiverse/cordis.git",
|
|
20
17
|
"directory": "packages/fs"
|
|
21
18
|
},
|
|
22
19
|
"bugs": {
|
|
23
|
-
"url": "https://github.com/cordiverse/
|
|
20
|
+
"url": "https://github.com/cordiverse/cordis/issues"
|
|
24
21
|
},
|
|
25
|
-
"homepage": "https://github.com/cordiverse/
|
|
26
|
-
"author": "Shigma <shigma10826@gmail.com>",
|
|
22
|
+
"homepage": "https://github.com/cordiverse/cordis",
|
|
27
23
|
"keywords": [
|
|
24
|
+
"cordis",
|
|
25
|
+
"component",
|
|
28
26
|
"fs",
|
|
29
|
-
"
|
|
30
|
-
"
|
|
31
|
-
"ponyfill",
|
|
32
|
-
"polyfill",
|
|
33
|
-
"node"
|
|
27
|
+
"file",
|
|
28
|
+
"service"
|
|
34
29
|
],
|
|
30
|
+
"cordis": {
|
|
31
|
+
"service": {
|
|
32
|
+
"implements": [
|
|
33
|
+
"fs"
|
|
34
|
+
]
|
|
35
|
+
}
|
|
36
|
+
},
|
|
37
|
+
"peerDependencies": {
|
|
38
|
+
"cordis": "^4.0.0-rc.13"
|
|
39
|
+
},
|
|
40
|
+
"devDependencies": {
|
|
41
|
+
"cordis": "^4.0.0-rc.13"
|
|
42
|
+
},
|
|
35
43
|
"dependencies": {
|
|
36
|
-
"
|
|
44
|
+
"cosmokit": "^1.8.1"
|
|
37
45
|
}
|
|
38
|
-
}
|
|
46
|
+
}
|
package/lib/constants.d.ts
DELETED
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
export declare const UV_FS_SYMLINK_DIR = 1;
|
|
2
|
-
export declare const UV_FS_SYMLINK_JUNCTION = 2;
|
|
3
|
-
export declare const O_RDONLY = 0;
|
|
4
|
-
export declare const O_WRONLY = 1;
|
|
5
|
-
export declare const O_RDWR = 2;
|
|
6
|
-
export declare const UV_DIRENT_UNKNOWN = 0;
|
|
7
|
-
export declare const UV_DIRENT_FILE = 1;
|
|
8
|
-
export declare const UV_DIRENT_DIR = 2;
|
|
9
|
-
export declare const UV_DIRENT_LINK = 3;
|
|
10
|
-
export declare const UV_DIRENT_FIFO = 4;
|
|
11
|
-
export declare const UV_DIRENT_SOCKET = 5;
|
|
12
|
-
export declare const UV_DIRENT_CHAR = 6;
|
|
13
|
-
export declare const UV_DIRENT_BLOCK = 7;
|
|
14
|
-
export declare const S_IFMT = 61440;
|
|
15
|
-
export declare const S_IFREG = 32768;
|
|
16
|
-
export declare const S_IFDIR = 16384;
|
|
17
|
-
export declare const S_IFCHR = 8192;
|
|
18
|
-
export declare const S_IFBLK = 24576;
|
|
19
|
-
export declare const S_IFIFO = 4096;
|
|
20
|
-
export declare const S_IFLNK = 40960;
|
|
21
|
-
export declare const S_IFSOCK = 49152;
|
|
22
|
-
export declare const O_CREAT = 512;
|
|
23
|
-
export declare const O_EXCL = 2048;
|
|
24
|
-
export declare const UV_FS_O_FILEMAP = 0;
|
|
25
|
-
export declare const O_NOCTTY = 131072;
|
|
26
|
-
export declare const O_TRUNC = 1024;
|
|
27
|
-
export declare const O_APPEND = 8;
|
|
28
|
-
export declare const O_DIRECTORY = 1048576;
|
|
29
|
-
export declare const O_NOFOLLOW = 256;
|
|
30
|
-
export declare const O_SYNC = 128;
|
|
31
|
-
export declare const O_DSYNC = 4194304;
|
|
32
|
-
export declare const O_SYMLINK = 2097152;
|
|
33
|
-
export declare const O_NONBLOCK = 4;
|
|
34
|
-
export declare const S_IRWXU = 448;
|
|
35
|
-
export declare const S_IRUSR = 256;
|
|
36
|
-
export declare const S_IWUSR = 128;
|
|
37
|
-
export declare const S_IXUSR = 64;
|
|
38
|
-
export declare const S_IRWXG = 56;
|
|
39
|
-
export declare const S_IRGRP = 32;
|
|
40
|
-
export declare const S_IWGRP = 16;
|
|
41
|
-
export declare const S_IXGRP = 8;
|
|
42
|
-
export declare const S_IRWXO = 7;
|
|
43
|
-
export declare const S_IROTH = 4;
|
|
44
|
-
export declare const S_IWOTH = 2;
|
|
45
|
-
export declare const S_IXOTH = 1;
|
|
46
|
-
export declare const F_OK = 0;
|
|
47
|
-
export declare const R_OK = 4;
|
|
48
|
-
export declare const W_OK = 2;
|
|
49
|
-
export declare const X_OK = 1;
|
|
50
|
-
export declare const UV_FS_COPYFILE_EXCL = 1;
|
|
51
|
-
export declare const COPYFILE_EXCL = 1;
|
|
52
|
-
export declare const UV_FS_COPYFILE_FICLONE = 2;
|
|
53
|
-
export declare const COPYFILE_FICLONE = 2;
|
|
54
|
-
export declare const UV_FS_COPYFILE_FICLONE_FORCE = 4;
|
|
55
|
-
export declare const COPYFILE_FICLONE_FORCE = 4;
|
|
56
|
-
export declare function parseFlags(flags: string | number): number;
|
package/lib/constants.js
DELETED
|
@@ -1,219 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
7
|
-
var __export = (target, all) => {
|
|
8
|
-
for (var name in all)
|
|
9
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
-
};
|
|
11
|
-
var __copyProps = (to, from, except, desc) => {
|
|
12
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
-
for (let key of __getOwnPropNames(from))
|
|
14
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
-
}
|
|
17
|
-
return to;
|
|
18
|
-
};
|
|
19
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
20
|
-
|
|
21
|
-
// src/constants.ts
|
|
22
|
-
var constants_exports = {};
|
|
23
|
-
__export(constants_exports, {
|
|
24
|
-
COPYFILE_EXCL: () => COPYFILE_EXCL,
|
|
25
|
-
COPYFILE_FICLONE: () => COPYFILE_FICLONE,
|
|
26
|
-
COPYFILE_FICLONE_FORCE: () => COPYFILE_FICLONE_FORCE,
|
|
27
|
-
F_OK: () => F_OK,
|
|
28
|
-
O_APPEND: () => O_APPEND,
|
|
29
|
-
O_CREAT: () => O_CREAT,
|
|
30
|
-
O_DIRECTORY: () => O_DIRECTORY,
|
|
31
|
-
O_DSYNC: () => O_DSYNC,
|
|
32
|
-
O_EXCL: () => O_EXCL,
|
|
33
|
-
O_NOCTTY: () => O_NOCTTY,
|
|
34
|
-
O_NOFOLLOW: () => O_NOFOLLOW,
|
|
35
|
-
O_NONBLOCK: () => O_NONBLOCK,
|
|
36
|
-
O_RDONLY: () => O_RDONLY,
|
|
37
|
-
O_RDWR: () => O_RDWR,
|
|
38
|
-
O_SYMLINK: () => O_SYMLINK,
|
|
39
|
-
O_SYNC: () => O_SYNC,
|
|
40
|
-
O_TRUNC: () => O_TRUNC,
|
|
41
|
-
O_WRONLY: () => O_WRONLY,
|
|
42
|
-
R_OK: () => R_OK,
|
|
43
|
-
S_IFBLK: () => S_IFBLK,
|
|
44
|
-
S_IFCHR: () => S_IFCHR,
|
|
45
|
-
S_IFDIR: () => S_IFDIR,
|
|
46
|
-
S_IFIFO: () => S_IFIFO,
|
|
47
|
-
S_IFLNK: () => S_IFLNK,
|
|
48
|
-
S_IFMT: () => S_IFMT,
|
|
49
|
-
S_IFREG: () => S_IFREG,
|
|
50
|
-
S_IFSOCK: () => S_IFSOCK,
|
|
51
|
-
S_IRGRP: () => S_IRGRP,
|
|
52
|
-
S_IROTH: () => S_IROTH,
|
|
53
|
-
S_IRUSR: () => S_IRUSR,
|
|
54
|
-
S_IRWXG: () => S_IRWXG,
|
|
55
|
-
S_IRWXO: () => S_IRWXO,
|
|
56
|
-
S_IRWXU: () => S_IRWXU,
|
|
57
|
-
S_IWGRP: () => S_IWGRP,
|
|
58
|
-
S_IWOTH: () => S_IWOTH,
|
|
59
|
-
S_IWUSR: () => S_IWUSR,
|
|
60
|
-
S_IXGRP: () => S_IXGRP,
|
|
61
|
-
S_IXOTH: () => S_IXOTH,
|
|
62
|
-
S_IXUSR: () => S_IXUSR,
|
|
63
|
-
UV_DIRENT_BLOCK: () => UV_DIRENT_BLOCK,
|
|
64
|
-
UV_DIRENT_CHAR: () => UV_DIRENT_CHAR,
|
|
65
|
-
UV_DIRENT_DIR: () => UV_DIRENT_DIR,
|
|
66
|
-
UV_DIRENT_FIFO: () => UV_DIRENT_FIFO,
|
|
67
|
-
UV_DIRENT_FILE: () => UV_DIRENT_FILE,
|
|
68
|
-
UV_DIRENT_LINK: () => UV_DIRENT_LINK,
|
|
69
|
-
UV_DIRENT_SOCKET: () => UV_DIRENT_SOCKET,
|
|
70
|
-
UV_DIRENT_UNKNOWN: () => UV_DIRENT_UNKNOWN,
|
|
71
|
-
UV_FS_COPYFILE_EXCL: () => UV_FS_COPYFILE_EXCL,
|
|
72
|
-
UV_FS_COPYFILE_FICLONE: () => UV_FS_COPYFILE_FICLONE,
|
|
73
|
-
UV_FS_COPYFILE_FICLONE_FORCE: () => UV_FS_COPYFILE_FICLONE_FORCE,
|
|
74
|
-
UV_FS_O_FILEMAP: () => UV_FS_O_FILEMAP,
|
|
75
|
-
UV_FS_SYMLINK_DIR: () => UV_FS_SYMLINK_DIR,
|
|
76
|
-
UV_FS_SYMLINK_JUNCTION: () => UV_FS_SYMLINK_JUNCTION,
|
|
77
|
-
W_OK: () => W_OK,
|
|
78
|
-
X_OK: () => X_OK,
|
|
79
|
-
parseFlags: () => parseFlags
|
|
80
|
-
});
|
|
81
|
-
module.exports = __toCommonJS(constants_exports);
|
|
82
|
-
var UV_FS_SYMLINK_DIR = 1;
|
|
83
|
-
var UV_FS_SYMLINK_JUNCTION = 2;
|
|
84
|
-
var O_RDONLY = 0;
|
|
85
|
-
var O_WRONLY = 1;
|
|
86
|
-
var O_RDWR = 2;
|
|
87
|
-
var UV_DIRENT_UNKNOWN = 0;
|
|
88
|
-
var UV_DIRENT_FILE = 1;
|
|
89
|
-
var UV_DIRENT_DIR = 2;
|
|
90
|
-
var UV_DIRENT_LINK = 3;
|
|
91
|
-
var UV_DIRENT_FIFO = 4;
|
|
92
|
-
var UV_DIRENT_SOCKET = 5;
|
|
93
|
-
var UV_DIRENT_CHAR = 6;
|
|
94
|
-
var UV_DIRENT_BLOCK = 7;
|
|
95
|
-
var S_IFMT = 61440;
|
|
96
|
-
var S_IFREG = 32768;
|
|
97
|
-
var S_IFDIR = 16384;
|
|
98
|
-
var S_IFCHR = 8192;
|
|
99
|
-
var S_IFBLK = 24576;
|
|
100
|
-
var S_IFIFO = 4096;
|
|
101
|
-
var S_IFLNK = 40960;
|
|
102
|
-
var S_IFSOCK = 49152;
|
|
103
|
-
var O_CREAT = 512;
|
|
104
|
-
var O_EXCL = 2048;
|
|
105
|
-
var UV_FS_O_FILEMAP = 0;
|
|
106
|
-
var O_NOCTTY = 131072;
|
|
107
|
-
var O_TRUNC = 1024;
|
|
108
|
-
var O_APPEND = 8;
|
|
109
|
-
var O_DIRECTORY = 1048576;
|
|
110
|
-
var O_NOFOLLOW = 256;
|
|
111
|
-
var O_SYNC = 128;
|
|
112
|
-
var O_DSYNC = 4194304;
|
|
113
|
-
var O_SYMLINK = 2097152;
|
|
114
|
-
var O_NONBLOCK = 4;
|
|
115
|
-
var S_IRWXU = 448;
|
|
116
|
-
var S_IRUSR = 256;
|
|
117
|
-
var S_IWUSR = 128;
|
|
118
|
-
var S_IXUSR = 64;
|
|
119
|
-
var S_IRWXG = 56;
|
|
120
|
-
var S_IRGRP = 32;
|
|
121
|
-
var S_IWGRP = 16;
|
|
122
|
-
var S_IXGRP = 8;
|
|
123
|
-
var S_IRWXO = 7;
|
|
124
|
-
var S_IROTH = 4;
|
|
125
|
-
var S_IWOTH = 2;
|
|
126
|
-
var S_IXOTH = 1;
|
|
127
|
-
var F_OK = 0;
|
|
128
|
-
var R_OK = 4;
|
|
129
|
-
var W_OK = 2;
|
|
130
|
-
var X_OK = 1;
|
|
131
|
-
var UV_FS_COPYFILE_EXCL = 1;
|
|
132
|
-
var COPYFILE_EXCL = 1;
|
|
133
|
-
var UV_FS_COPYFILE_FICLONE = 2;
|
|
134
|
-
var COPYFILE_FICLONE = 2;
|
|
135
|
-
var UV_FS_COPYFILE_FICLONE_FORCE = 4;
|
|
136
|
-
var COPYFILE_FICLONE_FORCE = 4;
|
|
137
|
-
function parseFlags(flags) {
|
|
138
|
-
if (typeof flags === "number") return flags;
|
|
139
|
-
let result = 0;
|
|
140
|
-
for (const flag of flags) {
|
|
141
|
-
switch (flag) {
|
|
142
|
-
case "r":
|
|
143
|
-
break;
|
|
144
|
-
case "w":
|
|
145
|
-
break;
|
|
146
|
-
case "a":
|
|
147
|
-
result |= O_APPEND;
|
|
148
|
-
break;
|
|
149
|
-
case "x":
|
|
150
|
-
result |= O_EXCL;
|
|
151
|
-
break;
|
|
152
|
-
case "+":
|
|
153
|
-
break;
|
|
154
|
-
default:
|
|
155
|
-
throw new Error(`invalid flags: ${flags}`);
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
return result;
|
|
159
|
-
}
|
|
160
|
-
__name(parseFlags, "parseFlags");
|
|
161
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
162
|
-
0 && (module.exports = {
|
|
163
|
-
COPYFILE_EXCL,
|
|
164
|
-
COPYFILE_FICLONE,
|
|
165
|
-
COPYFILE_FICLONE_FORCE,
|
|
166
|
-
F_OK,
|
|
167
|
-
O_APPEND,
|
|
168
|
-
O_CREAT,
|
|
169
|
-
O_DIRECTORY,
|
|
170
|
-
O_DSYNC,
|
|
171
|
-
O_EXCL,
|
|
172
|
-
O_NOCTTY,
|
|
173
|
-
O_NOFOLLOW,
|
|
174
|
-
O_NONBLOCK,
|
|
175
|
-
O_RDONLY,
|
|
176
|
-
O_RDWR,
|
|
177
|
-
O_SYMLINK,
|
|
178
|
-
O_SYNC,
|
|
179
|
-
O_TRUNC,
|
|
180
|
-
O_WRONLY,
|
|
181
|
-
R_OK,
|
|
182
|
-
S_IFBLK,
|
|
183
|
-
S_IFCHR,
|
|
184
|
-
S_IFDIR,
|
|
185
|
-
S_IFIFO,
|
|
186
|
-
S_IFLNK,
|
|
187
|
-
S_IFMT,
|
|
188
|
-
S_IFREG,
|
|
189
|
-
S_IFSOCK,
|
|
190
|
-
S_IRGRP,
|
|
191
|
-
S_IROTH,
|
|
192
|
-
S_IRUSR,
|
|
193
|
-
S_IRWXG,
|
|
194
|
-
S_IRWXO,
|
|
195
|
-
S_IRWXU,
|
|
196
|
-
S_IWGRP,
|
|
197
|
-
S_IWOTH,
|
|
198
|
-
S_IWUSR,
|
|
199
|
-
S_IXGRP,
|
|
200
|
-
S_IXOTH,
|
|
201
|
-
S_IXUSR,
|
|
202
|
-
UV_DIRENT_BLOCK,
|
|
203
|
-
UV_DIRENT_CHAR,
|
|
204
|
-
UV_DIRENT_DIR,
|
|
205
|
-
UV_DIRENT_FIFO,
|
|
206
|
-
UV_DIRENT_FILE,
|
|
207
|
-
UV_DIRENT_LINK,
|
|
208
|
-
UV_DIRENT_SOCKET,
|
|
209
|
-
UV_DIRENT_UNKNOWN,
|
|
210
|
-
UV_FS_COPYFILE_EXCL,
|
|
211
|
-
UV_FS_COPYFILE_FICLONE,
|
|
212
|
-
UV_FS_COPYFILE_FICLONE_FORCE,
|
|
213
|
-
UV_FS_O_FILEMAP,
|
|
214
|
-
UV_FS_SYMLINK_DIR,
|
|
215
|
-
UV_FS_SYMLINK_JUNCTION,
|
|
216
|
-
W_OK,
|
|
217
|
-
X_OK,
|
|
218
|
-
parseFlags
|
|
219
|
-
});
|
package/lib/promises.d.ts
DELETED
|
@@ -1,90 +0,0 @@
|
|
|
1
|
-
import { Buffer } from 'buffer';
|
|
2
|
-
import { Dirent } from '.';
|
|
3
|
-
declare global {
|
|
4
|
-
interface FileSystemCreateWritableOptions {
|
|
5
|
-
keepExistingData?: boolean;
|
|
6
|
-
}
|
|
7
|
-
interface FileSystemWritableFileStream extends WritableStream {
|
|
8
|
-
seek(position: number): Promise<void>;
|
|
9
|
-
truncate(size: number): Promise<void>;
|
|
10
|
-
write(data: string | ArrayBuffer | ArrayBufferView | Blob | DataView): Promise<void>;
|
|
11
|
-
}
|
|
12
|
-
interface FileSystemReadWriteOptions {
|
|
13
|
-
at: number;
|
|
14
|
-
}
|
|
15
|
-
interface FileSystemSyncAccessHandle {
|
|
16
|
-
close(): Promise<void>;
|
|
17
|
-
flush(): Promise<void>;
|
|
18
|
-
getSize(): Promise<number>;
|
|
19
|
-
read(buffer: ArrayBuffer | ArrayBufferView, options?: FileSystemReadWriteOptions): Promise<number>;
|
|
20
|
-
truncate(newSize: number): Promise<void>;
|
|
21
|
-
write(buffer: ArrayBuffer | ArrayBufferView, options?: FileSystemReadWriteOptions): Promise<number>;
|
|
22
|
-
}
|
|
23
|
-
interface FileSystemFileHandle {
|
|
24
|
-
createWritable(options?: FileSystemCreateWritableOptions): Promise<FileSystemWritableFileStream>;
|
|
25
|
-
createSyncAccessHandle(): Promise<FileSystemSyncAccessHandle>;
|
|
26
|
-
}
|
|
27
|
-
interface FileSystemDirectoryHandle {
|
|
28
|
-
entries(): AsyncIterable<[string, FileSystemHandle]>;
|
|
29
|
-
keys(): AsyncIterable<string>;
|
|
30
|
-
values(): AsyncIterable<FileSystemHandle>;
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
export interface EncodingOptions {
|
|
34
|
-
encoding?: BufferEncoding;
|
|
35
|
-
}
|
|
36
|
-
export declare function writeFile(path: string, data: string | ArrayBuffer | ArrayBufferView | Blob | DataView): Promise<void>;
|
|
37
|
-
export declare function appendFile(path: string, data: string | ArrayBuffer | ArrayBufferView | Blob | DataView): Promise<void>;
|
|
38
|
-
export declare function readFile(path: string, options?: BufferEncoding): Promise<string | Buffer<ArrayBuffer>>;
|
|
39
|
-
export interface ReadDirectoryOptions {
|
|
40
|
-
withFileTypes?: boolean;
|
|
41
|
-
}
|
|
42
|
-
export declare function readdir(path: string, options: ReadDirectoryOptions & {
|
|
43
|
-
withFileTypes: true;
|
|
44
|
-
}): Promise<Dirent[]>;
|
|
45
|
-
export declare function readdir(path: string, options?: ReadDirectoryOptions & {
|
|
46
|
-
withFileTypes?: false;
|
|
47
|
-
}): Promise<string[]>;
|
|
48
|
-
export interface MakeDirectoryOptions {
|
|
49
|
-
recursive?: boolean;
|
|
50
|
-
}
|
|
51
|
-
export declare function mkdir(path: string, options?: MakeDirectoryOptions): Promise<void>;
|
|
52
|
-
export interface RemoveOptions {
|
|
53
|
-
force?: boolean;
|
|
54
|
-
recursive?: boolean;
|
|
55
|
-
}
|
|
56
|
-
export declare function rm(path: string, options?: RemoveOptions): Promise<void>;
|
|
57
|
-
export { rm as unlink, rm as rmdir };
|
|
58
|
-
export interface CopyOptions {
|
|
59
|
-
force?: boolean;
|
|
60
|
-
recursive?: boolean;
|
|
61
|
-
}
|
|
62
|
-
export declare function cp(src: string, dst: string, options?: CopyOptions): Promise<void>;
|
|
63
|
-
export { cp as copyFile };
|
|
64
|
-
export declare function rename(oldPath: string, newPath: string): Promise<void>;
|
|
65
|
-
export declare function getHandle(path: string, kind: 'file'): Promise<FileSystemFileHandle>;
|
|
66
|
-
export declare function getHandle(path: string, kind: 'directory'): Promise<FileSystemDirectoryHandle>;
|
|
67
|
-
export declare function getHandle(path: string, kind?: FileSystemHandleKind): Promise<FileSystemHandle>;
|
|
68
|
-
export interface StatOptions {
|
|
69
|
-
}
|
|
70
|
-
export declare function stat(path: string, options?: StatOptions): Promise<{
|
|
71
|
-
isFile: () => boolean;
|
|
72
|
-
isDirectory: () => boolean;
|
|
73
|
-
}>;
|
|
74
|
-
export declare function access(path: string, mode?: number): Promise<void>;
|
|
75
|
-
interface FileHandleWriteResult<T> {
|
|
76
|
-
bytesWritten: number;
|
|
77
|
-
buffer: T;
|
|
78
|
-
}
|
|
79
|
-
declare class FileHandle {
|
|
80
|
-
private handle;
|
|
81
|
-
private flags;
|
|
82
|
-
private _streamTask?;
|
|
83
|
-
constructor(handle: FileSystemFileHandle, flags: number);
|
|
84
|
-
stream(): Promise<FileSystemWritableFileStream>;
|
|
85
|
-
readFile(encoding?: BufferEncoding): Promise<string | Buffer<ArrayBuffer>>;
|
|
86
|
-
write<T extends Uint8Array>(buffer: T, offset?: number, length?: number, position?: number): Promise<FileHandleWriteResult<T>>;
|
|
87
|
-
write(data: string, position?: number, encoding?: BufferEncoding): Promise<FileHandleWriteResult<string>>;
|
|
88
|
-
close(): Promise<void>;
|
|
89
|
-
}
|
|
90
|
-
export declare function open(path: string, flags: string | number, mode?: number): Promise<FileHandle>;
|
package/lib/promises.js
DELETED
|
@@ -1,325 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
7
|
-
var __export = (target, all) => {
|
|
8
|
-
for (var name in all)
|
|
9
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
-
};
|
|
11
|
-
var __copyProps = (to, from, except, desc) => {
|
|
12
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
-
for (let key of __getOwnPropNames(from))
|
|
14
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
-
}
|
|
17
|
-
return to;
|
|
18
|
-
};
|
|
19
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
20
|
-
|
|
21
|
-
// src/promises.ts
|
|
22
|
-
var promises_exports = {};
|
|
23
|
-
__export(promises_exports, {
|
|
24
|
-
access: () => access,
|
|
25
|
-
appendFile: () => appendFile,
|
|
26
|
-
copyFile: () => cp,
|
|
27
|
-
cp: () => cp,
|
|
28
|
-
getHandle: () => getHandle,
|
|
29
|
-
mkdir: () => mkdir,
|
|
30
|
-
open: () => open,
|
|
31
|
-
readFile: () => readFile,
|
|
32
|
-
readdir: () => readdir,
|
|
33
|
-
rename: () => rename,
|
|
34
|
-
rm: () => rm,
|
|
35
|
-
rmdir: () => rm,
|
|
36
|
-
stat: () => stat,
|
|
37
|
-
unlink: () => rm,
|
|
38
|
-
writeFile: () => writeFile
|
|
39
|
-
});
|
|
40
|
-
module.exports = __toCommonJS(promises_exports);
|
|
41
|
-
var import_buffer = require("buffer");
|
|
42
|
-
var import_constants = require("./constants");
|
|
43
|
-
var import__ = require(".");
|
|
44
|
-
var SystemError = class extends Error {
|
|
45
|
-
static {
|
|
46
|
-
__name(this, "SystemError");
|
|
47
|
-
}
|
|
48
|
-
constructor(message, options) {
|
|
49
|
-
super(`${options.code}: ${message}, ${options.syscall} '${options.path}'`);
|
|
50
|
-
}
|
|
51
|
-
};
|
|
52
|
-
var ENOENT = class extends SystemError {
|
|
53
|
-
static {
|
|
54
|
-
__name(this, "ENOENT");
|
|
55
|
-
}
|
|
56
|
-
constructor(syscall2, path) {
|
|
57
|
-
super("no such file or directory", {
|
|
58
|
-
errno: -2,
|
|
59
|
-
code: "EEXIST",
|
|
60
|
-
syscall: syscall2,
|
|
61
|
-
path
|
|
62
|
-
});
|
|
63
|
-
}
|
|
64
|
-
};
|
|
65
|
-
var EEXIST = class extends SystemError {
|
|
66
|
-
static {
|
|
67
|
-
__name(this, "EEXIST");
|
|
68
|
-
}
|
|
69
|
-
constructor(syscall2, path) {
|
|
70
|
-
super("file already exists", {
|
|
71
|
-
errno: -17,
|
|
72
|
-
code: "EEXIST",
|
|
73
|
-
syscall: syscall2,
|
|
74
|
-
path
|
|
75
|
-
});
|
|
76
|
-
}
|
|
77
|
-
};
|
|
78
|
-
var ENOTDIR = class extends SystemError {
|
|
79
|
-
static {
|
|
80
|
-
__name(this, "ENOTDIR");
|
|
81
|
-
}
|
|
82
|
-
constructor(syscall2, path) {
|
|
83
|
-
super("not a directory", {
|
|
84
|
-
errno: -20,
|
|
85
|
-
code: "ENOTDIR",
|
|
86
|
-
syscall: syscall2,
|
|
87
|
-
path
|
|
88
|
-
});
|
|
89
|
-
}
|
|
90
|
-
};
|
|
91
|
-
var EISDIR = class extends SystemError {
|
|
92
|
-
static {
|
|
93
|
-
__name(this, "EISDIR");
|
|
94
|
-
}
|
|
95
|
-
constructor(syscall2, path) {
|
|
96
|
-
super("illegal operation on a directory", {
|
|
97
|
-
errno: -21,
|
|
98
|
-
code: "EISDIR",
|
|
99
|
-
syscall: syscall2,
|
|
100
|
-
path
|
|
101
|
-
});
|
|
102
|
-
}
|
|
103
|
-
};
|
|
104
|
-
async function syscall(type, path, cb, dict) {
|
|
105
|
-
try {
|
|
106
|
-
return await cb();
|
|
107
|
-
} catch (e) {
|
|
108
|
-
if (!(e instanceof DOMException)) throw e;
|
|
109
|
-
const constructor = dict[e.code];
|
|
110
|
-
if (!constructor) throw e;
|
|
111
|
-
throw new constructor(type, path);
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
__name(syscall, "syscall");
|
|
115
|
-
async function getDirectoryHandle(type, path, parts, create) {
|
|
116
|
-
let root = await navigator.storage.getDirectory();
|
|
117
|
-
for (const part of parts) {
|
|
118
|
-
await syscall(type, path, async () => {
|
|
119
|
-
root = await root.getDirectoryHandle(part, { create });
|
|
120
|
-
}, {
|
|
121
|
-
[DOMException.TYPE_MISMATCH_ERR]: ENOTDIR,
|
|
122
|
-
[DOMException.NOT_FOUND_ERR]: ENOENT
|
|
123
|
-
});
|
|
124
|
-
}
|
|
125
|
-
return root;
|
|
126
|
-
}
|
|
127
|
-
__name(getDirectoryHandle, "getDirectoryHandle");
|
|
128
|
-
async function getParent(type, path, create = false) {
|
|
129
|
-
const parts = path.split("/").filter(Boolean);
|
|
130
|
-
const filename = parts.pop();
|
|
131
|
-
return [await getDirectoryHandle(type, path, parts, create), filename];
|
|
132
|
-
}
|
|
133
|
-
__name(getParent, "getParent");
|
|
134
|
-
async function getFileHandle(type, path, create = false) {
|
|
135
|
-
const [root, filename] = await getParent(type, path);
|
|
136
|
-
return syscall(type, path, () => root.getFileHandle(filename, { create }), {
|
|
137
|
-
[DOMException.TYPE_MISMATCH_ERR]: EISDIR,
|
|
138
|
-
[DOMException.NOT_FOUND_ERR]: ENOENT
|
|
139
|
-
});
|
|
140
|
-
}
|
|
141
|
-
__name(getFileHandle, "getFileHandle");
|
|
142
|
-
async function writeOrAppendFile(type, path, data, keepExistingData) {
|
|
143
|
-
const handle = await getFileHandle(type, path, true);
|
|
144
|
-
const stream = await handle.createWritable({ keepExistingData });
|
|
145
|
-
if (typeof data === "string") {
|
|
146
|
-
data = new TextEncoder().encode(data);
|
|
147
|
-
}
|
|
148
|
-
await stream.write(data);
|
|
149
|
-
await stream.close();
|
|
150
|
-
}
|
|
151
|
-
__name(writeOrAppendFile, "writeOrAppendFile");
|
|
152
|
-
async function writeFile(path, data) {
|
|
153
|
-
await writeOrAppendFile("write", path, data, false);
|
|
154
|
-
}
|
|
155
|
-
__name(writeFile, "writeFile");
|
|
156
|
-
async function appendFile(path, data) {
|
|
157
|
-
await writeOrAppendFile("append", path, data, true);
|
|
158
|
-
}
|
|
159
|
-
__name(appendFile, "appendFile");
|
|
160
|
-
async function _readFile(handle, encoding) {
|
|
161
|
-
const file = await handle.getFile();
|
|
162
|
-
if (encoding === "utf8" || encoding === "utf-8") {
|
|
163
|
-
return await file.text();
|
|
164
|
-
} else {
|
|
165
|
-
return import_buffer.Buffer.from(await file.arrayBuffer());
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
__name(_readFile, "_readFile");
|
|
169
|
-
async function readFile(path, options) {
|
|
170
|
-
const handle = await getFileHandle("read", path);
|
|
171
|
-
return await _readFile(handle, options);
|
|
172
|
-
}
|
|
173
|
-
__name(readFile, "readFile");
|
|
174
|
-
async function readdir(path, options = {}) {
|
|
175
|
-
const parts = path.split("/").filter(Boolean);
|
|
176
|
-
const root = await getDirectoryHandle("readdir", path, parts, false);
|
|
177
|
-
const results = [];
|
|
178
|
-
for await (const [name, handle] of root.entries()) {
|
|
179
|
-
results.push(options.withFileTypes ? new import__.Dirent(handle) : name);
|
|
180
|
-
}
|
|
181
|
-
return results;
|
|
182
|
-
}
|
|
183
|
-
__name(readdir, "readdir");
|
|
184
|
-
async function mkdir(path, options = {}) {
|
|
185
|
-
if (options.recursive) {
|
|
186
|
-
await getDirectoryHandle("mkdir", path, path.split("/").filter(Boolean), true);
|
|
187
|
-
return;
|
|
188
|
-
}
|
|
189
|
-
const [root, filename] = await getParent("mkdir", path);
|
|
190
|
-
try {
|
|
191
|
-
await root.getDirectoryHandle(filename);
|
|
192
|
-
} catch (e) {
|
|
193
|
-
if (!(e instanceof DOMException)) throw e;
|
|
194
|
-
if (e.code === DOMException.NOT_FOUND_ERR) {
|
|
195
|
-
await root.getDirectoryHandle(filename, { create: true });
|
|
196
|
-
return;
|
|
197
|
-
} else if (e.code === DOMException.TYPE_MISMATCH_ERR) {
|
|
198
|
-
throw new EEXIST("mkdir", path);
|
|
199
|
-
}
|
|
200
|
-
throw e;
|
|
201
|
-
}
|
|
202
|
-
throw new EEXIST("mkdir", path);
|
|
203
|
-
}
|
|
204
|
-
__name(mkdir, "mkdir");
|
|
205
|
-
async function rm(path, options = {}) {
|
|
206
|
-
try {
|
|
207
|
-
const [root, filename] = await getParent("rm", path);
|
|
208
|
-
await root.removeEntry(filename, { recursive: options.recursive });
|
|
209
|
-
} catch (e) {
|
|
210
|
-
if (options.force && e instanceof ENOENT) return;
|
|
211
|
-
throw e;
|
|
212
|
-
}
|
|
213
|
-
}
|
|
214
|
-
__name(rm, "rm");
|
|
215
|
-
async function cp(src, dst, options = {}) {
|
|
216
|
-
const oldHandle = await getHandle(src);
|
|
217
|
-
const newHandle = await getHandle(dst, oldHandle.kind);
|
|
218
|
-
if (oldHandle.kind === "file") {
|
|
219
|
-
const buffer = await oldHandle.getFile().then((file) => file.arrayBuffer());
|
|
220
|
-
const stream = await newHandle.createWritable();
|
|
221
|
-
await stream.write(buffer);
|
|
222
|
-
await stream.close();
|
|
223
|
-
} else {
|
|
224
|
-
for await (const name of oldHandle.keys()) {
|
|
225
|
-
await cp(src + "/" + name, dst + "/" + name);
|
|
226
|
-
}
|
|
227
|
-
}
|
|
228
|
-
}
|
|
229
|
-
__name(cp, "cp");
|
|
230
|
-
async function rename(oldPath, newPath) {
|
|
231
|
-
await cp(oldPath, newPath, { recursive: true });
|
|
232
|
-
await rm(oldPath, { recursive: true });
|
|
233
|
-
}
|
|
234
|
-
__name(rename, "rename");
|
|
235
|
-
async function getHandle(path, kind) {
|
|
236
|
-
const [root, filename] = await getParent("lstat", path, !!kind);
|
|
237
|
-
if (kind === "file") {
|
|
238
|
-
return await root.getFileHandle(filename, { create: true });
|
|
239
|
-
} else if (kind === "directory") {
|
|
240
|
-
return await root.getDirectoryHandle(filename, { create: true });
|
|
241
|
-
}
|
|
242
|
-
try {
|
|
243
|
-
return await root.getFileHandle(filename);
|
|
244
|
-
} catch {
|
|
245
|
-
return await root.getDirectoryHandle(filename);
|
|
246
|
-
}
|
|
247
|
-
}
|
|
248
|
-
__name(getHandle, "getHandle");
|
|
249
|
-
async function stat(path, options) {
|
|
250
|
-
const handle = await getHandle(path);
|
|
251
|
-
return {
|
|
252
|
-
isFile: /* @__PURE__ */ __name(() => handle.kind === "file", "isFile"),
|
|
253
|
-
isDirectory: /* @__PURE__ */ __name(() => handle.kind === "directory", "isDirectory")
|
|
254
|
-
};
|
|
255
|
-
}
|
|
256
|
-
__name(stat, "stat");
|
|
257
|
-
async function access(path, mode) {
|
|
258
|
-
await getHandle(path);
|
|
259
|
-
}
|
|
260
|
-
__name(access, "access");
|
|
261
|
-
var FileHandle = class {
|
|
262
|
-
constructor(handle, flags) {
|
|
263
|
-
this.handle = handle;
|
|
264
|
-
this.flags = flags;
|
|
265
|
-
}
|
|
266
|
-
static {
|
|
267
|
-
__name(this, "FileHandle");
|
|
268
|
-
}
|
|
269
|
-
_streamTask;
|
|
270
|
-
stream() {
|
|
271
|
-
return this._streamTask ||= this.handle.createWritable({
|
|
272
|
-
keepExistingData: !!(this.flags & import_constants.O_APPEND)
|
|
273
|
-
});
|
|
274
|
-
}
|
|
275
|
-
async readFile(encoding) {
|
|
276
|
-
return _readFile(this.handle, encoding);
|
|
277
|
-
}
|
|
278
|
-
async write(data, ...args) {
|
|
279
|
-
if (typeof data === "string") {
|
|
280
|
-
const result = await this.write(new TextEncoder().encode(data), void 0, void 0, args[1]);
|
|
281
|
-
return { ...result, buffer: data };
|
|
282
|
-
}
|
|
283
|
-
const offset = args[0] ?? 0;
|
|
284
|
-
const length = args[1] ?? data.byteLength - offset;
|
|
285
|
-
data = data.slice(offset, offset + length);
|
|
286
|
-
const stream = await this.stream();
|
|
287
|
-
await stream.write(data);
|
|
288
|
-
return { bytesWritten: data.byteLength, buffer: data };
|
|
289
|
-
}
|
|
290
|
-
async close() {
|
|
291
|
-
const stream = await this.stream();
|
|
292
|
-
await stream.close();
|
|
293
|
-
}
|
|
294
|
-
};
|
|
295
|
-
async function open(path, flags, mode) {
|
|
296
|
-
flags = (0, import_constants.parseFlags)(flags);
|
|
297
|
-
if (flags & import_constants.O_EXCL) {
|
|
298
|
-
try {
|
|
299
|
-
await getHandle(path);
|
|
300
|
-
} catch {
|
|
301
|
-
return new FileHandle(await getHandle(path, "file"), flags);
|
|
302
|
-
}
|
|
303
|
-
throw new EEXIST("open", path);
|
|
304
|
-
}
|
|
305
|
-
return new FileHandle(await getHandle(path, "file"), flags);
|
|
306
|
-
}
|
|
307
|
-
__name(open, "open");
|
|
308
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
309
|
-
0 && (module.exports = {
|
|
310
|
-
access,
|
|
311
|
-
appendFile,
|
|
312
|
-
copyFile,
|
|
313
|
-
cp,
|
|
314
|
-
getHandle,
|
|
315
|
-
mkdir,
|
|
316
|
-
open,
|
|
317
|
-
readFile,
|
|
318
|
-
readdir,
|
|
319
|
-
rename,
|
|
320
|
-
rm,
|
|
321
|
-
rmdir,
|
|
322
|
-
stat,
|
|
323
|
-
unlink,
|
|
324
|
-
writeFile
|
|
325
|
-
});
|