Socket
Socket
Sign inDemoInstall

@sveltejs/vite-plugin-svelte

Package Overview
Dependencies
199
Maintainers
4
Versions
102
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 2.0.2 to 2.0.3

src/utils/sourcemaps.ts

16

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

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

"debug": "^4.3.4",
"deepmerge": "^4.2.2",
"deepmerge": "^4.3.0",
"kleur": "^4.1.5",
"magic-string": "^0.27.0",
"magic-string": "^0.29.0",
"svelte-hmr": "^0.15.1",
"vitefu": "^0.2.3"
"vitefu": "^0.2.4"
},

@@ -54,7 +54,7 @@ "peerDependencies": {

"@types/debug": "^4.1.7",
"esbuild": "^0.16.4",
"esbuild": "^0.17.9",
"rollup": "^2.79.1",
"svelte": "^3.54.0",
"tsup": "^6.5.0",
"vite": "^4.0.0"
"svelte": "^3.55.1",
"tsup": "^6.6.3",
"vite": "^4.1.4"
},

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

@@ -7,2 +7,3 @@ import { ModuleNode, HmrContext } from 'vite';

import { ResolvedOptions } from './utils/options';
import { toRollupError } from './utils/error';

@@ -36,3 +37,3 @@ /**

cache.setError(svelteRequest, e);
throw e;
throw toRollupError(e, options);
}

@@ -39,0 +40,0 @@

@@ -222,7 +222,3 @@ import fs from 'fs';

if (svelteRequest) {
try {
return handleHotUpdate(compileSvelte, ctx, svelteRequest, cache, options);
} catch (e) {
throw toRollupError(e, options);
}
return handleHotUpdate(compileSvelte, ctx, svelteRequest, cache, options);
}

@@ -229,0 +225,0 @@ },

@@ -1,2 +0,1 @@

import path from 'path';
import { preprocessCSS, resolveConfig, transformWithEsbuild } from 'vite';

@@ -6,2 +5,3 @@ import type { ESBuildOptions, InlineConfig, ResolvedConfig } from 'vite';

import type { Preprocessor, PreprocessorGroup } from 'svelte/types/compiler/preprocess';
import { mapSourcesToRelative } from './utils/sourcemaps';

@@ -31,3 +31,3 @@ const supportedStyleLangs = ['css', 'less', 'sass', 'scss', 'styl', 'stylus', 'postcss', 'sss'];

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

@@ -43,5 +43,8 @@ target: 'esnext',

});
mapSourcesToRelative(map, filename);
return {
code: transformResult.code,
map: transformResult.map
code,
map
};

@@ -76,10 +79,9 @@ }

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

@@ -86,0 +88,0 @@ };

@@ -12,3 +12,3 @@ import { CompileOptions, ResolvedOptions } from './options';

import { createInjectScopeEverythingRulePreprocessorGroup } from './preprocess';
import path from 'path';
import { mapSourcesToRelative } from './sourcemaps';

@@ -19,19 +19,2 @@ const scriptLangRE = /<script [^>]*lang=["']?([^"' >]+)["']?[^>]*>/;

function mapSourcesToRelative(map: { sources?: string[] }, filename: string) {
// sourcemap sources are relative to the sourcemap itself
// assume the sourcemap location is the same as filename and turn absolute paths to relative
// to avoid leaking fs information like vite root
if (map?.sources) {
map.sources = map.sources.map((s) => {
if (path.isAbsolute(s)) {
const relative = path.relative(filename, s);
// empty string a source is not allowed, use simple filename
return relative === '' ? path.basename(filename) : relative;
} else {
return s;
}
});
}
}
const _createCompileSvelte = (makeHot: Function) => {

@@ -38,0 +21,0 @@ let stats: StatCollection | undefined;

@@ -1,4 +0,4 @@

const VITE_RESOLVE_MAIN_FIELDS = ['module', 'jsnext:main', 'jsnext'];
export const VITE_RESOLVE_MAIN_FIELDS = ['module', 'jsnext:main', 'jsnext'];
export const SVELTE_RESOLVE_MAIN_FIELDS = ['svelte', ...VITE_RESOLVE_MAIN_FIELDS];
export const SVELTE_RESOLVE_MAIN_FIELDS = ['svelte'];

@@ -5,0 +5,0 @@ export const SVELTE_IMPORTS = [

@@ -9,3 +9,4 @@ /* eslint-disable no-unused-vars */

SVELTE_IMPORTS,
SVELTE_RESOLVE_MAIN_FIELDS
SVELTE_RESOLVE_MAIN_FIELDS,
VITE_RESOLVE_MAIN_FIELDS
} from './constants';

@@ -328,5 +329,14 @@ // eslint-disable-next-line node/no-missing-import

): Promise<Partial<UserConfig>> {
// make sure we only readd vite default mainFields when no other plugin has changed the config already
// see https://github.com/sveltejs/vite-plugin-svelte/issues/581
if (!config.resolve) {
config.resolve = {};
}
config.resolve.mainFields = [
...SVELTE_RESOLVE_MAIN_FIELDS,
...(config.resolve.mainFields ?? VITE_RESOLVE_MAIN_FIELDS)
];
const extraViteConfig: Partial<UserConfig> = {
resolve: {
mainFields: [...SVELTE_RESOLVE_MAIN_FIELDS],
dedupe: [...SVELTE_IMPORTS, ...SVELTE_HMR_IMPORTS],

@@ -333,0 +343,0 @@ conditions: [...SVELTE_EXPORT_CONDITIONS]

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

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc