-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbundle.mjs
106 lines (94 loc) · 3.03 KB
/
bundle.mjs
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
import esbuild from 'esbuild';
import fs from 'fs';
import path from 'path';
import mkdir from 'make-dir';
import { fileURLToPath } from 'url';
let is_debug = false;
let args = process.argv.slice(2);
if (args.length == 0) {
console.warn('Usage: node bundle.mjs {debug/release}');
} else {
if (args[0] == 'debug') is_debug = true;
}
console.log(`DEBUG=${is_debug}`);
// -------------------------------
// Clear directory
const __dirname = path.dirname(fileURLToPath(import.meta.url));
const dist = path.resolve(__dirname, 'dist');
mkdir.sync(dist);
// -------------------------------
// Copy WASM files
const mode = is_debug ? "debug" : 'release';
const buildPath = path.resolve(__dirname, `arrow/cpp/build/${mode}/${mode}`);
fs.copyFileSync(path.resolve(buildPath, 'gandiva_wasm.wasm'), path.resolve(dist, 'gandiva_wasm.wasm'));
fs.copyFileSync(path.resolve(buildPath, 'gandiva_wasm.js'), path.resolve(dist, 'gandiva_wasm.js'));
// -------------------------------
// ESM
const TARGET = ['esnext'];
const EXTERNALS = ['fs', 'path'];
(async () => {
console.log('[ESBUILD] gandiva.module.js');
await esbuild.build({
entryPoints: ['./dist/gandiva_wasm.js'],
outfile: 'dist/gandiva.module.js',
platform: 'neutral',
format: 'esm',
target: TARGET,
bundle: true,
minify: true,
sourcemap: true,
external: EXTERNALS,
});
console.log('[ESBUILD] gandiva.browser.js');
await esbuild.build({
entryPoints: ['./dist/gandiva_wasm.js'],
outfile: 'dist/gandiva.browser.js',
platform: 'browser',
format: 'iife',
globalName: 'gandiva',
target: TARGET,
bundle: true,
minify: true,
define: { 'process.env.NODE_ENV': '"production"' },
sourcemap: is_debug ? 'inline' : true,
external: EXTERNALS,
});
console.log('[ESBUILD] gandiva.node.js');
await esbuild.build({
entryPoints: ['./dist/gandiva_wasm.js'],
outfile: 'dist/gandiva.node.js',
platform: 'node',
format: 'cjs',
target: TARGET,
bundle: true,
minify: true,
sourcemap: is_debug ? 'inline' : true,
external: EXTERNALS,
});
console.log('[ESBUILD] gandiva.benchmark.browser.js');
await esbuild.build({
entryPoints: ['./benchmarks/index.browser.ts'],
outfile: 'dist/gandiva.benchmark.browser.js',
platform: 'browser',
format: 'iife',
globalName: 'gandiva',
target: TARGET,
bundle: true,
minify: true,
define: { 'process.env.NODE_ENV': '"production"' },
sourcemap: is_debug ? 'inline' : true,
external: EXTERNALS,
});
console.log('[ESBUILD] gandiva.benchmark.node.js');
await esbuild.build({
entryPoints: ['./benchmarks/index.node.ts'],
outfile: 'dist/gandiva.benchmark.node.js',
platform: 'node',
format: 'cjs',
target: TARGET,
bundle: true,
minify: true,
sourcemap: true,
external: EXTERNALS,
});
})();