Skip to content

Commit

Permalink
chore: use peer dependencies rather than dev dependencies (#11433)
Browse files Browse the repository at this point in the history
* chore: use peer dependencies rather than dev dependencies

* changeset

* move to dependencies

---------

Co-authored-by: Rich Harris <rich.harris@vercel.com>
  • Loading branch information
Rich-Harris and Rich-Harris committed Jan 8, 2024
1 parent 1a1e786 commit 0679801
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 5 deletions.
5 changes: 5 additions & 0 deletions .changeset/smart-timers-promise.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@sveltejs/kit': patch
---

chore: use peer dependencies when linked
1 change: 1 addition & 0 deletions packages/kit/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"cookie": "^0.6.0",
"devalue": "^4.3.2",
"esm-env": "^1.0.0",
"import-meta-resolve": "^4.0.0",
"kleur": "^4.1.5",
"magic-string": "^0.30.5",
"mrmime": "^2.0.0",
Expand Down
25 changes: 20 additions & 5 deletions packages/kit/src/exports/vite/index.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import fs from 'node:fs';
import path from 'node:path';

import { svelte } from '@sveltejs/vite-plugin-svelte';
import * as imr from 'import-meta-resolve';
import colors from 'kleur';
import * as vite from 'vite';

import { copy, mkdirp, posixify, read, resolve_entry, rimraf } from '../../utils/filesystem.js';
import { create_static_module, create_dynamic_module } from '../../core/env.js';
Expand Down Expand Up @@ -34,6 +33,7 @@ import {
sveltekit_environment,
sveltekit_paths
} from './module_ids.js';
import { pathToFileURL } from 'node:url';

const cwd = process.cwd();

Expand Down Expand Up @@ -122,6 +122,17 @@ const warning_preprocessor = {
}
};

/**
* Resolve a dependency relative to the current working directory,
* rather than relative to this package
* @param {string} dependency
*/
async function resolve_peer_dependency(dependency) {
// @ts-expect-error the types are wrong
const resolved = await imr.resolve(dependency, pathToFileURL(process.cwd() + '/dummy.js'));
return import(resolved);
}

/**
* Returns the SvelteKit Vite plugins.
* @returns {Promise<import('vite').Plugin[]>}
Expand Down Expand Up @@ -153,7 +164,9 @@ export async function sveltekit() {
...svelte_config.vitePlugin
};

return [...svelte(vite_plugin_svelte_options), ...kit({ svelte_config })];
const { svelte } = await resolve_peer_dependency('@sveltejs/vite-plugin-svelte');

return [...svelte(vite_plugin_svelte_options), ...(await kit({ svelte_config }))];
}

// These variables live outside the `kit()` function because it is re-invoked by each Vite build
Expand All @@ -174,9 +187,11 @@ let manifest_data;
* - https://rollupjs.org/guide/en/#output-generation-hooks
*
* @param {{ svelte_config: import('types').ValidatedConfig }} options
* @return {import('vite').Plugin[]}
* @return {Promise<import('vite').Plugin[]>}
*/
function kit({ svelte_config }) {
async function kit({ svelte_config }) {
const vite = await resolve_peer_dependency('vite');

const { kit } = svelte_config;
const out = `${kit.outDir}/output`;

Expand Down
3 changes: 3 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 0679801

Please sign in to comment.