Skip to content

Commit

Permalink
feat(nuxi): allow passing overrides to other nuxi commands (nuxt#20760)
Browse files Browse the repository at this point in the history
  • Loading branch information
danielroe committed May 10, 2023
1 parent 53fef72 commit 29f2930
Show file tree
Hide file tree
Showing 8 changed files with 22 additions and 16 deletions.
7 changes: 4 additions & 3 deletions packages/nuxi/src/commands/analyze.ts
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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

0 comments on commit 29f2930

Please sign in to comment.