Skip to content

Commit

Permalink
fix: ignore ENOTDIR errors (#176)
Browse files Browse the repository at this point in the history
Fixed a bug with `map-workspaces` over-aggressively inspecting symbolic
links to files as workspaces. When this happens, an `ENOTDIR` error is
thrown. We should be able to safely ignore that error just like
`ENOENT`, which fixes the root cause of the referenced bug.

closes: npm/cli#7834
  • Loading branch information
brianlenz authored Nov 20, 2024
1 parent 44c0691 commit ae9cd9e
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ async function mapWorkspaces (opts = {}) {
try {
pkg = await pkgJson.normalize(path.join(opts.cwd, match))
} catch (err) {
if (err.code === 'ENOENT') {
if (err.code === 'ENOENT' || err.code === 'ENOTDIR') {
continue
} else {
throw err
Expand Down
6 changes: 6 additions & 0 deletions tap-snapshots/test/test.js.test.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,12 @@ Map {
}
`

exports[`test/test.js TAP ignore symlink workspace files > should not throw an error 1`] = `
Map {
"a" => "{CWD}/test/tap-testdir-test-ignore-symlink-workspace-files/packages/a",
}
`

exports[`test/test.js TAP match duplicates then exclude one > should include the non-excluded item on returned Map 1`] = `
Map {
"a" => "{CWD}/test/tap-testdir-test-match-duplicates-then-exclude-one/packages/a",
Expand Down
26 changes: 26 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -980,3 +980,29 @@ test('match duplicates then exclude one', t => {
'should include the non-excluded item on returned Map'
)
})

test('ignore symlink workspace files', t => {
const cwd = t.testdir({
'index.js': 'console.log("hi");',
packages: {
a: {
'package.json': '{ "name": "a" }',
'index.js': t.fixture('symlink', '../../index.js'),
},
},
})

return t.resolveMatchSnapshot(
mapWorkspaces({
cwd,
pkg: {
workspaces: {
packages: [
'packages/**',
],
},
},
}),
'should not throw an error'
)
})

0 comments on commit ae9cd9e

Please sign in to comment.