This repository has been archived by the owner on Dec 13, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 44
/
Copy pathrollup.config.js
113 lines (105 loc) · 3.3 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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
import babel from "rollup-plugin-babel";
import commonjs from "rollup-plugin-commonjs";
import json from "rollup-plugin-json";
import nodeResolve from "rollup-plugin-node-resolve";
import typescript from "rollup-plugin-typescript2";
import pkg from "./package.json";
const globals = {
"@counterfactual/cf.js": "cfjs",
eventemitter3: "EventEmitter",
ethers: "ethers",
"ethers/constants": "ethers.constants",
"ethers/errors": "ethers.errors",
"ethers/providers": "ethers.providers",
"ethers/utils": "ethers.utils",
"ethers/utils/hdnode": "ethers.utils.HDNode",
"ethers/wallet": "ethers.wallet",
firebase: "firebase",
"firebase/app": "firebase.app",
events: "EventEmitter",
loglevel: "log",
uuid: "uuid"
};
const bundledDependencies = new Set([
"@counterfactual/firebase-client",
"@counterfactual/cf-funding-protocol-contracts",
"@counterfactual/cf-adjudicator-contracts",
"@counterfactual/types",
"typescript-memoize",
"p-queue",
"rpc-server"
]);
const external = [
...Object.keys(pkg.dependencies || {}).filter(dependency => {
return !bundledDependencies.has(dependency);
}),
...Object.keys(pkg.peerDependencies || {}).filter(dependency => {
return !bundledDependencies.has(dependency);
})
];
const onwarn = warning => {
// Silence circular dependency warnings specifically for reasonable
// circular dependencies
// Rationale: The current implementation requires the `src/api.ts` to setup
// the mapping between method & event names to controllers. Each controller
// refers to the `RequestHandler` to access certain resources. The
// `RequestHandler` refers to the `src/api.ts` file to lookup the method & event
// mapping so it knows how to route the call.
// The more elegant solution, instead of overlooking this circular dependency,
// is to refactor how calls are routed to controllers, specifically the
// behavior around `mapPublicApiMethods` and `mapEventHandlers`
const circularDependencyWarnings = new Set([
"Circular dependency: src/api.ts -> src/methods/index.ts -> src/methods/app-instance/get-app-instance/controller.ts -> src/request-handler.ts -> src/api.ts"
]);
if (
circularDependencyWarnings.has(warning.message) ||
// It's expected that the ethers package is an external dependency
// meaning its import technically is unresolved at rollup time
(warning.code === "UNRESOLVED_IMPORT" && warning.message.includes("ethers"))
) {
return;
}
console.warn(`(!) ${warning.message}`);
};
export default [
{
input: "src/index.ts",
output: [
{
file: pkg.main,
sourcemap: true,
format: "cjs",
globals: globals
},
{
file: pkg.iife,
sourcemap: true,
name: "window",
format: "iife",
extend: true,
globals: globals
}
],
external: external,
plugins: [
commonjs({
namedExports: {
"../../node_modules/typescript-memoize/dist/memoize-decorator.js": [
"Memoize"
]
}
}),
json({ compact: true }),
nodeResolve({
only: [...bundledDependencies]
}),
typescript(),
// use Babel to transpile to ES5
babel({
exclude: "node_modules/**",
plugins: ["@babel/plugin-proposal-object-rest-spread"]
})
],
onwarn
}
];