robopark 3.1.0 → 3.1.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "robopark",
3
- "version": "3.1.0",
3
+ "version": "3.1.1",
4
4
  "description": "Standalone packaged RoboPark control center and supervised robot runtime.",
5
5
  "type": "module",
6
6
  "bin": {
@@ -9,6 +9,7 @@
9
9
  "files": [
10
10
  "bin/robopark.js",
11
11
  "dist",
12
+ "scripts/windows-shim-fix.cjs",
12
13
  "scheduler",
13
14
  "pi-client",
14
15
  "conversation",
@@ -21,6 +22,7 @@
21
22
  "clean": "node -e \"require('fs').rmSync('dist',{recursive:true,force:true})\"",
22
23
  "build": "npm run clean && tsc -p tsconfig.json",
23
24
  "test": "node --test \"test/**/*.test.mjs\"",
25
+ "postinstall": "node scripts/windows-shim-fix.cjs",
24
26
  "prepack": "npm run build && npm test"
25
27
  },
26
28
  "engines": {
@@ -0,0 +1,58 @@
1
+ 'use strict';
2
+
3
+ const { readFileSync, unlinkSync } = require('node:fs');
4
+ const { dirname, join } = require('node:path');
5
+
6
+ function isTruthy(value) {
7
+ return /^(1|true|yes)$/i.test(String(value || ''));
8
+ }
9
+
10
+ function resolveGlobalBinDirectory() {
11
+ if (process.env.ROBOPARK_SHIM_DIR) return process.env.ROBOPARK_SHIM_DIR;
12
+ if (!isTruthy(process.env.npm_config_global)) return null;
13
+ return process.env.npm_config_prefix || dirname(process.execPath);
14
+ }
15
+
16
+ function isOurNpmShim(contents) {
17
+ return contents
18
+ .replaceAll('\\', '/')
19
+ .includes('node_modules/robopark/bin/robopark.js');
20
+ }
21
+
22
+ function removeConflictingShim(path) {
23
+ let contents;
24
+ try {
25
+ contents = readFileSync(path, 'utf8');
26
+ } catch (error) {
27
+ if (error && error.code === 'ENOENT') return false;
28
+ throw error;
29
+ }
30
+ if (!isOurNpmShim(contents)) return false;
31
+ unlinkSync(path);
32
+ return true;
33
+ }
34
+
35
+ function repairWindowsCommandResolution() {
36
+ const forced = isTruthy(process.env.ROBOPARK_FORCE_SHIM_FIX);
37
+ if (process.platform !== 'win32' && !forced) return [];
38
+ const binDirectory = resolveGlobalBinDirectory();
39
+ if (!binDirectory) return [];
40
+
41
+ // Keep robopark.cmd as the single Windows global entrypoint. On affected
42
+ // hosts cmd.exe opens the extensionless POSIX shim with an application
43
+ // picker, while PowerShell may reject the .ps1 shim by execution policy.
44
+ return ['robopark', 'robopark.ps1']
45
+ .filter((name) => removeConflictingShim(join(binDirectory, name)));
46
+ }
47
+
48
+ try {
49
+ const removed = repairWindowsCommandResolution();
50
+ if (removed.length > 0) {
51
+ console.log(`robopark: repaired Windows command launch (${removed.join(', ')} removed; robopark.cmd retained).`);
52
+ }
53
+ } catch (error) {
54
+ // robopark.cmd remains available even on machines that forbid shim cleanup.
55
+ console.warn(`robopark: Windows command repair skipped: ${error.message}`);
56
+ }
57
+
58
+ module.exports = { isOurNpmShim, repairWindowsCommandResolution };