-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
fix: avoid concealing build errors #5520
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
Changes from all commits
56754ea
0e7bfe3
6405386
2f845d1
9ac7ca8
7c2e838
681d785
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| '@sveltejs/kit': patch | ||
| --- | ||
|
|
||
| fix: don't try adapting if build failed |
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
|
|
@@ -109,6 +109,12 @@ function kit() { | |||||||
| */ | ||||||||
| let paths; | ||||||||
|
|
||||||||
| /** @type {Error | undefined} */ | ||||||||
| let build_error; | ||||||||
|
|
||||||||
| /** @type {Error | undefined} */ | ||||||||
| let write_bundle_error; | ||||||||
|
|
||||||||
| function vite_client_config() { | ||||||||
| /** @type {Record<string, string>} */ | ||||||||
| const input = { | ||||||||
|
|
@@ -247,6 +253,9 @@ function kit() { | |||||||
| * Clears the output directories. | ||||||||
| */ | ||||||||
| buildStart() { | ||||||||
| // Reset errors in watch mode | ||||||||
| build_error = write_bundle_error = undefined; | ||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||
|
|
||||||||
| if (is_build) { | ||||||||
| rimraf(paths.build_dir); | ||||||||
| mkdirp(paths.build_dir); | ||||||||
|
|
@@ -256,6 +265,10 @@ function kit() { | |||||||
| } | ||||||||
| }, | ||||||||
|
|
||||||||
| buildEnd(err) { | ||||||||
| build_error = err; | ||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||
| }, | ||||||||
|
|
||||||||
| /** | ||||||||
| * Vite builds a single bundle. We need three bundles: client, server, and service worker. | ||||||||
| * The user's package.json scripts will invoke the Vite CLI to execute the client build. We | ||||||||
|
|
@@ -266,80 +279,86 @@ function kit() { | |||||||
| verbose: vite_config.logLevel === 'info' | ||||||||
| }); | ||||||||
|
|
||||||||
| fs.writeFileSync( | ||||||||
| `${paths.client_out_dir}/version.json`, | ||||||||
| JSON.stringify({ version: process.env.VITE_SVELTEKIT_APP_VERSION }) | ||||||||
| ); | ||||||||
| try { | ||||||||
| fs.writeFileSync( | ||||||||
| `${paths.client_out_dir}/version.json`, | ||||||||
| JSON.stringify({ version: process.env.VITE_SVELTEKIT_APP_VERSION }) | ||||||||
| ); | ||||||||
|
|
||||||||
| const { assets, chunks } = collect_output(bundle); | ||||||||
| log.info(`Client build completed. Wrote ${chunks.length} chunks and ${assets.length} assets`); | ||||||||
|
|
||||||||
| log.info('Building server'); | ||||||||
| const options = { | ||||||||
| cwd, | ||||||||
| config: svelte_config, | ||||||||
| vite_config_env, | ||||||||
| build_dir: paths.build_dir, // TODO just pass `paths` | ||||||||
| manifest_data, | ||||||||
| output_dir: paths.output_dir, | ||||||||
| service_worker_entry_file: resolve_entry(svelte_config.kit.files.serviceWorker) | ||||||||
| }; | ||||||||
| const client = client_build_info(assets, chunks); | ||||||||
| const server = await build_server(options, client); | ||||||||
|
|
||||||||
| /** @type {import('types').BuildData} */ | ||||||||
| build_data = { | ||||||||
| app_dir: svelte_config.kit.appDir, | ||||||||
| manifest_data, | ||||||||
| service_worker: options.service_worker_entry_file ? 'service-worker.js' : null, // TODO make file configurable? | ||||||||
| client, | ||||||||
| server | ||||||||
| }; | ||||||||
| const { assets, chunks } = collect_output(bundle); | ||||||||
| log.info( | ||||||||
| `Client build completed. Wrote ${chunks.length} chunks and ${assets.length} assets` | ||||||||
| ); | ||||||||
|
|
||||||||
| fs.writeFileSync( | ||||||||
| `${paths.output_dir}/server/manifest.js`, | ||||||||
| `export const manifest = ${generate_manifest({ | ||||||||
| build_data, | ||||||||
| relative_path: '.', | ||||||||
| routes: manifest_data.routes | ||||||||
| })};\n` | ||||||||
| ); | ||||||||
| log.info('Building server'); | ||||||||
| const options = { | ||||||||
| cwd, | ||||||||
| config: svelte_config, | ||||||||
| vite_config_env, | ||||||||
| build_dir: paths.build_dir, // TODO just pass `paths` | ||||||||
| manifest_data, | ||||||||
| output_dir: paths.output_dir, | ||||||||
| service_worker_entry_file: resolve_entry(svelte_config.kit.files.serviceWorker) | ||||||||
| }; | ||||||||
| const client = client_build_info(assets, chunks); | ||||||||
| const server = await build_server(options, client); | ||||||||
|
|
||||||||
| /** @type {import('types').BuildData} */ | ||||||||
| build_data = { | ||||||||
| app_dir: svelte_config.kit.appDir, | ||||||||
| manifest_data, | ||||||||
| service_worker: options.service_worker_entry_file ? 'service-worker.js' : null, // TODO make file configurable? | ||||||||
| client, | ||||||||
| server | ||||||||
| }; | ||||||||
|
|
||||||||
| fs.writeFileSync( | ||||||||
| `${paths.output_dir}/server/manifest.js`, | ||||||||
| `export const manifest = ${generate_manifest({ | ||||||||
| build_data, | ||||||||
| relative_path: '.', | ||||||||
| routes: manifest_data.routes | ||||||||
| })};\n` | ||||||||
| ); | ||||||||
|
|
||||||||
| process.env.SVELTEKIT_SERVER_BUILD_COMPLETED = 'true'; | ||||||||
| log.info('Prerendering'); | ||||||||
| process.env.SVELTEKIT_SERVER_BUILD_COMPLETED = 'true'; | ||||||||
| log.info('Prerendering'); | ||||||||
|
|
||||||||
| const static_files = manifest_data.assets.map((asset) => posixify(asset.file)); | ||||||||
| const static_files = manifest_data.assets.map((asset) => posixify(asset.file)); | ||||||||
|
|
||||||||
| const files = new Set([ | ||||||||
| ...static_files, | ||||||||
| ...chunks.map((chunk) => `${svelte_config.kit.appDir}/${chunk.fileName}`), | ||||||||
| ...assets.map((chunk) => `${svelte_config.kit.appDir}/${chunk.fileName}`) | ||||||||
| ]); | ||||||||
| const files = new Set([ | ||||||||
| ...static_files, | ||||||||
| ...chunks.map((chunk) => `${svelte_config.kit.appDir}/${chunk.fileName}`), | ||||||||
| ...assets.map((chunk) => `${svelte_config.kit.appDir}/${chunk.fileName}`) | ||||||||
| ]); | ||||||||
|
|
||||||||
| // TODO is this right? | ||||||||
| static_files.forEach((file) => { | ||||||||
| if (file.endsWith('/index.html')) { | ||||||||
| files.add(file.slice(0, -11)); | ||||||||
| } | ||||||||
| }); | ||||||||
| // TODO is this right? | ||||||||
| static_files.forEach((file) => { | ||||||||
| if (file.endsWith('/index.html')) { | ||||||||
| files.add(file.slice(0, -11)); | ||||||||
| } | ||||||||
| }); | ||||||||
|
|
||||||||
| prerendered = await prerender({ | ||||||||
| config: svelte_config.kit, | ||||||||
| entries: manifest_data.routes | ||||||||
| .map((route) => (route.type === 'page' ? route.path : '')) | ||||||||
| .filter(Boolean), | ||||||||
| files, | ||||||||
| log | ||||||||
| }); | ||||||||
|
|
||||||||
| if (options.service_worker_entry_file) { | ||||||||
| if (svelte_config.kit.paths.assets) { | ||||||||
| throw new Error('Cannot use service worker alongside config.kit.paths.assets'); | ||||||||
| } | ||||||||
|
|
||||||||
| prerendered = await prerender({ | ||||||||
| config: svelte_config.kit, | ||||||||
| entries: manifest_data.routes | ||||||||
| .map((route) => (route.type === 'page' ? route.path : '')) | ||||||||
| .filter(Boolean), | ||||||||
| files, | ||||||||
| log | ||||||||
| }); | ||||||||
| log.info('Building service worker'); | ||||||||
|
|
||||||||
| if (options.service_worker_entry_file) { | ||||||||
| if (svelte_config.kit.paths.assets) { | ||||||||
| throw new Error('Cannot use service worker alongside config.kit.paths.assets'); | ||||||||
| await build_service_worker(options, prerendered, client.vite_manifest); | ||||||||
| } | ||||||||
|
|
||||||||
| log.info('Building service worker'); | ||||||||
|
|
||||||||
| await build_service_worker(options, prerendered, client.vite_manifest); | ||||||||
| } catch (error) { | ||||||||
| throw (write_bundle_error = /** @type {Error} */ (error)); | ||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||
| } | ||||||||
|
|
||||||||
| console.log( | ||||||||
|
|
@@ -354,6 +373,11 @@ function kit() { | |||||||
| if (!is_build) { | ||||||||
| return; // vite calls closeBundle when dev-server restarts, ignore that | ||||||||
| } | ||||||||
|
|
||||||||
| if (build_error || write_bundle_error) { | ||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||
| return; // Do not try adapting if build failed | ||||||||
| } | ||||||||
|
|
||||||||
| if (svelte_config.kit.adapter) { | ||||||||
| const { adapt } = await import('../core/adapt/index.js'); | ||||||||
| await adapt(svelte_config, build_data, prerendered, { log }); | ||||||||
|
|
||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.