From cc573bb9c953c10b8b6a67cb9bccba783f474805 Mon Sep 17 00:00:00 2001 From: Patrick Sullivan Date: Sun, 28 Jul 2024 08:39:19 +0100 Subject: [PATCH] feat(monorepo): Code improvements and linting changes --- eslint.config.mjs | 3 +- packages/cli/src/program/index.ts | 8 +- packages/cli/src/program/shutdown.ts | 16 ++-- packages/cli/src/types.ts | 2 +- packages/cli/src/utilities/execute.ts | 22 ++--- packages/date-time/src/constants.ts | 6 +- packages/date-time/src/storm-date-time.ts | 16 ++-- packages/date-time/src/storm-date.ts | 32 +++---- packages/date-time/src/storm-time.ts | 16 +--- .../src/utilities/format-date-time-iso.ts | 29 +++--- .../src/utilities/format-date-time.ts | 31 ++++--- .../date-time/src/utilities/format-date.ts | 16 ++-- .../date-time/src/utilities/format-since.ts | 92 +++++++++---------- .../date-time/src/utilities/format-time.ts | 18 ++-- .../date-time/src/utilities/is-instant.ts | 2 +- .../src/utilities/validate-date-time.ts | 20 ++-- .../date-time/src/utilities/validate-date.ts | 22 ++--- .../date-time/src/utilities/validate-time.ts | 10 +- packages/errors/src/storm-error.ts | 23 ++--- .../src/utilities/create-storm-error.ts | 2 +- .../src/utilities/get-cause-from-unknown.ts | 2 +- .../errors/src/utilities/is-storm-error.ts | 2 +- .../errors/src/utilities/serialization.ts | 2 +- packages/file-system/src/files/copy-files.ts | 12 +-- .../file-system/src/files/file-path-fns.ts | 8 +- .../src/files/get-workspace-root.ts | 4 +- packages/file-system/src/files/join-paths.ts | 2 +- packages/file-system/src/files/read-file.ts | 12 +-- packages/file-system/src/files/write-file.ts | 8 +- .../src/package-management/get-tsconfig.ts | 6 +- .../src/package-management/package-fns.ts | 26 ++++-- .../logging/src/composition/logger-wrapper.ts | 2 +- packages/logging/src/storm-log.ts | 6 +- packages/logging/src/types.ts | 2 +- .../logging/src/utilities/get-log-level.ts | 24 +++-- .../logging/src/utilities/get-pino-options.ts | 5 +- .../logging/src/utilities/log-serializer.ts | 6 +- .../plugin-system/src/loader/plugin-loader.ts | 1 + .../src/manager/plugin-manager.ts | 29 +++--- packages/plugin-system/src/types.ts | 2 +- .../src/utilities/create-resolver.ts | 2 +- packages/utilities/src/crypto/sha-1.ts | 29 +----- pnpm-lock.yaml | 8 +- 43 files changed, 282 insertions(+), 304 deletions(-) diff --git a/eslint.config.mjs b/eslint.config.mjs index 44e26772..4edb0c7b 100644 --- a/eslint.config.mjs +++ b/eslint.config.mjs @@ -8,6 +8,7 @@ export default storm({ "unicorn/no-useless-switch-case": 0, "react/jsx-closing-bracket-location": 0, "no-undef": 0, - "unicorn/consistent-function-scoping": 0 + "unicorn/consistent-function-scoping": 0, + "class-methods-use-this": 0 } }); diff --git a/packages/cli/src/program/index.ts b/packages/cli/src/program/index.ts index d215866b..1ef51c06 100644 --- a/packages/cli/src/program/index.ts +++ b/packages/cli/src/program/index.ts @@ -2,11 +2,8 @@ import type { StormConfig } from "@storm-software/config"; import { createStormConfig } from "@storm-software/config-tools"; import { getCauseFromUnknown } from "@storm-stack/errors"; import { StormLog } from "@storm-stack/logging"; -import { - EMPTY_STRING, - NEWLINE_STRING, - titleCase -} from "@storm-stack/utilities"; +import { titleCase } from "@storm-stack/string-fns"; +import { EMPTY_STRING, NEWLINE_STRING } from "@storm-stack/types"; import chalk from "chalk"; import { Argument, Command, Option } from "commander"; import { Table } from "console-table-printer"; @@ -229,6 +226,7 @@ export async function createCLIProgram(cliConfig: CLIConfig): Promise { } } catch (error) { logger.fatal(error); + // eslint-disable-next-line unicorn/no-process-exit process.exit(1); } } diff --git a/packages/cli/src/program/shutdown.ts b/packages/cli/src/program/shutdown.ts index de544617..63cc6a67 100644 --- a/packages/cli/src/program/shutdown.ts +++ b/packages/cli/src/program/shutdown.ts @@ -1,5 +1,5 @@ import type { StormLog } from "@storm-stack/logging"; -import type { MaybePromise } from "@storm-stack/utilities"; +import type { MaybePromise } from "@storm-stack/types"; const errorTypes = ["unhandledRejection", "uncaughtException"]; const signalTraps = ["SIGTERM", "SIGINT", "SIGUSR2"]; @@ -27,9 +27,9 @@ export function registerShutdown(config: { await shutdown(); config.logger.info("Shutdown process complete, exiting with code 0"); process.exit(0); - } catch (e) { + } catch (error_) { config.logger.warn("Shutdown process failed, exiting with code 1"); - config.logger.error(e); + config.logger.error(error_); process.exit(1); } }); @@ -42,9 +42,9 @@ export function registerShutdown(config: { await shutdown(); config.logger.info("Shutdown process complete, exiting with code 0"); process.exit(0); - } catch (e) { + } catch (error_) { config.logger.warn("Shutdown process failed, exiting with code 1"); - config.logger.error(e); + config.logger.error(error_); process.exit(1); } }); @@ -55,10 +55,12 @@ export function registerShutdown(config: { config.logger.info(`Manual shutdown ${reason ? `(${reason})` : ""}`); await shutdown(); config.logger.info("Shutdown process complete, exiting with code 0"); + // eslint-disable-next-line unicorn/no-process-exit process.exit(0); - } catch (e) { + } catch (error_) { config.logger.warn("Shutdown process failed, exiting with code 1"); - config.logger.error(e); + config.logger.error(error_); + // eslint-disable-next-line unicorn/no-process-exit process.exit(1); } }; diff --git a/packages/cli/src/types.ts b/packages/cli/src/types.ts index f3a463ff..b0d8bfa2 100644 --- a/packages/cli/src/types.ts +++ b/packages/cli/src/types.ts @@ -1,4 +1,4 @@ -import { MaybePromise } from "@storm-stack/utilities"; +import { MaybePromise } from "@storm-stack/types"; import { Command } from "commander"; import { Fonts, Options } from "figlet"; diff --git a/packages/cli/src/utilities/execute.ts b/packages/cli/src/utilities/execute.ts index db3d63b6..d3815dc8 100644 --- a/packages/cli/src/utilities/execute.ts +++ b/packages/cli/src/utilities/execute.ts @@ -1,12 +1,12 @@ /* eslint-disable @typescript-eslint/no-explicit-any */ import { StormLog } from "@storm-stack/logging"; import { StormParser } from "@storm-stack/serialization"; -import { isEmptyObject } from "@storm-stack/utilities"; +import { isEmptyObject } from "@storm-stack/types"; import { ExecOptions, StdioOptions, execSync as extExecSync -} from "child_process"; +} from "node:child_process"; import { Readable } from "node:stream"; import { promisify } from "node:util"; @@ -28,26 +28,26 @@ export const execute = ( try { StormLog.info( `Executing command: "${command}"${ - !isEmptyObject(options) - ? `, options: ${StormParser.stringify(options)}` - : "" - }${!isEmptyObject(env) ? `, env: ${StormParser.stringify(env)}` : ""}${ - !stdio ? `, stdio: ${stdio}` : "" + isEmptyObject(options) + ? "" + : `, options: ${StormParser.stringify(options)}` + }${isEmptyObject(env) ? "" : `, env: ${StormParser.stringify(env)}`}${ + stdio ? "" : `, stdio: ${stdio}` }` ); return extExecSync(command, { - encoding: "utf-8", + encoding: "utf8", env: { ...process.env, ...env }, stdio, ...options }); - } catch (e) { + } catch (error_) { StormLog.error(`An error occurred executing command: "${command}"`); - StormLog.error(e); + StormLog.error(error_); return ( - (e as any)?.message ?? "Exception occurred while processing request " + (error_ as any)?.message ?? "Exception occurred while processing request " ); } }; diff --git a/packages/date-time/src/constants.ts b/packages/date-time/src/constants.ts index 0ff66d5c..2b741882 100644 --- a/packages/date-time/src/constants.ts +++ b/packages/date-time/src/constants.ts @@ -1,8 +1,8 @@ export const RFC_3339_DATETIME_REGEX = - /^(\d{4}-(0[1-9]|1[012])-(0[1-9]|[12][0-9]|3[01])T([01][0-9]|2[0-3]):([0-5][0-9]):([0-5][0-9]|60))(\.\d{1,})?(([Z])|([+|-]([01][0-9]|2[0-3]):[0-5][0-9]))$/; + /^(\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12]\d|3[01])T([01]\d|2[0-3]):([0-5]\d):([0-5]\d|60))(\.\d+)?((Z)|([+|-]([01]\d|2[0-3]):[0-5]\d))$/; export const RFC_3339_DATE_REGEX = - /^(\d{4}-(0[1-9]|1[012])-(0[1-9]|[12][0-9]|3[01]))$/; + /^(\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12]\d|3[01]))$/; export const RFC_3339_TIME_REGEX = - /^([01][0-9]|2[0-3]):([0-5][0-9]):([0-5][0-9])(\.\d{1,})?(([Z])|([+|-]([01][0-9]|2[0-3]):[0-5][0-9]))$/; + /^([01]\d|2[0-3]):([0-5]\d):([0-5]\d)(\.\d+)?((Z)|([+|-]([01]\d|2[0-3]):[0-5]\d))$/; diff --git a/packages/date-time/src/storm-date-time.ts b/packages/date-time/src/storm-date-time.ts index de6f0d3b..155f85c1 100644 --- a/packages/date-time/src/storm-date-time.ts +++ b/packages/date-time/src/storm-date-time.ts @@ -7,7 +7,7 @@ import { isObject, isSet, isSetString -} from "@storm-stack/utilities"; +} from "@storm-stack/types"; import { RFC_3339_DATETIME_REGEX } from "./constants"; import { isInstant } from "./utilities/is-instant"; @@ -72,6 +72,7 @@ export function deserializeStormDateTime(utcString: JsonValue): StormDateTime { * A wrapper of the and Date class used by Storm Software to provide Date-Time values * * @decorator `@Serializable()` + * @class StormDateTime */ @Serializable() export class StormDateTime extends Date { @@ -202,11 +203,11 @@ export class StormDateTime extends Date { if (instant && this.validate(_dateTime, options)) { this.#instant = instant; - const timeZone = options?.timeZone - ? options?.timeZone - : process.env.TZ - ? process.env.TZ - : Temporal.Now.timeZoneId(); + const timeZone = + options?.timeZone || + process.env.STORM_TIMEZONE || + process.env.TZ || + Temporal.Now.timeZoneId(); this.#zonedDateTime = options?.calendar ? this.#instant.toZonedDateTime({ timeZone, @@ -309,8 +310,7 @@ export class StormDateTime extends Date { let datetime: string | undefined; if (isDate(value) || isNumber(value) || isBigInt(value)) { - let date!: Date; - date = + const date = isNumber(value) || isBigInt(value) ? new Date(Number(value)) : value; if (Number.isNaN(date.getTime())) { diff --git a/packages/date-time/src/storm-date.ts b/packages/date-time/src/storm-date.ts index b31e79eb..d529440b 100644 --- a/packages/date-time/src/storm-date.ts +++ b/packages/date-time/src/storm-date.ts @@ -1,12 +1,7 @@ /* eslint-disable @typescript-eslint/no-explicit-any */ import { Temporal } from "@js-temporal/polyfill"; import { type JsonValue, Serializable } from "@storm-stack/serialization"; -import { - isBigInt, - isDate, - isNumber, - isSetString -} from "@storm-stack/utilities"; +import { isBigInt, isDate, isNumber, isSetString } from "@storm-stack/types"; import { RFC_3339_DATE_REGEX } from "./constants"; import type { DateTimeInput, DateTimeOptions } from "./storm-date-time"; import { StormDateTime } from "./storm-date-time"; @@ -38,6 +33,7 @@ export function deserializeStormDate(utcString: JsonValue): StormDate { * A wrapper of the and Date class used by Storm Software to provide Date-Time values * * @decorator `@Serializable()` + * @class StormDate */ @Serializable() export class StormDate extends StormDateTime { @@ -63,7 +59,7 @@ export class StormDate extends StormDateTime { * @returns A new instance of StormDateTime with the maximum date and time. */ public static override minimum(): StormDate { - return StormDate.create(new Date(-8640000000000000)); + return StormDate.create(new Date(-8_640_000_000_000_000)); } /** @@ -72,7 +68,7 @@ export class StormDate extends StormDateTime { * @returns A new instance of StormDateTime with the maximum date and time. */ public static override maximum(): StormDate { - return StormDate.create(new Date(8640000000000000)); + return StormDate.create(new Date(8_640_000_000_000_000)); } /** @@ -141,12 +137,8 @@ export class StormDate extends StormDateTime { let datetime: string | undefined; if (isDate(value) || isNumber(value) || isBigInt(value)) { - let date!: Date; - if (isNumber(value) || isBigInt(value)) { - date = new Date(Number(value)); - } else { - date = value; - } + const date = + isNumber(value) || isBigInt(value) ? new Date(Number(value)) : value; if (Number.isNaN(date.getTime())) { return false; @@ -174,23 +166,27 @@ export class StormDate extends StormDateTime { case 7: case 8: case 10: - case 12: + case 12: { return createdDateTime.zonedDateTime.day > 31; + } - case 2: + case 2: { return ( createdDateTime.zonedDateTime.day > (createdDateTime.zonedDateTime.inLeapYear ? 29 : 28) ); + } case 4: case 6: case 9: - case 11: + case 11: { return createdDateTime.zonedDateTime.day > 30; + } - default: + default: { return true; + } } } diff --git a/packages/date-time/src/storm-time.ts b/packages/date-time/src/storm-time.ts index 72878c1b..b938ed94 100644 --- a/packages/date-time/src/storm-time.ts +++ b/packages/date-time/src/storm-time.ts @@ -1,12 +1,7 @@ /* eslint-disable @typescript-eslint/no-explicit-any */ import { Temporal } from "@js-temporal/polyfill"; import { type JsonValue, Serializable } from "@storm-stack/serialization"; -import { - isBigInt, - isDate, - isNumber, - isSetString -} from "@storm-stack/utilities"; +import { isBigInt, isDate, isNumber, isSetString } from "@storm-stack/types"; import { RFC_3339_TIME_REGEX } from "./constants"; import type { DateTimeInput, DateTimeOptions } from "./storm-date-time"; import { StormDateTime } from "./storm-date-time"; @@ -38,6 +33,7 @@ export function deserializeStormTime(utcString: JsonValue): StormTime { * A wrapper of the and Date class used by Storm Software to provide Date-Time values * * @decorator `@Serializable()` + * @class StormTime */ @Serializable() export class StormTime extends StormDateTime { @@ -117,12 +113,8 @@ export class StormTime extends StormDateTime { let datetime: string | undefined; if (isDate(value) || isNumber(value) || isBigInt(value)) { - let date!: Date; - if (isNumber(value) || isBigInt(value)) { - date = new Date(Number(value)); - } else { - date = value; - } + const date = + isNumber(value) || isBigInt(value) ? new Date(Number(value)) : value; if (Number.isNaN(date.getTime())) { return false; diff --git a/packages/date-time/src/utilities/format-date-time-iso.ts b/packages/date-time/src/utilities/format-date-time-iso.ts index 03884454..38becc4d 100644 --- a/packages/date-time/src/utilities/format-date-time-iso.ts +++ b/packages/date-time/src/utilities/format-date-time-iso.ts @@ -1,5 +1,5 @@ import type { Temporal } from "@js-temporal/polyfill"; -import { EMPTY_STRING } from "@storm-stack/utilities"; +import { EMPTY_STRING } from "@storm-stack/types"; import type { StormDateTime } from "../storm-date-time"; /** @@ -11,16 +11,23 @@ import type { StormDateTime } from "../storm-date-time"; */ export const formatDateTimeISO = ( dateTime?: StormDateTime | null, - options: Partial = { - smallestUnit: "milliseconds", - roundingMode: "ceil", - calendarName: "never", - timeZoneName: "never", - offset: "never" - } -): string => - dateTime + options?: Partial +): string => { + const smallestUnit = options?.smallestUnit || "millisecond"; + const roundingMode = options?.roundingMode || "ceil"; + const calendarName = options?.calendarName || "never"; + const timeZoneName = options?.timeZoneName || "never"; + const offset = options?.offset || "never"; + + return dateTime ? `${dateTime.instant .toZonedDateTimeISO(dateTime.timeZoneId ?? process.env.TZ ?? "UTC") - .toString(options)}` + .toString({ + smallestUnit, + roundingMode, + calendarName, + timeZoneName, + offset + })}` : EMPTY_STRING; +}; diff --git a/packages/date-time/src/utilities/format-date-time.ts b/packages/date-time/src/utilities/format-date-time.ts index dddf307d..048bd04f 100644 --- a/packages/date-time/src/utilities/format-date-time.ts +++ b/packages/date-time/src/utilities/format-date-time.ts @@ -1,5 +1,5 @@ import type { Temporal } from "@js-temporal/polyfill"; -import { EMPTY_STRING } from "@storm-stack/utilities"; +import { EMPTY_STRING } from "@storm-stack/types"; import { StormDateTime } from "../storm-date-time"; /** @@ -11,14 +11,23 @@ import { StormDateTime } from "../storm-date-time"; */ export const formatDateTime = ( dateTime: StormDateTime = StormDateTime.current(), - options: Partial = { - smallestUnit: "millisecond", - roundingMode: "ceil", - calendarName: "never", - timeZoneName: "never", - offset: "never" - } -): string => - dateTime - ? `${dateTime.zonedDateTime.toString(options).replaceAll("T", " ")}` + options?: Partial +): string => { + const smallestUnit = options?.smallestUnit || "millisecond"; + const roundingMode = options?.roundingMode || "ceil"; + const calendarName = options?.calendarName || "never"; + const timeZoneName = options?.timeZoneName || "never"; + const offset = options?.offset || "never"; + + return dateTime + ? `${dateTime.zonedDateTime + .toString({ + smallestUnit, + roundingMode, + calendarName, + timeZoneName, + offset + }) + .replaceAll("T", " ")}` : EMPTY_STRING; +}; diff --git a/packages/date-time/src/utilities/format-date.ts b/packages/date-time/src/utilities/format-date.ts index 118fc254..3300df96 100644 --- a/packages/date-time/src/utilities/format-date.ts +++ b/packages/date-time/src/utilities/format-date.ts @@ -10,11 +10,11 @@ import type { StormDateTime } from "../storm-date-time"; */ export const formatDate = ( dateTime: StormDateTime = StormDate.current(), - options: Partial = { - smallestUnit: "minute", - roundingMode: "ceil", - calendarName: "never", - timeZoneName: "never", - offset: "never" - } -): string => dateTime.zonedDateTime.toPlainDate().toString(options); + options?: Partial +): string => { + const calendarName = options?.calendarName || "never"; + + return dateTime.zonedDateTime.toPlainDate().toString({ + calendarName + }); +}; diff --git a/packages/date-time/src/utilities/format-since.ts b/packages/date-time/src/utilities/format-since.ts index 8cdd2a46..b419c4ce 100644 --- a/packages/date-time/src/utilities/format-since.ts +++ b/packages/date-time/src/utilities/format-since.ts @@ -16,9 +16,9 @@ const parseMilliseconds = (milliseconds: number) => { } return { - days: Math.trunc(milliseconds / 86400000), - hours: Math.trunc(milliseconds / 3600000) % 24, - minutes: Math.trunc(milliseconds / 60000) % 60, + days: Math.trunc(milliseconds / 86_400_000), + hours: Math.trunc(milliseconds / 3_600_000) % 24, + minutes: Math.trunc(milliseconds / 60_000) % 60, seconds: Math.trunc(milliseconds / 1000) % 60, milliseconds: Math.trunc(milliseconds) % 1000, microseconds: Math.trunc(milliseconds * 1000) % 1000, @@ -94,24 +94,23 @@ export type FormatSinceOptions = { export const formatSince = ( dateTimeOrDuration: StormDateTime | Temporal.Duration, dateTimeTo: StormDateTime = StormDateTime.current(), - options: FormatSinceOptions = { - colonNotation: false, - compact: false, - formatSubMilliseconds: false, - keepDecimalsOnWholeSeconds: false, - millisecondsDecimalDigits: 0, - secondsDecimalDigits: 1, - separateMilliseconds: false, - unitCount: 0, - verbose: false - } + options?: FormatSinceOptions ): string => { + const colonNotation = options?.colonNotation ?? false; + let compact = options?.compact ?? false; + let formatSubMilliseconds = options?.formatSubMilliseconds ?? false; + const keepDecimalsOnWholeSeconds = + options?.keepDecimalsOnWholeSeconds ?? false; + let millisecondsDecimalDigits = options?.millisecondsDecimalDigits ?? 0; + let secondsDecimalDigits = options?.secondsDecimalDigits ?? 1; + let separateMilliseconds = options?.separateMilliseconds ?? false; + const unitCount = options?.unitCount ?? 0; + let verbose = options?.verbose ?? false; + let milliseconds!: number; - if (isDateTime(dateTimeOrDuration)) { - milliseconds = dateTimeTo.since(dateTimeOrDuration).milliseconds; - } else { - milliseconds = dateTimeOrDuration.milliseconds; - } + milliseconds = isDateTime(dateTimeOrDuration) + ? dateTimeTo.since(dateTimeOrDuration).milliseconds + : dateTimeOrDuration.milliseconds; if (!Number.isFinite(milliseconds)) { throw new StormError(DateTimeErrorCode.ms_format, { @@ -124,16 +123,16 @@ export const formatSince = ( milliseconds *= -1; } - if (options.colonNotation) { - options.compact = false; - options.formatSubMilliseconds = false; - options.separateMilliseconds = false; - options.verbose = false; + if (colonNotation) { + compact = false; + formatSubMilliseconds = false; + separateMilliseconds = false; + verbose = false; } - if (options.compact) { - options.secondsDecimalDigits = 0; - options.millisecondsDecimalDigits = 0; + if (compact) { + secondsDecimalDigits = 0; + millisecondsDecimalDigits = 0; } const result: string[] = []; @@ -152,9 +151,9 @@ export const formatSince = ( valueString?: string ) => { if ( - (result.length === 0 || !options.colonNotation) && + (result.length === 0 || !colonNotation) && value === 0 && - !(options.colonNotation && short === "m") + !(colonNotation && short === "m") ) { return; } @@ -162,7 +161,7 @@ export const formatSince = ( let _valueString = (valueString || value || "0").toString(); let prefix: string; let suffix: string; - if (options.colonNotation) { + if (colonNotation) { prefix = result.length > 0 ? ":" : ""; suffix = ""; const wholeDigits = _valueString.includes(".") @@ -173,7 +172,7 @@ export const formatSince = ( "0".repeat(Math.max(0, minLength - wholeDigits)) + _valueString; } else { prefix = ""; - suffix = options.verbose ? ` ${pluralize(long, value)}` : short; + suffix = verbose ? ` ${pluralize(long, value)}` : short; } result.push(prefix + _valueString + suffix); @@ -187,12 +186,12 @@ export const formatSince = ( add(parsed.minutes, "minute", "m"); if ( - options.separateMilliseconds || - options.formatSubMilliseconds || - (!options.colonNotation && milliseconds < 1000) + separateMilliseconds || + formatSubMilliseconds || + (!colonNotation && milliseconds < 1000) ) { add(parsed.seconds, "second", "s"); - if (options.formatSubMilliseconds) { + if (formatSubMilliseconds) { add(parsed.milliseconds, "millisecond", "ms"); add(parsed.microseconds, "microsecond", "µs"); add(parsed.nanoseconds, "nanosecond", "ns"); @@ -202,11 +201,6 @@ export const formatSince = ( parsed.microseconds / 1000 + parsed.nanoseconds / 1e6; - const millisecondsDecimalDigits = - typeof options.millisecondsDecimalDigits === "number" - ? options.millisecondsDecimalDigits - : 0; - const roundedMilliseconds = millisecondsAndBelow >= 1 ? Math.round(millisecondsAndBelow) @@ -225,22 +219,18 @@ export const formatSince = ( } } else { const seconds = (milliseconds / 1000) % 60; - const secondsDecimalDigits = - typeof options.secondsDecimalDigits === "number" - ? options.secondsDecimalDigits - : 1; const secondsFixed = floorDecimals(seconds, secondsDecimalDigits); - const secondsString = options.keepDecimalsOnWholeSeconds + const secondsString = keepDecimalsOnWholeSeconds ? secondsFixed : secondsFixed.replace(/\.0+$/, ""); add(Number.parseFloat(secondsString), "second", "s", secondsString); } if (result.length === 0) { - return `0${options.verbose ? " milliseconds" : "ms"}`; + return `0${verbose ? " milliseconds" : "ms"}`; } - if (options.compact) { + if (compact) { if (!result[0]) { throw new StormError(DateTimeErrorCode.formatting_failure, { message: "Unexpected empty result" @@ -250,10 +240,10 @@ export const formatSince = ( return result[0]; } - if (typeof options.unitCount === "number") { - const separator = options.colonNotation ? "" : " "; - return result.slice(0, Math.max(options.unitCount, 1)).join(separator); + if (typeof unitCount === "number") { + const separator = colonNotation ? "" : " "; + return result.slice(0, Math.max(unitCount, 1)).join(separator); } - return options.colonNotation ? result.join("") : result.join(" "); + return colonNotation ? result.join("") : result.join(" "); }; diff --git a/packages/date-time/src/utilities/format-time.ts b/packages/date-time/src/utilities/format-time.ts index 02d0943e..cfa24aca 100644 --- a/packages/date-time/src/utilities/format-time.ts +++ b/packages/date-time/src/utilities/format-time.ts @@ -10,11 +10,13 @@ import { StormTime } from "../storm-time"; */ export const formatTime = ( dateTime: StormDateTime = StormTime.current(), - options: Partial = { - smallestUnit: "milliseconds", - roundingMode: "ceil", - calendarName: "never", - timeZoneName: "never", - offset: "never" - } -): string => dateTime.zonedDateTime.toPlainTime().toString(options); + options?: Partial +): string => { + const smallestUnit = options?.smallestUnit || "milliseconds"; + const roundingMode = options?.roundingMode || "ceil"; + + return dateTime.zonedDateTime.toPlainTime().toString({ + smallestUnit, + roundingMode + }); +}; diff --git a/packages/date-time/src/utilities/is-instant.ts b/packages/date-time/src/utilities/is-instant.ts index c554d647..f9ec040f 100644 --- a/packages/date-time/src/utilities/is-instant.ts +++ b/packages/date-time/src/utilities/is-instant.ts @@ -1,5 +1,5 @@ import { Temporal } from "@js-temporal/polyfill"; -import { isFunction, isSet } from "@storm-stack/utilities"; +import { isFunction, isSet } from "@storm-stack/types"; /** * Type-check to determine if `value` is a `Temporal.Instant` object diff --git a/packages/date-time/src/utilities/validate-date-time.ts b/packages/date-time/src/utilities/validate-date-time.ts index 0be8d6d2..42a54926 100644 --- a/packages/date-time/src/utilities/validate-date-time.ts +++ b/packages/date-time/src/utilities/validate-date-time.ts @@ -1,4 +1,4 @@ -import { isBigInt, isDate, isNumber } from "@storm-stack/utilities"; +import { isBigInt, isDate, isNumber } from "@storm-stack/types"; import { RFC_3339_DATETIME_REGEX } from "../constants"; import type { DateTimeInput, DateTimeOptions } from "../storm-date-time"; import { isDateTime } from "./is-date-time"; @@ -25,12 +25,8 @@ export function validateDateTime( let datetime: string | undefined; if (isDate(value) || isNumber(value) || isBigInt(value)) { - let date!: Date; - if (isNumber(value) || isBigInt(value)) { - date = new Date(Number(value)); - } else { - date = value; - } + const date = + isNumber(value) || isBigInt(value) ? new Date(Number(value)) : value; if (Number.isNaN(date.getTime())) { return false; @@ -59,7 +55,13 @@ export function validateDateTime( // Split the date-time-string up into the string-date and time-string part. // and check whether these parts are RFC 3339 compliant. return !!( - validateDate(datetime.substring(0, datetime.indexOf("T")), options) && - validateTime(datetime.substring(datetime.indexOf("T") + 1), options) + validateDate( + datetime.slice(0, Math.max(0, datetime.indexOf("T"))), + options + ) && + validateTime( + datetime.slice(Math.max(0, datetime.indexOf("T") + 1)), + options + ) ); } diff --git a/packages/date-time/src/utilities/validate-date.ts b/packages/date-time/src/utilities/validate-date.ts index a4dc7638..ca7e5b1f 100644 --- a/packages/date-time/src/utilities/validate-date.ts +++ b/packages/date-time/src/utilities/validate-date.ts @@ -1,4 +1,4 @@ -import { isBigInt, isDate, isNumber } from "@storm-stack/utilities"; +import { isBigInt, isDate, isNumber } from "@storm-stack/types"; import { RFC_3339_DATE_REGEX } from "../constants"; import { type DateTimeInput, @@ -21,12 +21,8 @@ export function validateDate( let datetime: string | undefined; if (isDate(value) || isNumber(value) || isBigInt(value)) { - let date!: Date; - if (isNumber(value) || isBigInt(value)) { - date = new Date(Number(value)); - } else { - date = value; - } + const date = + isNumber(value) || isBigInt(value) ? new Date(Number(value)) : value; if (Number.isNaN(date.getTime())) { return false; @@ -54,22 +50,26 @@ export function validateDate( case 7: case 8: case 10: - case 12: + case 12: { return createdDateTime.zonedDateTime.day > 31; + } - case 2: + case 2: { return ( createdDateTime.zonedDateTime.day > (createdDateTime.zonedDateTime.inLeapYear ? 29 : 28) ); + } case 4: case 6: case 9: - case 11: + case 11: { return createdDateTime.zonedDateTime.day > 30; + } - default: + default: { return true; + } } } diff --git a/packages/date-time/src/utilities/validate-time.ts b/packages/date-time/src/utilities/validate-time.ts index 02293b4c..9a12da9d 100644 --- a/packages/date-time/src/utilities/validate-time.ts +++ b/packages/date-time/src/utilities/validate-time.ts @@ -1,4 +1,4 @@ -import { isBigInt, isDate, isNumber } from "@storm-stack/utilities"; +import { isBigInt, isDate, isNumber } from "@storm-stack/types"; import { RFC_3339_TIME_REGEX } from "../constants"; import type { DateTimeInput, DateTimeOptions } from "../storm-date-time"; import { isDateTime } from "./is-date-time"; @@ -17,12 +17,8 @@ export function validateTime( let datetime: string | undefined; if (isDate(value) || isNumber(value) || isBigInt(value)) { - let date!: Date; - if (isNumber(value) || isBigInt(value)) { - date = new Date(Number(value)); - } else { - date = value; - } + const date = + isNumber(value) || isBigInt(value) ? new Date(Number(value)) : value; if (Number.isNaN(date.getTime())) { return false; diff --git a/packages/errors/src/storm-error.ts b/packages/errors/src/storm-error.ts index e38a5d76..414366b7 100644 --- a/packages/errors/src/storm-error.ts +++ b/packages/errors/src/storm-error.ts @@ -1,10 +1,6 @@ /* eslint-disable @typescript-eslint/no-explicit-any */ import { Serializable } from "@storm-stack/serialization"; -import { - EMPTY_STRING, - NEWLINE_STRING, - isFunction -} from "@storm-stack/utilities"; +import { EMPTY_STRING, NEWLINE_STRING, isFunction } from "@storm-stack/types"; import { getCauseFromUnknown, isStormError } from "./utilities"; export interface StormErrorOptions { @@ -56,16 +52,13 @@ export class StormError extends Error { public constructor( code: TCode, - { name, message, cause, stack, data }: StormErrorOptions = { - name: "StormError", - message: "An error occurred during processing" - } + { name, message, cause, stack, data }: StormErrorOptions ) { super(message, { cause }); this.code = code; - this.message ??= message ? message : "An error occurred during processing"; - this.name ??= name ? name : this.constructor.name; + this.message ??= message || "An error occurred during processing"; + this.name ??= name || this.constructor.name; this.data = data; if (stack) { @@ -135,7 +128,7 @@ export class StormError extends Error { * @returns The stack trace string */ public get originalStack(): string { - return super.stack ? super.stack : this.stack; + return super.stack || this.stack; } /** @@ -169,9 +162,9 @@ export class StormError extends Error { public override toString(stacktrace?: boolean): string { return ( this.print() + - (stacktrace !== false - ? ` ${NEWLINE_STRING}Stack Trace: ${NEWLINE_STRING}${this.stack}` - : "") + (stacktrace === false + ? "" + : ` ${NEWLINE_STRING}Stack Trace: ${NEWLINE_STRING}${this.stack}`) ); } } diff --git a/packages/errors/src/utilities/create-storm-error.ts b/packages/errors/src/utilities/create-storm-error.ts index 6c625639..57141e1d 100644 --- a/packages/errors/src/utilities/create-storm-error.ts +++ b/packages/errors/src/utilities/create-storm-error.ts @@ -25,7 +25,7 @@ export function createStormError({ } const stormError = new StormError( - (code ? code : ErrorCode.internal_server_error) as TCode, + (code || ErrorCode.internal_server_error) as TCode, { name, message, diff --git a/packages/errors/src/utilities/get-cause-from-unknown.ts b/packages/errors/src/utilities/get-cause-from-unknown.ts index e4b480e2..2469e59f 100644 --- a/packages/errors/src/utilities/get-cause-from-unknown.ts +++ b/packages/errors/src/utilities/get-cause-from-unknown.ts @@ -1,4 +1,4 @@ -import { type Indexable, isError, isObject } from "@storm-stack/utilities"; +import { type Indexable, isError, isObject } from "@storm-stack/types"; import { ErrorCode } from "../errors"; import { StormError } from "../storm-error"; import { createStormError } from "./create-storm-error"; diff --git a/packages/errors/src/utilities/is-storm-error.ts b/packages/errors/src/utilities/is-storm-error.ts index d6e20e89..005deed2 100644 --- a/packages/errors/src/utilities/is-storm-error.ts +++ b/packages/errors/src/utilities/is-storm-error.ts @@ -1,4 +1,4 @@ -import { isError, isSetString } from "@storm-stack/utilities"; +import { isError, isSetString } from "@storm-stack/types"; import type { StormError } from "../storm-error"; /** diff --git a/packages/errors/src/utilities/serialization.ts b/packages/errors/src/utilities/serialization.ts index 4f277ad3..9a6d4f60 100644 --- a/packages/errors/src/utilities/serialization.ts +++ b/packages/errors/src/utilities/serialization.ts @@ -1,5 +1,5 @@ import type { JsonObject, JsonValue } from "@storm-stack/serialization"; -import { isSetObject } from "@storm-stack/utilities"; +import { isSetObject } from "@storm-stack/types"; import { ErrorCode } from "../errors"; import { StormError } from "../storm-error"; diff --git a/packages/file-system/src/files/copy-files.ts b/packages/file-system/src/files/copy-files.ts index 3ba6e9ea..b9969980 100644 --- a/packages/file-system/src/files/copy-files.ts +++ b/packages/file-system/src/files/copy-files.ts @@ -20,12 +20,12 @@ export const copyFiles = ( cpSync(from, to, options); return undefined; - } catch (e) { + } catch (error_) { StormLog.error("An error occurred copying files"); - StormLog.error(e); + StormLog.error(error_); return ( - (e as any)?.message ?? "Exception occurred while processing request " + (error_ as any)?.message ?? "Exception occurred while processing request " ); } }; @@ -47,12 +47,12 @@ export const copyFile = ( copyFileSync(file, dest, constants.COPYFILE_FICLONE); return undefined; - } catch (e) { + } catch (error_) { StormLog.error("An error occurred copying files"); - StormLog.error(e); + StormLog.error(error_); return ( - (e as any)?.message ?? "Exception occurred while processing request " + (error_ as any)?.message ?? "Exception occurred while processing request " ); } }; diff --git a/packages/file-system/src/files/file-path-fns.ts b/packages/file-system/src/files/file-path-fns.ts index 28ffa73f..7fb8e320 100644 --- a/packages/file-system/src/files/file-path-fns.ts +++ b/packages/file-system/src/files/file-path-fns.ts @@ -1,4 +1,4 @@ -import { EMPTY_STRING } from "@storm-stack/utilities"; +import { EMPTY_STRING } from "@storm-stack/types"; import { dirname, isAbsolute, parse, relative, sep } from "node:path"; import { getWorkspaceRoot } from "./get-workspace-root"; import { joinPaths } from "./join-paths"; @@ -58,7 +58,7 @@ export function findContainingFolder(filePath: string): string { folderPath.lastIndexOf("\\") === folderPath.length - 1 || folderPath.lastIndexOf("/") === folderPath.length - 1 ) { - folderPath = folderPath.substring(0, folderPath.length - 1); + folderPath = folderPath.slice(0, Math.max(0, folderPath.length - 1)); } return folderPath.split("\\").pop() ?? EMPTY_STRING; @@ -118,8 +118,8 @@ export function relativeToWorkspaceRoot(filePath: string) { /** * Rename the file name with a new name. * - * @param filePath The current file path being processed - * @param newFileName The updated file name being processed + * @param filePath - The current file path being processed + * @param newFileName - The updated file name being processed * @returns The modified or unmodified file path. */ export function renameFile(filePath: string, newFileName: string): string { diff --git a/packages/file-system/src/files/get-workspace-root.ts b/packages/file-system/src/files/get-workspace-root.ts index 358166aa..b03bb21f 100644 --- a/packages/file-system/src/files/get-workspace-root.ts +++ b/packages/file-system/src/files/get-workspace-root.ts @@ -20,7 +20,5 @@ export const getWorkspaceRoot = () => { return root?.dir; } - return process.env.STORM_WORKSPACE_ROOT - ? process.env.STORM_WORKSPACE_ROOT - : process.env.NX_WORKSPACE_ROOT_PATH; + return process.env.STORM_WORKSPACE_ROOT || process.env.NX_WORKSPACE_ROOT_PATH; }; diff --git a/packages/file-system/src/files/join-paths.ts b/packages/file-system/src/files/join-paths.ts index adca6d3b..b17c7101 100644 --- a/packages/file-system/src/files/join-paths.ts +++ b/packages/file-system/src/files/join-paths.ts @@ -12,5 +12,5 @@ export const joinPaths = (...paths: string[]): string => { const result = isAbsolute(path) ? path.replaceAll("/", "\\") : path.replaceAll("\\", "/"); - return result.startsWith("/C:") ? result.substring(1) : result; + return result.startsWith("/C:") ? result.slice(1) : result; }; diff --git a/packages/file-system/src/files/read-file.ts b/packages/file-system/src/files/read-file.ts index 2bddd730..4140294f 100644 --- a/packages/file-system/src/files/read-file.ts +++ b/packages/file-system/src/files/read-file.ts @@ -16,11 +16,11 @@ export const readFile = (filePath: string): string => { }); } - return readFileSync(filePath, { encoding: "utf-8" }); - } catch (e) { + return readFileSync(filePath, { encoding: "utf8" }); + } catch (error_) { throw new StormError(FileSystemErrorCode.file_write_failure, { message: "An error occurred writing data to file", - cause: e + cause: error_ }); } }; @@ -38,11 +38,11 @@ export const readFileAsync = (filePath: string): Promise => { }); } - return promisify(readFileFs)(filePath, { encoding: "utf-8" }); - } catch (e) { + return promisify(readFileFs)(filePath, { encoding: "utf8" }); + } catch (error_) { throw new StormError(FileSystemErrorCode.file_write_failure, { message: "An error occurred writing data to file", - cause: e + cause: error_ }); } }; diff --git a/packages/file-system/src/files/write-file.ts b/packages/file-system/src/files/write-file.ts index 8e8ce14d..d4b36989 100644 --- a/packages/file-system/src/files/write-file.ts +++ b/packages/file-system/src/files/write-file.ts @@ -24,10 +24,10 @@ export const writeFile = (filePath: string, content: any): void => { } writeFileSync(filePath, StormParser.stringify(content)); - } catch (e) { + } catch (error_) { throw new StormError(FileSystemErrorCode.file_write_failure, { message: "An error occurred writing data to file", - cause: e + cause: error_ }); } }; @@ -49,10 +49,10 @@ export const writeFileAsync = ( } return promisify(writeFileFs)(filePath, content); - } catch (e) { + } catch (error_) { throw new StormError(FileSystemErrorCode.file_write_failure, { message: "An error occurred writing data to file", - cause: e + cause: error_ }); } }; diff --git a/packages/file-system/src/package-management/get-tsconfig.ts b/packages/file-system/src/package-management/get-tsconfig.ts index fdb52bd2..550046b7 100644 --- a/packages/file-system/src/package-management/get-tsconfig.ts +++ b/packages/file-system/src/package-management/get-tsconfig.ts @@ -1,4 +1,4 @@ -import { EMPTY_STRING } from "@storm-stack/utilities"; +import { EMPTY_STRING } from "@storm-stack/types"; import fs from "node:fs"; import { createRequire } from "node:module"; import path from "node:path"; @@ -124,7 +124,7 @@ const stripJsonComments = ( const jsoncParse = (data: string) => { try { return new Function(`return ${stripJsonComments(data).trim()}`)(); - } catch (_) { + } catch { return {}; } }; @@ -178,7 +178,7 @@ const loadTsConfigInternal = ( return null; } - const data = jsoncParse(fs.readFileSync(id, "utf-8")); + const data = jsoncParse(fs.readFileSync(id, "utf8")); const configDir = path.dirname(id); // biome-ignore lint/suspicious/noAssignInExpressions: if ((_a = data.compilerOptions) == null ? void 0 : _a.baseUrl) { diff --git a/packages/file-system/src/package-management/package-fns.ts b/packages/file-system/src/package-management/package-fns.ts index fcb8b411..bbb9df49 100644 --- a/packages/file-system/src/package-management/package-fns.ts +++ b/packages/file-system/src/package-management/package-fns.ts @@ -36,14 +36,18 @@ function getPackageManager(projectPath = "."): PackageManagers { } switch (basename(lockFile)) { - case "yarn.lock": + case "yarn.lock": { return "yarn"; - case "pnpm-lock.yaml": + } + case "pnpm-lock.yaml": { return "pnpm"; - case "bun.lockb": + } + case "bun.lockb": { return "bun"; - default: + } + default: { return "npm"; + } } } @@ -58,23 +62,25 @@ export function installPackage( const manager = pkgManager ?? getPackageManager(projectPath); console.log(`Installing package "${pkg}@${tag}" with ${manager}`); switch (manager) { - case "yarn": + case "yarn": { execute( `yarn --cwd "${projectPath}" add ${exactVersion ? "--exact" : ""} ${pkg}@${tag} ${ dev ? " --dev" : "" }` ); break; + } - case "pnpm": + case "pnpm": { execute( `pnpm add -C "${projectPath}" ${exactVersion ? "--save-exact" : ""} ${ dev ? " --save-dev" : "" } ${pkg}@${tag}` ); break; + } - case "bun": + case "bun": { execute( `bun add ${exactVersion ? "--exact" : ""} ${dev ? " --dev" : ""} ${pkg}@${tag}`, { @@ -82,14 +88,16 @@ export function installPackage( } ); break; + } - default: + default: { execute( `npm install --prefix "${projectPath}" ${exactVersion ? "--save-exact" : ""} ${ dev ? " --save-dev" : "" } ${pkg}@${tag}` ); break; + } } } @@ -104,7 +112,7 @@ export function ensurePackage( const resolvePath = resolve(projectPath); try { require.resolve(pkg, { paths: [resolvePath] }); - } catch (_err) { + } catch { installPackage(pkg, dev, pkgManager, tag, resolvePath, exactVersion); } } diff --git a/packages/logging/src/composition/logger-wrapper.ts b/packages/logging/src/composition/logger-wrapper.ts index c67c19e3..1fe58c67 100644 --- a/packages/logging/src/composition/logger-wrapper.ts +++ b/packages/logging/src/composition/logger-wrapper.ts @@ -1,6 +1,6 @@ import type { StormConfig } from "@storm-software/config"; import { getCauseFromUnknown } from "@storm-stack/errors"; -import { type MaybePromise, isSet, isSetString } from "@storm-stack/utilities"; +import { type MaybePromise, isSet, isSetString } from "@storm-stack/types"; import type { ILogger, ILoggerWrapper } from "../types"; /** diff --git a/packages/logging/src/storm-log.ts b/packages/logging/src/storm-log.ts index 28f8318d..6d39488b 100644 --- a/packages/logging/src/storm-log.ts +++ b/packages/logging/src/storm-log.ts @@ -81,12 +81,12 @@ export class StormLog implements IStormLog { protected name?: string, protected additionalLoggers: ILoggerWrapper[] = [] ) { - this.name = name ? name : config.name; + this.name = name || config.name; this.#logger = StormLog.initialize( this.config, this.name, - this.getStreams() + StormLog.getStreams() ); this.#logLevel = getLogLevel(config.logLevel); } @@ -481,7 +481,7 @@ export class StormLog implements IStormLog { * * @returns Additional log streams to use during initialization */ - protected getStreams = (): Array< + protected static getStreams = (): Array< pino.DestinationStream | pino.StreamEntry > => []; } diff --git a/packages/logging/src/types.ts b/packages/logging/src/types.ts index bc9bce6d..b26c71bd 100644 --- a/packages/logging/src/types.ts +++ b/packages/logging/src/types.ts @@ -1,5 +1,5 @@ import type { StormTime } from "@storm-stack/date-time"; -import type { MaybePromise } from "@storm-stack/utilities"; +import type { MaybePromise } from "@storm-stack/types"; import type pino from "pino"; import type { LogLevel, LogLevelLabel } from "./utilities/get-log-level"; diff --git a/packages/logging/src/utilities/get-log-level.ts b/packages/logging/src/utilities/get-log-level.ts index e73258ba..6b260e6d 100644 --- a/packages/logging/src/utilities/get-log-level.ts +++ b/packages/logging/src/utilities/get-log-level.ts @@ -35,22 +35,30 @@ export const LogLevelLabel = { */ export const getLogLevel = (label: string): LogLevel => { switch (label) { - case "trace": + case "trace": { return LogLevel.TRACE; - case "debug": + } + case "debug": { return LogLevel.DEBUG; - case "info": + } + case "info": { return LogLevel.INFO; - case "warn": + } + case "warn": { return LogLevel.WARN; - case "error": + } + case "error": { return LogLevel.ERROR; - case "fatal": + } + case "fatal": { return LogLevel.FATAL; - case "silent": + } + case "silent": { return LogLevel.SILENT; - default: + } + default: { return LogLevel.INFO; + } } }; diff --git a/packages/logging/src/utilities/get-pino-options.ts b/packages/logging/src/utilities/get-pino-options.ts index 880067e1..6474d131 100644 --- a/packages/logging/src/utilities/get-pino-options.ts +++ b/packages/logging/src/utilities/get-pino-options.ts @@ -1,6 +1,7 @@ import type { StormConfig } from "@storm-software/config"; import { isStormError } from "@storm-stack/errors"; -import { isRuntimeServer, titleCase } from "@storm-stack/utilities"; +import { titleCase } from "@storm-stack/string-fns"; +import { isRuntimeServer } from "@storm-stack/utilities"; import type { LoggerOptions as PinoLoggerOptions } from "pino"; import { LogLevel, getLogLevel } from "./get-log-level"; import { createErrorSerializer } from "./log-serializer"; @@ -24,7 +25,7 @@ export const getPinoOptions = ( const errorSerializer = createErrorSerializer(_stacktrace); const baseOptions: PinoLoggerOptions = { - name: name ? name : "Storm Software", + name: name || "Storm Software", enabled: getLogLevel(config.logLevel) > LogLevel.SILENT, level: config.logLevel, messageKey: "msg", diff --git a/packages/logging/src/utilities/log-serializer.ts b/packages/logging/src/utilities/log-serializer.ts index a245f720..8c31c993 100644 --- a/packages/logging/src/utilities/log-serializer.ts +++ b/packages/logging/src/utilities/log-serializer.ts @@ -1,6 +1,6 @@ import { StormError, getCauseFromUnknown } from "@storm-stack/errors"; import { type JsonObject, StormParser } from "@storm-stack/serialization"; -import { EMPTY_STRING } from "@storm-stack/utilities"; +import { EMPTY_STRING } from "@storm-stack/types"; import { errWithCause } from "pino-std-serializers"; export const createErrorSerializer = @@ -16,8 +16,8 @@ export const createErrorSerializer = ...StormParser.serialize(stormError as unknown as JsonObject), fullMessage: stormError.toString(stacktrace) }; - } catch (e) { - const stormError = StormError.create(e); + } catch (error_) { + const stormError = StormError.create(error_); stormError.cause = err; return errWithCause(stormError); diff --git a/packages/plugin-system/src/loader/plugin-loader.ts b/packages/plugin-system/src/loader/plugin-loader.ts index 8f6cc55f..b3902ca3 100644 --- a/packages/plugin-system/src/loader/plugin-loader.ts +++ b/packages/plugin-system/src/loader/plugin-loader.ts @@ -47,6 +47,7 @@ export abstract class PluginLoader< return this.instantiate(definition, module, definition.provider, options); }; + // eslint-disable-next-line class-methods-use-this public isValid = (module: TPluginModule): boolean => { if (!module) { return false; diff --git a/packages/plugin-system/src/manager/plugin-manager.ts b/packages/plugin-system/src/manager/plugin-manager.ts index 521e40d6..a633b270 100644 --- a/packages/plugin-system/src/manager/plugin-manager.ts +++ b/packages/plugin-system/src/manager/plugin-manager.ts @@ -8,17 +8,16 @@ import { } from "@storm-stack/file-system"; import type { IStormLog } from "@storm-stack/logging"; import { StormParser } from "@storm-stack/serialization"; +import { kebabCase, titleCase } from "@storm-stack/string-fns"; import { EMPTY_STRING, type MaybePromise, - deepMerge, isFunction, isSet, isSetObject, - isString, - kebabCase, - titleCase -} from "@storm-stack/utilities"; + isString +} from "@storm-stack/types"; +import { deepMerge } from "@storm-stack/utilities"; import { glob } from "glob"; import md5 from "md5"; import { readFile } from "node:fs/promises"; @@ -122,14 +121,14 @@ export class PluginManager< public discover = async (): Promise> => { if (this._hasDiscovered) { - return Promise.resolve(this._registry); + return this._registry; } const fileGlob = this._globExpression(); this._logger.info(`Discovering plugins using glob ${fileGlob}`); const paths = await glob(fileGlob); - await Promise.all(paths.map(this.register) ?? []); + await Promise.all(paths.map(element => this.register(element)) ?? []); this._hasDiscovered = true; return this._registry; @@ -148,7 +147,7 @@ export class PluginManager< ): Promise> => { let instance = this.getInstance(provider, options); if (instance) { - return Promise.resolve(instance); + return instance; } const definition: PluginDefinition = await this.register(provider); @@ -223,8 +222,8 @@ export class PluginManager< try { instance.loader.process(context, instance, options); - } catch (e) { - result[provider] = StormError.create(e); + } catch (error_) { + result[provider] = StormError.create(error_); } return result; @@ -251,8 +250,7 @@ export class PluginManager< hooks.push({ provider, - // biome-ignore lint/style/noNonNullAssertion: - listener: value.module.hooks?.[name]!, + listener: value.module.hooks![name]!, dependencies: plugin?.definition?.dependencies ?? [] }); } @@ -284,7 +282,7 @@ export class PluginManager< edges ) // biome-ignore lint/style/noNonNullAssertion: - .map((hook: string) => hooks.find(h => h.provider === hook)?.listener!); + .map((hook: string) => hooks.find(h => h.provider === hook)!.listener!); } let nextContext = context; @@ -343,7 +341,9 @@ export class PluginManager< } this._registry.set(provider, definition); - await Promise.all(definition.dependencies.map(this.register)); + await Promise.all( + definition.dependencies.map(element => this.register(element)) + ); return definition; }; @@ -367,6 +367,7 @@ export class PluginManager< * @param options - The options for the plugin. * @returns The cache ID. */ + // eslint-disable-next-line class-methods-use-this private _getCacheId(provider: string, options: any): string { return md5(`${provider}::${StormParser.stringify(options)}`); } diff --git a/packages/plugin-system/src/types.ts b/packages/plugin-system/src/types.ts index 43bca1aa..7de82b5e 100644 --- a/packages/plugin-system/src/types.ts +++ b/packages/plugin-system/src/types.ts @@ -1,5 +1,5 @@ import type { StormDateTime } from "@storm-stack/date-time"; -import type { MaybePromise } from "@storm-stack/utilities"; +import type { MaybePromise } from "@storm-stack/types"; export type PluginDiscoveryMode = "auto" | "fallback" | "none"; export const PluginDiscoveryMode = { diff --git a/packages/plugin-system/src/utilities/create-resolver.ts b/packages/plugin-system/src/utilities/create-resolver.ts index 6a46e55b..c7a6131f 100644 --- a/packages/plugin-system/src/utilities/create-resolver.ts +++ b/packages/plugin-system/src/utilities/create-resolver.ts @@ -1,6 +1,6 @@ import { StormError } from "@storm-stack/errors"; import { joinPaths, loadTsConfigFile } from "@storm-stack/file-system"; -import { isString } from "@storm-stack/utilities"; +import { isString } from "@storm-stack/types"; import { CachedInputFileSystem, ResolverFactory } from "enhanced-resolve"; import fs from "node:fs"; import { PluginSystemErrorCode } from "../errors"; diff --git a/packages/utilities/src/crypto/sha-1.ts b/packages/utilities/src/crypto/sha-1.ts index 25077475..d997643e 100644 --- a/packages/utilities/src/crypto/sha-1.ts +++ b/packages/utilities/src/crypto/sha-1.ts @@ -70,7 +70,6 @@ export function sha1( } for (let t = 16; t < 80; ++t) { - // biome-ignore lint/style/noNonNullAssertion: W[t] = ROTL(W[t - 3]! ^ W[t - 8]! ^ W[t - 14]! ^ W[t - 16]!, 1); } @@ -82,68 +81,42 @@ export function sha1( for (let t = 0; t < 80; ++t) { const s = Math.floor(t / 20); - // biome-ignore lint/style/noNonNullAssertion: const T = (ROTL(a, 5) + f(s, b, c, d) + e + K[s]! + W[t]!) >>> 0; e = d; d = c; - // biome-ignore lint/style/noNonNullAssertion: + c = ROTL(b!, 30) >>> 0; b = a; a = T; } - // biome-ignore lint/style/noNonNullAssertion: H[0] = (H[0]! + a!) >>> 0; - // biome-ignore lint/style/noNonNullAssertion: H[1] = (H[1]! + b!) >>> 0; - // biome-ignore lint/style/noNonNullAssertion: H[2] = (H[2]! + c!) >>> 0; - // biome-ignore lint/style/noNonNullAssertion: H[3] = (H[3]! + d!) >>> 0; - // biome-ignore lint/style/noNonNullAssertion: H[4] = (H[4]! + e!) >>> 0; } return Uint8Array.from([ - // biome-ignore lint/style/noNonNullAssertion: (H[0]! >> 24) & 0xff, - // biome-ignore lint/style/noNonNullAssertion: (H[0]! >> 16) & 0xff, - // biome-ignore lint/style/noNonNullAssertion: (H[0]! >> 8) & 0xff, - // biome-ignore lint/style/noNonNullAssertion: H[0]! & 0xff, - // biome-ignore lint/style/noNonNullAssertion: (H[1]! >> 24) & 0xff, - // biome-ignore lint/style/noNonNullAssertion: (H[1]! >> 16) & 0xff, - // biome-ignore lint/style/noNonNullAssertion: (H[1]! >> 8) & 0xff, - // biome-ignore lint/style/noNonNullAssertion: H[1]! & 0xff, - // biome-ignore lint/style/noNonNullAssertion: (H[2]! >> 24) & 0xff, - // biome-ignore lint/style/noNonNullAssertion: (H[2]! >> 16) & 0xff, - // biome-ignore lint/style/noNonNullAssertion: (H[2]! >> 8) & 0xff, - // biome-ignore lint/style/noNonNullAssertion: H[2]! & 0xff, - // biome-ignore lint/style/noNonNullAssertion: (H[3]! >> 24) & 0xff, - // biome-ignore lint/style/noNonNullAssertion: (H[3]! >> 16) & 0xff, - // biome-ignore lint/style/noNonNullAssertion: (H[3]! >> 8) & 0xff, - // biome-ignore lint/style/noNonNullAssertion: H[3]! & 0xff, - // biome-ignore lint/style/noNonNullAssertion: (H[4]! >> 24) & 0xff, - // biome-ignore lint/style/noNonNullAssertion: (H[4]! >> 16) & 0xff, - // biome-ignore lint/style/noNonNullAssertion: (H[4]! >> 8) & 0xff, - // biome-ignore lint/style/noNonNullAssertion: H[4]! & 0xff ]); } diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 080336b1..f26e332a 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -88,7 +88,7 @@ importers: version: 1.30.0 '@storm-software/eslint': specifier: latest - version: 0.29.0(gzghyuw6hxvorjtnydejldz4ba) + version: 0.30.0(gzghyuw6hxvorjtnydejldz4ba) '@storm-software/git-tools': specifier: latest version: 2.34.1(@swc-node/register@1.9.2(@swc/core@1.5.7(@swc/helpers@0.5.12))(@swc/types@0.1.12)(typescript@5.5.4))(@swc/core@1.5.7(@swc/helpers@0.5.12)) @@ -4055,8 +4055,8 @@ packages: '@storm-software/config@1.30.0': resolution: {integrity: sha512-0F2l/YQzaYkMUyhhCVOeONz+ehbbv5dyDl0ewFA6cFUOhMu0Ic4EylmtqrV2zx5gI4hWlom0KElO7ou/j/ngBg==} - '@storm-software/eslint@0.29.0': - resolution: {integrity: sha512-VRoaqYY82+zXJgsPwif+bMYw9quTB8axwmvjZb9C6gkH2RhDb8gLBVUX//UGYJugh8plFayLVI10/BWccbqQ3w==} + '@storm-software/eslint@0.30.0': + resolution: {integrity: sha512-w8ayuWGEffb4xbwuep4RLj0DIc5J25AA3cRwJkyvBZRX8+h3cEaX+69hvx3jJ0BLcNc/ieSJ0kXqY2gWy4ezxQ==} peerDependencies: '@nx/eslint': '>=18.3.0' '@nx/eslint-plugin': '>=18.3.0' @@ -19392,7 +19392,7 @@ snapshots: dependencies: zod: 3.23.8 - '@storm-software/eslint@0.29.0(gzghyuw6hxvorjtnydejldz4ba)': + '@storm-software/eslint@0.30.0(gzghyuw6hxvorjtnydejldz4ba)': dependencies: '@graphql-eslint/eslint-plugin': 3.20.1(@babel/core@7.24.9)(@types/node@20.14.12)(bufferutil@4.0.8)(graphql@15.9.0)(utf-8-validate@5.0.10) '@next/eslint-plugin-next': 14.2.4