Skip to content

Commit

Permalink
feat: upgrade unimport to 0.7.0 (nuxt#8483)
Browse files Browse the repository at this point in the history
  • Loading branch information
antfu authored Oct 26, 2022
1 parent 12808f1 commit bbea416
Show file tree
Hide file tree
Showing 7 changed files with 62 additions and 20 deletions.
2 changes: 1 addition & 1 deletion packages/kit/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
2 changes: 1 addition & 1 deletion packages/nuxt/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
13 changes: 7 additions & 6 deletions packages/nuxt/src/imports/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down Expand Up @@ -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')

Expand All @@ -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 () => {};`
Expand Down Expand Up @@ -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.'
)
})
Expand Down
6 changes: 3 additions & 3 deletions packages/nuxt/src/imports/presets.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { defineUnimportPreset, Preset } from 'unimport'
import { defineUnimportPreset, InlinePreset } from 'unimport'

const commonPresets: Preset[] = [
const commonPresets: InlinePreset[] = [
// #head
defineUnimportPreset({
from: '#head',
Expand Down Expand Up @@ -137,7 +137,7 @@ const vuePreset = defineUnimportPreset({
] as Array<keyof typeof import('vue')>
})

export const defaultPresets = [
export const defaultPresets: InlinePreset[] = [
...commonPresets,
appPreset,
vuePreset
Expand Down
2 changes: 1 addition & 1 deletion packages/schema/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
4 changes: 2 additions & 2 deletions packages/schema/src/types/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -59,7 +59,7 @@ export type NuxtLayout = {
file: string
}

export interface ImportPresetWithDeprecation extends ImportPreset {
export interface ImportPresetWithDeprecation extends InlinePreset {
/**
* @deprecated renamed to `imports`
*/
Expand Down
53 changes: 47 additions & 6 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit bbea416

Please sign in to comment.