Skip to content
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix TypeScript project language detection #3604

Merged
merged 1 commit into from
Mar 14, 2023
Merged

Conversation

alexweininger
Copy link
Member

Changes in #3586 changed TypeScript language detection in that JavaScript would also be detected, which results in prompting the user to choose a language in cases that didn't before #3586 was merged. I found this while fixing the unit tests.

These changes fix the unit tests so that if TypeScript is detected (tsconfig found, etc.), then JavaScript won't also be detected.

@alexweininger alexweininger requested a review from a team as a code owner March 1, 2023 21:52
@@ -24,7 +24,10 @@ export async function detectProjectLanguage(context: IActionContext, projectPath
if (await isTypeScriptProject(projectPath)) {
detectedLangs.push(ProjectLanguage.TypeScript);
} else {
detectedLangs.push(ProjectLanguage.JavaScript);
// don't add JavaScript if TypeScript is already detected
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if TypeScript is detected (tsconfig found, etc.)

I don't think it's checking for tsconfig right now, but that's an interesting idea

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My bad, I thought we were doing that. Adding a check for a tsconfig would also satisfy these tests since a tsconfig is created upon initializing the test folder.

@@ -24,7 +24,10 @@ export async function detectProjectLanguage(context: IActionContext, projectPath
if (await isTypeScriptProject(projectPath)) {
detectedLangs.push(ProjectLanguage.TypeScript);
} else {
detectedLangs.push(ProjectLanguage.JavaScript);
// don't add JavaScript if TypeScript is already detected
if (!detectedLangs.includes(ProjectLanguage.TypeScript)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

isTypeScriptProject currently checks for typescript listed as a dev dependency. Isn't that required for TypeScript projects? At the end of the day, it seems fine if we prompt for JS vs TS for weird projects - and I think the unit tests might have weird projects

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If there's a */index.ts file, but typescript is not a dev dependency, then we will detect JS and TS. Whereas before we only detected TS.

Although the test case is weird, if we find a */index.ts file, I think it's totally safe to assume the project language isn't JS.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No strong preference from me 🤷‍♂️

@alexweininger alexweininger merged commit 803d7ac into main Mar 14, 2023
@alexweininger alexweininger deleted the alex/beige-rhinoceros branch March 14, 2023 21:46
@microsoft microsoft locked and limited conversation to collaborators Apr 29, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants