Skip to content

Commit

Permalink
fix: improve output dir handling
Browse files Browse the repository at this point in the history
  • Loading branch information
antfu committed Apr 19, 2023
1 parent 6e90de2 commit b62474d
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions src/node/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { join, resolve } from 'node:path'
import { isAbsolute, join, resolve } from 'node:path'
import fs from 'fs-extra'
import _debug from 'debug'
import type { Plugin, ResolvedConfig, ViteDevServer } from 'vite'
Expand Down Expand Up @@ -384,10 +384,17 @@ export default function PluginInspect(options: Options = {}): Plugin {

async function generateBuild() {
// outputs data to `node_modules/.vite/inspect folder
const targetDir = join(config.root, outputDir)
const targetDir = isAbsolute(outputDir)
? outputDir
: resolve(config.root, outputDir)
const reportsDir = join(targetDir, 'reports')

await fs.mkdir(targetDir, { recursive: true })
await fs.rm(targetDir, {
recursive: true,
force: true,
})
await fs.ensureDir(targetDir)
await fs.ensureDir(reportsDir)

await fs.copy(DIR_CLIENT, targetDir, { overwrite: true })

Expand All @@ -400,13 +407,6 @@ export default function PluginInspect(options: Options = {}): Plugin {
),
)

await fs.rm(reportsDir, {
recursive: true,
force: true,
})

await fs.mkdir(reportsDir, { recursive: true })

const isVirtual = (pluginName: string, transformName: string) => pluginName !== dummyLoadPluginName && transformName !== 'vite:load-fallback'

function list() {
Expand Down

0 comments on commit b62474d

Please sign in to comment.