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

bundlewatch

Package Overview
Dependencies
Maintainers
2
Versions
17
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

bundlewatch - npm Package Compare versions

Comparing version 0.2.7 to 0.3.0

36

lib/app/analyze/index.js

@@ -6,6 +6,8 @@ "use strict";

});
exports.default = exports.getPercentageChangeString = exports.getOverallDifference = void 0;
exports.default = exports.normalizeFilename = exports.getPercentageChangeString = exports.getOverallDifference = void 0;
var _bytes = _interopRequireDefault(require("bytes"));
var _path = require("path");
var _analyzeFiles = _interopRequireWildcard(require("./analyzeFiles"));

@@ -19,2 +21,8 @@

function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
const getOverallStatus = fileResults => {

@@ -108,8 +116,25 @@ return fileResults.reduce((status, fileResult) => {

const normalizeFilename = normalizeFilenames => result => {
var _filename$match;
let filename = (0, _path.basename)(result.filePath);
const [, ...matches] = (_filename$match = filename.match(normalizeFilenames)) !== null && _filename$match !== void 0 ? _filename$match : [];
let normalized = filename;
matches.forEach(match => {
normalized = normalized.replace(match, '');
});
return _objectSpread(_objectSpread({}, result), {}, {
filePath: result.filePath.slice(0, -filename.length) + normalized
});
};
exports.normalizeFilename = normalizeFilename;
const analyze = ({
currentBranchFileDetails,
baseBranchFileDetails,
baseBranchName
baseBranchName,
normalizeFilenames
}) => {
const fileResults = (0, _analyzeFiles.default)({
let fileResults = (0, _analyzeFiles.default)({
currentBranchFileDetails,

@@ -119,2 +144,7 @@ baseBranchFileDetails,

});
if (normalizeFilenames != null) {
fileResults = fileResults.map(normalizeFilename(normalizeFilenames));
}
const overallStatus = getOverallStatus(fileResults);

@@ -121,0 +151,0 @@ const summary = getSummary({

@@ -16,3 +16,3 @@ "use strict";

const ensureValid = config => {
const ensureFilesValid = config => {
if (!Array.isArray(config.files)) {

@@ -28,2 +28,6 @@ throw new _ValidationError.default('config.files must be an Array');

return config;
};
const ensureDefaultCompressionValid = config => {
if (!COMPRESSION_TYPES.includes(config.defaultCompression)) {

@@ -33,2 +37,24 @@ throw new _ValidationError.default('config.compression must be a valid type');

return config;
};
const ensureNormalizeFilenamesValid = config => {
const input = config.normalizeFilenames;
if (input == null) return config;
if (typeof input === 'string') {
try {
// eslint-disable-next-line no-param-reassign
config.normalizeFilenames = new RegExp(input);
} catch (e) {
throw new Error(`config.normalizeFilenames (${input}) is not a valid RegExp.`);
}
} else if (!(input instanceof RegExp)) {
throw new Error(`config.normalizeFilenames (${input}) is not a valid RegExp.`);
}
return config;
};
const ensureCiValid = config => {
if (!Array.isArray(config.ci.trackBranches)) {

@@ -71,5 +97,11 @@ throw new _ValidationError.default('config.ci.trackBranches must be an Array');

}
return config;
};
const validators = [ensureFilesValid, ensureDefaultCompressionValid, ensureNormalizeFilenamesValid, ensureCiValid]; // Runs and returns the result of each validator
const ensureValid = config => validators.reduce((c, validator) => validator(c), config);
var _default = ensureValid;
exports.default = _default;

4

lib/app/config/getConfig.js

@@ -18,2 +18,3 @@ "use strict";

const defaultConfig = {
normalizeFilenames: null,
files: [],

@@ -37,4 +38,3 @@ bundlewatchServiceHost: 'https://service.bundlewatch.io',

const config = (0, _lodash.default)({}, defaultConfig, customConfig);
(0, _ensureValid.default)(config);
return config;
return (0, _ensureValid.default)(config);
};

@@ -41,0 +41,0 @@

@@ -40,3 +40,4 @@ "use strict";

ci,
defaultCompression
defaultCompression,
normalizeFilenames
}) => {

@@ -64,3 +65,4 @@ const currentBranchFileDetails = (0, _getLocalFileDetails.default)({

baseBranchFileDetails,
baseBranchName: ci.repoBranchBase
baseBranchName: ci.repoBranchBase,
normalizeFilenames
});

@@ -67,0 +69,0 @@ const url = await (0, _createURL.default)({

@@ -89,3 +89,4 @@ "use strict";

files,
defaultCompression: cliOptions.compression || 'gzip'
defaultCompression: cliOptions.compression || 'gzip',
normalizeFilenames: cliOptions.normalize
};

@@ -92,0 +93,0 @@ }

@@ -117,3 +117,3 @@ #!/usr/bin/env node

_commander.default.usage('[options] <filePathGlobs ...>').option('--config [configFilePath]', 'file to read configuration from, if used all options are blown away').option('--max-size [maxSize]', 'maximum size threshold (e.g. 3kb)').option('--compression [compression]', 'specify which compression algorithm to use');
_commander.default.usage('[options] <filePathGlobs ...>').option('--config [configFilePath]', 'file to read configuration from, if used all options are blown away').option('--max-size [maxSize]', 'maximum size threshold (e.g. 3kb)').option('--compression [compression]', 'specify which compression algorithm to use').option('--normalize [regex]', 'normalize filenames via regex, any match will be removed');

@@ -120,0 +120,0 @@ _commander.default.on('--help', () => {

{
"name": "bundlewatch",
"version": "0.2.7",
"version": "0.3.0",
"description": "Keep watch of your bundle size",

@@ -56,3 +56,3 @@ "repository": {

"coveralls": "^3.0.1",
"eslint": "^6.8.0",
"eslint": "^7.2.0",
"eslint-config-airbnb-base": "^14.0.0",

@@ -65,6 +65,6 @@ "eslint-config-prettier": "^6.0.0",

"jest": "^26.0.0",
"jest-junit": "^10.0.0",
"jest-junit": "^11.0.0",
"lint-staged": "^10.0.8",
"prettier": "^2.0.5",
"yarn-deduplicate": "^2.0.0"
"yarn-deduplicate": "^3.0.0"
},

@@ -71,0 +71,0 @@ "jest": {

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