-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathesbuild.js
69 lines (62 loc) · 1.89 KB
/
esbuild.js
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
/*
* Copyright IBM Corp. 2023, 2024
*
* This source code is licensed under the Apache-2.0 license found in the
* LICENSE file in the root directory of this source tree.
*/
import path from 'node:path'
import { build } from 'esbuild'
const banner = `#!/usr/bin/env node
/*
* Copyright IBM Corp. 2023, 2024
*
* This source code is licensed under the Apache-2.0 license found in the
* LICENSE file in the root directory of this source tree.
*/`
const baseConfig = {
banner: {
js: banner
},
bundle: true,
format: 'esm',
minify: true,
platform: 'node',
target: 'es2021'
}
// collect is the main entrypoint. It calls spawn-background-process
await build({
...baseConfig,
bundle: false, // Do not include other esbuild output in this file
entryPoints: [path.join('dist', 'main', 'collect.js')],
outfile: path.join('dist', 'collect.js'),
target: 'es6'
})
// spawn-background-process spawns a new background-process process
await build({
...baseConfig,
entryPoints: [path.join('dist', 'main', 'spawn-background-process.js')],
outfile: path.join('dist', 'spawn-background-process.js')
})
// background-process is the main logic of the telemetry tooling
await build({
...baseConfig,
banner: {
// Require, __filename, and __dirname are polyfilled here to support the bundling of commonjs
// modules.
js:
banner +
`
const require = (await import("node:module")).createRequire(import.meta.url);
const __filename = (await import("node:url")).fileURLToPath(import.meta.url);
const __dirname = (await import("node:path")).dirname(__filename);
`
},
entryPoints: [path.join('dist', 'main', 'background-process.js')],
outfile: path.join('dist', 'background-process.js')
})
// notify logs a telemetry collection notice to the console
await build({
...baseConfig,
entryPoints: [path.join('dist', 'main', 'notify.js')],
outfile: path.join('dist', 'notify.js')
})