fix: ignore files in node_modules

PR #2741
close #2730
This commit is contained in:
Zoltan Kochan
2020-08-01 19:43:42 +03:00
committed by GitHub
parent 390006e872
commit 24af41f20b
3 changed files with 32 additions and 5 deletions

View File

@@ -0,0 +1,5 @@
---
"@pnpm/read-modules-dir": patch
---
Ignore files in node_modules.

View File

@@ -16,18 +16,18 @@ async function _readModulesDir (
) {
let pkgNames: string[] = []
const parentDir = scope ? path.join(modulesDir, scope) : modulesDir
for (const dir of await fs.readdir(parentDir)) {
if (dir[0] === '.') continue
for (const dir of await fs.readdir(parentDir, { withFileTypes: true })) {
if (dir.isFile() || dir.name[0] === '.') continue
if (!scope && dir[0] === '@') {
if (!scope && dir.name[0] === '@') {
pkgNames = [
...pkgNames,
...await _readModulesDir(modulesDir, dir),
...await _readModulesDir(modulesDir, dir.name),
]
continue
}
const pkgName = scope ? `${scope}/${dir}` : dir
const pkgName = scope ? `${scope}/${dir.name}` : dir.name
pkgNames.push(pkgName)
}
return pkgNames

View File

@@ -1148,3 +1148,25 @@ test('installing a package that has a manifest with byte order mark (BOM)', asyn
await project.has('paralleljs')
})
test('ignore files in node_modules', async (t: tape.Test) => {
const project = prepareEmpty(t)
const reporter = sinon.spy()
await fs.mkdir('node_modules')
await fs.writeFile('node_modules/foo', 'x', 'utf8')
await addDependenciesToPackage(
{
name: 'project',
version: '0.0.0',
},
['lodash@4.0.0'],
await testDefaults({ fastUnpack: false, reporter })
)
const m = project.requireModule('lodash')
t.ok(typeof m === 'function', '_ is available')
t.ok(typeof m.clone === 'function', '_.clone is available')
t.equal(await fs.readFile('node_modules/foo', 'utf8'), 'x')
})