@tsplc/build 0.2.16 → 0.2.18
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.
- package/dist/cli.js +628 -352
- package/dist/cli.js.map +30 -28
- package/dist/index.js +548 -387
- package/dist/index.js.map +27 -25
- package/dist/libraries.js +68 -27
- package/dist/libraries.js.map +3 -3
- package/docker/Dockerfile +2 -0
- package/docker/Dockerfile.dockerignore +4 -1
- package/docker/Dockerfile.source +3 -0
- package/docker/config.ts +10 -5
- package/docker/runner.ts +140 -127
- package/package.json +54 -53
- package/python/build.py +183 -124
- package/python/codesys_online.py +44 -45
- package/python/hardware.py +9 -9
- package/python/test_build.py +3 -3
- package/python/test_codesys_online.py +18 -12
- package/python/test_installer_packages.py +1 -0
- package/python/worker.py +11 -7
- package/src/artifacts.ts +82 -60
- package/src/build.ts +71 -62
- package/src/cli.ts +109 -100
- package/src/controller-online.ts +400 -425
- package/src/controller-protocol.ts +140 -0
- package/src/controller-session.ts +466 -397
- package/src/device-tree.ts +19 -15
- package/src/diagnostics.ts +59 -49
- package/src/docker-build.ts +217 -156
- package/src/docker-context.ts +49 -27
- package/src/docker-run.ts +137 -111
- package/src/engineering-settings.ts +42 -0
- package/src/host/codesys-command.ts +35 -34
- package/src/host/codesys-host.ts +157 -129
- package/src/host/codesys-worker.ts +318 -301
- package/src/host/windows-path.ts +63 -59
- package/src/import-request.ts +24 -0
- package/src/index.ts +37 -31
- package/src/io.ts +152 -116
- package/src/libraries.ts +214 -146
- package/src/package-path.ts +3 -1
- package/src/run.ts +132 -108
- package/src/runtime-status.ts +25 -19
- package/src/sources.ts +264 -225
- package/src/st/declarations.ts +181 -193
- package/src/st/lexer.ts +102 -118
- package/src/st/parse.ts +193 -171
- package/src/st/reader.ts +47 -42
- package/src/__tests__/fixtures/xml/fb-simple.xml +0 -40
- package/src/__tests__/fixtures/xml/fb-state-machine.xml +0 -86
- package/src/__tests__/fixtures/xml/prg-cyclic.xml +0 -44
- package/src/config.ts +0 -12
package/src/device-tree.ts
CHANGED
|
@@ -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 "
|
|
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
|
-
|
|
10
|
-
|
|
9
|
+
deviceTree: NonNullable<ResolvedConfig["deviceTree"]>,
|
|
10
|
+
directory: string,
|
|
11
11
|
) => {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
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
|
};
|
package/src/diagnostics.ts
CHANGED
|
@@ -1,42 +1,44 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
2
|
|
|
3
3
|
export const compilerDiagnosticSchema = z
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
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<
|
|
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
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
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
|
-
|
|
48
|
-
|
|
49
|
-
|
|
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
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
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
|
}
|
package/src/docker-build.ts
CHANGED
|
@@ -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 {
|
|
5
|
+
import { z } from "zod";
|
|
7
6
|
import { readBuild } from "./artifacts";
|
|
8
|
-
import { dockerImage, type ResolvedConfig } from "
|
|
7
|
+
import { dockerImage, type ResolvedConfig } from "@tsplc/config/build";
|
|
9
8
|
import { prepareDockerContext } from "./docker-context.ts";
|
|
10
|
-
import {
|
|
11
|
-
|
|
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
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
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
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
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
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
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
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
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
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
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
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
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
|
};
|