loose-envify-1.3.1/000077500000000000000000000000001303667365000141445ustar00rootroot00000000000000loose-envify-1.3.1/.gitignore000066400000000000000000000000301303667365000161250ustar00rootroot00000000000000.DS_Store /node_modules loose-envify-1.3.1/.npmignore000066400000000000000000000000311303667365000161350ustar00rootroot00000000000000bench/ test/ .travis.yml loose-envify-1.3.1/.travis.yml000066400000000000000000000001351303667365000162540ustar00rootroot00000000000000sudo: false language: node_js node_js: - "0.10" - "0.12" - "4" - "5" - "6" - "7" loose-envify-1.3.1/LICENSE000066400000000000000000000021141303667365000151470ustar00rootroot00000000000000The MIT License (MIT) Copyright (c) 2015 Andres Suarez 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. loose-envify-1.3.1/README.md000066400000000000000000000020571303667365000154270ustar00rootroot00000000000000# loose-envify [![Build Status](https://travis-ci.org/zertosh/loose-envify.svg?branch=master)](https://travis-ci.org/zertosh/loose-envify) Fast (and loose) selective `process.env` replacer using [js-tokens](https://github.com/lydell/js-tokens) instead of an AST. Works just like [envify](https://github.com/hughsk/envify) but much faster. ## Gotchas * Doesn't handle broken syntax. * Doesn't look inside embedded expressions in template strings. - **this won't work:** ```js console.log(`the current env is ${process.env.NODE_ENV}`); ``` * Doesn't replace oddly-spaced or oddly-commented expressions. - **this won't work:** ```js console.log(process./*won't*/env./*work*/NODE_ENV); ``` ## Usage/Options loose-envify has the exact same interface as [envify](https://github.com/hughsk/envify), including the CLI. ## Benchmark ``` envify: $ for i in {1..5}; do node bench/bench.js 'envify'; done 708ms 727ms 791ms 719ms 720ms loose-envify: $ for i in {1..5}; do node bench/bench.js '../'; done 51ms 52ms 52ms 52ms 52ms ``` loose-envify-1.3.1/bench/000077500000000000000000000000001303667365000152235ustar00rootroot00000000000000loose-envify-1.3.1/bench/bench.js000066400000000000000000000005141303667365000166400ustar00rootroot00000000000000'use strict'; var transform = require(process.argv[2]); var fs = require('fs') var start = Date.now(); var str = ''; fs.createReadStream('test/react/react-with-addons-with-node_env.js') .pipe(transform()) .on('data', function(buf) { str += buf; }) .on('end', function() { console.log('%sms', Date.now() - start); }); loose-envify-1.3.1/bench/results.txt000066400000000000000000000003271303667365000174670ustar00rootroot00000000000000envify: $ for i in {1..5}; do node bench/bench.js 'envify'; done 708ms 727ms 791ms 719ms 720ms loose-envify: $ for i in {1..5}; do node bench/bench.js '../'; done 51ms 52ms 52ms 52ms 52ms loose-envify-1.3.1/cli.js000077500000000000000000000005441303667365000152570ustar00rootroot00000000000000#!/usr/bin/env node 'use strict'; var looseEnvify = require('./'); var fs = require('fs'); if (process.argv[2]) { fs.createReadStream(process.argv[2], {encoding: 'utf8'}) .pipe(looseEnvify(process.argv[2])) .pipe(process.stdout); } else { process.stdin.resume() process.stdin .pipe(looseEnvify(__filename)) .pipe(process.stdout); } loose-envify-1.3.1/custom.js000066400000000000000000000001231303667365000160100ustar00rootroot00000000000000// envify compatibility 'use strict'; module.exports = require('./loose-envify'); loose-envify-1.3.1/index.js000066400000000000000000000001101303667365000156010ustar00rootroot00000000000000'use strict'; module.exports = require('./loose-envify')(process.env); loose-envify-1.3.1/loose-envify.js000066400000000000000000000014271303667365000171250ustar00rootroot00000000000000'use strict'; var stream = require('stream'); var util = require('util'); var replace = require('./replace'); var jsonExtRe = /\.json$/; module.exports = function(rootEnv) { rootEnv = rootEnv || process.env; return function (file, trOpts) { if (jsonExtRe.test(file)) { return stream.PassThrough(); } var envs = trOpts ? [rootEnv, trOpts] : [rootEnv]; return new LooseEnvify(envs); }; }; function LooseEnvify(envs) { stream.Transform.call(this); this._data = ''; this._envs = envs; } util.inherits(LooseEnvify, stream.Transform); LooseEnvify.prototype._transform = function(buf, enc, cb) { this._data += buf; cb(); }; LooseEnvify.prototype._flush = function(cb) { var replaced = replace(this._data, this._envs); this.push(replaced); cb(); }; loose-envify-1.3.1/package.json000066400000000000000000000014371303667365000164370ustar00rootroot00000000000000{ "name": "loose-envify", "version": "1.3.1", "description": "Fast (and loose) selective `process.env` replacer using js-tokens instead of an AST", "keywords": [ "environment", "variables", "browserify", "browserify-transform", "transform", "source", "configuration" ], "homepage": "https://github.com/zertosh/loose-envify", "license": "MIT", "author": "Andres Suarez ", "main": "index.js", "bin": { "loose-envify": "cli.js" }, "repository": { "type": "git", "url": "git://github.com/zertosh/loose-envify.git" }, "scripts": { "test": "tap test/*.js" }, "dependencies": { "js-tokens": "^3.0.0" }, "devDependencies": { "browserify": "^13.1.1", "envify": "^3.4.0", "tap": "^8.0.0" } } loose-envify-1.3.1/replace.js000066400000000000000000000027741303667365000161270ustar00rootroot00000000000000'use strict'; var jsTokens = require('js-tokens').default; var processEnvRe = /\bprocess\.env\.[_$a-zA-Z][$\w]+\b/; var spaceOrCommentRe = /^(?:\s|\/[/*])/; function replace(src, envs) { if (!processEnvRe.test(src)) { return src; } var out = []; var purge = envs.some(function(env) { return env._ && env._.indexOf('purge') !== -1; }); jsTokens.lastIndex = 0 var parts = src.match(jsTokens); for (var i = 0; i < parts.length; i++) { if (parts[i ] === 'process' && parts[i + 1] === '.' && parts[i + 2] === 'env' && parts[i + 3] === '.') { var prevCodeToken = getAdjacentCodeToken(-1, parts, i); var nextCodeToken = getAdjacentCodeToken(1, parts, i + 4); var replacement = getReplacementString(envs, parts[i + 4], purge); if (prevCodeToken !== '.' && nextCodeToken !== '.' && nextCodeToken !== '=' && typeof replacement === 'string') { out.push(replacement); i += 4; continue; } } out.push(parts[i]); } return out.join(''); } function getAdjacentCodeToken(dir, parts, i) { while (true) { var part = parts[i += dir]; if (!spaceOrCommentRe.test(part)) { return part; } } } function getReplacementString(envs, name, purge) { for (var j = 0; j < envs.length; j++) { var env = envs[j]; if (typeof env[name] !== 'undefined') { return JSON.stringify(env[name]); } } if (purge) { return 'undefined'; } } module.exports = replace; loose-envify-1.3.1/test/000077500000000000000000000000001303667365000151235ustar00rootroot00000000000000loose-envify-1.3.1/test/cli.js000066400000000000000000000021051303667365000162260ustar00rootroot00000000000000'use strict'; var child_process = require('child_process'); var test = require('tap').test; test('cli', function(t) { t.plan(5); var res = []; var ps = child_process.spawn( require.resolve('../cli.js'), [require.resolve('./react/react-with-addons-with-node_env.js')] ); var out = ''; var err = ''; ps.stdout.on('data', function(buf) { out += buf; }); ps.stderr.on('data', function(buf) { err += buf; }); ps.on('close', function() { t.equal(err, ''); t.ok(out); res.push(out); if (res.length === 2) done(); }); var envifyps = child_process.spawn( require.resolve('.bin/envify'), [require.resolve('./react/react-with-addons-with-node_env.js')] ); var envifyout = ''; var envifyerr = ''; envifyps.stdout.on('data', function(buf) { envifyout += buf; }); envifyps.stderr.on('data', function(buf) { envifyerr += buf; }); envifyps.on('close', function() { t.equal(envifyerr, ''); t.ok(envifyout); res.push(envifyout); if (res.length === 2) done(); }); function done() { t.same(res[0], res[1]); } }); loose-envify-1.3.1/test/custom.js000066400000000000000000000010651303667365000167750ustar00rootroot00000000000000'use strict'; var browserify = require('browserify'); var stream = require('stream'); var test = require('tap').test; test('custom', function(t) { t.plan(3); process.env.NODE_ENV = 'development'; var custom = require('../custom'); var source = stream.PassThrough(); var b = browserify(source); b.transform(custom({NODE_ENV: 'production'})); b.bundle(function(err, src) { t.notOk(err); t.match(String(src), /"production"/); t.notMatch(String(src), /"development"/); }); source.write('process.env.NODE_ENV;'); source.end(); }); loose-envify-1.3.1/test/edge-cases.js000066400000000000000000000030221303667365000174560ustar00rootroot00000000000000'use strict'; var browserify = require('browserify'); var looseEnvify = require('../'); var stream = require('stream'); var test = require('tap').test; test('edge-cases: assignment', function(t) { t.plan(4); var source = stream.PassThrough(); var b = browserify({ entries: source, detectGlobals: false }); b.transform(looseEnvify, {NODE_ENV: 'development'}); b.bundle(function(err, src) { t.notOk(err); t.match(String(src), /\bprocess\.env\.NODE_ENV\s+=\s+"production";/); t.match(String(src), /\bprocess\.env\.NODE_ENV\s+=\s+"line-break";/); t.match(String(src), /\bprocess\.env\.NODE_ENV\/\*comment\*\/\s+=\s+"comment";/); }); source.write('process.env.NODE_ENV = "production";'); source.write('process.env.NODE_ENV\n= "line-break";'); source.write('process.env.NODE_ENV/*comment*/ = "comment";'); source.end(); }); test('edge-cases: deep properties', function(t) { t.plan(2); var source = stream.PassThrough(); var b = browserify({ entries: source, detectGlobals: false }); b.transform(looseEnvify, {NODE_ENV: 'development'}); b.bundle(function(err, src) { t.notOk(err); t.notMatch(String(src), /"development"/); }); source.write([ 'var a = global.process.env.NODE_ENV;', 'var b = process.env.NODE_ENV.MORE_ENV;', 'var c = global.\nprocess.env.NODE_ENV;', 'var d = process.env.NODE_ENV\n.MORE_ENV;', 'var e = global./*comment*/process.env.NODE_ENV;', 'var f = process.env.NODE_ENV/*comment*/.MORE_ENV;' ].join('')); source.end(); }); loose-envify-1.3.1/test/envify.js000066400000000000000000000013111303667365000167550ustar00rootroot00000000000000'use strict'; var browserify = require('browserify'); var envify = require('envify'); var looseEnvify = require('../'); var test = require('tap').test; test('envify', function(t) { t.plan(3); var res = []; browserify({ entries: [__dirname + '/react/react-with-addons-with-node_env.js'] }) .transform(looseEnvify) .bundle(function(err, src) { t.notOk(err); if (res.push(src) === 2) done(); }); browserify({ entries: [__dirname + '/react/react-with-addons-with-node_env.js'] }) .transform(envify) .bundle(function(err, src) { t.notOk(err); if (res.push(src) === 2) done(); }); function done() { t.same(res[0], res[1]); } }); loose-envify-1.3.1/test/pkg.js000066400000000000000000000007211303667365000162420ustar00rootroot00000000000000'use strict'; var browserify = require('browserify'); var test = require('tap').test; test('pkg', function(t) { t.plan(4); process.env.NODE_ENV = 'development'; var b = browserify({ entries: [__dirname + '/pkg/index.js'] }); b.bundle(function(err, src) { t.notOk(err); t.notMatch(String(src), /\bprocess\.env\.NODE_ENV\b/); t.match(String(src), /"development"/); t.equal(String(src).match(/"development"/g).length, 2); }); }); loose-envify-1.3.1/test/pkg/000077500000000000000000000000001303667365000157045ustar00rootroot00000000000000loose-envify-1.3.1/test/pkg/index.js000066400000000000000000000000521303667365000173460ustar00rootroot00000000000000require('invariant'); require('warning'); loose-envify-1.3.1/test/pkg/node_modules/000077500000000000000000000000001303667365000203615ustar00rootroot00000000000000loose-envify-1.3.1/test/pkg/node_modules/invariant/000077500000000000000000000000001303667365000223545ustar00rootroot00000000000000loose-envify-1.3.1/test/pkg/node_modules/invariant/package.json000066400000000000000000000001351303667365000246410ustar00rootroot00000000000000{ "main": "index.js", "browserify": { "transform": [ "../../../.." ] } } loose-envify-1.3.1/test/pkg/node_modules/warning/000077500000000000000000000000001303667365000220265ustar00rootroot00000000000000loose-envify-1.3.1/test/pkg/node_modules/warning/package.json000066400000000000000000000001351303667365000243130ustar00rootroot00000000000000{ "main": "index.js", "browserify": { "transform": [ "../../../.." ] } } loose-envify-1.3.1/test/purge.js000066400000000000000000000011211303667365000165760ustar00rootroot00000000000000'use strict'; var browserify = require('browserify'); var looseEnvify = require('../'); var stream = require('stream'); var test = require('tap').test; test('purge', function(t) { t.plan(3); var source = stream.PassThrough(); var b = browserify({ entries: source }); b.transform(looseEnvify, {_:'purge'}); b.bundle(function(err, src) { t.notOk(err); t.notMatch(String(src), /\bprocess\.env\.NON_EXISTING_VAR\b/); t.match(String(src), /module\.exports = undefined;/); }); source.write('module.exports = process.env.NON_EXISTING_VAR;'); source.end(); }); loose-envify-1.3.1/test/react/000077500000000000000000000000001303667365000162215ustar00rootroot00000000000000