repopo 0.12.0 → 0.13.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +53 -0
- package/README.md +50 -90
- package/THIRD-PARTY-LICENSES.txt +169 -11
- package/bin/dev.js +0 -0
- package/esm/adapters/fluidFramework.d.ts +13 -9
- package/esm/adapters/fluidFramework.d.ts.map +1 -1
- package/esm/adapters/fluidFramework.js +20 -43
- package/esm/adapters/fluidFramework.js.map +1 -1
- package/esm/api.d.ts +64 -1
- package/esm/api.d.ts.map +1 -1
- package/esm/api.js +17 -1
- package/esm/api.js.map +1 -1
- package/esm/baseCommand.d.ts.map +1 -1
- package/esm/baseCommand.js +2 -2
- package/esm/baseCommand.js.map +1 -1
- package/esm/commands/check-native.d.ts +3 -3
- package/esm/commands/check-native.d.ts.map +1 -1
- package/esm/commands/check-native.js +26 -7
- package/esm/commands/check-native.js.map +1 -1
- package/esm/commands/check.d.ts +6 -21
- package/esm/commands/check.d.ts.map +1 -1
- package/esm/commands/check.js +73 -153
- package/esm/commands/check.js.map +1 -1
- package/esm/commands/list.d.ts.map +1 -1
- package/esm/commands/list.js +2 -1
- package/esm/commands/list.js.map +1 -1
- package/esm/concurrency.d.ts +3 -0
- package/esm/concurrency.d.ts.map +1 -0
- package/esm/concurrency.js +8 -0
- package/esm/concurrency.js.map +1 -0
- package/esm/config.d.ts +5 -39
- package/esm/config.d.ts.map +1 -1
- package/esm/config.js +3 -7
- package/esm/config.js.map +1 -1
- package/esm/context.d.ts +8 -1
- package/esm/context.d.ts.map +1 -1
- package/esm/context.js +8 -1
- package/esm/context.js.map +1 -1
- package/esm/executionContractError.d.ts +4 -0
- package/esm/executionContractError.d.ts.map +1 -0
- package/esm/executionContractError.js +4 -0
- package/esm/executionContractError.js.map +1 -0
- package/esm/fileCache.d.ts +12 -0
- package/esm/fileCache.d.ts.map +1 -0
- package/esm/fileCache.js +37 -0
- package/esm/fileCache.js.map +1 -0
- package/esm/filePaths.d.ts +2 -0
- package/esm/filePaths.d.ts.map +1 -0
- package/esm/filePaths.js +9 -0
- package/esm/filePaths.js.map +1 -0
- package/esm/generators.d.ts +0 -20
- package/esm/generators.d.ts.map +1 -1
- package/esm/generators.js.map +1 -1
- package/esm/index.d.ts +3 -16
- package/esm/index.d.ts.map +1 -1
- package/esm/index.js +3 -17
- package/esm/index.js.map +1 -1
- package/esm/makePolicy.d.ts +20 -100
- package/esm/makePolicy.d.ts.map +1 -1
- package/esm/makePolicy.js +44 -132
- package/esm/makePolicy.js.map +1 -1
- package/esm/perf.d.ts +5 -2
- package/esm/perf.d.ts.map +1 -1
- package/esm/perf.js +10 -9
- package/esm/perf.js.map +1 -1
- package/esm/policies/CargoLicenceValidated.d.ts +4 -4
- package/esm/policies/CargoLicenceValidated.d.ts.map +1 -1
- package/esm/policies/CargoLicenceValidated.js +9 -7
- package/esm/policies/CargoLicenceValidated.js.map +1 -1
- package/esm/policies/CargoLintsConfigured.d.ts +4 -4
- package/esm/policies/CargoLintsConfigured.d.ts.map +1 -1
- package/esm/policies/CargoLintsConfigured.js +19 -15
- package/esm/policies/CargoLintsConfigured.js.map +1 -1
- package/esm/policies/CargoLockPolicy.d.ts +4 -4
- package/esm/policies/CargoLockPolicy.d.ts.map +1 -1
- package/esm/policies/CargoLockPolicy.js +15 -11
- package/esm/policies/CargoLockPolicy.js.map +1 -1
- package/esm/policies/CargoTomlRequired.d.ts +5 -5
- package/esm/policies/CargoTomlRequired.d.ts.map +1 -1
- package/esm/policies/CargoTomlRequired.js +7 -7
- package/esm/policies/CargoTomlRequired.js.map +1 -1
- package/esm/policies/CargoTomlSorted.d.ts +4 -4
- package/esm/policies/CargoTomlSorted.d.ts.map +1 -1
- package/esm/policies/CargoTomlSorted.js +21 -17
- package/esm/policies/CargoTomlSorted.js.map +1 -1
- package/esm/policies/ConditionalScripts.d.ts +10 -8
- package/esm/policies/ConditionalScripts.d.ts.map +1 -1
- package/esm/policies/ConditionalScripts.js +24 -22
- package/esm/policies/ConditionalScripts.js.map +1 -1
- package/esm/policies/ExactScripts.d.ts +8 -6
- package/esm/policies/ExactScripts.d.ts.map +1 -1
- package/esm/policies/ExactScripts.js +15 -18
- package/esm/policies/ExactScripts.js.map +1 -1
- package/esm/policies/GleamDepVersions.d.ts +5 -5
- package/esm/policies/GleamDepVersions.d.ts.map +1 -1
- package/esm/policies/GleamDepVersions.js +5 -5
- package/esm/policies/GleamDepVersions.js.map +1 -1
- package/esm/policies/GleamDocExists.d.ts +4 -4
- package/esm/policies/GleamDocExists.d.ts.map +1 -1
- package/esm/policies/GleamDocExists.js +6 -6
- package/esm/policies/GleamDocExists.js.map +1 -1
- package/esm/policies/GleamInternalModulesConfigured.d.ts +4 -4
- package/esm/policies/GleamInternalModulesConfigured.d.ts.map +1 -1
- package/esm/policies/GleamInternalModulesConfigured.js +8 -6
- package/esm/policies/GleamInternalModulesConfigured.js.map +1 -1
- package/esm/policies/GleamLicenceConfigured.d.ts +4 -4
- package/esm/policies/GleamLicenceConfigured.d.ts.map +1 -1
- package/esm/policies/GleamLicenceConfigured.js +8 -6
- package/esm/policies/GleamLicenceConfigured.js.map +1 -1
- package/esm/policies/GleamManifestCommitted.d.ts +10 -3
- package/esm/policies/GleamManifestCommitted.d.ts.map +1 -1
- package/esm/policies/GleamManifestCommitted.js +10 -9
- package/esm/policies/GleamManifestCommitted.js.map +1 -1
- package/esm/policies/GleamMonorepoConsistency.d.ts +13 -5
- package/esm/policies/GleamMonorepoConsistency.d.ts.map +1 -1
- package/esm/policies/GleamMonorepoConsistency.js +10 -10
- package/esm/policies/GleamMonorepoConsistency.js.map +1 -1
- package/esm/policies/GleamNameRestrictions.d.ts +4 -4
- package/esm/policies/GleamNameRestrictions.d.ts.map +1 -1
- package/esm/policies/GleamNameRestrictions.js +6 -6
- package/esm/policies/GleamNameRestrictions.js.map +1 -1
- package/esm/policies/GleamNoPathDepsInPublished.d.ts +4 -4
- package/esm/policies/GleamNoPathDepsInPublished.d.ts.map +1 -1
- package/esm/policies/GleamNoPathDepsInPublished.js +6 -6
- package/esm/policies/GleamNoPathDepsInPublished.js.map +1 -1
- package/esm/policies/GleamPathDepsValid.d.ts +3 -3
- package/esm/policies/GleamPathDepsValid.d.ts.map +1 -1
- package/esm/policies/GleamPathDepsValid.js +5 -5
- package/esm/policies/GleamPathDepsValid.js.map +1 -1
- package/esm/policies/GleamProjectStructure.d.ts +11 -4
- package/esm/policies/GleamProjectStructure.d.ts.map +1 -1
- package/esm/policies/GleamProjectStructure.js +7 -8
- package/esm/policies/GleamProjectStructure.js.map +1 -1
- package/esm/policies/GleamSharedDependencyVersions.d.ts +12 -4
- package/esm/policies/GleamSharedDependencyVersions.d.ts.map +1 -1
- package/esm/policies/GleamSharedDependencyVersions.js +10 -10
- package/esm/policies/GleamSharedDependencyVersions.js.map +1 -1
- package/esm/policies/GleamTomlRequired.d.ts +4 -4
- package/esm/policies/GleamTomlRequired.d.ts.map +1 -1
- package/esm/policies/GleamTomlRequired.js +5 -5
- package/esm/policies/GleamTomlRequired.js.map +1 -1
- package/esm/policies/GleamTomlSorted.d.ts +4 -4
- package/esm/policies/GleamTomlSorted.d.ts.map +1 -1
- package/esm/policies/GleamTomlSorted.js +21 -17
- package/esm/policies/GleamTomlSorted.js.map +1 -1
- package/esm/policies/GleamVersionConstraint.d.ts +4 -4
- package/esm/policies/GleamVersionConstraint.d.ts.map +1 -1
- package/esm/policies/GleamVersionConstraint.js +14 -10
- package/esm/policies/GleamVersionConstraint.js.map +1 -1
- package/esm/policies/HtmlFileHeaders.d.ts +4 -2
- package/esm/policies/HtmlFileHeaders.d.ts.map +1 -1
- package/esm/policies/HtmlFileHeaders.js +1 -1
- package/esm/policies/HtmlFileHeaders.js.map +1 -1
- package/esm/policies/JsTsFileHeaders.d.ts +4 -2
- package/esm/policies/JsTsFileHeaders.d.ts.map +1 -1
- package/esm/policies/JsTsFileHeaders.js +1 -1
- package/esm/policies/JsTsFileHeaders.js.map +1 -1
- package/esm/policies/LicenseFileExists.d.ts +10 -4
- package/esm/policies/LicenseFileExists.d.ts.map +1 -1
- package/esm/policies/LicenseFileExists.js +27 -20
- package/esm/policies/LicenseFileExists.js.map +1 -1
- package/esm/policies/MutuallyExclusiveScripts.d.ts +8 -6
- package/esm/policies/MutuallyExclusiveScripts.d.ts.map +1 -1
- package/esm/policies/MutuallyExclusiveScripts.js +9 -13
- package/esm/policies/MutuallyExclusiveScripts.js.map +1 -1
- package/esm/policies/NoBuildDirectory.d.ts +9 -3
- package/esm/policies/NoBuildDirectory.d.ts.map +1 -1
- package/esm/policies/NoBuildDirectory.js +8 -13
- package/esm/policies/NoBuildDirectory.js.map +1 -1
- package/esm/policies/NoJsFileExtensions.d.ts +9 -3
- package/esm/policies/NoJsFileExtensions.d.ts.map +1 -1
- package/esm/policies/NoJsFileExtensions.js +9 -14
- package/esm/policies/NoJsFileExtensions.js.map +1 -1
- package/esm/policies/NoLargeBinaryFiles.d.ts +9 -4
- package/esm/policies/NoLargeBinaryFiles.d.ts.map +1 -1
- package/esm/policies/NoLargeBinaryFiles.js +10 -16
- package/esm/policies/NoLargeBinaryFiles.js.map +1 -1
- package/esm/policies/NoPrivateWorkspaceDependencies.d.ts +10 -6
- package/esm/policies/NoPrivateWorkspaceDependencies.d.ts.map +1 -1
- package/esm/policies/NoPrivateWorkspaceDependencies.js +12 -14
- package/esm/policies/NoPrivateWorkspaceDependencies.js.map +1 -1
- package/esm/policies/NoTargetArtifacts.d.ts +9 -3
- package/esm/policies/NoTargetArtifacts.d.ts.map +1 -1
- package/esm/policies/NoTargetArtifacts.js +9 -14
- package/esm/policies/NoTargetArtifacts.js.map +1 -1
- package/esm/policies/NoUnsafeWithoutJustification.d.ts +11 -4
- package/esm/policies/NoUnsafeWithoutJustification.d.ts.map +1 -1
- package/esm/policies/NoUnsafeWithoutJustification.js +8 -9
- package/esm/policies/NoUnsafeWithoutJustification.js.map +1 -1
- package/esm/policies/NoWildcardDependencies.d.ts +5 -5
- package/esm/policies/NoWildcardDependencies.d.ts.map +1 -1
- package/esm/policies/NoWildcardDependencies.js +6 -6
- package/esm/policies/NoWildcardDependencies.js.map +1 -1
- package/esm/policies/PackageAllowedScopes.d.ts +9 -5
- package/esm/policies/PackageAllowedScopes.d.ts.map +1 -1
- package/esm/policies/PackageAllowedScopes.js +15 -16
- package/esm/policies/PackageAllowedScopes.js.map +1 -1
- package/esm/policies/PackageEsmType.d.ts +7 -5
- package/esm/policies/PackageEsmType.d.ts.map +1 -1
- package/esm/policies/PackageEsmType.js +31 -31
- package/esm/policies/PackageEsmType.js.map +1 -1
- package/esm/policies/PackageFolderName.d.ts +8 -6
- package/esm/policies/PackageFolderName.d.ts.map +1 -1
- package/esm/policies/PackageFolderName.js +13 -16
- package/esm/policies/PackageFolderName.js.map +1 -1
- package/esm/policies/PackageJsonProperties.d.ts +5 -3
- package/esm/policies/PackageJsonProperties.d.ts.map +1 -1
- package/esm/policies/PackageJsonProperties.js +6 -17
- package/esm/policies/PackageJsonProperties.js.map +1 -1
- package/esm/policies/PackageJsonRepoDirectoryProperty.d.ts +2 -7
- package/esm/policies/PackageJsonRepoDirectoryProperty.d.ts.map +1 -1
- package/esm/policies/PackageJsonRepoDirectoryProperty.js +28 -42
- package/esm/policies/PackageJsonRepoDirectoryProperty.js.map +1 -1
- package/esm/policies/PackageJsonSorted.d.ts +2 -2
- package/esm/policies/PackageJsonSorted.d.ts.map +1 -1
- package/esm/policies/PackageJsonSorted.js +15 -30
- package/esm/policies/PackageJsonSorted.js.map +1 -1
- package/esm/policies/PackageLicense.d.ts +4 -4
- package/esm/policies/PackageLicense.d.ts.map +1 -1
- package/esm/policies/PackageLicense.js +31 -52
- package/esm/policies/PackageLicense.js.map +1 -1
- package/esm/policies/PackagePrivateField.d.ts +12 -8
- package/esm/policies/PackagePrivateField.d.ts.map +1 -1
- package/esm/policies/PackagePrivateField.js +31 -23
- package/esm/policies/PackagePrivateField.js.map +1 -1
- package/esm/policies/PackageReadme.d.ts +6 -5
- package/esm/policies/PackageReadme.d.ts.map +1 -1
- package/esm/policies/PackageReadme.js +22 -59
- package/esm/policies/PackageReadme.js.map +1 -1
- package/esm/policies/PackageScripts.d.ts +26 -22
- package/esm/policies/PackageScripts.d.ts.map +1 -1
- package/esm/policies/PackageScripts.js +39 -36
- package/esm/policies/PackageScripts.js.map +1 -1
- package/esm/policies/PackageTestScripts.d.ts +10 -6
- package/esm/policies/PackageTestScripts.d.ts.map +1 -1
- package/esm/policies/PackageTestScripts.js +14 -16
- package/esm/policies/PackageTestScripts.js.map +1 -1
- package/esm/policies/PublicApiDocumented.d.ts +4 -4
- package/esm/policies/PublicApiDocumented.d.ts.map +1 -1
- package/esm/policies/PublicApiDocumented.js +10 -8
- package/esm/policies/PublicApiDocumented.js.map +1 -1
- package/esm/policies/RequiredGitignorePatterns.d.ts +11 -4
- package/esm/policies/RequiredGitignorePatterns.d.ts.map +1 -1
- package/esm/policies/RequiredGitignorePatterns.js +29 -36
- package/esm/policies/RequiredGitignorePatterns.js.map +1 -1
- package/esm/policies/RequiredScripts.d.ts +9 -7
- package/esm/policies/RequiredScripts.d.ts.map +1 -1
- package/esm/policies/RequiredScripts.js +24 -24
- package/esm/policies/RequiredScripts.js.map +1 -1
- package/esm/policies/RustDocExists.d.ts +4 -4
- package/esm/policies/RustDocExists.d.ts.map +1 -1
- package/esm/policies/RustDocExists.js +6 -6
- package/esm/policies/RustDocExists.js.map +1 -1
- package/esm/policies/RustToolchainExists.d.ts +11 -4
- package/esm/policies/RustToolchainExists.d.ts.map +1 -1
- package/esm/policies/RustToolchainExists.js +10 -9
- package/esm/policies/RustToolchainExists.js.map +1 -1
- package/esm/policies/RustfmtConfigExists.d.ts +11 -4
- package/esm/policies/RustfmtConfigExists.d.ts.map +1 -1
- package/esm/policies/RustfmtConfigExists.js +10 -9
- package/esm/policies/RustfmtConfigExists.js.map +1 -1
- package/esm/policies/ScriptContains.d.ts +9 -7
- package/esm/policies/ScriptContains.d.ts.map +1 -1
- package/esm/policies/ScriptContains.js +9 -13
- package/esm/policies/ScriptContains.js.map +1 -1
- package/esm/policies/SharedDependencyVersions.d.ts +9 -4
- package/esm/policies/SharedDependencyVersions.d.ts.map +1 -1
- package/esm/policies/SharedDependencyVersions.js +28 -20
- package/esm/policies/SharedDependencyVersions.js.map +1 -1
- package/esm/policies/WorkspaceInheritance.d.ts +11 -4
- package/esm/policies/WorkspaceInheritance.d.ts.map +1 -1
- package/esm/policies/WorkspaceInheritance.js +10 -11
- package/esm/policies/WorkspaceInheritance.js.map +1 -1
- package/esm/policies/WorkspaceMembersValid.d.ts +11 -4
- package/esm/policies/WorkspaceMembersValid.d.ts.map +1 -1
- package/esm/policies/WorkspaceMembersValid.js +10 -11
- package/esm/policies/WorkspaceMembersValid.js.map +1 -1
- package/esm/policies/constants.d.ts.map +1 -1
- package/esm/policies/constants.js +1 -1
- package/esm/policies/constants.js.map +1 -1
- package/esm/policies.d.ts +13 -5
- package/esm/policies.d.ts.map +1 -1
- package/esm/policies.js +12 -5
- package/esm/policies.js.map +1 -1
- package/esm/policy.d.ts +61 -289
- package/esm/policy.d.ts.map +1 -1
- package/esm/policy.js +1 -122
- package/esm/policy.js.map +1 -1
- package/esm/policyDefiners/defineCargoPolicy.d.ts +25 -9
- package/esm/policyDefiners/defineCargoPolicy.d.ts.map +1 -1
- package/esm/policyDefiners/defineCargoPolicy.js +10 -28
- package/esm/policyDefiners/defineCargoPolicy.js.map +1 -1
- package/esm/policyDefiners/defineFileHeaderPolicy.d.ts +27 -14
- package/esm/policyDefiners/defineFileHeaderPolicy.d.ts.map +1 -1
- package/esm/policyDefiners/defineFileHeaderPolicy.js +16 -35
- package/esm/policyDefiners/defineFileHeaderPolicy.js.map +1 -1
- package/esm/policyDefiners/defineGleamPolicy.d.ts +25 -9
- package/esm/policyDefiners/defineGleamPolicy.d.ts.map +1 -1
- package/esm/policyDefiners/defineGleamPolicy.js +10 -27
- package/esm/policyDefiners/defineGleamPolicy.js.map +1 -1
- package/esm/policyDefiners/definePackagePolicy.d.ts +24 -13
- package/esm/policyDefiners/definePackagePolicy.d.ts.map +1 -1
- package/esm/policyDefiners/definePackagePolicy.js +9 -32
- package/esm/policyDefiners/definePackagePolicy.js.map +1 -1
- package/esm/policyDefiners/spdxValidator.d.ts +4 -12
- package/esm/policyDefiners/spdxValidator.d.ts.map +1 -1
- package/esm/policyDefiners/spdxValidator.js +26 -14
- package/esm/policyDefiners/spdxValidator.js.map +1 -1
- package/esm/policyExecution.d.ts +19 -0
- package/esm/policyExecution.d.ts.map +1 -0
- package/esm/policyExecution.js +224 -0
- package/esm/policyExecution.js.map +1 -0
- package/esm/repositoryFiles.d.ts +4 -0
- package/esm/repositoryFiles.d.ts.map +1 -0
- package/esm/repositoryFiles.js +8 -0
- package/esm/repositoryFiles.js.map +1 -0
- package/esm/runner.d.ts +72 -47
- package/esm/runner.d.ts.map +1 -1
- package/esm/runner.js +153 -138
- package/esm/runner.js.map +1 -1
- package/esm/settlePolicyPromise.d.ts +4 -0
- package/esm/settlePolicyPromise.d.ts.map +1 -0
- package/esm/settlePolicyPromise.js +10 -0
- package/esm/settlePolicyPromise.js.map +1 -0
- package/esm/tsdoc-metadata.json +1 -1
- package/esm/utils/safePaths.d.ts +9 -0
- package/esm/utils/safePaths.d.ts.map +1 -0
- package/esm/utils/safePaths.js +40 -0
- package/esm/utils/safePaths.js.map +1 -0
- package/oclif.manifest.json +19 -2
- package/package.json +42 -27
- package/scripts/benchmark.mjs +341 -0
- package/sidecar/sidecar.mjs +348 -417
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
import { existsSync } from "node:fs";
|
|
2
2
|
import path from "pathe";
|
|
3
|
-
import { makePolicyDefinition } from "../makePolicy.js";
|
|
4
3
|
const DEFAULT_NAMES = ["rust-toolchain.toml", "rust-toolchain"];
|
|
5
4
|
/**
|
|
6
5
|
* A policy that requires a rust-toolchain.toml file for reproducible Rust builds.
|
|
7
6
|
*
|
|
8
|
-
* @
|
|
7
|
+
* @public
|
|
9
8
|
*/
|
|
10
|
-
export const RustToolchainExists =
|
|
9
|
+
export const RustToolchainExists = {
|
|
11
10
|
name: "RustToolchainExists",
|
|
12
11
|
description: "Ensures a rust-toolchain.toml file exists for reproducible Rust builds.",
|
|
13
12
|
// Trigger on Cargo.toml to check once per project
|
|
@@ -16,12 +15,14 @@ export const RustToolchainExists = makePolicyDefinition({
|
|
|
16
15
|
const names = config?.acceptedNames ?? DEFAULT_NAMES;
|
|
17
16
|
const hasToolchain = names.some((name) => existsSync(path.join(root, name)));
|
|
18
17
|
if (hasToolchain) {
|
|
19
|
-
return
|
|
18
|
+
return [];
|
|
20
19
|
}
|
|
21
|
-
return
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
20
|
+
return [
|
|
21
|
+
{
|
|
22
|
+
message: `No rust-toolchain file found. Expected one of: ${names.join(", ")}`,
|
|
23
|
+
manualFix: "Create a rust-toolchain.toml file specifying the Rust toolchain version.",
|
|
24
|
+
},
|
|
25
|
+
];
|
|
25
26
|
},
|
|
26
|
-
}
|
|
27
|
+
};
|
|
27
28
|
//# sourceMappingURL=RustToolchainExists.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RustToolchainExists.js","sourceRoot":"","sources":["../../src/policies/RustToolchainExists.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AACrC,OAAO,IAAI,MAAM,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"RustToolchainExists.js","sourceRoot":"","sources":["../../src/policies/RustToolchainExists.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AACrC,OAAO,IAAI,MAAM,OAAO,CAAC;AAezB,MAAM,aAAa,GAAG,CAAC,qBAAqB,EAAE,gBAAgB,CAAC,CAAC;AAEhE;;;;GAIG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAG;IAClC,IAAI,EAAE,qBAAqB;IAC3B,WAAW,EACV,yEAAyE;IAC1E,kDAAkD;IAClD,KAAK,EAAE,eAAe;IACtB,OAAO,EAAE,KAAK,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE;QACnC,MAAM,KAAK,GAAG,MAAM,EAAE,aAAa,IAAI,aAAa,CAAC;QACrD,MAAM,YAAY,GAAG,KAAK,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE,CACxC,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC,CACjC,CAAC;QAEF,IAAI,YAAY,EAAE,CAAC;YAClB,OAAO,EAAE,CAAC;QACX,CAAC;QACD,OAAO;YACN;gBACC,OAAO,EAAE,kDAAkD,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE;gBAC7E,SAAS,EACR,0EAA0E;aAC3E;SACD,CAAC;IACH,CAAC;CACyD,CAAC","sourcesContent":["import { existsSync } from \"node:fs\";\nimport path from \"pathe\";\nimport type { FilePolicyDefinition } from \"../policy.js\";\n/**\n * Configuration for the RustToolchainExists policy.\n *\n * @public\n */\nexport interface RustToolchainExistsConfig {\n\t/**\n\t * Accepted file names for the toolchain file.\n\t * @defaultValue [\"rust-toolchain.toml\", \"rust-toolchain\"]\n\t */\n\tacceptedNames?: string[];\n}\n\nconst DEFAULT_NAMES = [\"rust-toolchain.toml\", \"rust-toolchain\"];\n\n/**\n * A policy that requires a rust-toolchain.toml file for reproducible Rust builds.\n *\n * @public\n */\nexport const RustToolchainExists = {\n\tname: \"RustToolchainExists\",\n\tdescription:\n\t\t\"Ensures a rust-toolchain.toml file exists for reproducible Rust builds.\",\n\t// Trigger on Cargo.toml to check once per project\n\tmatch: /^Cargo\\.toml$/,\n\thandler: async ({ root, config }) => {\n\t\tconst names = config?.acceptedNames ?? DEFAULT_NAMES;\n\t\tconst hasToolchain = names.some((name) =>\n\t\t\texistsSync(path.join(root, name)),\n\t\t);\n\n\t\tif (hasToolchain) {\n\t\t\treturn [];\n\t\t}\n\t\treturn [\n\t\t\t{\n\t\t\t\tmessage: `No rust-toolchain file found. Expected one of: ${names.join(\", \")}`,\n\t\t\t\tmanualFix:\n\t\t\t\t\t\"Create a rust-toolchain.toml file specifying the Rust toolchain version.\",\n\t\t\t},\n\t\t];\n\t},\n} satisfies FilePolicyDefinition<RustToolchainExistsConfig>;\n"]}
|
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import type { PolicyDefinition } from "../policy.js";
|
|
2
1
|
/**
|
|
3
2
|
* Configuration for the RustfmtConfigExists policy.
|
|
4
3
|
*
|
|
5
|
-
* @
|
|
4
|
+
* @public
|
|
6
5
|
*/
|
|
7
6
|
export interface RustfmtConfigExistsConfig {
|
|
8
7
|
/**
|
|
@@ -14,7 +13,15 @@ export interface RustfmtConfigExistsConfig {
|
|
|
14
13
|
/**
|
|
15
14
|
* A policy that requires a rustfmt.toml file for consistent Rust formatting.
|
|
16
15
|
*
|
|
17
|
-
* @
|
|
16
|
+
* @public
|
|
18
17
|
*/
|
|
19
|
-
export declare const RustfmtConfigExists:
|
|
18
|
+
export declare const RustfmtConfigExists: {
|
|
19
|
+
name: string;
|
|
20
|
+
description: string;
|
|
21
|
+
match: RegExp;
|
|
22
|
+
handler: ({ root, config }: import("../policy.js").PolicyArgs<RustfmtConfigExistsConfig>) => Promise<{
|
|
23
|
+
message: string;
|
|
24
|
+
manualFix: string;
|
|
25
|
+
}[]>;
|
|
26
|
+
};
|
|
20
27
|
//# sourceMappingURL=RustfmtConfigExists.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RustfmtConfigExists.d.ts","sourceRoot":"","sources":["../../src/policies/RustfmtConfigExists.ts"],"names":[],"mappings":"AAGA
|
|
1
|
+
{"version":3,"file":"RustfmtConfigExists.d.ts","sourceRoot":"","sources":["../../src/policies/RustfmtConfigExists.ts"],"names":[],"mappings":"AAGA;;;;GAIG;AACH,MAAM,WAAW,yBAAyB;IACzC;;;OAGG;IACH,aAAa,CAAC,EAAE,MAAM,EAAE,CAAC;CACzB;AAID;;;;GAIG;AACH,eAAO,MAAM,mBAAmB;;;;;;;;CAoB2B,CAAC"}
|
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
import { existsSync } from "node:fs";
|
|
2
2
|
import path from "pathe";
|
|
3
|
-
import { makePolicyDefinition } from "../makePolicy.js";
|
|
4
3
|
const DEFAULT_NAMES = ["rustfmt.toml", ".rustfmt.toml"];
|
|
5
4
|
/**
|
|
6
5
|
* A policy that requires a rustfmt.toml file for consistent Rust formatting.
|
|
7
6
|
*
|
|
8
|
-
* @
|
|
7
|
+
* @public
|
|
9
8
|
*/
|
|
10
|
-
export const RustfmtConfigExists =
|
|
9
|
+
export const RustfmtConfigExists = {
|
|
11
10
|
name: "RustfmtConfigExists",
|
|
12
11
|
description: "Ensures a rustfmt.toml file exists for consistent Rust formatting.",
|
|
13
12
|
// Trigger on Cargo.toml to check once per project
|
|
@@ -16,12 +15,14 @@ export const RustfmtConfigExists = makePolicyDefinition({
|
|
|
16
15
|
const names = config?.acceptedNames ?? DEFAULT_NAMES;
|
|
17
16
|
const hasConfig = names.some((name) => existsSync(path.join(root, name)));
|
|
18
17
|
if (hasConfig) {
|
|
19
|
-
return
|
|
18
|
+
return [];
|
|
20
19
|
}
|
|
21
|
-
return
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
20
|
+
return [
|
|
21
|
+
{
|
|
22
|
+
message: `No rustfmt config found. Expected one of: ${names.join(", ")}`,
|
|
23
|
+
manualFix: "Create a rustfmt.toml file to configure Rust formatting.",
|
|
24
|
+
},
|
|
25
|
+
];
|
|
25
26
|
},
|
|
26
|
-
}
|
|
27
|
+
};
|
|
27
28
|
//# sourceMappingURL=RustfmtConfigExists.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RustfmtConfigExists.js","sourceRoot":"","sources":["../../src/policies/RustfmtConfigExists.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AACrC,OAAO,IAAI,MAAM,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"RustfmtConfigExists.js","sourceRoot":"","sources":["../../src/policies/RustfmtConfigExists.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AACrC,OAAO,IAAI,MAAM,OAAO,CAAC;AAezB,MAAM,aAAa,GAAG,CAAC,cAAc,EAAE,eAAe,CAAC,CAAC;AAExD;;;;GAIG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAG;IAClC,IAAI,EAAE,qBAAqB;IAC3B,WAAW,EACV,oEAAoE;IACrE,kDAAkD;IAClD,KAAK,EAAE,eAAe;IACtB,OAAO,EAAE,KAAK,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE;QACnC,MAAM,KAAK,GAAG,MAAM,EAAE,aAAa,IAAI,aAAa,CAAC;QACrD,MAAM,SAAS,GAAG,KAAK,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC;QAE1E,IAAI,SAAS,EAAE,CAAC;YACf,OAAO,EAAE,CAAC;QACX,CAAC;QACD,OAAO;YACN;gBACC,OAAO,EAAE,6CAA6C,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE;gBACxE,SAAS,EAAE,0DAA0D;aACrE;SACD,CAAC;IACH,CAAC;CACyD,CAAC","sourcesContent":["import { existsSync } from \"node:fs\";\nimport path from \"pathe\";\nimport type { FilePolicyDefinition } from \"../policy.js\";\n/**\n * Configuration for the RustfmtConfigExists policy.\n *\n * @public\n */\nexport interface RustfmtConfigExistsConfig {\n\t/**\n\t * Accepted file names for the rustfmt config.\n\t * @defaultValue [\"rustfmt.toml\", \".rustfmt.toml\"]\n\t */\n\tacceptedNames?: string[];\n}\n\nconst DEFAULT_NAMES = [\"rustfmt.toml\", \".rustfmt.toml\"];\n\n/**\n * A policy that requires a rustfmt.toml file for consistent Rust formatting.\n *\n * @public\n */\nexport const RustfmtConfigExists = {\n\tname: \"RustfmtConfigExists\",\n\tdescription:\n\t\t\"Ensures a rustfmt.toml file exists for consistent Rust formatting.\",\n\t// Trigger on Cargo.toml to check once per project\n\tmatch: /^Cargo\\.toml$/,\n\thandler: async ({ root, config }) => {\n\t\tconst names = config?.acceptedNames ?? DEFAULT_NAMES;\n\t\tconst hasConfig = names.some((name) => existsSync(path.join(root, name)));\n\n\t\tif (hasConfig) {\n\t\t\treturn [];\n\t\t}\n\t\treturn [\n\t\t\t{\n\t\t\t\tmessage: `No rustfmt config found. Expected one of: ${names.join(\", \")}`,\n\t\t\t\tmanualFix: \"Create a rustfmt.toml file to configure Rust formatting.\",\n\t\t\t},\n\t\t];\n\t},\n} satisfies FilePolicyDefinition<RustfmtConfigExistsConfig>;\n"]}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Configuration for validating that a script's body contains required substrings.
|
|
3
3
|
*
|
|
4
|
-
* @
|
|
4
|
+
* @public
|
|
5
5
|
*/
|
|
6
6
|
export interface ScriptContainsRule {
|
|
7
7
|
/**
|
|
@@ -17,7 +17,7 @@ export interface ScriptContainsRule {
|
|
|
17
17
|
/**
|
|
18
18
|
* Configuration for the ScriptContains policy.
|
|
19
19
|
*
|
|
20
|
-
* @
|
|
20
|
+
* @public
|
|
21
21
|
*/
|
|
22
22
|
export interface ScriptContainsConfig {
|
|
23
23
|
/**
|
|
@@ -46,19 +46,21 @@ export interface ScriptContainsConfig {
|
|
|
46
46
|
*
|
|
47
47
|
* @example
|
|
48
48
|
* ```typescript
|
|
49
|
-
* import {
|
|
49
|
+
* import { makePolicy } from "repopo";
|
|
50
50
|
* import { ScriptContains } from "repopo/policies";
|
|
51
51
|
*
|
|
52
|
-
*
|
|
52
|
+
* makePolicy(ScriptContains, { config: {
|
|
53
53
|
* rules: [
|
|
54
54
|
* { script: "clean", mustContain: ["rimraf"] },
|
|
55
55
|
* { script: "build", mustContain: ["tsc"] },
|
|
56
56
|
* { script: "test", mustContain: ["vitest", "run"] },
|
|
57
57
|
* ],
|
|
58
|
-
* })
|
|
58
|
+
* } })
|
|
59
59
|
* ```
|
|
60
60
|
*
|
|
61
|
-
* @
|
|
61
|
+
* @public
|
|
62
62
|
*/
|
|
63
|
-
export declare const ScriptContains: import("../policy.js").
|
|
63
|
+
export declare const ScriptContains: import("../policy.js").FilePolicyDefinition<ScriptContainsConfig | undefined> & {
|
|
64
|
+
requiresConfig: true;
|
|
65
|
+
};
|
|
64
66
|
//# sourceMappingURL=ScriptContains.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ScriptContains.d.ts","sourceRoot":"","sources":["../../src/policies/ScriptContains.ts"],"names":[],"mappings":"AAGA;;;;GAIG;AACH,MAAM,WAAW,kBAAkB;IAClC;;OAEG;IACH,MAAM,EAAE,MAAM,CAAC;IAEf;;;OAGG;IACH,WAAW,EAAE,MAAM,EAAE,CAAC;CACtB;AAED;;;;GAIG;AACH,MAAM,WAAW,oBAAoB;IACpC;;;;;;;;;;OAUG;IACH,KAAK,EAAE,kBAAkB,EAAE,CAAC;CAC5B;AAID;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,eAAO,MAAM,cAAc,
|
|
1
|
+
{"version":3,"file":"ScriptContains.d.ts","sourceRoot":"","sources":["../../src/policies/ScriptContains.ts"],"names":[],"mappings":"AAGA;;;;GAIG;AACH,MAAM,WAAW,kBAAkB;IAClC;;OAEG;IACH,MAAM,EAAE,MAAM,CAAC;IAEf;;;OAGG;IACH,WAAW,EAAE,MAAM,EAAE,CAAC;CACtB;AAED;;;;GAIG;AACH,MAAM,WAAW,oBAAoB;IACpC;;;;;;;;;;OAUG;IACH,KAAK,EAAE,kBAAkB,EAAE,CAAC;CAC5B;AAID;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,eAAO,MAAM,cAAc;;CAsCzB,CAAC"}
|
|
@@ -13,26 +13,27 @@ const POLICY_NAME = "ScriptContains";
|
|
|
13
13
|
*
|
|
14
14
|
* @example
|
|
15
15
|
* ```typescript
|
|
16
|
-
* import {
|
|
16
|
+
* import { makePolicy } from "repopo";
|
|
17
17
|
* import { ScriptContains } from "repopo/policies";
|
|
18
18
|
*
|
|
19
|
-
*
|
|
19
|
+
* makePolicy(ScriptContains, { config: {
|
|
20
20
|
* rules: [
|
|
21
21
|
* { script: "clean", mustContain: ["rimraf"] },
|
|
22
22
|
* { script: "build", mustContain: ["tsc"] },
|
|
23
23
|
* { script: "test", mustContain: ["vitest", "run"] },
|
|
24
24
|
* ],
|
|
25
|
-
* })
|
|
25
|
+
* } })
|
|
26
26
|
* ```
|
|
27
27
|
*
|
|
28
|
-
* @
|
|
28
|
+
* @public
|
|
29
29
|
*/
|
|
30
30
|
export const ScriptContains = definePackagePolicy({
|
|
31
|
+
requiresConfig: true,
|
|
31
32
|
name: POLICY_NAME,
|
|
32
33
|
description: "Validates that script bodies contain required substrings.",
|
|
33
|
-
handler: async (json, {
|
|
34
|
+
handler: async (json, { config }) => {
|
|
34
35
|
if (config === undefined || config.rules.length === 0) {
|
|
35
|
-
return
|
|
36
|
+
return [];
|
|
36
37
|
}
|
|
37
38
|
const scripts = json.scripts ?? {};
|
|
38
39
|
const errors = [];
|
|
@@ -49,14 +50,9 @@ export const ScriptContains = definePackagePolicy({
|
|
|
49
50
|
}
|
|
50
51
|
}
|
|
51
52
|
if (errors.length === 0) {
|
|
52
|
-
return
|
|
53
|
+
return [];
|
|
53
54
|
}
|
|
54
|
-
return {
|
|
55
|
-
name: POLICY_NAME,
|
|
56
|
-
file,
|
|
57
|
-
autoFixable: false,
|
|
58
|
-
errorMessages: errors,
|
|
59
|
-
};
|
|
55
|
+
return errors.map((message) => ({ message }));
|
|
60
56
|
},
|
|
61
57
|
});
|
|
62
58
|
//# sourceMappingURL=ScriptContains.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ScriptContains.js","sourceRoot":"","sources":["../../src/policies/ScriptContains.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,mBAAmB,EAAE,MAAM,0CAA0C,CAAC;AAwC/E,MAAM,WAAW,GAAG,gBAAgB,CAAC;AAErC;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG,mBAAmB,CAG/C;IACD,IAAI,EAAE,WAAW;IACjB,WAAW,EAAE,2DAA2D;IACxE,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,EAAE,
|
|
1
|
+
{"version":3,"file":"ScriptContains.js","sourceRoot":"","sources":["../../src/policies/ScriptContains.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,mBAAmB,EAAE,MAAM,0CAA0C,CAAC;AAwC/E,MAAM,WAAW,GAAG,gBAAgB,CAAC;AAErC;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG,mBAAmB,CAG/C;IACD,cAAc,EAAE,IAAI;IACpB,IAAI,EAAE,WAAW;IACjB,WAAW,EAAE,2DAA2D;IACxE,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE;QACnC,IAAI,MAAM,KAAK,SAAS,IAAI,MAAM,CAAC,KAAK,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YACvD,OAAO,EAAE,CAAC;QACX,CAAC;QAED,MAAM,OAAO,GAAG,IAAI,CAAC,OAAO,IAAI,EAAE,CAAC;QACnC,MAAM,MAAM,GAAa,EAAE,CAAC;QAE5B,KAAK,MAAM,IAAI,IAAI,MAAM,CAAC,KAAK,EAAE,CAAC;YACjC,qCAAqC;YACrC,IAAI,MAAM,CAAC,MAAM,CAAC,OAAO,EAAE,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC;gBACzC,MAAM,UAAU,GAAG,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;gBACxC,IAAI,OAAO,UAAU,KAAK,QAAQ,EAAE,CAAC;oBACpC,MAAM,iBAAiB,GAAG,IAAI,CAAC,WAAW,CAAC,MAAM,CAChD,CAAC,SAAS,EAAE,EAAE,CAAC,CAAC,UAAU,CAAC,QAAQ,CAAC,SAAS,CAAC,CAC9C,CAAC;oBAEF,IAAI,iBAAiB,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;wBAClC,MAAM,CAAC,IAAI,CACV,WAAW,IAAI,CAAC,MAAM,mBAAmB,iBAAiB,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CACvE,CAAC;oBACH,CAAC;gBACF,CAAC;YACF,CAAC;QACF,CAAC;QAED,IAAI,MAAM,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YACzB,OAAO,EAAE,CAAC;QACX,CAAC;QACD,OAAO,MAAM,CAAC,GAAG,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC,EAAE,OAAO,EAAE,CAAC,CAAC,CAAC;IAC/C,CAAC;CACD,CAAC,CAAC","sourcesContent":["import type { PackageJson } from \"type-fest\";\nimport { definePackagePolicy } from \"../policyDefiners/definePackagePolicy.js\";\n\n/**\n * Configuration for validating that a script's body contains required substrings.\n *\n * @public\n */\nexport interface ScriptContainsRule {\n\t/**\n\t * The name of the script to validate.\n\t */\n\tscript: string;\n\n\t/**\n\t * Substrings that must appear in the script body.\n\t * All substrings must be present for the script to pass validation.\n\t */\n\tmustContain: string[];\n}\n\n/**\n * Configuration for the ScriptContains policy.\n *\n * @public\n */\nexport interface ScriptContainsConfig {\n\t/**\n\t * Rules for validating script body content.\n\t *\n\t * @example\n\t * ```typescript\n\t * rules: [\n\t * { script: \"clean\", mustContain: [\"rimraf\"] },\n\t * { script: \"build\", mustContain: [\"tsc\"] },\n\t * ]\n\t * ```\n\t */\n\trules: ScriptContainsRule[];\n}\n\nconst POLICY_NAME = \"ScriptContains\";\n\n/**\n * A policy that validates script bodies contain required substrings.\n *\n * @remarks\n * Use this policy to ensure specific scripts contain required commands or patterns\n * without requiring an exact match. For example, requiring that the \"clean\" script\n * uses \"rimraf\" or that \"build\" includes \"tsc\".\n *\n * The policy only validates scripts that exist. If a script doesn't exist,\n * it's not an error (use RequiredScripts for that).\n *\n * @example\n * ```typescript\n * import { makePolicy } from \"repopo\";\n * import { ScriptContains } from \"repopo/policies\";\n *\n * makePolicy(ScriptContains, { config: {\n * rules: [\n * { script: \"clean\", mustContain: [\"rimraf\"] },\n * { script: \"build\", mustContain: [\"tsc\"] },\n * { script: \"test\", mustContain: [\"vitest\", \"run\"] },\n * ],\n * } })\n * ```\n *\n * @public\n */\nexport const ScriptContains = definePackagePolicy<\n\tPackageJson,\n\tScriptContainsConfig | undefined\n>({\n\trequiresConfig: true,\n\tname: POLICY_NAME,\n\tdescription: \"Validates that script bodies contain required substrings.\",\n\thandler: async (json, { config }) => {\n\t\tif (config === undefined || config.rules.length === 0) {\n\t\t\treturn [];\n\t\t}\n\n\t\tconst scripts = json.scripts ?? {};\n\t\tconst errors: string[] = [];\n\n\t\tfor (const rule of config.rules) {\n\t\t\t// Only validate if the script exists\n\t\t\tif (Object.hasOwn(scripts, rule.script)) {\n\t\t\t\tconst scriptBody = scripts[rule.script];\n\t\t\t\tif (typeof scriptBody === \"string\") {\n\t\t\t\t\tconst missingSubstrings = rule.mustContain.filter(\n\t\t\t\t\t\t(substring) => !scriptBody.includes(substring),\n\t\t\t\t\t);\n\n\t\t\t\t\tif (missingSubstrings.length > 0) {\n\t\t\t\t\t\terrors.push(\n\t\t\t\t\t\t\t`Script \"${rule.script}\" must contain: ${missingSubstrings.join(\", \")}`,\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tif (errors.length === 0) {\n\t\t\treturn [];\n\t\t}\n\t\treturn errors.map((message) => ({ message }));\n\t},\n});\n"]}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { PolicyFinding } from "../policy.js";
|
|
2
2
|
/**
|
|
3
3
|
* Configuration for the SharedDependencyVersions policy.
|
|
4
4
|
*
|
|
5
|
-
* @
|
|
5
|
+
* @public
|
|
6
6
|
*/
|
|
7
7
|
export interface SharedDependencyVersionsConfig {
|
|
8
8
|
/**
|
|
@@ -18,7 +18,12 @@ export interface SharedDependencyVersionsConfig {
|
|
|
18
18
|
/**
|
|
19
19
|
* A policy that detects dependency version mismatches across Cargo workspace members.
|
|
20
20
|
*
|
|
21
|
-
* @
|
|
21
|
+
* @public
|
|
22
22
|
*/
|
|
23
|
-
export declare const SharedDependencyVersions:
|
|
23
|
+
export declare const SharedDependencyVersions: {
|
|
24
|
+
name: string;
|
|
25
|
+
description: string;
|
|
26
|
+
scope: "repository";
|
|
27
|
+
handler: ({ files, root, config }: import("../policy.js").RepositoryPolicyArgs<SharedDependencyVersionsConfig>) => Promise<PolicyFinding[]>;
|
|
28
|
+
};
|
|
24
29
|
//# sourceMappingURL=SharedDependencyVersions.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SharedDependencyVersions.d.ts","sourceRoot":"","sources":["../../src/policies/SharedDependencyVersions.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"SharedDependencyVersions.d.ts","sourceRoot":"","sources":["../../src/policies/SharedDependencyVersions.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,aAAa,EAA8B,MAAM,cAAc,CAAC;AAG9E;;;;GAIG;AACH,MAAM,WAAW,8BAA8B;IAC9C;;OAEG;IACH,oBAAoB,CAAC,EAAE,MAAM,EAAE,CAAC;IAEhC;;;OAGG;IACH,gBAAgB,CAAC,EAAE,OAAO,CAAC;CAC3B;AAsHD;;;;GAIG;AACH,eAAO,MAAM,wBAAwB;;;;;CA0DiC,CAAC"}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { readFile } from "node:fs/promises";
|
|
2
2
|
import path from "pathe";
|
|
3
3
|
import { glob } from "tinyglobby";
|
|
4
|
-
import { makePolicyDefinition } from "../makePolicy.js";
|
|
5
4
|
import { parseToml } from "../policyDefiners/tomlParser.js";
|
|
6
5
|
function extractVersion(dep) {
|
|
7
6
|
if (typeof dep === "string") {
|
|
@@ -69,18 +68,21 @@ function recordDependency(allDeps, name, version, member) {
|
|
|
69
68
|
/**
|
|
70
69
|
* Collect dependency versions from all workspace members and record which members use them.
|
|
71
70
|
*/
|
|
72
|
-
async function collectMemberDeps(members, root, exclude) {
|
|
71
|
+
async function collectMemberDeps(members, root, exclude, files) {
|
|
73
72
|
const allDeps = new Map();
|
|
74
73
|
const memberCargoPaths = await glob(members.map((member) => path.join(member, "Cargo.toml")), {
|
|
75
74
|
cwd: root,
|
|
76
75
|
ignore: exclude.map((member) => path.join(member, "Cargo.toml")),
|
|
77
76
|
});
|
|
78
77
|
for (const memberCargoPath of memberCargoPaths) {
|
|
78
|
+
if (!files.includes(memberCargoPath)) {
|
|
79
|
+
continue;
|
|
80
|
+
}
|
|
79
81
|
const memberContent = await readFile(path.resolve(root, memberCargoPath), "utf-8");
|
|
80
82
|
const memberToml = await parseToml(memberContent);
|
|
81
83
|
const deps = collectDeps(memberToml);
|
|
82
84
|
for (const [name, version] of deps) {
|
|
83
|
-
recordDependency(allDeps, name, version,
|
|
85
|
+
recordDependency(allDeps, name, version, memberCargoPath);
|
|
84
86
|
}
|
|
85
87
|
}
|
|
86
88
|
return allDeps;
|
|
@@ -88,48 +90,54 @@ async function collectMemberDeps(members, root, exclude) {
|
|
|
88
90
|
/**
|
|
89
91
|
* A policy that detects dependency version mismatches across Cargo workspace members.
|
|
90
92
|
*
|
|
91
|
-
* @
|
|
93
|
+
* @public
|
|
92
94
|
*/
|
|
93
|
-
export const SharedDependencyVersions =
|
|
95
|
+
export const SharedDependencyVersions = {
|
|
94
96
|
name: "SharedDependencyVersions",
|
|
95
97
|
description: "Detects dependency version mismatches across Cargo workspace members.",
|
|
96
|
-
|
|
97
|
-
handler: async ({
|
|
98
|
+
scope: "repository",
|
|
99
|
+
handler: async ({ files, root, config }) => {
|
|
100
|
+
if (!files.includes("Cargo.toml")) {
|
|
101
|
+
return [];
|
|
102
|
+
}
|
|
98
103
|
const detectMismatches = config?.detectMismatches ?? true;
|
|
99
|
-
const content = await readFile(path.resolve(root,
|
|
104
|
+
const content = await readFile(path.resolve(root, "Cargo.toml"), "utf-8");
|
|
100
105
|
const toml = await parseToml(content);
|
|
101
106
|
const workspace = toml.workspace;
|
|
102
107
|
if (!workspace) {
|
|
103
|
-
return
|
|
108
|
+
return [];
|
|
104
109
|
}
|
|
105
110
|
const members = workspace.members;
|
|
106
111
|
if (!members || members.length === 0) {
|
|
107
|
-
return
|
|
112
|
+
return [];
|
|
108
113
|
}
|
|
109
114
|
const errors = [];
|
|
115
|
+
const findings = [];
|
|
116
|
+
const manualFix = "Use [workspace.dependencies] with `dep.workspace = true` in member Cargo.toml files to share versions.";
|
|
110
117
|
// Check required workspace deps
|
|
111
118
|
const workspaceDeps = (workspace.dependencies ?? {});
|
|
112
119
|
checkRequiredWorkspaceDeps(config, workspaceDeps, errors);
|
|
120
|
+
for (const error of errors) {
|
|
121
|
+
findings.push({ message: error, files: ["Cargo.toml"], manualFix });
|
|
122
|
+
}
|
|
113
123
|
// Detect mismatches across members
|
|
114
124
|
if (detectMismatches) {
|
|
115
125
|
const exclude = (workspace.exclude ?? []);
|
|
116
|
-
const allDeps = await collectMemberDeps(members, root, exclude);
|
|
126
|
+
const allDeps = await collectMemberDeps(members, root, exclude, files);
|
|
117
127
|
for (const [dep, versionMap] of allDeps) {
|
|
118
128
|
if (versionMap.size > 1) {
|
|
119
129
|
const details = [...versionMap.entries()]
|
|
120
130
|
.map(([ver, memberList]) => `"${ver}" in ${memberList.join(", ")}`)
|
|
121
131
|
.join("; ");
|
|
122
|
-
|
|
132
|
+
findings.push({
|
|
133
|
+
message: `Version mismatch for "${dep}": ${details}`,
|
|
134
|
+
files: [...versionMap.values()].flat(),
|
|
135
|
+
manualFix,
|
|
136
|
+
});
|
|
123
137
|
}
|
|
124
138
|
}
|
|
125
139
|
}
|
|
126
|
-
|
|
127
|
-
return {
|
|
128
|
-
error: errors.join("; "),
|
|
129
|
-
manualFix: "Use [workspace.dependencies] with `dep.workspace = true` in member Cargo.toml files to share versions.",
|
|
130
|
-
};
|
|
131
|
-
}
|
|
132
|
-
return true;
|
|
140
|
+
return findings.length > 0 ? findings : [];
|
|
133
141
|
},
|
|
134
|
-
}
|
|
142
|
+
};
|
|
135
143
|
//# sourceMappingURL=SharedDependencyVersions.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SharedDependencyVersions.js","sourceRoot":"","sources":["../../src/policies/SharedDependencyVersions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,IAAI,MAAM,OAAO,CAAC;AACzB,OAAO,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC;AAClC,OAAO,EAAE,oBAAoB,EAAE,MAAM,kBAAkB,CAAC;AAExD,OAAO,EAAE,SAAS,EAAE,MAAM,iCAAiC,CAAC;AAoB5D,SAAS,cAAc,CAAC,GAAY;IACnC,IAAI,OAAO,GAAG,KAAK,QAAQ,EAAE,CAAC;QAC7B,OAAO,GAAG,CAAC;IACZ,CAAC;IACD,IAAI,OAAO,GAAG,KAAK,QAAQ,IAAI,GAAG,KAAK,IAAI,EAAE,CAAC;QAC7C,MAAM,MAAM,GAAG,GAA8B,CAAC;QAC9C,IAAI,OAAO,MAAM,CAAC,OAAO,KAAK,QAAQ,EAAE,CAAC;YACxC,OAAO,MAAM,CAAC,OAAO,CAAC;QACvB,CAAC;IACF,CAAC;IACD,OAAO,SAAS,CAAC;AAClB,CAAC;AAED;;GAEG;AACH,SAAS,WAAW,CAAC,IAA6B;IACjD,MAAM,IAAI,GAAG,IAAI,GAAG,EAAkB,CAAC;IACvC,MAAM,QAAQ,GAAG,CAAC,cAAc,EAAE,kBAAkB,EA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KAAK,MAAM,CAAC,GAAG,EAAE,UAAU,CAAC,IAAI,OAAO,EAAE,CAAC;gBACzC,IAAI,UAAU,CAAC,IAAI,GAAG,CAAC,EAAE,CAAC;oBACzB,MAAM,OAAO,GAAG,CAAC,GAAG,UAAU,CAAC,OAAO,EAAE,CAAC;yBACvC,GAAG,CACH,CAAC,CAAC,GAAG,EAAE,UAAU,CAAC,EAAE,EAAE,CAAC,IAAI,GAAG,QAAQ,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAC7D;yBACA,IAAI,CAAC,IAAI,CAAC,CAAC;oBACb,MAAM,CAAC,IAAI,CAAC,yBAAyB,GAAG,MAAM,OAAO,EAAE,CAAC,CAAC;gBAC1D,CAAC;YACF,CAAC;QACF,CAAC;QAED,IAAI,MAAM,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YACvB,OAAO;gBACN,KAAK,EAAE,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC;gBACxB,SAAS,EACR,wGAAwG;aACzG,CAAC;QACH,CAAC;QAED,OAAO,IAAI,CAAC;IACb,CAAC;CACD,CAAC,CAAC","sourcesContent":["import { readFile } from \"node:fs/promises\";\nimport path from \"pathe\";\nimport { glob } from \"tinyglobby\";\nimport { makePolicyDefinition } from \"../makePolicy.js\";\nimport type { PolicyDefinition } from \"../policy.js\";\nimport { parseToml } from \"../policyDefiners/tomlParser.js\";\n\n/**\n * Configuration for the SharedDependencyVersions policy.\n *\n * @alpha\n */\nexport interface SharedDependencyVersionsConfig {\n\t/**\n\t * Dependencies that should use workspace-level versions.\n\t */\n\trequireWorkspaceDeps?: string[];\n\n\t/**\n\t * If true, detect version mismatches across workspace members.\n\t * @defaultValue true\n\t */\n\tdetectMismatches?: boolean;\n}\n\nfunction extractVersion(dep: unknown): string | undefined {\n\tif (typeof dep === \"string\") {\n\t\treturn dep;\n\t}\n\tif (typeof dep === \"object\" && dep !== null) {\n\t\tconst record = dep as Record<string, unknown>;\n\t\tif (typeof record.version === \"string\") {\n\t\t\treturn record.version;\n\t\t}\n\t}\n\treturn undefined;\n}\n\n/**\n * Collect dependencies from a TOML object.\n */\nfunction collectDeps(toml: Record<string, unknown>): Map<string, string> {\n\tconst deps = new Map<string, string>();\n\tconst sections = [\"dependencies\", \"dev-dependencies\", \"build-dependencies\"];\n\n\tfor (const section of sections) {\n\t\tconst sectionDeps = toml[section] as Record<string, unknown> | undefined;\n\t\tif (!sectionDeps) {\n\t\t\tcontinue;\n\t\t}\n\t\tfor (const [name, value] of Object.entries(sectionDeps)) {\n\t\t\tconst version = extractVersion(value);\n\t\t\tif (version && !version.startsWith(\"workspace\")) {\n\t\t\t\tdeps.set(name, version);\n\t\t\t}\n\t\t}\n\t}\n\treturn deps;\n}\n\n/**\n * Check that required dependencies are defined at the workspace level.\n */\nfunction checkRequiredWorkspaceDeps(\n\tconfig: SharedDependencyVersionsConfig | undefined,\n\tworkspaceDeps: Record<string, unknown>,\n\terrors: string[],\n): void {\n\tif (!config?.requireWorkspaceDeps) {\n\t\treturn;\n\t}\n\tfor (const dep of config.requireWorkspaceDeps) {\n\t\tif (!(dep in workspaceDeps)) {\n\t\t\terrors.push(\n\t\t\t\t`Dependency \"${dep}\" should be defined in [workspace.dependencies]`,\n\t\t\t);\n\t\t}\n\t}\n}\n\n/**\n * Add a member's dependency version to the tracking map.\n */\nfunction recordDependency(\n\tallDeps: Map<string, Map<string, string[]>>,\n\tname: string,\n\tversion: string,\n\tmember: string,\n): void {\n\tif (!allDeps.has(name)) {\n\t\tallDeps.set(name, new Map());\n\t}\n\tconst versionMap = allDeps.get(name);\n\tif (versionMap !== undefined) {\n\t\tif (!versionMap.has(version)) {\n\t\t\tversionMap.set(version, []);\n\t\t}\n\t\tconst memberList = versionMap.get(version);\n\t\tif (memberList !== undefined) {\n\t\t\tmemberList.push(member);\n\t\t}\n\t}\n}\n\n/**\n * Collect dependency versions from all workspace members and record which members use them.\n */\nasync function collectMemberDeps(\n\tmembers: string[],\n\troot: string,\n\texclude: string[],\n): Promise<Map<string, Map<string, string[]>>> {\n\tconst allDeps = new Map<string, Map<string, string[]>>();\n\tconst memberCargoPaths = await glob(\n\t\tmembers.map((member) => path.join(member, \"Cargo.toml\")),\n\t\t{\n\t\t\tcwd: root,\n\t\t\tignore: exclude.map((member) => path.join(member, \"Cargo.toml\")),\n\t\t},\n\t);\n\n\tfor (const memberCargoPath of memberCargoPaths) {\n\t\tconst memberContent = await readFile(\n\t\t\tpath.resolve(root, memberCargoPath),\n\t\t\t\"utf-8\",\n\t\t);\n\t\tconst memberToml = await parseToml(memberContent);\n\t\tconst deps = collectDeps(memberToml);\n\n\t\tfor (const [name, version] of deps) {\n\t\t\trecordDependency(allDeps, name, version, path.dirname(memberCargoPath));\n\t\t}\n\t}\n\n\treturn allDeps;\n}\n\n/**\n * A policy that detects dependency version mismatches across Cargo workspace members.\n *\n * @alpha\n */\nexport const SharedDependencyVersions: PolicyDefinition<SharedDependencyVersionsConfig> =\n\tmakePolicyDefinition({\n\t\tname: \"SharedDependencyVersions\",\n\t\tdescription:\n\t\t\t\"Detects dependency version mismatches across Cargo workspace members.\",\n\t\tmatch: /^Cargo\\.toml$/,\n\t\thandler: async ({ file, root, config }) => {\n\t\t\tconst detectMismatches = config?.detectMismatches ?? true;\n\t\t\tconst content = await readFile(path.resolve(root, file), \"utf-8\");\n\t\t\tconst toml = await parseToml(content);\n\n\t\t\tconst workspace = toml.workspace as Record<string, unknown> | undefined;\n\t\t\tif (!workspace) {\n\t\t\t\treturn true;\n\t\t\t}\n\n\t\t\tconst members = workspace.members as string[] | undefined;\n\t\t\tif (!members || members.length === 0) {\n\t\t\t\treturn true;\n\t\t\t}\n\n\t\t\tconst errors: string[] = [];\n\n\t\t\t// Check required workspace deps\n\t\t\tconst workspaceDeps = (workspace.dependencies ?? {}) as Record<\n\t\t\t\tstring,\n\t\t\t\tunknown\n\t\t\t>;\n\t\t\tcheckRequiredWorkspaceDeps(config, workspaceDeps, errors);\n\n\t\t\t// Detect mismatches across members\n\t\t\tif (detectMismatches) {\n\t\t\t\tconst exclude = (workspace.exclude ?? []) as string[];\n\t\t\t\tconst allDeps = await collectMemberDeps(members, root, exclude);\n\n\t\t\t\tfor (const [dep, versionMap] of allDeps) {\n\t\t\t\t\tif (versionMap.size > 1) {\n\t\t\t\t\t\tconst details = [...versionMap.entries()]\n\t\t\t\t\t\t\t.map(\n\t\t\t\t\t\t\t\t([ver, memberList]) => `\"${ver}\" in ${memberList.join(\", \")}`,\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t.join(\"; \");\n\t\t\t\t\t\terrors.push(`Version mismatch for \"${dep}\": ${details}`);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif (errors.length > 0) {\n\t\t\t\treturn {\n\t\t\t\t\terror: errors.join(\"; \"),\n\t\t\t\t\tmanualFix:\n\t\t\t\t\t\t\"Use [workspace.dependencies] with `dep.workspace = true` in member Cargo.toml files to share versions.\",\n\t\t\t\t};\n\t\t\t}\n\n\t\t\treturn true;\n\t\t},\n\t});\n"]}
|
|
1
|
+
{"version":3,"file":"SharedDependencyVersions.js","sourceRoot":"","sources":["../../src/policies/SharedDependencyVersions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,IAAI,MAAM,OAAO,CAAC;AACzB,OAAO,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC;AAElC,OAAO,EAAE,SAAS,EAAE,MAAM,iCAAiC,CAAC;AAoB5D,SAAS,cAAc,CAAC,GAAY;IACnC,IAAI,OAAO,GAAG,KAAK,QAAQ,EAAE,CAAC;QAC7B,OAAO,GAAG,CAAC;IACZ,CAAC;IACD,IAAI,OAAO,GAAG,KAAK,QAAQ,IAAI,GAAG,KAAK,IAAI,EAAE,CAAC;QAC7C,MAAM,MAAM,GAAG,GAA8B,CAAC;QAC9C,IAAI,OAAO,MAAM,CAAC,OAAO,KAAK,QAAQ,EAAE,CAAC;YACx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,CAAC;YACF,CAAC;QACF,CAAC;QACD,OAAO,QAAQ,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,EAAE,CAAC;IAC5C,CAAC;CACoE,CAAC","sourcesContent":["import { readFile } from \"node:fs/promises\";\nimport path from \"pathe\";\nimport { glob } from \"tinyglobby\";\nimport type { PolicyFinding, RepositoryPolicyDefinition } from \"../policy.js\";\nimport { parseToml } from \"../policyDefiners/tomlParser.js\";\n\n/**\n * Configuration for the SharedDependencyVersions policy.\n *\n * @public\n */\nexport interface SharedDependencyVersionsConfig {\n\t/**\n\t * Dependencies that should use workspace-level versions.\n\t */\n\trequireWorkspaceDeps?: string[];\n\n\t/**\n\t * If true, detect version mismatches across workspace members.\n\t * @defaultValue true\n\t */\n\tdetectMismatches?: boolean;\n}\n\nfunction extractVersion(dep: unknown): string | undefined {\n\tif (typeof dep === \"string\") {\n\t\treturn dep;\n\t}\n\tif (typeof dep === \"object\" && dep !== null) {\n\t\tconst record = dep as Record<string, unknown>;\n\t\tif (typeof record.version === \"string\") {\n\t\t\treturn record.version;\n\t\t}\n\t}\n\treturn undefined;\n}\n\n/**\n * Collect dependencies from a TOML object.\n */\nfunction collectDeps(toml: Record<string, unknown>): Map<string, string> {\n\tconst deps = new Map<string, string>();\n\tconst sections = [\"dependencies\", \"dev-dependencies\", \"build-dependencies\"];\n\n\tfor (const section of sections) {\n\t\tconst sectionDeps = toml[section] as Record<string, unknown> | undefined;\n\t\tif (!sectionDeps) {\n\t\t\tcontinue;\n\t\t}\n\t\tfor (const [name, value] of Object.entries(sectionDeps)) {\n\t\t\tconst version = extractVersion(value);\n\t\t\tif (version && !version.startsWith(\"workspace\")) {\n\t\t\t\tdeps.set(name, version);\n\t\t\t}\n\t\t}\n\t}\n\treturn deps;\n}\n\n/**\n * Check that required dependencies are defined at the workspace level.\n */\nfunction checkRequiredWorkspaceDeps(\n\tconfig: SharedDependencyVersionsConfig | undefined,\n\tworkspaceDeps: Record<string, unknown>,\n\terrors: string[],\n): void {\n\tif (!config?.requireWorkspaceDeps) {\n\t\treturn;\n\t}\n\tfor (const dep of config.requireWorkspaceDeps) {\n\t\tif (!(dep in workspaceDeps)) {\n\t\t\terrors.push(\n\t\t\t\t`Dependency \"${dep}\" should be defined in [workspace.dependencies]`,\n\t\t\t);\n\t\t}\n\t}\n}\n\n/**\n * Add a member's dependency version to the tracking map.\n */\nfunction recordDependency(\n\tallDeps: Map<string, Map<string, string[]>>,\n\tname: string,\n\tversion: string,\n\tmember: string,\n): void {\n\tif (!allDeps.has(name)) {\n\t\tallDeps.set(name, new Map());\n\t}\n\tconst versionMap = allDeps.get(name);\n\tif (versionMap !== undefined) {\n\t\tif (!versionMap.has(version)) {\n\t\t\tversionMap.set(version, []);\n\t\t}\n\t\tconst memberList = versionMap.get(version);\n\t\tif (memberList !== undefined) {\n\t\t\tmemberList.push(member);\n\t\t}\n\t}\n}\n\n/**\n * Collect dependency versions from all workspace members and record which members use them.\n */\nasync function collectMemberDeps(\n\tmembers: string[],\n\troot: string,\n\texclude: string[],\n\tfiles: readonly string[],\n): Promise<Map<string, Map<string, string[]>>> {\n\tconst allDeps = new Map<string, Map<string, string[]>>();\n\tconst memberCargoPaths = await glob(\n\t\tmembers.map((member) => path.join(member, \"Cargo.toml\")),\n\t\t{\n\t\t\tcwd: root,\n\t\t\tignore: exclude.map((member) => path.join(member, \"Cargo.toml\")),\n\t\t},\n\t);\n\n\tfor (const memberCargoPath of memberCargoPaths) {\n\t\tif (!files.includes(memberCargoPath)) {\n\t\t\tcontinue;\n\t\t}\n\t\tconst memberContent = await readFile(\n\t\t\tpath.resolve(root, memberCargoPath),\n\t\t\t\"utf-8\",\n\t\t);\n\t\tconst memberToml = await parseToml(memberContent);\n\t\tconst deps = collectDeps(memberToml);\n\n\t\tfor (const [name, version] of deps) {\n\t\t\trecordDependency(allDeps, name, version, memberCargoPath);\n\t\t}\n\t}\n\n\treturn allDeps;\n}\n\n/**\n * A policy that detects dependency version mismatches across Cargo workspace members.\n *\n * @public\n */\nexport const SharedDependencyVersions = {\n\tname: \"SharedDependencyVersions\",\n\tdescription:\n\t\t\"Detects dependency version mismatches across Cargo workspace members.\",\n\tscope: \"repository\",\n\thandler: async ({ files, root, config }) => {\n\t\tif (!files.includes(\"Cargo.toml\")) {\n\t\t\treturn [];\n\t\t}\n\t\tconst detectMismatches = config?.detectMismatches ?? true;\n\t\tconst content = await readFile(path.resolve(root, \"Cargo.toml\"), \"utf-8\");\n\t\tconst toml = await parseToml(content);\n\n\t\tconst workspace = toml.workspace as Record<string, unknown> | undefined;\n\t\tif (!workspace) {\n\t\t\treturn [];\n\t\t}\n\n\t\tconst members = workspace.members as string[] | undefined;\n\t\tif (!members || members.length === 0) {\n\t\t\treturn [];\n\t\t}\n\n\t\tconst errors: string[] = [];\n\t\tconst findings: PolicyFinding[] = [];\n\t\tconst manualFix =\n\t\t\t\"Use [workspace.dependencies] with `dep.workspace = true` in member Cargo.toml files to share versions.\";\n\n\t\t// Check required workspace deps\n\t\tconst workspaceDeps = (workspace.dependencies ?? {}) as Record<\n\t\t\tstring,\n\t\t\tunknown\n\t\t>;\n\t\tcheckRequiredWorkspaceDeps(config, workspaceDeps, errors);\n\t\tfor (const error of errors) {\n\t\t\tfindings.push({ message: error, files: [\"Cargo.toml\"], manualFix });\n\t\t}\n\n\t\t// Detect mismatches across members\n\t\tif (detectMismatches) {\n\t\t\tconst exclude = (workspace.exclude ?? []) as string[];\n\t\t\tconst allDeps = await collectMemberDeps(members, root, exclude, files);\n\n\t\t\tfor (const [dep, versionMap] of allDeps) {\n\t\t\t\tif (versionMap.size > 1) {\n\t\t\t\t\tconst details = [...versionMap.entries()]\n\t\t\t\t\t\t.map(([ver, memberList]) => `\"${ver}\" in ${memberList.join(\", \")}`)\n\t\t\t\t\t\t.join(\"; \");\n\t\t\t\t\tfindings.push({\n\t\t\t\t\t\tmessage: `Version mismatch for \"${dep}\": ${details}`,\n\t\t\t\t\t\tfiles: [...versionMap.values()].flat(),\n\t\t\t\t\t\tmanualFix,\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\treturn findings.length > 0 ? findings : [];\n\t},\n} satisfies RepositoryPolicyDefinition<SharedDependencyVersionsConfig>;\n"]}
|
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import type { PolicyDefinition } from "../policy.js";
|
|
2
1
|
/**
|
|
3
2
|
* Configuration for the WorkspaceInheritance policy.
|
|
4
3
|
*
|
|
5
|
-
* @
|
|
4
|
+
* @public
|
|
6
5
|
*/
|
|
7
6
|
export interface WorkspaceInheritanceConfig {
|
|
8
7
|
/**
|
|
@@ -18,7 +17,15 @@ export interface WorkspaceInheritanceConfig {
|
|
|
18
17
|
/**
|
|
19
18
|
* A policy that ensures Cargo workspace members inherit fields from the workspace config.
|
|
20
19
|
*
|
|
21
|
-
* @
|
|
20
|
+
* @public
|
|
22
21
|
*/
|
|
23
|
-
export declare const WorkspaceInheritance:
|
|
22
|
+
export declare const WorkspaceInheritance: {
|
|
23
|
+
name: string;
|
|
24
|
+
description: string;
|
|
25
|
+
match: RegExp;
|
|
26
|
+
handler: ({ file, root, config }: import("../policy.js").PolicyArgs<WorkspaceInheritanceConfig>) => Promise<{
|
|
27
|
+
message: string;
|
|
28
|
+
manualFix: string;
|
|
29
|
+
}[]>;
|
|
30
|
+
};
|
|
24
31
|
//# sourceMappingURL=WorkspaceInheritance.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"WorkspaceInheritance.d.ts","sourceRoot":"","sources":["../../src/policies/WorkspaceInheritance.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"WorkspaceInheritance.d.ts","sourceRoot":"","sources":["../../src/policies/WorkspaceInheritance.ts"],"names":[],"mappings":"AAKA;;;;GAIG;AACH,MAAM,WAAW,0BAA0B;IAC1C;;;OAGG;IACH,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;IAEnB;;OAEG;IACH,cAAc,CAAC,EAAE,MAAM,EAAE,CAAC;CAC1B;AA0DD;;;;GAIG;AACH,eAAO,MAAM,oBAAoB;;;;;;;;CAuD2B,CAAC"}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { readFile } from "node:fs/promises";
|
|
2
2
|
import path from "pathe";
|
|
3
|
-
import { makePolicyDefinition } from "../makePolicy.js";
|
|
4
3
|
import { parseToml } from "../policyDefiners/tomlParser.js";
|
|
5
4
|
const DEFAULT_INHERIT_FIELDS = ["version", "authors", "license", "repository"];
|
|
6
5
|
/**
|
|
@@ -47,9 +46,9 @@ async function checkMemberInheritance(member, root, availableFields, errors) {
|
|
|
47
46
|
/**
|
|
48
47
|
* A policy that ensures Cargo workspace members inherit fields from the workspace config.
|
|
49
48
|
*
|
|
50
|
-
* @
|
|
49
|
+
* @public
|
|
51
50
|
*/
|
|
52
|
-
export const WorkspaceInheritance =
|
|
51
|
+
export const WorkspaceInheritance = {
|
|
53
52
|
name: "WorkspaceInheritance",
|
|
54
53
|
description: "Ensures Cargo workspace members inherit shared fields (version, authors, etc.) from workspace config.",
|
|
55
54
|
match: /^Cargo\.toml$/,
|
|
@@ -58,11 +57,11 @@ export const WorkspaceInheritance = makePolicyDefinition({
|
|
|
58
57
|
const toml = await parseToml(content);
|
|
59
58
|
const workspace = toml.workspace;
|
|
60
59
|
if (!workspace) {
|
|
61
|
-
return
|
|
60
|
+
return [];
|
|
62
61
|
}
|
|
63
62
|
const members = workspace.members;
|
|
64
63
|
if (!members || members.length === 0) {
|
|
65
|
-
return
|
|
64
|
+
return [];
|
|
66
65
|
}
|
|
67
66
|
const inheritFields = config?.inherit ?? DEFAULT_INHERIT_FIELDS;
|
|
68
67
|
const allowOverrides = config?.allowOverrides ?? [];
|
|
@@ -70,7 +69,7 @@ export const WorkspaceInheritance = makePolicyDefinition({
|
|
|
70
69
|
const workspacePkg = (workspace.package ?? {});
|
|
71
70
|
const availableFields = inheritFields.filter((field) => workspacePkg[field] !== undefined);
|
|
72
71
|
if (availableFields.length === 0) {
|
|
73
|
-
return
|
|
72
|
+
return [];
|
|
74
73
|
}
|
|
75
74
|
const errors = [];
|
|
76
75
|
for (const member of members) {
|
|
@@ -83,12 +82,12 @@ export const WorkspaceInheritance = makePolicyDefinition({
|
|
|
83
82
|
await checkMemberInheritance(member, root, availableFields, errors);
|
|
84
83
|
}
|
|
85
84
|
if (errors.length > 0) {
|
|
86
|
-
return {
|
|
87
|
-
|
|
85
|
+
return errors.map((message) => ({
|
|
86
|
+
message,
|
|
88
87
|
manualFix: "Use workspace inheritance in member Cargo.toml files, e.g., `version.workspace = true`.",
|
|
89
|
-
};
|
|
88
|
+
}));
|
|
90
89
|
}
|
|
91
|
-
return
|
|
90
|
+
return [];
|
|
92
91
|
},
|
|
93
|
-
}
|
|
92
|
+
};
|
|
94
93
|
//# sourceMappingURL=WorkspaceInheritance.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"WorkspaceInheritance.js","sourceRoot":"","sources":["../../src/policies/WorkspaceInheritance.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,IAAI,MAAM,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"WorkspaceInheritance.js","sourceRoot":"","sources":["../../src/policies/WorkspaceInheritance.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,IAAI,MAAM,OAAO,CAAC;AAEzB,OAAO,EAAE,SAAS,EAAE,MAAM,iCAAiC,CAAC;AAoB5D,MAAM,sBAAsB,GAAG,CAAC,SAAS,EAAE,SAAS,EAAE,SAAS,EAAE,YAAY,CAAC,CAAC;AAE/E;;GAEG;AACH,SAAS,iBAAiB,CAAC,MAAc,EAAE,cAAwB;IAClE,OAAO,cAAc,CAAC,IAAI,CAAC,CAAC,OAAO,EAAE,EAAE;QACtC,IAAI,OAAO,CAAC,QAAQ,C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E,CAAC;gBAC/C,SAAS;YACV,CAAC;YAED,MAAM,sBAAsB,CAAC,MAAM,EAAE,IAAI,EAAE,eAAe,EAAE,MAAM,CAAC,CAAC;QACrE,CAAC;QAED,IAAI,MAAM,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YACvB,OAAO,MAAM,CAAC,GAAG,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC;gBAC/B,OAAO;gBACP,SAAS,EACR,yFAAyF;aAC1F,CAAC,CAAC,CAAC;QACL,CAAC;QACD,OAAO,EAAE,CAAC;IACX,CAAC;CAC0D,CAAC","sourcesContent":["import { readFile } from \"node:fs/promises\";\nimport path from \"pathe\";\nimport type { FilePolicyDefinition } from \"../policy.js\";\nimport { parseToml } from \"../policyDefiners/tomlParser.js\";\n\n/**\n * Configuration for the WorkspaceInheritance policy.\n *\n * @public\n */\nexport interface WorkspaceInheritanceConfig {\n\t/**\n\t * Package fields that should use workspace inheritance.\n\t * @defaultValue [\"version\", \"authors\", \"license\", \"repository\"]\n\t */\n\tinherit?: string[];\n\n\t/**\n\t * Crate paths that are allowed to override inherited fields.\n\t */\n\tallowOverrides?: string[];\n}\n\nconst DEFAULT_INHERIT_FIELDS = [\"version\", \"authors\", \"license\", \"repository\"];\n\n/**\n * Check if a member path matches any override pattern.\n */\nfunction isOverrideAllowed(member: string, allowOverrides: string[]): boolean {\n\treturn allowOverrides.some((pattern) => {\n\t\tif (pattern.endsWith(\"*\")) {\n\t\t\treturn member.startsWith(pattern.slice(0, -1));\n\t\t}\n\t\treturn member === pattern;\n\t});\n}\n\n/**\n * Check a single member's fields for workspace inheritance compliance.\n */\nasync function checkMemberInheritance(\n\tmember: string,\n\troot: string,\n\tavailableFields: string[],\n\terrors: string[],\n): Promise<void> {\n\tconst memberCargoPath = path.join(root, member, \"Cargo.toml\");\n\n\ttry {\n\t\tconst memberContent = await readFile(memberCargoPath, \"utf-8\");\n\t\tconst memberToml = await parseToml(memberContent);\n\t\tconst memberPkg = memberToml.package as Record<string, unknown> | undefined;\n\n\t\tif (!memberPkg) {\n\t\t\treturn;\n\t\t}\n\n\t\tfor (const field of availableFields) {\n\t\t\tconst value = memberPkg[field];\n\t\t\t// Check if the field uses workspace inheritance\n\t\t\tif (\n\t\t\t\ttypeof value === \"object\" &&\n\t\t\t\tvalue !== null &&\n\t\t\t\t(value as Record<string, unknown>).workspace === true\n\t\t\t) {\n\t\t\t\t// Using workspace inheritance - good\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif (value !== undefined) {\n\t\t\t\terrors.push(\n\t\t\t\t\t`${member}: package.${field} should use workspace inheritance (${field}.workspace = true)`,\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\t} catch {\n\t\t// Member might not exist (handled by WorkspaceMembersValid)\n\t}\n}\n\n/**\n * A policy that ensures Cargo workspace members inherit fields from the workspace config.\n *\n * @public\n */\nexport const WorkspaceInheritance = {\n\tname: \"WorkspaceInheritance\",\n\tdescription:\n\t\t\"Ensures Cargo workspace members inherit shared fields (version, authors, etc.) from workspace config.\",\n\tmatch: /^Cargo\\.toml$/,\n\thandler: async ({ file, root, config }) => {\n\t\tconst content = await readFile(path.resolve(root, file), \"utf-8\");\n\t\tconst toml = await parseToml(content);\n\n\t\tconst workspace = toml.workspace as Record<string, unknown> | undefined;\n\t\tif (!workspace) {\n\t\t\treturn [];\n\t\t}\n\n\t\tconst members = workspace.members as string[] | undefined;\n\t\tif (!members || members.length === 0) {\n\t\t\treturn [];\n\t\t}\n\n\t\tconst inheritFields = config?.inherit ?? DEFAULT_INHERIT_FIELDS;\n\t\tconst allowOverrides = config?.allowOverrides ?? [];\n\n\t\t// Check which fields are defined at the workspace level\n\t\tconst workspacePkg = (workspace.package ?? {}) as Record<string, unknown>;\n\t\tconst availableFields = inheritFields.filter(\n\t\t\t(field) => workspacePkg[field] !== undefined,\n\t\t);\n\n\t\tif (availableFields.length === 0) {\n\t\t\treturn [];\n\t\t}\n\n\t\tconst errors: string[] = [];\n\n\t\tfor (const member of members) {\n\t\t\tif (member.includes(\"*\")) {\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tif (isOverrideAllowed(member, allowOverrides)) {\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tawait checkMemberInheritance(member, root, availableFields, errors);\n\t\t}\n\n\t\tif (errors.length > 0) {\n\t\t\treturn errors.map((message) => ({\n\t\t\t\tmessage,\n\t\t\t\tmanualFix:\n\t\t\t\t\t\"Use workspace inheritance in member Cargo.toml files, e.g., `version.workspace = true`.\",\n\t\t\t}));\n\t\t}\n\t\treturn [];\n\t},\n} satisfies FilePolicyDefinition<WorkspaceInheritanceConfig>;\n"]}
|
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import type { PolicyDefinition } from "../policy.js";
|
|
2
1
|
/**
|
|
3
2
|
* Configuration for the WorkspaceMembersValid policy.
|
|
4
3
|
*
|
|
5
|
-
* @
|
|
4
|
+
* @public
|
|
6
5
|
*/
|
|
7
6
|
export interface WorkspaceMembersValidConfig {
|
|
8
7
|
/**
|
|
@@ -14,7 +13,15 @@ export interface WorkspaceMembersValidConfig {
|
|
|
14
13
|
/**
|
|
15
14
|
* A policy that validates Cargo workspace member paths exist.
|
|
16
15
|
*
|
|
17
|
-
* @
|
|
16
|
+
* @public
|
|
18
17
|
*/
|
|
19
|
-
export declare const WorkspaceMembersValid:
|
|
18
|
+
export declare const WorkspaceMembersValid: {
|
|
19
|
+
name: string;
|
|
20
|
+
description: string;
|
|
21
|
+
match: RegExp;
|
|
22
|
+
handler: ({ file, root, config }: import("../policy.js").PolicyArgs<WorkspaceMembersValidConfig>) => Promise<{
|
|
23
|
+
message: string;
|
|
24
|
+
manualFix: string;
|
|
25
|
+
}[]>;
|
|
26
|
+
};
|
|
20
27
|
//# sourceMappingURL=WorkspaceMembersValid.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"WorkspaceMembersValid.d.ts","sourceRoot":"","sources":["../../src/policies/WorkspaceMembersValid.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"WorkspaceMembersValid.d.ts","sourceRoot":"","sources":["../../src/policies/WorkspaceMembersValid.ts"],"names":[],"mappings":"AAMA;;;;GAIG;AACH,MAAM,WAAW,2BAA2B;IAC3C;;;OAGG;IACH,aAAa,CAAC,EAAE,OAAO,CAAC;CACxB;AAoDD;;;;GAIG;AACH,eAAO,MAAM,qBAAqB;;;;;;;;CAwC2B,CAAC"}
|