plccheck 2.8.1 → 2.10.1
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 +26 -0
- package/bin/plccheck.js +123 -6
- package/package.json +8 -7
package/README.md
CHANGED
|
@@ -16,6 +16,7 @@ npx plccheck check ./path/to/project
|
|
|
16
16
|
- `plccheck check <files-or-folders...>`
|
|
17
17
|
- `plccheck emit --target <language> <file>`
|
|
18
18
|
- `plccheck test [--filter <text>] [--events-json] [--coverage-json <file>] [--coverage-lcov <file>] <file-or-folder>`
|
|
19
|
+
- `plccheck tia <list|export|import|repair-library-dependencies|online|offline|snapshot|compile|download|trust> ...`
|
|
19
20
|
- `plccheck version`
|
|
20
21
|
|
|
21
22
|
## Testing and Coverage
|
|
@@ -39,3 +40,28 @@ npx plccheck test ./my-plc-project --coverage-json coverage.json --coverage-lcov
|
|
|
39
40
|
```
|
|
40
41
|
|
|
41
42
|
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`.
|
|
43
|
+
|
|
44
|
+
## TIA Portal Openness
|
|
45
|
+
|
|
46
|
+
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.
|
|
47
|
+
|
|
48
|
+
```bash
|
|
49
|
+
npx plccheck tia trust --json
|
|
50
|
+
npx plccheck tia export --project Demo.ap21 --out exported --plc PLC_1 --delete-stale
|
|
51
|
+
npx plccheck tia import --project Demo.ap21 --root exported "exported/PLC_1/Program blocks/Main.scl" --create
|
|
52
|
+
npx plccheck tia import --project Demo.ap21 --root exported --skip-library-instances "exported/PLC_1"
|
|
53
|
+
npx plccheck tia import --project Demo.ap21 --root exported "exported/PLC_1/Program blocks"
|
|
54
|
+
npx plccheck tia repair-library-dependencies --project Demo.ap21 --plc PLC_1 --owner CA
|
|
55
|
+
npx plccheck tia compile --project Demo.ap21 --plc PLC_1 --json
|
|
56
|
+
npx plccheck tia online --project Demo.ap21 --plc PLC_1
|
|
57
|
+
npx plccheck tia online --project Demo.ap21 --plc PLC_1 --online-auth-type ProjectUser --online-user engineer --online-password-env TIA_PROJECT_PASSWORD
|
|
58
|
+
npx plccheck tia offline --project Demo.ap21 --plc PLC_1
|
|
59
|
+
npx plccheck tia snapshot --project Demo.ap21 --plc PLC_1 --json
|
|
60
|
+
npx plccheck tia download --project Demo.ap21 --plc PLC_1 --json
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
`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. 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.
|
|
64
|
+
|
|
65
|
+
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`.
|
|
66
|
+
|
|
67
|
+
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 may require Windows administrator approval through UAC. If the UAC relaunch path is blocked, save the returned `registryFile` content as a `.reg` file and import it 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
|
|
|
@@ -215,6 +212,27 @@ function readOptionalDepVersion(pkgName) {
|
|
|
215
212
|
}
|
|
216
213
|
}
|
|
217
214
|
|
|
215
|
+
function windowsBridgeArtifactsPresent(binDir) {
|
|
216
|
+
return fs.existsSync(path.join(binDir, 'tia-openness-bridge.exe'))
|
|
217
|
+
&& fs.existsSync(path.join(binDir, 'tia-openness-bridge.exe.config'));
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
function platformRequiresWindowsBridge(platform = process.platform, arch = process.arch) {
|
|
221
|
+
return platform === 'win32' && arch === 'x64';
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
function requireWindowsBridgeArtifacts(binDir, platform = process.platform, arch = process.arch) {
|
|
225
|
+
if (!platformRequiresWindowsBridge(platform, arch) || windowsBridgeArtifactsPresent(binDir)) {
|
|
226
|
+
return;
|
|
227
|
+
}
|
|
228
|
+
throw new Error(`platform package is missing required TIA Openness bridge artifacts in ${binDir}`);
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
function validateResolvedBinaryPath(binaryPath, platform = process.platform, arch = process.arch) {
|
|
232
|
+
requireWindowsBridgeArtifacts(path.dirname(binaryPath), platform, arch);
|
|
233
|
+
return binaryPath;
|
|
234
|
+
}
|
|
235
|
+
|
|
218
236
|
function isRepoDevelopmentMode(rootDir = path.join(__dirname, '..', '..', '..')) {
|
|
219
237
|
const repoRoot = path.resolve(rootDir);
|
|
220
238
|
const localGoMod = path.join(repoRoot, 'go_lsp', 'go.mod');
|
|
@@ -235,7 +253,7 @@ async function resolveBinaryPath() {
|
|
|
235
253
|
if (isRepoDevelopmentMode()) return 'go';
|
|
236
254
|
|
|
237
255
|
try {
|
|
238
|
-
return require(pkg);
|
|
256
|
+
return validateResolvedBinaryPath(require(pkg));
|
|
239
257
|
} catch (err) {
|
|
240
258
|
if (err && err.code !== 'MODULE_NOT_FOUND') throw err;
|
|
241
259
|
}
|
|
@@ -248,7 +266,9 @@ async function resolveBinaryPath() {
|
|
|
248
266
|
const binaryName = process.platform === 'win32' ? 'plccheck.exe' : 'plccheck';
|
|
249
267
|
const binDir = path.join(cacheRoot(), 'bin', version, `${process.platform}-${process.arch}`);
|
|
250
268
|
const binPath = path.join(binDir, binaryName);
|
|
251
|
-
if (fs.existsSync(binPath))
|
|
269
|
+
if (fs.existsSync(binPath) && (!platformRequiresWindowsBridge() || windowsBridgeArtifactsPresent(binDir))) {
|
|
270
|
+
return binPath;
|
|
271
|
+
}
|
|
252
272
|
|
|
253
273
|
const metaUrl = `https://registry.npmjs.org/${registryPackagePath(pkg)}`;
|
|
254
274
|
const meta = await httpsGetJson(metaUrl);
|
|
@@ -266,6 +286,19 @@ async function resolveBinaryPath() {
|
|
|
266
286
|
verifyIntegrity(tgzPath, v.dist.integrity, v.dist.shasum);
|
|
267
287
|
|
|
268
288
|
extractFileFromTgz(tgzPath, `package/${binaryName}`, binPath);
|
|
289
|
+
if (process.platform === 'win32') {
|
|
290
|
+
try {
|
|
291
|
+
extractFileFromTgz(tgzPath, 'package/tia-openness-bridge.exe', path.join(binDir, 'tia-openness-bridge.exe'));
|
|
292
|
+
} catch {
|
|
293
|
+
// Older platform packages do not include the optional TIA bridge.
|
|
294
|
+
}
|
|
295
|
+
try {
|
|
296
|
+
extractFileFromTgz(tgzPath, 'package/tia-openness-bridge.exe.config', path.join(binDir, 'tia-openness-bridge.exe.config'));
|
|
297
|
+
} catch {
|
|
298
|
+
// Older platform packages do not include the optional TIA bridge config.
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
requireWindowsBridgeArtifacts(binDir);
|
|
269
302
|
if (process.platform !== 'win32') {
|
|
270
303
|
await fsp.chmod(binPath, 0o755);
|
|
271
304
|
}
|
|
@@ -318,6 +351,9 @@ function resolveGoRunPaths(args, cwd) {
|
|
|
318
351
|
if (nextArgs.length === 0) {
|
|
319
352
|
return nextArgs;
|
|
320
353
|
}
|
|
354
|
+
if (nextArgs[0] === 'tia') {
|
|
355
|
+
return resolveTiaGoRunPaths(nextArgs, cwd);
|
|
356
|
+
}
|
|
321
357
|
const valueFlags = commandValueFlags[nextArgs[0]] || [];
|
|
322
358
|
for (let i = 1; i < nextArgs.length; i++) {
|
|
323
359
|
const arg = nextArgs[i];
|
|
@@ -345,6 +381,80 @@ function resolveGoRunPaths(args, cwd) {
|
|
|
345
381
|
return nextArgs;
|
|
346
382
|
}
|
|
347
383
|
|
|
384
|
+
function looksLikeTiaProjectPath(value) {
|
|
385
|
+
if (!value) {
|
|
386
|
+
return false;
|
|
387
|
+
}
|
|
388
|
+
if (path.isAbsolute(value) || value.includes('/') || value.includes('\\')) {
|
|
389
|
+
return true;
|
|
390
|
+
}
|
|
391
|
+
const extension = path.extname(value).toLowerCase();
|
|
392
|
+
return extension.startsWith('.ap') || extension.startsWith('.zap');
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
function resolveTiaPathFlagValue(baseFlag, value, cwd) {
|
|
396
|
+
if (!value || path.isAbsolute(value)) {
|
|
397
|
+
return value;
|
|
398
|
+
}
|
|
399
|
+
if ((baseFlag === '--project' || baseFlag === '-project') && !looksLikeTiaProjectPath(value)) {
|
|
400
|
+
return value;
|
|
401
|
+
}
|
|
402
|
+
return path.resolve(cwd, value);
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
function resolveTiaGoRunPaths(args, cwd) {
|
|
406
|
+
const nextArgs = args.slice();
|
|
407
|
+
const valueFlags = [
|
|
408
|
+
'--project', '-project',
|
|
409
|
+
'--plc', '-plc',
|
|
410
|
+
'--out', '-out',
|
|
411
|
+
'--root', '-root',
|
|
412
|
+
'--bridge', '-bridge',
|
|
413
|
+
'--owner', '-owner',
|
|
414
|
+
'--online-auth-type', '-online-auth-type',
|
|
415
|
+
'--online-user', '-online-user',
|
|
416
|
+
'--online-password-env', '-online-password-env',
|
|
417
|
+
];
|
|
418
|
+
const pathFlags = [
|
|
419
|
+
'--project', '-project',
|
|
420
|
+
'--out', '-out',
|
|
421
|
+
'--root', '-root',
|
|
422
|
+
'--bridge', '-bridge',
|
|
423
|
+
];
|
|
424
|
+
const action = nextArgs[1] || '';
|
|
425
|
+
let hasRoot = false;
|
|
426
|
+
for (let i = 2; i < nextArgs.length; i++) {
|
|
427
|
+
const arg = nextArgs[i];
|
|
428
|
+
if (arg.startsWith('-')) {
|
|
429
|
+
const baseFlag = arg.split('=')[0];
|
|
430
|
+
if (baseFlag === '--root' || baseFlag === '-root') {
|
|
431
|
+
hasRoot = true;
|
|
432
|
+
}
|
|
433
|
+
if (arg.includes('=')) {
|
|
434
|
+
const value = arg.slice(arg.indexOf('=') + 1);
|
|
435
|
+
if (value && pathFlags.includes(baseFlag)) {
|
|
436
|
+
nextArgs[i] = `${baseFlag}=${resolveTiaPathFlagValue(baseFlag, value, cwd)}`;
|
|
437
|
+
}
|
|
438
|
+
continue;
|
|
439
|
+
}
|
|
440
|
+
if (valueFlags.includes(baseFlag) && i + 1 < nextArgs.length) {
|
|
441
|
+
if (pathFlags.includes(baseFlag) && !nextArgs[i + 1].startsWith('-')) {
|
|
442
|
+
nextArgs[i + 1] = resolveTiaPathFlagValue(baseFlag, nextArgs[i + 1], cwd);
|
|
443
|
+
}
|
|
444
|
+
i++;
|
|
445
|
+
}
|
|
446
|
+
continue;
|
|
447
|
+
}
|
|
448
|
+
if ((action === 'import' || action === 'diff') && !path.isAbsolute(arg)) {
|
|
449
|
+
nextArgs[i] = path.resolve(cwd, arg);
|
|
450
|
+
}
|
|
451
|
+
}
|
|
452
|
+
if ((action === 'import' || action === 'diff') && !hasRoot) {
|
|
453
|
+
nextArgs.push('--root', cwd);
|
|
454
|
+
}
|
|
455
|
+
return nextArgs;
|
|
456
|
+
}
|
|
457
|
+
|
|
348
458
|
function reorderTestArgs(args) {
|
|
349
459
|
if (args[0] !== 'test' && !(args[0] === 'run' && args[1] === './cmd/siemens-lsp' && args[2] === 'test')) {
|
|
350
460
|
return args.slice();
|
|
@@ -411,10 +521,17 @@ async function main(argv = process.argv.slice(2)) {
|
|
|
411
521
|
|
|
412
522
|
module.exports = {
|
|
413
523
|
isRepoDevelopmentMode,
|
|
524
|
+
platformPackageName,
|
|
414
525
|
reorderTestArgs,
|
|
415
526
|
resolveCoverageOutputPaths,
|
|
416
527
|
resolveGoRunPaths,
|
|
528
|
+
resolveTiaGoRunPaths,
|
|
417
529
|
resolveTestPositionals,
|
|
530
|
+
looksLikeTiaProjectPath,
|
|
531
|
+
platformRequiresWindowsBridge,
|
|
532
|
+
requireWindowsBridgeArtifacts,
|
|
533
|
+
validateResolvedBinaryPath,
|
|
534
|
+
windowsBridgeArtifactsPresent,
|
|
418
535
|
};
|
|
419
536
|
|
|
420
537
|
if (require.main === module) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "plccheck",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.10.1",
|
|
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.
|
|
18
|
-
"@danielv123/plccheck-win-arm64": "2.
|
|
19
|
-
"@danielv123/plccheck-linux-x64": "2.
|
|
20
|
-
"@danielv123/plccheck-linux-arm64": "2.
|
|
21
|
-
"@danielv123/plccheck-darwin-x64": "2.
|
|
22
|
-
"@danielv123/plccheck-darwin-arm64": "2.
|
|
18
|
+
"@danielv123/plccheck-win-x64": "2.10.1",
|
|
19
|
+
"@danielv123/plccheck-win-arm64": "2.10.1",
|
|
20
|
+
"@danielv123/plccheck-linux-x64": "2.10.1",
|
|
21
|
+
"@danielv123/plccheck-linux-arm64": "2.10.1",
|
|
22
|
+
"@danielv123/plccheck-darwin-x64": "2.10.1",
|
|
23
|
+
"@danielv123/plccheck-darwin-arm64": "2.10.1"
|
|
23
24
|
},
|
|
24
25
|
"repository": {
|
|
25
26
|
"type": "git",
|