zhitalk 0.1.2 → 0.1.3
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/index.js +12 -4
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { Command } from 'commander';
|
|
3
|
-
import { readFileSync, existsSync } from 'fs';
|
|
3
|
+
import { readFileSync, existsSync, realpathSync } from 'fs';
|
|
4
4
|
import { join, dirname } from 'path';
|
|
5
|
-
import { fileURLToPath } from 'url';
|
|
5
|
+
import { fileURLToPath, pathToFileURL } from 'url';
|
|
6
6
|
import { CONFIG_PATH } from './agent/config.js';
|
|
7
7
|
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
8
8
|
const pkg = JSON.parse(readFileSync(join(__dirname, '../package.json'), 'utf-8'));
|
|
@@ -100,8 +100,16 @@ async function main() {
|
|
|
100
100
|
});
|
|
101
101
|
program.parse();
|
|
102
102
|
}
|
|
103
|
-
|
|
103
|
+
function isMainModule() {
|
|
104
|
+
try {
|
|
105
|
+
const realArgvPath = realpathSync(process.argv[1]);
|
|
106
|
+
return import.meta.url === pathToFileURL(realArgvPath).href;
|
|
107
|
+
}
|
|
108
|
+
catch {
|
|
109
|
+
return false;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
104
112
|
// 仅在直接运行本文件时执行 main,避免被测试导入时自动执行
|
|
105
|
-
if (
|
|
113
|
+
if (isMainModule()) {
|
|
106
114
|
main();
|
|
107
115
|
}
|
package/package.json
CHANGED