@tsplc/build 0.2.17 → 0.2.19

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 (51) hide show
  1. package/dist/cli.js +628 -352
  2. package/dist/cli.js.map +30 -28
  3. package/dist/index.js +548 -387
  4. package/dist/index.js.map +27 -25
  5. package/dist/libraries.js +68 -27
  6. package/dist/libraries.js.map +3 -3
  7. package/docker/Dockerfile +2 -0
  8. package/docker/Dockerfile.dockerignore +4 -1
  9. package/docker/Dockerfile.source +3 -0
  10. package/docker/config.ts +10 -5
  11. package/docker/runner.ts +140 -127
  12. package/package.json +54 -53
  13. package/python/build.py +183 -124
  14. package/python/codesys_online.py +44 -45
  15. package/python/hardware.py +9 -9
  16. package/python/test_build.py +3 -3
  17. package/python/test_codesys_online.py +18 -12
  18. package/python/test_installer_packages.py +1 -0
  19. package/python/worker.py +11 -7
  20. package/src/artifacts.ts +82 -60
  21. package/src/build.ts +71 -62
  22. package/src/cli.ts +109 -100
  23. package/src/controller-online.ts +400 -425
  24. package/src/controller-protocol.ts +140 -0
  25. package/src/controller-session.ts +466 -397
  26. package/src/device-tree.ts +19 -15
  27. package/src/diagnostics.ts +59 -49
  28. package/src/docker-build.ts +217 -156
  29. package/src/docker-context.ts +49 -27
  30. package/src/docker-run.ts +137 -111
  31. package/src/engineering-settings.ts +42 -0
  32. package/src/host/codesys-command.ts +35 -34
  33. package/src/host/codesys-host.ts +157 -129
  34. package/src/host/codesys-worker.ts +318 -301
  35. package/src/host/windows-path.ts +63 -59
  36. package/src/import-request.ts +24 -0
  37. package/src/index.ts +37 -31
  38. package/src/io.ts +152 -116
  39. package/src/libraries.ts +214 -146
  40. package/src/package-path.ts +3 -1
  41. package/src/run.ts +132 -108
  42. package/src/runtime-status.ts +25 -19
  43. package/src/sources.ts +264 -225
  44. package/src/st/declarations.ts +181 -193
  45. package/src/st/lexer.ts +102 -118
  46. package/src/st/parse.ts +193 -171
  47. package/src/st/reader.ts +47 -42
  48. package/src/__tests__/fixtures/xml/fb-simple.xml +0 -40
  49. package/src/__tests__/fixtures/xml/fb-state-machine.xml +0 -86
  50. package/src/__tests__/fixtures/xml/prg-cyclic.xml +0 -44
  51. package/src/config.ts +0 -12
@@ -2,23 +2,27 @@ import { createHash } from "node:crypto";
2
2
  import { mkdir, writeFile } from "node:fs/promises";
3
3
  import { resolve } from "node:path";
4
4
  import { buildFiles } from "./artifacts";
5
- import type { ResolvedConfig } from "./config";
5
+ import type { ResolvedConfig } from "@tsplc/config/build";
6
6
 
7
7
  /** Writes each adapter's EDS into `directory`, where CODESYS imports it, and returns the tree the worker reads. */
8
8
  export const writeDeviceTree = async (
9
- deviceTree: NonNullable<ResolvedConfig["deviceTree"]>,
10
- directory: string,
9
+ deviceTree: NonNullable<ResolvedConfig["deviceTree"]>,
10
+ directory: string,
11
11
  ) => {
12
- await mkdir(resolve(directory, buildFiles.devices), { recursive: true });
13
- return {
14
- ...deviceTree,
15
- devices: await Promise.all(
16
- deviceTree.devices.map(async (device) => {
17
- const eds = `${buildFiles.devices}/${device.name}.eds`;
18
- await writeFile(resolve(directory, eds), device.eds);
19
- // The digest keys project reuse on the description's content.
20
- return { ...device, eds, sha256: createHash("sha256").update(device.eds).digest("hex") };
21
- }),
22
- ),
23
- };
12
+ await mkdir(resolve(directory, buildFiles.devices), { recursive: true });
13
+ return {
14
+ ...deviceTree,
15
+ devices: await Promise.all(
16
+ deviceTree.devices.map(async (device) => {
17
+ const eds = `${buildFiles.devices}/${device.name}.eds`;
18
+ await writeFile(resolve(directory, eds), device.eds);
19
+ // The digest keys project reuse on the description's content.
20
+ return {
21
+ ...device,
22
+ eds,
23
+ sha256: createHash("sha256").update(device.eds).digest("hex"),
24
+ };
25
+ }),
26
+ ),
27
+ };
24
28
  };
