-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Re-land PR #139 after accidental patch release.
This reverts commit 4b46bb2.
- Loading branch information
Showing
9 changed files
with
141 additions
and
39 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export declare function install(): void; | ||
export declare function remove(): void; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
function maybe(thunk) { | ||
try { return thunk() } catch (_) {} | ||
} | ||
|
||
let needToRemove = false; | ||
|
||
export function install() { | ||
if (!maybe(() => process.env.NODE_ENV) && | ||
!maybe(() => process)) { | ||
Object.defineProperty(global, "process", { | ||
value: { | ||
env: { | ||
// This default needs to be "production" instead of "development", to | ||
// avoid the problem https://github.com/graphql/graphql-js/pull/2894 | ||
// will eventually solve, once merged and released. | ||
NODE_ENV: "production", | ||
}, | ||
}, | ||
// Let anyone else change global.process as they see fit, but hide it from | ||
// Object.keys(global) enumeration. | ||
configurable: true, | ||
enumerable: false, | ||
writable: true, | ||
}); | ||
needToRemove = true; | ||
} | ||
} | ||
|
||
// Call install() at least once, when this module is imported. | ||
install(); | ||
|
||
export function remove() { | ||
if (needToRemove) { | ||
delete global.process; | ||
needToRemove = false; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"name": "ts-invariant/process", | ||
"main": "./main.js", | ||
"module": "./module.js", | ||
"types": "./module.d.ts", | ||
"sideEffects": [ | ||
"./module.js", | ||
"./index.js" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters