@backtomyfuture/exchange-cli 0.1.4 → 0.1.6

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.
@@ -3,6 +3,7 @@
3
3
  const { execFileSync } = require('child_process');
4
4
  const fs = require('fs');
5
5
  const path = require('path');
6
+ const { ensureDarwinArm64RuntimeLayout } = require('./runtime-layout');
6
7
 
7
8
  const PLATFORM_PACKAGES = {
8
9
  'darwin-arm64': '@backtomyfuture/exchange-cli-darwin-arm64',
@@ -40,7 +41,9 @@ function getBinaryPath() {
40
41
  }
41
42
 
42
43
  try {
43
- execFileSync(getBinaryPath(), process.argv.slice(2), {
44
+ const binaryPath = getBinaryPath();
45
+ ensureDarwinArm64RuntimeLayout(binaryPath);
46
+ execFileSync(binaryPath, process.argv.slice(2), {
44
47
  stdio: 'inherit',
45
48
  env: { ...process.env },
46
49
  });
@@ -0,0 +1,114 @@
1
+ #!/usr/bin/env node
2
+
3
+ 'use strict';
4
+
5
+ const fs = require('fs');
6
+ const path = require('path');
7
+
8
+ function copyFileWithMode(src, dst) {
9
+ fs.mkdirSync(path.dirname(dst), { recursive: true });
10
+ fs.copyFileSync(src, dst);
11
+ try {
12
+ const stat = fs.statSync(src);
13
+ fs.chmodSync(dst, stat.mode & 0o777);
14
+ } catch {
15
+ // Best effort only.
16
+ }
17
+ }
18
+
19
+ function copyDirRecursive(srcDir, dstDir) {
20
+ fs.mkdirSync(dstDir, { recursive: true });
21
+ const entries = fs.readdirSync(srcDir, { withFileTypes: true });
22
+ for (const entry of entries) {
23
+ const src = path.join(srcDir, entry.name);
24
+ const dst = path.join(dstDir, entry.name);
25
+ if (entry.isDirectory()) {
26
+ copyDirRecursive(src, dst);
27
+ continue;
28
+ }
29
+ copyFileWithMode(src, dst);
30
+ }
31
+ }
32
+
33
+ function copyIfMissing(src, dst, logger) {
34
+ if (fs.existsSync(dst) || !fs.existsSync(src)) {
35
+ return false;
36
+ }
37
+ const stat = fs.statSync(src);
38
+ if (stat.isDirectory()) {
39
+ copyDirRecursive(src, dst);
40
+ } else {
41
+ copyFileWithMode(src, dst);
42
+ }
43
+ if (logger) {
44
+ logger(`exchange-cli: repaired missing runtime path ${path.basename(dst)}`);
45
+ }
46
+ return true;
47
+ }
48
+
49
+ function resolveFrameworkVersionDir(internalDir) {
50
+ const versionsDir = path.join(internalDir, 'Python.framework', 'Versions');
51
+ if (!fs.existsSync(versionsDir)) {
52
+ return null;
53
+ }
54
+ const currentDir = path.join(versionsDir, 'Current');
55
+ if (fs.existsSync(path.join(currentDir, 'Python'))) {
56
+ return currentDir;
57
+ }
58
+
59
+ const candidates = fs
60
+ .readdirSync(versionsDir, { withFileTypes: true })
61
+ .filter((entry) => entry.isDirectory() && entry.name !== 'Current')
62
+ .map((entry) => path.join(versionsDir, entry.name))
63
+ .filter((dirPath) => fs.existsSync(path.join(dirPath, 'Python')))
64
+ .sort();
65
+
66
+ if (candidates.length === 0) {
67
+ return null;
68
+ }
69
+ return candidates[candidates.length - 1];
70
+ }
71
+
72
+ function ensureDarwinArm64RuntimeLayout(binaryPath, logger = null) {
73
+ if (!(process.platform === 'darwin' && process.arch === 'arm64')) {
74
+ return { changed: false };
75
+ }
76
+ const binDir = path.dirname(binaryPath);
77
+ const internalDir = path.join(binDir, '_internal');
78
+ if (!fs.existsSync(internalDir)) {
79
+ return { changed: false };
80
+ }
81
+
82
+ const frameworkVersionDir = resolveFrameworkVersionDir(internalDir);
83
+ if (!frameworkVersionDir) {
84
+ return { changed: false };
85
+ }
86
+ const sourcePython = path.join(frameworkVersionDir, 'Python');
87
+ const sourceResources = path.join(frameworkVersionDir, 'Resources');
88
+
89
+ const targets = [
90
+ { src: sourcePython, dst: path.join(internalDir, 'Python') },
91
+ { src: sourcePython, dst: path.join(internalDir, 'Python.framework', 'Python') },
92
+ { src: sourceResources, dst: path.join(internalDir, 'Python.framework', 'Resources') },
93
+ {
94
+ src: frameworkVersionDir,
95
+ dst: path.join(internalDir, 'Python.framework', 'Versions', 'Current'),
96
+ },
97
+ ];
98
+
99
+ let changed = false;
100
+ for (const target of targets) {
101
+ changed = copyIfMissing(target.src, target.dst, logger) || changed;
102
+ }
103
+
104
+ try {
105
+ fs.chmodSync(binaryPath, 0o755);
106
+ } catch {
107
+ // Best effort only.
108
+ }
109
+ return { changed };
110
+ }
111
+
112
+ module.exports = {
113
+ ensureDarwinArm64RuntimeLayout,
114
+ };
package/install.js CHANGED
@@ -2,6 +2,7 @@
2
2
  'use strict';
3
3
 
4
4
  const fs = require('fs');
5
+ const { ensureDarwinArm64RuntimeLayout } = require('./bin/runtime-layout');
5
6
 
6
7
  const PLATFORM_PACKAGES = {
7
8
  'darwin-arm64': '@backtomyfuture/exchange-cli-darwin-arm64',
@@ -19,6 +20,7 @@ const ext = process.platform === 'win32' ? '.exe' : '';
19
20
 
20
21
  try {
21
22
  const binaryPath = require.resolve(`${pkg}/bin/exchange-cli${ext}`);
23
+ ensureDarwinArm64RuntimeLayout(binaryPath, (message) => console.log(message));
22
24
  if (process.platform !== 'win32') {
23
25
  fs.chmodSync(binaryPath, 0o755);
24
26
  console.log(`exchange-cli: set executable permission for ${platformKey}`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@backtomyfuture/exchange-cli",
3
- "version": "0.1.4",
3
+ "version": "0.1.6",
4
4
  "description": "Exchange Web Services CLI - email, calendar, tasks, contacts. Designed for AI agents.",
5
5
  "bin": {
6
6
  "exchange-cli": "bin/exchange-cli.js"
@@ -13,7 +13,7 @@
13
13
  "install.js"
14
14
  ],
15
15
  "optionalDependencies": {
16
- "@backtomyfuture/exchange-cli-darwin-arm64": "0.1.4"
16
+ "@backtomyfuture/exchange-cli-darwin-arm64": "0.1.6"
17
17
  },
18
18
  "engines": {
19
19
  "node": ">=14"