From 942ebd31e982176c811310a3813ded772dc3c72c Mon Sep 17 00:00:00 2001 From: Lukas Taegert-Atkinson Date: Sat, 8 Dec 2018 23:34:46 +0100 Subject: [PATCH] Use official warn hook --- .travis.yml | 4 ++-- src/index.js | 9 +++------ test/test.js | 15 ++++++--------- 3 files changed, 11 insertions(+), 17 deletions(-) diff --git a/.travis.yml b/.travis.yml index 81cac26..8e360a4 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,8 +1,8 @@ language: node_js node_js: - - "4" - "6" - - "stable" + - "8" + - "10" env: global: - BUILD_TIMEOUT=10000 diff --git a/src/index.js b/src/index.js index 45bec60..55fe93c 100644 --- a/src/index.js +++ b/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' ]; @@ -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' ); } @@ -75,7 +72,7 @@ export default function nodeResolve ( options = {} ) { preserveSymlinks = options.preserveSymlinks; }, - onwrite () { + generateBundle () { isFileCache = {}; readFileCache = {}; }, @@ -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` diff --git a/test/test.js b/test/test.js index 313c9dd..8658f4a 100644 --- a/test/test.js +++ b/test/test.js @@ -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(