Skip to content

Ensure all scripts are checked, fix errors #50326

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

Merged
merged 2 commits into from
Aug 17, 2022

Conversation

jakebailey
Copy link
Member

While working on a new lint rule, I noticed that a lot of the scripts have errors when I open them in the editor for various reasons, be it improper imports, type errors, etc.

Fix everything up and ensure any .ts files are included in this project, so we see their errors at build time.

There are a couple of the scripts that are written in js directly, so have handwritten d.ts files for them. I don't like that, but I think there must be some external callers (I see VSTS mentioned) that rely on being able to run the project without being compiled, it seems, so I won't change the status quo there quite yet.

@typescript-bot typescript-bot added Author: Team For Uncommitted Bug PR for untriaged, rejected, closed or missing bug labels Aug 16, 2022
Comment on lines -1 to -3
const fs = require("fs");
const async = require("async");
const glob = require("glob");
Copy link
Member

Choose a reason for hiding this comment

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

These are arguably more correct though, right?

Copy link
Member Author

Choose a reason for hiding this comment

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

Do you mean the old requires, or the new imports? (Some of the scripts already used imports; I have these changes also on my module transform branch too.)

Copy link
Member Author

Choose a reason for hiding this comment

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

(The output code is the same; with the imports, we generate const fs = require("fs") exactly)

Copy link
Member

Choose a reason for hiding this comment

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

I meant the old requires since those correspond to these being true CommonJS require calls anyway. It probably doesn't matter, so long as glob doesn't get called.

Copy link
Member Author

Choose a reason for hiding this comment

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

Ah, are you suggesting import glob from "glob"? I can do that, so long as we enable esModuleInterop. I opted to not change the tsconfig settings since import * seem to work.

Copy link
Member

@DanielRosenwasser DanielRosenwasser Aug 16, 2022

Choose a reason for hiding this comment

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

Right so that's the thing - import/require allows us to not worry about interop at all because we get to just say "yeah, the thing Node actually does with CJS.

The alternative is to swap to ESM scripts which I am actually open to as well for dog-fooding purposes. But maybe do that as a separate PR.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, that is actually the next step I wanted to take, but I wanted to get them to type check first.

@amcasey
Copy link
Member

amcasey commented Aug 16, 2022

I'm missing something - why are we changing import styles?

@jakebailey
Copy link
Member Author

jakebailey commented Aug 16, 2022

When I open say, scripts/configureLanguageServiceBuild.ts, this is what I get:

image

Import assignment cannot be used when targeting ECMAScript modules. Consider using 'import * as ns from "mod"', 'import {a} from "mod"', 'import d from "mod"', or another module format instead.

Technically, this is because the files are not included in the scripts project, so are getting some unspecified config. Fixing tsconfig.json to include all of the scripts fixes that.

I can totally undo the import changes and just leave the *.ts change; I originally fixed the imports directly, then later figured out that half of the scripts were not included in the project (so had other errors). Since half of the tests already use the "normal" import style, like buildProtocol.ts, I just left them as rewritten to be consistent when I sent the PR. I didn't expect that the import style would be the contentious thing 😃

@andrewbranch
Copy link
Member

andrewbranch commented Aug 17, 2022

I think as long as they type check and run, it doesn’t matter that much, but for my 2 cents, I think it’s strange to have ESM- and CJS-style imports in the same file, which is what we have before the change. I am totally on board with Daniel’s assessment that the requires are technically “more correct” but only if we also replace all the import { readFile } from "fs" with import fs = require("fs") too. So I think the proposed change is fine, and would be excited to see them transitioned to actually-ESM later.


I didn't expect that the import style would be the contentious thing

@jakebailey
Copy link
Member Author

jakebailey commented Aug 17, 2022

would be excited to see them transitioned to actually-ESM later.

That's next up; DT is already mjs (woo)

@amcasey
Copy link
Member

amcasey commented Aug 17, 2022

Don't block on me - I didn't read it carefully, but I have no objections.

@jakebailey
Copy link
Member Author

All good, I was busy with something else and just hadn't yet hit the button.

@jakebailey jakebailey merged commit 66d8b95 into microsoft:main Aug 17, 2022
@jakebailey jakebailey deleted the check-scripts branch August 17, 2022 23:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Author: Team For Uncommitted Bug PR for untriaged, rejected, closed or missing bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants