From f16f9763cb9786912f576bef7cb8974962ed3d72 Mon Sep 17 00:00:00 2001 From: Rajiv Tirumalareddy Date: Wed, 14 Jan 2015 11:20:36 -0800 Subject: [PATCH] 0.1.0 --- .gitignore | 2 ++ .npmignore | 2 ++ CONTRIBUTING.md | 7 +++++ LICENSE.md | 29 +++++++++++++++++ README.md | 62 +++++++++++++++++++++++++++++++++++++ lib/index.js | 5 +++ package.json | 17 ++++++++-- tests/fixtures/app/index.js | 9 ++++-- tests/unit/index.js | 23 ++++++++------ 9 files changed, 143 insertions(+), 13 deletions(-) create mode 100644 .npmignore create mode 100644 CONTRIBUTING.md create mode 100644 LICENSE.md create mode 100644 README.md diff --git a/.gitignore b/.gitignore index ce13816..fe96834 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,4 @@ node_modules tests/fixtures/app/bundle.js +/artifacts/ +npm-debug.log diff --git a/.npmignore b/.npmignore new file mode 100644 index 0000000..50db84d --- /dev/null +++ b/.npmignore @@ -0,0 +1,2 @@ +/artifacts/ +/tests/ diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 0000000..6bbf64c --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,7 @@ +Contributing Code to `webpack-strip` +------------------------------- + +Please be sure to sign our [CLA][] before you submit pull requests or otherwise contribute to `webpack-strip`. This protects developers, who rely on [BSD license][]. + +[BSD license]: https://github.com/yahoo/webpack-strip/blob/master/LICENSE.md +[CLA]: https://yahoocla.herokuapp.com/ diff --git a/LICENSE.md b/LICENSE.md new file mode 100644 index 0000000..2464f59 --- /dev/null +++ b/LICENSE.md @@ -0,0 +1,29 @@ +Software License Agreement (BSD License) +======================================== + +Copyright (c) 2015, Yahoo! Inc. All rights reserved. +---------------------------------------------------- + +Redistribution and use of this software in source and binary forms, with or +without modification, are permitted provided that the following conditions are +met: + + * Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + * Neither the name of Yahoo! Inc. nor the names of YUI's contributors may be + used to endorse or promote products derived from this software without + specific prior written permission of Yahoo! Inc. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR +ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON +ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/README.md b/README.md new file mode 100644 index 0000000..e298dd2 --- /dev/null +++ b/README.md @@ -0,0 +1,62 @@ +Webpack Strip +============= + +Simple [Webpack](http://webpack.github.io/) loader to strip custom functions from your code. This can be useful if you want to use debug statements while developing your app but don't want this info exposed in your production code. + +##Usage: + +In your client js source files: + +```javascript + +var debug = require('debug')('MyFile'); + +var makeFoo = function () { + // The following two lines of code will be stripped with our webpack loader + debug('makeFoo called'); + debug('makeFoo args', arguments); + // This code would remain + return 'Foo'; +}; + +``` + +### Single function +In your webpack config: + +```javascript +{ + module: { + loaders: [ + { test: /\.js$/, loader: "webpack-strip?strip[]=debug" } + ] + } +}; +``` + +### Multiple functions +In your webpack config: + +```javascript +{ + module: { + loaders: [ + { test: /\.js$/, loader: "webpack-strip?strip[]=debug,strip[]=console.log" } + ] + } +}; +``` + +### Use as library +In your webpack config: + +```javascript +var WebpackStrip = require('webpack-strip') +{ + module: { + loaders: [ + { test: /\.js$/, loader: WebpackStrip.loader('debug', 'console.log') } + ] + } +}; +``` diff --git a/lib/index.js b/lib/index.js index 163634d..9b6f111 100644 --- a/lib/index.js +++ b/lib/index.js @@ -1,3 +1,8 @@ +/** + * Copyright 2015, Yahoo! Inc. + * Copyrights licensed under the New BSD License. See the accompanying LICENSE file for terms. + */ + "use strict"; var loaderUtils = require('loader-utils'); diff --git a/package.json b/package.json index 18ee060..b3f1676 100644 --- a/package.json +++ b/package.json @@ -1,9 +1,11 @@ { "name": "webpack-strip", - "version": "0.0.1", - "description": "Webpack loader to strip arbitrary functions out of your code.", + "version": "0.1.0", + "description": "Webpack loader to strip arbitrary functions out of your production code.", "main": "lib/index.js", "scripts": { + "cover": "node node_modules/istanbul/lib/cli.js cover --dir artifacts -- ./node_modules/mocha/bin/_mocha tests/unit/ --recursive --reporter spec", + "lint": "./node_modules/.bin/jshint lib tests", "test": "mocha tests/unit --recursive --reporter spec" }, "keywords": [ @@ -13,10 +15,21 @@ "author": "Rajiv Tirumalareddy ", "devDependencies": { "chai": "^1.10.0", + "istanbul": "^0.3.5", + "jshint": "^2.5.11", "mocha": "^2.1.0", "webpack": "^1.4.15" }, "dependencies": { "loader-utils": "^0.2.6" + }, + "licenses": [ + { + "type": "BSD", + "url": "https://github.com/yahoo/webpack-strip/blob/master/LICENSE.md" + } + ], + "jshintConfig": { + "node": true } } diff --git a/tests/fixtures/app/index.js b/tests/fixtures/app/index.js index d18badb..87a1ef3 100644 --- a/tests/fixtures/app/index.js +++ b/tests/fixtures/app/index.js @@ -1,7 +1,12 @@ +/** + * Copyright 2015, Yahoo! Inc. + * Copyrights licensed under the New BSD License. See the accompanying LICENSE file for terms. + */ + var makeFoo = function (bar, baz) { // The following 2 lines of code will be stripped with our webpack loader - assert(1!==2, '1 must not equal 2'); - debug('1 must not equal 2'); + console.log('some debug info'); + debug('better debug info'); // This code would remain return new Foo(bar, baz); }; diff --git a/tests/unit/index.js b/tests/unit/index.js index 2e14e1a..74578c3 100644 --- a/tests/unit/index.js +++ b/tests/unit/index.js @@ -1,3 +1,8 @@ +/** + * Copyright 2015, Yahoo! Inc. + * Copyrights licensed under the New BSD License. See the accompanying LICENSE file for terms. + */ + /*global describe,it */ 'use strict'; @@ -28,37 +33,37 @@ var createWebpackConfigWithLoader = function (loaderOpt) { var createWebpackTest = function (done) { return function(err, stats) { - expect(err).to.be.null; - expect(stats.hasErrors()).to.be.false; + expect(err).to.be.null(); + expect(stats.hasErrors()).to.be.false(); var statsJson = stats.toJson(); expect(statsJson.errors).to.have.length(0); - var originalSource = fs.readFileSync(cwd + '/index.js', {encoding: 'utf8'}) - expect(originalSource).to.contain('assert'); + var originalSource = fs.readFileSync(cwd + '/index.js', {encoding: 'utf8'}); + expect(originalSource).to.contain('console.log'); expect(originalSource).to.contain('debug'); var strippedSource = statsJson.modules[0].source; - expect(strippedSource).to.not.contain('assert'); + expect(strippedSource).to.not.contain('console.log'); expect(strippedSource).to.not.contain('debug'); done(err); }; -} +}; describe('integration', function () { describe('webpack', function () { it('should work with loader query params', function (done) { webpack( - createWebpackConfigWithLoader(loaderLibPath + '?strip[]=assert,strip[]=debug'), + createWebpackConfigWithLoader(loaderLibPath + '?strip[]=console.log,strip[]=debug'), createWebpackTest(done) ); }); - it('should work with loader usage as library', function (done) { + it('should work with loader used as library', function (done) { webpack( - createWebpackConfigWithLoader(loaderLib.loader('assert', 'debug')), + createWebpackConfigWithLoader(loaderLib.loader('console.log', 'debug')), createWebpackTest(done) ); });