Skip to content

Commit 07b31a3

Browse files
committed
Restore the TypeScript sources
1 parent 21a00a6 commit 07b31a3

File tree

7 files changed

+40
-46
lines changed

7 files changed

+40
-46
lines changed

etc/eslint.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ export default ts.config(
7979
"no-implicit-globals": "error",
8080
"no-implied-eval": "error",
8181
"no-inline-comments": "off",
82-
"no-invalid-this": "error",
82+
"no-invalid-this": "off",
8383
"no-iterator": "error",
8484
"no-label-var": "error",
8585
"no-labels": "error",

gulpfile.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,20 @@ import {readFile, writeFile} from "node:fs/promises";
22
import {env} from "node:process";
33
import {deleteAsync} from "del";
44
import esbuild from "esbuild";
5-
import {$} from "execa";
5+
import {execa} from "execa";
66
import gulp from "gulp";
77
import pkg from "./package.json" with {type: "json"};
88

9+
// Runs a command.
10+
const $ = execa({preferLocal: true, stdio: "inherit"});
11+
12+
// Builds the project.
913
export async function build() {
1014
await $`tsc --project src`;
1115
return esbuild.build({
1216
banner: {js: "#!/usr/bin/env node"},
1317
bundle: true,
14-
entryPoints: ["src/cli.js"],
18+
entryPoints: ["src/cli.ts"],
1519
legalComments: "none",
1620
minify: true,
1721
outfile: "bin/setup_ant.cjs",

src/cli.js renamed to src/cli.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ import {Setup} from "./setup.js";
44

55
/**
66
* Application entry point.
7-
* @returns {Promise<void>} Resolves when Apache Ant has been installed.
7+
* @returns Resolves when Apache Ant has been installed.
88
*/
9-
async function main() {
9+
async function main(): Promise<void> {
1010
const version = getInput("version");
1111
const release = Release.find(!version || version == "latest" ? "*" : version);
1212
if (!release) throw Error("No release matching the version constraint.");
@@ -18,4 +18,4 @@ async function main() {
1818
}
1919

2020
// Start the application.
21-
main().catch(error => setFailed(error instanceof Error ? error : String(error)));
21+
main().catch((error: unknown) => setFailed(error instanceof Error ? error : String(error)));

src/data.js renamed to src/data.ts

File renamed without changes.
File renamed without changes.

src/release.js renamed to src/release.ts

Lines changed: 14 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -8,72 +8,63 @@ export class Release {
88

99
/**
1010
* The base URL of the releases.
11-
* @type {URL}
12-
* @readonly
1311
*/
14-
static #baseUrl = new URL("https://dlcdn.apache.org/ant/binaries/");
12+
static readonly #baseUrl = new URL("https://dlcdn.apache.org/ant/binaries/");
1513

1614
/**
1715
* The list of all releases.
18-
* @type {Release[]}
19-
* @readonly
2016
*/
21-
static #data = data.map(release => new this(release.version));
17+
static readonly #data: Release[] = data.map(release => new this(release.version));
2218

2319
/**
2420
* The version number.
25-
* @type {string}
26-
* @readonly
2721
*/
28-
version;
22+
readonly version: string;
2923

3024
/**
3125
* Creates a new release.
32-
* @param {string} version The version number.
26+
* @param version The version number.
3327
*/
34-
constructor(version) {
28+
constructor(version: string) {
3529
this.version = version;
3630
}
3731

3832
/**
3933
* The latest release.
40-
* @type {Release}
4134
*/
42-
static get latest() {
35+
static get latest(): Release {
4336
return this.#data[0];
4437
}
4538

4639
/**
4740
* Value indicating whether this release exists.
48-
* @type {boolean}
4941
*/
50-
get exists() {
42+
get exists(): boolean {
5143
return Release.#data.some(release => release.version == this.version);
5244
}
5345

5446
/**
5547
* The download URL.
56-
* @type {URL}
5748
*/
58-
get url() {
49+
get url(): URL {
5950
return new URL(`apache-ant-${this.version}-bin.zip`, Release.#baseUrl);
6051
}
6152

6253
/**
6354
* Finds a release that matches the specified version constraint.
64-
* @param {string} constraint The version constraint.
65-
* @returns {Release|null} The release corresponding to the specified constraint.
55+
* @param constraint The version constraint.
56+
* @returns The release corresponding to the specified constraint.
6657
*/
67-
static find(constraint) {
58+
static find(constraint: string): Release|null {
6859
return this.#data.find(release => semver.satisfies(release.version, constraint)) ?? null;
6960
}
7061

7162
/**
7263
* Gets the release corresponding to the specified version.
73-
* @param {string} version The version number of a release.
74-
* @returns {Release|null} The release corresponding to the specified version.
64+
* @param version The version number of a release.
65+
* @returns The release corresponding to the specified version.
7566
*/
76-
static get(version) {
67+
static get(version: string): Release|null {
7768
return this.#data.find(release => release.version == version) ?? null;
7869
}
7970
}

src/setup.js renamed to src/setup.ts

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import {join} from "node:path";
44
import {promisify} from "node:util";
55
import {addPath, exportVariable} from "@actions/core";
66
import {cacheDir, downloadTool, extractZip, find} from "@actions/tool-cache";
7+
import type {Release} from "./release.js";
78

89
/**
910
* Manages the download and installation of Apache Ant.
@@ -12,25 +13,23 @@ export class Setup {
1213

1314
/**
1415
* The release to download and install.
15-
* @type {import("./release.js").Release}
16-
* @readonly
1716
*/
18-
release;
17+
readonly release: Release;
1918

2019
/**
2120
* Creates a new setup.
22-
* @param {import("./release.js").Release} release The release to download and install.
21+
* @param release The release to download and install.
2322
*/
24-
constructor(release) {
23+
constructor(release: Release) {
2524
this.release = release;
2625
}
2726

2827
/**
2928
* Downloads and extracts the ZIP archive of Apache Ant.
30-
* @param {Partial<{optionalTasks: boolean}>} options Value indicating whether to fetch the Ant optional tasks.
31-
* @returns {Promise<string>} The path to the extracted directory.
29+
* @param options Value indicating whether to fetch the Ant optional tasks.
30+
* @returns The path to the extracted directory.
3231
*/
33-
async download(options = {}) {
32+
async download(options: Partial<{optionalTasks: boolean}> = {}): Promise<string> {
3433
const path = await extractZip(await downloadTool(this.release.url.href));
3534
const directory = join(path, await this.#findSubfolder(path));
3635
if (options.optionalTasks) await this.#fetchOptionalTasks(directory);
@@ -39,10 +38,10 @@ export class Setup {
3938

4039
/**
4140
* Installs Apache Ant, after downloading it if required.
42-
* @param {Partial<{optionalTasks: boolean}>} options Value indicating whether to fetch the Ant optional tasks.
43-
* @returns Promise<string> The path to the installation directory.
41+
* @param options Value indicating whether to fetch the Ant optional tasks.
42+
* @returns The path to the installation directory.
4443
*/
45-
async install(options = {}) {
44+
async install(options: Partial<{optionalTasks: boolean}> = {}): Promise<string> {
4645
let directory = find("ant", this.release.version);
4746
if (!directory) {
4847
const path = await this.download(options);
@@ -56,19 +55,19 @@ export class Setup {
5655

5756
/**
5857
* Fetches the external libraries required by Ant optional tasks.
59-
* @param {string} antHome The path to the Ant directory.
60-
* @returns {Promise<unknown>} Resolves when the optional tasks have been fetched.
58+
* @param antHome The path to the Ant directory.
59+
* @returns Resolves when the optional tasks have been fetched.
6160
*/
62-
#fetchOptionalTasks(antHome) {
61+
#fetchOptionalTasks(antHome: string): Promise<unknown> {
6362
return promisify(exec)("ant -buildfile fetch.xml -noinput -silent -Ddest=system", {cwd: antHome, env: {ANT_HOME: antHome}});
6463
}
6564

6665
/**
6766
* Determines the name of the single subfolder in the specified directory.
68-
* @param {string} directory The directory path.
69-
* @returns {Promise<string>} The name of the single subfolder in the specified directory.
67+
* @param directory The directory path.
68+
* @returns The name of the single subfolder in the specified directory.
7069
*/
71-
async #findSubfolder(directory) {
70+
async #findSubfolder(directory: string): Promise<string> {
7271
const folders = (await readdir(directory, {withFileTypes: true})).filter(entity => entity.isDirectory());
7372
switch (folders.length) {
7473
case 0: throw Error(`No subfolder found in: ${directory}.`);

0 commit comments

Comments
 (0)