@monorepolint/rules 0.5.0-alpha.10 → 0.5.0-alpha.106

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 (156) 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 +110 -0
  4. package/.turbo/turbo-test.log +638 -0
  5. package/.turbo/turbo-transpile-typescript.log +14 -0
  6. package/build/js/index.js +1417 -0
  7. package/build/js/index.js.map +1 -0
  8. package/build/tsconfig.tsbuildinfo +1 -0
  9. package/{lib/__tests__/utils.d.ts → build/types/__tests__/alphabeticalScripts.spec.d.ts} +2 -2
  10. package/build/types/__tests__/alphabeticalScripts.spec.d.ts.map +1 -0
  11. package/build/types/__tests__/bannedDependencies.spec.d.ts +2 -0
  12. package/build/types/__tests__/bannedDependencies.spec.d.ts.map +1 -0
  13. package/build/types/__tests__/consistentDependencies.spec.d.ts.map +1 -0
  14. package/build/types/__tests__/consistentVersions.spec.d.ts +8 -0
  15. package/build/types/__tests__/consistentVersions.spec.d.ts.map +1 -0
  16. package/build/types/__tests__/fileContents.spec.d.ts +8 -0
  17. package/build/types/__tests__/fileContents.spec.d.ts.map +1 -0
  18. package/build/types/__tests__/mustSatisfyPeerDependencies.spec.d.ts +8 -0
  19. package/build/types/__tests__/mustSatisfyPeerDependencies.spec.d.ts.map +1 -0
  20. package/build/types/__tests__/nestedWorkspaces.spec.d.ts +2 -0
  21. package/build/types/__tests__/nestedWorkspaces.spec.d.ts.map +1 -0
  22. package/build/types/__tests__/packageEntry.spec.d.ts.map +1 -0
  23. package/build/types/__tests__/packageOrder.spec.d.ts.map +1 -0
  24. package/build/types/__tests__/packageScript.spec.d.ts.map +1 -0
  25. package/build/types/__tests__/requireDependency.spec.d.ts +2 -0
  26. package/build/types/__tests__/requireDependency.spec.d.ts.map +1 -0
  27. package/build/types/__tests__/utils.d.ts +81 -0
  28. package/build/types/__tests__/utils.d.ts.map +1 -0
  29. package/build/types/alphabeticalDependencies.d.ts +9 -0
  30. package/build/types/alphabeticalDependencies.d.ts.map +1 -0
  31. package/build/types/alphabeticalScripts.d.ts +9 -0
  32. package/build/types/alphabeticalScripts.d.ts.map +1 -0
  33. package/build/types/bannedDependencies.d.ts +66 -0
  34. package/build/types/bannedDependencies.d.ts.map +1 -0
  35. package/build/types/consistentDependencies.d.ts +18 -0
  36. package/build/types/consistentDependencies.d.ts.map +1 -0
  37. package/build/types/consistentVersions.d.ts +21 -0
  38. package/build/types/consistentVersions.d.ts.map +1 -0
  39. package/build/types/fileContents.d.ts +39 -0
  40. package/build/types/fileContents.d.ts.map +1 -0
  41. package/build/types/index.d.ts +20 -0
  42. package/build/types/index.d.ts.map +1 -0
  43. package/build/types/mustSatisfyPeerDependencies.d.ts +427 -0
  44. package/build/types/mustSatisfyPeerDependencies.d.ts.map +1 -0
  45. package/build/types/nestedWorkspaces.d.ts +10 -0
  46. package/build/types/nestedWorkspaces.d.ts.map +1 -0
  47. package/build/types/packageEntry.d.ts +54 -0
  48. package/build/types/packageEntry.d.ts.map +1 -0
  49. package/build/types/packageOrder.d.ts +13 -0
  50. package/build/types/packageOrder.d.ts.map +1 -0
  51. package/build/types/packageScript.d.ts +37 -0
  52. package/build/types/packageScript.d.ts.map +1 -0
  53. package/build/types/public/util.d.ts +2 -0
  54. package/build/types/public/util.d.ts.map +1 -0
  55. package/build/types/requireDependency.d.ts +35 -0
  56. package/build/types/requireDependency.d.ts.map +1 -0
  57. package/build/types/standardTsconfig.d.ts +53 -0
  58. package/build/types/standardTsconfig.d.ts.map +1 -0
  59. package/build/types/util/checkAlpha.d.ts +10 -0
  60. package/build/types/util/checkAlpha.d.ts.map +1 -0
  61. package/build/types/util/makeDirectory.d.ts +8 -0
  62. package/build/types/util/makeDirectory.d.ts.map +1 -0
  63. package/build/types/util/makeRule.d.ts +13 -0
  64. package/build/types/util/makeRule.d.ts.map +1 -0
  65. package/build/types/util/packageDependencyGraphService.d.ts +37 -0
  66. package/build/types/util/packageDependencyGraphService.d.ts.map +1 -0
  67. package/package.json +45 -20
  68. package/src/__tests__/alphabeticalScripts.spec.ts +76 -0
  69. package/src/__tests__/bannedDependencies.spec.ts +189 -0
  70. package/src/__tests__/consistentDependencies.spec.ts +42 -28
  71. package/src/__tests__/consistentVersions.spec.ts +224 -0
  72. package/src/__tests__/fileContents.spec.ts +79 -0
  73. package/src/__tests__/mustSatisfyPeerDependencies.spec.ts +1189 -0
  74. package/src/__tests__/nestedWorkspaces.spec.ts +153 -0
  75. package/src/__tests__/packageEntry.spec.ts +127 -49
  76. package/src/__tests__/packageOrder.spec.ts +68 -53
  77. package/src/__tests__/packageScript.spec.ts +124 -98
  78. package/src/__tests__/requireDependency.spec.ts +152 -0
  79. package/src/__tests__/utils.ts +115 -11
  80. package/src/alphabeticalDependencies.ts +6 -50
  81. package/src/alphabeticalScripts.ts +19 -0
  82. package/src/bannedDependencies.ts +134 -45
  83. package/src/consistentDependencies.ts +39 -16
  84. package/src/consistentVersions.ts +141 -0
  85. package/src/fileContents.ts +39 -35
  86. package/src/index.ts +13 -8
  87. package/src/mustSatisfyPeerDependencies.ts +744 -0
  88. package/src/nestedWorkspaces.ts +60 -0
  89. package/src/packageEntry.ts +71 -27
  90. package/src/packageOrder.ts +15 -12
  91. package/src/packageScript.ts +14 -18
  92. package/src/public/util.ts +1 -0
  93. package/src/requireDependency.ts +71 -0
  94. package/src/standardTsconfig.ts +49 -26
  95. package/src/util/checkAlpha.ts +59 -0
  96. package/src/util/makeDirectory.ts +24 -0
  97. package/src/util/makeRule.ts +29 -0
  98. package/src/util/packageDependencyGraphService.ts +114 -0
  99. package/tsconfig.json +10 -2
  100. package/lib/__tests__/consistentDependencies.spec.d.ts.map +0 -1
  101. package/lib/__tests__/consistentDependencies.spec.js +0 -108
  102. package/lib/__tests__/consistentDependencies.spec.js.map +0 -1
  103. package/lib/__tests__/packageEntry.spec.d.ts.map +0 -1
  104. package/lib/__tests__/packageEntry.spec.js +0 -99
  105. package/lib/__tests__/packageEntry.spec.js.map +0 -1
  106. package/lib/__tests__/packageOrder.spec.d.ts.map +0 -1
  107. package/lib/__tests__/packageOrder.spec.js +0 -115
  108. package/lib/__tests__/packageOrder.spec.js.map +0 -1
  109. package/lib/__tests__/packageScript.spec.d.ts.map +0 -1
  110. package/lib/__tests__/packageScript.spec.js +0 -172
  111. package/lib/__tests__/packageScript.spec.js.map +0 -1
  112. package/lib/__tests__/utils.d.ts.map +0 -1
  113. package/lib/__tests__/utils.js +0 -23
  114. package/lib/__tests__/utils.js.map +0 -1
  115. package/lib/alphabeticalDependencies.d.ts +0 -10
  116. package/lib/alphabeticalDependencies.d.ts.map +0 -1
  117. package/lib/alphabeticalDependencies.js +0 -56
  118. package/lib/alphabeticalDependencies.js.map +0 -1
  119. package/lib/bannedDependencies.d.ts +0 -15
  120. package/lib/bannedDependencies.d.ts.map +0 -1
  121. package/lib/bannedDependencies.js +0 -57
  122. package/lib/bannedDependencies.js.map +0 -1
  123. package/lib/consistentDependencies.d.ts +0 -10
  124. package/lib/consistentDependencies.d.ts.map +0 -1
  125. package/lib/consistentDependencies.js +0 -57
  126. package/lib/consistentDependencies.js.map +0 -1
  127. package/lib/fileContents.d.ts +0 -25
  128. package/lib/fileContents.d.ts.map +0 -1
  129. package/lib/fileContents.js +0 -77
  130. package/lib/fileContents.js.map +0 -1
  131. package/lib/index.d.ts +0 -15
  132. package/lib/index.d.ts.map +0 -1
  133. package/lib/index.js +0 -25
  134. package/lib/index.js.map +0 -1
  135. package/lib/packageEntry.d.ts +0 -16
  136. package/lib/packageEntry.d.ts.map +0 -1
  137. package/lib/packageEntry.js +0 -40
  138. package/lib/packageEntry.js.map +0 -1
  139. package/lib/packageOrder.d.ts +0 -12
  140. package/lib/packageOrder.d.ts.map +0 -1
  141. package/lib/packageOrder.js +0 -103
  142. package/lib/packageOrder.js.map +0 -1
  143. package/lib/packageScript.d.ts +0 -25
  144. package/lib/packageScript.d.ts.map +0 -1
  145. package/lib/packageScript.js +0 -89
  146. package/lib/packageScript.js.map +0 -1
  147. package/lib/standardTsconfig.d.ts +0 -33
  148. package/lib/standardTsconfig.d.ts.map +0 -1
  149. package/lib/standardTsconfig.js +0 -98
  150. package/lib/standardTsconfig.js.map +0 -1
  151. package/tsconfig.tsbuildinfo +0 -2439
  152. /package/{lib → build/types}/__tests__/consistentDependencies.spec.d.ts +0 -0
  153. /package/{lib → build/types}/__tests__/packageEntry.spec.d.ts +0 -0
  154. /package/{lib → build/types}/__tests__/packageOrder.spec.d.ts +0 -0
  155. /package/{lib → build/types}/__tests__/packageScript.spec.d.ts +0 -0
  156. /package/{jest.config.js → jest.config.cjs} +0 -0
@@ -0,0 +1,10 @@
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
+ import { Context } from "@monorepolint/config";
8
+ export declare function checkAlpha(context: Context, block: "dependencies" | "devDependencies" | "peerDependencies" | "scripts"): void;
9
+ export declare function createIncorrectOrderErrorMessage(block: string, packageName: string): string;
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,13 @@
1
+ import { Context, RuleEntry, RuleModule } from "@monorepolint/config";
2
+ import * as r from "runtypes";
3
+ export declare function makeRule<T extends r.Runtype<unknown>>({ name, check, optionsRuntype, printStats, }: {
4
+ name: string;
5
+ check: (context: Context, options: r.Static<T>, extra: {
6
+ id: string;
7
+ }) => Promise<unknown> | unknown;
8
+ optionsRuntype: T;
9
+ printStats?: () => void;
10
+ }): RuleFunction<T>;
11
+ type RuleFunction<T extends r.Runtype<any>> = (ruleEntry: RuleEntry<r.Static<T>>) => RuleModule<T>;
12
+ export {};
13
+ //# 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;AACtE,OAAO,KAAK,CAAC,MAAM,UAAU,CAAC;AAG9B,wBAAgB,QAAQ,CAAC,CAAC,SAAS,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE,EACrD,IAAI,EACJ,KAAK,EACL,cAAc,EACd,UAAU,GACX,EAAE;IACD,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,CAAC,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE;QAAE,EAAE,EAAE,MAAM,CAAA;KAAE,KAAK,OAAO,CAAC,OAAO,CAAC,GAAG,OAAO,CAAC;IACrG,cAAc,EAAE,CAAC,CAAC;IAClB,UAAU,CAAC,EAAE,MAAM,IAAI,CAAC;CACzB,GAAG,YAAY,CAAC,CAAC,CAAC,CAYlB;AAED,KAAK,YAAY,CAAC,CAAC,SAAS,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,SAAS,EAAE,SAAS,CAAC,CAAC,CAAC,MAAM,CAAC,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.10+b584a18",
3
+ "version": "0.5.0-alpha.106+c717193",
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": ">=16"
23
+ },
12
24
  "scripts": {
13
- "clean": "rm -rf build lib node_modules *.tgz",
14
- "compile:typescript": "../../node_modules/.bin/tsc",
15
- "jest:watch": "../../node_modules/.bin/jest --config ../../jest.config.js --watch",
16
- "jest": "../../node_modules/.bin/jest --config ../../jest.config.js",
17
- "lint:typescript": "../../node_modules/.bin/tslint --config ../../tslint.json --project .",
18
- "test:watch": "../../node_modules/.bin/jest --colors --passWithNoTests --watch",
19
- "test": "../../node_modules/.bin/jest --colors --passWithNoTests"
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.10+b584a18",
23
- "@monorepolint/utils": "^0.5.0-alpha.10+b584a18",
24
- "jest-diff": "^24.9.0",
25
- "minimatch": "^3.0.4",
26
- "runtypes": "^4.0.0"
33
+ "@monorepolint/config": "^0.5.0-alpha.106+c717193",
34
+ "@monorepolint/core": "^0.5.0-alpha.106+c717193",
35
+ "@monorepolint/utils": "^0.5.0-alpha.106+c717193",
36
+ "globby": "^13.1.2",
37
+ "jest-diff": "^29.3.1",
38
+ "resolve-package-path": "^4.0.3",
39
+ "runtypes": "^6.6.0",
40
+ "semver": "^7.3.8",
41
+ "tslib": "^2.5.0"
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.3.1",
45
+ "@types/jest": "^29.2.4",
46
+ "@types/semver": "^7.3.13",
47
+ "@types/tmp": "^0.2.3",
48
+ "@typescript-eslint/eslint-plugin": "^5.45.1",
49
+ "@typescript-eslint/parser": "^5.45.1",
50
+ "eslint": "^8.29.0",
51
+ "jest": "^29.3.1",
52
+ "prettier": "^2.8.3",
53
+ "tmp": "^0.2.1",
54
+ "ts-jest": "^29.0.5",
55
+ "tslib": "^2.5.0",
56
+ "tsup": "^6.5.0",
57
+ "typescript": "^4.9.5"
33
58
  },
34
59
  "publishConfig": {
35
60
  "access": "public"
36
61
  },
37
- "gitHead": "b584a18e553330f84b64afd3a658342cab6c7234"
62
+ "gitHead": "c71719369db87ef0173ef8bd2293ce20cf8f9722"
38
63
  }
@@ -0,0 +1,76 @@
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
+
8
+ // tslint:disable:no-console
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";
14
+
15
+ const PACKAGE_SCRIPTS_SORTED = jsonToString({
16
+ name: "foo-lib",
17
+ scripts: {
18
+ a: "a-",
19
+ b: "b-",
20
+ c: "c-",
21
+ },
22
+ });
23
+
24
+ const PACKAGE_SCRIPTS_UNSORTED = jsonToString({
25
+ name: "foo-lib",
26
+ scripts: {
27
+ c: "c-",
28
+ a: "a-",
29
+ b: "b-",
30
+ },
31
+ });
32
+
33
+ describe.each(HOST_FACTORIES)("alphabeticalScripts ($name)", (hostFactory) => {
34
+ describe("fix: true", () => {
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");
47
+ });
48
+
49
+ it("fixes unsorted scripts", () => {
50
+ workspace.writeFile("package.json", PACKAGE_SCRIPTS_UNSORTED);
51
+
52
+ alphabeticalScripts({}).check(context);
53
+
54
+ expect(spy).toHaveBeenCalledTimes(1);
55
+
56
+ const failure: Failure = spy.mock.calls[0][0];
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);
66
+ });
67
+
68
+ it("does nothing if already sorted", () => {
69
+ workspace.writeFile("package.json", PACKAGE_SCRIPTS_SORTED);
70
+
71
+ alphabeticalScripts({}).check(context);
72
+
73
+ expect(spy).toHaveBeenCalledTimes(0);
74
+ });
75
+ });
76
+ });
@@ -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,15 +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
-
13
- function jsonToString(obj: {}) {
14
- return JSON.stringify(obj, undefined, 2) + "\n";
15
- }
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";
16
16
 
17
17
  const PACKAGE_ROOT = jsonToString({
18
18
  workspaces: {
@@ -29,6 +29,12 @@ const PACKAGE_CHILD_WITH_STAR = jsonToString({
29
29
  },
30
30
  });
31
31
 
32
+ const PACKAGE_CHILD_WITH_LATEST = jsonToString({
33
+ dependencies: {
34
+ foo: "latest",
35
+ },
36
+ });
37
+
32
38
  const PACKAGE_CHILD_WITH_RIGHT_VERSION = jsonToString({
33
39
  dependencies: {
34
40
  foo: "5",
@@ -54,19 +60,24 @@ describe("consistentDependencies", () => {
54
60
  });
55
61
 
56
62
  function makeWorkspace({ fix }: { fix: boolean }) {
57
- const dir: tmp.DirResult = tmp.dirSync();
63
+ const dir: tmp.DirResult = tmp.dirSync({ unsafeCleanup: true });
58
64
  cleanupJobs.push(() => dir.removeCallback());
59
65
 
60
- const workspaceContext = new WorkspaceContext(dir.name, {
61
- rules: [],
62
- fix,
63
- verbose: false,
64
- });
65
-
66
- 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) {
67
78
  const context = workspaceContext.createChildContext(path.resolve(dir.name, q));
68
79
  const addErrorSpy = jest.spyOn(context, "addError");
69
- consistentDependencies.check(context, undefined);
80
+ consistentDependencies({ options: opts }).check(context);
70
81
  return { context, addErrorSpy };
71
82
  }
72
83
 
@@ -74,17 +85,7 @@ describe("consistentDependencies", () => {
74
85
  const dirPath = path.resolve(dir.name, path.dirname(filePath));
75
86
  const resolvedFilePath = path.resolve(dir.name, filePath);
76
87
 
77
- // node < 10 doesn't support mkdirSync w/ recursive: true
78
- // so we manually do it instead
79
- const dirSegments = dirPath.split(path.sep);
80
- for (let i = 2; i <= dirSegments.length; i++) {
81
- // we skip the empty segment
82
- const curDirPath = dirSegments.slice(0, i).join(path.sep);
83
- if (!existsSync(curDirPath)) {
84
- mkdirSync(curDirPath);
85
- }
86
- }
87
-
88
+ makeDirectoryRecursively(dirPath);
88
89
  writeFileSync(resolvedFilePath, content);
89
90
  }
90
91
 
@@ -99,14 +100,18 @@ describe("consistentDependencies", () => {
99
100
  const { addFile, workspaceContext, checkAndSpy } = makeWorkspace({ fix: false });
100
101
  addFile("./package.json", PACKAGE_ROOT);
101
102
  addFile("./packages/star/package.json", PACKAGE_CHILD_WITH_STAR);
103
+ addFile("./packages/latest/package.json", PACKAGE_CHILD_WITH_LATEST);
102
104
  addFile("./packages/right/package.json", PACKAGE_CHILD_WITH_RIGHT_VERSION);
103
105
  addFile("./packages/wrong/package.json", PACKAGE_CHILD_WITH_WRONG_VERSION);
104
106
 
105
- consistentDependencies.check(workspaceContext, undefined);
107
+ consistentDependencies({}).check(workspaceContext);
106
108
 
107
109
  const star = checkAndSpy("./packages/star");
108
110
  expect(star.addErrorSpy).toHaveBeenCalledTimes(0);
109
111
 
112
+ const latest = checkAndSpy("./packages/latest");
113
+ expect(latest.addErrorSpy).toHaveBeenCalledTimes(0);
114
+
110
115
  const right = checkAndSpy("./packages/right");
111
116
  expect(right.addErrorSpy).toHaveBeenCalledTimes(0);
112
117
 
@@ -125,4 +130,13 @@ describe("consistentDependencies", () => {
125
130
  const contents = readFile("./packages/wrong/package.json");
126
131
  expect(contents).toEqual(PACKAGE_CHILD_WITH_RIGHT_VERSION);
127
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
+ });
128
142
  });