@cequrebackends/plugin-vite 1.0.0-rc.1 → 1.0.1
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.d.ts.map +1 -1
- package/dist/index.js +82 -25
- package/package.json +4 -5
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAiB,MAAM,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAiB,MAAM,MAAM,CAAC;AAalD,MAAM,WAAW,iBAAiB;IAChC,uDAAuD;IACvD,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,8JAA8J;IAC9J,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,0GAA0G;IAC1G,SAAS,CAAC,EAAE,OAAO,CAAC;CACrB;AAOD,wBAAgB,gBAAgB,CAAC,YAAY,CAAC,EAAE,MAAM,GAAG,MAAM,CAsD9D;AAED,wBAAgB,iBAAiB,CAAC,WAAW,CAAC,EAAE,MAAM,GAAG,MAAM,CAuB9D;AAED,wBAAgB,oBAAoB,IAAI;IAAE,OAAO,EAAE,MAAM,CAAC;IAAC,UAAU,EAAE,MAAM,EAAE,CAAA;CAAE,CAMhF;AAsFD,wBAAgB,UAAU,CAAC,OAAO,GAAE,iBAAsB,GAAG,MAAM,CAkMlE;yBAlMe,UAAU;0BA2MkB,sBAAsB;;AAPlE,MAAM,WAAW,sBAAsB;IACrC,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,MAAM,CAAC,EAAE,OAAO,CAAC;CAClB"}
|
package/dist/index.js
CHANGED
|
@@ -6,6 +6,12 @@ import { spawn, execSync } from "child_process";
|
|
|
6
6
|
import path from "path";
|
|
7
7
|
import fs from "fs";
|
|
8
8
|
import os from "os";
|
|
9
|
+
import { createHash } from "crypto";
|
|
10
|
+
var logger = {
|
|
11
|
+
info: (msg) => console.log(msg),
|
|
12
|
+
error: (msg) => console.error(msg),
|
|
13
|
+
warn: (msg) => console.warn(msg)
|
|
14
|
+
};
|
|
9
15
|
var g = globalThis;
|
|
10
16
|
var globalWsPort = g.__CEQURE_WS_PORT || 0;
|
|
11
17
|
var globalCequreProcess = g.__CEQURE_PROCESS || null;
|
|
@@ -63,12 +69,15 @@ function resolveEntryPoint(customEntry) {
|
|
|
63
69
|
return customEntry;
|
|
64
70
|
}
|
|
65
71
|
const candidates = [
|
|
72
|
+
"cequre/index.ts",
|
|
73
|
+
"cequre/app.ts",
|
|
66
74
|
"cequre/server/app.ts",
|
|
67
75
|
"cequre/server/index.ts",
|
|
68
76
|
"src/server/app.ts",
|
|
69
77
|
"src/app.ts",
|
|
70
78
|
"src/server/index.ts",
|
|
71
79
|
"server/index.ts",
|
|
80
|
+
"server.ts",
|
|
72
81
|
"src/index.ts",
|
|
73
82
|
"api/index.ts"
|
|
74
83
|
];
|
|
@@ -77,7 +86,7 @@ function resolveEntryPoint(customEntry) {
|
|
|
77
86
|
return cand;
|
|
78
87
|
}
|
|
79
88
|
}
|
|
80
|
-
return "cequre/
|
|
89
|
+
return "cequre/index.ts";
|
|
81
90
|
}
|
|
82
91
|
function getExecutableCommand() {
|
|
83
92
|
const localBin = path.join(process.cwd(), "node_modules", ".bin", "cequre");
|
|
@@ -86,10 +95,15 @@ function getExecutableCommand() {
|
|
|
86
95
|
}
|
|
87
96
|
return { command: "bunx", argsPrefix: ["cequre"] };
|
|
88
97
|
}
|
|
98
|
+
function lockPathFor(port) {
|
|
99
|
+
const root = path.resolve(process.cwd());
|
|
100
|
+
const digest = createHash("sha256").update(root).digest("hex").slice(0, 12);
|
|
101
|
+
return path.join(os.tmpdir(), `cequre-dev-${digest}-${port}.lock`);
|
|
102
|
+
}
|
|
89
103
|
function tryAcquireLock() {
|
|
90
104
|
if (!globalWsPort)
|
|
91
105
|
return false;
|
|
92
|
-
const lockPath =
|
|
106
|
+
const lockPath = lockPathFor(globalWsPort);
|
|
93
107
|
try {
|
|
94
108
|
const fd = fs.openSync(lockPath, "wx");
|
|
95
109
|
fs.closeSync(fd);
|
|
@@ -103,11 +117,59 @@ function tryAcquireLock() {
|
|
|
103
117
|
function releaseLock() {
|
|
104
118
|
if (!globalWsPort)
|
|
105
119
|
return;
|
|
106
|
-
const lockPath =
|
|
120
|
+
const lockPath = lockPathFor(globalWsPort);
|
|
107
121
|
try {
|
|
108
122
|
fs.unlinkSync(lockPath);
|
|
109
123
|
} catch {}
|
|
110
124
|
}
|
|
125
|
+
function isGeneratedPath(filePath) {
|
|
126
|
+
const normalized = path.normalize(filePath);
|
|
127
|
+
return normalized.split(path.sep).some((part) => part === "_generated" || part === "generated") || normalized.endsWith("schema.json") || normalized.endsWith("cequre-sdk.ts");
|
|
128
|
+
}
|
|
129
|
+
function forwardStderr(stream, onLine) {
|
|
130
|
+
if (!stream)
|
|
131
|
+
return;
|
|
132
|
+
let pending = "";
|
|
133
|
+
stream.on("data", (data) => {
|
|
134
|
+
pending += data.toString();
|
|
135
|
+
const lines = pending.split(/\r?\n/);
|
|
136
|
+
pending = lines.pop() || "";
|
|
137
|
+
for (const line of lines) {
|
|
138
|
+
const trimmed = line.trim();
|
|
139
|
+
if (trimmed)
|
|
140
|
+
onLine(trimmed);
|
|
141
|
+
}
|
|
142
|
+
});
|
|
143
|
+
stream.on("end", () => {
|
|
144
|
+
const trimmed = pending.trim();
|
|
145
|
+
if (trimmed)
|
|
146
|
+
onLine(trimmed);
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
function attachBackendWatch(server, onReload) {
|
|
150
|
+
let reloadTimer;
|
|
151
|
+
let changedFile = "";
|
|
152
|
+
server.watcher.on("change", (filePath) => {
|
|
153
|
+
if (isGeneratedPath(filePath))
|
|
154
|
+
return;
|
|
155
|
+
const normalized = path.resolve(process.cwd(), filePath);
|
|
156
|
+
const relative = path.relative(process.cwd(), normalized);
|
|
157
|
+
const parts = relative.split(path.sep);
|
|
158
|
+
const startsWith = (...prefix) => prefix.every((part, index) => parts[index] === part);
|
|
159
|
+
const isBackendFile = startsWith("cequre") || startsWith("src", "server") || startsWith("src", "routes") || relative === "cequre.config.json" || relative.includes("cequre-generated");
|
|
160
|
+
if (!isBackendFile)
|
|
161
|
+
return;
|
|
162
|
+
changedFile = filePath;
|
|
163
|
+
if (reloadTimer)
|
|
164
|
+
clearTimeout(reloadTimer);
|
|
165
|
+
reloadTimer = setTimeout(() => {
|
|
166
|
+
reloadTimer = undefined;
|
|
167
|
+
const file = changedFile;
|
|
168
|
+
changedFile = "";
|
|
169
|
+
onReload(file);
|
|
170
|
+
}, 100);
|
|
171
|
+
});
|
|
172
|
+
}
|
|
111
173
|
function cequreVite(options = {}) {
|
|
112
174
|
let resolvedApiPrefix = resolveApiPrefix(options.apiPrefix);
|
|
113
175
|
if (!globalCleanupRegistered) {
|
|
@@ -141,7 +203,7 @@ function cequreVite(options = {}) {
|
|
|
141
203
|
const srv = net.createServer();
|
|
142
204
|
srv.unref();
|
|
143
205
|
srv.on("error", reject);
|
|
144
|
-
srv.listen(port,
|
|
206
|
+
srv.listen(port, () => {
|
|
145
207
|
srv.close(resolve);
|
|
146
208
|
});
|
|
147
209
|
});
|
|
@@ -161,6 +223,10 @@ function cequreVite(options = {}) {
|
|
|
161
223
|
},
|
|
162
224
|
server: {
|
|
163
225
|
proxy: {
|
|
226
|
+
"/admin": {
|
|
227
|
+
target: `http://127.0.0.1:${globalWsPort}`,
|
|
228
|
+
changeOrigin: false
|
|
229
|
+
},
|
|
164
230
|
[resolvedApiPrefix]: {
|
|
165
231
|
target: `http://127.0.0.1:${globalWsPort}`,
|
|
166
232
|
changeOrigin: true,
|
|
@@ -213,21 +279,12 @@ function cequreVite(options = {}) {
|
|
|
213
279
|
server.config.logger.info(`[cequre.vite] Attached Cequre API (${resolvedApiPrefix}) to Vite host.`);
|
|
214
280
|
globalCequreProcess = spawn(exec.command, args, {
|
|
215
281
|
cwd: process.cwd(),
|
|
216
|
-
stdio: "pipe",
|
|
282
|
+
stdio: ["ignore", "ignore", "pipe"],
|
|
217
283
|
env: { ...process.env, PORT: String(globalWsPort), HOST: "127.0.0.1", CEQURE_VITE_MODE: "1" }
|
|
218
284
|
});
|
|
219
285
|
g.__CEQURE_PROCESS = globalCequreProcess;
|
|
220
|
-
globalCequreProcess.
|
|
221
|
-
|
|
222
|
-
if (msg && !msg.includes("Starting Bun dev server") && !msg.includes("URL:") && !msg.includes("starting on http") && !msg.includes("started gracefully on port") && !msg.includes(`:${globalWsPort}`)) {
|
|
223
|
-
server.config.logger.info(`[cequre] ${msg}`);
|
|
224
|
-
}
|
|
225
|
-
});
|
|
226
|
-
globalCequreProcess.stderr?.on("data", (data) => {
|
|
227
|
-
const msg = data.toString().trim();
|
|
228
|
-
if (msg) {
|
|
229
|
-
server.config.logger.error(`[cequre] ${msg}`);
|
|
230
|
-
}
|
|
286
|
+
forwardStderr(globalCequreProcess.stderr, (msg) => {
|
|
287
|
+
server.config.logger.error(`[cequre] ${msg}`);
|
|
231
288
|
});
|
|
232
289
|
globalCequreProcess.on("close", (code) => {
|
|
233
290
|
if (code !== 0 && code !== null) {
|
|
@@ -249,16 +306,16 @@ function cequreVite(options = {}) {
|
|
|
249
306
|
if (cequrePaths.length > 0) {
|
|
250
307
|
server.watcher.add(cequrePaths);
|
|
251
308
|
}
|
|
252
|
-
server
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
server.ws.send({ type: "full-reload" });
|
|
256
|
-
}
|
|
309
|
+
attachBackendWatch(server, (filePath) => {
|
|
310
|
+
server.config.logger.info(`[cequre.vite] Backend / SDK updated (${path.basename(filePath)}), triggering Vite HMR reload`);
|
|
311
|
+
server.ws.send({ type: "full-reload" });
|
|
257
312
|
});
|
|
258
313
|
if (server.httpServer?.listening) {
|
|
259
314
|
spawnCequre();
|
|
315
|
+
} else if (server.httpServer?.once) {
|
|
316
|
+
server.httpServer.once("listening", spawnCequre);
|
|
260
317
|
} else {
|
|
261
|
-
server.httpServer?.
|
|
318
|
+
server.httpServer?.on?.("listening", spawnCequre);
|
|
262
319
|
}
|
|
263
320
|
},
|
|
264
321
|
async closeBundle() {
|
|
@@ -273,7 +330,7 @@ cequreVite.build = async function(options = {}) {
|
|
|
273
330
|
const entry = resolveEntryPoint(options.entry);
|
|
274
331
|
const outDir = options.outDir || "build/server";
|
|
275
332
|
const minify = options.minify !== false;
|
|
276
|
-
|
|
333
|
+
logger.info(`[cequre.vite] Starting production build...`);
|
|
277
334
|
const absEntry = path.resolve(process.cwd(), entry);
|
|
278
335
|
if (!fs.existsSync(absEntry)) {
|
|
279
336
|
throw new Error(`[cequre.vite] Entry point not found: ${absEntry}`);
|
|
@@ -291,7 +348,7 @@ cequreVite.build = async function(options = {}) {
|
|
|
291
348
|
if (!fs.existsSync(buildOutDir)) {
|
|
292
349
|
fs.mkdirSync(buildOutDir, { recursive: true });
|
|
293
350
|
}
|
|
294
|
-
|
|
351
|
+
logger.info(`[cequre.vite] Bundling Cequre API with Bun...`);
|
|
295
352
|
const targetOutputPath = path.join(buildOutDir, naming);
|
|
296
353
|
if (typeof Bun !== "undefined") {
|
|
297
354
|
const buildResult = await Bun.build({
|
|
@@ -323,7 +380,7 @@ ${errorDetails}`);
|
|
|
323
380
|
const entryBasename = path.basename(absEntry, path.extname(absEntry)) + ".js";
|
|
324
381
|
const entryFallbackPath = path.join(buildOutDir, entryBasename);
|
|
325
382
|
const actualPath = fs.existsSync(targetOutputPath) ? targetOutputPath : fs.existsSync(entryFallbackPath) ? entryFallbackPath : targetOutputPath;
|
|
326
|
-
|
|
383
|
+
logger.info(`[cequre.vite] API bundled successfully to: ${actualPath}`);
|
|
327
384
|
if (!fs.existsSync(actualPath)) {
|
|
328
385
|
throw new Error(`[cequre.vite] Build reported success but output not found: ${actualPath}`);
|
|
329
386
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cequrebackends/plugin-vite",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.1",
|
|
4
|
+
"license": "BSL-1.0",
|
|
4
5
|
"type": "module",
|
|
5
6
|
"main": "./dist/index.js",
|
|
6
7
|
"module": "./dist/index.js",
|
|
@@ -13,15 +14,13 @@
|
|
|
13
14
|
"dev": "bun build ./src/index.ts --outdir ./dist --target bun --packages external --watch"
|
|
14
15
|
},
|
|
15
16
|
"peerDependencies": {
|
|
16
|
-
"vite": "8.
|
|
17
|
-
"@cequrebackends/cequre-ts": "^0.13.0"
|
|
17
|
+
"vite": "^8.0.0"
|
|
18
18
|
},
|
|
19
19
|
"devDependencies": {
|
|
20
20
|
"typescript": "^7.0.2",
|
|
21
21
|
"vite": "^8.1.5",
|
|
22
22
|
"@types/node": "^26.1.1",
|
|
23
|
-
"@types/bun": "latest"
|
|
24
|
-
"@cequrebackends/cequre-ts": "^0.13.0"
|
|
23
|
+
"@types/bun": "latest"
|
|
25
24
|
},
|
|
26
25
|
"sideEffects": false,
|
|
27
26
|
"exports": {
|