@openworkers/adapter-sveltekit 0.5.4 → 0.5.6
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.d.ts +2 -0
- package/dist/index.js +62 -2
- package/dist/runtime/function-worker.js +9 -7
- package/dist/runtime/page-worker.js +53 -0
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -101240,9 +101240,9 @@ export function extractParams(url) {
|
|
|
101240
101240
|
// src/adapter/build-function.ts
|
|
101241
101241
|
async function buildFunctionWorker(options8) {
|
|
101242
101242
|
const { endpointFile, outfile, routePattern, minify = false, debug = {}, hooksFile } = options8;
|
|
101243
|
-
const usesCookies = detectCookiesUsage(endpointFile);
|
|
101244
101243
|
const usesLocals = detectLocalsUsage(endpointFile);
|
|
101245
101244
|
const withHooks = usesLocals && !!hooksFile;
|
|
101245
|
+
const usesCookies = detectCookiesUsage(endpointFile) || withHooks && detectCookiesUsage(hooksFile);
|
|
101246
101246
|
const hasParams = routePattern.includes("[");
|
|
101247
101247
|
const tempDir = mkdtempSync(path15.join(tmpdir(), "adapter-params-"));
|
|
101248
101248
|
const paramsModulePath = path15.join(tempDir, "params.js");
|
|
@@ -101286,7 +101286,8 @@ async function buildFunctionWorker(options8) {
|
|
|
101286
101286
|
ROUTE_PATTERN: JSON.stringify(routePattern),
|
|
101287
101287
|
WITH_COOKIES: JSON.stringify(usesCookies),
|
|
101288
101288
|
WITH_PARAMS: JSON.stringify(hasParams),
|
|
101289
|
-
WITH_HOOKS: JSON.stringify(withHooks)
|
|
101289
|
+
WITH_HOOKS: JSON.stringify(withHooks),
|
|
101290
|
+
DEBUG_ERRORS: JSON.stringify(debug.errors ?? false)
|
|
101290
101291
|
}
|
|
101291
101292
|
});
|
|
101292
101293
|
if (debug.prettier) {
|
|
@@ -101418,6 +101419,65 @@ globalThis.process = globalThis.process || { env: { NODE_ENV: "production" } };`
|
|
|
101418
101419
|
builder.log.minor(` Generated function: ${routePattern} \u2192 ${workerFile}`);
|
|
101419
101420
|
}
|
|
101420
101421
|
}
|
|
101422
|
+
for (const route of builder.routes) {
|
|
101423
|
+
if (route.prerender === true) continue;
|
|
101424
|
+
if (route.page.methods.length === 0) continue;
|
|
101425
|
+
if (!route.id) continue;
|
|
101426
|
+
const workerName = route.id.replace(/\//g, "-").replace(/^-/, "") || "index";
|
|
101427
|
+
const workerFile = `functions/${workerName}.js`;
|
|
101428
|
+
const pageManifest = `${tmp}/manifest-${workerName}.js`;
|
|
101429
|
+
writeFileSync2(
|
|
101430
|
+
pageManifest,
|
|
101431
|
+
`export const manifest = ${builder.generateManifest({
|
|
101432
|
+
relativePath: path16.posix.relative(tmp, builder.getServerDirectory()),
|
|
101433
|
+
routes: [route]
|
|
101434
|
+
})};
|
|
101435
|
+
`
|
|
101436
|
+
);
|
|
101437
|
+
const pageEntry = `${tmp}/entry-${workerName}.js`;
|
|
101438
|
+
writeFileSync2(
|
|
101439
|
+
pageEntry,
|
|
101440
|
+
`import { Server } from '${serverPath}';
|
|
101441
|
+
import { manifest } from '${posixify(path16.resolve(pageManifest))}';
|
|
101442
|
+
export { Server, manifest };
|
|
101443
|
+
`
|
|
101444
|
+
);
|
|
101445
|
+
await build2({
|
|
101446
|
+
entryPoints: [`${files}/runtime/page-worker.js`],
|
|
101447
|
+
bundle: true,
|
|
101448
|
+
format: "esm",
|
|
101449
|
+
platform: "neutral",
|
|
101450
|
+
mainFields: ["module", "main"],
|
|
101451
|
+
outfile: `${dest}/${workerFile}`,
|
|
101452
|
+
alias: {
|
|
101453
|
+
SERVER: pageEntry,
|
|
101454
|
+
"node:async_hooks": `${shimsDir}/async-hooks.js`,
|
|
101455
|
+
...nodeCompat ? {
|
|
101456
|
+
path: `${shimsDir}/node-path.js`,
|
|
101457
|
+
"node:path": `${shimsDir}/node-path.js`,
|
|
101458
|
+
fs: `${shimsDir}/node-fs.js`,
|
|
101459
|
+
"node:fs": `${shimsDir}/node-fs.js`,
|
|
101460
|
+
url: `${shimsDir}/node-url.js`,
|
|
101461
|
+
"node:url": `${shimsDir}/node-url.js`
|
|
101462
|
+
} : {}
|
|
101463
|
+
},
|
|
101464
|
+
external: ["node:*"],
|
|
101465
|
+
minifySyntax: true,
|
|
101466
|
+
minifyWhitespace: true,
|
|
101467
|
+
minifyIdentifiers: true,
|
|
101468
|
+
treeShaking: true
|
|
101469
|
+
});
|
|
101470
|
+
const pattern = convertRouteToPattern(route.id);
|
|
101471
|
+
functions.push({
|
|
101472
|
+
pattern,
|
|
101473
|
+
worker: workerFile
|
|
101474
|
+
});
|
|
101475
|
+
functions.push({
|
|
101476
|
+
pattern: pattern + "/__data.json",
|
|
101477
|
+
worker: workerFile
|
|
101478
|
+
});
|
|
101479
|
+
builder.log.minor(` Generated page function: ${pattern} \u2192 ${workerFile}`);
|
|
101480
|
+
}
|
|
101421
101481
|
}
|
|
101422
101482
|
const routes = {
|
|
101423
101483
|
// Immutable assets (hashed filenames, cache forever)
|
|
@@ -83,13 +83,15 @@ var worker = {
|
|
|
83
83
|
});
|
|
84
84
|
}
|
|
85
85
|
console.error(`[Function] Error in ${method} handler:`, error);
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
86
|
+
const body = { error: "Internal Server Error" };
|
|
87
|
+
if (DEBUG_ERRORS) {
|
|
88
|
+
body.details = error?.message ?? String(error);
|
|
89
|
+
body.stack = error?.stack ?? "";
|
|
90
|
+
}
|
|
91
|
+
return Response.json(body, {
|
|
92
|
+
status: 500,
|
|
93
|
+
headers: { "Content-Type": "application/json" }
|
|
94
|
+
});
|
|
93
95
|
}
|
|
94
96
|
}
|
|
95
97
|
};
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
// src/runtime/page-worker.ts
|
|
2
|
+
import { Server, manifest } from "SERVER";
|
|
3
|
+
|
|
4
|
+
// src/shims/caches.ts
|
|
5
|
+
if (typeof caches === "undefined") {
|
|
6
|
+
const noopCache = {
|
|
7
|
+
match: async () => void 0,
|
|
8
|
+
put: async () => {
|
|
9
|
+
},
|
|
10
|
+
delete: async () => false
|
|
11
|
+
};
|
|
12
|
+
globalThis.caches = {
|
|
13
|
+
default: noopCache,
|
|
14
|
+
open: async () => noopCache
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
// src/runtime/page-worker.ts
|
|
19
|
+
var server = new Server(manifest);
|
|
20
|
+
var origin;
|
|
21
|
+
var initialized = server.init({
|
|
22
|
+
env: globalThis.env ?? {},
|
|
23
|
+
read: async (file) => {
|
|
24
|
+
const url = `${origin}/${file}`;
|
|
25
|
+
const response = await globalThis.env.ASSETS.fetch(url);
|
|
26
|
+
if (!response.ok) {
|
|
27
|
+
throw new Error(`read(...) failed: could not fetch ${url} (${response.status} ${response.statusText})`);
|
|
28
|
+
}
|
|
29
|
+
return response.body;
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
var worker = {
|
|
33
|
+
async fetch(req, env, ctx) {
|
|
34
|
+
const proto = req.headers.get("x-forwarded-proto");
|
|
35
|
+
if (proto && !req.url.startsWith(proto)) {
|
|
36
|
+
req = new Request(req.url.replace(/^http:/, `${proto}:`), req);
|
|
37
|
+
}
|
|
38
|
+
if (!origin) {
|
|
39
|
+
origin = new URL(req.url).origin;
|
|
40
|
+
}
|
|
41
|
+
await initialized;
|
|
42
|
+
return server.respond(req, {
|
|
43
|
+
platform: { env, ctx },
|
|
44
|
+
getClientAddress() {
|
|
45
|
+
return req.headers.get("x-real-ip") ?? req.headers.get("x-forwarded-for") ?? "";
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
var page_worker_default = worker;
|
|
51
|
+
export {
|
|
52
|
+
page_worker_default as default
|
|
53
|
+
};
|