refactor: fix types

This commit is contained in:
Marc Cataford 2021-02-19 02:00:39 -05:00
parent d3b4dae910
commit 6e5f03f14c
4 changed files with 18 additions and 10 deletions

View file

@ -33,7 +33,9 @@
"lint:fix": "yarn lint --fix", "lint:fix": "yarn lint --fix",
"test": "jest src", "test": "jest src",
"test:watch": "yarn test --watchAll", "test:watch": "yarn test --watchAll",
"test:coverage": "yarn test --coverage" "test:coverage": "yarn test --coverage",
"types": "tsc --noEmit src/**/*.ts",
"types:watch": "yarn types --watch"
}, },
"devDependencies": { "devDependencies": {
"@babel/cli": "^7.8.4", "@babel/cli": "^7.8.4",

View file

@ -6,12 +6,12 @@ import type { Report } from '../index.d'
import packwatch 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()}/`)
return workspacePath return workspacePath
} }
async function cleanUpWorkspace(paths: string[]): Promise<void> { async function cleanUpWorkspace(paths: string[]): Promise<void> {
return Promise.all( await Promise.all(
paths.map(async path => fs.rmdir(path, { recursive: true })), paths.map(async path => fs.rmdir(path, { recursive: true })),
) )
} }
@ -68,7 +68,9 @@ describe('Packwatch', () => {
workspacePath = await prepareWorkspace() workspacePath = await prepareWorkspace()
await createPackageJson(workspacePath) await createPackageJson(workspacePath)
await packwatch({ cwd: workspacePath }) await expect(async () =>
packwatch({ cwd: workspacePath }),
).rejects.toThrow()
const generatedManifest = await fs.readFile( const generatedManifest = await fs.readFile(
resolve(join(workspacePath, '.packwatch.json')), resolve(join(workspacePath, '.packwatch.json')),
@ -84,7 +86,9 @@ describe('Packwatch', () => {
workspacePath = await prepareWorkspace() workspacePath = await prepareWorkspace()
await createPackageJson(workspacePath) await createPackageJson(workspacePath)
await packwatch({ cwd: workspacePath }) await expect(async () =>
packwatch({ cwd: workspacePath }),
).rejects.toThrow()
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(

View file

@ -23,7 +23,7 @@ export default async function packwatch({
console.log( console.log(
'🤔 There is no package.json file here. Are you in the root directory of your project?', '🤔 There is no package.json file here. Are you in the root directory of your project?',
) )
return 1 return
} }
const currentStats = getCurrentPackageStats(cwd) const currentStats = getCurrentPackageStats(cwd)
@ -46,7 +46,8 @@ export default async function packwatch({
} }
// If the update flag wasn't specified, exit with a non-zero code so we // If the update flag wasn't specified, exit with a non-zero code so we
// don't "accidentally" pass CI builds if the manifest didn't exist // don't "accidentally" pass CI builds if the manifest didn't exist
return isUpdatingManifest ? 0 : 1 if (!isUpdatingManifest) throw new Error()
else return
} }
const previousStats = getPreviousPackageStats(cwd) const previousStats = getPreviousPackageStats(cwd)
@ -73,7 +74,7 @@ export default async function packwatch({
console.log( console.log(
`📝 Updated the manifest! Package size: ${packageSize}, Limit: ${packageSize}`, `📝 Updated the manifest! Package size: ${packageSize}, Limit: ${packageSize}`,
) )
return 0 return
} }
/* /*
@ -85,7 +86,7 @@ export default async function packwatch({
console.log( console.log(
`🔥🔥📦🔥🔥 Your package exceeds the limit set in ${MANIFEST_FILENAME}! ${packageSize} > ${limit}\nEither update the limit by using the --update-manifest flag or trim down your packed files!`, `🔥🔥📦🔥🔥 Your package exceeds the limit set in ${MANIFEST_FILENAME}! ${packageSize} > ${limit}\nEither update the limit by using the --update-manifest flag or trim down your packed files!`,
) )
return 1 return
} }
/* /*
@ -107,5 +108,5 @@ export default async function packwatch({
`📦 Nothing to report! Your package is the same size as the latest manifest reports! (Limit: ${limit})`, `📦 Nothing to report! Your package is the same size as the latest manifest reports! (Limit: ${limit})`,
) )
} }
return 0 return
} }

View file

@ -68,6 +68,7 @@ export function createOrUpdateManifest({
}: { }: {
previous?: Report previous?: Report
current: Report current: Report
manifestPath: string
updateLimit?: boolean updateLimit?: boolean
}): void { }): void {
const { limit } = previous || {} const { limit } = previous || {}