question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

emitted dts is bundled source

See original GitHub issue

This is only an issue on v5.11.8. src/index.ts:

const message = 'Hello World'

export const main = () => {
  console.log(message)
}

main()

dist/index.d.ts:

const message = 'Hello World!';

const main = () => {
  console.log(message);
};

main();

export { main };

expected dist/index.d.ts (emitted on v5.11.7):

declare const main: () => void;

export { main };

tsup config:

{
    "entry": ["src/index.ts"],
    "format": ["esm"],
    "dts": true
}

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:6 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
egoistcommented, Dec 25, 2021

should be fixed in v5.11.9

0reactions
Kiyozzcommented, Dec 30, 2021

I got something different.

"tsup": "^5.11.9"

tsc’s dts is not the same as what tsup is emitting (noEmit: false or true, bundle: false)

Source

packages/electron-esbuild/src/config/config.ts (may not be up to date with my local version)

/*
* Copyright (c) 2021 Kiyozz.
*
* All rights reserved.
*/

import { BuildOptions } from 'esbuild'
import { InlineConfig } from 'vite'
import { Configuration } from 'webpack'

import { Builder } from '../builder'
import { EsbuildBuilder } from '../builder/esbuild.builder'
import { ViteBuilder } from '../builder/vite.builder'
import { WebpackBuilder } from '../builder/webpack.builder'
import { unsupportedType } from '../console'
import { Configurator } from './configurators/base.configurator'
import { EsbuildConfigurator } from './configurators/esbuild.configurator'
import { ViteConfigurator } from './configurators/vite.configurator'
import { WebpackConfigurator } from './configurators/webpack.configurator'
import { Target, TypeConfig } from './enums'
import { PossibleConfiguration } from './types'
import { YamlItem } from './yaml'

export class EnvConfig {
readonly type: TypeConfig
readonly path: string
readonly src: string
readonly output: string
readonly html?: string

constructor({
  type,
  path,
  src,
  output,
  html,
}: {
  type: TypeConfig
  path: string
  src: string
  output: string
  html?: string
}) {
  this.type = type
  this.path = path
  this.src = src
  this.output = output
  this.html = html
}

static fromYaml(yaml: YamlItem): EnvConfig {
  return new this({
    type: yaml.type,
    path: yaml.path,
    src: yaml.src,
    output: yaml.output,
    html: yaml.html,
  })
}

toConfigurator(): Configurator<TypeConfig> {
  switch (this.type) {
    case TypeConfig.esbuild:
      return new EsbuildConfigurator(this)
    case TypeConfig.webpack:
      return new WebpackConfigurator(this)
    case TypeConfig.vite:
      return new ViteConfigurator(this)
    default:
      unsupportedType(this.type)
  }
}
}

export class Item<
T extends PossibleConfiguration | null = PossibleConfiguration,
F extends EnvConfig | null = EnvConfig | null,
> {
readonly config: T
readonly fileConfig: F
readonly target: Target
readonly isVite: boolean
readonly isWebpack: boolean
readonly isEsbuild: boolean
readonly isMain: boolean
readonly isRenderer: boolean

constructor({
  config,
  fileConfig,
  target,
}: {
  config: T
  fileConfig: F
  target: Target
}) {
  this.config = config
  this.fileConfig = fileConfig
  this.target = target
  this.isVite = this.fileConfig?.type === TypeConfig.vite
  this.isWebpack = this.fileConfig?.type === TypeConfig.webpack
  this.isEsbuild = this.fileConfig?.type === TypeConfig.esbuild
  this.isMain = this.target === Target.main
  this.isRenderer = this.target === Target.renderer
}

toBuilder(): Builder | null {
  if (this.isEsbuild) {
    return new EsbuildBuilder(this as Item<BuildOptions>)
  } else if (this.isWebpack) {
    return new WebpackBuilder(this as Item<Configuration>)
  } else if (this.isVite) {
    return new ViteBuilder(this as Item<InlineConfig>)
  }

  if (this.fileConfig !== null) {
    unsupportedType(this.fileConfig.type, this.isMain ? 'main' : 'renderer')
  }

  return null
}
}

export class Config<
M extends PossibleConfiguration,
R extends PossibleConfiguration,
> {
readonly main: Item<M, EnvConfig>
readonly renderer: Item<R | null>

constructor({
  main,
  renderer,
}: {
  main: Item<M, EnvConfig>
  renderer: Item<R | null>
}) {
  this.main = main
  this.renderer = renderer
}

toBuilders(): readonly [Builder, Builder | null] {
  return [this.main.toBuilder() as Builder, this.renderer.toBuilder()]
}
}
tsup's dts
import '../builder';
export { C as Config, E as EnvConfig, I as Item } from '../config-57276ad7';
import './enums';
import './types';
import 'esbuild';
import 'vite';
import 'webpack';

config-57276ad7.d.ts

import { Builder } from './builder';
import { TypeConfig, Target } from './config/enums';
import { ConfigMapping, PossibleConfiguration } from './config/types';

