Skip to content

TSServer Plugins with sub-packages/paths are not loadedΒ #57047

Closed

Description

πŸ”Ž Search Terms

"language server", "because only package name is allowed plugin name", "language server plugins"

πŸ•— Version & Regression Information

This behaviour must be going back to 4.2.2 as per #43124.

⏯ Playground Link

No response

πŸ’» Code

tsconfig.json

{
  "compilerOptions": {
    "plugins": [
      {
        "name": "package/lsp"
      }
    ]
  }
}

πŸ™ Actual behavior

TypeScript rejects sub-path package plugins, as per:

  • if (!pluginConfigEntry.name || parsePackageName(pluginConfigEntry.name).rest) {
    this.logger.info(`Skipped loading plugin ${pluginConfigEntry.name || JSON.stringify(pluginConfigEntry)} because only package name is allowed plugin name`);
    return;
    }
  • and;
    export function parsePackageName(moduleName: string): { packageName: string; rest: string; } {
    let idx = moduleName.indexOf(directorySeparator);
    if (moduleName[0] === "@") {
    idx = moduleName.indexOf(directorySeparator, idx + 1);
    }
    return idx === -1 ? { packageName: moduleName, rest: "" } : { packageName: moduleName.slice(0, idx), rest: moduleName.slice(idx + 1) };
    }

tsserver log

Info 11   [15:52:00.931] Enabling plugin package/subpath from candidate paths: [...]node_modules/typescript/lib/tsserver.js/../../..
Info 12   [15:52:00.931] Skipped loading plugin package/lsp because only package name is allowed plugin name

πŸ™‚ Expected behavior

Plugins are loaded as per either package.json:exports with subfolders specified, or via package/sub-path/package.json or package/sub-path/index.js.

Additional information about the issue

Related issues: #42688 and #42688.

If my understanding is correct, TypeScript only wants to allow packages that:

  • have been installed via a package manager, so that opening VSCode without installing doesn't immediately run unauthorised code
  • are not relative paths or local code that's checked into a repository

Neither applies to sub-packages. The use-case here is to publish packages that both provide code and an LSP package in one, without splitting this into two packages because of the assertion in TypeScript.

Activity

  1. RyanCavanaugh commented on Jan 16, 2024

    @RyanCavanaugh
    Member

    PRs accepted, but this will need to be very carefully vetted. We might need some different syntax to disambiguate that package isn't interpreted by anyone to be a relative path

  2. kitten commented on Feb 1, 2024

    @kitten
    ContributorAuthor

    PR, as linked, is for the proposed change. Happy to of course make changes, if a different syntax is required, but currently, I’m assuming that the PR can for now represent behaviour without breaking the documented behaviour that a package name is expected, or how the wiki puts it:

    This name can only be an NPM package name.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions