|
1 | 1 | import {publint} from 'publint'; |
2 | 2 | import {formatMessage} from 'publint/utils'; |
3 | | -import type {ReportPluginResult, Options, AnalysisContext} from '../types.js'; |
4 | | -import fs from 'node:fs/promises'; |
5 | | -import path from 'node:path'; |
| 3 | +import type {ReportPluginResult, AnalysisContext} from '../types.js'; |
6 | 4 |
|
7 | 5 | export async function runPublint( |
8 | 6 | context: AnalysisContext |
9 | | -): Promise<ReportPluginResult> { |
10 | | - const targetTarballs = context.options?.targetTarball; |
11 | | - |
12 | | - if (targetTarballs && targetTarballs.length > 0) { |
13 | | - return runPublintWithTarballs(targetTarballs, context.options); |
14 | | - } |
15 | | - |
16 | | - return {messages: []}; |
17 | | -} |
18 | | - |
19 | | -export async function runPublintWithTarballs( |
20 | | - targetTarballs: string[], |
21 | | - options?: Options |
22 | 7 | ): Promise<ReportPluginResult> { |
23 | 8 | const result: ReportPluginResult = { |
24 | 9 | messages: [] |
25 | 10 | }; |
26 | | - const root = options?.root || process.cwd(); |
27 | 11 |
|
28 | | - for (const targetTarball of targetTarballs) { |
29 | | - const targetTarballPath = path.resolve(root, targetTarball); |
30 | | - // TODO (jg): handle failed reads gracefully |
31 | | - const buffer = await fs.readFile(targetTarballPath); |
32 | | - const tarball = buffer.buffer.slice( |
33 | | - buffer.byteOffset, |
34 | | - buffer.byteOffset + buffer.byteLength |
35 | | - ) as ArrayBuffer; |
36 | | - const publintResult = await publint({pack: {tarball}}); |
| 12 | + try { |
| 13 | + const publintResult = await publint({pack: 'auto', pkgDir: context.root}); |
37 | 14 | for (const problem of publintResult.messages) { |
38 | 15 | result.messages.push({ |
39 | 16 | severity: problem.type, |
40 | 17 | score: 0, |
41 | 18 | message: formatMessage(problem, publintResult.pkg) ?? '' |
42 | 19 | }); |
43 | 20 | } |
| 21 | + } catch (error) { |
| 22 | + console.error(`Failed to run publint: ${error}`); |
44 | 23 | } |
45 | 24 |
|
46 | 25 | return result; |
|
0 commit comments