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

fix: replace isBrowser() with home made feature detection #1054

Merged
merged 5 commits into from
Jul 12, 2021

Conversation

alexander-fenster
Copy link
Contributor

Fixes #1046 by replacing general isBrowser() check with targeted feature detection.

Cc: @schmidt-sebastian

@alexander-fenster alexander-fenster requested a review from a team as a code owner July 9, 2021 22:26
@google-cla google-cla bot added the cla: yes This human has signed the Contributor License Agreement. label Jul 9, 2021
} from './featureDetection';

if (!hasTextEncoder() || !hasTextDecoder()) {
if (isNodeJS()) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I generally don't like the idea of trying to figure out if something is Node.js or not. The philosophy behind feature detection is to say which browser/env it is doesn't matter, and instead focus on the availability of the API itself. Things like electron and webpack make figuring out "is this node?" a fools errand. All that having been said - I don't have a ready made suggestion on how to do this better :)

Copy link
Contributor Author

@alexander-fenster alexander-fenster Jul 10, 2021

Choose a reason for hiding this comment

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

I thought about this. There are several use cases of isNodeJS(), what I actually need is hasUtil() (can require("util"), hasEmitWarning(), and something for "can authenticate GoogleAuth instance by accessing filesystem". Checking for process.emitWarning is straightforward (and it might make sense to have a separate "feature" for it), but I don't know a good way to check if require('util').TextEncoder and require('util').TextDecoder are available - so I'm just assuming here that if it's Node.js, it must be able to do require("util"). Do you think there might be a better way?

(and yes, we'll drop Node v10 and this particular if on line 29 will disappear)

@alexander-fenster alexander-fenster merged commit 2c8e56d into master Jul 12, 2021
@alexander-fenster alexander-fenster deleted the feature-detection branch July 12, 2021 17:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla: yes This human has signed the Contributor License Agreement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Unable to use gax in Jest with jsdom test environment
3 participants