Move node-fetch to separate package (#7009)

* move node-fetch to separate package

Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com>

* fix node-fetch package runtime error

Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com>

* fix test:unit nx dependency

Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com>

* fix test:unit nx dependency

Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com>

* Add prepare step for node-fetch

Signed-off-by: Sebastian Malton <sebastian@malton.name>

* Update lock

Signed-off-by: Sebastian Malton <sebastian@malton.name>

* Remove dead comment

Signed-off-by: Sebastian Malton <sebastian@malton.name>

* Remove unnecessary fetchModuleInjectable

Signed-off-by: Sebastian Malton <sebastian@malton.name>

Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com>
Signed-off-by: Sebastian Malton <sebastian@malton.name>
Co-authored-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
Jari KolehmainenandSebastian Malton authored and GitHub committed 2023-01-25 17:13:41 +02:00
1 parent 591d9f30f3
commit 7e8ae3fded
30 files changed
+1196 -3281

No files matched your search

@@ -3,7 +3,7 @@
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
import { getInjectable } from "@ogre-tools/injectable";
import type { RequestInit, Response } from "node-fetch";
import type { RequestInit, Response } from "@k8slens/node-fetch";
import type { AsyncResult } from "../utils/async-result";
import fetchInjectable from "./fetch.injectable";
@@ -22,7 +22,6 @@ const downloadBinaryInjectable = getInjectable({
let result: Response;
try {
// TODO: upgrade node-fetch once we switch to ESM
result = await fetch(url, opts as RequestInit);
} catch (error) {
return {
@@ -4,7 +4,7 @@
*/
import type { AsyncResult } from "../../utils/async-result";
import type { Fetch } from "../fetch.injectable";
import type { RequestInit, Response } from "node-fetch";
import type { RequestInit, Response } from "@k8slens/node-fetch";
export interface DownloadJsonOptions {
signal?: AbortSignal | null | undefined;
@@ -1,19 +0,0 @@
/**
* Copyright (c) OpenLens Authors. All rights reserved.
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
import { getInjectable } from "@ogre-tools/injectable";
import type * as FetchModule from "node-fetch";
const { NodeFetch } = require("../../../build/webpack/node-fetch.bundle") as { NodeFetch: typeof FetchModule };
/**
* NOTE: while using this module can cause side effects, this specific injectable is not marked as
* such since sometimes the request can be wholely within the perview of unit test
*/
const nodeFetchModuleInjectable = getInjectable({
id: "node-fetch-module",
instantiate: () => NodeFetch,
});
export default nodeFetchModuleInjectable;
@@ -3,18 +3,14 @@
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
import { getInjectable } from "@ogre-tools/injectable";
import type { RequestInit, Response } from "node-fetch";
import nodeFetchModuleInjectable from "./fetch-module.injectable";
import type { RequestInit, Response } from "@k8slens/node-fetch";
import fetch from "@k8slens/node-fetch";
export type Fetch = (url: string, init?: RequestInit) => Promise<Response>;
const fetchInjectable = getInjectable({
id: "fetch",
instantiate: (di): Fetch => {
const { default: fetch } = di.inject(nodeFetchModuleInjectable);
return (url, init) => fetch(url, init);
},
instantiate: () => fetch as Fetch,
causesSideEffects: true,
});
@@ -4,10 +4,10 @@
*/
import { getInjectable } from "@ogre-tools/injectable";
import { Agent } from "https";
import type { RequestInit, Response } from "node-fetch";
import type { RequestInit, Response } from "@k8slens/node-fetch";
import lensProxyPortInjectable from "../../main/lens-proxy/lens-proxy-port.injectable";
import lensProxyCertificateInjectable from "../certificate/lens-proxy-certificate.injectable";
import nodeFetchModuleInjectable from "./fetch-module.injectable";
import fetch from "@k8slens/node-fetch";
export type LensRequestInit = Omit<RequestInit, "agent">;
@@ -16,7 +16,6 @@ export type LensFetch = (pathnameAndQuery: string, init?: LensRequestInit) => Pr
const lensFetchInjectable = getInjectable({
id: "lens-fetch",
instantiate: (di): LensFetch => {
const { default: fetch } = di.inject(nodeFetchModuleInjectable);
const lensProxyPort = di.inject(lensProxyPortInjectable);
const lensProxyCertificate = di.inject(lensProxyCertificateInjectable);