Skip to content

Commit 811ca29

Browse files
TrevorBurnhamwraithgar
authored andcommitted
fix: stop working around bug fixed in npm-package-arg@12.0.2
Removes all usage of `.replace(/#/g, '%23')` for compatibility with the new version This is the code changes from npm#8112 isloated from the dependency update itself. Closes: npm/npm-package-arg#203 Credit: @TrevorBurnham
1 parent b153927 commit 811ca29

File tree

10 files changed

+21
-21
lines changed

10 files changed

+21
-21
lines changed

lib/commands/diff.js

+7-7
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ class Diff extends BaseCommand {
106106
const pkgName = await this.packageName()
107107
return [
108108
`${pkgName}@${this.npm.config.get('tag')}`,
109-
`file:${this.prefix.replace(/#/g, '%23')}`,
109+
`file:${this.prefix}`,
110110
]
111111
}
112112

@@ -134,7 +134,7 @@ class Diff extends BaseCommand {
134134
}
135135
return [
136136
`${pkgName}@${a}`,
137-
`file:${this.prefix.replace(/#/g, '%23')}`,
137+
`file:${this.prefix}`,
138138
]
139139
}
140140

@@ -166,7 +166,7 @@ class Diff extends BaseCommand {
166166
}
167167
return [
168168
`${spec.name}@${spec.fetchSpec}`,
169-
`file:${this.prefix.replace(/#/g, '%23')}`,
169+
`file:${this.prefix}`,
170170
]
171171
}
172172

@@ -179,7 +179,7 @@ class Diff extends BaseCommand {
179179
}
180180
}
181181

182-
const aSpec = `file:${node.realpath.replace(/#/g, '%23')}`
182+
const aSpec = `file:${node.realpath}`
183183

184184
// finds what version of the package to compare against, if a exact
185185
// version or tag was passed than it should use that, otherwise
@@ -212,8 +212,8 @@ class Diff extends BaseCommand {
212212
]
213213
} else if (spec.type === 'directory') {
214214
return [
215-
`file:${spec.fetchSpec.replace(/#/g, '%23')}`,
216-
`file:${this.prefix.replace(/#/g, '%23')}`,
215+
`file:${spec.fetchSpec}`,
216+
`file:${this.prefix}`,
217217
]
218218
} else {
219219
throw this.usageError(`Spec type ${spec.type} not supported.`)
@@ -281,7 +281,7 @@ class Diff extends BaseCommand {
281281

282282
const res = !node || !node.package || !node.package.version
283283
? spec.fetchSpec
284-
: `file:${node.realpath.replace(/#/g, '%23')}`
284+
: `file:${node.realpath}`
285285

286286
return `${spec.name}@${res}`
287287
})

lib/commands/link.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ class Link extends ArboristWorkspaceCmd {
124124
...this.npm.flatOptions,
125125
prune: false,
126126
path: this.npm.prefix,
127-
add: names.map(l => `file:${resolve(globalTop, 'node_modules', l).replace(/#/g, '%23')}`),
127+
add: names.map(l => `file:${resolve(globalTop, 'node_modules', l)}`),
128128
save,
129129
workspaces: this.workspaceNames,
130130
})
@@ -135,7 +135,7 @@ class Link extends ArboristWorkspaceCmd {
135135
async linkPkg () {
136136
const wsp = this.workspacePaths
137137
const paths = wsp && wsp.length ? wsp : [this.npm.prefix]
138-
const add = paths.map(path => `file:${path.replace(/#/g, '%23')}`)
138+
const add = paths.map(path => `file:${path}`)
139139
const globalTop = resolve(this.npm.globalDir, '..')
140140
const Arborist = require('@npmcli/arborist')
141141
const arb = new Arborist({

workspaces/arborist/lib/arborist/build-ideal-tree.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -447,7 +447,7 @@ module.exports = cls => class IdealTreeBuilder extends cls {
447447
.catch(/* istanbul ignore next */ () => null)
448448
if (st && st.isSymbolicLink()) {
449449
const target = await readlink(dir)
450-
const real = resolve(dirname(dir), target).replace(/#/g, '%23')
450+
const real = resolve(dirname(dir), target)
451451
tree.package.dependencies[name] = `file:${real}`
452452
} else {
453453
tree.package.dependencies[name] = '*'
@@ -522,12 +522,12 @@ module.exports = cls => class IdealTreeBuilder extends cls {
522522

523523
const { name } = spec
524524
if (spec.type === 'file') {
525-
spec = npa(`file:${relpath(path, spec.fetchSpec).replace(/#/g, '%23')}`, path)
525+
spec = npa(`file:${relpath(path, spec.fetchSpec)}`, path)
526526
spec.name = name
527527
} else if (spec.type === 'directory') {
528528
try {
529529
const real = await realpath(spec.fetchSpec, this[_rpcache], this[_stcache])
530-
spec = npa(`file:${relpath(path, real).replace(/#/g, '%23')}`, path)
530+
spec = npa(`file:${relpath(path, real)}`, path)
531531
spec.name = name
532532
} catch {
533533
// TODO: create synthetic test case to simulate realpath failure

workspaces/arborist/lib/arborist/load-actual.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ module.exports = cls => class ActualLoader extends cls {
216216
const actualRoot = tree.isLink ? tree.target : tree
217217
const { dependencies = {} } = actualRoot.package
218218
for (const [name, kid] of actualRoot.children.entries()) {
219-
const def = kid.isLink ? `file:${kid.realpath.replace(/#/g, '%23')}` : '*'
219+
const def = kid.isLink ? `file:${kid.realpath}` : '*'
220220
dependencies[name] = dependencies[name] || def
221221
}
222222
actualRoot.package = { ...actualRoot.package, dependencies }

workspaces/arborist/lib/arborist/load-virtual.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ module.exports = cls => class VirtualLoader extends cls {
149149
})
150150

151151
for (const [name, path] of workspaces.entries()) {
152-
lockWS[name] = `file:${path.replace(/#/g, '%23')}`
152+
lockWS[name] = `file:${path}`
153153
}
154154

155155
// Should rootNames exclude optional?

workspaces/arborist/lib/arborist/reify.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1364,7 +1364,7 @@ module.exports = cls => class Reifier extends cls {
13641364
// path initially, in which case we can end up with the wrong
13651365
// thing, so just get the ultimate fetchSpec and relativize it.
13661366
const p = req.fetchSpec.replace(/^file:/, '')
1367-
const rel = relpath(addTree.realpath, p).replace(/#/g, '%23')
1367+
const rel = relpath(addTree.realpath, p)
13681368
newSpec = `file:${rel}`
13691369
}
13701370
} else {

workspaces/arborist/lib/consistent-resolve.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ const consistentResolve = (resolved, fromPath, toPath, relPaths = false) => {
2020
raw,
2121
} = npa(resolved, fromPath)
2222
if (type === 'file' || type === 'directory') {
23-
const cleanFetchSpec = fetchSpec.replace(/#/g, '%23')
23+
const cleanFetchSpec = fetchSpec
2424
if (relPaths && toPath) {
2525
return `file:${relpath(toPath, cleanFetchSpec)}`
2626
}

workspaces/arborist/lib/link.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ class Link extends Node {
9999
// the path/realpath guard is there for the benefit of setting
100100
// these things in the "wrong" order
101101
return this.path && this.realpath
102-
? `file:${relpath(dirname(this.path), this.realpath).replace(/#/g, '%23')}`
102+
? `file:${relpath(dirname(this.path), this.realpath)}`
103103
: null
104104
}
105105

workspaces/arborist/lib/node.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -842,7 +842,7 @@ class Node {
842842
}
843843

844844
for (const [name, path] of this.#workspaces.entries()) {
845-
new Edge({ from: this, name, spec: `file:${path.replace(/#/g, '%23')}`, type: 'workspace' })
845+
new Edge({ from: this, name, spec: `file:${path}`, type: 'workspace' })
846846
}
847847
}
848848

workspaces/arborist/lib/shrinkwrap.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -817,7 +817,7 @@ class Shrinkwrap {
817817
if (!/^file:/.test(resolved)) {
818818
pathFixed = resolved
819819
} else {
820-
pathFixed = `file:${resolve(this.path, resolved.slice(5)).replace(/#/g, '%23')}`
820+
pathFixed = `file:${resolve(this.path, resolved.slice(5))}`
821821
}
822822
}
823823

@@ -1011,7 +1011,7 @@ class Shrinkwrap {
10111011
}
10121012

10131013
if (node.isLink) {
1014-
lock.version = `file:${relpath(this.path, node.realpath).replace(/#/g, '%23')}`
1014+
lock.version = `file:${relpath(this.path, node.realpath)}`
10151015
} else if (spec && (spec.type === 'file' || spec.type === 'remote')) {
10161016
lock.version = spec.saveSpec
10171017
} else if (spec && spec.type === 'git' || rSpec.type === 'git') {
@@ -1089,7 +1089,7 @@ class Shrinkwrap {
10891089
// this especially shows up with workspace edges when the root
10901090
// node is also a workspace in the set.
10911091
const p = resolve(node.realpath, spec.slice('file:'.length))
1092-
set[k] = `file:${relpath(node.realpath, p).replace(/#/g, '%23')}`
1092+
set[k] = `file:${relpath(node.realpath, p)}`
10931093
} else {
10941094
set[k] = spec
10951095
}

0 commit comments

Comments
 (0)