Breaking flag is because it may have some differences in the way the library is exported -
`module.exports = ` vs `module.exports.default = `. That would depend on the Webpack config,
so it should continue working, but just to be safe.
Previously, we had Webpack's ProvidePlugin injecting `node-fetch` as a
polyfill into Node builds, and web builds just relied on the `fetch`
built into the browser (if it's there).
Now, we use `cross-fetch` everywhere, and as a ponyfill instead of a
polyfill. This broke the unit tests in `fetch-tool.js` because they were
overriding `global.fetch` to mock `node-fetch`. Now, those tests use
`tap.mock` to mock `cross-fetch`. Of course, `tap.mock` didn't exist in
the old version of `node-tap`, so I also upgraded that.
Downstream webpack will need any dependencies src/ depends on so it can
successfully build. Also if multiple packages being built into a larger
script share a common dependency version range, they can share the
dependency instead of duplicating it. This will save built file size,
execution time, and memory.
Using UMD for the web build conflicts with the old `index-web.js` file,
since they both try to do roughly the same thing. This change should
have been part of the recent switch to UMD output for `dist/web`.
Using UMD makes the build output more flexible and adds a very small
amount of overhead.
The "browser" field is one of the key features we've been missing and
should solve many of our build frustrations. See here for details on the
"browser" field in `project.json`:
https://github.com/defunctzombie/package-browser-field-spec
Changes include:
- Use `bin-loader` instead of `arraybuffer-loader` since the latter is
only compatible with browsers, not with Node itself.
- Use `got` instead of `xhr` since `xhr` only works in browsers and
`got` is nicer anyway.
- Add `json-loader` to Webpack config since `got` requires it.
- Use lower-case values in `DataFormat` to match canonical file names.
- Update `ScratchStorage.addWebSource` to match `WebHelper`'s new API.
- Fix an error in the web helper which was causing an infinite loop on
error.