easyresearch 0.0.2 → 0.0.48

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.
Files changed (2) hide show
  1. package/launcher.mjs +44 -21
  2. package/package.json +12 -4
package/launcher.mjs CHANGED
@@ -8,14 +8,12 @@
8
8
  import { spawnSync } from "node:child_process";
9
9
  import { createRequire } from "node:module";
10
10
  import { existsSync } from "node:fs";
11
- import { dirname, join } from "node:path";
11
+ import { dirname, join, resolve } from "node:path";
12
12
  import { fileURLToPath } from "node:url";
13
13
  import { readFileSync } from "node:fs";
14
14
 
15
15
  const __dirname = dirname(fileURLToPath(import.meta.url));
16
16
  const require = createRequire(import.meta.url);
17
- const packageJson = JSON.parse(readFileSync(join(__dirname, "package.json"), "utf8"));
18
-
19
17
  const platformMap = {
20
18
  darwin: "darwin",
21
19
  linux: "linux",
@@ -23,31 +21,56 @@ const platformMap = {
23
21
  };
24
22
  const supportedArchs = ["x64", "arm64"];
25
23
 
26
- const platform = platformMap[process.platform];
27
- const arch = supportedArchs.includes(process.arch) ? process.arch : undefined;
28
- const name = platform && arch ? `easyresearch-${platform}-${arch}` : undefined;
24
+ export function missingOptionalPackageMessage(name) {
25
+ return `Required optional package ${name} is not installed. Run npm reinstall easyresearch and ensure optional dependencies are enabled.`;
26
+ }
29
27
 
30
- if (!name || !packageJson.optionalDependencies?.[name]) {
31
- console.error(
32
- `easyresearch does not ship a binary for ${process.platform}-${process.arch}. Supported platforms: linux-x64, darwin-arm64, windows-x64.`,
33
- );
34
- process.exit(1);
28
+ export function describeSpawnFailure(result, target) {
29
+ if (result.error) {
30
+ const code = result.error.code ? ` (${result.error.code})` : "";
31
+ return `Failed to execute ${target}${code}: ${result.error.message}`;
32
+ }
33
+ if (result.signal) return `${target} was terminated by signal ${result.signal}.`;
34
+ return `${target} exited with code ${result.status ?? 1}.`;
35
35
  }
36
36
 
37
- function binaryPath() {
37
+ function binaryPath(name, platform) {
38
38
  const packageJsonPath = require.resolve(`${name}/package.json`);
39
39
  const binary = join(dirname(packageJsonPath), "bin", platform === "windows" ? "easyresearch.exe" : "easyresearch");
40
- if (!existsSync(binary)) throw new Error(`Binary not found at ${binary}`);
40
+ if (!existsSync(binary)) throw new Error(`The ${name} package is installed but its executable is missing at ${binary}. Reinstall easyresearch.`);
41
41
  return binary;
42
42
  }
43
43
 
44
- let target;
45
- try {
46
- target = binaryPath();
47
- } catch (error) {
48
- console.error(error instanceof Error ? error.message : String(error));
49
- process.exit(1);
44
+ export function runLauncher(argv = process.argv.slice(2)) {
45
+ const packageJson = JSON.parse(readFileSync(join(__dirname, "package.json"), "utf8"));
46
+ const platform = platformMap[process.platform];
47
+ const arch = supportedArchs.includes(process.arch) ? process.arch : undefined;
48
+ const name = platform && arch ? `easyresearch-${platform}-${arch}` : undefined;
49
+ if (!name || !packageJson.optionalDependencies?.[name]) {
50
+ console.error(
51
+ `easyresearch does not ship a binary for ${process.platform}-${process.arch}. Supported platforms: linux-x64, darwin-arm64, windows-x64.`,
52
+ );
53
+ return 1;
54
+ }
55
+
56
+ let target;
57
+ try {
58
+ target = binaryPath(name, platform);
59
+ } catch (error) {
60
+ const candidate = error;
61
+ if (candidate && typeof candidate === "object" && candidate.code === "MODULE_NOT_FOUND") {
62
+ console.error(missingOptionalPackageMessage(name));
63
+ } else {
64
+ console.error(error instanceof Error ? error.message : String(error));
65
+ }
66
+ return 1;
67
+ }
68
+
69
+ const result = spawnSync(target, argv, { stdio: "inherit" });
70
+ if (result.error || result.signal || result.status !== 0) console.error(describeSpawnFailure(result, target));
71
+ return result.status ?? 1;
50
72
  }
51
73
 
52
- const result = spawnSync(target, process.argv.slice(2), { stdio: "inherit" });
53
- process.exit(result.status ?? 1);
74
+ if (process.argv[1] && resolve(process.argv[1]) === fileURLToPath(import.meta.url)) {
75
+ process.exit(runLauncher());
76
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "easyresearch",
3
- "version": "0.0.2",
3
+ "version": "0.0.48",
4
4
  "description": "Automated academic paper writing CLI built on the Pi agent harness",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -14,12 +14,20 @@
14
14
  "ai",
15
15
  "latex"
16
16
  ],
17
+ "files": [
18
+ "launcher.mjs",
19
+ "README.md",
20
+ "LICENSE"
21
+ ],
17
22
  "bin": {
18
23
  "easyresearch": "./launcher.mjs"
19
24
  },
20
25
  "optionalDependencies": {
21
- "easyresearch-linux-x64": "0.0.2",
22
- "easyresearch-darwin-arm64": "0.0.2",
23
- "easyresearch-windows-x64": "0.0.2"
26
+ "easyresearch-linux-x64": "0.0.48",
27
+ "easyresearch-darwin-arm64": "0.0.48",
28
+ "easyresearch-windows-x64": "0.0.48"
29
+ },
30
+ "publishConfig": {
31
+ "registry": "https://registry.npmjs.org/"
24
32
  }
25
33
  }