browserify-transform-tools
Advanced tools
Comparing version 1.1.0 to 1.2.0
@@ -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
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Trivial Package
Supply chain riskPackages less than 10 lines of code are easily copied into your own project and may not warrant the additional supply chain risk of an external dependency.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Uses eval
Supply chain riskPackage uses dynamic code execution (e.g., eval()), which is a dangerous practice. This can prevent the code from running in certain environments and increases the risk that the code may contain exploits or malicious behavior.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
20
0
61808
4
3
148
2