Skip to content

Commit

Permalink
fix: add optional chaining back to finalise hook (#8846)
Browse files Browse the repository at this point in the history
* fix: add optional chaining back to `finalise` hook

* add a test

* remove check task

* Update .changeset/grumpy-islands-collect.md

---------

Co-authored-by: Rich Harris <hello@rich-harris.dev>
  • Loading branch information
braebo and Rich-Harris authored Feb 2, 2023
1 parent 089c405 commit 7cdb7a6
Show file tree
Hide file tree
Showing 14 changed files with 120 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/grumpy-islands-collect.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@sveltejs/kit': patch
---

fix: preserve build error messages
2 changes: 1 addition & 1 deletion packages/kit/src/exports/vite/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -725,7 +725,7 @@ function kit({ svelte_config }) {
sequential: true,
async handler() {
if (!vite_config.build.ssr) return;
await finalise();
await finalise?.();
}
}
};
Expand Down
7 changes: 7 additions & 0 deletions packages/kit/test/build-errors/apps/syntax-error/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
.DS_Store
node_modules
/build
/.svelte-kit
/package
.env.*
!.env.example
1 change: 1 addition & 0 deletions packages/kit/test/build-errors/apps/syntax-error/.npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
engine-strict=true
18 changes: 18 additions & 0 deletions packages/kit/test/build-errors/apps/syntax-error/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"name": "syntax-error",
"version": "0.0.1",
"private": true,
"scripts": {
"dev": "vite dev",
"build": "vite build",
"preview": "vite preview"
},
"devDependencies": {
"@sveltejs/kit": "workspace:^",
"svelte": "^3.55.1",
"svelte-check": "^3.0.2",
"typescript": "^4.9.4",
"vite": "^4.0.4"
},
"type": "module"
}
12 changes: 12 additions & 0 deletions packages/kit/test/build-errors/apps/syntax-error/src/app.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<link rel="icon" href="%sveltekit.assets%/favicon.png" />
<meta name="viewport" content="width=device-width" />
%sveltekit.head%
</head>
<body>
<div>%sveltekit.body%</div>
</body>
</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const should_explode = 'boom';
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<div
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/** @type {import('@sveltejs/kit').Config} */
const config = {};

export default config;
19 changes: 19 additions & 0 deletions packages/kit/test/build-errors/apps/syntax-error/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"extends": "./.svelte-kit/tsconfig.json",
"compilerOptions": {
"allowJs": true,
"checkJs": true,
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"resolveJsonModule": true,
"skipLibCheck": true,
"sourceMap": true,
"strict": true,
"noEmit": true,
"paths": {
"types": ["../../../../types/internal"],
"$lib": ["./src/lib"],
"$lib/*": ["./src/lib/*"]
}
}
}
14 changes: 14 additions & 0 deletions packages/kit/test/build-errors/apps/syntax-error/vite.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { sveltekit } from '@sveltejs/kit/vite';
import path from 'path';

/** @type {import('vite').UserConfig} */
const config = {
plugins: [sveltekit()],
server: {
fs: {
allow: [path.resolve('../../../../src')]
}
}
};

export default config;
23 changes: 23 additions & 0 deletions packages/kit/test/build-errors/syntax-error.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { test } from 'uvu';
import * as assert from 'uvu/assert';
import { execSync } from 'node:child_process';
import path from 'node:path';

test('$lib/*.server.* is not statically importable from the client', () => {
try {
execSync('pnpm build', {
cwd: path.join(process.cwd(), 'apps/syntax-error'),
stdio: 'pipe',
timeout: 60000
});
} catch (err) {
assert.ok(
err.message.includes('Unexpected end of input'),
`received unexpected exception message ${err.message}`
);
return;
}
assert.unreachable();
});

test.run();
14 changes: 14 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 7cdb7a6

Please sign in to comment.