-
Notifications
You must be signed in to change notification settings - Fork 222
/
base.tsup.config.ts
62 lines (53 loc) · 1.65 KB
/
base.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
import path from 'path';
import type { Options } from 'tsup';
type PKG = {
dependencies?: Record<string, string>;
name: string;
};
const requesters = {
fetch: '@algolia/requester-fetch',
http: '@algolia/requester-node-http',
xhr: '@algolia/requester-browser-xhr',
};
type Requester = keyof typeof requesters;
export function getBaseConfig(cwd: string): Options {
return {
clean: true,
sourcemap: true,
splitting: false,
tsconfig: path.resolve(cwd, 'tsconfig.json'),
};
}
export function getDependencies(pkg: PKG, requester: Requester): string[] {
const deps = Object.keys(pkg.dependencies || {}) || [];
if (pkg.name !== 'algoliasearch') {
return deps;
}
switch (requester) {
case 'http':
return deps.filter((dep) => dep !== requesters.fetch && dep !== requesters.xhr);
case 'xhr':
return deps.filter((dep) => dep !== requesters.fetch && dep !== requesters.http);
case 'fetch':
return deps.filter((dep) => dep !== requesters.xhr && dep !== requesters.http);
default:
throw new Error('unknown requester', requester);
}
}
export function getBaseNodeOptions(pkg: PKG, cwd: string, requester: Requester = 'http'): Options {
return {
...getBaseConfig(cwd),
platform: 'node',
target: 'node14',
external: [...getDependencies(pkg, requester), 'node:crypto'],
};
}
export function getBaseBrowserOptions(pkg: PKG, cwd: string, requester: Requester = 'xhr'): Options {
return {
...getBaseConfig(cwd),
platform: 'browser',
format: ['esm'],
target: ['chrome109', 'safari15.6', 'firefox115', 'edge126'],
external: [...getDependencies(pkg, requester), 'dom'],
};
}