Skip to content

Commit

Permalink
use fm.rm in clean plugin and simplify it
Browse files Browse the repository at this point in the history
  • Loading branch information
sidvishnoi committed Aug 16, 2024
1 parent b17b5d5 commit d85b26c
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 91 deletions.
26 changes: 7 additions & 19 deletions esbuild/plugins.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import type { Plugin as ESBuildPlugin } from 'esbuild'
import { nodeBuiltin } from 'esbuild-node-builtin'
import esbuildStylePlugin from 'esbuild-style-plugin'
import { copy } from 'esbuild-plugin-copy'
import { rimraf } from 'rimraf'

import {
SRC_DIR,
Expand All @@ -22,7 +21,7 @@ export const getPlugins = ({
outDir: string
}): ESBuildPlugin[] => {
return [
cleanPlugin({ on: 'start', patterns: outDir }),
cleanPlugin([outDir]),
// nodeBuiltIn (powered by rollup plugin) replaces crypto with an empty
// package. But we need it, and we use crypto-browserify in for our use
// case. The JSPM crypto package is too large and not tree shakeable, so we
Expand Down Expand Up @@ -161,26 +160,15 @@ function processManifestPlugin({
}
}

interface CleanPluginOptions {
on: 'start' | 'end' | 'both'
patterns: string | string[]
}

function cleanPlugin({ on, patterns }: CleanPluginOptions): ESBuildPlugin {
function cleanPlugin(dirs: string[]): ESBuildPlugin {
return {
name: 'clean',
setup(build) {
if (on === 'start' || on === 'both') {
build.onStart(async () => {
await rimraf(patterns)
})
}

if (on === 'end' || on === 'both') {
build.onStart(async () => {
await rimraf(patterns)
})
}
build.onStart(async () => {
await Promise.all(
dirs.map((dir) => fs.rm(dir, { recursive: true, force: true }))
)
})
}
}
}
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@
"postcss": "^8.4.39",
"prettier": "^3.3.3",
"prettier-plugin-tailwindcss": "^0.6.5",
"rimraf": "^6.0.1",
"sade": "^1.8.1",
"tailwindcss": "^3.4.4",
"ts-jest": "^29.2.3",
Expand Down
71 changes: 0 additions & 71 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit d85b26c

Please sign in to comment.