@monorepolint/rules 0.5.0-alpha.98 → 0.5.0-beta.1
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 +22 -0
- package/package.json +47 -26
- package/src/__tests__/alphabeticalScripts.spec.ts +6 -5
- package/src/__tests__/bannedDependencies.spec.ts +5 -7
- package/src/__tests__/consistentDependencies.spec.ts +6 -5
- package/src/__tests__/consistentVersions.spec.ts +5 -4
- package/src/__tests__/fileContents.spec.ts +44 -17
- package/src/__tests__/mustSatisfyPeerDependencies.spec.ts +39 -38
- package/src/__tests__/nestedWorkspaces.spec.ts +5 -4
- package/src/__tests__/packageEntry.spec.ts +43 -32
- package/src/__tests__/packageOrder.spec.ts +23 -14
- package/src/__tests__/packageScript.spec.ts +61 -43
- package/src/__tests__/requireDependency.spec.ts +8 -7
- package/src/__tests__/utils.ts +8 -4
- package/src/alphabeticalDependencies.ts +7 -12
- package/src/alphabeticalScripts.ts +7 -12
- package/src/bannedDependencies.ts +9 -12
- package/src/consistentDependencies.ts +9 -10
- package/src/consistentVersions.ts +6 -8
- package/src/fileContents.ts +17 -16
- package/src/index.ts +13 -13
- package/src/mustSatisfyPeerDependencies.ts +16 -17
- package/src/nestedWorkspaces.ts +10 -12
- package/src/packageEntry.ts +7 -9
- package/src/packageOrder.ts +12 -10
- package/src/packageScript.ts +12 -19
- package/src/public/util.ts +1 -0
- package/src/requireDependency.ts +9 -10
- package/src/standardTsconfig.ts +10 -11
- package/src/util/checkAlpha.ts +1 -1
- package/src/util/makeRule.ts +29 -0
- package/src/util/packageDependencyGraphService.ts +2 -2
- package/tsconfig.json +7 -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 -23
- package/lib/alphabeticalDependencies.d.ts.map +0 -1
- package/lib/alphabeticalDependencies.js +0 -24
- package/lib/alphabeticalDependencies.js.map +0 -1
- package/lib/alphabeticalScripts.d.ts +0 -23
- package/lib/alphabeticalScripts.d.ts.map +0 -1
- package/lib/alphabeticalScripts.js +0 -22
- package/lib/alphabeticalScripts.js.map +0 -1
- package/lib/bannedDependencies.d.ts +0 -134
- package/lib/bannedDependencies.d.ts.map +0 -1
- package/lib/bannedDependencies.js +0 -133
- package/lib/bannedDependencies.js.map +0 -1
- package/lib/consistentDependencies.d.ts +0 -38
- package/lib/consistentDependencies.d.ts.map +0 -1
- package/lib/consistentDependencies.js +0 -77
- package/lib/consistentDependencies.js.map +0 -1
- package/lib/consistentVersions.d.ts +0 -47
- package/lib/consistentVersions.d.ts.map +0 -1
- package/lib/consistentVersions.js +0 -96
- package/lib/consistentVersions.js.map +0 -1
- package/lib/fileContents.d.ts +0 -111
- package/lib/fileContents.d.ts.map +0 -1
- package/lib/fileContents.js +0 -84
- 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 -49
- package/lib/index.js.map +0 -1
- package/lib/mustSatisfyPeerDependencies.d.ts +0 -721
- package/lib/mustSatisfyPeerDependencies.d.ts.map +0 -1
- package/lib/mustSatisfyPeerDependencies.js +0 -638
- package/lib/mustSatisfyPeerDependencies.js.map +0 -1
- package/lib/nestedWorkspaces.d.ts +0 -24
- package/lib/nestedWorkspaces.d.ts.map +0 -1
- package/lib/nestedWorkspaces.js +0 -52
- package/lib/nestedWorkspaces.js.map +0 -1
- package/lib/packageEntry.d.ts +0 -115
- package/lib/packageEntry.d.ts.map +0 -1
- package/lib/packageEntry.js +0 -77
- package/lib/packageEntry.js.map +0 -1
- package/lib/packageOrder.d.ts +0 -33
- package/lib/packageOrder.d.ts.map +0 -1
- package/lib/packageOrder.js +0 -105
- package/lib/packageOrder.js.map +0 -1
- package/lib/packageScript.d.ts +0 -102
- package/lib/packageScript.d.ts.map +0 -1
- package/lib/packageScript.js +0 -92
- package/lib/packageScript.js.map +0 -1
- package/lib/requireDependency.d.ts +0 -99
- package/lib/requireDependency.d.ts.map +0 -1
- package/lib/requireDependency.js +0 -67
- package/lib/requireDependency.js.map +0 -1
- package/lib/standardTsconfig.d.ts +0 -113
- package/lib/standardTsconfig.d.ts.map +0 -1
- package/lib/standardTsconfig.js +0 -118
- 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/createNewRuleConversion.d.ts +0 -30
- package/lib/util/createNewRuleConversion.d.ts.map +0 -1
- package/lib/util/createNewRuleConversion.js +0 -33
- package/lib/util/createNewRuleConversion.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/src/util/createNewRuleConversion.ts +0 -38
- package/tsconfig.tsbuildinfo +0 -1
- /package/{jest.config.js → jest.config.cjs} +0 -0
|
@@ -8,8 +8,9 @@
|
|
|
8
8
|
// tslint:disable:no-console
|
|
9
9
|
|
|
10
10
|
import { Context, Failure } from "@monorepolint/config";
|
|
11
|
-
import { createExpectedEntryErrorMessage, createStandardizedEntryErrorMessage, packageEntry } from "../packageEntry";
|
|
12
|
-
import { AddErrorSpy, createTestingWorkspace, HOST_FACTORIES, TestingWorkspace } from "./utils";
|
|
11
|
+
import { createExpectedEntryErrorMessage, createStandardizedEntryErrorMessage, packageEntry } from "../packageEntry.js";
|
|
12
|
+
import { AddErrorSpy, createTestingWorkspace, HOST_FACTORIES, TestingWorkspace } from "./utils.js";
|
|
13
|
+
import { describe, expect, it, beforeEach, afterEach, jest } from "@jest/globals";
|
|
13
14
|
|
|
14
15
|
const PACKAGE_MISSING_ENTRY =
|
|
15
16
|
JSON.stringify(
|
|
@@ -75,12 +76,14 @@ describe.each(HOST_FACTORIES)("expectPackageEntries ($name)", (hostFactory) => {
|
|
|
75
76
|
it("fixes missing entries", () => {
|
|
76
77
|
workspace.writeFile("package.json", PACKAGE_MISSING_ENTRY);
|
|
77
78
|
|
|
78
|
-
packageEntry
|
|
79
|
-
|
|
80
|
-
|
|
79
|
+
packageEntry({
|
|
80
|
+
options: {
|
|
81
|
+
entries: {
|
|
82
|
+
license: "UNLICENSED",
|
|
83
|
+
},
|
|
84
|
+
entriesExist: undefined,
|
|
81
85
|
},
|
|
82
|
-
|
|
83
|
-
});
|
|
86
|
+
}).check(context);
|
|
84
87
|
|
|
85
88
|
expect(spy).toHaveBeenCalledTimes(1);
|
|
86
89
|
|
|
@@ -99,15 +102,17 @@ describe.each(HOST_FACTORIES)("expectPackageEntries ($name)", (hostFactory) => {
|
|
|
99
102
|
it("fixes missing nested entries", () => {
|
|
100
103
|
workspace.writeFile("package.json", PACKAGE_MISSING_ENTRY);
|
|
101
104
|
|
|
102
|
-
packageEntry
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
105
|
+
packageEntry({
|
|
106
|
+
options: {
|
|
107
|
+
entries: {
|
|
108
|
+
repository: {
|
|
109
|
+
type: "git",
|
|
110
|
+
url: "https://github.com:foo/foo",
|
|
111
|
+
},
|
|
107
112
|
},
|
|
113
|
+
entriesExist: undefined,
|
|
108
114
|
},
|
|
109
|
-
|
|
110
|
-
});
|
|
115
|
+
}).check(context);
|
|
111
116
|
|
|
112
117
|
expect(spy).toHaveBeenCalledTimes(1);
|
|
113
118
|
|
|
@@ -126,15 +131,17 @@ describe.each(HOST_FACTORIES)("expectPackageEntries ($name)", (hostFactory) => {
|
|
|
126
131
|
it("doesn't error for nested entries that are defined", () => {
|
|
127
132
|
workspace.writeFile("package.json", PACKAGE_REPOSITORY);
|
|
128
133
|
|
|
129
|
-
packageEntry
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
+
packageEntry({
|
|
135
|
+
options: {
|
|
136
|
+
entries: {
|
|
137
|
+
repository: {
|
|
138
|
+
type: "git",
|
|
139
|
+
url: "https://github.com:foo/foo",
|
|
140
|
+
},
|
|
134
141
|
},
|
|
142
|
+
entriesExist: undefined,
|
|
135
143
|
},
|
|
136
|
-
|
|
137
|
-
});
|
|
144
|
+
}).check(context);
|
|
138
145
|
|
|
139
146
|
expect(spy).toHaveBeenCalledTimes(0);
|
|
140
147
|
expect(workspace.readFile("package.json")).toEqual(PACKAGE_REPOSITORY);
|
|
@@ -143,10 +150,12 @@ describe.each(HOST_FACTORIES)("expectPackageEntries ($name)", (hostFactory) => {
|
|
|
143
150
|
it("errors for keys that are missing", () => {
|
|
144
151
|
workspace.writeFile("package.json", PACKAGE_REPOSITORY);
|
|
145
152
|
|
|
146
|
-
packageEntry
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
153
|
+
packageEntry({
|
|
154
|
+
options: {
|
|
155
|
+
entries: undefined,
|
|
156
|
+
entriesExist: ["bugs"],
|
|
157
|
+
},
|
|
158
|
+
}).check(context);
|
|
150
159
|
|
|
151
160
|
expect(spy).toHaveBeenCalledTimes(1);
|
|
152
161
|
|
|
@@ -164,15 +173,17 @@ describe.each(HOST_FACTORIES)("expectPackageEntries ($name)", (hostFactory) => {
|
|
|
164
173
|
it("handles both entries and entriesExist", () => {
|
|
165
174
|
workspace.writeFile("package.json", PACKAGE_MISSING_ENTRY);
|
|
166
175
|
|
|
167
|
-
packageEntry
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
176
|
+
packageEntry({
|
|
177
|
+
options: {
|
|
178
|
+
entries: {
|
|
179
|
+
repository: {
|
|
180
|
+
type: "git",
|
|
181
|
+
url: "https://github.com:foo/foo",
|
|
182
|
+
},
|
|
172
183
|
},
|
|
184
|
+
entriesExist: ["bugs"],
|
|
173
185
|
},
|
|
174
|
-
|
|
175
|
-
});
|
|
186
|
+
}).check(context);
|
|
176
187
|
|
|
177
188
|
expect(spy).toHaveBeenCalledTimes(2);
|
|
178
189
|
|
|
@@ -6,9 +6,10 @@
|
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
8
|
// tslint:disable:no-console
|
|
9
|
-
import { AddErrorSpy, createTestingWorkspace, HOST_FACTORIES, TestingWorkspace } from "./utils";
|
|
9
|
+
import { AddErrorSpy, createTestingWorkspace, HOST_FACTORIES, TestingWorkspace } from "./utils.js";
|
|
10
10
|
import { Context, Failure } from "@monorepolint/config";
|
|
11
|
-
import { packageOrder } from "../packageOrder";
|
|
11
|
+
import { packageOrder } from "../packageOrder.js";
|
|
12
|
+
import { describe, expect, it, beforeEach, jest } from "@jest/globals";
|
|
12
13
|
|
|
13
14
|
const PACKAGE_UNORDERED =
|
|
14
15
|
JSON.stringify(
|
|
@@ -100,9 +101,11 @@ describe.each(HOST_FACTORIES)("expectPackageOrder ($name)", (hostFactory) => {
|
|
|
100
101
|
it("fixes order for expected keys", () => {
|
|
101
102
|
workspace.writeFile("package.json", PACKAGE_UNORDERED);
|
|
102
103
|
|
|
103
|
-
packageOrder
|
|
104
|
-
|
|
105
|
-
|
|
104
|
+
packageOrder({
|
|
105
|
+
options: {
|
|
106
|
+
order: orderArray,
|
|
107
|
+
},
|
|
108
|
+
}).check(context);
|
|
106
109
|
|
|
107
110
|
expect(spy).toHaveBeenCalledTimes(1);
|
|
108
111
|
|
|
@@ -121,9 +124,11 @@ describe.each(HOST_FACTORIES)("expectPackageOrder ($name)", (hostFactory) => {
|
|
|
121
124
|
it("fixes order for unexpected keys", () => {
|
|
122
125
|
workspace.writeFile("package.json", PACKAGE_UNORDERED_UNKOWN_KEYS);
|
|
123
126
|
|
|
124
|
-
packageOrder
|
|
125
|
-
|
|
126
|
-
|
|
127
|
+
packageOrder({
|
|
128
|
+
options: {
|
|
129
|
+
order: orderArray,
|
|
130
|
+
},
|
|
131
|
+
}).check(context);
|
|
127
132
|
|
|
128
133
|
expect(spy).toHaveBeenCalledTimes(1);
|
|
129
134
|
|
|
@@ -142,9 +147,11 @@ describe.each(HOST_FACTORIES)("expectPackageOrder ($name)", (hostFactory) => {
|
|
|
142
147
|
it("fixes order using function", () => {
|
|
143
148
|
workspace.writeFile("package.json", PACKAGE_UNORDERED);
|
|
144
149
|
|
|
145
|
-
packageOrder
|
|
146
|
-
|
|
147
|
-
|
|
150
|
+
packageOrder({
|
|
151
|
+
options: {
|
|
152
|
+
order: orderFunction,
|
|
153
|
+
},
|
|
154
|
+
}).check(context);
|
|
148
155
|
|
|
149
156
|
expect(spy).toHaveBeenCalledTimes(1);
|
|
150
157
|
|
|
@@ -163,9 +170,11 @@ describe.each(HOST_FACTORIES)("expectPackageOrder ($name)", (hostFactory) => {
|
|
|
163
170
|
it("does nothing if already order", () => {
|
|
164
171
|
workspace.writeFile("package.json", PACKAGE_ORDERED_UNKOWN_KEYS);
|
|
165
172
|
|
|
166
|
-
packageOrder
|
|
167
|
-
|
|
168
|
-
|
|
173
|
+
packageOrder({
|
|
174
|
+
options: {
|
|
175
|
+
order: orderArray,
|
|
176
|
+
},
|
|
177
|
+
}).check(context);
|
|
169
178
|
|
|
170
179
|
expect(spy).not.toHaveBeenCalled();
|
|
171
180
|
|
|
@@ -6,10 +6,10 @@
|
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
8
|
// tslint:disable:no-console
|
|
9
|
-
|
|
9
|
+
import { describe, expect, it, beforeEach, jest } from "@jest/globals";
|
|
10
10
|
import { Context, Failure } from "@monorepolint/config";
|
|
11
|
-
import { packageScript } from "../packageScript";
|
|
12
|
-
import { AddErrorSpy, createTestingWorkspace, HOST_FACTORIES, TestingWorkspace } from "./utils";
|
|
11
|
+
import { packageScript } from "../packageScript.js";
|
|
12
|
+
import { AddErrorSpy, createTestingWorkspace, HOST_FACTORIES, TestingWorkspace } from "./utils.js";
|
|
13
13
|
|
|
14
14
|
const json = (a: unknown) => JSON.stringify(a, undefined, 2) + "\n";
|
|
15
15
|
|
|
@@ -47,11 +47,13 @@ describe.each(HOST_FACTORIES)("expectPackageScript ($name)", (hostFactory) => {
|
|
|
47
47
|
it("handles an empty script section", () => {
|
|
48
48
|
workspace.writeFile("package.json", PACKAGE_WITHOUT_SCRIPTS);
|
|
49
49
|
|
|
50
|
-
packageScript
|
|
51
|
-
|
|
52
|
-
|
|
50
|
+
packageScript({
|
|
51
|
+
options: {
|
|
52
|
+
scripts: {
|
|
53
|
+
foo: "bar",
|
|
54
|
+
},
|
|
53
55
|
},
|
|
54
|
-
});
|
|
56
|
+
}).check(workspace.context);
|
|
55
57
|
|
|
56
58
|
expect(spy).toHaveBeenCalledTimes(1);
|
|
57
59
|
|
|
@@ -84,11 +86,13 @@ describe.each(HOST_FACTORIES)("expectPackageScript ($name)", (hostFactory) => {
|
|
|
84
86
|
it("fixes an empty script section", () => {
|
|
85
87
|
workspace.writeFile("package.json", PACKAGE_WITHOUT_SCRIPTS);
|
|
86
88
|
|
|
87
|
-
packageScript
|
|
88
|
-
|
|
89
|
-
|
|
89
|
+
packageScript({
|
|
90
|
+
options: {
|
|
91
|
+
scripts: {
|
|
92
|
+
foo: "bar",
|
|
93
|
+
},
|
|
90
94
|
},
|
|
91
|
-
});
|
|
95
|
+
}).check(context);
|
|
92
96
|
|
|
93
97
|
expect(spy).toHaveBeenCalledTimes(1);
|
|
94
98
|
|
|
@@ -107,11 +111,13 @@ describe.each(HOST_FACTORIES)("expectPackageScript ($name)", (hostFactory) => {
|
|
|
107
111
|
it("adds a script", () => {
|
|
108
112
|
workspace.writeFile("package.json", PACKAGE_WITH_SCRIPTS);
|
|
109
113
|
|
|
110
|
-
packageScript
|
|
111
|
-
|
|
112
|
-
|
|
114
|
+
packageScript({
|
|
115
|
+
options: {
|
|
116
|
+
scripts: {
|
|
117
|
+
[MISSING_SCRIPT_NAME]: MISSING_SCRIPT_VALUE,
|
|
118
|
+
},
|
|
113
119
|
},
|
|
114
|
-
});
|
|
120
|
+
}).check(context);
|
|
115
121
|
|
|
116
122
|
expect(spy).toHaveBeenCalledTimes(1);
|
|
117
123
|
|
|
@@ -120,7 +126,9 @@ describe.each(HOST_FACTORIES)("expectPackageScript ($name)", (hostFactory) => {
|
|
|
120
126
|
workspace.failureMatcher({
|
|
121
127
|
file: "package.json",
|
|
122
128
|
hasFixer: true,
|
|
123
|
-
message: expect.stringContaining(
|
|
129
|
+
message: expect.stringContaining(
|
|
130
|
+
`Expected standardized script entry for '${MISSING_SCRIPT_NAME}'`
|
|
131
|
+
) as unknown as string,
|
|
124
132
|
})
|
|
125
133
|
);
|
|
126
134
|
|
|
@@ -132,11 +140,13 @@ describe.each(HOST_FACTORIES)("expectPackageScript ($name)", (hostFactory) => {
|
|
|
132
140
|
it("does nothing if the value exists", () => {
|
|
133
141
|
workspace.writeFile("package.json", PACKAGE_WITH_SCRIPTS);
|
|
134
142
|
|
|
135
|
-
packageScript
|
|
136
|
-
|
|
137
|
-
|
|
143
|
+
packageScript({
|
|
144
|
+
options: {
|
|
145
|
+
scripts: {
|
|
146
|
+
[SCRIPT_NAME]: SCRIPT_VALUE,
|
|
147
|
+
},
|
|
138
148
|
},
|
|
139
|
-
});
|
|
149
|
+
}).check(context);
|
|
140
150
|
|
|
141
151
|
expect(spy).not.toHaveBeenCalled();
|
|
142
152
|
|
|
@@ -148,13 +158,15 @@ describe.each(HOST_FACTORIES)("expectPackageScript ($name)", (hostFactory) => {
|
|
|
148
158
|
it("errors if long form is used and no value matches and there is no fixValue", () => {
|
|
149
159
|
workspace.writeFile("package.json", PACKAGE_WITH_SCRIPTS);
|
|
150
160
|
|
|
151
|
-
packageScript
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
161
|
+
packageScript({
|
|
162
|
+
options: {
|
|
163
|
+
scripts: {
|
|
164
|
+
foo: {
|
|
165
|
+
options: ["a", "b"],
|
|
166
|
+
},
|
|
155
167
|
},
|
|
156
168
|
},
|
|
157
|
-
});
|
|
169
|
+
}).check(context);
|
|
158
170
|
|
|
159
171
|
const errors = spy.mock.calls;
|
|
160
172
|
|
|
@@ -165,14 +177,16 @@ describe.each(HOST_FACTORIES)("expectPackageScript ($name)", (hostFactory) => {
|
|
|
165
177
|
it("uses the fixValue for fixing if provided", () => {
|
|
166
178
|
workspace.writeFile("package.json", PACKAGE_WITH_SCRIPTS);
|
|
167
179
|
|
|
168
|
-
packageScript
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
180
|
+
packageScript({
|
|
181
|
+
options: {
|
|
182
|
+
scripts: {
|
|
183
|
+
foo: {
|
|
184
|
+
options: ["a", "b"],
|
|
185
|
+
fixValue: "a",
|
|
186
|
+
},
|
|
173
187
|
},
|
|
174
188
|
},
|
|
175
|
-
});
|
|
189
|
+
}).check(context);
|
|
176
190
|
|
|
177
191
|
const errors = spy.mock.calls;
|
|
178
192
|
|
|
@@ -188,14 +202,16 @@ describe.each(HOST_FACTORIES)("expectPackageScript ($name)", (hostFactory) => {
|
|
|
188
202
|
it("can fix to empty", () => {
|
|
189
203
|
workspace.writeFile("package.json", PACKAGE_WITH_SCRIPTS);
|
|
190
204
|
|
|
191
|
-
packageScript
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
205
|
+
packageScript({
|
|
206
|
+
options: {
|
|
207
|
+
scripts: {
|
|
208
|
+
[SCRIPT_NAME]: {
|
|
209
|
+
options: ["a", undefined],
|
|
210
|
+
fixValue: undefined,
|
|
211
|
+
},
|
|
196
212
|
},
|
|
197
213
|
},
|
|
198
|
-
});
|
|
214
|
+
}).check(context);
|
|
199
215
|
|
|
200
216
|
const errors = spy.mock.calls;
|
|
201
217
|
|
|
@@ -208,14 +224,16 @@ describe.each(HOST_FACTORIES)("expectPackageScript ($name)", (hostFactory) => {
|
|
|
208
224
|
it("can allow only empty", () => {
|
|
209
225
|
workspace.writeFile("package.json", PACKAGE_WITH_SCRIPTS);
|
|
210
226
|
|
|
211
|
-
packageScript
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
227
|
+
packageScript({
|
|
228
|
+
options: {
|
|
229
|
+
scripts: {
|
|
230
|
+
[SCRIPT_NAME]: {
|
|
231
|
+
options: [undefined],
|
|
232
|
+
fixValue: undefined,
|
|
233
|
+
},
|
|
216
234
|
},
|
|
217
235
|
},
|
|
218
|
-
});
|
|
236
|
+
}).check(context);
|
|
219
237
|
|
|
220
238
|
const errors = spy.mock.calls;
|
|
221
239
|
|
|
@@ -6,12 +6,13 @@
|
|
|
6
6
|
*/
|
|
7
7
|
import { WorkspaceContextImpl } from "@monorepolint/core";
|
|
8
8
|
import { SimpleHost } from "@monorepolint/utils";
|
|
9
|
-
import { readFileSync, writeFileSync } from "fs";
|
|
10
|
-
import * as path from "path";
|
|
9
|
+
import { readFileSync, writeFileSync } from "node:fs";
|
|
10
|
+
import * as path from "node:path";
|
|
11
11
|
import * as tmp from "tmp";
|
|
12
|
-
import { requireDependency } from "../requireDependency";
|
|
13
|
-
import { makeDirectoryRecursively } from "../util/makeDirectory";
|
|
14
|
-
import { jsonToString } from "./utils";
|
|
12
|
+
import { requireDependency } from "../requireDependency.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: {
|
|
@@ -88,7 +89,7 @@ describe("requireDependency", () => {
|
|
|
88
89
|
function checkAndSpy(q: string) {
|
|
89
90
|
const context = workspaceContext.createChildContext(path.resolve(dir.name, q));
|
|
90
91
|
const addErrorSpy = jest.spyOn(context, "addError");
|
|
91
|
-
requireDependency.check(context
|
|
92
|
+
requireDependency({ options: OPTIONS }).check(context);
|
|
92
93
|
return { context, addErrorSpy };
|
|
93
94
|
}
|
|
94
95
|
|
|
@@ -115,7 +116,7 @@ describe("requireDependency", () => {
|
|
|
115
116
|
addFile("./packages/wrong/package.json", PACKAGE_WITH_WRONG_ENTRIES);
|
|
116
117
|
addFile("./packages/right/package.json", PACKAGE_WITH_RIGHT_ENTRIES);
|
|
117
118
|
|
|
118
|
-
requireDependency.check(workspaceContext
|
|
119
|
+
requireDependency({ options: OPTIONS }).check(workspaceContext);
|
|
119
120
|
|
|
120
121
|
const none = checkAndSpy("./packages/none");
|
|
121
122
|
expect(none.addErrorSpy).toHaveBeenCalledTimes(2);
|
package/src/__tests__/utils.ts
CHANGED
|
@@ -8,10 +8,11 @@
|
|
|
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
|
|
11
|
+
import { expect, jest } from "@jest/globals";
|
|
12
|
+
import * as path from "node:path";
|
|
12
13
|
import * as tmp from "tmp";
|
|
13
14
|
|
|
14
|
-
export function jsonToString(obj:
|
|
15
|
+
export function jsonToString(obj: unknown) {
|
|
15
16
|
return JSON.stringify(obj, undefined, 2) + "\n";
|
|
16
17
|
}
|
|
17
18
|
|
|
@@ -75,7 +76,10 @@ export interface TestingWorkspace {
|
|
|
75
76
|
}
|
|
76
77
|
|
|
77
78
|
class DefaultTestingWorkspace implements TestingWorkspace {
|
|
78
|
-
constructor(
|
|
79
|
+
constructor(
|
|
80
|
+
private opts: RealTestingWorkspaceOpts,
|
|
81
|
+
public readonly context: WorkspaceContext
|
|
82
|
+
) {}
|
|
79
83
|
|
|
80
84
|
addProject(name: string, fields: object) {
|
|
81
85
|
this.writeJsonFile(path.join("packages", name, "package.json"), {
|
|
@@ -118,7 +122,7 @@ class DefaultTestingWorkspace implements TestingWorkspace {
|
|
|
118
122
|
}
|
|
119
123
|
}
|
|
120
124
|
|
|
121
|
-
export type AddErrorSpy = jest.
|
|
125
|
+
export type AddErrorSpy = jest.SpiedFunction<(options: AddErrorOptions) => void>;
|
|
122
126
|
|
|
123
127
|
export const HOST_FACTORIES: Array<{ name: string; make: () => Host }> = [
|
|
124
128
|
{ name: "SimpleHost", make: () => new SimpleHost() },
|
|
@@ -5,20 +5,15 @@
|
|
|
5
5
|
*
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
-
import {
|
|
9
|
-
import
|
|
10
|
-
import { checkAlpha } from "./util/checkAlpha";
|
|
11
|
-
import { createNewRuleConversion } from "./util/createNewRuleConversion";
|
|
8
|
+
import { checkAlpha } from "./util/checkAlpha.js";
|
|
9
|
+
import { makeRule } from "./util/makeRule.js";
|
|
12
10
|
|
|
13
|
-
const
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
check: function expectAlphabeticalDependencies(context: Context) {
|
|
11
|
+
export const alphabeticalDependencies = makeRule<undefined>({
|
|
12
|
+
name: "alphabeticalDependencies",
|
|
13
|
+
check: (context) => {
|
|
17
14
|
checkAlpha(context, "dependencies");
|
|
18
15
|
checkAlpha(context, "devDependencies");
|
|
19
16
|
checkAlpha(context, "peerDependencies");
|
|
20
17
|
},
|
|
21
|
-
|
|
22
|
-
};
|
|
23
|
-
|
|
24
|
-
export const AlphabeticalDependencies = createNewRuleConversion("AlphabetialDependencies", alphabeticalDependencies);
|
|
18
|
+
validateOptions: () => {},
|
|
19
|
+
});
|
|
@@ -5,18 +5,13 @@
|
|
|
5
5
|
*
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
-
import {
|
|
9
|
-
import
|
|
10
|
-
import { checkAlpha } from "./util/checkAlpha";
|
|
11
|
-
import { createNewRuleConversion } from "./util/createNewRuleConversion";
|
|
8
|
+
import { checkAlpha } from "./util/checkAlpha.js";
|
|
9
|
+
import { makeRule } from "./util/makeRule.js";
|
|
12
10
|
|
|
13
|
-
const
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
check: function expectAlphabeticalScripts(context: Context) {
|
|
11
|
+
export const alphabeticalScripts = makeRule<undefined>({
|
|
12
|
+
name: "alphabeticalScripts",
|
|
13
|
+
check: (context) => {
|
|
17
14
|
checkAlpha(context, "scripts");
|
|
18
15
|
},
|
|
19
|
-
|
|
20
|
-
};
|
|
21
|
-
|
|
22
|
-
export const AlphabeticalScripts = createNewRuleConversion("AlphabeticalScripts", alphabeticalScripts);
|
|
16
|
+
validateOptions: () => {},
|
|
17
|
+
});
|
|
@@ -5,14 +5,13 @@
|
|
|
5
5
|
*
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
-
import { Context
|
|
8
|
+
import { Context } from "@monorepolint/config";
|
|
9
9
|
import { matchesAnyGlob } from "@monorepolint/utils";
|
|
10
10
|
import { AggregateTiming } from "@monorepolint/utils";
|
|
11
|
-
import path from "path";
|
|
11
|
+
import * as path from "node:path";
|
|
12
12
|
import * as r from "runtypes";
|
|
13
|
-
import {
|
|
14
|
-
import { IPackageDependencyGraphNode, PackageDependencyGraphService } from "./util/packageDependencyGraphService";
|
|
15
|
-
|
|
13
|
+
import { makeRule } from "./util/makeRule.js";
|
|
14
|
+
import { IPackageDependencyGraphNode, PackageDependencyGraphService } from "./util/packageDependencyGraphService.js";
|
|
16
15
|
// FIXME: This rule is messed. bannedTransitiveDependencies doesnt glob
|
|
17
16
|
|
|
18
17
|
const bannedDepGlobsField = r.Union(
|
|
@@ -50,10 +49,9 @@ const setCache = new Map<ReadonlyArray<string>, Set<string>>();
|
|
|
50
49
|
|
|
51
50
|
const aggregateTiming = new AggregateTiming(":bannedDependencies stats");
|
|
52
51
|
|
|
53
|
-
export const bannedDependencies
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
check: function expectAllowedDependencies(context, opts, extra) {
|
|
52
|
+
export const bannedDependencies = makeRule<Options>({
|
|
53
|
+
name: "bannedDependencies",
|
|
54
|
+
check: (context, opts, extra) => {
|
|
57
55
|
aggregateTiming.start(extra?.id ?? "unknown id");
|
|
58
56
|
|
|
59
57
|
const packageJson = context.getPackageJson();
|
|
@@ -109,12 +107,11 @@ export const bannedDependencies: RuleModule<typeof Options> & {
|
|
|
109
107
|
|
|
110
108
|
aggregateTiming.stop();
|
|
111
109
|
},
|
|
112
|
-
|
|
110
|
+
validateOptions: Options.check,
|
|
113
111
|
printStats: () => {
|
|
114
112
|
aggregateTiming.printResults();
|
|
115
113
|
},
|
|
116
|
-
};
|
|
117
|
-
export const BannedDependencies = createNewRuleConversion("BannedDependencies", bannedDependencies);
|
|
114
|
+
});
|
|
118
115
|
|
|
119
116
|
function populateProblemsExact(banned: Set<string>, dependencies: ReadonlyArray<string>, violations: Set<string>) {
|
|
120
117
|
for (const dependency of dependencies) {
|
|
@@ -5,11 +5,10 @@
|
|
|
5
5
|
*
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
-
import { Context
|
|
9
|
-
import diff from "jest-diff";
|
|
8
|
+
import { Context } from "@monorepolint/config";
|
|
9
|
+
import { diff } from "jest-diff";
|
|
10
10
|
import * as r from "runtypes";
|
|
11
|
-
import {
|
|
12
|
-
|
|
11
|
+
import { makeRule } from "./util/makeRule.js";
|
|
13
12
|
const Options = r
|
|
14
13
|
.Record({
|
|
15
14
|
ignoredDependencies: r.Array(r.String).Or(r.Undefined),
|
|
@@ -19,16 +18,15 @@ export type Options = r.Static<typeof Options>;
|
|
|
19
18
|
|
|
20
19
|
const skippedVersions = ["*", "latest"];
|
|
21
20
|
|
|
22
|
-
export const consistentDependencies = {
|
|
23
|
-
|
|
21
|
+
export const consistentDependencies = makeRule<Options>({
|
|
22
|
+
name: "consistentDependencies",
|
|
23
|
+
check: (context, args) => {
|
|
24
24
|
checkDeps(context, args, "dependencies");
|
|
25
25
|
checkDeps(context, args, "devDependencies");
|
|
26
26
|
// we don't check peer deps since they can be more lenient
|
|
27
27
|
},
|
|
28
|
-
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
export const ConsistentDependencies = createNewRuleConversion("ConsistentDependencies", consistentDependencies);
|
|
28
|
+
validateOptions: Options.check,
|
|
29
|
+
});
|
|
32
30
|
|
|
33
31
|
function checkDeps(context: Context, args: Options, block: "dependencies" | "devDependencies" | "peerDependencies") {
|
|
34
32
|
const packageJson = context.getPackageJson();
|
|
@@ -68,6 +66,7 @@ function checkDeps(context: Context, args: Options, block: "dependencies" | "dev
|
|
|
68
66
|
}
|
|
69
67
|
|
|
70
68
|
function filterKeys(ob: Record<string, string>, filterOb: Record<string, string>) {
|
|
69
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
71
70
|
const newOb: Record<string, any> = {};
|
|
72
71
|
|
|
73
72
|
for (const key of Object.keys(filterOb)) {
|
|
@@ -5,22 +5,22 @@
|
|
|
5
5
|
*
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
-
import { Context
|
|
8
|
+
import { Context } from "@monorepolint/config";
|
|
9
9
|
import { mutateJson, PackageJson } from "@monorepolint/utils";
|
|
10
10
|
import * as r from "runtypes";
|
|
11
11
|
import { coerce, SemVer } from "semver";
|
|
12
|
-
import {
|
|
13
|
-
|
|
12
|
+
import { makeRule } from "./util/makeRule.js";
|
|
14
13
|
export const Options = r.Record({
|
|
15
14
|
matchDependencyVersions: r.Dictionary(r.Union(r.String, r.Array(r.String))),
|
|
16
15
|
});
|
|
17
16
|
|
|
18
17
|
export type Options = r.Static<typeof Options>;
|
|
19
18
|
|
|
20
|
-
export const consistentVersions
|
|
19
|
+
export const consistentVersions = makeRule({
|
|
20
|
+
name: "consistentVersions",
|
|
21
21
|
check: checkConsistentVersions,
|
|
22
|
-
|
|
23
|
-
};
|
|
22
|
+
validateOptions: Options.check,
|
|
23
|
+
});
|
|
24
24
|
|
|
25
25
|
function checkConsistentVersions(context: Context, options: Options) {
|
|
26
26
|
for (const [dependencyPackageName, expectedPackageDependencyValue] of Object.entries(
|
|
@@ -139,5 +139,3 @@ const ensurePackageMatchesSomeVersion = (
|
|
|
139
139
|
});
|
|
140
140
|
}
|
|
141
141
|
};
|
|
142
|
-
|
|
143
|
-
export const ConsistentVersions = createNewRuleConversion("ConsistentVersions", consistentVersions);
|