Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix filepath #152

Merged
merged 2 commits into from
Dec 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions apps/documentation/pages/checks/testing-checks.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -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 },
Expand All @@ -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 },
Expand Down Expand Up @@ -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();
});
Expand Down
6 changes: 3 additions & 3 deletions apps/documentation/pages/reference/checks.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
```
Expand All @@ -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 }),
};
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<PackageJson> = {
Expand All @@ -139,7 +139,7 @@ export const devPeerDependencyRange = defineCheck(() => {
return {
title,
suggestion: diff(source, target),
filepath: 'package.json',
filePath: 'package.json',
};
},
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)),
};
},
Expand Down
Original file line number Diff line number Diff line change
@@ -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 = [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,22 +134,22 @@ 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.',
};
}

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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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',
};
},
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,15 @@ export const validPackageName = defineCheck(() => ({
if (!packageJson || !packageJson.name) {
return {
title: 'Package name must be set in package.json',
filepath: 'package.json',
filePath: 'package.json',
};
}

const result = validateNpmPackageName(packageJson.name);

return {
title: 'Invalid package name',
filepath: 'package.json',
filePath: 'package.json',
suggestion: result.errors
? result.errors.join('\n')
: result.warnings?.join('\n'),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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',
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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');
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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']);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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',
Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -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: {
Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -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\\",
Expand Down Expand Up @@ -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');
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand All @@ -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');
});
});
});
Original file line number Diff line number Diff line change
@@ -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';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ type FunctionType<T = unknown> = (options: CheckOptions) => Awaitable<T>;
type TestConformer<T> = {
[P in keyof T]: P extends 'fix' | 'message' | 'validate'
? T[P] extends FunctionType
? () => ReturnType<T[P]>
? () => Promise<ReturnType<T[P]>>
: T[P]
: T[P];
};
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// packages/shared/ui-package/vitest.config.ts
import { defineConfig } from "file:///Users/alecortega/workspace/commonalityco/node_modules/.pnpm/[email protected]_@[email protected]/node_modules/vitest/dist/config.js";
import react from "file:///Users/alecortega/workspace/commonalityco/node_modules/.pnpm/@[email protected][email protected]/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,ewogICJ2ZXJzaW9uIjogMywKICAic291cmNlcyI6IFsicGFja2FnZXMvc2hhcmVkL3VpLXBhY2thZ2Uvdml0ZXN0LmNvbmZpZy50cyJdLAogICJzb3VyY2VzQ29udGVudCI6IFsiY29uc3QgX192aXRlX2luamVjdGVkX29yaWdpbmFsX2Rpcm5hbWUgPSBcIi9Vc2Vycy9hbGVjb3J0ZWdhL3dvcmtzcGFjZS9jb21tb25hbGl0eWNvL3BhY2thZ2VzL3NoYXJlZC91aS1wYWNrYWdlXCI7Y29uc3QgX192aXRlX2luamVjdGVkX29yaWdpbmFsX2ZpbGVuYW1lID0gXCIvVXNlcnMvYWxlY29ydGVnYS93b3Jrc3BhY2UvY29tbW9uYWxpdHljby9wYWNrYWdlcy9zaGFyZWQvdWktcGFja2FnZS92aXRlc3QuY29uZmlnLnRzXCI7Y29uc3QgX192aXRlX2luamVjdGVkX29yaWdpbmFsX2ltcG9ydF9tZXRhX3VybCA9IFwiZmlsZTovLy9Vc2Vycy9hbGVjb3J0ZWdhL3dvcmtzcGFjZS9jb21tb25hbGl0eWNvL3BhY2thZ2VzL3NoYXJlZC91aS1wYWNrYWdlL3ZpdGVzdC5jb25maWcudHNcIjtpbXBvcnQgeyBkZWZpbmVDb25maWcgfSBmcm9tICd2aXRlc3QvY29uZmlnJztcbmltcG9ydCByZWFjdCBmcm9tICdAdml0ZWpzL3BsdWdpbi1yZWFjdC1zd2MnO1xuXG5leHBvcnQgZGVmYXVsdCBkZWZpbmVDb25maWcoe1xuICBwbHVnaW5zOiBbcmVhY3QoKV0sXG4gIHRlc3Q6IHtcbiAgICBnbG9iYWxzOiB0cnVlLFxuICAgIGVudmlyb25tZW50OiAnanNkb20nLFxuICAgIHRocmVhZHM6IGZhbHNlLFxuICAgIHNldHVwRmlsZXM6IFsnLi90ZXN0L3NldHVwLnRzJ10sXG4gIH0sXG59KTtcbiJdLAogICJtYXBwaW5ncyI6ICI7QUFBa1ksU0FBUyxvQkFBb0I7QUFDL1osT0FBTyxXQUFXO0FBRWxCLElBQU8sd0JBQVEsYUFBYTtBQUFBLEVBQzFCLFNBQVMsQ0FBQyxNQUFNLENBQUM7QUFBQSxFQUNqQixNQUFNO0FBQUEsSUFDSixTQUFTO0FBQUEsSUFDVCxhQUFhO0FBQUEsSUFDYixTQUFTO0FBQUEsSUFDVCxZQUFZLENBQUMsaUJBQWlCO0FBQUEsRUFDaEM7QUFDRixDQUFDOyIsCiAgIm5hbWVzIjogW10KfQo=
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// packages/shared/ui-package/vitest.config.ts
import { defineConfig } from "file:///Users/alecortega/workspace/commonalityco/node_modules/.pnpm/[email protected]_@[email protected]/node_modules/vitest/dist/config.js";
import react from "file:///Users/alecortega/workspace/commonalityco/node_modules/.pnpm/@[email protected][email protected]/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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