@sveltejs/vite-plugin-svelte 2.2.0 → 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 +2 -68
- package/dist/index.js +21 -177
- package/dist/index.js.map +1 -1
- package/package.json +7 -7
- package/src/index.ts +12 -5
- package/src/utils/compile.ts +0 -3
- package/src/utils/options.ts +2 -1
- package/src/ui/inspector/Inspector.svelte +0 -384
- package/src/ui/inspector/load-inspector.js +0 -15
- package/src/ui/inspector/options.ts +0 -131
- package/src/ui/inspector/plugin.ts +0 -97
- package/src/ui/inspector/utils.ts +0 -13
package/dist/index.d.ts
CHANGED
|
@@ -3,73 +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
|
-
|
|
7
|
-
interface InspectorOptions {
|
|
8
|
-
/**
|
|
9
|
-
* define a key combo to toggle inspector,
|
|
10
|
-
* @default 'meta-shift' on mac, 'control-shift' on other os
|
|
11
|
-
*
|
|
12
|
-
* any number of modifiers `control` `shift` `alt` `meta` followed by zero or one regular key, separated by -
|
|
13
|
-
* examples: control-shift, control-o, control-alt-s meta-x control-meta
|
|
14
|
-
* Some keys have native behavior (e.g. alt-s opens history menu on firefox).
|
|
15
|
-
* To avoid conflicts or accidentally typing into inputs, modifier only combinations are recommended.
|
|
16
|
-
*/
|
|
17
|
-
toggleKeyCombo?: string;
|
|
18
|
-
/**
|
|
19
|
-
* define keys to select elements with via keyboard
|
|
20
|
-
* @default {parent: 'ArrowUp', child: 'ArrowDown', next: 'ArrowRight', prev: 'ArrowLeft' }
|
|
21
|
-
*
|
|
22
|
-
* improves accessibility and also helps when you want to select elements that do not have a hoverable surface area
|
|
23
|
-
* due to tight wrapping
|
|
24
|
-
*
|
|
25
|
-
* A note for users of screen-readers:
|
|
26
|
-
* If you are using arrow keys to navigate the page itself, change the navKeys to avoid conflicts.
|
|
27
|
-
* e.g. navKeys: {parent: 'w', prev: 'a', child: 's', next: 'd'}
|
|
28
|
-
*
|
|
29
|
-
*
|
|
30
|
-
* parent: select closest parent
|
|
31
|
-
* child: select first child (or grandchild)
|
|
32
|
-
* next: next sibling (or parent if no next sibling exists)
|
|
33
|
-
* prev: previous sibling (or parent if no prev sibling exists)
|
|
34
|
-
*/
|
|
35
|
-
navKeys?: {
|
|
36
|
-
parent: string;
|
|
37
|
-
child: string;
|
|
38
|
-
next: string;
|
|
39
|
-
prev: string;
|
|
40
|
-
};
|
|
41
|
-
/**
|
|
42
|
-
* define key to open the editor for the currently selected dom node
|
|
43
|
-
*
|
|
44
|
-
* @default 'Enter'
|
|
45
|
-
*/
|
|
46
|
-
openKey?: string;
|
|
47
|
-
/**
|
|
48
|
-
* inspector is automatically disabled when releasing toggleKeyCombo after holding it for a longpress
|
|
49
|
-
* @default true
|
|
50
|
-
*/
|
|
51
|
-
holdMode?: boolean;
|
|
52
|
-
/**
|
|
53
|
-
* when to show the toggle button
|
|
54
|
-
* @default 'active'
|
|
55
|
-
*/
|
|
56
|
-
showToggleButton?: 'always' | 'active' | 'never';
|
|
57
|
-
/**
|
|
58
|
-
* where to display the toggle button
|
|
59
|
-
* @default top-right
|
|
60
|
-
*/
|
|
61
|
-
toggleButtonPos?: 'top-right' | 'top-left' | 'bottom-right' | 'bottom-left';
|
|
62
|
-
/**
|
|
63
|
-
* inject custom styles when inspector is active
|
|
64
|
-
*/
|
|
65
|
-
customStyles?: boolean;
|
|
66
|
-
/**
|
|
67
|
-
* internal options that are automatically set, not to be set or used by users
|
|
68
|
-
*/
|
|
69
|
-
__internal?: {
|
|
70
|
-
base: string;
|
|
71
|
-
};
|
|
72
|
-
}
|
|
6
|
+
import { Options as Options$1 } from '@sveltejs/vite-plugin-svelte-inspector';
|
|
73
7
|
|
|
74
8
|
type Options = Omit<SvelteOptions, 'vitePlugin'> & PluginOptionsInline;
|
|
75
9
|
interface PluginOptionsInline extends PluginOptions {
|
|
@@ -157,7 +91,7 @@ interface PluginOptions {
|
|
|
157
91
|
*
|
|
158
92
|
* @default true
|
|
159
93
|
*/
|
|
160
|
-
inspector?:
|
|
94
|
+
inspector?: Options$1 | boolean;
|
|
161
95
|
/**
|
|
162
96
|
* These options are considered experimental and breaking changes to them can occur in any release
|
|
163
97
|
*/
|
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,
|
|
@@ -1739,173 +1739,11 @@ function generateSvelteMetadata(options) {
|
|
|
1739
1739
|
return metadata;
|
|
1740
1740
|
}
|
|
1741
1741
|
|
|
1742
|
-
// src/ui/inspector/plugin.ts
|
|
1743
|
-
import { normalizePath as normalizePath5 } from "vite";
|
|
1744
|
-
import path9 from "path";
|
|
1745
|
-
import { fileURLToPath } from "url";
|
|
1746
|
-
import fs6 from "fs";
|
|
1747
|
-
|
|
1748
|
-
// src/ui/inspector/utils.ts
|
|
1749
|
-
var FS_PREFIX = `/@fs/`;
|
|
1750
|
-
var IS_WINDOWS3 = process.platform === "win32";
|
|
1751
|
-
var queryRE = /\?.*$/s;
|
|
1752
|
-
var hashRE = /#.*$/s;
|
|
1753
|
-
function idToFile(id) {
|
|
1754
|
-
if (id.startsWith(FS_PREFIX)) {
|
|
1755
|
-
id = id = id.slice(IS_WINDOWS3 ? FS_PREFIX.length : FS_PREFIX.length - 1);
|
|
1756
|
-
}
|
|
1757
|
-
return id.replace(hashRE, "").replace(queryRE, "");
|
|
1758
|
-
}
|
|
1759
|
-
|
|
1760
|
-
// src/ui/inspector/options.ts
|
|
1761
|
-
import * as process2 from "process";
|
|
1762
|
-
import { loadEnv } from "vite";
|
|
1763
|
-
var defaultInspectorOptions = {
|
|
1764
|
-
toggleKeyCombo: process2.platform === "darwin" ? "meta-shift" : "control-shift",
|
|
1765
|
-
navKeys: { parent: "ArrowUp", child: "ArrowDown", next: "ArrowRight", prev: "ArrowLeft" },
|
|
1766
|
-
openKey: "Enter",
|
|
1767
|
-
holdMode: true,
|
|
1768
|
-
showToggleButton: "active",
|
|
1769
|
-
toggleButtonPos: "top-right",
|
|
1770
|
-
customStyles: true
|
|
1771
|
-
};
|
|
1772
|
-
function parseEnvironmentOptions(config) {
|
|
1773
|
-
const env = loadEnv(config.mode, config.envDir ?? process2.cwd(), "SVELTE_INSPECTOR");
|
|
1774
|
-
const options = env?.SVELTE_INSPECTOR_OPTIONS;
|
|
1775
|
-
const toggle = env?.SVELTE_INSPECTOR_TOGGLE;
|
|
1776
|
-
if (options) {
|
|
1777
|
-
try {
|
|
1778
|
-
const parsed = JSON.parse(options);
|
|
1779
|
-
const parsedType = typeof parsed;
|
|
1780
|
-
if (parsedType === "boolean") {
|
|
1781
|
-
return parsed;
|
|
1782
|
-
} else if (parsedType === "object") {
|
|
1783
|
-
if (Array.isArray(parsed)) {
|
|
1784
|
-
throw new Error("invalid type, expected object map but got array");
|
|
1785
|
-
}
|
|
1786
|
-
const parsedKeys = Object.keys(parsed);
|
|
1787
|
-
const defaultKeys = Object.keys(defaultInspectorOptions);
|
|
1788
|
-
const unknownKeys = parsedKeys.filter((k) => !defaultKeys.includes(k));
|
|
1789
|
-
if (unknownKeys.length) {
|
|
1790
|
-
log.warn(
|
|
1791
|
-
`ignoring unknown options in environment SVELTE_INSPECTOR_OPTIONS: ${unknownKeys.join(
|
|
1792
|
-
", "
|
|
1793
|
-
)}.`,
|
|
1794
|
-
void 0,
|
|
1795
|
-
"inspector"
|
|
1796
|
-
);
|
|
1797
|
-
for (const key of unknownKeys) {
|
|
1798
|
-
delete parsed[key];
|
|
1799
|
-
}
|
|
1800
|
-
}
|
|
1801
|
-
log.debug("loaded environment config", parsed, "inspector");
|
|
1802
|
-
return parsed;
|
|
1803
|
-
}
|
|
1804
|
-
} catch (e) {
|
|
1805
|
-
log.error(
|
|
1806
|
-
`failed to parse inspector options from environment SVELTE_INSPECTOR_OPTIONS="${options}"`,
|
|
1807
|
-
e,
|
|
1808
|
-
"inspector"
|
|
1809
|
-
);
|
|
1810
|
-
}
|
|
1811
|
-
} else if (toggle) {
|
|
1812
|
-
const keyConfig = {
|
|
1813
|
-
toggleKeyCombo: toggle
|
|
1814
|
-
};
|
|
1815
|
-
log.debug("loaded environment config", keyConfig, "inspector");
|
|
1816
|
-
return keyConfig;
|
|
1817
|
-
}
|
|
1818
|
-
}
|
|
1819
|
-
|
|
1820
|
-
// src/ui/inspector/plugin.ts
|
|
1821
|
-
function getInspectorPath() {
|
|
1822
|
-
const pluginPath = normalizePath5(path9.dirname(fileURLToPath(import.meta.url)));
|
|
1823
|
-
return pluginPath.replace(/\/vite-plugin-svelte\/dist$/, "/vite-plugin-svelte/src/ui/inspector/");
|
|
1824
|
-
}
|
|
1825
|
-
function svelteInspector() {
|
|
1826
|
-
const inspectorPath = getInspectorPath();
|
|
1827
|
-
log.debug.enabled && log.debug(`svelte inspector path: ${inspectorPath}`);
|
|
1828
|
-
let inspectorOptions;
|
|
1829
|
-
let disabled = false;
|
|
1830
|
-
return {
|
|
1831
|
-
name: "vite-plugin-svelte:inspector",
|
|
1832
|
-
apply: "serve",
|
|
1833
|
-
enforce: "pre",
|
|
1834
|
-
configResolved(config) {
|
|
1835
|
-
const vps = config.plugins.find((p) => p.name === "vite-plugin-svelte");
|
|
1836
|
-
if (!vps) {
|
|
1837
|
-
log.warn("vite-plugin-svelte is missing, inspector disabled", void 0, "inspector");
|
|
1838
|
-
disabled = true;
|
|
1839
|
-
return;
|
|
1840
|
-
}
|
|
1841
|
-
const configFileOptions = vps?.api?.options?.inspector;
|
|
1842
|
-
const environmentOptions = parseEnvironmentOptions(config);
|
|
1843
|
-
if (!configFileOptions && !environmentOptions) {
|
|
1844
|
-
log.debug("no options found, inspector disabled", void 0, "inspector");
|
|
1845
|
-
disabled = true;
|
|
1846
|
-
return;
|
|
1847
|
-
}
|
|
1848
|
-
if (environmentOptions === true) {
|
|
1849
|
-
inspectorOptions = defaultInspectorOptions;
|
|
1850
|
-
} else {
|
|
1851
|
-
inspectorOptions = {
|
|
1852
|
-
...defaultInspectorOptions,
|
|
1853
|
-
...configFileOptions,
|
|
1854
|
-
...environmentOptions || {}
|
|
1855
|
-
};
|
|
1856
|
-
}
|
|
1857
|
-
inspectorOptions.__internal = {
|
|
1858
|
-
base: config.base?.replace(/\/$/, "") || ""
|
|
1859
|
-
};
|
|
1860
|
-
},
|
|
1861
|
-
async resolveId(importee, importer, options) {
|
|
1862
|
-
if (options?.ssr || disabled) {
|
|
1863
|
-
return;
|
|
1864
|
-
}
|
|
1865
|
-
if (importee.startsWith("virtual:svelte-inspector-options")) {
|
|
1866
|
-
return importee;
|
|
1867
|
-
} else if (importee.startsWith("virtual:svelte-inspector-path:")) {
|
|
1868
|
-
const resolved = importee.replace("virtual:svelte-inspector-path:", inspectorPath);
|
|
1869
|
-
log.debug.enabled && log.debug(`resolved ${importee} with ${resolved}`, void 0, "inspector");
|
|
1870
|
-
return resolved;
|
|
1871
|
-
}
|
|
1872
|
-
},
|
|
1873
|
-
async load(id, options) {
|
|
1874
|
-
if (options?.ssr || disabled) {
|
|
1875
|
-
return;
|
|
1876
|
-
}
|
|
1877
|
-
if (id === "virtual:svelte-inspector-options") {
|
|
1878
|
-
return `export default ${JSON.stringify(inspectorOptions ?? {})}`;
|
|
1879
|
-
} else if (id.startsWith(inspectorPath)) {
|
|
1880
|
-
const file = idToFile(id);
|
|
1881
|
-
if (fs6.existsSync(file)) {
|
|
1882
|
-
return await fs6.promises.readFile(file, "utf-8");
|
|
1883
|
-
} else {
|
|
1884
|
-
log.error(
|
|
1885
|
-
`failed to find file for svelte-inspector: ${file}, referenced by id ${id}.`,
|
|
1886
|
-
void 0,
|
|
1887
|
-
"inspector"
|
|
1888
|
-
);
|
|
1889
|
-
}
|
|
1890
|
-
}
|
|
1891
|
-
},
|
|
1892
|
-
transform(code, id, options) {
|
|
1893
|
-
if (options?.ssr || disabled) {
|
|
1894
|
-
return;
|
|
1895
|
-
}
|
|
1896
|
-
if (id.includes("vite/dist/client/client.mjs")) {
|
|
1897
|
-
return { code: `${code}
|
|
1898
|
-
import('virtual:svelte-inspector-path:load-inspector.js')` };
|
|
1899
|
-
}
|
|
1900
|
-
}
|
|
1901
|
-
};
|
|
1902
|
-
}
|
|
1903
|
-
|
|
1904
1742
|
// src/utils/vite-plugin-svelte-cache.ts
|
|
1905
1743
|
import { readFileSync as readFileSync2 } from "fs";
|
|
1906
1744
|
import { dirname } from "path";
|
|
1907
1745
|
import { findClosestPkgJsonPath } from "vitefu";
|
|
1908
|
-
import { normalizePath as
|
|
1746
|
+
import { normalizePath as normalizePath5 } from "vite";
|
|
1909
1747
|
var VitePluginSvelteCache = class {
|
|
1910
1748
|
constructor() {
|
|
1911
1749
|
this._css = /* @__PURE__ */ new Map();
|
|
@@ -1993,8 +1831,8 @@ var VitePluginSvelteCache = class {
|
|
|
1993
1831
|
getError(svelteRequest) {
|
|
1994
1832
|
return this._errors.get(svelteRequest.normalizedFilename);
|
|
1995
1833
|
}
|
|
1996
|
-
getDependants(
|
|
1997
|
-
const dependants = this._dependants.get(
|
|
1834
|
+
getDependants(path9) {
|
|
1835
|
+
const dependants = this._dependants.get(path9);
|
|
1998
1836
|
return dependants ? [...dependants] : [];
|
|
1999
1837
|
}
|
|
2000
1838
|
getResolvedSvelteField(name, importer) {
|
|
@@ -2027,7 +1865,7 @@ async function findPackageInfo(file) {
|
|
|
2027
1865
|
version: "0.0.0-unknown",
|
|
2028
1866
|
path: "$unknown"
|
|
2029
1867
|
};
|
|
2030
|
-
let
|
|
1868
|
+
let path9 = await findClosestPkgJsonPath(file, (pkgPath) => {
|
|
2031
1869
|
const pkg = JSON.parse(readFileSync2(pkgPath, "utf-8"));
|
|
2032
1870
|
if (pkg.name != null) {
|
|
2033
1871
|
info.name = pkg.name;
|
|
@@ -2039,17 +1877,17 @@ async function findPackageInfo(file) {
|
|
|
2039
1877
|
}
|
|
2040
1878
|
return false;
|
|
2041
1879
|
});
|
|
2042
|
-
|
|
2043
|
-
info.path =
|
|
1880
|
+
path9 = normalizePath5(dirname(path9 ?? file)) + "/";
|
|
1881
|
+
info.path = path9;
|
|
2044
1882
|
return info;
|
|
2045
1883
|
}
|
|
2046
1884
|
|
|
2047
1885
|
// src/utils/load-raw.ts
|
|
2048
|
-
import
|
|
1886
|
+
import fs6 from "fs";
|
|
2049
1887
|
async function loadRaw(svelteRequest, compileSvelte2, options) {
|
|
2050
1888
|
const { id, filename, query } = svelteRequest;
|
|
2051
1889
|
let compileData;
|
|
2052
|
-
const source =
|
|
1890
|
+
const source = fs6.readFileSync(filename, "utf-8");
|
|
2053
1891
|
try {
|
|
2054
1892
|
svelteRequest.ssr = query.compilerOptions?.generate === "ssr";
|
|
2055
1893
|
const type = query.type;
|
|
@@ -2293,7 +2131,7 @@ function svelte(inlineOptions) {
|
|
|
2293
2131
|
}
|
|
2294
2132
|
if (viteConfig.assetsInclude(filename)) {
|
|
2295
2133
|
log.debug(`load returns raw content for ${filename}`);
|
|
2296
|
-
return
|
|
2134
|
+
return fs7.readFileSync(filename, "utf-8");
|
|
2297
2135
|
}
|
|
2298
2136
|
}
|
|
2299
2137
|
}
|
|
@@ -2377,10 +2215,16 @@ function svelte(inlineOptions) {
|
|
|
2377
2215
|
}
|
|
2378
2216
|
logCompilerWarnings(svelteRequest, compileData.compiled.warnings, options);
|
|
2379
2217
|
cache.update(compileData);
|
|
2380
|
-
if (compileData.dependencies?.length
|
|
2381
|
-
|
|
2382
|
-
|
|
2383
|
-
|
|
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
|
+
}
|
|
2384
2228
|
}
|
|
2385
2229
|
log.debug(`transform returns compiled js for ${svelteRequest.filename}`);
|
|
2386
2230
|
return {
|