-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathrollup.config.js
92 lines (80 loc) · 2.67 KB
/
rollup.config.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
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
const path = require('path');
const builtinModules = require('builtin-modules');
const license = require('rollup-plugin-license');
const replace = require('rollup-plugin-re');
const typescript = require('@rollup/plugin-typescript');
const json = require('@rollup/plugin-json');
const { generateCrossPlatformPath } = require('../../utils/build');
const packageJson = require('./package.json');
const { includes } = require('builtin-modules');
const FORMAT = {
CJS: 'cjs',
ES: 'es',
};
const CRYPTO_TYPE = {
WASM: 'wasm',
ASMJS: 'asmjs',
};
const sourcePath = path.join(__dirname, 'src');
const outputPath = path.join(__dirname, 'dist');
const getCryptoEntryPointName = (cryptoType, format) =>
`node${cryptoType === CRYPTO_TYPE.ASMJS ? '.asmjs' : ''}.${format}.js`;
const createEntry = (cryptoType, format) => {
const foundationModuleName = 'virgil-crypto';
let foundationEntryPoint = generateCrossPlatformPath(
foundationModuleName,
'dist',
getCryptoEntryPointName(cryptoType, format),
);
const pythiaModuleName = '@virgilsecurity/pythia-crypto';
const pythiaEntryPoint = generateCrossPlatformPath(
pythiaModuleName,
'dist',
getCryptoEntryPointName(cryptoType, format),
);
const external = builtinModules
.concat(Object.keys(packageJson.dependencies))
.concat([foundationEntryPoint, pythiaEntryPoint]);
const outputFileName = getCryptoEntryPointName(cryptoType, format);
return {
external,
input: path.join(sourcePath, 'index.ts'),
output: {
format,
file: path.join(outputPath, outputFileName),
},
plugins: [
replace({
patterns: [
{
match: /(index|EThree)\.ts$/,
test: foundationModuleName,
replace: foundationEntryPoint,
},
{
match: /EThree\.ts$/,
test: pythiaModuleName,
replace: pythiaEntryPoint,
},
],
}),
typescript({
tsconfig: './tsconfig.json',
}),
json(),
license({
banner: {
content: {
file: path.join(__dirname, '..', '..', 'LICENSE'),
},
},
}),
],
};
};
module.exports = [
createEntry(CRYPTO_TYPE.ASMJS, FORMAT.CJS),
createEntry(CRYPTO_TYPE.WASM, FORMAT.CJS),
createEntry(CRYPTO_TYPE.ASMJS, FORMAT.ES),
createEntry(CRYPTO_TYPE.WASM, FORMAT.ES),
];