vize 0.730.0 → 0.732.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/bin/vize CHANGED
@@ -1,2 +1,7 @@
1
1
  #!/usr/bin/env node
2
- import "../dist/cli.mjs";
2
+
3
+ if (process.argv[2] === "content-mapper") {
4
+ import("../dist/content-mapper-cli.mjs");
5
+ } else {
6
+ import("../dist/cli.mjs");
7
+ }
package/dist/cli.mjs CHANGED
@@ -1,126 +1,9 @@
1
+ import { n as ContentMapperFramingError, r as answerContentMapperInitialize, t as assertMatchingNativeVersion } from "./native-version-guard-Ck4rrm7v.mjs";
1
2
  import { createRequire } from "node:module";
2
- import fs, { readFileSync, readSync, writeSync } from "node:fs";
3
+ import fs from "node:fs";
3
4
  import path from "node:path";
4
- import { fileURLToPath } from "node:url";
5
5
  import { execFileSync, spawnSync } from "node:child_process";
6
6
  import readline from "node:readline";
7
- //#region src/content-mapper-launch.ts
8
- const MAX_HEADER_BYTES = 8 * 1024;
9
- const MAX_MESSAGE_BYTES = 64 * 1024 * 1024;
10
- const idle = new Int32Array(new SharedArrayBuffer(4));
11
- /** Error raised when the launcher receives invalid or incomplete content-mapper framing. */
12
- var ContentMapperFramingError = class extends Error {};
13
- function readSome(buffer, offset, length) {
14
- for (;;) try {
15
- return readSync(0, buffer, offset, length, null);
16
- } catch (error) {
17
- const code = error.code;
18
- if (code === "EOF") return 0;
19
- if (code !== "EAGAIN") throw error;
20
- Atomics.wait(idle, 0, 0, 5);
21
- }
22
- }
23
- /** One frame body, or `null` at EOF before any header byte. */
24
- function readFrame() {
25
- const byte = Buffer.alloc(1);
26
- let header = "";
27
- let line = "";
28
- let contentLength;
29
- for (;;) {
30
- if (header.length >= MAX_HEADER_BYTES) throw new ContentMapperFramingError("content-mapper headers exceed 8 KiB");
31
- if (readSome(byte, 0, 1) === 0) {
32
- if (header.length === 0) return null;
33
- throw new ContentMapperFramingError("EOF inside content-mapper headers");
34
- }
35
- const char = byte.toString("latin1");
36
- header += char;
37
- line += char;
38
- if (char !== "\n") continue;
39
- if (line === "\r\n" || line === "\n") break;
40
- const separator = line.indexOf(":");
41
- if (separator >= 0 && line.slice(0, separator).toLowerCase() === "content-length") {
42
- if (contentLength !== void 0) throw new ContentMapperFramingError("duplicate Content-Length header");
43
- const value = line.slice(separator + 1).trim();
44
- if (!/^\d+$/.test(value)) throw new ContentMapperFramingError("invalid Content-Length");
45
- contentLength = Number(value);
46
- }
47
- line = "";
48
- }
49
- if (contentLength === void 0) throw new ContentMapperFramingError("missing Content-Length header");
50
- if (contentLength > MAX_MESSAGE_BYTES) throw new ContentMapperFramingError("content-mapper message exceeds 64 MiB");
51
- const body = Buffer.alloc(contentLength);
52
- for (let offset = 0; offset < contentLength;) {
53
- const read = readSome(body, offset, contentLength - offset);
54
- if (read === 0) throw new ContentMapperFramingError("EOF inside a content-mapper message");
55
- offset += read;
56
- }
57
- return body;
58
- }
59
- function writeFrame(value) {
60
- const body = Buffer.from(JSON.stringify(value));
61
- const frame = Buffer.concat([Buffer.from(`Content-Length: ${body.length}\r\n\r\n`), body]);
62
- for (let offset = 0; offset < frame.length;) offset += writeSync(1, frame, offset);
63
- }
64
- const fail$1 = (id, code, message) => writeFrame({
65
- error: {
66
- code,
67
- message
68
- },
69
- id,
70
- jsonrpc: "2.0"
71
- });
72
- function initializeProblem(params) {
73
- if (typeof params !== "object" || params === null || Array.isArray(params)) return "Invalid initialize params: expected an object";
74
- const { locale, positionEncodings } = params;
75
- if (locale !== void 0 && locale !== null && typeof locale !== "string") return "Invalid initialize params: `locale` must be a string";
76
- if (positionEncodings === void 0) return "Invalid initialize params: missing field `positionEncodings`";
77
- if (!Array.isArray(positionEncodings) || positionEncodings.some((e) => typeof e !== "string")) return "Invalid initialize params: `positionEncodings` must be a string array";
78
- if (!positionEncodings.includes("utf-8")) return "Vize requires the utf-8 position encoding";
79
- return null;
80
- }
81
- /**
82
- * Answer the stream until `initialize` succeeds. `true` means the native
83
- * server takes over initialized; `false` means the host closed the stream
84
- * first and there is nothing to serve.
85
- */
86
- function answerContentMapperInitialize() {
87
- for (;;) {
88
- const body = readFrame();
89
- if (body === null) return false;
90
- let request;
91
- try {
92
- const parsed = JSON.parse(body.toString("utf8"));
93
- if (typeof parsed !== "object" || parsed === null || Array.isArray(parsed)) throw new Error("expected a request object");
94
- request = parsed;
95
- if (typeof request.method !== "string") throw new Error("missing field `method`");
96
- } catch (error) {
97
- fail$1(null, -32700, `Parse error: ${error.message}`);
98
- continue;
99
- }
100
- const id = request.id ?? null;
101
- if (request.method === "initialize") {
102
- const problem = initializeProblem(request.params ?? null);
103
- if (problem === null) {
104
- writeFrame({
105
- id,
106
- jsonrpc: "2.0",
107
- result: {
108
- diagnosticSource: "vize",
109
- positionEncoding: "utf-8"
110
- }
111
- });
112
- return true;
113
- }
114
- fail$1(id, -32602, problem);
115
- } else if ([
116
- "openProject",
117
- "closeProject",
118
- "transform"
119
- ].includes(request.method)) fail$1(id, -32002, "Content mapper is not initialized");
120
- else fail$1(id, -32601, `Method not found: ${request.method}`);
121
- }
122
- }
123
- //#endregion
124
7
  //#region src/setup/config.ts
125
8
  const VIZE_CONFIG_FILES = [
126
9
  "vize.config.pkl",
@@ -1917,21 +1800,6 @@ function runInitCommand(command) {
1917
1800
  throw new Error(failedInstallMessage(command.command, command.args, `${result.stderr ?? ""}\n${result.stdout ?? ""}`, result.signal ?? result.status));
1918
1801
  }
1919
1802
  //#endregion
1920
- //#region src/native-version.ts
1921
- /**
1922
- * Compares the `vize` CLI package with the installed `@vizejs/native` package.
1923
- *
1924
- * A mismatch must fail before the native binding loads. Otherwise `vize check`
1925
- * would type-check with a different release than the CLI the user invoked.
1926
- */
1927
- function nativeVersionMismatchMessage(cliVersion, nativeVersion, env = process.env) {
1928
- if (env.VIZE_ALLOW_NATIVE_VERSION_MISMATCH === "1") return null;
1929
- if (typeof cliVersion !== "string" || cliVersion.length === 0) return "vize package version is missing. Reinstall the vize package before type checking.";
1930
- if (typeof nativeVersion !== "string" || nativeVersion.length === 0) return "@vizejs/native package version is missing. Reinstall dependencies so type checking uses one Vize release.";
1931
- if (cliVersion === nativeVersion) return null;
1932
- return `vize@${cliVersion} and @vizejs/native@${nativeVersion} are different versions. Reinstall dependencies so type checking uses one Vize release.`;
1933
- }
1934
- //#endregion
1935
1803
  //#region src/setup/vite.ts
1936
1804
  const VITE_CONFIG_FILES = [
1937
1805
  "vite.config.ts",
@@ -2174,24 +2042,6 @@ function writePlannedFiles(root, plannedFiles, writeFile) {
2174
2042
  //#endregion
2175
2043
  //#region src/cli.ts
2176
2044
  const require = createRequire(import.meta.url);
2177
- function readPackageVersion(filename) {
2178
- return JSON.parse(readFileSync(filename, "utf8")).version;
2179
- }
2180
- function assertMatchingNativeVersion() {
2181
- const packageRoot = path.resolve(fileURLToPath(new URL(".", import.meta.url)), "..");
2182
- const cliVersion = readPackageVersion(path.join(packageRoot, "package.json"));
2183
- const nativeSpecifier = ["@vizejs/native", "package.json"].join("/");
2184
- let nativeVersion;
2185
- try {
2186
- nativeVersion = readPackageVersion(require.resolve(nativeSpecifier));
2187
- } catch (error) {
2188
- const code = typeof error === "object" && error !== null && "code" in error ? error.code : void 0;
2189
- if (code === "MODULE_NOT_FOUND" || code === "ERR_PACKAGE_PATH_NOT_EXPORTED") return;
2190
- throw error;
2191
- }
2192
- const message = nativeVersionMismatchMessage(cliVersion, nativeVersion);
2193
- if (message !== null) throw new Error(message);
2194
- }
2195
2045
  function fail(error) {
2196
2046
  const message = error instanceof Error ? error.message : String(error);
2197
2047
  process.stderr.write(`[vize] ${message}\n`);