refactor: fix types
This commit is contained in:
parent
d3b4dae910
commit
6e5f03f14c
4 changed files with 18 additions and 10 deletions
|
@ -33,7 +33,9 @@
|
|||
"lint:fix": "yarn lint --fix",
|
||||
"test": "jest src",
|
||||
"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": {
|
||||
"@babel/cli": "^7.8.4",
|
||||
|
|
|
@ -6,12 +6,12 @@ import type { Report } from '../index.d'
|
|||
import packwatch from '..'
|
||||
|
||||
async function prepareWorkspace(): Promise<string> {
|
||||
const workspacePath = await fs.mkdtemp(`${tmpdir()}/`, { recursive: true })
|
||||
const workspacePath = await fs.mkdtemp(`${tmpdir()}/`)
|
||||
return workspacePath
|
||||
}
|
||||
|
||||
async function cleanUpWorkspace(paths: string[]): Promise<void> {
|
||||
return Promise.all(
|
||||
await Promise.all(
|
||||
paths.map(async path => fs.rmdir(path, { recursive: true })),
|
||||
)
|
||||
}
|
||||
|
@ -68,7 +68,9 @@ describe('Packwatch', () => {
|
|||
workspacePath = await prepareWorkspace()
|
||||
await createPackageJson(workspacePath)
|
||||
|
||||
await packwatch({ cwd: workspacePath })
|
||||
await expect(async () =>
|
||||
packwatch({ cwd: workspacePath }),
|
||||
).rejects.toThrow()
|
||||
|
||||
const generatedManifest = await fs.readFile(
|
||||
resolve(join(workspacePath, '.packwatch.json')),
|
||||
|
@ -84,7 +86,9 @@ describe('Packwatch', () => {
|
|||
workspacePath = await prepareWorkspace()
|
||||
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[0][0]).toEqual(
|
||||
|
|
11
src/index.ts
11
src/index.ts
|
@ -23,7 +23,7 @@ export default async function packwatch({
|
|||
console.log(
|
||||
'🤔 There is no package.json file here. Are you in the root directory of your project?',
|
||||
)
|
||||
return 1
|
||||
return
|
||||
}
|
||||
|
||||
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
|
||||
// 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)
|
||||
|
@ -73,7 +74,7 @@ export default async function packwatch({
|
|||
console.log(
|
||||
`📝 Updated the manifest! Package size: ${packageSize}, Limit: ${packageSize}`,
|
||||
)
|
||||
return 0
|
||||
return
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -85,7 +86,7 @@ export default async function packwatch({
|
|||
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!`,
|
||||
)
|
||||
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})`,
|
||||
)
|
||||
}
|
||||
return 0
|
||||
return
|
||||
}
|
||||
|
|
|
@ -68,6 +68,7 @@ export function createOrUpdateManifest({
|
|||
}: {
|
||||
previous?: Report
|
||||
current: Report
|
||||
manifestPath: string
|
||||
updateLimit?: boolean
|
||||
}): void {
|
||||
const { limit } = previous || {}
|
||||
|
|
Reference in a new issue