@@ -70,11 +70,19 @@ function listChangedPaths(base, head = "HEAD") {
7070 . filter ( ( line ) => line . length > 0 ) ;
7171}
7272
73- function hasExtensionPackage ( extensionId ) {
74- return fs . existsSync ( path . join ( repoRoot , BUNDLED_PLUGIN_ROOT_DIR , extensionId , "package.json" ) ) ;
73+ function listAvailableExtensionIdsFromGit ( ) {
74+ const packageFiles = runGit ( [ "ls-files" , "--" , `:(glob)${ BUNDLED_PLUGIN_PATH_PREFIX } */package.json` ] )
75+ . split ( "\n" )
76+ . map ( ( line ) => normalizeRelative ( line . trim ( ) ) )
77+ . filter ( ( line ) => line . length > 0 ) ;
78+ return packageFiles
79+ . map ( ( file ) => file . match ( new RegExp ( `^${ BUNDLED_PLUGIN_PATH_PREFIX } ([^/]+)/package\\.json$` ) ) )
80+ . filter ( ( match ) => match )
81+ . map ( ( match ) => match [ 1 ] )
82+ . toSorted ( ( left , right ) => left . localeCompare ( right ) ) ;
7583}
7684
77- export function listAvailableExtensionIds ( ) {
85+ function listAvailableExtensionIdsFromDirectory ( ) {
7886 const extensionsDir = path . join ( repoRoot , BUNDLED_PLUGIN_ROOT_DIR ) ;
7987 if ( ! fs . existsSync ( extensionsDir ) ) {
8088 return [ ] ;
@@ -84,11 +92,22 @@ export function listAvailableExtensionIds() {
8492 . readdirSync ( extensionsDir , { withFileTypes : true } )
8593 . filter ( ( entry ) => entry . isDirectory ( ) )
8694 . map ( ( entry ) => entry . name )
87- . filter ( ( extensionId ) => hasExtensionPackage ( extensionId ) )
95+ . filter ( ( extensionId ) =>
96+ fs . existsSync ( path . join ( repoRoot , BUNDLED_PLUGIN_ROOT_DIR , extensionId , "package.json" ) ) ,
97+ )
8898 . toSorted ( ( left , right ) => left . localeCompare ( right ) ) ;
8999}
90100
101+ export function listAvailableExtensionIds ( ) {
102+ try {
103+ return listAvailableExtensionIdsFromGit ( ) ;
104+ } catch {
105+ return listAvailableExtensionIdsFromDirectory ( ) ;
106+ }
107+ }
108+
91109export function detectChangedExtensionIds ( changedPaths ) {
110+ const availableExtensionIds = new Set ( listAvailableExtensionIds ( ) ) ;
92111 const extensionIds = new Set ( ) ;
93112
94113 for ( const rawPath of changedPaths ) {
@@ -102,14 +121,14 @@ export function detectChangedExtensionIds(changedPaths) {
102121 ) ;
103122 if ( extensionMatch ) {
104123 const extensionId = extensionMatch [ 1 ] ;
105- if ( hasExtensionPackage ( extensionId ) ) {
124+ if ( availableExtensionIds . has ( extensionId ) ) {
106125 extensionIds . add ( extensionId ) ;
107126 }
108127 continue ;
109128 }
110129
111130 const pairedCoreMatch = relativePath . match ( / ^ s r c \/ ( [ ^ / ] + ) (?: \/ | $ ) / ) ;
112- if ( pairedCoreMatch && hasExtensionPackage ( pairedCoreMatch [ 1 ] ) ) {
131+ if ( pairedCoreMatch && availableExtensionIds . has ( pairedCoreMatch [ 1 ] ) ) {
113132 extensionIds . add ( pairedCoreMatch [ 1 ] ) ;
114133 }
115134 }
0 commit comments