@openworkers/adapter-sveltekit 0.4.5 → 0.5.1
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/index.js +16 -5
- package/dist/lib/async-hooks.js +31 -0
- package/dist/lib/node-fs.js +13 -0
- package/dist/lib/node-path.js +27 -0
- package/dist/lib/node-url.js +13 -0
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -203,9 +203,10 @@ function index_default(options = {}) {
|
|
|
203
203
|
return {
|
|
204
204
|
name,
|
|
205
205
|
async adapt(builder) {
|
|
206
|
-
const dest = options.
|
|
206
|
+
const dest = options.outDir ?? "build";
|
|
207
207
|
const assetsDir = `${dest}/assets`;
|
|
208
208
|
const functionsEnabled = options.functions ?? false;
|
|
209
|
+
const nodeCompat = options.nodeCompat ?? false;
|
|
209
210
|
const files = fileURLToPath2(new URL(".", import.meta.url).href);
|
|
210
211
|
const tmp = builder.getBuildDirectory("openworkers-tmp");
|
|
211
212
|
builder.rimraf(dest);
|
|
@@ -240,24 +241,34 @@ export { Server, manifest, prerendered, base_path };
|
|
|
240
241
|
`
|
|
241
242
|
);
|
|
242
243
|
const workerDest = `${dest}/_worker.js`;
|
|
243
|
-
const
|
|
244
|
+
const libDir = posixify(path2.resolve(files, "lib"));
|
|
244
245
|
await build2({
|
|
245
246
|
entryPoints: [`${files}/worker.js`],
|
|
246
247
|
bundle: true,
|
|
247
248
|
format: "esm",
|
|
248
249
|
platform: "neutral",
|
|
250
|
+
mainFields: ["module", "main"],
|
|
249
251
|
outfile: workerDest,
|
|
250
252
|
alias: {
|
|
251
253
|
SERVER: entryPoint,
|
|
252
254
|
MANIFEST: entryPoint,
|
|
253
|
-
"node:async_hooks":
|
|
255
|
+
"node:async_hooks": `${libDir}/async-hooks.js`,
|
|
256
|
+
...nodeCompat ? {
|
|
257
|
+
"path": `${libDir}/node-path.js`,
|
|
258
|
+
"node:path": `${libDir}/node-path.js`,
|
|
259
|
+
"fs": `${libDir}/node-fs.js`,
|
|
260
|
+
"node:fs": `${libDir}/node-fs.js`,
|
|
261
|
+
"url": `${libDir}/node-url.js`,
|
|
262
|
+
"node:url": `${libDir}/node-url.js`
|
|
263
|
+
} : {}
|
|
254
264
|
},
|
|
255
265
|
external: ["node:*"],
|
|
256
266
|
minifySyntax: true,
|
|
257
267
|
minifyIdentifiers: true,
|
|
258
268
|
treeShaking: true,
|
|
259
269
|
banner: {
|
|
260
|
-
js: `// Generated by ${name} v${version} at ${(/* @__PURE__ */ new Date()).toISOString()}`
|
|
270
|
+
js: `// Generated by ${name} v${version} at ${(/* @__PURE__ */ new Date()).toISOString()}` + (nodeCompat ? `
|
|
271
|
+
globalThis.process = globalThis.process || { env: { NODE_ENV: "production" } };` : "")
|
|
261
272
|
}
|
|
262
273
|
});
|
|
263
274
|
const functions = [];
|
|
@@ -311,7 +322,7 @@ export { Server, manifest, prerendered, base_path };
|
|
|
311
322
|
function extractEndpointsFromManifest(manifest, serverDir) {
|
|
312
323
|
const endpoints = [];
|
|
313
324
|
for (const [key, entry] of Object.entries(manifest)) {
|
|
314
|
-
if (!key.includes("+server.ts")) continue;
|
|
325
|
+
if (!key.includes("+server.ts") && !key.includes("+server.js")) continue;
|
|
315
326
|
const sourcePath = entry.src;
|
|
316
327
|
if (!sourcePath || !sourcePath.startsWith("src/routes/")) continue;
|
|
317
328
|
const routePart = sourcePath.replace(/^src\/routes/, "").replace(/\/\+server\.(ts|js)$/, "");
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
// src/lib/async-hooks.ts
|
|
2
|
+
var AsyncLocalStorage = class {
|
|
3
|
+
#store;
|
|
4
|
+
run(store, fn, ...args) {
|
|
5
|
+
this.#store = store;
|
|
6
|
+
return fn(...args);
|
|
7
|
+
}
|
|
8
|
+
getStore() {
|
|
9
|
+
return this.#store;
|
|
10
|
+
}
|
|
11
|
+
// Stubs for API completeness
|
|
12
|
+
enterWith(store) {
|
|
13
|
+
this.#store = store;
|
|
14
|
+
}
|
|
15
|
+
exit(fn, ...args) {
|
|
16
|
+
this.#store = void 0;
|
|
17
|
+
return fn(...args);
|
|
18
|
+
}
|
|
19
|
+
disable() {
|
|
20
|
+
this.#store = void 0;
|
|
21
|
+
}
|
|
22
|
+
static bind(fn) {
|
|
23
|
+
return fn;
|
|
24
|
+
}
|
|
25
|
+
static snapshot() {
|
|
26
|
+
return (fn, ...args) => fn(...args);
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
export {
|
|
30
|
+
AsyncLocalStorage
|
|
31
|
+
};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
// src/lib/node-path.ts
|
|
2
|
+
var sep = "/";
|
|
3
|
+
function dirname(p) {
|
|
4
|
+
return p.replace(/\/[^/]*$/, "") || "/";
|
|
5
|
+
}
|
|
6
|
+
function join(...parts) {
|
|
7
|
+
return parts.join("/").replace(/\/+/g, "/");
|
|
8
|
+
}
|
|
9
|
+
function resolve(...parts) {
|
|
10
|
+
return join(...parts);
|
|
11
|
+
}
|
|
12
|
+
function relative(_from, _to) {
|
|
13
|
+
return _to;
|
|
14
|
+
}
|
|
15
|
+
function isAbsolute(p) {
|
|
16
|
+
return p.startsWith("/");
|
|
17
|
+
}
|
|
18
|
+
var node_path_default = { sep, dirname, join, resolve, relative, isAbsolute };
|
|
19
|
+
export {
|
|
20
|
+
node_path_default as default,
|
|
21
|
+
dirname,
|
|
22
|
+
isAbsolute,
|
|
23
|
+
join,
|
|
24
|
+
relative,
|
|
25
|
+
resolve,
|
|
26
|
+
sep
|
|
27
|
+
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
// src/lib/node-url.ts
|
|
2
|
+
function pathToFileURL(p) {
|
|
3
|
+
return new URL(`file://${p}`);
|
|
4
|
+
}
|
|
5
|
+
function fileURLToPath(u) {
|
|
6
|
+
return typeof u === "string" ? u.replace("file://", "") : u.pathname;
|
|
7
|
+
}
|
|
8
|
+
var node_url_default = { pathToFileURL, fileURLToPath };
|
|
9
|
+
export {
|
|
10
|
+
node_url_default as default,
|
|
11
|
+
fileURLToPath,
|
|
12
|
+
pathToFileURL
|
|
13
|
+
};
|