reqscan 1.0.0 → 1.0.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/package.json +8 -4
- package/src/commands.js +6 -6
- package/src/index.js +1 -1
- package/test/test.js +0 -152
package/package.json
CHANGED
|
@@ -1,15 +1,19 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "reqscan",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.2",
|
|
4
4
|
"description": "Dependency Manager for Node.js — scan, install, clean, and audit your project dependencies",
|
|
5
5
|
"main": "src/scanner.js",
|
|
6
6
|
"bin": {
|
|
7
|
-
"
|
|
7
|
+
"reqscan": "./src/index.js"
|
|
8
8
|
},
|
|
9
9
|
"scripts": {
|
|
10
10
|
"start": "node src/index.js",
|
|
11
11
|
"test": "node test/test.js"
|
|
12
12
|
},
|
|
13
|
+
"files": [
|
|
14
|
+
"src",
|
|
15
|
+
"README.md"
|
|
16
|
+
],
|
|
13
17
|
"keywords": [
|
|
14
18
|
"npm",
|
|
15
19
|
"dependencies",
|
|
@@ -18,11 +22,11 @@
|
|
|
18
22
|
"audit",
|
|
19
23
|
"scanner",
|
|
20
24
|
"cli",
|
|
21
|
-
"
|
|
25
|
+
"reqscan"
|
|
22
26
|
],
|
|
23
27
|
"author": "",
|
|
24
28
|
"license": "MIT",
|
|
25
29
|
"engines": {
|
|
26
30
|
"node": ">=14.0.0"
|
|
27
31
|
}
|
|
28
|
-
}
|
|
32
|
+
}
|
package/src/commands.js
CHANGED
|
@@ -83,7 +83,7 @@ async function cmdCheck(targetDir) {
|
|
|
83
83
|
console.log(col.dim(col.LINE));
|
|
84
84
|
r.unused.forEach(p => console.log(` ${col.yellow('~')} ${p}`));
|
|
85
85
|
console.log();
|
|
86
|
-
console.log(col.dim('Tip: Run `
|
|
86
|
+
console.log(col.dim('Tip: Run `reqscan clean` to remove unused packages.'));
|
|
87
87
|
console.log();
|
|
88
88
|
}
|
|
89
89
|
|
|
@@ -122,7 +122,7 @@ async function cmdInstall(targetDir) {
|
|
|
122
122
|
console.log(col.boldGreen('✔ Successfully installed:'));
|
|
123
123
|
r.missing.forEach(p => console.log(` • ${col.green(p)}`));
|
|
124
124
|
console.log();
|
|
125
|
-
console.log(col.dim('💡 Run `
|
|
125
|
+
console.log(col.dim('💡 Run `reqscan check` again to verify all packages are declared.'));
|
|
126
126
|
} else {
|
|
127
127
|
console.log(col.boldRed('❌ Installation failed. Please check your npm setup and try again.'));
|
|
128
128
|
}
|
|
@@ -190,7 +190,7 @@ async function cmdClean(targetDir, { force = false } = {}) {
|
|
|
190
190
|
|
|
191
191
|
async function cmdFix(targetDir) {
|
|
192
192
|
console.log();
|
|
193
|
-
console.log(col.boldCyan('🔧 Running
|
|
193
|
+
console.log(col.boldCyan('🔧 Running reqscan fix (install missing + clean unused)...'));
|
|
194
194
|
console.log(col.dim(col.LINE));
|
|
195
195
|
await cmdInstall(targetDir);
|
|
196
196
|
console.log(col.dim(col.LINE));
|
|
@@ -235,8 +235,8 @@ async function cmdAudit(targetDir) {
|
|
|
235
235
|
|
|
236
236
|
// Recommendations
|
|
237
237
|
const recs = [];
|
|
238
|
-
if (r.missing.length > 0) recs.push(`Run ${col.cyan('
|
|
239
|
-
if (r.unused.length > 0) recs.push(`Run ${col.cyan('
|
|
238
|
+
if (r.missing.length > 0) recs.push(`Run ${col.cyan('reqscan install')} to install ${r.missing.length} missing package(s).`);
|
|
239
|
+
if (r.unused.length > 0) recs.push(`Run ${col.cyan('reqscan clean')} to remove ${r.unused.length} unused package(s).`);
|
|
240
240
|
if (recs.length === 0) recs.push(col.green('Your project dependencies look great!'));
|
|
241
241
|
|
|
242
242
|
console.log(col.bold('💡 Recommendations'));
|
|
@@ -287,4 +287,4 @@ async function cmdList(targetDir) {
|
|
|
287
287
|
console.log();
|
|
288
288
|
}
|
|
289
289
|
|
|
290
|
-
module.exports = { cmdCheck, cmdInstall, cmdClean, cmdFix, cmdAudit, cmdList };
|
|
290
|
+
module.exports = { cmdCheck, cmdInstall, cmdClean, cmdFix, cmdAudit, cmdList };
|
package/src/index.js
CHANGED
package/test/test.js
DELETED
|
@@ -1,152 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const fs = require('fs');
|
|
4
|
-
const path = require('path');
|
|
5
|
-
const os = require('os');
|
|
6
|
-
const { scanProject } = require('../src/scanner');
|
|
7
|
-
const { cmdCheck, cmdAudit, cmdList } = require('../src/commands');
|
|
8
|
-
|
|
9
|
-
// ─── Test helpers ─────────────────────────────────────────────────────────────
|
|
10
|
-
let passed = 0;
|
|
11
|
-
let failed = 0;
|
|
12
|
-
|
|
13
|
-
function assert(condition, label) {
|
|
14
|
-
if (condition) {
|
|
15
|
-
console.log(` \x1b[32m✓\x1b[0m ${label}`);
|
|
16
|
-
passed++;
|
|
17
|
-
} else {
|
|
18
|
-
console.error(` \x1b[31m✗\x1b[0m ${label}`);
|
|
19
|
-
failed++;
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
function section(title) {
|
|
24
|
-
console.log(`\n\x1b[1m\x1b[36m${title}\x1b[0m`);
|
|
25
|
-
console.log('─'.repeat(40));
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
// ─── Build mock project ───────────────────────────────────────────────────────
|
|
29
|
-
function buildMockProject() {
|
|
30
|
-
const tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'depm-test-'));
|
|
31
|
-
|
|
32
|
-
// package.json — express declared, jest declared (but never imported)
|
|
33
|
-
fs.writeFileSync(path.join(tmpDir, 'package.json'), JSON.stringify({
|
|
34
|
-
name: 'mock-project',
|
|
35
|
-
version: '1.0.0',
|
|
36
|
-
dependencies: {
|
|
37
|
-
express: '^4.18.0',
|
|
38
|
-
mongoose: '^7.0.0',
|
|
39
|
-
},
|
|
40
|
-
devDependencies: {
|
|
41
|
-
jest: '^29.0.0',
|
|
42
|
-
},
|
|
43
|
-
}, null, 2));
|
|
44
|
-
|
|
45
|
-
// index.js — requires express (declared), axios (missing), uuid (missing)
|
|
46
|
-
fs.writeFileSync(path.join(tmpDir, 'index.js'), `
|
|
47
|
-
const express = require('express');
|
|
48
|
-
const axios = require('axios');
|
|
49
|
-
const path = require('path'); // built-in
|
|
50
|
-
const fs = require('fs'); // built-in
|
|
51
|
-
import something from 'lodash';
|
|
52
|
-
`);
|
|
53
|
-
|
|
54
|
-
// utils/db.js — subdir, scoped pkg, subpath import
|
|
55
|
-
fs.mkdirSync(path.join(tmpDir, 'utils'));
|
|
56
|
-
fs.writeFileSync(path.join(tmpDir, 'utils', 'db.js'), `
|
|
57
|
-
const mongoose = require('mongoose'); // declared
|
|
58
|
-
const { v4 } = require('uuid'); // missing
|
|
59
|
-
import { format } from 'date-fns'; // missing
|
|
60
|
-
import core from '@babel/core'; // missing scoped
|
|
61
|
-
`);
|
|
62
|
-
|
|
63
|
-
// lib/helpers.ts — TypeScript file
|
|
64
|
-
fs.mkdirSync(path.join(tmpDir, 'lib'));
|
|
65
|
-
fs.writeFileSync(path.join(tmpDir, 'lib', 'helpers.ts'), `
|
|
66
|
-
import { useState } from 'react'; // missing
|
|
67
|
-
export { something } from 'lodash'; // missing (already found, de-duped)
|
|
68
|
-
`);
|
|
69
|
-
|
|
70
|
-
// node_modules — should be skipped entirely
|
|
71
|
-
fs.mkdirSync(path.join(tmpDir, 'node_modules', 'express'), { recursive: true });
|
|
72
|
-
fs.writeFileSync(path.join(tmpDir, 'node_modules', 'express', 'index.js'), `
|
|
73
|
-
require('some-internal-dep'); // should NOT be counted
|
|
74
|
-
`);
|
|
75
|
-
|
|
76
|
-
return tmpDir;
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
// ─── Run tests ────────────────────────────────────────────────────────────────
|
|
80
|
-
async function run() {
|
|
81
|
-
console.log('\n\x1b[1mdepm — Test Suite\x1b[0m');
|
|
82
|
-
|
|
83
|
-
const tmpDir = buildMockProject();
|
|
84
|
-
|
|
85
|
-
// ── Scanner tests ────────────────────────────────────────────────────────
|
|
86
|
-
section('Scanner: extracting imports');
|
|
87
|
-
const r = await scanProject(tmpDir);
|
|
88
|
-
|
|
89
|
-
assert(r.projectName === 'mock-project', 'project name read from package.json');
|
|
90
|
-
assert(r.scannedFiles.length >= 3, 'scanned js/ts files (not node_modules)');
|
|
91
|
-
assert(!r.allImports.includes('path'), 'built-in "path" excluded');
|
|
92
|
-
assert(!r.allImports.includes('fs'), 'built-in "fs" excluded');
|
|
93
|
-
assert(!r.allImports.includes('some-internal-dep'), 'node_modules skipped');
|
|
94
|
-
|
|
95
|
-
section('Scanner: detected packages');
|
|
96
|
-
assert(r.allImports.includes('express'), 'express detected');
|
|
97
|
-
assert(r.allImports.includes('axios'), 'axios detected');
|
|
98
|
-
assert(r.allImports.includes('lodash'), 'lodash detected (import default)');
|
|
99
|
-
assert(r.allImports.includes('mongoose'), 'mongoose detected');
|
|
100
|
-
assert(r.allImports.includes('uuid'), 'uuid detected');
|
|
101
|
-
assert(r.allImports.includes('date-fns'), 'date-fns detected');
|
|
102
|
-
assert(r.allImports.includes('@babel/core'),'scoped @babel/core detected');
|
|
103
|
-
assert(r.allImports.includes('react'), 'react detected from .ts file');
|
|
104
|
-
|
|
105
|
-
section('Scanner: missing vs present');
|
|
106
|
-
assert(r.present.includes('express'), 'express in present (declared)');
|
|
107
|
-
assert(r.present.includes('mongoose'), 'mongoose in present (declared)');
|
|
108
|
-
assert(r.missing.includes('axios'), 'axios in missing');
|
|
109
|
-
assert(r.missing.includes('uuid'), 'uuid in missing');
|
|
110
|
-
assert(r.missing.includes('date-fns'), 'date-fns in missing');
|
|
111
|
-
assert(r.missing.includes('@babel/core'), '@babel/core in missing');
|
|
112
|
-
assert(r.missing.includes('react'), 'react in missing');
|
|
113
|
-
assert(!r.missing.includes('express'), 'express NOT in missing');
|
|
114
|
-
assert(!r.missing.includes('mongoose'), 'mongoose NOT in missing');
|
|
115
|
-
|
|
116
|
-
section('Scanner: unused (declared but not imported)');
|
|
117
|
-
assert(r.unused.includes('jest'), 'jest in unused (declared, never imported)');
|
|
118
|
-
assert(!r.unused.includes('express'), 'express NOT in unused (it is imported)');
|
|
119
|
-
assert(!r.unused.includes('mongoose'), 'mongoose NOT in unused (it is imported)');
|
|
120
|
-
|
|
121
|
-
section('Commands: check (output only)');
|
|
122
|
-
console.log('\n--- depm check output ---');
|
|
123
|
-
await cmdCheck(tmpDir);
|
|
124
|
-
assert(true, 'cmdCheck ran without error');
|
|
125
|
-
|
|
126
|
-
section('Commands: audit (output only)');
|
|
127
|
-
console.log('\n--- depm audit output ---');
|
|
128
|
-
await cmdAudit(tmpDir);
|
|
129
|
-
assert(true, 'cmdAudit ran without error');
|
|
130
|
-
|
|
131
|
-
section('Commands: list (output only)');
|
|
132
|
-
console.log('\n--- depm list output ---');
|
|
133
|
-
await cmdList(tmpDir);
|
|
134
|
-
assert(true, 'cmdList ran without error');
|
|
135
|
-
|
|
136
|
-
// Cleanup
|
|
137
|
-
fs.rmSync(tmpDir, { recursive: true, force: true });
|
|
138
|
-
|
|
139
|
-
// ── Results ──────────────────────────────────────────────────────────────
|
|
140
|
-
console.log('\n' + '─'.repeat(40));
|
|
141
|
-
if (failed === 0) {
|
|
142
|
-
console.log(`\x1b[32m\x1b[1m✅ All ${passed} tests passed.\x1b[0m\n`);
|
|
143
|
-
} else {
|
|
144
|
-
console.error(`\x1b[31m\x1b[1m❌ ${failed} test(s) failed. ${passed} passed.\x1b[0m\n`);
|
|
145
|
-
process.exit(1);
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
run().catch(err => {
|
|
150
|
-
console.error('Unexpected error:', err);
|
|
151
|
-
process.exit(1);
|
|
152
|
-
});
|