Skip to content
This repository has been archived by the owner on Apr 6, 2023. It is now read-only.

fix(nuxt): handle schema types for relative module paths #7946

Merged
merged 1 commit into from
Oct 3, 2022

Conversation

danielroe
Copy link
Member

πŸ”— Linked issue

❓ Type of change

  • πŸ“– Documentation (updates to the documentation or readme)
  • 🐞 Bug fix (a non-breaking change that fixes an issue)
  • πŸ‘Œ Enhancement (improving an existing functionality like performance)
  • ✨ New feature (a non-breaking change that adds functionality)
  • ⚠️ Breaking change (fix or feature that would cause existing functionality to change)

πŸ“š Description

In the case where a module is specified with a relative path, it is not properly typed in schema.d.ts. For example:

export default defineNuxtConfig({
  modules: [
    '../src/module'
  ],
})

results in the following type:

declare module '@nuxt/schema' {
  interface NuxtConfig {
    ["metaKey"]?: typeof import("../src/module").default extends NuxtModule<infer O> ? Partial<O> : Record<string, any>
  }
}

But this relative import path either needs to be absolute or resolved relative to the generated schema.d.ts.

πŸ“ Checklist

  • I have linked an issue or discussion.
  • I have updated the documentation accordingly.

@danielroe danielroe added bug Something isn't working πŸ”¨ p3-minor-bug Priority 3: a bug in an edge case that only affects very specific usage labels Oct 1, 2022
@danielroe danielroe requested a review from pi0 October 1, 2022 12:35
@danielroe danielroe self-assigned this Oct 1, 2022
@codesandbox
Copy link

codesandbox bot commented Oct 1, 2022

CodeSandbox logoCodeSandbox logoΒ  Open in CodeSandbox Web Editor | VS Code | VS Code Insiders

@netlify
Copy link

netlify bot commented Oct 1, 2022

βœ… Deploy Preview for nuxt3-docs canceled.

Name Link
πŸ”¨ Latest commit afa2e34
πŸ” Latest deploy log https://app.netlify.com/sites/nuxt3-docs/deploys/633834149688400010d033cd

Copy link
Member

@atinux atinux left a comment

Choose a reason for hiding this comment

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

LGTM

@atinux atinux merged commit 4823b17 into main Oct 3, 2022
@atinux atinux deleted the fix/relative-modules branch October 3, 2022 13:32
@danielroe danielroe mentioned this pull request Oct 9, 2022
return [
"import { NuxtModule } from '@nuxt/schema'",
"declare module '@nuxt/schema' {",
' interface NuxtConfig {',
...moduleInfo.filter(Boolean).map(meta =>
` [${genString(meta.configKey)}]?: typeof ${genDynamicImport(meta.importName, { wrapper: false })}.default extends NuxtModule<infer O> ? Partial<O> : Record<string, any>`
` [${genString(meta.configKey)}]?: typeof ${genDynamicImport(meta.importName.startsWith('.') ? './' + join(relativeRoot, meta.importName) : meta.importName, { wrapper: false })}.default extends NuxtModule<infer O> ? Partial<O> : Record<string, any>`
Copy link
Member

Choose a reason for hiding this comment

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

Have you tested if it also works with extends layers that have different relative root?

Copy link
Member Author

Choose a reason for hiding this comment

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

Could you explain more? If an extends layer adds a module with a relative path I suspect it wouldn't work at all, quite apart from this PR.

@danielroe danielroe added the 3.x label Jan 19, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
3.x bug Something isn't working πŸ”¨ p3-minor-bug Priority 3: a bug in an edge case that only affects very specific usage
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants