Skip to content

Commit 1a129ea

Browse files
committed
Add isPath
1 parent 5f70d8f commit 1a129ea

File tree

3 files changed

+20
-4
lines changed

3 files changed

+20
-4
lines changed

registry/lib/npm.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
const { isDebug } = /*@__PURE__*/ require('./debug')
44
const { readJsonSync } = /*@__PURE__*/ require('./fs')
5-
const { isRelative } = /*@__PURE__*/ require('./path')
5+
const { isPath } = /*@__PURE__*/ require('./path')
66
const { spawn } = /*@__PURE__*/ require('./spawn')
77

88
let _fs
@@ -345,9 +345,7 @@ function runBin(binPath, args, options) {
345345
/*@__PURE__*/ require('./constants/exec-path'),
346346
[
347347
.../*@__PURE__*/ require('./constants/node-no-warnings-flags'),
348-
isRelative(binPath) || getPath().isAbsolute(binPath)
349-
? resolveBinPathSync(binPath)
350-
: whichBinSync(binPath),
348+
isPath(binPath) ? resolveBinPathSync(binPath) : whichBinSync(binPath),
351349
...args
352350
],
353351
options

registry/lib/path.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { PathLike } from 'node:fs'
33

44
declare const Path: {
55
isNodeModules(pathLike: PathLike): boolean
6+
isPath(pathLike: PathLike): boolean
67
isRelative(pathLike: PathLike): boolean
78
normalizePath(pathLike: PathLike): string
89
pathLikeToString(pathLike: PathLike): string

registry/lib/path.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,17 @@ function getBuffer() {
1717
return _buffer
1818
}
1919

20+
let _path
21+
/*@__NO_SIDE_EFFECTS__*/
22+
function getPath() {
23+
if (_path === undefined) {
24+
// Use non-'node:' prefixed require to avoid Webpack errors.
25+
// eslint-disable-next-line n/prefer-node-protocol
26+
_path = /*@__PURE__*/ require('path')
27+
}
28+
return _path
29+
}
30+
2031
let _url
2132
/*@__NO_SIDE_EFFECTS__*/
2233
function getUrl() {
@@ -34,6 +45,11 @@ function isNodeModules(pathLike) {
3445
return nodeModulesPathRegExp.test(filepath)
3546
}
3647

48+
/*@__NO_SIDE_EFFECTS__*/
49+
function isPath(pathLike) {
50+
return isRelative(pathLike) || getPath().isAbsolute(pathLike)
51+
}
52+
3753
/*@__NO_SIDE_EFFECTS__*/
3854
function isRelative(pathLike) {
3955
const filepath = pathLikeToString(pathLike)
@@ -156,6 +172,7 @@ function trimLeadingDotSlash(pathLike) {
156172

157173
module.exports = {
158174
isNodeModules,
175+
isPath,
159176
isRelative,
160177
normalizePath,
161178
pathLikeToString,

0 commit comments

Comments
 (0)