@tsplc/compiler 0.5.8 → 0.5.10

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.
Files changed (40) hide show
  1. package/dist/bun-runtime.js +8 -2
  2. package/dist/bun-runtime.js.map +3 -3
  3. package/dist/cli.js +353 -58
  4. package/dist/cli.js.map +9 -7
  5. package/dist/codesys.js +1567 -1507
  6. package/dist/codesys.js.map +13 -13
  7. package/dist/index.js +818 -681
  8. package/dist/index.js.map +17 -16
  9. package/dist/ir.js +13 -42
  10. package/dist/ir.js.map +6 -5
  11. package/dist/telemetry.js +8 -2
  12. package/dist/telemetry.js.map +3 -3
  13. package/package.json +9 -9
  14. package/src/codesys/emit.ts +2 -1
  15. package/src/codesys/engineering.ts +27 -12
  16. package/src/codesys/plan.ts +9 -22
  17. package/src/codesys/programs.ts +61 -1
  18. package/src/codesys/types.ts +34 -12
  19. package/src/frontend/async.ts +14 -8
  20. package/src/frontend/coroutines.ts +55 -16
  21. package/src/frontend/elaborate/expressions.ts +10 -2
  22. package/src/frontend/elaborate/filtered-arrays.ts +5 -5
  23. package/src/frontend/elaborate/index.ts +26 -3
  24. package/src/frontend/elaborate/model.ts +48 -1
  25. package/src/frontend/elaborate/references.ts +6 -6
  26. package/src/frontend/elaborate/specialize.ts +18 -4
  27. package/src/frontend/elaborate/storage.ts +3 -2
  28. package/src/frontend/generated-names.ts +95 -0
  29. package/src/frontend/promise-chains.ts +22 -8
  30. package/src/frontend/promises.ts +8 -10
  31. package/src/frontend/tasks.ts +8 -8
  32. package/src/frontend/typescript.ts +2 -2
  33. package/src/ir/identity.ts +9 -0
  34. package/src/ir/index.ts +8 -2
  35. package/src/ir/job-errors.ts +14 -0
  36. package/src/ir/share.ts +0 -52
  37. package/src/project/cli.ts +14 -3
  38. package/src/project/deployments.ts +443 -0
  39. package/src/project/git.ts +35 -0
  40. package/src/project/plant.ts +68 -34
@@ -5,21 +5,31 @@ import {
5
5
  type Target,
6
6
  type Variable,
7
7
  } from "@tsplc/agent";
8
- import {
9
- type AgentClient,
10
- AgentOperationError,
11
- createAgentClient,
12
- } from "@tsplc/agent/client";
8
+ import { type AgentClient, createAgentClient } from "@tsplc/agent/client";
13
9
  import type { LoginCommand, LoginResult } from "@tsplc/build";
14
10
  import type { CompileEnvironment } from "@tsplc/compiler";
15
11
  import type { LoadedConfig } from "@tsplc/config";
16
12
  import { LoginUnavailable, noLogin } from "@tsplc/debug";
17
13
  import { z } from "zod";
14
+ import {
15
+ type Approval,
16
+ type Follow,
17
+ openDashboard,
18
+ printDeployments,
19
+ redeploy,
20
+ rollBack,
21
+ submitDeployment,
22
+ } from "./deployments";
23
+ import { gitSource } from "./git";
18
24
  import { prepareRelease } from "./release";
19
25
  import { choose, confirm, progress, timedProgress } from "./terminal";
20
26
 
