Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
if (
(name && json.name !== name)
|| (version && json.version !== version)
) {
try {
json.name = name || json.name;
json.version = version || json.version;
await writeFile$(pkgPath, JSON.stringify(json, null, ' '));
} catch (e) {
// Do nothing, just skip
}
}
try {
await publish$(
json,
createReadStream(tarPath), {
npmVersion: `${json.name}@${json.version}`,
...npm,
},
);
return res.status(204).end();
} catch (e) {
return res.status(400).json({
message: req.t('NPM_REGISTRY_ERROR', {
msg: e.message,
}),
});
}
};
const publish = async (directory) => {
const pkgName = childProcess.execSync(`npm pack`, { cwd: directory }).toString('utf-8').trim()
const pkg = require(path.join(directory, 'package.json'))
const pkgPath = path.join(directory, pkgName)
const tarball = fs.createReadStream(pkgPath)
if (process.env.DRY_RUN) {
log.debug(`${pkg.name}@${pkg.version} - ${pkgPath}`)
} else {
return npmPublish(pkg, tarball, { token: process.env.NPM_AUTH_TOKEN })
}
}