forked from QwikDev/qwik
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsubmodule-testing.ts
81 lines (73 loc) · 2.3 KB
/
submodule-testing.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
import { getBanner, importPath, nodeTarget, target, watcher } from './util';
import { build, type BuildOptions } from 'esbuild';
import { type BuildConfig, type PackageJSON } from './util';
import { join } from 'node:path';
import { writePackageJson } from './package-json';
/**
* Builds @builder.io/testing
*/
export async function submoduleTesting(config: BuildConfig) {
const submodule = 'testing';
const opts: BuildOptions = {
entryPoints: [join(config.srcDir, submodule, 'index.ts')],
outdir: join(config.distPkgDir, submodule),
sourcemap: config.dev,
bundle: true,
target,
external: ['@builder.io/qwik/build'],
platform: 'node',
// external: [...nodeBuiltIns],
};
const esm = build({
...opts,
format: 'esm',
banner: { js: getBanner('@builder.io/qwik/testing', config.distVersion) },
outExtension: { '.js': '.mjs' },
plugins: [
importPath(/^@builder\.io\/qwik$/, '../core.mjs'),
importPath(/^@builder\.io\/qwik\/optimizer$/, '../optimizer.mjs'),
importPath(/^@builder\.io\/qwik\/server$/, '../server.mjs'),
],
watch: watcher(config, submodule),
define: {
'globalThis.MODULE_EXT': `"mjs"`,
'globalThis.RUNNER': `false`,
},
target: 'es2020' /* needed for import.meta */,
});
const cjs = build({
...opts,
format: 'cjs',
outExtension: { '.js': '.cjs' },
banner: {
js: getBanner('@builder.io/qwik/testing', config.distVersion),
},
plugins: [
importPath(/^@builder\.io\/qwik$/, '../core.cjs'),
importPath(/^@builder\.io\/qwik\/optimizer$/, '../optimizer.cjs'),
importPath(/^@builder\.io\/qwik\/server$/, '../server.cjs'),
],
watch: watcher(config),
define: {
'globalThis.MODULE_EXT': `"cjs"`,
'globalThis.RUNNER': `false`,
},
platform: 'node',
target: nodeTarget,
});
await Promise.all([esm, cjs]);
await generateTestingPackageJson(config);
console.log('🦁', submodule);
}
async function generateTestingPackageJson(config: BuildConfig) {
const pkg: PackageJSON = {
name: '@builder.io/qwik/testing',
version: config.distVersion,
main: 'index.mjs',
types: 'index.d.ts',
private: true,
type: 'module',
};
const testingDistDir = join(config.distPkgDir, 'testing');
await writePackageJson(testingDistDir, pkg);
}