ghostimport 0.1.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.
- package/README.md +240 -0
- package/dist/cache.d.ts +4 -0
- package/dist/cli.d.ts +1 -0
- package/dist/cli.js +587 -0
- package/dist/config.d.ts +3 -0
- package/dist/files.d.ts +3 -0
- package/dist/imports.d.ts +1 -0
- package/dist/index.cjs +476 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.js +431 -0
- package/dist/npm.d.ts +3 -0
- package/dist/scan.d.ts +2 -0
- package/dist/types.d.ts +70 -0
- package/package.json +61 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1,431 @@
|
|
|
1
|
+
// src/imports.ts
|
|
2
|
+
var IMPORT_PATTERNS = [
|
|
3
|
+
/import\s+(?:[\w*{}\s,]+\s+from\s+)?['"]([^'".\n][^'"]*)['"]/g,
|
|
4
|
+
/require\s*\(\s*['"]([^'".\n][^'"]*)['"]\s*\)/g,
|
|
5
|
+
/import\s*\(\s*['"]([^'".\n][^'"]*)['"]\s*\)/g,
|
|
6
|
+
/export\s+(?:[\w*{}\s,]+\s+from\s+)?['"]([^'".\n][^'"]*)['"]/g
|
|
7
|
+
];
|
|
8
|
+
var BUILTIN_MODULES = /* @__PURE__ */ new Set([
|
|
9
|
+
"assert",
|
|
10
|
+
"assert/strict",
|
|
11
|
+
"async_hooks",
|
|
12
|
+
"buffer",
|
|
13
|
+
"child_process",
|
|
14
|
+
"cluster",
|
|
15
|
+
"console",
|
|
16
|
+
"constants",
|
|
17
|
+
"crypto",
|
|
18
|
+
"dgram",
|
|
19
|
+
"diagnostics_channel",
|
|
20
|
+
"dns",
|
|
21
|
+
"dns/promises",
|
|
22
|
+
"domain",
|
|
23
|
+
"events",
|
|
24
|
+
"fs",
|
|
25
|
+
"fs/promises",
|
|
26
|
+
"http",
|
|
27
|
+
"http2",
|
|
28
|
+
"https",
|
|
29
|
+
"inspector",
|
|
30
|
+
"inspector/promises",
|
|
31
|
+
"module",
|
|
32
|
+
"net",
|
|
33
|
+
"os",
|
|
34
|
+
"path",
|
|
35
|
+
"path/posix",
|
|
36
|
+
"path/win32",
|
|
37
|
+
"perf_hooks",
|
|
38
|
+
"process",
|
|
39
|
+
"punycode",
|
|
40
|
+
"querystring",
|
|
41
|
+
"readline",
|
|
42
|
+
"readline/promises",
|
|
43
|
+
"repl",
|
|
44
|
+
"sea",
|
|
45
|
+
"stream",
|
|
46
|
+
"stream/consumers",
|
|
47
|
+
"stream/promises",
|
|
48
|
+
"stream/web",
|
|
49
|
+
"string_decoder",
|
|
50
|
+
"sys",
|
|
51
|
+
"test",
|
|
52
|
+
"timers",
|
|
53
|
+
"timers/promises",
|
|
54
|
+
"tls",
|
|
55
|
+
"trace_events",
|
|
56
|
+
"tty",
|
|
57
|
+
"url",
|
|
58
|
+
"util",
|
|
59
|
+
"util/types",
|
|
60
|
+
"v8",
|
|
61
|
+
"vm",
|
|
62
|
+
"wasi",
|
|
63
|
+
"worker_threads",
|
|
64
|
+
"zlib"
|
|
65
|
+
]);
|
|
66
|
+
function isBuiltin(name) {
|
|
67
|
+
if (name.startsWith("node:")) return true;
|
|
68
|
+
return BUILTIN_MODULES.has(name);
|
|
69
|
+
}
|
|
70
|
+
function toPackageName(importPath) {
|
|
71
|
+
if (importPath.startsWith("@")) {
|
|
72
|
+
const parts = importPath.split("/");
|
|
73
|
+
if (parts.length < 2) return null;
|
|
74
|
+
return `${parts[0]}/${parts[1]}`;
|
|
75
|
+
}
|
|
76
|
+
return importPath.split("/")[0];
|
|
77
|
+
}
|
|
78
|
+
function extractImports(code) {
|
|
79
|
+
const found = /* @__PURE__ */ new Set();
|
|
80
|
+
for (const pattern of IMPORT_PATTERNS) {
|
|
81
|
+
pattern.lastIndex = 0;
|
|
82
|
+
let match;
|
|
83
|
+
while ((match = pattern.exec(code)) !== null) {
|
|
84
|
+
const raw = match[1];
|
|
85
|
+
const pkg = toPackageName(raw);
|
|
86
|
+
if (pkg && !isBuiltin(raw) && !isBuiltin(pkg)) {
|
|
87
|
+
found.add(pkg);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
return [...found];
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
// src/cache.ts
|
|
95
|
+
import fs from "fs";
|
|
96
|
+
import path from "path";
|
|
97
|
+
import os from "os";
|
|
98
|
+
var CACHE_TTL = 24 * 60 * 60 * 1e3;
|
|
99
|
+
function getCacheDir() {
|
|
100
|
+
const dir = path.join(os.homedir(), ".ghostimport");
|
|
101
|
+
if (!fs.existsSync(dir)) fs.mkdirSync(dir, { recursive: true });
|
|
102
|
+
return dir;
|
|
103
|
+
}
|
|
104
|
+
function getCachePath() {
|
|
105
|
+
return path.join(getCacheDir(), "registry-cache.json");
|
|
106
|
+
}
|
|
107
|
+
function loadCache() {
|
|
108
|
+
const cachePath = getCachePath();
|
|
109
|
+
if (!fs.existsSync(cachePath)) return {};
|
|
110
|
+
try {
|
|
111
|
+
return JSON.parse(fs.readFileSync(cachePath, "utf8"));
|
|
112
|
+
} catch {
|
|
113
|
+
return {};
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
function saveCache(cache) {
|
|
117
|
+
fs.writeFileSync(getCachePath(), JSON.stringify(cache, null, 2), "utf8");
|
|
118
|
+
}
|
|
119
|
+
function getCached(cache, pkgName) {
|
|
120
|
+
const entry = cache[pkgName];
|
|
121
|
+
if (!entry) return null;
|
|
122
|
+
if (Date.now() - entry.ts > CACHE_TTL) return null;
|
|
123
|
+
return entry;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
// src/config.ts
|
|
127
|
+
import fs2 from "fs";
|
|
128
|
+
import path2 from "path";
|
|
129
|
+
var defaults = { ignore: [], includeUndeclared: true };
|
|
130
|
+
function loadConfig(dir) {
|
|
131
|
+
const configPath = path2.join(dir, ".ghostimportrc.json");
|
|
132
|
+
if (!fs2.existsSync(configPath)) return { ...defaults };
|
|
133
|
+
try {
|
|
134
|
+
const raw = JSON.parse(fs2.readFileSync(configPath, "utf8"));
|
|
135
|
+
return { ...defaults, ...raw };
|
|
136
|
+
} catch {
|
|
137
|
+
return { ...defaults };
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
function matchesIgnore(pkg, patterns) {
|
|
141
|
+
for (const pattern of patterns) {
|
|
142
|
+
if (pattern === pkg) return true;
|
|
143
|
+
if (pattern.endsWith("/*")) {
|
|
144
|
+
const prefix = pattern.slice(0, -1);
|
|
145
|
+
if (pkg.startsWith(prefix)) return true;
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
return false;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
// src/npm.ts
|
|
152
|
+
import https from "https";
|
|
153
|
+
function httpGetJson(url) {
|
|
154
|
+
return new Promise((resolve, reject) => {
|
|
155
|
+
const req = https.get(url, { headers: { Accept: "application/json" }, timeout: 8e3 }, (res) => {
|
|
156
|
+
let data = "";
|
|
157
|
+
res.on("data", (chunk) => {
|
|
158
|
+
data += chunk;
|
|
159
|
+
});
|
|
160
|
+
res.on("end", () => {
|
|
161
|
+
if (res.statusCode === 200) {
|
|
162
|
+
try {
|
|
163
|
+
resolve(JSON.parse(data));
|
|
164
|
+
} catch {
|
|
165
|
+
reject(new Error("Invalid JSON"));
|
|
166
|
+
}
|
|
167
|
+
} else if (res.statusCode === 404) {
|
|
168
|
+
resolve(null);
|
|
169
|
+
} else {
|
|
170
|
+
reject(new Error(`HTTP ${res.statusCode}`));
|
|
171
|
+
}
|
|
172
|
+
});
|
|
173
|
+
});
|
|
174
|
+
req.on("timeout", () => {
|
|
175
|
+
req.destroy();
|
|
176
|
+
reject(new Error("timeout"));
|
|
177
|
+
});
|
|
178
|
+
req.on("error", reject);
|
|
179
|
+
});
|
|
180
|
+
}
|
|
181
|
+
function encodePackageName(pkgName) {
|
|
182
|
+
return pkgName.startsWith("@") ? "@" + encodeURIComponent(pkgName.slice(1)) : encodeURIComponent(pkgName);
|
|
183
|
+
}
|
|
184
|
+
function checkNpm(pkgName) {
|
|
185
|
+
return new Promise((resolve) => {
|
|
186
|
+
const options = {
|
|
187
|
+
hostname: "registry.npmjs.org",
|
|
188
|
+
path: `/${encodePackageName(pkgName)}`,
|
|
189
|
+
method: "GET",
|
|
190
|
+
headers: { Accept: "application/json" },
|
|
191
|
+
timeout: 8e3
|
|
192
|
+
};
|
|
193
|
+
const req = https.request(options, (res) => {
|
|
194
|
+
res.resume();
|
|
195
|
+
if (res.statusCode === 200) {
|
|
196
|
+
resolve({ exists: true });
|
|
197
|
+
} else if (res.statusCode === 404) {
|
|
198
|
+
resolve({ exists: false });
|
|
199
|
+
} else {
|
|
200
|
+
resolve({ exists: null, error: `HTTP ${res.statusCode}` });
|
|
201
|
+
}
|
|
202
|
+
});
|
|
203
|
+
req.on("timeout", () => {
|
|
204
|
+
req.destroy();
|
|
205
|
+
resolve({ exists: null, error: "timeout" });
|
|
206
|
+
});
|
|
207
|
+
req.on("error", (err) => {
|
|
208
|
+
resolve({ exists: null, error: err.message });
|
|
209
|
+
});
|
|
210
|
+
req.end();
|
|
211
|
+
});
|
|
212
|
+
}
|
|
213
|
+
async function checkScary(pkgName) {
|
|
214
|
+
const encoded = encodePackageName(pkgName);
|
|
215
|
+
try {
|
|
216
|
+
const meta = await httpGetJson(`https://registry.npmjs.org/${encoded}`);
|
|
217
|
+
if (!meta) return { exists: false, squatRisk: "available" };
|
|
218
|
+
const created = meta.time?.created ? new Date(meta.time.created) : null;
|
|
219
|
+
const ageMs = created ? Date.now() - created.getTime() : Infinity;
|
|
220
|
+
const ageDays = Math.floor(ageMs / (1e3 * 60 * 60 * 24));
|
|
221
|
+
let downloads = null;
|
|
222
|
+
try {
|
|
223
|
+
const dl = await httpGetJson(`https://api.npmjs.org/downloads/point/last-week/${encoded}`);
|
|
224
|
+
downloads = dl?.downloads ?? null;
|
|
225
|
+
} catch {
|
|
226
|
+
}
|
|
227
|
+
const flags = [];
|
|
228
|
+
if (ageDays < 30) flags.push(`created ${ageDays} days ago`);
|
|
229
|
+
if (downloads !== null && downloads < 50) flags.push(`${downloads} weekly downloads`);
|
|
230
|
+
if (meta.versions && Object.keys(meta.versions).length <= 1) flags.push("single version published");
|
|
231
|
+
const risk = flags.length >= 2 ? "high" : flags.length === 1 ? "medium" : "low";
|
|
232
|
+
return {
|
|
233
|
+
exists: true,
|
|
234
|
+
created: created?.toISOString().slice(0, 10) ?? "unknown",
|
|
235
|
+
downloads,
|
|
236
|
+
versions: meta.versions ? Object.keys(meta.versions).length : 0,
|
|
237
|
+
risk,
|
|
238
|
+
flags
|
|
239
|
+
};
|
|
240
|
+
} catch (err) {
|
|
241
|
+
return { exists: null, error: err.message };
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
// src/files.ts
|
|
246
|
+
import fs3 from "fs";
|
|
247
|
+
import path3 from "path";
|
|
248
|
+
var SKIP_DIRS = /* @__PURE__ */ new Set(["node_modules", ".git", "dist", "build", ".next", "coverage", ".cache"]);
|
|
249
|
+
var CODE_EXTS = /* @__PURE__ */ new Set([".js", ".jsx", ".ts", ".tsx", ".mjs", ".cjs"]);
|
|
250
|
+
function walkFiles(dir) {
|
|
251
|
+
const results = [];
|
|
252
|
+
function walk(current) {
|
|
253
|
+
let entries;
|
|
254
|
+
try {
|
|
255
|
+
entries = fs3.readdirSync(current, { withFileTypes: true });
|
|
256
|
+
} catch {
|
|
257
|
+
return;
|
|
258
|
+
}
|
|
259
|
+
for (const entry of entries) {
|
|
260
|
+
if (entry.isDirectory()) {
|
|
261
|
+
if (!SKIP_DIRS.has(entry.name)) walk(path3.join(current, entry.name));
|
|
262
|
+
} else if (entry.isFile()) {
|
|
263
|
+
if (CODE_EXTS.has(path3.extname(entry.name))) results.push(path3.join(current, entry.name));
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
walk(dir);
|
|
268
|
+
return results;
|
|
269
|
+
}
|
|
270
|
+
function readPackageJsonDeps(dir) {
|
|
271
|
+
const pkgPath = path3.join(dir, "package.json");
|
|
272
|
+
if (!fs3.existsSync(pkgPath)) return /* @__PURE__ */ new Set();
|
|
273
|
+
try {
|
|
274
|
+
const pkg = JSON.parse(fs3.readFileSync(pkgPath, "utf8"));
|
|
275
|
+
return /* @__PURE__ */ new Set([
|
|
276
|
+
...Object.keys(pkg.dependencies ?? {}),
|
|
277
|
+
...Object.keys(pkg.devDependencies ?? {}),
|
|
278
|
+
...Object.keys(pkg.peerDependencies ?? {}),
|
|
279
|
+
...Object.keys(pkg.optionalDependencies ?? {})
|
|
280
|
+
]);
|
|
281
|
+
} catch {
|
|
282
|
+
return /* @__PURE__ */ new Set();
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
function readWorkspacePackages(dir) {
|
|
286
|
+
const names = /* @__PURE__ */ new Set();
|
|
287
|
+
try {
|
|
288
|
+
const pkg = JSON.parse(fs3.readFileSync(path3.join(dir, "package.json"), "utf8"));
|
|
289
|
+
const workspaces = Array.isArray(pkg.workspaces) ? pkg.workspaces : pkg.workspaces?.packages ?? [];
|
|
290
|
+
for (const pattern of workspaces) {
|
|
291
|
+
const base = pattern.replace(/\/?\*$/, "");
|
|
292
|
+
const wsDir = path3.join(dir, base);
|
|
293
|
+
if (!fs3.existsSync(wsDir)) continue;
|
|
294
|
+
for (const entry of fs3.readdirSync(wsDir, { withFileTypes: true })) {
|
|
295
|
+
if (!entry.isDirectory()) continue;
|
|
296
|
+
const wsPkgPath = path3.join(wsDir, entry.name, "package.json");
|
|
297
|
+
if (!fs3.existsSync(wsPkgPath)) continue;
|
|
298
|
+
try {
|
|
299
|
+
const wsPkg = JSON.parse(fs3.readFileSync(wsPkgPath, "utf8"));
|
|
300
|
+
if (wsPkg.name) names.add(wsPkg.name);
|
|
301
|
+
} catch {
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
} catch {
|
|
306
|
+
}
|
|
307
|
+
const pnpmPath = path3.join(dir, "pnpm-workspace.yaml");
|
|
308
|
+
if (!fs3.existsSync(pnpmPath)) return names;
|
|
309
|
+
try {
|
|
310
|
+
const content = fs3.readFileSync(pnpmPath, "utf8");
|
|
311
|
+
for (const m of content.matchAll(/- ['"]?([^'"\n]+)['"]?/g)) {
|
|
312
|
+
const base = m[1].replace(/\/?\*$/, "");
|
|
313
|
+
const wsDir = path3.join(dir, base);
|
|
314
|
+
if (!fs3.existsSync(wsDir)) continue;
|
|
315
|
+
for (const entry of fs3.readdirSync(wsDir, { withFileTypes: true })) {
|
|
316
|
+
if (!entry.isDirectory()) continue;
|
|
317
|
+
const wsPkgPath = path3.join(wsDir, entry.name, "package.json");
|
|
318
|
+
if (!fs3.existsSync(wsPkgPath)) continue;
|
|
319
|
+
try {
|
|
320
|
+
const wsPkg = JSON.parse(fs3.readFileSync(wsPkgPath, "utf8"));
|
|
321
|
+
if (wsPkg.name) names.add(wsPkg.name);
|
|
322
|
+
} catch {
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
} catch {
|
|
327
|
+
}
|
|
328
|
+
return names;
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
// src/scan.ts
|
|
332
|
+
import fs4 from "fs";
|
|
333
|
+
import path4 from "path";
|
|
334
|
+
var CONCURRENCY = 10;
|
|
335
|
+
async function scan(targetDir, { onProgress, useCache = true, scary = false, config } = {}) {
|
|
336
|
+
const conf = config ?? loadConfig(targetDir);
|
|
337
|
+
const files = walkFiles(targetDir);
|
|
338
|
+
const declaredDeps = readPackageJsonDeps(targetDir);
|
|
339
|
+
const workspacePkgs = readWorkspacePackages(targetDir);
|
|
340
|
+
const cache = useCache ? loadCache() : {};
|
|
341
|
+
let cacheHits = 0;
|
|
342
|
+
const importMap = /* @__PURE__ */ new Map();
|
|
343
|
+
for (const file of files) {
|
|
344
|
+
let code;
|
|
345
|
+
try {
|
|
346
|
+
code = fs4.readFileSync(file, "utf8");
|
|
347
|
+
} catch {
|
|
348
|
+
continue;
|
|
349
|
+
}
|
|
350
|
+
for (const pkg of extractImports(code)) {
|
|
351
|
+
if (!importMap.has(pkg)) importMap.set(pkg, []);
|
|
352
|
+
importMap.get(pkg).push(path4.relative(targetDir, file));
|
|
353
|
+
}
|
|
354
|
+
}
|
|
355
|
+
const allPkgs = [...importMap.keys()].filter(
|
|
356
|
+
(pkg) => !matchesIgnore(pkg, conf.ignore) && !workspacePkgs.has(pkg)
|
|
357
|
+
);
|
|
358
|
+
const results = {
|
|
359
|
+
scanned: files.length,
|
|
360
|
+
packages: allPkgs.length,
|
|
361
|
+
hallucinated: [],
|
|
362
|
+
notInPackageJson: [],
|
|
363
|
+
errors: [],
|
|
364
|
+
scary: [],
|
|
365
|
+
cacheHits: 0
|
|
366
|
+
};
|
|
367
|
+
for (let i = 0; i < allPkgs.length; i += CONCURRENCY) {
|
|
368
|
+
const batch = allPkgs.slice(i, i + CONCURRENCY);
|
|
369
|
+
const checks = await Promise.all(
|
|
370
|
+
batch.map((pkg) => {
|
|
371
|
+
const cached = getCached(cache, pkg);
|
|
372
|
+
if (cached) {
|
|
373
|
+
cacheHits++;
|
|
374
|
+
return Promise.resolve({ exists: cached.exists });
|
|
375
|
+
}
|
|
376
|
+
return checkNpm(pkg);
|
|
377
|
+
})
|
|
378
|
+
);
|
|
379
|
+
for (let j = 0; j < batch.length; j++) {
|
|
380
|
+
const pkg = batch[j];
|
|
381
|
+
const { exists, error } = checks[j];
|
|
382
|
+
const matchedFiles = importMap.get(pkg);
|
|
383
|
+
if (exists !== null && useCache) {
|
|
384
|
+
cache[pkg] = { exists, ts: Date.now() };
|
|
385
|
+
}
|
|
386
|
+
onProgress?.({ pkg, exists, error, total: allPkgs.length, done: i + j + 1 });
|
|
387
|
+
if (exists === false) {
|
|
388
|
+
results.hallucinated.push({ pkg, files: matchedFiles });
|
|
389
|
+
} else if (exists === null && error) {
|
|
390
|
+
results.errors.push({ pkg, error, files: matchedFiles });
|
|
391
|
+
} else if (exists === true && !declaredDeps.has(pkg)) {
|
|
392
|
+
results.notInPackageJson.push({ pkg, files: matchedFiles });
|
|
393
|
+
}
|
|
394
|
+
}
|
|
395
|
+
}
|
|
396
|
+
if (useCache) saveCache(cache);
|
|
397
|
+
results.cacheHits = cacheHits;
|
|
398
|
+
if (scary) {
|
|
399
|
+
for (const { pkg, files: matchedFiles } of results.hallucinated) {
|
|
400
|
+
results.scary.push({ pkg, files: matchedFiles, type: "available" });
|
|
401
|
+
}
|
|
402
|
+
for (const { pkg, files: matchedFiles } of results.notInPackageJson) {
|
|
403
|
+
const info = await checkScary(pkg);
|
|
404
|
+
if (info.exists === true && info.risk !== "low") {
|
|
405
|
+
results.scary.push({
|
|
406
|
+
pkg,
|
|
407
|
+
files: matchedFiles,
|
|
408
|
+
type: "suspicious",
|
|
409
|
+
exists: true,
|
|
410
|
+
created: info.created,
|
|
411
|
+
downloads: info.downloads,
|
|
412
|
+
versions: info.versions,
|
|
413
|
+
risk: info.risk,
|
|
414
|
+
flags: info.flags
|
|
415
|
+
});
|
|
416
|
+
}
|
|
417
|
+
}
|
|
418
|
+
}
|
|
419
|
+
return results;
|
|
420
|
+
}
|
|
421
|
+
export {
|
|
422
|
+
checkNpm,
|
|
423
|
+
checkScary,
|
|
424
|
+
extractImports,
|
|
425
|
+
loadCache,
|
|
426
|
+
loadConfig,
|
|
427
|
+
readPackageJsonDeps,
|
|
428
|
+
saveCache,
|
|
429
|
+
scan,
|
|
430
|
+
walkFiles
|
|
431
|
+
};
|
package/dist/npm.d.ts
ADDED
package/dist/scan.d.ts
ADDED
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
export interface Config {
|
|
2
|
+
ignore: string[];
|
|
3
|
+
includeUndeclared: boolean;
|
|
4
|
+
}
|
|
5
|
+
export interface ScanOptions {
|
|
6
|
+
onProgress?: (progress: ScanProgress) => void;
|
|
7
|
+
useCache?: boolean;
|
|
8
|
+
scary?: boolean;
|
|
9
|
+
config?: Config;
|
|
10
|
+
}
|
|
11
|
+
export interface ScanProgress {
|
|
12
|
+
pkg: string;
|
|
13
|
+
exists: boolean | null;
|
|
14
|
+
error?: string;
|
|
15
|
+
total: number;
|
|
16
|
+
done: number;
|
|
17
|
+
}
|
|
18
|
+
export interface PackageRef {
|
|
19
|
+
pkg: string;
|
|
20
|
+
files: string[];
|
|
21
|
+
}
|
|
22
|
+
export interface PackageError extends PackageRef {
|
|
23
|
+
error: string;
|
|
24
|
+
}
|
|
25
|
+
export type ScaryEntry = {
|
|
26
|
+
pkg: string;
|
|
27
|
+
files: string[];
|
|
28
|
+
type: 'available';
|
|
29
|
+
} | {
|
|
30
|
+
pkg: string;
|
|
31
|
+
files: string[];
|
|
32
|
+
type: 'suspicious';
|
|
33
|
+
exists: true;
|
|
34
|
+
created: string;
|
|
35
|
+
downloads: number | null;
|
|
36
|
+
versions: number;
|
|
37
|
+
risk: 'medium' | 'high';
|
|
38
|
+
flags: string[];
|
|
39
|
+
};
|
|
40
|
+
export interface ScanResult {
|
|
41
|
+
scanned: number;
|
|
42
|
+
packages: number;
|
|
43
|
+
hallucinated: PackageRef[];
|
|
44
|
+
notInPackageJson: PackageRef[];
|
|
45
|
+
errors: PackageError[];
|
|
46
|
+
scary: ScaryEntry[];
|
|
47
|
+
cacheHits: number;
|
|
48
|
+
}
|
|
49
|
+
export interface NpmCheckResult {
|
|
50
|
+
exists: boolean | null;
|
|
51
|
+
error?: string;
|
|
52
|
+
}
|
|
53
|
+
export type ScaryCheckResult = {
|
|
54
|
+
exists: true;
|
|
55
|
+
created: string;
|
|
56
|
+
downloads: number | null;
|
|
57
|
+
versions: number;
|
|
58
|
+
risk: 'low' | 'medium' | 'high';
|
|
59
|
+
flags: string[];
|
|
60
|
+
} | {
|
|
61
|
+
exists: false;
|
|
62
|
+
squatRisk: 'available';
|
|
63
|
+
} | {
|
|
64
|
+
exists: null;
|
|
65
|
+
error: string;
|
|
66
|
+
};
|
|
67
|
+
export interface CacheEntry {
|
|
68
|
+
exists: boolean;
|
|
69
|
+
ts: number;
|
|
70
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "ghostimport",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Detects ghost imports in your code - imports that don't exist, hallucinated by AI coding tools.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"npm",
|
|
7
|
+
"ai",
|
|
8
|
+
"hallucination",
|
|
9
|
+
"vibe-coding",
|
|
10
|
+
"cursor",
|
|
11
|
+
"claude",
|
|
12
|
+
"imports",
|
|
13
|
+
"security",
|
|
14
|
+
"lint",
|
|
15
|
+
"ghost"
|
|
16
|
+
],
|
|
17
|
+
"homepage": "https://github.com/FGuerreir0/ghostimport#readme",
|
|
18
|
+
"bugs": {
|
|
19
|
+
"url": "https://github.com/FGuerreir0/ghostimport/issues"
|
|
20
|
+
},
|
|
21
|
+
"repository": {
|
|
22
|
+
"type": "git",
|
|
23
|
+
"url": "git+https://github.com/FGuerreir0/ghostimport.git"
|
|
24
|
+
},
|
|
25
|
+
"license": "MIT",
|
|
26
|
+
"author": "Fábio Guerreiro",
|
|
27
|
+
"type": "module",
|
|
28
|
+
"main": "./dist/index.js",
|
|
29
|
+
"types": "./dist/index.d.ts",
|
|
30
|
+
"sideEffects": false,
|
|
31
|
+
"exports": {
|
|
32
|
+
".": {
|
|
33
|
+
"types": "./dist/index.d.ts",
|
|
34
|
+
"import": "./dist/index.js",
|
|
35
|
+
"require": "./dist/index.cjs"
|
|
36
|
+
}
|
|
37
|
+
},
|
|
38
|
+
"bin": {
|
|
39
|
+
"ghostimport": "dist/cli.js"
|
|
40
|
+
},
|
|
41
|
+
"files": [
|
|
42
|
+
"dist"
|
|
43
|
+
],
|
|
44
|
+
"engines": {
|
|
45
|
+
"node": ">=22"
|
|
46
|
+
},
|
|
47
|
+
"scripts": {
|
|
48
|
+
"build": "node build.js",
|
|
49
|
+
"typecheck": "tsc",
|
|
50
|
+
"clean": "node -e \"require('fs').rmSync('dist', { recursive: true, force: true })\"",
|
|
51
|
+
"test": "tsx tests/test.ts",
|
|
52
|
+
"dev": "tsx src/cli.ts",
|
|
53
|
+
"prepublishOnly": "npm run build"
|
|
54
|
+
},
|
|
55
|
+
"devDependencies": {
|
|
56
|
+
"@types/node": "^20.19.39",
|
|
57
|
+
"esbuild": "^0.25.0",
|
|
58
|
+
"tsx": "^4.21.0",
|
|
59
|
+
"typescript": "^5.9.3"
|
|
60
|
+
}
|
|
61
|
+
}
|