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.13 to 1.0.0-next.14

12

CHANGELOG.md
# @sveltejs/vite-plugin-svelte
## 1.0.0-next.14
### Patch Changes
- replace querystring with URLSearchParams ([#107](https://github.com/sveltejs/vite-plugin-svelte/pull/107))
* import svelte types instead of duplicating them ([#105](https://github.com/sveltejs/vite-plugin-svelte/pull/105))
- update svelte-hmr to 0.14.7 to fix issue with svelte 3.40 ([#112](https://github.com/sveltejs/vite-plugin-svelte/pull/112))
* turn diff-match-patch into an optional peer dependency to reduce footprint ([#110](https://github.com/sveltejs/vite-plugin-svelte/pull/110))
## 1.0.0-next.13

@@ -4,0 +16,0 @@

186

dist/index.d.ts
import { Plugin } from 'vite';
import { CompileOptions, Warning } from 'svelte/types/compiler/interfaces';
export { CompileOptions, Warning } from 'svelte/types/compiler/interfaces';
import { PreprocessorGroup } from 'svelte/types/compiler/preprocess';
export { MarkupPreprocessor, Preprocessor, PreprocessorGroup, Processed } from 'svelte/types/compiler/preprocess';

@@ -39,112 +43,11 @@ interface Options {

*
* set to object to pass custom options to svelte-hmr, see https://github.com/rixo/svelte-hmr#options
*
* @default true for development, always false for production
*/
hot?: undefined | boolean | {
/**
* preserve all local state
* @default false
*/
preserveLocalState?: boolean;
/**
* escape hatchs from preservation of local state
* disable preservation of state for this component
*
* @default ['\@hmr:reset', '\@!hmr']
*/
noPreserveStateKey?: string[];
/**
* enable preservation of state for all variables in this component
*
* @default '\@hmr:keep-all'
*/
preserveAllLocalStateKey?: string;
/**
* enable preservation of state for a given variable (must be inline or
* above the target variable or variables; can be repeated)
*
* @default '\@hmr:keep'
*/
preserveLocalStateKey?: string;
/**
* don't reload on fatal error
*
* @default false
*/
noReload?: boolean;
/**
* try to recover after runtime errors during component init
*
* @default true
*/
optimistic?: boolean;
/**
* auto accept modules of components that have named exports (i.e. exports
* from context="module")
*
* @default true
*/
acceptNamedExports?: boolean;
/**
* auto accept modules of components have accessors (either accessors compile
* option, or \<svelte:option accessors=\{true\} /\>) -- this means that if you
* set accessors compile option globally, you must also set this option to
* true, or no component will be hot reloaded (but there are a lot of edge
* cases that HMR can't support correctly with accessors)
*
* @default true
*/
acceptAccessors?: boolean;
/**
* only inject CSS instead of recreating components when only CSS changes
*
* @default true, but vite-plugin-svelte configures this automatically according to emitCss requirements
*/
hot?: boolean | {
injectCss?: boolean;
/**
* to mitigate FOUC between dispose (remove stylesheet) and accept
*
* note: has no effect when emitCss is true (vite-plugin-svelte default)
* @default 100
*/
cssEjectDelay?: number;
/**
* Svelte Native mode
*
* @default false
*/
native?: boolean;
/**
* name of the adapter import binding
*
* @default '___SVELTE_HMR_HOT_API_PROXY_ADAPTER'
*/
importAdapterName?: string;
/**
* use absolute file paths to import runtime deps of svelte-hmr
* (see https://github.com/rixo/svelte-hmr/issues/11)
*
* @default true
*/
absoluteImports?: boolean;
/**
* disable runtime error overlay
*
* @default false
*/
noOverlay?: boolean;
/**
* custom import path for hotApi
*/
hotApi?: string;
/**
* custom path for adapter
*/
adapter?: string;
[key: string]: any;
};
/**
* disable separate hmr update for css files via vite
* @default false
*/
disableCssHmr?: boolean;
/**
* vite plugins can contribute additional preprocessors by defining api.sveltePreprocess.

@@ -175,76 +78,13 @@ * If you don't want to use them, set this to true to ignore them all or use an array of strings with plugin names to specify which

* wrap all preprocessors in with a function that adds a sourcemap to the output if missing
*
* to use this option you have to install "diff-match-patch"
*/
generateMissingPreprocessorSourcemaps?: boolean;
}
declare type ModuleFormat = 'esm' | 'cjs';
interface CompileOptions {
format?: ModuleFormat;
name?: string;
filename?: string;
generate?: 'dom' | 'ssr' | false;
sourcemap?: object | string;
outputFilename?: string;
cssOutputFilename?: string;
sveltePath?: string;
dev?: boolean;
accessors?: boolean;
immutable?: boolean;
hydratable?: boolean;
legacy?: boolean;
customElement?: boolean;
tag?: string;
css?: boolean;
loopGuardTimeout?: number;
namespace?: string;
preserveComments?: boolean;
preserveWhitespace?: boolean;
cssHash?: CssHashGetter;
}
interface Processed {
code: string;
map?: string | object;
dependencies?: string[];
toString?: () => string;
}
declare type CssHashGetter = (args: {
name: string;
filename: string | undefined;
css: string;
hash: (input: string) => string;
}) => string;
declare type MarkupPreprocessor = (options: {
content: string;
filename: string;
}) => Processed | Promise<Processed>;
declare type Preprocessor = (options: {
content: string;
attributes: Record<string, string | boolean>;
filename?: string;
}) => Processed | Promise<Processed>;
interface PreprocessorGroup {
markup?: MarkupPreprocessor;
style?: Preprocessor;
script?: Preprocessor;
}
declare type ModuleFormat = NonNullable<CompileOptions['format']>;
declare type CssHashGetter = NonNullable<CompileOptions['cssHash']>;
declare type Arrayable<T> = T | T[];
interface Warning {
start?: {
line: number;
column: number;
pos?: number;
};
end?: {
line: number;
column: number;
};
pos?: number;
code: string;
message: string;
filename?: string;
frame?: string;
toString: () => string;
}
declare function svelte(inlineOptions?: Partial<Options>): Plugin;
export { Arrayable, CompileOptions, CssHashGetter, MarkupPreprocessor, ModuleFormat, Options, Preprocessor, PreprocessorGroup, Processed, Warning, svelte };
export { Arrayable, CssHashGetter, ModuleFormat, Options, svelte };

@@ -0,5 +1,9 @@

var __create = Object.create;
var __defProp = Object.defineProperty;
var __defProps = Object.defineProperties;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;

@@ -20,2 +24,3 @@ var __propIsEnum = Object.prototype.propertyIsEnumerable;

var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
var __markAsModule = (target) => __defProp(target, "__esModule", { value: true });
var __require = (x) => {

@@ -26,2 +31,13 @@ if (typeof require !== "undefined")

};
var __reExport = (target, module, desc) => {
if (module && typeof module === "object" || typeof module === "function") {
for (let key of __getOwnPropNames(module))
if (!__hasOwnProp.call(target, key) && key !== "default")
__defProp(target, key, { get: () => module[key], enumerable: !(desc = __getOwnPropDesc(module, key)) || desc.enumerable });
}
return target;
};
var __toModule = (module) => {
return __reExport(__markAsModule(__defProp(module != null ? __create(__getProtoOf(module)) : {}, "default", module && module.__esModule && "default" in module ? { get: () => module.default, enumerable: true } : { value: module, enumerable: true })), module);
};

@@ -321,3 +337,2 @@ // src/index.ts

// src/utils/id.ts
import qs from "querystring";
import { createFilter } from "@rollup/pluginutils";

@@ -337,8 +352,3 @@ import { normalizePath } from "vite";

function parseToSvelteRequest(id, filename, rawQuery, root, timestamp, ssr) {
const query = qs.parse(rawQuery);
for (const p of ["svelte", "url", "raw"]) {
if (query[p] != null) {
query[p] = true;
}
}
const query = parseRequestQuery(rawQuery);
if (query.url || query.raw) {

@@ -371,2 +381,11 @@ return;

}
function parseRequestQuery(rawQuery) {
const query = Object.fromEntries(new URLSearchParams(rawQuery));
for (const key in query) {
if (query[key] === "") {
query[key] = true;
}
}
return query;
}
function normalize(filename, normalizedRoot) {

@@ -499,3 +518,2 @@ return stripRoot(normalizePath(filename), normalizedRoot);

"hot",
"disableCssHmr",
"ignorePluginPreprocessors",

@@ -806,4 +824,13 @@ "experimental"

import MagicString from "magic-string";
import { diff_match_patch, DIFF_DELETE, DIFF_INSERT } from "diff-match-patch";
function buildMagicString(from, to, options) {
async function buildMagicString(from, to, options) {
let diff_match_patch, DIFF_DELETE, DIFF_INSERT;
try {
const dmpPkg = await Promise.resolve().then(() => __toModule(__require("diff-match-patch")));
diff_match_patch = dmpPkg.diff_match_patch;
DIFF_INSERT = dmpPkg.DIFF_INSERT;
DIFF_DELETE = dmpPkg.DIFF_DELETE;
} catch (e) {
log.error.once('Failed to import optional dependency "diff-match-patch". Please install it to enable generated sourcemaps.');
return null;
}
const dmp = new diff_match_patch();

@@ -837,5 +864,5 @@ const diffs = dmp.diff_main(from, to);

}
function buildSourceMap(from, to, filename) {
const m = buildMagicString(from, to, { filename });
return m.generateDecodedMap({ source: filename, hires: true, includeContent: false });
async function buildSourceMap(from, to, filename) {
const m = await buildMagicString(from, to, { filename });
return m ? m.generateDecodedMap({ source: filename, hires: true, includeContent: false }) : null;
}

@@ -983,5 +1010,7 @@

try {
const map = buildSourceMap(options.content, result.code, options.filename);
log.warn.once("adding generated sourcemap to preprocesor result");
result.map = map;
const map = await buildSourceMap(options.content, result.code, options.filename);
if (map) {
log.debug.enabled && log.debug(`adding generated sourcemap to preprocesor result for ${options.filename}`);
result.map = map;
}
} catch (e) {

@@ -988,0 +1017,0 @@ log.error(`failed to build sourcemap`, e);

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

@@ -27,3 +27,3 @@ "author": "dominikg",

"build:ci": "rimraf dist && tsup-node src/index.ts --format esm,cjs --no-splitting",
"build": "pnpm run build:ci -- --dts --dts-resolve --sourcemap"
"build": "pnpm run build:ci -- --dts --sourcemap"
},

@@ -50,21 +50,27 @@ "engines": {

"debug": "^4.3.2",
"diff-match-patch": "^1.0.5",
"kleur": "^4.1.4",
"magic-string": "^0.25.7",
"require-relative": "^0.8.7",
"svelte-hmr": "^0.14.6"
"svelte-hmr": "^0.14.7"
},
"peerDependencies": {
"diff-match-patch": "^1.0.5",
"svelte": "^3.34.0",
"vite": "^2.3.7"
},
"peerDependenciesMeta": {
"diff-match-patch": {
"optional": true
}
},
"devDependencies": {
"@types/debug": "^4.1.6",
"@types/diff-match-patch": "^1.0.32",
"diff-match-patch": "^1.0.5",
"esbuild": "^0.12.15",
"rollup": "^2.53.2",
"svelte": "^3.38.3",
"rollup": "^2.53.3",
"svelte": "^3.40.0",
"tsup": "^4.12.5",
"vite": "^2.4.2"
"vite": "^2.4.3"
}
}

@@ -5,6 +5,6 @@ import { buildMagicString, buildSourceMap } from '../sourcemap';

describe('buildMagicString', () => {
it('should return a valid magic string', () => {
it('should return a valid magic string', async () => {
const from = 'h1{color: blue}\nh2{color: green}\nh3{color: red}\n';
const to = 'h1{color: blue}\ndiv{color: white}\nh3{color: red}\nh2{color: green}\n';
const m = buildMagicString(from, to);
const m = await buildMagicString(from, to);
expect(m).toBeDefined();

@@ -16,4 +16,4 @@ expect(m.original).toBe(from);

describe('buildSourceMap', () => {
it('should return a map with mappings and filename', () => {
const map = buildSourceMap('foo', 'bar', 'foo.txt');
it('should return a map with mappings and filename', async () => {
const map = await buildSourceMap('foo', 'bar', 'foo.txt');
expect(map).toBeDefined();

@@ -20,0 +20,0 @@ expect(map.mappings).toBeDefined();

/* eslint-disable no-unused-vars */
import qs from 'querystring';
import { createFilter } from '@rollup/pluginutils';

@@ -47,9 +46,3 @@ import { Arrayable, ResolvedOptions } from './options';

): SvelteRequest | undefined {
const query: RequestQuery = qs.parse(rawQuery) as RequestQuery;
for (const p of ['svelte', 'url', 'raw'] as Array<keyof RequestQuery>) {
if (query[p] != null) {
// @ts-ignore
query[p] = true;
}
}
const query = parseRequestQuery(rawQuery);
if (query.url || query.raw) {

@@ -89,2 +82,13 @@ // skip requests with special vite tags

function parseRequestQuery(rawQuery: string): RequestQuery {
const query = Object.fromEntries(new URLSearchParams(rawQuery));
for (const key in query) {
if (query[key] === '') {
// @ts-ignore
query[key] = true;
}
}
return query as RequestQuery;
}
/**

@@ -91,0 +95,0 @@ * posixify and remove root at start

@@ -6,2 +6,11 @@ /* eslint-disable no-unused-vars */

import { SVELTE_HMR_IMPORTS, SVELTE_IMPORTS, SVELTE_RESOLVE_MAIN_FIELDS } from './constants';
// eslint-disable-next-line node/no-missing-import
import { CompileOptions, Warning } from 'svelte/types/compiler/interfaces';
import {
MarkupPreprocessor,
Preprocessor,
PreprocessorGroup,
Processed
// eslint-disable-next-line node/no-missing-import
} from 'svelte/types/compiler/preprocess';

@@ -18,3 +27,2 @@ const knownOptions = new Set([

'hot',
'disableCssHmr',
'ignorePluginPreprocessors',

@@ -257,130 +265,9 @@ 'experimental'

*
* set to object to pass custom options to svelte-hmr, see https://github.com/rixo/svelte-hmr#options
*
* @default true for development, always false for production
*/
hot?:
| undefined
| boolean
| {
// svelte-hmr options
/**
* preserve all local state
* @default false
*/
preserveLocalState?: boolean;
hot?: boolean | { injectCss?: boolean; [key: string]: any };
/**
* escape hatchs from preservation of local state
* disable preservation of state for this component
*
* @default ['\@hmr:reset', '\@!hmr']
*/
noPreserveStateKey?: string[];
/**
* enable preservation of state for all variables in this component
*
* @default '\@hmr:keep-all'
*/
preserveAllLocalStateKey?: string;
/**
* enable preservation of state for a given variable (must be inline or
* above the target variable or variables; can be repeated)
*
* @default '\@hmr:keep'
*/
preserveLocalStateKey?: string;
/**
* don't reload on fatal error
*
* @default false
*/
noReload?: boolean;
/**
* try to recover after runtime errors during component init
*
* @default true
*/
optimistic?: boolean;
/**
* auto accept modules of components that have named exports (i.e. exports
* from context="module")
*
* @default true
*/
acceptNamedExports?: boolean;
/**
* auto accept modules of components have accessors (either accessors compile
* option, or \<svelte:option accessors=\{true\} /\>) -- this means that if you
* set accessors compile option globally, you must also set this option to
* true, or no component will be hot reloaded (but there are a lot of edge
* cases that HMR can't support correctly with accessors)
*
* @default true
*/
acceptAccessors?: boolean;
/**
* only inject CSS instead of recreating components when only CSS changes
*
* @default true, but vite-plugin-svelte configures this automatically according to emitCss requirements
*/
injectCss?: boolean;
/**
* to mitigate FOUC between dispose (remove stylesheet) and accept
*
* note: has no effect when emitCss is true (vite-plugin-svelte default)
* @default 100
*/
cssEjectDelay?: number;
//
/**
* Svelte Native mode
*
* @default false
*/
native?: boolean;
/**
* name of the adapter import binding
*
* @default '___SVELTE_HMR_HOT_API_PROXY_ADAPTER'
*/
importAdapterName?: string;
/**
* use absolute file paths to import runtime deps of svelte-hmr
* (see https://github.com/rixo/svelte-hmr/issues/11)
*
* @default true
*/
absoluteImports?: boolean;
/**
* disable runtime error overlay
*
* @default false
*/
noOverlay?: boolean;
/**
* custom import path for hotApi
*/
hotApi?: string;
/**
* custom path for adapter
*/
adapter?: string;
};
/**
* disable separate hmr update for css files via vite
* @default false
*/
disableCssHmr?: boolean;
/**
* vite plugins can contribute additional preprocessors by defining api.sveltePreprocess.

@@ -414,2 +301,4 @@ * If you don't want to use them, set this to true to ignore them all or use an array of strings with plugin names to specify which

* wrap all preprocessors in with a function that adds a sourcemap to the output if missing
*
* to use this option you have to install "diff-match-patch"
*/

@@ -427,78 +316,15 @@ generateMissingPreprocessorSourcemaps?: boolean;

// TODO import from appropriate places
export declare type ModuleFormat = 'esm' | 'cjs';
export type {
CompileOptions,
Processed,
MarkupPreprocessor,
Preprocessor,
PreprocessorGroup,
Warning
};
export interface CompileOptions {
format?: ModuleFormat;
name?: string;
filename?: string;
generate?: 'dom' | 'ssr' | false;
sourcemap?: object | string;
outputFilename?: string;
cssOutputFilename?: string;
sveltePath?: string;
dev?: boolean;
accessors?: boolean;
immutable?: boolean;
hydratable?: boolean;
legacy?: boolean;
customElement?: boolean;
tag?: string;
css?: boolean;
loopGuardTimeout?: number;
namespace?: string;
preserveComments?: boolean;
preserveWhitespace?: boolean;
cssHash?: CssHashGetter;
}
export type ModuleFormat = NonNullable<CompileOptions['format']>;
export interface Processed {
code: string;
map?: string | object;
dependencies?: string[];
toString?: () => string;
}
export type CssHashGetter = NonNullable<CompileOptions['cssHash']>;
export declare type CssHashGetter = (args: {
name: string;
filename: string | undefined;
css: string;
hash: (input: string) => string;
}) => string;
export declare type MarkupPreprocessor = (options: {
content: string;
filename: string;
}) => Processed | Promise<Processed>;
export declare type Preprocessor = (options: {
content: string;
attributes: Record<string, string | boolean>;
filename?: string;
}) => Processed | Promise<Processed>;
export interface PreprocessorGroup {
markup?: MarkupPreprocessor;
style?: Preprocessor;
script?: Preprocessor;
}
export type Arrayable<T> = T | T[];
export interface Warning {
start?: {
line: number;
column: number;
pos?: number;
};
end?: {
line: number;
column: number;
};
pos?: number;
code: string;
message: string;
filename?: string;
frame?: string;
toString: () => string;
}

@@ -207,5 +207,10 @@ import { ResolvedConfig, TransformResult, Plugin } from 'vite';

try {
const map = buildSourceMap(options.content, result.code, options.filename);
log.warn.once('adding generated sourcemap to preprocesor result');
result.map = map;
const map = await buildSourceMap(options.content, result.code, options.filename);
if (map) {
log.debug.enabled &&
log.debug(
`adding generated sourcemap to preprocesor result for ${options.filename}`
);
result.map = map;
}
} catch (e) {

@@ -212,0 +217,0 @@ log.error(`failed to build sourcemap`, e);

import MagicString, { MagicStringOptions } from 'magic-string';
import { diff_match_patch, DIFF_DELETE, DIFF_INSERT } from 'diff-match-patch';
import { log } from './log';
export function buildMagicString(
export async function buildMagicString(
from: string,
to: string,
options?: MagicStringOptions
): MagicString {
): Promise<MagicString | null> {
let diff_match_patch, DIFF_DELETE: number, DIFF_INSERT: number;
try {
const dmpPkg = await import('diff-match-patch');
diff_match_patch = dmpPkg.diff_match_patch;
DIFF_INSERT = dmpPkg.DIFF_INSERT;
DIFF_DELETE = dmpPkg.DIFF_DELETE;
} catch (e) {
log.error.once(
'Failed to import optional dependency "diff-match-patch". Please install it to enable generated sourcemaps.'
);
return null;
}
const dmp = new diff_match_patch();

@@ -41,6 +54,6 @@ const diffs = dmp.diff_main(from, to);

export function buildSourceMap(from: string, to: string, filename?: string) {
export async function buildSourceMap(from: string, to: string, filename?: string) {
// @ts-ignore
const m = buildMagicString(from, to, { filename });
return m.generateDecodedMap({ source: filename, hires: true, includeContent: false });
const m = await buildMagicString(from, to, { filename });
return m ? m.generateDecodedMap({ source: filename, hires: true, includeContent: false }) : null;
}

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