Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const requestSource = async (url: string, connector: string): Promise => {
try {
if (connector === 'local') {
return await readFileAsync(asPathString(getAsUri(url)!));
}
/*
* Allow us to use our self-signed cert for testing.
* https://github.com/request/request/issues/418#issuecomment-23058601
*/
return await requestAsync({
rejectUnauthorized: false,
strictSSL: false,
url
});
} catch (e) {
// Some tests deliberately use invalid URLs (e.g. `test:`).
return '';
}
};
private async getGitIgnore() {
try {
const rawList = await readFileAsync(path.join(cwd(), '.gitignore'));
const splitList = rawList.split('\n');
const result = splitList.reduce((total: string[], ignore: string) => {
const value: string = ignore.trim();
/* istanbul ignore if */
if (!value) {
return total;
}
/* istanbul ignore if */
if (value[0] === '/') {
total.push(value.substr(1));
} else {
total.push(value);
}
for (const folder of desktopInstallationFolders) {
const executable = findChromeExecutable(folder, executables);
if (executable) {
return executable;
}
}
// 2. Look for executables by using the which command
for (const executable of executables) {
try {
const chromePath =
execFileSync('which', [executable], { stdio: 'pipe' }).toString()
.split(newLineRegex)[0];
if (chromePath && isFile(chromePath)) {
return chromePath;
}
} catch (e) {
// Not installed.
}
}
return '';
};
const getConnections = (): NetworkConfig[] => {
const configContent = readFile(`${__dirname}/connections.ini`);
const configsText = configContent
.replace(/#.*?\n/g, '') // remove comments
.replace(/\r\n/g, '\n') // remove \r in case the file has a Windows EOL
.split(`\n\n`);
const configs = configsText.map(parseConnection);
return configs;
};
const determineMediaTypeBasedOnFileName = (resource: string, rawContent: Buffer): string | null => {
const fileName = getFileName(resource);
if (!fileName) {
return null;
}
const configFileNameRegex = /^\.[a-z0-9]+rc$/i;
if (!configFileNameRegex.test(fileName)) {
return null;
}
try {
// Determine if this is a json file.
JSON.parse(rawContent.toString());
} catch (err) {
return 'text/plain';
return require('./snyk-snapshot.json');
}
try {
const snykDBPath = require.resolve('./snyk-snapshot.json');
const snykStat = await promisify(fs.stat)(snykDBPath);
const modified = new Date(snykStat.mtime).getTime();
// We check if the file is older than 24h to update it
/* istanbul ignore if */
if (now - modified > oneDay) {
debug('snkyDB is older than 24h.');
debug('Updating snykDB');
const res = await requestAsync('https://snyk.io/partners/api/v2/vulndb/clientside.json');
await writeFileAsync(snykDBPath, res);
}
} catch (e) /* istanbul ignore next */ {
debug(e);
debug(`Error loading snyk's data`);
}
return require('./snyk-snapshot.json');
};
]);
const { metaPath, hintPath, testPath } = data.isMulti ?
{
hintPath: join(hintFile.destination, `${hint.normalizedName}.ts`),
metaPath: join(metaFile.destination, 'meta', `${hint.normalizedName}.ts`),
testPath: join(testFile.destination, `${hint.normalizedName}.ts`)
} :
{
hintPath: join(hintFile.destination, 'hint.ts'),
metaPath: join(metaFile.destination, 'meta.ts'),
testPath: join(testFile.destination, `tests.ts`)
};
await Promise.all([mkdirpAsync(dirname(hintPath)), mkdirpAsync(dirname(testPath)), mkdirpAsync(dirname(metaPath))]);
await Promise.all([writeFileAsync(hintPath, hintContent), writeFileAsync(testPath, testContent), writeFileAsync(metaPath, metaContent)]);
if (data.isMulti) {
const docContent = await compileTemplate(docFile.path, hint);
// e.g.: hint-typescript-config/docs/is-valid.ts
const docPath = join(docFile.destination, `${hint.normalizedName}.md`);
await mkdirpAsync(dirname(docPath));
await writeFileAsync(docPath, docContent);
}
}
// Create `_locales` directory
if (data.official) {
const localeDir = {
destination: join(destination, 'src', '_locales', 'en', 'messages.json'),
const { destination: dest, path: p } = file;
const fileContent = await compileTemplate(p, data);
await mkdirpAsync(dirname(dest));
await writeFileAsync(dest, fileContent);
}
// For packages with multiple hints, we need to create an "index" meta file.
if (data.isMulti) {
const metaIndexContent = await compileTemplate(metaIndexFile.path, data);
// e.g.: hint-ssllabs/src/meta.ts
const metaIndexPath = join(metaIndexFile.destination, 'meta.ts');
await mkdirpAsync(dirname(metaIndexPath));
await writeFileAsync(metaIndexPath, metaIndexContent);
}
for (const hint of data.hints) {
const [hintContent, testContent, metaContent] = await Promise.all([
compileTemplate(hintFile.path, { hint, packageData: data }),
compileTemplate(testFile.path, hint),
compileTemplate(metaFile.path, { hint, packageData: data })
]);
const { metaPath, hintPath, testPath } = data.isMulti ?
{
hintPath: join(hintFile.destination, `${hint.normalizedName}.ts`),
metaPath: join(metaFile.destination, 'meta', `${hint.normalizedName}.ts`),
testPath: join(testFile.destination, `${hint.normalizedName}.ts`)
} :
{
hintPath: join(hintFile.destination, 'hint.ts'),
metaPath: join(metaFile.destination, 'meta.ts'),
testPath: join(testFile.destination, `tests.ts`)
};
await Promise.all([mkdirpAsync(dirname(hintPath)), mkdirpAsync(dirname(testPath)), mkdirpAsync(dirname(metaPath))]);
await Promise.all([writeFileAsync(hintPath, hintContent), writeFileAsync(testPath, testContent), writeFileAsync(metaPath, metaContent)]);
if (data.isMulti) {
const docContent = await compileTemplate(docFile.path, hint);
// e.g.: hint-typescript-config/docs/is-valid.ts
const docPath = join(docFile.destination, `${hint.normalizedName}.md`);
await mkdirpAsync(dirname(docPath));
await writeFileAsync(docPath, docContent);
}
}
// Create `_locales` directory
if (data.official) {
const localeDir = {
destination: join(destination, 'src', '_locales', 'en', 'messages.json'),
path: join(__dirname, TEMPLATE_PATH, 'locales-messages.json.hbs')
};
const localesContent = await compileTemplate(localeDir.path, data);
await mkdirpAsync(dirname(localeDir.destination));
await writeFileAsync(localeDir.destination, localesContent);
}
};
await mkdirpAsync(dirname(docPath));
await writeFileAsync(docPath, docContent);
}
}
// Create `_locales` directory
if (data.official) {
const localeDir = {
destination: join(destination, 'src', '_locales', 'en', 'messages.json'),
path: join(__dirname, TEMPLATE_PATH, 'locales-messages.json.hbs')
};
const localesContent = await compileTemplate(localeDir.path, data);
await mkdirpAsync(dirname(localeDir.destination));
await writeFileAsync(localeDir.destination, localesContent);
}
};