mirror of
https://github.com/nuxt/nuxt.git
synced 2025-01-30 23:32:38 +00:00
fix(kit): reorder #build
to the end of tsConfig
paths (#30520)
This commit is contained in:
parent
654f6c644b
commit
0c1f9438bc
@ -291,6 +291,10 @@ export async function _generateTypes (nuxt: Nuxt) {
|
|||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Ensure `#build` is placed at the end of the paths object.
|
||||||
|
// https://github.com/nuxt/nuxt/issues/30325
|
||||||
|
sortTsPaths(tsConfig.compilerOptions.paths)
|
||||||
|
|
||||||
tsConfig.include = [...new Set(tsConfig.include.map(p => isAbsolute(p) ? relativeWithDot(nuxt.options.buildDir, p) : p))]
|
tsConfig.include = [...new Set(tsConfig.include.map(p => isAbsolute(p) ? relativeWithDot(nuxt.options.buildDir, p) : p))]
|
||||||
tsConfig.exclude = [...new Set(tsConfig.exclude!.map(p => isAbsolute(p) ? relativeWithDot(nuxt.options.buildDir, p) : p))]
|
tsConfig.exclude = [...new Set(tsConfig.exclude!.map(p => isAbsolute(p) ? relativeWithDot(nuxt.options.buildDir, p) : p))]
|
||||||
|
|
||||||
@ -335,6 +339,17 @@ export async function writeTypes (nuxt: Nuxt) {
|
|||||||
await writeFile()
|
await writeFile()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function sortTsPaths (paths: Record<string, string[]>) {
|
||||||
|
for (const pathKey in paths) {
|
||||||
|
if (pathKey.startsWith('#build')) {
|
||||||
|
const pathValue = paths[pathKey]!
|
||||||
|
// Delete & Reassign to ensure key is inserted at the end of object.
|
||||||
|
delete paths[pathKey]
|
||||||
|
paths[pathKey] = pathValue
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function renderAttrs (obj: Record<string, string>) {
|
function renderAttrs (obj: Record<string, string>) {
|
||||||
const attrs: string[] = []
|
const attrs: string[] = []
|
||||||
for (const key in obj) {
|
for (const key in obj) {
|
||||||
|
@ -59,4 +59,42 @@ describe('tsConfig generation', () => {
|
|||||||
]
|
]
|
||||||
`)
|
`)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it('should add #build after #components to paths', async () => {
|
||||||
|
const { tsConfig } = await _generateTypes(mockNuxtWithOptions({
|
||||||
|
alias: {
|
||||||
|
'~': '/my-app',
|
||||||
|
'@': '/my-app',
|
||||||
|
'some-custom-alias': '/my-app/some-alias',
|
||||||
|
'#build': './build-dir',
|
||||||
|
'#build/*': './build-dir/*',
|
||||||
|
'#imports': './imports',
|
||||||
|
'#components': './components',
|
||||||
|
},
|
||||||
|
}))
|
||||||
|
|
||||||
|
expect(tsConfig.compilerOptions?.paths).toMatchObject({
|
||||||
|
'~': [
|
||||||
|
'..',
|
||||||
|
],
|
||||||
|
'some-custom-alias': [
|
||||||
|
'../some-alias',
|
||||||
|
],
|
||||||
|
'@': [
|
||||||
|
'..',
|
||||||
|
],
|
||||||
|
'#imports': [
|
||||||
|
'./imports',
|
||||||
|
],
|
||||||
|
'#components': [
|
||||||
|
'./components',
|
||||||
|
],
|
||||||
|
'#build': [
|
||||||
|
'./build-dir',
|
||||||
|
],
|
||||||
|
'#build/*': [
|
||||||
|
'./build-dir/*',
|
||||||
|
],
|
||||||
|
})
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
Loading…
Reference in New Issue
Block a user