Skip to content

Commit

Permalink
Merge branch 'sveltejs:main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
nikosgram authored Dec 19, 2024
2 parents 70d808e + 6531e36 commit a3f4f1f
Show file tree
Hide file tree
Showing 32 changed files with 315 additions and 120 deletions.
12 changes: 12 additions & 0 deletions packages/adapter-cloudflare/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
# @sveltejs/adapter-cloudflare

## 4.9.0
### Minor Changes


- feat: generate `.assetsignore` file for use with Cloudflare Workers Static Assets ([#13109](https://github.com/sveltejs/kit/pull/13109))


### Patch Changes

- Updated dependencies [[`20f2720aa3455f38fa2630a33d52f7532da27fce`](https://github.com/sveltejs/kit/commit/20f2720aa3455f38fa2630a33d52f7532da27fce)]:
- @sveltejs/kit@2.13.0

## 4.8.0
### Minor Changes

Expand Down
12 changes: 12 additions & 0 deletions packages/adapter-cloudflare/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,8 @@ export default function (options = {}) {
}`
);
}

writeFileSync(`${dest}/.assetsignore`, generate_assetsignore(), { flag: 'a' });
},
async emulate() {
const proxy = await getPlatformProxy(options.platformProxy);
Expand Down Expand Up @@ -263,3 +265,13 @@ ${rules}
# === END AUTOGENERATED SVELTE PRERENDERED REDIRECTS ===
`.trimEnd();
}

function generate_assetsignore() {
// this comes from https://github.com/cloudflare/workers-sdk/blob/main/packages/create-cloudflare/templates-experimental/svelte/templates/static/.assetsignore
return `
_worker.js
_routes.json
_headers
_redirects
`;
}
2 changes: 1 addition & 1 deletion packages/adapter-cloudflare/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@sveltejs/adapter-cloudflare",
"version": "4.8.0",
"version": "4.9.0",
"description": "Adapter for building SvelteKit applications on Cloudflare Pages with Workers integration",
"keywords": [
"adapter",
Expand Down
2 changes: 1 addition & 1 deletion packages/adapter-netlify/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
"@netlify/functions": "^2.4.1",
"@rollup/plugin-commonjs": "^28.0.1",
"@rollup/plugin-json": "^6.1.0",
"@rollup/plugin-node-resolve": "^15.3.0",
"@rollup/plugin-node-resolve": "^16.0.0",
"@sveltejs/kit": "workspace:^",
"@sveltejs/vite-plugin-svelte": "^5.0.1",
"@types/node": "^18.19.48",
Expand Down
9 changes: 9 additions & 0 deletions packages/adapter-node/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
# @sveltejs/adapter-node

## 5.2.11
### Patch Changes


- chore(deps): update dependency @rollup/plugin-node-resolve to v16 ([#13164](https://github.com/sveltejs/kit/pull/13164))

- Updated dependencies [[`19823dd716568140011eaa86110bb8868f0e2513`](https://github.com/sveltejs/kit/commit/19823dd716568140011eaa86110bb8868f0e2513), [`5d30191d13a596bda50e27e54522c10f3f6461e3`](https://github.com/sveltejs/kit/commit/5d30191d13a596bda50e27e54522c10f3f6461e3)]:
- @sveltejs/kit@2.12.2

## 5.2.10
### Patch Changes

Expand Down
4 changes: 2 additions & 2 deletions packages/adapter-node/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@sveltejs/adapter-node",
"version": "5.2.10",
"version": "5.2.11",
"description": "Adapter for SvelteKit apps that generates a standalone Node server",
"keywords": [
"adapter",
Expand Down Expand Up @@ -53,7 +53,7 @@
"dependencies": {
"@rollup/plugin-commonjs": "^28.0.1",
"@rollup/plugin-json": "^6.1.0",
"@rollup/plugin-node-resolve": "^15.3.0",
"@rollup/plugin-node-resolve": "^16.0.0",
"rollup": "^4.9.5"
},
"peerDependencies": {
Expand Down
15 changes: 15 additions & 0 deletions packages/kit/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,20 @@
# @sveltejs/kit

## 2.13.0
### Minor Changes


- feat: add `bundleStrategy: 'split' | 'single'` option ([#13173](https://github.com/sveltejs/kit/pull/13173))

## 2.12.2
### Patch Changes


- fix: correctly resolve no hooks file when a similarly named directory exists ([#13188](https://github.com/sveltejs/kit/pull/13188))


- fix: correctly resolve `$app/state` on the server with Vite 5 ([#13192](https://github.com/sveltejs/kit/pull/13192))

## 2.12.1
### Patch Changes

Expand Down
2 changes: 1 addition & 1 deletion packages/kit/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@sveltejs/kit",
"version": "2.12.1",
"version": "2.13.0",
"description": "SvelteKit is the fastest way to build Svelte apps",
"keywords": [
"framework",
Expand Down
2 changes: 1 addition & 1 deletion packages/kit/scripts/generate-dts.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ await createBundle({
'$app/navigation': 'src/runtime/app/navigation.js',
'$app/paths': 'src/runtime/app/paths/types.d.ts',
'$app/server': 'src/runtime/app/server/index.js',
'$app/state': 'src/runtime/app/state/client.js',
'$app/state': 'src/runtime/app/state/index.js',
'$app/stores': 'src/runtime/app/stores.js'
},
include: ['src']
Expand Down
2 changes: 1 addition & 1 deletion packages/kit/src/core/config/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ const get_defaults = (prefix = '') => ({
},
inlineStyleThreshold: 0,
moduleExtensions: ['.js', '.ts'],
output: { preloadStrategy: 'modulepreload' },
output: { preloadStrategy: 'modulepreload', bundleStrategy: 'split' },
outDir: join(prefix, '.svelte-kit'),
serviceWorker: {
register: true
Expand Down
3 changes: 2 additions & 1 deletion packages/kit/src/core/config/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,8 @@ const options = object(
outDir: string('.svelte-kit'),

output: object({
preloadStrategy: list(['modulepreload', 'preload-js', 'preload-mjs'], 'modulepreload')
preloadStrategy: list(['modulepreload', 'preload-js', 'preload-mjs']),
bundleStrategy: list(['split', 'single'])
}),

paths: object({
Expand Down
9 changes: 9 additions & 0 deletions packages/kit/src/exports/public.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -498,6 +498,15 @@ export interface KitConfig {
* @since 1.8.4
*/
preloadStrategy?: 'modulepreload' | 'preload-js' | 'preload-mjs';
/**
* If `'split'`, splits the app up into multiple .js/.css files so that they are loaded lazily as the user navigates around the app. This is the default, and is recommended for most scenarios.
* If `'single'`, creates just one .js bundle and one .css file containing code for the entire app.
*
* When using `'split'`, you can also adjust the bundling behaviour by setting [`output.experimentalMinChunkSize`](https://rollupjs.org/configuration-options/#output-experimentalminchunksize) and [`output.manualChunks`](https://rollupjs.org/configuration-options/#output-manualchunks)inside your Vite config's [`build.rollupOptions`](https://vite.dev/config/build-options.html#build-rollupoptions).
* @default 'split'
* @since 2.13.0
*/
bundleStrategy?: 'split' | 'single';
};
paths?: {
/**
Expand Down
5 changes: 3 additions & 2 deletions packages/kit/src/exports/vite/build/build_server.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@ import { normalizePath } from 'vite';
* @param {import('vite').Manifest} server_manifest
* @param {import('vite').Manifest | null} client_manifest
* @param {import('vite').Rollup.OutputAsset[] | null} css
* @param {import('types').RecursiveRequired<import('types').ValidatedConfig['kit']['output']>} output_config
*/
export function build_server_nodes(out, kit, manifest_data, server_manifest, client_manifest, css) {
export function build_server_nodes(out, kit, manifest_data, server_manifest, client_manifest, css, output_config) {
mkdirp(`${out}/server/nodes`);
mkdirp(`${out}/server/stylesheets`);

Expand Down Expand Up @@ -69,7 +70,7 @@ export function build_server_nodes(out, kit, manifest_data, server_manifest, cli
exports.push(`export const server_id = ${s(node.server)};`);
}

if (client_manifest && (node.universal || node.component)) {
if (client_manifest && (node.universal || node.component) && output_config.bundleStrategy === 'split') {
const entry = find_deps(
client_manifest,
`${normalizePath(kit.outDir)}/generated/client-optimized/nodes/${i}.js`,
Expand Down
72 changes: 55 additions & 17 deletions packages/kit/src/exports/vite/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,10 @@ async function kit({ svelte_config }) {
name: 'vite-plugin-sveltekit-virtual-modules',

resolveId(id, importer) {
if (id === '__sveltekit/manifest') {
return `${kit.outDir}/generated/client-optimized/app.js`;
}

// If importing from a service-worker, only allow $service-worker & $env/static/public, but none of the other virtual modules.
// This check won't catch transitive imports, but it will warn when the import comes from a service-worker directly.
// Transitive imports will be caught during the build.
Expand Down Expand Up @@ -605,10 +609,11 @@ async function kit({ svelte_config }) {
const name = posixify(path.join('entries/matchers', key));
input[name] = path.resolve(file);
});
} else if (svelte_config.kit.output.bundleStrategy !== 'split') {
input['bundle'] = `${runtime_directory}/client/bundle.js`;
} else {
input['entry/start'] = `${runtime_directory}/client/entry.js`;
input['entry/app'] = `${kit.outDir}/generated/client-optimized/app.js`;

manifest_data.nodes.forEach((node, i) => {
if (node.component || node.universal) {
input[`nodes/${i}`] = `${kit.outDir}/generated/client-optimized/nodes/${i}.js`;
Expand Down Expand Up @@ -643,7 +648,9 @@ async function kit({ svelte_config }) {
chunkFileNames: ssr ? 'chunks/[name].js' : `${prefix}/chunks/[name].[hash].${ext}`,
assetFileNames: `${prefix}/assets/[name].[hash][extname]`,
hoistTransitiveImports: false,
sourcemapIgnoreList
sourcemapIgnoreList,
manualChunks:
svelte_config.kit.output.bundleStrategy === 'single' ? () => 'bundle' : undefined
},
preserveEntrySignatures: 'strict'
},
Expand Down Expand Up @@ -775,7 +782,15 @@ async function kit({ svelte_config }) {
// first, build server nodes without the client manifest so we can analyse it
log.info('Analysing routes');

build_server_nodes(out, kit, manifest_data, server_manifest, null, null);
build_server_nodes(
out,
kit,
manifest_data,
server_manifest,
null,
null,
svelte_config.output
);

const metadata = await analyse({
manifest_path,
Expand Down Expand Up @@ -825,19 +840,34 @@ async function kit({ svelte_config }) {

const deps_of = /** @param {string} f */ (f) =>
find_deps(client_manifest, posixify(path.relative('.', f)), false);
const start = deps_of(`${runtime_directory}/client/entry.js`);
const app = deps_of(`${kit.outDir}/generated/client-optimized/app.js`);

build_data.client = {
start: start.file,
app: app.file,
imports: [...start.imports, ...app.imports],
stylesheets: [...start.stylesheets, ...app.stylesheets],
fonts: [...start.fonts, ...app.fonts],
uses_env_dynamic_public: output.some(
(chunk) => chunk.type === 'chunk' && chunk.modules[env_dynamic_public]
)
};

if (svelte_config.kit.output.bundleStrategy === 'split') {
const start = deps_of(`${runtime_directory}/client/entry.js`);
const app = deps_of(`${kit.outDir}/generated/client-optimized/app.js`);

build_data.client = {
start: start.file,
app: app.file,
imports: [...start.imports, ...app.imports],
stylesheets: [...start.stylesheets, ...app.stylesheets],
fonts: [...start.fonts, ...app.fonts],
uses_env_dynamic_public: output.some(
(chunk) => chunk.type === 'chunk' && chunk.modules[env_dynamic_public]
)
};
} else {
const start = deps_of(`${runtime_directory}/client/bundle.js`);

build_data.client = {
start: start.file,
imports: start.imports,
stylesheets: start.stylesheets,
fonts: start.fonts,
uses_env_dynamic_public: output.some(
(chunk) => chunk.type === 'chunk' && chunk.modules[env_dynamic_public]
)
};
}

const css = output.filter(
/** @type {(value: any) => value is import('vite').Rollup.OutputAsset} */
Expand All @@ -855,7 +885,15 @@ async function kit({ svelte_config }) {
);

// regenerate nodes with the client manifest...
build_server_nodes(out, kit, manifest_data, server_manifest, client_manifest, css);
build_server_nodes(
out,
kit,
manifest_data,
server_manifest,
client_manifest,
css,
svelte_config.kit.output
);

// ...and prerender
const { prerendered, prerender_map } = await prerender({
Expand Down
36 changes: 0 additions & 36 deletions packages/kit/src/runtime/app/state/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,32 +5,6 @@ import {
} from '../../client/state.svelte.js';
import { stores } from '../../client/client.js';

/**
* A reactive object with information about the current page, serving several use cases:
* - retrieving the combined `data` of all pages/layouts anywhere in your component tree (also see [loading data](https://svelte.dev/docs/kit/load))
* - retrieving the current value of the `form` prop anywhere in your component tree (also see [form actions](https://svelte.dev/docs/kit/form-actions))
* - retrieving the page state that was set through `goto`, `pushState` or `replaceState` (also see [goto](https://svelte.dev/docs/kit/$app-navigation#goto) and [shallow routing](https://svelte.dev/docs/kit/shallow-routing))
* - retrieving metadata such as the URL you're on, the current route and its parameters, and whether or not there was an error
*
* ```svelte
* <!--- file: +layout.svelte --->
* <script>
* import { page } from '$app/state';
* </script>
*
* <p>Currently at {page.url.pathname}</p>
*
* {#if page.error}
* <span class="red">Problem detected</span>
* {:else}
* <span class="small">All systems operational</span>
* {/if}
* ```
*
* On the server, values can only be read during rendering (in other words _not_ in e.g. `load` functions). In the browser, the values can be read at any time.
*
* @type {import('@sveltejs/kit').Page}
*/
export const page = {
get data() {
return _page.data;
Expand Down Expand Up @@ -58,12 +32,6 @@ export const page = {
}
};

/**
* An object representing an in-progress navigation, with `from`, `to`, `type` and (if `type === 'popstate'`) `delta` properties.
* Values are `null` when no navigation is occurring, or during server rendering.
* @type {import('@sveltejs/kit').Navigation | { from: null, to: null, type: null, willUnload: null, delta: null, complete: null }}
*/
// @ts-expect-error
export const navigating = {
get from() {
return _navigating.current ? _navigating.current.from : null;
Expand Down Expand Up @@ -92,10 +60,6 @@ Object.defineProperty(navigating, 'current', {
}
});

/**
* A reactive value that's initially `false`. If [`version.pollInterval`](https://svelte.dev/docs/kit/configuration#version) is a non-zero value, SvelteKit will poll for new versions of the app and update `current` to `true` when it detects one. `updated.check()` will force an immediate check, regardless of polling.
* @type {{ get current(): boolean; check(): Promise<boolean>; }}
*/
export const updated = {
get current() {
return _updated.current;
Expand Down
Loading

0 comments on commit a3f4f1f

Please sign in to comment.