track-cli 3.0.0-rc → 3.0.0-rc3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,19 +1,20 @@
1
1
  import { Deno } from "@deno/shim-deno";
2
2
  export { Deno } from "@deno/shim-deno";
3
3
  export { crypto, type Crypto, type SubtleCrypto, type AlgorithmIdentifier, type Algorithm, type RsaOaepParams, type BufferSource, type AesCtrParams, type AesCbcParams, type AesGcmParams, type CryptoKey, type KeyAlgorithm, type KeyType, type KeyUsage, type EcdhKeyDeriveParams, type HkdfParams, type HashAlgorithmIdentifier, type Pbkdf2Params, type AesDerivedKeyParams, type HmacImportParams, type JsonWebKey, type RsaOtherPrimesInfo, type KeyFormat, type RsaHashedKeyGenParams, type RsaKeyGenParams, type BigInteger, type EcKeyGenParams, type NamedCurve, type CryptoKeyPair, type AesKeyGenParams, type HmacKeyGenParams, type RsaHashedImportParams, type EcKeyImportParams, type AesKeyAlgorithm, type RsaPssParams, type EcdsaParams } from "@deno/shim-crypto";
4
- export { alert, confirm, prompt } from "@deno/shim-prompts";
5
4
  import { fetch, File, FormData, Headers, Request, Response } from "undici";
6
5
  export { fetch, File, FormData, Headers, Request, Response, type BodyInit, type HeadersInit, type RequestInit, type ResponseInit } from "undici";
