Floffah / esbuild-plugin-d.ts

🔌 Build Typescript declarations with ESBuild
http://npm.im/esbuild-plugin-d.ts
MIT License
57 stars 6 forks source link

declarationDir or outDir does not work #2

Closed TomokiMiyauci closed 3 years ago

TomokiMiyauci commented 3 years ago

Hi!

This project is valuable because it can generate a declaration file as a plugin for esbuild. Is it intentional that can't control the output destination of the type declaration file?

Minimum configuration to reproduce: version:

node -v
v16.1.0
esbuild: 0.12.5
esbuild-plugin-d.ts: 1.0.2
typescript: 4.3.2

File structure

.
├── node_modules
├── build.js
├── mod.ts
├── package.json
├── tsconfig.json
└── yarn.lock

tsconfig.json

{
    "compilerOptions": {
        "declaration": true,
        "declarationDir": "./dist",
    }
}

build.js

import esbuild from "esbuild";
import { dtsPlugin } from "esbuild-plugin-d.ts";
esbuild
  .build({
    entryPoints: ["mod.ts"],
    bundle: true,
    outdir: "dist",
    plugins: [dtsPlugin()],
  })
  .catch(() => process.exit(1));

Now when I build it I get the following output.

node build.js
.
├── build.js
├── dist
│   └── mod.js
├── mod.d.ts
├── mod.ts
├── package.json
├── tsconfig.json
└── yarn.lock

The same result when outDir of tsconfig is set. Is there a way to output the type declaration file under dist?

Floffah commented 3 years ago

Hi, in your tsconfig, try setting outDir to ./dist and let me know if that fixes it. If it doesn't, ill try and reproduce this and fix it.

In the mean time, I will edit the plugin to set outDir in the typescript config to your esbuild outdir which should clear up some confusion.

As I re-read your question, I realise you have already tried outDir. I will look into fixing this.

Floffah commented 3 years ago

Found the issue, Although the plugin was looking for the typescript configuration, it wasn't actually finding it or loading it. It should now load your tsconfig file and even if it doesn't it will automatically fall back to the outdir set in the esbuild options. Should be fixed in 1.0.3

I have tested the local built version and it should work however I haven't tested the scenario of installing it from npm so let me know if it doesn't work.

Thank you!