@rsvelte/vite-plugin-svelte-native 0.3.4 → 0.3.6
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.cjs +24 -27
- package/index.d.ts +8 -0
- package/package.json +7 -6
- package/platform.cjs +22 -0
package/index.cjs
CHANGED
|
@@ -4,36 +4,15 @@
|
|
|
4
4
|
|
|
5
5
|
const { decodeEnvelope, decodeBatch } = require('./envelope.js');
|
|
6
6
|
const { decodeParseEnvelope } = require('./parse-envelope.js');
|
|
7
|
+
const { resolveTriple } = require('./platform.cjs');
|
|
7
8
|
|
|
8
9
|
const { platform, arch } = process;
|
|
9
10
|
|
|
10
|
-
|
|
11
|
-
if (platform === 'darwin') {
|
|
12
|
-
if (arch === 'arm64') return 'darwin-arm64';
|
|
13
|
-
if (arch === 'x64') return 'darwin-x64';
|
|
14
|
-
} else if (platform === 'linux') {
|
|
15
|
-
// Node 18+ exposes the runtime glibc version in the report header. An
|
|
16
|
-
// empty value means we're on musl (Alpine, distroless, etc.).
|
|
17
|
-
let isMusl = false;
|
|
18
|
-
try {
|
|
19
|
-
const header = process.report.getReport().header;
|
|
20
|
-
isMusl = !header.glibcVersionRuntime;
|
|
21
|
-
} catch {
|
|
22
|
-
isMusl = false;
|
|
23
|
-
}
|
|
24
|
-
const libc = isMusl ? 'musl' : 'gnu';
|
|
25
|
-
if (arch === 'x64') return `linux-x64-${libc}`;
|
|
26
|
-
if (arch === 'arm64') return `linux-arm64-${libc}`;
|
|
27
|
-
} else if (platform === 'win32') {
|
|
28
|
-
if (arch === 'x64') return 'win32-x64-msvc';
|
|
29
|
-
}
|
|
30
|
-
return null;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
const triple = resolveTriple();
|
|
11
|
+
const triple = resolveTriple(process);
|
|
34
12
|
if (!triple) {
|
|
13
|
+
const muslHint = platform === 'linux' ? ' (musl/Alpine is not yet supported)' : '';
|
|
35
14
|
throw new Error(
|
|
36
|
-
`[@rsvelte/vite-plugin-svelte-native] Unsupported platform: ${platform}-${arch}. ` +
|
|
15
|
+
`[@rsvelte/vite-plugin-svelte-native] Unsupported platform: ${platform}-${arch}${muslHint}. ` +
|
|
37
16
|
`Open an issue at https://github.com/baseballyama/rsvelte/issues if you'd like it supported.`,
|
|
38
17
|
);
|
|
39
18
|
}
|
|
@@ -127,8 +106,9 @@ function applyWarningFilter(result, warningFilter) {
|
|
|
127
106
|
//
|
|
128
107
|
// Callers that need the raw envelope (e.g. to ship it across a worker
|
|
129
108
|
// boundary without re-encoding) can still grab `binding.compileEnvelope`
|
|
130
|
-
// directly
|
|
131
|
-
//
|
|
109
|
+
// directly, except with modernAst: the v1 envelope has no AST field.
|
|
110
|
+
// The legacy JSON path is preserved as `compileLegacy` for parity testing
|
|
111
|
+
// and as an escape hatch.
|
|
132
112
|
function compile(source, options) {
|
|
133
113
|
if (typeof options?.cssHash === 'function') {
|
|
134
114
|
// A dynamic cssHash needs the Rust→JS callback bridge, which would deadlock
|
|
@@ -138,6 +118,9 @@ function compile(source, options) {
|
|
|
138
118
|
);
|
|
139
119
|
}
|
|
140
120
|
const { options: resolved, warningFilter } = prepareCompileOptions(options);
|
|
121
|
+
if (resolved?.modernAst) {
|
|
122
|
+
return applyWarningFilter(binding.compile(source, resolved), warningFilter);
|
|
123
|
+
}
|
|
141
124
|
return applyWarningFilter(
|
|
142
125
|
decodeEnvelope(binding.compileEnvelopeExternalSources(source, resolved), source),
|
|
143
126
|
warningFilter,
|
|
@@ -175,6 +158,11 @@ function compileBatch(inputs) {
|
|
|
175
158
|
if (warningFilter) filters[i] = warningFilter;
|
|
176
159
|
return options === input.options ? input : { source: input.source, options };
|
|
177
160
|
});
|
|
161
|
+
if (prepared.some((input) => input.options?.modernAst)) {
|
|
162
|
+
return prepared.map((input, i) =>
|
|
163
|
+
applyWarningFilter(binding.compile(input.source, input.options), filters[i]),
|
|
164
|
+
);
|
|
165
|
+
}
|
|
178
166
|
const sourceContents = prepared.map((input) => input.source);
|
|
179
167
|
const results = decodeBatch(
|
|
180
168
|
binding.compileBatchExternalSources(prepared),
|
|
@@ -202,6 +190,9 @@ async function compileAsync(source, options) {
|
|
|
202
190
|
);
|
|
203
191
|
return applyWarningFilter(result, warningFilter);
|
|
204
192
|
}
|
|
193
|
+
if (resolved?.modernAst) {
|
|
194
|
+
return applyWarningFilter(binding.compile(source, resolved), warningFilter);
|
|
195
|
+
}
|
|
205
196
|
return applyWarningFilter(
|
|
206
197
|
decodeEnvelope(
|
|
207
198
|
await binding.compileEnvelopeExternalSourcesAsync(source, resolved),
|
|
@@ -219,6 +210,11 @@ async function compileBatchAsync(inputs) {
|
|
|
219
210
|
if (warningFilter) filters[i] = warningFilter;
|
|
220
211
|
return options === input.options ? input : { source: input.source, options };
|
|
221
212
|
});
|
|
213
|
+
if (prepared.some((input) => input.options?.modernAst)) {
|
|
214
|
+
return prepared.map((input, i) =>
|
|
215
|
+
applyWarningFilter(binding.compile(input.source, input.options), filters[i]),
|
|
216
|
+
);
|
|
217
|
+
}
|
|
222
218
|
const sourceContents = prepared.map((input) => input.source);
|
|
223
219
|
const results = decodeBatch(
|
|
224
220
|
await binding.compileBatchExternalSourcesAsync(prepared),
|
|
@@ -267,6 +263,7 @@ module.exports.preprocess = binding.preprocess;
|
|
|
267
263
|
module.exports.svelte2tsx = binding.svelte2tsx;
|
|
268
264
|
module.exports.hmrDiff = binding.hmrDiff;
|
|
269
265
|
module.exports.resolveId = binding.resolveId;
|
|
266
|
+
module.exports.buildInfo = binding.buildInfo;
|
|
270
267
|
// Standalone parse surfaces. `parse` returns a JSON string (decode with
|
|
271
268
|
// `JSON.parse`); `parseEnvelope` returns the raw-transfer Buffer that skips
|
|
272
269
|
// `JSON.parse` entirely — decode it with `decodeParseEnvelope` (re-exported
|
package/index.d.ts
CHANGED
|
@@ -101,6 +101,14 @@ export interface ModuleCompileOptions {
|
|
|
101
101
|
warningFilter?: (warning: Warning) => boolean;
|
|
102
102
|
}
|
|
103
103
|
|
|
104
|
+
/** Source revision embedded in the native addon at compile time. */
|
|
105
|
+
export interface BuildInfo {
|
|
106
|
+
commit: string;
|
|
107
|
+
dirty: boolean;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
export function buildInfo(): BuildInfo;
|
|
111
|
+
|
|
104
112
|
// ---------------------------------------------------------------------------
|
|
105
113
|
// Diagnostics
|
|
106
114
|
// ---------------------------------------------------------------------------
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rsvelte/vite-plugin-svelte-native",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.6",
|
|
4
4
|
"description": "NAPI bindings to the rsvelte compiler — used by the @rsvelte vite-plugin-svelte shim",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -24,16 +24,17 @@
|
|
|
24
24
|
"files": [
|
|
25
25
|
"envelope.js",
|
|
26
26
|
"parse-envelope.js",
|
|
27
|
+
"platform.cjs",
|
|
27
28
|
"lib/bounds-check.js",
|
|
28
29
|
"index.cjs",
|
|
29
30
|
"index.d.ts"
|
|
30
31
|
],
|
|
31
32
|
"optionalDependencies": {
|
|
32
|
-
"@rsvelte/vite-plugin-svelte-native-darwin-arm64": "^0.3.
|
|
33
|
-
"@rsvelte/vite-plugin-svelte-native-darwin-x64": "^0.3.
|
|
34
|
-
"@rsvelte/vite-plugin-svelte-native-linux-arm64-gnu": "^0.3.
|
|
35
|
-
"@rsvelte/vite-plugin-svelte-native-linux-x64-gnu": "^0.3.
|
|
36
|
-
"@rsvelte/vite-plugin-svelte-native-win32-x64-msvc": "^0.3.
|
|
33
|
+
"@rsvelte/vite-plugin-svelte-native-darwin-arm64": "^0.3.6",
|
|
34
|
+
"@rsvelte/vite-plugin-svelte-native-darwin-x64": "^0.3.6",
|
|
35
|
+
"@rsvelte/vite-plugin-svelte-native-linux-arm64-gnu": "^0.3.6",
|
|
36
|
+
"@rsvelte/vite-plugin-svelte-native-linux-x64-gnu": "^0.3.6",
|
|
37
|
+
"@rsvelte/vite-plugin-svelte-native-win32-x64-msvc": "^0.3.6"
|
|
37
38
|
},
|
|
38
39
|
"publishConfig": {
|
|
39
40
|
"access": "public"
|
package/platform.cjs
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
function resolveTriple(runtime) {
|
|
4
|
+
const { platform, arch } = runtime;
|
|
5
|
+
if (platform === 'darwin') {
|
|
6
|
+
if (arch === 'arm64') return 'darwin-arm64';
|
|
7
|
+
if (arch === 'x64') return 'darwin-x64';
|
|
8
|
+
} else if (platform === 'linux') {
|
|
9
|
+
let isMusl = false;
|
|
10
|
+
try {
|
|
11
|
+
isMusl = !runtime.report.getReport().header.glibcVersionRuntime;
|
|
12
|
+
} catch {}
|
|
13
|
+
if (isMusl) return null;
|
|
14
|
+
if (arch === 'x64') return 'linux-x64-gnu';
|
|
15
|
+
if (arch === 'arm64') return 'linux-arm64-gnu';
|
|
16
|
+
} else if (platform === 'win32' && arch === 'x64') {
|
|
17
|
+
return 'win32-x64-msvc';
|
|
18
|
+
}
|
|
19
|
+
return null;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
module.exports = { resolveTriple };
|