Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
83d078b
make build phase explicit rather than using ssr as a proxy
Rich-Harris Jan 20, 2023
444ca6b
separate build_server from build_server_nodes
Rich-Harris Jan 20, 2023
ba6b26f
extract guard plugin
Rich-Harris Jan 20, 2023
044ac7d
simplify
Rich-Harris Jan 20, 2023
ec5879c
simplify
Rich-Harris Jan 20, 2023
d75f2a8
remove unused code
Rich-Harris Jan 20, 2023
6b92046
simplify
Rich-Harris Jan 20, 2023
f84029f
dont quite understand this but whatever
Rich-Harris Jan 20, 2023
ef261df
remove unused property
Rich-Harris Jan 21, 2023
dab55fd
simplify
Rich-Harris Jan 21, 2023
4f96848
simplify
Rich-Harris Jan 21, 2023
3fc24c1
reverse order
Rich-Harris Jan 21, 2023
cb4e981
refactor
Rich-Harris Jan 21, 2023
39419d5
remove
Rich-Harris Jan 21, 2023
a6fde15
Merge branch 'master' into gh-7967-part-three
Rich-Harris Jan 21, 2023
5425090
skip
Rich-Harris Jan 21, 2023
0803fd2
keep state local
Rich-Harris Jan 21, 2023
1ff19cd
use devalue for cross-process communication
Rich-Harris Jan 21, 2023
c2025cf
DRY
Rich-Harris Jan 21, 2023
2077f3b
separate analysis from prerendering
Rich-Harris Jan 22, 2023
c5026de
optimize client build
Rich-Harris Jan 22, 2023
3dac5f6
run all tests
Rich-Harris Jan 22, 2023
8c6a102
oops
Rich-Harris Jan 22, 2023
20988b5
fix illegal module guard
Rich-Harris Jan 22, 2023
2508919
simplify
Rich-Harris Jan 22, 2023
917a861
fix prerender_map
Rich-Harris Jan 22, 2023
95ce92f
simplify/tidy up
Rich-Harris Jan 22, 2023
c1f01ce
changeset
Rich-Harris Jan 23, 2023
0bd072c
merge index.js and prerender.js
Rich-Harris Jan 24, 2023
4c21ff2
comment for plugin_guard
Rich-Harris Jan 24, 2023
048079f
move read util to filesystem.js
Rich-Harris Jan 25, 2023
85d4c17
remove out of date comment
Rich-Harris Jan 25, 2023
0e925e6
tweak comment
Rich-Harris Jan 25, 2023
0479a49
chore: better cross-process communication (#8729)
Rich-Harris Jan 26, 2023
450a62d
fix
dummdidumm Jan 26, 2023
8b9ddec
see if this helps for turbo
dummdidumm Jan 26, 2023
c1b8208
temporarily disable turbo cache
dummdidumm Jan 26, 2023
068cbe8
try debug mac failure
dummdidumm Jan 26, 2023
3362df0
Revert "try debug mac failure"
dummdidumm Jan 26, 2023
e900343
Merge branch 'master' into gh-7967-part-three
dummdidumm Jan 26, 2023
f209e73
delay until ready (#8739)
Rich-Harris Jan 26, 2023
ead8fa8
belts and braces
dummdidumm Jan 26, 2023
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
5 changes: 5 additions & 0 deletions .changeset/heavy-poems-retire.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@sveltejs/kit': patch
---

fix: only fetch `__data.json` files for routes with a server `load` function
5 changes: 5 additions & 0 deletions .changeset/young-planes-flash.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@sveltejs/kit': patch
---

fix: install polyfills when analysing code
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
"description": "monorepo for @sveltejs/kit and friends",
"private": true,
"scripts": {
"test": "turbo run test --filter=./packages/*",
"test:cross-platform": "turbo run test:cross-platform --filter=./packages/*",
"test": "turbo run test --filter=./packages/* --force",
"test:cross-platform": "turbo run test:cross-platform --filter=./packages/* --force",
"test:vite-ecosystem-ci": "pnpm test --dir packages/kit",
"check": "turbo run check",
"lint": "turbo run lint",
"check": "turbo run check --force",
"lint": "turbo run lint --force",
"format": "turbo run format",
"precommit": "turbo run precommit",
"release": "changeset publish"
Expand Down
20 changes: 6 additions & 14 deletions packages/kit/src/core/adapt/builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,14 @@ const pipe = promisify(pipeline);
* @param {{
* config: import('types').ValidatedConfig;
* build_data: import('types').BuildData;
* server_metadata: import('types').ServerMetadata;
* routes: import('types').RouteData[];
* prerendered: import('types').Prerendered;
* log: import('types').Logger;
* }} opts
* @returns {import('types').Builder}
*/
export function create_builder({ config, build_data, routes, prerendered, log }) {
export function create_builder({ config, build_data, server_metadata, routes, prerendered, log }) {
return {
log,
rimraf,
Expand Down Expand Up @@ -53,18 +54,9 @@ export function create_builder({ config, build_data, routes, prerendered, log })
async createEntries(fn) {
/** @type {import('types').RouteDefinition[]} */
const facades = routes.map((route) => {
/** @type {Set<import('types').HttpMethod>} */
const methods = new Set();

if (route.page) {
methods.add('GET');
}

if (route.endpoint) {
for (const method of build_data.server.methods[route.endpoint.file]) {
methods.add(method);
}
}
const methods =
/** @type {import('types').HttpMethod[]} */
(server_metadata.routes.get(route.id)?.methods);

return {
id: route.id,
Expand All @@ -74,7 +66,7 @@ export function create_builder({ config, build_data, routes, prerendered, log })
content: segment
})),
pattern: route.pattern,
methods: Array.from(methods)
methods
};
});

Expand Down
2 changes: 2 additions & 0 deletions packages/kit/src/core/adapt/builder.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ test('copy files', () => {
config: /** @type {import('types').ValidatedConfig} */ (mocked),
// @ts-expect-error
build_data: {},
// @ts-expect-error
server_metadata: {},
routes: [],
// @ts-expect-error
prerendered: {
Expand Down
6 changes: 4 additions & 2 deletions packages/kit/src/core/adapt/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,20 @@ import { create_builder } from './builder.js';
/**
* @param {import('types').ValidatedConfig} config
* @param {import('types').BuildData} build_data
* @param {import('types').ServerMetadata} server_metadata
* @param {import('types').Prerendered} prerendered
* @param {import('types').PrerenderMap} prerender_map
* @param {{ log: import('types').Logger }} opts
* @param {import('types').Logger} log
*/
export async function adapt(config, build_data, prerendered, prerender_map, { log }) {
export async function adapt(config, build_data, server_metadata, prerendered, prerender_map, log) {
const { name, adapt } = config.kit.adapter;

console.log(colors.bold().cyan(`\n> Using ${name}`));

const builder = create_builder({
config,
build_data,
server_metadata,
routes: build_data.manifest_data.routes.filter((route) => {
if (!route.page && !route.endpoint) return false;

Expand Down
4 changes: 2 additions & 2 deletions packages/kit/src/core/generate_manifest/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ export function generate_manifest({ build_data, relative_path, routes }) {
assets: new Set(${s(assets)}),
mimeTypes: ${s(get_mime_lookup(build_data.manifest_data))},
_: {
entry: ${s(build_data.client.entry)},
entry: ${s(build_data.client_entry)},
nodes: [
${(node_paths).map(loader).join(',\n\t\t\t\t')}
],
Expand All @@ -103,7 +103,7 @@ export function generate_manifest({ build_data, relative_path, routes }) {
pattern: ${route.pattern},
params: ${s(route.params)},
page: ${route.page ? `{ layouts: ${get_nodes(route.page.layouts)}, errors: ${get_nodes(route.page.errors)}, leaf: ${reindexed.get(route.page.leaf)} }` : 'null'},
endpoint: ${route.endpoint ? loader(join_relative(relative_path, resolve_symlinks(build_data.server.vite_manifest, route.endpoint.file).chunk.file)) : 'null'}
endpoint: ${route.endpoint ? loader(join_relative(relative_path, resolve_symlinks(build_data.server_manifest, route.endpoint.file).chunk.file)) : 'null'}
}`;
}).filter(Boolean).join(',\n\t\t\t\t')}
],
Expand Down
135 changes: 135 additions & 0 deletions packages/kit/src/core/postbuild/analyse.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
import { join } from 'path';
import { pathToFileURL } from 'url';
import { get_option } from '../../runtime/server/utils.js';
import {
validate_common_exports,
validate_page_server_exports,
validate_server_exports
} from '../../utils/exports.js';
import { load_config } from '../config/index.js';
import { forked } from '../../utils/fork.js';
import { should_polyfill } from '../../utils/platform.js';
import { installPolyfills } from '../../exports/node/polyfills.js';

export default forked(import.meta.url, analyse);

/**
* @param {{
* manifest_path: string;
* env: Record<string, string>
* }} opts
*/
async function analyse({ manifest_path, env }) {
/** @type {import('types').SSRManifest} */
const manifest = (await import(pathToFileURL(manifest_path).href)).manifest;

/** @type {import('types').ValidatedKitConfig} */
const config = (await load_config()).kit;

const server_root = join(config.outDir, 'output');

/** @type {import('types').ServerInternalModule} */
const internal = await import(pathToFileURL(`${server_root}/server/internal.js`).href);

if (should_polyfill) {
installPolyfills();
}

// configure `import { building } from '$app/environment'` —
// essential we do this before analysing the code
internal.set_building(true);

// set env, in case it's used in initialisation
const entries = Object.entries(env);
const prefix = config.env.publicPrefix;
internal.set_private_env(Object.fromEntries(entries.filter(([k]) => !k.startsWith(prefix))));
internal.set_public_env(Object.fromEntries(entries.filter(([k]) => k.startsWith(prefix))));

/** @type {import('types').ServerMetadata} */
const metadata = {
nodes: [],
routes: new Map()
};

// analyse nodes
for (const loader of manifest._.nodes) {
const node = await loader();

metadata.nodes.push({
has_server_load: node.server?.load !== undefined
});
}

// analyse routes
for (const route of manifest._.routes) {
/** @type {Set<import('types').HttpMethod>} */
const methods = new Set();

/** @type {import('types').PrerenderOption | undefined} */
let prerender = undefined;

if (route.endpoint) {
const mod = await route.endpoint();
if (mod.prerender !== undefined) {
validate_server_exports(mod, route.id);

if (mod.prerender && (mod.POST || mod.PATCH || mod.PUT || mod.DELETE)) {
throw new Error(
`Cannot prerender a +server file with POST, PATCH, PUT, or DELETE (${route.id})`
);
}

prerender = mod.prerender;
}

if (mod.GET) methods.add('GET');
if (mod.POST) methods.add('POST');
if (mod.PUT) methods.add('PUT');
if (mod.PATCH) methods.add('PATCH');
if (mod.DELETE) methods.add('DELETE');
}

if (route.page) {
const nodes = await Promise.all(
[...route.page.layouts, route.page.leaf].map((n) => {
if (n !== undefined) return manifest._.nodes[n]();
})
);

const layouts = nodes.slice(0, -1);
const page = nodes.at(-1);

for (const layout of layouts) {
if (layout) {
validate_common_exports(layout.server, route.id);
validate_common_exports(layout.universal, route.id);
}
}

if (page) {
methods.add('GET');
if (page.server?.actions) methods.add('POST');

validate_page_server_exports(page.server, route.id);
validate_common_exports(page.universal, route.id);
}

const should_prerender = get_option(nodes, 'prerender');
prerender =
should_prerender === true ||
// Try prerendering if ssr is false and no server needed. Set it to 'auto' so that
// the route is not removed from the manifest, there could be a server load function.
// People can opt out of this behavior by explicitly setting prerender to false
(should_prerender !== false && get_option(nodes, 'ssr') === false && !page?.server?.actions
? 'auto'
: should_prerender ?? false);
}

metadata.routes.set(route.id, {
prerender,
methods: Array.from(methods)
});
}

return metadata;
}
113 changes: 0 additions & 113 deletions packages/kit/src/core/postbuild/index.js

This file was deleted.

Loading