plccheck 2.9.0 → 2.11.0

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/README.md CHANGED
@@ -15,7 +15,10 @@ npx plccheck check ./path/to/project
15
15
  - `plccheck serve` (LSP server over stdio)
16
16
  - `plccheck check <files-or-folders...>`
17
17
  - `plccheck emit --target <language> <file>`
18
+ - `plccheck compile --out <exe> <file-or-folder>`
19
+ - `plccheck run <file-or-folder> [-- runtime args...]`
18
20
  - `plccheck test [--filter <text>] [--events-json] [--coverage-json <file>] [--coverage-lcov <file>] <file-or-folder>`
21
+ - `plccheck tia <list|export|import|repair-library-dependencies|online|offline|snapshot|compile|download|trust> ...`
19
22
  - `plccheck version`
20
23
 
21
24
  ## Testing and Coverage
@@ -39,3 +42,45 @@ npx plccheck test ./my-plc-project --coverage-json coverage.json --coverage-lcov
39
42
  ```
40
43
 
41
44
  Note: `--events-json` prints a stream of execution events to stdout, while `--coverage-json` writes a finalized coverage report to a file. Coverage artifacts include statement, function, and branch data where runtime data is available. For AI analysis, use the file artifact from `--coverage-json`.
45
+
46
+ ## Compile and Run PLC Runtime
47
+
48
+ Build a runnable PLC runtime executable:
49
+
50
+ ```bash
51
+ npx plccheck compile --out plc-run.exe ./my-plc-project
52
+ ```
53
+
54
+ Build and run it immediately, forwarding runtime flags after `--`:
55
+
56
+ ```bash
57
+ npx plccheck run ./my-plc-project -- --opcua-port 4849 --scan-period 24h
58
+ ```
59
+
60
+ ## TIA Portal Openness
61
+
62
+ On Windows x64 machines with TIA Portal Openness V21 or newer, `plccheck tia` can attach to a running TIA project or open an explicit `.ap21`/`.zap21` path.
63
+
64
+ ```bash
65
+ npx plccheck tia trust --json
66
+ npx plccheck tia export --project Demo.ap21 --out exported --plc PLC_1 --delete-stale
67
+ npx plccheck tia import --project Demo.ap21 --root exported "exported/PLC_1/Program blocks/Main.scl" --create
68
+ npx plccheck tia import --project Demo.ap21 --root exported "exported/PLC_1/Program blocks/Main.scl" --overwrite-remote-changes
69
+ npx plccheck tia import --project Demo.ap21 --root exported --skip-library-instances "exported/PLC_1"
70
+ npx plccheck tia import --project Demo.ap21 --root exported "exported/PLC_1/Program blocks"
71
+ npx plccheck tia repair-library-dependencies --project Demo.ap21 --plc PLC_1 --owner CA
72
+ npx plccheck tia compile --project Demo.ap21 --plc PLC_1 --json
73
+ npx plccheck tia online --project Demo.ap21 --plc PLC_1
74
+ npx plccheck tia online --project Demo.ap21 --plc PLC_1 --online-auth-type ProjectUser --online-user engineer --online-password-env TIA_PROJECT_PASSWORD
75
+ npx plccheck tia offline --project Demo.ap21 --plc PLC_1
76
+ npx plccheck tia snapshot --project Demo.ap21 --plc PLC_1 --json
77
+ npx plccheck tia download --project Demo.ap21 --plc PLC_1 --json
78
+ ```
79
+
80
+ `export` writes PLC roots with `.plc.json` files and the TIA folder structure. `import` accepts one or more source files or folders, expands folders recursively, and needs `--create` before creating missing TIA folders or blocks. Supported direct import sources are `.scl`, `.s7dcl`, `.db`, `.udt`, `.xml`, `.awl`, `.lad`, and `.fbd`; pass the owning source file instead of `.s7res` resource sidecars or `.meta.json` metadata sidecars. By default, import skips unchanged local files, skips local files whose TIA object changed while the local source stayed unchanged, and rejects files changed both locally and in TIA since the last metadata refresh. Pass `--overwrite` to import when both sides changed, or `--overwrite-remote-changes` to import when only the TIA object changed. Import refuses to overwrite an existing project-library type instance or one of its project-library dependencies by default; pass `--skip-library-instances` to leave those library-owned targets unchanged and continue importing the rest, or pass `--allow-library-instance-overwrite` only for an intentional mutation run. `repair-library-dependencies` is the safe repair path for that failure class: it recreates the named library instance's project-local dependency objects from the project library. `snapshot` uses TIA's online DB snapshot before moving retained values to start values, skipping safety DBs and DBs without retained members. `download` compiles first, uses the project-configured target, reports the selected target in JSON, and falls back to software-only changes when Siemens Openness rejects a full load because of fail-safe data.
81
+
82
+ If `tia list --json` shows `projectPath` but project commands report that TIA Openness did not expose the project, close that TIA Portal instance and rerun a verification export with `npx plccheck tia export --project <path> --out <dir>` to surface TIA's native open error. This often means the machine is missing a TIA product or add-on required by the project.
83
+
84
+ Device actions automatically accept non-secret TLS and online-authentication modes. If the PLC requires a project/global/password user, pass `--online-auth-type`, `--online-user` where applicable, and `--online-password-env <env>` so the password is read from an environment variable. Without flags, the bridge also reads `PLCCHECK_TIA_ONLINE_USER_TYPE` or `PLCCHECK_TIA_ONLINE_AUTH_TYPE`, `PLCCHECK_TIA_ONLINE_USER`, and `PLCCHECK_TIA_ONLINE_PASSWORD`.
85
+
86
+ Use `tia trust --install` to install the Siemens Openness AllowList entry for the packaged bridge after reviewing the `tia trust --json` output. Installation writes HKLM and ensures the current Windows user is a member of the local `Siemens TIA Openness` group, so it may require Windows administrator approval through UAC. If the UAC relaunch path is blocked, run the same command from an already elevated shell.
package/bin/plccheck.js CHANGED
@@ -10,10 +10,7 @@ const os = require('node:os');
10
10
  const path = require('node:path');
11
11
  const zlib = require('node:zlib');
12
12
 
13
- function platformPackageName() {
14
- const platform = process.platform;
15
- const arch = process.arch;
16
-
13
+ function platformPackageName(platform = process.platform, arch = process.arch) {
17
14
  if (platform === 'win32' && arch === 'x64') return '@danielv123/plccheck-win-x64';
18
15
  if (platform === 'win32' && arch === 'arm64') return '@danielv123/plccheck-win-arm64';
19
16
 
@@ -52,13 +49,16 @@ const commandValueFlags = {
52
49
  check: ['--jobs', '-jobs'],
53
50
  emit: ['--target', '-target'],
54
51
  transpile: ['--from', '-from', '--to', '-to'],
55
- 'go-gen': ['--out', '-out', '--module', '-module', '--entry-ob', '-entry-ob'],
52
+ generate: ['--out', '-out', '--module', '-module', '--entry-ob', '-entry-ob'],
53
+ compile: ['--out', '-out', '--workdir', '-workdir', '--module', '-module', '--entry-ob', '-entry-ob'],
54
+ run: ['--out', '-out', '--workdir', '-workdir', '--module', '-module', '--entry-ob', '-entry-ob'],
56
55
  test: testValueFlags,
57
56
  };
58
57
 
59
58
  const pathValueFlags = [
60
59
  ...coverageValueFlags,
61
60
  '--out', '-out',
61
+ '--workdir', '-workdir',
62
62
  ];
63
63
 
64
64
  function cacheRoot() {
@@ -215,6 +215,27 @@ function readOptionalDepVersion(pkgName) {
215
215
  }
216
216
  }
217
217
 
218
+ function windowsBridgeArtifactsPresent(binDir) {
219
+ return fs.existsSync(path.join(binDir, 'tia-openness-bridge.exe'))
220
+ && fs.existsSync(path.join(binDir, 'tia-openness-bridge.exe.config'));
221
+ }
222
+
223
+ function platformRequiresWindowsBridge(platform = process.platform, arch = process.arch) {
224
+ return platform === 'win32' && arch === 'x64';
225
+ }
226
+
227
+ function requireWindowsBridgeArtifacts(binDir, platform = process.platform, arch = process.arch) {
228
+ if (!platformRequiresWindowsBridge(platform, arch) || windowsBridgeArtifactsPresent(binDir)) {
229
+ return;
230
+ }
231
+ throw new Error(`platform package is missing required TIA Openness bridge artifacts in ${binDir}`);
232
+ }
233
+
234
+ function validateResolvedBinaryPath(binaryPath, platform = process.platform, arch = process.arch) {
235
+ requireWindowsBridgeArtifacts(path.dirname(binaryPath), platform, arch);
236
+ return binaryPath;
237
+ }
238
+
218
239
  function isRepoDevelopmentMode(rootDir = path.join(__dirname, '..', '..', '..')) {
219
240
  const repoRoot = path.resolve(rootDir);
220
241
  const localGoMod = path.join(repoRoot, 'go_lsp', 'go.mod');
@@ -235,7 +256,7 @@ async function resolveBinaryPath() {
235
256
  if (isRepoDevelopmentMode()) return 'go';
236
257
 
237
258
  try {
238
- return require(pkg);
259
+ return validateResolvedBinaryPath(require(pkg));
239
260
  } catch (err) {
240
261
  if (err && err.code !== 'MODULE_NOT_FOUND') throw err;
241
262
  }
@@ -248,7 +269,9 @@ async function resolveBinaryPath() {
248
269
  const binaryName = process.platform === 'win32' ? 'plccheck.exe' : 'plccheck';
249
270
  const binDir = path.join(cacheRoot(), 'bin', version, `${process.platform}-${process.arch}`);
250
271
  const binPath = path.join(binDir, binaryName);
251
- if (fs.existsSync(binPath)) return binPath;
272
+ if (fs.existsSync(binPath) && (!platformRequiresWindowsBridge() || windowsBridgeArtifactsPresent(binDir))) {
273
+ return binPath;
274
+ }
252
275
 
253
276
  const metaUrl = `https://registry.npmjs.org/${registryPackagePath(pkg)}`;
