mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Upgrade to electron@^19 (#5369)
* Upgrade to use electron 19.0.4 - Update documentation - Updated disturl in .yarnrc to fix build issue - Remove use of abort-controller package Signed-off-by: Sebastian Malton <sebastian@malton.name> * Remove support for webview tags Signed-off-by: Sebastian Malton <sebastian@malton.name> Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
1 parent
edacf3bec6
commit
6d37019089
18 files changed
+84
-134
No files matched your search
@@ -11,9 +11,8 @@ import { watch } from "chokidar";
|
||||
import type { Stats } from "fs";
|
||||
import fs from "fs";
|
||||
import path from "path";
|
||||
import type stream from "stream";
|
||||
import type { Disposer } from "../../../common/utils";
|
||||
import { bytesToUnits, getOrInsertWith, iter, noop } from "../../../common/utils";
|
||||
import { disposer, bytesToUnits, getOrInsertWith, iter, noop } from "../../../common/utils";
|
||||
import logger from "../../logger";
|
||||
import type { KubeConfig } from "@kubernetes/client-node";
|
||||
import { loadConfigFromString, splitConfig } from "../../../common/kube-helpers";
|
||||
@@ -265,47 +264,35 @@ const diffChangedConfigFor = (dependencies: ComputeDiffDependencies) => ({ fileP
|
||||
return noop;
|
||||
}
|
||||
|
||||
// TODO: replace with an AbortController with fs.readFile when we upgrade to Node 16 (after it comes out)
|
||||
const fileReader = fs.createReadStream(filePath, {
|
||||
mode: fs.constants.O_RDONLY,
|
||||
const controller = new AbortController();
|
||||
const fileContentsP = fs.promises.readFile(filePath, {
|
||||
signal: controller.signal,
|
||||
});
|
||||
const readStream: stream.Readable = fileReader;
|
||||
const decoder = new TextDecoder("utf-8", { fatal: true });
|
||||
let fileString = "";
|
||||
let closed = false;
|
||||
const cleanup = disposer(
|
||||
() => controller.abort(),
|
||||
);
|
||||
|
||||
const cleanup = () => {
|
||||
closed = true;
|
||||
fileReader.close(); // This may not close the stream.
|
||||
// Artificially marking end-of-stream, as if the underlying resource had
|
||||
// indicated end-of-file by itself, allows the stream to close.
|
||||
// This does not cancel pending read operations, and if there is such an
|
||||
// operation, the process may still not be able to exit successfully
|
||||
// until it finishes.
|
||||
fileReader.push(null);
|
||||
fileReader.read(0);
|
||||
readStream.removeAllListeners();
|
||||
};
|
||||
fileContentsP
|
||||
.then((fileData) => {
|
||||
const decoder = new TextDecoder("utf-8", { fatal: true });
|
||||
|
||||
readStream
|
||||
.on("data", (chunk: Buffer) => {
|
||||
try {
|
||||
fileString += decoder.decode(chunk, { stream: true });
|
||||
const fileString = decoder.decode(fileData);
|
||||
|
||||
computeDiff(dependencies)(fileString, source, filePath);
|
||||
} catch (error) {
|
||||
logger.warn(`${logPrefix} skipping ${filePath}: ${error}`);
|
||||
source.clear();
|
||||
cleanup();
|
||||
}
|
||||
})
|
||||
.on("close", () => cleanup())
|
||||
.on("error", error => {
|
||||
cleanup();
|
||||
logger.warn(`${logPrefix} failed to read file: ${error}`, { filePath });
|
||||
})
|
||||
.on("end", () => {
|
||||
if (!closed) {
|
||||
computeDiff(dependencies)(fileString, source, filePath);
|
||||
.catch(error => {
|
||||
if (controller.signal.aborted) {
|
||||
return;
|
||||
}
|
||||
|
||||
logger.warn(`${logPrefix} failed to read file: ${error}`, { filePath });
|
||||
cleanup();
|
||||
});
|
||||
|
||||
return cleanup;
|
||||
|
||||
Reference in new issue
Block a user