-
Notifications
You must be signed in to change notification settings - Fork 41
/
Copy pathesbuild.js
86 lines (78 loc) · 2.3 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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
import fs from 'node:fs/promises';
import { exec } from '@yao-pkg/pkg';
import { build } from 'esbuild';
import esbuildPluginPino from 'esbuild-plugin-pino';
import shell from 'shelljs';
shell.config.fatal = true;
const nodeVersion = 22;
const version = process.env.CONTAINERBASE_VERSION ?? '0.0.0-PLACEHOLDER';
shell.rm('-rf', 'dist/docker');
shell.mkdir('-p', 'dist/docker');
shell.cp('-r', 'src/usr', 'dist/docker/');
await fs.writeFile('dist/docker/usr/local/containerbase/version', version);
await build({
entryPoints: { 'containerbase-cli': './src/cli/index.ts' },
bundle: true,
packages: 'bundle',
platform: 'node',
target: `node${nodeVersion}`,
minify: false,
tsconfig: 'tsconfig.dist.json',
// format: "esm", // not supported https://github.com/vercel/pkg/issues/1291
outdir: './dist',
define: {
'globalThis.CONTAINERBASE_VERSION': `"${version}"`,
'globalThis.rootDir': 'null',
},
plugins: [esbuildPluginPino({ transports: ['pino-pretty'] })],
});
await fs.writeFile(
'./dist/package.json',
JSON.stringify(
{
name: 'containerbase-cli',
version,
private: true,
type: 'commonjs',
bin: {
'containerbase-cli': './containerbase-cli.js',
},
pkg: {
outputPath: './dist/cli',
scripts: ['pino-*.js', 'thread-stream-worker.js'],
targets: [
`node${nodeVersion}-linux-x64`,
`node${nodeVersion}-linux-arm64`,
],
patches: {
'./containerbase-cli.js': [
'pinoBundlerAbsolutePath("./pino-file.js")',
'"/snapshot/dist/pino-file.js"',
'pinoBundlerAbsolutePath("./pino-pipeline-worker.js")',
'"/snapshot/dist/pino-pipeline-worker.js"',
'pinoBundlerAbsolutePath("./pino-pretty.js")',
'"/snapshot/dist/pino-pretty.js"',
'pinoBundlerAbsolutePath("./pino-worker.js")',
'"/snapshot/dist/pino-worker.js"',
'pinoBundlerAbsolutePath("./thread-stream-worker.js")',
'"/snapshot/dist/thread-stream-worker.js"',
],
},
},
},
undefined,
2,
),
);
await exec([
'--no-bytecode',
'--public',
'--options',
'use-openssl-ca',
// '--debug',
'dist',
]);
await fs.rename(
'./dist/cli/containerbase-cli-x64',
'./dist/cli/containerbase-cli-amd64',
);