Skip to content

Commit

Permalink
[autofix.ci] apply automated fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
autofix-ci[bot] authored May 16, 2024
1 parent 666dfd4 commit 752a9d5
Show file tree
Hide file tree
Showing 26 changed files with 193 additions and 232 deletions.
4 changes: 2 additions & 2 deletions src/commands/add.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ export default defineCommand({

const template = ctx.args.template
const ext = extname(ctx.args.name)
const name
= ext === '.vue' || ext === '.ts'
const name =

Check failure on line 37 in src/commands/add.ts

View workflow job for this annotation

GitHub Actions / ci

'=' should be placed at the beginning of the line
ext === '.vue' || ext === '.ts'
? ctx.args.name.replace(ext, '')
: ctx.args.name

Expand Down
4 changes: 2 additions & 2 deletions src/commands/analyze.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ export default defineCommand({

const analyzeDir = nuxt.options.analyzeDir
const buildDir = nuxt.options.buildDir
const outDir
= nuxt.options.nitro.output?.dir || join(nuxt.options.rootDir, '.output')
const outDir =

Check failure on line 57 in src/commands/analyze.ts

View workflow job for this annotation

GitHub Actions / ci

'=' should be placed at the beginning of the line
nuxt.options.nitro.output?.dir || join(nuxt.options.rootDir, '.output')

nuxt.options.build.analyze = defu(nuxt.options.build.analyze, {
filename: join(analyzeDir, 'client.html'),
Expand Down
3 changes: 1 addition & 2 deletions src/commands/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,7 @@ export default defineCommand({
try {
// Use ? for backward compatibility for Nuxt <= RC.10
nitro = kit.useNitro?.()
}
catch {
} catch {

Check failure on line 69 in src/commands/build.ts

View workflow job for this annotation

GitHub Actions / ci

Closing curly brace appears on the same line as the subsequent block
//
}

Expand Down
17 changes: 6 additions & 11 deletions src/commands/dev-child.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,8 @@ import { consola } from 'consola'
import { defineCommand } from 'citty'
import { isTest } from 'std-env'
import { overrideEnv } from '../utils/env'
import type {
NuxtDevContext,
NuxtDevIPCMessage } from '../utils/dev'
import {
createNuxtDevServer,
} from '../utils/dev'
import type { NuxtDevContext, NuxtDevIPCMessage } from '../utils/dev'
import { createNuxtDevServer } from '../utils/dev'
import { sharedArgs, legacyRootDirArgs } from './_shared'

export default defineCommand({
Expand All @@ -35,8 +31,8 @@ export default defineCommand({
const cwd = resolve(ctx.args.cwd || ctx.args.rootDir || '.')

// Get dev context info
const devContext: NuxtDevContext
= JSON.parse(process.env.__NUXT_DEV__ || 'null') || {}
const devContext: NuxtDevContext =

Check failure on line 34 in src/commands/dev-child.ts

View workflow job for this annotation

GitHub Actions / ci

'=' should be placed at the beginning of the line
JSON.parse(process.env.__NUXT_DEV__ || 'null') || {}

// Init Nuxt dev
const nuxtDev = await createNuxtDevServer({
Expand All @@ -53,12 +49,11 @@ export default defineCommand({
function sendIPCMessage<T extends NuxtDevIPCMessage>(message: T) {
if (process.send) {
process.send(message)
}
else {
} else {

Check failure on line 52 in src/commands/dev-child.ts

View workflow job for this annotation

GitHub Actions / ci

Closing curly brace appears on the same line as the subsequent block
logger.info(
'Dev server event:',
Object.entries(message)
.map(e => e[0] + '=' + JSON.stringify(e[1]))
.map((e) => e[0] + '=' + JSON.stringify(e[1]))

Check failure on line 56 in src/commands/dev-child.ts

View workflow job for this annotation

GitHub Actions / ci

Unexpected parentheses around single function argument having a body with no curly braces
.join(' '),
)
}
Expand Down
106 changes: 53 additions & 53 deletions src/commands/dev.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,7 @@ const command = defineCommand({
const devProxy = await _createDevProxy(nuxtOptions, listenOptions)
await _startSubprocess(devProxy, ctx.rawArgs)
return { listener: devProxy?.listener }
}
else {
} else {

Check failure on line 73 in src/commands/dev.ts

View workflow job for this annotation

GitHub Actions / ci

Closing curly brace appears on the same line as the subsequent block
// Directly start Nuxt dev
const { createNuxtDevServer } = await import('../utils/dev')
const devServer = await createNuxtDevServer(
Expand All @@ -96,7 +95,10 @@ export default command

// --- Internal ---

type ArgsT = Exclude<Awaited<typeof command.args>, undefined | ((...args: unknown[]) => unknown)>
type ArgsT = Exclude<
Awaited<typeof command.args>,
undefined | ((...args: unknown[]) => unknown)
>

type DevProxy = Awaited<ReturnType<typeof _createDevProxy>>

Expand All @@ -105,10 +107,10 @@ async function _createDevProxy(
listenOptions: Partial<ListenOptions>,
) {
let loadingMessage = 'Nuxt dev server is starting...'
const loadingTemplate
= nuxtOptions.devServer.loadingTemplate
?? (await importModule('@nuxt/ui-templates', nuxtOptions.modulesDir).then(
r => r.loading,
const loadingTemplate =

Check failure on line 110 in src/commands/dev.ts

View workflow job for this annotation

GitHub Actions / ci

'=' should be placed at the beginning of the line
nuxtOptions.devServer.loadingTemplate ??

Check failure on line 111 in src/commands/dev.ts

View workflow job for this annotation

GitHub Actions / ci

'??' should be placed at the beginning of the line
(await importModule('@nuxt/ui-templates', nuxtOptions.modulesDir).then(
(r) => r.loading,

Check failure on line 113 in src/commands/dev.ts

View workflow job for this annotation

GitHub Actions / ci

Unexpected parentheses around single function argument having a body with no curly braces
))

const { createProxyServer } = await import('httpxy')
Expand Down Expand Up @@ -194,12 +196,10 @@ async function _startSubprocess(devProxy: DevProxy, rawArgs: string[]) {
childProc.on('message', (message: NuxtDevIPCMessage) => {
if (message.type === 'nuxt:internal:dev:ready') {
devProxy.setAddress(`http://127.0.0.1:${message.port}`)
}
else if (message.type === 'nuxt:internal:dev:loading') {
} else if (message.type === 'nuxt:internal:dev:loading') {
devProxy.setAddress(undefined)
devProxy.setLoadingMessage(message.message)
}
else if (message.type === 'nuxt:internal:dev:restart') {
} else if (message.type === 'nuxt:internal:dev:restart') {
restart()
}
})
Expand Down Expand Up @@ -229,57 +229,57 @@ function _resolveListenOptions(
nuxtOptions: NuxtOptions,
args: ParsedArgs<ArgsT>,
): Partial<ListenOptions> {
const _port
= args.port
?? args.p
?? process.env.NUXT_PORT
?? process.env.NITRO_PORT
?? process.env.PORT
?? nuxtOptions.devServer.port

const _hostname
= typeof args.host === 'string'
const _port =
args.port ??
args.p ??
process.env.NUXT_PORT ??
process.env.NITRO_PORT ??
process.env.PORT ??
nuxtOptions.devServer.port

const _hostname =
typeof args.host === 'string'
? args.host
: (args.host === true ? '' : undefined)
?? process.env.NUXT_HOST
?? process.env.NITRO_HOST
?? process.env.HOST
: (args.host === true ? '' : undefined) ??
process.env.NUXT_HOST ??
process.env.NITRO_HOST ??
process.env.HOST ??
// TODO: Default host in schema should be undefined instead of ''
?? nuxtOptions._layers?.[0].config?.devServer?.host
?? undefined
nuxtOptions._layers?.[0].config?.devServer?.host ??
undefined

const _public: boolean | undefined
= args.public
?? (_hostname && !['localhost', '127.0.0.1', '::1'].includes(_hostname))
const _public: boolean | undefined =
args.public ??
(_hostname && !['localhost', '127.0.0.1', '::1'].includes(_hostname))
? true
: undefined

const _httpsCert
= args['https.cert']
|| (args.sslCert as string)
|| process.env.NUXT_SSL_CERT
|| process.env.NITRO_SSL_CERT
|| (typeof nuxtOptions.devServer.https !== 'boolean'
&& nuxtOptions.devServer.https?.cert)
|| ''

const _httpsKey
= args['https.key']
|| (args.sslKey as string)
|| process.env.NUXT_SSL_KEY
|| process.env.NITRO_SSL_KEY
|| (typeof nuxtOptions.devServer.https !== 'boolean'
&& nuxtOptions.devServer.https?.key)
|| ''

const httpsEnabled
= args.https == true
|| (args.https === undefined && !!nuxtOptions.devServer.https)
const _httpsCert =
args['https.cert'] ||
(args.sslCert as string) ||
process.env.NUXT_SSL_CERT ||
process.env.NITRO_SSL_CERT ||
(typeof nuxtOptions.devServer.https !== 'boolean' &&
nuxtOptions.devServer.https?.cert) ||
''

const _httpsKey =
args['https.key'] ||
(args.sslKey as string) ||
process.env.NUXT_SSL_KEY ||
process.env.NITRO_SSL_KEY ||
(typeof nuxtOptions.devServer.https !== 'boolean' &&
nuxtOptions.devServer.https?.key) ||
''

const httpsEnabled =
args.https == true ||
(args.https === undefined && !!nuxtOptions.devServer.https)

const _listhenOptions = parseListhenArgs({
...args,
'open': (args.o as boolean) || args.open,
'https': httpsEnabled,
open: (args.o as boolean) || args.open,
https: httpsEnabled,
'https.cert': _httpsCert,
'https.key': _httpsKey,
})
Expand Down
34 changes: 17 additions & 17 deletions src/commands/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,22 @@ import type { CommandDef } from 'citty'
const _rDefault = (r: any) => (r.default || r) as Promise<CommandDef>

export const commands = {
'add': () => import('./add').then(_rDefault),
'analyze': () => import('./analyze').then(_rDefault),
add: () => import('./add').then(_rDefault),
analyze: () => import('./analyze').then(_rDefault),
'build-module': () => import('./build-module').then(_rDefault),
'build': () => import('./build').then(_rDefault),
'cleanup': () => import('./cleanup').then(_rDefault),
'_dev': () => import('./dev-child').then(_rDefault),
'dev': () => import('./dev').then(_rDefault),
'devtools': () => import('./devtools').then(_rDefault),
'generate': () => import('./generate').then(_rDefault),
'info': () => import('./info').then(_rDefault),
'init': () => import('./init').then(_rDefault),
'module': () => import('./module').then(_rDefault),
'prepare': () => import('./prepare').then(_rDefault),
'preview': () => import('./preview').then(_rDefault),
'start': () => import('./preview').then(_rDefault),
'test': () => import('./test').then(_rDefault),
'typecheck': () => import('./typecheck').then(_rDefault),
'upgrade': () => import('./upgrade').then(_rDefault),
build: () => import('./build').then(_rDefault),
cleanup: () => import('./cleanup').then(_rDefault),
_dev: () => import('./dev-child').then(_rDefault),
dev: () => import('./dev').then(_rDefault),
devtools: () => import('./devtools').then(_rDefault),
generate: () => import('./generate').then(_rDefault),
info: () => import('./info').then(_rDefault),
init: () => import('./init').then(_rDefault),
module: () => import('./module').then(_rDefault),
prepare: () => import('./prepare').then(_rDefault),
preview: () => import('./preview').then(_rDefault),
start: () => import('./preview').then(_rDefault),
test: () => import('./test').then(_rDefault),
typecheck: () => import('./typecheck').then(_rDefault),
upgrade: () => import('./upgrade').then(_rDefault),
} as const
42 changes: 19 additions & 23 deletions src/commands/info.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export default defineCommand({

const listModules = (arr = []) =>
arr
.map(m => normalizeConfigModule(m, cwd))
.map((m) => normalizeConfigModule(m, cwd))
.filter(Boolean)
.map((name) => {
const npmName = name!.split('/').splice(0, 2).join('/') // @foo/bar/baz => @foo/bar
Expand All @@ -54,12 +54,12 @@ export default defineCommand({
.join(', ')

// Check Nuxt version
const nuxtVersion
= getDepVersion('nuxt')
|| getDepVersion('nuxt-nightly')
|| getDepVersion('nuxt-edge')
|| getDepVersion('nuxt3')
|| '-'
const nuxtVersion =
getDepVersion('nuxt') ||
getDepVersion('nuxt-nightly') ||
getDepVersion('nuxt-edge') ||
getDepVersion('nuxt3') ||
'-'
const isLegacy = nuxtVersion.startsWith('2')
const builder = !isLegacy
? nuxtConfig.builder /* latest schema */ || '-'
Expand All @@ -69,12 +69,11 @@ export default defineCommand({
? 'vite' /* nuxt-vite */
: 'webpack'

let packageManager: keyof typeof packageManagerLocks | 'unknown' | null
= getPackageManager(cwd)
let packageManager: keyof typeof packageManagerLocks | 'unknown' | null =
getPackageManager(cwd)
if (packageManager) {
packageManager += '@' + getPackageManagerVersion(packageManager)
}
else {
} else {
packageManager = 'unknown'
}

Expand All @@ -87,7 +86,7 @@ export default defineCommand({
PackageManager: packageManager,
Builder: builder,
UserConfig: Object.keys(nuxtConfig)
.map(key => '`' + key + '`')
.map((key) => '`' + key + '`')
.join(', '),
RuntimeModules: listModules(nuxtConfig.modules),
BuildModules: listModules(nuxtConfig.buildModules || []),
Expand All @@ -105,11 +104,11 @@ export default defineCommand({
})
let infoStr = ''
for (const [label, value] of entries) {
infoStr
+= '- '
+ (label + ': ').padEnd(maxLength + 2)
+ (value.includes('`') ? value : '`' + value + '`')
+ '\n'
infoStr +=
'- ' +
(label + ': ').padEnd(maxLength + 2) +
(value.includes('`') ? value : '`' + value + '`') +
'\n'
}

const copied = await clipboardy
Expand Down Expand Up @@ -168,8 +167,7 @@ function getNuxtConfig(rootDir: string) {
)
delete (globalThis as any).defineNuxtConfig
return result
}
catch (err) {
} catch (err) {
// TODO: Show error as warning if it is not 404
return {}
}
Expand All @@ -183,8 +181,7 @@ function getPkg(name: string, rootDir: string) {
const _require = createRequire(rootDir)
try {
pkgPath = _require.resolve(name + '/package.json')
}
catch (_err) {
} catch (_err) {
// console.log('not found:', name)
}

Expand All @@ -205,8 +202,7 @@ function findPackage(rootDir: string) {
function readJSONSync(filePath: string) {
try {
return destr(readFileSync(filePath, 'utf-8'))
}
catch (err) {
} catch (err) {
// TODO: Warn error
return null
}
Expand Down
Loading

0 comments on commit 752a9d5

Please sign in to comment.