@cloud-ru/ft-deps-validator 1.1.2-preview-406fdd9.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.
@@ -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 (when actualVersion is undefined)', () => __awaiter(void 0, void 0, void 0, function* () {
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(1);
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,10 @@ 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
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;
@@ -23,7 +25,8 @@ vitest_1.vi.mock('../../utils/console', () => ({
23
25
  report.add(folder, state);
24
26
  const exitCode = report.printResultAndGetExitCode();
25
27
  (0, vitest_1.expect)(exitCode).toBe(1);
26
- (0, vitest_1.expect)(console_1.logInfo).toHaveBeenCalled();
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', () => {
@@ -44,8 +47,10 @@ vitest_1.vi.mock('../../utils/console', () => ({
44
47
  (0, vitest_1.it)('should return 0 when storage is empty', () => {
45
48
  const exitCode = report.printResultAndGetExitCode();
46
49
  (0, vitest_1.expect)(exitCode).toBe(0);
47
- (0, vitest_1.expect)(console_1.logInfo).not.toHaveBeenCalled();
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', {
@@ -56,8 +61,10 @@ vitest_1.vi.mock('../../utils/console', () => ({
56
61
  });
57
62
  const exitCode = report.printResultAndGetExitCode();
58
63
  (0, vitest_1.expect)(exitCode).toBe(0);
59
- (0, vitest_1.expect)(console_1.logInfo).not.toHaveBeenCalled();
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.logInfo).toHaveBeenCalledWith(folder);
71
- (0, vitest_1.expect)(console_1.logError).toHaveBeenCalledWith('\twrong version of internal packages:');
72
- (0, vitest_1.expect)(console_1.logError).toHaveBeenCalledWith('\t\t@cloud-ru/package1');
73
- (0, vitest_1.expect)(console_1.logError).toHaveBeenCalledWith('\t\t@cloud-ru/package2');
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.logInfo).toHaveBeenCalledWith(folder);
84
- (0, vitest_1.expect)(console_1.logError).toHaveBeenCalledWith('\tincorrect usage as dev dep of internal packages:');
85
- (0, vitest_1.expect)(console_1.logError).toHaveBeenCalledWith('\t\t@cloud-ru/package1');
86
- (0, vitest_1.expect)(console_1.logError).toHaveBeenCalledWith('\t\t@cloud-ru/package2');
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.logInfo).toHaveBeenCalledWith(folder);
97
- (0, vitest_1.expect)(console_1.logError).toHaveBeenCalledWith('\tunused dependencies:');
98
- (0, vitest_1.expect)(console_1.logError).toHaveBeenCalledWith('\t\tunused-dep1');
99
- (0, vitest_1.expect)(console_1.logError).toHaveBeenCalledWith('\t\tunused-dep2');
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.logInfo).toHaveBeenCalledWith(folder);
113
- (0, vitest_1.expect)(console_1.logError).toHaveBeenCalledWith('\tmissing dependencies:');
114
- (0, vitest_1.expect)(console_1.logError).toHaveBeenCalledWith('\t\tmissing-package1');
115
- (0, vitest_1.expect)(console_1.logError).toHaveBeenCalledWith('\t\tfile1.ts');
116
- (0, vitest_1.expect)(console_1.logError).toHaveBeenCalledWith('\t\tfile2.ts');
117
- (0, vitest_1.expect)(console_1.logError).toHaveBeenCalledWith('\t\tmissing-package2');
118
- (0, vitest_1.expect)(console_1.logError).toHaveBeenCalledWith('\t\tfile3.ts');
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.logInfo).toHaveBeenCalledWith(folder);
133
- (0, vitest_1.expect)(console_1.logError).toHaveBeenCalledWith('\twrong version of internal packages:');
134
- (0, vitest_1.expect)(console_1.logError).toHaveBeenCalledWith('\t\t@cloud-ru/package1');
135
- (0, vitest_1.expect)(console_1.logError).toHaveBeenCalledWith('\tincorrect usage as dev dep of internal packages:');
136
- (0, vitest_1.expect)(console_1.logError).toHaveBeenCalledWith('\t\t@cloud-ru/package2');
137
- (0, vitest_1.expect)(console_1.logError).toHaveBeenCalledWith('\tunused dependencies:');
138
- (0, vitest_1.expect)(console_1.logError).toHaveBeenCalledWith('\t\tunused-dep');
139
- (0, vitest_1.expect)(console_1.logError).toHaveBeenCalledWith('\tmissing dependencies:');
140
- (0, vitest_1.expect)(console_1.logError).toHaveBeenCalledWith('\t\tmissing-package');
141
- (0, vitest_1.expect)(console_1.logError).toHaveBeenCalledWith('\t\tfile.ts');
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,28 +156,30 @@ 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.logInfo).toHaveBeenCalledWith('packages/package1');
153
- (0, vitest_1.expect)(console_1.logError).toHaveBeenCalledWith(vitest_1.expect.stringContaining('wrong version'));
154
- (0, vitest_1.expect)(console_1.logInfo).toHaveBeenCalledWith('packages/package2');
155
- (0, vitest_1.expect)(console_1.logError).toHaveBeenCalledWith(vitest_1.expect.stringContaining('unused dependencies'));
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';
159
166
  report.add(folder, {});
160
167
  const exitCode = report.printResultAndGetExitCode();
161
168
  (0, vitest_1.expect)(exitCode).toBe(0);
162
- (0, vitest_1.expect)(console_1.logInfo).not.toHaveBeenCalled();
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 tabs', () => {
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.logInfo).toHaveBeenCalledWith('packages/test-package');
172
- (0, vitest_1.expect)(console_1.logError).toHaveBeenCalledWith('\twrong version of internal packages:');
173
- (0, vitest_1.expect)(console_1.logError).toHaveBeenCalledWith('\t\t@cloud-ru/package');
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
  });
