Hooks for sentry integration (#1460)

* add sentry webpack plugin

* allow override of webpack config

* work around cheerio inability to parse jinga templates

* webpack can not minify jinja templates

* allow script injection to specify other attributes

* allow script injection to specify other attributes

* Adjustments to make plugin systems work

* Add sourcemaps for javascript in prod webpack

* Update .gitignore

* Fix spelling errors

Co-authored-by: Matt Weiden <538456+mweiden@users.noreply.github.com>
This commit is contained in:
Bruce Martin
2020-05-08 15:59:56 -07:00
committed by GitHub
co-authored by Matt Weiden
parent 9026e0ce41
commit c1bf491a96
12 changed files with 100 additions and 38 deletions
+2 -5
View File
@@ -1,8 +1,4 @@
include ../common.mk
# https://stackoverflow.com/a/14777895/9587410
ifeq ($(shell uname),Darwin) # is Windows_NT on XP, 2000, 7, Vista, 10...
IS_DARWIN := "true"
endif
ANNOTATIONS := $(if $(ANNOTATIONS),$(ANNOTATIONS),../server/test/test_datasets/pbmc3k-annotations.csv)
ANNOTATIONS_FILENAME := $(shell basename $(ANNOTATIONS))
@@ -21,8 +17,9 @@ install:
npm install
.PHONY: build
WEBPACK_CONFIG ?= configuration/webpack/webpack.config.prod.js
build:
npm run build
npm run build $(WEBPACK_CONFIG)
# Formatting code
+9 -11
View File
@@ -32,17 +32,15 @@ class CspHashPlugin {
};
}
// remove no-csp-hash attributes
let foundOne = false;
$("script[no-csp-hash]").each((i, elmt) => {
$(elmt).removeAttr("no-csp-hash");
foundOne = true;
});
$("style[no-csp-hash]").each((i, elmt) => {
$(elmt).removeAttr("no-csp-hash");
foundOne = true;
});
if (foundOne) data.html = $.html();
// Remove no-csp-hash attributes. Cheerio does not parse Jinja templates
// correctly, so we brute force this with a regular expression.
data.html = data.html
.replace(/(<script .*)no-csp-hash(.*>)/, (match, p1, p2) =>
[p1, p2].join("")
)
.replace(/(<style .*)no-csp-hash(.*>)/, (match, p1, p2) =>
[p1, p2].join("")
);
// Tell webpack to move on
cb(null, data);
@@ -2,7 +2,6 @@
const path = require("path");
const HtmlWebpackPlugin = require("html-webpack-plugin");
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
const HtmlWebpackInlineSourcePlugin = require("html-webpack-inline-source-plugin");
const FaviconsWebpackPlugin = require("favicons-webpack-plugin");
const { CleanWebpackPlugin } = require("clean-webpack-plugin");
const TerserJSPlugin = require("terser-webpack-plugin");
@@ -38,6 +37,7 @@ module.exports = {
}),
],
},
devtool: "source-map",
module: {
rules: [
{
@@ -87,18 +87,7 @@ module.exports = {
filename: "index.html",
template: path.resolve("index_template.html"),
decodeEntities: false,
minify: {
removeComments: true,
collapseWhitespace: true,
removeRedundantAttributes: true,
useShortDoctype: true,
removeEmptyAttributes: true,
removeStyleLinkTypeAttributes: true,
keepClosingSlash: true,
minifyJS: true,
minifyCSS: true,
minifyURLs: true,
},
minify: false,
}),
new CleanWebpackPlugin({
verbose: true,
+7 -4
View File
@@ -50,12 +50,15 @@
</noscript>
<div id="root"></div>
{% for script in SCRIPTS %}
<script type="text/javascript" src="{{script | safe}}"></script>
{% endfor %}
{% for script in SCRIPTS -%}
<script type="text/javascript"
{{ ('integrity="%s"' % script.integrity) | safe if script.integrity }}
{{ ('crossorigin="%s"' % script.crossorigin) | safe if script.crossorigin }}
src="{{script.src | safe}}"
></script>
{%- endfor %}
{% for ils in INLINE_SCRIPTS %}
<!-- caution: do not change white space in this script element -->
<script type="text/javascript" no-csp-hash>{% include ils %}</script>
{% endfor %}
</body>
+43
View File
@@ -2547,6 +2547,49 @@
}
}
},
"@sentry/cli": {
"version": "1.52.3",
"resolved": "https://registry.npmjs.org/@sentry/cli/-/cli-1.52.3.tgz",
"integrity": "sha512-QOSIg5hxAEa6v6H7oEeF6A/Rpa0wloMhbu0Qed6zHv3lyoqf0Z34Kq2jCXdqGsOE3IzkO+3CNy81F6361j5TKg==",
"dev": true,
"requires": {
"https-proxy-agent": "^5.0.0",
"mkdirp": "^0.5.5",
"node-fetch": "^2.6.0",
"progress": "^2.0.3",
"proxy-from-env": "^1.1.0"
},
"dependencies": {
"https-proxy-agent": {
"version": "5.0.0",
"resolved": "https://registry.npmjs.org/https-proxy-agent/-/https-proxy-agent-5.0.0.tgz",
"integrity": "sha512-EkYm5BcKUGiduxzSt3Eppko+PiNWNEpa4ySk9vTC6wDsQJW9rHSa+UhGNJoRYp7bz6Ht1eaRIa6QaJqO5rCFbA==",
"dev": true,
"requires": {
"agent-base": "6",
"debug": "4"
}
},
"mkdirp": {
"version": "0.5.5",
"resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-0.5.5.tgz",
"integrity": "sha512-NKmAlESf6jMGym1++R0Ra7wvhV+wFW63FaSOFPwRahvea0gMUcGUhVeAg/0BC0wiv9ih5NYPB1Wn1UEI1/L+xQ==",
"dev": true,
"requires": {
"minimist": "^1.2.5"
}
}
}
},
"@sentry/webpack-plugin": {
"version": "1.11.1",
"resolved": "https://registry.npmjs.org/@sentry/webpack-plugin/-/webpack-plugin-1.11.1.tgz",
"integrity": "sha512-7uQiqHXK84GYy2mL/c+cW/QBtr/D8fNmf8U5nUDN4+44aNrQxSJ4vJmYJbxYg1zO6qN/xZyqJt3uKBlgA3FkZg==",
"dev": true,
"requires": {
"@sentry/cli": "^1.52.3"
}
},
"@sinonjs/commons": {
"version": "1.7.1",
"resolved": "https://registry.npmjs.org/@sinonjs/commons/-/commons-1.7.1.tgz",
+4 -2
View File
@@ -6,8 +6,9 @@
"repository": "https://github.com/chanzuckerberg/cellxgene",
"scripts": {
"clean": "rimraf build",
"build": "npm run clean && webpack --config configuration/webpack/webpack.config.prod.js",
"dev": "npm run clean && webpack --config configuration/webpack/webpack.config.dev.js",
"build": "npm run clean && webpack --config",
"prod": "npm run build -- configuration/webpack/webpack.config.prod.js",
"dev": "npm run build -- configuration/webpack/webpack.config.dev.js",
"fmt": "eslint --fix src",
"lint": "eslint src"
},
@@ -62,6 +63,7 @@
"@babel/preset-react": "^7.9.4",
"@babel/register": "^7.9.0",
"@babel/runtime": "^7.9.2",
"@sentry/webpack-plugin": "^1.11.1",
"babel-eslint": "^10.1.0",
"babel-jest": "^25.2.6",
"babel-loader": "^8.1.0",