skypackjs / skypack-cdn

An issue tracker for the CDN
107 stars 5 forks source link

How to support NodeJS when there are NodeJS specific files? #252

Open jeremymeng opened 2 years ago

jeremymeng commented 2 years ago

We have a package that use "browser" section to support both NodeJs and browsers. Mapped files will be used for browsers by bundlers.

https://github.com/Azure/azure-sdk-for-js/blob/%40azure/core-http_2.2.2/sdk/core/core-http/package.json#L49-L58

  "browser": {
    "./dist-esm/src/policies/msRestUserAgentPolicy.js": "./dist-esm/src/policies/msRestUserAgentPolicy.browser.js",
    "./dist-esm/src/policies/disableResponseDecompressionPolicy.js": "./dist-esm/src/policies/disableResponseDecompressionPolicy.browser.js",
    "./dist-esm/src/policies/proxyPolicy.js": "./dist-esm/src/policies/proxyPolicy.browser.js",
    "./dist-esm/src/util/base64.js": "./dist-esm/src/util/base64.browser.js",
    "./dist-esm/src/util/xml.js": "./dist-esm/src/util/xml.browser.js",
    "./dist-esm/src/defaultHttpClient.js": "./dist-esm/src/defaultHttpClient.browser.js",
    "./dist-esm/src/util/inspect.js": "./dist-esm/src/util/inspect.browser.js",
    "./dist-esm/src/util/url.js": "./dist-esm/src/util/url.browser.js"
  },

I believe skypack would only serves the file with the browser code, which doesn't work in NodeJS. What can we do to support NodeJS?

For example, the code at https://cdn.skypack.dev//-/@azure/core-http@v2.2.2-tk52XlrOqRIApLnT9rAE/dist=es2019,mode=imports/optimized/@azure/core-http.js

would only have xml code from ./dist-esm/src/util/xml.browser.js, not the NodeJS one from ./dist-esm/src/util/xml.js