Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
await Promise.all(deleteQueue);
await Promise.all(addQueue);
addQueue.length = 0;
// Second pass: clone module duplicates
for (const entry of addList) {
const copiedDstDir = persistedLocations.get(entry.srcDir);
if (entry.linkType !== LinkType.SOFT && entry.dstDir !== copiedDstDir) {
addQueue.push(cloneModule(copiedDstDir, entry.dstDir, {keepNodeModules: entry.keepNodeModules}));
}
}
await Promise.all(addQueue);
await xfs.mkdirpPromise(rootNmDirPath);
await writeLocatorState(locatorStatePath, locatorMap);
};
exports.writeFile = async function writeFile(target: PortablePath, body: string | Buffer): Promise {
await xfs.mkdirpPromise(ppath.dirname(target));
await xfs.writeFilePromise(target, body);
};
private async writeFileWithLock(file: PortablePath | null, generator: () => Promise) {
if (file === null)
return await generator();
await xfs.mkdirpPromise(ppath.dirname(file));
return await xfs.lockPromise(file, async () => {
return await generator();
});
}
}
}).then(async dirPath => {
dirPath = await xfs.realpathPromise(dirPath);
if (name) {
dirPath = ppath.join(dirPath, name);
await xfs.mkdirpPromise(dirPath);
}
return dirPath;
});
}
async executeRegular(configuration: Configuration) {
if (!xfs.existsSync(this.context.cwd))
await xfs.mkdirpPromise(this.context.cwd);
const manifest = new Manifest();
manifest.name = structUtils.makeIdent(configuration.get(`initScope`), ppath.basename(this.context.cwd));
manifest.version = configuration.get(`initVersion`);
manifest.private = this.private;
manifest.license = configuration.get(`initLicense`);
await updateAndSave(ppath.join(this.context.cwd, Manifest.fileName), (tracker: Object) => {
manifest.exportTo(tracker);
});
const inspectable: any = {};
manifest.exportTo(inspectable);
this.context.stdout.write(`${inspect(inspectable, {
depth: Infinity,
export async function setVersion(project: Project, bundleVersion: string, bundleBuffer: Buffer, {report}: {report: Report}) {
const relativePath = `.yarn/releases/yarn-${bundleVersion}.js` as PortablePath;
const absolutePath = ppath.resolve(project.cwd, relativePath);
report.reportInfo(MessageName.UNNAMED, `Saving the new release in ${project.configuration.format(relativePath, `magenta`)}`);
await xfs.mkdirpPromise(ppath.dirname(absolutePath));
await xfs.writeFilePromise(absolutePath, bundleBuffer);
await xfs.chmodPromise(absolutePath, 0o755);
await Configuration.updateConfiguration(project.cwd, {
yarnPath: relativePath,
});
}
async setup() {
if (!this.configuration.get(`enableGlobalCache`)) {
await xfs.mkdirpPromise(this.cwd);
const gitignorePath = ppath.resolve(this.cwd, toFilename(`.gitignore`));
const gitignoreExists = await xfs.existsPromise(gitignorePath);
if (!gitignoreExists) {
await xfs.writeFilePromise(gitignorePath, `/.gitignore\n*.lock\n`);
}
}
}
const cloneModule = async (srcDir: PortablePath, dstDir: PortablePath, options?: { keepNodeModules?: boolean, innerLoop?: boolean }) => {
try {
if (!options || !options.innerLoop) {
await removeDir(dstDir, {excludeNodeModules: options && options.keepNodeModules});
await xfs.mkdirpPromise(dstDir, {chmod: 0o777});
}
const entries = await xfs.readdirPromise(srcDir, {withFileTypes: true});
for (const entry of entries) {
const entryName = toFilename(entry.name);
const src = ppath.join(srcDir, entryName);
const dst = ppath.join(dstDir, entryName);
if (entryName !== NODE_MODULES || !options || !options.keepNodeModules) {
if (entry.isDirectory()) {
await xfs.mkdirPromise(dst);
await xfs.chmodPromise(dst, 0o777);
await cloneModule(src, dst, {keepNodeModules: false, innerLoop: true});
} else {
await xfs.copyFilePromise(src, dst, fs.constants.COPYFILE_FICLONE);
}
}
const promise: Promise = (async () => {
try {
await removeDir(dstDir, {excludeNodeModules: keepNodeModules});
if (linkType === LinkType.SOFT) {
await xfs.mkdirpPromise(ppath.dirname(dstDir));
await xfs.symlinkPromise(srcDir, dstDir);
} else {
const archivePath = getArchivePath(srcDir);
if (archivePath) {
const prefixInsideArchive = srcDir.substring(archivePath.length);
await xfs.createReadStream(archivePath)
.pipe(unzipper.Parse({concurrency: 8}))
.on('entry', (entry) => {
if (entry.path.length <= prefixInsideArchive.length) {
entry.autodrain();
} else {
const entryName = entry.path.substring(prefixInsideArchive.length);
const fullPath = ppath.join(dstDir, entryName);
if (entry.type === 'Directory') {
xfs.mkdirpSync(fullPath, {chmod: 0o777});
entry.autodrain();
async executeProxy(configuration: Configuration) {
if (configuration.get(`yarnPath`) !== null)
throw new UsageError(`Cannot use the --install flag when the current directory already uses yarnPath (from ${configuration.sources.get(`yarnPath`)})`);
if (configuration.projectCwd !== null)
throw new UsageError(`Cannot use the --install flag when the current directory is already part of a project`);
if (!xfs.existsSync(this.context.cwd))
await xfs.mkdirpPromise(this.context.cwd);
const lockfilePath = ppath.join(this.context.cwd, configuration.get(`lockfileFilename`));
if (!xfs.existsSync(lockfilePath))
await xfs.writeFilePromise(lockfilePath, ``);
const versionExitCode = await this.cli.run([`set`, `version`, this.install!]);
if (versionExitCode !== 0)
return versionExitCode;
this.context.stdout.write(`\n`);
const args: Array = [];
if (this.private)
args.push(`-p`);
if (this.yes)
args.push(`-y`);