From 0055af58988198bdfbfba1bea836b06947ab49f0 Mon Sep 17 00:00:00 2001 From: Zoltan Kochan Date: Wed, 11 Jan 2023 01:42:05 +0200 Subject: [PATCH] style: fix --- __utils__/eslint-config/eslint.json | 1 + cli/default-reporter/src/index.ts | 20 +++++-- .../src/reporterForClient/reportMisc.ts | 8 ++- exec/build-modules/src/index.ts | 4 +- exec/lifecycle/src/runLifecycleHook.ts | 4 +- .../src/implementation/index.ts | 4 +- hooks/pnpmfile/src/requireHooks.ts | 14 +++-- lockfile/lockfile-file/src/write.ts | 6 +- network/fetch/src/fetch.ts | 60 ++++++++++--------- pkg-manager/core/src/install/index.ts | 4 +- pkg-manager/core/src/link/index.ts | 4 +- pkg-manager/headless/src/index.ts | 4 +- .../package-requester/src/packageRequester.ts | 8 ++- .../plugin-commands-installation/test/link.ts | 8 ++- .../src/updateLockfile.ts | 4 +- .../plugin-commands-publishing/src/pack.ts | 4 +- resolving/npm-resolver/src/fetch.ts | 4 +- resolving/npm-resolver/test/index.ts | 4 +- store/cafs/src/addFilesFromTarball.ts | 4 +- store/cafs/src/parseJson.ts | 4 +- .../plugin-commands-store/test/storePrune.ts | 4 +- 21 files changed, 116 insertions(+), 61 deletions(-) diff --git a/__utils__/eslint-config/eslint.json b/__utils__/eslint-config/eslint.json index 59d2ca1cbc..c5e758b838 100644 --- a/__utils__/eslint-config/eslint.json +++ b/__utils__/eslint-config/eslint.json @@ -28,6 +28,7 @@ } } ], + "@typescript-eslint/consistent-indexed-object-style": "off", "@typescript-eslint/naming-convention": "error", "@typescript-eslint/explicit-function-return-type": "off", "@typescript-eslint/no-explicit-any": "error", diff --git a/cli/default-reporter/src/index.ts b/cli/default-reporter/src/index.ts index a292f34dce..ca5cc645b7 100644 --- a/cli/default-reporter/src/index.ts +++ b/cli/default-reporter/src/index.ts @@ -36,7 +36,9 @@ export function initDefaultReporter ( // eslint-disable-next-line const log$ = Rx.fromEvent(opts.streamParser as any, 'data') const subscription = reporterForServer(log$, opts.context.config) - return () => subscription.unsubscribe() + return () => { + subscription.unsubscribe() + } } const outputMaxWidth = opts.reportingOptions?.outputMaxWidth ?? (process.stdout.columns && process.stdout.columns - 2) ?? 80 const output$ = toOutput$({ @@ -53,10 +55,14 @@ export function initDefaultReporter ( const subscription = output$ .subscribe({ complete () {}, // eslint-disable-line:no-empty - error: (err) => console.error(err.message), + error: (err) => { + console.error(err.message) + }, next: writeNext, }) - return () => subscription.unsubscribe() + return () => { + subscription.unsubscribe() + } } const diff = createDiffer({ height: process.stdout.rows, @@ -65,7 +71,9 @@ export function initDefaultReporter ( const subscription = output$ .subscribe({ complete () {}, // eslint-disable-line:no-empty - error: (err) => logUpdate(err.message), + error: (err) => { + logUpdate(err.message) + }, next: logUpdate, }) const write = opts.useStderr @@ -78,7 +86,9 @@ export function initDefaultReporter ( if (!view.endsWith(EOL)) view += EOL write(diff.update(view)) } - return () => subscription.unsubscribe() + return () => { + subscription.unsubscribe() + } } export function toOutput$ ( diff --git a/cli/default-reporter/src/reporterForClient/reportMisc.ts b/cli/default-reporter/src/reporterForClient/reportMisc.ts index d6630e91d3..3a6b9bd1f1 100644 --- a/cli/default-reporter/src/reporterForClient/reportMisc.ts +++ b/cli/default-reporter/src/reporterForClient/reportMisc.ts @@ -79,10 +79,14 @@ function makeWarningReporter ( collapsedWarnings = new Rx.Subject() // For some reason, without using setTimeout, the warning summary is printed above the rest of the warnings // Even though the summary event happens last. Probably a bug in "most". - setTimeout(() => collapsedWarnings.next({ msg: warningMsg }), 0) + setTimeout(() => { + collapsedWarnings.next({ msg: warningMsg }) + }, 0) return Rx.from(collapsedWarnings) } - setTimeout(() => collapsedWarnings!.next({ msg: warningMsg }), 0) + setTimeout(() => { + collapsedWarnings!.next({ msg: warningMsg }) + }, 0) return Rx.NEVER } } diff --git a/exec/build-modules/src/index.ts b/exec/build-modules/src/index.ts index 980b50ce61..8c7a7d6410 100644 --- a/exec/build-modules/src/index.ts +++ b/exec/build-modules/src/index.ts @@ -43,7 +43,9 @@ export async function buildModules ( hoistedLocations?: Record } ) { - const warn = (message: string) => logger.warn({ message, prefix: opts.lockfileDir }) + const warn = (message: string) => { + logger.warn({ message, prefix: opts.lockfileDir }) + } // postinstall hooks const buildDepOpts = { ...opts, warn } diff --git a/exec/lifecycle/src/runLifecycleHook.ts b/exec/lifecycle/src/runLifecycleHook.ts index e24a0ecc90..40b97421ed 100644 --- a/exec/lifecycle/src/runLifecycleHook.ts +++ b/exec/lifecycle/src/runLifecycleHook.ts @@ -78,7 +78,9 @@ export async function runLifecycleHook ( showProgress: noop, silly: npmLog, verbose: npmLog, - warn: (...msg: string[]) => globalWarn(msg.join(' ')), + warn: (...msg: string[]) => { + globalWarn(msg.join(' ')) + }, }, runConcurrently: true, scriptsPrependNodePath: opts.scriptsPrependNodePath, diff --git a/exec/plugin-commands-rebuild/src/implementation/index.ts b/exec/plugin-commands-rebuild/src/implementation/index.ts index 9c7f8e1bb4..ad48f7c249 100644 --- a/exec/plugin-commands-rebuild/src/implementation/index.ts +++ b/exec/plugin-commands-rebuild/src/implementation/index.ts @@ -269,7 +269,9 @@ async function _rebuild ( groups: [nodesToBuildAndTransitiveArray], }) const chunks = graphSequencerResult.chunks as string[][] - const warn = (message: string) => logger.info({ message, prefix: opts.dir }) + const warn = (message: string) => { + logger.info({ message, prefix: opts.dir }) + } const groups = chunks.map((chunk) => chunk.filter((depPath) => ctx.pkgsToRebuild.has(depPath)).map((depPath) => async () => { const pkgSnapshot = pkgSnapshots[depPath] diff --git a/hooks/pnpmfile/src/requireHooks.ts b/hooks/pnpmfile/src/requireHooks.ts index 695593b5b0..6c0a833b70 100644 --- a/hooks/pnpmfile/src/requireHooks.ts +++ b/hooks/pnpmfile/src/requireHooks.ts @@ -96,12 +96,14 @@ export function requireHooks ( function createReadPackageHookContext (calledFrom: string, prefix: string, hook: string): HookContext { return { - log: (message: string) => hookLogger.debug({ - from: calledFrom, - hook, - message, - prefix, - }), + log: (message: string) => { + hookLogger.debug({ + from: calledFrom, + hook, + message, + prefix, + }) + }, } } diff --git a/lockfile/lockfile-file/src/write.ts b/lockfile/lockfile-file/src/write.ts index 9b1e145e1f..81cb9c5410 100644 --- a/lockfile/lockfile-file/src/write.ts +++ b/lockfile/lockfile-file/src/write.ts @@ -17,7 +17,11 @@ import { getWantedLockfileName } from './lockfileName' import { convertToInlineSpecifiersFormat } from './experiments/inlineSpecifiersLockfileConverters' async function writeFileAtomic (filename: string, data: string) { - return new Promise((resolve, reject) => writeFileAtomicCB(filename, data, {}, (err?: Error) => (err != null) ? reject(err) : resolve())) + return new Promise((resolve, reject) => { + writeFileAtomicCB(filename, data, {}, (err?: Error) => { + (err != null) ? reject(err) : resolve() + }) + }) } const LOCKFILE_YAML_FORMAT = { diff --git a/network/fetch/src/fetch.ts b/network/fetch/src/fetch.ts index 4f136f2fd8..ff527ee7a4 100644 --- a/network/fetch/src/fetch.ts +++ b/network/fetch/src/fetch.ts @@ -35,36 +35,38 @@ export async function fetch (url: RequestInfo, opts: RequestInit = {}): Promise< }) try { - return await new Promise((resolve, reject) => op.attempt(async (attempt) => { - try { - // this will be retried - const res = await nodeFetch(url as any, opts) // eslint-disable-line - // A retry on 409 sometimes helps when making requests to the Bit registry. - if ((res.status >= 500 && res.status < 600) || [408, 409, 420, 429].includes(res.status)) { - throw new ResponseError(res) - } else { - resolve(res) - return + return await new Promise((resolve, reject) => { + op.attempt(async (attempt) => { + try { + // this will be retried + const res = await nodeFetch(url as any, opts) // eslint-disable-line + // A retry on 409 sometimes helps when making requests to the Bit registry. + if ((res.status >= 500 && res.status < 600) || [408, 409, 420, 429].includes(res.status)) { + throw new ResponseError(res) + } else { + resolve(res) + return + } + } catch (error: any) { // eslint-disable-line + if (error.code && NO_RETRY_ERROR_CODES.has(error.code)) { + throw error + } + const timeout = op.retry(error) + if (timeout === false) { + reject(op.mainError()) + return + } + requestRetryLogger.debug({ + attempt, + error, + maxRetries, + method: opts.method ?? 'GET', + timeout, + url: url.toString(), + }) } - } catch (error: any) { // eslint-disable-line - if (error.code && NO_RETRY_ERROR_CODES.has(error.code)) { - throw error - } - const timeout = op.retry(error) - if (timeout === false) { - reject(op.mainError()) - return - } - requestRetryLogger.debug({ - attempt, - error, - maxRetries, - method: opts.method ?? 'GET', - timeout, - url: url.toString(), - }) - } - })) + }) + }) } catch (err) { if (err instanceof ResponseError) { return err.res diff --git a/pkg-manager/core/src/install/index.ts b/pkg-manager/core/src/install/index.ts index ea7b9b481a..83fed7785b 100644 --- a/pkg-manager/core/src/install/index.ts +++ b/pkg-manager/core/src/install/index.ts @@ -996,7 +996,9 @@ const _installInContext: InstallFunction = async (projects, ctx, opts) => { } } - const binWarn = (prefix: string, message: string) => logger.info({ message, prefix }) + const binWarn = (prefix: string, message: string) => { + logger.info({ message, prefix }) + } if (result.newDepPaths?.length) { const newPkgs = props(result.newDepPaths, dependenciesGraph) await linkAllBins(newPkgs, dependenciesGraph, { diff --git a/pkg-manager/core/src/link/index.ts b/pkg-manager/core/src/link/index.ts index 47fb045378..5f3e192a8a 100644 --- a/pkg-manager/core/src/link/index.ts +++ b/pkg-manager/core/src/link/index.ts @@ -103,7 +103,9 @@ export async function link ( const updatedCurrentLockfile = pruneSharedLockfile(ctx.currentLockfile) - const warn = (message: string) => logger.warn({ message, prefix: opts.dir }) + const warn = (message: string) => { + logger.warn({ message, prefix: opts.dir }) + } const updatedWantedLockfile = pruneSharedLockfile(ctx.wantedLockfile, { warn }) // Linking should happen after removing orphans diff --git a/pkg-manager/headless/src/index.ts b/pkg-manager/headless/src/index.ts index 0d670cca9a..db21fc913d 100644 --- a/pkg-manager/headless/src/index.ts +++ b/pkg-manager/headless/src/index.ts @@ -622,7 +622,9 @@ async function linkBinsOfImporter ( }, { extraNodePaths, preferSymlinkedExecutables }: { extraNodePaths?: string[], preferSymlinkedExecutables?: boolean } = {} ) { - const warn = (message: string) => logger.info({ message, prefix: rootDir }) + const warn = (message: string) => { + logger.info({ message, prefix: rootDir }) + } return linkBins(modulesDir, binsDir, { extraNodePaths, allowExoticManifests: true, diff --git a/pkg-manager/package-requester/src/packageRequester.ts b/pkg-manager/package-requester/src/packageRequester.ts index d1be0044ed..bb2496c2ec 100644 --- a/pkg-manager/package-requester/src/packageRequester.ts +++ b/pkg-manager/package-requester/src/packageRequester.ts @@ -505,7 +505,9 @@ Actual package in the store by the given integrity: ${pkgFilesIndex.name}@${pkgF }) if (manifest != null) { manifest() - .then((manifest) => bundledManifest.resolve(manifest == null ? manifest : normalizeBundledManifest(manifest))) + .then((manifest) => { + bundledManifest.resolve(manifest == null ? manifest : normalizeBundledManifest(manifest)) + }) .catch(bundledManifest.reject) } finishing.resolve(undefined) @@ -532,7 +534,9 @@ Actual package in the store by the given integrity: ${pkgFilesIndex.name}@${pkgF : undefined if (fetchManifest != null) { fetchManifest() - .then((manifest) => bundledManifest.resolve(manifest == null ? manifest : normalizeBundledManifest(manifest))) + .then((manifest) => { + bundledManifest.resolve(manifest == null ? manifest : normalizeBundledManifest(manifest)) + }) .catch(bundledManifest.reject) } const fetchedPackage = await ctx.requestsQueue.add(async () => ctx.fetch( diff --git a/pkg-manager/plugin-commands-installation/test/link.ts b/pkg-manager/plugin-commands-installation/test/link.ts index 4176f85d2a..2a924732c6 100644 --- a/pkg-manager/plugin-commands-installation/test/link.ts +++ b/pkg-manager/plugin-commands-installation/test/link.ts @@ -72,7 +72,9 @@ test('link global bin', async function () { }) process.env[PATH] = oldPath - await isExecutable((value) => expect(value).toBeTruthy(), path.join(globalBin, 'package-with-bin')) + await isExecutable((value) => { + expect(value).toBeTruthy() + }, path.join(globalBin, 'package-with-bin')) }) test('link to global bin from the specified directory', async function () { @@ -99,7 +101,9 @@ test('link to global bin from the specified directory', async function () { }) process.env[PATH] = oldPath - await isExecutable((value) => expect(value).toBeTruthy(), path.join(globalBin, 'package-with-bin-in-dir')) + await isExecutable((value) => { + expect(value).toBeTruthy() + }, path.join(globalBin, 'package-with-bin-in-dir')) }) test('link a global package to the specified directory', async function () { diff --git a/pkg-manager/resolve-dependencies/src/updateLockfile.ts b/pkg-manager/resolve-dependencies/src/updateLockfile.ts index a232ff736e..2d17e1745e 100644 --- a/pkg-manager/resolve-dependencies/src/updateLockfile.ts +++ b/pkg-manager/resolve-dependencies/src/updateLockfile.ts @@ -48,7 +48,9 @@ export function updateLockfile ( lockfileIncludeTarballUrl, }) } - const warn = (message: string) => logger.warn({ message, prefix }) + const warn = (message: string) => { + logger.warn({ message, prefix }) + } return { newLockfile: pruneSharedLockfile(lockfile, { warn }), pendingRequiresBuilds, diff --git a/releasing/plugin-commands-publishing/src/pack.ts b/releasing/plugin-commands-publishing/src/pack.ts index 0acd8c59bd..1437e4465c 100644 --- a/releasing/plugin-commands-publishing/src/pack.ts +++ b/releasing/plugin-commands-publishing/src/pack.ts @@ -165,6 +165,8 @@ async function packPkg (opts: { pack.pipe(createGzip()).pipe(tarball) pack.finalize() return new Promise((resolve, reject) => { - tarball.on('close', () => resolve()).on('error', reject) + tarball.on('close', () => { + resolve() + }).on('error', reject) }) } diff --git a/resolving/npm-resolver/src/fetch.ts b/resolving/npm-resolver/src/fetch.ts index 5acf2cfdc3..7390211d69 100644 --- a/resolving/npm-resolver/src/fetch.ts +++ b/resolving/npm-resolver/src/fetch.ts @@ -49,7 +49,7 @@ export async function fromRegistry ( ): Promise { const uri = toUri(pkgName, registry) const op = retry.operation(fetchOpts.retry) - return new Promise((resolve, reject) => + return new Promise((resolve, reject) => { op.attempt(async (attempt) => { let response: RegistryResponse try { @@ -94,7 +94,7 @@ export async function fromRegistry ( }) } }) - ) + }) } function toUri (pkgName: string, registry: string) { diff --git a/resolving/npm-resolver/test/index.ts b/resolving/npm-resolver/test/index.ts index 4c8eec7b8d..dc0dc3879d 100644 --- a/resolving/npm-resolver/test/index.ts +++ b/resolving/npm-resolver/test/index.ts @@ -27,7 +27,9 @@ const brokenIntegrity = loadJsonFile.sync(f.find('broken-integrity.json')) const registry = 'https://registry.npmjs.org/' -const delay = async (time: number) => new Promise((resolve) => setTimeout(() => resolve(), time)) +const delay = async (time: number) => new Promise((resolve) => setTimeout(() => { + resolve() +}, time)) const fetch = createFetchFromRegistry({}) const getAuthHeader = () => undefined diff --git a/store/cafs/src/addFilesFromTarball.ts b/store/cafs/src/addFilesFromTarball.ts index fa68d5d645..0256904fa2 100644 --- a/store/cafs/src/addFilesFromTarball.ts +++ b/store/cafs/src/addFilesFromTarball.ts @@ -38,7 +38,9 @@ export async function addFilesFromTarball ( next() }) // listener - extract.on('finish', () => resolve()) + extract.on('finish', () => { + resolve() + }) extract.on('error', reject) // pipe through extractor diff --git a/store/cafs/src/parseJson.ts b/store/cafs/src/parseJson.ts index d04ab13543..cc45e4dcac 100644 --- a/store/cafs/src/parseJson.ts +++ b/store/cafs/src/parseJson.ts @@ -19,6 +19,8 @@ export function parseJsonStream ( deferred: DeferredManifestPromise ) { stream.pipe( - concatStream((buffer) => parseJsonBuffer(buffer, deferred)) + concatStream((buffer) => { + parseJsonBuffer(buffer, deferred) + }) ) } diff --git a/store/plugin-commands-store/test/storePrune.ts b/store/plugin-commands-store/test/storePrune.ts index d45e08205d..8e45fb2bdb 100644 --- a/store/plugin-commands-store/test/storePrune.ts +++ b/store/plugin-commands-store/test/storePrune.ts @@ -139,7 +139,9 @@ test('keep dependencies used by others', async () => { const lockfile = await project.readLockfile() as Lockfile expect(isEmpty(lockfile.packages)).toBeFalsy() - Object.entries(lockfile.packages ?? {}).forEach(([depPath, dep]) => expect(dep.dev).toBeTruthy()) + Object.entries(lockfile.packages ?? {}).forEach(([_, dep]) => { + expect(dep.dev).toBeTruthy() + }) await store.handler({ cacheDir,