chore: enable lint for resources folder
MODIFY
internal/resources/Resource.ts
internal/resources/Resource.ts
import {enhanceNodeInspectClass} from "@internal/node";
-import {ResourceOptions, ResourceTree, ResourcesContainer, ResourceTreeEntry, ResourceGetDetails} from "./types";
+import {
+ ResourceGetDetails,
+ ResourceOptions,
+ ResourceTree,
+ ResourceTreeEntry,
+ ResourcesContainer,
+} from "./types";
import {extractResource} from "./index";
import {isEnvVarSet} from "@internal/cli-environment";
import {createResourceContainer} from "./factories";
@@ -30,13 +36,18 @@ export default class Resource {
timeoutError = new Error(timeoutMessage);
}
- this.timeout = setTimeout(() => {
+ this.timeout = setTimeout(
+ () => {
if (timeoutError === undefined) {
- throw new Error(`${timeoutMessage}. Set the environment variable ROME_RESOURCE_STACKS=1 for a creation stack.`);
+ throw new Error(
+ `${timeoutMessage}. Set the environment variable ROME_RESOURCE_STACKS=1 for a creation stack.`,
+ );
} else {
throw timeoutError;
}
- }, 0);
+ },
+ 0,
+ );
}
}
@@ -63,7 +74,9 @@ export default class Resource {
return tree;
}
- public buildSubTree(seen: Map<Resource, ResourceTreeEntry> = new Map()): ResourceTreeEntry {
+ public buildSubTree(
+ seen: Map<Resource, ResourceTreeEntry> = new Map(),
+ ): ResourceTreeEntry {
const children: ResourceTree = new Map();
const entry: ResourceTreeEntry = {
details: this.options.getDetails(),
@@ -96,7 +109,10 @@ export default class Resource {
return this._releaseBlock(this, new Set());
}
- private _releaseBlock(root: Resource = this, seen: Set<Resource> = new Set()): Promise<void> {
+ private _releaseBlock(
+ root: Resource = this,
+ seen: Set<Resource> = new Set(),
+ ): Promise<void> {
if (this._releasing) {
return this._releasing;
}
@@ -129,7 +145,7 @@ export default class Resource {
// Release ourselves
const {release} = this.options;
if (release !== undefined) {
- promises.push(callRelease(this, release))
+ promises.push(callRelease(this, release));
}
try {
@@ -149,7 +165,6 @@ export default class Resource {
this._releasing = undefined;
}
-
}
public bind(rawResource: ResourcesContainer): Resource {
@@ -159,13 +174,19 @@ export default class Resource {
return resource;
}
- public createContainer(name: string, initialResources?: ResourcesContainer[]): Resource {
+ public createContainer(
+ name: string,
+ initialResources?: ResourcesContainer[],
+ ): Resource {
const resource = createResourceContainer(name, {initialResources});
this.add(resource);
return resource;
}
- public add(rawResource: ResourcesContainer, markAttachment: boolean = true): Resource {
+ public add(
+ rawResource: ResourcesContainer,
+ markAttachment: boolean = true,
+ ): Resource {
const resource = extractResource(rawResource);
if (resource.closed || this.closed || this.resources.has(resource)) {
@@ -187,14 +208,20 @@ export default class Resource {
}
}
-function callRelease(resource: Resource, callback: AsyncVoidCallback): Promise<void> {
+function callRelease(
+ resource: Resource,
+ callback: AsyncVoidCallback,
+): Promise<void> {
const selfPromise: Promise<void> = new Promise((resolve) => {
resolve(callback());
});
- const timeout = setTimeout(() => {
+ const timeout = setTimeout(
+ () => {
// TODO: Add timeout informative log
- }, 3000);
+ },
+ 3_000,
+ );
selfPromise.finally(() => {
clearTimeout(timeout);
@@ -204,6 +231,9 @@ function callRelease(resource: Resource, callback: AsyncVoidCallback): Promise<v
}
// @ts-ignore: Yes I really want to do this on an abstract class... bite me
-enhanceNodeInspectClass(Resource, (resc) => {
+enhanceNodeInspectClass(
+ Resource,
+ (resc) => {
return resc[Symbol.toStringTag];
-});
+ },
+);

MODIFY
internal/resources/factories.ts
internal/resources/factories.ts
import {AsyncVoidCallback} from "@internal/typescript-helpers";
import Resource from "./Resource";
-import {FactoryResourceOptions, FactoryResourceContainerOptions, TimerResourceDetails} from "./types";
+import {
+ FactoryResourceContainerOptions,
+ FactoryResourceOptions,
+ TimerResourceDetails,
+} from "./types";
import {processResourceRoot} from "./index";
import workerThreads = require("worker_threads");
import childProcess = require("child_process");
import net = require("net");
-export function createResourceFromCallback(name: string, callback: AsyncVoidCallback, opts?: FactoryResourceOptions): Resource {
+export function createResourceFromCallback(
+ name: string,
+ callback: AsyncVoidCallback,
+ opts?: FactoryResourceOptions,
+): Resource {
return new Resource({
...opts,
name,
@@ -19,9 +27,18 @@ export function createResourceFromCallback(name: string, callback: AsyncVoidCall
});
}
-type PrivateTimeout = number | (NodeJS.Timeout & {_repeat?: null | number, _idleTimeout?: number});
+type PrivateTimeout =
+ | number
+ | (NodeJS.Timeout & {
+ _repeat?: null | number;
+ _idleTimeout?: number;
+ });
-export function createResourceFromTimeout(name: string, timeout: PrivateTimeout, opts?: FactoryResourceOptions): Resource {
+export function createResourceFromTimeout(
+ name: string,
+ timeout: PrivateTimeout,
+ opts?: FactoryResourceOptions,
+): Resource {
let methodName = "setTimeout";
let kind: TimerResourceDetails["kind"] = "unknown";
let delay: undefined | number;
@@ -40,7 +57,10 @@ export function createResourceFromTimeout(name: string, timeout: PrivateTimeout,
}
}
- const wrappedName = delay === undefined ? `${methodName}<${name}>` : `${methodName}<${name}, ${delay}ms>`;
+ const wrappedName =
+ delay === undefined
+ ? `${methodName}<${name}>`
+ : `${methodName}<${name}, ${delay}ms>`;
return new Resource({
...opts,
@@ -81,9 +101,12 @@ export function createResourceFromChildProcess(
proc.kill();
},
});
- proc.on("close", () => {
+ proc.on(
+ "close",
+ () => {
resc.release();
- });
+ },
+ );
return resc;
}
@@ -103,13 +126,20 @@ export function createResourceFromWorkerThread(
await worker.terminate();
},
});
- worker.on("exit", () => {
+ worker.on(
+ "exit",
+ () => {
resc.release();
- });
+ },
+ );
return resc;
}
-export function createResourceFromSocket(socket: net.Socket, name: string = "net.Socket", opts?: FactoryResourceOptions): Resource {
+export function createResourceFromSocket(
+ socket: net.Socket,
+ name: string = "net.Socket",
+ opts?: FactoryResourceOptions,
+): Resource {
const resc = new Resource({
...opts,
name,
@@ -125,13 +155,20 @@ export function createResourceFromSocket(socket: net.Socket, name: string = "net
socket.end();
},
});
- socket.on("close", () => {
+ socket.on(
+ "close",
+ () => {
resc.release();
- });
+ },
+ );
return resc;
}
-export function createResourceFromServer(server: net.Server, name: string = "net.Server", opts?: FactoryResourceOptions): Resource {
+export function createResourceFromServer(
+ server: net.Server,
+ name: string = "net.Server",
+ opts?: FactoryResourceOptions,
+): Resource {
const resc = new Resource({
...opts,
name,
@@ -151,13 +188,20 @@ export function createResourceFromServer(server: net.Server, name: string = "net
});
},
});
- server.on("close", () => {
+ server.on(
+ "close",
+ () => {
resc.release();
- });
+ },
+ );
return resc;
}
-export function createResourceFromWebSocket(socket: WebSocket, name: string = "WebSocket", opts?: FactoryResourceOptions): Resource {
+export function createResourceFromWebSocket(
+ socket: WebSocket,
+ name: string = "WebSocket",
+ opts?: FactoryResourceOptions,
+): Resource {
const resc = new Resource({
...opts,
name,
@@ -169,13 +213,19 @@ export function createResourceFromWebSocket(socket: WebSocket, name: string = "W
socket.close();
},
});
- socket.addEventListener("close", () => {
+ socket.addEventListener(
+ "close",
+ () => {
resc.release();
- });
+ },
+ );
return resc;
}
-export function createResourceRoot(name: string, callback?: AsyncVoidCallback): Resource {
+export function createResourceRoot(
+ name: string,
+ callback?: AsyncVoidCallback,
+): Resource {
const resc = new Resource({
name,
getDetails: () => {
@@ -189,7 +239,10 @@ export function createResourceRoot(name: string, callback?: AsyncVoidCallback):
return resc;
}
-export function createResourceContainer(name: string, opts?: FactoryResourceContainerOptions): Resource {
+export function createResourceContainer(
+ name: string,
+ opts?: FactoryResourceContainerOptions,
+): Resource {
return new Resource({
...opts,
name,

MODIFY
internal/resources/index.ts
internal/resources/index.ts
@@ -15,7 +15,7 @@ export function extractResource(rawResource: ResourcesContainer): Resource {
if (prop instanceof Resource) {
return prop;
} else {
- throw new Error(`Resource not provided`);
+ throw new Error("Resource not provided");
}
}
}
@@ -36,7 +36,9 @@ export const processResourceRoot = new Resource({
},
});
-const processResourceRelease = processResourceRoot.release.bind(processResourceRoot);
+const processResourceRelease = processResourceRoot.release.bind(
+ processResourceRoot,
+);
// Only ran when the event loop has ran out of work, we cannot "catch" exits si we need use safeProcessExit calls
process.on("beforeExit", processResourceRelease);
@@ -45,14 +47,18 @@ process.on("SIGHUP", processResourceRelease);
process.on("SIGTERM", processResourceRelease);
// We explicitly do not attach this to processResourceRelease as those should always be attached during teardown
-export const processResourceListeners = createResourceFromCallback("ProcessListeners", () => {
+export const processResourceListeners = createResourceFromCallback(
+ "ProcessListeners",
+ () => {
process.removeListener("beforeExit", processResourceRelease);
process.removeListener("SIGINT", processResourceRelease);
process.removeListener("SIGHUP", processResourceRelease);
process.removeListener("SIGTERM", processResourceRelease);
-}, {
+ },
+ {
optional: true,
-});
+ },
+);
export async function safeProcessExit(code: number): Promise<void> {
process.exitCode = code;
@@ -66,10 +72,10 @@ export async function safeProcessExit(code: number): Promise<void> {
try {
await processResourceRoot.releaseBlock();
} catch (err) {
- console.error(`safeProcessExit: Release failure`);
+ console.error("safeProcessExit: Release failure");
console.error(err.stack);
}
- console.error(`safeProcessExit: Process not exited by resource release`);
+ console.error("safeProcessExit: Process not exited by resource release");
process.exit(2);
}

MODIFY
internal/resources/types.ts
internal/resources/types.ts
@@ -11,7 +11,10 @@ export type FactoryResourceContainerOptions = FactoryResourceOptions & {
finalize?: AsyncVoidCallback;
};
-export type ResourceOptions = RequiredProps<FactoryResourceContainerOptions, "name"> & {
+export type ResourceOptions = RequiredProps<
+ FactoryResourceContainerOptions,
+ "name"
+> & {
getDetails: ResourceGetDetails;
release?: AsyncVoidCallback;
};
@@ -19,13 +22,15 @@ export type ResourceOptions = RequiredProps<FactoryResourceContainerOptions, "na
export type ResourceGetDetails = () => ResourceDetails;
// TODO: Get rid of this probably
-export type ResourcesContainer = Resource | {
+export type ResourcesContainer =
+ | Resource
+ | {
resources: undefined | Resource;
};
export type ResourceTreeEntry = {
details: ResourceDetails;
- children: ResourceTree,
+ children: ResourceTree;
};
export type ResourceTree = Map<Resource, ResourceTreeEntry>;
@@ -56,7 +61,7 @@ export type SocketResourceDetails = {
export type WebSocketResourceDetails = {
type: "websocket";
url: string;
-}
+};
export type ServerResourceDetails = {
type: "server";

MODIFY
package.json
package.json
"coverage",
"node_modules",
"core/static",
- "resources",
"test-fixtures",
"vendor",
"type-libs",
"lib/modules.js",
- "prelude.ts",
"internal/web-ui",
"out",
"vscode/node_modules"

chore: enable lint for resources folder (#1554)