Skip to content

Commit

Permalink
fix: link failing when cwd with hash tag
Browse files Browse the repository at this point in the history
Fixes #5120
  • Loading branch information
AgainPsychoX committed Jul 3, 2022
1 parent ef8d2ed commit 813615b
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 2 deletions.
5 changes: 3 additions & 2 deletions lib/commands/link.js
Expand Up @@ -2,6 +2,7 @@ const fs = require('fs')
const util = require('util')
const readdir = util.promisify(fs.readdir)
const { resolve } = require('path')
const { pathToFileURL } = require('url')

const Arborist = require('@npmcli/arborist')
const npa = require('npm-package-arg')
Expand Down Expand Up @@ -122,7 +123,7 @@ class Link extends ArboristWorkspaceCmd {
...this.npm.flatOptions,
prune: false,
path: this.npm.prefix,
add: names.map(l => `file:${resolve(globalTop, 'node_modules', l)}`),
add: names.map(l => pathToFileURL(resolve(globalTop, 'node_modules', l)).href),
save,
workspaces: this.workspaceNames,
})
Expand All @@ -133,7 +134,7 @@ class Link extends ArboristWorkspaceCmd {
async linkPkg () {
const wsp = this.workspacePaths
const paths = wsp && wsp.length ? wsp : [this.npm.prefix]
const add = paths.map(path => `file:${path}`)
const add = paths.map(path => pathToFileURL(path).href)
const globalTop = resolve(this.npm.globalDir, '..')
const arb = new Arborist({
...this.npm.flatOptions,
Expand Down
36 changes: 36 additions & 0 deletions test/lib/commands/link.js
Expand Up @@ -514,3 +514,39 @@ t.test('--global option', async t => {
'should throw an useful error'
)
})

t.test('hash character in working directory path', async t => {
const testdir = t.testdir({
'global-prefix': {
lib: {
node_modules: {
a: {
'package.json': JSON.stringify({
name: 'a',
version: '1.0.0',
}),
},
},
},
},
'i_like_#_in_my_paths': {
'test-pkg-link': {
'package.json': JSON.stringify({
name: 'test-pkg-link',
version: '1.0.0',
}),
},
},
})
npm.globalDir = resolve(testdir, 'global-prefix', 'lib', 'node_modules')
npm.prefix = resolve(testdir, 'i_like_#_in_my_paths', 'test-pkg-link')

link.workspacePaths = null
await link.exec([]);
const links = await printLinks({
path: resolve(npm.globalDir, '..'),
global: true,
})

console.log(links);
})

0 comments on commit 813615b

Please sign in to comment.