@@ -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 = [['info', 0, packageName]];
18
+ const messages = [[console_1.logDebug, 0, `\n${packageName}`]];
19
19
  if (wrongVersions.length) {
20
- messages.push(['error', 1, 'wrong version of internal packages:']);
21
- wrongVersions.forEach(dep => messages.push(['error', 2, dep]));
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(['error', 1, 'incorrect usage as dev dep of internal packages:']);
25
- internalAsDev.forEach(dep => messages.push(['error', 2, dep]));
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(['error', 1, 'unused dependencies:']);
29
- dependencies.forEach(dep => messages.push(['error', 2, dep]));
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(['error', 1, 'missing dependencies:']);
33
+ messages.push([console_1.logWarn, 1, 'missing dependencies:']);
34
34
  for (const [packageName, files] of missingEntities) {
35
- messages.push(['error', 2, packageName]);
35
+ messages.push([console_1.logError, 2, packageName]);
36
36
  for (const file of files) {
37
- messages.push(['error', 2, file]);
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 [level, tabs, message] of messages) {
50
- const log = level === 'info' ? console_1.logInfo : console_1.logError;
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',
@@ -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}\n`));
23
+ console.log(safe_1.default[themes[theme]](`${message}`));
24
24
  };
25
25
  const logError = (message) => log(message, 'error');
26
26
  exports.logError = logError;
@@ -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;
@@ -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 (when actualVersion is undefined)', () => __awaiter(void 0, void 0, void 0, function* () {
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(1);
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,11 @@
1
1
  import { beforeEach, describe, expect, it, vi } from 'vitest';
2
- import { logError, logInfo } 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
+ logDebug: vi.fn(),
5
6
  logError: vi.fn(),
6
7
  logInfo: vi.fn(),
8
+ logWarn: vi.fn(),
7
9
  }));
8
10
  describe('Report', () => {
9
11
  let report;
@@ -21,7 +23,8 @@ describe('Report', () => {
21
23
  report.add(folder, state);
22
24
  const exitCode = report.printResultAndGetExitCode();
23
25
  expect(exitCode).toBe(1);
24
- expect(logInfo).toHaveBeenCalled();
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', () => {
@@ -42,8 +45,10 @@ describe('Report', () => {
42
45
  it('should return 0 when storage is empty', () => {
43
46
  const exitCode = report.printResultAndGetExitCode();
44
47
  expect(exitCode).toBe(0);
45
- expect(logInfo).not.toHaveBeenCalled();
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', {
@@ -54,8 +59,10 @@ describe('Report', () => {
54
59
  });
55
60
  const exitCode = report.printResultAndGetExitCode();
56
61
  expect(exitCode).toBe(0);
57
- expect(logInfo).not.toHaveBeenCalled();
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(logInfo).toHaveBeenCalledWith(folder);
69
- expect(logError).toHaveBeenCalledWith('\twrong version of internal packages:');
70
- expect(logError).toHaveBeenCalledWith('\t\t@cloud-ru/package1');
71
- expect(logError).toHaveBeenCalledWith('\t\t@cloud-ru/package2');
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(logInfo).toHaveBeenCalledWith(folder);
82
- expect(logError).toHaveBeenCalledWith('\tincorrect usage as dev dep of internal packages:');
83
- expect(logError).toHaveBeenCalledWith('\t\t@cloud-ru/package1');
84
- expect(logError).toHaveBeenCalledWith('\t\t@cloud-ru/package2');
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(logInfo).toHaveBeenCalledWith(folder);
95
- expect(logError).toHaveBeenCalledWith('\tunused dependencies:');
96
- expect(logError).toHaveBeenCalledWith('\t\tunused-dep1');
97
- expect(logError).toHaveBeenCalledWith('\t\tunused-dep2');
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(logInfo).toHaveBeenCalledWith(folder);
111
- expect(logError).toHaveBeenCalledWith('\tmissing dependencies:');
112
- expect(logError).toHaveBeenCalledWith('\t\tmissing-package1');
113
- expect(logError).toHaveBeenCalledWith('\t\tfile1.ts');
114
- expect(logError).toHaveBeenCalledWith('\t\tfile2.ts');
115
- expect(logError).toHaveBeenCalledWith('\t\tmissing-package2');
116
- expect(logError).toHaveBeenCalledWith('\t\tfile3.ts');
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(logInfo).toHaveBeenCalledWith(folder);
131
- expect(logError).toHaveBeenCalledWith('\twrong version of internal packages:');
132
- expect(logError).toHaveBeenCalledWith('\t\t@cloud-ru/package1');
133
- expect(logError).toHaveBeenCalledWith('\tincorrect usage as dev dep of internal packages:');
134
- expect(logError).toHaveBeenCalledWith('\t\t@cloud-ru/package2');
135
- expect(logError).toHaveBeenCalledWith('\tunused dependencies:');
136
- expect(logError).toHaveBeenCalledWith('\t\tunused-dep');
137
- expect(logError).toHaveBeenCalledWith('\tmissing dependencies:');
138
- expect(logError).toHaveBeenCalledWith('\t\tmissing-package');
139
- expect(logError).toHaveBeenCalledWith('\t\tfile.ts');
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,28 +154,30 @@ describe('Report', () => {
147
154
  });
148
155
  const exitCode = report.printResultAndGetExitCode();
149
156
  expect(exitCode).toBe(1);
150
- expect(logInfo).toHaveBeenCalledWith('packages/package1');
151
- expect(logError).toHaveBeenCalledWith(expect.stringContaining('wrong version'));
152
- expect(logInfo).toHaveBeenCalledWith('packages/package2');
153
- expect(logError).toHaveBeenCalledWith(expect.stringContaining('unused dependencies'));
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';
157
164
  report.add(folder, {});
158
165
  const exitCode = report.printResultAndGetExitCode();
159
166
  expect(exitCode).toBe(0);
160
- expect(logInfo).not.toHaveBeenCalled();
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 tabs', () => {
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(logInfo).toHaveBeenCalledWith('packages/test-package');
170
- expect(logError).toHaveBeenCalledWith('\twrong version of internal packages:');
171
- expect(logError).toHaveBeenCalledWith('\t\t@cloud-ru/package');
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
  });
@@ -1,4 +1,4 @@
1
- import { logError, logInfo } 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 = [['info', 0, packageName]];
15
+ const messages = [[logDebug, 0, `\n${packageName}`]];
16
16
  if (wrongVersions.length) {
17
- messages.push(['error', 1, 'wrong version of internal packages:']);
18
- wrongVersions.forEach(dep => messages.push(['error', 2, dep]));
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(['error', 1, 'incorrect usage as dev dep of internal packages:']);
22
- internalAsDev.forEach(dep => messages.push(['error', 2, dep]));
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(['error', 1, 'unused dependencies:']);
26
- dependencies.forEach(dep => messages.push(['error', 2, dep]));
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(['error', 1, 'missing dependencies:']);
30
+ messages.push([logWarn, 1, 'missing dependencies:']);
31
31
  for (const [packageName, files] of missingEntities) {
32
- messages.push(['error', 2, packageName]);
32
+ messages.push([logError, 2, packageName]);
33
33
  for (const file of files) {
34
- messages.push(['error', 2, file]);
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 [level, tabs, message] of messages) {
47
- const log = level === 'info' ? logInfo : logError;
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;
@@ -14,10 +14,11 @@ 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}\n`));
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');
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-406fdd9.0",
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": "49873e65a333f8fe78c15a54a41fe79eafb569ae"
41
+ "gitHead": "cba3732de2facd5c1ebf32df6e1ec3e09f87790b"
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 (when actualVersion is undefined)', async () => {
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(1);
299
+ expect(exitCode).toBe(0);
302
300
  });
