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

unused-files-webpack-plugin

Package Overview
Dependencies
Maintainers
1
Versions
17
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

unused-files-webpack-plugin - npm Package Compare versions

Comparing version 1.3.0 to 2.0.0

lib/__tests__/index.spec.js

44

CHANGELOG.md

@@ -0,1 +1,45 @@

<a name="2.0.0"></a>
# [2.0.0](https://github.com/tomchentw/unused-files-webpack-plugin/compare/v1.3.0...v2.0.0) (2016-01-22)
### Features
* **src:** rewrite in ES2015 format ([9a61f21](https://github.com/tomchentw/unused-files-webpack-plugin/commit/9a61f21))
### BREAKING CHANGES
* src: Removes commonjs module support.
Before:
```js
// webpack.config.js
var UnusedFilesWebpackPlugin = require("unused-files-webpack-plugin");
```
After:
In ES2015 module format:
```js
import UnusedFilesWebpackPlugin from "unused-files-webpack-plugin";
// it's the same as
import { default as UnusedFilesWebpackPlugin } from "unused-files-webpack-plugin";
// You could access from named export as well.
import { UnusedFilesWebpackPlugin } from "unused-files-webpack-plugin";
```
If you still use commonjs:
```js
var UnusedFilesWebpackPlugin = require("unused-files-webpack-plugin").default;
// or named export
var UnusedFilesWebpackPlugin = require("unused-files-webpack-plugin").UnusedFilesWebpackPlugin;
// with destructive assignment
var { UnusedFilesWebpackPlugin } = require("unused-files-webpack-plugin");
```
<a name"1.3.0"></a>

@@ -2,0 +46,0 @@ ## 1.3.0 (2015-09-07)

142

lib/index.js
"use strict";
var Path = require("path");
var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
var objectAssign = require("object-assign");
var glob = require("glob");
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
function UnusedFilesWebpackPlugin (_options_) {
var options = this.options = _options_ || {};
options.pattern = options.pattern || "**/*.*";
options.failOnUnused = options.failOnUnused === true;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.UnusedFilesWebpackPlugin = undefined;
var globOptions = this.globOptions = objectAssign({
ignore: "node_modules/**/*"
}, options.globOptions);
}
var _path = require("path");
UnusedFilesWebpackPlugin.prototype.apply = function(compiler) {
var fn = this._applyAfterEmit.bind(this, compiler);
compiler.plugin("after-emit", fn);
};
var _glob = require("glob");
UnusedFilesWebpackPlugin.prototype._applyAfterEmit = function(compiler, compilation, done) {
var globOptions = this._getGlobOptions(compiler);
var _glob2 = _interopRequireDefault(_glob);
glob(this.options.pattern, globOptions, onGlobResult.bind(this));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
var fileDepsMap = this._getFileDepsMap(compilation);
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
var absolutePathResolver = Path.join.bind(Path, globOptions.cwd);
var UnusedFilesWebpackPlugin = exports.UnusedFilesWebpackPlugin = function () {
function UnusedFilesWebpackPlugin() {
var options = arguments.length <= 0 || arguments[0] === undefined ? {} : arguments[0];
function onGlobResult (err, files) {
if (err) {
compilation.errors.push(err);
} else {
var unused = files.filter(function (filepath) {
return !(absolutePathResolver(filepath) in fileDepsMap);
_classCallCheck(this, UnusedFilesWebpackPlugin);
this.options = _extends({
pattern: "**/*.*"
}, options, {
failOnUnused: options.failOnUnused === true
});
this.globOptions = _extends({
ignore: "node_modules/**/*"
}, options.globOptions);
}
_createClass(UnusedFilesWebpackPlugin, [{
key: "apply",
value: function apply(compiler) {
var _this = this;
compiler.plugin("after-emit", function (compilation, done) {
return _this._applyAfterEmit(compiler, compilation, done);
});
if (unused.length) {
var errmsg = "UnusedFilesWebpackPlugin found some unused files:\n" + unused.join("\n");
var error = new Error(errmsg);
}
}, {
key: "_applyAfterEmit",
value: function _applyAfterEmit(compiler, compilation, done) {
var _this2 = this;
if (this.options.failOnUnused) {
var globOptions = this._getGlobOptions(compiler);
var fileDepsMap = this._getFileDepsMap(compilation);
var absolutePathResolver = function absolutePathResolver(it) {
return (0, _path.join)(globOptions.cwd, it);
};
(0, _glob2.default)(this.options.pattern, globOptions, function (err, files) {
if (err) {
compilation.errors.push(err);
done();
return;
}
var unused = files.filter(function (filepath) {
return !(absolutePathResolver(filepath) in fileDepsMap);
});
if (unused.length === 0) {
done();
return;
}
var error = new Error("\nUnusedFilesWebpackPlugin found some unused files:\n" + unused.join("\n"));
if (_this2.options.failOnUnused) {
compilation.errors.push(error);

@@ -48,30 +79,33 @@ } else {

}
}
done();
});
}
done();
}
};
}, {
key: "_getGlobOptions",
value: function _getGlobOptions(compiler) {
return _extends({
cwd: compiler.context
}, this.globOptions);
}
}, {
key: "_getFileDepsMap",
value: function _getFileDepsMap(compilation) {
var fileDepsBy = {};
compilation.fileDependencies.forEach(function (usedFilepath) {
return fileDepsBy[usedFilepath] = usedFilepath;
});
UnusedFilesWebpackPlugin.prototype._getGlobOptions = function (compiler) {
var globOptions = objectAssign({}, this.globOptions);
if (null == globOptions.cwd) {
globOptions.cwd = compiler.context;
}
return globOptions;
};
var assets = compilation.assets;
UnusedFilesWebpackPlugin.prototype._getFileDepsMap = function (compilation) {
var fileDepsBy = {};
compilation.fileDependencies.forEach(function (usedFilepath) {
fileDepsBy[usedFilepath] = usedFilepath;
});
Object.keys(assets).forEach(function (assetRelpath) {
var existsAt = assets[assetRelpath].existsAt;
fileDepsBy[existsAt] = existsAt;
});
return fileDepsBy;
}
}]);
Object.keys(compilation.assets).forEach(function (assetRelpath) {
var existsAt = this[assetRelpath].existsAt;
fileDepsBy[existsAt] = existsAt;
}, compilation.assets);
return UnusedFilesWebpackPlugin;
}();
return fileDepsBy;
};
module.exports = UnusedFilesWebpackPlugin;
exports.default = UnusedFilesWebpackPlugin;
{
"__template__gist__": "https://gist.github.com/tomchentw/368a93bb748ad9d576f1#file-package-json",
"name": "unused-files-webpack-plugin",
"version": "1.3.0",
"version": "2.0.0",
"description": "Glob all files that are not compiled by webpack under webpack's context",
"main": "lib/index.js",
"files": [
"lib/",
"src/",
"CHANGELOG.md"
],
"scripts": {
"build": "echo 'build script' && exit 0",
"test:cov": "istanbul cover --report lcov tape $npm_package_config_tape",
"test": "tape $npm_package_config_tape"
"clean": "rimraf lib",
"prebuild": "npm run lint && npm run clean",
"build": "cross-env NODE_ENV=production babel src --out-dir lib",
"lint": "cross-env NODE_ENV=test eslint .",
"pretest:cov": "npm run lint",
"pretest": "npm run lint",
"test:cov": "cross-env NODE_ENV=test babel-node ./node_modules/.bin/isparta cover --report lcov ./node_modules/.bin/tape -- $npm_package_config_tape",
"test": "cross-env NODE_ENV=test babel-node ./node_modules/.bin/tape $npm_package_config_tape"
},
"config": {
"tape": "lib/**/*-test.js"
"tape": "src/**/*.spec.js"
},

@@ -38,13 +47,27 @@ "repository": {

"devDependencies": {
"codeclimate-test-reporter": "^0.1.0",
"istanbul": "^0.3.19",
"memory-fs": "^0.2.0",
"tape": "^4.2.0",
"tomchentw-npm-dev": "^3.0.0",
"webpack": "^1.12.1"
"babel-cli": "^6.4.5",
"babel-core": "^6.4.5",
"babel-eslint": "^5.0.0-beta6",
"babel-plugin-transform-flow-comments": "^6.4.0",
"babel-plugin-typecheck": "^3.6.1",
"babel-preset-es2015": "^6.3.13",
"babel-preset-react": "^6.3.13",
"babel-preset-stage-0": "^6.3.13",
"babel-register": "^6.4.3",
"codeclimate-test-reporter": "^0.3.0",
"cross-env": "^1.0.7",
"eslint": "^1.10.3",
"eslint-config-airbnb": "^3.1.0",
"eslint-plugin-react": "^3.15.0",
"isparta": "^4.0.0",
"istanbul": "^0.4.2",
"memory-fs": "^0.3.0",
"rimraf": "^2.5.0",
"tape": "^4.4.0",
"tomchentw-npm-dev": "^3.2.0",
"webpack": "^1.12.11"
},
"dependencies": {
"glob": "^5.0.7",
"object-assign": "^4.0.1"
"glob": "^6.0.4"
}
}

@@ -44,3 +44,3 @@ # unused-files-webpack-plugin [![Travis CI][travis-image]][travis-url] [![Quality][codeclimate-image]][codeclimate-url] [![Coverage][codeclimate-coverage-image]][codeclimate-coverage-url] [![Dependencies][gemnasium-image]][gemnasium-url] [![Gitter][gitter-image]][gitter-url]

* Default: `undefined`
* Default: `false`
* Explicitly set it to `true` to enable this feature

@@ -47,0 +47,0 @@

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