Skip to content

Commit 0e3552d

Browse files
authored
build(cdn): Ensure ES5 bundles do not use non-ES5 code (#7550)
1 parent 21dd20d commit 0e3552d

File tree

16 files changed

+255
-28
lines changed

16 files changed

+255
-28
lines changed

.github/workflows/build.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -321,8 +321,10 @@ jobs:
321321
uses: ./.github/actions/restore-cache
322322
env:
323323
DEPENDENCY_CACHE_KEY: ${{ needs.job_build.outputs.dependency_cache_key }}
324-
- name: Run linter
324+
- name: Lint source files
325325
run: yarn lint
326+
- name: Validate ES5 builds
327+
run: yarn validate:es5
326328

327329
job_circular_dep_check:
328330
name: Circular Dependency Check

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
"link:yarn": "lerna exec yarn link",
2424
"lint": "lerna run lint",
2525
"lint:eslint": "lerna run lint:eslint",
26+
"validate:es5": "lerna run validate:es5",
2627
"postpublish": "lerna run --stream --concurrency 1 postpublish",
2728
"test": "lerna run --ignore @sentry-internal/* test",
2829
"test:unit": "lerna run --ignore @sentry-internal/* test:unit",
@@ -89,6 +90,7 @@
8990
"chai": "^4.1.2",
9091
"codecov": "^3.6.5",
9192
"deepmerge": "^4.2.2",
93+
"es-check": "7.1.0",
9294
"eslint": "7.32.0",
9395
"jest": "^27.5.1",
9496
"jest-environment-node": "^27.5.1",

packages/browser/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@
6666
"lint": "run-s lint:prettier lint:eslint",
6767
"lint:eslint": "eslint . --format stylish",
6868
"lint:prettier": "prettier --check \"{src,test,scripts}/**/**.ts\"",
69+
"validate:es5": "es-check es5 build/bundles/bundle.es5.js",
6970
"size:check": "run-p size:check:es5 size:check:es6",
7071
"size:check:es5": "cat build/bundles/bundle.min.js | gzip -9 | wc -c | awk '{$1=$1/1024; print \"ES5: \",$1,\"kB\";}'",
7172
"size:check:es6": "cat build/bundles/bundle.es6.min.js | gzip -9 | wc -c | awk '{$1=$1/1024; print \"ES6: \",$1,\"kB\";}'",

packages/eslint-config-sdk/src/index.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,9 @@ module.exports = {
161161

162162
// All imports should be accounted for
163163
'import/no-extraneous-dependencies': 'error',
164+
165+
// Do not allow usage of functions we do not polyfill for ES5
166+
'@sentry-internal/sdk/no-unsupported-es6-methods': 'error',
164167
},
165168
},
166169
{

packages/eslint-plugin-sdk/src/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,6 @@ module.exports = {
1313
'no-optional-chaining': require('./rules/no-optional-chaining'),
1414
'no-nullish-coalescing': require('./rules/no-nullish-coalescing'),
1515
'no-eq-empty': require('./rules/no-eq-empty'),
16+
'no-unsupported-es6-methods': require('./rules/no-unsupported-es6-methods'),
1617
},
1718
};
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
'use strict';
2+
3+
/**
4+
* Taken and adapted from https://github.com/nkt/eslint-plugin-es5/blob/master/src/rules/no-es6-methods.js
5+
*/
6+
7+
module.exports = {
8+
meta: {
9+
docs: {
10+
description: 'Forbid methods added in ES6 which are not polyfilled by Sentry.',
11+
},
12+
schema: [],
13+
},
14+
create(context) {
15+
return {
16+
CallExpression(node) {
17+
if (!node.callee || !node.callee.property) {
18+
return;
19+
}
20+
const functionName = node.callee.property.name;
21+
22+
const es6ArrayFunctions = ['copyWithin', 'values', 'fill'];
23+
const es6StringFunctions = ['repeat'];
24+
25+
const es6Functions = [].concat(es6ArrayFunctions, es6StringFunctions);
26+
if (es6Functions.indexOf(functionName) > -1) {
27+
context.report({
28+
node: node.callee.property,
29+
message: `ES6 methods not allowed: ${functionName}`,
30+
});
31+
}
32+
},
33+
};
34+
},
35+
};

packages/node/.eslintrc.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,6 @@ module.exports = {
66
rules: {
77
'@sentry-internal/sdk/no-optional-chaining': 'off',
88
'@sentry-internal/sdk/no-nullish-coalescing': 'off',
9+
'@sentry-internal/sdk/no-unsupported-es6-methods': 'off',
910
},
1011
};

packages/overhead-metrics/.eslintrc.cjs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ module.exports = {
1010
'import/no-unresolved': 'off',
1111
'@sentry-internal/sdk/no-optional-chaining': 'off',
1212
'@sentry-internal/sdk/no-nullish-coalescing': 'off',
13+
'@sentry-internal/sdk/no-unsupported-es6-methods': 'off',
1314
'jsdoc/require-jsdoc': 'off',
1415
},
1516
},

packages/replay/.eslintrc.js

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,21 +7,8 @@ module.exports = {
77
extends: ['../../.eslintrc.js'],
88
overrides: [
99
{
10-
files: ['worker/**/*.ts'],
11-
parserOptions: {
12-
// TODO: figure out if we need a worker-specific tsconfig
13-
project: ['tsconfig.worker.json'],
14-
},
15-
rules: {
16-
// We cannot use backticks, as that conflicts with the stringified worker
17-
'prefer-template': 'off',
18-
},
19-
},
20-
{
21-
files: ['src/worker/**/*.js'],
22-
parserOptions: {
23-
sourceType: 'module',
24-
},
10+
files: ['src/**/*.ts'],
11+
rules: {},
2512
},
2613
{
2714
files: ['jest.setup.ts', 'jest.config.ts'],

packages/svelte/.eslintrc.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,7 @@ module.exports = {
33
browser: true,
44
},
55
extends: ['../../.eslintrc.js'],
6+
rules: {
7+
'@sentry-internal/sdk/no-unsupported-es6-methods': 'off',
8+
},
69
};

0 commit comments

Comments
 (0)