@@ -13,7 +13,10 @@ export async function getWindowsVisualStudioEditionPaths() {
1313 const platform = getPlatform ( ) ;
1414
1515 if ( platform !== "win" )
16- return [ ] ;
16+ return {
17+ vsEditionPaths : [ ] ,
18+ programFilesPaths : [ ]
19+ } ;
1720
1821 const programFilesPaths = await getWindowsProgramFilesPaths ( ) ;
1922 const potentialVisualStudioPaths = programFilesPaths
@@ -22,8 +25,10 @@ export async function getWindowsVisualStudioEditionPaths() {
2225 const versionPaths = ( await Promise . all (
2326 potentialVisualStudioPaths . map ( async ( vsPath ) => {
2427 if ( await fs . pathExists ( vsPath ) ) {
25- const versions = await fs . readdir ( vsPath ) ;
28+ const versions = await fs . readdir ( vsPath , { withFileTypes : true } ) ;
2629 return versions
30+ . filter ( ( dirent ) => dirent . isDirectory ( ) )
31+ . map ( ( dirent ) => dirent . name )
2732 . sort ( ( a , b ) => {
2833 const aNumber = parseInt ( a ) ;
2934 const bNumber = parseInt ( b ) ;
@@ -44,31 +49,40 @@ export async function getWindowsVisualStudioEditionPaths() {
4449 } )
4550 ) ) . flat ( ) ;
4651
47- const editionPaths = ( await Promise . all (
52+ const vsEditionPaths = ( await Promise . all (
4853 versionPaths . map ( async ( versionPath ) => {
49- const editions = await fs . readdir ( versionPath ) ;
50- return editions . map ( ( edition ) => path . join ( versionPath , edition ) ) ;
54+ const editions = await fs . readdir ( versionPath , { withFileTypes : true } ) ;
55+ return editions
56+ . filter ( ( dirent ) => dirent . isDirectory ( ) )
57+ . map ( ( edition ) => path . join ( versionPath , edition . name ) ) ;
5158 } )
5259 ) ) . flat ( ) ;
5360
54- return editionPaths ;
61+ return {
62+ vsEditionPaths,
63+ programFilesPaths
64+ } ;
5565}
5666
5767export async function detectWindowsBuildTools ( targetArch : typeof process . arch = process . arch ) {
5868 try {
5969 const currentArch = process . arch ;
60- const editionPaths = await getWindowsVisualStudioEditionPaths ( ) ;
70+ const { vsEditionPaths , programFilesPaths } = await getWindowsVisualStudioEditionPaths ( ) ;
6171
62- if ( editionPaths . length === 0 )
72+ if ( vsEditionPaths . length === 0 && programFilesPaths . length === 0 )
6373 return {
6474 hasCmake : false ,
6575 hasNinja : false ,
6676 hasLlvm : false ,
6777 hasLibExe : false
6878 } ;
6979
80+ const programDataPaths : string [ ] = [
81+ process . env [ "ProgramData" ]
82+ ] . filter ( ( programDataPath ) => programDataPath != null ) ;
83+
7084 const msvcPaths = ( await Promise . all (
71- editionPaths . map ( async ( editionPath ) => {
85+ vsEditionPaths . map ( async ( editionPath ) => {
7286 const msvcVersionsPath = path . join ( editionPath , "VC" , "Tools" , "MSVC" ) ;
7387
7488 if ( await fs . pathExists ( msvcVersionsPath ) ) {
@@ -94,20 +108,29 @@ export async function detectWindowsBuildTools(targetArch: typeof process.arch =
94108 } )
95109 ) ) . flat ( ) ;
96110
97- const potentialCmakePaths = editionPaths . map ( ( editionPath ) => (
98- path . join ( editionPath , "Common7" , "IDE" , "CommonExtensions" , "Microsoft" , "CMake" , "CMake" , "bin" , "cmake.exe" )
99- ) ) ;
100- const potentialNinjaPaths = editionPaths . map ( ( editionPath ) => (
101- path . join ( editionPath , "Common7" , "IDE" , "CommonExtensions" , "Microsoft" , "CMake" , "Ninja" , "ninja.exe" )
102- ) ) ;
103- const potentialLlvmPaths = editionPaths . map ( ( editionPath ) => {
104- if ( currentArch === "x64" )
105- return path . join ( editionPath , "VC" , "Tools" , "Llvm" , "x64" , "bin" ) ;
106- else if ( currentArch === "arm64" )
107- return path . join ( editionPath , "VC" , "Tools" , "Llvm" , "ARM64" , "bin" ) ;
108-
109- return path . join ( editionPath , "VC" , "Tools" , "Llvm" , "bin" ) ;
110- } ) ;
111+ const potentialCmakePaths = [
112+ ...programFilesPaths . map ( ( programFilesPath ) => path . join ( programFilesPath , "CMake" , "bin" , "cmake.exe" ) ) ,
113+ ...vsEditionPaths . map ( ( editionPath ) => (
114+ path . join ( editionPath , "Common7" , "IDE" , "CommonExtensions" , "Microsoft" , "CMake" , "CMake" , "bin" , "cmake.exe" )
115+ ) )
116+ ] ;
117+ const potentialNinjaPaths = [
118+ ...programDataPaths . map ( ( programDataPath ) => path . join ( programDataPath , "chocolatey" , "bin" , "ninja.exe" ) ) ,
119+ ...vsEditionPaths . map ( ( editionPath ) => (
120+ path . join ( editionPath , "Common7" , "IDE" , "CommonExtensions" , "Microsoft" , "CMake" , "Ninja" , "ninja.exe" )
121+ ) )
122+ ] ;
123+ const potentialLlvmPaths = [
124+ ...programFilesPaths . map ( ( programFilesPath ) => path . join ( programFilesPath , "LLVM" , "bin" ) ) ,
125+ ...vsEditionPaths . map ( ( editionPath ) => {
126+ if ( currentArch === "x64" )
127+ return path . join ( editionPath , "VC" , "Tools" , "Llvm" , "x64" , "bin" ) ;
128+ else if ( currentArch === "arm64" )
129+ return path . join ( editionPath , "VC" , "Tools" , "Llvm" , "ARM64" , "bin" ) ;
130+
131+ return path . join ( editionPath , "VC" , "Tools" , "Llvm" , "bin" ) ;
132+ } )
133+ ] ;
111134 const potentialLibExePaths = msvcPaths . map ( ( msvcPath ) => {
112135 const hostArchDirName = currentArch === "x64"
113136 ? "Hostx64"
0 commit comments