@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.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";
@@ -272,14 +272,16 @@ function toSafe(base64) {
272
272
  }
273
273
 
274
274
  // src/utils/compile.ts
275
+ var scriptLangRE = /<script [^>]*lang=["']?([^"' >]+)["']?[^>]*>/;
275
276
  var _createCompileSvelte = (makeHot) => async function compileSvelte2(svelteRequest, code, options) {
276
- var _a, _b;
277
+ var _a, _b, _c;
277
278
  const { filename, normalizedFilename, cssId, ssr } = svelteRequest;
278
279
  const { emitCss = true } = options;
279
280
  const dependencies = [];
280
281
  const compileOptions = __spreadProps(__spreadValues({}, options.compilerOptions), {
281
282
  filename,
282
- generate: ssr ? "ssr" : "dom"
283
+ generate: ssr ? "ssr" : "dom",
284
+ format: "esm"
283
285
  });
284
286
  if (options.hot && options.emitCss) {
285
287
  const hash = `s-${safeBase64Hash(normalizedFilename)}`;
@@ -336,6 +338,7 @@ import ${JSON.stringify(cssId)};
336
338
  return {
337
339
  filename,
338
340
  normalizedFilename,
341
+ lang: ((_c = code.match(scriptLangRE)) == null ? void 0 : _c[1]) || "js",
339
342
  compiled,
340
343
  ssr,
341
344
  dependencies
@@ -569,7 +572,7 @@ function findRootSvelteDependencies(root, cwdFallback = true) {
569
572
  ].filter((dep) => !is_common_without_svelte_field(dep));
570
573
  return getSvelteDependencies(deps, root);
571
574
  }
572
- function getSvelteDependencies(deps, pkgDir, path8 = []) {
575
+ function getSvelteDependencies(deps, pkgDir, path9 = []) {
573
576
  const result = [];
574
577
  const localRequire = createRequire2(`${pkgDir}/package.json`);
575
578
  const resolvedDeps = deps.map((dep) => resolveDependencyData(dep, localRequire)).filter(Boolean);
@@ -577,18 +580,18 @@ function getSvelteDependencies(deps, pkgDir, path8 = []) {
577
580
  const type = getSvelteDependencyType(pkg);
578
581
  if (!type)
579
582
  continue;
580
- result.push({ name: pkg.name, type, pkg, dir, path: path8 });
583
+ result.push({ name: pkg.name, type, pkg, dir, path: path9 });
581
584
  if (type === "component-library" && pkg.dependencies) {
582
585
  let dependencyNames = Object.keys(pkg.dependencies);
583
- const circular = dependencyNames.filter((name) => path8.includes(name));
586
+ const circular = dependencyNames.filter((name) => path9.includes(name));
584
587
  if (circular.length > 0) {
585
- log.warn.enabled && log.warn(`skipping circular svelte dependencies in automated vite optimizeDeps handling`, circular.map((x) => path8.concat(x).join(">")));
586
- dependencyNames = dependencyNames.filter((name) => !path8.includes(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));
587
590
  }
588
- if (path8.length === 3) {
589
- log.debug.once(`encountered deep svelte dependency tree: ${path8.join(">")}`);
591
+ if (path9.length === 3) {
592
+ log.debug.once(`encountered deep svelte dependency tree: ${path9.join(">")}`);
590
593
  }
591
- result.push(...getSvelteDependencies(dependencyNames, dir, path8.concat(pkg.name)));
594
+ result.push(...getSvelteDependencies(dependencyNames, dir, path9.concat(pkg.name)));
592
595
  }
593
596
  }
594
597
  return result;
@@ -1053,6 +1056,7 @@ function validateSourceMapOutputWrapper(group, i) {
1053
1056
  }
1054
1057
 
1055
1058
  // src/utils/options.ts
1059
+ import deepmerge from "deepmerge";
1056
1060
  var knownOptions = /* @__PURE__ */ new Set([
1057
1061
  "configFile",
1058
1062
  "include",
@@ -1065,7 +1069,8 @@ var knownOptions = /* @__PURE__ */ new Set([
1065
1069
  "hot",
1066
1070
  "ignorePluginPreprocessors",
1067
1071
  "disableDependencyReinclusion",
1068
- "experimental"
1072
+ "experimental",
1073
+ "kit"
1069
1074
  ]);
1070
1075
  function validateInlineOptions(inlineOptions) {
1071
1076
  const invalidKeys = Object.keys(inlineOptions || {}).filter((key) => !knownOptions.has(key));
@@ -1079,25 +1084,30 @@ async function preResolveOptions(inlineOptions = {}, viteUserConfig, viteEnv) {
1079
1084
  });
1080
1085
  const defaultOptions = {
1081
1086
  extensions: [".svelte"],
1082
- emitCss: true,
1083
- compilerOptions: {
1084
- format: "esm"
1085
- }
1087
+ emitCss: true
1086
1088
  };
1087
1089
  const svelteConfig = await loadSvelteConfig(viteConfigWithResolvedRoot, inlineOptions);
1088
- const merged = __spreadProps(__spreadValues(__spreadValues(__spreadValues({}, defaultOptions), svelteConfig), inlineOptions), {
1089
- compilerOptions: __spreadValues(__spreadValues(__spreadValues({}, defaultOptions == null ? void 0 : defaultOptions.compilerOptions), svelteConfig == null ? void 0 : svelteConfig.compilerOptions), inlineOptions == null ? void 0 : inlineOptions.compilerOptions),
1090
- experimental: __spreadValues(__spreadValues(__spreadValues({}, defaultOptions == null ? void 0 : defaultOptions.experimental), svelteConfig == null ? void 0 : svelteConfig.experimental), inlineOptions == null ? void 0 : inlineOptions.experimental),
1090
+ const extraOptions = {
1091
1091
  root: viteConfigWithResolvedRoot.root,
1092
1092
  isBuild: viteEnv.command === "build",
1093
1093
  isServe: viteEnv.command === "serve",
1094
1094
  isDebug: process.env.DEBUG != null
1095
- });
1095
+ };
1096
+ const merged = mergeConfigs(defaultOptions, svelteConfig, inlineOptions, extraOptions);
1096
1097
  if (svelteConfig == null ? void 0 : svelteConfig.configFile) {
1097
1098
  merged.configFile = svelteConfig.configFile;
1098
1099
  }
1099
1100
  return merged;
1100
1101
  }
1102
+ function mergeConfigs(...configs) {
1103
+ let result = {};
1104
+ for (const config of configs.filter(Boolean)) {
1105
+ result = deepmerge(result, config, {
1106
+ arrayMerge: (target, source) => source ?? target
1107
+ });
1108
+ }
1109
+ return result;
1110
+ }
1101
1111
  function resolveOptions(preResolveOptions2, viteConfig) {
1102
1112
  const defaultOptions = {
1103
1113
  hot: viteConfig.isProduction ? false : { injectCss: !preResolveOptions2.emitCss },
@@ -1106,11 +1116,12 @@ function resolveOptions(preResolveOptions2, viteConfig) {
1106
1116
  dev: !viteConfig.isProduction
1107
1117
  }
1108
1118
  };
1109
- const merged = __spreadProps(__spreadValues(__spreadValues({}, defaultOptions), preResolveOptions2), {
1110
- compilerOptions: __spreadValues(__spreadValues({}, defaultOptions.compilerOptions), preResolveOptions2.compilerOptions),
1119
+ const extraOptions = {
1111
1120
  root: viteConfig.root,
1112
1121
  isProduction: viteConfig.isProduction
1113
- });
1122
+ };
1123
+ const merged = mergeConfigs(defaultOptions, preResolveOptions2, extraOptions);
1124
+ removeIgnoredOptions(merged);
1114
1125
  addExtraPreprocessors(merged, viteConfig);
1115
1126
  enforceOptionsForHmr(merged);
1116
1127
  enforceOptionsForProduction(merged);
@@ -1159,10 +1170,25 @@ function enforceOptionsForProduction(options) {
1159
1170
  }
1160
1171
  }
1161
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
+ }
1162
1187
  function resolveViteRoot(viteConfig) {
1163
1188
  return normalizePath2(viteConfig.root ? path4.resolve(viteConfig.root) : process.cwd());
1164
1189
  }
1165
1190
  function buildExtraViteConfig(options, config) {
1191
+ var _a;
1166
1192
  const svelteDeps = findRootSvelteDependencies(options.root);
1167
1193
  const extraViteConfig = {
1168
1194
  resolve: {
@@ -1173,7 +1199,7 @@ function buildExtraViteConfig(options, config) {
1173
1199
  if (options.isServe) {
1174
1200
  extraViteConfig.optimizeDeps = buildOptimizeDepsForSvelte(svelteDeps, options, config.optimizeDeps);
1175
1201
  }
1176
- if (options.experimental.prebundleSvelteLibraries) {
1202
+ if ((_a = options.experimental) == null ? void 0 : _a.prebundleSvelteLibraries) {
1177
1203
  extraViteConfig.optimizeDeps = __spreadProps(__spreadValues({}, extraViteConfig.optimizeDeps), {
1178
1204
  extensions: options.extensions ?? [".svelte"],
1179
1205
  esbuildOptions: {
@@ -1186,15 +1212,16 @@ function buildExtraViteConfig(options, config) {
1186
1212
  return extraViteConfig;
1187
1213
  }
1188
1214
  function buildOptimizeDepsForSvelte(svelteDeps, options, optimizeDeps) {
1215
+ var _a;
1189
1216
  const include = [];
1190
1217
  const exclude = ["svelte-hmr"];
1191
1218
  const isIncluded = (dep) => {
1192
- var _a;
1193
- return include.includes(dep) || ((_a = optimizeDeps == null ? void 0 : optimizeDeps.include) == null ? void 0 : _a.includes(dep));
1219
+ var _a2;
1220
+ return include.includes(dep) || ((_a2 = optimizeDeps == null ? void 0 : optimizeDeps.include) == null ? void 0 : _a2.includes(dep));
1194
1221
  };
1195
1222
  const isExcluded = (dep) => {
1196
- var _a;
1197
- return exclude.includes(dep) || ((_a = optimizeDeps == null ? void 0 : optimizeDeps.exclude) == null ? void 0 : _a.some((id) => dep === id || id.startsWith(`${dep}/`)));
1223
+ var _a2;
1224
+ return exclude.includes(dep) || ((_a2 = optimizeDeps == null ? void 0 : optimizeDeps.exclude) == null ? void 0 : _a2.some((id) => dep === id || id.startsWith(`${dep}/`)));
1198
1225
  };
1199
1226
  if (!isExcluded("svelte")) {
1200
1227
  const svelteImportsToInclude = SVELTE_IMPORTS.filter((x) => x !== "svelte/ssr");
@@ -1203,7 +1230,7 @@ function buildOptimizeDepsForSvelte(svelteDeps, options, optimizeDeps) {
1203
1230
  } else {
1204
1231
  log.debug('"svelte" is excluded in optimizeDeps.exclude, skipped adding it to include.');
1205
1232
  }
1206
- if (options.experimental.prebundleSvelteLibraries) {
1233
+ if ((_a = options.experimental) == null ? void 0 : _a.prebundleSvelteLibraries) {
1207
1234
  return { include, exclude };
1208
1235
  }
1209
1236
  svelteDeps = svelteDeps.filter((dep) => dep.type === "component-library");
@@ -1326,8 +1353,8 @@ var VitePluginSvelteCache = class {
1326
1353
  return this._js.get(svelteRequest.normalizedFilename);
1327
1354
  }
1328
1355
  }
1329
- getDependants(path8) {
1330
- const dependants = this._dependants.get(path8);
1356
+ getDependants(path9) {
1357
+ const dependants = this._dependants.get(path9);
1331
1358
  return dependants ? [...dependants] : [];
1332
1359
  }
1333
1360
  getResolvedSvelteField(name, importer) {
@@ -1382,27 +1409,29 @@ function setupWatchers(options, cache, requestParser) {
1382
1409
  server.restart();
1383
1410
  }
1384
1411
  };
1385
- const possibleSvelteConfigs = knownSvelteConfigNames.map((cfg) => path5.join(root, cfg));
1386
- const restartOnConfigAdd = (filename) => {
1387
- if (possibleSvelteConfigs.includes(filename)) {
1388
- triggerViteRestart(filename);
1389
- }
1390
- };
1391
- const restartOnConfigChange = (filename) => {
1392
- if (filename === svelteConfigFile) {
1393
- triggerViteRestart(filename);
1394
- }
1395
- };
1396
1412
  const listenerCollection = {
1397
1413
  add: [],
1398
1414
  change: [emitChangeEventOnDependants],
1399
1415
  unlink: [removeUnlinkedFromCache, emitChangeEventOnDependants]
1400
1416
  };
1401
- if (svelteConfigFile) {
1402
- listenerCollection.change.push(restartOnConfigChange);
1403
- listenerCollection.unlink.push(restartOnConfigChange);
1404
- } else {
1405
- listenerCollection.add.push(restartOnConfigAdd);
1417
+ if (svelteConfigFile !== false) {
1418
+ const possibleSvelteConfigs = knownSvelteConfigNames.map((cfg) => path5.join(root, cfg));
1419
+ const restartOnConfigAdd = (filename) => {
1420
+ if (possibleSvelteConfigs.includes(filename)) {
1421
+ triggerViteRestart(filename);
1422
+ }
1423
+ };
1424
+ const restartOnConfigChange = (filename) => {
1425
+ if (filename === svelteConfigFile) {
1426
+ triggerViteRestart(filename);
1427
+ }
1428
+ };
1429
+ if (svelteConfigFile) {
1430
+ listenerCollection.change.push(restartOnConfigChange);
1431
+ listenerCollection.unlink.push(restartOnConfigChange);
1432
+ } else {
1433
+ listenerCollection.add.push(restartOnConfigAdd);
1434
+ }
1406
1435
  }
1407
1436
  Object.entries(listenerCollection).forEach(([evt, listeners]) => {
1408
1437
  if (listeners.length > 0) {
@@ -1489,6 +1518,101 @@ function generateSvelteMetadata(options) {
1489
1518
  return metadata;
1490
1519
  }
1491
1520
 
1521
+ // src/ui/inspector/plugin.ts
1522
+ import { normalizePath as normalizePath3 } from "vite";
1523
+ import path8 from "path";
1524
+ import { fileURLToPath } from "url";
1525
+ import fs7 from "fs";
1526
+ var defaultInspectorOptions = {
1527
+ toggleKeyCombo: process.platform === "win32" ? "control-shift" : "meta-shift",
1528
+ holdMode: false,
1529
+ showToggleButton: "active",
1530
+ toggleButtonPos: "top-right",
1531
+ customStyles: true
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
+ }
1537
+ function svelteInspector() {
1538
+ const inspectorPath = getInspectorPath();
1539
+ log.debug.enabled && log.debug(`svelte inspector path: ${inspectorPath}`);
1540
+ let inspectorOptions;
1541
+ let appendTo;
1542
+ let disabled = false;
1543
+ return {
1544
+ name: "vite-plugin-svelte:inspector",
1545
+ apply: "serve",
1546
+ enforce: "pre",
1547
+ configResolved(config) {
1548
+ var _a, _b, _c;
1549
+ const vps = config.plugins.find((p) => p.name === "vite-plugin-svelte");
1550
+ 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) {
1551
+ inspectorOptions = __spreadValues(__spreadValues({}, defaultInspectorOptions), vps.api.options.experimental.inspector);
1552
+ }
1553
+ if (!vps || !inspectorOptions) {
1554
+ log.debug("inspector disabled, could not find config");
1555
+ disabled = true;
1556
+ } else {
1557
+ if (vps.api.options.kit && !inspectorOptions.appendTo) {
1558
+ const out_dir = path8.basename(vps.api.options.kit.outDir || ".svelte-kit");
1559
+ inspectorOptions.appendTo = `${out_dir}/runtime/client/start.js`;
1560
+ }
1561
+ appendTo = inspectorOptions.appendTo;
1562
+ }
1563
+ },
1564
+ async resolveId(importee, importer, options) {
1565
+ if ((options == null ? void 0 : options.ssr) || disabled) {
1566
+ return;
1567
+ }
1568
+ if (importee.startsWith("virtual:svelte-inspector-options")) {
1569
+ return importee;
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;
1574
+ }
1575
+ },
1576
+ async load(id, options) {
1577
+ if ((options == null ? void 0 : options.ssr) || disabled) {
1578
+ return;
1579
+ }
1580
+ if (id === "virtual:svelte-inspector-options") {
1581
+ return `export default ${JSON.stringify(inspectorOptions ?? {})}`;
1582
+ } else if (id.startsWith(inspectorPath)) {
1583
+ return await fs7.promises.readFile(id, "utf-8");
1584
+ }
1585
+ },
1586
+ transform(code, id, options) {
1587
+ if ((options == null ? void 0 : options.ssr) || disabled || !appendTo) {
1588
+ return;
1589
+ }
1590
+ if (id.endsWith(appendTo)) {
1591
+ return { code: `${code}
1592
+ import 'virtual:svelte-inspector-path:load-inspector.js'` };
1593
+ }
1594
+ },
1595
+ transformIndexHtml(html) {
1596
+ if (disabled || appendTo) {
1597
+ return;
1598
+ }
1599
+ return {
1600
+ html,
1601
+ tags: [
1602
+ {
1603
+ tag: "script",
1604
+ injectTo: "body",
1605
+ attrs: {
1606
+ type: "module",
1607
+ src: "/@id/virtual:svelte-inspector-path:load-inspector.js"
1608
+ }
1609
+ }
1610
+ ]
1611
+ };
1612
+ }
1613
+ };
1614
+ }
1615
+
1492
1616
  // src/index.ts
1493
1617
  function svelte(inlineOptions) {
1494
1618
  if (process.env.DEBUG != null) {
@@ -1501,124 +1625,138 @@ function svelte(inlineOptions) {
1501
1625
  let viteConfig;
1502
1626
  let compileSvelte2;
1503
1627
  let resolvedSvelteSSR;
1504
- return {
1505
- name: "vite-plugin-svelte",
1506
- enforce: "pre",
1507
- async config(config, configEnv) {
1508
- if (process.env.DEBUG) {
1509
- log.setLevel("debug");
1510
- } else if (config.logLevel) {
1511
- log.setLevel(config.logLevel);
1512
- }
1513
- options = await preResolveOptions(inlineOptions, config, configEnv);
1514
- const extraViteConfig = buildExtraViteConfig(options, config);
1515
- log.debug("additional vite config", extraViteConfig);
1516
- return extraViteConfig;
1517
- },
1518
- async configResolved(config) {
1519
- options = resolveOptions(options, config);
1520
- patchResolvedViteConfig(config, options);
1521
- requestParser = buildIdParser(options);
1522
- compileSvelte2 = createCompileSvelte(options);
1523
- viteConfig = config;
1524
- log.debug("resolved options", options);
1525
- },
1526
- async buildStart() {
1527
- if (!options.experimental.prebundleSvelteLibraries)
1528
- return;
1529
- const isSvelteMetadataChanged = await saveSvelteMetadata(viteConfig.cacheDir, options);
1530
- if (isSvelteMetadataChanged) {
1531
- viteConfig.server.force = true;
1532
- }
1533
- },
1534
- configureServer(server) {
1535
- options.server = server;
1536
- setupWatchers(options, cache, requestParser);
1537
- },
1538
- load(id, opts) {
1539
- const ssr = opts === true || (opts == null ? void 0 : opts.ssr);
1540
- const svelteRequest = requestParser(id, !!ssr);
1541
- if (svelteRequest) {
1542
- const { filename, query } = svelteRequest;
1543
- if (query.svelte && query.type === "style") {
1544
- const css = cache.getCSS(svelteRequest);
1545
- if (css) {
1546
- log.debug(`load returns css for ${filename}`);
1547
- return css;
1628
+ const api = {};
1629
+ const plugins = [
1630
+ {
1631
+ name: "vite-plugin-svelte",
1632
+ enforce: "pre",
1633
+ api,
1634
+ async config(config, configEnv) {
1635
+ if (process.env.DEBUG) {
1636
+ log.setLevel("debug");
1637
+ } else if (config.logLevel) {
1638
+ log.setLevel(config.logLevel);
1639
+ }
1640
+ options = await preResolveOptions(inlineOptions, config, configEnv);
1641
+ const extraViteConfig = buildExtraViteConfig(options, config);
1642
+ log.debug("additional vite config", extraViteConfig);
1643
+ return extraViteConfig;
1644
+ },
1645
+ async configResolved(config) {
1646
+ options = resolveOptions(options, config);
1647
+ patchResolvedViteConfig(config, options);
1648
+ requestParser = buildIdParser(options);
1649
+ compileSvelte2 = createCompileSvelte(options);
1650
+ viteConfig = config;
1651
+ api.options = options;
1652
+ log.debug("resolved options", options);
1653
+ },
1654
+ async buildStart() {
1655
+ var _a;
1656
+ if (!((_a = options.experimental) == null ? void 0 : _a.prebundleSvelteLibraries))
1657
+ return;
1658
+ const isSvelteMetadataChanged = await saveSvelteMetadata(viteConfig.cacheDir, options);
1659
+ if (isSvelteMetadataChanged) {
1660
+ viteConfig.server.force = true;
1661
+ }
1662
+ },
1663
+ configureServer(server) {
1664
+ options.server = server;
1665
+ setupWatchers(options, cache, requestParser);
1666
+ },
1667
+ load(id, opts) {
1668
+ const ssr = opts === true || (opts == null ? void 0 : opts.ssr);
1669
+ const svelteRequest = requestParser(id, !!ssr);
1670
+ if (svelteRequest) {
1671
+ const { filename, query } = svelteRequest;
1672
+ if (query.svelte && query.type === "style") {
1673
+ const css = cache.getCSS(svelteRequest);
1674
+ if (css) {
1675
+ log.debug(`load returns css for ${filename}`);
1676
+ return css;
1677
+ }
1678
+ }
1679
+ if (viteConfig.assetsInclude(filename)) {
1680
+ log.debug(`load returns raw content for ${filename}`);
1681
+ return fs8.readFileSync(filename, "utf-8");
1548
1682
  }
1549
1683
  }
1550
- if (viteConfig.assetsInclude(filename)) {
1551
- log.debug(`load returns raw content for ${filename}`);
1552
- return fs7.readFileSync(filename, "utf-8");
1684
+ },
1685
+ async resolveId(importee, importer, opts) {
1686
+ const ssr = !!(opts == null ? void 0 : opts.ssr);
1687
+ const svelteRequest = requestParser(importee, ssr);
1688
+ if (svelteRequest == null ? void 0 : svelteRequest.query.svelte) {
1689
+ if (svelteRequest.query.type === "style") {
1690
+ log.debug(`resolveId resolved virtual css module ${svelteRequest.cssId}`);
1691
+ return svelteRequest.cssId;
1692
+ }
1693
+ log.debug(`resolveId resolved ${importee}`);
1694
+ return importee;
1553
1695
  }
1554
- }
1555
- },
1556
- async resolveId(importee, importer, opts) {
1557
- const ssr = !!(opts == null ? void 0 : opts.ssr);
1558
- const svelteRequest = requestParser(importee, ssr);
1559
- if (svelteRequest == null ? void 0 : svelteRequest.query.svelte) {
1560
- if (svelteRequest.query.type === "style") {
1561
- log.debug(`resolveId resolved virtual css module ${svelteRequest.cssId}`);
1562
- return svelteRequest.cssId;
1696
+ if (ssr && importee === "svelte") {
1697
+ if (!resolvedSvelteSSR) {
1698
+ resolvedSvelteSSR = this.resolve("svelte/ssr", void 0, { skipSelf: true }).then((svelteSSR) => {
1699
+ log.debug("resolved svelte to svelte/ssr");
1700
+ return svelteSSR;
1701
+ }, (err) => {
1702
+ log.debug("failed to resolve svelte to svelte/ssr. Update svelte to a version that exports it", err);
1703
+ return null;
1704
+ });
1705
+ }
1706
+ return resolvedSvelteSSR;
1563
1707
  }
1564
- log.debug(`resolveId resolved ${importee}`);
1565
- return importee;
1566
- }
1567
- if (ssr && importee === "svelte") {
1568
- if (!resolvedSvelteSSR) {
1569
- resolvedSvelteSSR = this.resolve("svelte/ssr", void 0, { skipSelf: true }).then((svelteSSR) => {
1570
- log.debug("resolved svelte to svelte/ssr");
1571
- return svelteSSR;
1572
- }, (err) => {
1573
- log.debug("failed to resolve svelte to svelte/ssr. Update svelte to a version that exports it", err);
1574
- return null;
1575
- });
1708
+ try {
1709
+ const resolved = resolveViaPackageJsonSvelte(importee, importer, cache);
1710
+ if (resolved) {
1711
+ log.debug(`resolveId resolved ${resolved} via package.json svelte field of ${importee}`);
1712
+ return resolved;
1713
+ }
1714
+ } catch (e) {
1715
+ log.debug.once(`error trying to resolve ${importee} from ${importer} via package.json svelte field `, e);
1576
1716
  }
1577
- return resolvedSvelteSSR;
1578
- }
1579
- try {
1580
- const resolved = resolveViaPackageJsonSvelte(importee, importer, cache);
1581
- if (resolved) {
1582
- log.debug(`resolveId resolved ${resolved} via package.json svelte field of ${importee}`);
1583
- return resolved;
1717
+ },
1718
+ async transform(code, id, opts) {
1719
+ var _a;
1720
+ const ssr = !!(opts == null ? void 0 : opts.ssr);
1721
+ const svelteRequest = requestParser(id, ssr);
1722
+ if (!svelteRequest || svelteRequest.query.svelte) {
1723
+ return;
1584
1724
  }
1585
- } catch (e) {
1586
- log.debug.once(`error trying to resolve ${importee} from ${importer} via package.json svelte field `, e);
1587
- }
1588
- },
1589
- async transform(code, id, opts) {
1590
- var _a;
1591
- const ssr = !!(opts == null ? void 0 : opts.ssr);
1592
- const svelteRequest = requestParser(id, ssr);
1593
- if (!svelteRequest || svelteRequest.query.svelte) {
1594
- return;
1595
- }
1596
- let compileData;
1597
- try {
1598
- compileData = await compileSvelte2(svelteRequest, code, options);
1599
- } catch (e) {
1600
- throw toRollupError(e, options);
1601
- }
1602
- logCompilerWarnings(compileData.compiled.warnings, options);
1603
- cache.update(compileData);
1604
- if (((_a = compileData.dependencies) == null ? void 0 : _a.length) && options.server) {
1605
- compileData.dependencies.forEach((d) => {
1606
- ensureWatchedFile(options.server.watcher, d, options.root);
1725
+ let compileData;
1726
+ try {
1727
+ compileData = await compileSvelte2(svelteRequest, code, options);
1728
+ } catch (e) {
1729
+ throw toRollupError(e, options);
1730
+ }
1731
+ logCompilerWarnings(compileData.compiled.warnings, options);
1732
+ cache.update(compileData);
1733
+ if (((_a = compileData.dependencies) == null ? void 0 : _a.length) && options.server) {
1734
+ compileData.dependencies.forEach((d) => {
1735
+ ensureWatchedFile(options.server.watcher, d, options.root);
1736
+ });
1737
+ }
1738
+ log.debug(`transform returns compiled js for ${svelteRequest.filename}`);
1739
+ return __spreadProps(__spreadValues({}, compileData.compiled.js), {
1740
+ meta: {
1741
+ vite: {
1742
+ lang: compileData.lang
1743
+ }
1744
+ }
1607
1745
  });
1608
- }
1609
- log.debug(`transform returns compiled js for ${svelteRequest.filename}`);
1610
- return compileData.compiled.js;
1611
- },
1612
- handleHotUpdate(ctx) {
1613
- if (!options.hot || !options.emitCss) {
1614
- return;
1615
- }
1616
- const svelteRequest = requestParser(ctx.file, false, ctx.timestamp);
1617
- if (svelteRequest) {
1618
- return handleHotUpdate(compileSvelte2, ctx, svelteRequest, cache, options);
1746
+ },
1747
+ handleHotUpdate(ctx) {
1748
+ if (!options.hot || !options.emitCss) {
1749
+ return;
1750
+ }
1751
+ const svelteRequest = requestParser(ctx.file, false, ctx.timestamp);
1752
+ if (svelteRequest) {
1753
+ return handleHotUpdate(compileSvelte2, ctx, svelteRequest, cache, options);
1754
+ }
1619
1755
  }
1620
1756
  }
1621
- };
1757
+ ];
1758
+ plugins.push(svelteInspector());
1759
+ return plugins.filter(Boolean);
1622
1760
  }
1623
1761
  export {
1624
1762
  svelte