binary-collections 2.0.9 → 2.0.11
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/.puppeterrc.cjs +25 -0
- package/binaries/binary-executor.cjs +178 -0
- package/{bin → binaries}/clean-nodemodule +0 -0
- package/binaries/clean-nodemodule.cjs +178 -0
- package/binaries/clean-nodemodule.cmd +4 -0
- package/{bin → binaries}/clean-nodemodules +0 -0
- package/binaries/clean-nodemodules.cjs +178 -0
- package/binaries/clean-nodemodules.cmd +5 -0
- package/{bin → binaries}/dev +0 -0
- package/binaries/dev.cjs +178 -0
- package/{bin → binaries}/empty +0 -0
- package/binaries/empty.cjs +178 -0
- package/{bin → binaries}/git-reduce-size +0 -0
- package/binaries/git-reduce-size.cjs +178 -0
- package/binaries/javakill.cjs +178 -0
- package/{bin → binaries}/javakill.cmd +0 -0
- package/binaries/kill-night-crows.bat +7 -0
- package/binaries/kill-night-crows.ps1 +172 -0
- package/{bin → binaries}/kill-process +0 -0
- package/binaries/kill-process.cjs +178 -0
- package/binaries/nodekill.cjs +178 -0
- package/{bin → binaries}/nodekill.ps1 +0 -0
- package/{bin → binaries}/prod +0 -0
- package/binaries/prod.cjs +178 -0
- package/binaries/py +111 -0
- package/binaries/py.cjs +178 -0
- package/binaries/py.cmd +49 -0
- package/{bin → binaries}/rmfind +0 -0
- package/binaries/rmfind.cjs +178 -0
- package/{bin → binaries}/rmx +0 -0
- package/binaries/rmx.cjs +178 -0
- package/{bin → binaries}/submodule-token +0 -0
- package/binaries/submodule-token.cjs +178 -0
- package/binaries/test-cjs +10 -0
- package/binaries/test-cjs.cjs +178 -0
- package/binaries/test-cjs.cmd +11 -0
- package/binaries/yarn-clean +32 -0
- package/binaries/yarn-clean.cjs +178 -0
- package/binaries/yarn-clean.cmd +30 -0
- package/binaries/yarn-clean.py +148 -0
- package/docs-src/clean-github-actions-caches.md +26 -0
- package/docs-src/free-chatgpt.md +26 -0
- package/lib/binary-collections-config.cjs +3 -2
- package/lib/binary-collections-config.mjs +2 -2
- package/lib/binary-collections.cjs +513 -105
- package/lib/binary-collections.mjs +178 -117
- package/lib/changelog.cjs +64 -16
- package/lib/changelog.mjs +177 -171
- package/lib/{chunk-VVEZVNIV.mjs → chunk-2CBJCW7E.mjs} +3 -3
- package/lib/chunk-34IQDTLZ.mjs +27 -0
- package/lib/chunk-3HFFECCI.mjs +27 -0
- package/lib/chunk-4UHL4WVN.mjs +136 -0
- package/lib/{chunk-4BYBVEYC.mjs → chunk-66PAU5PS.mjs} +5 -4
- package/lib/chunk-6HHJRKFB.mjs +59 -0
- package/lib/chunk-6S4NXESK.mjs +26 -0
- package/lib/chunk-7XTEJHOE.mjs +193 -0
- package/lib/{chunk-ZYAQRPUL.mjs → chunk-7YD7IPFF.mjs} +2 -2
- package/lib/{chunk-SH3L6HHV.mjs → chunk-A2JQXI5Z.mjs} +2 -2
- package/lib/{chunk-EGSSKVDH.mjs → chunk-A3VUZEJK.mjs} +1 -1
- package/lib/chunk-AJDD5DZM.mjs +109 -0
- package/lib/chunk-BZWVHODJ.mjs +62 -0
- package/lib/chunk-FCDQGYBF.mjs +136 -0
- package/lib/chunk-FKI7IEB5.mjs +172 -0
- package/lib/chunk-GEYA2USY.mjs +207 -0
- package/lib/chunk-GJTGHXRA.mjs +356 -0
- package/lib/{chunk-YV7DO3YV.mjs → chunk-HLGOWBEO.mjs} +1 -1
- package/lib/chunk-ID2WBTE2.mjs +80 -0
- package/lib/chunk-JXFOHKDM.mjs +239 -0
- package/lib/{chunk-YX5U7XDR.mjs → chunk-M3YIYRHT.mjs} +6 -5
- package/lib/chunk-N436BNBK.mjs +514 -0
- package/lib/chunk-NCXAP7AA.mjs +31 -0
- package/lib/chunk-PDN26I7O.mjs +188 -0
- package/lib/{chunk-JGR2NW6D.mjs → chunk-PDSXF5HY.mjs} +3 -3
- package/lib/{chunk-AASHBCRW.mjs → chunk-QQ4A6DLD.mjs} +8 -0
- package/lib/{chunk-ONIBBBQ3.mjs → chunk-RWLXRTYP.mjs} +4 -3
- package/lib/chunk-TOIVAQF7.mjs +136 -0
- package/lib/chunk-V5SKYJUB.mjs +136 -0
- package/lib/chunk-WSRETQCA.mjs +59 -0
- package/lib/chunk-XA3SNBPA.mjs +184 -0
- package/lib/chunk-XVBFFVCJ.mjs +209 -0
- package/lib/chunk-YYLIQQKF.mjs +31 -0
- package/lib/{chunk-APBWENF6.mjs → chunk-Z6JLYU2J.mjs} +63 -16
- package/lib/chunk-ZDMWBSYF.mjs +81 -0
- package/lib/clean-github-actions-caches.cjs +291 -148
- package/lib/clean-github-actions-caches.mjs +4 -3
- package/lib/del-gradle.cjs +63 -15
- package/lib/del-gradle.js +2 -1
- package/lib/del-gradle.mjs +2 -2
- package/lib/del-node-modules.cjs +143 -148
- package/lib/del-node-modules.js +210 -14
- package/lib/del-node-modules.mjs +149 -18
- package/lib/del-ps.cjs +90 -21
- package/lib/del-ps.js +3 -2
- package/lib/del-ps.mjs +7 -5
- package/lib/del-yarn-caches.cjs +87 -18
- package/lib/del-yarn-caches.js +38 -3
- package/lib/del-yarn-caches.mjs +6 -6
- package/lib/find-node-modules-cli.cjs +5 -4
- package/lib/find-node-modules-cli.js +2 -1
- package/lib/find-node-modules-cli.mjs +2 -2
- package/lib/find-node-modules.cjs +4 -3
- package/lib/{find-node-modules.d.ts → find-node-modules.d.cts} +1 -1
- package/lib/find-node-modules.mjs +2 -2
- package/lib/free-chatgpt.cjs +754 -0
- package/lib/free-chatgpt.js +51 -0
- package/lib/free-chatgpt.mjs +50 -0
- package/lib/git/gitattributes.cjs +2 -1
- package/lib/git/{gitattributes.d.ts → gitattributes.d.cts} +7 -2
- package/lib/git/gitattributes.mjs +2 -2
- package/lib/git/line-endings.cjs +298 -64
- package/lib/git/line-endings.mjs +4 -4
- package/lib/git/normalize.cjs +26 -36
- package/lib/git/normalize.mjs +2 -2
- package/lib/git/permissions.cjs +77 -11
- package/lib/git/permissions.mjs +3 -3
- package/lib/git/pull-strategy.cjs +76 -9
- package/lib/git/pull-strategy.mjs +3 -3
- package/lib/git/undo-commit-cli.cjs +110 -0
- package/lib/git/undo-commit-cli.d.ts +1 -0
- package/lib/git/undo-commit-cli.js +4 -0
- package/lib/git/undo-commit-cli.mjs +14 -0
- package/lib/git/undo-commit.cjs +81 -0
- package/lib/git/undo-commit.d.cts +1 -0
- package/lib/git/undo-commit.mjs +7 -0
- package/lib/git/undo-staged-cli.cjs +110 -0
- package/lib/git/undo-staged-cli.d.ts +1 -0
- package/lib/git/undo-staged-cli.js +4 -0
- package/lib/git/undo-staged-cli.mjs +14 -0
- package/lib/git/undo-staged.cjs +81 -0
- package/lib/git/undo-staged.d.cts +1 -0
- package/lib/git/undo-staged.mjs +7 -0
- package/lib/git/user-config.cjs +313 -83
- package/lib/git/user-config.mjs +4 -4
- package/lib/git/utils.cjs +40 -60
- package/lib/git/utils.mjs +2 -2
- package/lib/git-diff-cli.cjs +857 -0
- package/lib/git-diff-cli.js +16 -0
- package/lib/git-diff-cli.mjs +17 -0
- package/lib/git-diff.cjs +862 -58
- package/lib/git-diff.d.ts +38 -83
- package/lib/git-diff.js +152 -0
- package/lib/git-diff.mjs +23 -85
- package/lib/git-fix.cjs +733 -97
- package/lib/git-fix.mjs +10 -9
- package/lib/git-purge.cjs +64 -16
- package/lib/git-purge.d.cts +1 -0
- package/lib/git-purge.mjs +43 -37
- package/lib/index.cjs +7 -6
- package/lib/index.d.ts +1 -1
- package/lib/index.js +2 -5
- package/lib/index.mjs +4 -4
- package/lib/kill-night-crows.cjs +87 -0
- package/lib/kill-night-crows.d.mts +1 -0
- package/lib/kill-night-crows.mjs +65 -0
- package/lib/npm-run-series.cjs +63 -16
- package/lib/npm-run-series.mjs +42 -36
- package/lib/package-resolutions-updater-cli.cjs +560 -0
- package/lib/package-resolutions-updater-cli.d.mts +1 -0
- package/lib/package-resolutions-updater-cli.mjs +124 -0
- package/lib/package-resolutions-updater.cjs +178 -158
- package/lib/package-resolutions-updater.d.mts +32 -1
- package/lib/package-resolutions-updater.mjs +17 -338
- package/lib/php-cs-fixer-staged.cjs +105 -0
- package/lib/php-cs-fixer-staged.d.cts +2 -0
- package/lib/php-cs-fixer-staged.mjs +117 -0
- package/lib/print-directory-tree.cjs +320 -207
- package/lib/print-directory-tree.mjs +3 -3
- package/lib/ps/connected-domain.cjs +25 -2
- package/lib/ps/connected-domain.d.ts +10 -2
- package/lib/ps/connected-domain.js +5 -2
- package/lib/ps/connected-domain.mjs +8 -4
- package/lib/ps/index.cjs +345 -322
- package/lib/ps/index.d.mjs +1 -1
- package/lib/ps/index.js +2 -1
- package/lib/ps/index.mjs +179 -182
- package/lib/ps/isWin.cjs +24 -1
- package/lib/ps/isWin.d.ts +1 -1
- package/lib/ps/isWin.js +3 -1
- package/lib/ps/isWin.mjs +8 -4
- package/lib/ps/table-parser.cjs +167 -159
- package/lib/ps/table-parser.d.ts +5 -0
- package/lib/ps/table-parser.js +10 -4
- package/lib/ps/table-parser.mjs +9 -5
- package/lib/remove-module.cjs +310 -0
- package/lib/remove-module.d.mts +1 -0
- package/lib/remove-module.mjs +111 -0
- package/lib/rmpath.cjs +322 -0
- package/lib/rmpath.d.mts +3 -0
- package/lib/rmpath.mjs +108 -0
- package/lib/submodule-install.cjs +311 -86
- package/lib/submodule-install.mjs +53 -5
- package/lib/submodule-remove-cli.cjs +107 -0
- package/lib/submodule-remove-cli.d.ts +1 -0
- package/lib/submodule-remove-cli.js +31 -0
- package/lib/submodule-remove-cli.mjs +28 -0
- package/lib/submodule-remove.cjs +46 -0
- package/lib/submodule-remove.d.cts +2 -0
- package/lib/submodule-remove.mjs +6 -0
- package/lib/utils/chatgpt.cjs +541 -0
- package/lib/utils/chatgpt.d.ts +31 -0
- package/lib/utils/chatgpt.js +708 -0
- package/lib/utils/chatgpt.mjs +8 -0
- package/lib/utils/findEnvFiles.cjs +107 -0
- package/lib/utils/findEnvFiles.d.ts +8 -0
- package/lib/utils/findEnvFiles.js +121 -0
- package/lib/utils/findEnvFiles.mjs +8 -0
- package/lib/utils/findWorkspaceRoot.cjs +70 -0
- package/lib/utils/findWorkspaceRoot.d.ts +9 -0
- package/lib/utils/findWorkspaceRoot.js +57 -0
- package/lib/utils/findWorkspaceRoot.mjs +40 -0
- package/lib/{utils.cjs → utils/index.cjs} +61 -14
- package/lib/{utils.mjs → utils/index.mjs} +2 -2
- package/lib/utils/isGithubTokenValid.cjs +64 -0
- package/lib/utils/isGithubTokenValid.d.ts +7 -0
- package/lib/utils/isGithubTokenValid.js +48 -0
- package/lib/utils/isGithubTokenValid.mjs +36 -0
- package/lib/yarn-reinstall.cjs +220 -38
- package/lib/yarn-reinstall.mjs +2 -2
- package/package.json +138 -104
- package/readme.md +48 -75
- package/releases/readme.md +36 -0
- package/requirements.txt +1 -0
- package/test/README.md +101 -0
- package/test/package.json +2 -1
- package/test-project/readme.md +26 -0
- package/tmp/test-repo/README.md +35 -0
- package/tmp/test-repo/package.json +1 -1
- package/tmp/typedoc/readme.md +320 -0
- package/bin/bash-dummy +0 -56
- package/bin/bash-dummy.cmd +0 -25
- package/bin/dir-tree.cmd +0 -7
- package/bin/git-diff +0 -4
- package/bin/git-diff.cmd +0 -7
- package/bin/git-fix +0 -36
- package/bin/git-fix.cmd +0 -7
- package/bin/rmpath +0 -70
- package/bin/submodule-install.txt +0 -118
- package/bin/submodule-remove +0 -46
- package/bin/submodule.txt +0 -172
- package/lib/binary-collections-config.d.mts +0 -18
- package/lib/binary-collections-config.js +0 -39
- package/lib/binary-collections.d.mts +0 -137
- package/lib/binary-collections.d.ts +0 -137
- package/lib/changelog.d.mts +0 -2
- package/lib/changelog.js +0 -226
- package/lib/chunk-DPKAJKFO.mjs +0 -171
- package/lib/chunk-G3THLIDT.mjs +0 -200
- package/lib/chunk-W3ENOM53.mjs +0 -18
- package/lib/clean-github-actions-caches.d.mts +0 -169
- package/lib/clean-github-actions-caches.d.ts +0 -169
- package/lib/del-gradle.d.mts +0 -2
- package/lib/del-node-modules.d.mts +0 -2
- package/lib/del-ps.d.mts +0 -2
- package/lib/del-yarn-caches.d.mts +0 -2
- package/lib/find-node-modules-cli.d.mts +0 -1
- package/lib/find-node-modules.d.mts +0 -13
- package/lib/find-node-modules.js +0 -53
- package/lib/git/gitattributes.d.mts +0 -35
- package/lib/git/gitattributes.js +0 -223
- package/lib/git/line-endings.d.mts +0 -83
- package/lib/git/line-endings.d.ts +0 -83
- package/lib/git/normalize.d.mts +0 -43
- package/lib/git/normalize.d.ts +0 -43
- package/lib/git/permissions.d.mts +0 -17
- package/lib/git/permissions.d.ts +0 -17
- package/lib/git/pull-strategy.d.mts +0 -15
- package/lib/git/pull-strategy.d.ts +0 -15
- package/lib/git/user-config.d.mts +0 -105
- package/lib/git/user-config.d.ts +0 -105
- package/lib/git/utils.d.mts +0 -69
- package/lib/git/utils.d.ts +0 -69
- package/lib/git-diff.d.mts +0 -84
- package/lib/git-fix.d.mts +0 -141
- package/lib/git-fix.d.ts +0 -141
- package/lib/git-purge.d.mts +0 -2
- package/lib/git-purge.js +0 -59
- package/lib/index.d.mts +0 -1
- package/lib/npm-run-series.d.mts +0 -1
- package/lib/npm-run-series.js +0 -86
- package/lib/package-resolutions-updater.d.ts +0 -352
- package/lib/print-directory-tree.d.mts +0 -234
- package/lib/print-directory-tree.d.ts +0 -234
- package/lib/ps/connected-domain.d.mts +0 -3
- package/lib/ps/index.d.d.mts +0 -26
- package/lib/ps/index.d.d.ts +0 -26
- package/lib/ps/index.d.mts +0 -26
- package/lib/ps/isWin.d.mts +0 -3
- package/lib/ps/table-parser.d.mts +0 -3
- package/lib/submodule-install.d.mts +0 -121
- package/lib/submodule-install.d.ts +0 -121
- package/lib/utils.d.mts +0 -40
- package/lib/utils.js +0 -181
- package/lib/yarn-reinstall.d.mts +0 -49
- package/lib/yarn-reinstall.d.ts +0 -49
- package/src/package-resolutions-updater.mjs +0 -350
- package/src/print-directory-tree.cjs +0 -234
- package/src/ps/index.js +0 -286
- package/src/yarn-reinstall.cjs +0 -49
- /package/{bin → binaries}/nodekill +0 -0
- /package/{bin → binaries}/nodekill.cmd +0 -0
- /package/lib/{binary-collections-config.d.ts → binary-collections-config.d.cts} +0 -0
- /package/lib/{changelog.d.ts → changelog.d.cts} +0 -0
- /package/lib/{git-purge.d.ts → free-chatgpt.d.ts} +0 -0
- /package/lib/{git-diff.d.cts → git-diff-cli.d.ts} +0 -0
- /package/lib/{npm-run-series.d.ts → npm-run-series.d.cts} +0 -0
- /package/lib/{utils.d.ts → utils/index.d.cts} +0 -0
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
16
|
+
const minimist_1 = __importDefault(require("minimist"));
|
|
17
|
+
const upath_1 = __importDefault(require("upath"));
|
|
18
|
+
const submodule_remove_cjs_1 = __importDefault(require("./submodule-remove.cjs"));
|
|
19
|
+
const args = (0, minimist_1.default)(process.argv.slice(2));
|
|
20
|
+
const submodulePath = args._[0];
|
|
21
|
+
if (!submodulePath) {
|
|
22
|
+
console.error("Usage: node submodule-remove.cjs <submodule-path>");
|
|
23
|
+
process.exit(1);
|
|
24
|
+
}
|
|
25
|
+
if (!fs_extra_1.default.existsSync(upath_1.default.resolve(submodulePath))) {
|
|
26
|
+
console.error(`Error: The path "${submodulePath}" does not exist.`);
|
|
27
|
+
process.exit(1);
|
|
28
|
+
}
|
|
29
|
+
(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
30
|
+
yield (0, submodule_remove_cjs_1.default)(submodulePath);
|
|
31
|
+
}))();
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { createRequire } from 'module'; const require = createRequire(import.meta.url);
|
|
2
|
+
import {
|
|
3
|
+
require_submodule_remove
|
|
4
|
+
} from "./chunk-BZWVHODJ.mjs";
|
|
5
|
+
import {
|
|
6
|
+
__toESM,
|
|
7
|
+
init_esm_shims
|
|
8
|
+
} from "./chunk-QQ4A6DLD.mjs";
|
|
9
|
+
|
|
10
|
+
// src/submodule-remove-cli.js
|
|
11
|
+
init_esm_shims();
|
|
12
|
+
var import_submodule_remove = __toESM(require_submodule_remove(), 1);
|
|
13
|
+
import fs from "fs-extra";
|
|
14
|
+
import minimist from "minimist";
|
|
15
|
+
import path from "upath";
|
|
16
|
+
var args = minimist(process.argv.slice(2));
|
|
17
|
+
var submodulePath = args._[0];
|
|
18
|
+
if (!submodulePath) {
|
|
19
|
+
console.error("Usage: node submodule-remove.cjs <submodule-path>");
|
|
20
|
+
process.exit(1);
|
|
21
|
+
}
|
|
22
|
+
if (!fs.existsSync(path.resolve(submodulePath))) {
|
|
23
|
+
console.error(`Error: The path "${submodulePath}" does not exist.`);
|
|
24
|
+
process.exit(1);
|
|
25
|
+
}
|
|
26
|
+
(async () => {
|
|
27
|
+
await (0, import_submodule_remove.default)(submodulePath);
|
|
28
|
+
})();
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
// src/submodule-remove.cjs
|
|
2
|
+
var { spawnAsync } = require("cross-spawn");
|
|
3
|
+
var path = require("upath");
|
|
4
|
+
var fs = require("fs-extra");
|
|
5
|
+
var dotenv = require("dotenv");
|
|
6
|
+
var envPath = path.resolve(process.cwd(), ".env");
|
|
7
|
+
if (fs.existsSync(envPath)) {
|
|
8
|
+
dotenv.config({ path: envPath, override: true, quiet: true });
|
|
9
|
+
}
|
|
10
|
+
async function removeSubmodule(submodulePath) {
|
|
11
|
+
try {
|
|
12
|
+
await spawnAsync("git", ["submodule", "deinit", "-f", submodulePath], { stdio: "inherit" });
|
|
13
|
+
} catch (error) {
|
|
14
|
+
console.warn(`Warning: Could not deinitialize submodule "${submodulePath}". It may not exist.`);
|
|
15
|
+
console.warn(error.message);
|
|
16
|
+
}
|
|
17
|
+
try {
|
|
18
|
+
await spawnAsync("git", ["config", "--remove-section", `submodule.${submodulePath}`], { stdio: "inherit" });
|
|
19
|
+
} catch (error) {
|
|
20
|
+
console.warn(`Warning: Could not remove git config section for submodule "${submodulePath}". It may not exist.`);
|
|
21
|
+
console.warn(error.message);
|
|
22
|
+
}
|
|
23
|
+
const gitModulesPath = path.resolve(".git", "modules", submodulePath);
|
|
24
|
+
if (fs.existsSync(gitModulesPath)) {
|
|
25
|
+
fs.rmSync(gitModulesPath, { recursive: true, force: true });
|
|
26
|
+
console.log(`Removed .git/modules entry for submodule "${submodulePath}".`);
|
|
27
|
+
} else {
|
|
28
|
+
console.warn(`Warning: The path "${gitModulesPath}" does not exist. Skipping removal of .git/modules entry.`);
|
|
29
|
+
}
|
|
30
|
+
const gitmodulesPath = path.resolve(".gitmodules");
|
|
31
|
+
if (fs.existsSync(gitmodulesPath)) {
|
|
32
|
+
let gitmodulesContent = fs.readFileSync(gitmodulesPath, "utf-8");
|
|
33
|
+
const submoduleSectionRegex = new RegExp(
|
|
34
|
+
`\\[submodule "${submodulePath.replace(/[-/\\^$*+?.()|[\]{}]/g, "\\$&")}"]([\\s\\S]*?)(?=\\[|$)`,
|
|
35
|
+
"g"
|
|
36
|
+
);
|
|
37
|
+
gitmodulesContent = gitmodulesContent.replace(submoduleSectionRegex, "").trim();
|
|
38
|
+
fs.writeFileSync(gitmodulesPath, gitmodulesContent);
|
|
39
|
+
console.log(`Removed submodule "${submodulePath}" from .gitmodules.`);
|
|
40
|
+
} else {
|
|
41
|
+
console.warn(`Warning: The .gitmodules file does not exist. Skipping removal of submodule "${submodulePath}".`);
|
|
42
|
+
}
|
|
43
|
+
fs.rmSync(path.resolve(submodulePath), { recursive: true, force: true });
|
|
44
|
+
console.log(`Submodule "${submodulePath}" has been removed.`);
|
|
45
|
+
}
|
|
46
|
+
module.exports = removeSubmodule;
|
|
@@ -0,0 +1,541 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
21
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
22
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
23
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
24
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
25
|
+
mod
|
|
26
|
+
));
|
|
27
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
28
|
+
|
|
29
|
+
// src/utils/chatgpt.js
|
|
30
|
+
var chatgpt_exports = {};
|
|
31
|
+
__export(chatgpt_exports, {
|
|
32
|
+
runChatGpt: () => runChatGpt
|
|
33
|
+
});
|
|
34
|
+
module.exports = __toCommonJS(chatgpt_exports);
|
|
35
|
+
var import_fs_extra = __toESM(require("fs-extra"), 1);
|
|
36
|
+
var import_puppeteer_extra = __toESM(require("puppeteer-extra"), 1);
|
|
37
|
+
var import_puppeteer_extra_plugin_stealth = __toESM(require("puppeteer-extra-plugin-stealth"), 1);
|
|
38
|
+
var import_upath = __toESM(require("upath"), 1);
|
|
39
|
+
var COOKIE_DIR = import_upath.default.join(process.cwd(), "tmp", "cookies");
|
|
40
|
+
var DEFAULT_COOKIE_PATH = import_upath.default.join(COOKIE_DIR, "cookies.json");
|
|
41
|
+
var NAVIGATION_TIMEOUT_MS = 9e4;
|
|
42
|
+
var NETWORK_IDLE_TIMEOUT_MS = 15e3;
|
|
43
|
+
var MAX_INLINE_QUESTION_FILE_BYTES = 2 * 1024;
|
|
44
|
+
import_fs_extra.default.ensureDirSync(COOKIE_DIR);
|
|
45
|
+
async function gotoWithFallback(page, url) {
|
|
46
|
+
await page.goto(url, { waitUntil: "domcontentloaded", timeout: NAVIGATION_TIMEOUT_MS });
|
|
47
|
+
try {
|
|
48
|
+
await page.waitForNetworkIdle({ idleTime: 1e3, timeout: NETWORK_IDLE_TIMEOUT_MS });
|
|
49
|
+
} catch {
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
async function saveCookies(page, path2 = DEFAULT_COOKIE_PATH) {
|
|
53
|
+
const cookies = await page.cookies();
|
|
54
|
+
import_fs_extra.default.writeFileSync(path2, JSON.stringify(cookies, null, 2));
|
|
55
|
+
}
|
|
56
|
+
function getCookiePathForUrl(url) {
|
|
57
|
+
try {
|
|
58
|
+
const { hostname } = new URL(url);
|
|
59
|
+
return import_upath.default.join(COOKIE_DIR, `cookies_${hostname}.json`);
|
|
60
|
+
} catch {
|
|
61
|
+
return DEFAULT_COOKIE_PATH;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
async function navigatePage(page, url) {
|
|
65
|
+
const cookiePath = getCookiePathForUrl(url);
|
|
66
|
+
const cookies = loadCookies(cookiePath);
|
|
67
|
+
if (cookies) {
|
|
68
|
+
await page.setCookie(...cookies);
|
|
69
|
+
}
|
|
70
|
+
await gotoWithFallback(page, url);
|
|
71
|
+
await page.evaluate(() => {
|
|
72
|
+
window.__domStillUpdating = true;
|
|
73
|
+
if (window.__domObserver) {
|
|
74
|
+
window.__domObserver.disconnect();
|
|
75
|
+
}
|
|
76
|
+
window.__domObserver = new MutationObserver(() => {
|
|
77
|
+
window.__lastDomMutation = Date.now();
|
|
78
|
+
});
|
|
79
|
+
window.__lastDomMutation = Date.now();
|
|
80
|
+
window.__domObserver.observe(document.body, {
|
|
81
|
+
childList: true,
|
|
82
|
+
subtree: true,
|
|
83
|
+
attributes: true,
|
|
84
|
+
characterData: true
|
|
85
|
+
});
|
|
86
|
+
setTimeout(() => {
|
|
87
|
+
window.__domStillUpdating = false;
|
|
88
|
+
window.__domObserver.disconnect();
|
|
89
|
+
}, 3e4);
|
|
90
|
+
});
|
|
91
|
+
const waitForDomIdle = async (idleMs = 1e3, timeout = 1e4) => {
|
|
92
|
+
const start = Date.now();
|
|
93
|
+
while (Date.now() - start < timeout) {
|
|
94
|
+
const lastMutation = await page.evaluate(() => window.__lastDomMutation);
|
|
95
|
+
const idle = Date.now() - lastMutation;
|
|
96
|
+
if (idle >= idleMs) {
|
|
97
|
+
return true;
|
|
98
|
+
}
|
|
99
|
+
await new Promise((r) => setTimeout(r, 200));
|
|
100
|
+
}
|
|
101
|
+
throw new Error("DOM did not stabilize within timeout");
|
|
102
|
+
};
|
|
103
|
+
return { waitForDomIdle };
|
|
104
|
+
}
|
|
105
|
+
function loadCookies(cookieFilePath = DEFAULT_COOKIE_PATH) {
|
|
106
|
+
if (!import_fs_extra.default.existsSync(cookieFilePath)) return null;
|
|
107
|
+
return JSON.parse(import_fs_extra.default.readFileSync(cookieFilePath));
|
|
108
|
+
}
|
|
109
|
+
async function writeQuestion(page, question) {
|
|
110
|
+
const promptTextarea = await page.waitForSelector("#prompt-textarea", { timeout: 3e4 });
|
|
111
|
+
if (!promptTextarea) {
|
|
112
|
+
console.log(
|
|
113
|
+
"Cannot find the prompt input on the webpage. Please check whether you have access to chat.openai.com without logging in via your browser."
|
|
114
|
+
);
|
|
115
|
+
return;
|
|
116
|
+
}
|
|
117
|
+
await page.evaluate((text) => {
|
|
118
|
+
const promptEl = document.querySelector("#prompt-textarea");
|
|
119
|
+
if (!promptEl) {
|
|
120
|
+
return;
|
|
121
|
+
}
|
|
122
|
+
promptEl.focus();
|
|
123
|
+
promptEl.innerHTML = "";
|
|
124
|
+
const lines = String(text).split("\n");
|
|
125
|
+
for (const line of lines) {
|
|
126
|
+
const p = document.createElement("p");
|
|
127
|
+
p.textContent = line;
|
|
128
|
+
promptEl.appendChild(p);
|
|
129
|
+
}
|
|
130
|
+
promptEl.dispatchEvent(new InputEvent("beforeinput", { bubbles: true, inputType: "insertFromPaste", data: text }));
|
|
131
|
+
promptEl.dispatchEvent(new InputEvent("input", { bubbles: true, inputType: "insertFromPaste", data: text }));
|
|
132
|
+
promptEl.dispatchEvent(new Event("change", { bubbles: true }));
|
|
133
|
+
}, question);
|
|
134
|
+
const hasPromptText = await page.evaluate(() => {
|
|
135
|
+
const promptEl = document.querySelector("#prompt-textarea");
|
|
136
|
+
return Boolean(promptEl && promptEl.textContent && promptEl.textContent.trim().length > 0);
|
|
137
|
+
});
|
|
138
|
+
if (!hasPromptText) {
|
|
139
|
+
console.log("Prompt state not updated by DOM injection. Falling back to keyboard insertText.");
|
|
140
|
+
await promptTextarea.click({ clickCount: 1 });
|
|
141
|
+
await page.keyboard.down("Control");
|
|
142
|
+
await page.keyboard.press("KeyA");
|
|
143
|
+
await page.keyboard.up("Control");
|
|
144
|
+
await page.keyboard.insertText(question);
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
async function clickSubmitButton(page) {
|
|
148
|
+
console.log("Attempting to click the submit button...");
|
|
149
|
+
try {
|
|
150
|
+
const userMessageCountBefore = await page.$$eval('[data-message-author-role="user"]', (elements) => elements.length);
|
|
151
|
+
const waitForSubmit = async (timeout = 5e3) => {
|
|
152
|
+
try {
|
|
153
|
+
await page.waitForFunction(
|
|
154
|
+
(previousCount) => {
|
|
155
|
+
const currentCount = document.querySelectorAll('[data-message-author-role="user"]').length;
|
|
156
|
+
return currentCount > previousCount;
|
|
157
|
+
},
|
|
158
|
+
{ timeout },
|
|
159
|
+
userMessageCountBefore
|
|
160
|
+
);
|
|
161
|
+
return true;
|
|
162
|
+
} catch {
|
|
163
|
+
return false;
|
|
164
|
+
}
|
|
165
|
+
};
|
|
166
|
+
await page.waitForFunction(() => {
|
|
167
|
+
const candidates = [
|
|
168
|
+
document.querySelector('[data-testid="fruitjuice-send-button"]'),
|
|
169
|
+
document.querySelector("#composer-submit-button"),
|
|
170
|
+
document.querySelector('[data-testid="send-button"]')
|
|
171
|
+
].filter(Boolean);
|
|
172
|
+
return candidates.some((button) => {
|
|
173
|
+
const isDisabled = button.disabled || button.getAttribute("aria-disabled") === "true";
|
|
174
|
+
const isVisible = button.offsetParent !== null;
|
|
175
|
+
return !isDisabled && isVisible;
|
|
176
|
+
});
|
|
177
|
+
}, { timeout: 5e3 }).catch(() => {
|
|
178
|
+
});
|
|
179
|
+
const buttonDetails = await page.evaluate(() => {
|
|
180
|
+
const selectors = [
|
|
181
|
+
'[data-testid="fruitjuice-send-button"]',
|
|
182
|
+
"#composer-submit-button",
|
|
183
|
+
'[data-testid="send-button"]'
|
|
184
|
+
];
|
|
185
|
+
const details = selectors.map((selector) => {
|
|
186
|
+
const el = document.querySelector(selector);
|
|
187
|
+
const exists = Boolean(el);
|
|
188
|
+
const disabled = exists ? Boolean(el.disabled || el.getAttribute("aria-disabled") === "true") : null;
|
|
189
|
+
const visible = exists ? el.offsetParent !== null : null;
|
|
190
|
+
return { selector, exists, disabled, visible };
|
|
191
|
+
});
|
|
192
|
+
return details;
|
|
193
|
+
});
|
|
194
|
+
console.log(`Submit button details: ${JSON.stringify(buttonDetails)}`);
|
|
195
|
+
const clickable = buttonDetails.find((item) => item.exists && item.visible && item.disabled === false);
|
|
196
|
+
const selectedSelector = clickable ? clickable.selector : null;
|
|
197
|
+
if (selectedSelector) {
|
|
198
|
+
await page.click(selectedSelector);
|
|
199
|
+
console.log(`Clicked submit button selector: ${selectedSelector}`);
|
|
200
|
+
if (await waitForSubmit(5e3)) {
|
|
201
|
+
console.log("Submission detected after selector click.");
|
|
202
|
+
return true;
|
|
203
|
+
}
|
|
204
|
+
const forcedClickWorked = await page.evaluate((selector) => {
|
|
205
|
+
const el = document.querySelector(selector);
|
|
206
|
+
if (!el) {
|
|
207
|
+
return false;
|
|
208
|
+
}
|
|
209
|
+
el.click();
|
|
210
|
+
return true;
|
|
211
|
+
}, selectedSelector);
|
|
212
|
+
if (forcedClickWorked) {
|
|
213
|
+
console.log(`Forced DOM click on selector: ${selectedSelector}`);
|
|
214
|
+
if (await waitForSubmit(5e3)) {
|
|
215
|
+
console.log("Submission detected after forced DOM click.");
|
|
216
|
+
return true;
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
console.log("Submit button path did not submit. Trying Enter key fallback on prompt.");
|
|
221
|
+
await page.focus("#prompt-textarea");
|
|
222
|
+
await page.keyboard.press("Enter");
|
|
223
|
+
if (await waitForSubmit(5e3)) {
|
|
224
|
+
console.log("Submission detected after Enter key fallback.");
|
|
225
|
+
return true;
|
|
226
|
+
}
|
|
227
|
+
const didRequestSubmit = await page.evaluate(() => {
|
|
228
|
+
const prompt = document.querySelector("#prompt-textarea");
|
|
229
|
+
if (!prompt) {
|
|
230
|
+
return false;
|
|
231
|
+
}
|
|
232
|
+
const form = prompt.closest("form");
|
|
233
|
+
if (!form) {
|
|
234
|
+
return false;
|
|
235
|
+
}
|
|
236
|
+
if (typeof form.requestSubmit === "function") {
|
|
237
|
+
form.requestSubmit();
|
|
238
|
+
} else {
|
|
239
|
+
form.submit();
|
|
240
|
+
}
|
|
241
|
+
return true;
|
|
242
|
+
});
|
|
243
|
+
if (didRequestSubmit) {
|
|
244
|
+
console.log("Triggered form submit fallback.");
|
|
245
|
+
if (await waitForSubmit(5e3)) {
|
|
246
|
+
console.log("Submission detected after form submit fallback.");
|
|
247
|
+
return true;
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
console.log("Failed to submit prompt after all strategies.");
|
|
251
|
+
return false;
|
|
252
|
+
} catch (e) {
|
|
253
|
+
console.log(`Failed to click the send button: ${e}`);
|
|
254
|
+
return false;
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
var lastMessageId = null;
|
|
258
|
+
var messageCount = 0;
|
|
259
|
+
var is_streaming = false;
|
|
260
|
+
function sleep(ms) {
|
|
261
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
262
|
+
}
|
|
263
|
+
async function waitForInitialResponse(page, timeout = 3e4) {
|
|
264
|
+
const startTime = Date.now();
|
|
265
|
+
while (Date.now() - startTime < timeout) {
|
|
266
|
+
const assistantMessages = await page.$$('[data-message-author-role="assistant"]');
|
|
267
|
+
const currentMessageCount = assistantMessages.length;
|
|
268
|
+
if (currentMessageCount > messageCount) {
|
|
269
|
+
const lastMessage = assistantMessages[assistantMessages.length - 1];
|
|
270
|
+
const isThinking = await lastMessage.$(".result-thinking");
|
|
271
|
+
if (!isThinking) {
|
|
272
|
+
lastMessageId = await page.evaluate((element) => element.getAttribute("data-message-id"), lastMessage);
|
|
273
|
+
messageCount = currentMessageCount;
|
|
274
|
+
return;
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
await sleep(100);
|
|
278
|
+
}
|
|
279
|
+
console.log("Timed out waiting for the initial response.");
|
|
280
|
+
}
|
|
281
|
+
async function handleStreamingResponse(page, outputFile = import_upath.default.join(process.cwd(), "tmp/response.txt")) {
|
|
282
|
+
let previousText = "";
|
|
283
|
+
let completeResponse = "";
|
|
284
|
+
let newContentDetected = false;
|
|
285
|
+
while (!newContentDetected) {
|
|
286
|
+
const assistantMessages = await page.$$('[data-message-author-role="assistant"]');
|
|
287
|
+
if (assistantMessages.length > 0) {
|
|
288
|
+
const lastMessage = assistantMessages[assistantMessages.length - 1];
|
|
289
|
+
const currentMessageId = await page.evaluate((element) => element.getAttribute("data-message-id"), lastMessage);
|
|
290
|
+
if (currentMessageId === lastMessageId) {
|
|
291
|
+
const currentText = await page.evaluate((element) => element.textContent, lastMessage);
|
|
292
|
+
console.log(`Current text: ${currentText}`);
|
|
293
|
+
if (currentText !== previousText) {
|
|
294
|
+
if (is_streaming) {
|
|
295
|
+
process.stdout.write(currentText.slice(previousText.length));
|
|
296
|
+
} else {
|
|
297
|
+
completeResponse += currentText.slice(previousText.length);
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
previousText = currentText;
|
|
301
|
+
const isStreaming = await lastMessage.$(".result-streaming");
|
|
302
|
+
if (!isStreaming) {
|
|
303
|
+
newContentDetected = true;
|
|
304
|
+
}
|
|
305
|
+
} else {
|
|
306
|
+
lastMessageId = currentMessageId;
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
await sleep(100);
|
|
310
|
+
}
|
|
311
|
+
if (!is_streaming) {
|
|
312
|
+
console.log(completeResponse.trim());
|
|
313
|
+
console.log("\n\n");
|
|
314
|
+
import_fs_extra.default.ensureDirSync(import_upath.default.dirname(outputFile));
|
|
315
|
+
import_fs_extra.default.writeFileSync(outputFile, completeResponse.trim());
|
|
316
|
+
console.log(`Response saved to ${outputFile}`);
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
async function isLoggedIn(page) {
|
|
320
|
+
const result = await page.evaluate(() => {
|
|
321
|
+
const loginButton = document.querySelector('[data-testid="login-button"]');
|
|
322
|
+
return !(loginButton && loginButton.offsetParent !== null);
|
|
323
|
+
});
|
|
324
|
+
return result === true;
|
|
325
|
+
}
|
|
326
|
+
async function createBrowser(browserOptions = {}) {
|
|
327
|
+
const windowsChromeExecutable = "C:\\Program Files\\Google\\Chrome\\Application\\chrome.exe";
|
|
328
|
+
const hasWindowsChrome = process.platform === "win32" && import_fs_extra.default.existsSync(windowsChromeExecutable);
|
|
329
|
+
const defaultOptions = {
|
|
330
|
+
headless: false,
|
|
331
|
+
defaultViewport: null,
|
|
332
|
+
userDataDir: import_upath.default.join(process.cwd(), "tmp/puppeteer-profile"),
|
|
333
|
+
// Windows-specific options to handle browser launch issues
|
|
334
|
+
args: [
|
|
335
|
+
"--start-maximized",
|
|
336
|
+
"--no-sandbox",
|
|
337
|
+
"--disable-setuid-sandbox",
|
|
338
|
+
"--disable-dev-shm-usage",
|
|
339
|
+
"--disable-accelerated-2d-canvas",
|
|
340
|
+
"--no-first-run",
|
|
341
|
+
"--no-zygote",
|
|
342
|
+
"--disable-gpu",
|
|
343
|
+
"--disable-background-timer-throttling",
|
|
344
|
+
"--disable-backgrounding-occluded-windows",
|
|
345
|
+
"--disable-renderer-backgrounding"
|
|
346
|
+
],
|
|
347
|
+
ignoreDefaultArgs: ["--disable-extensions"],
|
|
348
|
+
...hasWindowsChrome && {
|
|
349
|
+
// Prefer local Chrome installation when present on Windows.
|
|
350
|
+
executablePath: windowsChromeExecutable
|
|
351
|
+
}
|
|
352
|
+
};
|
|
353
|
+
try {
|
|
354
|
+
return await import_puppeteer_extra.default.use((0, import_puppeteer_extra_plugin_stealth.default)()).launch({ ...defaultOptions, ...browserOptions });
|
|
355
|
+
} catch (_error) {
|
|
356
|
+
console.error("Failed to launch browser with default options. Trying fallback options...");
|
|
357
|
+
try {
|
|
358
|
+
return await import_puppeteer_extra.default.use((0, import_puppeteer_extra_plugin_stealth.default)()).launch({
|
|
359
|
+
headless: browserOptions.headless || false,
|
|
360
|
+
defaultViewport: null,
|
|
361
|
+
args: ["--start-maximized", "--no-sandbox", "--disable-setuid-sandbox"],
|
|
362
|
+
ignoreDefaultArgs: false,
|
|
363
|
+
...hasWindowsChrome && {
|
|
364
|
+
executablePath: windowsChromeExecutable
|
|
365
|
+
},
|
|
366
|
+
...browserOptions
|
|
367
|
+
});
|
|
368
|
+
} catch (fallbackError) {
|
|
369
|
+
console.error("Browser launch failed completely. Common solutions:");
|
|
370
|
+
console.error("1. Install Google Chrome if not installed");
|
|
371
|
+
console.error("2. Update Node.js to the latest version");
|
|
372
|
+
console.error("3. Try running: npm install puppeteer --force");
|
|
373
|
+
console.error("4. Check if antivirus is blocking browser launch");
|
|
374
|
+
throw new Error(`Browser launch failed: ${fallbackError.message}`);
|
|
375
|
+
}
|
|
376
|
+
}
|
|
377
|
+
}
|
|
378
|
+
async function loginToChatGpt() {
|
|
379
|
+
const browser = await createBrowser({ headless: false });
|
|
380
|
+
const page = (await browser.pages()).length > 0 ? (await browser.pages())[0] : await browser.newPage();
|
|
381
|
+
const url = "https://chat.openai.com";
|
|
382
|
+
const navigate = await navigatePage(page, url);
|
|
383
|
+
await navigate.waitForDomIdle(2e3, 1e4);
|
|
384
|
+
const loginButtonExists = await page.evaluate(() => {
|
|
385
|
+
return document.querySelector('[data-testid="login-button"]') !== null;
|
|
386
|
+
});
|
|
387
|
+
if (loginButtonExists) {
|
|
388
|
+
console.log("Login button found, clicking to log in...");
|
|
389
|
+
await page.click('[data-testid="login-button"]');
|
|
390
|
+
await page.waitForNavigation({ waitUntil: "domcontentloaded", timeout: NAVIGATION_TIMEOUT_MS });
|
|
391
|
+
try {
|
|
392
|
+
await page.waitForNetworkIdle({ idleTime: 1e3, timeout: NETWORK_IDLE_TIMEOUT_MS });
|
|
393
|
+
} catch {
|
|
394
|
+
}
|
|
395
|
+
console.log("Login process completed.");
|
|
396
|
+
} else {
|
|
397
|
+
console.log("No login required - user appears to be already logged in.");
|
|
398
|
+
}
|
|
399
|
+
}
|
|
400
|
+
async function runChatGpt(chatgptOptions = {}) {
|
|
401
|
+
const headless = chatgptOptions.headless !== void 0 ? chatgptOptions.headless : true;
|
|
402
|
+
const questionFile = chatgptOptions.questionFile;
|
|
403
|
+
let question = chatgptOptions.question;
|
|
404
|
+
let shouldUploadQuestionFile = Boolean(questionFile);
|
|
405
|
+
const responseFile = chatgptOptions.responseFile || import_upath.default.join(process.cwd(), "tmp", "response.txt");
|
|
406
|
+
const noInputProvided = !question && !questionFile;
|
|
407
|
+
const questionIsEmpty = question && question.trim().length === 0;
|
|
408
|
+
const questionFileIsEmpty = questionFile && questionFile.trim().length === 0;
|
|
409
|
+
if (noInputProvided || questionIsEmpty || questionFileIsEmpty) {
|
|
410
|
+
throw new Error("You must provide a question or a question file.");
|
|
411
|
+
}
|
|
412
|
+
if (!question && questionFile) {
|
|
413
|
+
if (!import_fs_extra.default.existsSync(questionFile)) {
|
|
414
|
+
throw new Error(`Question file does not exist: ${questionFile}`);
|
|
415
|
+
}
|
|
416
|
+
const questionFileStats = import_fs_extra.default.statSync(questionFile);
|
|
417
|
+
if (questionFileStats.size <= MAX_INLINE_QUESTION_FILE_BYTES) {
|
|
418
|
+
question = import_fs_extra.default.readFileSync(questionFile, "utf8").trim();
|
|
419
|
+
if (!question) {
|
|
420
|
+
throw new Error("Question file is empty.");
|
|
421
|
+
}
|
|
422
|
+
shouldUploadQuestionFile = false;
|
|
423
|
+
console.log(
|
|
424
|
+
`Question file is ${questionFileStats.size} bytes (<= ${MAX_INLINE_QUESTION_FILE_BYTES}). Sending as text prompt.`
|
|
425
|
+
);
|
|
426
|
+
}
|
|
427
|
+
}
|
|
428
|
+
let browser;
|
|
429
|
+
try {
|
|
430
|
+
browser = await createBrowser({ headless });
|
|
431
|
+
} catch (error) {
|
|
432
|
+
console.error("Error running ChatGPT:", error);
|
|
433
|
+
console.error("\nTroubleshooting steps:");
|
|
434
|
+
console.error("1. Make sure Google Chrome is installed");
|
|
435
|
+
console.error("2. Try running: yarn add puppeteer --force");
|
|
436
|
+
console.error("3. Check if your antivirus is blocking the browser");
|
|
437
|
+
console.error("4. Close any running Chrome instances and try again");
|
|
438
|
+
throw error;
|
|
439
|
+
}
|
|
440
|
+
const allPages = await browser.pages();
|
|
441
|
+
const page = allPages.length > 0 ? allPages[0] : await browser.newPage();
|
|
442
|
+
await page.bringToFront();
|
|
443
|
+
if (allPages.length > 1) {
|
|
444
|
+
for (const p of allPages) {
|
|
445
|
+
if (p !== page) {
|
|
446
|
+
await p.close();
|
|
447
|
+
}
|
|
448
|
+
}
|
|
449
|
+
}
|
|
450
|
+
try {
|
|
451
|
+
const url = "https://chat.openai.com";
|
|
452
|
+
const navigate = await navigatePage(page, url);
|
|
453
|
+
await navigate.waitForDomIdle(2e3, 15e3);
|
|
454
|
+
try {
|
|
455
|
+
const tempChatButton = await page.$('button[aria-label="Turn on temporary chat"]');
|
|
456
|
+
if (tempChatButton) {
|
|
457
|
+
await page.evaluate((el) => el.click(), tempChatButton);
|
|
458
|
+
console.log("Successfully clicked temporary chat button");
|
|
459
|
+
await navigate.waitForDomIdle(1e3, 1e4);
|
|
460
|
+
} else {
|
|
461
|
+
console.log("Temporary chat button not found, proceeding without it.");
|
|
462
|
+
}
|
|
463
|
+
} catch (error) {
|
|
464
|
+
console.log(`Failed to click temporary chat button: ${error.message}`);
|
|
465
|
+
}
|
|
466
|
+
if (question) {
|
|
467
|
+
await writeQuestion(page, question);
|
|
468
|
+
const didSubmit = await clickSubmitButton(page);
|
|
469
|
+
if (!didSubmit) {
|
|
470
|
+
throw new Error("Prompt was not submitted. The composer button may be disabled or blocked.");
|
|
471
|
+
}
|
|
472
|
+
await navigate.waitForDomIdle(1e3, 3e4);
|
|
473
|
+
await waitForInitialResponse(page);
|
|
474
|
+
await handleStreamingResponse(page, responseFile);
|
|
475
|
+
await saveCookies(page, getCookiePathForUrl(url));
|
|
476
|
+
} else if (shouldUploadQuestionFile && questionFile) {
|
|
477
|
+
await navigate.waitForDomIdle(2e3, 1e4);
|
|
478
|
+
const isUserLoggedIn = await isLoggedIn(page);
|
|
479
|
+
console.log(`Login status: ${isUserLoggedIn ? "Logged in" : "Not logged in"}`);
|
|
480
|
+
if (!isUserLoggedIn) {
|
|
481
|
+
console.log(
|
|
482
|
+
"Not logged in. Please log in to ChatGPT in the browser window, then close it and run the command again."
|
|
483
|
+
);
|
|
484
|
+
return loginToChatGpt();
|
|
485
|
+
}
|
|
486
|
+
const plusButtonExists = await page.evaluate(() => {
|
|
487
|
+
const button = document.querySelector('[data-testid="composer-plus-btn"]');
|
|
488
|
+
return button !== null;
|
|
489
|
+
});
|
|
490
|
+
if (plusButtonExists) {
|
|
491
|
+
await page.click('[data-testid="composer-plus-btn"]');
|
|
492
|
+
await sleep(500);
|
|
493
|
+
const menuItems = await page.$$('[role="menuitem"]');
|
|
494
|
+
let clicked = false;
|
|
495
|
+
for (const item of menuItems) {
|
|
496
|
+
const text = await page.evaluate((el) => el.innerText, item);
|
|
497
|
+
if (text && text.includes("Add photos") && text.includes("files")) {
|
|
498
|
+
await item.hover();
|
|
499
|
+
clicked = true;
|
|
500
|
+
break;
|
|
501
|
+
}
|
|
502
|
+
}
|
|
503
|
+
if (!clicked) {
|
|
504
|
+
console.log('Could not find the "Add photos & files" menu item.');
|
|
505
|
+
return;
|
|
506
|
+
}
|
|
507
|
+
try {
|
|
508
|
+
await sleep(1e3);
|
|
509
|
+
const fileInput = await page.waitForSelector('input[type="file"]', { timeout: 1e4 });
|
|
510
|
+
if (fileInput) {
|
|
511
|
+
console.log(`Uploading file: ${questionFile}`);
|
|
512
|
+
await fileInput.uploadFile(questionFile);
|
|
513
|
+
await navigate.waitForDomIdle(2e3, 15e3);
|
|
514
|
+
console.log("File uploaded successfully");
|
|
515
|
+
const didSubmit = await clickSubmitButton(page);
|
|
516
|
+
if (!didSubmit) {
|
|
517
|
+
throw new Error("Prompt was not submitted after file upload.");
|
|
518
|
+
}
|
|
519
|
+
await navigate.waitForDomIdle(1e3, 3e4);
|
|
520
|
+
await waitForInitialResponse(page);
|
|
521
|
+
await handleStreamingResponse(page, responseFile);
|
|
522
|
+
} else {
|
|
523
|
+
console.log("Could not find file input element");
|
|
524
|
+
}
|
|
525
|
+
} catch (error) {
|
|
526
|
+
console.log(`Error uploading file: ${error.message}`);
|
|
527
|
+
}
|
|
528
|
+
} else {
|
|
529
|
+
console.log('Could not find the [data-testid="composer-plus-btn"] button.');
|
|
530
|
+
}
|
|
531
|
+
}
|
|
532
|
+
} finally {
|
|
533
|
+
if (browser) {
|
|
534
|
+
await browser.close();
|
|
535
|
+
}
|
|
536
|
+
}
|
|
537
|
+
}
|
|
538
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
539
|
+
0 && (module.exports = {
|
|
540
|
+
runChatGpt
|
|
541
|
+
});
|