@sveltejs/vite-plugin-svelte 2.4.0 → 2.4.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": "2.4.0",
3
+ "version": "2.4.1",
4
4
  "license": "MIT",
5
5
  "author": "dominikg",
6
6
  "files": [
@@ -40,10 +40,10 @@
40
40
  "magic-string": "^0.30.0",
41
41
  "svelte-hmr": "^0.15.1",
42
42
  "vitefu": "^0.2.4",
43
- "@sveltejs/vite-plugin-svelte-inspector": "^1.0.1"
43
+ "@sveltejs/vite-plugin-svelte-inspector": "^1.0.2"
44
44
  },
45
45
  "peerDependencies": {
46
- "svelte": "^3.54.0",
46
+ "svelte": "^3.54.0 || ^4.0.0-next.0",
47
47
  "vite": "^4.0.0"
48
48
  },
49
49
  "devDependencies": {
package/src/index.d.ts CHANGED
@@ -172,7 +172,7 @@ interface ExperimentalOptions {
172
172
  disableSvelteResolveWarnings?: boolean;
173
173
  }
174
174
 
175
- type ModuleFormat = NonNullable<CompileOptions['format']>;
175
+ type ModuleFormat = NonNullable<'esm'>;
176
176
  type CssHashGetter = NonNullable<CompileOptions['cssHash']>;
177
177
  type Arrayable<T> = T | T[];
178
178
 
package/src/index.js CHANGED
@@ -1,5 +1,4 @@
1
1
  import fs from 'fs';
2
- import { VERSION as svelteVersion } from 'svelte/compiler';
3
2
  import { version as viteVersion } from 'vite';
4
3
 
5
4
  import { svelteInspector } from '@sveltejs/vite-plugin-svelte-inspector';
@@ -25,9 +24,9 @@ import { saveSvelteMetadata } from './utils/optimizer.js';
25
24
  import { VitePluginSvelteCache } from './utils/vite-plugin-svelte-cache.js';
26
25
  import { loadRaw } from './utils/load-raw.js';
27
26
  import { FAQ_LINK_CONFLICTS_IN_SVELTE_RESOLVE } from './utils/constants.js';
27
+ import { isSvelte3 } from './utils/svelte-version.js';
28
28
 
29
29
  const isVite4_0 = viteVersion.startsWith('4.0');
30
- const isSvelte3 = svelteVersion.startsWith('3');
31
30
 
32
31
  /** @type {import('./index.d.ts').svelte} */
33
32
  export function svelte(inlineOptions) {
@@ -9,6 +9,8 @@ import { mapToRelative } from './sourcemaps.js';
9
9
 
10
10
  const scriptLangRE = /<script [^>]*lang=["']?([^"' >]+)["']?[^>]*>/;
11
11
 
12
+ import { isSvelte3 } from './svelte-version.js';
13
+
12
14
  /**
13
15
  * @param {Function} [makeHot]
14
16
  * @returns {import('../types/compile.d.ts').CompileSvelte}
@@ -51,9 +53,12 @@ export const _createCompileSvelte = (makeHot) => {
51
53
  const compileOptions = {
52
54
  ...options.compilerOptions,
53
55
  filename: normalizedFilename, // use normalized here to avoid bleeding absolute fs path
54
- generate: ssr ? 'ssr' : 'dom',
55
- format: 'esm'
56
+ generate: ssr ? 'ssr' : 'dom'
56
57
  };
58
+ if (isSvelte3) {
59
+ // @ts-ignore
60
+ compileOptions.format = 'esm';
61
+ }
57
62
  if (options.hot && options.emitCss) {
58
63
  const hash = `s-${safeBase64Hash(normalizedFilename)}`;
59
64
  log.debug(`setting cssHash ${hash} for ${normalizedFilename}`);
@@ -2,6 +2,7 @@ import { readFileSync } from 'fs';
2
2
  import { compile, preprocess } from 'svelte/compiler';
3
3
  import { log } from './log.js';
4
4
  import { toESBuildError } from './error.js';
5
+ import { isSvelte3 } from './svelte-version.js';
5
6
 
6
7
  /**
7
8
  * @typedef {NonNullable<import('vite').DepOptimizationOptions['esbuildOptions']>} EsbuildOptions
@@ -64,10 +65,12 @@ async function compileSvelte(options, { filename, code }, statsCollection) {
64
65
  ...options.compilerOptions,
65
66
  css,
66
67
  filename,
67
- format: 'esm',
68
68
  generate: 'dom'
69
69
  };
70
-
70
+ if (isSvelte3) {
71
+ // @ts-ignore
72
+ compileOptions.format = 'esm';
73
+ }
71
74
  let preprocessed;
72
75
 
73
76
  if (options.preprocess) {
@@ -1,45 +1,6 @@
1
1
  import { VERSION } from 'svelte/compiler';
2
- const svelteVersion = parseVersion(VERSION);
3
2
 
4
3
  /**
5
- * @param {string} version
6
- * @returns {number[]}
4
+ * @type {boolean}
7
5
  */
8
- export function parseVersion(version) {
9
- const segments = version.split('.', 3).map((s) => parseInt(s, 10));
10
- while (segments.length < 3) {
11
- segments.push(0);
12
- }
13
- return segments;
14
- }
15
-
16
- /**
17
- * compare version with current svelte, only takes major.minor.patch into account.
18
- * If you don't pass all three, values will be filled with 0, ie `3` is equal to `3.0.0`
19
- *
20
- * @param {string} version
21
- * @returns {1 | 0 | -1} 1 if passed version is larger than current, 0 if it is equal and -1 if it is lower
22
- */
23
- export function compareToSvelte(version) {
24
- const parsedVersion = parseVersion(version);
25
- for (let i = 0; i < svelteVersion.length; i++) {
26
- const a = parsedVersion[i];
27
- const b = svelteVersion[i];
28
- if (a === b) {
29
- continue;
30
- } else if (a > b) {
31
- return 1;
32
- } else {
33
- return -1;
34
- }
35
- }
36
- return 0;
37
- }
38
-
39
- /**
40
- * @param {string} version
41
- * @returns {boolean}
42
- */
43
- export function atLeastSvelte(version) {
44
- return compareToSvelte(version) <= 0;
45
- }
6
+ export const isSvelte3 = VERSION.startsWith('3.');