@di-framework/cli-plugin-platform 0.0.1 → 6.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +408 -0
- package/dist/actor-protocol.d.ts +4 -0
- package/dist/actor-protocol.js +162 -0
- package/dist/actors.d.ts +31 -0
- package/dist/actors.js +296 -0
- package/dist/args.d.ts +15 -0
- package/dist/args.js +66 -0
- package/dist/assets/http-adapter.js +876 -0
- package/dist/assets/platform/.gitignore.tmpl +6 -0
- package/dist/assets/platform/Pulumi.yaml.tmpl +6 -0
- package/dist/assets/platform/README.md +208 -0
- package/dist/assets/platform/index.ts.tmpl +2 -0
- package/dist/assets/platform/package.json.tmpl +18 -0
- package/dist/assets/platform/tsconfig.json +11 -0
- package/dist/assets/queue-adapter.js +60 -0
- package/dist/assets/sqlite/BUILD-INFO.txt +13 -0
- package/dist/assets/sqlite/SHA256SUMS +2 -0
- package/dist/assets/sqlite/di-framework-sqlite.wasm +0 -0
- package/dist/assets/sqlite/di-framework-sqlite.wit +337 -0
- package/dist/assets/wit/deps/LICENSE.md +8 -0
- package/dist/assets/wit/deps/di-framework-queues/package.wit +18 -0
- package/dist/assets/wit/deps/di-framework-sqlite/package.wit +211 -0
- package/dist/assets/wit/deps/wasi-cli/package.wit +70 -0
- package/dist/assets/wit/deps/wasi-clocks/package.wit +42 -0
- package/dist/assets/wit/deps/wasi-config/package.wit +15 -0
- package/dist/assets/wit/deps/wasi-filesystem/package.wit +184 -0
- package/dist/assets/wit/deps/wasi-http/package.wit +170 -0
- package/dist/assets/wit/deps/wasi-random/package.wit +17 -0
- package/dist/assets/wit/deps/wasi-sockets/package.wit +105 -0
- package/dist/assets/wit/deps/wasi-tls/package.wit +26 -0
- package/dist/assets/wit/deps/wasmcloud-blobstore/package.wit +153 -0
- package/dist/assets/wit/deps/wasmcloud-keyvalue/package.wit +370 -0
- package/dist/assets/wit/deps/wasmcloud-messaging/package.wit +125 -0
- package/dist/assets/wit/deps/wasmcloud-postgres/package.wit +435 -0
- package/dist/assets/wit/deps/wasmcloud-secrets/package.wit +80 -0
- package/dist/async-transform.d.ts +3 -0
- package/dist/async-transform.js +60 -0
- package/dist/bindings.d.ts +34 -0
- package/dist/bindings.js +307 -0
- package/dist/build.d.ts +29 -0
- package/dist/build.js +325 -0
- package/dist/command.d.ts +3 -0
- package/dist/command.js +141 -0
- package/dist/control/auth.d.ts +18 -0
- package/dist/control/auth.js +89 -0
- package/dist/control/cron.d.ts +7 -0
- package/dist/control/cron.js +86 -0
- package/dist/control/index.d.ts +4 -0
- package/dist/control/index.js +4 -0
- package/dist/control/network.d.ts +12 -0
- package/dist/control/network.js +49 -0
- package/dist/control/queues.d.ts +15 -0
- package/dist/control/queues.js +77 -0
- package/dist/cron.d.ts +26 -0
- package/dist/cron.js +239 -0
- package/dist/deploy.d.ts +29 -0
- package/dist/deploy.js +57 -0
- package/dist/deps.d.ts +96 -0
- package/dist/deps.js +303 -0
- package/dist/destroy.d.ts +3 -0
- package/dist/destroy.js +24 -0
- package/dist/dev-runner.d.ts +24 -0
- package/dist/dev-runner.js +83 -0
- package/dist/dev.d.ts +8 -0
- package/dist/dev.js +76 -0
- package/dist/discovery.d.ts +15 -0
- package/dist/discovery.js +182 -0
- package/dist/doctor.d.ts +8 -0
- package/dist/doctor.js +82 -0
- package/dist/guests.d.ts +9 -0
- package/dist/guests.js +56 -0
- package/dist/host-interface.d.ts +29 -0
- package/dist/host-interface.js +142 -0
- package/dist/index.d.ts +33 -0
- package/dist/index.js +39 -0
- package/dist/kubernetes.d.ts +9 -0
- package/dist/kubernetes.js +17 -0
- package/dist/managed-bindings.d.ts +9 -0
- package/dist/managed-bindings.js +150 -0
- package/dist/manifest.d.ts +36 -0
- package/dist/manifest.js +257 -0
- package/dist/namespace.d.ts +2 -0
- package/dist/namespace.js +4 -0
- package/dist/node-compat/async-hooks.d.ts +29 -0
- package/dist/node-compat/async-hooks.js +80 -0
- package/dist/node-compat/bootstrap.d.ts +1 -0
- package/dist/node-compat/bootstrap.js +9 -0
- package/dist/node-compat/bytes.d.ts +7 -0
- package/dist/node-compat/bytes.js +41 -0
- package/dist/node-compat/crypto-hash.d.ts +27 -0
- package/dist/node-compat/crypto-hash.js +108 -0
- package/dist/node-compat/crypto-subtle.d.ts +59 -0
- package/dist/node-compat/crypto-subtle.js +288 -0
- package/dist/node-compat/crypto.d.ts +136 -0
- package/dist/node-compat/crypto.js +142 -0
- package/dist/node-compat/dgram.d.ts +49 -0
- package/dist/node-compat/dgram.js +197 -0
- package/dist/node-compat/env.d.ts +6 -0
- package/dist/node-compat/env.js +88 -0
- package/dist/node-compat/fetch-runtime.d.ts +80 -0
- package/dist/node-compat/fetch-runtime.js +314 -0
- package/dist/node-compat/fs.d.ts +84 -0
- package/dist/node-compat/fs.js +285 -0
- package/dist/node-compat/http-parser.d.ts +40 -0
- package/dist/node-compat/http-parser.js +185 -0
- package/dist/node-compat/http.d.ts +130 -0
- package/dist/node-compat/http.js +688 -0
- package/dist/node-compat/https.d.ts +28 -0
- package/dist/node-compat/https.js +88 -0
- package/dist/node-compat/module.d.ts +11 -0
- package/dist/node-compat/module.js +35 -0
- package/dist/node-compat/net.d.ts +119 -0
- package/dist/node-compat/net.js +441 -0
- package/dist/node-compat/process.d.ts +25 -0
- package/dist/node-compat/process.js +63 -0
- package/dist/node-compat/runtime-application.d.ts +4 -0
- package/dist/node-compat/runtime-application.js +24 -0
- package/dist/node-compat/seed-virtual.d.ts +6 -0
- package/dist/node-compat/seed-virtual.js +6 -0
- package/dist/node-compat/seed.d.ts +20 -0
- package/dist/node-compat/seed.js +106 -0
- package/dist/node-compat/socket-address.d.ts +35 -0
- package/dist/node-compat/socket-address.js +162 -0
- package/dist/node-compat/timers.d.ts +32 -0
- package/dist/node-compat/timers.js +96 -0
- package/dist/node-compat/tls.d.ts +57 -0
- package/dist/node-compat/tls.js +290 -0
- package/dist/node-compat/wasi-random.d.ts +2 -0
- package/dist/node-compat/wasi-random.js +25 -0
- package/dist/node-compat/wasi-sockets.d.ts +47 -0
- package/dist/node-compat/wasi-sockets.js +134 -0
- package/dist/oci.d.ts +9 -0
- package/dist/oci.js +9 -0
- package/dist/paths.d.ts +7 -0
- package/dist/paths.js +13 -0
- package/dist/platform-init.d.ts +13 -0
- package/dist/platform-init.js +265 -0
- package/dist/platform.d.ts +22 -0
- package/dist/platform.js +170 -0
- package/dist/project.d.ts +39 -0
- package/dist/project.js +130 -0
- package/dist/publish.d.ts +15 -0
- package/dist/publish.js +57 -0
- package/dist/pulumi.d.ts +4 -0
- package/dist/pulumi.js +27 -0
- package/dist/queues-module.d.ts +4 -0
- package/dist/queues-module.js +89 -0
- package/dist/queues.d.ts +16 -0
- package/dist/queues.js +167 -0
- package/dist/registry.d.ts +16 -0
- package/dist/registry.js +27 -0
- package/dist/service.d.ts +162 -0
- package/dist/service.js +678 -0
- package/dist/support.d.ts +14 -0
- package/dist/support.js +37 -0
- package/dist/target.d.ts +18 -0
- package/dist/target.js +45 -0
- package/dist/toml.d.ts +6 -0
- package/dist/toml.js +245 -0
- package/dist/wash-dev.d.ts +18 -0
- package/dist/wash-dev.js +80 -0
- package/dist/wit.d.ts +76 -0
- package/dist/wit.js +248 -0
- package/dist/workload-members.d.ts +12 -0
- package/dist/workload-members.js +136 -0
- package/dist/workload.d.ts +45 -0
- package/dist/workload.js +457 -0
- package/package.json +55 -8
- package/src/index.ts +0 -2
|
@@ -0,0 +1,314 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Minimal Fetch/URL/encoding globals for QuickJS-based WASI 0.3 guests.
|
|
3
|
+
*
|
|
4
|
+
* WASI 0.3 async HTTP (`wasi:http/handler#handle`) is the component interface,
|
|
5
|
+
* not the WHATWG Fetch API. componentize-qjs embeds QuickJS, which has neither
|
|
6
|
+
* `Request`/`Response` nor `URLSearchParams`. StarlingMonkey does provide
|
|
7
|
+
* Fetch; install these polyfills only when those globals are missing so the
|
|
8
|
+
* application contract (`new Response(...)`) stays unchanged.
|
|
9
|
+
*/
|
|
10
|
+
export class TextEncoderPolyfill {
|
|
11
|
+
encode(input = '') {
|
|
12
|
+
const utf8 = unescape(encodeURIComponent(String(input)));
|
|
13
|
+
const bytes = new Uint8Array(utf8.length);
|
|
14
|
+
for (let i = 0; i < utf8.length; i++)
|
|
15
|
+
bytes[i] = utf8.charCodeAt(i);
|
|
16
|
+
return bytes;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
export class TextDecoderPolyfill {
|
|
20
|
+
decode(input) {
|
|
21
|
+
if (input == null)
|
|
22
|
+
return '';
|
|
23
|
+
const bytes = input instanceof ArrayBuffer
|
|
24
|
+
? new Uint8Array(input)
|
|
25
|
+
: new Uint8Array(input.buffer, input.byteOffset, input.byteLength);
|
|
26
|
+
let binary = '';
|
|
27
|
+
for (let i = 0; i < bytes.length; i++)
|
|
28
|
+
binary += String.fromCharCode(bytes[i] ?? 0);
|
|
29
|
+
return decodeURIComponent(escape(binary));
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
export class URLSearchParamsPolyfill {
|
|
33
|
+
#pairs = [];
|
|
34
|
+
constructor(init) {
|
|
35
|
+
if (typeof init === 'string') {
|
|
36
|
+
const query = init.startsWith('?') ? init.slice(1) : init;
|
|
37
|
+
if (query !== '') {
|
|
38
|
+
for (const part of query.split('&')) {
|
|
39
|
+
const eq = part.indexOf('=');
|
|
40
|
+
const name = decodeURIComponent(eq === -1 ? part : part.slice(0, eq));
|
|
41
|
+
const value = decodeURIComponent(eq === -1 ? '' : part.slice(eq + 1));
|
|
42
|
+
this.#pairs.push([name, value]);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
else if (init instanceof URLSearchParamsPolyfill) {
|
|
47
|
+
this.#pairs = init.#pairs.map(([name, value]) => [name, value]);
|
|
48
|
+
}
|
|
49
|
+
else if (init && typeof init === 'object') {
|
|
50
|
+
for (const [name, value] of Object.entries(init))
|
|
51
|
+
this.#pairs.push([name, String(value)]);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
get(name) {
|
|
55
|
+
const found = this.#pairs.find(([key]) => key === name);
|
|
56
|
+
return found ? found[1] : null;
|
|
57
|
+
}
|
|
58
|
+
*entries() {
|
|
59
|
+
yield* this.#pairs;
|
|
60
|
+
}
|
|
61
|
+
[Symbol.iterator]() {
|
|
62
|
+
return this.entries();
|
|
63
|
+
}
|
|
64
|
+
toString() {
|
|
65
|
+
return this.#pairs
|
|
66
|
+
.map(([name, value]) => `${encodeURIComponent(name)}=${encodeURIComponent(value)}`)
|
|
67
|
+
.join('&');
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
export class URLPolyfill {
|
|
71
|
+
href;
|
|
72
|
+
protocol;
|
|
73
|
+
hostname;
|
|
74
|
+
host;
|
|
75
|
+
port;
|
|
76
|
+
pathname;
|
|
77
|
+
search;
|
|
78
|
+
hash;
|
|
79
|
+
origin;
|
|
80
|
+
searchParams;
|
|
81
|
+
constructor(url, base) {
|
|
82
|
+
const resolved = resolveUrl(String(url), base === undefined ? undefined : String(base));
|
|
83
|
+
const match = resolved.match(/^([a-zA-Z][a-zA-Z0-9+.-]*:)(\/\/)?([^/?#]*)([^?#]*)(\?[^#]*)?(#.*)?$/) ?? ['', 'http:', '//', '', '/', '', ''];
|
|
84
|
+
this.protocol = match[1] ?? 'http:';
|
|
85
|
+
this.host = match[3] ?? '';
|
|
86
|
+
const hostParts = this.host.split(':');
|
|
87
|
+
this.hostname = hostParts[0] ?? '';
|
|
88
|
+
this.port = hostParts.length > 1 ? (hostParts[hostParts.length - 1] ?? '') : '';
|
|
89
|
+
this.pathname = match[4] || '/';
|
|
90
|
+
this.search = match[5] ?? '';
|
|
91
|
+
this.hash = match[6] ?? '';
|
|
92
|
+
this.origin = `${this.protocol}//${this.host}`;
|
|
93
|
+
this.href = resolved;
|
|
94
|
+
this.searchParams = new URLSearchParamsPolyfill(this.search);
|
|
95
|
+
}
|
|
96
|
+
toString() {
|
|
97
|
+
return this.href;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
function resolveUrl(url, base) {
|
|
101
|
+
if (/^[a-zA-Z][a-zA-Z0-9+.-]*:/.test(url))
|
|
102
|
+
return url;
|
|
103
|
+
if (base === undefined)
|
|
104
|
+
throw new TypeError(`Invalid URL: ${url}`);
|
|
105
|
+
const baseUrl = new URLPolyfill(base);
|
|
106
|
+
if (url.startsWith('/'))
|
|
107
|
+
return `${baseUrl.origin}${url}`;
|
|
108
|
+
const directory = baseUrl.pathname.slice(0, baseUrl.pathname.lastIndexOf('/') + 1);
|
|
109
|
+
return `${baseUrl.origin}${directory}${url}`;
|
|
110
|
+
}
|
|
111
|
+
export class HeadersPolyfill {
|
|
112
|
+
#map = new Map();
|
|
113
|
+
constructor(init) {
|
|
114
|
+
if (init instanceof HeadersPolyfill) {
|
|
115
|
+
for (const [name, value] of init.entries())
|
|
116
|
+
this.append(name, value);
|
|
117
|
+
}
|
|
118
|
+
else if (Array.isArray(init)) {
|
|
119
|
+
for (const [name, value] of init)
|
|
120
|
+
this.append(name, value);
|
|
121
|
+
}
|
|
122
|
+
else if (init) {
|
|
123
|
+
for (const [name, value] of Object.entries(init))
|
|
124
|
+
this.append(name, value);
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
#key(name) {
|
|
128
|
+
return name.toLowerCase();
|
|
129
|
+
}
|
|
130
|
+
append(name, value) {
|
|
131
|
+
const key = this.#key(name);
|
|
132
|
+
const existing = this.#map.get(key) ?? [];
|
|
133
|
+
existing.push(String(value));
|
|
134
|
+
this.#map.set(key, existing);
|
|
135
|
+
}
|
|
136
|
+
set(name, value) {
|
|
137
|
+
this.#map.set(this.#key(name), [String(value)]);
|
|
138
|
+
}
|
|
139
|
+
get(name) {
|
|
140
|
+
const values = this.#map.get(this.#key(name));
|
|
141
|
+
return values === undefined ? null : values.join(', ');
|
|
142
|
+
}
|
|
143
|
+
has(name) {
|
|
144
|
+
return this.#map.has(this.#key(name));
|
|
145
|
+
}
|
|
146
|
+
delete(name) {
|
|
147
|
+
this.#map.delete(this.#key(name));
|
|
148
|
+
}
|
|
149
|
+
*entries() {
|
|
150
|
+
for (const [name, values] of this.#map) {
|
|
151
|
+
for (const value of values)
|
|
152
|
+
yield [name, value];
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
forEach(callback) {
|
|
156
|
+
for (const [name, value] of this.entries())
|
|
157
|
+
callback(value, name, this);
|
|
158
|
+
}
|
|
159
|
+
[Symbol.iterator]() {
|
|
160
|
+
return this.entries();
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
export function isAsyncIterable(value) {
|
|
164
|
+
return value != null && typeof value === 'object' && Symbol.asyncIterator in value;
|
|
165
|
+
}
|
|
166
|
+
function toBodySource(body) {
|
|
167
|
+
if (body == null)
|
|
168
|
+
return null;
|
|
169
|
+
if (body instanceof Uint8Array)
|
|
170
|
+
return body;
|
|
171
|
+
if (body instanceof ArrayBuffer)
|
|
172
|
+
return new Uint8Array(body);
|
|
173
|
+
if (isAsyncIterable(body))
|
|
174
|
+
return body;
|
|
175
|
+
if (typeof body === 'string')
|
|
176
|
+
return new TextEncoderPolyfill().encode(body);
|
|
177
|
+
return new TextEncoderPolyfill().encode(String(body));
|
|
178
|
+
}
|
|
179
|
+
export async function collectBytes(source) {
|
|
180
|
+
if (source == null)
|
|
181
|
+
return new Uint8Array();
|
|
182
|
+
if (source instanceof Uint8Array)
|
|
183
|
+
return source;
|
|
184
|
+
const chunks = [];
|
|
185
|
+
let total = 0;
|
|
186
|
+
for await (const chunk of source) {
|
|
187
|
+
const bytes = chunk instanceof Uint8Array
|
|
188
|
+
? chunk
|
|
189
|
+
: typeof chunk === 'number'
|
|
190
|
+
? new Uint8Array([chunk])
|
|
191
|
+
: new Uint8Array(chunk);
|
|
192
|
+
chunks.push(bytes);
|
|
193
|
+
total += bytes.length;
|
|
194
|
+
}
|
|
195
|
+
const body = new Uint8Array(total);
|
|
196
|
+
let offset = 0;
|
|
197
|
+
for (const chunk of chunks) {
|
|
198
|
+
body.set(chunk, offset);
|
|
199
|
+
offset += chunk.length;
|
|
200
|
+
}
|
|
201
|
+
return body;
|
|
202
|
+
}
|
|
203
|
+
async function* bytesAsStream(bytes) {
|
|
204
|
+
if (bytes.length > 0)
|
|
205
|
+
yield bytes;
|
|
206
|
+
}
|
|
207
|
+
export function bodyAsStream(source) {
|
|
208
|
+
if (source == null)
|
|
209
|
+
return null;
|
|
210
|
+
if (source instanceof Uint8Array)
|
|
211
|
+
return bytesAsStream(source);
|
|
212
|
+
return source;
|
|
213
|
+
}
|
|
214
|
+
export class RequestPolyfill {
|
|
215
|
+
method;
|
|
216
|
+
url;
|
|
217
|
+
headers;
|
|
218
|
+
#body;
|
|
219
|
+
constructor(input, init = {}) {
|
|
220
|
+
if (input instanceof RequestPolyfill) {
|
|
221
|
+
this.method = String(init.method ?? input.method);
|
|
222
|
+
this.url = input.url;
|
|
223
|
+
this.headers = new HeadersPolyfill(init.headers ?? input.headers);
|
|
224
|
+
this.#body = init.body === undefined ? input.#body : toBodySource(init.body);
|
|
225
|
+
}
|
|
226
|
+
else {
|
|
227
|
+
this.method = String(init.method ?? 'GET').toUpperCase();
|
|
228
|
+
this.url = String(input);
|
|
229
|
+
this.headers = new HeadersPolyfill(init.headers);
|
|
230
|
+
this.#body = toBodySource(init.body);
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
get body() {
|
|
234
|
+
return bodyAsStream(this.#body);
|
|
235
|
+
}
|
|
236
|
+
clone() {
|
|
237
|
+
const body = this.#body instanceof Uint8Array ? this.#body.slice() : this.#body;
|
|
238
|
+
return new RequestPolyfill(this, { body });
|
|
239
|
+
}
|
|
240
|
+
async arrayBuffer() {
|
|
241
|
+
const bytes = await collectBytes(this.#body);
|
|
242
|
+
this.#body = bytes;
|
|
243
|
+
return bytes.buffer.slice(bytes.byteOffset, bytes.byteOffset + bytes.byteLength);
|
|
244
|
+
}
|
|
245
|
+
async text() {
|
|
246
|
+
return new TextDecoderPolyfill().decode(new Uint8Array(await this.arrayBuffer()));
|
|
247
|
+
}
|
|
248
|
+
async json() {
|
|
249
|
+
return JSON.parse(await this.text());
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
export class ResponsePolyfill {
|
|
253
|
+
status;
|
|
254
|
+
statusText;
|
|
255
|
+
headers;
|
|
256
|
+
ok;
|
|
257
|
+
#body;
|
|
258
|
+
constructor(body, init = {}) {
|
|
259
|
+
this.status = Number(init.status ?? 200);
|
|
260
|
+
this.statusText = String(init.statusText ?? '');
|
|
261
|
+
this.headers = new HeadersPolyfill(init.headers);
|
|
262
|
+
this.ok = this.status >= 200 && this.status < 300;
|
|
263
|
+
this.#body = toBodySource(body);
|
|
264
|
+
}
|
|
265
|
+
static json(data, init = {}) {
|
|
266
|
+
const headers = new HeadersPolyfill(init.headers);
|
|
267
|
+
if (!headers.has('content-type'))
|
|
268
|
+
headers.set('content-type', 'application/json');
|
|
269
|
+
return new ResponsePolyfill(JSON.stringify(data), { ...init, headers });
|
|
270
|
+
}
|
|
271
|
+
get body() {
|
|
272
|
+
return bodyAsStream(this.#body);
|
|
273
|
+
}
|
|
274
|
+
async arrayBuffer() {
|
|
275
|
+
const bytes = await collectBytes(this.#body);
|
|
276
|
+
this.#body = bytes;
|
|
277
|
+
return bytes.buffer.slice(bytes.byteOffset, bytes.byteOffset + bytes.byteLength);
|
|
278
|
+
}
|
|
279
|
+
async text() {
|
|
280
|
+
return new TextDecoderPolyfill().decode(new Uint8Array(await this.arrayBuffer()));
|
|
281
|
+
}
|
|
282
|
+
async json() {
|
|
283
|
+
return JSON.parse(await this.text());
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
const noopConsole = {
|
|
287
|
+
log() { },
|
|
288
|
+
info() { },
|
|
289
|
+
warn() { },
|
|
290
|
+
error() { },
|
|
291
|
+
debug() { },
|
|
292
|
+
};
|
|
293
|
+
export function installFetchRuntime(force = false) {
|
|
294
|
+
const global = globalThis;
|
|
295
|
+
if (force || typeof global.TextEncoder !== 'function')
|
|
296
|
+
global.TextEncoder = TextEncoderPolyfill;
|
|
297
|
+
if (force || typeof global.TextDecoder !== 'function')
|
|
298
|
+
global.TextDecoder = TextDecoderPolyfill;
|
|
299
|
+
if (force || typeof global.URLSearchParams !== 'function') {
|
|
300
|
+
global.URLSearchParams = URLSearchParamsPolyfill;
|
|
301
|
+
}
|
|
302
|
+
if (force || typeof global.URL !== 'function')
|
|
303
|
+
global.URL = URLPolyfill;
|
|
304
|
+
if (force || typeof global.Headers !== 'function')
|
|
305
|
+
global.Headers = HeadersPolyfill;
|
|
306
|
+
if (force || typeof global.Request !== 'function')
|
|
307
|
+
global.Request = RequestPolyfill;
|
|
308
|
+
if (force || typeof global.Response !== 'function')
|
|
309
|
+
global.Response = ResponsePolyfill;
|
|
310
|
+
if (force || typeof global.console !== 'object' || global.console === null) {
|
|
311
|
+
global.console = noopConsole;
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
installFetchRuntime();
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
export declare function normalizeFsPath(path: string, cwd?: string): string;
|
|
2
|
+
export declare function readFileSync(path: string, encoding?: string | {
|
|
3
|
+
encoding?: string | null;
|
|
4
|
+
}): string | Uint8Array;
|
|
5
|
+
export declare function writeFileSync(path: string, data: string | Uint8Array, _encoding?: string | {
|
|
6
|
+
encoding?: string | null;
|
|
7
|
+
}): void;
|
|
8
|
+
export declare function existsSync(path: string): boolean;
|
|
9
|
+
export declare function mkdirSync(path: string, options?: {
|
|
10
|
+
recursive?: boolean;
|
|
11
|
+
} | number): string | undefined;
|
|
12
|
+
export declare function readdirSync(path: string, options?: {
|
|
13
|
+
withFileTypes?: boolean;
|
|
14
|
+
} | string | null): string[] | Array<{
|
|
15
|
+
name: string;
|
|
16
|
+
isFile(): boolean;
|
|
17
|
+
isDirectory(): boolean;
|
|
18
|
+
}>;
|
|
19
|
+
export declare function statSync(path: string): {
|
|
20
|
+
isFile(): boolean;
|
|
21
|
+
isDirectory(): boolean;
|
|
22
|
+
size: number;
|
|
23
|
+
mtimeMs: number;
|
|
24
|
+
};
|
|
25
|
+
export declare function lstatSync(path: string): {
|
|
26
|
+
isFile(): boolean;
|
|
27
|
+
isDirectory(): boolean;
|
|
28
|
+
size: number;
|
|
29
|
+
mtimeMs: number;
|
|
30
|
+
};
|
|
31
|
+
export declare function fstatSync(fd: number): {
|
|
32
|
+
isFile(): boolean;
|
|
33
|
+
isDirectory(): boolean;
|
|
34
|
+
size: number;
|
|
35
|
+
mtimeMs: number;
|
|
36
|
+
};
|
|
37
|
+
export declare function openSync(path: string, flags?: string | number, _mode?: number): number;
|
|
38
|
+
export declare function closeSync(fd: number): void;
|
|
39
|
+
export declare function readSync(fd: number, buffer: Uint8Array, offset?: number, length?: number, position?: number | null): number;
|
|
40
|
+
export declare function writeSync(fd: number, data: string | Uint8Array, offset?: number, length?: number, position?: number | null): number;
|
|
41
|
+
export declare function createReadStream(path: string): {
|
|
42
|
+
on(event: string, listener: (...args: unknown[]) => void): unknown;
|
|
43
|
+
once(event: string, listener: (...args: unknown[]) => void): unknown;
|
|
44
|
+
[Symbol.asyncIterator](): AsyncGenerator<Uint8Array>;
|
|
45
|
+
};
|
|
46
|
+
export declare function rmSync(path: string, options?: {
|
|
47
|
+
recursive?: boolean;
|
|
48
|
+
force?: boolean;
|
|
49
|
+
}): void;
|
|
50
|
+
export declare function unlinkSync(path: string): void;
|
|
51
|
+
export declare function renameSync(from: string, to: string): void;
|
|
52
|
+
export declare const constants: {
|
|
53
|
+
F_OK: number;
|
|
54
|
+
R_OK: number;
|
|
55
|
+
W_OK: number;
|
|
56
|
+
X_OK: number;
|
|
57
|
+
};
|
|
58
|
+
export declare function accessSync(path: string, _mode?: number): void;
|
|
59
|
+
declare const _default: {
|
|
60
|
+
accessSync: typeof accessSync;
|
|
61
|
+
closeSync: typeof closeSync;
|
|
62
|
+
constants: {
|
|
63
|
+
F_OK: number;
|
|
64
|
+
R_OK: number;
|
|
65
|
+
W_OK: number;
|
|
66
|
+
X_OK: number;
|
|
67
|
+
};
|
|
68
|
+
createReadStream: typeof createReadStream;
|
|
69
|
+
existsSync: typeof existsSync;
|
|
70
|
+
fstatSync: typeof fstatSync;
|
|
71
|
+
lstatSync: typeof lstatSync;
|
|
72
|
+
mkdirSync: typeof mkdirSync;
|
|
73
|
+
openSync: typeof openSync;
|
|
74
|
+
readFileSync: typeof readFileSync;
|
|
75
|
+
readSync: typeof readSync;
|
|
76
|
+
readdirSync: typeof readdirSync;
|
|
77
|
+
renameSync: typeof renameSync;
|
|
78
|
+
rmSync: typeof rmSync;
|
|
79
|
+
statSync: typeof statSync;
|
|
80
|
+
unlinkSync: typeof unlinkSync;
|
|
81
|
+
writeFileSync: typeof writeFileSync;
|
|
82
|
+
writeSync: typeof writeSync;
|
|
83
|
+
};
|
|
84
|
+
export default _default;
|
|
@@ -0,0 +1,285 @@
|
|
|
1
|
+
import { nodeCompatSeed } from './seed-virtual.js';
|
|
2
|
+
function errno(code, syscall, path, errnoValue) {
|
|
3
|
+
const error = new Error(`${code}: no such file or directory, ${syscall} '${path}'`);
|
|
4
|
+
error.code = code;
|
|
5
|
+
error.errno = errnoValue;
|
|
6
|
+
error.syscall = syscall;
|
|
7
|
+
error.path = path;
|
|
8
|
+
return error;
|
|
9
|
+
}
|
|
10
|
+
export function normalizeFsPath(path, cwd = nodeCompatSeed.cwd) {
|
|
11
|
+
const base = path.startsWith('/') ? path : `${cwd.replace(/\/$/, '')}/${path}`;
|
|
12
|
+
const parts = [];
|
|
13
|
+
for (const part of base.split('/')) {
|
|
14
|
+
if (part === '' || part === '.')
|
|
15
|
+
continue;
|
|
16
|
+
if (part === '..')
|
|
17
|
+
parts.pop();
|
|
18
|
+
else
|
|
19
|
+
parts.push(part);
|
|
20
|
+
}
|
|
21
|
+
return `/${parts.join('/')}`;
|
|
22
|
+
}
|
|
23
|
+
function encodingName(encoding) {
|
|
24
|
+
if (typeof encoding === 'string')
|
|
25
|
+
return encoding;
|
|
26
|
+
if (encoding !== null && typeof encoding === 'object' && 'encoding' in encoding) {
|
|
27
|
+
const value = encoding.encoding;
|
|
28
|
+
return typeof value === 'string' ? value : undefined;
|
|
29
|
+
}
|
|
30
|
+
return undefined;
|
|
31
|
+
}
|
|
32
|
+
function asText(data) {
|
|
33
|
+
return typeof data === 'string' ? data : new TextDecoder().decode(data);
|
|
34
|
+
}
|
|
35
|
+
function asBytes(data) {
|
|
36
|
+
return typeof data === 'string' ? new TextEncoder().encode(data) : data;
|
|
37
|
+
}
|
|
38
|
+
export function readFileSync(path, encoding) {
|
|
39
|
+
const normalized = normalizeFsPath(String(path));
|
|
40
|
+
const content = nodeCompatSeed.files[normalized];
|
|
41
|
+
if (content === undefined) {
|
|
42
|
+
throw errno('ENOENT', 'open', normalized, -2);
|
|
43
|
+
}
|
|
44
|
+
if (encodingName(encoding) !== undefined)
|
|
45
|
+
return content;
|
|
46
|
+
const bytes = new TextEncoder().encode(content);
|
|
47
|
+
return typeof Buffer === 'undefined' ? bytes : Buffer.from(bytes);
|
|
48
|
+
}
|
|
49
|
+
export function writeFileSync(path, data, _encoding) {
|
|
50
|
+
nodeCompatSeed.files[normalizeFsPath(String(path))] = asText(data);
|
|
51
|
+
}
|
|
52
|
+
function directoryKey(path) {
|
|
53
|
+
const normalized = normalizeFsPath(path).replace(/\/$/, '');
|
|
54
|
+
return normalized === '' ? '/' : `${normalized}/`;
|
|
55
|
+
}
|
|
56
|
+
export function existsSync(path) {
|
|
57
|
+
const normalized = normalizeFsPath(String(path));
|
|
58
|
+
return normalized in nodeCompatSeed.files || directoryKey(normalized) in nodeCompatSeed.files;
|
|
59
|
+
}
|
|
60
|
+
export function mkdirSync(path, options) {
|
|
61
|
+
const normalized = normalizeFsPath(String(path)).replace(/\/$/, '') || '/';
|
|
62
|
+
const recursive = typeof options === 'object' && options?.recursive === true;
|
|
63
|
+
if (normalized in nodeCompatSeed.files || directoryKey(normalized) in nodeCompatSeed.files) {
|
|
64
|
+
if (recursive)
|
|
65
|
+
return undefined;
|
|
66
|
+
const error = errno('EEXIST', 'mkdir', normalized, -17);
|
|
67
|
+
error.message = `EEXIST: file already exists, mkdir '${normalized}'`;
|
|
68
|
+
throw error;
|
|
69
|
+
}
|
|
70
|
+
if (recursive) {
|
|
71
|
+
const parts = normalized.split('/').filter(Boolean);
|
|
72
|
+
let current = '';
|
|
73
|
+
for (const part of parts) {
|
|
74
|
+
current += `/${part}`;
|
|
75
|
+
nodeCompatSeed.files[directoryKey(current)] = '';
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
else {
|
|
79
|
+
nodeCompatSeed.files[directoryKey(normalized)] = '';
|
|
80
|
+
}
|
|
81
|
+
return recursive ? normalized : undefined;
|
|
82
|
+
}
|
|
83
|
+
export function readdirSync(path, options) {
|
|
84
|
+
const normalized = normalizeFsPath(String(path)).replace(/\/$/, '') || '/';
|
|
85
|
+
const prefix = normalized === '/' ? '/' : `${normalized}/`;
|
|
86
|
+
const names = new Set();
|
|
87
|
+
for (const key of Object.keys(nodeCompatSeed.files)) {
|
|
88
|
+
if (!key.startsWith(prefix) || key === prefix)
|
|
89
|
+
continue;
|
|
90
|
+
const rest = key.slice(prefix.length);
|
|
91
|
+
const name = rest.split('/')[0];
|
|
92
|
+
if (name)
|
|
93
|
+
names.add(name.replace(/\/$/, ''));
|
|
94
|
+
}
|
|
95
|
+
const list = [...names].sort();
|
|
96
|
+
const withFileTypes = options !== null && typeof options === 'object' && options.withFileTypes === true;
|
|
97
|
+
if (!withFileTypes)
|
|
98
|
+
return list;
|
|
99
|
+
return list.map((name) => {
|
|
100
|
+
const child = normalizeFsPath(`${normalized}/${name}`);
|
|
101
|
+
const isDirectory = directoryKey(child) in nodeCompatSeed.files && !(child in nodeCompatSeed.files);
|
|
102
|
+
return {
|
|
103
|
+
name,
|
|
104
|
+
isFile: () => !isDirectory,
|
|
105
|
+
isDirectory: () => isDirectory,
|
|
106
|
+
};
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
export function statSync(path) {
|
|
110
|
+
const normalized = normalizeFsPath(String(path));
|
|
111
|
+
const content = nodeCompatSeed.files[normalized];
|
|
112
|
+
if (content !== undefined) {
|
|
113
|
+
return {
|
|
114
|
+
isFile: () => true,
|
|
115
|
+
isDirectory: () => false,
|
|
116
|
+
size: new TextEncoder().encode(content).byteLength,
|
|
117
|
+
mtimeMs: Date.now(),
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
if (directoryKey(normalized) in nodeCompatSeed.files) {
|
|
121
|
+
return {
|
|
122
|
+
isFile: () => false,
|
|
123
|
+
isDirectory: () => true,
|
|
124
|
+
size: 0,
|
|
125
|
+
mtimeMs: Date.now(),
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
throw errno('ENOENT', 'stat', normalized, -2);
|
|
129
|
+
}
|
|
130
|
+
export function lstatSync(path) {
|
|
131
|
+
return statSync(path);
|
|
132
|
+
}
|
|
133
|
+
export function fstatSync(fd) {
|
|
134
|
+
const handle = openHandles.get(fd);
|
|
135
|
+
if (handle === undefined)
|
|
136
|
+
throw errno('EBADF', 'fstat', String(fd), -9);
|
|
137
|
+
return statSync(handle.path);
|
|
138
|
+
}
|
|
139
|
+
let nextFd = 3;
|
|
140
|
+
const openHandles = new Map();
|
|
141
|
+
export function openSync(path, flags = 'r', _mode) {
|
|
142
|
+
const normalized = normalizeFsPath(String(path));
|
|
143
|
+
const flag = typeof flags === 'string' ? flags : 'r';
|
|
144
|
+
const writing = flag.includes('w') || flag.includes('a') || flag.includes('+');
|
|
145
|
+
if (!(normalized in nodeCompatSeed.files) && !writing) {
|
|
146
|
+
throw errno('ENOENT', 'open', normalized, -2);
|
|
147
|
+
}
|
|
148
|
+
if (writing && !(normalized in nodeCompatSeed.files)) {
|
|
149
|
+
nodeCompatSeed.files[normalized] = '';
|
|
150
|
+
}
|
|
151
|
+
const fd = nextFd++;
|
|
152
|
+
openHandles.set(fd, {
|
|
153
|
+
path: normalized,
|
|
154
|
+
position: flag.includes('a') ? Number.MAX_SAFE_INTEGER : 0,
|
|
155
|
+
flags: flag,
|
|
156
|
+
});
|
|
157
|
+
return fd;
|
|
158
|
+
}
|
|
159
|
+
export function closeSync(fd) {
|
|
160
|
+
if (!openHandles.delete(fd))
|
|
161
|
+
throw errno('EBADF', 'close', String(fd), -9);
|
|
162
|
+
}
|
|
163
|
+
export function readSync(fd, buffer, offset = 0, length = buffer.byteLength - offset, position = null) {
|
|
164
|
+
const handle = openHandles.get(fd);
|
|
165
|
+
if (handle === undefined)
|
|
166
|
+
throw errno('EBADF', 'read', String(fd), -9);
|
|
167
|
+
const content = asBytes(nodeCompatSeed.files[handle.path] ?? '');
|
|
168
|
+
const start = position === null ? handle.position : position;
|
|
169
|
+
const slice = content.subarray(start, start + length);
|
|
170
|
+
buffer.set(slice, offset);
|
|
171
|
+
if (position === null)
|
|
172
|
+
handle.position = start + slice.byteLength;
|
|
173
|
+
return slice.byteLength;
|
|
174
|
+
}
|
|
175
|
+
export function writeSync(fd, data, offset, length, position) {
|
|
176
|
+
const handle = openHandles.get(fd);
|
|
177
|
+
if (handle === undefined)
|
|
178
|
+
throw errno('EBADF', 'write', String(fd), -9);
|
|
179
|
+
const bytes = asBytes(data).subarray(offset ?? 0, (offset ?? 0) + (length ?? asBytes(data).byteLength));
|
|
180
|
+
const existing = asBytes(nodeCompatSeed.files[handle.path] ?? '');
|
|
181
|
+
const start = position == null
|
|
182
|
+
? handle.flags.includes('a')
|
|
183
|
+
? existing.byteLength
|
|
184
|
+
: handle.position
|
|
185
|
+
: position;
|
|
186
|
+
const next = new Uint8Array(Math.max(existing.byteLength, start + bytes.byteLength));
|
|
187
|
+
next.set(existing, 0);
|
|
188
|
+
next.set(bytes, start);
|
|
189
|
+
nodeCompatSeed.files[handle.path] = new TextDecoder().decode(next);
|
|
190
|
+
if (position == null)
|
|
191
|
+
handle.position = start + bytes.byteLength;
|
|
192
|
+
return bytes.byteLength;
|
|
193
|
+
}
|
|
194
|
+
export function createReadStream(path) {
|
|
195
|
+
const data = asBytes(readFileSync(path));
|
|
196
|
+
const listeners = new Map();
|
|
197
|
+
const stream = {
|
|
198
|
+
on(event, listener) {
|
|
199
|
+
const list = listeners.get(event) ?? [];
|
|
200
|
+
list.push(listener);
|
|
201
|
+
listeners.set(event, list);
|
|
202
|
+
if (event === 'data')
|
|
203
|
+
queueMicrotask(() => listener(data));
|
|
204
|
+
if (event === 'end')
|
|
205
|
+
queueMicrotask(() => listener());
|
|
206
|
+
return stream;
|
|
207
|
+
},
|
|
208
|
+
once(event, listener) {
|
|
209
|
+
const wrapped = (...args) => {
|
|
210
|
+
listener(...args);
|
|
211
|
+
const list = listeners.get(event) ?? [];
|
|
212
|
+
listeners.set(event, list.filter((entry) => entry !== wrapped));
|
|
213
|
+
};
|
|
214
|
+
return stream.on(event, wrapped);
|
|
215
|
+
},
|
|
216
|
+
async *[Symbol.asyncIterator]() {
|
|
217
|
+
yield data;
|
|
218
|
+
},
|
|
219
|
+
};
|
|
220
|
+
return stream;
|
|
221
|
+
}
|
|
222
|
+
export function rmSync(path, options) {
|
|
223
|
+
const normalized = normalizeFsPath(String(path));
|
|
224
|
+
const prefix = normalized === '/' ? '/' : `${normalized}/`;
|
|
225
|
+
const keys = Object.keys(nodeCompatSeed.files).filter((key) => key === normalized || key === directoryKey(normalized) || key.startsWith(prefix));
|
|
226
|
+
if (keys.length === 0) {
|
|
227
|
+
if (options?.force)
|
|
228
|
+
return;
|
|
229
|
+
throw errno('ENOENT', 'rm', normalized, -2);
|
|
230
|
+
}
|
|
231
|
+
for (const key of keys)
|
|
232
|
+
delete nodeCompatSeed.files[key];
|
|
233
|
+
}
|
|
234
|
+
export function unlinkSync(path) {
|
|
235
|
+
const normalized = normalizeFsPath(String(path));
|
|
236
|
+
if (!(normalized in nodeCompatSeed.files))
|
|
237
|
+
throw errno('ENOENT', 'unlink', normalized, -2);
|
|
238
|
+
delete nodeCompatSeed.files[normalized];
|
|
239
|
+
}
|
|
240
|
+
export function renameSync(from, to) {
|
|
241
|
+
const source = normalizeFsPath(String(from));
|
|
242
|
+
const target = normalizeFsPath(String(to));
|
|
243
|
+
if (!(source in nodeCompatSeed.files) && !(directoryKey(source) in nodeCompatSeed.files)) {
|
|
244
|
+
throw errno('ENOENT', 'rename', source, -2);
|
|
245
|
+
}
|
|
246
|
+
if (source in nodeCompatSeed.files) {
|
|
247
|
+
nodeCompatSeed.files[target] = nodeCompatSeed.files[source];
|
|
248
|
+
delete nodeCompatSeed.files[source];
|
|
249
|
+
return;
|
|
250
|
+
}
|
|
251
|
+
const prefix = directoryKey(source);
|
|
252
|
+
const targetPrefix = directoryKey(target);
|
|
253
|
+
for (const key of Object.keys(nodeCompatSeed.files)) {
|
|
254
|
+
if (key === prefix || key.startsWith(prefix)) {
|
|
255
|
+
const next = targetPrefix + key.slice(prefix.length);
|
|
256
|
+
nodeCompatSeed.files[next] = nodeCompatSeed.files[key];
|
|
257
|
+
delete nodeCompatSeed.files[key];
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
export const constants = { F_OK: 0, R_OK: 4, W_OK: 2, X_OK: 1 };
|
|
262
|
+
export function accessSync(path, _mode) {
|
|
263
|
+
if (!existsSync(path))
|
|
264
|
+
throw errno('ENOENT', 'access', normalizeFsPath(String(path)), -2);
|
|
265
|
+
}
|
|
266
|
+
export default {
|
|
267
|
+
accessSync,
|
|
268
|
+
closeSync,
|
|
269
|
+
constants,
|
|
270
|
+
createReadStream,
|
|
271
|
+
existsSync,
|
|
272
|
+
fstatSync,
|
|
273
|
+
lstatSync,
|
|
274
|
+
mkdirSync,
|
|
275
|
+
openSync,
|
|
276
|
+
readFileSync,
|
|
277
|
+
readSync,
|
|
278
|
+
readdirSync,
|
|
279
|
+
renameSync,
|
|
280
|
+
rmSync,
|
|
281
|
+
statSync,
|
|
282
|
+
unlinkSync,
|
|
283
|
+
writeFileSync,
|
|
284
|
+
writeSync,
|
|
285
|
+
};
|