@monorepolint/rules 0.6.0-alpha.1 → 0.6.0-alpha.3
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/.turbo/turbo-clean.log +1 -1
- package/.turbo/turbo-compile-typescript.log +1 -1
- package/.turbo/turbo-lint.log +1 -1
- package/.turbo/turbo-test.log +272 -667
- package/.turbo/turbo-transpile-typescript.log +5 -5
- package/CHANGELOG.md +42 -0
- package/build/js/index.js +411 -263
- package/build/js/index.js.map +1 -1
- package/build/tsconfig.tsbuildinfo +1 -1
- package/build/types/__tests__/utils.d.ts +4 -10
- package/build/types/__tests__/utils.d.ts.map +1 -1
- package/build/types/bannedDependencies.d.ts.map +1 -1
- package/build/types/fileContents.d.ts +1 -1
- package/build/types/fileContents.d.ts.map +1 -1
- package/build/types/index.d.ts +3 -3
- package/build/types/index.d.ts.map +1 -1
- package/build/types/mustSatisfyPeerDependencies.d.ts.map +1 -1
- package/build/types/nestedWorkspaces.d.ts.map +1 -1
- package/build/types/packageEntry.d.ts.map +1 -1
- package/build/types/packageOrder.d.ts.map +1 -1
- package/build/types/packageScript.d.ts.map +1 -1
- package/build/types/requireDependency.d.ts +12 -12
- package/build/types/requireDependency.d.ts.map +1 -1
- package/build/types/standardTsconfig.d.ts.map +1 -1
- package/build/types/util/checkAlpha.d.ts.map +1 -1
- package/build/types/util/createRuleFactory.d.ts.map +1 -1
- package/build/types/util/packageDependencyGraphService.d.ts.map +1 -1
- package/coverage/base.css +224 -0
- package/coverage/block-navigation.js +87 -0
- package/coverage/clover.xml +1887 -0
- package/coverage/coverage-final.json +19 -0
- package/coverage/favicon.png +0 -0
- package/coverage/index.html +131 -0
- package/coverage/prettify.css +1 -0
- package/coverage/prettify.js +2 -0
- package/coverage/sort-arrow-sprite.png +0 -0
- package/coverage/sorter.js +196 -0
- package/coverage/src/alphabeticalDependencies.ts.html +142 -0
- package/coverage/src/alphabeticalScripts.ts.html +136 -0
- package/coverage/src/bannedDependencies.ts.html +610 -0
- package/coverage/src/consistentDependencies.ts.html +394 -0
- package/coverage/src/consistentVersions.ts.html +619 -0
- package/coverage/src/fileContents.ts.html +409 -0
- package/coverage/src/index.html +311 -0
- package/coverage/src/index.ts.html +169 -0
- package/coverage/src/mustSatisfyPeerDependencies.ts.html +2605 -0
- package/coverage/src/nestedWorkspaces.ts.html +304 -0
- package/coverage/src/packageEntry.ts.html +376 -0
- package/coverage/src/packageOrder.ts.html +472 -0
- package/coverage/src/packageScript.ts.html +436 -0
- package/coverage/src/requireDependency.ts.html +349 -0
- package/coverage/src/standardTsconfig.ts.html +553 -0
- package/coverage/src/util/checkAlpha.ts.html +271 -0
- package/coverage/src/util/createRuleFactory.ts.html +196 -0
- package/coverage/src/util/index.html +161 -0
- package/coverage/src/util/makeDirectory.ts.html +157 -0
- package/coverage/src/util/packageDependencyGraphService.ts.html +508 -0
- package/package.json +15 -20
- package/src/__tests__/alphabeticalScripts.spec.ts +13 -5
- package/src/__tests__/bannedDependencies.spec.ts +47 -18
- package/src/__tests__/consistentDependencies.spec.ts +12 -6
- package/src/__tests__/consistentVersions.spec.ts +74 -20
- package/src/__tests__/fileContents.spec.ts +11 -7
- package/src/__tests__/mustSatisfyPeerDependencies.spec.ts +193 -78
- package/src/__tests__/nestedWorkspaces.spec.ts +12 -8
- package/src/__tests__/packageEntry.spec.ts +55 -49
- package/src/__tests__/packageOrder.spec.ts +78 -72
- package/src/__tests__/packageScript.spec.ts +27 -13
- package/src/__tests__/requireDependency.spec.ts +13 -7
- package/src/__tests__/utils.ts +18 -9
- package/src/bannedDependencies.ts +32 -15
- package/src/consistentDependencies.ts +22 -9
- package/src/consistentVersions.ts +84 -47
- package/src/fileContents.ts +24 -10
- package/src/index.ts +3 -3
- package/src/mustSatisfyPeerDependencies.ts +162 -66
- package/src/nestedWorkspaces.ts +23 -10
- package/src/packageEntry.ts +18 -11
- package/src/packageOrder.ts +9 -3
- package/src/packageScript.ts +37 -19
- package/src/requireDependency.ts +28 -11
- package/src/standardTsconfig.ts +32 -10
- package/src/util/checkAlpha.ts +5 -2
- package/src/util/createRuleFactory.ts +6 -2
- package/src/util/packageDependencyGraphService.ts +41 -14
- package/vitest.config.mjs +17 -0
- package/jest.config.cjs +0 -4
|
@@ -8,50 +8,56 @@
|
|
|
8
8
|
// tslint:disable:no-console
|
|
9
9
|
|
|
10
10
|
import { Context, Failure } from "@monorepolint/config";
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
11
|
+
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
|
12
|
+
import {
|
|
13
|
+
createExpectedEntryErrorMessage,
|
|
14
|
+
createStandardizedEntryErrorMessage,
|
|
15
|
+
packageEntry,
|
|
16
|
+
} from "../packageEntry.js";
|
|
17
|
+
import {
|
|
18
|
+
AddErrorSpy,
|
|
19
|
+
createTestingWorkspace,
|
|
20
|
+
HOST_FACTORIES,
|
|
21
|
+
TestingWorkspace,
|
|
22
|
+
} from "./utils.js";
|
|
23
|
+
|
|
24
|
+
const PACKAGE_MISSING_ENTRY = JSON.stringify(
|
|
25
|
+
{
|
|
26
|
+
name: "package",
|
|
27
|
+
version: {},
|
|
28
|
+
scripts: {},
|
|
29
|
+
dependencies: {},
|
|
30
|
+
},
|
|
31
|
+
undefined,
|
|
32
|
+
2,
|
|
33
|
+
) + "\n";
|
|
34
|
+
|
|
35
|
+
const PACKAGE_LICENSE = JSON.stringify(
|
|
36
|
+
{
|
|
37
|
+
name: "package",
|
|
38
|
+
version: {},
|
|
39
|
+
scripts: {},
|
|
40
|
+
dependencies: {},
|
|
41
|
+
license: "UNLICENSED",
|
|
42
|
+
},
|
|
43
|
+
undefined,
|
|
44
|
+
2,
|
|
45
|
+
) + "\n";
|
|
46
|
+
|
|
47
|
+
const PACKAGE_REPOSITORY = JSON.stringify(
|
|
48
|
+
{
|
|
49
|
+
name: "package",
|
|
50
|
+
version: {},
|
|
51
|
+
scripts: {},
|
|
52
|
+
dependencies: {},
|
|
53
|
+
repository: {
|
|
54
|
+
type: "git",
|
|
55
|
+
url: "https://github.com:foo/foo",
|
|
22
56
|
},
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
const PACKAGE_LICENSE =
|
|
28
|
-
JSON.stringify(
|
|
29
|
-
{
|
|
30
|
-
name: "package",
|
|
31
|
-
version: {},
|
|
32
|
-
scripts: {},
|
|
33
|
-
dependencies: {},
|
|
34
|
-
license: "UNLICENSED",
|
|
35
|
-
},
|
|
36
|
-
undefined,
|
|
37
|
-
2
|
|
38
|
-
) + "\n";
|
|
39
|
-
|
|
40
|
-
const PACKAGE_REPOSITORY =
|
|
41
|
-
JSON.stringify(
|
|
42
|
-
{
|
|
43
|
-
name: "package",
|
|
44
|
-
version: {},
|
|
45
|
-
scripts: {},
|
|
46
|
-
dependencies: {},
|
|
47
|
-
repository: {
|
|
48
|
-
type: "git",
|
|
49
|
-
url: "https://github.com:foo/foo",
|
|
50
|
-
},
|
|
51
|
-
},
|
|
52
|
-
undefined,
|
|
53
|
-
2
|
|
54
|
-
) + "\n";
|
|
57
|
+
},
|
|
58
|
+
undefined,
|
|
59
|
+
2,
|
|
60
|
+
) + "\n";
|
|
55
61
|
|
|
56
62
|
describe.each(HOST_FACTORIES)("expectPackageEntries ($name)", (hostFactory) => {
|
|
57
63
|
describe("fix: true", () => {
|
|
@@ -66,7 +72,7 @@ describe.each(HOST_FACTORIES)("expectPackageEntries ($name)", (hostFactory) => {
|
|
|
66
72
|
});
|
|
67
73
|
context = workspace.context; // minimizing delta
|
|
68
74
|
|
|
69
|
-
spy =
|
|
75
|
+
spy = vi.spyOn(workspace.context, "addError");
|
|
70
76
|
});
|
|
71
77
|
|
|
72
78
|
afterEach(() => {
|
|
@@ -93,7 +99,7 @@ describe.each(HOST_FACTORIES)("expectPackageEntries ($name)", (hostFactory) => {
|
|
|
93
99
|
file: "package.json",
|
|
94
100
|
hasFixer: true,
|
|
95
101
|
message: createStandardizedEntryErrorMessage("license"),
|
|
96
|
-
})
|
|
102
|
+
}),
|
|
97
103
|
);
|
|
98
104
|
|
|
99
105
|
expect(workspace.readFile("package.json")).toEqual(PACKAGE_LICENSE);
|
|
@@ -122,7 +128,7 @@ describe.each(HOST_FACTORIES)("expectPackageEntries ($name)", (hostFactory) => {
|
|
|
122
128
|
file: "package.json",
|
|
123
129
|
hasFixer: true,
|
|
124
130
|
message: createStandardizedEntryErrorMessage("repository"),
|
|
125
|
-
})
|
|
131
|
+
}),
|
|
126
132
|
);
|
|
127
133
|
|
|
128
134
|
expect(workspace.readFile("package.json")).toEqual(PACKAGE_REPOSITORY);
|
|
@@ -165,7 +171,7 @@ describe.each(HOST_FACTORIES)("expectPackageEntries ($name)", (hostFactory) => {
|
|
|
165
171
|
file: "package.json",
|
|
166
172
|
hasFixer: false,
|
|
167
173
|
message: createExpectedEntryErrorMessage("bugs"),
|
|
168
|
-
})
|
|
174
|
+
}),
|
|
169
175
|
);
|
|
170
176
|
expect(workspace.readFile("package.json")).toEqual(PACKAGE_REPOSITORY);
|
|
171
177
|
});
|
|
@@ -193,7 +199,7 @@ describe.each(HOST_FACTORIES)("expectPackageEntries ($name)", (hostFactory) => {
|
|
|
193
199
|
file: "package.json",
|
|
194
200
|
hasFixer: true,
|
|
195
201
|
message: createStandardizedEntryErrorMessage("repository"),
|
|
196
|
-
})
|
|
202
|
+
}),
|
|
197
203
|
);
|
|
198
204
|
|
|
199
205
|
const failure2: Failure = spy.mock.calls[1][0];
|
|
@@ -202,7 +208,7 @@ describe.each(HOST_FACTORIES)("expectPackageEntries ($name)", (hostFactory) => {
|
|
|
202
208
|
file: "package.json",
|
|
203
209
|
hasFixer: false,
|
|
204
210
|
message: createExpectedEntryErrorMessage("bugs"),
|
|
205
|
-
})
|
|
211
|
+
}),
|
|
206
212
|
);
|
|
207
213
|
|
|
208
214
|
expect(workspace.readFile("package.json")).toEqual(PACKAGE_REPOSITORY);
|
|
@@ -6,36 +6,39 @@
|
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
8
|
// tslint:disable:no-console
|
|
9
|
-
import { AddErrorSpy, createTestingWorkspace, HOST_FACTORIES, TestingWorkspace } from "./utils.js";
|
|
10
9
|
import { Context, Failure } from "@monorepolint/config";
|
|
10
|
+
import { beforeEach, describe, expect, it, vi } from "vitest";
|
|
11
11
|
import { packageOrder } from "../packageOrder.js";
|
|
12
|
-
import {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
},
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
},
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
12
|
+
import {
|
|
13
|
+
AddErrorSpy,
|
|
14
|
+
createTestingWorkspace,
|
|
15
|
+
HOST_FACTORIES,
|
|
16
|
+
TestingWorkspace,
|
|
17
|
+
} from "./utils.js";
|
|
18
|
+
|
|
19
|
+
const PACKAGE_UNORDERED = JSON.stringify(
|
|
20
|
+
{
|
|
21
|
+
scripts: {},
|
|
22
|
+
dependencies: {},
|
|
23
|
+
version: {},
|
|
24
|
+
name: "package",
|
|
25
|
+
},
|
|
26
|
+
undefined,
|
|
27
|
+
2,
|
|
28
|
+
) + "\n";
|
|
29
|
+
|
|
30
|
+
const PACKAGE_UNORDERED_UNKOWN_KEYS = JSON.stringify(
|
|
31
|
+
{
|
|
32
|
+
butter: false,
|
|
33
|
+
apple: false,
|
|
34
|
+
scripts: {},
|
|
35
|
+
dependencies: {},
|
|
36
|
+
version: {},
|
|
37
|
+
name: "package-unknown-keys",
|
|
38
|
+
},
|
|
39
|
+
undefined,
|
|
40
|
+
2,
|
|
41
|
+
) + "\n";
|
|
39
42
|
|
|
40
43
|
const orderArray = ["name", "version", "scripts", "dependencies"];
|
|
41
44
|
|
|
@@ -44,43 +47,40 @@ const orderFunction = (_context: Context) => (a: string, b: string) => {
|
|
|
44
47
|
return b.length - a.length || a.localeCompare(b);
|
|
45
48
|
};
|
|
46
49
|
|
|
47
|
-
const PACKAGE_ORDERED =
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
{
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
{
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
undefined,
|
|
82
|
-
2
|
|
83
|
-
) + "\n";
|
|
50
|
+
const PACKAGE_ORDERED = JSON.stringify(
|
|
51
|
+
{
|
|
52
|
+
name: "package",
|
|
53
|
+
version: {},
|
|
54
|
+
scripts: {},
|
|
55
|
+
dependencies: {},
|
|
56
|
+
},
|
|
57
|
+
undefined,
|
|
58
|
+
2,
|
|
59
|
+
) + "\n";
|
|
60
|
+
|
|
61
|
+
const PACKAGE_ORDERED_BY_LENGTH = JSON.stringify(
|
|
62
|
+
{
|
|
63
|
+
dependencies: {},
|
|
64
|
+
scripts: {},
|
|
65
|
+
version: {},
|
|
66
|
+
name: "package",
|
|
67
|
+
},
|
|
68
|
+
undefined,
|
|
69
|
+
2,
|
|
70
|
+
) + "\n";
|
|
71
|
+
|
|
72
|
+
const PACKAGE_ORDERED_UNKOWN_KEYS = JSON.stringify(
|
|
73
|
+
{
|
|
74
|
+
name: "package-unknown-keys",
|
|
75
|
+
version: {},
|
|
76
|
+
scripts: {},
|
|
77
|
+
dependencies: {},
|
|
78
|
+
apple: false,
|
|
79
|
+
butter: false,
|
|
80
|
+
},
|
|
81
|
+
undefined,
|
|
82
|
+
2,
|
|
83
|
+
) + "\n";
|
|
84
84
|
|
|
85
85
|
describe.each(HOST_FACTORIES)("expectPackageOrder ($name)", (hostFactory) => {
|
|
86
86
|
describe("fix: true", () => {
|
|
@@ -95,7 +95,7 @@ describe.each(HOST_FACTORIES)("expectPackageOrder ($name)", (hostFactory) => {
|
|
|
95
95
|
});
|
|
96
96
|
context = workspace.context; // minimizing delta
|
|
97
97
|
|
|
98
|
-
spy =
|
|
98
|
+
spy = vi.spyOn(workspace.context, "addError");
|
|
99
99
|
});
|
|
100
100
|
|
|
101
101
|
it("fixes order for expected keys", () => {
|
|
@@ -115,7 +115,7 @@ describe.each(HOST_FACTORIES)("expectPackageOrder ($name)", (hostFactory) => {
|
|
|
115
115
|
file: "package.json",
|
|
116
116
|
hasFixer: true,
|
|
117
117
|
message: "Incorrect order of fields in package.json",
|
|
118
|
-
})
|
|
118
|
+
}),
|
|
119
119
|
);
|
|
120
120
|
|
|
121
121
|
expect(workspace.readFile("package.json")).toEqual(PACKAGE_ORDERED);
|
|
@@ -138,10 +138,12 @@ describe.each(HOST_FACTORIES)("expectPackageOrder ($name)", (hostFactory) => {
|
|
|
138
138
|
file: "package.json",
|
|
139
139
|
hasFixer: true,
|
|
140
140
|
message: "Incorrect order of fields in package.json",
|
|
141
|
-
})
|
|
141
|
+
}),
|
|
142
142
|
);
|
|
143
143
|
|
|
144
|
-
expect(workspace.readFile("package.json")).toEqual(
|
|
144
|
+
expect(workspace.readFile("package.json")).toEqual(
|
|
145
|
+
PACKAGE_ORDERED_UNKOWN_KEYS,
|
|
146
|
+
);
|
|
145
147
|
});
|
|
146
148
|
|
|
147
149
|
it("fixes order using function", () => {
|
|
@@ -161,10 +163,12 @@ describe.each(HOST_FACTORIES)("expectPackageOrder ($name)", (hostFactory) => {
|
|
|
161
163
|
file: "package.json",
|
|
162
164
|
hasFixer: true,
|
|
163
165
|
message: "Incorrect order of fields in package.json",
|
|
164
|
-
})
|
|
166
|
+
}),
|
|
165
167
|
);
|
|
166
168
|
|
|
167
|
-
expect(workspace.readFile("package.json")).toEqual(
|
|
169
|
+
expect(workspace.readFile("package.json")).toEqual(
|
|
170
|
+
PACKAGE_ORDERED_BY_LENGTH,
|
|
171
|
+
);
|
|
168
172
|
});
|
|
169
173
|
|
|
170
174
|
it("does nothing if already order", () => {
|
|
@@ -178,7 +182,9 @@ describe.each(HOST_FACTORIES)("expectPackageOrder ($name)", (hostFactory) => {
|
|
|
178
182
|
|
|
179
183
|
expect(spy).not.toHaveBeenCalled();
|
|
180
184
|
|
|
181
|
-
expect(workspace.readFile("package.json")).toEqual(
|
|
185
|
+
expect(workspace.readFile("package.json")).toEqual(
|
|
186
|
+
PACKAGE_ORDERED_UNKOWN_KEYS,
|
|
187
|
+
);
|
|
182
188
|
});
|
|
183
189
|
});
|
|
184
190
|
});
|
|
@@ -6,10 +6,15 @@
|
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
8
|
// tslint:disable:no-console
|
|
9
|
-
import { describe, expect, it, beforeEach, jest } from "@jest/globals";
|
|
10
9
|
import { Context, Failure } from "@monorepolint/config";
|
|
10
|
+
import { beforeEach, describe, expect, it, vi } from "vitest";
|
|
11
11
|
import { packageScript } from "../packageScript.js";
|
|
12
|
-
import {
|
|
12
|
+
import {
|
|
13
|
+
AddErrorSpy,
|
|
14
|
+
createTestingWorkspace,
|
|
15
|
+
HOST_FACTORIES,
|
|
16
|
+
TestingWorkspace,
|
|
17
|
+
} from "./utils.js";
|
|
13
18
|
|
|
14
19
|
const json = (a: unknown) => JSON.stringify(a, undefined, 2) + "\n";
|
|
15
20
|
|
|
@@ -41,7 +46,7 @@ describe.each(HOST_FACTORIES)("expectPackageScript ($name)", (hostFactory) => {
|
|
|
41
46
|
host: hostFactory.make(),
|
|
42
47
|
});
|
|
43
48
|
|
|
44
|
-
spy =
|
|
49
|
+
spy = vi.spyOn(workspace.context, "addError");
|
|
45
50
|
});
|
|
46
51
|
|
|
47
52
|
it("handles an empty script section", () => {
|
|
@@ -63,7 +68,7 @@ describe.each(HOST_FACTORIES)("expectPackageScript ($name)", (hostFactory) => {
|
|
|
63
68
|
file: "package.json",
|
|
64
69
|
hasFixer: true,
|
|
65
70
|
message: "No scripts block in package.json",
|
|
66
|
-
})
|
|
71
|
+
}),
|
|
67
72
|
);
|
|
68
73
|
});
|
|
69
74
|
});
|
|
@@ -79,7 +84,7 @@ describe.each(HOST_FACTORIES)("expectPackageScript ($name)", (hostFactory) => {
|
|
|
79
84
|
host: hostFactory.make(),
|
|
80
85
|
});
|
|
81
86
|
|
|
82
|
-
spy =
|
|
87
|
+
spy = vi.spyOn(workspace.context, "addError");
|
|
83
88
|
context = workspace.context; // minimizing delta
|
|
84
89
|
});
|
|
85
90
|
|
|
@@ -102,10 +107,12 @@ describe.each(HOST_FACTORIES)("expectPackageScript ($name)", (hostFactory) => {
|
|
|
102
107
|
file: "package.json",
|
|
103
108
|
hasFixer: true,
|
|
104
109
|
message: "No scripts block in package.json",
|
|
105
|
-
})
|
|
110
|
+
}),
|
|
106
111
|
);
|
|
107
112
|
|
|
108
|
-
expect(JSON.parse(workspace.readFile("package.json")!).scripts).toEqual(
|
|
113
|
+
expect(JSON.parse(workspace.readFile("package.json")!).scripts).toEqual(
|
|
114
|
+
{},
|
|
115
|
+
);
|
|
109
116
|
});
|
|
110
117
|
|
|
111
118
|
it("adds a script", () => {
|
|
@@ -127,13 +134,16 @@ describe.each(HOST_FACTORIES)("expectPackageScript ($name)", (hostFactory) => {
|
|
|
127
134
|
file: "package.json",
|
|
128
135
|
hasFixer: true,
|
|
129
136
|
message: expect.stringContaining(
|
|
130
|
-
`Expected standardized script entry for '${MISSING_SCRIPT_NAME}'
|
|
137
|
+
`Expected standardized script entry for '${MISSING_SCRIPT_NAME}'`,
|
|
131
138
|
) as unknown as string,
|
|
132
|
-
})
|
|
139
|
+
}),
|
|
133
140
|
);
|
|
134
141
|
|
|
135
|
-
expect(
|
|
136
|
-
|
|
142
|
+
expect(
|
|
143
|
+
JSON.parse(workspace.readFile("package.json")!)
|
|
144
|
+
.scripts[MISSING_SCRIPT_NAME],
|
|
145
|
+
).toEqual(
|
|
146
|
+
MISSING_SCRIPT_VALUE,
|
|
137
147
|
);
|
|
138
148
|
});
|
|
139
149
|
|
|
@@ -218,7 +228,9 @@ describe.each(HOST_FACTORIES)("expectPackageScript ($name)", (hostFactory) => {
|
|
|
218
228
|
expect(errors.length).toBe(1);
|
|
219
229
|
expect(errors[0][0].fixer).toBeDefined();
|
|
220
230
|
|
|
221
|
-
expect(JSON.parse(workspace.readFile("package.json")!).scripts).toEqual(
|
|
231
|
+
expect(JSON.parse(workspace.readFile("package.json")!).scripts).toEqual(
|
|
232
|
+
{},
|
|
233
|
+
);
|
|
222
234
|
});
|
|
223
235
|
|
|
224
236
|
it("can allow only empty", () => {
|
|
@@ -240,7 +252,9 @@ describe.each(HOST_FACTORIES)("expectPackageScript ($name)", (hostFactory) => {
|
|
|
240
252
|
expect(errors.length).toBe(1);
|
|
241
253
|
expect(errors[0][0].fixer).toBeDefined();
|
|
242
254
|
|
|
243
|
-
expect(JSON.parse(workspace.readFile("package.json")!).scripts).toEqual(
|
|
255
|
+
expect(JSON.parse(workspace.readFile("package.json")!).scripts).toEqual(
|
|
256
|
+
{},
|
|
257
|
+
);
|
|
244
258
|
});
|
|
245
259
|
});
|
|
246
260
|
});
|
|
@@ -9,10 +9,10 @@ import { SimpleHost } from "@monorepolint/utils";
|
|
|
9
9
|
import { readFileSync, writeFileSync } from "node:fs";
|
|
10
10
|
import * as path from "node:path";
|
|
11
11
|
import * as tmp from "tmp";
|
|
12
|
+
import { afterEach, describe, expect, it, vi } from "vitest";
|
|
12
13
|
import { requireDependency } from "../requireDependency.js";
|
|
13
14
|
import { makeDirectoryRecursively } from "../util/makeDirectory.js";
|
|
14
15
|
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: {
|
|
@@ -36,6 +36,7 @@ const PACKAGE_WITH_WRONG_ENTRIES = jsonToString({
|
|
|
36
36
|
},
|
|
37
37
|
devDependencies: {
|
|
38
38
|
bar: "1.0.0",
|
|
39
|
+
baz: "1.0.0",
|
|
39
40
|
},
|
|
40
41
|
});
|
|
41
42
|
|
|
@@ -54,6 +55,7 @@ const OPTIONS = {
|
|
|
54
55
|
},
|
|
55
56
|
devDependencies: {
|
|
56
57
|
bar: "^2.0.0",
|
|
58
|
+
baz: undefined,
|
|
57
59
|
},
|
|
58
60
|
} as const;
|
|
59
61
|
|
|
@@ -83,12 +85,14 @@ describe("requireDependency", () => {
|
|
|
83
85
|
verbose: false,
|
|
84
86
|
silent: true,
|
|
85
87
|
},
|
|
86
|
-
new SimpleHost()
|
|
88
|
+
new SimpleHost(),
|
|
87
89
|
);
|
|
88
90
|
|
|
89
91
|
function checkAndSpy(q: string) {
|
|
90
|
-
const context = workspaceContext.createChildContext(
|
|
91
|
-
|
|
92
|
+
const context = workspaceContext.createChildContext(
|
|
93
|
+
path.resolve(dir.name, q),
|
|
94
|
+
);
|
|
95
|
+
const addErrorSpy = vi.spyOn(context, "addError");
|
|
92
96
|
requireDependency({ options: OPTIONS }).check(context);
|
|
93
97
|
return { context, addErrorSpy };
|
|
94
98
|
}
|
|
@@ -109,7 +113,9 @@ describe("requireDependency", () => {
|
|
|
109
113
|
}
|
|
110
114
|
|
|
111
115
|
it("checks correctly", () => {
|
|
112
|
-
const { addFile, workspaceContext, checkAndSpy } = makeWorkspace({
|
|
116
|
+
const { addFile, workspaceContext, checkAndSpy } = makeWorkspace({
|
|
117
|
+
fix: false,
|
|
118
|
+
});
|
|
113
119
|
addFile("./package.json", PACKAGE_ROOT);
|
|
114
120
|
addFile("./packages/none/package.json", PACKAGE_WITH_NO_ENTRIES);
|
|
115
121
|
addFile("./packages/missing/package.json", PACKAGE_WITH_ENTRIES_MISSING);
|
|
@@ -125,7 +131,7 @@ describe("requireDependency", () => {
|
|
|
125
131
|
expect(missing.addErrorSpy).toHaveBeenCalledTimes(2);
|
|
126
132
|
|
|
127
133
|
const wrong = checkAndSpy("./packages/wrong");
|
|
128
|
-
expect(wrong.addErrorSpy).toHaveBeenCalledTimes(
|
|
134
|
+
expect(wrong.addErrorSpy).toHaveBeenCalledTimes(3);
|
|
129
135
|
|
|
130
136
|
const right = checkAndSpy("./packages/right");
|
|
131
137
|
expect(right.addErrorSpy).toHaveBeenCalledTimes(0);
|
|
@@ -141,7 +147,7 @@ describe("requireDependency", () => {
|
|
|
141
147
|
expect(missing.addErrorSpy).toHaveBeenCalledTimes(2);
|
|
142
148
|
|
|
143
149
|
const wrong = checkAndSpy("./packages/wrong");
|
|
144
|
-
expect(wrong.addErrorSpy).toHaveBeenCalledTimes(
|
|
150
|
+
expect(wrong.addErrorSpy).toHaveBeenCalledTimes(3);
|
|
145
151
|
|
|
146
152
|
const missingContents = readFile("./packages/missing/package.json");
|
|
147
153
|
expect(missingContents).toEqual(CORRECT_OUTPUT);
|
package/src/__tests__/utils.ts
CHANGED
|
@@ -8,9 +8,9 @@
|
|
|
8
8
|
import { AddErrorOptions, WorkspaceContext } from "@monorepolint/config";
|
|
9
9
|
import { WorkspaceContextImpl } from "@monorepolint/core";
|
|
10
10
|
import { CachingHost, Host, SimpleHost } from "@monorepolint/utils";
|
|
11
|
-
import { expect, jest } from "@jest/globals";
|
|
12
11
|
import * as path from "node:path";
|
|
13
12
|
import * as tmp from "tmp";
|
|
13
|
+
import { expect, MockInstance } from "vitest";
|
|
14
14
|
|
|
15
15
|
export function jsonToString(obj: unknown) {
|
|
16
16
|
return JSON.stringify(obj, undefined, 2) + "\n";
|
|
@@ -22,7 +22,9 @@ interface TestingWorkspaceOpts {
|
|
|
22
22
|
fixFlag: boolean;
|
|
23
23
|
}
|
|
24
24
|
|
|
25
|
-
export async function createTestingWorkspace(
|
|
25
|
+
export async function createTestingWorkspace(
|
|
26
|
+
inboundOpts: TestingWorkspaceOpts,
|
|
27
|
+
) {
|
|
26
28
|
tmp.setGracefulCleanup();
|
|
27
29
|
const tmpdir = tmp.dirSync();
|
|
28
30
|
const opts = {
|
|
@@ -43,7 +45,11 @@ export async function createTestingWorkspace(inboundOpts: TestingWorkspaceOpts)
|
|
|
43
45
|
|
|
44
46
|
return new DefaultTestingWorkspace(
|
|
45
47
|
{ ...opts, rootPath },
|
|
46
|
-
new WorkspaceContextImpl(
|
|
48
|
+
new WorkspaceContextImpl(
|
|
49
|
+
rootPath,
|
|
50
|
+
{ fix: opts.fixFlag, rules: [] },
|
|
51
|
+
opts.host,
|
|
52
|
+
),
|
|
47
53
|
);
|
|
48
54
|
}
|
|
49
55
|
|
|
@@ -67,10 +73,11 @@ export interface TestingWorkspace {
|
|
|
67
73
|
readFile(filePath: string): string;
|
|
68
74
|
|
|
69
75
|
/**
|
|
70
|
-
* Helper method for matching failures via
|
|
71
|
-
*
|
|
76
|
+
* Helper method for matching failures via vi `expect().toMatchObject
|
|
72
77
|
*/
|
|
73
|
-
failureMatcher(
|
|
78
|
+
failureMatcher(
|
|
79
|
+
opts: { file: string; message: string; hasFixer: boolean },
|
|
80
|
+
): any;
|
|
74
81
|
|
|
75
82
|
readonly context: WorkspaceContext;
|
|
76
83
|
}
|
|
@@ -78,7 +85,7 @@ export interface TestingWorkspace {
|
|
|
78
85
|
class DefaultTestingWorkspace implements TestingWorkspace {
|
|
79
86
|
constructor(
|
|
80
87
|
private opts: RealTestingWorkspaceOpts,
|
|
81
|
-
public readonly context: WorkspaceContext
|
|
88
|
+
public readonly context: WorkspaceContext,
|
|
82
89
|
) {}
|
|
83
90
|
|
|
84
91
|
addProject(name: string, fields: object) {
|
|
@@ -110,7 +117,9 @@ class DefaultTestingWorkspace implements TestingWorkspace {
|
|
|
110
117
|
}
|
|
111
118
|
|
|
112
119
|
readFile(filePath: string) {
|
|
113
|
-
return this.opts.host.readFile(this.getFilePath(filePath), {
|
|
120
|
+
return this.opts.host.readFile(this.getFilePath(filePath), {
|
|
121
|
+
encoding: "utf-8",
|
|
122
|
+
});
|
|
114
123
|
}
|
|
115
124
|
|
|
116
125
|
failureMatcher(opts: { file: string; message: string; hasFixer: boolean }) {
|
|
@@ -122,7 +131,7 @@ class DefaultTestingWorkspace implements TestingWorkspace {
|
|
|
122
131
|
}
|
|
123
132
|
}
|
|
124
133
|
|
|
125
|
-
export type AddErrorSpy =
|
|
134
|
+
export type AddErrorSpy = MockInstance<(options: AddErrorOptions) => void>;
|
|
126
135
|
|
|
127
136
|
export const HOST_FACTORIES: Array<{ name: string; make: () => Host }> = [
|
|
128
137
|
{ name: "SimpleHost", make: () => new SimpleHost() },
|