Add path validation and remove -o flag check
Signed-off-by: Juan Escalada <juanescalada175@gmail.com>
This commit is contained in:
@@ -24,6 +24,7 @@ import {
|
||||
} from './api-extractor';
|
||||
import { paths as cliPaths, resolvePackagePaths } from '../../lib/paths';
|
||||
import { generateTypeDeclarations } from './generateTypeDeclarations';
|
||||
import fs from 'fs/promises';
|
||||
|
||||
type Options = {
|
||||
ci?: boolean;
|
||||
@@ -45,17 +46,14 @@ export const buildApiReports = async (paths: string[] = [], opts: Options) => {
|
||||
const runTsc = opts.tsc;
|
||||
const allowWarnings = parseArrayOption(opts.allowWarnings);
|
||||
const allowAllWarnings = opts.allowAllWarnings;
|
||||
const omitMessagesRaw = opts.omitMessages;
|
||||
|
||||
if (omitMessagesRaw && omitMessagesRaw.endsWith(',')) {
|
||||
throw new Error(
|
||||
`Invalid value for --omit-messages: ${omitMessagesRaw}\nMust be a comma-separated list of strings without spaces or wrapped in quotations.`,
|
||||
);
|
||||
}
|
||||
|
||||
const omitMessages = parseArrayOption(omitMessagesRaw);
|
||||
const omitMessages = parseArrayOption(opts.omitMessages);
|
||||
|
||||
const isAllPackages = !paths?.length;
|
||||
|
||||
if (!isAllPackages) {
|
||||
checkValidPaths(paths);
|
||||
}
|
||||
|
||||
const selectedPackageDirs = await resolvePackagePaths({
|
||||
paths,
|
||||
include: opts.include,
|
||||
@@ -138,5 +136,26 @@ export const buildApiReports = async (paths: string[] = [], opts: Options) => {
|
||||
* // returns []
|
||||
*/
|
||||
function parseArrayOption(value: string | undefined) {
|
||||
return value ? value.split(',').map(s => s.trim()) : [];
|
||||
return value
|
||||
? value
|
||||
.split(',')
|
||||
.map(s => s.trim())
|
||||
.filter(Boolean)
|
||||
: [];
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the provided paths are valid.
|
||||
*
|
||||
* @throws Error if any of the paths are invalid.
|
||||
* @param paths An array of paths to check.
|
||||
*/
|
||||
function checkValidPaths(paths: string[]) {
|
||||
paths.forEach(async path => {
|
||||
try {
|
||||
await fs.access(path);
|
||||
} catch (error) {
|
||||
throw new Error(`Invalid path provided: ${path}`);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user