sv 1.1.0 → 1.1.1

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.
@@ -1,4 +1,4 @@
1
- import { D as getSharedFiles, pt as R, v as defineAddon, y as defineAddonOptions } from "./engine-DB9amJxd.mjs";
1
+ import { D as getSharedFiles, pt as R, v as defineAddon, y as defineAddonOptions } from "./engine-CpcTzL2R.mjs";
2
2
  import fs from "node:fs";
3
3
  import path from "node:path";
4
4
  import { KIT3_TSCONFIG, Walker, coerceVersion, color, createPrinter, dedent, defineDemoPage, defineEnv, fileExists, isKit3, loadPackageJson, pnpm, resolveCommandArray, resolveLibPrefix, sanitizeName, svelteConfig, transforms } from "@sveltejs/sv-utils";
package/dist/bin.mjs CHANGED
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env node
2
- import { $ as parse$1, A as cliOptions, B as runAndValidateVerifications, C as execSync, D as getSharedFiles, E as dist, F as getPadding, G as UnsupportedError, H as updateAgent, I as helpConfig, J as array, K as name, L as isNodeError, M as filePaths, N as forwardExitCode, O as PackageJSONSchema, P as getHelpSections, Q as optional, R as normalizePosix, S as exec, T as templates, U as updateLibraryBuild, V as runCommand, W as updateReadme, X as literal, Y as boolean, Z as nonEmpty, _ as createLoadedAddon, _t as pe, a as setupAddons, at as string, b as getErrorHint, bt as R$1, c as AGENT_NAMES, ct as program, d as installDependencies, dt as Ce, et as picklist, f as installOption, ft as Ee, g as from, gt as le, h as up$2, ht as ge, i as prepareSvApi, it as strictObject, j as errorAndExit, k as buildAndLogArgs, l as addAllowBuildsIfPnpm, lt as Command, m as up$1, mt as Re, n as applyAddons, nt as record, o as createWorkspace, ot as transform, p as packageManagerPrompt, pt as R, q as version, r as orderAddons, rt as safeParse, s as findWorkspaceRoot, st as union, tt as pipe, u as detectPackageManager, ut as Option, vt, w as create$1, x as NonZeroExitError, yt as we, z as parseAddonOptions } from "./engine-DB9amJxd.mjs";
3
- import { n as officialAddons$1, t as getAddonDetails } from "./addons-OcP_HeQ_.mjs";
2
+ import { $ as parse$1, A as cliOptions, B as runAndValidateVerifications, C as execSync, D as getSharedFiles, E as dist, F as getPadding, G as UnsupportedError, H as updateAgent, I as helpConfig, J as array, K as name, L as isNodeError, M as filePaths, N as forwardExitCode, O as PackageJSONSchema, P as getHelpSections, Q as optional, R as normalizePosix, S as exec, T as templates, U as updateLibraryBuild, V as runCommand, W as updateReadme, X as literal, Y as boolean, Z as nonEmpty, _ as createLoadedAddon, _t as pe, a as setupAddons, at as string, b as getErrorHint, bt as R$1, c as AGENT_NAMES, ct as program, d as installDependencies, dt as Ce, et as picklist, f as installOption, ft as Ee, g as from, gt as le, h as up$2, ht as ge, i as prepareSvApi, it as strictObject, j as errorAndExit, k as buildAndLogArgs, l as addAllowBuildsIfPnpm, lt as Command, m as up$1, mt as Re, n as applyAddons, nt as record, o as createWorkspace, ot as transform, p as packageManagerPrompt, pt as R, q as version, r as orderAddons, rt as safeParse, s as findWorkspaceRoot, st as union, tt as pipe, u as detectPackageManager, ut as Option, vt, w as create$1, x as NonZeroExitError, yt as we, z as parseAddonOptions } from "./engine-CpcTzL2R.mjs";
3
+ import { n as officialAddons$1, t as getAddonDetails } from "./addons-DaktRhvH.mjs";
4
4
  import * as fs$1 from "node:fs";
5
5
  import fs from "node:fs";
6
6
  import * as path$1 from "node:path";
@@ -3846,7 +3846,7 @@ var lib_alias_default = defineMigrationTask({
3846
3846
  };
3847
3847
  }));
