File tree 3 files changed +16
-7
lines changed
3 files changed +16
-7
lines changed Original file line number Diff line number Diff line change 1
- import { Version , VersionRange } from "./_namespaces/ts" ;
1
+ import { isNodeLikeSystem , Version , VersionRange } from "./_namespaces/ts" ;
2
2
3
3
// The following definitions provide the minimum compatible support for the Web Performance User Timings API
4
4
// between browsers and NodeJS:
@@ -80,7 +80,7 @@ function tryGetWebPerformanceHooks(): PerformanceHooks | undefined {
80
80
}
81
81
82
82
function tryGetNodePerformanceHooks ( ) : PerformanceHooks | undefined {
83
- if ( typeof process !== "undefined" && process . nextTick && ! process . browser && typeof module === "object" && typeof require === "function" ) {
83
+ if ( isNodeLikeSystem ( ) ) {
84
84
try {
85
85
let performance : Performance ;
86
86
const { performance : nodePerformance , PerformanceObserver } = require ( "perf_hooks" ) as typeof import ( "perf_hooks" ) ;
Original file line number Diff line number Diff line change @@ -1429,6 +1429,17 @@ export function getNodeMajorVersion(): number | undefined {
1429
1429
return parseInt ( version . substring ( 1 , dot ) ) ;
1430
1430
}
1431
1431
1432
+ /** @internal */
1433
+ export function isNodeLikeSystem ( ) : boolean {
1434
+ // Note: we don't use the presence of `require` to check if we are in Node;
1435
+ // when bundled using esbuild, this function will be rewritten to `__require`
1436
+ // and definitely exist.
1437
+ return typeof process !== "undefined"
1438
+ && process . nextTick
1439
+ && ! process . browser
1440
+ && typeof module === "object" ;
1441
+ }
1442
+
1432
1443
// TODO: GH#18217 this is used as if it's certainly defined in many places.
1433
1444
// eslint-disable-next-line prefer-const
1434
1445
export let sys : System = ( ( ) => {
@@ -1978,9 +1989,7 @@ export let sys: System = (() => {
1978
1989
}
1979
1990
1980
1991
let sys : System | undefined ;
1981
- if ( typeof process !== "undefined" && process . nextTick && ! process . browser && typeof require !== "undefined" ) {
1982
- // process and process.nextTick checks if current environment is node-like
1983
- // process.browser check excludes webpack and browserify
1992
+ if ( isNodeLikeSystem ( ) ) {
1984
1993
sys = getNodeSystem ( ) ;
1985
1994
}
1986
1995
if ( sys ) {
Original file line number Diff line number Diff line change 1
- import { TypeScriptServicesFactory , versionMajorMinor } from "./_namespaces/ts" ;
1
+ import { isNodeLikeSystem , TypeScriptServicesFactory , versionMajorMinor } from "./_namespaces/ts" ;
2
2
3
3
// We polyfill `globalThis` here so re can reliably patch the global scope
4
4
// in the contexts we want to in the same way across script and module formats
@@ -47,7 +47,7 @@ declare global {
47
47
48
48
// if `process` is undefined, we're probably not running in node - patch legacy members onto the global scope
49
49
// @ts -ignore
50
- if ( typeof process === "undefined" || process . browser ) {
50
+ if ( ! isNodeLikeSystem ( ) ) {
51
51
/// TODO: this is used by VS, clean this up on both sides of the interface
52
52
53
53
//@ts -ignore
You can’t perform that action at this time.
0 commit comments