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
|
@@ -31,7 +31,7 @@ async function loadSortPackageJson() {
|
|
|
31
31
|
/**
|
|
32
32
|
* A repo policy that checks if package.json files in the repo are sorted using sort-package-json.
|
|
33
33
|
*
|
|
34
|
-
* @
|
|
34
|
+
* @public
|
|
35
35
|
*/
|
|
36
36
|
export const PackageJsonSorted = definePackagePolicy({
|
|
37
37
|
name: "PackageJsonSorted",
|
|
@@ -39,53 +39,38 @@ export const PackageJsonSorted = definePackagePolicy({
|
|
|
39
39
|
handler: async (json, { file, root, resolve }) => {
|
|
40
40
|
const sortPackageJson = await loadSortPackageJson();
|
|
41
41
|
if (sortPackageJson === undefined) {
|
|
42
|
-
const result = {
|
|
43
|
-
name: PackageJsonSorted.name,
|
|
44
|
-
file,
|
|
45
|
-
autoFixable: false,
|
|
46
|
-
errorMessages: [missingDependencyMessage],
|
|
47
|
-
};
|
|
42
|
+
const result = [missingDependencyMessage].map((message) => ({ message }));
|
|
48
43
|
return result;
|
|
49
44
|
}
|
|
50
45
|
const sortedJson = sortPackageJson(json);
|
|
51
46
|
const isSorted = JSON.stringify(sortedJson) === JSON.stringify(json);
|
|
52
47
|
if (isSorted) {
|
|
53
|
-
return
|
|
48
|
+
return [];
|
|
54
49
|
}
|
|
55
50
|
if (resolve) {
|
|
56
51
|
try {
|
|
57
52
|
const packageJsonPath = resolvePath(root, file);
|
|
58
53
|
const indent = await detectIndentation(packageJsonPath);
|
|
59
54
|
await writeJson(packageJsonPath, sortedJson, { spaces: indent });
|
|
60
|
-
const result =
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
resolved: true,
|
|
64
|
-
errorMessages: [],
|
|
65
|
-
};
|
|
55
|
+
const result = [
|
|
56
|
+
{ message: "package.json is not sorted.", fixStatus: "fixed" },
|
|
57
|
+
];
|
|
66
58
|
return result;
|
|
67
59
|
}
|
|
68
60
|
catch (error) {
|
|
69
|
-
const result =
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
error.message,
|
|
76
|
-
error.stack ?? "",
|
|
77
|
-
],
|
|
78
|
-
};
|
|
61
|
+
const result = [
|
|
62
|
+
{
|
|
63
|
+
message: error instanceof Error ? error.message : String(error),
|
|
64
|
+
fixStatus: "failed",
|
|
65
|
+
},
|
|
66
|
+
];
|
|
79
67
|
return result;
|
|
80
68
|
}
|
|
81
69
|
}
|
|
82
70
|
else {
|
|
83
|
-
const result =
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
autoFixable: true,
|
|
87
|
-
errorMessages: [],
|
|
88
|
-
};
|
|
71
|
+
const result = [
|
|
72
|
+
{ message: "package.json is not sorted.", fixStatus: "available" },
|
|
73
|
+
];
|
|
89
74
|
return result;
|
|
90
75
|
}
|
|
91
76
|
},
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PackageJsonSorted.js","sourceRoot":"","sources":["../../src/policies/PackageJsonSorted.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;AAC/E,OAAO,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AAE5D,MAAM,EAAE,SAAS,EAAE,SAAS,EAAE,GAAG,QAAQ,CAAC;AAC1C,MAAM,wBAAwB,GAC7B,8GAA8G,CAAC;AAEhH,SAAS,6BAA6B,CAAC,KAAc;IACpD,IACC,KAAK,YAAY,KAAK;QACtB,MAAM,IAAI,KAAK;QACf,KAAK,CAAC,IAAI,KAAK,sBAAsB;QACrC,KAAK,CAAC,OAAO,CAAC,QAAQ,CAAC,mBAAmB,CAAC,EAC1C,CAAC;QACF,OAAO,IAAI,CAAC;IACb,CAAC;IAED,OAAO,CACN,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AAS,CAAC,UAAU,CAAC,KAAK,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC;QAErE,IAAI,QAAQ,EAAE,CAAC;YACd,OAAO,EAAE,CAAC;QACX,CAAC;QAED,IAAI,OAAO,EAAE,CAAC;YACb,IAAI,CAAC;gBACJ,MAAM,eAAe,GAAG,WAAW,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;gBAChD,MAAM,MAAM,GAAG,MAAM,iBAAiB,CAAC,eAAe,CAAC,CAAC;gBACxD,MAAM,SAAS,CAAC,eAAe,EAAE,UAAU,EAAE,EAAE,MAAM,EAAE,MAAM,EAAE,CAAC,CAAC;gBACjE,MAAM,MAAM,GAAoB;oBAC/B,EAAE,OAAO,EAAE,6BAA6B,EAAE,SAAS,EAAE,OAAO,EAAE;iBAC9D,CAAC;gBACF,OAAO,MAAM,CAAC;YACf,CAAC;YAAC,OAAO,KAAc,EAAE,CAAC;gBACzB,MAAM,MAAM,GAAoB;oBAC/B;wBACC,OAAO,EAAE,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC;wBAC/D,SAAS,EAAE,QAAQ;qBACnB;iBACD,CAAC;gBACF,OAAO,MAAM,CAAC;YACf,CAAC;QACF,CAAC;aAAM,CAAC;YACP,MAAM,MAAM,GAAoB;gBAC/B,EAAE,OAAO,EAAE,6BAA6B,EAAE,SAAS,EAAE,WAAW,EAAE;aAClE,CAAC;YACF,OAAO,MAAM,CAAC;QACf,CAAC;IACF,CAAC;CACD,CAAC,CAAC","sourcesContent":["import jsonfile from \"jsonfile\";\nimport { resolve as resolvePath } from \"pathe\";\nimport type { PolicyFinding } from \"../policy.js\";\nimport { definePackagePolicy } from \"../policyDefiners/definePackagePolicy.js\";\nimport { detectIndentation } from \"../utils/indentation.js\";\n\nconst { writeFile: writeJson } = jsonfile;\nconst missingDependencyMessage =\n\t\"PackageJsonSorted requires the optional peer dependency sort-package-json. Install it to enable this policy.\";\n\nfunction isMissingSortPackageJsonError(error: unknown): boolean {\n\tif (\n\t\terror instanceof Error &&\n\t\t\"code\" in error &&\n\t\terror.code === \"ERR_MODULE_NOT_FOUND\" &&\n\t\terror.message.includes(\"sort-package-json\")\n\t) {\n\t\treturn true;\n\t}\n\n\treturn (\n\t\ttypeof error === \"object\" &&\n\t\terror !== null &&\n\t\t\"cause\" in error &&\n\t\tisMissingSortPackageJsonError(error.cause)\n\t);\n}\n\nasync function loadSortPackageJson() {\n\ttry {\n\t\tconst { sortPackageJson } = await import(\"sort-package-json\");\n\t\treturn sortPackageJson;\n\t} catch (error: unknown) {\n\t\tif (isMissingSortPackageJsonError(error)) {\n\t\t\treturn undefined;\n\t\t}\n\t\tthrow error;\n\t}\n}\n\n/**\n * A repo policy that checks if package.json files in the repo are sorted using sort-package-json.\n *\n * @public\n */\nexport const PackageJsonSorted = definePackagePolicy({\n\tname: \"PackageJsonSorted\",\n\tdescription:\n\t\t\"Ensures package.json files are sorted consistently using sort-package-json.\",\n\thandler: async (json, { file, root, resolve }) => {\n\t\tconst sortPackageJson = await loadSortPackageJson();\n\t\tif (sortPackageJson === undefined) {\n\t\t\tconst result: PolicyFinding[] = [missingDependencyMessage].map(\n\t\t\t\t(message) => ({ message }),\n\t\t\t);\n\t\t\treturn result;\n\t\t}\n\n\t\tconst sortedJson = sortPackageJson(json);\n\t\tconst isSorted = JSON.stringify(sortedJson) === JSON.stringify(json);\n\n\t\tif (isSorted) {\n\t\t\treturn [];\n\t\t}\n\n\t\tif (resolve) {\n\t\t\ttry {\n\t\t\t\tconst packageJsonPath = resolvePath(root, file);\n\t\t\t\tconst indent = await detectIndentation(packageJsonPath);\n\t\t\t\tawait writeJson(packageJsonPath, sortedJson, { spaces: indent });\n\t\t\t\tconst result: PolicyFinding[] = [\n\t\t\t\t\t{ message: \"package.json is not sorted.\", fixStatus: \"fixed\" },\n\t\t\t\t];\n\t\t\t\treturn result;\n\t\t\t} catch (error: unknown) {\n\t\t\t\tconst result: PolicyFinding[] = [\n\t\t\t\t\t{\n\t\t\t\t\t\tmessage: error instanceof Error ? error.message : String(error),\n\t\t\t\t\t\tfixStatus: \"failed\",\n\t\t\t\t\t},\n\t\t\t\t];\n\t\t\t\treturn result;\n\t\t\t}\n\t\t} else {\n\t\t\tconst result: PolicyFinding[] = [\n\t\t\t\t{ message: \"package.json is not sorted.\", fixStatus: \"available\" },\n\t\t\t];\n\t\t\treturn result;\n\t\t}\n\t},\n});\n"]}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Policy settings for the PackageLicense repo policy.
|
|
3
3
|
*
|
|
4
|
-
* @
|
|
4
|
+
* @public
|
|
5
5
|
*/
|
|
6
6
|
export interface PackageLicenseSettings {
|
|
7
7
|
/**
|
|
@@ -50,12 +50,12 @@ export interface PackageLicenseSettings {
|
|
|
50
50
|
* makePolicy(PackageLicense),
|
|
51
51
|
*
|
|
52
52
|
* // Or require LICENSE for all packages including private
|
|
53
|
-
* makePolicy(PackageLicense, { skipPrivate: false }),
|
|
53
|
+
* // makePolicy(PackageLicense, { config: { skipPrivate: false } }),
|
|
54
54
|
* ],
|
|
55
55
|
* };
|
|
56
56
|
* ```
|
|
57
57
|
*
|
|
58
|
-
* @
|
|
58
|
+
* @public
|
|
59
59
|
*/
|
|
60
|
-
export declare const PackageLicense: import("../policy.js").
|
|
60
|
+
export declare const PackageLicense: import("../policy.js").FilePolicyDefinition<PackageLicenseSettings | undefined>;
|
|
61
61
|
//# sourceMappingURL=PackageLicense.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PackageLicense.d.ts","sourceRoot":"","sources":["../../src/policies/PackageLicense.ts"],"names":[],"mappings":"AAOA;;;;GAIG;AACH,MAAM,WAAW,sBAAsB;IACtC;;;;;;;;;;OAUG;IACH,WAAW,CAAC,EAAE,OAAO,CAAC;IAEtB;;;;OAIG;IACH,eAAe,CAAC,EAAE,MAAM,CAAC;CACzB;
|
|
1
|
+
{"version":3,"file":"PackageLicense.d.ts","sourceRoot":"","sources":["../../src/policies/PackageLicense.ts"],"names":[],"mappings":"AAOA;;;;GAIG;AACH,MAAM,WAAW,sBAAsB;IACtC;;;;;;;;;;OAUG;IACH,WAAW,CAAC,EAAE,OAAO,CAAC;IAEtB;;;;OAIG;IACH,eAAe,CAAC,EAAE,MAAM,CAAC;CACzB;AAkCD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AACH,eAAO,MAAM,cAAc,iFA6EzB,CAAC"}
|
|
@@ -6,35 +6,23 @@ const DEFAULT_LICENSE_FILE_NAME = "LICENSE";
|
|
|
6
6
|
const POLICY_NAME = "PackageLicense";
|
|
7
7
|
/**
|
|
8
8
|
* Copies the root LICENSE file to the package directory.
|
|
9
|
-
* @returns
|
|
9
|
+
* @returns Findings that record whether the license was fixed.
|
|
10
10
|
*/
|
|
11
|
-
async function copyLicenseFile(rootLicensePath, packageLicensePath,
|
|
11
|
+
async function copyLicenseFile(rootLicensePath, packageLicensePath, _policyName, _file, packageName, licenseFileName, isCreate) {
|
|
12
12
|
try {
|
|
13
13
|
await copyFile(rootLicensePath, packageLicensePath);
|
|
14
|
-
return
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
errorMessages: [
|
|
20
|
-
isCreate
|
|
21
|
-
? `Created ${licenseFileName} file for package "${packageName}"`
|
|
22
|
-
: `Updated ${licenseFileName} file for package "${packageName}" to match root`,
|
|
23
|
-
],
|
|
24
|
-
};
|
|
14
|
+
return [
|
|
15
|
+
isCreate
|
|
16
|
+
? `Created ${licenseFileName} file for package "${packageName}"`
|
|
17
|
+
: `Updated ${licenseFileName} file for package "${packageName}" to match root`,
|
|
18
|
+
].map((message) => ({ message, fixStatus: "fixed" }));
|
|
25
19
|
}
|
|
26
20
|
catch {
|
|
27
|
-
return
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
errorMessages: [
|
|
33
|
-
isCreate
|
|
34
|
-
? `Failed to copy ${licenseFileName} to package "${packageName}"`
|
|
35
|
-
: `Failed to update ${licenseFileName} for package "${packageName}"`,
|
|
36
|
-
],
|
|
37
|
-
};
|
|
21
|
+
return [
|
|
22
|
+
isCreate
|
|
23
|
+
? `Failed to copy ${licenseFileName} to package "${packageName}"`
|
|
24
|
+
: `Failed to update ${licenseFileName} for package "${packageName}"`,
|
|
25
|
+
].map((message) => ({ message, fixStatus: "failed" }));
|
|
38
26
|
}
|
|
39
27
|
}
|
|
40
28
|
/**
|
|
@@ -64,12 +52,12 @@ async function copyLicenseFile(rootLicensePath, packageLicensePath, policyName,
|
|
|
64
52
|
* makePolicy(PackageLicense),
|
|
65
53
|
*
|
|
66
54
|
* // Or require LICENSE for all packages including private
|
|
67
|
-
* makePolicy(PackageLicense, { skipPrivate: false }),
|
|
55
|
+
* // makePolicy(PackageLicense, { config: { skipPrivate: false } }),
|
|
68
56
|
* ],
|
|
69
57
|
* };
|
|
70
58
|
* ```
|
|
71
59
|
*
|
|
72
|
-
* @
|
|
60
|
+
* @public
|
|
73
61
|
*/
|
|
74
62
|
export const PackageLicense = definePackagePolicy({
|
|
75
63
|
name: "PackageLicense",
|
|
@@ -79,7 +67,7 @@ export const PackageLicense = definePackagePolicy({
|
|
|
79
67
|
const licenseFileName = config?.licenseFileName ?? DEFAULT_LICENSE_FILE_NAME;
|
|
80
68
|
// Skip private packages if configured to do so
|
|
81
69
|
if (skipPrivate && json.private === true) {
|
|
82
|
-
return
|
|
70
|
+
return [];
|
|
83
71
|
}
|
|
84
72
|
const packageName = json.name ?? "unknown";
|
|
85
73
|
const packageDir = path.dirname(path.resolve(root, file));
|
|
@@ -87,28 +75,21 @@ export const PackageLicense = definePackagePolicy({
|
|
|
87
75
|
const rootLicensePath = path.join(root, licenseFileName);
|
|
88
76
|
// Check if root LICENSE exists
|
|
89
77
|
if (!existsSync(rootLicensePath)) {
|
|
90
|
-
return
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
autoFixable: false,
|
|
94
|
-
errorMessages: [
|
|
95
|
-
`Cannot validate package LICENSE: root ${licenseFileName} file not found`,
|
|
96
|
-
],
|
|
97
|
-
};
|
|
78
|
+
return [
|
|
79
|
+
`Cannot validate package LICENSE: root ${licenseFileName} file not found`,
|
|
80
|
+
].map((message) => ({ message }));
|
|
98
81
|
}
|
|
99
82
|
// Check if package LICENSE exists
|
|
100
83
|
if (!existsSync(packageLicensePath)) {
|
|
101
84
|
if (resolve) {
|
|
102
85
|
return await copyLicenseFile(rootLicensePath, packageLicensePath, POLICY_NAME, file, packageName, licenseFileName, true);
|
|
103
86
|
}
|
|
104
|
-
return
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
],
|
|
111
|
-
};
|
|
87
|
+
return [
|
|
88
|
+
`${licenseFileName} file missing for package "${packageName}"`,
|
|
89
|
+
].map((message) => ({
|
|
90
|
+
message,
|
|
91
|
+
fixStatus: "available",
|
|
92
|
+
}));
|
|
112
93
|
}
|
|
113
94
|
// Compare package LICENSE with root LICENSE
|
|
114
95
|
const [packageLicenseContent, rootLicenseContent] = await Promise.all([
|
|
@@ -119,16 +100,14 @@ export const PackageLicense = definePackagePolicy({
|
|
|
119
100
|
if (resolve) {
|
|
120
101
|
return await copyLicenseFile(rootLicensePath, packageLicensePath, POLICY_NAME, file, packageName, licenseFileName, false);
|
|
121
102
|
}
|
|
122
|
-
return
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
],
|
|
129
|
-
};
|
|
103
|
+
return [
|
|
104
|
+
`${licenseFileName} file in package "${packageName}" doesn't match root ${licenseFileName}`,
|
|
105
|
+
].map((message) => ({
|
|
106
|
+
message,
|
|
107
|
+
fixStatus: "available",
|
|
108
|
+
}));
|
|
130
109
|
}
|
|
131
|
-
return
|
|
110
|
+
return [];
|
|
132
111
|
},
|
|
133
112
|
});
|
|
134
113
|
//# sourceMappingURL=PackageLicense.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PackageLicense.js","sourceRoot":"","sources":["../../src/policies/PackageLicense.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AACrC,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AACtD,OAAO,IAAI,MAAM,OAAO,CAAC;AAGzB,OAAO,EAAE,mBAAmB,EAAE,MAAM,0CAA0C,CAAC;AA6B/E,MAAM,yBAAyB,GAAG,SAAS,CAAC;AAC5C,MAAM,WAAW,GAAG,gBAAgB,CAAC;AAErC;;;GAGG;AACH,KAAK,UAAU,eAAe,CAC7B,eAAuB,EACvB,kBAA0B,EAC1B,
|
|
1
|
+
{"version":3,"file":"PackageLicense.js","sourceRoot":"","sources":["../../src/policies/PackageLicense.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AACrC,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AACtD,OAAO,IAAI,MAAM,OAAO,CAAC;AAGzB,OAAO,EAAE,mBAAmB,EAAE,MAAM,0CAA0C,CAAC;AA6B/E,MAAM,yBAAyB,GAAG,SAAS,CAAC;AAC5C,MAAM,WAAW,GAAG,gBAAgB,CAAC;AAErC;;;GAGG;AACH,KAAK,UAAU,eAAe,CAC7B,eAAuB,EACvB,kBAA0B,EAC1B,WAAmB,EACnB,KAAa,EACb,WAAmB,EACnB,eAAuB,EACvB,QAAiB;IAEjB,IAAI,CAAC;QACJ,MAAM,QAAQ,CAAC,eAAe,EAAE,kBAAkB,CAAC,CAAC;QACpD,OAAO;YACN,QAAQ;gBACP,CAAC,CAAC,WAAW,eAAe,sBAAsB,WAAW,GAAG;gBAChE,CAAC,CAAC,WAAW,eAAe,sBAAsB,WAAW,iBAAiB;SAC/E,CAAC,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C,CAAC;QACL,CAAC;QACD,OAAO,EAAE,CAAC;IACX,CAAC;CACD,CAAC,CAAC","sourcesContent":["import { existsSync } from \"node:fs\";\nimport { copyFile, readFile } from \"node:fs/promises\";\nimport path from \"pathe\";\nimport type { PackageJson } from \"type-fest\";\nimport type { PolicyFinding } from \"../policy.js\";\nimport { definePackagePolicy } from \"../policyDefiners/definePackagePolicy.js\";\n\n/**\n * Policy settings for the PackageLicense repo policy.\n *\n * @public\n */\nexport interface PackageLicenseSettings {\n\t/**\n\t * Whether to skip validation for private packages.\n\t *\n\t * @defaultValue true\n\t *\n\t * @remarks\n\t *\n\t * Private packages (those with `private: true` in package.json) are typically\n\t * not published and may not need a LICENSE file. Set to `false` to require\n\t * LICENSE files for all packages.\n\t */\n\tskipPrivate?: boolean;\n\n\t/**\n\t * The name of the LICENSE file to look for and sync.\n\t *\n\t * @defaultValue \"LICENSE\"\n\t */\n\tlicenseFileName?: string;\n}\n\nconst DEFAULT_LICENSE_FILE_NAME = \"LICENSE\";\nconst POLICY_NAME = \"PackageLicense\";\n\n/**\n * Copies the root LICENSE file to the package directory.\n * @returns Findings that record whether the license was fixed.\n */\nasync function copyLicenseFile(\n\trootLicensePath: string,\n\tpackageLicensePath: string,\n\t_policyName: string,\n\t_file: string,\n\tpackageName: string,\n\tlicenseFileName: string,\n\tisCreate: boolean,\n): Promise<PolicyFinding[]> {\n\ttry {\n\t\tawait copyFile(rootLicensePath, packageLicensePath);\n\t\treturn [\n\t\t\tisCreate\n\t\t\t\t? `Created ${licenseFileName} file for package \"${packageName}\"`\n\t\t\t\t: `Updated ${licenseFileName} file for package \"${packageName}\" to match root`,\n\t\t].map((message) => ({ message, fixStatus: \"fixed\" }));\n\t} catch {\n\t\treturn [\n\t\t\tisCreate\n\t\t\t\t? `Failed to copy ${licenseFileName} to package \"${packageName}\"`\n\t\t\t\t: `Failed to update ${licenseFileName} for package \"${packageName}\"`,\n\t\t].map((message) => ({ message, fixStatus: \"failed\" }));\n\t}\n}\n\n/**\n * A repo policy that ensures each package has a LICENSE file that matches the root LICENSE.\n *\n * @remarks\n *\n * This policy is essential for monorepos where individual packages are published\n * to npm. Each published package should include a LICENSE file, and it should\n * match the root repository's LICENSE to ensure consistent licensing.\n *\n * The policy:\n * 1. Checks if a LICENSE file exists in the package directory\n * 2. Compares it with the root LICENSE file\n * 3. Can auto-fix by copying the root LICENSE to the package directory\n *\n * By default, private packages are skipped since they're not published.\n *\n * @example\n * ```typescript\n * import { makePolicy } from \"repopo\";\n * import { PackageLicense } from \"repopo/policies\";\n *\n * const config: RepopoConfig = {\n * policies: [\n * // Use defaults (skip private, look for LICENSE)\n * makePolicy(PackageLicense),\n *\n * // Or require LICENSE for all packages including private\n * // makePolicy(PackageLicense, { config: { skipPrivate: false } }),\n * ],\n * };\n * ```\n *\n * @public\n */\nexport const PackageLicense = definePackagePolicy<\n\tPackageJson,\n\tPackageLicenseSettings | undefined\n>({\n\tname: \"PackageLicense\",\n\tdescription:\n\t\t\"Ensures each package has a LICENSE file that matches the root repository LICENSE.\",\n\thandler: async (json, { file, root, resolve, config }) => {\n\t\tconst skipPrivate = config?.skipPrivate ?? true;\n\t\tconst licenseFileName =\n\t\t\tconfig?.licenseFileName ?? DEFAULT_LICENSE_FILE_NAME;\n\n\t\t// Skip private packages if configured to do so\n\t\tif (skipPrivate && json.private === true) {\n\t\t\treturn [];\n\t\t}\n\n\t\tconst packageName = json.name ?? \"unknown\";\n\t\tconst packageDir = path.dirname(path.resolve(root, file));\n\t\tconst packageLicensePath = path.join(packageDir, licenseFileName);\n\t\tconst rootLicensePath = path.join(root, licenseFileName);\n\n\t\t// Check if root LICENSE exists\n\t\tif (!existsSync(rootLicensePath)) {\n\t\t\treturn [\n\t\t\t\t`Cannot validate package LICENSE: root ${licenseFileName} file not found`,\n\t\t\t].map((message) => ({ message }));\n\t\t}\n\n\t\t// Check if package LICENSE exists\n\t\tif (!existsSync(packageLicensePath)) {\n\t\t\tif (resolve) {\n\t\t\t\treturn await copyLicenseFile(\n\t\t\t\t\trootLicensePath,\n\t\t\t\t\tpackageLicensePath,\n\t\t\t\t\tPOLICY_NAME,\n\t\t\t\t\tfile,\n\t\t\t\t\tpackageName,\n\t\t\t\t\tlicenseFileName,\n\t\t\t\t\ttrue,\n\t\t\t\t);\n\t\t\t}\n\t\t\treturn [\n\t\t\t\t`${licenseFileName} file missing for package \"${packageName}\"`,\n\t\t\t].map((message) => ({\n\t\t\t\tmessage,\n\t\t\t\tfixStatus: \"available\",\n\t\t\t}));\n\t\t}\n\n\t\t// Compare package LICENSE with root LICENSE\n\t\tconst [packageLicenseContent, rootLicenseContent] = await Promise.all([\n\t\t\treadFile(packageLicensePath, \"utf-8\"),\n\t\t\treadFile(rootLicensePath, \"utf-8\"),\n\t\t]);\n\n\t\tif (packageLicenseContent !== rootLicenseContent) {\n\t\t\tif (resolve) {\n\t\t\t\treturn await copyLicenseFile(\n\t\t\t\t\trootLicensePath,\n\t\t\t\t\tpackageLicensePath,\n\t\t\t\t\tPOLICY_NAME,\n\t\t\t\t\tfile,\n\t\t\t\t\tpackageName,\n\t\t\t\t\tlicenseFileName,\n\t\t\t\t\tfalse,\n\t\t\t\t);\n\t\t\t}\n\t\t\treturn [\n\t\t\t\t`${licenseFileName} file in package \"${packageName}\" doesn't match root ${licenseFileName}`,\n\t\t\t].map((message) => ({\n\t\t\t\tmessage,\n\t\t\t\tfixStatus: \"available\",\n\t\t\t}));\n\t\t}\n\t\treturn [];\n\t},\n});\n"]}
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
* };
|
|
20
20
|
* ```
|
|
21
21
|
*
|
|
22
|
-
* @
|
|
22
|
+
* @public
|
|
23
23
|
*/
|
|
24
24
|
export interface PackagePrivateFieldConfig {
|
|
25
25
|
/**
|
|
@@ -30,7 +30,7 @@ export interface PackagePrivateFieldConfig {
|
|
|
30
30
|
*
|
|
31
31
|
* @remarks
|
|
32
32
|
*
|
|
33
|
-
* Uses glob patterns via picomatch. Use
|
|
33
|
+
* Uses glob patterns via picomatch. Use `@scope/*` to match all packages in a scope,
|
|
34
34
|
* or use exact package names.
|
|
35
35
|
*
|
|
36
36
|
* @example
|
|
@@ -109,16 +109,20 @@ export interface PackagePrivateFieldConfig {
|
|
|
109
109
|
* const config: RepopoConfig = {
|
|
110
110
|
* policies: [
|
|
111
111
|
* makePolicy(PackagePrivateField, {
|
|
112
|
-
*
|
|
113
|
-
*
|
|
114
|
-
*
|
|
115
|
-
*
|
|
112
|
+
* config: {
|
|
113
|
+
* mustPublish: ["@myorg/*"],
|
|
114
|
+
* mustBePrivate: ["@internal/*"],
|
|
115
|
+
* mayPublish: ["@experimental/*"],
|
|
116
|
+
* unmatchedPackages: "private",
|
|
117
|
+
* },
|
|
116
118
|
* }),
|
|
117
119
|
* ],
|
|
118
120
|
* };
|
|
119
121
|
* ```
|
|
120
122
|
*
|
|
121
|
-
* @
|
|
123
|
+
* @public
|
|
122
124
|
*/
|
|
123
|
-
export declare const PackagePrivateField: import("../policy.js").
|
|
125
|
+
export declare const PackagePrivateField: import("../policy.js").FilePolicyDefinition<PackagePrivateFieldConfig | undefined> & {
|
|
126
|
+
requiresConfig: true;
|
|
127
|
+
};
|
|
124
128
|
//# sourceMappingURL=PackagePrivateField.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PackagePrivateField.d.ts","sourceRoot":"","sources":["../../src/policies/PackagePrivateField.ts"],"names":[],"mappings":"AAuBA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,MAAM,WAAW,yBAAyB;IACzC;;;;;;;;;;;;;;;OAeG;IACH,WAAW,CAAC,EAAE,MAAM,EAAE,CAAC;IAEvB;;;;;;;;;;;;;;OAcG;IACH,aAAa,CAAC,EAAE,MAAM,EAAE,CAAC;IAEzB;;;;;;;;;;;;;;;OAeG;IACH,UAAU,CAAC,EAAE,MAAM,EAAE,CAAC;IAEtB;;;;;;;;OAQG;IACH,iBAAiB,CAAC,EAAE,SAAS,GAAG,QAAQ,GAAG,QAAQ,CAAC;CACpD;AA+DD
|
|
1
|
+
{"version":3,"file":"PackagePrivateField.d.ts","sourceRoot":"","sources":["../../src/policies/PackagePrivateField.ts"],"names":[],"mappings":"AAuBA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,MAAM,WAAW,yBAAyB;IACzC;;;;;;;;;;;;;;;OAeG;IACH,WAAW,CAAC,EAAE,MAAM,EAAE,CAAC;IAEvB;;;;;;;;;;;;;;OAcG;IACH,aAAa,CAAC,EAAE,MAAM,EAAE,CAAC;IAEzB;;;;;;;;;;;;;;;OAeG;IACH,UAAU,CAAC,EAAE,MAAM,EAAE,CAAC;IAEtB;;;;;;;;OAQG;IACH,iBAAiB,CAAC,EAAE,SAAS,GAAG,QAAQ,GAAG,QAAQ,CAAC;CACpD;AA+DD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsCG;AACH,eAAO,MAAM,mBAAmB;;CAsF9B,CAAC"}
|
|
@@ -83,59 +83,60 @@ function getRequiredPrivateState(packageName, config) {
|
|
|
83
83
|
* const config: RepopoConfig = {
|
|
84
84
|
* policies: [
|
|
85
85
|
* makePolicy(PackagePrivateField, {
|
|
86
|
-
*
|
|
87
|
-
*
|
|
88
|
-
*
|
|
89
|
-
*
|
|
86
|
+
* config: {
|
|
87
|
+
* mustPublish: ["@myorg/*"],
|
|
88
|
+
* mustBePrivate: ["@internal/*"],
|
|
89
|
+
* mayPublish: ["@experimental/*"],
|
|
90
|
+
* unmatchedPackages: "private",
|
|
91
|
+
* },
|
|
90
92
|
* }),
|
|
91
93
|
* ],
|
|
92
94
|
* };
|
|
93
95
|
* ```
|
|
94
96
|
*
|
|
95
|
-
* @
|
|
97
|
+
* @public
|
|
96
98
|
*/
|
|
97
99
|
export const PackagePrivateField = definePackagePolicy({
|
|
98
100
|
name: "PackagePrivateField",
|
|
101
|
+
requiresConfig: true,
|
|
99
102
|
description: "Enforces the private field in package.json based on package scope or name patterns.",
|
|
100
103
|
handler: async (json, { file, root, config, resolve }) => {
|
|
101
104
|
// If no config provided, skip validation
|
|
102
105
|
if (config === undefined) {
|
|
103
|
-
return
|
|
106
|
+
return [];
|
|
104
107
|
}
|
|
105
108
|
const packageName = json.name;
|
|
106
109
|
// Skip packages without a name (shouldn't happen in practice)
|
|
107
110
|
if (packageName === undefined) {
|
|
108
|
-
return
|
|
111
|
+
return [];
|
|
109
112
|
}
|
|
110
113
|
// Skip the root package (typically named "root" in monorepos)
|
|
111
114
|
if (packageName === "root") {
|
|
112
|
-
return
|
|
115
|
+
return [];
|
|
113
116
|
}
|
|
114
117
|
const requiredState = getRequiredPrivateState(packageName, config);
|
|
115
118
|
// If "ignore", the package can be either private or public
|
|
116
119
|
if (requiredState === IGNORE_PRIVATE_STATE) {
|
|
117
|
-
return
|
|
120
|
+
return [];
|
|
118
121
|
}
|
|
119
122
|
const currentlyPrivate = json.private === true;
|
|
120
123
|
// Check if the current state matches the required state
|
|
121
124
|
if (requiredState === currentlyPrivate) {
|
|
122
|
-
return
|
|
125
|
+
return [];
|
|
123
126
|
}
|
|
124
127
|
// State mismatch - build error message
|
|
125
128
|
const errorMessage = requiredState === true
|
|
126
129
|
? `Package "${packageName}" must be marked private. Add "private": true to package.json.`
|
|
127
130
|
: `Package "${packageName}" must not be marked private. Remove "private": true from package.json to allow publishing.`;
|
|
128
|
-
const failResult = {
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
errorMessages: [errorMessage],
|
|
133
|
-
};
|
|
131
|
+
const failResult = [errorMessage].map((message) => ({
|
|
132
|
+
message,
|
|
133
|
+
fixStatus: "available",
|
|
134
|
+
}));
|
|
134
135
|
if (resolve) {
|
|
135
|
-
const fixResult = {
|
|
136
|
-
...
|
|
137
|
-
|
|
138
|
-
};
|
|
136
|
+
const fixResult = failResult.map((finding) => ({
|
|
137
|
+
...finding,
|
|
138
|
+
fixStatus: "failed",
|
|
139
|
+
}));
|
|
139
140
|
try {
|
|
140
141
|
if (requiredState === true) {
|
|
141
142
|
// Add private: true
|
|
@@ -146,11 +147,18 @@ export const PackagePrivateField = definePackagePolicy({
|
|
|
146
147
|
delete json.private;
|
|
147
148
|
}
|
|
148
149
|
await writeJson(resolvePath(root, file), json, { spaces: "\t" });
|
|
149
|
-
fixResult
|
|
150
|
+
for (const finding of fixResult) {
|
|
151
|
+
finding.fixStatus = "fixed";
|
|
152
|
+
}
|
|
150
153
|
}
|
|
151
154
|
catch {
|
|
152
|
-
fixResult
|
|
153
|
-
|
|
155
|
+
for (const finding of fixResult) {
|
|
156
|
+
finding.fixStatus = "failed";
|
|
157
|
+
}
|
|
158
|
+
fixResult.splice(0, fixResult.length, ...[`Failed to update ${file}`].map((message) => ({
|
|
159
|
+
...fixResult[0],
|
|
160
|
+
message,
|
|
161
|
+
})));
|
|
154
162
|
}
|
|
155
163
|
return fixResult;
|
|
156
164
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PackagePrivateField.js","sourceRoot":"","sources":["../../src/policies/PackagePrivateField.ts"],"names":[],"mappings":"AAAA,OAAO,QAAQ,MAAM,UAAU,CAAC;AAChC,OAAO,EAAE,OAAO,IAAI,WAAW,EAAE,MAAM,OAAO,CAAC;AAC/C,OAAO,SAAS,MAAM,WAAW,CAAC;AAGlC,OAAO,EAAE,mBAAmB,EAAE,MAAM,0CAA0C,CAAC;AAE/E,MAAM,EAAE,SAAS,EAAE,SAAS,EAAE,GAAG,QAAQ,CAAC;AAE1C;;;GAGG;AACH,MAAM,oBAAoB,GAAG,QAAiB,CAAC;AAmG/C;;;;;;;;;;;GAWG;AACH,SAAS,iBAAiB,CACzB,WAAmB,EACnB,QAA8B;IAE9B,IAAI,QAAQ,KAAK,SAAS,IAAI,QAAQ,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACrD,OAAO,KAAK,CAAC;IACd,CAAC;IAED,OAAO,SAAS,CAAC,OAAO,CAAC,WAAW,EAAE,QAAQ,CAAC,CAAC;AACjD,CAAC;AAED;;;;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3B,CAAC;YAAC,MAAM,CAAC;gBACR,SAAS,CAAC,QAAQ,GAAG,KAAK,CAAC;gBAC3B,SAAS,CAAC,aAAa,GAAG,CAAC,oBAAoB,IAAI,EAAE,CAAC,CAAC;YACxD,CAAC;YAED,OAAO,SAAS,CAAC;QAClB,CAAC;QAED,OAAO,UAAU,CAAC;IACnB,CAAC;CACD,CAAC,CAAC","sourcesContent":["import jsonfile from \"jsonfile\";\nimport { resolve as resolvePath } from \"pathe\";\nimport picomatch from \"picomatch\";\nimport type { PackageJson } from \"type-fest\";\nimport type { PolicyFailure, PolicyFixResult } from \"../policy.js\";\nimport { definePackagePolicy } from \"../policyDefiners/definePackagePolicy.js\";\n\nconst { writeFile: writeJson } = jsonfile;\n\n/**\n * Sentinel value indicating that the package's private status should not be enforced.\n * This is more explicit than using `undefined` to represent \"ignore\".\n */\nconst IGNORE_PRIVATE_STATE = \"ignore\" as const;\n\n/**\n * The required private state for a package.\n * - `true`: Package must have `private: true`\n * - `false`: Package must NOT have `private: true`\n * - `\"ignore\"`: No enforcement - package can be either private or public\n */\ntype RequiredPrivateState = boolean | typeof IGNORE_PRIVATE_STATE;\n\n/**\n * Configuration for the PackagePrivateField policy.\n *\n * This policy enforces that packages are correctly marked as private or public based on\n * their scope or name. This is essential for monorepos where some packages should be\n * published to npm while others should remain internal.\n *\n * All pattern matching uses glob patterns via picomatch.\n *\n * @example\n * ```typescript\n * const config: PackagePrivateFieldConfig = {\n * // Packages in myorg scope must be published (private: false or absent)\n * mustPublish: [\"@myorg/*\"],\n * // Packages in internal scope must be private\n * mustBePrivate: [\"@internal/*\"],\n * // Packages in experimental scope can choose\n * mayPublish: [\"@experimental/*\"],\n * };\n * ```\n *\n * @alpha\n */\nexport interface PackagePrivateFieldConfig {\n\t/**\n\t * A list of glob patterns for packages that must be published.\n\t *\n\t * Packages matching these patterns must NOT have `private: true` in their package.json.\n\t * If they do, the policy will fail and can auto-fix by removing the private field.\n\t *\n\t * @remarks\n\t *\n\t * Uses glob patterns via picomatch. Use \"@scope/*\" to match all packages in a scope,\n\t * or use exact package names.\n\t *\n\t * @example\n\t * ```typescript\n\t * mustPublish: [\"@fluidframework/*\", \"@fluid-tools/*\", \"tinylicious\"]\n\t * ```\n\t */\n\tmustPublish?: string[];\n\n\t/**\n\t * A list of glob patterns for packages that must be private.\n\t *\n\t * Packages matching these patterns must have `private: true` in their package.json.\n\t * If they don't, the policy will fail and can auto-fix by adding `private: true`.\n\t *\n\t * @remarks\n\t *\n\t * Uses glob patterns via picomatch (see mustPublish for pattern examples).\n\t *\n\t * @example\n\t * ```typescript\n\t * mustBePrivate: [\"@fluid-internal/*\", \"@fluid-private/*\"]\n\t * ```\n\t */\n\tmustBePrivate?: string[];\n\n\t/**\n\t * A list of glob patterns for packages that may optionally be published.\n\t *\n\t * Packages matching these patterns can choose whether to be private or public.\n\t * The policy will not enforce either state for these packages.\n\t *\n\t * @remarks\n\t *\n\t * Uses glob patterns via picomatch (see mustPublish for pattern examples).\n\t * Packages not matching any list default to requiring `private: true`.\n\t *\n\t * @example\n\t * ```typescript\n\t * mayPublish: [\"@fluid-experimental/*\"]\n\t * ```\n\t */\n\tmayPublish?: string[];\n\n\t/**\n\t * Default behavior for packages that don't match any of the above lists.\n\t *\n\t * - `\"private\"` (default): Unmatched packages must have `private: true`\n\t * - `\"public\"`: Unmatched packages must NOT have `private: true`\n\t * - `\"ignore\"`: No enforcement for unmatched packages\n\t *\n\t * @defaultValue \"private\"\n\t */\n\tunmatchedPackages?: \"private\" | \"public\" | \"ignore\";\n}\n\n/**\n * Check if a package name matches any pattern in the list.\n *\n * Supports glob patterns via picomatch. Use patterns like:\n * - \"@myorg/\\*\" - matches all packages in the myorg scope\n * - \"my-package\" - exact match\n * - \"my-*\" - matches my-foo, my-bar, etc.\n *\n * @param packageName - The package name to check (e.g., `@myorg/foo`)\n * @param patterns - List of glob patterns or exact package names\n * @returns `true` if the package matches any pattern\n */\nfunction matchesAnyPattern(\n\tpackageName: string,\n\tpatterns: string[] | undefined,\n): boolean {\n\tif (patterns === undefined || patterns.length === 0) {\n\t\treturn false;\n\t}\n\n\treturn picomatch.isMatch(packageName, patterns);\n}\n\n/**\n * Determine what the private field should be for a package.\n *\n * @returns `true` if package must be private, `false` if must be public, `\"ignore\"` if either is ok\n */\nfunction getRequiredPrivateState(\n\tpackageName: string,\n\tconfig: PackagePrivateFieldConfig,\n): RequiredPrivateState {\n\t// Check mustPublish first - these packages must NOT be private\n\tif (matchesAnyPattern(packageName, config.mustPublish)) {\n\t\treturn false;\n\t}\n\n\t// Check mustBePrivate - these packages MUST be private\n\tif (matchesAnyPattern(packageName, config.mustBePrivate)) {\n\t\treturn true;\n\t}\n\n\t// Check mayPublish - these packages can be either\n\tif (matchesAnyPattern(packageName, config.mayPublish)) {\n\t\treturn IGNORE_PRIVATE_STATE;\n\t}\n\n\t// Default behavior for unmatched packages\n\tconst unmatchedBehavior = config.unmatchedPackages ?? \"private\";\n\tswitch (unmatchedBehavior) {\n\t\tcase \"private\":\n\t\t\treturn true;\n\t\tcase \"public\":\n\t\t\treturn false;\n\t\tcase \"ignore\":\n\t\t\treturn IGNORE_PRIVATE_STATE;\n\t\tdefault:\n\t\t\tthrow new Error(`Unknown unmatchedPackages value: ${unmatchedBehavior}`);\n\t}\n}\n\n/**\n * A policy that enforces the `private` field in package.json based on package scope or name.\n *\n * This policy is essential for monorepos where publishing control is important:\n *\n * - Prevent accidental publishing of internal packages\n * - Ensure public packages don't have `private: true` blocking publishing\n * - Allow experimental packages to choose their own publishing status\n *\n * @remarks\n *\n * The policy evaluates packages in the following order:\n *\n * 1. If the package matches `mustPublish`, it must NOT have `private: true`\n * 2. If the package matches `mustBePrivate`, it MUST have `private: true`\n * 3. If the package matches `mayPublish`, no enforcement is applied\n * 4. Otherwise, the `unmatchedPackages` setting determines behavior (defaults to requiring private)\n *\n * @example\n * ```typescript\n * import { makePolicy } from \"repopo\";\n * import { PackagePrivateField } from \"repopo/policies\";\n *\n * const config: RepopoConfig = {\n * policies: [\n * makePolicy(PackagePrivateField, {\n * mustPublish: [\"@myorg/*\"],\n * mustBePrivate: [\"@internal/*\"],\n * mayPublish: [\"@experimental/*\"],\n * unmatchedPackages: \"private\",\n * }),\n * ],\n * };\n * ```\n *\n * @alpha\n */\nexport const PackagePrivateField = definePackagePolicy<\n\tPackageJson,\n\tPackagePrivateFieldConfig | undefined\n>({\n\tname: \"PackagePrivateField\",\n\tdescription:\n\t\t\"Enforces the private field in package.json based on package scope or name patterns.\",\n\thandler: async (json, { file, root, config, resolve }) => {\n\t\t// If no config provided, skip validation\n\t\tif (config === undefined) {\n\t\t\treturn true;\n\t\t}\n\n\t\tconst packageName = json.name;\n\n\t\t// Skip packages without a name (shouldn't happen in practice)\n\t\tif (packageName === undefined) {\n\t\t\treturn true;\n\t\t}\n\n\t\t// Skip the root package (typically named \"root\" in monorepos)\n\t\tif (packageName === \"root\") {\n\t\t\treturn true;\n\t\t}\n\n\t\tconst requiredState = getRequiredPrivateState(packageName, config);\n\n\t\t// If \"ignore\", the package can be either private or public\n\t\tif (requiredState === IGNORE_PRIVATE_STATE) {\n\t\t\treturn true;\n\t\t}\n\n\t\tconst currentlyPrivate = json.private === true;\n\n\t\t// Check if the current state matches the required state\n\t\tif (requiredState === currentlyPrivate) {\n\t\t\treturn true;\n\t\t}\n\n\t\t// State mismatch - build error message\n\t\tconst errorMessage =\n\t\t\trequiredState === true\n\t\t\t\t? `Package \"${packageName}\" must be marked private. Add \"private\": true to package.json.`\n\t\t\t\t: `Package \"${packageName}\" must not be marked private. Remove \"private\": true from package.json to allow publishing.`;\n\n\t\tconst failResult: PolicyFailure = {\n\t\t\tname: PackagePrivateField.name,\n\t\t\tfile,\n\t\t\tautoFixable: true,\n\t\t\terrorMessages: [errorMessage],\n\t\t};\n\n\t\tif (resolve) {\n\t\t\tconst fixResult: PolicyFixResult = {\n\t\t\t\t...failResult,\n\t\t\t\tresolved: false,\n\t\t\t};\n\n\t\t\ttry {\n\t\t\t\tif (requiredState === true) {\n\t\t\t\t\t// Add private: true\n\t\t\t\t\tjson.private = true;\n\t\t\t\t} else {\n\t\t\t\t\t// Remove private field\n\t\t\t\t\tdelete json.private;\n\t\t\t\t}\n\n\t\t\t\tawait writeJson(resolvePath(root, file), json, { spaces: \"\\t\" });\n\t\t\t\tfixResult.resolved = true;\n\t\t\t} catch {\n\t\t\t\tfixResult.resolved = false;\n\t\t\t\tfixResult.errorMessages = [`Failed to update ${file}`];\n\t\t\t}\n\n\t\t\treturn fixResult;\n\t\t}\n\n\t\treturn failResult;\n\t},\n});\n"]}
|
|
1
|
+
{"version":3,"file":"PackagePrivateField.js","sourceRoot":"","sources":["../../src/policies/PackagePrivateField.ts"],"names":[],"mappings":"AAAA,OAAO,QAAQ,MAAM,UAAU,CAAC;AAChC,OAAO,EAAE,OAAO,IAAI,WAAW,EAAE,MAAM,OAAO,CAAC;AAC/C,OAAO,SAAS,MAAM,WAAW,CAAC;AAGlC,OAAO,EAAE,mBAAmB,EAAE,MAAM,0CAA0C,CAAC;AAE/E,MAAM,EAAE,SAAS,EAAE,SAAS,EAAE,GAAG,QAAQ,CAAC;AAE1C;;;GAGG;AACH,MAAM,oBAAoB,GAAG,QAAiB,CAAC;AAmG/C;;;;;;;;;;;GAWG;AACH,SAAS,iBAAiB,CACzB,WAAmB,EACnB,QAA8B;IAE9B,IAAI,QAAQ,KAAK,SAAS,IAAI,QAAQ,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACrD,OAAO,KAAK,CAAC;IACd,CAAC;IAED,OAAO,SAAS,CAAC,OAAO,CAAC,WAAW,EAAE,QAAQ,CAAC,CAAC;AACjD,CAAC;AAED;;;;GAIG;AACH,SAAS,uBAAuB,CAC/B,WAAmB,EACnB,MAAiC;IAEjC,+DAA+D;IAC/D,IAAI,iBAAiB,CAAC,WAAW,EAAE,MAAM,CAAC,WAAW,CAAC,EAAE,CAAC;QACxD,OAAO,KAAK,CAAC;IACd,CAAC;IAED,uDAAuD;IACvD,IAAI,i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MAAM,OAAO,IAAI,SAAS,EAAE,CAAC;oBACjC,OAAO,CAAC,SAAS,GAAG,QAAQ,CAAC;gBAC9B,CAAC;gBACD,SAAS,CAAC,MAAM,CACf,CAAC,EACD,SAAS,CAAC,MAAM,EAChB,GAAG,CAAC,oBAAoB,IAAI,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC;oBACjD,GAAG,SAAS,CAAC,CAAC,CAAC;oBACf,OAAO;iBACP,CAAC,CAAC,CACH,CAAC;YACH,CAAC;YAED,OAAO,SAAS,CAAC;QAClB,CAAC;QAED,OAAO,UAAU,CAAC;IACnB,CAAC;CACD,CAAC,CAAC","sourcesContent":["import jsonfile from \"jsonfile\";\nimport { resolve as resolvePath } from \"pathe\";\nimport picomatch from \"picomatch\";\nimport type { PackageJson } from \"type-fest\";\nimport type { PolicyFinding } from \"../policy.js\";\nimport { definePackagePolicy } from \"../policyDefiners/definePackagePolicy.js\";\n\nconst { writeFile: writeJson } = jsonfile;\n\n/**\n * Sentinel value indicating that the package's private status should not be enforced.\n * This is more explicit than using `undefined` to represent \"ignore\".\n */\nconst IGNORE_PRIVATE_STATE = \"ignore\" as const;\n\n/**\n * The required private state for a package.\n * - `true`: Package must have `private: true`\n * - `false`: Package must NOT have `private: true`\n * - `\"ignore\"`: No enforcement - package can be either private or public\n */\ntype RequiredPrivateState = boolean | typeof IGNORE_PRIVATE_STATE;\n\n/**\n * Configuration for the PackagePrivateField policy.\n *\n * This policy enforces that packages are correctly marked as private or public based on\n * their scope or name. This is essential for monorepos where some packages should be\n * published to npm while others should remain internal.\n *\n * All pattern matching uses glob patterns via picomatch.\n *\n * @example\n * ```typescript\n * const config: PackagePrivateFieldConfig = {\n * // Packages in myorg scope must be published (private: false or absent)\n * mustPublish: [\"@myorg/*\"],\n * // Packages in internal scope must be private\n * mustBePrivate: [\"@internal/*\"],\n * // Packages in experimental scope can choose\n * mayPublish: [\"@experimental/*\"],\n * };\n * ```\n *\n * @public\n */\nexport interface PackagePrivateFieldConfig {\n\t/**\n\t * A list of glob patterns for packages that must be published.\n\t *\n\t * Packages matching these patterns must NOT have `private: true` in their package.json.\n\t * If they do, the policy will fail and can auto-fix by removing the private field.\n\t *\n\t * @remarks\n\t *\n\t * Uses glob patterns via picomatch. Use `@scope/*` to match all packages in a scope,\n\t * or use exact package names.\n\t *\n\t * @example\n\t * ```typescript\n\t * mustPublish: [\"@fluidframework/*\", \"@fluid-tools/*\", \"tinylicious\"]\n\t * ```\n\t */\n\tmustPublish?: string[];\n\n\t/**\n\t * A list of glob patterns for packages that must be private.\n\t *\n\t * Packages matching these patterns must have `private: true` in their package.json.\n\t * If they don't, the policy will fail and can auto-fix by adding `private: true`.\n\t *\n\t * @remarks\n\t *\n\t * Uses glob patterns via picomatch (see mustPublish for pattern examples).\n\t *\n\t * @example\n\t * ```typescript\n\t * mustBePrivate: [\"@fluid-internal/*\", \"@fluid-private/*\"]\n\t * ```\n\t */\n\tmustBePrivate?: string[];\n\n\t/**\n\t * A list of glob patterns for packages that may optionally be published.\n\t *\n\t * Packages matching these patterns can choose whether to be private or public.\n\t * The policy will not enforce either state for these packages.\n\t *\n\t * @remarks\n\t *\n\t * Uses glob patterns via picomatch (see mustPublish for pattern examples).\n\t * Packages not matching any list default to requiring `private: true`.\n\t *\n\t * @example\n\t * ```typescript\n\t * mayPublish: [\"@fluid-experimental/*\"]\n\t * ```\n\t */\n\tmayPublish?: string[];\n\n\t/**\n\t * Default behavior for packages that don't match any of the above lists.\n\t *\n\t * - `\"private\"` (default): Unmatched packages must have `private: true`\n\t * - `\"public\"`: Unmatched packages must NOT have `private: true`\n\t * - `\"ignore\"`: No enforcement for unmatched packages\n\t *\n\t * @defaultValue \"private\"\n\t */\n\tunmatchedPackages?: \"private\" | \"public\" | \"ignore\";\n}\n\n/**\n * Check if a package name matches any pattern in the list.\n *\n * Supports glob patterns via picomatch. Use patterns like:\n * - \"@myorg/\\*\" - matches all packages in the myorg scope\n * - \"my-package\" - exact match\n * - \"my-*\" - matches my-foo, my-bar, etc.\n *\n * @param packageName - The package name to check (e.g., `@myorg/foo`)\n * @param patterns - List of glob patterns or exact package names\n * @returns `true` if the package matches any pattern\n */\nfunction matchesAnyPattern(\n\tpackageName: string,\n\tpatterns: string[] | undefined,\n): boolean {\n\tif (patterns === undefined || patterns.length === 0) {\n\t\treturn false;\n\t}\n\n\treturn picomatch.isMatch(packageName, patterns);\n}\n\n/**\n * Determine what the private field should be for a package.\n *\n * @returns `true` if package must be private, `false` if must be public, `\"ignore\"` if either is ok\n */\nfunction getRequiredPrivateState(\n\tpackageName: string,\n\tconfig: PackagePrivateFieldConfig,\n): RequiredPrivateState {\n\t// Check mustPublish first - these packages must NOT be private\n\tif (matchesAnyPattern(packageName, config.mustPublish)) {\n\t\treturn false;\n\t}\n\n\t// Check mustBePrivate - these packages MUST be private\n\tif (matchesAnyPattern(packageName, config.mustBePrivate)) {\n\t\treturn true;\n\t}\n\n\t// Check mayPublish - these packages can be either\n\tif (matchesAnyPattern(packageName, config.mayPublish)) {\n\t\treturn IGNORE_PRIVATE_STATE;\n\t}\n\n\t// Default behavior for unmatched packages\n\tconst unmatchedBehavior = config.unmatchedPackages ?? \"private\";\n\tswitch (unmatchedBehavior) {\n\t\tcase \"private\":\n\t\t\treturn true;\n\t\tcase \"public\":\n\t\t\treturn false;\n\t\tcase \"ignore\":\n\t\t\treturn IGNORE_PRIVATE_STATE;\n\t\tdefault:\n\t\t\tthrow new Error(`Unknown unmatchedPackages value: ${unmatchedBehavior}`);\n\t}\n}\n\n/**\n * A policy that enforces the `private` field in package.json based on package scope or name.\n *\n * This policy is essential for monorepos where publishing control is important:\n *\n * - Prevent accidental publishing of internal packages\n * - Ensure public packages don't have `private: true` blocking publishing\n * - Allow experimental packages to choose their own publishing status\n *\n * @remarks\n *\n * The policy evaluates packages in the following order:\n *\n * 1. If the package matches `mustPublish`, it must NOT have `private: true`\n * 2. If the package matches `mustBePrivate`, it MUST have `private: true`\n * 3. If the package matches `mayPublish`, no enforcement is applied\n * 4. Otherwise, the `unmatchedPackages` setting determines behavior (defaults to requiring private)\n *\n * @example\n * ```typescript\n * import { makePolicy } from \"repopo\";\n * import { PackagePrivateField } from \"repopo/policies\";\n *\n * const config: RepopoConfig = {\n * policies: [\n * makePolicy(PackagePrivateField, {\n * config: {\n * mustPublish: [\"@myorg/*\"],\n * mustBePrivate: [\"@internal/*\"],\n * mayPublish: [\"@experimental/*\"],\n * unmatchedPackages: \"private\",\n * },\n * }),\n * ],\n * };\n * ```\n *\n * @public\n */\nexport const PackagePrivateField = definePackagePolicy<\n\tPackageJson,\n\tPackagePrivateFieldConfig | undefined\n>({\n\tname: \"PackagePrivateField\",\n\trequiresConfig: true,\n\tdescription:\n\t\t\"Enforces the private field in package.json based on package scope or name patterns.\",\n\thandler: async (json, { file, root, config, resolve }) => {\n\t\t// If no config provided, skip validation\n\t\tif (config === undefined) {\n\t\t\treturn [];\n\t\t}\n\n\t\tconst packageName = json.name;\n\n\t\t// Skip packages without a name (shouldn't happen in practice)\n\t\tif (packageName === undefined) {\n\t\t\treturn [];\n\t\t}\n\n\t\t// Skip the root package (typically named \"root\" in monorepos)\n\t\tif (packageName === \"root\") {\n\t\t\treturn [];\n\t\t}\n\n\t\tconst requiredState = getRequiredPrivateState(packageName, config);\n\n\t\t// If \"ignore\", the package can be either private or public\n\t\tif (requiredState === IGNORE_PRIVATE_STATE) {\n\t\t\treturn [];\n\t\t}\n\n\t\tconst currentlyPrivate = json.private === true;\n\n\t\t// Check if the current state matches the required state\n\t\tif (requiredState === currentlyPrivate) {\n\t\t\treturn [];\n\t\t}\n\n\t\t// State mismatch - build error message\n\t\tconst errorMessage =\n\t\t\trequiredState === true\n\t\t\t\t? `Package \"${packageName}\" must be marked private. Add \"private\": true to package.json.`\n\t\t\t\t: `Package \"${packageName}\" must not be marked private. Remove \"private\": true from package.json to allow publishing.`;\n\t\tconst failResult: PolicyFinding[] = [errorMessage].map((message) => ({\n\t\t\tmessage,\n\t\t\tfixStatus: \"available\",\n\t\t}));\n\t\tif (resolve) {\n\t\t\tconst fixResult: PolicyFinding[] = failResult.map((finding) => ({\n\t\t\t\t...finding,\n\t\t\t\tfixStatus: \"failed\",\n\t\t\t}));\n\t\t\ttry {\n\t\t\t\tif (requiredState === true) {\n\t\t\t\t\t// Add private: true\n\t\t\t\t\tjson.private = true;\n\t\t\t\t} else {\n\t\t\t\t\t// Remove private field\n\t\t\t\t\tdelete json.private;\n\t\t\t\t}\n\n\t\t\t\tawait writeJson(resolvePath(root, file), json, { spaces: \"\\t\" });\n\t\t\t\tfor (const finding of fixResult) {\n\t\t\t\t\tfinding.fixStatus = \"fixed\";\n\t\t\t\t}\n\t\t\t} catch {\n\t\t\t\tfor (const finding of fixResult) {\n\t\t\t\t\tfinding.fixStatus = \"failed\";\n\t\t\t\t}\n\t\t\t\tfixResult.splice(\n\t\t\t\t\t0,\n\t\t\t\t\tfixResult.length,\n\t\t\t\t\t...[`Failed to update ${file}`].map((message) => ({\n\t\t\t\t\t\t...fixResult[0],\n\t\t\t\t\t\tmessage,\n\t\t\t\t\t})),\n\t\t\t\t);\n\t\t\t}\n\n\t\t\treturn fixResult;\n\t\t}\n\n\t\treturn failResult;\n\t},\n});\n"]}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Policy settings for the PackageReadme repo policy.
|
|
3
3
|
*
|
|
4
|
-
* @
|
|
4
|
+
* @public
|
|
5
5
|
*/
|
|
6
6
|
export interface PackageReadmeSettings {
|
|
7
7
|
/**
|
|
@@ -61,17 +61,18 @@ export interface PackageReadmeSettings {
|
|
|
61
61
|
* const config: RepopoConfig = {
|
|
62
62
|
* policies: [
|
|
63
63
|
* // Basic README validation
|
|
64
|
-
* makePolicy(PackageReadme),
|
|
64
|
+
* makePolicy(PackageReadme, { instanceId: "readme" }),
|
|
65
65
|
*
|
|
66
66
|
* // Require trademark notice in all READMEs
|
|
67
67
|
* makePolicy(PackageReadme, {
|
|
68
|
-
*
|
|
68
|
+
* instanceId: "readme-trademark",
|
|
69
|
+
* config: { requiredContent: "## Trademark" },
|
|
69
70
|
* }),
|
|
70
71
|
* ],
|
|
71
72
|
* };
|
|
72
73
|
* ```
|
|
73
74
|
*
|
|
74
|
-
* @
|
|
75
|
+
* @public
|
|
75
76
|
*/
|
|
76
|
-
export declare const PackageReadme: import("../policy.js").
|
|
77
|
+
export declare const PackageReadme: import("../policy.js").FilePolicyDefinition<PackageReadmeSettings | undefined>;
|
|
77
78
|
//# sourceMappingURL=PackageReadme.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PackageReadme.d.ts","sourceRoot":"","sources":["../../src/policies/PackageReadme.ts"],"names":[],"mappings":"AAWA;;;;GAIG;AACH,MAAM,WAAW,qBAAqB;IACrC;;;;;;;;;OASG;IACH,WAAW,CAAC,EAAE,OAAO,CAAC;IAEtB;;;;;;;;;OASG;IACH,oBAAoB,CAAC,EAAE,OAAO,CAAC;IAE/B;;;;;;;;;;;;OAYG;IACH,eAAe,CAAC,EAAE,MAAM,CAAC;CACzB;
|
|
1
|
+
{"version":3,"file":"PackageReadme.d.ts","sourceRoot":"","sources":["../../src/policies/PackageReadme.ts"],"names":[],"mappings":"AAWA;;;;GAIG;AACH,MAAM,WAAW,qBAAqB;IACrC;;;;;;;;;OASG;IACH,WAAW,CAAC,EAAE,OAAO,CAAC;IAEtB;;;;;;;;;OASG;IACH,oBAAoB,CAAC,EAAE,OAAO,CAAC;IAE/B;;;;;;;;;;;;OAYG;IACH,eAAe,CAAC,EAAE,MAAM,CAAC;CACzB;AA0JD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AACH,eAAO,MAAM,aAAa,gFA4CxB,CAAC"}
|