eth-p / eth-p/esbuild-plugin-dts-bundle-generator

Output path resolution is different compared to esbuild

Open
#1 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
TypeScript
Stars
6
Forks
0
PR merge metrics
No merged PRs in 30d

Description

The following config will output the `index.d.ts` file into `./dist/src/index.d.ts` instead of `./dist/index.d.ts`.
```ts
import { type BuildOptions } from 'esbuild';

const srcPath = './src/index.ts';

const config: BuildOptions = {
entryPoints: [srcPath],
outdir: './dist',
format: 'esm',
sourcemap: true,
bundle: true,
write: true,
minify: false,
platform: 'node',
packages: 'external',
plugins: [dts()],
};
```

I suspect that the issue is caused by the difference in how output path is resolved by the plugin compared to how esbuild resolve it. At the moment, I don't have a proposal to solve this issue.

It might be related to lower common ancestor:
https://esbuild.github.io/api/#outdir

I don't have enough experience with esbuild api, but `build.resolve` would be the first thing I would check:
https://esbuild.github.io/plugins/#resolve

## Workaround:
```ts
import { type BuildOptions } from 'esbuild';

const srcPath = './src/index.ts';

const config: BuildOptions = {
entryPoints: [srcPath],
outdir: './dist',
format: 'esm',
sourcemap: true,
bundle: true,
write: true,
minify: false,
platform: 'node',
packages: 'external',
// required because the plugin doesn't resolve the output path the same as esbuild
plugins: [dts({ entryPoints: [{ in: srcPath, out: 'index' }] })],
};
```

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.