@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 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.8/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");
@@ -302,7 +302,8 @@ var _createCompileSvelte = (makeHot) => async function compileSvelte2(svelteRequ
302
302
  const dependencies = [];
303
303
  const compileOptions = __spreadProps(__spreadValues({}, options.compilerOptions), {
304
304
  filename,
305
- generate: ssr ? "ssr" : "dom"
305
+ generate: ssr ? "ssr" : "dom",
306
+ format: "esm"
306
307
  });
307
308
  if (options.hot && options.emitCss) {
308
309
  const hash = `s-${safeBase64Hash(normalizedFilename)}`;
@@ -591,7 +592,7 @@ function findRootSvelteDependencies(root, cwdFallback = true) {
591
592
  ].filter((dep) => !is_common_without_svelte_field(dep));
592
593
  return getSvelteDependencies(deps, root);
593
594
  }
594
- function getSvelteDependencies(deps, pkgDir, path8 = []) {
595
+ function getSvelteDependencies(deps, pkgDir, path9 = []) {
595
596
  const result = [];
596
597
  const localRequire = (0, import_module2.createRequire)(`${pkgDir}/package.json`);
597
598
  const resolvedDeps = deps.map((dep) => resolveDependencyData(dep, localRequire)).filter(Boolean);
@@ -599,18 +600,18 @@ function getSvelteDependencies(deps, pkgDir, path8 = []) {
599
600
  const type = getSvelteDependencyType(pkg);
600
601
  if (!type)
601
602
  continue;
602
- result.push({ name: pkg.name, type, pkg, dir, path: path8 });
603
+ result.push({ name: pkg.name, type, pkg, dir, path: path9 });
603
604
  if (type === "component-library" && pkg.dependencies) {
604
605
  let dependencyNames = Object.keys(pkg.dependencies);
605
- const circular = dependencyNames.filter((name) => path8.includes(name));
606
+ const circular = dependencyNames.filter((name) => path9.includes(name));
606
607
  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));
608
+ log.warn.enabled && log.warn(`skipping circular svelte dependencies in automated vite optimizeDeps handling`, circular.map((x) => path9.concat(x).join(">")));
609
+ dependencyNames = dependencyNames.filter((name) => !path9.includes(name));
609
610
  }
610
- if (path8.length === 3) {
611
- log.debug.once(`encountered deep svelte dependency tree: ${path8.join(">")}`);
611
+ if (path9.length === 3) {
612
+ log.debug.once(`encountered deep svelte dependency tree: ${path9.join(">")}`);
612
613
  }
613
- result.push(...getSvelteDependencies(dependencyNames, dir, path8.concat(pkg.name)));
614
+ result.push(...getSvelteDependencies(dependencyNames, dir, path9.concat(pkg.name)));
614
615
  }
615
616
  }
616
617
  return result;
@@ -1101,10 +1102,7 @@ async function preResolveOptions(inlineOptions = {}, viteUserConfig, viteEnv) {
1101
1102
  });
1102
1103
  const defaultOptions = {
1103
1104
  extensions: [".svelte"],
1104
- emitCss: true,
1105
- compilerOptions: {
1106
- format: "esm"
1107
- }
1105
+ emitCss: true
1108
1106
  };
1109
1107
  const svelteConfig = await loadSvelteConfig(viteConfigWithResolvedRoot, inlineOptions);
1110
1108
  const extraOptions = {
@@ -1141,6 +1139,7 @@ function resolveOptions(preResolveOptions2, viteConfig) {
1141
1139
  isProduction: viteConfig.isProduction
1142
1140
  };
1143
1141
  const merged = mergeConfigs(defaultOptions, preResolveOptions2, extraOptions);
1142
+ removeIgnoredOptions(merged);
1144
1143
  addExtraPreprocessors(merged, viteConfig);
1145
1144
  enforceOptionsForHmr(merged);
1146
1145
  enforceOptionsForProduction(merged);
@@ -1189,6 +1188,20 @@ function enforceOptionsForProduction(options) {
1189
1188
  }
1190
1189
  }
1191
1190
  }
