@jira-deploy/core 1.0.6 → 1.0.7

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": "@jira-deploy/core",
3
- "version": "1.0.6",
3
+ "version": "1.0.7",
4
4
  "type": "module",
5
5
  "main": "./index.js",
6
6
  "repository": {
@@ -30,6 +30,6 @@
30
30
  "dotenv": "^16.3.0"
31
31
  },
32
32
  "scripts": {
33
- "test": "node --test tools.test.js"
33
+ "test": "node --test tools.test.js tools/jabber.test.js"
34
34
  }
35
35
  }
package/tools/jabber.js CHANGED
@@ -7,11 +7,36 @@ import fs from 'fs';
7
7
  import path from 'path';
8
8
  import {error, ok} from './helpers.js';
9
9
 
10
- function getDefaultScriptPath() {
10
+ function realpathOrNull(filePath) {
11
+ try {
12
+ return fs.realpathSync(filePath);
13
+ } catch {
14
+ return null;
15
+ }
16
+ }
17
+
18
+ function unique(values) {
19
+ return [...new Set(values.filter(Boolean))];
20
+ }
21
+
22
+ export function resolveJabberNotifyScriptPath({
23
+ env = process.env,
24
+ execPath = process.execPath,
25
+ cwd = process.cwd(),
26
+ } = {}) {
27
+ if (env.JABBER_NOTIFY_SCRIPT) {
28
+ return env.JABBER_NOTIFY_SCRIPT;
29
+ }
30
+
31
+ const resolvedExecPath = realpathOrNull(execPath);
11
32
  const candidates = [
12
- path.resolve(process.cwd(), 'packages/jira-core/scripts/jabber_notify.py'),
13
- path.resolve(process.cwd(), 'scripts/jabber_notify.py'),
33
+ ...unique([resolvedExecPath, execPath]).map((candidate) =>
34
+ path.resolve(path.dirname(candidate), 'scripts/jabber_notify.py')
35
+ ),
36
+ path.resolve(cwd, 'packages/jira-core/scripts/jabber_notify.py'),
37
+ path.resolve(cwd, 'scripts/jabber_notify.py'),
14
38
  ];
39
+
15
40
  return candidates.find((candidate) => fs.existsSync(candidate)) ?? candidates[0];
16
41
  }
17
42
 
@@ -49,7 +74,7 @@ export function getJabberToolDefinitions() {
49
74
  // ── Handler ───────────────────────────────────────────────────────
50
75
 
51
76
  export async function handleSendJabberMessage(args, _ctx) {
52
- const scriptPath = process.env.JABBER_NOTIFY_SCRIPT ?? getDefaultScriptPath();
77
+ const scriptPath = resolveJabberNotifyScriptPath();
53
78
 
54
79
  // dryRun 模式:不實際發送,直接回傳預覽
55
80
  if (args.dryRun) {
@@ -0,0 +1,35 @@
1
+ import test from 'node:test';
2
+ import assert from 'node:assert/strict';
3
+ import {mkdtempSync, mkdirSync, writeFileSync} from 'node:fs';
4
+ import {tmpdir} from 'node:os';
5
+ import {join} from 'node:path';
6
+
7
+ import {resolveJabberNotifyScriptPath} from './jabber.js';
8
+
9
+ test('resolveJabberNotifyScriptPath ignores empty env and prefers packaged script beside binary', () => {
10
+ const root = mkdtempSync(join(tmpdir(), 'ares-jabber-'));
11
+ const binDir = join(root, 'app');
12
+ const scriptPath = join(binDir, 'scripts', 'jabber_notify.py');
13
+ mkdirSync(join(binDir, 'scripts'), {recursive: true});
14
+ writeFileSync(scriptPath, '#!/usr/bin/env python3\n');
15
+
16
+ assert.equal(
17
+ resolveJabberNotifyScriptPath({
18
+ env: {JABBER_NOTIFY_SCRIPT: ''},
19
+ execPath: join(binDir, 'ares'),
20
+ cwd: join(root, 'work'),
21
+ }),
22
+ scriptPath,
23
+ );
24
+ });
25
+
26
+ test('resolveJabberNotifyScriptPath keeps explicit env override', () => {
27
+ assert.equal(
28
+ resolveJabberNotifyScriptPath({
29
+ env: {JABBER_NOTIFY_SCRIPT: '/custom/jabber_notify.py'},
30
+ execPath: '/opt/ares/ares',
31
+ cwd: '/tmp',
32
+ }),
33
+ '/custom/jabber_notify.py',
34
+ );
35
+ });