1
1
import fs from 'node:fs' ;
2
- import { extname , join } from 'node:path' ;
2
+ import { extname , join , normalize } from 'node:path' ;
3
3
import type { FsUpdates , UpdateAppOptions } from '../types' ;
4
4
import { getPackageManager } from '../utils/utils' ;
5
5
@@ -22,12 +22,18 @@ export async function mergeIntegrationDir(
22
22
const s = await fs . promises . stat ( srcChildPath ) ;
23
23
24
24
if ( s . isDirectory ( ) ) {
25
- await mergeIntegrationDir ( fileUpdates , opts , srcChildPath , destRootPath , alwaysInRoot ) ;
25
+ await mergeIntegrationDir (
26
+ fileUpdates ,
27
+ opts ,
28
+ srcChildPath ,
29
+ normalize ( destRootPath ) . replace ( / \\ / g, '/' ) ,
30
+ alwaysInRoot
31
+ ) ;
26
32
} else if ( s . isFile ( ) ) {
27
33
const finalDestPath = getFinalDestPath ( opts , destRootPath , destDir , destName , alwaysInRoot ) ;
28
34
29
35
if ( destName === 'package.json' ) {
30
- await mergePackageJsons ( fileUpdates , srcChildPath , destRootPath ) ;
36
+ await mergePackageJsons ( fileUpdates , srcChildPath , finalDestPath ) ;
31
37
} else if ( destName === 'settings.json' ) {
32
38
await mergeJsons ( fileUpdates , srcChildPath , finalDestPath ) ;
33
39
} else if ( destName === 'README.md' ) {
@@ -37,7 +43,7 @@ export async function mergeIntegrationDir(
37
43
destName === '.prettierignore' ||
38
44
destName === '.eslintignore'
39
45
) {
40
- await mergeIgnoresFile ( fileUpdates , srcChildPath , destRootPath ) ;
46
+ await mergeIgnoresFile ( fileUpdates , srcChildPath , finalDestPath ) ;
41
47
} else if ( ext === '.css' ) {
42
48
await mergeCss ( fileUpdates , srcChildPath , finalDestPath , opts ) ;
43
49
} else if ( fs . existsSync ( finalDestPath ) ) {
@@ -75,11 +81,17 @@ function getFinalDestPath(
75
81
76
82
const finalDestPath =
77
83
alwaysInRoot &&
78
- alwaysInRoot . some ( ( rootItem ) => destName . includes ( rootItem ) || destDir . includes ( rootItem ) )
84
+ ( destName === 'package.json' ||
85
+ alwaysInRoot . some (
86
+ ( rootItem ) =>
87
+ normalize ( destName ) . replace ( / \\ / g, '/' ) . includes ( rootItem ) ||
88
+ normalize ( destDir ) . replace ( / \\ / g, '/' ) . includes ( rootItem )
89
+ ) )
79
90
? destRootPath
80
91
: destChildPath ;
81
92
82
- return finalDestPath ;
93
+ // Normalize path separators to forward slashes for cross-platform compatibility
94
+ return normalize ( finalDestPath ) . replace ( / \\ / g, '/' ) ;
83
95
}
84
96
85
97
async function mergePackageJsons ( fileUpdates : FsUpdates , srcPath : string , destPath : string ) {
0 commit comments