-
Notifications
You must be signed in to change notification settings - Fork 1.5k
/
build.ts
120 lines (111 loc) · 3.68 KB
/
build.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
import { Extractor, ExtractorConfig } from '@microsoft/api-extractor'
import path from 'path'
import type { BuildOptions } from '../../../helpers/compile/build'
import { build } from '../../../helpers/compile/build'
import { fillPlugin } from '../../../helpers/compile/plugins/fill-plugin/fillPlugin'
// we define the config for runtime
const runtimeBuildConfig: BuildOptions = {
entryPoints: ['src/runtime/index.ts'],
outfile: 'runtime/index',
bundle: true,
define: {
'globalThis.NOT_PRISMA_DATA_PROXY': 'true',
// that fixes an issue with lz-string umd builds
'define.amd': 'false',
},
}
// we define the config for browser
const browserBuildConfig: BuildOptions = {
entryPoints: ['src/runtime/index-browser.ts'],
outfile: 'runtime/index-browser',
target: ['chrome58', 'firefox57', 'safari11', 'edge16'],
bundle: true,
}
// we define the config for proxy
const proxyBuildConfig: BuildOptions = {
entryPoints: ['src/runtime/index.ts'],
outfile: 'runtime/proxy',
bundle: true,
minify: true,
legalComments: 'none',
define: {
// that helps us to tree-shake unused things out
'globalThis.NOT_PRISMA_DATA_PROXY': 'false',
// that fixes an issue with lz-string umd builds
'define.amd': 'false',
},
plugins: [
fillPlugin(
{
// TODO no tree shaking on wrapper pkgs
'@prisma/get-platform': { contents: '' },
// removes un-needed code out of `chalk`
'supports-color': { contents: '' },
// these can not be exported any longer
'./warnEnvConflicts': { contents: '' },
'./utils/find': { contents: '' },
},
// we only trigger it on the first step (esm)
// because that is where tree-shaking happens
(options) => options.format === 'esm',
),
],
logLevel: 'error',
}
// we define the config for generator
const generatorBuildConfig: BuildOptions = {
entryPoints: ['src/generation/generator.ts'],
outfile: 'generator-build/index',
bundle: true,
}
/**
* Bundle all type definitions by using the API Extractor from RushStack
* @param filename the source d.ts to bundle
* @param outfile the output bundled file
*/
function bundleTypeDefinitions(filename: string, outfile: string) {
// we give the config in its raw form instead of a file
const extractorConfig = ExtractorConfig.prepare({
configObject: {
projectFolder: path.join(__dirname, '..'),
mainEntryPointFilePath: `${filename}.d.ts`,
bundledPackages: [
'decimal.js',
'sql-template-tag',
'@opentelemetry/api',
'@prisma/sdk',
'@prisma/engine-core',
'@prisma/generator-helper',
],
compiler: {
tsconfigFilePath: 'tsconfig.build.json',
},
dtsRollup: {
enabled: true,
untrimmedFilePath: `${outfile}.d.ts`,
},
tsdocMetadata: {
enabled: false,
},
},
packageJsonFullPath: path.join(__dirname, '..', 'package.json'),
configObjectFullPath: undefined,
})
// here we trigger the "command line" interface equivalent
const extractorResult = Extractor.invoke(extractorConfig, {
showVerboseMessages: true,
localBuild: true,
})
// we exit the process immediately if there were errors
if (extractorResult.succeeded === false) {
console.error(`API Extractor completed with errors`)
process.exit(1)
}
}
void build([generatorBuildConfig, runtimeBuildConfig, browserBuildConfig, proxyBuildConfig]).then(() => {
if (process.env.DEV !== 'true') {
bundleTypeDefinitions('declaration/runtime/index', 'runtime/index')
bundleTypeDefinitions('declaration/runtime/index', 'runtime/proxy')
bundleTypeDefinitions('declaration/runtime/index-browser', 'runtime/index-browser')
}
})