@sveltejs/vite-plugin-svelte 1.0.0-next.43 → 1.0.0-next.46
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.cjs +64 -45
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +4 -2
- package/dist/index.js +63 -44
- package/dist/index.js.map +1 -1
- package/package.json +11 -12
- package/src/ui/inspector/Inspector.svelte +25 -9
- package/src/ui/inspector/{load-inspector.ts → load-inspector.js} +1 -2
- package/src/ui/inspector/plugin.ts +37 -32
- package/src/utils/__tests__/dependencies.spec.ts +7 -4
- package/src/utils/__tests__/sourcemap.spec.ts +1 -0
- package/src/utils/compile.ts +2 -1
- package/src/utils/options.ts +26 -6
- package/src/ui/inspector/icon.svg +0 -5
package/dist/index.d.ts
CHANGED
|
@@ -46,11 +46,13 @@ interface Options {
|
|
|
46
46
|
*/
|
|
47
47
|
emitCss?: boolean;
|
|
48
48
|
/**
|
|
49
|
-
* The options to be passed to the Svelte compiler
|
|
49
|
+
* The options to be passed to the Svelte compiler. A few options are set by default,
|
|
50
|
+
* including `dev` and `css`. However, some options are non-configurable, like
|
|
51
|
+
* `filename`, `format`, `generate`, and `cssHash` (in dev).
|
|
50
52
|
*
|
|
51
53
|
* @see https://svelte.dev/docs#svelte_compile
|
|
52
54
|
*/
|
|
53
|
-
compilerOptions?: CompileOptions
|
|
55
|
+
compilerOptions?: Omit<CompileOptions, 'filename' | 'format' | 'generate'>;
|
|
54
56
|
/**
|
|
55
57
|
* Handles warning emitted from the Svelte compiler
|
|
56
58
|
*/
|
package/dist/index.js
CHANGED
|
@@ -26,7 +26,7 @@ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require
|
|
|
26
26
|
});
|
|
27
27
|
|
|
28
28
|
// src/index.ts
|
|
29
|
-
import
|
|
29
|
+
import fs8 from "fs";
|
|
30
30
|
|
|
31
31
|
// src/utils/log.ts
|
|
32
32
|
import { cyan, yellow, red } from "kleur/colors";
|
|
@@ -280,7 +280,8 @@ var _createCompileSvelte = (makeHot) => async function compileSvelte2(svelteRequ
|
|
|
280
280
|
const dependencies = [];
|
|
281
281
|
const compileOptions = __spreadProps(__spreadValues({}, options.compilerOptions), {
|
|
282
282
|
filename,
|
|
283
|
-
generate: ssr ? "ssr" : "dom"
|
|
283
|
+
generate: ssr ? "ssr" : "dom",
|
|
284
|
+
format: "esm"
|
|
284
285
|
});
|
|
285
286
|
if (options.hot && options.emitCss) {
|
|
286
287
|
const hash = `s-${safeBase64Hash(normalizedFilename)}`;
|
|
@@ -571,7 +572,7 @@ function findRootSvelteDependencies(root, cwdFallback = true) {
|
|
|
571
572
|
].filter((dep) => !is_common_without_svelte_field(dep));
|
|
572
573
|
return getSvelteDependencies(deps, root);
|
|
573
574
|
}
|
|
574
|
-
function getSvelteDependencies(deps, pkgDir,
|
|
575
|
+
function getSvelteDependencies(deps, pkgDir, path9 = []) {
|
|
575
576
|
const result = [];
|
|
576
577
|
const localRequire = createRequire2(`${pkgDir}/package.json`);
|
|
577
578
|
const resolvedDeps = deps.map((dep) => resolveDependencyData(dep, localRequire)).filter(Boolean);
|
|
@@ -579,18 +580,18 @@ function getSvelteDependencies(deps, pkgDir, path8 = []) {
|
|
|
579
580
|
const type = getSvelteDependencyType(pkg);
|
|
580
581
|
if (!type)
|
|
581
582
|
continue;
|
|
582
|
-
result.push({ name: pkg.name, type, pkg, dir, path:
|
|
583
|
+
result.push({ name: pkg.name, type, pkg, dir, path: path9 });
|
|
583
584
|
if (type === "component-library" && pkg.dependencies) {
|
|
584
585
|
let dependencyNames = Object.keys(pkg.dependencies);
|
|
585
|
-
const circular = dependencyNames.filter((name) =>
|
|
586
|
+
const circular = dependencyNames.filter((name) => path9.includes(name));
|
|
586
587
|
if (circular.length > 0) {
|
|
587
|
-
log.warn.enabled && log.warn(`skipping circular svelte dependencies in automated vite optimizeDeps handling`, circular.map((x) =>
|
|
588
|
-
dependencyNames = dependencyNames.filter((name) => !
|
|
588
|
+
log.warn.enabled && log.warn(`skipping circular svelte dependencies in automated vite optimizeDeps handling`, circular.map((x) => path9.concat(x).join(">")));
|
|
589
|
+
dependencyNames = dependencyNames.filter((name) => !path9.includes(name));
|
|
589
590
|
}
|
|
590
|
-
if (
|
|
591
|
-
log.debug.once(`encountered deep svelte dependency tree: ${
|
|
591
|
+
if (path9.length === 3) {
|
|
592
|
+
log.debug.once(`encountered deep svelte dependency tree: ${path9.join(">")}`);
|
|
592
593
|
}
|
|
593
|
-
result.push(...getSvelteDependencies(dependencyNames, dir,
|
|
594
|
+
result.push(...getSvelteDependencies(dependencyNames, dir, path9.concat(pkg.name)));
|
|
594
595
|
}
|
|
595
596
|
}
|
|
596
597
|
return result;
|
|
@@ -1083,10 +1084,7 @@ async function preResolveOptions(inlineOptions = {}, viteUserConfig, viteEnv) {
|
|
|
1083
1084
|
});
|
|
1084
1085
|
const defaultOptions = {
|
|
1085
1086
|
extensions: [".svelte"],
|
|
1086
|
-
emitCss: true
|
|
1087
|
-
compilerOptions: {
|
|
1088
|
-
format: "esm"
|
|
1089
|
-
}
|
|
1087
|
+
emitCss: true
|
|
1090
1088
|
};
|
|
1091
1089
|
const svelteConfig = await loadSvelteConfig(viteConfigWithResolvedRoot, inlineOptions);
|
|
1092
1090
|
const extraOptions = {
|
|
@@ -1123,6 +1121,7 @@ function resolveOptions(preResolveOptions2, viteConfig) {
|
|
|
1123
1121
|
isProduction: viteConfig.isProduction
|
|
1124
1122
|
};
|
|
1125
1123
|
const merged = mergeConfigs(defaultOptions, preResolveOptions2, extraOptions);
|
|
1124
|
+
removeIgnoredOptions(merged);
|
|
1126
1125
|
addExtraPreprocessors(merged, viteConfig);
|
|
1127
1126
|
enforceOptionsForHmr(merged);
|
|
1128
1127
|
enforceOptionsForProduction(merged);
|
|
@@ -1171,6 +1170,20 @@ function enforceOptionsForProduction(options) {
|
|
|
1171
1170
|
}
|
|
1172
1171
|
}
|
|
1173
1172
|
}
|
|
1173
|
+
function removeIgnoredOptions(options) {
|
|
1174
|
+
const ignoredCompilerOptions = ["generate", "format", "filename"];
|
|
1175
|
+
if (options.hot && options.emitCss) {
|
|
1176
|
+
ignoredCompilerOptions.push("cssHash");
|
|
1177
|
+
}
|
|
1178
|
+
const passedCompilerOptions = Object.keys(options.compilerOptions || {});
|
|
1179
|
+
const passedIgnored = passedCompilerOptions.filter((o) => ignoredCompilerOptions.includes(o));
|
|
1180
|
+
if (passedIgnored.length) {
|
|
1181
|
+
log.warn(`The following Svelte compilerOptions are controlled by vite-plugin-svelte and essential to its functionality. User-specified values are ignored. Please remove them from your configuration: ${passedIgnored.join(", ")}`);
|
|
1182
|
+
passedIgnored.forEach((ignored) => {
|
|
1183
|
+
delete options.compilerOptions[ignored];
|
|
1184
|
+
});
|
|
1185
|
+
}
|
|
1186
|
+
}
|
|
1174
1187
|
function resolveViteRoot(viteConfig) {
|
|
1175
1188
|
return normalizePath2(viteConfig.root ? path4.resolve(viteConfig.root) : process.cwd());
|
|
1176
1189
|
}
|
|
@@ -1340,8 +1353,8 @@ var VitePluginSvelteCache = class {
|
|
|
1340
1353
|
return this._js.get(svelteRequest.normalizedFilename);
|
|
1341
1354
|
}
|
|
1342
1355
|
}
|
|
1343
|
-
getDependants(
|
|
1344
|
-
const dependants = this._dependants.get(
|
|
1356
|
+
getDependants(path9) {
|
|
1357
|
+
const dependants = this._dependants.get(path9);
|
|
1345
1358
|
return dependants ? [...dependants] : [];
|
|
1346
1359
|
}
|
|
1347
1360
|
getResolvedSvelteField(name, importer) {
|
|
@@ -1506,7 +1519,10 @@ function generateSvelteMetadata(options) {
|
|
|
1506
1519
|
}
|
|
1507
1520
|
|
|
1508
1521
|
// src/ui/inspector/plugin.ts
|
|
1509
|
-
import {
|
|
1522
|
+
import { normalizePath as normalizePath3 } from "vite";
|
|
1523
|
+
import path8 from "path";
|
|
1524
|
+
import { fileURLToPath } from "url";
|
|
1525
|
+
import fs7 from "fs";
|
|
1510
1526
|
var defaultInspectorOptions = {
|
|
1511
1527
|
toggleKeyCombo: process.platform === "win32" ? "control-shift" : "meta-shift",
|
|
1512
1528
|
holdMode: false,
|
|
@@ -1514,11 +1530,16 @@ var defaultInspectorOptions = {
|
|
|
1514
1530
|
toggleButtonPos: "top-right",
|
|
1515
1531
|
customStyles: true
|
|
1516
1532
|
};
|
|
1533
|
+
function getInspectorPath() {
|
|
1534
|
+
const pluginPath = normalizePath3(path8.dirname(fileURLToPath(import.meta.url)));
|
|
1535
|
+
return pluginPath.replace(/\/vite-plugin-svelte\/dist$/, "/vite-plugin-svelte/src/ui/inspector/");
|
|
1536
|
+
}
|
|
1517
1537
|
function svelteInspector() {
|
|
1518
|
-
|
|
1519
|
-
|
|
1538
|
+
const inspectorPath = getInspectorPath();
|
|
1539
|
+
log.debug.enabled && log.debug(`svelte inspector path: ${inspectorPath}`);
|
|
1520
1540
|
let inspectorOptions;
|
|
1521
|
-
let
|
|
1541
|
+
let appendTo;
|
|
1542
|
+
let disabled = false;
|
|
1522
1543
|
return {
|
|
1523
1544
|
name: "vite-plugin-svelte:inspector",
|
|
1524
1545
|
apply: "serve",
|
|
@@ -1530,51 +1551,49 @@ function svelteInspector() {
|
|
|
1530
1551
|
inspectorOptions = __spreadValues(__spreadValues({}, defaultInspectorOptions), vps.api.options.experimental.inspector);
|
|
1531
1552
|
}
|
|
1532
1553
|
if (!vps || !inspectorOptions) {
|
|
1533
|
-
|
|
1534
|
-
|
|
1554
|
+
log.debug("inspector disabled, could not find config");
|
|
1555
|
+
disabled = true;
|
|
1535
1556
|
} else {
|
|
1536
|
-
root = config.root || process.cwd();
|
|
1537
|
-
rootRequire = createRequire5(root);
|
|
1538
1557
|
if (vps.api.options.kit && !inspectorOptions.appendTo) {
|
|
1539
|
-
const out_dir = vps.api.options.kit.outDir || ".svelte-kit";
|
|
1558
|
+
const out_dir = path8.basename(vps.api.options.kit.outDir || ".svelte-kit");
|
|
1540
1559
|
inspectorOptions.appendTo = `${out_dir}/runtime/client/start.js`;
|
|
1541
1560
|
}
|
|
1542
|
-
|
|
1561
|
+
appendTo = inspectorOptions.appendTo;
|
|
1543
1562
|
}
|
|
1544
1563
|
},
|
|
1545
1564
|
async resolveId(importee, importer, options) {
|
|
1546
|
-
if (options == null ? void 0 : options.ssr) {
|
|
1565
|
+
if ((options == null ? void 0 : options.ssr) || disabled) {
|
|
1547
1566
|
return;
|
|
1548
1567
|
}
|
|
1549
|
-
if (importee
|
|
1568
|
+
if (importee.startsWith("virtual:svelte-inspector-options")) {
|
|
1550
1569
|
return importee;
|
|
1551
|
-
}
|
|
1552
|
-
|
|
1553
|
-
|
|
1554
|
-
|
|
1555
|
-
if (path8) {
|
|
1556
|
-
return path8;
|
|
1557
|
-
} else {
|
|
1558
|
-
log.error.once(`failed to resolve ${file} for ${importee} from ${root}`);
|
|
1559
|
-
}
|
|
1570
|
+
} else if (importee.startsWith("virtual:svelte-inspector-path:")) {
|
|
1571
|
+
const resolved = importee.replace("virtual:svelte-inspector-path:", inspectorPath);
|
|
1572
|
+
log.debug.enabled && log.debug(`resolved ${importee} with ${resolved}`);
|
|
1573
|
+
return resolved;
|
|
1560
1574
|
}
|
|
1561
1575
|
},
|
|
1562
|
-
load(id) {
|
|
1576
|
+
async load(id, options) {
|
|
1577
|
+
if ((options == null ? void 0 : options.ssr) || disabled) {
|
|
1578
|
+
return;
|
|
1579
|
+
}
|
|
1563
1580
|
if (id === "virtual:svelte-inspector-options") {
|
|
1564
1581
|
return `export default ${JSON.stringify(inspectorOptions ?? {})}`;
|
|
1582
|
+
} else if (id.startsWith(inspectorPath)) {
|
|
1583
|
+
return await fs7.promises.readFile(id, "utf-8");
|
|
1565
1584
|
}
|
|
1566
1585
|
},
|
|
1567
1586
|
transform(code, id, options) {
|
|
1568
|
-
if ((options == null ? void 0 : options.ssr) || !
|
|
1587
|
+
if ((options == null ? void 0 : options.ssr) || disabled || !appendTo) {
|
|
1569
1588
|
return;
|
|
1570
1589
|
}
|
|
1571
|
-
if (id.endsWith(
|
|
1590
|
+
if (id.endsWith(appendTo)) {
|
|
1572
1591
|
return { code: `${code}
|
|
1573
|
-
import 'virtual:svelte-inspector:load-inspector.
|
|
1592
|
+
import 'virtual:svelte-inspector-path:load-inspector.js'` };
|
|
1574
1593
|
}
|
|
1575
1594
|
},
|
|
1576
1595
|
transformIndexHtml(html) {
|
|
1577
|
-
if (
|
|
1596
|
+
if (disabled || appendTo) {
|
|
1578
1597
|
return;
|
|
1579
1598
|
}
|
|
1580
1599
|
return {
|
|
@@ -1585,7 +1604,7 @@ import 'virtual:svelte-inspector:load-inspector.ts'` };
|
|
|
1585
1604
|
injectTo: "body",
|
|
1586
1605
|
attrs: {
|
|
1587
1606
|
type: "module",
|
|
1588
|
-
src: "/@id/virtual:svelte-inspector:load-inspector.
|
|
1607
|
+
src: "/@id/virtual:svelte-inspector-path:load-inspector.js"
|
|
1589
1608
|
}
|
|
1590
1609
|
}
|
|
1591
1610
|
]
|
|
@@ -1659,7 +1678,7 @@ function svelte(inlineOptions) {
|
|
|
1659
1678
|
}
|
|
1660
1679
|
if (viteConfig.assetsInclude(filename)) {
|
|
1661
1680
|
log.debug(`load returns raw content for ${filename}`);
|
|
1662
|
-
return
|
|
1681
|
+
return fs8.readFileSync(filename, "utf-8");
|
|
1663
1682
|
}
|
|
1664
1683
|
}
|
|
1665
1684
|
},
|