Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
writeFileSync(lockfilePath, JSON.stringify(lockfile, null, 2))
} else if (options.packageManager === 'yarn') {
const lockfilePath = path.join(process.cwd(), 'yarn.lock')
if (!existsSync(lockfilePath)) {
console.info(`🤷 No yarn.lock found`) // eslint-disable-line no-console
return
}
console.info(`🔏 Updating yarn.lock`) // eslint-disable-line no-console
const lockfile = yarnLockfile.parse(readFileSync(lockfilePath, 'utf8'))
replaceRegistryPath(lockfile.object, new URL(options.registry))
writeFileSync(lockfilePath, yarnLockfile.stringify(lockfile, null, 2))
}
}
protected serialize(): string {
// abstract
return lockfile.stringify(this._shrinkwrapJson);
}
json[`${name}@${p.requestedVersion}`] = dedupedPackage.pkg;
})
} else {
// otherwise dedupe each package to its maxSatisfying version
packages.forEach(p => {
const targetVersion = semver.maxSatisfying(versions, p.requestedVersion);
if (targetVersion === null) return;
if (targetVersion !== p.pkg.version) {
const dedupedPackage = packages.find( p => p.pkg.version === targetVersion);
json[`${name}@${p.requestedVersion}`] = dedupedPackage.pkg;
}
})
}
});
return lockfile.stringify(json);
}
import { parse, stringify, FirstLevelDependency } from '@yarnpkg/lockfile';
function testFirstLevelDependency(obj: FirstLevelDependency) {}
const file = '';
const parseResult = parse(file);
const fileAgain = stringify(parseResult);
fileAgain.toLowerCase();
if (parseResult.type === 'merge' || parseResult.type === 'success') {
Object.keys(parseResult.object).forEach(k => {
const value = parseResult.object[k];
testFirstLevelDependency(value);
});
}
module.exports.fixDuplicates = (yarnLock, { includePackages = [], useMostCommon = false } = {}) => {
const json = parseYarnLock(yarnLock);
getDuplicatedPackages(json, { includePackages, useMostCommon }).forEach(
({ bestVersion, name, versions, requestedVersion }) => {
json[`${name}@${requestedVersion}`] = versions[bestVersion].pkg;
}
);
return lockfile.stringify(json);
};
sets.map(async ({dir, meta, lockfile}) => {
await exec(`mkdir -p ${dir}`);
await write(
`${dir}/package.json`,
`${JSON.stringify(meta, null, 2)}\n`,
'utf8'
);
await write(`${dir}/yarn.lock`, stringify(lockfile), 'utf8');
})
);