pi-rtk-optimizer 0.3.2 → 0.4.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.
@@ -1,155 +1,155 @@
1
- import { matchesCommandPatterns } from "./command-detection.js";
2
-
3
- interface BuildStats {
4
- compiled: number;
5
- errors: string[][];
6
- warnings: string[];
7
- }
8
-
9
- const BUILD_COMMAND_PATTERNS = [
10
- /^cargo\s+(build|check)\b/,
11
- /^bun\s+build\b/,
12
- /^npm\s+run\s+build\b/,
13
- /^yarn\s+build\b/,
14
- /^pnpm\s+build\b/,
15
- /^(?:npx\s+)?tsc\b/,
16
- /^make\b/,
17
- /^cmake\b/,
18
- /^gradle\b/,
19
- /^mvn\b/,
20
- /^go\s+(build|install)\b/,
21
- /^python\s+setup\.py\s+build\b/,
22
- /^pip\s+install\b/,
23
- ] as const;
24
-
25
- const SKIP_PATTERNS = [
26
- /^\s*Compiling\s+/,
27
- /^\s*Checking\s+/,
28
- /^\s*Downloading\s+/,
29
- /^\s*Downloaded\s+/,
30
- /^\s*Fetching\s+/,
31
- /^\s*Fetched\s+/,
32
- /^\s*Updating\s+/,
33
- /^\s*Updated\s+/,
34
- /^\s*Building\s+/,
35
- /^\s*Generated\s+/,
36
- /^\s*Creating\s+/,
37
- /^\s*Running\s+/,
38
- ];
39
-
40
- const ERROR_START_PATTERNS = [/^error\[/, /^error:/, /^\[ERROR\]/, /^FAIL/];
41
- const WARNING_PATTERNS = [/^warning:/, /^\[WARNING\]/, /^warn:/];
42
-
43
- function isSkipLine(line: string): boolean {
44
- return SKIP_PATTERNS.some((pattern) => pattern.test(line));
45
- }
46
-
47
- function isErrorStart(line: string): boolean {
48
- return ERROR_START_PATTERNS.some((pattern) => pattern.test(line));
49
- }
50
-
51
- function isWarning(line: string): boolean {
52
- return WARNING_PATTERNS.some((pattern) => pattern.test(line));
53
- }
54
-
55
- export function isBuildCommand(command: string | undefined | null): boolean {
56
- return matchesCommandPatterns(command, BUILD_COMMAND_PATTERNS);
57
- }
58
-
59
- export function filterBuildOutput(output: string, command: string | undefined | null): string | null {
60
- if (!isBuildCommand(command)) {
61
- return null;
62
- }
63
-
64
- const lines = output.split("\n");
65
- const stats: BuildStats = {
66
- compiled: 0,
67
- errors: [],
68
- warnings: [],
69
- };
70
-
71
- let inErrorBlock = false;
72
- let currentError: string[] = [];
73
- let blankCount = 0;
74
-
75
- for (const line of lines) {
76
- if (line.match(/^\s*(Compiling|Checking|Building)\s+/)) {
77
- stats.compiled++;
78
- continue;
79
- }
80
-
81
- if (isSkipLine(line)) {
82
- continue;
83
- }
84
-
85
- if (isErrorStart(line)) {
86
- if (inErrorBlock && currentError.length > 0) {
87
- stats.errors.push([...currentError]);
88
- }
89
- inErrorBlock = true;
90
- currentError = [line];
91
- blankCount = 0;
92
- continue;
93
- }
94
-
95
- if (isWarning(line)) {
96
- stats.warnings.push(line);
97
- continue;
98
- }
99
-
100
- if (!inErrorBlock) {
101
- continue;
102
- }
103
-
104
- if (line.trim() === "") {
105
- blankCount++;
106
- if (blankCount >= 2 && currentError.length > 3) {
107
- stats.errors.push([...currentError]);
108
- inErrorBlock = false;
109
- currentError = [];
110
- } else {
111
- currentError.push(line);
112
- }
113
- continue;
114
- }
115
-
116
- if (line.match(/^\s/) || line.match(/^-->/)) {
117
- currentError.push(line);
118
- blankCount = 0;
119
- continue;
120
- }
121
-
122
- stats.errors.push([...currentError]);
123
- inErrorBlock = false;
124
- currentError = [];
125
- }
126
-
127
- if (inErrorBlock && currentError.length > 0) {
128
- stats.errors.push(currentError);
129
- }
130
-
131
- if (stats.errors.length === 0 && stats.warnings.length === 0) {
132
- return `✓ Build successful (${stats.compiled} units compiled)`;
133
- }
134
-
135
- const result: string[] = [];
136
-
137
- if (stats.errors.length > 0) {
138
- result.push(`❌ ${stats.errors.length} error(s):`);
139
- for (const error of stats.errors.slice(0, 5)) {
140
- result.push(...error.slice(0, 10));
141
- if (error.length > 10) {
142
- result.push(" ...");
143
- }
144
- }
145
- if (stats.errors.length > 5) {
146
- result.push(`... and ${stats.errors.length - 5} more errors`);
147
- }
148
- }
149
-
150
- if (stats.warnings.length > 0) {
151
- result.push(`\n⚠️ ${stats.warnings.length} warning(s)`);
152
- }
153
-
154
- return result.join("\n");
155
- }
1
+ import { matchesCommandPatterns } from "./command-detection.js";
2
+
3
+ interface BuildStats {
4
+ compiled: number;
5
+ errors: string[][];
6
+ warnings: string[];
7
+ }
8
+
9
+ const BUILD_COMMAND_PATTERNS = [
10
+ /^cargo\s+(build|check)\b/,
11
+ /^bun\s+build\b/,
12
+ /^npm\s+run\s+build\b/,
13
+ /^yarn\s+build\b/,
14
+ /^pnpm\s+build\b/,
15
+ /^(?:npx\s+)?tsc\b/,
16
+ /^make\b/,
17
+ /^cmake\b/,
18
+ /^gradle\b/,
19
+ /^mvn\b/,
20
+ /^go\s+(build|install)\b/,
21
+ /^python\s+setup\.py\s+build\b/,
22
+ /^pip\s+install\b/,
23
+ ] as const;
24
+
25
+ const SKIP_PATTERNS = [
26
+ /^\s*Compiling\s+/,
27
+ /^\s*Checking\s+/,
28
+ /^\s*Downloading\s+/,
29
+ /^\s*Downloaded\s+/,
30
+ /^\s*Fetching\s+/,
31
+ /^\s*Fetched\s+/,
32
+ /^\s*Updating\s+/,
33
+ /^\s*Updated\s+/,
34
+ /^\s*Building\s+/,
35
+ /^\s*Generated\s+/,
36
+ /^\s*Creating\s+/,
37
+ /^\s*Running\s+/,
38
+ ];
39
+
40
+ const ERROR_START_PATTERNS = [/^error\[/, /^error:/, /^\[ERROR\]/, /^FAIL/];
41
+ const WARNING_PATTERNS = [/^warning:/, /^\[WARNING\]/, /^warn:/];
42
+
43
+ function isSkipLine(line: string): boolean {
44
+ return SKIP_PATTERNS.some((pattern) => pattern.test(line));
45
+ }
46
+
47
+ function isErrorStart(line: string): boolean {
48
+ return ERROR_START_PATTERNS.some((pattern) => pattern.test(line));
49
+ }
50
+
51
+ function isWarning(line: string): boolean {
52
+ return WARNING_PATTERNS.some((pattern) => pattern.test(line));
53
+ }
54
+
55
+ export function isBuildCommand(command: string | undefined | null): boolean {
56
+ return matchesCommandPatterns(command, BUILD_COMMAND_PATTERNS);
57
+ }
58
+
59
+ export function filterBuildOutput(output: string, command: string | undefined | null): string | null {
60
+ if (!isBuildCommand(command)) {
61
+ return null;
62
+ }
63
+
64
+ const lines = output.split("\n");
65
+ const stats: BuildStats = {
66
+ compiled: 0,
67
+ errors: [],
68
+ warnings: [],
69
+ };
70
+
71
+ let inErrorBlock = false;
72
+ let currentError: string[] = [];
73
+ let blankCount = 0;
74
+
75
+ for (const line of lines) {
76
+ if (line.match(/^\s*(Compiling|Checking|Building)\s+/)) {
77
+ stats.compiled++;
78
+ continue;
79
+ }
80
+
81
+ if (isSkipLine(line)) {
82
+ continue;
83
+ }
84
+
85
+ if (isErrorStart(line)) {
86
+ if (inErrorBlock && currentError.length > 0) {
87
+ stats.errors.push([...currentError]);
88
+ }
89
+ inErrorBlock = true;
90
+ currentError = [line];
91
+ blankCount = 0;
92
+ continue;
93
+ }
94
+
95
+ if (isWarning(line)) {
96
+ stats.warnings.push(line);
97
+ continue;
98
+ }
99
+
100
+ if (!inErrorBlock) {
101
+ continue;
102
+ }
103
+
104
+ if (line.trim() === "") {
105
+ blankCount++;
106
+ if (blankCount >= 2 && currentError.length > 3) {
107
+ stats.errors.push([...currentError]);
108
+ inErrorBlock = false;
109
+ currentError = [];
110
+ } else {
111
+ currentError.push(line);
112
+ }
113
+ continue;
114
+ }
115
+
116
+ if (line.match(/^\s/) || line.match(/^-->/)) {
117
+ currentError.push(line);
118
+ blankCount = 0;
119
+ continue;
120
+ }
121
+
122
+ stats.errors.push([...currentError]);
123
+ inErrorBlock = false;
124
+ currentError = [];
125
+ }
126
+
127
+ if (inErrorBlock && currentError.length > 0) {
128
+ stats.errors.push(currentError);
129
+ }
130
+
131
+ if (stats.errors.length === 0 && stats.warnings.length === 0) {
132
+ return `[OK] Build successful (${stats.compiled} units compiled)`;
133
+ }
134
+
135
+ const result: string[] = [];
136
+
137
+ if (stats.errors.length > 0) {
138
+ result.push(`[ERROR] ${stats.errors.length} error(s):`);
139
+ for (const error of stats.errors.slice(0, 5)) {
140
+ result.push(...error.slice(0, 10));
141
+ if (error.length > 10) {
142
+ result.push(" ...");
143
+ }
144
+ }
145
+ if (stats.errors.length > 5) {
146
+ result.push(`... and ${stats.errors.length - 5} more errors`);
147
+ }
148
+ }
149
+
150
+ if (stats.warnings.length > 0) {
151
+ result.push(`\n[WARN] ${stats.warnings.length} warning(s)`);
152
+ }
153
+
154
+ return result.join("\n");
155
+ }