fix: types

This commit is contained in:
Zoltan Kochan
2020-11-22 23:06:38 +02:00
parent 26118a730a
commit fba7155123
7 changed files with 27 additions and 22 deletions

View File

@@ -0,0 +1,5 @@
---
"@pnpm/lockfile-file": patch
---
writeLockfiles should return Promise<void>.

View File

@@ -23,5 +23,5 @@ async function removeModules () {
}
function rimraf (dir: string) {
return new Promise((resolve, reject) => rimrafModule(dir, err => err ? reject(err) : resolve()))
return new Promise<void>((resolve, reject) => rimrafModule(dir, err => err ? reject(err) : resolve()))
}

View File

@@ -143,7 +143,7 @@ function normalizeLockfile (lockfile: Lockfile, forceSharedFormat: boolean) {
}
}
export default function writeLockfiles (
export default async function writeLockfiles (
opts: {
forceSharedFormat?: boolean
wantedLockfile: Lockfile
@@ -157,10 +157,11 @@ export default function writeLockfiles (
// empty lockfile is not saved
if (isEmptyLockfile(opts.wantedLockfile)) {
return Promise.all([
await Promise.all([
rimraf(wantedLockfilePath),
rimraf(currentLockfilePath),
])
return
}
const forceSharedFormat = opts?.forceSharedFormat === true
@@ -170,13 +171,14 @@ export default function writeLockfiles (
// in those cases the YAML document can be stringified only once for both files
// which is more efficient
if (opts.wantedLockfile === opts.currentLockfile) {
return Promise.all([
await Promise.all([
writeFileAtomic(wantedLockfilePath, yamlDoc),
(async () => {
await fs.mkdir(path.dirname(currentLockfilePath), { recursive: true })
await writeFileAtomic(currentLockfilePath, yamlDoc)
})(),
])
return
}
logger.debug({
@@ -186,7 +188,7 @@ export default function writeLockfiles (
const currentYamlDoc = yamlStringify(opts.currentLockfile, forceSharedFormat)
return Promise.all([
await Promise.all([
writeFileAtomic(wantedLockfilePath, yamlDoc),
(async () => {
await fs.mkdir(path.dirname(currentLockfilePath), { recursive: true })

View File

@@ -5,9 +5,9 @@ export async function add (pkg: string, version: string, distTag: string) {
const client = new RegClient()
// just to make verdaccio cache the package
await new Promise((resolve, reject) => client.distTags.fetch(`http://localhost:${REGISTRY_MOCK_PORT}`, { package: pkg }, (err: Error) => err ? reject(err) : resolve()))
await new Promise<void>((resolve, reject) => client.distTags.fetch(`http://localhost:${REGISTRY_MOCK_PORT}`, { package: pkg }, (err: Error) => err ? reject(err) : resolve()))
// the tag has to be removed first because in verdaccio it is an array of versions
await new Promise((resolve, reject) => client.distTags.rm(`http://localhost:${REGISTRY_MOCK_PORT}`, { package: pkg, distTag }, (err: Error) => err ? reject(err) : resolve()))
await new Promise((resolve, reject) => client.distTags.add(`http://localhost:${REGISTRY_MOCK_PORT}`, { package: pkg, version, distTag }, (err: Error) => err ? reject(err) : resolve()))
await new Promise<void>((resolve, reject) => client.distTags.rm(`http://localhost:${REGISTRY_MOCK_PORT}`, { package: pkg, distTag }, (err: Error) => err ? reject(err) : resolve()))
await new Promise<void>((resolve, reject) => client.distTags.add(`http://localhost:${REGISTRY_MOCK_PORT}`, { package: pkg, version, distTag }, (err: Error) => err ? reject(err) : resolve()))
}

View File

@@ -13,7 +13,7 @@ export async function execPnpm (
env: Object
}
): Promise<void> {
await new Promise((resolve, reject) => {
await new Promise<void>((resolve, reject) => {
const proc = spawnPnpm(args, opts)
proc.on('error', reject)
@@ -42,7 +42,7 @@ export function spawnPnpm (
}
export async function execPnpx (args: string[]): Promise<void> {
await new Promise((resolve, reject) => {
await new Promise<void>((resolve, reject) => {
const proc = spawnPnpx(args)
proc.on('error', reject)

View File

@@ -832,15 +832,13 @@ async function installInContext (
await Promise.all([
opts.useLockfile
? (async () => {
await writeLockfiles({
currentLockfile: result.currentLockfile,
currentLockfileDir: ctx.virtualStoreDir,
wantedLockfile: newLockfile,
wantedLockfileDir: ctx.lockfileDir,
...lockfileOpts,
})
})()
? writeLockfiles({
currentLockfile: result.currentLockfile,
currentLockfileDir: ctx.virtualStoreDir,
wantedLockfile: newLockfile,
wantedLockfileDir: ctx.lockfileDir,
...lockfileOpts,
})
: writeCurrentLockfile(ctx.virtualStoreDir, result.currentLockfile, lockfileOpts),
(() => {
if (result.currentLockfile.packages === undefined && result.removedDepPaths.size === 0) {

View File

@@ -5,9 +5,9 @@ export async function add (packageName: string, version: string, distTag: string
const client = new RegClient()
// just to make verdaccio cache the package
await new Promise((resolve, reject) => client.distTags.fetch(`http://localhost:${REGISTRY_MOCK_PORT}`, { package: packageName }, (err?: Error) => err != null ? reject(err) : resolve()))
await new Promise<void>((resolve, reject) => client.distTags.fetch(`http://localhost:${REGISTRY_MOCK_PORT}`, { package: packageName }, (err?: Error) => err != null ? reject(err) : resolve()))
// the tag has to be removed first because in verdaccio it is an array of versions
await new Promise((resolve, reject) => client.distTags.rm(`http://localhost:${REGISTRY_MOCK_PORT}`, { package: packageName, distTag }, (err?: Error) => err != null ? reject(err) : resolve()))
await new Promise((resolve, reject) => client.distTags.add(`http://localhost:${REGISTRY_MOCK_PORT}`, { package: packageName, version, distTag }, (err?: Error) => err != null ? reject(err) : resolve()))
await new Promise<void>((resolve, reject) => client.distTags.rm(`http://localhost:${REGISTRY_MOCK_PORT}`, { package: packageName, distTag }, (err?: Error) => err != null ? reject(err) : resolve()))
await new Promise<void>((resolve, reject) => client.distTags.add(`http://localhost:${REGISTRY_MOCK_PORT}`, { package: packageName, version, distTag }, (err?: Error) => err != null ? reject(err) : resolve()))
}