Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
...normalizedConfig(pkg['flow-coverage-report']),
...args
};
}
} catch (err) {
if (process.env.VERBOSE) {
console.error('Unable to load config from project package.json', packageJSONPath, err);
}
}
let projectConfigPath;
try {
projectConfigPath = path.resolve(path.join(getProjectDir(args), '.flow-coverage-report.json'));
const projectConfigRaw = fs.readFileSync(projectConfigPath);
const projectConfigData = parseJSON(stripJSONComments(String(projectConfigRaw)));
if (process.env.VERBOSE) {
console.log('Loaded config from project dir', projectConfigPath, projectConfigData);
}
return {
...defaultConfig,
...normalizedConfig(projectConfigData),
...args
};
} catch (err) {
if (process.env.VERBOSE) {
console.error('Unable to load config from file', projectConfigPath, err);
}
}
export default function(configPath) {
const configContent = stripComments(fs.readFileSync(configPath, 'utf8'));
return yaml.safeLoad(configContent);
}
private load(): void {
let jsonc = FS.readFileSync(this.path, 'utf8');
let json = stripJSONComments(jsonc);
this.raw = JSON.parse(json);
}
}
loadJSONConfigFile(filePath: string) {
this.ctx.logger.debug(`Loading JSON config file: ${filePath}`);
try {
return JSON.parse(stripComments(this.readFile(filePath)));
} catch (e) {
this.ctx.logger.debug(`Error reading JSON file: ${filePath}`);
e.message = `Cannot read config file: ${filePath}\nError: ${e.message}`;
e.messageTemplate = "failed-to-read-json";
e.messageData = {
path: filePath,
message: e.message
};
throw e;
}
}
export default function(path) {
const content = stripJsonComments(readFileSync(path, 'utf-8'));
return JSON.parse(content);
}
function parseConfigFile(configFilePath) {
const configContent = stripComments(fs.readFileSync(configFilePath, 'utf8'));
try {
return jsYaml.safeLoad(configContent);
} catch (YAMLException) {
throw new Error(`Config file cannot be parsed: ${configFilePath}'`);
}
}
let messageData: LocalizedMessageData;
let messageContents: string | Buffer;
let extensionName: string = manifestData.name;
try {
messageContents = await fs.readFile(messageFile, {encoding: 'utf-8'});
} catch (error) {
throw new UsageError(
`Error reading messages.json file at ${messageFile}: ${error}`);
}
messageContents = stripBom(messageContents);
try {
messageData = parseJSON(stripJsonComments(messageContents));
} catch (error) {
throw new UsageError(
`Error parsing messages.json file at ${messageFile}: ${error}`);
}
extensionName = manifestData.name.replace(
/__MSG_([A-Za-z0-9@_]+?)__/g,
(match, messageName) => {
if (!(messageData[messageName]
&& messageData[messageName].message)) {
const error = new UsageError(
`The locale file ${messageFile} ` +
`is missing key: ${messageName}`);
throw error;
} else {
return messageData[messageName].message;
_createConfigFromFile(configPath)
{
configPath = path.resolve(configPath);
const ext = path.extname(configPath);
if (ext === '.js')
{
return require(configPath);
}
else
{
const configJSON = fs.readFileSync(configPath, { encode: 'utf8' }).toString();
return JSON.parse(stripJsonComments(configJSON));
}
}
static async eval(command, callback) {
if (typeof callback === 'function') {
callback(command);
}
}
static getLabel(key) {
if (!labels.hasOwnProperty(key)) {
return `[${key}]`;
}
return labels[key].message;
}
}
const json = stripJsonComments(fs.readFileSync('_locales/en/messages.json', 'utf8'));
const labels = JSON.parse(json);