Retry "npm publish" when to enter OTP is faeild (#11031)
* Retry "npm publish" when to enter OTP is faeild * Fix else * Break * Use async function * Update cspell.json * Address review * Update scripts/release/steps/publish-to-npm.js Co-authored-by: fisker Cheung <lionkay@gmail.com> * Update scripts/release/steps/publish-to-npm.js Co-authored-by: fisker Cheung <lionkay@gmail.com> Co-authored-by: fisker Cheung <lionkay@gmail.com>
This commit is contained in:
1 parent
4847f31abe
commit
321f736183
2 files changed
+24
-7
No files matched your search
@@ -108,6 +108,7 @@
|
|||||||
"elektronik",
|
"elektronik",
|
||||||
"Eneman",
|
"Eneman",
|
||||||
"ENOENT",
|
"ENOENT",
|
||||||
|
"EOTP",
|
||||||
"eqeqeq",
|
"eqeqeq",
|
||||||
"Ericsburgh",
|
"Ericsburgh",
|
||||||
"errored",
|
"errored",
|
||||||
|
|||||||
@@ -5,18 +5,34 @@ const { string: outdentString } = require("outdent");
|
|||||||
const execa = require("execa");
|
const execa = require("execa");
|
||||||
const { logPromise, waitForEnter } = require("../utils");
|
const { logPromise, waitForEnter } = require("../utils");
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retry "npm publish" when to enter OTP is failed.
|
||||||
|
*/
|
||||||
|
async function retryNpmPublish() {
|
||||||
|
const runNpmPublish = () =>
|
||||||
|
execa("npm", ["publish"], {
|
||||||
|
cwd: "./dist",
|
||||||
|
stdio: "inherit", // we need to input OTP if 2FA enabled
|
||||||
|
});
|
||||||
|
for (let i = 5; i > 0; i--) {
|
||||||
|
try {
|
||||||
|
return await runNpmPublish();
|
||||||
|
} catch (error) {
|
||||||
|
if (error.code === "EOTP" && i > 0) {
|
||||||
|
console.log(`To enter OTP is failed, you can retry it ${i} times.`);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
module.exports = async function ({ dry, version }) {
|
module.exports = async function ({ dry, version }) {
|
||||||
if (dry) {
|
if (dry) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
await logPromise(
|
await logPromise("Publishing to npm", retryNpmPublish());
|
||||||
"Publishing to npm",
|
|
||||||
execa("npm", ["publish"], {
|
|
||||||
cwd: "./dist",
|
|
||||||
stdio: "inherit", // we need to input OTP if 2FA enabled
|
|
||||||
})
|
|
||||||
);
|
|
||||||
|
|
||||||
console.log(
|
console.log(
|
||||||
outdentString(chalk`
|
outdentString(chalk`
|
||||||
|
|||||||
Reference in new issue
Block a user