Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@sveltejs/vite-plugin-svelte

Package Overview
Dependencies
Maintainers
4
Versions
109
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@sveltejs/vite-plugin-svelte - npm Package Compare versions

Comparing version 1.0.0-next.21 to 1.0.0-next.22

32

dist/index.js

@@ -573,3 +573,3 @@ var __create = Object.create;

const localRequire = createRequire2(`${pkgDir}/package.json`);
const resolvedDeps = deps.map((dep) => resolveSvelteDependency(dep, localRequire)).filter(Boolean);
const resolvedDeps = deps.map((dep) => resolveDependencyData(dep, localRequire)).filter((depData) => !!depData && isSvelte(depData.pkg));
for (const { pkg, dir } of resolvedDeps) {

@@ -592,9 +592,6 @@ result.push({ name: pkg.name, pkg, dir, path: path6 });

}
function resolveSvelteDependency(dep, localRequire) {
function resolveDependencyData(dep, localRequire) {
try {
const pkgJson = `${dep}/package.json`;
const pkg = localRequire(pkgJson);
if (!isSvelte(pkg)) {
return;
}
const dir = path2.dirname(localRequire.resolve(pkgJson));

@@ -609,6 +606,2 @@ return { dir, pkg };

if (pkg && pkg.name === dep) {
if (!isSvelte(pkg)) {
return;
}
log.warn.once(`package.json of ${dep} has a "svelte" field but does not include itself in exports field. Please ask package maintainer to update`);
return { dir, pkg };

@@ -677,4 +670,12 @@ }

}
function needsOptimization(dep, localRequire) {
const depData = resolveDependencyData(dep, localRequire);
if (!depData)
return false;
const pkg = depData.pkg;
return pkg.main && !pkg.module && !pkg.exports;
}
// src/utils/options.ts
import { createRequire as createRequire3 } from "module";
var knownOptions = new Set([

@@ -789,7 +790,6 @@ "configFile",

}
function buildExtraViteConfig(options, config) {
function buildExtraViteConfig(options, config, configEnv) {
var _a;
const svelteDeps = findRootSvelteDependencies(options.root);
const extraViteConfig = {
optimizeDeps: buildOptimizeDepsForSvelte(svelteDeps, options, config.optimizeDeps),
resolve: {

@@ -800,2 +800,5 @@ mainFields: [...SVELTE_RESOLVE_MAIN_FIELDS],

};
if (configEnv.command === "serve") {
extraViteConfig.optimizeDeps = buildOptimizeDepsForSvelte(svelteDeps, options, config.optimizeDeps);
}
extraViteConfig.ssr = buildSSROptionsForSvelte(svelteDeps, options, config);

@@ -839,3 +842,6 @@ if ((_a = options.experimental) == null ? void 0 : _a.useVitePreprocess) {

}
const transitiveDepsToInclude = svelteDeps.filter((dep) => !disabledReinclusions.includes(dep.name) && isExcluded(dep.name)).flatMap((dep) => Object.keys(dep.pkg.dependencies || {}).filter((depOfDep) => !isExcluded(depOfDep)).map((depOfDep) => dep.path.concat(dep.name, depOfDep).join(" > ")));
const transitiveDepsToInclude = svelteDeps.filter((dep) => !disabledReinclusions.includes(dep.name) && isExcluded(dep.name)).flatMap((dep) => {
const localRequire = createRequire3(`${dep.dir}/package.json`);
return Object.keys(dep.pkg.dependencies || {}).filter((depOfDep) => !isExcluded(depOfDep) && needsOptimization(depOfDep, localRequire)).map((depOfDep) => dep.path.concat(dep.name, depOfDep).join(" > "));
});
log.debug(`reincluding transitive dependencies of excluded svelte dependencies`, transitiveDepsToInclude);

@@ -1268,3 +1274,3 @@ include.push(...transitiveDepsToInclude);

options = await resolveOptions(inlineOptions, config, configEnv);
const extraViteConfig = buildExtraViteConfig(options, config);
const extraViteConfig = buildExtraViteConfig(options, config, configEnv);
log.debug("additional vite config", extraViteConfig);

@@ -1271,0 +1277,0 @@ return extraViteConfig;

{
"name": "@sveltejs/vite-plugin-svelte",
"version": "1.0.0-next.21",
"version": "1.0.0-next.22",
"license": "MIT",

@@ -5,0 +5,0 @@ "author": "dominikg",

@@ -55,3 +55,3 @@ import fs from 'fs';

// extra vite config
const extraViteConfig = buildExtraViteConfig(options, config);
const extraViteConfig = buildExtraViteConfig(options, config, configEnv);
log.debug('additional vite config', extraViteConfig);

@@ -58,0 +58,0 @@ return extraViteConfig as Partial<UserConfig>;

@@ -42,4 +42,4 @@ import { log } from './log';

const resolvedDeps = deps
.map((dep) => resolveSvelteDependency(dep, localRequire))
.filter(Boolean);
.map((dep) => resolveDependencyData(dep, localRequire))
.filter((depData) => !!depData && isSvelte(depData.pkg)) as DependencyData[];
// @ts-ignore

@@ -68,12 +68,6 @@ for (const { pkg, dir } of resolvedDeps) {

function resolveSvelteDependency(
dep: string,
localRequire: NodeRequire
): { dir: string; pkg: Pkg } | void {
function resolveDependencyData(dep: string, localRequire: NodeRequire): DependencyData | void {
try {
const pkgJson = `${dep}/package.json`;
const pkg = localRequire(pkgJson);
if (!isSvelte(pkg)) {
return;
}
const dir = path.dirname(localRequire.resolve(pkgJson));

@@ -89,8 +83,2 @@ return { dir, pkg };

if (pkg && pkg.name === dep) {
if (!isSvelte(pkg)) {
return;
}
log.warn.once(
`package.json of ${dep} has a "svelte" field but does not include itself in exports field. Please ask package maintainer to update`
);
return { dir, pkg };

@@ -180,2 +168,16 @@ }

export function needsOptimization(dep: string, localRequire: NodeRequire): boolean {
const depData = resolveDependencyData(dep, localRequire);
if (!depData) return false;
const pkg = depData.pkg;
// only optimize if is cjs, using the below as heuristic
// see https://github.com/sveltejs/vite-plugin-svelte/issues/162
return pkg.main && !pkg.module && !pkg.exports;
}
interface DependencyData {
dir: string;
pkg: Pkg;
}
export interface SvelteDependency {

@@ -182,0 +184,0 @@ name: string;

@@ -16,4 +16,5 @@ /* eslint-disable no-unused-vars */

import path from 'path';
import { findRootSvelteDependencies, SvelteDependency } from './dependencies';
import { findRootSvelteDependencies, needsOptimization, SvelteDependency } from './dependencies';
import { DepOptimizationOptions } from 'vite/src/node/optimizer/index';
import { createRequire } from 'module';

@@ -184,3 +185,4 @@ const knownOptions = new Set([

options: ResolvedOptions,
config: UserConfig
config: UserConfig,
configEnv: ConfigEnv
): Partial<UserConfig> {

@@ -190,3 +192,2 @@ // extra handling for svelte dependencies in the project

const extraViteConfig: Partial<UserConfig> = {
optimizeDeps: buildOptimizeDepsForSvelte(svelteDeps, options, config.optimizeDeps),
resolve: {

@@ -202,2 +203,10 @@ mainFields: [...SVELTE_RESOLVE_MAIN_FIELDS],

if (configEnv.command === 'serve') {
extraViteConfig.optimizeDeps = buildOptimizeDepsForSvelte(
svelteDeps,
options,
config.optimizeDeps
);
}
// @ts-ignore

@@ -260,7 +269,8 @@ extraViteConfig.ssr = buildSSROptionsForSvelte(svelteDeps, options, config);

.filter((dep) => !disabledReinclusions.includes(dep.name) && isExcluded(dep.name))
.flatMap((dep) =>
Object.keys(dep.pkg.dependencies || {})
.filter((depOfDep) => !isExcluded(depOfDep))
.map((depOfDep) => dep.path.concat(dep.name, depOfDep).join(' > '))
);
.flatMap((dep) => {
const localRequire = createRequire(`${dep.dir}/package.json`);
return Object.keys(dep.pkg.dependencies || {})
.filter((depOfDep) => !isExcluded(depOfDep) && needsOptimization(depOfDep, localRequire))
.map((depOfDep) => dep.path.concat(dep.name, depOfDep).join(' > '));
});
log.debug(

@@ -267,0 +277,0 @@ `reincluding transitive dependencies of excluded svelte dependencies`,

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc