Skip to content

Commit 9b07770

Browse files
authored
chore: release 1.0.8 (#7)
* chore: remove obsolete VibeSync configuration files and update changelog links * chore: update package references to @nicepkg/vsync and release version 1.0.9 * chore: update package.json with repository details, author information, and keywords * chore: update package.json description to clarify functionality of the CLI tool * chore: remove obsolete changeset for version 10 * feat: add isMainModule function to determine if the current module is the main entry point * fix: resolve CLI functionality issue
1 parent 07d41f7 commit 9b07770

File tree

4 files changed

+66
-4
lines changed

4 files changed

+66
-4
lines changed

.changeset/short-coins-push.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@nicepkg/vsync": patch
3+
---
4+
5+
fix cli not working

cli/src/index.ts

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,34 @@
77
* Single source of truth → Compile to multiple formats → Diff-based sync
88
*/
99

10+
import { realpathSync } from "node:fs";
11+
import { resolve } from "node:path";
12+
import { fileURLToPath } from "node:url";
1013
import { runCLI } from "./cli-setup.js";
1114

1215
export async function main(): Promise<void> {
1316
await runCLI();
1417
}
1518

19+
export function isMainModule(
20+
argvPath: string | undefined,
21+
moduleUrl: string,
22+
): boolean {
23+
if (!argvPath) {
24+
return false;
25+
}
26+
27+
try {
28+
const argvRealPath = realpathSync(resolve(argvPath));
29+
const moduleRealPath = realpathSync(fileURLToPath(moduleUrl));
30+
return argvRealPath === moduleRealPath;
31+
} catch {
32+
return false;
33+
}
34+
}
35+
1636
// Run CLI if this is the main module
17-
if (import.meta.url === `file://${process.argv[1]}`) {
37+
if (isMainModule(process.argv[1], import.meta.url)) {
1838
main().catch((error) => {
1939
console.error("Fatal error:", error);
2040
process.exit(1);

cli/src/utils/config-initializer.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,11 @@ export async function ensureLanguageConfig(): Promise<Language> {
4747
message: "Choose your preferred language / 选择你的语言偏好:",
4848
choices: [
4949
{
50-
name: `English (detected: ${systemLang === "en" ? "✓" : "×"})`,
50+
name: `English`,
5151
value: "en",
5252
},
5353
{
54-
name: `中文 (detected: ${systemLang === "zh" ? "✓" : "×"})`,
54+
name: `中文`,
5555
value: "zh",
5656
},
5757
],

cli/test/index.test.ts

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
import { describe, it, expect } from "vitest";
2-
import { main } from "@src/index.js";
2+
import { mkdtemp, rm, symlink, writeFile } from "node:fs/promises";
3+
import { tmpdir } from "node:os";
4+
import { join, relative } from "node:path";
5+
import { pathToFileURL } from "node:url";
6+
import { isMainModule, main } from "@src/index.js";
37

48
describe("CLI Entry Point", () => {
59
it("should export main function", () => {
@@ -10,4 +14,37 @@ describe("CLI Entry Point", () => {
1014
it("should be async function", () => {
1115
expect(main.constructor.name).toBe("AsyncFunction");
1216
});
17+
18+
it("detects main module with relative argv path", async () => {
19+
const dir = await mkdtemp(join(tmpdir(), "vsync-index-"));
20+
const filePath = join(dir, "index.js");
21+
await writeFile(filePath, "console.log('test');");
22+
23+
try {
24+
const metaUrl = pathToFileURL(filePath).href;
25+
const argvPath = relative(process.cwd(), filePath);
26+
expect(isMainModule(argvPath, metaUrl)).toBe(true);
27+
} finally {
28+
await rm(dir, { recursive: true, force: true });
29+
}
30+
});
31+
32+
it("detects main module when argv is a symlink", async () => {
33+
const dir = await mkdtemp(join(tmpdir(), "vsync-index-"));
34+
const filePath = join(dir, "index.js");
35+
const linkPath = join(dir, "index-link.js");
36+
await writeFile(filePath, "console.log('test');");
37+
await symlink(filePath, linkPath);
38+
39+
try {
40+
const metaUrl = pathToFileURL(filePath).href;
41+
expect(isMainModule(linkPath, metaUrl)).toBe(true);
42+
} finally {
43+
await rm(dir, { recursive: true, force: true });
44+
}
45+
});
46+
47+
it("returns false when argv is missing", () => {
48+
expect(isMainModule(undefined, "file:///tmp/index.js")).toBe(false);
49+
});
1350
});

0 commit comments

Comments
 (0)