-
Notifications
You must be signed in to change notification settings - Fork 6
/
build.test.mjs
60 lines (52 loc) · 1.87 KB
/
build.test.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
import fs from 'node:fs';
import { build } from 'esbuild';
import * as importMap from "esbuild-plugin-import-map";
import packageJson from './package.json' assert { type: 'json' };
async function loadImportMapForBundle(bundledPath) {
importMap.clear();
await importMap.load({
imports: {
'../dist/lib/index.js': bundledPath
}
});
}
function getExternalDependencies(allow = []) {
const deps = packageJson.dependencies ? Object.keys(packageJson.dependencies).filter(dep => !allow.includes(dep)) : [];
const peerDeps = packageJson.peerDependencies ? Object.keys(packageJson.peerDependencies).filter(dep => !allow.includes(dep)) : [];
return [...deps, ...peerDeps];
}
async function buildModule() {
const shared = {
platform: 'node',
entryPoints: ['test/test.js'],
bundle: true,
minify: false,
treeShaking: false,
sourcemap: true,
external: getExternalDependencies(),
define: {
'process.env.__PARSE_TEST_RELATIVE_PATH__': `'../../../test/parse'`,
'process.env.__PARSE_TREE_TEST_RELATIVE_PATH__': `'../../../test/parseTree'`,
}
};
loadImportMapForBundle('../../../bundled/lib/commonjs/index.js');
await build({
...shared,
outfile: 'bundled/test/commonjs/index.js',
format: 'cjs',
plugins: [importMap.plugin()]
});
loadImportMapForBundle('../../../bundled/lib/esm/index.esm.js');
await build({
...shared,
outfile: 'bundled/test/esm/index.esm.js',
format: 'esm',
plugins: [importMap.plugin()]
});
}
function generateCommonjsPackageJson() {
const packageJsonCommonJs = JSON.stringify({ ...packageJson, type: undefined }, null, 2);
fs.writeFileSync('./bundled/test/commonjs/package.json', packageJsonCommonJs);
}
await buildModule();
generateCommonjsPackageJson();