@cequrebackends/plugin-vite 0.13.0
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/README.md +63 -0
- package/dist/index.d.ts +26 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +316 -0
- package/package.json +42 -0
package/README.md
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
# @cequrebackends/plugin-vite
|
|
2
|
+
|
|
3
|
+
Vite dev server integration plugin for Cequre backends. Bridge your Cequre backend and Vite frontend into a single seamless dev server on the same port.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
bun add @cequrebackends/plugin-vite
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Usage
|
|
12
|
+
|
|
13
|
+
### Zero Config (Dev Mode)
|
|
14
|
+
|
|
15
|
+
```typescript
|
|
16
|
+
// vite.config.ts
|
|
17
|
+
import { defineConfig } from "vite";
|
|
18
|
+
import react from "@vitejs/plugin-react";
|
|
19
|
+
import { cequreVite } from "@cequrebackends/plugin-vite";
|
|
20
|
+
|
|
21
|
+
export default defineConfig({
|
|
22
|
+
plugins: [
|
|
23
|
+
react(),
|
|
24
|
+
cequreVite()
|
|
25
|
+
]
|
|
26
|
+
});
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
### Full-Stack Build (`autoBuild: true`)
|
|
30
|
+
|
|
31
|
+
```typescript
|
|
32
|
+
// vite.config.ts
|
|
33
|
+
import { defineConfig } from "vite";
|
|
34
|
+
import react from "@vitejs/plugin-react";
|
|
35
|
+
import { cequreVite } from "@cequrebackends/plugin-vite";
|
|
36
|
+
|
|
37
|
+
export default defineConfig({
|
|
38
|
+
plugins: [
|
|
39
|
+
react(),
|
|
40
|
+
cequreVite({
|
|
41
|
+
autoBuild: true // Bundles Cequre backend into build/server/server.js on `vite build`
|
|
42
|
+
})
|
|
43
|
+
]
|
|
44
|
+
});
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
## Features
|
|
48
|
+
|
|
49
|
+
- **Single-Port Parity**: Proxies HTTP and WebSockets (`ws: true`) from Vite to Cequre automatically under `/api`.
|
|
50
|
+
- **Fast Execution**: Probes local `node_modules/.bin/cequre` to bypass `bunx` startup latency.
|
|
51
|
+
- **Auto Entry Detection**: Finds your Cequre backend entry point automatically.
|
|
52
|
+
- **SDK Watcher**: Triggers Vite HMR reloads automatically when Cequre generates updated `client.ts` / SDK files.
|
|
53
|
+
- **Unified Build**: Set `autoBuild: true` to bundle backend server output automatically during `vite build`.
|
|
54
|
+
|
|
55
|
+
## WebSocket & SSE Support
|
|
56
|
+
|
|
57
|
+
WebSocket proxying is enabled **automatically by default under the hood**. No configuration options are needed in `cequreVite()`. In your frontend, connect directly using relative URLs over Vite's dev port:
|
|
58
|
+
|
|
59
|
+
```typescript
|
|
60
|
+
const protocol = window.location.protocol === "https:" ? "wss:" : "ws:";
|
|
61
|
+
const socket = new WebSocket(`${protocol}//${window.location.host}/api/ws`);
|
|
62
|
+
```
|
|
63
|
+
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { Plugin } from "vite";
|
|
2
|
+
export interface CequreViteOptions {
|
|
3
|
+
/** URL prefix for API routes. Defaults to `"/api"`. */
|
|
4
|
+
apiPrefix?: string;
|
|
5
|
+
/** Custom entry point for the Cequre server. Defaults to auto-detecting `src/server/index.ts`, `server/index.ts`, `src/index.ts`, or `api/index.ts`. */
|
|
6
|
+
entry?: string;
|
|
7
|
+
/** Automatically run backend production build during Vite build closeBundle hook. Defaults to `false`. */
|
|
8
|
+
autoBuild?: boolean;
|
|
9
|
+
}
|
|
10
|
+
export declare function resolveApiPrefix(customPrefix?: string): string;
|
|
11
|
+
export declare function resolveEntryPoint(customEntry?: string): string;
|
|
12
|
+
export declare function getExecutableCommand(): {
|
|
13
|
+
command: string;
|
|
14
|
+
argsPrefix: string[];
|
|
15
|
+
};
|
|
16
|
+
export declare function cequreVite(options?: CequreViteOptions): Plugin;
|
|
17
|
+
export declare namespace cequreVite {
|
|
18
|
+
var build: (options?: CequreViteBuildOptions) => Promise<void>;
|
|
19
|
+
}
|
|
20
|
+
export interface CequreViteBuildOptions {
|
|
21
|
+
entry?: string;
|
|
22
|
+
outDir?: string;
|
|
23
|
+
outFile?: string;
|
|
24
|
+
minify?: boolean;
|
|
25
|
+
}
|
|
26
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAiB,MAAM,MAAM,CAAC;AAMlD,MAAM,WAAW,iBAAiB;IAChC,uDAAuD;IACvD,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,wJAAwJ;IACxJ,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,0GAA0G;IAC1G,SAAS,CAAC,EAAE,OAAO,CAAC;CACrB;AAOD,wBAAgB,gBAAgB,CAAC,YAAY,CAAC,EAAE,MAAM,GAAG,MAAM,CAoC9D;AAED,wBAAgB,iBAAiB,CAAC,WAAW,CAAC,EAAE,MAAM,GAAG,MAAM,CAkB9D;AAED,wBAAgB,oBAAoB,IAAI;IAAE,OAAO,EAAE,MAAM,CAAC;IAAC,UAAU,EAAE,MAAM,EAAE,CAAA;CAAE,CAMhF;AAqBD,wBAAgB,UAAU,CAAC,OAAO,GAAE,iBAAsB,GAAG,MAAM,CAmMlE;yBAnMe,UAAU;0BA4MkB,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
ADDED
|
@@ -0,0 +1,316 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
var __require = import.meta.require;
|
|
3
|
+
|
|
4
|
+
// src/index.ts
|
|
5
|
+
import { spawn, execSync } from "child_process";
|
|
6
|
+
import path from "path";
|
|
7
|
+
import fs from "fs";
|
|
8
|
+
import os from "os";
|
|
9
|
+
var g = globalThis;
|
|
10
|
+
var globalWsPort = g.__CEQURE_WS_PORT || 0;
|
|
11
|
+
var globalCequreProcess = g.__CEQURE_PROCESS || null;
|
|
12
|
+
var globalCleanupRegistered = g.__CEQURE_CLEANUP || false;
|
|
13
|
+
function resolveApiPrefix(customPrefix) {
|
|
14
|
+
if (customPrefix) {
|
|
15
|
+
return customPrefix.startsWith("/") ? customPrefix : "/" + customPrefix;
|
|
16
|
+
}
|
|
17
|
+
const schemaPath = path.resolve(process.cwd(), "node_modules", ".cequre", "schema.json");
|
|
18
|
+
if (fs.existsSync(schemaPath)) {
|
|
19
|
+
try {
|
|
20
|
+
const schema = JSON.parse(fs.readFileSync(schemaPath, "utf-8"));
|
|
21
|
+
if (schema.core?.api?.prefix) {
|
|
22
|
+
const prefix = schema.core.api.prefix;
|
|
23
|
+
return prefix.startsWith("/") ? prefix : "/" + prefix;
|
|
24
|
+
}
|
|
25
|
+
} catch {}
|
|
26
|
+
}
|
|
27
|
+
const cequreDir = path.resolve(process.cwd(), "cequre");
|
|
28
|
+
if (fs.existsSync(cequreDir)) {
|
|
29
|
+
try {
|
|
30
|
+
const files = fs.readdirSync(cequreDir);
|
|
31
|
+
for (const f of files) {
|
|
32
|
+
if (f.endsWith(".cequre")) {
|
|
33
|
+
const content = fs.readFileSync(path.join(cequreDir, f), "utf-8");
|
|
34
|
+
const match = content.match(/prefix:\s*["']([^"']+)["']/);
|
|
35
|
+
if (match && match[1]) {
|
|
36
|
+
const prefix = match[1];
|
|
37
|
+
return prefix.startsWith("/") ? prefix : "/" + prefix;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
} catch {}
|
|
42
|
+
}
|
|
43
|
+
return "/api";
|
|
44
|
+
}
|
|
45
|
+
function resolveEntryPoint(customEntry) {
|
|
46
|
+
if (customEntry) {
|
|
47
|
+
return customEntry;
|
|
48
|
+
}
|
|
49
|
+
const candidates = [
|
|
50
|
+
"src/server/app.ts",
|
|
51
|
+
"src/app.ts",
|
|
52
|
+
"src/server/index.ts",
|
|
53
|
+
"server/index.ts",
|
|
54
|
+
"src/index.ts",
|
|
55
|
+
"api/index.ts"
|
|
56
|
+
];
|
|
57
|
+
for (const cand of candidates) {
|
|
58
|
+
if (fs.existsSync(path.resolve(process.cwd(), cand))) {
|
|
59
|
+
return cand;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
return "src/index.ts";
|
|
63
|
+
}
|
|
64
|
+
function getExecutableCommand() {
|
|
65
|
+
const localBin = path.join(process.cwd(), "node_modules", ".bin", "cequre");
|
|
66
|
+
if (fs.existsSync(localBin)) {
|
|
67
|
+
return { command: localBin, argsPrefix: [] };
|
|
68
|
+
}
|
|
69
|
+
return { command: "bunx", argsPrefix: ["cequre"] };
|
|
70
|
+
}
|
|
71
|
+
function tryAcquireLock() {
|
|
72
|
+
if (!globalWsPort)
|
|
73
|
+
return false;
|
|
74
|
+
const lockPath = path.join(os.tmpdir(), `cequre-dev-${globalWsPort}.lock`);
|
|
75
|
+
try {
|
|
76
|
+
const fd = fs.openSync(lockPath, "wx");
|
|
77
|
+
fs.closeSync(fd);
|
|
78
|
+
return true;
|
|
79
|
+
} catch (e) {
|
|
80
|
+
if (e.code === "EEXIST")
|
|
81
|
+
return false;
|
|
82
|
+
throw e;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
function releaseLock() {
|
|
86
|
+
if (!globalWsPort)
|
|
87
|
+
return;
|
|
88
|
+
const lockPath = path.join(os.tmpdir(), `cequre-dev-${globalWsPort}.lock`);
|
|
89
|
+
try {
|
|
90
|
+
fs.unlinkSync(lockPath);
|
|
91
|
+
} catch {}
|
|
92
|
+
}
|
|
93
|
+
function cequreVite(options = {}) {
|
|
94
|
+
let resolvedApiPrefix = resolveApiPrefix(options.apiPrefix);
|
|
95
|
+
if (!globalCleanupRegistered) {
|
|
96
|
+
globalCleanupRegistered = true;
|
|
97
|
+
g.__CEQURE_CLEANUP = true;
|
|
98
|
+
const cleanup = () => {
|
|
99
|
+
if (globalCequreProcess) {
|
|
100
|
+
globalCequreProcess.kill("SIGTERM");
|
|
101
|
+
globalCequreProcess = null;
|
|
102
|
+
g.__CEQURE_PROCESS = null;
|
|
103
|
+
}
|
|
104
|
+
releaseLock();
|
|
105
|
+
};
|
|
106
|
+
process.on("beforeExit", cleanup);
|
|
107
|
+
process.on("exit", cleanup);
|
|
108
|
+
}
|
|
109
|
+
return {
|
|
110
|
+
name: "cequre-vite-plugin",
|
|
111
|
+
async config(config, env) {
|
|
112
|
+
if (env.command === "serve") {
|
|
113
|
+
resolvedApiPrefix = resolveApiPrefix(options.apiPrefix);
|
|
114
|
+
const envPort = process.env.CEQURE_DEV_PORT;
|
|
115
|
+
if (envPort) {
|
|
116
|
+
globalWsPort = parseInt(envPort, 10);
|
|
117
|
+
g.__CEQURE_WS_PORT = globalWsPort;
|
|
118
|
+
} else if (!globalWsPort) {
|
|
119
|
+
const net = await import("net");
|
|
120
|
+
for (let port = 3001;port < 3100; port++) {
|
|
121
|
+
try {
|
|
122
|
+
await new Promise((resolve, reject) => {
|
|
123
|
+
const srv = net.createServer();
|
|
124
|
+
srv.unref();
|
|
125
|
+
srv.on("error", reject);
|
|
126
|
+
srv.listen(port, "127.0.0.1", () => {
|
|
127
|
+
srv.close(resolve);
|
|
128
|
+
});
|
|
129
|
+
});
|
|
130
|
+
globalWsPort = port;
|
|
131
|
+
g.__CEQURE_WS_PORT = port;
|
|
132
|
+
releaseLock();
|
|
133
|
+
break;
|
|
134
|
+
} catch (e) {}
|
|
135
|
+
}
|
|
136
|
+
if (!globalWsPort) {
|
|
137
|
+
throw new Error("[cequre.vite] No available port found in range 3001-3099. Set CEQURE_DEV_PORT env var or free a port in this range.");
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
const viteConfig = {
|
|
141
|
+
define: {
|
|
142
|
+
__CEQURE_DEV_WS_URL__: JSON.stringify(`ws://127.0.0.1:${globalWsPort}`)
|
|
143
|
+
},
|
|
144
|
+
server: {
|
|
145
|
+
proxy: {
|
|
146
|
+
[resolvedApiPrefix]: {
|
|
147
|
+
target: `http://127.0.0.1:${globalWsPort}`,
|
|
148
|
+
changeOrigin: true,
|
|
149
|
+
ws: true,
|
|
150
|
+
configure: (proxy, _options) => {
|
|
151
|
+
proxy.on("proxyReq", (proxyReq, req) => {
|
|
152
|
+
if (req && req.headers && req.headers.host) {
|
|
153
|
+
proxyReq.setHeader("x-forwarded-host", req.headers.host);
|
|
154
|
+
proxyReq.setHeader("x-forwarded-proto", req.socket?.encrypted ? "https" : "http");
|
|
155
|
+
}
|
|
156
|
+
});
|
|
157
|
+
const originalEmit = proxy.emit.bind(proxy);
|
|
158
|
+
proxy.emit = function(event, ...args) {
|
|
159
|
+
if (event === "error" && args[0] && args[0].code === "ECONNREFUSED") {
|
|
160
|
+
const res = args[2];
|
|
161
|
+
if (res && !res.headersSent && typeof res.writeHead === "function") {
|
|
162
|
+
res.writeHead(503, {
|
|
163
|
+
"Content-Type": "application/json",
|
|
164
|
+
"Retry-After": "1"
|
|
165
|
+
});
|
|
166
|
+
res.end(JSON.stringify({ error: "Cequre backend restarting", code: "ECONNREFUSED_CEQURE" }));
|
|
167
|
+
}
|
|
168
|
+
return false;
|
|
169
|
+
}
|
|
170
|
+
return originalEmit(event, ...args);
|
|
171
|
+
};
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
};
|
|
177
|
+
return viteConfig;
|
|
178
|
+
}
|
|
179
|
+
return {};
|
|
180
|
+
},
|
|
181
|
+
async configureServer(server) {
|
|
182
|
+
const envName = server.environment?.name ?? server.config?.environments?.client?.name ?? "";
|
|
183
|
+
if (envName && envName !== "client")
|
|
184
|
+
return;
|
|
185
|
+
const spawnCequre = () => {
|
|
186
|
+
if (globalCequreProcess || !tryAcquireLock()) {
|
|
187
|
+
return;
|
|
188
|
+
}
|
|
189
|
+
const resolvedEntry = resolveEntryPoint(options.entry);
|
|
190
|
+
const exec = getExecutableCommand();
|
|
191
|
+
const args = [...exec.argsPrefix, "dev"];
|
|
192
|
+
if (resolvedEntry) {
|
|
193
|
+
args.push("--entry", resolvedEntry);
|
|
194
|
+
}
|
|
195
|
+
server.config.logger.info(`[cequre.vite] Attached Cequre API (${resolvedApiPrefix}) to Vite host.`);
|
|
196
|
+
globalCequreProcess = spawn(exec.command, args, {
|
|
197
|
+
cwd: process.cwd(),
|
|
198
|
+
stdio: "pipe",
|
|
199
|
+
env: { ...process.env, PORT: String(globalWsPort), HOST: "127.0.0.1", CEQURE_VITE_MODE: "1" }
|
|
200
|
+
});
|
|
201
|
+
g.__CEQURE_PROCESS = globalCequreProcess;
|
|
202
|
+
globalCequreProcess.stdout?.on("data", (data) => {
|
|
203
|
+
const msg = data.toString().trim();
|
|
204
|
+
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}`)) {
|
|
205
|
+
server.config.logger.info(`[cequre] ${msg}`);
|
|
206
|
+
}
|
|
207
|
+
});
|
|
208
|
+
globalCequreProcess.stderr?.on("data", (data) => {
|
|
209
|
+
const msg = data.toString().trim();
|
|
210
|
+
if (msg) {
|
|
211
|
+
server.config.logger.error(`[cequre] ${msg}`);
|
|
212
|
+
}
|
|
213
|
+
});
|
|
214
|
+
globalCequreProcess.on("close", (code) => {
|
|
215
|
+
if (code !== 0 && code !== null) {
|
|
216
|
+
server.config.logger.error(`[cequre.vite] Cequre binary exited with code ${code}`);
|
|
217
|
+
}
|
|
218
|
+
globalCequreProcess = null;
|
|
219
|
+
g.__CEQURE_PROCESS = null;
|
|
220
|
+
releaseLock();
|
|
221
|
+
});
|
|
222
|
+
};
|
|
223
|
+
const cequrePaths = [
|
|
224
|
+
path.resolve(process.cwd(), "cequre"),
|
|
225
|
+
path.resolve(process.cwd(), "src/server"),
|
|
226
|
+
path.resolve(process.cwd(), "src/routes"),
|
|
227
|
+
path.resolve(process.cwd(), "cequre.config.json")
|
|
228
|
+
].filter((p) => fs.existsSync(p));
|
|
229
|
+
if (cequrePaths.length > 0) {
|
|
230
|
+
server.watcher.add(cequrePaths);
|
|
231
|
+
}
|
|
232
|
+
server.watcher.on("change", (filePath) => {
|
|
233
|
+
if (filePath.endsWith("client.ts") || filePath.endsWith("sdk.ts") || filePath.includes("cequre-generated") || filePath.includes("cequre") || filePath.includes("server") || filePath.includes("routes")) {
|
|
234
|
+
server.config.logger.info(`[cequre.vite] Backend / SDK updated (${path.basename(filePath)}), triggering Vite HMR reload`);
|
|
235
|
+
server.ws.send({ type: "full-reload" });
|
|
236
|
+
}
|
|
237
|
+
});
|
|
238
|
+
if (server.httpServer?.listening) {
|
|
239
|
+
spawnCequre();
|
|
240
|
+
} else {
|
|
241
|
+
server.httpServer?.once("listening", spawnCequre);
|
|
242
|
+
}
|
|
243
|
+
},
|
|
244
|
+
async closeBundle() {
|
|
245
|
+
if (options.autoBuild) {
|
|
246
|
+
const resolvedEntry = resolveEntryPoint(options.entry);
|
|
247
|
+
await cequreVite.build({ entry: resolvedEntry });
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
};
|
|
251
|
+
}
|
|
252
|
+
cequreVite.build = async function(options = {}) {
|
|
253
|
+
const entry = resolveEntryPoint(options.entry);
|
|
254
|
+
const outDir = options.outDir || "build/server";
|
|
255
|
+
const minify = options.minify !== false;
|
|
256
|
+
console.log(`[cequre.vite] Starting production build...`);
|
|
257
|
+
const absEntry = path.resolve(process.cwd(), entry);
|
|
258
|
+
if (!fs.existsSync(absEntry)) {
|
|
259
|
+
throw new Error(`[cequre.vite] Entry point not found: ${absEntry}`);
|
|
260
|
+
}
|
|
261
|
+
let buildOutDir;
|
|
262
|
+
let naming;
|
|
263
|
+
if (options.outFile) {
|
|
264
|
+
const absOutFile = path.resolve(process.cwd(), options.outFile);
|
|
265
|
+
buildOutDir = path.dirname(absOutFile);
|
|
266
|
+
naming = path.basename(absOutFile);
|
|
267
|
+
} else {
|
|
268
|
+
buildOutDir = path.resolve(process.cwd(), outDir);
|
|
269
|
+
naming = "server.js";
|
|
270
|
+
}
|
|
271
|
+
if (!fs.existsSync(buildOutDir)) {
|
|
272
|
+
fs.mkdirSync(buildOutDir, { recursive: true });
|
|
273
|
+
}
|
|
274
|
+
console.log(`[cequre.vite] Bundling Cequre API with Bun...`);
|
|
275
|
+
const targetOutputPath = path.join(buildOutDir, naming);
|
|
276
|
+
if (typeof Bun !== "undefined") {
|
|
277
|
+
const buildResult = await Bun.build({
|
|
278
|
+
entrypoints: [absEntry],
|
|
279
|
+
outdir: buildOutDir,
|
|
280
|
+
naming,
|
|
281
|
+
target: "bun",
|
|
282
|
+
minify
|
|
283
|
+
});
|
|
284
|
+
if (!buildResult.success) {
|
|
285
|
+
const errorDetails = buildResult.logs.map((log) => typeof log === "string" ? log : `${log.message ?? ""} (${log.position?.file ?? "?"}:${log.position?.line ?? "?"})`).join(`
|
|
286
|
+
`);
|
|
287
|
+
throw new Error(`[cequre.vite] Bun.build failed:
|
|
288
|
+
${errorDetails}`);
|
|
289
|
+
}
|
|
290
|
+
} else {
|
|
291
|
+
const localBin = path.join(process.cwd(), "node_modules", ".bin", "bun");
|
|
292
|
+
const bunCmd = fs.existsSync(localBin) ? localBin : "bun";
|
|
293
|
+
const minifyFlag = minify ? " --minify" : "";
|
|
294
|
+
try {
|
|
295
|
+
execSync(`${bunCmd} build "${absEntry}" --outfile "${targetOutputPath}" --target bun${minifyFlag}`, {
|
|
296
|
+
stdio: "inherit",
|
|
297
|
+
env: process.env
|
|
298
|
+
});
|
|
299
|
+
} catch (err) {
|
|
300
|
+
throw new Error(`[cequre.vite] Bundling Cequre API failed using '${bunCmd}'. Ensure Bun is installed on your system or run builds using Bun ('bun run build'). Error: ${err.message}`);
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
const entryBasename = path.basename(absEntry, path.extname(absEntry)) + ".js";
|
|
304
|
+
const entryFallbackPath = path.join(buildOutDir, entryBasename);
|
|
305
|
+
const actualPath = fs.existsSync(targetOutputPath) ? targetOutputPath : fs.existsSync(entryFallbackPath) ? entryFallbackPath : targetOutputPath;
|
|
306
|
+
console.log(`[cequre.vite] API bundled successfully to: ${actualPath}`);
|
|
307
|
+
if (!fs.existsSync(actualPath)) {
|
|
308
|
+
throw new Error(`[cequre.vite] Build reported success but output not found: ${actualPath}`);
|
|
309
|
+
}
|
|
310
|
+
};
|
|
311
|
+
export {
|
|
312
|
+
resolveEntryPoint,
|
|
313
|
+
resolveApiPrefix,
|
|
314
|
+
getExecutableCommand,
|
|
315
|
+
cequreVite
|
|
316
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@cequrebackends/plugin-vite",
|
|
3
|
+
"version": "0.13.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"main": "./dist/index.js",
|
|
6
|
+
"module": "./dist/index.js",
|
|
7
|
+
"types": "./dist/index.d.ts",
|
|
8
|
+
"files": [
|
|
9
|
+
"dist"
|
|
10
|
+
],
|
|
11
|
+
"scripts": {
|
|
12
|
+
"build": "rm -rf dist && bun build ./src/index.ts --outdir ./dist --target bun --packages external && tsc --emitDeclarationOnly",
|
|
13
|
+
"dev": "bun build ./src/index.ts --outdir ./dist --target bun --packages external --watch"
|
|
14
|
+
},
|
|
15
|
+
"peerDependencies": {
|
|
16
|
+
"vite": "8.1.5",
|
|
17
|
+
"@cequrebackends/cequre-ts": "^0.13.0"
|
|
18
|
+
},
|
|
19
|
+
"devDependencies": {
|
|
20
|
+
"typescript": "^7.0.2",
|
|
21
|
+
"vite": "^8.1.5",
|
|
22
|
+
"@types/node": "^26.1.1",
|
|
23
|
+
"@types/bun": "latest",
|
|
24
|
+
"@cequrebackends/cequre-ts": "^0.13.0"
|
|
25
|
+
},
|
|
26
|
+
"sideEffects": false,
|
|
27
|
+
"exports": {
|
|
28
|
+
".": {
|
|
29
|
+
"types": "./dist/index.d.ts",
|
|
30
|
+
"import": "./dist/index.js",
|
|
31
|
+
"default": "./dist/index.js"
|
|
32
|
+
}
|
|
33
|
+
},
|
|
34
|
+
"publishConfig": {
|
|
35
|
+
"access": "public",
|
|
36
|
+
"registry": "https://registry.npmjs.org/"
|
|
37
|
+
},
|
|
38
|
+
"repository": {
|
|
39
|
+
"type": "git",
|
|
40
|
+
"url": "git+https://github.com/cequrebackends/cequre.git"
|
|
41
|
+
}
|
|
42
|
+
}
|