Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
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/gentle-paws-listen.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@sveltejs/vite-plugin-svelte': patch
---

chore: remove internal dependency type
28 changes: 4 additions & 24 deletions packages/vite-plugin-svelte/src/utils/dependencies.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,10 @@ function getSvelteDependencies(
.map((dep) => resolveDependencyData(dep, localRequire))
.filter(Boolean) as DependencyData[];
for (const { pkg, dir } of resolvedDeps) {
const type = getSvelteDependencyType(pkg);
if (!type) continue;
result.push({ name: pkg.name, type, pkg, dir, path });
if (!isSvelteLib(pkg)) continue;
result.push({ name: pkg.name, pkg, dir, path });
// continue crawling for component libraries so we can optimize them, js libraries are fine
if (type === 'component-library' && pkg.dependencies) {
if (pkg.dependencies) {
let dependencyNames = Object.keys(pkg.dependencies);
const circular = dependencyNames.filter((name) => path.includes(name));
if (circular.length > 0) {
Expand Down Expand Up @@ -107,22 +106,8 @@ function parsePkg(dir: string, silent = false): Pkg | void {
}
}

function getSvelteDependencyType(pkg: Pkg): SvelteDependencyType | undefined {
if (isSvelteComponentLib(pkg)) {
return 'component-library';
} else if (isSvelteLib(pkg)) {
return 'js-library';
} else {
return undefined;
}
}

function isSvelteComponentLib(pkg: Pkg) {
return !!pkg.svelte;
}

function isSvelteLib(pkg: Pkg) {
return !!pkg.dependencies?.svelte || !!pkg.peerDependencies?.svelte;
return !!pkg.svelte || !!pkg.dependencies?.svelte || !!pkg.peerDependencies?.svelte;
}

const COMMON_DEPENDENCIES_WITHOUT_SVELTE_FIELD = [
Expand Down Expand Up @@ -217,16 +202,11 @@ interface DependencyData {

export interface SvelteDependency {
name: string;
type: SvelteDependencyType;
dir: string;
pkg: Pkg;
path: string[];
}

// component-library => exports svelte components
// js-library => only uses svelte api, no components
export type SvelteDependencyType = 'component-library' | 'js-library';

export interface Pkg {
name: string;
svelte?: string;
Expand Down
3 changes: 0 additions & 3 deletions packages/vite-plugin-svelte/src/utils/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -393,9 +393,6 @@ function buildOptimizeDepsForSvelte(
return { include, exclude };
}

// only svelte component libraries needs to be processed for optimizeDeps, js libraries work fine
svelteDeps = svelteDeps.filter((dep) => dep.type === 'component-library');

const svelteDepsToExclude = Array.from(new Set(svelteDeps.map((dep) => dep.name))).filter(
(dep) => !isIncluded(dep)
);
Expand Down