@rsvelte/vite-plugin-svelte 0.5.1 → 0.5.3
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/package.json +8 -6
- package/src/utils/compile.js +10 -26
- package/src/utils/map-edits.js +37 -5
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rsvelte/vite-plugin-svelte",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.3",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"author": "dominikg",
|
|
6
6
|
"files": [
|
|
@@ -36,13 +36,13 @@
|
|
|
36
36
|
"dependencies": {
|
|
37
37
|
"@jridgewell/remapping": "^2.3.5",
|
|
38
38
|
"@jridgewell/trace-mapping": "^0.3.31",
|
|
39
|
+
"@rsvelte/vite-plugin-svelte-native": "^0.3.14",
|
|
39
40
|
"@sveltejs/vite-plugin-svelte-inspector": "^5.0.0",
|
|
40
41
|
"acorn": "^8.16.0",
|
|
41
42
|
"deepmerge": "^4.3.1",
|
|
42
43
|
"magic-string": "^1.0.0",
|
|
43
|
-
"obug": "^
|
|
44
|
-
"vitefu": "^1.1.1"
|
|
45
|
-
"@rsvelte/vite-plugin-svelte-native": "^0.3.7"
|
|
44
|
+
"obug": "^3.0.0",
|
|
45
|
+
"vitefu": "^1.1.1"
|
|
46
46
|
},
|
|
47
47
|
"peerDependencies": {
|
|
48
48
|
"svelte": "^5.0.0",
|
|
@@ -51,10 +51,12 @@
|
|
|
51
51
|
"devDependencies": {
|
|
52
52
|
"@types/debug": "^4.1.12",
|
|
53
53
|
"sass": "^1.94.2",
|
|
54
|
-
"svelte": "
|
|
55
|
-
"vite": "^8.0.0"
|
|
54
|
+
"svelte": "5.57.0",
|
|
55
|
+
"vite": "^8.0.0",
|
|
56
|
+
"vitest": "^5.0.0"
|
|
56
57
|
},
|
|
57
58
|
"scripts": {
|
|
59
|
+
"test": "vitest run",
|
|
58
60
|
"check:publint": "publint --strict",
|
|
59
61
|
"check:types": "tsc --noEmit",
|
|
60
62
|
"generate:types": "dts-buddy -m \"@rsvelte/vite-plugin-svelte:src/public.d.ts\""
|
package/src/utils/compile.js
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
import * as svelte from '@rsvelte/vite-plugin-svelte-native';
|
|
2
2
|
import { safeBase64Hash } from './hash.js';
|
|
3
3
|
import { log } from './log.js';
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
import { mapToRelative } from './sourcemaps.js';
|
|
4
|
+
import { postprocessCompiled } from './map-edits.js';
|
|
7
5
|
import { enhanceCompileError } from './error.js';
|
|
8
6
|
|
|
9
7
|
// TODO this is a patched version of https://github.com/sveltejs/vite-plugin-svelte/pull/796/files#diff-3bce0b33034aad4b35ca094893671f7e7ddf4d27254ae7b9b0f912027a001b15R10
|
|
@@ -105,17 +103,6 @@ export function createCompileSvelte() {
|
|
|
105
103
|
typeof finalCompileOptions.cssHash === 'function'
|
|
106
104
|
? await svelte.compileAsync(finalCode, { ...finalCompileOptions, filename })
|
|
107
105
|
: svelte.compile(finalCode, { ...finalCompileOptions, filename });
|
|
108
|
-
|
|
109
|
-
// patch output with partial accept until svelte does it
|
|
110
|
-
// TODO remove later
|
|
111
|
-
if (
|
|
112
|
-
options.server?.config.experimental.hmrPartialAccept &&
|
|
113
|
-
compiled.js.code.includes('import.meta.hot')
|
|
114
|
-
) {
|
|
115
|
-
applyMapEdits(compiled, filename, (editor, generated) => {
|
|
116
|
-
addPartialAcceptExports(editor, generated);
|
|
117
|
-
});
|
|
118
|
-
}
|
|
119
106
|
} catch (e) {
|
|
120
107
|
enhanceCompileError(e, code, options.preprocess);
|
|
121
108
|
throw e;
|
|
@@ -124,24 +111,21 @@ export function createCompileSvelte() {
|
|
|
124
111
|
if (endStat) {
|
|
125
112
|
endStat();
|
|
126
113
|
}
|
|
127
|
-
mapToRelative(compiled.js?.map, filename);
|
|
128
|
-
mapToRelative(compiled.css?.map, filename);
|
|
129
114
|
if (warnings.length) {
|
|
130
115
|
if (!compiled.warnings) {
|
|
131
116
|
compiled.warnings = [];
|
|
132
117
|
}
|
|
133
118
|
compiled.warnings.push(...warnings);
|
|
134
119
|
}
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
}
|
|
120
|
+
// compiler might not emit css with mode none or it may be empty
|
|
121
|
+
const hasCss = compiled.css?.code?.trim()?.length ?? 0 > 0;
|
|
122
|
+
postprocessCompiled(compiled, {
|
|
123
|
+
filename,
|
|
124
|
+
cssId,
|
|
125
|
+
// patch output with partial accept until svelte does it
|
|
126
|
+
partialAccept: !!options.server?.config.experimental.hmrPartialAccept,
|
|
127
|
+
emitCssImport: !raw && emitCss && hasCss
|
|
128
|
+
});
|
|
145
129
|
|
|
146
130
|
let lang = 'js';
|
|
147
131
|
for (const match of code.matchAll(scriptLangRE)) {
|
package/src/utils/map-edits.js
CHANGED
|
@@ -1,6 +1,12 @@
|
|
|
1
1
|
import remapping from '@jridgewell/remapping';
|
|
2
2
|
import { parse } from 'acorn';
|
|
3
3
|
import MagicString from 'magic-string';
|
|
4
|
+
import { mapToRelative } from './sourcemaps.js';
|
|
5
|
+
|
|
6
|
+
// remapping resolves a loaded map's sources against the URI of the source it
|
|
7
|
+
// replaces, so a name with a directory component would rewrite relative sources
|
|
8
|
+
// into absolute ones. A bare name leaves every spelling untouched.
|
|
9
|
+
const PRE_EDIT_SOURCE = 'rsvelte-pre-edit-source';
|
|
4
10
|
|
|
5
11
|
/** @param {any} callee */
|
|
6
12
|
function isHotAcceptCallee(callee) {
|
|
@@ -39,22 +45,48 @@ function collectHotAcceptCalls(node, calls) {
|
|
|
39
45
|
|
|
40
46
|
/**
|
|
41
47
|
* @param {{ js: { code: string, map: any } }} compiled
|
|
42
|
-
* @param {string} filename
|
|
43
48
|
* @param {(editor: MagicString, code: string) => void} edit
|
|
44
49
|
*/
|
|
45
|
-
export function applyMapEdits(compiled,
|
|
50
|
+
export function applyMapEdits(compiled, edit) {
|
|
46
51
|
const editor = new MagicString(compiled.js.code);
|
|
47
52
|
edit(editor, compiled.js.code);
|
|
48
53
|
const previousMap = compiled.js.map;
|
|
49
54
|
compiled.js.code = editor.toString();
|
|
50
55
|
if (!previousMap) return;
|
|
51
|
-
const editMap = editor.generateMap({ hires: true, source:
|
|
56
|
+
const editMap = editor.generateMap({ hires: true, source: PRE_EDIT_SOURCE });
|
|
52
57
|
let loadedPreviousMap = false;
|
|
53
|
-
|
|
54
|
-
if (source !==
|
|
58
|
+
const composed = remapping(/** @type {any} */ (editMap), (source) => {
|
|
59
|
+
if (source !== PRE_EDIT_SOURCE || loadedPreviousMap) return null;
|
|
55
60
|
loadedPreviousMap = true;
|
|
56
61
|
return /** @type {any} */ (previousMap);
|
|
57
62
|
});
|
|
63
|
+
// the edit map carries no `file`, so composing would otherwise drop it
|
|
64
|
+
if (previousMap.file != null) {
|
|
65
|
+
/** @type {any} */ (composed).file = previousMap.file;
|
|
66
|
+
}
|
|
67
|
+
compiled.js.map = composed;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Rewrite the compiled JavaScript for the dev server — HMR partial accept and the
|
|
72
|
+
* emitted-CSS import — keeping `js.map` in step with every edit.
|
|
73
|
+
*
|
|
74
|
+
* @param {{ js: { code: string, map: any }, css?: { map?: any } | null }} compiled
|
|
75
|
+
* @param {{ filename: string, cssId: string, partialAccept: boolean, emitCssImport: boolean }} options
|
|
76
|
+
*/
|
|
77
|
+
export function postprocessCompiled(compiled, { filename, cssId, partialAccept, emitCssImport }) {
|
|
78
|
+
if (partialAccept && compiled.js.code.includes('import.meta.hot')) {
|
|
79
|
+
applyMapEdits(compiled, (editor, generated) => {
|
|
80
|
+
addPartialAcceptExports(editor, generated);
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
mapToRelative(compiled.js?.map, filename);
|
|
84
|
+
mapToRelative(compiled.css?.map, filename);
|
|
85
|
+
if (emitCssImport) {
|
|
86
|
+
applyMapEdits(compiled, (editor) => {
|
|
87
|
+
editor.append(`\nimport ${JSON.stringify(cssId)};\n`);
|
|
88
|
+
});
|
|
89
|
+
}
|
|
58
90
|
}
|
|
59
91
|
|
|
60
92
|
/**
|