Skip to content

Commit 03ff947

Browse files
author
雅影
committed
fix: fix publish error situation
1. local tag existing 2. remote tag existing 3. package version existing 4. stop publish while error happen
1 parent 7bef5af commit 03ff947

2 files changed

Lines changed: 49 additions & 49 deletions

File tree

src/built-in-plugins/command-publish/plugin/run-publish.ts

Lines changed: 37 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -217,54 +217,48 @@ async function publishPackageAndItsMonoPackage(
217217
});
218218
}
219219

220-
// async publish queue & add tag and push
221-
const publishQueue = depMonoPackages.map(item => {
222-
return new Promise(async resolve => {
223-
await buildComponent(item);
224-
225-
if (options.bundle) {
226-
await commandBundle({ skipLint: true });
227-
}
228-
229-
await moveSourceFilesToTempFolderAndPublish(
230-
item.name,
231-
options,
232-
item.config,
233-
item.rootPath,
234-
depMap,
235-
isDevelopBranch,
236-
);
237-
238-
await addTagAndPush(generateTag(item.name, item.packageJson), item.packageJson);
239-
resolve();
220+
try {
221+
const publishQueue = [];
222+
// async publish & add tag and push
223+
depMonoPackages.map(item => {
224+
publishQueue.push(buildComponentAndPublish(item, options, depMap, isDevelopBranch));
240225
});
241-
});
242226

243-
// push current package into publishQueue
244-
publishQueue.push(
245-
new Promise(async resolve => {
246-
await buildComponent(targetPackageInfo);
227+
// publish current package
228+
publishQueue.push(buildComponentAndPublish(targetPackageInfo, options, depMap, isDevelopBranch));
247229

248-
if (options.bundle) {
249-
await commandBundle({ skipLint: true });
250-
}
251-
252-
await moveSourceFilesToTempFolderAndPublish(
253-
sourceType,
254-
options,
255-
targetConfig,
256-
targetRoot,
257-
depMap,
258-
isDevelopBranch,
259-
);
230+
return Promise.all(publishQueue);
231+
} catch (e) {
232+
logInfo(`publish error ${e} stop publish`);
233+
await fs.remove(path.join(pri.projectRootPath, tempPath.dir, declarationPath.dir));
234+
await exec(`git push origin ${currentBranchName}`);
235+
return process.exit(0);
236+
}
237+
}
260238

261-
await addTagAndPush(generateTag(sourceType, targetPackageJson), targetPackageJson);
239+
async function buildComponentAndPublish(
240+
packageInfo: PackageInfo,
241+
options: PublishOption,
242+
depMap: DepMap,
243+
isDevelopBranch: boolean,
244+
) {
245+
return new Promise(async resolve => {
246+
await buildComponent(packageInfo);
262247

263-
resolve();
264-
}),
265-
);
248+
if (options.bundle) {
249+
await commandBundle({ skipLint: true });
250+
}
266251

267-
await spinner(`Publish`, async () => {
268-
await Promise.all(publishQueue);
252+
await moveSourceFilesToTempFolderAndPublish(
253+
packageInfo.name,
254+
options,
255+
packageInfo.config,
256+
packageInfo.rootPath,
257+
depMap,
258+
isDevelopBranch,
259+
);
260+
261+
await addTagAndPush(generateTag(packageInfo.name, packageInfo.packageJson), packageInfo.packageJson);
262+
resolve();
269263
});
270264
}

src/built-in-plugins/command-publish/plugin/utils.ts

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -61,12 +61,9 @@ export async function checkEnvBeforePublish(targetPackageJson: Partial<PackageJs
6161
}
6262

6363
export async function addTagAndPush(tagName: string, targetPackageJson: Partial<PackageJson>) {
64-
await spinner(`Add tag`, async () => {
65-
await exec(`git tag -a ${tagName} -m "release"`);
66-
});
67-
68-
await spinner(`Push tag`, async () => {
69-
await exec(`git push origin ${tagName}`);
64+
await spinner(`Add and push tag`, async () => {
65+
await exec(`git tag -a ${tagName} -m "release" -f`);
66+
await exec(`git push origin ${tagName} -f`);
7067
});
7168

7269
logText(`+ ${targetPackageJson.name}@${targetPackageJson.version}`);
@@ -115,6 +112,15 @@ export async function generateVersion(
115112
'prerelease',
116113
currentBranchName.replace(/\//g, '').replace(/\./g, ''),
117114
);
115+
let checkBetaVersionResult;
116+
version = targetPackageJson.version;
117+
// check the package verion and if it existing auto increase it
118+
do {
119+
version = (semver.inc as any)(version, 'prerelease', currentBranchName.replace(/\//g, '').replace(/\./g, ''));
120+
checkBetaVersionResult = execSync(`${targetConfig.npmClient} view ${targetPackageJson.name}@${version} version`)
121+
.toString()
122+
.trim();
123+
} while (checkBetaVersionResult);
118124
} else if (versionResult) {
119125
if (!options.semver) {
120126
const versionPrompt = await inquirer.prompt([

0 commit comments

Comments
 (0)