Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose ts-invariant/process entry point for optional global.process polyfill. #139

Merged
merged 1 commit into from
Jun 16, 2021

Conversation

benjamn
Copy link
Member

@benjamn benjamn commented Jun 16, 2021

Though ts-invariant stopped polyfilling global.process in #94, there's a chance existing applications were accidentally depending on that API, so we can make it easy to install (and then remove!) the global.process polyfill if they still need it:

import { install, remove } from "ts-invariant/process"
install();
// Do stuff assuming process.env.NODE_ENV exists...
remove();

By default, the polyfill will be installed upon importing ts-invariant/process for the first time, so you may not need to call
install() in most cases (though it doesn't hurt).

Calling remove() cleans up the global namespace, removing the stub global.process object (if ts-invariant/process defined one). This allows you to import other packages that depend on process.env before removing the polyfill, without permanently polluting the global namespace.

Though ts-invariant stopped polyfilling global.process in #94, there's a
chance existing applications were accidentally depending on that API, so
we can make it easy to install (and then remove!) the global.process
polyfill if you still need it:

  import { install, remove } from "ts-invariant/process"
  install();
  ...
  remove();

By default, the polyfill will be installed upon importing
ts-invariant/process for the first time, so you may not need to call
install() in most cases (though it doesn't hurt).

Calling remove() cleans up the global namespace, removing the stub
global.process object (if ts-invariant/process defined one). This allows
you to import other packages that depend on process.env before removing
the polyfill, without permanently polluting the global namespace.
@benjamn benjamn self-assigned this Jun 16, 2021
@benjamn benjamn changed the title Expose ts-invariant/process entry point for optional polyfill. Expose ts-invariant/process entry point for optional global.process polyfill. Jun 16, 2021
@benjamn benjamn added the enhancement New feature or request label Jun 16, 2021
Copy link

@brainkim brainkim left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TIL this repository exists

Copy link
Member

@hwillson hwillson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 from me as well - thanks!

@benjamn benjamn merged commit 5f290c9 into main Jun 16, 2021
@benjamn benjamn deleted the ts-invariant/process-polyfill branch June 16, 2021 16:16
benjamn added a commit that referenced this pull request Jun 16, 2021
…rocess polyfill (#139)"

This reverts commit 5f290c9, which was
intended to be published in a minor version (ts-invariant@0.8.0) but was
accidentally published in version 0.7.4.
benjamn added a commit that referenced this pull request Jun 16, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants