Skip to content

Commit 757dfd8

Browse files
authored
chore: check user permissions to publish (#327)
1 parent 6060dd7 commit 757dfd8

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

scripts/publish-npm.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,32 @@ function markTaskAsDone(task, releaseDirPath) {
6767
fs.writeFileSync(taskDoneFilePath(task, releaseDirPath), '');
6868
}
6969

70+
function checkUserPermissionsToPublish() {
71+
const lerna = path.resolve(rootPath, 'node_modules', '.bin', 'lerna');
72+
73+
const userPackagesAccess = JSON.parse(execSync(`npm access ls-packages`).toString().trim())
74+
const lernaPackages = JSON.parse(execFileSync(lerna,
75+
['list', '--json', '--no-private', '--loglevel=error']).toString().trim());
76+
77+
const missingAccess = [];
78+
79+
for (const repo of lernaPackages) {
80+
if (userPackagesAccess[repo.name] !== 'read-write') {
81+
missingAccess.push(repo.name);
82+
}
83+
}
84+
85+
if (missingAccess.length) {
86+
throw new Error(
87+
`Required write access missing for the following packages: ${missingAccess.join(', ')}`
88+
);
89+
}
90+
}
91+
7092
async function publish() {
7193
const segmentApiKey = requireSegmentApiKey();
94+
checkUserPermissionsToPublish();
95+
7296
const remoteUrl = getGitRemoteUrl();
7397
const remoteHeadSha = getGitRemoteHeadSHA(remoteUrl);
7498
const releaseDirPath = path.resolve(rootPath, 'tmp', 'releases', remoteHeadSha);

0 commit comments

Comments
 (0)