这是indexloc提供的服务,不要输入任何密码
Skip to content

fix watch catch error, earlier prev process kill #277

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

Merged
merged 3 commits into from
Mar 17, 2021
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import { readFileSync } from 'fs'
import { join } from 'path'
import { cac } from 'cac'
import { handlError } from './errors'
import { handleError } from './errors'
import { Format, Options } from './'

function ensureArray(input: string): string[] {
Expand Down Expand Up @@ -98,4 +98,4 @@ async function main() {
await cli.runMatchedCommand()
}

main().catch(handlError)
main().catch(handleError)
2 changes: 1 addition & 1 deletion src/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export class PrettyError extends Error {
}
}

export function handlError(error: any) {
export function handleError(error: any) {
if (error.loc) {
console.error(
colors.bold(
Expand Down
8 changes: 4 additions & 4 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {
} from './utils'
import { FSWatcher } from 'chokidar'
import glob from 'globby'
import { PrettyError } from './errors'
import { PrettyError, handleError } from './errors'
import { postcssPlugin } from './esbuild/postcss'
import { externalPlugin } from './esbuild/external'
import { sveltePlugin } from './esbuild/svelte'
Expand Down Expand Up @@ -344,13 +344,15 @@ export async function build(_options: Options) {
ignoreInitial: true,
}
).on('all', async () => {
await buildAll()
await buildAll().catch(handleError)
})
}

let existingOnSuccess: ChildProcess | undefined

const buildAll = async () => {
if (existingOnSuccess) existingOnSuccess.kill()

if (options.clean) {
await removeFiles(['**/*', '!**/*.d.ts'], options.outDir)
console.log(makeLabel('CLI', 'info'), `Cleaning output folder`)
Expand All @@ -363,8 +365,6 @@ export async function build(_options: Options) {
),
])
if (options.onSuccess) {
if (existingOnSuccess) existingOnSuccess.kill()

const parts = parseArgsStringToArgv(options.onSuccess)
const exec = parts[0]
const args = parts.splice(1)
Expand Down
6 changes: 3 additions & 3 deletions src/rollup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { makeLabel, NormalizedOptions } from './'
import dtsPlugin from 'rollup-plugin-dts'
import hashbangPlugin from 'rollup-plugin-hashbang'
import jsonPlugin from '@rollup/plugin-json'
import { handlError } from './errors'
import { handleError } from './errors'
import { getDeps, removeFiles } from './utils'
import { TsResolveOptions, tsResolvePlugin } from './rollup/ts-resolve'

Expand Down Expand Up @@ -89,7 +89,7 @@ async function runRollup(options: RollupConfig) {
)
} catch (error) {
console.log(`${makeLabel('dts', 'error')} Build error`)
handlError(error)
handleError(error)
}
}

Expand All @@ -115,7 +115,7 @@ async function watchRollup(options: {
)
} else if (event.code === 'ERROR') {
console.log(`${makeLabel('dts', 'error')} Build error`)
handlError(event.error)
handleError(event.error)
}
})
}
Expand Down