@wrongstack/tools 0.7.8 → 0.8.2
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/builtin.js +41 -34
- package/dist/builtin.js.map +1 -1
- package/dist/codebase-index/index.js +50 -45
- package/dist/codebase-index/index.js.map +1 -1
- package/dist/exec.js +5 -2
- package/dist/exec.js.map +1 -1
- package/dist/index.js +41 -34
- package/dist/index.js.map +1 -1
- package/dist/install.js +1 -1
- package/dist/install.js.map +1 -1
- package/dist/pack.js +41 -34
- package/dist/pack.js.map +1 -1
- package/package.json +2 -2
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import * as fs2 from 'node:fs/promises';
|
|
2
|
-
import * as
|
|
2
|
+
import * as path4 from 'node:path';
|
|
3
3
|
import { compileGlob } from '@wrongstack/core';
|
|
4
4
|
import { createRequire } from 'node:module';
|
|
5
5
|
import * as fs from 'node:fs';
|
|
6
|
-
import { mkdirSync, writeFileSync
|
|
6
|
+
import { mkdirSync, writeFileSync } from 'node:fs';
|
|
7
7
|
import * as ts from 'typescript';
|
|
8
8
|
import { execSync, spawnSync } from 'node:child_process';
|
|
9
|
+
import * as os from 'node:os';
|
|
9
10
|
|
|
10
11
|
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
|
|
11
12
|
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
|
|
@@ -111,10 +112,10 @@ function loadDatabaseSync() {
|
|
|
111
112
|
var IndexStore = class {
|
|
112
113
|
constructor(projectRoot) {
|
|
113
114
|
this.projectRoot = projectRoot;
|
|
114
|
-
const dir =
|
|
115
|
+
const dir = path4.join(projectRoot, INDEX_DIR);
|
|
115
116
|
fs.mkdirSync(dir, { recursive: true });
|
|
116
117
|
const Database = loadDatabaseSync();
|
|
117
|
-
this.db = new Database(
|
|
118
|
+
this.db = new Database(path4.join(dir, DB_FILE));
|
|
118
119
|
this.initSchema();
|
|
119
120
|
}
|
|
120
121
|
projectRoot;
|
|
@@ -309,7 +310,7 @@ var IndexStore = class {
|
|
|
309
310
|
totalFiles,
|
|
310
311
|
byLang,
|
|
311
312
|
byKind,
|
|
312
|
-
indexPath:
|
|
313
|
+
indexPath: path4.join(this.projectRoot, INDEX_DIR),
|
|
313
314
|
lastIndexed,
|
|
314
315
|
sizeBytes,
|
|
315
316
|
version: SCHEMA_VERSION
|
|
@@ -402,7 +403,7 @@ var IndexStore = class {
|
|
|
402
403
|
}));
|
|
403
404
|
}
|
|
404
405
|
sizeBytes() {
|
|
405
|
-
const dbPath =
|
|
406
|
+
const dbPath = path4.join(this.projectRoot, INDEX_DIR, DB_FILE);
|
|
406
407
|
try {
|
|
407
408
|
return fs.statSync(dbPath).size;
|
|
408
409
|
} catch {
|
|
@@ -617,6 +618,7 @@ import (
|
|
|
617
618
|
"go/ast"
|
|
618
619
|
"go/parser"
|
|
619
620
|
"go/token"
|
|
621
|
+
"io"
|
|
620
622
|
"os"
|
|
621
623
|
"strings"
|
|
622
624
|
)
|
|
@@ -631,17 +633,13 @@ type Sym struct {
|
|
|
631
633
|
}
|
|
632
634
|
|
|
633
635
|
func main() {
|
|
634
|
-
|
|
635
|
-
fmt.Print("[]")
|
|
636
|
-
return
|
|
637
|
-
}
|
|
638
|
-
src, err := os.ReadFile(os.Args[1])
|
|
636
|
+
src, err := io.ReadAll(os.Stdin)
|
|
639
637
|
if err != nil {
|
|
640
638
|
fmt.Print("[]")
|
|
641
639
|
return
|
|
642
640
|
}
|
|
643
641
|
fset := token.NewFileSet()
|
|
644
|
-
node, err := parser.ParseFile(fset,
|
|
642
|
+
node, err := parser.ParseFile(fset, "src.go", src, 0)
|
|
645
643
|
if err != nil {
|
|
646
644
|
fmt.Print("[]")
|
|
647
645
|
return
|
|
@@ -785,7 +783,7 @@ func formatMethods(fields []*ast.Field) string {
|
|
|
785
783
|
return formatFields(fields)
|
|
786
784
|
}
|
|
787
785
|
|
|
788
|
-
func formatTypeParams(tp *ast.
|
|
786
|
+
func formatTypeParams(tp *ast.FieldList) string {
|
|
789
787
|
if tp == nil || len(tp.List) == 0 {
|
|
790
788
|
return ""
|
|
791
789
|
}
|
|
@@ -828,30 +826,33 @@ func formatType(t ast.Expr) string {
|
|
|
828
826
|
return "chan " + formatType(v.Value)
|
|
829
827
|
case *ast.BasicLit:
|
|
830
828
|
return v.Value
|
|
829
|
+
case *ast.IndexExpr:
|
|
830
|
+
// Generic instantiation with one type arg, e.g. Logger[int].
|
|
831
|
+
return formatType(v.X) + "[" + formatType(v.Index) + "]"
|
|
832
|
+
case *ast.IndexListExpr:
|
|
833
|
+
// Generic instantiation with multiple type args, e.g. Map[K, V].
|
|
834
|
+
args := make([]string, len(v.Indices))
|
|
835
|
+
for i, idx := range v.Indices {
|
|
836
|
+
args[i] = formatType(idx)
|
|
837
|
+
}
|
|
838
|
+
return formatType(v.X) + "[" + strings.Join(args, ", ") + "]"
|
|
831
839
|
default:
|
|
832
840
|
return "?"
|
|
833
841
|
}
|
|
834
842
|
}
|
|
835
843
|
`;
|
|
836
|
-
function syncGoParse(filePath,
|
|
837
|
-
const tmpDir =
|
|
844
|
+
function syncGoParse(filePath, content, lang) {
|
|
845
|
+
const tmpDir = path4.join(os.tmpdir(), "ws-go-parse");
|
|
838
846
|
try {
|
|
839
847
|
mkdirSync(tmpDir, { recursive: true });
|
|
840
|
-
const scriptPath =
|
|
848
|
+
const scriptPath = path4.join(tmpDir, "parse.go");
|
|
841
849
|
writeFileSync(scriptPath, GO_PARSE_SCRIPT, "utf8");
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
});
|
|
849
|
-
} finally {
|
|
850
|
-
try {
|
|
851
|
-
unlinkSync(scriptPath);
|
|
852
|
-
} catch {
|
|
853
|
-
}
|
|
854
|
-
}
|
|
850
|
+
const stdout = execSync(`go run "${scriptPath}"`, {
|
|
851
|
+
input: content,
|
|
852
|
+
timeout: 15e3,
|
|
853
|
+
encoding: "utf8",
|
|
854
|
+
windowsHide: true
|
|
855
|
+
});
|
|
855
856
|
if (!stdout.trim()) {
|
|
856
857
|
return { file: filePath, lang, symbols: [], mtimeMs: Date.now() };
|
|
857
858
|
}
|
|
@@ -1088,7 +1089,11 @@ print(json.dumps([s.to_dict() for s in syms]))
|
|
|
1088
1089
|
`;
|
|
1089
1090
|
function syncPyParse(filePath, lang) {
|
|
1090
1091
|
try {
|
|
1091
|
-
const
|
|
1092
|
+
const tmpDir = path4.join(os.tmpdir(), "ws-py-parse");
|
|
1093
|
+
mkdirSync(tmpDir, { recursive: true });
|
|
1094
|
+
const scriptPath = path4.join(tmpDir, "parse.py");
|
|
1095
|
+
writeFileSync(scriptPath, PY_PARSE_SCRIPT, "utf8");
|
|
1096
|
+
const stdout = execSync(`python "${scriptPath}" "${filePath}"`, {
|
|
1092
1097
|
timeout: 15e3,
|
|
1093
1098
|
encoding: "utf8",
|
|
1094
1099
|
windowsHide: true
|
|
@@ -1127,10 +1132,10 @@ function parseSymbols4(opts) {
|
|
|
1127
1132
|
function checkNativeParser() {
|
|
1128
1133
|
try {
|
|
1129
1134
|
execSync("rustc --version", { stdio: "pipe" });
|
|
1130
|
-
const toolsDir =
|
|
1135
|
+
const toolsDir = path4.join(process.cwd(), "tools");
|
|
1131
1136
|
try {
|
|
1132
1137
|
execSync(
|
|
1133
|
-
"cargo metadata --no-deps --format-version 1 --manifest-path " +
|
|
1138
|
+
"cargo metadata --no-deps --format-version 1 --manifest-path " + path4.join(toolsDir, "Cargo.toml"),
|
|
1134
1139
|
{ stdio: "pipe" }
|
|
1135
1140
|
);
|
|
1136
1141
|
return true;
|
|
@@ -1143,14 +1148,14 @@ function checkNativeParser() {
|
|
|
1143
1148
|
}
|
|
1144
1149
|
function tryNativeParse(file, content) {
|
|
1145
1150
|
try {
|
|
1146
|
-
const toolsDir =
|
|
1147
|
-
const crateDir =
|
|
1148
|
-
const tmpFile =
|
|
1149
|
-
const { writeFileSync:
|
|
1150
|
-
|
|
1151
|
+
const toolsDir = path4.join(process.cwd(), "tools");
|
|
1152
|
+
const crateDir = path4.join(toolsDir, "syn-parser");
|
|
1153
|
+
const tmpFile = path4.join(crateDir, "src", "input.rs");
|
|
1154
|
+
const { writeFileSync: writeFileSync3 } = __require("node:fs");
|
|
1155
|
+
writeFileSync3(tmpFile, content, "utf8");
|
|
1151
1156
|
const result = spawnSync(
|
|
1152
1157
|
"cargo",
|
|
1153
|
-
["run", "--manifest-path",
|
|
1158
|
+
["run", "--manifest-path", path4.join(toolsDir, "Cargo.toml")],
|
|
1154
1159
|
{
|
|
1155
1160
|
cwd: process.cwd(),
|
|
1156
1161
|
encoding: "utf8",
|
|
@@ -1248,7 +1253,7 @@ function parseSymbols5(opts) {
|
|
|
1248
1253
|
function regexParse2(opts) {
|
|
1249
1254
|
const { file, content, lang } = opts;
|
|
1250
1255
|
const symbols = [];
|
|
1251
|
-
const basename2 =
|
|
1256
|
+
const basename2 = path4.basename(file).toLowerCase();
|
|
1252
1257
|
const isPackageJson = basename2 === "package.json";
|
|
1253
1258
|
const isTsconfig = basename2 === "tsconfig.json" || basename2 === "tsconfig.build.json";
|
|
1254
1259
|
const isJsonSchema = content.includes("$schema") || content.includes("$id") || content.includes("$ref");
|
|
@@ -1274,11 +1279,11 @@ function regexParse2(opts) {
|
|
|
1274
1279
|
const line = lineFromOffset(offset);
|
|
1275
1280
|
symbols.push(
|
|
1276
1281
|
makeSymbol({
|
|
1277
|
-
name:
|
|
1282
|
+
name: path4.basename(file),
|
|
1278
1283
|
kind: "object",
|
|
1279
1284
|
line,
|
|
1280
1285
|
col: 0,
|
|
1281
|
-
signature: `"${
|
|
1286
|
+
signature: `"${path4.basename(file)}" = { ... }`,
|
|
1282
1287
|
file,
|
|
1283
1288
|
lang
|
|
1284
1289
|
})
|
|
@@ -1626,12 +1631,12 @@ async function findSourceFiles(projectRoot, ignore) {
|
|
|
1626
1631
|
}
|
|
1627
1632
|
for (const e of entries) {
|
|
1628
1633
|
if (ignoreSet.has(e.name)) continue;
|
|
1629
|
-
const full =
|
|
1634
|
+
const full = path4.join(dir, e.name);
|
|
1630
1635
|
if (e.isDirectory()) {
|
|
1631
1636
|
await walk(full);
|
|
1632
1637
|
} else if (e.isFile()) {
|
|
1633
|
-
const rel =
|
|
1634
|
-
const ext =
|
|
1638
|
+
const rel = path4.relative(projectRoot, full).replace(/\\/g, "/");
|
|
1639
|
+
const ext = path4.extname(e.name);
|
|
1635
1640
|
for (const { ext: extName, pat } of globs) {
|
|
1636
1641
|
if (ext === extName && (pat.test(rel) || pat.test(e.name))) {
|
|
1637
1642
|
results.push(full);
|
|
@@ -1675,7 +1680,7 @@ async function runIndexer(ctx, opts) {
|
|
|
1675
1680
|
let symbolsIndexed = 0;
|
|
1676
1681
|
let files;
|
|
1677
1682
|
if (opts.files && opts.files.length > 0) {
|
|
1678
|
-
files = opts.files.map((f) =>
|
|
1683
|
+
files = opts.files.map((f) => path4.resolve(projectRoot, f));
|
|
1679
1684
|
} else {
|
|
1680
1685
|
files = await findSourceFiles(projectRoot, ignore);
|
|
1681
1686
|
}
|