Skip to content

Commit 74d3a63

Browse files
authored
Merge pull request #92 from kingsword09/migrate-from-tsup-to-tsdown
refactor: Migrate from tsup to tsdown
2 parents 2d52fe6 + 1403fe3 commit 74d3a63

File tree

9 files changed

+17456
-20336
lines changed

9 files changed

+17456
-20336
lines changed

.github/workflows/ci.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ on:
55
pull_request:
66
merge_group:
77

8+
concurrency:
9+
group: ${{ github.workflow }}-${{ github.ref }}
10+
cancel-in-progress: true
11+
812
permissions: {}
913

1014
env:

dist/chunk1.js

Lines changed: 16881 additions & 19809 deletions
Large diffs are not rendered by default.

dist/main.js

Lines changed: 46 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -1,99 +1,63 @@
1-
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
1+
const require_utils = require('./chunk1.js');
22

3-
4-
5-
6-
7-
8-
9-
10-
var _chunk1js = require('./chunk1.js');
11-
12-
// src/main.ts
13-
var core2 = _chunk1js.__toESM.call(void 0, _chunk1js.require_core.call(void 0, ));
14-
15-
// src/registry_url.ts
16-
var core = _chunk1js.__toESM.call(void 0, _chunk1js.require_core.call(void 0, ));
3+
//#region src/registry_url.ts
4+
var import_core$1 = /* @__PURE__ */ require_utils.__toESM(require_utils.require_core());
175
function getAudienceFromUrl(url) {
18-
const audience = url.replace(/^https?:\/\//, "");
19-
if (audience.startsWith("http://") || audience.startsWith("https://")) {
20-
throw new Error(
21-
"Bug: The audience should not include the protocol (http:// or https://)."
22-
);
23-
}
24-
return audience;
6+
const audience = url.replace(/^https?:\/\//, "");
7+
if (audience.startsWith("http://") || audience.startsWith("https://")) throw new Error("Bug: The audience should not include the protocol (http:// or https://).");
8+
return audience;
259
}
2610
function getRegistryUrl() {
27-
const url = core.getInput("url") || "https://crates.io";
28-
if (url.endsWith("/")) {
29-
return url.slice(0, -1);
30-
}
31-
return url;
11+
const url = import_core$1.getInput("url") || "https://crates.io";
12+
if (url.endsWith("/")) return url.slice(0, -1);
13+
return url;
3214
}
3315

34-
// src/main.ts
35-
_chunk1js.runAction.call(void 0, run);
16+
//#endregion
17+
//#region src/main.ts
18+
var import_core = /* @__PURE__ */ require_utils.__toESM(require_utils.require_core());
19+
require_utils.runAction(run);
3620
async function run() {
37-
checkPermissions();
38-
const registryUrl = getRegistryUrl();
39-
const audience = getAudienceFromUrl(registryUrl);
40-
const jwtToken = await getJwtToken(audience);
41-
const token = await requestTrustedPublishingToken(registryUrl, jwtToken);
42-
setTokenOutput(token);
43-
core2.saveState(_chunk1js.TOKEN_KEY, token);
44-
core2.saveState(_chunk1js.REGISTRY_URL_KEY, registryUrl);
21+
checkPermissions();
22+
const registryUrl = getRegistryUrl();
23+
const token = await requestTrustedPublishingToken(registryUrl, await getJwtToken(getAudienceFromUrl(registryUrl)));
24+
setTokenOutput(token);
25+
import_core.saveState(require_utils.TOKEN_KEY, token);
26+
import_core.saveState(require_utils.REGISTRY_URL_KEY, registryUrl);
4527
}
28+
/** Check that GitHub Actions workflow permissions are set correctly. */
4629
function checkPermissions() {
47-
if (process.env.ACTIONS_ID_TOKEN_REQUEST_URL === void 0 || !process.env.ACTIONS_ID_TOKEN_REQUEST_URL) {
48-
throw new Error(
49-
"Please ensure the 'id-token' permission is set to 'write' in your workflow. For more information, see: https://docs.github.com/en/actions/security-for-github-actions/security-hardening-your-deployments/about-security-hardening-with-openid-connect#adding-permissions-settings"
50-
);
51-
}
30+
if (process.env.ACTIONS_ID_TOKEN_REQUEST_URL === void 0 || !process.env.ACTIONS_ID_TOKEN_REQUEST_URL) throw new Error("Please ensure the 'id-token' permission is set to 'write' in your workflow. For more information, see: https://docs.github.com/en/actions/security-for-github-actions/security-hardening-your-deployments/about-security-hardening-with-openid-connect#adding-permissions-settings");
5231
}
5332
async function getJwtToken(audience) {
54-
core2.info(`Retrieving GitHub Actions JWT token with audience: ${audience}`);
55-
const jwtToken = await core2.getIDToken(audience);
56-
if (!jwtToken) {
57-
throw new Error("Failed to retrieve JWT token from GitHub Actions");
58-
}
59-
core2.info("Retrieved JWT token successfully");
60-
return jwtToken;
33+
import_core.info(`Retrieving GitHub Actions JWT token with audience: ${audience}`);
34+
const jwtToken = await import_core.getIDToken(audience);
35+
if (!jwtToken) throw new Error("Failed to retrieve JWT token from GitHub Actions");
36+
import_core.info("Retrieved JWT token successfully");
37+
return jwtToken;
6138
}
6239
async function requestTrustedPublishingToken(registryUrl, jwtToken) {
63-
const tokenUrl = _chunk1js.getTokensEndpoint.call(void 0, registryUrl);
64-
const userAgent = _chunk1js.getUserAgent.call(void 0, );
65-
core2.info(
66-
`Requesting token from: ${tokenUrl}. User agent: ${userAgent["User-Agent"]}`
67-
);
68-
const response = await fetch(tokenUrl, {
69-
method: "POST",
70-
headers: {
71-
/* eslint-disable @typescript-eslint/naming-convention */
72-
"Content-Type": "application/json",
73-
...userAgent
74-
},
75-
body: JSON.stringify({ jwt: jwtToken })
76-
});
77-
if (!response.ok) {
78-
await _chunk1js.throwHttpErrorMessage.call(void 0,
79-
"Failed to retrieve token from Cargo registry",
80-
response
81-
);
82-
}
83-
const tokenResponse = await response.json();
84-
if (!tokenResponse.token) {
85-
await _chunk1js.throwHttpErrorMessage.call(void 0,
86-
"Failed to retrieve token from the Cargo registry response body",
87-
response
88-
);
89-
}
90-
core2.info("Retrieved token successfully");
91-
return tokenResponse.token;
40+
const tokenUrl = require_utils.getTokensEndpoint(registryUrl);
41+
const userAgent = require_utils.getUserAgent();
42+
import_core.info(`Requesting token from: ${tokenUrl}. User agent: ${userAgent["User-Agent"]}`);
43+
const response = await fetch(tokenUrl, {
44+
method: "POST",
45+
headers: {
46+
"Content-Type": "application/json",
47+
...userAgent
48+
},
49+
body: JSON.stringify({ jwt: jwtToken })
50+
});
51+
if (!response.ok) await require_utils.throwHttpErrorMessage("Failed to retrieve token from Cargo registry", response);
52+
const tokenResponse = await response.json();
53+
if (!tokenResponse.token) await require_utils.throwHttpErrorMessage("Failed to retrieve token from the Cargo registry response body", response);
54+
import_core.info("Retrieved token successfully");
55+
return tokenResponse.token;
9256
}
9357
function setTokenOutput(token) {
94-
core2.setSecret(token);
95-
core2.setOutput(_chunk1js.TOKEN_KEY, token);
58+
import_core.setSecret(token);
59+
import_core.setOutput(require_utils.TOKEN_KEY, token);
9660
}
9761

98-
99-
exports.run = run;
62+
//#endregion
63+
exports.run = run;

dist/post.js

Lines changed: 24 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,30 @@
1-
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
1+
const require_utils = require('./chunk1.js');
22

3-
4-
5-
6-
7-
8-
9-
10-
var _chunk1js = require('./chunk1.js');
11-
12-
// src/post.ts
13-
var core = _chunk1js.__toESM.call(void 0, _chunk1js.require_core.call(void 0, ));
14-
_chunk1js.runAction.call(void 0, cleanup);
3+
//#region src/post.ts
4+
var import_core = /* @__PURE__ */ require_utils.__toESM(require_utils.require_core());
5+
require_utils.runAction(cleanup);
156
async function cleanup() {
16-
const token = core.getState(_chunk1js.TOKEN_KEY);
17-
const registryUrl = core.getState(_chunk1js.REGISTRY_URL_KEY);
18-
if (!token) {
19-
core.info("No token to revoke");
20-
return;
21-
}
22-
await revokeToken(registryUrl, token);
7+
const token = import_core.getState(require_utils.TOKEN_KEY);
8+
const registryUrl = import_core.getState(require_utils.REGISTRY_URL_KEY);
9+
if (!token) {
10+
import_core.info("No token to revoke");
11+
return;
12+
}
13+
await revokeToken(registryUrl, token);
2314
}
2415
async function revokeToken(registryUrl, token) {
25-
const tokensEndpoint = _chunk1js.getTokensEndpoint.call(void 0, registryUrl);
26-
core.info(`Revoking trusted publishing token at ${tokensEndpoint}`);
27-
const response = await fetch(tokensEndpoint, {
28-
method: "DELETE",
29-
headers: {
30-
/* eslint-disable @typescript-eslint/naming-convention */
31-
Authorization: `Bearer ${token}`,
32-
..._chunk1js.getUserAgent.call(void 0, )
33-
}
34-
});
35-
if (!response.ok) {
36-
await _chunk1js.throwHttpErrorMessage.call(void 0, "Failed to revoke token", response);
37-
}
38-
core.info("Token revoked successfully");
16+
const tokensEndpoint = require_utils.getTokensEndpoint(registryUrl);
17+
import_core.info(`Revoking trusted publishing token at ${tokensEndpoint}`);
18+
const response = await fetch(tokensEndpoint, {
19+
method: "DELETE",
20+
headers: {
21+
Authorization: `Bearer ${token}`,
22+
...require_utils.getUserAgent()
23+
}
24+
});
25+
if (!response.ok) await require_utils.throwHttpErrorMessage("Failed to revoke token", response);
26+
import_core.info("Token revoked successfully");
3927
}
4028

41-
42-
exports.cleanup = cleanup;
29+
//#endregion
30+
exports.cleanup = cleanup;

eslint.config.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ export default defineConfig([
1313
...tseslint.configs.strict,
1414
...tseslint.configs.strictTypeChecked,
1515
{
16-
ignores: ["**/dist", "**/node_modules", "tsup.config.ts"],
16+
ignores: ["**/dist", "**/node_modules", "tsdown.config.ts"],
1717
},
1818
{
1919
files: ["src/**/*.ts", "*.mjs"],

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"description": "Get a temporary access token that you can use to interact with crates.io.",
55
"private": true,
66
"scripts": {
7-
"package": "tsup",
7+
"package": "tsdown",
88
"format": "prettier --write .",
99
"lint": "eslint",
1010
"test": "vitest"
@@ -28,8 +28,8 @@
2828
"globals": "^16.4.0",
2929
"msw": "^2.11.5",
3030
"prettier": "^3.6.2",
31+
"tsdown": "^0.15.10",
3132
"tslib": "^2.8.1",
32-
"tsup": "^8.5.0",
3333
"typescript": "^5.9.3",
3434
"typescript-eslint": "^8.46.1",
3535
"vitest": "^3.2.4"

0 commit comments

Comments
 (0)