Skip to content

Commit

Permalink
fix(cli): handle perf.json path when output is overriden
Browse files Browse the repository at this point in the history
closes #85
  • Loading branch information
pionxzh committed Dec 28, 2023
1 parent e3da389 commit 332c84b
Showing 1 changed file with 19 additions and 16 deletions.
35 changes: 19 additions & 16 deletions packages/cli/src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -462,26 +462,29 @@ async function nonInteractive(features: Feature[], {
const unpackerOutput = _unpackerOutput ?? (singleFeature ? outputBase : path.join(outputBase, defaultUnpackerOutputFolder))
const unminifyOutput = _unminifyOutput ?? (singleFeature ? outputBase : path.join(outputBase, defaultUnminifyOutputFolder))

if (!isPathInside(cwd, outputBase)) {
log.error('Output directory must be inside the current working directory')
return process.exit(1)
}
const perfOutputBase = singleFeature
? features.includes(Feature.Unpacker) ? unpackerOutput : unminifyOutput
: outputBase
const perfOutputPath = path.join(perfOutputBase, 'perf.json')

if (!force) {
if (fsa.existsSync(outputBase)) {
log.error(`Output directory already exists at ${c.green(outputBase)}. Pass ${c.green('--force')} to overwrite`)
return process.exit(1)
}
const outputPathsToCheck = []
if (features.includes(Feature.Unpacker)) outputPathsToCheck.push(unpackerOutput)
if (features.includes(Feature.Unminify)) outputPathsToCheck.push(unminifyOutput)

if (features.includes(Feature.Unpacker) && fsa.existsSync(unpackerOutput)) {
log.error(`Output directory already exists at ${c.green(unpackerOutput)}. Pass ${c.green('--force')} to overwrite`)
outputPathsToCheck.forEach((p) => {
if (!isPathInside(cwd, p)) {
log.error('Output directory must be inside the current working directory')
return process.exit(1)
}
})

if (features.includes(Feature.Unminify) && fsa.existsSync(unminifyOutput)) {
log.error(`Output directory already exists at ${c.green(unminifyOutput)}. Pass ${c.green('--force')} to overwrite`)
return process.exit(1)
}
if (!force) {
outputPathsToCheck.forEach((p) => {
if (fsa.existsSync(p)) {
log.error(`Output directory already exists at ${c.green(getRelativePath(cwd, p))}. Pass ${c.green('--force')} to overwrite`)
return process.exit(1)
}
})
}

const minConcurrency = 1
Expand Down Expand Up @@ -567,7 +570,7 @@ async function nonInteractive(features: Feature[], {
if (perf) {
printPerfStats(measurements)

writePerfStats(measurements, path.join(outputBase, 'perf.json'))
writePerfStats(measurements, perfOutputPath)
}
}
}
Expand Down

0 comments on commit 332c84b

Please sign in to comment.