mirror of
https://github.com/nuxt/nuxt.git
synced 2025-01-31 07:40:33 +00:00
fix(bridge): replace nuxt 3 auto-imports (#3850)
This commit is contained in:
parent
11c460fa99
commit
23e7afb5ec
@ -57,7 +57,7 @@
|
||||
"scule": "^0.2.1",
|
||||
"semver": "^7.3.5",
|
||||
"ufo": "^0.8.1",
|
||||
"unimport": "^0.1.2",
|
||||
"unimport": "^0.1.3",
|
||||
"unplugin": "^0.6.0",
|
||||
"unplugin-vue2-script-setup": "^0.10.0",
|
||||
"untyped": "^0.4.3",
|
||||
|
@ -2,7 +2,7 @@ import { installModule, useNuxt } from '@nuxt/kit'
|
||||
import * as CompositionApi from '@vue/composition-api'
|
||||
import type { Preset } from 'unimport'
|
||||
import autoImports from '../../nuxt3/src/auto-imports/module'
|
||||
import { vuePreset, commonPresets, appPreset } from '../../nuxt3/src/auto-imports/presets'
|
||||
import { vuePreset } from '../../nuxt3/src/auto-imports/presets'
|
||||
|
||||
const UnsupportedImports = new Set(['useAsyncData', 'useFetch', 'useError', 'throwError', 'clearError'])
|
||||
const CapiHelpers = new Set(Object.keys(CompositionApi))
|
||||
@ -11,19 +11,27 @@ export function setupAutoImports () {
|
||||
const nuxt = useNuxt()
|
||||
|
||||
const bridgePresets: Preset[] = [
|
||||
...commonPresets,
|
||||
{
|
||||
from: '#app',
|
||||
imports: [
|
||||
...appPreset.imports.filter(i => !UnsupportedImports.has(i as string)),
|
||||
'useNuxt2Meta'
|
||||
]
|
||||
},
|
||||
{
|
||||
from: '@vue/composition-api',
|
||||
imports: vuePreset.imports.filter(i => CapiHelpers.has(i as string))
|
||||
},
|
||||
{
|
||||
from: '#app',
|
||||
imports: ['useNuxt2Meta']
|
||||
}
|
||||
]
|
||||
nuxt.hook('autoImports:sources', (presets) => {
|
||||
const vuePreset = presets.find(p => p.from === 'vue')
|
||||
if (vuePreset) { vuePreset.disabled = true }
|
||||
})
|
||||
|
||||
nuxt.hook('autoImports:extend', (imports) => {
|
||||
for (const i of imports) {
|
||||
if (i.from === '#app' && UnsupportedImports.has(i.name)) {
|
||||
i.disabled = true
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
nuxt.hook('modules:done', () => installModule(autoImports, { presets: bridgePresets }))
|
||||
}
|
||||
|
@ -29,7 +29,7 @@
|
||||
"scule": "^0.2.1",
|
||||
"semver": "^7.3.5",
|
||||
"unctx": "^1.1.0",
|
||||
"unimport": "^0.1.2",
|
||||
"unimport": "^0.1.3",
|
||||
"untyped": "^0.4.3"
|
||||
},
|
||||
"devDependencies": {
|
||||
|
@ -59,7 +59,7 @@
|
||||
"perfect-debounce": "^0.1.3",
|
||||
"scule": "^0.2.1",
|
||||
"ufo": "^0.8.1",
|
||||
"unimport": "^0.1.2",
|
||||
"unimport": "^0.1.3",
|
||||
"unplugin": "^0.6.0",
|
||||
"untyped": "^0.4.3",
|
||||
"vue": "^3.2.31",
|
||||
|
@ -1,7 +1,7 @@
|
||||
import { addVitePlugin, addWebpackPlugin, defineNuxtModule, addTemplate, resolveAlias, useNuxt, addPluginTemplate, logger } from '@nuxt/kit'
|
||||
import { isAbsolute, join, relative, resolve, normalize } from 'pathe'
|
||||
import { createUnimport, Import, toImports, Unimport } from 'unimport'
|
||||
import { AutoImportsOptions, ImportPresetWithDeperection } from '@nuxt/schema'
|
||||
import { AutoImportsOptions, ImportPresetWithDeprecation } from '@nuxt/schema'
|
||||
import { TransformPlugin } from './transform'
|
||||
import { defaultPresets } from './presets'
|
||||
import { scanForComposables } from './composables'
|
||||
@ -22,9 +22,9 @@ export default defineNuxtModule<Partial<AutoImportsOptions>>({
|
||||
},
|
||||
async setup (options, nuxt) {
|
||||
// Allow modules extending sources
|
||||
await nuxt.callHook('autoImports:sources', options.presets as ImportPresetWithDeperection[])
|
||||
await nuxt.callHook('autoImports:sources', options.presets as ImportPresetWithDeprecation[])
|
||||
|
||||
options.presets.forEach((i: ImportPresetWithDeperection) => {
|
||||
options.presets.forEach((i: ImportPresetWithDeprecation) => {
|
||||
if (typeof i !== 'string' && i.names && !i.imports) {
|
||||
i.imports = i.names
|
||||
logger.warn('auto-imports: presets.names is deprecated, use presets.imports instead')
|
||||
@ -36,7 +36,7 @@ export default defineNuxtModule<Partial<AutoImportsOptions>>({
|
||||
|
||||
// Create a context to share state between module internals
|
||||
const ctx = createUnimport({
|
||||
presets: defaultPresets,
|
||||
presets: options.presets,
|
||||
imports: options.imports
|
||||
})
|
||||
|
||||
|
@ -28,7 +28,7 @@
|
||||
"scule": "^0.2.1",
|
||||
"std-env": "^3.0.1",
|
||||
"ufo": "^0.8.1",
|
||||
"unimport": "^0.1.2"
|
||||
"unimport": "^0.1.3"
|
||||
},
|
||||
"engines": {
|
||||
"node": "^14.16.0 || ^16.11.0 || ^17.0.0"
|
||||
|
@ -52,7 +52,7 @@ export type NuxtLayout = {
|
||||
file: string
|
||||
}
|
||||
|
||||
export interface ImportPresetWithDeperection extends ImportPreset {
|
||||
export interface ImportPresetWithDeprecation extends ImportPreset {
|
||||
/**
|
||||
* @deprecated renamed to `imports`
|
||||
*/
|
||||
@ -72,7 +72,7 @@ export interface NuxtHooks {
|
||||
'pages:middleware:extend': (middleware: NuxtMiddleware[]) => HookResult
|
||||
|
||||
// Auto imports
|
||||
'autoImports:sources': (presets: ImportPresetWithDeperection[]) => HookResult
|
||||
'autoImports:sources': (presets: ImportPresetWithDeprecation[]) => HookResult
|
||||
'autoImports:extend': (imports: Import[]) => HookResult
|
||||
'autoImports:dirs': (dirs: string[]) => HookResult
|
||||
|
||||
|
16
yarn.lock
16
yarn.lock
@ -2675,7 +2675,7 @@ __metadata:
|
||||
semver: ^7.3.5
|
||||
ufo: ^0.8.1
|
||||
unbuild: latest
|
||||
unimport: ^0.1.2
|
||||
unimport: ^0.1.3
|
||||
unplugin: ^0.6.0
|
||||
unplugin-vue2-script-setup: ^0.10.0
|
||||
untyped: ^0.4.3
|
||||
@ -2974,7 +2974,7 @@ __metadata:
|
||||
semver: ^7.3.5
|
||||
unbuild: latest
|
||||
unctx: ^1.1.0
|
||||
unimport: ^0.1.2
|
||||
unimport: ^0.1.3
|
||||
untyped: ^0.4.3
|
||||
languageName: unknown
|
||||
linkType: soft
|
||||
@ -3138,7 +3138,7 @@ __metadata:
|
||||
std-env: ^3.0.1
|
||||
ufo: ^0.8.1
|
||||
unbuild: latest
|
||||
unimport: ^0.1.2
|
||||
unimport: ^0.1.3
|
||||
languageName: unknown
|
||||
linkType: soft
|
||||
|
||||
@ -15605,7 +15605,7 @@ __metadata:
|
||||
scule: ^0.2.1
|
||||
ufo: ^0.8.1
|
||||
unbuild: latest
|
||||
unimport: ^0.1.2
|
||||
unimport: ^0.1.3
|
||||
unplugin: ^0.6.0
|
||||
untyped: ^0.4.3
|
||||
vue: ^3.2.31
|
||||
@ -21301,9 +21301,9 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"unimport@npm:^0.1.2":
|
||||
version: 0.1.2
|
||||
resolution: "unimport@npm:0.1.2"
|
||||
"unimport@npm:^0.1.3":
|
||||
version: 0.1.3
|
||||
resolution: "unimport@npm:0.1.3"
|
||||
dependencies:
|
||||
"@rollup/pluginutils": ^4.1.2
|
||||
escape-string-regexp: ^5.0.0
|
||||
@ -21314,7 +21314,7 @@ __metadata:
|
||||
pathe: ^0.2.0
|
||||
scule: ^0.2.1
|
||||
unplugin: ^0.3.3
|
||||
checksum: 212b56cd24796471c7af635f90275aa6f8d8c4c2085e89a8ebef0da5533e1d5fb56eeeb3b36753ee6365e62ccb241bf7baac961b34c123bbf5ce06c7f86d2a2c
|
||||
checksum: a4e58b13cd1b9e8d6fbc783b026c66db5d101e6b660d4e92043c1b32089a12f8aa4864263823a05624ff55bac59b6637305cd22f35ac0c24e9f36b9cd3364752
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user