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

webpack-sentry-plugin

Package Overview
Dependencies
Maintainers
1
Versions
30
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

webpack-sentry-plugin - npm Package Compare versions

Comparing version 1.7.1 to 1.8.0

CONTRIBUTING.md

273

dist/index.js

@@ -5,6 +5,2 @@ 'use strict';

var _lodash = require('lodash');
var _lodash2 = _interopRequireDefault(_lodash);
var _requestPromise = require('request-promise');

@@ -24,141 +20,170 @@

var DEFAULT_INCLUDE = /\.js$|\.map$/;
var DEFAULT_TRANSFORM = function DEFAULT_TRANSFORM(filename) {
return '~/' + filename;
return '~/' + filename;
};
var DEFAULT_DELETE_REGEX = /\.map$/;
module.exports = function () {
function SentryPlugin(options) {
_classCallCheck(this, SentryPlugin);
function SentryPlugin(options) {
_classCallCheck(this, SentryPlugin);
this.baseSentryURL = options.baseSentryURL || BASE_SENTRY_URL;
this.organisationSlug = options.organisation;
this.projectSlug = options.project;
this.apiKey = options.apiKey;
this.baseSentryURL = options.baseSentryURL || BASE_SENTRY_URL;
this.organisationSlug = options.organisation;
this.projectSlug = options.project;
this.apiKey = options.apiKey;
this.releaseVersion = options.release;
this.releaseVersion = options.release;
this.include = options.include || /\.js$|\.map$/;
this.exclude = options.exclude;
this.include = options.include || DEFAULT_INCLUDE;
this.exclude = options.exclude;
this.filenameTransform = options.filenameTransform || DEFAULT_TRANSFORM;
this.suppressErrors = options.suppressErrors;
}
this.filenameTransform = options.filenameTransform || DEFAULT_TRANSFORM;
this.suppressErrors = options.suppressErrors;
_createClass(SentryPlugin, [{
key: 'apply',
value: function apply(compiler) {
var _this = this;
this.deleteAfterCompile = options.deleteAfterCompile;
this.deleteRegex = options.deleteRegex || DEFAULT_DELETE_REGEX;
}
compiler.plugin('after-emit', function (compilation, cb) {
var errors = _this.ensureRequiredOptions();
_createClass(SentryPlugin, [{
key: 'apply',
value: function apply(compiler) {
var _this = this;
if (errors) {
return _this.handleErrors(errors, compilation, cb);
}
compiler.plugin('after-emit', function (compilation, cb) {
var errors = _this.ensureRequiredOptions();
var files = _this.getFiles(compilation);
if (errors) {
return _this.handleErrors(errors, compilation, cb);
}
if (_lodash2.default.isFunction(_this.releaseVersion)) {
_this.releaseVersion = _this.releaseVersion(compilation.hash);
}
var files = _this.getFiles(compilation);
return _this.createRelease().then(function () {
return _this.uploadFiles(files);
}).then(function () {
return cb();
}).catch(function (err) {
return _this.handleErrors(err, compilation, cb);
});
});
}
}, {
key: 'handleErrors',
value: function handleErrors(err, compilation, cb) {
var errorMsg = 'Sentry Plugin: ' + err;
if (this.suppressErrors) {
compilation.warnings.push(errorMsg);
} else {
compilation.errors.push(errorMsg);
}
if (typeof _this.releaseVersion === 'function') {
_this.releaseVersion = _this.releaseVersion(compilation.hash);
}
cb();
}
}, {
key: 'ensureRequiredOptions',
value: function ensureRequiredOptions() {
if (!this.organisationSlug) {
return new Error('Must provide organisation');
} else if (!this.projectSlug) {
return new Error('Must provide project');
} else if (!this.apiKey) {
return new Error('Must provide api key');
} else if (!this.releaseVersion) {
return new Error('Must provide release version');
} else {
return null;
}
}
}, {
key: 'getFiles',
value: function getFiles(compilation) {
var _this2 = this;
return _this.createRelease().then(function () {
return _this.uploadFiles(files);
}).then(function () {
return cb();
}).catch(function (err) {
return _this.handleErrors(err, compilation, cb);
});
});
return _lodash2.default.reduce(compilation.assets, function (acc, asset, name) {
return _this2.isIncludeOrExclude(name) ? acc.concat({ name: name, path: asset.existsAt }) : acc;
}, []);
}
}, {
key: 'isIncludeOrExclude',
value: function isIncludeOrExclude(filename) {
var isIncluded = this.include ? this.include.test(filename) : true;
var isExcluded = this.exclude ? this.exclude.test(filename) : false;
compiler.plugin('done', function (stats) {
if (_this.deleteAfterCompile) {
_this.deleteFiles(stats);
}
});
}
}, {
key: 'handleErrors',
value: function handleErrors(err, compilation, cb) {
var errorMsg = 'Sentry Plugin: ' + err;
if (this.suppressErrors) {
compilation.warnings.push(errorMsg);
} else {
compilation.errors.push(errorMsg);
}
return isIncluded && !isExcluded;
}
}, {
key: 'createRelease',
value: function createRelease() {
return (0, _requestPromise2.default)({
url: this.sentryReleaseUrl() + '/',
method: 'POST',
auth: {
bearer: this.apiKey
},
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({ version: this.releaseVersion })
});
}
}, {
key: 'uploadFiles',
value: function uploadFiles(files) {
return Promise.all(files.map(this.uploadFile.bind(this)));
}
}, {
key: 'uploadFile',
value: function uploadFile(_ref) {
var path = _ref.path,
name = _ref.name;
cb();
}
}, {
key: 'ensureRequiredOptions',
value: function ensureRequiredOptions() {
if (!this.organisationSlug) {
return new Error('Must provide organisation');
} else if (!this.projectSlug) {
return new Error('Must provide project');
} else if (!this.apiKey) {
return new Error('Must provide api key');
} else if (!this.releaseVersion) {
return new Error('Must provide release version');
} else {
return null;
}
}
}, {
key: 'getFiles',
value: function getFiles(compilation) {
var _this2 = this;
return (0, _requestPromise2.default)({
url: this.sentryReleaseUrl() + '/' + this.releaseVersion + '/files/',
method: 'POST',
auth: {
bearer: this.apiKey
},
formData: {
file: _fs2.default.createReadStream(path),
name: this.filenameTransform(name)
}
});
}
}, {
key: 'sentryReleaseUrl',
value: function sentryReleaseUrl() {
return this.baseSentryURL + '/' + this.organisationSlug + '/' + this.projectSlug + '/releases';
}
}]);
return Object.keys(compilation.assets).map(function (name) {
if (_this2.isIncludeOrExclude(name)) {
return { name: name, path: compilation.assets[name].existsAt };
}
return null;
}).filter(function (i) {
return i;
});
}
}, {
key: 'isIncludeOrExclude',
value: function isIncludeOrExclude(filename) {
var isIncluded = this.include ? this.include.test(filename) : true;
var isExcluded = this.exclude ? this.exclude.test(filename) : false;
return SentryPlugin;
return isIncluded && !isExcluded;
}
}, {
key: 'createRelease',
value: function createRelease() {
return (0, _requestPromise2.default)({
url: this.sentryReleaseUrl() + '/',
method: 'POST',
auth: {
bearer: this.apiKey
},
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({ version: this.releaseVersion })
});
}
}, {
key: 'uploadFiles',
value: function uploadFiles(files) {
return Promise.all(files.map(this.uploadFile.bind(this)));
}
}, {
key: 'uploadFile',
value: function uploadFile(_ref) {
var path = _ref.path,
name = _ref.name;
return (0, _requestPromise2.default)({
url: this.sentryReleaseUrl() + '/' + this.releaseVersion + '/files/',
method: 'POST',
auth: {
bearer: this.apiKey
},
formData: {
file: _fs2.default.createReadStream(path),
name: this.filenameTransform(name)
}
});
}
}, {
key: 'sentryReleaseUrl',
value: function sentryReleaseUrl() {
return this.baseSentryURL + '/' + this.organisationSlug + '/' + this.projectSlug + '/releases'; // eslint-disable-line max-len
}
}, {
key: 'deleteFiles',
value: function deleteFiles(stats) {
var _this3 = this;
Object.keys(stats.compilation.assets).filter(function (name) {
return _this3.deleteRegex.test(name);
}).forEach(function (name) {
var existsAt = stats.compilation.assets[name].existsAt;
_fs2.default.unlinkSync(existsAt);
});
}
}]);
return SentryPlugin;
}();
{
"name": "webpack-sentry-plugin",
"version": "1.7.1",
"version": "1.8.0",
"description": "Webpack plugin to upload source maps to Sentry",

@@ -14,4 +14,5 @@ "keywords": [

"build": "babel src --out-dir dist",
"prepublish": "npm test && npm run lint && npm run build",
"prepublish": "npm test && npm run format && npm run lint && npm run build",
"test": "jest",
"format": "prettier-eslint --write \"{src,test}/**/*.js\"",
"lint": "eslint src test; exit 0"

@@ -30,3 +31,2 @@ },

"dependencies": {
"lodash": "^4.17.2",
"request": "^2.79.0",

@@ -45,2 +45,4 @@ "request-promise": "^4.1.1"

"jest": "^17.0.3",
"prettier": "^0.22.0",
"prettier-eslint-cli": "^3.1.2",
"webpack": "^1.14.0"

@@ -47,0 +49,0 @@ },

@@ -114,2 +114,4 @@ # Sentry plugin

- `deleteAfterCompile`: Boolean determining whether source maps should be deleted after the webpack compile finishes. Defaults to `false`
- `organisation`: Sentry organisation to upload files to

@@ -116,0 +118,0 @@

Sorry, the diff of this file is not supported yet

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