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

Missing definition files in dist folder #184

Closed
3 tasks done
frank-weindel opened this issue Feb 28, 2023 · 3 comments
Closed
3 tasks done

Missing definition files in dist folder #184

frank-weindel opened this issue Feb 28, 2023 · 3 comments
Labels
bug Something isn't working

Comments

@frank-weindel
Copy link

frank-weindel commented Feb 28, 2023

Describe the bug

I have some manual d.ts definition files that import some other manual d.ts files that do not have corresponding .js code files. Specifically in my reproduction below I have these files in my src directory:

src
├── types   <------ NONE OF THE FILES IN THIS DIRECTORY ARE COPIED TO `dist`
│   ├── README.md
│   ├── lng.components.namespace.d.ts
│   ├── lng.d.ts
│   ├── lng.shaders.c2d.namespace.d.ts
│   ├── lng.shaders.namespace.d.ts
│   ├── lng.textures.namespace.d.ts
│   ├── lng.tools.namespace.d.ts
│   └── lng.types.namespace.d.ts
├── internalTypes.d.mts <------ ALSO MISSING
├── commonTypes.d.mts <------ ALSO MISSING
├── lightning.d.mts
├── lightning.mjs
└── ...

src/lightning.d.mts

// ...
import * as lng from "./types/lng"; // <----- This `d.ts` file and the files it depends on are not copied over to `dist`

/**
 * This seeming nonsense helps us export all the types with the same names/structure as
 * their runtime counterparts.
 */
declare namespace lng_ {
  export import lng_ = lng;
}

export default lng_.lng_;

src/types/lng.d.ts

// ...
import * as shaders from './lng.shaders.namespace';
import * as textures from './lng.textures.namespace';
import * as components from './lng.components.namespace';
import * as tools from './lng.tools.namespace';
import * as types from './lng.types.namespace';
// ^ ----- None of these are copied over either

export {
  Application,
  Component,
  Base,
  Utils,
  StageUtils,
  Element,
  Tools,
  Stage,
  ElementCore,
  ElementTexturizer,
  Texture,
  EventEmitter,
  shaders,
  textures,
  components,
  tools
};

// `types` has to be exported as type so TS/IDEs don't allow you access it from runtime context
export type {
  types
};

As mentioned in the comments of the code above, none of the files in the src/types directory are copied over to dist. Which causes TypeScript to throw errors because of missing dependencies in any application that uses this library as a dependency.

dist
├── index.d.ts <--- Definition file copied over by vite-plugin-dts
├── ...
└── src <--- Definition files copied over by vite-plugin-dts
    ├── EventEmitter.d.mts
    ├── EventEmitter.d.mts.map
    ├── animation
    ├── application
    ├── components
    ├── flex
    ├── lightning.d.mts
    ├── lightning.d.mts.map
    ├── platforms
    ├── renderer
    ├── textures
    ├── tools
    └── tree
                ^----------- Note how the `types` directory is completely missing.
                             As well as `internalTypes.d.mts`/`commonTypes.d.mts`

I believe in 2174868 (prompted by #178) is where you added the copying of manual .d.ts files.

Thanks!

Reproduction

https://stackblitz.com/~/github.com/frank-weindel/lightning/tree/vite-plugin-dts-bug-3

Steps to reproduce

  1. npm install
  2. npm run build:lightning

System Info

System:
    OS: macOS 12.2.1
  Binaries:
    Node: 16.14.0 - ~/.nodenv/versions/16.14.0/bin/node
    npm: 8.3.1 - ~/.nodenv/versions/16.14.0/bin/npm
  npmPackages:
    @vitejs/plugin-legacy: ^3.0.1 => 3.0.1 
    vite: ^4.0.4 => 4.0.4 
    vite-plugin-dts: ^2.0.2 => 2.0.2

Validations

@saurabhnemade
Copy link

I also observed similar issue. may be that one is also connected to this issue.

Here is how it looks on my end:

config on vite.config

  plugins: [
    react(),
    dts({
      insertTypesEntry: false
    })
  ],

Files generated after first run (no previous build present):
Screenshot 2023-06-03 at 17 10 24

Files generated after second run (previous build present):

Screenshot 2023-06-03 at 17 11 17

@saurabhnemade
Copy link

For me downgrading to "vite-plugin-dts": "1.7.3", resolved the issue.

@qmhc qmhc added the bug Something isn't working label Jun 30, 2023
@qmhc qmhc closed this as completed in 5b7c5e5 Jun 30, 2023
@qmhc
Copy link
Owner

qmhc commented Jun 30, 2023

Fixed in 3.0.1. You need to specify copyDtsFiles: true.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants