johannschopplich / kirbyup

🆙 Official bundler for Kirby Panel plugins
https://kirbyup.getkirby.com
MIT License
51 stars 3 forks source link

Wrong types for `kirbyup.import()` #32

Closed arnoson closed 1 year ago

arnoson commented 1 year ago

Right now the import function has this signature:

import(modules: Record<string, Module>): Record<string, any>;

But the example suggest that using a blob-string instead of a modules record is possible. Which will result in typescript errors, or am I missing something (I guess the blob-string gets transformed into a record by vite)?

kirbyup.import('./components/blocks/*.vue')
johannschopplich commented 1 year ago

You guessed correctly, an internal Vite plugin will transform the following code in a first transformation step:

-kirbyup.import(<path>)
+kirbyup.import(import.meta.glob(<path>, { eager: true }))

Afterwards, Vite's glob import (transformation step 2) will handle resolving the JavaScript files.

The typings are technically correct, but not for the user, since won't see any of the transformations applied. We should improve the typings. Good catch.

arnoson commented 1 year ago

Wow, thanks for the quick fix!