Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

fix(typescript-estree): don't throw on missing tsconfig.json by default in project service#9989

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
Show file tree
Hide file tree
Changes fromall 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
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -42,9 +42,10 @@ export function createProjectService(
jsDocParsingMode: ts.JSDocParsingMode | undefined,
tsconfigRootDir: string | undefined,
): ProjectServiceSettings {
const optionsRawObject = typeof optionsRaw === 'object' ? optionsRaw : {};
const options = {
defaultProject: 'tsconfig.json',
...(typeof optionsRaw === 'object' && optionsRaw),
...optionsRawObject,
};
validateDefaultProjectForFilesGlob(options.allowDefaultProject);

Expand DownExpand Up@@ -126,7 +127,7 @@ export function createProjectService(
});

log('Enabling default project: %s', options.defaultProject);
let configFile: ts.ParsedCommandLine;
let configFile: ts.ParsedCommandLine | undefined;

try {
configFile = getParsedConfigFile(
Expand All@@ -135,18 +136,22 @@ export function createProjectService(
tsconfigRootDir,
);
} catch (error) {
throw new Error(
`Could not read project service default project '${options.defaultProject}': ${(error as Error).message}`,
);
if (optionsRawObject.defaultProject) {
throw new Error(
`Could not read project service default project '${options.defaultProject}': ${(error as Error).message}`,
);
}
}

service.setCompilerOptionsForInferredProjects(
// NOTE: The inferred projects API is not intended for source files when a tsconfig
// exists. There is no API that generates an InferredProjectCompilerOptions suggesting
// it is meant for hard coded options passed in. Hard asserting as a work around.
// See https://github.com/microsoft/TypeScript/blob/27bcd4cb5a98bce46c9cdd749752703ead021a4b/src/server/protocol.ts#L1904
configFile.options as ts.server.protocol.InferredProjectCompilerOptions,
);
if (configFile) {
service.setCompilerOptionsForInferredProjects(
// NOTE: The inferred projects API is not intended for source files when a tsconfig
// exists. There is no API that generates an InferredProjectCompilerOptions suggesting
// it is meant for hard coded options passed in. Hard asserting as a work around.
// See https://github.com/microsoft/TypeScript/blob/27bcd4cb5a98bce46c9cdd749752703ead021a4b/src/server/protocol.ts#L1904
configFile.options as ts.server.protocol.InferredProjectCompilerOptions,
);
}

return {
allowDefaultProject: options.allowDefaultProject,
Expand Down
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -65,7 +65,7 @@ describe('createProjectService', () => {
expect(settings.allowDefaultProject).toBeUndefined();
});

it('throws an error with a local path when options.defaultProject is not provided and getParsedConfigFile throws a diagnostic error', () => {
it('does not throw an error when options.defaultProject is not provided and getParsedConfigFile throws a diagnostic error', () => {
mockGetParsedConfigFile.mockImplementation(() => {
throw new Error('tsconfig.json(1,1): error TS1234: Oh no!');
});
Expand All@@ -78,9 +78,7 @@ describe('createProjectService', () => {
undefined,
undefined,
),
).toThrow(
/Could not read project service default project 'tsconfig.json': .+ error TS1234: Oh no!/,
);
).not.toThrow();
});

it('throws an error with a relative path when options.defaultProject is set to a relative path and getParsedConfigFile throws a diagnostic error', () => {
Expand DownExpand Up@@ -132,6 +130,7 @@ describe('createProjectService', () => {
createProjectService(
{
allowDefaultProject: ['file.js'],
defaultProject: 'tsconfig.json',
},
undefined,
undefined,
Expand Down
Loading

[8]ページ先頭

©2009-2025 Movatter.jp