repopo 0.12.0 → 0.14.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 +70 -0
- package/README.md +57 -90
- package/THIRD-PARTY-LICENSES.txt +169 -11
- package/bin/dev.js +0 -0
- package/esm/adapters/fluidFramework.d.ts +13 -9
- package/esm/adapters/fluidFramework.d.ts.map +1 -1
- package/esm/adapters/fluidFramework.js +20 -43
- package/esm/adapters/fluidFramework.js.map +1 -1
- package/esm/api.d.ts +66 -1
- package/esm/api.d.ts.map +1 -1
- package/esm/api.js +18 -1
- package/esm/api.js.map +1 -1
- package/esm/baseCommand.d.ts.map +1 -1
- package/esm/baseCommand.js +2 -2
- package/esm/baseCommand.js.map +1 -1
- package/esm/commands/check-native.d.ts +5 -3
- package/esm/commands/check-native.d.ts.map +1 -1
- package/esm/commands/check-native.js +35 -7
- package/esm/commands/check-native.js.map +1 -1
- package/esm/commands/check.d.ts +8 -21
- package/esm/commands/check.d.ts.map +1 -1
- package/esm/commands/check.js +98 -154
- package/esm/commands/check.js.map +1 -1
- package/esm/commands/list.d.ts.map +1 -1
- package/esm/commands/list.js +1 -0
- 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 +10 -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 +10 -1
- package/esm/context.d.ts.map +1 -1
- package/esm/context.js +19 -1
- package/esm/context.js.map +1 -1
- package/esm/executionContractError.d.ts +4 -0
- package/esm/executionContractError.d.ts.map +1 -0
- package/esm/executionContractError.js +4 -0
- package/esm/executionContractError.js.map +1 -0
- package/esm/fileCache.d.ts +12 -0
- package/esm/fileCache.d.ts.map +1 -0
- package/esm/fileCache.js +37 -0
- package/esm/fileCache.js.map +1 -0
- package/esm/filePaths.d.ts +2 -0
- package/esm/filePaths.d.ts.map +1 -0
- package/esm/filePaths.js +9 -0
- package/esm/filePaths.js.map +1 -0
- package/esm/generators.d.ts +0 -20
- package/esm/generators.d.ts.map +1 -1
- package/esm/generators.js.map +1 -1
- package/esm/index.d.ts +3 -16
- package/esm/index.d.ts.map +1 -1
- package/esm/index.js +3 -17
- package/esm/index.js.map +1 -1
- package/esm/makePolicy.d.ts +20 -100
- package/esm/makePolicy.d.ts.map +1 -1
- package/esm/makePolicy.js +46 -132
- package/esm/makePolicy.js.map +1 -1
- package/esm/perf.d.ts +5 -2
- package/esm/perf.d.ts.map +1 -1
- package/esm/perf.js +10 -9
- package/esm/perf.js.map +1 -1
- package/esm/policies/CargoLicenceValidated.d.ts +4 -4
- package/esm/policies/CargoLicenceValidated.d.ts.map +1 -1
- package/esm/policies/CargoLicenceValidated.js +9 -7
- package/esm/policies/CargoLicenceValidated.js.map +1 -1
- package/esm/policies/CargoLintsConfigured.d.ts +4 -4
- package/esm/policies/CargoLintsConfigured.d.ts.map +1 -1
- package/esm/policies/CargoLintsConfigured.js +19 -15
- package/esm/policies/CargoLintsConfigured.js.map +1 -1
- package/esm/policies/CargoLockPolicy.d.ts +4 -4
- package/esm/policies/CargoLockPolicy.d.ts.map +1 -1
- package/esm/policies/CargoLockPolicy.js +15 -11
- package/esm/policies/CargoLockPolicy.js.map +1 -1
- package/esm/policies/CargoTomlRequired.d.ts +5 -5
- package/esm/policies/CargoTomlRequired.d.ts.map +1 -1
- package/esm/policies/CargoTomlRequired.js +7 -7
- package/esm/policies/CargoTomlRequired.js.map +1 -1
- package/esm/policies/CargoTomlSorted.d.ts +4 -4
- package/esm/policies/CargoTomlSorted.d.ts.map +1 -1
- package/esm/policies/CargoTomlSorted.js +21 -17
- package/esm/policies/CargoTomlSorted.js.map +1 -1
- package/esm/policies/ConditionalScripts.d.ts +10 -8
- package/esm/policies/ConditionalScripts.d.ts.map +1 -1
- package/esm/policies/ConditionalScripts.js +24 -22
- package/esm/policies/ConditionalScripts.js.map +1 -1
- package/esm/policies/ExactScripts.d.ts +8 -6
- package/esm/policies/ExactScripts.d.ts.map +1 -1
- package/esm/policies/ExactScripts.js +15 -18
- package/esm/policies/ExactScripts.js.map +1 -1
- package/esm/policies/GleamDepVersions.d.ts +5 -5
- package/esm/policies/GleamDepVersions.d.ts.map +1 -1
- package/esm/policies/GleamDepVersions.js +5 -5
- package/esm/policies/GleamDepVersions.js.map +1 -1
- package/esm/policies/GleamDocExists.d.ts +4 -4
- package/esm/policies/GleamDocExists.d.ts.map +1 -1
- package/esm/policies/GleamDocExists.js +6 -6
- package/esm/policies/GleamDocExists.js.map +1 -1
- package/esm/policies/GleamInternalModulesConfigured.d.ts +4 -4
- package/esm/policies/GleamInternalModulesConfigured.d.ts.map +1 -1
- package/esm/policies/GleamInternalModulesConfigured.js +8 -6
- package/esm/policies/GleamInternalModulesConfigured.js.map +1 -1
- package/esm/policies/GleamLicenceConfigured.d.ts +4 -4
- package/esm/policies/GleamLicenceConfigured.d.ts.map +1 -1
- package/esm/policies/GleamLicenceConfigured.js +8 -6
- package/esm/policies/GleamLicenceConfigured.js.map +1 -1
- package/esm/policies/GleamManifestCommitted.d.ts +10 -3
- package/esm/policies/GleamManifestCommitted.d.ts.map +1 -1
- package/esm/policies/GleamManifestCommitted.js +10 -9
- package/esm/policies/GleamManifestCommitted.js.map +1 -1
- package/esm/policies/GleamMonorepoConsistency.d.ts +13 -5
- package/esm/policies/GleamMonorepoConsistency.d.ts.map +1 -1
- package/esm/policies/GleamMonorepoConsistency.js +10 -10
- package/esm/policies/GleamMonorepoConsistency.js.map +1 -1
- package/esm/policies/GleamNameRestrictions.d.ts +4 -4
- package/esm/policies/GleamNameRestrictions.d.ts.map +1 -1
- package/esm/policies/GleamNameRestrictions.js +6 -6
- package/esm/policies/GleamNameRestrictions.js.map +1 -1
- package/esm/policies/GleamNoPathDepsInPublished.d.ts +4 -4
- package/esm/policies/GleamNoPathDepsInPublished.d.ts.map +1 -1
- package/esm/policies/GleamNoPathDepsInPublished.js +6 -6
- package/esm/policies/GleamNoPathDepsInPublished.js.map +1 -1
- package/esm/policies/GleamPathDepsValid.d.ts +3 -3
- package/esm/policies/GleamPathDepsValid.d.ts.map +1 -1
- package/esm/policies/GleamPathDepsValid.js +5 -5
- package/esm/policies/GleamPathDepsValid.js.map +1 -1
- package/esm/policies/GleamProjectStructure.d.ts +11 -4
- package/esm/policies/GleamProjectStructure.d.ts.map +1 -1
- package/esm/policies/GleamProjectStructure.js +7 -8
- package/esm/policies/GleamProjectStructure.js.map +1 -1
- package/esm/policies/GleamSharedDependencyVersions.d.ts +12 -4
- package/esm/policies/GleamSharedDependencyVersions.d.ts.map +1 -1
- package/esm/policies/GleamSharedDependencyVersions.js +10 -10
- package/esm/policies/GleamSharedDependencyVersions.js.map +1 -1
- package/esm/policies/GleamTomlRequired.d.ts +4 -4
- package/esm/policies/GleamTomlRequired.d.ts.map +1 -1
- package/esm/policies/GleamTomlRequired.js +5 -5
- package/esm/policies/GleamTomlRequired.js.map +1 -1
- package/esm/policies/GleamTomlSorted.d.ts +4 -4
- package/esm/policies/GleamTomlSorted.d.ts.map +1 -1
- package/esm/policies/GleamTomlSorted.js +21 -17
- package/esm/policies/GleamTomlSorted.js.map +1 -1
- package/esm/policies/GleamVersionConstraint.d.ts +4 -4
- package/esm/policies/GleamVersionConstraint.d.ts.map +1 -1
- package/esm/policies/GleamVersionConstraint.js +14 -10
- package/esm/policies/GleamVersionConstraint.js.map +1 -1
- package/esm/policies/HtmlFileHeaders.d.ts +4 -2
- package/esm/policies/HtmlFileHeaders.d.ts.map +1 -1
- package/esm/policies/HtmlFileHeaders.js +1 -1
- package/esm/policies/HtmlFileHeaders.js.map +1 -1
- package/esm/policies/JsTsFileHeaders.d.ts +4 -2
- package/esm/policies/JsTsFileHeaders.d.ts.map +1 -1
- package/esm/policies/JsTsFileHeaders.js +1 -1
- package/esm/policies/JsTsFileHeaders.js.map +1 -1
- package/esm/policies/LicenseFileExists.d.ts +10 -4
- package/esm/policies/LicenseFileExists.d.ts.map +1 -1
- package/esm/policies/LicenseFileExists.js +27 -20
- package/esm/policies/LicenseFileExists.js.map +1 -1
- package/esm/policies/MaxChangedFiles.d.ts +17 -0
- package/esm/policies/MaxChangedFiles.d.ts.map +1 -0
- package/esm/policies/MaxChangedFiles.js +22 -0
- package/esm/policies/MaxChangedFiles.js.map +1 -0
- package/esm/policies/MutuallyExclusiveScripts.d.ts +8 -6
- package/esm/policies/MutuallyExclusiveScripts.d.ts.map +1 -1
- package/esm/policies/MutuallyExclusiveScripts.js +9 -13
- package/esm/policies/MutuallyExclusiveScripts.js.map +1 -1
- package/esm/policies/NoBuildDirectory.d.ts +9 -3
- package/esm/policies/NoBuildDirectory.d.ts.map +1 -1
- package/esm/policies/NoBuildDirectory.js +8 -13
- package/esm/policies/NoBuildDirectory.js.map +1 -1
- package/esm/policies/NoJsFileExtensions.d.ts +9 -3
- package/esm/policies/NoJsFileExtensions.d.ts.map +1 -1
- package/esm/policies/NoJsFileExtensions.js +9 -14
- package/esm/policies/NoJsFileExtensions.js.map +1 -1
- package/esm/policies/NoLargeBinaryFiles.d.ts +9 -4
- package/esm/policies/NoLargeBinaryFiles.d.ts.map +1 -1
- package/esm/policies/NoLargeBinaryFiles.js +10 -16
- package/esm/policies/NoLargeBinaryFiles.js.map +1 -1
- package/esm/policies/NoPrivateWorkspaceDependencies.d.ts +10 -6
- package/esm/policies/NoPrivateWorkspaceDependencies.d.ts.map +1 -1
- package/esm/policies/NoPrivateWorkspaceDependencies.js +12 -14
- package/esm/policies/NoPrivateWorkspaceDependencies.js.map +1 -1
- package/esm/policies/NoTargetArtifacts.d.ts +9 -3
- package/esm/policies/NoTargetArtifacts.d.ts.map +1 -1
- package/esm/policies/NoTargetArtifacts.js +9 -14
- package/esm/policies/NoTargetArtifacts.js.map +1 -1
- package/esm/policies/NoUnsafeWithoutJustification.d.ts +11 -4
- package/esm/policies/NoUnsafeWithoutJustification.d.ts.map +1 -1
- package/esm/policies/NoUnsafeWithoutJustification.js +8 -9
- package/esm/policies/NoUnsafeWithoutJustification.js.map +1 -1
- package/esm/policies/NoWildcardDependencies.d.ts +5 -5
- package/esm/policies/NoWildcardDependencies.d.ts.map +1 -1
- package/esm/policies/NoWildcardDependencies.js +6 -6
- package/esm/policies/NoWildcardDependencies.js.map +1 -1
- package/esm/policies/PackageAllowedScopes.d.ts +9 -5
- package/esm/policies/PackageAllowedScopes.d.ts.map +1 -1
- package/esm/policies/PackageAllowedScopes.js +15 -16
- package/esm/policies/PackageAllowedScopes.js.map +1 -1
- package/esm/policies/PackageEsmType.d.ts +7 -5
- package/esm/policies/PackageEsmType.d.ts.map +1 -1
- package/esm/policies/PackageEsmType.js +31 -31
- package/esm/policies/PackageEsmType.js.map +1 -1
- package/esm/policies/PackageFolderName.d.ts +8 -6
- package/esm/policies/PackageFolderName.d.ts.map +1 -1
- package/esm/policies/PackageFolderName.js +13 -16
- package/esm/policies/PackageFolderName.js.map +1 -1
- package/esm/policies/PackageJsonProperties.d.ts +5 -3
- package/esm/policies/PackageJsonProperties.d.ts.map +1 -1
- package/esm/policies/PackageJsonProperties.js +6 -17
- package/esm/policies/PackageJsonProperties.js.map +1 -1
- package/esm/policies/PackageJsonRepoDirectoryProperty.d.ts +2 -7
- package/esm/policies/PackageJsonRepoDirectoryProperty.d.ts.map +1 -1
- package/esm/policies/PackageJsonRepoDirectoryProperty.js +28 -42
- package/esm/policies/PackageJsonRepoDirectoryProperty.js.map +1 -1
- package/esm/policies/PackageJsonSorted.d.ts +2 -2
- package/esm/policies/PackageJsonSorted.d.ts.map +1 -1
- package/esm/policies/PackageJsonSorted.js +15 -30
- package/esm/policies/PackageJsonSorted.js.map +1 -1
- package/esm/policies/PackageLicense.d.ts +4 -4
- package/esm/policies/PackageLicense.d.ts.map +1 -1
- package/esm/policies/PackageLicense.js +31 -52
- package/esm/policies/PackageLicense.js.map +1 -1
- package/esm/policies/PackagePrivateField.d.ts +12 -8
- package/esm/policies/PackagePrivateField.d.ts.map +1 -1
- package/esm/policies/PackagePrivateField.js +31 -23
- package/esm/policies/PackagePrivateField.js.map +1 -1
- package/esm/policies/PackageReadme.d.ts +6 -5
- package/esm/policies/PackageReadme.d.ts.map +1 -1
- package/esm/policies/PackageReadme.js +22 -59
- package/esm/policies/PackageReadme.js.map +1 -1
- package/esm/policies/PackageScripts.d.ts +26 -22
- package/esm/policies/PackageScripts.d.ts.map +1 -1
- package/esm/policies/PackageScripts.js +39 -36
- package/esm/policies/PackageScripts.js.map +1 -1
- package/esm/policies/PackageTestScripts.d.ts +10 -6
- package/esm/policies/PackageTestScripts.d.ts.map +1 -1
- package/esm/policies/PackageTestScripts.js +14 -16
- package/esm/policies/PackageTestScripts.js.map +1 -1
- package/esm/policies/PublicApiDocumented.d.ts +4 -4
- package/esm/policies/PublicApiDocumented.d.ts.map +1 -1
- package/esm/policies/PublicApiDocumented.js +10 -8
- package/esm/policies/PublicApiDocumented.js.map +1 -1
- package/esm/policies/RequireCompanionChanges.d.ts +16 -0
- package/esm/policies/RequireCompanionChanges.d.ts.map +1 -0
- package/esm/policies/RequireCompanionChanges.js +42 -0
- package/esm/policies/RequireCompanionChanges.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 +24 -24
- package/esm/policies/RequiredScripts.js.map +1 -1
- package/esm/policies/RustDocExists.d.ts +4 -4
- package/esm/policies/RustDocExists.d.ts.map +1 -1
- package/esm/policies/RustDocExists.js +6 -6
- package/esm/policies/RustDocExists.js.map +1 -1
- package/esm/policies/RustToolchainExists.d.ts +11 -4
- package/esm/policies/RustToolchainExists.d.ts.map +1 -1
- package/esm/policies/RustToolchainExists.js +10 -9
- package/esm/policies/RustToolchainExists.js.map +1 -1
- package/esm/policies/RustfmtConfigExists.d.ts +11 -4
- package/esm/policies/RustfmtConfigExists.d.ts.map +1 -1
- package/esm/policies/RustfmtConfigExists.js +10 -9
- package/esm/policies/RustfmtConfigExists.js.map +1 -1
- package/esm/policies/ScriptContains.d.ts +9 -7
- package/esm/policies/ScriptContains.d.ts.map +1 -1
- package/esm/policies/ScriptContains.js +9 -13
- package/esm/policies/ScriptContains.js.map +1 -1
- package/esm/policies/SharedDependencyVersions.d.ts +9 -4
- package/esm/policies/SharedDependencyVersions.d.ts.map +1 -1
- package/esm/policies/SharedDependencyVersions.js +28 -20
- package/esm/policies/SharedDependencyVersions.js.map +1 -1
- package/esm/policies/WorkspaceInheritance.d.ts +11 -4
- package/esm/policies/WorkspaceInheritance.d.ts.map +1 -1
- package/esm/policies/WorkspaceInheritance.js +10 -11
- package/esm/policies/WorkspaceInheritance.js.map +1 -1
- package/esm/policies/WorkspaceMembersValid.d.ts +11 -4
- package/esm/policies/WorkspaceMembersValid.d.ts.map +1 -1
- package/esm/policies/WorkspaceMembersValid.js +10 -11
- package/esm/policies/WorkspaceMembersValid.js.map +1 -1
- package/esm/policies/constants.d.ts.map +1 -1
- package/esm/policies/constants.js +1 -1
- package/esm/policies/constants.js.map +1 -1
- package/esm/policies.d.ts +15 -5
- package/esm/policies.d.ts.map +1 -1
- package/esm/policies.js +14 -5
- package/esm/policies.js.map +1 -1
- package/esm/policy.d.ts +67 -289
- package/esm/policy.d.ts.map +1 -1
- package/esm/policy.js +1 -122
- package/esm/policy.js.map +1 -1
- package/esm/policyDefiners/defineCargoPolicy.d.ts +25 -9
- package/esm/policyDefiners/defineCargoPolicy.d.ts.map +1 -1
- package/esm/policyDefiners/defineCargoPolicy.js +10 -28
- package/esm/policyDefiners/defineCargoPolicy.js.map +1 -1
- package/esm/policyDefiners/defineFileHeaderPolicy.d.ts +27 -14
- package/esm/policyDefiners/defineFileHeaderPolicy.d.ts.map +1 -1
- package/esm/policyDefiners/defineFileHeaderPolicy.js +16 -35
- package/esm/policyDefiners/defineFileHeaderPolicy.js.map +1 -1
- package/esm/policyDefiners/defineGleamPolicy.d.ts +25 -9
- package/esm/policyDefiners/defineGleamPolicy.d.ts.map +1 -1
- package/esm/policyDefiners/defineGleamPolicy.js +10 -27
- package/esm/policyDefiners/defineGleamPolicy.js.map +1 -1
- package/esm/policyDefiners/definePackagePolicy.d.ts +24 -13
- package/esm/policyDefiners/definePackagePolicy.d.ts.map +1 -1
- package/esm/policyDefiners/definePackagePolicy.js +9 -32
- package/esm/policyDefiners/definePackagePolicy.js.map +1 -1
- package/esm/policyDefiners/spdxValidator.d.ts +4 -12
- package/esm/policyDefiners/spdxValidator.d.ts.map +1 -1
- package/esm/policyDefiners/spdxValidator.js +26 -14
- package/esm/policyDefiners/spdxValidator.js.map +1 -1
- package/esm/policyExecution.d.ts +20 -0
- package/esm/policyExecution.d.ts.map +1 -0
- package/esm/policyExecution.js +234 -0
- package/esm/policyExecution.js.map +1 -0
- package/esm/repositoryChanges.d.ts +26 -0
- package/esm/repositoryChanges.d.ts.map +1 -0
- package/esm/repositoryChanges.js +172 -0
- package/esm/repositoryChanges.js.map +1 -0
- package/esm/repositoryFiles.d.ts +6 -0
- package/esm/repositoryFiles.d.ts.map +1 -0
- package/esm/repositoryFiles.js +11 -0
- package/esm/repositoryFiles.js.map +1 -0
- package/esm/runner.d.ts +73 -47
- package/esm/runner.d.ts.map +1 -1
- package/esm/runner.js +158 -144
- package/esm/runner.js.map +1 -1
- package/esm/settlePolicyPromise.d.ts +4 -0
- package/esm/settlePolicyPromise.d.ts.map +1 -0
- package/esm/settlePolicyPromise.js +10 -0
- package/esm/settlePolicyPromise.js.map +1 -0
- package/esm/tsdoc-metadata.json +1 -1
- package/esm/utils/safePaths.d.ts +9 -0
- package/esm/utils/safePaths.d.ts.map +1 -0
- package/esm/utils/safePaths.js +40 -0
- package/esm/utils/safePaths.js.map +1 -0
- package/oclif.manifest.json +57 -2
- package/package.json +42 -27
- package/scripts/benchmark.mjs +341 -0
- package/sidecar/sidecar.mjs +388 -417
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { type Operation } from "effection";
|
|
2
|
-
import type {
|
|
2
|
+
import type { DefinedConfig, FilePolicyDefinition, PolicyArgs, PolicyResult } from "../policy.js";
|
|
3
3
|
/**
|
|
4
4
|
* A parsed Cargo.toml represented as a record of sections and values.
|
|
5
5
|
*
|
|
6
|
-
* @
|
|
6
|
+
* @public
|
|
7
7
|
*/
|
|
8
8
|
export type CargoToml = Record<string, unknown>;
|
|
9
9
|
/**
|
|
@@ -12,13 +12,13 @@ export type CargoToml = Record<string, unknown>;
|
|
|
12
12
|
* @remarks
|
|
13
13
|
* Receives the parsed TOML content and the standard policy arguments.
|
|
14
14
|
*
|
|
15
|
-
* @
|
|
15
|
+
* @public
|
|
16
16
|
*/
|
|
17
|
-
export type CargoTomlHandler<C> = (toml: CargoToml, args: PolicyArgs<C>) => Operation<
|
|
17
|
+
export type CargoTomlHandler<C> = (toml: CargoToml, args: PolicyArgs<C>) => Operation<PolicyResult> | Promise<PolicyResult>;
|
|
18
18
|
/**
|
|
19
19
|
* Input arguments for defining a Cargo.toml policy.
|
|
20
20
|
*
|
|
21
|
-
* @
|
|
21
|
+
* @public
|
|
22
22
|
*/
|
|
23
23
|
export interface DefineCargoPolicyArgs<C> {
|
|
24
24
|
/**
|
|
@@ -37,6 +37,7 @@ export interface DefineCargoPolicyArgs<C> {
|
|
|
37
37
|
* Optional default configuration for the policy.
|
|
38
38
|
*/
|
|
39
39
|
defaultConfig?: C;
|
|
40
|
+
requiresConfig?: boolean;
|
|
40
41
|
}
|
|
41
42
|
/**
|
|
42
43
|
* Define a repo policy for Cargo.toml files.
|
|
@@ -45,6 +46,9 @@ export interface DefineCargoPolicyArgs<C> {
|
|
|
45
46
|
* This is a helper function that creates a policy pre-configured to match
|
|
46
47
|
* Cargo.toml files. The handler receives the parsed TOML content.
|
|
47
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
|
+
*
|
|
48
52
|
* @example
|
|
49
53
|
* ```typescript
|
|
50
54
|
* const MyCargoPolicy = defineCargoPolicy({
|
|
@@ -53,14 +57,26 @@ export interface DefineCargoPolicyArgs<C> {
|
|
|
53
57
|
* handler: async (toml, { file }) => {
|
|
54
58
|
* const pkg = toml.package as Record<string, unknown> | undefined;
|
|
55
59
|
* if (!pkg?.name) {
|
|
56
|
-
* return {
|
|
60
|
+
* return [{ message: "Missing package name" }];
|
|
57
61
|
* }
|
|
58
|
-
* return
|
|
62
|
+
* return [];
|
|
59
63
|
* },
|
|
60
64
|
* });
|
|
61
65
|
* ```
|
|
62
66
|
*
|
|
63
|
-
* @
|
|
67
|
+
* @public
|
|
64
68
|
*/
|
|
65
|
-
export declare function defineCargoPolicy<C =
|
|
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>;
|
|
66
82
|
//# sourceMappingURL=defineCargoPolicy.d.ts.map
|
|
@@ -1 +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;
|
|
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"}
|
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
import { readFile } from "node:fs/promises";
|
|
2
2
|
import { call } from "effection";
|
|
3
3
|
import { resolve } from "pathe";
|
|
4
|
+
import { ExecutionContractError } from "../executionContractError.js";
|
|
5
|
+
import { readParsedFile } from "../fileCache.js";
|
|
4
6
|
import { CargoTomlRegexMatch } from "../policies/constants.js";
|
|
7
|
+
import { settlePolicyPromise } from "../settlePolicyPromise.js";
|
|
5
8
|
import { parseToml } from "./tomlParser.js";
|
|
6
9
|
/**
|
|
7
10
|
* Type guard to check if a value is an Effection Operation (generator).
|
|
@@ -12,30 +15,6 @@ function isOperation(value) {
|
|
|
12
15
|
"next" in value &&
|
|
13
16
|
typeof value.next === "function");
|
|
14
17
|
}
|
|
15
|
-
/**
|
|
16
|
-
* Define a repo policy for Cargo.toml files.
|
|
17
|
-
*
|
|
18
|
-
* @remarks
|
|
19
|
-
* This is a helper function that creates a policy pre-configured to match
|
|
20
|
-
* Cargo.toml files. The handler receives the parsed TOML content.
|
|
21
|
-
*
|
|
22
|
-
* @example
|
|
23
|
-
* ```typescript
|
|
24
|
-
* const MyCargoPolicy = defineCargoPolicy({
|
|
25
|
-
* name: "MyCargoPolicy",
|
|
26
|
-
* description: "Ensures Cargo.toml has required fields",
|
|
27
|
-
* handler: async (toml, { file }) => {
|
|
28
|
-
* const pkg = toml.package as Record<string, unknown> | undefined;
|
|
29
|
-
* if (!pkg?.name) {
|
|
30
|
-
* return { error: "Missing package name", fixable: false };
|
|
31
|
-
* }
|
|
32
|
-
* return true;
|
|
33
|
-
* },
|
|
34
|
-
* });
|
|
35
|
-
* ```
|
|
36
|
-
*
|
|
37
|
-
* @alpha
|
|
38
|
-
*/
|
|
39
18
|
export function defineCargoPolicy(args) {
|
|
40
19
|
const { name, description, handler: cargoHandler, defaultConfig } = args;
|
|
41
20
|
return {
|
|
@@ -43,17 +22,20 @@ export function defineCargoPolicy(args) {
|
|
|
43
22
|
description,
|
|
44
23
|
match: CargoTomlRegexMatch,
|
|
45
24
|
defaultConfig,
|
|
25
|
+
requiresConfig: args.requiresConfig,
|
|
46
26
|
handler: function* (innerArgs) {
|
|
47
|
-
const
|
|
48
|
-
|
|
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
|
+
}));
|
|
49
31
|
const result = cargoHandler(toml, innerArgs);
|
|
50
32
|
if (result instanceof Promise) {
|
|
51
|
-
return yield*
|
|
33
|
+
return yield* settlePolicyPromise(result);
|
|
52
34
|
}
|
|
53
35
|
if (isOperation(result)) {
|
|
54
36
|
return yield* result;
|
|
55
37
|
}
|
|
56
|
-
throw new
|
|
38
|
+
throw new ExecutionContractError(`Unexpected handler result type: ${typeof result}`);
|
|
57
39
|
},
|
|
58
40
|
};
|
|
59
41
|
}
|
|
@@ -1 +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,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;
|
|
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"}
|
|
@@ -1,23 +1,9 @@
|
|
|
1
1
|
import { readFile, writeFile } from "node:fs/promises";
|
|
2
2
|
import { EOL as newline } from "node:os";
|
|
3
3
|
import { call } from "effection";
|
|
4
|
-
import { extname
|
|
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 ?? "";
|
|
@@ -35,44 +21,39 @@ export function defineFileHeaderPolicy(args) {
|
|
|
35
21
|
name,
|
|
36
22
|
description,
|
|
37
23
|
match: config.match,
|
|
24
|
+
requiresConfig: true,
|
|
25
|
+
defaultConfig: args.defaultConfig,
|
|
38
26
|
handler: function* ({ file, root, resolve, config: policyConfig }) {
|
|
39
27
|
if (policyConfig === undefined) {
|
|
40
|
-
|
|
28
|
+
throw new TypeError(`${name} requires config.`);
|
|
41
29
|
}
|
|
42
30
|
const regex = new RegExp(`^${pre}${toRegex(policyConfig.headerText)}(${toRegex(policyConfig.autoGenText ?? config.autoGenText ?? "")})?${post}`);
|
|
43
|
-
const
|
|
44
|
-
|
|
45
|
-
file,
|
|
46
|
-
autoFixable: true,
|
|
47
|
-
errorMessages: [],
|
|
48
|
-
};
|
|
31
|
+
const filePath = resolveRepoFilePath(root, file);
|
|
32
|
+
const failResult = [];
|
|
49
33
|
// TODO: Consider reading only the first 512B or so since headers are typically
|
|
50
34
|
// at the beginning of the file.
|
|
51
|
-
const filePath = resolvePath(root, file);
|
|
52
35
|
const content = yield* call(() => readFile(filePath, { encoding: "utf8" }));
|
|
53
36
|
const failed = !regex.test(content);
|
|
54
37
|
if (failed) {
|
|
55
|
-
failResult.
|
|
38
|
+
failResult.push({
|
|
39
|
+
message: `${extname(file)} file missing header`,
|
|
40
|
+
fixStatus: "available",
|
|
41
|
+
});
|
|
56
42
|
}
|
|
57
43
|
if (failed) {
|
|
58
44
|
if (resolve) {
|
|
59
45
|
const newContent = config.replacer(content, policyConfig);
|
|
60
46
|
yield* call(() => writeFile(filePath, newContent));
|
|
61
|
-
const fixResult = {
|
|
62
|
-
...
|
|
63
|
-
|
|
64
|
-
};
|
|
47
|
+
const fixResult = failResult.map((finding) => ({
|
|
48
|
+
...finding,
|
|
49
|
+
fixStatus: "fixed",
|
|
50
|
+
}));
|
|
65
51
|
return fixResult;
|
|
66
52
|
}
|
|
67
53
|
return failResult;
|
|
68
54
|
}
|
|
69
|
-
return
|
|
55
|
+
return [];
|
|
70
56
|
},
|
|
71
57
|
};
|
|
72
58
|
}
|
|
73
|
-
/**
|
|
74
|
-
* Alias for defineFileHeaderPolicy.
|
|
75
|
-
* @alpha
|
|
76
|
-
*/
|
|
77
|
-
export const fileHeaderPolicy = defineFileHeaderPolicy;
|
|
78
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,SAAS,EAAE,MAAM,kBAAkB,CAAC;AACvD,OAAO,EAAE,GAAG,IAAI,OAAO,EAAE,MAAM,SAAS,CAAC;AACzC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,OAAO,EAAE,OAAO,
|
|
1
|
+
{"version":3,"file":"defineFileHeaderPolicy.js","sourceRoot":"","sources":["../../src/policyDefiners/defineFileHeaderPolicy.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AACvD,OAAO,EAAE,GAAG,IAAI,OAAO,EAAE,MAAM,SAAS,CAAC;AACzC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,OAAO,EAAE,MAAM,OAAO,CAAC;AAEhC,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAE5D,MAAM,cAAc,GAAG,aAAa,CAAC;AAqHrC,MAAM,UAAU,sBAAsB,CACrC,IAAgC;IAEhC,MAAM,EAAE,IAAI,EAAE,WAAW,EAAE,MAAM,EAAE,GAAG,IAAI,CAAC;IAC3C,MAAM,GAAG,GAAG,MAAM,CAAC,WAAW,EAAE,MAAM,IAAI,EAAE,CAAC;IAC7C,MAAM,KAAK,GAAG,MAAM,CAAC,SAAS,CAAC,MAAM,CAAC;IACtC,MAAM,GAAG,GAAG,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC;IAClC,MAAM,IAAI,GAAG,MAAM,CAAC,SAAS,EAAE,MAAM,IAAI,EAAE,CAAC;IAE5C,2EAA2E;IAC3E,mGAAmG;IACnG,MAAM,OAAO,GAAG,CAAC,IAAY,EAAU,EAAE,CACxC,IAAI;SACF,KAAK,CAAC,OAAO,CAAC;SACd,GAAG,CACH,CAAC,IAAI,EAAE,EAAE,CACR,GAAG,KAAK,GAAG,IAAI,CAAC,OAAO,CAAC,qBAAqB,EAAE,MAAM,CAAC,GAAG,GAAG,EAAE,CAC/D;SACA,IAAI,CAAC,EAAE,CAAC;SACR,OAAO,CAAC,cAAc,EAAE,SAAS,CAAC,CAAC,CAAC,uCAAuC;IAE9E,OAAO;QACN,IAAI;QACJ,WAAW;QACX,KAAK,EAAE,MAAM,CAAC,KAAK;QACnB,cAAc,EAAE,IAAI;QACpB,aAAa,EAAE,IAAI,CAAC,aAAa;QACjC,OAAO,EAAE,QAAQ,CAAC,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,EAAE,YAAY,EAAE;YAChE,IAAI,YAAY,KAAK,SAAS,EAAE,CAAC;gBAChC,MAAM,IAAI,SAAS,CAAC,GAAG,IAAI,mBAAmB,CAAC,CAAC;YACjD,CAAC;YAED,MAAM,KAAK,GAAG,IAAI,MAAM,CACvB,IAAI,GAAG,GAAG,OAAO,CAAC,YAAY,CAAC,UAAU,CAAC,IAAI,OAAO,CAAC,YAAY,CAAC,WAAW,IAAI,MAAM,CAAC,WAAW,IAAI,EAAE,CAAC,KAAK,IAAI,EAAE,CACtH,CAAC;YACF,MAAM,QAAQ,GAAG,mBAAmB,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;YACjD,MAAM,UAAU,GAAoB,EAAE,CAAC;YACvC,+EAA+E;YAC/E,gCAAgC;YAChC,MAAM,OAAO,GAAG,KAAK,CAAC,CAAC,IAAI,CAAC,GAAG,EAAE,CAChC,QAAQ,CAAC,QAAQ,EAAE,EAAE,QAAQ,EAAE,MAAM,EAAE,CAAC,CACxC,CAAC;YACF,MAAM,MAAM,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;YAEpC,IAAI,MAAM,EAAE,CAAC;gBACZ,UAAU,CAAC,IAAI,CAAC;oBACf,OAAO,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,sBAAsB;oBAC/C,SAAS,EAAE,WAAW;iBACtB,CAAC,CAAC;YACJ,CAAC;YAED,IAAI,MAAM,EAAE,CAAC;gBACZ,IAAI,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"]}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { type Operation } from "effection";
|
|
2
|
-
import type {
|
|
2
|
+
import type { DefinedConfig, FilePolicyDefinition, PolicyArgs, PolicyResult } from "../policy.js";
|
|
3
3
|
/**
|
|
4
4
|
* A parsed gleam.toml represented as a record of sections and values.
|
|
5
5
|
*
|
|
6
|
-
* @
|
|
6
|
+
* @public
|
|
7
7
|
*/
|
|
8
8
|
export type GleamToml = Record<string, unknown>;
|
|
9
9
|
/**
|
|
@@ -12,13 +12,13 @@ export type GleamToml = Record<string, unknown>;
|
|
|
12
12
|
* @remarks
|
|
13
13
|
* Receives the parsed TOML content and the standard policy arguments.
|
|
14
14
|
*
|
|
15
|
-
* @
|
|
15
|
+
* @public
|
|
16
16
|
*/
|
|
17
|
-
export type GleamTomlHandler<C> = (toml: GleamToml, args: PolicyArgs<C>) => Operation<
|
|
17
|
+
export type GleamTomlHandler<C> = (toml: GleamToml, args: PolicyArgs<C>) => Operation<PolicyResult> | Promise<PolicyResult>;
|
|
18
18
|
/**
|
|
19
19
|
* Input arguments for defining a gleam.toml policy.
|
|
20
20
|
*
|
|
21
|
-
* @
|
|
21
|
+
* @public
|
|
22
22
|
*/
|
|
23
23
|
export interface DefineGleamPolicyArgs<C> {
|
|
24
24
|
/**
|
|
@@ -37,6 +37,7 @@ export interface DefineGleamPolicyArgs<C> {
|
|
|
37
37
|
* Optional default configuration for the policy.
|
|
38
38
|
*/
|
|
39
39
|
defaultConfig?: C;
|
|
40
|
+
requiresConfig?: boolean;
|
|
40
41
|
}
|
|
41
42
|
/**
|
|
42
43
|
* Define a repo policy for gleam.toml files.
|
|
@@ -45,6 +46,9 @@ export interface DefineGleamPolicyArgs<C> {
|
|
|
45
46
|
* This is a helper function that creates a policy pre-configured to match
|
|
46
47
|
* gleam.toml files. The handler receives the parsed TOML content.
|
|
47
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
|
+
*
|
|
48
52
|
* @example
|
|
49
53
|
* ```typescript
|
|
50
54
|
* const MyGleamPolicy = defineGleamPolicy({
|
|
@@ -52,14 +56,26 @@ export interface DefineGleamPolicyArgs<C> {
|
|
|
52
56
|
* description: "Ensures gleam.toml has required fields",
|
|
53
57
|
* handler: async (toml, { file }) => {
|
|
54
58
|
* if (!toml.name) {
|
|
55
|
-
* return {
|
|
59
|
+
* return [{ message: "Missing name field" }];
|
|
56
60
|
* }
|
|
57
|
-
* return
|
|
61
|
+
* return [];
|
|
58
62
|
* },
|
|
59
63
|
* });
|
|
60
64
|
* ```
|
|
61
65
|
*
|
|
62
|
-
* @
|
|
66
|
+
* @public
|
|
63
67
|
*/
|
|
64
|
-
export declare function defineGleamPolicy<C =
|
|
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>;
|
|
65
81
|
//# sourceMappingURL=defineGleamPolicy.d.ts.map
|
|
@@ -1 +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;
|
|
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,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"}
|
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
import { readFile } from "node:fs/promises";
|
|
2
2
|
import { call } from "effection";
|
|
3
3
|
import { resolve } from "pathe";
|
|
4
|
+
import { ExecutionContractError } from "../executionContractError.js";
|
|
5
|
+
import { readParsedFile } from "../fileCache.js";
|
|
4
6
|
import { GleamTomlRegexMatch } from "../policies/constants.js";
|
|
7
|
+
import { settlePolicyPromise } from "../settlePolicyPromise.js";
|
|
5
8
|
import { parseToml } from "./tomlParser.js";
|
|
6
9
|
/**
|
|
7
10
|
* Type guard to check if a value is an Effection Operation (generator).
|
|
@@ -12,29 +15,6 @@ function isOperation(value) {
|
|
|
12
15
|
"next" in value &&
|
|
13
16
|
typeof value.next === "function");
|
|
14
17
|
}
|
|
15
|
-
/**
|
|
16
|
-
* Define a repo policy for gleam.toml files.
|
|
17
|
-
*
|
|
18
|
-
* @remarks
|
|
19
|
-
* This is a helper function that creates a policy pre-configured to match
|
|
20
|
-
* gleam.toml files. The handler receives the parsed TOML content.
|
|
21
|
-
*
|
|
22
|
-
* @example
|
|
23
|
-
* ```typescript
|
|
24
|
-
* const MyGleamPolicy = defineGleamPolicy({
|
|
25
|
-
* name: "MyGleamPolicy",
|
|
26
|
-
* description: "Ensures gleam.toml has required fields",
|
|
27
|
-
* handler: async (toml, { file }) => {
|
|
28
|
-
* if (!toml.name) {
|
|
29
|
-
* return { error: "Missing name field", fixable: false };
|
|
30
|
-
* }
|
|
31
|
-
* return true;
|
|
32
|
-
* },
|
|
33
|
-
* });
|
|
34
|
-
* ```
|
|
35
|
-
*
|
|
36
|
-
* @alpha
|
|
37
|
-
*/
|
|
38
18
|
export function defineGleamPolicy(args) {
|
|
39
19
|
const { name, description, handler: gleamHandler, defaultConfig } = args;
|
|
40
20
|
return {
|
|
@@ -42,17 +22,20 @@ export function defineGleamPolicy(args) {
|
|
|
42
22
|
description,
|
|
43
23
|
match: GleamTomlRegexMatch,
|
|
44
24
|
defaultConfig,
|
|
25
|
+
requiresConfig: args.requiresConfig,
|
|
45
26
|
handler: function* (innerArgs) {
|
|
46
|
-
const
|
|
47
|
-
|
|
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
|
+
}));
|
|
48
31
|
const result = gleamHandler(toml, innerArgs);
|
|
49
32
|
if (result instanceof Promise) {
|
|
50
|
-
return yield*
|
|
33
|
+
return yield* settlePolicyPromise(result);
|
|
51
34
|
}
|
|
52
35
|
if (isOperation(result)) {
|
|
53
36
|
return yield* result;
|
|
54
37
|
}
|
|
55
|
-
throw new
|
|
38
|
+
throw new ExecutionContractError(`Unexpected handler result type: ${typeof result}`);
|
|
56
39
|
},
|
|
57
40
|
};
|
|
58
41
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"defineGleamPolicy.js","sourceRoot":"","sources":["../../src/policyDefiners/defineGleamPolicy.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,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;
|
|
1
|
+
{"version":3,"file":"defineGleamPolicy.js","sourceRoot":"","sources":["../../src/policyDefiners/defineGleamPolicy.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;AAmED,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 { GleamTomlRegexMatch } 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 gleam.toml represented as a record of sections and values.\n *\n * @public\n */\nexport type GleamToml = Record<string, unknown>;\n\n/**\n * A policy handler for gleam.toml policies.\n *\n * @remarks\n * Receives the parsed TOML content and the standard policy arguments.\n *\n * @public\n */\nexport type GleamTomlHandler<C> = (\n\ttoml: GleamToml,\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 gleam.toml policy.\n *\n * @public\n */\nexport interface DefineGleamPolicyArgs<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 gleam.toml and policy arguments.\n\t */\n\thandler: GleamTomlHandler<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 gleam.toml files.\n *\n * @remarks\n * This is a helper function that creates a policy pre-configured to match\n * gleam.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 gleam.toml files.\n *\n * @example\n * ```typescript\n * const MyGleamPolicy = defineGleamPolicy({\n * name: \"MyGleamPolicy\",\n * description: \"Ensures gleam.toml has required fields\",\n * handler: async (toml, { file }) => {\n * if (!toml.name) {\n * return [{ message: \"Missing name field\" }];\n * }\n * return [];\n * },\n * });\n * ```\n *\n * @public\n */\nexport function defineGleamPolicy<C = void>(\n\targs: DefineGleamPolicyArgs<C> & { defaultConfig: DefinedConfig<C> },\n): FilePolicyDefinition<C> & { defaultConfig: DefinedConfig<C> };\n/** Define a Gleam policy that requires explicit configuration. @public */\nexport function defineGleamPolicy<C = void>(\n\targs: DefineGleamPolicyArgs<C> & { requiresConfig: true },\n): FilePolicyDefinition<C> & { requiresConfig: true };\n/** Define a Gleam policy with optional configuration. @public */\nexport function defineGleamPolicy<C = void>(\n\targs: DefineGleamPolicyArgs<C>,\n): FilePolicyDefinition<C>;\nexport function defineGleamPolicy<C = void>(\n\targs: DefineGleamPolicyArgs<C>,\n): FilePolicyDefinition<C> {\n\tconst { name, description, handler: gleamHandler, defaultConfig } = args;\n\treturn {\n\t\tname,\n\t\tdescription,\n\t\tmatch: GleamTomlRegexMatch,\n\t\tdefaultConfig,\n\t\trequiresConfig: args.requiresConfig,\n\t\thandler: function* (innerArgs) {\n\t\t\tconst toml: GleamToml = 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 = gleamHandler(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"]}
|