@meituan-nocode/vite-plugin-nocode-compiler 0.2.4-beta.4 → 0.2.4-beta.6

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
@@ -73,61 +73,31 @@ function componentCompiler(options = {}) {
73
73
  configureServer(_server) {
74
74
  if (!options.enableOverride) return;
75
75
  server = _server;
76
- server.middlewares.use("/__nocode_file_override", async (req, res, next) => {
77
- if (req.method !== "POST") {
78
- return next();
79
- }
80
- try {
81
- const { file, code } = await readJsonBody(req);
82
- if (!file || typeof code !== "string") {
83
- res.statusCode = 400;
84
- res.end(JSON.stringify({ error: "file and code are required" }));
85
- return;
86
- }
87
- const absolutePath = (0, import_path.resolve)(server.config.root, file);
88
- overrideMap.set(absolutePath, code);
89
- const mods = server.moduleGraph.getModulesByFile(absolutePath);
76
+ server.ws.on("connection", () => {
77
+ if (overrideMap.size === 0) return;
78
+ for (const filePath of overrideMap.keys()) {
79
+ const mods = server.moduleGraph.getModulesByFile(filePath);
90
80
  if (mods && mods.size > 0) {
91
81
  for (const mod of mods) {
92
82
  server.moduleGraph.invalidateModule(mod);
93
- server.ws.send({
94
- type: "update",
95
- updates: [
96
- {
97
- type: "js-update",
98
- path: mod.url,
99
- acceptedPath: mod.url,
100
- timestamp: Date.now()
101
- }
102
- ]
103
- });
104
83
  }
105
84
  }
106
- res.statusCode = 200;
107
- res.end(JSON.stringify({ success: true }));
108
- } catch (error) {
109
- res.statusCode = 500;
110
- res.end(JSON.stringify({ error: String(error) }));
111
85
  }
86
+ overrideMap.clear();
112
87
  });
113
- server.middlewares.use("/__nocode_file_override_reset", async (req, res, next) => {
88
+ server.middlewares.use("/__nocode_file_override", async (req, res, next) => {
114
89
  if (req.method !== "POST") {
115
90
  return next();
116
91
  }
117
92
  try {
118
- const { file } = await readJsonBody(req);
119
- if (!file) {
93
+ const { file, code } = await readJsonBody(req);
94
+ if (!file || typeof code !== "string") {
120
95
  res.statusCode = 400;
121
- res.end(JSON.stringify({ error: "file is required" }));
96
+ res.end(JSON.stringify({ error: "file and code are required" }));
122
97
  return;
123
98
  }
124
99
  const absolutePath = (0, import_path.resolve)(server.config.root, file);
125
- const hadOverride = overrideMap.delete(absolutePath);
126
- if (!hadOverride) {
127
- res.statusCode = 200;
128
- res.end(JSON.stringify({ success: true, message: "no override to reset" }));
129
- return;
130
- }
100
+ overrideMap.set(absolutePath, code);
131
101
  const mods = server.moduleGraph.getModulesByFile(absolutePath);
132
102
  if (mods && mods.size > 0) {
133
103
  for (const mod of mods) {
package/dist/index.js CHANGED
@@ -48,61 +48,31 @@ function componentCompiler(options = {}) {
48
48
  configureServer(_server) {
49
49
  if (!options.enableOverride) return;
50
50
  server = _server;
51
- server.middlewares.use("/__nocode_file_override", async (req, res, next) => {
52
- if (req.method !== "POST") {
53
- return next();
54
- }
55
- try {
56
- const { file, code } = await readJsonBody(req);
57
- if (!file || typeof code !== "string") {
58
- res.statusCode = 400;
59
- res.end(JSON.stringify({ error: "file and code are required" }));
60
- return;
61
- }
62
- const absolutePath = resolve(server.config.root, file);
63
- overrideMap.set(absolutePath, code);
64
- const mods = server.moduleGraph.getModulesByFile(absolutePath);
51
+ server.ws.on("connection", () => {
52
+ if (overrideMap.size === 0) return;
53
+ for (const filePath of overrideMap.keys()) {
54
+ const mods = server.moduleGraph.getModulesByFile(filePath);
65
55
  if (mods && mods.size > 0) {
66
56
  for (const mod of mods) {
67
57
  server.moduleGraph.invalidateModule(mod);
68
- server.ws.send({
69
- type: "update",
70
- updates: [
71
- {
72
- type: "js-update",
73
- path: mod.url,
74
- acceptedPath: mod.url,
75
- timestamp: Date.now()
76
- }
77
- ]
78
- });
79
58
  }
80
59
  }
81
- res.statusCode = 200;
82
- res.end(JSON.stringify({ success: true }));
83
- } catch (error) {
84
- res.statusCode = 500;
85
- res.end(JSON.stringify({ error: String(error) }));
86
60
  }
61
+ overrideMap.clear();
87
62
  });
88
- server.middlewares.use("/__nocode_file_override_reset", async (req, res, next) => {
63
+ server.middlewares.use("/__nocode_file_override", async (req, res, next) => {
89
64
  if (req.method !== "POST") {
90
65
  return next();
91
66
  }
92
67
  try {
93
- const { file } = await readJsonBody(req);
94
- if (!file) {
68
+ const { file, code } = await readJsonBody(req);
69
+ if (!file || typeof code !== "string") {
95
70
  res.statusCode = 400;
96
- res.end(JSON.stringify({ error: "file is required" }));
71
+ res.end(JSON.stringify({ error: "file and code are required" }));
97
72
  return;
98
73
  }
99
74
  const absolutePath = resolve(server.config.root, file);
100
- const hadOverride = overrideMap.delete(absolutePath);
101
- if (!hadOverride) {
102
- res.statusCode = 200;
103
- res.end(JSON.stringify({ success: true, message: "no override to reset" }));
104
- return;
105
- }
75
+ overrideMap.set(absolutePath, code);
106
76
  const mods = server.moduleGraph.getModulesByFile(absolutePath);
107
77
  if (mods && mods.size > 0) {
108
78
  for (const mod of mods) {
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.4",
3
+ "version": "0.2.4-beta.6",
4
4
  "description": "Vite plugin for nocode compiler",
5
5
  "type": "module",
6
6
  "exports": {