Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
private async parseBabelConfig(fetchEnd: FetchEnd) {
const resource = fetchEnd.resource;
const resourceFileName = path.basename(resource);
const isPackageJson: boolean = resourceFileName === 'package.json';
const isBabelrc: boolean = resourceFileName === '.babelrc';
if (!isBabelrc && !isPackageJson) {
return;
}
let config: BabelConfig;
try {
const response = fetchEnd.response;
// When using local connector to read local files, 'content' is empty.
let result = parseJSON(response.body.content, 'extends');
if (isPackageJson && !result.data.babel) {
return;
}
await this.engine.emitAsync('parse::start::babel-config', { resource });
// `result.scope('babel')` won't be null since `result.data.babel` was confirmed to exist above.
result = isPackageJson ? result.scope('babel')! : result;
config = result.data;
const originalConfig: BabelConfig = cloneDeep(config);
const finalConfig = calculateFinalConfig(config, resource);
if (finalConfig instanceof Error) {
if (response.statusCode >= 400) {
return;
}
await this.engine.emitAsync(`parse::start::manifest`, { resource });
let result: IJSONResult;
/*
* Try to see if the content of the web app manifest file
* is a valid JSON.
*/
try {
result = parseJSON(response.body.content);
} catch (e) {
await this.engine.emitAsync(this.parseJSONErrorEventName, {
error: e,
resource
});
return;
}
/*
* Try to see if the content of the web app manifest file
* is a valid acording to the schema.
*/
const validationResult: SchemaValidationResult = validate(schema, result.data, result.getLocation);
private async parsePackageJson(fetchEnd: FetchEnd) {
const resource = fetchEnd.resource;
const resourceFileName = path.basename(resource);
const isPackageJson: boolean = resourceFileName === 'package.json';
if (!isPackageJson) {
return;
}
try {
const response = fetchEnd.response;
const result = parseJSON(response.body.content);
await this.engine.emitAsync('parse::start::package-json', { resource });
const config: IJsonSchemaForNpmPackageJsonFiles = result.data;
const validationResult: SchemaValidationResult = await this.validateSchema(config, resource, result);
if (!validationResult.valid) {
await this.emitInvalidPackageJson(validationResult, resource);
return;
}
await this.engine.emitAsync('parse::end::package-json', {
config: validationResult.data,
getLocation: result.getLocation,
*
* Not Match examples:
* tsconfigimproved.json
* anythingelse.json
* tsconfig.schema.json
*/
if (!fileName.match(/^tsconfig\.([^.]*\.)?json$/gi) || fileName === 'tsconfig.schema.json') {
return;
}
await this.engine.emitAsync(`parse::start::typescript-config`, { resource });
let result: IJSONResult;
try {
result = parseJSON(fetchEnd.response.body.content);
const originalConfig = cloneDeep(result.data);
const config = finalConfig(result.data, resource);
if (config instanceof Error) {
await this.engine.emitAsync(`parse::error::typescript-config::extends`,
{
error: config,
getLocation: result.getLocation,
resource: config.resource
});
return;
}