Closed charlag closed 4 years ago
I'm not sure if it's solves the original issue so maybe it's too early for review, sorry
I tried this alternatively:
var inspect
if (hasProcess) {
import("util").then(function (util) {
inspect = util.inspect
})
}
in the beginning of the file and it seems to work. It's not bulletproof. What do you think?
Please confirm this also works with Rollup and Webpack, as some users do use this in the browser.
My second proposal in the comment works with Rollup, I need to check more browsers.
About conditional exports: Rollup's plugin does not understand them yet but you can tell it to look into the module
field of package.json and then it works.
I think that dynamic import as in the comment is a better solution to be honest.
@charlag If you want to take a shot at that comment, feel free to. I'd definitely be open to considering it.
closing in favor of #27
Description
This commit changes how exports are defined to handle different usage scenarios. Now build systems can detect what is required and node will pick appropriate version.
Motivation and Context
There are three different scenarios which require different imports: node with commonjs, node with es modules and browser (assumed to have es modules or be transpiled). Previously ospec would break if executed in a module context, build systems are also not able to fix that because require is used dynamically. issue #25
How Has This Been Tested?
I ran test-api with node 12. I was not able to run test-cli before or after the changes
Types of changes
Checklist: