fix(smartpnpm): harden pnpm license parsing and modernize test and package configuration
This commit is contained in:
@@ -10,6 +10,8 @@ export interface IPnpmLicenseResult {
|
||||
"description": string;
|
||||
}
|
||||
|
||||
export type TPnpmLicenseMap = Record<string, IPnpmLicenseResult[]>;
|
||||
|
||||
export class SmartPnpm {
|
||||
public projectDir: string;
|
||||
|
||||
@@ -19,18 +21,12 @@ export class SmartPnpm {
|
||||
|
||||
private smartshellInstance = new plugins.smartshell.Smartshell({
|
||||
executor: 'bash',
|
||||
})
|
||||
});
|
||||
|
||||
async getDependencyLicenseJson() {
|
||||
try {
|
||||
// Get store directory
|
||||
const execResult = await this.smartshellInstance.execSilent(`(cd ${this.projectDir} && pnpm licenses list --json)`);
|
||||
const licenseJson: {[key: string]: Array<IPnpmLicenseResult>} = JSON.parse(execResult.stdout);
|
||||
return licenseJson;
|
||||
|
||||
} catch (error) {
|
||||
console.error('Error:', error);
|
||||
}
|
||||
async getDependencyLicenseJson(): Promise<TPnpmLicenseMap> {
|
||||
const projectDir = this.projectDir.replace(/(["\\$`])/g, '\\$1');
|
||||
const execResult = await this.smartshellInstance.execSilent(`(cd "${projectDir}" && pnpm licenses list --json)`);
|
||||
return JSON.parse(execResult.stdout) as TPnpmLicenseMap;
|
||||
}
|
||||
|
||||
public async printDependencyLicenseSummary() {
|
||||
@@ -45,7 +41,7 @@ export class SmartPnpm {
|
||||
} else {
|
||||
console.log(`|-- ${refArray.length} packages. Not detailing this license type.`);
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
public async getDependencyLicenseFlatArray() {
|
||||
|
||||
Reference in New Issue
Block a user