3848
3848
  sv.files({
3849
- include: `${directory.src}/**/*.{svelte,svelte.ts,svelte.js,ts,js,svx,md}`,
3849
+ include: `**/*.{svelte,svelte.ts,svelte.js,ts,js,svx,md}`,
3850
3850
  where: (content) => content.includes("$lib")
3851
3851
  }, (content, file) => {
3852
3852
  let styleLibPath = path.posix.relative(path.posix.dirname(file.replaceAll("\\", "/")), directory.lib.replaceAll("\\", "/"));
@@ -3859,7 +3859,7 @@ var lib_alias_default = defineMigrationTask({
3859
3859
  ".ts",
3860
3860
  "/index.js",
3861
3861
  "/index.ts"
3862
- ]) if (fs.existsSync(`${cwd}/${directory.lib}/${import_path}${ending}`)) return match.slice(0, -1) + ending.replace(".ts", ".js") + match.slice(-1);
3862
+ ]) if (fs.existsSync(path.join(cwd, directory.lib, import_path + ending))) return match.slice(0, -1) + ending.replace(".ts", ".js") + match.slice(-1);
3863
3863
  }
3864
3864
  return match;
3865
3865
  });
@@ -3873,7 +3873,7 @@ const KIT3_MIN_VERSIONS = {
3873
3873
  vite: "^8.0.12",
3874
3874
  "@sveltejs/vite-plugin-svelte": "^7.0.0",
3875
3875
  svelte: "^5.57.1",
3876
- "@sveltejs/package": "^2.5.8",
3876
+ "@sveltejs/package": "^3.0.0",
3877
3877
  "svelte-check": "^4.7.5",
3878
3878
  typescript: "^6.0.0"
3879
3879
  };
