@sveltejs/vite-plugin-svelte 6.1.4 → 6.2.1

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sveltejs/vite-plugin-svelte",
3
- "version": "6.1.4",
3
+ "version": "6.2.1",
4
4
  "license": "MIT",
5
5
  "author": "dominikg",
6
6
  "files": [
package/src/utils/log.js CHANGED
@@ -1,5 +1,6 @@
1
1
  /* eslint-disable no-console */
2
2
 
3
+ // eslint-disable-next-line n/no-unsupported-features/node-builtins
3
4
  import { styleText } from 'node:util';
4
5
  const cyan = (/** @type {string} */ txt) => styleText('cyan', txt);
5
6
  const yellow = (/** @type {string} */ txt) => styleText('yellow', txt);
@@ -145,9 +146,7 @@ export function logCompilerWarnings(svelteRequest, warnings, options) {
145
146
  let warn = isBuild ? warnBuild : warnDev;
146
147
  /** @type {import('svelte/compiler').Warning[]} */
147
148
  const handledByDefaultWarn = [];
148
- const notIgnored = warnings?.filter((w) => !ignoreCompilerWarning(w, isBuild, emitCss));
149
- const extra = buildExtraWarnings(warnings, isBuild);
150
- const allWarnings = [...notIgnored, ...extra];
149
+ const allWarnings = warnings?.filter((w) => !ignoreCompilerWarning(w, isBuild, emitCss));
151
150
  if (sendViaWS) {
152
151
  const _warn = warn;
153
152
  /** @type {(w: import('svelte/compiler').Warning) => void} */
@@ -202,31 +201,6 @@ function isNoScopableElementWarning(warning) {
202
201
  return warning.code === 'css_unused_selector' && warning.message.includes('"*"');
203
202
  }
204
203
 
205
- /**
206
- *
207
- * @param {import('svelte/compiler').Warning[]} warnings
208
- * @param {boolean} isBuild
209
- * @returns {import('svelte/compiler').Warning[]}
210
- */
211
- function buildExtraWarnings(warnings, isBuild) {
212
- const extraWarnings = [];
213
- if (!isBuild) {
214
- const noScopableElementWarnings = warnings.filter((w) => isNoScopableElementWarning(w));
215
- if (noScopableElementWarnings.length > 0) {
216
- // in case there are multiple, use last one as that is the one caused by our *{} rule
217
- const noScopableElementWarning =
218
- noScopableElementWarnings[noScopableElementWarnings.length - 1];
219
- extraWarnings.push({
220
- ...noScopableElementWarning,
221
- code: 'vite-plugin-svelte-css-no-scopable-elements',
222
- message:
223
- "No scopable elements found in template. If you're using global styles in the style tag, you should move it into an external stylesheet file and import it in JS. See https://github.com/sveltejs/vite-plugin-svelte/blob/main/docs/faq.md#where-should-i-put-my-global-styles."
224
- });
225
- }
226
- }
227
- return extraWarnings;
228
- }
229
-
230
204
  /**
231
205
  * @param {import('svelte/compiler').Warning} w
232
206
  */
@@ -6,7 +6,9 @@ const {
6
6
  defaultClientConditions,
7
7
  defaultServerConditions,
8
8
  normalizePath,
9
- searchForWorkspaceRoot
9
+ searchForWorkspaceRoot,
10
+ // @ts-ignore
11
+ rolldownVersion
10
12
  } = vite;
11
13
  import { log } from './log.js';
12
14
  import { loadSvelteConfig } from './load-svelte-config.js';
@@ -418,6 +420,20 @@ function validateViteConfig(extraViteConfig, config, options) {
418
420
  );
419
421
  }
420
422
  }
423
+ if (rolldownVersion && isBuild) {
424
+ // read user config inlineConst value
425
+ const inlineConst =
426
+ //@ts-ignore optimization only exists in rolldown-vite
427
+ config.build?.rolldownOptions?.optimization?.inlineConst ??
428
+ //@ts-ignore optimization only exists in rolldown-vite
429
+ config.build?.rollupOptions?.optimization?.inlineConst;
430
+
431
+ if (inlineConst === false) {
432
+ log.warn(
433
+ 'Your rolldown config contains `optimization.inlineConst: false`. This can lead to increased bundle size and leaked server code in client build.'
434
+ );
435
+ }
436
+ }
421
437
  }
422
438
 
423
439
  /**
@@ -6,15 +6,34 @@ import { VERSION } from 'svelte/compiler';
6
6
  export const isSvelteWithAsync = gte(VERSION, '5.36.0');
7
7
 
8
8
  /**
9
- * compare semver versions, does not include comparing tags (-next.xy is ignored)
9
+ * split semver string and convert to number, ignores non digits in tag
10
+ * @param {string} semver
11
+ * @return {number[]} [major,minor,patch,tag]
12
+ */
13
+ function splitToNumbers(semver) {
14
+ const num = semver
15
+ .replace(/[^\d.-]/g, '')
16
+ .split(/[.-]+/, 4)
17
+ .map(Number);
18
+ while (num.length < 3) {
19
+ num.push(0);
20
+ }
21
+ if (num.length < 4) {
22
+ num.push(Infinity);
23
+ }
24
+ return num;
25
+ }
26
+
27
+ /**
28
+ * compare semver versions, tags are compared by their numeric part only
10
29
  *
11
30
  * @param {string} a semver version
12
31
  * @param {string} b semver version
13
32
  * @return {boolean} true if a is greater or equal to b
14
33
  */
15
34
  export function gte(a, b) {
16
- const aNum = a.split(/[.-]/, 3).map(Number);
17
- const bNum = b.split(/[.-]/, 3).map(Number);
35
+ const aNum = splitToNumbers(a);
36
+ const bNum = splitToNumbers(b);
18
37
  for (let i = 0; i < aNum.length; i++) {
19
38
  if (aNum[i] < bNum[i]) {
20
39
  return false;