@@ -1,42 +1,44 @@
1
1
  import { z } from "zod";
2
2
 
3
3
  export const compilerDiagnosticSchema = z
4
- .object({
5
- category: z.string(),
6
- text: z.string(),
7
- severity: z.string().nullable(),
8
- project: z.string().nullable(),
9
- object: z
10
- .object({
11
- name: z.string(),
12
- guid: z.string(),
13
- path: z.array(z.string()),
14
- /** Verified against this message project's active application GUID. */
15
- isApplicationChild: z.boolean().nullable(),
16
- })
17
- .passthrough()
18
- .nullable(),
19
- /** Opaque vendor position. It must not be decoded as a line or column. */
20
- position: z.string().nullable(),
21
- positionText: z.string().nullable(),
22
- positionOffset: z.int().nullable(),
23
- length: z.int().nullable(),
24
- prefix: z.string().nullable(),
25
- number: z.int().nullable(),
26
- })
27
- .passthrough();
4
+ .object({
5
+ category: z.string(),
6
+ text: z.string(),
7
+ severity: z.string().nullable(),
8
+ project: z.string().nullable(),
9
+ object: z
10
+ .object({
11
+ name: z.string(),
12
+ guid: z.string(),
13
+ path: z.array(z.string()),
14
+ /** Verified against this message project's active application GUID. */
15
+ isApplicationChild: z.boolean().nullable(),
16
+ })
17
+ .passthrough()
18
+ .nullable(),
19
+ /** Opaque vendor position. It must not be decoded as a line or column. */
20
+ position: z.string().nullable(),
21
+ positionText: z.string().nullable(),
22
+ positionOffset: z.int().nullable(),
23
+ length: z.int().nullable(),
24
+ prefix: z.string().nullable(),
25
+ number: z.int().nullable(),
26
+ })
27
+ .passthrough();
28
28
 
29
- export type CodesysCompilerDiagnostic = z.infer<typeof compilerDiagnosticSchema>;
29
+ export type CodesysCompilerDiagnostic = z.infer<
30
+ typeof compilerDiagnosticSchema
31
+ >;
30
32
 
31
33
  /** Preserves vendor diagnostics as the cause of a buildProject failure. */
32
34
  export class CodesysCompilerError extends Error {
33
- constructor(
34
- message: string,
35
- readonly diagnostics: readonly CodesysCompilerDiagnostic[],
36
- ) {
37
- super(message);
38
- this.name = "CodesysCompilerError";
39
- }
35
+ constructor(
36
+ message: string,
37
+ readonly diagnostics: readonly CodesysCompilerDiagnostic[],
38
+ ) {
39
+ super(message);
40
+ this.name = "CodesysCompilerError";
41
+ }
40
42
  }
41
43
 
42
44
  // A failed container job publishes diagnostics separately from its successful build receipt.
@@ -44,25 +46,33 @@ export const buildFailureFile = ".codesys/docker/failure.json";
44
46
  /** Why the last download, online change or inspection failed, for the host to report. */
45
47
  export const controllerFailureFile = ".codesys/controller/failure.txt";
46
48
  export const buildFailureSchema = z.strictObject({
47
- operationId: z.uuid(),
48
- message: z.string(),
49
- diagnostics: z.array(compilerDiagnosticSchema),
49
+ operationId: z.uuid(),
50
+ message: z.string(),
51
+ diagnostics: z.array(compilerDiagnosticSchema),
50
52
  });
51
53
 
52
54
  /** Keep the primary compiler location and the shutdown context across the Docker boundary. */
53
55
  export function describeBuildFailure(cause: unknown) {
54
- const messages: string[] = [];
55
- let diagnostics: readonly CodesysCompilerDiagnostic[] = [];
56
- let current = cause;
57
- while (current instanceof Error) {
58
- messages.push(current.message);
59
- if (current instanceof AggregateError) {
60
- // withWorkerShutdown puts the primary failure in cause and secondary failures in errors.
61
- for (const secondary of current.errors.slice(1))
62
- messages.push(secondary instanceof Error ? secondary.message : String(secondary));
63
- }
64
- if (current instanceof CodesysCompilerError) diagnostics = current.diagnostics;
65
- current = current.cause;
66
- }
67
- return { message: messages.length ? messages.join("\n") : String(cause), diagnostics };
56
+ const messages: string[] = [];
57
+ let diagnostics: readonly CodesysCompilerDiagnostic[] = [];
58
+ let current = cause;
59
+ while (current instanceof Error) {
60
+ messages.push(current.message);
61
+ if (current instanceof AggregateError) {
62
+ // withWorkerShutdown puts the primary failure in cause and secondary failures in errors.
63
+ for (const secondary of current.errors.slice(1)) {
64
+ messages.push(
65
+ secondary instanceof Error ? secondary.message : String(secondary),
66
+ );
67
+ }
68
+ }
69
+ if (current instanceof CodesysCompilerError) {
70
+ diagnostics = current.diagnostics;
71
+ }
72
+ current = current.cause;
73
+ }
74
+ return {
75
+ message: messages.length ? messages.join("\n") : String(cause),
76
+ diagnostics,
77
+ };
68
78
  }
@@ -1,190 +1,251 @@
1
- import { execFile } from "node:child_process";
2
1
  import { randomUUID } from "node:crypto";
3
2
  import { cp, mkdir, mkdtemp, readFile, rm } from "node:fs/promises";
4
3
  import { tmpdir } from "node:os";
5
4
  import { resolve } from "node:path";
6
- import { promisify } from "node:util";
5
+ import { z } from "zod";
7
6
  import { readBuild } from "./artifacts";
8
- import { dockerImage, type ResolvedConfig } from "./config";
7
+ import { dockerImage, type ResolvedConfig } from "@tsplc/config/build";
9
8
  import { prepareDockerContext } from "./docker-context.ts";
10
- import { buildFailureFile, buildFailureSchema, CodesysCompilerError } from "./diagnostics.ts";
11
- import { prepareContainerRun, runDocker } from "./docker-run.ts";
9
+ import {
10
+ buildFailureFile,
11
+ buildFailureSchema,
12
+ CodesysCompilerError,
13
+ } from "./diagnostics.ts";
14
+ import { captureDocker, prepareContainerRun, runDocker } from "./docker-run.ts";
12
15
  import { packageDirectory } from "./package-path.ts";
13
16
 
14
- const execute = promisify(execFile);
15
-
16
17
  /** Each tsPLC version's images, published so that setup pulls them instead of installing CODESYS. */
17
18
  export const publishedImage = async (image: string) => {
18
- const { version } = JSON.parse(
19
- await readFile(resolve(packageDirectory, "package.json"), "utf8"),
20
- ) as { version: string };
21
- return `ghcr.io/livingforjesus/${image.split(":")[0]}:${version}`;
19
+ const { version } = z
20
+ .object({ version: z.string() })
21
+ .parse(
22
+ JSON.parse(
23
+ await readFile(resolve(packageDirectory, "package.json"), "utf8"),
24
+ ),
25
+ );
26
+ return `ghcr.io/livingforjesus/${image.split(":")[0]}:${version}`;
22
27
  };
23
28
 
24
29
  /** Pulls this version's published `image`; false when it isn't available, so the caller builds it. */
25
30
  const pullPublished = async (image: string) => {
26
- const published = await publishedImage(image);
27
- console.log(`Pulling ${published}`);
28
- try {
29
- await runDocker(
30
- ["pull", "--platform", "linux/amd64", published],
31
- (status) => `Docker pull failed (${status})`,
32
- );
33
- } catch {
34
- console.log(`${published} is not available; building ${image} locally instead.`);
35
- return false;
36
- }
37
- await runDocker(["tag", published, image], (status) => `Docker tag failed (${status})`);
38
- return true;
31
+ const published = await publishedImage(image);
32
+ console.log(`Pulling ${published}`);
33
+ try {
34
+ await runDocker(
35
+ ["pull", "--platform", "linux/amd64", published],
36
+ (status) => `Docker pull failed (${status})`,
37
+ );
38
+ } catch {
39
+ console.log(
40
+ `${published} is not available; building ${image} locally instead.`,
41
+ );
42
+ return false;
43
+ }
44
+ await runDocker(
45
+ ["tag", published, image],
46
+ (status) => `Docker tag failed (${status})`,
47
+ );
48
+ return true;
39
49
  };
