Skip to content

[Feature]: Imports/exports of generated DTS don't have file extensions #1052

@charpeni

Description

@charpeni

What problem does this feature solve?

I've been trying to migrate away from tsup in favor of rslib because I've been enjoying y'all's work, unfortunately, and I can't figure out how to finalize that migration without this feature.

I want to dual-publish (CJS/ESM) using the following configuration:

import { defineConfig } from '@rslib/core';

export default defineConfig({
  lib: [
    {
      format: 'esm',
      bundle: false,
      dts: {
        autoExtension: true,
      },
    },
    {
      format: 'cjs',
      bundle: false,
      dts: true,
    },
  ],
  source: {
    entry: {
      index: ['./src/**', '!src/**/__tests__/**'],
    },
  },
  output: {
    target: 'web',
    cleanDistPath: true,
    distPath: {
      root: './lib',
    },
  },
});

It is almost working, I had to tweak one lib to use dts: { autoExtension: true }, otherwise it was just overwriting the other one and generating only one set of DTS.

But then, both generated DTS aren't using extensions in their imports/exports, which is causing errors with @arethetypeswrong/cli as it expects an explicit extension matching our other files (.js and .mts in our case):

"problems": [
      {
        "kind": "InternalResolutionError",
        "resolutionOption": "node16",
        "fileName": "/node_modules/@shortcut/client/lib/index.d.mts",
        "moduleSpecifier": "./ShortcutClient",
        "pos": 41,
        "end": 60,
        "resolutionMode": 99,
        "trace": [
          "======== Resolving module './ShortcutClient' from '/node_modules/@shortcut/client/lib/index.d.mts'. ========",
          "Explicitly specified module resolution kind: 'Node16'.",
          "Resolving in ESM mode with conditions 'import', 'types', 'node'.",
          "Loading module as file / folder, candidate module location '/node_modules/@shortcut/client/lib/ShortcutClient', target file types: TypeScript, JavaScript, Declaration, JSON.",
          "Directory '/node_modules/@shortcut/client/lib/ShortcutClient' does not exist, skipping all lookups in it.",
          "======== Module name './ShortcutClient' was not resolved. ========"
        ]
      },
  ...

What does the proposed API look like?

I'm not sure exactly if it should be working out-of-the-box, I assumed so since other tools are doing it? So, is it a feature request or a bug report. 🤔

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions