@monorepolint/rules 0.5.0-alpha.12 → 0.5.0-alpha.125

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 (171) hide show
  1. package/.turbo/turbo-clean.log +4 -0
  2. package/.turbo/turbo-compile-typescript.log +4 -0
  3. package/.turbo/turbo-lint.log +14 -0
  4. package/.turbo/turbo-test.log +666 -0
  5. package/.turbo/turbo-transpile-typescript.log +18 -0
  6. package/build/js/chunk-A2MUUSNE.js +26 -0
  7. package/build/js/chunk-A2MUUSNE.js.map +1 -0
  8. package/build/js/index.js +1402 -0
  9. package/build/js/index.js.map +1 -0
  10. package/build/js/public/util.js +7 -0
  11. package/build/js/public/util.js.map +1 -0
  12. package/build/tsconfig.tsbuildinfo +1 -0
  13. package/build/types/__tests__/alphabeticalScripts.spec.d.ts.map +1 -0
  14. package/build/types/__tests__/bannedDependencies.spec.d.ts +2 -0
  15. package/build/types/__tests__/bannedDependencies.spec.d.ts.map +1 -0
  16. package/build/types/__tests__/consistentDependencies.spec.d.ts.map +1 -0
  17. package/build/types/__tests__/consistentVersions.spec.d.ts +8 -0
  18. package/build/types/__tests__/consistentVersions.spec.d.ts.map +1 -0
  19. package/build/types/__tests__/fileContents.spec.d.ts +8 -0
  20. package/build/types/__tests__/fileContents.spec.d.ts.map +1 -0
  21. package/build/types/__tests__/mustSatisfyPeerDependencies.spec.d.ts +8 -0
  22. package/build/types/__tests__/mustSatisfyPeerDependencies.spec.d.ts.map +1 -0
  23. package/build/types/__tests__/nestedWorkspaces.spec.d.ts +2 -0
  24. package/build/types/__tests__/nestedWorkspaces.spec.d.ts.map +1 -0
  25. package/build/types/__tests__/packageEntry.spec.d.ts.map +1 -0
  26. package/build/types/__tests__/packageOrder.spec.d.ts.map +1 -0
  27. package/build/types/__tests__/packageScript.spec.d.ts.map +1 -0
  28. package/build/types/__tests__/requireDependency.spec.d.ts +2 -0
  29. package/build/types/__tests__/requireDependency.spec.d.ts.map +1 -0
  30. package/build/types/__tests__/utils.d.ts +81 -0
  31. package/build/types/__tests__/utils.d.ts.map +1 -0
  32. package/build/types/alphabeticalDependencies.d.ts +8 -0
  33. package/build/types/alphabeticalDependencies.d.ts.map +1 -0
  34. package/build/types/alphabeticalScripts.d.ts +8 -0
  35. package/build/types/alphabeticalScripts.d.ts.map +1 -0
  36. package/build/types/bannedDependencies.d.ts +66 -0
  37. package/build/types/bannedDependencies.d.ts.map +1 -0
  38. package/build/types/consistentDependencies.d.ts +18 -0
  39. package/build/types/consistentDependencies.d.ts.map +1 -0
  40. package/build/types/consistentVersions.d.ts +25 -0
  41. package/build/types/consistentVersions.d.ts.map +1 -0
  42. package/build/types/fileContents.d.ts +39 -0
  43. package/build/types/fileContents.d.ts.map +1 -0
  44. package/build/types/index.d.ts +20 -0
  45. package/build/types/index.d.ts.map +1 -0
  46. package/build/types/mustSatisfyPeerDependencies.d.ts +427 -0
  47. package/build/types/mustSatisfyPeerDependencies.d.ts.map +1 -0
  48. package/build/types/nestedWorkspaces.d.ts +10 -0
  49. package/build/types/nestedWorkspaces.d.ts.map +1 -0
  50. package/build/types/packageEntry.d.ts +62 -0
  51. package/build/types/packageEntry.d.ts.map +1 -0
  52. package/build/types/packageOrder.d.ts +12 -0
  53. package/build/types/packageOrder.d.ts.map +1 -0
  54. package/build/types/packageScript.d.ts +47 -0
  55. package/build/types/packageScript.d.ts.map +1 -0
  56. package/build/types/public/util.d.ts +2 -0
  57. package/build/types/public/util.d.ts.map +1 -0
  58. package/build/types/requireDependency.d.ts +50 -0
  59. package/build/types/requireDependency.d.ts.map +1 -0
  60. package/build/types/standardTsconfig.d.ts +29 -0
  61. package/build/types/standardTsconfig.d.ts.map +1 -0
  62. package/{lib → build/types}/util/checkAlpha.d.ts +2 -1
  63. package/build/types/util/checkAlpha.d.ts.map +1 -0
  64. package/build/types/util/makeDirectory.d.ts +8 -0
  65. package/build/types/util/makeDirectory.d.ts.map +1 -0
  66. package/build/types/util/makeRule.d.ts +12 -0
  67. package/build/types/util/makeRule.d.ts.map +1 -0
  68. package/build/types/util/packageDependencyGraphService.d.ts +37 -0
  69. package/build/types/util/packageDependencyGraphService.d.ts.map +1 -0
  70. package/package.json +45 -20
  71. package/src/__tests__/alphabeticalScripts.spec.ts +33 -31
  72. package/src/__tests__/bannedDependencies.spec.ts +189 -0
  73. package/src/__tests__/consistentDependencies.spec.ts +42 -26
  74. package/src/__tests__/consistentVersions.spec.ts +224 -0
  75. package/src/__tests__/fileContents.spec.ts +101 -0
  76. package/src/__tests__/mustSatisfyPeerDependencies.spec.ts +1189 -0
  77. package/src/__tests__/nestedWorkspaces.spec.ts +153 -0
  78. package/src/__tests__/packageEntry.spec.ts +127 -49
  79. package/src/__tests__/packageOrder.spec.ts +68 -53
  80. package/src/__tests__/packageScript.spec.ts +124 -98
  81. package/src/__tests__/requireDependency.spec.ts +152 -0
  82. package/src/__tests__/utils.ts +113 -13
  83. package/src/alphabeticalDependencies.ts +7 -9
  84. package/src/alphabeticalScripts.ts +7 -9
  85. package/src/bannedDependencies.ts +135 -46
  86. package/src/consistentDependencies.ts +41 -17
  87. package/src/consistentVersions.ts +141 -0
  88. package/src/fileContents.ts +44 -37
  89. package/src/index.ts +13 -9
  90. package/src/mustSatisfyPeerDependencies.ts +744 -0
  91. package/src/nestedWorkspaces.ts +60 -0
  92. package/src/packageEntry.ts +72 -28
  93. package/src/packageOrder.ts +17 -13
  94. package/src/packageScript.ts +15 -19
  95. package/src/public/util.ts +1 -0
  96. package/src/requireDependency.ts +71 -0
  97. package/src/standardTsconfig.ts +51 -27
  98. package/src/util/checkAlpha.ts +9 -6
  99. package/src/util/makeDirectory.ts +24 -0
  100. package/src/util/makeRule.ts +29 -0
  101. package/src/util/packageDependencyGraphService.ts +114 -0
  102. package/tsconfig.json +10 -2
  103. package/lib/__tests__/alphabeticalScripts.spec.d.ts.map +0 -1
  104. package/lib/__tests__/alphabeticalScripts.spec.js +0 -61
  105. package/lib/__tests__/alphabeticalScripts.spec.js.map +0 -1
  106. package/lib/__tests__/consistentDependencies.spec.d.ts.map +0 -1
  107. package/lib/__tests__/consistentDependencies.spec.js +0 -107
  108. package/lib/__tests__/consistentDependencies.spec.js.map +0 -1
  109. package/lib/__tests__/packageEntry.spec.d.ts.map +0 -1
  110. package/lib/__tests__/packageEntry.spec.js +0 -99
  111. package/lib/__tests__/packageEntry.spec.js.map +0 -1
  112. package/lib/__tests__/packageOrder.spec.d.ts.map +0 -1
  113. package/lib/__tests__/packageOrder.spec.js +0 -115
  114. package/lib/__tests__/packageOrder.spec.js.map +0 -1
  115. package/lib/__tests__/packageScript.spec.d.ts.map +0 -1
  116. package/lib/__tests__/packageScript.spec.js +0 -172
  117. package/lib/__tests__/packageScript.spec.js.map +0 -1
  118. package/lib/__tests__/utils.d.ts +0 -9
  119. package/lib/__tests__/utils.d.ts.map +0 -1
  120. package/lib/__tests__/utils.js +0 -27
  121. package/lib/__tests__/utils.js.map +0 -1
  122. package/lib/alphabeticalDependencies.d.ts +0 -12
  123. package/lib/alphabeticalDependencies.d.ts.map +0 -1
  124. package/lib/alphabeticalDependencies.js +0 -21
  125. package/lib/alphabeticalDependencies.js.map +0 -1
  126. package/lib/alphabeticalScripts.d.ts +0 -12
  127. package/lib/alphabeticalScripts.d.ts.map +0 -1
  128. package/lib/alphabeticalScripts.js +0 -19
  129. package/lib/alphabeticalScripts.js.map +0 -1
  130. package/lib/bannedDependencies.d.ts +0 -15
  131. package/lib/bannedDependencies.d.ts.map +0 -1
  132. package/lib/bannedDependencies.js +0 -57
  133. package/lib/bannedDependencies.js.map +0 -1
  134. package/lib/consistentDependencies.d.ts +0 -10
  135. package/lib/consistentDependencies.d.ts.map +0 -1
  136. package/lib/consistentDependencies.js +0 -57
  137. package/lib/consistentDependencies.js.map +0 -1
  138. package/lib/fileContents.d.ts +0 -25
  139. package/lib/fileContents.d.ts.map +0 -1
  140. package/lib/fileContents.js +0 -77
  141. package/lib/fileContents.js.map +0 -1
  142. package/lib/index.d.ts +0 -16
  143. package/lib/index.d.ts.map +0 -1
  144. package/lib/index.js +0 -27
  145. package/lib/index.js.map +0 -1
  146. package/lib/packageEntry.d.ts +0 -16
  147. package/lib/packageEntry.d.ts.map +0 -1
  148. package/lib/packageEntry.js +0 -40
  149. package/lib/packageEntry.js.map +0 -1
  150. package/lib/packageOrder.d.ts +0 -12
  151. package/lib/packageOrder.d.ts.map +0 -1
  152. package/lib/packageOrder.js +0 -103
  153. package/lib/packageOrder.js.map +0 -1
  154. package/lib/packageScript.d.ts +0 -25
  155. package/lib/packageScript.d.ts.map +0 -1
  156. package/lib/packageScript.js +0 -89
  157. package/lib/packageScript.js.map +0 -1
  158. package/lib/standardTsconfig.d.ts +0 -33
  159. package/lib/standardTsconfig.d.ts.map +0 -1
  160. package/lib/standardTsconfig.js +0 -98
  161. package/lib/standardTsconfig.js.map +0 -1
  162. package/lib/util/checkAlpha.d.ts.map +0 -1
  163. package/lib/util/checkAlpha.js +0 -47
  164. package/lib/util/checkAlpha.js.map +0 -1
  165. package/tsconfig.tsbuildinfo +0 -2484
  166. /package/{lib → build/types}/__tests__/alphabeticalScripts.spec.d.ts +0 -0
  167. /package/{lib → build/types}/__tests__/consistentDependencies.spec.d.ts +0 -0
  168. /package/{lib → build/types}/__tests__/packageEntry.spec.d.ts +0 -0
  169. /package/{lib → build/types}/__tests__/packageOrder.spec.d.ts +0 -0
  170. /package/{lib → build/types}/__tests__/packageScript.spec.d.ts +0 -0
  171. /package/{jest.config.js → jest.config.cjs} +0 -0
@@ -4,6 +4,7 @@
4
4
  * Licensed under the MIT license. See LICENSE file in the project root for details.
5
5
  *
6
6
  */
7
- import { Context } from "@monorepolint/core";
7
+ import { Context } from "@monorepolint/config";
8
8
  export declare function checkAlpha(context: Context, block: "dependencies" | "devDependencies" | "peerDependencies" | "scripts"): void;
9
+ export declare function createIncorrectOrderErrorMessage(block: string, packageName: string): string;
9
10
  //# sourceMappingURL=checkAlpha.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"checkAlpha.d.ts","sourceRoot":"","sources":["../../../src/util/checkAlpha.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AAG/C,wBAAgB,UAAU,CACxB,OAAO,EAAE,OAAO,EAChB,KAAK,EAAE,cAAc,GAAG,iBAAiB,GAAG,kBAAkB,GAAG,SAAS,QAgC3E;AAYD,wBAAgB,gCAAgC,CAAC,KAAK,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,UAElF"}
@@ -0,0 +1,8 @@
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 declare function makeDirectoryRecursively(directoryPath: string): void;
8
+ //# sourceMappingURL=makeDirectory.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"makeDirectory.d.ts","sourceRoot":"","sources":["../../../src/util/makeDirectory.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAKH,wBAAgB,wBAAwB,CAAC,aAAa,EAAE,MAAM,QAa7D"}
@@ -0,0 +1,12 @@
1
+ import { Context, RuleEntry, RuleModule } from "@monorepolint/config";
2
+ export declare function makeRule<X>({ name, check, validateOptions, printStats, }: {
3
+ name: string;
4
+ check: (context: Context, options: X, extra: {
5
+ id: string;
6
+ }) => Promise<unknown> | unknown;
7
+ printStats?: () => void;
8
+ validateOptions: (options: unknown) => asserts options is X;
9
+ }): RuleFunction<X>;
10
+ type RuleFunction<T> = (ruleEntry: RuleEntry<T>) => RuleModule<T>;
11
+ export {};
12
+ //# sourceMappingURL=makeRule.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"makeRule.d.ts","sourceRoot":"","sources":["../../../src/util/makeRule.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAGtE,wBAAgB,QAAQ,CAAC,CAAC,EAAE,EAC1B,IAAI,EACJ,KAAK,EACL,eAAe,EACf,UAAU,GACX,EAAE;IACD,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,CAAC,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,CAAC,EAAE,KAAK,EAAE;QAAE,EAAE,EAAE,MAAM,CAAA;KAAE,KAAK,OAAO,CAAC,OAAO,CAAC,GAAG,OAAO,CAAC;IAC3F,UAAU,CAAC,EAAE,MAAM,IAAI,CAAC;IACxB,eAAe,EAAE,CAAC,OAAO,EAAE,OAAO,KAAK,OAAO,CAAC,OAAO,IAAI,CAAC,CAAC;CAC7D,GAAG,YAAY,CAAC,CAAC,CAAC,CAalB;AAED,KAAK,YAAY,CAAC,CAAC,IAAI,CAAC,SAAS,EAAE,SAAS,CAAC,CAAC,CAAC,KAAK,UAAU,CAAC,CAAC,CAAC,CAAC"}
@@ -0,0 +1,37 @@
1
+ /**
2
+ * @license Copyright 2019 Palantir Technologies, Inc. All rights reserved.
3
+ */
4
+ import { Host, PackageJson } from "@monorepolint/utils";
5
+ /** Interface for a node in a package dependency graph. */
6
+ export interface IPackageDependencyGraphNode {
7
+ packageJson: PackageJson;
8
+ dependencies: Map<string, IPackageDependencyGraphNode>;
9
+ paths: {
10
+ packageJsonPath: string;
11
+ rootDirectory: string;
12
+ };
13
+ }
14
+ /** Service abstraction for constructing and traversing package dependency graphs. */
15
+ export interface IPackageDependencyGraphService {
16
+ /** Construct a graph of package dependencies. */
17
+ buildDependencyGraph(packageJsonPath: string, host: Host, maxDepth?: number): IPackageDependencyGraphNode;
18
+ /** Traverse a package dependency graph. */
19
+ traverse(root: IPackageDependencyGraphNode, opts?: {
20
+ /** Traverse each unique path to a given package (potentially slow). */
21
+ traverseAllPaths?: boolean;
22
+ }): IterableIterator<IPackageDependencyGraphNode & {
23
+ importPath: IPackageDependencyGraphNode[];
24
+ }>;
25
+ }
26
+ /** Default implementation of the package dependency graph service. */
27
+ export declare class PackageDependencyGraphService implements IPackageDependencyGraphService {
28
+ /** Construct a graph of package dependencies and return the root node. */
29
+ buildDependencyGraph(startPackageJsonPath: string, host: Host, maxDepth?: number): IPackageDependencyGraphNode;
30
+ /** Traverse a package dependency graph with an iterator. */
31
+ traverse(root: IPackageDependencyGraphNode, opts?: {
32
+ traverseAllPaths: boolean;
33
+ }): IterableIterator<IPackageDependencyGraphNode & {
34
+ importPath: IPackageDependencyGraphNode[];
35
+ }>;
36
+ }
37
+ //# sourceMappingURL=packageDependencyGraphService.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"packageDependencyGraphService.d.ts","sourceRoot":"","sources":["../../../src/util/packageDependencyGraphService.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,IAAI,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAIxD,0DAA0D;AAC1D,MAAM,WAAW,2BAA2B;IAC1C,WAAW,EAAE,WAAW,CAAC;IACzB,YAAY,EAAE,GAAG,CAAC,MAAM,EAAE,2BAA2B,CAAC,CAAC;IACvD,KAAK,EAAE;QACL,eAAe,EAAE,MAAM,CAAC;QACxB,aAAa,EAAE,MAAM,CAAC;KACvB,CAAC;CACH;AAED,qFAAqF;AACrF,MAAM,WAAW,8BAA8B;IAC7C,iDAAiD;IACjD,oBAAoB,CAAC,eAAe,EAAE,MAAM,EAAE,IAAI,EAAE,IAAI,EAAE,QAAQ,CAAC,EAAE,MAAM,GAAG,2BAA2B,CAAC;IAE1G,2CAA2C;IAC3C,QAAQ,CACN,IAAI,EAAE,2BAA2B,EACjC,IAAI,CAAC,EAAE;QACL,uEAAuE;QACvE,gBAAgB,CAAC,EAAE,OAAO,CAAC;KAC5B,GACA,gBAAgB,CAAC,2BAA2B,GAAG;QAAE,UAAU,EAAE,2BAA2B,EAAE,CAAA;KAAE,CAAC,CAAC;CAClG;AAED,sEAAsE;AACtE,qBAAa,6BAA8B,YAAW,8BAA8B;IAClF,0EAA0E;IACnE,oBAAoB,CACzB,oBAAoB,EAAE,MAAM,EAC5B,IAAI,EAAE,IAAI,EACV,QAAQ,CAAC,EAAE,MAAM,GAChB,2BAA2B;IAuC9B,4DAA4D;IACpD,QAAQ,CACd,IAAI,EAAE,2BAA2B,EACjC,IAAI;;KAA8B,GACjC,gBAAgB,CAAC,2BAA2B,GAAG;QAAE,UAAU,EAAE,2BAA2B,EAAE,CAAA;KAAE,CAAC;CA8BjG"}
package/package.json CHANGED
@@ -1,38 +1,63 @@
1
1
  {
2
2
  "name": "@monorepolint/rules",
3
- "version": "0.5.0-alpha.12+7cf8550",
3
+ "version": "0.5.0-alpha.125+a94c83e",
4
4
  "author": "Eric L Anderson (https://github.com/ericanderson)",
5
5
  "contributors": [
6
6
  "Mac Lockard (https://github.com/maclockard)"
7
7
  ],
8
8
  "url": "https://github.com/monorepolint/monorepolint",
9
9
  "license": "MIT",
10
- "main": "lib/index.js",
11
- "typings": "lib/index.d.ts",
10
+ "type": "module",
11
+ "exports": {
12
+ ".": {
13
+ "types": "./build/types/index.d.ts",
14
+ "import": "./build/js/index.js"
15
+ },
16
+ "./*": {
17
+ "types": "./build/types/public/*.d.ts",
18
+ "import": "./build/js/public/*.js"
19
+ }
20
+ },
21
+ "engines": {
22
+ "node": ">=18"
23
+ },
12
24
  "scripts": {
13
- "clean": "rm -rf build lib node_modules *.tgz",
14
- "compile:typescript": "../../node_modules/.bin/tsc",
15
- "jest": "../../node_modules/.bin/jest --config ../../jest.config.js",
16
- "jest:watch": "../../node_modules/.bin/jest --config ../../jest.config.js --watch",
17
- "lint:typescript": "../../node_modules/.bin/tslint --config ../../tslint.json --project .",
18
- "test": "../../node_modules/.bin/jest --colors --passWithNoTests",
19
- "test:watch": "../../node_modules/.bin/jest --colors --passWithNoTests --watch"
25
+ "clean": "rm -rf build dist lib node_modules *.tgz tsconfig.tsbuildinfo",
26
+ "compile-typescript": "tsc --build",
27
+ "lint": "eslint .",
28
+ "test": "NODE_OPTIONS=--experimental-vm-modules jest --colors --passWithNoTests",
29
+ "test:watch": "NODE_OPTIONS=--experimental-vm-modules jest --colors --passWithNoTests --watch",
30
+ "transpile-typescript": "tsup --config ../../tsup.config.cjs"
20
31
  },
21
32
  "dependencies": {
22
- "@monorepolint/core": "^0.5.0-alpha.12+7cf8550",
23
- "@monorepolint/utils": "^0.5.0-alpha.12+7cf8550",
24
- "jest-diff": "^24.9.0",
25
- "minimatch": "^3.0.4",
26
- "runtypes": "^4.0.0"
33
+ "@monorepolint/config": "^0.5.0-alpha.125+a94c83e",
34
+ "@monorepolint/core": "^0.5.0-alpha.125+a94c83e",
35
+ "@monorepolint/utils": "^0.5.0-alpha.125+a94c83e",
36
+ "globby": "^14.0.0",
37
+ "jest-diff": "^29.7.0",
38
+ "resolve-package-path": "^4.0.3",
39
+ "runtypes": "^6.7.0",
40
+ "semver": "^7.5.4",
41
+ "tslib": "^2.6.2"
27
42
  },
28
43
  "devDependencies": {
29
- "@types/jest-diff": "^20.0.0",
30
- "@types/minimatch": "^3.0.3",
31
- "@types/tmp": "^0.1.0",
32
- "tmp": "^0.1.0"
44
+ "@jest/globals": "^29.7.0",
45
+ "@types/jest": "^29.5.10",
46
+ "@types/semver": "^7.5.6",
47
+ "@types/tmp": "^0.2.6",
48
+ "@typescript-eslint/eslint-plugin": "^6.13.1",
49
+ "@typescript-eslint/parser": "^6.13.1",
50
+ "eslint": "^8.54.0",
51
+ "jest": "^29.7.0",
52
+ "prettier": "^3.1.0",
53
+ "tmp": "^0.2.1",
54
+ "ts-jest": "^29.1.1",
55
+ "tslib": "^2.6.2",
56
+ "tsup": "^8.0.1",
57
+ "typescript": "^5.3.2"
33
58
  },
34
59
  "publishConfig": {
35
60
  "access": "public"
36
61
  },
37
- "gitHead": "7cf85507b1b968a26b8e501bec25aefc12558c6e"
62
+ "gitHead": "a94c83edd6800fbd70dce53643b251fa6b769fd8"
38
63
  }
@@ -6,15 +6,14 @@
6
6
  */
7
7
 
8
8
  // tslint:disable:no-console
9
- import { createMockFiles, jsonToString } from "./utils";
10
-
11
- // done first since this also mocks 'fs'
12
- const mockFiles: Map<string, string> = createMockFiles();
13
-
14
- import { Failure, PackageContext } from "@monorepolint/core";
15
- import { alphabeticalScripts } from "../alphabeticalScripts";
9
+ import { describe, expect, it, beforeEach, jest } from "@jest/globals";
10
+ import { AddErrorSpy, createTestingWorkspace, HOST_FACTORIES, jsonToString, TestingWorkspace } from "./utils.js";
11
+ import { Context, Failure } from "@monorepolint/config";
12
+ import { alphabeticalScripts } from "../alphabeticalScripts.js";
13
+ import { createIncorrectOrderErrorMessage } from "../util/checkAlpha.js";
16
14
 
17
15
  const PACKAGE_SCRIPTS_SORTED = jsonToString({
16
+ name: "foo-lib",
18
17
  scripts: {
19
18
  a: "a-",
20
19
  b: "b-",
@@ -23,6 +22,7 @@ const PACKAGE_SCRIPTS_SORTED = jsonToString({
23
22
  });
24
23
 
25
24
  const PACKAGE_SCRIPTS_UNSORTED = jsonToString({
25
+ name: "foo-lib",
26
26
  scripts: {
27
27
  c: "c-",
28
28
  a: "a-",
@@ -30,43 +30,45 @@ const PACKAGE_SCRIPTS_UNSORTED = jsonToString({
30
30
  },
31
31
  });
32
32
 
33
- describe("alphabeticalScripts", () => {
34
- afterEach(() => {
35
- mockFiles.clear();
36
- });
37
-
33
+ describe.each(HOST_FACTORIES)("alphabeticalScripts ($name)", (hostFactory) => {
38
34
  describe("fix: true", () => {
39
- const context = new PackageContext(".", {
40
- rules: [],
41
- fix: true,
42
- verbose: false,
43
- silent: true,
44
- });
45
- const spy = jest.spyOn(context, "addError");
46
-
47
- afterEach(() => {
48
- spy.mockClear();
35
+ let workspace: TestingWorkspace;
36
+ let spy: AddErrorSpy;
37
+ let context: Context;
38
+
39
+ beforeEach(async () => {
40
+ workspace = await createTestingWorkspace({
41
+ fixFlag: true,
42
+ host: hostFactory.make(),
43
+ });
44
+ context = workspace.context; // minimizing delta
45
+
46
+ spy = jest.spyOn(workspace.context, "addError");
49
47
  });
50
48
 
51
49
  it("fixes unsorted scripts", () => {
52
- mockFiles.set("package.json", PACKAGE_SCRIPTS_UNSORTED);
50
+ workspace.writeFile("package.json", PACKAGE_SCRIPTS_UNSORTED);
53
51
 
54
- alphabeticalScripts.check(context, undefined);
52
+ alphabeticalScripts({}).check(context);
55
53
 
56
54
  expect(spy).toHaveBeenCalledTimes(1);
57
55
 
58
56
  const failure: Failure = spy.mock.calls[0][0];
59
- expect(failure.file).toBe("package.json");
60
- expect(failure.fixer).not.toBeUndefined();
61
- expect(failure.message).toBe("Incorrect order of scripts in package.json");
62
-
63
- expect(mockFiles.get("package.json")).toEqual(PACKAGE_SCRIPTS_SORTED);
57
+ expect(failure).toMatchObject(
58
+ workspace.failureMatcher({
59
+ file: "package.json",
60
+ hasFixer: true,
61
+ message: createIncorrectOrderErrorMessage("scripts", "foo-lib"),
62
+ })
63
+ );
64
+
65
+ expect(workspace.readFile("package.json")).toEqual(PACKAGE_SCRIPTS_SORTED);
64
66
  });
65
67
 
66
68
  it("does nothing if already sorted", () => {
67
- mockFiles.set("package.json", PACKAGE_SCRIPTS_SORTED);
69
+ workspace.writeFile("package.json", PACKAGE_SCRIPTS_SORTED);
68
70
 
69
- alphabeticalScripts.check(context, undefined);
71
+ alphabeticalScripts({}).check(context);
70
72
 
71
73
  expect(spy).toHaveBeenCalledTimes(0);
72
74
  });
@@ -0,0 +1,189 @@
1
+ /*!
2
+ * Copyright 2020 Palantir Technologies, Inc.
3
+ *
4
+ * Licensed under the MIT license. See LICENSE file in the project root for details.
5
+ *
6
+ */
7
+ import { describe, expect, it, beforeEach, jest, afterEach } from "@jest/globals";
8
+ import { WorkspaceContextImpl } from "@monorepolint/core";
9
+ import { SimpleHost } from "@monorepolint/utils";
10
+ import { writeFileSync } from "fs";
11
+ import * as path from "path";
12
+ import * as tmp from "tmp";
13
+ import { bannedDependencies, Options } from "../bannedDependencies.js";
14
+ import { makeDirectoryRecursively } from "../util/makeDirectory.js";
15
+ import { jsonToString } from "./utils.js";
16
+ const EMPTY_PACKAGE = jsonToString({});
17
+
18
+ describe("bannedDependencies", () => {
19
+ tmp.setGracefulCleanup();
20
+
21
+ let cleanupJobs: Array<() => void> = [];
22
+ let cwd: string | undefined;
23
+
24
+ beforeEach(() => {
25
+ const dir = tmp.dirSync({ unsafeCleanup: true });
26
+ cleanupJobs.push(() => dir.removeCallback());
27
+ cwd = dir.name;
28
+
29
+ const spy = jest.spyOn(process, "cwd");
30
+ spy.mockReturnValue(cwd);
31
+ });
32
+
33
+ afterEach(() => {
34
+ for (const cleanupJob of cleanupJobs) {
35
+ cleanupJob();
36
+ }
37
+ cleanupJobs = [];
38
+ });
39
+
40
+ function makeWorkspace() {
41
+ const workspaceContext = new WorkspaceContextImpl(
42
+ cwd!,
43
+ {
44
+ rules: [],
45
+ fix: false,
46
+ verbose: false,
47
+ silent: true,
48
+ },
49
+ new SimpleHost()
50
+ );
51
+
52
+ function checkAndSpy(options: Options) {
53
+ const addErrorSpy = jest.spyOn(workspaceContext, "addError");
54
+ bannedDependencies({ options }).check(workspaceContext);
55
+ return { addErrorSpy };
56
+ }
57
+
58
+ function addFile(filePath: string, content: string) {
59
+ const dirPath = path.resolve(cwd!, path.dirname(filePath));
60
+ const resolvedFilePath = path.resolve(cwd!, filePath);
61
+
62
+ makeDirectoryRecursively(dirPath);
63
+ writeFileSync(resolvedFilePath, content);
64
+ return resolvedFilePath;
65
+ }
66
+
67
+ return { addFile, workspaceContext, checkAndSpy };
68
+ }
69
+
70
+ it("Flags banned dependencies correctly", async () => {
71
+ const { addFile, checkAndSpy } = makeWorkspace();
72
+ const rootPackageJson = jsonToString({
73
+ dependencies: {
74
+ aaa: "0.0.1",
75
+ ccc: "0.0.1",
76
+ },
77
+ });
78
+ addFile("./package.json", rootPackageJson);
79
+
80
+ const { addErrorSpy: addErrorSpy1 } = checkAndSpy({ bannedDependencies: ["ccc"] });
81
+ expect(addErrorSpy1).toHaveBeenCalledTimes(1);
82
+ addErrorSpy1.mockReset();
83
+
84
+ const { addErrorSpy: addErrorSpy2 } = checkAndSpy({ bannedDependencies: ["ddd"] });
85
+ expect(addErrorSpy2).toHaveBeenCalledTimes(0);
86
+ addErrorSpy2.mockReset();
87
+
88
+ const { addErrorSpy: addErrorSpy3 } = checkAndSpy({ bannedDependencies: ["ccc", "ddd"] });
89
+ expect(addErrorSpy3).toHaveBeenCalledTimes(1);
90
+ addErrorSpy3.mockReset();
91
+ });
92
+
93
+ it("Flags banned dependencies correctly w legacy globs", async () => {
94
+ const { addFile, checkAndSpy } = makeWorkspace();
95
+ const rootPackageJson = jsonToString({
96
+ dependencies: {
97
+ aaa: "0.0.1",
98
+ ccc: "0.0.1",
99
+ },
100
+ });
101
+ addFile("./package.json", rootPackageJson);
102
+
103
+ const { addErrorSpy: addErrorSpy1 } = checkAndSpy({ bannedDependencies: ["c*c"] });
104
+ expect(addErrorSpy1).toHaveBeenCalledTimes(1);
105
+ addErrorSpy1.mockReset();
106
+
107
+ const { addErrorSpy: addErrorSpy2 } = checkAndSpy({ bannedDependencies: ["d*d"] });
108
+ expect(addErrorSpy2).toHaveBeenCalledTimes(0);
109
+ addErrorSpy2.mockReset();
110
+
111
+ const { addErrorSpy: addErrorSpy3 } = checkAndSpy({ bannedDependencies: ["c*c", "d*d"] });
112
+ expect(addErrorSpy3).toHaveBeenCalledTimes(1);
113
+ addErrorSpy3.mockReset();
114
+ });
115
+
116
+ it("Flags banned dependencies correctly w new globs", async () => {
117
+ const { addFile, checkAndSpy } = makeWorkspace();
118
+ const rootPackageJson = jsonToString({
119
+ dependencies: {
120
+ aaa: "0.0.1",
121
+ ccc: "0.0.1",
122
+ },
123
+ });
124
+ addFile("./package.json", rootPackageJson);
125
+
126
+ const { addErrorSpy: addErrorSpy1 } = checkAndSpy({ bannedDependencies: { glob: ["c*c"] } });
127
+ expect(addErrorSpy1).toHaveBeenCalledTimes(1);
128
+ addErrorSpy1.mockReset();
129
+
130
+ const { addErrorSpy: addErrorSpy2 } = checkAndSpy({ bannedDependencies: { glob: ["d*d"] } });
131
+ expect(addErrorSpy2).toHaveBeenCalledTimes(0);
132
+ addErrorSpy2.mockReset();
133
+
134
+ const { addErrorSpy: addErrorSpy3 } = checkAndSpy({ bannedDependencies: { glob: ["c*c", "d*d"] } });
135
+ expect(addErrorSpy3).toHaveBeenCalledTimes(1);
136
+ addErrorSpy3.mockReset();
137
+ });
138
+
139
+ it("Flags banned dependencies correctly w exact", async () => {
140
+ const { addFile, checkAndSpy } = makeWorkspace();
141
+ const rootPackageJson = jsonToString({
142
+ dependencies: {
143
+ aaa: "0.0.1",
144
+ ccc: "0.0.1",
145
+ },
146
+ });
147
+ addFile("./package.json", rootPackageJson);
148
+
149
+ const { addErrorSpy: addErrorSpy1 } = checkAndSpy({ bannedDependencies: { exact: ["ccc"] } });
150
+ expect(addErrorSpy1).toHaveBeenCalledTimes(1);
151
+ addErrorSpy1.mockReset();
152
+
153
+ const { addErrorSpy: addErrorSpy2 } = checkAndSpy({ bannedDependencies: { exact: ["ddd"] } });
154
+ expect(addErrorSpy2).toHaveBeenCalledTimes(0);
155
+ addErrorSpy2.mockReset();
156
+
157
+ const { addErrorSpy: addErrorSpy3 } = checkAndSpy({ bannedDependencies: { exact: ["ccc", "ddd"] } });
158
+ expect(addErrorSpy3).toHaveBeenCalledTimes(1);
159
+ addErrorSpy3.mockReset();
160
+ });
161
+
162
+ it("Flags banned transitives correctly", async () => {
163
+ const { addFile, checkAndSpy } = makeWorkspace();
164
+ const rootPackageJson = jsonToString({
165
+ dependencies: {
166
+ aaa: "0.0.1",
167
+ },
168
+ });
169
+ addFile("./package.json", rootPackageJson);
170
+
171
+ const aaaPackageJson = jsonToString({
172
+ dependencies: {
173
+ bbb: "0.0.1",
174
+ ccc: "0.0.1",
175
+ },
176
+ });
177
+ addFile("./node_modules/aaa/package.json", aaaPackageJson);
178
+ const bbbPackageJson = jsonToString({
179
+ dependencies: {
180
+ ddd: "0.0.1",
181
+ },
182
+ });
183
+ addFile("./node_modules/aaa/node_modules/bbb/package.json", bbbPackageJson);
184
+ addFile("./node_modules/aaa/node_modules/bbb/node_modules/ddd/package.json", EMPTY_PACKAGE);
185
+ addFile("./node_modules/aaa/node_modules/ccc/package.json", EMPTY_PACKAGE);
186
+
187
+ expect(checkAndSpy({ bannedTransitiveDependencies: ["ccc", "ddd"] }).addErrorSpy).toHaveBeenCalledTimes(2);
188
+ });
189
+ });
@@ -4,12 +4,15 @@
4
4
  * Licensed under the MIT license. See LICENSE file in the project root for details.
5
5
  *
6
6
  */
7
- import { WorkspaceContext } from "@monorepolint/core";
8
- import { existsSync, mkdirSync, readFileSync, writeFileSync } from "fs";
7
+ import { WorkspaceContextImpl } from "@monorepolint/core";
8
+ import { SimpleHost } from "@monorepolint/utils";
9
+ import { readFileSync, writeFileSync } from "fs";
9
10
  import * as path from "path";
10
11
  import * as tmp from "tmp";
11
- import { consistentDependencies } from "../consistentDependencies";
12
- import { jsonToString } from "./utils";
12
+ import { consistentDependencies, Options } from "../consistentDependencies.js";
13
+ import { makeDirectoryRecursively } from "../util/makeDirectory.js";
14
+ import { jsonToString } from "./utils.js";
15
+ import { describe, expect, it, afterEach, jest } from "@jest/globals";
13
16
 
14
17
  const PACKAGE_ROOT = jsonToString({
15
18
  workspaces: {
@@ -26,6 +29,12 @@ const PACKAGE_CHILD_WITH_STAR = jsonToString({
26
29
  },
27
30
  });
28
31
 
32
+ const PACKAGE_CHILD_WITH_LATEST = jsonToString({
33
+ dependencies: {
34
+ foo: "latest",
35
+ },
36
+ });
37
+
29
38
  const PACKAGE_CHILD_WITH_RIGHT_VERSION = jsonToString({
30
39
  dependencies: {
31
40
  foo: "5",
@@ -51,20 +60,24 @@ describe("consistentDependencies", () => {
51
60
  });
52
61
 
53
62
  function makeWorkspace({ fix }: { fix: boolean }) {
54
- const dir: tmp.DirResult = tmp.dirSync();
63
+ const dir: tmp.DirResult = tmp.dirSync({ unsafeCleanup: true });
55
64
  cleanupJobs.push(() => dir.removeCallback());
56
65
 
57
- const workspaceContext = new WorkspaceContext(dir.name, {
58
- rules: [],
59
- fix,
60
- verbose: false,
61
- silent: true,
62
- });
63
-
64
- function checkAndSpy(q: string) {
66
+ const workspaceContext = new WorkspaceContextImpl(
67
+ dir.name,
68
+ {
69
+ rules: [],
70
+ fix,
71
+ verbose: false,
72
+ silent: true,
73
+ },
74
+ new SimpleHost()
75
+ );
76
+
77
+ function checkAndSpy(q: string, opts?: Options) {
65
78
  const context = workspaceContext.createChildContext(path.resolve(dir.name, q));
66
79
  const addErrorSpy = jest.spyOn(context, "addError");
67
- consistentDependencies.check(context, undefined);
80
+ consistentDependencies({ options: opts }).check(context);
68
81
  return { context, addErrorSpy };
69
82
  }
70
83
 
@@ -72,17 +85,7 @@ describe("consistentDependencies", () => {
72
85
  const dirPath = path.resolve(dir.name, path.dirname(filePath));
73
86
  const resolvedFilePath = path.resolve(dir.name, filePath);
74
87
 
75
- // node < 10 doesn't support mkdirSync w/ recursive: true
76
- // so we manually do it instead
77
- const dirSegments = dirPath.split(path.sep);
78
- for (let i = 2; i <= dirSegments.length; i++) {
79
- // we skip the empty segment
80
- const curDirPath = dirSegments.slice(0, i).join(path.sep);
81
- if (!existsSync(curDirPath)) {
82
- mkdirSync(curDirPath);
83
- }
84
- }
85
-
88
+ makeDirectoryRecursively(dirPath);
86
89
  writeFileSync(resolvedFilePath, content);
87
90
  }
88
91
 
@@ -97,14 +100,18 @@ describe("consistentDependencies", () => {
97
100
  const { addFile, workspaceContext, checkAndSpy } = makeWorkspace({ fix: false });
98
101
  addFile("./package.json", PACKAGE_ROOT);
99
102
  addFile("./packages/star/package.json", PACKAGE_CHILD_WITH_STAR);
103
+ addFile("./packages/latest/package.json", PACKAGE_CHILD_WITH_LATEST);
100
104
  addFile("./packages/right/package.json", PACKAGE_CHILD_WITH_RIGHT_VERSION);
101
105
  addFile("./packages/wrong/package.json", PACKAGE_CHILD_WITH_WRONG_VERSION);
102
106
 
103
- consistentDependencies.check(workspaceContext, undefined);
107
+ consistentDependencies({}).check(workspaceContext);
104
108
 
105
109
  const star = checkAndSpy("./packages/star");
106
110
  expect(star.addErrorSpy).toHaveBeenCalledTimes(0);
107
111
 
112
+ const latest = checkAndSpy("./packages/latest");
113
+ expect(latest.addErrorSpy).toHaveBeenCalledTimes(0);
114
+
108
115
  const right = checkAndSpy("./packages/right");
109
116
  expect(right.addErrorSpy).toHaveBeenCalledTimes(0);
110
117
 
@@ -123,4 +130,13 @@ describe("consistentDependencies", () => {
123
130
  const contents = readFile("./packages/wrong/package.json");
124
131
  expect(contents).toEqual(PACKAGE_CHILD_WITH_RIGHT_VERSION);
125
132
  });
133
+
134
+ it("ignores ignored dependencies", () => {
135
+ const { addFile, checkAndSpy } = makeWorkspace({ fix: false });
136
+ addFile("./package.json", PACKAGE_ROOT);
137
+ addFile("./packages/wrong/package.json", PACKAGE_CHILD_WITH_WRONG_VERSION);
138
+
139
+ const ignored = checkAndSpy("./packages/wrong", { ignoredDependencies: ["foo"] });
140
+ expect(ignored.addErrorSpy).toHaveBeenCalledTimes(0);
141
+ });
126
142
  });