Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
async persistManifest() {
const data = {};
this.manifest.exportTo(data);
const content = `${JSON.stringify(data, null, this.manifest.indent)}\n`;
await xfs.changeFilePromise(ppath.join(this.cwd, toFilename(`package.json`)), content);
}
}
async persistLockfile() {
const lockfilePath = ppath.join(this.cwd, this.configuration.get(`lockfileFilename`));
const lockfileContent = this.generateLockfile();
await xfs.changeFilePromise(lockfilePath, lockfileContent);
}
const addVSCodeWorkspaceSettings = async (projectRoot: PortablePath, settings: any) => {
const settingsPath = ppath.join(projectRoot, `.vscode/settings.json` as PortablePath);
const content = await xfs.existsPromise(settingsPath) ? await xfs.readFilePromise(settingsPath, `utf8`) : `{}`;
const data = json5.parse(content);
const patched = `${json5.stringify({...data, ...settings}, null, 2)}\n`;
await xfs.mkdirpPromise(ppath.dirname(settingsPath));
await xfs.changeFilePromise(settingsPath, patched);
};
return [structUtils.stringifyLocator(pkg), hash, name];
});
if (bstateData.length > 0) {
let bstateFile = `# Warning: This file is automatically generated. Removing it is fine, but will\n# cause all your builds to become invalidated.\n`;
for (const [locatorString, locatorHash, buildHash] of miscUtils.sortMap(bstateData, [d => d[0], d => d[1]])) {
bstateFile += `\n`;
bstateFile += `# ${locatorString}\n`;
bstateFile += `${JSON.stringify(locatorHash)}:\n`;
bstateFile += ` ${buildHash}\n`;
}
await xfs.mkdirpPromise(ppath.dirname(bstatePath));
await xfs.changeFilePromise(bstatePath, bstateFile);
} else {
await xfs.removePromise(bstatePath);
}
}
const pnpDataPath = this.opts.project.configuration.get(`pnpDataPath`);
const pnpSettings: PnpSettings = {
blacklistedLocations,
dependencyTreeRoots,
enableTopLevelFallback,
fallbackExclusionList,
ignorePattern,
packageRegistry,
shebang,
};
if (this.opts.project.configuration.get(`pnpEnableInlining`)) {
const loaderFile = generateInlinedScript(pnpSettings);
await xfs.changeFilePromise(pnpPath, loaderFile);
await xfs.chmodPromise(pnpPath, 0o755);
await xfs.removePromise(pnpDataPath);
} else {
const dataLocation = ppath.relative(ppath.dirname(pnpPath), pnpDataPath);
const {dataFile, loaderFile} = generateSplitScript({...pnpSettings, dataLocation});
await xfs.changeFilePromise(pnpPath, loaderFile);
await xfs.chmodPromise(pnpPath, 0o755);
await xfs.changeFilePromise(pnpDataPath, dataFile);
await xfs.chmodPromise(pnpDataPath, 0o644);
}
const pnpUnpluggedFolder = this.opts.project.configuration.get(`pnpUnpluggedFolder`);
if (this.unpluggedPaths.size === 0) {
const [left, right] = getVariants(file);
let parsedLeft;
let parsedRight;
try {
parsedLeft = parseSyml(left);
parsedRight = parseSyml(right);
} catch (error) {
throw new ReportError(MessageName.AUTOMERGE_FAILED_TO_PARSE, `The individual variants of the lockfile failed to parse`);
}
const merged = Object.assign({}, parsedLeft, parsedRight);
const serialized = stringifySyml(merged);
await xfs.changeFilePromise(lockfilePath, serialized);
return true;
}
const nextValue = typeof patch[key] === `function`
? patch[key](currentValue)
: patch[key];
if (currentValue === nextValue)
continue;
current[key] = nextValue;
patched = true;
}
if (!patched)
return;
await xfs.changeFilePromise(configurationPath, stringifySyml(current));
}
if (this.opts.project.configuration.get(`pnpEnableInlining`)) {
const loaderFile = generateInlinedScript(pnpSettings);
await xfs.changeFilePromise(pnpPath, loaderFile);
await xfs.chmodPromise(pnpPath, 0o755);
await xfs.removePromise(pnpDataPath);
} else {
const dataLocation = ppath.relative(ppath.dirname(pnpPath), pnpDataPath);
const {dataFile, loaderFile} = generateSplitScript({...pnpSettings, dataLocation});
await xfs.changeFilePromise(pnpPath, loaderFile);
await xfs.chmodPromise(pnpPath, 0o755);
await xfs.changeFilePromise(pnpDataPath, dataFile);
await xfs.chmodPromise(pnpDataPath, 0o644);
}
const pnpUnpluggedFolder = this.opts.project.configuration.get(`pnpUnpluggedFolder`);
if (this.unpluggedPaths.size === 0) {
await xfs.removePromise(pnpUnpluggedFolder);
} else {
for (const entry of await xfs.readdirPromise(pnpUnpluggedFolder)) {
const unpluggedPath = ppath.resolve(pnpUnpluggedFolder, entry);
if (!this.unpluggedPaths.has(unpluggedPath)) {
await xfs.removePromise(unpluggedPath);
}
}
}
}