Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(nuxi): allow passing overrides to other nuxi commands #20760

Merged
merged 3 commits into from May 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 4 additions & 3 deletions packages/nuxi/src/commands/analyze.ts
Expand Up @@ -3,6 +3,7 @@ import { join, resolve } from 'pathe'
import { createApp, eventHandler, lazyEventHandler, toNodeListener } from 'h3'
import { listen } from 'listhen'
import type { NuxtAnalyzeMeta } from '@nuxt/schema'
import { defu } from 'defu'
import { loadKit } from '../utils/kit'
import { clearDir } from '../utils/fs'
import { overrideEnv } from '../utils/env'
Expand All @@ -14,7 +15,7 @@ export default defineNuxtCommand({
usage: 'npx nuxi analyze [--log-level] [--name] [--no-serve] [rootDir]',
description: 'Build nuxt and analyze production bundle (experimental)'
},
async invoke (args) {
async invoke (args, options = {}) {
overrideEnv('production')

const name = args.name || 'default'
Expand All @@ -31,7 +32,7 @@ export default defineNuxtCommand({

const nuxt = await loadNuxt({
rootDir,
overrides: {
overrides: defu(options.overrides, {
build: {
analyze: true
},
Expand All @@ -43,7 +44,7 @@ export default defineNuxtCommand({
}
},
logLevel: args['log-level']
}
})
})

analyzeDir = nuxt.options.analyzeDir
Expand Down
3 changes: 2 additions & 1 deletion packages/nuxi/src/commands/build-module.ts
Expand Up @@ -18,7 +18,8 @@ export default defineNuxtCommand({
const hasLocal = await tryResolveModule(`${MODULE_BUILDER_PKG}/package.json`, rootDir)

const execArgs = Object.entries({
'--stub': args.stub
'--stub': args.stub,
'--prepare': args.prepare
}).filter(([, value]) => value).map(([key]) => key)

let cmd = 'nuxt-module-build'
Expand Down
5 changes: 3 additions & 2 deletions packages/nuxi/src/commands/build.ts
Expand Up @@ -13,7 +13,7 @@ export default defineNuxtCommand({
usage: 'npx nuxi build [--prerender] [--dotenv] [--log-level] [rootDir]',
description: 'Build nuxt for production deployment'
},
async invoke (args) {
async invoke (args, options = {}) {
overrideEnv('production')

const rootDir = resolve(args._[0] || '.')
Expand All @@ -29,7 +29,8 @@ export default defineNuxtCommand({
},
overrides: {
logLevel: args['log-level'],
_generate: args.prerender
_generate: args.prerender,
...(options?.overrides || {})
}
})

Expand Down
4 changes: 2 additions & 2 deletions packages/nuxi/src/commands/generate.ts
Expand Up @@ -7,8 +7,8 @@ export default defineNuxtCommand({
usage: 'npx nuxi generate [rootDir] [--dotenv]',
description: 'Build Nuxt and prerender static routes'
},
async invoke (args) {
async invoke (args, options = {}) {
args.prerender = true
await buildCommand.invoke(args)
await buildCommand.invoke(args, options)
}
})
5 changes: 3 additions & 2 deletions packages/nuxi/src/commands/prepare.ts
Expand Up @@ -11,7 +11,7 @@ export default defineNuxtCommand({
usage: 'npx nuxi prepare [--log-level] [rootDir]',
description: 'Prepare nuxt for development/build'
},
async invoke (args) {
async invoke (args, options = {}) {
process.env.NODE_ENV = process.env.NODE_ENV || 'production'
const rootDir = resolve(args._[0] || '.')

Expand All @@ -20,7 +20,8 @@ export default defineNuxtCommand({
rootDir,
overrides: {
_prepare: true,
logLevel: args['log-level']
logLevel: args['log-level'],
...(options.overrides || {})
}
})
await clearBuildDir(nuxt.options.buildDir)
Expand Down
4 changes: 2 additions & 2 deletions packages/nuxi/src/commands/preview.ts
Expand Up @@ -14,11 +14,11 @@ export default defineNuxtCommand({
usage: 'npx nuxi preview|start [--dotenv] [rootDir]',
description: 'Launches nitro server for local testing after `nuxi build`.'
},
async invoke (args) {
async invoke (args, options = {}) {
process.env.NODE_ENV = process.env.NODE_ENV || 'production'
const rootDir = resolve(args._[0] || '.')
const { loadNuxtConfig } = await loadKit(rootDir)
const config = await loadNuxtConfig({ cwd: rootDir })
const config = await loadNuxtConfig({ cwd: rootDir, overrides: options?.overrides || {} })

const resolvedOutputDir = resolve(config.srcDir || rootDir, config.nitro.srcDir || 'server', config.nitro.output?.dir || '.output', 'nitro.json')
const defaultOutput = resolve(rootDir, '.output', 'nitro.json') // for backwards compatibility
Expand Down
5 changes: 3 additions & 2 deletions packages/nuxi/src/commands/test.ts
Expand Up @@ -7,14 +7,15 @@ export default defineNuxtCommand({
usage: 'npx nuxi test [--dev] [--watch] [rootDir]',
description: 'Run tests'
},
async invoke (args) {
async invoke (args, options = {}) {
process.env.NODE_ENV = process.env.NODE_ENV || 'test'
const rootDir = resolve(args._[0] || '.')
const { runTests } = await importTestUtils()
await runTests({
rootDir,
dev: !!args.dev,
watch: !!args.watch
watch: !!args.watch,
...(options || {})
})

if (args.watch) {
Expand Down
5 changes: 3 additions & 2 deletions packages/nuxi/src/commands/typecheck.ts
Expand Up @@ -12,7 +12,7 @@ export default defineNuxtCommand({
usage: 'npx nuxi typecheck [--log-level] [rootDir]',
description: 'Runs `vue-tsc` to check types throughout your app.'
},
async invoke (args) {
async invoke (args, options = {}) {
process.env.NODE_ENV = process.env.NODE_ENV || 'production'
const rootDir = resolve(args._[0] || '.')

Expand All @@ -21,7 +21,8 @@ export default defineNuxtCommand({
rootDir,
overrides: {
_prepare: true,
logLevel: args['log-level']
logLevel: args['log-level'],
...(options?.overrides || {})
}
})

Expand Down