Skip to content

Commit

Permalink
breaking: remove support for svelte3 (#746)
Browse files Browse the repository at this point in the history
* chore(node): drop support for 14 and 16

* chore(updates): remove support for svelte 3
  • Loading branch information
dominikg authored Sep 15, 2023
1 parent d5b952f commit 10ec2a4
Show file tree
Hide file tree
Showing 8 changed files with 12 additions and 60 deletions.
6 changes: 6 additions & 0 deletions .changeset/grumpy-planets-crash.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@sveltejs/vite-plugin-svelte-inspector': major
'@sveltejs/vite-plugin-svelte': major
---

breaking: remove support for svelte 3
8 changes: 1 addition & 7 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,9 @@ jobs:
matrix:
node: [18]
os: [ubuntu-latest, macos-latest, windows-latest]
svelte: [4]
include:
- node: 20
os: ubuntu-latest
svelte: 4
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v3
Expand All @@ -91,10 +89,6 @@ jobs:
PNPM_VER=$(jq -r '.packageManager | if .[0:5] == "pnpm@" then .[5:] else "packageManager in package.json does not start with pnpm@\n" | halt_error(1) end' package.json)
echo installing pnpm version $PNPM_VER
npm i -g pnpm@$PNPM_VER
- name: use svelte 3
if: matrix.svelte == 3
run: |
tmppkg="$(jq '.devDependencies.svelte = "^3.59.2"' package.json)" && echo -E "${tmppkg}" > package.json && tmppkg=""
- uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node }}
Expand All @@ -113,7 +107,7 @@ jobs:
- uses: actions/upload-artifact@v3
if: failure()
with:
name: test-failure-${{github.run_id}}-${{ matrix.os }}-${{ matrix.node }}-${{ matrix.svelte }}
name: test-failure-${{github.run_id}}-${{ matrix.os }}-${{ matrix.node }}
path: |
test-temp.tar
pnpm-debug.log
2 changes: 1 addition & 1 deletion packages/vite-plugin-svelte-inspector/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
},
"peerDependencies": {
"@sveltejs/vite-plugin-svelte": "^2.2.0",
"svelte": "^3.54.0 || ^4.0.0",
"svelte": "^4.0.0",
"vite": "^5.0.0-beta.1 || ^5.0.0"
},
"devDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion packages/vite-plugin-svelte/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
"vitefu": "^0.2.4"
},
"peerDependencies": {
"svelte": "^3.54.0 || ^4.0.0",
"svelte": "^4.0.0",
"vite": "^5.0.0-beta.1 || ^5.0.0"
},
"devDependencies": {
Expand Down
25 changes: 0 additions & 25 deletions packages/vite-plugin-svelte/src/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import fs from 'node:fs';
import { version as viteVersion } from 'vite';

import { svelteInspector } from '@sveltejs/vite-plugin-svelte-inspector';

Expand All @@ -24,9 +23,6 @@ import { saveSvelteMetadata } from './utils/optimizer.js';
import { VitePluginSvelteCache } from './utils/vite-plugin-svelte-cache.js';
import { loadRaw } from './utils/load-raw.js';
import { FAQ_LINK_CONFLICTS_IN_SVELTE_RESOLVE } from './utils/constants.js';
import { isSvelte3 } from './utils/svelte-version.js';

const isVite4_0 = viteVersion.startsWith('4.0');

/** @type {import('./index.d.ts').svelte} */
export function svelte(inlineOptions) {
Expand All @@ -47,8 +43,6 @@ export function svelte(inlineOptions) {
let compileSvelte;
/* eslint-enable no-unused-vars */

/** @type {Promise<import('vite').Rollup.PartialResolvedId | null>} */
let resolvedSvelteSSR;
/** @type {Set<string>} */
let packagesWithResolveWarnings;
/** @type {import('./types/plugin-api.d.ts').PluginAPI} */
Expand Down Expand Up @@ -145,25 +139,6 @@ export function svelte(inlineOptions) {
}
}

// TODO: remove this after bumping peerDep on Vite to 4.1+ or Svelte to 4.0+
if (isVite4_0 && isSvelte3 && ssr && importee === 'svelte') {
if (!resolvedSvelteSSR) {
resolvedSvelteSSR = this.resolve('svelte/ssr', undefined, { skipSelf: true }).then(
(svelteSSR) => {
log.debug('resolved svelte to svelte/ssr');
return svelteSSR;
},
(err) => {
log.debug(
'failed to resolve svelte to svelte/ssr. Update svelte to a version that exports it',
err
);
return null; // returning null here leads to svelte getting resolved regularly
}
);
}
return resolvedSvelteSSR;
}
//@ts-expect-error scan
const scan = !!opts?.scan; // scanner phase of optimizeDeps
const isPrebundled =
Expand Down
16 changes: 1 addition & 15 deletions packages/vite-plugin-svelte/src/utils/compile.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ import { mapToRelative } from './sourcemaps.js';

const scriptLangRE = /<script [^>]*lang=["']?([^"' >]+)["']?[^>]*>/;

import { isSvelte3 } from './svelte-version.js';

/**
* @param {Function} [makeHot]
* @returns {import('../types/compile.d.ts').CompileSvelte}
Expand Down Expand Up @@ -55,10 +53,7 @@ export const _createCompileSvelte = (makeHot) => {
filename,
generate: ssr ? 'ssr' : 'dom'
};
if (isSvelte3) {
// @ts-ignore
compileOptions.format = 'esm';
}

if (options.hot && options.emitCss) {
const hash = `s-${safeBase64Hash(normalizedFilename)}`;
log.debug(`setting cssHash ${hash} for ${normalizedFilename}`);
Expand Down Expand Up @@ -125,15 +120,6 @@ export const _createCompileSvelte = (makeHot) => {
const endStat = stats?.start(filename);
const compiled = compile(finalCode, finalCompileOptions);

if (isSvelte3) {
// prevent dangling pure comments
// see https://github.com/sveltejs/kit/issues/9492#issuecomment-1487704985
// uses regex replace with whitespace to keep sourcemap/character count unmodified
compiled.js.code = compiled.js.code.replace(
/\/\* [@#]__PURE__ \*\/(\s*)$/gm,
' $1'
);
}
if (endStat) {
endStat();
}
Expand Down
7 changes: 1 addition & 6 deletions packages/vite-plugin-svelte/src/utils/constants.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import { isSvelte3 } from './svelte-version.js';

export const VITE_RESOLVE_MAIN_FIELDS = ['module', 'jsnext:main', 'jsnext'];

export const SVELTE_RESOLVE_MAIN_FIELDS = ['svelte'];
Expand All @@ -8,16 +6,13 @@ export const SVELTE_IMPORTS = [
'svelte/animate',
'svelte/easing',
'svelte/internal',
'svelte/internal/disclose-version',
'svelte/motion',
'svelte/ssr',
'svelte/store',
'svelte/transition',
'svelte'
];
// TODO add to global list after dropping svelte 3
if (!isSvelte3) {
SVELTE_IMPORTS.push('svelte/internal/disclose-version');
}

export const SVELTE_HMR_IMPORTS = [
'svelte-hmr/runtime/hot-api-esm.js',
Expand Down
6 changes: 1 addition & 5 deletions packages/vite-plugin-svelte/src/utils/esbuild.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { readFileSync } from 'node:fs';
import { compile, preprocess } from 'svelte/compiler';
import { log } from './log.js';
import { toESBuildError } from './error.js';
import { isSvelte3 } from './svelte-version.js';

/**
* @typedef {NonNullable<import('vite').DepOptimizationOptions['esbuildOptions']>} EsbuildOptions
Expand Down Expand Up @@ -67,10 +66,7 @@ async function compileSvelte(options, { filename, code }, statsCollection) {
filename,
generate: 'dom'
};
if (isSvelte3) {
// @ts-ignore
compileOptions.format = 'esm';
}

let preprocessed;

if (options.preprocess) {
Expand Down

0 comments on commit 10ec2a4

Please sign in to comment.