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

TSCONFIG Plugin doesn't trigger when using TSC #60952

Open
2dragonly opened this issue Jan 11, 2025 · 4 comments
Open

TSCONFIG Plugin doesn't trigger when using TSC #60952

2dragonly opened this issue Jan 11, 2025 · 4 comments
Labels
Working as Intended The behavior described is the intended behavior; this is not a bug

Comments

@2dragonly
Copy link

🔎 Search Terms

"tsconfig plugin" "tsc"

🕗 Version & Regression Information

  • This changed between versions ______ and _______
  • This changed in commit or PR _______
  • This is the behavior in every version I tried, and I reviewed the FAQ for entries about _________
  • I was unable to test this on prior versions because _______

⏯ Playground Link

No response

💻 Code

tsconfig.json:

{
  "plugins": [{ "name": "tsserver-plugin" }]
}

tsserver-plugin:

import { appendFileSync } from "node:fs";
import { join } from "node:path";
import { inspect } from "node:util";
import type tsm from "typescript/lib/tsserverlibrary";

function log(info: tsm.server.PluginCreateInfo, ...contents: any[]) {
  const message = `[tsserver-plugin]: ${contents
    .map((content) => inspect(content, { depth: null }))
    .join(" ")}`;

  info.project.projectService.logger.info(message);
  appendFileSync(
    join(info.project.getCurrentDirectory(), "tsconfig-plugin-debug.log"),
    `${message}\n`,
  );
}

const plugin: tsm.server.PluginModuleFactory = ({ typescript: ts }) => {
  function create(info: tsm.server.PluginCreateInfo) {
    log(info, "called!");
    const proxy: tsm.LanguageService = Object.create(null);

    for (const k of Object.keys(info.languageService) as Array<
      keyof tsm.LanguageService
    >) {
      const x = info.languageService[k]!;
      // @ts-expect-error - mismatch
      proxy[k] = (...args: Array<Record<string, unknown>>) =>
        Reflect.apply(x, info.languageService, args);
    }

    return proxy;
  }

  return { create };
};

export = plugin;

🙁 Actual behavior

The plugin does not seem to be invoked, and no logging output from the plugin is observed during the compilation.

🙂 Expected behavior

The plugin should trigger during the compilation process, and the logging statement ("[tsserver-plugin]: called!") should appear in the logs.

Additional information about the issue

The tsconfig plugin does not trigger or function as expected when running the tsc (TypeScript Compiler) command. Despite being correctly configured in tsconfig.json and implemented as a tsserver plugin, the expected behavior or logging from the plugin does not occur during compilation.

Steps to Reproduce

  1. Configure tsconfig.json to include the plugin as shown above.
  2. Implement the plugin to log an informational message when called.
  3. Run tsc in the project directory to compile the code.
@MartinJohns
Copy link
Contributor

This is working as intended and documented on the wiki:

Plugins can't add new language features such as new syntax or different typechecking behavior, and plugins aren't loaded during normal commandline typechecking or emitting, (so are not loaded by tsc).

The plugins are solely for editors, as suggested by the tsconfig documentation:

List of language service plugins to run inside the editor.

@acutmore
Copy link
Contributor

This is the expected behaviour. Plugins, for now, are only used by the language server.

Related issue: #14419

@2dragonly
Copy link
Author

2dragonly commented Jan 12, 2025

I want to use plugins for my package that override paths in tsconfig.json, but it only works on the typescript language server.

Any luck about this? How can i overrides the tsconfig.json before being used in tsc?

@jakebailey
Copy link
Member

There is no way to do this besides wrapping TS's API or using package like ts-patch.

FWIW I would really question the need for any use of paths today; have you considered using package.json import maps? Why do you need a plugin to do this? This seems like an "XY problem" to me; you're asking for a specific solution but not describing the problem you're trying to solve.

@RyanCavanaugh RyanCavanaugh added the Working as Intended The behavior described is the intended behavior; this is not a bug label Jan 13, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Working as Intended The behavior described is the intended behavior; this is not a bug
Projects
None yet
Development

No branches or pull requests

5 participants