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

How to improve extension author experience dealing with vscode- to @vscode npm module change #140585

Closed
Tyriar opened this issue Jan 12, 2022 · 12 comments
Assignees
Labels
important Issue identified as high-priority insiders-released Patch has been released in VS Code Insiders

Comments

@Tyriar
Copy link
Member

Tyriar commented Jan 12, 2022

We're probably going to get a bunch of extension issues like this: Gruntfuggly/todo-tree#595

Should we:

  • Add an alias to vscode- when requiring to automatically fix the problem?
  • Email extension authors using the modules?
  • Write in the release notes of the change?
  • Delay the module change an extra iteration?

I know the modules we ship with the product are not "public API", but there are many extensions that do use them.

@connor4312
Copy link
Member

We're probably going to get a bunch of extension issues like this

I'm not sure that we are. This is pretty dangerous internal use from the get-go and I would hope is pretty rare.

Add an alias to vscode- when requiring to automatically fix the problem?

This isn't being required, instead it's pulled from the app installation directory: https://github.com/Gruntfuggly/todo-tree/blob/dfd91634b8047614644e5161c588d595b2100ac6/src/config.js#L97-L107 Hence the extra danger and hopeful rarity.

We could preserve the install structure, but the structure of the app folder is not contract we ever intended to have so I dislike treating it as such...

@Tyriar
Copy link
Member Author

Tyriar commented Jan 12, 2022

I know there are several internal and at least this one using node-pty for example:

https://github.com/mmis1000/Vscode-terminal-tab/blob/a0720ad131664748aecd9915fb3a24ddb42163ab/src/terminal.ts#L6-L21

No one told the author how to do that. It would make sense to me that ripgrep would also see similar usage since searching text is a big use case for extensions and working with native modules in extension also isn't really supported (you can but it's a pain).

@Tyriar
Copy link
Member Author

Tyriar commented Jan 12, 2022

👀 https://github.com/search?q=getCoreNodeModule&type=code

Just looking at the results page (not digging in when it's not obvious) I see a bunch of uses for keytar, vscode-oniguruma, vscode-textmate, windows-process-tree and node-pty. That doesn't includes the majority of those 7 pages of results, and also doesn't include if the function/mechanism they used was not named exactly getCoreNodeModule.

@connor4312
Copy link
Member

If we want to have this be "contract", perhaps we actually expose require.resolve and allow that to resolve internal vscode modules? Then authors could use that instead of depending on modules hackily like this.

@Tyriar
Copy link
Member Author

Tyriar commented Jan 12, 2022

I kind of like the "soft contract" similar to commands, we're not technically restricted from making breaking changes (I wouldn't want node-pty to never have breaking changes). By using that getCodeNodeModule function, people should know that there are risks, an explicit API would give a signal that it's fine.

Just here, we should be careful about not causing a bunch of broken extensions because we are able to. I'm not saying support vscode-ripgrep forever. We could for example have aliases built-in on the exthost side that logs a warning when used, announce in the release notes of the change, and pull it out 3 months later. Seems like very little effort and much less problems.

@connor4312
Copy link
Member

We could for example have aliases built-in on the exthost side that logs a warning when used, announce in the release notes of the change, and pull it out 3 months later. Seems like very little effort and much less problems.

This sounds good. I'll implement this and then link the relevant code here so that, as others migrate their packages, they can add aliases.

@connor4312
Copy link
Member

connor4312 commented Jan 12, 2022

Ok, so one note -- aliasing require is fine which would make getCoreNodeModule work, but todo-tree uses fs.existsSync to check the existence of the file before attempting to require it, which this won't cover. And I don't want to get into patching fs.

@Tyriar
Copy link
Member Author

Tyriar commented Jan 12, 2022

Yeah I wouldn't do anything there either, but we can catch the common code snippet at least

@connor4312
Copy link
Member

connor4312 commented Jan 12, 2022

It looks like vscode-ripgrep actually exports the rgPath, so a safe alternative would be for them to try { return getCoreNodeModule('vscode-ripgrep').rgPath; } catch {}. I will PR to that effect and create issues on other consumers of vscode-ripgrep.

@connor4312
Copy link
Member

connor4312 commented Jan 12, 2022

Here's the template I posted and all repos I could find who use ripgrep in this way:

And the aliases:

/**
* Map of aliased internal node_modules, used to allow for modules to be
* renamed without breaking extensions. In the form "original -> new name".
*/
private static readonly aliased: ReadonlyMap<string, string> = new Map([
['vscode-ripgrep', '@vscode/ripgrep'],
]);

@Tyriar
Copy link
Member Author

Tyriar commented Jan 12, 2022

@connor4312 oh is vscode-textmate and vscode-oniguruma not republished yet?

@connor4312
Copy link
Member

Not yet

@github-actions github-actions bot locked and limited conversation to collaborators Feb 26, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
important Issue identified as high-priority insiders-released Patch has been released in VS Code Insiders
Projects
None yet
Development

No branches or pull requests

3 participants
@Tyriar @connor4312 and others