@@ -62,9 +62,11 @@ import {
62
62
getSupportedExtensions ,
63
63
getSupportedExtensionsWithJsonIfResolveJsonModule ,
64
64
getTextOfPropertyName ,
65
+ getTsConfigObjectLiteralExpression ,
65
66
getTsConfigPropArrayElementValue ,
66
67
hasExtension ,
67
68
hasProperty ,
69
+ identity ,
68
70
ImportsNotUsedAsValues ,
69
71
isArray ,
70
72
isArrayLiteralExpression ,
@@ -527,6 +529,14 @@ export const commonOptionsWithBuild: CommandLineOption[] = [
527
529
description : Diagnostics . Set_the_language_of_the_messaging_from_TypeScript_This_does_not_affect_emit ,
528
530
defaultValueDescription : Diagnostics . Platform_specific
529
531
} ,
532
+ {
533
+ name : "allowPlugins" ,
534
+ type : "boolean" ,
535
+ category : Diagnostics . Command_line_Options ,
536
+ isCommandLineOnly : true ,
537
+ description : Diagnostics . Allow_running_plugins ,
538
+ defaultValueDescription : false ,
539
+ } ,
530
540
] ;
531
541
532
542
/** @internal */
@@ -1819,6 +1829,10 @@ export function parseCommandLineWorker(
1819
1829
const errors : Diagnostic [ ] = [ ] ;
1820
1830
1821
1831
parseStrings ( commandLine ) ;
1832
+ if ( options . watch && watchOptions ?. watchFactory && ! options . allowPlugins ) {
1833
+ errors . push ( createCompilerDiagnostic ( Diagnostics . Option_watchFactory_cannot_be_specified_without_passing_allowPlugins_on_command_line ) ) ;
1834
+ watchOptions . watchFactory = undefined ;
1835
+ }
1822
1836
return {
1823
1837
options,
1824
1838
watchOptions,
@@ -2096,6 +2110,7 @@ export function getParsedCommandLineOfConfigFile(
2096
2110
extendedConfigCache ?: Map < string , ExtendedConfigCacheEntry > ,
2097
2111
watchOptionsToExtend ?: WatchOptions ,
2098
2112
extraFileExtensions ?: readonly FileExtensionInfo [ ] ,
2113
+ checkAllowPlugins ?: boolean ,
2099
2114
) : ParsedCommandLine | undefined {
2100
2115
const configFileText = tryReadFile ( configFileName , fileName => host . readFile ( fileName ) ) ;
2101
2116
if ( ! isString ( configFileText ) ) {
@@ -2117,7 +2132,8 @@ export function getParsedCommandLineOfConfigFile(
2117
2132
/*resolutionStack*/ undefined ,
2118
2133
extraFileExtensions ,
2119
2134
extendedConfigCache ,
2120
- watchOptionsToExtend
2135
+ watchOptionsToExtend ,
2136
+ checkAllowPlugins ,
2121
2137
) ;
2122
2138
}
2123
2139
@@ -2852,9 +2868,20 @@ export function parseJsonConfigFileContent(json: any, host: ParseConfigHost, bas
2852
2868
* @param basePath A root directory to resolve relative path entries in the config
2853
2869
* file to. e.g. outDir
2854
2870
*/
2855
- export function parseJsonSourceFileConfigFileContent ( sourceFile : TsConfigSourceFile , host : ParseConfigHost , basePath : string , existingOptions ?: CompilerOptions , configFileName ?: string , resolutionStack ?: Path [ ] , extraFileExtensions ?: readonly FileExtensionInfo [ ] , extendedConfigCache ?: Map < string , ExtendedConfigCacheEntry > , existingWatchOptions ?: WatchOptions ) : ParsedCommandLine {
2871
+ export function parseJsonSourceFileConfigFileContent (
2872
+ sourceFile : TsConfigSourceFile ,
2873
+ host : ParseConfigHost ,
2874
+ basePath : string ,
2875
+ existingOptions ?: CompilerOptions ,
2876
+ configFileName ?: string ,
2877
+ resolutionStack ?: Path [ ] ,
2878
+ extraFileExtensions ?: readonly FileExtensionInfo [ ] ,
2879
+ extendedConfigCache ?: Map < string , ExtendedConfigCacheEntry > ,
2880
+ existingWatchOptions ?: WatchOptions ,
2881
+ checkAllowPlugins ?: boolean ,
2882
+ ) : ParsedCommandLine {
2856
2883
tracing ?. push ( tracing . Phase . Parse , "parseJsonSourceFileConfigFileContent" , { path : sourceFile . fileName } ) ;
2857
- const result = parseJsonConfigFileContentWorker ( /*json*/ undefined , sourceFile , host , basePath , existingOptions , existingWatchOptions , configFileName , resolutionStack , extraFileExtensions , extendedConfigCache ) ;
2884
+ const result = parseJsonConfigFileContentWorker ( /*json*/ undefined , sourceFile , host , basePath , existingOptions , existingWatchOptions , configFileName , resolutionStack , extraFileExtensions , extendedConfigCache , checkAllowPlugins ) ;
2858
2885
tracing ?. pop ( ) ;
2859
2886
return result ;
2860
2887
}
@@ -2898,7 +2925,8 @@ function parseJsonConfigFileContentWorker(
2898
2925
configFileName ?: string ,
2899
2926
resolutionStack : Path [ ] = [ ] ,
2900
2927
extraFileExtensions : readonly FileExtensionInfo [ ] = [ ] ,
2901
- extendedConfigCache ?: Map < string , ExtendedConfigCacheEntry >
2928
+ extendedConfigCache ?: Map < string , ExtendedConfigCacheEntry > ,
2929
+ checkAllowPlugins ?: boolean ,
2902
2930
) : ParsedCommandLine {
2903
2931
Debug . assert ( ( json === undefined && sourceFile !== undefined ) || ( json !== undefined && sourceFile === undefined ) ) ;
2904
2932
const errors : Diagnostic [ ] = [ ] ;
@@ -2910,6 +2938,21 @@ function parseJsonConfigFileContentWorker(
2910
2938
extend ( existingWatchOptions || { } , parsedConfig . watchOptions || { } ) :
2911
2939
undefined ;
2912
2940
2941
+ if ( options . watch && watchOptions ?. watchFactory && checkAllowPlugins && ! options . allowPlugins ) {
2942
+ const watchFactoryNameProp = forEachPropertyAssignment (
2943
+ getTsConfigObjectLiteralExpression ( sourceFile ) ,
2944
+ "watchOptions" ,
2945
+ prop => isObjectLiteralExpression ( prop . initializer ) ?
2946
+ forEachPropertyAssignment ( prop . initializer , "watchFactory" , watchFactoryProp => isObjectLiteralExpression ( watchFactoryProp . initializer ) ?
2947
+ forEachPropertyAssignment ( watchFactoryProp . initializer , "name" , identity ) || watchFactoryProp :
2948
+ watchFactoryProp
2949
+ ) :
2950
+ undefined
2951
+ ) ;
2952
+ errors . push ( createDiagnosticForNodeInSourceFileOrCompilerDiagnostic ( sourceFile , watchFactoryNameProp ?. name , Diagnostics . Option_watchFactory_cannot_be_specified_without_passing_allowPlugins_on_command_line ) ) ;
2953
+ watchOptions . watchFactory = undefined ;
2954
+ }
2955
+
2913
2956
options . configFilePath = configFileName && normalizeSlashes ( configFileName ) ;
2914
2957
const configFileSpecs = getConfigFileSpecs ( ) ;
2915
2958
if ( sourceFile ) sourceFile . configFileSpecs = configFileSpecs ;
@@ -3533,7 +3576,11 @@ export function convertJsonOption(
3533
3576
convertJsonOptionOfListType ( opt , value , basePath , errors , propertyAssignment , valueExpression as ArrayLiteralExpression | undefined , sourceFile ) :
3534
3577
convertJsonOption ( opt . element , value , basePath , errors , propertyAssignment , valueExpression , sourceFile ) ;
3535
3578
}
3536
- else if ( ! isString ( opt . type ) ) {
3579
+ if ( opt . isCommandLineOnly ) {
3580
+ errors . push ( createDiagnosticForNodeInSourceFileOrCompilerDiagnostic ( sourceFile , valueExpression , Diagnostics . Option_0_can_only_be_specified_on_command_line , opt . name ) ) ;
3581
+ return ;
3582
+ }
3583
+ if ( ! isString ( opt . type ) ) {
3537
3584
return convertJsonOptionOfCustomType ( opt as CommandLineOptionOfCustomType , value as string , errors , valueExpression , sourceFile ) ;
3538
3585
}
3539
3586
const validatedValue = validateJsonOptionValue ( opt , value , errors , valueExpression , sourceFile ) ;
0 commit comments