/
warnOnBuiltins.ts
44 lines (40 loc) · 1.03 KB
/
warnOnBuiltins.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
import { ChunkDependencies } from '../../Chunk';
import { RollupWarning } from '../../rollup/types';
import { printQuotedStringList } from '../../utils/printStringList';
const builtins = {
assert: true,
buffer: true,
console: true,
constants: true,
domain: true,
events: true,
http: true,
https: true,
os: true,
path: true,
process: true,
punycode: true,
querystring: true,
stream: true,
string_decoder: true,
timers: true,
tty: true,
url: true,
util: true,
vm: true,
zlib: true
};
export default function warnOnBuiltins(
warn: (warning: RollupWarning) => void,
dependencies: ChunkDependencies
): void {
const externalBuiltins = dependencies.map(({ id }) => id).filter(id => id in builtins);
if (!externalBuiltins.length) return;
warn({
code: 'MISSING_NODE_BUILTINS',
message: `Creating a browser bundle that depends on Node.js built-in modules (${printQuotedStringList(
externalBuiltins
)}). You might need to include https://github.com/snowpackjs/rollup-plugin-polyfill-node`,
modules: externalBuiltins
});
}