-
Notifications
You must be signed in to change notification settings - Fork 8
/
tsup.config.ts
97 lines (85 loc) · 2.11 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
import { execSync } from 'node:child_process';
import { defineConfig } from 'tsup';
const adapters = [
'apollo-server',
'aws',
'azure',
'digital-ocean',
'dummy',
'huawei',
];
const frameworks = [
'apollo-server',
'body-parser',
'cors',
'deepkit',
'express',
'fastify',
'hapi',
'koa',
'lazy',
'polka',
'trpc',
];
const handlers = [
'aws',
'azure',
'default',
'digital-ocean',
'firebase',
'gcp',
'huawei',
];
const resolvers = ['aws-context', 'callback', 'dummy', 'promise'];
const libEntries = [
...adapters.map(adapter => `src/adapters/${adapter}/index.ts`),
...frameworks.map(framework => `src/frameworks/${framework}/index.ts`),
...handlers.map(handler => `src/handlers/${handler}/index.ts`),
...resolvers.map(resolver => `src/resolvers/${resolver}/index.ts`),
];
const createExport = (filePath: string) => ({
import: {
types: `./lib/${filePath}.d.ts`,
default: `./lib/${filePath}.mjs`,
},
require: {
types: `./lib/${filePath}.d.cts`,
default: `./lib/${filePath}.cjs`,
},
});
const createExportReducer =
(initialPath: string) => (acc: object, name: string) => {
acc[`./${initialPath}/${name}`] = createExport(
`${initialPath}/${name}/index`,
);
acc[`./lib/${initialPath}/${name}`] = createExport(
`${initialPath}/${name}/index`,
);
return acc;
};
const packageExports = {
'.': createExport('index'),
...adapters.reduce(createExportReducer('adapters'), {}),
...frameworks.reduce(createExportReducer('frameworks'), {}),
...handlers.reduce(createExportReducer('handlers'), {}),
...resolvers.reduce(createExportReducer('resolvers'), {}),
};
execSync(`npm pkg set exports='${JSON.stringify(packageExports)}' --json`);
export default defineConfig({
outDir: './lib',
clean: true,
dts: true,
format: ['esm', 'cjs'],
outExtension: ({ format }) => ({
js: format === 'cjs' ? '.cjs' : '.mjs',
}),
cjsInterop: true,
entry: ['src/index.ts', ...libEntries],
sourcemap: true,
skipNodeModulesBundle: true,
minify: true,
target: 'es2022',
tsconfig: './tsconfig.build.json',
keepNames: true,
bundle: true,
});