floffah / esbuild-plugin-d.ts Goto Github PK
View Code? Open in Web Editor NEWπ Convenience plugin for compiling typescript definitions with ESBuild
Home Page: http://npm.im/esbuild-plugin-d.ts
License: MIT License
π Convenience plugin for compiling typescript definitions with ESBuild
Home Page: http://npm.im/esbuild-plugin-d.ts
License: MIT License
When running yarn tsc --build
I get an output tsconfig.tsbuildinfo
file used the the Typescript incremental builds. Subsequent builds are much faster.
This file doesn't get generated when using esbuild-plugin-d.ts
Even if I specify the tsBuildInfoFile
option, same thing.
{
"extends": "../../tsconfig.settings.json",
"compilerOptions": {
"composite": true,
"tsBuildInfoFile": "tsconfig.tsbuildinfo",
"outDir": "lib",
"rootDir": "src"
},
"include": ["src/**/*"],
"exclude": ["src/**/*.test.ts", "src/**/*.test.tsx"]
}
In our monorepo, each package has a tsconfig that extends a shared tsconfig located at the root of the yarn workspace. It seems that the compilerOptions from the extended tsconfig are not being taken into consideration.
For example, I had to add "declarationMap": true,
in order to generate sourcemaps for d.ts files even though the option is enabled in tsconfig.settings.json
.
{
"extends": "../../tsconfig.settings.json",
"compilerOptions": {
"declarationDir": "dist",
"emitDeclarationOnly": true,
"declarationMap": true,
"rootDir": "src"
},
"include": ["src"]
}
esbuild-plugin-d.ts/src/plugin.ts
Line 15 in 362490f
Not a big deal I guess, but simply wanted to point this out.
Thanks for that plugin! ;-)
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
?
{
"compilerOptions": {
"target": "ESNext",
"lib": ["ESNext"],
"outDir": "./dist",
"skipLibCheck": true,
"esModuleInterop": true,
"strict": true,
"module": "ESNext",
"moduleResolution": "node",
"sourceMap": true,
"declaration": true,
"declarationMap": true
},
"include": ["src"],
"typedocOptions": {
"entryPoints": ["src/index.ts"],
"out": "docs",
"readme": "README.md",
"gitRemote": "origin"
}
}
Reproducible steps
See error
esbuild
.build({
entryPoints: await globFils(),
bundle: false,
splitting: false,
outdir: path.join(process.cwd(), 'dist'),
format: 'cjs',
platform: 'node',
watch: !isPro && {
onRebuild(err, result) {
if (err) console.error(err)
},
},
minify: false,
sourcemap: false,
color: true,
loader: {
'.ts': 'tsx',
'.tsx': 'tsx',
},
plugins: [dtsPlugin()],
})
fixed types issue with tsup by bumping the package version and all other packages in the repo.
unmet peer typescript@^4.1.0: found 5.0.4
i use esbuild-plugin-d.ts only generate generate .d.ts files when i change the ts.config.json's value "declarationMap" from TRUE to FALSE or from FALSE from TRUE:
i think it would be e issue.
if i dont change ts.config.json file, only run npm run build, the .d.ts files cant be created the secrec time!
Context:
My workflow is such:
1: build -> 2: clean -> 3: build -> clean -> build -> etc...
'clean' removes all file from "dist" folder (which is the output folder)
Problem:
on step 3 (second build) d.ts files are not being created (if no files changed) or d.ts files are only created for changed files
Expectation:
build d.ts files if they are not present on disk
What I found out so far:
the problem seems to come from typescript incremental build program.
when you delete the .tsbuildinfo file before step 3, everything works
personal context:
the problem for me with that is, that i have not found a way to delete this file programmatically in a way that works for different platforms/systems (linux, windows, max), because it (the file) is located in temporary folder (/tmp/@package-scope/package-name/.esbuild/.tsbuildinfo on my system). and i'd have to guess that this folder is named differently on windows :) and even on some linux distros.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. πππ
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google β€οΈ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.