Skip to content

Commit

Permalink
handle more errors while reading from node_modules
Browse files Browse the repository at this point in the history
  • Loading branch information
Cammisuli committed Dec 16, 2021
1 parent ba2bfd0 commit 792a5d7
Showing 1 changed file with 28 additions and 19 deletions.
47 changes: 28 additions & 19 deletions libs/server/src/lib/utils/read-projects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import {
normalizeSchema,
readAndCacheJsonFile,
} from '../utils/utils';
import { getTelemetry } from '../telemetry';
import { getOutputChannel } from './output-channel';

export function readTargetDef(
targetName: string,
Expand Down Expand Up @@ -57,25 +59,32 @@ export async function readBuilderSchema(
basedir: string,
builder: string,
projectDefaults?: { [name: string]: string }
): Promise<Option[]> {
const [npmPackage, builderName] = builder.split(':');
const packageJson = await readAndCacheJsonFile(
path.join(npmPackage, 'package.json'),
path.join(basedir, 'node_modules')
);
const b = packageJson.json.builders || packageJson.json.executors;
const buildersPath = b.startsWith('.') ? b : `./${b}`;
const buildersJson = await readAndCacheJsonFile(
buildersPath,
path.dirname(packageJson.path)
);
): Promise<Option[] | undefined> {
try {
const [npmPackage, builderName] = builder.split(':');
const packageJson = await readAndCacheJsonFile(
path.join(npmPackage, 'package.json'),
path.join(basedir, 'node_modules')
);
const b = packageJson.json.builders || packageJson.json.executors;
const buildersPath = b.startsWith('.') ? b : `./${b}`;
const buildersJson = await readAndCacheJsonFile(
buildersPath,
path.dirname(packageJson.path)
);

const builderDef = (buildersJson.json.builders ||
buildersJson.json.executors)[builderName];
const builderSchema = await readAndCacheJsonFile(
builderDef.schema,
path.dirname(buildersJson.path)
);
const builderDef = (buildersJson.json.builders ||
buildersJson.json.executors)[builderName];
const builderSchema = await readAndCacheJsonFile(
builderDef.schema,
path.dirname(buildersJson.path)
);

return await normalizeSchema(builderSchema.json, projectDefaults);
return await normalizeSchema(builderSchema.json, projectDefaults);
} catch (e) {
// todo: make this a utility function to be used in more places.
const stringifiedError = e.toString ? e.toString() : JSON.stringify(e);
getOutputChannel().appendLine(stringifiedError);
getTelemetry().exception(stringifiedError);
}
}

0 comments on commit 792a5d7

Please sign in to comment.