Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

esbuild-plugin-clean

Package Overview
Dependencies
Maintainers
1
Versions
18
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

esbuild-plugin-clean - npm Package Compare versions

Comparing version 0.0.1 to 0.0.2-1

26

package.json
{
"name": "esbuild-plugin-clean",
"version": "0.0.1",
"version": "0.0.2-1",
"description": "ESBuild plugin for cleaning up assets before building.",
"keywords": [
"esbuild",
"ESBuild",
"clean",
"plugin"
],
"homepage": "https://github.com/linbudu599/nx-plugins/tree/master/packages/esbuild-plugin-clean#readme",
"bugs": {
"url": "https://github.com/linbudu599/nx-plugins/issues"
},
"repository": {
"type": "git",
"url": "git+https://github.com/linbudu599/nx-plugins.git"
},
"license": "MIT",
"author": "Linbudu <linbudu599@gmail.com> (https://github.com/linbudu599)",
"dependencies": {
"chalk": "^4.1.1",
"del": "^6.0.0"
},
"peerDependencies": {
"esbuild": "^0.11.19"
},
"main": "./src/index.js",
"typings": "./src/index.d.ts"
}
# esbuild-plugin-clean
This library was generated with [Nx](https://nx.dev).
ESBuild plugin for cleaning up output/assets before building.
## Running unit tests
## Usage
Run `nx test esbuild-plugin-clean` to execute the unit tests via [Jest](https://jestjs.io).
**Node: this plugin require ESBuild version ^0.11.19 for the `onStart`/`onEnd` hooks**
**GitHub Repository/Homepage is private for now, if you got any troubles, just open issue in this [repo](https://github.com/linbudu599/Blog).**
```bash
npm i esbuild-plugin-clean -D
pnpm i esbuild-plugin-clean
yarn add esbuild-plugin-clean -D
```
```typescript
import { build } from 'esbuild';
import clean from 'esbuild-plugin-clean';
(async () => {
const res1 = await build({
entryPoints: ['./demo.ts'],
bundle: true,
outfile: './dist/main.js',
plugins: [
clean({
patterns: ['./dist/*'],
}),
],
});
})();
```
## Configuration
This plugin use [del](https://www.npmjs.com/package/del) under the hood, so you can easily pass del options to plugin.
```typescript
export interface CleanOptions {
// del patterns
// default: []
patterns?: string | string[];
// use dry-run mode to have a try
// default: false
dryRun?: boolean;
// del options
// default: {}
options?: DelOptions;
// use del or del.sync for cleaning up
// default: true
sync?: boolean;
// do cleaning in start/end/both
// maybe in some strange cases you will need it ? :)
// default: "start"
cleanOn?: 'start' | 'end' | 'both';
}
```

@@ -1,1 +0,11 @@

export declare function esbuildPluginClean(): string;
import { Plugin } from 'esbuild';
import { Options as DelOptions } from 'del';
export interface CleanOptions {
patterns?: string | string[];
dryRun?: boolean;
options?: DelOptions;
sync?: boolean;
cleanOn?: 'start' | 'end' | 'both';
}
declare const _default: (options?: CleanOptions) => Plugin;
export default _default;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.esbuildPluginClean = void 0;
function esbuildPluginClean() {
return 'esbuild-plugin-clean';
}
exports.esbuildPluginClean = esbuildPluginClean;
const tslib_1 = require("tslib");
const chalk_1 = tslib_1.__importDefault(require("chalk"));
const del_1 = tslib_1.__importDefault(require("del"));
exports.default = (options = {}) => {
var _a, _b, _c, _d, _e;
const patterns = (_a = options.patterns) !== null && _a !== void 0 ? _a : [];
const dryRun = (_b = options.dryRun) !== null && _b !== void 0 ? _b : false;
const delOptions = (_c = options.options) !== null && _c !== void 0 ? _c : {};
const sync = (_d = options.sync) !== null && _d !== void 0 ? _d : true;
const cleanOn = (_e = options.cleanOn) !== null && _e !== void 0 ? _e : 'start';
const logCleanFiles = (cleanFiles) => {
if (dryRun) {
console.log(chalk_1.default.blue('i'), `Clean plugin invoked in dryRun mode`);
}
console.log(chalk_1.default.blue('i'), `File Cleaned: ${cleanFiles.join('\n')}`);
};
const handler = sync
? () => {
const cleanFiles = del_1.default.sync(patterns, Object.assign({ dryRun }, delOptions));
logCleanFiles(cleanFiles);
}
: () => {
del_1.default(patterns, Object.assign({ dryRun }, delOptions)).then((cleanFiles) => {
logCleanFiles(cleanFiles);
});
};
return {
name: 'esbuild:clean',
setup({ initialOptions, onStart: registerOnStartCallback, onEnd: registerOnEndCallback, }) {
if (!patterns.length) {
return;
}
if (cleanOn === 'start' || cleanOn === 'both') {
registerOnStartCallback(() => {
handler();
});
}
if (cleanOn === 'end' || cleanOn === 'both') {
registerOnEndCallback(() => {
handler();
});
}
},
};
};
//# sourceMappingURL=esbuild-plugin-clean.js.map

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc