@@ -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 */
@@ -1821,6 +1831,10 @@ export function parseCommandLineWorker(
1821
1831
const errors : Diagnostic [ ] = [ ] ;
1822
1832
1823
1833
parseStrings ( commandLine ) ;
1834
+ if ( options . watch && watchOptions ?. watchFactory && ! options . allowPlugins ) {
1835
+ errors . push ( createCompilerDiagnostic ( Diagnostics . Option_watchFactory_cannot_be_specified_without_passing_allowPlugins_on_command_line ) ) ;
1836
+ watchOptions . watchFactory = undefined ;
1837
+ }
1824
1838
return {
1825
1839
options,
1826
1840
watchOptions,
@@ -2098,6 +2112,7 @@ export function getParsedCommandLineOfConfigFile(
2098
2112
extendedConfigCache ?: Map < string , ExtendedConfigCacheEntry > ,
2099
2113
watchOptionsToExtend ?: WatchOptions ,
2100
2114
extraFileExtensions ?: readonly FileExtensionInfo [ ] ,
2115
+ checkAllowPlugins ?: boolean ,
2101
2116
) : ParsedCommandLine | undefined {
2102
2117
const configFileText = tryReadFile ( configFileName , fileName => host . readFile ( fileName ) ) ;
2103
2118
if ( ! isString ( configFileText ) ) {
@@ -2119,7 +2134,8 @@ export function getParsedCommandLineOfConfigFile(
2119
2134
/*resolutionStack*/ undefined ,
2120
2135
extraFileExtensions ,
2121
2136
extendedConfigCache ,
2122
- watchOptionsToExtend
2137
+ watchOptionsToExtend ,
2138
+ checkAllowPlugins ,
2123
2139
) ;
2124
2140
}
2125
2141
@@ -2854,9 +2870,20 @@ export function parseJsonConfigFileContent(json: any, host: ParseConfigHost, bas
2854
2870
* @param basePath A root directory to resolve relative path entries in the config
2855
2871
* file to. e.g. outDir
2856
2872
*/
2857
- 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 {
2873
+ export function parseJsonSourceFileConfigFileContent (
2874
+ sourceFile : TsConfigSourceFile ,
2875
+ host : ParseConfigHost ,
2876
+ basePath : string ,
2877
+ existingOptions ?: CompilerOptions ,
2878
+ configFileName ?: string ,
2879
+ resolutionStack ?: Path [ ] ,
2880
+ extraFileExtensions ?: readonly FileExtensionInfo [ ] ,
2881
+ extendedConfigCache ?: Map < string , ExtendedConfigCacheEntry > ,
2882
+ existingWatchOptions ?: WatchOptions ,
2883
+ checkAllowPlugins ?: boolean ,
2884
+ ) : ParsedCommandLine {
2858
2885
tracing ?. push ( tracing . Phase . Parse , "parseJsonSourceFileConfigFileContent" , { path : sourceFile . fileName } ) ;
2859
- const result = parseJsonConfigFileContentWorker ( /*json*/ undefined , sourceFile , host , basePath , existingOptions , existingWatchOptions , configFileName , resolutionStack , extraFileExtensions , extendedConfigCache ) ;
2886
+ const result = parseJsonConfigFileContentWorker ( /*json*/ undefined , sourceFile , host , basePath , existingOptions , existingWatchOptions , configFileName , resolutionStack , extraFileExtensions , extendedConfigCache , checkAllowPlugins ) ;
2860
2887
tracing ?. pop ( ) ;
2861
2888
return result ;
2862
2889
}
@@ -2900,7 +2927,8 @@ function parseJsonConfigFileContentWorker(
2900
2927
configFileName ?: string ,
2901
2928
resolutionStack : Path [ ] = [ ] ,
2902
2929
extraFileExtensions : readonly FileExtensionInfo [ ] = [ ] ,
2903
- extendedConfigCache ?: Map < string , ExtendedConfigCacheEntry >
2930
+ extendedConfigCache ?: Map < string , ExtendedConfigCacheEntry > ,
2931
+ checkAllowPlugins ?: boolean ,
2904
2932
) : ParsedCommandLine {
2905
2933
Debug . assert ( ( json === undefined && sourceFile !== undefined ) || ( json !== undefined && sourceFile === undefined ) ) ;
2906
2934
const errors : Diagnostic [ ] = [ ] ;
@@ -2912,6 +2940,21 @@ function parseJsonConfigFileContentWorker(
2912
2940
extend ( existingWatchOptions || { } , parsedConfig . watchOptions || { } ) :
2913
2941
undefined ;
2914
2942
2943
+ if ( options . watch && watchOptions ?. watchFactory && checkAllowPlugins && ! options . allowPlugins ) {
2944
+ const watchFactoryNameProp = forEachPropertyAssignment (
2945
+ getTsConfigObjectLiteralExpression ( sourceFile ) ,
2946
+ "watchOptions" ,
2947
+ prop => isObjectLiteralExpression ( prop . initializer ) ?
2948
+ forEachPropertyAssignment ( prop . initializer , "watchFactory" , watchFactoryProp => isObjectLiteralExpression ( watchFactoryProp . initializer ) ?
2949
+ forEachPropertyAssignment ( watchFactoryProp . initializer , "name" , identity ) || watchFactoryProp :
2950
+ watchFactoryProp
2951
+ ) :
2952
+ undefined
2953
+ ) ;
2954
+ errors . push ( createDiagnosticForNodeInSourceFileOrCompilerDiagnostic ( sourceFile , watchFactoryNameProp ?. name , Diagnostics . Option_watchFactory_cannot_be_specified_without_passing_allowPlugins_on_command_line ) ) ;
2955
+ watchOptions . watchFactory = undefined ;
2956
+ }
2957
+
2915
2958
options . configFilePath = configFileName && normalizeSlashes ( configFileName ) ;
2916
2959
const configFileSpecs = getConfigFileSpecs ( ) ;
2917
2960
if ( sourceFile ) sourceFile . configFileSpecs = configFileSpecs ;
@@ -3535,7 +3578,11 @@ export function convertJsonOption(
3535
3578
convertJsonOptionOfListType ( opt , value , basePath , errors , propertyAssignment , valueExpression as ArrayLiteralExpression | undefined , sourceFile ) :
3536
3579
convertJsonOption ( opt . element , value , basePath , errors , propertyAssignment , valueExpression , sourceFile ) ;
3537
3580
}
3538
- else if ( ! isString ( opt . type ) ) {
3581
+ if ( opt . isCommandLineOnly ) {
3582
+ errors . push ( createDiagnosticForNodeInSourceFileOrCompilerDiagnostic ( sourceFile , valueExpression , Diagnostics . Option_0_can_only_be_specified_on_command_line , opt . name ) ) ;
3583
+ return ;
3584
+ }
3585
+ if ( ! isString ( opt . type ) ) {
3539
3586
return convertJsonOptionOfCustomType ( opt as CommandLineOptionOfCustomType , value as string , errors , valueExpression , sourceFile ) ;
3540
3587
}
3541
3588
const validatedValue = validateJsonOptionValue ( opt , value , errors , valueExpression , sourceFile ) ;
0 commit comments