binary-collections 2.0.11 → 2.0.12
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/.opencode/package.json +5 -0
- package/binaries/rmx +15 -1
- package/binaries/rmx.cmd +12 -0
- package/binaries/test-cjs +9 -1
- package/binaries/test-cjs.cmd +16 -1
- package/binaries/test-esm +16 -0
- package/binaries/test-esm.cjs +178 -0
- package/binaries/test-esm.cmd +23 -0
- package/binaries/yarn-clean +1 -1
- package/binaries/yarn-clean.cmd +1 -1
- package/binaries/yarn-clean.py +33 -15
- package/binaries/yc +110 -0
- package/binaries/yc.cjs +178 -0
- package/lib/binary-collections/config.cjs +126 -0
- package/lib/binary-collections/config.mjs +7 -0
- package/lib/binary-collections/executeScript.cjs +19 -0
- package/lib/binary-collections/executeScript.d.cts +12 -0
- package/lib/binary-collections/executeScript.mjs +6 -0
- package/lib/binary-collections/findScript.cjs +284 -0
- package/lib/binary-collections/findScript.d.cts +12 -0
- package/lib/binary-collections/findScript.mjs +7 -0
- package/lib/binary-collections/listScript.cjs +266 -0
- package/lib/binary-collections/listScript.d.cts +19 -0
- package/lib/binary-collections/listScript.mjs +7 -0
- package/lib/binary-collections.cjs +224 -137
- package/lib/binary-collections.mjs +22 -282
- package/lib/changelog.cjs +2 -2
- package/lib/changelog.mjs +1 -1
- package/lib/{chunk-AJDD5DZM.mjs → chunk-2LSRSEXF.mjs} +1 -1
- package/lib/{chunk-Z6JLYU2J.mjs → chunk-5RTXZVCW.mjs} +2 -2
- package/lib/{chunk-XA3SNBPA.mjs → chunk-66KDU4TX.mjs} +93 -9
- package/lib/chunk-6PU7BAHB.mjs +61 -0
- package/lib/chunk-C6D2TTYU.mjs +32 -0
- package/lib/chunk-FB2WKVJD.mjs +158 -0
- package/lib/{chunk-NCXAP7AA.mjs → chunk-G5UUEWUO.mjs} +9 -5
- package/lib/{chunk-N436BNBK.mjs → chunk-GAGABICI.mjs} +19 -13
- package/lib/chunk-H44UWUFY.mjs +105 -0
- package/lib/chunk-NCZPTKDV.mjs +79 -0
- package/lib/chunk-NGFK3EYW.mjs +28 -0
- package/lib/chunk-NVEG3LEZ.mjs +143 -0
- package/lib/chunk-OGXVGBRI.mjs +29 -0
- package/lib/chunk-OXV52GD5.mjs +62 -0
- package/lib/chunk-PXBMHE7O.mjs +35 -0
- package/lib/chunk-R5FJOR63.mjs +47 -0
- package/lib/chunk-SPTECFE5.mjs +180 -0
- package/lib/chunk-UXCFNAR6.mjs +55 -0
- package/lib/chunk-V2IBPCEV.mjs +39 -0
- package/lib/chunk-XPJGCDOD.mjs +14 -0
- package/lib/chunk-ZOWVMII3.mjs +228 -0
- package/lib/clean-github-actions-caches-cli.cjs +465 -0
- package/lib/clean-github-actions-caches-cli.d.cts +1 -0
- package/lib/clean-github-actions-caches-cli.mjs +56 -0
- package/lib/clean-github-actions-caches.cjs +149 -205
- package/lib/clean-github-actions-caches.d.cts +15 -1
- package/lib/clean-github-actions-caches.mjs +4 -130
- package/lib/cross-env/command.cjs +63 -0
- package/lib/cross-env/command.d.ts +8 -0
- package/lib/cross-env/command.js +45 -0
- package/lib/cross-env/command.mjs +9 -0
- package/lib/cross-env/index.cjs +178 -0
- package/lib/cross-env/index.d.ts +8 -0
- package/lib/cross-env/index.js +102 -0
- package/lib/cross-env/index.mjs +101 -0
- package/lib/cross-env/variable.cjs +60 -0
- package/lib/cross-env/variable.d.ts +7 -0
- package/lib/cross-env/variable.js +59 -0
- package/lib/cross-env/variable.mjs +9 -0
- package/lib/del-gradle.cjs +2 -2
- package/lib/del-gradle.js +8 -8
- package/lib/del-gradle.mjs +1 -1
- package/lib/del-node-modules.js +24 -24
- package/lib/del-ps.cjs +2 -2
- package/lib/del-ps.js +8 -8
- package/lib/del-ps.mjs +1 -1
- package/lib/del-yarn-caches.cjs +2 -2
- package/lib/del-yarn-caches.js +2 -2
- package/lib/del-yarn-caches.mjs +1 -1
- package/lib/file/copy-cli.cjs +92 -0
- package/lib/file/copy-cli.d.mts +1 -0
- package/lib/file/copy-cli.mjs +55 -0
- package/lib/file/copy.cjs +56 -0
- package/lib/file/copy.d.mts +1 -0
- package/lib/file/copy.mjs +8 -0
- package/lib/file/move-cli.cjs +91 -0
- package/lib/file/move-cli.d.mts +1 -0
- package/lib/file/move-cli.mjs +55 -0
- package/lib/file/move.cjs +55 -0
- package/lib/file/move.d.mts +1 -0
- package/lib/file/move.mjs +8 -0
- package/lib/find-node-modules-cli.js +1 -1
- package/lib/free-chatgpt.cjs +21 -15
- package/lib/free-chatgpt.js +10 -10
- package/lib/free-chatgpt.mjs +2 -2
- package/lib/git/user-config.cjs +2 -2
- package/lib/git/user-config.mjs +2 -2
- package/lib/git-diff-cli.cjs +188 -42
- package/lib/git-diff-cli.mjs +5 -4
- package/lib/git-diff.cjs +188 -42
- package/lib/git-diff.d.ts +2 -1
- package/lib/git-diff.js +91 -34
- package/lib/git-diff.mjs +5 -4
- package/lib/git-fix.cjs +2 -2
- package/lib/git-fix.mjs +2 -2
- package/lib/git-purge.cjs +2 -2
- package/lib/git-purge.mjs +1 -1
- package/lib/index.d.ts +1 -1
- package/lib/kill-night-crows.cjs +7 -7
- package/lib/kill-night-crows.mjs +7 -7
- package/lib/node-cache-cleaner/npm.cjs +65 -0
- package/lib/node-cache-cleaner/npm.d.ts +2 -0
- package/lib/node-cache-cleaner/npm.js +41 -0
- package/lib/node-cache-cleaner/npm.mjs +10 -0
- package/lib/node-cache-cleaner/npx.cjs +89 -0
- package/lib/node-cache-cleaner/npx.d.ts +4 -0
- package/lib/node-cache-cleaner/npx.js +82 -0
- package/lib/{ps/index.d.mjs → node-cache-cleaner/npx.mjs} +6 -5
- package/lib/node-cache-cleaner/yarn.cjs +73 -0
- package/lib/node-cache-cleaner/yarn.d.ts +2 -0
- package/lib/node-cache-cleaner/yarn.js +62 -0
- package/lib/node-cache-cleaner/yarn.mjs +10 -0
- package/lib/node-cache-cleaner-cli.cjs +182 -0
- package/lib/node-cache-cleaner-cli.d.ts +2 -0
- package/lib/node-cache-cleaner-cli.js +60 -0
- package/lib/node-cache-cleaner-cli.mjs +56 -0
- package/lib/node-executor.cjs +91 -0
- package/lib/node-executor.d.cts +2 -0
- package/lib/node-executor.mjs +103 -0
- package/lib/npm-run-series.cjs +21 -28
- package/lib/npm-run-series.mjs +20 -6
- package/lib/package-resolutions-updater-cli.cjs +213 -128
- package/lib/package-resolutions-updater-cli.mjs +17 -39
- package/lib/package-resolutions-updater.cjs +204 -98
- package/lib/package-resolutions-updater.d.mts +20 -1
- package/lib/package-resolutions-updater.mjs +7 -5
- package/lib/print-directory-tree.cjs +2 -2
- package/lib/print-directory-tree.mjs +1 -1
- package/lib/ps/connected-domain.js +10 -10
- package/lib/ps/index.cjs +1 -1
- package/lib/ps/index.mjs +177 -171
- package/lib/ps/isWin.js +1 -1
- package/lib/ps/table-parser.js +6 -6
- package/lib/remove-module.cjs +2 -2
- package/lib/remove-module.mjs +1 -1
- package/lib/rm-node-module-cli.cjs +222 -0
- package/lib/rm-node-module-cli.d.cts +1 -0
- package/lib/rm-node-module-cli.mjs +89 -0
- package/lib/rm-node-modules.cjs +127 -0
- package/lib/rm-node-modules.d.cts +35 -0
- package/lib/{binary-collections-config.mjs → rm-node-modules.mjs} +3 -3
- package/lib/rmpath.cjs +2 -2
- package/lib/rmpath.mjs +1 -1
- package/lib/submodule-install.cjs +47 -34
- package/lib/submodule-install.mjs +46 -33
- package/lib/submodule-remove-cli.cjs +1 -2
- package/lib/submodule-remove-cli.js +3 -3
- package/lib/submodule-remove-cli.mjs +1 -2
- package/lib/utils/chatgpt.cjs +19 -13
- package/lib/utils/chatgpt.js +94 -94
- package/lib/utils/chatgpt.mjs +1 -1
- package/lib/utils/findEnvFiles.cjs +28 -46
- package/lib/utils/findEnvFiles.d.cts +19 -0
- package/lib/utils/findEnvFiles.mjs +3 -5
- package/lib/utils/findWorkspaceRoot.js +4 -4
- package/lib/utils/index.cjs +2 -2
- package/lib/utils/index.mjs +1 -1
- package/lib/utils/isGithubTokenValid.js +7 -7
- package/lib/{ps/index.d.cjs → utils/isWindows.cjs} +17 -3
- package/lib/utils/isWindows.d.ts +5 -0
- package/lib/utils/isWindows.js +10 -0
- package/lib/utils/isWindows.mjs +8 -0
- package/lib/utils/runBash.cjs +53 -0
- package/lib/utils/runBash.d.cts +12 -0
- package/lib/utils/runBash.mjs +66 -0
- package/lib/yarn-per-branch-lock-installer.cjs +97 -0
- package/lib/yarn-per-branch-lock-installer.d.cts +2 -0
- package/lib/yarn-per-branch-lock-installer.mjs +109 -0
- package/lib/yarn-reinstall.cjs +2 -2
- package/lib/yarn-reinstall.mjs +1 -1
- package/package.json +61 -52
- package/readme.html +784 -0
- package/readme.md +106 -218
- package/releases/readme.md +1 -1
- package/test/README.md +2 -2
- package/test-project/package.json +8 -2
- package/test-project/workspaces/workspace-a/package.json +135 -0
- package/test-project/workspaces/workspace-a/readme.md +20 -0
- package/test-project/workspaces/workspace-a/release/readme.md +42 -0
- package/test-project/workspaces/workspace-a/test/demo/package.json +25 -0
- package/test-project/workspaces/workspace-a/test/readme.md +12 -0
- package/test-project/workspaces/workspace-b/package.json +139 -0
- package/test-project/workspaces/workspace-b/readme.md +94 -0
- package/test-project/workspaces/workspace-b/requirements.txt +1 -0
- package/test-project/workspaces/workspace-b/test/sample-project/package.json +7 -0
- package/test-project/workspaces/workspace-b/themes/hexo-theme-flowbite/package.json +96 -0
- package/test-project/workspaces/workspace-b/themes/hexo-theme-flowbite/readme.md +156 -0
- package/tmp/rm-node-modules-test-project/package.json +17 -0
- package/tmp/rm-node-modules-test-project/packages/workspace-a/package.json +16 -0
- package/tmp/rm-node-modules-test-project/packages/workspace-b/package.json +16 -0
- package/tmp/test-repo/README.md +2 -35
- package/tmp/test-repo/package.json +13 -3
- package/docs-src/clean-github-actions-caches.md +0 -26
- package/docs-src/free-chatgpt.md +0 -26
- package/lib/binary-collections-config.cjs +0 -15
- package/lib/chunk-2CBJCW7E.mjs +0 -81
- package/lib/chunk-4UHL4WVN.mjs +0 -136
- package/lib/chunk-66PAU5PS.mjs +0 -31
- package/lib/chunk-6HHJRKFB.mjs +0 -59
- package/lib/chunk-7XTEJHOE.mjs +0 -193
- package/lib/chunk-FCDQGYBF.mjs +0 -136
- package/lib/chunk-GEYA2USY.mjs +0 -207
- package/lib/chunk-GJTGHXRA.mjs +0 -356
- package/lib/chunk-ID2WBTE2.mjs +0 -80
- package/lib/chunk-JXFOHKDM.mjs +0 -239
- package/lib/chunk-PDSXF5HY.mjs +0 -187
- package/lib/chunk-RWLXRTYP.mjs +0 -109
- package/lib/chunk-TOIVAQF7.mjs +0 -136
- package/lib/chunk-V5SKYJUB.mjs +0 -136
- package/lib/chunk-WSRETQCA.mjs +0 -59
- package/lib/chunk-YYLIQQKF.mjs +0 -31
- package/lib/ps/index.d.ts +0 -2
- package/lib/ps/index.js +0 -254
- package/lib/utils/findEnvFiles.d.ts +0 -8
- package/lib/utils/findEnvFiles.js +0 -121
- package/tmp/typedoc/readme.md +0 -320
- /package/lib/{binary-collections-config.d.cts → binary-collections/config.d.cts} +0 -0
package/lib/chunk-FCDQGYBF.mjs
DELETED
|
@@ -1,136 +0,0 @@
|
|
|
1
|
-
import { createRequire } from 'module'; const require = createRequire(import.meta.url);
|
|
2
|
-
import {
|
|
3
|
-
runChatGpt
|
|
4
|
-
} from "./chunk-N436BNBK.mjs";
|
|
5
|
-
import {
|
|
6
|
-
require_binary_collections_config
|
|
7
|
-
} from "./chunk-YYLIQQKF.mjs";
|
|
8
|
-
import {
|
|
9
|
-
require_utils
|
|
10
|
-
} from "./chunk-Z6JLYU2J.mjs";
|
|
11
|
-
import {
|
|
12
|
-
__toESM,
|
|
13
|
-
init_esm_shims
|
|
14
|
-
} from "./chunk-QQ4A6DLD.mjs";
|
|
15
|
-
|
|
16
|
-
// src/git-diff.js
|
|
17
|
-
init_esm_shims();
|
|
18
|
-
var import_binary_collections_config = __toESM(require_binary_collections_config(), 1);
|
|
19
|
-
import { execSync } from "child_process";
|
|
20
|
-
import fs from "fs-extra";
|
|
21
|
-
import path from "upath";
|
|
22
|
-
import { fileURLToPath } from "url";
|
|
23
|
-
var import_utils = __toESM(require_utils(), 1);
|
|
24
|
-
var __filename = fileURLToPath(import.meta.url);
|
|
25
|
-
var __dirname = path.dirname(__filename);
|
|
26
|
-
var DIFF_OUTPUT = (0, import_binary_collections_config.getTempPath)("git-diff.txt");
|
|
27
|
-
var GPT_DIFF_OUTPUT = (0, import_binary_collections_config.getTempPath)("gpt-question.txt");
|
|
28
|
-
var CACHE_DIR = path.dirname(DIFF_OUTPUT);
|
|
29
|
-
var DIFF_OUTPUT_RELATIVE = path.relative(process.cwd(), DIFF_OUTPUT);
|
|
30
|
-
var GPT_DIFF_OUTPUT_RELATIVE = path.relative(process.cwd(), GPT_DIFF_OUTPUT);
|
|
31
|
-
if (!fs.existsSync(CACHE_DIR)) {
|
|
32
|
-
fs.mkdirSync(CACHE_DIR, { recursive: true });
|
|
33
|
-
}
|
|
34
|
-
function showHelp() {
|
|
35
|
-
console.log("\u{1F4DD} Git Diff Helper");
|
|
36
|
-
console.log("\u{1F4C4} Usage:");
|
|
37
|
-
console.log(" \u{1F4C2} git-diff FILE Show staged diff of specified file");
|
|
38
|
-
console.log(" \u{1F4C2} git-diff --staged-only Show staged diff of all files");
|
|
39
|
-
console.log(" \u{1F4C2} git-diff -s | -S Same as --staged-only");
|
|
40
|
-
console.log(" \u{1F4C2} git-diff --ai Run ChatGPT automation for commit message");
|
|
41
|
-
console.log(" \u{1F4C2} git-diff --help | -h Show this help message");
|
|
42
|
-
console.log("");
|
|
43
|
-
console.log(`\u{1F4BE} Output is saved to: ${DIFF_OUTPUT_RELATIVE}`);
|
|
44
|
-
console.log(`\u{1F916} GPT prompt is saved to: ${GPT_DIFF_OUTPUT_RELATIVE}`);
|
|
45
|
-
process.exit(0);
|
|
46
|
-
}
|
|
47
|
-
function runGitDiff(command, successMessage, errorMessage) {
|
|
48
|
-
try {
|
|
49
|
-
console.log(`\u{1F50D} [i] Running command: ${command}`);
|
|
50
|
-
const result = execSync(command, {
|
|
51
|
-
encoding: "utf8",
|
|
52
|
-
maxBuffer: 1024 * 1024 * 10
|
|
53
|
-
// 10MB buffer to handle large diffs
|
|
54
|
-
});
|
|
55
|
-
if (!result || result.trim() === "") {
|
|
56
|
-
console.log(`\u2139\uFE0F [i] No changes found for the specified criteria`);
|
|
57
|
-
fs.writeFileSync(DIFF_OUTPUT, "# No changes found\n");
|
|
58
|
-
console.log(`\u2705 Empty diff saved to "${DIFF_OUTPUT_RELATIVE}"`);
|
|
59
|
-
return;
|
|
60
|
-
}
|
|
61
|
-
fs.writeFileSync(DIFF_OUTPUT, result);
|
|
62
|
-
fs.writeFileSync(
|
|
63
|
-
GPT_DIFF_OUTPUT,
|
|
64
|
-
`Hello, ChatGPT!
|
|
65
|
-
Can you create a conventional commit message by diff content below:
|
|
66
|
-
|
|
67
|
-
\`\`\`${result}
|
|
68
|
-
\`\`\`
|
|
69
|
-
|
|
70
|
-
Give me result as codeblock with language "text" only.
|
|
71
|
-
|
|
72
|
-
Thank you!`
|
|
73
|
-
);
|
|
74
|
-
console.log(`\u2705 ${successMessage}`);
|
|
75
|
-
console.log(`\u{1F4BE} GPT diff prompt saved to "${GPT_DIFF_OUTPUT_RELATIVE}"`);
|
|
76
|
-
} catch (error) {
|
|
77
|
-
console.error(`\u274C ${errorMessage}`);
|
|
78
|
-
console.error(`\u{1F4DD} Command: ${command}`);
|
|
79
|
-
console.error(`\u26A0\uFE0F Error: ${error.message}`);
|
|
80
|
-
if (error.message.includes("not a git repository")) {
|
|
81
|
-
console.error("\u{1F6A7} Make sure you are in a git repository");
|
|
82
|
-
}
|
|
83
|
-
process.exit(1);
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
async function mainGitDiff() {
|
|
87
|
-
const args = (0, import_utils.getArgs)();
|
|
88
|
-
const positional = args._ || [];
|
|
89
|
-
if (args.help || args.h) {
|
|
90
|
-
showHelp();
|
|
91
|
-
}
|
|
92
|
-
if (args["staged-only"] || args.s || args.S) {
|
|
93
|
-
runGitDiff(
|
|
94
|
-
"git --no-pager diff --staged",
|
|
95
|
-
`Full staged diff saved to "${DIFF_OUTPUT_RELATIVE}"`,
|
|
96
|
-
"Failed to save staged diff"
|
|
97
|
-
);
|
|
98
|
-
} else {
|
|
99
|
-
const file = positional[0];
|
|
100
|
-
if (!file) {
|
|
101
|
-
runGitDiff(
|
|
102
|
-
"git --no-pager diff",
|
|
103
|
-
`Full staged diff saved to "${DIFF_OUTPUT_RELATIVE}"`,
|
|
104
|
-
"Failed to save all diff's"
|
|
105
|
-
);
|
|
106
|
-
} else {
|
|
107
|
-
runGitDiff(
|
|
108
|
-
`git --no-pager diff --cached -- "${file}"`,
|
|
109
|
-
`Staged diff of "${file}" saved to "${DIFF_OUTPUT_RELATIVE}"`,
|
|
110
|
-
`Failed to generate diff for "${file}"`
|
|
111
|
-
);
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
if (args.ai) {
|
|
115
|
-
try {
|
|
116
|
-
await runChatGpt({ headless: true, questionFile: GPT_DIFF_OUTPUT });
|
|
117
|
-
} catch (error) {
|
|
118
|
-
console.error("\u274C Error running ChatGPT:", error.message);
|
|
119
|
-
console.error("\u{1F4A1} Try running with visible browser mode or check if Chrome is installed");
|
|
120
|
-
}
|
|
121
|
-
} else {
|
|
122
|
-
console.log("\u{1F4A1} Tip: Use --ai flag to generate commit message with ChatGPT");
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
var git_diff_default = runGitDiff;
|
|
126
|
-
|
|
127
|
-
export {
|
|
128
|
-
DIFF_OUTPUT,
|
|
129
|
-
GPT_DIFF_OUTPUT,
|
|
130
|
-
CACHE_DIR,
|
|
131
|
-
DIFF_OUTPUT_RELATIVE,
|
|
132
|
-
GPT_DIFF_OUTPUT_RELATIVE,
|
|
133
|
-
runGitDiff,
|
|
134
|
-
mainGitDiff,
|
|
135
|
-
git_diff_default
|
|
136
|
-
};
|
package/lib/chunk-GEYA2USY.mjs
DELETED
|
@@ -1,207 +0,0 @@
|
|
|
1
|
-
import { createRequire } from 'module'; const require = createRequire(import.meta.url);
|
|
2
|
-
import {
|
|
3
|
-
findEnvFiles
|
|
4
|
-
} from "./chunk-ID2WBTE2.mjs";
|
|
5
|
-
import {
|
|
6
|
-
require_utils
|
|
7
|
-
} from "./chunk-Z6JLYU2J.mjs";
|
|
8
|
-
import {
|
|
9
|
-
__toESM,
|
|
10
|
-
init_esm_shims
|
|
11
|
-
} from "./chunk-QQ4A6DLD.mjs";
|
|
12
|
-
|
|
13
|
-
// src/package-resolutions-updater.mjs
|
|
14
|
-
init_esm_shims();
|
|
15
|
-
var utils = __toESM(require_utils(), 1);
|
|
16
|
-
import * as dotenv from "dotenv";
|
|
17
|
-
import fs from "fs";
|
|
18
|
-
import https from "https";
|
|
19
|
-
import os from "os";
|
|
20
|
-
import path from "path";
|
|
21
|
-
var projectDir = process.cwd();
|
|
22
|
-
var envPath = path.join(projectDir, ".env");
|
|
23
|
-
var args = utils.getArgs();
|
|
24
|
-
if (!fs.existsSync(envPath)) {
|
|
25
|
-
const envFiles = findEnvFiles(projectDir, (file) => {
|
|
26
|
-
const content = fs.readFileSync(file, "utf-8");
|
|
27
|
-
return /GITHUB_TOKEN|ACCESS_TOKEN/.test(content);
|
|
28
|
-
});
|
|
29
|
-
if (envFiles.length > 0) {
|
|
30
|
-
envPath = envFiles[0];
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
if (fs.existsSync(envPath)) {
|
|
34
|
-
dotenv.config({ path: envPath, quiet: true, override: true });
|
|
35
|
-
}
|
|
36
|
-
var ACCESS_TOKEN = process.env.GITHUB_TOKEN || process.env.ACCESS_TOKEN;
|
|
37
|
-
if (args.help || args.h) {
|
|
38
|
-
showHelp();
|
|
39
|
-
}
|
|
40
|
-
function showHelp() {
|
|
41
|
-
const helpText = `
|
|
42
|
-
GitHub Package Resolutions Updater
|
|
43
|
-
Usage:
|
|
44
|
-
node src/package-resolutions-updater.mjs [options]
|
|
45
|
-
Options:
|
|
46
|
-
--help, -h Show this help message
|
|
47
|
-
Description:
|
|
48
|
-
Updates the commit hashes in package.json's 'resolutions' field for GitHub tarball URLs to point to the latest commit SHA of the corresponding repository and branch.
|
|
49
|
-
Features:
|
|
50
|
-
- Parses GitHub URLs to extract repository owner, name, and branch.
|
|
51
|
-
- Fetches the latest commit SHA across all branches using GitHub's API.
|
|
52
|
-
- Replaces the old branch or commit in the URL with the latest SHA.
|
|
53
|
-
- Overwrites package.json with the updated URLs.
|
|
54
|
-
Requirements:
|
|
55
|
-
- GitHub Personal Access Token (GITHUB_TOKEN) via .env
|
|
56
|
-
- ESM support (type: "module" in package.json)
|
|
57
|
-
- Node.js v18+ recommended
|
|
58
|
-
Dependencies:
|
|
59
|
-
- ansi-colors \u2013 for styled terminal output
|
|
60
|
-
- dotenv \u2013 to load GitHub token from .env
|
|
61
|
-
Examples:
|
|
62
|
-
node src/package-resolutions-updater.mjs
|
|
63
|
-
node src/package-resolutions-updater.mjs --help
|
|
64
|
-
|
|
65
|
-
`;
|
|
66
|
-
console.log(helpText);
|
|
67
|
-
process.exit(0);
|
|
68
|
-
}
|
|
69
|
-
var GITHUB_USER_AGENTS = [
|
|
70
|
-
"octokit-rest.js/19.0.7",
|
|
71
|
-
"GitHub CLI/2.40.0",
|
|
72
|
-
"Mozilla/5.0 (compatible; GitHubCopilot/1.0)",
|
|
73
|
-
"PostmanRuntime/7.32.3",
|
|
74
|
-
"binary-collections-resolver/1.0 (+https://github.com/dimaslanjaka/bin)"
|
|
75
|
-
];
|
|
76
|
-
var userAgentDir = path.join(os.tmpdir(), "nodejs");
|
|
77
|
-
var userAgentFile = path.join(userAgentDir, "useragent.txt");
|
|
78
|
-
var selectedUserAgent;
|
|
79
|
-
try {
|
|
80
|
-
if (!fs.existsSync(userAgentDir)) fs.mkdirSync(userAgentDir, { recursive: true });
|
|
81
|
-
if (fs.existsSync(userAgentFile)) {
|
|
82
|
-
const fileAgent = fs.readFileSync(userAgentFile, "utf-8").trim();
|
|
83
|
-
if (GITHUB_USER_AGENTS.includes(fileAgent)) {
|
|
84
|
-
selectedUserAgent = fileAgent;
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
if (!selectedUserAgent) {
|
|
88
|
-
selectedUserAgent = GITHUB_USER_AGENTS[Math.floor(Math.random() * GITHUB_USER_AGENTS.length)];
|
|
89
|
-
fs.writeFileSync(userAgentFile, selectedUserAgent, "utf-8");
|
|
90
|
-
}
|
|
91
|
-
} catch (_e) {
|
|
92
|
-
selectedUserAgent = GITHUB_USER_AGENTS[Math.floor(Math.random() * GITHUB_USER_AGENTS.length)];
|
|
93
|
-
}
|
|
94
|
-
function fetchJson(url) {
|
|
95
|
-
const headers = {
|
|
96
|
-
"User-Agent": selectedUserAgent,
|
|
97
|
-
Accept: "application/vnd.github.v3+json",
|
|
98
|
-
"X-GitHub-Api-Version": "2022-11-28",
|
|
99
|
-
...ACCESS_TOKEN ? { Authorization: `token ${ACCESS_TOKEN}` } : {}
|
|
100
|
-
};
|
|
101
|
-
return new Promise((resolve, reject) => {
|
|
102
|
-
https.get(url, { headers }, (res) => {
|
|
103
|
-
let data = "";
|
|
104
|
-
res.on("data", (chunk) => data += chunk);
|
|
105
|
-
res.on("end", () => {
|
|
106
|
-
try {
|
|
107
|
-
const json = JSON.parse(data);
|
|
108
|
-
if (res.statusCode < 200 || res.statusCode >= 300) {
|
|
109
|
-
return reject(
|
|
110
|
-
new Error(`GitHub API Error ${res.statusCode}: ${json.message || "Unknown error"}
|
|
111
|
-
URL: ${url}`)
|
|
112
|
-
);
|
|
113
|
-
}
|
|
114
|
-
resolve(json);
|
|
115
|
-
} catch {
|
|
116
|
-
reject(new Error(`Invalid JSON from: ${url}`));
|
|
117
|
-
}
|
|
118
|
-
});
|
|
119
|
-
}).on("error", reject);
|
|
120
|
-
});
|
|
121
|
-
}
|
|
122
|
-
async function getLatestCommit(owner, repo, branch = "main") {
|
|
123
|
-
var _a, _b, _c, _d;
|
|
124
|
-
const url = `https://api.github.com/repos/${owner}/${repo}/commits/${branch}`;
|
|
125
|
-
const json = await fetchJson(url);
|
|
126
|
-
const sha = json.sha;
|
|
127
|
-
const dateStr = ((_b = (_a = json.commit) == null ? void 0 : _a.committer) == null ? void 0 : _b.date) || ((_d = (_c = json.commit) == null ? void 0 : _c.author) == null ? void 0 : _d.date);
|
|
128
|
-
if (!sha || !dateStr) {
|
|
129
|
-
console.log(json);
|
|
130
|
-
throw new Error(`Missing SHA or date for ${owner}/${repo}@${branch}`);
|
|
131
|
-
}
|
|
132
|
-
return {
|
|
133
|
-
owner,
|
|
134
|
-
repo,
|
|
135
|
-
branch,
|
|
136
|
-
sha,
|
|
137
|
-
date: new Date(dateStr).toISOString()
|
|
138
|
-
};
|
|
139
|
-
}
|
|
140
|
-
async function getLatestCommitAcrossBranches(owner, repo) {
|
|
141
|
-
const branches = await fetchJson(`https://api.github.com/repos/${owner}/${repo}/branches`);
|
|
142
|
-
const commits = await Promise.all(
|
|
143
|
-
branches.map(async ({ name, commit }) => {
|
|
144
|
-
var _a, _b, _c, _d;
|
|
145
|
-
const commitSha = commit == null ? void 0 : commit.sha;
|
|
146
|
-
if (!commitSha) {
|
|
147
|
-
console.warn(`No commit SHA for '${owner}/${repo}' branch: ${name}`);
|
|
148
|
-
return { branch: name, sha: "", date: /* @__PURE__ */ new Date(0) };
|
|
149
|
-
}
|
|
150
|
-
try {
|
|
151
|
-
const commitData = await fetchJson(`https://api.github.com/repos/${owner}/${repo}/commits/${commitSha}`);
|
|
152
|
-
const dateStr = ((_b = (_a = commitData.commit) == null ? void 0 : _a.committer) == null ? void 0 : _b.date) || ((_d = (_c = commitData.commit) == null ? void 0 : _c.author) == null ? void 0 : _d.date);
|
|
153
|
-
const date = dateStr ? new Date(dateStr) : /* @__PURE__ */ new Date(0);
|
|
154
|
-
return { branch: name, sha: commitData.sha, date };
|
|
155
|
-
} catch (e) {
|
|
156
|
-
console.warn(`Failed to fetch commit for ${name}: ${e.message}`);
|
|
157
|
-
return { branch: name, sha: commitSha, date: /* @__PURE__ */ new Date(0) };
|
|
158
|
-
}
|
|
159
|
-
})
|
|
160
|
-
);
|
|
161
|
-
const latest = commits.reduce((a, b) => a.date > b.date ? a : b, { date: /* @__PURE__ */ new Date(0) });
|
|
162
|
-
return {
|
|
163
|
-
owner,
|
|
164
|
-
repo,
|
|
165
|
-
branch: latest.branch,
|
|
166
|
-
sha: latest.sha,
|
|
167
|
-
date: latest.date.toISOString()
|
|
168
|
-
};
|
|
169
|
-
}
|
|
170
|
-
function replaceRawWithLatestHash(url, latestHash) {
|
|
171
|
-
const match = url.match(/^https:\/\/github\.com\/([^/]+)\/([^/]+)\/raw\/([^/]+)\/(.+)$/);
|
|
172
|
-
if (!match) throw new Error("Invalid GitHub raw URL");
|
|
173
|
-
const [, owner, repo, _oldHash, path2] = match;
|
|
174
|
-
return `https://github.com/${owner}/${repo}/raw/${latestHash}/${path2}`;
|
|
175
|
-
}
|
|
176
|
-
function parseGitHubUrl(url) {
|
|
177
|
-
const ghRepoRoot = /^https:\/\/github\.com\/([^/]+)\/([^/]+)\/?$/;
|
|
178
|
-
const ghTreeOrBlob = /^https:\/\/github\.com\/([^/]+)\/([^/]+)\/(tree|blob)\/([^/]+(?:\/[^/]+)*)/;
|
|
179
|
-
const ghRaw = /^https:\/\/raw\.githubusercontent\.com\/([^/]+)\/([^/]+)\/([^/]+)(\/.+)?$/;
|
|
180
|
-
const ghDotComRaw = /^https:\/\/github\.com\/([^/]+)\/([^/]+)\/raw\/([^/]+)\/.+$/;
|
|
181
|
-
let match;
|
|
182
|
-
if (match = url.match(ghRaw)) {
|
|
183
|
-
const [, owner, repo, branch] = match;
|
|
184
|
-
return { owner, repo, branch, url };
|
|
185
|
-
}
|
|
186
|
-
if (match = url.match(ghDotComRaw)) {
|
|
187
|
-
const [, owner, repo, branch] = match;
|
|
188
|
-
return { owner, repo, branch, url };
|
|
189
|
-
}
|
|
190
|
-
if (match = url.match(ghTreeOrBlob)) {
|
|
191
|
-
const [, owner, repo, , branchPath] = match;
|
|
192
|
-
return { owner, repo, branch: branchPath, url };
|
|
193
|
-
}
|
|
194
|
-
if (match = url.match(ghRepoRoot)) {
|
|
195
|
-
const [, owner, repo] = match;
|
|
196
|
-
return { owner, repo, url };
|
|
197
|
-
}
|
|
198
|
-
throw new Error(`Unsupported GitHub URL: ${url}`);
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
export {
|
|
202
|
-
fetchJson,
|
|
203
|
-
getLatestCommit,
|
|
204
|
-
getLatestCommitAcrossBranches,
|
|
205
|
-
replaceRawWithLatestHash,
|
|
206
|
-
parseGitHubUrl
|
|
207
|
-
};
|
package/lib/chunk-GJTGHXRA.mjs
DELETED
|
@@ -1,356 +0,0 @@
|
|
|
1
|
-
import { createRequire } from 'module'; const require = createRequire(import.meta.url);
|
|
2
|
-
import {
|
|
3
|
-
init_esm_shims
|
|
4
|
-
} from "./chunk-QQ4A6DLD.mjs";
|
|
5
|
-
|
|
6
|
-
// src/utils/chatgpt.js
|
|
7
|
-
init_esm_shims();
|
|
8
|
-
import fs from "fs-extra";
|
|
9
|
-
import puppeteer from "puppeteer-extra";
|
|
10
|
-
import StealthPlugin from "puppeteer-extra-plugin-stealth";
|
|
11
|
-
import path from "upath";
|
|
12
|
-
var COOKIE_DIR = path.join(process.cwd(), "tmp", "cookies");
|
|
13
|
-
var DEFAULT_COOKIE_PATH = path.join(COOKIE_DIR, "cookies.json");
|
|
14
|
-
fs.ensureDirSync(COOKIE_DIR);
|
|
15
|
-
async function saveCookies(page, path2 = DEFAULT_COOKIE_PATH) {
|
|
16
|
-
const cookies = await page.cookies();
|
|
17
|
-
fs.writeFileSync(path2, JSON.stringify(cookies, null, 2));
|
|
18
|
-
}
|
|
19
|
-
function getCookiePathForUrl(url) {
|
|
20
|
-
try {
|
|
21
|
-
const { hostname } = new URL(url);
|
|
22
|
-
return path.join(COOKIE_DIR, `cookies_${hostname}.json`);
|
|
23
|
-
} catch {
|
|
24
|
-
return DEFAULT_COOKIE_PATH;
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
async function navigatePage(page, url) {
|
|
28
|
-
const cookiePath = getCookiePathForUrl(url);
|
|
29
|
-
const cookies = loadCookies(cookiePath);
|
|
30
|
-
if (cookies) {
|
|
31
|
-
await page.setCookie(...cookies);
|
|
32
|
-
}
|
|
33
|
-
await page.goto(url, { waitUntil: "networkidle0" });
|
|
34
|
-
await page.evaluate(() => {
|
|
35
|
-
window.__domStillUpdating = true;
|
|
36
|
-
if (window.__domObserver) {
|
|
37
|
-
window.__domObserver.disconnect();
|
|
38
|
-
}
|
|
39
|
-
window.__domObserver = new MutationObserver(() => {
|
|
40
|
-
window.__lastDomMutation = Date.now();
|
|
41
|
-
});
|
|
42
|
-
window.__lastDomMutation = Date.now();
|
|
43
|
-
window.__domObserver.observe(document.body, {
|
|
44
|
-
childList: true,
|
|
45
|
-
subtree: true,
|
|
46
|
-
attributes: true,
|
|
47
|
-
characterData: true
|
|
48
|
-
});
|
|
49
|
-
setTimeout(() => {
|
|
50
|
-
window.__domStillUpdating = false;
|
|
51
|
-
window.__domObserver.disconnect();
|
|
52
|
-
}, 3e4);
|
|
53
|
-
});
|
|
54
|
-
const waitForDomIdle = async (idleMs = 1e3, timeout = 1e4) => {
|
|
55
|
-
const start = Date.now();
|
|
56
|
-
while (Date.now() - start < timeout) {
|
|
57
|
-
const lastMutation = await page.evaluate(() => window.__lastDomMutation);
|
|
58
|
-
const idle = Date.now() - lastMutation;
|
|
59
|
-
if (idle >= idleMs) {
|
|
60
|
-
return true;
|
|
61
|
-
}
|
|
62
|
-
await new Promise((r) => setTimeout(r, 200));
|
|
63
|
-
}
|
|
64
|
-
throw new Error("DOM did not stabilize within timeout");
|
|
65
|
-
};
|
|
66
|
-
return { waitForDomIdle };
|
|
67
|
-
}
|
|
68
|
-
function loadCookies(cookieFilePath = DEFAULT_COOKIE_PATH) {
|
|
69
|
-
if (!fs.existsSync(cookieFilePath)) return null;
|
|
70
|
-
return JSON.parse(fs.readFileSync(cookieFilePath));
|
|
71
|
-
}
|
|
72
|
-
async function writeQuestion(page, question) {
|
|
73
|
-
const questions = question.split("\n");
|
|
74
|
-
const promptTextarea = await page.waitForSelector("#prompt-textarea", { timeout: 3e4 });
|
|
75
|
-
if (!promptTextarea) {
|
|
76
|
-
console.log(
|
|
77
|
-
"Cannot find the prompt input on the webpage. Please check whether you have access to chat.openai.com without logging in via your browser."
|
|
78
|
-
);
|
|
79
|
-
}
|
|
80
|
-
await page.evaluate(() => {
|
|
81
|
-
document.querySelector("#prompt-textarea").innerHTML = `<p></p>`;
|
|
82
|
-
});
|
|
83
|
-
if (questions.length === 1) {
|
|
84
|
-
await page.type("#prompt-textarea", questions[0], { delay: 100 });
|
|
85
|
-
return;
|
|
86
|
-
}
|
|
87
|
-
for (const q of questions) {
|
|
88
|
-
await page.type("#prompt-textarea", q, { delay: 100 });
|
|
89
|
-
if (q !== questions[questions.length - 1]) {
|
|
90
|
-
await page.keyboard.down("Shift");
|
|
91
|
-
await page.keyboard.press("Enter");
|
|
92
|
-
await page.keyboard.up("Shift");
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
async function clickSubmitButton(page) {
|
|
97
|
-
try {
|
|
98
|
-
const fruitjuiceSendButton = await page.evaluate(() => {
|
|
99
|
-
return document.querySelector('[data-testid="fruitjuice-send-button"]') !== null;
|
|
100
|
-
});
|
|
101
|
-
const sendButton = await page.evaluate(() => {
|
|
102
|
-
return document.querySelector('[data-testid="send-button"]') !== null;
|
|
103
|
-
});
|
|
104
|
-
if (fruitjuiceSendButton) {
|
|
105
|
-
await page.click('[data-testid="fruitjuice-send-button"]');
|
|
106
|
-
} else if (sendButton) {
|
|
107
|
-
await page.click('[data-testid="send-button"]');
|
|
108
|
-
} else {
|
|
109
|
-
console.log("Neither send button is present");
|
|
110
|
-
}
|
|
111
|
-
} catch (e) {
|
|
112
|
-
console.log(`Failed to click the send button: ${e}`);
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
var lastMessageId = null;
|
|
116
|
-
var messageCount = 0;
|
|
117
|
-
var is_streaming = false;
|
|
118
|
-
function sleep(ms) {
|
|
119
|
-
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
120
|
-
}
|
|
121
|
-
async function waitForInitialResponse(page, timeout = 3e4) {
|
|
122
|
-
const startTime = Date.now();
|
|
123
|
-
while (Date.now() - startTime < timeout) {
|
|
124
|
-
const assistantMessages = await page.$$('[data-message-author-role="assistant"]');
|
|
125
|
-
const currentMessageCount = assistantMessages.length;
|
|
126
|
-
if (currentMessageCount > messageCount) {
|
|
127
|
-
const lastMessage = assistantMessages[assistantMessages.length - 1];
|
|
128
|
-
const isThinking = await lastMessage.$(".result-thinking");
|
|
129
|
-
if (!isThinking) {
|
|
130
|
-
lastMessageId = await page.evaluate((element) => element.getAttribute("data-message-id"), lastMessage);
|
|
131
|
-
messageCount = currentMessageCount;
|
|
132
|
-
return;
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
await sleep(100);
|
|
136
|
-
}
|
|
137
|
-
console.log("Timed out waiting for the initial response.");
|
|
138
|
-
}
|
|
139
|
-
async function handleStreamingResponse(page, outputFile = path.join(process.cwd(), "tmp/response.txt")) {
|
|
140
|
-
let previousText = "";
|
|
141
|
-
let completeResponse = "";
|
|
142
|
-
let newContentDetected = false;
|
|
143
|
-
while (!newContentDetected) {
|
|
144
|
-
const assistantMessages = await page.$$('[data-message-author-role="assistant"]');
|
|
145
|
-
if (assistantMessages.length > 0) {
|
|
146
|
-
const lastMessage = assistantMessages[assistantMessages.length - 1];
|
|
147
|
-
const currentMessageId = await page.evaluate((element) => element.getAttribute("data-message-id"), lastMessage);
|
|
148
|
-
if (currentMessageId === lastMessageId) {
|
|
149
|
-
const currentText = await page.evaluate((element) => element.textContent, lastMessage);
|
|
150
|
-
console.log(`Current text: ${currentText}`);
|
|
151
|
-
if (currentText !== previousText) {
|
|
152
|
-
if (is_streaming) {
|
|
153
|
-
process.stdout.write(currentText.slice(previousText.length));
|
|
154
|
-
} else {
|
|
155
|
-
completeResponse += currentText.slice(previousText.length);
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
previousText = currentText;
|
|
159
|
-
const isStreaming = await lastMessage.$(".result-streaming");
|
|
160
|
-
if (!isStreaming) {
|
|
161
|
-
newContentDetected = true;
|
|
162
|
-
}
|
|
163
|
-
} else {
|
|
164
|
-
lastMessageId = currentMessageId;
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
|
-
await sleep(100);
|
|
168
|
-
}
|
|
169
|
-
if (!is_streaming) {
|
|
170
|
-
console.log(completeResponse.trim());
|
|
171
|
-
console.log("\n\n");
|
|
172
|
-
fs.ensureDirSync(path.dirname(outputFile));
|
|
173
|
-
fs.writeFileSync(outputFile, completeResponse.trim());
|
|
174
|
-
console.log(`Response saved to ${outputFile}`);
|
|
175
|
-
}
|
|
176
|
-
}
|
|
177
|
-
async function isLoggedIn(page) {
|
|
178
|
-
const result = await page.evaluate(() => {
|
|
179
|
-
const loginButton = document.querySelector('[data-testid="login-button"]');
|
|
180
|
-
return !(loginButton && loginButton.offsetParent !== null);
|
|
181
|
-
});
|
|
182
|
-
return result === true;
|
|
183
|
-
}
|
|
184
|
-
async function createBrowser(browserOptions = {}) {
|
|
185
|
-
const defaultOptions = {
|
|
186
|
-
headless: false,
|
|
187
|
-
userDataDir: path.join(process.cwd(), "tmp/puppeteer-profile"),
|
|
188
|
-
// Windows-specific options to handle browser launch issues
|
|
189
|
-
args: [
|
|
190
|
-
"--no-sandbox",
|
|
191
|
-
"--disable-setuid-sandbox",
|
|
192
|
-
"--disable-dev-shm-usage",
|
|
193
|
-
"--disable-accelerated-2d-canvas",
|
|
194
|
-
"--no-first-run",
|
|
195
|
-
"--no-zygote",
|
|
196
|
-
"--disable-gpu",
|
|
197
|
-
"--disable-background-timer-throttling",
|
|
198
|
-
"--disable-backgrounding-occluded-windows",
|
|
199
|
-
"--disable-renderer-backgrounding"
|
|
200
|
-
],
|
|
201
|
-
ignoreDefaultArgs: ["--disable-extensions"],
|
|
202
|
-
...process.platform === "win32" && {
|
|
203
|
-
// Additional Windows-specific options
|
|
204
|
-
executablePath: void 0
|
|
205
|
-
// Let Puppeteer find Chrome automatically
|
|
206
|
-
}
|
|
207
|
-
};
|
|
208
|
-
try {
|
|
209
|
-
return await puppeteer.use(StealthPlugin()).launch({ ...defaultOptions, ...browserOptions });
|
|
210
|
-
} catch (_error) {
|
|
211
|
-
console.error("Failed to launch browser with default options. Trying fallback options...");
|
|
212
|
-
try {
|
|
213
|
-
return await puppeteer.use(StealthPlugin()).launch({
|
|
214
|
-
headless: browserOptions.headless || false,
|
|
215
|
-
args: ["--no-sandbox", "--disable-setuid-sandbox"],
|
|
216
|
-
ignoreDefaultArgs: false,
|
|
217
|
-
...browserOptions
|
|
218
|
-
});
|
|
219
|
-
} catch (fallbackError) {
|
|
220
|
-
console.error("Browser launch failed completely. Common solutions:");
|
|
221
|
-
console.error("1. Install Google Chrome if not installed");
|
|
222
|
-
console.error("2. Update Node.js to the latest version");
|
|
223
|
-
console.error("3. Try running: npm install puppeteer --force");
|
|
224
|
-
console.error("4. Check if antivirus is blocking browser launch");
|
|
225
|
-
throw new Error(`Browser launch failed: ${fallbackError.message}`);
|
|
226
|
-
}
|
|
227
|
-
}
|
|
228
|
-
}
|
|
229
|
-
async function loginToChatGpt() {
|
|
230
|
-
const browser = await createBrowser({ headless: false });
|
|
231
|
-
const page = (await browser.pages()).length > 0 ? (await browser.pages())[0] : await browser.newPage();
|
|
232
|
-
const url = "https://chat.openai.com";
|
|
233
|
-
const navigate = await navigatePage(page, url);
|
|
234
|
-
await navigate.waitForDomIdle(2e3, 1e4);
|
|
235
|
-
const loginButtonExists = await page.evaluate(() => {
|
|
236
|
-
return document.querySelector('[data-testid="login-button"]') !== null;
|
|
237
|
-
});
|
|
238
|
-
if (loginButtonExists) {
|
|
239
|
-
console.log("Login button found, clicking to log in...");
|
|
240
|
-
await page.click('[data-testid="login-button"]');
|
|
241
|
-
await page.waitForNavigation({ waitUntil: "networkidle0" });
|
|
242
|
-
console.log("Login process completed.");
|
|
243
|
-
} else {
|
|
244
|
-
console.log("No login required - user appears to be already logged in.");
|
|
245
|
-
}
|
|
246
|
-
}
|
|
247
|
-
async function runChatGpt(chatgptOptions = {}) {
|
|
248
|
-
const headless = chatgptOptions.headless !== void 0 ? chatgptOptions.headless : true;
|
|
249
|
-
const questionFile = chatgptOptions.questionFile;
|
|
250
|
-
let question = chatgptOptions.question;
|
|
251
|
-
const responseFile = chatgptOptions.responseFile || path.join(process.cwd(), "tmp", "response.txt");
|
|
252
|
-
const noInputProvided = !question && !questionFile;
|
|
253
|
-
const questionIsEmpty = question && question.trim().length === 0;
|
|
254
|
-
const questionFileIsEmpty = questionFile && questionFile.trim().length === 0;
|
|
255
|
-
if (noInputProvided || questionIsEmpty || questionFileIsEmpty) {
|
|
256
|
-
throw new Error("You must provide a question or a question file.");
|
|
257
|
-
}
|
|
258
|
-
let browser;
|
|
259
|
-
try {
|
|
260
|
-
browser = await createBrowser({ headless });
|
|
261
|
-
} catch (error) {
|
|
262
|
-
console.error("Error running ChatGPT:", error);
|
|
263
|
-
console.error("\nTroubleshooting steps:");
|
|
264
|
-
console.error("1. Make sure Google Chrome is installed");
|
|
265
|
-
console.error("2. Try running: yarn add puppeteer --force");
|
|
266
|
-
console.error("3. Check if your antivirus is blocking the browser");
|
|
267
|
-
console.error("4. Close any running Chrome instances and try again");
|
|
268
|
-
throw error;
|
|
269
|
-
}
|
|
270
|
-
const page = (await browser.pages()).length > 0 ? (await browser.pages())[0] : await browser.newPage();
|
|
271
|
-
try {
|
|
272
|
-
const url = "https://chat.openai.com";
|
|
273
|
-
const navigate = await navigatePage(page, url);
|
|
274
|
-
await navigate.waitForDomIdle(2e3, 15e3);
|
|
275
|
-
try {
|
|
276
|
-
const tempChatButton = await page.$('button[aria-label="Turn on temporary chat"]');
|
|
277
|
-
if (tempChatButton) {
|
|
278
|
-
await page.evaluate((el) => el.click(), tempChatButton);
|
|
279
|
-
console.log("Successfully clicked temporary chat button");
|
|
280
|
-
await navigate.waitForDomIdle(1e3, 1e4);
|
|
281
|
-
} else {
|
|
282
|
-
console.log("Temporary chat button not found, proceeding without it.");
|
|
283
|
-
}
|
|
284
|
-
} catch (error) {
|
|
285
|
-
console.log(`Failed to click temporary chat button: ${error.message}`);
|
|
286
|
-
}
|
|
287
|
-
if (question) {
|
|
288
|
-
await writeQuestion(page, question);
|
|
289
|
-
await clickSubmitButton(page);
|
|
290
|
-
await navigate.waitForDomIdle(1e3, 3e4);
|
|
291
|
-
await waitForInitialResponse(page);
|
|
292
|
-
await handleStreamingResponse(page, responseFile);
|
|
293
|
-
await saveCookies(page, getCookiePathForUrl(url));
|
|
294
|
-
} else if (questionFile) {
|
|
295
|
-
await navigate.waitForDomIdle(2e3, 1e4);
|
|
296
|
-
const isUserLoggedIn = await isLoggedIn(page);
|
|
297
|
-
console.log(`Login status: ${isUserLoggedIn ? "Logged in" : "Not logged in"}`);
|
|
298
|
-
if (!isUserLoggedIn) {
|
|
299
|
-
console.log(
|
|
300
|
-
"Not logged in. Please log in to ChatGPT in the browser window, then close it and run the command again."
|
|
301
|
-
);
|
|
302
|
-
return loginToChatGpt();
|
|
303
|
-
}
|
|
304
|
-
const plusButtonExists = await page.evaluate(() => {
|
|
305
|
-
const button = document.querySelector('[data-testid="composer-plus-btn"]');
|
|
306
|
-
return button !== null;
|
|
307
|
-
});
|
|
308
|
-
if (plusButtonExists) {
|
|
309
|
-
await page.click('[data-testid="composer-plus-btn"]');
|
|
310
|
-
await sleep(500);
|
|
311
|
-
const menuItems = await page.$$('[role="menuitem"]');
|
|
312
|
-
let clicked = false;
|
|
313
|
-
for (const item of menuItems) {
|
|
314
|
-
const text = await page.evaluate((el) => el.innerText, item);
|
|
315
|
-
if (text && text.includes("Add photos") && text.includes("files")) {
|
|
316
|
-
await item.hover();
|
|
317
|
-
clicked = true;
|
|
318
|
-
break;
|
|
319
|
-
}
|
|
320
|
-
}
|
|
321
|
-
if (!clicked) {
|
|
322
|
-
console.log('Could not find the "Add photos & files" menu item.');
|
|
323
|
-
return;
|
|
324
|
-
}
|
|
325
|
-
try {
|
|
326
|
-
await sleep(1e3);
|
|
327
|
-
const fileInput = await page.waitForSelector('input[type="file"]', { timeout: 1e4 });
|
|
328
|
-
if (fileInput) {
|
|
329
|
-
console.log(`Uploading file: ${questionFile}`);
|
|
330
|
-
await fileInput.uploadFile(questionFile);
|
|
331
|
-
await navigate.waitForDomIdle(2e3, 15e3);
|
|
332
|
-
console.log("File uploaded successfully");
|
|
333
|
-
await clickSubmitButton(page);
|
|
334
|
-
await navigate.waitForDomIdle(1e3, 3e4);
|
|
335
|
-
await waitForInitialResponse(page);
|
|
336
|
-
await handleStreamingResponse(page, responseFile);
|
|
337
|
-
} else {
|
|
338
|
-
console.log("Could not find file input element");
|
|
339
|
-
}
|
|
340
|
-
} catch (error) {
|
|
341
|
-
console.log(`Error uploading file: ${error.message}`);
|
|
342
|
-
}
|
|
343
|
-
} else {
|
|
344
|
-
console.log('Could not find the [data-testid="composer-plus-btn"] button.');
|
|
345
|
-
}
|
|
346
|
-
}
|
|
347
|
-
} finally {
|
|
348
|
-
if (browser) {
|
|
349
|
-
await browser.close();
|
|
350
|
-
}
|
|
351
|
-
}
|
|
352
|
-
}
|
|
353
|
-
|
|
354
|
-
export {
|
|
355
|
-
runChatGpt
|
|
356
|
-
};
|