Skip to content

Commit

Permalink
fix: /utils and /kit subpath exports
Browse files Browse the repository at this point in the history
  • Loading branch information
harlan-zw committed Nov 24, 2024
1 parent 4e7c741 commit b9dd1cc
Show file tree
Hide file tree
Showing 8 changed files with 47 additions and 32 deletions.
3 changes: 2 additions & 1 deletion build.config.ts → packages/module/build.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ import { defineBuildConfig } from 'unbuild'
export default defineBuildConfig({
declaration: true,
entries: [
{ input: 'src/kit/index', name: 'kit' },
{ input: 'src/kit', name: 'kit' },
{ input: 'src/utils', name: 'utils' },
],
externals: [
'#imports',
Expand Down
1 change: 1 addition & 0 deletions packages/module/kit.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './dist/kit'
12 changes: 11 additions & 1 deletion packages/module/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,22 @@
"types": "./dist/types.d.ts",
"import": "./dist/module.mjs",
"require": "./dist/module.cjs"
},
"./kit": {
"types": "./dist/kit.d.ts",
"import": "./dist/kit.mjs"
},
"./utils": {
"types": "./dist/utils.d.ts",
"import": "./dist/utils.mjs"
}
},
"main": "./dist/module.cjs",
"types": "./dist/types.d.ts",
"files": [
"dist"
"dist",
"kit.d.ts",
"utils.d.ts"
],
"scripts": {
"build": "nuxt-module-build build --stub && nuxt-module-build prepare && nuxt-module-build build",
Expand Down
30 changes: 1 addition & 29 deletions packages/module/src/kit.ts
Original file line number Diff line number Diff line change
@@ -1,29 +1 @@
import { addTemplate, createResolver, useNuxt } from '@nuxt/kit'
import { relative } from 'pathe'

export function extendTypes(module: string, template: (options: { typesPath: string }) => string | Promise<string>) {
const nuxt = useNuxt()
const { resolve } = createResolver(import.meta.url)
// paths.d.ts
addTemplate({
filename: `module/${module}.d.ts`,
getContents: async () => {
const typesPath = relative(resolve(nuxt!.options.rootDir, nuxt!.options.buildDir, 'module'), resolve('runtime/types'))
const s = await template({ typesPath })
return `// Generated by ${module}
${s}
export {}
`
},
})

nuxt.hooks.hook('prepare:types', ({ references }) => {
references.push({ path: resolve(nuxt.options.buildDir, `module/${module}.d.ts`) })
})
nuxt.hooks.hook('nitro:config', (config) => {
config.typescript = config.typescript || {}
config.typescript.tsConfig = config.typescript.tsConfig || {}
config.typescript.tsConfig.include = config.typescript.tsConfig.include || []
config.typescript.tsConfig.include.push(`./module/${module}.d.ts`)
})
}
export * from 'nuxt-site-config-kit'
2 changes: 1 addition & 1 deletion packages/module/src/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { getSiteConfigStack, initSiteConfig, updateSiteConfig } from 'nuxt-site-
import { readPackageJSON } from 'pkg-types'
import { validateSiteConfigStack } from 'site-config-stack'
import { setupDevToolsUI } from './devtools'
import { extendTypes } from './kit'
import { extendTypes } from './nuxt-kit'

export interface ModuleOptions extends SiteConfigInput {
componentOptions?: {
Expand Down
29 changes: 29 additions & 0 deletions packages/module/src/nuxt-kit.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { addTemplate, createResolver, useNuxt } from '@nuxt/kit'
import { relative } from 'pathe'

export function extendTypes(module: string, template: (options: { typesPath: string }) => string | Promise<string>) {
const nuxt = useNuxt()
const { resolve } = createResolver(import.meta.url)
// paths.d.ts
addTemplate({
filename: `module/${module}.d.ts`,
getContents: async () => {
const typesPath = relative(resolve(nuxt!.options.rootDir, nuxt!.options.buildDir, 'module'), resolve('runtime/types'))
const s = await template({ typesPath })
return `// Generated by ${module}
${s}
export {}
`
},
})

nuxt.hooks.hook('prepare:types', ({ references }) => {
references.push({ path: resolve(nuxt.options.buildDir, `module/${module}.d.ts`) })
})
nuxt.hooks.hook('nitro:config', (config) => {
config.typescript = config.typescript || {}
config.typescript.tsConfig = config.typescript.tsConfig || {}
config.typescript.tsConfig.include = config.typescript.tsConfig.include || []
config.typescript.tsConfig.include.push(`./module/${module}.d.ts`)
})
}
1 change: 1 addition & 0 deletions packages/module/src/utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from 'site-config-stack'
1 change: 1 addition & 0 deletions packages/module/utils.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './dist/utils'

0 comments on commit b9dd1cc

Please sign in to comment.