3 Star 1 Fork 4

VTJ.PRO/node_modules

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README

append-transform Build Status Coverage Status

Install a transform to require.extensions that always runs last, even if additional extensions are added later.

The typical require extension looks something like this:

  var myTransform = require('my-transform');
  
  var oldExtension = require.extensions['.js'];
  require.extensions['.js'] = function (module, filename) {
    var oldCompile = module._compile;
    module._compile = function (code, filename) {
      code = myTransform(code);
      module._compile = oldCompile;
      module._compile(code, filename);
    };  
    oldExtension(module, filename);
  };

In almost all cases, that is sufficient and is the method that should be used (check out pirates for an easy way to do it correctly). In rare cases you must ensure your transform remains the last one, even if other transforms are added later. For example, nyc uses this module to ensure its transform is applied last so it can capture the final source-map information, and ensure any language extensions it can't understand are already transpiled (ES2015 via babel for instance).

WARNING: You should be sure you actually need this, as it takes control away from the user. Your transform remains the last one applied, even as users continue to add more transforms. This is potentially confusing. Coverage libraries like nyc (and istanbul on which it relies) have valid reasons for doing this, but you should prefer conventional transform installation via pirates.

References:

Install

$ npm install --save append-transform

Usage

var appendTransform = require('append-transform');
var myTransform = require('my-transform');

appendTransform(function (code, filename) {
  if (myTransform.shouldTransform(filename)) {
    code = myTransform.transform(code);
  }
  return code;
});

API

appendTransform(transformFn, [extension])

transformFn

Type: function(code: string, filename: string)
Required

A callback that modifies the incoming code argument in some way, and returns the transformed result. filename is provided to filter which files the transform applies to. If a transform should not manipulate a particular file, just return code without modifying it. It is fairly common to avoid transforming files in node_modules. In that case you may want to use node-modules-regexp to help reliably detect node_modules paths and avoid transforming them.

extension

Type: string
Default: ".js"

The extension for the types of files this transform is capable of handling.

License

MIT © James Talmage

马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
JavaScript
1
https://gitee.com/newgateway/node_modules.git
git@gitee.com:newgateway/node_modules.git
newgateway
node_modules
node_modules
master

搜索帮助