@travetto/base
Advanced tools
Comparing version 2.2.0 to 2.2.1
import { color } from '@travetto/cli/src/color'; | ||
import { BasePlugin } from '@travetto/cli/src/plugin-base'; | ||
import { BasePlugin, OptionConfig } from '@travetto/cli/src/plugin-base'; | ||
import { BuildUtil } from './lib'; | ||
type Options = { | ||
output: OptionConfig<string>; | ||
quiet: OptionConfig<boolean>; | ||
}; | ||
/** | ||
@@ -10,3 +15,3 @@ * Command line support for building the code with the ability to | ||
*/ | ||
export class BaseBuildPlugin extends BasePlugin { | ||
export class BaseBuildPlugin extends BasePlugin<Options> { | ||
@@ -17,4 +22,3 @@ name = 'build'; | ||
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type | ||
getOptions() { | ||
getOptions(): Options { | ||
return { | ||
@@ -21,0 +25,0 @@ output: this.option({ desc: 'Output directory', completion: true }), |
import * as fs from 'fs/promises'; | ||
import { color } from '@travetto/cli/src/color'; | ||
import { BasePlugin } from '@travetto/cli/src/plugin-base'; | ||
import { BasePlugin, OptionConfig } from '@travetto/cli/src/plugin-base'; | ||
import { FileCache, PathUtil } from '@travetto/boot'; | ||
type Options = { | ||
quiet: OptionConfig<boolean>; | ||
}; | ||
/** | ||
@@ -12,3 +16,3 @@ * `npx trv clean` | ||
*/ | ||
export class BaseCleanPlugin extends BasePlugin { | ||
export class BaseCleanPlugin extends BasePlugin<Options> { | ||
@@ -19,4 +23,3 @@ name = 'clean'; | ||
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type | ||
getOptions() { | ||
getOptions(): Options { | ||
return { quiet: this.boolOption({ desc: 'Quiet operation' }) }; | ||
@@ -23,0 +26,0 @@ } |
{ | ||
"name": "@travetto/base", | ||
"displayName": "Base", | ||
"version": "2.2.0", | ||
"version": "2.2.1", | ||
"description": "Application phase management, environment config and common utilities for travetto applications.", | ||
@@ -31,6 +31,6 @@ "keywords": [ | ||
"dependencies": { | ||
"@travetto/boot": "^2.2.0" | ||
"@travetto/boot": "^2.2.1" | ||
}, | ||
"optionalPeerDependencies": { | ||
"@travetto/cli": "^2.2.0" | ||
"@travetto/cli": "^2.2.1" | ||
}, | ||
@@ -37,0 +37,0 @@ "docDependencies": { |
@@ -13,2 +13,6 @@ import { SourceUtil } from '@travetto/boot/src/internal/source-util'; | ||
function setGlobal<K extends string | symbol>(ctx: Partial<Record<K, unknown>>, key: K, val: unknown): void { | ||
ctx[key] = val; | ||
} | ||
const CONSOLE_RE = /(\bconsole[.](debug|info|warn|log|error)[(])|\n/g; | ||
@@ -51,4 +55,4 @@ | ||
constructor(public readonly key: string) { | ||
// @ts-expect-error | ||
global[this.key] = this.invoke.bind(this); | ||
setGlobal(globalThis, this.key, this.invoke.bind(this)); | ||
this.#exclude = new Set(); | ||
@@ -55,0 +59,0 @@ |
export type SerializedError = { $?: boolean, message: string, stack?: string, name: string }; | ||
function isSerialized(e: unknown): e is SerializedError { | ||
return !!e && (typeof e === 'object') && '$' in e; | ||
} | ||
/** | ||
@@ -75,4 +79,3 @@ * Mapping from error category to standard http error codes | ||
error = { $: true, name: e.name, message: '' }; | ||
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions | ||
for (const k of Object.keys(e) as ['name' | 'message']) { | ||
for (const k of Object.keys<{ name: string }>(e)) { | ||
error[k] = e[k]; | ||
@@ -97,8 +100,6 @@ } | ||
static deserializeError(e: Error | SerializedError | undefined): Error | undefined { | ||
if (e && '$' in e) { | ||
if (isSerialized(e)) { | ||
const err = new Error(); | ||
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions | ||
const keys = Object.keys(e) as ('name' | 'message')[]; | ||
for (const k of keys) { | ||
for (const k of Object.keys<{ name: string }>(e)) { | ||
err[k] = e[k]; | ||
@@ -111,6 +112,5 @@ } | ||
} else if (e) { | ||
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions | ||
return e as Error; | ||
return e; | ||
} | ||
} | ||
} |
@@ -9,2 +9,5 @@ import { StacktraceUtil } from '../stacktrace'; | ||
interface AsyncIterable<T> { toArray(): Promise<T[]> } | ||
interface ObjectConstructor { | ||
keys<T = unknown, K extends keyof T = keyof T>(o: T): K[]; | ||
} | ||
} | ||
@@ -11,0 +14,0 @@ |
import * as crypto from 'crypto'; | ||
import * as timers from 'timers/promises'; | ||
import { EnvUtil } from '@travetto/boot'; | ||
@@ -35,6 +37,2 @@ import { Class, ClassInstance } from './types'; | ||
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions | ||
static getKeys = Object.keys.bind(Object) as | ||
<K extends string | symbol | number = string, T extends object = object>(o: T) => K[]; | ||
static #deepAssignRaw(a: unknown, b: unknown, mode: 'replace' | 'loose' | 'strict' | 'coerce' = 'loose'): unknown { | ||
@@ -346,3 +344,3 @@ const isEmptyA = a === undefined || a === null; | ||
static wait(n: number | TimeSpan, unit?: TimeUnit): Promise<void> { | ||
return new Promise(res => setTimeout(res, this.timeToMs(n, unit))); | ||
return timers.setTimeout(this.timeToMs(n, unit)); | ||
} | ||
@@ -349,0 +347,0 @@ |
1657
67858
Updated@travetto/boot@^2.2.1