Skip to content

Commit

Permalink
fix: revert exclude non-root README.md/LICENSE files
Browse files Browse the repository at this point in the history
This was a workaround for a bug that has since been fixed in
ignore-walk.

The test and README were left in place, since the behavior still stands.

This reverts commit 24344a2.
  • Loading branch information
wraithgar committed Dec 6, 2023
1 parent 9cff49f commit a3dee68
Showing 1 changed file with 3 additions and 31 deletions.
34 changes: 3 additions & 31 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,22 +38,13 @@ const defaults = [
]

const strictDefaults = [
// these are forcibly excluded
'/.git',
]

const allLevels = [
// these are included by default but can be excluded by package.json files array
// these are forcibly included at all levels
'!/readme{,.*[^~$]}',
'!/copying{,.*[^~$]}',
'!/license{,.*[^~$]}',
'!/licence{,.*[^~$]}',
]

const rootOnly = [
/^!.*readme/i,
/^!.*copying/i,
/^!.*licen[sc]e/i,
// these are forcibly excluded
'/.git',
]

const normalizePath = (path) => path.split('\\').join('/')
Expand Down Expand Up @@ -141,7 +132,6 @@ class PackWalker extends IgnoreWalker {
// known required files for this directory
this.injectRules(strictRules, [
...strictDefaults,
...allLevels,
...this.requiredFiles.map((file) => `!${file}`),
])
}
Expand Down Expand Up @@ -294,7 +284,6 @@ class PackWalker extends IgnoreWalker {
const ignores = []
const strict = [
...strictDefaults,
...allLevels,
'!/package.json',
'/.git',
'/node_modules',
Expand All @@ -315,9 +304,6 @@ class PackWalker extends IgnoreWalker {
file = file.slice(0, -2)
}
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
Expand Down Expand Up @@ -366,20 +352,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 () {
Expand Down

0 comments on commit a3dee68

Please sign in to comment.