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
package/esm/fileCache.js
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { resolve } from "pathe";
|
|
2
|
+
/** Internal context shared with policies loaded through different module loaders. */
|
|
3
|
+
export const fileCache = Symbol.for("repopo.fileCache");
|
|
4
|
+
function cloneToml(value) {
|
|
5
|
+
if (value instanceof Date) {
|
|
6
|
+
// TomlDate stores date/time kind and offset in private fields.
|
|
7
|
+
return Reflect.construct(value.constructor, [value.toISOString()]);
|
|
8
|
+
}
|
|
9
|
+
if (Array.isArray(value)) {
|
|
10
|
+
return value.map(cloneToml);
|
|
11
|
+
}
|
|
12
|
+
if (value !== null && typeof value === "object") {
|
|
13
|
+
return Object.fromEntries(Object.entries(value).map(([key, entry]) => [key, cloneToml(entry)]));
|
|
14
|
+
}
|
|
15
|
+
return value;
|
|
16
|
+
}
|
|
17
|
+
export class ParsedFileCache {
|
|
18
|
+
entries = new Map();
|
|
19
|
+
async read(key, load, clone = structuredClone) {
|
|
20
|
+
let pending = this.entries.get(key);
|
|
21
|
+
if (pending === undefined) {
|
|
22
|
+
pending = load();
|
|
23
|
+
this.entries.set(key, pending);
|
|
24
|
+
}
|
|
25
|
+
return clone(await pending);
|
|
26
|
+
}
|
|
27
|
+
clear() {
|
|
28
|
+
this.entries.clear();
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
export function readParsedFile(args, format, load) {
|
|
32
|
+
const cache = args.resolve ? undefined : args[fileCache];
|
|
33
|
+
return cache
|
|
34
|
+
? cache.read(JSON.stringify([format, resolve(args.root, args.file)]), load, format === "toml" ? cloneToml : structuredClone)
|
|
35
|
+
: load();
|
|
36
|
+
}
|
|
37
|
+
//# sourceMappingURL=fileCache.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fileCache.js","sourceRoot":"","sources":["../src/fileCache.ts"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,CAAM,CAAC;IAClC,CAAC;IAEM,KAAK;QACX,IAAI,CAAC,OAAO,CAAC,KAAK,EAAE,CAAC;IACtB,CAAC;CACD;AAED,MAAM,UAAU,cAAc,CAC7B,IAAyE,EACzE,MAAuB,EACvB,IAAsB;IAEtB,MAAM,KAAK,GAAG,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;IACzD,OAAO,KAAK;QACX,CAAC,CAAC,KAAK,CAAC,IAAI,CACV,IAAI,CAAC,SAAS,CAAC,CAAC,MAAM,EAAE,OAAO,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,EACvD,IAAI,EACJ,MAAM,KAAK,MAAM,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,eAAe,CAC/C;QACF,CAAC,CAAC,IAAI,EAAE,CAAC;AACX,CAAC","sourcesContent":["import { resolve } from \"pathe\";\nimport type { PolicyArgs } from \"./policy.js\";\n\n/** Internal context shared with policies loaded through different module loaders. */\nexport const fileCache = Symbol.for(\"repopo.fileCache\");\n\nfunction cloneToml(value: unknown): unknown {\n\tif (value instanceof Date) {\n\t\t// TomlDate stores date/time kind and offset in private fields.\n\t\treturn Reflect.construct(value.constructor, [value.toISOString()]);\n\t}\n\tif (Array.isArray(value)) {\n\t\treturn value.map(cloneToml);\n\t}\n\tif (value !== null && typeof value === \"object\") {\n\t\treturn Object.fromEntries(\n\t\t\tObject.entries(value).map(([key, entry]) => [key, cloneToml(entry)]),\n\t\t);\n\t}\n\treturn value;\n}\n\nexport class ParsedFileCache {\n\tprivate readonly entries = new Map<string, Promise<unknown>>();\n\n\tpublic async read<T>(\n\t\tkey: string,\n\t\tload: () => Promise<T>,\n\t\tclone: (value: unknown) => unknown = structuredClone,\n\t): Promise<T> {\n\t\tlet pending = this.entries.get(key);\n\t\tif (pending === undefined) {\n\t\t\tpending = load();\n\t\t\tthis.entries.set(key, pending);\n\t\t}\n\t\treturn clone(await pending) as T;\n\t}\n\n\tpublic clear(): void {\n\t\tthis.entries.clear();\n\t}\n}\n\nexport function readParsedFile<T>(\n\targs: PolicyArgs<unknown> & { [fileCache]?: ParsedFileCache | undefined },\n\tformat: \"json\" | \"toml\",\n\tload: () => Promise<T>,\n): Promise<T> {\n\tconst cache = args.resolve ? undefined : args[fileCache];\n\treturn cache\n\t\t? cache.read(\n\t\t\t\tJSON.stringify([format, resolve(args.root, args.file)]),\n\t\t\t\tload,\n\t\t\t\tformat === \"toml\" ? cloneToml : structuredClone,\n\t\t\t)\n\t\t: load();\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"filePaths.d.ts","sourceRoot":"","sources":["../src/filePaths.ts"],"names":[],"mappings":"AAGA,wBAAgB,cAAc,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,EAAE,CAKtD"}
|
package/esm/filePaths.js
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
const WINDOWS_SEPARATOR = /\\/g;
|
|
2
|
+
const LINE_BREAK = /\r?\n/;
|
|
3
|
+
export function parseFilePaths(input) {
|
|
4
|
+
return input
|
|
5
|
+
.replace(WINDOWS_SEPARATOR, "/")
|
|
6
|
+
.split(input.includes("\0") ? "\0" : LINE_BREAK)
|
|
7
|
+
.filter((filePath) => filePath.length > 0);
|
|
8
|
+
}
|
|
9
|
+
//# sourceMappingURL=filePaths.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"filePaths.js","sourceRoot":"","sources":["../src/filePaths.ts"],"names":[],"mappings":"AAAA,MAAM,iBAAiB,GAAG,KAAK,CAAC;AAChC,MAAM,UAAU,GAAG,OAAO,CAAC;AAE3B,MAAM,UAAU,cAAc,CAAC,KAAa;IAC3C,OAAO,KAAK;SACV,OAAO,CAAC,iBAAiB,EAAE,GAAG,CAAC;SAC/B,KAAK,CAAC,KAAK,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,UAAU,CAAC;SAC/C,MAAM,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC,QAAQ,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;AAC7C,CAAC","sourcesContent":["const WINDOWS_SEPARATOR = /\\\\/g;\nconst LINE_BREAK = /\\r?\\n/;\n\nexport function parseFilePaths(input: string): string[] {\n\treturn input\n\t\t.replace(WINDOWS_SEPARATOR, \"/\")\n\t\t.split(input.includes(\"\\0\") ? \"\\0\" : LINE_BREAK)\n\t\t.filter((filePath) => filePath.length > 0);\n}\n"]}
|
package/esm/generators.d.ts
CHANGED
|
@@ -1,23 +1,3 @@
|
|
|
1
|
-
import type { PolicyDefinition } from "./policy.js";
|
|
2
|
-
/**
|
|
3
|
-
* The definition of a free function that returns a RepoPolicy.
|
|
4
|
-
*
|
|
5
|
-
* @alpha
|
|
6
|
-
*/
|
|
7
|
-
export type PolicyCreatorFunction<C = undefined> = (args: PolicyDefinition<C>) => PolicyDefinition<C>;
|
|
8
|
-
/**
|
|
9
|
-
* The definition of a constructor function that returns a RepoPolicy.
|
|
10
|
-
*
|
|
11
|
-
* @alpha
|
|
12
|
-
*/
|
|
13
|
-
export type PolicyCreatorConstructor<C = undefined> = new (args: PolicyDefinition<C>) => PolicyDefinition<C>;
|
|
14
|
-
/**
|
|
15
|
-
* A PolicyCreator is a function that can be used to generate a {@link PolicyDefinition}. The function can be a free
|
|
16
|
-
* function or a constructor that creates a class implementing the {@link PolicyDefinition} interface.
|
|
17
|
-
*
|
|
18
|
-
* @alpha
|
|
19
|
-
*/
|
|
20
|
-
export type PolicyCreator = PolicyCreatorConstructor | PolicyCreatorFunction;
|
|
21
1
|
/**
|
|
22
2
|
* Checks if a given function is a generator function.
|
|
23
3
|
*
|
package/esm/generators.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generators.d.ts","sourceRoot":"","sources":["../src/generators.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"generators.d.ts","sourceRoot":"","sources":["../src/generators.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AAEH,wBAAgB,mBAAmB,CAAC,EAAE,EAAE,QAAQ,GAAG,EAAE,IAAI,iBAAiB,CAEzE"}
|
package/esm/generators.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generators.js","sourceRoot":"","sources":["../src/generators.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"generators.js","sourceRoot":"","sources":["../src/generators.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,oEAAoE;AACpE,MAAM,UAAU,mBAAmB,CAAC,EAAY;IAC/C,OAAO,EAAE,CAAC,WAAW,CAAC,IAAI,KAAK,mBAAmB,CAAC;AACpD,CAAC","sourcesContent":["/**\n * Checks if a given function is a generator function.\n *\n * A generator function is a function that can be paused and resumed, and can yield\n * multiple values over time. This utility function helps identify such functions\n * by checking their constructor name.\n *\n * @param fn - The function to check\n * @returns `true` if the function is a generator function, `false` otherwise\n *\n * @example\n * ```typescript\n * function* myGenerator() {\n * yield 1;\n * yield 2;\n * }\n *\n * function regularFunction() {\n * return 1;\n * }\n *\n * console.log(isGeneratorFunction(myGenerator)); // true\n * console.log(isGeneratorFunction(regularFunction)); // false\n * ```\n *\n * @alpha\n */\n// biome-ignore lint/complexity/noBannedTypes: broad type is OK here\nexport function isGeneratorFunction(fn: Function): fn is GeneratorFunction {\n\treturn fn.constructor.name === \"GeneratorFunction\";\n}\n"]}
|
package/esm/index.d.ts
CHANGED
|
@@ -1,23 +1,10 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* Repository policy authoring, execution, and CLI entry point.
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
* Repopo provides a framework for defining and enforcing policies across repositories,
|
|
6
|
-
* such as file headers, package.json consistency, and other code standards.
|
|
7
|
-
* It can be used as a CLI tool or integrated into CI/CD pipelines.
|
|
4
|
+
* Import `repopo/api` for the programmatic API without the CLI entry point.
|
|
8
5
|
*
|
|
9
6
|
* @packageDocumentation
|
|
10
7
|
*/
|
|
11
8
|
export { run } from "@oclif/core";
|
|
12
|
-
export
|
|
13
|
-
export type { RepopoConfig, } from "./config.js";
|
|
14
|
-
export type { ExcludedPolicyFileMap } from "./context.js";
|
|
15
|
-
export { makePolicy, makePolicyDefinition, type PolicyDefinitionInput, type PolicyOptions, policy, } from "./makePolicy.js";
|
|
16
|
-
export type { PolicyAction, PolicyHandlerPerfStats } from "./perf.js";
|
|
17
|
-
export { type ConfiguredPolicy, type IdentifiedPolicy, isPolicyError, isPolicyFailure, isPolicyFixResult, Policy, type PolicyArgs, type PolicyDefinition, type PolicyError, type PolicyFailure, type PolicyFixResult, type PolicyFunctionArguments, type PolicyHandler, type PolicyHandlerResult, type PolicyInstance, type PolicyInstanceId, type PolicyInstanceSettings, type PolicyName, type PolicyResolver, type PolicyResult, type PolicyShape, type PolicyStandaloneResolver, } from "./policy.js";
|
|
18
|
-
export { type CargoToml, type CargoTomlHandler, type DefineCargoPolicyArgs, defineCargoPolicy, } from "./policyDefiners/defineCargoPolicy.js";
|
|
19
|
-
export { type DefineFileHeaderPolicyArgs, defineFileHeaderPolicy, type FileHeaderGeneratorConfig, type FileHeaderPolicyConfig, } from "./policyDefiners/defineFileHeaderPolicy.js";
|
|
20
|
-
export { type DefineGleamPolicyArgs, defineGleamPolicy, type GleamToml, type GleamTomlHandler, } from "./policyDefiners/defineGleamPolicy.js";
|
|
21
|
-
export { type DefinePackagePolicyArgs, definePackagePolicy as generatePackagePolicy, type PackageJsonHandler, } from "./policyDefiners/definePackagePolicy.js";
|
|
22
|
-
export { type PolicyFileResult, PolicyRunner, type PolicyRunnerOptions, type PolicyRunResults, } from "./runner.js";
|
|
9
|
+
export * from "./api.js";
|
|
23
10
|
//# sourceMappingURL=index.d.ts.map
|
package/esm/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,GAAG,EAAE,MAAM,aAAa,CAAC;AAClC,cAAc,UAAU,CAAC"}
|
package/esm/index.js
CHANGED
|
@@ -1,24 +1,10 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* Repository policy authoring, execution, and CLI entry point.
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
* Repopo provides a framework for defining and enforcing policies across repositories,
|
|
6
|
-
* such as file headers, package.json consistency, and other code standards.
|
|
7
|
-
* It can be used as a CLI tool or integrated into CI/CD pipelines.
|
|
4
|
+
* Import `repopo/api` for the programmatic API without the CLI entry point.
|
|
8
5
|
*
|
|
9
6
|
* @packageDocumentation
|
|
10
7
|
*/
|
|
11
8
|
export { run } from "@oclif/core";
|
|
12
|
-
export
|
|
13
|
-
export { makePolicy, makePolicyDefinition, policy, } from "./makePolicy.js";
|
|
14
|
-
export {
|
|
15
|
-
// Type guards
|
|
16
|
-
isPolicyError, isPolicyFailure, isPolicyFixResult,
|
|
17
|
-
// New types
|
|
18
|
-
Policy, } from "./policy.js";
|
|
19
|
-
export { defineCargoPolicy, } from "./policyDefiners/defineCargoPolicy.js";
|
|
20
|
-
export { defineFileHeaderPolicy, } from "./policyDefiners/defineFileHeaderPolicy.js";
|
|
21
|
-
export { defineGleamPolicy, } from "./policyDefiners/defineGleamPolicy.js";
|
|
22
|
-
export { definePackagePolicy as generatePackagePolicy, } from "./policyDefiners/definePackagePolicy.js";
|
|
23
|
-
export { PolicyRunner, } from "./runner.js";
|
|
9
|
+
export * from "./api.js";
|
|
24
10
|
//# sourceMappingURL=index.js.map
|
package/esm/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,GAAG,EAAE,MAAM,aAAa,CAAC;AAClC,cAAc,UAAU,CAAC","sourcesContent":["/**\n * Repository policy authoring, execution, and CLI entry point.\n *\n * Import `repopo/api` for the programmatic API without the CLI entry point.\n *\n * @packageDocumentation\n */\n\nexport { run } from \"@oclif/core\";\nexport * from \"./api.js\";\n"]}
|
package/esm/makePolicy.d.ts
CHANGED
|
@@ -1,107 +1,27 @@
|
|
|
1
|
-
import type { ConfiguredPolicy,
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* Configure a policy for use in repopo.
|
|
22
|
-
*
|
|
23
|
-
* @remarks
|
|
24
|
-
* This function takes a policy definition and returns a configured policy instance
|
|
25
|
-
* that can be added to the `policies` array in `repopo.config.ts`.
|
|
26
|
-
*
|
|
27
|
-
* Handlers are automatically normalized: async functions are wrapped for Effection
|
|
28
|
-
* compatibility, while generator functions are used directly.
|
|
29
|
-
*
|
|
30
|
-
* @example
|
|
31
|
-
* ```typescript
|
|
32
|
-
* // Policy with no config, just options
|
|
33
|
-
* policy(NoJsFileExtensions, { exclude: ["bin/*"] })
|
|
34
|
-
*
|
|
35
|
-
* // Policy with config
|
|
36
|
-
* policy(PackageJsonProperties, { verbatim: { license: "MIT" } })
|
|
37
|
-
*
|
|
38
|
-
* // Policy with config and options
|
|
39
|
-
* policy(PackageJsonProperties, { verbatim: { license: "MIT" } }, { exclude: ["vendor/*"] })
|
|
40
|
-
*
|
|
41
|
-
* // Duplicate policies need stable instance IDs
|
|
42
|
-
* policy(PackageJsonProperties, sourceConfig, { instanceId: "source-packages" })
|
|
43
|
-
* policy(PackageJsonProperties, testConfig, { instanceId: "test-packages" })
|
|
44
|
-
* ```
|
|
45
|
-
*
|
|
46
|
-
* @alpha
|
|
47
|
-
*/
|
|
48
|
-
export declare function policy<C = void>(policyDef: PolicyShape<C>, options?: PolicyOptions & {
|
|
49
|
-
exclude: (string | RegExp)[];
|
|
50
|
-
}): ConfiguredPolicy<C>;
|
|
51
|
-
/** @alpha */
|
|
52
|
-
export declare function policy<C>(policyDef: PolicyShape<C>, config: C, options?: PolicyOptions): ConfiguredPolicy<C>;
|
|
53
|
-
/**
|
|
54
|
-
* Assigns stable identities to configured policy instances.
|
|
55
|
-
*
|
|
56
|
-
* Single instances retain the policy name for compatibility. Duplicate instances
|
|
57
|
-
* must declare explicit identities so their identities remain stable across config
|
|
58
|
-
* reordering and policy renames.
|
|
59
|
-
*
|
|
60
|
-
* @internal
|
|
61
|
-
*/
|
|
1
|
+
import type { ConfiguredFilePolicy, ConfiguredPolicy, ConfiguredRepositoryPolicy, DefinedConfig, FilePolicyDefinition, PolicyDefinition, PolicyInstanceId, PolicyName, PolicyOptions, RepositoryPolicyDefinition } from "./policy.js";
|
|
2
|
+
type ConfigOf<D> = D extends PolicyDefinition<infer C> ? C : never;
|
|
3
|
+
type RequiredConfigDefinitions<D> = D extends {
|
|
4
|
+
requiresConfig: true;
|
|
5
|
+
} ? D extends {
|
|
6
|
+
defaultConfig: infer Default;
|
|
7
|
+
} ? undefined extends Default ? D : never : D : never;
|
|
8
|
+
type OptionsFor<D> = [RequiredConfigDefinitions<D>] extends [never] ? [options?: PolicyOptions<ConfigOf<D>>] : [
|
|
9
|
+
options: PolicyOptions<ConfigOf<D>> & {
|
|
10
|
+
config: DefinedConfig<ConfigOf<RequiredConfigDefinitions<D>>>;
|
|
11
|
+
}
|
|
12
|
+
];
|
|
13
|
+
/** Configure a file definition using a single options object. @public */
|
|
14
|
+
export declare function makePolicy<D extends FilePolicyDefinition<unknown>>(definition: D, ...options: OptionsFor<D>): ConfiguredFilePolicy<ConfigOf<D>>;
|
|
15
|
+
/** Configure a repository definition using a single options object. @public */
|
|
16
|
+
export declare function makePolicy<D extends RepositoryPolicyDefinition<unknown>>(definition: D, ...options: OptionsFor<D>): ConfiguredRepositoryPolicy<ConfigOf<D>>;
|
|
17
|
+
/** Configure a common-union definition without losing scope discrimination. @public */
|
|
18
|
+
export declare function makePolicy<D extends PolicyDefinition<unknown>>(definition: D, ...options: OptionsFor<D>): ConfiguredPolicy<ConfigOf<D>>;
|
|
19
|
+
/** Assign stable IDs, rejecting ambiguous duplicates. @internal */
|
|
62
20
|
export declare function identifyPolicyInstances<T extends {
|
|
63
21
|
name: PolicyName;
|
|
64
22
|
instanceId?: PolicyInstanceId | undefined;
|
|
65
23
|
}>(policies: readonly T[]): (T & {
|
|
66
24
|
instanceId: PolicyInstanceId;
|
|
67
25
|
})[];
|
|
68
|
-
|
|
69
|
-
* Input arguments for creating a policy definition.
|
|
70
|
-
*
|
|
71
|
-
* @deprecated Use {@link PolicyShape} directly instead.
|
|
72
|
-
*
|
|
73
|
-
* @alpha
|
|
74
|
-
*/
|
|
75
|
-
export type PolicyDefinitionInput<C = undefined> = PolicyDefinition<C>;
|
|
76
|
-
/**
|
|
77
|
-
* Creates a {@link PolicyDefinition} from the provided arguments.
|
|
78
|
-
*
|
|
79
|
-
* @deprecated Define policies as object literals satisfying {@link PolicyShape} instead.
|
|
80
|
-
*
|
|
81
|
-
* @example
|
|
82
|
-
* ```typescript
|
|
83
|
-
* const MyPolicy = makePolicyDefinition({
|
|
84
|
-
* name: "MyPolicy",
|
|
85
|
-
* description: "Ensures files follow conventions",
|
|
86
|
-
* match: /\.ts$/,
|
|
87
|
-
* handler: async ({ file }) => true,
|
|
88
|
-
* });
|
|
89
|
-
* ```
|
|
90
|
-
*
|
|
91
|
-
* @alpha
|
|
92
|
-
*/
|
|
93
|
-
export declare function makePolicyDefinition<C = undefined>(args: PolicyDefinitionInput<C>): PolicyDefinition<C>;
|
|
94
|
-
/**
|
|
95
|
-
* Combine a {@link PolicyDefinition} with a policy-specific config and other settings.
|
|
96
|
-
*
|
|
97
|
-
* @deprecated Use the `policy` function instead, which has a simpler API.
|
|
98
|
-
*
|
|
99
|
-
* @example
|
|
100
|
-
* ```typescript
|
|
101
|
-
* makePolicy(NoJsFileExtensions, undefined, { excludeFiles: ["bin/*"] })
|
|
102
|
-
* ```
|
|
103
|
-
*
|
|
104
|
-
* @alpha
|
|
105
|
-
*/
|
|
106
|
-
export declare function makePolicy<C>(definition: PolicyDefinition<C>, config?: C, settings?: PolicyInstanceSettings<C>): PolicyInstance<C>;
|
|
26
|
+
export {};
|
|
107
27
|
//# sourceMappingURL=makePolicy.d.ts.map
|
package/esm/makePolicy.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"makePolicy.d.ts","sourceRoot":"","sources":["../src/makePolicy.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"makePolicy.d.ts","sourceRoot":"","sources":["../src/makePolicy.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACX,oBAAoB,EACpB,gBAAgB,EAChB,0BAA0B,EAC1B,aAAa,EACb,oBAAoB,EACpB,gBAAgB,EAChB,gBAAgB,EAChB,UAAU,EACV,aAAa,EACb,0BAA0B,EAC1B,MAAM,aAAa,CAAC;AAErB,KAAK,QAAQ,CAAC,CAAC,IAAI,CAAC,SAAS,gBAAgB,CAAC,MAAM,CAAC,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;AACnE,KAAK,yBAAyB,CAAC,CAAC,IAAI,CAAC,SAAS;IAAE,cAAc,EAAE,IAAI,CAAA;CAAE,GACnE,CAAC,SAAS;IAAE,aAAa,EAAE,MAAM,OAAO,CAAA;CAAE,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C,EAAE,GAAG,CAAC,CAAC,GAAG;IAAE,UAAU,EAAE,gBAAgB,CAAA;CAAE,CAAC,EAAE,CA6BlE"}
|
package/esm/makePolicy.js
CHANGED
|
@@ -1,146 +1,60 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
1
|
+
import { exclusionRegex } from "./context.js";
|
|
2
|
+
export function makePolicy(definition, options, ...extra) {
|
|
3
|
+
const guidance = "Use makePolicy(definition, { config, exclude, instanceId }); positional config, third arguments and excludeFiles are no longer supported.";
|
|
4
|
+
if (extra.length > 0 ||
|
|
5
|
+
(options !== undefined &&
|
|
6
|
+
(typeof options !== "object" ||
|
|
7
|
+
options === null ||
|
|
8
|
+
Array.isArray(options) ||
|
|
9
|
+
Object.keys(options).some((key) => !["config", "exclude", "instanceId"].includes(key))))) {
|
|
10
|
+
throw new TypeError(guidance);
|
|
11
11
|
}
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
};
|
|
17
|
-
}
|
|
18
|
-
/** @alpha */
|
|
19
|
-
export function policy(policyDef, configOrOptions, maybeOptions) {
|
|
20
|
-
// Determine if the second argument is config or options
|
|
21
|
-
let config;
|
|
22
|
-
let options;
|
|
23
|
-
if (maybeOptions !== undefined) {
|
|
24
|
-
// Three-argument form: policy(def, config, options)
|
|
25
|
-
config = configOrOptions;
|
|
26
|
-
options = maybeOptions;
|
|
12
|
+
if (definition.scope !== undefined &&
|
|
13
|
+
definition.scope !== "file" &&
|
|
14
|
+
definition.resolver !== undefined) {
|
|
15
|
+
throw new TypeError("Repository policies support inline fixes only; remove resolver.");
|
|
27
16
|
}
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
// It's options (has 'exclude' and only option keys)
|
|
37
|
-
options = configOrOptions;
|
|
38
|
-
}
|
|
39
|
-
else {
|
|
40
|
-
// It's config
|
|
41
|
-
config = configOrOptions;
|
|
42
|
-
}
|
|
17
|
+
if (options?.exclude !== undefined &&
|
|
18
|
+
!(Array.isArray(options.exclude) &&
|
|
19
|
+
options.exclude.every((value) => typeof value === "string" || value instanceof RegExp))) {
|
|
20
|
+
throw new TypeError(guidance);
|
|
21
|
+
}
|
|
22
|
+
if (options?.instanceId !== undefined &&
|
|
23
|
+
(typeof options.instanceId !== "string" || options.instanceId.length === 0)) {
|
|
24
|
+
throw new TypeError("instanceId must be a nonempty string.");
|
|
43
25
|
}
|
|
44
|
-
|
|
45
|
-
const
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
config: effectiveConfig,
|
|
51
|
-
exclude: excludePatterns,
|
|
52
|
-
excludeFiles: excludePatterns,
|
|
53
|
-
instanceId: options?.instanceId,
|
|
54
|
-
_internalHandler: normalizeHandler(policyDef.handler),
|
|
55
|
-
};
|
|
26
|
+
options?.exclude?.forEach(exclusionRegex);
|
|
27
|
+
const config = options?.config === undefined ? definition.defaultConfig : options.config;
|
|
28
|
+
if (definition.requiresConfig && config === undefined) {
|
|
29
|
+
throw new TypeError(`Policy '${definition.name}' requires config. ${guidance}`);
|
|
30
|
+
}
|
|
31
|
+
return { ...definition, ...options, config };
|
|
56
32
|
}
|
|
57
|
-
/**
|
|
58
|
-
* Assigns stable identities to configured policy instances.
|
|
59
|
-
*
|
|
60
|
-
* Single instances retain the policy name for compatibility. Duplicate instances
|
|
61
|
-
* must declare explicit identities so their identities remain stable across config
|
|
62
|
-
* reordering and policy renames.
|
|
63
|
-
*
|
|
64
|
-
* @internal
|
|
65
|
-
*/
|
|
33
|
+
/** Assign stable IDs, rejecting ambiguous duplicates. @internal */
|
|
66
34
|
export function identifyPolicyInstances(policies) {
|
|
67
|
-
const
|
|
68
|
-
const
|
|
69
|
-
for (const
|
|
70
|
-
|
|
71
|
-
if (
|
|
72
|
-
if (
|
|
73
|
-
throw new Error(`Duplicate policy instance ID: ${
|
|
35
|
+
const names = new Map();
|
|
36
|
+
const ids = new Set();
|
|
37
|
+
for (const policy of policies) {
|
|
38
|
+
names.set(policy.name, (names.get(policy.name) ?? 0) + 1);
|
|
39
|
+
if (policy.instanceId !== undefined) {
|
|
40
|
+
if (ids.has(policy.instanceId)) {
|
|
41
|
+
throw new Error(`Duplicate policy instance ID: ${policy.instanceId}`);
|
|
74
42
|
}
|
|
75
|
-
|
|
43
|
+
ids.add(policy.instanceId);
|
|
76
44
|
}
|
|
77
45
|
}
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
return {
|
|
82
|
-
...configuredPolicy,
|
|
83
|
-
instanceId: configuredPolicy.instanceId,
|
|
84
|
-
};
|
|
46
|
+
return policies.map((policy) => {
|
|
47
|
+
if (policy.instanceId !== undefined) {
|
|
48
|
+
return { ...policy, instanceId: policy.instanceId };
|
|
85
49
|
}
|
|
86
|
-
if ((
|
|
87
|
-
throw new Error(`Policy '${
|
|
50
|
+
if ((names.get(policy.name) ?? 0) > 1) {
|
|
51
|
+
throw new Error(`Policy '${policy.name}' is configured multiple times. Set a unique instanceId for each instance.`);
|
|
88
52
|
}
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
throw new Error(`Policy instance ID '${instanceId}' conflicts with another configured policy. Set an explicit unique instanceId.`);
|
|
53
|
+
if (ids.has(policy.name)) {
|
|
54
|
+
throw new Error(`Policy instance ID '${policy.name}' conflicts with another configured policy. Set an explicit unique instanceId.`);
|
|
92
55
|
}
|
|
93
|
-
|
|
94
|
-
return {
|
|
95
|
-
...configuredPolicy,
|
|
96
|
-
instanceId,
|
|
97
|
-
};
|
|
56
|
+
ids.add(policy.name);
|
|
57
|
+
return { ...policy, instanceId: policy.name };
|
|
98
58
|
});
|
|
99
59
|
}
|
|
100
|
-
/**
|
|
101
|
-
* Creates a {@link PolicyDefinition} from the provided arguments.
|
|
102
|
-
*
|
|
103
|
-
* @deprecated Define policies as object literals satisfying {@link PolicyShape} instead.
|
|
104
|
-
*
|
|
105
|
-
* @example
|
|
106
|
-
* ```typescript
|
|
107
|
-
* const MyPolicy = makePolicyDefinition({
|
|
108
|
-
* name: "MyPolicy",
|
|
109
|
-
* description: "Ensures files follow conventions",
|
|
110
|
-
* match: /\.ts$/,
|
|
111
|
-
* handler: async ({ file }) => true,
|
|
112
|
-
* });
|
|
113
|
-
* ```
|
|
114
|
-
*
|
|
115
|
-
* @alpha
|
|
116
|
-
*/
|
|
117
|
-
export function makePolicyDefinition(args) {
|
|
118
|
-
return {
|
|
119
|
-
name: args.name,
|
|
120
|
-
description: args.description,
|
|
121
|
-
match: args.match,
|
|
122
|
-
handler: args.handler,
|
|
123
|
-
defaultConfig: args.defaultConfig,
|
|
124
|
-
resolver: args.resolver,
|
|
125
|
-
};
|
|
126
|
-
}
|
|
127
|
-
/**
|
|
128
|
-
* Combine a {@link PolicyDefinition} with a policy-specific config and other settings.
|
|
129
|
-
*
|
|
130
|
-
* @deprecated Use the `policy` function instead, which has a simpler API.
|
|
131
|
-
*
|
|
132
|
-
* @example
|
|
133
|
-
* ```typescript
|
|
134
|
-
* makePolicy(NoJsFileExtensions, undefined, { excludeFiles: ["bin/*"] })
|
|
135
|
-
* ```
|
|
136
|
-
*
|
|
137
|
-
* @alpha
|
|
138
|
-
*/
|
|
139
|
-
export function makePolicy(definition, config, settings) {
|
|
140
|
-
return {
|
|
141
|
-
...definition,
|
|
142
|
-
...settings,
|
|
143
|
-
config,
|
|
144
|
-
};
|
|
145
|
-
}
|
|
146
60
|
//# sourceMappingURL=makePolicy.js.map
|
package/esm/makePolicy.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"makePolicy.js","sourceRoot":"","sources":["../src/makePolicy.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAkB,MAAM,WAAW,CAAC;AACjD,OAAO,EAAE,mBAA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AC;QAED,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,gBAAgB,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,EAAE,CAAC;YACtD,MAAM,IAAI,KAAK,CACd,WAAW,gBAAgB,CAAC,IAAI,4EAA4E,CAC5G,CAAC;QACH,CAAC;QAED,MAAM,UAAU,GAAG,gBAAgB,CAAC,IAAI,CAAC;QACzC,IAAI,OAAO,CAAC,GAAG,CAAC,UAAU,CAAC,EAAE,CAAC;YAC7B,MAAM,IAAI,KAAK,CACd,uBAAuB,UAAU,gFAAgF,CACjH,CAAC;QACH,CAAC;QACD,OAAO,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC;QAExB,OAAO;YACN,GAAG,gBAAgB;YACnB,UAAU;SACV,CAAC;IACH,CAAC,CAAC,CAAC;AACJ,CAAC;AAeD;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,UAAU,oBAAoB,CACnC,IAA8B;IAE9B,OAAO;QACN,IAAI,EAAE,IAAI,CAAC,IAAI;QACf,WAAW,EAAE,IAAI,CAAC,WAAW;QAC7B,KAAK,EAAE,IAAI,CAAC,KAAK;QACjB,OAAO,EAAE,IAAI,CAAC,OAAO;QACrB,aAAa,EAAE,IAAI,CAAC,aAAa;QACjC,QAAQ,EAAE,IAAI,CAAC,QAAQ;KACvB,CAAC;AACH,CAAC;AAED;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,UAAU,CACzB,UAA+B,EAC/B,MAAU,EACV,QAAoC;IAEpC,OAAO;QACN,GAAG,UAAU;QACb,GAAG,QAAQ;QACX,MAAM;KACsB,CAAC;AAC/B,CAAC","sourcesContent":["import { call, type Operation } from \"effection\";\nimport { isGeneratorFunction } from \"./generators.js\";\nimport type {\n\tConfiguredPolicy,\n\tPolicyArgs,\n\tPolicyDefinition,\n\tPolicyHandler,\n\tPolicyHandlerResult,\n\tPolicyInstance,\n\tPolicyInstanceId,\n\tPolicyInstanceSettings,\n\tPolicyName,\n\tPolicyShape,\n} from \"./policy.js\";\n\n// ============================================================================\n// New API: policy() function\n// ============================================================================\n\n/**\n * Options for configuring a policy instance.\n *\n * @alpha\n */\nexport interface PolicyOptions {\n\t/**\n\t * A stable identifier for this configured policy instance.\n\t *\n\t * This is required when the same policy definition is configured more than once.\n\t */\n\tinstanceId?: PolicyInstanceId;\n\n\t/**\n\t * File paths matching these patterns will be excluded from this policy.\n\t * Patterns are matched against repo-relative paths.\n\t */\n\texclude?: (string | RegExp)[];\n}\n\n/**\n * Normalizes a handler to always return an Effection Operation.\n * Detection happens once at registration time, not per-invocation.\n */\nfunction normalizeHandler<C>(\n\thandler: PolicyHandler<C>,\n): (args: PolicyArgs<C>) => Operation<PolicyHandlerResult> {\n\tif (isGeneratorFunction(handler)) {\n\t\t// Already a generator, return as-is\n\t\treturn handler as (args: PolicyArgs<C>) => Operation<PolicyHandlerResult>;\n\t}\n\n\t// Async function - wrap with call()\n\treturn function* (args: PolicyArgs<C>): Operation<PolicyHandlerResult> {\n\t\tconst asyncHandler = handler as (\n\t\t\tpolicyArgs: PolicyArgs<C>,\n\t\t) => Promise<PolicyHandlerResult>;\n\t\treturn yield* call(() => asyncHandler(args));\n\t};\n}\n\n/**\n * Configure a policy for use in repopo.\n *\n * @remarks\n * This function takes a policy definition and returns a configured policy instance\n * that can be added to the `policies` array in `repopo.config.ts`.\n *\n * Handlers are automatically normalized: async functions are wrapped for Effection\n * compatibility, while generator functions are used directly.\n *\n * @example\n * ```typescript\n * // Policy with no config, just options\n * policy(NoJsFileExtensions, { exclude: [\"bin/*\"] })\n *\n * // Policy with config\n * policy(PackageJsonProperties, { verbatim: { license: \"MIT\" } })\n *\n * // Policy with config and options\n * policy(PackageJsonProperties, { verbatim: { license: \"MIT\" } }, { exclude: [\"vendor/*\"] })\n *\n * // Duplicate policies need stable instance IDs\n * policy(PackageJsonProperties, sourceConfig, { instanceId: \"source-packages\" })\n * policy(PackageJsonProperties, testConfig, { instanceId: \"test-packages\" })\n * ```\n *\n * @alpha\n */\nexport function policy<C = void>(\n\tpolicyDef: PolicyShape<C>,\n\toptions?: PolicyOptions & { exclude: (string | RegExp)[] },\n): ConfiguredPolicy<C>;\n/** @alpha */\nexport function policy<C>(\n\tpolicyDef: PolicyShape<C>,\n\tconfig: C,\n\toptions?: PolicyOptions,\n): ConfiguredPolicy<C>;\n/** @alpha */\nexport function policy<C>(\n\tpolicyDef: PolicyShape<C>,\n\tconfigOrOptions?: C | PolicyOptions,\n\tmaybeOptions?: PolicyOptions,\n): ConfiguredPolicy<C> {\n\t// Determine if the second argument is config or options\n\tlet config: C | undefined;\n\tlet options: PolicyOptions | undefined;\n\n\tif (maybeOptions !== undefined) {\n\t\t// Three-argument form: policy(def, config, options)\n\t\tconfig = configOrOptions as C;\n\t\toptions = maybeOptions;\n\t} else if (configOrOptions !== undefined) {\n\t\t// Two-argument form: need to determine if it's config or options\n\t\t// PolicyOptions has a specific shape with 'exclude' property\n\t\tif (\n\t\t\ttypeof configOrOptions === \"object\" &&\n\t\t\tconfigOrOptions !== null &&\n\t\t\t\"exclude\" in configOrOptions &&\n\t\t\t!(\"name\" in configOrOptions) &&\n\t\t\tObject.keys(configOrOptions).every(\n\t\t\t\t(k) => k === \"exclude\" || k === \"instanceId\",\n\t\t\t)\n\t\t) {\n\t\t\t// It's options (has 'exclude' and only option keys)\n\t\t\toptions = configOrOptions as PolicyOptions;\n\t\t} else {\n\t\t\t// It's config\n\t\t\tconfig = configOrOptions as C;\n\t\t}\n\t}\n\n\t// Merge with default config if available\n\tconst effectiveConfig = config ?? (policyDef.defaultConfig as C | undefined);\n\n\t// Support both 'exclude' and 'excludeFiles' for backward compatibility\n\tconst excludePatterns = options?.exclude;\n\n\treturn {\n\t\t...policyDef,\n\t\tconfig: effectiveConfig,\n\t\texclude: excludePatterns,\n\t\texcludeFiles: excludePatterns,\n\t\tinstanceId: options?.instanceId,\n\t\t_internalHandler: normalizeHandler(policyDef.handler),\n\t};\n}\n\n/**\n * Assigns stable identities to configured policy instances.\n *\n * Single instances retain the policy name for compatibility. Duplicate instances\n * must declare explicit identities so their identities remain stable across config\n * reordering and policy renames.\n *\n * @internal\n */\nexport function identifyPolicyInstances<\n\tT extends {\n\t\tname: PolicyName;\n\t\tinstanceId?: PolicyInstanceId | undefined;\n\t},\n>(policies: readonly T[]): (T & { instanceId: PolicyInstanceId })[] {\n\tconst explicitIds = new Set<PolicyInstanceId>();\n\tconst nameCounts = new Map<PolicyName, number>();\n\n\tfor (const configuredPolicy of policies) {\n\t\tnameCounts.set(\n\t\t\tconfiguredPolicy.name,\n\t\t\t(nameCounts.get(configuredPolicy.name) ?? 0) + 1,\n\t\t);\n\t\tif (configuredPolicy.instanceId !== undefined) {\n\t\t\tif (explicitIds.has(configuredPolicy.instanceId)) {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t`Duplicate policy instance ID: ${configuredPolicy.instanceId}`,\n\t\t\t\t);\n\t\t\t}\n\t\t\texplicitIds.add(configuredPolicy.instanceId);\n\t\t}\n\t}\n\n\tconst usedIds = new Set(explicitIds);\n\n\treturn policies.map((configuredPolicy) => {\n\t\tif (configuredPolicy.instanceId !== undefined) {\n\t\t\treturn {\n\t\t\t\t...configuredPolicy,\n\t\t\t\tinstanceId: configuredPolicy.instanceId,\n\t\t\t};\n\t\t}\n\n\t\tif ((nameCounts.get(configuredPolicy.name) ?? 0) > 1) {\n\t\t\tthrow new Error(\n\t\t\t\t`Policy '${configuredPolicy.name}' is configured multiple times. Set a unique instanceId for each instance.`,\n\t\t\t);\n\t\t}\n\n\t\tconst instanceId = configuredPolicy.name;\n\t\tif (usedIds.has(instanceId)) {\n\t\t\tthrow new Error(\n\t\t\t\t`Policy instance ID '${instanceId}' conflicts with another configured policy. Set an explicit unique instanceId.`,\n\t\t\t);\n\t\t}\n\t\tusedIds.add(instanceId);\n\n\t\treturn {\n\t\t\t...configuredPolicy,\n\t\t\tinstanceId,\n\t\t};\n\t});\n}\n\n// ============================================================================\n// Legacy API (Still supported for backward compatibility)\n// ============================================================================\n\n/**\n * Input arguments for creating a policy definition.\n *\n * @deprecated Use {@link PolicyShape} directly instead.\n *\n * @alpha\n */\nexport type PolicyDefinitionInput<C = undefined> = PolicyDefinition<C>;\n\n/**\n * Creates a {@link PolicyDefinition} from the provided arguments.\n *\n * @deprecated Define policies as object literals satisfying {@link PolicyShape} instead.\n *\n * @example\n * ```typescript\n * const MyPolicy = makePolicyDefinition({\n * name: \"MyPolicy\",\n * description: \"Ensures files follow conventions\",\n * match: /\\.ts$/,\n * handler: async ({ file }) => true,\n * });\n * ```\n *\n * @alpha\n */\nexport function makePolicyDefinition<C = undefined>(\n\targs: PolicyDefinitionInput<C>,\n): PolicyDefinition<C> {\n\treturn {\n\t\tname: args.name,\n\t\tdescription: args.description,\n\t\tmatch: args.match,\n\t\thandler: args.handler,\n\t\tdefaultConfig: args.defaultConfig,\n\t\tresolver: args.resolver,\n\t};\n}\n\n/**\n * Combine a {@link PolicyDefinition} with a policy-specific config and other settings.\n *\n * @deprecated Use the `policy` function instead, which has a simpler API.\n *\n * @example\n * ```typescript\n * makePolicy(NoJsFileExtensions, undefined, { excludeFiles: [\"bin/*\"] })\n * ```\n *\n * @alpha\n */\nexport function makePolicy<C>(\n\tdefinition: PolicyDefinition<C>,\n\tconfig?: C,\n\tsettings?: PolicyInstanceSettings<C>,\n): PolicyInstance<C> {\n\treturn {\n\t\t...definition,\n\t\t...settings,\n\t\tconfig,\n\t} satisfies PolicyInstance<C>;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"makePolicy.js","sourceRoot":"","sources":["../src/makePolicy.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AA6C9C,MAAM,UAAU,UAAU,CACzB,UAAqC,EACrC,OAAgC,EAChC,GAAG,KAAgB;IAEnB,MAAM,QAAQ,GACb,2IAA2I,CAAC;IAC7I,IACC,KAAK,CAAC,MAAM,GAAG,CAAC;QAChB,CAAC,OAAO,KAAK,SAAS;YACrB,CAA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GAAG,CAAC,EAAE,CAAC;YACvC,MAAM,IAAI,KAAK,CACd,WAAW,MAAM,CAAC,IAAI,4EAA4E,CAClG,CAAC;QACH,CAAC;QACD,IAAI,GAAG,CAAC,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC;YAC1B,MAAM,IAAI,KAAK,CACd,uBAAuB,MAAM,CAAC,IAAI,gFAAgF,CAClH,CAAC;QACH,CAAC;QACD,GAAG,CAAC,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;QACrB,OAAO,EAAE,GAAG,MAAM,EAAE,UAAU,EAAE,MAAM,CAAC,IAAI,EAAE,CAAC;IAC/C,CAAC,CAAC,CAAC;AACJ,CAAC","sourcesContent":["import { exclusionRegex } from \"./context.js\";\nimport type {\n\tConfiguredFilePolicy,\n\tConfiguredPolicy,\n\tConfiguredRepositoryPolicy,\n\tDefinedConfig,\n\tFilePolicyDefinition,\n\tPolicyDefinition,\n\tPolicyInstanceId,\n\tPolicyName,\n\tPolicyOptions,\n\tRepositoryPolicyDefinition,\n} from \"./policy.js\";\n\ntype ConfigOf<D> = D extends PolicyDefinition<infer C> ? C : never;\ntype RequiredConfigDefinitions<D> = D extends { requiresConfig: true }\n\t? D extends { defaultConfig: infer Default }\n\t\t? undefined extends Default\n\t\t\t? D\n\t\t\t: never\n\t\t: D\n\t: never;\ntype OptionsFor<D> = [RequiredConfigDefinitions<D>] extends [never]\n\t? [options?: PolicyOptions<ConfigOf<D>>]\n\t: [\n\t\t\toptions: PolicyOptions<ConfigOf<D>> & {\n\t\t\t\tconfig: DefinedConfig<ConfigOf<RequiredConfigDefinitions<D>>>;\n\t\t\t},\n\t\t];\n\n/** Configure a file definition using a single options object. @public */\nexport function makePolicy<D extends FilePolicyDefinition<unknown>>(\n\tdefinition: D,\n\t...options: OptionsFor<D>\n): ConfiguredFilePolicy<ConfigOf<D>>;\n/** Configure a repository definition using a single options object. @public */\nexport function makePolicy<D extends RepositoryPolicyDefinition<unknown>>(\n\tdefinition: D,\n\t...options: OptionsFor<D>\n): ConfiguredRepositoryPolicy<ConfigOf<D>>;\n/** Configure a common-union definition without losing scope discrimination. @public */\nexport function makePolicy<D extends PolicyDefinition<unknown>>(\n\tdefinition: D,\n\t...options: OptionsFor<D>\n): ConfiguredPolicy<ConfigOf<D>>;\nexport function makePolicy(\n\tdefinition: PolicyDefinition<unknown>,\n\toptions?: PolicyOptions<unknown>,\n\t...extra: unknown[]\n): ConfiguredPolicy<unknown> {\n\tconst guidance =\n\t\t\"Use makePolicy(definition, { config, exclude, instanceId }); positional config, third arguments and excludeFiles are no longer supported.\";\n\tif (\n\t\textra.length > 0 ||\n\t\t(options !== undefined &&\n\t\t\t(typeof options !== \"object\" ||\n\t\t\t\toptions === null ||\n\t\t\t\tArray.isArray(options) ||\n\t\t\t\tObject.keys(options).some(\n\t\t\t\t\t(key) => ![\"config\", \"exclude\", \"instanceId\"].includes(key),\n\t\t\t\t)))\n\t) {\n\t\tthrow new TypeError(guidance);\n\t}\n\tif (\n\t\tdefinition.scope !== undefined &&\n\t\tdefinition.scope !== \"file\" &&\n\t\tdefinition.resolver !== undefined\n\t) {\n\t\tthrow new TypeError(\n\t\t\t\"Repository policies support inline fixes only; remove resolver.\",\n\t\t);\n\t}\n\tif (\n\t\toptions?.exclude !== undefined &&\n\t\t!(\n\t\t\tArray.isArray(options.exclude) &&\n\t\t\toptions.exclude.every(\n\t\t\t\t(value) => typeof value === \"string\" || value instanceof RegExp,\n\t\t\t)\n\t\t)\n\t) {\n\t\tthrow new TypeError(guidance);\n\t}\n\tif (\n\t\toptions?.instanceId !== undefined &&\n\t\t(typeof options.instanceId !== \"string\" || options.instanceId.length === 0)\n\t) {\n\t\tthrow new TypeError(\"instanceId must be a nonempty string.\");\n\t}\n\toptions?.exclude?.forEach(exclusionRegex);\n\tconst config =\n\t\toptions?.config === undefined ? definition.defaultConfig : options.config;\n\tif (definition.requiresConfig && config === undefined) {\n\t\tthrow new TypeError(\n\t\t\t`Policy '${definition.name}' requires config. ${guidance}`,\n\t\t);\n\t}\n\treturn { ...definition, ...options, config };\n}\n\n/** Assign stable IDs, rejecting ambiguous duplicates. @internal */\nexport function identifyPolicyInstances<\n\tT extends { name: PolicyName; instanceId?: PolicyInstanceId | undefined },\n>(policies: readonly T[]): (T & { instanceId: PolicyInstanceId })[] {\n\tconst names = new Map<string, number>();\n\tconst ids = new Set<string>();\n\tfor (const policy of policies) {\n\t\tnames.set(policy.name, (names.get(policy.name) ?? 0) + 1);\n\t\tif (policy.instanceId !== undefined) {\n\t\t\tif (ids.has(policy.instanceId)) {\n\t\t\t\tthrow new Error(`Duplicate policy instance ID: ${policy.instanceId}`);\n\t\t\t}\n\t\t\tids.add(policy.instanceId);\n\t\t}\n\t}\n\treturn policies.map((policy) => {\n\t\tif (policy.instanceId !== undefined) {\n\t\t\treturn { ...policy, instanceId: policy.instanceId };\n\t\t}\n\t\tif ((names.get(policy.name) ?? 0) > 1) {\n\t\t\tthrow new Error(\n\t\t\t\t`Policy '${policy.name}' is configured multiple times. Set a unique instanceId for each instance.`,\n\t\t\t);\n\t\t}\n\t\tif (ids.has(policy.name)) {\n\t\t\tthrow new Error(\n\t\t\t\t`Policy instance ID '${policy.name}' conflicts with another configured policy. Set an explicit unique instanceId.`,\n\t\t\t);\n\t\t}\n\t\tids.add(policy.name);\n\t\treturn { ...policy, instanceId: policy.name };\n\t});\n}\n"]}
|
package/esm/perf.d.ts
CHANGED
|
@@ -3,16 +3,19 @@ import type { Operation } from "effection";
|
|
|
3
3
|
import type { PolicyInstanceId } from "./policy.js";
|
|
4
4
|
/**
|
|
5
5
|
* The type of action a policy can perform.
|
|
6
|
-
* @
|
|
6
|
+
* @public
|
|
7
7
|
*/
|
|
8
8
|
export type PolicyAction = "check" | "resolve" | "handle";
|
|
9
9
|
/**
|
|
10
10
|
* Stores performance data for each handler. Used to collect and display performance stats.
|
|
11
|
-
* @
|
|
11
|
+
* @public
|
|
12
12
|
*/
|
|
13
13
|
export interface PolicyHandlerPerfStats {
|
|
14
|
+
/** Number of candidate file paths supplied to the runner. */
|
|
14
15
|
count: number;
|
|
16
|
+
/** Number of candidate files admitted past global exclusions. */
|
|
15
17
|
processed: number;
|
|
18
|
+
/** Total elapsed milliseconds per action and configured policy instance. */
|
|
16
19
|
data: Map<PolicyAction, Map<PolicyInstanceId, number>>;
|
|
17
20
|
}
|
|
18
21
|
export declare function newPerfStats(): PolicyHandlerPerfStats;
|
package/esm/perf.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"perf.d.ts","sourceRoot":"","sources":["../src/perf.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAC/C,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAC3C,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAEpD;;;GAGG;AACH,MAAM,MAAM,YAAY,GAAG,OAAO,GAAG,SAAS,GAAG,QAAQ,CAAC;AAE1D;;;GAGG;AACH,MAAM,WAAW,sBAAsB;IACtC,KAAK,EAAE,MAAM,CAAC;IACd,SAAS,EAAE,MAAM,CAAC;IAClB,IAAI,EAAE,GAAG,CAAC,YAAY,EAAE,GAAG,CAAC,gBAAgB,EAAE,MAAM,CAAC,CAAC,CAAC;CACvD;AAED,wBAAgB,YAAY,IAAI,sBAAsB,CAMrD;AAED,wBAAiB,WAAW,CAAC,CAAC,EAC7B,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,YAAY,EACpB,KAAK,EAAE,sBAAsB,EAC7B,GAAG,EAAE,MAAM,SAAS,CAAC,CAAC,CAAC,GACrB,SAAS,CAAC,CAAC,CAAC,
|
|
1
|
+
{"version":3,"file":"perf.d.ts","sourceRoot":"","sources":["../src/perf.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAC/C,OAAO,KAAK,EAAE,S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