Skip to content

Commit

Permalink
Avoid assigning globalThis.process when not defined.
Browse files Browse the repository at this point in the history
Follow-up to #91.

Some websites use the existence of a global process object to
feature-detect the Node.js host environment, so it's not safe for this
package to initialize globalThis.process when it does not already exist.
  • Loading branch information
benjamn committed Mar 17, 2021
1 parent ee0e656 commit b1a3288
Showing 1 changed file with 0 additions and 10 deletions.
10 changes: 0 additions & 10 deletions packages/ts-invariant/src/invariant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,15 +64,5 @@ export function setVerbosity(level: VerbosityLevel): VerbosityLevel {
// also attempt to define the stub globally when it is not already defined.
const processStub = global.process || { env: {} };
export { processStub as process };
if (!global.process) try {
Object.defineProperty(globalThis, "process", {
value: processStub,
writable: true,
enumerable: false,
configurable: true
});
} catch {
// If this fails, it isn't the end of the world.
}

export default invariant;

0 comments on commit b1a3288

Please sign in to comment.