21
27
  const plantCommands = [
22
28
  "deploy",
29
+ "deployments",
30
+ "rollback",
31
+ "redeploy",
32
+ "dashboard",
23
33
  "target",
24
34
  "status",
25
35
  "login",
@@ -41,6 +51,9 @@ export const plantCommand = (name: string) =>
41
51
 
42
52
  export interface PlantFlags {
43
53
  download?: boolean;
54
+ format?: "json" | "text";
55
+ review?: boolean;
56
+ wait?: boolean;
44
57
  "initialize-user"?: boolean;
45
58
  restore?: boolean;
46
59
  select?: boolean;
@@ -159,6 +172,7 @@ const deploy = async (
159
172
  loaded: LoadedConfig,
160
173
  flags: PlantFlags,
161
174
  environment: CompileEnvironment,
175
+ follow: Follow,
162
176
  ) => {
163
177
  const status = await agent.status();
164
178
  if (status.login) {
@@ -202,29 +216,21 @@ const deploy = async (
202
216
  };
203
217
  console.log(
204
218
  release.manifest.server
205
- ? "Deploying the server and the program…"
206
- : "Deploying the program…",
219
+ ? "Uploading the server and the program…"
220
+ : "Uploading the program…",
207
221
  );
208
- const deploying = timedProgress();
209
- deploying("Uploading");
210
- try {
211
- return await agent.deploy(release, settings, deploying);
212
- } catch (error) {
213
- if (
214
- !(error instanceof AgentOperationError && error.downloadRequired) ||
215
- !(await confirm(
216
- `${error.message}. A full download stops the running application while it loads. Download now?`,
217
- flags,
218
- ))
219
- ) {
220
- throw error;
221
- }
222
- return agent.deploy(
222
+ return {
223
+ exitCode: await submitDeployment(
224
+ agent,
223
225
  release,
224
- { ...settings, download: true },
225
- timedProgress(),
226
- );
227
- }
226
+ settings,
227
+ {
228
+ mode: flags.review ? "review" : "apply",
229
+ git: await gitSource(loaded.root),
230
+ },
231
+ follow,
232
+ ),
233
+ };
228
234
  };
229
235
 
230
236
  /** Opens a login when none is working; it stays open across commands until `tsplc logout`. */
@@ -346,7 +352,7 @@ const printLogin = (result: LoginResult) => {
346
352
 
347
353
  /**
348
354
  * Runs a command against the plant agent. Returns a deployment's compiler diagnostics when the
349
- * program doesn't compile.
355
+ * program doesn't compile, and the exit code of a command that queues a deployment.
350
356
  */
351
357
  export const runPlantCommand = async (
352
358
  agent: AgentClient,
@@ -358,8 +364,16 @@ export const runPlantCommand = async (
358
364
  load: () => Promise<LoadedConfig>;
359
365
  /** What the release's compilation reads. */
360
366
  environment: CompileEnvironment;
367
+ /** Someone at a terminal can answer prompts. */
368
+ interactive: boolean;
361
369
  },
362
370
  ) => {
371
+ const approval: Approval = {
372
+ yes: flags.yes ?? false,
373
+ interactive: project.interactive,
374
+ confirm: (question) => confirm(question, {}),
375
+ };
376
+ const follow = { wait: flags.wait ?? false, approval };
363
377
  const expect = (count: number, usage: string) => {
364
378
  if (args.length !== count) {
365
379
  throw new Error(`Usage: tsplc ${command} ${usage}`);
@@ -370,24 +384,44 @@ export const runPlantCommand = async (
370
384
  printLogin(await agent.command(loginCommand));
371
385
  };
372
386
  switch (command) {
373
- case "deploy": {
387
+ case "deploy":
374
388
  expect(
375
389
  0,
376
- "[--target name] [--download] [--select] [--initialize-user] [--simulate]",
390
+ "[--target name] [--download] [--select] [--initialize-user] [--simulate] [--review] [--wait] [-y]",
377
391
  );
378
- const deployed = await deploy(
392
+ return deploy(
379
393
  agent,
380
394
  project.file,
381
395
  await project.load(),
382
396
  flags,
383
397
  project.environment,
398
+ follow,
384
399
  );
385
- if ("diagnostics" in deployed) {
386
- return deployed;
400
+ case "deployments":
401
+ expect(0, "[--format json]");
402
+ return printDeployments(agent, flags);
403
+ case "rollback":
404
+ if (args.length > 1) {
405
+ throw new Error("Usage: tsplc rollback [id] [--wait] [-y]");
387
406
  }
388
- console.log(`Deployed release ${deployed.id} (${deployed.operation}).`);
389
- return;
407
+ return { exitCode: await rollBack(agent, args[0], follow) };
408
+ case "redeploy": {
409
+ const [id, ...extra] = args;
410
+ if (!id || extra.length) {
411
+ throw new Error("Usage: tsplc redeploy <id> [--review] [--wait] [-y]");
412
+ }
413
+ return {
414
+ exitCode: await redeploy(
415
+ agent,
416
+ id,
417
+ flags.review ? "review" : "apply",
418
+ follow,
419
+ ),
420
+ };
390
421
  }
422
+ case "dashboard":
423
+ expect(0, "");
424
+ return openDashboard(agent, project.interactive);
391
425
  case "target": {
392
426
  expect(0, "");
393
427
  const target = await selectTarget(agent);