Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
log('debug', 'Reading file at', filePath);
try {
content = await fs.readFileAsync(filePath, 'utf-8');
log('debug', 'File sucessfully read', filePath);
if (SHEBANG_REGEXP.test(content)) {
log('debug', 'Found a shebang, commenting it', filePath);
content = '// Shebang commented by jsarch: ' + content;
}
} catch (err) {
log('error', 'File read failure:', filePath);
log('stack', 'Stack:', err.stack);
throw YError.wrap(err, 'E_FILE_FAILURE', filePath);
}
try {
const ast = parser(content);
const architectureNotes = [];
visit(ast, {
visitComment: function(path) {
const comment = path.value.value;
const matches = ARCHITECTURE_NOTE_REGEXP.exec(comment);
if (matches) {
architectureNotes.push({
num: matches[1],
title: matches[2].trim(),
content: comment.substr(matches[0].length).trim(),
return function resolveModule(metapakModuleName, packageConf) {
try {
// Cover the case a metapak plugin runs itself
if (metapakModuleName === packageConf.name) {
return path.dirname(require.resolve(`${PROJECT_DIR}/package`));
}
return path.dirname(require.resolve(`${metapakModuleName}/package`));
} catch (err) {
throw YError.wrap(err, 'E_MODULE_NOT_FOUND', metapakModuleName);
}
};
}
.catch(err => {
throw YError.wrap(err, 'E_PACKAGE_NOT_FOUND', path);
})
.then(_parseJSON.bind(null, { log }, path));
);
if (!serviceDescriptor) {
debug('Provider did not return a descriptor:', serviceName);
return Promise.reject(new YError(E_BAD_SERVICE_PROVIDER, serviceName));
}
debug('Successfully initialized a service descriptor:', serviceName);
if (serviceDescriptor.fatalErrorPromise) {
debug('Registering service descriptor error promise:', serviceName);
siloContext.errorsPromises.push(serviceDescriptor.fatalErrorPromise);
}
siloContext.servicesDescriptors.set(serviceName, serviceDescriptor);
} catch (err) {
debug('Error initializing a service descriptor:', serviceName, err.stack);
if (E_UNMATCHED_DEPENDENCY === err.code) {
throw YError.wrap(
...[err, E_UNMATCHED_DEPENDENCY, serviceName].concat(err.params),
);
}
throw err;
}
return serviceDescriptor;
}
.catch(err => {
throw YError.wrap(err, 'E_MALFORMED_PACKAGE', path);
});
}
this.traverse(path);
},
});
log('debug', 'File sucessfully processed', path);
log(
'debug',
'Architecture notes found:',
architectureNotes.map(a => a.title),
);
return architectureNotes;
} catch (err) {
log('error', 'File parse failure:', filePath);
log('stack', 'Stack:', err.stack);
throw YError.wrap(err, 'E_FILE_PARSE_FAILURE', filePath);
}
}
log('debug', 'Processing pattern:', pattern);
try {
const files = await glob(pattern, {
cwd,
dot: true,
nodir: true,
absolute: true,
});
log('debug', 'Pattern sucessfully resolved', pattern);
log('debug', 'Files:', files);
return files;
} catch (err) {
log('error', 'Pattern failure:', pattern);
log('stack', 'Stack:', err.stack);
throw YError.wrap(err, 'E_PATTERN_FAILURE', pattern);
}
}),
),