GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — angular/node_modules/append-transform at master · rkshgupta/angular

Expand file tree

/

append-transform

/
Copy path

Directory actions

More options

More options

Directory actions

More options

More options

Latest commit

 

History

History
History
/

append-transform

/
Copy path

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
index.js
index.js
 
 
license
license
 
 
package.json
package.json
 
 
readme.md
readme.md
 
 

readme.md

Outline

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:

  • Detailed Breakdown of How Require Extensions Work
  • The test suite provides a good overview of how this library manipulates the order in which transforms are applied.

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

You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.