Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .prettierrc
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,15 @@
"**/vite.config.js.timestamp-*",
"**/.svelte-kit/**",
"**/.custom-out-dir/**",
"**/build/**",
"**/test-results/**",
"**/.wrangler/**",
"documentation/**/*.md",
"packages/package/test/fixtures/**/expected/**/*",
"packages/package/test/watch/expected/**/*",
"packages/package/test/watch/package/**/*",
"packages/kit/src/core/postbuild/fixtures/**/*",
"packages/adapter-cloudflare/test/apps/workers/dist/**/*"
"packages/adapter-cloudflare/test/apps/workers/dist/**/*",
"packages/*/test/**/build"
],
"options": {
"rangeEnd": 0

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What the heck is up with this? Why aren't these files just ignored if we're formatting 0% of them?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like maybe it's some kind of a performance hack? (#13058) Perhaps @dominikg knows more

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rangeEnd 0 makes prettier read the first 0 bytes, so not read the file at all.

this is a way to define ignores in prettier config rather than a separate .prettierignore

Expand Down
5 changes: 2 additions & 3 deletions packages/kit/.prettierignore

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a way we could do this with a negative pattern? i.e. ignore **/build/** and do !packages/kit/src/exports/vite/build/build_server.js?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doing just !packages/kit/src/exports/vite/build/build_server.js seems risky because as soon as you add a second file in the directory you'd be surprised it wasn't getting formatted. I'd want to at least do !packages/kit/src/exports/vite/build

Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
test/build-errors/apps/syntax-error/src/routes/+page.svelte
/types
src/runtime/components/svelte-5/layout.svelte
/src/runtime/components/svelte-5/layout.svelte
.svelte-kit
.custom-out-dir
build
test-results
/test/apps/basics/test/errors.json
/test/build-errors/apps/syntax-error/src/routes/+page.svelte
37 changes: 26 additions & 11 deletions packages/kit/src/exports/vite/build/build_server.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import { normalizePath } from 'vite';
import { basename, join } from 'node:path';
import { create_node_analyser } from '../static_analysis/index.js';


/**
* @param {string} out
* @param {import('types').ValidatedKitConfig} kit
Expand All @@ -18,7 +17,17 @@ import { create_node_analyser } from '../static_analysis/index.js';
* @param {import('types').RecursiveRequired<import('types').ValidatedConfig['kit']['output']>} output_config
* @param {Map<string, { page_options: Record<string, any> | null, children: string[] }>} static_exports
*/
export async function build_server_nodes(out, kit, manifest_data, server_manifest, client_manifest, server_bundle, client_chunks, output_config, static_exports) {
export async function build_server_nodes(
out,
kit,
manifest_data,
server_manifest,
client_manifest,
server_bundle,
client_chunks,
output_config,
static_exports
) {
mkdirp(`${out}/server/nodes`);
mkdirp(`${out}/server/stylesheets`);

Expand All @@ -37,7 +46,7 @@ export async function build_server_nodes(out, kit, manifest_data, server_manifes
}
client_stylesheet.forEach((file, i) => {
stylesheets_to_inline.set(file, server_stylesheet[i]);
})
});
}

