feat: upgrade unimport to 0.7.0 (#8483)

This commit is contained in:
Anthony Fu 2022-10-26 16:28:00 +08:00 committed by GitHub
parent 12808f175b
commit bbea416c23
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 62 additions and 20 deletions

View File

@ -29,7 +29,7 @@
"scule": "^0.3.2",
"semver": "^7.3.8",
"unctx": "^2.0.2",
"unimport": "^0.6.8",
"unimport": "^0.7.0",
"untyped": "^0.5.0"
},
"devDependencies": {

View File

@ -70,7 +70,7 @@
"ultrahtml": "^0.4.0",
"unctx": "^2.0.2",
"unenv": "^0.6.2",
"unimport": "^0.6.8",
"unimport": "^0.7.0",
"unplugin": "^0.10.1",
"untyped": "^0.5.0",
"vue": "^3.2.41",

View File

@ -34,7 +34,8 @@ export default defineNuxtModule<Partial<ImportsOptions>>({
// Allow modules extending sources
await nuxt.callHook('imports:sources', options.presets as ImportPresetWithDeprecation[])
options.presets?.forEach((i: ImportPresetWithDeprecation | string) => {
options.presets?.forEach((_i) => {
const i = _i as ImportPresetWithDeprecation | string
if (typeof i !== 'string' && i.names && !i.imports) {
i.imports = i.names
logger.warn('imports: presets.names is deprecated, use presets.imports instead')
@ -72,7 +73,7 @@ export default defineNuxtModule<Partial<ImportsOptions>>({
// Support for importing from '#imports'
addTemplate({
filename: 'imports.mjs',
getContents: () => ctx.toExports() + '\nif (process.dev) { console.warn("[nuxt] `#imports` should be transformed with real imports. There seems to be something wrong with the imports plugin.") }'
getContents: async () => await ctx.toExports() + '\nif (process.dev) { console.warn("[nuxt] `#imports` should be transformed with real imports. There seems to be something wrong with the imports plugin.") }'
})
nuxt.options.alias['#imports'] = join(nuxt.options.buildDir, 'imports')
@ -81,8 +82,8 @@ export default defineNuxtModule<Partial<ImportsOptions>>({
// Add all imports to globalThis in development mode
addPluginTemplate({
filename: 'imports.mjs',
getContents: () => {
const imports = ctx.getImports()
getContents: async () => {
const imports = await ctx.getImports()
const importStatement = toImports(imports)
const globalThisSet = imports.map(i => `globalThis.${i.as} = ${i.as};`).join('\n')
return `${importStatement}\n\n${globalThisSet}\n\nexport default () => {};`
@ -164,9 +165,9 @@ function addDeclarationTemplates (ctx: Unimport, options: Partial<ImportsOptions
addTemplate({
filename: 'types/imports.d.ts',
getContents: () => '// Generated by auto imports\n' + (
getContents: async () => '// Generated by auto imports\n' + (
options.autoImport
? ctx.generateTypeDeclarations({ resolvePath: r })
? await ctx.generateTypeDeclarations({ resolvePath: r })
: '// Implicit auto importing is disabled, you can use explicitly import from `#imports` instead.'
)
})

View File

@ -1,6 +1,6 @@
import { defineUnimportPreset, Preset } from 'unimport'
import { defineUnimportPreset, InlinePreset } from 'unimport'
const commonPresets: Preset[] = [
const commonPresets: InlinePreset[] = [
// #head
defineUnimportPreset({
from: '#head',
@ -137,7 +137,7 @@ const vuePreset = defineUnimportPreset({
] as Array<keyof typeof import('vue')>
})
export const defaultPresets = [
export const defaultPresets: InlinePreset[] = [
...commonPresets,
appPreset,
vuePreset

View File

@ -33,7 +33,7 @@
"scule": "^0.3.2",
"std-env": "^3.3.0",
"ufo": "^0.8.6",
"unimport": "^0.6.8",
"unimport": "^0.7.0",
"untyped": "^0.5.0"
},
"engines": {

View File

@ -7,7 +7,7 @@ import type { Manifest } from 'vue-bundle-renderer'
import type { EventHandler } from 'h3'
import type { ModuleContainer } from './module'
import type { NuxtTemplate, Nuxt, NuxtApp, ResolvedNuxtTemplate } from './nuxt'
import type { Preset as ImportPreset, Import } from 'unimport'
import type { Import, InlinePreset } from 'unimport'
import type { NuxtConfig, NuxtOptions } from './config'
import type { Nitro, NitroConfig } from 'nitropack'
import type { Component, ComponentsOptions } from './components'
@ -59,7 +59,7 @@ export type NuxtLayout = {
file: string
}
export interface ImportPresetWithDeprecation extends ImportPreset {
export interface ImportPresetWithDeprecation extends InlinePreset {
/**
* @deprecated renamed to `imports`
*/

View File

@ -318,7 +318,7 @@ importers:
semver: ^7.3.8
unbuild: ^0.9.4
unctx: ^2.0.2
unimport: ^0.6.8
unimport: ^0.7.0
untyped: ^0.5.0
dependencies:
'@nuxt/schema': link:../schema
@ -337,7 +337,7 @@ importers:
scule: 0.3.2
semver: 7.3.8
unctx: 2.0.2
unimport: 0.6.8
unimport: 0.7.0
untyped: 0.5.0
devDependencies:
'@types/lodash.template': 4.5.1
@ -446,7 +446,7 @@ importers:
unbuild: ^0.9.4
unctx: ^2.0.2
unenv: ^0.6.2
unimport: ^0.6.8
unimport: ^0.7.0
unplugin: ^0.10.1
untyped: ^0.5.0
vue: 3.2.41
@ -489,7 +489,7 @@ importers:
ultrahtml: 0.4.0
unctx: 2.0.2
unenv: 0.6.2
unimport: 0.6.8
unimport: 0.7.0
unplugin: 0.10.1
untyped: 0.5.0
vue: 3.2.41
@ -520,7 +520,7 @@ importers:
std-env: ^3.3.0
ufo: ^0.8.6
unbuild: ^0.9.4
unimport: ^0.6.8
unimport: ^0.7.0
untyped: ^0.5.0
vite: ^3.1.8
dependencies:
@ -534,7 +534,7 @@ importers:
scule: 0.3.2
std-env: 3.3.0
ufo: 0.8.6
unimport: 0.6.8
unimport: 0.7.0
untyped: 0.5.0
devDependencies:
'@types/lodash.template': 4.5.1
@ -1711,6 +1711,20 @@ packages:
rollup: 3.2.1
dev: true
/@rollup/pluginutils/5.0.2:
resolution: {integrity: sha512-pTd9rIsP92h+B6wWwFbW8RkZv4hiR/xKsqre4SIuAOaOEQRxi0lqLke9k2/7WegC85GgUs9pjmOjCUi3In4vwA==}
engines: {node: '>=14.0.0'}
peerDependencies:
rollup: ^1.20.0||^2.0.0||^3.0.0
peerDependenciesMeta:
rollup:
optional: true
dependencies:
'@types/estree': 1.0.0
estree-walker: 2.0.2
picomatch: 2.3.1
dev: false
/@sinclair/typebox/0.24.46:
resolution: {integrity: sha512-ng4ut1z2MCBhK/NwDVwIQp3pAUOCs/KNaW3cBxdFB2xTDrOuo1xuNmpr/9HHFhxqIvHrs1NTH3KJg6q+JSy1Kw==}
dev: false
@ -8587,6 +8601,24 @@ packages:
strip-literal: 0.4.2
unplugin: 0.9.6
/unimport/0.7.0:
resolution: {integrity: sha512-Cr0whz4toYVid3JHlni/uThwavDVVCk6Zw0Gxnol1c7DprTA+Isr4T+asO6rDGkhkgV7r3vSdSs5Ym8F15JA+w==}
dependencies:
'@rollup/pluginutils': 5.0.2
escape-string-regexp: 5.0.0
fast-glob: 3.2.12
local-pkg: 0.4.2
magic-string: 0.26.7
mlly: 0.5.16
pathe: 0.3.9
pkg-types: 0.3.5
scule: 0.3.2
strip-literal: 0.4.2
unplugin: 0.10.2
transitivePeerDependencies:
- rollup
dev: false
/universalify/2.0.0:
resolution: {integrity: sha512-hAZsKq7Yy11Zu1DE0OzWjw7nnLZmJZYTDZZyEFHZdUhV8FkH5MCfoU1XMaxXovpyW5nq5scPqq0ZDP9Zyl04oQ==}
engines: {node: '>= 10.0.0'}
@ -8663,6 +8695,15 @@ packages:
webpack-virtual-modules: 0.4.5
dev: false
/unplugin/0.10.2:
resolution: {integrity: sha512-6rk7GUa4ICYjae5PrAllvcDeuT8pA9+j5J5EkxbMFaV+SalHhxZ7X2dohMzu6C3XzsMT+6jwR/+pwPNR3uK9MA==}
dependencies:
acorn: 8.8.0
chokidar: 3.5.3
webpack-sources: 3.2.3
webpack-virtual-modules: 0.4.5
dev: false
/unplugin/0.9.6:
resolution: {integrity: sha512-YYLtfoNiie/lxswy1GOsKXgnLJTE27la/PeCGznSItk+8METYZErO+zzV9KQ/hXhPwzIJsfJ4s0m1Rl7ZCWZ4Q==}
dependencies: