npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

tsc-dts-fix

v0.1.19

Published

Applies some fixes to libdefs produced with tsc

Downloads

319

Readme

tsc-dts-fix

Applies some fixes to libdefs (d.ts) produced with tsc

lcov npm

Problem

Despite the fact that TS is actively developed, there are still a number of problems with its tsc compiler. In some situations, generated bundles require modification to work correctly in runtime. Other issues affect typings. This library is aimed to provide a workaroud for couple of them:

  1. Extra extensions in modules declarations force dependent projects to partially inherit tsconfig rules.

coderef-1

// a.ts
export * from './b.ts'
// b.ts
export const b = 'b'
// index.ts
export * from './a.ts'
tsc --emitDeclarationOnly --allowImportingTsExtensions

gives several dts:

// a.d.ts
export * from './b.ts'
// b.d.ts
export const b = 'b'
// index.d.ts
export * from './a.ts'

Meanwhile, coderef-2

export * from 'allow-ts-ext'
tsc --emitDeclarationOnly

1:15 - error TS5097: An import path can only end with a '.ts' extension when 'allowImportingTsExtensions' is enabled.
1 export * from './a.ts'
                ~~~~~~~~
Found 2 errors in 2 files.
Errors  Files
     1  ../allow-ts-ext/a.ts:1
     1  ../allow-ts-ext/index.ts:1
  1. Merging dts may cause name conflicts between local and external modules.
  • https://github.com/microsoft/TypeScript/issues/4433
  • https://stackoverflow.com/questions/75608981/get-rid-of-folder-prefix-in-declare-module-typescript-type-files

coderef

// depseek.ts
export const foo = 'bar'

// index.ts
export {foo} from './depseek'
export {depseek} from 'depseek'
tsc --emitDeclarationOnly --declaration --outFile index.d.ts

gives:

declare module "index" {
  export {foo} from "depseek";
  export {depseek} from "depseek";
}

Solution

While the dts-bundle-generator and dts-bundle projects are focused on deep restructuring of declarations, I would still like to keep tsc as libdefs producer and assist it make some minor adjustments to module paths resolution:

  • fix relative paths
  • remap extensions
  • explicitly declare pkg entrypoints

Status

Working draft

Install

yarn add tsc-dts-fix -D

Usage

JS API

import {generateDts} from 'tsc-dts-fix'

const declarations = generateDts({
  input: 'index.ts',      // Compilation entrypoint: string | string[]
  compilerOptions: {},    // Standard ts.CompilerOptions,
  strategy: 'separate',   // Generator strategy:
                          //   'separate' – formats libdefs as separate files,
                          //   'bundle' – uses tsc to produce single dts file via `outFile` param,
                          //   'merge' – assembles separate dts chunks into single file.
  ext: '',                // Extension to remap, for ex '.js', '.cjs'.
                          // Default is '' which means to remove any existent. If `undefined`, no effect
  pkgName: 'pkg-name',    // Package name to prepend to module declarations.
  entryPoints: {
    '.': 'index.ts',      // Entry points map.
    '/cli': 'cli.ts'
  },
  conceal: true           // Restrict access to internal modules (technically replaces their names with randoms).
})

CLI

tsc-dts-fix --strategy='merge' --pkg-name='@foo/bar'

Alternatives

License

MIT