Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: allow package installs in drive root directories #7038

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 48 additions & 0 deletions test/lib/commands/install.js
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,54 @@ t.test('exec commands', async t => {
}
)
})

await t.test('Windows - npm install works in drive root directory', async t => {
if (process.platform !== 'win32') {
return t.skip('root directory install - test not relevant on platform')
}

let failed = false

const { npm } = await loadMockNpm(t, {
config: {
prefix: 'C:\\',
'dry-run': true,
},
})

try {
await npm.exec('install', ['fizzbuzz'])
} catch (error) {
failed = true
throw error
}

t.strictSame(failed, false, 'packages would install')
})

await t.test('Not Windows - npm install works in drive root directory', async t => {
if (process.platform === 'win32') {
return t.skip('root directory install - test not relevant on platform')
}

let failed = false

const { npm } = await loadMockNpm(t, {
config: {
prefix: '/',
'dry-run': true,
},
})

try {
await npm.exec('install', ['fizzbuzz'])
} catch (error) {
failed = true
throw error
}

t.strictSame(failed, false, 'packages would install')
})
})

t.test('completion', async t => {
Expand Down
8 changes: 7 additions & 1 deletion workspaces/arborist/lib/arborist/reify.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ const {
mkdir,
rm,
symlink,
access,
} = require('fs/promises')
const { moveFile } = require('@npmcli/fs')
const PackageJson = require('@npmcli/package-json')
Expand Down Expand Up @@ -192,7 +193,12 @@ module.exports = cls => class Reifier extends cls {
// we do NOT want to set ownership on this folder, especially
// recursively, because it can have other side effects to do that
// in a project directory. We just want to make it if it's missing.
await mkdir(resolve(this.path), { recursive: true })
try {
await access(resolve(this.path))
} catch {
// The project directory is missing so we make it.
await mkdir(resolve(this.path), { recursive: true })
}

// do not allow the top-level node_modules to be a symlink
await this[_validateNodeModules](resolve(this.path, 'node_modules'))
Expand Down