@cloud-ru/ft-deps-validator 1.1.2-preview-13c2d04.0 → 1.1.2-preview-6670171.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/Report/__tests__/Report.spec.js +46 -37
- package/dist/cjs/Report/index.js +15 -13
- package/dist/cjs/utils/console.d.ts +1 -0
- package/dist/cjs/utils/console.js +3 -1
- package/dist/esm/Report/__tests__/Report.spec.js +47 -38
- package/dist/esm/Report/index.js +16 -14
- package/dist/esm/utils/console.d.ts +1 -0
- package/dist/esm/utils/console.js +1 -0
- package/package.json +2 -2
- package/src/Report/__tests__/Report.spec.ts +47 -38
- package/src/Report/index.ts +18 -15
- package/src/utils/console.ts +1 -0
|
@@ -6,6 +6,8 @@ const index_1 = require("../index");
|
|
|
6
6
|
vitest_1.vi.mock('../../utils/console', () => ({
|
|
7
7
|
logDebug: vitest_1.vi.fn(),
|
|
8
8
|
logError: vitest_1.vi.fn(),
|
|
9
|
+
logInfo: vitest_1.vi.fn(),
|
|
10
|
+
logWarn: vitest_1.vi.fn(),
|
|
9
11
|
}));
|
|
10
12
|
(0, vitest_1.describe)('Report', () => {
|
|
11
13
|
let report;
|
|
@@ -24,6 +26,7 @@ vitest_1.vi.mock('../../utils/console', () => ({
|
|
|
24
26
|
const exitCode = report.printResultAndGetExitCode();
|
|
25
27
|
(0, vitest_1.expect)(exitCode).toBe(1);
|
|
26
28
|
(0, vitest_1.expect)(console_1.logDebug).toHaveBeenCalled();
|
|
29
|
+
(0, vitest_1.expect)(console_1.logWarn).toHaveBeenCalled();
|
|
27
30
|
(0, vitest_1.expect)(console_1.logError).toHaveBeenCalled();
|
|
28
31
|
});
|
|
29
32
|
(0, vitest_1.it)('should throw error when trying to add state for existing folder', () => {
|
|
@@ -45,7 +48,9 @@ vitest_1.vi.mock('../../utils/console', () => ({
|
|
|
45
48
|
const exitCode = report.printResultAndGetExitCode();
|
|
46
49
|
(0, vitest_1.expect)(exitCode).toBe(0);
|
|
47
50
|
(0, vitest_1.expect)(console_1.logDebug).not.toHaveBeenCalled();
|
|
51
|
+
(0, vitest_1.expect)(console_1.logWarn).not.toHaveBeenCalled();
|
|
48
52
|
(0, vitest_1.expect)(console_1.logError).not.toHaveBeenCalled();
|
|
53
|
+
(0, vitest_1.expect)(console_1.logInfo).toHaveBeenCalledWith('Dependencies have been checked. Everything is ok.');
|
|
49
54
|
});
|
|
50
55
|
(0, vitest_1.it)('should return 0 when there are no errors', () => {
|
|
51
56
|
report.add('packages/test-package', {
|
|
@@ -57,7 +62,9 @@ vitest_1.vi.mock('../../utils/console', () => ({
|
|
|
57
62
|
const exitCode = report.printResultAndGetExitCode();
|
|
58
63
|
(0, vitest_1.expect)(exitCode).toBe(0);
|
|
59
64
|
(0, vitest_1.expect)(console_1.logDebug).not.toHaveBeenCalled();
|
|
65
|
+
(0, vitest_1.expect)(console_1.logWarn).not.toHaveBeenCalled();
|
|
60
66
|
(0, vitest_1.expect)(console_1.logError).not.toHaveBeenCalled();
|
|
67
|
+
(0, vitest_1.expect)(console_1.logInfo).toHaveBeenCalledWith('Dependencies have been checked. Everything is ok.');
|
|
61
68
|
});
|
|
62
69
|
(0, vitest_1.it)('should return 1 and log errors when wrongVersions exist', () => {
|
|
63
70
|
const folder = 'packages/test-package';
|
|
@@ -67,10 +74,10 @@ vitest_1.vi.mock('../../utils/console', () => ({
|
|
|
67
74
|
});
|
|
68
75
|
const exitCode = report.printResultAndGetExitCode();
|
|
69
76
|
(0, vitest_1.expect)(exitCode).toBe(1);
|
|
70
|
-
(0, vitest_1.expect)(console_1.logDebug).toHaveBeenCalledWith(folder);
|
|
71
|
-
(0, vitest_1.expect)(console_1.
|
|
72
|
-
(0, vitest_1.expect)(console_1.logError).toHaveBeenCalledWith('
|
|
73
|
-
(0, vitest_1.expect)(console_1.logError).toHaveBeenCalledWith('
|
|
77
|
+
(0, vitest_1.expect)(console_1.logDebug).toHaveBeenCalledWith(`\n${folder}`);
|
|
78
|
+
(0, vitest_1.expect)(console_1.logWarn).toHaveBeenCalledWith(' wrong version of internal packages:');
|
|
79
|
+
(0, vitest_1.expect)(console_1.logError).toHaveBeenCalledWith(' @cloud-ru/package1');
|
|
80
|
+
(0, vitest_1.expect)(console_1.logError).toHaveBeenCalledWith(' @cloud-ru/package2');
|
|
74
81
|
});
|
|
75
82
|
(0, vitest_1.it)('should return 1 and log errors when internalAsDev exist', () => {
|
|
76
83
|
const folder = 'packages/test-package';
|
|
@@ -80,10 +87,10 @@ vitest_1.vi.mock('../../utils/console', () => ({
|
|
|
80
87
|
});
|
|
81
88
|
const exitCode = report.printResultAndGetExitCode();
|
|
82
89
|
(0, vitest_1.expect)(exitCode).toBe(1);
|
|
83
|
-
(0, vitest_1.expect)(console_1.logDebug).toHaveBeenCalledWith(folder);
|
|
84
|
-
(0, vitest_1.expect)(console_1.
|
|
85
|
-
(0, vitest_1.expect)(console_1.logError).toHaveBeenCalledWith('
|
|
86
|
-
(0, vitest_1.expect)(console_1.logError).toHaveBeenCalledWith('
|
|
90
|
+
(0, vitest_1.expect)(console_1.logDebug).toHaveBeenCalledWith(`\n${folder}`);
|
|
91
|
+
(0, vitest_1.expect)(console_1.logWarn).toHaveBeenCalledWith(' incorrect usage as dev dep of internal packages:');
|
|
92
|
+
(0, vitest_1.expect)(console_1.logError).toHaveBeenCalledWith(' @cloud-ru/package1');
|
|
93
|
+
(0, vitest_1.expect)(console_1.logError).toHaveBeenCalledWith(' @cloud-ru/package2');
|
|
87
94
|
});
|
|
88
95
|
(0, vitest_1.it)('should return 1 and log errors when dependencies exist', () => {
|
|
89
96
|
const folder = 'packages/test-package';
|
|
@@ -93,10 +100,10 @@ vitest_1.vi.mock('../../utils/console', () => ({
|
|
|
93
100
|
});
|
|
94
101
|
const exitCode = report.printResultAndGetExitCode();
|
|
95
102
|
(0, vitest_1.expect)(exitCode).toBe(1);
|
|
96
|
-
(0, vitest_1.expect)(console_1.logDebug).toHaveBeenCalledWith(folder);
|
|
97
|
-
(0, vitest_1.expect)(console_1.
|
|
98
|
-
(0, vitest_1.expect)(console_1.logError).toHaveBeenCalledWith('
|
|
99
|
-
(0, vitest_1.expect)(console_1.logError).toHaveBeenCalledWith('
|
|
103
|
+
(0, vitest_1.expect)(console_1.logDebug).toHaveBeenCalledWith(`\n${folder}`);
|
|
104
|
+
(0, vitest_1.expect)(console_1.logWarn).toHaveBeenCalledWith(' unused dependencies:');
|
|
105
|
+
(0, vitest_1.expect)(console_1.logError).toHaveBeenCalledWith(' unused-dep1');
|
|
106
|
+
(0, vitest_1.expect)(console_1.logError).toHaveBeenCalledWith(' unused-dep2');
|
|
100
107
|
});
|
|
101
108
|
(0, vitest_1.it)('should return 1 and log errors when missing dependencies exist', () => {
|
|
102
109
|
const folder = 'packages/test-package';
|
|
@@ -109,13 +116,13 @@ vitest_1.vi.mock('../../utils/console', () => ({
|
|
|
109
116
|
});
|
|
110
117
|
const exitCode = report.printResultAndGetExitCode();
|
|
111
118
|
(0, vitest_1.expect)(exitCode).toBe(1);
|
|
112
|
-
(0, vitest_1.expect)(console_1.logDebug).toHaveBeenCalledWith(folder);
|
|
113
|
-
(0, vitest_1.expect)(console_1.
|
|
114
|
-
(0, vitest_1.expect)(console_1.logError).toHaveBeenCalledWith('
|
|
115
|
-
(0, vitest_1.expect)(console_1.logError).toHaveBeenCalledWith('
|
|
116
|
-
(0, vitest_1.expect)(console_1.logError).toHaveBeenCalledWith('
|
|
117
|
-
(0, vitest_1.expect)(console_1.logError).toHaveBeenCalledWith('
|
|
118
|
-
(0, vitest_1.expect)(console_1.logError).toHaveBeenCalledWith('
|
|
119
|
+
(0, vitest_1.expect)(console_1.logDebug).toHaveBeenCalledWith(`\n${folder}`);
|
|
120
|
+
(0, vitest_1.expect)(console_1.logWarn).toHaveBeenCalledWith(' missing dependencies:');
|
|
121
|
+
(0, vitest_1.expect)(console_1.logError).toHaveBeenCalledWith(' missing-package1');
|
|
122
|
+
(0, vitest_1.expect)(console_1.logError).toHaveBeenCalledWith(' file1.ts');
|
|
123
|
+
(0, vitest_1.expect)(console_1.logError).toHaveBeenCalledWith(' file2.ts');
|
|
124
|
+
(0, vitest_1.expect)(console_1.logError).toHaveBeenCalledWith(' missing-package2');
|
|
125
|
+
(0, vitest_1.expect)(console_1.logError).toHaveBeenCalledWith(' file3.ts');
|
|
119
126
|
});
|
|
120
127
|
(0, vitest_1.it)('should handle all error types together', () => {
|
|
121
128
|
const folder = 'packages/test-package';
|
|
@@ -129,16 +136,16 @@ vitest_1.vi.mock('../../utils/console', () => ({
|
|
|
129
136
|
});
|
|
130
137
|
const exitCode = report.printResultAndGetExitCode();
|
|
131
138
|
(0, vitest_1.expect)(exitCode).toBe(1);
|
|
132
|
-
(0, vitest_1.expect)(console_1.logDebug).toHaveBeenCalledWith(folder);
|
|
133
|
-
(0, vitest_1.expect)(console_1.
|
|
134
|
-
(0, vitest_1.expect)(console_1.logError).toHaveBeenCalledWith('
|
|
135
|
-
(0, vitest_1.expect)(console_1.
|
|
136
|
-
(0, vitest_1.expect)(console_1.logError).toHaveBeenCalledWith('
|
|
137
|
-
(0, vitest_1.expect)(console_1.
|
|
138
|
-
(0, vitest_1.expect)(console_1.logError).toHaveBeenCalledWith('
|
|
139
|
-
(0, vitest_1.expect)(console_1.
|
|
140
|
-
(0, vitest_1.expect)(console_1.logError).toHaveBeenCalledWith('
|
|
141
|
-
(0, vitest_1.expect)(console_1.logError).toHaveBeenCalledWith('
|
|
139
|
+
(0, vitest_1.expect)(console_1.logDebug).toHaveBeenCalledWith(`\n${folder}`);
|
|
140
|
+
(0, vitest_1.expect)(console_1.logWarn).toHaveBeenCalledWith(' wrong version of internal packages:');
|
|
141
|
+
(0, vitest_1.expect)(console_1.logError).toHaveBeenCalledWith(' @cloud-ru/package1');
|
|
142
|
+
(0, vitest_1.expect)(console_1.logWarn).toHaveBeenCalledWith(' incorrect usage as dev dep of internal packages:');
|
|
143
|
+
(0, vitest_1.expect)(console_1.logError).toHaveBeenCalledWith(' @cloud-ru/package2');
|
|
144
|
+
(0, vitest_1.expect)(console_1.logWarn).toHaveBeenCalledWith(' unused dependencies:');
|
|
145
|
+
(0, vitest_1.expect)(console_1.logError).toHaveBeenCalledWith(' unused-dep');
|
|
146
|
+
(0, vitest_1.expect)(console_1.logWarn).toHaveBeenCalledWith(' missing dependencies:');
|
|
147
|
+
(0, vitest_1.expect)(console_1.logError).toHaveBeenCalledWith(' missing-package');
|
|
148
|
+
(0, vitest_1.expect)(console_1.logError).toHaveBeenCalledWith(' file.ts');
|
|
142
149
|
});
|
|
143
150
|
(0, vitest_1.it)('should process multiple packages', () => {
|
|
144
151
|
report.add('packages/package1', {
|
|
@@ -149,10 +156,10 @@ vitest_1.vi.mock('../../utils/console', () => ({
|
|
|
149
156
|
});
|
|
150
157
|
const exitCode = report.printResultAndGetExitCode();
|
|
151
158
|
(0, vitest_1.expect)(exitCode).toBe(1);
|
|
152
|
-
(0, vitest_1.expect)(console_1.logDebug).toHaveBeenCalledWith('
|
|
153
|
-
(0, vitest_1.expect)(console_1.
|
|
154
|
-
(0, vitest_1.expect)(console_1.logDebug).toHaveBeenCalledWith('
|
|
155
|
-
(0, vitest_1.expect)(console_1.
|
|
159
|
+
(0, vitest_1.expect)(console_1.logDebug).toHaveBeenCalledWith('\npackages/package1');
|
|
160
|
+
(0, vitest_1.expect)(console_1.logWarn).toHaveBeenCalledWith(vitest_1.expect.stringContaining('wrong version'));
|
|
161
|
+
(0, vitest_1.expect)(console_1.logDebug).toHaveBeenCalledWith('\npackages/package2');
|
|
162
|
+
(0, vitest_1.expect)(console_1.logWarn).toHaveBeenCalledWith(vitest_1.expect.stringContaining('unused dependencies'));
|
|
156
163
|
});
|
|
157
164
|
(0, vitest_1.it)('should use default values for undefined fields', () => {
|
|
158
165
|
const folder = 'packages/test-package';
|
|
@@ -160,17 +167,19 @@ vitest_1.vi.mock('../../utils/console', () => ({
|
|
|
160
167
|
const exitCode = report.printResultAndGetExitCode();
|
|
161
168
|
(0, vitest_1.expect)(exitCode).toBe(0);
|
|
162
169
|
(0, vitest_1.expect)(console_1.logDebug).not.toHaveBeenCalled();
|
|
170
|
+
(0, vitest_1.expect)(console_1.logWarn).not.toHaveBeenCalled();
|
|
163
171
|
(0, vitest_1.expect)(console_1.logError).not.toHaveBeenCalled();
|
|
172
|
+
(0, vitest_1.expect)(console_1.logInfo).toHaveBeenCalledWith('Dependencies have been checked. Everything is ok.');
|
|
164
173
|
});
|
|
165
|
-
(0, vitest_1.it)('should format messages with correct
|
|
174
|
+
(0, vitest_1.it)('should format messages with correct spaces', () => {
|
|
166
175
|
const folder = 'packages/test-package';
|
|
167
176
|
report.add(folder, {
|
|
168
177
|
wrongVersions: ['@cloud-ru/package'],
|
|
169
178
|
});
|
|
170
179
|
report.printResultAndGetExitCode();
|
|
171
|
-
(0, vitest_1.expect)(console_1.logDebug).toHaveBeenCalledWith(
|
|
172
|
-
(0, vitest_1.expect)(console_1.
|
|
173
|
-
(0, vitest_1.expect)(console_1.logError).toHaveBeenCalledWith('
|
|
180
|
+
(0, vitest_1.expect)(console_1.logDebug).toHaveBeenCalledWith(`\n${folder}`);
|
|
181
|
+
(0, vitest_1.expect)(console_1.logWarn).toHaveBeenCalledWith(' wrong version of internal packages:');
|
|
182
|
+
(0, vitest_1.expect)(console_1.logError).toHaveBeenCalledWith(' @cloud-ru/package');
|
|
174
183
|
});
|
|
175
184
|
});
|
|
176
185
|
});
|
package/dist/cjs/Report/index.js
CHANGED
|
@@ -15,26 +15,26 @@ 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 = [[console_1.logDebug, 0, `\n${packageName}`]];
|
|
19
19
|
if (wrongVersions.length) {
|
|
20
|
-
messages.push([
|
|
21
|
-
wrongVersions.forEach(dep => messages.push([
|
|
20
|
+
messages.push([console_1.logWarn, 1, 'wrong version of internal packages:']);
|
|
21
|
+
wrongVersions.forEach(dep => messages.push([console_1.logError, 2, dep]));
|
|
22
22
|
}
|
|
23
23
|
if (internalAsDev.length) {
|
|
24
|
-
messages.push([
|
|
25
|
-
internalAsDev.forEach(dep => messages.push([
|
|
24
|
+
messages.push([console_1.logWarn, 1, 'incorrect usage as dev dep of internal packages:']);
|
|
25
|
+
internalAsDev.forEach(dep => messages.push([console_1.logError, 2, dep]));
|
|
26
26
|
}
|
|
27
27
|
if (dependencies.length) {
|
|
28
|
-
messages.push([
|
|
29
|
-
dependencies.forEach(dep => messages.push([
|
|
28
|
+
messages.push([console_1.logWarn, 1, 'unused dependencies:']);
|
|
29
|
+
dependencies.forEach(dep => messages.push([console_1.logError, 2, dep]));
|
|
30
30
|
}
|
|
31
31
|
const missingEntities = Object.entries(missing);
|
|
32
32
|
if (missingEntities.length) {
|
|
33
|
-
messages.push([
|
|
33
|
+
messages.push([console_1.logWarn, 1, 'missing dependencies:']);
|
|
34
34
|
for (const [packageName, files] of missingEntities) {
|
|
35
|
-
messages.push([
|
|
35
|
+
messages.push([console_1.logError, 2, packageName]);
|
|
36
36
|
for (const file of files) {
|
|
37
|
-
messages.push([
|
|
37
|
+
messages.push([console_1.logError, 2, file]);
|
|
38
38
|
}
|
|
39
39
|
}
|
|
40
40
|
}
|
|
@@ -43,12 +43,14 @@ class Report {
|
|
|
43
43
|
this.printMessages(messages);
|
|
44
44
|
}
|
|
45
45
|
}
|
|
46
|
+
if (exitCode === 0) {
|
|
47
|
+
(0, console_1.logInfo)('Dependencies have been checked. Everything is ok.');
|
|
48
|
+
}
|
|
46
49
|
return exitCode;
|
|
47
50
|
}
|
|
48
51
|
printMessages(messages) {
|
|
49
|
-
for (const [
|
|
50
|
-
|
|
51
|
-
log(`${'\t'.repeat(tabs)}${message}`);
|
|
52
|
+
for (const [logger, indent, message] of messages) {
|
|
53
|
+
logger(`${' '.repeat(indent)}${message}`);
|
|
52
54
|
}
|
|
53
55
|
}
|
|
54
56
|
}
|
|
@@ -3,3 +3,4 @@ export declare const logInfo: (message: string) => void;
|
|
|
3
3
|
export declare const logHelp: (message: string) => void;
|
|
4
4
|
export declare const logSilly: (message: string) => void;
|
|
5
5
|
export declare const logDebug: (message: string) => void;
|
|
6
|
+
export declare const logWarn: (message: string) => void;
|
|
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.logDebug = exports.logSilly = exports.logHelp = exports.logInfo = exports.logError = void 0;
|
|
6
|
+
exports.logWarn = exports.logDebug = exports.logSilly = exports.logHelp = exports.logInfo = exports.logError = void 0;
|
|
7
7
|
const safe_1 = __importDefault(require("colors/safe"));
|
|
8
8
|
const themes = {
|
|
9
9
|
silly: 'rainbow',
|
|
@@ -32,3 +32,5 @@ const logSilly = (message) => log(message, 'silly');
|
|
|
32
32
|
exports.logSilly = logSilly;
|
|
33
33
|
const logDebug = (message) => log(message, 'debug');
|
|
34
34
|
exports.logDebug = logDebug;
|
|
35
|
+
const logWarn = (message) => log(message, 'warn');
|
|
36
|
+
exports.logWarn = logWarn;
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import { beforeEach, describe, expect, it, vi } from 'vitest';
|
|
2
|
-
import { logDebug, logError } from '../../utils/console';
|
|
2
|
+
import { logDebug, logError, logInfo, logWarn } from '../../utils/console';
|
|
3
3
|
import { Report } from '../index';
|
|
4
4
|
vi.mock('../../utils/console', () => ({
|
|
5
5
|
logDebug: vi.fn(),
|
|
6
6
|
logError: vi.fn(),
|
|
7
|
+
logInfo: vi.fn(),
|
|
8
|
+
logWarn: vi.fn(),
|
|
7
9
|
}));
|
|
8
10
|
describe('Report', () => {
|
|
9
11
|
let report;
|
|
@@ -22,6 +24,7 @@ describe('Report', () => {
|
|
|
22
24
|
const exitCode = report.printResultAndGetExitCode();
|
|
23
25
|
expect(exitCode).toBe(1);
|
|
24
26
|
expect(logDebug).toHaveBeenCalled();
|
|
27
|
+
expect(logWarn).toHaveBeenCalled();
|
|
25
28
|
expect(logError).toHaveBeenCalled();
|
|
26
29
|
});
|
|
27
30
|
it('should throw error when trying to add state for existing folder', () => {
|
|
@@ -43,7 +46,9 @@ describe('Report', () => {
|
|
|
43
46
|
const exitCode = report.printResultAndGetExitCode();
|
|
44
47
|
expect(exitCode).toBe(0);
|
|
45
48
|
expect(logDebug).not.toHaveBeenCalled();
|
|
49
|
+
expect(logWarn).not.toHaveBeenCalled();
|
|
46
50
|
expect(logError).not.toHaveBeenCalled();
|
|
51
|
+
expect(logInfo).toHaveBeenCalledWith('Dependencies have been checked. Everything is ok.');
|
|
47
52
|
});
|
|
48
53
|
it('should return 0 when there are no errors', () => {
|
|
49
54
|
report.add('packages/test-package', {
|
|
@@ -55,7 +60,9 @@ describe('Report', () => {
|
|
|
55
60
|
const exitCode = report.printResultAndGetExitCode();
|
|
56
61
|
expect(exitCode).toBe(0);
|
|
57
62
|
expect(logDebug).not.toHaveBeenCalled();
|
|
63
|
+
expect(logWarn).not.toHaveBeenCalled();
|
|
58
64
|
expect(logError).not.toHaveBeenCalled();
|
|
65
|
+
expect(logInfo).toHaveBeenCalledWith('Dependencies have been checked. Everything is ok.');
|
|
59
66
|
});
|
|
60
67
|
it('should return 1 and log errors when wrongVersions exist', () => {
|
|
61
68
|
const folder = 'packages/test-package';
|
|
@@ -65,10 +72,10 @@ describe('Report', () => {
|
|
|
65
72
|
});
|
|
66
73
|
const exitCode = report.printResultAndGetExitCode();
|
|
67
74
|
expect(exitCode).toBe(1);
|
|
68
|
-
expect(logDebug).toHaveBeenCalledWith(folder);
|
|
69
|
-
expect(
|
|
70
|
-
expect(logError).toHaveBeenCalledWith('
|
|
71
|
-
expect(logError).toHaveBeenCalledWith('
|
|
75
|
+
expect(logDebug).toHaveBeenCalledWith(`\n${folder}`);
|
|
76
|
+
expect(logWarn).toHaveBeenCalledWith(' wrong version of internal packages:');
|
|
77
|
+
expect(logError).toHaveBeenCalledWith(' @cloud-ru/package1');
|
|
78
|
+
expect(logError).toHaveBeenCalledWith(' @cloud-ru/package2');
|
|
72
79
|
});
|
|
73
80
|
it('should return 1 and log errors when internalAsDev exist', () => {
|
|
74
81
|
const folder = 'packages/test-package';
|
|
@@ -78,10 +85,10 @@ describe('Report', () => {
|
|
|
78
85
|
});
|
|
79
86
|
const exitCode = report.printResultAndGetExitCode();
|
|
80
87
|
expect(exitCode).toBe(1);
|
|
81
|
-
expect(logDebug).toHaveBeenCalledWith(folder);
|
|
82
|
-
expect(
|
|
83
|
-
expect(logError).toHaveBeenCalledWith('
|
|
84
|
-
expect(logError).toHaveBeenCalledWith('
|
|
88
|
+
expect(logDebug).toHaveBeenCalledWith(`\n${folder}`);
|
|
89
|
+
expect(logWarn).toHaveBeenCalledWith(' incorrect usage as dev dep of internal packages:');
|
|
90
|
+
expect(logError).toHaveBeenCalledWith(' @cloud-ru/package1');
|
|
91
|
+
expect(logError).toHaveBeenCalledWith(' @cloud-ru/package2');
|
|
85
92
|
});
|
|
86
93
|
it('should return 1 and log errors when dependencies exist', () => {
|
|
87
94
|
const folder = 'packages/test-package';
|
|
@@ -91,10 +98,10 @@ describe('Report', () => {
|
|
|
91
98
|
});
|
|
92
99
|
const exitCode = report.printResultAndGetExitCode();
|
|
93
100
|
expect(exitCode).toBe(1);
|
|
94
|
-
expect(logDebug).toHaveBeenCalledWith(folder);
|
|
95
|
-
expect(
|
|
96
|
-
expect(logError).toHaveBeenCalledWith('
|
|
97
|
-
expect(logError).toHaveBeenCalledWith('
|
|
101
|
+
expect(logDebug).toHaveBeenCalledWith(`\n${folder}`);
|
|
102
|
+
expect(logWarn).toHaveBeenCalledWith(' unused dependencies:');
|
|
103
|
+
expect(logError).toHaveBeenCalledWith(' unused-dep1');
|
|
104
|
+
expect(logError).toHaveBeenCalledWith(' unused-dep2');
|
|
98
105
|
});
|
|
99
106
|
it('should return 1 and log errors when missing dependencies exist', () => {
|
|
100
107
|
const folder = 'packages/test-package';
|
|
@@ -107,13 +114,13 @@ describe('Report', () => {
|
|
|
107
114
|
});
|
|
108
115
|
const exitCode = report.printResultAndGetExitCode();
|
|
109
116
|
expect(exitCode).toBe(1);
|
|
110
|
-
expect(logDebug).toHaveBeenCalledWith(folder);
|
|
111
|
-
expect(
|
|
112
|
-
expect(logError).toHaveBeenCalledWith('
|
|
113
|
-
expect(logError).toHaveBeenCalledWith('
|
|
114
|
-
expect(logError).toHaveBeenCalledWith('
|
|
115
|
-
expect(logError).toHaveBeenCalledWith('
|
|
116
|
-
expect(logError).toHaveBeenCalledWith('
|
|
117
|
+
expect(logDebug).toHaveBeenCalledWith(`\n${folder}`);
|
|
118
|
+
expect(logWarn).toHaveBeenCalledWith(' missing dependencies:');
|
|
119
|
+
expect(logError).toHaveBeenCalledWith(' missing-package1');
|
|
120
|
+
expect(logError).toHaveBeenCalledWith(' file1.ts');
|
|
121
|
+
expect(logError).toHaveBeenCalledWith(' file2.ts');
|
|
122
|
+
expect(logError).toHaveBeenCalledWith(' missing-package2');
|
|
123
|
+
expect(logError).toHaveBeenCalledWith(' file3.ts');
|
|
117
124
|
});
|
|
118
125
|
it('should handle all error types together', () => {
|
|
119
126
|
const folder = 'packages/test-package';
|
|
@@ -127,16 +134,16 @@ describe('Report', () => {
|
|
|
127
134
|
});
|
|
128
135
|
const exitCode = report.printResultAndGetExitCode();
|
|
129
136
|
expect(exitCode).toBe(1);
|
|
130
|
-
expect(logDebug).toHaveBeenCalledWith(folder);
|
|
131
|
-
expect(
|
|
132
|
-
expect(logError).toHaveBeenCalledWith('
|
|
133
|
-
expect(
|
|
134
|
-
expect(logError).toHaveBeenCalledWith('
|
|
135
|
-
expect(
|
|
136
|
-
expect(logError).toHaveBeenCalledWith('
|
|
137
|
-
expect(
|
|
138
|
-
expect(logError).toHaveBeenCalledWith('
|
|
139
|
-
expect(logError).toHaveBeenCalledWith('
|
|
137
|
+
expect(logDebug).toHaveBeenCalledWith(`\n${folder}`);
|
|
138
|
+
expect(logWarn).toHaveBeenCalledWith(' wrong version of internal packages:');
|
|
139
|
+
expect(logError).toHaveBeenCalledWith(' @cloud-ru/package1');
|
|
140
|
+
expect(logWarn).toHaveBeenCalledWith(' incorrect usage as dev dep of internal packages:');
|
|
141
|
+
expect(logError).toHaveBeenCalledWith(' @cloud-ru/package2');
|
|
142
|
+
expect(logWarn).toHaveBeenCalledWith(' unused dependencies:');
|
|
143
|
+
expect(logError).toHaveBeenCalledWith(' unused-dep');
|
|
144
|
+
expect(logWarn).toHaveBeenCalledWith(' missing dependencies:');
|
|
145
|
+
expect(logError).toHaveBeenCalledWith(' missing-package');
|
|
146
|
+
expect(logError).toHaveBeenCalledWith(' file.ts');
|
|
140
147
|
});
|
|
141
148
|
it('should process multiple packages', () => {
|
|
142
149
|
report.add('packages/package1', {
|
|
@@ -147,10 +154,10 @@ describe('Report', () => {
|
|
|
147
154
|
});
|
|
148
155
|
const exitCode = report.printResultAndGetExitCode();
|
|
149
156
|
expect(exitCode).toBe(1);
|
|
150
|
-
expect(logDebug).toHaveBeenCalledWith('
|
|
151
|
-
expect(
|
|
152
|
-
expect(logDebug).toHaveBeenCalledWith('
|
|
153
|
-
expect(
|
|
157
|
+
expect(logDebug).toHaveBeenCalledWith('\npackages/package1');
|
|
158
|
+
expect(logWarn).toHaveBeenCalledWith(expect.stringContaining('wrong version'));
|
|
159
|
+
expect(logDebug).toHaveBeenCalledWith('\npackages/package2');
|
|
160
|
+
expect(logWarn).toHaveBeenCalledWith(expect.stringContaining('unused dependencies'));
|
|
154
161
|
});
|
|
155
162
|
it('should use default values for undefined fields', () => {
|
|
156
163
|
const folder = 'packages/test-package';
|
|
@@ -158,17 +165,19 @@ describe('Report', () => {
|
|
|
158
165
|
const exitCode = report.printResultAndGetExitCode();
|
|
159
166
|
expect(exitCode).toBe(0);
|
|
160
167
|
expect(logDebug).not.toHaveBeenCalled();
|
|
168
|
+
expect(logWarn).not.toHaveBeenCalled();
|
|
161
169
|
expect(logError).not.toHaveBeenCalled();
|
|
170
|
+
expect(logInfo).toHaveBeenCalledWith('Dependencies have been checked. Everything is ok.');
|
|
162
171
|
});
|
|
163
|
-
it('should format messages with correct
|
|
172
|
+
it('should format messages with correct spaces', () => {
|
|
164
173
|
const folder = 'packages/test-package';
|
|
165
174
|
report.add(folder, {
|
|
166
175
|
wrongVersions: ['@cloud-ru/package'],
|
|
167
176
|
});
|
|
168
177
|
report.printResultAndGetExitCode();
|
|
169
|
-
expect(logDebug).toHaveBeenCalledWith(
|
|
170
|
-
expect(
|
|
171
|
-
expect(logError).toHaveBeenCalledWith('
|
|
178
|
+
expect(logDebug).toHaveBeenCalledWith(`\n${folder}`);
|
|
179
|
+
expect(logWarn).toHaveBeenCalledWith(' wrong version of internal packages:');
|
|
180
|
+
expect(logError).toHaveBeenCalledWith(' @cloud-ru/package');
|
|
172
181
|
});
|
|
173
182
|
});
|
|
174
183
|
});
|
package/dist/esm/Report/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { logDebug, logError } from '../utils/console';
|
|
1
|
+
import { logDebug, logError, logInfo, logWarn } from '../utils/console';
|
|
2
2
|
export class Report {
|
|
3
3
|
constructor() {
|
|
4
4
|
this.storage = {};
|
|
@@ -12,26 +12,26 @@ 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 = [[logDebug, 0, `\n${packageName}`]];
|
|
16
16
|
if (wrongVersions.length) {
|
|
17
|
-
messages.push([
|
|
18
|
-
wrongVersions.forEach(dep => messages.push([
|
|
17
|
+
messages.push([logWarn, 1, 'wrong version of internal packages:']);
|
|
18
|
+
wrongVersions.forEach(dep => messages.push([logError, 2, dep]));
|
|
19
19
|
}
|
|
20
20
|
if (internalAsDev.length) {
|
|
21
|
-
messages.push([
|
|
22
|
-
internalAsDev.forEach(dep => messages.push([
|
|
21
|
+
messages.push([logWarn, 1, 'incorrect usage as dev dep of internal packages:']);
|
|
22
|
+
internalAsDev.forEach(dep => messages.push([logError, 2, dep]));
|
|
23
23
|
}
|
|
24
24
|
if (dependencies.length) {
|
|
25
|
-
messages.push([
|
|
26
|
-
dependencies.forEach(dep => messages.push([
|
|
25
|
+
messages.push([logWarn, 1, 'unused dependencies:']);
|
|
26
|
+
dependencies.forEach(dep => messages.push([logError, 2, dep]));
|
|
27
27
|
}
|
|
28
28
|
const missingEntities = Object.entries(missing);
|
|
29
29
|
if (missingEntities.length) {
|
|
30
|
-
messages.push([
|
|
30
|
+
messages.push([logWarn, 1, 'missing dependencies:']);
|
|
31
31
|
for (const [packageName, files] of missingEntities) {
|
|
32
|
-
messages.push([
|
|
32
|
+
messages.push([logError, 2, packageName]);
|
|
33
33
|
for (const file of files) {
|
|
34
|
-
messages.push([
|
|
34
|
+
messages.push([logError, 2, file]);
|
|
35
35
|
}
|
|
36
36
|
}
|
|
37
37
|
}
|
|
@@ -40,12 +40,14 @@ export class Report {
|
|
|
40
40
|
this.printMessages(messages);
|
|
41
41
|
}
|
|
42
42
|
}
|
|
43
|
+
if (exitCode === 0) {
|
|
44
|
+
logInfo('Dependencies have been checked. Everything is ok.');
|
|
45
|
+
}
|
|
43
46
|
return exitCode;
|
|
44
47
|
}
|
|
45
48
|
printMessages(messages) {
|
|
46
|
-
for (const [
|
|
47
|
-
|
|
48
|
-
log(`${'\t'.repeat(tabs)}${message}`);
|
|
49
|
+
for (const [logger, indent, message] of messages) {
|
|
50
|
+
logger(`${' '.repeat(indent)}${message}`);
|
|
49
51
|
}
|
|
50
52
|
}
|
|
51
53
|
}
|
|
@@ -3,3 +3,4 @@ export declare const logInfo: (message: string) => void;
|
|
|
3
3
|
export declare const logHelp: (message: string) => void;
|
|
4
4
|
export declare const logSilly: (message: string) => void;
|
|
5
5
|
export declare const logDebug: (message: string) => void;
|
|
6
|
+
export declare const logWarn: (message: string) => void;
|
|
@@ -21,3 +21,4 @@ export const logInfo = (message) => log(message, 'info');
|
|
|
21
21
|
export const logHelp = (message) => log(message, 'help');
|
|
22
22
|
export const logSilly = (message) => log(message, 'silly');
|
|
23
23
|
export const logDebug = (message) => log(message, 'debug');
|
|
24
|
+
export const logWarn = (message) => log(message, 'warn');
|
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-6670171.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": "cba3732de2facd5c1ebf32df6e1ec3e09f87790b"
|
|
42
42
|
}
|
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
import { beforeEach, describe, expect, it, vi } from 'vitest';
|
|
2
2
|
|
|
3
|
-
import { logDebug, logError } from '../../utils/console';
|
|
3
|
+
import { logDebug, logError, logInfo, logWarn } from '../../utils/console';
|
|
4
4
|
import { Report } from '../index';
|
|
5
5
|
|
|
6
6
|
vi.mock('../../utils/console', () => ({
|
|
7
7
|
logDebug: vi.fn(),
|
|
8
8
|
logError: vi.fn(),
|
|
9
|
+
logInfo: vi.fn(),
|
|
10
|
+
logWarn: vi.fn(),
|
|
9
11
|
}));
|
|
10
12
|
|
|
11
13
|
describe('Report', () => {
|
|
@@ -29,6 +31,7 @@ describe('Report', () => {
|
|
|
29
31
|
const exitCode = report.printResultAndGetExitCode();
|
|
30
32
|
expect(exitCode).toBe(1);
|
|
31
33
|
expect(logDebug).toHaveBeenCalled();
|
|
34
|
+
expect(logWarn).toHaveBeenCalled();
|
|
32
35
|
expect(logError).toHaveBeenCalled();
|
|
33
36
|
});
|
|
34
37
|
|
|
@@ -55,7 +58,9 @@ describe('Report', () => {
|
|
|
55
58
|
|
|
56
59
|
expect(exitCode).toBe(0);
|
|
57
60
|
expect(logDebug).not.toHaveBeenCalled();
|
|
61
|
+
expect(logWarn).not.toHaveBeenCalled();
|
|
58
62
|
expect(logError).not.toHaveBeenCalled();
|
|
63
|
+
expect(logInfo).toHaveBeenCalledWith('Dependencies have been checked. Everything is ok.');
|
|
59
64
|
});
|
|
60
65
|
|
|
61
66
|
it('should return 0 when there are no errors', () => {
|
|
@@ -70,7 +75,9 @@ describe('Report', () => {
|
|
|
70
75
|
|
|
71
76
|
expect(exitCode).toBe(0);
|
|
72
77
|
expect(logDebug).not.toHaveBeenCalled();
|
|
78
|
+
expect(logWarn).not.toHaveBeenCalled();
|
|
73
79
|
expect(logError).not.toHaveBeenCalled();
|
|
80
|
+
expect(logInfo).toHaveBeenCalledWith('Dependencies have been checked. Everything is ok.');
|
|
74
81
|
});
|
|
75
82
|
|
|
76
83
|
it('should return 1 and log errors when wrongVersions exist', () => {
|
|
@@ -84,10 +91,10 @@ describe('Report', () => {
|
|
|
84
91
|
const exitCode = report.printResultAndGetExitCode();
|
|
85
92
|
|
|
86
93
|
expect(exitCode).toBe(1);
|
|
87
|
-
expect(logDebug).toHaveBeenCalledWith(folder);
|
|
88
|
-
expect(
|
|
89
|
-
expect(logError).toHaveBeenCalledWith('
|
|
90
|
-
expect(logError).toHaveBeenCalledWith('
|
|
94
|
+
expect(logDebug).toHaveBeenCalledWith(`\n${folder}`);
|
|
95
|
+
expect(logWarn).toHaveBeenCalledWith(' wrong version of internal packages:');
|
|
96
|
+
expect(logError).toHaveBeenCalledWith(' @cloud-ru/package1');
|
|
97
|
+
expect(logError).toHaveBeenCalledWith(' @cloud-ru/package2');
|
|
91
98
|
});
|
|
92
99
|
|
|
93
100
|
it('should return 1 and log errors when internalAsDev exist', () => {
|
|
@@ -101,10 +108,10 @@ describe('Report', () => {
|
|
|
101
108
|
const exitCode = report.printResultAndGetExitCode();
|
|
102
109
|
|
|
103
110
|
expect(exitCode).toBe(1);
|
|
104
|
-
expect(logDebug).toHaveBeenCalledWith(folder);
|
|
105
|
-
expect(
|
|
106
|
-
expect(logError).toHaveBeenCalledWith('
|
|
107
|
-
expect(logError).toHaveBeenCalledWith('
|
|
111
|
+
expect(logDebug).toHaveBeenCalledWith(`\n${folder}`);
|
|
112
|
+
expect(logWarn).toHaveBeenCalledWith(' incorrect usage as dev dep of internal packages:');
|
|
113
|
+
expect(logError).toHaveBeenCalledWith(' @cloud-ru/package1');
|
|
114
|
+
expect(logError).toHaveBeenCalledWith(' @cloud-ru/package2');
|
|
108
115
|
});
|
|
109
116
|
|
|
110
117
|
it('should return 1 and log errors when dependencies exist', () => {
|
|
@@ -118,10 +125,10 @@ describe('Report', () => {
|
|
|
118
125
|
const exitCode = report.printResultAndGetExitCode();
|
|
119
126
|
|
|
120
127
|
expect(exitCode).toBe(1);
|
|
121
|
-
expect(logDebug).toHaveBeenCalledWith(folder);
|
|
122
|
-
expect(
|
|
123
|
-
expect(logError).toHaveBeenCalledWith('
|
|
124
|
-
expect(logError).toHaveBeenCalledWith('
|
|
128
|
+
expect(logDebug).toHaveBeenCalledWith(`\n${folder}`);
|
|
129
|
+
expect(logWarn).toHaveBeenCalledWith(' unused dependencies:');
|
|
130
|
+
expect(logError).toHaveBeenCalledWith(' unused-dep1');
|
|
131
|
+
expect(logError).toHaveBeenCalledWith(' unused-dep2');
|
|
125
132
|
});
|
|
126
133
|
|
|
127
134
|
it('should return 1 and log errors when missing dependencies exist', () => {
|
|
@@ -138,13 +145,13 @@ describe('Report', () => {
|
|
|
138
145
|
const exitCode = report.printResultAndGetExitCode();
|
|
139
146
|
|
|
140
147
|
expect(exitCode).toBe(1);
|
|
141
|
-
expect(logDebug).toHaveBeenCalledWith(folder);
|
|
142
|
-
expect(
|
|
143
|
-
expect(logError).toHaveBeenCalledWith('
|
|
144
|
-
expect(logError).toHaveBeenCalledWith('
|
|
145
|
-
expect(logError).toHaveBeenCalledWith('
|
|
146
|
-
expect(logError).toHaveBeenCalledWith('
|
|
147
|
-
expect(logError).toHaveBeenCalledWith('
|
|
148
|
+
expect(logDebug).toHaveBeenCalledWith(`\n${folder}`);
|
|
149
|
+
expect(logWarn).toHaveBeenCalledWith(' missing dependencies:');
|
|
150
|
+
expect(logError).toHaveBeenCalledWith(' missing-package1');
|
|
151
|
+
expect(logError).toHaveBeenCalledWith(' file1.ts');
|
|
152
|
+
expect(logError).toHaveBeenCalledWith(' file2.ts');
|
|
153
|
+
expect(logError).toHaveBeenCalledWith(' missing-package2');
|
|
154
|
+
expect(logError).toHaveBeenCalledWith(' file3.ts');
|
|
148
155
|
});
|
|
149
156
|
|
|
150
157
|
it('should handle all error types together', () => {
|
|
@@ -162,16 +169,16 @@ describe('Report', () => {
|
|
|
162
169
|
const exitCode = report.printResultAndGetExitCode();
|
|
163
170
|
|
|
164
171
|
expect(exitCode).toBe(1);
|
|
165
|
-
expect(logDebug).toHaveBeenCalledWith(folder);
|
|
166
|
-
expect(
|
|
167
|
-
expect(logError).toHaveBeenCalledWith('
|
|
168
|
-
expect(
|
|
169
|
-
expect(logError).toHaveBeenCalledWith('
|
|
170
|
-
expect(
|
|
171
|
-
expect(logError).toHaveBeenCalledWith('
|
|
172
|
-
expect(
|
|
173
|
-
expect(logError).toHaveBeenCalledWith('
|
|
174
|
-
expect(logError).toHaveBeenCalledWith('
|
|
172
|
+
expect(logDebug).toHaveBeenCalledWith(`\n${folder}`);
|
|
173
|
+
expect(logWarn).toHaveBeenCalledWith(' wrong version of internal packages:');
|
|
174
|
+
expect(logError).toHaveBeenCalledWith(' @cloud-ru/package1');
|
|
175
|
+
expect(logWarn).toHaveBeenCalledWith(' incorrect usage as dev dep of internal packages:');
|
|
176
|
+
expect(logError).toHaveBeenCalledWith(' @cloud-ru/package2');
|
|
177
|
+
expect(logWarn).toHaveBeenCalledWith(' unused dependencies:');
|
|
178
|
+
expect(logError).toHaveBeenCalledWith(' unused-dep');
|
|
179
|
+
expect(logWarn).toHaveBeenCalledWith(' missing dependencies:');
|
|
180
|
+
expect(logError).toHaveBeenCalledWith(' missing-package');
|
|
181
|
+
expect(logError).toHaveBeenCalledWith(' file.ts');
|
|
175
182
|
});
|
|
176
183
|
|
|
177
184
|
it('should process multiple packages', () => {
|
|
@@ -186,10 +193,10 @@ describe('Report', () => {
|
|
|
186
193
|
const exitCode = report.printResultAndGetExitCode();
|
|
187
194
|
|
|
188
195
|
expect(exitCode).toBe(1);
|
|
189
|
-
expect(logDebug).toHaveBeenCalledWith('
|
|
190
|
-
expect(
|
|
191
|
-
expect(logDebug).toHaveBeenCalledWith('
|
|
192
|
-
expect(
|
|
196
|
+
expect(logDebug).toHaveBeenCalledWith('\npackages/package1');
|
|
197
|
+
expect(logWarn).toHaveBeenCalledWith(expect.stringContaining('wrong version'));
|
|
198
|
+
expect(logDebug).toHaveBeenCalledWith('\npackages/package2');
|
|
199
|
+
expect(logWarn).toHaveBeenCalledWith(expect.stringContaining('unused dependencies'));
|
|
193
200
|
});
|
|
194
201
|
|
|
195
202
|
it('should use default values for undefined fields', () => {
|
|
@@ -201,10 +208,12 @@ describe('Report', () => {
|
|
|
201
208
|
|
|
202
209
|
expect(exitCode).toBe(0);
|
|
203
210
|
expect(logDebug).not.toHaveBeenCalled();
|
|
211
|
+
expect(logWarn).not.toHaveBeenCalled();
|
|
204
212
|
expect(logError).not.toHaveBeenCalled();
|
|
213
|
+
expect(logInfo).toHaveBeenCalledWith('Dependencies have been checked. Everything is ok.');
|
|
205
214
|
});
|
|
206
215
|
|
|
207
|
-
it('should format messages with correct
|
|
216
|
+
it('should format messages with correct spaces', () => {
|
|
208
217
|
const folder = 'packages/test-package';
|
|
209
218
|
|
|
210
219
|
report.add(folder, {
|
|
@@ -213,9 +222,9 @@ describe('Report', () => {
|
|
|
213
222
|
|
|
214
223
|
report.printResultAndGetExitCode();
|
|
215
224
|
|
|
216
|
-
expect(logDebug).toHaveBeenCalledWith(
|
|
217
|
-
expect(
|
|
218
|
-
expect(logError).toHaveBeenCalledWith('
|
|
225
|
+
expect(logDebug).toHaveBeenCalledWith(`\n${folder}`);
|
|
226
|
+
expect(logWarn).toHaveBeenCalledWith(' wrong version of internal packages:');
|
|
227
|
+
expect(logError).toHaveBeenCalledWith(' @cloud-ru/package');
|
|
219
228
|
});
|
|
220
229
|
});
|
|
221
230
|
});
|
package/src/Report/index.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { Results } from 'depcheck';
|
|
2
2
|
|
|
3
|
-
import { logDebug, logError } from '../utils/console';
|
|
3
|
+
import { logDebug, logError, logInfo, logWarn } from '../utils/console';
|
|
4
4
|
|
|
5
|
-
type Messages = [
|
|
5
|
+
type Messages = [typeof logDebug | typeof logError | typeof logWarn, number, string][];
|
|
6
6
|
|
|
7
7
|
export type CheckState = Partial<
|
|
8
8
|
Pick<Results, 'dependencies' | 'missing'> & {
|
|
@@ -29,30 +29,30 @@ 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 = [[logDebug, 0, `\n${packageName}`]];
|
|
33
33
|
|
|
34
34
|
if (wrongVersions.length) {
|
|
35
|
-
messages.push([
|
|
36
|
-
wrongVersions.forEach(dep => messages.push([
|
|
35
|
+
messages.push([logWarn, 1, 'wrong version of internal packages:']);
|
|
36
|
+
wrongVersions.forEach(dep => messages.push([logError, 2, dep]));
|
|
37
37
|
}
|
|
38
38
|
|
|
39
39
|
if (internalAsDev.length) {
|
|
40
|
-
messages.push([
|
|
41
|
-
internalAsDev.forEach(dep => messages.push([
|
|
40
|
+
messages.push([logWarn, 1, 'incorrect usage as dev dep of internal packages:']);
|
|
41
|
+
internalAsDev.forEach(dep => messages.push([logError, 2, dep]));
|
|
42
42
|
}
|
|
43
43
|
|
|
44
44
|
if (dependencies.length) {
|
|
45
|
-
messages.push([
|
|
46
|
-
dependencies.forEach(dep => messages.push([
|
|
45
|
+
messages.push([logWarn, 1, 'unused dependencies:']);
|
|
46
|
+
dependencies.forEach(dep => messages.push([logError, 2, dep]));
|
|
47
47
|
}
|
|
48
48
|
|
|
49
49
|
const missingEntities = Object.entries(missing);
|
|
50
50
|
if (missingEntities.length) {
|
|
51
|
-
messages.push([
|
|
51
|
+
messages.push([logWarn, 1, 'missing dependencies:']);
|
|
52
52
|
for (const [packageName, files] of missingEntities) {
|
|
53
|
-
messages.push([
|
|
53
|
+
messages.push([logError, 2, packageName]);
|
|
54
54
|
for (const file of files) {
|
|
55
|
-
messages.push([
|
|
55
|
+
messages.push([logError, 2, file]);
|
|
56
56
|
}
|
|
57
57
|
}
|
|
58
58
|
}
|
|
@@ -63,13 +63,16 @@ export class Report {
|
|
|
63
63
|
}
|
|
64
64
|
}
|
|
65
65
|
|
|
66
|
+
if (exitCode === 0) {
|
|
67
|
+
logInfo('Dependencies have been checked. Everything is ok.');
|
|
68
|
+
}
|
|
69
|
+
|
|
66
70
|
return exitCode;
|
|
67
71
|
}
|
|
68
72
|
|
|
69
73
|
private printMessages(messages: Messages) {
|
|
70
|
-
for (const [
|
|
71
|
-
|
|
72
|
-
log(`${'\t'.repeat(tabs)}${message}`);
|
|
74
|
+
for (const [logger, indent, message] of messages) {
|
|
75
|
+
logger(`${' '.repeat(indent)}${message}`);
|
|
73
76
|
}
|
|
74
77
|
}
|
|
75
78
|
}
|
package/src/utils/console.ts
CHANGED
|
@@ -25,3 +25,4 @@ export const logInfo = (message: string) => log(message, 'info');
|
|
|
25
25
|
export const logHelp = (message: string) => log(message, 'help');
|
|
26
26
|
export const logSilly = (message: string) => log(message, 'silly');
|
|
27
27
|
export const logDebug = (message: string) => log(message, 'debug');
|
|
28
|
+
export const logWarn = (message: string) => log(message, 'warn');
|