Skip to content

Commit

Permalink
fix: silence node builtin warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
wardpeet committed Aug 16, 2020
1 parent 5881387 commit 3f12b2b
Show file tree
Hide file tree
Showing 6 changed files with 73 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changeset/tame-singers-grin.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'microbundle': patch
---

Disable warnings for node's builtin-modules when using node as a target environment.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@
"babel-plugin-transform-async-to-promises": "^0.8.15",
"babel-plugin-transform-replace-expressions": "^0.2.0",
"brotli-size": "^4.0.0",
"builtin-modules": "^3.1.0",
"camelcase": "^5.3.1",
"cssnano": "^4.1.10",
"es6-promisify": "^6.1.1",
Expand Down
7 changes: 7 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import glob from 'tiny-glob/sync';
import autoprefixer from 'autoprefixer';
import cssnano from 'cssnano';
import { rollup, watch } from 'rollup';
import builtinModules from 'builtin-modules';
import commonjs from '@rollup/plugin-commonjs';
import babel from '@rollup/plugin-babel';
import customBabel from './lib/babel-custom';
Expand Down Expand Up @@ -306,6 +307,12 @@ function createConfig(options, entry, format, writeMeta) {
const moduleAliases = options.alias ? parseAliasArgument(options.alias) : [];
const aliasIds = moduleAliases.map(alias => alias.find);

// We want to silence rollup warnings for node builtins as we rollup-node-resolve threats them as externals anyway
// @see https://github.com/rollup/plugins/tree/master/packages/node-resolve/#resolving-built-ins-like-fs
if (options.target === 'node') {
external = external.concat(builtinModules);
}

const peerDeps = Object.keys(pkg.peerDependencies || {});
if (options.external === 'none') {
// bundle everything (external=[])
Expand Down
41 changes: 41 additions & 0 deletions test/__snapshots__/index.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -859,6 +859,47 @@ exports[`fixtures build basic-no-pkg-main with microbundle 3`] = `
"
`;
exports[`fixtures build basic-node-internals with microbundle 1`] = `
"Used script: microbundle --target=node -f cjs
Directory tree:
basic-node-internals
dist
basic-node-internals.js
basic-node-internals.js.map
package.json
src
index.js
Build \\"basicNodeInternals\\" to dist:
191 B: basic-node-internals.js.gz
149 B: basic-node-internals.js.br"
`;
exports[`fixtures build basic-node-internals with microbundle 2`] = `2`;
exports[`fixtures build basic-node-internals with microbundle 3`] = `
"var child_process = require('child_process');
function runCommand(cmd) {
return new Promise((resolve, reject) => {
child_process.exec(cmd, (error, stdout, stderr) => {
if (error) {
reject(error);
}
resolve(stdout || stderr);
});
});
}
exports.runCommand = runCommand;
//# sourceMappingURL=basic-node-internals.js.map
"
`;
exports[`fixtures build basic-ts with microbundle 1`] = `
"Used script: microbundle
Expand Down
6 changes: 6 additions & 0 deletions test/fixtures/basic-node-internals/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"name": "basic-node-internals",
"scripts": {
"build": "microbundle --target=node -f cjs"
}
}
13 changes: 13 additions & 0 deletions test/fixtures/basic-node-internals/src/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { exec } from 'child_process';

export function runCommand(cmd) {
return new Promise((resolve, reject) => {
exec(cmd, (error, stdout, stderr) => {
if (error) {
reject(error);
}

resolve(stdout || stderr);
});
});
}

0 comments on commit 3f12b2b

Please sign in to comment.