cclaw-cli 8.1.1 → 8.1.2
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/dist/cli.js +33 -2
- package/dist/constants.d.ts +1 -1
- package/dist/constants.js +1 -1
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { realpathSync } from "node:fs";
|
|
4
|
+
import { fileURLToPath } from "node:url";
|
|
2
5
|
import { CCLAW_VERSION } from "./constants.js";
|
|
3
6
|
import { initCclaw, syncCclaw, uninstallCclaw, upgradeCclaw } from "./install.js";
|
|
4
7
|
import { configureLogger, error as logError, info } from "./logger.js";
|
|
@@ -112,8 +115,36 @@ export async function runCli(argv, context) {
|
|
|
112
115
|
return 2;
|
|
113
116
|
}
|
|
114
117
|
}
|
|
115
|
-
|
|
116
|
-
|
|
118
|
+
/**
|
|
119
|
+
* True when this module is the program entry point. Resolves both the
|
|
120
|
+
* argv[1] path and the import.meta.url to their realpath because:
|
|
121
|
+
* - `npx cclaw-cli` invokes the CLI through a symlink under
|
|
122
|
+
* `~/.npm/_npx/<hash>/node_modules/.bin/cclaw-cli` that points at the
|
|
123
|
+
* real `dist/cli.js`. argv[1] keeps the symlink path, but
|
|
124
|
+
* import.meta.url resolves through to the real file. The naive
|
|
125
|
+
* `import.meta.url === \`file://${argv[1]}\`` check returns false in
|
|
126
|
+
* this case and the CLI silently exits 0 without doing anything.
|
|
127
|
+
* - On macOS `/tmp` is a symlink to `/private/tmp`, which produces the
|
|
128
|
+
* same mismatch even when no user-level symlink is involved.
|
|
129
|
+
* - `npm install -g cclaw-cli` creates a similar symlink in the global
|
|
130
|
+
* bin directory.
|
|
131
|
+
*
|
|
132
|
+
* Mirrors the v7.x `isDirectExecution()` check that is known to work
|
|
133
|
+
* across npx, global installs, and macOS path normalisation.
|
|
134
|
+
*/
|
|
135
|
+
function isDirectExecution() {
|
|
136
|
+
if (!process.argv[1])
|
|
137
|
+
return false;
|
|
138
|
+
try {
|
|
139
|
+
const entryPath = realpathSync(path.resolve(process.argv[1]));
|
|
140
|
+
const modulePath = realpathSync(fileURLToPath(import.meta.url));
|
|
141
|
+
return entryPath === modulePath;
|
|
142
|
+
}
|
|
143
|
+
catch {
|
|
144
|
+
return false;
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
if (isDirectExecution()) {
|
|
117
148
|
runCli(process.argv.slice(2), { cwd: process.cwd(), stdout: process.stdout, stderr: process.stderr })
|
|
118
149
|
.then((code) => {
|
|
119
150
|
process.exit(code);
|
package/dist/constants.d.ts
CHANGED
package/dist/constants.js
CHANGED