This repository has been archived by the owner on Apr 21, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 31
/
index.ts
54 lines (50 loc) 路 1.72 KB
/
index.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
import path from 'path';
import fs from 'fs';
import {BuilderOptions, MessageError} from '@pika/types';
import {rollup} from 'rollup';
const DEFAULT_ENTRYPOINT = 'module';
export async function beforeJob({out}: BuilderOptions) {
const srcDirectory = path.join(out, 'dist-src/');
if (!fs.existsSync(srcDirectory)) {
throw new MessageError('"dist-src/" does not exist, or was not yet created in the pipeline.');
}
const srcEntrypoint = path.join(out, 'dist-src/index.js');
if (!fs.existsSync(srcEntrypoint)) {
throw new MessageError('"dist-src/index.js" is the expected standard entrypoint, but it does not exist.');
}
}
export function manifest(manifest, {options}: BuilderOptions) {
if (options.entrypoint !== null) {
let keys = options.entrypoint || [DEFAULT_ENTRYPOINT];
if (typeof keys === 'string') {
keys = [keys];
}
for (const key of keys) {
manifest[key] = manifest[key] || 'dist-web/index.js';
}
}
}
export async function build({out, options, reporter}: BuilderOptions): Promise<void> {
const writeToWeb = path.join(out, 'dist-web', 'index.js');
const result = await rollup({
input: path.join(out, 'dist-src/index.js'),
plugins: [],
onwarn: ((warning, defaultOnWarnHandler) => {
// // Unresolved external imports are expected
if (
warning.code === 'UNRESOLVED_IMPORT' &&
!(warning.source.startsWith('./') || warning.source.startsWith('../'))
) {
return;
}
defaultOnWarnHandler(warning);
}) as any,
});
await result.write({
file: writeToWeb,
format: 'esm',
exports: 'named',
sourcemap: options.sourcemap === undefined ? true : options.sourcemap,
});
reporter.created(writeToWeb, 'module');
}