1- import { resolvePath , getDirectoryPath , ResolveCompilerOptionsOptions , formatDiagnostic } from "@typespec/compiler" ;
2- import { ModuleResolutionResult , resolveModule , ResolveModuleHost } from "@typespec/compiler/module-resolver" ;
1+ import {
2+ resolvePath ,
3+ getDirectoryPath ,
4+ ResolveCompilerOptionsOptions ,
5+ formatDiagnostic ,
6+ } from "@typespec/compiler" ;
7+ import {
8+ ModuleResolutionResult ,
9+ resolveModule ,
10+ ResolveModuleHost ,
11+ } from "@typespec/compiler/module-resolver" ;
312import { Logger } from "./log.js" ;
413import { readFile , readdir , realpath , stat } from "fs/promises" ;
514import { pathToFileURL } from "url" ;
@@ -19,7 +28,9 @@ export function resolveTspConfigUrl(configUrl: string): {
1928} {
2029 let resolvedConfigUrl = configUrl ;
2130
22- const res = configUrl . match ( '^https://(?<urlRoot>github|raw.githubusercontent).com/(?<repo>[^/]*/azure-rest-api-specs(-pr)?)/(tree/|blob/)?(?<commit>[0-9a-f]{40})/(?<path>.*)/tspconfig.yaml$' )
31+ const res = configUrl . match (
32+ "^https://(?<urlRoot>github|raw.githubusercontent).com/(?<repo>[^/]*/azure-rest-api-specs(-pr)?)/(tree/|blob/)?(?<commit>[0-9a-f]{40})/(?<path>.*)/tspconfig.yaml$" ,
33+ ) ;
2334 if ( res && res . groups ) {
2435 if ( res . groups [ "urlRoot" ] ! === "github" ) {
2536 resolvedConfigUrl = configUrl . replace ( "github.com" , "raw.githubusercontent.com" ) ;
@@ -30,24 +41,23 @@ export function resolveTspConfigUrl(configUrl: string): {
3041 commit : res . groups ! [ "commit" ] ! ,
3142 repo : res . groups ! [ "repo" ] ! ,
3243 path : res . groups ! [ "path" ] ! ,
33- }
44+ } ;
3445 } else {
3546 throw new Error ( `Invalid tspconfig.yaml url: ${ configUrl } ` ) ;
3647 }
3748}
3849
39-
4050export async function discoverMainFile ( srcDir : string ) : Promise < string > {
41- Logger . debug ( `Discovering entry file in ${ srcDir } ` )
51+ Logger . debug ( `Discovering entry file in ${ srcDir } ` ) ;
4252 let entryTsp = "" ;
43- const files = await readdir ( srcDir , { recursive : true } ) ;
53+ const files = await readdir ( srcDir , { recursive : true } ) ;
4454 for ( const file of files ) {
4555 if ( file . includes ( "client.tsp" ) || file . includes ( "main.tsp" ) ) {
4656 entryTsp = file ;
4757 Logger . debug ( `Found entry file: ${ entryTsp } ` ) ;
4858 return entryTsp ;
4959 }
50- } ;
60+ }
5161 throw new Error ( `No main.tsp or client.tsp found` ) ;
5262}
5363
@@ -73,7 +83,7 @@ export async function compileTsp({
7383 "emitter-output-dir" : outputDir ,
7484 } ,
7585 } ;
76- const emitterOverrideOptions = overrideOptions [ emitterPackage ] ?? { [ emitterPackage ] : { } } ;
86+ const emitterOverrideOptions = overrideOptions [ emitterPackage ] ?? { [ emitterPackage ] : { } } ;
7787 if ( saveInputs ) {
7888 emitterOverrideOptions [ "save-inputs" ] = "true" ;
7989 }
@@ -98,21 +108,44 @@ export async function compileTsp({
98108 } ) ;
99109 Logger . debug ( `Compiler options: ${ JSON . stringify ( options ) } ` ) ;
100110 if ( diagnostics . length > 0 ) {
111+ let errorDiagnostic = false ;
101112 // This should not happen, but if it does, we should log it.
102- Logger . error ( "Diagnostics were reported while resolving compiler options. Use the `--debug` flag to see the diagnostic output." )
103- diagnostics . forEach ( ( diagnostic ) => { Logger . debug ( formatDiagnostic ( diagnostic ) ) ; } ) ;
104- return false ;
113+ Logger . warn (
114+ "Diagnostics were reported while resolving compiler options. Use the `--debug` flag to see if there is warning diagnostic output." ,
115+ ) ;
116+ for ( const diagnostic of diagnostics ) {
117+ if ( diagnostic . severity === "error" ) {
118+ Logger . error ( formatDiagnostic ( diagnostic ) ) ;
119+ errorDiagnostic = true ;
120+ } else {
121+ Logger . debug ( formatDiagnostic ( diagnostic ) ) ;
122+ }
123+ }
124+ if ( errorDiagnostic ) {
125+ return false ;
126+ }
105127 }
106128
107129 const program = await compile ( NodeHost , resolvedMainFilePath , options ) ;
108130
109131 if ( program . diagnostics . length > 0 ) {
110- Logger . error ( "Diagnostics were reported during compilation. Use the `--debug` flag to see the diagnostic output." ) ;
111- program . diagnostics . forEach ( ( diagnostic ) => { Logger . debug ( formatDiagnostic ( diagnostic ) ) ; } ) ;
112- return false ;
113- } else {
114- Logger . success ( "generation complete" ) ;
132+ let errorDiagnostic = false ;
133+ Logger . warn (
134+ "Diagnostics were reported during compilation. Use the `--debug` flag to see if there is warning diagnostic output." ,
135+ ) ;
136+ for ( const diagnostic of program . diagnostics ) {
137+ if ( diagnostic . severity === "error" ) {
138+ Logger . error ( formatDiagnostic ( diagnostic ) ) ;
139+ errorDiagnostic = true ;
140+ } else {
141+ Logger . debug ( formatDiagnostic ( diagnostic ) ) ;
142+ }
143+ }
144+ if ( errorDiagnostic ) {
145+ return false ;
146+ }
115147 }
148+ Logger . success ( "generation complete" ) ;
116149 return true ;
117150}
118151
0 commit comments