webpack-plugin-webmcp-nexus 0.1.9

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Alibaba
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,10 @@
1
+ // ../../node_modules/.pnpm/tsup@8.5.1_postcss@8.5.15_typescript@6.0.3/node_modules/tsup/assets/esm_shims.js
2
+ import path from "path";
3
+ import { fileURLToPath } from "url";
4
+ var getFilename = () => fileURLToPath(import.meta.url);
5
+ var getDirname = () => path.dirname(getFilename());
6
+ var __dirname = /* @__PURE__ */ getDirname();
7
+
8
+ export {
9
+ __dirname
10
+ };
@@ -0,0 +1,20 @@
1
+ import { Compiler } from 'webpack';
2
+
3
+ interface WebMcpPluginOptions {
4
+ /** 文件匹配规则,默认 /\.[jt]sx?$/ */
5
+ test?: RegExp;
6
+ /** 包含的目录路径(相对于项目根目录或绝对路径),默认 ['src'] */
7
+ include?: string[];
8
+ /**
9
+ * 额外的模块路径 alias(合并到 webpack 的 resolve.alias 之上)。
10
+ * 用于解析 `import * as api from '@alias/xxx'` 类型的模块说明符。
11
+ */
12
+ alias?: Record<string, string>;
13
+ }
14
+ declare class WebMcpPlugin {
15
+ private options;
16
+ constructor(options?: WebMcpPluginOptions);
17
+ apply(compiler: Compiler): void;
18
+ }
19
+
20
+ export { WebMcpPlugin, type WebMcpPluginOptions };
@@ -0,0 +1,20 @@
1
+ import { Compiler } from 'webpack';
2
+
3
+ interface WebMcpPluginOptions {
4
+ /** 文件匹配规则,默认 /\.[jt]sx?$/ */
5
+ test?: RegExp;
6
+ /** 包含的目录路径(相对于项目根目录或绝对路径),默认 ['src'] */
7
+ include?: string[];
8
+ /**
9
+ * 额外的模块路径 alias(合并到 webpack 的 resolve.alias 之上)。
10
+ * 用于解析 `import * as api from '@alias/xxx'` 类型的模块说明符。
11
+ */
12
+ alias?: Record<string, string>;
13
+ }
14
+ declare class WebMcpPlugin {
15
+ private options;
16
+ constructor(options?: WebMcpPluginOptions);
17
+ apply(compiler: Compiler): void;
18
+ }
19
+
20
+ export { WebMcpPlugin, type WebMcpPluginOptions };
package/dist/index.js ADDED
@@ -0,0 +1,100 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+
30
+ // src/index.ts
31
+ var index_exports = {};
32
+ __export(index_exports, {
33
+ WebMcpPlugin: () => WebMcpPlugin
34
+ });
35
+ module.exports = __toCommonJS(index_exports);
36
+
37
+ // src/plugin.ts
38
+ var import_node_path2 = __toESM(require("path"));
39
+
40
+ // src/resolve-loader.ts
41
+ var import_node_path = __toESM(require("path"));
42
+ function resolveLoaderPath() {
43
+ return import_node_path.default.resolve(__dirname, "loader.js");
44
+ }
45
+
46
+ // src/plugin.ts
47
+ var PLUGIN_NAME = "WebMcpPlugin";
48
+ function normalizeWebpackAlias(raw) {
49
+ const out = {};
50
+ if (!raw) return out;
51
+ if (Array.isArray(raw)) {
52
+ for (const item of raw) {
53
+ if (!item || typeof item !== "object") continue;
54
+ const name = item.name;
55
+ const alias = item.alias;
56
+ if (typeof name === "string" && typeof alias === "string") {
57
+ out[name] = alias;
58
+ }
59
+ }
60
+ return out;
61
+ }
62
+ if (typeof raw === "object") {
63
+ for (const [k, v] of Object.entries(raw)) {
64
+ if (typeof v === "string") out[k] = v;
65
+ }
66
+ }
67
+ return out;
68
+ }
69
+ var WebMcpPlugin = class {
70
+ options;
71
+ constructor(options = {}) {
72
+ this.options = {
73
+ test: options.test ?? /\.[jt]sx?$/,
74
+ include: options.include ?? ["src"],
75
+ alias: options.alias ?? {}
76
+ };
77
+ }
78
+ apply(compiler) {
79
+ const projectRoot = compiler.context;
80
+ const loaderPath = resolveLoaderPath();
81
+ const webpackAlias = normalizeWebpackAlias(compiler.options.resolve?.alias);
82
+ const mergedAlias = { ...webpackAlias, ...this.options.alias };
83
+ const rule = {
84
+ test: this.options.test,
85
+ // Webpack RuleSetRule.include 使用绝对路径前缀匹配,不支持 glob
86
+ include: this.options.include.map(
87
+ (p) => import_node_path2.default.isAbsolute(p) ? p : import_node_path2.default.resolve(projectRoot, p)
88
+ ),
89
+ enforce: "pre",
90
+ use: [{ loader: loaderPath, options: { projectRoot, alias: mergedAlias } }]
91
+ };
92
+ compiler.options.module.rules.push(rule);
93
+ compiler.hooks.done.tap(PLUGIN_NAME, (_stats) => {
94
+ });
95
+ }
96
+ };
97
+ // Annotate the CommonJS export names for ESM import in node:
98
+ 0 && (module.exports = {
99
+ WebMcpPlugin
100
+ });
package/dist/index.mjs ADDED
@@ -0,0 +1,67 @@
1
+ import {
2
+ __dirname
3
+ } from "./chunk-HWIKAAWN.mjs";
4
+
5
+ // src/plugin.ts
6
+ import path2 from "path";
7
+
8
+ // src/resolve-loader.ts
9
+ import path from "path";
10
+ function resolveLoaderPath() {
11
+ return path.resolve(__dirname, "loader.js");
12
+ }
13
+
14
+ // src/plugin.ts
15
+ var PLUGIN_NAME = "WebMcpPlugin";
16
+ function normalizeWebpackAlias(raw) {
17
+ const out = {};
18
+ if (!raw) return out;
19
+ if (Array.isArray(raw)) {
20
+ for (const item of raw) {
21
+ if (!item || typeof item !== "object") continue;
22
+ const name = item.name;
23
+ const alias = item.alias;
24
+ if (typeof name === "string" && typeof alias === "string") {
25
+ out[name] = alias;
26
+ }
27
+ }
28
+ return out;
29
+ }
30
+ if (typeof raw === "object") {
31
+ for (const [k, v] of Object.entries(raw)) {
32
+ if (typeof v === "string") out[k] = v;
33
+ }
34
+ }
35
+ return out;
36
+ }
37
+ var WebMcpPlugin = class {
38
+ options;
39
+ constructor(options = {}) {
40
+ this.options = {
41
+ test: options.test ?? /\.[jt]sx?$/,
42
+ include: options.include ?? ["src"],
43
+ alias: options.alias ?? {}
44
+ };
45
+ }
46
+ apply(compiler) {
47
+ const projectRoot = compiler.context;
48
+ const loaderPath = resolveLoaderPath();
49
+ const webpackAlias = normalizeWebpackAlias(compiler.options.resolve?.alias);
50
+ const mergedAlias = { ...webpackAlias, ...this.options.alias };
51
+ const rule = {
52
+ test: this.options.test,
53
+ // Webpack RuleSetRule.include 使用绝对路径前缀匹配,不支持 glob
54
+ include: this.options.include.map(
55
+ (p) => path2.isAbsolute(p) ? p : path2.resolve(projectRoot, p)
56
+ ),
57
+ enforce: "pre",
58
+ use: [{ loader: loaderPath, options: { projectRoot, alias: mergedAlias } }]
59
+ };
60
+ compiler.options.module.rules.push(rule);
61
+ compiler.hooks.done.tap(PLUGIN_NAME, (_stats) => {
62
+ });
63
+ }
64
+ };
65
+ export {
66
+ WebMcpPlugin
67
+ };
@@ -0,0 +1,10 @@
1
+ import { LoaderContext } from 'webpack';
2
+ import { AliasMap } from 'webmcp-nexus-core';
3
+
4
+ interface WebMcpLoaderOptions {
5
+ projectRoot?: string;
6
+ alias?: AliasMap;
7
+ }
8
+ declare function webmcpLoader(this: LoaderContext<WebMcpLoaderOptions>, source: string): string;
9
+
10
+ export { webmcpLoader as default };
@@ -0,0 +1,10 @@
1
+ import { LoaderContext } from 'webpack';
2
+ import { AliasMap } from 'webmcp-nexus-core';
3
+
4
+ interface WebMcpLoaderOptions {
5
+ projectRoot?: string;
6
+ alias?: AliasMap;
7
+ }
8
+ declare function webmcpLoader(this: LoaderContext<WebMcpLoaderOptions>, source: string): string;
9
+
10
+ export { webmcpLoader as default };
package/dist/loader.js ADDED
@@ -0,0 +1,53 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/loader.ts
21
+ var loader_exports = {};
22
+ __export(loader_exports, {
23
+ default: () => webmcpLoader
24
+ });
25
+ module.exports = __toCommonJS(loader_exports);
26
+ var import_webmcp_nexus_core = require("webmcp-nexus-core");
27
+ var isDebug = () => (process.env.DEBUG ?? "").toLowerCase().includes("webmcp");
28
+ function webmcpLoader(source) {
29
+ const filePath = this.resourcePath;
30
+ const options = this.getOptions() ?? {};
31
+ if (isDebug()) {
32
+ console.log(`[webmcp] loader processing: ${filePath}`);
33
+ }
34
+ try {
35
+ const result = (0, import_webmcp_nexus_core.transformCode)(source, filePath, {
36
+ projectRoot: options.projectRoot,
37
+ alias: options.alias
38
+ });
39
+ if (result.transformed) {
40
+ if (isDebug()) {
41
+ console.log(`[webmcp] transformed: ${filePath}`);
42
+ }
43
+ return result.code;
44
+ }
45
+ } catch (err) {
46
+ const message = err instanceof Error ? err.message : String(err);
47
+ this.emitWarning(new Error(`[webmcp] transform failed for ${filePath}: ${message}`));
48
+ if (isDebug()) {
49
+ console.warn(`[webmcp] transform error:`, err);
50
+ }
51
+ }
52
+ return source;
53
+ }
@@ -0,0 +1,34 @@
1
+ import "./chunk-HWIKAAWN.mjs";
2
+
3
+ // src/loader.ts
4
+ import { transformCode } from "webmcp-nexus-core";
5
+ var isDebug = () => (process.env.DEBUG ?? "").toLowerCase().includes("webmcp");
6
+ function webmcpLoader(source) {
7
+ const filePath = this.resourcePath;
8
+ const options = this.getOptions() ?? {};
9
+ if (isDebug()) {
10
+ console.log(`[webmcp] loader processing: ${filePath}`);
11
+ }
12
+ try {
13
+ const result = transformCode(source, filePath, {
14
+ projectRoot: options.projectRoot,
15
+ alias: options.alias
16
+ });
17
+ if (result.transformed) {
18
+ if (isDebug()) {
19
+ console.log(`[webmcp] transformed: ${filePath}`);
20
+ }
21
+ return result.code;
22
+ }
23
+ } catch (err) {
24
+ const message = err instanceof Error ? err.message : String(err);
25
+ this.emitWarning(new Error(`[webmcp] transform failed for ${filePath}: ${message}`));
26
+ if (isDebug()) {
27
+ console.warn(`[webmcp] transform error:`, err);
28
+ }
29
+ }
30
+ return source;
31
+ }
32
+ export {
33
+ webmcpLoader as default
34
+ };
package/package.json ADDED
@@ -0,0 +1,39 @@
1
+ {
2
+ "name": "webpack-plugin-webmcp-nexus",
3
+ "version": "0.1.9",
4
+ "description": "Webpack plugin for WebMCP - auto-injects __webmcpSchema at build time",
5
+ "main": "./dist/index.js",
6
+ "module": "./dist/index.mjs",
7
+ "types": "./dist/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "types": "./dist/index.d.ts",
11
+ "import": "./dist/index.mjs",
12
+ "require": "./dist/index.js"
13
+ },
14
+ "./loader": {
15
+ "types": "./dist/loader.d.ts",
16
+ "import": "./dist/loader.mjs",
17
+ "require": "./dist/loader.js"
18
+ }
19
+ },
20
+ "files": [
21
+ "dist"
22
+ ],
23
+ "dependencies": {
24
+ "webmcp-nexus-core": "0.1.9"
25
+ },
26
+ "peerDependencies": {
27
+ "webpack": "^5.0.0"
28
+ },
29
+ "devDependencies": {
30
+ "@types/node": "^24.12.2",
31
+ "tsup": "^8.5.0",
32
+ "webpack": "^5.98.0"
33
+ },
34
+ "scripts": {
35
+ "build": "tsup",
36
+ "test": "vitest run",
37
+ "test:watch": "vitest"
38
+ }
39
+ }