40
50
 
41
51
  /** Install the IDE and its prerequisites in the Docker builder image. */
42
52
  export const configureDocker = async () => {
43
- const image = dockerImage;
44
- const { stdout } = await execute(
45
- "docker",
46
- ["info", "--format", "{{.OSType}}/{{.Architecture}}"],
47
- { timeout: 30_000 },
48
- ).catch((cause: unknown) => {
49
- throw new Error("Cannot connect to Docker. Install and start Docker Desktop or Docker Engine", {
50
- cause,
51
- });
52
- });
53
- const architecture = stdout.trim();
54
- const arm = architecture === "linux/aarch64" || architecture === "linux/arm64";
55
- if (!arm && architecture !== "linux/x86_64" && architecture !== "linux/amd64") {
56
- throw new Error("The builder requires a Linux Docker server on ARM64 or AMD64");
57
- }
58
- if (await pullPublished(image)) return image;
59
- const context = await mkdtemp(resolve(tmpdir(), "codesys-installer-"));
60
- let buildContext: string | undefined;
61
- try {
62
- buildContext = await prepareDockerContext();
63
- const cache = resolve(context, "winetricks");
64
- await mkdir(cache);
65
- if (process.env["CODESYS_WINETRICKS_CACHE"]) {
66
- await cp(process.env["CODESYS_WINETRICKS_CACHE"], cache, {
67
- recursive: true,
68
- });
69
- }
70
- console.log(
71
- `Preparing Docker builder (${image}). Downloading and installing CODESYS 3.5.22.30 and prerequisites.`,
72
- );
73
- await runDocker(
74
- [
75
- "build",
76
- "--platform",
77
- "linux/amd64",
78
- "--build-arg",
79
- `SETUP_BASE=${arm ? "arm-setup" : "base"}`,
80
- "--build-arg",
81
- `SETUP_PLATFORM=${arm ? "linux/arm64" : "linux/amd64"}`,
82
- "--build-arg",
83
- "INSTALLER_SOURCE=installer-download",
84
- "--progress",
85
- "plain",
86
- "--build-context",
87
- `installer=${context}`,
88
- "-f",
89
- resolve(buildContext, "docker/Dockerfile"),
90
- "-t",
91
- image,
92
- buildContext,
93
- ],
94
- (status) =>
95
- `Docker configuration failed (${status}). Review the image-build output and run tsplc configure again`,
96
- );
97
- return image;
98
- } finally {
99
- await Promise.all([
100
- rm(context, { recursive: true, force: true }),
101
- ...(buildContext ? [rm(buildContext, { recursive: true, force: true })] : []),
102
- ]);
103
- }
53
+ const image = dockerImage;
54
+ const { stdout } = await captureDocker(
55
+ ["info", "--format", "{{.OSType}}/{{.Architecture}}"],
56
+ 30_000,
57
+ ).catch((cause: unknown) => {
58
+ throw new Error(
59
+ "Cannot connect to Docker. Install and start Docker Desktop or Docker Engine",
60
+ {
61
+ cause,
62
+ },
63
+ );
64
+ });
65
+ const architecture = stdout.trim();
66
+ const arm =
67
+ architecture === "linux/aarch64" || architecture === "linux/arm64";
68
+ if (
69
+ !arm &&
70
+ architecture !== "linux/x86_64" &&
71
+ architecture !== "linux/amd64"
72
+ ) {
73
+ throw new Error(
74
+ "The builder requires a Linux Docker server on ARM64 or AMD64",
75
+ );
76
+ }
77
+ if (await pullPublished(image)) {
78
+ return image;
79
+ }
80
+ const context = await mkdtemp(resolve(tmpdir(), "codesys-installer-"));
81
+ let buildContext: string | undefined;
82
+ try {
83
+ buildContext = await prepareDockerContext();
84
+ const cache = resolve(context, "winetricks");
85
+ await mkdir(cache);
86
+ if (process.env["CODESYS_WINETRICKS_CACHE"]) {
87
+ await cp(process.env["CODESYS_WINETRICKS_CACHE"], cache, {
88
+ recursive: true,
89
+ });
90
+ }
91
+ console.log(
92
+ `Preparing Docker builder (${image}). Downloading and installing CODESYS 3.5.22.30 and prerequisites.`,
93
+ );
94
+ await runDocker(
95
+ [
96
+ "build",
97
+ "--platform",
98
+ "linux/amd64",
99
+ "--build-arg",
100
+ `SETUP_BASE=${arm ? "arm-setup" : "base"}`,
101
+ "--build-arg",
102
+ `SETUP_PLATFORM=${arm ? "linux/arm64" : "linux/amd64"}`,
103
+ "--build-arg",
104
+ "INSTALLER_SOURCE=installer-download",
105
+ "--progress",
106
+ "plain",
107
+ "--build-context",
108
+ `installer=${context}`,
109
+ "-f",
110
+ resolve(buildContext, "docker/Dockerfile"),
111
+ "-t",
112
+ image,
113
+ buildContext,
114
+ ],
115
+ (status) =>
116
+ `Docker configuration failed (${status}). Review the image-build output and run tsplc configure again`,
117
+ );
118
+ return image;
119
+ } finally {
120
+ await Promise.all([
121
+ rm(context, { recursive: true, force: true }),
122
+ ...(buildContext
123
+ ? [rm(buildContext, { recursive: true, force: true })]
124
+ : []),
125
+ ]);
126
+ }
104
127
  };
