esbuild-plugin-clean
Advanced tools
Comparing version 0.0.1 to 0.0.2-1
{ | ||
"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
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No contributors or author data
MaintenancePackage does not specify a list of contributors or an author in package.json.
Found 1 instance in 1 package
No bug tracker
MaintenancePackage does not have a linked bug tracker in package.json.
Found 1 instance in 1 package
No License Found
License(Experimental) License information could not be found.
Found 1 instance in 1 package
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
Found 1 instance in 1 package
No website
QualityPackage does not have a website.
Found 1 instance in 1 package
6531
0
63
0
1
60
0
3
+ Addedchalk@^4.1.1
+ Addeddel@^6.0.0
+ Added@nodelib/fs.scandir@2.1.5(transitive)
+ Added@nodelib/fs.stat@2.0.5(transitive)
+ Added@nodelib/fs.walk@1.2.8(transitive)
+ Addedaggregate-error@3.1.0(transitive)
+ Addedansi-styles@4.3.0(transitive)
+ Addedarray-union@2.1.0(transitive)
+ Addedbalanced-match@1.0.2(transitive)
+ Addedbrace-expansion@1.1.11(transitive)
+ Addedbraces@3.0.3(transitive)
+ Addedchalk@4.1.2(transitive)
+ Addedclean-stack@2.2.0(transitive)
+ Addedcolor-convert@2.0.1(transitive)
+ Addedcolor-name@1.1.4(transitive)
+ Addedconcat-map@0.0.1(transitive)
+ Addeddel@6.1.1(transitive)
+ Addeddir-glob@3.0.1(transitive)
+ Addedesbuild@0.11.23(transitive)
+ Addedfast-glob@3.3.2(transitive)
+ Addedfastq@1.17.1(transitive)
+ Addedfill-range@7.1.1(transitive)
+ Addedfs.realpath@1.0.0(transitive)
+ Addedglob@7.2.3(transitive)
+ Addedglob-parent@5.1.2(transitive)
+ Addedglobby@11.1.0(transitive)
+ Addedgraceful-fs@4.2.11(transitive)
+ Addedhas-flag@4.0.0(transitive)
+ Addedignore@5.3.2(transitive)
+ Addedindent-string@4.0.0(transitive)
+ Addedinflight@1.0.6(transitive)
+ Addedinherits@2.0.4(transitive)
+ Addedis-extglob@2.1.1(transitive)
+ Addedis-glob@4.0.3(transitive)
+ Addedis-number@7.0.0(transitive)
+ Addedis-path-cwd@2.2.0(transitive)
+ Addedis-path-inside@3.0.3(transitive)
+ Addedmerge2@1.4.1(transitive)
+ Addedmicromatch@4.0.8(transitive)
+ Addedminimatch@3.1.2(transitive)
+ Addedonce@1.4.0(transitive)
+ Addedp-map@4.0.0(transitive)
+ Addedpath-is-absolute@1.0.1(transitive)
+ Addedpath-type@4.0.0(transitive)
+ Addedpicomatch@2.3.1(transitive)
+ Addedqueue-microtask@1.2.3(transitive)
+ Addedreusify@1.0.4(transitive)
+ Addedrimraf@3.0.2(transitive)
+ Addedrun-parallel@1.2.0(transitive)
+ Addedslash@3.0.0(transitive)
+ Addedsupports-color@7.2.0(transitive)
+ Addedto-regex-range@5.0.1(transitive)
+ Addedwrappy@1.0.2(transitive)