@@ -218,6 +218,14 @@ function isResponseOk(response: IncomingMessage): boolean {
218
218
)
219
219
}
220
220
221
+ function resolveBasePath ( pathsRelativeTo = '.' ) : string {
222
+ // Node's path.resolve will process path segments from right to left until
223
+ // it creates a valid absolute path. So if `pathsRelativeTo` is an absolute
224
+ // path, process.cwd() is not used, which is the common expectation. If none
225
+ // of the paths resolve then it defaults to process.cwd().
226
+ return path . resolve ( process . cwd ( ) , pathsRelativeTo )
227
+ }
228
+
221
229
/**
222
230
* Package.json data to base the User-Agent on
223
231
*/
@@ -445,7 +453,7 @@ export class SocketSdk {
445
453
filepaths : string [ ] ,
446
454
pathsRelativeTo = '.'
447
455
) : Promise < SocketSdkResultType < 'createDependenciesSnapshot' > > {
448
- const basePath = path . join ( process . cwd ( ) , pathsRelativeTo )
456
+ const basePath = resolveBasePath ( pathsRelativeTo )
449
457
const absFilepaths = filepaths . map ( p => path . join ( basePath , p ) )
450
458
try {
451
459
const data = await getResponseJson (
@@ -468,11 +476,7 @@ export class SocketSdk {
468
476
filepaths : string [ ] ,
469
477
pathsRelativeTo : string = '.'
470
478
) : Promise < SocketSdkResultType < 'CreateOrgFullScan' > > {
471
- // Resolve will process path segments until it creates a valid absolute
472
- // path. So if the given pathsRelativeTo is an absolute path, the cwd()
473
- // is not used, which is the common expectation. If none of the paths
474
- // resolve then it defaults to process.cwd()
475
- const basePath = path . resolve ( process . cwd ( ) , pathsRelativeTo )
479
+ const basePath = resolveBasePath ( pathsRelativeTo )
476
480
const absFilepaths = filepaths . map ( p => path . join ( basePath , p ) )
477
481
try {
478
482
const data = await getResponseJson (
@@ -513,7 +517,7 @@ export class SocketSdk {
513
517
pathsRelativeTo : string = '.' ,
514
518
issueRules ?: Record < string , boolean >
515
519
) : Promise < SocketSdkResultType < 'createReport' > > {
516
- const basePath = path . join ( process . cwd ( ) , pathsRelativeTo )
520
+ const basePath = resolveBasePath ( pathsRelativeTo )
517
521
const absFilepaths = filepaths . map ( p => path . join ( basePath , p ) )
518
522
try {
519
523
const data = await createUploadRequest (
0 commit comments