Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

browserify-transform-tools

Package Overview
Dependencies
Maintainers
1
Versions
20
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

browserify-transform-tools - npm Package Compare versions

Comparing version 1.1.0 to 1.2.0

src/loadConfig.coffee

4

CHANGELOG.md

@@ -1,3 +0,1 @@

* v1.1.0: Add `setConfig()` and `configure()` methods to transforms.
* v1.0.2: Include the name of the transform in error messages.
Change log available here: https://github.com/benbria/browserify-transform-tools/wiki/Change-log
{
"name": "browserify-transform-tools",
"version": "1.1.0",
"version": "1.2.0",
"description": "Utilities for writing browserify transforms.",

@@ -29,4 +29,11 @@ "main": "./lib/transformTools.js",

"coffee-script": "1.6.3",
"mocha": "1.15.0"
"mocha": "1.15.0",
"browserify": "~3.14.1",
"async": "~0.2.9"
},
"scripts": {
"test": "cake test",
"prepublish": "cake build",
"build": "cake build"
}
}

@@ -11,2 +11,3 @@ This package contains tools for helping you write [transforms](https://github.com/substack/node-browserify#btransformtr) for [browserify](https://github.com/substack/node-browserify).

Installation

@@ -58,4 +59,6 @@ ============

* `transformOptions.file` is the name of the file (as would be passed to a normal browserify transform.)
* `transformOptions.configData` is the configuration data for the transform (see
`loadTransformConfig` below for details on where this comes from.)
* `transformOptions.config` is a copy of `transformOptions.configData.config` for convenience.

@@ -70,2 +73,7 @@

* `options.jsFilesOnly` - If set true, then your transform will only run on "javascript" files.
This is handy for Falafel and Require transforms, defined below. This is equivalent to
passing
`includeExtensions: [".js", ".coffee", ".coffee.md", ".litcoffee", "._js", "._coffee"]`.
Creating a Falafel Transform

@@ -117,54 +125,6 @@ ============================

All `make*Transform()` functions will automatically load configuration for your transform and make it available via `transformOptions.configData` and `transformOptions.config`.
All `make*Transform()` functions will automatically load configuration for your transform and make it available via `transformOptions.config` (and through the more detailed `transformOptions.configData`.) Functions are also provided for reading configuration if you are not using one of the `make*Transform()` functions.
All `make*Transform()` functions return a transform which has a function called `configure(config, options)` which can be called to pass configuration directly to the transform. `config` will be passed to the transform as `transformOptions.configData.config` and `transformOptions.config`. If `options.configFile` is set, it will be used to set `transformOptions.configFile` and `transformOptions.configDir` - these are passed to transforms so they can resolve relative path names. You can also specify `options.configDir` directly. `configure()` returns a new transform instance and does not modify the existing transform. If want to modify the configuration on an existing instance, you can call `setConfig()` with the same options.
Transform configuration can be loaded from a project's package.json file, from a js or coffee file specified in package.json, or programatically. For details, see [the transform configuration documentation](https://github.com/benbria/browserify-transform-tools/wiki/Transform-Configuration).
If neither `configure()` nor `setConfig()` is called, then a transform will look for configuration in package.json. For example, for a "unbluify" transform:
```JavaScript
{
"name": "myProject",
"version": "1.0.0",
...
"unbluify": {"newColor": "red"}
}
```
Or alternatively you can set the "unbluify" key to be a js or JSON file:
```JavaScript
{
"unbluify": "unbluifyConfig.js"
}
```
And then configuration will be loaded from that file:
```JavaScript
module.exports = {
newColor: "red"
};
```
Note this means you can use enviroment variables to make changes to your configuration.
If you are writing your own transform which doesn't use a `make*Transform()` function, you can still use browserify-transform-tools to load configuration from package.json:
```JavaScript
var transformTools = require('browserify-transform-tools');
var configData = transformTools.loadTransformConfig('myTransform', file, function(err, configData) {
var config = configData.config;
var configDir = configData.configDir;
...
});
```
`loadTransformConfig()` will search the parent directory of `file` and its ancestors to find a `package.json` file. Once it finds one, it will look for a key called 'myTransform' (taken from the transformName passed into `loadTransformConfig()`.) If this key maps to a JSON object, then `loadTransformConfigSync()` will return the object. If this key maps to a string, then `loadTransformConfigSync()` will try to load the JSON or JS file the string represents and will return that instead. For example, if package.json contains `{"myTransform": "./myTransform.json"}`, then the contents of "myTransform.json" will be returned. `configData.config` is the loaded data. `configData.configDir` is the directory which contained the file that data was loaded from (handy for resolving relative path names.) For other fields returned by `loadTransformConfigSync()`, see comments in [the source](https://github.com/benbria/browserify-transform-tools/blob/master/src/transformTools.coffee).
There is a synchronous version of this function, as well, called `loadTransformConfigSync(transformName, file)`.
Note that since configuration can be supplied in a .js file, the .js file can alter the configuration based on environment variables.
Running a Transform

@@ -171,0 +131,0 @@ ===================

@@ -8,3 +8,6 @@ {

"foo": "bar"
},
"applyToExtify": {
"appliesTo": {"files": ["./green.js"]}
}
}

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc