diff --git a/apps/documentation/pages/checks/testing-checks.mdx b/apps/documentation/pages/checks/testing-checks.mdx index 7f69a234..f59fef49 100644 --- a/apps/documentation/pages/checks/testing-checks.mdx +++ b/apps/documentation/pages/checks/testing-checks.mdx @@ -37,7 +37,7 @@ const ensureLicense = defineCheck((license: string = 'MIT') => { if (!packageJson || !packageJson.license) { return { title: 'Package.json must have a license', - filepath: 'package.json', + filePath: 'package.json', context: diff( { name: packageJson.name }, { name: packageJson.name, license }, @@ -47,7 +47,7 @@ const ensureLicense = defineCheck((license: string = 'MIT') => { return { title: `Package.json license must be ${license}`, - filepath: 'package.json', + filePath: 'package.json', context: diff( { name: packageJson.name, license: packageJson.license }, { name: packageJson.name, license }, @@ -142,7 +142,7 @@ describe('ensureLicense', () => { const message = await check.message(); expect(message.title).toEqual('Package.json license must be MIT'); - expect(message.filepath).toEqual('package.json'); + expect(message.filePath).toEqual('package.json'); // We recommend snapshot testing suggestions as the formatting can be tricky to hardode expect(message.suggestion).toMatchInlineSnapshot(); }); diff --git a/apps/documentation/pages/reference/checks.mdx b/apps/documentation/pages/reference/checks.mdx index 8930247b..1160d742 100644 --- a/apps/documentation/pages/reference/checks.mdx +++ b/apps/documentation/pages/reference/checks.mdx @@ -93,7 +93,7 @@ You can return a `Message` object from the `message` function to dynamically con ```ts type Message = { text: string; - filepath?: string; + filePath?: string; context?: string; }; ``` @@ -113,13 +113,13 @@ const ensureTSConfigExtends = defineCheck((base: string) => { if (!tsConfig) { return { text: 'tsconfig.json does not exist', - filepath: 'tsconfig.json', + filePath: 'tsconfig.json', }; } return { text: `tsconfig.json must extend ${base}`, - filepath: 'tsconfig.json', + filePath: 'tsconfig.json', context: diff(tsConfig, { ...tsConfig, extends: base }), }; }, diff --git a/packages/commonality/commonality-recommended/src/dev-peer-dependency-range.ts b/packages/commonality/commonality-recommended/src/dev-peer-dependency-range.ts index cf73568c..024df8fa 100644 --- a/packages/commonality/commonality-recommended/src/dev-peer-dependency-range.ts +++ b/packages/commonality/commonality-recommended/src/dev-peer-dependency-range.ts @@ -118,7 +118,7 @@ export const devPeerDependencyRange = defineCheck(() => { const expectedDevDependencies = getExpectedDevDependencies(packageJson); if (!expectedDevDependencies) { - return { title, filepath: 'package.json' }; + return { title, filePath: 'package.json' }; } const source: Partial = { @@ -139,7 +139,7 @@ export const devPeerDependencyRange = defineCheck(() => { return { title, suggestion: diff(source, target), - filepath: 'package.json', + filePath: 'package.json', }; }, }; diff --git a/packages/commonality/commonality-recommended/src/multiple-dependency-types.ts b/packages/commonality/commonality-recommended/src/multiple-dependency-types.ts index 6c1c3188..0647c401 100644 --- a/packages/commonality/commonality-recommended/src/multiple-dependency-types.ts +++ b/packages/commonality/commonality-recommended/src/multiple-dependency-types.ts @@ -93,7 +93,7 @@ export const multipleDependencyTypes = defineCheck(() => { return { title: 'A dependency should only be in one of dependencies, devDependencies, or optionalDependencies', - filepath: 'package.json', + filePath: 'package.json', suggestion: diff(packageJson, getExpectedPackageJson(packageJson)), }; }, diff --git a/packages/commonality/commonality-recommended/src/no-external-mismatch.ts b/packages/commonality/commonality-recommended/src/no-external-mismatch.ts index 5367f427..7efd525a 100644 --- a/packages/commonality/commonality-recommended/src/no-external-mismatch.ts +++ b/packages/commonality/commonality-recommended/src/no-external-mismatch.ts @@ -1,6 +1,5 @@ import { defineCheck, diff, json, PackageJson, Workspace } from 'commonality'; import { getExternalVersionMap } from './utils/get-external-version-map'; -import path from 'node:path'; import pick from 'lodash/pick'; export const DEPENDENCY_TYPES = [ diff --git a/packages/commonality/commonality-recommended/src/respository-field.ts b/packages/commonality/commonality-recommended/src/respository-field.ts index 7256d5d3..4c9cc3be 100644 --- a/packages/commonality/commonality-recommended/src/respository-field.ts +++ b/packages/commonality/commonality-recommended/src/respository-field.ts @@ -134,7 +134,7 @@ export const repositoryField = defineCheck(() => { if (!packageJson) { return { title: 'Package.json is missing.', - filepath: 'package.json', + filePath: 'package.json', suggestion: 'Create a package.json file in your workspace.', }; } @@ -142,14 +142,14 @@ export const repositoryField = defineCheck(() => { if (!newConfig) { return { title: 'Repository field is missing.', - filepath: 'package.json', + filePath: 'package.json', suggestion: 'Add a repository field to your root package.json', }; } return { title: `Package's repository property must extend the repository property at the root of your project.`, - filepath: 'package.json', + filePath: 'package.json', suggestion: diff( pick(packageJson, ['name', 'repository']), pick( diff --git a/packages/commonality/commonality-recommended/src/sorted-dependencies.ts b/packages/commonality/commonality-recommended/src/sorted-dependencies.ts index ecaf330a..d7b706ee 100644 --- a/packages/commonality/commonality-recommended/src/sorted-dependencies.ts +++ b/packages/commonality/commonality-recommended/src/sorted-dependencies.ts @@ -74,7 +74,7 @@ export const sortedDependencies = defineCheck(() => { message: () => { return { title: 'Dependencies in package.json must be sorted alphabetically', - filepath: 'package.json', + filePath: 'package.json', }; }, }; diff --git a/packages/commonality/commonality-recommended/src/valid-package-name.ts b/packages/commonality/commonality-recommended/src/valid-package-name.ts index 74917bf6..081a9898 100644 --- a/packages/commonality/commonality-recommended/src/valid-package-name.ts +++ b/packages/commonality/commonality-recommended/src/valid-package-name.ts @@ -34,7 +34,7 @@ export const validPackageName = defineCheck(() => ({ if (!packageJson || !packageJson.name) { return { title: 'Package name must be set in package.json', - filepath: 'package.json', + filePath: 'package.json', }; } @@ -42,7 +42,7 @@ export const validPackageName = defineCheck(() => ({ return { title: 'Invalid package name', - filepath: 'package.json', + filePath: 'package.json', suggestion: result.errors ? result.errors.join('\n') : result.warnings?.join('\n'), diff --git a/packages/commonality/commonality-recommended/test/dev-peer-dependency-range.test.ts b/packages/commonality/commonality-recommended/test/dev-peer-dependency-range.test.ts index 55955299..b4d363f4 100644 --- a/packages/commonality/commonality-recommended/test/dev-peer-dependency-range.test.ts +++ b/packages/commonality/commonality-recommended/test/dev-peer-dependency-range.test.ts @@ -167,7 +167,7 @@ describe('dev-peer-dependency-range', () => { await conformer.fix(); - const packageJson = await json('package.json').get(); + const packageJson = await json('./', 'package.json').get(); expect(packageJson).toEqual({ name: 'pkg-a', @@ -194,7 +194,7 @@ describe('dev-peer-dependency-range', () => { await conformer.fix(); - const packageJson = await json('package.json').get(); + const packageJson = await json('./', 'package.json').get(); expect(packageJson).toEqual({ name: 'pkg-a', @@ -229,6 +229,7 @@ describe('dev-peer-dependency-range', () => { expect(result.title).toEqual( 'Packages with peerDependencies must have matching devDependencies within a valid range', ); + expect(result.filePath).toEqual('package.json'); expect(result.suggestion).toMatchInlineSnapshot(` " Object { \\"devDependencies\\": Object { @@ -262,6 +263,7 @@ describe('dev-peer-dependency-range', () => { expect(result.title).toEqual( 'Packages with peerDependencies must have matching devDependencies within a valid range', ); + expect(result.filePath).toEqual('package.json'); expect(result.suggestion).toMatchInlineSnapshot('undefined'); }); }); diff --git a/packages/commonality/commonality-recommended/test/ensure-readme.test.ts b/packages/commonality/commonality-recommended/test/ensure-readme.test.ts index 72efc92d..c10aca15 100644 --- a/packages/commonality/commonality-recommended/test/ensure-readme.test.ts +++ b/packages/commonality/commonality-recommended/test/ensure-readme.test.ts @@ -45,7 +45,7 @@ describe('ensureReadme', () => { await conformer.fix(); - const readme = await text('README.md').get(); + const readme = await text('./', 'README.md').get(); expect(readme).toEqual(['# workspaceName', '> workspaceDescription']); }); diff --git a/packages/commonality/commonality-recommended/test/multiple-dependency-types.test.ts b/packages/commonality/commonality-recommended/test/multiple-dependency-types.test.ts index b56d37b2..beff74bc 100644 --- a/packages/commonality/commonality-recommended/test/multiple-dependency-types.test.ts +++ b/packages/commonality/commonality-recommended/test/multiple-dependency-types.test.ts @@ -97,7 +97,7 @@ describe('multipleDependencyTypes', () => { await conformer.fix(); - const packageJson = await json('package.json').get(); + const packageJson = await json('./', 'package.json').get(); expect(packageJson).toEqual({ name: 'pkg-b', @@ -124,7 +124,7 @@ describe('multipleDependencyTypes', () => { await conformer.fix(); - const packageJson = await json('package.json').get(); + const packageJson = await json('./', 'package.json').get(); expect(packageJson).toEqual({ name: 'pkg-b', @@ -155,7 +155,7 @@ describe('multipleDependencyTypes', () => { await conformer.fix(); - const packageJson = await json('package.json').get(); + const packageJson = await json('./', 'package.json').get(); expect(packageJson).toEqual({ name: 'pkg-b', @@ -193,7 +193,7 @@ describe('multipleDependencyTypes', () => { expect(message.title).toEqual( 'A dependency should only be in one of dependencies, devDependencies, or optionalDependencies', ); - + expect(message.filePath).toEqual('package.json'); expect(message.suggestion ?? '').toMatchInlineSnapshot( ` " Object { diff --git a/packages/commonality/commonality-recommended/test/no-external-mismatch.test.ts b/packages/commonality/commonality-recommended/test/no-external-mismatch.test.ts index 770aca02..ce701cda 100644 --- a/packages/commonality/commonality-recommended/test/no-external-mismatch.test.ts +++ b/packages/commonality/commonality-recommended/test/no-external-mismatch.test.ts @@ -167,7 +167,10 @@ describe('no-external-mismatch', () => { await conformer.fix(); - const pkgAResult = await json('./packages/pkg-a/package.json').get(); + const pkgAResult = await json( + './', + './packages/pkg-a/package.json', + ).get(); expect(pkgAResult).toEqual({ name: 'pkg-a', @@ -251,7 +254,10 @@ describe('no-external-mismatch', () => { await conformer.fix(); - const pkgEResult = await json('./packages/pkg-e/package.json').get(); + const pkgEResult = await json( + './', + './packages/pkg-e/package.json', + ).get(); expect(pkgEResult).toEqual({ name: 'pkg-e', diff --git a/packages/commonality/commonality-recommended/test/repository-field.test.ts b/packages/commonality/commonality-recommended/test/repository-field.test.ts index 1ab5202c..c5c9f759 100644 --- a/packages/commonality/commonality-recommended/test/repository-field.test.ts +++ b/packages/commonality/commonality-recommended/test/repository-field.test.ts @@ -213,7 +213,7 @@ describe('repository-field', () => { await conformer.fix(); - const result = await json('./packages/pkg-a/package.json').get(); + const result = await json('./', './packages/pkg-a/package.json').get(); expect(result).toEqual({ repository: 'https://github.com/npm/cli.git/packages/pkg-a', @@ -245,7 +245,7 @@ describe('repository-field', () => { await conformer.fix(); - const result = await json('./packages/pkg-a/package.json').get(); + const result = await json('./', './packages/pkg-a/package.json').get(); expect(result).toEqual({ repository: 'https://github.com/npm/cli.git/packages/pkg-a', @@ -282,7 +282,7 @@ describe('repository-field', () => { await conformer.fix(); - const result = await json('./packages/pkg-a/package.json').get(); + const result = await json('./', './packages/pkg-a/package.json').get(); expect(result).toEqual({ repository: { @@ -319,7 +319,7 @@ describe('repository-field', () => { await conformer.fix(); - const result = await json('./packages/pkg-a/package.json').get(); + const result = await json('./', './packages/pkg-a/package.json').get(); expect(result).toEqual({ repository: 'https://github.com/npm/cli.git/packages/pkg-a', @@ -358,6 +358,10 @@ describe('repository-field', () => { const result = await conformer.message(); + expect(result.title).toEqual( + `Package's repository property must extend the repository property at the root of your project.`, + ); + expect(result.filePath).toEqual('package.json'); expect(result.suggestion).toMatchInlineSnapshot(` " Object { \\"name\\": \\"foo\\", @@ -398,6 +402,10 @@ describe('repository-field', () => { const result = await conformer.message(); + expect(result.title).toEqual( + `Package's repository property must extend the repository property at the root of your project.`, + ); + expect(result.filePath).toEqual('package.json'); expect(result.suggestion).toMatchInlineSnapshot('undefined'); }); }); diff --git a/packages/commonality/commonality-recommended/test/sorted-dependencies.test.ts b/packages/commonality/commonality-recommended/test/sorted-dependencies.test.ts index 1809f917..5494750f 100644 --- a/packages/commonality/commonality-recommended/test/sorted-dependencies.test.ts +++ b/packages/commonality/commonality-recommended/test/sorted-dependencies.test.ts @@ -55,7 +55,7 @@ describe('sortedDependencies', () => { await conformer.fix(); - const result = await json('package.json').get(); + const result = await json('./', 'package.json').get(); expect(result).toEqual({ dependencies: { @@ -73,4 +73,24 @@ describe('sortedDependencies', () => { }); }); }); + + describe('message', () => { + it('return the correct message for unsorted dependencies', async () => { + mockFs({ + 'package.json': JSON.stringify({ + dependencies: { 'b-dep': '1.0.0', 'a-dep': '1.0.0' }, + devDependencies: { 'b-dep': '1.0.0', 'a-dep': '1.0.0' }, + peerDependencies: { 'b-dep': '1.0.0', 'a-dep': '1.0.0' }, + }), + }); + const conformer = createTestCheck(sortedDependencies()); + + const result = await conformer.message(); + console.log({ result }); + expect(result.title).toEqual( + 'Dependencies in package.json must be sorted alphabetically', + ); + expect(result.filePath).toEqual('package.json'); + }); + }); }); diff --git a/packages/commonality/commonality-recommended/test/valid-package-name.test.ts b/packages/commonality/commonality-recommended/test/valid-package-name.test.ts index 4077b965..5324f8ce 100644 --- a/packages/commonality/commonality-recommended/test/valid-package-name.test.ts +++ b/packages/commonality/commonality-recommended/test/valid-package-name.test.ts @@ -1,4 +1,4 @@ -import { afterEach, beforeEach, describe, expect, it } from 'vitest'; +import { afterEach, describe, expect, it } from 'vitest'; import { validPackageName } from '../src/valid-package-name'; import { createTestCheck } from 'commonality'; import mockFs from 'mock-fs'; diff --git a/packages/conformance/utils-conformance/src/create-test-check.ts b/packages/conformance/utils-conformance/src/create-test-check.ts index 0454b6de..1ae61212 100644 --- a/packages/conformance/utils-conformance/src/create-test-check.ts +++ b/packages/conformance/utils-conformance/src/create-test-check.ts @@ -9,7 +9,7 @@ type FunctionType = (options: CheckOptions) => Awaitable; type TestConformer = { [P in keyof T]: P extends 'fix' | 'message' | 'validate' ? T[P] extends FunctionType - ? () => ReturnType + ? () => Promise> : T[P] : T[P]; }; diff --git a/packages/shared/ui-package/vitest.config.ts.timestamp-1703187671404-d1a6ec463916e.mjs b/packages/shared/ui-package/vitest.config.ts.timestamp-1703187671404-d1a6ec463916e.mjs new file mode 100644 index 00000000..f78cfead --- /dev/null +++ b/packages/shared/ui-package/vitest.config.ts.timestamp-1703187671404-d1a6ec463916e.mjs @@ -0,0 +1,16 @@ +// packages/shared/ui-package/vitest.config.ts +import { defineConfig } from "file:///Users/alecortega/workspace/commonalityco/node_modules/.pnpm/vitest@1.1.0_@types+node@20.10.5/node_modules/vitest/dist/config.js"; +import react from "file:///Users/alecortega/workspace/commonalityco/node_modules/.pnpm/@vitejs+plugin-react-swc@3.5.0_vite@5.0.10/node_modules/@vitejs/plugin-react-swc/index.mjs"; +var vitest_config_default = defineConfig({ + plugins: [react()], + test: { + globals: true, + environment: "jsdom", + threads: false, + setupFiles: ["./test/setup.ts"] + } +}); +export { + vitest_config_default as default +}; +//# sourceMappingURL=data:application/json;base64,ewogICJ2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O0FBRWxCLElBQU8sd0JBQVEsYUFBYTtBQUFBLEVBQzFCLFNBQVMsQ0FBQyxNQUFNLENBQUM7QUFBQSxFQUNqQixNQUFNO0FBQUEsSUFDSixTQUFTO0FBQUEsSUFDVCxhQUFhO0FBQUEsSUFDYixTQUFTO0FBQUEsSUFDVCxZQUFZLENBQUMsaUJBQWlCO0FBQUEsRUFDaEM7QUFDRixDQUFDOyIsCiAgIm5hbWVzIjogW10KfQo= diff --git a/packages/shared/ui-package/vitest.config.ts.timestamp-1703187677213-62984ad833982.mjs b/packages/shared/ui-package/vitest.config.ts.timestamp-1703187677213-62984ad833982.mjs new file mode 100644 index 00000000..f78cfead --- /dev/null +++ b/packages/shared/ui-package/vitest.config.ts.timestamp-1703187677213-62984ad833982.mjs @@ -0,0 +1,16 @@ +// packages/shared/ui-package/vitest.config.ts +import { defineConfig } from "file:///Users/alecortega/workspace/commonalityco/node_modules/.pnpm/vitest@1.1.0_@types+node@20.10.5/node_modules/vitest/dist/config.js"; +import react from "file:///Users/alecortega/workspace/commonalityco/node_modules/.pnpm/@vitejs+plugin-react-swc@3.5.0_vite@5.0.10/node_modules/@vitejs/plugin-react-swc/index.mjs"; +var vitest_config_default = defineConfig({ + plugins: [react()], + test: { + globals: true, + environment: "jsdom", + threads: false, + setupFiles: ["./test/setup.ts"] + } +}); +export { + vitest_config_default as default +}; +//# sourceMappingURL=data:application/json;base64,ewogICJ2ZXJzaW9uIjogMywKICAic291cmNlcyI6IFsicGFja2FnZXMvc2hhcmVkL3VpLXBhY2thZ2Uvdml0ZXN0LmNvbmZpZy50cyJdLAogICJzb3VyY2VzQ29udGVudCI6IFsiY29uc3QgX192aXRlX2luamVjdGVkX29yaWdpbmFsX2Rpcm5hbWUgPSBcIi9Vc2Vycy9hbGVjb3J0ZWdhL3dvcmtzcGFjZS9jb21tb25hbGl0eWNvL3BhY2thZ2VzL3NoYXJlZC91aS1wYWNrYWdlXCI7Y29uc3QgX192aXRlX2luamVjdGVkX29yaWdp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