repack-logs-mcp 1.0.0 → 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +55 -7
- package/dist/index.js +0 -0
- package/dist/plugin.d.ts +24 -0
- package/dist/plugin.d.ts.map +1 -0
- package/dist/plugin.js +105 -0
- package/dist/plugin.js.map +1 -0
- package/package.json +14 -1
- package/src/plugin.ts +130 -0
package/README.md
CHANGED
|
@@ -4,12 +4,9 @@ An MCP (Model Context Protocol) server for tailing Re.Pack/Rspack dev server log
|
|
|
4
4
|
|
|
5
5
|
## How It Works
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
# Run your dev server with file logging
|
|
11
|
-
npx react-native start --log-file .repack-logs.json
|
|
12
|
-
```
|
|
7
|
+
This package provides two components:
|
|
8
|
+
1. **RepackLogsPlugin** - An Rspack/Webpack plugin that writes build logs to a JSON file
|
|
9
|
+
2. **MCP Server** - Watches the log file and provides tools for AI assistants to query logs
|
|
13
10
|
|
|
14
11
|
## Installation
|
|
15
12
|
|
|
@@ -19,6 +16,50 @@ npm install -g repack-logs-mcp
|
|
|
19
16
|
npx repack-logs-mcp /path/to/.repack-logs.json
|
|
20
17
|
```
|
|
21
18
|
|
|
19
|
+
## Setup
|
|
20
|
+
|
|
21
|
+
### Step 1: Add the Plugin to Your Rspack Config
|
|
22
|
+
|
|
23
|
+
Add the `RepackLogsPlugin` to your `rspack.config.mjs` (or `rspack.config.js`):
|
|
24
|
+
|
|
25
|
+
```js
|
|
26
|
+
import { RepackLogsPlugin } from 'repack-logs-mcp/plugin';
|
|
27
|
+
|
|
28
|
+
export default {
|
|
29
|
+
// ... your existing config
|
|
30
|
+
plugins: [
|
|
31
|
+
// ... your existing plugins
|
|
32
|
+
new RepackLogsPlugin({
|
|
33
|
+
// Path to write logs (default: '.repack-logs.json')
|
|
34
|
+
outputPath: '/absolute/path/to/.repack-logs.json',
|
|
35
|
+
// Clear logs on each build start (default: true)
|
|
36
|
+
clearOnStart: true,
|
|
37
|
+
}),
|
|
38
|
+
],
|
|
39
|
+
};
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
**Example with Re.Pack:**
|
|
43
|
+
|
|
44
|
+
```js
|
|
45
|
+
import * as Repack from '@callstack/repack';
|
|
46
|
+
import { RepackLogsPlugin } from 'repack-logs-mcp/plugin';
|
|
47
|
+
|
|
48
|
+
export default Repack.defineRspackConfig({
|
|
49
|
+
// ... your config
|
|
50
|
+
plugins: [
|
|
51
|
+
new Repack.RepackPlugin(),
|
|
52
|
+
new RepackLogsPlugin({
|
|
53
|
+
outputPath: '/Users/yourname/project/.repack-logs.json',
|
|
54
|
+
}),
|
|
55
|
+
],
|
|
56
|
+
});
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
### Step 2: Configure the MCP Server
|
|
60
|
+
|
|
61
|
+
Point the MCP server to the same log file path used in your plugin config.
|
|
62
|
+
|
|
22
63
|
## Tools Provided
|
|
23
64
|
|
|
24
65
|
| Tool | Description |
|
|
@@ -44,7 +85,14 @@ The log file path can be set via:
|
|
|
44
85
|
|
|
45
86
|
3. **Default**: `.repack-logs.json` in current directory
|
|
46
87
|
|
|
47
|
-
###
|
|
88
|
+
### Plugin Options
|
|
89
|
+
|
|
90
|
+
| Option | Description | Default |
|
|
91
|
+
|--------|-------------|---------|
|
|
92
|
+
| `outputPath` | Path to the log file | `.repack-logs.json` |
|
|
93
|
+
| `clearOnStart` | Clear log file on each build start | `true` |
|
|
94
|
+
|
|
95
|
+
### Environment Variables (MCP Server)
|
|
48
96
|
|
|
49
97
|
| Variable | Description | Default |
|
|
50
98
|
|----------|-------------|---------|
|
package/dist/index.js
CHANGED
|
File without changes
|
package/dist/plugin.d.ts
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { Compiler } from '@rspack/core';
|
|
2
|
+
export interface RepackLogsPluginOptions {
|
|
3
|
+
/**
|
|
4
|
+
* Path to the log file. Defaults to '.repack-logs.json' in the project root.
|
|
5
|
+
*/
|
|
6
|
+
outputPath?: string;
|
|
7
|
+
/**
|
|
8
|
+
* Whether to clear the log file on each build start. Defaults to true.
|
|
9
|
+
*/
|
|
10
|
+
clearOnStart?: boolean;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Rspack/Webpack plugin that writes build logs to a JSON file
|
|
14
|
+
* for consumption by the repack-logs-mcp server.
|
|
15
|
+
*/
|
|
16
|
+
export declare class RepackLogsPlugin {
|
|
17
|
+
private outputPath;
|
|
18
|
+
private clearOnStart;
|
|
19
|
+
constructor(options?: RepackLogsPluginOptions);
|
|
20
|
+
apply(compiler: Compiler): void;
|
|
21
|
+
private writeLog;
|
|
22
|
+
}
|
|
23
|
+
export default RepackLogsPlugin;
|
|
24
|
+
//# sourceMappingURL=plugin.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plugin.d.ts","sourceRoot":"","sources":["../src/plugin.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,QAAQ,EAAS,MAAM,cAAc,CAAC;AAGpD,MAAM,WAAW,uBAAuB;IACtC;;OAEG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB;;OAEG;IACH,YAAY,CAAC,EAAE,OAAO,CAAC;CACxB;AAED;;;GAGG;AACH,qBAAa,gBAAgB;IAC3B,OAAO,CAAC,UAAU,CAAS;IAC3B,OAAO,CAAC,YAAY,CAAU;gBAElB,OAAO,GAAE,uBAA4B;IAKjD,KAAK,CAAC,QAAQ,EAAE,QAAQ,GAAG,IAAI;IAsF/B,OAAO,CAAC,QAAQ;CAYjB;AAED,eAAe,gBAAgB,CAAC"}
|
package/dist/plugin.js
ADDED
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
/**
|
|
4
|
+
* Rspack/Webpack plugin that writes build logs to a JSON file
|
|
5
|
+
* for consumption by the repack-logs-mcp server.
|
|
6
|
+
*/
|
|
7
|
+
export class RepackLogsPlugin {
|
|
8
|
+
outputPath;
|
|
9
|
+
clearOnStart;
|
|
10
|
+
constructor(options = {}) {
|
|
11
|
+
this.outputPath = options.outputPath ?? '.repack-logs.json';
|
|
12
|
+
this.clearOnStart = options.clearOnStart ?? true;
|
|
13
|
+
}
|
|
14
|
+
apply(compiler) {
|
|
15
|
+
const pluginName = 'RepackLogsPlugin';
|
|
16
|
+
// Ensure output directory exists
|
|
17
|
+
const outputDir = path.dirname(this.outputPath);
|
|
18
|
+
if (outputDir && outputDir !== '.') {
|
|
19
|
+
fs.mkdirSync(outputDir, { recursive: true });
|
|
20
|
+
}
|
|
21
|
+
// Clear log file on build start
|
|
22
|
+
if (this.clearOnStart) {
|
|
23
|
+
compiler.hooks.beforeCompile.tap(pluginName, () => {
|
|
24
|
+
fs.writeFileSync(this.outputPath, '');
|
|
25
|
+
this.writeLog({
|
|
26
|
+
type: 'info',
|
|
27
|
+
message: 'Starting Re.Pack bundler...',
|
|
28
|
+
issuer: 'repack',
|
|
29
|
+
});
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
// Log compilation progress
|
|
33
|
+
compiler.hooks.compilation.tap(pluginName, (compilation) => {
|
|
34
|
+
this.writeLog({
|
|
35
|
+
type: 'progress',
|
|
36
|
+
message: 'Compilation started',
|
|
37
|
+
issuer: 'webpack',
|
|
38
|
+
});
|
|
39
|
+
});
|
|
40
|
+
// Log warnings and errors
|
|
41
|
+
compiler.hooks.done.tap(pluginName, (stats) => {
|
|
42
|
+
const info = stats.toJson({
|
|
43
|
+
errors: true,
|
|
44
|
+
warnings: true,
|
|
45
|
+
timings: true,
|
|
46
|
+
});
|
|
47
|
+
// Log warnings
|
|
48
|
+
if (info.warnings) {
|
|
49
|
+
for (const warning of info.warnings) {
|
|
50
|
+
this.writeLog({
|
|
51
|
+
type: 'warn',
|
|
52
|
+
message: typeof warning === 'string' ? warning : warning.message,
|
|
53
|
+
file: typeof warning === 'object' ? warning.moduleName : undefined,
|
|
54
|
+
issuer: 'webpack',
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
// Log errors
|
|
59
|
+
if (info.errors) {
|
|
60
|
+
for (const error of info.errors) {
|
|
61
|
+
this.writeLog({
|
|
62
|
+
type: 'error',
|
|
63
|
+
message: typeof error === 'string' ? error : error.message,
|
|
64
|
+
file: typeof error === 'object' ? error.moduleName : undefined,
|
|
65
|
+
stack: typeof error === 'object' ? error.stack : undefined,
|
|
66
|
+
issuer: 'webpack',
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
// Log completion
|
|
71
|
+
const hasErrors = info.errors && info.errors.length > 0;
|
|
72
|
+
this.writeLog({
|
|
73
|
+
type: hasErrors ? 'error' : 'success',
|
|
74
|
+
message: hasErrors
|
|
75
|
+
? `Compilation failed with ${info.errors?.length} error(s)`
|
|
76
|
+
: `Compilation finished in ${info.time}ms`,
|
|
77
|
+
duration: info.time,
|
|
78
|
+
issuer: 'repack',
|
|
79
|
+
});
|
|
80
|
+
});
|
|
81
|
+
// Log watch mode rebuilds
|
|
82
|
+
compiler.hooks.invalid.tap(pluginName, (fileName) => {
|
|
83
|
+
this.writeLog({
|
|
84
|
+
type: 'info',
|
|
85
|
+
message: `File changed: ${fileName || 'unknown'}`,
|
|
86
|
+
file: fileName || undefined,
|
|
87
|
+
issuer: 'watcher',
|
|
88
|
+
});
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
writeLog(entry) {
|
|
92
|
+
const logEntry = {
|
|
93
|
+
timestamp: new Date().toISOString(),
|
|
94
|
+
...entry,
|
|
95
|
+
};
|
|
96
|
+
try {
|
|
97
|
+
fs.appendFileSync(this.outputPath, JSON.stringify(logEntry) + '\n');
|
|
98
|
+
}
|
|
99
|
+
catch (err) {
|
|
100
|
+
console.error('[RepackLogsPlugin] Failed to write log:', err);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
export default RepackLogsPlugin;
|
|
105
|
+
//# sourceMappingURL=plugin.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plugin.js","sourceRoot":"","sources":["../src/plugin.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,IAAI,MAAM,WAAW,CAAC;AAe7B;;;GAGG;AACH,MAAM,OAAO,gBAAgB;IACnB,UAAU,CAAS;IACnB,YAAY,CAAU;IAE9B,YAAY,UAAmC,EAAE;QAC/C,IAAI,CAAC,UAAU,GAAG,OAAO,CAAC,UAAU,IAAI,mBAAmB,CAAC;QAC5D,IAAI,CAAC,YAAY,GAAG,OAAO,CAAC,YAAY,IAAI,IAAI,CAAC;IACnD,CAAC;IAED,KAAK,CAAC,QAAkB;QACtB,MAAM,UAAU,GAAG,kBAAkB,CAAC;QAEtC,iCAAiC;QACjC,MAAM,SAAS,GAAG,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;QAChD,IAAI,SAAS,IAAI,SAAS,KAAK,GAAG,EAAE,CAAC;YACnC,EAAE,CAAC,SAAS,CAAC,SAAS,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;QAC/C,CAAC;QAED,gCAAgC;QAChC,IAAI,IAAI,CAAC,YAAY,EAAE,CAAC;YACtB,QAAQ,CAAC,KAAK,CAAC,aAAa,CAAC,GAAG,CAAC,UAAU,EAAE,GAAG,EAAE;gBAChD,EAAE,CAAC,aAAa,CAAC,IAAI,CAAC,UAAU,EAAE,EAAE,CAAC,CAAC;gBACtC,IAAI,CAAC,QAAQ,CAAC;oBACZ,IAAI,EAAE,MAAM;oBACZ,OAAO,EAAE,6BAA6B;oBACtC,MAAM,EAAE,QAAQ;iBACjB,CAAC,CAAC;YACL,CAAC,CAAC,CAAC;QACL,CAAC;QAED,2BAA2B;QAC3B,QAAQ,CAAC,KAAK,CAAC,WAAW,CAAC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AAC,SAAS,CAAC,QAAQ,CAAC,GAAG,IAAI,CAAC,CAAC;QACtE,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACb,OAAO,CAAC,KAAK,CAAC,yCAAyC,EAAE,GAAG,CAAC,CAAC;QAChE,CAAC;IACH,CAAC;CACF;AAED,eAAe,gBAAgB,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,12 +1,16 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "repack-logs-mcp",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.1",
|
|
4
4
|
"description": "MCP server for tailing Re.Pack/Rock.js dev server logs",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
7
7
|
"bin": {
|
|
8
8
|
"repack-logs-mcp": "dist/index.js"
|
|
9
9
|
},
|
|
10
|
+
"exports": {
|
|
11
|
+
".": "./dist/index.js",
|
|
12
|
+
"./plugin": "./dist/plugin.js"
|
|
13
|
+
},
|
|
10
14
|
"scripts": {
|
|
11
15
|
"build": "tsc",
|
|
12
16
|
"dev": "tsc --watch",
|
|
@@ -27,9 +31,18 @@
|
|
|
27
31
|
"zod": "^3.23.0"
|
|
28
32
|
},
|
|
29
33
|
"devDependencies": {
|
|
34
|
+
"@rspack/core": "^1.0.0",
|
|
30
35
|
"@types/node": "^22.0.0",
|
|
31
36
|
"typescript": "^5.6.0"
|
|
32
37
|
},
|
|
38
|
+
"peerDependencies": {
|
|
39
|
+
"@rspack/core": ">=1.0.0"
|
|
40
|
+
},
|
|
41
|
+
"peerDependenciesMeta": {
|
|
42
|
+
"@rspack/core": {
|
|
43
|
+
"optional": true
|
|
44
|
+
}
|
|
45
|
+
},
|
|
33
46
|
"engines": {
|
|
34
47
|
"node": ">=18"
|
|
35
48
|
}
|
package/src/plugin.ts
ADDED
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import type { Compiler, Stats } from '@rspack/core';
|
|
4
|
+
import type { LogEntry, LogType } from './types.js';
|
|
5
|
+
|
|
6
|
+
export interface RepackLogsPluginOptions {
|
|
7
|
+
/**
|
|
8
|
+
* Path to the log file. Defaults to '.repack-logs.json' in the project root.
|
|
9
|
+
*/
|
|
10
|
+
outputPath?: string;
|
|
11
|
+
/**
|
|
12
|
+
* Whether to clear the log file on each build start. Defaults to true.
|
|
13
|
+
*/
|
|
14
|
+
clearOnStart?: boolean;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Rspack/Webpack plugin that writes build logs to a JSON file
|
|
19
|
+
* for consumption by the repack-logs-mcp server.
|
|
20
|
+
*/
|
|
21
|
+
export class RepackLogsPlugin {
|
|
22
|
+
private outputPath: string;
|
|
23
|
+
private clearOnStart: boolean;
|
|
24
|
+
|
|
25
|
+
constructor(options: RepackLogsPluginOptions = {}) {
|
|
26
|
+
this.outputPath = options.outputPath ?? '.repack-logs.json';
|
|
27
|
+
this.clearOnStart = options.clearOnStart ?? true;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
apply(compiler: Compiler): void {
|
|
31
|
+
const pluginName = 'RepackLogsPlugin';
|
|
32
|
+
|
|
33
|
+
// Ensure output directory exists
|
|
34
|
+
const outputDir = path.dirname(this.outputPath);
|
|
35
|
+
if (outputDir && outputDir !== '.') {
|
|
36
|
+
fs.mkdirSync(outputDir, { recursive: true });
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
// Clear log file on build start
|
|
40
|
+
if (this.clearOnStart) {
|
|
41
|
+
compiler.hooks.beforeCompile.tap(pluginName, () => {
|
|
42
|
+
fs.writeFileSync(this.outputPath, '');
|
|
43
|
+
this.writeLog({
|
|
44
|
+
type: 'info',
|
|
45
|
+
message: 'Starting Re.Pack bundler...',
|
|
46
|
+
issuer: 'repack',
|
|
47
|
+
});
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
// Log compilation progress
|
|
52
|
+
compiler.hooks.compilation.tap(pluginName, (compilation) => {
|
|
53
|
+
this.writeLog({
|
|
54
|
+
type: 'progress',
|
|
55
|
+
message: 'Compilation started',
|
|
56
|
+
issuer: 'webpack',
|
|
57
|
+
});
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
// Log warnings and errors
|
|
61
|
+
compiler.hooks.done.tap(pluginName, (stats: Stats) => {
|
|
62
|
+
const info = stats.toJson({
|
|
63
|
+
errors: true,
|
|
64
|
+
warnings: true,
|
|
65
|
+
timings: true,
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
// Log warnings
|
|
69
|
+
if (info.warnings) {
|
|
70
|
+
for (const warning of info.warnings) {
|
|
71
|
+
this.writeLog({
|
|
72
|
+
type: 'warn',
|
|
73
|
+
message: typeof warning === 'string' ? warning : warning.message,
|
|
74
|
+
file: typeof warning === 'object' ? warning.moduleName : undefined,
|
|
75
|
+
issuer: 'webpack',
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
// Log errors
|
|
81
|
+
if (info.errors) {
|
|
82
|
+
for (const error of info.errors) {
|
|
83
|
+
this.writeLog({
|
|
84
|
+
type: 'error',
|
|
85
|
+
message: typeof error === 'string' ? error : error.message,
|
|
86
|
+
file: typeof error === 'object' ? error.moduleName : undefined,
|
|
87
|
+
stack: typeof error === 'object' ? error.stack : undefined,
|
|
88
|
+
issuer: 'webpack',
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
// Log completion
|
|
94
|
+
const hasErrors = info.errors && info.errors.length > 0;
|
|
95
|
+
this.writeLog({
|
|
96
|
+
type: hasErrors ? 'error' : 'success',
|
|
97
|
+
message: hasErrors
|
|
98
|
+
? `Compilation failed with ${info.errors?.length} error(s)`
|
|
99
|
+
: `Compilation finished in ${info.time}ms`,
|
|
100
|
+
duration: info.time,
|
|
101
|
+
issuer: 'repack',
|
|
102
|
+
});
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
// Log watch mode rebuilds
|
|
106
|
+
compiler.hooks.invalid.tap(pluginName, (fileName) => {
|
|
107
|
+
this.writeLog({
|
|
108
|
+
type: 'info',
|
|
109
|
+
message: `File changed: ${fileName || 'unknown'}`,
|
|
110
|
+
file: fileName || undefined,
|
|
111
|
+
issuer: 'watcher',
|
|
112
|
+
});
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
private writeLog(entry: Omit<LogEntry, 'timestamp'>): void {
|
|
117
|
+
const logEntry = {
|
|
118
|
+
timestamp: new Date().toISOString(),
|
|
119
|
+
...entry,
|
|
120
|
+
} as LogEntry;
|
|
121
|
+
|
|
122
|
+
try {
|
|
123
|
+
fs.appendFileSync(this.outputPath, JSON.stringify(logEntry) + '\n');
|
|
124
|
+
} catch (err) {
|
|
125
|
+
console.error('[RepackLogsPlugin] Failed to write log:', err);
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
export default RepackLogsPlugin;
|