
Security News
Axios Maintainer Confirms Social Engineering Attack Behind npm Compromise
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.
Dead simple conditional build tool.
npm install diverge
Usage: diverge <input> <output>
Options:
-h, --help output usage information
-V, --version output the version number
-f, --force forces overwrite of output file
Examples:
$ env=cjs diverge common.js cjs.js
$ env=meteor diverge common.js meteor.js
$ env=globals diverge common.js globals.js
There's 4 conditional directives available:
diverge:ifdiverge:elifdiverge:elsediverge:fiYou can use both equality and inequality operators:
// diverge:if env=browser
var equality = 'is browser';
// diverge:elif env!=browser
var inequality = 'is not browser';
// diverge:fi
In this example, we have a javascript file which we want to use in:
commonjsglobalsmeteorSo, first we need to instrument it:
sample.js
// diverge:if env=cjs
module.exports
// diverge:elif env=meteor
MyModule
// diverge:else
window.MyModule;
// diverge:fi
= function(){
console.log('Hello World');
}
Note that comments are used so the original functionality doesn't get modified whatsoever. You can do the same for the text file you're dealing with.
In the next step we'll see how we send the env value so our conditionals
can work properly.
In order to compile we need to set our variables accordingly, as we expect
them. In this example, we're checking conditions against the env variable. So
we set it right before the diverge call.
Lets see three examples and their corresponding outputs:
// $ env=cjs diverge sample.js cjs.js
module.exports
= function(){
console.log('Hello World');
}
// $ env=meteor diverge sample.js meteor.js
MyModule
= function(){
console.log('Hello World');
}
// $ env=globals diverge sample.js globals.js
window.MyModule
= function(){
console.log('Hello World');
}
Signature is such as follows:
diverge(<input>, <output>, {locals}, {options});
/*
input - input file path
output - output file path
locals - variables accessible to instrumented code
options - same as CLI options
*/
Practical example:
var diverge = require('diverge');
diverge('source.js', 'cjs.js', {env: 'cjs'}, {force: true});
Note that in the CLI mode our variables (
locals) gets read fromprocess.envbut in the Javascript mode, we need to explicitly set them.
The options are the same of the CLI, but informed without aliases / dashes.
The MIT License (MIT)
Copyright (c) 2015 Anderson Arboleya
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
FAQs
Conditional build tool for text files
We found that diverge demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.

Security News
The Axios compromise shows how time-dependent dependency resolution makes exposure harder to detect and contain.