repopo 0.7.1 → 0.9.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.
Files changed (122) hide show
  1. package/CHANGELOG.md +217 -6
  2. package/THIRD-PARTY-LICENSES.txt +152 -5
  3. package/esm/adapters/fluidFramework.d.ts +103 -0
  4. package/esm/adapters/fluidFramework.d.ts.map +1 -0
  5. package/esm/adapters/fluidFramework.js +124 -0
  6. package/esm/adapters/fluidFramework.js.map +1 -0
  7. package/esm/baseCommand.d.ts +1 -0
  8. package/esm/baseCommand.d.ts.map +1 -1
  9. package/esm/baseCommand.js +2 -0
  10. package/esm/baseCommand.js.map +1 -1
  11. package/esm/commands/check.d.ts.map +1 -1
  12. package/esm/commands/check.js +76 -50
  13. package/esm/commands/check.js.map +1 -1
  14. package/esm/commands/list.d.ts.map +1 -1
  15. package/esm/commands/list.js +3 -1
  16. package/esm/commands/list.js.map +1 -1
  17. package/esm/generators.d.ts +30 -2
  18. package/esm/generators.d.ts.map +1 -1
  19. package/esm/generators.js +31 -1
  20. package/esm/generators.js.map +1 -1
  21. package/esm/index.d.ts +14 -3
  22. package/esm/index.d.ts.map +1 -1
  23. package/esm/index.js +13 -2
  24. package/esm/index.js.map +1 -1
  25. package/esm/makePolicy.d.ts +31 -2
  26. package/esm/makePolicy.d.ts.map +1 -1
  27. package/esm/makePolicy.js +27 -13
  28. package/esm/makePolicy.js.map +1 -1
  29. package/esm/perf.d.ts +6 -2
  30. package/esm/perf.d.ts.map +1 -1
  31. package/esm/perf.js +5 -4
  32. package/esm/perf.js.map +1 -1
  33. package/esm/policies/HtmlFileHeaders.d.ts.map +1 -1
  34. package/esm/policies/HtmlFileHeaders.js +11 -7
  35. package/esm/policies/HtmlFileHeaders.js.map +1 -1
  36. package/esm/policies/JsTsFileHeaders.d.ts.map +1 -1
  37. package/esm/policies/JsTsFileHeaders.js +11 -7
  38. package/esm/policies/JsTsFileHeaders.js.map +1 -1
  39. package/esm/policies/LicenseFileExists.d.ts.map +1 -1
  40. package/esm/policies/LicenseFileExists.js +22 -16
  41. package/esm/policies/LicenseFileExists.js.map +1 -1
  42. package/esm/policies/NoJsFileExtensions.d.ts.map +1 -1
  43. package/esm/policies/NoJsFileExtensions.js +16 -9
  44. package/esm/policies/NoJsFileExtensions.js.map +1 -1
  45. package/esm/policies/NoLargeBinaryFiles.d.ts.map +1 -1
  46. package/esm/policies/NoLargeBinaryFiles.js +35 -29
  47. package/esm/policies/NoLargeBinaryFiles.js.map +1 -1
  48. package/esm/policies/NoPrivateWorkspaceDependencies.d.ts +37 -0
  49. package/esm/policies/NoPrivateWorkspaceDependencies.d.ts.map +1 -0
  50. package/esm/policies/NoPrivateWorkspaceDependencies.js +145 -0
  51. package/esm/policies/NoPrivateWorkspaceDependencies.js.map +1 -0
  52. package/esm/policies/PackageAllowedScopes.d.ts +88 -0
  53. package/esm/policies/PackageAllowedScopes.d.ts.map +1 -0
  54. package/esm/policies/PackageAllowedScopes.js +118 -0
  55. package/esm/policies/PackageAllowedScopes.js.map +1 -0
  56. package/esm/policies/PackageEsmType.d.ts +100 -0
  57. package/esm/policies/PackageEsmType.d.ts.map +1 -0
  58. package/esm/policies/PackageEsmType.js +261 -0
  59. package/esm/policies/PackageEsmType.js.map +1 -0
  60. package/esm/policies/PackageFolderName.d.ts +97 -0
  61. package/esm/policies/PackageFolderName.d.ts.map +1 -0
  62. package/esm/policies/PackageFolderName.js +108 -0
  63. package/esm/policies/PackageFolderName.js.map +1 -0
  64. package/esm/policies/PackageJsonProperties.d.ts.map +1 -1
  65. package/esm/policies/PackageJsonProperties.js +36 -30
  66. package/esm/policies/PackageJsonProperties.js.map +1 -1
  67. package/esm/policies/PackageJsonRepoDirectoryProperty.d.ts.map +1 -1
  68. package/esm/policies/PackageJsonRepoDirectoryProperty.js +41 -37
  69. package/esm/policies/PackageJsonRepoDirectoryProperty.js.map +1 -1
  70. package/esm/policies/PackageJsonSorted.d.ts.map +1 -1
  71. package/esm/policies/PackageJsonSorted.js +40 -28
  72. package/esm/policies/PackageJsonSorted.js.map +1 -1
  73. package/esm/policies/PackageLicense.d.ts +61 -0
  74. package/esm/policies/PackageLicense.d.ts.map +1 -0
  75. package/esm/policies/PackageLicense.js +135 -0
  76. package/esm/policies/PackageLicense.js.map +1 -0
  77. package/esm/policies/PackagePrivateField.d.ts +124 -0
  78. package/esm/policies/PackagePrivateField.d.ts.map +1 -0
  79. package/esm/policies/PackagePrivateField.js +159 -0
  80. package/esm/policies/PackagePrivateField.js.map +1 -0
  81. package/esm/policies/PackageReadme.d.ts +77 -0
  82. package/esm/policies/PackageReadme.d.ts.map +1 -0
  83. package/esm/policies/PackageReadme.js +213 -0
  84. package/esm/policies/PackageReadme.js.map +1 -0
  85. package/esm/policies/PackageScripts.d.ts +180 -2
  86. package/esm/policies/PackageScripts.d.ts.map +1 -1
  87. package/esm/policies/PackageScripts.js +358 -34
  88. package/esm/policies/PackageScripts.js.map +1 -1
  89. package/esm/policies/PackageTestScripts.d.ts +100 -0
  90. package/esm/policies/PackageTestScripts.d.ts.map +1 -0
  91. package/esm/policies/PackageTestScripts.js +155 -0
  92. package/esm/policies/PackageTestScripts.js.map +1 -0
  93. package/esm/policies/RequiredGitignorePatterns.d.ts.map +1 -1
  94. package/esm/policies/RequiredGitignorePatterns.js +30 -19
  95. package/esm/policies/RequiredGitignorePatterns.js.map +1 -1
  96. package/esm/policies.d.ts +9 -1
  97. package/esm/policies.d.ts.map +1 -1
  98. package/esm/policies.js +10 -1
  99. package/esm/policies.js.map +1 -1
  100. package/esm/policy.d.ts +37 -8
  101. package/esm/policy.d.ts.map +1 -1
  102. package/esm/policy.js +18 -9
  103. package/esm/policy.js.map +1 -1
  104. package/esm/policyDefiners/defineFileHeaderPolicy.d.ts +43 -1
  105. package/esm/policyDefiners/defineFileHeaderPolicy.d.ts.map +1 -1
  106. package/esm/policyDefiners/defineFileHeaderPolicy.js +18 -5
  107. package/esm/policyDefiners/defineFileHeaderPolicy.js.map +1 -1
  108. package/esm/policyDefiners/definePackagePolicy.d.ts +43 -2
  109. package/esm/policyDefiners/definePackagePolicy.d.ts.map +1 -1
  110. package/esm/policyDefiners/definePackagePolicy.js +41 -5
  111. package/esm/policyDefiners/definePackagePolicy.js.map +1 -1
  112. package/esm/tsdoc-metadata.json +1 -1
  113. package/esm/utils/indentation.d.ts +73 -0
  114. package/esm/utils/indentation.d.ts.map +1 -0
  115. package/esm/utils/indentation.js +97 -0
  116. package/esm/utils/indentation.js.map +1 -0
  117. package/esm/utils/packageName.d.ts +71 -0
  118. package/esm/utils/packageName.d.ts.map +1 -0
  119. package/esm/utils/packageName.js +79 -0
  120. package/esm/utils/packageName.js.map +1 -0
  121. package/oclif.manifest.json +1 -1
  122. package/package.json +33 -16
