@tsplc/build 0.5.2 → 0.5.4

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/docker/runner.ts CHANGED
@@ -18,12 +18,12 @@ import {
18
18
  buildFailureFile,
19
19
  controllerFailureFile,
20
20
  describeBuildFailure,
21
- } from "../src/diagnostics.ts";
21
+ } from "../src/diagnostics";
22
22
  import {
23
23
  createCodesysWorker,
24
24
  withWorkerShutdown,
25
25
  } from "../src/host/codesys-worker";
26
- import { resolveContainerConfig } from "./config.ts";
26
+ import { resolveContainerConfig } from "./config";
27
27
 
28
28
  const operations = [
29
29
  "build",
package/package.json CHANGED
@@ -15,7 +15,7 @@
15
15
  "url": "git+https://github.com/rip-technologies/tsplc.git",
16
16
  "directory": "packages/build"
17
17
  },
18
- "version": "0.5.2",
18
+ "version": "0.5.4",
19
19
  "type": "module",
20
20
  "exports": {
21
21
  ".": {
@@ -54,9 +54,9 @@
54
54
  },
55
55
  "dependencies": {
56
56
  "zod": "4.3.6",
57
- "@tsplc/config": "0.5.2",
58
- "@tsplc/typegen": "0.5.2",
59
- "@tsplc/iec": "0.5.2"
57
+ "@tsplc/config": "0.5.4",
58
+ "@tsplc/typegen": "0.5.4",
59
+ "@tsplc/iec": "0.5.4"
60
60
  },
61
61
  "bin": {
62
62
  "tsplc-build": "./dist/cli.js"
@@ -5,8 +5,8 @@ import io
5
5
  import json
6
6
  import os
7
7
  import re
8
- from build import (clear_diagnostics, fail_on_errors, import_source, keep_device_tree, open_template,
9
- reported_errors, write_progress)
8
+ from build import (CompilerError, clear_diagnostics, fail_on_errors, import_source, keep_device_tree,
9
+ open_template, reported_errors, write_progress)
10
10
  from hardware import update_device_tree, verify_pinned
11
11
  from System import Activator, AppDomain, Array, Enum, Environment, Object
12
12
  from System.Net import Dns, IPAddress
@@ -22,6 +22,17 @@ TERMINAL_ESCAPE = re.compile(r'\x1b\[[0-?]*[ -/]*[@-~]')
22
22
  # What CODESYS answers when the controller's runtime rejects the application it is sent, as Control
23
23
  # for Linux SL 4.22 does while a task of the old application it stopped can't be deleted.
24
24
  RUNTIME_REFUSAL = 'Invalid result package'
25
+ # What CODESYS reports as an error when a project still holding the controller's downloaded reference
26
+ # can't be applied as an online change: advice to perform a full download.
27
+ NO_ONLINE_CHANGE = 'No online change possible'
28
+
29
+
30
+ def fail_on_download_errors(engine):
31
+ """A full download is what CODESYS's no-online-change advice asks for, so that advice alone
32
+ doesn't stop one; every other error still does."""
33
+ errors = [error for error in reported_errors(engine) if not error['text'].startswith(NO_ONLINE_CHANGE)]
34
+ if errors:
35
+ raise CompilerError(errors)
25
36
 
26
37
 
27
38
  def download_required(message):
@@ -507,16 +518,17 @@ def run_online(engine, request, log, prepared=None, keep=None):
507
518
  # saved once the controller has it; a failed transfer discards it.
508
519
  progress('Rebuilding application for full download')
509
520
  application.rebuild()
510
- fail_on_errors(engine)
521
+ fail_on_download_errors(engine)
511
522
  progress('Generating application code')
512
523
  application.generate_code()
513
524
  verify_pinned(pinned)
525
+ fail_on_download_errors(engine)
514
526
  else:
515
527
  # Cleaning would discard the downloaded reference needed to decide
516
528
  # whether a source edit can be applied as an online change.
517
529
  progress('Building application incrementally for online change')
518
530
  application.build()
519
- fail_on_errors(engine)
531
+ fail_on_errors(engine)
520
532
  if request['operation'] == 'download':
521
533
  online_app = engine.online.create_online_application(application)
522
534
  core = core_application(online_app)
package/src/build.ts CHANGED
@@ -12,9 +12,9 @@ import type { ResolvedConfig } from "@tsplc/config/build";
12
12
  import { buildFiles, publishBuild, readBuild } from "./artifacts";
13
13
  import { writeDeviceTree } from "./device-tree";
14
14
  import { buildInDocker } from "./docker-build";
15
- import type { ProgressOptions } from "./docker-run.ts";
15
+ import type { ProgressOptions } from "./docker-run";
16
16
  import { createCodesysWorker, withWorkerLock } from "./host/codesys-worker";
17
- import { builderImage } from "./images.ts";
17
+ import { builderImage } from "./images";
18
18
  import { importRequest } from "./import-request";
19
19
  import { loadSources } from "./sources";
20
20
 
@@ -1,8 +1,8 @@
1
1
  import { isDeepStrictEqual } from "node:util";
2
2
  import { z } from "zod";
3
- import { builderRecipe, containerManifest } from "./docker-context.ts";
4
- import { captureDocker } from "./docker-run.ts";
5
- import { builderImage, recipeLabel } from "./images.ts";
3
+ import { builderRecipe, containerManifest } from "./docker-context";
4
+ import { captureDocker } from "./docker-run";
5
+ import { builderImage, recipeLabel } from "./images";
6
6
 
7
7
  /** Where the image's recipe wrote the manifest of the third-party packages it installed. */
8
8
  const imageManifest = "/opt/codesys-build/package.json";
package/src/cli.ts CHANGED
@@ -2,16 +2,16 @@
2
2
  import { parseArgs } from "node:util";
3
3
  import { loadTsplcConfig } from "@tsplc/config";
4
4
  import { z } from "zod";
5
- import { buildProject } from "./build.ts";
6
- import { updateController } from "./controller-online.ts";
7
- import { configureDocker, configureRuntime } from "./docker-build.ts";
8
- import { rawEngineeringSettings } from "./engineering-settings.ts";
9
- import { installLibraries } from "./libraries.ts";
5
+ import { buildProject } from "./build";
6
+ import { updateController } from "./controller-online";
7
+ import { configureDocker, configureRuntime } from "./docker-build";
8
+ import { rawEngineeringSettings } from "./engineering-settings";
9
+ import { installLibraries } from "./libraries";
10
10
  import {
11
11
  checkRawSources,
12
12
  inspectProjectController,
13
- } from "./project-operations.ts";
14
- import { runProject } from "./run.ts";
13
+ } from "./project-operations";
14
+ import { runProject } from "./run";
15
15
 
16
16
  const commandSchema = z.enum([
17
17
  "configure",
@@ -25,10 +25,10 @@ import {
25
25
  tracebackFailure,
26
26
  transferRollback,
27
27
  type warmOperationSchema,
28
- } from "./controller-protocol.ts";
29
- import { controllerDirectory, jobProgressLog } from "./controller-session.ts";
30
- import { controllerFailureFile } from "./diagnostics.ts";
31
- import { containerCodeDigest } from "./docker-context.ts";
28
+ } from "./controller-protocol";
29
+ import { controllerDirectory, jobProgressLog } from "./controller-session";
30
+ import { controllerFailureFile } from "./diagnostics";
31
+ import { containerCodeDigest } from "./docker-context";
32
32
  import {
33
33
  type ContainerEnvironment,
34
34
  captureDocker,
@@ -37,8 +37,8 @@ import {
37
37
  prepareContainerRun,
38
38
  runDocker,
39
39
  writeOperationRequest,
40
- } from "./docker-run.ts";
41
- import { builderImage } from "./images.ts";
40
+ } from "./docker-run";
41
+ import { builderImage } from "./images";
42
42
 
43
43
  /** Where an operation reads the controller user's environment variables from; this process's environment by default. */
44
44
  export interface CredentialSource {
@@ -3,14 +3,13 @@ import { mkdir, mkdtemp, readFile, rm } from "node:fs/promises";
3
3
  import { tmpdir } from "node:os";
4
4
  import { resolve } from "node:path";
5
5
  import type { ResolvedConfig } from "@tsplc/config/build";
6
- import { z } from "zod";
7
6
  import { readBuild } from "./artifacts";
8
- import { builderImageStatus, setupReason } from "./builder-image.ts";
7
+ import { builderImageStatus, setupReason } from "./builder-image";
9
8
  import {
10
9
  buildFailureFile,
11
10
  buildFailureSchema,
12
11
  CodesysCompilerError,
13
- } from "./diagnostics.ts";
12
+ } from "./diagnostics";
14
13
  import {
15
14
  captureDocker,
16
15
  type ProgressOptions,
@@ -18,31 +17,24 @@ import {
18
17
  prepareContainerRun,
19
18
  progressLog,
20
19
  runDocker,
21
- } from "./docker-run.ts";
20
+ } from "./docker-run";
22
21
  import {
23
22
  buildBuilderImage,
24
23
  builderImage,
25
24
  buildGatewayImage,
26
25
  buildRuntimeImage,
27
26
  gatewayImage,
27
+ publishedBuilderImage,
28
28
  publishedImage,
29
29
  runtimeImage,
30
30
  setupPlatformFor,
31
- } from "./images.ts";
32
- import { packageDirectory } from "./package-path.ts";
31
+ } from "./images";
33
32
 
34
- const packageVersion = async () =>
35
- z
36
- .object({ version: z.string() })
37
- .parse(
38
- JSON.parse(
39
- await readFile(resolve(packageDirectory, "package.json"), "utf8"),
40
- ),
41
- ).version;
42
-
43
- /** Pulls this version's published `image`; false when it isn't available, so the caller builds it. */
44
- const pullPublished = async (image: string, progress: ProgressStream) => {
45
- const published = publishedImage(image, await packageVersion());
33
+ /** Pulls `published` and tags it as the local `image`; false when it isn't available, so the caller builds it. */
34
+ const pullPublished = async (
35
+ { image, published }: { image: string; published: string },
36
+ progress: ProgressStream,
37
+ ) => {
46
38
  const output = { progress, environment: {} };
47
39
  progressLog(progress)(`Pulling ${published}`);
48
40
  try {
@@ -108,7 +100,10 @@ export const configureDocker = async ({
108
100
  `Rebuilding the Docker builder: ${status.kind === "unverified" ? status.reason : setupReason(status)}.`,
109
101
  );
110
102
  if (
111
- (await pullPublished(image, progress)) &&
103
+ (await pullPublished(
104
+ { image, published: await publishedBuilderImage() },
105
+ progress,
106
+ )) &&
112
107
  (await builderImageStatus(image)).kind === "current"
113
108
  ) {
114
109
  return image;
@@ -165,7 +160,12 @@ export const configureGateway = async ({
165
160
  progressLog(progress)(`The CODESYS gateway (${gatewayImage}) is present.`);
166
161
  return gatewayImage;
167
162
  }
168
- if (await pullPublished(gatewayImage, progress)) {
163
+ if (
164
+ await pullPublished(
165
+ { image: gatewayImage, published: publishedImage(gatewayImage) },
166
+ progress,
167
+ )
168
+ ) {
169
169
  return gatewayImage;
170
170
  }
171
171
  progressLog(progress)(`Preparing the CODESYS gateway (${gatewayImage}).`);
@@ -13,7 +13,7 @@ import { createRequire } from "node:module";
13
13
  import { tmpdir } from "node:os";
14
14
  import { basename, dirname, posix, relative, resolve, sep } from "node:path";
15
15
  import { z } from "zod";
16
- import { packageDirectory } from "./package-path.ts";
16
+ import { packageDirectory } from "./package-path";
17
17
 
18
18
  const includeSource = (source: string) => {
19
19
  const name = basename(source);
@@ -191,7 +191,9 @@ export const containerManifest = async () => {
191
191
  /**
192
192
  * The files of the image's recipe that its containers can't take from the installed package: the
193
193
  * Dockerfile, the entrypoint and the installation's scripts and data. Tests and checks of the
194
- * installation's own tools stay out, as the published package leaves them out.
194
+ * installation's own tools stay out, as the published package leaves them out, and so does
195
+ * `.npmignore`, which npm never packs: an image built from a checkout carries the recipe an
196
+ * installed tsPLC computes, so it finds the image published under that recipe current.
195
197
  */
196
198
  const recipeFile = (path: string) =>
197
199
  path === "docker" ||
@@ -199,6 +201,7 @@ const recipeFile = (path: string) =>
199
201
  path === "docker/entrypoint.sh" ||
200
202
  ((path === "docker/install" || path.startsWith("docker/install/")) &&
201
203
  includeSource(basename(path)) &&
204
+ basename(path) !== ".npmignore" &&
202
205
  !path.split("/").includes("tests") &&
203
206
  path !== "docker/install/wine-signal/check.sh");
204
207
 
package/src/docker-run.ts CHANGED
@@ -4,7 +4,7 @@ import { copyFile, cp, mkdir, readFile, writeFile } from "node:fs/promises";
4
4
  import { basename, posix, relative, resolve, sep } from "node:path";
5
5
  import { promisify } from "node:util";
6
6
  import type { ResolvedConfig } from "@tsplc/config/build";
7
- import { containerCode } from "./docker-context.ts";
7
+ import { containerCode } from "./docker-context";
8
8
 
9
9
  const execute = promisify(execFile);
10
10
 
@@ -7,7 +7,7 @@ import {
7
7
  import { resolveConfig } from "@tsplc/config/build";
8
8
  import { deviceTree } from "@tsplc/typegen";
9
9
  import { loadHardware, resolveIo } from "@tsplc/typegen/hardware";
10
- import { installLibraries } from "./libraries.ts";
10
+ import { installLibraries } from "./libraries";
11
11
 
12
12
  /**
13
13
  * The settings a raw Structured Text project builds, runs and updates its controller with:
package/src/images.ts CHANGED
@@ -2,8 +2,8 @@ import { copyFile, cp, mkdir, mkdtemp, rm } from "node:fs/promises";
2
2
  import { tmpdir } from "node:os";
3
3
  import { resolve } from "node:path";
4
4
  import { dockerImage } from "@tsplc/config/build";
5
- import { builderRecipe, prepareDockerContext } from "./docker-context.ts";
6
- import { packageDirectory } from "./package-path.ts";
5
+ import { builderRecipe, prepareDockerContext } from "./docker-context";
6
+ import { packageDirectory } from "./package-path";
7
7
 
8
8
  export const builderImage = dockerImage;
9
9
 
@@ -12,9 +12,21 @@ export const gatewayImage = "tsplc-edge-gateway:4.22.0.0";
12
12
  /** The local CODESYS Control for Linux SL runtime; it is always built here, never published. */
13
13
  export const runtimeImage = "tsplc-control-linux-sl:4.22.0.0";
14
14
 
15
- /** The registry name each tsPLC version's copy of a local image is published under. */
16
- export const publishedImage = (image: string, version: string) =>
17
- `ghcr.io/livingforjesus/${image.split(":")[0]}:${version}`;
15
+ const registry = "ghcr.io/livingforjesus";
16
+
17
+ /**
18
+ * The published copy of a local image whose tag already names what is in it, as the gateway's names its CODESYS version:
19
+ * every tsPLC that uses that version shares the one copy.
20
+ */
21
+ export const publishedImage = (image: string) => `${registry}/${image}`;
22
+
23
+ /**
24
+ * The published copy of the builder image for this installation's recipe. Containers run the installed tsPLC's code, so
25
+ * the image changes only with its recipe, and every tsPLC with the same recipe shares the one copy rather than a release
26
+ * rebuilding the vendor installation.
27
+ */
28
+ export const publishedBuilderImage = async () =>
29
+ `${registry}/${builderImage.split(":")[0]}:recipe-${await builderRecipe()}`;
18
30
 
19
31
  /** The platform the vendor installer runs on; the compiler image itself is always AMD64. */
20
32
  export type SetupPlatform = "linux/amd64" | "linux/arm64";
package/src/index.ts CHANGED
@@ -7,13 +7,13 @@ export {
7
7
  type ResolvedConfig,
8
8
  resolveConfig,
9
9
  } from "@tsplc/config/build";
10
- export { readBuild } from "./artifacts.ts";
10
+ export { readBuild } from "./artifacts";
11
11
  export { buildProject } from "./build";
12
12
  export {
13
13
  type BuilderImageStatus,
14
14
  builderImageStatus,
15
15
  setupReason,
16
- } from "./builder-image.ts";
16
+ } from "./builder-image";
17
17
  export {
18
18
  type ControllerLogin,
19
19
  findControllerLogin,
@@ -38,7 +38,7 @@ export {
38
38
  TransferFailedError,
39
39
  transferRollback,
40
40
  } from "./controller-protocol";
41
- export { controllerBaseline } from "./controller-session.ts";
41
+ export { controllerBaseline } from "./controller-session";
42
42
  export {
43
43
  type CodesysCompilerDiagnostic,
44
44
  CodesysCompilerError,
@@ -47,26 +47,26 @@ export {
47
47
  configureDocker,
48
48
  configureGateway,
49
49
  configureRuntime,
50
- } from "./docker-build.ts";
50
+ } from "./docker-build";
51
51
  export {
52
52
  captureDocker,
53
53
  type ProgressOptions,
54
54
  type ProgressStream,
55
55
  progressLog,
56
- } from "./docker-run.ts";
56
+ } from "./docker-run";
57
57
  export { rawEngineeringSettings } from "./engineering-settings";
58
- export { workerScriptsDigest } from "./host/codesys-worker.ts";
59
- export { gatewayImage } from "./images.ts";
58
+ export { workerScriptsDigest } from "./host/codesys-worker";
59
+ export { gatewayImage } from "./images";
60
60
  export {
61
61
  type InstalledLibrary,
62
62
  installLibraries,
63
63
  libraryIndex,
64
64
  validateLibrary,
65
- } from "./libraries.ts";
65
+ } from "./libraries";
66
66
  export {
67
67
  checkRawSources,
68
68
  inspectProjectController,
69
- } from "./project-operations.ts";
69
+ } from "./project-operations";
70
70
  export { runProject } from "./run";
71
71
  export { loadSources, type SourceObject } from "./sources";
72
72
  export { StSyntaxError } from "./st/lexer";
package/src/io.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import { ioArray, ioScalarBits, sizePrefix } from "@tsplc/iec";
2
2
  import { qualifiers, variableSections } from "@tsplc/iec/st";
3
- import type { SourceObject } from "./sources.ts";
4
- import { type Token, tokenize } from "./st/lexer.ts";
3
+ import type { SourceObject } from "./sources";
4
+ import { type Token, tokenize } from "./st/lexer";
5
5
 
6
6
  export interface DirectIoBinding {
7
7
  address: string;
@@ -5,9 +5,9 @@ import {
5
5
  } from "@tsplc/config";
6
6
  import { resolveConfig } from "@tsplc/config/build";
7
7
  import { loadHardware, resolveIo } from "@tsplc/typegen/hardware";
8
- import { inspectController } from "./controller-online.ts";
9
- import type { ProgressOptions } from "./docker-run.ts";
10
- import { loadSources } from "./sources.ts";
8
+ import { inspectController } from "./controller-online";
9
+ import type { ProgressOptions } from "./docker-run";
10
+ import { loadSources } from "./sources";
11
11
 
12
12
  /** Parses a raw Structured Text project's sources with its IO bound, without installing libraries or building. */
13
13
  export const checkRawSources = async ({
package/src/run.ts CHANGED
@@ -7,7 +7,7 @@ import { z } from "zod";
7
7
  import { readBuild } from "./artifacts";
8
8
  import { captureDocker, type ProgressOptions, progressLog } from "./docker-run";
9
9
  import { withWorkerLock } from "./host/codesys-worker";
10
- import { runtimeImage } from "./images.ts";
10
+ import { runtimeImage } from "./images";
11
11
  import { getApplicationStatus } from "./runtime-status";
12
12
 
13
13
  const stateSchema = z.object({
package/src/sources.ts CHANGED
@@ -2,7 +2,7 @@ import { readdir, readFile } from "node:fs/promises";
2
2
  import { basename, resolve } from "node:path";
3
3
  import type { ResolvedConfig } from "@tsplc/config/build";
4
4
  import { identifierPattern } from "@tsplc/iec/st";
5
- import { bindStructuredTextIo } from "./io.ts";
5
+ import { bindStructuredTextIo } from "./io";
6
6
  import { type ObjectKind, type ParsedSource, parseSource } from "./st/parse";
7
7
 
8
8
  export type SourceObject = ParsedSource & {