forked from ethers-io/ethers.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rollup-tests.config.js
89 lines (76 loc) · 2.59 KB
/
rollup-tests.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
"use strict";
import path from "path"
import fs from "fs";
import builtins from '@erquhart/rollup-plugin-node-builtins';
import resolve from 'rollup-plugin-node-resolve';
import commonjs from 'rollup-plugin-commonjs';
import json from 'rollup-plugin-json';
import _globals from "rollup-plugin-node-globals";
const undef = "module.exports = undefined;";
const empty = "module.exports = {};";
import { createFilter } from 'rollup-pluginutils';
function replacer(libPath, options = {}) {
const filter = createFilter(options.include, options.exclude);
return {
name: "file-replacer",
resolveId(id, importee) {
if (id == "ethers") {
return path.resolve(importee.match(/^(.*\/packages\/)/)[1], `./tests/${ libPath }/browser-ethers.js`);
}
//return null;
},
transform(code, id) {
if (id.match(/\/browser-fs\.json$/)) {
const config = JSON.parse(code);
const data = { "_": { name: "browser-fs", config: config } };
config.dirs.forEach((dirname) => {
let fulldirname = path.resolve(path.dirname(id), "..", dirname);
fs.readdirSync(fulldirname).forEach((filename) => {
const key = path.join(dirname, filename);
const content = fs.readFileSync(path.resolve(fulldirname, filename));
data[key] = content.toString("base64");
console.log(`Added ${ key } (${ content.length } bytes)`);
});
});
return {
code: JSON.stringify(data),
map: { mappings: '' }
};
}
return null;
}
};
}
export default commandLineArgs => {
let buildModule = commandLineArgs.configModule;
let input = "./packages/tests/lib/index.js"
let format = "umd";
let mainFields = [ "browser", "main" ];
let libPath = "lib";
if (buildModule) {
input = "./packages/tests/lib.esm/index.js";
format = "esm";
mainFields = [ "browser", "module", "main" ];
libPath = "lib.esm";
}
const plugins = [
replacer(libPath),
json(),
commonjs({ }),
builtins(),
resolve({
mainFields: mainFields
}),
_globals(),
];
return {
input: input,
output: {
file: ("./packages/tests/dist/tests." + format + ".js"),
format: format,
name: "testing"
},
treeshake: false,
plugins: plugins
};
}