105
128
 
106
129
  export const runtimeImage = "tsplc-control-linux-sl:4.22.0.0";
107
130
 
108
131
  /** Build the local CODESYS Control for Linux SL runtime, the same device as a production build. */
109
132
  export const configureRuntime = async () => {
110
- const context = resolve(packageDirectory, "docker/control-linux-sl");
111
- console.log(`Preparing the local PLC runtime (${runtimeImage}).`);
112
- await runDocker(
113
- ["build", "--platform", "linux/amd64", "--progress", "plain", "-t", runtimeImage, context],
114
- (status) => `Runtime image build failed (${status}). Review the image-build output`,
115
- );
116
- return runtimeImage;
133
+ const context = resolve(packageDirectory, "docker/control-linux-sl");
134
+ console.log(`Preparing the local PLC runtime (${runtimeImage}).`);
135
+ await runDocker(
136
+ [
137
+ "build",
138
+ "--platform",
139
+ "linux/amd64",
140
+ "--progress",
141
+ "plain",
142
+ "-t",
143
+ runtimeImage,
144
+ context,
145
+ ],
146
+ (status) =>
147
+ `Runtime image build failed (${status}). Review the image-build output`,
148
+ );
149
+ return runtimeImage;
117
150
  };
118
151
 
119
152
  export const gatewayImage = "tsplc-edge-gateway:4.22.0.0";
120
153
 
121
154
  /** Build the CODESYS Edge Gateway that builder containers reach a plant controller through. */
122
155
  export const configureGateway = async () => {
123
- if (await pullPublished(gatewayImage)) return gatewayImage;
124
- const context = resolve(packageDirectory, "docker/edge-gateway");
125
- console.log(`Preparing the CODESYS gateway (${gatewayImage}).`);
126
- await runDocker(
127
- ["build", "--platform", "linux/amd64", "--progress", "plain", "-t", gatewayImage, context],
128
- (status) => `Gateway image build failed (${status}). Review the image-build output`,
129
- );
130
- return gatewayImage;
156
+ if (await pullPublished(gatewayImage)) {
157
+ return gatewayImage;
158
+ }
159
+ const context = resolve(packageDirectory, "docker/edge-gateway");
160
+ console.log(`Preparing the CODESYS gateway (${gatewayImage}).`);
161
+ await runDocker(
162
+ [
163
+ "build",
164
+ "--platform",
165
+ "linux/amd64",
166
+ "--progress",
167
+ "plain",
168
+ "-t",
169
+ gatewayImage,
170
+ context,
171
+ ],
172
+ (status) =>
173
+ `Gateway image build failed (${status}). Review the image-build output`,
174
+ );
175
+ return gatewayImage;
131
176
  };
132
177
 
