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
package/esm/policy.js
CHANGED
|
@@ -1,128 +1,7 @@
|
|
|
1
1
|
import { NoJsFileExtensions } from "./policies/NoJsFileExtensions.js";
|
|
2
2
|
import { PackageJsonRepoDirectoryProperty } from "./policies/PackageJsonRepoDirectoryProperty.js";
|
|
3
3
|
import { PackageJsonSorted } from "./policies/PackageJsonSorted.js";
|
|
4
|
-
/**
|
|
5
|
-
* Abstract base class for creating policies with object-based construction.
|
|
6
|
-
*
|
|
7
|
-
* @remarks
|
|
8
|
-
* This class accepts a {@link PolicyShape} object in its constructor,
|
|
9
|
-
* making it easier to add new optional properties in the future without breaking changes.
|
|
10
|
-
*
|
|
11
|
-
* @alpha
|
|
12
|
-
*/
|
|
13
|
-
export class Policy {
|
|
14
|
-
name;
|
|
15
|
-
description;
|
|
16
|
-
match;
|
|
17
|
-
handler;
|
|
18
|
-
defaultConfig;
|
|
19
|
-
resolver;
|
|
20
|
-
constructor(definition) {
|
|
21
|
-
this.name = definition.name;
|
|
22
|
-
this.description = definition.description;
|
|
23
|
-
this.match = definition.match;
|
|
24
|
-
this.handler = definition.handler;
|
|
25
|
-
this.defaultConfig = definition.defaultConfig;
|
|
26
|
-
this.resolver = definition.resolver;
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
// ============================================================================
|
|
30
|
-
// Type Guards
|
|
31
|
-
// ============================================================================
|
|
32
|
-
/**
|
|
33
|
-
* Type guard to check if a result is a {@link PolicyFixResult} (legacy).
|
|
34
|
-
*
|
|
35
|
-
* @deprecated Use {@link isPolicyError} instead when working with the new {@link PolicyError} format.
|
|
36
|
-
*
|
|
37
|
-
* @alpha
|
|
38
|
-
*/
|
|
39
|
-
// biome-ignore lint/suspicious/noExplicitAny: type guard
|
|
40
|
-
export function isPolicyFixResult(toCheck) {
|
|
41
|
-
if (typeof toCheck !== "object" || toCheck === null) {
|
|
42
|
-
return false;
|
|
43
|
-
}
|
|
44
|
-
return "resolved" in toCheck;
|
|
45
|
-
}
|
|
46
|
-
/**
|
|
47
|
-
* Type guard to check if a result is a PolicyError (new format).
|
|
48
|
-
*
|
|
49
|
-
* @alpha
|
|
50
|
-
*/
|
|
51
|
-
// biome-ignore lint/suspicious/noExplicitAny: type guard
|
|
52
|
-
export function isPolicyError(toCheck) {
|
|
53
|
-
if (typeof toCheck !== "object" || toCheck === null) {
|
|
54
|
-
return false;
|
|
55
|
-
}
|
|
56
|
-
return "error" in toCheck && typeof toCheck.error === "string";
|
|
57
|
-
}
|
|
58
|
-
/**
|
|
59
|
-
* Type guard to check if a result is a {@link PolicyFailure} (legacy format).
|
|
60
|
-
*
|
|
61
|
-
* @deprecated Use {@link isPolicyError} instead when working with the new {@link PolicyError} format.
|
|
62
|
-
*
|
|
63
|
-
* @alpha
|
|
64
|
-
*/
|
|
65
|
-
// biome-ignore lint/suspicious/noExplicitAny: type guard
|
|
66
|
-
export function isPolicyFailure(toCheck) {
|
|
67
|
-
if (typeof toCheck !== "object" || toCheck === null) {
|
|
68
|
-
return false;
|
|
69
|
-
}
|
|
70
|
-
return "errorMessages" in toCheck && Array.isArray(toCheck.errorMessages);
|
|
71
|
-
}
|
|
72
|
-
// ============================================================================
|
|
73
|
-
// Conversion Functions
|
|
74
|
-
// ============================================================================
|
|
75
|
-
/**
|
|
76
|
-
* Converts a legacy PolicyFailure/PolicyFixResult to the new PolicyError format.
|
|
77
|
-
* @internal
|
|
78
|
-
*/
|
|
79
|
-
export function convertLegacyResult(result, _file) {
|
|
80
|
-
if (result === true) {
|
|
81
|
-
return true;
|
|
82
|
-
}
|
|
83
|
-
// Check if it's already the new format
|
|
84
|
-
if (isPolicyError(result)) {
|
|
85
|
-
return result;
|
|
86
|
-
}
|
|
87
|
-
// It's a legacy PolicyFailure or PolicyFixResult
|
|
88
|
-
const error = result.errorMessages?.join("; ") ?? "Policy violation";
|
|
89
|
-
const isFixResult = isPolicyFixResult(result);
|
|
90
|
-
return {
|
|
91
|
-
error,
|
|
92
|
-
fixable: result.autoFixable ?? false,
|
|
93
|
-
fixed: isFixResult ? result.resolved : undefined,
|
|
94
|
-
manualFix: result.manualFix,
|
|
95
|
-
};
|
|
96
|
-
}
|
|
97
|
-
/**
|
|
98
|
-
* Converts a new PolicyError to the legacy PolicyFailure format.
|
|
99
|
-
* @internal
|
|
100
|
-
*/
|
|
101
|
-
export function convertToLegacyResult(result, policyName, file) {
|
|
102
|
-
const base = {
|
|
103
|
-
name: policyName,
|
|
104
|
-
file,
|
|
105
|
-
autoFixable: result.fixable,
|
|
106
|
-
errorMessages: [result.error],
|
|
107
|
-
manualFix: result.manualFix,
|
|
108
|
-
};
|
|
109
|
-
if (result.fixed !== undefined) {
|
|
110
|
-
return {
|
|
111
|
-
...base,
|
|
112
|
-
resolved: result.fixed,
|
|
113
|
-
};
|
|
114
|
-
}
|
|
115
|
-
return base;
|
|
116
|
-
}
|
|
117
|
-
// ============================================================================
|
|
118
|
-
// Default Policies
|
|
119
|
-
// ============================================================================
|
|
120
|
-
/**
|
|
121
|
-
* Default policies included with repopo.
|
|
122
|
-
*
|
|
123
|
-
* @alpha
|
|
124
|
-
*/
|
|
125
|
-
// biome-ignore lint/suspicious/noExplicitAny: FIXME
|
|
4
|
+
/** The default definitions, configured when no policies are supplied. @public */
|
|
126
5
|
export const DefaultPolicies = [
|
|
127
6
|
NoJsFileExtensions,
|
|
128
7
|
PackageJsonRepoDirectoryProperty,
|
package/esm/policy.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"policy.js","sourceRoot":"","sources":["../src/policy.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,kBAAkB,EAAE,MAAM,kCAAkC,CAAC;AACtE,OAAO,EAAE,gCAAgC,EAAE,MAAM,gDAAgD,CAAC;AAClG,OAAO,EAAE,iBAAiB,EAAE,MAAM,iCAAiC,CAAC;AAuOpE;;;;;;;;GAQG;AACH,MAAM,OAAgB,MAAM;IACX,IAAI,CAAS;IACb,WAAW,CAAS;IACpB,KAAK,CAAS;IACd,OAAO,CAAmB;IAC1B,aAAa,CAAiB;IAC9B,QAAQ,CAA2C;IAEnE,YAAmB,UAA0B;QAC5C,IAAI,CAAC,IAA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ions } from \"./policies/NoJsFileExtensions.js\";\nimport { PackageJsonRepoDirectoryProperty } from \"./policies/PackageJsonRepoDirectoryProperty.js\";\nimport { PackageJsonSorted } from \"./policies/PackageJsonSorted.js\";\n\n/**\n * A type representing a policy name.\n *\n * @alpha\n */\nexport type PolicyName = string;\n\n/**\n * Arguments passed to policy handler functions.\n *\n * @alpha\n */\nexport interface PolicyArgs<C = void> {\n\t/**\n\t * Path to the file, relative to the repo root.\n\t */\n\tfile: string;\n\n\t/**\n\t * Absolute path to the root of the repo.\n\t */\n\troot: string;\n\n\t/**\n\t * If true, the handler should resolve any violations automatically if possible.\n\t */\n\tresolve: boolean;\n\n\t/**\n\t * Optional configuration for the policy.\n\t */\n\tconfig?: C | undefined;\n}\n\n/**\n * @deprecated Use {@link PolicyArgs} instead.\n * @alpha\n */\nexport type PolicyFunctionArguments<C> = PolicyArgs<C>;\n\n// ============================================================================\n// New Result Types\n// ============================================================================\n\n/**\n * A policy error returned when a file fails a policy check.\n *\n * @alpha\n */\nexport interface PolicyError {\n\t/**\n\t * The error message describing what failed.\n\t */\n\terror: string;\n\n\t/**\n\t * Set to `true` if the policy violation can be fixed automatically.\n\t */\n\tfixable?: boolean | undefined;\n\n\t/**\n\t * Set to `true` if the violation was successfully fixed (only set when resolve=true).\n\t */\n\tfixed?: boolean | undefined;\n\n\t/**\n\t * An optional string that tells the user how to manually fix the failure.\n\t */\n\tmanualFix?: string | undefined;\n}\n\n/**\n * The result of a policy handler.\n * Returns `true` if the file passes the policy, or a {@link PolicyError} if it fails.\n *\n * @alpha\n */\nexport type PolicyResult = true | PolicyError;\n\n// ============================================================================\n// Legacy Result Types (Still supported for backward compatibility)\n// ============================================================================\n\n/**\n * A policy failure (legacy format).\n *\n * @deprecated Use {@link PolicyError} instead, which has a simpler API.\n *\n * @alpha\n */\nexport interface PolicyFailure {\n\t/**\n\t * Name of the policy that failed.\n\t */\n\tname: PolicyName;\n\n\t/**\n\t * Path to the file that failed the policy.\n\t */\n\tfile: string;\n\n\t/**\n\t * Set to `true` if the policy can be fixed automatically.\n\t */\n\tautoFixable?: boolean | undefined;\n\n\t/**\n\t * An optional error message accompanying the failure.\n\t */\n\terrorMessages: string[];\n\n\t/**\n\t * An optional string that tells the user how to fix the failure(s).\n\t */\n\tmanualFix?: string | undefined;\n}\n\n/**\n * The result of an automatic fix for a failing policy (legacy format).\n *\n * @deprecated Use {@link PolicyError} with `fixed: boolean` instead.\n *\n * @alpha\n */\nexport interface PolicyFixResult extends PolicyFailure {\n\t/**\n\t * Set to true if the failure was resolved by the automated fixer.\n\t */\n\tresolved: boolean;\n}\n\n/**\n * Result type that accepts both legacy and new formats.\n *\n * @alpha\n */\nexport type PolicyHandlerResult =\n\t| true\n\t| PolicyFailure\n\t| PolicyFixResult\n\t| PolicyError;\n\n// ============================================================================\n// Handler Types\n// ============================================================================\n\n/**\n * A policy handler function that checks a file against a policy.\n *\n * @remarks\n * Policy handlers can be implemented in two ways:\n * - As an async function returning a Promise\n * - As an Effection generator function returning an Operation\n *\n * Both styles are supported. Async handlers are automatically wrapped for Effection.\n *\n * Handlers can return either the legacy format ({@link PolicyFailure}) or\n * the new format ({@link PolicyError}). The new format is simpler and recommended\n * for new policies.\n *\n * @alpha\n */\nexport type PolicyHandler<C = unknown | undefined> =\n\t| ((args: PolicyArgs<C>) => Promise<PolicyHandlerResult>)\n\t| ((args: PolicyArgs<C>) => Operation<PolicyHandlerResult>);\n\n/**\n * A standalone resolver function that can fix policy violations (legacy format).\n *\n * @deprecated Use {@link PolicyResolver} instead, which uses {@link PolicyError}.\n *\n * @alpha\n */\nexport type PolicyStandaloneResolver<C = undefined> = (\n\targs: Omit<PolicyArgs<C>, \"resolve\">,\n) => Promise<PolicyFixResult> | Operation<PolicyFixResult>;\n\n/**\n * A standalone resolver function using the new format.\n *\n * @alpha\n */\nexport type PolicyResolver<C = void> = (\n\targs: Omit<PolicyArgs<C>, \"resolve\">,\n) => Promise<PolicyError> | Operation<PolicyError>;\n\n// ============================================================================\n// Policy Definition Types\n// ============================================================================\n\n/**\n * Interface describing the shape of a policy definition.\n *\n * @typeParam C - Type of configuration object used by the policy\n *\n * @alpha\n */\nexport interface PolicyShape<C = void> {\n\t/**\n\t * The name of the policy; displayed in UI and used in settings.\n\t */\n\tname: PolicyName;\n\n\t/**\n\t * A detailed description of the policy and its purpose.\n\t */\n\tdescription: string;\n\n\t/**\n\t * A regular expression that matches files this policy applies to.\n\t */\n\tmatch: RegExp;\n\n\t/**\n\t * The handler function that checks if a file complies with the policy.\n\t */\n\thandler: PolicyHandler<C>;\n\n\t/**\n\t * An optional resolver function that can automatically fix violations.\n\t */\n\tresolver?: PolicyStandaloneResolver<C> | undefined;\n\n\t/**\n\t * A default configuration that will be used if none is provided.\n\t */\n\tdefaultConfig?: C | undefined;\n}\n\n/**\n * Abstract base class for creating policies with object-based construction.\n *\n * @remarks\n * This class accepts a {@link PolicyShape} object in its constructor,\n * making it easier to add new optional properties in the future without breaking changes.\n *\n * @alpha\n */\nexport abstract class Policy<C = void> implements PolicyShape<C> {\n\tpublic readonly name: string;\n\tpublic readonly description: string;\n\tpublic readonly match: RegExp;\n\tpublic readonly handler: PolicyHandler<C>;\n\tpublic readonly defaultConfig?: C | undefined;\n\tpublic readonly resolver?: PolicyStandaloneResolver<C> | undefined;\n\n\tpublic constructor(definition: PolicyShape<C>) {\n\t\tthis.name = definition.name;\n\t\tthis.description = definition.description;\n\t\tthis.match = definition.match;\n\t\tthis.handler = definition.handler;\n\t\tthis.defaultConfig = definition.defaultConfig;\n\t\tthis.resolver = definition.resolver;\n\t}\n}\n\n/**\n * @deprecated Use {@link PolicyShape} instead.\n * @alpha\n */\nexport type PolicyDefinition<C = undefined> = PolicyShape<C>;\n\n/**\n * A policy instance with configuration and exclusion settings applied.\n *\n * @typeParam C - Type of configuration object used by the policy\n *\n * @alpha\n */\nexport interface ConfiguredPolicy<C = void> extends PolicyShape<C> {\n\t/**\n\t * The configuration applied to this policy instance.\n\t */\n\tconfig?: C | undefined;\n\n\t/**\n\t * File paths matching these patterns will be excluded from this policy.\n\t * @deprecated Use `excludeFiles` instead for backward compatibility.\n\t */\n\texclude?: (string | RegExp)[] | undefined;\n\n\t/**\n\t * File paths matching these patterns will be excluded from this policy.\n\t */\n\texcludeFiles?: (string | RegExp)[] | undefined;\n\n\t/**\n\t * Internal normalized handler (always an Effection Operation).\n\t * This is set by the policy() function and used by the execution engine.\n\t * @internal\n\t */\n\t_internalHandler?: (args: PolicyArgs<C>) => Operation<PolicyHandlerResult>;\n}\n\n/**\n * Settings for configuring a policy instance.\n * @alpha\n */\nexport interface PolicyInstanceSettings<C> {\n\t/**\n\t * An array of strings/regular expressions. File paths that match any of these expressions will be completely excluded\n\t * from policy.\n\t *\n\t * Paths will be matched relative to the root of the repo.\n\t */\n\texcludeFiles?: (string | RegExp)[];\n\n\t/**\n\t * The config that is applied to the policy instance.\n\t */\n\tconfig?: C | undefined;\n}\n\n/**\n * @deprecated Use {@link ConfiguredPolicy} instead.\n * @alpha\n */\nexport type PolicyInstance<C = undefined> = ConfiguredPolicy<C>;\n\n// ============================================================================\n// Type Guards\n// ============================================================================\n\n/**\n * Type guard to check if a result is a {@link PolicyFixResult} (legacy).\n *\n * @deprecated Use {@link isPolicyError} instead when working with the new {@link PolicyError} format.\n *\n * @alpha\n */\n// biome-ignore lint/suspicious/noExplicitAny: type guard\nexport function isPolicyFixResult(toCheck: any): toCheck is PolicyFixResult {\n\tif (typeof toCheck !== \"object\" || toCheck === null) {\n\t\treturn false;\n\t}\n\treturn \"resolved\" in toCheck;\n}\n\n/**\n * Type guard to check if a result is a PolicyError (new format).\n *\n * @alpha\n */\n// biome-ignore lint/suspicious/noExplicitAny: type guard\nexport function isPolicyError(toCheck: any): toCheck is PolicyError {\n\tif (typeof toCheck !== \"object\" || toCheck === null) {\n\t\treturn false;\n\t}\n\treturn \"error\" in toCheck && typeof toCheck.error === \"string\";\n}\n\n/**\n * Type guard to check if a result is a {@link PolicyFailure} (legacy format).\n *\n * @deprecated Use {@link isPolicyError} instead when working with the new {@link PolicyError} format.\n *\n * @alpha\n */\n// biome-ignore lint/suspicious/noExplicitAny: type guard\nexport function isPolicyFailure(toCheck: any): toCheck is PolicyFailure {\n\tif (typeof toCheck !== \"object\" || toCheck === null) {\n\t\treturn false;\n\t}\n\treturn \"errorMessages\" in toCheck && Array.isArray(toCheck.errorMessages);\n}\n\n// ============================================================================\n// Conversion Functions\n// ============================================================================\n\n/**\n * Converts a legacy PolicyFailure/PolicyFixResult to the new PolicyError format.\n * @internal\n */\nexport function convertLegacyResult(\n\tresult: PolicyHandlerResult,\n\t_file: string,\n): PolicyResult {\n\tif (result === true) {\n\t\treturn true;\n\t}\n\n\t// Check if it's already the new format\n\tif (isPolicyError(result)) {\n\t\treturn result;\n\t}\n\n\t// It's a legacy PolicyFailure or PolicyFixResult\n\tconst error = result.errorMessages?.join(\"; \") ?? \"Policy violation\";\n\tconst isFixResult = isPolicyFixResult(result);\n\n\treturn {\n\t\terror,\n\t\tfixable: result.autoFixable ?? false,\n\t\tfixed: isFixResult ? result.resolved : undefined,\n\t\tmanualFix: result.manualFix,\n\t};\n}\n\n/**\n * Converts a new PolicyError to the legacy PolicyFailure format.\n * @internal\n */\nexport function convertToLegacyResult(\n\tresult: PolicyError,\n\tpolicyName: string,\n\tfile: string,\n): PolicyFailure | PolicyFixResult {\n\tconst base: PolicyFailure = {\n\t\tname: policyName,\n\t\tfile,\n\t\tautoFixable: result.fixable,\n\t\terrorMessages: [result.error],\n\t\tmanualFix: result.manualFix,\n\t};\n\n\tif (result.fixed !== undefined) {\n\t\treturn {\n\t\t\t...base,\n\t\t\tresolved: result.fixed,\n\t\t} satisfies PolicyFixResult;\n\t}\n\n\treturn base;\n}\n\n// ============================================================================\n// Default Policies\n// ============================================================================\n\n/**\n * Default policies included with repopo.\n *\n * @alpha\n */\n// biome-ignore lint/suspicious/noExplicitAny: FIXME\nexport const DefaultPolicies: Policy<any>[] = [\n\tNoJsFileExtensions,\n\tPackageJsonRepoDirectoryProperty,\n\tPackageJsonSorted,\n] as const;\n"]}
|
|
1
|
+
{"version":3,"file":"policy.js","sourceRoot":"","sources":["../src/policy.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,kBAAkB,EAAE,MAAM,kCAAkC,CAAC;AACtE,OAAO,EAAE,gCAAgC,EAAE,MAAM,gDAAgD,CAAC;AAClG,OAAO,EAAE,iBAAiB,EAAE,MAAM,iCAAiC,CAAC;AAqGpE,iFAAiF;AACjF,MAAM,CAAC,MAAM,eAAe,GAAG;IAC9B,kBAAkB;IAClB,gCAAgC;IAChC,iBAAiB;CACR,CAAC","sourcesContent":["import type { Operation } from \"effection\";\nimport { NoJsFileExtensions } from \"./policies/NoJsFileExtensions.js\";\nimport { PackageJsonRepoDirectoryProperty } from \"./policies/PackageJsonRepoDirectoryProperty.js\";\nimport { PackageJsonSorted } from \"./policies/PackageJsonSorted.js\";\n\n/** Display name of a policy. @public */\nexport type PolicyName = string;\n/** Stable configured-instance identity. @public */\nexport type PolicyInstanceId = string;\n\n/** Arguments supplied to a file handler. @public */\nexport interface PolicyArgs<C = void> {\n\tfile: string;\n\troot: string;\n\tresolve: boolean;\n\tconfig?: C | undefined;\n}\n\n/** Arguments supplied to a repository handler; selection never limits files. @public */\nexport interface RepositoryPolicyArgs<C = void>\n\textends Omit<PolicyArgs<C>, \"file\"> {\n\tfiles: readonly string[];\n}\n\n/** A single independently actionable violation or recorded fix. @public */\nexport interface PolicyFinding {\n\tmessage: string;\n\tmanualFix?: string | undefined;\n\tfixStatus?: \"available\" | \"fixed\" | \"failed\" | undefined;\n\t/** Repo-relative affected files. Only repository handlers may supply this. */\n\tfiles?: readonly string[] | undefined;\n}\n\n/** Empty means pass. Fixed findings remain visible. @public */\nexport type PolicyResult = readonly PolicyFinding[];\n\n/** Standalone file fixers receive and return the complete findings list. @public */\nexport type PolicyResolver<C = void> = {\n\tresolve(\n\t\targs: Omit<PolicyArgs<C>, \"resolve\"> & { findings: PolicyResult },\n\t): Promise<PolicyResult> | Operation<PolicyResult>;\n}[\"resolve\"];\n\n/** File scope is the default. @public */\nexport interface FilePolicyDefinition<C = void> {\n\tname: PolicyName;\n\tdescription: string;\n\tscope?: \"file\";\n\tmatch: RegExp;\n\thandler(args: PolicyArgs<C>): Promise<PolicyResult> | Operation<PolicyResult>;\n\tresolver?: PolicyResolver<C> | undefined;\n\tdefaultConfig?: C | undefined;\n\trequiresConfig?: boolean | undefined;\n}\n\n/** Repository scope is explicit; repository fixers are inline only. @public */\nexport interface RepositoryPolicyDefinition<C = void> {\n\tname: PolicyName;\n\tdescription: string;\n\tscope: \"repository\";\n\thandler(\n\t\targs: RepositoryPolicyArgs<C>,\n\t): Promise<PolicyResult> | Operation<PolicyResult>;\n\tresolver?: never;\n\tdefaultConfig?: C | undefined;\n\trequiresConfig?: boolean | undefined;\n}\n\n/** A canonical policy definition. @public */\nexport type PolicyDefinition<C = void> =\n\t| FilePolicyDefinition<C>\n\t| RepositoryPolicyDefinition<C>;\n\n/** Async and Effection file handlers are supported. @public */\nexport type PolicyHandler<C = void> = FilePolicyDefinition<C>[\"handler\"];\n/** Async and Effection repository handlers are supported. @public */\nexport type RepositoryPolicyHandler<C = void> =\n\tRepositoryPolicyDefinition<C>[\"handler\"];\n\n/** Exclude undefined (including void) while preserving allowed null values. @internal */\nexport type DefinedConfig<C> = NonNullable<C> | (C & null);\n\n/** Instance configuration and repo-relative regex exclusions. @public */\nexport interface PolicyOptions<C = void> {\n\tconfig?: C | undefined;\n\texclude?: readonly (string | RegExp)[] | undefined;\n\tinstanceId?: PolicyInstanceId | undefined;\n}\n\n/** A configured file policy. @public */\nexport type ConfiguredFilePolicy<C = void> = FilePolicyDefinition<C> &\n\tPolicyOptions<C>;\n/** A configured repository policy. @public */\nexport type ConfiguredRepositoryPolicy<C = void> =\n\tRepositoryPolicyDefinition<C> & PolicyOptions<C>;\n/** A configured policy, retaining scope discrimination. @public */\nexport type ConfiguredPolicy<C = unknown> =\n\t| ConfiguredFilePolicy<C>\n\t| ConfiguredRepositoryPolicy<C>;\n/** A configured policy with a validated stable identity. @public */\nexport type IdentifiedPolicy<C = unknown> = ConfiguredPolicy<C> & {\n\tinstanceId: PolicyInstanceId;\n};\n\n/** The default definitions, configured when no policies are supplied. @public */\nexport const DefaultPolicies = [\n\tNoJsFileExtensions,\n\tPackageJsonRepoDirectoryProperty,\n\tPackageJsonSorted,\n] as const;\n"]}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { type Operation } from "effection";
|
|
2
|
+
import type { DefinedConfig, FilePolicyDefinition, PolicyArgs, PolicyResult } from "../policy.js";
|
|
3
|
+
/**
|
|
4
|
+
* A parsed Cargo.toml represented as a record of sections and values.
|
|
5
|
+
*
|
|
6
|
+
* @public
|
|
7
|
+
*/
|
|
8
|
+
export type CargoToml = Record<string, unknown>;
|
|
9
|
+
/**
|
|
10
|
+
* A policy handler for Cargo.toml policies.
|
|
11
|
+
*
|
|
12
|
+
* @remarks
|
|
13
|
+
* Receives the parsed TOML content and the standard policy arguments.
|
|
14
|
+
*
|
|
15
|
+
* @public
|
|
16
|
+
*/
|
|
17
|
+
export type CargoTomlHandler<C> = (toml: CargoToml, args: PolicyArgs<C>) => Operation<PolicyResult> | Promise<PolicyResult>;
|
|
18
|
+
/**
|
|
19
|
+
* Input arguments for defining a Cargo.toml policy.
|
|
20
|
+
*
|
|
21
|
+
* @public
|
|
22
|
+
*/
|
|
23
|
+
export interface DefineCargoPolicyArgs<C> {
|
|
24
|
+
/**
|
|
25
|
+
* The name of the policy.
|
|
26
|
+
*/
|
|
27
|
+
name: string;
|
|
28
|
+
/**
|
|
29
|
+
* A description of the policy's purpose.
|
|
30
|
+
*/
|
|
31
|
+
description: string;
|
|
32
|
+
/**
|
|
33
|
+
* The handler function that receives the parsed Cargo.toml and policy arguments.
|
|
34
|
+
*/
|
|
35
|
+
handler: CargoTomlHandler<C>;
|
|
36
|
+
/**
|
|
37
|
+
* Optional default configuration for the policy.
|
|
38
|
+
*/
|
|
39
|
+
defaultConfig?: C;
|
|
40
|
+
requiresConfig?: boolean;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Define a repo policy for Cargo.toml files.
|
|
44
|
+
*
|
|
45
|
+
* @remarks
|
|
46
|
+
* This is a helper function that creates a policy pre-configured to match
|
|
47
|
+
* Cargo.toml files. The handler receives the parsed TOML content.
|
|
48
|
+
*
|
|
49
|
+
* @param args - Policy metadata, parsed-TOML handler, and optional defaults.
|
|
50
|
+
* @returns A file policy that reads and parses matching Cargo.toml files.
|
|
51
|
+
*
|
|
52
|
+
* @example
|
|
53
|
+
* ```typescript
|
|
54
|
+
* const MyCargoPolicy = defineCargoPolicy({
|
|
55
|
+
* name: "MyCargoPolicy",
|
|
56
|
+
* description: "Ensures Cargo.toml has required fields",
|
|
57
|
+
* handler: async (toml, { file }) => {
|
|
58
|
+
* const pkg = toml.package as Record<string, unknown> | undefined;
|
|
59
|
+
* if (!pkg?.name) {
|
|
60
|
+
* return [{ message: "Missing package name" }];
|
|
61
|
+
* }
|
|
62
|
+
* return [];
|
|
63
|
+
* },
|
|
64
|
+
* });
|
|
65
|
+
* ```
|
|
66
|
+
*
|
|
67
|
+
* @public
|
|
68
|
+
*/
|
|
69
|
+
export declare function defineCargoPolicy<C = void>(args: DefineCargoPolicyArgs<C> & {
|
|
70
|
+
defaultConfig: DefinedConfig<C>;
|
|
71
|
+
}): FilePolicyDefinition<C> & {
|
|
72
|
+
defaultConfig: DefinedConfig<C>;
|
|
73
|
+
};
|
|
74
|
+
/** Define a Cargo policy that requires explicit configuration. @public */
|
|
75
|
+
export declare function defineCargoPolicy<C = void>(args: DefineCargoPolicyArgs<C> & {
|
|
76
|
+
requiresConfig: true;
|
|
77
|
+
}): FilePolicyDefinition<C> & {
|
|
78
|
+
requiresConfig: true;
|
|
79
|
+
};
|
|
80
|
+
/** Define a Cargo policy with optional configuration. @public */
|
|
81
|
+
export declare function defineCargoPolicy<C = void>(args: DefineCargoPolicyArgs<C>): FilePolicyDefinition<C>;
|
|
82
|
+
//# sourceMappingURL=defineCargoPolicy.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"defineCargoPolicy.d.ts","sourceRoot":"","sources":["../../src/policyDefiners/defineCargoPolicy.ts"],"names":[],"mappings":"AACA,OAAO,EAAQ,KAAK,SAAS,EAAE,MAAM,WAAW,CAAC;AAKjD,OAAO,KAAK,EACX,aAAa,EACb,oBAAoB,EACpB,UAAU,EACV,YAAY,EACZ,MAAM,cAAc,CAAC;AAItB;;;;GAIG;AACH,MAAM,MAAM,SAAS,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AAEhD;;;;;;;GAOG;AACH,MAAM,MAAM,gBAAgB,CAAC,CAAC,IAAI,CACjC,IAAI,EAAE,SAAS,EACf,IAAI,EAAE,UAAU,CAAC,CAAC,CAAC,KACf,SAAS,CAAC,YAAY,CAAC,GAAG,OAAO,CAAC,YAAY,CAAC,CAAC;AAcrD;;;;GAIG;AACH,MAAM,WAAW,qBAAqB,CAAC,CAAC;IACvC;;OAEG;IACH,IAAI,EAAE,MAAM,CAAC;IAEb;;OAEG;IACH,WAAW,EAAE,MAAM,CAAC;IAEpB;;OAEG;IACH,OAAO,EAAE,gBAAgB,CAAC,CAAC,CAAC,CAAC;IAE7B;;OAEG;IACH,aAAa,CAAC,EAAE,CAAC,CAAC;IAClB,cAAc,CAAC,EAAE,OAAO,CAAC;CACzB;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,wBAAgB,iBAAiB,CAAC,CAAC,GAAG,IAAI,EACzC,IAAI,EAAE,qBAAqB,CAAC,CAAC,CAAC,GAAG;IAAE,aAAa,EAAE,aAAa,CAAC,CAAC,CAAC,CAAA;CAAE,GAClE,oBAAoB,CAAC,CAAC,CAAC,GAAG;IAAE,aAAa,EAAE,aAAa,CAAC,CAAC,CAAC,CAAA;CAAE,CAAC;AACjE,0EAA0E;AAC1E,wBAAgB,iBAAiB,CAAC,CAAC,GAAG,IAAI,EACzC,IAAI,EAAE,qBAAqB,CAAC,CAAC,CAAC,GAAG;IAAE,cAAc,EAAE,IAAI,CAAA;CAAE,GACvD,oBAAoB,CAAC,CAAC,CAAC,GAAG;IAAE,cAAc,EAAE,IAAI,CAAA;CAAE,CAAC;AACtD,iEAAiE;AACjE,wBAAgB,iBAAiB,CAAC,CAAC,GAAG,IAAI,EACzC,IAAI,EAAE,qBAAqB,CAAC,CAAC,CAAC,GAC5B,oBAAoB,CAAC,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { readFile } from "node:fs/promises";
|
|
2
|
+
import { call } from "effection";
|
|
3
|
+
import { resolve } from "pathe";
|
|
4
|
+
import { ExecutionContractError } from "../executionContractError.js";
|
|
5
|
+
import { readParsedFile } from "../fileCache.js";
|
|
6
|
+
import { CargoTomlRegexMatch } from "../policies/constants.js";
|
|
7
|
+
import { settlePolicyPromise } from "../settlePolicyPromise.js";
|
|
8
|
+
import { parseToml } from "./tomlParser.js";
|
|
9
|
+
/**
|
|
10
|
+
* Type guard to check if a value is an Effection Operation (generator).
|
|
11
|
+
*/
|
|
12
|
+
function isOperation(value) {
|
|
13
|
+
return (typeof value === "object" &&
|
|
14
|
+
value !== null &&
|
|
15
|
+
"next" in value &&
|
|
16
|
+
typeof value.next === "function");
|
|
17
|
+
}
|
|
18
|
+
export function defineCargoPolicy(args) {
|
|
19
|
+
const { name, description, handler: cargoHandler, defaultConfig } = args;
|
|
20
|
+
return {
|
|
21
|
+
name,
|
|
22
|
+
description,
|
|
23
|
+
match: CargoTomlRegexMatch,
|
|
24
|
+
defaultConfig,
|
|
25
|
+
requiresConfig: args.requiresConfig,
|
|
26
|
+
handler: function* (innerArgs) {
|
|
27
|
+
const toml = yield* call(() => readParsedFile(innerArgs, "toml", async () => {
|
|
28
|
+
const content = await readFile(resolve(innerArgs.root, innerArgs.file), "utf-8");
|
|
29
|
+
return parseToml(content);
|
|
30
|
+
}));
|
|
31
|
+
const result = cargoHandler(toml, innerArgs);
|
|
32
|
+
if (result instanceof Promise) {
|
|
33
|
+
return yield* settlePolicyPromise(result);
|
|
34
|
+
}
|
|
35
|
+
if (isOperation(result)) {
|
|
36
|
+
return yield* result;
|
|
37
|
+
}
|
|
38
|
+
throw new ExecutionContractError(`Unexpected handler result type: ${typeof result}`);
|
|
39
|
+
},
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
//# sourceMappingURL=defineCargoPolicy.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"defineCargoPolicy.js","sourceRoot":"","sources":["../../src/policyDefiners/defineCargoPolicy.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,EAAE,IAAI,EAAkB,MAAM,WAAW,CAAC;AACjD,OAAO,EAAE,OAAO,EAAE,MAAM,OAAO,CAAC;AAChC,OAAO,EAAE,sBAAsB,EAAE,MAAM,8BAA8B,CAAC;AACtE,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AACjD,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAO/D,OAAO,EAAE,mBAAmB,EAAE,MAAM,2BAA2B,CAAC;AAChE,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAsB5C;;GAEG;AACH,SAAS,WAAW,CAAI,KAAc;IACrC,OAAO,CACN,OAAO,KAAK,KAAK,QAAQ;QACzB,KAAK,KAAK,IAAI;QACd,MAAM,IAAI,KAAK;QACf,OAAQ,KAA2B,CAAC,IAAI,KAAK,UAAU,CACvD,CAAC;AACH,CAAC;AAoED,MAAM,UAAU,iBAAiB,CAChC,IAA8B;IAE9B,MAAM,EAAE,IAAI,EAAE,WAAW,EAAE,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,GAAG,IAAI,CAAC;IACzE,OAAO;QACN,IAAI;QACJ,WAAW;QACX,KAAK,EAAE,mBAAmB;QAC1B,aAAa;QACb,cAAc,EAAE,IAAI,CAAC,cAAc;QACnC,OAAO,EAAE,QAAQ,CAAC,EAAE,SAAS;YAC5B,MAAM,IAAI,GAAc,KAAK,CAAC,CAAC,IAAI,CAAC,GAAG,EAAE,CACxC,cAAc,CAAC,SAAS,EAAE,MAAM,EAAE,KAAK,IAAI,EAAE;gBAC5C,MAAM,OAAO,GAAG,MAAM,QAAQ,CAC7B,OAAO,CAAC,SAAS,CAAC,IAAI,EAAE,SAAS,CAAC,IAAI,CAAC,EACvC,OAAO,CACP,CAAC;gBACF,OAAO,SAAS,CAAC,OAAO,CAAC,CAAC;YAC3B,CAAC,CAAC,CACF,CAAC;YACF,MAAM,MAAM,GAAG,YAAY,CAAC,IAAI,EAAE,SAAS,CAAC,CAAC;YAE7C,IAAI,MAAM,YAAY,OAAO,EAAE,CAAC;gBAC/B,OAAO,KAAK,CAAC,CAAC,mBAAmB,CAAC,MAAM,CAAC,CAAC;YAC3C,CAAC;YACD,IAAI,WAAW,CAAe,MAAM,CAAC,EAAE,CAAC;gBACvC,OAAO,KAAK,CAAC,CAAC,MAAM,CAAC;YACtB,CAAC;YACD,MAAM,IAAI,sBAAsB,CAC/B,mCAAmC,OAAO,MAAM,EAAE,CAClD,CAAC;QACH,CAAC;KACD,CAAC;AACH,CAAC","sourcesContent":["import { readFile } from \"node:fs/promises\";\nimport { call, type Operation } from \"effection\";\nimport { resolve } from \"pathe\";\nimport { ExecutionContractError } from \"../executionContractError.js\";\nimport { readParsedFile } from \"../fileCache.js\";\nimport { CargoTomlRegexMatch } from \"../policies/constants.js\";\nimport type {\n\tDefinedConfig,\n\tFilePolicyDefinition,\n\tPolicyArgs,\n\tPolicyResult,\n} from \"../policy.js\";\nimport { settlePolicyPromise } from \"../settlePolicyPromise.js\";\nimport { parseToml } from \"./tomlParser.js\";\n\n/**\n * A parsed Cargo.toml represented as a record of sections and values.\n *\n * @public\n */\nexport type CargoToml = Record<string, unknown>;\n\n/**\n * A policy handler for Cargo.toml policies.\n *\n * @remarks\n * Receives the parsed TOML content and the standard policy arguments.\n *\n * @public\n */\nexport type CargoTomlHandler<C> = (\n\ttoml: CargoToml,\n\targs: PolicyArgs<C>,\n) => Operation<PolicyResult> | Promise<PolicyResult>;\n\n/**\n * Type guard to check if a value is an Effection Operation (generator).\n */\nfunction isOperation<T>(value: unknown): value is Operation<T> {\n\treturn (\n\t\ttypeof value === \"object\" &&\n\t\tvalue !== null &&\n\t\t\"next\" in value &&\n\t\ttypeof (value as { next: unknown }).next === \"function\"\n\t);\n}\n\n/**\n * Input arguments for defining a Cargo.toml policy.\n *\n * @public\n */\nexport interface DefineCargoPolicyArgs<C> {\n\t/**\n\t * The name of the policy.\n\t */\n\tname: string;\n\n\t/**\n\t * A description of the policy's purpose.\n\t */\n\tdescription: string;\n\n\t/**\n\t * The handler function that receives the parsed Cargo.toml and policy arguments.\n\t */\n\thandler: CargoTomlHandler<C>;\n\n\t/**\n\t * Optional default configuration for the policy.\n\t */\n\tdefaultConfig?: C;\n\trequiresConfig?: boolean;\n}\n\n/**\n * Define a repo policy for Cargo.toml files.\n *\n * @remarks\n * This is a helper function that creates a policy pre-configured to match\n * Cargo.toml files. The handler receives the parsed TOML content.\n *\n * @param args - Policy metadata, parsed-TOML handler, and optional defaults.\n * @returns A file policy that reads and parses matching Cargo.toml files.\n *\n * @example\n * ```typescript\n * const MyCargoPolicy = defineCargoPolicy({\n * name: \"MyCargoPolicy\",\n * description: \"Ensures Cargo.toml has required fields\",\n * handler: async (toml, { file }) => {\n * const pkg = toml.package as Record<string, unknown> | undefined;\n * if (!pkg?.name) {\n * return [{ message: \"Missing package name\" }];\n * }\n * return [];\n * },\n * });\n * ```\n *\n * @public\n */\nexport function defineCargoPolicy<C = void>(\n\targs: DefineCargoPolicyArgs<C> & { defaultConfig: DefinedConfig<C> },\n): FilePolicyDefinition<C> & { defaultConfig: DefinedConfig<C> };\n/** Define a Cargo policy that requires explicit configuration. @public */\nexport function defineCargoPolicy<C = void>(\n\targs: DefineCargoPolicyArgs<C> & { requiresConfig: true },\n): FilePolicyDefinition<C> & { requiresConfig: true };\n/** Define a Cargo policy with optional configuration. @public */\nexport function defineCargoPolicy<C = void>(\n\targs: DefineCargoPolicyArgs<C>,\n): FilePolicyDefinition<C>;\nexport function defineCargoPolicy<C = void>(\n\targs: DefineCargoPolicyArgs<C>,\n): FilePolicyDefinition<C> {\n\tconst { name, description, handler: cargoHandler, defaultConfig } = args;\n\treturn {\n\t\tname,\n\t\tdescription,\n\t\tmatch: CargoTomlRegexMatch,\n\t\tdefaultConfig,\n\t\trequiresConfig: args.requiresConfig,\n\t\thandler: function* (innerArgs) {\n\t\t\tconst toml: CargoToml = yield* call(() =>\n\t\t\t\treadParsedFile(innerArgs, \"toml\", async () => {\n\t\t\t\t\tconst content = await readFile(\n\t\t\t\t\t\tresolve(innerArgs.root, innerArgs.file),\n\t\t\t\t\t\t\"utf-8\",\n\t\t\t\t\t);\n\t\t\t\t\treturn parseToml(content);\n\t\t\t\t}),\n\t\t\t);\n\t\t\tconst result = cargoHandler(toml, innerArgs);\n\n\t\t\tif (result instanceof Promise) {\n\t\t\t\treturn yield* settlePolicyPromise(result);\n\t\t\t}\n\t\t\tif (isOperation<PolicyResult>(result)) {\n\t\t\t\treturn yield* result;\n\t\t\t}\n\t\t\tthrow new ExecutionContractError(\n\t\t\t\t`Unexpected handler result type: ${typeof result}`,\n\t\t\t);\n\t\t},\n\t};\n}\n"]}
|
|
@@ -1,6 +1,8 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { FilePolicyDefinition } from "../policy.js";
|
|
2
2
|
/**
|
|
3
|
-
*
|
|
3
|
+
* Header text required by a file-header policy.
|
|
4
|
+
*
|
|
5
|
+
* @public
|
|
4
6
|
*/
|
|
5
7
|
export interface FileHeaderPolicyConfig {
|
|
6
8
|
/**
|
|
@@ -19,13 +21,13 @@ export interface FileHeaderPolicyConfig {
|
|
|
19
21
|
* This interface extends FileHeaderPolicyConfig and adds formatting-specific
|
|
20
22
|
* properties to control how headers are inserted into different file types.
|
|
21
23
|
*
|
|
22
|
-
* @
|
|
24
|
+
* @public
|
|
23
25
|
*/
|
|
24
26
|
export interface FileHeaderGeneratorConfig extends Partial<FileHeaderPolicyConfig> {
|
|
25
27
|
/** Regular expression that matches files this header generator applies to */
|
|
26
28
|
match: RegExp;
|
|
27
29
|
/**
|
|
28
|
-
* Regex matching header prefix
|
|
30
|
+
* Regex matching the header prefix, such as a block-comment opener.
|
|
29
31
|
*/
|
|
30
32
|
headerStart?: RegExp;
|
|
31
33
|
/**
|
|
@@ -52,7 +54,7 @@ export interface FileHeaderGeneratorConfig extends Partial<FileHeaderPolicyConfi
|
|
|
52
54
|
/**
|
|
53
55
|
* Input arguments for defining a file header policy.
|
|
54
56
|
*
|
|
55
|
-
* @
|
|
57
|
+
* @public
|
|
56
58
|
*/
|
|
57
59
|
export interface DefineFileHeaderPolicyArgs {
|
|
58
60
|
/**
|
|
@@ -67,10 +69,17 @@ export interface DefineFileHeaderPolicyArgs {
|
|
|
67
69
|
* Configuration for how headers are detected and inserted.
|
|
68
70
|
*/
|
|
69
71
|
config: FileHeaderGeneratorConfig;
|
|
72
|
+
/** Complete default instance configuration, if the policy is usable without an override. */
|
|
73
|
+
defaultConfig?: FileHeaderPolicyConfig;
|
|
70
74
|
}
|
|
71
75
|
/**
|
|
72
|
-
*
|
|
73
|
-
*
|
|
76
|
+
* Creates a file-header policy that detects missing or incorrect headers and can replace them.
|
|
77
|
+
*
|
|
78
|
+
* Supply {@link FileHeaderPolicyConfig} when configuring the policy, unless
|
|
79
|
+
* the definition supplies a complete default.
|
|
80
|
+
*
|
|
81
|
+
* @param args - Policy metadata and header matching and replacement rules.
|
|
82
|
+
* @returns A file policy configured for the supplied file types.
|
|
74
83
|
*
|
|
75
84
|
* @example
|
|
76
85
|
* ```typescript
|
|
@@ -81,12 +90,16 @@ export interface DefineFileHeaderPolicyArgs {
|
|
|
81
90
|
* });
|
|
82
91
|
* ```
|
|
83
92
|
*
|
|
84
|
-
* @
|
|
85
|
-
*/
|
|
86
|
-
export declare function defineFileHeaderPolicy(args: DefineFileHeaderPolicyArgs): PolicyShape<FileHeaderPolicyConfig>;
|
|
87
|
-
/**
|
|
88
|
-
* Alias for defineFileHeaderPolicy.
|
|
89
|
-
* @alpha
|
|
93
|
+
* @public
|
|
90
94
|
*/
|
|
91
|
-
export declare
|
|
95
|
+
export declare function defineFileHeaderPolicy(args: DefineFileHeaderPolicyArgs & {
|
|
96
|
+
defaultConfig: FileHeaderPolicyConfig;
|
|
97
|
+
}): FilePolicyDefinition<FileHeaderPolicyConfig> & {
|
|
98
|
+
requiresConfig: true;
|
|
99
|
+
defaultConfig: FileHeaderPolicyConfig;
|
|
100
|
+
};
|
|
101
|
+
/** Define a header policy that requires explicit header configuration. @public */
|
|
102
|
+
export declare function defineFileHeaderPolicy(args: DefineFileHeaderPolicyArgs): FilePolicyDefinition<FileHeaderPolicyConfig> & {
|
|
103
|
+
requiresConfig: true;
|
|
104
|
+
};
|
|
92
105
|
//# sourceMappingURL=defineFileHeaderPolicy.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"defineFileHeaderPolicy.d.ts","sourceRoot":"","sources":["../../src/policyDefiners/defineFileHeaderPolicy.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"defineFileHeaderPolicy.d.ts","sourceRoot":"","sources":["../../src/policyDefiners/defineFileHeaderPolicy.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,oBAAoB,EAAiB,MAAM,cAAc,CAAC;AAKxE;;;;GAIG;AACH,MAAM,WAAW,sBAAsB;IACtC;;OAEG;IACH,UAAU,EAAE,MAAM,CAAC;IAEnB;;OAEG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;CACrB;AAED;;;;;;;;GAQG;AACH,MAAM,WAAW,yBAChB,SAAQ,OAAO,CAAC,sBAAsB,CAAC;IACvC,6EAA6E;IAC7E,KAAK,EAAE,MAAM,CAAC;IAEd;;OAEG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;IAErB;;OAEG;IACH,SAAS,EAAE,MAAM,CAAC;IAElB;;OAEG;IACH,OAAO,EAAE,MAAM,CAAC;IAEhB;;OAEG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;IAEnB;;;;;;OAMG;IACH,QAAQ,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,sBAAsB,KAAK,MAAM,CAAC;CACtE;AAED;;;;GAIG;AACH,MAAM,WAAW,0BAA0B;IAC1C;;OAEG;IACH,IAAI,EAAE,MAAM,CAAC;IAEb;;OAEG;IACH,WAAW,EAAE,MAAM,CAAC;IAEpB;;OAEG;IACH,MAAM,EAAE,yBAAyB,CAAC;IAClC,4FAA4F;IAC5F,aAAa,CAAC,EAAE,sBAAsB,CAAC;CACvC;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,sBAAsB,CACrC,IAAI,EAAE,0BAA0B,GAAG;IAAE,aAAa,EAAE,sBAAsB,CAAA;CAAE,GAC1E,oBAAoB,CAAC,sBAAsB,CAAC,GAAG;IACjD,cAAc,EAAE,IAAI,CAAC;IACrB,aAAa,EAAE,sBAAsB,CAAC;CACtC,CAAC;AACF,kFAAkF;AAClF,wBAAgB,sBAAsB,CACrC,IAAI,EAAE,0BAA0B,GAC9B,oBAAoB,CAAC,sBAAsB,CAAC,GAAG;IAAE,cAAc,EAAE,IAAI,CAAA;CAAE,CAAC"}
|
|
@@ -2,22 +2,8 @@ import { readFile, writeFile } from "node:fs/promises";
|
|
|
2
2
|
import { EOL as newline } from "node:os";
|
|
3
3
|
import { call } from "effection";
|
|
4
4
|
import { extname } from "pathe";
|
|
5
|
+
import { resolveRepoFilePath } from "../utils/safePaths.js";
|
|
5
6
|
const trailingSpaces = /\s*\\r\?\\n/;
|
|
6
|
-
/**
|
|
7
|
-
* Given a {@link FileHeaderPolicyConfig}, produces a function that detects correct file headers
|
|
8
|
-
* and returns an error string if the header is missing or incorrect.
|
|
9
|
-
*
|
|
10
|
-
* @example
|
|
11
|
-
* ```typescript
|
|
12
|
-
* const MyHeaderPolicy = defineFileHeaderPolicy({
|
|
13
|
-
* name: "MyHeaderPolicy",
|
|
14
|
-
* description: "Ensures files have required headers",
|
|
15
|
-
* config: { match: /\.ts$/, lineStart: /\/\/ /, lineEnd: /\r?\n/, replacer: ... },
|
|
16
|
-
* });
|
|
17
|
-
* ```
|
|
18
|
-
*
|
|
19
|
-
* @alpha
|
|
20
|
-
*/
|
|
21
7
|
export function defineFileHeaderPolicy(args) {
|
|
22
8
|
const { name, description, config } = args;
|
|
23
9
|
const pre = config.headerStart?.source ?? "";
|
|
@@ -31,49 +17,43 @@ export function defineFileHeaderPolicy(args) {
|
|
|
31
17
|
.map((line) => `${start}${line.replace(/[$()*+.?[\\\]^{|}]/g, "\\$&")}${end}`)
|
|
32
18
|
.join("")
|
|
33
19
|
.replace(trailingSpaces, "\\r?\\n"); // Trim trailing spaces at end-of-line.
|
|
34
|
-
// Detection regex matches the header start (if any), followed by lines in 'headerText',
|
|
35
|
-
// optionally followed by lines in the 'autoGenText', and finally the header end (if any).
|
|
36
|
-
const regex = new RegExp(`^${pre}${toRegex(config.headerText ?? "")}(${toRegex(config.autoGenText ?? "")})?${post}`);
|
|
37
20
|
return {
|
|
38
21
|
name,
|
|
39
22
|
description,
|
|
40
23
|
match: config.match,
|
|
41
|
-
|
|
24
|
+
requiresConfig: true,
|
|
25
|
+
defaultConfig: args.defaultConfig,
|
|
26
|
+
handler: function* ({ file, root, resolve, config: policyConfig }) {
|
|
42
27
|
if (policyConfig === undefined) {
|
|
43
|
-
|
|
28
|
+
throw new TypeError(`${name} requires config.`);
|
|
44
29
|
}
|
|
45
|
-
const
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
autoFixable: true,
|
|
49
|
-
errorMessages: [],
|
|
50
|
-
};
|
|
30
|
+
const regex = new RegExp(`^${pre}${toRegex(policyConfig.headerText)}(${toRegex(policyConfig.autoGenText ?? config.autoGenText ?? "")})?${post}`);
|
|
31
|
+
const filePath = resolveRepoFilePath(root, file);
|
|
32
|
+
const failResult = [];
|
|
51
33
|
// TODO: Consider reading only the first 512B or so since headers are typically
|
|
52
34
|
// at the beginning of the file.
|
|
53
|
-
const content = yield* call(() => readFile(
|
|
35
|
+
const content = yield* call(() => readFile(filePath, { encoding: "utf8" }));
|
|
54
36
|
const failed = !regex.test(content);
|
|
55
37
|
if (failed) {
|
|
56
|
-
failResult.
|
|
38
|
+
failResult.push({
|
|
39
|
+
message: `${extname(file)} file missing header`,
|
|
40
|
+
fixStatus: "available",
|
|
41
|
+
});
|
|
57
42
|
}
|
|
58
43
|
if (failed) {
|
|
59
44
|
if (resolve) {
|
|
60
45
|
const newContent = config.replacer(content, policyConfig);
|
|
61
|
-
yield* call(() => writeFile(
|
|
62
|
-
const fixResult = {
|
|
63
|
-
...
|
|
64
|
-
|
|
65
|
-
};
|
|
46
|
+
yield* call(() => writeFile(filePath, newContent));
|
|
47
|
+
const fixResult = failResult.map((finding) => ({
|
|
48
|
+
...finding,
|
|
49
|
+
fixStatus: "fixed",
|
|
50
|
+
}));
|
|
66
51
|
return fixResult;
|
|
67
52
|
}
|
|
68
53
|
return failResult;
|
|
69
54
|
}
|
|
70
|
-
return
|
|
55
|
+
return [];
|
|
71
56
|
},
|
|
72
57
|
};
|
|
73
58
|
}
|
|
74
|
-
/**
|
|
75
|
-
* Alias for defineFileHeaderPolicy.
|
|
76
|
-
* @alpha
|
|
77
|
-
*/
|
|
78
|
-
export const fileHeaderPolicy = defineFileHeaderPolicy;
|
|
79
59
|
//# sourceMappingURL=defineFileHeaderPolicy.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"defineFileHeaderPolicy.js","sourceRoot":"","sources":["../../src/policyDefiners/defineFileHeaderPolicy.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,S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I,OAAO,EAAE,CAAC;oBACb,MAAM,UAAU,GAAG,MAAM,CAAC,QAAQ,CAAC,OAAO,EAAE,YAAY,CAAC,CAAC;oBAC1D,KAAK,CAAC,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,SAAS,CAAC,QAAQ,EAAE,UAAU,CAAC,CAAC,CAAC;oBACnD,MAAM,SAAS,GAAoB,UAAU,CAAC,GAAG,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC;wBAC/D,GAAG,OAAO;wBACV,SAAS,EAAE,OAAO;qBAClB,CAAC,CAAC,CAAC;oBACJ,OAAO,SAAS,CAAC;gBAClB,CAAC;gBACD,OAAO,UAAU,CAAC;YACnB,CAAC;YACD,OAAO,EAAE,CAAC;QACX,CAAC;KACD,CAAC;AACH,CAAC","sourcesContent":["import { readFile, writeFile } from \"node:fs/promises\";\nimport { EOL as newline } from \"node:os\";\nimport { call } from \"effection\";\nimport { extname } from \"pathe\";\nimport type { FilePolicyDefinition, PolicyFinding } from \"../policy.js\";\nimport { resolveRepoFilePath } from \"../utils/safePaths.js\";\n\nconst trailingSpaces = /\\s*\\\\r\\?\\\\n/;\n\n/**\n * Header text required by a file-header policy.\n *\n * @public\n */\nexport interface FileHeaderPolicyConfig {\n\t/**\n\t * The text to use as the header.\n\t */\n\theaderText: string;\n\n\t/**\n\t * An optional string that will be appended to the headerText.\n\t */\n\tautoGenText?: string;\n}\n\n/**\n * Configuration for generating file headers with specific formatting rules.\n *\n * @remarks\n * This interface extends FileHeaderPolicyConfig and adds formatting-specific\n * properties to control how headers are inserted into different file types.\n *\n * @public\n */\nexport interface FileHeaderGeneratorConfig\n\textends Partial<FileHeaderPolicyConfig> {\n\t/** Regular expression that matches files this header generator applies to */\n\tmatch: RegExp;\n\n\t/**\n\t * Regex matching the header prefix, such as a block-comment opener.\n\t */\n\theaderStart?: RegExp;\n\n\t/**\n\t * Regex matching beginning of each line (e.g. ' * ')\n\t */\n\tlineStart: RegExp;\n\n\t/**\n\t * Regex matching the end of each line (e.g., `\\r?\\n`)\n\t */\n\tlineEnd: RegExp;\n\n\t/**\n\t * Regex matching the header postfix.\n\t */\n\theaderEnd?: RegExp;\n\n\t/**\n\t * Function that generates the properly formatted header content for insertion into files.\n\t *\n\t * @param content - The original file content\n\t * @param config - The file header policy configuration\n\t * @returns The formatted header string to insert\n\t */\n\treplacer: (content: string, config: FileHeaderPolicyConfig) => string;\n}\n\n/**\n * Input arguments for defining a file header policy.\n *\n * @public\n */\nexport interface DefineFileHeaderPolicyArgs {\n\t/**\n\t * The name of the policy.\n\t */\n\tname: string;\n\n\t/**\n\t * A description of the policy's purpose.\n\t */\n\tdescription: string;\n\n\t/**\n\t * Configuration for how headers are detected and inserted.\n\t */\n\tconfig: FileHeaderGeneratorConfig;\n\t/** Complete default instance configuration, if the policy is usable without an override. */\n\tdefaultConfig?: FileHeaderPolicyConfig;\n}\n\n/**\n * Creates a file-header policy that detects missing or incorrect headers and can replace them.\n *\n * Supply {@link FileHeaderPolicyConfig} when configuring the policy, unless\n * the definition supplies a complete default.\n *\n * @param args - Policy metadata and header matching and replacement rules.\n * @returns A file policy configured for the supplied file types.\n *\n * @example\n * ```typescript\n * const MyHeaderPolicy = defineFileHeaderPolicy({\n * name: \"MyHeaderPolicy\",\n * description: \"Ensures files have required headers\",\n * config: { match: /\\.ts$/, lineStart: /\\/\\/ /, lineEnd: /\\r?\\n/, replacer: ... },\n * });\n * ```\n *\n * @public\n */\nexport function defineFileHeaderPolicy(\n\targs: DefineFileHeaderPolicyArgs & { defaultConfig: FileHeaderPolicyConfig },\n): FilePolicyDefinition<FileHeaderPolicyConfig> & {\n\trequiresConfig: true;\n\tdefaultConfig: FileHeaderPolicyConfig;\n};\n/** Define a header policy that requires explicit header configuration. @public */\nexport function defineFileHeaderPolicy(\n\targs: DefineFileHeaderPolicyArgs,\n): FilePolicyDefinition<FileHeaderPolicyConfig> & { requiresConfig: true };\nexport function defineFileHeaderPolicy(\n\targs: DefineFileHeaderPolicyArgs,\n): FilePolicyDefinition<FileHeaderPolicyConfig> & { requiresConfig: true } {\n\tconst { name, description, config } = args;\n\tconst pre = config.headerStart?.source ?? \"\";\n\tconst start = config.lineStart.source;\n\tconst end = config.lineEnd.source;\n\tconst post = config.headerEnd?.source ?? \"\";\n\n\t// Helper which constructs a matching RegExp from a given multiline string.\n\t// (See https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions#escaping)\n\tconst toRegex = (text: string): string =>\n\t\ttext\n\t\t\t.split(newline)\n\t\t\t.map(\n\t\t\t\t(line) =>\n\t\t\t\t\t`${start}${line.replace(/[$()*+.?[\\\\\\]^{|}]/g, \"\\\\$&\")}${end}`,\n\t\t\t)\n\t\t\t.join(\"\")\n\t\t\t.replace(trailingSpaces, \"\\\\r?\\\\n\"); // Trim trailing spaces at end-of-line.\n\n\treturn {\n\t\tname,\n\t\tdescription,\n\t\tmatch: config.match,\n\t\trequiresConfig: true,\n\t\tdefaultConfig: args.defaultConfig,\n\t\thandler: function* ({ file, root, resolve, config: policyConfig }) {\n\t\t\tif (policyConfig === undefined) {\n\t\t\t\tthrow new TypeError(`${name} requires config.`);\n\t\t\t}\n\n\t\t\tconst regex = new RegExp(\n\t\t\t\t`^${pre}${toRegex(policyConfig.headerText)}(${toRegex(policyConfig.autoGenText ?? config.autoGenText ?? \"\")})?${post}`,\n\t\t\t);\n\t\t\tconst filePath = resolveRepoFilePath(root, file);\n\t\t\tconst failResult: PolicyFinding[] = [];\n\t\t\t// TODO: Consider reading only the first 512B or so since headers are typically\n\t\t\t// at the beginning of the file.\n\t\t\tconst content = yield* call(() =>\n\t\t\t\treadFile(filePath, { encoding: \"utf8\" }),\n\t\t\t);\n\t\t\tconst failed = !regex.test(content);\n\n\t\t\tif (failed) {\n\t\t\t\tfailResult.push({\n\t\t\t\t\tmessage: `${extname(file)} file missing header`,\n\t\t\t\t\tfixStatus: \"available\",\n\t\t\t\t});\n\t\t\t}\n\n\t\t\tif (failed) {\n\t\t\t\tif (resolve) {\n\t\t\t\t\tconst newContent = config.replacer(content, policyConfig);\n\t\t\t\t\tyield* call(() => writeFile(filePath, newContent));\n\t\t\t\t\tconst fixResult: PolicyFinding[] = failResult.map((finding) => ({\n\t\t\t\t\t\t...finding,\n\t\t\t\t\t\tfixStatus: \"fixed\",\n\t\t\t\t\t}));\n\t\t\t\t\treturn fixResult;\n\t\t\t\t}\n\t\t\t\treturn failResult;\n\t\t\t}\n\t\t\treturn [];\n\t\t},\n\t};\n}\n"]}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { type Operation } from "effection";
|
|
2
|
+
import type { DefinedConfig, FilePolicyDefinition, PolicyArgs, PolicyResult } from "../policy.js";
|
|
3
|
+
/**
|
|
4
|
+
* A parsed gleam.toml represented as a record of sections and values.
|
|
5
|
+
*
|
|
6
|
+
* @public
|
|
7
|
+
*/
|
|
8
|
+
export type GleamToml = Record<string, unknown>;
|
|
9
|
+
/**
|
|
10
|
+
* A policy handler for gleam.toml policies.
|
|
11
|
+
*
|
|
12
|
+
* @remarks
|
|
13
|
+
* Receives the parsed TOML content and the standard policy arguments.
|
|
14
|
+
*
|
|
15
|
+
* @public
|
|
16
|
+
*/
|
|
17
|
+
export type GleamTomlHandler<C> = (toml: GleamToml, args: PolicyArgs<C>) => Operation<PolicyResult> | Promise<PolicyResult>;
|
|
18
|
+
/**
|
|
19
|
+
* Input arguments for defining a gleam.toml policy.
|
|
20
|
+
*
|
|
21
|
+
* @public
|
|
22
|
+
*/
|
|
23
|
+
export interface DefineGleamPolicyArgs<C> {
|
|
24
|
+
/**
|
|
25
|
+
* The name of the policy.
|
|
26
|
+
*/
|
|
27
|
+
name: string;
|
|
28
|
+
/**
|
|
29
|
+
* A description of the policy's purpose.
|
|
30
|
+
*/
|
|
31
|
+
description: string;
|
|
32
|
+
/**
|
|
33
|
+
* The handler function that receives the parsed gleam.toml and policy arguments.
|
|
34
|
+
*/
|
|
35
|
+
handler: GleamTomlHandler<C>;
|
|
36
|
+
/**
|
|
37
|
+
* Optional default configuration for the policy.
|
|
38
|
+
*/
|
|
39
|
+
defaultConfig?: C;
|
|
40
|
+
requiresConfig?: boolean;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Define a repo policy for gleam.toml files.
|
|
44
|
+
*
|
|
45
|
+
* @remarks
|
|
46
|
+
* This is a helper function that creates a policy pre-configured to match
|
|
47
|
+
* gleam.toml files. The handler receives the parsed TOML content.
|
|
48
|
+
*
|
|
49
|
+
* @param args - Policy metadata, parsed-TOML handler, and optional defaults.
|
|
50
|
+
* @returns A file policy that reads and parses matching gleam.toml files.
|
|
51
|
+
*
|
|
52
|
+
* @example
|
|
53
|
+
* ```typescript
|
|
54
|
+
* const MyGleamPolicy = defineGleamPolicy({
|
|
55
|
+
* name: "MyGleamPolicy",
|
|
56
|
+
* description: "Ensures gleam.toml has required fields",
|
|
57
|
+
* handler: async (toml, { file }) => {
|
|
58
|
+
* if (!toml.name) {
|
|
59
|
+
* return [{ message: "Missing name field" }];
|
|
60
|
+
* }
|
|
61
|
+
* return [];
|
|
62
|
+
* },
|
|
63
|
+
* });
|
|
64
|
+
* ```
|
|
65
|
+
*
|
|
66
|
+
* @public
|
|
67
|
+
*/
|
|
68
|
+
export declare function defineGleamPolicy<C = void>(args: DefineGleamPolicyArgs<C> & {
|
|
69
|
+
defaultConfig: DefinedConfig<C>;
|
|
70
|
+
}): FilePolicyDefinition<C> & {
|
|
71
|
+
defaultConfig: DefinedConfig<C>;
|
|
72
|
+
};
|
|
73
|
+
/** Define a Gleam policy that requires explicit configuration. @public */
|
|
74
|
+
export declare function defineGleamPolicy<C = void>(args: DefineGleamPolicyArgs<C> & {
|
|
75
|
+
requiresConfig: true;
|
|
76
|
+
}): FilePolicyDefinition<C> & {
|
|
77
|
+
requiresConfig: true;
|
|
78
|
+
};
|
|
79
|
+
/** Define a Gleam policy with optional configuration. @public */
|
|
80
|
+
export declare function defineGleamPolicy<C = void>(args: DefineGleamPolicyArgs<C>): FilePolicyDefinition<C>;
|
|
81
|
+
//# sourceMappingURL=defineGleamPolicy.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"defineGleamPolicy.d.ts","sourceRoot":"","sources":["../../src/policyDefiners/defineGleamPolicy.ts"],"names":[],"mappings":"AACA,OAAO,EAAQ,KAAK,SAAS,EAAE,MAAM,WAAW,CAAC;AAKjD,OAAO,KAAK,EACX,aAAa,EACb,oBAAoB,EACpB,UAAU,EACV,YAAY,EACZ,MAAM,cAAc,CAAC;AAItB;;;;GAIG;AACH,MAAM,MAAM,SAAS,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AAEhD;;;;;;;GAOG;AACH,MAAM,MAAM,gBAAgB,CAAC,CAAC,IAAI,CACjC,IAAI,EAAE,SAAS,EACf,IAAI,EAAE,UAAU,CAAC,CAAC,CAAC,KACf,SAAS,CAAC,YAAY,CAAC,GAAG,OAAO,CAAC,YAAY,CAAC,CAAC;AAcrD;;;;GAIG;AACH,MAAM,WAAW,qBAAqB,CAAC,CAAC;IACvC;;OAEG;IACH,IAAI,EAAE,MAAM,CAAC;IAEb;;OAEG;IACH,WAAW,EAAE,MAAM,CAAC;IAEpB;;OAEG;IACH,OAAO,EAAE,gBAAgB,CAAC,CAAC,CAAC,CAAC;IAE7B;;OAEG;IACH,aAAa,CAAC,EAAE,CAAC,CAAC;IAClB,cAAc,CAAC,EAAE,OAAO,CAAC;CACzB;AAED;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,wBAAgB,iBAAiB,CAAC,CAAC,GAAG,IAAI,EACzC,IAAI,EAAE,qBAAqB,CAAC,CAAC,CAAC,GAAG;IAAE,aAAa,EAAE,aAAa,CAAC,CAAC,CAAC,CAAA;CAAE,GAClE,oBAAoB,CAAC,CAAC,CAAC,GAAG;IAAE,aAAa,EAAE,aAAa,CAAC,CAAC,CAAC,CAAA;CAAE,CAAC;AACjE,0EAA0E;AAC1E,wBAAgB,iBAAiB,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