Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
async function determinePackageInstaller(
fs: FileSystem,
filepath: FilePath,
): Promise {
let configFile = await resolveConfig(fs, filepath, [
'yarn.lock',
'package-lock.json',
]);
let hasYarn = await Yarn.exists();
// If Yarn isn't available, or there is a package-lock.json file, use npm.
let configName = configFile && path.basename(configFile);
if (!hasYarn || configName === 'package-lock.json') {
return new Npm();
}
return new Yarn();
}
dotenvFiles.map(async dotenvFile => {
const envPath = await resolveConfig(fs, filePath, [dotenvFile]);
if (envPath == null) {
return;
}
// `ignoreProcessEnv` prevents dotenv-expand from writing values into `process.env`:
// https://github.com/motdotla/dotenv-expand/blob/ddb73d02322fe8522b4e05b73e1c1ad24ea7c14a/lib/main.js#L5
let output = variableExpansion({
parsed: dotenv.parse(await fs.readFile(envPath)),
ignoreProcessEnv: true
});
if (output.error != null) {
throw output.error;
}
return output.parsed;
entries = [path.resolve(initialOptions.entries)];
}
let inputFS = initialOptions.inputFS || new NodeFS();
let outputFS = initialOptions.outputFS || new NodeFS();
let packageManager =
initialOptions.packageManager || new NodePackageManager(inputFS);
let rootDir =
initialOptions.rootDir != null
? path.resolve(initialOptions.rootDir)
: getRootDir(entries);
let projectRootFile =
(await resolveConfig(inputFS, path.join(rootDir, 'index'), [
...LOCK_FILE_NAMES,
'.git',
'.hg'
])) || path.join(inputFS.cwd(), 'index'); // ? Should this just be rootDir
let lockFile = null;
let rootFileName = path.basename(projectRootFile);
if (LOCK_FILE_NAMES.includes(rootFileName)) {
lockFile = projectRootFile;
}
let projectRoot = path.dirname(projectRootFile);
let outputCwd = outputFS.cwd();
let cacheDir =
// If a cacheDir is provided, resolve it relative to cwd. Otherwise,
// use a default directory resolved relative to the project root.
export async function resolveParcelConfig(
filePath: FilePath,
options: ParcelOptions
) {
let configPath = await resolveConfig(options.inputFS, filePath, [
'.parcelrc'
]);
if (!configPath) {
return null;
}
return readAndProcess(configPath, options);
}
async function install(
fs: FileSystem,
modules: Array,
filepath: FilePath,
options: InstallOptions = {},
): Promise {
let {installPeers = true, saveDev = true, packageInstaller} = options;
logger.progress(`Installing ${modules.join(', ')}...`);
let packagePath = await resolveConfig(fs, filepath, ['package.json']);
let cwd = packagePath ? path.dirname(packagePath) : fs.cwd();
if (!packageInstaller) {
packageInstaller = await determinePackageInstaller(fs, filepath);
}
try {
await packageInstaller.install({modules, saveDev, cwd, packagePath, fs});
} catch (err) {
throw new Error(`Failed to install ${modules.join(', ')}.`);
}
if (installPeers) {
await Promise.all(
modules.map(m => installPeerDependencies(fs, filepath, m, options)),
);