@monodog/backend 1.5.2 → 1.5.4
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/CHANGELOG.md +13 -0
- package/LICENCE +21 -0
- package/README.md +19 -19
- package/dist/cli.js +20 -20
- package/dist/config-loader.js +13 -13
- package/dist/index.js +59 -15
- package/dist/utils/helpers.js +50 -9
- package/monodog-conf.example.json +11 -11
- package/package.json +17 -16
- package/src/cli.ts +190 -154
- package/src/config-loader.ts +57 -50
- package/src/get-db-url.ts +0 -1
- package/src/index.ts +1366 -1331
- package/src/types/monorepo-scanner.d.ts +7 -8
- package/src/utils/helpers.js +169 -165
- package/src/utils/helpers.ts +82 -77
- package/tsconfig.json +0 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// This declaration explicitly tells TypeScript about the specific functions
|
|
1
|
+
// This declaration explicitly tells TypeScript about the specific functions
|
|
2
2
|
// exported by the '@monodog/monorepo-scanner' package, bypassing TS7016 errors.
|
|
3
3
|
|
|
4
4
|
declare module '@monodog/monorepo-scanner' {
|
|
@@ -19,15 +19,14 @@ declare module '@monodog/monorepo-scanner' {
|
|
|
19
19
|
*/
|
|
20
20
|
export class MonorepoScanner {
|
|
21
21
|
// Constructor (when called with `new`)
|
|
22
|
-
constructor(options?: any);
|
|
23
|
-
|
|
24
|
-
/** * Resets any internal cache state for the scanner.
|
|
22
|
+
constructor(options?: any);
|
|
23
|
+
|
|
24
|
+
/** * Resets any internal cache state for the scanner.
|
|
25
25
|
*/
|
|
26
26
|
clearCache(): void;
|
|
27
|
-
|
|
28
|
-
/** * Retrieves the processed results from the scan.
|
|
27
|
+
|
|
28
|
+
/** * Retrieves the processed results from the scan.
|
|
29
29
|
*/
|
|
30
30
|
exportResults(result: any, format: 'json' | 'csv' | 'html'): any;
|
|
31
|
-
|
|
32
31
|
}
|
|
33
|
-
}
|
|
32
|
+
}
|
package/src/utils/helpers.js
CHANGED
|
@@ -1,199 +1,203 @@
|
|
|
1
|
-
|
|
2
|
-
var __importDefault =
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
'use strict';
|
|
2
|
+
var __importDefault =
|
|
3
|
+
(this && this.__importDefault) ||
|
|
4
|
+
function (mod) {
|
|
5
|
+
return mod && mod.__esModule ? mod : { default: mod };
|
|
6
|
+
};
|
|
7
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
6
8
|
exports.getCommits = getCommits;
|
|
7
9
|
exports.storePackage = storePackage;
|
|
8
10
|
exports.storeCommits = storeCommits;
|
|
9
11
|
exports.getPackageDependenciesInfo = getPackageDependenciesInfo;
|
|
10
12
|
exports.storeDependencies = storeDependencies;
|
|
11
|
-
const dotenv_1 = __importDefault(require(
|
|
12
|
-
const path_1 = __importDefault(require(
|
|
13
|
+
const dotenv_1 = __importDefault(require('dotenv'));
|
|
14
|
+
const path_1 = __importDefault(require('path'));
|
|
13
15
|
dotenv_1.default.config({ path: path_1.default.resolve(__dirname, '../.env') });
|
|
14
|
-
const client_1 = require(
|
|
16
|
+
const client_1 = require('@prisma/client');
|
|
15
17
|
const prisma = new client_1.PrismaClient();
|
|
16
18
|
const API_BASE = `http://localhost:4000/api`;
|
|
17
19
|
async function getCommits(path) {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
return await res.json();
|
|
20
|
+
const res = await fetch(API_BASE + `/commits/` + encodeURIComponent(path));
|
|
21
|
+
if (!res.ok) throw new Error('Failed to fetch commits');
|
|
22
|
+
return await res.json();
|
|
22
23
|
}
|
|
23
24
|
async function storeCommits(packageName, commits) {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
}
|
|
25
|
+
console.log('💾 Storing commits for:' + packageName);
|
|
26
|
+
// Create or update dependencies
|
|
27
|
+
for (const commit of commits) {
|
|
28
|
+
try {
|
|
29
|
+
await prisma.commit.upsert({
|
|
30
|
+
where: {
|
|
31
|
+
hash: commit.hash,
|
|
32
|
+
},
|
|
33
|
+
update: {
|
|
34
|
+
message: commit.message,
|
|
35
|
+
author: commit.author,
|
|
36
|
+
date: commit.date,
|
|
37
|
+
type: commit.type,
|
|
38
|
+
},
|
|
39
|
+
create: {
|
|
40
|
+
hash: commit.hash,
|
|
41
|
+
message: commit.message,
|
|
42
|
+
author: commit.author,
|
|
43
|
+
date: commit.date,
|
|
44
|
+
type: commit.type,
|
|
45
|
+
packageName: packageName,
|
|
46
|
+
},
|
|
47
|
+
});
|
|
48
|
+
} catch (e) {
|
|
49
|
+
if (
|
|
50
|
+
e instanceof client_1.Prisma.PrismaClientKnownRequestError &&
|
|
51
|
+
e.code === 'P2002'
|
|
52
|
+
) {
|
|
53
|
+
// Handle unique constraint violation (e.g., commit already exists)
|
|
54
|
+
console.warn(
|
|
55
|
+
`Skipping commit: ${commit.hash} (Depenndency already exists)`
|
|
56
|
+
);
|
|
57
|
+
} else {
|
|
58
|
+
// Handle any other unexpected errors
|
|
59
|
+
console.error(`Failed to store commit: ${commit.hash}`, e);
|
|
60
|
+
}
|
|
59
61
|
}
|
|
62
|
+
}
|
|
60
63
|
}
|
|
61
64
|
/**
|
|
62
65
|
* Store packages in database
|
|
63
66
|
*/
|
|
64
67
|
async function storePackage(pkg) {
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
}
|
|
110
|
-
const dependenciesInfo = getPackageDependenciesInfo(pkg);
|
|
111
|
-
if (dependenciesInfo.length) {
|
|
112
|
-
await storeDependencies(pkg.name, dependenciesInfo);
|
|
113
|
-
}
|
|
68
|
+
try {
|
|
69
|
+
// Create or update package
|
|
70
|
+
await prisma.package.upsert({
|
|
71
|
+
where: { name: pkg.name },
|
|
72
|
+
update: {
|
|
73
|
+
version: pkg.version,
|
|
74
|
+
type: pkg.type,
|
|
75
|
+
path: pkg.path,
|
|
76
|
+
description: pkg.description,
|
|
77
|
+
license: pkg.license,
|
|
78
|
+
repository: JSON.stringify(pkg.repository),
|
|
79
|
+
scripts: JSON.stringify(pkg.scripts),
|
|
80
|
+
lastUpdated: new Date(),
|
|
81
|
+
},
|
|
82
|
+
create: {
|
|
83
|
+
// Timestamps
|
|
84
|
+
createdAt: new Date(),
|
|
85
|
+
lastUpdated: new Date(),
|
|
86
|
+
// Key Metrics and Relationships
|
|
87
|
+
dependencies: JSON.stringify(pkg.dependencies), // The total number of direct dependencies (12 in your example)
|
|
88
|
+
// Manual Serialization Required: Stores a JSON array string of maintainers, e.g., '["team-frontend"]'
|
|
89
|
+
maintainers: pkg.maintainers.join(','),
|
|
90
|
+
// Manual Serialization Required: Stores a JSON array string of tags, e.g., '["core", "ui"]'
|
|
91
|
+
// Manual Serialization Required: Stores the scripts object as a JSON string
|
|
92
|
+
// Example: '{"dev": "vite", "build": "tsc && vite build"}'
|
|
93
|
+
scripts: JSON.stringify(pkg.scripts),
|
|
94
|
+
// Dependency Lists (Manual Serialization Required)
|
|
95
|
+
// Stores a JSON array string of dependencies.
|
|
96
|
+
// dependenciesList: JSON.stringify(pkg.dependenciesList),
|
|
97
|
+
devDependencies: JSON.stringify(pkg.devDependencies),
|
|
98
|
+
peerDependencies: JSON.stringify(pkg.peerDependencies),
|
|
99
|
+
name: pkg.name,
|
|
100
|
+
version: pkg.version,
|
|
101
|
+
type: pkg.type,
|
|
102
|
+
path: pkg.path,
|
|
103
|
+
description: pkg.description ?? '',
|
|
104
|
+
license: pkg.license ?? '',
|
|
105
|
+
repository: JSON.stringify(pkg.repository),
|
|
106
|
+
status: '',
|
|
107
|
+
},
|
|
108
|
+
});
|
|
109
|
+
const commits = await getCommits(pkg.path ?? '');
|
|
110
|
+
if (commits.length) {
|
|
111
|
+
await storeCommits(pkg.name, commits);
|
|
114
112
|
}
|
|
115
|
-
|
|
116
|
-
|
|
113
|
+
const dependenciesInfo = getPackageDependenciesInfo(pkg);
|
|
114
|
+
if (dependenciesInfo.length) {
|
|
115
|
+
await storeDependencies(pkg.name, dependenciesInfo);
|
|
117
116
|
}
|
|
117
|
+
} catch (error) {
|
|
118
|
+
console.warn(`⚠️ Failed to store report for ${pkg.name}:`, error);
|
|
119
|
+
}
|
|
118
120
|
}
|
|
119
121
|
/**
|
|
120
122
|
* Get package dependencies
|
|
121
123
|
*/
|
|
122
124
|
function getPackageDependenciesInfo(pkg) {
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
});
|
|
125
|
+
const allDeps = [];
|
|
126
|
+
Object.keys(pkg.dependencies || {}).forEach(depName => {
|
|
127
|
+
allDeps.push({
|
|
128
|
+
name: depName,
|
|
129
|
+
version: pkg.dependencies[depName],
|
|
130
|
+
type: 'dependency',
|
|
131
|
+
latest: '',
|
|
132
|
+
outdated: false,
|
|
132
133
|
});
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
134
|
+
});
|
|
135
|
+
Object.keys(pkg.devDependencies || {}).forEach(depName => {
|
|
136
|
+
allDeps.push({
|
|
137
|
+
name: depName,
|
|
138
|
+
version: pkg.devDependencies[depName],
|
|
139
|
+
type: 'devDependency',
|
|
140
|
+
latest: '',
|
|
141
|
+
outdated: false,
|
|
141
142
|
});
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
143
|
+
});
|
|
144
|
+
Object.keys(pkg.peerDependencies || {}).forEach(depName => {
|
|
145
|
+
allDeps.push({
|
|
146
|
+
name: depName,
|
|
147
|
+
version: pkg.peerDependencies[depName],
|
|
148
|
+
type: 'peerDependency',
|
|
149
|
+
latest: '',
|
|
150
|
+
outdated: false,
|
|
150
151
|
});
|
|
151
|
-
|
|
152
|
+
});
|
|
153
|
+
return allDeps;
|
|
152
154
|
}
|
|
153
155
|
/**
|
|
154
156
|
* Store dependencies in database
|
|
155
157
|
*/
|
|
156
158
|
async function storeDependencies(packageName, dependencies) {
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
}
|
|
159
|
+
console.log('💾 Storing Dependencies for:' + packageName);
|
|
160
|
+
// Create or update dependencies
|
|
161
|
+
for (const dep of dependencies) {
|
|
162
|
+
try {
|
|
163
|
+
await prisma.dependencyInfo.upsert({
|
|
164
|
+
where: {
|
|
165
|
+
name_packageName: {
|
|
166
|
+
// This refers to the composite unique constraint
|
|
167
|
+
name: dep.name,
|
|
168
|
+
packageName,
|
|
169
|
+
},
|
|
170
|
+
},
|
|
171
|
+
update: {
|
|
172
|
+
version: dep.version,
|
|
173
|
+
type: dep.type,
|
|
174
|
+
latest: dep.latest,
|
|
175
|
+
outdated: dep.outdated,
|
|
176
|
+
},
|
|
177
|
+
create: {
|
|
178
|
+
name: dep.name,
|
|
179
|
+
version: dep.version,
|
|
180
|
+
type: dep.type,
|
|
181
|
+
latest: dep.latest,
|
|
182
|
+
outdated: dep.outdated,
|
|
183
|
+
packageName: packageName,
|
|
184
|
+
},
|
|
185
|
+
});
|
|
186
|
+
console.log('💾 Dependencies stored in database:' + dep.name);
|
|
187
|
+
} catch (e) {
|
|
188
|
+
if (
|
|
189
|
+
e instanceof client_1.Prisma.PrismaClientKnownRequestError &&
|
|
190
|
+
e.code === 'P2002'
|
|
191
|
+
) {
|
|
192
|
+
// Handle unique constraint violation (e.g., depedency already exists)
|
|
193
|
+
console.warn(
|
|
194
|
+
`Skipping dependency: ${dep.name} (Depenndency already exists)`
|
|
195
|
+
);
|
|
196
|
+
} else {
|
|
197
|
+
// Handle any other unexpected errors
|
|
198
|
+
console.error(`Failed to store dependency: ${dep.name}`, e);
|
|
199
|
+
}
|
|
197
200
|
}
|
|
201
|
+
}
|
|
198
202
|
}
|
|
199
|
-
//# sourceMappingURL=helpers.js.map
|
|
203
|
+
//# sourceMappingURL=helpers.js.map
|
package/src/utils/helpers.ts
CHANGED
|
@@ -1,16 +1,17 @@
|
|
|
1
|
-
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
PackageInfo,
|
|
5
|
-
DependencyInfo,
|
|
6
|
-
} from '@monodog/utils/helpers'
|
|
1
|
+
import { PackageInfo, DependencyInfo } from '@monodog/utils/helpers';
|
|
7
2
|
// import dotenv from 'dotenv';
|
|
8
3
|
import path from 'path';
|
|
9
4
|
// dotenv.config({ path: path.resolve(__dirname, '../.env') });
|
|
10
|
-
import
|
|
5
|
+
// Fallback import to handle environments where PrismaClient isn't a named export
|
|
6
|
+
import * as PrismaPkg from '@prisma/client';
|
|
7
|
+
const PrismaClient = (PrismaPkg as any).PrismaClient || (PrismaPkg as any).default || PrismaPkg;
|
|
8
|
+
// Provide a fallback reference to the Prisma namespace so errors like
|
|
9
|
+
// Prisma.PrismaClientKnownRequestError can be referenced safely.
|
|
10
|
+
const Prisma = (PrismaPkg as any).Prisma || (PrismaPkg as any).PrismaClient?.Prisma || (PrismaPkg as any).default?.Prisma || PrismaPkg;
|
|
11
|
+
// Import the validateConfig function from your utils
|
|
11
12
|
import { loadConfig } from '../config-loader';
|
|
12
13
|
|
|
13
|
-
|
|
14
|
+
const appConfig = loadConfig();
|
|
14
15
|
|
|
15
16
|
// Default settings
|
|
16
17
|
const DEFAULT_PORT = 4000;
|
|
@@ -23,9 +24,16 @@ const API_BASE = `http://${host}:${port}/api`;
|
|
|
23
24
|
async function getCommits(path: string): Promise<Commit[]> {
|
|
24
25
|
const res = await fetch(API_BASE + `/commits/` + encodeURIComponent(path));
|
|
25
26
|
if (!res.ok) throw new Error('Failed to fetch commits');
|
|
26
|
-
return await res.json() as Commit[];
|
|
27
|
+
return (await res.json()) as Commit[];
|
|
28
|
+
}
|
|
29
|
+
// Commit type used by getCommits/storeCommits
|
|
30
|
+
export interface Commit {
|
|
31
|
+
hash: string;
|
|
32
|
+
message?: string;
|
|
33
|
+
author?: string;
|
|
34
|
+
date?: string;
|
|
35
|
+
type?: string;
|
|
27
36
|
}
|
|
28
|
-
|
|
29
37
|
async function storeCommits(
|
|
30
38
|
packageName: string,
|
|
31
39
|
commits: Commit[]
|
|
@@ -54,9 +62,10 @@ async function storeCommits(
|
|
|
54
62
|
},
|
|
55
63
|
});
|
|
56
64
|
} catch (e) {
|
|
65
|
+
const err = e as any;
|
|
57
66
|
if (
|
|
58
|
-
|
|
59
|
-
|
|
67
|
+
err instanceof Prisma.PrismaClientKnownRequestError &&
|
|
68
|
+
err.code === 'P2002'
|
|
60
69
|
) {
|
|
61
70
|
// Handle unique constraint violation (e.g., commit already exists)
|
|
62
71
|
console.warn(
|
|
@@ -64,7 +73,7 @@ async function storeCommits(
|
|
|
64
73
|
);
|
|
65
74
|
} else {
|
|
66
75
|
// Handle any other unexpected errors
|
|
67
|
-
console.error(`Failed to store commit: ${commit.hash}`,
|
|
76
|
+
console.error(`Failed to store commit: ${commit.hash}`, err);
|
|
68
77
|
}
|
|
69
78
|
}
|
|
70
79
|
}
|
|
@@ -73,68 +82,63 @@ async function storeCommits(
|
|
|
73
82
|
* Store packages in database
|
|
74
83
|
*/
|
|
75
84
|
async function storePackage(pkg: PackageInfo): Promise<void> {
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
});
|
|
121
|
-
|
|
122
|
-
const commits = await getCommits(pkg.path ?? '');
|
|
123
|
-
if (commits.length) {
|
|
124
|
-
await storeCommits(pkg.name, commits);
|
|
125
|
-
}
|
|
126
|
-
const dependenciesInfo = getPackageDependenciesInfo(pkg);
|
|
127
|
-
if (dependenciesInfo.length) {
|
|
128
|
-
await storeDependencies(pkg.name, dependenciesInfo);
|
|
129
|
-
}
|
|
85
|
+
try {
|
|
86
|
+
// Create or update package
|
|
87
|
+
await prisma.package.upsert({
|
|
88
|
+
where: { name: pkg.name },
|
|
89
|
+
update: {
|
|
90
|
+
version: pkg.version,
|
|
91
|
+
type: pkg.type,
|
|
92
|
+
path: pkg.path,
|
|
93
|
+
description: pkg.description,
|
|
94
|
+
license: pkg.license,
|
|
95
|
+
repository: JSON.stringify(pkg.repository),
|
|
96
|
+
scripts: JSON.stringify(pkg.scripts),
|
|
97
|
+
lastUpdated: new Date(),
|
|
98
|
+
},
|
|
99
|
+
create: {
|
|
100
|
+
// Timestamps
|
|
101
|
+
createdAt: new Date(),
|
|
102
|
+
lastUpdated: new Date(),
|
|
103
|
+
|
|
104
|
+
// Key Metrics and Relationships
|
|
105
|
+
dependencies: JSON.stringify(pkg.dependencies), // The total number of direct dependencies (12 in your example)
|
|
106
|
+
// Manual Serialization Required: Stores a JSON array string of maintainers, e.g., '["team-frontend"]'
|
|
107
|
+
maintainers: pkg.maintainers.join(','),
|
|
108
|
+
// Manual Serialization Required: Stores a JSON array string of tags, e.g., '["core", "ui"]'
|
|
109
|
+
|
|
110
|
+
// Manual Serialization Required: Stores the scripts object as a JSON string
|
|
111
|
+
// Example: '{"dev": "vite", "build": "tsc && vite build"}'
|
|
112
|
+
scripts: JSON.stringify(pkg.scripts),
|
|
113
|
+
|
|
114
|
+
// Dependency Lists (Manual Serialization Required)
|
|
115
|
+
// Stores a JSON array string of dependencies.
|
|
116
|
+
// dependenciesList: JSON.stringify(pkg.dependenciesList),
|
|
117
|
+
devDependencies: JSON.stringify(pkg.devDependencies),
|
|
118
|
+
peerDependencies: JSON.stringify(pkg.peerDependencies),
|
|
119
|
+
name: pkg.name,
|
|
120
|
+
version: pkg.version,
|
|
121
|
+
type: pkg.type,
|
|
122
|
+
path: pkg.path,
|
|
123
|
+
description: pkg.description ?? '',
|
|
124
|
+
license: pkg.license ?? '',
|
|
125
|
+
repository: JSON.stringify(pkg.repository),
|
|
126
|
+
status: '',
|
|
127
|
+
},
|
|
128
|
+
});
|
|
130
129
|
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
130
|
+
const commits = await getCommits(pkg.path ?? '');
|
|
131
|
+
if (commits.length) {
|
|
132
|
+
await storeCommits(pkg.name, commits);
|
|
133
|
+
}
|
|
134
|
+
const dependenciesInfo = getPackageDependenciesInfo(pkg);
|
|
135
|
+
if (dependenciesInfo.length) {
|
|
136
|
+
await storeDependencies(pkg.name, dependenciesInfo);
|
|
136
137
|
}
|
|
138
|
+
} catch (error) {
|
|
139
|
+
console.warn(`⚠️ Failed to store report for ${pkg.name}:`, error);
|
|
137
140
|
}
|
|
141
|
+
}
|
|
138
142
|
|
|
139
143
|
/**
|
|
140
144
|
* Get package dependencies
|
|
@@ -207,9 +211,10 @@ async function storeDependencies(
|
|
|
207
211
|
});
|
|
208
212
|
console.log('💾 Dependencies stored in database:' + dep.name);
|
|
209
213
|
} catch (e) {
|
|
214
|
+
const err = e as any;
|
|
210
215
|
if (
|
|
211
|
-
|
|
212
|
-
|
|
216
|
+
err instanceof Prisma.PrismaClientKnownRequestError &&
|
|
217
|
+
err.code === 'P2002'
|
|
213
218
|
) {
|
|
214
219
|
// Handle unique constraint violation (e.g., depedency already exists)
|
|
215
220
|
console.warn(
|
|
@@ -217,7 +222,7 @@ async function storeDependencies(
|
|
|
217
222
|
);
|
|
218
223
|
} else {
|
|
219
224
|
// Handle any other unexpected errors
|
|
220
|
-
console.error(`Failed to store dependency: ${dep.name}`,
|
|
225
|
+
console.error(`Failed to store dependency: ${dep.name}`, err);
|
|
221
226
|
}
|
|
222
227
|
}
|
|
223
228
|
}
|
|
@@ -228,5 +233,5 @@ export {
|
|
|
228
233
|
storePackage,
|
|
229
234
|
storeCommits,
|
|
230
235
|
getPackageDependenciesInfo,
|
|
231
|
-
storeDependencies
|
|
232
|
-
}
|
|
236
|
+
storeDependencies,
|
|
237
|
+
};
|