133
178
  export const buildInDocker = async (config: ResolvedConfig, image: string) => {
134
- const requestDirectory = await mkdtemp(resolve(tmpdir(), "codesys-docker-"));
135
- try {
136
- const operationId = randomUUID();
137
- await mkdir(config.outDir, { recursive: true });
138
- const failurePath = resolve(config.outDir, buildFailureFile);
139
- await rm(failurePath, { force: true });
140
- const args = [
141
- "run",
142
- "--rm",
143
- ...(await prepareContainerRun(config, requestDirectory, { network: "none", sources: true })),
144
- image,
145
- "--request",
146
- "/input/config.json",
147
- "--operation-id",
148
- operationId,
149
- ];
150
- console.log(`Building with Docker (${image})`);
151
- try {
152
- await runDocker(
153
- args,
154
- (status) =>
155
- `Docker build failed (${status}). Run tsplc configure if the image is missing; inspect ${config.outDir}/.codesys/docker for compiler logs`,
156
- );
157
- } catch (cause) {
158
- const message = cause instanceof Error ? cause.message : String(cause);
159
- const failure = await readFile(failurePath, "utf8")
160
- .then((text) => buildFailureSchema.parse(JSON.parse(text)))
161
- .catch((error: unknown) => {
162
- if (error instanceof Error && "code" in error && error.code === "ENOENT") return;
163
- throw new AggregateError(
164
- [cause, error],
165
- `${message}. Invalid CODESYS failure metadata (${failurePath})`,
166
- { cause: error },
167
- );
168
- });
169
- if (!failure) throw cause;
170
- if (failure.operationId !== operationId)
171
- throw new Error(
172
- `${message}. CODESYS failure metadata belongs to a different Docker build`,
173
- {
174
- cause,
175
- },
176
- );
177
- if (cause instanceof Error) {
178
- // The mapper keeps ordinary error messages as notes, while vendor
179
- // diagnostics supply their own text. Preserve shutdown context there.
180
- cause.message = `${message}\n${failure.message}`;
181
- if (failure.diagnostics.length)
182
- cause.cause = new CodesysCompilerError(failure.message, failure.diagnostics);
183
- }
184
- throw cause;
185
- }
186
- return await readBuild(config.outDir);
187
- } finally {
188
- await rm(requestDirectory, { recursive: true, force: true });
189
- }
179
+ const requestDirectory = await mkdtemp(resolve(tmpdir(), "codesys-docker-"));
180
+ try {
181
+ const operationId = randomUUID();
182
+ await mkdir(config.outDir, { recursive: true });
183
+ const failurePath = resolve(config.outDir, buildFailureFile);
184
+ await rm(failurePath, { force: true });
185
+ const args = [
186
+ "run",
187
+ "--rm",
188
+ ...(await prepareContainerRun(config, requestDirectory, {
189
+ network: "none",
190
+ sources: true,
191
+ })),
192
+ image,
193
+ "--request",
194
+ "/input/config.json",
195
+ "--operation-id",
196
+ operationId,
197
+ ];
198
+ console.log(`Building with Docker (${image})`);
199
+ try {
200
+ await runDocker(
201
+ args,
202
+ (status) =>
203
+ `Docker build failed (${status}). Run tsplc configure if the image is missing; inspect ${config.outDir}/.codesys/docker for compiler logs`,
204
+ );
205
+ } catch (cause) {
206
+ const message = cause instanceof Error ? cause.message : String(cause);
207
+ const failure = await readFile(failurePath, "utf8")
208
+ .then((text) => buildFailureSchema.parse(JSON.parse(text)))
209
+ .catch((error: unknown) => {
210
+ if (
211
+ error instanceof Error &&
212
+ "code" in error &&
213
+ error.code === "ENOENT"
214
+ ) {
215
+ return;
216
+ }
217
+ throw new AggregateError(
218
+ [cause, error],
219
+ `${message}. Invalid CODESYS failure metadata (${failurePath})`,
220
+ { cause: error },
221
+ );
222
+ });
223
+ if (!failure) {
224
+ throw cause;
225
+ }
226
+ if (failure.operationId !== operationId) {
227
+ throw new Error(
228
+ `${message}. CODESYS failure metadata belongs to a different Docker build`,
229
+ {
230
+ cause,
231
+ },
232
+ );
233
+ }
234
+ if (cause instanceof Error) {
235
+ // The mapper keeps ordinary error messages as notes, while vendor
236
+ // diagnostics supply their own text. Preserve shutdown context there.
237
+ cause.message = `${message}\n${failure.message}`;
238
+ if (failure.diagnostics.length) {
239
+ cause.cause = new CodesysCompilerError(
240
+ failure.message,
241
+ failure.diagnostics,
242
+ );
243
+ }
244
+ }
245
+ throw cause;
246
+ }
247
+ return await readBuild(config.outDir);
248
+ } finally {
249
+ await rm(requestDirectory, { recursive: true, force: true });
250
+ }
190
251
  };