From 88fe84d1e7b29f6b1209106de03fc36bdb790adf Mon Sep 17 00:00:00 2001 From: Miroslav Jonas Date: Fri, 28 Jun 2024 15:21:07 +0200 Subject: [PATCH 1/4] feat: enable cwd override for vite plugin --- packages/kit/src/exports/vite/index.js | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/packages/kit/src/exports/vite/index.js b/packages/kit/src/exports/vite/index.js index 2280025bcc62..44a221a1fa76 100644 --- a/packages/kit/src/exports/vite/index.js +++ b/packages/kit/src/exports/vite/index.js @@ -35,8 +35,6 @@ import { } from './module_ids.js'; import { resolve_peer_dependency } from '../../utils/import.js'; -const cwd = process.cwd(); - /** @type {import('./types.js').EnforcedConfig} */ const enforced_config = { appType: true, @@ -126,8 +124,8 @@ const warning_preprocessor = { * Returns the SvelteKit Vite plugins. * @returns {Promise} */ -export async function sveltekit() { - const svelte_config = await load_config(); +export async function sveltekit({ cwd = process.cwd() } = {}) { + const svelte_config = await load_config({ cwd }); /** @type {import('@sveltejs/vite-plugin-svelte').Options['preprocess']} */ let preprocess = svelte_config.preprocess; @@ -154,7 +152,7 @@ export async function sveltekit() { const { svelte } = await resolve_peer_dependency('@sveltejs/vite-plugin-svelte'); - return [...svelte(vite_plugin_svelte_options), ...(await kit({ svelte_config }))]; + return [...svelte(vite_plugin_svelte_options), ...(await kit({ svelte_config }, cwd))]; } // These variables live outside the `kit()` function because it is re-invoked by each Vite build @@ -177,7 +175,7 @@ let manifest_data; * @param {{ svelte_config: import('types').ValidatedConfig }} options * @return {Promise} */ -async function kit({ svelte_config }) { +async function kit({ svelte_config }, cwd = process.cwd()) { const vite = await resolve_peer_dependency('vite'); const { kit } = svelte_config; @@ -519,7 +517,7 @@ async function kit({ svelte_config }) { if (vite_config.build.ssr) return; const guard = module_guard(this, { - cwd: vite.normalizePath(process.cwd()), + cwd: vite.normalizePath(cwd), lib: vite.normalizePath(kit.files.lib) }); @@ -935,7 +933,7 @@ function warn_overridden_config(config, resolved_config) { if (overridden.length > 0) { console.error( colors.bold().red('The following Vite config options will be overridden by SvelteKit:') + - overridden.map((key) => `\n - ${key}`).join('') + overridden.map((key) => `\n - ${key}`).join('') ); } } @@ -979,9 +977,9 @@ const create_service_worker_module = (config) => dedent` export const build = []; export const files = [ ${create_assets(config) - .filter((asset) => config.kit.serviceWorker.files(asset.file)) - .map((asset) => `${s(`${config.kit.paths.base}/${asset.file}`)}`) - .join(',\n')} + .filter((asset) => config.kit.serviceWorker.files(asset.file)) + .map((asset) => `${s(`${config.kit.paths.base}/${asset.file}`)}`) + .join(',\n')} ]; export const prerendered = []; export const version = ${s(config.kit.version.name)}; From 783415c7ef95410949b65afaecb93f7e3b9b693f Mon Sep 17 00:00:00 2001 From: Miroslav Jonas Date: Fri, 28 Jun 2024 15:31:20 +0200 Subject: [PATCH 2/4] chore: add changeset --- .changeset/long-buckets-cheer.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/long-buckets-cheer.md diff --git a/.changeset/long-buckets-cheer.md b/.changeset/long-buckets-cheer.md new file mode 100644 index 000000000000..cf4b707c50a6 --- /dev/null +++ b/.changeset/long-buckets-cheer.md @@ -0,0 +1,5 @@ +--- +'@sveltejs/kit': major +--- + +Enable overriding working dir when using vite plugin From 4e63a0594e315ab56b1791438e7e7bcb8f36f9ec Mon Sep 17 00:00:00 2001 From: Miroslav Jonas Date: Fri, 28 Jun 2024 15:33:51 +0200 Subject: [PATCH 3/4] docs: add api documention --- packages/kit/src/exports/vite/index.js | 8 ++++---- packages/kit/types/index.d.ts | 4 +++- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/packages/kit/src/exports/vite/index.js b/packages/kit/src/exports/vite/index.js index 44a221a1fa76..1857192a2f48 100644 --- a/packages/kit/src/exports/vite/index.js +++ b/packages/kit/src/exports/vite/index.js @@ -933,7 +933,7 @@ function warn_overridden_config(config, resolved_config) { if (overridden.length > 0) { console.error( colors.bold().red('The following Vite config options will be overridden by SvelteKit:') + - overridden.map((key) => `\n - ${key}`).join('') + overridden.map((key) => `\n - ${key}`).join('') ); } } @@ -977,9 +977,9 @@ const create_service_worker_module = (config) => dedent` export const build = []; export const files = [ ${create_assets(config) - .filter((asset) => config.kit.serviceWorker.files(asset.file)) - .map((asset) => `${s(`${config.kit.paths.base}/${asset.file}`)}`) - .join(',\n')} + .filter((asset) => config.kit.serviceWorker.files(asset.file)) + .map((asset) => `${s(`${config.kit.paths.base}/${asset.file}`)}`) + .join(',\n')} ]; export const prerendered = []; export const version = ${s(config.kit.version.name)}; diff --git a/packages/kit/types/index.d.ts b/packages/kit/types/index.d.ts index e3bf549b2407..c53654e3de03 100644 --- a/packages/kit/types/index.d.ts +++ b/packages/kit/types/index.d.ts @@ -1944,7 +1944,9 @@ declare module '@sveltejs/kit/vite' { /** * Returns the SvelteKit Vite plugins. * */ - export function sveltekit(): Promise; + export function sveltekit({ cwd }?: { + cwd?: string | undefined; + }): Promise; } declare module '$app/environment' { From dec9864c73d248b4074a896f2ae8f51b96530a56 Mon Sep 17 00:00:00 2001 From: Miroslav Jonas Date: Fri, 5 Jul 2024 14:34:07 +0200 Subject: [PATCH 4/4] fix: change to minor --- .changeset/long-buckets-cheer.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.changeset/long-buckets-cheer.md b/.changeset/long-buckets-cheer.md index cf4b707c50a6..ab030b55fdd9 100644 --- a/.changeset/long-buckets-cheer.md +++ b/.changeset/long-buckets-cheer.md @@ -1,5 +1,5 @@ --- -'@sveltejs/kit': major +'@sveltejs/kit': minor --- Enable overriding working dir when using vite plugin