sv 0.6.26 → 0.7.0

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 { __commonJS, __toESM, be, detect, getUserAgent, log, parseJson, parseScript, parseScript$1, resolveCommand, serializeScript, stripAst, up, walk_exports } from "./package-manager-BF1V21Xa.js";
1
+ import { __commonJS, __toESM, be, detect, getUserAgent, log, parseJson, parseScript, parseScript$1, resolveCommand, serializeScript, stripAst, up, walk_exports } from "./package-manager-BfHgHI9y.js";
2
2
  import fs from "node:fs";
3
3
  import path from "node:path";
4
4
  import process$1 from "node:process";
@@ -188,7 +188,7 @@ else mindent = Math.min(mindent, indent);
188
188
  }
189
189
 
190
190
  //#endregion
191
- //#region packages/core/dist/common-DU6ydIJj.js
191
+ //#region packages/core/dist/common-Dee02diz.js
192
192
  function decircular(object) {
193
193
  const seenObjects = new WeakMap();
194
194
  function internalDecircular(value, path$1 = []) {
@@ -215,6 +215,7 @@ __export(common_exports, {
215
215
  createSpreadElement: () => createSpreadElement,
216
216
  expressionFromString: () => expressionFromString,
217
217
  expressionStatement: () => expressionStatement,
218
+ fromString: () => fromString,
218
219
  hasNode: () => hasNode,
219
220
  hasTypeProp: () => hasTypeProp,
220
221
  satisfiesExpression: () => satisfiesExpression,
@@ -223,9 +224,8 @@ __export(common_exports, {
223
224
  });
224
225
  function addJsDocTypeComment(node, type) {
225
226
  const comment = {
226
- type: "CommentBlock",
227
- value: `* @type {${type}} `,
228
- leading: true
227
+ type: "Block",
228
+ value: `* @type {${type}} `
229
229
  };
230
230
  addComment(node, comment);
231
231
  }
@@ -233,16 +233,15 @@ function addJsDocComment(node, params) {
233
233
  const commentLines = [];
234
234
  for (const [key, value] of Object.entries(params)) commentLines.push(`@param {${key}} ${value}`);
235
235
  const comment = {
236
- type: "CommentBlock",
237
- value: `*\n * ${commentLines.join("\n * ")}\n `,
238
- leading: true
236
+ type: "Block",
237
+ value: `*\n * ${commentLines.join("\n * ")}\n `
239
238
  };
240
239
  addComment(node, comment);
241
240
  }
242
241
  function addComment(node, comment) {
243
- node.comments ??= [];
244
- const found = node.comments.find((n) => n.type === "CommentBlock" && n.value === comment.value);
245
- if (!found) node.comments.push(comment);
242
+ node.leadingComments ??= [];
243
+ const found = node.leadingComments.find((n) => n.type === "Block" && n.value === comment.value);
244
+ if (!found) node.leadingComments.push(comment);
246
245
  }
247
246
  function typeAnnotateExpression(node, type) {
248
247
  const expression = {
@@ -286,8 +285,8 @@ function createLiteral(value = null) {
286
285
  return literal;
287
286
  }
288
287
  function areNodesEqual(ast1, ast2) {
289
- const ast1Clone = stripAst(decircular(ast1), "loc");
290
- const ast2Clone = stripAst(decircular(ast2), "loc");
288
+ const ast1Clone = stripAst(decircular(ast1), ["loc", "raw"]);
289
+ const ast2Clone = stripAst(decircular(ast2), ["loc", "raw"]);
291
290
  return serializeScript(ast1Clone) === serializeScript(ast2Clone);
292
291
  }
293
292
  function blockStatement() {
@@ -315,6 +314,9 @@ function expressionFromString(value) {
315
314
  return statement.expression;
316
315
  }
317
316
  function statementFromString(value) {
317
+ return fromString(value);
318
+ }
319
+ function fromString(value) {
318
320
  const program = parseScript$1(dedent_default(value));
319
321
  const statement = program.body[0];
320
322
  return statement;
@@ -324,7 +326,7 @@ function addStatement(ast, statement) {
324
326
  }
325
327
  function hasNode(ast, nodeToMatch) {
326
328
  let found = false;
327
- walk_exports.walk(ast, {}, { _(node, { next, stop }) {
329
+ walk_exports.walk(ast, null, { _(node, { next, stop }) {
328
330
  if (node.type === nodeToMatch.type) {
329
331
  found = areNodesEqual(node, nodeToMatch);
330
332
  if (found) stop();
@@ -360,11 +362,11 @@ function unshift(ast, data) {
360
362
  }
361
363
  function insertElement(ast, data, insertEnd) {
362
364
  if (typeof data === "string") {
363
- const existingLiterals = ast.elements.filter((x) => x?.type === "StringLiteral");
365
+ const existingLiterals = ast.elements.filter((x) => x !== null && x.type === "Literal");
364
366
  let literal = existingLiterals.find((x) => x.value === data);
365
367
  if (!literal) {
366
368
  literal = {
367
- type: "StringLiteral",
369
+ type: "Literal",
368
370
  value: data
369
371
  };
370
372
  if (insertEnd) ast.elements.push(literal);
@@ -372,7 +374,7 @@ else ast.elements.unshift(literal);
372
374
  }
373
375
  } else {
374
376
  const elements = ast.elements;
375
- const anyNodeEquals = elements.some((node) => areNodesEqual(data, node));
377
+ const anyNodeEquals = elements.some((node) => node && areNodesEqual(data, node));
376
378
  if (!anyNodeEquals) if (insertEnd) ast.elements.push(data);
377
379
  else ast.elements.unshift(data);
378
380
  }
@@ -389,25 +391,28 @@ __export(object_exports, {
389
391
  });
390
392
  function property(ast, name, fallback) {
391
393
  const objectExpression = ast;
392
- const properties$1 = objectExpression.properties.filter((x) => x.type == "ObjectProperty");
393
- let property$1 = properties$1.find((x) => x.key.name == name);
394
+ const properties$1 = objectExpression.properties.filter((x) => x.type === "Property");
395
+ let property$1 = properties$1.find((x) => x.key.name === name);
394
396
  let propertyValue;
395
397
  if (property$1) propertyValue = property$1.value;
396
398
  else {
397
399
  let isShorthand = false;
398
- if (fallback.type == "Identifier") {
400
+ if (fallback.type === "Identifier") {
399
401
  const identifier$1 = fallback;
400
- isShorthand = identifier$1.name == name;
402
+ isShorthand = identifier$1.name === name;
401
403
  }
402
404
  propertyValue = fallback;
403
405
  property$1 = {
404
- type: "ObjectProperty",
406
+ type: "Property",
405
407
  shorthand: isShorthand,
406
408
  key: {
407
409
  type: "Identifier",
408
410
  name
409
411
  },
410
- value: propertyValue
412
+ value: propertyValue,
413
+ kind: "init",
414
+ computed: false,
415
+ method: false
411
416
  };
412
417
  objectExpression.properties.push(property$1);
413
418
  }
@@ -415,8 +420,8 @@ else {
415
420
  }
416
421
  function overrideProperty(ast, name, value) {
417
422
  const objectExpression = ast;
418
- const properties$1 = objectExpression.properties.filter((x) => x.type == "ObjectProperty");
419
- const prop = properties$1.find((x) => x.key.name == name);
423
+ const properties$1 = objectExpression.properties.filter((x) => x.type === "Property");
424
+ const prop = properties$1.find((x) => x.key.name === name);
420
425
  if (!prop) return property(ast, name, value);
421
426
  prop.value = value;
422
427
  return value;
@@ -434,7 +439,7 @@ function properties(ast, obj) {
434
439
  }
435
440
  }
436
441
  function removeProperty(ast, property$1) {
437
- const properties$1 = ast.properties.filter((x) => x.type === "ObjectProperty");
442
+ const properties$1 = ast.properties.filter((x) => x.type === "Property");
438
443
  const propIdx = properties$1.findIndex((x) => x.key.name === property$1);
439
444
  if (propIdx !== -1) ast.properties.splice(propIdx, 1);
440
445
  }
@@ -467,7 +472,8 @@ function call(name, args) {
467
472
  type: "Identifier",
468
473
  name
469
474
  },
470
- arguments: []
475
+ arguments: [],
476
+ optional: false
471
477
  };
472
478
  for (const argument of args) callExpression.arguments.push({
473
479
  type: "Literal",
@@ -482,7 +488,8 @@ function callByIdentifier(name, args) {
482
488
  type: "Identifier",
483
489
  name
484
490
  },
485
- arguments: []
491
+ arguments: [],
492
+ optional: false
486
493
  };
487
494
  for (const argument of args) {
488
495
  const identifier$1 = {
@@ -498,7 +505,8 @@ function arrowFunction(async, body) {
498
505
  type: "ArrowFunctionExpression",
499
506
  async,
500
507
  body,
501
- params: []
508
+ params: [],
509
+ expression: body.type !== "BlockStatement"
502
510
  };
503
511
  return arrowFunction$1;
504
512
  }
@@ -521,13 +529,15 @@ function addEmpty(ast, importFrom) {
521
529
  type: "Literal",
522
530
  value: importFrom
523
531
  },
524
- specifiers: []
532
+ specifiers: [],
533
+ importKind: "value"
525
534
  };
526
535
  addImportIfNecessary(ast, expectedImportDeclaration);
527
536
  }
528
537
  function addNamespace(ast, importFrom, importAs) {
529
538
  const expectedImportDeclaration = {
530
539
  type: "ImportDeclaration",
540
+ importKind: "value",
531
541
  source: {
532
542
  type: "Literal",
533
543
  value: importFrom
@@ -555,7 +565,8 @@ function addDefault(ast, importFrom, importAs) {
555
565
  type: "Identifier",
556
566
  name: importAs
557
567
  }
558
- }]
568
+ }],
569
+ importKind: "value"
559
570
  };
560
571
  addImportIfNecessary(ast, expectedImportDeclaration);
561
572
  }
@@ -575,12 +586,13 @@ function addNamed(ast, importFrom, exportedAsImportAs, isType = false) {
575
586
  return specifier;
576
587
  });
577
588
  let importDecl;
578
- walk_exports.walk(ast, {}, { ImportDeclaration(node) {
589
+ walk_exports.walk(ast, null, { ImportDeclaration(node) {
579
590
  if (node.source.value === importFrom && node.specifiers) importDecl = node;
580
591
  } });
581
592
  if (importDecl) {
582
593
  specifiers.forEach((specifierToAdd) => {
583
- if (importDecl?.specifiers?.every((existingSpecifier) => existingSpecifier.type === "ImportSpecifier" && existingSpecifier.local?.name !== specifierToAdd.local?.name && existingSpecifier.imported.name !== specifierToAdd.imported.name)) importDecl?.specifiers?.push(specifierToAdd);
594
+ const sourceExists = importDecl?.specifiers?.every((existingSpecifier) => existingSpecifier.type === "ImportSpecifier" && existingSpecifier.local?.name !== specifierToAdd.local?.name && existingSpecifier.imported.type === "Identifier" && specifierToAdd.imported.type === "Identifier" && existingSpecifier.imported.name !== specifierToAdd.imported.name);
595
+ if (sourceExists) importDecl?.specifiers?.push(specifierToAdd);
584
596
  });
585
597
  return;
586
598
  }
@@ -591,12 +603,12 @@ function addNamed(ast, importFrom, exportedAsImportAs, isType = false) {
591
603
  value: importFrom
592
604
  },
593
605
  specifiers,
594
- importKind: isType ? "type" : undefined
606
+ importKind: isType ? "type" : "value"
595
607
  };
596
608
  ast.body.unshift(expectedImportDeclaration);
597
609
  }
598
610
  function addImportIfNecessary(ast, expectedImportDeclaration) {
599
- const importDeclarations = ast.body.filter((x) => x.type == "ImportDeclaration");
611
+ const importDeclarations = ast.body.filter((x) => x.type === "ImportDeclaration");
600
612
  const importDeclaration = importDeclarations.find((x) => areNodesEqual(x, expectedImportDeclaration));
601
613
  if (!importDeclaration) ast.body.unshift(expectedImportDeclaration);
602
614
  }
@@ -607,11 +619,11 @@ __export(variables_exports, {
607
619
  typeAnnotateDeclarator: () => typeAnnotateDeclarator
608
620
  });
609
621
  function declaration(ast, kind, name, value) {
610
- const declarations = ast.type == "Program" ? ast.body.filter((x) => x.type == "VariableDeclaration") : [ast];
622
+ const declarations = ast.type === "Program" ? ast.body.filter((x) => x.type === "VariableDeclaration") : [ast];
611
623
  let declaration$1 = declarations.find((x) => {
612
624
  const declarator = x.declarations[0];
613
625
  const identifier$1 = declarator.id;
614
- return identifier$1.name == name;
626
+ return identifier$1.name === name;
615
627
  });
616
628
  if (declaration$1) return declaration$1;
617
629
  declaration$1 = {
@@ -691,17 +703,18 @@ function defaultExport(ast, fallbackDeclaration) {
691
703
  };
692
704
  }
693
705
  function namedExport(ast, name, fallback) {
694
- const namedExports = ast.body.filter((x) => x.type == "ExportNamedDeclaration");
706
+ const namedExports = ast.body.filter((x) => x.type === "ExportNamedDeclaration");
695
707
  let namedExport$1 = namedExports.find((x) => {
696
708
  const variableDeclaration = x.declaration;
697
709
  const variableDeclarator = variableDeclaration.declarations[0];
698
710
  const identifier$1 = variableDeclarator.id;
699
- return identifier$1.name == name;
711
+ return identifier$1.name === name;
700
712
  });
701
713
  if (namedExport$1) return namedExport$1;
702
714
  namedExport$1 = {
703
715
  type: "ExportNamedDeclaration",
704
- declaration: fallback
716
+ declaration: fallback,
717
+ specifiers: []
705
718
  };
706
719
  ast.body.push(namedExport$1);
707
720
  return namedExport$1;
@@ -714,13 +727,13 @@ __export(kit_exports, {
714
727
  function addGlobalAppInterface(ast, name) {
715
728
  let globalDecl = ast.body.filter((n) => n.type === "TSModuleDeclaration").find((m) => m.global && m.declare);
716
729
  if (!globalDecl) {
717
- globalDecl = statementFromString("declare global {}");
730
+ globalDecl = fromString("declare global {}");
718
731
  ast.body.push(globalDecl);
719
732
  }
720
733
  if (globalDecl.body?.type !== "TSModuleBlock") throw new Error("Unexpected body type of `declare global` in `src/app.d.ts`");
721
734
  let app;
722
735
  let interfaceNode;
723
- walk_exports.walk(globalDecl, {}, {
736
+ walk_exports.walk(globalDecl, null, {
724
737
  TSModuleDeclaration(node, { next }) {
725
738
  if (node.id.type === "Identifier" && node.id.name === "App") app = node;
726
739
  next();
@@ -730,12 +743,12 @@ function addGlobalAppInterface(ast, name) {
730
743
  }
731
744
  });
732
745
  if (!app) {
733
- app = statementFromString("namespace App {}");
746
+ app = fromString("namespace App {}");
734
747
  globalDecl.body.body.push(app);
735
748
  }
736
749
  if (app.body?.type !== "TSModuleBlock") throw new Error("Unexpected body type of `namespace App` in `src/app.d.ts`");
737
750
  if (!interfaceNode) {
738
- interfaceNode = statementFromString(`interface ${name} {}`);
751
+ interfaceNode = fromString(`interface ${name} {}`);
739
752
  app.body.body.push(interfaceNode);
740
753
  }
741
754
  return interfaceNode;
@@ -746,10 +759,10 @@ function addHooksHandle(ast, typescript, newHandleName, handleContent) {
746
759
  let handleName = "handle";
747
760
  let exportDecl;
748
761
  let originalHandleDecl;
749
- walk_exports.walk(ast, {}, { ExportNamedDeclaration(node) {
762
+ walk_exports.walk(ast, null, { ExportNamedDeclaration(node) {
750
763
  let maybeHandleDecl;
751
- const handleSpecifier = node.specifiers?.find((s) => s.exported.name === "handle");
752
- if (handleSpecifier) {
764
+ const handleSpecifier = node.specifiers?.find((s) => s.exported.type === "Identifier" && s.exported.name === "handle");
765
+ if (handleSpecifier && handleSpecifier.local.type === "Identifier" && handleSpecifier.exported.type === "Identifier") {
753
766
  isSpecifier = true;
754
767
  handleName = handleSpecifier.local?.name ?? handleSpecifier.exported.name;
755
768
  const handleFunc = ast.body.find((n) => isFunctionDeclaration(n, handleName));