Socket
Socket
Sign inDemoInstall

@sveltejs/vite-plugin-svelte

Package Overview
Dependencies
Maintainers
4
Versions
107
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.33 to 1.0.0-next.34

src/utils/optimizer.ts

110

dist/index.js

@@ -29,3 +29,3 @@ var __defProp = Object.defineProperty;

// src/index.ts
import fs7 from "fs";
import fs8 from "fs";

@@ -93,3 +93,3 @@ // src/utils/log.ts

const logFn = _log.bind(null, logger);
const logged = new Set();
const logged = /* @__PURE__ */ new Set();
const once = function(message, payload) {

@@ -186,3 +186,3 @@ if (logged.has(message)) {

cache.update(compileData);
const affectedModules = new Set();
const affectedModules = /* @__PURE__ */ new Set();
const cssModule = server.moduleGraph.getModuleById(svelteRequest.cssId);

@@ -251,6 +251,4 @@ const mainModule = server.moduleGraph.getModuleById(svelteRequest.id);

// src/utils/hash.ts
import {
createHash
} from "crypto";
var hashes = Object.create(null);
import * as crypto from "crypto";
var hashes = /* @__PURE__ */ Object.create(null);
var hash_length = 12;

@@ -261,3 +259,3 @@ function safeBase64Hash(input) {

}
const md5 = createHash("md5");
const md5 = crypto.createHash("md5");
md5.update(input);

@@ -365,5 +363,3 @@ const hash = toSafe(md5.digest("base64")).substr(0, hash_length);

import { normalizePath } from "vite";
import {
existsSync
} from "fs";
import * as fs from "fs";
var VITE_FS_PREFIX = "/@fs/";

@@ -422,3 +418,3 @@ var IS_WINDOWS = process.platform === "win32";

}
return existsSync(root + filename);
return fs.existsSync(root + filename);
}

@@ -572,3 +568,3 @@ function stripRoot(normalizedFilename, normalizedRoot) {

}
function getSvelteDependencies(deps, pkgDir, path6 = []) {
function getSvelteDependencies(deps, pkgDir, path7 = []) {
const result = [];

@@ -581,14 +577,14 @@ const localRequire = createRequire2(`${pkgDir}/package.json`);

continue;
result.push({ name: pkg.name, type, pkg, dir, path: path6 });
result.push({ name: pkg.name, type, pkg, dir, path: path7 });
if (type === "component-library" && pkg.dependencies) {
let dependencyNames = Object.keys(pkg.dependencies);
const circular = dependencyNames.filter((name) => path6.includes(name));
const circular = dependencyNames.filter((name) => path7.includes(name));
if (circular.length > 0) {
log.warn.enabled && log.warn(`skipping circular svelte dependencies in automated vite optimizeDeps handling`, circular.map((x) => path6.concat(x).join(">")));
dependencyNames = dependencyNames.filter((name) => !path6.includes(name));
log.warn.enabled && log.warn(`skipping circular svelte dependencies in automated vite optimizeDeps handling`, circular.map((x) => path7.concat(x).join(">")));
dependencyNames = dependencyNames.filter((name) => !path7.includes(name));
}
if (path6.length === 3) {
log.debug.once(`encountered deep svelte dependency tree: ${path6.join(">")}`);
if (path7.length === 3) {
log.debug.once(`encountered deep svelte dependency tree: ${path7.join(">")}`);
}
result.push(...getSvelteDependencies(dependencyNames, dir, path6.concat(pkg.name)));
result.push(...getSvelteDependencies(dependencyNames, dir, path7.concat(pkg.name)));
}

@@ -887,3 +883,4 @@ }

compilerOptions: {
importsNotUsedAsValues: "preserve"
importsNotUsedAsValues: "preserve",
preserveValueImports: true
}

@@ -1052,3 +1049,3 @@ }

// src/utils/options.ts
var knownOptions = new Set([
var knownOptions = /* @__PURE__ */ new Set([
"configFile",

@@ -1107,2 +1104,3 @@ "include",

compilerOptions: __spreadValues(__spreadValues({}, defaultOptions.compilerOptions), preResolveOptions2.compilerOptions),
root: viteConfig.root,
isProduction: viteConfig.isProduction

@@ -1175,3 +1173,3 @@ });

}
function buildOptimizeDepsForSvelte(svelteDeps, options, optimizeDeps) {
function buildOptimizeDepsForSvelte(svelteDeps, options, optimizeDeps2) {
const include = [];

@@ -1181,7 +1179,7 @@ const exclude = ["svelte-hmr"];

var _a;
return include.includes(dep) || ((_a = optimizeDeps == null ? void 0 : optimizeDeps.include) == null ? void 0 : _a.includes(dep));
return include.includes(dep) || ((_a = optimizeDeps2 == null ? void 0 : optimizeDeps2.include) == null ? void 0 : _a.includes(dep));
};
const isExcluded = (dep) => {
var _a;
return exclude.includes(dep) || ((_a = optimizeDeps == null ? void 0 : optimizeDeps.exclude) == null ? void 0 : _a.some((id) => dep === id || id.startsWith(`${dep}/`)));
return exclude.includes(dep) || ((_a = optimizeDeps2 == null ? void 0 : optimizeDeps2.exclude) == null ? void 0 : _a.some((id) => dep === id || id.startsWith(`${dep}/`)));
};

@@ -1252,6 +1250,6 @@ if (!isExcluded("svelte")) {

constructor() {
this._css = new Map();
this._js = new Map();
this._dependencies = new Map();
this._dependants = new Map();
this._css = /* @__PURE__ */ new Map();
this._js = /* @__PURE__ */ new Map();
this._dependencies = /* @__PURE__ */ new Map();
this._dependants = /* @__PURE__ */ new Map();
}

@@ -1280,3 +1278,3 @@ update(compileData) {

if (!this._dependants.has(d)) {
this._dependants.set(d, new Set());
this._dependants.set(d, /* @__PURE__ */ new Set());
}

@@ -1319,4 +1317,4 @@ this._dependants.get(d).add(compileData.filename);

}
getDependants(path6) {
const dependants = this._dependants.get(path6);
getDependants(path7) {
const dependants = this._dependants.get(path7);
return dependants ? [...dependants] : [];

@@ -1355,3 +1353,2 @@ }

const triggerViteRestart = (filename) => {
var _a;
if (serverConfig.middlewareMode) {

@@ -1366,3 +1363,3 @@ const message = "Svelte config change detected, restart your dev process to apply the changes.";

log.info(`svelte config changed: restarting vite server. - file: ${filename}`);
server.restart(!!((_a = options.experimental) == null ? void 0 : _a.prebundleSvelteLibraries));
server.restart();
}

@@ -1432,2 +1429,40 @@ };

// src/utils/optimizer.ts
import fs7 from "fs";
import path6 from "path";
import { optimizeDeps } from "vite";
var PREBUNDLE_SENSITIVE_OPTIONS = [
"compilerOptions",
"configFile",
"experimental",
"extensions",
"ignorePluginPreprocessors",
"preprocess"
];
async function handleOptimizeDeps(options, viteConfig) {
if (!options.experimental.prebundleSvelteLibraries || !viteConfig.cacheDir)
return;
const viteMetadataPath = path6.resolve(viteConfig.cacheDir, "_metadata.json");
if (!fs7.existsSync(viteMetadataPath))
return;
const svelteMetadataPath = path6.resolve(viteConfig.cacheDir, "_svelte_metadata.json");
const currentSvelteMetadata = JSON.stringify(generateSvelteMetadata(options), (_, value) => {
return typeof value === "function" ? value.toString() : value;
});
if (fs7.existsSync(svelteMetadataPath)) {
const existingSvelteMetadata = fs7.readFileSync(svelteMetadataPath, "utf8");
if (existingSvelteMetadata === currentSvelteMetadata)
return;
}
await optimizeDeps(viteConfig, true);
fs7.writeFileSync(svelteMetadataPath, currentSvelteMetadata);
}
function generateSvelteMetadata(options) {
const metadata = {};
for (const key of PREBUNDLE_SENSITIVE_OPTIONS) {
metadata[key] = options[key];
}
return metadata;
}
// src/index.ts

@@ -1440,3 +1475,3 @@ function svelte(inlineOptions) {

const cache = new VitePluginSvelteCache();
const pkg_export_errors = new Set();
const pkg_export_errors = /* @__PURE__ */ new Set();
let requestParser;

@@ -1469,2 +1504,5 @@ let options;

},
async buildStart() {
await handleOptimizeDeps(options, viteConfig);
},
configureServer(server) {

@@ -1488,3 +1526,3 @@ options.server = server;

log.debug(`load returns raw content for ${filename}`);
return fs7.readFileSync(filename, "utf-8");
return fs8.readFileSync(filename, "utf-8");
}

@@ -1491,0 +1529,0 @@ }

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

@@ -64,7 +64,7 @@ "author": "dominikg",

"diff-match-patch": "^1.0.5",
"esbuild": "^0.13.15",
"esbuild": "^0.14.10",
"rollup": "^2.62.0",
"svelte": "^3.44.3",
"tsup": "^5.11.9",
"vite": "^2.7.7"
"tsup": "^5.11.10",
"vite": "^2.7.10"
},

@@ -71,0 +71,0 @@ "scripts": {

@@ -22,2 +22,3 @@ import fs from 'fs';

import { toRollupError } from './utils/error';
import { handleOptimizeDeps } from './utils/optimizer';

@@ -73,2 +74,6 @@ export function svelte(inlineOptions?: Partial<Options>): Plugin {

async buildStart() {
await handleOptimizeDeps(options, viteConfig);
},
configureServer(server) {

@@ -75,0 +80,0 @@ // eslint-disable-next-line no-unused-vars

@@ -115,2 +115,3 @@ /* eslint-disable no-unused-vars */

},
root: viteConfig.root,
isProduction: viteConfig.isProduction

@@ -117,0 +118,0 @@ };

@@ -28,3 +28,4 @@ import {

// svelte typescript needs this flag to work with type imports
importsNotUsedAsValues: 'preserve'
importsNotUsedAsValues: 'preserve',
preserveValueImports: true
}

@@ -31,0 +32,0 @@ }

@@ -57,3 +57,3 @@ import { VitePluginSvelteCache } from './vite-plugin-svelte-cache';

log.info(`svelte config changed: restarting vite server. - file: ${filename}`);
server.restart(!!options.experimental?.prebundleSvelteLibraries);
server.restart();
}

@@ -60,0 +60,0 @@ };

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