Skip to content

Avoid __nodeRequire() #74398

Closed
Closed

Description

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:

Activity

  1. isidorn commented on May 27, 2019

    @isidorn

    Andre Weinand (@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. Andre Weinand (@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

  2. joaomoreno commented on May 27, 2019

    @joaomoreno
    Contributor

    Isn't this still going sync, deep down?

  3. weinand commented on May 27, 2019

    @weinand
    Contributor

    Isidor Nikolic (@isidorn) __$__nodeRequire comes from the vscode.loader. The owner of that package (alexandrudima or Johannes Rieken (@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.

  4. bpasero commented on May 27, 2019

    @bpasero
    ContributorAuthor

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

  5. changed the title [-]Avoid sync __nodeRequire()[/-] [+]Avoid __nodeRequire()[/+] on May 27, 2019
  6. bpasero commented on May 27, 2019

    @bpasero
    ContributorAuthor

    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.

  7. jrieken commented on May 27, 2019

    @jrieken
    Contributor

    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. Andre Weinand (@weinand) should we specify that we use vsda somewhere?

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

  8. isidorn commented on May 27, 2019

    @isidorn

    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. Benjamin Pasero (@bpasero) should I put the vsda.d.ts in some other typings folder, since the RemoteAgentConnection can not depend on it from src/typings?

  9. added a commit that references this issue on May 27, 2019
  10. 6 remaining items

  11. Tyriar commented on Jun 4, 2019

    @Tyriar
    Contributor

    Terminal ones removed in #74858

  12. removed their assignment
    on Jun 4, 2019
  13. isidorn commented on Jun 5, 2019

    @isidorn

    Benjamin Pasero (@bpasero) I can look into moving remoteAgentConnection to node.
    Martin Aeschlimann (@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

  14. chrmarti commented on Jun 5, 2019

    @chrmarti
    Collaborator

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

  15. isidorn commented on Jun 5, 2019

    @isidorn

    Benjamin Pasero (@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.

  16. bpasero commented on Jun 5, 2019

    @bpasero
    ContributorAuthor

    Christof Marti (@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.

    Isidor Nikolic (@isidorn) I do not understand

  17. isidorn commented on Jun 11, 2019

    @isidorn

    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

  18. isidorn commented on Jun 11, 2019

    @isidorn

    Created #75257 as a follow up

  19. locked and limited conversation to collaborators on Jul 26, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

debt

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions