Skip to content

Commit 3488411

Browse files
authored
fix: disable node-builtin warnings (#700)
1 parent dfa25e0 commit 3488411

File tree

6 files changed

+73
-0
lines changed

6 files changed

+73
-0
lines changed

.changeset/tame-singers-grin.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'microbundle': patch
3+
---
4+
5+
Disable warnings for node's builtin-modules when using node as a target environment.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@
9393
"babel-plugin-transform-async-to-promises": "^0.8.15",
9494
"babel-plugin-transform-replace-expressions": "^0.2.0",
9595
"brotli-size": "^4.0.0",
96+
"builtin-modules": "^3.1.0",
9697
"camelcase": "^5.3.1",
9798
"cssnano": "^4.1.10",
9899
"es6-promisify": "^6.1.1",

src/index.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import glob from 'tiny-glob/sync';
88
import autoprefixer from 'autoprefixer';
99
import cssnano from 'cssnano';
1010
import { rollup, watch } from 'rollup';
11+
import builtinModules from 'builtin-modules';
1112
import commonjs from '@rollup/plugin-commonjs';
1213
import babel from '@rollup/plugin-babel';
1314
import customBabel from './lib/babel-custom';
@@ -306,6 +307,12 @@ function createConfig(options, entry, format, writeMeta) {
306307
const moduleAliases = options.alias ? parseAliasArgument(options.alias) : [];
307308
const aliasIds = moduleAliases.map(alias => alias.find);
308309

310+
// We want to silence rollup warnings for node builtins as we rollup-node-resolve threats them as externals anyway
311+
// @see https://github.com/rollup/plugins/tree/master/packages/node-resolve/#resolving-built-ins-like-fs
312+
if (options.target === 'node') {
313+
external = external.concat(builtinModules);
314+
}
315+
309316
const peerDeps = Object.keys(pkg.peerDependencies || {});
310317
if (options.external === 'none') {
311318
// bundle everything (external=[])

test/__snapshots__/index.test.js.snap

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -859,6 +859,47 @@ exports[`fixtures build basic-no-pkg-main with microbundle 3`] = `
859859
"
860860
`;
861861
862+
exports[`fixtures build basic-node-internals with microbundle 1`] = `
863+
"Used script: microbundle --target=node -f cjs
864+
865+
Directory tree:
866+
867+
basic-node-internals
868+
dist
869+
basic-node-internals.js
870+
basic-node-internals.js.map
871+
package.json
872+
src
873+
index.js
874+
875+
876+
Build \\"basicNodeInternals\\" to dist:
877+
191 B: basic-node-internals.js.gz
878+
149 B: basic-node-internals.js.br"
879+
`;
880+
881+
exports[`fixtures build basic-node-internals with microbundle 2`] = `2`;
882+
883+
exports[`fixtures build basic-node-internals with microbundle 3`] = `
884+
"var child_process = require('child_process');
885+
886+
function runCommand(cmd) {
887+
return new Promise((resolve, reject) => {
888+
child_process.exec(cmd, (error, stdout, stderr) => {
889+
if (error) {
890+
reject(error);
891+
}
892+
893+
resolve(stdout || stderr);
894+
});
895+
});
896+
}
897+
898+
exports.runCommand = runCommand;
899+
//# sourceMappingURL=basic-node-internals.js.map
900+
"
901+
`;
902+
862903
exports[`fixtures build basic-ts with microbundle 1`] = `
863904
"Used script: microbundle
864905
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"name": "basic-node-internals",
3+
"scripts": {
4+
"build": "microbundle --target=node -f cjs"
5+
}
6+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { exec } from 'child_process';
2+
3+
export function runCommand(cmd) {
4+
return new Promise((resolve, reject) => {
5+
exec(cmd, (error, stdout, stderr) => {
6+
if (error) {
7+
reject(error);
8+
}
9+
10+
resolve(stdout || stderr);
11+
});
12+
});
13+
}

0 commit comments

Comments
 (0)