Skip to content

Commit f3bac46

Browse files
Merge pull request #90 from FrontEndDev-org/create-pull-request/patch
Changes by create-pull-request action
2 parents af5d7b1 + 5207782 commit f3bac46

File tree

1 file changed

+67
-63
lines changed

1 file changed

+67
-63
lines changed

dist/index.cjs

Lines changed: 67 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -27488,6 +27488,62 @@ function runCommand(command2, cwd = process.cwd()) {
2748827488
env: process.env
2748927489
});
2749027490
}
27491+
async function sync(name) {
27492+
const syncURL = `https://registry-direct.npmmirror.com/${name}/sync?sync_upstream=true`;
27493+
try {
27494+
core.debug(`PUT ${syncURL}`);
27495+
const resp = await fetch(syncURL, {
27496+
method: "PUT"
27497+
});
27498+
const json = await resp.json();
27499+
core.debug(`response status = ${resp.status}`);
27500+
core.debug(`response headers = ${resp.headers}`);
27501+
core.debug(`response json = ${json}`);
27502+
if (json && typeof json === "object" && json.ok && json.logId && typeof json.logId === "string") {
27503+
return json.logId;
27504+
}
27505+
core.debug("响应结果不匹配");
27506+
return "";
27507+
} catch (err) {
27508+
core.debug("请求或响应错误");
27509+
core.debug(String(err));
27510+
return "";
27511+
}
27512+
}
27513+
async function check(name, logId) {
27514+
try {
27515+
const checkURL = `https://registry-direct.npmmirror.com/${name}/sync/log/${logId}`;
27516+
core.debug(`GET ${checkURL}`);
27517+
const resp = await fetch(checkURL);
27518+
const json = await resp.json();
27519+
core.debug(`response status = ${resp.status}`);
27520+
core.debug(`response headers = ${resp.headers}`);
27521+
core.debug(`response json = ${JSON.stringify(json)}`);
27522+
if (json && typeof json === "object" && json.syncDone) return true;
27523+
core.debug(`响应结果不匹配`);
27524+
return false;
27525+
} catch (err) {
27526+
core.debug(`请求或响应错误`);
27527+
core.debug(String(err));
27528+
return false;
27529+
}
27530+
}
27531+
async function syncPackage(name, options) {
27532+
const logId = await sync(name);
27533+
if (!logId) {
27534+
core.error("检查失败:未查询到同步日志 ID");
27535+
return true;
27536+
}
27537+
const startCheckTime = Date.now();
27538+
let checked = false;
27539+
let times = 0;
27540+
while (!checked && Date.now() - startCheckTime < options.syncTimeout) {
27541+
times++;
27542+
core.info(`第 ${times} 次同步结果检查`);
27543+
checked = await check(name, logId);
27544+
await new Promise((resolve) => setTimeout(resolve, 1e3));
27545+
}
27546+
}
2749127547
function checkPackageExist(pkg) {
2749227548
try {
2749327549
const options = core.isDebug() ? "--verbose" : "";
@@ -27497,7 +27553,12 @@ function checkPackageExist(pkg) {
2749727553
return false;
2749827554
}
2749927555
}
27500-
function publishPackage(pkg, options) {
27556+
async function publishPackage(pkg, options) {
27557+
core.info(`publish package cwd: ${pkg.cwd}`);
27558+
core.info(`publish package name: ${pkg.name}`);
27559+
core.info(`publish package version: ${pkg.version}`);
27560+
core.info(`publish package tag: ${options.tag}`);
27561+
core.info(`publish package target: ${options.target}`);
2750127562
const npmrcFile = require$$0$9.resolve(".npmrc");
2750227563
const backupFile = npmrcFile + "-" + Date.now();
2750327564
const exists = fs$9.existsSync(npmrcFile);
@@ -27525,10 +27586,10 @@ function publishPackage(pkg, options) {
2752527586
}
2752627587
};
2752727588
const check2 = () => {
27528-
core.info(`checking package is exist`);
27589+
core.info(`checking package`);
2752927590
const isExist = checkPackageExist(pkg);
2753027591
if (isExist) {
27531-
core.info(`package is exists, skip publish`);
27592+
core.info(`${pkg.name}@${pkg.version} is exists, skip publish`);
2753227593
cleanup();
2753327594
return true;
2753427595
}
@@ -27554,61 +27615,9 @@ function publishPackage(pkg, options) {
2755427615
};
2755527616
if (check2()) return;
2755627617
publish();
27557-
}
27558-
async function sync(name) {
27559-
const syncURL = `https://registry-direct.npmmirror.com/${name}/sync?sync_upstream=true`;
27560-
try {
27561-
core.debug(`PUT ${syncURL}`);
27562-
const resp = await fetch(syncURL, {
27563-
method: "PUT"
27564-
});
27565-
const json = await resp.json();
27566-
core.debug(`response status = ${resp.status}`);
27567-
core.debug(`response headers = ${resp.headers}`);
27568-
core.debug(`response json = ${json}`);
27569-
if (json && typeof json === "object" && json.ok && json.logId && typeof json.logId === "string") {
27570-
return json.logId;
27571-
}
27572-
core.debug("响应结果不匹配");
27573-
return "";
27574-
} catch (err) {
27575-
core.debug("请求或响应错误");
27576-
core.debug(String(err));
27577-
return "";
27578-
}
27579-
}
27580-
async function check(name, logId) {
27581-
try {
27582-
const checkURL = `https://registry-direct.npmmirror.com/${name}/sync/log/${logId}`;
27583-
core.debug(`GET ${checkURL}`);
27584-
const resp = await fetch(checkURL);
27585-
const json = await resp.json();
27586-
core.debug(`response status = ${resp.status}`);
27587-
core.debug(`response headers = ${resp.headers}`);
27588-
core.debug(`response json = ${JSON.stringify(json)}`);
27589-
if (json && typeof json === "object" && json.syncDone) return true;
27590-
core.debug(`响应结果不匹配`);
27591-
return false;
27592-
} catch (err) {
27593-
core.debug(`请求或响应错误`);
27594-
core.debug(String(err));
27595-
return false;
27596-
}
27597-
}
27598-
async function syncPackage(name, options) {
27599-
const logId = await sync(name);
27600-
if (!logId) {
27601-
core.error("检查失败:未查询到同步日志 ID");
27602-
return true;
27603-
}
27604-
const startCheckTime = Date.now();
27605-
let checked = false;
27606-
let times = 0;
27607-
while (!checked && Date.now() - startCheckTime < options.syncTimeout) {
27608-
times++;
27609-
core.info(`第 ${times} 次同步结果检查`);
27610-
checked = await check(name, logId);
27611-
await new Promise((resolve) => setTimeout(resolve, 1e3));
27618+
if (options.target === "npm" && options.syncNpmmirror) {
27619+
core.info(`syncing package`);
27620+
await syncPackage(pkg.name, options);
2761227621
}
2761327622
}
2761427623
async function publishPackages(options) {
@@ -27651,7 +27660,6 @@ async function publishPackages(options) {
2765127660
fs$9.writeFileSync(pkgFile, JSON.stringify(pkg2), "utf-8");
2765227661
}
2765327662
try {
27654-
core.info(`publish package: ${pkgPath} ${pkg2.name}@${pkg2.version} as ${options.tag} to ${options.target}`);
2765527663
publishPackage(
2765627664
{
2765727665
cwd: require$$0$9.dirname(pkgFile),
@@ -27660,10 +27668,6 @@ async function publishPackages(options) {
2766027668
},
2766127669
options
2766227670
);
27663-
if (options.target === "npm" && options.syncNpmmirror) {
27664-
core.info(`sync package: ${pkgPath} ${pkg2.name}@${pkg2.version} to npmmirror.com`);
27665-
await syncPackage(pkg2.name, options);
27666-
}
2766727671
} finally {
2766827672
if (options.target === "github") {
2766927673
fs$9.writeFileSync(pkgPath, origin, "utf-8");

0 commit comments

Comments
 (0)