@meituan-nocode/vite-plugin-nocode-compiler 0.2.4-beta.0 → 0.2.4-beta.2

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/dist/index.cjs CHANGED
@@ -102,6 +102,48 @@ function componentCompiler(options = {}) {
102
102
  res.end(JSON.stringify({ error: String(error) }));
103
103
  }
104
104
  });
105
+ server.middlewares.use("/__nocode_file_override_reset", async (req, res, next) => {
106
+ if (req.method !== "POST") {
107
+ return next();
108
+ }
109
+ try {
110
+ const { file } = await readJsonBody(req);
111
+ if (!file) {
112
+ res.statusCode = 400;
113
+ res.end(JSON.stringify({ error: "file is required" }));
114
+ return;
115
+ }
116
+ const absolutePath = (0, import_path.resolve)(server.config.root, file);
117
+ const hadOverride = overrideMap.delete(absolutePath);
118
+ if (!hadOverride) {
119
+ res.statusCode = 200;
120
+ res.end(JSON.stringify({ success: true, message: "no override to reset" }));
121
+ return;
122
+ }
123
+ const mods = server.moduleGraph.getModulesByFile(absolutePath);
124
+ if (mods && mods.size > 0) {
125
+ for (const mod of mods) {
126
+ server.moduleGraph.invalidateModule(mod);
127
+ server.ws.send({
128
+ type: "update",
129
+ updates: [
130
+ {
131
+ type: "js-update",
132
+ path: mod.url,
133
+ acceptedPath: mod.url,
134
+ timestamp: Date.now()
135
+ }
136
+ ]
137
+ });
138
+ }
139
+ }
140
+ res.statusCode = 200;
141
+ res.end(JSON.stringify({ success: true }));
142
+ } catch (error) {
143
+ res.statusCode = 500;
144
+ res.end(JSON.stringify({ error: String(error) }));
145
+ }
146
+ });
105
147
  },
106
148
  /**
107
149
  * 加载模块时,如果有 override 则返回 override 内容
package/dist/index.js CHANGED
@@ -77,6 +77,48 @@ function componentCompiler(options = {}) {
77
77
  res.end(JSON.stringify({ error: String(error) }));
78
78
  }
79
79
  });
80
+ server.middlewares.use("/__nocode_file_override_reset", async (req, res, next) => {
81
+ if (req.method !== "POST") {
82
+ return next();
83
+ }
84
+ try {
85
+ const { file } = await readJsonBody(req);
86
+ if (!file) {
87
+ res.statusCode = 400;
88
+ res.end(JSON.stringify({ error: "file is required" }));
89
+ return;
90
+ }
91
+ const absolutePath = resolve(server.config.root, file);
92
+ const hadOverride = overrideMap.delete(absolutePath);
93
+ if (!hadOverride) {
94
+ res.statusCode = 200;
95
+ res.end(JSON.stringify({ success: true, message: "no override to reset" }));
96
+ return;
97
+ }
98
+ const mods = server.moduleGraph.getModulesByFile(absolutePath);
99
+ if (mods && mods.size > 0) {
100
+ for (const mod of mods) {
101
+ server.moduleGraph.invalidateModule(mod);
102
+ server.ws.send({
103
+ type: "update",
104
+ updates: [
105
+ {
106
+ type: "js-update",
107
+ path: mod.url,
108
+ acceptedPath: mod.url,
109
+ timestamp: Date.now()
110
+ }
111
+ ]
112
+ });
113
+ }
114
+ }
115
+ res.statusCode = 200;
116
+ res.end(JSON.stringify({ success: true }));
117
+ } catch (error) {
118
+ res.statusCode = 500;
119
+ res.end(JSON.stringify({ error: String(error) }));
120
+ }
121
+ });
80
122
  },
81
123
  /**
82
124
  * 加载模块时,如果有 override 则返回 override 内容
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@meituan-nocode/vite-plugin-nocode-compiler",
3
- "version": "0.2.4-beta.0",
3
+ "version": "0.2.4-beta.2",
4
4
  "description": "Vite plugin for nocode compiler",
5
5
  "type": "module",
6
6
  "exports": {