@jspm/local-mcp 0.1.1 → 0.1.3
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 +54 -76
- package/dist/cli.d.ts +3 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +20 -0
- package/dist/cli.js.map +1 -0
- package/dist/context.d.ts +39 -0
- package/dist/context.d.ts.map +1 -0
- package/dist/context.js +254 -0
- package/dist/context.js.map +1 -0
- package/dist/generator-options.d.ts +64 -0
- package/dist/generator-options.d.ts.map +1 -0
- package/dist/generator-options.js +78 -0
- package/dist/generator-options.js.map +1 -0
- package/dist/index.d.ts +10 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +17 -291
- package/dist/index.js.map +1 -1
- package/dist/tools/get-importmap.d.ts +4 -0
- package/dist/tools/get-importmap.d.ts.map +1 -0
- package/dist/tools/get-importmap.js +26 -0
- package/dist/tools/get-importmap.js.map +1 -0
- package/dist/tools/get-status.d.ts +4 -0
- package/dist/tools/get-status.d.ts.map +1 -0
- package/dist/tools/get-status.js +27 -0
- package/dist/tools/get-status.js.map +1 -0
- package/dist/tools/index.d.ts +4 -0
- package/dist/tools/index.d.ts.map +1 -0
- package/dist/tools/index.js +33 -0
- package/dist/tools/index.js.map +1 -0
- package/dist/tools/install-package.d.ts +4 -0
- package/dist/tools/install-package.d.ts.map +1 -0
- package/dist/tools/install-package.js +32 -0
- package/dist/tools/install-package.js.map +1 -0
- package/dist/tools/remove-provider-override.d.ts +4 -0
- package/dist/tools/remove-provider-override.d.ts.map +1 -0
- package/dist/tools/remove-provider-override.js +40 -0
- package/dist/tools/remove-provider-override.js.map +1 -0
- package/dist/tools/remove-resolution.d.ts +4 -0
- package/dist/tools/remove-resolution.d.ts.map +1 -0
- package/dist/tools/remove-resolution.js +40 -0
- package/dist/tools/remove-resolution.js.map +1 -0
- package/dist/tools/set-cache.d.ts +4 -0
- package/dist/tools/set-cache.d.ts.map +1 -0
- package/dist/tools/set-cache.js +40 -0
- package/dist/tools/set-cache.js.map +1 -0
- package/dist/tools/set-env.d.ts +4 -0
- package/dist/tools/set-env.d.ts.map +1 -0
- package/dist/tools/set-env.js +41 -0
- package/dist/tools/set-env.js.map +1 -0
- package/dist/tools/set-generator-options.d.ts +4 -0
- package/dist/tools/set-generator-options.d.ts.map +1 -0
- package/dist/tools/set-generator-options.js +43 -0
- package/dist/tools/set-generator-options.js.map +1 -0
- package/dist/tools/set-ignore.d.ts +4 -0
- package/dist/tools/set-ignore.d.ts.map +1 -0
- package/dist/tools/set-ignore.js +38 -0
- package/dist/tools/set-ignore.js.map +1 -0
- package/dist/tools/set-project.d.ts +4 -0
- package/dist/tools/set-project.d.ts.map +1 -0
- package/dist/tools/set-project.js +59 -0
- package/dist/tools/set-project.js.map +1 -0
- package/dist/tools/set-provider.d.ts +4 -0
- package/dist/tools/set-provider.d.ts.map +1 -0
- package/dist/tools/set-provider.js +57 -0
- package/dist/tools/set-provider.js.map +1 -0
- package/dist/tools/set-resolution.d.ts +4 -0
- package/dist/tools/set-resolution.d.ts.map +1 -0
- package/dist/tools/set-resolution.js +43 -0
- package/dist/tools/set-resolution.js.map +1 -0
- package/dist/tools/set-target.d.ts +4 -0
- package/dist/tools/set-target.d.ts.map +1 -0
- package/dist/tools/set-target.js +72 -0
- package/dist/tools/set-target.js.map +1 -0
- package/dist/tools/trace-file.d.ts +4 -0
- package/dist/tools/trace-file.d.ts.map +1 -0
- package/dist/tools/trace-file.js +48 -0
- package/dist/tools/trace-file.js.map +1 -0
- package/dist/tools/uninstall-package.d.ts +4 -0
- package/dist/tools/uninstall-package.d.ts.map +1 -0
- package/dist/tools/uninstall-package.js +32 -0
- package/dist/tools/uninstall-package.js.map +1 -0
- package/dist/utils.d.ts +3 -0
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +59 -2
- package/dist/utils.js.map +1 -1
- package/package.json +7 -4
package/Readme.md
CHANGED
|
@@ -1,37 +1,62 @@
|
|
|
1
1
|
# `@jspm/local-mcp`
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
A local-first [Model Context Protocol](https://modelcontextprotocol.io/) server for managing JSPM import maps inside a real project directory. Uses `@jspm/generator` to keep the full import map correct instead of hand-editing only the `imports` section.
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
Built for coding agents with filesystem access to your repo (Codex, Claude Code / Claude Desktop, Cursor, VS Code MCP).
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
## Tools
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
### Read-only
|
|
10
10
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
11
|
+
| Tool | Description | Inputs |
|
|
12
|
+
|------|-------------|--------|
|
|
13
|
+
| `get_status` | Returns the active project path, map target, environment conditions, and generator options. | none |
|
|
14
|
+
| `get_importmap` | Returns the current import map as JSON with the list of installed top-level specifiers. Requires `set_project` first. | none |
|
|
15
15
|
|
|
16
|
-
|
|
16
|
+
### Project setup
|
|
17
17
|
|
|
18
|
-
|
|
18
|
+
| Tool | Description | Inputs |
|
|
19
|
+
|------|-------------|--------|
|
|
20
|
+
| `set_project` | Sets the active project directory. | `path: string` |
|
|
21
|
+
| `set_target` | Choose `importmap` file or HTML injection mode. | `target: string`, `fileName?: string`, `esModuleShims?: boolean` |
|
|
22
|
+
| `set_env` | Switch between `"production"` and `"development"`. | `environment: "production"|"development"`, `customConditions?: string[]` |
|
|
19
23
|
|
|
20
|
-
|
|
21
|
-
- `set_target`: choose `importmap` or `html` output mode.
|
|
22
|
-
- `install_package`: install one or more packages with JSPM.
|
|
23
|
-
- `uninstall_package`: remove one or more packages from the import map.
|
|
24
|
-
- `trace_file`: trace imports from local source files and add the required mappings.
|
|
24
|
+
### Generator configuration
|
|
25
25
|
|
|
26
|
-
|
|
26
|
+
| Tool | Description | Inputs |
|
|
27
|
+
|------|-------------|--------|
|
|
28
|
+
| `set_generator_options` | Configure CommonJS, TypeScript, SystemJS, integrity, fetch retries, default provider, and more. | `commonJS?`, `typeScript?`, `system?`, `integrity?`, `fetchRetries?`, `defaultProvider?`, `cache?`, `providers?`, `resolutions?`, `ignore?`, `reinstall?` |
|
|
29
|
+
| `set_provider` | Set default provider (e.g. `"jspm.io"`, `"jsdelivr"`, `"unpkg"`) and scoped overrides. | `defaultProvider?`, `overrides?`, `reinstall?` |
|
|
30
|
+
| `remove_provider_override` | Remove one or more scoped provider overrides. | `specifiers: string[]`, `reinstall?` |
|
|
31
|
+
| `set_cache` | Configure cache mode (`true`, `false`, or `"offline"`). | `cache: boolean|"offline"`, `reinstall?` |
|
|
32
|
+
| `set_resolution` | Add or update package resolution overrides. | `resolutions: {specifier, target}[]`, `reinstall?` |
|
|
33
|
+
| `remove_resolution` | Remove package resolution overrides. | `specifiers: string[]`, `reinstall?` |
|
|
34
|
+
| `set_ignore` | Replace the list of specifiers JSPM ignores during tracing. | `specifiers: string[]`, `reinstall?` |
|
|
35
|
+
|
|
36
|
+
### Package management
|
|
37
|
+
|
|
38
|
+
| Tool | Description | Inputs |
|
|
39
|
+
|------|-------------|--------|
|
|
40
|
+
| `install_package` | Install one or more packages via the configured provider. | `packages: {packageName, version?}[]` |
|
|
41
|
+
| `uninstall_package` | Remove one or more packages from the import map. | `packageName: string|string[]` |
|
|
42
|
+
| `trace_file` | Trace imports from local source files and add required mappings. | `fileNames: string[]` |
|
|
43
|
+
|
|
44
|
+
## Typical Flow
|
|
45
|
+
|
|
46
|
+
```text
|
|
47
|
+
1. set_project({ path: "/absolute/path/to/project" })
|
|
48
|
+
2. set_target({ target: "html", fileName: "index.html" })
|
|
49
|
+
3. install_package({ packages: [{ packageName: "react" }, { packageName: "react-dom" }] })
|
|
50
|
+
4. trace_file({ fileNames: ["src/main.js"] })
|
|
51
|
+
```
|
|
27
52
|
|
|
28
|
-
|
|
53
|
+
## Install
|
|
29
54
|
|
|
30
55
|
```sh
|
|
31
56
|
npx -y @jspm/local-mcp
|
|
32
57
|
```
|
|
33
58
|
|
|
34
|
-
|
|
59
|
+
Or globally:
|
|
35
60
|
|
|
36
61
|
```sh
|
|
37
62
|
npm install -g @jspm/local-mcp
|
|
@@ -40,9 +65,7 @@ jspm-local-mcp
|
|
|
40
65
|
|
|
41
66
|
## MCP Client Setup
|
|
42
67
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
Add an MCP server that runs `npx`:
|
|
68
|
+
All clients use the same pattern:
|
|
46
69
|
|
|
47
70
|
```json
|
|
48
71
|
{
|
|
@@ -55,60 +78,17 @@ Add an MCP server that runs `npx`:
|
|
|
55
78
|
}
|
|
56
79
|
```
|
|
57
80
|
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
```json
|
|
61
|
-
{
|
|
62
|
-
"mcpServers": {
|
|
63
|
-
"jspm": {
|
|
64
|
-
"command": "npx",
|
|
65
|
-
"args": ["-y", "@jspm/local-mcp"]
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
```
|
|
81
|
+
For VS Code / GitHub Copilot, use the `"servers"` key instead of `"mcpServers"`.
|
|
70
82
|
|
|
71
|
-
|
|
83
|
+
If `npx` is unavailable, point directly to the installed executable:
|
|
72
84
|
|
|
73
85
|
```json
|
|
74
86
|
{
|
|
75
|
-
"
|
|
76
|
-
|
|
77
|
-
"command": "npx",
|
|
78
|
-
"args": ["-y", "@jspm/local-mcp"]
|
|
79
|
-
}
|
|
80
|
-
}
|
|
87
|
+
"command": "node",
|
|
88
|
+
"args": ["/path/to/jspm-mcp/dist/cli.js"]
|
|
81
89
|
}
|
|
82
90
|
```
|
|
83
91
|
|
|
84
|
-
If your environment does not expose `npx`, point the client at the installed executable instead.
|
|
85
|
-
|
|
86
|
-
## Typical Flow
|
|
87
|
-
|
|
88
|
-
Example conversation:
|
|
89
|
-
|
|
90
|
-
```text
|
|
91
|
-
Set the project to the current workspace.
|
|
92
|
-
Use index.html as the import map target.
|
|
93
|
-
Install react and react-dom.
|
|
94
|
-
Trace src/main.js and update the import map.
|
|
95
|
-
```
|
|
96
|
-
|
|
97
|
-
Equivalent tool calls:
|
|
98
|
-
|
|
99
|
-
1. `set_project({ path: "/absolute/path/to/project" })`
|
|
100
|
-
2. `set_target({ target: "html", fileName: "index.html" })`
|
|
101
|
-
3. `install_package({ packages: [{ packageName: "react" }, { packageName: "react-dom" }] })`
|
|
102
|
-
4. `trace_file({ fileNames: ["src/main.js"] })`
|
|
103
|
-
|
|
104
|
-
## Behavior Notes
|
|
105
|
-
|
|
106
|
-
- `set_project` defaults to `importmap.json`.
|
|
107
|
-
- Switching targets reloads the generator from the current file state.
|
|
108
|
-
- `set_target("html")` reads the existing HTML file and preserves any inline import map already there.
|
|
109
|
-
- `trace_file` works on files inside the configured project directory.
|
|
110
|
-
- Target files are restricted to the configured project directory.
|
|
111
|
-
|
|
112
92
|
## Local Development
|
|
113
93
|
|
|
114
94
|
```sh
|
|
@@ -117,16 +97,14 @@ npm run build
|
|
|
117
97
|
npm start
|
|
118
98
|
```
|
|
119
99
|
|
|
120
|
-
For
|
|
100
|
+
For auto-reload during development:
|
|
121
101
|
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
}
|
|
127
|
-
```
|
|
102
|
+
- Terminal: `npm run dev` (watches `src/` and rebuilds `dist/` on save)
|
|
103
|
+
- MCP client config: `node --watch /path/to/jspm-mcp/dist/cli.js`
|
|
104
|
+
|
|
105
|
+
The `--watch` flag restarts the server automatically when `dist/` changes.
|
|
128
106
|
|
|
129
|
-
## Publish
|
|
107
|
+
## Publish
|
|
130
108
|
|
|
131
109
|
```sh
|
|
132
110
|
npm run build
|
package/dist/cli.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":""}
|
package/dist/cli.js
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
|
3
|
+
import process from "node:process";
|
|
4
|
+
import { fileURLToPath } from "node:url";
|
|
5
|
+
import { createServer } from "./index.js";
|
|
6
|
+
async function main() {
|
|
7
|
+
const { server } = createServer();
|
|
8
|
+
const transport = new StdioServerTransport();
|
|
9
|
+
await server.connect(transport);
|
|
10
|
+
await server.sendLoggingMessage({
|
|
11
|
+
level: "info",
|
|
12
|
+
data: "JSPM MCP server started",
|
|
13
|
+
});
|
|
14
|
+
console.error(`JSPM MCP server running from ${fileURLToPath(import.meta.url)}`);
|
|
15
|
+
}
|
|
16
|
+
main().catch((error) => {
|
|
17
|
+
console.error("Fatal error:", error);
|
|
18
|
+
process.exit(1);
|
|
19
|
+
});
|
|
20
|
+
//# sourceMappingURL=cli.js.map
|
package/dist/cli.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cli.js","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":";AAEA,OAAO,EAAC,oBAAoB,EAAC,MAAM,2CAA2C,CAAA;AAC9E,OAAO,OAAO,MAAM,cAAc,CAAA;AAClC,OAAO,EAAC,aAAa,EAAC,MAAM,UAAU,CAAA;AACtC,OAAO,EAAC,YAAY,EAAC,MAAM,YAAY,CAAA;AAEvC,KAAK,UAAU,IAAI;IACjB,MAAM,EAAC,MAAM,EAAC,GAAG,YAAY,EAAE,CAAA;IAC/B,MAAM,SAAS,GAAG,IAAI,oBAAoB,EAAE,CAAA;IAE5C,MAAM,MAAM,CAAC,OAAO,CAAC,SAAS,CAAC,CAAA;IAC/B,MAAM,MAAM,CAAC,kBAAkB,CAAC;QAC9B,KAAK,EAAE,MAAM;QACb,IAAI,EAAE,yBAAyB;KAChC,CAAC,CAAA;IAEF,OAAO,CAAC,KAAK,CACX,gCAAgC,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,CACjE,CAAA;AACH,CAAC;AAED,IAAI,EAAE,CAAC,KAAK,CAAC,CAAC,KAAK,EAAE,EAAE;IACrB,OAAO,CAAC,KAAK,CAAC,cAAc,EAAE,KAAK,CAAC,CAAA;IACpC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAA;AACjB,CAAC,CAAC,CAAA"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { Generator } from "@jspm/generator";
|
|
2
|
+
import { CallToolResult } from "@modelcontextprotocol/sdk/types.js";
|
|
3
|
+
import { type ProjectGeneratorOptions } from "./generator-options.js";
|
|
4
|
+
export type MapTarget = "importmap" | "html";
|
|
5
|
+
export type ProjectEnvironment = "production" | "development";
|
|
6
|
+
export declare const DEFAULT_GENERATOR_ENV: string[];
|
|
7
|
+
export type ProjectContextState = {
|
|
8
|
+
projectPath?: string;
|
|
9
|
+
mapTarget: MapTarget;
|
|
10
|
+
env: string[];
|
|
11
|
+
generatorOptions: ProjectGeneratorOptions;
|
|
12
|
+
htmlFileName?: string;
|
|
13
|
+
esModuleShims: boolean;
|
|
14
|
+
generator?: Generator;
|
|
15
|
+
};
|
|
16
|
+
export type ProjectContext = {
|
|
17
|
+
state: ProjectContextState;
|
|
18
|
+
failure(text: string): CallToolResult;
|
|
19
|
+
ensureStateProjectPath(): string;
|
|
20
|
+
resolveProjectFilePath(fileName: string): string;
|
|
21
|
+
getGenerator(): Generator;
|
|
22
|
+
setEnv(env: string[]): void;
|
|
23
|
+
setGeneratorOptions(options: Partial<ProjectGeneratorOptions>): void;
|
|
24
|
+
setProviderOverride(specifier: string, provider: string): void;
|
|
25
|
+
removeProviderOverride(specifier: string): void;
|
|
26
|
+
setResolution(specifier: string, target: string): void;
|
|
27
|
+
removeResolution(specifier: string): void;
|
|
28
|
+
setIgnoreList(ignore: string[]): void;
|
|
29
|
+
reinstallTopLevelImports(): Promise<void>;
|
|
30
|
+
refreshGenerator(): Promise<void>;
|
|
31
|
+
resyncFromDisk(): Promise<void>;
|
|
32
|
+
applyConfigChange(mutate: () => void, reinstall: boolean): Promise<void>;
|
|
33
|
+
runExclusive<T>(work: () => Promise<T>): Promise<T>;
|
|
34
|
+
saveImportMap(): Promise<void>;
|
|
35
|
+
setDefaultMapTarget(): Promise<void>;
|
|
36
|
+
};
|
|
37
|
+
export declare function buildGeneratorEnv(environment: ProjectEnvironment, extraConditions?: string[]): string[];
|
|
38
|
+
export declare function createProjectContext(): ProjectContext;
|
|
39
|
+
//# sourceMappingURL=context.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../src/context.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,SAAS,EAAC,MAAM,iBAAiB,CAAA;AACzC,OAAO,EAAC,cAAc,EAAC,MAAM,oCAAoC,CAAA;AAWjE,OAAO,EAEL,KAAK,uBAAuB,EAC7B,MAAM,wBAAwB,CAAA;AAE/B,MAAM,MAAM,SAAS,GAAG,WAAW,GAAG,MAAM,CAAA;AAC5C,MAAM,MAAM,kBAAkB,GAAG,YAAY,GAAG,aAAa,CAAA;AAE7D,eAAO,MAAM,qBAAqB,UAAsC,CAAA;AAExE,MAAM,MAAM,mBAAmB,GAAG;IAChC,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB,SAAS,EAAE,SAAS,CAAA;IACpB,GAAG,EAAE,MAAM,EAAE,CAAA;IACb,gBAAgB,EAAE,uBAAuB,CAAA;IACzC,YAAY,CAAC,EAAE,MAAM,CAAA;IACrB,aAAa,EAAE,OAAO,CAAA;IACtB,SAAS,CAAC,EAAE,SAAS,CAAA;CACtB,CAAA;AAED,MAAM,MAAM,cAAc,GAAG;IAC3B,KAAK,EAAE,mBAAmB,CAAA;IAC1B,OAAO,CAAC,IAAI,EAAE,MAAM,GAAG,cAAc,CAAA;IACrC,sBAAsB,IAAI,MAAM,CAAA;IAChC,sBAAsB,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAAA;IAChD,YAAY,IAAI,SAAS,CAAA;IACzB,MAAM,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,IAAI,CAAA;IAC3B,mBAAmB,CAAC,OAAO,EAAE,OAAO,CAAC,uBAAuB,CAAC,GAAG,IAAI,CAAA;IACpE,mBAAmB,CAAC,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAA;IAC9D,sBAAsB,CAAC,SAAS,EAAE,MAAM,GAAG,IAAI,CAAA;IAC/C,aAAa,CAAC,SAAS,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,IAAI,CAAA;IACtD,gBAAgB,CAAC,SAAS,EAAE,MAAM,GAAG,IAAI,CAAA;IACzC,aAAa,CAAC,MAAM,EAAE,MAAM,EAAE,GAAG,IAAI,CAAA;IACrC,wBAAwB,IAAI,OAAO,CAAC,IAAI,CAAC,CAAA;IACzC,gBAAgB,IAAI,OAAO,CAAC,IAAI,CAAC,CAAA;IACjC,cAAc,IAAI,OAAO,CAAC,IAAI,CAAC,CAAA;IAC/B,iBAAiB,CAAC,MAAM,EAAE,MAAM,IAAI,EAAE,SAAS,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;IACxE,YAAY,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAAA;IACnD,aAAa,IAAI,OAAO,CAAC,IAAI,CAAC,CAAA;IAC9B,mBAAmB,IAAI,OAAO,CAAC,IAAI,CAAC,CAAA;CACrC,CAAA;AAiBD,wBAAgB,iBAAiB,CAC/B,WAAW,EAAE,kBAAkB,EAC/B,eAAe,GAAE,MAAM,EAAO,GAC7B,MAAM,EAAE,CAIV;AAED,wBAAgB,oBAAoB,IAAI,cAAc,CAsRrD"}
|
package/dist/context.js
ADDED
|
@@ -0,0 +1,254 @@
|
|
|
1
|
+
import { Generator } from "@jspm/generator";
|
|
2
|
+
import { existsSync, readFileSync, writeFileSync } from "node:fs";
|
|
3
|
+
import { dirname, resolve, sep } from "node:path";
|
|
4
|
+
import { pathToFileURL } from "node:url";
|
|
5
|
+
import { ensureProjectDirectory, ensureWritable, getImportMapLocation, getProjectFileLocation, isPathInside, } from "./utils.js";
|
|
6
|
+
import { DEFAULT_GENERATOR_OPTIONS, } from "./generator-options.js";
|
|
7
|
+
export const DEFAULT_GENERATOR_ENV = ["production", "browser", "module"];
|
|
8
|
+
function trailingSlash(path) {
|
|
9
|
+
return path.endsWith(sep) ? path : `${path}${sep}`;
|
|
10
|
+
}
|
|
11
|
+
function assertInsideProject(projectPath, candidatePath) {
|
|
12
|
+
if (!isPathInside(projectPath, candidatePath)) {
|
|
13
|
+
throw new Error("Target file must stay inside the configured project");
|
|
14
|
+
}
|
|
15
|
+
return resolve(candidatePath);
|
|
16
|
+
}
|
|
17
|
+
export function buildGeneratorEnv(environment, extraConditions = []) {
|
|
18
|
+
return Array.from(new Set([environment, "module", "browser", ...extraConditions]));
|
|
19
|
+
}
|
|
20
|
+
export function createProjectContext() {
|
|
21
|
+
const state = {
|
|
22
|
+
mapTarget: "importmap",
|
|
23
|
+
env: [...DEFAULT_GENERATOR_ENV],
|
|
24
|
+
generatorOptions: { ...DEFAULT_GENERATOR_OPTIONS },
|
|
25
|
+
esModuleShims: false,
|
|
26
|
+
};
|
|
27
|
+
// The MCP SDK dispatches incoming requests without serializing them, so a
|
|
28
|
+
// client that pipelines tool calls can run two handlers concurrently against
|
|
29
|
+
// this shared mutable context. Chain every mutating handler through a single
|
|
30
|
+
// promise queue so each one's refresh/reinstall/save runs atomically.
|
|
31
|
+
let queue = Promise.resolve();
|
|
32
|
+
function runExclusive(work) {
|
|
33
|
+
const result = queue.then(work, work);
|
|
34
|
+
queue = result.then(() => undefined, () => undefined);
|
|
35
|
+
return result;
|
|
36
|
+
}
|
|
37
|
+
async function setDefaultMapTarget() {
|
|
38
|
+
const projectPath = ensureStateProjectPath();
|
|
39
|
+
const importmapPath = getImportMapLocation(projectPath);
|
|
40
|
+
const htmlFileName = "index.html";
|
|
41
|
+
const htmlPath = getProjectFileLocation(projectPath, htmlFileName);
|
|
42
|
+
if (existsSync(importmapPath)) {
|
|
43
|
+
state.mapTarget = "importmap";
|
|
44
|
+
state.htmlFileName = undefined;
|
|
45
|
+
}
|
|
46
|
+
else if (existsSync(htmlPath)) {
|
|
47
|
+
state.mapTarget = "html";
|
|
48
|
+
state.htmlFileName = htmlFileName;
|
|
49
|
+
}
|
|
50
|
+
else {
|
|
51
|
+
state.mapTarget = "html";
|
|
52
|
+
state.htmlFileName = undefined;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
function failure(text) {
|
|
56
|
+
return {
|
|
57
|
+
content: [{ type: "text", text }],
|
|
58
|
+
isError: true,
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
function ensureStateProjectPath() {
|
|
62
|
+
return ensureProjectDirectory(state.projectPath);
|
|
63
|
+
}
|
|
64
|
+
function resolveProjectFilePath(fileName) {
|
|
65
|
+
const projectPath = ensureStateProjectPath();
|
|
66
|
+
const filePath = getProjectFileLocation(projectPath, fileName);
|
|
67
|
+
return assertInsideProject(projectPath, filePath);
|
|
68
|
+
}
|
|
69
|
+
function getGenerator() {
|
|
70
|
+
if (!state.generator) {
|
|
71
|
+
throw new Error("Generator is not ready. Call set_project first and optionally set_target.");
|
|
72
|
+
}
|
|
73
|
+
return state.generator;
|
|
74
|
+
}
|
|
75
|
+
function setEnv(env) {
|
|
76
|
+
state.env = env;
|
|
77
|
+
}
|
|
78
|
+
function setGeneratorOptions(options) {
|
|
79
|
+
state.generatorOptions = {
|
|
80
|
+
...state.generatorOptions,
|
|
81
|
+
...options,
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
function setProviderOverride(specifier, provider) {
|
|
85
|
+
state.generatorOptions.providers = {
|
|
86
|
+
...state.generatorOptions.providers,
|
|
87
|
+
[specifier]: provider,
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
function removeProviderOverride(specifier) {
|
|
91
|
+
const providers = { ...state.generatorOptions.providers };
|
|
92
|
+
delete providers[specifier];
|
|
93
|
+
state.generatorOptions.providers = providers;
|
|
94
|
+
}
|
|
95
|
+
function setResolution(specifier, target) {
|
|
96
|
+
state.generatorOptions.resolutions = {
|
|
97
|
+
...state.generatorOptions.resolutions,
|
|
98
|
+
[specifier]: target,
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
function removeResolution(specifier) {
|
|
102
|
+
const resolutions = { ...state.generatorOptions.resolutions };
|
|
103
|
+
delete resolutions[specifier];
|
|
104
|
+
state.generatorOptions.resolutions = resolutions;
|
|
105
|
+
}
|
|
106
|
+
function setIgnoreList(ignore) {
|
|
107
|
+
state.generatorOptions.ignore = Array.from(new Set(ignore));
|
|
108
|
+
}
|
|
109
|
+
async function refreshGenerator() {
|
|
110
|
+
const projectPath = ensureStateProjectPath();
|
|
111
|
+
const projectUrl = pathToFileURL(trailingSlash(projectPath));
|
|
112
|
+
const mapPath = state.mapTarget === "html"
|
|
113
|
+
? resolveProjectFilePath(state.htmlFileName)
|
|
114
|
+
: getImportMapLocation(projectPath);
|
|
115
|
+
const mapUrl = pathToFileURL(mapPath);
|
|
116
|
+
const generator = new Generator({
|
|
117
|
+
mapUrl,
|
|
118
|
+
rootUrl: projectUrl,
|
|
119
|
+
env: state.env,
|
|
120
|
+
defaultProvider: state.generatorOptions.defaultProvider,
|
|
121
|
+
cache: state.generatorOptions.cache,
|
|
122
|
+
providers: state.generatorOptions.providers,
|
|
123
|
+
resolutions: state.generatorOptions.resolutions,
|
|
124
|
+
ignore: state.generatorOptions.ignore,
|
|
125
|
+
commonJS: state.generatorOptions.commonJS,
|
|
126
|
+
typeScript: state.generatorOptions.typeScript,
|
|
127
|
+
system: state.generatorOptions.system,
|
|
128
|
+
integrity: state.generatorOptions.integrity,
|
|
129
|
+
fetchRetries: state.generatorOptions.fetchRetries,
|
|
130
|
+
});
|
|
131
|
+
if (state.mapTarget === "importmap") {
|
|
132
|
+
if (existsSync(mapPath)) {
|
|
133
|
+
const mapSource = readFileSync(mapPath, "utf-8");
|
|
134
|
+
let mapJson;
|
|
135
|
+
try {
|
|
136
|
+
mapJson = JSON.parse(mapSource);
|
|
137
|
+
}
|
|
138
|
+
catch (error) {
|
|
139
|
+
throw new Error(`importmap.json is not valid JSON: ${error.message}`);
|
|
140
|
+
}
|
|
141
|
+
await generator.addMappings(mapJson, mapUrl, projectUrl);
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
else {
|
|
145
|
+
const htmlSource = readFileSync(mapPath, "utf-8");
|
|
146
|
+
await generator.addMappings(htmlSource, mapUrl, projectUrl);
|
|
147
|
+
}
|
|
148
|
+
state.generator = generator;
|
|
149
|
+
}
|
|
150
|
+
async function reinstallTopLevelImports() {
|
|
151
|
+
const generator = getGenerator();
|
|
152
|
+
try {
|
|
153
|
+
await generator.install();
|
|
154
|
+
}
|
|
155
|
+
catch (error) {
|
|
156
|
+
// An argumentless install() reinstalls the top-level imports, but the
|
|
157
|
+
// generator's reinstall path throws a "reading 'target'" TypeError when
|
|
158
|
+
// there are no top-level locks to reinstall (e.g. an empty project).
|
|
159
|
+
// Reinstalling nothing is a no-op, so swallow that specific crash and
|
|
160
|
+
// let any genuine install error propagate.
|
|
161
|
+
if (error instanceof TypeError &&
|
|
162
|
+
/reading 'target'/.test(error.message)) {
|
|
163
|
+
return;
|
|
164
|
+
}
|
|
165
|
+
throw error;
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
// Discard any in-memory generator mutations from a failed operation by
|
|
169
|
+
// rebuilding the generator from the on-disk map, so a failed tool call
|
|
170
|
+
// cannot be silently persisted by a later one.
|
|
171
|
+
async function resyncFromDisk() {
|
|
172
|
+
if (state.generator) {
|
|
173
|
+
await refreshGenerator();
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
// Apply a configuration change transactionally: snapshot the config,
|
|
177
|
+
// mutate, rebuild the generator, optionally reinstall, then save. On any
|
|
178
|
+
// failure, restore the snapshot and resync from disk so a rejected change
|
|
179
|
+
// never lingers in memory to activate on a later call. Runs exclusively so
|
|
180
|
+
// it cannot interleave with another mutating handler.
|
|
181
|
+
function applyConfigChange(mutate, reinstall) {
|
|
182
|
+
return runExclusive(async () => {
|
|
183
|
+
const previousOptions = { ...state.generatorOptions };
|
|
184
|
+
const previousEnv = [...state.env];
|
|
185
|
+
try {
|
|
186
|
+
mutate();
|
|
187
|
+
await refreshGenerator();
|
|
188
|
+
if (reinstall) {
|
|
189
|
+
await reinstallTopLevelImports();
|
|
190
|
+
}
|
|
191
|
+
await saveImportMap();
|
|
192
|
+
}
|
|
193
|
+
catch (error) {
|
|
194
|
+
state.generatorOptions = previousOptions;
|
|
195
|
+
state.env = previousEnv;
|
|
196
|
+
await resyncFromDisk();
|
|
197
|
+
throw error;
|
|
198
|
+
}
|
|
199
|
+
});
|
|
200
|
+
}
|
|
201
|
+
async function saveImportMap() {
|
|
202
|
+
const projectPath = ensureStateProjectPath();
|
|
203
|
+
const generator = getGenerator();
|
|
204
|
+
const projectUrl = pathToFileURL(trailingSlash(projectPath));
|
|
205
|
+
try {
|
|
206
|
+
if (state.mapTarget === "importmap") {
|
|
207
|
+
const importMapPath = getImportMapLocation(projectPath);
|
|
208
|
+
const parentDirectory = dirname(importMapPath);
|
|
209
|
+
await ensureWritable(parentDirectory);
|
|
210
|
+
writeFileSync(importMapPath, `${JSON.stringify(generator.getMap(), null, 2)}\n`, "utf-8");
|
|
211
|
+
return;
|
|
212
|
+
}
|
|
213
|
+
const htmlPath = resolveProjectFilePath(state.htmlFileName);
|
|
214
|
+
const htmlSource = readFileSync(htmlPath, "utf-8");
|
|
215
|
+
await ensureWritable(htmlPath);
|
|
216
|
+
const injectedHtml = await generator.htmlInject(htmlSource, {
|
|
217
|
+
trace: true,
|
|
218
|
+
pins: true,
|
|
219
|
+
htmlUrl: pathToFileURL(htmlPath),
|
|
220
|
+
rootUrl: projectUrl,
|
|
221
|
+
esModuleShims: state.esModuleShims,
|
|
222
|
+
});
|
|
223
|
+
writeFileSync(htmlPath, injectedHtml, "utf-8");
|
|
224
|
+
}
|
|
225
|
+
catch (error) {
|
|
226
|
+
if (error.code === "EACCES") {
|
|
227
|
+
throw new Error("Permission denied while updating the import map target");
|
|
228
|
+
}
|
|
229
|
+
throw error;
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
return {
|
|
233
|
+
state,
|
|
234
|
+
failure,
|
|
235
|
+
ensureStateProjectPath,
|
|
236
|
+
resolveProjectFilePath,
|
|
237
|
+
getGenerator,
|
|
238
|
+
setEnv,
|
|
239
|
+
setGeneratorOptions,
|
|
240
|
+
setProviderOverride,
|
|
241
|
+
removeProviderOverride,
|
|
242
|
+
setResolution,
|
|
243
|
+
removeResolution,
|
|
244
|
+
setIgnoreList,
|
|
245
|
+
reinstallTopLevelImports,
|
|
246
|
+
refreshGenerator,
|
|
247
|
+
resyncFromDisk,
|
|
248
|
+
applyConfigChange,
|
|
249
|
+
runExclusive,
|
|
250
|
+
saveImportMap,
|
|
251
|
+
setDefaultMapTarget,
|
|
252
|
+
};
|
|
253
|
+
}
|
|
254
|
+
//# sourceMappingURL=context.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"context.js","sourceRoot":"","sources":["../src/context.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,SAAS,EAAC,MAAM,iBAAiB,CAAA;AAEzC,OAAO,EAAC,UAAU,EAAE,YAAY,EAAE,aAAa,EAAC,MAAM,SAAS,CAAA;AAC/D,OAAO,EAAC,OAAO,EAAE,OAAO,EAAE,GAAG,EAAC,MAAM,WAAW,CAAA;AAC/C,OAAO,EAAC,aAAa,EAAC,MAAM,UAAU,CAAA;AACtC,OAAO,EACL,sBAAsB,EACtB,cAAc,EACd,oBAAoB,EACpB,sBAAsB,EACtB,YAAY,GACb,MAAM,YAAY,CAAA;AACnB,OAAO,EACL,yBAAyB,GAE1B,MAAM,wBAAwB,CAAA;AAK/B,MAAM,CAAC,MAAM,qBAAqB,GAAG,CAAC,YAAY,EAA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C5D,MAAM,UAAU,GAAG,YAAY,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAA;YAElD,MAAM,cAAc,CAAC,QAAQ,CAAC,CAAA;YAC9B,MAAM,YAAY,GAAG,MAAM,SAAS,CAAC,UAAU,CAAC,UAAU,EAAE;gBAC1D,KAAK,EAAE,IAAI;gBACX,IAAI,EAAE,IAAI;gBACV,OAAO,EAAE,aAAa,CAAC,QAAQ,CAAC;gBAChC,OAAO,EAAE,UAAU;gBACnB,aAAa,EAAE,KAAK,CAAC,aAAa;aACnC,CAAC,CAAA;YACF,aAAa,CAAC,QAAQ,EAAE,YAAY,EAAE,OAAO,CAAC,CAAA;QAChD,CAAC;QAAC,OAAO,KAAc,EAAE,CAAC;YACxB,IAAK,KAA+B,CAAC,IAAI,KAAK,QAAQ,EAAE,CAAC;gBACvD,MAAM,IAAI,KAAK,CACb,wDAAwD,CACzD,CAAA;YACH,CAAC;YAED,MAAM,KAAK,CAAA;QACb,CAAC;IACH,CAAC;IAED,OAAO;QACL,KAAK;QACL,OAAO;QACP,sBAAsB;QACtB,sBAAsB;QACtB,YAAY;QACZ,MAAM;QACN,mBAAmB;QACnB,mBAAmB;QACnB,sBAAsB;QACtB,aAAa;QACb,gBAAgB;QAChB,aAAa;QACb,wBAAwB;QACxB,gBAAgB;QAChB,cAAc;QACd,iBAAiB;QACjB,YAAY;QACZ,aAAa;QACb,mBAAmB;KACpB,CAAA;AACH,CAAC"}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { type GeneratorOptions } from "@jspm/generator";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
export declare const PROVIDER_SCHEMA: z.ZodEnum<["jspm.io", "jspm.io#system", "nodemodules", "skypack", "jsdelivr", "unpkg", "esm.sh"]>;
|
|
4
|
+
export declare const PROJECT_GENERATOR_OPTION_KEYS: readonly ["commonJS", "typeScript", "system", "integrity", "fetchRetries", "defaultProvider", "cache", "providers", "resolutions", "ignore"];
|
|
5
|
+
export type ProjectGeneratorOptions = Required<Pick<GeneratorOptions, (typeof PROJECT_GENERATOR_OPTION_KEYS)[number]>>;
|
|
6
|
+
export declare const DEFAULT_GENERATOR_OPTIONS: {
|
|
7
|
+
commonJS: false;
|
|
8
|
+
typeScript: false;
|
|
9
|
+
system: false;
|
|
10
|
+
integrity: false;
|
|
11
|
+
fetchRetries: number;
|
|
12
|
+
defaultProvider: string;
|
|
13
|
+
cache: true;
|
|
14
|
+
providers: {};
|
|
15
|
+
resolutions: {};
|
|
16
|
+
ignore: never[];
|
|
17
|
+
};
|
|
18
|
+
export declare const PROJECT_GENERATOR_OPTION_FIELDS: {
|
|
19
|
+
readonly commonJS: z.ZodOptional<z.ZodBoolean>;
|
|
20
|
+
readonly typeScript: z.ZodOptional<z.ZodBoolean>;
|
|
21
|
+
readonly system: z.ZodOptional<z.ZodBoolean>;
|
|
22
|
+
readonly integrity: z.ZodOptional<z.ZodBoolean>;
|
|
23
|
+
readonly fetchRetries: z.ZodOptional<z.ZodNumber>;
|
|
24
|
+
readonly defaultProvider: z.ZodOptional<z.ZodEnum<["jspm.io", "jspm.io#system", "nodemodules", "skypack", "jsdelivr", "unpkg", "esm.sh"]>>;
|
|
25
|
+
readonly cache: z.ZodOptional<z.ZodUnion<[z.ZodBoolean, z.ZodLiteral<"offline">]>>;
|
|
26
|
+
readonly providers: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodEnum<["jspm.io", "jspm.io#system", "nodemodules", "skypack", "jsdelivr", "unpkg", "esm.sh"]>>>;
|
|
27
|
+
readonly resolutions: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
28
|
+
readonly ignore: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
29
|
+
};
|
|
30
|
+
export declare const PROJECT_GENERATOR_OPTIONS_SCHEMA: z.ZodObject<{
|
|
31
|
+
readonly commonJS: z.ZodOptional<z.ZodBoolean>;
|
|
32
|
+
readonly typeScript: z.ZodOptional<z.ZodBoolean>;
|
|
33
|
+
readonly system: z.ZodOptional<z.ZodBoolean>;
|
|
34
|
+
readonly integrity: z.ZodOptional<z.ZodBoolean>;
|
|
35
|
+
readonly fetchRetries: z.ZodOptional<z.ZodNumber>;
|
|
36
|
+
readonly defaultProvider: z.ZodOptional<z.ZodEnum<["jspm.io", "jspm.io#system", "nodemodules", "skypack", "jsdelivr", "unpkg", "esm.sh"]>>;
|
|
37
|
+
readonly cache: z.ZodOptional<z.ZodUnion<[z.ZodBoolean, z.ZodLiteral<"offline">]>>;
|
|
38
|
+
readonly providers: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodEnum<["jspm.io", "jspm.io#system", "nodemodules", "skypack", "jsdelivr", "unpkg", "esm.sh"]>>>;
|
|
39
|
+
readonly resolutions: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
40
|
+
readonly ignore: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
41
|
+
}, "strip", z.ZodTypeAny, {
|
|
42
|
+
commonJS?: boolean | undefined;
|
|
43
|
+
typeScript?: boolean | undefined;
|
|
44
|
+
system?: boolean | undefined;
|
|
45
|
+
integrity?: boolean | undefined;
|
|
46
|
+
fetchRetries?: number | undefined;
|
|
47
|
+
defaultProvider?: "jspm.io" | "jspm.io#system" | "nodemodules" | "skypack" | "jsdelivr" | "unpkg" | "esm.sh" | undefined;
|
|
48
|
+
cache?: boolean | "offline" | undefined;
|
|
49
|
+
providers?: Record<string, "jspm.io" | "jspm.io#system" | "nodemodules" | "skypack" | "jsdelivr" | "unpkg" | "esm.sh"> | undefined;
|
|
50
|
+
resolutions?: Record<string, string> | undefined;
|
|
51
|
+
ignore?: string[] | undefined;
|
|
52
|
+
}, {
|
|
53
|
+
commonJS?: boolean | undefined;
|
|
54
|
+
typeScript?: boolean | undefined;
|
|
55
|
+
system?: boolean | undefined;
|
|
56
|
+
integrity?: boolean | undefined;
|
|
57
|
+
fetchRetries?: number | undefined;
|
|
58
|
+
defaultProvider?: "jspm.io" | "jspm.io#system" | "nodemodules" | "skypack" | "jsdelivr" | "unpkg" | "esm.sh" | undefined;
|
|
59
|
+
cache?: boolean | "offline" | undefined;
|
|
60
|
+
providers?: Record<string, "jspm.io" | "jspm.io#system" | "nodemodules" | "skypack" | "jsdelivr" | "unpkg" | "esm.sh"> | undefined;
|
|
61
|
+
resolutions?: Record<string, string> | undefined;
|
|
62
|
+
ignore?: string[] | undefined;
|
|
63
|
+
}>;
|
|
64
|
+
//# sourceMappingURL=generator-options.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generator-options.d.ts","sourceRoot":"","sources":["../src/generator-options.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,KAAK,gBAAgB,EAAC,MAAM,iBAAiB,CAAA;AACrD,OAAO,EAAC,CAAC,EAAC,MAAM,KAAK,CAAA;AAErB,eAAO,MAAM,eAAe,mGAQ1B,CAAA;AAEF,eAAO,MAAM,6BAA6B,8IAWhC,CAAA;AAEV,MAAM,MAAM,uBAAuB,GAAG,QAAQ,CAC5C,IAAI,CAAC,gBAAgB,EAAE,CAAC,OAAO,6BAA6B,CAAC,CAAC,MAAM,CAAC,CAAC,CACvE,CAAA;AAED,eAAO,MAAM,yBAAyB;;;;;;;;;;;CAWH,CAAA;AAEnC,eAAO,MAAM,+BAA+B;;;;;;;;;;;CA+ClC,CAAA;AAEV,eAAO,MAAM,gCAAgC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAE5C,CAAA"}
|