// filter out stylesheets that should not be inlined
Expand All @@ -60,7 +69,9 @@ export async function build_server_nodes(out, kit, manifest_data, server_manifes
const { get_page_options } = create_node_analyser({
resolve: (server_node) => {
// Windows needs the file:// protocol for absolute path dynamic imports
return import(`file://${join(out, 'server', resolve_symlinks(server_manifest, server_node).chunk.file)}`);
return import(
`file://${join(out, 'server', resolve_symlinks(server_manifest, server_node).chunk.file)}`
);
},
static_exports
});
Expand Down Expand Up @@ -97,7 +108,7 @@ export async function build_server_nodes(out, kit, manifest_data, server_manifes
if (node.universal) {
const page_options = await get_page_options(node);
if (!!page_options && page_options.ssr === false) {
exports.push(`export const universal = ${s(page_options, null, 2)};`)
exports.push(`export const universal = ${s(page_options, null, 2)};`);
} else {
imports.push(
`import * as universal from '../${resolve_symlinks(server_manifest, node.universal).chunk.file}';`
Expand All @@ -116,14 +127,18 @@ export async function build_server_nodes(out, kit, manifest_data, server_manifes
exports.push(`export const server_id = ${s(node.server)};`);
}

if (client_manifest && (node.universal || node.component) && output_config.bundleStrategy === 'split') {
if (
client_manifest &&
(node.universal || node.component) &&
output_config.bundleStrategy === 'split'
) {
const entry_path = `${normalizePath(kit.outDir)}/generated/client-optimized/nodes/${i}.js`;
const entry = find_deps(client_manifest, entry_path, true);

// eagerly load client stylesheets and fonts imported by the SSR-ed page to avoid FOUC.
// However, if it is not used during SSR (not present in the server manifest),
// then it can be lazily loaded in the browser.

/** @type {import('types').AssetDependencies | undefined} */
let component;
if (node.component) {
Expand All @@ -149,8 +164,8 @@ export async function build_server_nodes(out, kit, manifest_data, server_manifes
}

if (component?.stylesheet_map.has(filepath) || universal?.stylesheet_map.has(filepath)) {
value.css.forEach(file => eager_css.add(file));
value.assets.forEach(file => eager_assets.add(file));
value.css.forEach((file) => eager_css.add(file));
value.assets.forEach((file) => eager_assets.add(file));
}
});

Expand Down Expand Up @@ -196,7 +211,7 @@ export async function build_server_nodes(out, kit, manifest_data, server_manifes
}

/**
* @param {(import('vite').Rollup.OutputAsset | import('vite').Rollup.OutputChunk)[]} chunks
* @param {(import('vite').Rollup.OutputAsset | import('vite').Rollup.OutputChunk)[]} chunks
*/
function get_stylesheets(chunks) {
/**
Expand All @@ -222,7 +237,7 @@ function get_stylesheets(chunks) {
if (chunk.viteMetadata?.importedCss.size) {
const css = Array.from(chunk.viteMetadata.importedCss);
for (const id of chunk.moduleIds) {
stylesheets_used.set(id, css );
stylesheets_used.set(id, css);
}
}
}
Expand Down
14 changes: 9 additions & 5 deletions packages/kit/src/exports/vite/build/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,17 @@ export function find_deps(manifest, entry, add_dynamic_css) {
if (add_js) imports.add(chunk.file);

if (chunk.assets) {
chunk.assets.forEach(asset => imported_assets.add(asset));
chunk.assets.forEach((asset) => imported_assets.add(asset));
}

if (chunk.css) {
chunk.css.forEach((file) => stylesheets.add(file));
}

if (chunk.imports) {
chunk.imports.forEach((file) => traverse(file, add_js, initial_importer, dynamic_import_depth));
chunk.imports.forEach((file) =>
traverse(file, add_js, initial_importer, dynamic_import_depth)
);
}

if (!add_dynamic_css) return;
Expand All @@ -58,7 +60,9 @@ export function find_deps(manifest, entry, add_dynamic_css) {
// a transitive dependency, it doesn't have a suitable name we can map back to
// the server manifest
if (stylesheet_map.has(initial_importer)) {
const { css, assets } = /** @type {{ css: Set<string>; assets: Set<string> }} */ (stylesheet_map.get(initial_importer));
const { css, assets } = /** @type {{ css: Set<string>; assets: Set<string> }} */ (
stylesheet_map.get(initial_importer)
);
if (chunk.css) chunk.css.forEach((file) => css.add(file));
if (chunk.assets) chunk.assets.forEach((file) => assets.add(file));
} else {
Expand Down Expand Up @@ -111,14 +115,14 @@ export function resolve_symlinks(manifest, file) {
}

/**
* @param {string[]} assets
* @param {string[]} assets
* @returns {string[]}
*/
export function filter_fonts(assets) {
return assets.filter((asset) => /\.(woff2?|ttf|otf)$/.test(asset));
}

const method_names = new Set((['GET', 'HEAD', 'PUT', 'POST', 'DELETE', 'PATCH', 'OPTIONS']));
const method_names = new Set(['GET', 'HEAD', 'PUT', 'POST', 'DELETE', 'PATCH', 'OPTIONS']);

// If we'd written this in TypeScript, it could be easy...
/**
Expand Down
Loading