@rsvelte/vite-plugin-svelte-native 0.3.14 → 0.3.16
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/envelope.js +4 -1
- package/index.cjs +15 -6
- package/index.d.ts +25 -7
- package/lib/source-map.js +73 -0
- package/package.json +7 -6
- package/parse-envelope.js +2 -0
package/envelope.js
CHANGED
|
@@ -13,6 +13,7 @@
|
|
|
13
13
|
'use strict';
|
|
14
14
|
|
|
15
15
|
const { isWindowOutOfBounds, windowOutOfBoundsMessage } = require('./lib/bounds-check.js');
|
|
16
|
+
const { attachSourceMapMethods } = require('./lib/source-map.js');
|
|
16
17
|
|
|
17
18
|
const MAGIC = 0x31565352; // "RSV1" little-endian
|
|
18
19
|
const VERSION = 1;
|
|
@@ -199,7 +200,9 @@ function makeCodeMapObject(buf, slice, codeOff, codeLen, mapOff, mapLen, sourceC
|
|
|
199
200
|
// parsed object matches the legacy compile() shape —
|
|
200
201
|
// callers that just want the raw JSON to write to disk
|
|
201
202
|
// should prefer `mapBytes` / `mapText` (no JSON.parse).
|
|
202
|
-
mapCache =
|
|
203
|
+
mapCache = attachSourceMapMethods(
|
|
204
|
+
attachSourceContent(JSON.parse(slice(mapOff, mapLen)), sourceContent),
|
|
205
|
+
);
|
|
203
206
|
}
|
|
204
207
|
return mapCache;
|
|
205
208
|
},
|
package/index.cjs
CHANGED
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
const { decodeEnvelope, decodeBatch } = require('./envelope.js');
|
|
6
6
|
const { decodeParseEnvelope } = require('./parse-envelope.js');
|
|
7
7
|
const { resolveTriple } = require('./platform.cjs');
|
|
8
|
+
const { attachResultSourceMapMethods } = require('./lib/source-map.js');
|
|
8
9
|
|
|
9
10
|
const { platform, arch } = process;
|
|
10
11
|
|
|
@@ -93,7 +94,9 @@ function compile(source, options) {
|
|
|
93
94
|
}
|
|
94
95
|
const { options: resolved, warningFilter } = prepareCompileOptions(options);
|
|
95
96
|
if (resolved?.modernAst) {
|
|
96
|
-
return
|
|
97
|
+
return attachResultSourceMapMethods(
|
|
98
|
+
applyWarningFilter(binding.compile(source, resolved), warningFilter),
|
|
99
|
+
);
|
|
97
100
|
}
|
|
98
101
|
return applyWarningFilter(
|
|
99
102
|
decodeEnvelope(binding.compileEnvelopeExternalSources(source, resolved), source),
|
|
@@ -134,7 +137,9 @@ function compileBatch(inputs) {
|
|
|
134
137
|
});
|
|
135
138
|
if (prepared.some((input) => input.options?.modernAst)) {
|
|
136
139
|
return prepared.map((input, i) =>
|
|
137
|
-
|
|
140
|
+
attachResultSourceMapMethods(
|
|
141
|
+
applyWarningFilter(binding.compile(input.source, input.options), filters[i]),
|
|
142
|
+
),
|
|
138
143
|
);
|
|
139
144
|
}
|
|
140
145
|
const sourceContents = prepared.map((input) => input.source);
|
|
@@ -160,10 +165,12 @@ async function compileAsync(source, options) {
|
|
|
160
165
|
// The callback is handed straight through: Rust calls it with upstream's
|
|
161
166
|
// own `{ hash, css, name, filename }` object and reads the string back.
|
|
162
167
|
const result = await binding.compileWithCssHash(source, resolved, options.cssHash);
|
|
163
|
-
return applyWarningFilter(result, warningFilter);
|
|
168
|
+
return attachResultSourceMapMethods(applyWarningFilter(result, warningFilter));
|
|
164
169
|
}
|
|
165
170
|
if (resolved?.modernAst) {
|
|
166
|
-
return
|
|
171
|
+
return attachResultSourceMapMethods(
|
|
172
|
+
applyWarningFilter(binding.compile(source, resolved), warningFilter),
|
|
173
|
+
);
|
|
167
174
|
}
|
|
168
175
|
return applyWarningFilter(
|
|
169
176
|
decodeEnvelope(
|
|
@@ -184,7 +191,9 @@ async function compileBatchAsync(inputs) {
|
|
|
184
191
|
});
|
|
185
192
|
if (prepared.some((input) => input.options?.modernAst)) {
|
|
186
193
|
return prepared.map((input, i) =>
|
|
187
|
-
|
|
194
|
+
attachResultSourceMapMethods(
|
|
195
|
+
applyWarningFilter(binding.compile(input.source, input.options), filters[i]),
|
|
196
|
+
),
|
|
188
197
|
);
|
|
189
198
|
}
|
|
190
199
|
const sourceContents = prepared.map((input) => input.source);
|
|
@@ -254,4 +263,4 @@ module.exports.decodeParseEnvelope = decodeParseEnvelope;
|
|
|
254
263
|
// with `submodules/svelte/packages/svelte/package.json` by hand; run
|
|
255
264
|
// `node scripts/dev/check-vps-version.mjs` (also wired into CI) to
|
|
256
265
|
// catch drift.
|
|
257
|
-
module.exports.VERSION = '5.57.
|
|
266
|
+
module.exports.VERSION = '5.57.1';
|
package/index.d.ts
CHANGED
|
@@ -135,16 +135,34 @@ export interface Warning {
|
|
|
135
135
|
// Compile result
|
|
136
136
|
// ---------------------------------------------------------------------------
|
|
137
137
|
|
|
138
|
+
/**
|
|
139
|
+
* What `svelte/compiler` hands back as `js.map` / `css.map`: the standard
|
|
140
|
+
* Source Map v3 fields plus magic-string's `toString()` / `toUrl()`, which
|
|
141
|
+
* tooling calls to inline a map. Both methods are non-enumerable, so the
|
|
142
|
+
* object still serializes as a plain map.
|
|
143
|
+
*/
|
|
144
|
+
export interface SourceMap {
|
|
145
|
+
version: number;
|
|
146
|
+
file?: string;
|
|
147
|
+
sources: string[];
|
|
148
|
+
sourcesContent?: (string | null)[];
|
|
149
|
+
names: string[];
|
|
150
|
+
mappings: string;
|
|
151
|
+
toString(): string;
|
|
152
|
+
toUrl(): string;
|
|
153
|
+
}
|
|
154
|
+
|
|
138
155
|
export interface CompileResultJs {
|
|
139
156
|
code: string;
|
|
140
157
|
/**
|
|
141
|
-
* A standard SourceMap v3 JSON object
|
|
142
|
-
*
|
|
143
|
-
*
|
|
144
|
-
* sending over the wire)
|
|
145
|
-
* to skip the parse
|
|
158
|
+
* A standard SourceMap v3 JSON object carrying magic-string's
|
|
159
|
+
* `toString()` / `toUrl()`. Accessing this triggers a one-time
|
|
160
|
+
* `JSON.parse` of the underlying envelope bytes. For callers that
|
|
161
|
+
* immediately re-serialize (writing to disk, sending over the wire)
|
|
162
|
+
* prefer {@link mapBytes} / {@link mapText} to skip the parse
|
|
163
|
+
* round-trip.
|
|
146
164
|
*/
|
|
147
|
-
map:
|
|
165
|
+
map: SourceMap | null;
|
|
148
166
|
/**
|
|
149
167
|
* Zero-copy `Buffer` / `Uint8Array` view over the raw sourcemap
|
|
150
168
|
* JSON bytes in a raw envelope. The standard `compile` wrappers
|
|
@@ -159,7 +177,7 @@ export interface CompileResultJs {
|
|
|
159
177
|
export interface CompileResultCss {
|
|
160
178
|
code: string;
|
|
161
179
|
/** See {@link CompileResultJs.map}. */
|
|
162
|
-
map:
|
|
180
|
+
map: SourceMap | null;
|
|
163
181
|
mapBytes: Buffer | Uint8Array | null;
|
|
164
182
|
mapText: string | null;
|
|
165
183
|
hasGlobal: boolean;
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
// `svelte/compiler`'s `compile` / `compileModule` return `js.map` and
|
|
2
|
+
// `css.map` as magic-string `SourceMap` instances, so downstream tooling
|
|
3
|
+
// calls `map.toUrl()` to inline the map (upstream does it itself in
|
|
4
|
+
// `3-transform/css/index.js`, and `vite-plugin-svelte`'s dep optimizer does
|
|
5
|
+
// it in `setup-optimizer.js`). The NAPI boundary can only hand back a plain
|
|
6
|
+
// Source Map v3 object, so those callers get `map.toUrl is not a function`
|
|
7
|
+
// (#4695).
|
|
8
|
+
//
|
|
9
|
+
// Upstream hits the same problem in `utils/mapped_code.js` and solves it the
|
|
10
|
+
// same way — tack the two methods on instead of wrapping in a class, so the
|
|
11
|
+
// object stays a plain data map for `JSON.stringify` and structural
|
|
12
|
+
// comparison. Both are non-enumerable, which is what keeps `{...map}`,
|
|
13
|
+
// `Object.keys(map)` and a serialized envelope byte-identical to before.
|
|
14
|
+
|
|
15
|
+
'use strict';
|
|
16
|
+
|
|
17
|
+
// browser vs node.js, mirroring `mapped_code.js`'s `b64enc`.
|
|
18
|
+
const b64enc =
|
|
19
|
+
typeof window !== 'undefined' && typeof btoa === 'function'
|
|
20
|
+
? /** @param {string} str */ (str) => btoa(unescape(encodeURIComponent(str)))
|
|
21
|
+
: /** @param {string} str */ (str) => Buffer.from(str).toString('base64');
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Give a plain Source Map v3 object magic-string's `SourceMap` methods.
|
|
25
|
+
* Returns the same object; a non-object (or a map that already carries
|
|
26
|
+
* `toUrl`, e.g. one a caller assigned) is handed back untouched.
|
|
27
|
+
*
|
|
28
|
+
* @template T
|
|
29
|
+
* @param {T} map
|
|
30
|
+
* @returns {T}
|
|
31
|
+
*/
|
|
32
|
+
function attachSourceMapMethods(map) {
|
|
33
|
+
if (map === null || typeof map !== 'object') return map;
|
|
34
|
+
if (typeof (/** @type {any} */ (map).toUrl) === 'function') return map;
|
|
35
|
+
Object.defineProperties(map, {
|
|
36
|
+
toString: {
|
|
37
|
+
enumerable: false,
|
|
38
|
+
writable: true,
|
|
39
|
+
configurable: true,
|
|
40
|
+
value: function toString() {
|
|
41
|
+
return JSON.stringify(this);
|
|
42
|
+
},
|
|
43
|
+
},
|
|
44
|
+
toUrl: {
|
|
45
|
+
enumerable: false,
|
|
46
|
+
writable: true,
|
|
47
|
+
configurable: true,
|
|
48
|
+
value: function toUrl() {
|
|
49
|
+
return 'data:application/json;charset=utf-8;base64,' + b64enc(this.toString());
|
|
50
|
+
},
|
|
51
|
+
},
|
|
52
|
+
});
|
|
53
|
+
return map;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Apply {@link attachSourceMapMethods} to every map a `CompileResult`
|
|
58
|
+
* carries. The JSON NAPI entries (`modernAst`, `compileWithCssHash`) return
|
|
59
|
+
* plain objects rather than an envelope, so they need it at the call site.
|
|
60
|
+
*
|
|
61
|
+
* @template T
|
|
62
|
+
* @param {T} result
|
|
63
|
+
* @returns {T}
|
|
64
|
+
*/
|
|
65
|
+
function attachResultSourceMapMethods(result) {
|
|
66
|
+
if (result === null || typeof result !== 'object') return result;
|
|
67
|
+
const r = /** @type {any} */ (result);
|
|
68
|
+
if (r.js) attachSourceMapMethods(r.js.map);
|
|
69
|
+
if (r.css) attachSourceMapMethods(r.css.map);
|
|
70
|
+
return result;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
module.exports = { attachSourceMapMethods, attachResultSourceMapMethods };
|
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.16",
|
|
4
4
|
"description": "NAPI bindings to the rsvelte compiler — used by the @rsvelte vite-plugin-svelte shim",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -26,15 +26,16 @@
|
|
|
26
26
|
"parse-envelope.js",
|
|
27
27
|
"platform.cjs",
|
|
28
28
|
"lib/bounds-check.js",
|
|
29
|
+
"lib/source-map.js",
|
|
29
30
|
"index.cjs",
|
|
30
31
|
"index.d.ts"
|
|
31
32
|
],
|
|
32
33
|
"optionalDependencies": {
|
|
33
|
-
"@rsvelte/vite-plugin-svelte-native-darwin-arm64": "^0.3.
|
|
34
|
-
"@rsvelte/vite-plugin-svelte-native-darwin-x64": "^0.3.
|
|
35
|
-
"@rsvelte/vite-plugin-svelte-native-linux-arm64-gnu": "^0.3.
|
|
36
|
-
"@rsvelte/vite-plugin-svelte-native-linux-x64-gnu": "^0.3.
|
|
37
|
-
"@rsvelte/vite-plugin-svelte-native-win32-x64-msvc": "^0.3.
|
|
34
|
+
"@rsvelte/vite-plugin-svelte-native-darwin-arm64": "^0.3.16",
|
|
35
|
+
"@rsvelte/vite-plugin-svelte-native-darwin-x64": "^0.3.16",
|
|
36
|
+
"@rsvelte/vite-plugin-svelte-native-linux-arm64-gnu": "^0.3.16",
|
|
37
|
+
"@rsvelte/vite-plugin-svelte-native-linux-x64-gnu": "^0.3.16",
|
|
38
|
+
"@rsvelte/vite-plugin-svelte-native-win32-x64-msvc": "^0.3.16"
|
|
38
39
|
},
|
|
39
40
|
"publishConfig": {
|
|
40
41
|
"access": "public"
|
package/parse-envelope.js
CHANGED
|
@@ -1168,9 +1168,11 @@ function readJsProgram(ctx, start, end) {
|
|
|
1168
1168
|
function readJsExpressionStatement(ctx, start, end) {
|
|
1169
1169
|
const loc = readTypedLoc(ctx);
|
|
1170
1170
|
const expression = readNode(ctx);
|
|
1171
|
+
const directive = readOptStr(ctx);
|
|
1171
1172
|
const node = { type: 'ExpressionStatement', start, end };
|
|
1172
1173
|
if (loc !== null) node.loc = loc;
|
|
1173
1174
|
node.expression = expression;
|
|
1175
|
+
if (directive !== null) node.directive = directive;
|
|
1174
1176
|
return node;
|
|
1175
1177
|
}
|
|
1176
1178
|
|