Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to generate .d.ts.map #564

Closed
eric-burel opened this issue Feb 7, 2022 · 2 comments · Fixed by #566
Closed

How to generate .d.ts.map #564

eric-burel opened this issue Feb 7, 2022 · 2 comments · Fixed by #566

Comments

@eric-burel
Copy link
Contributor

eric-burel commented Feb 7, 2022

Hi,

I am able to generate .d.ts, however in a monorepo it's also a requirement to produce .d.ts.map files to allow jumping between files (see https://stackoverflow.com/questions/55318663/how-to-generate-d-ts-and-d-ts-map-files-using-webpack).

My tsconfig enables declarationMap, however it doesn't seem to be respected by tsup. Do you have an idea of how to force this parameter to be taken into account? I guess you use tsc under the hood so that's just a matter of passing the right config.

My tsup.config.ts:

import { defineConfig } from "tsup";

const commonConfig = {
  clean: true,
  splitting: false,
  dts: true,
  sourcemap: true,
};
export default defineConfig([
  {
    entry: ["index.ts"],
    ...commonConfig,
    format: ["cjs", "esm", "iife"],
    outDir: "dist",
  },

Adding: tsconfig: path.resolve(__dirname, "./tsconfig.build.json"), (with the config enabling declarationMap) doesn't seem to work.

My tsconfig.json:

{
  "compilerOptions": {
    "allowJs": false,
    "alwaysStrict": true,
    "declaration": true,
    "declarationMap": true, // Allow navigation to definition in VS Code https://stackoverflow.com/questions/54459847/vscode-lerna-typescript-monorepo-code-navigation
    "emitDecoratorMetadata": true,
    "esModuleInterop": true,
    "experimentalDecorators": true,
    "forceConsistentCasingInFileNames": true,
    "isolatedModules": true,
    "jsx": "react",
    "lib": [
      "es6",
      "dom"
    ],
    "module": "commonjs",
    "moduleResolution": "node",
    "noFallthroughCasesInSwitch": true,
    "noImplicitAny": false,
    "noLib": false,
    "noUnusedLocals": false, // won't fail on unused variables
    "noUnusedParameters": false,
    "removeComments": true,
    "resolveJsonModule": true,
    "skipLibCheck": true,
    "strictNullChecks": true,
    "strictBindCallApply": true, // @see https://github.com/storybookjs/storybook/issues/11916
    "sourceMap": true,
    "strict": false,
    "target": "es6",
    "typeRoots": [
      "./types",
      "./node_modules/@types"
    ]
  },
  "exclude": [
    "node_modules",
    "**/*.d.ts",
    "**/dist/*",
    "**/webpack.config.js",
    // @see https://github.com/facebook/docusaurus/issues/3424
    "packages/docusaurus"
  ]
}
@sachinraja
Copy link
Contributor

tsup uses rollup-plugin-dts to bundle the dts files, which doesn't support generating declaration maps. You could run tsc onSuccess.

@eric-burel
Copy link
Contributor Author

Thanks for the tip with onSuccess. I've eventually disabled dts generation from Tsup and instead run tsc afterward: tsc --emitDeclarationOnly --declaration.
I'll close the issue since it's a minor use case, but at least Googlers can find it if needed.

github-merge-queue bot pushed a commit to proofcarryingdata/zupass that referenced this issue Dec 12, 2023
Since `tsup` [does not support declaration
maps](egoist/tsup#564) we have to use `tsc`
for this.

I've refactored the build commands a bit so that it's a bit easier to
see what is going on. Most packages now have two `build` commands,
`build:ts` and `build:types`. The first uses `tsup` to build the
TypeScript and bundle the resulting JS, and the second creates type
declarations and declaration maps. Some packages with separate node and
browser builds have three: instead of `build:ts` they have
`build:browser` and `build:node`, with `build:types` remaining the same.

I have also created `dev:*` equivalents of these build commands.
github-merge-queue bot pushed a commit to proofcarryingdata/zupass that referenced this issue Dec 12, 2023
Since `tsup` [does not support declaration
maps](egoist/tsup#564) we have to use `tsc`
for this.

I've refactored the build commands a bit so that it's a bit easier to
see what is going on. Most packages now have two `build` commands,
`build:ts` and `build:types`. The first uses `tsup` to build the
TypeScript and bundle the resulting JS, and the second creates type
declarations and declaration maps. Some packages with separate node and
browser builds have three: instead of `build:ts` they have
`build:browser` and `build:node`, with `build:types` remaining the same.

I have also created `dev:*` equivalents of these build commands.
mikoloism added a commit to wonize/biruni that referenced this issue Apr 27, 2024
remove `tsup.config.ts` file, instead
	add `build.ts` to `scripts/`
	do build with tsup programatic api (`build` function)
rename `scripts/release.ts` to `release-helper.ts`

change behavior of `dts` function
	replace tsup `dts` configuration with built-in handy `tsc` commandline
	issued in egoist/tsup#564 (comment)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants