@sveltejs/vite-plugin-svelte 1.0.0-next.43 → 1.0.0-next.44

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.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 fs7 from "fs";
29
+ import fs8 from "fs";
30
30
 
31
31
  // src/utils/log.ts
32
32
  import { cyan, yellow, red } from "kleur/colors";
@@ -571,7 +571,7 @@ function findRootSvelteDependencies(root, cwdFallback = true) {
571
571
  ].filter((dep) => !is_common_without_svelte_field(dep));
572
572
  return getSvelteDependencies(deps, root);
573
573
  }
574
- function getSvelteDependencies(deps, pkgDir, path8 = []) {
574
+ function getSvelteDependencies(deps, pkgDir, path9 = []) {
575
575
  const result = [];
576
576
  const localRequire = createRequire2(`${pkgDir}/package.json`);
577
577
  const resolvedDeps = deps.map((dep) => resolveDependencyData(dep, localRequire)).filter(Boolean);
@@ -579,18 +579,18 @@ function getSvelteDependencies(deps, pkgDir, path8 = []) {
579
579
  const type = getSvelteDependencyType(pkg);
580
580
  if (!type)
581
581
  continue;
582
- result.push({ name: pkg.name, type, pkg, dir, path: path8 });
582
+ result.push({ name: pkg.name, type, pkg, dir, path: path9 });
583
583
  if (type === "component-library" && pkg.dependencies) {
584
584
  let dependencyNames = Object.keys(pkg.dependencies);
585
- const circular = dependencyNames.filter((name) => path8.includes(name));
585
+ const circular = dependencyNames.filter((name) => path9.includes(name));
586
586
  if (circular.length > 0) {
587
- log.warn.enabled && log.warn(`skipping circular svelte dependencies in automated vite optimizeDeps handling`, circular.map((x) => path8.concat(x).join(">")));
588
- dependencyNames = dependencyNames.filter((name) => !path8.includes(name));
587
+ log.warn.enabled && log.warn(`skipping circular svelte dependencies in automated vite optimizeDeps handling`, circular.map((x) => path9.concat(x).join(">")));
588
+ dependencyNames = dependencyNames.filter((name) => !path9.includes(name));
589
589
  }
590
- if (path8.length === 3) {
591
- log.debug.once(`encountered deep svelte dependency tree: ${path8.join(">")}`);
590
+ if (path9.length === 3) {
591
+ log.debug.once(`encountered deep svelte dependency tree: ${path9.join(">")}`);
592
592
  }
593
- result.push(...getSvelteDependencies(dependencyNames, dir, path8.concat(pkg.name)));
593
+ result.push(...getSvelteDependencies(dependencyNames, dir, path9.concat(pkg.name)));
594
594
  }
595
595
  }
596
596
  return result;
@@ -1340,8 +1340,8 @@ var VitePluginSvelteCache = class {
1340
1340
  return this._js.get(svelteRequest.normalizedFilename);
1341
1341
  }
1342
1342
  }
1343
- getDependants(path8) {
1344
- const dependants = this._dependants.get(path8);
1343
+ getDependants(path9) {
1344
+ const dependants = this._dependants.get(path9);
1345
1345
  return dependants ? [...dependants] : [];
1346
1346
  }
1347
1347
  getResolvedSvelteField(name, importer) {
@@ -1506,7 +1506,10 @@ function generateSvelteMetadata(options) {
1506
1506
  }
1507
1507
 
1508
1508
  // src/ui/inspector/plugin.ts
1509
- import { createRequire as createRequire5 } from "module";
1509
+ import { normalizePath as normalizePath3 } from "vite";
1510
+ import path8 from "path";
1511
+ import { fileURLToPath } from "url";
1512
+ import fs7 from "fs";
1510
1513
  var defaultInspectorOptions = {
1511
1514
  toggleKeyCombo: process.platform === "win32" ? "control-shift" : "meta-shift",
1512
1515
  holdMode: false,
@@ -1514,11 +1517,16 @@ var defaultInspectorOptions = {
1514
1517
  toggleButtonPos: "top-right",
1515
1518
  customStyles: true
1516
1519
  };
1520
+ function getInspectorPath() {
1521
+ const pluginPath = normalizePath3(path8.dirname(fileURLToPath(import.meta.url)));
1522
+ return pluginPath.replace(/\/vite-plugin-svelte\/dist$/, "/vite-plugin-svelte/src/ui/inspector/");
1523
+ }
1517
1524
  function svelteInspector() {
1518
- let root;
1519
- let rootRequire;
1525
+ const inspectorPath = getInspectorPath();
1526
+ log.debug.enabled && log.debug(`svelte inspector path: ${inspectorPath}`);
1520
1527
  let inspectorOptions;
1521
- let append_to;
1528
+ let appendTo;
1529
+ let disabled = false;
1522
1530
  return {
1523
1531
  name: "vite-plugin-svelte:inspector",
1524
1532
  apply: "serve",
@@ -1530,51 +1538,49 @@ function svelteInspector() {
1530
1538
  inspectorOptions = __spreadValues(__spreadValues({}, defaultInspectorOptions), vps.api.options.experimental.inspector);
1531
1539
  }
1532
1540
  if (!vps || !inspectorOptions) {
1533
- this.resolveId = this.load = this.transformIndexHtml = this.transform = () => {
1534
- };
1541
+ log.debug("inspector disabled, could not find config");
1542
+ disabled = true;
1535
1543
  } else {
1536
- root = config.root || process.cwd();
1537
- rootRequire = createRequire5(root);
1538
1544
  if (vps.api.options.kit && !inspectorOptions.appendTo) {
1539
1545
  const out_dir = vps.api.options.kit.outDir || ".svelte-kit";
1540
1546
  inspectorOptions.appendTo = `${out_dir}/runtime/client/start.js`;
1541
1547
  }
1542
- append_to = inspectorOptions.appendTo;
1548
+ appendTo = inspectorOptions.appendTo;
1543
1549
  }
1544
1550
  },
1545
1551
  async resolveId(importee, importer, options) {
1546
- if (options == null ? void 0 : options.ssr) {
1552
+ if ((options == null ? void 0 : options.ssr) || disabled) {
1547
1553
  return;
1548
1554
  }
1549
- if (importee === "virtual:svelte-inspector-options") {
1555
+ if (importee.startsWith("virtual:svelte-inspector-options")) {
1550
1556
  return importee;
1551
- }
1552
- if (importee.startsWith("virtual:svelte-inspector:")) {
1553
- const file = importee.replace("virtual:svelte-inspector:", "@sveltejs/vite-plugin-svelte/src/ui/inspector/");
1554
- const path8 = rootRequire.resolve(file);
1555
- if (path8) {
1556
- return path8;
1557
- } else {
1558
- log.error.once(`failed to resolve ${file} for ${importee} from ${root}`);
1559
- }
1557
+ } else if (importee.startsWith("virtual:svelte-inspector-path:")) {
1558
+ const resolved = importee.replace("virtual:svelte-inspector-path:", inspectorPath);
1559
+ log.debug.enabled && log.debug(`resolved ${importee} with ${resolved}`);
1560
+ return resolved;
1560
1561
  }
1561
1562
  },
1562
- load(id) {
1563
+ async load(id, options) {
1564
+ if ((options == null ? void 0 : options.ssr) || disabled) {
1565
+ return;
1566
+ }
1563
1567
  if (id === "virtual:svelte-inspector-options") {
1564
1568
  return `export default ${JSON.stringify(inspectorOptions ?? {})}`;
1569
+ } else if (id.startsWith(inspectorPath)) {
1570
+ return await fs7.promises.readFile(id, "utf-8");
1565
1571
  }
1566
1572
  },
1567
1573
  transform(code, id, options) {
1568
- if ((options == null ? void 0 : options.ssr) || !append_to) {
1574
+ if ((options == null ? void 0 : options.ssr) || disabled || !appendTo) {
1569
1575
  return;
1570
1576
  }
1571
- if (id.endsWith(append_to)) {
1577
+ if (id.endsWith(appendTo)) {
1572
1578
  return { code: `${code}
1573
- import 'virtual:svelte-inspector:load-inspector.ts'` };
1579
+ import 'virtual:svelte-inspector-path:load-inspector.js'` };
1574
1580
  }
1575
1581
  },
1576
1582
  transformIndexHtml(html) {
1577
- if (append_to) {
1583
+ if (disabled || appendTo) {
1578
1584
  return;
1579
1585
  }
1580
1586
  return {
@@ -1585,7 +1591,7 @@ import 'virtual:svelte-inspector:load-inspector.ts'` };
1585
1591
  injectTo: "body",
1586
1592
  attrs: {
1587
1593
  type: "module",
1588
- src: "/@id/virtual:svelte-inspector:load-inspector.ts"
1594
+ src: "/@id/virtual:svelte-inspector-path:load-inspector.js"
1589
1595
  }
1590
1596
  }
1591
1597
  ]
@@ -1659,7 +1665,7 @@ function svelte(inlineOptions) {
1659
1665
  }
1660
1666
  if (viteConfig.assetsInclude(filename)) {
1661
1667
  log.debug(`load returns raw content for ${filename}`);
1662
- return fs7.readFileSync(filename, "utf-8");
1668
+ return fs8.readFileSync(filename, "utf-8");
1663
1669
  }
1664
1670
  }
1665
1671
  },