[add] implement vulnerability checking and advisory fetching, enhance repo processing, and add utility functions

This commit is contained in:
2025-08-19 19:13:24 +01:00
parent 52d0c7b649
commit 2c30fce7c8
14 changed files with 700 additions and 15 deletions

View File

@@ -1,21 +1,25 @@
import wp from 'webpack';
import path from 'node:path'
import {createRequire,builtinModules} from 'node:module'
import { mkdirSync } from 'node:fs';
/**
*
* @param {string} l library name
* @param {string} moduleLocation module location
* @param {string} outputPath
* @returns
* @returns the compressed file path
*/
export function wpCompress(l, moduleLocation,outputPath = path.resolve('./output/')) {
const basePackage = path.basename(path.resolve(moduleLocation));
const finalOutputPath = path.resolve(outputPath, basePackage);
mkdirSync(finalOutputPath, { recursive: true });
return new Promise((resolve, reject) => {
const libraryLocation = extractFunctionForModule(l, moduleLocation);
console.log(libraryLocation);
// console.log(libraryLocation);
const outputFile = l + '.bundle.cjs';
console.log(`[WebPack] Compressing ${l} in ${moduleLocation} to ${path.join(outputPath, outputFile)}`);
console.log(`[WebPack] Compressing ${l} in ${moduleLocation} to ${path.join(finalOutputPath, outputFile)}`);
const moduleFallbackMap = builtinModules.reduce((prev, current) => {
prev[current] = false;
return prev;
@@ -36,7 +40,7 @@ export function wpCompress(l, moduleLocation,outputPath = path.resolve('./output
fallback:moduleFallbackMap
},
output: {
path: outputPath,
path: finalOutputPath,
filename: outputFile,
clean: false,
iife: false,
@@ -52,7 +56,7 @@ export function wpCompress(l, moduleLocation,outputPath = path.resolve('./output
// console.log(`[WebPack]`,stats?.toJson().errors);
reject(err || stats);
}else{
resolve(path.resolve(outputPath, outputFile));
resolve(path.resolve(finalOutputPath, outputFile));
}
});
});

View File

@@ -82,7 +82,9 @@ export class LibraryTypesRecorder {
return undefined;
} else if(type.isNull()){
return null;
} else if(type.isBigInt()){
} else if (type.isVoid()){
return undefined;
}else if(type.isBigInt()){
return simpleFaker.number.bigInt();
}else if (type.isString()) {

View File

@@ -16,8 +16,14 @@ import {builtinModules} from 'node:module'
export function getImportCallsAndArgumentTypes(importDecls, checker, mainFilePath, libraryTypesRecorder) {
// const libraryTypesRecorder = new LibraryTypesRecorder(checker);
for (const importStringDecl of importDecls) {
// console.log(importStringDecl);
const importDecl = importStringDecl.getFirstAncestor();
const packageName = importStringDecl.getLiteralValue();
if(isNodeModule(packageName)) {
// just skip node module scanning.
continue;
}
if (importDecl === undefined) {
console.error("Import declaration is undefined for", importStringDecl.getText());
continue;