diff --git a/lib/index.js b/lib/index.js index 8445925..e46ea7e 100644 --- a/lib/index.js +++ b/lib/index.js @@ -42,20 +42,6 @@ const strictDefaults = [ '/.git', ] -const allLevels = [ - // these are included by default but can be excluded by package.json files array - '!/readme{,.*[^~$]}', - '!/copying{,.*[^~$]}', - '!/license{,.*[^~$]}', - '!/licence{,.*[^~$]}', -] - -const rootOnly = [ - /^!.*readme/i, - /^!.*copying/i, - /^!.*licen[sc]e/i, -] - const normalizePath = (path) => path.split('\\').join('/') const readOutOfTreeIgnoreFiles = (root, rel, result = []) => { @@ -141,7 +127,6 @@ class PackWalker extends IgnoreWalker { // known required files for this directory this.injectRules(strictRules, [ ...strictDefaults, - ...allLevels, ...this.requiredFiles.map((file) => `!${file}`), ]) } @@ -294,8 +279,11 @@ class PackWalker extends IgnoreWalker { const ignores = [] const strict = [ ...strictDefaults, - ...allLevels, '!/package.json', + '!/readme{,.*[^~$]}', + '!/copying{,.*[^~$]}', + '!/license{,.*[^~$]}', + '!/licence{,.*[^~$]}', '/.git', '/node_modules', '.npmrc', @@ -314,9 +302,6 @@ class PackWalker extends IgnoreWalker { file = file.slice(0, -1) } const inverse = `!${file}` - - this.excludeNonRoot(file) - try { // if an entry in the files array is a specific file, then we need to include it as a // strict requirement for this package. if it's a directory or a pattern, it's a default @@ -365,20 +350,6 @@ class PackWalker extends IgnoreWalker { this.injectRules(strictRules, strict, callback) } - // excludes non root files by checking if elements from the files array in - // package.json contain an ! and readme/license/licence/copying, and then - // removing readme/license/licence/copying accordingly from strict defaults - excludeNonRoot (file) { - // Find the pattern - const matchingPattern = rootOnly.find(regex => regex.test(file)) - - if (matchingPattern) { - // Find which index matches the pattern and remove it from allLevels - const indexToRemove = allLevels.findIndex(element => matchingPattern.test(element)) - allLevels.splice(indexToRemove, 1) - } - } - // custom method: after we've finished gathering the files for the root package, we call this // before emitting the 'done' event in order to gather all of the files for bundled deps async gatherBundles () { diff --git a/test/package-json-negate-non-root.js b/test/package-json-negate-non-root.js index 02c3c85..8db7143 100644 --- a/test/package-json-negate-non-root.js +++ b/test/package-json-negate-non-root.js @@ -1,4 +1,4 @@ -// exclude readme, license, and licnce files if package.json +// exclude readme, license, and licence files if package.json // files array includes !readme, !license, or !licence 'use strict' @@ -9,7 +9,7 @@ const packlist = require('../') const pkg = t.testdir({ 'package.json': JSON.stringify({ files: [ - '**/*.js', + 'lib', '!readme.md', '!licence', '!license', @@ -65,5 +65,8 @@ t.test('package with negated readme, licence and license files', async (t) => { 'lib/a/b/c/c.js', 'package.json', 'readme.md', + 'lib/a/b/c/file.txt', + 'lib/a/b/file.txt', + 'lib/a/file.txt', ]) })