@kokiito0926/cli2module 0.0.7 → 0.0.8

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 (3) hide show
  1. package/example.js +11 -13
  2. package/index.js +1 -14
  3. package/package.json +1 -1
package/example.js CHANGED
@@ -2,18 +2,16 @@
2
2
 
3
3
  import { cli2module } from "./index.js";
4
4
 
5
- console.log('--- Case 1: Running zx help ---');
5
+ // const result = await cli2module("zx/cli", []);
6
6
  const result = await cli2module("zx/cli", ["--help"]);
7
- console.log(`Code: ${result.code}`);
8
- console.log(`Stdout length: ${result.stdout.length}`);
7
+ // const result = await cli2module("zx/cli", ["--version"]);
8
+ console.log(result);
9
+ console.log(result?.code);
10
+ console.log(result?.stdout);
11
+ console.log(result?.stderr);
9
12
 
10
- console.log('\n--- Case 2: Passing stdin to zx ---');
11
- const result2 = await cli2module("zx/cli", [], 'console.log("Hello, zx!")');
12
- console.log(`Stdout: ${result2.stdout}`);
13
-
14
- console.log('\n--- Case 3: Error handling (invalid module) ---');
15
- try {
16
- await cli2module("non-existent-module");
17
- } catch (err) {
18
- console.log(`Caught expected error: ${err.message}`);
19
- }
13
+ const result2 = await cli2module("zx/cli", [], 'console.log("Hello, world!")');
14
+ console.log(result2);
15
+ console.log(result2?.code);
16
+ console.log(result2?.stdout);
17
+ console.log(result2?.stderr);
package/index.js CHANGED
@@ -21,8 +21,6 @@ function runInWorker(scriptPath, args = [], input = "") {
21
21
  try {
22
22
  await import('file:///' + workerData.path.replace(/\\\\/g, '/'));
23
23
  } catch (err) {
24
- // ワーカースレッド内での例外(構文エラーやインポートエラー等)を確実に投げ、
25
- // 親スレッドの 'error' イベントでキャッチできるようにする。
26
24
  throw err;
27
25
  }
28
26
  `;
@@ -67,18 +65,7 @@ function runInWorker(scriptPath, args = [], input = "") {
67
65
  }
68
66
 
69
67
  export async function cli2module(specifier, args = [], input = "") {
70
- let cliUrl;
71
- try {
72
- // 相対パス(./ か ../)で始まる場合は、直感的な動作のために process.cwd() を基準に解決を試みる
73
- if (specifier.startsWith("./") || specifier.startsWith("../")) {
74
- cliUrl = pathToFileURL(path.resolve(process.cwd(), specifier)).href;
75
- } else {
76
- cliUrl = await import.meta.resolve(specifier);
77
- }
78
- } catch (err) {
79
- throw new Error(`Failed to resolve specifier "${specifier}": ${err.message}`);
80
- }
81
-
68
+ const cliUrl = await import.meta.resolve(specifier);
82
69
  const cliPath = fileURLToPath(cliUrl);
83
70
  return await runInWorker(cliPath, args, input);
84
71
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kokiito0926/cli2module",
3
- "version": "0.0.7",
3
+ "version": "0.0.8",
4
4
  "private": false,
5
5
  "description": "CLIのツールをワーカースレッドで実行することができるライブラリです。",
6
6
  "keywords": [