Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(deps): remove cross-fetch dependency #521

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
1 change: 0 additions & 1 deletion packages/fbjs-scripts/third-party-module-map.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
{
"cross-fetch": "cross-fetch",
"fbjs-css-vars": "fbjs-css-vars",
"isomorphic-fetch": "isomorphic-fetch",
"object-assign": "object-assign",
Expand Down
1 change: 0 additions & 1 deletion packages/fbjs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@
]
},
"dependencies": {
"cross-fetch": "^3.1.5",
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Side-note, I am not sure why this was included as a dependency, it seems like this was only ever used during testing.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fbjs was created to support FB projects, goal being to provide the same core/shared libraries we had internally. fetch was one of those things but had too much internal-specific code so it was a "forked" implementation here. It relied on cross-fetch and re-exported it (as you saw) but was not otherwise used directly.

"fbjs-css-vars": "^1.0.0",
"loose-envify": "^1.0.0",
"object-assign": "^4.1.0",
Expand Down
18 changes: 2 additions & 16 deletions packages/fbjs/src/__forks__/__tests__/fetch-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@
'use strict';

jest.unmock('fetch');
jest.mock('cross-fetch');

const fetchImpl = require('cross-fetch');

describe('fetch', function() {
afterEach(() => {
Expand All @@ -23,23 +20,12 @@ describe('fetch', function() {
it('works with global fetch', () => {
const fetchMock = jest.fn();

global.fetch = fetchMock;
globalThis.fetch = fetchMock;
const fetch = require('fetch');
fetch();

expect(fetchMock).toHaveBeenCalled();
expect(fetchImpl).not.toHaveBeenCalled();

delete global.fetch;
});

it('uses ponyfill without global fetch', () => {
// If node ever gets a global fetch, we'll start failing this case.
expect(global.fetch).toBeUndefined();

const fetch = require('fetch');
fetch();

expect(fetchImpl).toHaveBeenCalled();
delete globalThis.fetch;
});
});
9 changes: 1 addition & 8 deletions packages/fbjs/src/__forks__/fetch.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,4 @@

'use strict';

// This hopefully supports the React Native case, which is already bringing along
// its own fetch polyfill. That should exist on `global`. If that doesn't exist
// then we'll try to ponyfill, which might not work correctly in all environments.
if (global.fetch) {
module.exports = global.fetch.bind(global);
} else {
module.exports = require('cross-fetch');
}
module.exports = globalThis.fetch.bind(globalThis);
32 changes: 0 additions & 32 deletions packages/fbjs/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1538,13 +1538,6 @@ [email protected], core-util-is@~1.0.0:
resolved "https://registry.yarnpkg.com/core-util-is/-/core-util-is-1.0.2.tgz#b5fd54220aa2bc5ab57aab7140c940754503c1a7"
integrity sha1-tf1UIgqivFq1eqtxQMlAdUUDwac=

cross-fetch@^3.1.5:
version "3.1.5"
resolved "https://registry.yarnpkg.com/cross-fetch/-/cross-fetch-3.1.5.tgz#e1389f44d9e7ba767907f7af8454787952ab534f"
integrity sha512-lvb1SBsI0Z7GDwmuid+mU3kWVBwTVUbe7S0H52yaaAdQOXq2YktTCZdlAcNKFzE6QtRz0snpw9bNiPeOIkkQvw==
dependencies:
node-fetch "2.6.7"

cross-spawn@^5.0.1, cross-spawn@^5.1.0:
version "5.1.0"
resolved "https://registry.yarnpkg.com/cross-spawn/-/cross-spawn-5.1.0.tgz#e8bd0efee58fcff6f8f94510a0a554bbfa235449"
Expand Down Expand Up @@ -3876,13 +3869,6 @@ next-tick@~1.0.0:
resolved "https://registry.yarnpkg.com/next-tick/-/next-tick-1.0.0.tgz#ca86d1fe8828169b0120208e3dc8424b9db8342c"
integrity sha1-yobR/ogoFpsBICCOPchCS524NCw=

[email protected]:
version "2.6.7"
resolved "https://registry.yarnpkg.com/node-fetch/-/node-fetch-2.6.7.tgz#24de9fba827e3b4ae44dc8b20256a379160052ad"
integrity sha512-ZjMPFEfVx5j+y2yF35Kzx5sF7kDzxuDj6ziH4FFbOp87zKDZNx8yExJIb05OGF4Nlt9IHFIMBkRl41VdvcNdbQ==
dependencies:
whatwg-url "^5.0.0"

node-int64@^0.4.0:
version "0.4.0"
resolved "https://registry.yarnpkg.com/node-int64/-/node-int64-0.4.0.tgz#87a9065cdb355d3182d8f94ce11188b825c68a3b"
Expand Down Expand Up @@ -5232,11 +5218,6 @@ tr46@^1.0.1:
dependencies:
punycode "^2.1.0"

tr46@~0.0.3:
version "0.0.3"
resolved "https://registry.yarnpkg.com/tr46/-/tr46-0.0.3.tgz#8184fd347dac9cdc185992f3a6622e14b9d9ab6a"
integrity sha1-gYT9NH2snNwYWZLzpmIuFLnZq2o=

trim-right@^1.0.1:
version "1.0.1"
resolved "https://registry.yarnpkg.com/trim-right/-/trim-right-1.0.1.tgz#cb2e1203067e0c8de1f614094b9fe45704ea6003"
Expand Down Expand Up @@ -5476,11 +5457,6 @@ watch@~0.18.0:
exec-sh "^0.2.0"
minimist "^1.2.0"

webidl-conversions@^3.0.0:
version "3.0.1"
resolved "https://registry.yarnpkg.com/webidl-conversions/-/webidl-conversions-3.0.1.tgz#24534275e2a7bc6be7bc86611cc16ae0a5654871"
integrity sha1-JFNCdeKnvGvnvIZhHMFq4KVlSHE=

webidl-conversions@^4.0.2:
version "4.0.2"
resolved "https://registry.yarnpkg.com/webidl-conversions/-/webidl-conversions-4.0.2.tgz#a855980b1f0b6b359ba1d5d9fb39ae941faa63ad"
Expand All @@ -5498,14 +5474,6 @@ whatwg-mimetype@^2.1.0:
resolved "https://registry.yarnpkg.com/whatwg-mimetype/-/whatwg-mimetype-2.2.0.tgz#a3d58ef10b76009b042d03e25591ece89b88d171"
integrity sha512-5YSO1nMd5D1hY3WzAQV3PzZL83W3YeyR1yW9PcH26Weh1t+Vzh9B6XkDh7aXm83HBZ4nSMvkjvN2H2ySWIvBgw==

whatwg-url@^5.0.0:
version "5.0.0"
resolved "https://registry.yarnpkg.com/whatwg-url/-/whatwg-url-5.0.0.tgz#966454e8765462e37644d3626f6742ce8b70965d"
integrity sha1-lmRU6HZUYuN2RNNib2dCzotwll0=
dependencies:
tr46 "~0.0.3"
webidl-conversions "^3.0.0"

whatwg-url@^6.4.1:
version "6.5.0"
resolved "https://registry.yarnpkg.com/whatwg-url/-/whatwg-url-6.5.0.tgz#f2df02bff176fd65070df74ad5ccbb5a199965a8"
Expand Down