1191
+ function removeIgnoredOptions(options) {
1192
+ const ignoredCompilerOptions = ["generate", "format", "filename"];
1193
+ if (options.hot && options.emitCss) {
1194
+ ignoredCompilerOptions.push("cssHash");
1195
+ }
1196
+ const passedCompilerOptions = Object.keys(options.compilerOptions || {});
1197
+ const passedIgnored = passedCompilerOptions.filter((o) => ignoredCompilerOptions.includes(o));
1198
+ if (passedIgnored.length) {
1199
+ 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(", ")}`);
1200
+ passedIgnored.forEach((ignored) => {
1201
+ delete options.compilerOptions[ignored];
1202
+ });
1203
+ }
1204
+ }
1192
1205
  function resolveViteRoot(viteConfig) {
1193
1206
  return (0, import_vite3.normalizePath)(viteConfig.root ? import_path4.default.resolve(viteConfig.root) : process.cwd());
1194
1207
  }
@@ -1358,8 +1371,8 @@ var VitePluginSvelteCache = class {
1358
1371
  return this._js.get(svelteRequest.normalizedFilename);
1359
1372
  }
1360
1373
  }
1361
- getDependants(path8) {
1362
- const dependants = this._dependants.get(path8);
1374
+ getDependants(path9) {
1375
+ const dependants = this._dependants.get(path9);
1363
1376
  return dependants ? [...dependants] : [];
1364
1377
  }
1365
1378
  getResolvedSvelteField(name, importer) {
@@ -1524,7 +1537,10 @@ function generateSvelteMetadata(options) {
1524
1537
  }
1525
1538
 
1526
1539
  // src/ui/inspector/plugin.ts
1527
- var import_module5 = require("module");
1540
+ var import_vite4 = require("vite");
1541
+ var import_path8 = __toESM(require("path"), 1);
1542
+ var import_url2 = require("url");
1543
+ var import_fs6 = __toESM(require("fs"), 1);
1528
1544
  var defaultInspectorOptions = {
1529
1545
  toggleKeyCombo: process.platform === "win32" ? "control-shift" : "meta-shift",
1530
1546
  holdMode: false,
@@ -1532,11 +1548,16 @@ var defaultInspectorOptions = {
1532
1548
  toggleButtonPos: "top-right",
1533
1549
  customStyles: true
1534
1550
  };
1551
+ function getInspectorPath() {
1552
+ const pluginPath = (0, import_vite4.normalizePath)(import_path8.default.dirname((0, import_url2.fileURLToPath)(importMetaUrl)));
1553
+ return pluginPath.replace(/\/vite-plugin-svelte\/dist$/, "/vite-plugin-svelte/src/ui/inspector/");
1554
+ }
1535
1555
  function svelteInspector() {
1536
- let root;
1537
- let rootRequire;
1556
+ const inspectorPath = getInspectorPath();
1557
+ log.debug.enabled && log.debug(`svelte inspector path: ${inspectorPath}`);
1538
1558
  let inspectorOptions;
1539
- let append_to;
1559
+ let appendTo;
1560
+ let disabled = false;
1540
1561
  return {
1541
1562
  name: "vite-plugin-svelte:inspector",
1542
1563
  apply: "serve",
@@ -1548,51 +1569,49 @@ function svelteInspector() {
1548
1569
  inspectorOptions = __spreadValues(__spreadValues({}, defaultInspectorOptions), vps.api.options.experimental.inspector);
1549
1570
  }
1550
1571
  if (!vps || !inspectorOptions) {
1551
- this.resolveId = this.load = this.transformIndexHtml = this.transform = () => {
1552
- };
1572
+ log.debug("inspector disabled, could not find config");
1573
+ disabled = true;
1553
1574
  } else {
1554
- root = config.root || process.cwd();
1555
- rootRequire = (0, import_module5.createRequire)(root);
1556
1575
  if (vps.api.options.kit && !inspectorOptions.appendTo) {
1557
- const out_dir = vps.api.options.kit.outDir || ".svelte-kit";
1576
+ const out_dir = import_path8.default.basename(vps.api.options.kit.outDir || ".svelte-kit");
1558
1577
  inspectorOptions.appendTo = `${out_dir}/runtime/client/start.js`;
1559
1578
  }
1560
- append_to = inspectorOptions.appendTo;
1579
+ appendTo = inspectorOptions.appendTo;
1561
1580
  }
1562
1581
  },
1563
1582
  async resolveId(importee, importer, options) {
1564
- if (options == null ? void 0 : options.ssr) {
1583
+ if ((options == null ? void 0 : options.ssr) || disabled) {
1565
1584
  return;
1566
1585
  }
1567
- if (importee === "virtual:svelte-inspector-options") {
1586
+ if (importee.startsWith("virtual:svelte-inspector-options")) {
1568
1587
  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
- }
1588
+ } else if (importee.startsWith("virtual:svelte-inspector-path:")) {
1589
+ const resolved = importee.replace("virtual:svelte-inspector-path:", inspectorPath);
1590
+ log.debug.enabled && log.debug(`resolved ${importee} with ${resolved}`);
1591
+ return resolved;
1578
1592
  }
1579
1593
  },
1580
- load(id) {
1594
+ async load(id, options) {
1595
+ if ((options == null ? void 0 : options.ssr) || disabled) {
1596
+ return;
1597
+ }
1581
1598
  if (id === "virtual:svelte-inspector-options") {
1582
1599
  return `export default ${JSON.stringify(inspectorOptions ?? {})}`;
1600
+ } else if (id.startsWith(inspectorPath)) {
1601
+ return await import_fs6.default.promises.readFile(id, "utf-8");
1583
1602
  }
1584
1603
  },
1585
1604
  transform(code, id, options) {
1586
- if ((options == null ? void 0 : options.ssr) || !append_to) {
1605
+ if ((options == null ? void 0 : options.ssr) || disabled || !appendTo) {
1587
1606
  return;
1588
1607
  }
1589
- if (id.endsWith(append_to)) {
1608
+ if (id.endsWith(appendTo)) {
1590
1609
  return { code: `${code}
1591
- import 'virtual:svelte-inspector:load-inspector.ts'` };
1610
+ import 'virtual:svelte-inspector-path:load-inspector.js'` };
1592
1611
  }
1593
1612
  },
1594
1613
  transformIndexHtml(html) {
1595
- if (append_to) {
1614
+ if (disabled || appendTo) {
1596
1615
  return;
1597
1616
  }
1598
1617
  return {
@@ -1603,7 +1622,7 @@ import 'virtual:svelte-inspector:load-inspector.ts'` };
1603
1622
  injectTo: "body",
1604
1623
  attrs: {
1605
1624
  type: "module",
1606
- src: "/@id/virtual:svelte-inspector:load-inspector.ts"
1625
+ src: "/@id/virtual:svelte-inspector-path:load-inspector.js"
1607
1626
  }
1608
1627
  }
1609
1628
  ]
@@ -1677,7 +1696,7 @@ function svelte(inlineOptions) {
1677
1696
  }
1678
1697
  if (viteConfig.assetsInclude(filename)) {
1679
1698
  log.debug(`load returns raw content for ${filename}`);
1680
- return import_fs6.default.readFileSync(filename, "utf-8");
1699
+ return import_fs7.default.readFileSync(filename, "utf-8");
1681
1700
  }
1682
1701
  }
1683
1702
  },