Skip to content

Commit 3ae6536

Browse files
committed
Publish: check if token is set
1 parent fe6d1e7 commit 3ae6536

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

src/publish.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { execSync } from 'child_process';
22
import { appendFileSync, existsSync, readFileSync } from 'fs';
33
import { resolve } from 'path';
44
import { sendMessageToWebhook } from './webhooks.js';
5-
import { tryExecSync } from './utils.js';
5+
import { obfuscateToken, tryExecSync } from './utils.js';
66

77

88
/**
@@ -30,6 +30,11 @@ export async function publish(args) {
3030
logger.info(`Package: ${packageJson.name}@${packageJson.version}`);
3131
logger.info(`Build time: ${buildTime}`);
3232
logger.info(`Short SHA: ${shortSha}`);
33+
logger.info(`Token: '${obfuscateToken(args.accessToken)}'`);
34+
35+
if (!args.accessToken?.length) {
36+
logger.warn(`No access token provided. Publishing to registry ${args.registry} may fail.`);
37+
}
3338

3439
if (webhook) {
3540
await sendMessageToWebhook(webhook, `📦 Publishing package ${packageJson.name}@${packageJson.version} to registry ${args.registry} with tag ${args.tag || '-'}\nBuild time: ${buildTime}\nShort SHA: ${shortSha}\nRepository: ${repoUrl}`);

src/utils.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,13 @@ export function tryExecSync(cmd, options) {
1515
console.error(`Command failed: ${cmd}\n— Error: "${oneLineError}"`);
1616
return false;
1717
}
18+
}
19+
20+
/**
21+
* Obfuscates a token by replacing the middle characters with asterisks.
22+
* @param {string | null | undefined} token - The token to obfuscate.
23+
*/
24+
export function obfuscateToken(token) {
25+
if (!token) return '';
26+
return `${token.slice(0, 2)}***${token.slice(-2)}`;
1827
}

0 commit comments

Comments
 (0)