-
-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: separate generated from non-generated server code (#8429)
* rename node.server to node.has_server_load - more descriptive * rename core/prerender to core/postbuild * fix * move logic around * rename server/index.js to server/respond.js * move some logic around * move some stuff around * remove options.paths * move read to internal request options * remove version from SSROptions * tidy up * add note * tidy up * remove public_env from SSROptions * move logic to sync * notes to self * WIP * hack around the problem * oops * partial solution to stack traces * fix a few more tests * insane * use __SVELTEKIT_DEV__ instead of state.dev * fix * set globalThis.__SVELTEKIT_DEV__ * tidy some stuff up * add ambient declaration * set paths correctly * remove import * DRY * reduce indirection * use private fields * separate manifest from server configuration * tidy up * exclude SvelteKit deps from Vite processing * regenerate server-internal.js as necessary * tidy up * see if this fixes windows * of course it's a path separator issue * remove unused exports * tidy up, see if this still works in windows * remove some unused code * Create gorgeous-actors-run.md Co-authored-by: Simon Holthausen <[email protected]>
- Loading branch information
1 parent
b6c238a
commit efc2a4a
Showing
62 changed files
with
1,061 additions
and
1,002 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@sveltejs/kit": patch | ||
--- | ||
|
||
chore: separate generated from non-generated server code |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
import { writeFileSync } from 'fs'; | ||
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 { prerender } from './prerender.js'; | ||
|
||
const [, , client_out_dir, manifest_path, results_path, verbose, env] = process.argv; | ||
|
||
/** @type {import('types').SSRManifest} */ | ||
const manifest = (await import(pathToFileURL(manifest_path).href)).manifest; | ||
|
||
/** @type {import('types').PrerenderMap} */ | ||
const prerender_map = new Map(); | ||
|
||
/** @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); | ||
|
||
/** @type {import('types').ServerModule} */ | ||
const { Server } = await import(pathToFileURL(`${server_root}/server/index.js`).href); | ||
|
||
// configure `import { building } from '$app/environment'` — | ||
// essential we do this before analysing the code | ||
internal.set_building(true); | ||
|
||
// analyse routes | ||
for (const route of manifest._.routes) { | ||
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_map.set(route.id, mod.prerender); | ||
} | ||
} | ||
|
||
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) { | ||
validate_page_server_exports(page.server, route.id); | ||
validate_common_exports(page.universal, route.id); | ||
} | ||
|
||
const should_prerender = get_option(nodes, 'prerender'); | ||
const 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); | ||
|
||
prerender_map.set(route.id, prerender); | ||
} | ||
} | ||
|
||
const { prerendered } = await prerender({ | ||
Server, | ||
internal, | ||
manifest, | ||
prerender_map, | ||
client_out_dir, | ||
verbose, | ||
env | ||
}); | ||
|
||
writeFileSync( | ||
results_path, | ||
JSON.stringify({ prerendered, prerender_map }, (_key, value) => | ||
value instanceof Map ? Array.from(value.entries()) : value | ||
) | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.