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.
Injecting the path into the "code" was causing the backslashes to be
interpreted as escape characters instead of path separators. I could
have escaped them, but this approach is more similar to what Webpack
does with `arraybuffer-loader` and (IMO) easier to read.
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.
This workaround was making the tests pass even when `fetch` was
undefined. That made sense if you assume that the only Node-based
clients of `scratch-storage` are its own tests, but it doesn't help (for
example) Node-based tests in `scratch-vm`. Since we now ensure that
`fetch` is polyfilled for Node, this workaround is no longer necessary.
When calling `load`, you may now explicitly state a data format / file extension. If you don't
specify one, the default for that asset type will be used.
Resolves#7
Actually, to the prototype. This allows consumers of this module to
access `Asset` and `AssetType` without having to `require` the storage
module itself.
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.