Skip to content

Commit

Permalink
[fix] update to TS 4.4.3 (#2432)
Browse files Browse the repository at this point in the history
  • Loading branch information
dummdidumm committed Sep 15, 2021
1 parent b02ea03 commit d8efaa2
Show file tree
Hide file tree
Showing 21 changed files with 206 additions and 87 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
"playwright-chromium": "^1.10.0",
"prettier": "2.2.1",
"rollup": "^2.55.0",
"typescript": "^4.3.5"
"typescript": "^4.4.3"
},
"type": "module"
}
2 changes: 1 addition & 1 deletion packages/create-svelte/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"prettier-plugin-svelte": "^2.2.0",
"sucrase": "^3.18.1",
"svelte": "^3.42.4",
"svelte-preprocess": "^4.7.3",
"svelte-preprocess": "^4.9.0",
"tiny-glob": "^0.2.8"
},
"scripts": {
Expand Down
4 changes: 2 additions & 2 deletions packages/create-svelte/shared/+typescript/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
"check:watch": "svelte-check --tsconfig ./tsconfig.json --watch"
},
"devDependencies": {
"typescript": "^4.0.0",
"typescript": "^4.4.0",
"tslib": "^2.0.0",
"svelte-check": "^2.0.0",
"svelte-preprocess": "^4.0.0"
"svelte-preprocess": "^4.9.0"
}
}
4 changes: 2 additions & 2 deletions packages/create-svelte/templates/default/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
"@sveltejs/adapter-vercel": "next",
"@sveltejs/kit": "next",
"svelte": "^3.42.4",
"svelte-preprocess": "^4.7.3",
"typescript": "^4.3.5"
"svelte-preprocess": "^4.9.0",
"typescript": "^4.4.0"
},
"type": "module",
"dependencies": {
Expand Down
2 changes: 1 addition & 1 deletion packages/kit/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
"selfsigned": "^1.10.11",
"sirv": "^1.0.12",
"svelte": "^3.42.4",
"svelte-check": "^2.2.4",
"svelte-check": "^2.2.6",
"svelte2tsx": "~0.4.1",
"tiny-glob": "^0.2.8",
"uvu": "^0.5.1"
Expand Down
19 changes: 12 additions & 7 deletions packages/kit/src/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import colors from 'kleur';
import * as ports from 'port-authority';
import { load_config } from './core/config/index.js';
import { networkInterfaces, release } from 'os';
import { coalesce_to_error, has_error_code } from './utils/error.js';

async function get_config() {
// TODO this is temporary, for the benefit of early adopters
Expand All @@ -23,11 +24,12 @@ async function get_config() {

try {
return await load_config();
} catch (error) {
} catch (err) {
const error = coalesce_to_error(err);
let message = error.message;

if (
error.code === 'MODULE_NOT_FOUND' &&
has_error_code(error, 'MODULE_NOT_FOUND') &&
/Cannot find module svelte\.config\./.test(error.message)
) {
message = 'Missing svelte.config.js';
Expand All @@ -36,16 +38,19 @@ async function get_config() {
}

console.error(colors.bold().red(message));
console.error(colors.grey(error.stack));
if (error.stack) {
console.error(colors.grey(error.stack));
}
process.exit(1);
}
}

/** @param {Error} error */
/** @param {unknown} error */
function handle_error(error) {
console.log(colors.bold().red(`> ${error.message}`));
if (error.stack) {
console.log(colors.gray(error.stack));
const err = coalesce_to_error(error);
console.log(colors.bold().red(`> ${err.message}`));
if (err.stack) {
console.log(colors.gray(err.stack));
}
process.exit(1);
}
Expand Down
2 changes: 1 addition & 1 deletion packages/kit/src/core/config/test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ test('errors on loading config with incorrect default export', async () => {
try {
const cwd = join(__dirname, 'fixtures', 'export-string');
await load_config({ cwd });
} catch (e) {
} catch (/** @type {any} */ e) {
errorMessage = e.message;
}

Expand Down
8 changes: 5 additions & 3 deletions packages/kit/src/core/dev/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import { getRawBody } from '../node/index.js';
import { get_server } from '../server/index.js';
import { SVELTE_KIT, SVELTE_KIT_ASSETS } from '../constants.js';
import { copy_assets, resolve_entry } from '../utils.js';
import { coalesce_to_error } from '../../utils/error.js';

/** @typedef {{ cwd?: string, port: number, host?: string, https: boolean, config: import('types/config').ValidatedConfig }} Options */
/** @typedef {import('types/internal').SSRComponent} SSRComponent */
Expand Down Expand Up @@ -334,7 +335,7 @@ async function create_handler(vite, config, dir, cwd, get_manifest) {

try {
body = await getRawBody(req);
} catch (err) {
} catch (/** @type {any} */ err) {
res.statusCode = err.status || 400;
return res.end(err.reason || 'Invalid request body');
}
Expand Down Expand Up @@ -486,9 +487,10 @@ async function create_handler(vite, config, dir, cwd, get_manifest) {
not_found(res);
}
} catch (e) {
vite.ssrFixStacktrace(e);
const error = coalesce_to_error(e);
vite.ssrFixStacktrace(error);
res.statusCode = 500;
res.end(e.stack);
res.end(error.stack);
}
});
};
Expand Down
2 changes: 1 addition & 1 deletion packages/kit/src/core/preview/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ export async function preview({

try {
body = await getRawBody(req);
} catch (err) {
} catch (/** @type {any} */ err) {
res.statusCode = err.status || 400;
return res.end(err.reason || 'Invalid request body');
}
Expand Down
6 changes: 3 additions & 3 deletions packages/kit/src/runtime/client/renderer.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { writable } from 'svelte/store';
import { coalesce_to_error } from '../../utils/error.js';
import { hash } from '../hash.js';
import { normalize } from '../load.js';
import { coalesce_to_error } from '../utils.js';

/**
* @typedef {import('types/internal').CSRComponent} CSRComponent
Expand Down Expand Up @@ -181,7 +181,7 @@ export class Renderer {
result = error_args
? await this._load_error(error_args)
: await this._get_navigation_result_from_branch({ page, branch });
} catch (/** @type {unknown} */ e) {
} catch (e) {
if (error) throw e;

result = await this._load_error({
Expand Down Expand Up @@ -637,7 +637,7 @@ export class Renderer {
}
} catch (e) {
status = 500;
error = e;
error = coalesce_to_error(e);
}

if (error) {
Expand Down
2 changes: 1 addition & 1 deletion packages/kit/src/runtime/server/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import { render_response } from './page/render.js';
import { respond_with_error } from './page/respond_with_error.js';
import { parse_body } from './parse_body/index.js';
import { lowercase_keys } from './utils.js';
import { coalesce_to_error } from '../utils.js';
import { hash } from '../hash.js';
import { get_single_valued_header } from '../../utils/http.js';
import { coalesce_to_error } from '../../utils/error.js';

/** @type {import('@sveltejs/kit/ssr').Respond} */
export async function respond(incoming, options, state = {}) {
Expand Down
3 changes: 2 additions & 1 deletion packages/kit/src/runtime/server/page/render.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import devalue from 'devalue';
import { writable } from 'svelte/store';
import { coalesce_to_error } from '../../../utils/error.js';
import { hash } from '../../hash.js';

const s = JSON.stringify;
Expand Down Expand Up @@ -203,7 +204,7 @@ function try_serialize(data, fail) {
try {
return devalue(data);
} catch (err) {
if (fail) fail(err);
if (fail) fail(coalesce_to_error(err));
return null;
}
}
Expand Down
10 changes: 5 additions & 5 deletions packages/kit/src/runtime/server/page/respond.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { render_response } from './render.js';
import { load_node } from './load_node.js';
import { is_prerender_enabled, respond_with_error } from './respond_with_error.js';
import { coalesce_to_error } from '../../utils.js';
import { coalesce_to_error } from '../../../utils/error.js';

/**
* @typedef {import('./types.js').Loaded} Loaded
Expand Down Expand Up @@ -30,7 +30,7 @@ export async function respond(opts) {

try {
nodes = await Promise.all(route.a.map((id) => (id ? options.load_component(id) : undefined)));
} catch (/** @type {unknown} */ err) {
} catch (err) {
const error = coalesce_to_error(err);

options.handle_error(error, request);
Expand Down Expand Up @@ -111,7 +111,7 @@ export async function respond(opts) {
if (loaded.loaded.error) {
({ status, error } = loaded.loaded);
}
} catch (/** @type {unknown} */ err) {
} catch (err) {
const e = coalesce_to_error(err);

options.handle_error(e, request);
Expand Down Expand Up @@ -156,7 +156,7 @@ export async function respond(opts) {
page_config = get_page_config(error_node.module, options);
branch = branch.slice(0, j + 1).concat(error_loaded);
break ssr;
} catch (/** @type {unknown} */ err) {
} catch (err) {
const e = coalesce_to_error(err);

options.handle_error(e, request);
Expand Down Expand Up @@ -204,7 +204,7 @@ export async function respond(opts) {
}),
set_cookie_headers
);
} catch (/** @type {unknown} */ err) {
} catch (err) {
const error = coalesce_to_error(err);

options.handle_error(error, request);
Expand Down
4 changes: 2 additions & 2 deletions packages/kit/src/runtime/server/page/respond_with_error.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { render_response } from './render.js';
import { load_node } from './load_node.js';
import { coalesce_to_error } from '../../utils.js';
import { coalesce_to_error } from '../../../utils/error.js';

/**
* @typedef {import('./types.js').Loaded} Loaded
Expand Down Expand Up @@ -78,7 +78,7 @@ export async function respond_with_error({ request, options, state, $session, st
branch,
page
});
} catch (/** @type {unknown} */ err) {
} catch (err) {
const error = coalesce_to_error(err);

options.handle_error(error, request);
Expand Down
7 changes: 0 additions & 7 deletions packages/kit/src/runtime/utils.js

This file was deleted.

19 changes: 19 additions & 0 deletions packages/kit/src/utils/error.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/**
* @param {unknown} err
* @return {Error}
*/
export function coalesce_to_error(err) {
return err instanceof Error ||
(err && /** @type {any} */ (err).name && /** @type {any} */ (err).message)
? /** @type {Error} */ (err)
: new Error(JSON.stringify(err));
}

/**
* @param {Error} err
* @param {any} errorCode
* @return {err is Error & {code: any}}
*/
export function has_error_code(err, errorCode = undefined) {
return 'code' in err && (errorCode === undefined || /** @type {any} */ (err).code === errorCode);
}
2 changes: 1 addition & 1 deletion packages/kit/src/utils/filesystem.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import path from 'path';
export function mkdirp(dir) {
try {
fs.mkdirSync(dir, { recursive: true });
} catch (e) {
} catch (/** @type {any} */ e) {
if (e.code === 'EEXIST') return;
throw e;
}
Expand Down
2 changes: 1 addition & 1 deletion packages/kit/test/apps/basics/src/routes/errors/_tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export default function (test, is_dev) {
try {
// ???
// await visit('/errors/clientside');
} catch (error) {
} catch (/** @type {any} */ error) {
assert.ok(/Crashing now/.test(error.message));
} finally {
// this is the Snowpack error overlay
Expand Down
2 changes: 1 addition & 1 deletion packages/kit/test/apps/basics/src/routes/routing/_tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ export default function (test, is_dev) {
try {
await app.prefetch('https://example.com');
throw new Error('Error was not thrown');
} catch (e) {
} catch (/** @type {any} */ e) {
assert.ok(
e.message.includes('Attempted to prefetch a URL that does not belong to this app')
);
Expand Down
2 changes: 1 addition & 1 deletion packages/kit/test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ async function main() {
try {
context.watcher = await dev({ cwd, port, config, host: undefined, https: false });
Object.assign(context, await setup({ port }));
} catch (e) {
} catch (/** @type {any} */ e) {
console.log(e.stack);
throw e;
}
Expand Down
Loading

0 comments on commit d8efaa2

Please sign in to comment.