microsoft / TypeScript

TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
https://www.typescriptlang.org
Apache License 2.0
100.77k stars 12.46k forks source link

Respect Node's `--loader` for VS Code Intellisense #57129

Open F1LT3R opened 9 months ago

F1LT3R commented 9 months ago

I would like VS Code to be able to use a custom Node.js loader for Intellisense.

For example, if I remove the .mjs extension from my code, I can no longer see the Intellisense for mime-types.mjs.

But my custom loader does not require the extension.

Here is what I am hoping to see: (without the .mjs extension on the import)

image

I can see the .html reference in the Intellisense drop down.

image

But here is what I actually see:

image

I think that now Node.js loaders are going through the normalization process - heading out of experimental, it is a good time for VS Code to start working on respecting loaders.

Perhaps this could live in .vscode/settings.json:

// .vscode/settings.json
{
    "loader": "./loader.mjs"
}

It would be important to provide different loaders for different directories for more complex projects/monorepos, etc:

// .vscode/settings.json
{
    "loader": {
        "./app-one": "./loaders/my-custom-loader-1.mjs",
        "./app-two": "./loaders/my-custom-loader-2.mjs",
        "./app-three": "react-loader"  // <-- Uses a package as a loader
    }
}
RyanCavanaugh commented 9 months ago

I don't think we'd be able to support arbitrary loaders -- running untrusted code here is a security boundary violation.

You probably would be able to use https://www.typescriptlang.org/tsconfig#customConditions in a jsconfig file assuming the loader has some reasonably-standardish behavior. What does this loader you have actually do?

F1LT3R commented 9 months ago

The loader does the following:

  1. Resolves extension-less .mjs file imports across http:// and file://
  2. Resolves directories to their containing index.mjs files across http:// and file://

Should a loader still be considered untrusted if the loader is run from within the loaded project, specifically after the user has already selected "Trust Authors" or "Trust Workspace?