refactor: rename, async main
This commit is contained in:
parent
2d0c631223
commit
d3b4dae910
3 changed files with 17 additions and 16 deletions
|
@ -3,7 +3,7 @@ import { tmpdir } from 'os'
|
|||
import { join, resolve } from 'path'
|
||||
|
||||
import type { Report } from '../index.d'
|
||||
import runPackwatch from '..'
|
||||
import packwatch from '..'
|
||||
|
||||
async function prepareWorkspace(): Promise<string> {
|
||||
const workspacePath = await fs.mkdtemp(`${tmpdir()}/`, { recursive: true })
|
||||
|
@ -53,7 +53,7 @@ describe('Packwatch', () => {
|
|||
|
||||
it('warns the user and errors if run away from package.json', async () => {
|
||||
workspacePath = await prepareWorkspace()
|
||||
runPackwatch({ cwd: workspacePath })
|
||||
await packwatch({ cwd: workspacePath })
|
||||
|
||||
expect(mockLogger.mock.calls).toHaveLength(1)
|
||||
expect(mockLogger.mock.calls[0][0]).toEqual(
|
||||
|
@ -68,7 +68,7 @@ describe('Packwatch', () => {
|
|||
workspacePath = await prepareWorkspace()
|
||||
await createPackageJson(workspacePath)
|
||||
|
||||
runPackwatch({ cwd: workspacePath })
|
||||
await packwatch({ cwd: workspacePath })
|
||||
|
||||
const generatedManifest = await fs.readFile(
|
||||
resolve(join(workspacePath, '.packwatch.json')),
|
||||
|
@ -84,7 +84,7 @@ describe('Packwatch', () => {
|
|||
workspacePath = await prepareWorkspace()
|
||||
await createPackageJson(workspacePath)
|
||||
|
||||
runPackwatch({ cwd: workspacePath })
|
||||
await packwatch({ cwd: workspacePath })
|
||||
|
||||
expect(mockLogger.mock.calls).toHaveLength(2)
|
||||
expect(mockLogger.mock.calls[0][0]).toEqual(
|
||||
|
@ -104,7 +104,7 @@ describe('Packwatch', () => {
|
|||
|
||||
await createPackageJson(workspacePath)
|
||||
|
||||
runPackwatch({ cwd: workspacePath, isUpdatingManifest: true })
|
||||
await packwatch({ cwd: workspacePath, isUpdatingManifest: true })
|
||||
|
||||
expect(mockLogger.mock.calls).toHaveLength(1)
|
||||
expect(mockLogger.mock.calls[0][0]).toEqual(
|
||||
|
@ -125,7 +125,7 @@ describe('Packwatch', () => {
|
|||
packageSize: '160B',
|
||||
unpackedSize: '150B',
|
||||
})
|
||||
runPackwatch({ cwd: workspacePath })
|
||||
await packwatch({ cwd: workspacePath })
|
||||
expect(mockLogger.mock.calls).toHaveLength(1)
|
||||
expect(mockLogger.mock.calls[0][0]).toEqual(
|
||||
expect.stringMatching(
|
||||
|
@ -144,7 +144,7 @@ describe('Packwatch', () => {
|
|||
unpackedSize: '150B',
|
||||
})
|
||||
|
||||
runPackwatch({ cwd: workspacePath })
|
||||
await packwatch({ cwd: workspacePath })
|
||||
expect(mockLogger.mock.calls).toHaveLength(1)
|
||||
expect(mockLogger.mock.calls[0][0]).toEqual(
|
||||
expect.stringMatching(
|
||||
|
@ -162,7 +162,7 @@ describe('Packwatch', () => {
|
|||
unpackedSize: '140B',
|
||||
})
|
||||
|
||||
runPackwatch({ cwd: workspacePath })
|
||||
await packwatch({ cwd: workspacePath })
|
||||
expect(mockLogger.mock.calls).toHaveLength(1)
|
||||
expect(mockLogger.mock.calls[0][0]).toEqual(
|
||||
expect.stringMatching(
|
||||
|
@ -180,7 +180,7 @@ describe('Packwatch', () => {
|
|||
unpackedSize: '140B',
|
||||
})
|
||||
|
||||
runPackwatch({ cwd: workspacePath })
|
||||
await packwatch({ cwd: workspacePath })
|
||||
expect(mockLogger.mock.calls).toHaveLength(1)
|
||||
expect(mockLogger.mock.calls[0][0]).toEqual(
|
||||
expect.stringMatching(
|
||||
|
@ -198,7 +198,7 @@ describe('Packwatch', () => {
|
|||
unpackedSize: '140B',
|
||||
})
|
||||
|
||||
runPackwatch({ cwd: workspacePath })
|
||||
await packwatch({ cwd: workspacePath })
|
||||
expect(mockLogger.mock.calls).toHaveLength(1)
|
||||
expect(mockLogger.mock.calls[0][0]).toEqual(
|
||||
expect.stringMatching(
|
||||
|
@ -217,7 +217,7 @@ describe('Packwatch', () => {
|
|||
unpackedSize: '140B',
|
||||
})
|
||||
|
||||
runPackwatch({ cwd: workspacePath, isUpdatingManifest: true })
|
||||
await packwatch({ cwd: workspacePath, isUpdatingManifest: true })
|
||||
expect(mockLogger.mock.calls).toHaveLength(1)
|
||||
expect(mockLogger.mock.calls[0][0]).toEqual(
|
||||
expect.stringMatching(
|
||||
|
|
|
@ -1,8 +1,9 @@
|
|||
#!/usr/bin/env node
|
||||
|
||||
import runPackwatch from '.'
|
||||
import packwatch from '.'
|
||||
|
||||
const isUpdatingManifest = process.argv.includes('--update-manifest')
|
||||
const cwd = process.cwd()
|
||||
const processExit = runPackwatch({ cwd, isUpdatingManifest })
|
||||
process.exit(processExit)
|
||||
packwatch({ cwd, isUpdatingManifest })
|
||||
.catch(() => process.exit(1))
|
||||
.then(() => process.exit(0))
|
||||
|
|
|
@ -9,13 +9,13 @@ import {
|
|||
|
||||
const MANIFEST_FILENAME = '.packwatch.json'
|
||||
|
||||
export default function run({
|
||||
export default async function packwatch({
|
||||
cwd,
|
||||
isUpdatingManifest,
|
||||
}: {
|
||||
cwd?: string
|
||||
isUpdatingManifest?: boolean
|
||||
}): number {
|
||||
}): Promise<void> {
|
||||
const packageJsonPath = resolve(join(cwd, 'package.json'))
|
||||
const manifestPath = resolve(join(cwd, MANIFEST_FILENAME))
|
||||
|
||||
|
|
Reference in a new issue