@staff0rd/assist 0.170.1 → 0.170.3
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 +96 -79
- 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.170.
|
|
9
|
+
version: "0.170.3",
|
|
10
10
|
type: "module",
|
|
11
11
|
main: "dist/index.js",
|
|
12
12
|
bin: {
|
|
@@ -161,13 +161,9 @@ function loadBacklog() {
|
|
|
161
161
|
if (!existsSync(backlogPath)) {
|
|
162
162
|
return [];
|
|
163
163
|
}
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
return backlogFileSchema.parse(raw);
|
|
168
|
-
} catch {
|
|
169
|
-
return [];
|
|
170
|
-
}
|
|
164
|
+
const content = readFileSync(backlogPath, "utf-8");
|
|
165
|
+
const raw = parseYaml(content) || [];
|
|
166
|
+
return backlogFileSchema.parse(raw);
|
|
171
167
|
}
|
|
172
168
|
function saveBacklog(items) {
|
|
173
169
|
const backlogPath = getBacklogPath();
|
|
@@ -8000,7 +7996,7 @@ function isNameReferencedInSource(sourceFile, name) {
|
|
|
8000
7996
|
}
|
|
8001
7997
|
async function applyExtraction(functionName, sourceFile, destPath, plan2, project) {
|
|
8002
7998
|
project.createSourceFile(destPath, plan2.destContent, { overwrite: false });
|
|
8003
|
-
for (const fn of [plan2.target, ...plan2.
|
|
7999
|
+
for (const fn of [plan2.target, ...plan2.functionsToRemove]) {
|
|
8004
8000
|
fn.remove();
|
|
8005
8001
|
}
|
|
8006
8002
|
for (const stmt of plan2.statementsToRemove) {
|
|
@@ -8037,7 +8033,7 @@ async function applyExtraction(functionName, sourceFile, destPath, plan2, projec
|
|
|
8037
8033
|
|
|
8038
8034
|
// src/commands/refactor/extract/collectDependencies.ts
|
|
8039
8035
|
import {
|
|
8040
|
-
SyntaxKind as
|
|
8036
|
+
SyntaxKind as SyntaxKind7
|
|
8041
8037
|
} from "ts-morph";
|
|
8042
8038
|
|
|
8043
8039
|
// src/commands/refactor/extract/collectPrivateFunctions.ts
|
|
@@ -8076,6 +8072,41 @@ function collectPrivateFunctions(target, fnMap) {
|
|
|
8076
8072
|
});
|
|
8077
8073
|
}
|
|
8078
8074
|
|
|
8075
|
+
// src/commands/refactor/extract/collectPrivateStatements.ts
|
|
8076
|
+
import { SyntaxKind as SyntaxKind5 } from "ts-morph";
|
|
8077
|
+
function getReferencedIdentifiers(fn) {
|
|
8078
|
+
const names = /* @__PURE__ */ new Set();
|
|
8079
|
+
for (const id of fn.getDescendantsOfKind(SyntaxKind5.Identifier)) {
|
|
8080
|
+
names.add(id.getText());
|
|
8081
|
+
}
|
|
8082
|
+
return names;
|
|
8083
|
+
}
|
|
8084
|
+
function collectPrivateStatements(functions, stmtMap) {
|
|
8085
|
+
const seen = /* @__PURE__ */ new Set();
|
|
8086
|
+
for (const fn of functions) {
|
|
8087
|
+
for (const name of getReferencedIdentifiers(fn)) {
|
|
8088
|
+
const stmt = stmtMap.get(name);
|
|
8089
|
+
if (stmt) seen.add(stmt);
|
|
8090
|
+
}
|
|
8091
|
+
}
|
|
8092
|
+
return [...seen];
|
|
8093
|
+
}
|
|
8094
|
+
|
|
8095
|
+
// src/commands/refactor/extract/getFunctionMap.ts
|
|
8096
|
+
import {
|
|
8097
|
+
SyntaxKind as SyntaxKind6
|
|
8098
|
+
} from "ts-morph";
|
|
8099
|
+
function getFunctionMap(sourceFile) {
|
|
8100
|
+
const map = /* @__PURE__ */ new Map();
|
|
8101
|
+
for (const fn of sourceFile.getDescendantsOfKind(
|
|
8102
|
+
SyntaxKind6.FunctionDeclaration
|
|
8103
|
+
)) {
|
|
8104
|
+
const name = fn.getName();
|
|
8105
|
+
if (name) map.set(name, fn);
|
|
8106
|
+
}
|
|
8107
|
+
return map;
|
|
8108
|
+
}
|
|
8109
|
+
|
|
8079
8110
|
// src/commands/refactor/extract/getPrivateStatementMap.ts
|
|
8080
8111
|
function getPrivateStatementMap(sourceFile) {
|
|
8081
8112
|
const map = /* @__PURE__ */ new Map();
|
|
@@ -8093,73 +8124,61 @@ function getPrivateStatementMap(sourceFile) {
|
|
|
8093
8124
|
}
|
|
8094
8125
|
|
|
8095
8126
|
// src/commands/refactor/extract/collectDependencies.ts
|
|
8096
|
-
function
|
|
8097
|
-
|
|
8098
|
-
for (const id of fn.getDescendantsOfKind(SyntaxKind5.Identifier)) {
|
|
8099
|
-
names.add(id.getText());
|
|
8100
|
-
}
|
|
8101
|
-
return names;
|
|
8102
|
-
}
|
|
8103
|
-
function getFunctionMap(sourceFile) {
|
|
8104
|
-
const map = /* @__PURE__ */ new Map();
|
|
8105
|
-
for (const fn of sourceFile.getDescendantsOfKind(
|
|
8106
|
-
SyntaxKind5.FunctionDeclaration
|
|
8107
|
-
)) {
|
|
8108
|
-
const name = fn.getName();
|
|
8109
|
-
if (name) map.set(name, fn);
|
|
8110
|
-
}
|
|
8111
|
-
return map;
|
|
8127
|
+
function getRemainingFunctions(sourceFile, extracted) {
|
|
8128
|
+
return sourceFile.getDescendantsOfKind(SyntaxKind7.FunctionDeclaration).filter((fn) => !extracted.has(fn));
|
|
8112
8129
|
}
|
|
8113
|
-
function
|
|
8114
|
-
const
|
|
8115
|
-
for (const fn of
|
|
8116
|
-
for (const
|
|
8117
|
-
|
|
8118
|
-
if (stmt) seen.add(stmt);
|
|
8130
|
+
function collectFnsUsedByRemaining(remaining, fnMap) {
|
|
8131
|
+
const used = /* @__PURE__ */ new Set();
|
|
8132
|
+
for (const fn of remaining) {
|
|
8133
|
+
for (const dep of collectPrivateFunctions(fn, fnMap)) {
|
|
8134
|
+
used.add(dep);
|
|
8119
8135
|
}
|
|
8120
8136
|
}
|
|
8121
|
-
return
|
|
8122
|
-
}
|
|
8123
|
-
function getRemainingFunctions(sourceFile, extracted) {
|
|
8124
|
-
return sourceFile.getDescendantsOfKind(SyntaxKind5.FunctionDeclaration).filter((fn) => !extracted.has(fn));
|
|
8137
|
+
return used;
|
|
8125
8138
|
}
|
|
8126
8139
|
function collectDependencies(target, sourceFile) {
|
|
8127
8140
|
const fnMap = getFunctionMap(sourceFile);
|
|
8128
8141
|
const depFunctions = collectPrivateFunctions(target, fnMap);
|
|
8129
8142
|
const allExtracted = [target, ...depFunctions];
|
|
8130
8143
|
const stmtMap = getPrivateStatementMap(sourceFile);
|
|
8131
|
-
const
|
|
8132
|
-
const
|
|
8133
|
-
const
|
|
8134
|
-
const
|
|
8135
|
-
const
|
|
8144
|
+
const stmtsToCopy = collectPrivateStatements(allExtracted, stmtMap);
|
|
8145
|
+
const remaining = getRemainingFunctions(sourceFile, new Set(allExtracted));
|
|
8146
|
+
const fnsUsedByRemaining = collectFnsUsedByRemaining(remaining, fnMap);
|
|
8147
|
+
const fnsToRemove = depFunctions.filter((fn) => !fnsUsedByRemaining.has(fn));
|
|
8148
|
+
const staysInSource = [
|
|
8149
|
+
...remaining,
|
|
8150
|
+
...depFunctions.filter((fn) => fnsUsedByRemaining.has(fn))
|
|
8151
|
+
];
|
|
8152
|
+
const stmtsToRemove = stmtsToCopy.filter(
|
|
8153
|
+
(s) => !new Set(collectPrivateStatements(staysInSource, stmtMap)).has(s)
|
|
8154
|
+
);
|
|
8136
8155
|
return {
|
|
8137
|
-
functions: depFunctions,
|
|
8138
|
-
statements: { toCopy, toRemove }
|
|
8156
|
+
functions: { toCopy: depFunctions, toRemove: fnsToRemove },
|
|
8157
|
+
statements: { toCopy: stmtsToCopy, toRemove: stmtsToRemove }
|
|
8139
8158
|
};
|
|
8140
8159
|
}
|
|
8141
8160
|
|
|
8142
8161
|
// src/commands/refactor/extract/findFunction.ts
|
|
8143
8162
|
import {
|
|
8144
|
-
SyntaxKind as
|
|
8163
|
+
SyntaxKind as SyntaxKind8
|
|
8145
8164
|
} from "ts-morph";
|
|
8146
8165
|
function findFunction(sourceFile, functionName) {
|
|
8147
|
-
return sourceFile.getDescendantsOfKind(
|
|
8166
|
+
return sourceFile.getDescendantsOfKind(SyntaxKind8.FunctionDeclaration).find((fn) => fn.getName() === functionName);
|
|
8148
8167
|
}
|
|
8149
8168
|
|
|
8150
8169
|
// src/commands/refactor/extract/getExportedDependencyNames.ts
|
|
8151
|
-
import { SyntaxKind as
|
|
8170
|
+
import { SyntaxKind as SyntaxKind9 } from "ts-morph";
|
|
8152
8171
|
function getExportedDependencyNames(target, sourceFile) {
|
|
8153
8172
|
const calledNames = /* @__PURE__ */ new Set();
|
|
8154
|
-
for (const call of target.getDescendantsOfKind(
|
|
8173
|
+
for (const call of target.getDescendantsOfKind(SyntaxKind9.CallExpression)) {
|
|
8155
8174
|
const expr = call.getExpression();
|
|
8156
|
-
if (expr.getKind() ===
|
|
8175
|
+
if (expr.getKind() === SyntaxKind9.Identifier) {
|
|
8157
8176
|
calledNames.add(expr.getText());
|
|
8158
8177
|
}
|
|
8159
8178
|
}
|
|
8160
8179
|
const exported = [];
|
|
8161
8180
|
for (const fn of sourceFile.getDescendantsOfKind(
|
|
8162
|
-
|
|
8181
|
+
SyntaxKind9.FunctionDeclaration
|
|
8163
8182
|
)) {
|
|
8164
8183
|
const name = fn.getName();
|
|
8165
8184
|
if (name && calledNames.has(name) && fn.isExported()) {
|
|
@@ -8170,9 +8189,9 @@ function getExportedDependencyNames(target, sourceFile) {
|
|
|
8170
8189
|
}
|
|
8171
8190
|
|
|
8172
8191
|
// src/commands/refactor/extract/getStatementNames.ts
|
|
8173
|
-
import { SyntaxKind as
|
|
8192
|
+
import { SyntaxKind as SyntaxKind10 } from "ts-morph";
|
|
8174
8193
|
function getStatementNames(node) {
|
|
8175
|
-
if (node.getKind() ===
|
|
8194
|
+
if (node.getKind() === SyntaxKind10.VariableStatement) {
|
|
8176
8195
|
const stmt = node;
|
|
8177
8196
|
return stmt.getDeclarations().map((d) => d.getName());
|
|
8178
8197
|
}
|
|
@@ -8182,7 +8201,7 @@ function getStatementNames(node) {
|
|
|
8182
8201
|
|
|
8183
8202
|
// src/commands/refactor/extract/resolveImports.ts
|
|
8184
8203
|
import {
|
|
8185
|
-
SyntaxKind as
|
|
8204
|
+
SyntaxKind as SyntaxKind11
|
|
8186
8205
|
} from "ts-morph";
|
|
8187
8206
|
|
|
8188
8207
|
// src/commands/refactor/extract/matchImport.ts
|
|
@@ -8226,7 +8245,7 @@ function matchImport(importDecl, neededNames) {
|
|
|
8226
8245
|
function getReferencedNames(nodes) {
|
|
8227
8246
|
const names = /* @__PURE__ */ new Set();
|
|
8228
8247
|
for (const node of nodes) {
|
|
8229
|
-
for (const id of node.getDescendantsOfKind(
|
|
8248
|
+
for (const id of node.getDescendantsOfKind(SyntaxKind11.Identifier)) {
|
|
8230
8249
|
names.add(id.getText());
|
|
8231
8250
|
}
|
|
8232
8251
|
}
|
|
@@ -8241,7 +8260,7 @@ function getLocallyDeclaredNames(functions) {
|
|
|
8241
8260
|
names.add(param.getName());
|
|
8242
8261
|
}
|
|
8243
8262
|
for (const varDecl of fn.getDescendantsOfKind(
|
|
8244
|
-
|
|
8263
|
+
SyntaxKind11.VariableDeclaration
|
|
8245
8264
|
)) {
|
|
8246
8265
|
names.add(varDecl.getName());
|
|
8247
8266
|
}
|
|
@@ -8278,26 +8297,24 @@ function extractTexts(target, allFunctions, statements) {
|
|
|
8278
8297
|
function analyseTarget(sourceFile, functionName) {
|
|
8279
8298
|
const target = findFunction(sourceFile, functionName);
|
|
8280
8299
|
if (!target) throw new Error(`Function "${functionName}" not found`);
|
|
8281
|
-
const { functions
|
|
8282
|
-
|
|
8283
|
-
sourceFile
|
|
8284
|
-
);
|
|
8285
|
-
const all = [target, ...dependencies];
|
|
8300
|
+
const { functions, statements } = collectDependencies(target, sourceFile);
|
|
8301
|
+
const all = [target, ...functions.toCopy];
|
|
8286
8302
|
return {
|
|
8287
8303
|
target,
|
|
8288
|
-
dependencies,
|
|
8304
|
+
dependencies: functions.toCopy,
|
|
8305
|
+
functionsToRemove: functions.toRemove,
|
|
8289
8306
|
statementsToCopy: statements.toCopy,
|
|
8290
8307
|
statementsToRemove: statements.toRemove,
|
|
8291
8308
|
imports: resolveImports(
|
|
8292
8309
|
target,
|
|
8293
|
-
|
|
8310
|
+
functions.toCopy,
|
|
8294
8311
|
sourceFile,
|
|
8295
8312
|
statements.toCopy
|
|
8296
8313
|
),
|
|
8297
8314
|
exportedDeps: getExportedDependencyNames(target, sourceFile),
|
|
8298
8315
|
extractedNames: [
|
|
8299
8316
|
...statements.toRemove.flatMap(getStatementNames),
|
|
8300
|
-
...
|
|
8317
|
+
...[target, ...functions.toRemove].map((fn) => fn.getName()).filter(Boolean)
|
|
8301
8318
|
],
|
|
8302
8319
|
functionTexts: extractTexts(target, all, statements.toCopy)
|
|
8303
8320
|
};
|
|
@@ -8398,16 +8415,16 @@ function rewriteImportPaths(imports, sourcePath, destPath) {
|
|
|
8398
8415
|
}
|
|
8399
8416
|
|
|
8400
8417
|
// src/commands/refactor/extract/sourceReferencesName.ts
|
|
8401
|
-
import { SyntaxKind as
|
|
8418
|
+
import { SyntaxKind as SyntaxKind12 } from "ts-morph";
|
|
8402
8419
|
var DECLARATION_KINDS = /* @__PURE__ */ new Set([
|
|
8403
|
-
|
|
8404
|
-
|
|
8405
|
-
|
|
8420
|
+
SyntaxKind12.FunctionDeclaration,
|
|
8421
|
+
SyntaxKind12.ImportSpecifier,
|
|
8422
|
+
SyntaxKind12.ExportSpecifier
|
|
8406
8423
|
]);
|
|
8407
8424
|
function isInsideExtractedFunction(node, extracted) {
|
|
8408
8425
|
let current = node;
|
|
8409
8426
|
while (current) {
|
|
8410
|
-
if (current.getKind() !==
|
|
8427
|
+
if (current.getKind() !== SyntaxKind12.FunctionDeclaration) {
|
|
8411
8428
|
current = current.getParent();
|
|
8412
8429
|
continue;
|
|
8413
8430
|
}
|
|
@@ -8419,7 +8436,7 @@ function isInsideExtractedFunction(node, extracted) {
|
|
|
8419
8436
|
}
|
|
8420
8437
|
function sourceReferencesName(sourceFile, functionName, extractedNames) {
|
|
8421
8438
|
const extracted = new Set(extractedNames);
|
|
8422
|
-
for (const id of sourceFile.getDescendantsOfKind(
|
|
8439
|
+
for (const id of sourceFile.getDescendantsOfKind(SyntaxKind12.Identifier)) {
|
|
8423
8440
|
if (id.getText() !== functionName) continue;
|
|
8424
8441
|
const parent = id.getParent();
|
|
8425
8442
|
if (!parent || DECLARATION_KINDS.has(parent.getKind())) continue;
|
|
@@ -8624,24 +8641,24 @@ import chalk107 from "chalk";
|
|
|
8624
8641
|
import { Project as Project3 } from "ts-morph";
|
|
8625
8642
|
|
|
8626
8643
|
// src/commands/refactor/renameSymbol/findSymbol.ts
|
|
8627
|
-
import { SyntaxKind as
|
|
8644
|
+
import { SyntaxKind as SyntaxKind13 } from "ts-morph";
|
|
8628
8645
|
var declarationKinds = [
|
|
8629
|
-
|
|
8630
|
-
|
|
8631
|
-
|
|
8632
|
-
|
|
8633
|
-
|
|
8634
|
-
|
|
8635
|
-
|
|
8636
|
-
|
|
8637
|
-
|
|
8646
|
+
SyntaxKind13.VariableDeclaration,
|
|
8647
|
+
SyntaxKind13.FunctionDeclaration,
|
|
8648
|
+
SyntaxKind13.ClassDeclaration,
|
|
8649
|
+
SyntaxKind13.InterfaceDeclaration,
|
|
8650
|
+
SyntaxKind13.TypeAliasDeclaration,
|
|
8651
|
+
SyntaxKind13.EnumDeclaration,
|
|
8652
|
+
SyntaxKind13.PropertyDeclaration,
|
|
8653
|
+
SyntaxKind13.MethodDeclaration,
|
|
8654
|
+
SyntaxKind13.Parameter
|
|
8638
8655
|
];
|
|
8639
8656
|
function isDeclaration(identifier) {
|
|
8640
8657
|
const parent = identifier.getParent();
|
|
8641
8658
|
return parent !== void 0 && declarationKinds.includes(parent.getKind());
|
|
8642
8659
|
}
|
|
8643
8660
|
function findSymbol(sourceFile, symbolName) {
|
|
8644
|
-
for (const id of sourceFile.getDescendantsOfKind(
|
|
8661
|
+
for (const id of sourceFile.getDescendantsOfKind(SyntaxKind13.Identifier)) {
|
|
8645
8662
|
if (id.getText() === symbolName && isDeclaration(id)) return id;
|
|
8646
8663
|
}
|
|
8647
8664
|
return void 0;
|