mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-11 08:33:53 +00:00
feat(nuxt): scan composables with star export (#19249)
This commit is contained in:
parent
5cfd835163
commit
59918f569e
@ -5,6 +5,7 @@
|
|||||||
<p>Named export <code>useC</code> : {{ c }}</p>
|
<p>Named export <code>useC</code> : {{ c }}</p>
|
||||||
<p>Named export <code>useD</code> : {{ d }}</p>
|
<p>Named export <code>useD</code> : {{ d }}</p>
|
||||||
<p>Default export <code>useFoo</code> : {{ foo }}</p>
|
<p>Default export <code>useFoo</code> : {{ foo }}</p>
|
||||||
|
<p>Star export <code>useNestedBar</code> : {{ bar }}</p>
|
||||||
</NuxtExampleLayout>
|
</NuxtExampleLayout>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
@ -14,4 +15,5 @@ const b = useB()
|
|||||||
const c = useC()
|
const c = useC()
|
||||||
const d = useD()
|
const d = useD()
|
||||||
const foo = useFoo()
|
const foo = useFoo()
|
||||||
|
const bar = useNestedBar()
|
||||||
</script>
|
</script>
|
||||||
|
@ -29,7 +29,7 @@
|
|||||||
"scule": "^1.0.0",
|
"scule": "^1.0.0",
|
||||||
"semver": "^7.3.8",
|
"semver": "^7.3.8",
|
||||||
"unctx": "^2.1.2",
|
"unctx": "^2.1.2",
|
||||||
"unimport": "^2.2.4",
|
"unimport": "^3.0.2",
|
||||||
"untyped": "^1.2.2"
|
"untyped": "^1.2.2"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
@ -78,7 +78,7 @@
|
|||||||
"unctx": "^2.1.2",
|
"unctx": "^2.1.2",
|
||||||
"unenv": "^1.2.1",
|
"unenv": "^1.2.1",
|
||||||
"unhead": "^1.1.14",
|
"unhead": "^1.1.14",
|
||||||
"unimport": "^2.2.4",
|
"unimport": "^3.0.2",
|
||||||
"unplugin": "^1.1.0",
|
"unplugin": "^1.1.0",
|
||||||
"untyped": "^1.2.2",
|
"untyped": "^1.2.2",
|
||||||
"vue": "^3.2.47",
|
"vue": "^3.2.47",
|
||||||
|
@ -35,7 +35,7 @@
|
|||||||
"scule": "^1.0.0",
|
"scule": "^1.0.0",
|
||||||
"std-env": "^3.3.2",
|
"std-env": "^3.3.2",
|
||||||
"ufo": "^1.1.1",
|
"ufo": "^1.1.1",
|
||||||
"unimport": "^2.2.4",
|
"unimport": "^3.0.2",
|
||||||
"untyped": "^1.2.2"
|
"untyped": "^1.2.2"
|
||||||
},
|
},
|
||||||
"engines": {
|
"engines": {
|
||||||
|
@ -319,7 +319,7 @@ importers:
|
|||||||
semver: ^7.3.8
|
semver: ^7.3.8
|
||||||
unbuild: ^1.1.2
|
unbuild: ^1.1.2
|
||||||
unctx: ^2.1.2
|
unctx: ^2.1.2
|
||||||
unimport: ^2.2.4
|
unimport: ^3.0.2
|
||||||
untyped: ^1.2.2
|
untyped: ^1.2.2
|
||||||
dependencies:
|
dependencies:
|
||||||
'@nuxt/schema': link:../schema
|
'@nuxt/schema': link:../schema
|
||||||
@ -338,7 +338,7 @@ importers:
|
|||||||
scule: 1.0.0
|
scule: 1.0.0
|
||||||
semver: 7.3.8
|
semver: 7.3.8
|
||||||
unctx: 2.1.2
|
unctx: 2.1.2
|
||||||
unimport: 2.2.4
|
unimport: 3.0.2
|
||||||
untyped: 1.2.2
|
untyped: 1.2.2
|
||||||
devDependencies:
|
devDependencies:
|
||||||
'@types/lodash.template': 4.5.1
|
'@types/lodash.template': 4.5.1
|
||||||
@ -450,7 +450,7 @@ importers:
|
|||||||
unctx: ^2.1.2
|
unctx: ^2.1.2
|
||||||
unenv: ^1.2.1
|
unenv: ^1.2.1
|
||||||
unhead: ^1.1.14
|
unhead: ^1.1.14
|
||||||
unimport: ^2.2.4
|
unimport: ^3.0.2
|
||||||
unplugin: ^1.1.0
|
unplugin: ^1.1.0
|
||||||
untyped: ^1.2.2
|
untyped: ^1.2.2
|
||||||
vue: 3.2.47
|
vue: 3.2.47
|
||||||
@ -495,7 +495,7 @@ importers:
|
|||||||
unctx: 2.1.2
|
unctx: 2.1.2
|
||||||
unenv: 1.2.1
|
unenv: 1.2.1
|
||||||
unhead: 1.1.14
|
unhead: 1.1.14
|
||||||
unimport: 2.2.4
|
unimport: 3.0.2
|
||||||
unplugin: 1.1.0
|
unplugin: 1.1.0
|
||||||
untyped: 1.2.2
|
untyped: 1.2.2
|
||||||
vue: 3.2.47
|
vue: 3.2.47
|
||||||
@ -527,7 +527,7 @@ importers:
|
|||||||
std-env: ^3.3.2
|
std-env: ^3.3.2
|
||||||
ufo: ^1.1.1
|
ufo: ^1.1.1
|
||||||
unbuild: ^1.1.2
|
unbuild: ^1.1.2
|
||||||
unimport: ^2.2.4
|
unimport: ^3.0.2
|
||||||
untyped: ^1.2.2
|
untyped: ^1.2.2
|
||||||
vite: ^4.1.4
|
vite: ^4.1.4
|
||||||
dependencies:
|
dependencies:
|
||||||
@ -542,7 +542,7 @@ importers:
|
|||||||
scule: 1.0.0
|
scule: 1.0.0
|
||||||
std-env: 3.3.2
|
std-env: 3.3.2
|
||||||
ufo: 1.1.1
|
ufo: 1.1.1
|
||||||
unimport: 2.2.4
|
unimport: 3.0.2
|
||||||
untyped: 1.2.2
|
untyped: 1.2.2
|
||||||
devDependencies:
|
devDependencies:
|
||||||
'@types/lodash.template': 4.5.1
|
'@types/lodash.template': 4.5.1
|
||||||
@ -8197,24 +8197,6 @@ packages:
|
|||||||
hookable: 5.4.2
|
hookable: 5.4.2
|
||||||
dev: false
|
dev: false
|
||||||
|
|
||||||
/unimport/2.2.4:
|
|
||||||
resolution: {integrity: sha512-qMgmeEGqqrrmEtm0dqxMG37J6xBtrriqxq9hILvDb+e6l2F0yTnJomLoCCp0eghLR7bYGeBsUU5Y0oyiUYhViw==}
|
|
||||||
dependencies:
|
|
||||||
'@rollup/pluginutils': 5.0.2
|
|
||||||
escape-string-regexp: 5.0.0
|
|
||||||
fast-glob: 3.2.12
|
|
||||||
local-pkg: 0.4.3
|
|
||||||
magic-string: 0.30.0
|
|
||||||
mlly: 1.1.1
|
|
||||||
pathe: 1.1.0
|
|
||||||
pkg-types: 1.0.2
|
|
||||||
scule: 1.0.0
|
|
||||||
strip-literal: 1.0.1
|
|
||||||
unplugin: 1.1.0
|
|
||||||
transitivePeerDependencies:
|
|
||||||
- rollup
|
|
||||||
dev: false
|
|
||||||
|
|
||||||
/unimport/2.2.4_rollup@3.17.3:
|
/unimport/2.2.4_rollup@3.17.3:
|
||||||
resolution: {integrity: sha512-qMgmeEGqqrrmEtm0dqxMG37J6xBtrriqxq9hILvDb+e6l2F0yTnJomLoCCp0eghLR7bYGeBsUU5Y0oyiUYhViw==}
|
resolution: {integrity: sha512-qMgmeEGqqrrmEtm0dqxMG37J6xBtrriqxq9hILvDb+e6l2F0yTnJomLoCCp0eghLR7bYGeBsUU5Y0oyiUYhViw==}
|
||||||
dependencies:
|
dependencies:
|
||||||
@ -8232,6 +8214,24 @@ packages:
|
|||||||
transitivePeerDependencies:
|
transitivePeerDependencies:
|
||||||
- rollup
|
- rollup
|
||||||
|
|
||||||
|
/unimport/3.0.2:
|
||||||
|
resolution: {integrity: sha512-OQ0hShpcerS1PSsISsyn/NV2dGe5xfdUn4p5nwOodq0iqq5xxYQrTidHqlFGjxIliPDtDJp80OeySzyPTjYHmA==}
|
||||||
|
dependencies:
|
||||||
|
'@rollup/pluginutils': 5.0.2
|
||||||
|
escape-string-regexp: 5.0.0
|
||||||
|
fast-glob: 3.2.12
|
||||||
|
local-pkg: 0.4.3
|
||||||
|
magic-string: 0.30.0
|
||||||
|
mlly: 1.1.1
|
||||||
|
pathe: 1.1.0
|
||||||
|
pkg-types: 1.0.2
|
||||||
|
scule: 1.0.0
|
||||||
|
strip-literal: 1.0.1
|
||||||
|
unplugin: 1.1.0
|
||||||
|
transitivePeerDependencies:
|
||||||
|
- rollup
|
||||||
|
dev: false
|
||||||
|
|
||||||
/universalify/2.0.0:
|
/universalify/2.0.0:
|
||||||
resolution: {integrity: sha512-hAZsKq7Yy11Zu1DE0OzWjw7nnLZmJZYTDZZyEFHZdUhV8FkH5MCfoU1XMaxXovpyW5nq5scPqq0ZDP9Zyl04oQ==}
|
resolution: {integrity: sha512-hAZsKq7Yy11Zu1DE0OzWjw7nnLZmJZYTDZZyEFHZdUhV8FkH5MCfoU1XMaxXovpyW5nq5scPqq0ZDP9Zyl04oQ==}
|
||||||
engines: {node: '>= 10.0.0'}
|
engines: {node: '>= 10.0.0'}
|
||||||
|
@ -60,9 +60,10 @@ describe('pages', () => {
|
|||||||
expect(html).toContain('RuntimeConfig | testConfig: 123')
|
expect(html).toContain('RuntimeConfig | testConfig: 123')
|
||||||
expect(html).toContain('needsFallback:')
|
expect(html).toContain('needsFallback:')
|
||||||
// composables auto import
|
// composables auto import
|
||||||
expect(html).toContain('Composable | foo: auto imported from ~/components/foo.ts')
|
expect(html).toContain('Composable | foo: auto imported from ~/composables/foo.ts')
|
||||||
expect(html).toContain('Composable | bar: auto imported from ~/components/useBar.ts')
|
expect(html).toContain('Composable | bar: auto imported from ~/utils/useBar.ts')
|
||||||
expect(html).toContain('Composable | template: auto imported from ~/components/template.ts')
|
expect(html).toContain('Composable | template: auto imported from ~/composables/template.ts')
|
||||||
|
expect(html).toContain('Composable | star: auto imported from ~/composables/nested/bar.ts via star export')
|
||||||
// should import components
|
// should import components
|
||||||
expect(html).toContain('This is a custom component with a named export.')
|
expect(html).toContain('This is a custom component with a named export.')
|
||||||
// should apply attributes to client-only components
|
// should apply attributes to client-only components
|
||||||
|
1
test/fixtures/basic/composables/export-star.ts
vendored
Normal file
1
test/fixtures/basic/composables/export-star.ts
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
export * from './nested/bar'
|
2
test/fixtures/basic/composables/foo.ts
vendored
2
test/fixtures/basic/composables/foo.ts
vendored
@ -1,3 +1,3 @@
|
|||||||
export function useFoo () {
|
export function useFoo () {
|
||||||
return 'auto imported from ~/components/foo.ts'
|
return 'auto imported from ~/composables/foo.ts'
|
||||||
}
|
}
|
||||||
|
3
test/fixtures/basic/composables/nested/bar.ts
vendored
Normal file
3
test/fixtures/basic/composables/nested/bar.ts
vendored
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
export function useNestedBar () {
|
||||||
|
return 'auto imported from ~/composables/nested/bar.ts via star export'
|
||||||
|
}
|
2
test/fixtures/basic/composables/template.ts
vendored
2
test/fixtures/basic/composables/template.ts
vendored
@ -1 +1 @@
|
|||||||
export const templateAutoImport = 'auto imported from ~/components/template.ts'
|
export const templateAutoImport = 'auto imported from ~/composables/template.ts'
|
||||||
|
3
test/fixtures/basic/pages/index.vue
vendored
3
test/fixtures/basic/pages/index.vue
vendored
@ -7,9 +7,10 @@
|
|||||||
<div>RuntimeConfig | testConfig: {{ config.testConfig }}</div>
|
<div>RuntimeConfig | testConfig: {{ config.testConfig }}</div>
|
||||||
<div>Composable | foo: {{ foo }}</div>
|
<div>Composable | foo: {{ foo }}</div>
|
||||||
<div>Composable | bar: {{ bar }}</div>
|
<div>Composable | bar: {{ bar }}</div>
|
||||||
|
<div>Composable | template: {{ templateAutoImport }}</div>
|
||||||
|
<div>Composable | star: {{ useNestedBar() }}</div>
|
||||||
<DevOnly>Some dev-only info</DevOnly>
|
<DevOnly>Some dev-only info</DevOnly>
|
||||||
<div><DevOnly>Some dev-only info</DevOnly></div>
|
<div><DevOnly>Some dev-only info</DevOnly></div>
|
||||||
<div>Composable | template: {{ templateAutoImport }}</div>
|
|
||||||
<div>Path: {{ $route.fullPath }}</div>
|
<div>Path: {{ $route.fullPath }}</div>
|
||||||
<NuxtLink to="/">
|
<NuxtLink to="/">
|
||||||
Link
|
Link
|
||||||
|
4
test/fixtures/basic/utils/useBar.ts
vendored
4
test/fixtures/basic/utils/useBar.ts
vendored
@ -1,3 +1,3 @@
|
|||||||
export default function useFoo () {
|
export default function () {
|
||||||
return 'auto imported from ~/components/useBar.ts'
|
return 'auto imported from ~/utils/useBar.ts'
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user