nuxt / module-builder

Complete solution to build and ship Nuxt modules.
MIT License
213 stars 23 forks source link

Type generation is broken for subfolders (subfolder is imported with .js extension) #308

Open madskronborg opened 1 week ago

madskronborg commented 1 week ago

Reproduction

Stackblitz

Build command: cd ~/projects/vitejs-vite-tu4fsx/my-module/ && npm run dev:build && npm run prepack

Describe the bug

After upgrading from 0.5.5 to 0.8.0 the generated bundle has invalid import paths for types that exist in subfolders.

We have e.g. the following structure in our nuxt module runtime/ folder:

src/
  runtime/
    types/
      index.ts (export * from './components')
      components/
        index.ts (export * from './Alert')
        Alert.ts

Which results in the following build:

dist/
  runtime/
    types/
      index.d.ts (export * from './components.js')
      components/
        index.d.ts (export * from './Alert.js')
        Alert.d.ts
        Alert.js

Where the path ./components.js is invalid. It should be: ./components. I am also unsure whether components/index.d.ts in the build should export ./Alert.js or Alert.d.ts.

danielroe commented 1 week ago

I'll fix this, but you should probably do from './components/index' anyway. (And this should probably resolve the issue for now.)

madskronborg commented 6 days ago

I'll fix this, but you should probably do from './components/index' anyway. (And this should probably resolve the issue for now.)

Thank you for the quick reply and the great work on nuxt! :)

I hadn't thought about referencing the index file directly - I tested it and it does indeed fix the type referencing.

Appreciate the help :+1: