@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.
- package/CHANGELOG.md +14 -0
- package/package.json +47 -25
- package/src/__tests__/alphabeticalScripts.spec.ts +7 -6
- package/src/__tests__/bannedDependencies.spec.ts +7 -9
- package/src/__tests__/consistentDependencies.spec.ts +8 -7
- package/src/__tests__/consistentVersions.spec.ts +7 -6
- package/src/__tests__/fileContents.spec.ts +45 -18
- package/src/__tests__/mustSatisfyPeerDependencies.spec.ts +41 -40
- package/src/__tests__/nestedWorkspaces.spec.ts +7 -6
- package/src/__tests__/packageEntry.spec.ts +44 -33
- package/src/__tests__/packageOrder.spec.ts +24 -15
- package/src/__tests__/packageScript.spec.ts +62 -44
- package/src/__tests__/requireDependency.spec.ts +10 -9
- package/src/__tests__/utils.ts +11 -6
- package/src/alphabeticalDependencies.ts +7 -9
- package/src/alphabeticalScripts.ts +7 -9
- package/src/bannedDependencies.ts +9 -10
- package/src/consistentDependencies.ts +9 -7
- package/src/consistentVersions.ts +6 -5
- package/src/fileContents.ts +17 -14
- package/src/index.ts +13 -13
- package/src/mustSatisfyPeerDependencies.ts +16 -11
- package/src/nestedWorkspaces.ts +10 -9
- package/src/packageEntry.ts +7 -6
- package/src/packageOrder.ts +12 -7
- package/src/packageScript.ts +12 -16
- package/src/public/util.ts +1 -0
- package/src/requireDependency.ts +9 -7
- package/src/standardTsconfig.ts +11 -9
- package/src/util/checkAlpha.ts +2 -2
- package/src/util/makeRule.ts +29 -0
- package/src/util/packageDependencyGraphService.ts +2 -2
- package/tsconfig.json +10 -2
- package/lib/__tests__/alphabeticalScripts.spec.d.ts +0 -8
- package/lib/__tests__/alphabeticalScripts.spec.d.ts.map +0 -1
- package/lib/__tests__/alphabeticalScripts.spec.js +0 -61
- package/lib/__tests__/alphabeticalScripts.spec.js.map +0 -1
- package/lib/__tests__/bannedDependencies.spec.d.ts +0 -2
- package/lib/__tests__/bannedDependencies.spec.d.ts.map +0 -1
- package/lib/__tests__/bannedDependencies.spec.js +0 -161
- package/lib/__tests__/bannedDependencies.spec.js.map +0 -1
- package/lib/__tests__/consistentDependencies.spec.d.ts +0 -2
- package/lib/__tests__/consistentDependencies.spec.d.ts.map +0 -1
- package/lib/__tests__/consistentDependencies.spec.js +0 -115
- package/lib/__tests__/consistentDependencies.spec.js.map +0 -1
- package/lib/__tests__/consistentVersions.spec.d.ts +0 -8
- package/lib/__tests__/consistentVersions.spec.d.ts.map +0 -1
- package/lib/__tests__/consistentVersions.spec.js +0 -183
- package/lib/__tests__/consistentVersions.spec.js.map +0 -1
- package/lib/__tests__/fileContents.spec.d.ts +0 -8
- package/lib/__tests__/fileContents.spec.d.ts.map +0 -1
- package/lib/__tests__/fileContents.spec.js +0 -59
- package/lib/__tests__/fileContents.spec.js.map +0 -1
- package/lib/__tests__/mustSatisfyPeerDependencies.spec.d.ts +0 -8
- package/lib/__tests__/mustSatisfyPeerDependencies.spec.d.ts.map +0 -1
- package/lib/__tests__/mustSatisfyPeerDependencies.spec.js +0 -1063
- package/lib/__tests__/mustSatisfyPeerDependencies.spec.js.map +0 -1
- package/lib/__tests__/nestedWorkspaces.spec.d.ts +0 -2
- package/lib/__tests__/nestedWorkspaces.spec.d.ts.map +0 -1
- package/lib/__tests__/nestedWorkspaces.spec.js +0 -124
- package/lib/__tests__/nestedWorkspaces.spec.js.map +0 -1
- package/lib/__tests__/packageEntry.spec.d.ts +0 -8
- package/lib/__tests__/packageEntry.spec.d.ts.map +0 -1
- package/lib/__tests__/packageEntry.spec.js +0 -144
- package/lib/__tests__/packageEntry.spec.js.map +0 -1
- package/lib/__tests__/packageOrder.spec.d.ts +0 -8
- package/lib/__tests__/packageOrder.spec.d.ts.map +0 -1
- package/lib/__tests__/packageOrder.spec.js +0 -116
- package/lib/__tests__/packageOrder.spec.js.map +0 -1
- package/lib/__tests__/packageScript.spec.d.ts +0 -8
- package/lib/__tests__/packageScript.spec.d.ts.map +0 -1
- package/lib/__tests__/packageScript.spec.js +0 -171
- package/lib/__tests__/packageScript.spec.js.map +0 -1
- package/lib/__tests__/requireDependency.spec.d.ts +0 -2
- package/lib/__tests__/requireDependency.spec.d.ts.map +0 -1
- package/lib/__tests__/requireDependency.spec.js +0 -123
- package/lib/__tests__/requireDependency.spec.js.map +0 -1
- package/lib/__tests__/utils.d.ts +0 -76
- package/lib/__tests__/utils.d.ts.map +0 -1
- package/lib/__tests__/utils.js +0 -83
- package/lib/__tests__/utils.js.map +0 -1
- package/lib/alphabeticalDependencies.d.ts +0 -12
- package/lib/alphabeticalDependencies.d.ts.map +0 -1
- package/lib/alphabeticalDependencies.js +0 -22
- package/lib/alphabeticalDependencies.js.map +0 -1
- package/lib/alphabeticalScripts.d.ts +0 -12
- package/lib/alphabeticalScripts.d.ts.map +0 -1
- package/lib/alphabeticalScripts.js +0 -20
- package/lib/alphabeticalScripts.js.map +0 -1
- package/lib/bannedDependencies.d.ts +0 -33
- package/lib/bannedDependencies.d.ts.map +0 -1
- package/lib/bannedDependencies.js +0 -131
- package/lib/bannedDependencies.js.map +0 -1
- package/lib/consistentDependencies.d.ts +0 -17
- package/lib/consistentDependencies.d.ts.map +0 -1
- package/lib/consistentDependencies.js +0 -75
- package/lib/consistentDependencies.js.map +0 -1
- package/lib/consistentVersions.d.ts +0 -14
- package/lib/consistentVersions.d.ts.map +0 -1
- package/lib/consistentVersions.js +0 -94
- package/lib/consistentVersions.js.map +0 -1
- package/lib/fileContents.d.ts +0 -25
- package/lib/fileContents.d.ts.map +0 -1
- package/lib/fileContents.js +0 -82
- package/lib/fileContents.js.map +0 -1
- package/lib/index.d.ts +0 -20
- package/lib/index.d.ts.map +0 -1
- package/lib/index.js +0 -36
- package/lib/index.js.map +0 -1
- package/lib/mustSatisfyPeerDependencies.d.ts +0 -240
- package/lib/mustSatisfyPeerDependencies.d.ts.map +0 -1
- package/lib/mustSatisfyPeerDependencies.js +0 -636
- package/lib/mustSatisfyPeerDependencies.js.map +0 -1
- package/lib/nestedWorkspaces.d.ts +0 -13
- package/lib/nestedWorkspaces.d.ts.map +0 -1
- package/lib/nestedWorkspaces.js +0 -50
- package/lib/nestedWorkspaces.js.map +0 -1
- package/lib/packageEntry.d.ts +0 -25
- package/lib/packageEntry.d.ts.map +0 -1
- package/lib/packageEntry.js +0 -75
- package/lib/packageEntry.js.map +0 -1
- package/lib/packageOrder.d.ts +0 -12
- package/lib/packageOrder.d.ts.map +0 -1
- package/lib/packageOrder.js +0 -103
- package/lib/packageOrder.js.map +0 -1
- package/lib/packageScript.d.ts +0 -25
- package/lib/packageScript.d.ts.map +0 -1
- package/lib/packageScript.js +0 -90
- package/lib/packageScript.js.map +0 -1
- package/lib/requireDependency.d.ts +0 -15
- package/lib/requireDependency.d.ts.map +0 -1
- package/lib/requireDependency.js +0 -65
- package/lib/requireDependency.js.map +0 -1
- package/lib/standardTsconfig.d.ts +0 -45
- package/lib/standardTsconfig.d.ts.map +0 -1
- package/lib/standardTsconfig.js +0 -116
- package/lib/standardTsconfig.js.map +0 -1
- package/lib/util/checkAlpha.d.ts +0 -10
- package/lib/util/checkAlpha.d.ts.map +0 -1
- package/lib/util/checkAlpha.js +0 -51
- package/lib/util/checkAlpha.js.map +0 -1
- package/lib/util/makeDirectory.d.ts +0 -8
- package/lib/util/makeDirectory.d.ts.map +0 -1
- package/lib/util/makeDirectory.js +0 -28
- package/lib/util/makeDirectory.js.map +0 -1
- package/lib/util/packageDependencyGraphService.d.ts +0 -37
- package/lib/util/packageDependencyGraphService.d.ts.map +0 -1
- package/lib/util/packageDependencyGraphService.js +0 -70
- package/lib/util/packageDependencyGraphService.js.map +0 -1
- package/tsconfig.tsbuildinfo +0 -1
- /package/{jest.config.js → jest.config.cjs} +0 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
# @monorepolint/rules
|
|
2
|
+
|
|
3
|
+
## 0.5.0-beta.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- 45fb496: I failed to take good notes over the last few years. Sorry.
|
|
8
|
+
|
|
9
|
+
### Patch Changes
|
|
10
|
+
|
|
11
|
+
- Updated dependencies [45fb496]
|
|
12
|
+
- @monorepolint/config@0.5.0-beta.0
|
|
13
|
+
- @monorepolint/core@0.5.0-beta.0
|
|
14
|
+
- @monorepolint/utils@0.5.0-beta.0
|
package/package.json
CHANGED
|
@@ -1,41 +1,63 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@monorepolint/rules",
|
|
3
|
-
"version": "0.5.0-
|
|
3
|
+
"version": "0.5.0-beta.0",
|
|
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
|
-
"
|
|
11
|
-
"
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
"
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
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"
|
|
20
23
|
},
|
|
21
24
|
"dependencies": {
|
|
22
|
-
"
|
|
23
|
-
"
|
|
24
|
-
"
|
|
25
|
-
"
|
|
26
|
-
"
|
|
27
|
-
"
|
|
28
|
-
"
|
|
29
|
-
"
|
|
25
|
+
"globby": "^14.0.1",
|
|
26
|
+
"jest-diff": "^29.7.0",
|
|
27
|
+
"resolve-package-path": "^4.0.3",
|
|
28
|
+
"runtypes": "^6.7.0",
|
|
29
|
+
"semver": "^7.6.0",
|
|
30
|
+
"tslib": "^2.6.2",
|
|
31
|
+
"@monorepolint/utils": "^0.5.0-beta.0",
|
|
32
|
+
"@monorepolint/config": "^0.5.0-beta.0",
|
|
33
|
+
"@monorepolint/core": "^0.5.0-beta.0"
|
|
30
34
|
},
|
|
31
35
|
"devDependencies": {
|
|
32
|
-
"@
|
|
33
|
-
"@types/
|
|
34
|
-
"@types/
|
|
35
|
-
"tmp": "^0.2.
|
|
36
|
+
"@jest/globals": "^29.7.0",
|
|
37
|
+
"@types/jest": "^29.5.12",
|
|
38
|
+
"@types/semver": "^7.5.8",
|
|
39
|
+
"@types/tmp": "^0.2.6",
|
|
40
|
+
"@typescript-eslint/eslint-plugin": "^7.7.1",
|
|
41
|
+
"@typescript-eslint/parser": "^7.7.1",
|
|
42
|
+
"eslint": "^9.1.1",
|
|
43
|
+
"jest": "^29.7.0",
|
|
44
|
+
"prettier": "^3.2.5",
|
|
45
|
+
"tmp": "^0.2.3",
|
|
46
|
+
"ts-jest": "^29.1.2",
|
|
47
|
+
"tslib": "^2.6.2",
|
|
48
|
+
"tsup": "^8.0.2",
|
|
49
|
+
"typescript": "^5.4.5"
|
|
36
50
|
},
|
|
37
51
|
"publishConfig": {
|
|
38
52
|
"access": "public"
|
|
39
53
|
},
|
|
40
|
-
"gitHead": "
|
|
41
|
-
|
|
54
|
+
"gitHead": "74320e31cfce7555aece7a98d71d01d2f329be0f",
|
|
55
|
+
"scripts": {
|
|
56
|
+
"clean": "rm -rf build dist lib node_modules *.tgz tsconfig.tsbuildinfo",
|
|
57
|
+
"compile-typescript": "tsc --build",
|
|
58
|
+
"lint": "eslint .",
|
|
59
|
+
"test": "NODE_OPTIONS=--experimental-vm-modules jest --colors --passWithNoTests",
|
|
60
|
+
"test:watch": "NODE_OPTIONS=--experimental-vm-modules jest --colors --passWithNoTests --watch",
|
|
61
|
+
"transpile-typescript": "tsup --config ../../tsup.config.cjs"
|
|
62
|
+
}
|
|
63
|
+
}
|
|
@@ -6,10 +6,11 @@
|
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
8
|
// tslint:disable:no-console
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
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";
|
|
13
14
|
|
|
14
15
|
const PACKAGE_SCRIPTS_SORTED = jsonToString({
|
|
15
16
|
name: "foo-lib",
|
|
@@ -48,7 +49,7 @@ describe.each(HOST_FACTORIES)("alphabeticalScripts ($name)", (hostFactory) => {
|
|
|
48
49
|
it("fixes unsorted scripts", () => {
|
|
49
50
|
workspace.writeFile("package.json", PACKAGE_SCRIPTS_UNSORTED);
|
|
50
51
|
|
|
51
|
-
alphabeticalScripts.check(context
|
|
52
|
+
alphabeticalScripts({}).check(context);
|
|
52
53
|
|
|
53
54
|
expect(spy).toHaveBeenCalledTimes(1);
|
|
54
55
|
|
|
@@ -67,7 +68,7 @@ describe.each(HOST_FACTORIES)("alphabeticalScripts ($name)", (hostFactory) => {
|
|
|
67
68
|
it("does nothing if already sorted", () => {
|
|
68
69
|
workspace.writeFile("package.json", PACKAGE_SCRIPTS_SORTED);
|
|
69
70
|
|
|
70
|
-
alphabeticalScripts.check(context
|
|
71
|
+
alphabeticalScripts({}).check(context);
|
|
71
72
|
|
|
72
73
|
expect(spy).toHaveBeenCalledTimes(0);
|
|
73
74
|
});
|
|
@@ -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 {
|
|
7
|
+
import { describe, expect, it, beforeEach, jest, afterEach } from "@jest/globals";
|
|
8
|
+
import { WorkspaceContextImpl } from "@monorepolint/core";
|
|
8
9
|
import { SimpleHost } from "@monorepolint/utils";
|
|
9
10
|
import { writeFileSync } from "fs";
|
|
10
11
|
import * as path from "path";
|
|
11
12
|
import * as tmp from "tmp";
|
|
12
|
-
import { bannedDependencies, Options } from "../bannedDependencies";
|
|
13
|
-
import { makeDirectoryRecursively } from "../util/makeDirectory";
|
|
14
|
-
import { jsonToString } from "./utils";
|
|
15
|
-
|
|
13
|
+
import { bannedDependencies, Options } from "../bannedDependencies.js";
|
|
14
|
+
import { makeDirectoryRecursively } from "../util/makeDirectory.js";
|
|
15
|
+
import { jsonToString } from "./utils.js";
|
|
16
16
|
const EMPTY_PACKAGE = jsonToString({});
|
|
17
17
|
|
|
18
18
|
describe("bannedDependencies", () => {
|
|
@@ -38,7 +38,7 @@ describe("bannedDependencies", () => {
|
|
|
38
38
|
});
|
|
39
39
|
|
|
40
40
|
function makeWorkspace() {
|
|
41
|
-
const workspaceContext = new
|
|
41
|
+
const workspaceContext = new WorkspaceContextImpl(
|
|
42
42
|
cwd!,
|
|
43
43
|
{
|
|
44
44
|
rules: [],
|
|
@@ -51,9 +51,7 @@ describe("bannedDependencies", () => {
|
|
|
51
51
|
|
|
52
52
|
function checkAndSpy(options: Options) {
|
|
53
53
|
const addErrorSpy = jest.spyOn(workspaceContext, "addError");
|
|
54
|
-
bannedDependencies.check(workspaceContext
|
|
55
|
-
...options,
|
|
56
|
-
});
|
|
54
|
+
bannedDependencies({ options }).check(workspaceContext);
|
|
57
55
|
return { addErrorSpy };
|
|
58
56
|
}
|
|
59
57
|
|
|
@@ -4,14 +4,15 @@
|
|
|
4
4
|
* Licensed under the MIT license. See LICENSE file in the project root for details.
|
|
5
5
|
*
|
|
6
6
|
*/
|
|
7
|
-
import {
|
|
7
|
+
import { WorkspaceContextImpl } from "@monorepolint/core";
|
|
8
8
|
import { SimpleHost } from "@monorepolint/utils";
|
|
9
9
|
import { readFileSync, writeFileSync } from "fs";
|
|
10
10
|
import * as path from "path";
|
|
11
11
|
import * as tmp from "tmp";
|
|
12
|
-
import { consistentDependencies, Options } from "../consistentDependencies";
|
|
13
|
-
import { makeDirectoryRecursively } from "../util/makeDirectory";
|
|
14
|
-
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";
|
|
15
16
|
|
|
16
17
|
const PACKAGE_ROOT = jsonToString({
|
|
17
18
|
workspaces: {
|
|
@@ -62,7 +63,7 @@ describe("consistentDependencies", () => {
|
|
|
62
63
|
const dir: tmp.DirResult = tmp.dirSync({ unsafeCleanup: true });
|
|
63
64
|
cleanupJobs.push(() => dir.removeCallback());
|
|
64
65
|
|
|
65
|
-
const workspaceContext = new
|
|
66
|
+
const workspaceContext = new WorkspaceContextImpl(
|
|
66
67
|
dir.name,
|
|
67
68
|
{
|
|
68
69
|
rules: [],
|
|
@@ -76,7 +77,7 @@ describe("consistentDependencies", () => {
|
|
|
76
77
|
function checkAndSpy(q: string, opts?: Options) {
|
|
77
78
|
const context = workspaceContext.createChildContext(path.resolve(dir.name, q));
|
|
78
79
|
const addErrorSpy = jest.spyOn(context, "addError");
|
|
79
|
-
consistentDependencies.check(context
|
|
80
|
+
consistentDependencies({ options: opts }).check(context);
|
|
80
81
|
return { context, addErrorSpy };
|
|
81
82
|
}
|
|
82
83
|
|
|
@@ -103,7 +104,7 @@ describe("consistentDependencies", () => {
|
|
|
103
104
|
addFile("./packages/right/package.json", PACKAGE_CHILD_WITH_RIGHT_VERSION);
|
|
104
105
|
addFile("./packages/wrong/package.json", PACKAGE_CHILD_WITH_WRONG_VERSION);
|
|
105
106
|
|
|
106
|
-
consistentDependencies.check(workspaceContext
|
|
107
|
+
consistentDependencies({}).check(workspaceContext);
|
|
107
108
|
|
|
108
109
|
const star = checkAndSpy("./packages/star");
|
|
109
110
|
expect(star.addErrorSpy).toHaveBeenCalledTimes(0);
|
|
@@ -5,12 +5,13 @@
|
|
|
5
5
|
*
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
-
import {
|
|
8
|
+
import { WorkspaceContextImpl } from "@monorepolint/core";
|
|
9
9
|
import { Host, PackageJson, SimpleHost } from "@monorepolint/utils";
|
|
10
10
|
import * as path from "path";
|
|
11
11
|
import * as tmp from "tmp";
|
|
12
|
-
import { consistentVersions, Options } from "../consistentVersions";
|
|
13
|
-
import { makeDirectoryRecursively } from "../util/makeDirectory";
|
|
12
|
+
import { consistentVersions, Options } from "../consistentVersions.js";
|
|
13
|
+
import { makeDirectoryRecursively } from "../util/makeDirectory.js";
|
|
14
|
+
import { describe, expect, it, beforeEach, afterEach, jest } from "@jest/globals";
|
|
14
15
|
|
|
15
16
|
describe("consistentVersions", () => {
|
|
16
17
|
tmp.setGracefulCleanup();
|
|
@@ -36,7 +37,7 @@ describe("consistentVersions", () => {
|
|
|
36
37
|
|
|
37
38
|
function makeWorkspace(fix = false) {
|
|
38
39
|
const host: Host = new SimpleHost();
|
|
39
|
-
const workspaceContext = new
|
|
40
|
+
const workspaceContext = new WorkspaceContextImpl(
|
|
40
41
|
cwd!,
|
|
41
42
|
{
|
|
42
43
|
rules: [],
|
|
@@ -49,7 +50,7 @@ describe("consistentVersions", () => {
|
|
|
49
50
|
const addErrorSpy = jest.spyOn(workspaceContext, "addError");
|
|
50
51
|
|
|
51
52
|
function check(options: Options = { matchDependencyVersions: {} }) {
|
|
52
|
-
consistentVersions.check(workspaceContext
|
|
53
|
+
consistentVersions({ options }).check(workspaceContext);
|
|
53
54
|
}
|
|
54
55
|
|
|
55
56
|
return { addErrorSpy, check, host };
|
|
@@ -62,7 +63,7 @@ describe("consistentVersions", () => {
|
|
|
62
63
|
makeDirectoryRecursively(dirPath);
|
|
63
64
|
host.writeJson(resolvedFilePath, packageJson);
|
|
64
65
|
return (): PackageJson => {
|
|
65
|
-
return host.readJson(resolvedFilePath);
|
|
66
|
+
return host.readJson(resolvedFilePath) as PackageJson;
|
|
66
67
|
};
|
|
67
68
|
}
|
|
68
69
|
|
|
@@ -6,16 +6,17 @@
|
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
8
|
// tslint:disable:no-console
|
|
9
|
-
import { createTestingWorkspace, HOST_FACTORIES, TestingWorkspace } from "./utils";
|
|
10
|
-
import { AddErrorOptions, Failure } from "@monorepolint/
|
|
11
|
-
import { fileContents } from "../fileContents";
|
|
9
|
+
import { createTestingWorkspace, HOST_FACTORIES, TestingWorkspace } from "./utils.js";
|
|
10
|
+
import { AddErrorOptions, Failure } from "@monorepolint/config";
|
|
11
|
+
import { fileContents } from "../fileContents.js";
|
|
12
|
+
import { describe, expect, it, beforeEach, jest } from "@jest/globals";
|
|
12
13
|
|
|
13
14
|
const EXPECTED_FOO_FILE = "hello world";
|
|
14
15
|
|
|
15
16
|
describe.each(HOST_FACTORIES)("fileContents ($name)", (hostFactory) => {
|
|
16
17
|
describe("fix: true", () => {
|
|
17
18
|
let workspace: TestingWorkspace;
|
|
18
|
-
let spy: jest.
|
|
19
|
+
let spy: jest.SpiedFunction<(opts: AddErrorOptions) => void>;
|
|
19
20
|
|
|
20
21
|
beforeEach(async () => {
|
|
21
22
|
workspace = await createTestingWorkspace({
|
|
@@ -27,13 +28,13 @@ describe.each(HOST_FACTORIES)("fileContents ($name)", (hostFactory) => {
|
|
|
27
28
|
spy = jest.spyOn(workspace.context, "addError");
|
|
28
29
|
});
|
|
29
30
|
|
|
30
|
-
it("
|
|
31
|
-
fileContents
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
});
|
|
31
|
+
it("works with async generator", async () => {
|
|
32
|
+
await fileContents({
|
|
33
|
+
options: {
|
|
34
|
+
file: "foo.txt",
|
|
35
|
+
generator: () => Promise.resolve(EXPECTED_FOO_FILE),
|
|
36
|
+
},
|
|
37
|
+
}).check(workspace.context);
|
|
37
38
|
|
|
38
39
|
expect(spy).toHaveBeenCalledTimes(1);
|
|
39
40
|
|
|
@@ -49,13 +50,39 @@ describe.each(HOST_FACTORIES)("fileContents ($name)", (hostFactory) => {
|
|
|
49
50
|
expect(workspace.readFile("foo.txt")).toEqual(EXPECTED_FOO_FILE);
|
|
50
51
|
});
|
|
51
52
|
|
|
52
|
-
it("fixes missing
|
|
53
|
-
fileContents
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
53
|
+
it("fixes missing file", async () => {
|
|
54
|
+
await fileContents({
|
|
55
|
+
options: {
|
|
56
|
+
file: "foo.txt",
|
|
57
|
+
templateFile: "shared/foo-template.txt",
|
|
58
|
+
generator: undefined,
|
|
59
|
+
template: undefined,
|
|
60
|
+
},
|
|
61
|
+
}).check(workspace.context);
|
|
62
|
+
|
|
63
|
+
expect(spy).toHaveBeenCalledTimes(1);
|
|
64
|
+
|
|
65
|
+
const failure: Failure = spy.mock.calls[0][0];
|
|
66
|
+
expect(failure).toMatchObject(
|
|
67
|
+
workspace.failureMatcher({
|
|
68
|
+
file: "foo.txt",
|
|
69
|
+
hasFixer: true,
|
|
70
|
+
message: "Expect file contents to match",
|
|
71
|
+
})
|
|
72
|
+
);
|
|
73
|
+
|
|
74
|
+
expect(workspace.readFile("foo.txt")).toEqual(EXPECTED_FOO_FILE);
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
it("fixes missing nested file", async () => {
|
|
78
|
+
await fileContents({
|
|
79
|
+
options: {
|
|
80
|
+
file: "nested/foo.txt",
|
|
81
|
+
templateFile: "shared/foo-template.txt",
|
|
82
|
+
generator: undefined,
|
|
83
|
+
template: undefined,
|
|
84
|
+
},
|
|
85
|
+
}).check(workspace.context);
|
|
59
86
|
|
|
60
87
|
expect(spy).toHaveBeenCalledTimes(1);
|
|
61
88
|
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
*
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
-
import {
|
|
8
|
+
import { WorkspaceContextImpl } from "@monorepolint/core";
|
|
9
9
|
import { Host, PackageJson, SimpleHost } from "@monorepolint/utils";
|
|
10
10
|
import * as path from "path";
|
|
11
11
|
import * as tmp from "tmp";
|
|
@@ -19,8 +19,9 @@ import {
|
|
|
19
19
|
mustSatisfyPeerDependencies,
|
|
20
20
|
Options,
|
|
21
21
|
RANGE_REGEX,
|
|
22
|
-
} from "../mustSatisfyPeerDependencies";
|
|
23
|
-
import { makeDirectoryRecursively } from "../util/makeDirectory";
|
|
22
|
+
} from "../mustSatisfyPeerDependencies.js";
|
|
23
|
+
import { makeDirectoryRecursively } from "../util/makeDirectory.js";
|
|
24
|
+
import { describe, expect, it, beforeEach, afterEach, jest } from "@jest/globals";
|
|
24
25
|
|
|
25
26
|
const doesASatisfyB = (a: string, b: string) => {
|
|
26
27
|
if (!isValidRange(a)) {
|
|
@@ -66,7 +67,7 @@ describe("mustSatisfyPeerDependencies", () => {
|
|
|
66
67
|
|
|
67
68
|
function makeWorkspace(fix = false) {
|
|
68
69
|
const host: Host = new SimpleHost();
|
|
69
|
-
const workspaceContext = new
|
|
70
|
+
const workspaceContext = new WorkspaceContextImpl(
|
|
70
71
|
cwd!,
|
|
71
72
|
{
|
|
72
73
|
rules: [],
|
|
@@ -78,8 +79,8 @@ describe("mustSatisfyPeerDependencies", () => {
|
|
|
78
79
|
);
|
|
79
80
|
const addErrorSpy = jest.spyOn(workspaceContext, "addError");
|
|
80
81
|
|
|
81
|
-
function check(options: Options) {
|
|
82
|
-
mustSatisfyPeerDependencies.check(workspaceContext
|
|
82
|
+
async function check(options: Options) {
|
|
83
|
+
await mustSatisfyPeerDependencies({ options }).check(workspaceContext);
|
|
83
84
|
}
|
|
84
85
|
|
|
85
86
|
return { addErrorSpy, check, host };
|
|
@@ -92,7 +93,7 @@ describe("mustSatisfyPeerDependencies", () => {
|
|
|
92
93
|
makeDirectoryRecursively(dirPath);
|
|
93
94
|
host.writeJson(resolvedFilePath, packageJson);
|
|
94
95
|
return (): PackageJson => {
|
|
95
|
-
return host.readJson(resolvedFilePath);
|
|
96
|
+
return host.readJson(resolvedFilePath) as PackageJson;
|
|
96
97
|
};
|
|
97
98
|
}
|
|
98
99
|
|
|
@@ -844,7 +845,7 @@ describe("mustSatisfyPeerDependencies", () => {
|
|
|
844
845
|
};
|
|
845
846
|
addPackageJson(host, "./node_modules/greatLib/package.json", greatLibPackageJson);
|
|
846
847
|
|
|
847
|
-
check({});
|
|
848
|
+
await check({});
|
|
848
849
|
expect(addErrorSpy).toHaveBeenCalledTimes(1);
|
|
849
850
|
expect(addErrorSpy.mock.calls[0][0].message).toEqual(
|
|
850
851
|
`[0] Package ${testPackageJson.name} has overloaded greatLib dependencies.\n\t` +
|
|
@@ -894,7 +895,7 @@ describe("mustSatisfyPeerDependencies", () => {
|
|
|
894
895
|
};
|
|
895
896
|
addPackageJson(host, "./node_modules/ccc/package.json", cccPackageJson);
|
|
896
897
|
|
|
897
|
-
check({});
|
|
898
|
+
await check({});
|
|
898
899
|
expect(addErrorSpy).toHaveBeenCalledTimes(1);
|
|
899
900
|
expect(addErrorSpy.mock.calls[0][0].message).toEqual(
|
|
900
901
|
`[1] Package ${testPackageJson.name} has conflicting inherited greatLib peer dependencies.\n\t` +
|
|
@@ -903,7 +904,7 @@ describe("mustSatisfyPeerDependencies", () => {
|
|
|
903
904
|
);
|
|
904
905
|
addErrorSpy.mockReset();
|
|
905
906
|
|
|
906
|
-
check({ enforceForDevDependencies: true });
|
|
907
|
+
await check({ enforceForDevDependencies: true });
|
|
907
908
|
expect(addErrorSpy).toHaveBeenCalledTimes(2);
|
|
908
909
|
expect(addErrorSpy.mock.calls[1][0].message).toEqual(
|
|
909
910
|
`[1] Package ${testPackageJson.name} has conflicting inherited greatestLib peer dependencies.\n\t` +
|
|
@@ -955,7 +956,7 @@ describe("mustSatisfyPeerDependencies", () => {
|
|
|
955
956
|
};
|
|
956
957
|
addPackageJson(host, "./node_modules/ccc/package.json", cccPackageJson);
|
|
957
958
|
|
|
958
|
-
check({});
|
|
959
|
+
await check({});
|
|
959
960
|
expect(addErrorSpy).toHaveBeenCalledTimes(1);
|
|
960
961
|
expect(addErrorSpy.mock.calls[0][0].message).toEqual(
|
|
961
962
|
`[2] Package ${testPackageJson.name} dependency on greatLib '${testPackageJson.dependencies.greatLib}' does not satisfy inherited peer dependencies.\n\t` +
|
|
@@ -963,7 +964,7 @@ describe("mustSatisfyPeerDependencies", () => {
|
|
|
963
964
|
);
|
|
964
965
|
addErrorSpy.mockReset();
|
|
965
966
|
|
|
966
|
-
check({ enforceForDevDependencies: true });
|
|
967
|
+
await check({ enforceForDevDependencies: true });
|
|
967
968
|
expect(addErrorSpy).toHaveBeenCalledTimes(1);
|
|
968
969
|
expect(addErrorSpy.mock.calls[0][0].message).toEqual(
|
|
969
970
|
`[2] Package ${testPackageJson.name} dependency on greatLib '${testPackageJson.dependencies.greatLib}' does not satisfy inherited peer dependencies.\n\t` +
|
|
@@ -984,32 +985,32 @@ describe("mustSatisfyPeerDependencies", () => {
|
|
|
984
985
|
devDependencies: {
|
|
985
986
|
ccc: "0.0.1",
|
|
986
987
|
},
|
|
987
|
-
};
|
|
988
|
+
} as const;
|
|
988
989
|
const readTestPackageJson = addPackageJson(host, "./package.json", testPackageJson);
|
|
989
990
|
|
|
990
991
|
const aaaPackageJson = {
|
|
991
|
-
name: "
|
|
992
|
+
name: "aaa",
|
|
992
993
|
peerDependencies: {
|
|
993
994
|
greatLib: "15 || ^16.2",
|
|
994
995
|
},
|
|
995
|
-
};
|
|
996
|
+
} as const;
|
|
996
997
|
addPackageJson(host, "./node_modules/aaa/package.json", aaaPackageJson);
|
|
997
998
|
const bbbPackageJson = {
|
|
998
|
-
name: "
|
|
999
|
+
name: "bbbb",
|
|
999
1000
|
peerDependencies: {
|
|
1000
1001
|
greatLib: "^16",
|
|
1001
1002
|
},
|
|
1002
|
-
};
|
|
1003
|
+
} as const;
|
|
1003
1004
|
addPackageJson(host, "./node_modules/bbb/package.json", bbbPackageJson);
|
|
1004
1005
|
const cccPackageJson = {
|
|
1005
|
-
name: "
|
|
1006
|
+
name: "ccc",
|
|
1006
1007
|
peerDependencies: {
|
|
1007
1008
|
greatestLib: "100",
|
|
1008
1009
|
},
|
|
1009
|
-
};
|
|
1010
|
+
} as const;
|
|
1010
1011
|
addPackageJson(host, "./node_modules/ccc/package.json", cccPackageJson);
|
|
1011
1012
|
|
|
1012
|
-
check({});
|
|
1013
|
+
await check({});
|
|
1013
1014
|
expect(addErrorSpy).toHaveBeenCalledTimes(1);
|
|
1014
1015
|
expect(addErrorSpy.mock.calls[0][0].message).toEqual(
|
|
1015
1016
|
`[3] Package ${testPackageJson.name} is missing required greatLib dependency.\n\t` +
|
|
@@ -1020,9 +1021,9 @@ describe("mustSatisfyPeerDependencies", () => {
|
|
|
1020
1021
|
expect(readTestPackageJson().peerDependencies!.greatLib).toEqual("^16.2");
|
|
1021
1022
|
addErrorSpy.mockReset();
|
|
1022
1023
|
|
|
1023
|
-
check({ enforceForDevDependencies: true });
|
|
1024
|
-
expect(addErrorSpy).toHaveBeenCalledTimes(
|
|
1025
|
-
expect(addErrorSpy.mock.calls[
|
|
1024
|
+
await check({ enforceForDevDependencies: true });
|
|
1025
|
+
expect(addErrorSpy).toHaveBeenCalledTimes(1);
|
|
1026
|
+
expect(addErrorSpy.mock.calls[0][0].message).toEqual(
|
|
1026
1027
|
`[3] Package ${testPackageJson.name} is missing required greatestLib dependency.\n\t` +
|
|
1027
1028
|
`Dependency ${cccPackageJson.name} requires '${cccPackageJson.peerDependencies.greatestLib}'.`
|
|
1028
1029
|
);
|
|
@@ -1044,32 +1045,32 @@ describe("mustSatisfyPeerDependencies", () => {
|
|
|
1044
1045
|
devDependencies: {
|
|
1045
1046
|
ccc: "0.0.1",
|
|
1046
1047
|
},
|
|
1047
|
-
};
|
|
1048
|
+
} as const;
|
|
1048
1049
|
const readTestPackageJson = addPackageJson(host, "./package.json", testPackageJson);
|
|
1049
1050
|
|
|
1050
1051
|
const aaaPackageJson = {
|
|
1051
|
-
name: "
|
|
1052
|
+
name: "aaa",
|
|
1052
1053
|
peerDependencies: {
|
|
1053
1054
|
greatLib: "15 || ^16",
|
|
1054
1055
|
},
|
|
1055
|
-
};
|
|
1056
|
+
} as const;
|
|
1056
1057
|
addPackageJson(host, "./node_modules/aaa/package.json", aaaPackageJson);
|
|
1057
1058
|
const bbbPackageJson = {
|
|
1058
|
-
name: "
|
|
1059
|
+
name: "bbb",
|
|
1059
1060
|
peerDependencies: {
|
|
1060
1061
|
greatLib: "^16",
|
|
1061
1062
|
},
|
|
1062
|
-
};
|
|
1063
|
+
} as const;
|
|
1063
1064
|
addPackageJson(host, "./node_modules/bbb/package.json", bbbPackageJson);
|
|
1064
1065
|
const cccPackageJson = {
|
|
1065
|
-
name: "
|
|
1066
|
+
name: "ccc",
|
|
1066
1067
|
peerDependencies: {
|
|
1067
1068
|
greatLib: "^16.2",
|
|
1068
1069
|
},
|
|
1069
|
-
};
|
|
1070
|
+
} as const;
|
|
1070
1071
|
addPackageJson(host, "./node_modules/ccc/package.json", cccPackageJson);
|
|
1071
1072
|
|
|
1072
|
-
check({});
|
|
1073
|
+
await check({});
|
|
1073
1074
|
expect(addErrorSpy).toHaveBeenCalledTimes(1);
|
|
1074
1075
|
expect(addErrorSpy.mock.calls[0][0].message).toEqual(
|
|
1075
1076
|
`[4] Package ${testPackageJson.name} peer dependency on greatLib '${testPackageJson.peerDependencies.greatLib}' is not strict enough.\n\t` +
|
|
@@ -1078,10 +1079,10 @@ describe("mustSatisfyPeerDependencies", () => {
|
|
|
1078
1079
|
expect(readTestPackageJson().peerDependencies!.greatLib).toEqual(bbbPackageJson.peerDependencies.greatLib);
|
|
1079
1080
|
addErrorSpy.mockReset();
|
|
1080
1081
|
|
|
1081
|
-
check({ enforceForDevDependencies: true });
|
|
1082
|
+
await check({ enforceForDevDependencies: true });
|
|
1082
1083
|
expect(addErrorSpy).toHaveBeenCalledTimes(1);
|
|
1083
1084
|
expect(addErrorSpy.mock.calls[0][0].message).toEqual(
|
|
1084
|
-
`[4] Package ${testPackageJson.name} peer dependency on greatLib '${
|
|
1085
|
+
`[4] Package ${testPackageJson.name} peer dependency on greatLib '${bbbPackageJson.peerDependencies.greatLib}' is not strict enough.\n\t` +
|
|
1085
1086
|
`Dependency ${cccPackageJson.name} requires '${cccPackageJson.peerDependencies.greatLib}'.`
|
|
1086
1087
|
);
|
|
1087
1088
|
addErrorSpy.mockReset();
|
|
@@ -1127,9 +1128,9 @@ describe("mustSatisfyPeerDependencies", () => {
|
|
|
1127
1128
|
};
|
|
1128
1129
|
addPackageJson(host, "./node_modules/bbb/package.json", bbbPackageJson);
|
|
1129
1130
|
|
|
1130
|
-
check({ dependencyWhitelist: ["startHere"] });
|
|
1131
|
+
await check({ dependencyWhitelist: ["startHere"] });
|
|
1131
1132
|
expect(addErrorSpy).toHaveBeenCalledTimes(0);
|
|
1132
|
-
check({ dependencyWhitelist: ["startHere", "greatLib"] });
|
|
1133
|
+
await check({ dependencyWhitelist: ["startHere", "greatLib"] });
|
|
1133
1134
|
expect(addErrorSpy).toHaveBeenCalledTimes(2);
|
|
1134
1135
|
});
|
|
1135
1136
|
|
|
@@ -1159,29 +1160,29 @@ describe("mustSatisfyPeerDependencies", () => {
|
|
|
1159
1160
|
};
|
|
1160
1161
|
addPackageJson(host, "./node_modules/greatLib/package.json", greatLibPackageJson);
|
|
1161
1162
|
const aaaPackageJson = {
|
|
1162
|
-
name: "
|
|
1163
|
+
name: "aaa",
|
|
1163
1164
|
peerDependencies: {
|
|
1164
1165
|
greatLib: "15",
|
|
1165
1166
|
},
|
|
1166
1167
|
};
|
|
1167
1168
|
addPackageJson(host, "./node_modules/aaa/package.json", aaaPackageJson);
|
|
1168
1169
|
const bbbPackageJson = {
|
|
1169
|
-
name: "
|
|
1170
|
+
name: "bbb",
|
|
1170
1171
|
peerDependencies: {
|
|
1171
1172
|
greatLib: "16",
|
|
1172
1173
|
},
|
|
1173
1174
|
};
|
|
1174
1175
|
addPackageJson(host, "./node_modules/bbb/package.json", bbbPackageJson);
|
|
1175
1176
|
|
|
1176
|
-
check({ dependencyBlacklist: ["greatLib"] });
|
|
1177
|
+
await check({ dependencyBlacklist: ["greatLib"] });
|
|
1177
1178
|
expect(addErrorSpy).toHaveBeenCalledTimes(0);
|
|
1178
1179
|
addErrorSpy.mockReset();
|
|
1179
1180
|
|
|
1180
|
-
check({ dependencyBlacklist: ["greatLib"], dependencyWhitelist: ["greatLib"] });
|
|
1181
|
+
await check({ dependencyBlacklist: ["greatLib"], dependencyWhitelist: ["greatLib"] });
|
|
1181
1182
|
expect(addErrorSpy).toHaveBeenCalledTimes(0);
|
|
1182
1183
|
addErrorSpy.mockReset();
|
|
1183
1184
|
|
|
1184
|
-
check({});
|
|
1185
|
+
await check({});
|
|
1185
1186
|
expect(addErrorSpy).toHaveBeenCalledTimes(2);
|
|
1186
1187
|
addErrorSpy.mockReset();
|
|
1187
1188
|
});
|
|
@@ -4,14 +4,15 @@
|
|
|
4
4
|
* Licensed under the MIT license. See LICENSE file in the project root for details.
|
|
5
5
|
*
|
|
6
6
|
*/
|
|
7
|
-
import {
|
|
7
|
+
import { WorkspaceContextImpl } from "@monorepolint/core";
|
|
8
8
|
import { SimpleHost } from "@monorepolint/utils";
|
|
9
9
|
import { writeFileSync } from "fs";
|
|
10
10
|
import * as path from "path";
|
|
11
11
|
import * as tmp from "tmp";
|
|
12
|
-
import { nestedWorkspaces } from "../nestedWorkspaces";
|
|
13
|
-
import { makeDirectoryRecursively } from "../util/makeDirectory";
|
|
14
|
-
import { jsonToString } from "./utils";
|
|
12
|
+
import { nestedWorkspaces } from "../nestedWorkspaces.js";
|
|
13
|
+
import { makeDirectoryRecursively } from "../util/makeDirectory.js";
|
|
14
|
+
import { jsonToString } from "./utils.js";
|
|
15
|
+
import { describe, expect, it, beforeEach, afterEach, jest } from "@jest/globals";
|
|
15
16
|
|
|
16
17
|
const EMPTY_PACKAGE = jsonToString({});
|
|
17
18
|
|
|
@@ -57,7 +58,7 @@ describe("nestedWorkspaces", () => {
|
|
|
57
58
|
|
|
58
59
|
function makeWorkspace() {
|
|
59
60
|
const host = new SimpleHost();
|
|
60
|
-
const workspaceContext = new
|
|
61
|
+
const workspaceContext = new WorkspaceContextImpl(
|
|
61
62
|
cwd!,
|
|
62
63
|
{
|
|
63
64
|
rules: [],
|
|
@@ -71,7 +72,7 @@ describe("nestedWorkspaces", () => {
|
|
|
71
72
|
async function checkAndSpy() {
|
|
72
73
|
const addErrorSpy = jest.spyOn(workspaceContext, "addError");
|
|
73
74
|
|
|
74
|
-
await nestedWorkspaces.check(workspaceContext
|
|
75
|
+
await nestedWorkspaces({}).check(workspaceContext);
|
|
75
76
|
return { addErrorSpy };
|
|
76
77
|
}
|
|
77
78
|
|