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.1.0 to 1.1.1

9

package.json
{
"name": "@sveltejs/vite-plugin-svelte",
"version": "1.1.0",
"version": "1.1.1",
"license": "MIT",

@@ -19,2 +19,3 @@ "author": "dominikg",

".": {
"types": "./dist/index.d.ts",
"import": "./dist/index.js",

@@ -65,7 +66,7 @@ "require": "./dist/index.cjs"

"diff-match-patch": "^1.0.5",
"esbuild": "^0.15.12",
"esbuild": "^0.15.13",
"rollup": "^2.79.1",
"svelte": "^3.52.0",
"tsup": "^6.3.0",
"vite": "^3.1.8"
"tsup": "^6.4.0",
"vite": "^3.2.3"
},

@@ -72,0 +73,0 @@ "scripts": {

@@ -1,12 +0,6 @@

import {
transformWithEsbuild,
ESBuildOptions,
ResolvedConfig,
TransformResult,
Plugin
} from 'vite';
import * as vite from 'vite';
import type { ESBuildOptions, ResolvedConfig, Plugin } from 'vite';
import MagicString from 'magic-string';
import { preprocess } from 'svelte/compiler';
import { Preprocessor, PreprocessorGroup, Processed, ResolvedOptions } from './options';
import { TransformPluginContext } from 'rollup';
import { log } from './log';

@@ -24,3 +18,3 @@ import { buildSourceMap } from './sourcemap';

if (!supportedScriptLangs.includes(lang)) return;
const transformResult = await transformWithEsbuild(content, filename, {
const transformResult = await vite.transformWithEsbuild(content, filename, {
loader: lang as ESBuildOptions['loader'],

@@ -44,11 +38,3 @@ target: 'esnext',

function createViteStylePreprocessor(config: ResolvedConfig): Preprocessor {
const pluginName = 'vite:css';
const plugin = config.plugins.find((p) => p.name === pluginName);
if (!plugin) {
throw new Error(`failed to find plugin ${pluginName}`);
}
if (!plugin.transform) {
throw new Error(`plugin ${pluginName} has no transform`);
}
const pluginTransform = plugin.transform!.bind(null as unknown as TransformPluginContext);
const transform = getCssTransformFn(config);
return async ({ attributes, content, filename = '' }) => {

@@ -58,13 +44,10 @@ const lang = attributes.lang as string;

const moduleId = `${filename}.${lang}`;
const transformResult: TransformResult = (await pluginTransform(
content,
moduleId
)) as TransformResult;
const result = await transform(content, moduleId);
// patch sourcemap source to point back to original filename
if (transformResult.map?.sources?.[0] === moduleId) {
transformResult.map.sources[0] = path.basename(filename);
if (result.map?.sources?.[0] === moduleId) {
result.map.sources[0] = path.basename(filename);
}
return {
code: transformResult.code,
map: transformResult.map ?? undefined
code: result.code,
map: result.map ?? undefined
};

@@ -74,2 +57,26 @@ };

// eslint-disable-next-line no-unused-vars
type CssTransform = (code: string, filename: string) => Promise<{ code: string; map?: any }>;
function getCssTransformFn(config: ResolvedConfig): CssTransform {
// API is only available in Vite 3.2 and above
// TODO: Remove Vite plugin hack when bump peer dep to Vite 3.2
if (vite.preprocessCSS) {
return async (code, filename) => {
return vite.preprocessCSS(code, filename, config);
};
} else {
const pluginName = 'vite:css';
const plugin = config.plugins.find((p) => p.name === pluginName);
if (!plugin) {
throw new Error(`failed to find plugin ${pluginName}`);
}
if (!plugin.transform) {
throw new Error(`plugin ${pluginName} has no transform`);
}
// @ts-expect-error
return plugin.transform.bind(null);
}
}
function createVitePreprocessorGroup(config: ResolvedConfig): PreprocessorGroup {

@@ -76,0 +83,0 @@ return {

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 too big to display

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