@@ -4487,18 +4487,29 @@ function gotoOptions(replace, state) {
4487
4487
  function migrateNavigationHook(call) {
4488
4488
  const callback = call.arguments[0];
4489
4489
  if (callback?.type !== "ArrowFunctionExpression" && callback?.type !== "FunctionExpression") return false;
4490
- const shallow = shallowTest(callback);
4491
- if (!shallow) return false;
4490
+ const properties = navigationHookProperties(callback);
4491
+ if (!properties) return false;
4492
+ const [shallow, type] = properties;
4492
4493
  const guard = {
4493
4494
  type: "IfStatement",
4494
- test: shallow,
4495
+ test: {
4496
+ type: "LogicalExpression",
4497
+ operator: "&&",
4498
+ left: shallow,
4499
+ right: {
4500
+ type: "BinaryExpression",
4501
+ operator: "===",
4502
+ left: type,
4503
+ right: js.common.createLiteral("goto")
4504
+ }
4505
+ },
4495
4506
  consequent: {
4496
4507
  type: "ReturnStatement",
4497
4508
  argument: null
4498
4509
  }
4499
4510
  };
4500
4511
  if (callback.body.type === "BlockStatement") {
4501
- if (startsWithShallowGuard(callback.body, shallow)) return false;
4512
+ if (startsWithNavigationGuard(callback.body, shallow, type)) return false;
4502
4513
  callback.body.body.unshift(guard);
4503
4514
  } else callback.body = {
4504
4515
  type: "BlockStatement",
@@ -4509,35 +4520,43 @@ function migrateNavigationHook(call) {
4509
4520
  };
4510
4521
  return true;
4511
4522
  }
4512
- function shallowTest(callback) {
4523
+ function navigationHookProperties(callback) {
4513
4524
  const parameter = callback.params[0];
4514
4525
  if (!parameter) {
4515
4526
  callback.params.push({
4516
4527
  type: "ObjectPattern",
4517
- properties: [patternProperty("shallow")]
4528
+ properties: [patternProperty("shallow"), patternProperty("type")]
4518
4529
  });
4519
- return js.variables.createIdentifier("shallow");
4530
+ return [js.variables.createIdentifier("shallow"), js.variables.createIdentifier("type")];
4520
4531
  }
4521
- if (parameter.type === "Identifier") return member(parameter.name, "shallow");
4522
- if (parameter.type === "AssignmentPattern" && parameter.left.type === "Identifier") return member(parameter.left.name, "shallow");
4532
+ if (parameter.type === "Identifier") return [member(parameter.name, "shallow"), member(parameter.name, "type")];
4533
+ if (parameter.type === "AssignmentPattern" && parameter.left.type === "Identifier") return [member(parameter.left.name, "shallow"), member(parameter.left.name, "type")];
4523
4534
  if (parameter.type !== "ObjectPattern") return void 0;
4535
+ const shallow = patternIdentifier(parameter, "shallow");
4536
+ const type = patternIdentifier(parameter, "type");
4537
+ if (shallow === null || type === null) return void 0;
4538
+ for (const name of [shallow ? void 0 : "shallow", type ? void 0 : "type"]) {
4539
+ if (!name) continue;
4540
+ const restIndex = parameter.properties.findIndex((entry) => entry.type === "RestElement");
4541
+ const property = patternProperty(name);
4542
+ if (restIndex === -1) parameter.properties.push(property);
4543
+ else parameter.properties.splice(restIndex, 0, property);
4544
+ }
4545
+ return [shallow ?? js.variables.createIdentifier("shallow"), type ?? js.variables.createIdentifier("type")];
4546
+ }
4547
+ function patternIdentifier(parameter, name) {
4524
4548
  for (const entry of parameter.properties) {
4525
4549
  if (entry.type !== "Property") continue;
4526
4550
  const key = entry.key;
4527
- if ((key.type !== "Identifier" || key.name !== "shallow") && (key.type !== "Literal" || key.value !== "shallow")) continue;
4551
+ if ((key.type !== "Identifier" || key.name !== name) && (key.type !== "Literal" || key.value !== name)) continue;
4528
4552
  if (entry.value.type === "Identifier") return js.variables.createIdentifier(entry.value.name);
4529
4553
  if (entry.value.type === "AssignmentPattern" && entry.value.left.type === "Identifier") return js.variables.createIdentifier(entry.value.left.name);
4530
- return;
4554
+ return null;
4531
4555
  }
4532
- const restIndex = parameter.properties.findIndex((entry) => entry.type === "RestElement");
4533
- const shallowProperty = patternProperty("shallow");
4534
- if (restIndex === -1) parameter.properties.push(shallowProperty);
4535
- else parameter.properties.splice(restIndex, 0, shallowProperty);
4536
- return js.variables.createIdentifier("shallow");
4537
4556
  }
4538
- function startsWithShallowGuard(body, shallow) {
4557
+ function startsWithNavigationGuard(body, shallow, type) {
4539
4558
  const first = body.body[0];
4540
- return first?.type === "IfStatement" && first.consequent.type === "ReturnStatement" && first.consequent.argument === null && sameExpression(first.test, shallow);
4559
+ return first?.type === "IfStatement" && first.consequent.type === "ReturnStatement" && first.consequent.argument === null && first.test.type === "LogicalExpression" && first.test.operator === "&&" && sameExpression(first.test.left, shallow) && first.test.right.type === "BinaryExpression" && first.test.right.operator === "===" && first.test.right.left.type !== "PrivateIdentifier" && sameExpression(first.test.right.left, type) && first.test.right.right.type === "Literal" && first.test.right.right.value === "goto";
4541
4560
  }
4542
4561
  function sameExpression(left, right) {
4543
4562
  if (left.type === "Identifier" && right.type === "Identifier") return left.name === right.name;
@@ -4573,7 +4592,15 @@ var svelte_config_default = defineMigrationTask({
4573
4592
  run: ({ sv, cwd }) => {
4574
4593
  const configSource = svelteConfig.find(cwd);
4575
4594
  if (!configSource) return;
4576
- if (configSource.kind === "vite") return;
4595
+ if (configSource.kind === "vite") {
4596
+ svelteConfig.edit({
4597
+ sv,
4598
+ cwd
4599
+ }, ({ config }) => {
4600
+ if (!removeFilesLib(config)) return false;
4601
+ });
4602
+ return;
4603
+ }
4577
4604
  const originalConfigObject = svelteConfig.read(cwd);
4578
4605
  if (!originalConfigObject) return;
4579
4606
  sv.removeFile(configSource.path);
@@ -4588,6 +4615,16 @@ var svelte_config_default = defineMigrationTask({
4588
4615
  const originalStatements = [];
4589
4616
  for (const node of originalConfigObject.ast.body) if (node.type === "ImportDeclaration") originalImports.push(node);
4590
4617
  else if (node.type !== "ExportDefaultDeclaration" && node !== configDeclaration) originalStatements.push(node);
4618
+ const existingBindings = js.scope.topLevelBindings([ast]);
4619
+ const movedProgram = {
4620
+ ...originalConfigObject.ast,
4621
+ body: [...originalImports, ...originalStatements]
4622
+ };
4623
+ const movedBindings = js.scope.topLevelBindings([movedProgram]);
4624
+ const usedBindings = /* @__PURE__ */ new Set([...existingBindings, ...movedBindings]);
4625
+ const renames = /* @__PURE__ */ new Map();
4626
+ for (const name of movedBindings) if (existingBindings.has(name)) renames.set(name, js.identifiers.uniqueName(name, usedBindings));
4627
+ js.identifiers.renameReferences([originalConfigObject.ast], renames);
4591
4628
  ast.body.unshift(...originalImports);
4592
4629
  const exportIndex = ast.body.findIndex((node) => node.type === "ExportDefaultDeclaration");
4593
4630
  ast.body.splice(exportIndex, 0, ...originalStatements);
@@ -4598,24 +4635,24 @@ var svelte_config_default = defineMigrationTask({
4598
4635
  let trustsAllOrigins = false;
4599
4636
  for (const prop of newConfigProperties) {
4600
4637
  if (prop.type !== "Property") continue;
4601
- if (prop.key.type !== "Identifier") continue;
4602
- if (prop.key.name === "kit") continue;
4638
+ const key = js.object.propertyName(prop);
4639
+ if (!key || key === "kit") continue;
4603
4640
  const propAttachment = attachments.get(prop);
4604
- keyedConfig[prop.key.name] = prop.value;
4605
- if (propAttachment) propComments.set(prop.key.name, propAttachment);
4641
+ keyedConfig[key] = prop.value;
4642
+ if (propAttachment) propComments.set(key, propAttachment);
4606
4643
  }
4607
4644
  for (const [key, value] of Object.entries(keyedConfig)) {
4608
4645
  if (key === "experimental" && value.type === "ObjectExpression") {
4609
- removeProperty(value, "handleRenderingErrors");
4610
- removeProperty(value, "instrumentation");
4611
- const index = value.properties.findIndex((prop) => prop.type === "Property" && prop.key.type === "Identifier" && prop.key.name === "tracing");
4612
- if (index !== -1) {
4613
- keyedConfig.tracing = value.properties[index].value;
4614
- value.properties.splice(index, 1);
4646
+ js.object.removeProperty(value, { name: "handleRenderingErrors" });
4647
+ js.object.removeProperty(value, { name: "instrumentation" });
4648
+ const tracing = js.object.findProperty(value, { name: "tracing" });
4649
+ if (tracing) {
4650
+ keyedConfig.tracing = tracing.value;
4651
+ js.object.removeProperty(value, { name: "tracing" });
4615
4652
  }
4616
4653
  }
4617
4654
  if (key === "prerender" && value.type === "ObjectExpression") {
4618
- const originProp = value.properties.find((prop) => prop.type === "Property" && prop.key.type === "Identifier" && prop.key.name === "origin");
4655
+ const originProp = js.object.findProperty(value, { name: "origin" });
4619
4656
  if (originProp) {
4620
4657
  keyedConfig.paths ??= {
4621
4658
  type: "ObjectExpression",
@@ -4633,14 +4670,22 @@ var svelte_config_default = defineMigrationTask({
4633
4670
  shorthand: false,
4634
4671
  computed: false
4635
4672
  });
4636
- removeProperty(value, "origin");
4673
+ js.object.removeProperty(value, { name: "origin" });
4637
4674
  if (value.properties.length === 0) delete keyedConfig.prerender;
4638
4675
  }
4639
4676
  }
4677
+ if (key === "files" && value.type === "ObjectExpression") {
4678
+ js.object.removeProperty(value, { name: "lib" });
4679
+ if (value.properties.length === 0) delete keyedConfig.files;
4680
+ }
4640
4681
  if (key === "csrf" && value.type === "ObjectExpression") {
4641
4682
  const checkOrigin = findDisabledCheckOrigin(value);
4642
4683
  if (checkOrigin) {
4643
- checkOrigin.key.name = "trustedOrigins";
4684
+ checkOrigin.key = {
4685
+ type: "Identifier",
4686
+ name: "trustedOrigins"
4687
+ };
4688
+ checkOrigin.computed = false;
4644
4689
  checkOrigin.value = {
4645
4690
  type: "ArrayExpression",
4646
4691
  elements: [{
@@ -4671,7 +4716,10 @@ var svelte_config_default = defineMigrationTask({
4671
4716
  apply(node, attachments.get(node));
4672
4717
  if (node.type === "CallExpression" && node.callee.type === "Identifier" && node.callee.name === "sveltekit" && node.arguments[0]?.type === "ObjectExpression") rootConfig = node.arguments[0];
4673
4718
  });
4674
- for (const prop of rootConfig?.properties ?? []) if (prop.type === "Property" && prop.key.type === "Identifier") apply(prop, propComments.get(prop.key.name));
4719
+ for (const prop of rootConfig?.properties ?? []) if (prop.type === "Property") {
4720
+ const key = js.object.propertyName(prop);
4721
+ if (key) apply(prop, propComments.get(key));
4722
+ }
4675
4723
  });
4676
4724
  let addedConfigLoader = false;
4677
4725
  sv.files({
@@ -4721,10 +4769,19 @@ function forEachNode(root, visit) {
4721
4769
  forEachNode(node[key], visit);
4722
4770
  }
4723
4771
  }
4724
- /** Removes a statically named property from an object literal. */
4725
- function removeProperty(value, name) {
4726
- const index = value.properties.findIndex((prop) => prop.type === "Property" && prop.key.type === "Identifier" && prop.key.name === name);
4727
- if (index !== -1) value.properties.splice(index, 1);
4772
+ /**
4773
+ * Drops the `files.lib` option from a kit config object, deleting `files` itself when it only
4774
+ * contained `lib`.
4775
+ * Returns whether anything was removed.
4776
+ */
4777
+ function removeFilesLib(config) {
4778
+ const filesProp = js.object.findProperty(config, { name: "files" });
4779
+ if (!filesProp) return false;
4780
+ const files = filesProp.value;
4781
+ if (files.type !== "ObjectExpression") return false;
4782
+ if (!js.object.removeProperty(files, { name: "lib" })) return false;
4783
+ if (files.properties.length === 0) js.object.removeProperty(config, { name: "files" });
4784
+ return true;
4728
4785
  }
4729
4786
  /**
4730
4787
  * Maps each source comment to the node it documents, returned keyed by node identity. A comment is
@@ -4780,7 +4837,8 @@ function collectComments(ast, source) {
4780
4837
  }
4781
4838
  /** Returns the `checkOrigin: false` property of a `csrf` object, if present. */
4782
4839
  function findDisabledCheckOrigin(value) {
4783
- return value.properties.find((p) => p.type === "Property" && p.key.type === "Identifier" && p.key.name === "checkOrigin" && p.value.type === "Literal" && p.value.value === false);
4840
+ const property = js.object.findProperty(value, { name: "checkOrigin" });
4841
+ return property?.value.type === "Literal" && property.value.value === false ? property : void 0;
4784
4842
  }
4785
4843
  //#endregion
4786
4844
  //#region src/migrate/migrations/sveltekit-3/tasks/tsconfig.ts
@@ -5020,7 +5020,7 @@ function safeParse(schema, input, config$1) {
5020
5020
  //#endregion
5021
5021
  //#region package.json
5022
5022
  var name = "sv";
5023
- var version = "1.1.0";
5023
+ var version = "1.1.1";
5024
5024
  //#endregion
5025
5025
  //#region src/core/errors.ts
5026
5026
  var UnsupportedError = class extends Error {
@@ -1,3 +1,3 @@
1
- import { t as add, v as defineAddon, w as create, y as defineAddonOptions } from "../engine-DB9amJxd.mjs";
2
- import { n as officialAddons } from "../addons-OcP_HeQ_.mjs";
1
+ import { t as add, v as defineAddon, w as create, y as defineAddonOptions } from "../engine-CpcTzL2R.mjs";
2
+ import { n as officialAddons } from "../addons-DaktRhvH.mjs";
3
3
  export { add, create, defineAddon, defineAddonOptions, officialAddons };
@@ -1,4 +1,4 @@
1
- import { C as execSync, Ct as __toESM, S as exec, St as __require, l as addAllowBuildsIfPnpm, t as add, w as create, xt as __commonJSMin } from "../engine-DB9amJxd.mjs";
1
+ import { C as execSync, Ct as __toESM, S as exec, St as __require, l as addAllowBuildsIfPnpm, t as add, w as create, xt as __commonJSMin } from "../engine-CpcTzL2R.mjs";
2
2
  import fs from "node:fs";
3
3
  import path from "node:path";
4
4
  import V from "node:process";
@@ -22,11 +22,11 @@
22
22
  "access": "public"
23
23
  },
24
24
  "peerDependencies": {
25
- "sv": "^1.1.0"
25
+ "sv": "^1.1.1"
26
26
  },
27
27
  "devDependencies": {
28
- "sv": "^1.1.0",
29
- "@sveltejs/sv-utils": "^1.0.1",
28
+ "sv": "^1.1.1",
29
+ "@sveltejs/sv-utils": "^1.0.2",
30
30
  "@playwright/test": "^1.60.0",
31
31
  "@types/node": "^25.9.1",
32
32
  "tsdown": "^0.22.1",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sv",
3
- "version": "1.1.0",
3
+ "version": "1.1.1",
4
4
  "description": "A command line interface (CLI) for creating and maintaining Svelte applications",
5
5
  "keywords": [
6
6
  "create",
@@ -34,7 +34,7 @@
34
34
  }
35
35
  },
36
36
  "dependencies": {
37
- "@sveltejs/sv-utils": "1.0.1"
37
+ "@sveltejs/sv-utils": "1.0.2"
38
38
  },
39
39
  "devDependencies": {
40
40
  "@clack/prompts": "1.5.0",