@@ -8,44 +8,48 @@ import { definePackagePolicy } from "../policyDefiners/definePackagePolicy.js";
8
8
  *
9
9
  * @alpha
10
10
  */
11
- export const PackageJsonRepoDirectoryProperty = definePackagePolicy("PackageJsonRepoDirectoryProperty", async (json, { file, root, resolve }) => {
12
- const failResult = {
13
- name: PackageJsonRepoDirectoryProperty.name,
14
- file,
15
- autoFixable: true,
16
- };
17
- const fixResult = {
18
- ...failResult,
19
- resolved: false,
20
- };
21
- const pkgDir = path.dirname(file);
22
- const maybeDir = path.relative(root, pkgDir);
23
- const relativePkgDir = maybeDir === "" ? undefined : maybeDir;
24
- if (typeof json.repository === "object" &&
25
- json.repository.directory !== relativePkgDir) {
26
- if (resolve) {
27
- try {
28
- // biome-ignore lint/nursery/noShadow: no need to use shadowed variable
29
- updatePackageJsonFile(file, (json) => {
30
- assert(typeof json.repository === "object");
31
- if (relativePkgDir === undefined) {
32
- delete json.repository.directory;
33
- }
34
- else {
35
- json.repository.directory = relativePkgDir;
36
- }
37
- });
38
- fixResult.resolved = true;
11
+ export const PackageJsonRepoDirectoryProperty = definePackagePolicy({
12
+ name: "PackageJsonRepoDirectoryProperty",
13
+ description: "Ensures the repository.directory property in package.json is set correctly for monorepo packages.",
14
+ handler: function* (json, { file, root, resolve }) {
15
+ const failResult = {
16
+ name: PackageJsonRepoDirectoryProperty.name,
17
+ file,
18
+ autoFixable: true,
19
+ errorMessages: [],
20
+ };
21
+ const fixResult = {
22
+ ...failResult,
23
+ resolved: false,
24
+ };
25
+ const pkgDir = path.dirname(file);
26
+ const maybeDir = path.relative(root, pkgDir);
27
+ const relativePkgDir = maybeDir === "" ? undefined : maybeDir;
28
+ if (typeof json.repository === "object" &&
29
+ json.repository.directory !== relativePkgDir) {
30
+ if (resolve) {
31
+ try {
32
+ updatePackageJsonFile(file, (pkgJson) => {
33
+ assert(typeof pkgJson.repository === "object");
34
+ if (relativePkgDir === undefined) {
35
+ delete pkgJson.repository.directory;
36
+ }
37
+ else {
38
+ pkgJson.repository.directory = relativePkgDir;
39
+ }
40
+ });
41
+ fixResult.resolved = true;
42
+ }
43
+ catch (error) {
44
+ fixResult.resolved = false;
45
+ fixResult.errorMessages.push(`${error.message}\n${error.stack}`);
46
+ }
47
+ return fixResult;
39
48
  }
40
- catch (error) {
41
- fixResult.resolved = false;
42
- fixResult.errorMessage = `${error.message}\n${error.stack}`;
43
- }
44
- return fixResult;
49
+ failResult.errorMessages.push(`repository.directory value is wrong. Expected '${relativePkgDir}', got '${json.repository.directory}'`);
50
+ return failResult;
45
51
  }
46
- failResult.errorMessage = `repository.directory value is wrong. Expected '${relativePkgDir}', got '${json.repository.directory}'`;
47
- return failResult;
48
- }
49
- return true;
52
+ return true;
53
+ },
50
54
  });
51
55
  //# sourceMappingURL=PackageJsonRepoDirectoryProperty.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"PackageJsonRepoDirectoryProperty.js","sourceRoot":"","sources":["../../src/policies/PackageJsonRepoDirectoryProperty.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,oBAAoB,CAAC;AACxC,OAAO,EAAE,qBAAqB,EAAE,MAAM,mCAAmC,CAAC;AAC1E,OAAO,IAAI,MAAM,OAAO,CAAC;AAGzB,OAAO,EAA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CAAC;gBACzB,SAAS,CAAC,QAAQ,GAAG,KAAK,CAAC;gBAC3B,SAAS,CAAC,YAAY,GAAG,GAAI,KAAe,CAAC,OAAO,KAClD,KAAe,CAAC,KAClB,EAAE,CAAC;YACJ,CAAC;YACD,OAAO,SAAS,CAAC;QAClB,CAAC;QACD,UAAU,CAAC,YAAY,GAAG,kDAAkD,cAAc,WAAW,IAAI,CAAC,UAAU,CAAC,SAAS,GAAG,CAAC;QAClI,OAAO,UAAU,CAAC;IACnB,CAAC;IAED,OAAO,IAAI,CAAC;AACb,CAAC,CAAC,CAAC","sourcesContent":["import assert from \"node:assert/strict\";\nimport { updatePackageJsonFile } from \"@fluid-tools/build-infrastructure\";\nimport path from \"pathe\";\nimport type { PackageJson } from \"type-fest\";\nimport type { PolicyFailure, PolicyFixResult } from \"../policy.js\";\nimport { definePackagePolicy } from \"../policyDefiners/definePackagePolicy.js\";\n\n/**\n * A RepoPolicy that checks that the repository.directory property in package.json is set correctly. If the repository\n * field is a string instead of an object the package will be ignored.\n *\n * @alpha\n */\nexport const PackageJsonRepoDirectoryProperty = definePackagePolicy<\n\tPackageJson,\n\tundefined\n>(\"PackageJsonRepoDirectoryProperty\", async (json, { file, root, resolve }) => {\n\tconst failResult: PolicyFailure = {\n\t\tname: PackageJsonRepoDirectoryProperty.name,\n\t\tfile,\n\t\tautoFixable: true,\n\t};\n\n\tconst fixResult: PolicyFixResult = {\n\t\t...failResult,\n\t\tresolved: false,\n\t};\n\n\tconst pkgDir = path.dirname(file);\n\tconst maybeDir = path.relative(root, pkgDir);\n\tconst relativePkgDir = maybeDir === \"\" ? undefined : maybeDir;\n\n\tif (\n\t\ttypeof json.repository === \"object\" &&\n\t\tjson.repository.directory !== relativePkgDir\n\t) {\n\t\tif (resolve) {\n\t\t\ttry {\n\t\t\t\t// biome-ignore lint/nursery/noShadow: no need to use shadowed variable\n\t\t\t\tupdatePackageJsonFile(file, (json) => {\n\t\t\t\t\tassert(typeof json.repository === \"object\");\n\t\t\t\t\tif (relativePkgDir === undefined) {\n\t\t\t\t\t\tdelete json.repository.directory;\n\t\t\t\t\t} else {\n\t\t\t\t\t\tjson.repository.directory = relativePkgDir;\n\t\t\t\t\t}\n\t\t\t\t});\n\t\t\t\tfixResult.resolved = true;\n\t\t\t} catch (error: unknown) {\n\t\t\t\tfixResult.resolved = false;\n\t\t\t\tfixResult.errorMessage = `${(error as Error).message}\\n${\n\t\t\t\t\t(error as Error).stack\n\t\t\t\t}`;\n\t\t\t}\n\t\t\treturn fixResult;\n\t\t}\n\t\tfailResult.errorMessage = `repository.directory value is wrong. Expected '${relativePkgDir}', got '${json.repository.directory}'`;\n\t\treturn failResult;\n\t}\n\n\treturn true;\n});\n"]}
1
+ {"version":3,"file":"PackageJsonRepoDirectoryProperty.js","sourceRoot":"","sources":["../../src/policies/PackageJsonRepoDirectoryProperty.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,oBAAoB,CAAC;AACxC,OAAO,EAAE,qBAAqB,EAAE,MAAM,mCAAmC,CAAC;AAC1E,OAAO,IAAI,MAAM,OAAO,CAAC;AAGzB,OAAO,EAAE,mBAAmB,EAAE,MAAM,0CAA0C,CAAC;AAE/E;;;;;GAKG;AACH,MAAM,CAAC,MAAM,gCAAgC,GAAG,mBAAmB,CAGjE;IACD,IAAI,EAAE,kCAAkC;IACxC,WAAW,EACV,mGAAmG;IACpG,OAAO,EAAE,QAAQ,CAAC,EAAE,IAAI,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,OAAO,EAAE;QAChD,MAAM,UAAU,GAAkB;YACjC,IAAI,EAAE,gCAAgC,CAAC,IAAI;YAC3C,IAAI;YACJ,WAAW,EAAE,IAAI;YACjB,aAAa,EAAE,EAAE;SACjB,CAAC;QAEF,MAAM,SAAS,GAAoB;YAClC,GAAG,UAAU;YACb,QAAQ,EAAE,KAAK;SACf,CAAC;QAEF,MAAM,MAAM,GAAG,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;QAClC,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\nimport path from \"pathe\";\nimport type { PackageJson } from \"type-fest\";\nimport type { PolicyFailure, PolicyFixResult } from \"../policy.js\";\nimport { definePackagePolicy } from \"../policyDefiners/definePackagePolicy.js\";\n\n/**\n * A RepoPolicy that checks that the repository.directory property in package.json is set correctly. If the repository\n * field is a string instead of an object the package will be ignored.\n *\n * @alpha\n */\nexport const PackageJsonRepoDirectoryProperty = definePackagePolicy<\n\tPackageJson,\n\tundefined\n>({\n\tname: \"PackageJsonRepoDirectoryProperty\",\n\tdescription:\n\t\t\"Ensures the repository.directory property in package.json is set correctly for monorepo packages.\",\n\thandler: function* (json, { file, root, resolve }) {\n\t\tconst failResult: PolicyFailure = {\n\t\t\tname: PackageJsonRepoDirectoryProperty.name,\n\t\t\tfile,\n\t\t\tautoFixable: true,\n\t\t\terrorMessages: [],\n\t\t};\n\n\t\tconst fixResult: PolicyFixResult = {\n\t\t\t...failResult,\n\t\t\tresolved: false,\n\t\t};\n\n\t\tconst pkgDir = path.dirname(file);\n\t\tconst maybeDir = path.relative(root, pkgDir);\n\t\tconst relativePkgDir = maybeDir === \"\" ? undefined : maybeDir;\n\n\t\tif (\n\t\t\ttypeof json.repository === \"object\" &&\n\t\t\tjson.repository.directory !== relativePkgDir\n\t\t) {\n\t\t\tif (resolve) {\n\t\t\t\ttry {\n\t\t\t\t\tupdatePackageJsonFile(file, (pkgJson) => {\n\t\t\t\t\t\tassert(typeof pkgJson.repository === \"object\");\n\t\t\t\t\t\tif (relativePkgDir === undefined) {\n\t\t\t\t\t\t\tdelete pkgJson.repository.directory;\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tpkgJson.repository.directory = relativePkgDir;\n\t\t\t\t\t\t}\n\t\t\t\t\t});\n\t\t\t\t\tfixResult.resolved = true;\n\t\t\t\t} catch (error: unknown) {\n\t\t\t\t\tfixResult.resolved = false;\n\t\t\t\t\tfixResult.errorMessages.push(\n\t\t\t\t\t\t`${(error as Error).message}\\n${(error as Error).stack}`,\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\treturn fixResult;\n\t\t\t}\n\t\t\tfailResult.errorMessages.push(\n\t\t\t\t`repository.directory value is wrong. Expected '${relativePkgDir}', got '${json.repository.directory}'`,\n\t\t\t);\n\t\t\treturn failResult;\n\t\t}\n\n\t\treturn true;\n\t},\n});\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"PackageJsonSorted.d.ts","sourceRoot":"","sources":["../../src/policies/PackageJsonSorted.ts"],"names":[],"mappings":"AAKA;;;;GAIG;AACH,eAAO,MAAM,iBAAiB,oDAuC7B,CAAC"}
1
+ {"version":3,"file":"PackageJsonSorted.d.ts","sourceRoot":"","sources":["../../src/policies/PackageJsonSorted.ts"],"names":[],"mappings":"AAOA;;;;GAIG;AACH,eAAO,MAAM,iBAAiB,oDAiD5B,CAAC"}
@@ -1,4 +1,6 @@
1
1
  import { updatePackageJsonFile } from "@tylerbu/cli-api";
2
+ import { call } from "effection";
3
+ import { resolve as resolvePath } from "pathe";
2
4
  import { sortPackageJson } from "sort-package-json";
3
5
  import { definePackagePolicy } from "../policyDefiners/definePackagePolicy.js";
4
6
  /**
@@ -6,41 +8,51 @@ import { definePackagePolicy } from "../policyDefiners/definePackagePolicy.js";
6
8
  *
7
9
  * @alpha
8
10
  */
9
- export const PackageJsonSorted = definePackagePolicy("PackageJsonSorted", async (json, { file, resolve }) => {
10
- const sortedJson = sortPackageJson(json);
11
- const isSorted = JSON.stringify(sortedJson) === JSON.stringify(json);
12
- if (isSorted) {
13
- return true;
14
- }
15
- if (resolve) {
16
- try {
17
- // biome-ignore lint/nursery/noShadow: no need to use the shadowed variable
18
- await updatePackageJsonFile(file, (json) => json, { sort: true });
19
- const result = {
20
- name: PackageJsonSorted.name,
21
- file,
22
- resolved: true,
23
- };
24
- return result;
11
+ export const PackageJsonSorted = definePackagePolicy({
12
+ name: "PackageJsonSorted",
13
+ description: "Ensures package.json files are sorted consistently using sort-package-json.",
14
+ handler: function* (json, { file, root, resolve }) {
15
+ const sortedJson = sortPackageJson(json);
16
+ const isSorted = JSON.stringify(sortedJson) === JSON.stringify(json);
17
+ if (isSorted) {
18
+ return true;
19
+ }
20
+ if (resolve) {
21
+ try {
22
+ yield* call(() => updatePackageJsonFile(resolvePath(root, file), (pkgJson) => pkgJson, {
23
+ sort: true,
24
+ }));
25
+ const result = {
26
+ name: PackageJsonSorted.name,
27
+ file,
28
+ resolved: true,
29
+ errorMessages: [],
30
+ };
31
+ return result;
32
+ }
33
+ catch (error) {
34
+ const result = {
35
+ name: PackageJsonSorted.name,
36
+ file,
37
+ resolved: false,
38
+ autoFixable: true,
39
+ errorMessages: [
40
+ error.message,
41
+ error.stack ?? "",
42
+ ],
43
+ };
44
+ return result;
45
+ }
25
46
  }
26
- catch (error) {
47
+ else {
27
48
  const result = {
28
49
  name: PackageJsonSorted.name,
29
50
  file,
30
- resolved: false,
31
51
  autoFixable: true,
32
- errorMessage: error.message,
52
+ errorMessages: [],
33
53
  };
34
54
  return result;
35
55
  }
36
- }
37
- else {
38
- const result = {
39
- name: PackageJsonSorted.name,
40
- file,
41
- autoFixable: true,
42
- };
43
- return result;
44
- }
56
+ },
45
57
  });
46
58
  //# sourceMappingURL=PackageJsonSorted.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"PackageJsonSorted.js","sourceRoot":"","sources":["../../src/policies/PackageJsonSorted.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,MAAM,kBAAkB,CAAC;AACzD,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAEpD,OAAO,EAAE,mBAAmB,EAAE,MAAM,0CAA0C,CAAC;AAE/E;;;;GAIG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAG,mBAAmB,CACnD,mBAAmB,EACnB,KAAK,EAAE,IAAI,EAAE,EAAE,IAAI,EAAE,OAAO,EAAE,EAAE,EAAE;IACjC,MAAM,UAAU,GAAG,eAAe,CAAC,IAAI,CAAC,CAAC;IACzC,MAAM,QAAQ,GAAG,IAAI,CAAC,SAAS,CAAC,UAAU,CAAC,KAAK,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC;IAErE,IAAI,QAAQ,EAAE,CAAC;QACd,OAAO,IAAI,CAAC;IACb,CAAC;IAED,IAAI,OAAO,EAAE,CAAC;QACb,IAAI,CAAC;YACJ,2EAA2E;YAC3E,MAAM,qBAAqB,CAAC,IAAI,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC;YAClE,MAAM,MAAM,GAAoB;gBAC/B,IAAI,EAAE,iBAAiB,CAAC,IAAI;gBAC5B,IAAI;gBACJ,QAAQ,EAAE,IAAI;aACd,CAAC;YACF,OAAO,MAAM,CAAC;QACf,CAAC;QAAC,OAAO,KAAc,EAAE,CAAC;YACzB,MAAM,MAAM,GAAoB;gBAC/B,IAAI,EAAE,iBAAiB,CAAC,IAAI;gBAC5B,IAAI;gBACJ,QAAQ,EAAE,KAAK;gBACf,WAAW,EAAE,IAAI;gBACjB,YAAY,EAAG,KAAe,CAAC,OAAO;aACtC,CAAC;YACF,OAAO,MAAM,CAAC;QACf,CAAC;IACF,CAAC;SAAM,CAAC;QACP,MAAM,MAAM,GAAkB;YAC7B,IAAI,EAAE,iBAAiB,CAAC,IAAI;YAC5B,IAAI;YACJ,WAAW,EAAE,IAAI;SACjB,CAAC;QACF,OAAO,MAAM,CAAC;IACf,CAAC;AACF,CAAC,CACD,CAAC","sourcesContent":["import { updatePackageJsonFile } from \"@tylerbu/cli-api\";\nimport { sortPackageJson } from \"sort-package-json\";\nimport type { PolicyFailure, PolicyFixResult } from \"../policy.js\";\nimport { definePackagePolicy } from \"../policyDefiners/definePackagePolicy.js\";\n\n/**\n * A repo policy that checks if package.json files in the repo are sorted using sort-package-json.\n *\n * @alpha\n */\nexport const PackageJsonSorted = definePackagePolicy(\n\t\"PackageJsonSorted\",\n\tasync (json, { file, resolve }) => {\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 true;\n\t\t}\n\n\t\tif (resolve) {\n\t\t\ttry {\n\t\t\t\t// biome-ignore lint/nursery/noShadow: no need to use the shadowed variable\n\t\t\t\tawait updatePackageJsonFile(file, (json) => json, { sort: true });\n\t\t\t\tconst result: PolicyFixResult = {\n\t\t\t\t\tname: PackageJsonSorted.name,\n\t\t\t\t\tfile,\n\t\t\t\t\tresolved: true,\n\t\t\t\t};\n\t\t\t\treturn result;\n\t\t\t} catch (error: unknown) {\n\t\t\t\tconst result: PolicyFixResult = {\n\t\t\t\t\tname: PackageJsonSorted.name,\n\t\t\t\t\tfile,\n\t\t\t\t\tresolved: false,\n\t\t\t\t\tautoFixable: true,\n\t\t\t\t\terrorMessage: (error as Error).message,\n\t\t\t\t};\n\t\t\t\treturn result;\n\t\t\t}\n\t\t} else {\n\t\t\tconst result: PolicyFailure = {\n\t\t\t\tname: PackageJsonSorted.name,\n\t\t\t\tfile,\n\t\t\t\tautoFixable: true,\n\t\t\t};\n\t\t\treturn result;\n\t\t}\n\t},\n);\n"]}
1
+ {"version":3,"file":"PackageJsonSorted.js","sourceRoot":"","sources":["../../src/policies/PackageJsonSorted.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,MAAM,kBAAkB,CAAC;AACzD,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,OAAO,IAAI,WAAW,EAAE,MAAM,OAAO,CAAC;AAC/C,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAEpD,OAAO,EAAE,mBAAmB,EAAE,MAAM,0CAA0C,CAAC;AAE/E;;;;GAIG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAG,mBAAmB,CAAC;IACpD,IAAI,EAAE,mBAAmB;IACzB,WAAW,EACV,6EAA6E;IAC9E,OAAO,EAAE,QAAQ,CAAC,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C,CAAC","sourcesContent":["import { updatePackageJsonFile } from \"@tylerbu/cli-api\";\nimport { call } from \"effection\";\nimport { resolve as resolvePath } from \"pathe\";\nimport { sortPackageJson } from \"sort-package-json\";\nimport type { PolicyFailure, PolicyFixResult } from \"../policy.js\";\nimport { definePackagePolicy } from \"../policyDefiners/definePackagePolicy.js\";\n\n/**\n * A repo policy that checks if package.json files in the repo are sorted using sort-package-json.\n *\n * @alpha\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: function* (json, { file, root, resolve }) {\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 true;\n\t\t}\n\n\t\tif (resolve) {\n\t\t\ttry {\n\t\t\t\tyield* call(() =>\n\t\t\t\t\tupdatePackageJsonFile(resolvePath(root, file), (pkgJson) => pkgJson, {\n\t\t\t\t\t\tsort: true,\n\t\t\t\t\t}),\n\t\t\t\t);\n\t\t\t\tconst result: PolicyFixResult = {\n\t\t\t\t\tname: PackageJsonSorted.name,\n\t\t\t\t\tfile,\n\t\t\t\t\tresolved: true,\n\t\t\t\t\terrorMessages: [],\n\t\t\t\t};\n\t\t\t\treturn result;\n\t\t\t} catch (error: unknown) {\n\t\t\t\tconst result: PolicyFixResult = {\n\t\t\t\t\tname: PackageJsonSorted.name,\n\t\t\t\t\tfile,\n\t\t\t\t\tresolved: false,\n\t\t\t\t\tautoFixable: true,\n\t\t\t\t\terrorMessages: [\n\t\t\t\t\t\t(error as Error).message,\n\t\t\t\t\t\t(error as Error).stack ?? \"\",\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: PolicyFailure = {\n\t\t\t\tname: PackageJsonSorted.name,\n\t\t\t\tfile,\n\t\t\t\tautoFixable: true,\n\t\t\t\terrorMessages: [],\n\t\t\t};\n\t\t\treturn result;\n\t\t}\n\t},\n});\n"]}
@@ -0,0 +1,61 @@
1
+ /**
2
+ * Policy settings for the PackageLicense repo policy.
3
+ *
4
+ * @alpha
5
+ */
6
+ export interface PackageLicenseSettings {
7
+ /**
8
+ * Whether to skip validation for private packages.
9
+ *
10
+ * @defaultValue true
11
+ *
12
+ * @remarks
13
+ *
14
+ * Private packages (those with `private: true` in package.json) are typically
15
+ * not published and may not need a LICENSE file. Set to `false` to require
16
+ * LICENSE files for all packages.
17
+ */
18
+ skipPrivate?: boolean;
19
+ /**
20
+ * The name of the LICENSE file to look for and sync.
21
+ *
22
+ * @defaultValue "LICENSE"
23
+ */
24
+ licenseFileName?: string;
25
+ }
26
+ /**
27
+ * A repo policy that ensures each package has a LICENSE file that matches the root LICENSE.
28
+ *
29
+ * @remarks
30
+ *
31
+ * This policy is essential for monorepos where individual packages are published
32
+ * to npm. Each published package should include a LICENSE file, and it should
33
+ * match the root repository's LICENSE to ensure consistent licensing.
34
+ *
35
+ * The policy:
36
+ * 1. Checks if a LICENSE file exists in the package directory
37
+ * 2. Compares it with the root LICENSE file
38
+ * 3. Can auto-fix by copying the root LICENSE to the package directory
39
+ *
40
+ * By default, private packages are skipped since they're not published.
41
+ *
42
+ * @example
43
+ * ```typescript
44
+ * import { makePolicy } from "repopo";
45
+ * import { PackageLicense } from "repopo/policies";
46
+ *
47
+ * const config: RepopoConfig = {
48
+ * policies: [
49
+ * // Use defaults (skip private, look for LICENSE)
50
+ * makePolicy(PackageLicense),
51
+ *
52
+ * // Or require LICENSE for all packages including private
53
+ * makePolicy(PackageLicense, { skipPrivate: false }),
54
+ * ],
55
+ * };
56
+ * ```
57
+ *
58
+ * @alpha
59
+ */
60
+ export declare const PackageLicense: import("../policy.js").PolicyDefinition<PackageLicenseSettings | undefined>;
61
+ //# sourceMappingURL=PackageLicense.d.ts.map
@@ -0,0 +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;AA8CD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AACH,eAAO,MAAM,cAAc,6EA0FzB,CAAC"}
@@ -0,0 +1,135 @@
1
+ import { existsSync } from "node:fs";
2
+ import { copyFile, readFile } from "node:fs/promises";
3
+ import path from "pathe";
4
+ import { definePackagePolicy } from "../policyDefiners/definePackagePolicy.js";
5
+ const DEFAULT_LICENSE_FILE_NAME = "LICENSE";
6
+ const POLICY_NAME = "PackageLicense";
7
+ /**
8
+ * Copies the root LICENSE file to the package directory.
9
+ * @returns A PolicyFixResult indicating success or failure.
10
+ */
11
+ async function copyLicenseFile(rootLicensePath, packageLicensePath, policyName, file, packageName, licenseFileName, isCreate) {
12
+ try {
13
+ await copyFile(rootLicensePath, packageLicensePath);
14
+ return {
15
+ name: policyName,
16
+ file,
17
+ resolved: true,
18
+ autoFixable: true,
19
+ errorMessages: [
20
+ isCreate
21
+ ? `Created ${licenseFileName} file for package "${packageName}"`
22
+ : `Updated ${licenseFileName} file for package "${packageName}" to match root`,
23
+ ],
24
+ };
25
+ }
26
+ catch {
27
+ return {
28
+ name: policyName,
29
+ file,
30
+ resolved: false,
31
+ autoFixable: true,
32
+ errorMessages: [
33
+ isCreate
34
+ ? `Failed to copy ${licenseFileName} to package "${packageName}"`
35
+ : `Failed to update ${licenseFileName} for package "${packageName}"`,
36
+ ],
37
+ };
38
+ }
39
+ }
40
+ /**
41
+ * A repo policy that ensures each package has a LICENSE file that matches the root LICENSE.
42
+ *
43
+ * @remarks
44
+ *
45
+ * This policy is essential for monorepos where individual packages are published
46
+ * to npm. Each published package should include a LICENSE file, and it should
47
+ * match the root repository's LICENSE to ensure consistent licensing.
48
+ *
49
+ * The policy:
50
+ * 1. Checks if a LICENSE file exists in the package directory
51
+ * 2. Compares it with the root LICENSE file
52
+ * 3. Can auto-fix by copying the root LICENSE to the package directory
53
+ *
54
+ * By default, private packages are skipped since they're not published.
55
+ *
56
+ * @example
57
+ * ```typescript
58
+ * import { makePolicy } from "repopo";
59
+ * import { PackageLicense } from "repopo/policies";
60
+ *
61
+ * const config: RepopoConfig = {
62
+ * policies: [
63
+ * // Use defaults (skip private, look for LICENSE)
64
+ * makePolicy(PackageLicense),
65
+ *
66
+ * // Or require LICENSE for all packages including private
67
+ * makePolicy(PackageLicense, { skipPrivate: false }),
68
+ * ],
69
+ * };
70
+ * ```
71
+ *
72
+ * @alpha
73
+ */
74
+ export const PackageLicense = definePackagePolicy({
75
+ name: "PackageLicense",
76
+ description: "Ensures each package has a LICENSE file that matches the root repository LICENSE.",
77
+ handler: async (json, { file, root, resolve, config }) => {
78
+ const skipPrivate = config?.skipPrivate ?? true;
79
+ const licenseFileName = config?.licenseFileName ?? DEFAULT_LICENSE_FILE_NAME;
80
+ // Skip private packages if configured to do so
81
+ if (skipPrivate && json.private === true) {
82
+ return true;
83
+ }
84
+ const packageName = json.name ?? "unknown";
85
+ // file is an absolute path, get the directory containing package.json
86
+ const packageDir = path.dirname(file);
87
+ const packageLicensePath = path.join(packageDir, licenseFileName);
88
+ const rootLicensePath = path.join(root, licenseFileName);
89
+ // Check if root LICENSE exists
90
+ if (!existsSync(rootLicensePath)) {
91
+ return {
92
+ name: POLICY_NAME,
93
+ file,
94
+ autoFixable: false,
95
+ errorMessages: [
96
+ `Cannot validate package LICENSE: root ${licenseFileName} file not found`,
97
+ ],
98
+ };
99
+ }
100
+ // Check if package LICENSE exists
101
+ if (!existsSync(packageLicensePath)) {
102
+ if (resolve) {
103
+ return await copyLicenseFile(rootLicensePath, packageLicensePath, POLICY_NAME, file, packageName, licenseFileName, true);
104
+ }
105
+ return {
106
+ name: POLICY_NAME,
107
+ file,
108
+ autoFixable: true,
109
+ errorMessages: [
110
+ `${licenseFileName} file missing for package "${packageName}"`,
111
+ ],
112
+ };
113
+ }
114
+ // Compare package LICENSE with root LICENSE
115
+ const [packageLicenseContent, rootLicenseContent] = await Promise.all([
116
+ readFile(packageLicensePath, "utf-8"),
117
+ readFile(rootLicensePath, "utf-8"),
118
+ ]);
119
+ if (packageLicenseContent !== rootLicenseContent) {
120
+ if (resolve) {
121
+ return await copyLicenseFile(rootLicensePath, packageLicensePath, POLICY_NAME, file, packageName, licenseFileName, false);
122
+ }
123
+ return {
124
+ name: POLICY_NAME,
125
+ file,
126
+ autoFixable: true,
127
+ errorMessages: [
128
+ `${licenseFileName} file in package "${packageName}" doesn't match root ${licenseFileName}`,
129
+ ],
130
+ };
131
+ }
132
+ return true;
133
+ },
134
+ });
135
+ //# sourceMappingURL=PackageLicense.js.map
@@ -0,0 +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,UAAkB,EAClB,IAAY,EACZ,WAAmB,EACnB,eAAuB,EACvB,QAAiB;IAEjB,IAAI,CAAC;QACJ,MAAM,QAAQ,CAAC,eAAe,EAAE,kBAAkB,CAAC,CAAC;QACpD,OAAO;YACN,IAAI,EAAE,UAAU;YAChB,IAAI;YACJ,QAAQ,EAAE,IAAI;YACd,WAAW,EAAE,IAAI;YACjB,aAAa,EAAE;gB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AC;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 { PolicyFixResult } from \"../policy.js\";\nimport { definePackagePolicy } from \"../policyDefiners/definePackagePolicy.js\";\n\n/**\n * Policy settings for the PackageLicense repo policy.\n *\n * @alpha\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 A PolicyFixResult indicating success or failure.\n */\nasync function copyLicenseFile(\n\trootLicensePath: string,\n\tpackageLicensePath: string,\n\tpolicyName: string,\n\tfile: string,\n\tpackageName: string,\n\tlicenseFileName: string,\n\tisCreate: boolean,\n): Promise<PolicyFixResult> {\n\ttry {\n\t\tawait copyFile(rootLicensePath, packageLicensePath);\n\t\treturn {\n\t\t\tname: policyName,\n\t\t\tfile,\n\t\t\tresolved: true,\n\t\t\tautoFixable: true,\n\t\t\terrorMessages: [\n\t\t\t\tisCreate\n\t\t\t\t\t? `Created ${licenseFileName} file for package \"${packageName}\"`\n\t\t\t\t\t: `Updated ${licenseFileName} file for package \"${packageName}\" to match root`,\n\t\t\t],\n\t\t};\n\t} catch {\n\t\treturn {\n\t\t\tname: policyName,\n\t\t\tfile,\n\t\t\tresolved: false,\n\t\t\tautoFixable: true,\n\t\t\terrorMessages: [\n\t\t\t\tisCreate\n\t\t\t\t\t? `Failed to copy ${licenseFileName} to package \"${packageName}\"`\n\t\t\t\t\t: `Failed to update ${licenseFileName} for package \"${packageName}\"`,\n\t\t\t],\n\t\t};\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, { skipPrivate: false }),\n * ],\n * };\n * ```\n *\n * @alpha\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 true;\n\t\t}\n\n\t\tconst packageName = json.name ?? \"unknown\";\n\t\t// file is an absolute path, get the directory containing package.json\n\t\tconst packageDir = path.dirname(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\tname: POLICY_NAME,\n\t\t\t\tfile,\n\t\t\t\tautoFixable: false,\n\t\t\t\terrorMessages: [\n\t\t\t\t\t`Cannot validate package LICENSE: root ${licenseFileName} file not found`,\n\t\t\t\t],\n\t\t\t};\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\n\t\t\treturn {\n\t\t\t\tname: POLICY_NAME,\n\t\t\t\tfile,\n\t\t\t\tautoFixable: true,\n\t\t\t\terrorMessages: [\n\t\t\t\t\t`${licenseFileName} file missing for package \"${packageName}\"`,\n\t\t\t\t],\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\n\t\t\treturn {\n\t\t\t\tname: POLICY_NAME,\n\t\t\t\tfile,\n\t\t\t\tautoFixable: true,\n\t\t\t\terrorMessages: [\n\t\t\t\t\t`${licenseFileName} file in package \"${packageName}\" doesn't match root ${licenseFileName}`,\n\t\t\t\t],\n\t\t\t};\n\t\t}\n\n\t\treturn true;\n\t},\n});\n"]}
@@ -0,0 +1,124 @@
1
+ /**
2
+ * Configuration for the PackagePrivateField policy.
3
+ *
4
+ * This policy enforces that packages are correctly marked as private or public based on
5
+ * their scope or name. This is essential for monorepos where some packages should be
6
+ * published to npm while others should remain internal.
7
+ *
8
+ * All pattern matching uses glob patterns via picomatch.
9
+ *
10
+ * @example
11
+ * ```typescript
12
+ * const config: PackagePrivateFieldConfig = {
13
+ * // Packages in myorg scope must be published (private: false or absent)
14
+ * mustPublish: ["@myorg/*"],
15
+ * // Packages in internal scope must be private
16
+ * mustBePrivate: ["@internal/*"],
17
+ * // Packages in experimental scope can choose
18
+ * mayPublish: ["@experimental/*"],
19
+ * };
20
+ * ```
21
+ *
22
+ * @alpha
23
+ */
24
+ export interface PackagePrivateFieldConfig {
25
+ /**
26
+ * A list of glob patterns for packages that must be published.
27
+ *
28
+ * Packages matching these patterns must NOT have `private: true` in their package.json.
29
+ * If they do, the policy will fail and can auto-fix by removing the private field.
30
+ *
31
+ * @remarks
32
+ *
33
+ * Uses glob patterns via picomatch. Use "@scope/*" to match all packages in a scope,
34
+ * or use exact package names.
35
+ *
36
+ * @example
37
+ * ```typescript
38
+ * mustPublish: ["@fluidframework/*", "@fluid-tools/*", "tinylicious"]
39
+ * ```
40
+ */
41
+ mustPublish?: string[];
42
+ /**
43
+ * A list of glob patterns for packages that must be private.
44
+ *
45
+ * Packages matching these patterns must have `private: true` in their package.json.
46
+ * If they don't, the policy will fail and can auto-fix by adding `private: true`.
47
+ *
48
+ * @remarks
49
+ *
50
+ * Uses glob patterns via picomatch (see mustPublish for pattern examples).
51
+ *
52
+ * @example
53
+ * ```typescript
54
+ * mustBePrivate: ["@fluid-internal/*", "@fluid-private/*"]
55
+ * ```
56
+ */
57
+ mustBePrivate?: string[];
58
+ /**
59
+ * A list of glob patterns for packages that may optionally be published.
60
+ *
61
+ * Packages matching these patterns can choose whether to be private or public.
62
+ * The policy will not enforce either state for these packages.
63
+ *
64
+ * @remarks
65
+ *
66
+ * Uses glob patterns via picomatch (see mustPublish for pattern examples).
67
+ * Packages not matching any list default to requiring `private: true`.
68
+ *
69
+ * @example
70
+ * ```typescript
71
+ * mayPublish: ["@fluid-experimental/*"]
72
+ * ```
73
+ */
74
+ mayPublish?: string[];
75
+ /**
76
+ * Default behavior for packages that don't match any of the above lists.
77
+ *
78
+ * - `"private"` (default): Unmatched packages must have `private: true`
79
+ * - `"public"`: Unmatched packages must NOT have `private: true`
80
+ * - `"ignore"`: No enforcement for unmatched packages
81
+ *
82
+ * @defaultValue "private"
83
+ */
84
+ unmatchedPackages?: "private" | "public" | "ignore";
85
+ }
86
+ /**
87
+ * A policy that enforces the `private` field in package.json based on package scope or name.
88
+ *
89
+ * This policy is essential for monorepos where publishing control is important:
90
+ *
91
+ * - Prevent accidental publishing of internal packages
92
+ * - Ensure public packages don't have `private: true` blocking publishing
93
+ * - Allow experimental packages to choose their own publishing status
94
+ *
95
+ * @remarks
96
+ *
97
+ * The policy evaluates packages in the following order:
98
+ *
99
+ * 1. If the package matches `mustPublish`, it must NOT have `private: true`
100
+ * 2. If the package matches `mustBePrivate`, it MUST have `private: true`
101
+ * 3. If the package matches `mayPublish`, no enforcement is applied
102
+ * 4. Otherwise, the `unmatchedPackages` setting determines behavior (defaults to requiring private)
103
+ *
104
+ * @example
105
+ * ```typescript
106
+ * import { makePolicy } from "repopo";
107
+ * import { PackagePrivateField } from "repopo/policies";
108
+ *
109
+ * const config: RepopoConfig = {
110
+ * policies: [
111
+ * makePolicy(PackagePrivateField, {
112
+ * mustPublish: ["@myorg/*"],
113
+ * mustBePrivate: ["@internal/*"],
114
+ * mayPublish: ["@experimental/*"],
115
+ * unmatchedPackages: "private",
116
+ * }),
117
+ * ],
118
+ * };
119
+ * ```
120
+ *
121
+ * @alpha
122
+ */
123
+ export declare const PackagePrivateField: import("../policy.js").PolicyDefinition<PackagePrivateFieldConfig | undefined>;
124
+ //# sourceMappingURL=PackagePrivateField.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PackagePrivateField.d.ts","sourceRoot":"","sources":["../../src/policies/PackagePrivateField.ts"],"names":[],"mappings":"AAsBA;;;;;;;;;;;;;;;;;;;;;;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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoCG;AACH,eAAO,MAAM,mBAAmB,gFA+E9B,CAAC"}