@@ -18,6 +18,23 @@ const BOWER_COMPONENTS_PATTERN = `${path.sep}bower_components${path.sep}`
18
18
/** @internal */
19
19
export const ELECTRON_COMPILE_SHIM_FILENAME = "__shim.js"
20
20
21
+ function findLongestCommonDirectory ( path1 : string , path2 : string ) {
22
+ const parts1 = path1 . split ( path . sep )
23
+ const parts2 = path2 . split ( path . sep )
24
+
25
+ const commonParts = [ ]
26
+
27
+ for ( let i = 0 ; i < Math . min ( parts1 . length , parts2 . length ) ; i ++ ) {
28
+ if ( parts1 [ i ] === parts2 [ i ] ) {
29
+ commonParts . push ( parts1 [ i ] )
30
+ } else {
31
+ break
32
+ }
33
+ }
34
+
35
+ return commonParts . length > 0 ? path . join ( ...commonParts , path . sep ) : path . sep
36
+ }
37
+
21
38
export function getDestinationPath ( file : string , fileSet : ResolvedFileSet ) {
22
39
if ( file === fileSet . src ) {
23
40
return fileSet . destination
@@ -27,17 +44,8 @@ export function getDestinationPath(file: string, fileSet: ResolvedFileSet) {
27
44
if ( file . length > src . length && file . startsWith ( src ) && file [ src . length ] === path . sep ) {
28
45
return dest + file . substring ( src . length )
29
46
} else {
30
- // hoisted node_modules
31
- // not lastIndexOf, to ensure that nested module (top-level module depends on) copied to parent node_modules, not to top-level directory
32
- // project https://github.com/angexis/punchcontrol/commit/cf929aba55c40d0d8901c54df7945e1d001ce022
33
- let index = file . indexOf ( NODE_MODULES_PATTERN )
34
- if ( index < 0 && file . endsWith ( `${ path . sep } node_modules` ) ) {
35
- index = file . length - 13
36
- }
37
- // if (index < 0) {
38
- // throw new Error(`File "${file}" not under the source directory "${fileSet.src}"`)
39
- // }
40
- return dest + file . substring ( index )
47
+ const commonParts = findLongestCommonDirectory ( file , dest )
48
+ return dest + file . substring ( commonParts . length )
41
49
}
42
50
}
43
51
}
0 commit comments