Skip to content

Commit 5b78cbc

Browse files
authored
ref: Restore node 6 support due to yarn engine checks, add performance.now fallback (getsentry#2460)
1 parent 73c28c5 commit 5b78cbc

File tree

3 files changed

+19
-10
lines changed

3 files changed

+19
-10
lines changed

.travis.yml

+3
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ jobs:
2929
name: '@sentry/packages - build + lint + test + codecov + danger [node v12]'
3030
node_js: '12'
3131
script: scripts/danger.sh
32+
- name: '@sentry/packages - build and test [node v6]'
33+
node_js: '6'
34+
script: scripts/test.sh
3235
- name: '@sentry/packages - build and test [node v8]'
3336
node_js: '8'
3437
script: scripts/test.sh

packages/apm/src/span.ts

+15-9
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,24 @@ import {
1313
uuid4,
1414
} from '@sentry/utils';
1515

16+
const INITIAL_TIME = Date.now();
17+
18+
const performanceFallback: Pick<Performance, 'now'> = {
19+
now(): number {
20+
return INITIAL_TIME - Date.now();
21+
},
22+
};
23+
1624
const crossPlatformPerformance: Pick<Performance, 'now'> = (() => {
1725
if (isNodeEnv()) {
18-
const { performance } = dynamicRequire(module, 'perf_hooks') as { performance: Performance };
19-
return performance;
20-
}
21-
return (
22-
getGlobalObject<Window>().performance || {
23-
now(): number {
24-
return Date.now();
25-
},
26+
try {
27+
const perfHooks = dynamicRequire(module, 'perf_hooks') as { performance: Performance };
28+
return perfHooks.performance;
29+
} catch (_) {
30+
return performanceFallback;
2631
}
27-
);
32+
}
33+
return getGlobalObject<Window>().performance || performanceFallback;
2834
})();
2935

3036
// TODO: Should this be exported?

packages/node/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"author": "Sentry",
88
"license": "BSD-3-Clause",
99
"engines": {
10-
"node": ">=8"
10+
"node": ">=6"
1111
},
1212
"main": "dist/index.js",
1313
"module": "esm/index.js",

0 commit comments

Comments
 (0)