interface Configurator<P extends TypeConfig> {
    readonly type: TypeConfig;
    readonly config: EnvConfig;
    toBuilderConfig(partial: Partial<ConfigMapping[P]>, config: ConfigMapping[P], target: Target): ConfigMapping[P];
}

declare type YamlItem = {
    type: TypeConfig;
    path: string;
    src: string;
    output: string;
    html?: string;
};
declare type YamlSkeleton = {
    mainConfig: YamlItem;
    rendererConfig: YamlItem | null;
};
declare class Yaml {
    readonly main: EnvConfig;
    readonly renderer: EnvConfig | null;
    constructor({ main, renderer, }: {
        main: EnvConfig;
        renderer: EnvConfig | null;
    });
}

declare class EnvConfig {
    readonly type: TypeConfig;
    readonly path: string;
    readonly src: string;
    readonly output: string;
    readonly html?: string;
    constructor({ type, path, src, output, html, }: {
        type: TypeConfig;
        path: string;
        src: string;
        output: string;
        html?: string;
    });
    static fromYaml(yaml: YamlItem): EnvConfig;
    toConfigurator(): Configurator<TypeConfig>;
}
declare class Item<T extends PossibleConfiguration | null = PossibleConfiguration, F extends EnvConfig | null = EnvConfig | null> {
    readonly config: T;
    readonly fileConfig: F;
    readonly target: Target;
    readonly isVite: boolean;
    readonly isWebpack: boolean;
    readonly isEsbuild: boolean;
    readonly isMain: boolean;
    readonly isRenderer: boolean;
    constructor({ config, fileConfig, target, }: {
        config: T;
        fileConfig: F;
        target: Target;
    });
    toBuilder(): Builder | null;
}
declare class Config<M extends PossibleConfiguration, R extends PossibleConfiguration> {
    readonly main: Item<M, EnvConfig>;
    readonly renderer: Item<R | null>;
    constructor({ main, renderer, }: {
        main: Item<M, EnvConfig>;
        renderer: Item<R | null>;
    });
    toBuilders(): readonly [Builder, Builder | null];
}

export { Config as C, EnvConfig as E, Item as I, Yaml as Y, Configurator as a, YamlSkeleton as b, YamlItem as c };
tsc's dts
import { Builder } from '../builder';
import { Configurator } from './configurators/base.configurator';
import { Target, TypeConfig } from './enums';
import { PossibleConfiguration } from './types';
import { YamlItem } from './yaml';
export declare class EnvConfig {
  readonly type: TypeConfig;
  readonly path: string;
  readonly src: string;
  readonly output: string;
  readonly html?: string;
  constructor({ type, path, src, output, html, }: {
      type: TypeConfig;
      path: string;
      src: string;
      output: string;
      html?: string;
  });
  static fromYaml(yaml: YamlItem): EnvConfig;
  toConfigurator(): Configurator<TypeConfig>;
}
export declare class Item<T extends PossibleConfiguration | null = PossibleConfiguration, F extends EnvConfig | null = EnvConfig | null> {
  readonly config: T;
  readonly fileConfig: F;
  readonly target: Target;
  readonly isVite: boolean;
  readonly isWebpack: boolean;
  readonly isEsbuild: boolean;
  readonly isMain: boolean;
  readonly isRenderer: boolean;
  constructor({ config, fileConfig, target, }: {
      config: T;
      fileConfig: F;
      target: Target;
  });
  toBuilder(): Builder | null;
}
export declare class Config<M extends PossibleConfiguration, R extends PossibleConfiguration> {
  readonly main: Item<M, EnvConfig>;
  readonly renderer: Item<R | null>;
  constructor({ main, renderer, }: {
      main: Item<M, EnvConfig>;
      renderer: Item<R | null>;
  });
  toBuilders(): readonly [Builder, Builder | null];
}

Why tsup emit a config-5727ad8.d.ts file (splitting: true or false)? Why import 'vite', import 'webpack', …?

Read more comments on GitHub >

github_iconTop Results From Across the Web

TypeStrong/dts-bundle: Export TypeScript .d.ts files ... - GitHub
This module is a naïve string-based approach at generating bundles from the .d.ts declaration files generated by a TypeScript compiler.
Read more >
dts-bundle-webpack | Yarn - Package Manager
This is wrapper for dts-bundle plugin to use inside WebPack build. Generates bundle from the .d.ts declaration files generated by a TypeSript compiler....
Read more >
tsup
Bundle your TypeScript library with no config, powered by esbuild. What can it bundle? Anything that's supported by Node.js natively, ...
Read more >
Documentation - tsc CLI Options - TypeScript
Flag Type Default ‑‑allowJs boolean false ‑‑allowUmdGlobalAccess boolean false ‑‑allowUnreachableCode boolean
Read more >
How to merge d.ts typings with dts-bundle and Webpack
It will create one file per .ts source, but we need one file. Here's dts-bundle join the game. Install it first from npm...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found