Skip to content

Commit

Permalink
chore(deps): upgrade dev dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
zenflow committed May 7, 2023
1 parent c62d73d commit a396380
Show file tree
Hide file tree
Showing 30 changed files with 1,994 additions and 3,710 deletions.
3 changes: 2 additions & 1 deletion .babelrc
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
"node": "10"
}
}
]
],
"@babel/preset-typescript"
],
"plugins": [
["macros"]
Expand Down
2 changes: 2 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
dist/
node_modules/
15 changes: 0 additions & 15 deletions .eslintrc.js

This file was deleted.

5 changes: 5 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"extends": [
"zenflow"
]
}
8 changes: 3 additions & 5 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
/** @type {import('ts-jest').JestConfigWithTsJest} */
module.exports = {
globals: {
"ts-jest": {
babelConfig: ".babelrc",
},
},
preset: "ts-jest",
testEnvironment: "node",
};
35 changes: 21 additions & 14 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,44 +25,52 @@
"main": "dist/index.js",
"typings": "dist/index.d.ts",
"files": [
"dist/index.js",
"dist/**/*.js",
"dist/**/*.d.ts",
"src"
],
"scripts": {
"lint": "tsdx lint src test",
"lint": "eslint . --ext .js,.ts,.jsx,.tsx",
"lint-fix": "yarn lint --fix",
"_tsdx_build": "tsdx --target node --format cjs --entry src/index.ts",
"build": "yarn _tsdx_build build",
"build-watch": "yarn _tsdx_build watch",
"_tsdx_test": "tsdx test --runInBand",
"test-only": "yarn _tsdx_test --ci",
"test-watch": "yarn _tsdx_test --watch",
"test": "yarn lint && yarn build && yarn test-only"
"clean": "shx rm -rf dist",
"build:types": "tsc",
"build:js": "babel src --source-maps true --extensions .ts --out-dir dist",
"build": "yarn build:types && yarn build:js",
"test-only": "jest --ci --runInBand",
"test": "yarn lint && yarn clean && yarn build && yarn test-only"
},
"dependencies": {
"cloneable-readable": "^3.0.0",
"merge-stream": "^2.0.0",
"npm-run-path": "^4.0.1",
"split2": "^4.2.0",
"ts-interface-checker": "^1.0.2",
"which": "^3.0.0"
"which": "^3.0.1"
},
"optionalDependencies": {
"generate-ctrl-c-event": "^2.0.1"
},
"devDependencies": {
"@babel/cli": "^7.21.5",
"@babel/core": "^7.21.8",
"@babel/preset-env": "^7.21.5",
"@babel/preset-typescript": "^7.21.5",
"@types/cloneable-readable": "^2.0.0",
"@types/generate-ctrl-c-event": "^2.0.1",
"@types/jest": "^29.5.1",
"@types/merge-stream": "^1.1.2",
"@types/node-fetch": "^2.6.3",
"@types/split2": "^4.2.0",
"@types/which": "^3.0.0",
"babel-plugin-macros": "^3.1.0",
"eslint": "^8.40.0",
"eslint-config-zenflow": "^4.0.0",
"jest": "^29.5.0",
"node-fetch": "^2.6.9",
"shx": "0.3.4",
"ts-interface-builder": "^0.3.3",
"tsdx": "^0.14.1",
"typescript": "^3.9.10"
"ts-jest": "^29.1.0",
"typescript": "^4.9.5"
},
"license": "MIT",
"author": {
Expand All @@ -78,7 +86,6 @@
},
"homepage": "https://github.com/zenflow/composite-service#readme",
"prettier": {
"printWidth": 100,
"trailingComma": "all"
"printWidth": 100
}
}
24 changes: 12 additions & 12 deletions src/CompositeService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,33 +31,33 @@ export class CompositeService {
process.on("SIGTERM", () => this.handleShutdownSignal(143, "SIGTERM"));
if (process.stdin.isTTY) {
process.stdin.setRawMode(true);
process.stdin.on("data", buffer => {
process.stdin.on("data", (buffer) => {
if (buffer.toString("utf8") === "\u0003") {
this.handleShutdownSignal(130, "ctrl+c");
}
});
}

this.services = Object.entries(this.config.services).map(
([id, config]) => new Service(id, config, this.logger, this.handleFatalError.bind(this)),
([id, config]) => new Service(id, config, this.logger, this.handleFatalError.bind(this))
);
this.serviceMap = new Map(this.services.map(service => [service.id, service]));
this.serviceMap = new Map(this.services.map((service) => [service.id, service]));

outputStream.add(
this.services.map(({ output, id }) =>
output.pipe(mapStreamLines(line => `${id} | ${line}\n`)),
),
output.pipe(mapStreamLines((line) => `${id} | ${line}\n`))
)
);

this.logger.log("debug", "Starting composite service...");
Promise.all(this.services.map(service => this.startService(service))).then(() =>
this.logger.log("debug", "Started composite service"),
Promise.all(this.services.map((service) => this.startService(service))).then(() =>
this.logger.log("debug", "Started composite service")
);
}

private async startService(service: Service) {
const dependencies = service.config.dependencies.map(id => this.serviceMap.get(id)!);
await Promise.all(dependencies.map(service => this.startService(service)));
const dependencies = service.config.dependencies.map((id) => this.serviceMap.get(id)!);
await Promise.all(dependencies.map((service) => this.startService(service)));
if (this.stopping) {
await never();
}
Expand Down Expand Up @@ -90,7 +90,7 @@ export class CompositeService {
.generateCtrlCAsync()
.catch((error: Error) => this.logger.log("error", String(error)));
}
Promise.all(this.services.map(service => this.stopService(service)))
Promise.all(this.services.map((service) => this.stopService(service)))
.then(() => this.logger.log("debug", "Stopped composite service"))
// Wait one micro tick for output to flush
.then(() => process.exit(exitCode));
Expand All @@ -99,9 +99,9 @@ export class CompositeService {
private async stopService(service: Service) {
if (this.config.gracefulShutdown) {
const dependents = this.services.filter(({ config }) =>
config.dependencies.includes(service.id),
config.dependencies.includes(service.id)
);
await Promise.all(dependents.map(service => this.stopService(service)));
await Promise.all(dependents.map((service) => this.stopService(service)));
}
await service.stop(this.config.windowsCtrlCShutdown);
}
Expand Down
8 changes: 4 additions & 4 deletions src/Service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,15 @@ export class Service {
id: string,
config: NormalizedServiceConfig,
logger: Logger,
handleFatalError: (message: string) => void,
handleFatalError: (message: string) => void
) {
this.id = id;
this.config = config;
this.logger = logger;
this.handleFatalError = handleFatalError;
}

private die(context: string, error: Error) {
private die(context: string, error: unknown) {
this.handleFatalError(`${context}: ${inspect(error)}`);
return never();
}
Expand All @@ -62,7 +62,7 @@ export class Service {
const ctx = createReadyContext(this.outputClone);
this.ready = promiseTry(() => this.config.ready(ctx))
.finally(() => this.outputClone.destroy())
.catch(error => this.die(`In \`service.${this.id}.ready\``, error));
.catch((error) => this.die(`In \`service.${this.id}.ready\``, error));
}

private async startProcess() {
Expand Down Expand Up @@ -141,7 +141,7 @@ function isResolved(promise: Promise<any>): Promise<boolean> {
return Promise.race([
promise.then(
() => true,
() => false,
() => false
),
Promise.resolve().then(() => false),
]);
Expand Down
14 changes: 7 additions & 7 deletions src/ServiceProcess.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export class ServiceProcess {
serviceId: string,
serviceConfig: NormalizedServiceConfig,
logger: Logger,
onCrash: () => void,
onCrash: () => void
) {
this.serviceId = serviceId;
this.serviceConfig = serviceConfig;
Expand All @@ -38,12 +38,12 @@ export class ServiceProcess {
this.output = getProcessOutput(this.process);
if (this.serviceConfig.logTailLength > 0) {
this.output = this.output.pipe(
tapStreamLines(line => {
tapStreamLines((line) => {
this.logTail.push(line);
if (this.logTail.length > this.serviceConfig.logTailLength) {
this.logTail.shift();
}
}),
})
);
}
this.ended = once(this.output, "end").then(() => {
Expand Down Expand Up @@ -89,9 +89,9 @@ export class ServiceProcess {
}

function getProcessOutput(proc: ChildProcessWithoutNullStreams) {
return (mergeStream(
return mergeStream(
[proc.stdout, proc.stderr]
.map(stream => stream.setEncoding("utf8"))
.map(stream => pipeline(stream, splitStream(), filterBlankLastLine(""), () => {})),
) as unknown) as Readable;
.map((stream) => stream.setEncoding("utf8"))
.map((stream) => pipeline(stream, splitStream(), filterBlankLastLine(""), () => {}))
) as unknown as Readable;
}
8 changes: 4 additions & 4 deletions src/createReadyContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ export function createReadyContext(output: stream.Readable): ReadyContext {
return {
onceTcpPortUsed,
onceHttpOk,
onceOutputLineIs: line => onceOutputLine(output, l => l === line),
onceOutputLineIncludes: text => onceOutputLine(output, l => l.includes(text)),
onceOutputLine: test => onceOutputLine(output, test),
onceDelay: milliseconds => delay(milliseconds),
onceOutputLineIs: (line) => onceOutputLine(output, (l) => l === line),
onceOutputLineIncludes: (text) => onceOutputLine(output, (l) => l.includes(text)),
onceOutputLine: (test) => onceOutputLine(output, test),
onceDelay: (milliseconds) => delay(milliseconds),
};
}
10 changes: 5 additions & 5 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
export { startCompositeService } from "./startCompositeService";

export { CompositeServiceConfig } from "./interfaces/CompositeServiceConfig";
export { ServiceConfig } from "./interfaces/ServiceConfig";
export { ReadyContext } from "./interfaces/ReadyContext";
export { OnCrashContext } from "./interfaces/OnCrashContext";
export { ServiceCrash } from "./interfaces/ServiceCrash";
export type { CompositeServiceConfig } from "./interfaces/CompositeServiceConfig";
export type { ServiceConfig } from "./interfaces/ServiceConfig";
export type { ReadyContext } from "./interfaces/ReadyContext";
export type { OnCrashContext } from "./interfaces/OnCrashContext";
export type { ServiceCrash } from "./interfaces/ServiceCrash";
2 changes: 1 addition & 1 deletion src/interfaces/ReadyContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export interface ReadyContext {
*/
onceHttpOk: (
requestOptions: { url?: string | undefined } & RequestOptions,
expectedStatus?: number | undefined,
expectedStatus?: number | undefined
) => Promise<void>;

/**
Expand Down
11 changes: 4 additions & 7 deletions src/spawnProcess.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,30 +43,27 @@ function readEnvCaseInsensitive(env: { [key: string]: string }, key: string): st
const upperCaseKey = key.toUpperCase();
const caseInsensitiveKey = Object.keys(env)
.reverse()
.find(key => key.toUpperCase() === upperCaseKey);
.find((key) => key.toUpperCase() === upperCaseKey);
return caseInsensitiveKey === undefined ? undefined : env[caseInsensitiveKey];
}

function writeEnvCaseNormalized(
env: { [key: string]: string },
key: string,
value: string,
value: string
): { [key: string]: string } {
const upperCaseKey = key.toUpperCase();
return {
...Object.fromEntries(
Object.entries(env).filter(([key]) => key.toUpperCase() !== upperCaseKey),
Object.entries(env).filter(([key]) => key.toUpperCase() !== upperCaseKey)
),
[upperCaseKey]: value,
};
}

function filterBlankParts(string: string) {
const colon = isWindows ? ";" : ":";
return string
.split(colon)
.filter(Boolean)
.join(colon);
return string.split(colon).filter(Boolean).join(colon);
}

// Version of `which.sync` that adds a `cwd` parameter & doesn't throw
Expand Down
2 changes: 1 addition & 1 deletion src/util/onceAsyncTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const delay = promisify(setTimeout);

export async function onceAsyncTest(
minimumInterval: number,
test: () => Promise<boolean>,
test: () => Promise<boolean>
): Promise<void> {
while (true) {
const delayPromise = delay(minimumInterval);
Expand Down
2 changes: 1 addition & 1 deletion src/util/onceHttpOk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { onceAsyncTest } from "./onceAsyncTest";

export async function onceHttpOk(
requestOptions: { url?: string | undefined } & RequestOptions,
expectedStatus = 200,
expectedStatus = 200
): Promise<void> {
const { url, ...options } = requestOptions;
return onceAsyncTest(250, async () => {
Expand Down
2 changes: 1 addition & 1 deletion src/util/onceOutputLine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import stream from "stream";

export function onceOutputLine(
output: stream.Readable,
test: (line: string) => boolean,
test: (line: string) => boolean
): Promise<void> {
return new Promise<void>((resolve, reject) => {
const handler = (line: string) => {
Expand Down
2 changes: 1 addition & 1 deletion src/util/processSpawned.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@ export async function processSpawned(process: ChildProcessWithoutNullStreams) {
}

function isSpawnEventSupported() {
const [major, minor, patch] = process.versions.node.split(".").map(s => Number(s));
const [major, minor, patch] = process.versions.node.split(".").map((s) => Number(s));
return major > 15 || (major === 15 && minor >= 1 && patch >= 0);
}
Loading

0 comments on commit a396380

Please sign in to comment.