Skip to content

Commit

Permalink
feat: better warns for checks
Browse files Browse the repository at this point in the history
  • Loading branch information
christophehurpeau committed Mar 12, 2022
1 parent 0da17e3 commit 18c47ef
Show file tree
Hide file tree
Showing 53 changed files with 1,442 additions and 537 deletions.
10 changes: 8 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,21 @@ createCheckPackage(/* '.' */)
isLibrary: false,
})
.checkDirectPeerDependencies({
onlyWarnsFor: [],
// Allow to only warn for not respected peer dependencies.
// Example: { '@babel/cli': ['@babel/core'] }
// Only warns for missing "@babel/core" peer dependency asked in "@babel/cli".
// You can also use "*" for any library
// { '*': ['semver'] }
missingOnlyWarnsFor: {},
invalidOnlyWarnsFor: {},
})
// Check that there are no duplicates among your dependencies and your devDependencies.
// For example, If you use "@babel/core": "7.0.0" and one of your direct dependency requires "^7.0.1" (in dependencies, not peerDependency)
// you will have two versions of @babel/core. This check will display an error that can be changed to a warning.
// You will probably need to add warnings for common library where duplicate have low impact,
// like type-fest or fast-deep-equal.
.checkDirectDuplicateDependencies({
onlyWarnsFor: ['type-fest'],
onlyWarnsFor: { '*': 'type-fest' },
})
// Check that all your resolutions are also present in an "resolutionsExplained" field, forcing you to explain why the resolution was necessary
.checkResolutionsHasExplanation()
Expand Down
16 changes: 13 additions & 3 deletions dist/check-package-with-workspaces.d.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,21 @@
import type { OnlyWarnsFor } from 'utils/shouldOnlyWarnFor';
import type { CheckPackageApi, CreateCheckPackageOptions } from './check-package';
import type { CreateCheckPackageOptions, CheckPackageApi, OnlyWarnsForInDependenciesCheckPackageRecommendedOption, OnlyWarnsForInDependencyCheckPackageRecommendedOption, OnlyWarnsForInPackageCheckPackageRecommendedOption } from './check-package';
import type { CheckResolutionMessage } from './checks/checkResolutionsHasExplanation';
import type { OnlyWarnsFor, OnlyWarnsForOptionalDependencyMapping } from './utils/warnForUtils';
interface OnlyWarnsForInMonorepoPackageCheckPackageRecommendedOption extends OnlyWarnsForInPackageCheckPackageRecommendedOption {
duplicateDirectDependency: OnlyWarnsForInDependencyCheckPackageRecommendedOption['duplicateDirectDependency'];
}
declare type OnlyWarnsForInMonorepoPackagesCheckPackageRecommendedOption = Record<'*' | string, OnlyWarnsForInMonorepoPackageCheckPackageRecommendedOption>;
export interface CheckPackageWithWorkspacesRecommendedOptions {
isLibrary?: (pkgName: string) => boolean;
allowRangeVersionsInLibraries?: boolean;
/** @deprecated use onlyWarnsFor */
peerDependenciesOnlyWarnsFor?: OnlyWarnsFor;
/** @deprecated use onlyWarnsFor */
directDuplicateDependenciesOnlyWarnsFor?: OnlyWarnsFor;
monorepoDirectDuplicateDependenciesOnlyWarnsFor?: OnlyWarnsFor;
monorepoDirectDuplicateDependenciesOnlyWarnsFor?: OnlyWarnsForOptionalDependencyMapping;
onlyWarnsForInRootPackage?: OnlyWarnsForInPackageCheckPackageRecommendedOption;
onlyWarnsForInMonorepoPackages?: OnlyWarnsForInMonorepoPackagesCheckPackageRecommendedOption;
onlyWarnsForInDependencies?: OnlyWarnsForInDependenciesCheckPackageRecommendedOption;
checkResolutionMessage?: CheckResolutionMessage;
}
export interface CheckPackageWithWorkspacesApi {
Expand All @@ -16,4 +25,5 @@ export interface CheckPackageWithWorkspacesApi {
for: (id: string, callback: (checkPackage: CheckPackageApi) => void) => CheckPackageWithWorkspacesApi;
}
export declare function createCheckPackageWithWorkspaces(pkgDirectoryPath?: string, createCheckPackageOptions?: CreateCheckPackageOptions): CheckPackageWithWorkspacesApi;
export {};
//# sourceMappingURL=check-package-with-workspaces.d.ts.map
2 changes: 1 addition & 1 deletion dist/check-package-with-workspaces.d.ts.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

31 changes: 24 additions & 7 deletions dist/check-package.d.ts
Original file line number Diff line number Diff line change
@@ -1,29 +1,46 @@
import type { OnlyWarnsFor } from 'utils/shouldOnlyWarnFor';
import type { CheckResolutionMessage } from './checks/checkResolutionsHasExplanation';
import type { GetDependencyPackageJson } from './utils/createGetDependencyPackageJson';
import type { DependencyTypes, PackageJson } from './utils/packageTypes';
import type { OnlyWarnsForOptionalDependencyMapping, OnlyWarnsFor } from './utils/warnForUtils';
export interface CreateCheckPackageOptions {
tryToAutoFix?: boolean;
}
export interface CheckDirectPeerDependenciesOptions {
isLibrary?: boolean;
onlyWarnsFor?: OnlyWarnsFor;
/** @deprecated use missingOnlyWarnsFor or invalidOnlyWarnsFor */
onlyWarnsFor?: OnlyWarnsForOptionalDependencyMapping;
missingOnlyWarnsFor?: OnlyWarnsForOptionalDependencyMapping;
invalidOnlyWarnsFor?: OnlyWarnsForOptionalDependencyMapping;
internalMissingConfigName?: string;
internalInvalidConfigName?: string;
}
export interface CheckDirectDuplicateDependenciesOptions {
onlyWarnsFor?: OnlyWarnsFor;
/** @internal */
internalWarnedForDuplicate?: Set<string>;
onlyWarnsFor?: OnlyWarnsForOptionalDependencyMapping;
internalConfigName?: string;
}
export interface OnlyWarnsForInPackageCheckPackageRecommendedOption {
exactVersions: OnlyWarnsFor;
}
export interface OnlyWarnsForInDependencyCheckPackageRecommendedOption {
duplicateDirectDependency: OnlyWarnsFor;
missingPeerDependency: OnlyWarnsFor;
invalidPeerDependencyVersion: OnlyWarnsFor;
}
export declare type OnlyWarnsForInDependenciesCheckPackageRecommendedOption = Record<'*' | string, OnlyWarnsForInDependencyCheckPackageRecommendedOption>;
export interface CheckRecommendedOptions {
isLibrary?: boolean;
/** default is true for libraries, false otherwise */
allowRangeVersionsInDependencies?: boolean;
onlyWarnsForInPackage?: OnlyWarnsForInPackageCheckPackageRecommendedOption;
onlyWarnsForInDependencies?: OnlyWarnsForInDependenciesCheckPackageRecommendedOption;
/** @deprecated use onlyWarnsForInDependencies option */
peerDependenciesOnlyWarnsFor?: OnlyWarnsFor;
/** @deprecated use onlyWarnsForInDependencies option */
directDuplicateDependenciesOnlyWarnsFor?: OnlyWarnsFor;
/** @deprecated use onlyWarnsForInPackage option */
exactVersionsOnlyWarnsFor?: OnlyWarnsFor;
/** function to check the value in the "resolutionExplained" key in package.json */
checkResolutionMessage?: CheckResolutionMessage;
/** @internal */
internalWarnedForDuplicate?: Set<string>;
}
export interface CheckExactVersionsOptions {
allowRangeVersionsInDependencies?: boolean;
Expand Down
2 changes: 1 addition & 1 deletion dist/check-package.d.ts.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions dist/checks/checkDirectDuplicateDependencies.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { ReportError } from '../utils/createReportError';
import type { GetDependencyPackageJson } from 'utils/createGetDependencyPackageJson';
import type { PackageJson, DependencyTypes } from '../utils/packageTypes';
export declare function checkWarnedFor(reportError: ReportError, warnedFor: Set<string>, onlyWarnsFor?: string[]): void;
export declare function checkDirectDuplicateDependencies(pkg: PackageJson, pkgPathName: string, depType: DependencyTypes, searchIn: DependencyTypes[], depPkg: PackageJson, onlyWarnsFor?: string[], warnedForInternal?: Set<string>, reportErrorNamePrefix?: string): void;
import type { OnlyWarnsForMappingCheck } from '../utils/warnForUtils';
export declare function checkDirectDuplicateDependencies(pkg: PackageJson, pkgPathName: string, depType: DependencyTypes, getDependencyPackageJson: GetDependencyPackageJson, onlyWarnsForCheck: OnlyWarnsForMappingCheck, reportErrorNamePrefix?: string): void;
//# sourceMappingURL=checkDirectDuplicateDependencies.d.ts.map
2 changes: 1 addition & 1 deletion dist/checks/checkDirectDuplicateDependencies.d.ts.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions dist/checks/checkDirectPeerDependencies.d.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import type { PackageJson, RegularDependencyTypes } from '../utils/packageTypes';
export declare function checkDirectPeerDependencies(isLibrary: boolean, pkg: PackageJson, pkgPathName: string, depPkgType: RegularDependencyTypes, depPkg: PackageJson, onlyWarnsFor?: string[]): void;
import type { GetDependencyPackageJson } from 'utils/createGetDependencyPackageJson';
import type { PackageJson } from '../utils/packageTypes';
import type { OnlyWarnsForMappingCheck } from '../utils/warnForUtils';
export declare function checkDirectPeerDependencies(isLibrary: boolean, pkg: PackageJson, pkgPathName: string, getDependencyPackageJson: GetDependencyPackageJson, missingOnlyWarnsForCheck: OnlyWarnsForMappingCheck, invalidOnlyWarnsForCheck: OnlyWarnsForMappingCheck): void;
//# sourceMappingURL=checkDirectPeerDependencies.d.ts.map
2 changes: 1 addition & 1 deletion dist/checks/checkDirectPeerDependencies.d.ts.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions dist/checks/checkDuplicateDependencies.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import type { ReportError } from '../utils/createReportError';
import type { PackageJson, DependencyTypes } from '../utils/packageTypes';
import type { OnlyWarnsForCheck } from '../utils/warnForUtils';
export declare function checkDuplicateDependencies(reportError: ReportError, pkg: PackageJson, depType: DependencyTypes, searchIn: DependencyTypes[], depPkg: PackageJson, onlyWarnsForCheck: OnlyWarnsForCheck): void;
//# sourceMappingURL=checkDuplicateDependencies.d.ts.map
1 change: 1 addition & 0 deletions dist/checks/checkDuplicateDependencies.d.ts.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 18c47ef

Please sign in to comment.