@monorepolint/rules 0.5.0-alpha.97 → 0.5.0-beta.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 (151) hide show
  1. package/CHANGELOG.md +14 -0
  2. package/package.json +47 -25
  3. package/src/__tests__/alphabeticalScripts.spec.ts +7 -6
  4. package/src/__tests__/bannedDependencies.spec.ts +7 -9
  5. package/src/__tests__/consistentDependencies.spec.ts +8 -7
  6. package/src/__tests__/consistentVersions.spec.ts +7 -6
  7. package/src/__tests__/fileContents.spec.ts +45 -18
  8. package/src/__tests__/mustSatisfyPeerDependencies.spec.ts +41 -40
  9. package/src/__tests__/nestedWorkspaces.spec.ts +7 -6
  10. package/src/__tests__/packageEntry.spec.ts +44 -33
  11. package/src/__tests__/packageOrder.spec.ts +24 -15
  12. package/src/__tests__/packageScript.spec.ts +62 -44
  13. package/src/__tests__/requireDependency.spec.ts +10 -9
  14. package/src/__tests__/utils.ts +11 -6
  15. package/src/alphabeticalDependencies.ts +7 -9
  16. package/src/alphabeticalScripts.ts +7 -9
  17. package/src/bannedDependencies.ts +9 -10
  18. package/src/consistentDependencies.ts +9 -7
  19. package/src/consistentVersions.ts +6 -5
  20. package/src/fileContents.ts +17 -14
  21. package/src/index.ts +13 -13
  22. package/src/mustSatisfyPeerDependencies.ts +16 -11
  23. package/src/nestedWorkspaces.ts +10 -9
  24. package/src/packageEntry.ts +7 -6
  25. package/src/packageOrder.ts +12 -7
  26. package/src/packageScript.ts +12 -16
  27. package/src/public/util.ts +1 -0
  28. package/src/requireDependency.ts +9 -7
  29. package/src/standardTsconfig.ts +11 -9
  30. package/src/util/checkAlpha.ts +2 -2
  31. package/src/util/makeRule.ts +29 -0
  32. package/src/util/packageDependencyGraphService.ts +2 -2
  33. package/tsconfig.json +10 -2
  34. package/lib/__tests__/alphabeticalScripts.spec.d.ts +0 -8
  35. package/lib/__tests__/alphabeticalScripts.spec.d.ts.map +0 -1
  36. package/lib/__tests__/alphabeticalScripts.spec.js +0 -61
  37. package/lib/__tests__/alphabeticalScripts.spec.js.map +0 -1
  38. package/lib/__tests__/bannedDependencies.spec.d.ts +0 -2
  39. package/lib/__tests__/bannedDependencies.spec.d.ts.map +0 -1
  40. package/lib/__tests__/bannedDependencies.spec.js +0 -161
  41. package/lib/__tests__/bannedDependencies.spec.js.map +0 -1
  42. package/lib/__tests__/consistentDependencies.spec.d.ts +0 -2
  43. package/lib/__tests__/consistentDependencies.spec.d.ts.map +0 -1
  44. package/lib/__tests__/consistentDependencies.spec.js +0 -115
  45. package/lib/__tests__/consistentDependencies.spec.js.map +0 -1
  46. package/lib/__tests__/consistentVersions.spec.d.ts +0 -8
  47. package/lib/__tests__/consistentVersions.spec.d.ts.map +0 -1
  48. package/lib/__tests__/consistentVersions.spec.js +0 -183
  49. package/lib/__tests__/consistentVersions.spec.js.map +0 -1
  50. package/lib/__tests__/fileContents.spec.d.ts +0 -8
  51. package/lib/__tests__/fileContents.spec.d.ts.map +0 -1
  52. package/lib/__tests__/fileContents.spec.js +0 -59
  53. package/lib/__tests__/fileContents.spec.js.map +0 -1
  54. package/lib/__tests__/mustSatisfyPeerDependencies.spec.d.ts +0 -8
  55. package/lib/__tests__/mustSatisfyPeerDependencies.spec.d.ts.map +0 -1
  56. package/lib/__tests__/mustSatisfyPeerDependencies.spec.js +0 -1063
  57. package/lib/__tests__/mustSatisfyPeerDependencies.spec.js.map +0 -1
  58. package/lib/__tests__/nestedWorkspaces.spec.d.ts +0 -2
  59. package/lib/__tests__/nestedWorkspaces.spec.d.ts.map +0 -1
  60. package/lib/__tests__/nestedWorkspaces.spec.js +0 -124
  61. package/lib/__tests__/nestedWorkspaces.spec.js.map +0 -1
  62. package/lib/__tests__/packageEntry.spec.d.ts +0 -8
  63. package/lib/__tests__/packageEntry.spec.d.ts.map +0 -1
  64. package/lib/__tests__/packageEntry.spec.js +0 -144
  65. package/lib/__tests__/packageEntry.spec.js.map +0 -1
  66. package/lib/__tests__/packageOrder.spec.d.ts +0 -8
  67. package/lib/__tests__/packageOrder.spec.d.ts.map +0 -1
  68. package/lib/__tests__/packageOrder.spec.js +0 -116
  69. package/lib/__tests__/packageOrder.spec.js.map +0 -1
  70. package/lib/__tests__/packageScript.spec.d.ts +0 -8
  71. package/lib/__tests__/packageScript.spec.d.ts.map +0 -1
  72. package/lib/__tests__/packageScript.spec.js +0 -171
  73. package/lib/__tests__/packageScript.spec.js.map +0 -1
  74. package/lib/__tests__/requireDependency.spec.d.ts +0 -2
  75. package/lib/__tests__/requireDependency.spec.d.ts.map +0 -1
  76. package/lib/__tests__/requireDependency.spec.js +0 -123
  77. package/lib/__tests__/requireDependency.spec.js.map +0 -1
  78. package/lib/__tests__/utils.d.ts +0 -76
  79. package/lib/__tests__/utils.d.ts.map +0 -1
  80. package/lib/__tests__/utils.js +0 -83
  81. package/lib/__tests__/utils.js.map +0 -1
  82. package/lib/alphabeticalDependencies.d.ts +0 -12
  83. package/lib/alphabeticalDependencies.d.ts.map +0 -1
  84. package/lib/alphabeticalDependencies.js +0 -22
  85. package/lib/alphabeticalDependencies.js.map +0 -1
  86. package/lib/alphabeticalScripts.d.ts +0 -12
  87. package/lib/alphabeticalScripts.d.ts.map +0 -1
  88. package/lib/alphabeticalScripts.js +0 -20
  89. package/lib/alphabeticalScripts.js.map +0 -1
  90. package/lib/bannedDependencies.d.ts +0 -33
  91. package/lib/bannedDependencies.d.ts.map +0 -1
  92. package/lib/bannedDependencies.js +0 -131
  93. package/lib/bannedDependencies.js.map +0 -1
  94. package/lib/consistentDependencies.d.ts +0 -17
  95. package/lib/consistentDependencies.d.ts.map +0 -1
  96. package/lib/consistentDependencies.js +0 -75
  97. package/lib/consistentDependencies.js.map +0 -1
  98. package/lib/consistentVersions.d.ts +0 -14
  99. package/lib/consistentVersions.d.ts.map +0 -1
  100. package/lib/consistentVersions.js +0 -94
  101. package/lib/consistentVersions.js.map +0 -1
  102. package/lib/fileContents.d.ts +0 -25
  103. package/lib/fileContents.d.ts.map +0 -1
  104. package/lib/fileContents.js +0 -82
  105. package/lib/fileContents.js.map +0 -1
  106. package/lib/index.d.ts +0 -20
  107. package/lib/index.d.ts.map +0 -1
  108. package/lib/index.js +0 -36
  109. package/lib/index.js.map +0 -1
  110. package/lib/mustSatisfyPeerDependencies.d.ts +0 -240
  111. package/lib/mustSatisfyPeerDependencies.d.ts.map +0 -1
  112. package/lib/mustSatisfyPeerDependencies.js +0 -636
  113. package/lib/mustSatisfyPeerDependencies.js.map +0 -1
  114. package/lib/nestedWorkspaces.d.ts +0 -13
  115. package/lib/nestedWorkspaces.d.ts.map +0 -1
  116. package/lib/nestedWorkspaces.js +0 -50
  117. package/lib/nestedWorkspaces.js.map +0 -1
  118. package/lib/packageEntry.d.ts +0 -25
  119. package/lib/packageEntry.d.ts.map +0 -1
  120. package/lib/packageEntry.js +0 -75
  121. package/lib/packageEntry.js.map +0 -1
  122. package/lib/packageOrder.d.ts +0 -12
  123. package/lib/packageOrder.d.ts.map +0 -1
  124. package/lib/packageOrder.js +0 -103
  125. package/lib/packageOrder.js.map +0 -1
  126. package/lib/packageScript.d.ts +0 -25
  127. package/lib/packageScript.d.ts.map +0 -1
  128. package/lib/packageScript.js +0 -90
  129. package/lib/packageScript.js.map +0 -1
  130. package/lib/requireDependency.d.ts +0 -15
  131. package/lib/requireDependency.d.ts.map +0 -1
  132. package/lib/requireDependency.js +0 -65
  133. package/lib/requireDependency.js.map +0 -1
  134. package/lib/standardTsconfig.d.ts +0 -45
  135. package/lib/standardTsconfig.d.ts.map +0 -1
  136. package/lib/standardTsconfig.js +0 -116
  137. package/lib/standardTsconfig.js.map +0 -1
  138. package/lib/util/checkAlpha.d.ts +0 -10
  139. package/lib/util/checkAlpha.d.ts.map +0 -1
  140. package/lib/util/checkAlpha.js +0 -51
  141. package/lib/util/checkAlpha.js.map +0 -1
  142. package/lib/util/makeDirectory.d.ts +0 -8
  143. package/lib/util/makeDirectory.d.ts.map +0 -1
  144. package/lib/util/makeDirectory.js +0 -28
  145. package/lib/util/makeDirectory.js.map +0 -1
  146. package/lib/util/packageDependencyGraphService.d.ts +0 -37
  147. package/lib/util/packageDependencyGraphService.d.ts.map +0 -1
  148. package/lib/util/packageDependencyGraphService.js +0 -70
  149. package/lib/util/packageDependencyGraphService.js.map +0 -1
  150. package/tsconfig.tsbuildinfo +0 -1
  151. /package/{jest.config.js → jest.config.cjs} +0 -0
