From 2d0c6312230b91327c2dec78ae280838e2eff03c Mon Sep 17 00:00:00 2001 From: Marc Cataford Date: Fri, 19 Feb 2021 01:45:45 -0500 Subject: [PATCH 01/11] chore: misplaced test file --- src/{ => __tests__}/utils.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename src/{ => __tests__}/utils.test.ts (89%) diff --git a/src/utils.test.ts b/src/__tests__/utils.test.ts similarity index 89% rename from src/utils.test.ts rename to src/__tests__/utils.test.ts index 5a4ea33..f7cc2f9 100644 --- a/src/utils.test.ts +++ b/src/__tests__/utils.test.ts @@ -1,4 +1,4 @@ -import { convertSizeToBytes } from './utils' +import { convertSizeToBytes } from '../utils' describe('utils', () => { it.each` -- 2.45.2 From d3b4dae910d57406aeae14a3e3c170613c0ba22d Mon Sep 17 00:00:00 2001 From: Marc Cataford Date: Fri, 19 Feb 2021 01:46:14 -0500 Subject: [PATCH 02/11] refactor: rename, async main --- src/__tests__/index.test.ts | 22 +++++++++++----------- src/cli.ts | 7 ++++--- src/index.ts | 4 ++-- 3 files changed, 17 insertions(+), 16 deletions(-) diff --git a/src/__tests__/index.test.ts b/src/__tests__/index.test.ts index 880a897..e2796f7 100644 --- a/src/__tests__/index.test.ts +++ b/src/__tests__/index.test.ts @@ -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 { 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( diff --git a/src/cli.ts b/src/cli.ts index a13de2f..3d830c3 100644 --- a/src/cli.ts +++ b/src/cli.ts @@ -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)) diff --git a/src/index.ts b/src/index.ts index faced80..4a799f6 100644 --- a/src/index.ts +++ b/src/index.ts @@ -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 { const packageJsonPath = resolve(join(cwd, 'package.json')) const manifestPath = resolve(join(cwd, MANIFEST_FILENAME)) -- 2.45.2 From 6e5f03f14cb0919fa27dbd7e02a04ec942ad8877 Mon Sep 17 00:00:00 2001 From: Marc Cataford Date: Fri, 19 Feb 2021 02:00:39 -0500 Subject: [PATCH 03/11] refactor: fix types --- package.json | 4 +++- src/__tests__/index.test.ts | 12 ++++++++---- src/index.ts | 11 ++++++----- src/utils.ts | 1 + 4 files changed, 18 insertions(+), 10 deletions(-) diff --git a/package.json b/package.json index 776128f..48b8694 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/__tests__/index.test.ts b/src/__tests__/index.test.ts index e2796f7..e44cd52 100644 --- a/src/__tests__/index.test.ts +++ b/src/__tests__/index.test.ts @@ -6,12 +6,12 @@ import type { Report } from '../index.d' import packwatch from '..' async function prepareWorkspace(): Promise { - const workspacePath = await fs.mkdtemp(`${tmpdir()}/`, { recursive: true }) + const workspacePath = await fs.mkdtemp(`${tmpdir()}/`) return workspacePath } async function cleanUpWorkspace(paths: string[]): Promise { - 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( diff --git a/src/index.ts b/src/index.ts index 4a799f6..c08abf2 100644 --- a/src/index.ts +++ b/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 } diff --git a/src/utils.ts b/src/utils.ts index 9e254fd..0c5182b 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -68,6 +68,7 @@ export function createOrUpdateManifest({ }: { previous?: Report current: Report + manifestPath: string updateLimit?: boolean }): void { const { limit } = previous || {} -- 2.45.2 From da7571fba506b9e72161d72aaafd9c7b0be64059 Mon Sep 17 00:00:00 2001 From: Marc Cataford Date: Fri, 19 Feb 2021 02:03:16 -0500 Subject: [PATCH 04/11] chore: type args --- src/index.d.ts | 5 +++++ src/index.ts | 6 ++---- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/index.d.ts b/src/index.d.ts index c0a52f0..c35984e 100644 --- a/src/index.d.ts +++ b/src/index.d.ts @@ -1,3 +1,8 @@ +export type PackwatchArguments = { + cwd?: string + isUpdatingManifest?: boolean +} + export type Report = { packageSize: string unpackedSize?: string diff --git a/src/index.ts b/src/index.ts index c08abf2..a41a650 100644 --- a/src/index.ts +++ b/src/index.ts @@ -6,16 +6,14 @@ import { getCurrentPackageStats, getPreviousPackageStats, } from './utils' +import type { PackwatchArguments } from './index.d' const MANIFEST_FILENAME = '.packwatch.json' export default async function packwatch({ cwd, isUpdatingManifest, -}: { - cwd?: string - isUpdatingManifest?: boolean -}): Promise { +}: PackwatchArguments): Promise { const packageJsonPath = resolve(join(cwd, 'package.json')) const manifestPath = resolve(join(cwd, MANIFEST_FILENAME)) -- 2.45.2 From ef6fb52498a512195688ab9116cb6ecc7d930f6f Mon Sep 17 00:00:00 2001 From: Marc Cataford Date: Fri, 19 Feb 2021 02:16:10 -0500 Subject: [PATCH 05/11] refactor: extract package root invariant --- src/__tests__/index.test.ts | 4 +++- src/index.ts | 9 ++------- src/invariants.ts | 14 ++++++++++++++ 3 files changed, 19 insertions(+), 8 deletions(-) create mode 100644 src/invariants.ts diff --git a/src/__tests__/index.test.ts b/src/__tests__/index.test.ts index e44cd52..f9cacdf 100644 --- a/src/__tests__/index.test.ts +++ b/src/__tests__/index.test.ts @@ -53,7 +53,9 @@ describe('Packwatch', () => { it('warns the user and errors if run away from package.json', async () => { workspacePath = await prepareWorkspace() - await packwatch({ cwd: workspacePath }) + await expect(async () => + packwatch({ cwd: workspacePath }), + ).rejects.toThrow('NOT_IN_PACKAGE_ROOT') expect(mockLogger.mock.calls).toHaveLength(1) expect(mockLogger.mock.calls[0][0]).toEqual( diff --git a/src/index.ts b/src/index.ts index a41a650..f464536 100644 --- a/src/index.ts +++ b/src/index.ts @@ -7,6 +7,7 @@ import { getPreviousPackageStats, } from './utils' import type { PackwatchArguments } from './index.d' +import { assertInPackageRoot } from './invariants' const MANIFEST_FILENAME = '.packwatch.json' @@ -14,15 +15,9 @@ export default async function packwatch({ cwd, isUpdatingManifest, }: PackwatchArguments): Promise { - const packageJsonPath = resolve(join(cwd, 'package.json')) const manifestPath = resolve(join(cwd, MANIFEST_FILENAME)) - if (!existsSync(packageJsonPath)) { - console.log( - '🤔 There is no package.json file here. Are you in the root directory of your project?', - ) - return - } + assertInPackageRoot(cwd) const currentStats = getCurrentPackageStats(cwd) diff --git a/src/invariants.ts b/src/invariants.ts new file mode 100644 index 0000000..ed8839e --- /dev/null +++ b/src/invariants.ts @@ -0,0 +1,14 @@ +import { existsSync } from 'fs' +import { join, resolve } from 'path' + +export function assertInPackageRoot(cwd: string): void { + const packagePath = resolve(join(cwd, 'package.json')) + const packageJsonExists = existsSync(packagePath) + + if (!packageJsonExists) { + console.log( + '🤔 There is no package.json file here. Are you in the root directory of your project?', + ) + throw new Error('NOT_IN_PACKAGE_ROOT') + } +} -- 2.45.2 From dd8958875fb2f0342aa1f93e492baf09a4798417 Mon Sep 17 00:00:00 2001 From: Marc Cataford Date: Fri, 19 Feb 2021 09:49:13 -0500 Subject: [PATCH 06/11] refactor: error behaviour on limit exceeded --- src/__tests__/index.test.ts | 4 +++- src/index.ts | 8 +++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/__tests__/index.test.ts b/src/__tests__/index.test.ts index f9cacdf..b6d789c 100644 --- a/src/__tests__/index.test.ts +++ b/src/__tests__/index.test.ts @@ -204,7 +204,9 @@ describe('Packwatch', () => { unpackedSize: '140B', }) - await packwatch({ cwd: workspacePath }) + await expect(async () => + packwatch({ cwd: workspacePath }), + ).rejects.toThrow('PACKAGE_EXCEEDS_LIMIT') expect(mockLogger.mock.calls).toHaveLength(1) expect(mockLogger.mock.calls[0][0]).toEqual( expect.stringMatching( diff --git a/src/index.ts b/src/index.ts index f464536..670f70c 100644 --- a/src/index.ts +++ b/src/index.ts @@ -36,11 +36,9 @@ export default async function packwatch({ console.log( '❗ It looks like you ran PackWatch without a manifest. To prevent accidental passes in CI or hooks, packwatch will terminate with an error. If you are running packwatch for the first time in your project, this is expected!', ) + throw new Error('NO_MANIFEST_NO_UPDATE') } - // 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 - if (!isUpdatingManifest) throw new Error() - else return + return } const previousStats = getPreviousPackageStats(cwd) @@ -79,7 +77,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 + throw new Error('PACKAGE_EXCEEDS_LIMIT') } /* -- 2.45.2 From a5081e3db6156fe7cfd3738b99eea00970d59bb3 Mon Sep 17 00:00:00 2001 From: Marc Cataford Date: Fri, 19 Feb 2021 10:02:47 -0500 Subject: [PATCH 07/11] test: more precise error cov --- src/__tests__/index.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/__tests__/index.test.ts b/src/__tests__/index.test.ts index b6d789c..87e08d0 100644 --- a/src/__tests__/index.test.ts +++ b/src/__tests__/index.test.ts @@ -72,7 +72,7 @@ describe('Packwatch', () => { await expect(async () => packwatch({ cwd: workspacePath }), - ).rejects.toThrow() + ).rejects.toThrow('NO_MANIFEST_NO_UPDATE') const generatedManifest = await fs.readFile( resolve(join(workspacePath, '.packwatch.json')), -- 2.45.2 From 4eb2e87fd71af4cd17d477a45da88717941a4f7d Mon Sep 17 00:00:00 2001 From: Marc Cataford Date: Fri, 19 Feb 2021 10:11:41 -0500 Subject: [PATCH 08/11] refactor: extract logging --- src/index.ts | 15 ++++++++------- src/invariants.ts | 4 +++- src/logger.ts | 11 +++++++++++ 3 files changed, 22 insertions(+), 8 deletions(-) create mode 100644 src/logger.ts diff --git a/src/index.ts b/src/index.ts index 670f70c..5e6c827 100644 --- a/src/index.ts +++ b/src/index.ts @@ -8,6 +8,7 @@ import { } from './utils' import type { PackwatchArguments } from './index.d' import { assertInPackageRoot } from './invariants' +import logger from './logger' const MANIFEST_FILENAME = '.packwatch.json' @@ -28,12 +29,12 @@ export default async function packwatch({ if (!existsSync(manifestPath)) { createOrUpdateManifest({ manifestPath, current: currentStats }) - console.log( + logger.log( `📝 No Manifest to compare against! Current package stats written to ${MANIFEST_FILENAME}!\nPackage size (${currentStats.packageSize}) adopted as new limit.`, ) if (!isUpdatingManifest) { - console.log( + logger.log( '❗ It looks like you ran PackWatch without a manifest. To prevent accidental passes in CI or hooks, packwatch will terminate with an error. If you are running packwatch for the first time in your project, this is expected!', ) throw new Error('NO_MANIFEST_NO_UPDATE') @@ -62,7 +63,7 @@ export default async function packwatch({ updateLimit: true, manifestPath, }) - console.log( + logger.log( `📝 Updated the manifest! Package size: ${packageSize}, Limit: ${packageSize}`, ) return @@ -74,7 +75,7 @@ export default async function packwatch({ */ if (hasExceededLimit) { - console.log( + logger.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!`, ) throw new Error('PACKAGE_EXCEEDS_LIMIT') @@ -87,15 +88,15 @@ export default async function packwatch({ */ if (packageSizeBytes > previousSizeBytes) { - console.log( + logger.log( `📦 👀 Your package grew! ${packageSize} > ${previousSize} (Limit: ${limit})`, ) } else if (packageSizeBytes < previousSizeBytes) { - console.log( + logger.log( `📦 💯 Your package shrank! ${packageSize} < ${previousSize} (Limit: ${limit})`, ) } else { - console.log( + logger.log( `📦 Nothing to report! Your package is the same size as the latest manifest reports! (Limit: ${limit})`, ) } diff --git a/src/invariants.ts b/src/invariants.ts index ed8839e..01309aa 100644 --- a/src/invariants.ts +++ b/src/invariants.ts @@ -1,12 +1,14 @@ import { existsSync } from 'fs' import { join, resolve } from 'path' +import logger from './logger' + export function assertInPackageRoot(cwd: string): void { const packagePath = resolve(join(cwd, 'package.json')) const packageJsonExists = existsSync(packagePath) if (!packageJsonExists) { - console.log( + logger.log( '🤔 There is no package.json file here. Are you in the root directory of your project?', ) throw new Error('NOT_IN_PACKAGE_ROOT') diff --git a/src/logger.ts b/src/logger.ts new file mode 100644 index 0000000..9e7eaa8 --- /dev/null +++ b/src/logger.ts @@ -0,0 +1,11 @@ +export default { + log: (...args: unknown[]): void => { + console.log(...args) + }, + warn: (...args: unknown[]): void => { + console.warn(...args) + }, + error: (...args: unknown[]): void => { + console.error(...args) + }, +} -- 2.45.2 From 2d9a0eec160aed868087fa047908cee31db47c37 Mon Sep 17 00:00:00 2001 From: Marc Cataford Date: Fri, 19 Mar 2021 16:38:47 -0400 Subject: [PATCH 09/11] refactor: logger --- src/__tests__/index.test.ts | 22 ++++++++++++++-------- src/index.ts | 6 +++--- 2 files changed, 17 insertions(+), 11 deletions(-) diff --git a/src/__tests__/index.test.ts b/src/__tests__/index.test.ts index 87e08d0..8ace7d3 100644 --- a/src/__tests__/index.test.ts +++ b/src/__tests__/index.test.ts @@ -2,6 +2,7 @@ import { promises as fs } from 'fs' import { tmpdir } from 'os' import { join, resolve } from 'path' +import logger from '../logger' import type { Report } from '../index.d' import packwatch from '..' @@ -37,9 +38,13 @@ async function createManifest( } describe('Packwatch', () => { let mockLogger + let mockWarn + let mockError let workspacePath beforeEach(() => { - mockLogger = jest.spyOn(global.console, 'log').mockImplementation() + mockLogger = jest.spyOn(logger, 'log').mockImplementation() + mockWarn = jest.spyOn(logger, 'warn').mockImplementation() + mockError = jest.spyOn(logger, 'error').mockImplementation() }) afterEach(async () => { @@ -92,13 +97,14 @@ describe('Packwatch', () => { packwatch({ cwd: workspacePath }), ).rejects.toThrow() - expect(mockLogger.mock.calls).toHaveLength(2) - expect(mockLogger.mock.calls[0][0]).toEqual( + expect(mockWarn.mock.calls).toHaveLength(1) + expect(mockWarn.mock.calls[0][0]).toEqual( expect.stringMatching( /No Manifest to compare against! Current package stats written to \.packwatch\.json!\nPackage size \(\d+ B\) adopted as new limit\./, ), ) - expect(mockLogger.mock.calls[1][0]).toEqual( + expect(mockError.mock.calls).toHaveLength(1) + expect(mockError.mock.calls[1][0]).toEqual( expect.stringMatching( 'It looks like you ran PackWatch without a manifest. To prevent accidental passes in CI or hooks, packwatch will terminate with an error. If you are running packwatch for the first time in your project, this is expected!', ), @@ -112,8 +118,8 @@ describe('Packwatch', () => { await packwatch({ cwd: workspacePath, isUpdatingManifest: true }) - expect(mockLogger.mock.calls).toHaveLength(1) - expect(mockLogger.mock.calls[0][0]).toEqual( + expect(mockWarn.mock.calls).toHaveLength(1) + expect(mockWarn.mock.calls[0][0]).toEqual( expect.stringMatching( /No Manifest to compare against! Current package stats written to \.packwatch\.json!\nPackage size \(\d+ B\) adopted as new limit\./, ), @@ -207,8 +213,8 @@ describe('Packwatch', () => { await expect(async () => packwatch({ cwd: workspacePath }), ).rejects.toThrow('PACKAGE_EXCEEDS_LIMIT') - expect(mockLogger.mock.calls).toHaveLength(1) - expect(mockLogger.mock.calls[0][0]).toEqual( + expect(mockError.mock.calls).toHaveLength(1) + expect(mockError.mock.calls[0][0]).toEqual( expect.stringMatching( /Your package exceeds the limit set in \.packwatch\.json! \d+ B > 10B\nEither update the limit by using the --update-manifest flag or trim down your packed files!/, ), diff --git a/src/index.ts b/src/index.ts index 5e6c827..9adeaa7 100644 --- a/src/index.ts +++ b/src/index.ts @@ -29,12 +29,12 @@ export default async function packwatch({ if (!existsSync(manifestPath)) { createOrUpdateManifest({ manifestPath, current: currentStats }) - logger.log( + logger.warn( `📝 No Manifest to compare against! Current package stats written to ${MANIFEST_FILENAME}!\nPackage size (${currentStats.packageSize}) adopted as new limit.`, ) if (!isUpdatingManifest) { - logger.log( + logger.error( '❗ It looks like you ran PackWatch without a manifest. To prevent accidental passes in CI or hooks, packwatch will terminate with an error. If you are running packwatch for the first time in your project, this is expected!', ) throw new Error('NO_MANIFEST_NO_UPDATE') @@ -75,7 +75,7 @@ export default async function packwatch({ */ if (hasExceededLimit) { - logger.log( + logger.error( `🔥🔥📦🔥🔥 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!`, ) throw new Error('PACKAGE_EXCEEDS_LIMIT') -- 2.45.2 From b695a0a7ff5b61806d71a2b0a067ddde7ec0b9e3 Mon Sep 17 00:00:00 2001 From: Marc Cataford Date: Fri, 19 Mar 2021 16:41:30 -0400 Subject: [PATCH 10/11] test: index fix --- src/__tests__/index.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/__tests__/index.test.ts b/src/__tests__/index.test.ts index 8ace7d3..72b640a 100644 --- a/src/__tests__/index.test.ts +++ b/src/__tests__/index.test.ts @@ -104,7 +104,7 @@ describe('Packwatch', () => { ), ) expect(mockError.mock.calls).toHaveLength(1) - expect(mockError.mock.calls[1][0]).toEqual( + expect(mockError.mock.calls[0][0]).toEqual( expect.stringMatching( 'It looks like you ran PackWatch without a manifest. To prevent accidental passes in CI or hooks, packwatch will terminate with an error. If you are running packwatch for the first time in your project, this is expected!', ), -- 2.45.2 From 5ea1d01345f9f8025dc881003d40d034bde81fda Mon Sep 17 00:00:00 2001 From: Marc Cataford Date: Fri, 19 Mar 2021 16:46:10 -0400 Subject: [PATCH 11/11] refactor: move mocking downstream --- src/__tests__/index.test.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/__tests__/index.test.ts b/src/__tests__/index.test.ts index 72b640a..42631a9 100644 --- a/src/__tests__/index.test.ts +++ b/src/__tests__/index.test.ts @@ -42,9 +42,9 @@ describe('Packwatch', () => { let mockError let workspacePath beforeEach(() => { - mockLogger = jest.spyOn(logger, 'log').mockImplementation() - mockWarn = jest.spyOn(logger, 'warn').mockImplementation() - mockError = jest.spyOn(logger, 'error').mockImplementation() + mockLogger = jest.spyOn(console, 'log').mockImplementation() + mockWarn = jest.spyOn(console, 'warn').mockImplementation() + mockError = jest.spyOn(console, 'error').mockImplementation() }) afterEach(async () => { -- 2.45.2