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

d.ts files not built on repeated build runs #8

Closed sngn closed 8 months ago

sngn commented 2 years ago

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.

sngn commented 2 years ago

versions info: tsc 4.5.4 esbuild 0.14.11 esbuild-plugin-d.ts 1.1.0

Floffah commented 2 years ago

Would it be more beneficial to make it use incremental support by default and use normal ts programs when an option is present or the other way round using ts programs and incremental when an option is present?

sachinraja commented 2 years ago

Having the same issue, but I would still like for the .d.ts files to be cached across runs (tsc takes quite a long time). I think it makes sense to read the option from your tsconfig.json. Might be worth looking into how @rollup/plugin-typescript handles this (https://github.com/rollup/plugins/pull/535) or rollup-plugin-typescript2 (probably better since it uses a hash).

Floffah commented 2 years ago

Having the same issue, but I would still like for the .d.ts files to be cached across runs (tsc takes quite a long time). I think it makes sense to read the option from your tsconfig.json. Might be worth looking into how @rollup/plugin-typescript handles this (rollup/plugins#535) or rollup-plugin-typescript2 (probably better since it uses a hash).

thank you ill look into this when i get time feel free to submit any prs in the time being

cuttleman commented 1 year ago

@sngn like below code When I ran the code to remove the cached folder before the build command, the d.ts file was created normally.

const packagejson = require("./package.json");
const fs = require("fs");

const cachedPath = tmpdir + "/" + packagejson.name;

fs.rm(cachedPath, { recursive: true }, (err) => {
  if (err) {
    console.error(err.message);
    return;
  }
  console.log("Caching File deleted successfully");
  console.log(`Deleted File: ${cachedPath}`);
});
HarikalarKutusu commented 1 year ago

Just hit this issue on my library rebuild. Actually, there is the "tsBuildInfoFile": "lib/.tsbuildinfo", definition in the tsconfig.json file in the library, but it is not taken into consideration by esbuild either... If it were, removing the "./lib" directory would resolve the problem...

Or is there a way?

HarikalarKutusu commented 1 year ago

const cachedPath = tmpdir + "/" + packagejson.name;

I had workspace modules defined like "@app/lib", they were created as a directory tree under my Windows temp directory. I solved it like this (should be portable):

import { rmSync } from "node:fs";
import path from "path";
import pjson from "./package.json" assert { type: "json" };

const appTemp= path.join(process.env.TEMP, pjson.name);
rmSync(appTemp, { force: true, recursive: true });

I will add this to all esbuild's so that they are kept clean of this issue...

Floffah commented 8 months ago

This issue should be fixed in 1.2.0, please confirm. It was related to the assumed incremental compilation which is now conditional based on if the incremental compiler option is present or not.

Floffah commented 8 months ago

Just hit this issue on my library rebuild. Actually, there is the "tsBuildInfoFile": "lib/.tsbuildinfo", definition in the tsconfig.json file in the library, but it is not taken into consideration by esbuild either... If it were, removing the "./lib" directory would resolve the problem...

Or is there a way?

This issue should also be fixed, the plugin will take into consideration the tsBuildInfoFile setting and not use its own unless it isn't present while incremental is true.