feat(nuxt): auto-install @nuxt/webpack-builder when needed (#21747)

This commit is contained in:
Jean-Pierre Carvalho 2023-07-30 21:25:00 +01:00 committed by GitHub
parent 2df9a4b9db
commit 620097241a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 13 additions and 6 deletions

View File

@ -78,7 +78,6 @@
"jiti": "^1.19.1",
"klona": "^2.0.6",
"knitwork": "^1.0.0",
"local-pkg": "^0.4.3",
"magic-string": "^0.30.2",
"mlly": "^1.4.0",
"nitropack": "^2.5.2",
@ -88,6 +87,7 @@
"ohash": "^1.1.2",
"pathe": "^1.1.1",
"perfect-debounce": "^1.0.0",
"pkg-types": "^1.0.3",
"prompts": "^2.4.2",
"scule": "^1.0.0",
"strip-literal": "^1.0.1",

View File

@ -1,10 +1,10 @@
import { addDependency } from 'nypm'
import { isPackageExists } from 'local-pkg'
import { resolvePackageJSON } from 'pkg-types'
import { logger } from '@nuxt/kit'
import prompts from 'prompts'
export async function ensurePackageInstalled (rootDir: string, name: string, searchPaths?: string[]) {
if (isPackageExists(name, { paths: searchPaths })) {
if (await resolvePackageJSON(name, { url: searchPaths }).catch(() => null)) {
return true
}

View File

@ -411,6 +411,13 @@ export async function loadNuxt (opts: LoadNuxtOptions): Promise<Nuxt> {
}
}
// Nuxt Webpack Builder is currently opt-in
if (options.builder === '@nuxt/webpack-builder') {
if (!await import('./features').then(r => r.ensurePackageInstalled(options.rootDir, '@nuxt/webpack-builder', options.modulesDir))) {
logger.warn('Failed to install `@nuxt/webpack-builder`, please install it manually, or change the `builder` option to vite in `nuxt.config`')
}
}
// Add core modules
options._modules.push(pagesModule, metaModule, componentsModule)
options._modules.push([importsModule, {

View File

@ -415,9 +415,6 @@ importers:
knitwork:
specifier: ^1.0.0
version: 1.0.0
local-pkg:
specifier: ^0.4.3
version: 0.4.3
magic-string:
specifier: ^0.30.2
version: 0.30.2
@ -445,6 +442,9 @@ importers:
perfect-debounce:
specifier: ^1.0.0
version: 1.0.0
pkg-types:
specifier: ^1.0.3
version: 1.0.3
prompts:
specifier: ^2.4.2
version: 2.4.2