style: fix

This commit is contained in:
Zoltan Kochan
2023-01-11 01:42:05 +02:00
parent 5bac26658f
commit 0055af5898
21 changed files with 116 additions and 61 deletions

View File

@@ -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",

View File

@@ -36,7 +36,9 @@ export function initDefaultReporter (
// eslint-disable-next-line
const log$ = Rx.fromEvent<logs.Log>(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$ (

View File

@@ -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
}
}

View File

@@ -43,7 +43,9 @@ export async function buildModules (
hoistedLocations?: Record<string, string[]>
}
) {
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 }

View File

@@ -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,

View File

@@ -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]

View File

@@ -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,
})
},
}
}

View File

@@ -17,7 +17,11 @@ import { getWantedLockfileName } from './lockfileName'
import { convertToInlineSpecifiersFormat } from './experiments/inlineSpecifiersLockfileConverters'
async function writeFileAtomic (filename: string, data: string) {
return new Promise<void>((resolve, reject) => writeFileAtomicCB(filename, data, {}, (err?: Error) => (err != null) ? reject(err) : resolve()))
return new Promise<void>((resolve, reject) => {
writeFileAtomicCB(filename, data, {}, (err?: Error) => {
(err != null) ? reject(err) : resolve()
})
})
}
const LOCKFILE_YAML_FORMAT = {

View File

@@ -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

View File

@@ -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<string, DependenciesGraphNode>(result.newDepPaths, dependenciesGraph)
await linkAllBins(newPkgs, dependenciesGraph, {

View File

@@ -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

View File

@@ -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,

View File

@@ -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(

View File

@@ -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 () {

View File

@@ -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,

View File

@@ -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)
})
}

View File

@@ -49,7 +49,7 @@ export async function fromRegistry (
): Promise<PackageMeta> {
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) {

View File

@@ -27,7 +27,9 @@ const brokenIntegrity = loadJsonFile.sync<any>(f.find('broken-integrity.json'))
const registry = 'https://registry.npmjs.org/'
const delay = async (time: number) => new Promise<void>((resolve) => setTimeout(() => resolve(), time))
const delay = async (time: number) => new Promise<void>((resolve) => setTimeout(() => {
resolve()
}, time))
const fetch = createFetchFromRegistry({})
const getAuthHeader = () => undefined

View File

@@ -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

View File

@@ -19,6 +19,8 @@ export function parseJsonStream (
deferred: DeferredManifestPromise
) {
stream.pipe(
concatStream((buffer) => parseJsonBuffer(buffer, deferred))
concatStream((buffer) => {
parseJsonBuffer(buffer, deferred)
})
)
}

View File

@@ -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,