mirror of
https://github.com/egoist/tsup.git
synced 2025-12-08 20:35:58 +00:00
fix: start dts build as soon as possible
This commit is contained in:
parent
d0fb8df7b1
commit
1ebe663b28
@ -35,6 +35,6 @@ export function handleError(error: any) {
|
||||
}
|
||||
process.exitCode = 1
|
||||
if (!isMainThread && parentPort) {
|
||||
parentPort.postMessage('has-error')
|
||||
parentPort.postMessage('error')
|
||||
}
|
||||
}
|
||||
|
||||
45
src/index.ts
45
src/index.ts
@ -144,6 +144,25 @@ export async function build(_options: Options) {
|
||||
logger.info('CLI', 'Running in watch mode')
|
||||
}
|
||||
|
||||
if (options.dts) {
|
||||
const worker = new Worker(path.join(__dirname, './rollup.js'))
|
||||
worker.postMessage({
|
||||
configName: item?.name,
|
||||
options: {
|
||||
...options, // functions cannot be cloned
|
||||
esbuildPlugins: undefined,
|
||||
esbuildOptions: undefined,
|
||||
},
|
||||
})
|
||||
worker.on('message', (data) => {
|
||||
if (data === 'error') {
|
||||
process.exitCode = 1
|
||||
} else if (data === 'success') {
|
||||
process.exitCode = 0
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
if (!options.dts?.only) {
|
||||
let existingOnSuccess: ChildProcess | undefined
|
||||
/** Files imported by the entry */
|
||||
@ -195,7 +214,7 @@ export async function build(_options: Options) {
|
||||
await runEsbuild(options, {
|
||||
pluginContainer,
|
||||
format,
|
||||
css: (index === 0 || options.injectStyle) ? css : undefined,
|
||||
css: index === 0 || options.injectStyle ? css : undefined,
|
||||
logger,
|
||||
buildDependencies,
|
||||
})
|
||||
@ -273,30 +292,6 @@ export async function build(_options: Options) {
|
||||
|
||||
startWatcher()
|
||||
}
|
||||
|
||||
if (options.dts) {
|
||||
const hasTypescript = resolveFrom.silent(process.cwd(), 'typescript')
|
||||
if (!hasTypescript) {
|
||||
throw new Error(`You need to install "typescript" in your project`)
|
||||
}
|
||||
|
||||
const worker = new Worker(path.join(__dirname, './rollup.js'))
|
||||
worker.postMessage({
|
||||
configName: item?.name,
|
||||
options: {
|
||||
...options, // functions cannot be cloned
|
||||
esbuildPlugins: undefined,
|
||||
esbuildOptions: undefined,
|
||||
},
|
||||
})
|
||||
worker.on('message', (data) => {
|
||||
if (data === 'error') {
|
||||
process.exitCode = 1
|
||||
} else if (data === 'success') {
|
||||
process.exitCode = 0
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
)
|
||||
)
|
||||
|
||||
@ -11,6 +11,7 @@ import { createLogger, setSilent } from './log'
|
||||
import { getDeps } from './load'
|
||||
import path from 'path'
|
||||
import { reportSize } from './lib/report-size'
|
||||
import resolveFrom from 'resolve-from'
|
||||
|
||||
const logger = createLogger()
|
||||
|
||||
@ -196,7 +197,6 @@ async function runRollup(options: RollupConfig) {
|
||||
)
|
||||
} catch (error) {
|
||||
logger.error('dts', 'Build error')
|
||||
parentPort?.postMessage('error')
|
||||
handleError(error)
|
||||
}
|
||||
}
|
||||
@ -219,7 +219,6 @@ async function watchRollup(options: {
|
||||
parentPort?.postMessage('success')
|
||||
} else if (event.code === 'ERROR') {
|
||||
logger.error('dts', 'Build failed')
|
||||
parentPort?.postMessage('error')
|
||||
handleError(event.error)
|
||||
}
|
||||
})
|
||||
@ -237,5 +236,12 @@ const startRollup = async (options: NormalizedOptions) => {
|
||||
|
||||
parentPort?.on('message', (data) => {
|
||||
logger.setName(data.configName)
|
||||
const hasTypescript = resolveFrom.silent(process.cwd(), 'typescript')
|
||||
if (!hasTypescript) {
|
||||
logger.error('dts', `You need to install "typescript" in your project`)
|
||||
parentPort?.postMessage('error')
|
||||
parentPort?.close()
|
||||
return
|
||||
}
|
||||
startRollup(data.options)
|
||||
})
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user