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

@sewing-kit/hooks

Package Overview
Dependencies
Maintainers
3
Versions
37
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@sewing-kit/hooks

Interfaces and types for `sewing-kit` hooks.

  • 0.1.7
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
76
increased by406.67%
Maintainers
3
Weekly downloads
 
Created
Source

@sewing-kit/hooks

Interfaces and types for sewing-kit hooks.

Installation

yarn add @sewing-kit/hooks --dev

Overview

Hooks, along with plugins, form the functional heart of sewing-kit. Inspired by webpack's tapable library (guide), hooks provide a way for plugins to tap into sewing-kit tasks in order to impart functionality to your workspace's dev setup.

Calling hooks

The two types of hooks provided are a SeriesHook and a WaterfallHook. Both of these clases provide a hook and run method

import {SeriesHook} from '@sewing-kit/hooks';

const dog = {
  breed: new SeriesHook<string>(),
};

dog.breed.hook((breed) => {
  console.log('Received changes on the breed: ', breed);
});

dog.breed.run('American Bully');
// Received changes on the breed: American Bully

SeriesHook vs WaterfallHooks

When run is called on a SeriesHook all the conainted hooks are resolved in sequential order. With a Waterfall hook, the result of a hook is passed in as the argument for the next hook.

Usage

Adding hooks

A lot of your use cases can probably covered by the hooks provided by core sewing-kit, but you can always add your own hooks via plugins and a task's configureHooks hook (adding hooks with hooks). For example, if you add, say, a plugin that introduces Jest to your workspace's testing setup, that plugin can also add a hook to let other plugins hook into its Jest configuration.

// Code from @sewing-kit/plugin-jest

hooks.configureHooks.hook(
  addHooks<JestWorkspaceHooks>(() => ({
    jestSetupEnv: new WaterfallHook(),
    jestSetupTests: new WaterfallHook(),
    jestWatchPlugins: new WaterfallHook(),
    jestConfig: new WaterfallHook(),
    jestFlags: new WaterfallHook(),
  })),
);

Configuring/tapping into hooks

Following from the previous example, another plugin further down might then do something like:

createWorkspaceTestPlugin('CustomPlugin', ({hooks}) => {
  hooks.configure.hook((hooks) => {
    hooks.jestSetupEnv.hook((oldJestSetupEnv) => {
      // Do something to oldJestSetupEnv and return the new value
    });

    hooks.jestConfig.hook((oldJestConfig) => {
      // Do something to oldJestConfig and return the new value
    });

    // ..etc
  });
});

When you run sk test, sewing-kit will pick up your configs and plugins and run Jest with your specified option/config values.

FAQs

Package last updated on 03 Mar 2021

Did you know?

Socket

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.

Install

Related posts

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