Skip to content

Commit

Permalink
fix(mkdist): rmdir before stubbing
Browse files Browse the repository at this point in the history
  • Loading branch information
pi0 committed Apr 21, 2021
1 parent f7c03e2 commit 1ca50a4
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 7 deletions.
6 changes: 4 additions & 2 deletions src/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ import consola from 'consola'
import defu from 'defu'
import prettyBytes from 'pretty-bytes'
import jiti from 'jiti'
import { dumpObject, cleanDir } from './utils'
import mkdirp from 'mkdirp'
import { dumpObject, rmdir } from './utils'
import type { BuildContext } from './types'
import { validateDependencies } from './validate'
import { rollupBuild } from './builder/rollup'
Expand Down Expand Up @@ -85,7 +86,8 @@ export async function build (rootDir: string, stub: boolean) {
// Clean dist dirs
if (ctx.clean) {
for (const dir of new Set(ctx.entries.map(e => e.outDir).sort())) {
await cleanDir(dir!)
await rmdir(dir!)
await mkdirp(dir!)
}
}

Expand Down
3 changes: 2 additions & 1 deletion src/builder/mkdist.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { mkdist } from 'mkdist'
import { symlink } from '../utils'
import { symlink, rmdir } from '../utils'
import type { BuildContext } from '../types'

export async function mkdistBuild (ctx: BuildContext) {
for (const entry of ctx.entries.filter(e => e.builder === 'mkdist')) {
const distDir = entry.outDir!
if (ctx.stub) {
await rmdir(distDir)
await symlink(entry.input, distDir)
} else {
const { writtenFiles } = await mkdist({
Expand Down
9 changes: 5 additions & 4 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import fsp from 'fs/promises'
import { promisify } from 'util'
import { dirname } from 'upath'
import mkdirp from 'mkdirp'
import rimraf from 'rimraf'
import _rimraf from 'rimraf'

export async function ensuredir (path: string) {
await mkdirp(dirname(path))
Expand All @@ -25,8 +25,9 @@ export function getpkg (id: string = '') {
return s[0][0] === '@' ? `${s[0]}/${s[1]}` : s[0]
}

export async function cleanDir (dir: string) {
const rimraf = promisify(_rimraf)

export async function rmdir (dir: string) {
await fsp.unlink(dir).catch(() => { })
await promisify(rimraf)(dir)
await mkdirp(dir)
await rimraf(dir)
}

0 comments on commit 1ca50a4

Please sign in to comment.