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