@staff0rd/assist 0.215.0 → 0.215.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.
- package/dist/index.js +52 -33
- 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.215.
|
|
9
|
+
version: "0.215.1",
|
|
10
10
|
type: "module",
|
|
11
11
|
main: "dist/index.js",
|
|
12
12
|
bin: {
|
|
@@ -10247,7 +10247,7 @@ async function check(pattern2, options2) {
|
|
|
10247
10247
|
}
|
|
10248
10248
|
|
|
10249
10249
|
// src/commands/refactor/extract/index.ts
|
|
10250
|
-
import
|
|
10250
|
+
import path37 from "path";
|
|
10251
10251
|
import chalk120 from "chalk";
|
|
10252
10252
|
|
|
10253
10253
|
// src/commands/refactor/extract/applyExtraction.ts
|
|
@@ -10844,35 +10844,63 @@ function displayPlan(functionName, relDest, plan2, cwd) {
|
|
|
10844
10844
|
}
|
|
10845
10845
|
|
|
10846
10846
|
// src/commands/refactor/extract/loadProjectFile.ts
|
|
10847
|
+
import path36 from "path";
|
|
10848
|
+
import chalk119 from "chalk";
|
|
10849
|
+
import { Project as Project3 } from "ts-morph";
|
|
10850
|
+
|
|
10851
|
+
// src/commands/refactor/extract/findTsConfig.ts
|
|
10847
10852
|
import fs19 from "fs";
|
|
10848
10853
|
import path35 from "path";
|
|
10849
|
-
import chalk119 from "chalk";
|
|
10850
10854
|
import { Project as Project2 } from "ts-morph";
|
|
10851
10855
|
function findTsConfig(sourcePath) {
|
|
10852
10856
|
const rootConfig = path35.resolve("tsconfig.json");
|
|
10853
10857
|
if (!fs19.existsSync(rootConfig)) return rootConfig;
|
|
10854
|
-
const
|
|
10858
|
+
const tried = /* @__PURE__ */ new Set();
|
|
10859
|
+
const candidates = [rootConfig, ...readReferences(rootConfig)];
|
|
10860
|
+
for (const candidate of candidates) {
|
|
10861
|
+
if (tried.has(candidate)) continue;
|
|
10862
|
+
tried.add(candidate);
|
|
10863
|
+
if (projectIncludes(candidate, sourcePath)) return candidate;
|
|
10864
|
+
}
|
|
10865
|
+
const siblings = fs19.readdirSync(path35.dirname(rootConfig)).filter((f) => /^tsconfig.*\.json$/.test(f)).map((f) => path35.resolve(path35.dirname(rootConfig), f));
|
|
10866
|
+
for (const sibling of siblings) {
|
|
10867
|
+
if (tried.has(sibling)) continue;
|
|
10868
|
+
tried.add(sibling);
|
|
10869
|
+
if (projectIncludes(sibling, sourcePath)) return sibling;
|
|
10870
|
+
}
|
|
10871
|
+
return rootConfig;
|
|
10872
|
+
}
|
|
10873
|
+
function readReferences(configPath) {
|
|
10874
|
+
if (!fs19.existsSync(configPath)) return [];
|
|
10875
|
+
const raw = fs19.readFileSync(configPath, "utf-8");
|
|
10855
10876
|
const stripped = raw.replace(/\/\/.*$/gm, "").replace(/\/\*[\s\S]*?\*\//g, "");
|
|
10856
10877
|
let parsed;
|
|
10857
10878
|
try {
|
|
10858
10879
|
parsed = JSON.parse(stripped);
|
|
10859
10880
|
} catch {
|
|
10860
|
-
return
|
|
10881
|
+
return [];
|
|
10861
10882
|
}
|
|
10862
|
-
if (!parsed.references?.length) return
|
|
10863
|
-
|
|
10864
|
-
|
|
10865
|
-
const
|
|
10866
|
-
|
|
10883
|
+
if (!parsed.references?.length) return [];
|
|
10884
|
+
const cwd = path35.dirname(configPath);
|
|
10885
|
+
return parsed.references.map((ref) => {
|
|
10886
|
+
const refPath = path35.resolve(cwd, ref.path);
|
|
10887
|
+
return fs19.statSync(refPath, { throwIfNoEntry: false })?.isDirectory() ? path35.join(refPath, "tsconfig.json") : refPath;
|
|
10888
|
+
}).filter((p) => fs19.existsSync(p));
|
|
10889
|
+
}
|
|
10890
|
+
function projectIncludes(configPath, sourcePath) {
|
|
10891
|
+
try {
|
|
10867
10892
|
const project = new Project2({ tsConfigFilePath: configPath });
|
|
10868
|
-
|
|
10893
|
+
return !!project.getSourceFile(sourcePath);
|
|
10894
|
+
} catch {
|
|
10895
|
+
return false;
|
|
10869
10896
|
}
|
|
10870
|
-
return rootConfig;
|
|
10871
10897
|
}
|
|
10898
|
+
|
|
10899
|
+
// src/commands/refactor/extract/loadProjectFile.ts
|
|
10872
10900
|
function loadProjectFile(file) {
|
|
10873
|
-
const sourcePath =
|
|
10901
|
+
const sourcePath = path36.resolve(file);
|
|
10874
10902
|
const tsConfigPath = findTsConfig(sourcePath);
|
|
10875
|
-
const project = new
|
|
10903
|
+
const project = new Project3({
|
|
10876
10904
|
tsConfigFilePath: tsConfigPath
|
|
10877
10905
|
});
|
|
10878
10906
|
const sourceFile = project.getSourceFile(sourcePath);
|
|
@@ -10885,10 +10913,10 @@ function loadProjectFile(file) {
|
|
|
10885
10913
|
|
|
10886
10914
|
// src/commands/refactor/extract/index.ts
|
|
10887
10915
|
async function extract(file, functionName, destination, options2 = {}) {
|
|
10888
|
-
const sourcePath =
|
|
10889
|
-
const destPath =
|
|
10916
|
+
const sourcePath = path37.resolve(file);
|
|
10917
|
+
const destPath = path37.resolve(destination);
|
|
10890
10918
|
const cwd = process.cwd();
|
|
10891
|
-
const relDest =
|
|
10919
|
+
const relDest = path37.relative(cwd, destPath);
|
|
10892
10920
|
const { project, sourceFile } = loadProjectFile(file);
|
|
10893
10921
|
const plan2 = buildPlan(
|
|
10894
10922
|
functionName,
|
|
@@ -10935,13 +10963,13 @@ function ignore(file) {
|
|
|
10935
10963
|
}
|
|
10936
10964
|
|
|
10937
10965
|
// src/commands/refactor/rename/index.ts
|
|
10938
|
-
import
|
|
10966
|
+
import path38 from "path";
|
|
10939
10967
|
import chalk122 from "chalk";
|
|
10940
10968
|
async function rename(source, destination, options2 = {}) {
|
|
10941
|
-
const destPath =
|
|
10969
|
+
const destPath = path38.resolve(destination);
|
|
10942
10970
|
const cwd = process.cwd();
|
|
10943
|
-
const relSource =
|
|
10944
|
-
const relDest =
|
|
10971
|
+
const relSource = path38.relative(cwd, path38.resolve(source));
|
|
10972
|
+
const relDest = path38.relative(cwd, destPath);
|
|
10945
10973
|
const { project, sourceFile } = loadProjectFile(source);
|
|
10946
10974
|
console.log(chalk122.bold(`Rename: ${relSource} \u2192 ${relDest}`));
|
|
10947
10975
|
if (options2.apply) {
|
|
@@ -10954,9 +10982,7 @@ async function rename(source, destination, options2 = {}) {
|
|
|
10954
10982
|
}
|
|
10955
10983
|
|
|
10956
10984
|
// src/commands/refactor/renameSymbol/index.ts
|
|
10957
|
-
import path39 from "path";
|
|
10958
10985
|
import chalk123 from "chalk";
|
|
10959
|
-
import { Project as Project3 } from "ts-morph";
|
|
10960
10986
|
|
|
10961
10987
|
// src/commands/refactor/renameSymbol/findSymbol.ts
|
|
10962
10988
|
import { SyntaxKind as SyntaxKind13 } from "ts-morph";
|
|
@@ -10983,12 +11009,12 @@ function findSymbol(sourceFile, symbolName) {
|
|
|
10983
11009
|
}
|
|
10984
11010
|
|
|
10985
11011
|
// src/commands/refactor/renameSymbol/groupReferences.ts
|
|
10986
|
-
import
|
|
11012
|
+
import path39 from "path";
|
|
10987
11013
|
function groupReferences(symbol, cwd) {
|
|
10988
11014
|
const refs = symbol.findReferencesAsNodes();
|
|
10989
11015
|
const grouped = /* @__PURE__ */ new Map();
|
|
10990
11016
|
for (const ref of refs) {
|
|
10991
|
-
const refFile =
|
|
11017
|
+
const refFile = path39.relative(cwd, ref.getSourceFile().getFilePath());
|
|
10992
11018
|
const lines = grouped.get(refFile) ?? [];
|
|
10993
11019
|
if (!grouped.has(refFile)) grouped.set(refFile, lines);
|
|
10994
11020
|
lines.push(ref.getStartLineNumber());
|
|
@@ -10998,15 +11024,8 @@ function groupReferences(symbol, cwd) {
|
|
|
10998
11024
|
|
|
10999
11025
|
// src/commands/refactor/renameSymbol/index.ts
|
|
11000
11026
|
async function renameSymbol(file, oldName, newName, options2 = {}) {
|
|
11001
|
-
const filePath = path39.resolve(file);
|
|
11002
|
-
const tsConfigPath = path39.resolve("tsconfig.json");
|
|
11003
11027
|
const cwd = process.cwd();
|
|
11004
|
-
const project =
|
|
11005
|
-
const sourceFile = project.getSourceFile(filePath);
|
|
11006
|
-
if (!sourceFile) {
|
|
11007
|
-
console.log(chalk123.red(`File not found in project: ${file}`));
|
|
11008
|
-
process.exit(1);
|
|
11009
|
-
}
|
|
11028
|
+
const { project, sourceFile } = loadProjectFile(file);
|
|
11010
11029
|
const symbol = findSymbol(sourceFile, oldName);
|
|
11011
11030
|
if (!symbol) {
|
|
11012
11031
|
console.log(chalk123.red(`Symbol "${oldName}" not found in ${file}`));
|