Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export const loadCreateHintPackage = () => {
// webpack will embed the package.json
/* istanbul ignore if */
if (process.env.webpack) { // eslint-disable-line no-process-env
return require('../package.json');
}
const pkgRoot = findPackageRoot(__dirname, 'package.json');
return require(`${pkgRoot}/package.json`);
};
hasMultipleResources,
isFullPackageName,
loadResource,
requirePackage,
ResourceErrorStatus,
ResourceType
} from '@hint/utils';
import { readFile } from '@hint/utils-fs';
import { debug as d } from '@hint/utils-debug';
import { IHintConstructor, HintResources } from '../types';
import { Configuration } from '../config';
import { IConnectorConstructor } from '../types/connector';
const debug: debug.IDebugger = d(__filename);
const HINT_ROOT: string = findPackageRoot();
const NODE_MODULES_ROOT: string = (() => {
const root: string = findNodeModulesRoot();
return root;
})();
/** Cache of resources ids. */
const resourceIds: Map = new Map();
/*
* ------------------------------------------------------------------------------
* Public
* ------------------------------------------------------------------------------
*/
/** Returns a list with the ids of all the core resources of the given `type`. */
const browserslistConfigExists = (): boolean => {
let browserslistFolder: string | null;
try {
browserslistFolder = findPackageRoot(__dirname, '.browserslistrc');
} catch (e) {
browserslistFolder = null;
}
if (browserslistFolder) {
return true;
}
let packageJsonFolder: string | null;
try {
packageJsonFolder = findPackageRoot(__dirname, 'package.json');
} catch (e) {
packageJsonFolder = null;
}
let browserslistFolder: string | null;
try {
browserslistFolder = findPackageRoot(__dirname, '.browserslistrc');
} catch (e) {
browserslistFolder = null;
}
if (browserslistFolder) {
return true;
}
let packageJsonFolder: string | null;
try {
packageJsonFolder = findPackageRoot(__dirname, 'package.json');
} catch (e) {
packageJsonFolder = null;
}
if (packageJsonFolder) {
const packageJson = require(path.join(packageJsonFolder, 'package.json'));
return !!packageJson.browserslist;
}
return false;
};