-
Notifications
You must be signed in to change notification settings - Fork 12.5k
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
Use regular imports instead of require where possible #59017
Conversation
@typescript-bot perf test this |
@jakebailey Here they are:
tscComparison Report - baseline..pr
System info unknown
Hosts
Scenarios
tsserverComparison Report - baseline..pr
System info unknown
Hosts
Scenarios
startupComparison Report - baseline..pr
System info unknown
Hosts
Scenarios
Developer Information: |
import childProcess from "child_process"; | ||
import fs from "fs"; | ||
import net from "net"; | ||
import os from "os"; | ||
import readline from "readline"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there any risk now that these are unconditional imports?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nope, this is the tsserver project which only runs in node.
@@ -326,7 +277,7 @@ export function initializeNodeSystem(): StartInput { | |||
|
|||
let cancellationToken: ts.server.ServerCancellationToken; | |||
try { | |||
const factory = require("./cancellationToken"); | |||
const factory = require("./cancellationToken.js"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi, I came across this line running dependency-cruiser on the typescript codebase. After building, it's the only require/import that can't be resolved. I notice that this file, nodeServer
, does not have a cancellationToken
sibling file - is it possible that this is always throwing (seems like it could be, since the catch block silently catches the error and uses ts.server.nullCancellationToken
)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This file should exist as a sibling. https://unpkg.com/browse/[email protected]/lib/cancellationToken.js
Are you running this tool on the built code, or the source?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(realistically, it's not clear to me why this is a separate file at all anyway)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh I see. I'm running it on the source, so I guess it's missing some part of the build process that compiles src/tsserver/nodeServer.ts
into lib/tsserver.js
, and src/cancellationToken/cancellationToken.ts
into lib/cancellationToken.js
, is that right? (Something in Hereby?)
Would it not work as require("../cancellationToken/cancellationToken.js")
(which I think is what would be correct for the source file structure)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, that would not work. Our input source structure has nothing to do with our output source structure; it's bundled and placed in a different directory.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Got it - thanks very much!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#60250 you've inspired me
This is pulled out of #58419, since I think this is generally better and we can do it now.