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

TSServer plugins pointing to relative paths are not loaded in 4.2.2 #43124

Closed
TomasHubelbauer opened this issue Mar 7, 2021 · 2 comments
Closed

Comments

@TomasHubelbauer
Copy link

Bug Report

TS Server will not load plugins whose name as defined in tsconfig.json is a relative path to a directory. This behavior is documented as supported in Writing a TypeScript Language Service Plugin:

or it can be a path to a directory with an index.js file

give it the path to your plugin in the tsconfig.json file

{
    "compilerOptions": {
        "plugins": [{
            "name": "../your_plugin",
        }]
    }
}

I have a repro repo showing that this does not in fact work. The repro branch references the plugin by a path of a directory and TS Server fails to load the plugin as seen in its log viewable through Ctrl/Cmd+Shift+P > TypeScript: Show TS Server log (be in a TS/JS file editor to see this option):

Skipped loading plugin ./plugin because only package name is allowed plugin name

In the master branch I have instead placed the plugin source code into node_modules and referenced the plugin by name, which works, but it only works when the workspace TypeScript version used comes from node_modules of the project directory too, because the plugins are looked up by going up the node_modules chain starting from where tsserver.js is (so project directory, its parent directory etc. all the way up until the drive root looking through node_modules at each of these paths).

This is a blocker for my attempt at building a TypeScript language server plugin which be distributed as a VS Code extension (contributes.typescriptServerPlugins), because the extension cannot place the plugin into the project directory where it is supposed to work in (that would affect the user's project code) nor can I guarantee that the user would have a workspace version of TypeScript (or that they would have it where it needs to be for the plugin to get loaded), meaning if they use the VS Code version of TypeScript (99.999 % of people probably), it wouldn't work for them. Again, I cannot force users to make this selection just for the sake of this plugin, because they may have different configuration to suit their own needs.

I'm hoping the ability to load the plugins by directory path (relative and absolute) is returned as it is much simpler and greatly simplifies using plugins both as a developer in testing and as a user.

BTW, this issue has also been brought up on Stack overflow which is where I found that this not working is a know issue which has been closed and not resolved.

🔎 Search Terms

TSServer plugins pointing to relative paths

This search yielded #18623 which raises this bug but is closed by the author despite the bug being unfixed. The reporter of that issue prompted another commented to open a new issue if they still want to see this fixed, that person did not seem to do that (according to my issue search with them for the author filter) and so here I am doing just that.

🕗 Version & Regression Information

When did you start seeing this bug occur?

I have first come across this bug in 4.2.2 but it seems to date all the way back to 2.5 if not longer.

This is a crash

Technically it doesn't crash TS Server but it does prevent the plugin from loading

This changed between versions

Worked prior to 2.5 (or thereabouts) and stopped working in 2.5

This is the behavior in every version I tried, and I reviewed the FAQ for entries about

I have been able to reproduce this in 4.2.2

I was unable to test this on prior versions because

They are not bundled with VS Code and I am working on developing a TS Server plugin that would work in the latest version of VS Code so I am bound to the version of TypeScript VS Code is shipping. This working in other versions does not solve this issue for this case even if it was working, which is seems it is not anyway, since 2.5 up.

⏯ Playground Link

This is not reproducible in TS Playground as it has to do with the TS Server, but see my repro repo.

💻 Code

{
  "compilerOptions": {
    "plugins": [
      {
        "name": "./plugin"
      }
    ],
    "allowJs": true,
    "noEmit": true
  }
}

🙁 Actual behavior

TS Server refuses to load the plugin despite it being defined in a way recommended by the documentation for this feature.

🙂 Expected behavior

TS Server loads the plugin!

@MartinJohns
Copy link
Contributor

Possible related? #42688

@TomasHubelbauer
Copy link
Author

@MartinJohns Thanks for the find Martin. That sucks, but security is security. I'm going to close this issue.

FWIW if anyone comes across this, I have documented my workaround to this problem in here:

https://stackoverflow.com/a/66504080/2715716 & https://github.com/TomasHubelbauer/lsp-plugin

It is less of a problem when publishing the plugin it turns out, one can just make a VS Code extension, use the contribution point for TS Server plugins, install the plugin extracted as an NPM package to the VS Code extension and then either publish or package the extension. It will bundle up the plugin dependency and VS Code will load the plugin the right way through the extension to the TS Server. Example extension developed for the above repo:

https://github.com/TomasHubelbauer/vscode-esm-url

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants