Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 39 additions & 2 deletions src/compiler/commandLineParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2949,8 +2949,45 @@ function convertToOptionValueWithAbsolutePaths(option: CommandLineOption | undef
* @param basePath A root directory to resolve relative path entries in the config
* file to. e.g. outDir
*/
export function parseJsonConfigFileContent(json: any, host: ParseConfigHost, basePath: string, existingOptions?: CompilerOptions, configFileName?: string, resolutionStack?: Path[], extraFileExtensions?: readonly FileExtensionInfo[], extendedConfigCache?: Map<string, ExtendedConfigCacheEntry>, existingWatchOptions?: WatchOptions): ParsedCommandLine {
return parseJsonConfigFileContentWorker(json, /*sourceFile*/ undefined, host, basePath, existingOptions, existingWatchOptions, configFileName, resolutionStack, extraFileExtensions, extendedConfigCache);
export function parseJsonConfigFileContent(
json: any,
host: ParseConfigHost,
basePath: string,
existingOptions?: CompilerOptions,
configFileName?: string,
resolutionStack?: Path[],
extraFileExtensions?: readonly FileExtensionInfo[],
extendedConfigCache?: Map<string, ExtendedConfigCacheEntry>,
existingWatchOptions?: WatchOptions,
): ParsedCommandLine {
const parsed = parseJsonConfigFileContentWorker(
json,
/*sourceFile*/ undefined,
host,
basePath,
existingOptions,
existingWatchOptions,
configFileName,
resolutionStack,
extraFileExtensions,
extendedConfigCache,
);

const { files, references, composite } = parsed.options;

// Detect ambiguous configurations
if (Array.isArray(files) && files.length === 0 && !references && !composite) {
parsed.errors.push(
createCompilerDiagnostic(
Diagnostics.No_actionable_task_Add_composite_Colon_true_valid_references_or_use_tsc_b,
),
);

// Default to build mode to prevent silent failure
parsed.options.build = true;
}

return parsed;
}

/**
Expand Down
4 changes: 4 additions & 0 deletions src/compiler/diagnosticMessages.json
Original file line number Diff line number Diff line change
Expand Up @@ -4828,6 +4828,10 @@
"category": "Message",
"code": 6041
},
"No actionable task. Add 'composite': true, valid 'references', or use 'tsc -b'.": {
"category": "Message",
"code": 6042
},
"Generates corresponding '.map' file.": {
"category": "Message",
"code": 6043
Expand Down
39 changes: 38 additions & 1 deletion src/compiler/program.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1412,6 +1412,25 @@ export function getImpliedNodeFormatForFile(fileName: string, packageJsonInfoCac
return typeof result === "object" ? result.impliedNodeFormat : result;
}

/**
* Determines if the provided compiler configuration is ambiguous.
*
* A configuration is considered ambiguous if:
* - `rootNames` is an empty array
* - `options.composite` is false
* - `projectReferences` is undefined or an empty array
* - `options.include` is undefined or an empty array
* - `options.files` is undefined or an empty array
*
* @param options - The compiler options to check.
* @param rootNames - The root file names for the program.
* @param projectReferences - The project references for the program.
* @returns `true` if the configuration is ambiguous, otherwise `false`.
*/
export function isAmbiguousConfiguration(options: CompilerOptions, rootNames: readonly string[], projectReferences: readonly ProjectReference[] | undefined): boolean {
return (rootNames.length === 0 && !options.composite && (!projectReferences || projectReferences.length === 0) && (!options.include || (Array.isArray(options.include) && options.include.length === 0)) && (!options.files || (Array.isArray(options.files) && options.files.length === 0)));
}

/** @internal */
export function getImpliedNodeFormatForFileWorker(
fileName: string,
Expand Down Expand Up @@ -1595,7 +1614,8 @@ export function createProgram(createProgramOptions: CreateProgramOptions): Progr
export function createProgram(rootNames: readonly string[], options: CompilerOptions, host?: CompilerHost, oldProgram?: Program, configFileParsingDiagnostics?: readonly Diagnostic[]): Program;
export function createProgram(rootNamesOrOptions: readonly string[] | CreateProgramOptions, _options?: CompilerOptions, _host?: CompilerHost, _oldProgram?: Program, _configFileParsingDiagnostics?: readonly Diagnostic[]): Program {
const createProgramOptions = isArray(rootNamesOrOptions) ? createCreateProgramOptions(rootNamesOrOptions, _options!, _host, _oldProgram, _configFileParsingDiagnostics) : rootNamesOrOptions; // TODO: GH#18217
const { rootNames, options, configFileParsingDiagnostics, projectReferences, typeScriptVersion } = createProgramOptions;
const { rootNames, options, projectReferences, typeScriptVersion } = createProgramOptions;
let configFileParsingDiagnostics = createProgramOptions.configFileParsingDiagnostics;
let { oldProgram } = createProgramOptions;
for (const option of commandLineOptionOfCustomType) {
if (hasProperty(options, option.name)) {
Expand All @@ -1605,6 +1625,23 @@ export function createProgram(rootNamesOrOptions: readonly string[] | CreateProg
}
}

// Validate ambiguous configurations
if (options.configFilePath) {
const configPath = options.configFilePath;
if (isAmbiguousConfiguration(options, rootNames, projectReferences)) {
// Ensure diagnostics array is initialized
if (!configFileParsingDiagnostics) {
configFileParsingDiagnostics = [];
}
(configFileParsingDiagnostics as Diagnostic[]).push(
createCompilerDiagnostic(
Diagnostics.No_actionable_task_Add_composite_Colon_true_valid_references_or_use_tsc_b,
configPath,
),
);
}
}

const reportInvalidIgnoreDeprecations = memoize(() => createOptionValueDiagnostic("ignoreDeprecations", Diagnostics.Invalid_value_for_ignoreDeprecations));

let processingDefaultLibFiles: SourceFile[] | undefined;
Expand Down
16 changes: 16 additions & 0 deletions tests/baselines/reference/api/typescript.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9553,6 +9553,22 @@ declare namespace ts {
* @returns `undefined` if the path has no relevant implied format, `ModuleKind.ESNext` for esm format, and `ModuleKind.CommonJS` for cjs format
*/
function getImpliedNodeFormatForFile(fileName: string, packageJsonInfoCache: PackageJsonInfoCache | undefined, host: ModuleResolutionHost, options: CompilerOptions): ResolutionMode;
/**
* Determines if the provided compiler configuration is ambiguous.
*
* A configuration is considered ambiguous if:
* - `rootNames` is an empty array
* - `options.composite` is false
* - `projectReferences` is undefined or an empty array
* - `options.include` is undefined or an empty array
* - `options.files` is undefined or an empty array
*
* @param options - The compiler options to check.
* @param rootNames - The root file names for the program.
* @param projectReferences - The project references for the program.
* @returns `true` if the configuration is ambiguous, otherwise `false`.
*/
function isAmbiguousConfiguration(options: CompilerOptions, rootNames: readonly string[], projectReferences: readonly ProjectReference[] | undefined): boolean;
/**
* Create a new 'Program' instance. A Program is an immutable collection of 'SourceFile's and a 'CompilerOptions'
* that represent a compilation unit.
Expand Down
15 changes: 15 additions & 0 deletions tests/baselines/reference/containerProjectNoEmit.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
//// [tests/cases/compiler/containerProjectNoEmit.ts] ////

//// [containerProjectNoEmit.ts]
export const tsconfig = {
"files": []
}


//// [containerProjectNoEmit.js]
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.tsconfig = void 0;
exports.tsconfig = {
"files": []
};
10 changes: 10 additions & 0 deletions tests/baselines/reference/containerProjectNoEmit.symbols
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
//// [tests/cases/compiler/containerProjectNoEmit.ts] ////

=== containerProjectNoEmit.ts ===
export const tsconfig = {
>tsconfig : Symbol(tsconfig, Decl(containerProjectNoEmit.ts, 0, 12))

"files": []
>"files" : Symbol("files", Decl(containerProjectNoEmit.ts, 0, 25))
}

16 changes: 16 additions & 0 deletions tests/baselines/reference/containerProjectNoEmit.types
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
//// [tests/cases/compiler/containerProjectNoEmit.ts] ////

=== containerProjectNoEmit.ts ===
export const tsconfig = {
>tsconfig : { files: any[]; }
> : ^^^^^^^^^^^^^^^^^
>{ "files": []} : { files: undefined[]; }
> : ^^^^^^^^^^^^^^^^^^^^^^^

"files": []
>"files" : undefined[]
> : ^^^^^^^^^^^
>[] : undefined[]
> : ^^^^^^^^^^^
}

Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,20 @@ interface Foo {
x: number;
}
export default Foo;


//// [DtsFileErrors]


message TS6042: No actionable task. Add 'composite': true, valid 'references', or use 'tsc -b'.


!!! message TS6042: No actionable task. Add 'composite': true, valid 'references', or use 'tsc -b'.
==== /foo/tsconfig.json (0 errors) ====
{
"compilerOptions": {
"declaration": true,
"declarationDir": "out"
}
}

14 changes: 14 additions & 0 deletions tests/baselines/reference/emptyFilesConfig.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
//// [tests/cases/compiler/emptyFilesConfig.ts] ////

//// [emptyFilesConfig.ts]
export const tsconfig = {
"files": []
}

//// [emptyFilesConfig.js]
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.tsconfig = void 0;
exports.tsconfig = {
"files": []
};
9 changes: 9 additions & 0 deletions tests/baselines/reference/emptyFilesConfig.symbols
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
//// [tests/cases/compiler/emptyFilesConfig.ts] ////

=== emptyFilesConfig.ts ===
export const tsconfig = {
>tsconfig : Symbol(tsconfig, Decl(emptyFilesConfig.ts, 0, 12))

"files": []
>"files" : Symbol("files", Decl(emptyFilesConfig.ts, 0, 25))
}
15 changes: 15 additions & 0 deletions tests/baselines/reference/emptyFilesConfig.types
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
//// [tests/cases/compiler/emptyFilesConfig.ts] ////

=== emptyFilesConfig.ts ===
export const tsconfig = {
>tsconfig : { files: any[]; }
> : ^^^^^^^^^^^^^^^^^
>{ "files": []} : { files: undefined[]; }
> : ^^^^^^^^^^^^^^^^^^^^^^^

"files": []
>"files" : undefined[]
> : ^^^^^^^^^^^
>[] : undefined[]
> : ^^^^^^^^^^^
}
17 changes: 17 additions & 0 deletions tests/baselines/reference/filesWithReferences.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
//// [tests/cases/compiler/filesWithReferences.ts] ////

//// [filesWithReferences.ts]
export const tsconfig = {
"files": [],
"references": [{ "path": "./lib" }]
}


//// [filesWithReferences.js]
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.tsconfig = void 0;
exports.tsconfig = {
"files": [],
"references": [{ "path": "./lib" }]
};
14 changes: 14 additions & 0 deletions tests/baselines/reference/filesWithReferences.symbols
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
//// [tests/cases/compiler/filesWithReferences.ts] ////

=== filesWithReferences.ts ===
export const tsconfig = {
>tsconfig : Symbol(tsconfig, Decl(filesWithReferences.ts, 0, 12))

"files": [],
>"files" : Symbol("files", Decl(filesWithReferences.ts, 0, 25))

"references": [{ "path": "./lib" }]
>"references" : Symbol("references", Decl(filesWithReferences.ts, 1, 16))
>"path" : Symbol("path", Decl(filesWithReferences.ts, 2, 20))
}

28 changes: 28 additions & 0 deletions tests/baselines/reference/filesWithReferences.types
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
//// [tests/cases/compiler/filesWithReferences.ts] ////

=== filesWithReferences.ts ===
export const tsconfig = {
>tsconfig : { files: any[]; references: { path: string; }[]; }
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>{ "files": [], "references": [{ "path": "./lib" }]} : { files: undefined[]; references: { path: string; }[]; }
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

"files": [],
>"files" : undefined[]
> : ^^^^^^^^^^^
>[] : undefined[]
> : ^^^^^^^^^^^

"references": [{ "path": "./lib" }]
>"references" : { path: string; }[]
> : ^^^^^^^^^^^^^^^^^^^
>[{ "path": "./lib" }] : { path: string; }[]
> : ^^^^^^^^^^^^^^^^^^^
>{ "path": "./lib" } : { path: string; }
> : ^^^^^^^^^^^^^^^^^
>"path" : string
> : ^^^^^^
>"./lib" : "./lib"
> : ^^^^^^^
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
message TS6042: No actionable task. Add 'composite': true, valid 'references', or use 'tsc -b'.


!!! message TS6042: No actionable task. Add 'composite': true, valid 'references', or use 'tsc -b'.
==== /parent/tsconfig.json (0 errors) ====
{
"files": [],
"references": [{ "path": "../child" }]
}

// @filename: /child/tsconfig.json
{
"compilerOptions": {
"declaration": true,
"declarationDir": "out",
"composite": true
},
"include": ["index.ts"]
}

// @filename: /child/index.ts
export const childConst = "I am child!";

49 changes: 49 additions & 0 deletions tests/baselines/reference/nodeAllowJsPackageSelfName2.errors.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/test/foo.js(1,21): error TS2307: Cannot find module 'js-self-name-import/foo.js' or its corresponding type declarations.


==== /tsconfig.json (0 errors) ====
{
"compilerOptions": {
"module": "nodenext",
"target": "esnext",
"emitDeclarationOnly": true,
"declaration": true,
"declarationDir": "./types",
"checkJs": true,
"rootDir": ".",
"strict": true,
"moduleResolution": "node16" // Ensures compatibility with Node's module resolution rules
},
"include": ["src", "test"]
}

==== /src/foo.js (0 errors) ====
export const foo = 1;

==== /test/foo.js (1 errors) ====
import { foo } from "js-self-name-import/foo.js";
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
!!! error TS2307: Cannot find module 'js-self-name-import/foo.js' or its corresponding type declarations.

==== /package.json (0 errors) ====
{
"name": "js-self-name-import",
"type": "module",
"exports": {
"./src/*": {
"types": "./types/src/*",
"default": "./src/*"
},
"./test/*": {
"types": "./types/test/*",
"default": "./test/*"
}
}
}

==== /types/src/foo.d.ts (0 errors) ====
export const foo: 1;

==== /types/test/foo.d.ts (0 errors) ====
export {};

Loading