7
- export declare const dntGlobalThis: Omit<typeof globalThis, "alert" | "confirm" | "prompt" | "Deno" | "crypto" | "fetch" | "File" | "FormData" | "Headers" | "Request" | "Response"> & {
6
+ import { alert, confirm, prompt } from "./shim/prompts.js";
7
+ export { alert, confirm, prompt } from "./shim/prompts.js";
8
+ export declare const dntGlobalThis: Omit<typeof globalThis, "Deno" | "crypto" | "fetch" | "File" | "FormData" | "Headers" | "Request" | "Response" | "alert" | "confirm" | "prompt"> & {
8
9
  Deno: typeof Deno;
9
10
  crypto: import("@deno/shim-crypto").Crypto;
10
- alert: (message?: any) => void;
11
- confirm: (message?: string | undefined) => boolean;
12
- prompt: (message?: string | undefined, _default?: string | undefined) => string | null;
13
11
  fetch: typeof fetch;
14
12
  File: typeof File;
15
13
  FormData: typeof FormData;
16
14
  Headers: typeof Headers;
17
15
  Request: typeof Request;
18
16
  Response: typeof Response;
17
+ alert: typeof alert;
18
+ confirm: typeof confirm;
19
+ prompt: typeof prompt;
19
20
  };
package/esm/_dnt.shims.js CHANGED
@@ -2,22 +2,22 @@ import { Deno } from "@deno/shim-deno";
2
2
  export { Deno } from "@deno/shim-deno";
3
3
  import { crypto } from "@deno/shim-crypto";
4
4
  export { crypto } from "@deno/shim-crypto";
5
- import { alert, confirm, prompt } from "@deno/shim-prompts";
6
- export { alert, confirm, prompt } from "@deno/shim-prompts";
7
5
  import { fetch, File, FormData, Headers, Request, Response } from "undici";
8
6
  export { fetch, File, FormData, Headers, Request, Response } from "undici";
7
+ import { alert, confirm, prompt } from "./shim/prompts.js";
8
+ export { alert, confirm, prompt } from "./shim/prompts.js";
9
9
  const dntGlobals = {
10
10
  Deno,
11
11
  crypto,
12
- alert,
13
- confirm,
14
- prompt,
15
12
  fetch,
16
13
  File,
17
14
  FormData,
18
15
  Headers,
19
16
  Request,
20
17
  Response,
18
+ alert,
19
+ confirm,
20
+ prompt,
21
21
  };
22
22
  export const dntGlobalThis = createMergeProxy(globalThis, dntGlobals);
23
23
  // deno-lint-ignore ban-types
@@ -35,7 +35,7 @@ export declare class TableLayout {
35
35
  * original cell.
36
36
  */
37
37
  protected spanRows(rows: Array<IRow>): Row<Cell>[];
38
- protected getDeleteCount(rows: Array<Array<unknown>>, rowIndex: number, colIndex: number): 0 | 1;
38
+ protected getDeleteCount(rows: Array<Array<unknown>>, rowIndex: number, colIndex: number): 1 | 0;
39
39
  /**
40
40
  * Create a new row from existing row or cell array.
41
41
  * @param row Original row.
@@ -0,0 +1,3 @@
1
+ export function alert(message: any): void;
2
+ export function confirm(message: any): boolean;
3
+ export function prompt(message: any, defaultValue?: undefined): string | null;
@@ -0,0 +1,44 @@
1
+ // Temporary fixed version of shims for prompts
2
+ // See original version: https://github.com/denoland/node_shims/blob/main/packages/shim-prompts
3
+ import * as dntShim from "../_dnt.shims.js";
4
+ import { readSync, writeSync } from "fs";
5
+ export function alert(message) {
6
+ dntShim.dntGlobalThis.alert(message);
7
+ writeSync(process.stdout.fd, new TextEncoder().encode(`${message} [Enter] `));
8
+ readlineSync();
9
+ }
10
+ export function confirm(message) {
11
+ writeSync(process.stdout.fd, new TextEncoder().encode(`${message} [y/N] `));
12
+ const result = readlineSync();
13
+ return ["y", "Y"].includes(result);
14
+ }
15
+ export function prompt(message, defaultValue = undefined) {
16
+ writeSync(process.stdout.fd, new TextEncoder().encode(`${message} ${defaultValue == null ? "" : `[${defaultValue}]`} `));
17
+ const result = readlineSync();
18
+ return result.length > 0 ? result : defaultValue ?? null;
19
+ }
20
+ function readlineSync() {
21
+ let line = "";
22
+ let char = "";
23
+ const buf = Buffer.alloc(1);
24
+ while (char !== "\r" && char !== "\n") {
25
+ line += char;
26
+ try {
27
+ const bytesRead = readSync(process.stdin.fd, buf, 0, 1, null);
28
+ if (bytesRead === 0) {
29
+ return line;
30
+ }
31
+ }
32
+ catch (err) {
33
+ if (err.code === "EOF") {
34
+ return line;
35
+ }
36
+ continue;
37
+ }
38
+ char = String(buf);
39
+ }
40
+ if (char === "\r") {
41
+ readSync(process.stdin.fd, buf, 0, 1, null);
42
+ }
43
+ return line;
44
+ }
@@ -16,7 +16,7 @@ export async function lang() {
16
16
  const availableLanguages = (await api.getProgrammingLanguages())
17
17
  .filter((pl) => codingContext.programmingLanguages.find((n) => n === pl.value));
18
18
  console.log("Your existing code will be archived in this directory and the original challenge code for the new language will be downloaded");
19
- const shouldContinue = dntShim.confirm("Are you sure you want to continue? (y/n):");
19
+ const shouldContinue = dntShim.confirm("Are you sure you want to continue?");
20
20
  if (!shouldContinue) {
21
21
  return;
22
22
  }
package/esm/src/main.js CHANGED
@@ -27,8 +27,8 @@ import { Command } from "../deps/deno.land/x/cliffy@v0.25.7/command/mod.js";
27
27
  });
28
28
  });
29
29
  const runCommand = new Command()
30
- .description("Save and run the challenge on the remote code execution server")
31
- .option("--no-save", "If this flag is specified, your files will not be uploaded to track after running the challenge tests")
30
+ .description("Save and run the challenge on the remote code execution server.")
31
+ .option("--no-save", "If this flag is specified, your files will not be uploaded to track after running the challenge tests.")
32
32
  .action(async ({ save }) => {
33
33
  await runAction({ noSave: !save });
34
34
  });
@@ -38,30 +38,30 @@ import { Command } from "../deps/deno.land/x/cliffy@v0.25.7/command/mod.js";
38
38
  await langAction();
39
39
  });
40
40
  const resetCommand = new Command()
41
- .description("Reset the challenge files back to their starting point and archive your current challenge files")
41
+ .description("Reset the challenge files back to their starting point and archive your current challenge files.")
42
42
  .action(async () => {
43
43
  await resetAction();
44
44
  });
45
45
  const pullCommand = new Command()
46
- .description("Pull your most recent changes into this directory (caution: overwrites existing files)")
46
+ .description("Pull your most recent changes into this directory (caution: overwrites existing files).")
47
47
  .action(async () => {
48
48
  await pullAction();
49
49
  });
50
50
  const addCommand = new Command()
51
- .description("Add a file to be included in your challenge submission")
51
+ .description("Add a file to be included in your challenge submission.")
52
52
  .arguments("<file_paths...:string>")
53
53
  .action(async (_, ...filePaths) => {
54
54
  await addAction(filePaths);
55
55
  });
56
56
  const removeCommand = new Command()
57
- .description("Remove files from your challenge submission")
57
+ .description("Remove files from your challenge submission.")
58
58
  .arguments("<file_paths...:string>")
59
59
  .option("-r --recursive", "Allow recursive removal when a directory is given")
60
60
  .action(async ({ recursive }, ...filePaths) => {
61
61
  await removeAction(filePaths, { recursive });
62
62
  });
63
63
  const statusCommand = new Command()
64
- .description("Display the current status for this challenge")
64
+ .description("Display the current status for this challenge.")
65
65
  .action(async () => {
66
66
  await statusAction();
67
67
  });
package/esm/src/meta.d.ts CHANGED
@@ -1,3 +1,3 @@
1
- export declare const VERSION = "3.0.0-rc1";
1
+ export declare const VERSION = "3.0.0-rc3";
2
2
  export declare const DESCRIPTION = "A CLI for interacting with tracks.run and running code tests on track's servers";
3
3
  export declare function checkUpdates(): Promise<boolean>;
package/esm/src/meta.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import * as colors from "../deps/deno.land/std@0.195.0/fmt/colors.js";
2
2
  // @ts-ignore: has no exported member
3
3
  import { CookieJar, fetch } from "node-fetch-cookies";
4
- export const VERSION = "3.0.0-rc1";
4
+ export const VERSION = "3.0.0-rc3";
5
5
  export const DESCRIPTION = "A CLI for interacting with tracks.run and running code tests on track's servers";
6
6
  const VERSION_RE = /^(\d+)\.(\d+)\.(\d+)(?:-?(.*))$/;
7
7
  function parseSemver(s) {
@@ -3,7 +3,7 @@ import { OtherError } from "../shared/errors.js";
3
3
  import { SnakeCase } from "../shared/mod.js";
4
4
  import { green, red } from "../../deps/deno.land/std@0.195.0/fmt/colors.js";
5
5
  import { EventEmitter } from "eventemitter3";
6
- import ProxyAgent from "proxy-agent";
6
+ import { ProxyAgent } from "proxy-agent";
7
7
  import WebSocket from "ws";
8
8
  const RE_TAP_OK = new RegExp("^ok \\d+ ");
9
9
  const RE_TAP_NG = new RegExp("^not ok \\d+ ");
@@ -4,7 +4,8 @@ import { TrackClient } from "../track/client.js";
4
4
  import { ApplicantExamForNoAuth, ChallengeResult, ChallengeSettings, CodingContext, ExamSession, ExamSessionChallenge, FileListType, ProgrammingLanguageInfo } from "../track/types.js";
5
5
  import { CodingAnswers } from "../track/types.js";
6
6
  export declare const _internals: {
7
- prompt: (message?: string | undefined, _default?: string | undefined) => string | null;
7
+ prompt: typeof dntShim.prompt;
8
+ scoreRatio: typeof scoreRatio;
8
9
  };
9
10
  export declare const HttpStatus: {
10
11
  readonly OK: 200;
@@ -30,6 +31,7 @@ export declare const SnakeCase: {
30
31
  from<T_1>(obj: T_1): T_1;
31
32
  };
32
33
  export declare function getCommonChallengeContext(): Promise<TrackCLIContext>;
34
+ declare function scoreRatio(editorScore: number | undefined, openTestcases: number | undefined): string;
33
35
  export declare function printChallengeInfo(trackContext: TrackCLIContext): Promise<void>;
34
36
  export declare function printWorkingFileSet(codingContext: CodingContext): void;
35
37
  export declare function downloadChallengeFilesTo(codingContext: CodingContext, dest: string, api: TrackClient, applicantExamId: number, challengeResultId: number, showFileDiff: boolean, includeTarball: boolean): Promise<void>;
@@ -38,3 +40,4 @@ export type ArchiveExistingChallengeFilesOptions = {
38
40
  selectedLanguage?: ProgrammingLanguageInfo;
39
41
  };
40
42
  export declare function archiveExistingChallengeFiles(orgName: string, challengePosition: number, options?: ArchiveExistingChallengeFilesOptions): Promise<void>;
43
+ export {};
@@ -10,6 +10,7 @@ import { format as duration } from "../../deps/deno.land/std@0.195.0/fmt/duratio
10
10
  import * as fs from "../../deps/deno.land/std@0.195.0/fs/mod.js";
11
11
  export const _internals = {
12
12
  prompt: dntShim.prompt,
13
+ scoreRatio: scoreRatio,
13
14
  };
14
15
  export const HttpStatus = {
15
16
  OK: 200,
@@ -103,7 +104,7 @@ export async function tryStartingChallenge(challenge, api, applicantExam, result
103
104
  ? `The challenge will start after this point.\n${timeMsg}`
104
105
  : `The challenge will start after you select a programming language in the next step.\n${timeMsg}`;
105
106
  console.log(wariningMsg);
106
- const shouldContinue = dntShim.confirm("Do you want to continue? (y/n): ");
107
+ const shouldContinue = dntShim.confirm("Do you want to continue?");
107
108
  if (!shouldContinue) {
108
109
  throw new OtherError("Aborted. Challenge was not started.");
109
110
  }
@@ -295,6 +296,15 @@ function getResultFromExamSession(examSession, challengeId) {
295
296
  .results
296
297
  .find((cr) => cr.challengeId === challengeId);
297
298
  }
299
+ function scoreRatio(editorScore, openTestcases) {
300
+ // @ts-expect-error: isFinite(undefined) === false, isFinite(0) === true. See MDN
301
+ if (isFinite(editorScore) && openTestcases) {
302
+ return `\t${editorScore}/${openTestcases}`;
303
+ }
304
+ else {
305
+ return "\tN/A - Use 'track run' to save and run your submission";
306
+ }
307
+ }
298
308
  export async function printChallengeInfo(trackContext) {
299
309
  const { config, api, challengeResult: result } = trackContext;
300
310
  const timeLeft = await api.timeLeft(config.applicantExamId, config.challengeResultId);
@@ -303,11 +313,8 @@ export async function printChallengeInfo(trackContext) {
303
313
  const lastScoredAt = result.lastScoredAt
304
314
  ? ` (Ran at ${datetime.format(new Date(result.lastScoredAt), "yyyy-MM-dd HH:mm:ss")})`
305
315
  : "";
306
- const scoreRatio = (result.editorScore && trackContext.challenge.openTestcases)
307
- ? `\t${result.editorScore}/${trackContext.challenge.openTestcases}`
308
- : "\tN/A - Use 'track run' to save and run your submission";
309
316
  console.log(`Latest score${lastScoredAt}`);
310
- console.log(colors.green(scoreRatio));
317
+ console.log(colors.green(scoreRatio(result.editorScore, trackContext.challenge.openTestcases)));
311
318
  console.log();
312
319
  printTimeLeft(timeLeft);
313
320
  }
@@ -3,7 +3,7 @@ import { HttpStatus } from "../shared/mod.js";
3
3
  import { APIError, OtherError } from "../shared/errors.js";
4
4
  // @ts-ignore: has no exported member
5
5
  import { CookieJar, fetch } from "node-fetch-cookies";
6
- import ProxyAgent from "proxy-agent";
6
+ import { ProxyAgent } from "proxy-agent";
7
7
  export const FormType = {
8
8
  URLEncoded: "urlencoded",
9
9
  JSON: "json",
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "track": "./esm/src/main.js"
4
4
  },
5
5
  "name": "track-cli",
6
- "version": "3.0.0-rc",
6
+ "version": "3.0.0-rc3",
7
7
  "description": "A CLI for interacting with tracks.run and running code tests on track's servers",
8
8
  "license": "MIT",
9
9
  "repository": {
@@ -20,16 +20,15 @@
20
20
  "@hazae41/foras": "*",
21
21
  "eventemitter3": "5.0.1",
22
22
  "node-fetch-cookies": "2.0.4",
23
- "proxy-agent": "5.0.0",
23
+ "proxy-agent": "6.3.0",
24
24
  "tar": "*",
25
25
  "ws": "7.4.6",
26
26
  "@deno/shim-deno": "~0.16.1",
27
27
  "@deno/shim-crypto": "~0.3.1",
28
- "@deno/shim-prompts": "~0.1.0",
29
28
  "undici": "^5.21.0"
30
29
  },
31
30
  "devDependencies": {
32
31
  "@types/node": "^18.11.9",
33
32
  "picocolors": "^1.0.0"
34
33
  }
35
- }
34
+ }