Skip to content

Commit 9031ac6

Browse files
committed
Add allowPlugins on commandline which is needed to resolve watchFactory
1 parent 774b5d2 commit 9031ac6

File tree

56 files changed

+1487
-170
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+1487
-170
lines changed

src/compiler/commandLineParser.ts

+52-5
Original file line numberDiff line numberDiff line change
@@ -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);

src/compiler/diagnosticMessages.json

+8
Original file line numberDiff line numberDiff line change
@@ -4337,6 +4337,10 @@
43374337
"category": "Error",
43384338
"code": 5109
43394339
},
4340+
"Option 'watchFactory' cannot be specified without passing '--allowPlugins' on command line.": {
4341+
"category": "Error",
4342+
"code": 5110
4343+
},
43404344

43414345
"Generates a sourcemap for each corresponding '.d.ts' file.": {
43424346
"category": "Message",
@@ -6107,6 +6111,10 @@
61076111
"category": "Message",
61086112
"code": 6804
61096113
},
6114+
"Allow running plugins.": {
6115+
"category": "Message",
6116+
"code": 6805
6117+
},
61106118

61116119
"one of:": {
61126120
"category": "Message",

src/compiler/tsbuildPublic.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,7 @@ export interface BuildOptions {
161161
/** @internal */ locale?: string;
162162
/** @internal */ generateCpuProfile?: string;
163163
/** @internal */ generateTrace?: string;
164+
/** @internal */ allowPlugins?: boolean;
164165

165166
[option: string]: CompilerOptionsValue | undefined;
166167
}
@@ -567,7 +568,7 @@ function parseConfigFile<T extends BuilderProgram>(state: SolutionBuilderState<T
567568
}
568569
else {
569570
parseConfigFileHost.onUnRecoverableConfigFileDiagnostic = d => diagnostic = d;
570-
parsed = getParsedCommandLineOfConfigFile(configFileName, baseCompilerOptions, parseConfigFileHost, extendedConfigCache, baseWatchOptions);
571+
parsed = getParsedCommandLineOfConfigFile(configFileName, baseCompilerOptions, parseConfigFileHost, extendedConfigCache, baseWatchOptions, /*extraFileExtensions*/ undefined, state.hostWithWatch.checkAllowPlugins);
571572
parseConfigFileHost.onUnRecoverableConfigFileDiagnostic = noop;
572573
}
573574
configFileCache.set(configFilePath, parsed || diagnostic!);

src/compiler/types.ts

+1
Original file line numberDiff line numberDiff line change
@@ -7158,6 +7158,7 @@ export interface CompilerOptions {
71587158
*/
71597159
pathsBasePath?: string;
71607160
/** @internal */ plugins?: PluginImport[];
7161+
/** @internal */ allowPlugins?: boolean;
71617162
preserveConstEnums?: boolean;
71627163
noImplicitOverride?: boolean;
71637164
preserveSymlinks?: boolean;

src/compiler/watch.ts

+10-2
Original file line numberDiff line numberDiff line change
@@ -213,10 +213,18 @@ export function createWatchStatusReporter(system: System, pretty?: boolean): Wat
213213
*
214214
* @internal
215215
*/
216-
export function parseConfigFileWithSystem(configFileName: string, optionsToExtend: CompilerOptions, extendedConfigCache: Map<string, ExtendedConfigCacheEntry> | undefined, watchOptionsToExtend: WatchOptions | undefined, system: System, reportDiagnostic: DiagnosticReporter): ParsedCommandLine | undefined {
216+
export function parseConfigFileWithSystem(
217+
configFileName: string,
218+
optionsToExtend: CompilerOptions,
219+
extendedConfigCache: Map<string, ExtendedConfigCacheEntry> | undefined,
220+
watchOptionsToExtend: WatchOptions | undefined,
221+
system: System,
222+
reportDiagnostic: DiagnosticReporter,
223+
checkAllowPlugins: boolean,
224+
): ParsedCommandLine | undefined {
217225
const host: ParseConfigFileHost = system as any;
218226
host.onUnRecoverableConfigFileDiagnostic = diagnostic => reportUnrecoverableDiagnostic(system, reportDiagnostic, diagnostic);
219-
const result = getParsedCommandLineOfConfigFile(configFileName, optionsToExtend, host, extendedConfigCache, watchOptionsToExtend);
227+
const result = getParsedCommandLineOfConfigFile(configFileName, optionsToExtend, host, extendedConfigCache, watchOptionsToExtend, /*extraFileExtensions*/ undefined, checkAllowPlugins);
220228
host.onUnRecoverableConfigFileDiagnostic = undefined!; // TODO: GH#18217
221229
return result;
222230
}

src/compiler/watchPublic.ts

+6-2
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,7 @@ export interface WatchHost {
161161
setTimeout?(callback: (...args: any[]) => void, ms: number, ...args: any[]): any;
162162
/** If provided, will be used to reset existing delayed compilation */
163163
clearTimeout?(timeoutId: any): void;
164+
/** @internal */ checkAllowPlugins?: boolean;
164165
}
165166
export interface ProgramHost<T extends BuilderProgram> {
166167
/**
@@ -902,7 +903,8 @@ export function createWatchProgram<T extends BuilderProgram>(host: WatchCompiler
902903
parseConfigFileHost,
903904
extendedConfigCache ||= new Map(),
904905
watchOptionsToExtend,
905-
extraFileExtensions
906+
extraFileExtensions,
907+
host.checkAllowPlugins,
906908
)!); // TODO: GH#18217
907909
}
908910

@@ -962,7 +964,9 @@ export function createWatchProgram<T extends BuilderProgram>(host: WatchCompiler
962964
/*optionsToExtend*/ undefined,
963965
parseConfigFileHost,
964966
extendedConfigCache ||= new Map(),
965-
watchOptionsToExtend
967+
watchOptionsToExtend,
968+
host.extraFileExtensions,
969+
host.checkAllowPlugins,
966970
);
967971
parseConfigFileHost.onUnRecoverableConfigFileDiagnostic = onUnRecoverableConfigFileDiagnostic;
968972
return parsedCommandLine;

src/executeCommandLine/executeCommandLine.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -645,7 +645,7 @@ function executeCommandLineWorker(
645645
);
646646
if (configFileName) {
647647
const extendedConfigCache = new Map<string, ExtendedConfigCacheEntry>();
648-
const configParseResult = parseConfigFileWithSystem(configFileName, commandLineOptions, extendedConfigCache, commandLine.watchOptions, sys, reportDiagnostic)!; // TODO: GH#18217
648+
const configParseResult = parseConfigFileWithSystem(configFileName, commandLineOptions, extendedConfigCache, commandLine.watchOptions, sys, reportDiagnostic, /*checkAllowPlugins*/ true)!; // TODO: GH#18217
649649
if (commandLineOptions.showConfig) {
650650
if (configParseResult.errors.length !== 0) {
651651
reportDiagnostic = updateReportDiagnostic(
@@ -847,6 +847,7 @@ function performBuild(
847847
);
848848
const solutionPerformance = enableSolutionPerformance(sys, buildOptions);
849849
updateSolutionBuilderHost(sys, cb, buildHost, solutionPerformance);
850+
buildHost.checkAllowPlugins = true;
850851
const onWatchStatusChange = buildHost.onWatchStatusChange;
851852
let reportBuildStatistics = false;
852853
buildHost.onWatchStatusChange = (d, newLine, options, errorCount) => {
@@ -979,6 +980,7 @@ function updateWatchCompilationHost(
979980
cb: ExecuteCommandLineCallbacks,
980981
watchCompilerHost: WatchCompilerHost<EmitAndSemanticDiagnosticsBuilderProgram>,
981982
) {
983+
watchCompilerHost.checkAllowPlugins = true;
982984
updateCreateProgram(sys, watchCompilerHost, /*isBuildMode*/ false);
983985
const emitFilesUsingBuilder = watchCompilerHost.afterProgramCreate!; // TODO: GH#18217
984986
watchCompilerHost.afterProgramCreate = builderProgram => {

src/testRunner/unittests/reuseProgramStructure.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -586,7 +586,7 @@ describe("unittests:: Reuse program structure:: isProgramUptoDate", () => {
586586
configFileName,
587587
system
588588
})).getCurrentProgram().getProgram();
589-
const { fileNames, options } = ts.parseConfigFileWithSystem(configFileName, {}, /*extendedConfigCache*/ undefined, /*watchOptionsToExtend*/ undefined, system, ts.notImplemented)!; // TODO: GH#18217
589+
const { fileNames, options } = ts.parseConfigFileWithSystem(configFileName, {}, /*extendedConfigCache*/ undefined, /*watchOptionsToExtend*/ undefined, system, ts.notImplemented, /*checkAllowPlugins*/ true)!; // TODO: GH#18217
590590
verifyProgramIsUptoDate(program, fileNames, options);
591591
}
592592

src/testRunner/unittests/tsbuild/outputPaths.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ describe("unittests:: tsbuild - output file paths", () => {
3232

3333
assert.deepEqual(
3434
ts.getOutputFileNames(
35-
ts.parseConfigFileWithSystem("/src/tsconfig.json", {}, /*extendedConfigCache*/ undefined, {}, sys, ts.noop)!,
35+
ts.parseConfigFileWithSystem("/src/tsconfig.json", {}, /*extendedConfigCache*/ undefined, {}, sys, ts.noop, /*checkAllowPlugins*/ true)!,
3636
"/src/src/index.ts",
3737
/*ignoreCase*/ false
3838
),

0 commit comments

Comments
 (0)