303
301
 
304
302
  it('should handle empty dependencies and devDependencies', async () => {
@@ -1,11 +1,13 @@
1
1
  import { beforeEach, describe, expect, it, vi } from 'vitest';
2
2
 
3
- import { logError, logInfo } 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
+ logDebug: vi.fn(),
7
8
  logError: vi.fn(),
8
9
  logInfo: vi.fn(),
10
+ logWarn: vi.fn(),
9
11
  }));
10
12
 
11
13
  describe('Report', () => {
@@ -28,7 +30,8 @@ describe('Report', () => {
28
30
 
29
31
  const exitCode = report.printResultAndGetExitCode();
30
32
  expect(exitCode).toBe(1);
31
- expect(logInfo).toHaveBeenCalled();
33
+ expect(logDebug).toHaveBeenCalled();
34
+ expect(logWarn).toHaveBeenCalled();
32
35
  expect(logError).toHaveBeenCalled();
33
36
  });
34
37
 
@@ -54,8 +57,10 @@ describe('Report', () => {
54
57
  const exitCode = report.printResultAndGetExitCode();
55
58
 
56
59
  expect(exitCode).toBe(0);
57
- expect(logInfo).not.toHaveBeenCalled();
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', () => {
@@ -69,8 +74,10 @@ describe('Report', () => {
69
74
  const exitCode = report.printResultAndGetExitCode();
70
75
 
71
76
  expect(exitCode).toBe(0);
72
- expect(logInfo).not.toHaveBeenCalled();
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(logInfo).toHaveBeenCalledWith(folder);
88
- expect(logError).toHaveBeenCalledWith('\twrong version of internal packages:');
89
- expect(logError).toHaveBeenCalledWith('\t\t@cloud-ru/package1');
90
- expect(logError).toHaveBeenCalledWith('\t\t@cloud-ru/package2');
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(logInfo).toHaveBeenCalledWith(folder);
105
- expect(logError).toHaveBeenCalledWith('\tincorrect usage as dev dep of internal packages:');
106
- expect(logError).toHaveBeenCalledWith('\t\t@cloud-ru/package1');
107
- expect(logError).toHaveBeenCalledWith('\t\t@cloud-ru/package2');
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(logInfo).toHaveBeenCalledWith(folder);
122
- expect(logError).toHaveBeenCalledWith('\tunused dependencies:');
123
- expect(logError).toHaveBeenCalledWith('\t\tunused-dep1');
124
- expect(logError).toHaveBeenCalledWith('\t\tunused-dep2');
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(logInfo).toHaveBeenCalledWith(folder);
142
- expect(logError).toHaveBeenCalledWith('\tmissing dependencies:');
143
- expect(logError).toHaveBeenCalledWith('\t\tmissing-package1');
144
- expect(logError).toHaveBeenCalledWith('\t\tfile1.ts');
145
- expect(logError).toHaveBeenCalledWith('\t\tfile2.ts');
146
- expect(logError).toHaveBeenCalledWith('\t\tmissing-package2');
147
- expect(logError).toHaveBeenCalledWith('\t\tfile3.ts');
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(logInfo).toHaveBeenCalledWith(folder);
166
- expect(logError).toHaveBeenCalledWith('\twrong version of internal packages:');
167
- expect(logError).toHaveBeenCalledWith('\t\t@cloud-ru/package1');
168
- expect(logError).toHaveBeenCalledWith('\tincorrect usage as dev dep of internal packages:');
169
- expect(logError).toHaveBeenCalledWith('\t\t@cloud-ru/package2');
170
- expect(logError).toHaveBeenCalledWith('\tunused dependencies:');
171
- expect(logError).toHaveBeenCalledWith('\t\tunused-dep');
172
- expect(logError).toHaveBeenCalledWith('\tmissing dependencies:');
173
- expect(logError).toHaveBeenCalledWith('\t\tmissing-package');
174
- expect(logError).toHaveBeenCalledWith('\t\tfile.ts');
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(logInfo).toHaveBeenCalledWith('packages/package1');
190
- expect(logError).toHaveBeenCalledWith(expect.stringContaining('wrong version'));
191
- expect(logInfo).toHaveBeenCalledWith('packages/package2');
192
- expect(logError).toHaveBeenCalledWith(expect.stringContaining('unused dependencies'));
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', () => {
@@ -200,11 +207,13 @@ describe('Report', () => {
200
207
  const exitCode = report.printResultAndGetExitCode();
201
208
 
202
209
  expect(exitCode).toBe(0);
203
- expect(logInfo).not.toHaveBeenCalled();
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 tabs', () => {
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(logInfo).toHaveBeenCalledWith('packages/test-package');
217
- expect(logError).toHaveBeenCalledWith('\twrong version of internal packages:');
218
- expect(logError).toHaveBeenCalledWith('\t\t@cloud-ru/package');
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
  });
@@ -1,8 +1,8 @@
1
1
  import { Results } from 'depcheck';
2
2
 
3
- import { logError, logInfo } from '../utils/console';
3
+ import { logDebug, logError, logInfo, logWarn } from '../utils/console';
4
4
 
5
- type Messages = ['info' | 'error', number, string][];
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 = [['info', 0, packageName]];
32
+ const messages: Messages = [[logDebug, 0, `\n${packageName}`]];
33
33
 
34
34
  if (wrongVersions.length) {
35
- messages.push(['error', 1, 'wrong version of internal packages:']);
36
- wrongVersions.forEach(dep => messages.push(['error', 2, dep]));
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(['error', 1, 'incorrect usage as dev dep of internal packages:']);
41
- internalAsDev.forEach(dep => messages.push(['error', 2, dep]));
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(['error', 1, 'unused dependencies:']);
46
- dependencies.forEach(dep => messages.push(['error', 2, dep]));
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(['error', 1, 'missing dependencies:']);
51
+ messages.push([logWarn, 1, 'missing dependencies:']);
52
52
  for (const [packageName, files] of missingEntities) {
53
- messages.push(['error', 2, packageName]);
53
+ messages.push([logError, 2, packageName]);
54
54
  for (const file of files) {
55
- messages.push(['error', 2, file]);
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 [level, tabs, message] of messages) {
71
- const log = level === 'info' ? logInfo : logError;
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
  }
@@ -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}\n`));
20
+ console.log(colors[themes[theme]](`${message}`));
21
21
  };
22
22
 
23
23
  export const logError = (message: string) => log(message, 'error');
@@ -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');