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

broccoli-persistent-filter

Package Overview
Dependencies
Maintainers
4
Versions
59
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

broccoli-persistent-filter

broccoli filter but with a persistent cache

  • 3.1.3
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
747K
increased by27.6%
Maintainers
4
Weekly downloads
 
Created

What is broccoli-persistent-filter?

broccoli-persistent-filter is a Broccoli plugin that provides a base class for creating filters that can cache their results to improve build performance. It is particularly useful for tasks that involve transforming files, such as transpiling, minifying, or linting.

What are broccoli-persistent-filter's main functionalities?

Basic Filtering

This feature allows you to create a custom filter by extending the `Filter` class and implementing the `processString` method. The `processString` method is where you define the transformation logic for the file contents.

const Filter = require('broccoli-persistent-filter');

class MyFilter extends Filter {
  constructor(inputNode, options) {
    super(inputNode, options);
  }

  processString(contents, relativePath) {
    // Perform some transformation on the file contents
    return contents.toUpperCase();
  }
}

module.exports = MyFilter;

Caching

This feature demonstrates how to implement caching in your custom filter. By overriding the `cacheKeyProcessString` method, you can generate a cache key based on the file contents, which helps in reusing the cached results for unchanged files.

const Filter = require('broccoli-persistent-filter');

class MyFilter extends Filter {
  constructor(inputNode, options) {
    super(inputNode, options);
    this.extensions = ['js'];
    this.targetExtension = 'js';
  }

  processString(contents, relativePath) {
    // Perform some transformation on the file contents
    return contents.toUpperCase();
  }

  cacheKeyProcessString(contents, relativePath) {
    // Generate a cache key based on the file contents
    return contents;
  }
}

module.exports = MyFilter;

Handling Multiple File Types

This feature shows how to handle multiple file types by setting the `extensions` property. The `targetExtension` property specifies the extension of the output files.

const Filter = require('broccoli-persistent-filter');

class MyFilter extends Filter {
  constructor(inputNode, options) {
    super(inputNode, options);
    this.extensions = ['js', 'css'];
    this.targetExtension = 'txt';
  }

  processString(contents, relativePath) {
    // Perform some transformation on the file contents
    return contents.toUpperCase();
  }
}

module.exports = MyFilter;

Other packages similar to broccoli-persistent-filter

Keywords

FAQs

Package last updated on 22 Aug 2022

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