npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

fs-intercept

v0.1.0

Published

Intercepts file reads.

Downloads

3

Readme

FS Read Interceptor

Build Status

FS Read Interceptor automatically transforms files as they are read into your Node.js script or application.

Designed for bundling tools like polymer-bundler and Browserify that automatically bundle dependencies into a single file, this library adds precompilation steps when files are read.

The same rules can also be applied to files served by serve-static, replacing compilation middleware.

:warning: Read Interceptor is only intended to be used during development and compilation. See the Limitations for more information.

Basic Usage

Install fs-intercept via NPM

npm install --save-dev fs-intercept

Define or import InterceptRules.

"use strict";
const InterceptRule = require("fs-intercept/InterceptRule");
class CoffeeScriptIntercept extends InterceptRule {
  
  intercept(path) { return path.indexOf(".js") > -1; }
  
  readFile(path, options, callback) {
    require("fs").readFile(path.replace(".js", ".coffee"), "utf8", function(err, cs) {
      if(err) { return cb(err); }
      cb(null, require("coffee-script").compile(cs));
    });
  }
  
}
module.exports = CoffeeScriptIntercept;

Use InterceptRules, and start intercepting files.

var FSReadInterceptor = require("fs-intercept");
var interceptor = new FSReadInterceptor();
interceptor.use(new CoffeeScriptIntercept());
interceptor.intercept();

Now fs.readFile("src.js"); will compile src.coffee if src.js isn't found. and return the corresponding JavaScript.

Implemented Methods

  • fs.readFile, fs.readFileSync
  • fs.stat, fs.lstat
  • fs.createReadStream

Tested Environments

Please suggest additional environments to test, so they can be added to the automated testing suite.

Limitations

No Caching

:construction: This limitation will be removed in a future release.

Currently, no caching is applied to transformations made when files are read. This would cause poor latency when reading files multiple times.

Partial Implementation

:no_entry_sign: This limitation is potentially removable, but is not planned to be removed.

Read Interceptor overrides several of the fs methods, but by no means has an exhaustive implementation for all of Node's file system methods. This means that while fs.readFile might correctly transform files, fs.watch would not handle the file transformation.

See the list of implemented methods for more information.

In addition, FS Read Interceptor only works for file reads that go through the JavaScript fs API. Calls through C functions and other executable programs (cat, md5, Python, etc.) would not have file transformations applied.

Synchronous and Stream Method Wrapping

:information_source: This limitation can be avoided if users spend extra effort when writing Interceptors.

To allow quicker usage, Interceptors only require the asynchronous methods to be implemented. Synchronous and file-stream versions of methods are created by default, which wrap the asynchronous method.

Environments made for Streams or expecting synchronous methods might experience performance issues if the asynchronous wrapping is used. To prevent this, users can implement stream and synchronous versions of their Interceptor logic.

Stream Implementation

:construction: This limitation may be removed in a future release.

The current implementation of createReadStream doesn't take advantage of read streams to pipe data, as data can come from multiple sources - direct from the file system, or transformed from another file.