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.js
67 lines (67 loc) 路 2.53 KB
/
index.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
import fs from 'fs';
import path from 'path';
import babelPluginDynamicImportSyntax from '@babel/plugin-syntax-dynamic-import';
import babelPluginImportMetaSyntax from '@babel/plugin-syntax-import-meta';
import babelPresetEnv from '@babel/preset-env';
import babelPluginDynamicImport from 'babel-plugin-dynamic-import-node-babel-7';
import builtinModules from 'builtin-modules';
import rollupBabel from 'rollup-plugin-babel';
import { MessageError } from '@pika/types';
import { rollup } from 'rollup';
const DEFAULT_MIN_NODE_VERSION = '6';
export function manifest(manifest) {
manifest.main = manifest.main || 'dist-node/index.js';
}
export async function beforeJob({ out }) {
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 async function build({ out, reporter, options }) {
const writeToNode = path.join(out, 'dist-node', 'index.js');
// TODO: KEEP FIXING THIS,
const result = await rollup({
input: path.join(out, 'dist-src/index.js'),
external: builtinModules,
plugins: [
rollupBabel({
babelrc: false,
compact: false,
presets: [
[
babelPresetEnv,
{
modules: false,
targets: { node: options.minNodeVersion || DEFAULT_MIN_NODE_VERSION },
spec: true,
},
],
],
plugins: [
babelPluginDynamicImport,
babelPluginDynamicImportSyntax,
babelPluginImportMetaSyntax,
],
}),
],
onwarn: ((warning, defaultOnWarnHandler) => {
// Unresolved external imports are expected
if (warning.code === 'UNRESOLVED_IMPORT' &&
!(warning.source.startsWith('./') || warning.source.startsWith('../'))) {
return;
}
defaultOnWarnHandler(warning);
}),
});
await result.write({
file: writeToNode,
format: 'cjs',
exports: 'named',
});
reporter.created(writeToNode, 'main');
}