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

feat(kit): provide type support for module options in installModule #26744

Open
wants to merge 9 commits into
base: main
Choose a base branch
from

Conversation

ineshbose
Copy link
Member

@ineshbose ineshbose commented Apr 11, 2024

🔗 Linked issue

📚 Description

These changes relies and builds on top of #18416 (my first PR on Nuxt 😄); it extracts the options from there after module authors run prepare.

Try this in the repo playground:

import { installModule } from "@nuxt/kit";

installModule('@nuxt/devtools', { customTabs: [] })

Copy link

stackblitz bot commented Apr 11, 2024

Review PR in StackBlitz Codeflow Run & review this pull request in StackBlitz Codeflow.

@danielroe danielroe changed the title chore(kit): provide type support for module options in installModule feat(kit): provide type support for module options in installModule Apr 12, 2024
@@ -41,6 +41,15 @@ export default defineNuxtConfig({
filename: 'test.d.ts',
getContents: () => 'declare type Fromage = "cheese"',
})
function _test () {
installModule('~/modules/example', {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this doesn't seem to be picking up because .nuxt/types/schema.d.ts now seems to be using resolved paths, i.e.

declare module 'nuxt/schema' {
  interface NuxtConfig {
    modules?: (["/home/nuxt/nuxt/test/fixtures/basic-types/modules/example", Exclude<NuxtConfig["sampleModule"], boolean>] | ["@nuxt/devtools", Exclude<NuxtConfig["devtools"], boolean>])[],
  }
}

so where T = '~/modules/example', it is not equal to /home/nuxt/nuxt/test/fixtures/basic-types/modules/example; so this will work for package names more than local modules, sure, but I'm not sure how the usage ahead of ['~/modules/example, { typeTest: () {} }] worked even when the path isn't same 🤔

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but I'm not sure how the usage ahead of ['~/modules/example, { typeTest: () {} }] worked even when the path isn't same

it's likely that its just the TypeScript is quite relaxed with all the union options.

Copy link
Member Author

@ineshbose ineshbose Apr 13, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it should work now; also note that (as I had thought), we're doing a dynamic import of NuxtConfig within types (edit: CI still failing... hmm)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like the dynamic import https://github.com/nuxt/nuxt/pull/26744/files#diff-84e752bfeb5965269318fc84ddc24d24fa76cdca52fcc7d4e61f9ea5e7efae21R17 ends up using NuxtConfig from @nuxt/schema instead of nuxt/schema after build, but nuxt/schema is augmented by the generated types https://github.com/nuxt/nuxt/pull/26744/files#diff-2176c7ab69dcd5ffc94e79963693b007471788f25591aeb72e7533240ebad2c2R168.

If you use a type import instead of the dynamic import and set nuxt/schema as external it seems to work as expected, but I have no idea if this has other unintended results.

I couldn't open a PR on your branch for some reason so you can check out my changes in this commit instead BobbieGoede/nuxt@f1ba5e1 (#5).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're absolutely amazing ❤️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants