@sveltejs/vite-plugin-svelte 2.1.1 → 2.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +7 -72
- package/dist/index.js +40 -158
- package/dist/index.js.map +1 -1
- package/package.json +8 -8
- package/src/index.ts +15 -8
- package/src/utils/compile.ts +0 -3
- package/src/utils/options.ts +27 -100
- package/src/ui/inspector/Inspector.svelte +0 -365
- package/src/ui/inspector/load-inspector.js +0 -15
- package/src/ui/inspector/plugin.ts +0 -115
- package/src/ui/inspector/utils.ts +0 -13
package/dist/index.d.ts
CHANGED
|
@@ -3,6 +3,7 @@ import { CompileOptions, Warning } from 'svelte/types/compiler/interfaces';
|
|
|
3
3
|
export { CompileOptions, Warning } from 'svelte/types/compiler/interfaces';
|
|
4
4
|
import { PreprocessorGroup } from 'svelte/types/compiler/preprocess';
|
|
5
5
|
export { MarkupPreprocessor, Preprocessor, PreprocessorGroup, Processed } from 'svelte/types/compiler/preprocess';
|
|
6
|
+
import { Options as Options$1 } from '@sveltejs/vite-plugin-svelte-inspector';
|
|
6
7
|
|
|
7
8
|
type Options = Omit<SvelteOptions, 'vitePlugin'> & PluginOptionsInline;
|
|
8
9
|
interface PluginOptionsInline extends PluginOptions {
|
|
@@ -85,6 +86,12 @@ interface PluginOptions {
|
|
|
85
86
|
* @default true for dev, false for build
|
|
86
87
|
*/
|
|
87
88
|
prebundleSvelteLibraries?: boolean;
|
|
89
|
+
/**
|
|
90
|
+
* toggle/configure Svelte Inspector
|
|
91
|
+
*
|
|
92
|
+
* @default true
|
|
93
|
+
*/
|
|
94
|
+
inspector?: Options$1 | boolean;
|
|
88
95
|
/**
|
|
89
96
|
* These options are considered experimental and breaking changes to them can occur in any release
|
|
90
97
|
*/
|
|
@@ -148,10 +155,6 @@ interface ExperimentalOptions {
|
|
|
148
155
|
code: string;
|
|
149
156
|
compileOptions: Partial<CompileOptions>;
|
|
150
157
|
}) => Promise<Partial<CompileOptions> | void> | Partial<CompileOptions> | void;
|
|
151
|
-
/**
|
|
152
|
-
* enable svelte inspector
|
|
153
|
-
*/
|
|
154
|
-
inspector?: InspectorOptions | boolean;
|
|
155
158
|
/**
|
|
156
159
|
* send a websocket message with svelte compiler warnings during dev
|
|
157
160
|
*
|
|
@@ -164,74 +167,6 @@ interface ExperimentalOptions {
|
|
|
164
167
|
*/
|
|
165
168
|
disableSvelteResolveWarnings?: boolean;
|
|
166
169
|
}
|
|
167
|
-
interface InspectorOptions {
|
|
168
|
-
/**
|
|
169
|
-
* define a key combo to toggle inspector,
|
|
170
|
-
* @default 'control-shift' on windows, 'meta-shift' on other os
|
|
171
|
-
*
|
|
172
|
-
* any number of modifiers `control` `shift` `alt` `meta` followed by zero or one regular key, separated by -
|
|
173
|
-
* examples: control-shift, control-o, control-alt-s meta-x control-meta
|
|
174
|
-
* Some keys have native behavior (e.g. alt-s opens history menu on firefox).
|
|
175
|
-
* To avoid conflicts or accidentally typing into inputs, modifier only combinations are recommended.
|
|
176
|
-
*/
|
|
177
|
-
toggleKeyCombo?: string;
|
|
178
|
-
/**
|
|
179
|
-
* define keys to select elements with via keyboard
|
|
180
|
-
* @default {parent: 'ArrowUp', child: 'ArrowDown', next: 'ArrowRight', prev: 'ArrowLeft' }
|
|
181
|
-
*
|
|
182
|
-
* improves accessibility and also helps when you want to select elements that do not have a hoverable surface area
|
|
183
|
-
* due to tight wrapping
|
|
184
|
-
*
|
|
185
|
-
* A note for users of screen-readers:
|
|
186
|
-
* If you are using arrow keys to navigate the page itself, change the navKeys to avoid conflicts.
|
|
187
|
-
* e.g. navKeys: {parent: 'w', prev: 'a', child: 's', next: 'd'}
|
|
188
|
-
*
|
|
189
|
-
*
|
|
190
|
-
* parent: select closest parent
|
|
191
|
-
* child: select first child (or grandchild)
|
|
192
|
-
* next: next sibling (or parent if no next sibling exists)
|
|
193
|
-
* prev: previous sibling (or parent if no prev sibling exists)
|
|
194
|
-
*/
|
|
195
|
-
navKeys?: {
|
|
196
|
-
parent: string;
|
|
197
|
-
child: string;
|
|
198
|
-
next: string;
|
|
199
|
-
prev: string;
|
|
200
|
-
};
|
|
201
|
-
/**
|
|
202
|
-
* define key to open the editor for the currently selected dom node
|
|
203
|
-
*
|
|
204
|
-
* @default 'Enter'
|
|
205
|
-
*/
|
|
206
|
-
openKey?: string;
|
|
207
|
-
/**
|
|
208
|
-
* inspector is automatically disabled when releasing toggleKeyCombo after holding it for a longpress
|
|
209
|
-
* @default false
|
|
210
|
-
*/
|
|
211
|
-
holdMode?: boolean;
|
|
212
|
-
/**
|
|
213
|
-
* when to show the toggle button
|
|
214
|
-
* @default 'active'
|
|
215
|
-
*/
|
|
216
|
-
showToggleButton?: 'always' | 'active' | 'never';
|
|
217
|
-
/**
|
|
218
|
-
* where to display the toggle button
|
|
219
|
-
* @default top-right
|
|
220
|
-
*/
|
|
221
|
-
toggleButtonPos?: 'top-right' | 'top-left' | 'bottom-right' | 'bottom-left';
|
|
222
|
-
/**
|
|
223
|
-
* inject custom styles when inspector is active
|
|
224
|
-
*/
|
|
225
|
-
customStyles?: boolean;
|
|
226
|
-
/**
|
|
227
|
-
* append an import to the module id ending with `appendTo` instead of adding a script into body
|
|
228
|
-
* useful for frameworks that do not support trannsformIndexHtml hook
|
|
229
|
-
*
|
|
230
|
-
* WARNING: only set this if you know exactly what it does.
|
|
231
|
-
* Regular users of vite-plugin-svelte or SvelteKit do not need it
|
|
232
|
-
*/
|
|
233
|
-
appendTo?: string;
|
|
234
|
-
}
|
|
235
170
|
type ModuleFormat = NonNullable<CompileOptions['format']>;
|
|
236
171
|
type CssHashGetter = NonNullable<CompileOptions['cssHash']>;
|
|
237
172
|
type Arrayable<T> = T | T[];
|
package/dist/index.js
CHANGED
|
@@ -7,11 +7,12 @@ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require
|
|
|
7
7
|
});
|
|
8
8
|
|
|
9
9
|
// src/index.ts
|
|
10
|
-
import
|
|
10
|
+
import fs7 from "fs";
|
|
11
11
|
import { VERSION as svelteVersion } from "svelte/compiler";
|
|
12
12
|
import {
|
|
13
13
|
version as viteVersion
|
|
14
14
|
} from "vite";
|
|
15
|
+
import { svelteInspector } from "@sveltejs/vite-plugin-svelte-inspector";
|
|
15
16
|
import { isDepExcluded as isDepExcluded2 } from "vitefu";
|
|
16
17
|
|
|
17
18
|
// src/utils/log.ts
|
|
@@ -599,7 +600,6 @@ import ${JSON.stringify(cssId)};
|
|
|
599
600
|
});
|
|
600
601
|
}
|
|
601
602
|
}
|
|
602
|
-
compiled.js.dependencies = dependencies;
|
|
603
603
|
return {
|
|
604
604
|
filename,
|
|
605
605
|
normalizedFilename,
|
|
@@ -1169,16 +1169,11 @@ var allowedPluginOptions = /* @__PURE__ */ new Set([
|
|
|
1169
1169
|
"ignorePluginPreprocessors",
|
|
1170
1170
|
"disableDependencyReinclusion",
|
|
1171
1171
|
"prebundleSvelteLibraries",
|
|
1172
|
+
"inspector",
|
|
1172
1173
|
"experimental"
|
|
1173
1174
|
]);
|
|
1174
1175
|
var knownRootOptions = /* @__PURE__ */ new Set(["extensions", "compilerOptions", "preprocess", "onwarn"]);
|
|
1175
|
-
var allowedInlineOptions = /* @__PURE__ */ new Set([
|
|
1176
|
-
"configFile",
|
|
1177
|
-
"kit",
|
|
1178
|
-
// only for internal use by sveltekit
|
|
1179
|
-
...allowedPluginOptions,
|
|
1180
|
-
...knownRootOptions
|
|
1181
|
-
]);
|
|
1176
|
+
var allowedInlineOptions = /* @__PURE__ */ new Set(["configFile", ...allowedPluginOptions, ...knownRootOptions]);
|
|
1182
1177
|
function validateInlineOptions(inlineOptions) {
|
|
1183
1178
|
const invalidKeys = Object.keys(inlineOptions || {}).filter(
|
|
1184
1179
|
(key) => !allowedInlineOptions.has(key)
|
|
@@ -1300,7 +1295,6 @@ function resolveOptions(preResolveOptions2, viteConfig, cache) {
|
|
|
1300
1295
|
const merged = mergeConfigs(defaultOptions, preResolveOptions2, extraOptions);
|
|
1301
1296
|
removeIgnoredOptions(merged);
|
|
1302
1297
|
handleDeprecatedOptions(merged);
|
|
1303
|
-
addSvelteKitOptions(merged);
|
|
1304
1298
|
addExtraPreprocessors(merged, viteConfig);
|
|
1305
1299
|
enforceOptionsForHmr(merged);
|
|
1306
1300
|
enforceOptionsForProduction(merged);
|
|
@@ -1382,21 +1376,21 @@ function removeIgnoredOptions(options) {
|
|
|
1382
1376
|
});
|
|
1383
1377
|
}
|
|
1384
1378
|
}
|
|
1385
|
-
function addSvelteKitOptions(options) {
|
|
1386
|
-
if (options?.kit != null && options.compilerOptions.hydratable == null) {
|
|
1387
|
-
log.debug(`Setting compilerOptions.hydratable = true for SvelteKit`);
|
|
1388
|
-
options.compilerOptions.hydratable = true;
|
|
1389
|
-
}
|
|
1390
|
-
}
|
|
1391
1379
|
function handleDeprecatedOptions(options) {
|
|
1392
|
-
|
|
1393
|
-
|
|
1394
|
-
|
|
1395
|
-
|
|
1396
|
-
|
|
1397
|
-
|
|
1398
|
-
|
|
1399
|
-
|
|
1380
|
+
const experimental = options.experimental;
|
|
1381
|
+
if (experimental) {
|
|
1382
|
+
for (const promoted of ["prebundleSvelteLibraries", "inspector"]) {
|
|
1383
|
+
if (experimental[promoted]) {
|
|
1384
|
+
options[promoted] = experimental[promoted];
|
|
1385
|
+
delete experimental[promoted];
|
|
1386
|
+
log.warn(
|
|
1387
|
+
`Option "vitePlugin.experimental.${promoted}" is no longer experimental and has moved to "vitePlugin.${promoted}". Please update your svelte config.`
|
|
1388
|
+
);
|
|
1389
|
+
}
|
|
1390
|
+
}
|
|
1391
|
+
if (experimental.generateMissingPreprocessorSourcemaps) {
|
|
1392
|
+
log.warn("experimental.generateMissingPreprocessorSourcemaps has been removed.");
|
|
1393
|
+
}
|
|
1400
1394
|
}
|
|
1401
1395
|
}
|
|
1402
1396
|
function resolveViteRoot(viteConfig) {
|
|
@@ -1745,129 +1739,11 @@ function generateSvelteMetadata(options) {
|
|
|
1745
1739
|
return metadata;
|
|
1746
1740
|
}
|
|
1747
1741
|
|
|
1748
|
-
// src/ui/inspector/plugin.ts
|
|
1749
|
-
import { normalizePath as normalizePath5 } from "vite";
|
|
1750
|
-
import path9 from "path";
|
|
1751
|
-
import { fileURLToPath } from "url";
|
|
1752
|
-
import fs6 from "fs";
|
|
1753
|
-
|
|
1754
|
-
// src/ui/inspector/utils.ts
|
|
1755
|
-
var FS_PREFIX = `/@fs/`;
|
|
1756
|
-
var IS_WINDOWS3 = process.platform === "win32";
|
|
1757
|
-
var queryRE = /\?.*$/s;
|
|
1758
|
-
var hashRE = /#.*$/s;
|
|
1759
|
-
function idToFile(id) {
|
|
1760
|
-
if (id.startsWith(FS_PREFIX)) {
|
|
1761
|
-
id = id = id.slice(IS_WINDOWS3 ? FS_PREFIX.length : FS_PREFIX.length - 1);
|
|
1762
|
-
}
|
|
1763
|
-
return id.replace(hashRE, "").replace(queryRE, "");
|
|
1764
|
-
}
|
|
1765
|
-
|
|
1766
|
-
// src/ui/inspector/plugin.ts
|
|
1767
|
-
var defaultInspectorOptions = {
|
|
1768
|
-
toggleKeyCombo: process.platform === "win32" ? "control-shift" : "meta-shift",
|
|
1769
|
-
navKeys: { parent: "ArrowUp", child: "ArrowDown", next: "ArrowRight", prev: "ArrowLeft" },
|
|
1770
|
-
openKey: "Enter",
|
|
1771
|
-
holdMode: false,
|
|
1772
|
-
showToggleButton: "active",
|
|
1773
|
-
toggleButtonPos: "top-right",
|
|
1774
|
-
customStyles: true
|
|
1775
|
-
};
|
|
1776
|
-
function getInspectorPath() {
|
|
1777
|
-
const pluginPath = normalizePath5(path9.dirname(fileURLToPath(import.meta.url)));
|
|
1778
|
-
return pluginPath.replace(/\/vite-plugin-svelte\/dist$/, "/vite-plugin-svelte/src/ui/inspector/");
|
|
1779
|
-
}
|
|
1780
|
-
function svelteInspector() {
|
|
1781
|
-
const inspectorPath = getInspectorPath();
|
|
1782
|
-
log.debug.enabled && log.debug(`svelte inspector path: ${inspectorPath}`);
|
|
1783
|
-
let inspectorOptions;
|
|
1784
|
-
let appendTo;
|
|
1785
|
-
let disabled = false;
|
|
1786
|
-
return {
|
|
1787
|
-
name: "vite-plugin-svelte:inspector",
|
|
1788
|
-
apply: "serve",
|
|
1789
|
-
enforce: "pre",
|
|
1790
|
-
configResolved(config) {
|
|
1791
|
-
const vps = config.plugins.find((p) => p.name === "vite-plugin-svelte");
|
|
1792
|
-
const options = vps?.api?.options?.experimental?.inspector;
|
|
1793
|
-
if (!vps || !options) {
|
|
1794
|
-
log.debug("inspector disabled, could not find config");
|
|
1795
|
-
disabled = true;
|
|
1796
|
-
return;
|
|
1797
|
-
}
|
|
1798
|
-
inspectorOptions = {
|
|
1799
|
-
...defaultInspectorOptions,
|
|
1800
|
-
...options
|
|
1801
|
-
};
|
|
1802
|
-
const isSvelteKit = config.plugins.some((p) => p.name.startsWith("vite-plugin-sveltekit"));
|
|
1803
|
-
if (isSvelteKit && !inspectorOptions.appendTo) {
|
|
1804
|
-
inspectorOptions.appendTo = `/generated/root.svelte`;
|
|
1805
|
-
}
|
|
1806
|
-
appendTo = inspectorOptions.appendTo;
|
|
1807
|
-
},
|
|
1808
|
-
async resolveId(importee, importer, options) {
|
|
1809
|
-
if (options?.ssr || disabled) {
|
|
1810
|
-
return;
|
|
1811
|
-
}
|
|
1812
|
-
if (importee.startsWith("virtual:svelte-inspector-options")) {
|
|
1813
|
-
return importee;
|
|
1814
|
-
} else if (importee.startsWith("virtual:svelte-inspector-path:")) {
|
|
1815
|
-
const resolved = importee.replace("virtual:svelte-inspector-path:", inspectorPath);
|
|
1816
|
-
log.debug.enabled && log.debug(`resolved ${importee} with ${resolved}`);
|
|
1817
|
-
return resolved;
|
|
1818
|
-
}
|
|
1819
|
-
},
|
|
1820
|
-
async load(id, options) {
|
|
1821
|
-
if (options?.ssr || disabled) {
|
|
1822
|
-
return;
|
|
1823
|
-
}
|
|
1824
|
-
if (id === "virtual:svelte-inspector-options") {
|
|
1825
|
-
return `export default ${JSON.stringify(inspectorOptions ?? {})}`;
|
|
1826
|
-
} else if (id.startsWith(inspectorPath)) {
|
|
1827
|
-
const file = idToFile(id);
|
|
1828
|
-
if (fs6.existsSync(file)) {
|
|
1829
|
-
return await fs6.promises.readFile(file, "utf-8");
|
|
1830
|
-
} else {
|
|
1831
|
-
log.error(`failed to find file for svelte-inspector: ${file}, referenced by id ${id}.`);
|
|
1832
|
-
}
|
|
1833
|
-
}
|
|
1834
|
-
},
|
|
1835
|
-
transform(code, id, options) {
|
|
1836
|
-
if (options?.ssr || disabled || !appendTo) {
|
|
1837
|
-
return;
|
|
1838
|
-
}
|
|
1839
|
-
if (id.endsWith(appendTo)) {
|
|
1840
|
-
return { code: `${code}
|
|
1841
|
-
import 'virtual:svelte-inspector-path:load-inspector.js'` };
|
|
1842
|
-
}
|
|
1843
|
-
},
|
|
1844
|
-
transformIndexHtml(html) {
|
|
1845
|
-
if (disabled || appendTo) {
|
|
1846
|
-
return;
|
|
1847
|
-
}
|
|
1848
|
-
return {
|
|
1849
|
-
html,
|
|
1850
|
-
tags: [
|
|
1851
|
-
{
|
|
1852
|
-
tag: "script",
|
|
1853
|
-
injectTo: "body",
|
|
1854
|
-
attrs: {
|
|
1855
|
-
type: "module",
|
|
1856
|
-
// /@id/ is needed, otherwise the virtual: is seen as protocol by browser and cors error happens
|
|
1857
|
-
src: "/@id/virtual:svelte-inspector-path:load-inspector.js"
|
|
1858
|
-
}
|
|
1859
|
-
}
|
|
1860
|
-
]
|
|
1861
|
-
};
|
|
1862
|
-
}
|
|
1863
|
-
};
|
|
1864
|
-
}
|
|
1865
|
-
|
|
1866
1742
|
// src/utils/vite-plugin-svelte-cache.ts
|
|
1867
1743
|
import { readFileSync as readFileSync2 } from "fs";
|
|
1868
1744
|
import { dirname } from "path";
|
|
1869
1745
|
import { findClosestPkgJsonPath } from "vitefu";
|
|
1870
|
-
import { normalizePath as
|
|
1746
|
+
import { normalizePath as normalizePath5 } from "vite";
|
|
1871
1747
|
var VitePluginSvelteCache = class {
|
|
1872
1748
|
constructor() {
|
|
1873
1749
|
this._css = /* @__PURE__ */ new Map();
|
|
@@ -1955,8 +1831,8 @@ var VitePluginSvelteCache = class {
|
|
|
1955
1831
|
getError(svelteRequest) {
|
|
1956
1832
|
return this._errors.get(svelteRequest.normalizedFilename);
|
|
1957
1833
|
}
|
|
1958
|
-
getDependants(
|
|
1959
|
-
const dependants = this._dependants.get(
|
|
1834
|
+
getDependants(path9) {
|
|
1835
|
+
const dependants = this._dependants.get(path9);
|
|
1960
1836
|
return dependants ? [...dependants] : [];
|
|
1961
1837
|
}
|
|
1962
1838
|
getResolvedSvelteField(name, importer) {
|
|
@@ -1989,7 +1865,7 @@ async function findPackageInfo(file) {
|
|
|
1989
1865
|
version: "0.0.0-unknown",
|
|
1990
1866
|
path: "$unknown"
|
|
1991
1867
|
};
|
|
1992
|
-
let
|
|
1868
|
+
let path9 = await findClosestPkgJsonPath(file, (pkgPath) => {
|
|
1993
1869
|
const pkg = JSON.parse(readFileSync2(pkgPath, "utf-8"));
|
|
1994
1870
|
if (pkg.name != null) {
|
|
1995
1871
|
info.name = pkg.name;
|
|
@@ -2001,17 +1877,17 @@ async function findPackageInfo(file) {
|
|
|
2001
1877
|
}
|
|
2002
1878
|
return false;
|
|
2003
1879
|
});
|
|
2004
|
-
|
|
2005
|
-
info.path =
|
|
1880
|
+
path9 = normalizePath5(dirname(path9 ?? file)) + "/";
|
|
1881
|
+
info.path = path9;
|
|
2006
1882
|
return info;
|
|
2007
1883
|
}
|
|
2008
1884
|
|
|
2009
1885
|
// src/utils/load-raw.ts
|
|
2010
|
-
import
|
|
1886
|
+
import fs6 from "fs";
|
|
2011
1887
|
async function loadRaw(svelteRequest, compileSvelte2, options) {
|
|
2012
1888
|
const { id, filename, query } = svelteRequest;
|
|
2013
1889
|
let compileData;
|
|
2014
|
-
const source =
|
|
1890
|
+
const source = fs6.readFileSync(filename, "utf-8");
|
|
2015
1891
|
try {
|
|
2016
1892
|
svelteRequest.ssr = query.compilerOptions?.generate === "ssr";
|
|
2017
1893
|
const type = query.type;
|
|
@@ -2255,7 +2131,7 @@ function svelte(inlineOptions) {
|
|
|
2255
2131
|
}
|
|
2256
2132
|
if (viteConfig.assetsInclude(filename)) {
|
|
2257
2133
|
log.debug(`load returns raw content for ${filename}`);
|
|
2258
|
-
return
|
|
2134
|
+
return fs7.readFileSync(filename, "utf-8");
|
|
2259
2135
|
}
|
|
2260
2136
|
}
|
|
2261
2137
|
}
|
|
@@ -2339,10 +2215,16 @@ function svelte(inlineOptions) {
|
|
|
2339
2215
|
}
|
|
2340
2216
|
logCompilerWarnings(svelteRequest, compileData.compiled.warnings, options);
|
|
2341
2217
|
cache.update(compileData);
|
|
2342
|
-
if (compileData.dependencies?.length
|
|
2343
|
-
|
|
2344
|
-
|
|
2345
|
-
|
|
2218
|
+
if (compileData.dependencies?.length) {
|
|
2219
|
+
if (options.server) {
|
|
2220
|
+
for (const dep of compileData.dependencies) {
|
|
2221
|
+
ensureWatchedFile(options.server.watcher, dep, options.root);
|
|
2222
|
+
}
|
|
2223
|
+
} else if (options.isBuild && viteConfig.build.watch) {
|
|
2224
|
+
for (const dep of compileData.dependencies) {
|
|
2225
|
+
this.addWatchFile(dep);
|
|
2226
|
+
}
|
|
2227
|
+
}
|
|
2346
2228
|
}
|
|
2347
2229
|
log.debug(`transform returns compiled js for ${svelteRequest.filename}`);
|
|
2348
2230
|
return {
|
|
@@ -2377,10 +2259,10 @@ Please see ${FAQ_LINK_CONFLICTS_IN_SVELTE_RESOLVE} for details.`
|
|
|
2377
2259
|
);
|
|
2378
2260
|
}
|
|
2379
2261
|
}
|
|
2380
|
-
}
|
|
2262
|
+
},
|
|
2263
|
+
svelteInspector()
|
|
2381
2264
|
];
|
|
2382
|
-
plugins
|
|
2383
|
-
return plugins.filter(Boolean);
|
|
2265
|
+
return plugins;
|
|
2384
2266
|
}
|
|
2385
2267
|
export {
|
|
2386
2268
|
loadSvelteConfig,
|