Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

breaking: upgrade to TypeScript 5 #11160

Merged
merged 13 commits into from
Dec 1, 2023
5 changes: 0 additions & 5 deletions .changeset/itchy-bags-lay.md

This file was deleted.

5 changes: 5 additions & 0 deletions .changeset/silent-mayflies-burn.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@sveltejs/kit': major
---

breaking: upgrade to TypeScript 5 and default `moduleResolution` to `bundler` in user projects
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
"playwright": "1.30.0",
"prettier": "^3.1.0",
"svelte": "^4.2.7",
"typescript": "^4.9.4"
"typescript": "^5.3.2"
},
"packageManager": "[email protected]",
"engines": {
Expand Down
2 changes: 1 addition & 1 deletion packages/adapter-auto/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"devDependencies": {
"@sveltejs/kit": "workspace:^",
"@types/node": "^16.18.6",
"typescript": "^4.9.4"
"typescript": "^5.3.2"
},
"dependencies": {
"import-meta-resolve": "^4.0.0"
Expand Down
2 changes: 1 addition & 1 deletion packages/adapter-cloudflare-workers/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
"devDependencies": {
"@cloudflare/kv-asset-handler": "^0.3.0",
"@types/node": "^16.18.6",
"typescript": "^4.9.4"
"typescript": "^5.3.2"
},
"peerDependencies": {
"@sveltejs/kit": "^1.0.0"
Expand Down
2 changes: 1 addition & 1 deletion packages/adapter-cloudflare/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
"devDependencies": {
"@types/node": "^16.18.6",
"@types/ws": "^8.5.3",
"typescript": "^4.9.4"
"typescript": "^5.3.2"
},
"peerDependencies": {
"@sveltejs/kit": "^1.0.0"
Expand Down
4 changes: 2 additions & 2 deletions packages/adapter-netlify/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,15 @@
"set-cookie-parser": "^2.6.0"
},
"devDependencies": {
"@netlify/functions": "^2.0.1",
"@netlify/functions": "^2.4.0",
"@rollup/plugin-commonjs": "^25.0.7",
"@rollup/plugin-json": "^6.0.1",
"@rollup/plugin-node-resolve": "^15.2.3",
"@sveltejs/kit": "workspace:^",
"@types/node": "^16.18.6",
"@types/set-cookie-parser": "^2.4.2",
"rollup": "^4.2.0",
"typescript": "^4.9.4",
"typescript": "^5.3.2",
"vitest": "^0.34.5"
},
"peerDependencies": {
Expand Down
1 change: 1 addition & 0 deletions packages/adapter-netlify/rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ const config = {
dir: 'files/esm',
format: 'esm'
},
// @ts-ignore https://github.com/rollup/plugins/issues/1329
plugins: [nodeResolve({ preferBuiltins: true }), commonjs(), json()],
external: (id) => id === '0SERVER' || id.startsWith('node:'),
preserveEntrySignatures: 'exports-only'
Expand Down
8 changes: 4 additions & 4 deletions packages/adapter-netlify/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
"noEmit": true,
"noImplicitAny": true,
"target": "es2022",
"module": "es2022",
// `@netlify/function` > `@netlify/serverless-functions-api` types are not compatible,
// so using this moduleResolution for now
"moduleResolution": "node",
"module": "node16",
"moduleResolution": "node16",
// https://github.com/netlify/functions/issues/447
"skipLibCheck": true,
"allowSyntheticDefaultImports": true,
"baseUrl": ".",
"paths": {
Expand Down
2 changes: 2 additions & 0 deletions packages/adapter-node/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,9 @@ export default function (opts = {}) {
preferBuiltins: true,
exportConditions: ['node']
}),
// @ts-ignore https://github.com/rollup/plugins/issues/1329
commonjs({ strictRequires: true }),
// @ts-ignore https://github.com/rollup/plugins/issues/1329
json()
]
});
Expand Down
2 changes: 1 addition & 1 deletion packages/adapter-node/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
"c8": "^8.0.0",
"polka": "^1.0.0-next.23",
"sirv": "^2.0.3",
"typescript": "^4.9.4",
"typescript": "^5.3.2",
"vitest": "^0.34.5"
},
"dependencies": {
Expand Down
1 change: 1 addition & 0 deletions packages/adapter-node/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export const path = env('SOCKET_PATH', false);
export const host = env('HOST', '0.0.0.0');
export const port = env('PORT', !path && '3000');

// @ts-ignore - https://github.com/lukeed/polka/issues/199
const server = polka().use(handler);

server.listen({ path, host, port }, () => {
Expand Down
7 changes: 2 additions & 5 deletions packages/adapter-node/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,8 @@
"noImplicitAny": true,
"allowSyntheticDefaultImports": true,
"target": "es2022",
"module": "es2022",
// Can't use moduleResolution: node16 because of these issues:
// https://github.com/rollup/plugins/issues/1329
// https://github.com/lukeed/polka/issues/199
"moduleResolution": "node",
"module": "node16",
"moduleResolution": "node16",
"baseUrl": ".",
"paths": {
"@sveltejs/kit": ["../kit/types/index"]
Expand Down
1 change: 1 addition & 0 deletions packages/adapter-static/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ See https://kit.svelte.dev/docs/page-options#prerender for more details`
}

const {
// @ts-ignore
pages = 'build',
assets = pages,
fallback,
Expand Down
2 changes: 1 addition & 1 deletion packages/adapter-static/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
"@types/node": "^16.18.6",
"sirv": "^2.0.3",
"svelte": "^4.2.7",
"typescript": "^4.9.4",
"typescript": "^5.3.2",
"vite": "^5.0.4"
},
"peerDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion packages/adapter-vercel/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
"devDependencies": {
"@sveltejs/kit": "workspace:^",
"@types/node": "^16.18.6",
"typescript": "^4.9.4",
"typescript": "^5.3.2",
"vitest": "^0.34.5"
},
"peerDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion packages/create-svelte/templates/default/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"@sveltejs/adapter-auto": "workspace:*",
"@sveltejs/kit": "workspace:*",
"svelte": "^4.2.7",
"typescript": "^5.0.0",
"typescript": "^5.3.2",
"vite": "^5.0.4"
},
"type": "module",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"publint": "^0.1.9",
"svelte": "^4.2.7",
"tslib": "^2.4.1",
"typescript": "^5.0.0",
"typescript": "^5.3.2",
"vite": "^5.0.3"
},
"svelte": "./dist/index.js",
Expand Down
5 changes: 3 additions & 2 deletions packages/enhanced-img/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,15 @@
"dependencies": {
"magic-string": "^0.30.0",
"svelte-parse-markup": "^0.1.1",
"vite-imagetools": "^6.2.5"
"vite-imagetools": "^6.2.6"
},
"devDependencies": {
"@types/estree": "^1.0.2",
"@types/node": "^16.18.6",
"estree-walker": "^3.0.3",
"rollup": "^4.2.0",
"svelte": "^4.2.7",
"typescript": "^4.9.4",
"typescript": "^5.3.2",
"vite": "^5.0.4",
"vitest": "^0.34.0"
}
Expand Down
4 changes: 2 additions & 2 deletions packages/enhanced-img/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
"noEmit": true,
"strict": true,
"target": "es2022",
"module": "es2022",
"moduleResolution": "node",
"module": "node16",
"moduleResolution": "node16",
"allowSyntheticDefaultImports": true,
"paths": {
"types": ["./types/index"],
Expand Down
4 changes: 2 additions & 2 deletions packages/kit/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@
"@types/node": "^16.18.6",
"@types/sade": "^1.7.4",
"@types/set-cookie-parser": "^2.4.2",
"dts-buddy": "^0.2.4",
"dts-buddy": "^0.4.0",
"rollup": "^4.2.0",
"svelte": "^4.2.7",
"svelte-preprocess": "^5.1.1",
"typescript": "^4.9.4",
"typescript": "^5.3.2",
"vite": "^5.0.4",
"vitest": "^0.34.5"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/kit/src/core/sync/write_tsconfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ export function get_tsconfig(kit, include_base_url) {
// This is required for svelte-package to work as expected
// Can be overwritten
lib: ['esnext', 'DOM', 'DOM.Iterable'],
moduleResolution: 'node', // TODO change to "bundler" in SvelteKit v2
moduleResolution: 'bundler',
module: 'esnext',
noEmit: true, // prevent tsconfig error "overwriting input files" - Vite handles the build and ignores this
target: 'esnext',
Expand Down
2 changes: 2 additions & 0 deletions packages/kit/src/core/sync/write_tsconfig.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ test('Allows generated tsconfig to be mutated', () => {

const config = get_tsconfig(kit, false);

// @ts-expect-error
assert.equal(config.extends, 'some/other/tsconfig.json');
});

Expand All @@ -82,6 +83,7 @@ test('Allows generated tsconfig to be replaced', () => {

const config = get_tsconfig(kit, false);

// @ts-expect-error
assert.equal(config.extends, 'some/other/tsconfig.json');
});

Expand Down
1 change: 1 addition & 0 deletions packages/kit/src/core/sync/write_types/test/package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"private": true,
"type": "module",
"scripts": {
"testtypes": "tsc"
}
Expand Down
4 changes: 2 additions & 2 deletions packages/kit/src/core/sync/write_types/test/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
"checkJs": true,
"noEmit": true,
"strict": true,
"target": "es2020",
"target": "es2022",
"module": "es2022",
"moduleResolution": "node",
"moduleResolution": "bundler",
"allowSyntheticDefaultImports": true,
"baseUrl": ".",
"paths": {
Expand Down
4 changes: 2 additions & 2 deletions packages/kit/src/exports/vite/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ const options_regex = /(export\s+const\s+(prerender|csr|ssr|trailingSlash))\s*=/
/** @type {Set<string>} */
const warned = new Set();

/** @type {import('@sveltejs/vite-plugin-svelte').PreprocessorGroup} */
/** @type {import('svelte/compiler').PreprocessorGroup} */
const warning_preprocessor = {
script: ({ content, filename }) => {
if (!filename) return;
Expand Down Expand Up @@ -630,7 +630,7 @@ function kit({ svelte_config }) {
scoped(
assets,
sirv(join(svelte_config.kit.outDir, 'output/client'), {
setHeaders: (res, pathname) => {
setHeaders: (res, pathname) => {
// only apply to immutable directory, not e.g. version.json
if (pathname.startsWith(`/${svelte_config.kit.appDir}/immutable`)) {
res.setHeader('cache-control', 'public,max-age=31536000,immutable');
Expand Down
98 changes: 48 additions & 50 deletions packages/kit/src/exports/vite/preview/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,69 +60,67 @@ export async function preview(vite, vite_config, svelte_config) {

// prerendered pages (we can't just use sirv because we need to
// preserve the correct trailingSlash behaviour)
vite.middlewares.use(
(req, res, next) => {
let if_none_match_value = req.headers['if-none-match'];
vite.middlewares.use((req, res, next) => {
let if_none_match_value = req.headers['if-none-match'];

if (if_none_match_value?.startsWith('W/"')) {
if_none_match_value = if_none_match_value.substring(2);
}
if (if_none_match_value?.startsWith('W/"')) {
if_none_match_value = if_none_match_value.substring(2);
}

if (if_none_match_value === etag) {
res.statusCode = 304;
res.end();
return;
}
if (if_none_match_value === etag) {
res.statusCode = 304;
res.end();
return;
}

const { pathname, search } = new URL(/** @type {string} */ (req.url), 'http://dummy');

let filename = normalizePath(
join(svelte_config.kit.outDir, 'output/prerendered/pages' + pathname)
);
let prerendered = is_file(filename);

if (!prerendered) {
const has_trailing_slash = pathname.endsWith('/');
const html_filename = `${filename}${has_trailing_slash ? 'index.html' : '.html'}`;

/** @type {string | undefined} */
let redirect;

if (is_file(html_filename)) {
filename = html_filename;
prerendered = true;
} else if (has_trailing_slash) {
if (is_file(filename.slice(0, -1) + '.html')) {
redirect = pathname.slice(0, -1);
}
} else if (is_file(filename + '/index.html')) {
redirect = pathname + '/';
}
const { pathname, search } = new URL(/** @type {string} */ (req.url), 'http://dummy');

let filename = normalizePath(
join(svelte_config.kit.outDir, 'output/prerendered/pages' + pathname)
);
let prerendered = is_file(filename);

if (redirect) {
if (search) redirect += search;
res.writeHead(307, {
location: redirect
});
if (!prerendered) {
const has_trailing_slash = pathname.endsWith('/');
const html_filename = `${filename}${has_trailing_slash ? 'index.html' : '.html'}`;

res.end();
/** @type {string | undefined} */
let redirect;

return;
if (is_file(html_filename)) {
filename = html_filename;
prerendered = true;
} else if (has_trailing_slash) {
if (is_file(filename.slice(0, -1) + '.html')) {
redirect = pathname.slice(0, -1);
}
} else if (is_file(filename + '/index.html')) {
redirect = pathname + '/';
}

if (prerendered) {
res.writeHead(200, {
'content-type': lookup(pathname) || 'text/html',
etag
if (redirect) {
if (search) redirect += search;
res.writeHead(307, {
location: redirect
});

fs.createReadStream(filename).pipe(res);
} else {
next();
res.end();

return;
}
}
);

if (prerendered) {
res.writeHead(200, {
'content-type': lookup(pathname) || 'text/html',
etag
});

fs.createReadStream(filename).pipe(res);
} else {
next();
}
});

// SSR
vite.middlewares.use(async (req, res) => {
Expand Down
Loading
Loading