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

split URL to node/browser versions and add brower mapping to package.json #1

Merged
merged 1 commit into from
May 17, 2021

Conversation

chradek
Copy link

@chradek chradek commented May 17, 2021

This PR shows how get around some of the bundling issues. Since browsers don't have access to the node.js modules, what we end up doing to keep bundlers happy is create runtime-specific versions of the APIs we need.

This looks at URL specifically. We're lucky in that both node.js and browsers support a URL parser with the same API, but in browsers we access the API via a global. So what I've done is created utils/url.ts and utils/url.browser.ts that both just re-export the URL object. Then in package.json, I added a mapping in the browser field so bundlers know that if they are targetting a browser, they should pull in the browser version of url instead of the node.js version.

You may need to do this for other APIs too, but this at least gets the karma tests starting to run versus just throwing a TypeError.

Copy link
Owner

@YoDaMa YoDaMa left a comment

Choose a reason for hiding this comment

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

lgtm

@YoDaMa YoDaMa merged commit 54a6be1 into YoDaMa:device-models-tools May 17, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants