mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Fix bad imports of node-fetch
Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
parent
e8bc887f0b
commit
58cbf5f300
17
.eslintrc.js
17
.eslintrc.js
@ -296,5 +296,22 @@ module.exports = {
|
|||||||
}],
|
}],
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
files: [
|
||||||
|
"src/**/*.ts",
|
||||||
|
"src/**/*.tsx",
|
||||||
|
],
|
||||||
|
rules: {
|
||||||
|
"@typescript-eslint/no-restricted-imports": ["error", {
|
||||||
|
"paths": [
|
||||||
|
{
|
||||||
|
"name": "node-fetch",
|
||||||
|
"allowTypeImports": true,
|
||||||
|
"message": "node-fetch@v3 is an ESM package and there cannot be directly imported.",
|
||||||
|
},
|
||||||
|
],
|
||||||
|
}],
|
||||||
|
},
|
||||||
|
},
|
||||||
],
|
],
|
||||||
};
|
};
|
||||||
|
|||||||
@ -33,7 +33,7 @@ const canvasPrebuildUrl = canvasPrebuiltUrlBuilder(canvasVersion, nodeModuleVers
|
|||||||
|
|
||||||
const canvasPrebuilt = await fetch(canvasPrebuildUrl);
|
const canvasPrebuilt = await fetch(canvasPrebuildUrl);
|
||||||
|
|
||||||
if (canvasPrebuilt.status !== 200) {
|
if (canvasPrebuilt.status !== 200 || !canvasPrebuilt.body) {
|
||||||
throw new Error(`Failed to download prebuilt from ${canvasPrebuildUrl}: ${canvasPrebuilt.statusText}`);
|
throw new Error(`Failed to download prebuilt from ${canvasPrebuildUrl}: ${canvasPrebuilt.statusText}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -7,8 +7,13 @@ import type { Cluster } from "../common/cluster/cluster";
|
|||||||
import { getInjectable } from "@ogre-tools/injectable";
|
import { getInjectable } from "@ogre-tools/injectable";
|
||||||
import type { RequestInit } from "node-fetch";
|
import type { RequestInit } from "node-fetch";
|
||||||
import lensFetchInjectable from "../common/fetch/lens-fetch.injectable";
|
import lensFetchInjectable from "../common/fetch/lens-fetch.injectable";
|
||||||
|
import { withTimeout } from "../common/fetch/timeout-controller";
|
||||||
|
|
||||||
export type K8sRequest = (cluster: Cluster, path: string, options?: RequestInit) => Promise<unknown>;
|
export interface K8sRequestInit extends Omit<RequestInit, "signal"> {
|
||||||
|
timeout?: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
export type K8sRequest = (cluster: Cluster, path: string, init?: K8sRequestInit) => Promise<unknown>;
|
||||||
|
|
||||||
const k8sRequestInjectable = getInjectable({
|
const k8sRequestInjectable = getInjectable({
|
||||||
id: "k8s-request",
|
id: "k8s-request",
|
||||||
@ -16,7 +21,14 @@ const k8sRequestInjectable = getInjectable({
|
|||||||
instantiate: (di): K8sRequest => {
|
instantiate: (di): K8sRequest => {
|
||||||
const lensFetch = di.inject(lensFetchInjectable);
|
const lensFetch = di.inject(lensFetchInjectable);
|
||||||
|
|
||||||
return async (cluster, path, init) => lensFetch(`/${cluster.id}${apiKubePrefix}${path}`, init);
|
return async (cluster, path, { timeout = 30_000, ...init } = {}) => {
|
||||||
|
const controller = withTimeout(timeout);
|
||||||
|
|
||||||
|
return lensFetch(`/${cluster.id}${apiKubePrefix}${path}`, {
|
||||||
|
...init,
|
||||||
|
signal: controller.signal,
|
||||||
|
});
|
||||||
|
};
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user