@@ -62,9 +62,11 @@ import {
6262 getSupportedExtensions ,
6363 getSupportedExtensionsWithJsonIfResolveJsonModule ,
6464 getTextOfPropertyName ,
65+ getTsConfigObjectLiteralExpression ,
6566 getTsConfigPropArrayElementValue ,
6667 hasExtension ,
6768 hasProperty ,
69+ identity ,
6870 ImportsNotUsedAsValues ,
6971 isArray ,
7072 isArrayLiteralExpression ,
@@ -527,6 +529,14 @@ export const commonOptionsWithBuild: CommandLineOption[] = [
527529 description : Diagnostics . Set_the_language_of_the_messaging_from_TypeScript_This_does_not_affect_emit ,
528530 defaultValueDescription : Diagnostics . Platform_specific
529531 } ,
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+ } ,
530540] ;
531541
532542/** @internal */
@@ -1821,6 +1831,10 @@ export function parseCommandLineWorker(
18211831 const errors : Diagnostic [ ] = [ ] ;
18221832
18231833 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+ }
18241838 return {
18251839 options,
18261840 watchOptions,
@@ -2098,6 +2112,7 @@ export function getParsedCommandLineOfConfigFile(
20982112 extendedConfigCache ?: Map < string , ExtendedConfigCacheEntry > ,
20992113 watchOptionsToExtend ?: WatchOptions ,
21002114 extraFileExtensions ?: readonly FileExtensionInfo [ ] ,
2115+ checkAllowPlugins ?: boolean ,
21012116) : ParsedCommandLine | undefined {
21022117 const configFileText = tryReadFile ( configFileName , fileName => host . readFile ( fileName ) ) ;
21032118 if ( ! isString ( configFileText ) ) {
@@ -2119,7 +2134,8 @@ export function getParsedCommandLineOfConfigFile(
21192134 /*resolutionStack*/ undefined ,
21202135 extraFileExtensions ,
21212136 extendedConfigCache ,
2122- watchOptionsToExtend
2137+ watchOptionsToExtend ,
2138+ checkAllowPlugins ,
21232139 ) ;
21242140}
21252141
@@ -2854,9 +2870,20 @@ export function parseJsonConfigFileContent(json: any, host: ParseConfigHost, bas
28542870 * @param basePath A root directory to resolve relative path entries in the config
28552871 * file to. e.g. outDir
28562872 */
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 {
28582885 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 ) ;
28602887 tracing ?. pop ( ) ;
28612888 return result ;
28622889}
@@ -2900,7 +2927,8 @@ function parseJsonConfigFileContentWorker(
29002927 configFileName ?: string ,
29012928 resolutionStack : Path [ ] = [ ] ,
29022929 extraFileExtensions : readonly FileExtensionInfo [ ] = [ ] ,
2903- extendedConfigCache ?: Map < string , ExtendedConfigCacheEntry >
2930+ extendedConfigCache ?: Map < string , ExtendedConfigCacheEntry > ,
2931+ checkAllowPlugins ?: boolean ,
29042932) : ParsedCommandLine {
29052933 Debug . assert ( ( json === undefined && sourceFile !== undefined ) || ( json !== undefined && sourceFile === undefined ) ) ;
29062934 const errors : Diagnostic [ ] = [ ] ;
@@ -2912,6 +2940,21 @@ function parseJsonConfigFileContentWorker(
29122940 extend ( existingWatchOptions || { } , parsedConfig . watchOptions || { } ) :
29132941 undefined ;
29142942
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+
29152958 options . configFilePath = configFileName && normalizeSlashes ( configFileName ) ;
29162959 const configFileSpecs = getConfigFileSpecs ( ) ;
29172960 if ( sourceFile ) sourceFile . configFileSpecs = configFileSpecs ;
@@ -3535,7 +3578,11 @@ export function convertJsonOption(
35353578 convertJsonOptionOfListType ( opt , value , basePath , errors , propertyAssignment , valueExpression as ArrayLiteralExpression | undefined , sourceFile ) :
35363579 convertJsonOption ( opt . element , value , basePath , errors , propertyAssignment , valueExpression , sourceFile ) ;
35373580 }
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 ) ) {
35393586 return convertJsonOptionOfCustomType ( opt as CommandLineOptionOfCustomType , value as string , errors , valueExpression , sourceFile ) ;
35403587 }
35413588 const validatedValue = validateJsonOptionValue ( opt , value , errors , valueExpression , sourceFile ) ;
0 commit comments