From d49e257503ccf0c24fa3b261b77c2dd414401029 Mon Sep 17 00:00:00 2001 From: Mike Harder Date: Fri, 21 Jun 2019 23:51:47 -0700 Subject: [PATCH] Treat sideEffects array as inclusion list (#227) * Treat sideEffects array as inclusion list - Fixes #226 * Rename 'true-index' to 'array-index' for clarity * Inline unnecessary local variable * Rename test files from "-free" to "-effect" --- src/index.js | 3 +-- .../side-effects-array/{dep3-free.js => dep3-effect.js} | 0 test/node_modules/side-effects-array/index.js | 6 +++--- .../nested/{dep5-free.js => dep5-effect.js} | 0 test/node_modules/side-effects-array/package.json | 3 ++- test/test.js | 7 ++++--- 6 files changed, 10 insertions(+), 9 deletions(-) rename test/node_modules/side-effects-array/{dep3-free.js => dep3-effect.js} (100%) rename test/node_modules/side-effects-array/nested/{dep5-free.js => dep5-effect.js} (100%) diff --git a/src/index.js b/src/index.js index d2f75b5..dca731c 100644 --- a/src/index.js +++ b/src/index.js @@ -145,8 +145,7 @@ export default function nodeResolve ( options = {} ) { if (typeof packageSideEffects === 'boolean') { packageInfo.hasModuleSideEffects = () => packageSideEffects; } else if (Array.isArray(packageSideEffects)) { - const filter = createFilter(packageSideEffects, null, {resolve: pkgRoot}); - packageInfo.hasModuleSideEffects = id => !filter(id); + packageInfo.hasModuleSideEffects = createFilter(packageSideEffects, null, {resolve: pkgRoot}); } packageInfoCache.set(pkgPath, packageInfo); diff --git a/test/node_modules/side-effects-array/dep3-free.js b/test/node_modules/side-effects-array/dep3-effect.js similarity index 100% rename from test/node_modules/side-effects-array/dep3-free.js rename to test/node_modules/side-effects-array/dep3-effect.js diff --git a/test/node_modules/side-effects-array/index.js b/test/node_modules/side-effects-array/index.js index bd33706..0e04e8f 100644 --- a/test/node_modules/side-effects-array/index.js +++ b/test/node_modules/side-effects-array/index.js @@ -1,8 +1,8 @@ global.sideEffects = global.sideEffects || []; -global.sideEffects.push('true-index'); +global.sideEffects.push('array-index'); export {value as value1} from './dep1.js'; export {value as value2} from './dep2.js'; -export {value as value3} from './dep3-free.js'; +export {value as value3} from './dep3-effect.js'; export {value as value4} from './nested/dep4'; -export {value as value5} from './nested/dep5-free'; +export {value as value5} from './nested/dep5-effect'; diff --git a/test/node_modules/side-effects-array/nested/dep5-free.js b/test/node_modules/side-effects-array/nested/dep5-effect.js similarity index 100% rename from test/node_modules/side-effects-array/nested/dep5-free.js rename to test/node_modules/side-effects-array/nested/dep5-effect.js diff --git a/test/node_modules/side-effects-array/package.json b/test/node_modules/side-effects-array/package.json index 5afd642..2a39b98 100644 --- a/test/node_modules/side-effects-array/package.json +++ b/test/node_modules/side-effects-array/package.json @@ -1,7 +1,8 @@ { "main": "./index.js", "sideEffects": [ + "./index.js", "./dep1.js", - "**/*-free.js" + "**/*-effect.js" ] } diff --git a/test/test.js b/test/test.js index d0b52f6..c7b1b7b 100644 --- a/test/test.js +++ b/test/test.js @@ -890,9 +890,10 @@ describe( 'rollup-plugin-node-resolve', function () { 'true-dep1', 'true-dep2', 'true-index', - 'array-dep2', - 'array-dep4', - 'true-index' + 'array-dep1', + 'array-dep3', + 'array-dep5', + 'array-index' ]); delete global.sideEffects; }));