Skip to content

Commit 529de00

Browse files
committed
Add test for reading pkg.files
1 parent 8b5caae commit 529de00

File tree

7 files changed

+23
-7
lines changed

7 files changed

+23
-7
lines changed

process-dir.js

+4-7
Original file line numberDiff line numberDiff line change
@@ -178,14 +178,11 @@ async function process (dir) {
178178
let pattern = '**/*.js'
179179

180180
let pkgPath = join(dir, 'package.json')
181-
let pkgFile = {}
182-
183181
if (fs.existsSync(pkgPath)) {
184-
pkgFile = JSON.parse(await readFile(pkgPath))
185-
}
186-
187-
if ('files' in pkgFile) {
188-
pattern = pkgFile.files
182+
let pkg = JSON.parse(await readFile(pkgPath))
183+
if (pkg.files) {
184+
pattern = pkg.files
185+
}
189186
}
190187

191188
let all = await globby(pattern, { ignore, cwd: dir })

test/fixtures/files/a/file.js

Whitespace-only changes.

test/fixtures/files/a/index.js

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
function a () {
2+
console.log('cjs a')
3+
}
4+
5+
module.exports = { a, toShare }

test/fixtures/files/file.js

Whitespace-only changes.

test/fixtures/files/index.js

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
const { a } = require('./a')

test/fixtures/files/package.json

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"name": "files",
3+
"version": "0.0.0",
4+
"files": [
5+
"index.js",
6+
"a/index.js"
7+
]
8+
}

test/index.test.js

+5
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,11 @@ it('reads npmignore', async () => {
129129
expect(files).not.toContain('e/index.cjs')
130130
})
131131

132+
it('reads package.files', async () => {
133+
let [lib] = await copyDirs('files')
134+
await processDir(lib)
135+
})
136+
132137
it('throws on non-index file', async () => {
133138
let [lib] = await copyDirs('non-index-error')
134139
let err

0 commit comments

Comments
 (0)