254
277
  const meta = await httpsGetJson(metaUrl);
@@ -266,6 +289,19 @@ async function resolveBinaryPath() {
266
289
  verifyIntegrity(tgzPath, v.dist.integrity, v.dist.shasum);
267
290
 
268
291
  extractFileFromTgz(tgzPath, `package/${binaryName}`, binPath);
292
+ if (process.platform === 'win32') {
293
+ try {
294
+ extractFileFromTgz(tgzPath, 'package/tia-openness-bridge.exe', path.join(binDir, 'tia-openness-bridge.exe'));
295
+ } catch {
296
+ // Older platform packages do not include the optional TIA bridge.
297
+ }
298
+ try {
299
+ extractFileFromTgz(tgzPath, 'package/tia-openness-bridge.exe.config', path.join(binDir, 'tia-openness-bridge.exe.config'));
300
+ } catch {
301
+ // Older platform packages do not include the optional TIA bridge config.
302
+ }
303
+ }
304
+ requireWindowsBridgeArtifacts(binDir);
269
305
  if (process.platform !== 'win32') {
270
306
  await fsp.chmod(binPath, 0o755);
271
307
  }
@@ -318,9 +354,15 @@ function resolveGoRunPaths(args, cwd) {
318
354
  if (nextArgs.length === 0) {
319
355
  return nextArgs;
320
356
  }
357
+ if (nextArgs[0] === 'tia') {
358
+ return resolveTiaGoRunPaths(nextArgs, cwd);
359
+ }
321
360
  const valueFlags = commandValueFlags[nextArgs[0]] || [];
322
361
  for (let i = 1; i < nextArgs.length; i++) {
323
362
  const arg = nextArgs[i];
363
+ if (nextArgs[0] === 'run' && arg === '--') {
364
+ break;
365
+ }
324
366
  if (arg.startsWith('-')) {
325
367
  const baseFlag = arg.split('=')[0];
326
368
  if (arg.includes('=')) {
@@ -345,6 +387,80 @@ function resolveGoRunPaths(args, cwd) {
345
387
  return nextArgs;
346
388
  }
347
389
 
390
+ function looksLikeTiaProjectPath(value) {
391
+ if (!value) {
392
+ return false;
393
+ }
394
+ if (path.isAbsolute(value) || value.includes('/') || value.includes('\\')) {
395
+ return true;
396
+ }
397
+ const extension = path.extname(value).toLowerCase();
398
+ return extension.startsWith('.ap') || extension.startsWith('.zap');
399
+ }
400
+
401
+ function resolveTiaPathFlagValue(baseFlag, value, cwd) {
402
+ if (!value || path.isAbsolute(value)) {
403
+ return value;
404
+ }
405
+ if ((baseFlag === '--project' || baseFlag === '-project') && !looksLikeTiaProjectPath(value)) {
406
+ return value;
407
+ }
408
+ return path.resolve(cwd, value);
409
+ }
410
+
411
+ function resolveTiaGoRunPaths(args, cwd) {
412
+ const nextArgs = args.slice();
413
+ const valueFlags = [
414
+ '--project', '-project',
415
+ '--plc', '-plc',
416
+ '--out', '-out',
417
+ '--root', '-root',
418
+ '--bridge', '-bridge',
419
+ '--owner', '-owner',
420
+ '--online-auth-type', '-online-auth-type',
421
+ '--online-user', '-online-user',
422
+ '--online-password-env', '-online-password-env',
423
+ ];
424
+ const pathFlags = [
425
+ '--project', '-project',
426
+ '--out', '-out',
427
+ '--root', '-root',
428
+ '--bridge', '-bridge',
429
+ ];
430
+ const action = nextArgs[1] || '';
431
+ let hasRoot = false;
432
+ for (let i = 2; i < nextArgs.length; i++) {
433
+ const arg = nextArgs[i];
434
+ if (arg.startsWith('-')) {
435
+ const baseFlag = arg.split('=')[0];
436
+ if (baseFlag === '--root' || baseFlag === '-root') {
437
+ hasRoot = true;
438
+ }
439
+ if (arg.includes('=')) {
440
+ const value = arg.slice(arg.indexOf('=') + 1);
441
+ if (value && pathFlags.includes(baseFlag)) {
442
+ nextArgs[i] = `${baseFlag}=${resolveTiaPathFlagValue(baseFlag, value, cwd)}`;
443
+ }
444
+ continue;
445
+ }
446
+ if (valueFlags.includes(baseFlag) && i + 1 < nextArgs.length) {
447
+ if (pathFlags.includes(baseFlag) && !nextArgs[i + 1].startsWith('-')) {
448
+ nextArgs[i + 1] = resolveTiaPathFlagValue(baseFlag, nextArgs[i + 1], cwd);
449
+ }
450
+ i++;
451
+ }
452
+ continue;
453
+ }
454
+ if ((action === 'import' || action === 'diff') && !path.isAbsolute(arg)) {
455
+ nextArgs[i] = path.resolve(cwd, arg);
456
+ }
457
+ }
458
+ if ((action === 'import' || action === 'diff') && !hasRoot) {
459
+ nextArgs.push('--root', cwd);
460
+ }
461
+ return nextArgs;
462
+ }
463
+
348
464
  function reorderTestArgs(args) {
349
465
  if (args[0] !== 'test' && !(args[0] === 'run' && args[1] === './cmd/siemens-lsp' && args[2] === 'test')) {
350
466
  return args.slice();
@@ -411,10 +527,17 @@ async function main(argv = process.argv.slice(2)) {
411
527
 
412
528
  module.exports = {
413
529
  isRepoDevelopmentMode,
530
+ platformPackageName,
414
531
  reorderTestArgs,
415
532
  resolveCoverageOutputPaths,
416
533
  resolveGoRunPaths,
534
+ resolveTiaGoRunPaths,
417
535
  resolveTestPositionals,
536
+ looksLikeTiaProjectPath,
537
+ platformRequiresWindowsBridge,
538
+ requireWindowsBridgeArtifacts,
539
+ validateResolvedBinaryPath,
540
+ windowsBridgeArtifactsPresent,
418
541
  };
419
542
 
420
543
  if (require.main === module) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "plccheck",
3
- "version": "2.9.0",
3
+ "version": "2.11.0",
4
4
  "description": "Siemens PLC language checker + LSP CLI (SCL/ST/LAD/FBD, etc.)",
5
5
  "license": "CC-BY-NC-4.0",
6
6
  "bin": {
@@ -11,15 +11,16 @@
11
11
  "README.md"
12
12
  ],
13
13
  "scripts": {
14
+ "test": "node --test bin/plccheck.test.js",
14
15
  "version": "node ../scripts/plccheck-npm-version-hook.mjs"
15
16
  },
16
17
  "optionalDependencies": {
17
- "@danielv123/plccheck-win-x64": "2.9.0",
18
- "@danielv123/plccheck-win-arm64": "2.9.0",
19
- "@danielv123/plccheck-linux-x64": "2.9.0",
20
- "@danielv123/plccheck-linux-arm64": "2.9.0",
21
- "@danielv123/plccheck-darwin-x64": "2.9.0",
22
- "@danielv123/plccheck-darwin-arm64": "2.9.0"
18
+ "@danielv123/plccheck-win-x64": "2.11.0",
19
+ "@danielv123/plccheck-win-arm64": "2.11.0",
20
+ "@danielv123/plccheck-linux-x64": "2.11.0",
21
+ "@danielv123/plccheck-linux-arm64": "2.11.0",
22
+ "@danielv123/plccheck-darwin-x64": "2.11.0",
23
+ "@danielv123/plccheck-darwin-arm64": "2.11.0"
23
24
  },
24
25
  "repository": {
25
26
  "type": "git",