@sveltejs/vite-plugin-svelte 1.0.0-next.42 → 1.0.0-next.45

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");
@@ -294,14 +294,16 @@ function toSafe(base64) {
294
294
  }
295
295
 
296
296
  // src/utils/compile.ts
297
+ var scriptLangRE = /<script [^>]*lang=["']?([^"' >]+)["']?[^>]*>/;
297
298
  var _createCompileSvelte = (makeHot) => async function compileSvelte2(svelteRequest, code, options) {
298
- var _a, _b;
299
+ var _a, _b, _c;
299
300
  const { filename, normalizedFilename, cssId, ssr } = svelteRequest;
300
301
  const { emitCss = true } = options;
301
302
  const dependencies = [];
302
303
  const compileOptions = __spreadProps(__spreadValues({}, options.compilerOptions), {
303
304
  filename,
304
- generate: ssr ? "ssr" : "dom"
305
+ generate: ssr ? "ssr" : "dom",
306
+ format: "esm"
305
307
  });
306
308
  if (options.hot && options.emitCss) {
307
309
  const hash = `s-${safeBase64Hash(normalizedFilename)}`;
@@ -358,6 +360,7 @@ import ${JSON.stringify(cssId)};
358
360
  return {
359
361
  filename,
360
362
  normalizedFilename,
363
+ lang: ((_c = code.match(scriptLangRE)) == null ? void 0 : _c[1]) || "js",
361
364
  compiled,
362
365
  ssr,
363
366
  dependencies
@@ -589,7 +592,7 @@ function findRootSvelteDependencies(root, cwdFallback = true) {
589
592
  ].filter((dep) => !is_common_without_svelte_field(dep));
590
593
  return getSvelteDependencies(deps, root);
591
594
  }
592
- function getSvelteDependencies(deps, pkgDir, path8 = []) {
595
+ function getSvelteDependencies(deps, pkgDir, path9 = []) {
593
596
  const result = [];
594
597
  const localRequire = (0, import_module2.createRequire)(`${pkgDir}/package.json`);
595
598
  const resolvedDeps = deps.map((dep) => resolveDependencyData(dep, localRequire)).filter(Boolean);
@@ -597,18 +600,18 @@ function getSvelteDependencies(deps, pkgDir, path8 = []) {
597
600
  const type = getSvelteDependencyType(pkg);
598
601
  if (!type)
599
602
  continue;
600
- result.push({ name: pkg.name, type, pkg, dir, path: path8 });
603
+ result.push({ name: pkg.name, type, pkg, dir, path: path9 });
601
604
  if (type === "component-library" && pkg.dependencies) {
602
605
  let dependencyNames = Object.keys(pkg.dependencies);
603
- const circular = dependencyNames.filter((name) => path8.includes(name));
606
+ const circular = dependencyNames.filter((name) => path9.includes(name));
604
607
  if (circular.length > 0) {
605
- log.warn.enabled && log.warn(`skipping circular svelte dependencies in automated vite optimizeDeps handling`, circular.map((x) => path8.concat(x).join(">")));
606
- 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));
607
610
  }
608
- if (path8.length === 3) {
609
- 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(">")}`);
610
613
  }
611
- result.push(...getSvelteDependencies(dependencyNames, dir, path8.concat(pkg.name)));
614
+ result.push(...getSvelteDependencies(dependencyNames, dir, path9.concat(pkg.name)));
612
615
  }
613
616
  }
614
617
  return result;
@@ -1071,6 +1074,7 @@ function validateSourceMapOutputWrapper(group, i) {
1071
1074
  }
1072
1075
 
1073
1076
  // src/utils/options.ts
1077
+ var import_deepmerge = __toESM(require("deepmerge"), 1);
1074
1078
  var knownOptions = /* @__PURE__ */ new Set([
1075
1079
  "configFile",
1076
1080
  "include",
@@ -1083,7 +1087,8 @@ var knownOptions = /* @__PURE__ */ new Set([
1083
1087
  "hot",
1084
1088
  "ignorePluginPreprocessors",
1085
1089
  "disableDependencyReinclusion",
1086
- "experimental"
1090
+ "experimental",
1091
+ "kit"
1087
1092
  ]);
1088
1093
  function validateInlineOptions(inlineOptions) {
1089
1094
  const invalidKeys = Object.keys(inlineOptions || {}).filter((key) => !knownOptions.has(key));
@@ -1097,25 +1102,30 @@ async function preResolveOptions(inlineOptions = {}, viteUserConfig, viteEnv) {
1097
1102
  });
1098
1103
  const defaultOptions = {
1099
1104
  extensions: [".svelte"],
1100
- emitCss: true,
1101
- compilerOptions: {
1102
- format: "esm"
1103
- }
1105
+ emitCss: true
1104
1106
  };
1105
1107
  const svelteConfig = await loadSvelteConfig(viteConfigWithResolvedRoot, inlineOptions);
1106
- const merged = __spreadProps(__spreadValues(__spreadValues(__spreadValues({}, defaultOptions), svelteConfig), inlineOptions), {
1107
- compilerOptions: __spreadValues(__spreadValues(__spreadValues({}, defaultOptions == null ? void 0 : defaultOptions.compilerOptions), svelteConfig == null ? void 0 : svelteConfig.compilerOptions), inlineOptions == null ? void 0 : inlineOptions.compilerOptions),
1108
- experimental: __spreadValues(__spreadValues(__spreadValues({}, defaultOptions == null ? void 0 : defaultOptions.experimental), svelteConfig == null ? void 0 : svelteConfig.experimental), inlineOptions == null ? void 0 : inlineOptions.experimental),
1108
+ const extraOptions = {
1109
1109
  root: viteConfigWithResolvedRoot.root,
1110
1110
  isBuild: viteEnv.command === "build",
1111
1111
  isServe: viteEnv.command === "serve",
1112
1112
  isDebug: process.env.DEBUG != null
1113
- });
1113
+ };
1114
+ const merged = mergeConfigs(defaultOptions, svelteConfig, inlineOptions, extraOptions);
1114
1115
  if (svelteConfig == null ? void 0 : svelteConfig.configFile) {
1115
1116
  merged.configFile = svelteConfig.configFile;
1116
1117
  }
1117
1118
  return merged;
1118
1119
  }
1120
+ function mergeConfigs(...configs) {
1121
+ let result = {};
1122
+ for (const config of configs.filter(Boolean)) {
1123
+ result = (0, import_deepmerge.default)(result, config, {
1124
+ arrayMerge: (target, source) => source ?? target
1125
+ });
1126
+ }
1127
+ return result;
1128
+ }
1119
1129
  function resolveOptions(preResolveOptions2, viteConfig) {
1120
1130
  const defaultOptions = {
1121
1131
  hot: viteConfig.isProduction ? false : { injectCss: !preResolveOptions2.emitCss },
@@ -1124,11 +1134,12 @@ function resolveOptions(preResolveOptions2, viteConfig) {
1124
1134
  dev: !viteConfig.isProduction
1125
1135
  }
1126
1136
  };
1127
- const merged = __spreadProps(__spreadValues(__spreadValues({}, defaultOptions), preResolveOptions2), {
1128
- compilerOptions: __spreadValues(__spreadValues({}, defaultOptions.compilerOptions), preResolveOptions2.compilerOptions),
1137
+ const extraOptions = {
1129
1138
  root: viteConfig.root,
1130
1139
  isProduction: viteConfig.isProduction
1131
- });
1140
+ };
1141
+ const merged = mergeConfigs(defaultOptions, preResolveOptions2, extraOptions);
1142
+ removeIgnoredOptions(merged);
1132
1143
  addExtraPreprocessors(merged, viteConfig);
1133
1144
  enforceOptionsForHmr(merged);
1134
1145
  enforceOptionsForProduction(merged);
@@ -1177,10 +1188,25 @@ function enforceOptionsForProduction(options) {
1177
1188
  }
1178
1189
  }
1179
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
+ }
1180
1205
  function resolveViteRoot(viteConfig) {
1181
1206
  return (0, import_vite3.normalizePath)(viteConfig.root ? import_path4.default.resolve(viteConfig.root) : process.cwd());
1182
1207
  }
1183
1208
  function buildExtraViteConfig(options, config) {
1209
+ var _a;
1184
1210
  const svelteDeps = findRootSvelteDependencies(options.root);
1185
1211
  const extraViteConfig = {
1186
1212
  resolve: {
@@ -1191,7 +1217,7 @@ function buildExtraViteConfig(options, config) {
1191
1217
  if (options.isServe) {
1192
1218
  extraViteConfig.optimizeDeps = buildOptimizeDepsForSvelte(svelteDeps, options, config.optimizeDeps);
1193
1219
  }
1194
- if (options.experimental.prebundleSvelteLibraries) {
1220
+ if ((_a = options.experimental) == null ? void 0 : _a.prebundleSvelteLibraries) {
1195
1221
  extraViteConfig.optimizeDeps = __spreadProps(__spreadValues({}, extraViteConfig.optimizeDeps), {
1196
1222
  extensions: options.extensions ?? [".svelte"],
1197
1223
  esbuildOptions: {
@@ -1204,15 +1230,16 @@ function buildExtraViteConfig(options, config) {
1204
1230
  return extraViteConfig;
1205
1231
  }
1206
1232
  function buildOptimizeDepsForSvelte(svelteDeps, options, optimizeDeps) {
1233
+ var _a;
1207
1234
  const include = [];
1208
1235
  const exclude = ["svelte-hmr"];
1209
1236
  const isIncluded = (dep) => {
1210
- var _a;
1211
- return include.includes(dep) || ((_a = optimizeDeps == null ? void 0 : optimizeDeps.include) == null ? void 0 : _a.includes(dep));
1237
+ var _a2;
1238
+ return include.includes(dep) || ((_a2 = optimizeDeps == null ? void 0 : optimizeDeps.include) == null ? void 0 : _a2.includes(dep));
1212
1239
  };
1213
1240
  const isExcluded = (dep) => {
1214
- var _a;
1215
- return exclude.includes(dep) || ((_a = optimizeDeps == null ? void 0 : optimizeDeps.exclude) == null ? void 0 : _a.some((id) => dep === id || id.startsWith(`${dep}/`)));
1241
+ var _a2;
1242
+ return exclude.includes(dep) || ((_a2 = optimizeDeps == null ? void 0 : optimizeDeps.exclude) == null ? void 0 : _a2.some((id) => dep === id || id.startsWith(`${dep}/`)));
1216
1243
  };
1217
1244
  if (!isExcluded("svelte")) {
1218
1245
  const svelteImportsToInclude = SVELTE_IMPORTS.filter((x) => x !== "svelte/ssr");
@@ -1221,7 +1248,7 @@ function buildOptimizeDepsForSvelte(svelteDeps, options, optimizeDeps) {
1221
1248
  } else {
1222
1249
  log.debug('"svelte" is excluded in optimizeDeps.exclude, skipped adding it to include.');
1223
1250
  }
1224
- if (options.experimental.prebundleSvelteLibraries) {
1251
+ if ((_a = options.experimental) == null ? void 0 : _a.prebundleSvelteLibraries) {
1225
1252
  return { include, exclude };
1226
1253
  }
1227
1254
  svelteDeps = svelteDeps.filter((dep) => dep.type === "component-library");
@@ -1344,8 +1371,8 @@ var VitePluginSvelteCache = class {
1344
1371
  return this._js.get(svelteRequest.normalizedFilename);
1345
1372
  }
1346
1373
  }
1347
- getDependants(path8) {
1348
- const dependants = this._dependants.get(path8);
1374
+ getDependants(path9) {
1375
+ const dependants = this._dependants.get(path9);
1349
1376
  return dependants ? [...dependants] : [];
1350
1377
  }
1351
1378
  getResolvedSvelteField(name, importer) {
@@ -1400,27 +1427,29 @@ function setupWatchers(options, cache, requestParser) {
1400
1427
  server.restart();
1401
1428
  }
1402
1429
  };
1403
- const possibleSvelteConfigs = knownSvelteConfigNames.map((cfg) => import_path5.default.join(root, cfg));
1404
- const restartOnConfigAdd = (filename) => {
1405
- if (possibleSvelteConfigs.includes(filename)) {
1406
- triggerViteRestart(filename);
1407
- }
1408
- };
1409
- const restartOnConfigChange = (filename) => {
1410
- if (filename === svelteConfigFile) {
1411
- triggerViteRestart(filename);
1412
- }
1413
- };
1414
1430
  const listenerCollection = {
1415
1431
  add: [],
1416
1432
  change: [emitChangeEventOnDependants],
1417
1433
  unlink: [removeUnlinkedFromCache, emitChangeEventOnDependants]
1418
1434
  };
1419
- if (svelteConfigFile) {
1420
- listenerCollection.change.push(restartOnConfigChange);
1421
- listenerCollection.unlink.push(restartOnConfigChange);
1422
- } else {
1423
- listenerCollection.add.push(restartOnConfigAdd);
1435
+ if (svelteConfigFile !== false) {
1436
+ const possibleSvelteConfigs = knownSvelteConfigNames.map((cfg) => import_path5.default.join(root, cfg));
1437
+ const restartOnConfigAdd = (filename) => {
1438
+ if (possibleSvelteConfigs.includes(filename)) {
1439
+ triggerViteRestart(filename);
1440
+ }
1441
+ };
1442
+ const restartOnConfigChange = (filename) => {
1443
+ if (filename === svelteConfigFile) {
1444
+ triggerViteRestart(filename);
1445
+ }
1446
+ };
1447
+ if (svelteConfigFile) {
1448
+ listenerCollection.change.push(restartOnConfigChange);
1449
+ listenerCollection.unlink.push(restartOnConfigChange);
1450
+ } else {
1451
+ listenerCollection.add.push(restartOnConfigAdd);
1452
+ }
1424
1453
  }
1425
1454
  Object.entries(listenerCollection).forEach(([evt, listeners]) => {
1426
1455
  if (listeners.length > 0) {
@@ -1507,6 +1536,101 @@ function generateSvelteMetadata(options) {
1507
1536
  return metadata;
1508
1537
  }
1509
1538
 
1539
+ // src/ui/inspector/plugin.ts
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);
1544
+ var defaultInspectorOptions = {
1545
+ toggleKeyCombo: process.platform === "win32" ? "control-shift" : "meta-shift",
1546
+ holdMode: false,
1547
+ showToggleButton: "active",
1548
+ toggleButtonPos: "top-right",
1549
+ customStyles: true
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
+ }
1555
+ function svelteInspector() {
1556
+ const inspectorPath = getInspectorPath();
1557
+ log.debug.enabled && log.debug(`svelte inspector path: ${inspectorPath}`);
1558
+ let inspectorOptions;
1559
+ let appendTo;
1560
+ let disabled = false;
1561
+ return {
1562
+ name: "vite-plugin-svelte:inspector",
1563
+ apply: "serve",
1564
+ enforce: "pre",
1565
+ configResolved(config) {
1566
+ var _a, _b, _c;
1567
+ const vps = config.plugins.find((p) => p.name === "vite-plugin-svelte");
1568
+ if ((_c = (_b = (_a = vps == null ? void 0 : vps.api) == null ? void 0 : _a.options) == null ? void 0 : _b.experimental) == null ? void 0 : _c.inspector) {
1569
+ inspectorOptions = __spreadValues(__spreadValues({}, defaultInspectorOptions), vps.api.options.experimental.inspector);
1570
+ }
1571
+ if (!vps || !inspectorOptions) {
1572
+ log.debug("inspector disabled, could not find config");
1573
+ disabled = true;
1574
+ } else {
1575
+ if (vps.api.options.kit && !inspectorOptions.appendTo) {
1576
+ const out_dir = import_path8.default.basename(vps.api.options.kit.outDir || ".svelte-kit");
1577
+ inspectorOptions.appendTo = `${out_dir}/runtime/client/start.js`;
1578
+ }
1579
+ appendTo = inspectorOptions.appendTo;
1580
+ }
1581
+ },
1582
+ async resolveId(importee, importer, options) {
1583
+ if ((options == null ? void 0 : options.ssr) || disabled) {
1584
+ return;
1585
+ }
1586
+ if (importee.startsWith("virtual:svelte-inspector-options")) {
1587
+ return importee;
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;
1592
+ }
1593
+ },
1594
+ async load(id, options) {
1595
+ if ((options == null ? void 0 : options.ssr) || disabled) {
1596
+ return;
1597
+ }
1598
+ if (id === "virtual:svelte-inspector-options") {
1599
+ return `export default ${JSON.stringify(inspectorOptions ?? {})}`;
1600
+ } else if (id.startsWith(inspectorPath)) {
1601
+ return await import_fs6.default.promises.readFile(id, "utf-8");
1602
+ }
1603
+ },
1604
+ transform(code, id, options) {
1605
+ if ((options == null ? void 0 : options.ssr) || disabled || !appendTo) {
1606
+ return;
1607
+ }
1608
+ if (id.endsWith(appendTo)) {
1609
+ return { code: `${code}
1610
+ import 'virtual:svelte-inspector-path:load-inspector.js'` };
1611
+ }
1612
+ },
1613
+ transformIndexHtml(html) {
1614
+ if (disabled || appendTo) {
1615
+ return;
1616
+ }
1617
+ return {
1618
+ html,
1619
+ tags: [
1620
+ {
1621
+ tag: "script",
1622
+ injectTo: "body",
1623
+ attrs: {
1624
+ type: "module",
1625
+ src: "/@id/virtual:svelte-inspector-path:load-inspector.js"
1626
+ }
1627
+ }
1628
+ ]
1629
+ };
1630
+ }
1631
+ };
1632
+ }
1633
+
1510
1634
  // src/index.ts
1511
1635
  function svelte(inlineOptions) {
1512
1636
  if (process.env.DEBUG != null) {
@@ -1519,124 +1643,138 @@ function svelte(inlineOptions) {
1519
1643
  let viteConfig;
1520
1644
  let compileSvelte2;
1521
1645
  let resolvedSvelteSSR;
1522
- return {
1523
- name: "vite-plugin-svelte",
1524
- enforce: "pre",
1525
- async config(config, configEnv) {
1526
- if (process.env.DEBUG) {
1527
- log.setLevel("debug");
1528
- } else if (config.logLevel) {
1529
- log.setLevel(config.logLevel);
1530
- }
1531
- options = await preResolveOptions(inlineOptions, config, configEnv);
1532
- const extraViteConfig = buildExtraViteConfig(options, config);
1533
- log.debug("additional vite config", extraViteConfig);
1534
- return extraViteConfig;
1535
- },
1536
- async configResolved(config) {
1537
- options = resolveOptions(options, config);
1538
- patchResolvedViteConfig(config, options);
1539
- requestParser = buildIdParser(options);
1540
- compileSvelte2 = createCompileSvelte(options);
1541
- viteConfig = config;
1542
- log.debug("resolved options", options);
1543
- },
1544
- async buildStart() {
1545
- if (!options.experimental.prebundleSvelteLibraries)
1546
- return;
1547
- const isSvelteMetadataChanged = await saveSvelteMetadata(viteConfig.cacheDir, options);
1548
- if (isSvelteMetadataChanged) {
1549
- viteConfig.server.force = true;
1550
- }
1551
- },
1552
- configureServer(server) {
1553
- options.server = server;
1554
- setupWatchers(options, cache, requestParser);
1555
- },
1556
- load(id, opts) {
1557
- const ssr = opts === true || (opts == null ? void 0 : opts.ssr);
1558
- const svelteRequest = requestParser(id, !!ssr);
1559
- if (svelteRequest) {
1560
- const { filename, query } = svelteRequest;
1561
- if (query.svelte && query.type === "style") {
1562
- const css = cache.getCSS(svelteRequest);
1563
- if (css) {
1564
- log.debug(`load returns css for ${filename}`);
1565
- return css;
1646
+ const api = {};
1647
+ const plugins = [
1648
+ {
1649
+ name: "vite-plugin-svelte",
1650
+ enforce: "pre",
1651
+ api,
1652
+ async config(config, configEnv) {
1653
+ if (process.env.DEBUG) {
1654
+ log.setLevel("debug");
1655
+ } else if (config.logLevel) {
1656
+ log.setLevel(config.logLevel);
1657
+ }
1658
+ options = await preResolveOptions(inlineOptions, config, configEnv);
1659
+ const extraViteConfig = buildExtraViteConfig(options, config);
1660
+ log.debug("additional vite config", extraViteConfig);
1661
+ return extraViteConfig;
1662
+ },
1663
+ async configResolved(config) {
1664
+ options = resolveOptions(options, config);
1665
+ patchResolvedViteConfig(config, options);
1666
+ requestParser = buildIdParser(options);
1667
+ compileSvelte2 = createCompileSvelte(options);
1668
+ viteConfig = config;
1669
+ api.options = options;
1670
+ log.debug("resolved options", options);
1671
+ },
1672
+ async buildStart() {
1673
+ var _a;
1674
+ if (!((_a = options.experimental) == null ? void 0 : _a.prebundleSvelteLibraries))
1675
+ return;
1676
+ const isSvelteMetadataChanged = await saveSvelteMetadata(viteConfig.cacheDir, options);
1677
+ if (isSvelteMetadataChanged) {
1678
+ viteConfig.server.force = true;
1679
+ }
1680
+ },
1681
+ configureServer(server) {
1682
+ options.server = server;
1683
+ setupWatchers(options, cache, requestParser);
1684
+ },
1685
+ load(id, opts) {
1686
+ const ssr = opts === true || (opts == null ? void 0 : opts.ssr);
1687
+ const svelteRequest = requestParser(id, !!ssr);
1688
+ if (svelteRequest) {
1689
+ const { filename, query } = svelteRequest;
1690
+ if (query.svelte && query.type === "style") {
1691
+ const css = cache.getCSS(svelteRequest);
1692
+ if (css) {
1693
+ log.debug(`load returns css for ${filename}`);
1694
+ return css;
1695
+ }
1696
+ }
1697
+ if (viteConfig.assetsInclude(filename)) {
1698
+ log.debug(`load returns raw content for ${filename}`);
1699
+ return import_fs7.default.readFileSync(filename, "utf-8");
1566
1700
  }
1567
1701
  }
1568
- if (viteConfig.assetsInclude(filename)) {
1569
- log.debug(`load returns raw content for ${filename}`);
1570
- return import_fs6.default.readFileSync(filename, "utf-8");
1702
+ },
1703
+ async resolveId(importee, importer, opts) {
1704
+ const ssr = !!(opts == null ? void 0 : opts.ssr);
1705
+ const svelteRequest = requestParser(importee, ssr);
1706
+ if (svelteRequest == null ? void 0 : svelteRequest.query.svelte) {
1707
+ if (svelteRequest.query.type === "style") {
1708
+ log.debug(`resolveId resolved virtual css module ${svelteRequest.cssId}`);
1709
+ return svelteRequest.cssId;
1710
+ }
1711
+ log.debug(`resolveId resolved ${importee}`);
1712
+ return importee;
1571
1713
  }
1572
- }
1573
- },
1574
- async resolveId(importee, importer, opts) {
1575
- const ssr = !!(opts == null ? void 0 : opts.ssr);
1576
- const svelteRequest = requestParser(importee, ssr);
1577
- if (svelteRequest == null ? void 0 : svelteRequest.query.svelte) {
1578
- if (svelteRequest.query.type === "style") {
1579
- log.debug(`resolveId resolved virtual css module ${svelteRequest.cssId}`);
1580
- return svelteRequest.cssId;
1714
+ if (ssr && importee === "svelte") {
1715
+ if (!resolvedSvelteSSR) {
1716
+ resolvedSvelteSSR = this.resolve("svelte/ssr", void 0, { skipSelf: true }).then((svelteSSR) => {
1717
+ log.debug("resolved svelte to svelte/ssr");
1718
+ return svelteSSR;
1719
+ }, (err) => {
1720
+ log.debug("failed to resolve svelte to svelte/ssr. Update svelte to a version that exports it", err);
1721
+ return null;
1722
+ });
1723
+ }
1724
+ return resolvedSvelteSSR;
1581
1725
  }
1582
- log.debug(`resolveId resolved ${importee}`);
1583
- return importee;
1584
- }
1585
- if (ssr && importee === "svelte") {
1586
- if (!resolvedSvelteSSR) {
1587
- resolvedSvelteSSR = this.resolve("svelte/ssr", void 0, { skipSelf: true }).then((svelteSSR) => {
1588
- log.debug("resolved svelte to svelte/ssr");
1589
- return svelteSSR;
1590
- }, (err) => {
1591
- log.debug("failed to resolve svelte to svelte/ssr. Update svelte to a version that exports it", err);
1592
- return null;
1593
- });
1726
+ try {
1727
+ const resolved = resolveViaPackageJsonSvelte(importee, importer, cache);
1728
+ if (resolved) {
1729
+ log.debug(`resolveId resolved ${resolved} via package.json svelte field of ${importee}`);
1730
+ return resolved;
1731
+ }
1732
+ } catch (e) {
1733
+ log.debug.once(`error trying to resolve ${importee} from ${importer} via package.json svelte field `, e);
1594
1734
  }
1595
- return resolvedSvelteSSR;
1596
- }
1597
- try {
1598
- const resolved = resolveViaPackageJsonSvelte(importee, importer, cache);
1599
- if (resolved) {
1600
- log.debug(`resolveId resolved ${resolved} via package.json svelte field of ${importee}`);
1601
- return resolved;
1735
+ },
1736
+ async transform(code, id, opts) {
1737
+ var _a;
1738
+ const ssr = !!(opts == null ? void 0 : opts.ssr);
1739
+ const svelteRequest = requestParser(id, ssr);
1740
+ if (!svelteRequest || svelteRequest.query.svelte) {
1741
+ return;
1602
1742
  }
1603
- } catch (e) {
1604
- log.debug.once(`error trying to resolve ${importee} from ${importer} via package.json svelte field `, e);
1605
- }
1606
- },
1607
- async transform(code, id, opts) {
1608
- var _a;
1609
- const ssr = !!(opts == null ? void 0 : opts.ssr);
1610
- const svelteRequest = requestParser(id, ssr);
1611
- if (!svelteRequest || svelteRequest.query.svelte) {
1612
- return;
1613
- }
1614
- let compileData;
1615
- try {
1616
- compileData = await compileSvelte2(svelteRequest, code, options);
1617
- } catch (e) {
1618
- throw toRollupError(e, options);
1619
- }
1620
- logCompilerWarnings(compileData.compiled.warnings, options);
1621
- cache.update(compileData);
1622
- if (((_a = compileData.dependencies) == null ? void 0 : _a.length) && options.server) {
1623
- compileData.dependencies.forEach((d) => {
1624
- ensureWatchedFile(options.server.watcher, d, options.root);
1743
+ let compileData;
1744
+ try {
1745
+ compileData = await compileSvelte2(svelteRequest, code, options);
1746
+ } catch (e) {
1747
+ throw toRollupError(e, options);
1748
+ }
1749
+ logCompilerWarnings(compileData.compiled.warnings, options);
1750
+ cache.update(compileData);
1751
+ if (((_a = compileData.dependencies) == null ? void 0 : _a.length) && options.server) {
1752
+ compileData.dependencies.forEach((d) => {
1753
+ ensureWatchedFile(options.server.watcher, d, options.root);
1754
+ });
1755
+ }
1756
+ log.debug(`transform returns compiled js for ${svelteRequest.filename}`);
1757
+ return __spreadProps(__spreadValues({}, compileData.compiled.js), {
1758
+ meta: {
1759
+ vite: {
1760
+ lang: compileData.lang
1761
+ }
1762
+ }
1625
1763
  });
1626
- }
1627
- log.debug(`transform returns compiled js for ${svelteRequest.filename}`);
1628
- return compileData.compiled.js;
1629
- },
1630
- handleHotUpdate(ctx) {
1631
- if (!options.hot || !options.emitCss) {
1632
- return;
1633
- }
1634
- const svelteRequest = requestParser(ctx.file, false, ctx.timestamp);
1635
- if (svelteRequest) {
1636
- return handleHotUpdate(compileSvelte2, ctx, svelteRequest, cache, options);
1764
+ },
1765
+ handleHotUpdate(ctx) {
1766
+ if (!options.hot || !options.emitCss) {
1767
+ return;
1768
+ }
1769
+ const svelteRequest = requestParser(ctx.file, false, ctx.timestamp);
1770
+ if (svelteRequest) {
1771
+ return handleHotUpdate(compileSvelte2, ctx, svelteRequest, cache, options);
1772
+ }
1637
1773
  }
1638
1774
  }
1639
- };
1775
+ ];
1776
+ plugins.push(svelteInspector());
1777
+ return plugins.filter(Boolean);
1640
1778
  }
1641
1779
  // Annotate the CommonJS export names for ESM import in node:
1642
1780
  0 && (module.exports = {