vite-plugin-surrealkit 0.1.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 +59 -0
- package/dist/index.cjs +259 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +31 -0
- package/dist/index.d.ts +31 -0
- package/dist/index.js +226 -0
- package/dist/index.js.map +1 -0
- package/package.json +48 -0
package/README.md
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
# vite-plugin-surrealkit
|
|
2
|
+
|
|
3
|
+
Run `surrealkit sync` from Vite so you do not need a separate `surrealkit sync --watch` process.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```sh
|
|
8
|
+
npm i -D vite-plugin-surrealkit
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Usage
|
|
12
|
+
|
|
13
|
+
```ts
|
|
14
|
+
// vite.config.ts
|
|
15
|
+
import { defineConfig } from 'vite';
|
|
16
|
+
import { surrealkitPlugin } from 'vite-plugin-surrealkit';
|
|
17
|
+
|
|
18
|
+
export default defineConfig({
|
|
19
|
+
plugins: [
|
|
20
|
+
surrealkitPlugin({
|
|
21
|
+
// Optional: pass flags to `surrealkit sync`
|
|
22
|
+
syncArgs: ['--allow-shared-prune'],
|
|
23
|
+
}),
|
|
24
|
+
],
|
|
25
|
+
});
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
Default behavior:
|
|
29
|
+
|
|
30
|
+
- Runs `surrealkit sync` on dev server startup
|
|
31
|
+
- Watches `database/schema/**/*.surql`
|
|
32
|
+
- Runs `surrealkit sync` again whenever those files are added/changed/removed
|
|
33
|
+
- Debounces and queues runs to avoid overlapping processes
|
|
34
|
+
|
|
35
|
+
## Options
|
|
36
|
+
|
|
37
|
+
```ts
|
|
38
|
+
type RunMode = 'serve' | 'build';
|
|
39
|
+
type LogLevel = 'silent' | 'error' | 'info' | 'debug';
|
|
40
|
+
|
|
41
|
+
interface SurrealkitPluginOptions {
|
|
42
|
+
binary?: string;
|
|
43
|
+
cwd?: string;
|
|
44
|
+
env?: Record<string, string>;
|
|
45
|
+
syncArgs?: string[];
|
|
46
|
+
schemaGlobs?: string[];
|
|
47
|
+
include?: RunMode[];
|
|
48
|
+
runOnStartup?: boolean;
|
|
49
|
+
reloadOnSync?: boolean;
|
|
50
|
+
debounceMs?: number;
|
|
51
|
+
logLevel?: LogLevel;
|
|
52
|
+
failBuildOnError?: boolean;
|
|
53
|
+
}
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
## Vite Compatibility
|
|
57
|
+
|
|
58
|
+
- Vite `^7.0.0`
|
|
59
|
+
- Vite `^8.0.0` (peer range included for forward compatibility)
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,259 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
|
|
30
|
+
// src/index.ts
|
|
31
|
+
var index_exports = {};
|
|
32
|
+
__export(index_exports, {
|
|
33
|
+
default: () => index_default,
|
|
34
|
+
surrealkitPlugin: () => surrealkitPlugin
|
|
35
|
+
});
|
|
36
|
+
module.exports = __toCommonJS(index_exports);
|
|
37
|
+
var import_node_child_process = require("child_process");
|
|
38
|
+
var import_node_path = __toESM(require("path"), 1);
|
|
39
|
+
var import_picomatch = __toESM(require("picomatch"), 1);
|
|
40
|
+
var import_vite = require("vite");
|
|
41
|
+
var DEFAULT_SCHEMA_GLOBS = ["database/schema/**/*.surql"];
|
|
42
|
+
function resolveOptions(options) {
|
|
43
|
+
return {
|
|
44
|
+
binary: options.binary ?? "surrealkit",
|
|
45
|
+
cwd: options.cwd,
|
|
46
|
+
env: options.env,
|
|
47
|
+
syncArgs: options.syncArgs ?? [],
|
|
48
|
+
schemaGlobs: options.schemaGlobs ?? DEFAULT_SCHEMA_GLOBS,
|
|
49
|
+
include: new Set(options.include ?? ["serve"]),
|
|
50
|
+
runOnStartup: options.runOnStartup ?? true,
|
|
51
|
+
reloadOnSync: options.reloadOnSync ?? false,
|
|
52
|
+
debounceMs: options.debounceMs ?? 150,
|
|
53
|
+
logLevel: options.logLevel ?? "info",
|
|
54
|
+
failBuildOnError: options.failBuildOnError ?? true
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
function truncateOutput(value, maxChars = 4e3) {
|
|
58
|
+
if (value.length <= maxChars) {
|
|
59
|
+
return value;
|
|
60
|
+
}
|
|
61
|
+
const sliced = value.slice(value.length - maxChars);
|
|
62
|
+
return `...${sliced}`;
|
|
63
|
+
}
|
|
64
|
+
function runSyncCommand(options, root, onDebugLine) {
|
|
65
|
+
return new Promise((resolve, reject) => {
|
|
66
|
+
const commandArgs = ["sync", ...options.syncArgs];
|
|
67
|
+
const child = (0, import_node_child_process.spawn)(options.binary, commandArgs, {
|
|
68
|
+
cwd: options.cwd ?? root,
|
|
69
|
+
env: {
|
|
70
|
+
...process.env,
|
|
71
|
+
...options.env
|
|
72
|
+
},
|
|
73
|
+
shell: process.platform === "win32",
|
|
74
|
+
stdio: ["ignore", "pipe", "pipe"]
|
|
75
|
+
});
|
|
76
|
+
let output = "";
|
|
77
|
+
const consume = (chunk) => {
|
|
78
|
+
output += chunk;
|
|
79
|
+
if (!onDebugLine) {
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
const lines = chunk.split("\n").map((line) => line.trimEnd()).filter(Boolean);
|
|
83
|
+
for (const line of lines) {
|
|
84
|
+
onDebugLine(line);
|
|
85
|
+
}
|
|
86
|
+
};
|
|
87
|
+
child.stdout?.setEncoding("utf8");
|
|
88
|
+
child.stderr?.setEncoding("utf8");
|
|
89
|
+
child.stdout?.on("data", consume);
|
|
90
|
+
child.stderr?.on("data", consume);
|
|
91
|
+
child.on("error", reject);
|
|
92
|
+
child.on("close", (code, signal) => {
|
|
93
|
+
resolve({
|
|
94
|
+
code,
|
|
95
|
+
signal,
|
|
96
|
+
output: truncateOutput(output.trim())
|
|
97
|
+
});
|
|
98
|
+
});
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
function createMatcher(root, globs) {
|
|
102
|
+
const matchers = globs.map((glob) => (0, import_picomatch.default)(glob));
|
|
103
|
+
return (filePath) => {
|
|
104
|
+
const rel = (0, import_vite.normalizePath)(import_node_path.default.relative(root, filePath));
|
|
105
|
+
return matchers.some((matcher) => matcher(rel));
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
function surrealkitPlugin(rawOptions = {}) {
|
|
109
|
+
const options = resolveOptions(rawOptions);
|
|
110
|
+
let config;
|
|
111
|
+
let server;
|
|
112
|
+
let matchesSchemaFile;
|
|
113
|
+
let queued = false;
|
|
114
|
+
let queuedReason;
|
|
115
|
+
let running = false;
|
|
116
|
+
let timer;
|
|
117
|
+
const log = {
|
|
118
|
+
error: (message) => {
|
|
119
|
+
if (options.logLevel === "silent") {
|
|
120
|
+
return;
|
|
121
|
+
}
|
|
122
|
+
(config?.logger ?? console).error(`[vite-plugin-surrealkit] ${message}`);
|
|
123
|
+
},
|
|
124
|
+
info: (message) => {
|
|
125
|
+
if (options.logLevel === "silent" || options.logLevel === "error") {
|
|
126
|
+
return;
|
|
127
|
+
}
|
|
128
|
+
(config?.logger ?? console).info(`[vite-plugin-surrealkit] ${message}`);
|
|
129
|
+
},
|
|
130
|
+
debug: (message) => {
|
|
131
|
+
if (options.logLevel !== "debug") {
|
|
132
|
+
return;
|
|
133
|
+
}
|
|
134
|
+
(config?.logger ?? console).info(`[vite-plugin-surrealkit] ${message}`);
|
|
135
|
+
}
|
|
136
|
+
};
|
|
137
|
+
const runSync = async (reason) => {
|
|
138
|
+
if (!config) return;
|
|
139
|
+
if (running) {
|
|
140
|
+
queued = true;
|
|
141
|
+
queuedReason = reason;
|
|
142
|
+
return;
|
|
143
|
+
}
|
|
144
|
+
running = true;
|
|
145
|
+
let currentReason = reason;
|
|
146
|
+
try {
|
|
147
|
+
do {
|
|
148
|
+
queued = false;
|
|
149
|
+
queuedReason = void 0;
|
|
150
|
+
log.info(`running \`surrealkit sync\` (${currentReason})`);
|
|
151
|
+
const result = await runSyncCommand(options, config.root, (line) => {
|
|
152
|
+
log.debug(line);
|
|
153
|
+
}).catch((err) => {
|
|
154
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
155
|
+
log.error(`failed to start SurrealKit process: ${message}`);
|
|
156
|
+
return {
|
|
157
|
+
code: 1,
|
|
158
|
+
signal: null,
|
|
159
|
+
output: ""
|
|
160
|
+
};
|
|
161
|
+
});
|
|
162
|
+
if (result.code === 0) {
|
|
163
|
+
log.info("Database schema sync completed successfully");
|
|
164
|
+
if (options.reloadOnSync && currentReason !== "startup" && server) {
|
|
165
|
+
server.ws.send({ type: "full-reload" });
|
|
166
|
+
log.debug("sent full-reload to browser");
|
|
167
|
+
}
|
|
168
|
+
} else {
|
|
169
|
+
const exit = result.code === null ? `signal ${result.signal ?? "unknown"}` : `exit code ${result.code}`;
|
|
170
|
+
const detail = result.output ? `
|
|
171
|
+
${result.output}` : "";
|
|
172
|
+
const message = `sync failed (${exit})${detail}`;
|
|
173
|
+
log.error(message);
|
|
174
|
+
if (config.command === "build" && options.failBuildOnError) {
|
|
175
|
+
throw new Error(message);
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
if (queued) {
|
|
179
|
+
currentReason = queuedReason ?? "queued";
|
|
180
|
+
}
|
|
181
|
+
} while (queued);
|
|
182
|
+
} finally {
|
|
183
|
+
running = false;
|
|
184
|
+
queuedReason = void 0;
|
|
185
|
+
}
|
|
186
|
+
};
|
|
187
|
+
const scheduleSync = (reason) => {
|
|
188
|
+
if (timer) clearTimeout(timer);
|
|
189
|
+
timer = setTimeout(() => {
|
|
190
|
+
void runSync(reason);
|
|
191
|
+
}, options.debounceMs);
|
|
192
|
+
};
|
|
193
|
+
return {
|
|
194
|
+
name: "vite-plugin-surrealkit",
|
|
195
|
+
configResolved(resolved) {
|
|
196
|
+
config = resolved;
|
|
197
|
+
matchesSchemaFile = createMatcher(resolved.root, options.schemaGlobs);
|
|
198
|
+
if (options.include.size === 0) {
|
|
199
|
+
log.error(
|
|
200
|
+
"no include modes configured; plugin is effectively disabled"
|
|
201
|
+
);
|
|
202
|
+
}
|
|
203
|
+
},
|
|
204
|
+
async buildStart() {
|
|
205
|
+
if (!config || !options.include.has("build") || config.command !== "build") {
|
|
206
|
+
return;
|
|
207
|
+
}
|
|
208
|
+
if (options.runOnStartup) {
|
|
209
|
+
await runSync("build-start");
|
|
210
|
+
}
|
|
211
|
+
},
|
|
212
|
+
configureServer(devServer) {
|
|
213
|
+
if (!options.include.has("serve")) {
|
|
214
|
+
return;
|
|
215
|
+
}
|
|
216
|
+
server = devServer;
|
|
217
|
+
if (options.schemaGlobs.length > 0) {
|
|
218
|
+
devServer.watcher.add(
|
|
219
|
+
options.schemaGlobs.map(
|
|
220
|
+
(glob) => import_node_path.default.resolve(devServer.config.root, glob)
|
|
221
|
+
)
|
|
222
|
+
);
|
|
223
|
+
}
|
|
224
|
+
const onSchemaEvent = (event) => (filePath) => {
|
|
225
|
+
if (!matchesSchemaFile || !matchesSchemaFile(filePath)) {
|
|
226
|
+
return;
|
|
227
|
+
}
|
|
228
|
+
log.debug(
|
|
229
|
+
`${event}: ${(0, import_vite.normalizePath)(import_node_path.default.relative(devServer.config.root, filePath))}`
|
|
230
|
+
);
|
|
231
|
+
scheduleSync(`${event}`);
|
|
232
|
+
};
|
|
233
|
+
const onAdd = onSchemaEvent("add");
|
|
234
|
+
const onChange = onSchemaEvent("change");
|
|
235
|
+
const onUnlink = onSchemaEvent("unlink");
|
|
236
|
+
devServer.watcher.on("add", onAdd);
|
|
237
|
+
devServer.watcher.on("change", onChange);
|
|
238
|
+
devServer.watcher.on("unlink", onUnlink);
|
|
239
|
+
devServer.httpServer?.once("close", () => {
|
|
240
|
+
devServer.watcher.off("add", onAdd);
|
|
241
|
+
devServer.watcher.off("change", onChange);
|
|
242
|
+
devServer.watcher.off("unlink", onUnlink);
|
|
243
|
+
if (timer) {
|
|
244
|
+
clearTimeout(timer);
|
|
245
|
+
timer = void 0;
|
|
246
|
+
}
|
|
247
|
+
});
|
|
248
|
+
if (options.runOnStartup) {
|
|
249
|
+
scheduleSync("startup");
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
};
|
|
253
|
+
}
|
|
254
|
+
var index_default = surrealkitPlugin;
|
|
255
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
256
|
+
0 && (module.exports = {
|
|
257
|
+
surrealkitPlugin
|
|
258
|
+
});
|
|
259
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["import { spawn } from \"node:child_process\";\nimport path from \"node:path\";\n\nimport picomatch from \"picomatch\";\nimport {\n\tnormalizePath,\n\ttype Plugin,\n\ttype ResolvedConfig,\n\ttype ViteDevServer,\n} from \"vite\";\n\nconst DEFAULT_SCHEMA_GLOBS = [\"database/schema/**/*.surql\"];\n\ntype RunMode = \"serve\" | \"build\";\ntype LogLevel = \"silent\" | \"error\" | \"info\" | \"debug\";\n\nexport interface SurrealkitPluginOptions {\n\t/** SurrealKit binary (or executable path). */\n\tbinary?: string;\n\t/** Working directory for the SurrealKit process. Defaults to Vite root. */\n\tcwd?: string;\n\t/** Extra env vars merged with process.env. */\n\tenv?: Record<string, string>;\n\t/** Additional args appended after `surrealkit sync`. */\n\tsyncArgs?: string[];\n\t/** Globs (relative to Vite root) that trigger sync in dev. */\n\tschemaGlobs?: string[];\n\t/** Where the plugin runs. Default: ['serve']. */\n\tinclude?: RunMode[];\n\t/** Run an initial sync when dev server starts or build begins. Default: true. */\n\trunOnStartup?: boolean;\n\t/** Send full-reload after a successful schema-triggered sync in dev. Default: false. */\n\treloadOnSync?: boolean;\n\t/** Debounce window for dev file changes in ms. Default: 150. */\n\tdebounceMs?: number;\n\t/** Logging verbosity. Default: 'info'. */\n\tlogLevel?: LogLevel;\n\t/** Fail Vite build if sync exits non-zero. Default: true. */\n\tfailBuildOnError?: boolean;\n}\n\ninterface ResolvedOptions {\n\tbinary: string;\n\tcwd?: string;\n\tenv?: Record<string, string>;\n\tsyncArgs: string[];\n\tschemaGlobs: string[];\n\tinclude: Set<RunMode>;\n\trunOnStartup: boolean;\n\treloadOnSync: boolean;\n\tdebounceMs: number;\n\tlogLevel: LogLevel;\n\tfailBuildOnError: boolean;\n}\n\nfunction resolveOptions(options: SurrealkitPluginOptions): ResolvedOptions {\n\treturn {\n\t\tbinary: options.binary ?? \"surrealkit\",\n\t\tcwd: options.cwd,\n\t\tenv: options.env,\n\t\tsyncArgs: options.syncArgs ?? [],\n\t\tschemaGlobs: options.schemaGlobs ?? DEFAULT_SCHEMA_GLOBS,\n\t\tinclude: new Set(options.include ?? [\"serve\"]),\n\t\trunOnStartup: options.runOnStartup ?? true,\n\t\treloadOnSync: options.reloadOnSync ?? false,\n\t\tdebounceMs: options.debounceMs ?? 150,\n\t\tlogLevel: options.logLevel ?? \"info\",\n\t\tfailBuildOnError: options.failBuildOnError ?? true,\n\t};\n}\n\ninterface CommandResult {\n\tcode: number | null;\n\tsignal: NodeJS.Signals | null;\n\toutput: string;\n}\n\nfunction truncateOutput(value: string, maxChars = 4000): string {\n\tif (value.length <= maxChars) {\n\t\treturn value;\n\t}\n\n\tconst sliced = value.slice(value.length - maxChars);\n\treturn `...${sliced}`;\n}\n\nfunction runSyncCommand(\n\toptions: ResolvedOptions,\n\troot: string,\n\tonDebugLine?: (line: string) => void,\n): Promise<CommandResult> {\n\treturn new Promise((resolve, reject) => {\n\t\tconst commandArgs = [\"sync\", ...options.syncArgs];\n\t\tconst child = spawn(options.binary, commandArgs, {\n\t\t\tcwd: options.cwd ?? root,\n\t\t\tenv: {\n\t\t\t\t...process.env,\n\t\t\t\t...options.env,\n\t\t\t},\n\t\t\tshell: process.platform === \"win32\",\n\t\t\tstdio: [\"ignore\", \"pipe\", \"pipe\"],\n\t\t});\n\n\t\tlet output = \"\";\n\n\t\tconst consume = (chunk: string): void => {\n\t\t\toutput += chunk;\n\t\t\tif (!onDebugLine) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tconst lines = chunk\n\t\t\t\t.split(\"\\n\")\n\t\t\t\t.map((line) => line.trimEnd())\n\t\t\t\t.filter(Boolean);\n\t\t\tfor (const line of lines) {\n\t\t\t\tonDebugLine(line);\n\t\t\t}\n\t\t};\n\n\t\tchild.stdout?.setEncoding(\"utf8\");\n\t\tchild.stderr?.setEncoding(\"utf8\");\n\t\tchild.stdout?.on(\"data\", consume);\n\t\tchild.stderr?.on(\"data\", consume);\n\n\t\tchild.on(\"error\", reject);\n\t\tchild.on(\"close\", (code, signal) => {\n\t\t\tresolve({\n\t\t\t\tcode,\n\t\t\t\tsignal,\n\t\t\t\toutput: truncateOutput(output.trim()),\n\t\t\t});\n\t\t});\n\t});\n}\n\nfunction createMatcher(\n\troot: string,\n\tglobs: string[],\n): (filePath: string) => boolean {\n\tconst matchers = globs.map((glob) => picomatch(glob));\n\n\treturn (filePath: string): boolean => {\n\t\tconst rel = normalizePath(path.relative(root, filePath));\n\t\treturn matchers.some((matcher) => matcher(rel));\n\t};\n}\n\nexport function surrealkitPlugin(\n\trawOptions: SurrealkitPluginOptions = {},\n): Plugin {\n\tconst options = resolveOptions(rawOptions);\n\n\tlet config: ResolvedConfig | undefined;\n\tlet server: ViteDevServer | undefined;\n\tlet matchesSchemaFile: ((filePath: string) => boolean) | undefined;\n\n\tlet queued = false;\n\tlet queuedReason: string | undefined;\n\tlet running = false;\n\tlet timer: NodeJS.Timeout | undefined;\n\n\tconst log = {\n\t\terror: (message: string): void => {\n\t\t\tif (options.logLevel === \"silent\") {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\t(config?.logger ?? console).error(`[vite-plugin-surrealkit] ${message}`);\n\t\t},\n\t\tinfo: (message: string): void => {\n\t\t\tif (options.logLevel === \"silent\" || options.logLevel === \"error\") {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\t(config?.logger ?? console).info(`[vite-plugin-surrealkit] ${message}`);\n\t\t},\n\t\tdebug: (message: string): void => {\n\t\t\tif (options.logLevel !== \"debug\") {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\t(config?.logger ?? console).info(`[vite-plugin-surrealkit] ${message}`);\n\t\t},\n\t};\n\n\tconst runSync = async (reason: string): Promise<void> => {\n\t\tif (!config) return;\n\n\t\tif (running) {\n\t\t\tqueued = true;\n\t\t\tqueuedReason = reason;\n\t\t\treturn;\n\t\t}\n\n\t\trunning = true;\n\t\tlet currentReason = reason;\n\t\ttry {\n\t\t\tdo {\n\t\t\t\tqueued = false;\n\t\t\t\tqueuedReason = undefined;\n\t\t\t\tlog.info(`running \\`surrealkit sync\\` (${currentReason})`);\n\n\t\t\t\tconst result = await runSyncCommand(options, config.root, (line) => {\n\t\t\t\t\tlog.debug(line);\n\t\t\t\t}).catch((err: unknown) => {\n\t\t\t\t\tconst message = err instanceof Error ? err.message : String(err);\n\t\t\t\t\tlog.error(`failed to start SurrealKit process: ${message}`);\n\t\t\t\t\treturn {\n\t\t\t\t\t\tcode: 1,\n\t\t\t\t\t\tsignal: null,\n\t\t\t\t\t\toutput: \"\",\n\t\t\t\t\t} satisfies CommandResult;\n\t\t\t\t});\n\n\t\t\t\tif (result.code === 0) {\n\t\t\t\t\tlog.info(\"Database schema sync completed successfully\");\n\n\t\t\t\t\tif (options.reloadOnSync && currentReason !== \"startup\" && server) {\n\t\t\t\t\t\tserver.ws.send({ type: \"full-reload\" });\n\t\t\t\t\t\tlog.debug(\"sent full-reload to browser\");\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\tconst exit =\n\t\t\t\t\t\tresult.code === null\n\t\t\t\t\t\t\t? `signal ${result.signal ?? \"unknown\"}`\n\t\t\t\t\t\t\t: `exit code ${result.code}`;\n\t\t\t\t\tconst detail = result.output ? `\\n${result.output}` : \"\";\n\t\t\t\t\tconst message = `sync failed (${exit})${detail}`;\n\n\t\t\t\t\tlog.error(message);\n\n\t\t\t\t\tif (config.command === \"build\" && options.failBuildOnError) {\n\t\t\t\t\t\tthrow new Error(message);\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tif (queued) {\n\t\t\t\t\tcurrentReason = queuedReason ?? \"queued\";\n\t\t\t\t}\n\t\t\t} while (queued);\n\t\t} finally {\n\t\t\trunning = false;\n\t\t\tqueuedReason = undefined;\n\t\t}\n\t};\n\n\tconst scheduleSync = (reason: string): void => {\n\t\tif (timer) clearTimeout(timer);\n\n\t\ttimer = setTimeout(() => {\n\t\t\tvoid runSync(reason);\n\t\t}, options.debounceMs);\n\t};\n\n\treturn {\n\t\tname: \"vite-plugin-surrealkit\",\n\n\t\tconfigResolved(resolved) {\n\t\t\tconfig = resolved;\n\t\t\tmatchesSchemaFile = createMatcher(resolved.root, options.schemaGlobs);\n\n\t\t\tif (options.include.size === 0) {\n\t\t\t\tlog.error(\n\t\t\t\t\t\"no include modes configured; plugin is effectively disabled\",\n\t\t\t\t);\n\t\t\t}\n\t\t},\n\n\t\tasync buildStart() {\n\t\t\tif (\n\t\t\t\t!config ||\n\t\t\t\t!options.include.has(\"build\") ||\n\t\t\t\tconfig.command !== \"build\"\n\t\t\t) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tif (options.runOnStartup) {\n\t\t\t\tawait runSync(\"build-start\");\n\t\t\t}\n\t\t},\n\n\t\tconfigureServer(devServer) {\n\t\t\tif (!options.include.has(\"serve\")) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tserver = devServer;\n\n\t\t\tif (options.schemaGlobs.length > 0) {\n\t\t\t\tdevServer.watcher.add(\n\t\t\t\t\toptions.schemaGlobs.map((glob) =>\n\t\t\t\t\t\tpath.resolve(devServer.config.root, glob),\n\t\t\t\t\t),\n\t\t\t\t);\n\t\t\t}\n\n\t\t\tconst onSchemaEvent =\n\t\t\t\t(event: \"add\" | \"change\" | \"unlink\") =>\n\t\t\t\t(filePath: string): void => {\n\t\t\t\t\tif (!matchesSchemaFile || !matchesSchemaFile(filePath)) {\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\n\t\t\t\t\tlog.debug(\n\t\t\t\t\t\t`${event}: ${normalizePath(path.relative(devServer.config.root, filePath))}`,\n\t\t\t\t\t);\n\t\t\t\t\tscheduleSync(`${event}`);\n\t\t\t\t};\n\n\t\t\tconst onAdd = onSchemaEvent(\"add\");\n\t\t\tconst onChange = onSchemaEvent(\"change\");\n\t\t\tconst onUnlink = onSchemaEvent(\"unlink\");\n\n\t\t\tdevServer.watcher.on(\"add\", onAdd);\n\t\t\tdevServer.watcher.on(\"change\", onChange);\n\t\t\tdevServer.watcher.on(\"unlink\", onUnlink);\n\n\t\t\tdevServer.httpServer?.once(\"close\", () => {\n\t\t\t\tdevServer.watcher.off(\"add\", onAdd);\n\t\t\t\tdevServer.watcher.off(\"change\", onChange);\n\t\t\t\tdevServer.watcher.off(\"unlink\", onUnlink);\n\n\t\t\t\tif (timer) {\n\t\t\t\t\tclearTimeout(timer);\n\t\t\t\t\ttimer = undefined;\n\t\t\t\t}\n\t\t\t});\n\n\t\t\tif (options.runOnStartup) {\n\t\t\t\tscheduleSync(\"startup\");\n\t\t\t}\n\t\t},\n\t};\n}\n\nexport default surrealkitPlugin;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,gCAAsB;AACtB,uBAAiB;AAEjB,uBAAsB;AACtB,kBAKO;AAEP,IAAM,uBAAuB,CAAC,4BAA4B;AA4C1D,SAAS,eAAe,SAAmD;AAC1E,SAAO;AAAA,IACN,QAAQ,QAAQ,UAAU;AAAA,IAC1B,KAAK,QAAQ;AAAA,IACb,KAAK,QAAQ;AAAA,IACb,UAAU,QAAQ,YAAY,CAAC;AAAA,IAC/B,aAAa,QAAQ,eAAe;AAAA,IACpC,SAAS,IAAI,IAAI,QAAQ,WAAW,CAAC,OAAO,CAAC;AAAA,IAC7C,cAAc,QAAQ,gBAAgB;AAAA,IACtC,cAAc,QAAQ,gBAAgB;AAAA,IACtC,YAAY,QAAQ,cAAc;AAAA,IAClC,UAAU,QAAQ,YAAY;AAAA,IAC9B,kBAAkB,QAAQ,oBAAoB;AAAA,EAC/C;AACD;AAQA,SAAS,eAAe,OAAe,WAAW,KAAc;AAC/D,MAAI,MAAM,UAAU,UAAU;AAC7B,WAAO;AAAA,EACR;AAEA,QAAM,SAAS,MA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
+
import { Plugin } from 'vite';
|
|
2
|
+
|
|
3
|
+
type RunMode = "serve" | "build";
|
|
4
|
+
type LogLevel = "silent" | "error" | "info" | "debug";
|
|
5
|
+
interface SurrealkitPluginOptions {
|
|
6
|
+
/** SurrealKit binary (or executable path). */
|
|
7
|
+
binary?: string;
|
|
8
|
+
/** Working directory for the SurrealKit process. Defaults to Vite root. */
|
|
9
|
+
cwd?: string;
|
|
10
|
+
/** Extra env vars merged with process.env. */
|
|
11
|
+
env?: Record<string, string>;
|
|
12
|
+
/** Additional args appended after `surrealkit sync`. */
|
|
13
|
+
syncArgs?: string[];
|
|
14
|
+
/** Globs (relative to Vite root) that trigger sync in dev. */
|
|
15
|
+
schemaGlobs?: string[];
|
|
16
|
+
/** Where the plugin runs. Default: ['serve']. */
|
|
17
|
+
include?: RunMode[];
|
|
18
|
+
/** Run an initial sync when dev server starts or build begins. Default: true. */
|
|
19
|
+
runOnStartup?: boolean;
|
|
20
|
+
/** Send full-reload after a successful schema-triggered sync in dev. Default: false. */
|
|
21
|
+
reloadOnSync?: boolean;
|
|
22
|
+
/** Debounce window for dev file changes in ms. Default: 150. */
|
|
23
|
+
debounceMs?: number;
|
|
24
|
+
/** Logging verbosity. Default: 'info'. */
|
|
25
|
+
logLevel?: LogLevel;
|
|
26
|
+
/** Fail Vite build if sync exits non-zero. Default: true. */
|
|
27
|
+
failBuildOnError?: boolean;
|
|
28
|
+
}
|
|
29
|
+
declare function surrealkitPlugin(rawOptions?: SurrealkitPluginOptions): Plugin;
|
|
30
|
+
|
|
31
|
+
export { type SurrealkitPluginOptions, surrealkitPlugin as default, surrealkitPlugin };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { Plugin } from 'vite';
|
|
2
|
+
|
|
3
|
+
type RunMode = "serve" | "build";
|
|
4
|
+
type LogLevel = "silent" | "error" | "info" | "debug";
|
|
5
|
+
interface SurrealkitPluginOptions {
|
|
6
|
+
/** SurrealKit binary (or executable path). */
|
|
7
|
+
binary?: string;
|
|
8
|
+
/** Working directory for the SurrealKit process. Defaults to Vite root. */
|
|
9
|
+
cwd?: string;
|
|
10
|
+
/** Extra env vars merged with process.env. */
|
|
11
|
+
env?: Record<string, string>;
|
|
12
|
+
/** Additional args appended after `surrealkit sync`. */
|
|
13
|
+
syncArgs?: string[];
|
|
14
|
+
/** Globs (relative to Vite root) that trigger sync in dev. */
|
|
15
|
+
schemaGlobs?: string[];
|
|
16
|
+
/** Where the plugin runs. Default: ['serve']. */
|
|
17
|
+
include?: RunMode[];
|
|
18
|
+
/** Run an initial sync when dev server starts or build begins. Default: true. */
|
|
19
|
+
runOnStartup?: boolean;
|
|
20
|
+
/** Send full-reload after a successful schema-triggered sync in dev. Default: false. */
|
|
21
|
+
reloadOnSync?: boolean;
|
|
22
|
+
/** Debounce window for dev file changes in ms. Default: 150. */
|
|
23
|
+
debounceMs?: number;
|
|
24
|
+
/** Logging verbosity. Default: 'info'. */
|
|
25
|
+
logLevel?: LogLevel;
|
|
26
|
+
/** Fail Vite build if sync exits non-zero. Default: true. */
|
|
27
|
+
failBuildOnError?: boolean;
|
|
28
|
+
}
|
|
29
|
+
declare function surrealkitPlugin(rawOptions?: SurrealkitPluginOptions): Plugin;
|
|
30
|
+
|
|
31
|
+
export { type SurrealkitPluginOptions, surrealkitPlugin as default, surrealkitPlugin };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,226 @@
|
|
|
1
|
+
// src/index.ts
|
|
2
|
+
import { spawn } from "child_process";
|
|
3
|
+
import path from "path";
|
|
4
|
+
import picomatch from "picomatch";
|
|
5
|
+
import {
|
|
6
|
+
normalizePath
|
|
7
|
+
} from "vite";
|
|
8
|
+
var DEFAULT_SCHEMA_GLOBS = ["database/schema/**/*.surql"];
|
|
9
|
+
function resolveOptions(options) {
|
|
10
|
+
return {
|
|
11
|
+
binary: options.binary ?? "surrealkit",
|
|
12
|
+
cwd: options.cwd,
|
|
13
|
+
env: options.env,
|
|
14
|
+
syncArgs: options.syncArgs ?? [],
|
|
15
|
+
schemaGlobs: options.schemaGlobs ?? DEFAULT_SCHEMA_GLOBS,
|
|
16
|
+
include: new Set(options.include ?? ["serve"]),
|
|
17
|
+
runOnStartup: options.runOnStartup ?? true,
|
|
18
|
+
reloadOnSync: options.reloadOnSync ?? false,
|
|
19
|
+
debounceMs: options.debounceMs ?? 150,
|
|
20
|
+
logLevel: options.logLevel ?? "info",
|
|
21
|
+
failBuildOnError: options.failBuildOnError ?? true
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
function truncateOutput(value, maxChars = 4e3) {
|
|
25
|
+
if (value.length <= maxChars) {
|
|
26
|
+
return value;
|
|
27
|
+
}
|
|
28
|
+
const sliced = value.slice(value.length - maxChars);
|
|
29
|
+
return `...${sliced}`;
|
|
30
|
+
}
|
|
31
|
+
function runSyncCommand(options, root, onDebugLine) {
|
|
32
|
+
return new Promise((resolve, reject) => {
|
|
33
|
+
const commandArgs = ["sync", ...options.syncArgs];
|
|
34
|
+
const child = spawn(options.binary, commandArgs, {
|
|
35
|
+
cwd: options.cwd ?? root,
|
|
36
|
+
env: {
|
|
37
|
+
...process.env,
|
|
38
|
+
...options.env
|
|
39
|
+
},
|
|
40
|
+
shell: process.platform === "win32",
|
|
41
|
+
stdio: ["ignore", "pipe", "pipe"]
|
|
42
|
+
});
|
|
43
|
+
let output = "";
|
|
44
|
+
const consume = (chunk) => {
|
|
45
|
+
output += chunk;
|
|
46
|
+
if (!onDebugLine) {
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
const lines = chunk.split("\n").map((line) => line.trimEnd()).filter(Boolean);
|
|
50
|
+
for (const line of lines) {
|
|
51
|
+
onDebugLine(line);
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
child.stdout?.setEncoding("utf8");
|
|
55
|
+
child.stderr?.setEncoding("utf8");
|
|
56
|
+
child.stdout?.on("data", consume);
|
|
57
|
+
child.stderr?.on("data", consume);
|
|
58
|
+
child.on("error", reject);
|
|
59
|
+
child.on("close", (code, signal) => {
|
|
60
|
+
resolve({
|
|
61
|
+
code,
|
|
62
|
+
signal,
|
|
63
|
+
output: truncateOutput(output.trim())
|
|
64
|
+
});
|
|
65
|
+
});
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
function createMatcher(root, globs) {
|
|
69
|
+
const matchers = globs.map((glob) => picomatch(glob));
|
|
70
|
+
return (filePath) => {
|
|
71
|
+
const rel = normalizePath(path.relative(root, filePath));
|
|
72
|
+
return matchers.some((matcher) => matcher(rel));
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
function surrealkitPlugin(rawOptions = {}) {
|
|
76
|
+
const options = resolveOptions(rawOptions);
|
|
77
|
+
let config;
|
|
78
|
+
let server;
|
|
79
|
+
let matchesSchemaFile;
|
|
80
|
+
let queued = false;
|
|
81
|
+
let queuedReason;
|
|
82
|
+
let running = false;
|
|
83
|
+
let timer;
|
|
84
|
+
const log = {
|
|
85
|
+
error: (message) => {
|
|
86
|
+
if (options.logLevel === "silent") {
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
(config?.logger ?? console).error(`[vite-plugin-surrealkit] ${message}`);
|
|
90
|
+
},
|
|
91
|
+
info: (message) => {
|
|
92
|
+
if (options.logLevel === "silent" || options.logLevel === "error") {
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
95
|
+
(config?.logger ?? console).info(`[vite-plugin-surrealkit] ${message}`);
|
|
96
|
+
},
|
|
97
|
+
debug: (message) => {
|
|
98
|
+
if (options.logLevel !== "debug") {
|
|
99
|
+
return;
|
|
100
|
+
}
|
|
101
|
+
(config?.logger ?? console).info(`[vite-plugin-surrealkit] ${message}`);
|
|
102
|
+
}
|
|
103
|
+
};
|
|
104
|
+
const runSync = async (reason) => {
|
|
105
|
+
if (!config) return;
|
|
106
|
+
if (running) {
|
|
107
|
+
queued = true;
|
|
108
|
+
queuedReason = reason;
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
111
|
+
running = true;
|
|
112
|
+
let currentReason = reason;
|
|
113
|
+
try {
|
|
114
|
+
do {
|
|
115
|
+
queued = false;
|
|
116
|
+
queuedReason = void 0;
|
|
117
|
+
log.info(`running \`surrealkit sync\` (${currentReason})`);
|
|
118
|
+
const result = await runSyncCommand(options, config.root, (line) => {
|
|
119
|
+
log.debug(line);
|
|
120
|
+
}).catch((err) => {
|
|
121
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
122
|
+
log.error(`failed to start SurrealKit process: ${message}`);
|
|
123
|
+
return {
|
|
124
|
+
code: 1,
|
|
125
|
+
signal: null,
|
|
126
|
+
output: ""
|
|
127
|
+
};
|
|
128
|
+
});
|
|
129
|
+
if (result.code === 0) {
|
|
130
|
+
log.info("Database schema sync completed successfully");
|
|
131
|
+
if (options.reloadOnSync && currentReason !== "startup" && server) {
|
|
132
|
+
server.ws.send({ type: "full-reload" });
|
|
133
|
+
log.debug("sent full-reload to browser");
|
|
134
|
+
}
|
|
135
|
+
} else {
|
|
136
|
+
const exit = result.code === null ? `signal ${result.signal ?? "unknown"}` : `exit code ${result.code}`;
|
|
137
|
+
const detail = result.output ? `
|
|
138
|
+
${result.output}` : "";
|
|
139
|
+
const message = `sync failed (${exit})${detail}`;
|
|
140
|
+
log.error(message);
|
|
141
|
+
if (config.command === "build" && options.failBuildOnError) {
|
|
142
|
+
throw new Error(message);
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
if (queued) {
|
|
146
|
+
currentReason = queuedReason ?? "queued";
|
|
147
|
+
}
|
|
148
|
+
} while (queued);
|
|
149
|
+
} finally {
|
|
150
|
+
running = false;
|
|
151
|
+
queuedReason = void 0;
|
|
152
|
+
}
|
|
153
|
+
};
|
|
154
|
+
const scheduleSync = (reason) => {
|
|
155
|
+
if (timer) clearTimeout(timer);
|
|
156
|
+
timer = setTimeout(() => {
|
|
157
|
+
void runSync(reason);
|
|
158
|
+
}, options.debounceMs);
|
|
159
|
+
};
|
|
160
|
+
return {
|
|
161
|
+
name: "vite-plugin-surrealkit",
|
|
162
|
+
configResolved(resolved) {
|
|
163
|
+
config = resolved;
|
|
164
|
+
matchesSchemaFile = createMatcher(resolved.root, options.schemaGlobs);
|
|
165
|
+
if (options.include.size === 0) {
|
|
166
|
+
log.error(
|
|
167
|
+
"no include modes configured; plugin is effectively disabled"
|
|
168
|
+
);
|
|
169
|
+
}
|
|
170
|
+
},
|
|
171
|
+
async buildStart() {
|
|
172
|
+
if (!config || !options.include.has("build") || config.command !== "build") {
|
|
173
|
+
return;
|
|
174
|
+
}
|
|
175
|
+
if (options.runOnStartup) {
|
|
176
|
+
await runSync("build-start");
|
|
177
|
+
}
|
|
178
|
+
},
|
|
179
|
+
configureServer(devServer) {
|
|
180
|
+
if (!options.include.has("serve")) {
|
|
181
|
+
return;
|
|
182
|
+
}
|
|
183
|
+
server = devServer;
|
|
184
|
+
if (options.schemaGlobs.length > 0) {
|
|
185
|
+
devServer.watcher.add(
|
|
186
|
+
options.schemaGlobs.map(
|
|
187
|
+
(glob) => path.resolve(devServer.config.root, glob)
|
|
188
|
+
)
|
|
189
|
+
);
|
|
190
|
+
}
|
|
191
|
+
const onSchemaEvent = (event) => (filePath) => {
|
|
192
|
+
if (!matchesSchemaFile || !matchesSchemaFile(filePath)) {
|
|
193
|
+
return;
|
|
194
|
+
}
|
|
195
|
+
log.debug(
|
|
196
|
+
`${event}: ${normalizePath(path.relative(devServer.config.root, filePath))}`
|
|
197
|
+
);
|
|
198
|
+
scheduleSync(`${event}`);
|
|
199
|
+
};
|
|
200
|
+
const onAdd = onSchemaEvent("add");
|
|
201
|
+
const onChange = onSchemaEvent("change");
|
|
202
|
+
const onUnlink = onSchemaEvent("unlink");
|
|
203
|
+
devServer.watcher.on("add", onAdd);
|
|
204
|
+
devServer.watcher.on("change", onChange);
|
|
205
|
+
devServer.watcher.on("unlink", onUnlink);
|
|
206
|
+
devServer.httpServer?.once("close", () => {
|
|
207
|
+
devServer.watcher.off("add", onAdd);
|
|
208
|
+
devServer.watcher.off("change", onChange);
|
|
209
|
+
devServer.watcher.off("unlink", onUnlink);
|
|
210
|
+
if (timer) {
|
|
211
|
+
clearTimeout(timer);
|
|
212
|
+
timer = void 0;
|
|
213
|
+
}
|
|
214
|
+
});
|
|
215
|
+
if (options.runOnStartup) {
|
|
216
|
+
scheduleSync("startup");
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
};
|
|
220
|
+
}
|
|
221
|
+
var index_default = surrealkitPlugin;
|
|
222
|
+
export {
|
|
223
|
+
index_default as default,
|
|
224
|
+
surrealkitPlugin
|
|
225
|
+
};
|
|
226
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["import { spawn } from \"node:child_process\";\nimport path from \"node:path\";\n\nimport picomatch from \"picomatch\";\nimport {\n\tnormalizePath,\n\ttype Plugin,\n\ttype ResolvedConfig,\n\ttype ViteDevServer,\n} from \"vite\";\n\nconst DEFAULT_SCHEMA_GLOBS = [\"database/schema/**/*.surql\"];\n\ntype RunMode = \"serve\" | \"build\";\ntype LogLevel = \"silent\" | \"error\" | \"info\" | \"debug\";\n\nexport interface SurrealkitPluginOptions {\n\t/** SurrealKit binary (or executable path). */\n\tbinary?: string;\n\t/** Working directory for the SurrealKit process. Defaults to Vite root. */\n\tcwd?: string;\n\t/** Extra env vars merged with process.env. */\n\tenv?: Record<string, string>;\n\t/** Additional args appended after `surrealkit sync`. */\n\tsyncArgs?: string[];\n\t/** Globs (relative to Vite root) that trigger sync in dev. */\n\tschemaGlobs?: string[];\n\t/** Where the plugin runs. Default: ['serve']. */\n\tinclude?: RunMode[];\n\t/** Run an initial sync when dev server starts or build begins. Default: true. */\n\trunOnStartup?: boolean;\n\t/** Send full-reload after a successful schema-triggered sync in dev. Default: false. */\n\treloadOnSync?: boolean;\n\t/** Debounce window for dev file changes in ms. Default: 150. */\n\tdebounceMs?: number;\n\t/** Logging verbosity. Default: 'info'. */\n\tlogLevel?: LogLevel;\n\t/** Fail Vite build if sync exits non-zero. Default: true. */\n\tfailBuildOnError?: boolean;\n}\n\ninterface ResolvedOptions {\n\tbinary: string;\n\tcwd?: string;\n\tenv?: Record<string, string>;\n\tsyncArgs: string[];\n\tschemaGlobs: string[];\n\tinclude: Set<RunMode>;\n\trunOnStartup: boolean;\n\treloadOnSync: boolean;\n\tdebounceMs: number;\n\tlogLevel: LogLevel;\n\tfailBuildOnError: boolean;\n}\n\nfunction resolveOptions(options: SurrealkitPluginOptions): ResolvedOptions {\n\treturn {\n\t\tbinary: options.binary ?? \"surrealkit\",\n\t\tcwd: options.cwd,\n\t\tenv: options.env,\n\t\tsyncArgs: options.syncArgs ?? [],\n\t\tschemaGlobs: options.schemaGlobs ?? DEFAULT_SCHEMA_GLOBS,\n\t\tinclude: new Set(options.include ?? [\"serve\"]),\n\t\trunOnStartup: options.runOnStartup ?? true,\n\t\treloadOnSync: options.reloadOnSync ?? false,\n\t\tdebounceMs: options.debounceMs ?? 150,\n\t\tlogLevel: options.logLevel ?? \"info\",\n\t\tfailBuildOnError: options.failBuildOnError ?? true,\n\t};\n}\n\ninterface CommandResult {\n\tcode: number | null;\n\tsignal: NodeJS.Signals | null;\n\toutput: string;\n}\n\nfunction truncateOutput(value: string, maxChars = 4000): string {\n\tif (value.length <= maxChars) {\n\t\treturn value;\n\t}\n\n\tconst sliced = value.slice(value.length - maxChars);\n\treturn `...${sliced}`;\n}\n\nfunction runSyncCommand(\n\toptions: ResolvedOptions,\n\troot: string,\n\tonDebugLine?: (line: string) => void,\n): Promise<CommandResult> {\n\treturn new Promise((resolve, reject) => {\n\t\tconst commandArgs = [\"sync\", ...options.syncArgs];\n\t\tconst child = spawn(options.binary, commandArgs, {\n\t\t\tcwd: options.cwd ?? root,\n\t\t\tenv: {\n\t\t\t\t...process.env,\n\t\t\t\t...options.env,\n\t\t\t},\n\t\t\tshell: process.platform === \"win32\",\n\t\t\tstdio: [\"ignore\", \"pipe\", \"pipe\"],\n\t\t});\n\n\t\tlet output = \"\";\n\n\t\tconst consume = (chunk: string): void => {\n\t\t\toutput += chunk;\n\t\t\tif (!onDebugLine) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tconst lines = chunk\n\t\t\t\t.split(\"\\n\")\n\t\t\t\t.map((line) => line.trimEnd())\n\t\t\t\t.filter(Boolean);\n\t\t\tfor (const line of lines) {\n\t\t\t\tonDebugLine(line);\n\t\t\t}\n\t\t};\n\n\t\tchild.stdout?.setEncoding(\"utf8\");\n\t\tchild.stderr?.setEncoding(\"utf8\");\n\t\tchild.stdout?.on(\"data\", consume);\n\t\tchild.stderr?.on(\"data\", consume);\n\n\t\tchild.on(\"error\", reject);\n\t\tchild.on(\"close\", (code, signal) => {\n\t\t\tresolve({\n\t\t\t\tcode,\n\t\t\t\tsignal,\n\t\t\t\toutput: truncateOutput(output.trim()),\n\t\t\t});\n\t\t});\n\t});\n}\n\nfunction createMatcher(\n\troot: string,\n\tglobs: string[],\n): (filePath: string) => boolean {\n\tconst matchers = globs.map((glob) => picomatch(glob));\n\n\treturn (filePath: string): boolean => {\n\t\tconst rel = normalizePath(path.relative(root, filePath));\n\t\treturn matchers.some((matcher) => matcher(rel));\n\t};\n}\n\nexport function surrealkitPlugin(\n\trawOptions: SurrealkitPluginOptions = {},\n): Plugin {\n\tconst options = resolveOptions(rawOptions);\n\n\tlet config: ResolvedConfig | undefined;\n\tlet server: ViteDevServer | undefined;\n\tlet matchesSchemaFile: ((filePath: string) => boolean) | undefined;\n\n\tlet queued = false;\n\tlet queuedReason: string | undefined;\n\tlet running = false;\n\tlet timer: NodeJS.Timeout | undefined;\n\n\tconst log = {\n\t\terror: (message: string): void => {\n\t\t\tif (options.logLevel === \"silent\") {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\t(config?.logger ?? console).error(`[vite-plugin-surrealkit] ${message}`);\n\t\t},\n\t\tinfo: (message: string): void => {\n\t\t\tif (options.logLevel === \"silent\" || options.logLevel === \"error\") {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\t(config?.logger ?? console).info(`[vite-plugin-surrealkit] ${message}`);\n\t\t},\n\t\tdebug: (message: string): void => {\n\t\t\tif (options.logLevel !== \"debug\") {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\t(config?.logger ?? console).info(`[vite-plugin-surrealkit] ${message}`);\n\t\t},\n\t};\n\n\tconst runSync = async (reason: string): Promise<void> => {\n\t\tif (!config) return;\n\n\t\tif (running) {\n\t\t\tqueued = true;\n\t\t\tqueuedReason = reason;\n\t\t\treturn;\n\t\t}\n\n\t\trunning = true;\n\t\tlet currentReason = reason;\n\t\ttry {\n\t\t\tdo {\n\t\t\t\tqueued = false;\n\t\t\t\tqueuedReason = undefined;\n\t\t\t\tlog.info(`running \\`surrealkit sync\\` (${currentReason})`);\n\n\t\t\t\tconst result = await runSyncCommand(options, config.root, (line) => {\n\t\t\t\t\tlog.debug(line);\n\t\t\t\t}).catch((err: unknown) => {\n\t\t\t\t\tconst message = err instanceof Error ? err.message : String(err);\n\t\t\t\t\tlog.error(`failed to start SurrealKit process: ${message}`);\n\t\t\t\t\treturn {\n\t\t\t\t\t\tcode: 1,\n\t\t\t\t\t\tsignal: null,\n\t\t\t\t\t\toutput: \"\",\n\t\t\t\t\t} satisfies CommandResult;\n\t\t\t\t});\n\n\t\t\t\tif (result.code === 0) {\n\t\t\t\t\tlog.info(\"Database schema sync completed successfully\");\n\n\t\t\t\t\tif (options.reloadOnSync && currentReason !== \"startup\" && server) {\n\t\t\t\t\t\tserver.ws.send({ type: \"full-reload\" });\n\t\t\t\t\t\tlog.debug(\"sent full-reload to browser\");\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\tconst exit =\n\t\t\t\t\t\tresult.code === null\n\t\t\t\t\t\t\t? `signal ${result.signal ?? \"unknown\"}`\n\t\t\t\t\t\t\t: `exit code ${result.code}`;\n\t\t\t\t\tconst detail = result.output ? `\\n${result.output}` : \"\";\n\t\t\t\t\tconst message = `sync failed (${exit})${detail}`;\n\n\t\t\t\t\tlog.error(message);\n\n\t\t\t\t\tif (config.command === \"build\" && options.failBuildOnError) {\n\t\t\t\t\t\tthrow new Error(message);\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tif (queued) {\n\t\t\t\t\tcurrentReason = queuedReason ?? \"queued\";\n\t\t\t\t}\n\t\t\t} while (queued);\n\t\t} finally {\n\t\t\trunning = false;\n\t\t\tqueuedReason = undefined;\n\t\t}\n\t};\n\n\tconst scheduleSync = (reason: string): void => {\n\t\tif (timer) clearTimeout(timer);\n\n\t\ttimer = setTimeout(() => {\n\t\t\tvoid runSync(reason);\n\t\t}, options.debounceMs);\n\t};\n\n\treturn {\n\t\tname: \"vite-plugin-surrealkit\",\n\n\t\tconfigResolved(resolved) {\n\t\t\tconfig = resolved;\n\t\t\tmatchesSchemaFile = createMatcher(resolved.root, options.schemaGlobs);\n\n\t\t\tif (options.include.size === 0) {\n\t\t\t\tlog.error(\n\t\t\t\t\t\"no include modes configured; plugin is effectively disabled\",\n\t\t\t\t);\n\t\t\t}\n\t\t},\n\n\t\tasync buildStart() {\n\t\t\tif (\n\t\t\t\t!config ||\n\t\t\t\t!options.include.has(\"build\") ||\n\t\t\t\tconfig.command !== \"build\"\n\t\t\t) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tif (options.runOnStartup) {\n\t\t\t\tawait runSync(\"build-start\");\n\t\t\t}\n\t\t},\n\n\t\tconfigureServer(devServer) {\n\t\t\tif (!options.include.has(\"serve\")) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tserver = devServer;\n\n\t\t\tif (options.schemaGlobs.length > 0) {\n\t\t\t\tdevServer.watcher.add(\n\t\t\t\t\toptions.schemaGlobs.map((glob) =>\n\t\t\t\t\t\tpath.resolve(devServer.config.root, glob),\n\t\t\t\t\t),\n\t\t\t\t);\n\t\t\t}\n\n\t\t\tconst onSchemaEvent =\n\t\t\t\t(event: \"add\" | \"change\" | \"unlink\") =>\n\t\t\t\t(filePath: string): void => {\n\t\t\t\t\tif (!matchesSchemaFile || !matchesSchemaFile(filePath)) {\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\n\t\t\t\t\tlog.debug(\n\t\t\t\t\t\t`${event}: ${normalizePath(path.relative(devServer.config.root, filePath))}`,\n\t\t\t\t\t);\n\t\t\t\t\tscheduleSync(`${event}`);\n\t\t\t\t};\n\n\t\t\tconst onAdd = onSchemaEvent(\"add\");\n\t\t\tconst onChange = onSchemaEvent(\"change\");\n\t\t\tconst onUnlink = onSchemaEvent(\"unlink\");\n\n\t\t\tdevServer.watcher.on(\"add\", onAdd);\n\t\t\tdevServer.watcher.on(\"change\", onChange);\n\t\t\tdevServer.watcher.on(\"unlink\", onUnlink);\n\n\t\t\tdevServer.httpServer?.once(\"close\", () => {\n\t\t\t\tdevServer.watcher.off(\"add\", onAdd);\n\t\t\t\tdevServer.watcher.off(\"change\", onChange);\n\t\t\t\tdevServer.watcher.off(\"unlink\", onUnlink);\n\n\t\t\t\tif (timer) {\n\t\t\t\t\tclearTimeout(timer);\n\t\t\t\t\ttimer = undefined;\n\t\t\t\t}\n\t\t\t});\n\n\t\t\tif (options.runOnStartup) {\n\t\t\t\tscheduleSync(\"startup\");\n\t\t\t}\n\t\t},\n\t};\n}\n\nexport default surrealkitPlugin;\n"],"mappings":";AAAA,SAAS,aAAa;AACtB,OAAO,UAAU;AAEjB,OAAO,eAAe;AACtB;AAAA,EACC;AAAA,OAIM;AAEP,IAAM,uBAAuB,CAAC,4BAA4B;AA4C1D,SAAS,eAAe,SAAmD;AAC1E,SAAO;AAAA,IACN,QAAQ,QAAQ,UAAU;AAAA,IAC1B,KAAK,QAAQ;AAAA,IACb,KAAK,QAAQ;AAAA,IACb,UAAU,QAAQ,YAAY,CAAC;AAAA,IAC/B,aAAa,QAAQ,eAAe;AAAA,IACpC,SAAS,IAAI,IAAI,QAAQ,WAAW,CAAC,OAAO,CAAC;AAAA,IAC7C,cAAc,QAAQ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O;AACV,uBAAa,KAAK;AAClB,kBAAQ;AAAA,QACT;AAAA,MACD,CAAC;AAED,UAAI,QAAQ,cAAc;AACzB,qBAAa,SAAS;AAAA,MACvB;AAAA,IACD;AAAA,EACD;AACD;AAEA,IAAO,gBAAQ;","names":[]}
|
package/package.json
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "vite-plugin-surrealkit",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Vite plugin to run SurrealKit schema sync during dev/build",
|
|
5
|
+
"license": "Unlicense",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"main": "./dist/index.cjs",
|
|
8
|
+
"module": "./dist/index.js",
|
|
9
|
+
"types": "./dist/index.d.ts",
|
|
10
|
+
"exports": {
|
|
11
|
+
".": {
|
|
12
|
+
"types": "./dist/index.d.ts",
|
|
13
|
+
"import": "./dist/index.js",
|
|
14
|
+
"require": "./dist/index.cjs"
|
|
15
|
+
}
|
|
16
|
+
},
|
|
17
|
+
"files": [
|
|
18
|
+
"dist"
|
|
19
|
+
],
|
|
20
|
+
"sideEffects": false,
|
|
21
|
+
"engines": {
|
|
22
|
+
"node": ">=20.19.0"
|
|
23
|
+
},
|
|
24
|
+
"scripts": {
|
|
25
|
+
"build": "tsup",
|
|
26
|
+
"clean": "rm -rf dist",
|
|
27
|
+
"typecheck": "tsc --noEmit"
|
|
28
|
+
},
|
|
29
|
+
"keywords": [
|
|
30
|
+
"vite",
|
|
31
|
+
"surrealdb",
|
|
32
|
+
"surrealkit"
|
|
33
|
+
],
|
|
34
|
+
"peerDependencies": {
|
|
35
|
+
"vite": "^7.0.0 || ^8.0.0"
|
|
36
|
+
},
|
|
37
|
+
"dependencies": {
|
|
38
|
+
"@biomejs/biome": "^2.4.2",
|
|
39
|
+
"picomatch": "^4.0.3"
|
|
40
|
+
},
|
|
41
|
+
"devDependencies": {
|
|
42
|
+
"@types/node": "^24.3.0",
|
|
43
|
+
"@types/picomatch": "^4.0.2",
|
|
44
|
+
"tsup": "^8.2.4",
|
|
45
|
+
"typescript": "^5.9.2",
|
|
46
|
+
"vite": "^7.0.0"
|
|
47
|
+
}
|
|
48
|
+
}
|