repopo 0.10.0 → 0.13.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +113 -0
- package/README.md +76 -77
- package/THIRD-PARTY-LICENSES.txt +232 -14
- package/bin/dev.js +5 -1
- package/esm/adapters/fluidFramework.d.ts +13 -9
- package/esm/adapters/fluidFramework.d.ts.map +1 -1
- package/esm/adapters/fluidFramework.js +20 -43
- package/esm/adapters/fluidFramework.js.map +1 -1
- package/esm/api.d.ts +64 -1
- package/esm/api.d.ts.map +1 -1
- package/esm/api.js +17 -1
- package/esm/api.js.map +1 -1
- package/esm/baseCommand.d.ts +1 -1
- package/esm/baseCommand.d.ts.map +1 -1
- package/esm/baseCommand.js +7 -10
- package/esm/baseCommand.js.map +1 -1
- package/esm/commands/check-native.d.ts +25 -0
- package/esm/commands/check-native.d.ts.map +1 -0
- package/esm/commands/check-native.js +156 -0
- package/esm/commands/check-native.js.map +1 -0
- package/esm/commands/check.d.ts +7 -34
- package/esm/commands/check.d.ts.map +1 -1
- package/esm/commands/check.js +76 -265
- package/esm/commands/check.js.map +1 -1
- package/esm/commands/list.d.ts.map +1 -1
- package/esm/commands/list.js +6 -6
- package/esm/commands/list.js.map +1 -1
- package/esm/concurrency.d.ts +3 -0
- package/esm/concurrency.d.ts.map +1 -0
- package/esm/concurrency.js +8 -0
- package/esm/concurrency.js.map +1 -0
- package/esm/config.d.ts +5 -39
- package/esm/config.d.ts.map +1 -1
- package/esm/config.js +3 -7
- package/esm/config.js.map +1 -1
- package/esm/context.d.ts +20 -3
- package/esm/context.d.ts.map +1 -1
- package/esm/context.js +18 -1
- package/esm/context.js.map +1 -1
- package/esm/executionContractError.d.ts +4 -0
- package/esm/executionContractError.d.ts.map +1 -0
- package/esm/executionContractError.js +4 -0
- package/esm/executionContractError.js.map +1 -0
- package/esm/fileCache.d.ts +12 -0
- package/esm/fileCache.d.ts.map +1 -0
- package/esm/fileCache.js +37 -0
- package/esm/fileCache.js.map +1 -0
- package/esm/filePaths.d.ts +2 -0
- package/esm/filePaths.d.ts.map +1 -0
- package/esm/filePaths.js +9 -0
- package/esm/filePaths.js.map +1 -0
- package/esm/generators.d.ts +0 -20
- package/esm/generators.d.ts.map +1 -1
- package/esm/generators.js.map +1 -1
- package/esm/index.d.ts +3 -11
- package/esm/index.d.ts.map +1 -1
- package/esm/index.js +3 -14
- package/esm/index.js.map +1 -1
- package/esm/makePolicy.d.ts +26 -79
- package/esm/makePolicy.d.ts.map +1 -1
- package/esm/makePolicy.js +51 -95
- package/esm/makePolicy.js.map +1 -1
- package/esm/perf.d.ts +10 -2
- package/esm/perf.d.ts.map +1 -1
- package/esm/perf.js +10 -9
- package/esm/perf.js.map +1 -1
- package/esm/policies/CargoLicenceValidated.d.ts +41 -0
- package/esm/policies/CargoLicenceValidated.d.ts.map +1 -0
- package/esm/policies/CargoLicenceValidated.js +47 -0
- package/esm/policies/CargoLicenceValidated.js.map +1 -0
- package/esm/policies/CargoLintsConfigured.d.ts +30 -0
- package/esm/policies/CargoLintsConfigured.d.ts.map +1 -0
- package/esm/policies/CargoLintsConfigured.js +65 -0
- package/esm/policies/CargoLintsConfigured.js.map +1 -0
- package/esm/policies/CargoLockPolicy.d.ts +34 -0
- package/esm/policies/CargoLockPolicy.d.ts.map +1 -0
- package/esm/policies/CargoLockPolicy.js +61 -0
- package/esm/policies/CargoLockPolicy.js.map +1 -0
- package/esm/policies/CargoTomlRequired.d.ts +34 -0
- package/esm/policies/CargoTomlRequired.d.ts.map +1 -0
- package/esm/policies/CargoTomlRequired.js +77 -0
- package/esm/policies/CargoTomlRequired.js.map +1 -0
- package/esm/policies/CargoTomlSorted.d.ts +20 -0
- package/esm/policies/CargoTomlSorted.d.ts.map +1 -0
- package/esm/policies/CargoTomlSorted.js +168 -0
- package/esm/policies/CargoTomlSorted.js.map +1 -0
- package/esm/policies/ConditionalScripts.d.ts +10 -8
- package/esm/policies/ConditionalScripts.d.ts.map +1 -1
- package/esm/policies/ConditionalScripts.js +27 -24
- package/esm/policies/ConditionalScripts.js.map +1 -1
- package/esm/policies/ExactScripts.d.ts +8 -6
- package/esm/policies/ExactScripts.d.ts.map +1 -1
- package/esm/policies/ExactScripts.js +18 -20
- package/esm/policies/ExactScripts.js.map +1 -1
- package/esm/policies/GleamDepVersions.d.ts +25 -0
- package/esm/policies/GleamDepVersions.d.ts.map +1 -0
- package/esm/policies/GleamDepVersions.js +67 -0
- package/esm/policies/GleamDepVersions.js.map +1 -0
- package/esm/policies/GleamDocExists.d.ts +24 -0
- package/esm/policies/GleamDocExists.d.ts.map +1 -0
- package/esm/policies/GleamDocExists.js +39 -0
- package/esm/policies/GleamDocExists.js.map +1 -0
- package/esm/policies/GleamInternalModulesConfigured.d.ts +21 -0
- package/esm/policies/GleamInternalModulesConfigured.d.ts.map +1 -0
- package/esm/policies/GleamInternalModulesConfigured.js +32 -0
- package/esm/policies/GleamInternalModulesConfigured.js.map +1 -0
- package/esm/policies/GleamLicenceConfigured.d.ts +29 -0
- package/esm/policies/GleamLicenceConfigured.d.ts.map +1 -0
- package/esm/policies/GleamLicenceConfigured.js +36 -0
- package/esm/policies/GleamLicenceConfigured.js.map +1 -0
- package/esm/policies/GleamManifestCommitted.d.ts +16 -0
- package/esm/policies/GleamManifestCommitted.d.ts.map +1 -0
- package/esm/policies/GleamManifestCommitted.js +27 -0
- package/esm/policies/GleamManifestCommitted.js.map +1 -0
- package/esm/policies/GleamMonorepoConsistency.d.ts +38 -0
- package/esm/policies/GleamMonorepoConsistency.d.ts.map +1 -0
- package/esm/policies/GleamMonorepoConsistency.js +74 -0
- package/esm/policies/GleamMonorepoConsistency.js.map +1 -0
- package/esm/policies/GleamNameRestrictions.d.ts +25 -0
- package/esm/policies/GleamNameRestrictions.d.ts.map +1 -0
- package/esm/policies/GleamNameRestrictions.js +44 -0
- package/esm/policies/GleamNameRestrictions.js.map +1 -0
- package/esm/policies/GleamNoPathDepsInPublished.d.ts +22 -0
- package/esm/policies/GleamNoPathDepsInPublished.d.ts.map +1 -0
- package/esm/policies/GleamNoPathDepsInPublished.js +43 -0
- package/esm/policies/GleamNoPathDepsInPublished.js.map +1 -0
- package/esm/policies/GleamPathDepsValid.d.ts +9 -0
- package/esm/policies/GleamPathDepsValid.d.ts.map +1 -0
- package/esm/policies/GleamPathDepsValid.js +59 -0
- package/esm/policies/GleamPathDepsValid.js.map +1 -0
- package/esm/policies/GleamProjectStructure.d.ts +32 -0
- package/esm/policies/GleamProjectStructure.d.ts.map +1 -0
- package/esm/policies/GleamProjectStructure.js +32 -0
- package/esm/policies/GleamProjectStructure.js.map +1 -0
- package/esm/policies/GleamSharedDependencyVersions.d.ts +37 -0
- package/esm/policies/GleamSharedDependencyVersions.d.ts.map +1 -0
- package/esm/policies/GleamSharedDependencyVersions.js +101 -0
- package/esm/policies/GleamSharedDependencyVersions.js.map +1 -0
- package/esm/policies/GleamTomlRequired.d.ts +30 -0
- package/esm/policies/GleamTomlRequired.d.ts.map +1 -0
- package/esm/policies/GleamTomlRequired.js +37 -0
- package/esm/policies/GleamTomlRequired.js.map +1 -0
- package/esm/policies/GleamTomlSorted.d.ts +20 -0
- package/esm/policies/GleamTomlSorted.d.ts.map +1 -0
- package/esm/policies/GleamTomlSorted.js +157 -0
- package/esm/policies/GleamTomlSorted.js.map +1 -0
- package/esm/policies/GleamVersionConstraint.d.ts +20 -0
- package/esm/policies/GleamVersionConstraint.d.ts.map +1 -0
- package/esm/policies/GleamVersionConstraint.js +68 -0
- package/esm/policies/GleamVersionConstraint.js.map +1 -0
- package/esm/policies/HtmlFileHeaders.d.ts +4 -2
- package/esm/policies/HtmlFileHeaders.d.ts.map +1 -1
- package/esm/policies/HtmlFileHeaders.js +2 -2
- package/esm/policies/HtmlFileHeaders.js.map +1 -1
- package/esm/policies/JsTsFileHeaders.d.ts +4 -2
- package/esm/policies/JsTsFileHeaders.d.ts.map +1 -1
- package/esm/policies/JsTsFileHeaders.js +1 -1
- package/esm/policies/JsTsFileHeaders.js.map +1 -1
- package/esm/policies/LicenseFileExists.d.ts +10 -4
- package/esm/policies/LicenseFileExists.d.ts.map +1 -1
- package/esm/policies/LicenseFileExists.js +27 -20
- package/esm/policies/LicenseFileExists.js.map +1 -1
- package/esm/policies/MutuallyExclusiveScripts.d.ts +8 -6
- package/esm/policies/MutuallyExclusiveScripts.d.ts.map +1 -1
- package/esm/policies/MutuallyExclusiveScripts.js +9 -13
- package/esm/policies/MutuallyExclusiveScripts.js.map +1 -1
- package/esm/policies/NoBuildDirectory.d.ts +15 -0
- package/esm/policies/NoBuildDirectory.d.ts.map +1 -0
- package/esm/policies/NoBuildDirectory.js +24 -0
- package/esm/policies/NoBuildDirectory.js.map +1 -0
- package/esm/policies/NoJsFileExtensions.d.ts +9 -3
- package/esm/policies/NoJsFileExtensions.d.ts.map +1 -1
- package/esm/policies/NoJsFileExtensions.js +9 -14
- package/esm/policies/NoJsFileExtensions.js.map +1 -1
- package/esm/policies/NoLargeBinaryFiles.d.ts +9 -4
- package/esm/policies/NoLargeBinaryFiles.d.ts.map +1 -1
- package/esm/policies/NoLargeBinaryFiles.js +10 -16
- package/esm/policies/NoLargeBinaryFiles.js.map +1 -1
- package/esm/policies/NoPrivateWorkspaceDependencies.d.ts +10 -6
- package/esm/policies/NoPrivateWorkspaceDependencies.d.ts.map +1 -1
- package/esm/policies/NoPrivateWorkspaceDependencies.js +12 -14
- package/esm/policies/NoPrivateWorkspaceDependencies.js.map +1 -1
- package/esm/policies/NoTargetArtifacts.d.ts +14 -0
- package/esm/policies/NoTargetArtifacts.d.ts.map +1 -0
- package/esm/policies/NoTargetArtifacts.js +37 -0
- package/esm/policies/NoTargetArtifacts.js.map +1 -0
- package/esm/policies/NoUnsafeWithoutJustification.d.ts +31 -0
- package/esm/policies/NoUnsafeWithoutJustification.d.ts.map +1 -0
- package/esm/policies/NoUnsafeWithoutJustification.js +79 -0
- package/esm/policies/NoUnsafeWithoutJustification.js.map +1 -0
- package/esm/policies/NoWildcardDependencies.d.ts +30 -0
- package/esm/policies/NoWildcardDependencies.d.ts.map +1 -0
- package/esm/policies/NoWildcardDependencies.js +83 -0
- package/esm/policies/NoWildcardDependencies.js.map +1 -0
- package/esm/policies/PackageAllowedScopes.d.ts +9 -5
- package/esm/policies/PackageAllowedScopes.d.ts.map +1 -1
- package/esm/policies/PackageAllowedScopes.js +15 -16
- package/esm/policies/PackageAllowedScopes.js.map +1 -1
- package/esm/policies/PackageEsmType.d.ts +7 -5
- package/esm/policies/PackageEsmType.d.ts.map +1 -1
- package/esm/policies/PackageEsmType.js +38 -36
- package/esm/policies/PackageEsmType.js.map +1 -1
- package/esm/policies/PackageFolderName.d.ts +8 -6
- package/esm/policies/PackageFolderName.d.ts.map +1 -1
- package/esm/policies/PackageFolderName.js +13 -16
- package/esm/policies/PackageFolderName.js.map +1 -1
- package/esm/policies/PackageJsonProperties.d.ts +5 -3
- package/esm/policies/PackageJsonProperties.d.ts.map +1 -1
- package/esm/policies/PackageJsonProperties.js +18 -21
- package/esm/policies/PackageJsonProperties.js.map +1 -1
- package/esm/policies/PackageJsonRepoDirectoryProperty.d.ts +2 -7
- package/esm/policies/PackageJsonRepoDirectoryProperty.d.ts.map +1 -1
- package/esm/policies/PackageJsonRepoDirectoryProperty.js +29 -42
- package/esm/policies/PackageJsonRepoDirectoryProperty.js.map +1 -1
- package/esm/policies/PackageJsonSorted.d.ts +2 -2
- package/esm/policies/PackageJsonSorted.d.ts.map +1 -1
- package/esm/policies/PackageJsonSorted.js +51 -31
- package/esm/policies/PackageJsonSorted.js.map +1 -1
- package/esm/policies/PackageLicense.d.ts +4 -4
- package/esm/policies/PackageLicense.d.ts.map +1 -1
- package/esm/policies/PackageLicense.js +32 -54
- package/esm/policies/PackageLicense.js.map +1 -1
- package/esm/policies/PackagePrivateField.d.ts +12 -8
- package/esm/policies/PackagePrivateField.d.ts.map +1 -1
- package/esm/policies/PackagePrivateField.js +34 -25
- package/esm/policies/PackagePrivateField.js.map +1 -1
- package/esm/policies/PackageReadme.d.ts +6 -5
- package/esm/policies/PackageReadme.d.ts.map +1 -1
- package/esm/policies/PackageReadme.js +24 -61
- package/esm/policies/PackageReadme.js.map +1 -1
- package/esm/policies/PackageScripts.d.ts +26 -22
- package/esm/policies/PackageScripts.d.ts.map +1 -1
- package/esm/policies/PackageScripts.js +42 -38
- package/esm/policies/PackageScripts.js.map +1 -1
- package/esm/policies/PackageTestScripts.d.ts +10 -6
- package/esm/policies/PackageTestScripts.d.ts.map +1 -1
- package/esm/policies/PackageTestScripts.js +17 -19
- package/esm/policies/PackageTestScripts.js.map +1 -1
- package/esm/policies/PublicApiDocumented.d.ts +21 -0
- package/esm/policies/PublicApiDocumented.d.ts.map +1 -0
- package/esm/policies/PublicApiDocumented.js +38 -0
- package/esm/policies/PublicApiDocumented.js.map +1 -0
- package/esm/policies/RequiredGitignorePatterns.d.ts +11 -4
- package/esm/policies/RequiredGitignorePatterns.d.ts.map +1 -1
- package/esm/policies/RequiredGitignorePatterns.js +29 -36
- package/esm/policies/RequiredGitignorePatterns.js.map +1 -1
- package/esm/policies/RequiredScripts.d.ts +9 -7
- package/esm/policies/RequiredScripts.d.ts.map +1 -1
- package/esm/policies/RequiredScripts.js +27 -26
- package/esm/policies/RequiredScripts.js.map +1 -1
- package/esm/policies/RustDocExists.d.ts +24 -0
- package/esm/policies/RustDocExists.d.ts.map +1 -0
- package/esm/policies/RustDocExists.js +49 -0
- package/esm/policies/RustDocExists.js.map +1 -0
- package/esm/policies/RustToolchainExists.d.ts +27 -0
- package/esm/policies/RustToolchainExists.d.ts.map +1 -0
- package/esm/policies/RustToolchainExists.js +28 -0
- package/esm/policies/RustToolchainExists.js.map +1 -0
- package/esm/policies/RustfmtConfigExists.d.ts +27 -0
- package/esm/policies/RustfmtConfigExists.d.ts.map +1 -0
- package/esm/policies/RustfmtConfigExists.js +28 -0
- package/esm/policies/RustfmtConfigExists.js.map +1 -0
- package/esm/policies/ScriptContains.d.ts +9 -7
- package/esm/policies/ScriptContains.d.ts.map +1 -1
- package/esm/policies/ScriptContains.js +9 -13
- package/esm/policies/ScriptContains.js.map +1 -1
- package/esm/policies/SharedDependencyVersions.d.ts +29 -0
- package/esm/policies/SharedDependencyVersions.d.ts.map +1 -0
- package/esm/policies/SharedDependencyVersions.js +143 -0
- package/esm/policies/SharedDependencyVersions.js.map +1 -0
- package/esm/policies/WorkspaceInheritance.d.ts +31 -0
- package/esm/policies/WorkspaceInheritance.d.ts.map +1 -0
- package/esm/policies/WorkspaceInheritance.js +93 -0
- package/esm/policies/WorkspaceInheritance.js.map +1 -0
- package/esm/policies/WorkspaceMembersValid.d.ts +27 -0
- package/esm/policies/WorkspaceMembersValid.d.ts.map +1 -0
- package/esm/policies/WorkspaceMembersValid.js +87 -0
- package/esm/policies/WorkspaceMembersValid.js.map +1 -0
- package/esm/policies/constants.d.ts +8 -0
- package/esm/policies/constants.d.ts.map +1 -1
- package/esm/policies/constants.js +9 -1
- package/esm/policies/constants.js.map +1 -1
- package/esm/policies.d.ts +43 -5
- package/esm/policies.d.ts.map +1 -1
- package/esm/policies.js +63 -6
- package/esm/policies.js.map +1 -1
- package/esm/policy.d.ts +65 -269
- package/esm/policy.d.ts.map +1 -1
- package/esm/policy.js +1 -122
- package/esm/policy.js.map +1 -1
- package/esm/policyDefiners/defineCargoPolicy.d.ts +82 -0
- package/esm/policyDefiners/defineCargoPolicy.d.ts.map +1 -0
- package/esm/policyDefiners/defineCargoPolicy.js +42 -0
- package/esm/policyDefiners/defineCargoPolicy.js.map +1 -0
- package/esm/policyDefiners/defineFileHeaderPolicy.d.ts +27 -14
- package/esm/policyDefiners/defineFileHeaderPolicy.d.ts.map +1 -1
- package/esm/policyDefiners/defineFileHeaderPolicy.js +19 -39
- package/esm/policyDefiners/defineFileHeaderPolicy.js.map +1 -1
- package/esm/policyDefiners/defineGleamPolicy.d.ts +81 -0
- package/esm/policyDefiners/defineGleamPolicy.d.ts.map +1 -0
- package/esm/policyDefiners/defineGleamPolicy.js +42 -0
- package/esm/policyDefiners/defineGleamPolicy.js.map +1 -0
- package/esm/policyDefiners/definePackagePolicy.d.ts +24 -13
- package/esm/policyDefiners/definePackagePolicy.d.ts.map +1 -1
- package/esm/policyDefiners/definePackagePolicy.js +9 -32
- package/esm/policyDefiners/definePackagePolicy.js.map +1 -1
- package/esm/policyDefiners/spdxValidator.d.ts +66 -0
- package/esm/policyDefiners/spdxValidator.d.ts.map +1 -0
- package/esm/policyDefiners/spdxValidator.js +139 -0
- package/esm/policyDefiners/spdxValidator.js.map +1 -0
- package/esm/policyDefiners/tomlParser.d.ts +8 -0
- package/esm/policyDefiners/tomlParser.d.ts.map +1 -0
- package/esm/policyDefiners/tomlParser.js +17 -0
- package/esm/policyDefiners/tomlParser.js.map +1 -0
- package/esm/policyExecution.d.ts +19 -0
- package/esm/policyExecution.d.ts.map +1 -0
- package/esm/policyExecution.js +224 -0
- package/esm/policyExecution.js.map +1 -0
- package/esm/repositoryFiles.d.ts +4 -0
- package/esm/repositoryFiles.d.ts.map +1 -0
- package/esm/repositoryFiles.js +8 -0
- package/esm/repositoryFiles.js.map +1 -0
- package/esm/runner.d.ts +85 -0
- package/esm/runner.d.ts.map +1 -0
- package/esm/runner.js +189 -0
- package/esm/runner.js.map +1 -0
- package/esm/settlePolicyPromise.d.ts +4 -0
- package/esm/settlePolicyPromise.d.ts.map +1 -0
- package/esm/settlePolicyPromise.js +10 -0
- package/esm/settlePolicyPromise.js.map +1 -0
- package/esm/tsdoc-metadata.json +1 -1
- package/esm/utils/safePaths.d.ts +9 -0
- package/esm/utils/safePaths.d.ts.map +1 -0
- package/esm/utils/safePaths.js +40 -0
- package/esm/utils/safePaths.js.map +1 -0
- package/oclif.manifest.json +117 -3
- package/package.json +66 -36
- package/scripts/benchmark.mjs +341 -0
- package/scripts/postinstall.mjs +154 -0
- package/sidecar/sidecar.mjs +399 -0
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import jsonfile from "jsonfile";
|
|
2
|
+
import { resolve as resolvePath } from "pathe";
|
|
2
3
|
import { definePackagePolicy } from "../policyDefiners/definePackagePolicy.js";
|
|
3
4
|
const POLICY_NAME = "ExactScripts";
|
|
4
5
|
function validateScripts(scripts, expectedScripts) {
|
|
@@ -51,31 +52,32 @@ async function fixScripts(json, file, scriptsToFix, expectedScripts, existingScr
|
|
|
51
52
|
*
|
|
52
53
|
* @example
|
|
53
54
|
* ```typescript
|
|
54
|
-
* import {
|
|
55
|
+
* import { makePolicy } from "repopo";
|
|
55
56
|
* import { ExactScripts } from "repopo/policies";
|
|
56
57
|
*
|
|
57
|
-
*
|
|
58
|
+
* makePolicy(ExactScripts, { config: {
|
|
58
59
|
* scripts: {
|
|
59
60
|
* clean: "rimraf dist esm",
|
|
60
61
|
* format: "biome format --write .",
|
|
61
62
|
* lint: "biome lint .",
|
|
62
63
|
* },
|
|
63
|
-
* })
|
|
64
|
+
* } })
|
|
64
65
|
* ```
|
|
65
66
|
*
|
|
66
|
-
* @
|
|
67
|
+
* @public
|
|
67
68
|
*/
|
|
68
69
|
export const ExactScripts = definePackagePolicy({
|
|
70
|
+
requiresConfig: true,
|
|
69
71
|
name: POLICY_NAME,
|
|
70
72
|
description: "Validates that scripts exist and have exact content in package.json.",
|
|
71
|
-
handler: async (json, { file, resolve, config }) => {
|
|
73
|
+
handler: async (json, { file, root, resolve, config }) => {
|
|
72
74
|
if (config === undefined || Object.keys(config.scripts).length === 0) {
|
|
73
|
-
return
|
|
75
|
+
return [];
|
|
74
76
|
}
|
|
75
77
|
const scripts = json.scripts ?? {};
|
|
76
78
|
const validation = validateScripts(scripts, config.scripts);
|
|
77
79
|
if (validation.errors.length === 0) {
|
|
78
|
-
return
|
|
80
|
+
return [];
|
|
79
81
|
}
|
|
80
82
|
const scriptsToFix = [
|
|
81
83
|
...validation.missingScripts,
|
|
@@ -84,24 +86,20 @@ export const ExactScripts = definePackagePolicy({
|
|
|
84
86
|
const hasAutoFixableErrors = scriptsToFix.length > 0;
|
|
85
87
|
if (resolve && hasAutoFixableErrors) {
|
|
86
88
|
try {
|
|
87
|
-
const fixedScripts = await fixScripts(json, file, scriptsToFix, config.scripts, scripts);
|
|
88
|
-
return {
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
errorMessages: [`Fixed scripts: ${fixedScripts.join(", ")}`],
|
|
93
|
-
};
|
|
89
|
+
const fixedScripts = await fixScripts(json, resolvePath(root, file), scriptsToFix, config.scripts, scripts);
|
|
90
|
+
return [`Fixed scripts: ${fixedScripts.join(", ")}`].map((message) => ({
|
|
91
|
+
message,
|
|
92
|
+
fixStatus: "fixed",
|
|
93
|
+
}));
|
|
94
94
|
}
|
|
95
95
|
catch {
|
|
96
96
|
// Fall through to return regular failure
|
|
97
97
|
}
|
|
98
98
|
}
|
|
99
|
-
return {
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
errorMessages: validation.errors,
|
|
104
|
-
};
|
|
99
|
+
return validation.errors.map((message) => ({
|
|
100
|
+
message,
|
|
101
|
+
fixStatus: hasAutoFixableErrors ? "available" : undefined,
|
|
102
|
+
}));
|
|
105
103
|
},
|
|
106
104
|
});
|
|
107
105
|
//# sourceMappingURL=ExactScripts.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ExactScripts.js","sourceRoot":"","sources":["../../src/policies/ExactScripts.ts"],"names":[],"mappings":"AAAA,OAAO,QAAQ,MAAM,UAAU,CAAC;
|
|
1
|
+
{"version":3,"file":"ExactScripts.js","sourceRoot":"","sources":["../../src/policies/ExactScripts.ts"],"names":[],"mappings":"AAAA,OAAO,QAAQ,MAAM,UAAU,CAAC;AAChC,OAAO,EAAE,OAAO,IAAI,WAAW,EAAE,MAAM,OAAO,CAAC;AAE/C,OAAO,EAAE,mBAAmB,EAAE,MAAM,0CAA0C,CAAC;AA2B/E,MAAM,WAAW,GAAG,cAAc,CAAC;AAQnC,SAAS,eAAe,CACvB,OAA2C,EAC3C,eAAuC;IAEvC,MAAM,MAAM,GAAa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;YACrC,IAAI,CAAC;gBACJ,MAAM,YAAY,GAAG,MAAM,UAAU,CACpC,IAAI,EACJ,WAAW,CAAC,IAAI,EAAE,IAAI,CAAC,EACvB,YAAY,EACZ,MAAM,CAAC,OAAO,EACd,OAAO,CACP,CAAC;gBACF,OAAO,CAAC,kBAAkB,YAAY,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC;oBACtE,OAAO;oBACP,SAAS,EAAE,OAAO;iBAClB,CAAC,CAAC,CAAC;YACL,CAAC;YAAC,MAAM,CAAC;gBACR,yCAAyC;YAC1C,CAAC;QACF,CAAC;QACD,OAAO,UAAU,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC;YAC1C,OAAO;YACP,SAAS,EAAE,oBAAoB,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,SAAS;SACzD,CAAC,CAAC,CAAC;IACL,CAAC;CACD,CAAC,CAAC","sourcesContent":["import jsonfile from \"jsonfile\";\nimport { resolve as resolvePath } from \"pathe\";\nimport type { PackageJson } from \"type-fest\";\nimport { definePackagePolicy } from \"../policyDefiners/definePackagePolicy.js\";\n\n/**\n * Configuration for the ExactScripts policy.\n *\n * @public\n */\nexport interface ExactScriptsConfig {\n\t/**\n\t * Scripts that must exist AND have exact content.\n\t *\n\t * @remarks\n\t * Unlike RequiredScripts, scripts in `exact` are validated against\n\t * the specified value. If a script exists but has different content, it fails validation.\n\t * Both missing and mismatched scripts are auto-fixable.\n\t *\n\t * @example\n\t * ```typescript\n\t * scripts: {\n\t * clean: \"rimraf dist esm\",\n\t * format: \"biome format --write .\",\n\t * }\n\t * ```\n\t */\n\tscripts: Record<string, string>;\n}\n\nconst POLICY_NAME = \"ExactScripts\";\n\ninterface ValidationResult {\n\terrors: string[];\n\tmissingScripts: string[];\n\tmismatchedScripts: string[];\n}\n\nfunction validateScripts(\n\tscripts: Record<string, string | undefined>,\n\texpectedScripts: Record<string, string>,\n): ValidationResult {\n\tconst errors: string[] = [];\n\tconst missingScripts: string[] = [];\n\tconst mismatchedScripts: string[] = [];\n\n\tfor (const [scriptName, expectedValue] of Object.entries(expectedScripts)) {\n\t\tif (Object.hasOwn(scripts, scriptName)) {\n\t\t\tconst actualValue = scripts[scriptName];\n\t\t\tif (actualValue !== expectedValue) {\n\t\t\t\tmismatchedScripts.push(scriptName);\n\t\t\t\terrors.push(\n\t\t\t\t\t`Script \"${scriptName}\" must be \"${expectedValue}\", but found \"${actualValue}\"`,\n\t\t\t\t);\n\t\t\t}\n\t\t} else {\n\t\t\tmissingScripts.push(scriptName);\n\t\t\terrors.push(`Missing required script: ${scriptName}`);\n\t\t}\n\t}\n\n\treturn { errors, missingScripts, mismatchedScripts };\n}\n\nasync function fixScripts(\n\tjson: PackageJson,\n\tfile: string,\n\tscriptsToFix: string[],\n\texpectedScripts: Record<string, string>,\n\texistingScripts: Record<string, string | undefined>,\n): Promise<string[]> {\n\tconst updatedScripts: Record<string, string> = {};\n\n\t// Copy existing scripts\n\tfor (const [key, value] of Object.entries(existingScripts)) {\n\t\tif (value !== undefined) {\n\t\t\tupdatedScripts[key] = value;\n\t\t}\n\t}\n\n\t// Add/update scripts\n\tconst fixedScripts: string[] = [];\n\tfor (const scriptName of scriptsToFix) {\n\t\tconst expectedValue = expectedScripts[scriptName];\n\t\tif (expectedValue !== undefined) {\n\t\t\tupdatedScripts[scriptName] = expectedValue;\n\t\t\tfixedScripts.push(scriptName);\n\t\t}\n\t}\n\n\tawait jsonfile.writeFile(\n\t\tfile,\n\t\t{ ...json, scripts: updatedScripts },\n\t\t{ spaces: 2 },\n\t);\n\n\treturn fixedScripts;\n}\n\n/**\n * A policy that validates scripts exist AND have exact content in package.json.\n *\n * @remarks\n * Use this policy when you want to enforce exact script content, not just presence.\n * This is useful for scripts that must be exactly the same across packages.\n *\n * For scripts where you only care about presence (not content), use RequiredScripts instead.\n *\n * @example\n * ```typescript\n * import { makePolicy } from \"repopo\";\n * import { ExactScripts } from \"repopo/policies\";\n *\n * makePolicy(ExactScripts, { config: {\n * scripts: {\n * clean: \"rimraf dist esm\",\n * format: \"biome format --write .\",\n * lint: \"biome lint .\",\n * },\n * } })\n * ```\n *\n * @public\n */\nexport const ExactScripts = definePackagePolicy<\n\tPackageJson,\n\tExactScriptsConfig | undefined\n>({\n\trequiresConfig: true,\n\tname: POLICY_NAME,\n\tdescription:\n\t\t\"Validates that scripts exist and have exact content in package.json.\",\n\thandler: async (json, { file, root, resolve, config }) => {\n\t\tif (config === undefined || Object.keys(config.scripts).length === 0) {\n\t\t\treturn [];\n\t\t}\n\n\t\tconst scripts = json.scripts ?? {};\n\t\tconst validation = validateScripts(scripts, config.scripts);\n\n\t\tif (validation.errors.length === 0) {\n\t\t\treturn [];\n\t\t}\n\n\t\tconst scriptsToFix = [\n\t\t\t...validation.missingScripts,\n\t\t\t...validation.mismatchedScripts,\n\t\t];\n\t\tconst hasAutoFixableErrors = scriptsToFix.length > 0;\n\n\t\tif (resolve && hasAutoFixableErrors) {\n\t\t\ttry {\n\t\t\t\tconst fixedScripts = await fixScripts(\n\t\t\t\t\tjson,\n\t\t\t\t\tresolvePath(root, file),\n\t\t\t\t\tscriptsToFix,\n\t\t\t\t\tconfig.scripts,\n\t\t\t\t\tscripts,\n\t\t\t\t);\n\t\t\t\treturn [`Fixed scripts: ${fixedScripts.join(\", \")}`].map((message) => ({\n\t\t\t\t\tmessage,\n\t\t\t\t\tfixStatus: \"fixed\",\n\t\t\t\t}));\n\t\t\t} catch {\n\t\t\t\t// Fall through to return regular failure\n\t\t\t}\n\t\t}\n\t\treturn validation.errors.map((message) => ({\n\t\t\tmessage,\n\t\t\tfixStatus: hasAutoFixableErrors ? \"available\" : undefined,\n\t\t}));\n\t},\n});\n"]}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { FilePolicyDefinition } from "../policy.js";
|
|
2
|
+
/**
|
|
3
|
+
* Configuration for the GleamDepVersions policy.
|
|
4
|
+
*
|
|
5
|
+
* @public
|
|
6
|
+
*/
|
|
7
|
+
export interface GleamDepVersionsConfig {
|
|
8
|
+
/**
|
|
9
|
+
* If true, require all dependencies to have version constraints.
|
|
10
|
+
* @defaultValue true
|
|
11
|
+
*/
|
|
12
|
+
requireVersions?: boolean;
|
|
13
|
+
/**
|
|
14
|
+
* If true, warn on unbounded version ranges (e.g., `">= 1.0.0"` without an upper bound).
|
|
15
|
+
* @defaultValue false
|
|
16
|
+
*/
|
|
17
|
+
warnUnbounded?: boolean;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* A policy that prevents missing or overly loose version constraints in Gleam dependencies.
|
|
21
|
+
*
|
|
22
|
+
* @public
|
|
23
|
+
*/
|
|
24
|
+
export declare const GleamDepVersions: FilePolicyDefinition<GleamDepVersionsConfig>;
|
|
25
|
+
//# sourceMappingURL=GleamDepVersions.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"GleamDepVersions.d.ts","sourceRoot":"","sources":["../../src/policies/GleamDepVersions.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,cAAc,CAAC;AAMzD;;;;GAIG;AACH,MAAM,WAAW,sBAAsB;IACtC;;;OAGG;IACH,eAAe,CAAC,EAAE,OAAO,CAAC;IAE1B;;;OAGG;IACH,aAAa,CAAC,EAAE,OAAO,CAAC;CACxB;AAkDD;;;;GAIG;AACH,eAAO,MAAM,gBAAgB,8CAoC4B,CAAC"}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { defineGleamPolicy, } from "../policyDefiners/defineGleamPolicy.js";
|
|
2
|
+
function extractVersion(dep) {
|
|
3
|
+
if (typeof dep === "string") {
|
|
4
|
+
return dep;
|
|
5
|
+
}
|
|
6
|
+
if (typeof dep === "object" && dep !== null) {
|
|
7
|
+
const record = dep;
|
|
8
|
+
if (typeof record.version === "string") {
|
|
9
|
+
return record.version;
|
|
10
|
+
}
|
|
11
|
+
// Path-only dependencies don't need version checks
|
|
12
|
+
if (typeof record.path === "string") {
|
|
13
|
+
return undefined;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
return undefined;
|
|
17
|
+
}
|
|
18
|
+
function checkSection(sectionName, deps, requireVersions, warnUnbounded) {
|
|
19
|
+
const errors = [];
|
|
20
|
+
for (const [name, value] of Object.entries(deps)) {
|
|
21
|
+
const version = extractVersion(value);
|
|
22
|
+
if (requireVersions && version === undefined) {
|
|
23
|
+
// Skip path dependencies
|
|
24
|
+
if (typeof value === "object" &&
|
|
25
|
+
value !== null &&
|
|
26
|
+
typeof value.path === "string") {
|
|
27
|
+
continue;
|
|
28
|
+
}
|
|
29
|
+
errors.push(`[${sectionName}] "${name}" has no version constraint`);
|
|
30
|
+
}
|
|
31
|
+
if (warnUnbounded && version !== undefined && version.startsWith(">=")) {
|
|
32
|
+
errors.push(`[${sectionName}] "${name}" = "${version}" uses an unbounded version range`);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
return errors;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* A policy that prevents missing or overly loose version constraints in Gleam dependencies.
|
|
39
|
+
*
|
|
40
|
+
* @public
|
|
41
|
+
*/
|
|
42
|
+
export const GleamDepVersions = defineGleamPolicy({
|
|
43
|
+
name: "GleamDepVersions",
|
|
44
|
+
description: "Prevents missing or overly loose version constraints in gleam.toml dependencies.",
|
|
45
|
+
handler: async (toml, { config }) => {
|
|
46
|
+
const requireVersions = config?.requireVersions ?? true;
|
|
47
|
+
const warnUnbounded = config?.warnUnbounded ?? false;
|
|
48
|
+
const errors = [];
|
|
49
|
+
const sections = [
|
|
50
|
+
{ name: "dependencies", data: toml.dependencies },
|
|
51
|
+
{ name: "dev-dependencies", data: toml["dev-dependencies"] },
|
|
52
|
+
];
|
|
53
|
+
for (const { name, data } of sections) {
|
|
54
|
+
if (data && typeof data === "object") {
|
|
55
|
+
errors.push(...checkSection(name, data, requireVersions, warnUnbounded));
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
if (errors.length > 0) {
|
|
59
|
+
return errors.map((message) => ({
|
|
60
|
+
message,
|
|
61
|
+
manualFix: 'Add specific version constraints (e.g., ">= 1.0.0 and < 2.0.0") to all dependencies.',
|
|
62
|
+
}));
|
|
63
|
+
}
|
|
64
|
+
return [];
|
|
65
|
+
},
|
|
66
|
+
});
|
|
67
|
+
//# sourceMappingURL=GleamDepVersions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"GleamDepVersions.js","sourceRoot":"","sources":["../../src/policies/GleamDepVersions.ts"],"names":[],"mappings":"AACA,OAAO,EACN,iBAAiB,GAEjB,MAAM,wCAAwC,CAAC;AAqBhD,SAAS,cAAc,CAAC,GAAY;IACnC,IAAI,OAAO,GAAG,KAAK,QAAQ,EAAE,CAAC;QAC7B,OAAO,GAAG,CAAC;IACZ,CAAC;IACD,IAAI,OAAO,GAAG,KAAK,QAAQ,IAAI,GAAG,KAAK,IAAI,EAAE,CAAC;QAC7C,MAAM,MAAM,GAAG,GAA8B,CAAC;QAC9C,IAAI,OAAO,MAAM,CAAC,OAAO,KAAK,QAAQ,EAAE,CAAC;YACxC,OAAO,MAAM,CAAC,OAAO,CAAC;QACvB,CAAC;QACD,mDAAmD;QACnD,IAAI,OAAO,MAAM,CAAC,IAAI,KAAK,QAAQ,EAAE,CAAC;YACrC,OAAO,SAAS,CAAC;QAClB,CAAC;IACF,CAAC;IACD,OAAO,SAAS,CAAC;AAClB,CAAC;AAED,SAAS,YAAY,CACpB,WAAmB,EACnB,IAA6B,EAC7B,eAAwB,EACxB,aAAsB;IAEtB,MAAM,MAAM,GAAa,EAAE,CAAC;IAC5B,KAAK,MAAM,CAAC,IAAI,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,CAAC;QAClD,MAAM,OAAO,GAAG,cAAc,CAAC,K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gBACtC,MAAM,CAAC,IAAI,CACV,GAAG,YAAY,CACd,IAAI,EACJ,IAA+B,EAC/B,eAAe,EACf,aAAa,CACb,CACD,CAAC;YACH,CAAC;QACF,CAAC;QAED,IAAI,MAAM,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YACvB,OAAO,MAAM,CAAC,GAAG,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC;gBAC/B,OAAO;gBACP,SAAS,EACR,sFAAsF;aACvF,CAAC,CAAC,CAAC;QACL,CAAC;QACD,OAAO,EAAE,CAAC;IACX,CAAC;CACD,CAAwD,CAAC","sourcesContent":["import type { FilePolicyDefinition } from \"../policy.js\";\nimport {\n\tdefineGleamPolicy,\n\ttype GleamToml,\n} from \"../policyDefiners/defineGleamPolicy.js\";\n\n/**\n * Configuration for the GleamDepVersions policy.\n *\n * @public\n */\nexport interface GleamDepVersionsConfig {\n\t/**\n\t * If true, require all dependencies to have version constraints.\n\t * @defaultValue true\n\t */\n\trequireVersions?: boolean;\n\n\t/**\n\t * If true, warn on unbounded version ranges (e.g., `\">= 1.0.0\"` without an upper bound).\n\t * @defaultValue false\n\t */\n\twarnUnbounded?: boolean;\n}\n\nfunction extractVersion(dep: unknown): string | undefined {\n\tif (typeof dep === \"string\") {\n\t\treturn dep;\n\t}\n\tif (typeof dep === \"object\" && dep !== null) {\n\t\tconst record = dep as Record<string, unknown>;\n\t\tif (typeof record.version === \"string\") {\n\t\t\treturn record.version;\n\t\t}\n\t\t// Path-only dependencies don't need version checks\n\t\tif (typeof record.path === \"string\") {\n\t\t\treturn undefined;\n\t\t}\n\t}\n\treturn undefined;\n}\n\nfunction checkSection(\n\tsectionName: string,\n\tdeps: Record<string, unknown>,\n\trequireVersions: boolean,\n\twarnUnbounded: boolean,\n): string[] {\n\tconst errors: string[] = [];\n\tfor (const [name, value] of Object.entries(deps)) {\n\t\tconst version = extractVersion(value);\n\n\t\tif (requireVersions && version === undefined) {\n\t\t\t// Skip path dependencies\n\t\t\tif (\n\t\t\t\ttypeof value === \"object\" &&\n\t\t\t\tvalue !== null &&\n\t\t\t\ttypeof (value as Record<string, unknown>).path === \"string\"\n\t\t\t) {\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\terrors.push(`[${sectionName}] \"${name}\" has no version constraint`);\n\t\t}\n\n\t\tif (warnUnbounded && version !== undefined && version.startsWith(\">=\")) {\n\t\t\terrors.push(\n\t\t\t\t`[${sectionName}] \"${name}\" = \"${version}\" uses an unbounded version range`,\n\t\t\t);\n\t\t}\n\t}\n\treturn errors;\n}\n\n/**\n * A policy that prevents missing or overly loose version constraints in Gleam dependencies.\n *\n * @public\n */\nexport const GleamDepVersions = defineGleamPolicy({\n\tname: \"GleamDepVersions\",\n\tdescription:\n\t\t\"Prevents missing or overly loose version constraints in gleam.toml dependencies.\",\n\thandler: async (toml: GleamToml, { config }) => {\n\t\tconst requireVersions = config?.requireVersions ?? true;\n\t\tconst warnUnbounded = config?.warnUnbounded ?? false;\n\t\tconst errors: string[] = [];\n\n\t\tconst sections = [\n\t\t\t{ name: \"dependencies\", data: toml.dependencies },\n\t\t\t{ name: \"dev-dependencies\", data: toml[\"dev-dependencies\"] },\n\t\t];\n\n\t\tfor (const { name, data } of sections) {\n\t\t\tif (data && typeof data === \"object\") {\n\t\t\t\terrors.push(\n\t\t\t\t\t...checkSection(\n\t\t\t\t\t\tname,\n\t\t\t\t\t\tdata as Record<string, unknown>,\n\t\t\t\t\t\trequireVersions,\n\t\t\t\t\t\twarnUnbounded,\n\t\t\t\t\t),\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\n\t\tif (errors.length > 0) {\n\t\t\treturn errors.map((message) => ({\n\t\t\t\tmessage,\n\t\t\t\tmanualFix:\n\t\t\t\t\t'Add specific version constraints (e.g., \">= 1.0.0 and < 2.0.0\") to all dependencies.',\n\t\t\t}));\n\t\t}\n\t\treturn [];\n\t},\n}) satisfies FilePolicyDefinition<GleamDepVersionsConfig>;\n"]}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { FilePolicyDefinition } from "../policy.js";
|
|
2
|
+
/**
|
|
3
|
+
* Configuration for the GleamDocExists policy.
|
|
4
|
+
*
|
|
5
|
+
* @public
|
|
6
|
+
*/
|
|
7
|
+
export interface GleamDocExistsConfig {
|
|
8
|
+
/**
|
|
9
|
+
* Files that must exist alongside the gleam.toml.
|
|
10
|
+
* @defaultValue ["README.md"]
|
|
11
|
+
*/
|
|
12
|
+
required?: string[];
|
|
13
|
+
/**
|
|
14
|
+
* Files that are recommended but not required. Missing ones produce warnings.
|
|
15
|
+
*/
|
|
16
|
+
recommended?: string[];
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* A policy that validates documentation files exist for Gleam packages.
|
|
20
|
+
*
|
|
21
|
+
* @public
|
|
22
|
+
*/
|
|
23
|
+
export declare const GleamDocExists: FilePolicyDefinition<GleamDocExistsConfig>;
|
|
24
|
+
//# sourceMappingURL=GleamDocExists.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"GleamDocExists.d.ts","sourceRoot":"","sources":["../../src/policies/GleamDocExists.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,cAAc,CAAC;AAMzD;;;;GAIG;AACH,MAAM,WAAW,oBAAoB;IACpC;;;OAGG;IACH,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAC;IAEpB;;OAEG;IACH,WAAW,CAAC,EAAE,MAAM,EAAE,CAAC;CACvB;AAID;;;;GAIG;AACH,eAAO,MAAM,cAAc,4CA0C4B,CAAC"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { existsSync } from "node:fs";
|
|
2
|
+
import path from "pathe";
|
|
3
|
+
import { defineGleamPolicy, } from "../policyDefiners/defineGleamPolicy.js";
|
|
4
|
+
const DEFAULT_REQUIRED = ["README.md"];
|
|
5
|
+
/**
|
|
6
|
+
* A policy that validates documentation files exist for Gleam packages.
|
|
7
|
+
*
|
|
8
|
+
* @public
|
|
9
|
+
*/
|
|
10
|
+
export const GleamDocExists = defineGleamPolicy({
|
|
11
|
+
name: "GleamDocExists",
|
|
12
|
+
description: "Validates that documentation files (README.md, etc.) exist for Gleam packages.",
|
|
13
|
+
handler: async (toml, { file, root, config }) => {
|
|
14
|
+
// Skip if the package looks like it's not for publishing
|
|
15
|
+
if (!(toml.description || toml.licences)) {
|
|
16
|
+
return [];
|
|
17
|
+
}
|
|
18
|
+
const dir = path.dirname(path.resolve(root, file));
|
|
19
|
+
const required = config?.required ?? DEFAULT_REQUIRED;
|
|
20
|
+
const recommended = config?.recommended ?? [];
|
|
21
|
+
const errors = [];
|
|
22
|
+
const missingRequired = required.filter((f) => !existsSync(path.join(dir, f)));
|
|
23
|
+
const missingRecommended = recommended.filter((f) => !existsSync(path.join(dir, f)));
|
|
24
|
+
if (missingRequired.length > 0) {
|
|
25
|
+
errors.push(`Missing required documentation: ${missingRequired.join(", ")}`);
|
|
26
|
+
}
|
|
27
|
+
if (missingRecommended.length > 0) {
|
|
28
|
+
errors.push(`Missing recommended documentation: ${missingRecommended.join(", ")}`);
|
|
29
|
+
}
|
|
30
|
+
if (errors.length > 0) {
|
|
31
|
+
return errors.map((message) => ({
|
|
32
|
+
message,
|
|
33
|
+
manualFix: "Create the missing documentation files alongside gleam.toml.",
|
|
34
|
+
}));
|
|
35
|
+
}
|
|
36
|
+
return [];
|
|
37
|
+
},
|
|
38
|
+
});
|
|
39
|
+
//# sourceMappingURL=GleamDocExists.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"GleamDocExists.js","sourceRoot":"","sources":["../../src/policies/GleamDocExists.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AACrC,OAAO,IAAI,MAAM,OAAO,CAAC;AAEzB,OAAO,EACN,iBAAiB,GAEjB,MAAM,wCAAwC,CAAC;AAoBhD,MAAM,gBAAgB,GAAG,CAAC,WAAW,C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,CAAC,IAAI,CAAC,EAAE,CACrE,CAAC;QACH,CAAC;QAED,IAAI,MAAM,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YACvB,OAAO,MAAM,CAAC,GAAG,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC;gBAC/B,OAAO;gBACP,SAAS,EACR,8DAA8D;aAC/D,CAAC,CAAC,CAAC;QACL,CAAC;QACD,OAAO,EAAE,CAAC;IACX,CAAC;CACD,CAAsD,CAAC","sourcesContent":["import { existsSync } from \"node:fs\";\nimport path from \"pathe\";\nimport type { FilePolicyDefinition } from \"../policy.js\";\nimport {\n\tdefineGleamPolicy,\n\ttype GleamToml,\n} from \"../policyDefiners/defineGleamPolicy.js\";\n\n/**\n * Configuration for the GleamDocExists policy.\n *\n * @public\n */\nexport interface GleamDocExistsConfig {\n\t/**\n\t * Files that must exist alongside the gleam.toml.\n\t * @defaultValue [\"README.md\"]\n\t */\n\trequired?: string[];\n\n\t/**\n\t * Files that are recommended but not required. Missing ones produce warnings.\n\t */\n\trecommended?: string[];\n}\n\nconst DEFAULT_REQUIRED = [\"README.md\"];\n\n/**\n * A policy that validates documentation files exist for Gleam packages.\n *\n * @public\n */\nexport const GleamDocExists = defineGleamPolicy({\n\tname: \"GleamDocExists\",\n\tdescription:\n\t\t\"Validates that documentation files (README.md, etc.) exist for Gleam packages.\",\n\thandler: async (toml: GleamToml, { file, root, config }) => {\n\t\t// Skip if the package looks like it's not for publishing\n\t\tif (!(toml.description || toml.licences)) {\n\t\t\treturn [];\n\t\t}\n\n\t\tconst dir = path.dirname(path.resolve(root, file));\n\t\tconst required = config?.required ?? DEFAULT_REQUIRED;\n\t\tconst recommended = config?.recommended ?? [];\n\t\tconst errors: string[] = [];\n\n\t\tconst missingRequired = required.filter(\n\t\t\t(f) => !existsSync(path.join(dir, f)),\n\t\t);\n\t\tconst missingRecommended = recommended.filter(\n\t\t\t(f) => !existsSync(path.join(dir, f)),\n\t\t);\n\n\t\tif (missingRequired.length > 0) {\n\t\t\terrors.push(\n\t\t\t\t`Missing required documentation: ${missingRequired.join(\", \")}`,\n\t\t\t);\n\t\t}\n\t\tif (missingRecommended.length > 0) {\n\t\t\terrors.push(\n\t\t\t\t`Missing recommended documentation: ${missingRecommended.join(\", \")}`,\n\t\t\t);\n\t\t}\n\n\t\tif (errors.length > 0) {\n\t\t\treturn errors.map((message) => ({\n\t\t\t\tmessage,\n\t\t\t\tmanualFix:\n\t\t\t\t\t\"Create the missing documentation files alongside gleam.toml.\",\n\t\t\t}));\n\t\t}\n\t\treturn [];\n\t},\n}) satisfies FilePolicyDefinition<GleamDocExistsConfig>;\n"]}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { FilePolicyDefinition } from "../policy.js";
|
|
2
|
+
/**
|
|
3
|
+
* Configuration for the GleamInternalModulesConfigured policy.
|
|
4
|
+
*
|
|
5
|
+
* @public
|
|
6
|
+
*/
|
|
7
|
+
export interface GleamInternalModulesConfiguredConfig {
|
|
8
|
+
/**
|
|
9
|
+
* If true, suggest common internal_modules patterns when the field is missing.
|
|
10
|
+
* @defaultValue true
|
|
11
|
+
*/
|
|
12
|
+
suggestPatterns?: boolean;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* A policy that ensures `internal_modules` is configured in gleam.toml
|
|
16
|
+
* to hide implementation details from generated documentation.
|
|
17
|
+
*
|
|
18
|
+
* @public
|
|
19
|
+
*/
|
|
20
|
+
export declare const GleamInternalModulesConfigured: FilePolicyDefinition<GleamInternalModulesConfiguredConfig>;
|
|
21
|
+
//# sourceMappingURL=GleamInternalModulesConfigured.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"GleamInternalModulesConfigured.d.ts","sourceRoot":"","sources":["../../src/policies/GleamInternalModulesConfigured.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,cAAc,CAAC;AAMzD;;;;GAIG;AACH,MAAM,WAAW,oCAAoC;IACpD;;;OAGG;IACH,eAAe,CAAC,EAAE,OAAO,CAAC;CAC1B;AAED;;;;;GAKG;AACH,eAAO,MAAM,8BAA8B,4DA+B4B,CAAC"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { defineGleamPolicy, } from "../policyDefiners/defineGleamPolicy.js";
|
|
2
|
+
/**
|
|
3
|
+
* A policy that ensures `internal_modules` is configured in gleam.toml
|
|
4
|
+
* to hide implementation details from generated documentation.
|
|
5
|
+
*
|
|
6
|
+
* @public
|
|
7
|
+
*/
|
|
8
|
+
export const GleamInternalModulesConfigured = defineGleamPolicy({
|
|
9
|
+
name: "GleamInternalModulesConfigured",
|
|
10
|
+
description: "Ensures internal_modules is configured in gleam.toml to hide implementation details from docs.",
|
|
11
|
+
handler: async (toml, { config }) => {
|
|
12
|
+
const internalModules = toml.internal_modules;
|
|
13
|
+
if (internalModules !== undefined &&
|
|
14
|
+
Array.isArray(internalModules) &&
|
|
15
|
+
internalModules.length > 0) {
|
|
16
|
+
return [];
|
|
17
|
+
}
|
|
18
|
+
const name = toml.name;
|
|
19
|
+
const suggestPatterns = config?.suggestPatterns ?? true;
|
|
20
|
+
let manualFix = "Add an internal_modules field to gleam.toml to hide implementation details from docs.";
|
|
21
|
+
if (suggestPatterns && name) {
|
|
22
|
+
manualFix = `Add to gleam.toml:\ninternal_modules = ["${name}/internal", "${name}/internal/*"]`;
|
|
23
|
+
}
|
|
24
|
+
return [
|
|
25
|
+
{
|
|
26
|
+
message: "Missing internal_modules configuration in gleam.toml. Published packages should hide internal modules from documentation.",
|
|
27
|
+
manualFix: manualFix,
|
|
28
|
+
},
|
|
29
|
+
];
|
|
30
|
+
},
|
|
31
|
+
});
|
|
32
|
+
//# sourceMappingURL=GleamInternalModulesConfigured.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"GleamInternalModulesConfigured.js","sourceRoot":"","sources":["../../src/policies/GleamInternalModulesConfigured.ts"],"names":[],"mappings":"AACA,OAAO,EACN,iBAAiB,GAEjB,MAAM,wCAAwC,CAAC;AAehD;;;;;GAKG;AACH,MAAM,CAAC,MAAM,8BAA8B,GAAG,iBAAiB,CAAC;IAC/D,IAAI,EAAE,gCAAgC;IACtC,WAAW,EACV,gGAAgG;IACjG,OAAO,EAAE,KAAK,EAAE,IAAe,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE;QAC9C,MAAM,eAAe,GAAG,IAAI,CAAC,gBAAwC,CAAC;QAEtE,IACC,eAAe,KAAK,SAAS;YAC7B,KAAK,CAAC,OAAO,CAAC,eAAe,CAAC;YAC9B,eAAe,CAAC,MAAM,GAAG,CAAC,EACzB,CAAC;YACF,OAAO,EAAE,CAAC;QACX,CAAC;QAED,MAAM,IAAI,GAAG,IAAI,CAAC,IAA0B,CAAC;QAC7C,MAAM,eAAe,GAAG,MAAM,EAAE,eAAe,IAAI,IAAI,CAAC;QAExD,IAAI,SAAS,GACZ,uFAAuF,CAAC;QACzF,IAAI,eAAe,IAAI,IAAI,EAAE,CAAC;YAC7B,SAAS,GAAG,4CAA4C,IAAI,gBAAgB,IAAI,eAAe,CAAC;QACjG,CAAC;QACD,OAAO;YACN;gBACC,OAAO,EACN,2HAA2H;gBAC5H,SAAS,EAAE,SAAS;aACpB;SACD,CAAC;IACH,CAAC;CACD,CAAsE,CAAC","sourcesContent":["import type { FilePolicyDefinition } from \"../policy.js\";\nimport {\n\tdefineGleamPolicy,\n\ttype GleamToml,\n} from \"../policyDefiners/defineGleamPolicy.js\";\n\n/**\n * Configuration for the GleamInternalModulesConfigured policy.\n *\n * @public\n */\nexport interface GleamInternalModulesConfiguredConfig {\n\t/**\n\t * If true, suggest common internal_modules patterns when the field is missing.\n\t * @defaultValue true\n\t */\n\tsuggestPatterns?: boolean;\n}\n\n/**\n * A policy that ensures `internal_modules` is configured in gleam.toml\n * to hide implementation details from generated documentation.\n *\n * @public\n */\nexport const GleamInternalModulesConfigured = defineGleamPolicy({\n\tname: \"GleamInternalModulesConfigured\",\n\tdescription:\n\t\t\"Ensures internal_modules is configured in gleam.toml to hide implementation details from docs.\",\n\thandler: async (toml: GleamToml, { config }) => {\n\t\tconst internalModules = toml.internal_modules as string[] | undefined;\n\n\t\tif (\n\t\t\tinternalModules !== undefined &&\n\t\t\tArray.isArray(internalModules) &&\n\t\t\tinternalModules.length > 0\n\t\t) {\n\t\t\treturn [];\n\t\t}\n\n\t\tconst name = toml.name as string | undefined;\n\t\tconst suggestPatterns = config?.suggestPatterns ?? true;\n\n\t\tlet manualFix =\n\t\t\t\"Add an internal_modules field to gleam.toml to hide implementation details from docs.\";\n\t\tif (suggestPatterns && name) {\n\t\t\tmanualFix = `Add to gleam.toml:\\ninternal_modules = [\"${name}/internal\", \"${name}/internal/*\"]`;\n\t\t}\n\t\treturn [\n\t\t\t{\n\t\t\t\tmessage:\n\t\t\t\t\t\"Missing internal_modules configuration in gleam.toml. Published packages should hide internal modules from documentation.\",\n\t\t\t\tmanualFix: manualFix,\n\t\t\t},\n\t\t];\n\t},\n}) satisfies FilePolicyDefinition<GleamInternalModulesConfiguredConfig>;\n"]}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { FilePolicyDefinition } from "../policy.js";
|
|
2
|
+
/**
|
|
3
|
+
* Configuration for the GleamLicenceConfigured policy.
|
|
4
|
+
*
|
|
5
|
+
* @public
|
|
6
|
+
*/
|
|
7
|
+
export interface GleamLicenceConfiguredConfig {
|
|
8
|
+
/**
|
|
9
|
+
* Allowed SPDX licence identifiers. If set, only these are accepted.
|
|
10
|
+
*/
|
|
11
|
+
allowedLicences?: string[];
|
|
12
|
+
/**
|
|
13
|
+
* If true, validate licence values against the SPDX licence list
|
|
14
|
+
* using `spdx-correct`. When enabled, typos like "MIIT" are detected
|
|
15
|
+
* and can be auto-fixed to the correct identifier ("MIT").
|
|
16
|
+
*
|
|
17
|
+
* Requires the optional peer dependency `spdx-correct` to be installed.
|
|
18
|
+
*
|
|
19
|
+
* @defaultValue false
|
|
20
|
+
*/
|
|
21
|
+
validateSpdx?: boolean;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* A policy that ensures licence metadata is properly configured in gleam.toml.
|
|
25
|
+
*
|
|
26
|
+
* @public
|
|
27
|
+
*/
|
|
28
|
+
export declare const GleamLicenceConfigured: FilePolicyDefinition<GleamLicenceConfiguredConfig>;
|
|
29
|
+
//# sourceMappingURL=GleamLicenceConfigured.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"GleamLicenceConfigured.d.ts","sourceRoot":"","sources":["../../src/policies/GleamLicenceConfigured.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,cAAc,CAAC;AAOzD;;;;GAIG;AACH,MAAM,WAAW,4BAA4B;IAC5C;;OAEG;IACH,eAAe,CAAC,EAAE,MAAM,EAAE,CAAC;IAE3B;;;;;;;;OAQG;IACH,YAAY,CAAC,EAAE,OAAO,CAAC;CACvB;AAKD;;;;GAIG;AACH,eAAO,MAAM,sBAAsB,oDAgC4B,CAAC"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { resolve } from "pathe";
|
|
2
|
+
import { defineGleamPolicy, } from "../policyDefiners/defineGleamPolicy.js";
|
|
3
|
+
import { validateLicenceField } from "../policyDefiners/spdxValidator.js";
|
|
4
|
+
const MANUAL_FIX = "Use valid SPDX licence identifiers (e.g., MIT, Apache-2.0, MPL-2.0).";
|
|
5
|
+
/**
|
|
6
|
+
* A policy that ensures licence metadata is properly configured in gleam.toml.
|
|
7
|
+
*
|
|
8
|
+
* @public
|
|
9
|
+
*/
|
|
10
|
+
export const GleamLicenceConfigured = defineGleamPolicy({
|
|
11
|
+
name: "GleamLicenceConfigured",
|
|
12
|
+
description: "Ensures gleam.toml has valid SPDX licence identifiers configured.",
|
|
13
|
+
handler: async (toml, { file, root, resolve: shouldResolve, config }) => {
|
|
14
|
+
const licences = toml.licences;
|
|
15
|
+
if (!Array.isArray(licences) || licences.length === 0) {
|
|
16
|
+
return [
|
|
17
|
+
{
|
|
18
|
+
message: "Missing or empty licences field in gleam.toml.",
|
|
19
|
+
manualFix: 'Add licences = ["MIT"] (or appropriate SPDX identifier) to gleam.toml.',
|
|
20
|
+
},
|
|
21
|
+
];
|
|
22
|
+
}
|
|
23
|
+
const result = await validateLicenceField({
|
|
24
|
+
licences: licences,
|
|
25
|
+
...(config?.allowedLicences !== undefined && {
|
|
26
|
+
allowedLicences: config.allowedLicences,
|
|
27
|
+
}),
|
|
28
|
+
validateSpdx: config?.validateSpdx ?? false,
|
|
29
|
+
shouldResolve,
|
|
30
|
+
filePath: resolve(root, file),
|
|
31
|
+
manualFixMessage: MANUAL_FIX,
|
|
32
|
+
});
|
|
33
|
+
return result;
|
|
34
|
+
},
|
|
35
|
+
});
|
|
36
|
+
//# sourceMappingURL=GleamLicenceConfigured.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"GleamLicenceConfigured.js","sourceRoot":"","sources":["../../src/policies/GleamLicenceConfigured.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,OAAO,CAAC;AAEhC,OAAO,EACN,iBAAiB,GAEjB,MAAM,wCAAwC,CAAC;AAChD,OAAO,EAAE,oBAAoB,EAAE,MAAM,oCAAoC,CAAC;AAyB1E,MAAM,UAAU,GACf,sEAAsE,CAAC;AAExE;;;;GAIG;AACH,MAAM,CAAC,MAAM,sBAAsB,GAAG,iBAAiB,CAAC;IACvD,IAAI,EAAE,wBAAwB;IAC9B,WAAW,EACV,mEAAmE;IACpE,OAAO,EAAE,KAAK,EACb,IAAe,EACf,EAAE,IAAI,EAAE,IAAI,EAAE,OAAO,EAAE,aAAa,EAAE,MAAM,EAAE,EAC7C,EAAE;QACH,MAAM,QAAQ,GAAG,IAAI,CAAC,QAAQ,CAAC;QAE/B,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,QAAQ,CAAC,IAAI,QAAQ,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YACvD,OAAO;gBACN;oBACC,OAAO,EAAE,gDAAgD;oBACzD,SAAS,EACR,wEAAwE;iBACzE;aACD,CAAC;QACH,CAAC;QAED,MAAM,MAAM,GAAG,MAAM,oBAAoB,CAAC;YACzC,QAAQ,EAAE,QAAoB;YAC9B,GAAG,CAAC,MAAM,EAAE,eAAe,KAAK,SAAS,IAAI;gBAC5C,eAAe,EAAE,MAAM,CAAC,eAAe;aACvC,CAAC;YACF,YAAY,EAAE,MAAM,EAAE,YAAY,IAAI,KAAK;YAC3C,aAAa;YACb,QAAQ,EAAE,OAAO,CAAC,IAAI,EAAE,IAAI,CAAC;YAC7B,gBAAgB,EAAE,UAAU;SAC5B,CAAC,CAAC;QACH,OAAO,MAAM,CAAC;IACf,CAAC;CACD,CAA8D,CAAC","sourcesContent":["import { resolve } from \"pathe\";\nimport type { FilePolicyDefinition } from \"../policy.js\";\nimport {\n\tdefineGleamPolicy,\n\ttype GleamToml,\n} from \"../policyDefiners/defineGleamPolicy.js\";\nimport { validateLicenceField } from \"../policyDefiners/spdxValidator.js\";\n\n/**\n * Configuration for the GleamLicenceConfigured policy.\n *\n * @public\n */\nexport interface GleamLicenceConfiguredConfig {\n\t/**\n\t * Allowed SPDX licence identifiers. If set, only these are accepted.\n\t */\n\tallowedLicences?: string[];\n\n\t/**\n\t * If true, validate licence values against the SPDX licence list\n\t * using `spdx-correct`. When enabled, typos like \"MIIT\" are detected\n\t * and can be auto-fixed to the correct identifier (\"MIT\").\n\t *\n\t * Requires the optional peer dependency `spdx-correct` to be installed.\n\t *\n\t * @defaultValue false\n\t */\n\tvalidateSpdx?: boolean;\n}\n\nconst MANUAL_FIX =\n\t\"Use valid SPDX licence identifiers (e.g., MIT, Apache-2.0, MPL-2.0).\";\n\n/**\n * A policy that ensures licence metadata is properly configured in gleam.toml.\n *\n * @public\n */\nexport const GleamLicenceConfigured = defineGleamPolicy({\n\tname: \"GleamLicenceConfigured\",\n\tdescription:\n\t\t\"Ensures gleam.toml has valid SPDX licence identifiers configured.\",\n\thandler: async (\n\t\ttoml: GleamToml,\n\t\t{ file, root, resolve: shouldResolve, config },\n\t) => {\n\t\tconst licences = toml.licences;\n\n\t\tif (!Array.isArray(licences) || licences.length === 0) {\n\t\t\treturn [\n\t\t\t\t{\n\t\t\t\t\tmessage: \"Missing or empty licences field in gleam.toml.\",\n\t\t\t\t\tmanualFix:\n\t\t\t\t\t\t'Add licences = [\"MIT\"] (or appropriate SPDX identifier) to gleam.toml.',\n\t\t\t\t},\n\t\t\t];\n\t\t}\n\n\t\tconst result = await validateLicenceField({\n\t\t\tlicences: licences as string[],\n\t\t\t...(config?.allowedLicences !== undefined && {\n\t\t\t\tallowedLicences: config.allowedLicences,\n\t\t\t}),\n\t\t\tvalidateSpdx: config?.validateSpdx ?? false,\n\t\t\tshouldResolve,\n\t\t\tfilePath: resolve(root, file),\n\t\t\tmanualFixMessage: MANUAL_FIX,\n\t\t});\n\t\treturn result;\n\t},\n}) satisfies FilePolicyDefinition<GleamLicenceConfiguredConfig>;\n"]}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A policy that ensures manifest.toml is committed alongside gleam.toml
|
|
3
|
+
* for reproducible Gleam builds.
|
|
4
|
+
*
|
|
5
|
+
* @public
|
|
6
|
+
*/
|
|
7
|
+
export declare const GleamManifestCommitted: {
|
|
8
|
+
name: string;
|
|
9
|
+
description: string;
|
|
10
|
+
match: RegExp;
|
|
11
|
+
handler: ({ file, root }: import("../policy.js").PolicyArgs<void>) => Promise<{
|
|
12
|
+
message: string;
|
|
13
|
+
manualFix: string;
|
|
14
|
+
}[]>;
|
|
15
|
+
};
|
|
16
|
+
//# sourceMappingURL=GleamManifestCommitted.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"GleamManifestCommitted.d.ts","sourceRoot":"","sources":["../../src/policies/GleamManifestCommitted.ts"],"names":[],"mappings":"AAGA;;;;;GAKG;AACH,eAAO,MAAM,sBAAsB;;;;;;;;CAqBH,CAAC"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { existsSync } from "node:fs";
|
|
2
|
+
import path from "pathe";
|
|
3
|
+
/**
|
|
4
|
+
* A policy that ensures manifest.toml is committed alongside gleam.toml
|
|
5
|
+
* for reproducible Gleam builds.
|
|
6
|
+
*
|
|
7
|
+
* @public
|
|
8
|
+
*/
|
|
9
|
+
export const GleamManifestCommitted = {
|
|
10
|
+
name: "GleamManifestCommitted",
|
|
11
|
+
description: "Ensures manifest.toml is committed alongside gleam.toml for reproducible builds.",
|
|
12
|
+
match: /gleam\.toml$/,
|
|
13
|
+
handler: async ({ file, root }) => {
|
|
14
|
+
const dir = path.dirname(path.resolve(root, file));
|
|
15
|
+
const manifestPath = path.join(dir, "manifest.toml");
|
|
16
|
+
if (existsSync(manifestPath)) {
|
|
17
|
+
return [];
|
|
18
|
+
}
|
|
19
|
+
return [
|
|
20
|
+
{
|
|
21
|
+
message: "Missing manifest.toml. Gleam projects should commit manifest.toml for reproducible builds.",
|
|
22
|
+
manualFix: "Run `gleam build` to generate manifest.toml, then commit it to source control.",
|
|
23
|
+
},
|
|
24
|
+
];
|
|
25
|
+
},
|
|
26
|
+
};
|
|
27
|
+
//# sourceMappingURL=GleamManifestCommitted.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"GleamManifestCommitted.js","sourceRoot":"","sources":["../../src/policies/GleamManifestCommitted.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AACrC,OAAO,IAAI,MAAM,OAAO,CAAC;AAEzB;;;;;GAKG;AACH,MAAM,CAAC,MAAM,sBAAsB,GAAG;IACrC,IAAI,EAAE,wBAAwB;IAC9B,WAAW,EACV,kFAAkF;IACnF,KAAK,EAAE,cAAc;IACrB,OAAO,EAAE,KAAK,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,EAAE,EAAE;QACjC,MAAM,GAAG,GAAG,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC,CAAC;QACnD,MAAM,YAAY,GAAG,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE,eAAe,CAAC,CAAC;QAErD,IAAI,UAAU,CAAC,YAAY,CAAC,EAAE,CAAC;YAC9B,OAAO,EAAE,CAAC;QACX,CAAC;QACD,OAAO;YACN;gBACC,OAAO,EACN,4FAA4F;gBAC7F,SAAS,EACR,gFAAgF;aACjF;SACD,CAAC;IACH,CAAC;CAC8B,CAAC","sourcesContent":["import { existsSync } from \"node:fs\";\nimport path from \"pathe\";\nimport type { FilePolicyDefinition } from \"../policy.js\";\n/**\n * A policy that ensures manifest.toml is committed alongside gleam.toml\n * for reproducible Gleam builds.\n *\n * @public\n */\nexport const GleamManifestCommitted = {\n\tname: \"GleamManifestCommitted\",\n\tdescription:\n\t\t\"Ensures manifest.toml is committed alongside gleam.toml for reproducible builds.\",\n\tmatch: /gleam\\.toml$/,\n\thandler: async ({ file, root }) => {\n\t\tconst dir = path.dirname(path.resolve(root, file));\n\t\tconst manifestPath = path.join(dir, \"manifest.toml\");\n\n\t\tif (existsSync(manifestPath)) {\n\t\t\treturn [];\n\t\t}\n\t\treturn [\n\t\t\t{\n\t\t\t\tmessage:\n\t\t\t\t\t\"Missing manifest.toml. Gleam projects should commit manifest.toml for reproducible builds.\",\n\t\t\t\tmanualFix:\n\t\t\t\t\t\"Run `gleam build` to generate manifest.toml, then commit it to source control.\",\n\t\t\t},\n\t\t];\n\t},\n} satisfies FilePolicyDefinition;\n"]}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Configuration for the GleamMonorepoConsistency policy.
|
|
3
|
+
*
|
|
4
|
+
* @public
|
|
5
|
+
*/
|
|
6
|
+
export interface GleamMonorepoConsistencyConfig {
|
|
7
|
+
/**
|
|
8
|
+
* Top-level fields that should be consistent across all packages.
|
|
9
|
+
* @defaultValue ["licences"]
|
|
10
|
+
*/
|
|
11
|
+
syncFields?: string[];
|
|
12
|
+
/**
|
|
13
|
+
* If true, ensure the `gleam` version constraint is consistent.
|
|
14
|
+
* @defaultValue true
|
|
15
|
+
*/
|
|
16
|
+
syncGleamVersion?: boolean;
|
|
17
|
+
/**
|
|
18
|
+
* Paths to gleam.toml files to compare (relative to repo root).
|
|
19
|
+
* With fewer than two paths, the policy reports no findings.
|
|
20
|
+
*/
|
|
21
|
+
packages?: string[];
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* A policy that enforces consistent metadata across Gleam packages in a monorepo.
|
|
25
|
+
*
|
|
26
|
+
* @public
|
|
27
|
+
*/
|
|
28
|
+
export declare const GleamMonorepoConsistency: {
|
|
29
|
+
name: string;
|
|
30
|
+
requiresConfig: true;
|
|
31
|
+
description: string;
|
|
32
|
+
match: RegExp;
|
|
33
|
+
handler: ({ root, config }: import("../policy.js").PolicyArgs<GleamMonorepoConsistencyConfig>) => Promise<{
|
|
34
|
+
message: string;
|
|
35
|
+
manualFix: string;
|
|
36
|
+
}[]>;
|
|
37
|
+
};
|
|
38
|
+
//# sourceMappingURL=GleamMonorepoConsistency.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"GleamMonorepoConsistency.d.ts","sourceRoot":"","sources":["../../src/policies/GleamMonorepoConsistency.ts"],"names":[],"mappings":"AAKA;;;;GAIG;AACH,MAAM,WAAW,8BAA8B;IAC9C;;;OAGG;IACH,UAAU,CAAC,EAAE,MAAM,EAAE,CAAC;IAEtB;;;OAGG;IACH,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAE3B;;;OAGG;IACH,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAC;CACpB;AAuCD;;;;GAIG;AACH,eAAO,MAAM,wBAAwB;;;;;;;;;CA8C2B,CAAC"}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { readFile } from "node:fs/promises";
|
|
2
|
+
import path from "pathe";
|
|
3
|
+
import { parseToml } from "../policyDefiners/tomlParser.js";
|
|
4
|
+
const DEFAULT_SYNC_FIELDS = ["licences"];
|
|
5
|
+
async function loadGleamToml(filePath) {
|
|
6
|
+
try {
|
|
7
|
+
const content = await readFile(filePath, "utf-8");
|
|
8
|
+
return await parseToml(content);
|
|
9
|
+
}
|
|
10
|
+
catch {
|
|
11
|
+
return undefined;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
function checkFieldConsistency(packages, field) {
|
|
15
|
+
const values = new Map();
|
|
16
|
+
for (const [pkg, toml] of packages) {
|
|
17
|
+
const value = JSON.stringify(toml[field] ?? null);
|
|
18
|
+
if (!values.has(value)) {
|
|
19
|
+
values.set(value, []);
|
|
20
|
+
}
|
|
21
|
+
values.get(value)?.push(pkg);
|
|
22
|
+
}
|
|
23
|
+
if (values.size <= 1) {
|
|
24
|
+
return [];
|
|
25
|
+
}
|
|
26
|
+
const details = [...values.entries()]
|
|
27
|
+
.map(([val, pkgs]) => `${val} in ${pkgs.join(", ")}`)
|
|
28
|
+
.join("; ");
|
|
29
|
+
return [`Inconsistent "${field}" across packages: ${details}`];
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* A policy that enforces consistent metadata across Gleam packages in a monorepo.
|
|
33
|
+
*
|
|
34
|
+
* @public
|
|
35
|
+
*/
|
|
36
|
+
export const GleamMonorepoConsistency = {
|
|
37
|
+
name: "GleamMonorepoConsistency",
|
|
38
|
+
requiresConfig: true,
|
|
39
|
+
description: "Enforces consistent metadata (licences, gleam version, etc.) across Gleam packages in a monorepo.",
|
|
40
|
+
match: /^gleam\.toml$/,
|
|
41
|
+
handler: async ({ root, config }) => {
|
|
42
|
+
const packagePaths = config?.packages;
|
|
43
|
+
if (!packagePaths || packagePaths.length < 2) {
|
|
44
|
+
return [];
|
|
45
|
+
}
|
|
46
|
+
const syncFields = config?.syncFields ?? DEFAULT_SYNC_FIELDS;
|
|
47
|
+
const syncGleamVersion = config?.syncGleamVersion ?? true;
|
|
48
|
+
const packages = new Map();
|
|
49
|
+
for (const pkgPath of packagePaths) {
|
|
50
|
+
const toml = await loadGleamToml(path.resolve(root, pkgPath));
|
|
51
|
+
if (toml) {
|
|
52
|
+
packages.set(pkgPath, toml);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
if (packages.size < 2) {
|
|
56
|
+
return [];
|
|
57
|
+
}
|
|
58
|
+
const errors = [];
|
|
59
|
+
for (const field of syncFields) {
|
|
60
|
+
errors.push(...checkFieldConsistency(packages, field));
|
|
61
|
+
}
|
|
62
|
+
if (syncGleamVersion) {
|
|
63
|
+
errors.push(...checkFieldConsistency(packages, "gleam"));
|
|
64
|
+
}
|
|
65
|
+
if (errors.length > 0) {
|
|
66
|
+
return errors.map((message) => ({
|
|
67
|
+
message,
|
|
68
|
+
manualFix: "Ensure all Gleam packages in the monorepo use consistent metadata values.",
|
|
69
|
+
}));
|
|
70
|
+
}
|
|
71
|
+
return [];
|
|
72
|
+
},
|
|
73
|
+
};
|
|
74
|
+
//# sourceMappingURL=GleamMonorepoConsistency.js.map
|