repopo 0.10.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 +113 -0
- package/README.md +76 -77
- package/THIRD-PARTY-LICENSES.txt +232 -14
- package/bin/dev.js +5 -1
- 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 +1 -1
- package/esm/baseCommand.d.ts.map +1 -1
- package/esm/baseCommand.js +7 -10
- package/esm/baseCommand.js.map +1 -1
- package/esm/commands/check-native.d.ts +25 -0
- package/esm/commands/check-native.d.ts.map +1 -0
- package/esm/commands/check-native.js +156 -0
- package/esm/commands/check-native.js.map +1 -0
- package/esm/commands/check.d.ts +7 -34
- package/esm/commands/check.d.ts.map +1 -1
- package/esm/commands/check.js +76 -265
- package/esm/commands/check.js.map +1 -1
- package/esm/commands/list.d.ts.map +1 -1
- package/esm/commands/list.js +6 -6
- 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 +20 -3
- package/esm/context.d.ts.map +1 -1
- package/esm/context.js +18 -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 -11
- package/esm/index.d.ts.map +1 -1
- package/esm/index.js +3 -14
- package/esm/index.js.map +1 -1
- package/esm/makePolicy.d.ts +26 -79
- package/esm/makePolicy.d.ts.map +1 -1
- package/esm/makePolicy.js +51 -95
- package/esm/makePolicy.js.map +1 -1
- package/esm/perf.d.ts +10 -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 +41 -0
- package/esm/policies/CargoLicenceValidated.d.ts.map +1 -0
- package/esm/policies/CargoLicenceValidated.js +47 -0
- package/esm/policies/CargoLicenceValidated.js.map +1 -0
- package/esm/policies/CargoLintsConfigured.d.ts +30 -0
- package/esm/policies/CargoLintsConfigured.d.ts.map +1 -0
- package/esm/policies/CargoLintsConfigured.js +65 -0
- package/esm/policies/CargoLintsConfigured.js.map +1 -0
- package/esm/policies/CargoLockPolicy.d.ts +34 -0
- package/esm/policies/CargoLockPolicy.d.ts.map +1 -0
- package/esm/policies/CargoLockPolicy.js +61 -0
- package/esm/policies/CargoLockPolicy.js.map +1 -0
- package/esm/policies/CargoTomlRequired.d.ts +34 -0
- package/esm/policies/CargoTomlRequired.d.ts.map +1 -0
- package/esm/policies/CargoTomlRequired.js +77 -0
- package/esm/policies/CargoTomlRequired.js.map +1 -0
- package/esm/policies/CargoTomlSorted.d.ts +20 -0
- package/esm/policies/CargoTomlSorted.d.ts.map +1 -0
- package/esm/policies/CargoTomlSorted.js +168 -0
- package/esm/policies/CargoTomlSorted.js.map +1 -0
- package/esm/policies/ConditionalScripts.d.ts +10 -8
- package/esm/policies/ConditionalScripts.d.ts.map +1 -1
- package/esm/policies/ConditionalScripts.js +27 -24
- 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 +18 -20
- package/esm/policies/ExactScripts.js.map +1 -1
- package/esm/policies/GleamDepVersions.d.ts +25 -0
- package/esm/policies/GleamDepVersions.d.ts.map +1 -0
- package/esm/policies/GleamDepVersions.js +67 -0
- package/esm/policies/GleamDepVersions.js.map +1 -0
- package/esm/policies/GleamDocExists.d.ts +24 -0
- package/esm/policies/GleamDocExists.d.ts.map +1 -0
- package/esm/policies/GleamDocExists.js +39 -0
- package/esm/policies/GleamDocExists.js.map +1 -0
- package/esm/policies/GleamInternalModulesConfigured.d.ts +21 -0
- package/esm/policies/GleamInternalModulesConfigured.d.ts.map +1 -0
- package/esm/policies/GleamInternalModulesConfigured.js +32 -0
- package/esm/policies/GleamInternalModulesConfigured.js.map +1 -0
- package/esm/policies/GleamLicenceConfigured.d.ts +29 -0
- package/esm/policies/GleamLicenceConfigured.d.ts.map +1 -0
- package/esm/policies/GleamLicenceConfigured.js +36 -0
- package/esm/policies/GleamLicenceConfigured.js.map +1 -0
- package/esm/policies/GleamManifestCommitted.d.ts +16 -0
- package/esm/policies/GleamManifestCommitted.d.ts.map +1 -0
- package/esm/policies/GleamManifestCommitted.js +27 -0
- package/esm/policies/GleamManifestCommitted.js.map +1 -0
- package/esm/policies/GleamMonorepoConsistency.d.ts +38 -0
- package/esm/policies/GleamMonorepoConsistency.d.ts.map +1 -0
- package/esm/policies/GleamMonorepoConsistency.js +74 -0
- package/esm/policies/GleamMonorepoConsistency.js.map +1 -0
- package/esm/policies/GleamNameRestrictions.d.ts +25 -0
- package/esm/policies/GleamNameRestrictions.d.ts.map +1 -0
- package/esm/policies/GleamNameRestrictions.js +44 -0
- package/esm/policies/GleamNameRestrictions.js.map +1 -0
- package/esm/policies/GleamNoPathDepsInPublished.d.ts +22 -0
- package/esm/policies/GleamNoPathDepsInPublished.d.ts.map +1 -0
- package/esm/policies/GleamNoPathDepsInPublished.js +43 -0
- package/esm/policies/GleamNoPathDepsInPublished.js.map +1 -0
- package/esm/policies/GleamPathDepsValid.d.ts +9 -0
- package/esm/policies/GleamPathDepsValid.d.ts.map +1 -0
- package/esm/policies/GleamPathDepsValid.js +59 -0
- package/esm/policies/GleamPathDepsValid.js.map +1 -0
- package/esm/policies/GleamProjectStructure.d.ts +32 -0
- package/esm/policies/GleamProjectStructure.d.ts.map +1 -0
- package/esm/policies/GleamProjectStructure.js +32 -0
- package/esm/policies/GleamProjectStructure.js.map +1 -0
- package/esm/policies/GleamSharedDependencyVersions.d.ts +37 -0
- package/esm/policies/GleamSharedDependencyVersions.d.ts.map +1 -0
- package/esm/policies/GleamSharedDependencyVersions.js +101 -0
- package/esm/policies/GleamSharedDependencyVersions.js.map +1 -0
- package/esm/policies/GleamTomlRequired.d.ts +30 -0
- package/esm/policies/GleamTomlRequired.d.ts.map +1 -0
- package/esm/policies/GleamTomlRequired.js +37 -0
- package/esm/policies/GleamTomlRequired.js.map +1 -0
- package/esm/policies/GleamTomlSorted.d.ts +20 -0
- package/esm/policies/GleamTomlSorted.d.ts.map +1 -0
- package/esm/policies/GleamTomlSorted.js +157 -0
- package/esm/policies/GleamTomlSorted.js.map +1 -0
- package/esm/policies/GleamVersionConstraint.d.ts +20 -0
- package/esm/policies/GleamVersionConstraint.d.ts.map +1 -0
- package/esm/policies/GleamVersionConstraint.js +68 -0
- package/esm/policies/GleamVersionConstraint.js.map +1 -0
- package/esm/policies/HtmlFileHeaders.d.ts +4 -2
- package/esm/policies/HtmlFileHeaders.d.ts.map +1 -1
- package/esm/policies/HtmlFileHeaders.js +2 -2
- 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 +15 -0
- package/esm/policies/NoBuildDirectory.d.ts.map +1 -0
- package/esm/policies/NoBuildDirectory.js +24 -0
- package/esm/policies/NoBuildDirectory.js.map +1 -0
- 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 +14 -0
- package/esm/policies/NoTargetArtifacts.d.ts.map +1 -0
- package/esm/policies/NoTargetArtifacts.js +37 -0
- package/esm/policies/NoTargetArtifacts.js.map +1 -0
- package/esm/policies/NoUnsafeWithoutJustification.d.ts +31 -0
- package/esm/policies/NoUnsafeWithoutJustification.d.ts.map +1 -0
- package/esm/policies/NoUnsafeWithoutJustification.js +79 -0
- package/esm/policies/NoUnsafeWithoutJustification.js.map +1 -0
- package/esm/policies/NoWildcardDependencies.d.ts +30 -0
- package/esm/policies/NoWildcardDependencies.d.ts.map +1 -0
- package/esm/policies/NoWildcardDependencies.js +83 -0
- package/esm/policies/NoWildcardDependencies.js.map +1 -0
- 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 +38 -36
- 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 +18 -21
- 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 +29 -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 +51 -31
- 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 +32 -54
- 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 +34 -25
- 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 +24 -61
- 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 +42 -38
- 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 +17 -19
- package/esm/policies/PackageTestScripts.js.map +1 -1
- package/esm/policies/PublicApiDocumented.d.ts +21 -0
- package/esm/policies/PublicApiDocumented.d.ts.map +1 -0
- package/esm/policies/PublicApiDocumented.js +38 -0
- package/esm/policies/PublicApiDocumented.js.map +1 -0
- 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 +27 -26
- package/esm/policies/RequiredScripts.js.map +1 -1
- package/esm/policies/RustDocExists.d.ts +24 -0
- package/esm/policies/RustDocExists.d.ts.map +1 -0
- package/esm/policies/RustDocExists.js +49 -0
- package/esm/policies/RustDocExists.js.map +1 -0
- package/esm/policies/RustToolchainExists.d.ts +27 -0
- package/esm/policies/RustToolchainExists.d.ts.map +1 -0
- package/esm/policies/RustToolchainExists.js +28 -0
- package/esm/policies/RustToolchainExists.js.map +1 -0
- package/esm/policies/RustfmtConfigExists.d.ts +27 -0
- package/esm/policies/RustfmtConfigExists.d.ts.map +1 -0
- package/esm/policies/RustfmtConfigExists.js +28 -0
- package/esm/policies/RustfmtConfigExists.js.map +1 -0
- 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 +29 -0
- package/esm/policies/SharedDependencyVersions.d.ts.map +1 -0
- package/esm/policies/SharedDependencyVersions.js +143 -0
- package/esm/policies/SharedDependencyVersions.js.map +1 -0
- package/esm/policies/WorkspaceInheritance.d.ts +31 -0
- package/esm/policies/WorkspaceInheritance.d.ts.map +1 -0
- package/esm/policies/WorkspaceInheritance.js +93 -0
- package/esm/policies/WorkspaceInheritance.js.map +1 -0
- package/esm/policies/WorkspaceMembersValid.d.ts +27 -0
- package/esm/policies/WorkspaceMembersValid.d.ts.map +1 -0
- package/esm/policies/WorkspaceMembersValid.js +87 -0
- package/esm/policies/WorkspaceMembersValid.js.map +1 -0
- package/esm/policies/constants.d.ts +8 -0
- package/esm/policies/constants.d.ts.map +1 -1
- package/esm/policies/constants.js +9 -1
- package/esm/policies/constants.js.map +1 -1
- package/esm/policies.d.ts +43 -5
- package/esm/policies.d.ts.map +1 -1
- package/esm/policies.js +63 -6
- package/esm/policies.js.map +1 -1
- package/esm/policy.d.ts +65 -269
- 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 +82 -0
- package/esm/policyDefiners/defineCargoPolicy.d.ts.map +1 -0
- package/esm/policyDefiners/defineCargoPolicy.js +42 -0
- package/esm/policyDefiners/defineCargoPolicy.js.map +1 -0
- package/esm/policyDefiners/defineFileHeaderPolicy.d.ts +27 -14
- package/esm/policyDefiners/defineFileHeaderPolicy.d.ts.map +1 -1
- package/esm/policyDefiners/defineFileHeaderPolicy.js +19 -39
- package/esm/policyDefiners/defineFileHeaderPolicy.js.map +1 -1
- package/esm/policyDefiners/defineGleamPolicy.d.ts +81 -0
- package/esm/policyDefiners/defineGleamPolicy.d.ts.map +1 -0
- package/esm/policyDefiners/defineGleamPolicy.js +42 -0
- package/esm/policyDefiners/defineGleamPolicy.js.map +1 -0
- 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 +66 -0
- package/esm/policyDefiners/spdxValidator.d.ts.map +1 -0
- package/esm/policyDefiners/spdxValidator.js +139 -0
- package/esm/policyDefiners/spdxValidator.js.map +1 -0
- package/esm/policyDefiners/tomlParser.d.ts +8 -0
- package/esm/policyDefiners/tomlParser.d.ts.map +1 -0
- package/esm/policyDefiners/tomlParser.js +17 -0
- package/esm/policyDefiners/tomlParser.js.map +1 -0
- 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 +85 -0
- package/esm/runner.d.ts.map +1 -0
- package/esm/runner.js +189 -0
- package/esm/runner.js.map +1 -0
- 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 +117 -3
- package/package.json +66 -36
- package/scripts/benchmark.mjs +341 -0
- package/scripts/postinstall.mjs +154 -0
- package/sidecar/sidecar.mjs +399 -0
|
@@ -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;I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C,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"]}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { PolicyFinding } from "../policy.js";
|
|
2
|
+
/**
|
|
3
|
+
* Configuration for the SharedDependencyVersions policy.
|
|
4
|
+
*
|
|
5
|
+
* @public
|
|
6
|
+
*/
|
|
7
|
+
export interface SharedDependencyVersionsConfig {
|
|
8
|
+
/**
|
|
9
|
+
* Dependencies that should use workspace-level versions.
|
|
10
|
+
*/
|
|
11
|
+
requireWorkspaceDeps?: string[];
|
|
12
|
+
/**
|
|
13
|
+
* If true, detect version mismatches across workspace members.
|
|
14
|
+
* @defaultValue true
|
|
15
|
+
*/
|
|
16
|
+
detectMismatches?: boolean;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* A policy that detects dependency version mismatches across Cargo workspace members.
|
|
20
|
+
*
|
|
21
|
+
* @public
|
|
22
|
+
*/
|
|
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
|
+
};
|
|
29
|
+
//# sourceMappingURL=SharedDependencyVersions.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
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"}
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
import { readFile } from "node:fs/promises";
|
|
2
|
+
import path from "pathe";
|
|
3
|
+
import { glob } from "tinyglobby";
|
|
4
|
+
import { parseToml } from "../policyDefiners/tomlParser.js";
|
|
5
|
+
function extractVersion(dep) {
|
|
6
|
+
if (typeof dep === "string") {
|
|
7
|
+
return dep;
|
|
8
|
+
}
|
|
9
|
+
if (typeof dep === "object" && dep !== null) {
|
|
10
|
+
const record = dep;
|
|
11
|
+
if (typeof record.version === "string") {
|
|
12
|
+
return record.version;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
return undefined;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Collect dependencies from a TOML object.
|
|
19
|
+
*/
|
|
20
|
+
function collectDeps(toml) {
|
|
21
|
+
const deps = new Map();
|
|
22
|
+
const sections = ["dependencies", "dev-dependencies", "build-dependencies"];
|
|
23
|
+
for (const section of sections) {
|
|
24
|
+
const sectionDeps = toml[section];
|
|
25
|
+
if (!sectionDeps) {
|
|
26
|
+
continue;
|
|
27
|
+
}
|
|
28
|
+
for (const [name, value] of Object.entries(sectionDeps)) {
|
|
29
|
+
const version = extractVersion(value);
|
|
30
|
+
if (version && !version.startsWith("workspace")) {
|
|
31
|
+
deps.set(name, version);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
return deps;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Check that required dependencies are defined at the workspace level.
|
|
39
|
+
*/
|
|
40
|
+
function checkRequiredWorkspaceDeps(config, workspaceDeps, errors) {
|
|
41
|
+
if (!config?.requireWorkspaceDeps) {
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
for (const dep of config.requireWorkspaceDeps) {
|
|
45
|
+
if (!(dep in workspaceDeps)) {
|
|
46
|
+
errors.push(`Dependency "${dep}" should be defined in [workspace.dependencies]`);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Add a member's dependency version to the tracking map.
|
|
52
|
+
*/
|
|
53
|
+
function recordDependency(allDeps, name, version, member) {
|
|
54
|
+
if (!allDeps.has(name)) {
|
|
55
|
+
allDeps.set(name, new Map());
|
|
56
|
+
}
|
|
57
|
+
const versionMap = allDeps.get(name);
|
|
58
|
+
if (versionMap !== undefined) {
|
|
59
|
+
if (!versionMap.has(version)) {
|
|
60
|
+
versionMap.set(version, []);
|
|
61
|
+
}
|
|
62
|
+
const memberList = versionMap.get(version);
|
|
63
|
+
if (memberList !== undefined) {
|
|
64
|
+
memberList.push(member);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Collect dependency versions from all workspace members and record which members use them.
|
|
70
|
+
*/
|
|
71
|
+
async function collectMemberDeps(members, root, exclude, files) {
|
|
72
|
+
const allDeps = new Map();
|
|
73
|
+
const memberCargoPaths = await glob(members.map((member) => path.join(member, "Cargo.toml")), {
|
|
74
|
+
cwd: root,
|
|
75
|
+
ignore: exclude.map((member) => path.join(member, "Cargo.toml")),
|
|
76
|
+
});
|
|
77
|
+
for (const memberCargoPath of memberCargoPaths) {
|
|
78
|
+
if (!files.includes(memberCargoPath)) {
|
|
79
|
+
continue;
|
|
80
|
+
}
|
|
81
|
+
const memberContent = await readFile(path.resolve(root, memberCargoPath), "utf-8");
|
|
82
|
+
const memberToml = await parseToml(memberContent);
|
|
83
|
+
const deps = collectDeps(memberToml);
|
|
84
|
+
for (const [name, version] of deps) {
|
|
85
|
+
recordDependency(allDeps, name, version, memberCargoPath);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
return allDeps;
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* A policy that detects dependency version mismatches across Cargo workspace members.
|
|
92
|
+
*
|
|
93
|
+
* @public
|
|
94
|
+
*/
|
|
95
|
+
export const SharedDependencyVersions = {
|
|
96
|
+
name: "SharedDependencyVersions",
|
|
97
|
+
description: "Detects dependency version mismatches across Cargo workspace members.",
|
|
98
|
+
scope: "repository",
|
|
99
|
+
handler: async ({ files, root, config }) => {
|
|
100
|
+
if (!files.includes("Cargo.toml")) {
|
|
101
|
+
return [];
|
|
102
|
+
}
|
|
103
|
+
const detectMismatches = config?.detectMismatches ?? true;
|
|
104
|
+
const content = await readFile(path.resolve(root, "Cargo.toml"), "utf-8");
|
|
105
|
+
const toml = await parseToml(content);
|
|
106
|
+
const workspace = toml.workspace;
|
|
107
|
+
if (!workspace) {
|
|
108
|
+
return [];
|
|
109
|
+
}
|
|
110
|
+
const members = workspace.members;
|
|
111
|
+
if (!members || members.length === 0) {
|
|
112
|
+
return [];
|
|
113
|
+
}
|
|
114
|
+
const errors = [];
|
|
115
|
+
const findings = [];
|
|
116
|
+
const manualFix = "Use [workspace.dependencies] with `dep.workspace = true` in member Cargo.toml files to share versions.";
|
|
117
|
+
// Check required workspace deps
|
|
118
|
+
const workspaceDeps = (workspace.dependencies ?? {});
|
|
119
|
+
checkRequiredWorkspaceDeps(config, workspaceDeps, errors);
|
|
120
|
+
for (const error of errors) {
|
|
121
|
+
findings.push({ message: error, files: ["Cargo.toml"], manualFix });
|
|
122
|
+
}
|
|
123
|
+
// Detect mismatches across members
|
|
124
|
+
if (detectMismatches) {
|
|
125
|
+
const exclude = (workspace.exclude ?? []);
|
|
126
|
+
const allDeps = await collectMemberDeps(members, root, exclude, files);
|
|
127
|
+
for (const [dep, versionMap] of allDeps) {
|
|
128
|
+
if (versionMap.size > 1) {
|
|
129
|
+
const details = [...versionMap.entries()]
|
|
130
|
+
.map(([ver, memberList]) => `"${ver}" in ${memberList.join(", ")}`)
|
|
131
|
+
.join("; ");
|
|
132
|
+
findings.push({
|
|
133
|
+
message: `Version mismatch for "${dep}": ${details}`,
|
|
134
|
+
files: [...versionMap.values()].flat(),
|
|
135
|
+
manualFix,
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
return findings.length > 0 ? findings : [];
|
|
141
|
+
},
|
|
142
|
+
};
|
|
143
|
+
//# sourceMappingURL=SharedDependencyVersions.js.map
|
|
@@ -0,0 +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;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;YACxC,OAAO,MAAM,CAAC,OAAO,CAAC;QACvB,CAAC;IACF,CAAC;IACD,OA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AG,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"]}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Configuration for the WorkspaceInheritance policy.
|
|
3
|
+
*
|
|
4
|
+
* @public
|
|
5
|
+
*/
|
|
6
|
+
export interface WorkspaceInheritanceConfig {
|
|
7
|
+
/**
|
|
8
|
+
* Package fields that should use workspace inheritance.
|
|
9
|
+
* @defaultValue ["version", "authors", "license", "repository"]
|
|
10
|
+
*/
|
|
11
|
+
inherit?: string[];
|
|
12
|
+
/**
|
|
13
|
+
* Crate paths that are allowed to override inherited fields.
|
|
14
|
+
*/
|
|
15
|
+
allowOverrides?: string[];
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* A policy that ensures Cargo workspace members inherit fields from the workspace config.
|
|
19
|
+
*
|
|
20
|
+
* @public
|
|
21
|
+
*/
|
|
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
|
+
};
|
|
31
|
+
//# sourceMappingURL=WorkspaceInheritance.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
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"}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import { readFile } from "node:fs/promises";
|
|
2
|
+
import path from "pathe";
|
|
3
|
+
import { parseToml } from "../policyDefiners/tomlParser.js";
|
|
4
|
+
const DEFAULT_INHERIT_FIELDS = ["version", "authors", "license", "repository"];
|
|
5
|
+
/**
|
|
6
|
+
* Check if a member path matches any override pattern.
|
|
7
|
+
*/
|
|
8
|
+
function isOverrideAllowed(member, allowOverrides) {
|
|
9
|
+
return allowOverrides.some((pattern) => {
|
|
10
|
+
if (pattern.endsWith("*")) {
|
|
11
|
+
return member.startsWith(pattern.slice(0, -1));
|
|
12
|
+
}
|
|
13
|
+
return member === pattern;
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Check a single member's fields for workspace inheritance compliance.
|
|
18
|
+
*/
|
|
19
|
+
async function checkMemberInheritance(member, root, availableFields, errors) {
|
|
20
|
+
const memberCargoPath = path.join(root, member, "Cargo.toml");
|
|
21
|
+
try {
|
|
22
|
+
const memberContent = await readFile(memberCargoPath, "utf-8");
|
|
23
|
+
const memberToml = await parseToml(memberContent);
|
|
24
|
+
const memberPkg = memberToml.package;
|
|
25
|
+
if (!memberPkg) {
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
for (const field of availableFields) {
|
|
29
|
+
const value = memberPkg[field];
|
|
30
|
+
// Check if the field uses workspace inheritance
|
|
31
|
+
if (typeof value === "object" &&
|
|
32
|
+
value !== null &&
|
|
33
|
+
value.workspace === true) {
|
|
34
|
+
// Using workspace inheritance - good
|
|
35
|
+
continue;
|
|
36
|
+
}
|
|
37
|
+
if (value !== undefined) {
|
|
38
|
+
errors.push(`${member}: package.${field} should use workspace inheritance (${field}.workspace = true)`);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
catch {
|
|
43
|
+
// Member might not exist (handled by WorkspaceMembersValid)
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* A policy that ensures Cargo workspace members inherit fields from the workspace config.
|
|
48
|
+
*
|
|
49
|
+
* @public
|
|
50
|
+
*/
|
|
51
|
+
export const WorkspaceInheritance = {
|
|
52
|
+
name: "WorkspaceInheritance",
|
|
53
|
+
description: "Ensures Cargo workspace members inherit shared fields (version, authors, etc.) from workspace config.",
|
|
54
|
+
match: /^Cargo\.toml$/,
|
|
55
|
+
handler: async ({ file, root, config }) => {
|
|
56
|
+
const content = await readFile(path.resolve(root, file), "utf-8");
|
|
57
|
+
const toml = await parseToml(content);
|
|
58
|
+
const workspace = toml.workspace;
|
|
59
|
+
if (!workspace) {
|
|
60
|
+
return [];
|
|
61
|
+
}
|
|
62
|
+
const members = workspace.members;
|
|
63
|
+
if (!members || members.length === 0) {
|
|
64
|
+
return [];
|
|
65
|
+
}
|
|
66
|
+
const inheritFields = config?.inherit ?? DEFAULT_INHERIT_FIELDS;
|
|
67
|
+
const allowOverrides = config?.allowOverrides ?? [];
|
|
68
|
+
// Check which fields are defined at the workspace level
|
|
69
|
+
const workspacePkg = (workspace.package ?? {});
|
|
70
|
+
const availableFields = inheritFields.filter((field) => workspacePkg[field] !== undefined);
|
|
71
|
+
if (availableFields.length === 0) {
|
|
72
|
+
return [];
|
|
73
|
+
}
|
|
74
|
+
const errors = [];
|
|
75
|
+
for (const member of members) {
|
|
76
|
+
if (member.includes("*")) {
|
|
77
|
+
continue;
|
|
78
|
+
}
|
|
79
|
+
if (isOverrideAllowed(member, allowOverrides)) {
|
|
80
|
+
continue;
|
|
81
|
+
}
|
|
82
|
+
await checkMemberInheritance(member, root, availableFields, errors);
|
|
83
|
+
}
|
|
84
|
+
if (errors.length > 0) {
|
|
85
|
+
return errors.map((message) => ({
|
|
86
|
+
message,
|
|
87
|
+
manualFix: "Use workspace inheritance in member Cargo.toml files, e.g., `version.workspace = true`.",
|
|
88
|
+
}));
|
|
89
|
+
}
|
|
90
|
+
return [];
|
|
91
|
+
},
|
|
92
|
+
};
|
|
93
|
+
//# sourceMappingURL=WorkspaceInheritance.js.map
|
|
@@ -0,0 +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;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,CAAC,GAAG,CAAC,EAAE,CAAC;YAC3B,OAAO,MAAM,CAAC,UAAU,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC;QAChD,CAAC;QACD,OAAO,MAAM,KAAK,OAAO,CAAC;IAC3B,CAAC,CAAC,CAAC;AACJ,CAAC;AAED;;GAEG;AACH,KAAK,UAAU,sBAAsB,CACpC,MAAc,EACd,IAAY,EACZ,eAAyB,EACzB,MAAgB;IAEhB,MAAM,eAAe,GAAG,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,MAAM,EAAE,YAAY,CAAC,CAAC;IAE9D,IAAI,CAAC;QACJ,MAAM,aAAa,GAAG,MAAM,QAAQ,CAAC,eAAe,EAAE,OAAO,CAAC,CAAC;QAC/D,MAAM,UAAU,GAAG,MAAM,SAAS,CAAC,aAAa,CAAC,CAAC;QAClD,MAAM,SAAS,GAAG,UAAU,CAAC,OAA8C,CAAC;QAE5E,IAAI,CAAC,SAAS,EAAE,CAAC;YAChB,OAAO;QACR,CAAC;QAED,KAAK,MAAM,K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AAc,IAAI,EAAE,CAAC;QAEpD,wDAAwD;QACxD,MAAM,YAAY,GAAG,CAAC,SAAS,CAAC,OAAO,IAAI,EAAE,CAA4B,CAAC;QAC1E,MAAM,eAAe,GAAG,aAAa,CAAC,MAAM,CAC3C,CAAC,KAAK,EAAE,EAAE,CAAC,YAAY,CAAC,KAAK,CAAC,KAAK,SAAS,CAC5C,CAAC;QAEF,IAAI,eAAe,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YAClC,OAAO,EAAE,CAAC;QACX,CAAC;QAED,MAAM,MAAM,GAAa,EAAE,CAAC;QAE5B,KAAK,MAAM,MAAM,IAAI,OAAO,EAAE,CAAC;YAC9B,IAAI,MAAM,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE,CAAC;gBAC1B,SAAS;YACV,CAAC;YAED,IAAI,iBAAiB,CAAC,MAAM,EAAE,cAAc,CAAC,EAAE,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"]}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Configuration for the WorkspaceMembersValid policy.
|
|
3
|
+
*
|
|
4
|
+
* @public
|
|
5
|
+
*/
|
|
6
|
+
export interface WorkspaceMembersValidConfig {
|
|
7
|
+
/**
|
|
8
|
+
* If true, validate that all member paths exist on disk.
|
|
9
|
+
* @defaultValue true
|
|
10
|
+
*/
|
|
11
|
+
validatePaths?: boolean;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* A policy that validates Cargo workspace member paths exist.
|
|
15
|
+
*
|
|
16
|
+
* @public
|
|
17
|
+
*/
|
|
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
|
+
};
|
|
27
|
+
//# sourceMappingURL=WorkspaceMembersValid.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
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"}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { existsSync, readdirSync } from "node:fs";
|
|
2
|
+
import { readFile } from "node:fs/promises";
|
|
3
|
+
import path from "pathe";
|
|
4
|
+
import { parseToml } from "../policyDefiners/tomlParser.js";
|
|
5
|
+
const GLOB_SUFFIX_REGEX = /\/?\*\*?$/;
|
|
6
|
+
/**
|
|
7
|
+
* Expand a simple glob pattern (e.g., "crates/*") into matching directories.
|
|
8
|
+
*/
|
|
9
|
+
function expandSimpleGlob(root, pattern) {
|
|
10
|
+
if (!pattern.includes("*")) {
|
|
11
|
+
return [pattern];
|
|
12
|
+
}
|
|
13
|
+
const base = pattern.replace(GLOB_SUFFIX_REGEX, "");
|
|
14
|
+
const baseDir = path.join(root, base);
|
|
15
|
+
if (!existsSync(baseDir)) {
|
|
16
|
+
return [];
|
|
17
|
+
}
|
|
18
|
+
try {
|
|
19
|
+
const entries = readdirSync(baseDir, { withFileTypes: true });
|
|
20
|
+
return entries
|
|
21
|
+
.filter((e) => e.isDirectory())
|
|
22
|
+
.filter((e) => existsSync(path.join(baseDir, e.name, "Cargo.toml")))
|
|
23
|
+
.map((e) => path.join(base, e.name));
|
|
24
|
+
}
|
|
25
|
+
catch {
|
|
26
|
+
return [];
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Validate a single workspace member entry.
|
|
31
|
+
*/
|
|
32
|
+
function validateMember(member, root, errors) {
|
|
33
|
+
if (member.includes("*")) {
|
|
34
|
+
// Expand glob and check each result
|
|
35
|
+
const expanded = expandSimpleGlob(root, member);
|
|
36
|
+
if (expanded.length === 0) {
|
|
37
|
+
errors.push(`Workspace member glob "${member}" matches no directories with Cargo.toml`);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
else {
|
|
41
|
+
const memberPath = path.join(root, member);
|
|
42
|
+
if (!existsSync(memberPath)) {
|
|
43
|
+
errors.push(`Workspace member "${member}" does not exist`);
|
|
44
|
+
}
|
|
45
|
+
else if (!existsSync(path.join(memberPath, "Cargo.toml"))) {
|
|
46
|
+
errors.push(`Workspace member "${member}" exists but has no Cargo.toml`);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* A policy that validates Cargo workspace member paths exist.
|
|
52
|
+
*
|
|
53
|
+
* @public
|
|
54
|
+
*/
|
|
55
|
+
export const WorkspaceMembersValid = {
|
|
56
|
+
name: "WorkspaceMembersValid",
|
|
57
|
+
description: "Validates that all Cargo workspace member paths exist and contain Cargo.toml files.",
|
|
58
|
+
match: /^Cargo\.toml$/,
|
|
59
|
+
handler: async ({ file, root, config }) => {
|
|
60
|
+
const validatePaths = config?.validatePaths ?? true;
|
|
61
|
+
const content = await readFile(path.resolve(root, file), "utf-8");
|
|
62
|
+
const toml = await parseToml(content);
|
|
63
|
+
const workspace = toml.workspace;
|
|
64
|
+
if (!workspace) {
|
|
65
|
+
return [];
|
|
66
|
+
}
|
|
67
|
+
const members = workspace.members;
|
|
68
|
+
if (!members || members.length === 0) {
|
|
69
|
+
return [];
|
|
70
|
+
}
|
|
71
|
+
if (!validatePaths) {
|
|
72
|
+
return [];
|
|
73
|
+
}
|
|
74
|
+
const errors = [];
|
|
75
|
+
for (const member of members) {
|
|
76
|
+
validateMember(member, root, errors);
|
|
77
|
+
}
|
|
78
|
+
if (errors.length > 0) {
|
|
79
|
+
return errors.map((message) => ({
|
|
80
|
+
message,
|
|
81
|
+
manualFix: "Fix the workspace.members paths in root Cargo.toml to point to valid crate directories.",
|
|
82
|
+
}));
|
|
83
|
+
}
|
|
84
|
+
return [];
|
|
85
|
+
},
|
|
86
|
+
};
|
|
87
|
+
//# sourceMappingURL=WorkspaceMembersValid.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"WorkspaceMembersValid.js","sourceRoot":"","sources":["../../src/policies/WorkspaceMembersValid.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAClD,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,IAAI,MAAM,OAAO,CAAC;AAEzB,OAAO,EAAE,SAAS,EAAE,MAAM,iCAAiC,CAAC;AAe5D,MAAM,iBAAiB,GAAG,WAAW,CAAC;AAEtC;;GAEG;AACH,SAAS,gBAAgB,CAAC,IAAY,EAAE,OAAe;IACtD,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE,CAAC;QAC5B,OAAO,CAAC,OAAO,CAAC,CAAC;IAClB,CAAC;IAED,MAAM,IAAI,GAAG,OAAO,CAAC,OAAO,CAAC,iBAAiB,EAAE,EAAE,CAAC,CAAC;IACpD,MAAM,OAAO,GAAG,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,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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;CAC2D,CAAC","sourcesContent":["import { existsSync, readdirSync } from \"node:fs\";\nimport { 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 WorkspaceMembersValid policy.\n *\n * @public\n */\nexport interface WorkspaceMembersValidConfig {\n\t/**\n\t * If true, validate that all member paths exist on disk.\n\t * @defaultValue true\n\t */\n\tvalidatePaths?: boolean;\n}\n\nconst GLOB_SUFFIX_REGEX = /\\/?\\*\\*?$/;\n\n/**\n * Expand a simple glob pattern (e.g., \"crates/*\") into matching directories.\n */\nfunction expandSimpleGlob(root: string, pattern: string): string[] {\n\tif (!pattern.includes(\"*\")) {\n\t\treturn [pattern];\n\t}\n\n\tconst base = pattern.replace(GLOB_SUFFIX_REGEX, \"\");\n\tconst baseDir = path.join(root, base);\n\n\tif (!existsSync(baseDir)) {\n\t\treturn [];\n\t}\n\n\ttry {\n\t\tconst entries = readdirSync(baseDir, { withFileTypes: true });\n\t\treturn entries\n\t\t\t.filter((e) => e.isDirectory())\n\t\t\t.filter((e) => existsSync(path.join(baseDir, e.name, \"Cargo.toml\")))\n\t\t\t.map((e) => path.join(base, e.name));\n\t} catch {\n\t\treturn [];\n\t}\n}\n\n/**\n * Validate a single workspace member entry.\n */\nfunction validateMember(member: string, root: string, errors: string[]): void {\n\tif (member.includes(\"*\")) {\n\t\t// Expand glob and check each result\n\t\tconst expanded = expandSimpleGlob(root, member);\n\t\tif (expanded.length === 0) {\n\t\t\terrors.push(\n\t\t\t\t`Workspace member glob \"${member}\" matches no directories with Cargo.toml`,\n\t\t\t);\n\t\t}\n\t} else {\n\t\tconst memberPath = path.join(root, member);\n\t\tif (!existsSync(memberPath)) {\n\t\t\terrors.push(`Workspace member \"${member}\" does not exist`);\n\t\t} else if (!existsSync(path.join(memberPath, \"Cargo.toml\"))) {\n\t\t\terrors.push(`Workspace member \"${member}\" exists but has no Cargo.toml`);\n\t\t}\n\t}\n}\n\n/**\n * A policy that validates Cargo workspace member paths exist.\n *\n * @public\n */\nexport const WorkspaceMembersValid = {\n\tname: \"WorkspaceMembersValid\",\n\tdescription:\n\t\t\"Validates that all Cargo workspace member paths exist and contain Cargo.toml files.\",\n\tmatch: /^Cargo\\.toml$/,\n\thandler: async ({ file, root, config }) => {\n\t\tconst validatePaths = config?.validatePaths ?? true;\n\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\tif (!validatePaths) {\n\t\t\treturn [];\n\t\t}\n\n\t\tconst errors: string[] = [];\n\n\t\tfor (const member of members) {\n\t\t\tvalidateMember(member, root, 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\"Fix the workspace.members paths in root Cargo.toml to point to valid crate directories.\",\n\t\t\t}));\n\t\t}\n\t\treturn [];\n\t},\n} satisfies FilePolicyDefinition<WorkspaceMembersValidConfig>;\n"]}
|
|
@@ -2,4 +2,12 @@
|
|
|
2
2
|
* A regular expression that matches package.json files in path strings.
|
|
3
3
|
*/
|
|
4
4
|
export declare const PackageJsonRegexMatch: RegExp;
|
|
5
|
+
/**
|
|
6
|
+
* A regular expression that matches Cargo.toml files in path strings.
|
|
7
|
+
*/
|
|
8
|
+
export declare const CargoTomlRegexMatch: RegExp;
|
|
9
|
+
/**
|
|
10
|
+
* A regular expression that matches gleam.toml files in path strings.
|
|
11
|
+
*/
|
|
12
|
+
export declare const GleamTomlRegexMatch: RegExp;
|
|
5
13
|
//# sourceMappingURL=constants.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../src/policies/constants.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,eAAO,MAAM,qBAAqB,
|
|
1
|
+
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../src/policies/constants.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,eAAO,MAAM,qBAAqB,QAA0B,CAAC;AAC7D;;GAEG;AACH,eAAO,MAAM,mBAAmB,QAAuB,CAAC;AAExD;;GAEG;AACH,eAAO,MAAM,mBAAmB,QAAuB,CAAC"}
|
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* A regular expression that matches package.json files in path strings.
|
|
3
3
|
*/
|
|
4
|
-
export const PackageJsonRegexMatch = /(^|\/)package\.json
|
|
4
|
+
export const PackageJsonRegexMatch = /(^|\/)package\.json$/i;
|
|
5
|
+
/**
|
|
6
|
+
* A regular expression that matches Cargo.toml files in path strings.
|
|
7
|
+
*/
|
|
8
|
+
export const CargoTomlRegexMatch = /(^|\/)Cargo\.toml$/;
|
|
9
|
+
/**
|
|
10
|
+
* A regular expression that matches gleam.toml files in path strings.
|
|
11
|
+
*/
|
|
12
|
+
export const GleamTomlRegexMatch = /(^|\/)gleam\.toml$/;
|
|
5
13
|
//# sourceMappingURL=constants.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../src/policies/constants.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,CAAC,MAAM,qBAAqB,GAAG,
|
|
1
|
+
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../src/policies/constants.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,CAAC,MAAM,qBAAqB,GAAG,uBAAuB,CAAC;AAC7D;;GAEG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAG,oBAAoB,CAAC;AAExD;;GAEG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAG,oBAAoB,CAAC","sourcesContent":["/**\n * A regular expression that matches package.json files in path strings.\n */\nexport const PackageJsonRegexMatch = /(^|\\/)package\\.json$/i;\n/**\n * A regular expression that matches Cargo.toml files in path strings.\n */\nexport const CargoTomlRegexMatch = /(^|\\/)Cargo\\.toml$/;\n\n/**\n * A regular expression that matches gleam.toml files in path strings.\n */\nexport const GleamTomlRegexMatch = /(^|\\/)gleam\\.toml$/;\n"]}
|