@@ -6,6 +6,7 @@ import { IDiagnosticDump, IDiagnosticSource } from '../adapter/diagnosics';
6
6
import { DebugType } from '../common/contributionUtils' ;
7
7
8
8
const nodeInternalMarker = '<node_internals>' ;
9
+ const node16InternalUrl = 'node:' ;
9
10
10
11
export const isNodeType = ( dump : IDiagnosticDump ) =>
11
12
dump . config . type === DebugType . Node ||
@@ -16,11 +17,14 @@ export const isBrowserType = (dump: IDiagnosticDump) =>
16
17
dump . config . type === DebugType . Chrome || dump . config . type === DebugType . Edge ;
17
18
18
19
export const sortScore = ( source : IDiagnosticSource ) => {
19
- if ( source . absolutePath . startsWith ( nodeInternalMarker ) ) {
20
+ if (
21
+ source . absolutePath . startsWith ( nodeInternalMarker ) ||
22
+ source . url . startsWith ( node16InternalUrl )
23
+ ) {
20
24
return 2 ;
21
25
}
22
26
23
- if ( source . absolutePath . includes ( 'node_moeules ' ) ) {
27
+ if ( source . absolutePath . includes ( 'node_modules ' ) ) {
24
28
return 1 ;
25
29
}
26
30
@@ -31,6 +35,10 @@ export const prettyName = (
31
35
source : { absolutePath : string ; url : string } ,
32
36
dump : IDiagnosticDump ,
33
37
) => {
38
+ if ( source . url . startsWith ( node16InternalUrl ) ) {
39
+ return source . url ;
40
+ }
41
+
34
42
if ( source . absolutePath . startsWith ( nodeInternalMarker ) ) {
35
43
return source . absolutePath ;
36
44
}
@@ -57,18 +65,17 @@ export const isAbsolutePosix = (path: string) => path.startsWith('/');
57
65
export const isAbsoluteWin32 = ( path : string ) => / ^ [ a - z ] : / i. test ( path ) ;
58
66
59
67
export const relative = ( fromPath : string , toPath : string ) => {
60
- const parts = fromPath . split ( '/' ) ;
61
- for ( const segment of toPath . split ( '/' ) ) {
62
- if ( segment === '..' ) {
63
- parts . pop ( ) ;
64
- } else if ( segment === '.' ) {
65
- // no-op
66
- } else {
67
- parts . push ( segment ) ;
68
- }
68
+ // shift off the shared prefix of both paths
69
+ const fromParts = fromPath . split ( '/' ) ;
70
+ const toParts = toPath . split ( '/' ) ;
71
+ while ( fromParts . length && toParts [ 0 ] === fromParts [ 0 ] ) {
72
+ fromParts . shift ( ) ;
73
+ toParts . shift ( ) ;
69
74
}
70
75
71
- return parts . join ( '/' ) ;
76
+ // ".." for each remaining level in the fromParts
77
+ const nav = fromParts . length ? new Array ( fromParts . length ) . fill ( '..' ) : [ '.' ] ;
78
+ return nav . concat ( toParts ) . join ( '/' ) ;
72
79
} ;
73
80
74
81
export const properRelative = ( fromPath : string , toPath : string ) : string => {
0 commit comments