refactor: more cleanup #164

Merged
mcataford merged 11 commits from more-refactor into master 2021-03-19 20:49:27 +00:00
3 changed files with 17 additions and 16 deletions
Showing only changes of commit d3b4dae910 - Show all commits

View file

@ -3,7 +3,7 @@ import { tmpdir } from 'os'
import { join, resolve } from 'path' import { join, resolve } from 'path'
import type { Report } from '../index.d' import type { Report } from '../index.d'
import runPackwatch from '..' import packwatch from '..'
async function prepareWorkspace(): Promise<string> { async function prepareWorkspace(): Promise<string> {
const workspacePath = await fs.mkdtemp(`${tmpdir()}/`, { recursive: true }) 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 () => { it('warns the user and errors if run away from package.json', async () => {
workspacePath = await prepareWorkspace() workspacePath = await prepareWorkspace()
runPackwatch({ cwd: workspacePath }) await packwatch({ cwd: workspacePath })
expect(mockLogger.mock.calls).toHaveLength(1) expect(mockLogger.mock.calls).toHaveLength(1)
expect(mockLogger.mock.calls[0][0]).toEqual( expect(mockLogger.mock.calls[0][0]).toEqual(
@ -68,7 +68,7 @@ describe('Packwatch', () => {
workspacePath = await prepareWorkspace() workspacePath = await prepareWorkspace()
await createPackageJson(workspacePath) await createPackageJson(workspacePath)
runPackwatch({ cwd: workspacePath }) await packwatch({ cwd: workspacePath })
const generatedManifest = await fs.readFile( const generatedManifest = await fs.readFile(
resolve(join(workspacePath, '.packwatch.json')), resolve(join(workspacePath, '.packwatch.json')),
@ -84,7 +84,7 @@ describe('Packwatch', () => {
workspacePath = await prepareWorkspace() workspacePath = await prepareWorkspace()
await createPackageJson(workspacePath) await createPackageJson(workspacePath)
runPackwatch({ cwd: workspacePath }) await packwatch({ cwd: workspacePath })
expect(mockLogger.mock.calls).toHaveLength(2) expect(mockLogger.mock.calls).toHaveLength(2)
expect(mockLogger.mock.calls[0][0]).toEqual( expect(mockLogger.mock.calls[0][0]).toEqual(
@ -104,7 +104,7 @@ describe('Packwatch', () => {
await createPackageJson(workspacePath) await createPackageJson(workspacePath)
runPackwatch({ cwd: workspacePath, isUpdatingManifest: true }) await packwatch({ cwd: workspacePath, isUpdatingManifest: true })
expect(mockLogger.mock.calls).toHaveLength(1) expect(mockLogger.mock.calls).toHaveLength(1)
expect(mockLogger.mock.calls[0][0]).toEqual( expect(mockLogger.mock.calls[0][0]).toEqual(
@ -125,7 +125,7 @@ describe('Packwatch', () => {
packageSize: '160B', packageSize: '160B',
unpackedSize: '150B', unpackedSize: '150B',
}) })
runPackwatch({ cwd: workspacePath }) await packwatch({ cwd: workspacePath })
expect(mockLogger.mock.calls).toHaveLength(1) expect(mockLogger.mock.calls).toHaveLength(1)
expect(mockLogger.mock.calls[0][0]).toEqual( expect(mockLogger.mock.calls[0][0]).toEqual(
expect.stringMatching( expect.stringMatching(
@ -144,7 +144,7 @@ describe('Packwatch', () => {
unpackedSize: '150B', unpackedSize: '150B',
}) })
runPackwatch({ cwd: workspacePath }) await packwatch({ cwd: workspacePath })
expect(mockLogger.mock.calls).toHaveLength(1) expect(mockLogger.mock.calls).toHaveLength(1)
expect(mockLogger.mock.calls[0][0]).toEqual( expect(mockLogger.mock.calls[0][0]).toEqual(
expect.stringMatching( expect.stringMatching(
@ -162,7 +162,7 @@ describe('Packwatch', () => {
unpackedSize: '140B', unpackedSize: '140B',
}) })
runPackwatch({ cwd: workspacePath }) await packwatch({ cwd: workspacePath })
expect(mockLogger.mock.calls).toHaveLength(1) expect(mockLogger.mock.calls).toHaveLength(1)
expect(mockLogger.mock.calls[0][0]).toEqual( expect(mockLogger.mock.calls[0][0]).toEqual(
expect.stringMatching( expect.stringMatching(
@ -180,7 +180,7 @@ describe('Packwatch', () => {
unpackedSize: '140B', unpackedSize: '140B',
}) })
runPackwatch({ cwd: workspacePath }) await packwatch({ cwd: workspacePath })
expect(mockLogger.mock.calls).toHaveLength(1) expect(mockLogger.mock.calls).toHaveLength(1)
expect(mockLogger.mock.calls[0][0]).toEqual( expect(mockLogger.mock.calls[0][0]).toEqual(
expect.stringMatching( expect.stringMatching(
@ -198,7 +198,7 @@ describe('Packwatch', () => {
unpackedSize: '140B', unpackedSize: '140B',
}) })
runPackwatch({ cwd: workspacePath }) await packwatch({ cwd: workspacePath })
expect(mockLogger.mock.calls).toHaveLength(1) expect(mockLogger.mock.calls).toHaveLength(1)
expect(mockLogger.mock.calls[0][0]).toEqual( expect(mockLogger.mock.calls[0][0]).toEqual(
expect.stringMatching( expect.stringMatching(
@ -217,7 +217,7 @@ describe('Packwatch', () => {
unpackedSize: '140B', unpackedSize: '140B',
}) })
runPackwatch({ cwd: workspacePath, isUpdatingManifest: true }) await packwatch({ cwd: workspacePath, isUpdatingManifest: true })
expect(mockLogger.mock.calls).toHaveLength(1) expect(mockLogger.mock.calls).toHaveLength(1)
expect(mockLogger.mock.calls[0][0]).toEqual( expect(mockLogger.mock.calls[0][0]).toEqual(
expect.stringMatching( expect.stringMatching(

View file

@ -1,8 +1,9 @@
#!/usr/bin/env node #!/usr/bin/env node
import runPackwatch from '.' import packwatch from '.'
const isUpdatingManifest = process.argv.includes('--update-manifest') const isUpdatingManifest = process.argv.includes('--update-manifest')
const cwd = process.cwd() const cwd = process.cwd()
const processExit = runPackwatch({ cwd, isUpdatingManifest }) packwatch({ cwd, isUpdatingManifest })
process.exit(processExit) .catch(() => process.exit(1))
.then(() => process.exit(0))

View file

@ -9,13 +9,13 @@ import {
const MANIFEST_FILENAME = '.packwatch.json' const MANIFEST_FILENAME = '.packwatch.json'
export default function run({ export default async function packwatch({
cwd, cwd,
isUpdatingManifest, isUpdatingManifest,
}: { }: {
cwd?: string cwd?: string
isUpdatingManifest?: boolean isUpdatingManifest?: boolean
}): number { }): Promise<void> {
const packageJsonPath = resolve(join(cwd, 'package.json')) const packageJsonPath = resolve(join(cwd, 'package.json'))
const manifestPath = resolve(join(cwd, MANIFEST_FILENAME)) const manifestPath = resolve(join(cwd, MANIFEST_FILENAME))