@mac-bug-screenshot/native-host 1.0.4 → 1.0.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.
package/README.md CHANGED
@@ -22,7 +22,7 @@ mac-bug-screenshot-install <확장_프로그램_ID>
22
22
  ## 게시 정보
23
23
 
24
24
  - npm 패키지: https://www.npmjs.com/package/@mac-bug-screenshot/native-host
25
- - 현재 버전: 1.0.2
25
+ - 현재 버전: 1.0.5
26
26
 
27
27
  ## 문제 해결
28
28
 
package/bin/install.js CHANGED
@@ -2,12 +2,11 @@
2
2
  const fs = require("fs");
3
3
  const path = require("path");
4
4
  const os = require("os");
5
- const { execSync } = require("child_process");
6
5
 
7
6
  const HOST_NAME = "com.sobbangcompany.mac_bug_screenshot";
8
7
  const ROOT_DIR = path.resolve(__dirname, "..");
9
8
  const TEMPLATE_PATH = path.join(ROOT_DIR, "manifest.template.json");
10
- const HOST_PATH = resolveGlobalHostPath();
9
+ const HOST_PATH = path.join(ROOT_DIR, "host.js");
11
10
  const WRAPPER_DIR = path.join(os.homedir(), ".mac-bug-screenshot");
12
11
  const WRAPPER_PATH = path.join(WRAPPER_DIR, "native-host.sh");
13
12
  const TARGET_DIR = path.join(
@@ -36,13 +35,18 @@ function main() {
36
35
  .replace(/__HOST_PATH__/g, WRAPPER_PATH)
37
36
  .replace(/__EXTENSION_ID__/g, extensionId);
38
37
 
38
+ if (!fs.existsSync(HOST_PATH)) {
39
+ console.error("host.js를 찾을 수 없습니다:", HOST_PATH);
40
+ process.exit(1);
41
+ }
42
+
39
43
  fs.mkdirSync(WRAPPER_DIR, { recursive: true });
40
44
  const wrapperScript = [
41
45
  "#!/bin/sh",
42
46
  `NODE_PATH="${process.execPath}"`,
43
47
  `HOST_PATH="${HOST_PATH}"`,
44
48
  'exec "$NODE_PATH" "$HOST_PATH"'
45
- ].join("\n");
49
+ ].join("\n") + "\n";
46
50
  fs.writeFileSync(WRAPPER_PATH, wrapperScript);
47
51
  fs.chmodSync(WRAPPER_PATH, 0o755);
48
52
 
@@ -54,16 +58,4 @@ function main() {
54
58
  console.log(TARGET_PATH);
55
59
  }
56
60
 
57
- function resolveGlobalHostPath() {
58
- try {
59
- const npmRoot = execSync("npm root -g", { encoding: "utf8" }).trim();
60
- if (npmRoot) {
61
- return path.join(npmRoot, "@mac-bug-screenshot", "native-host", "host.js");
62
- }
63
- } catch (error) {
64
- // fallback to local package path
65
- }
66
- return path.join(ROOT_DIR, "host.js");
67
- }
68
-
69
61
  main();
package/host.js CHANGED
@@ -50,32 +50,29 @@ function writeMessage(message) {
50
50
 
51
51
  function readMessage() {
52
52
  return new Promise((resolve, reject) => {
53
- const lengthBuffer = Buffer.alloc(4);
54
- let lengthOffset = 0;
53
+ let buffer = Buffer.alloc(0);
55
54
 
56
- function readLength(chunk) {
57
- chunk.copy(lengthBuffer, lengthOffset);
58
- lengthOffset += chunk.length;
59
- if (lengthOffset >= 4) {
60
- const length = lengthBuffer.readUInt32LE(0);
61
- const messageBuffer = Buffer.alloc(length);
62
- let messageOffset = 0;
55
+ function onData(chunk) {
56
+ buffer = Buffer.concat([buffer, chunk]);
57
+ if (buffer.length < 4) {
58
+ return;
59
+ }
63
60
 
64
- function readMessageBody(bodyChunk) {
65
- bodyChunk.copy(messageBuffer, messageOffset);
66
- messageOffset += bodyChunk.length;
67
- if (messageOffset >= length) {
68
- process.stdin.removeListener("data", readMessageBody);
69
- resolve(JSON.parse(messageBuffer.toString("utf8")));
70
- }
71
- }
61
+ const length = buffer.readUInt32LE(0);
62
+ if (buffer.length < 4 + length) {
63
+ return;
64
+ }
72
65
 
73
- process.stdin.removeListener("data", readLength);
74
- process.stdin.on("data", readMessageBody);
66
+ const messageBuffer = buffer.subarray(4, 4 + length);
67
+ process.stdin.removeListener("data", onData);
68
+ try {
69
+ resolve(JSON.parse(messageBuffer.toString("utf8")));
70
+ } catch (error) {
71
+ reject(error);
75
72
  }
76
73
  }
77
74
 
78
- process.stdin.on("data", readLength);
75
+ process.stdin.on("data", onData);
79
76
  process.stdin.on("error", reject);
80
77
  });
81
78
  }
@@ -92,6 +89,8 @@ async function main() {
92
89
  writeMessage({ ok: true, outputPath });
93
90
  } catch (error) {
94
91
  writeMessage({ ok: false, error: error.message });
92
+ } finally {
93
+ setImmediate(() => process.exit(0));
95
94
  }
96
95
  }
97
96
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mac-bug-screenshot/native-host",
3
- "version": "1.0.4",
3
+ "version": "1.0.6",
4
4
  "description": "Native messaging host for Mac Bug Screenshot.",
5
5
  "bin": {
6
6
  "mac-bug-screenshot-install": "bin/install.js"