@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.cjs CHANGED
@@ -43,12 +43,12 @@ __export(src_exports, {
43
43
  });
44
44
  module.exports = __toCommonJS(src_exports);
45
45
 
46
- // ../../node_modules/.pnpm/tsup@5.12.5_typescript@4.6.3/node_modules/tsup/assets/cjs_shims.js
46
+ // ../../node_modules/.pnpm/tsup@5.12.7/node_modules/tsup/assets/cjs_shims.js
47
47
  var getImportMetaUrl = () => typeof document === "undefined" ? new URL("file:" + __filename).href : document.currentScript && document.currentScript.src || new URL("main.js", document.baseURI).href;
48
48
  var importMetaUrl = /* @__PURE__ */ getImportMetaUrl();
49
49
 
50
50
  // src/index.ts
51
- var import_fs6 = __toESM(require("fs"), 1);
51
+ var import_fs7 = __toESM(require("fs"), 1);
52
52
 
53
53
  // src/utils/log.ts
54
54
  var import_colors = require("kleur/colors");
@@ -591,7 +591,7 @@ function findRootSvelteDependencies(root, cwdFallback = true) {
591
591
  ].filter((dep) => !is_common_without_svelte_field(dep));
592
592
  return getSvelteDependencies(deps, root);
593
593
  }
594
- function getSvelteDependencies(deps, pkgDir, path8 = []) {
594
+ function getSvelteDependencies(deps, pkgDir, path9 = []) {
595
595
  const result = [];
596
596
  const localRequire = (0, import_module2.createRequire)(`${pkgDir}/package.json`);
597
597
  const resolvedDeps = deps.map((dep) => resolveDependencyData(dep, localRequire)).filter(Boolean);
@@ -599,18 +599,18 @@ function getSvelteDependencies(deps, pkgDir, path8 = []) {
599
599
  const type = getSvelteDependencyType(pkg);
600
600
  if (!type)
601
601
  continue;
602
- result.push({ name: pkg.name, type, pkg, dir, path: path8 });
602
+ result.push({ name: pkg.name, type, pkg, dir, path: path9 });
603
603
  if (type === "component-library" && pkg.dependencies) {
604
604
  let dependencyNames = Object.keys(pkg.dependencies);
605
- const circular = dependencyNames.filter((name) => path8.includes(name));
605
+ const circular = dependencyNames.filter((name) => path9.includes(name));
606
606
  if (circular.length > 0) {
607
- log.warn.enabled && log.warn(`skipping circular svelte dependencies in automated vite optimizeDeps handling`, circular.map((x) => path8.concat(x).join(">")));
608
- dependencyNames = dependencyNames.filter((name) => !path8.includes(name));
607
+ log.warn.enabled && log.warn(`skipping circular svelte dependencies in automated vite optimizeDeps handling`, circular.map((x) => path9.concat(x).join(">")));
608
+ dependencyNames = dependencyNames.filter((name) => !path9.includes(name));
609
609
  }
610
- if (path8.length === 3) {
611
- log.debug.once(`encountered deep svelte dependency tree: ${path8.join(">")}`);
610
+ if (path9.length === 3) {
611
+ log.debug.once(`encountered deep svelte dependency tree: ${path9.join(">")}`);
612
612
  }
613
- result.push(...getSvelteDependencies(dependencyNames, dir, path8.concat(pkg.name)));
613
+ result.push(...getSvelteDependencies(dependencyNames, dir, path9.concat(pkg.name)));
614
614
  }
615
615
  }
616
616
  return result;
@@ -1358,8 +1358,8 @@ var VitePluginSvelteCache = class {
1358
1358
  return this._js.get(svelteRequest.normalizedFilename);
1359
1359
  }
1360
1360
  }
1361
- getDependants(path8) {
1362
- const dependants = this._dependants.get(path8);
1361
+ getDependants(path9) {
1362
+ const dependants = this._dependants.get(path9);
1363
1363
  return dependants ? [...dependants] : [];
1364
1364
  }
1365
1365
  getResolvedSvelteField(name, importer) {
@@ -1524,7 +1524,10 @@ function generateSvelteMetadata(options) {
1524
1524
  }
1525
1525
 
1526
1526
  // src/ui/inspector/plugin.ts
1527
- var import_module5 = require("module");
1527
+ var import_vite4 = require("vite");
1528
+ var import_path8 = __toESM(require("path"), 1);
1529
+ var import_url2 = require("url");
1530
+ var import_fs6 = __toESM(require("fs"), 1);
1528
1531
  var defaultInspectorOptions = {
1529
1532
  toggleKeyCombo: process.platform === "win32" ? "control-shift" : "meta-shift",
1530
1533
  holdMode: false,
@@ -1532,11 +1535,16 @@ var defaultInspectorOptions = {
1532
1535
  toggleButtonPos: "top-right",
1533
1536
  customStyles: true
1534
1537
  };
1538
+ function getInspectorPath() {
1539
+ const pluginPath = (0, import_vite4.normalizePath)(import_path8.default.dirname((0, import_url2.fileURLToPath)(importMetaUrl)));
1540
+ return pluginPath.replace(/\/vite-plugin-svelte\/dist$/, "/vite-plugin-svelte/src/ui/inspector/");
1541
+ }
1535
1542
  function svelteInspector() {
1536
- let root;
1537
- let rootRequire;
1543
+ const inspectorPath = getInspectorPath();
1544
+ log.debug.enabled && log.debug(`svelte inspector path: ${inspectorPath}`);
1538
1545
  let inspectorOptions;
1539
- let append_to;
1546
+ let appendTo;
1547
+ let disabled = false;
1540
1548
  return {
1541
1549
  name: "vite-plugin-svelte:inspector",
1542
1550
  apply: "serve",
@@ -1548,51 +1556,49 @@ function svelteInspector() {
1548
1556
  inspectorOptions = __spreadValues(__spreadValues({}, defaultInspectorOptions), vps.api.options.experimental.inspector);
1549
1557
  }
1550
1558
  if (!vps || !inspectorOptions) {
1551
- this.resolveId = this.load = this.transformIndexHtml = this.transform = () => {
1552
- };
1559
+ log.debug("inspector disabled, could not find config");
1560
+ disabled = true;
1553
1561
  } else {
1554
- root = config.root || process.cwd();
1555
- rootRequire = (0, import_module5.createRequire)(root);
1556
1562
  if (vps.api.options.kit && !inspectorOptions.appendTo) {
1557
1563
  const out_dir = vps.api.options.kit.outDir || ".svelte-kit";
1558
1564
  inspectorOptions.appendTo = `${out_dir}/runtime/client/start.js`;
1559
1565
  }
1560
- append_to = inspectorOptions.appendTo;
1566
+ appendTo = inspectorOptions.appendTo;
1561
1567
  }
1562
1568
  },
1563
1569
  async resolveId(importee, importer, options) {
1564
- if (options == null ? void 0 : options.ssr) {
1570
+ if ((options == null ? void 0 : options.ssr) || disabled) {
1565
1571
  return;
1566
1572
  }
1567
- if (importee === "virtual:svelte-inspector-options") {
1573
+ if (importee.startsWith("virtual:svelte-inspector-options")) {
1568
1574
  return importee;
1569
- }
1570
- if (importee.startsWith("virtual:svelte-inspector:")) {
1571
- const file = importee.replace("virtual:svelte-inspector:", "@sveltejs/vite-plugin-svelte/src/ui/inspector/");
1572
- const path8 = rootRequire.resolve(file);
1573
- if (path8) {
1574
- return path8;
1575
- } else {
1576
- log.error.once(`failed to resolve ${file} for ${importee} from ${root}`);
1577
- }
1575
+ } else if (importee.startsWith("virtual:svelte-inspector-path:")) {
1576
+ const resolved = importee.replace("virtual:svelte-inspector-path:", inspectorPath);
1577
+ log.debug.enabled && log.debug(`resolved ${importee} with ${resolved}`);
1578
+ return resolved;
1578
1579
  }
1579
1580
  },
1580
- load(id) {
1581
+ async load(id, options) {
1582
+ if ((options == null ? void 0 : options.ssr) || disabled) {
1583
+ return;
1584
+ }
1581
1585
  if (id === "virtual:svelte-inspector-options") {
1582
1586
  return `export default ${JSON.stringify(inspectorOptions ?? {})}`;
1587
+ } else if (id.startsWith(inspectorPath)) {
1588
+ return await import_fs6.default.promises.readFile(id, "utf-8");
1583
1589
  }
1584
1590
  },
1585
1591
  transform(code, id, options) {
1586
- if ((options == null ? void 0 : options.ssr) || !append_to) {
1592
+ if ((options == null ? void 0 : options.ssr) || disabled || !appendTo) {
1587
1593
  return;
1588
1594
  }
1589
- if (id.endsWith(append_to)) {
1595
+ if (id.endsWith(appendTo)) {
1590
1596
  return { code: `${code}
1591
- import 'virtual:svelte-inspector:load-inspector.ts'` };
1597
+ import 'virtual:svelte-inspector-path:load-inspector.js'` };
1592
1598
  }
1593
1599
  },
1594
1600
  transformIndexHtml(html) {
1595
- if (append_to) {
1601
+ if (disabled || appendTo) {
1596
1602
  return;
1597
1603
  }
1598
1604
  return {
@@ -1603,7 +1609,7 @@ import 'virtual:svelte-inspector:load-inspector.ts'` };
1603
1609
  injectTo: "body",
1604
1610
  attrs: {
1605
1611
  type: "module",
1606
- src: "/@id/virtual:svelte-inspector:load-inspector.ts"
1612
+ src: "/@id/virtual:svelte-inspector-path:load-inspector.js"
1607
1613
  }
1608
1614
  }
1609
1615
  ]
@@ -1677,7 +1683,7 @@ function svelte(inlineOptions) {
1677
1683
  }
1678
1684
  if (viteConfig.assetsInclude(filename)) {
1679
1685
  log.debug(`load returns raw content for ${filename}`);
1680
- return import_fs6.default.readFileSync(filename, "utf-8");
1686
+ return import_fs7.default.readFileSync(filename, "utf-8");
1681
1687
  }
1682
1688
  }
1683
1689
  },