1
+ /* eslint-disable no-console */
1
2
import { readFileSync , writeFileSync } from 'fs' ;
2
3
import { cp } from 'fs/promises' ;
3
- import { join , resolve } from 'path' ;
4
+ import { join } from 'path' ;
4
5
5
6
export async function copyToTemp ( originalPath : string , tmpDirPath : string ) : Promise < void > {
6
7
// copy files to tmp dir
@@ -12,25 +13,40 @@ export async function copyToTemp(originalPath: string, tmpDirPath: string): Prom
12
13
function fixPackageJson ( cwd : string ) : void {
13
14
const packageJsonPath = join ( cwd , 'package.json' ) ;
14
15
const packageJson = JSON . parse ( readFileSync ( packageJsonPath , 'utf8' ) ) as {
16
+ dependencies ?: Record < string , string > ;
15
17
devDependencies ?: Record < string , string > ;
16
18
volta ?: Record < string , unknown > ;
17
19
} ;
18
20
19
21
// 1. Fix file dependencies
20
- if ( packageJson . devDependencies ?. [ '@sentry-internal/test-utils' ] ) {
21
- const newPath = join ( __dirname , '../../test-utils' ) ;
22
- packageJson . devDependencies [ '@sentry-internal/test-utils' ] = `link:${ newPath } ` ;
23
- // eslint-disable-next-line no-console
24
- console . log ( `Fixed devDependencies['@sentry-internal/test-utils'] to ${ newPath } ` ) ;
22
+ const didFixTestUtilsDependency =
23
+ ( packageJson . dependencies && fixTestUtilsDependency ( packageJson . dependencies ) ) ||
24
+ ( packageJson . devDependencies && fixTestUtilsDependency ( packageJson . devDependencies ) ) ;
25
+
26
+ if ( ! didFixTestUtilsDependency ) {
27
+ console . log ( "No '@sentry-internal/test-utils' dependency found" ) ;
25
28
}
26
29
27
30
// 2. Fix volta extends
28
31
if ( packageJson . volta ?. extends === '../../package.json' ) {
29
32
const newPath = join ( __dirname , '../package.json' ) ;
30
33
packageJson . volta . extends = newPath ;
31
- // eslint-disable-next-line no-console
32
34
console . log ( `Fixed volta.extends to ${ newPath } ` ) ;
35
+ } else {
36
+ console . log ( 'No volta.extends found' ) ;
33
37
}
34
38
35
39
writeFileSync ( packageJsonPath , JSON . stringify ( packageJson , null , 2 ) ) ;
36
40
}
41
+
42
+ function fixTestUtilsDependency ( dependencyObj : Record < string , string > ) : boolean {
43
+ // 1. Fix file dependencies
44
+ if ( dependencyObj [ '@sentry-internal/test-utils' ] ) {
45
+ const newPath = join ( __dirname , '../../test-utils' ) ;
46
+ dependencyObj [ '@sentry-internal/test-utils' ] = `link:${ newPath } ` ;
47
+ console . log ( `Fixed '@sentry-internal/test-utils' dependency to ${ newPath } ` ) ;
48
+ return true ;
49
+ }
50
+
51
+ return false ;
52
+ }
0 commit comments