@staff0rd/assist 0.238.0 → 0.238.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.
Files changed (2) hide show
  1. package/dist/index.js +73 -45
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -6,7 +6,7 @@ import { Command } from "commander";
6
6
  // package.json
7
7
  var package_default = {
8
8
  name: "@staff0rd/assist",
9
- version: "0.238.0",
9
+ version: "0.238.1",
10
10
  type: "module",
11
11
  main: "dist/index.js",
12
12
  bin: {
@@ -11407,14 +11407,42 @@ import path36 from "path";
11407
11407
  import chalk132 from "chalk";
11408
11408
 
11409
11409
  // src/commands/refactor/extract/applyExtraction.ts
11410
- import { SyntaxKind as SyntaxKind3 } from "ts-morph";
11410
+ import { SyntaxKind as SyntaxKind4 } from "ts-morph";
11411
+
11412
+ // src/commands/refactor/extract/addImportPreservingSuppressions.ts
11413
+ import {
11414
+ SyntaxKind as SyntaxKind2
11415
+ } from "ts-morph";
11416
+ var suppressionPattern = /^\s*(\/\/|\/\*)\s*biome-ignore(-all)?\b/;
11417
+ function countLeadingSuppressions(sourceFile) {
11418
+ let count6 = 0;
11419
+ for (const stmt of sourceFile.getStatementsWithComments()) {
11420
+ const kind = stmt.getKind();
11421
+ if ((kind === SyntaxKind2.SingleLineCommentTrivia || kind === SyntaxKind2.MultiLineCommentTrivia) && suppressionPattern.test(stmt.getText())) {
11422
+ count6++;
11423
+ } else {
11424
+ break;
11425
+ }
11426
+ }
11427
+ return count6;
11428
+ }
11429
+ function addImportPreservingSuppressions(sourceFile, structure) {
11430
+ if (sourceFile.getImportDeclarations().length > 0) {
11431
+ sourceFile.addImportDeclaration(structure);
11432
+ return;
11433
+ }
11434
+ sourceFile.insertImportDeclaration(
11435
+ countLeadingSuppressions(sourceFile),
11436
+ structure
11437
+ );
11438
+ }
11411
11439
 
11412
11440
  // src/commands/refactor/extract/removeStaleImports.ts
11413
- import { SyntaxKind as SyntaxKind2 } from "ts-morph";
11441
+ import { SyntaxKind as SyntaxKind3 } from "ts-morph";
11414
11442
  function collectReferencedNames(sourceFile) {
11415
11443
  const names = /* @__PURE__ */ new Set();
11416
- for (const id of sourceFile.getDescendantsOfKind(SyntaxKind2.Identifier)) {
11417
- if (id.getFirstAncestorByKind(SyntaxKind2.ImportDeclaration)) continue;
11444
+ for (const id of sourceFile.getDescendantsOfKind(SyntaxKind3.Identifier)) {
11445
+ if (id.getFirstAncestorByKind(SyntaxKind3.ImportDeclaration)) continue;
11418
11446
  names.add(id.getText());
11419
11447
  }
11420
11448
  return names;
@@ -11457,7 +11485,7 @@ function updateImporters(functionName, sourceFile, importers) {
11457
11485
  importDecl.remove();
11458
11486
  }
11459
11487
  }
11460
- importerFile.addImportDeclaration({
11488
+ addImportPreservingSuppressions(importerFile, {
11461
11489
  moduleSpecifier: relPath2,
11462
11490
  namedImports: [alias ? { name: functionName, alias } : functionName]
11463
11491
  });
@@ -11466,7 +11494,7 @@ function updateImporters(functionName, sourceFile, importers) {
11466
11494
 
11467
11495
  // src/commands/refactor/extract/applyExtraction.ts
11468
11496
  function isNameReferencedInSource(sourceFile, name) {
11469
- return sourceFile.getDescendantsOfKind(SyntaxKind3.Identifier).some((id) => id.getText() === name);
11497
+ return sourceFile.getDescendantsOfKind(SyntaxKind4.Identifier).some((id) => id.getText() === name);
11470
11498
  }
11471
11499
  async function applyExtraction(functionName, sourceFile, destPath, plan2, project) {
11472
11500
  project.createSourceFile(destPath, plan2.destContent, { overwrite: false });
@@ -11478,7 +11506,7 @@ async function applyExtraction(functionName, sourceFile, destPath, plan2, projec
11478
11506
  }
11479
11507
  removeStaleImports(sourceFile);
11480
11508
  if (isNameReferencedInSource(sourceFile, functionName)) {
11481
- sourceFile.addImportDeclaration({
11509
+ addImportPreservingSuppressions(sourceFile, {
11482
11510
  moduleSpecifier: plan2.destRelPath,
11483
11511
  namedImports: [functionName]
11484
11512
  });
@@ -11507,19 +11535,19 @@ async function applyExtraction(functionName, sourceFile, destPath, plan2, projec
11507
11535
 
11508
11536
  // src/commands/refactor/extract/collectDependencies.ts
11509
11537
  import {
11510
- SyntaxKind as SyntaxKind7
11538
+ SyntaxKind as SyntaxKind8
11511
11539
  } from "ts-morph";
11512
11540
 
11513
11541
  // src/commands/refactor/extract/collectPrivateFunctions.ts
11514
- import { SyntaxKind as SyntaxKind4 } from "ts-morph";
11542
+ import { SyntaxKind as SyntaxKind5 } from "ts-morph";
11515
11543
  function isPrivate(fn) {
11516
11544
  return !fn.isExported() && !fn.isDefaultExport();
11517
11545
  }
11518
11546
  function getCalledFunctionNames(fn) {
11519
11547
  const names = /* @__PURE__ */ new Set();
11520
- for (const call of fn.getDescendantsOfKind(SyntaxKind4.CallExpression)) {
11548
+ for (const call of fn.getDescendantsOfKind(SyntaxKind5.CallExpression)) {
11521
11549
  const expr = call.getExpression();
11522
- if (expr.getKind() === SyntaxKind4.Identifier) {
11550
+ if (expr.getKind() === SyntaxKind5.Identifier) {
11523
11551
  names.add(expr.getText());
11524
11552
  }
11525
11553
  }
@@ -11547,10 +11575,10 @@ function collectPrivateFunctions(target, fnMap) {
11547
11575
  }
11548
11576
 
11549
11577
  // src/commands/refactor/extract/collectPrivateStatements.ts
11550
- import { SyntaxKind as SyntaxKind5 } from "ts-morph";
11578
+ import { SyntaxKind as SyntaxKind6 } from "ts-morph";
11551
11579
  function getReferencedIdentifiers(fn) {
11552
11580
  const names = /* @__PURE__ */ new Set();
11553
- for (const id of fn.getDescendantsOfKind(SyntaxKind5.Identifier)) {
11581
+ for (const id of fn.getDescendantsOfKind(SyntaxKind6.Identifier)) {
11554
11582
  names.add(id.getText());
11555
11583
  }
11556
11584
  return names;
@@ -11568,12 +11596,12 @@ function collectPrivateStatements(functions, stmtMap) {
11568
11596
 
11569
11597
  // src/commands/refactor/extract/getFunctionMap.ts
11570
11598
  import {
11571
- SyntaxKind as SyntaxKind6
11599
+ SyntaxKind as SyntaxKind7
11572
11600
  } from "ts-morph";
11573
11601
  function getFunctionMap(sourceFile) {
11574
11602
  const map = /* @__PURE__ */ new Map();
11575
11603
  for (const fn of sourceFile.getDescendantsOfKind(
11576
- SyntaxKind6.FunctionDeclaration
11604
+ SyntaxKind7.FunctionDeclaration
11577
11605
  )) {
11578
11606
  const name = fn.getName();
11579
11607
  if (name) map.set(name, fn);
@@ -11599,7 +11627,7 @@ function getPrivateStatementMap(sourceFile) {
11599
11627
 
11600
11628
  // src/commands/refactor/extract/collectDependencies.ts
11601
11629
  function getRemainingFunctions(sourceFile, extracted) {
11602
- return sourceFile.getDescendantsOfKind(SyntaxKind7.FunctionDeclaration).filter((fn) => !extracted.has(fn));
11630
+ return sourceFile.getDescendantsOfKind(SyntaxKind8.FunctionDeclaration).filter((fn) => !extracted.has(fn));
11603
11631
  }
11604
11632
  function collectFnsUsedByRemaining(remaining, fnMap) {
11605
11633
  const used = /* @__PURE__ */ new Set();
@@ -11634,25 +11662,25 @@ function collectDependencies(target, sourceFile) {
11634
11662
 
11635
11663
  // src/commands/refactor/extract/findFunction.ts
11636
11664
  import {
11637
- SyntaxKind as SyntaxKind8
11665
+ SyntaxKind as SyntaxKind9
11638
11666
  } from "ts-morph";
11639
11667
  function findFunction(sourceFile, functionName) {
11640
- return sourceFile.getDescendantsOfKind(SyntaxKind8.FunctionDeclaration).find((fn) => fn.getName() === functionName);
11668
+ return sourceFile.getDescendantsOfKind(SyntaxKind9.FunctionDeclaration).find((fn) => fn.getName() === functionName);
11641
11669
  }
11642
11670
 
11643
11671
  // src/commands/refactor/extract/getExportedDependencyNames.ts
11644
- import { SyntaxKind as SyntaxKind9 } from "ts-morph";
11672
+ import { SyntaxKind as SyntaxKind10 } from "ts-morph";
11645
11673
  function getExportedDependencyNames(target, sourceFile) {
11646
11674
  const calledNames = /* @__PURE__ */ new Set();
11647
- for (const call of target.getDescendantsOfKind(SyntaxKind9.CallExpression)) {
11675
+ for (const call of target.getDescendantsOfKind(SyntaxKind10.CallExpression)) {
11648
11676
  const expr = call.getExpression();
11649
- if (expr.getKind() === SyntaxKind9.Identifier) {
11677
+ if (expr.getKind() === SyntaxKind10.Identifier) {
11650
11678
  calledNames.add(expr.getText());
11651
11679
  }
11652
11680
  }
11653
11681
  const exported = [];
11654
11682
  for (const fn of sourceFile.getDescendantsOfKind(
11655
- SyntaxKind9.FunctionDeclaration
11683
+ SyntaxKind10.FunctionDeclaration
11656
11684
  )) {
11657
11685
  const name = fn.getName();
11658
11686
  if (name && calledNames.has(name) && fn.isExported()) {
@@ -11663,9 +11691,9 @@ function getExportedDependencyNames(target, sourceFile) {
11663
11691
  }
11664
11692
 
11665
11693
  // src/commands/refactor/extract/getStatementNames.ts
11666
- import { SyntaxKind as SyntaxKind10 } from "ts-morph";
11694
+ import { SyntaxKind as SyntaxKind11 } from "ts-morph";
11667
11695
  function getStatementNames(node) {
11668
- if (node.getKind() === SyntaxKind10.VariableStatement) {
11696
+ if (node.getKind() === SyntaxKind11.VariableStatement) {
11669
11697
  const stmt = node;
11670
11698
  return stmt.getDeclarations().map((d) => d.getName());
11671
11699
  }
@@ -11675,7 +11703,7 @@ function getStatementNames(node) {
11675
11703
 
11676
11704
  // src/commands/refactor/extract/resolveImports.ts
11677
11705
  import {
11678
- SyntaxKind as SyntaxKind11
11706
+ SyntaxKind as SyntaxKind12
11679
11707
  } from "ts-morph";
11680
11708
 
11681
11709
  // src/commands/refactor/extract/matchImport.ts
@@ -11719,7 +11747,7 @@ function matchImport(importDecl, neededNames) {
11719
11747
  function getReferencedNames(nodes) {
11720
11748
  const names = /* @__PURE__ */ new Set();
11721
11749
  for (const node of nodes) {
11722
- for (const id of node.getDescendantsOfKind(SyntaxKind11.Identifier)) {
11750
+ for (const id of node.getDescendantsOfKind(SyntaxKind12.Identifier)) {
11723
11751
  names.add(id.getText());
11724
11752
  }
11725
11753
  }
@@ -11734,7 +11762,7 @@ function getLocallyDeclaredNames(functions) {
11734
11762
  names.add(param.getName());
11735
11763
  }
11736
11764
  for (const varDecl of fn.getDescendantsOfKind(
11737
- SyntaxKind11.VariableDeclaration
11765
+ SyntaxKind12.VariableDeclaration
11738
11766
  )) {
11739
11767
  names.add(varDecl.getName());
11740
11768
  }
@@ -11889,16 +11917,16 @@ function rewriteImportPaths(imports, sourcePath, destPath) {
11889
11917
  }
11890
11918
 
11891
11919
  // src/commands/refactor/extract/sourceReferencesName.ts
11892
- import { SyntaxKind as SyntaxKind12 } from "ts-morph";
11920
+ import { SyntaxKind as SyntaxKind13 } from "ts-morph";
11893
11921
  var DECLARATION_KINDS = /* @__PURE__ */ new Set([
11894
- SyntaxKind12.FunctionDeclaration,
11895
- SyntaxKind12.ImportSpecifier,
11896
- SyntaxKind12.ExportSpecifier
11922
+ SyntaxKind13.FunctionDeclaration,
11923
+ SyntaxKind13.ImportSpecifier,
11924
+ SyntaxKind13.ExportSpecifier
11897
11925
  ]);
11898
11926
  function isInsideExtractedFunction(node, extracted) {
11899
11927
  let current = node;
11900
11928
  while (current) {
11901
- if (current.getKind() !== SyntaxKind12.FunctionDeclaration) {
11929
+ if (current.getKind() !== SyntaxKind13.FunctionDeclaration) {
11902
11930
  current = current.getParent();
11903
11931
  continue;
11904
11932
  }
@@ -11910,7 +11938,7 @@ function isInsideExtractedFunction(node, extracted) {
11910
11938
  }
11911
11939
  function sourceReferencesName(sourceFile, functionName, extractedNames) {
11912
11940
  const extracted = new Set(extractedNames);
11913
- for (const id of sourceFile.getDescendantsOfKind(SyntaxKind12.Identifier)) {
11941
+ for (const id of sourceFile.getDescendantsOfKind(SyntaxKind13.Identifier)) {
11914
11942
  if (id.getText() !== functionName) continue;
11915
11943
  const parent = id.getParent();
11916
11944
  if (!parent || DECLARATION_KINDS.has(parent.getKind())) continue;
@@ -12141,24 +12169,24 @@ async function rename(source, destination, options2 = {}) {
12141
12169
  import chalk135 from "chalk";
12142
12170
 
12143
12171
  // src/commands/refactor/renameSymbol/findSymbol.ts
12144
- import { SyntaxKind as SyntaxKind13 } from "ts-morph";
12172
+ import { SyntaxKind as SyntaxKind14 } from "ts-morph";
12145
12173
  var declarationKinds = [
12146
- SyntaxKind13.VariableDeclaration,
12147
- SyntaxKind13.FunctionDeclaration,
12148
- SyntaxKind13.ClassDeclaration,
12149
- SyntaxKind13.InterfaceDeclaration,
12150
- SyntaxKind13.TypeAliasDeclaration,
12151
- SyntaxKind13.EnumDeclaration,
12152
- SyntaxKind13.PropertyDeclaration,
12153
- SyntaxKind13.MethodDeclaration,
12154
- SyntaxKind13.Parameter
12174
+ SyntaxKind14.VariableDeclaration,
12175
+ SyntaxKind14.FunctionDeclaration,
12176
+ SyntaxKind14.ClassDeclaration,
12177
+ SyntaxKind14.InterfaceDeclaration,
12178
+ SyntaxKind14.TypeAliasDeclaration,
12179
+ SyntaxKind14.EnumDeclaration,
12180
+ SyntaxKind14.PropertyDeclaration,
12181
+ SyntaxKind14.MethodDeclaration,
12182
+ SyntaxKind14.Parameter
12155
12183
  ];
12156
12184
  function isDeclaration(identifier) {
12157
12185
  const parent = identifier.getParent();
12158
12186
  return parent !== void 0 && declarationKinds.includes(parent.getKind());
12159
12187
  }
12160
12188
  function findSymbol(sourceFile, symbolName) {
12161
- for (const id of sourceFile.getDescendantsOfKind(SyntaxKind13.Identifier)) {
12189
+ for (const id of sourceFile.getDescendantsOfKind(SyntaxKind14.Identifier)) {
12162
12190
  if (id.getText() === symbolName && isDeclaration(id)) return id;
12163
12191
  }
12164
12192
  return void 0;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@staff0rd/assist",
3
- "version": "0.238.0",
3
+ "version": "0.238.1",
4
4
  "type": "module",
5
5
  "main": "dist/index.js",
6
6
  "bin": {