Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
fix: update node-fetch to 3.x
node-fetch is now ESM module only, thus this will be a breaking change
and will requires at least Node.js 12.20.0.

As suggested[1] by `node-fetch`, async import() function is used to load
`node-fetch` asynchronously.

BREAKING CHANGE: requires at least node 12.20.0

[1]: https://github.com/node-fetch/node-fetch#commonjs
  • Loading branch information
RishikeshDarandale committed Feb 3, 2022
commit 385868d9f7d78f4b95e8ee4659c191df8d112f68
12,639 changes: 7,196 additions & 5,443 deletions package-lock.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
"cross-var": "^1.1.0",
"eslint": "^3.13.1",
"eslint-config-developit": "^1.1.1",
"jest": "^23.6.0",
"jest": "^27.4.7",
"microbundle": "^0.10.1"
}
}
3 changes: 2 additions & 1 deletion packages/isomorphic-unfetch/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
function r(m){return m && m.default || m;}
module.exports = global.fetch = global.fetch || (
typeof process=='undefined' ? r(require('unfetch')) : (function(url, opts) {
return r(require('node-fetch'))(String(url).replace(/^\/\//g,'https://'), opts);
const fetch = (...args) => import('node-fetch').then(({default: fetch}) => fetch(...args));
return r(fetch)(String(url).replace(/^\/\//g,'https://'), opts);
})
);
50 changes: 46 additions & 4 deletions packages/isomorphic-unfetch/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/isomorphic-unfetch/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"main": "index.js",
"types": "index.d.ts",
"dependencies": {
"node-fetch": "^2.6.1",
"node-fetch": "^3.2.0",
"unfetch": "^4.2.0"
}
}
2 changes: 2 additions & 0 deletions packages/isomorphic-unfetch/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ Switches between [unfetch](https://github.com/developit/unfetch) & [node-fetch](

This project uses [node](http://nodejs.org) and [npm](https://npmjs.com). Go check them out if you don't have them locally installed.

> Note: This module uses node-fetch 3.x, which is ESM module and requires at least node 12.20.0.

```sh
$ npm i isomorphic-unfetch
```
Expand Down
10 changes: 9 additions & 1 deletion test/isomorphic.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,15 @@ describe('isomorphic-unfetch', () => {
sandbox.global.process = sandbox.process;
sandbox.module = { exports: sandbox.exports };
let filename = require.resolve('../packages/isomorphic-unfetch');
vm.runInNewContext(fs.readFileSync(filename), sandbox, filename);
vm.runInNewContext(fs.readFileSync(filename), sandbox, {
filename,
importModuleDynamically: () => {
const module = new vm.SyntheticModule(['node-fetch'], function() {
this.setExport('default', 'I AM NODE-FETCH');
});
return module;
}
});

expect(sandbox.module.exports('/')).toBe(modules['node-fetch']('/'));
});
Expand Down