@sveltejs/vite-plugin-svelte 6.1.3 → 6.2.0

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.3",
3
+ "version": "6.2.0",
4
4
  "license": "MIT",
5
5
  "author": "dominikg",
6
6
  "files": [
@@ -37,7 +37,6 @@
37
37
  "@sveltejs/vite-plugin-svelte-inspector": "^5.0.0",
38
38
  "debug": "^4.4.1",
39
39
  "deepmerge": "^4.3.1",
40
- "kleur": "^4.1.5",
41
40
  "magic-string": "^0.30.17",
42
41
  "vitefu": "^1.1.1"
43
42
  },
@@ -47,9 +46,9 @@
47
46
  },
48
47
  "devDependencies": {
49
48
  "@types/debug": "^4.1.12",
50
- "sass": "^1.90.0",
51
- "svelte": "^5.38.2",
52
- "vite": "^7.1.2"
49
+ "sass": "^1.91.0",
50
+ "svelte": "^5.38.6",
51
+ "vite": "^7.1.4"
53
52
  },
54
53
  "scripts": {
55
54
  "check:publint": "publint --strict",
@@ -12,6 +12,7 @@ import {
12
12
  } from '../utils/options.js';
13
13
  import { buildIdFilter, buildIdParser } from '../utils/id.js';
14
14
  import { createCompileSvelte } from '../utils/compile.js';
15
+ import { gte } from '../utils/svelte-version.js';
15
16
 
16
17
  // @ts-ignore rolldownVersion
17
18
  const { version: viteVersion, rolldownVersion } = vite;
@@ -58,7 +59,39 @@ export function configure(api, inlineOptions) {
58
59
  preOptions = await preResolveOptions(inlineOptions, config, configEnv);
59
60
  // extra vite config
60
61
  const extraViteConfig = await buildExtraViteConfig(preOptions, config);
62
+
63
+ if (
64
+ rolldownVersion &&
65
+ configEnv.command === 'build' &&
66
+ gte(rolldownVersion, '1.0.0-beta.35') // inlineConst received a critical bugfix in 1.0.0-beta.35
67
+ ) {
68
+ extraViteConfig.build ??= {};
69
+ // rename rollupOptions to rolldownOptions
70
+ //@ts-ignore rolldownOptions only exists in rolldown-vite
71
+ extraViteConfig.build.rolldownOptions = extraViteConfig.build.rollupOptions || {};
72
+ delete extraViteConfig.build.rollupOptions;
73
+ // read user config inlineConst value
74
+ const inlineConst =
75
+ //@ts-ignore optimization only exists in rolldown-vite
76
+ config.build?.rolldownOptions?.optimization?.inlineConst ??
77
+ //@ts-ignore optimization only exists in rolldown-vite
78
+ config.build?.rollupOptions?.optimization?.inlineConst;
79
+
80
+ if (inlineConst == null) {
81
+ // set inlineConst build optimization for esm-env
82
+ //@ts-ignore rolldownOptions only exists in rolldown-vite
83
+ extraViteConfig.build.rolldownOptions.optimization ??= {};
84
+ //@ts-ignore rolldownOptions only exists in rolldown-vite
85
+ extraViteConfig.build.rolldownOptions.optimization.inlineConst = true;
86
+ } else if (inlineConst === false) {
87
+ log.warn(
88
+ 'Your rolldown config contains `optimization.inlineConst: false`. This can lead to increased bundle size and leaked server code in client build.'
89
+ );
90
+ }
91
+ }
92
+
61
93
  log.debug('additional vite config', extraViteConfig, 'config');
94
+
62
95
  return extraViteConfig;
63
96
  }
64
97
  },
@@ -31,18 +31,21 @@ export function preprocess(api) {
31
31
  name: 'vite-plugin-svelte:preprocess',
32
32
  enforce: 'pre',
33
33
  configResolved(c) {
34
- //@ts-expect-error defined below but filter not in type
35
- plugin.transform.filter = api.filter;
36
34
  options = api.options;
37
35
  if (arraify(options.preprocess).length > 0) {
38
36
  preprocessSvelte = createPreprocessSvelte(options, c);
37
+ // @ts-expect-error defined below but filter not in type
38
+ plugin.transform.filter = api.filter;
39
39
  } else {
40
40
  log.debug(
41
41
  `disabling ${plugin.name} because no preprocessor is configured`,
42
42
  undefined,
43
43
  'preprocess'
44
44
  );
45
- delete plugin.transform;
45
+ // @ts-expect-error force set undefined to clear memory
46
+ preprocessSvelte = undefined;
47
+ // @ts-expect-error defined below but filter not in type
48
+ plugin.transform.filter = { id: /$./ }; // never match
46
49
  }
47
50
  },
48
51
  configureServer(server) {
package/src/public.d.ts CHANGED
@@ -121,7 +121,7 @@ export interface SvelteConfig {
121
121
  /**
122
122
  * An array of preprocessors to transform the Svelte source code before compilation
123
123
  *
124
- * @see https://svelte.dev/docs#svelte_preprocess
124
+ * @see https://svelte.dev/docs/svelte/svelte-compiler#PreprocessorGroup
125
125
  */
126
126
  preprocess?: Arrayable<PreprocessorGroup>;
127
127
  /**
@@ -129,7 +129,7 @@ export interface SvelteConfig {
129
129
  * including `dev` and `css`. However, some options are non-configurable, like
130
130
  * `filename`, `format`, `generate`, and `cssHash` (in dev).
131
131
  *
132
- * @see https://svelte.dev/docs#svelte_compile
132
+ * @see https://svelte.dev/docs/svelte/svelte-compiler#CompileOptions
133
133
  */
134
134
  compilerOptions?: Omit<CompileOptions, 'filename' | 'format' | 'generate'>;
135
135
 
package/src/utils/log.js CHANGED
@@ -1,5 +1,10 @@
1
1
  /* eslint-disable no-console */
2
- import { cyan, red, yellow } from 'kleur/colors';
2
+
3
+ import { styleText } from 'node:util';
4
+ const cyan = (/** @type {string} */ txt) => styleText('cyan', txt);
5
+ const yellow = (/** @type {string} */ txt) => styleText('yellow', txt);
6
+ const red = (/** @type {string} */ txt) => styleText('red', txt);
7
+
3
8
  import debug from 'debug';
4
9
 
5
10
  /** @type {import('../types/log.d.ts').LogLevel[]} */
@@ -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;
package/types/index.d.ts CHANGED
@@ -121,7 +121,7 @@ declare module '@sveltejs/vite-plugin-svelte' {
121
121
  /**
122
122
  * An array of preprocessors to transform the Svelte source code before compilation
123
123
  *
124
- * @see https://svelte.dev/docs#svelte_preprocess
124
+ * @see https://svelte.dev/docs/svelte/svelte-compiler#PreprocessorGroup
125
125
  */
126
126
  preprocess?: Arrayable<PreprocessorGroup>;
127
127
  /**
@@ -129,7 +129,7 @@ declare module '@sveltejs/vite-plugin-svelte' {
129
129
  * including `dev` and `css`. However, some options are non-configurable, like
130
130
  * `filename`, `format`, `generate`, and `cssHash` (in dev).
131
131
  *
132
- * @see https://svelte.dev/docs#svelte_compile
132
+ * @see https://svelte.dev/docs/svelte/svelte-compiler#CompileOptions
133
133
  */
134
134
  compilerOptions?: Omit<CompileOptions, 'filename' | 'format' | 'generate'>;
135
135