-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathtsup.config.ts
More file actions
106 lines (96 loc) · 3.02 KB
/
tsup.config.ts
File metadata and controls
106 lines (96 loc) · 3.02 KB
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
/// <reference lib="es2023" />
/// <reference types="node" />
import { spawn } from 'child_process';
import { readFile, readFileSync, writeFileSync } from 'fs';
import { defineConfig } from 'tsup';
const prod = process.env.BUILD_ENV === 'runtime';
export default defineConfig({
entry: {
// events: 'packages/events/src/index.ts',
// commander: 'packages/commander/src/index.ts',
// server: 'packages/server/src/index.ts',
mws: 'packages/mws/src/index.ts',
},
tsconfig: "tsconfig.json",
format: ['esm'],
outDir: "dist",
external: [
"tiddlywiki",
"esbuild",
"env-cmd",
"zod-to-ts",
"@prisma/adapter-libsql",
"@prisma/adapter-better-sqlite3",
"@serenity-kit/opaque",
],
dts: false,
keepNames: true,
sourcemap: true,
clean: true,
minify: false,
splitting: false,
cjsInterop: true,
shims: true,
metafile: true,
banner: (ctx) => ctx.format === "esm" ? {
js: [
"import {createRequire as __createRequire} from 'module';",
"const require=__createRequire(import.meta.url);",
].join("\n")
} : ctx.format === "cjs" ? {
js: [
].join("\n")
} : {},
esbuildOptions(options, context) {
options.conditions = [
"tsup",
"esbuild",
"build",
]
},
define: prod ? {
"process.env.CLIENT_BUILD": "false",
"process.env.DEVSERVER": "false",
} : {},
noExternal: ["@tiddlywiki/mws", "@tiddlywiki/mws-prisma"],
async onSuccess() {
writeFileSync("dist/mws.d.ts", [
"export default function startServer(): Promise<void>;",
].join("\n"));
console.log("TSC dist/mws.d.ts");
// writeFileSync("public/stats/server.json", readFileSync("dist/metafile-esm.json"));
if (process.env.TSCMWS) {
const tag = "TSC ⚡️ done";
console.time(tag);
await start("npx tsc -p tsconfig.json --noEmit", []).catch((code) => code);
console.timeEnd(tag);
}
// if (process.env.PLUGINDTS) {
// const tag = "TSC ⚡️ done";
// console.time(tag);
// await start("npx tsc -p tsconfig.types.json", [
// "--outFile", "./plugins/client/src/types.d.ts"
// ]).catch((code) => code);
// let file = readFileSync("./plugins/client/src/types.d.ts", "utf-8");
// file = file.replaceAll(`import("@tiddlywiki/server")`, `import("packages/server/src/index")`);
// file = file.replaceAll(`import("prisma/client")`, `import("@tiddlywiki/mws-prisma")`);
// writeFileSync("./plugins/client/src/types.d.ts", file);
// console.log("TSC plugins/client/src/types.d.ts");
// console.timeEnd(tag);
// }
},
});
function start(cmd: string, args: string[], env2 = {}, { cwd = process.cwd(), detached = false } = {}) {
const cp = spawn(cmd, args, {
cwd,
env: { ...process.env, ...env2, },
shell: true,
stdio: ["inherit", "inherit", "inherit"],
detached,
});
if (detached) cp.unref();
return new Promise<void>((r, c) => {
// if any process errors it will immediately exit the script
cp.on("exit", (code) => { if (code) c(code); else r(); });
});
}