Skip to content
This repository has been archived by the owner on Apr 6, 2023. It is now read-only.

Commit

Permalink
fix: update types
Browse files Browse the repository at this point in the history
  • Loading branch information
antfu committed Oct 18, 2022
1 parent 6164fd2 commit 0fc28e6
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 12 deletions.
8 changes: 6 additions & 2 deletions packages/kit/src/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,9 +127,13 @@ export function addWebpackPlugin (plugin: WebpackPluginInstance, options?: Exten
/**
* Append Vite plugin to the config.
*/
export function addVitePlugin (plugin: VitePlugin, options?: ExtendViteConfigOptions) {
export function addVitePlugin (plugin: VitePlugin | VitePlugin[], options?: ExtendViteConfigOptions) {
extendViteConfig((config) => {
config.plugins = config.plugins || []
config.plugins.push(plugin)
if (Array.isArray(plugin)) {
config.plugins.push(...plugin)
} else {
config.plugins.push(plugin)
}
}, options)
}
19 changes: 11 additions & 8 deletions packages/nuxt/src/core/nitro.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { resolvePath } from '@nuxt/kit'
import defu from 'defu'
import fsExtra from 'fs-extra'
import { dynamicEventHandler } from 'h3'
import { Plugin } from 'rollup'
import { distDir } from '../dirs'
import { ImportProtectionPlugin } from './plugins/import-protection'

Expand Down Expand Up @@ -121,14 +122,16 @@ export async function initNitro (nuxt: Nuxt & { _nitro?: Nitro }) {
}

// Register nuxt protection patterns
nitroConfig.rollupConfig!.plugins!.push(ImportProtectionPlugin.rollup({
rootDir: nuxt.options.rootDir,
patterns: [
...['#app', /^#build(\/|$)/]
.map(p => [p, 'Vue app aliases are not allowed in server routes.']) as [RegExp | string, string][]
],
exclude: [/core[\\/]runtime[\\/]nitro[\\/]renderer/]
}))
nitroConfig.rollupConfig!.plugins!.push(
ImportProtectionPlugin.rollup({
rootDir: nuxt.options.rootDir,
patterns: [
...['#app', /^#build(\/|$)/]
.map(p => [p, 'Vue app aliases are not allowed in server routes.']) as [RegExp | string, string][]
],
exclude: [/core[\\/]runtime[\\/]nitro[\\/]renderer/]
}) as Plugin
)

// Extend nitro config with hook
await nuxt.callHook('nitro:config', nitroConfig)
Expand Down
5 changes: 3 additions & 2 deletions packages/nuxt/test/auto-imports.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { join } from 'pathe'
import { createCommonJS, findExports } from 'mlly'
import * as VueFunctions from 'vue'
import { createUnimport, Import } from 'unimport'
import type { Plugin } from 'vite'
import { TransformPlugin } from '../src/imports/transform'
import { defaultPresets } from '../src/imports/presets'

Expand All @@ -18,9 +19,9 @@ describe('imports:transform', () => {
imports
})

const transformPlugin = TransformPlugin.raw({ ctx, options: { transform: { exclude: [/node_modules/] } } }, { framework: 'rollup' })
const transformPlugin = TransformPlugin.raw({ ctx, options: { transform: { exclude: [/node_modules/] } } }, { framework: 'rollup' }) as Plugin
const transform = async (source: string) => {
const result = await transformPlugin.transform!.call({ error: null, warn: null } as any, source, '')
const result = await (transformPlugin.transform as Function).call({ error: null, warn: null } as any, source, '')
return typeof result === 'string' ? result : result?.code
}

Expand Down

0 comments on commit 0fc28e6

Please sign in to comment.