This repository has been archived by the owner on Oct 27, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
/
index.js
83 lines (71 loc) · 2.23 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
import { fileURLToPath } from "node:url";
import { build } from "esbuild";
const usageOptions = {
deno: "deno",
compile: "deno-compile",
};
/** @type {import('.').default} */
export default function (opts = {}) {
const { out = "build", buildOptions = {}, usage = usageOptions.deno } = opts;
return {
name: "deno-deploy-adapter",
async adapt(builder) {
const tmp = builder.getBuildDirectory("deno-deploy-adapter");
builder.rimraf(out);
builder.rimraf(tmp);
builder.mkdirp(tmp);
const outDir = `${out}/static/${builder.config.kit.paths.base}`;
builder.writeClient(outDir);
builder.writePrerendered(outDir);
builder.writeServer(`${out}/server`);
const denoPath = fileURLToPath(new URL("./files", import.meta.url).href);
builder.copy(denoPath, `${out}`, {});
const modPath = fileURLToPath(
new URL("./files/mod.ts", import.meta.url).href,
);
builder.copy(modPath, `${out}/mod.ts`, {
replace: {
SERVER: "./server.js",
APP_DIR: builder.getAppPath(),
PRERENDERED: JSON.stringify(builder.prerendered.paths),
CURRENT_DIRNAME: usage === usageOptions.deno
? "fromFileUrl(import.meta.url)"
: "Deno.execPath()",
},
});
const defaultOptions = {
entryPoints: [`${out}/server.js`],
outfile: `${out}/server.js`,
bundle: true,
format: "esm",
target: "esnext",
platform: "node",
allowOverwrite: true,
};
for (const key of Object.keys(buildOptions)) {
if (Object.hasOwn(defaultOptions, key)) {
console.warn(
`Warning: "buildOptions" has override for default "${key}" this may break deployment.`,
);
}
}
try {
await build({
...defaultOptions,
...buildOptions,
});
} catch (err) {
console.error(err);
process.exit(1);
} finally {
builder.rimraf(`${out}/server`);
console.warn(`
PLEASE NOTE: This adapter is no longer maintained.
Deno is now compatible with the official Node adapters:
https://svelte.dev/docs/kit/adapters
Use adapter v0.16.0 to hide this message.
`);
}
},
};
}