Skip to content
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

[chore] return config from server start methods #5043

Merged
merged 2 commits into from
May 24, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
5 changes: 5 additions & 0 deletions .changeset/fresh-sheep-help.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@sveltejs/kit': patch
---

[chore] get base from Vite server for welcome message
29 changes: 12 additions & 17 deletions packages/kit/src/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,25 +61,23 @@ prog
/** @type {() => Promise<void>} */
let close;

/** @param {import('types').ValidatedConfig} config */
async function start(config) {
async function start() {
const { dev } = await import('./core/dev/index.js');

const { address_info, server_config, close } = await dev({
const { address_info, config, close } = await dev({
port,
host,
https,
config
https
});

welcome({
port: address_info.port,
host: address_info.address,
https: !!(https || server_config.https),
open: first && (open || !!server_config.open),
base: config.kit.paths.base,
loose: server_config.fs.strict === false,
allow: server_config.fs.allow
https: !!(https || config.server.https),
open: first && (open || !!config.server.open),
base: config.base,
Rich-Harris marked this conversation as resolved.
Show resolved Hide resolved
loose: config.server.fs.strict === false,
allow: config.server.fs.allow
});

first = false;
Expand All @@ -92,9 +90,8 @@ prog
relaunching = true;

try {
const updated_config = await load_config();
await close();
close = await start(updated_config);
close = await start();

if (id !== uid) relaunch();
} catch (e) {
Expand All @@ -114,8 +111,7 @@ prog

process.env.NODE_ENV = process.env.NODE_ENV || 'development';

const config = await load_config();
close = await start(config);
close = await start();

chokidar.watch('svelte.config.js', { ignoreInitial: true }).on('change', () => {
if (relaunching) uid += 1;
Expand Down Expand Up @@ -178,13 +174,12 @@ prog
await check_port(port);

process.env.NODE_ENV = process.env.NODE_ENV || 'production';
const config = await load_config();

const { preview } = await import('./core/preview/index.js');

await preview({ port, host, config, https });
const server = await preview({ port, host, https });

welcome({ port, host, https, open, base: config.kit.paths.base });
welcome({ port, host, https, open, base: server.config.base });
} catch (error) {
handle_error(error);
}
Expand Down
10 changes: 6 additions & 4 deletions packages/kit/src/core/dev/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import path from 'path';
import { svelte } from '@sveltejs/vite-plugin-svelte';
import * as vite from 'vite';
import { deep_merge } from '../../utils/object.js';
import { print_config_conflicts } from '../config/index.js';
import { load_config, print_config_conflicts } from '../config/index.js';
import { get_aliases, get_runtime_path } from '../utils.js';
import { create_plugin } from './plugin.js';
import * as sync from '../sync/sync.js';
Expand All @@ -14,13 +14,15 @@ const cwd = process.cwd();
* port: number,
* host?: string,
* https: boolean,
* config: import('types').ValidatedConfig
* }} Options
* @typedef {import('types').SSRComponent} SSRComponent
*/

/** @param {Options} opts */
export async function dev({ port, host, https, config }) {
export async function dev({ port, host, https }) {
/** @type {import('types').ValidatedConfig} */
const config = await load_config();

sync.init(config);

const [vite_config] = deep_merge(
Expand Down Expand Up @@ -104,7 +106,7 @@ export async function dev({ port, host, https, config }) {

return {
address_info,
server_config: vite_config.server,
config: server.config,
close: () => server.close()
};
}
5 changes: 3 additions & 2 deletions packages/kit/src/core/preview/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import sirv from 'sirv';
import { pathToFileURL } from 'url';
import { getRequest, setResponse } from '../../node/index.js';
import { installPolyfills } from '../../node/polyfills.js';
import { load_config } from '../config/index.js';
import { SVELTE_KIT_ASSETS } from '../constants.js';

/** @typedef {import('http').IncomingMessage} Req */
Expand All @@ -28,14 +29,14 @@ const mutable = (dir) =>
* @param {{
* port: number;
* host?: string;
* config: import('types').ValidatedConfig;
* https?: boolean;
* cwd?: string;
* }} opts
*/
export async function preview({ port, host, config, https: use_https = false }) {
export async function preview({ port, host, https: use_https = false }) {
installPolyfills();

const config = await load_config();
const { paths } = config.kit;
const base = paths.base;
const assets = paths.assets ? SVELTE_KIT_ASSETS : paths.base;
Expand Down