Skip to content

Commit

Permalink
Revert "fix: preserve slashes in specified files (npm#205)"
Browse files Browse the repository at this point in the history
This reverts commit cd5ddbd.
  • Loading branch information
danpere committed Dec 14, 2023
1 parent 734e65a commit ff9aae5
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 9 deletions.
8 changes: 5 additions & 3 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -308,10 +308,12 @@ class PackWalker extends IgnoreWalker {
if (files) {
for (let file of files) {
// invert the rule because these are things we want to include
if (file.startsWith('./')) {
if (file.startsWith('/')) {
file = file.slice(1)
} else if (file.startsWith('./')) {
file = file.slice(2)
} else if (file.endsWith('/*')) {
file = file.slice(0, -1)
file = file.slice(0, -2)
}
const inverse = `!${file}`

Expand All @@ -325,7 +327,7 @@ class PackWalker extends IgnoreWalker {
// if we have a file and we know that, it's strictly required
if (stat.isFile()) {
strict.unshift(inverse)
this.requiredFiles.push(file.startsWith('/') ? file.slice(1) : file)
this.requiredFiles.push(file)
} else if (stat.isDirectory()) {
// otherwise, it's a default ignore, and since we got here we know it's not a pattern
// so we include the directory contents
Expand Down
2 changes: 0 additions & 2 deletions test/package-json-dir-with-slashes.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ const pkg = t.testdir({
files: [
'/lib',
'./lib2',
'./lib3/*',
],
}),
lib: {
Expand All @@ -27,7 +26,6 @@ const pkg = t.testdir({
'fiv.js': 'fiv',
'.DS_Store': 'a store of ds',
},
lib3: 'not a dir',
})

t.test('package with slash directories', async (t) => {
Expand Down
4 changes: 0 additions & 4 deletions test/package-json-files-with-slashes.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,17 @@ const packlist = require('../')
const pkg = t.testdir({
'package.json': JSON.stringify({
files: [
'./fiv.js',
'/lib/one.js',
'/lib/two.js',
'/lib/tre.js',
'./lib/for.js',
],
}),
'fiv.js': 'fiv',
lib: {
'one.js': 'one',
'two.js': 'two',
'tre.js': 'tre',
'for.js': 'for',
'fiv.js': 'fiv',
'.npmignore': 'two.js',
'.DS_Store': 'a store of ds',
},
Expand All @@ -35,7 +32,6 @@ t.test('package with slash files', async (t) => {
const tree = await arborist.loadActual()
const files = await packlist(tree)
t.same(files, [
'fiv.js',
'lib/for.js',
'lib/one.js',
'lib/tre.js',
Expand Down

0 comments on commit ff9aae5

Please sign in to comment.