mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-25 23:22:02 +00:00
fix: improve autoImports
deprecation dx (#7158)
This commit is contained in:
parent
3c571ba357
commit
abd5dc58c9
@ -1,21 +0,0 @@
|
||||
import { Import } from 'unimport'
|
||||
import { useNuxt } from './context'
|
||||
import { assertNuxtCompatibility } from './compatibility'
|
||||
|
||||
export function addAutoImport (imports: Import | Import[]) {
|
||||
assertNuxtCompatibility({ bridge: true })
|
||||
|
||||
useNuxt().hook('imports:extend', (_imports) => {
|
||||
_imports.push(...(Array.isArray(imports) ? imports : [imports]))
|
||||
})
|
||||
}
|
||||
|
||||
export function addAutoImportDir (dirs: string | string[]) {
|
||||
assertNuxtCompatibility({ bridge: true })
|
||||
|
||||
useNuxt().hook('imports:dirs', (_dirs: string[]) => {
|
||||
for (const dir of (Array.isArray(dirs) ? dirs : [dirs])) {
|
||||
_dirs.push(dir)
|
||||
}
|
||||
})
|
||||
}
|
33
packages/kit/src/imports.ts
Normal file
33
packages/kit/src/imports.ts
Normal file
@ -0,0 +1,33 @@
|
||||
import { Import } from 'unimport'
|
||||
import { useNuxt } from './context'
|
||||
import { assertNuxtCompatibility } from './compatibility'
|
||||
|
||||
export function addImports (imports: Import | Import[]) {
|
||||
assertNuxtCompatibility({ bridge: true })
|
||||
|
||||
// TODO: Use imports:* when widely adopted
|
||||
useNuxt().hook('autoImports:extend', (_imports) => {
|
||||
_imports.push(...(Array.isArray(imports) ? imports : [imports]))
|
||||
}, { allowDeprecated: true })
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated Please use `addImports` instead with nuxt>=3.0.0-rc.9
|
||||
*/
|
||||
export const addAutoImport = addImports
|
||||
|
||||
export function addImportsDir (dirs: string | string[]) {
|
||||
assertNuxtCompatibility({ bridge: true })
|
||||
|
||||
// TODO: Use imports:* when widely adopted
|
||||
useNuxt().hook('autoImports:dirs', (_dirs: string[]) => {
|
||||
for (const dir of (Array.isArray(dirs) ? dirs : [dirs])) {
|
||||
_dirs.push(dir)
|
||||
}
|
||||
}, { allowDeprecated: true })
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated Please use `addImportsDir` instead with nuxt>=3.0.0-rc.9
|
||||
*/
|
||||
export const addAutoImportDir = addImportsDir
|
@ -8,7 +8,7 @@ export * from './loader/config'
|
||||
export * from './loader/nuxt'
|
||||
|
||||
// Utils
|
||||
export * from './auto-import'
|
||||
export * from './imports'
|
||||
export * from './build'
|
||||
export * from './compatibility'
|
||||
export * from './components'
|
||||
|
@ -48,7 +48,7 @@
|
||||
"globby": "^13.1.2",
|
||||
"h3": "^0.7.19",
|
||||
"hash-sum": "^2.0.0",
|
||||
"hookable": "^5.2.2",
|
||||
"hookable": "^5.3.0",
|
||||
"knitwork": "^0.1.2",
|
||||
"magic-string": "^0.26.3",
|
||||
"mlly": "^0.5.14",
|
||||
|
@ -134,6 +134,22 @@ async function initNuxt (nuxt: Nuxt) {
|
||||
filePath: resolve(nuxt.options.appDir, 'components/nuxt-loading-indicator')
|
||||
})
|
||||
|
||||
// Deprecate hooks
|
||||
nuxt.hooks.deprecateHooks({
|
||||
'autoImports:sources': {
|
||||
to: 'imports:sources',
|
||||
message: '`autoImports:sources` hook is deprecated. Use `imports:sources` with `nuxt>=3.0.0-rc.9`.'
|
||||
},
|
||||
'autoImports:dirs': {
|
||||
to: 'imports:dirs',
|
||||
message: '`autoImports:sources` hook is deprecated. Use `addImports()` from `@nuxt/kit` or `imports:sources` with `nuxt>=3.0.0-rc.9`.'
|
||||
},
|
||||
'autoImports:extend': {
|
||||
to: 'imports:extend',
|
||||
message: '`autoImports:extend` hook is deprecated. Use `addImports()` from `@nuxt/kit` or `imports:sources` with `nuxt>=3.0.0-rc.9`.'
|
||||
}
|
||||
})
|
||||
|
||||
for (const m of modulesToInstall) {
|
||||
if (Array.isArray(m)) {
|
||||
await installModule(m[0], m[1])
|
||||
|
@ -31,12 +31,6 @@ export default defineNuxtModule<Partial<ImportsOptions>>({
|
||||
options = defu(nuxt.options.autoImports, options)
|
||||
}
|
||||
|
||||
nuxt.hooks.deprecateHooks({
|
||||
'autoImports:sources': { to: 'imports:sources' },
|
||||
'autoImports:dirs': { to: 'imports:dirs' },
|
||||
'autoImports:extend': { to: 'imports:extend' }
|
||||
})
|
||||
|
||||
// Allow modules extending sources
|
||||
await nuxt.callHook('imports:sources', options.presets as ImportPresetWithDeprecation[])
|
||||
|
||||
|
98
yarn.lock
98
yarn.lock
@ -48,7 +48,7 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"@babel/core@npm:^7.18.13, @babel/core@npm:^7.18.6":
|
||||
"@babel/core@npm:^7.18.13":
|
||||
version: 7.18.13
|
||||
resolution: "@babel/core@npm:7.18.13"
|
||||
dependencies:
|
||||
@ -314,7 +314,7 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"@babel/plugin-transform-typescript@npm:^7.18.8":
|
||||
"@babel/plugin-transform-typescript@npm:^7.18.12":
|
||||
version: 7.18.12
|
||||
resolution: "@babel/plugin-transform-typescript@npm:7.18.12"
|
||||
dependencies:
|
||||
@ -1597,23 +1597,23 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"@nrwl/cli@npm:14.6.2":
|
||||
version: 14.6.2
|
||||
resolution: "@nrwl/cli@npm:14.6.2"
|
||||
"@nrwl/cli@npm:14.6.3":
|
||||
version: 14.6.3
|
||||
resolution: "@nrwl/cli@npm:14.6.3"
|
||||
dependencies:
|
||||
nx: 14.6.2
|
||||
checksum: 55f9cfd2bcbc2f19b259efc0b0eed54101c9b8b5a6287fc9dedd06d5294d20a9758832ffa385f94f9cb97bb29d0efff6a8f0fd49b0f5e82923d279fec8bb9b83
|
||||
nx: 14.6.3
|
||||
checksum: 6d1a6b40324d10c6c45e069b9732d3b74388d57eefa7cf00ef11fe1bd6b3a085191980cb928fd75cef5dfb84c4cf42b6de37f4f9e801229de9f93b11c93f0088
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"@nrwl/tao@npm:14.6.2":
|
||||
version: 14.6.2
|
||||
resolution: "@nrwl/tao@npm:14.6.2"
|
||||
"@nrwl/tao@npm:14.6.3":
|
||||
version: 14.6.3
|
||||
resolution: "@nrwl/tao@npm:14.6.3"
|
||||
dependencies:
|
||||
nx: 14.6.2
|
||||
nx: 14.6.3
|
||||
bin:
|
||||
tao: index.js
|
||||
checksum: 2f66126fa56878f55ccfce8c9dc3e5192ce5df50d862de672d4d212b199ed33d34262a3b530d7f19e925e8e8bcd12d19d109e31ff06251bf84b6b9bc1c49f82b
|
||||
checksum: fdead3c743b5fa12e8ff327d20f6fd60801b49d7c9ba11a484b1a097f9a467c201c3957d87cdd63dbd8e7f6201b6597062a2a0c6878ecccc1ce4fc1bfe1a76a3
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
@ -2910,8 +2910,8 @@ __metadata:
|
||||
linkType: hard
|
||||
|
||||
"@vercel/nft@npm:^0.22.0":
|
||||
version: 0.22.0
|
||||
resolution: "@vercel/nft@npm:0.22.0"
|
||||
version: 0.22.1
|
||||
resolution: "@vercel/nft@npm:0.22.1"
|
||||
dependencies:
|
||||
"@mapbox/node-pre-gyp": ^1.0.5
|
||||
acorn: ^8.6.0
|
||||
@ -2926,22 +2926,22 @@ __metadata:
|
||||
rollup-pluginutils: ^2.8.2
|
||||
bin:
|
||||
nft: out/cli.js
|
||||
checksum: 06f649f76a0ffae0c02964cfe66acb9b722de054e0317829f0a992dfb9b941328cfa7cb722af847b8d641b87497c994cb315ecf2c7d1fbe8c15176af57676887
|
||||
checksum: 05850e25a8e3a4fd7b76d911e8d14f97403f58cf8f92fbae630adaeee99589a167f288b87b3edc5901bf87bf2adad689059f43755c448930d1d087cdb66cec93
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"@vitejs/plugin-vue-jsx@npm:^2.0.0":
|
||||
version: 2.0.0
|
||||
resolution: "@vitejs/plugin-vue-jsx@npm:2.0.0"
|
||||
version: 2.0.1
|
||||
resolution: "@vitejs/plugin-vue-jsx@npm:2.0.1"
|
||||
dependencies:
|
||||
"@babel/core": ^7.18.6
|
||||
"@babel/core": ^7.18.13
|
||||
"@babel/plugin-syntax-import-meta": ^7.10.4
|
||||
"@babel/plugin-transform-typescript": ^7.18.8
|
||||
"@babel/plugin-transform-typescript": ^7.18.12
|
||||
"@vue/babel-plugin-jsx": ^1.1.1
|
||||
peerDependencies:
|
||||
vite: ^3.0.0
|
||||
vue: ^3.0.0
|
||||
checksum: 197b0dd0263b5b7df22a055155da6d9b7f21098f7de43e94589ce8daa494c12c9850157bc4e228a766fbe602aafa5935e4bef0edec9158a0507cee5581f0a067
|
||||
checksum: 2ed52597fd92fbcbfe00f07cb05b3e6efa97dc073a5b66c704d90c65a0deba164bb7bc6ebce5a285ed3c9d1156ae0a9abb21dd25c0cb30b169dfe33c52b68b5d
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
@ -4148,9 +4148,9 @@ __metadata:
|
||||
linkType: hard
|
||||
|
||||
"caniuse-lite@npm:^1.0.0, caniuse-lite@npm:^1.0.30001370, caniuse-lite@npm:^1.0.30001373":
|
||||
version: 1.0.30001387
|
||||
resolution: "caniuse-lite@npm:1.0.30001387"
|
||||
checksum: 57b894aa54da582f867018cdbc3c8956f894962988233cd4ace8710ab0e3405dd928926e35f46e5a9b4068e5cea7e36c6e14f930c9c40972885f329df7e8119e
|
||||
version: 1.0.30001388
|
||||
resolution: "caniuse-lite@npm:1.0.30001388"
|
||||
checksum: 4934f99bf99521484d4048023f57046812fbc9218924dbe30bb8379cd7b0315d9489b7de4d226a9921b0a9fd5d05b12023930ad6b4104854fb03dcbf999784db
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
@ -5339,9 +5339,9 @@ __metadata:
|
||||
linkType: hard
|
||||
|
||||
"electron-to-chromium@npm:^1.4.202":
|
||||
version: 1.4.239
|
||||
resolution: "electron-to-chromium@npm:1.4.239"
|
||||
checksum: 4e16eadc647d69353520a200953a76beb6557284172259703c483d4ec8302a331ff243d85b49da13d58c6c7e99f8917d26b529e6159cf69489fa62021ba25cac
|
||||
version: 1.4.240
|
||||
resolution: "electron-to-chromium@npm:1.4.240"
|
||||
checksum: 6590e2cddd2e6a564cc491fb1ece5719c35dcbbeed34fc66e878b1659753653d0e344908b36b11741968dfc47a0141759e3780546384bb5308d38bc5232e0cb5
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
@ -5488,14 +5488,14 @@ __metadata:
|
||||
linkType: hard
|
||||
|
||||
"es-abstract@npm:^1.19.0, es-abstract@npm:^1.19.1, es-abstract@npm:^1.19.2, es-abstract@npm:^1.19.5":
|
||||
version: 1.20.1
|
||||
resolution: "es-abstract@npm:1.20.1"
|
||||
version: 1.20.2
|
||||
resolution: "es-abstract@npm:1.20.2"
|
||||
dependencies:
|
||||
call-bind: ^1.0.2
|
||||
es-to-primitive: ^1.2.1
|
||||
function-bind: ^1.1.1
|
||||
function.prototype.name: ^1.1.5
|
||||
get-intrinsic: ^1.1.1
|
||||
get-intrinsic: ^1.1.2
|
||||
get-symbol-description: ^1.0.0
|
||||
has: ^1.0.3
|
||||
has-property-descriptors: ^1.0.0
|
||||
@ -5507,14 +5507,14 @@ __metadata:
|
||||
is-shared-array-buffer: ^1.0.2
|
||||
is-string: ^1.0.7
|
||||
is-weakref: ^1.0.2
|
||||
object-inspect: ^1.12.0
|
||||
object-inspect: ^1.12.2
|
||||
object-keys: ^1.1.1
|
||||
object.assign: ^4.1.2
|
||||
object.assign: ^4.1.4
|
||||
regexp.prototype.flags: ^1.4.3
|
||||
string.prototype.trimend: ^1.0.5
|
||||
string.prototype.trimstart: ^1.0.5
|
||||
unbox-primitive: ^1.0.2
|
||||
checksum: 28da27ae0ed9c76df7ee8ef5c278df79dcfdb554415faf7068bb7c58f8ba8e2a16bfb59e586844be6429ab4c302ca7748979d48442224cb1140b051866d74b7f
|
||||
checksum: ab893dd1f849250f5a2da82656b4e21b511f76429b25a4aea5c8b2a3007ff01cb8e112987d0dd7693b9ad9e6399f8f7be133285d6196a5ebd1b13a4ee2258f70
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
@ -7154,7 +7154,7 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"get-intrinsic@npm:^1.0.2, get-intrinsic@npm:^1.1.0, get-intrinsic@npm:^1.1.1":
|
||||
"get-intrinsic@npm:^1.0.2, get-intrinsic@npm:^1.1.0, get-intrinsic@npm:^1.1.1, get-intrinsic@npm:^1.1.2":
|
||||
version: 1.1.2
|
||||
resolution: "get-intrinsic@npm:1.1.2"
|
||||
dependencies:
|
||||
@ -7576,10 +7576,10 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"hookable@npm:^5.2.2":
|
||||
version: 5.2.2
|
||||
resolution: "hookable@npm:5.2.2"
|
||||
checksum: fb4b3104a62ecf47f1743e8ea1a573656ee8d0601903fafa6a5c7247bc18a007be603e58a302400576f3b4c358b641372b073adf649018db00294d8c34123dbc
|
||||
"hookable@npm:^5.2.2, hookable@npm:^5.3.0":
|
||||
version: 5.3.0
|
||||
resolution: "hookable@npm:5.3.0"
|
||||
checksum: 5a170b790fc472fae11cc8ebc7a1336e7063c3f0a9697cefb5b18d455fcda4d1eadf21c254a27c0625fbbe31f736fd662797c21e6425e9c8cf073182b2ecae7f
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
@ -10001,7 +10001,7 @@ __metadata:
|
||||
globby: ^13.1.2
|
||||
h3: ^0.7.19
|
||||
hash-sum: ^2.0.0
|
||||
hookable: ^5.2.2
|
||||
hookable: ^5.3.0
|
||||
knitwork: ^0.1.2
|
||||
magic-string: ^0.26.3
|
||||
mlly: ^0.5.14
|
||||
@ -10031,12 +10031,12 @@ __metadata:
|
||||
languageName: unknown
|
||||
linkType: soft
|
||||
|
||||
"nx@npm:14.6.2, nx@npm:>=14.6.1 < 16":
|
||||
version: 14.6.2
|
||||
resolution: "nx@npm:14.6.2"
|
||||
"nx@npm:14.6.3, nx@npm:>=14.6.1 < 16":
|
||||
version: 14.6.3
|
||||
resolution: "nx@npm:14.6.3"
|
||||
dependencies:
|
||||
"@nrwl/cli": 14.6.2
|
||||
"@nrwl/tao": 14.6.2
|
||||
"@nrwl/cli": 14.6.3
|
||||
"@nrwl/tao": 14.6.3
|
||||
"@parcel/watcher": 2.0.4
|
||||
chalk: 4.1.0
|
||||
chokidar: ^3.5.1
|
||||
@ -10075,7 +10075,7 @@ __metadata:
|
||||
optional: true
|
||||
bin:
|
||||
nx: bin/nx.js
|
||||
checksum: 8e7ad2a899b57167c6ff7c961a22c52b8433c85e9fc4822c74cf147ab632f662bd567d8b02e988ec81c2d360bf15ad44302ddec3fba4ec03be78fff1442fea7c
|
||||
checksum: e8cd884c7ee9d086eb85eb6bf10c939ea88466a1d070495e9712579e569664a0a272a7ea6809ca2903d671c10ce91c9188d26fe00754d1c54233aa12c401fa10
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
@ -10086,7 +10086,7 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"object-inspect@npm:^1.12.0, object-inspect@npm:^1.9.0":
|
||||
"object-inspect@npm:^1.12.2, object-inspect@npm:^1.9.0":
|
||||
version: 1.12.2
|
||||
resolution: "object-inspect@npm:1.12.2"
|
||||
checksum: a534fc1b8534284ed71f25ce3a496013b7ea030f3d1b77118f6b7b1713829262be9e6243acbcb3ef8c626e2b64186112cb7f6db74e37b2789b9c789ca23048b2
|
||||
@ -10100,7 +10100,7 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"object.assign@npm:^4.1.2":
|
||||
"object.assign@npm:^4.1.4":
|
||||
version: 4.1.4
|
||||
resolution: "object.assign@npm:4.1.4"
|
||||
dependencies:
|
||||
@ -13198,8 +13198,8 @@ __metadata:
|
||||
linkType: hard
|
||||
|
||||
"update-browserslist-db@npm:^1.0.5":
|
||||
version: 1.0.5
|
||||
resolution: "update-browserslist-db@npm:1.0.5"
|
||||
version: 1.0.7
|
||||
resolution: "update-browserslist-db@npm:1.0.7"
|
||||
dependencies:
|
||||
escalade: ^3.1.1
|
||||
picocolors: ^1.0.0
|
||||
@ -13207,7 +13207,7 @@ __metadata:
|
||||
browserslist: ">= 4.21.0"
|
||||
bin:
|
||||
browserslist-lint: cli.js
|
||||
checksum: 7e425fe5dbbebdccf72a84ce70ec47fc74dce561d28f47bc2b84a1c2b84179a862c2261b18ab66a5e73e261c7e2ef9e11c6129112989d4d52e8f75a56bb923f8
|
||||
checksum: 443ed6e77d4607b8bdf12710fe1c0b570fcbb992ebcafaa0c647811e5646fa51e0b5a17641637e10044e4b770bfc3a9ce2a9350a646477545aed882a1fcff8ce
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user