{"id":19841272,"url":"https://github.com/codelenny/fs-intercept","last_synced_at":"2026-05-11T21:31:57.266Z","repository":{"id":57242279,"uuid":"82356555","full_name":"CodeLenny/fs-intercept","owner":"CodeLenny","description":"Intercepts Node.js file reads.","archived":false,"fork":false,"pushed_at":"2017-02-22T17:06:15.000Z","size":71,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-02-11T12:06:36.626Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"CoffeeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/CodeLenny.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-02-18T02:50:36.000Z","updated_at":"2017-02-19T00:21:31.000Z","dependencies_parsed_at":"2022-09-07T22:01:09.978Z","dependency_job_id":null,"html_url":"https://github.com/CodeLenny/fs-intercept","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CodeLenny%2Ffs-intercept","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CodeLenny%2Ffs-intercept/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CodeLenny%2Ffs-intercept/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CodeLenny%2Ffs-intercept/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/CodeLenny","download_url":"https://codeload.github.com/CodeLenny/fs-intercept/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241210624,"owners_count":19927816,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-12T12:29:52.294Z","updated_at":"2026-05-11T21:31:57.216Z","avatar_url":"https://github.com/CodeLenny.png","language":"CoffeeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# FS Read Interceptor\n[![Build Status](https://travis-ci.org/CodeLenny/fs-intercept.svg?branch=master)](https://travis-ci.org/CodeLenny/fs-intercept)\n[![npm](https://img.shields.io/npm/v/fs-intercept.svg)]()\n\nFS Read Interceptor automatically transforms files as they are read into your [Node.js][] script or application.\n\nDesigned for bundling tools like [polymer-bundler][] and [Browserify][] that automatically bundle dependencies into a\nsingle file, this library adds precompilation steps when files are read.\n\nThe same rules can also be applied to files served by [serve-static][], replacing compilation middleware.\n\n:warning: Read Interceptor is only intended to be used during development and compilation.  See the\n[Limitations](#limitations) for more information.\n\n## Basic Usage\n\nInstall `fs-intercept` via [NPM][]\n\n```sh\nnpm install --save-dev fs-intercept\n```\n\nDefine or import `InterceptRule`s.\n\n```js\n\"use strict\";\nconst InterceptRule = require(\"fs-intercept/InterceptRule\");\nclass CoffeeScriptIntercept extends InterceptRule {\n  \n  intercept(method, params) {\n    const path = params[0];\n    return path.indexOf(\".js\") \u003e -1;\n  }\n  \n  readFile(path, options, callback) {\n    require(\"fs\").readFile(path.replace(\".js\", \".coffee\"), \"utf8\", function(err, cs) {\n      if(err) { return cb(err); }\n      cb(null, require(\"coffee-script\").compile(cs));\n    });\n  }\n  \n}\nmodule.exports = CoffeeScriptIntercept;\n```\n\nUse `InterceptRule`s, and start intercepting files.\n\n```js\nvar FSReadInterceptor = require(\"fs-intercept\");\nvar interceptor = new FSReadInterceptor();\ninterceptor.use(new CoffeeScriptIntercept());\ninterceptor.intercept();\n```\n\nNow `fs.readFile(\"src.js\");` will compile `src.coffee` if `src.js` isn't found. and return the corresponding JavaScript.\n\n### Implemented Methods\n\n- `fs.readFile`, `fs.readFileSync`\n- `fs.stat`, `fs.lstat`\n- `fs.createReadStream`\n\n### Tested Environments\n\n- ![`express.static()` Tested][express-static-badge] [serve-static][]\n- ![`polymer-bundler` Tested][polymer-bundler-badge] [polymer-bundler][]\n- ![`browserify` Tested][browserify-badge] [Browserify][]\n\nPlease suggest additional environments to test, so they can be added to the automated testing suite.\n\n[express-static-badge]: https://img.shields.io/badge/express.static()-tested-brightgreen.svg?style=flat-square\n[polymer-bundler-badge]: https://img.shields.io/badge/polymer--bundler-tested-brightgreen.svg?style=flat-square\n[browserify-badge]: https://img.shields.io/badge/browserify-tested-brightgreen.svg?style=flat-square\n\n## Limitations\n\n### No Caching\n:construction: This limitation will be removed in a future release.\n\nCurrently, no caching is applied to transformations made when files are read.  This would cause poor latency when\nreading files multiple times.\n\n### Partial Implementation\n:no_entry_sign: This limitation is potentially removable, but is not planned to be removed.\n\nRead Interceptor overrides several of the [fs][node-fs] methods, but by no means has an exhaustive implementation for\nall of Node's file system methods.  This means that while `fs.readFile` might correctly transform files, `fs.watch`\nwould not handle the file transformation.\n\nSee the list of [implemented methods](#implemented-methods) for more information.\n\nIn addition, FS Read Interceptor only works for file reads that go through the JavaScript `fs` API.  Calls through C\nfunctions and other executable programs (`cat`, `md5`, Python, etc.) would not have file transformations applied.\n\n### Synchronous and Stream Method Wrapping\n:information_source: This limitation can be avoided if users spend extra effort when writing Interceptors.\n\nTo allow quicker usage, Interceptors only require the asynchronous methods to be implemented.  Synchronous and\nfile-stream versions of methods are created by default, which wrap the asynchronous method.\n\nEnvironments made for Streams or expecting synchronous methods might experience performance issues if the asynchronous\nwrapping is used.  To prevent this, users can implement stream and synchronous versions of their Interceptor logic.\n\n### Stream Implementation\n:construction: This limitation *may* be removed in a future release.\n\nThe current implementation of `createReadStream` doesn't take advantage of read streams to pipe data, as data can come\nfrom multiple sources - direct from the file system, or transformed from another file.\n\n\n[Node.js]: https://nodejs.org/\n[NPM]: https://www.npmjs.com/\n[polymer-bundler]: https://github.com/Polymer/polymer-bundler\n[Browserify]: http://browserify.org/\n[serve-static]: https://github.com/expressjs/serve-static\n[node-fs]: https://nodejs.org/api/fs.html\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcodelenny%2Ffs-intercept","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcodelenny%2Ffs-intercept","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcodelenny%2Ffs-intercept/lists"}