Software zum Installieren eines Smart-Mirror Frameworks , zum Nutzen von hochschulrelevanten Informationen, auf einem Raspberry-Pi.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

readme.md 3.3KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. # append-transform [![Build Status](https://travis-ci.org/istanbuljs/append-transform.svg?branch=master)](https://travis-ci.org/istanbuljs/append-transform) [![Coverage Status](https://coveralls.io/repos/github/istanbuljs/append-transform/badge.svg?branch=master)](https://coveralls.io/github/istanbuljs/append-transform?branch=master)
  2. > Install a transform to `require.extensions` that always runs last, even if additional extensions are added later
  3. The [typical require extension](https://gist.github.com/jamestalmage/df922691475cff66c7e6) looks something like this:
  4. ```js
  5. const myTransform = require('my-transform');
  6. const oldExtension = require.extensions['.js'];
  7. require.extensions['.js'] = (module, filename) => {
  8. const oldCompile = module._compile;
  9. module._compile = (code, filename) => {
  10. code = myTransform(code);
  11. module._compile = oldCompile;
  12. module._compile(code, filename);
  13. };
  14. oldExtension(module, filename);
  15. };
  16. ```
  17. In **almost** all cases, that is sufficient and is the method that should be used (check out [`pirates`](https://www.npmjs.com/package/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).
  18. *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`](https://www.npmjs.com/package/pirates).
  19. References:
  20. - [Detailed Breakdown of How Require Extensions Work](https://gist.github.com/jamestalmage/df922691475cff66c7e6)
  21. - The [test suite](https://github.com/avajs/append-transform/blob/master/test/execution-order.js) provides a good overview of how this library manipulates the order in which transforms are applied.
  22. ## Install
  23. ```
  24. $ npm install --save append-transform
  25. ```
  26. ## Usage
  27. ```js
  28. const appendTransform = require('append-transform');
  29. const myTransform = require('my-transform');
  30. appendTransform((code, filename) => {
  31. if (myTransform.shouldTransform(filename)) {
  32. code = myTransform.transform(code);
  33. }
  34. return code;
  35. });
  36. ```
  37. ## API
  38. ### appendTransform(transformFn, [extension])
  39. #### transformFn
  40. Type: `function(code: string, filename: string)`
  41. 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`](https://www.npmjs.com/package/node-modules-regexp) to help reliably detect `node_modules` paths and avoid transforming them.
  42. #### extension
  43. Type: `string`<br>
  44. Default: `'.js'`
  45. The extension for the types of files this transform is capable of handling.
  46. ## License
  47. MIT © [James Talmage](https://github.com/jamestalmage)