Skip to content

Commit 2ac3fc5

Browse files
committed
Use more path.resolve
1 parent 046b2cf commit 2ac3fc5

File tree

1 file changed

+6
-8
lines changed

1 file changed

+6
-8
lines changed

src/index.ts

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -224,12 +224,13 @@ function isResponseOk(response: IncomingMessage): boolean {
224224
)
225225
}
226226

227-
function resolveBasePath(pathsRelativeTo = '.'): string {
227+
function resolveAbsPaths(filepaths: string[], pathsRelativeTo = '.'): string[] {
228228
// Node's path.resolve will process path segments from right to left until
229229
// it creates a valid absolute path. So if `pathsRelativeTo` is an absolute
230230
// path, process.cwd() is not used, which is the common expectation. If none
231231
// of the paths resolve then it defaults to process.cwd().
232-
return path.resolve(process.cwd(), pathsRelativeTo)
232+
const basePath = path.resolve(process.cwd(), pathsRelativeTo)
233+
return filepaths.map(p => path.resolve(basePath, p))
233234
}
234235

235236
/**
@@ -459,8 +460,7 @@ export class SocketSdk {
459460
filepaths: string[],
460461
pathsRelativeTo = '.'
461462
): Promise<SocketSdkResultType<'createDependenciesSnapshot'>> {
462-
const basePath = resolveBasePath(pathsRelativeTo)
463-
const absFilepaths = filepaths.map(p => path.join(basePath, p))
463+
const absFilepaths = resolveAbsPaths(filepaths, pathsRelativeTo)
464464
try {
465465
const data = await getResponseJson(
466466
await createUploadRequest(
@@ -482,8 +482,7 @@ export class SocketSdk {
482482
filepaths: string[],
483483
pathsRelativeTo: string = '.'
484484
): Promise<SocketSdkResultType<'CreateOrgFullScan'>> {
485-
const basePath = resolveBasePath(pathsRelativeTo)
486-
const absFilepaths = filepaths.map(p => path.join(basePath, p))
485+
const absFilepaths = resolveAbsPaths(filepaths, pathsRelativeTo)
487486
try {
488487
const data = await getResponseJson(
489488
await createUploadRequest(
@@ -523,8 +522,7 @@ export class SocketSdk {
523522
pathsRelativeTo: string = '.',
524523
issueRules?: Record<string, boolean>
525524
): Promise<SocketSdkResultType<'createReport'>> {
526-
const basePath = resolveBasePath(pathsRelativeTo)
527-
const absFilepaths = filepaths.map(p => path.join(basePath, p))
525+
const absFilepaths = resolveAbsPaths(filepaths, pathsRelativeTo)
528526
try {
529527
const data = await createUploadRequest(
530528
this.#baseUrl,

0 commit comments

Comments
 (0)