@vizejs/native 0.778.0 → 0.780.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/index.d.ts CHANGED
@@ -100,6 +100,11 @@ export interface AutogenOutputNapi {
100
100
  }
101
101
 
102
102
  export interface BatchCompileOptionsNapi {
103
+ /**
104
+ * Digest of a `vue.plugins` plan registered with `registerPluginPlan`;
105
+ * its directive contracts apply to this compile.
106
+ */
107
+ pluginPlan?: string;
103
108
  /** Fallback tsconfig when inputs have no nearest user project. */
104
109
  typeResolutionFallbackTsconfig?: string;
105
110
  whitespace?: string;
@@ -1317,6 +1322,12 @@ export interface RelatedLocationNapi {
1317
1322
  filename?: string;
1318
1323
  }
1319
1324
 
1325
+ /**
1326
+ * Verify one projected `{ digest, plan }` (JSON) and keep it for later
1327
+ * compiles; returns the digest compile options name it by.
1328
+ */
1329
+ export declare function registerPluginPlan(projected: string): string;
1330
+
1320
1331
  export declare function resolveDesignTokenReferences(categories: string): string;
1321
1332
 
1322
1333
  export declare function resolveViteAliasRequest(
@@ -1385,6 +1396,11 @@ export interface SfcBlockAttributeNapi {
1385
1396
  }
1386
1397
 
1387
1398
  export interface SfcCompileOptionsNapi {
1399
+ /**
1400
+ * Digest of a `vue.plugins` plan registered with `registerPluginPlan`;
1401
+ * its directive contracts apply to this compile.
1402
+ */
1403
+ pluginPlan?: string;
1388
1404
  /** Fallback tsconfig when an input has no nearest user project. */
1389
1405
  typeResolutionFallbackTsconfig?: string;
1390
1406
  whitespace?: string;
package/index.js CHANGED
@@ -103,6 +103,7 @@ module.exports.analyzeSfc = nativeBinding.analyzeSfc;
103
103
  module.exports.parseSfc = nativeBinding.parseSfc;
104
104
  module.exports.parseTemplate = nativeBinding.parseTemplate;
105
105
  module.exports.printCssAst = nativeBinding.printCssAst;
106
+ module.exports.registerPluginPlan = nativeBinding.registerPluginPlan;
106
107
  module.exports.resolveDesignTokenReferences = nativeBinding.resolveDesignTokenReferences;
107
108
  module.exports.resolveViteAliasRequest = nativeBinding.resolveViteAliasRequest;
108
109
  module.exports.resolveViteCssImports = nativeBinding.resolveViteCssImports;
package/native-binding.js CHANGED
@@ -4,6 +4,7 @@
4
4
  const { loadTarget, nativeTargets } = require("./native-targets");
5
5
  const { requireWithBindingIdentity } = require("./native-binding-identity");
6
6
  const loadErrors = [];
7
+ let attemptedTargets = [];
7
8
 
8
9
  function isMissingModuleForSpecifier(error, specifier) {
9
10
  return (
@@ -38,7 +39,8 @@ function loadNativeBinding() {
38
39
  return configured;
39
40
  }
40
41
 
41
- for (const target of nativeTargets(loadErrors)) {
42
+ attemptedTargets = nativeTargets(loadErrors);
43
+ for (const target of attemptedTargets) {
42
44
  const binding = loadTarget(target, loadErrors);
43
45
  if (binding) {
44
46
  return binding;
@@ -78,32 +80,129 @@ function loadWasiBinding() {
78
80
  return wasiBinding;
79
81
  }
80
82
 
83
+ // Every Linux GNU binding is linked against this glibc and gated on it at
84
+ // release (tools/support/github/glibc-floor.ts keeps the same value).
85
+ const linuxGnuGlibcFloor = "2.17";
86
+ const linuxFloorDocs =
87
+ "https://github.com/ubugeeei-prod/vize/blob/main/docs/content/stability.md#linux-glibc-floor";
88
+
89
+ function compareVersions(left, right) {
90
+ const a = left.split(".").map(Number);
91
+ const b = right.split(".").map(Number);
92
+ for (let index = 0; index < Math.max(a.length, b.length); index += 1) {
93
+ const difference = (a[index] ?? 0) - (b[index] ?? 0);
94
+ if (difference !== 0) return difference;
95
+ }
96
+ return 0;
97
+ }
98
+
99
+ function runtimeGlibcVersion() {
100
+ if (process.platform !== "linux") return null;
101
+ try {
102
+ const version = process.report?.getReport?.()?.header?.glibcVersionRuntime;
103
+ return typeof version === "string" ? version : null;
104
+ } catch {
105
+ return null;
106
+ }
107
+ }
108
+
109
+ // `/lib64/libm.so.6: version `GLIBC_2.35' not found (required by ...)`
110
+ function glibcHints(message) {
111
+ const required = /version [`'"]?(GLIBC_[A-Z0-9_.]+)[`'"]? not found/.exec(message)?.[1];
112
+ if (!required) return null;
113
+ const system = runtimeGlibcVersion();
114
+ const version = require("./package.json").version;
115
+ const hints = [
116
+ `This system has ${system ? `glibc ${system}` : "an unknown glibc"}; the binding asks for ${required}.`,
117
+ ];
118
+ if (system && compareVersions(system, linuxGnuGlibcFloor) < 0) {
119
+ hints.push(
120
+ `@vizejs/native ${version} supports glibc ${linuxGnuGlibcFloor} or newer: run on a newer distribution or base image.`,
121
+ );
122
+ } else {
123
+ hints.push(
124
+ `@vizejs/native ${version} is built for glibc ${linuxGnuGlibcFloor} or newer, so this is a packaging bug. ` +
125
+ "Please report it at https://github.com/ubugeeei-prod/vize/issues with this message. " +
126
+ "Until a fixed release, use a distribution with a newer glibc.",
127
+ );
128
+ }
129
+ hints.push(
130
+ `The musl build (@vizejs/native-linux-${process.arch}-musl) only loads on musl systems such as Alpine, not in a glibc process.`,
131
+ `Supported Linux systems: ${linuxFloorDocs}`,
132
+ );
133
+ return hints;
134
+ }
135
+
136
+ function dlopenHints(error) {
137
+ const message = String(error?.message ?? "");
138
+ const glibc = glibcHints(message);
139
+ if (glibc) return glibc;
140
+ if (/cannot open shared object file/.test(message)) {
141
+ return [
142
+ "A system library the binding links is missing. Linux GNU bindings need only libc, libm, and libgcc_s (`libgcc` / `libgcc-s1`); install the missing one.",
143
+ ];
144
+ }
145
+ if (
146
+ /invalid ELF header|wrong ELF class|Exec format error|not a valid Win32 application/.test(
147
+ message,
148
+ )
149
+ ) {
150
+ return [
151
+ "The installed binding was built for another platform. Install dependencies on this machine instead of copying node_modules from another OS or CPU.",
152
+ ];
153
+ }
154
+ return [];
155
+ }
156
+
157
+ function nodeEngineFloor() {
158
+ const range = require("./package.json").engines?.node;
159
+ return /^>=\s*(\d+(?:\.\d+){0,2})$/.exec(range ?? "")?.[1] ?? null;
160
+ }
161
+
162
+ function missingHints() {
163
+ const packages = attemptedTargets.map((target) => `@vizejs/native-${target}`);
164
+ const glibc = runtimeGlibcVersion();
165
+ const libc = process.platform === "linux" ? `, ${glibc ? `glibc ${glibc}` : "musl"}` : "";
166
+ const hints = [
167
+ `${packages.join(" or ") || "No platform package"} is not installed (${process.platform}-${process.arch}${libc}, Node.js ${process.versions.node}).`,
168
+ ];
169
+ const nodeFloor = nodeEngineFloor();
170
+ if (nodeFloor && compareVersions(process.versions.node, nodeFloor) < 0) {
171
+ hints.push(
172
+ `@vizejs/native supports Node.js ${nodeFloor} or newer, and package managers skip its platform package on older Node.js versions. Use Node.js ${nodeFloor} or newer and install again.`,
173
+ );
174
+ } else {
175
+ hints.push(
176
+ "The platform package is an optional dependency: install without --omit=optional / --no-optional, and do not reuse node_modules or a lockfile made on another OS or CPU.",
177
+ "npm has a bug related to optional dependencies (https://github.com/npm/cli/issues/4828): if it persists, remove package-lock.json and node_modules and install again.",
178
+ );
179
+ }
180
+ return hints;
181
+ }
182
+
81
183
  function buildLoadError() {
82
184
  if (loadErrors.length === 0) {
83
185
  return new Error("Failed to load native binding");
84
186
  }
85
187
 
188
+ // A binding that exists but cannot be loaded outranks every candidate that
189
+ // is merely absent (the local file, the WASI fallback).
86
190
  const loadFailure = loadErrors.find((error) => !error?.vizeMissingNativeSpecifier);
87
191
  if (loadFailure) {
88
- return new Error(`Failed to load native binding: ${loadFailure.message}`, {
89
- cause: loadErrors.reduce((error, current) => {
90
- current.cause = error;
91
- return current;
92
- }),
93
- });
192
+ return new Error(
193
+ [`Failed to load native binding: ${loadFailure.message}`, ...dlopenHints(loadFailure)].join(
194
+ "\n",
195
+ ),
196
+ { cause: loadFailure },
197
+ );
94
198
  }
95
199
 
96
- return new Error(
97
- `Cannot find native binding. ` +
98
- `npm has a bug related to optional dependencies (https://github.com/npm/cli/issues/4828). ` +
99
- "Please try `npm i` again after removing both package-lock.json and node_modules directory.",
100
- {
101
- cause: loadErrors.reduce((error, current) => {
102
- current.cause = error;
103
- return current;
104
- }),
105
- },
106
- );
200
+ return new Error(["Cannot find native binding.", ...missingHints()].join("\n"), {
201
+ cause: loadErrors.reduce((error, current) => {
202
+ current.cause = error;
203
+ return current;
204
+ }),
205
+ });
107
206
  }
108
207
 
109
208
  let nativeBinding = loadNativeBinding();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vizejs/native",
3
- "version": "0.778.0",
3
+ "version": "0.780.0",
4
4
  "description": "High-performance Vue.js compiler - Native bindings",
5
5
  "keywords": [
6
6
  "compiler",
@@ -38,14 +38,14 @@
38
38
  "@napi-rs/cli": "3.10.12"
39
39
  },
40
40
  "optionalDependencies": {
41
- "@vizejs/native-darwin-x64": "0.778.0",
42
- "@vizejs/native-darwin-arm64": "0.778.0",
43
- "@vizejs/native-win32-x64-msvc": "0.778.0",
44
- "@vizejs/native-win32-arm64-msvc": "0.778.0",
45
- "@vizejs/native-linux-x64-gnu": "0.778.0",
46
- "@vizejs/native-linux-x64-musl": "0.778.0",
47
- "@vizejs/native-linux-arm64-gnu": "0.778.0",
48
- "@vizejs/native-linux-arm64-musl": "0.778.0"
41
+ "@vizejs/native-darwin-x64": "0.780.0",
42
+ "@vizejs/native-darwin-arm64": "0.780.0",
43
+ "@vizejs/native-win32-x64-msvc": "0.780.0",
44
+ "@vizejs/native-win32-arm64-msvc": "0.780.0",
45
+ "@vizejs/native-linux-x64-gnu": "0.780.0",
46
+ "@vizejs/native-linux-x64-musl": "0.780.0",
47
+ "@vizejs/native-linux-arm64-gnu": "0.780.0",
48
+ "@vizejs/native-linux-arm64-musl": "0.780.0"
49
49
  },
50
50
  "napi": {
51
51
  "binaryName": "vize-vitrine",