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

bundlewatch

Package Overview
Dependencies
Maintainers
3
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.3.3 to 0.4.0

24

lib/app/analyze/analyzeFiles/index.js

@@ -7,8 +7,5 @@ "use strict";

exports.default = exports.STATUSES = void 0;
var _bytes = _interopRequireDefault(require("bytes"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
const STATUSES = {
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
const STATUSES = exports.STATUSES = {
PASS: 'pass',

@@ -19,8 +16,5 @@ WARN: 'warn',

};
exports.STATUSES = STATUSES;
const getCompressionText = compression => {
return compression === 'none' ? '(no compression)' : `(${compression})`;
};
const analyzeFiles = ({

@@ -36,3 +30,2 @@ currentBranchFileDetails,

const baseBranchFile = baseBranchFileDetails[filePath];
if (!currentBranchFile) {

@@ -50,3 +43,2 @@ // baseBranchFile must exist

}
if (currentBranchFile.error) {

@@ -60,3 +52,2 @@ results.push({

}
const {

@@ -70,3 +61,2 @@ size,

const prettySize = maxSize === Infinity ? 'Infinity' : (0, _bytes.default)(maxSize);
if (size > maxSize) {

@@ -78,10 +68,9 @@ status = STATUSES.FAIL;

message += `< ${prettySize} `;
if (baseBranchFile) {
const diff = size - baseBranchFile.size;
if (diff < 0) {
message += `(${(0, _bytes.default)(Math.abs(diff))} smaller than ${baseBranchName}) `;
} else if (diff > 0) {
message += `(${(0, _bytes.default)(diff)} larger than ${baseBranchName}) `; // TODO: add in threshold for STATUSES.WARN
message += `(${(0, _bytes.default)(diff)} larger than ${baseBranchName}) `;
// TODO: add in threshold for STATUSES.WARN
// STATUSES.WARN

@@ -93,3 +82,2 @@ } else {

}
message += `${getCompressionText(compression)}`;

@@ -107,4 +95,2 @@ results.push({

};
var _default = analyzeFiles;
exports.default = _default;
var _default = exports.default = analyzeFiles;

@@ -7,13 +7,7 @@ "use strict";

exports.getPercentageChangeString = exports.getOverallDifference = exports.default = void 0;
var _bytes = _interopRequireDefault(require("bytes"));
var _analyzeFiles = _interopRequireWildcard(require("./analyzeFiles"));
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
const getOverallStatus = fileResults => {

@@ -24,11 +18,8 @@ return fileResults.reduce((status, fileResult) => {

}
if (status === _analyzeFiles.STATUSES.WARN || fileResult.status === _analyzeFiles.STATUSES.WARN) {
return _analyzeFiles.STATUSES.WARN;
}
return _analyzeFiles.STATUSES.PASS;
}, _analyzeFiles.STATUSES.PASS);
};
const getOverallDifference = fullResults => {

@@ -42,3 +33,2 @@ let totalBaseBranchSize = 0;

totalFileResultSize += fileResult.size;
if (fileResult.size < fileResult.baseBranchSize) {

@@ -57,5 +47,3 @@ totalRemoved += fileResult.baseBranchSize - fileResult.size;

};
exports.getOverallDifference = getOverallDifference;
const getPercentageChangeString = percentageChange => {

@@ -65,18 +53,12 @@ if (percentageChange === null) {

}
const percentageChangeFixed = percentageChange.toFixed(1);
if (percentageChange > 0) {
return `+${percentageChangeFixed}%`;
}
if (percentageChange < 0) {
return `${percentageChangeFixed}%`;
}
return `±${percentageChangeFixed}%`;
};
exports.getPercentageChangeString = getPercentageChangeString;
const getSummary = ({

@@ -90,5 +72,3 @@ overallStatus,

}
let differenceSummary = '';
if (baseBranchName) {

@@ -104,10 +84,7 @@ const {

}
if (overallStatus === _analyzeFiles.STATUSES.WARN) {
return `File(s) have passed tolerance thresholds ${differenceSummary}`;
}
return `Everything is in check ${differenceSummary}`;
};
const analyze = ({

@@ -135,4 +112,2 @@ currentBranchFileDetails,

};
var _default = analyze;
exports.default = _default;
var _default = exports.default = analyze;

@@ -7,15 +7,11 @@ "use strict";

exports.default = void 0;
var _ValidationError = _interopRequireDefault(require("../errors/ValidationError"));
var _logger = _interopRequireDefault(require("../../logger"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
const COMPRESSION_TYPES = ['gzip', 'brotli', 'none'];
const ensureFilesValid = config => {
if (!Array.isArray(config.files)) {
throw new _ValidationError.default('config.files must be an Array');
} // TODO: more validation per file, path, maxSize, compression etc
}
// TODO: more validation per file, path, maxSize, compression etc
// const FILE_TYPE = {

@@ -27,6 +23,4 @@ // path: '', // required

return config;
};
const ensureDefaultCompressionValid = config => {

@@ -36,10 +30,7 @@ if (!COMPRESSION_TYPES.includes(config.defaultCompression)) {

}
return config;
};
const ensureNormalizeFilenamesValid = config => {
const input = config.normalizeFilenames;
if (input == null) return config;
if (typeof input === 'string') {

@@ -55,6 +46,4 @@ try {

}
return config;
};
const ensureCiValid = config => {

@@ -64,3 +53,2 @@ if (!Array.isArray(config.ci.trackBranches)) {

}
const requiredOptionsToConnectToBuild = ['githubAccessToken', 'repoOwner', 'repoName', 'commitSha'];

@@ -71,6 +59,4 @@ const missingOptions = requiredOptionsToConnectToBuild.reduce((optionAccumulator, option) => {

}
return optionAccumulator;
}, []);
if (missingOptions.length === 0) {

@@ -87,3 +73,2 @@ if (!config.bundlewatchServiceHost) {

}
if (!config.ci.repoCurrentBranch) {

@@ -101,11 +86,8 @@ _logger.default.warn(`The ci.repoCurrentBranch was not supplied, bundlewatch results with not be saved:

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

@@ -7,9 +7,7 @@ "use strict";

exports.default = void 0;
const getCIVars = env => {
Object.assign(process.env, env); // eslint-disable-next-line global-require
const ci = require('ci-env'); // Take CI preferred vars over everything
Object.assign(process.env, env);
// eslint-disable-next-line global-require
const ci = require('ci-env');
// Take CI preferred vars over everything
let repoOwner = env.CI_REPO_OWNER;

@@ -21,6 +19,4 @@ let repoName = env.CI_REPO_NAME;

let repo = env.CI_REPO_SLUG || ci.repo;
if (!repo) {
const gitUrl = env.GIT_URL;
if (gitUrl) {

@@ -32,3 +28,2 @@ const GET_REPO_FROM_STRING = /github\.com[/:](.*).git/;

}
if (repo) {

@@ -38,3 +33,2 @@ if (!repoOwner) {

}
if (!repoName) {

@@ -44,3 +38,2 @@ repoName = repo.split('/')[1];

}
const githubAccessToken = env.BUNDLEWATCH_GITHUB_TOKEN || env.GITHUB_ACCESS_TOKEN;

@@ -56,4 +49,2 @@ return {

};
var _default = getCIVars;
exports.default = _default;
var _default = exports.default = getCIVars;

@@ -7,11 +7,6 @@ "use strict";

exports.default = void 0;
var _lodash = _interopRequireDefault(require("lodash.merge"));
var _getCIVars = _interopRequireDefault(require("./getCIVars"));
var _ensureValid = _interopRequireDefault(require("./ensureValid"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
const ciVars = (0, _getCIVars.default)(process.env);

@@ -35,3 +30,2 @@ const defaultConfig = {

};
const getConfig = customConfig => {

@@ -41,4 +35,2 @@ const config = (0, _lodash.default)({}, defaultConfig, customConfig);

};
var _default = getConfig;
exports.default = _default;
var _default = exports.default = getConfig;

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

exports.default = void 0;
class ValidationError {

@@ -14,6 +13,3 @@ constructor(message) {

}
}
var _default = ValidationError;
exports.default = _default;
var _default = exports.default = ValidationError;

@@ -7,16 +7,9 @@ "use strict";

exports.default = void 0;
var _fs = _interopRequireDefault(require("fs"));
var _gzipSize = _interopRequireDefault(require("gzip-size"));
var _logger = _interopRequireDefault(require("../../logger"));
var _ValidationError = _interopRequireDefault(require("../errors/ValidationError"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
const getBrotliSize = data => {
let brotli;
try {

@@ -27,6 +20,4 @@ brotli = require('brotli-size'); // eslint-disable-line global-require

}
return brotli.sync(data);
};
const getSize = ({

@@ -37,3 +28,2 @@ filePath,

let data;
try {

@@ -43,8 +33,5 @@ data = _fs.default.readFileSync(filePath);

_logger.default.error(`Could not read file: ${filePath}}`, error);
return null;
}
let size;
switch (compression) {

@@ -54,7 +41,5 @@ case 'gzip':

break;
case 'brotli':
size = getBrotliSize(data);
break;
case 'none':

@@ -64,7 +49,4 @@ default:

}
return size;
};
var _default = getSize;
exports.default = _default;
var _default = exports.default = getSize;

@@ -7,13 +7,7 @@ "use strict";

exports.default = void 0;
var _bytes = _interopRequireDefault(require("bytes"));
var _glob = _interopRequireDefault(require("glob"));
var _getSize = _interopRequireDefault(require("./getSize"));
var _logger = _interopRequireDefault(require("../../logger"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
const getLocalFileDetails = ({

@@ -27,8 +21,5 @@ files,

const paths = _glob.default.sync(file.path);
if (!paths.length) {
const errorMessage = `There is no matching file for ${file.path}`;
_logger.default.error(errorMessage);
fileDetails[file.path] = {

@@ -45,7 +36,9 @@ error: errorMessage

});
const normalizedFilePath = normalizeFilenames ? // remove matched capture groups
filePath // find all matching segments
.split(normalizeFilenames).reduce((partiallyNormalizedPath, matchingSegment) => // remove matching segment from normalized path
const normalizedFilePath = normalizeFilenames && normalizeFilenames.test(filePath) ?
// remove matched capture groups
filePath
// find all matching segments
.split(normalizeFilenames).reduce((partiallyNormalizedPath, matchingSegment) =>
// remove matching segment from normalized path
partiallyNormalizedPath.replace(matchingSegment, ''), filePath) : filePath;
if (size) {

@@ -59,5 +52,3 @@ fileDetails[normalizedFilePath] = {

const errorMessage = `Could not read file ${filePath}}`;
_logger.default.error(errorMessage);
fileDetails[filePath] = {

@@ -72,4 +63,2 @@ error: errorMessage

};
var _default = getLocalFileDetails;
exports.default = _default;
var _default = exports.default = getLocalFileDetails;

@@ -13,25 +13,10 @@ "use strict";

exports.default = void 0;
var _getLocalFileDetails = _interopRequireDefault(require("./getLocalFileDetails"));
var _BundleWatchService = _interopRequireDefault(require("./reporting/BundleWatchService"));
var _GitHubService = _interopRequireDefault(require("./reporting/GitHubService"));
var _analyze = _interopRequireDefault(require("./analyze"));
var _analyzeFiles = require("./analyze/analyzeFiles");
var _getConfig = _interopRequireDefault(require("./config/getConfig"));
var _createURL = _interopRequireDefault(require("./resultsPage/createURL"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); 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 = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : 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; }
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
const main = async ({

@@ -77,7 +62,7 @@ files,

});
return _objectSpread(_objectSpread({}, results), {}, {
return {
...results,
url
});
};
};
const bundlewatchApi = async customConfig => {

@@ -94,6 +79,4 @@ const config = (0, _getConfig.default)(customConfig);

});
try {
const results = await main(config);
if (results.status === _analyzeFiles.STATUSES.FAIL) {

@@ -111,3 +94,2 @@ await githubService.fail({

}
return Promise.resolve();

@@ -122,7 +104,6 @@ }));

}
return results;
} catch (e) {
await githubService.error({
message: `Unable to analyze, check logs. ${e ? e.messsage : ''}`
message: `Unable to analyze, check logs. ${e ? e.message : ''}`
});

@@ -132,4 +113,2 @@ throw e;

};
var _default = bundlewatchApi;
exports.default = _default;
var _default = exports.default = bundlewatchApi;

@@ -7,9 +7,5 @@ "use strict";

exports.default = void 0;
var _logger = _interopRequireDefault(require("../../../logger"));
var _axios = _interopRequireDefault(require("axios"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
class bundlewatchService {

@@ -33,7 +29,5 @@ constructor({

}
get bundlewatchServiceStoreUrl() {
return `${this.bundlewatchServiceHost}/store`;
}
get enabled() {

@@ -43,6 +37,4 @@ if (this.githubAccessToken && this.repoOwner && this.repoName && this.bundlewatchServiceHost) {

}
return false;
}
getFileDetailsForBaseBranch() {

@@ -52,5 +44,3 @@ if (!this.enabled || !this.repoBranchBase) {

}
_logger.default.info(`Retrieving comparison`);
return _axios.default.post(`${this.bundlewatchServiceStoreUrl}/lookup`, {

@@ -68,9 +58,6 @@ repoOwner: this.repoOwner,

_logger.default.debug(error);
_logger.default.error(`Unable to fetch fileDetails for baseBranch=${this.repoBranchBase} from ${this.bundlewatchServiceStoreUrl} code=${error.code || error.message}`);
return {};
});
}
saveFileDetailsForCurrentBranch({

@@ -83,15 +70,10 @@ fileDetailsByPath,

}
if (this.repoBranchBase && this.repoCurrentBranch !== this.repoBranchBase) {
_logger.default.info(`${this.repoBranchBase} !== ${this.repoCurrentBranch}, no results saved`);
}
if (!trackBranches.includes(this.repoCurrentBranch)) {
_logger.default.info(`${this.repoCurrentBranch} is not a branch to track, no results saved`);
return Promise.resolve();
}
_logger.default.info(`Saving results`);
return _axios.default.post(`${this.bundlewatchServiceStoreUrl}`, {

@@ -108,10 +90,6 @@ repoOwner: this.repoOwner,

_logger.default.debug(error);
_logger.default.error(`Unable to save fileDetails for currentBranch=${this.repoCurrentBranch} code=${error.code || error.message}`);
});
}
}
var _default = bundlewatchService;
exports.default = _default;
var _default = exports.default = bundlewatchService;

@@ -7,15 +7,9 @@ "use strict";

exports.default = void 0;
var _axios = _interopRequireDefault(require("axios"));
var _logger = _interopRequireDefault(require("../../../logger"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
const getContextForFilePath = filePath => {
let context = 'bundlewatch';
if (filePath) {
const TRUNCATE_TO_LENGTH = 35;
if (filePath.length > TRUNCATE_TO_LENGTH) {

@@ -27,6 +21,4 @@ context += ' *' + filePath.substring(filePath.length - TRUNCATE_TO_LENGTH - 2, filePath.length);

}
return context;
};
class GitHubService {

@@ -45,7 +37,5 @@ constructor({

}
get repo() {
return `${this.repoOwner}/${this.repoName}`;
}
get enabled() {

@@ -55,6 +45,4 @@ if (this.githubAccessToken && this.repoOwner && this.repoName && this.commitSha) {

}
return false;
}
update(message, url, status, filePath) {

@@ -64,11 +52,7 @@ if (!this.enabled) {

}
const context = getContextForFilePath(filePath);
if (!this.contexts.has(context) && this.contexts.size >= 5) {
_logger.default.warn(`Max reported statuses reached, github status will not be reported`);
return Promise.resolve();
}
this.contexts.add(context);

@@ -92,10 +76,7 @@ return (0, _axios.default)({

_logger.default.error(`GitHubService HTTP_${error.response.status} :: ${error.response.data ? error.response.data.message : ''}`);
return;
}
throw error;
});
}
start({

@@ -106,3 +87,2 @@ message

}
pass({

@@ -114,3 +94,2 @@ message,

}
fail({

@@ -123,3 +102,2 @@ message,

}
error({

@@ -130,6 +108,3 @@ message

}
}
var _default = GitHubService;
exports.default = _default;
var _default = exports.default = GitHubService;

@@ -7,11 +7,6 @@ "use strict";

exports.default = void 0;
var _lodash = _interopRequireDefault(require("lodash.merge"));
var _main = _interopRequireDefault(require("jsonpack/main"));
var _shortenURL = _interopRequireDefault(require("./shortenURL"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
const createURL = async ({

@@ -32,3 +27,2 @@ results,

});
const packedJSON = _main.default.pack({

@@ -44,3 +38,2 @@ details: {

});
const urlResultData = encodeURIComponent(packedJSON);

@@ -51,4 +44,2 @@ const longURL = `${bundlewatchServiceHost}/results?d=${urlResultData}`;

};
var _default = createURL;
exports.default = _default;
var _default = exports.default = createURL;

@@ -7,12 +7,7 @@ "use strict";

exports.default = void 0;
var _axios = _interopRequireDefault(require("axios"));
var _logger = _interopRequireDefault(require("../../logger"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
const API_KEY = 'AIzaSyBhfxTjDFr98q7w7Us9x0Uxk34PgdkW2WI';
const DOMAIN_BASE = 'ja2r7.app.goo.gl';
const shortenURL = url => {

@@ -30,18 +25,11 @@ return _axios.default.post(`https://firebasedynamiclinks.googleapis.com/v1/shortLinks?key=${API_KEY}`, {

}
_logger.default.error('Unable to shorten URL, no URL found in response');
_logger.default.debug(response.data);
return url;
}).catch(error => {
_logger.default.debug(error);
_logger.default.error(`Unable to shorten URL code=${error.code || error.message}`);
return url;
});
};
var _default = shortenURL;
exports.default = _default;
var _default = exports.default = shortenURL;

@@ -7,15 +7,8 @@ "use strict";

exports.default = void 0;
var _fs = _interopRequireDefault(require("fs"));
var _path = _interopRequireDefault(require("path"));
var _readPkgUp = _interopRequireDefault(require("read-pkg-up"));
var _ValidationError = _interopRequireDefault(require("../app/errors/ValidationError"));
var _logger = _interopRequireDefault(require("../logger"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
const readConfigFile = configFilePath => {

@@ -26,14 +19,10 @@ try {

_logger.default.error(`Exception while trying to read JSON config file`, error);
return null;
}
};
const getConfigFileJson = configFilePath => {
const configFileContents = readConfigFile(configFilePath);
if (!configFileContents) {
throw new _ValidationError.default(`Could not find JSON config file: ${configFilePath}}`);
}
try {

@@ -43,12 +32,8 @@ return JSON.parse(configFileContents);

_logger.default.error(`Exception while parsing JSON config`, error);
throw new _ValidationError.default(`Could not parse JSON config file: ${configFilePath}`);
}
};
const getConfigFileJS = configFilePath => {
const projectDir = _path.default.resolve(_fs.default.realpathSync(process.cwd()));
const fullPath = `${projectDir}/${configFilePath}`;
try {

@@ -58,19 +43,14 @@ return require(fullPath); // eslint-disable-line global-require

_logger.default.error(`Exception while loading JS config`, error);
throw new _ValidationError.default(`Exception while loading JS config: ${fullPath}`);
}
};
const getConfigFileContents = configFilePath => {
if (configFilePath.endsWith('.js')) {
if (configFilePath.endsWith('.js') || configFilePath.endsWith('.cjs') || configFilePath.endsWith('.mjs')) {
return getConfigFileJS(configFilePath);
}
return getConfigFileJson(configFilePath);
};
const determineConfig = cliOptions => {
const pkgJson = (_readPkgUp.default.sync() || {}).packageJson;
let pkgJsonbundlewatch = pkgJson.bundlewatch;
if (cliOptions.args && cliOptions.args.length > 0) {

@@ -80,7 +60,5 @@ if (pkgJsonbundlewatch) {

}
if (cliOptions.configFilePath) {
_logger.default.warn(`CLI files supplied, configFilePath will be ignored (this must be used on its own)`);
}
const files = cliOptions.args.map(filePathGlob => {

@@ -98,3 +76,2 @@ return {

}
if (cliOptions.config) {

@@ -104,6 +81,4 @@ if (pkgJsonbundlewatch) {

}
return getConfigFileContents(cliOptions.config);
}
if (pkgJsonbundlewatch) {

@@ -115,10 +90,6 @@ if (Array.isArray(pkgJsonbundlewatch)) {

}
return pkgJsonbundlewatch;
}
return {};
};
var _default = determineConfig;
exports.default = _default;
var _default = exports.default = determineConfig;

@@ -5,97 +5,60 @@ #!/usr/bin/env node

var _commander = _interopRequireDefault(require("commander"));
var _chalk = _interopRequireDefault(require("chalk"));
var _determineConfig = _interopRequireDefault(require("./determineConfig"));
var _logger = _interopRequireDefault(require("../logger"));
var _app = _interopRequireWildcard(require("../app"));
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
const prettyPrintResults = fullResults => {
_logger.default.log('');
fullResults.forEach(result => {
const filePath = _chalk.default.italic(result.filePath) + ':';
if (result.error) {
_logger.default.log(`${_chalk.default.red('ERROR')} ${filePath} ${result.error}`);
return;
}
if (result.status === _app.STATUSES.FAIL) {
_logger.default.log(`${_chalk.default.redBright('FAIL')} ${filePath} ${result.message}`);
return;
}
if (result.status === _app.STATUSES.WARN) {
_logger.default.log(`${_chalk.default.yellowBright('WARN')} ${filePath} ${result.message}`);
return;
}
_logger.default.log(`${_chalk.default.greenBright('PASS')} ${filePath} ${result.message}`);
});
_logger.default.log('');
};
const main = async () => {
const config = (0, _determineConfig.default)(_commander.default);
if (config.files && config.files.length > 0) {
const results = await (0, _app.default)(config);
if (results.url) {
_logger.default.log('');
_logger.default.log(`${_chalk.default.cyanBright('Result breakdown at:')} ${results.url}`);
}
prettyPrintResults(results.fullResults);
if (results.status === _app.STATUSES.FAIL) {
_logger.default.log(_chalk.default.redBright(`bundlewatch FAIL`));
_logger.default.log(results.summary);
_logger.default.log('');
return 1;
}
if (results.status === _app.STATUSES.WARN) {
_logger.default.log(_chalk.default.redBright(`bundlewatch WARN`));
_logger.default.log(results.summary);
_logger.default.log('');
return 0;
}
_logger.default.log(_chalk.default.greenBright(`bundlewatch PASS`));
_logger.default.log(results.summary);
_logger.default.log('');
return 0;
}
_logger.default.error(`Configuration missing:
Run ${_chalk.default.italic('bundlewatch --help')} for examples and options
Documentation available at: http://bundlewatch.io/`);
return 1;
};
const mainSafe = async () => {

@@ -108,46 +71,27 @@ try {

_logger.default.fatal(error.message);
return 1;
}
_logger.default.fatal(`Uncaught exception`, error);
return 1;
}
};
_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');
_commander.default.on('--help', () => {
_logger.default.log('');
_logger.default.log(' Examples:');
_logger.default.log('');
_logger.default.log(' Read configuration from package.json');
_logger.default.log(' $ bundlewatch ');
_logger.default.log('');
_logger.default.log(' Read configuration from file');
_logger.default.log(' $ bundlewatch --config internals/bundlewatch.config.js');
_logger.default.log('');
_logger.default.log(' Use command line');
_logger.default.log(' $ bundlewatch --max-size 100KB ./src/*.js /lib/*.js');
_logger.default.log('');
_logger.default.log('');
});
_commander.default.parse(process.argv);
mainSafe().then(errorCode => {
process.exitCode = errorCode;
});

@@ -7,9 +7,5 @@ "use strict";

exports.default = void 0;
var _chalk = _interopRequireDefault(require("chalk"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
const stdout = console.log; // eslint-disable-line no-console
const stderr = console.error; // eslint-disable-line no-console

@@ -22,39 +18,31 @@

stderr(error);
try {
stderr(JSON.stringify(debugObject, undefined, 2));
} catch (e) {// eat it
} catch (e) {
// eat it
}
}
};
const log = message => {
stdout(message);
};
const info = message => {
stdout(_chalk.default.cyan(`[INFO] ${message}`));
};
const warn = message => {
stdout(_chalk.default.yellow(`[WARNING] ${message}`));
};
const error = (messsage, errorStack) => {
const error = (message, errorStack) => {
if (errorStack) {
stdout(errorStack);
}
stderr(_chalk.default.red(`[ERROR] ${messsage}`));
stderr(_chalk.default.red(`[ERROR] ${message}`));
};
const fatal = (messsage, errorStack) => {
const fatal = (message, errorStack) => {
if (errorStack) {
stdout(errorStack);
}
stderr(_chalk.default.black.bgRed(`[FATAL] ${messsage}`));
stderr(_chalk.default.black.bgRed(`[FATAL] ${message}`));
};
var _default = {
var _default = exports.default = {
debug,

@@ -66,3 +54,2 @@ log,

fatal
};
exports.default = _default;
};
{
"name": "bundlewatch",
"version": "0.3.3",
"version": "0.4.0",
"description": "Keep watch of your bundle size",

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

"dependencies": {
"axios": "^0.24.0",
"axios": "^0.28.0",
"bytes": "^3.1.1",

@@ -44,10 +44,9 @@ "chalk": "^4.0.0",

"devDependencies": {
"@babel/cli": "^7.16.8",
"@babel/core": "^7.16.7",
"@babel/eslint-parser": "^7.16.5",
"@babel/plugin-proposal-object-rest-spread": "^7.16.7",
"@babel/plugin-transform-modules-commonjs": "^7.16.8",
"@babel/preset-env": "^7.16.8",
"@babel/cli": "^7.24.8",
"@babel/core": "^7.24.9",
"@babel/eslint-parser": "^7.24.8",
"@babel/preset-env": "^7.24.8",
"axios-mock-adapter": "^1.20.0",
"coveralls": "^3.1.1",
"del-cli": "^5.1.0",
"eslint": "^8.6.0",

@@ -71,3 +70,3 @@ "eslint-config-airbnb-base": "^15.0.0",

"engines": {
"node": ">=10"
"node": ">=16"
},

@@ -74,0 +73,0 @@ "bundlewatch": {

@@ -124,3 +124,3 @@ <div align="center">

- [x] New and improved CI behaviour
- [ ] Show history of BundleWatchs over time (coming soon)
- [ ] Show history of BundleWatchs over time

@@ -161,3 +161,3 @@ ## Contributors

Contributions of any kind are welcome!
[See the Contributing docs][contrib-docs-url] or [Join us on Slack][slack-invite-url].
[See the Contributing docs][contrib-docs-url].

@@ -176,6 +176,2 @@ [all-contrib-emoji-key]: https://allcontributors.org/docs/en/emoji-key

[contrib-url]: https://github.com/bundlewatch/bundlewatch/graphs/contributors
[deps]: https://david-dm.org/bundlewatch/bundlewatch/status.svg
[deps-url]: https://david-dm.org/bundlewatch/bundlewatch
[dev-deps]: https://david-dm.org/bundlewatch/bundlewatch/dev-status.svg
[dev-deps-url]: https://david-dm.org/bundlewatch/bundlewatch?type=dev
[get-ci-vars-source]: https://github.com/bundlewatch/bundlewatch/blob/master/src/app/config/getCIVars.js

@@ -182,0 +178,0 @@ [node]: https://img.shields.io/node/v/bundlewatch.svg

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