-
Notifications
You must be signed in to change notification settings - Fork 22
/
tsup.config.ts
126 lines (119 loc) · 3.03 KB
/
tsup.config.ts
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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
import { defineConfig, Options } from "tsup";
import resolve from "esbuild-plugin-resolve";
import { replace } from "esbuild-plugin-replace";
const external = [
"path",
"react",
"fs",
"fs/promises",
"node:fs",
"node:fs/promises",
"util",
"os",
"url",
"node:path",
"node:os",
"node:url",
"assert",
"stream",
"better-sqlite3",
];
const stopFile = {
"node:fs/promises": "../../../bundle-not-impl.js",
"fs/promises": "../../../bundle-not-impl.js",
"../runtime/store-file.js": "../../bundle-not-impl.js",
"../runtime/gateways/file/gateway.js": "../bundle-not-impl.js",
"./mem-filesystem.js": "../../../bundle-not-impl.js",
"./gateways/file/gateway.js": "../bundle-not-impl.js",
"./node-sys-container.js": "../bundle-not-impl.js",
"./key-bag-file.js": "../bundle-not-impl.js",
};
const ourMultiformat = {
// "multiformats/block": `${__dirname}/src/runtime/multiformat/block.ts`
};
const LIBRARY_BUNDLE_OPTIONS: Options = {
format: ["esm", "cjs", "iife"],
target: ["esnext", "node18"],
globalName: "Fireproof",
external,
clean: true,
sourcemap: true,
metafile: true,
minify: false,
};
function packageVersion() {
// return JSON.stringify(JSON.parse(fs.readFileSync(file, "utf-8")).version);
let version = "refs/tags/v0.0.0-smoke";
if (process.env.GITHUB_REF && process.env.GITHUB_REF.startsWith("refs/tags/v")) {
version = process.env.GITHUB_REF;
}
version = version.split("/").slice(-1)[0].replace(/^v/, "");
// console.log(`Patch version ${version} in package.json`);
// packageJson.version = version;
return JSON.stringify(version);
}
const LIBRARY_BUNDLES: readonly Options[] = [
{
...LIBRARY_BUNDLE_OPTIONS,
format: ["iife"],
name: "@fireproof/core",
entry: ["src/index.ts"],
platform: "browser",
outDir: "dist/fireproof-core",
esbuildPlugins: [
replace({
__packageVersion__: packageVersion(),
include: /version/,
}),
resolve({
...stopFile,
...ourMultiformat,
}),
],
dts: {
footer: "declare module '@fireproof/core'",
},
},
{
...LIBRARY_BUNDLE_OPTIONS,
format: ["esm", "cjs"],
name: "@fireproof/core",
entry: ["src/index.ts"],
platform: "browser",
outDir: "dist/fireproof-core",
esbuildPlugins: [
replace({
__packageVersion__: packageVersion(),
include: /version/,
}),
resolve({
...ourMultiformat,
}),
],
dts: {
footer: "declare module '@fireproof/core'",
},
},
{
...LIBRARY_BUNDLE_OPTIONS,
name: "use-fireproof",
entry: ["src/react/index.ts"],
target: ["esnext"],
platform: "browser",
outDir: "dist/use-fireproof",
esbuildPlugins: [
replace({
__packageVersion__: packageVersion(),
include: /version/,
}),
resolve({
...stopFile,
...ourMultiformat,
}),
],
dts: {
footer: "declare module 'use-fireproof'",
},
},
];
export default defineConfig((options) => [...LIBRARY_BUNDLES, ...(options.watch || [])]);