@cloud-ru/ft-deps-validator 1.1.2-preview-406fdd9.0 → 1.1.2-preview-13c2d04.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/dist/cjs/Checker/MonorepoChecker.js +3 -3
- package/dist/cjs/Checker/__tests__/MonorepoChecker.spec.js +2 -4
- package/dist/cjs/Report/__tests__/Report.spec.js +13 -13
- package/dist/cjs/Report/index.js +2 -2
- package/dist/cjs/utils/console.js +1 -1
- package/dist/esm/Checker/MonorepoChecker.js +3 -3
- package/dist/esm/Checker/__tests__/MonorepoChecker.spec.js +2 -4
- package/dist/esm/Report/__tests__/Report.spec.js +14 -14
- package/dist/esm/Report/index.js +3 -3
- package/dist/esm/utils/console.js +1 -1
- package/package.json +2 -2
- package/src/Checker/MonorepoChecker.ts +3 -3
- package/src/Checker/__tests__/MonorepoChecker.spec.ts +2 -4
- package/src/Report/__tests__/Report.spec.ts +14 -14
- package/src/Report/index.ts +4 -4
- package/src/utils/console.ts +1 -1
|
@@ -16,7 +16,7 @@ class MonorepoChecker extends RepoChecker_1.RepoChecker {
|
|
|
16
16
|
constructor(config) {
|
|
17
17
|
super(config);
|
|
18
18
|
this.actualVersions = {};
|
|
19
|
-
this.config.getFolders().reduce((acc, folder) => {
|
|
19
|
+
this.actualVersions = this.config.getFolders().reduce((acc, folder) => {
|
|
20
20
|
const pkg = (0, readPackageJsonFile_1.readPackageJsonFileSync)(folder);
|
|
21
21
|
acc[pkg.name] = pkg.version;
|
|
22
22
|
return acc;
|
|
@@ -31,10 +31,10 @@ class MonorepoChecker extends RepoChecker_1.RepoChecker {
|
|
|
31
31
|
if (pkg.dependencies) {
|
|
32
32
|
for (const [dep, version] of Object.entries(pkg.dependencies)) {
|
|
33
33
|
const actualVersion = this.actualVersions[dep];
|
|
34
|
-
if (actualVersion !== version) {
|
|
34
|
+
if (actualVersion && actualVersion !== version) {
|
|
35
35
|
const message = `"${dep}" has wrong version "${version}", but need "${actualVersion}".`;
|
|
36
36
|
if (result.wrongVersions) {
|
|
37
|
-
result.wrongVersions.push();
|
|
37
|
+
result.wrongVersions.push(message);
|
|
38
38
|
}
|
|
39
39
|
else {
|
|
40
40
|
result.wrongVersions = [message];
|
|
@@ -253,7 +253,7 @@ vitest_1.vi.mock('../../utils/readPackageJsonFile', () => ({
|
|
|
253
253
|
const exitCode = report.printResultAndGetExitCode();
|
|
254
254
|
(0, vitest_1.expect)(exitCode).toBe(1);
|
|
255
255
|
}));
|
|
256
|
-
(0, vitest_1.it)('should add wrongVersions for external packages
|
|
256
|
+
(0, vitest_1.it)('should not add wrongVersions for external packages', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
257
257
|
const folders = ['/test/folder1'];
|
|
258
258
|
vitest_1.vi.mocked(mockConfig.getFolders).mockReturnValue(folders);
|
|
259
259
|
mockReadPackageJsonFileSync.mockReturnValue({
|
|
@@ -273,10 +273,8 @@ vitest_1.vi.mock('../../utils/readPackageJsonFile', () => ({
|
|
|
273
273
|
vitest_1.vi.mocked(mockConfig.getFolderOptions).mockReturnValue({});
|
|
274
274
|
const checker = new MonorepoChecker_1.MonorepoChecker(mockConfig);
|
|
275
275
|
const report = yield checker.check();
|
|
276
|
-
// Текущая реализация добавляет ошибку для внешних пакетов,
|
|
277
|
-
// так как actualVersion === undefined, и условие undefined !== "1.0.0" будет true
|
|
278
276
|
const exitCode = report.printResultAndGetExitCode();
|
|
279
|
-
(0, vitest_1.expect)(exitCode).toBe(
|
|
277
|
+
(0, vitest_1.expect)(exitCode).toBe(0);
|
|
280
278
|
}));
|
|
281
279
|
(0, vitest_1.it)('should handle empty dependencies and devDependencies', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
282
280
|
const folders = ['/test/folder1'];
|
|
@@ -4,8 +4,8 @@ const vitest_1 = require("vitest");
|
|
|
4
4
|
const console_1 = require("../../utils/console");
|
|
5
5
|
const index_1 = require("../index");
|
|
6
6
|
vitest_1.vi.mock('../../utils/console', () => ({
|
|
7
|
+
logDebug: vitest_1.vi.fn(),
|
|
7
8
|
logError: vitest_1.vi.fn(),
|
|
8
|
-
logInfo: vitest_1.vi.fn(),
|
|
9
9
|
}));
|
|
10
10
|
(0, vitest_1.describe)('Report', () => {
|
|
11
11
|
let report;
|
|
@@ -23,7 +23,7 @@ vitest_1.vi.mock('../../utils/console', () => ({
|
|
|
23
23
|
report.add(folder, state);
|
|
24
24
|
const exitCode = report.printResultAndGetExitCode();
|
|
25
25
|
(0, vitest_1.expect)(exitCode).toBe(1);
|
|
26
|
-
(0, vitest_1.expect)(console_1.
|
|
26
|
+
(0, vitest_1.expect)(console_1.logDebug).toHaveBeenCalled();
|
|
27
27
|
(0, vitest_1.expect)(console_1.logError).toHaveBeenCalled();
|
|
28
28
|
});
|
|
29
29
|
(0, vitest_1.it)('should throw error when trying to add state for existing folder', () => {
|
|
@@ -44,7 +44,7 @@ vitest_1.vi.mock('../../utils/console', () => ({
|
|
|
44
44
|
(0, vitest_1.it)('should return 0 when storage is empty', () => {
|
|
45
45
|
const exitCode = report.printResultAndGetExitCode();
|
|
46
46
|
(0, vitest_1.expect)(exitCode).toBe(0);
|
|
47
|
-
(0, vitest_1.expect)(console_1.
|
|
47
|
+
(0, vitest_1.expect)(console_1.logDebug).not.toHaveBeenCalled();
|
|
48
48
|
(0, vitest_1.expect)(console_1.logError).not.toHaveBeenCalled();
|
|
49
49
|
});
|
|
50
50
|
(0, vitest_1.it)('should return 0 when there are no errors', () => {
|
|
@@ -56,7 +56,7 @@ vitest_1.vi.mock('../../utils/console', () => ({
|
|
|
56
56
|
});
|
|
57
57
|
const exitCode = report.printResultAndGetExitCode();
|
|
58
58
|
(0, vitest_1.expect)(exitCode).toBe(0);
|
|
59
|
-
(0, vitest_1.expect)(console_1.
|
|
59
|
+
(0, vitest_1.expect)(console_1.logDebug).not.toHaveBeenCalled();
|
|
60
60
|
(0, vitest_1.expect)(console_1.logError).not.toHaveBeenCalled();
|
|
61
61
|
});
|
|
62
62
|
(0, vitest_1.it)('should return 1 and log errors when wrongVersions exist', () => {
|
|
@@ -67,7 +67,7 @@ vitest_1.vi.mock('../../utils/console', () => ({
|
|
|
67
67
|
});
|
|
68
68
|
const exitCode = report.printResultAndGetExitCode();
|
|
69
69
|
(0, vitest_1.expect)(exitCode).toBe(1);
|
|
70
|
-
(0, vitest_1.expect)(console_1.
|
|
70
|
+
(0, vitest_1.expect)(console_1.logDebug).toHaveBeenCalledWith(folder);
|
|
71
71
|
(0, vitest_1.expect)(console_1.logError).toHaveBeenCalledWith('\twrong version of internal packages:');
|
|
72
72
|
(0, vitest_1.expect)(console_1.logError).toHaveBeenCalledWith('\t\t@cloud-ru/package1');
|
|
73
73
|
(0, vitest_1.expect)(console_1.logError).toHaveBeenCalledWith('\t\t@cloud-ru/package2');
|
|
@@ -80,7 +80,7 @@ vitest_1.vi.mock('../../utils/console', () => ({
|
|
|
80
80
|
});
|
|
81
81
|
const exitCode = report.printResultAndGetExitCode();
|
|
82
82
|
(0, vitest_1.expect)(exitCode).toBe(1);
|
|
83
|
-
(0, vitest_1.expect)(console_1.
|
|
83
|
+
(0, vitest_1.expect)(console_1.logDebug).toHaveBeenCalledWith(folder);
|
|
84
84
|
(0, vitest_1.expect)(console_1.logError).toHaveBeenCalledWith('\tincorrect usage as dev dep of internal packages:');
|
|
85
85
|
(0, vitest_1.expect)(console_1.logError).toHaveBeenCalledWith('\t\t@cloud-ru/package1');
|
|
86
86
|
(0, vitest_1.expect)(console_1.logError).toHaveBeenCalledWith('\t\t@cloud-ru/package2');
|
|
@@ -93,7 +93,7 @@ vitest_1.vi.mock('../../utils/console', () => ({
|
|
|
93
93
|
});
|
|
94
94
|
const exitCode = report.printResultAndGetExitCode();
|
|
95
95
|
(0, vitest_1.expect)(exitCode).toBe(1);
|
|
96
|
-
(0, vitest_1.expect)(console_1.
|
|
96
|
+
(0, vitest_1.expect)(console_1.logDebug).toHaveBeenCalledWith(folder);
|
|
97
97
|
(0, vitest_1.expect)(console_1.logError).toHaveBeenCalledWith('\tunused dependencies:');
|
|
98
98
|
(0, vitest_1.expect)(console_1.logError).toHaveBeenCalledWith('\t\tunused-dep1');
|
|
99
99
|
(0, vitest_1.expect)(console_1.logError).toHaveBeenCalledWith('\t\tunused-dep2');
|
|
@@ -109,7 +109,7 @@ vitest_1.vi.mock('../../utils/console', () => ({
|
|
|
109
109
|
});
|
|
110
110
|
const exitCode = report.printResultAndGetExitCode();
|
|
111
111
|
(0, vitest_1.expect)(exitCode).toBe(1);
|
|
112
|
-
(0, vitest_1.expect)(console_1.
|
|
112
|
+
(0, vitest_1.expect)(console_1.logDebug).toHaveBeenCalledWith(folder);
|
|
113
113
|
(0, vitest_1.expect)(console_1.logError).toHaveBeenCalledWith('\tmissing dependencies:');
|
|
114
114
|
(0, vitest_1.expect)(console_1.logError).toHaveBeenCalledWith('\t\tmissing-package1');
|
|
115
115
|
(0, vitest_1.expect)(console_1.logError).toHaveBeenCalledWith('\t\tfile1.ts');
|
|
@@ -129,7 +129,7 @@ vitest_1.vi.mock('../../utils/console', () => ({
|
|
|
129
129
|
});
|
|
130
130
|
const exitCode = report.printResultAndGetExitCode();
|
|
131
131
|
(0, vitest_1.expect)(exitCode).toBe(1);
|
|
132
|
-
(0, vitest_1.expect)(console_1.
|
|
132
|
+
(0, vitest_1.expect)(console_1.logDebug).toHaveBeenCalledWith(folder);
|
|
133
133
|
(0, vitest_1.expect)(console_1.logError).toHaveBeenCalledWith('\twrong version of internal packages:');
|
|
134
134
|
(0, vitest_1.expect)(console_1.logError).toHaveBeenCalledWith('\t\t@cloud-ru/package1');
|
|
135
135
|
(0, vitest_1.expect)(console_1.logError).toHaveBeenCalledWith('\tincorrect usage as dev dep of internal packages:');
|
|
@@ -149,9 +149,9 @@ vitest_1.vi.mock('../../utils/console', () => ({
|
|
|
149
149
|
});
|
|
150
150
|
const exitCode = report.printResultAndGetExitCode();
|
|
151
151
|
(0, vitest_1.expect)(exitCode).toBe(1);
|
|
152
|
-
(0, vitest_1.expect)(console_1.
|
|
152
|
+
(0, vitest_1.expect)(console_1.logDebug).toHaveBeenCalledWith('packages/package1');
|
|
153
153
|
(0, vitest_1.expect)(console_1.logError).toHaveBeenCalledWith(vitest_1.expect.stringContaining('wrong version'));
|
|
154
|
-
(0, vitest_1.expect)(console_1.
|
|
154
|
+
(0, vitest_1.expect)(console_1.logDebug).toHaveBeenCalledWith('packages/package2');
|
|
155
155
|
(0, vitest_1.expect)(console_1.logError).toHaveBeenCalledWith(vitest_1.expect.stringContaining('unused dependencies'));
|
|
156
156
|
});
|
|
157
157
|
(0, vitest_1.it)('should use default values for undefined fields', () => {
|
|
@@ -159,7 +159,7 @@ vitest_1.vi.mock('../../utils/console', () => ({
|
|
|
159
159
|
report.add(folder, {});
|
|
160
160
|
const exitCode = report.printResultAndGetExitCode();
|
|
161
161
|
(0, vitest_1.expect)(exitCode).toBe(0);
|
|
162
|
-
(0, vitest_1.expect)(console_1.
|
|
162
|
+
(0, vitest_1.expect)(console_1.logDebug).not.toHaveBeenCalled();
|
|
163
163
|
(0, vitest_1.expect)(console_1.logError).not.toHaveBeenCalled();
|
|
164
164
|
});
|
|
165
165
|
(0, vitest_1.it)('should format messages with correct tabs', () => {
|
|
@@ -168,7 +168,7 @@ vitest_1.vi.mock('../../utils/console', () => ({
|
|
|
168
168
|
wrongVersions: ['@cloud-ru/package'],
|
|
169
169
|
});
|
|
170
170
|
report.printResultAndGetExitCode();
|
|
171
|
-
(0, vitest_1.expect)(console_1.
|
|
171
|
+
(0, vitest_1.expect)(console_1.logDebug).toHaveBeenCalledWith('packages/test-package');
|
|
172
172
|
(0, vitest_1.expect)(console_1.logError).toHaveBeenCalledWith('\twrong version of internal packages:');
|
|
173
173
|
(0, vitest_1.expect)(console_1.logError).toHaveBeenCalledWith('\t\t@cloud-ru/package');
|
|
174
174
|
});
|
package/dist/cjs/Report/index.js
CHANGED
|
@@ -15,7 +15,7 @@ class Report {
|
|
|
15
15
|
printResultAndGetExitCode() {
|
|
16
16
|
let exitCode = 0;
|
|
17
17
|
for (const [packageName, { dependencies = [], internalAsDev = [], wrongVersions = [], missing = {} },] of Object.entries(this.storage)) {
|
|
18
|
-
const messages = [['
|
|
18
|
+
const messages = [['debug', 0, packageName]];
|
|
19
19
|
if (wrongVersions.length) {
|
|
20
20
|
messages.push(['error', 1, 'wrong version of internal packages:']);
|
|
21
21
|
wrongVersions.forEach(dep => messages.push(['error', 2, dep]));
|
|
@@ -47,7 +47,7 @@ class Report {
|
|
|
47
47
|
}
|
|
48
48
|
printMessages(messages) {
|
|
49
49
|
for (const [level, tabs, message] of messages) {
|
|
50
|
-
const log = level === '
|
|
50
|
+
const log = level === 'debug' ? console_1.logDebug : console_1.logError;
|
|
51
51
|
log(`${'\t'.repeat(tabs)}${message}`);
|
|
52
52
|
}
|
|
53
53
|
}
|
|
@@ -20,7 +20,7 @@ const themes = {
|
|
|
20
20
|
safe_1.default.setTheme(themes);
|
|
21
21
|
const log = (message, theme = 'warn') => {
|
|
22
22
|
// eslint-disable-next-line no-console
|
|
23
|
-
console.log(safe_1.default[themes[theme]](`${message}
|
|
23
|
+
console.log(safe_1.default[themes[theme]](`${message}`));
|
|
24
24
|
};
|
|
25
25
|
const logError = (message) => log(message, 'error');
|
|
26
26
|
exports.logError = logError;
|
|
@@ -13,7 +13,7 @@ export class MonorepoChecker extends RepoChecker {
|
|
|
13
13
|
constructor(config) {
|
|
14
14
|
super(config);
|
|
15
15
|
this.actualVersions = {};
|
|
16
|
-
this.config.getFolders().reduce((acc, folder) => {
|
|
16
|
+
this.actualVersions = this.config.getFolders().reduce((acc, folder) => {
|
|
17
17
|
const pkg = readPackageJsonFileSync(folder);
|
|
18
18
|
acc[pkg.name] = pkg.version;
|
|
19
19
|
return acc;
|
|
@@ -28,10 +28,10 @@ export class MonorepoChecker extends RepoChecker {
|
|
|
28
28
|
if (pkg.dependencies) {
|
|
29
29
|
for (const [dep, version] of Object.entries(pkg.dependencies)) {
|
|
30
30
|
const actualVersion = this.actualVersions[dep];
|
|
31
|
-
if (actualVersion !== version) {
|
|
31
|
+
if (actualVersion && actualVersion !== version) {
|
|
32
32
|
const message = `"${dep}" has wrong version "${version}", but need "${actualVersion}".`;
|
|
33
33
|
if (result.wrongVersions) {
|
|
34
|
-
result.wrongVersions.push();
|
|
34
|
+
result.wrongVersions.push(message);
|
|
35
35
|
}
|
|
36
36
|
else {
|
|
37
37
|
result.wrongVersions = [message];
|
|
@@ -248,7 +248,7 @@ describe('MonorepoChecker', () => {
|
|
|
248
248
|
const exitCode = report.printResultAndGetExitCode();
|
|
249
249
|
expect(exitCode).toBe(1);
|
|
250
250
|
}));
|
|
251
|
-
it('should add wrongVersions for external packages
|
|
251
|
+
it('should not add wrongVersions for external packages', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
252
252
|
const folders = ['/test/folder1'];
|
|
253
253
|
vi.mocked(mockConfig.getFolders).mockReturnValue(folders);
|
|
254
254
|
mockReadPackageJsonFileSync.mockReturnValue({
|
|
@@ -268,10 +268,8 @@ describe('MonorepoChecker', () => {
|
|
|
268
268
|
vi.mocked(mockConfig.getFolderOptions).mockReturnValue({});
|
|
269
269
|
const checker = new MonorepoChecker(mockConfig);
|
|
270
270
|
const report = yield checker.check();
|
|
271
|
-
// Текущая реализация добавляет ошибку для внешних пакетов,
|
|
272
|
-
// так как actualVersion === undefined, и условие undefined !== "1.0.0" будет true
|
|
273
271
|
const exitCode = report.printResultAndGetExitCode();
|
|
274
|
-
expect(exitCode).toBe(
|
|
272
|
+
expect(exitCode).toBe(0);
|
|
275
273
|
}));
|
|
276
274
|
it('should handle empty dependencies and devDependencies', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
277
275
|
const folders = ['/test/folder1'];
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { beforeEach, describe, expect, it, vi } from 'vitest';
|
|
2
|
-
import {
|
|
2
|
+
import { logDebug, logError } from '../../utils/console';
|
|
3
3
|
import { Report } from '../index';
|
|
4
4
|
vi.mock('../../utils/console', () => ({
|
|
5
|
+
logDebug: vi.fn(),
|
|
5
6
|
logError: vi.fn(),
|
|
6
|
-
logInfo: vi.fn(),
|
|
7
7
|
}));
|
|
8
8
|
describe('Report', () => {
|
|
9
9
|
let report;
|
|
@@ -21,7 +21,7 @@ describe('Report', () => {
|
|
|
21
21
|
report.add(folder, state);
|
|
22
22
|
const exitCode = report.printResultAndGetExitCode();
|
|
23
23
|
expect(exitCode).toBe(1);
|
|
24
|
-
expect(
|
|
24
|
+
expect(logDebug).toHaveBeenCalled();
|
|
25
25
|
expect(logError).toHaveBeenCalled();
|
|
26
26
|
});
|
|
27
27
|
it('should throw error when trying to add state for existing folder', () => {
|
|
@@ -42,7 +42,7 @@ describe('Report', () => {
|
|
|
42
42
|
it('should return 0 when storage is empty', () => {
|
|
43
43
|
const exitCode = report.printResultAndGetExitCode();
|
|
44
44
|
expect(exitCode).toBe(0);
|
|
45
|
-
expect(
|
|
45
|
+
expect(logDebug).not.toHaveBeenCalled();
|
|
46
46
|
expect(logError).not.toHaveBeenCalled();
|
|
47
47
|
});
|
|
48
48
|
it('should return 0 when there are no errors', () => {
|
|
@@ -54,7 +54,7 @@ describe('Report', () => {
|
|
|
54
54
|
});
|
|
55
55
|
const exitCode = report.printResultAndGetExitCode();
|
|
56
56
|
expect(exitCode).toBe(0);
|
|
57
|
-
expect(
|
|
57
|
+
expect(logDebug).not.toHaveBeenCalled();
|
|
58
58
|
expect(logError).not.toHaveBeenCalled();
|
|
59
59
|
});
|
|
60
60
|
it('should return 1 and log errors when wrongVersions exist', () => {
|
|
@@ -65,7 +65,7 @@ describe('Report', () => {
|
|
|
65
65
|
});
|
|
66
66
|
const exitCode = report.printResultAndGetExitCode();
|
|
67
67
|
expect(exitCode).toBe(1);
|
|
68
|
-
expect(
|
|
68
|
+
expect(logDebug).toHaveBeenCalledWith(folder);
|
|
69
69
|
expect(logError).toHaveBeenCalledWith('\twrong version of internal packages:');
|
|
70
70
|
expect(logError).toHaveBeenCalledWith('\t\t@cloud-ru/package1');
|
|
71
71
|
expect(logError).toHaveBeenCalledWith('\t\t@cloud-ru/package2');
|
|
@@ -78,7 +78,7 @@ describe('Report', () => {
|
|
|
78
78
|
});
|
|
79
79
|
const exitCode = report.printResultAndGetExitCode();
|
|
80
80
|
expect(exitCode).toBe(1);
|
|
81
|
-
expect(
|
|
81
|
+
expect(logDebug).toHaveBeenCalledWith(folder);
|
|
82
82
|
expect(logError).toHaveBeenCalledWith('\tincorrect usage as dev dep of internal packages:');
|
|
83
83
|
expect(logError).toHaveBeenCalledWith('\t\t@cloud-ru/package1');
|
|
84
84
|
expect(logError).toHaveBeenCalledWith('\t\t@cloud-ru/package2');
|
|
@@ -91,7 +91,7 @@ describe('Report', () => {
|
|
|
91
91
|
});
|
|
92
92
|
const exitCode = report.printResultAndGetExitCode();
|
|
93
93
|
expect(exitCode).toBe(1);
|
|
94
|
-
expect(
|
|
94
|
+
expect(logDebug).toHaveBeenCalledWith(folder);
|
|
95
95
|
expect(logError).toHaveBeenCalledWith('\tunused dependencies:');
|
|
96
96
|
expect(logError).toHaveBeenCalledWith('\t\tunused-dep1');
|
|
97
97
|
expect(logError).toHaveBeenCalledWith('\t\tunused-dep2');
|
|
@@ -107,7 +107,7 @@ describe('Report', () => {
|
|
|
107
107
|
});
|
|
108
108
|
const exitCode = report.printResultAndGetExitCode();
|
|
109
109
|
expect(exitCode).toBe(1);
|
|
110
|
-
expect(
|
|
110
|
+
expect(logDebug).toHaveBeenCalledWith(folder);
|
|
111
111
|
expect(logError).toHaveBeenCalledWith('\tmissing dependencies:');
|
|
112
112
|
expect(logError).toHaveBeenCalledWith('\t\tmissing-package1');
|
|
113
113
|
expect(logError).toHaveBeenCalledWith('\t\tfile1.ts');
|
|
@@ -127,7 +127,7 @@ describe('Report', () => {
|
|
|
127
127
|
});
|
|
128
128
|
const exitCode = report.printResultAndGetExitCode();
|
|
129
129
|
expect(exitCode).toBe(1);
|
|
130
|
-
expect(
|
|
130
|
+
expect(logDebug).toHaveBeenCalledWith(folder);
|
|
131
131
|
expect(logError).toHaveBeenCalledWith('\twrong version of internal packages:');
|
|
132
132
|
expect(logError).toHaveBeenCalledWith('\t\t@cloud-ru/package1');
|
|
133
133
|
expect(logError).toHaveBeenCalledWith('\tincorrect usage as dev dep of internal packages:');
|
|
@@ -147,9 +147,9 @@ describe('Report', () => {
|
|
|
147
147
|
});
|
|
148
148
|
const exitCode = report.printResultAndGetExitCode();
|
|
149
149
|
expect(exitCode).toBe(1);
|
|
150
|
-
expect(
|
|
150
|
+
expect(logDebug).toHaveBeenCalledWith('packages/package1');
|
|
151
151
|
expect(logError).toHaveBeenCalledWith(expect.stringContaining('wrong version'));
|
|
152
|
-
expect(
|
|
152
|
+
expect(logDebug).toHaveBeenCalledWith('packages/package2');
|
|
153
153
|
expect(logError).toHaveBeenCalledWith(expect.stringContaining('unused dependencies'));
|
|
154
154
|
});
|
|
155
155
|
it('should use default values for undefined fields', () => {
|
|
@@ -157,7 +157,7 @@ describe('Report', () => {
|
|
|
157
157
|
report.add(folder, {});
|
|
158
158
|
const exitCode = report.printResultAndGetExitCode();
|
|
159
159
|
expect(exitCode).toBe(0);
|
|
160
|
-
expect(
|
|
160
|
+
expect(logDebug).not.toHaveBeenCalled();
|
|
161
161
|
expect(logError).not.toHaveBeenCalled();
|
|
162
162
|
});
|
|
163
163
|
it('should format messages with correct tabs', () => {
|
|
@@ -166,7 +166,7 @@ describe('Report', () => {
|
|
|
166
166
|
wrongVersions: ['@cloud-ru/package'],
|
|
167
167
|
});
|
|
168
168
|
report.printResultAndGetExitCode();
|
|
169
|
-
expect(
|
|
169
|
+
expect(logDebug).toHaveBeenCalledWith('packages/test-package');
|
|
170
170
|
expect(logError).toHaveBeenCalledWith('\twrong version of internal packages:');
|
|
171
171
|
expect(logError).toHaveBeenCalledWith('\t\t@cloud-ru/package');
|
|
172
172
|
});
|
package/dist/esm/Report/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { logDebug, logError } from '../utils/console';
|
|
2
2
|
export class Report {
|
|
3
3
|
constructor() {
|
|
4
4
|
this.storage = {};
|
|
@@ -12,7 +12,7 @@ export class Report {
|
|
|
12
12
|
printResultAndGetExitCode() {
|
|
13
13
|
let exitCode = 0;
|
|
14
14
|
for (const [packageName, { dependencies = [], internalAsDev = [], wrongVersions = [], missing = {} },] of Object.entries(this.storage)) {
|
|
15
|
-
const messages = [['
|
|
15
|
+
const messages = [['debug', 0, packageName]];
|
|
16
16
|
if (wrongVersions.length) {
|
|
17
17
|
messages.push(['error', 1, 'wrong version of internal packages:']);
|
|
18
18
|
wrongVersions.forEach(dep => messages.push(['error', 2, dep]));
|
|
@@ -44,7 +44,7 @@ export class Report {
|
|
|
44
44
|
}
|
|
45
45
|
printMessages(messages) {
|
|
46
46
|
for (const [level, tabs, message] of messages) {
|
|
47
|
-
const log = level === '
|
|
47
|
+
const log = level === 'debug' ? logDebug : logError;
|
|
48
48
|
log(`${'\t'.repeat(tabs)}${message}`);
|
|
49
49
|
}
|
|
50
50
|
}
|
|
@@ -14,7 +14,7 @@ const themes = {
|
|
|
14
14
|
colors.setTheme(themes);
|
|
15
15
|
const log = (message, theme = 'warn') => {
|
|
16
16
|
// eslint-disable-next-line no-console
|
|
17
|
-
console.log(colors[themes[theme]](`${message}
|
|
17
|
+
console.log(colors[themes[theme]](`${message}`));
|
|
18
18
|
};
|
|
19
19
|
export const logError = (message) => log(message, 'error');
|
|
20
20
|
export const logInfo = (message) => log(message, 'info');
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cloud-ru/ft-deps-validator",
|
|
3
|
-
"version": "1.1.2-preview-
|
|
3
|
+
"version": "1.1.2-preview-13c2d04.0",
|
|
4
4
|
"description": "Validator for unused, missing or wrong version dependencies in monorepo's packages",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -38,5 +38,5 @@
|
|
|
38
38
|
"glob": "10.5.0",
|
|
39
39
|
"yargs": "18.0.0"
|
|
40
40
|
},
|
|
41
|
-
"gitHead": "
|
|
41
|
+
"gitHead": "792fb24a0a872e694f0b4246a891b16c42aa8fdf"
|
|
42
42
|
}
|
|
@@ -8,7 +8,7 @@ export class MonorepoChecker extends RepoChecker {
|
|
|
8
8
|
constructor(config: MonorepoConfig) {
|
|
9
9
|
super(config);
|
|
10
10
|
|
|
11
|
-
this.config.getFolders().reduce((acc, folder) => {
|
|
11
|
+
this.actualVersions = this.config.getFolders().reduce((acc, folder) => {
|
|
12
12
|
const pkg = readPackageJsonFileSync(folder);
|
|
13
13
|
acc[pkg.name] = pkg.version;
|
|
14
14
|
return acc;
|
|
@@ -21,10 +21,10 @@ export class MonorepoChecker extends RepoChecker {
|
|
|
21
21
|
if (pkg.dependencies) {
|
|
22
22
|
for (const [dep, version] of Object.entries(pkg.dependencies)) {
|
|
23
23
|
const actualVersion = this.actualVersions[dep];
|
|
24
|
-
if (actualVersion !== version) {
|
|
24
|
+
if (actualVersion && actualVersion !== version) {
|
|
25
25
|
const message = `"${dep}" has wrong version "${version}", but need "${actualVersion}".`;
|
|
26
26
|
if (result.wrongVersions) {
|
|
27
|
-
result.wrongVersions.push();
|
|
27
|
+
result.wrongVersions.push(message);
|
|
28
28
|
} else {
|
|
29
29
|
result.wrongVersions = [message];
|
|
30
30
|
}
|
|
@@ -273,7 +273,7 @@ describe('MonorepoChecker', () => {
|
|
|
273
273
|
expect(exitCode).toBe(1);
|
|
274
274
|
});
|
|
275
275
|
|
|
276
|
-
it('should add wrongVersions for external packages
|
|
276
|
+
it('should not add wrongVersions for external packages', async () => {
|
|
277
277
|
const folders = ['/test/folder1'];
|
|
278
278
|
vi.mocked(mockConfig.getFolders).mockReturnValue(folders);
|
|
279
279
|
mockReadPackageJsonFileSync.mockReturnValue({
|
|
@@ -295,10 +295,8 @@ describe('MonorepoChecker', () => {
|
|
|
295
295
|
const checker = new MonorepoChecker(mockConfig);
|
|
296
296
|
const report = await checker.check();
|
|
297
297
|
|
|
298
|
-
// Текущая реализация добавляет ошибку для внешних пакетов,
|
|
299
|
-
// так как actualVersion === undefined, и условие undefined !== "1.0.0" будет true
|
|
300
298
|
const exitCode = report.printResultAndGetExitCode();
|
|
301
|
-
expect(exitCode).toBe(
|
|
299
|
+
expect(exitCode).toBe(0);
|
|
302
300
|
});
|
|
303
301
|
|
|
304
302
|
it('should handle empty dependencies and devDependencies', async () => {
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { beforeEach, describe, expect, it, vi } from 'vitest';
|
|
2
2
|
|
|
3
|
-
import {
|
|
3
|
+
import { logDebug, logError } from '../../utils/console';
|
|
4
4
|
import { Report } from '../index';
|
|
5
5
|
|
|
6
6
|
vi.mock('../../utils/console', () => ({
|
|
7
|
+
logDebug: vi.fn(),
|
|
7
8
|
logError: vi.fn(),
|
|
8
|
-
logInfo: vi.fn(),
|
|
9
9
|
}));
|
|
10
10
|
|
|
11
11
|
describe('Report', () => {
|
|
@@ -28,7 +28,7 @@ describe('Report', () => {
|
|
|
28
28
|
|
|
29
29
|
const exitCode = report.printResultAndGetExitCode();
|
|
30
30
|
expect(exitCode).toBe(1);
|
|
31
|
-
expect(
|
|
31
|
+
expect(logDebug).toHaveBeenCalled();
|
|
32
32
|
expect(logError).toHaveBeenCalled();
|
|
33
33
|
});
|
|
34
34
|
|
|
@@ -54,7 +54,7 @@ describe('Report', () => {
|
|
|
54
54
|
const exitCode = report.printResultAndGetExitCode();
|
|
55
55
|
|
|
56
56
|
expect(exitCode).toBe(0);
|
|
57
|
-
expect(
|
|
57
|
+
expect(logDebug).not.toHaveBeenCalled();
|
|
58
58
|
expect(logError).not.toHaveBeenCalled();
|
|
59
59
|
});
|
|
60
60
|
|
|
@@ -69,7 +69,7 @@ describe('Report', () => {
|
|
|
69
69
|
const exitCode = report.printResultAndGetExitCode();
|
|
70
70
|
|
|
71
71
|
expect(exitCode).toBe(0);
|
|
72
|
-
expect(
|
|
72
|
+
expect(logDebug).not.toHaveBeenCalled();
|
|
73
73
|
expect(logError).not.toHaveBeenCalled();
|
|
74
74
|
});
|
|
75
75
|
|
|
@@ -84,7 +84,7 @@ describe('Report', () => {
|
|
|
84
84
|
const exitCode = report.printResultAndGetExitCode();
|
|
85
85
|
|
|
86
86
|
expect(exitCode).toBe(1);
|
|
87
|
-
expect(
|
|
87
|
+
expect(logDebug).toHaveBeenCalledWith(folder);
|
|
88
88
|
expect(logError).toHaveBeenCalledWith('\twrong version of internal packages:');
|
|
89
89
|
expect(logError).toHaveBeenCalledWith('\t\t@cloud-ru/package1');
|
|
90
90
|
expect(logError).toHaveBeenCalledWith('\t\t@cloud-ru/package2');
|
|
@@ -101,7 +101,7 @@ describe('Report', () => {
|
|
|
101
101
|
const exitCode = report.printResultAndGetExitCode();
|
|
102
102
|
|
|
103
103
|
expect(exitCode).toBe(1);
|
|
104
|
-
expect(
|
|
104
|
+
expect(logDebug).toHaveBeenCalledWith(folder);
|
|
105
105
|
expect(logError).toHaveBeenCalledWith('\tincorrect usage as dev dep of internal packages:');
|
|
106
106
|
expect(logError).toHaveBeenCalledWith('\t\t@cloud-ru/package1');
|
|
107
107
|
expect(logError).toHaveBeenCalledWith('\t\t@cloud-ru/package2');
|
|
@@ -118,7 +118,7 @@ describe('Report', () => {
|
|
|
118
118
|
const exitCode = report.printResultAndGetExitCode();
|
|
119
119
|
|
|
120
120
|
expect(exitCode).toBe(1);
|
|
121
|
-
expect(
|
|
121
|
+
expect(logDebug).toHaveBeenCalledWith(folder);
|
|
122
122
|
expect(logError).toHaveBeenCalledWith('\tunused dependencies:');
|
|
123
123
|
expect(logError).toHaveBeenCalledWith('\t\tunused-dep1');
|
|
124
124
|
expect(logError).toHaveBeenCalledWith('\t\tunused-dep2');
|
|
@@ -138,7 +138,7 @@ describe('Report', () => {
|
|
|
138
138
|
const exitCode = report.printResultAndGetExitCode();
|
|
139
139
|
|
|
140
140
|
expect(exitCode).toBe(1);
|
|
141
|
-
expect(
|
|
141
|
+
expect(logDebug).toHaveBeenCalledWith(folder);
|
|
142
142
|
expect(logError).toHaveBeenCalledWith('\tmissing dependencies:');
|
|
143
143
|
expect(logError).toHaveBeenCalledWith('\t\tmissing-package1');
|
|
144
144
|
expect(logError).toHaveBeenCalledWith('\t\tfile1.ts');
|
|
@@ -162,7 +162,7 @@ describe('Report', () => {
|
|
|
162
162
|
const exitCode = report.printResultAndGetExitCode();
|
|
163
163
|
|
|
164
164
|
expect(exitCode).toBe(1);
|
|
165
|
-
expect(
|
|
165
|
+
expect(logDebug).toHaveBeenCalledWith(folder);
|
|
166
166
|
expect(logError).toHaveBeenCalledWith('\twrong version of internal packages:');
|
|
167
167
|
expect(logError).toHaveBeenCalledWith('\t\t@cloud-ru/package1');
|
|
168
168
|
expect(logError).toHaveBeenCalledWith('\tincorrect usage as dev dep of internal packages:');
|
|
@@ -186,9 +186,9 @@ describe('Report', () => {
|
|
|
186
186
|
const exitCode = report.printResultAndGetExitCode();
|
|
187
187
|
|
|
188
188
|
expect(exitCode).toBe(1);
|
|
189
|
-
expect(
|
|
189
|
+
expect(logDebug).toHaveBeenCalledWith('packages/package1');
|
|
190
190
|
expect(logError).toHaveBeenCalledWith(expect.stringContaining('wrong version'));
|
|
191
|
-
expect(
|
|
191
|
+
expect(logDebug).toHaveBeenCalledWith('packages/package2');
|
|
192
192
|
expect(logError).toHaveBeenCalledWith(expect.stringContaining('unused dependencies'));
|
|
193
193
|
});
|
|
194
194
|
|
|
@@ -200,7 +200,7 @@ describe('Report', () => {
|
|
|
200
200
|
const exitCode = report.printResultAndGetExitCode();
|
|
201
201
|
|
|
202
202
|
expect(exitCode).toBe(0);
|
|
203
|
-
expect(
|
|
203
|
+
expect(logDebug).not.toHaveBeenCalled();
|
|
204
204
|
expect(logError).not.toHaveBeenCalled();
|
|
205
205
|
});
|
|
206
206
|
|
|
@@ -213,7 +213,7 @@ describe('Report', () => {
|
|
|
213
213
|
|
|
214
214
|
report.printResultAndGetExitCode();
|
|
215
215
|
|
|
216
|
-
expect(
|
|
216
|
+
expect(logDebug).toHaveBeenCalledWith('packages/test-package');
|
|
217
217
|
expect(logError).toHaveBeenCalledWith('\twrong version of internal packages:');
|
|
218
218
|
expect(logError).toHaveBeenCalledWith('\t\t@cloud-ru/package');
|
|
219
219
|
});
|
package/src/Report/index.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { Results } from 'depcheck';
|
|
2
2
|
|
|
3
|
-
import {
|
|
3
|
+
import { logDebug, logError } from '../utils/console';
|
|
4
4
|
|
|
5
|
-
type Messages = ['
|
|
5
|
+
type Messages = ['debug' | 'error', number, string][];
|
|
6
6
|
|
|
7
7
|
export type CheckState = Partial<
|
|
8
8
|
Pick<Results, 'dependencies' | 'missing'> & {
|
|
@@ -29,7 +29,7 @@ export class Report {
|
|
|
29
29
|
packageName,
|
|
30
30
|
{ dependencies = [], internalAsDev = [], wrongVersions = [], missing = {} },
|
|
31
31
|
] of Object.entries(this.storage)) {
|
|
32
|
-
const messages: Messages = [['
|
|
32
|
+
const messages: Messages = [['debug', 0, packageName]];
|
|
33
33
|
|
|
34
34
|
if (wrongVersions.length) {
|
|
35
35
|
messages.push(['error', 1, 'wrong version of internal packages:']);
|
|
@@ -68,7 +68,7 @@ export class Report {
|
|
|
68
68
|
|
|
69
69
|
private printMessages(messages: Messages) {
|
|
70
70
|
for (const [level, tabs, message] of messages) {
|
|
71
|
-
const log = level === '
|
|
71
|
+
const log = level === 'debug' ? logDebug : logError;
|
|
72
72
|
log(`${'\t'.repeat(tabs)}${message}`);
|
|
73
73
|
}
|
|
74
74
|
}
|
package/src/utils/console.ts
CHANGED
|
@@ -17,7 +17,7 @@ colors.setTheme(themes);
|
|
|
17
17
|
|
|
18
18
|
const log = (message: string, theme: keyof typeof themes = 'warn'): void => {
|
|
19
19
|
// eslint-disable-next-line no-console
|
|
20
|
-
console.log(colors[themes[theme]](`${message}
|
|
20
|
+
console.log(colors[themes[theme]](`${message}`));
|
|
21
21
|
};
|
|
22
22
|
|
|
23
23
|
export const logError = (message: string) => log(message, 'error');
|