@sveltejs/vite-plugin-svelte 4.0.0-next.2 → 4.0.0-next.4
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 +6 -6
- package/src/index.js +0 -1
- package/src/preprocess.js +6 -5
- package/src/public.d.ts +1 -3
- package/src/types/log.d.ts +2 -2
- package/src/utils/compile.js +1 -2
- package/src/utils/constants.js +17 -13
- package/src/utils/id.js +11 -5
- package/src/utils/load-raw.js +2 -3
- package/src/utils/log.js +7 -3
- package/src/utils/options.js +5 -7
- package/src/utils/preprocess.js +2 -2
- package/src/utils/vite-plugin-svelte-stats.js +1 -0
- package/src/utils/watch.js +1 -1
- package/types/index.d.ts +4 -2
- package/types/index.d.ts.map +1 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sveltejs/vite-plugin-svelte",
|
|
3
|
-
"version": "4.0.0-next.
|
|
3
|
+
"version": "4.0.0-next.4",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"author": "dominikg",
|
|
6
6
|
"files": [
|
|
@@ -37,7 +37,7 @@
|
|
|
37
37
|
"homepage": "https://github.com/sveltejs/vite-plugin-svelte#readme",
|
|
38
38
|
"dependencies": {
|
|
39
39
|
"@sveltejs/vite-plugin-svelte-inspector": "^3.0.0-next.0||^3.0.0",
|
|
40
|
-
"debug": "^4.3.
|
|
40
|
+
"debug": "^4.3.5",
|
|
41
41
|
"deepmerge": "^4.3.1",
|
|
42
42
|
"kleur": "^4.1.5",
|
|
43
43
|
"magic-string": "^0.30.10",
|
|
@@ -49,10 +49,10 @@
|
|
|
49
49
|
},
|
|
50
50
|
"devDependencies": {
|
|
51
51
|
"@types/debug": "^4.1.12",
|
|
52
|
-
"esbuild": "^0.
|
|
53
|
-
"sass": "^1.77.
|
|
54
|
-
"svelte": "^5.0.0-next.
|
|
55
|
-
"vite": "^5.
|
|
52
|
+
"esbuild": "^0.23.0",
|
|
53
|
+
"sass": "^1.77.6",
|
|
54
|
+
"svelte": "^5.0.0-next.178",
|
|
55
|
+
"vite": "^5.3.3"
|
|
56
56
|
},
|
|
57
57
|
"scripts": {
|
|
58
58
|
"check:publint": "publint --strict",
|
package/src/index.js
CHANGED
|
@@ -39,7 +39,6 @@ export function svelte(inlineOptions) {
|
|
|
39
39
|
let viteConfig;
|
|
40
40
|
/** @type {import('./types/compile.d.ts').CompileSvelte} */
|
|
41
41
|
let compileSvelte;
|
|
42
|
-
/* eslint-enable no-unused-vars */
|
|
43
42
|
/** @type {import('./types/plugin-api.d.ts').PluginAPI} */
|
|
44
43
|
const api = {};
|
|
45
44
|
/** @type {import('vite').Plugin[]} */
|
package/src/preprocess.js
CHANGED
|
@@ -98,15 +98,16 @@ async function createCssTransform(style, config) {
|
|
|
98
98
|
let resolvedConfig;
|
|
99
99
|
// @ts-expect-error special prop added if running in v-p-s
|
|
100
100
|
if (style.__resolvedConfig) {
|
|
101
|
-
// @ts-expect-error
|
|
101
|
+
// @ts-expect-error not typed
|
|
102
102
|
resolvedConfig = style.__resolvedConfig;
|
|
103
103
|
} else if (isResolvedConfig(config)) {
|
|
104
104
|
resolvedConfig = config;
|
|
105
105
|
} else {
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
106
|
+
// default to "build" if no NODE_ENV is set to avoid running in dev mode for svelte-check etc.
|
|
107
|
+
const useBuild = !process.env.NODE_ENV || process.env.NODE_ENV === 'production';
|
|
108
|
+
const command = useBuild ? 'build' : 'serve';
|
|
109
|
+
const defaultMode = useBuild ? 'production' : 'development';
|
|
110
|
+
resolvedConfig = await resolveConfig(config, command, defaultMode, defaultMode, false);
|
|
110
111
|
}
|
|
111
112
|
return async (code, filename) => {
|
|
112
113
|
return preprocessCSS(code, filename, resolvedConfig);
|
package/src/public.d.ts
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
import type { InlineConfig, ResolvedConfig } from 'vite';
|
|
2
|
-
import type { CompileOptions } from 'svelte/compiler';
|
|
3
|
-
import type { Warning } from 'svelte/compiler';
|
|
4
|
-
import type { PreprocessorGroup } from 'svelte/compiler';
|
|
2
|
+
import type { CompileOptions, Warning, PreprocessorGroup } from 'svelte/compiler';
|
|
5
3
|
import type { Options as InspectorOptions } from '@sveltejs/vite-plugin-svelte-inspector';
|
|
6
4
|
|
|
7
5
|
export type Options = Omit<SvelteConfig, 'vitePlugin'> & PluginOptionsInline;
|
package/src/types/log.d.ts
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import type { Warning } from 'svelte/compiler';
|
|
2
2
|
|
|
3
3
|
export interface LogFn extends SimpleLogFn {
|
|
4
|
-
(message: string, payload?:
|
|
4
|
+
(message: string, payload?: unknown, namespace?: string): void;
|
|
5
5
|
|
|
6
6
|
enabled: boolean;
|
|
7
7
|
once: SimpleLogFn;
|
|
8
8
|
}
|
|
9
9
|
|
|
10
10
|
export interface SimpleLogFn {
|
|
11
|
-
(message: string, payload?:
|
|
11
|
+
(message: string, payload?: unknown, namespace?: string): void;
|
|
12
12
|
}
|
|
13
13
|
|
|
14
14
|
export type SvelteWarningsMessage = {
|
package/src/utils/compile.js
CHANGED
|
@@ -132,7 +132,7 @@ export function createCompileSvelte() {
|
|
|
132
132
|
/** @type {import('svelte/compiler').CompileResult} */
|
|
133
133
|
let compiled;
|
|
134
134
|
try {
|
|
135
|
-
compiled = svelte.compile(finalCode, { ...finalCompileOptions, filename
|
|
135
|
+
compiled = svelte.compile(finalCode, { ...finalCompileOptions, filename });
|
|
136
136
|
// patch output with partial accept until svelte does it
|
|
137
137
|
// TODO remove later
|
|
138
138
|
if (
|
|
@@ -182,7 +182,6 @@ export function createCompileSvelte() {
|
|
|
182
182
|
filename,
|
|
183
183
|
normalizedFilename,
|
|
184
184
|
lang,
|
|
185
|
-
// @ts-ignore
|
|
186
185
|
compiled,
|
|
187
186
|
ssr,
|
|
188
187
|
dependencies,
|
package/src/utils/constants.js
CHANGED
|
@@ -1,20 +1,24 @@
|
|
|
1
|
+
import { createRequire } from 'node:module';
|
|
2
|
+
|
|
1
3
|
export const VITE_RESOLVE_MAIN_FIELDS = ['browser', 'module', 'jsnext:main', 'jsnext'];
|
|
2
4
|
|
|
3
5
|
export const SVELTE_RESOLVE_MAIN_FIELDS = ['svelte'];
|
|
4
6
|
|
|
5
|
-
export const SVELTE_IMPORTS =
|
|
6
|
-
'svelte/
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
7
|
+
export const SVELTE_IMPORTS = Object.entries(
|
|
8
|
+
createRequire(import.meta.url)('svelte/package.json').exports
|
|
9
|
+
)
|
|
10
|
+
.map(([name, config]) => {
|
|
11
|
+
// ignore type only
|
|
12
|
+
if (typeof config === 'object' && Object.keys(config).length === 1 && config.types) {
|
|
13
|
+
return '';
|
|
14
|
+
}
|
|
15
|
+
// ignore names
|
|
16
|
+
if (name === './package.json' || name === './compiler') {
|
|
17
|
+
return '';
|
|
18
|
+
}
|
|
19
|
+
return name.replace(/^\./, 'svelte');
|
|
20
|
+
})
|
|
21
|
+
.filter((s) => s.length > 0);
|
|
18
22
|
|
|
19
23
|
export const SVELTE_EXPORT_CONDITIONS = ['svelte'];
|
|
20
24
|
|
package/src/utils/id.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { createFilter, normalizePath } from 'vite';
|
|
2
2
|
import * as fs from 'node:fs';
|
|
3
|
+
import * as path from 'node:path';
|
|
3
4
|
import { log } from './log.js';
|
|
4
5
|
import { DEFAULT_SVELTE_MODULE_EXT, DEFAULT_SVELTE_MODULE_INFIX } from './constants.js';
|
|
5
6
|
|
|
@@ -90,7 +91,7 @@ function parseRequestQuery(rawQuery) {
|
|
|
90
91
|
const query = Object.fromEntries(new URLSearchParams(rawQuery));
|
|
91
92
|
for (const key in query) {
|
|
92
93
|
if (query[key] === '') {
|
|
93
|
-
// @ts-
|
|
94
|
+
// @ts-expect-error not boolean
|
|
94
95
|
query[key] = true;
|
|
95
96
|
}
|
|
96
97
|
}
|
|
@@ -179,10 +180,15 @@ function buildFilter(include, exclude, extensions) {
|
|
|
179
180
|
*/
|
|
180
181
|
function buildModuleFilter(include, exclude, infixes, extensions) {
|
|
181
182
|
const rollupFilter = createFilter(include, exclude);
|
|
182
|
-
return (filename) =>
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
183
|
+
return (filename) => {
|
|
184
|
+
const basename = path.basename(filename);
|
|
185
|
+
|
|
186
|
+
return (
|
|
187
|
+
rollupFilter(filename) &&
|
|
188
|
+
infixes.some((infix) => basename.includes(infix)) &&
|
|
189
|
+
extensions.some((ext) => basename.endsWith(ext))
|
|
190
|
+
);
|
|
191
|
+
};
|
|
186
192
|
}
|
|
187
193
|
|
|
188
194
|
/**
|
package/src/utils/load-raw.js
CHANGED
|
@@ -60,7 +60,7 @@ export async function loadRaw(svelteRequest, compileSvelte, options) {
|
|
|
60
60
|
let directOutput = result.code;
|
|
61
61
|
// @ts-expect-error might not be SourceMap but toUrl check should suffice
|
|
62
62
|
if (query.sourcemap && result.map?.toUrl) {
|
|
63
|
-
// @ts-expect-error
|
|
63
|
+
// @ts-expect-error toUrl might not exist
|
|
64
64
|
const map = `sourceMappingURL=${result.map.toUrl()}`;
|
|
65
65
|
if (query.type === 'style') {
|
|
66
66
|
directOutput += `\n\n/*# ${map} */\n`;
|
|
@@ -114,8 +114,7 @@ function allToRawExports(compileData, source) {
|
|
|
114
114
|
function toRawExports(object) {
|
|
115
115
|
let exports =
|
|
116
116
|
Object.entries(object)
|
|
117
|
-
//
|
|
118
|
-
.filter(([key, value]) => typeof value !== 'function') // preprocess output has a toString function that's enumerable
|
|
117
|
+
.filter(([_key, value]) => typeof value !== 'function') // preprocess output has a toString function that's enumerable
|
|
119
118
|
.sort(([a], [b]) => (a < b ? -1 : a === b ? 0 : 1))
|
|
120
119
|
.map(([key, value]) => `export const ${key}=${JSON.stringify(value)}`)
|
|
121
120
|
.join('\n') + '\n';
|
package/src/utils/log.js
CHANGED
|
@@ -72,7 +72,11 @@ function _log(logger, message, payload, namespace) {
|
|
|
72
72
|
}
|
|
73
73
|
log = logger.log.extend(namespace);
|
|
74
74
|
}
|
|
75
|
-
payload !== undefined
|
|
75
|
+
if (payload !== undefined) {
|
|
76
|
+
log(message, payload);
|
|
77
|
+
} else {
|
|
78
|
+
log(message);
|
|
79
|
+
}
|
|
76
80
|
} else {
|
|
77
81
|
logger.log(
|
|
78
82
|
logger.color(
|
|
@@ -222,14 +226,14 @@ function buildExtraWarnings(warnings, isBuild) {
|
|
|
222
226
|
* @param {import('svelte/compiler').Warning} w
|
|
223
227
|
*/
|
|
224
228
|
function warnDev(w) {
|
|
225
|
-
log.info.enabled
|
|
229
|
+
if (log.info.enabled) log.info(buildExtendedLogMessage(w));
|
|
226
230
|
}
|
|
227
231
|
|
|
228
232
|
/**
|
|
229
233
|
* @param {import('svelte/compiler').Warning & {frame?: string}} w
|
|
230
234
|
*/
|
|
231
235
|
function warnBuild(w) {
|
|
232
|
-
log.warn.enabled
|
|
236
|
+
if (log.warn.enabled) log.warn(buildExtendedLogMessage(w), w.frame);
|
|
233
237
|
}
|
|
234
238
|
|
|
235
239
|
/**
|
package/src/utils/options.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
/* eslint-disable no-unused-vars */
|
|
2
1
|
import { normalizePath } from 'vite';
|
|
3
2
|
import { isDebugNamespaceEnabled, log } from './log.js';
|
|
4
3
|
import { loadSvelteConfig } from './load-svelte-config.js';
|
|
@@ -30,7 +29,6 @@ import {
|
|
|
30
29
|
|
|
31
30
|
import { isCommonDepWithoutSvelteField } from './dependencies.js';
|
|
32
31
|
import { VitePluginSvelteStats } from './vite-plugin-svelte-stats.js';
|
|
33
|
-
import { VitePluginSvelteCache } from './vite-plugin-svelte-cache.js';
|
|
34
32
|
|
|
35
33
|
const allowedPluginOptions = new Set([
|
|
36
34
|
'include',
|
|
@@ -109,7 +107,7 @@ function convertPluginOptions(config) {
|
|
|
109
107
|
)}`
|
|
110
108
|
);
|
|
111
109
|
unknownPluginOptions.forEach((unkownOption) => {
|
|
112
|
-
// @ts-
|
|
110
|
+
// @ts-expect-error not typed
|
|
113
111
|
delete pluginOptions[unkownOption];
|
|
114
112
|
});
|
|
115
113
|
}
|
|
@@ -191,7 +189,7 @@ function mergeConfigs(...configs) {
|
|
|
191
189
|
*
|
|
192
190
|
* @param {import('../types/options.d.ts').PreResolvedOptions} preResolveOptions
|
|
193
191
|
* @param {import('vite').ResolvedConfig} viteConfig
|
|
194
|
-
* @param {VitePluginSvelteCache} cache
|
|
192
|
+
* @param {import('./vite-plugin-svelte-cache.js').VitePluginSvelteCache} cache
|
|
195
193
|
* @returns {import('../types/options.d.ts').ResolvedOptions}
|
|
196
194
|
*/
|
|
197
195
|
export function resolveOptions(preResolveOptions, viteConfig, cache) {
|
|
@@ -352,7 +350,6 @@ export async function buildExtraViteConfig(options, config) {
|
|
|
352
350
|
}
|
|
353
351
|
// this option is still awaiting a PR in vite to be supported
|
|
354
352
|
// see https://github.com/sveltejs/vite-plugin-svelte/issues/60
|
|
355
|
-
// @ts-ignore
|
|
356
353
|
// knownJsSrcExtensions: options.extensions
|
|
357
354
|
};
|
|
358
355
|
|
|
@@ -394,7 +391,6 @@ export async function buildExtraViteConfig(options, config) {
|
|
|
394
391
|
extraViteConfig.optimizeDeps = {
|
|
395
392
|
...extraViteConfig.optimizeDeps,
|
|
396
393
|
// Experimental Vite API to allow these extensions to be scanned and prebundled
|
|
397
|
-
// @ts-ignore
|
|
398
394
|
extensions: options.extensions ?? ['.svelte'],
|
|
399
395
|
// Add esbuild plugin to prebundle Svelte files.
|
|
400
396
|
// Currently a placeholder as more information is needed after Vite config is resolved,
|
|
@@ -557,7 +553,9 @@ function buildExtraConfigForSvelte(config) {
|
|
|
557
553
|
/** @type {string[]} */
|
|
558
554
|
const exclude = [];
|
|
559
555
|
if (!isDepExcluded('svelte', config.optimizeDeps?.exclude ?? [])) {
|
|
560
|
-
const svelteImportsToInclude = SVELTE_IMPORTS
|
|
556
|
+
const svelteImportsToInclude = SVELTE_IMPORTS.filter(
|
|
557
|
+
(si) => !(si.endsWith('/server') || si.includes('/server/'))
|
|
558
|
+
);
|
|
561
559
|
log.debug(
|
|
562
560
|
`adding bare svelte packages to optimizeDeps.include: ${svelteImportsToInclude.join(', ')} `,
|
|
563
561
|
undefined,
|
package/src/utils/preprocess.js
CHANGED
|
@@ -42,7 +42,7 @@ function buildExtraPreprocessors(options, config) {
|
|
|
42
42
|
/** @type {import('svelte/compiler').PreprocessorGroup[]} */
|
|
43
43
|
const appendPreprocessors = [];
|
|
44
44
|
|
|
45
|
-
// @ts-
|
|
45
|
+
// @ts-expect-error not typed
|
|
46
46
|
const pluginsWithPreprocessorsDeprecated = config.plugins.filter((p) => p?.sveltePreprocess);
|
|
47
47
|
if (pluginsWithPreprocessorsDeprecated.length > 0) {
|
|
48
48
|
log.warn(
|
|
@@ -56,7 +56,7 @@ function buildExtraPreprocessors(options, config) {
|
|
|
56
56
|
p.api = {};
|
|
57
57
|
}
|
|
58
58
|
if (p.api.sveltePreprocess === undefined) {
|
|
59
|
-
// @ts-
|
|
59
|
+
// @ts-expect-error not typed
|
|
60
60
|
p.api.sveltePreprocess = p.sveltePreprocess;
|
|
61
61
|
} else {
|
|
62
62
|
log.error(
|
|
@@ -89,6 +89,7 @@ export class VitePluginSvelteStats {
|
|
|
89
89
|
/** @type {import('../types/vite-plugin-svelte-stats.d.ts').Stat[]} */
|
|
90
90
|
const stats = [];
|
|
91
91
|
const collectionStart = performance.now();
|
|
92
|
+
|
|
92
93
|
const _this = this;
|
|
93
94
|
let hasLoggedProgress = false;
|
|
94
95
|
/** @type {import('../types/vite-plugin-svelte-stats.d.ts').StatCollection} */
|
package/src/utils/watch.js
CHANGED
|
@@ -22,7 +22,7 @@ export function setupWatchers(options, cache, requestParser) {
|
|
|
22
22
|
dependants.forEach((dependant) => {
|
|
23
23
|
if (fs.existsSync(dependant)) {
|
|
24
24
|
log.debug(
|
|
25
|
-
`emitting virtual change event for "${dependant}" because
|
|
25
|
+
`emitting virtual change event for "${dependant}" because dependency "${filename}" changed`,
|
|
26
26
|
undefined,
|
|
27
27
|
'hmr'
|
|
28
28
|
);
|
package/types/index.d.ts
CHANGED
|
@@ -202,9 +202,11 @@ declare module '@sveltejs/vite-plugin-svelte' {
|
|
|
202
202
|
*/
|
|
203
203
|
style?: boolean | InlineConfig | ResolvedConfig;
|
|
204
204
|
}
|
|
205
|
-
export function svelte(inlineOptions?: Partial<Options> | undefined): import(
|
|
206
|
-
export function vitePreprocess(opts?: VitePreprocessOptions | undefined): import(
|
|
205
|
+
export function svelte(inlineOptions?: Partial<Options> | undefined): import("vite").Plugin[];
|
|
206
|
+
export function vitePreprocess(opts?: VitePreprocessOptions | undefined): import("svelte/compiler").PreprocessorGroup;
|
|
207
207
|
export function loadSvelteConfig(viteConfig?: import("vite").UserConfig | undefined, inlineOptions?: Partial<Options> | undefined): Promise<Partial<SvelteConfig> | undefined>;
|
|
208
|
+
|
|
209
|
+
export {};
|
|
208
210
|
}
|
|
209
211
|
|
|
210
212
|
//# sourceMappingURL=index.d.ts.map
|
package/types/index.d.ts.map
CHANGED
|
@@ -21,5 +21,5 @@
|
|
|
21
21
|
null,
|
|
22
22
|
null
|
|
23
23
|
],
|
|
24
|
-
"mappings": ";;;;
|
|
24
|
+
"mappings": ";;;;aAIYA,OAAOA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;kBA6GFC,YAAYA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;kBA8EZC,qBAAqBA;;;;;;;;;;;;;iBCvKtBC,MAAMA;iBCTNC,cAAcA;iBCgBRC,gBAAgBA"
|
|
25
25
|
}
|