Skip to content
This repository has been archived by the owner on Aug 4, 2021. It is now read-only.

Commit

Permalink
Use official warn hook
Browse files Browse the repository at this point in the history
  • Loading branch information
lukastaegert committed Dec 9, 2018
1 parent 8ff5ec8 commit 942ebd3
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 17 deletions.
4 changes: 2 additions & 2 deletions .travis.yml
@@ -1,8 +1,8 @@
language: node_js
node_js:
- "4"
- "6"
- "stable"
- "8"
- "10"
env:
global:
- BUILD_TIMEOUT=10000
9 changes: 3 additions & 6 deletions src/index.js
@@ -1,11 +1,10 @@
import { dirname, resolve, extname, normalize, sep } from 'path';
import {dirname, extname, normalize, resolve, sep} from 'path';
import builtins from 'builtin-modules';
import resolveId from 'resolve';
import isModule from 'is-module';
import fs from 'fs';

const ES6_BROWSER_EMPTY = resolve( __dirname, '../src/empty.js' );
const CONSOLE_WARN = ( ...args ) => console.warn( ...args ); // eslint-disable-line no-console
// It is important that .mjs occur before .js so that Rollup will interpret npm modules
// which deploy both ESM .mjs and CommonJS .js files as ESM.
const DEFAULT_EXTS = [ '.mjs', '.js', '.json', '.node' ];
Expand Down Expand Up @@ -56,8 +55,6 @@ export default function nodeResolve ( options = {} ) {
: null;
const browserMapCache = {};

const onwarn = options.onwarn || CONSOLE_WARN;

if ( options.skip ) {
throw new Error( 'options.skip is no longer supported — you should use the main Rollup `external` option instead' );
}
Expand All @@ -75,7 +72,7 @@ export default function nodeResolve ( options = {} ) {
preserveSymlinks = options.preserveSymlinks;
},

onwrite () {
generateBundle () {
isFileCache = {};
readFileCache = {};
},
Expand Down Expand Up @@ -178,7 +175,7 @@ export default function nodeResolve ( options = {} ) {
return null;
} else if ( ~builtins.indexOf( importee ) && preferBuiltins ) {
if ( !isPreferBuiltinsSet ) {
onwarn(
this.warn(
`preferring built-in module '${importee}' over local alternative ` +
`at '${resolved}', pass 'preferBuiltins: false' to disable this ` +
`behavior or 'preferBuiltins: true' to disable this warning`
Expand Down
15 changes: 6 additions & 9 deletions test/test.js
Expand Up @@ -382,15 +382,12 @@ describe( 'rollup-plugin-node-resolve', function () {
let warning = null;
return rollup.rollup({
input: 'samples/prefer-builtin/main.js',
plugins: [
nodeResolve({
onwarn ( message ) {
if ( ~message.indexOf( 'prefer' ) ) {
warning = message;
}
}
})
]
onwarn ({message}) {
if ( ~message.indexOf( 'preferring' ) ) {
warning = message;
}
},
plugins: [nodeResolve()]
}).then( () => {
const localPath = path.join(__dirname, 'node_modules/events/index.js');
assert.strictEqual(
Expand Down

0 comments on commit 942ebd3

Please sign in to comment.