@@ -1,20 +1,19 @@
1
1
  /*!
2
- * Copyright 2019 Palantir Technologies, Inc.
2
+ * Copyright 2023 Palantir Technologies, Inc.
3
3
  *
4
4
  * Licensed under the MIT license. See LICENSE file in the project root for details.
5
5
  *
6
6
  */
7
7
 
8
- import { Context } from "@monorepolint/core";
9
- import { RuleModule } from "@monorepolint/core";
10
- import diff from "jest-diff";
8
+ import { Context } from "@monorepolint/config";
9
+ import { diff } from "jest-diff";
11
10
  import * as path from "path";
12
11
  import * as r from "runtypes";
13
-
12
+ import { makeRule } from "./util/makeRule.js";
14
13
  const Options = r.Union(
15
14
  r.Record({
16
15
  file: r.String,
17
- generator: r.Function,
16
+ generator: r.Function.withGuard((x): x is (context: Context) => string | Promise<string> => x != undefined),
18
17
  template: r.Undefined.optional(),
19
18
  templateFile: r.Undefined.optional(),
20
19
  }),
@@ -36,10 +35,11 @@ const Options = r.Union(
36
35
 
37
36
  type Options = r.Static<typeof Options>;
38
37
 
39
- export const fileContents = {
40
- check: function expectFileContents(context: Context, opts: Options) {
38
+ export const fileContents = makeRule<Options>({
39
+ name: "fileContents",
40
+ check: async (context, opts) => {
41
41
  const fullPath = path.join(context.packageDir, opts.file);
42
- const expectedContent = getExpectedContents(context, opts);
42
+ const expectedContent = await getExpectedContents(context, opts);
43
43
 
44
44
  const pathExists = context.host.exists(fullPath);
45
45
  const actualContent = pathExists ? context.host.readFile(fullPath, { encoding: "utf-8" }) : undefined;
@@ -59,12 +59,15 @@ export const fileContents = {
59
59
  });
60
60
  }
61
61
  },
62
- optionsRuntype: Options,
63
- } as RuleModule<typeof Options>;
62
+ validateOptions: Options.check,
63
+ });
64
64
 
65
- const optionsCache = new Map<Options, ((context: Context) => string | undefined) | string | undefined>();
65
+ const optionsCache = new Map<
66
+ Options,
67
+ ((context: Context) => Promise<string> | string | undefined) | string | undefined
68
+ >();
66
69
 
67
- function getExpectedContents(context: Context, opts: Options) {
70
+ async function getExpectedContents(context: Context, opts: Options) {
68
71
  // we need to use has because undefined is a valid value in the cache
69
72
  if (optionsCache.has(opts)) {
70
73
  const cachedEntry = optionsCache.get(opts);
@@ -76,7 +79,7 @@ function getExpectedContents(context: Context, opts: Options) {
76
79
 
77
80
  if (opts.generator) {
78
81
  optionsCache.set(opts, opts.generator);
79
- return opts.generator(context) as string | undefined; // we have no guarentee its the right kind of function
82
+ return opts.generator(context);
80
83
  } else if (opts.templateFile) {
81
84
  const { packageDir: workspacePackageDir } = context.getWorkspaceContext();
82
85
  const fullPath = path.resolve(workspacePackageDir, opts.templateFile);
package/src/index.ts CHANGED
@@ -5,16 +5,16 @@
5
5
  *
6
6
  */
7
7
 
8
- export { alphabeticalDependencies } from "./alphabeticalDependencies";
9
- export { alphabeticalScripts } from "./alphabeticalScripts";
10
- export { bannedDependencies } from "./bannedDependencies";
11
- export { consistentDependencies } from "./consistentDependencies";
12
- export { consistentVersions } from "./consistentVersions";
13
- export { fileContents } from "./fileContents";
14
- export { mustSatisfyPeerDependencies } from "./mustSatisfyPeerDependencies";
15
- export { packageOrder } from "./packageOrder";
16
- export { packageEntry } from "./packageEntry";
17
- export { packageScript } from "./packageScript";
18
- export { standardTsconfig } from "./standardTsconfig";
19
- export { nestedWorkspaces } from "./nestedWorkspaces";
20
- export { requireDependency } from "./requireDependency";
8
+ export { alphabeticalDependencies } from "./alphabeticalDependencies.js";
9
+ export { alphabeticalScripts } from "./alphabeticalScripts.js";
10
+ export { bannedDependencies } from "./bannedDependencies.js";
11
+ export { consistentDependencies } from "./consistentDependencies.js";
12
+ export { consistentVersions } from "./consistentVersions.js";
13
+ export { fileContents } from "./fileContents.js";
14
+ export { mustSatisfyPeerDependencies } from "./mustSatisfyPeerDependencies.js";
15
+ export { packageOrder } from "./packageOrder.js";
16
+ export { packageEntry } from "./packageEntry.js";
17
+ export { packageScript } from "./packageScript.js";
18
+ export { standardTsconfig } from "./standardTsconfig.js";
19
+ export { nestedWorkspaces } from "./nestedWorkspaces.js";
20
+ export { requireDependency } from "./requireDependency.js";
@@ -5,12 +5,13 @@
5
5
  *
6
6
  */
7
7
 
8
- import { Context, RuleModule } from "@monorepolint/core";
8
+ import { Context } from "@monorepolint/config";
9
9
  import { Host, mutateJson, PackageJson } from "@monorepolint/utils";
10
- import path from "path";
11
- import resolvePackagePath from "resolve-package-path";
10
+ import * as path from "node:path";
12
11
  import * as r from "runtypes";
13
12
  import { coerce } from "semver";
13
+ import resolvePackagePath from "resolve-package-path";
14
+ import { makeRule } from "./util/makeRule.js";
14
15
 
15
16
  const Options = r.Union(
16
17
  r.Partial({
@@ -183,10 +184,11 @@ const Options = r.Union(
183
184
 
184
185
  export type Options = r.Static<typeof Options>;
185
186
 
186
- export const mustSatisfyPeerDependencies: RuleModule<typeof Options> = {
187
+ export const mustSatisfyPeerDependencies = makeRule({
188
+ name: "mustSatisfyPeerDependencies",
187
189
  check: checkSatisfyPeerDependencies,
188
- optionsRuntype: Options,
189
- };
190
+ validateOptions: Options.check,
191
+ });
190
192
 
191
193
  /**
192
194
  * separating on `|`, this regex allows any of the following formats:
@@ -213,7 +215,8 @@ export const MATCH_ANY_VERSION_RANGE = /^(\*|x)$/;
213
215
  *
214
216
  * More info: https://docs.npmjs.com/about-semantic-versioning
215
217
  */
216
- export const MATCH_GREATER_OR_EQUAL_VERSION_RANGE = /^>= ?\d+(?:\.\d+|\.\d+\.\d+(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?)?$/;
218
+ export const MATCH_GREATER_OR_EQUAL_VERSION_RANGE =
219
+ /^>= ?\d+(?:\.\d+|\.\d+\.\d+(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?)?$/;
217
220
 
218
221
  /**
219
222
  * This regex allows any of the following formats:
@@ -237,7 +240,8 @@ export const MATCH_GREATER_OR_EQUAL_VERSION_RANGE = /^>= ?\d+(?:\.\d+|\.\d+\.\d+
237
240
  *
238
241
  * More info: https://docs.npmjs.com/about-semantic-versioning
239
242
  */
240
- export const MATCH_MAJOR_VERSION_RANGE = /^(?:\^?\d+|\^?\d+\.x|\^?\d+\.x\.x|\^\d+\.\d+|\^\d+\.\d+\.x|\^\d+\.\d+\.\d+(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?)$/;
243
+ export const MATCH_MAJOR_VERSION_RANGE =
244
+ /^(?:\^?\d+|\^?\d+\.x|\^?\d+\.x\.x|\^\d+\.\d+|\^\d+\.\d+\.x|\^\d+\.\d+\.\d+(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?)$/;
241
245
 
242
246
  /**
243
247
  * Does not currently accept `<`, `<=`, `>`, `=` or `-` for ranges (e.g. `> 2.5.1 < 3` or `1.0.0 - 1.2.0`),
@@ -252,7 +256,8 @@ export const MATCH_MAJOR_VERSION_RANGE = /^(?:\^?\d+|\^?\d+\.x|\^?\d+\.x\.x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+\.\d+(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?)?)*)$/;
256
261
 
257
262
  interface IPeerDependencyRequirement {
258
263
  fromPackageName: string;
@@ -267,7 +272,7 @@ interface IResolvedPeerDependencyRequirement {
267
272
  function checkSatisfyPeerDependencies(context: Context, opts: Options) {
268
273
  const { dependencyBlacklist, dependencyWhitelist, enforceForDevDependencies, skipUnparseableRanges } = opts;
269
274
  const packageJsonPath = path.resolve(context.getPackageJsonPath());
270
- const packageJson: PackageJson = require(packageJsonPath);
275
+ const packageJson = context.host.readJson(packageJsonPath) as PackageJson;
271
276
  const packageDependencies = packageJson.dependencies || {};
272
277
  const packageDevDependencies = packageJson.devDependencies || {};
273
278
  const packagePeerDependencies = packageJson.peerDependencies || {};
@@ -302,7 +307,7 @@ function checkSatisfyPeerDependencies(context: Context, opts: Options) {
302
307
  if (dependencyPackageJsonPath == null) {
303
308
  throw new Error(`Could not resolve ${dependency} from ${path.dirname(packageJsonPath)}`);
304
309
  }
305
- const dependencyPackageJson: PackageJson = require(dependencyPackageJsonPath);
310
+ const dependencyPackageJson = context.host.readJson(dependencyPackageJsonPath) as PackageJson;
306
311
  const requiredPeerDependencies = dependencyPackageJson.peerDependencies;
307
312
  if (requiredPeerDependencies == null) {
308
313
  continue;
@@ -5,22 +5,23 @@
5
5
  *
6
6
  */
7
7
 
8
- import { Context, RuleModule } from "@monorepolint/core";
9
- import globby from "globby";
10
- import path from "path";
8
+ import * as globby from "globby";
9
+ import * as path from "node:path";
11
10
  import * as r from "runtypes";
11
+ import { makeRule } from "./util/makeRule.js";
12
12
 
13
13
  export const Options = r.Undefined;
14
14
 
15
15
  type Options = r.Static<typeof Options>;
16
16
 
17
17
  // Enforce that the root package.json contains all of the workspaces in the repo (including nested packages)
18
- export const nestedWorkspaces: RuleModule<typeof Options> = {
19
- check: (context: Context) => {
18
+ export const nestedWorkspaces = makeRule({
19
+ name: "nestedWorkspaces",
20
+ check: (context) => {
20
21
  const rootPackageJson = context.getWorkspaceContext().getPackageJson();
21
22
 
22
23
  // Expand a set of globs covering all package.json files in the entire repo (except the root)
23
- const packageJsonPaths = globby.sync(["*/**/package.json", "!**/node_modules/**"]);
24
+ const packageJsonPaths = globby.globbySync(["*/**/package.json", "!**/node_modules/**"]);
24
25
 
25
26
  const workspaces = Array.isArray(rootPackageJson.workspaces)
26
27
  ? rootPackageJson.workspaces
@@ -40,7 +41,7 @@ export const nestedWorkspaces: RuleModule<typeof Options> = {
40
41
  const workspacePackageJsons = (workspaces || []).map((item) => `${item}/package.json`);
41
42
 
42
43
  // Expand the globs to get an array of all package.json files that are in packages specified by a workspace.
43
- const expandedWorkspacesGlobs = globby.sync([...workspacePackageJsons, "!**/node_modules/**"]);
44
+ const expandedWorkspacesGlobs = globby.globbySync([...workspacePackageJsons, "!**/node_modules/**"]);
44
45
 
45
46
  // Ensure there are no package.jsons which are not included in the globbed workspaces set
46
47
  const difference = packageJsonPaths.filter((packageJsonPath) => !expandedWorkspacesGlobs.includes(packageJsonPath));
@@ -55,5 +56,5 @@ export const nestedWorkspaces: RuleModule<typeof Options> = {
55
56
  });
56
57
  }
57
58
  },
58
- optionsRuntype: Options,
59
- };
59
+ validateOptions: Options.check,
60
+ });
@@ -5,10 +5,10 @@
5
5
  *
6
6
  */
7
7
 
8
- import { Context, RuleModule } from "@monorepolint/core";
9
8
  import { mutateJson, PackageJson } from "@monorepolint/utils";
10
- import diff from "jest-diff";
9
+ import { diff } from "jest-diff";
11
10
  import * as r from "runtypes";
11
+ import { makeRule } from "./util/makeRule.js";
12
12
 
13
13
  export const Options = r.Union(
14
14
  r
@@ -37,8 +37,9 @@ export const Options = r.Union(
37
37
 
38
38
  export type Options = r.Static<typeof Options>;
39
39
 
40
- export const packageEntry: RuleModule<typeof Options> = {
41
- check: function expectPackageEntry(context: Context, options: Options) {
40
+ export const packageEntry = makeRule<Options>({
41
+ name: "packageEntry",
42
+ check: (context, options) => {
42
43
  const packageJson = context.getPackageJson();
43
44
 
44
45
  if (options.entries) {
@@ -77,8 +78,8 @@ export const packageEntry: RuleModule<typeof Options> = {
77
78
  }
78
79
  }
79
80
  },
80
- optionsRuntype: Options,
81
- };
81
+ validateOptions: Options.check,
82
+ });
82
83
 
83
84
  export function createStandardizedEntryErrorMessage(key: string) {
84
85
  return `Expected standardized entry for '${key}'`;
@@ -5,10 +5,10 @@
5
5
  *
6
6
  */
7
7
 
8
- import { Context, RuleModule } from "@monorepolint/core";
9
- import diff from "jest-diff";
8
+ import { Context } from "@monorepolint/config";
9
+ import { diff } from "jest-diff";
10
10
  import * as r from "runtypes";
11
-
11
+ import { makeRule } from "./util/makeRule.js";
12
12
  type OrderFunction = (context: Context) => (a: string, b: string) => number;
13
13
 
14
14
  const Options = r
@@ -27,9 +27,12 @@ const defaultKeyOrder = [
27
27
  "contributors",
28
28
  "url",
29
29
  "license",
30
+ "type",
31
+ "exports",
30
32
  "private",
31
33
  "engines",
32
34
  "bin",
35
+ "types",
33
36
  "main",
34
37
  "module",
35
38
  "typings",
@@ -48,8 +51,9 @@ const defaultKeyOrder = [
48
51
  "publishConfig",
49
52
  ];
50
53
 
51
- export const packageOrder = {
52
- check: function expectPackageOrder(context: Context, opts: Options) {
54
+ export const packageOrder = makeRule<Options>({
55
+ name: "packageOrder",
56
+ check: (context, opts) => {
53
57
  const packageJson = context.getPackageJson();
54
58
  const packagePath = context.getPackageJsonPath();
55
59
 
@@ -66,6 +70,7 @@ export const packageOrder = {
66
70
  message: "Incorrect order of fields in package.json",
67
71
  longMessage: diff(expectedOrder, actualOrder, { expand: true }),
68
72
  fixer: () => {
73
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
69
74
  const expectedPackageJson: Record<string, any> = {};
70
75
 
71
76
  expectedOrder.forEach((key) => {
@@ -77,8 +82,8 @@ export const packageOrder = {
77
82
  });
78
83
  }
79
84
  },
80
- optionsRuntype: Options,
81
- } as RuleModule<typeof Options>;
85
+ validateOptions: Options.check,
86
+ });
82
87
 
83
88
  function arrayOrderCompare(a: ReadonlyArray<string>, b: ReadonlyArray<string>) {
84
89
  for (let index = 0; index < a.length; index++) {
@@ -5,24 +5,19 @@
5
5
  *
6
6
  */
7
7
 
8
- import { Context, RuleModule } from "@monorepolint/core";
9
8
  import { mutateJson, PackageJson } from "@monorepolint/utils";
10
- import diff from "jest-diff";
9
+ import { diff } from "jest-diff";
11
10
  import * as r from "runtypes";
11
+ import { makeRule } from "./util/makeRule.js";
12
12
 
13
13
  export const Options = r.Record({
14
14
  scripts: r.Dictionary(
15
15
  r.Union(
16
16
  r.String,
17
- r
18
- .Record({
19
- options: r.Array(r.String.Or(r.Undefined)),
20
- })
21
- .And(
22
- r.Partial({
23
- fixValue: r.Union(r.String, r.Undefined, r.Literal(false)),
24
- })
25
- )
17
+ r.Record({
18
+ options: r.Array(r.String.Or(r.Undefined)),
19
+ fixValue: r.Union(r.String, r.Undefined, r.Literal(false)).optional(),
20
+ })
26
21
  )
27
22
  ), // string => string
28
23
  });
@@ -31,8 +26,9 @@ export type Options = r.Static<typeof Options>;
31
26
 
32
27
  export const MSG_NO_SCRIPTS_BLOCK = "No scripts block in package.json";
33
28
 
34
- export const packageScript = {
35
- check: function expectPackageScript(context: Context, options: Options) {
29
+ export const packageScript = makeRule<Options>({
30
+ name: "packageScript",
31
+ check: (context, options) => {
36
32
  const packageJson = context.getPackageJson();
37
33
  if (packageJson.scripts === undefined) {
38
34
  context.addError({
@@ -63,7 +59,7 @@ export const packageScript = {
63
59
  }
64
60
  allowedValues.add(q);
65
61
  }
66
- fixToEmpty = value.hasOwnProperty("fixValue") && value.fixValue === undefined;
62
+ fixToEmpty = Object.prototype.hasOwnProperty.call(value, "fixValue") && value.fixValue === undefined;
67
63
  fixValue = value.fixValue;
68
64
  }
69
65
 
@@ -99,5 +95,5 @@ export const packageScript = {
99
95
  }
100
96
  }
101
97
  },
102
- optionsRuntype: Options,
103
- } as RuleModule<typeof Options>;
98
+ validateOptions: Options.check,
99
+ });
@@ -0,0 +1 @@
1
+ export { makeRule } from "../util/makeRule.js";
@@ -5,10 +5,11 @@
5
5
  *
6
6
  */
7
7
 
8
- import { Context, RuleModule } from "@monorepolint/core";
8
+ import { Context } from "@monorepolint/config";
9
9
  import { mutateJson, PackageJson } from "@monorepolint/utils";
10
- import diff from "jest-diff";
10
+ import { diff } from "jest-diff";
11
11
  import * as r from "runtypes";
12
+ import { makeRule } from "./util/makeRule.js";
12
13
 
13
14
  const Options = r.Partial({
14
15
  dependencies: r.Dictionary(r.String),
@@ -19,7 +20,8 @@ const Options = r.Partial({
19
20
 
20
21
  type Options = r.Static<typeof Options>;
21
22
 
22
- export const requireDependency = {
23
+ export const requireDependency = makeRule({
24
+ name: "requireDependency",
23
25
  check: function expectPackageEntry(context: Context, options: Options) {
24
26
  const packageJson = context.getPackageJson();
25
27
  const packageJsonPath = context.getPackageJsonPath();
@@ -49,11 +51,11 @@ export const requireDependency = {
49
51
  }
50
52
 
51
53
  for (const [dep, version] of Object.entries(options[type]!)) {
52
- if (packageJson[type][dep] !== version) {
54
+ if (packageJson[type]?.[dep] !== version) {
53
55
  context.addError({
54
56
  file: packageJsonPath,
55
57
  message: `Expected dependency ${dep}@${version}`,
56
- longMessage: diff(`${dep}@${version}\n`, `${dep}@${packageJson[type][dep] || "missing"}\n`)!,
58
+ longMessage: diff(`${dep}@${version}\n`, `${dep}@${packageJson[type]![dep] || "missing"}\n`)!,
57
59
  fixer: () => {
58
60
  mutateJson<PackageJson>(packageJsonPath, context.host, (input) => {
59
61
  input[type] = { ...input[type], [dep]: version };
@@ -65,5 +67,5 @@ export const requireDependency = {
65
67
  }
66
68
  });
67
69
  },
68
- optionsRuntype: Options,
69
- } as RuleModule<typeof Options>;
70
+ validateOptions: Options.check,
71
+ });
@@ -5,11 +5,12 @@
5
5
  *
6
6
  */
7
7
 
8
- import { Context, RuleModule } from "@monorepolint/core";
8
+ import { Context } from "@monorepolint/config";
9
9
  import { matchesAnyGlob } from "@monorepolint/utils";
10
- import diff from "jest-diff";
10
+ import { diff } from "jest-diff";
11
11
  import * as path from "path";
12
12
  import * as r from "runtypes";
13
+ import { makeRule } from "./util/makeRule.js";
13
14
 
14
15
  const DEFAULT_TSCONFIG_FILENAME = "tsconfig.json";
15
16
 
@@ -38,10 +39,11 @@ const Options = r
38
39
  return count === 1 || "Expect one of { generator, template, templateFile }";
39
40
  });
40
41
 
41
- export type Options = r.Static<typeof Options>;
42
+ export interface Options extends r.Static<typeof Options> {}
42
43
 
43
- export const standardTsconfig = {
44
- check: async function expectStandardTsconfig(context: Context, opts: Options) {
44
+ export const standardTsconfig = makeRule<Options>({
45
+ name: "standardTsconfig",
46
+ check: async (context, opts) => {
45
47
  const tsconfigFileName = opts.file ?? DEFAULT_TSCONFIG_FILENAME;
46
48
  const fullPath = path.resolve(context.packageDir, tsconfigFileName);
47
49
  const generator = getGenerator(context, opts);
@@ -72,8 +74,8 @@ export const standardTsconfig = {
72
74
  });
73
75
  }
74
76
  },
75
- optionsRuntype: Options,
76
- } as RuleModule<typeof Options>;
77
+ validateOptions: Options.check,
78
+ });
77
79
 
78
80
  function getGenerator(context: Context, opts: Options) {
79
81
  if (opts.generator) {
@@ -92,6 +94,7 @@ function getGenerator(context: Context, opts: Options) {
92
94
  }
93
95
 
94
96
  function makeGenerator(
97
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
95
98
  template: any,
96
99
  excludedReferences: ReadonlyArray<string> | undefined,
97
100
  additionalReferences: ReadonlyArray<string> | undefined,
@@ -107,10 +110,9 @@ function makeGenerator(
107
110
 
108
111
  const packageJson = context.getPackageJson();
109
112
  const deps = [...Object.keys(packageJson.dependencies || {}), ...Object.keys(packageJson.devDependencies || {})];
110
-
111
113
  for (const dep of deps) {
112
114
  const packageDir = nameToDirectory.get(dep);
113
- if (packageDir !== undefined && (excludedReferences === undefined || matchesAnyGlob(dep, excludedReferences))) {
115
+ if (packageDir !== undefined && (excludedReferences === undefined || !matchesAnyGlob(dep, excludedReferences))) {
114
116
  const absoluteReferencePath =
115
117
  tsconfigReferenceFile !== undefined ? path.join(packageDir, tsconfigReferenceFile) : packageDir;
116
118
  template.references.push({
@@ -5,8 +5,8 @@
5
5
  *
6
6
  */
7
7
 
8
- import { Context } from "@monorepolint/core";
9
- import diff from "jest-diff";
8
+ import { Context } from "@monorepolint/config";
9
+ import { diff } from "jest-diff";
10
10
 
11
11
  export function checkAlpha(
12
12
  context: Context,
@@ -0,0 +1,29 @@
1
+ import { Context, RuleEntry, RuleModule } from "@monorepolint/config";
2
+
3
+ let globalId = 0;
4
+ export function makeRule<X>({
5
+ name,
6
+ check,
7
+ validateOptions,
8
+ printStats,
9
+ }: {
10
+ name: string;
11
+ check: (context: Context, options: X, extra: { id: string }) => Promise<unknown> | unknown;
12
+ printStats?: () => void;
13
+ validateOptions: (options: unknown) => asserts options is X;
14
+ }): RuleFunction<X> {
15
+ return function (ruleEntry) {
16
+ const id = `${name} :: ${globalId++}`;
17
+ return {
18
+ id,
19
+ // eslint-disable-next-line @typescript-eslint/no-extra-non-null-assertion
20
+ check: (context) => check(context, ruleEntry.options!!, { id }),
21
+ name,
22
+ validateOptions,
23
+ ruleEntry,
24
+ printStats,
25
+ };
26
+ };
27
+ }
28
+
29
+ type RuleFunction<T> = (ruleEntry: RuleEntry<T>) => RuleModule<T>;
@@ -3,7 +3,7 @@
3
3
  */
4
4
 
5
5
  import { Host, PackageJson } from "@monorepolint/utils";
6
- import path from "path";
6
+ import * as path from "node:path";
7
7
  import resolvePackagePath from "resolve-package-path";
8
8
 
9
9
  /** Interface for a node in a package dependency graph. */
@@ -45,7 +45,7 @@ export class PackageDependencyGraphService implements IPackageDependencyGraphSer
45
45
  return nodes.get(packageJsonPath)!;
46
46
  }
47
47
 
48
- const packageJson: PackageJson = host.readJson(packageJsonPath);
48
+ const packageJson = host.readJson(packageJsonPath) as PackageJson;
49
49
  const node: IPackageDependencyGraphNode = {
50
50
  packageJson,
51
51
  dependencies: new Map<string, IPackageDependencyGraphNode>(),
package/tsconfig.json CHANGED
@@ -1,10 +1,18 @@
1
1
  {
2
2
  "extends": "../../tsconfig.base.json",
3
3
  "compilerOptions": {
4
- "outDir": "./lib",
5
- "rootDir": "./src"
4
+ "outDir": "./build/js",
5
+ "rootDir": "./src",
6
+ "declarationDir": "./build/types",
7
+ "tsBuildInfoFile": "./build/tsconfig.tsbuildinfo"
6
8
  },
9
+ "include": [
10
+ "src"
11
+ ],
7
12
  "references": [
13
+ {
14
+ "path": "../config"
15
+ },
8
16
  {
9
17
  "path": "../core"
10
18
  },
@@ -1,8 +0,0 @@
1
- /*!
2
- * Copyright 2019 Palantir Technologies, Inc.
3
- *
4
- * Licensed under the MIT license. See LICENSE file in the project root for details.
5
- *
6
- */
7
- export {};
8
- //# sourceMappingURL=alphabeticalScripts.spec.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"alphabeticalScripts.spec.d.ts","sourceRoot":"","sources":["../../src/__tests__/alphabeticalScripts.spec.ts"],"names":[],"mappings":"AAAA;;;;;GAKG"}
@@ -1,61 +0,0 @@
1
- "use strict";
2
- /*!
3
- * Copyright 2019 Palantir Technologies, Inc.
4
- *
5
- * Licensed under the MIT license. See LICENSE file in the project root for details.
6
- *
7
- */
8
- Object.defineProperty(exports, "__esModule", { value: true });
9
- // tslint:disable:no-console
10
- const utils_1 = require("./utils");
11
- const alphabeticalScripts_1 = require("../alphabeticalScripts");
12
- const checkAlpha_1 = require("../util/checkAlpha");
13
- const PACKAGE_SCRIPTS_SORTED = (0, utils_1.jsonToString)({
14
- name: "foo-lib",
15
- scripts: {
16
- a: "a-",
17
- b: "b-",
18
- c: "c-",
19
- },
20
- });
21
- const PACKAGE_SCRIPTS_UNSORTED = (0, utils_1.jsonToString)({
22
- name: "foo-lib",
23
- scripts: {
24
- c: "c-",
25
- a: "a-",
26
- b: "b-",
27
- },
28
- });
29
- describe.each(utils_1.HOST_FACTORIES)("alphabeticalScripts ($name)", (hostFactory) => {
30
- describe("fix: true", () => {
31
- let workspace;
32
- let spy;
33
- let context;
34
- beforeEach(async () => {
35
- workspace = await (0, utils_1.createTestingWorkspace)({
36
- fixFlag: true,
37
- host: hostFactory.make(),
38
- });
39
- context = workspace.context; // minimizing delta
40
- spy = jest.spyOn(workspace.context, "addError");
41
- });
42
- it("fixes unsorted scripts", () => {
43
- workspace.writeFile("package.json", PACKAGE_SCRIPTS_UNSORTED);
44
- alphabeticalScripts_1.alphabeticalScripts.check(context, undefined);
45
- expect(spy).toHaveBeenCalledTimes(1);
46
- const failure = spy.mock.calls[0][0];
47
- expect(failure).toMatchObject(workspace.failureMatcher({
48
- file: "package.json",
49
- hasFixer: true,
50
- message: (0, checkAlpha_1.createIncorrectOrderErrorMessage)("scripts", "foo-lib"),
51
- }));
52
- expect(workspace.readFile("package.json")).toEqual(PACKAGE_SCRIPTS_SORTED);
53
- });
54
- it("does nothing if already sorted", () => {
55
- workspace.writeFile("package.json", PACKAGE_SCRIPTS_SORTED);
56
- alphabeticalScripts_1.alphabeticalScripts.check(context, undefined);
57
- expect(spy).toHaveBeenCalledTimes(0);
58
- });
59
- });
60
- });
61
- //# sourceMappingURL=alphabeticalScripts.spec.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"alphabeticalScripts.spec.js","sourceRoot":"","sources":["../../src/__tests__/alphabeticalScripts.spec.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;AAEH,4BAA4B;AAC5B,mCAA8G;AAE9G,gEAA6D;AAC7D,mDAAsE;AAEtE,MAAM,sBAAsB,GAAG,IAAA,oBAAY,EAAC;IAC1C,IAAI,EAAE,SAAS;IACf,OAAO,EAAE;QACP,CAAC,EAAE,IAAI;QACP,CAAC,EAAE,IAAI;QACP,CAAC,EAAE,IAAI;KACR;CACF,CAAC,CAAC;AAEH,MAAM,wBAAwB,GAAG,IAAA,oBAAY,EAAC;IAC5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C,SAAS,CAAC,QAAQ,CAAC,cAAc,CAAC,CAAC,CAAC,OAAO,CAAC,sBAAsB,CAAC,CAAC;QAC7E,CAAC,CAAC,CAAC;QAEH,EAAE,CAAC,gCAAgC,EAAE,GAAG,EAAE;YACxC,SAAS,CAAC,SAAS,CAAC,cAAc,EAAE,sBAAsB,CAAC,CAAC;YAE5D,yCAAmB,CAAC,KAAK,CAAC,OAAO,EAAE,SAAS,CAAC,CAAC;YAE9C,MAAM,CAAC,GAAG,CAAC,CAAC,qBAAqB,CAAC,CAAC,CAAC,CAAC;QACvC,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=bannedDependencies.spec.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"bannedDependencies.spec.d.ts","sourceRoot":"","sources":["../../src/__tests__/bannedDependencies.spec.ts"],"names":[],"mappings":""}