@monorepolint/rules 0.5.0-alpha.82 → 0.5.0-alpha.85
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/lib/__tests__/alphabeticalScripts.spec.js +22 -24
- package/lib/__tests__/alphabeticalScripts.spec.js.map +1 -1
- package/lib/__tests__/bannedDependencies.spec.js +67 -9
- package/lib/__tests__/bannedDependencies.spec.js.map +1 -1
- package/lib/__tests__/consistentDependencies.spec.js +11 -10
- package/lib/__tests__/consistentDependencies.spec.js.map +1 -1
- package/lib/__tests__/consistentVersions.spec.js +23 -22
- package/lib/__tests__/consistentVersions.spec.js.map +1 -1
- package/lib/__tests__/fileContents.spec.js +25 -32
- package/lib/__tests__/fileContents.spec.js.map +1 -1
- package/lib/__tests__/mustSatisfyPeerDependencies.spec.js +49 -48
- package/lib/__tests__/mustSatisfyPeerDependencies.spec.js.map +1 -1
- package/lib/__tests__/nestedWorkspaces.spec.js +10 -8
- package/lib/__tests__/nestedWorkspaces.spec.js.map +1 -1
- package/lib/__tests__/packageEntry.spec.js +47 -40
- package/lib/__tests__/packageEntry.spec.js.map +1 -1
- package/lib/__tests__/packageOrder.spec.js +34 -33
- package/lib/__tests__/packageOrder.spec.js.map +1 -1
- package/lib/__tests__/packageScript.spec.js +50 -51
- package/lib/__tests__/packageScript.spec.js.map +1 -1
- package/lib/__tests__/requireDependency.spec.js +12 -11
- package/lib/__tests__/requireDependency.spec.js.map +1 -1
- package/lib/__tests__/utils.d.ts +68 -1
- package/lib/__tests__/utils.d.ts.map +1 -1
- package/lib/__tests__/utils.js +70 -21
- package/lib/__tests__/utils.js.map +1 -1
- package/lib/alphabeticalDependencies.js +3 -3
- package/lib/alphabeticalDependencies.js.map +1 -1
- package/lib/alphabeticalScripts.js +1 -1
- package/lib/alphabeticalScripts.js.map +1 -1
- package/lib/bannedDependencies.d.ts +21 -12
- package/lib/bannedDependencies.d.ts.map +1 -1
- package/lib/bannedDependencies.js +86 -57
- package/lib/bannedDependencies.js.map +1 -1
- package/lib/consistentDependencies.d.ts +6 -6
- package/lib/consistentDependencies.d.ts.map +1 -1
- package/lib/consistentDependencies.js +2 -3
- package/lib/consistentDependencies.js.map +1 -1
- package/lib/consistentVersions.d.ts +1 -1
- package/lib/consistentVersions.js +8 -8
- package/lib/consistentVersions.js.map +1 -1
- package/lib/fileContents.d.ts +8 -8
- package/lib/fileContents.d.ts.map +1 -1
- package/lib/fileContents.js +32 -31
- package/lib/fileContents.js.map +1 -1
- package/lib/index.js +1 -0
- package/lib/index.js.map +1 -1
- package/lib/mustSatisfyPeerDependencies.d.ts +31 -31
- package/lib/mustSatisfyPeerDependencies.d.ts.map +1 -1
- package/lib/mustSatisfyPeerDependencies.js +18 -16
- package/lib/mustSatisfyPeerDependencies.js.map +1 -1
- package/lib/packageEntry.d.ts +11 -20
- package/lib/packageEntry.d.ts.map +1 -1
- package/lib/packageEntry.js +15 -7
- package/lib/packageEntry.js.map +1 -1
- package/lib/packageOrder.d.ts +3 -3
- package/lib/packageOrder.d.ts.map +1 -1
- package/lib/packageOrder.js +2 -3
- package/lib/packageOrder.js.map +1 -1
- package/lib/packageScript.d.ts +10 -10
- package/lib/packageScript.js +4 -4
- package/lib/packageScript.js.map +1 -1
- package/lib/requireDependency.d.ts +6 -6
- package/lib/requireDependency.d.ts.map +1 -1
- package/lib/requireDependency.js +3 -3
- package/lib/requireDependency.js.map +1 -1
- package/lib/standardTsconfig.d.ts +10 -10
- package/lib/standardTsconfig.d.ts.map +1 -1
- package/lib/standardTsconfig.js +26 -21
- package/lib/standardTsconfig.js.map +1 -1
- package/lib/util/checkAlpha.d.ts +1 -0
- package/lib/util/checkAlpha.d.ts.map +1 -1
- package/lib/util/checkAlpha.js +8 -5
- package/lib/util/checkAlpha.js.map +1 -1
- package/lib/util/makeDirectory.js +2 -2
- package/lib/util/makeDirectory.js.map +1 -1
- package/lib/util/packageDependencyGraphService.d.ts +3 -3
- package/lib/util/packageDependencyGraphService.d.ts.map +1 -1
- package/lib/util/packageDependencyGraphService.js +3 -3
- package/lib/util/packageDependencyGraphService.js.map +1 -1
- package/package.json +8 -9
- package/src/__tests__/alphabeticalScripts.spec.ts +27 -28
- package/src/__tests__/bannedDependencies.spec.ts +80 -6
- package/src/__tests__/consistentDependencies.spec.ts +11 -6
- package/src/__tests__/consistentVersions.spec.ts +32 -27
- package/src/__tests__/fileContents.spec.ts +32 -40
- package/src/__tests__/mustSatisfyPeerDependencies.spec.ts +52 -47
- package/src/__tests__/nestedWorkspaces.spec.ts +12 -6
- package/src/__tests__/packageEntry.spec.ts +64 -45
- package/src/__tests__/packageOrder.spec.ts +46 -40
- package/src/__tests__/packageScript.spec.ts +62 -54
- package/src/__tests__/requireDependency.spec.ts +11 -6
- package/src/__tests__/utils.ts +109 -19
- package/src/bannedDependencies.ts +106 -74
- package/src/consistentDependencies.ts +1 -2
- package/src/consistentVersions.ts +2 -2
- package/src/fileContents.ts +32 -30
- package/src/mustSatisfyPeerDependencies.ts +6 -2
- package/src/packageEntry.ts +13 -5
- package/src/packageOrder.ts +1 -2
- package/src/packageScript.ts +2 -2
- package/src/requireDependency.ts +2 -2
- package/src/standardTsconfig.ts +22 -19
- package/src/util/checkAlpha.ts +6 -3
- package/src/util/packageDependencyGraphService.ts +8 -5
- package/tsconfig.tsbuildinfo +1 -6233
|
@@ -10,13 +10,13 @@ const resolve_package_path_1 = tslib_1.__importDefault(require("resolve-package-
|
|
|
10
10
|
/** Default implementation of the package dependency graph service. */
|
|
11
11
|
class PackageDependencyGraphService {
|
|
12
12
|
/** Construct a graph of package dependencies and return the root node. */
|
|
13
|
-
buildDependencyGraph(startPackageJsonPath, maxDepth) {
|
|
13
|
+
buildDependencyGraph(startPackageJsonPath, host, maxDepth) {
|
|
14
14
|
const nodes = new Map();
|
|
15
15
|
const visit = (packageJsonPath, currentDepth) => {
|
|
16
16
|
if (nodes.has(packageJsonPath)) {
|
|
17
17
|
return nodes.get(packageJsonPath);
|
|
18
18
|
}
|
|
19
|
-
const packageJson =
|
|
19
|
+
const packageJson = host.readJson(packageJsonPath);
|
|
20
20
|
const node = {
|
|
21
21
|
packageJson,
|
|
22
22
|
dependencies: new Map(),
|
|
@@ -31,7 +31,7 @@ class PackageDependencyGraphService {
|
|
|
31
31
|
if (maxDepth == null || nextDepth <= maxDepth) {
|
|
32
32
|
const dependencies = packageJson.dependencies != null ? Object.keys(packageJson.dependencies) : [];
|
|
33
33
|
for (const dependency of dependencies) {
|
|
34
|
-
const dependencyPackageJsonPath = resolve_package_path_1.default(dependency, node.paths.rootDirectory);
|
|
34
|
+
const dependencyPackageJsonPath = (0, resolve_package_path_1.default)(dependency, node.paths.rootDirectory);
|
|
35
35
|
if (dependencyPackageJsonPath == null) {
|
|
36
36
|
throw new Error(`Could not resolve ${dependency} from ${node.paths.rootDirectory}`);
|
|
37
37
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"packageDependencyGraphService.js","sourceRoot":"","sources":["../../src/util/packageDependencyGraphService.ts"],"names":[],"mappings":";AAAA;;GAEG;;;;AAGH,wDAAwB;AACxB,wFAAsD;AA2BtD,sEAAsE;AACtE,MAAa,6BAA6B;IACxC,0EAA0E;IACnE,oBAAoB,
|
|
1
|
+
{"version":3,"file":"packageDependencyGraphService.js","sourceRoot":"","sources":["../../src/util/packageDependencyGraphService.ts"],"names":[],"mappings":"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"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@monorepolint/rules",
|
|
3
|
-
"version": "0.5.0-alpha.
|
|
3
|
+
"version": "0.5.0-alpha.85+a81e29c",
|
|
4
4
|
"author": "Eric L Anderson (https://github.com/ericanderson)",
|
|
5
5
|
"contributors": [
|
|
6
6
|
"Mac Lockard (https://github.com/maclockard)"
|
|
@@ -13,24 +13,23 @@
|
|
|
13
13
|
"clean": "rm -rf build lib node_modules *.tgz tsconfig.tsbuildinfo",
|
|
14
14
|
"compile:typescript": "../../node_modules/.bin/tsc",
|
|
15
15
|
"jest": "../../node_modules/.bin/jest --config ../../jest.config.js",
|
|
16
|
-
"jest:watch": "../../node_modules/.bin/jest --
|
|
16
|
+
"jest:watch": "../../node_modules/.bin/jest --watch",
|
|
17
17
|
"lint:typescript": "../../node_modules/.bin/tslint --config ../../tslint.json --project .",
|
|
18
18
|
"test": "../../node_modules/.bin/jest --colors --passWithNoTests",
|
|
19
19
|
"test:watch": "../../node_modules/.bin/jest --colors --passWithNoTests --watch"
|
|
20
20
|
},
|
|
21
21
|
"dependencies": {
|
|
22
|
-
"@monorepolint/core": "^0.5.0-alpha.
|
|
23
|
-
"@monorepolint/utils": "^0.5.0-alpha.
|
|
22
|
+
"@monorepolint/core": "^0.5.0-alpha.85+a81e29c",
|
|
23
|
+
"@monorepolint/utils": "^0.5.0-alpha.85+a81e29c",
|
|
24
24
|
"globby": "^11.0.1",
|
|
25
25
|
"jest-diff": "^26.0.1",
|
|
26
|
-
"minimatch": "^3.0.4",
|
|
27
26
|
"resolve-package-path": "^3.1.0",
|
|
28
|
-
"runtypes": "^
|
|
29
|
-
"semver": "^7.3.2"
|
|
27
|
+
"runtypes": "^6.5.1",
|
|
28
|
+
"semver": "^7.3.2",
|
|
29
|
+
"tslib": "^2.3.1"
|
|
30
30
|
},
|
|
31
31
|
"devDependencies": {
|
|
32
32
|
"@types/jest-diff": "^24.3.0",
|
|
33
|
-
"@types/minimatch": "^3.0.3",
|
|
34
33
|
"@types/semver": "^7.2.0",
|
|
35
34
|
"@types/tmp": "^0.2.0",
|
|
36
35
|
"tmp": "^0.2.1"
|
|
@@ -38,5 +37,5 @@
|
|
|
38
37
|
"publishConfig": {
|
|
39
38
|
"access": "public"
|
|
40
39
|
},
|
|
41
|
-
"gitHead": "
|
|
40
|
+
"gitHead": "a81e29c6c64476756dcc3f9ae9248abe754ff1e9"
|
|
42
41
|
}
|
|
@@ -6,13 +6,10 @@
|
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
8
|
// tslint:disable:no-console
|
|
9
|
-
import {
|
|
10
|
-
|
|
11
|
-
// done first since this also mocks 'fs'
|
|
12
|
-
const mockFiles: Map<string, string> = createMockFiles();
|
|
13
|
-
|
|
14
|
-
import { Failure, PackageContext } from "@monorepolint/core";
|
|
9
|
+
import { AddErrorSpy, createTestingWorkspace, HOST_FACTORIES, jsonToString, TestingWorkspace } from "./utils";
|
|
10
|
+
import { Context, Failure } from "@monorepolint/core";
|
|
15
11
|
import { alphabeticalScripts } from "../alphabeticalScripts";
|
|
12
|
+
import { createIncorrectOrderErrorMessage } from "../util/checkAlpha";
|
|
16
13
|
|
|
17
14
|
const PACKAGE_SCRIPTS_SORTED = jsonToString({
|
|
18
15
|
name: "foo-lib",
|
|
@@ -32,41 +29,43 @@ const PACKAGE_SCRIPTS_UNSORTED = jsonToString({
|
|
|
32
29
|
},
|
|
33
30
|
});
|
|
34
31
|
|
|
35
|
-
describe("alphabeticalScripts", () => {
|
|
36
|
-
afterEach(() => {
|
|
37
|
-
mockFiles.clear();
|
|
38
|
-
});
|
|
39
|
-
|
|
32
|
+
describe.each(HOST_FACTORIES)("alphabeticalScripts ($name)", (hostFactory) => {
|
|
40
33
|
describe("fix: true", () => {
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
34
|
+
let workspace: TestingWorkspace;
|
|
35
|
+
let spy: AddErrorSpy;
|
|
36
|
+
let context: Context;
|
|
37
|
+
|
|
38
|
+
beforeEach(async () => {
|
|
39
|
+
workspace = await createTestingWorkspace({
|
|
40
|
+
fixFlag: true,
|
|
41
|
+
host: hostFactory.make(),
|
|
42
|
+
});
|
|
43
|
+
context = workspace.context; // minimizing delta
|
|
44
|
+
|
|
45
|
+
spy = jest.spyOn(workspace.context, "addError");
|
|
51
46
|
});
|
|
52
47
|
|
|
53
48
|
it("fixes unsorted scripts", () => {
|
|
54
|
-
|
|
49
|
+
workspace.writeFile("package.json", PACKAGE_SCRIPTS_UNSORTED);
|
|
55
50
|
|
|
56
51
|
alphabeticalScripts.check(context, undefined);
|
|
57
52
|
|
|
58
53
|
expect(spy).toHaveBeenCalledTimes(1);
|
|
59
54
|
|
|
60
55
|
const failure: Failure = spy.mock.calls[0][0];
|
|
61
|
-
expect(failure
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
56
|
+
expect(failure).toMatchObject(
|
|
57
|
+
workspace.failureMatcher({
|
|
58
|
+
file: "package.json",
|
|
59
|
+
hasFixer: true,
|
|
60
|
+
message: createIncorrectOrderErrorMessage("scripts", "foo-lib"),
|
|
61
|
+
})
|
|
62
|
+
);
|
|
63
|
+
|
|
64
|
+
expect(workspace.readFile("package.json")).toEqual(PACKAGE_SCRIPTS_SORTED);
|
|
66
65
|
});
|
|
67
66
|
|
|
68
67
|
it("does nothing if already sorted", () => {
|
|
69
|
-
|
|
68
|
+
workspace.writeFile("package.json", PACKAGE_SCRIPTS_SORTED);
|
|
70
69
|
|
|
71
70
|
alphabeticalScripts.check(context, undefined);
|
|
72
71
|
|
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
*
|
|
6
6
|
*/
|
|
7
7
|
import { WorkspaceContext } from "@monorepolint/core";
|
|
8
|
+
import { SimpleHost } from "@monorepolint/utils";
|
|
8
9
|
import { writeFileSync } from "fs";
|
|
9
10
|
import * as path from "path";
|
|
10
11
|
import * as tmp from "tmp";
|
|
@@ -37,12 +38,16 @@ describe("bannedDependencies", () => {
|
|
|
37
38
|
});
|
|
38
39
|
|
|
39
40
|
function makeWorkspace() {
|
|
40
|
-
const workspaceContext = new WorkspaceContext(
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
41
|
+
const workspaceContext = new WorkspaceContext(
|
|
42
|
+
cwd!,
|
|
43
|
+
{
|
|
44
|
+
rules: [],
|
|
45
|
+
fix: false,
|
|
46
|
+
verbose: false,
|
|
47
|
+
silent: true,
|
|
48
|
+
},
|
|
49
|
+
new SimpleHost()
|
|
50
|
+
);
|
|
46
51
|
|
|
47
52
|
function checkAndSpy(options: Options) {
|
|
48
53
|
const addErrorSpy = jest.spyOn(workspaceContext, "addError");
|
|
@@ -87,6 +92,75 @@ describe("bannedDependencies", () => {
|
|
|
87
92
|
addErrorSpy3.mockReset();
|
|
88
93
|
});
|
|
89
94
|
|
|
95
|
+
it("Flags banned dependencies correctly w legacy globs", async () => {
|
|
96
|
+
const { addFile, checkAndSpy } = makeWorkspace();
|
|
97
|
+
const rootPackageJson = jsonToString({
|
|
98
|
+
dependencies: {
|
|
99
|
+
aaa: "0.0.1",
|
|
100
|
+
ccc: "0.0.1",
|
|
101
|
+
},
|
|
102
|
+
});
|
|
103
|
+
addFile("./package.json", rootPackageJson);
|
|
104
|
+
|
|
105
|
+
const { addErrorSpy: addErrorSpy1 } = checkAndSpy({ bannedDependencies: ["c*c"] });
|
|
106
|
+
expect(addErrorSpy1).toHaveBeenCalledTimes(1);
|
|
107
|
+
addErrorSpy1.mockReset();
|
|
108
|
+
|
|
109
|
+
const { addErrorSpy: addErrorSpy2 } = checkAndSpy({ bannedDependencies: ["d*d"] });
|
|
110
|
+
expect(addErrorSpy2).toHaveBeenCalledTimes(0);
|
|
111
|
+
addErrorSpy2.mockReset();
|
|
112
|
+
|
|
113
|
+
const { addErrorSpy: addErrorSpy3 } = checkAndSpy({ bannedDependencies: ["c*c", "d*d"] });
|
|
114
|
+
expect(addErrorSpy3).toHaveBeenCalledTimes(1);
|
|
115
|
+
addErrorSpy3.mockReset();
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
it("Flags banned dependencies correctly w new globs", async () => {
|
|
119
|
+
const { addFile, checkAndSpy } = makeWorkspace();
|
|
120
|
+
const rootPackageJson = jsonToString({
|
|
121
|
+
dependencies: {
|
|
122
|
+
aaa: "0.0.1",
|
|
123
|
+
ccc: "0.0.1",
|
|
124
|
+
},
|
|
125
|
+
});
|
|
126
|
+
addFile("./package.json", rootPackageJson);
|
|
127
|
+
|
|
128
|
+
const { addErrorSpy: addErrorSpy1 } = checkAndSpy({ bannedDependencies: { glob: ["c*c"] } });
|
|
129
|
+
expect(addErrorSpy1).toHaveBeenCalledTimes(1);
|
|
130
|
+
addErrorSpy1.mockReset();
|
|
131
|
+
|
|
132
|
+
const { addErrorSpy: addErrorSpy2 } = checkAndSpy({ bannedDependencies: { glob: ["d*d"] } });
|
|
133
|
+
expect(addErrorSpy2).toHaveBeenCalledTimes(0);
|
|
134
|
+
addErrorSpy2.mockReset();
|
|
135
|
+
|
|
136
|
+
const { addErrorSpy: addErrorSpy3 } = checkAndSpy({ bannedDependencies: { glob: ["c*c", "d*d"] } });
|
|
137
|
+
expect(addErrorSpy3).toHaveBeenCalledTimes(1);
|
|
138
|
+
addErrorSpy3.mockReset();
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
it("Flags banned dependencies correctly w exact", async () => {
|
|
142
|
+
const { addFile, checkAndSpy } = makeWorkspace();
|
|
143
|
+
const rootPackageJson = jsonToString({
|
|
144
|
+
dependencies: {
|
|
145
|
+
aaa: "0.0.1",
|
|
146
|
+
ccc: "0.0.1",
|
|
147
|
+
},
|
|
148
|
+
});
|
|
149
|
+
addFile("./package.json", rootPackageJson);
|
|
150
|
+
|
|
151
|
+
const { addErrorSpy: addErrorSpy1 } = checkAndSpy({ bannedDependencies: { exact: ["ccc"] } });
|
|
152
|
+
expect(addErrorSpy1).toHaveBeenCalledTimes(1);
|
|
153
|
+
addErrorSpy1.mockReset();
|
|
154
|
+
|
|
155
|
+
const { addErrorSpy: addErrorSpy2 } = checkAndSpy({ bannedDependencies: { exact: ["ddd"] } });
|
|
156
|
+
expect(addErrorSpy2).toHaveBeenCalledTimes(0);
|
|
157
|
+
addErrorSpy2.mockReset();
|
|
158
|
+
|
|
159
|
+
const { addErrorSpy: addErrorSpy3 } = checkAndSpy({ bannedDependencies: { exact: ["ccc", "ddd"] } });
|
|
160
|
+
expect(addErrorSpy3).toHaveBeenCalledTimes(1);
|
|
161
|
+
addErrorSpy3.mockReset();
|
|
162
|
+
});
|
|
163
|
+
|
|
90
164
|
it("Flags banned transitives correctly", async () => {
|
|
91
165
|
const { addFile, checkAndSpy } = makeWorkspace();
|
|
92
166
|
const rootPackageJson = jsonToString({
|
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
*
|
|
6
6
|
*/
|
|
7
7
|
import { WorkspaceContext } from "@monorepolint/core";
|
|
8
|
+
import { SimpleHost } from "@monorepolint/utils";
|
|
8
9
|
import { readFileSync, writeFileSync } from "fs";
|
|
9
10
|
import * as path from "path";
|
|
10
11
|
import * as tmp from "tmp";
|
|
@@ -61,12 +62,16 @@ describe("consistentDependencies", () => {
|
|
|
61
62
|
const dir: tmp.DirResult = tmp.dirSync({ unsafeCleanup: true });
|
|
62
63
|
cleanupJobs.push(() => dir.removeCallback());
|
|
63
64
|
|
|
64
|
-
const workspaceContext = new WorkspaceContext(
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
65
|
+
const workspaceContext = new WorkspaceContext(
|
|
66
|
+
dir.name,
|
|
67
|
+
{
|
|
68
|
+
rules: [],
|
|
69
|
+
fix,
|
|
70
|
+
verbose: false,
|
|
71
|
+
silent: true,
|
|
72
|
+
},
|
|
73
|
+
new SimpleHost()
|
|
74
|
+
);
|
|
70
75
|
|
|
71
76
|
function checkAndSpy(q: string, opts?: Options) {
|
|
72
77
|
const context = workspaceContext.createChildContext(path.resolve(dir.name, q));
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
8
|
import { WorkspaceContext } from "@monorepolint/core";
|
|
9
|
-
import {
|
|
9
|
+
import { Host, PackageJson, SimpleHost } from "@monorepolint/utils";
|
|
10
10
|
import * as path from "path";
|
|
11
11
|
import * as tmp from "tmp";
|
|
12
12
|
import { consistentVersions, Options } from "../consistentVersions";
|
|
@@ -35,29 +35,34 @@ describe("consistentVersions", () => {
|
|
|
35
35
|
});
|
|
36
36
|
|
|
37
37
|
function makeWorkspace(fix = false) {
|
|
38
|
-
const
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
38
|
+
const host: Host = new SimpleHost();
|
|
39
|
+
const workspaceContext = new WorkspaceContext(
|
|
40
|
+
cwd!,
|
|
41
|
+
{
|
|
42
|
+
rules: [],
|
|
43
|
+
fix,
|
|
44
|
+
verbose: false,
|
|
45
|
+
silent: true,
|
|
46
|
+
},
|
|
47
|
+
host
|
|
48
|
+
);
|
|
44
49
|
const addErrorSpy = jest.spyOn(workspaceContext, "addError");
|
|
45
50
|
|
|
46
51
|
function check(options: Options = { matchDependencyVersions: {} }) {
|
|
47
52
|
consistentVersions.check(workspaceContext, options);
|
|
48
53
|
}
|
|
49
54
|
|
|
50
|
-
return { addErrorSpy, check };
|
|
55
|
+
return { addErrorSpy, check, host };
|
|
51
56
|
}
|
|
52
57
|
|
|
53
|
-
function addPackageJson(filePath: string, packageJson: PackageJson) {
|
|
58
|
+
function addPackageJson(host: Host, filePath: string, packageJson: PackageJson) {
|
|
54
59
|
const dirPath = path.resolve(cwd!, path.dirname(filePath));
|
|
55
60
|
const resolvedFilePath = path.resolve(cwd!, filePath);
|
|
56
61
|
|
|
57
62
|
makeDirectoryRecursively(dirPath);
|
|
58
|
-
writeJson(resolvedFilePath, packageJson);
|
|
63
|
+
host.writeJson(resolvedFilePath, packageJson);
|
|
59
64
|
return (): PackageJson => {
|
|
60
|
-
return readJson(resolvedFilePath);
|
|
65
|
+
return host.readJson(resolvedFilePath);
|
|
61
66
|
};
|
|
62
67
|
}
|
|
63
68
|
|
|
@@ -82,8 +87,8 @@ describe("consistentVersions", () => {
|
|
|
82
87
|
});
|
|
83
88
|
|
|
84
89
|
it("Does nothing when arguments are empty", async () => {
|
|
85
|
-
const { addErrorSpy, check } = makeWorkspace();
|
|
86
|
-
addPackageJson("./package.json", testPackageJson);
|
|
90
|
+
const { addErrorSpy, check, host } = makeWorkspace();
|
|
91
|
+
addPackageJson(host, "./package.json", testPackageJson);
|
|
87
92
|
|
|
88
93
|
check();
|
|
89
94
|
expect(addErrorSpy).toHaveBeenCalledTimes(0);
|
|
@@ -92,8 +97,8 @@ describe("consistentVersions", () => {
|
|
|
92
97
|
});
|
|
93
98
|
|
|
94
99
|
it("Fixes packages that have an incorrect dependency version", async () => {
|
|
95
|
-
const { addErrorSpy, check } = makeWorkspace(true);
|
|
96
|
-
const readTestPackageJson = addPackageJson("./package.json", testPackageJson);
|
|
100
|
+
const { addErrorSpy, check, host } = makeWorkspace(true);
|
|
101
|
+
const readTestPackageJson = addPackageJson(host, "./package.json", testPackageJson);
|
|
97
102
|
|
|
98
103
|
const requiredGreatLibVersion = "1.2.3";
|
|
99
104
|
expect(addErrorSpy).toHaveBeenCalledTimes(0);
|
|
@@ -105,8 +110,8 @@ describe("consistentVersions", () => {
|
|
|
105
110
|
});
|
|
106
111
|
|
|
107
112
|
it("Ignores packages that have a correct dependency version", async () => {
|
|
108
|
-
const { addErrorSpy, check } = makeWorkspace();
|
|
109
|
-
addPackageJson("./package.json", testPackageJson);
|
|
113
|
+
const { addErrorSpy, check, host } = makeWorkspace();
|
|
114
|
+
addPackageJson(host, "./package.json", testPackageJson);
|
|
110
115
|
|
|
111
116
|
expect(addErrorSpy).toHaveBeenCalledTimes(0);
|
|
112
117
|
check({
|
|
@@ -119,8 +124,8 @@ describe("consistentVersions", () => {
|
|
|
119
124
|
});
|
|
120
125
|
|
|
121
126
|
it("Fixes packages that have an incorrect devDependency version", async () => {
|
|
122
|
-
const { addErrorSpy, check } = makeWorkspace(true);
|
|
123
|
-
const readTestPackageJson = addPackageJson("./package.json", testPackageJson);
|
|
127
|
+
const { addErrorSpy, check, host } = makeWorkspace(true);
|
|
128
|
+
const readTestPackageJson = addPackageJson(host, "./package.json", testPackageJson);
|
|
124
129
|
|
|
125
130
|
const requiredElseLibVersion = "1.2.3";
|
|
126
131
|
expect(addErrorSpy).toHaveBeenCalledTimes(0);
|
|
@@ -130,8 +135,8 @@ describe("consistentVersions", () => {
|
|
|
130
135
|
});
|
|
131
136
|
|
|
132
137
|
it("Ignores packages that have a correct devDependency version", async () => {
|
|
133
|
-
const { addErrorSpy, check } = makeWorkspace();
|
|
134
|
-
addPackageJson("./package.json", testPackageJson);
|
|
138
|
+
const { addErrorSpy, check, host } = makeWorkspace();
|
|
139
|
+
addPackageJson(host, "./package.json", testPackageJson);
|
|
135
140
|
|
|
136
141
|
expect(addErrorSpy).toHaveBeenCalledTimes(0);
|
|
137
142
|
check({
|
|
@@ -144,8 +149,8 @@ describe("consistentVersions", () => {
|
|
|
144
149
|
});
|
|
145
150
|
|
|
146
151
|
it("Fixes packages that have an incorrect dependency and devDependency versions", async () => {
|
|
147
|
-
const { addErrorSpy, check } = makeWorkspace(true);
|
|
148
|
-
const readTestPackageJson = addPackageJson("./package.json", testPackageJson);
|
|
152
|
+
const { addErrorSpy, check, host } = makeWorkspace(true);
|
|
153
|
+
const readTestPackageJson = addPackageJson(host, "./package.json", testPackageJson);
|
|
149
154
|
|
|
150
155
|
const requiredBothVersion = "1.2.3";
|
|
151
156
|
expect(addErrorSpy).toHaveBeenCalledTimes(0);
|
|
@@ -177,8 +182,8 @@ describe("consistentVersions", () => {
|
|
|
177
182
|
});
|
|
178
183
|
|
|
179
184
|
it("Accepts a match when multiple versions are configured", async () => {
|
|
180
|
-
const { addErrorSpy, check } = makeWorkspace();
|
|
181
|
-
addPackageJson("./package.json", testPackageJson);
|
|
185
|
+
const { addErrorSpy, check, host } = makeWorkspace();
|
|
186
|
+
addPackageJson(host, "./package.json", testPackageJson);
|
|
182
187
|
|
|
183
188
|
expect(addErrorSpy).toHaveBeenCalledTimes(0);
|
|
184
189
|
check({ matchDependencyVersions: { greatLib: [testPackageJson.dependencies!.greatLib] } });
|
|
@@ -192,8 +197,8 @@ describe("consistentVersions", () => {
|
|
|
192
197
|
});
|
|
193
198
|
|
|
194
199
|
it("Errors when version does not match", async () => {
|
|
195
|
-
const { addErrorSpy, check } = makeWorkspace();
|
|
196
|
-
addPackageJson("./package.json", testPackageJson);
|
|
200
|
+
const { addErrorSpy, check, host } = makeWorkspace();
|
|
201
|
+
addPackageJson(host, "./package.json", testPackageJson);
|
|
197
202
|
|
|
198
203
|
expect(addErrorSpy).toHaveBeenCalledTimes(0);
|
|
199
204
|
check({ matchDependencyVersions: { greatLib: ["1", "2"] } });
|
|
@@ -6,41 +6,31 @@
|
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
8
|
// tslint:disable:no-console
|
|
9
|
-
import {
|
|
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 * as path from "path";
|
|
9
|
+
import { createTestingWorkspace, HOST_FACTORIES, TestingWorkspace } from "./utils";
|
|
10
|
+
import { AddErrorOptions, Failure } from "@monorepolint/core";
|
|
16
11
|
import { fileContents } from "../fileContents";
|
|
17
12
|
|
|
18
13
|
const EXPECTED_FOO_FILE = "hello world";
|
|
19
14
|
|
|
20
|
-
describe("fileContents", () => {
|
|
21
|
-
afterEach(() => {
|
|
22
|
-
mockFiles.clear();
|
|
23
|
-
});
|
|
24
|
-
|
|
15
|
+
describe.each(HOST_FACTORIES)("fileContents ($name)", (hostFactory) => {
|
|
25
16
|
describe("fix: true", () => {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
17
|
+
let workspace: TestingWorkspace;
|
|
18
|
+
let spy: jest.SpyInstance<void, [AddErrorOptions]>;
|
|
19
|
+
|
|
20
|
+
beforeEach(async () => {
|
|
21
|
+
workspace = await createTestingWorkspace({
|
|
22
|
+
fixFlag: true,
|
|
23
|
+
host: hostFactory.make(),
|
|
24
|
+
});
|
|
25
|
+
workspace.writeFile("shared/foo-template.txt", EXPECTED_FOO_FILE);
|
|
33
26
|
|
|
34
|
-
|
|
35
|
-
spy.mockClear();
|
|
27
|
+
spy = jest.spyOn(workspace.context, "addError");
|
|
36
28
|
});
|
|
37
29
|
|
|
38
30
|
it("fixes missing file", () => {
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
fileContents.check(context, {
|
|
31
|
+
fileContents.check(workspace.context, {
|
|
42
32
|
file: "foo.txt",
|
|
43
|
-
templateFile: "foo-template.txt",
|
|
33
|
+
templateFile: "shared/foo-template.txt",
|
|
44
34
|
generator: undefined,
|
|
45
35
|
template: undefined,
|
|
46
36
|
});
|
|
@@ -48,20 +38,19 @@ describe("fileContents", () => {
|
|
|
48
38
|
expect(spy).toHaveBeenCalledTimes(1);
|
|
49
39
|
|
|
50
40
|
const failure: Failure = spy.mock.calls[0][0];
|
|
51
|
-
expect(failure
|
|
52
|
-
|
|
53
|
-
|
|
41
|
+
expect(failure).toMatchObject(
|
|
42
|
+
workspace.failureMatcher({
|
|
43
|
+
file: "foo.txt",
|
|
44
|
+
hasFixer: true,
|
|
45
|
+
message: "Expect file contents to match",
|
|
46
|
+
})
|
|
47
|
+
);
|
|
54
48
|
|
|
55
|
-
expect(
|
|
49
|
+
expect(workspace.readFile("foo.txt")).toEqual(EXPECTED_FOO_FILE);
|
|
56
50
|
});
|
|
57
51
|
|
|
58
52
|
it("fixes missing nested file", () => {
|
|
59
|
-
|
|
60
|
-
path.resolve(context.getWorkspaceContext().packageDir, "shared/foo-template.txt"),
|
|
61
|
-
EXPECTED_FOO_FILE
|
|
62
|
-
);
|
|
63
|
-
|
|
64
|
-
fileContents.check(context, {
|
|
53
|
+
fileContents.check(workspace.context, {
|
|
65
54
|
file: "nested/foo.txt",
|
|
66
55
|
templateFile: "shared/foo-template.txt",
|
|
67
56
|
generator: undefined,
|
|
@@ -71,12 +60,15 @@ describe("fileContents", () => {
|
|
|
71
60
|
expect(spy).toHaveBeenCalledTimes(1);
|
|
72
61
|
|
|
73
62
|
const failure: Failure = spy.mock.calls[0][0];
|
|
74
|
-
expect(failure
|
|
75
|
-
|
|
76
|
-
|
|
63
|
+
expect(failure).toMatchObject(
|
|
64
|
+
workspace.failureMatcher({
|
|
65
|
+
file: "nested/foo.txt",
|
|
66
|
+
hasFixer: true,
|
|
67
|
+
message: "Expect file contents to match",
|
|
68
|
+
})
|
|
69
|
+
);
|
|
77
70
|
|
|
78
|
-
expect(
|
|
79
|
-
expect(mockFiles.get("nested/foo.txt")).toEqual(EXPECTED_FOO_FILE);
|
|
71
|
+
expect(workspace.readFile("nested/foo.txt")).toEqual(EXPECTED_FOO_FILE);
|
|
80
72
|
});
|
|
81
73
|
});
|
|
82
74
|
});
|