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

emitted dts is bundled source #509

Closed
sachinraja opened this issue Dec 24, 2021 · 6 comments
Closed

emitted dts is bundled source #509

sachinraja opened this issue Dec 24, 2021 · 6 comments

Comments

@sachinraja
Copy link
Contributor

sachinraja commented Dec 24, 2021

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
}
@egoist
Copy link
Owner

egoist commented Dec 24, 2021

can't reproduce it 🤔

@sachinraja
Copy link
Contributor Author

sachinraja commented Dec 24, 2021

Looks like it might have been a pnpm error? I ran pnpm install --force to reverify and relink the packages and it seems to work now.

I cannot reproduce it in another folder (even when I clone the same repo), so I'm not sure what the issue is.

@sachinraja
Copy link
Contributor Author

Not able to reproduce so I'll close this.

@sachinraja
Copy link
Contributor Author

sachinraja commented Dec 24, 2021

Ah ok, I figured this out. It happens when "noEmit": true is set in tsconfig.json. Here's a repro: https://github.com/sachinraja/tsup-dts-repro.

@sachinraja sachinraja reopened this Dec 24, 2021
egoist added a commit that referenced this issue Dec 25, 2021
@egoist
Copy link
Owner

egoist commented Dec 25, 2021

should be fixed in v5.11.9

@egoist egoist closed this as completed Dec 25, 2021
@Kiyozz
Copy link

Kiyozz commented 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', ...?

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

No branches or pull requests

3 participants