forked from rocicorp/mono
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.ts
More file actions
61 lines (57 loc) · 1.39 KB
/
build.ts
File metadata and controls
61 lines (57 loc) · 1.39 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
import {readFileSync} from 'node:fs';
const external = [
'node:*',
'@badrap/valita',
'@rocicorp/datadog-util',
'@rocicorp/lock',
'@rocicorp/logger',
'@rocicorp/resolver',
'replicache',
];
export function sharedOptions(
minify: boolean | undefined = true,
metafile: boolean | undefined = false,
) {
const opts = {
bundle: true,
target: 'es2022',
format: 'esm',
external,
minify,
sourcemap: true,
metafile,
} as const;
if (minify) {
return /** @type {const} */ {
...opts,
mangleProps: /^_./,
reserveProps: /^__.*__$/,
} as const;
}
return opts;
}
function getVersion(name: string): string {
const url = new URL(`../../${name}/package.json`, import.meta.url);
const s = readFileSync(url, 'utf-8');
return JSON.parse(s).version;
}
export function makeDefine(
mode: 'debug' | 'release' | 'unknown' = 'unknown',
): Record<string, string> {
/** @type {Record<string, string>} */
const define: Record<string, string> = {
['process.env.REPLICACHE_VERSION']: JSON.stringify(
getVersion('replicache'),
),
['process.env.ZERO_VERSION']: JSON.stringify(getVersion('zero')),
['process.env.DISABLE_MUTATION_RECOVERY']: 'false',
['TESTING']: 'false',
};
if (mode === 'unknown') {
return define;
}
return {
...define,
'process.env.NODE_ENV': mode === 'debug' ? '"development"' : '"production"',
};
}