
Product
Rust Support Now in Beta
Socket's Rust support is moving to Beta: all users can scan Cargo projects and generate SBOMs, including Cargo.toml-only crates, with Rust-aware supply chain checks.
Execute injected hooks in the workflow of gulp.
Using pnpm
to install:
pnpm add gulp-hooks
Using yarn
or npm
:
# with yarn
yarn add gulp-hooks
# with npm
npm i gulp-hooks
Starting from a simple example, if we need to add an updatedAt field to the json to indicate its update time, we can do it like this.
import tapHooks, { registerHooks } from 'gulp-hooks';
registerHooks('compileJSON', (file) => {
const json = JSON.parse(file.contents.toString());
json.updatedAt = Date.now();
file.contents = Buffer.from(JSON.stringify(json));
});
function task() {
return gulp
.src('**/*.json')
.pipe(tapHooks('compileJSON'))
.pipe(jsonmin())
.pipe(gulp.dest('dist'));
}
The second argument passed to tapHooks will be received by the hook, and you can pass any value you need.
registerHooks('compileJSON', (file, { version }) => {
// ...
});
tapHooks('compileJSON', { version: 'v1.0.0' });
Sometimes, we may need to determine whether to execute the hook based on certain condition, which can be done.
registerHooks('compileJSON', {
condition: ['**/*.json'],
fn: (file) => {
// ...
},
});
registerHooks('compileJSON', {
condition: (file) => file.extname === '.json',
fn: (file) => {
// ...
},
});
Of course, you can register multiple handlers function for the same hook.
registerHooks('hookName', [
(file) => {
// ...
},
(file) => {
// ...
},
]);
If needed, you can also return a stream.
registerHooks('compileJSON', (file) => {
return jsonmin();
});
FAQs
Execute injected hooks in the workflow of gulp.
We found that gulp-hooks demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Socket's Rust support is moving to Beta: all users can scan Cargo projects and generate SBOMs, including Cargo.toml-only crates, with Rust-aware supply chain checks.
Product
Socket Fix 2.0 brings targeted CVE remediation, smarter upgrade planning, and broader ecosystem support to help developers get to zero alerts.
Security News
Socket CEO Feross Aboukhadijeh joins Risky Business Weekly to unpack recent npm phishing attacks, their limited impact, and the risks if attackers get smarter.