11/* eslint-disable no-console */
22import { readFileSync , writeFileSync } from 'fs' ;
33import { cp } from 'fs/promises' ;
4- import { isAbsolute , join } from 'path' ;
4+ import { isAbsolute , join , resolve } from 'path' ;
55
66export async function copyToTemp ( originalPath : string , tmpDirPath : string ) : Promise < void > {
77 // copy files to tmp dir
@@ -35,7 +35,7 @@ function fixPackageJson(cwd: string): void {
3535 const extendsPath = packageJson . volta . extends ;
3636 // We add a virtual dir to ensure that the relative depth is consistent
3737 // dirPath is relative to ./../test-applications/xxx
38- const newPath = join ( __dirname , 'virtual-dir/' , extendsPath ) ;
38+ const newPath = resolve ( __dirname , 'virtual-dir/' , extendsPath ) ;
3939 packageJson . volta . extends = newPath ;
4040 console . log ( `Fixed volta.extends to ${ newPath } ` ) ;
4141 } else {
@@ -45,7 +45,8 @@ function fixPackageJson(cwd: string): void {
4545 writeFileSync ( packageJsonPath , JSON . stringify ( packageJson , null , 2 ) ) ;
4646}
4747
48- function fixFileLinkDependencies ( dependencyObj : Record < string , string > ) : void {
48+ // Exported for pnpmOverrides as well
49+ export function fixFileLinkDependencies ( dependencyObj : Record < string , string > ) : void {
4950 for ( const [ key , value ] of Object . entries ( dependencyObj ) ) {
5051 const prefix = value . startsWith ( 'link:' ) ? 'link:' : value . startsWith ( 'file:' ) ? 'file:' : null ;
5152 if ( ! prefix ) {
@@ -59,9 +60,9 @@ function fixFileLinkDependencies(dependencyObj: Record<string, string>): void {
5960
6061 // We add a virtual dir to ensure that the relative depth is consistent
6162 // dirPath is relative to ./../test-applications/xxx
62- const newPath = join ( __dirname , 'virtual-dir/ ' , dirPath ) ;
63+ const absPath = resolve ( __dirname , 'virtual-dir' , dirPath ) ;
6364
64- dependencyObj [ key ] = `${ prefix } ${ newPath } ` ;
65- console . log ( `Fixed ${ key } dependency to ${ newPath } ` ) ;
65+ dependencyObj [ key ] = `${ prefix } ${ absPath } ` ;
66+ console . log ( `Fixed ${ key } dependency to ${ absPath } ` ) ;
6667 }
6768}
0 commit comments