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

Avoid __nodeRequire() #74398

Closed
5 of 6 tasks
bpasero opened this issue May 27, 2019 · 19 comments · Fixed by #75200
Closed
5 of 6 tasks

Avoid __nodeRequire() #74398

bpasero opened this issue May 27, 2019 · 19 comments · Fixed by #75200
Assignees
Labels
debt Code quality issues

Comments

@bpasero
Copy link
Member

bpasero commented May 27, 2019

We still have a few places of a __nodeRequire that we should convert into async import().

For example, code such as:

this._keytar = <IKeytarModule>require.__$__nodeRequire('keytar');

becomes:

this._keytar = await import('keytar');

Places:

@bpasero bpasero added the debt Code quality issues label May 27, 2019
@isidorn
Copy link
Contributor

isidorn commented May 27, 2019

@weinand actually added the dependency to vsda. However when I change the code to await import('vsda'); I get an error that vsda can not be found. @weinand should we specify that we use vsda somewhere?
Code pointer https://github.com/Microsoft/vscode/blob/a00a9a29452546c6f5018f89d5c9f051f841dd38/src/vs/workbench/contrib/debug/electron-browser/rawDebugSession.ts#L531

@joaomoreno
Copy link
Member

joaomoreno commented May 27, 2019

Isn't this still going sync, deep down?

@weinand
Copy link
Contributor

weinand commented May 27, 2019

@isidorn __$__nodeRequire comes from the vscode.loader. The owner of that package (@alexandrudima or @jrieken) should advise how to replace this with an async import.

BTW, 'vsda' is used in two places: RawDebugSession and RemoteAgentConnection. Please fix both of them since Alex is out.

@bpasero
Copy link
Member Author

bpasero commented May 27, 2019

@isidorn yeah that sucks, we probably need to throw in a vsda.d.ts into src/typings to make TS happy :-|

@bpasero bpasero changed the title Avoid sync __nodeRequire() Avoid __nodeRequire() May 27, 2019
@bpasero
Copy link
Member Author

bpasero commented May 27, 2019

Updated the title, there is no difference in loading behaviour but I feel __nodeRequire() is really a hack from the times where we could not write async import(...). It also gives us proper typing.

@jrieken
Copy link
Member

jrieken commented May 27, 2019

Isn't this still going sync, deep down?

Yeah, it's still equally sync. Writing async import 'foo' is the same as writing new Promise(resolve => load_module('foo')). It still helps because it auto-generates load_module for you.

I get an error that vsda can not be found. @weinand should we specify that we use vsda somewhere?

Putting declare module 'vsda' {} anywhere in your code should help

@isidorn
Copy link
Contributor

isidorn commented May 27, 2019

Thanks for advice.
Added vsda.d.ts and fixed the issue in rawDebugSession
Now strangly the RemoteAgentConnection can not await import('keytar'); since that import violates the ts lint import rule. @bpasero should I put the vsda.d.ts in some other typings folder, since the RemoteAgentConnection can not depend on it from src/typings?

isidorn added a commit that referenced this issue May 27, 2019
@bpasero
Copy link
Member Author

bpasero commented May 27, 2019

It should be able to depend, then we need to tweak some tslint rule maybe.

@isidorn
Copy link
Contributor

isidorn commented May 27, 2019

Ok. I have tweaked the tslint rule to allow vsda to be imported. Did not use a * to not allow random node modules to be imported there.
Seems to work fine now

@bpasero
Copy link
Member Author

bpasero commented May 27, 2019

@isidorn looks like this is causing build failures and they can be explained by the fact that remoteAgentConnection is living in common when it should live in node. I am not sure why that is, maybe we should leave that one up for next milestone and move it properly.

@isidorn
Copy link
Contributor

isidorn commented May 27, 2019

@bpasero yup, just saw the build failure. Reverting my commit. Let's tackle in June.

@Tyriar
Copy link
Member

Tyriar commented May 27, 2019

I'll be replacing these with importing standalone modules soon:

Terminal.applyAddon(require.__$__nodeRequire('vscode-xterm/lib/addons/search/search'));
Terminal.applyAddon(require.__$__nodeRequire('vscode-xterm/lib/addons/webLinks/webLinks'));

@Tyriar
Copy link
Member

Tyriar commented Jun 4, 2019

Terminal ones removed in #74858

@Tyriar Tyriar removed their assignment Jun 4, 2019
@isidorn
Copy link
Contributor

isidorn commented Jun 5, 2019

@bpasero I can look into moving remoteAgentConnection to node.
@aeschli does this make sense to you? I see some modules from common depend on it, so I wold probalby split the remoteAgentConnection to have the implementation in node and interfaces in common

@joaomoreno joaomoreno removed their assignment Jun 5, 2019
joaomoreno added a commit that referenced this issue Jun 5, 2019
chrmarti added a commit that referenced this issue Jun 5, 2019
@chrmarti
Copy link
Collaborator

chrmarti commented Jun 5, 2019

@bpasero Do you know why mainThreadKeytar.ts was placed in the 'browser' and not the 'node' folder? Maybe that was an oversight.

chrmarti added a commit that referenced this issue Jun 5, 2019
@chrmarti chrmarti removed their assignment Jun 5, 2019
@isidorn
Copy link
Contributor

isidorn commented Jun 5, 2019

@bpasero I looked into the remoteAgentConnection and it is a bit more complex. The issue is that it can not be nicely split up between common and node since the actual function that uses require.__$__nodeRequire syntax is used by other modules not living in node.
We seem to use the vsda module for signing when in the native environment. And due to that I believe we need two implementations of connectToRemoteExtensionHostAgent one for the native and one for the rest. So we basically get rid of this check.

I could also pass in the signer as part of the options, so the remoteAgentConnection stays in common and different clients would pass a signer.

@bpasero
Copy link
Member Author

bpasero commented Jun 5, 2019

@chrmarti I noticed this and it is a bad hack, but I am not sure why that was done. The right solution would be to introduce a service for this and implement it in browser and node environments.

@isidorn I do not understand

@isidorn
Copy link
Contributor

isidorn commented Jun 11, 2019

fyi
There is a difference in the behaivor of the __nodeRequiere() and await import('')
When the module is missing, the second pattern will only throw the error the first time you import the moduel.
Due to that I had to cache the promise to always have the expected behavior for the missing module

https://github.com/Microsoft/vscode/blob/18f4630bc51a3d87c7b31d96ca9c8ea95aa649b0/src/vs/platform/sign/node/signService.ts#L15

@isidorn
Copy link
Contributor

isidorn commented Jun 11, 2019

Created #75257 as a follow up

@vscodebot vscodebot bot locked and limited conversation to collaborators Jul 26, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
debt Code quality issues
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants