@sveltejs/vite-plugin-svelte 3.0.0 → 3.0.2
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 +7 -7
- package/src/handle-hot-update.js +4 -2
- package/src/preprocess.js +1 -1
- package/src/utils/compile.js +15 -3
- package/src/utils/constants.js +1 -1
- package/src/utils/error.js +6 -3
- package/src/utils/esbuild.js +1 -1
- package/src/utils/load-raw.js +1 -1
- package/src/utils/load-svelte-config.js +3 -3
- package/src/utils/options.js +2 -2
- package/types/index.d.ts +2 -2
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sveltejs/vite-plugin-svelte",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.2",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"author": "dominikg",
|
|
6
6
|
"files": [
|
|
@@ -36,13 +36,13 @@
|
|
|
36
36
|
},
|
|
37
37
|
"homepage": "https://github.com/sveltejs/vite-plugin-svelte#readme",
|
|
38
38
|
"dependencies": {
|
|
39
|
-
"@sveltejs/vite-plugin-svelte-inspector": "^2.0.0-next.0 || ^2.0.0",
|
|
40
39
|
"debug": "^4.3.4",
|
|
41
40
|
"deepmerge": "^4.3.1",
|
|
42
41
|
"kleur": "^4.1.5",
|
|
43
42
|
"magic-string": "^0.30.5",
|
|
44
43
|
"svelte-hmr": "^0.15.3",
|
|
45
|
-
"vitefu": "^0.2.5"
|
|
44
|
+
"vitefu": "^0.2.5",
|
|
45
|
+
"@sveltejs/vite-plugin-svelte-inspector": "^2.0.0"
|
|
46
46
|
},
|
|
47
47
|
"peerDependencies": {
|
|
48
48
|
"svelte": "^4.0.0 || ^5.0.0-next.0",
|
|
@@ -50,10 +50,10 @@
|
|
|
50
50
|
},
|
|
51
51
|
"devDependencies": {
|
|
52
52
|
"@types/debug": "^4.1.12",
|
|
53
|
-
"esbuild": "^0.19.
|
|
54
|
-
"sass": "^1.
|
|
55
|
-
"svelte": "^4.2.
|
|
56
|
-
"vite": "^5.0.
|
|
53
|
+
"esbuild": "^0.19.12",
|
|
54
|
+
"sass": "^1.70.0",
|
|
55
|
+
"svelte": "^4.2.9",
|
|
56
|
+
"vite": "^5.0.11"
|
|
57
57
|
},
|
|
58
58
|
"scripts": {
|
|
59
59
|
"check:publint": "publint --strict",
|
package/src/handle-hot-update.js
CHANGED
|
@@ -104,8 +104,10 @@ function jsChanged(prev, next, filename) {
|
|
|
104
104
|
}
|
|
105
105
|
const isLooseEqual = isCodeEqual(normalizeJsCode(prevJs), normalizeJsCode(nextJs));
|
|
106
106
|
if (!isStrictEqual && isLooseEqual) {
|
|
107
|
-
log.
|
|
108
|
-
`ignoring compiler output js change for ${filename} as it is equal to previous output after normalization
|
|
107
|
+
log.debug(
|
|
108
|
+
`ignoring compiler output js change for ${filename} as it is equal to previous output after normalization`,
|
|
109
|
+
undefined,
|
|
110
|
+
'hmr'
|
|
109
111
|
);
|
|
110
112
|
}
|
|
111
113
|
return !isLooseEqual;
|
package/src/preprocess.js
CHANGED
|
@@ -10,7 +10,7 @@ const supportedScriptLangs = ['ts'];
|
|
|
10
10
|
export const lang_sep = '.vite-preprocess';
|
|
11
11
|
|
|
12
12
|
/**
|
|
13
|
-
* @param {import('./public.d.ts').VitePreprocessOptions} opts
|
|
13
|
+
* @param {import('./public.d.ts').VitePreprocessOptions} [opts]
|
|
14
14
|
* @returns {import('svelte/compiler').PreprocessorGroup}
|
|
15
15
|
*/
|
|
16
16
|
export function vitePreprocess(opts) {
|
package/src/utils/compile.js
CHANGED
|
@@ -12,7 +12,11 @@ import { mapToRelative } from './sourcemaps.js';
|
|
|
12
12
|
import { enhanceCompileError } from './error.js';
|
|
13
13
|
import { isSvelte5 } from './svelte-version.js';
|
|
14
14
|
|
|
15
|
-
|
|
15
|
+
// TODO this is a patched version of https://github.com/sveltejs/vite-plugin-svelte/pull/796/files#diff-3bce0b33034aad4b35ca094893671f7e7ddf4d27254ae7b9b0f912027a001b15R10
|
|
16
|
+
// which is closer to the other regexes in at least not falling into commented script
|
|
17
|
+
// but ideally would be shared exactly with svelte and other tools that use it
|
|
18
|
+
const scriptLangRE =
|
|
19
|
+
/<!--[^]*?-->|<script (?:[^>]*|(?:[^=>'"/]+=(?:"[^"]*"|'[^']*'|[^>\s]+)\s+)*)lang=["']?([^"' >]+)["']?[^>]*>/g;
|
|
16
20
|
|
|
17
21
|
/**
|
|
18
22
|
* @param {Function} [makeHot]
|
|
@@ -133,7 +137,7 @@ export const _createCompileSvelte = (makeHot) => {
|
|
|
133
137
|
? {
|
|
134
138
|
...compileOptions,
|
|
135
139
|
...dynamicCompileOptions
|
|
136
|
-
|
|
140
|
+
}
|
|
137
141
|
: compileOptions;
|
|
138
142
|
|
|
139
143
|
const endStat = stats?.start(filename);
|
|
@@ -180,10 +184,18 @@ export const _createCompileSvelte = (makeHot) => {
|
|
|
180
184
|
}
|
|
181
185
|
}
|
|
182
186
|
|
|
187
|
+
let lang = 'js';
|
|
188
|
+
for (const match of code.matchAll(scriptLangRE)) {
|
|
189
|
+
if (match[1]) {
|
|
190
|
+
lang = match[1];
|
|
191
|
+
break;
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
|
|
183
195
|
return {
|
|
184
196
|
filename,
|
|
185
197
|
normalizedFilename,
|
|
186
|
-
lang
|
|
198
|
+
lang,
|
|
187
199
|
// @ts-ignore
|
|
188
200
|
compiled,
|
|
189
201
|
ssr,
|
package/src/utils/constants.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { isSvelte5 } from './svelte-version.js';
|
|
2
2
|
|
|
3
|
-
export const VITE_RESOLVE_MAIN_FIELDS = ['module', 'jsnext:main', 'jsnext'];
|
|
3
|
+
export const VITE_RESOLVE_MAIN_FIELDS = ['browser', 'module', 'jsnext:main', 'jsnext'];
|
|
4
4
|
|
|
5
5
|
export const SVELTE_RESOLVE_MAIN_FIELDS = ['svelte'];
|
|
6
6
|
|
package/src/utils/error.js
CHANGED
|
@@ -114,8 +114,9 @@ export function enhanceCompileError(err, originalCode, preprocessors) {
|
|
|
114
114
|
|
|
115
115
|
// Handle incorrect TypeScript usage
|
|
116
116
|
if (err.code === 'parse-error') {
|
|
117
|
-
// Reference from Svelte: https://github.com/sveltejs/svelte/blob/
|
|
118
|
-
const scriptRe =
|
|
117
|
+
// Reference from Svelte: https://github.com/sveltejs/svelte/blob/9926347ad9dbdd0f3324d5538e25dcb7f5e442f8/packages/svelte/src/compiler/preprocess/index.js#L259
|
|
118
|
+
const scriptRe =
|
|
119
|
+
/<!--[^]*?-->|<script((?:\s+[^=>'"/]+=(?:"[^"]*"|'[^']*'|[^>\s]+)|\s+[^=>'"/]+)*\s*)(?:\/>|>([\S\s]*?)<\/script>)/g;
|
|
119
120
|
const errIndex = err.pos ?? -1;
|
|
120
121
|
|
|
121
122
|
let m;
|
|
@@ -142,7 +143,9 @@ export function enhanceCompileError(err, originalCode, preprocessors) {
|
|
|
142
143
|
|
|
143
144
|
// Handle incorrect CSS preprocessor usage
|
|
144
145
|
if (err.code === 'css-syntax-error') {
|
|
145
|
-
|
|
146
|
+
// Reference from Svelte: https://github.com/sveltejs/svelte/blob/9926347ad9dbdd0f3324d5538e25dcb7f5e442f8/packages/svelte/src/compiler/preprocess/index.js#L257
|
|
147
|
+
const styleRe =
|
|
148
|
+
/<!--[^]*?-->|<style((?:\s+[^=>'"/]+=(?:"[^"]*"|'[^']*'|[^>\s]+)|\s+[^=>'"/]+)*\s*)(?:\/>|>([\S\s]*?)<\/style>)/g;
|
|
146
149
|
|
|
147
150
|
let m;
|
|
148
151
|
while ((m = styleRe.exec(originalCode))) {
|
package/src/utils/esbuild.js
CHANGED
|
@@ -120,7 +120,7 @@ async function compileSvelte(options, { filename, code }, statsCollection) {
|
|
|
120
120
|
? {
|
|
121
121
|
...compileOptions,
|
|
122
122
|
...dynamicCompileOptions
|
|
123
|
-
|
|
123
|
+
}
|
|
124
124
|
: compileOptions;
|
|
125
125
|
const endStat = statsCollection?.start(filename);
|
|
126
126
|
const compiled = svelte.compile(finalCode, finalCompileOptions);
|
package/src/utils/load-raw.js
CHANGED
|
@@ -25,8 +25,8 @@ async function dynamicImportDefault(filePath, timestamp) {
|
|
|
25
25
|
}
|
|
26
26
|
|
|
27
27
|
/**
|
|
28
|
-
* @param {import('vite').UserConfig} viteConfig
|
|
29
|
-
* @param {Partial<import('../public.d.ts').Options>} inlineOptions
|
|
28
|
+
* @param {import('vite').UserConfig} [viteConfig]
|
|
29
|
+
* @param {Partial<import('../public.d.ts').Options>} [inlineOptions]
|
|
30
30
|
* @returns {Promise<Partial<import('../public.d.ts').SvelteConfig> | undefined>}
|
|
31
31
|
*/
|
|
32
32
|
export async function loadSvelteConfig(viteConfig, inlineOptions) {
|
|
@@ -63,7 +63,7 @@ export async function loadSvelteConfig(viteConfig, inlineOptions) {
|
|
|
63
63
|
const _require = import.meta.url
|
|
64
64
|
? esmRequire ?? (esmRequire = createRequire(import.meta.url))
|
|
65
65
|
: // eslint-disable-next-line no-undef
|
|
66
|
-
|
|
66
|
+
require;
|
|
67
67
|
|
|
68
68
|
// avoid loading cached version on reload
|
|
69
69
|
delete _require.cache[_require.resolve(configFile)];
|
package/src/utils/options.js
CHANGED
|
@@ -199,7 +199,7 @@ export function resolveOptions(preResolveOptions, viteConfig, cache) {
|
|
|
199
199
|
: {
|
|
200
200
|
injectCss: css === 'injected',
|
|
201
201
|
partialAccept: !!viteConfig.experimental?.hmrPartialAccept
|
|
202
|
-
|
|
202
|
+
},
|
|
203
203
|
compilerOptions: {
|
|
204
204
|
css,
|
|
205
205
|
dev: !viteConfig.isProduction
|
|
@@ -551,7 +551,7 @@ async function buildExtraConfigForDependencies(options, config) {
|
|
|
551
551
|
.slice(0, -1)
|
|
552
552
|
.some((d) => isDepExcluded(d.trim(), userExclude))
|
|
553
553
|
);
|
|
554
|
-
|
|
554
|
+
});
|
|
555
555
|
}
|
|
556
556
|
if (options.disableDependencyReinclusion === true) {
|
|
557
557
|
depsConfig.optimizeDeps.include = depsConfig.optimizeDeps.include.filter(
|
package/types/index.d.ts
CHANGED
|
@@ -190,8 +190,8 @@ declare module '@sveltejs/vite-plugin-svelte' {
|
|
|
190
190
|
style?: boolean | InlineConfig | ResolvedConfig;
|
|
191
191
|
}
|
|
192
192
|
export function svelte(inlineOptions?: Partial<Options> | undefined): import('vite').Plugin[];
|
|
193
|
-
export function vitePreprocess(opts
|
|
194
|
-
export function loadSvelteConfig(viteConfig
|
|
193
|
+
export function vitePreprocess(opts?: VitePreprocessOptions | undefined): import('svelte/compiler').PreprocessorGroup;
|
|
194
|
+
export function loadSvelteConfig(viteConfig?: import("vite").UserConfig | undefined, inlineOptions?: Partial<Options> | undefined): Promise<Partial<SvelteConfig> | undefined>;
|
|
195
195
|
}
|
|
196
196
|
|
|
197
197
|
//# sourceMappingURL=index.d.ts.map
|