antigravity-auth 1.6.0 → 1.7.0
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/README.md +79 -41
- package/dist/cli.js +2868 -0
- package/dist/handler.js +25119 -0
- package/dist/index.js +25110 -5
- package/package.json +66 -54
- package/dist/antigravity/oauth.d.ts +0 -30
- package/dist/antigravity/oauth.js +0 -170
- package/dist/claude/login.d.ts +0 -7
- package/dist/claude/login.js +0 -480
- package/dist/claude/menu-helpers.d.ts +0 -22
- package/dist/claude/menu-helpers.js +0 -281
- package/dist/claude/proxy-manager.d.ts +0 -11
- package/dist/claude/proxy-manager.js +0 -129
- package/dist/claude/proxy.d.ts +0 -1
- package/dist/claude/proxy.js +0 -733
- package/dist/constants.d.ts +0 -138
- package/dist/constants.js +0 -216
- package/dist/hooks/auto-update-checker/cache.d.ts +0 -2
- package/dist/hooks/auto-update-checker/cache.js +0 -70
- package/dist/hooks/auto-update-checker/checker.d.ts +0 -15
- package/dist/hooks/auto-update-checker/checker.js +0 -233
- package/dist/hooks/auto-update-checker/constants.d.ts +0 -8
- package/dist/hooks/auto-update-checker/constants.js +0 -22
- package/dist/hooks/auto-update-checker/index.d.ts +0 -33
- package/dist/hooks/auto-update-checker/index.js +0 -121
- package/dist/hooks/auto-update-checker/logging.d.ts +0 -2
- package/dist/hooks/auto-update-checker/logging.js +0 -8
- package/dist/hooks/auto-update-checker/types.d.ts +0 -24
- package/dist/hooks/auto-update-checker/types.js +0 -1
- package/dist/index.d.ts +0 -6
- package/dist/opencode/hooks/auto-update-checker/cache.d.ts +0 -2
- package/dist/opencode/hooks/auto-update-checker/cache.js +0 -70
- package/dist/opencode/hooks/auto-update-checker/checker.d.ts +0 -15
- package/dist/opencode/hooks/auto-update-checker/checker.js +0 -233
- package/dist/opencode/hooks/auto-update-checker/constants.d.ts +0 -8
- package/dist/opencode/hooks/auto-update-checker/constants.js +0 -22
- package/dist/opencode/hooks/auto-update-checker/index.d.ts +0 -33
- package/dist/opencode/hooks/auto-update-checker/index.js +0 -121
- package/dist/opencode/hooks/auto-update-checker/logging.d.ts +0 -2
- package/dist/opencode/hooks/auto-update-checker/logging.js +0 -8
- package/dist/opencode/hooks/auto-update-checker/types.d.ts +0 -24
- package/dist/opencode/hooks/auto-update-checker/types.js +0 -1
- package/dist/opencode/plugin.d.ts +0 -29
- package/dist/opencode/plugin.js +0 -2954
- package/dist/plugin/accounts.d.ts +0 -173
- package/dist/plugin/accounts.js +0 -966
- package/dist/plugin/auth.d.ts +0 -20
- package/dist/plugin/auth.js +0 -44
- package/dist/plugin/cache/index.d.ts +0 -4
- package/dist/plugin/cache/index.js +0 -4
- package/dist/plugin/cache/signature-cache.d.ts +0 -110
- package/dist/plugin/cache/signature-cache.js +0 -347
- package/dist/plugin/cache.d.ts +0 -43
- package/dist/plugin/cache.js +0 -180
- package/dist/plugin/cli.d.ts +0 -26
- package/dist/plugin/cli.js +0 -126
- package/dist/plugin/config/index.d.ts +0 -15
- package/dist/plugin/config/index.js +0 -15
- package/dist/plugin/config/loader.d.ts +0 -38
- package/dist/plugin/config/loader.js +0 -150
- package/dist/plugin/config/models.d.ts +0 -26
- package/dist/plugin/config/models.js +0 -95
- package/dist/plugin/config/schema.d.ts +0 -144
- package/dist/plugin/config/schema.js +0 -458
- package/dist/plugin/config/updater.d.ts +0 -76
- package/dist/plugin/config/updater.js +0 -205
- package/dist/plugin/core/streaming/index.d.ts +0 -2
- package/dist/plugin/core/streaming/index.js +0 -2
- package/dist/plugin/core/streaming/transformer.d.ts +0 -9
- package/dist/plugin/core/streaming/transformer.js +0 -301
- package/dist/plugin/core/streaming/types.d.ts +0 -28
- package/dist/plugin/core/streaming/types.js +0 -1
- package/dist/plugin/debug.d.ts +0 -93
- package/dist/plugin/debug.js +0 -375
- package/dist/plugin/errors.d.ts +0 -27
- package/dist/plugin/errors.js +0 -41
- package/dist/plugin/fingerprint.d.ts +0 -69
- package/dist/plugin/fingerprint.js +0 -137
- package/dist/plugin/image-saver.d.ts +0 -24
- package/dist/plugin/image-saver.js +0 -78
- package/dist/plugin/logger.d.ts +0 -35
- package/dist/plugin/logger.js +0 -67
- package/dist/plugin/logging-utils.d.ts +0 -22
- package/dist/plugin/logging-utils.js +0 -91
- package/dist/plugin/project.d.ts +0 -32
- package/dist/plugin/project.js +0 -229
- package/dist/plugin/quota.d.ts +0 -34
- package/dist/plugin/quota.js +0 -261
- package/dist/plugin/recovery/constants.d.ts +0 -21
- package/dist/plugin/recovery/constants.js +0 -42
- package/dist/plugin/recovery/index.d.ts +0 -11
- package/dist/plugin/recovery/index.js +0 -11
- package/dist/plugin/recovery/storage.d.ts +0 -23
- package/dist/plugin/recovery/storage.js +0 -340
- package/dist/plugin/recovery/types.d.ts +0 -115
- package/dist/plugin/recovery/types.js +0 -6
- package/dist/plugin/recovery.d.ts +0 -60
- package/dist/plugin/recovery.js +0 -360
- package/dist/plugin/refresh-queue.d.ts +0 -99
- package/dist/plugin/refresh-queue.js +0 -235
- package/dist/plugin/request-helpers.d.ts +0 -281
- package/dist/plugin/request-helpers.js +0 -2200
- package/dist/plugin/request.d.ts +0 -110
- package/dist/plugin/request.js +0 -1489
- package/dist/plugin/rotation.d.ts +0 -182
- package/dist/plugin/rotation.js +0 -364
- package/dist/plugin/search.d.ts +0 -31
- package/dist/plugin/search.js +0 -185
- package/dist/plugin/server.d.ts +0 -22
- package/dist/plugin/server.js +0 -306
- package/dist/plugin/storage.d.ts +0 -136
- package/dist/plugin/storage.js +0 -599
- package/dist/plugin/stores/signature-store.d.ts +0 -4
- package/dist/plugin/stores/signature-store.js +0 -24
- package/dist/plugin/thinking-recovery.d.ts +0 -89
- package/dist/plugin/thinking-recovery.js +0 -289
- package/dist/plugin/token.d.ts +0 -18
- package/dist/plugin/token.js +0 -127
- package/dist/plugin/transform/claude.d.ts +0 -79
- package/dist/plugin/transform/claude.js +0 -256
- package/dist/plugin/transform/cross-model-sanitizer.d.ts +0 -34
- package/dist/plugin/transform/cross-model-sanitizer.js +0 -224
- package/dist/plugin/transform/gemini.d.ts +0 -132
- package/dist/plugin/transform/gemini.js +0 -659
- package/dist/plugin/transform/index.d.ts +0 -14
- package/dist/plugin/transform/index.js +0 -9
- package/dist/plugin/transform/model-resolver.d.ts +0 -98
- package/dist/plugin/transform/model-resolver.js +0 -320
- package/dist/plugin/transform/types.d.ts +0 -110
- package/dist/plugin/transform/types.js +0 -1
- package/dist/plugin/types.d.ts +0 -95
- package/dist/plugin/types.js +0 -1
- package/dist/plugin/ui/ansi.d.ts +0 -31
- package/dist/plugin/ui/ansi.js +0 -45
- package/dist/plugin/ui/auth-menu.d.ts +0 -47
- package/dist/plugin/ui/auth-menu.js +0 -199
- package/dist/plugin/ui/confirm.d.ts +0 -1
- package/dist/plugin/ui/confirm.js +0 -14
- package/dist/plugin/ui/select.d.ts +0 -22
- package/dist/plugin/ui/select.js +0 -243
- package/dist/plugin/version.d.ts +0 -18
- package/dist/plugin/version.js +0 -79
- package/dist/src/antigravity/oauth.d.ts +0 -30
- package/dist/src/antigravity/oauth.js +0 -170
- package/dist/src/constants.d.ts +0 -138
- package/dist/src/constants.js +0 -216
- package/dist/src/hooks/auto-update-checker/cache.d.ts +0 -2
- package/dist/src/hooks/auto-update-checker/cache.js +0 -70
- package/dist/src/hooks/auto-update-checker/checker.d.ts +0 -15
- package/dist/src/hooks/auto-update-checker/checker.js +0 -233
- package/dist/src/hooks/auto-update-checker/constants.d.ts +0 -8
- package/dist/src/hooks/auto-update-checker/constants.js +0 -22
- package/dist/src/hooks/auto-update-checker/index.d.ts +0 -33
- package/dist/src/hooks/auto-update-checker/index.js +0 -121
- package/dist/src/hooks/auto-update-checker/logging.d.ts +0 -2
- package/dist/src/hooks/auto-update-checker/logging.js +0 -8
- package/dist/src/hooks/auto-update-checker/types.d.ts +0 -24
- package/dist/src/hooks/auto-update-checker/types.js +0 -1
- package/dist/src/index.d.ts +0 -6
- package/dist/src/index.js +0 -5
- package/dist/src/plugin/accounts.d.ts +0 -173
- package/dist/src/plugin/accounts.js +0 -966
- package/dist/src/plugin/auth.d.ts +0 -20
- package/dist/src/plugin/auth.js +0 -44
- package/dist/src/plugin/cache/index.d.ts +0 -4
- package/dist/src/plugin/cache/index.js +0 -4
- package/dist/src/plugin/cache/signature-cache.d.ts +0 -110
- package/dist/src/plugin/cache/signature-cache.js +0 -347
- package/dist/src/plugin/cache.d.ts +0 -43
- package/dist/src/plugin/cache.js +0 -180
- package/dist/src/plugin/cli.d.ts +0 -26
- package/dist/src/plugin/cli.js +0 -126
- package/dist/src/plugin/config/index.d.ts +0 -15
- package/dist/src/plugin/config/index.js +0 -15
- package/dist/src/plugin/config/loader.d.ts +0 -38
- package/dist/src/plugin/config/loader.js +0 -150
- package/dist/src/plugin/config/models.d.ts +0 -26
- package/dist/src/plugin/config/models.js +0 -95
- package/dist/src/plugin/config/schema.d.ts +0 -144
- package/dist/src/plugin/config/schema.js +0 -458
- package/dist/src/plugin/config/updater.d.ts +0 -76
- package/dist/src/plugin/config/updater.js +0 -205
- package/dist/src/plugin/core/streaming/index.d.ts +0 -2
- package/dist/src/plugin/core/streaming/index.js +0 -2
- package/dist/src/plugin/core/streaming/transformer.d.ts +0 -9
- package/dist/src/plugin/core/streaming/transformer.js +0 -301
- package/dist/src/plugin/core/streaming/types.d.ts +0 -28
- package/dist/src/plugin/core/streaming/types.js +0 -1
- package/dist/src/plugin/debug.d.ts +0 -93
- package/dist/src/plugin/debug.js +0 -375
- package/dist/src/plugin/errors.d.ts +0 -27
- package/dist/src/plugin/errors.js +0 -41
- package/dist/src/plugin/fingerprint.d.ts +0 -69
- package/dist/src/plugin/fingerprint.js +0 -137
- package/dist/src/plugin/image-saver.d.ts +0 -24
- package/dist/src/plugin/image-saver.js +0 -78
- package/dist/src/plugin/logger.d.ts +0 -35
- package/dist/src/plugin/logger.js +0 -67
- package/dist/src/plugin/logging-utils.d.ts +0 -22
- package/dist/src/plugin/logging-utils.js +0 -91
- package/dist/src/plugin/project.d.ts +0 -32
- package/dist/src/plugin/project.js +0 -229
- package/dist/src/plugin/quota.d.ts +0 -34
- package/dist/src/plugin/quota.js +0 -261
- package/dist/src/plugin/recovery/constants.d.ts +0 -21
- package/dist/src/plugin/recovery/constants.js +0 -42
- package/dist/src/plugin/recovery/index.d.ts +0 -11
- package/dist/src/plugin/recovery/index.js +0 -11
- package/dist/src/plugin/recovery/storage.d.ts +0 -23
- package/dist/src/plugin/recovery/storage.js +0 -340
- package/dist/src/plugin/recovery/types.d.ts +0 -115
- package/dist/src/plugin/recovery/types.js +0 -6
- package/dist/src/plugin/recovery.d.ts +0 -60
- package/dist/src/plugin/recovery.js +0 -360
- package/dist/src/plugin/refresh-queue.d.ts +0 -99
- package/dist/src/plugin/refresh-queue.js +0 -235
- package/dist/src/plugin/request-helpers.d.ts +0 -281
- package/dist/src/plugin/request-helpers.js +0 -2200
- package/dist/src/plugin/request.d.ts +0 -110
- package/dist/src/plugin/request.js +0 -1489
- package/dist/src/plugin/rotation.d.ts +0 -182
- package/dist/src/plugin/rotation.js +0 -364
- package/dist/src/plugin/search.d.ts +0 -31
- package/dist/src/plugin/search.js +0 -185
- package/dist/src/plugin/server.d.ts +0 -22
- package/dist/src/plugin/server.js +0 -306
- package/dist/src/plugin/storage.d.ts +0 -136
- package/dist/src/plugin/storage.js +0 -599
- package/dist/src/plugin/stores/signature-store.d.ts +0 -4
- package/dist/src/plugin/stores/signature-store.js +0 -24
- package/dist/src/plugin/thinking-recovery.d.ts +0 -89
- package/dist/src/plugin/thinking-recovery.js +0 -289
- package/dist/src/plugin/token.d.ts +0 -18
- package/dist/src/plugin/token.js +0 -127
- package/dist/src/plugin/transform/claude.d.ts +0 -79
- package/dist/src/plugin/transform/claude.js +0 -256
- package/dist/src/plugin/transform/cross-model-sanitizer.d.ts +0 -34
- package/dist/src/plugin/transform/cross-model-sanitizer.js +0 -224
- package/dist/src/plugin/transform/gemini.d.ts +0 -132
- package/dist/src/plugin/transform/gemini.js +0 -659
- package/dist/src/plugin/transform/index.d.ts +0 -14
- package/dist/src/plugin/transform/index.js +0 -9
- package/dist/src/plugin/transform/model-resolver.d.ts +0 -98
- package/dist/src/plugin/transform/model-resolver.js +0 -320
- package/dist/src/plugin/transform/types.d.ts +0 -110
- package/dist/src/plugin/transform/types.js +0 -1
- package/dist/src/plugin/types.d.ts +0 -95
- package/dist/src/plugin/types.js +0 -1
- package/dist/src/plugin/ui/ansi.d.ts +0 -31
- package/dist/src/plugin/ui/ansi.js +0 -45
- package/dist/src/plugin/ui/auth-menu.d.ts +0 -47
- package/dist/src/plugin/ui/auth-menu.js +0 -199
- package/dist/src/plugin/ui/confirm.d.ts +0 -1
- package/dist/src/plugin/ui/confirm.js +0 -14
- package/dist/src/plugin/ui/select.d.ts +0 -22
- package/dist/src/plugin/ui/select.js +0 -243
- package/dist/src/plugin/version.d.ts +0 -18
- package/dist/src/plugin/version.js +0 -79
package/dist/cli.js
ADDED
|
@@ -0,0 +1,2868 @@
|
|
|
1
|
+
import { createRequire as __coreAuthCreateRequire } from 'module'; const require = __coreAuthCreateRequire(import.meta.url);
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
|
|
9
|
+
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
|
|
10
|
+
}) : x)(function(x) {
|
|
11
|
+
if (typeof require !== "undefined") return require.apply(this, arguments);
|
|
12
|
+
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
13
|
+
});
|
|
14
|
+
var __commonJS = (cb, mod) => function __require2() {
|
|
15
|
+
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
16
|
+
};
|
|
17
|
+
var __export = (target, all) => {
|
|
18
|
+
for (var name in all)
|
|
19
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
20
|
+
};
|
|
21
|
+
var __copyProps = (to, from, except, desc) => {
|
|
22
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
23
|
+
for (let key of __getOwnPropNames(from))
|
|
24
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
25
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
26
|
+
}
|
|
27
|
+
return to;
|
|
28
|
+
};
|
|
29
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
30
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
31
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
32
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
33
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
34
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
35
|
+
mod
|
|
36
|
+
));
|
|
37
|
+
|
|
38
|
+
// node_modules/graceful-fs/polyfills.js
|
|
39
|
+
var require_polyfills = __commonJS({
|
|
40
|
+
"node_modules/graceful-fs/polyfills.js"(exports, module) {
|
|
41
|
+
var constants = __require("constants");
|
|
42
|
+
var origCwd = process.cwd;
|
|
43
|
+
var cwd = null;
|
|
44
|
+
var platform = process.env.GRACEFUL_FS_PLATFORM || process.platform;
|
|
45
|
+
process.cwd = function() {
|
|
46
|
+
if (!cwd)
|
|
47
|
+
cwd = origCwd.call(process);
|
|
48
|
+
return cwd;
|
|
49
|
+
};
|
|
50
|
+
try {
|
|
51
|
+
process.cwd();
|
|
52
|
+
} catch (er) {
|
|
53
|
+
}
|
|
54
|
+
if (typeof process.chdir === "function") {
|
|
55
|
+
chdir = process.chdir;
|
|
56
|
+
process.chdir = function(d) {
|
|
57
|
+
cwd = null;
|
|
58
|
+
chdir.call(process, d);
|
|
59
|
+
};
|
|
60
|
+
if (Object.setPrototypeOf) Object.setPrototypeOf(process.chdir, chdir);
|
|
61
|
+
}
|
|
62
|
+
var chdir;
|
|
63
|
+
module.exports = patch;
|
|
64
|
+
function patch(fs) {
|
|
65
|
+
if (constants.hasOwnProperty("O_SYMLINK") && process.version.match(/^v0\.6\.[0-2]|^v0\.5\./)) {
|
|
66
|
+
patchLchmod(fs);
|
|
67
|
+
}
|
|
68
|
+
if (!fs.lutimes) {
|
|
69
|
+
patchLutimes(fs);
|
|
70
|
+
}
|
|
71
|
+
fs.chown = chownFix(fs.chown);
|
|
72
|
+
fs.fchown = chownFix(fs.fchown);
|
|
73
|
+
fs.lchown = chownFix(fs.lchown);
|
|
74
|
+
fs.chmod = chmodFix(fs.chmod);
|
|
75
|
+
fs.fchmod = chmodFix(fs.fchmod);
|
|
76
|
+
fs.lchmod = chmodFix(fs.lchmod);
|
|
77
|
+
fs.chownSync = chownFixSync(fs.chownSync);
|
|
78
|
+
fs.fchownSync = chownFixSync(fs.fchownSync);
|
|
79
|
+
fs.lchownSync = chownFixSync(fs.lchownSync);
|
|
80
|
+
fs.chmodSync = chmodFixSync(fs.chmodSync);
|
|
81
|
+
fs.fchmodSync = chmodFixSync(fs.fchmodSync);
|
|
82
|
+
fs.lchmodSync = chmodFixSync(fs.lchmodSync);
|
|
83
|
+
fs.stat = statFix(fs.stat);
|
|
84
|
+
fs.fstat = statFix(fs.fstat);
|
|
85
|
+
fs.lstat = statFix(fs.lstat);
|
|
86
|
+
fs.statSync = statFixSync(fs.statSync);
|
|
87
|
+
fs.fstatSync = statFixSync(fs.fstatSync);
|
|
88
|
+
fs.lstatSync = statFixSync(fs.lstatSync);
|
|
89
|
+
if (fs.chmod && !fs.lchmod) {
|
|
90
|
+
fs.lchmod = function(path, mode, cb) {
|
|
91
|
+
if (cb) process.nextTick(cb);
|
|
92
|
+
};
|
|
93
|
+
fs.lchmodSync = function() {
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
if (fs.chown && !fs.lchown) {
|
|
97
|
+
fs.lchown = function(path, uid, gid, cb) {
|
|
98
|
+
if (cb) process.nextTick(cb);
|
|
99
|
+
};
|
|
100
|
+
fs.lchownSync = function() {
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
if (platform === "win32") {
|
|
104
|
+
fs.rename = typeof fs.rename !== "function" ? fs.rename : (function(fs$rename) {
|
|
105
|
+
function rename(from, to, cb) {
|
|
106
|
+
var start = Date.now();
|
|
107
|
+
var backoff = 0;
|
|
108
|
+
fs$rename(from, to, function CB(er) {
|
|
109
|
+
if (er && (er.code === "EACCES" || er.code === "EPERM" || er.code === "EBUSY") && Date.now() - start < 6e4) {
|
|
110
|
+
setTimeout(function() {
|
|
111
|
+
fs.stat(to, function(stater, st) {
|
|
112
|
+
if (stater && stater.code === "ENOENT")
|
|
113
|
+
fs$rename(from, to, CB);
|
|
114
|
+
else
|
|
115
|
+
cb(er);
|
|
116
|
+
});
|
|
117
|
+
}, backoff);
|
|
118
|
+
if (backoff < 100)
|
|
119
|
+
backoff += 10;
|
|
120
|
+
return;
|
|
121
|
+
}
|
|
122
|
+
if (cb) cb(er);
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
if (Object.setPrototypeOf) Object.setPrototypeOf(rename, fs$rename);
|
|
126
|
+
return rename;
|
|
127
|
+
})(fs.rename);
|
|
128
|
+
}
|
|
129
|
+
fs.read = typeof fs.read !== "function" ? fs.read : (function(fs$read) {
|
|
130
|
+
function read(fd, buffer, offset, length, position, callback_) {
|
|
131
|
+
var callback;
|
|
132
|
+
if (callback_ && typeof callback_ === "function") {
|
|
133
|
+
var eagCounter = 0;
|
|
134
|
+
callback = function(er, _, __) {
|
|
135
|
+
if (er && er.code === "EAGAIN" && eagCounter < 10) {
|
|
136
|
+
eagCounter++;
|
|
137
|
+
return fs$read.call(fs, fd, buffer, offset, length, position, callback);
|
|
138
|
+
}
|
|
139
|
+
callback_.apply(this, arguments);
|
|
140
|
+
};
|
|
141
|
+
}
|
|
142
|
+
return fs$read.call(fs, fd, buffer, offset, length, position, callback);
|
|
143
|
+
}
|
|
144
|
+
if (Object.setPrototypeOf) Object.setPrototypeOf(read, fs$read);
|
|
145
|
+
return read;
|
|
146
|
+
})(fs.read);
|
|
147
|
+
fs.readSync = typeof fs.readSync !== "function" ? fs.readSync : /* @__PURE__ */ (function(fs$readSync) {
|
|
148
|
+
return function(fd, buffer, offset, length, position) {
|
|
149
|
+
var eagCounter = 0;
|
|
150
|
+
while (true) {
|
|
151
|
+
try {
|
|
152
|
+
return fs$readSync.call(fs, fd, buffer, offset, length, position);
|
|
153
|
+
} catch (er) {
|
|
154
|
+
if (er.code === "EAGAIN" && eagCounter < 10) {
|
|
155
|
+
eagCounter++;
|
|
156
|
+
continue;
|
|
157
|
+
}
|
|
158
|
+
throw er;
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
};
|
|
162
|
+
})(fs.readSync);
|
|
163
|
+
function patchLchmod(fs2) {
|
|
164
|
+
fs2.lchmod = function(path, mode, callback) {
|
|
165
|
+
fs2.open(
|
|
166
|
+
path,
|
|
167
|
+
constants.O_WRONLY | constants.O_SYMLINK,
|
|
168
|
+
mode,
|
|
169
|
+
function(err, fd) {
|
|
170
|
+
if (err) {
|
|
171
|
+
if (callback) callback(err);
|
|
172
|
+
return;
|
|
173
|
+
}
|
|
174
|
+
fs2.fchmod(fd, mode, function(err2) {
|
|
175
|
+
fs2.close(fd, function(err22) {
|
|
176
|
+
if (callback) callback(err2 || err22);
|
|
177
|
+
});
|
|
178
|
+
});
|
|
179
|
+
}
|
|
180
|
+
);
|
|
181
|
+
};
|
|
182
|
+
fs2.lchmodSync = function(path, mode) {
|
|
183
|
+
var fd = fs2.openSync(path, constants.O_WRONLY | constants.O_SYMLINK, mode);
|
|
184
|
+
var threw = true;
|
|
185
|
+
var ret;
|
|
186
|
+
try {
|
|
187
|
+
ret = fs2.fchmodSync(fd, mode);
|
|
188
|
+
threw = false;
|
|
189
|
+
} finally {
|
|
190
|
+
if (threw) {
|
|
191
|
+
try {
|
|
192
|
+
fs2.closeSync(fd);
|
|
193
|
+
} catch (er) {
|
|
194
|
+
}
|
|
195
|
+
} else {
|
|
196
|
+
fs2.closeSync(fd);
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
return ret;
|
|
200
|
+
};
|
|
201
|
+
}
|
|
202
|
+
function patchLutimes(fs2) {
|
|
203
|
+
if (constants.hasOwnProperty("O_SYMLINK") && fs2.futimes) {
|
|
204
|
+
fs2.lutimes = function(path, at, mt, cb) {
|
|
205
|
+
fs2.open(path, constants.O_SYMLINK, function(er, fd) {
|
|
206
|
+
if (er) {
|
|
207
|
+
if (cb) cb(er);
|
|
208
|
+
return;
|
|
209
|
+
}
|
|
210
|
+
fs2.futimes(fd, at, mt, function(er2) {
|
|
211
|
+
fs2.close(fd, function(er22) {
|
|
212
|
+
if (cb) cb(er2 || er22);
|
|
213
|
+
});
|
|
214
|
+
});
|
|
215
|
+
});
|
|
216
|
+
};
|
|
217
|
+
fs2.lutimesSync = function(path, at, mt) {
|
|
218
|
+
var fd = fs2.openSync(path, constants.O_SYMLINK);
|
|
219
|
+
var ret;
|
|
220
|
+
var threw = true;
|
|
221
|
+
try {
|
|
222
|
+
ret = fs2.futimesSync(fd, at, mt);
|
|
223
|
+
threw = false;
|
|
224
|
+
} finally {
|
|
225
|
+
if (threw) {
|
|
226
|
+
try {
|
|
227
|
+
fs2.closeSync(fd);
|
|
228
|
+
} catch (er) {
|
|
229
|
+
}
|
|
230
|
+
} else {
|
|
231
|
+
fs2.closeSync(fd);
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
return ret;
|
|
235
|
+
};
|
|
236
|
+
} else if (fs2.futimes) {
|
|
237
|
+
fs2.lutimes = function(_a, _b, _c, cb) {
|
|
238
|
+
if (cb) process.nextTick(cb);
|
|
239
|
+
};
|
|
240
|
+
fs2.lutimesSync = function() {
|
|
241
|
+
};
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
function chmodFix(orig) {
|
|
245
|
+
if (!orig) return orig;
|
|
246
|
+
return function(target, mode, cb) {
|
|
247
|
+
return orig.call(fs, target, mode, function(er) {
|
|
248
|
+
if (chownErOk(er)) er = null;
|
|
249
|
+
if (cb) cb.apply(this, arguments);
|
|
250
|
+
});
|
|
251
|
+
};
|
|
252
|
+
}
|
|
253
|
+
function chmodFixSync(orig) {
|
|
254
|
+
if (!orig) return orig;
|
|
255
|
+
return function(target, mode) {
|
|
256
|
+
try {
|
|
257
|
+
return orig.call(fs, target, mode);
|
|
258
|
+
} catch (er) {
|
|
259
|
+
if (!chownErOk(er)) throw er;
|
|
260
|
+
}
|
|
261
|
+
};
|
|
262
|
+
}
|
|
263
|
+
function chownFix(orig) {
|
|
264
|
+
if (!orig) return orig;
|
|
265
|
+
return function(target, uid, gid, cb) {
|
|
266
|
+
return orig.call(fs, target, uid, gid, function(er) {
|
|
267
|
+
if (chownErOk(er)) er = null;
|
|
268
|
+
if (cb) cb.apply(this, arguments);
|
|
269
|
+
});
|
|
270
|
+
};
|
|
271
|
+
}
|
|
272
|
+
function chownFixSync(orig) {
|
|
273
|
+
if (!orig) return orig;
|
|
274
|
+
return function(target, uid, gid) {
|
|
275
|
+
try {
|
|
276
|
+
return orig.call(fs, target, uid, gid);
|
|
277
|
+
} catch (er) {
|
|
278
|
+
if (!chownErOk(er)) throw er;
|
|
279
|
+
}
|
|
280
|
+
};
|
|
281
|
+
}
|
|
282
|
+
function statFix(orig) {
|
|
283
|
+
if (!orig) return orig;
|
|
284
|
+
return function(target, options, cb) {
|
|
285
|
+
if (typeof options === "function") {
|
|
286
|
+
cb = options;
|
|
287
|
+
options = null;
|
|
288
|
+
}
|
|
289
|
+
function callback(er, stats) {
|
|
290
|
+
if (stats) {
|
|
291
|
+
if (stats.uid < 0) stats.uid += 4294967296;
|
|
292
|
+
if (stats.gid < 0) stats.gid += 4294967296;
|
|
293
|
+
}
|
|
294
|
+
if (cb) cb.apply(this, arguments);
|
|
295
|
+
}
|
|
296
|
+
return options ? orig.call(fs, target, options, callback) : orig.call(fs, target, callback);
|
|
297
|
+
};
|
|
298
|
+
}
|
|
299
|
+
function statFixSync(orig) {
|
|
300
|
+
if (!orig) return orig;
|
|
301
|
+
return function(target, options) {
|
|
302
|
+
var stats = options ? orig.call(fs, target, options) : orig.call(fs, target);
|
|
303
|
+
if (stats) {
|
|
304
|
+
if (stats.uid < 0) stats.uid += 4294967296;
|
|
305
|
+
if (stats.gid < 0) stats.gid += 4294967296;
|
|
306
|
+
}
|
|
307
|
+
return stats;
|
|
308
|
+
};
|
|
309
|
+
}
|
|
310
|
+
function chownErOk(er) {
|
|
311
|
+
if (!er)
|
|
312
|
+
return true;
|
|
313
|
+
if (er.code === "ENOSYS")
|
|
314
|
+
return true;
|
|
315
|
+
var nonroot = !process.getuid || process.getuid() !== 0;
|
|
316
|
+
if (nonroot) {
|
|
317
|
+
if (er.code === "EINVAL" || er.code === "EPERM")
|
|
318
|
+
return true;
|
|
319
|
+
}
|
|
320
|
+
return false;
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
});
|
|
325
|
+
|
|
326
|
+
// node_modules/graceful-fs/legacy-streams.js
|
|
327
|
+
var require_legacy_streams = __commonJS({
|
|
328
|
+
"node_modules/graceful-fs/legacy-streams.js"(exports, module) {
|
|
329
|
+
var Stream = __require("stream").Stream;
|
|
330
|
+
module.exports = legacy;
|
|
331
|
+
function legacy(fs) {
|
|
332
|
+
return {
|
|
333
|
+
ReadStream,
|
|
334
|
+
WriteStream
|
|
335
|
+
};
|
|
336
|
+
function ReadStream(path, options) {
|
|
337
|
+
if (!(this instanceof ReadStream)) return new ReadStream(path, options);
|
|
338
|
+
Stream.call(this);
|
|
339
|
+
var self = this;
|
|
340
|
+
this.path = path;
|
|
341
|
+
this.fd = null;
|
|
342
|
+
this.readable = true;
|
|
343
|
+
this.paused = false;
|
|
344
|
+
this.flags = "r";
|
|
345
|
+
this.mode = 438;
|
|
346
|
+
this.bufferSize = 64 * 1024;
|
|
347
|
+
options = options || {};
|
|
348
|
+
var keys = Object.keys(options);
|
|
349
|
+
for (var index = 0, length = keys.length; index < length; index++) {
|
|
350
|
+
var key = keys[index];
|
|
351
|
+
this[key] = options[key];
|
|
352
|
+
}
|
|
353
|
+
if (this.encoding) this.setEncoding(this.encoding);
|
|
354
|
+
if (this.start !== void 0) {
|
|
355
|
+
if ("number" !== typeof this.start) {
|
|
356
|
+
throw TypeError("start must be a Number");
|
|
357
|
+
}
|
|
358
|
+
if (this.end === void 0) {
|
|
359
|
+
this.end = Infinity;
|
|
360
|
+
} else if ("number" !== typeof this.end) {
|
|
361
|
+
throw TypeError("end must be a Number");
|
|
362
|
+
}
|
|
363
|
+
if (this.start > this.end) {
|
|
364
|
+
throw new Error("start must be <= end");
|
|
365
|
+
}
|
|
366
|
+
this.pos = this.start;
|
|
367
|
+
}
|
|
368
|
+
if (this.fd !== null) {
|
|
369
|
+
process.nextTick(function() {
|
|
370
|
+
self._read();
|
|
371
|
+
});
|
|
372
|
+
return;
|
|
373
|
+
}
|
|
374
|
+
fs.open(this.path, this.flags, this.mode, function(err, fd) {
|
|
375
|
+
if (err) {
|
|
376
|
+
self.emit("error", err);
|
|
377
|
+
self.readable = false;
|
|
378
|
+
return;
|
|
379
|
+
}
|
|
380
|
+
self.fd = fd;
|
|
381
|
+
self.emit("open", fd);
|
|
382
|
+
self._read();
|
|
383
|
+
});
|
|
384
|
+
}
|
|
385
|
+
function WriteStream(path, options) {
|
|
386
|
+
if (!(this instanceof WriteStream)) return new WriteStream(path, options);
|
|
387
|
+
Stream.call(this);
|
|
388
|
+
this.path = path;
|
|
389
|
+
this.fd = null;
|
|
390
|
+
this.writable = true;
|
|
391
|
+
this.flags = "w";
|
|
392
|
+
this.encoding = "binary";
|
|
393
|
+
this.mode = 438;
|
|
394
|
+
this.bytesWritten = 0;
|
|
395
|
+
options = options || {};
|
|
396
|
+
var keys = Object.keys(options);
|
|
397
|
+
for (var index = 0, length = keys.length; index < length; index++) {
|
|
398
|
+
var key = keys[index];
|
|
399
|
+
this[key] = options[key];
|
|
400
|
+
}
|
|
401
|
+
if (this.start !== void 0) {
|
|
402
|
+
if ("number" !== typeof this.start) {
|
|
403
|
+
throw TypeError("start must be a Number");
|
|
404
|
+
}
|
|
405
|
+
if (this.start < 0) {
|
|
406
|
+
throw new Error("start must be >= zero");
|
|
407
|
+
}
|
|
408
|
+
this.pos = this.start;
|
|
409
|
+
}
|
|
410
|
+
this.busy = false;
|
|
411
|
+
this._queue = [];
|
|
412
|
+
if (this.fd === null) {
|
|
413
|
+
this._open = fs.open;
|
|
414
|
+
this._queue.push([this._open, this.path, this.flags, this.mode, void 0]);
|
|
415
|
+
this.flush();
|
|
416
|
+
}
|
|
417
|
+
}
|
|
418
|
+
}
|
|
419
|
+
}
|
|
420
|
+
});
|
|
421
|
+
|
|
422
|
+
// node_modules/graceful-fs/clone.js
|
|
423
|
+
var require_clone = __commonJS({
|
|
424
|
+
"node_modules/graceful-fs/clone.js"(exports, module) {
|
|
425
|
+
"use strict";
|
|
426
|
+
module.exports = clone;
|
|
427
|
+
var getPrototypeOf = Object.getPrototypeOf || function(obj) {
|
|
428
|
+
return obj.__proto__;
|
|
429
|
+
};
|
|
430
|
+
function clone(obj) {
|
|
431
|
+
if (obj === null || typeof obj !== "object")
|
|
432
|
+
return obj;
|
|
433
|
+
if (obj instanceof Object)
|
|
434
|
+
var copy = { __proto__: getPrototypeOf(obj) };
|
|
435
|
+
else
|
|
436
|
+
var copy = /* @__PURE__ */ Object.create(null);
|
|
437
|
+
Object.getOwnPropertyNames(obj).forEach(function(key) {
|
|
438
|
+
Object.defineProperty(copy, key, Object.getOwnPropertyDescriptor(obj, key));
|
|
439
|
+
});
|
|
440
|
+
return copy;
|
|
441
|
+
}
|
|
442
|
+
}
|
|
443
|
+
});
|
|
444
|
+
|
|
445
|
+
// node_modules/graceful-fs/graceful-fs.js
|
|
446
|
+
var require_graceful_fs = __commonJS({
|
|
447
|
+
"node_modules/graceful-fs/graceful-fs.js"(exports, module) {
|
|
448
|
+
var fs = __require("fs");
|
|
449
|
+
var polyfills = require_polyfills();
|
|
450
|
+
var legacy = require_legacy_streams();
|
|
451
|
+
var clone = require_clone();
|
|
452
|
+
var util = __require("util");
|
|
453
|
+
var gracefulQueue;
|
|
454
|
+
var previousSymbol;
|
|
455
|
+
if (typeof Symbol === "function" && typeof Symbol.for === "function") {
|
|
456
|
+
gracefulQueue = Symbol.for("graceful-fs.queue");
|
|
457
|
+
previousSymbol = Symbol.for("graceful-fs.previous");
|
|
458
|
+
} else {
|
|
459
|
+
gracefulQueue = "___graceful-fs.queue";
|
|
460
|
+
previousSymbol = "___graceful-fs.previous";
|
|
461
|
+
}
|
|
462
|
+
function noop() {
|
|
463
|
+
}
|
|
464
|
+
function publishQueue(context, queue2) {
|
|
465
|
+
Object.defineProperty(context, gracefulQueue, {
|
|
466
|
+
get: function() {
|
|
467
|
+
return queue2;
|
|
468
|
+
}
|
|
469
|
+
});
|
|
470
|
+
}
|
|
471
|
+
var debug = noop;
|
|
472
|
+
if (util.debuglog)
|
|
473
|
+
debug = util.debuglog("gfs4");
|
|
474
|
+
else if (/\bgfs4\b/i.test(process.env.NODE_DEBUG || ""))
|
|
475
|
+
debug = function() {
|
|
476
|
+
var m = util.format.apply(util, arguments);
|
|
477
|
+
m = "GFS4: " + m.split(/\n/).join("\nGFS4: ");
|
|
478
|
+
console.error(m);
|
|
479
|
+
};
|
|
480
|
+
if (!fs[gracefulQueue]) {
|
|
481
|
+
queue = global[gracefulQueue] || [];
|
|
482
|
+
publishQueue(fs, queue);
|
|
483
|
+
fs.close = (function(fs$close) {
|
|
484
|
+
function close(fd, cb) {
|
|
485
|
+
return fs$close.call(fs, fd, function(err) {
|
|
486
|
+
if (!err) {
|
|
487
|
+
resetQueue();
|
|
488
|
+
}
|
|
489
|
+
if (typeof cb === "function")
|
|
490
|
+
cb.apply(this, arguments);
|
|
491
|
+
});
|
|
492
|
+
}
|
|
493
|
+
Object.defineProperty(close, previousSymbol, {
|
|
494
|
+
value: fs$close
|
|
495
|
+
});
|
|
496
|
+
return close;
|
|
497
|
+
})(fs.close);
|
|
498
|
+
fs.closeSync = (function(fs$closeSync) {
|
|
499
|
+
function closeSync2(fd) {
|
|
500
|
+
fs$closeSync.apply(fs, arguments);
|
|
501
|
+
resetQueue();
|
|
502
|
+
}
|
|
503
|
+
Object.defineProperty(closeSync2, previousSymbol, {
|
|
504
|
+
value: fs$closeSync
|
|
505
|
+
});
|
|
506
|
+
return closeSync2;
|
|
507
|
+
})(fs.closeSync);
|
|
508
|
+
if (/\bgfs4\b/i.test(process.env.NODE_DEBUG || "")) {
|
|
509
|
+
process.on("exit", function() {
|
|
510
|
+
debug(fs[gracefulQueue]);
|
|
511
|
+
__require("assert").equal(fs[gracefulQueue].length, 0);
|
|
512
|
+
});
|
|
513
|
+
}
|
|
514
|
+
}
|
|
515
|
+
var queue;
|
|
516
|
+
if (!global[gracefulQueue]) {
|
|
517
|
+
publishQueue(global, fs[gracefulQueue]);
|
|
518
|
+
}
|
|
519
|
+
module.exports = patch(clone(fs));
|
|
520
|
+
if (process.env.TEST_GRACEFUL_FS_GLOBAL_PATCH && !fs.__patched) {
|
|
521
|
+
module.exports = patch(fs);
|
|
522
|
+
fs.__patched = true;
|
|
523
|
+
}
|
|
524
|
+
function patch(fs2) {
|
|
525
|
+
polyfills(fs2);
|
|
526
|
+
fs2.gracefulify = patch;
|
|
527
|
+
fs2.createReadStream = createReadStream;
|
|
528
|
+
fs2.createWriteStream = createWriteStream2;
|
|
529
|
+
var fs$readFile = fs2.readFile;
|
|
530
|
+
fs2.readFile = readFile;
|
|
531
|
+
function readFile(path, options, cb) {
|
|
532
|
+
if (typeof options === "function")
|
|
533
|
+
cb = options, options = null;
|
|
534
|
+
return go$readFile(path, options, cb);
|
|
535
|
+
function go$readFile(path2, options2, cb2, startTime) {
|
|
536
|
+
return fs$readFile(path2, options2, function(err) {
|
|
537
|
+
if (err && (err.code === "EMFILE" || err.code === "ENFILE"))
|
|
538
|
+
enqueue([go$readFile, [path2, options2, cb2], err, startTime || Date.now(), Date.now()]);
|
|
539
|
+
else {
|
|
540
|
+
if (typeof cb2 === "function")
|
|
541
|
+
cb2.apply(this, arguments);
|
|
542
|
+
}
|
|
543
|
+
});
|
|
544
|
+
}
|
|
545
|
+
}
|
|
546
|
+
var fs$writeFile = fs2.writeFile;
|
|
547
|
+
fs2.writeFile = writeFile;
|
|
548
|
+
function writeFile(path, data, options, cb) {
|
|
549
|
+
if (typeof options === "function")
|
|
550
|
+
cb = options, options = null;
|
|
551
|
+
return go$writeFile(path, data, options, cb);
|
|
552
|
+
function go$writeFile(path2, data2, options2, cb2, startTime) {
|
|
553
|
+
return fs$writeFile(path2, data2, options2, function(err) {
|
|
554
|
+
if (err && (err.code === "EMFILE" || err.code === "ENFILE"))
|
|
555
|
+
enqueue([go$writeFile, [path2, data2, options2, cb2], err, startTime || Date.now(), Date.now()]);
|
|
556
|
+
else {
|
|
557
|
+
if (typeof cb2 === "function")
|
|
558
|
+
cb2.apply(this, arguments);
|
|
559
|
+
}
|
|
560
|
+
});
|
|
561
|
+
}
|
|
562
|
+
}
|
|
563
|
+
var fs$appendFile = fs2.appendFile;
|
|
564
|
+
if (fs$appendFile)
|
|
565
|
+
fs2.appendFile = appendFile;
|
|
566
|
+
function appendFile(path, data, options, cb) {
|
|
567
|
+
if (typeof options === "function")
|
|
568
|
+
cb = options, options = null;
|
|
569
|
+
return go$appendFile(path, data, options, cb);
|
|
570
|
+
function go$appendFile(path2, data2, options2, cb2, startTime) {
|
|
571
|
+
return fs$appendFile(path2, data2, options2, function(err) {
|
|
572
|
+
if (err && (err.code === "EMFILE" || err.code === "ENFILE"))
|
|
573
|
+
enqueue([go$appendFile, [path2, data2, options2, cb2], err, startTime || Date.now(), Date.now()]);
|
|
574
|
+
else {
|
|
575
|
+
if (typeof cb2 === "function")
|
|
576
|
+
cb2.apply(this, arguments);
|
|
577
|
+
}
|
|
578
|
+
});
|
|
579
|
+
}
|
|
580
|
+
}
|
|
581
|
+
var fs$copyFile = fs2.copyFile;
|
|
582
|
+
if (fs$copyFile)
|
|
583
|
+
fs2.copyFile = copyFile;
|
|
584
|
+
function copyFile(src, dest, flags, cb) {
|
|
585
|
+
if (typeof flags === "function") {
|
|
586
|
+
cb = flags;
|
|
587
|
+
flags = 0;
|
|
588
|
+
}
|
|
589
|
+
return go$copyFile(src, dest, flags, cb);
|
|
590
|
+
function go$copyFile(src2, dest2, flags2, cb2, startTime) {
|
|
591
|
+
return fs$copyFile(src2, dest2, flags2, function(err) {
|
|
592
|
+
if (err && (err.code === "EMFILE" || err.code === "ENFILE"))
|
|
593
|
+
enqueue([go$copyFile, [src2, dest2, flags2, cb2], err, startTime || Date.now(), Date.now()]);
|
|
594
|
+
else {
|
|
595
|
+
if (typeof cb2 === "function")
|
|
596
|
+
cb2.apply(this, arguments);
|
|
597
|
+
}
|
|
598
|
+
});
|
|
599
|
+
}
|
|
600
|
+
}
|
|
601
|
+
var fs$readdir = fs2.readdir;
|
|
602
|
+
fs2.readdir = readdir;
|
|
603
|
+
var noReaddirOptionVersions = /^v[0-5]\./;
|
|
604
|
+
function readdir(path, options, cb) {
|
|
605
|
+
if (typeof options === "function")
|
|
606
|
+
cb = options, options = null;
|
|
607
|
+
var go$readdir = noReaddirOptionVersions.test(process.version) ? function go$readdir2(path2, options2, cb2, startTime) {
|
|
608
|
+
return fs$readdir(path2, fs$readdirCallback(
|
|
609
|
+
path2,
|
|
610
|
+
options2,
|
|
611
|
+
cb2,
|
|
612
|
+
startTime
|
|
613
|
+
));
|
|
614
|
+
} : function go$readdir2(path2, options2, cb2, startTime) {
|
|
615
|
+
return fs$readdir(path2, options2, fs$readdirCallback(
|
|
616
|
+
path2,
|
|
617
|
+
options2,
|
|
618
|
+
cb2,
|
|
619
|
+
startTime
|
|
620
|
+
));
|
|
621
|
+
};
|
|
622
|
+
return go$readdir(path, options, cb);
|
|
623
|
+
function fs$readdirCallback(path2, options2, cb2, startTime) {
|
|
624
|
+
return function(err, files) {
|
|
625
|
+
if (err && (err.code === "EMFILE" || err.code === "ENFILE"))
|
|
626
|
+
enqueue([
|
|
627
|
+
go$readdir,
|
|
628
|
+
[path2, options2, cb2],
|
|
629
|
+
err,
|
|
630
|
+
startTime || Date.now(),
|
|
631
|
+
Date.now()
|
|
632
|
+
]);
|
|
633
|
+
else {
|
|
634
|
+
if (files && files.sort)
|
|
635
|
+
files.sort();
|
|
636
|
+
if (typeof cb2 === "function")
|
|
637
|
+
cb2.call(this, err, files);
|
|
638
|
+
}
|
|
639
|
+
};
|
|
640
|
+
}
|
|
641
|
+
}
|
|
642
|
+
if (process.version.substr(0, 4) === "v0.8") {
|
|
643
|
+
var legStreams = legacy(fs2);
|
|
644
|
+
ReadStream = legStreams.ReadStream;
|
|
645
|
+
WriteStream = legStreams.WriteStream;
|
|
646
|
+
}
|
|
647
|
+
var fs$ReadStream = fs2.ReadStream;
|
|
648
|
+
if (fs$ReadStream) {
|
|
649
|
+
ReadStream.prototype = Object.create(fs$ReadStream.prototype);
|
|
650
|
+
ReadStream.prototype.open = ReadStream$open;
|
|
651
|
+
}
|
|
652
|
+
var fs$WriteStream = fs2.WriteStream;
|
|
653
|
+
if (fs$WriteStream) {
|
|
654
|
+
WriteStream.prototype = Object.create(fs$WriteStream.prototype);
|
|
655
|
+
WriteStream.prototype.open = WriteStream$open;
|
|
656
|
+
}
|
|
657
|
+
Object.defineProperty(fs2, "ReadStream", {
|
|
658
|
+
get: function() {
|
|
659
|
+
return ReadStream;
|
|
660
|
+
},
|
|
661
|
+
set: function(val) {
|
|
662
|
+
ReadStream = val;
|
|
663
|
+
},
|
|
664
|
+
enumerable: true,
|
|
665
|
+
configurable: true
|
|
666
|
+
});
|
|
667
|
+
Object.defineProperty(fs2, "WriteStream", {
|
|
668
|
+
get: function() {
|
|
669
|
+
return WriteStream;
|
|
670
|
+
},
|
|
671
|
+
set: function(val) {
|
|
672
|
+
WriteStream = val;
|
|
673
|
+
},
|
|
674
|
+
enumerable: true,
|
|
675
|
+
configurable: true
|
|
676
|
+
});
|
|
677
|
+
var FileReadStream = ReadStream;
|
|
678
|
+
Object.defineProperty(fs2, "FileReadStream", {
|
|
679
|
+
get: function() {
|
|
680
|
+
return FileReadStream;
|
|
681
|
+
},
|
|
682
|
+
set: function(val) {
|
|
683
|
+
FileReadStream = val;
|
|
684
|
+
},
|
|
685
|
+
enumerable: true,
|
|
686
|
+
configurable: true
|
|
687
|
+
});
|
|
688
|
+
var FileWriteStream = WriteStream;
|
|
689
|
+
Object.defineProperty(fs2, "FileWriteStream", {
|
|
690
|
+
get: function() {
|
|
691
|
+
return FileWriteStream;
|
|
692
|
+
},
|
|
693
|
+
set: function(val) {
|
|
694
|
+
FileWriteStream = val;
|
|
695
|
+
},
|
|
696
|
+
enumerable: true,
|
|
697
|
+
configurable: true
|
|
698
|
+
});
|
|
699
|
+
function ReadStream(path, options) {
|
|
700
|
+
if (this instanceof ReadStream)
|
|
701
|
+
return fs$ReadStream.apply(this, arguments), this;
|
|
702
|
+
else
|
|
703
|
+
return ReadStream.apply(Object.create(ReadStream.prototype), arguments);
|
|
704
|
+
}
|
|
705
|
+
function ReadStream$open() {
|
|
706
|
+
var that = this;
|
|
707
|
+
open(that.path, that.flags, that.mode, function(err, fd) {
|
|
708
|
+
if (err) {
|
|
709
|
+
if (that.autoClose)
|
|
710
|
+
that.destroy();
|
|
711
|
+
that.emit("error", err);
|
|
712
|
+
} else {
|
|
713
|
+
that.fd = fd;
|
|
714
|
+
that.emit("open", fd);
|
|
715
|
+
that.read();
|
|
716
|
+
}
|
|
717
|
+
});
|
|
718
|
+
}
|
|
719
|
+
function WriteStream(path, options) {
|
|
720
|
+
if (this instanceof WriteStream)
|
|
721
|
+
return fs$WriteStream.apply(this, arguments), this;
|
|
722
|
+
else
|
|
723
|
+
return WriteStream.apply(Object.create(WriteStream.prototype), arguments);
|
|
724
|
+
}
|
|
725
|
+
function WriteStream$open() {
|
|
726
|
+
var that = this;
|
|
727
|
+
open(that.path, that.flags, that.mode, function(err, fd) {
|
|
728
|
+
if (err) {
|
|
729
|
+
that.destroy();
|
|
730
|
+
that.emit("error", err);
|
|
731
|
+
} else {
|
|
732
|
+
that.fd = fd;
|
|
733
|
+
that.emit("open", fd);
|
|
734
|
+
}
|
|
735
|
+
});
|
|
736
|
+
}
|
|
737
|
+
function createReadStream(path, options) {
|
|
738
|
+
return new fs2.ReadStream(path, options);
|
|
739
|
+
}
|
|
740
|
+
function createWriteStream2(path, options) {
|
|
741
|
+
return new fs2.WriteStream(path, options);
|
|
742
|
+
}
|
|
743
|
+
var fs$open = fs2.open;
|
|
744
|
+
fs2.open = open;
|
|
745
|
+
function open(path, flags, mode, cb) {
|
|
746
|
+
if (typeof mode === "function")
|
|
747
|
+
cb = mode, mode = null;
|
|
748
|
+
return go$open(path, flags, mode, cb);
|
|
749
|
+
function go$open(path2, flags2, mode2, cb2, startTime) {
|
|
750
|
+
return fs$open(path2, flags2, mode2, function(err, fd) {
|
|
751
|
+
if (err && (err.code === "EMFILE" || err.code === "ENFILE"))
|
|
752
|
+
enqueue([go$open, [path2, flags2, mode2, cb2], err, startTime || Date.now(), Date.now()]);
|
|
753
|
+
else {
|
|
754
|
+
if (typeof cb2 === "function")
|
|
755
|
+
cb2.apply(this, arguments);
|
|
756
|
+
}
|
|
757
|
+
});
|
|
758
|
+
}
|
|
759
|
+
}
|
|
760
|
+
return fs2;
|
|
761
|
+
}
|
|
762
|
+
function enqueue(elem) {
|
|
763
|
+
debug("ENQUEUE", elem[0].name, elem[1]);
|
|
764
|
+
fs[gracefulQueue].push(elem);
|
|
765
|
+
retry();
|
|
766
|
+
}
|
|
767
|
+
var retryTimer;
|
|
768
|
+
function resetQueue() {
|
|
769
|
+
var now = Date.now();
|
|
770
|
+
for (var i = 0; i < fs[gracefulQueue].length; ++i) {
|
|
771
|
+
if (fs[gracefulQueue][i].length > 2) {
|
|
772
|
+
fs[gracefulQueue][i][3] = now;
|
|
773
|
+
fs[gracefulQueue][i][4] = now;
|
|
774
|
+
}
|
|
775
|
+
}
|
|
776
|
+
retry();
|
|
777
|
+
}
|
|
778
|
+
function retry() {
|
|
779
|
+
clearTimeout(retryTimer);
|
|
780
|
+
retryTimer = void 0;
|
|
781
|
+
if (fs[gracefulQueue].length === 0)
|
|
782
|
+
return;
|
|
783
|
+
var elem = fs[gracefulQueue].shift();
|
|
784
|
+
var fn = elem[0];
|
|
785
|
+
var args = elem[1];
|
|
786
|
+
var err = elem[2];
|
|
787
|
+
var startTime = elem[3];
|
|
788
|
+
var lastTime = elem[4];
|
|
789
|
+
if (startTime === void 0) {
|
|
790
|
+
debug("RETRY", fn.name, args);
|
|
791
|
+
fn.apply(null, args);
|
|
792
|
+
} else if (Date.now() - startTime >= 6e4) {
|
|
793
|
+
debug("TIMEOUT", fn.name, args);
|
|
794
|
+
var cb = args.pop();
|
|
795
|
+
if (typeof cb === "function")
|
|
796
|
+
cb.call(null, err);
|
|
797
|
+
} else {
|
|
798
|
+
var sinceAttempt = Date.now() - lastTime;
|
|
799
|
+
var sinceStart = Math.max(lastTime - startTime, 1);
|
|
800
|
+
var desiredDelay = Math.min(sinceStart * 1.2, 100);
|
|
801
|
+
if (sinceAttempt >= desiredDelay) {
|
|
802
|
+
debug("RETRY", fn.name, args);
|
|
803
|
+
fn.apply(null, args.concat([startTime]));
|
|
804
|
+
} else {
|
|
805
|
+
fs[gracefulQueue].push(elem);
|
|
806
|
+
}
|
|
807
|
+
}
|
|
808
|
+
if (retryTimer === void 0) {
|
|
809
|
+
retryTimer = setTimeout(retry, 0);
|
|
810
|
+
}
|
|
811
|
+
}
|
|
812
|
+
}
|
|
813
|
+
});
|
|
814
|
+
|
|
815
|
+
// node_modules/retry/lib/retry_operation.js
|
|
816
|
+
var require_retry_operation = __commonJS({
|
|
817
|
+
"node_modules/retry/lib/retry_operation.js"(exports, module) {
|
|
818
|
+
function RetryOperation(timeouts, options) {
|
|
819
|
+
if (typeof options === "boolean") {
|
|
820
|
+
options = { forever: options };
|
|
821
|
+
}
|
|
822
|
+
this._originalTimeouts = JSON.parse(JSON.stringify(timeouts));
|
|
823
|
+
this._timeouts = timeouts;
|
|
824
|
+
this._options = options || {};
|
|
825
|
+
this._maxRetryTime = options && options.maxRetryTime || Infinity;
|
|
826
|
+
this._fn = null;
|
|
827
|
+
this._errors = [];
|
|
828
|
+
this._attempts = 1;
|
|
829
|
+
this._operationTimeout = null;
|
|
830
|
+
this._operationTimeoutCb = null;
|
|
831
|
+
this._timeout = null;
|
|
832
|
+
this._operationStart = null;
|
|
833
|
+
if (this._options.forever) {
|
|
834
|
+
this._cachedTimeouts = this._timeouts.slice(0);
|
|
835
|
+
}
|
|
836
|
+
}
|
|
837
|
+
module.exports = RetryOperation;
|
|
838
|
+
RetryOperation.prototype.reset = function() {
|
|
839
|
+
this._attempts = 1;
|
|
840
|
+
this._timeouts = this._originalTimeouts;
|
|
841
|
+
};
|
|
842
|
+
RetryOperation.prototype.stop = function() {
|
|
843
|
+
if (this._timeout) {
|
|
844
|
+
clearTimeout(this._timeout);
|
|
845
|
+
}
|
|
846
|
+
this._timeouts = [];
|
|
847
|
+
this._cachedTimeouts = null;
|
|
848
|
+
};
|
|
849
|
+
RetryOperation.prototype.retry = function(err) {
|
|
850
|
+
if (this._timeout) {
|
|
851
|
+
clearTimeout(this._timeout);
|
|
852
|
+
}
|
|
853
|
+
if (!err) {
|
|
854
|
+
return false;
|
|
855
|
+
}
|
|
856
|
+
var currentTime = (/* @__PURE__ */ new Date()).getTime();
|
|
857
|
+
if (err && currentTime - this._operationStart >= this._maxRetryTime) {
|
|
858
|
+
this._errors.unshift(new Error("RetryOperation timeout occurred"));
|
|
859
|
+
return false;
|
|
860
|
+
}
|
|
861
|
+
this._errors.push(err);
|
|
862
|
+
var timeout = this._timeouts.shift();
|
|
863
|
+
if (timeout === void 0) {
|
|
864
|
+
if (this._cachedTimeouts) {
|
|
865
|
+
this._errors.splice(this._errors.length - 1, this._errors.length);
|
|
866
|
+
this._timeouts = this._cachedTimeouts.slice(0);
|
|
867
|
+
timeout = this._timeouts.shift();
|
|
868
|
+
} else {
|
|
869
|
+
return false;
|
|
870
|
+
}
|
|
871
|
+
}
|
|
872
|
+
var self = this;
|
|
873
|
+
var timer = setTimeout(function() {
|
|
874
|
+
self._attempts++;
|
|
875
|
+
if (self._operationTimeoutCb) {
|
|
876
|
+
self._timeout = setTimeout(function() {
|
|
877
|
+
self._operationTimeoutCb(self._attempts);
|
|
878
|
+
}, self._operationTimeout);
|
|
879
|
+
if (self._options.unref) {
|
|
880
|
+
self._timeout.unref();
|
|
881
|
+
}
|
|
882
|
+
}
|
|
883
|
+
self._fn(self._attempts);
|
|
884
|
+
}, timeout);
|
|
885
|
+
if (this._options.unref) {
|
|
886
|
+
timer.unref();
|
|
887
|
+
}
|
|
888
|
+
return true;
|
|
889
|
+
};
|
|
890
|
+
RetryOperation.prototype.attempt = function(fn, timeoutOps) {
|
|
891
|
+
this._fn = fn;
|
|
892
|
+
if (timeoutOps) {
|
|
893
|
+
if (timeoutOps.timeout) {
|
|
894
|
+
this._operationTimeout = timeoutOps.timeout;
|
|
895
|
+
}
|
|
896
|
+
if (timeoutOps.cb) {
|
|
897
|
+
this._operationTimeoutCb = timeoutOps.cb;
|
|
898
|
+
}
|
|
899
|
+
}
|
|
900
|
+
var self = this;
|
|
901
|
+
if (this._operationTimeoutCb) {
|
|
902
|
+
this._timeout = setTimeout(function() {
|
|
903
|
+
self._operationTimeoutCb();
|
|
904
|
+
}, self._operationTimeout);
|
|
905
|
+
}
|
|
906
|
+
this._operationStart = (/* @__PURE__ */ new Date()).getTime();
|
|
907
|
+
this._fn(this._attempts);
|
|
908
|
+
};
|
|
909
|
+
RetryOperation.prototype.try = function(fn) {
|
|
910
|
+
console.log("Using RetryOperation.try() is deprecated");
|
|
911
|
+
this.attempt(fn);
|
|
912
|
+
};
|
|
913
|
+
RetryOperation.prototype.start = function(fn) {
|
|
914
|
+
console.log("Using RetryOperation.start() is deprecated");
|
|
915
|
+
this.attempt(fn);
|
|
916
|
+
};
|
|
917
|
+
RetryOperation.prototype.start = RetryOperation.prototype.try;
|
|
918
|
+
RetryOperation.prototype.errors = function() {
|
|
919
|
+
return this._errors;
|
|
920
|
+
};
|
|
921
|
+
RetryOperation.prototype.attempts = function() {
|
|
922
|
+
return this._attempts;
|
|
923
|
+
};
|
|
924
|
+
RetryOperation.prototype.mainError = function() {
|
|
925
|
+
if (this._errors.length === 0) {
|
|
926
|
+
return null;
|
|
927
|
+
}
|
|
928
|
+
var counts = {};
|
|
929
|
+
var mainError = null;
|
|
930
|
+
var mainErrorCount = 0;
|
|
931
|
+
for (var i = 0; i < this._errors.length; i++) {
|
|
932
|
+
var error = this._errors[i];
|
|
933
|
+
var message = error.message;
|
|
934
|
+
var count = (counts[message] || 0) + 1;
|
|
935
|
+
counts[message] = count;
|
|
936
|
+
if (count >= mainErrorCount) {
|
|
937
|
+
mainError = error;
|
|
938
|
+
mainErrorCount = count;
|
|
939
|
+
}
|
|
940
|
+
}
|
|
941
|
+
return mainError;
|
|
942
|
+
};
|
|
943
|
+
}
|
|
944
|
+
});
|
|
945
|
+
|
|
946
|
+
// node_modules/retry/lib/retry.js
|
|
947
|
+
var require_retry = __commonJS({
|
|
948
|
+
"node_modules/retry/lib/retry.js"(exports) {
|
|
949
|
+
var RetryOperation = require_retry_operation();
|
|
950
|
+
exports.operation = function(options) {
|
|
951
|
+
var timeouts = exports.timeouts(options);
|
|
952
|
+
return new RetryOperation(timeouts, {
|
|
953
|
+
forever: options && options.forever,
|
|
954
|
+
unref: options && options.unref,
|
|
955
|
+
maxRetryTime: options && options.maxRetryTime
|
|
956
|
+
});
|
|
957
|
+
};
|
|
958
|
+
exports.timeouts = function(options) {
|
|
959
|
+
if (options instanceof Array) {
|
|
960
|
+
return [].concat(options);
|
|
961
|
+
}
|
|
962
|
+
var opts = {
|
|
963
|
+
retries: 10,
|
|
964
|
+
factor: 2,
|
|
965
|
+
minTimeout: 1 * 1e3,
|
|
966
|
+
maxTimeout: Infinity,
|
|
967
|
+
randomize: false
|
|
968
|
+
};
|
|
969
|
+
for (var key in options) {
|
|
970
|
+
opts[key] = options[key];
|
|
971
|
+
}
|
|
972
|
+
if (opts.minTimeout > opts.maxTimeout) {
|
|
973
|
+
throw new Error("minTimeout is greater than maxTimeout");
|
|
974
|
+
}
|
|
975
|
+
var timeouts = [];
|
|
976
|
+
for (var i = 0; i < opts.retries; i++) {
|
|
977
|
+
timeouts.push(this.createTimeout(i, opts));
|
|
978
|
+
}
|
|
979
|
+
if (options && options.forever && !timeouts.length) {
|
|
980
|
+
timeouts.push(this.createTimeout(i, opts));
|
|
981
|
+
}
|
|
982
|
+
timeouts.sort(function(a, b) {
|
|
983
|
+
return a - b;
|
|
984
|
+
});
|
|
985
|
+
return timeouts;
|
|
986
|
+
};
|
|
987
|
+
exports.createTimeout = function(attempt, opts) {
|
|
988
|
+
var random = opts.randomize ? Math.random() + 1 : 1;
|
|
989
|
+
var timeout = Math.round(random * opts.minTimeout * Math.pow(opts.factor, attempt));
|
|
990
|
+
timeout = Math.min(timeout, opts.maxTimeout);
|
|
991
|
+
return timeout;
|
|
992
|
+
};
|
|
993
|
+
exports.wrap = function(obj, options, methods) {
|
|
994
|
+
if (options instanceof Array) {
|
|
995
|
+
methods = options;
|
|
996
|
+
options = null;
|
|
997
|
+
}
|
|
998
|
+
if (!methods) {
|
|
999
|
+
methods = [];
|
|
1000
|
+
for (var key in obj) {
|
|
1001
|
+
if (typeof obj[key] === "function") {
|
|
1002
|
+
methods.push(key);
|
|
1003
|
+
}
|
|
1004
|
+
}
|
|
1005
|
+
}
|
|
1006
|
+
for (var i = 0; i < methods.length; i++) {
|
|
1007
|
+
var method = methods[i];
|
|
1008
|
+
var original = obj[method];
|
|
1009
|
+
obj[method] = function retryWrapper(original2) {
|
|
1010
|
+
var op = exports.operation(options);
|
|
1011
|
+
var args = Array.prototype.slice.call(arguments, 1);
|
|
1012
|
+
var callback = args.pop();
|
|
1013
|
+
args.push(function(err) {
|
|
1014
|
+
if (op.retry(err)) {
|
|
1015
|
+
return;
|
|
1016
|
+
}
|
|
1017
|
+
if (err) {
|
|
1018
|
+
arguments[0] = op.mainError();
|
|
1019
|
+
}
|
|
1020
|
+
callback.apply(this, arguments);
|
|
1021
|
+
});
|
|
1022
|
+
op.attempt(function() {
|
|
1023
|
+
original2.apply(obj, args);
|
|
1024
|
+
});
|
|
1025
|
+
}.bind(obj, original);
|
|
1026
|
+
obj[method].options = options;
|
|
1027
|
+
}
|
|
1028
|
+
};
|
|
1029
|
+
}
|
|
1030
|
+
});
|
|
1031
|
+
|
|
1032
|
+
// node_modules/retry/index.js
|
|
1033
|
+
var require_retry2 = __commonJS({
|
|
1034
|
+
"node_modules/retry/index.js"(exports, module) {
|
|
1035
|
+
module.exports = require_retry();
|
|
1036
|
+
}
|
|
1037
|
+
});
|
|
1038
|
+
|
|
1039
|
+
// node_modules/signal-exit/signals.js
|
|
1040
|
+
var require_signals = __commonJS({
|
|
1041
|
+
"node_modules/signal-exit/signals.js"(exports, module) {
|
|
1042
|
+
module.exports = [
|
|
1043
|
+
"SIGABRT",
|
|
1044
|
+
"SIGALRM",
|
|
1045
|
+
"SIGHUP",
|
|
1046
|
+
"SIGINT",
|
|
1047
|
+
"SIGTERM"
|
|
1048
|
+
];
|
|
1049
|
+
if (process.platform !== "win32") {
|
|
1050
|
+
module.exports.push(
|
|
1051
|
+
"SIGVTALRM",
|
|
1052
|
+
"SIGXCPU",
|
|
1053
|
+
"SIGXFSZ",
|
|
1054
|
+
"SIGUSR2",
|
|
1055
|
+
"SIGTRAP",
|
|
1056
|
+
"SIGSYS",
|
|
1057
|
+
"SIGQUIT",
|
|
1058
|
+
"SIGIOT"
|
|
1059
|
+
// should detect profiler and enable/disable accordingly.
|
|
1060
|
+
// see #21
|
|
1061
|
+
// 'SIGPROF'
|
|
1062
|
+
);
|
|
1063
|
+
}
|
|
1064
|
+
if (process.platform === "linux") {
|
|
1065
|
+
module.exports.push(
|
|
1066
|
+
"SIGIO",
|
|
1067
|
+
"SIGPOLL",
|
|
1068
|
+
"SIGPWR",
|
|
1069
|
+
"SIGSTKFLT",
|
|
1070
|
+
"SIGUNUSED"
|
|
1071
|
+
);
|
|
1072
|
+
}
|
|
1073
|
+
}
|
|
1074
|
+
});
|
|
1075
|
+
|
|
1076
|
+
// node_modules/signal-exit/index.js
|
|
1077
|
+
var require_signal_exit = __commonJS({
|
|
1078
|
+
"node_modules/signal-exit/index.js"(exports, module) {
|
|
1079
|
+
var process2 = global.process;
|
|
1080
|
+
var processOk = function(process3) {
|
|
1081
|
+
return process3 && typeof process3 === "object" && typeof process3.removeListener === "function" && typeof process3.emit === "function" && typeof process3.reallyExit === "function" && typeof process3.listeners === "function" && typeof process3.kill === "function" && typeof process3.pid === "number" && typeof process3.on === "function";
|
|
1082
|
+
};
|
|
1083
|
+
if (!processOk(process2)) {
|
|
1084
|
+
module.exports = function() {
|
|
1085
|
+
return function() {
|
|
1086
|
+
};
|
|
1087
|
+
};
|
|
1088
|
+
} else {
|
|
1089
|
+
assert = __require("assert");
|
|
1090
|
+
signals = require_signals();
|
|
1091
|
+
isWin = /^win/i.test(process2.platform);
|
|
1092
|
+
EE = __require("events");
|
|
1093
|
+
if (typeof EE !== "function") {
|
|
1094
|
+
EE = EE.EventEmitter;
|
|
1095
|
+
}
|
|
1096
|
+
if (process2.__signal_exit_emitter__) {
|
|
1097
|
+
emitter = process2.__signal_exit_emitter__;
|
|
1098
|
+
} else {
|
|
1099
|
+
emitter = process2.__signal_exit_emitter__ = new EE();
|
|
1100
|
+
emitter.count = 0;
|
|
1101
|
+
emitter.emitted = {};
|
|
1102
|
+
}
|
|
1103
|
+
if (!emitter.infinite) {
|
|
1104
|
+
emitter.setMaxListeners(Infinity);
|
|
1105
|
+
emitter.infinite = true;
|
|
1106
|
+
}
|
|
1107
|
+
module.exports = function(cb, opts) {
|
|
1108
|
+
if (!processOk(global.process)) {
|
|
1109
|
+
return function() {
|
|
1110
|
+
};
|
|
1111
|
+
}
|
|
1112
|
+
assert.equal(typeof cb, "function", "a callback must be provided for exit handler");
|
|
1113
|
+
if (loaded === false) {
|
|
1114
|
+
load();
|
|
1115
|
+
}
|
|
1116
|
+
var ev = "exit";
|
|
1117
|
+
if (opts && opts.alwaysLast) {
|
|
1118
|
+
ev = "afterexit";
|
|
1119
|
+
}
|
|
1120
|
+
var remove = function() {
|
|
1121
|
+
emitter.removeListener(ev, cb);
|
|
1122
|
+
if (emitter.listeners("exit").length === 0 && emitter.listeners("afterexit").length === 0) {
|
|
1123
|
+
unload();
|
|
1124
|
+
}
|
|
1125
|
+
};
|
|
1126
|
+
emitter.on(ev, cb);
|
|
1127
|
+
return remove;
|
|
1128
|
+
};
|
|
1129
|
+
unload = function unload2() {
|
|
1130
|
+
if (!loaded || !processOk(global.process)) {
|
|
1131
|
+
return;
|
|
1132
|
+
}
|
|
1133
|
+
loaded = false;
|
|
1134
|
+
signals.forEach(function(sig) {
|
|
1135
|
+
try {
|
|
1136
|
+
process2.removeListener(sig, sigListeners[sig]);
|
|
1137
|
+
} catch (er) {
|
|
1138
|
+
}
|
|
1139
|
+
});
|
|
1140
|
+
process2.emit = originalProcessEmit;
|
|
1141
|
+
process2.reallyExit = originalProcessReallyExit;
|
|
1142
|
+
emitter.count -= 1;
|
|
1143
|
+
};
|
|
1144
|
+
module.exports.unload = unload;
|
|
1145
|
+
emit = function emit2(event, code, signal) {
|
|
1146
|
+
if (emitter.emitted[event]) {
|
|
1147
|
+
return;
|
|
1148
|
+
}
|
|
1149
|
+
emitter.emitted[event] = true;
|
|
1150
|
+
emitter.emit(event, code, signal);
|
|
1151
|
+
};
|
|
1152
|
+
sigListeners = {};
|
|
1153
|
+
signals.forEach(function(sig) {
|
|
1154
|
+
sigListeners[sig] = function listener() {
|
|
1155
|
+
if (!processOk(global.process)) {
|
|
1156
|
+
return;
|
|
1157
|
+
}
|
|
1158
|
+
var listeners = process2.listeners(sig);
|
|
1159
|
+
if (listeners.length === emitter.count) {
|
|
1160
|
+
unload();
|
|
1161
|
+
emit("exit", null, sig);
|
|
1162
|
+
emit("afterexit", null, sig);
|
|
1163
|
+
if (isWin && sig === "SIGHUP") {
|
|
1164
|
+
sig = "SIGINT";
|
|
1165
|
+
}
|
|
1166
|
+
process2.kill(process2.pid, sig);
|
|
1167
|
+
}
|
|
1168
|
+
};
|
|
1169
|
+
});
|
|
1170
|
+
module.exports.signals = function() {
|
|
1171
|
+
return signals;
|
|
1172
|
+
};
|
|
1173
|
+
loaded = false;
|
|
1174
|
+
load = function load2() {
|
|
1175
|
+
if (loaded || !processOk(global.process)) {
|
|
1176
|
+
return;
|
|
1177
|
+
}
|
|
1178
|
+
loaded = true;
|
|
1179
|
+
emitter.count += 1;
|
|
1180
|
+
signals = signals.filter(function(sig) {
|
|
1181
|
+
try {
|
|
1182
|
+
process2.on(sig, sigListeners[sig]);
|
|
1183
|
+
return true;
|
|
1184
|
+
} catch (er) {
|
|
1185
|
+
return false;
|
|
1186
|
+
}
|
|
1187
|
+
});
|
|
1188
|
+
process2.emit = processEmit;
|
|
1189
|
+
process2.reallyExit = processReallyExit;
|
|
1190
|
+
};
|
|
1191
|
+
module.exports.load = load;
|
|
1192
|
+
originalProcessReallyExit = process2.reallyExit;
|
|
1193
|
+
processReallyExit = function processReallyExit2(code) {
|
|
1194
|
+
if (!processOk(global.process)) {
|
|
1195
|
+
return;
|
|
1196
|
+
}
|
|
1197
|
+
process2.exitCode = code || /* istanbul ignore next */
|
|
1198
|
+
0;
|
|
1199
|
+
emit("exit", process2.exitCode, null);
|
|
1200
|
+
emit("afterexit", process2.exitCode, null);
|
|
1201
|
+
originalProcessReallyExit.call(process2, process2.exitCode);
|
|
1202
|
+
};
|
|
1203
|
+
originalProcessEmit = process2.emit;
|
|
1204
|
+
processEmit = function processEmit2(ev, arg) {
|
|
1205
|
+
if (ev === "exit" && processOk(global.process)) {
|
|
1206
|
+
if (arg !== void 0) {
|
|
1207
|
+
process2.exitCode = arg;
|
|
1208
|
+
}
|
|
1209
|
+
var ret = originalProcessEmit.apply(this, arguments);
|
|
1210
|
+
emit("exit", process2.exitCode, null);
|
|
1211
|
+
emit("afterexit", process2.exitCode, null);
|
|
1212
|
+
return ret;
|
|
1213
|
+
} else {
|
|
1214
|
+
return originalProcessEmit.apply(this, arguments);
|
|
1215
|
+
}
|
|
1216
|
+
};
|
|
1217
|
+
}
|
|
1218
|
+
var assert;
|
|
1219
|
+
var signals;
|
|
1220
|
+
var isWin;
|
|
1221
|
+
var EE;
|
|
1222
|
+
var emitter;
|
|
1223
|
+
var unload;
|
|
1224
|
+
var emit;
|
|
1225
|
+
var sigListeners;
|
|
1226
|
+
var loaded;
|
|
1227
|
+
var load;
|
|
1228
|
+
var originalProcessReallyExit;
|
|
1229
|
+
var processReallyExit;
|
|
1230
|
+
var originalProcessEmit;
|
|
1231
|
+
var processEmit;
|
|
1232
|
+
}
|
|
1233
|
+
});
|
|
1234
|
+
|
|
1235
|
+
// node_modules/proper-lockfile/lib/mtime-precision.js
|
|
1236
|
+
var require_mtime_precision = __commonJS({
|
|
1237
|
+
"node_modules/proper-lockfile/lib/mtime-precision.js"(exports, module) {
|
|
1238
|
+
"use strict";
|
|
1239
|
+
var cacheSymbol = Symbol();
|
|
1240
|
+
function probe(file, fs, callback) {
|
|
1241
|
+
const cachedPrecision = fs[cacheSymbol];
|
|
1242
|
+
if (cachedPrecision) {
|
|
1243
|
+
return fs.stat(file, (err, stat) => {
|
|
1244
|
+
if (err) {
|
|
1245
|
+
return callback(err);
|
|
1246
|
+
}
|
|
1247
|
+
callback(null, stat.mtime, cachedPrecision);
|
|
1248
|
+
});
|
|
1249
|
+
}
|
|
1250
|
+
const mtime = new Date(Math.ceil(Date.now() / 1e3) * 1e3 + 5);
|
|
1251
|
+
fs.utimes(file, mtime, mtime, (err) => {
|
|
1252
|
+
if (err) {
|
|
1253
|
+
return callback(err);
|
|
1254
|
+
}
|
|
1255
|
+
fs.stat(file, (err2, stat) => {
|
|
1256
|
+
if (err2) {
|
|
1257
|
+
return callback(err2);
|
|
1258
|
+
}
|
|
1259
|
+
const precision = stat.mtime.getTime() % 1e3 === 0 ? "s" : "ms";
|
|
1260
|
+
Object.defineProperty(fs, cacheSymbol, { value: precision });
|
|
1261
|
+
callback(null, stat.mtime, precision);
|
|
1262
|
+
});
|
|
1263
|
+
});
|
|
1264
|
+
}
|
|
1265
|
+
function getMtime(precision) {
|
|
1266
|
+
let now = Date.now();
|
|
1267
|
+
if (precision === "s") {
|
|
1268
|
+
now = Math.ceil(now / 1e3) * 1e3;
|
|
1269
|
+
}
|
|
1270
|
+
return new Date(now);
|
|
1271
|
+
}
|
|
1272
|
+
module.exports.probe = probe;
|
|
1273
|
+
module.exports.getMtime = getMtime;
|
|
1274
|
+
}
|
|
1275
|
+
});
|
|
1276
|
+
|
|
1277
|
+
// node_modules/proper-lockfile/lib/lockfile.js
|
|
1278
|
+
var require_lockfile = __commonJS({
|
|
1279
|
+
"node_modules/proper-lockfile/lib/lockfile.js"(exports, module) {
|
|
1280
|
+
"use strict";
|
|
1281
|
+
var path = __require("path");
|
|
1282
|
+
var fs = require_graceful_fs();
|
|
1283
|
+
var retry = require_retry2();
|
|
1284
|
+
var onExit = require_signal_exit();
|
|
1285
|
+
var mtimePrecision = require_mtime_precision();
|
|
1286
|
+
var locks = {};
|
|
1287
|
+
function getLockFile(file, options) {
|
|
1288
|
+
return options.lockfilePath || `${file}.lock`;
|
|
1289
|
+
}
|
|
1290
|
+
function resolveCanonicalPath(file, options, callback) {
|
|
1291
|
+
if (!options.realpath) {
|
|
1292
|
+
return callback(null, path.resolve(file));
|
|
1293
|
+
}
|
|
1294
|
+
options.fs.realpath(file, callback);
|
|
1295
|
+
}
|
|
1296
|
+
function acquireLock(file, options, callback) {
|
|
1297
|
+
const lockfilePath = getLockFile(file, options);
|
|
1298
|
+
options.fs.mkdir(lockfilePath, (err) => {
|
|
1299
|
+
if (!err) {
|
|
1300
|
+
return mtimePrecision.probe(lockfilePath, options.fs, (err2, mtime, mtimePrecision2) => {
|
|
1301
|
+
if (err2) {
|
|
1302
|
+
options.fs.rmdir(lockfilePath, () => {
|
|
1303
|
+
});
|
|
1304
|
+
return callback(err2);
|
|
1305
|
+
}
|
|
1306
|
+
callback(null, mtime, mtimePrecision2);
|
|
1307
|
+
});
|
|
1308
|
+
}
|
|
1309
|
+
if (err.code !== "EEXIST") {
|
|
1310
|
+
return callback(err);
|
|
1311
|
+
}
|
|
1312
|
+
if (options.stale <= 0) {
|
|
1313
|
+
return callback(Object.assign(new Error("Lock file is already being held"), { code: "ELOCKED", file }));
|
|
1314
|
+
}
|
|
1315
|
+
options.fs.stat(lockfilePath, (err2, stat) => {
|
|
1316
|
+
if (err2) {
|
|
1317
|
+
if (err2.code === "ENOENT") {
|
|
1318
|
+
return acquireLock(file, { ...options, stale: 0 }, callback);
|
|
1319
|
+
}
|
|
1320
|
+
return callback(err2);
|
|
1321
|
+
}
|
|
1322
|
+
if (!isLockStale(stat, options)) {
|
|
1323
|
+
return callback(Object.assign(new Error("Lock file is already being held"), { code: "ELOCKED", file }));
|
|
1324
|
+
}
|
|
1325
|
+
removeLock(file, options, (err3) => {
|
|
1326
|
+
if (err3) {
|
|
1327
|
+
return callback(err3);
|
|
1328
|
+
}
|
|
1329
|
+
acquireLock(file, { ...options, stale: 0 }, callback);
|
|
1330
|
+
});
|
|
1331
|
+
});
|
|
1332
|
+
});
|
|
1333
|
+
}
|
|
1334
|
+
function isLockStale(stat, options) {
|
|
1335
|
+
return stat.mtime.getTime() < Date.now() - options.stale;
|
|
1336
|
+
}
|
|
1337
|
+
function removeLock(file, options, callback) {
|
|
1338
|
+
options.fs.rmdir(getLockFile(file, options), (err) => {
|
|
1339
|
+
if (err && err.code !== "ENOENT") {
|
|
1340
|
+
return callback(err);
|
|
1341
|
+
}
|
|
1342
|
+
callback();
|
|
1343
|
+
});
|
|
1344
|
+
}
|
|
1345
|
+
function updateLock(file, options) {
|
|
1346
|
+
const lock2 = locks[file];
|
|
1347
|
+
if (lock2.updateTimeout) {
|
|
1348
|
+
return;
|
|
1349
|
+
}
|
|
1350
|
+
lock2.updateDelay = lock2.updateDelay || options.update;
|
|
1351
|
+
lock2.updateTimeout = setTimeout(() => {
|
|
1352
|
+
lock2.updateTimeout = null;
|
|
1353
|
+
options.fs.stat(lock2.lockfilePath, (err, stat) => {
|
|
1354
|
+
const isOverThreshold = lock2.lastUpdate + options.stale < Date.now();
|
|
1355
|
+
if (err) {
|
|
1356
|
+
if (err.code === "ENOENT" || isOverThreshold) {
|
|
1357
|
+
return setLockAsCompromised(file, lock2, Object.assign(err, { code: "ECOMPROMISED" }));
|
|
1358
|
+
}
|
|
1359
|
+
lock2.updateDelay = 1e3;
|
|
1360
|
+
return updateLock(file, options);
|
|
1361
|
+
}
|
|
1362
|
+
const isMtimeOurs = lock2.mtime.getTime() === stat.mtime.getTime();
|
|
1363
|
+
if (!isMtimeOurs) {
|
|
1364
|
+
return setLockAsCompromised(
|
|
1365
|
+
file,
|
|
1366
|
+
lock2,
|
|
1367
|
+
Object.assign(
|
|
1368
|
+
new Error("Unable to update lock within the stale threshold"),
|
|
1369
|
+
{ code: "ECOMPROMISED" }
|
|
1370
|
+
)
|
|
1371
|
+
);
|
|
1372
|
+
}
|
|
1373
|
+
const mtime = mtimePrecision.getMtime(lock2.mtimePrecision);
|
|
1374
|
+
options.fs.utimes(lock2.lockfilePath, mtime, mtime, (err2) => {
|
|
1375
|
+
const isOverThreshold2 = lock2.lastUpdate + options.stale < Date.now();
|
|
1376
|
+
if (lock2.released) {
|
|
1377
|
+
return;
|
|
1378
|
+
}
|
|
1379
|
+
if (err2) {
|
|
1380
|
+
if (err2.code === "ENOENT" || isOverThreshold2) {
|
|
1381
|
+
return setLockAsCompromised(file, lock2, Object.assign(err2, { code: "ECOMPROMISED" }));
|
|
1382
|
+
}
|
|
1383
|
+
lock2.updateDelay = 1e3;
|
|
1384
|
+
return updateLock(file, options);
|
|
1385
|
+
}
|
|
1386
|
+
lock2.mtime = mtime;
|
|
1387
|
+
lock2.lastUpdate = Date.now();
|
|
1388
|
+
lock2.updateDelay = null;
|
|
1389
|
+
updateLock(file, options);
|
|
1390
|
+
});
|
|
1391
|
+
});
|
|
1392
|
+
}, lock2.updateDelay);
|
|
1393
|
+
if (lock2.updateTimeout.unref) {
|
|
1394
|
+
lock2.updateTimeout.unref();
|
|
1395
|
+
}
|
|
1396
|
+
}
|
|
1397
|
+
function setLockAsCompromised(file, lock2, err) {
|
|
1398
|
+
lock2.released = true;
|
|
1399
|
+
if (lock2.updateTimeout) {
|
|
1400
|
+
clearTimeout(lock2.updateTimeout);
|
|
1401
|
+
}
|
|
1402
|
+
if (locks[file] === lock2) {
|
|
1403
|
+
delete locks[file];
|
|
1404
|
+
}
|
|
1405
|
+
lock2.options.onCompromised(err);
|
|
1406
|
+
}
|
|
1407
|
+
function lock(file, options, callback) {
|
|
1408
|
+
options = {
|
|
1409
|
+
stale: 1e4,
|
|
1410
|
+
update: null,
|
|
1411
|
+
realpath: true,
|
|
1412
|
+
retries: 0,
|
|
1413
|
+
fs,
|
|
1414
|
+
onCompromised: (err) => {
|
|
1415
|
+
throw err;
|
|
1416
|
+
},
|
|
1417
|
+
...options
|
|
1418
|
+
};
|
|
1419
|
+
options.retries = options.retries || 0;
|
|
1420
|
+
options.retries = typeof options.retries === "number" ? { retries: options.retries } : options.retries;
|
|
1421
|
+
options.stale = Math.max(options.stale || 0, 2e3);
|
|
1422
|
+
options.update = options.update == null ? options.stale / 2 : options.update || 0;
|
|
1423
|
+
options.update = Math.max(Math.min(options.update, options.stale / 2), 1e3);
|
|
1424
|
+
resolveCanonicalPath(file, options, (err, file2) => {
|
|
1425
|
+
if (err) {
|
|
1426
|
+
return callback(err);
|
|
1427
|
+
}
|
|
1428
|
+
const operation = retry.operation(options.retries);
|
|
1429
|
+
operation.attempt(() => {
|
|
1430
|
+
acquireLock(file2, options, (err2, mtime, mtimePrecision2) => {
|
|
1431
|
+
if (operation.retry(err2)) {
|
|
1432
|
+
return;
|
|
1433
|
+
}
|
|
1434
|
+
if (err2) {
|
|
1435
|
+
return callback(operation.mainError());
|
|
1436
|
+
}
|
|
1437
|
+
const lock2 = locks[file2] = {
|
|
1438
|
+
lockfilePath: getLockFile(file2, options),
|
|
1439
|
+
mtime,
|
|
1440
|
+
mtimePrecision: mtimePrecision2,
|
|
1441
|
+
options,
|
|
1442
|
+
lastUpdate: Date.now()
|
|
1443
|
+
};
|
|
1444
|
+
updateLock(file2, options);
|
|
1445
|
+
callback(null, (releasedCallback) => {
|
|
1446
|
+
if (lock2.released) {
|
|
1447
|
+
return releasedCallback && releasedCallback(Object.assign(new Error("Lock is already released"), { code: "ERELEASED" }));
|
|
1448
|
+
}
|
|
1449
|
+
unlock(file2, { ...options, realpath: false }, releasedCallback);
|
|
1450
|
+
});
|
|
1451
|
+
});
|
|
1452
|
+
});
|
|
1453
|
+
});
|
|
1454
|
+
}
|
|
1455
|
+
function unlock(file, options, callback) {
|
|
1456
|
+
options = {
|
|
1457
|
+
fs,
|
|
1458
|
+
realpath: true,
|
|
1459
|
+
...options
|
|
1460
|
+
};
|
|
1461
|
+
resolveCanonicalPath(file, options, (err, file2) => {
|
|
1462
|
+
if (err) {
|
|
1463
|
+
return callback(err);
|
|
1464
|
+
}
|
|
1465
|
+
const lock2 = locks[file2];
|
|
1466
|
+
if (!lock2) {
|
|
1467
|
+
return callback(Object.assign(new Error("Lock is not acquired/owned by you"), { code: "ENOTACQUIRED" }));
|
|
1468
|
+
}
|
|
1469
|
+
lock2.updateTimeout && clearTimeout(lock2.updateTimeout);
|
|
1470
|
+
lock2.released = true;
|
|
1471
|
+
delete locks[file2];
|
|
1472
|
+
removeLock(file2, options, callback);
|
|
1473
|
+
});
|
|
1474
|
+
}
|
|
1475
|
+
function check(file, options, callback) {
|
|
1476
|
+
options = {
|
|
1477
|
+
stale: 1e4,
|
|
1478
|
+
realpath: true,
|
|
1479
|
+
fs,
|
|
1480
|
+
...options
|
|
1481
|
+
};
|
|
1482
|
+
options.stale = Math.max(options.stale || 0, 2e3);
|
|
1483
|
+
resolveCanonicalPath(file, options, (err, file2) => {
|
|
1484
|
+
if (err) {
|
|
1485
|
+
return callback(err);
|
|
1486
|
+
}
|
|
1487
|
+
options.fs.stat(getLockFile(file2, options), (err2, stat) => {
|
|
1488
|
+
if (err2) {
|
|
1489
|
+
return err2.code === "ENOENT" ? callback(null, false) : callback(err2);
|
|
1490
|
+
}
|
|
1491
|
+
return callback(null, !isLockStale(stat, options));
|
|
1492
|
+
});
|
|
1493
|
+
});
|
|
1494
|
+
}
|
|
1495
|
+
function getLocks() {
|
|
1496
|
+
return locks;
|
|
1497
|
+
}
|
|
1498
|
+
onExit(() => {
|
|
1499
|
+
for (const file in locks) {
|
|
1500
|
+
const options = locks[file].options;
|
|
1501
|
+
try {
|
|
1502
|
+
options.fs.rmdirSync(getLockFile(file, options));
|
|
1503
|
+
} catch (e) {
|
|
1504
|
+
}
|
|
1505
|
+
}
|
|
1506
|
+
});
|
|
1507
|
+
module.exports.lock = lock;
|
|
1508
|
+
module.exports.unlock = unlock;
|
|
1509
|
+
module.exports.check = check;
|
|
1510
|
+
module.exports.getLocks = getLocks;
|
|
1511
|
+
}
|
|
1512
|
+
});
|
|
1513
|
+
|
|
1514
|
+
// node_modules/proper-lockfile/lib/adapter.js
|
|
1515
|
+
var require_adapter = __commonJS({
|
|
1516
|
+
"node_modules/proper-lockfile/lib/adapter.js"(exports, module) {
|
|
1517
|
+
"use strict";
|
|
1518
|
+
var fs = require_graceful_fs();
|
|
1519
|
+
function createSyncFs(fs2) {
|
|
1520
|
+
const methods = ["mkdir", "realpath", "stat", "rmdir", "utimes"];
|
|
1521
|
+
const newFs = { ...fs2 };
|
|
1522
|
+
methods.forEach((method) => {
|
|
1523
|
+
newFs[method] = (...args) => {
|
|
1524
|
+
const callback = args.pop();
|
|
1525
|
+
let ret;
|
|
1526
|
+
try {
|
|
1527
|
+
ret = fs2[`${method}Sync`](...args);
|
|
1528
|
+
} catch (err) {
|
|
1529
|
+
return callback(err);
|
|
1530
|
+
}
|
|
1531
|
+
callback(null, ret);
|
|
1532
|
+
};
|
|
1533
|
+
});
|
|
1534
|
+
return newFs;
|
|
1535
|
+
}
|
|
1536
|
+
function toPromise(method) {
|
|
1537
|
+
return (...args) => new Promise((resolve, reject) => {
|
|
1538
|
+
args.push((err, result) => {
|
|
1539
|
+
if (err) {
|
|
1540
|
+
reject(err);
|
|
1541
|
+
} else {
|
|
1542
|
+
resolve(result);
|
|
1543
|
+
}
|
|
1544
|
+
});
|
|
1545
|
+
method(...args);
|
|
1546
|
+
});
|
|
1547
|
+
}
|
|
1548
|
+
function toSync(method) {
|
|
1549
|
+
return (...args) => {
|
|
1550
|
+
let err;
|
|
1551
|
+
let result;
|
|
1552
|
+
args.push((_err, _result) => {
|
|
1553
|
+
err = _err;
|
|
1554
|
+
result = _result;
|
|
1555
|
+
});
|
|
1556
|
+
method(...args);
|
|
1557
|
+
if (err) {
|
|
1558
|
+
throw err;
|
|
1559
|
+
}
|
|
1560
|
+
return result;
|
|
1561
|
+
};
|
|
1562
|
+
}
|
|
1563
|
+
function toSyncOptions(options) {
|
|
1564
|
+
options = { ...options };
|
|
1565
|
+
options.fs = createSyncFs(options.fs || fs);
|
|
1566
|
+
if (typeof options.retries === "number" && options.retries > 0 || options.retries && typeof options.retries.retries === "number" && options.retries.retries > 0) {
|
|
1567
|
+
throw Object.assign(new Error("Cannot use retries with the sync api"), { code: "ESYNC" });
|
|
1568
|
+
}
|
|
1569
|
+
return options;
|
|
1570
|
+
}
|
|
1571
|
+
module.exports = {
|
|
1572
|
+
toPromise,
|
|
1573
|
+
toSync,
|
|
1574
|
+
toSyncOptions
|
|
1575
|
+
};
|
|
1576
|
+
}
|
|
1577
|
+
});
|
|
1578
|
+
|
|
1579
|
+
// node_modules/proper-lockfile/index.js
|
|
1580
|
+
var require_proper_lockfile = __commonJS({
|
|
1581
|
+
"node_modules/proper-lockfile/index.js"(exports, module) {
|
|
1582
|
+
"use strict";
|
|
1583
|
+
var lockfile2 = require_lockfile();
|
|
1584
|
+
var { toPromise, toSync, toSyncOptions } = require_adapter();
|
|
1585
|
+
async function lock(file, options) {
|
|
1586
|
+
const release = await toPromise(lockfile2.lock)(file, options);
|
|
1587
|
+
return toPromise(release);
|
|
1588
|
+
}
|
|
1589
|
+
function lockSync(file, options) {
|
|
1590
|
+
const release = toSync(lockfile2.lock)(file, toSyncOptions(options));
|
|
1591
|
+
return toSync(release);
|
|
1592
|
+
}
|
|
1593
|
+
function unlock(file, options) {
|
|
1594
|
+
return toPromise(lockfile2.unlock)(file, options);
|
|
1595
|
+
}
|
|
1596
|
+
function unlockSync(file, options) {
|
|
1597
|
+
return toSync(lockfile2.unlock)(file, toSyncOptions(options));
|
|
1598
|
+
}
|
|
1599
|
+
function check(file, options) {
|
|
1600
|
+
return toPromise(lockfile2.check)(file, options);
|
|
1601
|
+
}
|
|
1602
|
+
function checkSync(file, options) {
|
|
1603
|
+
return toSync(lockfile2.check)(file, toSyncOptions(options));
|
|
1604
|
+
}
|
|
1605
|
+
module.exports = lock;
|
|
1606
|
+
module.exports.lock = lock;
|
|
1607
|
+
module.exports.unlock = unlock;
|
|
1608
|
+
module.exports.lockSync = lockSync;
|
|
1609
|
+
module.exports.unlockSync = unlockSync;
|
|
1610
|
+
module.exports.check = check;
|
|
1611
|
+
module.exports.checkSync = checkSync;
|
|
1612
|
+
}
|
|
1613
|
+
});
|
|
1614
|
+
|
|
1615
|
+
// core-auth/dist/env.js
|
|
1616
|
+
import { existsSync } from "fs";
|
|
1617
|
+
import { join } from "path";
|
|
1618
|
+
import { homedir } from "os";
|
|
1619
|
+
function getConfigDir() {
|
|
1620
|
+
return process.env.HUB_CONFIG_DIR || (existsSync(join(homedir(), ".claude")) ? join(homedir(), ".claude") : join(homedir(), ".config", "opencode"));
|
|
1621
|
+
}
|
|
1622
|
+
function configFolder() {
|
|
1623
|
+
return join(getConfigDir(), "config");
|
|
1624
|
+
}
|
|
1625
|
+
|
|
1626
|
+
// core-auth/dist/log.js
|
|
1627
|
+
var START_TIME = (/* @__PURE__ */ new Date()).toISOString().replace(/:/g, "-").split(".")[0];
|
|
1628
|
+
|
|
1629
|
+
// core-auth/dist/accounts.js
|
|
1630
|
+
import { existsSync as existsSync2, readFileSync, writeFileSync, mkdirSync, renameSync, openSync, closeSync, unlinkSync, statSync } from "fs";
|
|
1631
|
+
import { join as join2 } from "path";
|
|
1632
|
+
import { randomBytes } from "crypto";
|
|
1633
|
+
var DEFAULT_FILE = "core-auth-accounts.json";
|
|
1634
|
+
var LOCK_STALE_MS = 15 * 1e3;
|
|
1635
|
+
var LOCK_WAIT_MS = 5 * 1e3;
|
|
1636
|
+
var LOCK_POLL_MS = 25;
|
|
1637
|
+
function storeFile(opts) {
|
|
1638
|
+
return join2(opts && opts.dir || configFolder(), opts && opts.file || DEFAULT_FILE);
|
|
1639
|
+
}
|
|
1640
|
+
function ensureDir(opts) {
|
|
1641
|
+
const dir = opts && opts.dir || configFolder();
|
|
1642
|
+
if (!existsSync2(dir))
|
|
1643
|
+
mkdirSync(dir, { recursive: true });
|
|
1644
|
+
}
|
|
1645
|
+
function sleepSync(ms) {
|
|
1646
|
+
try {
|
|
1647
|
+
Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, ms);
|
|
1648
|
+
} catch {
|
|
1649
|
+
}
|
|
1650
|
+
}
|
|
1651
|
+
function withLock(opts, fn) {
|
|
1652
|
+
ensureDir(opts);
|
|
1653
|
+
const lockPath = storeFile(opts) + ".lock";
|
|
1654
|
+
const deadline = Date.now() + LOCK_WAIT_MS;
|
|
1655
|
+
let handle = null;
|
|
1656
|
+
while (handle === null) {
|
|
1657
|
+
try {
|
|
1658
|
+
handle = openSync(lockPath, "wx");
|
|
1659
|
+
} catch (error) {
|
|
1660
|
+
if (!error || error.code !== "EEXIST")
|
|
1661
|
+
break;
|
|
1662
|
+
try {
|
|
1663
|
+
if (Date.now() - statSync(lockPath).mtimeMs > LOCK_STALE_MS) {
|
|
1664
|
+
unlinkSync(lockPath);
|
|
1665
|
+
continue;
|
|
1666
|
+
}
|
|
1667
|
+
} catch {
|
|
1668
|
+
}
|
|
1669
|
+
if (Date.now() > deadline)
|
|
1670
|
+
break;
|
|
1671
|
+
sleepSync(LOCK_POLL_MS);
|
|
1672
|
+
}
|
|
1673
|
+
}
|
|
1674
|
+
try {
|
|
1675
|
+
return fn();
|
|
1676
|
+
} finally {
|
|
1677
|
+
if (handle !== null) {
|
|
1678
|
+
try {
|
|
1679
|
+
closeSync(handle);
|
|
1680
|
+
} catch {
|
|
1681
|
+
}
|
|
1682
|
+
try {
|
|
1683
|
+
unlinkSync(lockPath);
|
|
1684
|
+
} catch {
|
|
1685
|
+
}
|
|
1686
|
+
}
|
|
1687
|
+
}
|
|
1688
|
+
}
|
|
1689
|
+
function readStore(opts) {
|
|
1690
|
+
try {
|
|
1691
|
+
const file = storeFile(opts);
|
|
1692
|
+
if (existsSync2(file))
|
|
1693
|
+
return JSON.parse(readFileSync(file, "utf8")) || {};
|
|
1694
|
+
} catch {
|
|
1695
|
+
}
|
|
1696
|
+
return { version: 1, providers: {} };
|
|
1697
|
+
}
|
|
1698
|
+
function writeStore(store, opts) {
|
|
1699
|
+
ensureDir(opts);
|
|
1700
|
+
const file = storeFile(opts);
|
|
1701
|
+
const tmp = file + "." + randomBytes(6).toString("hex") + ".tmp";
|
|
1702
|
+
writeFileSync(tmp, JSON.stringify(store, null, 2), { encoding: "utf8", mode: 384 });
|
|
1703
|
+
renameSync(tmp, file);
|
|
1704
|
+
}
|
|
1705
|
+
function emptyPool() {
|
|
1706
|
+
return { accounts: [], activeIndex: 0, activeIndexByLane: {} };
|
|
1707
|
+
}
|
|
1708
|
+
function poolFrom(store, provider) {
|
|
1709
|
+
const p = store.providers && store.providers[provider];
|
|
1710
|
+
if (!p || !Array.isArray(p.accounts))
|
|
1711
|
+
return emptyPool();
|
|
1712
|
+
return { accounts: p.accounts, activeIndex: p.activeIndex || 0, activeIndexByLane: p.activeIndexByLane || {} };
|
|
1713
|
+
}
|
|
1714
|
+
function loadAccounts(provider, opts) {
|
|
1715
|
+
return poolFrom(readStore(opts), provider);
|
|
1716
|
+
}
|
|
1717
|
+
function updateAccounts(provider, mutator, opts) {
|
|
1718
|
+
const pool = withLock(opts, () => {
|
|
1719
|
+
const store = readStore(opts);
|
|
1720
|
+
store.version = 1;
|
|
1721
|
+
store.providers = store.providers || {};
|
|
1722
|
+
const current = poolFrom(store, provider);
|
|
1723
|
+
mutator(current);
|
|
1724
|
+
store.providers[provider] = {
|
|
1725
|
+
accounts: current.accounts || [],
|
|
1726
|
+
activeIndex: current.activeIndex || 0,
|
|
1727
|
+
activeIndexByLane: current.activeIndexByLane || {}
|
|
1728
|
+
};
|
|
1729
|
+
writeStore(store, opts);
|
|
1730
|
+
return current;
|
|
1731
|
+
});
|
|
1732
|
+
return pool;
|
|
1733
|
+
}
|
|
1734
|
+
function listAccounts(provider, opts) {
|
|
1735
|
+
return loadAccounts(provider, opts).accounts;
|
|
1736
|
+
}
|
|
1737
|
+
function addAccount(provider, account, opts) {
|
|
1738
|
+
updateAccounts(provider, (pool) => {
|
|
1739
|
+
const i = pool.accounts.findIndex((a) => account.id && a.id === account.id || account.refresh && a.refresh === account.refresh);
|
|
1740
|
+
if (i >= 0)
|
|
1741
|
+
pool.accounts[i] = { ...pool.accounts[i], ...account };
|
|
1742
|
+
else
|
|
1743
|
+
pool.accounts.push(account);
|
|
1744
|
+
}, opts);
|
|
1745
|
+
}
|
|
1746
|
+
function removeAccount(provider, id, opts) {
|
|
1747
|
+
updateAccounts(provider, (pool) => {
|
|
1748
|
+
pool.accounts = pool.accounts.filter((a) => a.id !== id);
|
|
1749
|
+
}, opts);
|
|
1750
|
+
}
|
|
1751
|
+
|
|
1752
|
+
// core-auth/dist/ui/ansi.js
|
|
1753
|
+
function isTTY() {
|
|
1754
|
+
return Boolean(process.stdin.isTTY);
|
|
1755
|
+
}
|
|
1756
|
+
|
|
1757
|
+
// core-auth/dist/ui/menu-render.js
|
|
1758
|
+
import { createInterface as createInterface2 } from "node:readline/promises";
|
|
1759
|
+
|
|
1760
|
+
// core-auth/dist/ui/prompt.js
|
|
1761
|
+
import { createInterface } from "node:readline/promises";
|
|
1762
|
+
|
|
1763
|
+
// core-auth/dist/proxy/store.js
|
|
1764
|
+
import { existsSync as existsSync3, readFileSync as readFileSync2, writeFileSync as writeFileSync2, mkdirSync as mkdirSync2, renameSync as renameSync2 } from "fs";
|
|
1765
|
+
import { join as join3 } from "path";
|
|
1766
|
+
import { randomBytes as randomBytes2 } from "crypto";
|
|
1767
|
+
var FILE = "core-auth-proxies.json";
|
|
1768
|
+
function storeFile2() {
|
|
1769
|
+
return join3(configFolder(), FILE);
|
|
1770
|
+
}
|
|
1771
|
+
function empty() {
|
|
1772
|
+
return { version: 1, mode: "disabled", providers: {}, proxies: [], assignments: {}, manualSelection: {} };
|
|
1773
|
+
}
|
|
1774
|
+
function loadProxyStore() {
|
|
1775
|
+
try {
|
|
1776
|
+
const f = storeFile2();
|
|
1777
|
+
if (existsSync3(f))
|
|
1778
|
+
return { ...empty(), ...JSON.parse(readFileSync2(f, "utf8")) || {} };
|
|
1779
|
+
} catch {
|
|
1780
|
+
}
|
|
1781
|
+
return empty();
|
|
1782
|
+
}
|
|
1783
|
+
function saveProxyStore(store) {
|
|
1784
|
+
try {
|
|
1785
|
+
if (!existsSync3(configFolder()))
|
|
1786
|
+
mkdirSync2(configFolder(), { recursive: true });
|
|
1787
|
+
const file = storeFile2();
|
|
1788
|
+
const tmp = file + "." + randomBytes2(6).toString("hex") + ".tmp";
|
|
1789
|
+
writeFileSync2(tmp, JSON.stringify(store, null, 2), { encoding: "utf8", mode: 384 });
|
|
1790
|
+
renameSync2(tmp, file);
|
|
1791
|
+
} catch {
|
|
1792
|
+
}
|
|
1793
|
+
}
|
|
1794
|
+
function updateProxyStore(mutator) {
|
|
1795
|
+
const store = loadProxyStore();
|
|
1796
|
+
mutator(store);
|
|
1797
|
+
saveProxyStore(store);
|
|
1798
|
+
return store;
|
|
1799
|
+
}
|
|
1800
|
+
|
|
1801
|
+
// core-auth/dist/proxy/providers.js
|
|
1802
|
+
async function getText(url, init) {
|
|
1803
|
+
const aborter = new AbortController();
|
|
1804
|
+
const timer = setTimeout(() => aborter.abort(), 1e4);
|
|
1805
|
+
try {
|
|
1806
|
+
const r = await fetch(url, { ...init || {}, signal: aborter.signal });
|
|
1807
|
+
return r.ok ? await r.text() : "";
|
|
1808
|
+
} catch {
|
|
1809
|
+
return "";
|
|
1810
|
+
} finally {
|
|
1811
|
+
clearTimeout(timer);
|
|
1812
|
+
}
|
|
1813
|
+
}
|
|
1814
|
+
function linesToProxies(text, provider) {
|
|
1815
|
+
return text.split(/\s+/).map((l) => l.trim()).filter(Boolean).map((hostPort) => ({ url: hostPort.startsWith("http") ? hostPort : "http://" + hostPort, provider }));
|
|
1816
|
+
}
|
|
1817
|
+
async function proxyscrape() {
|
|
1818
|
+
const text = await getText("https://api.proxyscrape.com/v2/?request=displayproxies&protocol=http&timeout=5000&country=all&ssl=all&anonymity=all");
|
|
1819
|
+
return linesToProxies(text, "proxyscrape");
|
|
1820
|
+
}
|
|
1821
|
+
async function proxifly() {
|
|
1822
|
+
const text = await getText("https://cdn.jsdelivr.net/gh/proxifly/free-proxy-list@main/proxies/protocols/http/data.txt");
|
|
1823
|
+
return linesToProxies(text, "proxifly");
|
|
1824
|
+
}
|
|
1825
|
+
async function pubproxy() {
|
|
1826
|
+
const text = await getText("http://pubproxy.com/api/proxy?limit=20&type=http&format=txt");
|
|
1827
|
+
return linesToProxies(text, "pubproxy");
|
|
1828
|
+
}
|
|
1829
|
+
async function geonix() {
|
|
1830
|
+
const text = await getText("https://cdn.jsdelivr.net/gh/TheSpeedX/PROXY-List@master/http.txt");
|
|
1831
|
+
return linesToProxies(text, "geonix");
|
|
1832
|
+
}
|
|
1833
|
+
async function iplocate() {
|
|
1834
|
+
const text = await getText("https://cdn.jsdelivr.net/gh/monosans/proxy-list@main/proxies/http.txt");
|
|
1835
|
+
return linesToProxies(text, "iplocate");
|
|
1836
|
+
}
|
|
1837
|
+
async function keyed(provider, config) {
|
|
1838
|
+
if (!config || !config.key)
|
|
1839
|
+
return [];
|
|
1840
|
+
return [];
|
|
1841
|
+
}
|
|
1842
|
+
var FREE = { proxyscrape, proxifly, pubproxy, geonix, iplocate };
|
|
1843
|
+
var KEYED = ["webshare", "brightdata", "oxylabs", "litport"];
|
|
1844
|
+
async function fetchEnabledProxies(providersConfig) {
|
|
1845
|
+
const config = providersConfig || {};
|
|
1846
|
+
const out = [];
|
|
1847
|
+
for (const [name, fn] of Object.entries(FREE)) {
|
|
1848
|
+
if (config[name] && config[name].enabled) {
|
|
1849
|
+
try {
|
|
1850
|
+
out.push(...await fn());
|
|
1851
|
+
} catch {
|
|
1852
|
+
}
|
|
1853
|
+
}
|
|
1854
|
+
}
|
|
1855
|
+
for (const name of KEYED) {
|
|
1856
|
+
if (config[name] && config[name].enabled) {
|
|
1857
|
+
try {
|
|
1858
|
+
out.push(...await keyed(name, config[name]));
|
|
1859
|
+
} catch {
|
|
1860
|
+
}
|
|
1861
|
+
}
|
|
1862
|
+
}
|
|
1863
|
+
return out;
|
|
1864
|
+
}
|
|
1865
|
+
var PROXY_PROVIDERS = ["manual", ...Object.keys(FREE), ...KEYED];
|
|
1866
|
+
|
|
1867
|
+
// core-auth/dist/proxy/manager.js
|
|
1868
|
+
var MAX_ACCOUNTS_PER_PROXY = 3;
|
|
1869
|
+
function countAssignments(store, url) {
|
|
1870
|
+
return Object.values(store.assignments || {}).filter((u) => u === url).length;
|
|
1871
|
+
}
|
|
1872
|
+
function scoreOf(store, proxy) {
|
|
1873
|
+
const s = proxy.stats || {};
|
|
1874
|
+
const checks = s.checks || 0;
|
|
1875
|
+
const failRate = checks ? (s.failures || 0) / checks : 0.5;
|
|
1876
|
+
const inUse = countAssignments(store, proxy.url);
|
|
1877
|
+
return (s.avgLatencyMs || 2e3) / 1e3 + failRate * 10 + (s.ipRateLimitHits || 0) * 20 + inUse * 5 - (proxy.provider === "manual" ? 10 : 0);
|
|
1878
|
+
}
|
|
1879
|
+
var ProxyManager = class {
|
|
1880
|
+
load() {
|
|
1881
|
+
return loadProxyStore();
|
|
1882
|
+
}
|
|
1883
|
+
getMode() {
|
|
1884
|
+
return this.load().mode || "disabled";
|
|
1885
|
+
}
|
|
1886
|
+
setMode(mode) {
|
|
1887
|
+
updateProxyStore((s) => {
|
|
1888
|
+
s.mode = mode;
|
|
1889
|
+
});
|
|
1890
|
+
}
|
|
1891
|
+
enableProvider(name, on, key) {
|
|
1892
|
+
updateProxyStore((s) => {
|
|
1893
|
+
s.providers[name] = { ...s.providers[name] || {}, enabled: !!on, ...key !== void 0 ? { key } : {} };
|
|
1894
|
+
});
|
|
1895
|
+
}
|
|
1896
|
+
providersConfig() {
|
|
1897
|
+
return this.load().providers || {};
|
|
1898
|
+
}
|
|
1899
|
+
// proxies sorted best-first (lowest score)
|
|
1900
|
+
list() {
|
|
1901
|
+
const store = this.load();
|
|
1902
|
+
return [...store.proxies].map((p) => ({ ...p, score: scoreOf(store, p), inUse: countAssignments(store, p.url) })).sort((a, b) => a.score - b.score);
|
|
1903
|
+
}
|
|
1904
|
+
// global view (account-only proxies are excluded; they show in their account's menu)
|
|
1905
|
+
byProvider() {
|
|
1906
|
+
const groups = {};
|
|
1907
|
+
for (const p of this.list())
|
|
1908
|
+
if (!p.owner)
|
|
1909
|
+
(groups[p.provider] = groups[p.provider] || []).push(p);
|
|
1910
|
+
return groups;
|
|
1911
|
+
}
|
|
1912
|
+
// proxies visible to one account: all global + the account's own
|
|
1913
|
+
accountProxies(accountId) {
|
|
1914
|
+
return this.list().filter((p) => !p.owner || p.owner === accountId);
|
|
1915
|
+
}
|
|
1916
|
+
get(url) {
|
|
1917
|
+
return this.list().find((p) => p.url === url) || null;
|
|
1918
|
+
}
|
|
1919
|
+
// owner set -> account-only (visible + auto-used for that account only); else global
|
|
1920
|
+
addManual(url, owner) {
|
|
1921
|
+
const clean = url.startsWith("http") ? url : "http://" + url;
|
|
1922
|
+
updateProxyStore((s) => {
|
|
1923
|
+
if (!s.proxies.find((p) => p.url === clean))
|
|
1924
|
+
s.proxies.push({ url: clean, provider: "manual", owner: owner || void 0, addedAt: Date.now(), stats: { checks: 0, failures: 0, avgLatencyMs: 0, ipRateLimitHits: 0, lastOkAt: 0 } });
|
|
1925
|
+
});
|
|
1926
|
+
return clean;
|
|
1927
|
+
}
|
|
1928
|
+
remove(url) {
|
|
1929
|
+
updateProxyStore((s) => {
|
|
1930
|
+
s.proxies = s.proxies.filter((p) => p.url !== url);
|
|
1931
|
+
for (const [acc, u] of Object.entries(s.assignments))
|
|
1932
|
+
if (u === url)
|
|
1933
|
+
delete s.assignments[acc];
|
|
1934
|
+
for (const acc of Object.keys(s.manualSelection))
|
|
1935
|
+
s.manualSelection[acc] = (s.manualSelection[acc] || []).filter((u) => u !== url);
|
|
1936
|
+
});
|
|
1937
|
+
}
|
|
1938
|
+
// manual-mode per-account selection (urls from the pool)
|
|
1939
|
+
getAccountSelection(accountId) {
|
|
1940
|
+
return this.load().manualSelection[accountId] || [];
|
|
1941
|
+
}
|
|
1942
|
+
setAccountSelection(accountId, urls) {
|
|
1943
|
+
updateProxyStore((s) => {
|
|
1944
|
+
s.manualSelection[accountId] = urls;
|
|
1945
|
+
});
|
|
1946
|
+
}
|
|
1947
|
+
// pick a proxy url for an account per mode; sticks until freed (rate-limit) or cap-bound
|
|
1948
|
+
selectForAccount(accountId) {
|
|
1949
|
+
const store = this.load();
|
|
1950
|
+
if (store.mode === "disabled")
|
|
1951
|
+
return null;
|
|
1952
|
+
if (store.mode === "manual") {
|
|
1953
|
+
const owned = store.proxies.filter((p) => p.owner === accountId).map((p) => p.url);
|
|
1954
|
+
const pool = [.../* @__PURE__ */ new Set([...store.manualSelection[accountId] || [], ...owned])].filter((u) => store.proxies.find((p) => p.url === u));
|
|
1955
|
+
if (!pool.length)
|
|
1956
|
+
return null;
|
|
1957
|
+
const current2 = store.assignments[accountId];
|
|
1958
|
+
if (current2 && pool.includes(current2))
|
|
1959
|
+
return current2;
|
|
1960
|
+
const chosen2 = pool[0];
|
|
1961
|
+
updateProxyStore((s) => {
|
|
1962
|
+
s.assignments[accountId] = chosen2;
|
|
1963
|
+
});
|
|
1964
|
+
return chosen2;
|
|
1965
|
+
}
|
|
1966
|
+
const current = store.assignments[accountId];
|
|
1967
|
+
if (current && store.proxies.find((p) => p.url === current))
|
|
1968
|
+
return current;
|
|
1969
|
+
const candidates = store.proxies.filter((p) => (!p.owner || p.owner === accountId) && countAssignments(store, p.url) < MAX_ACCOUNTS_PER_PROXY).sort((a, b) => scoreOf(store, a) - scoreOf(store, b));
|
|
1970
|
+
if (!candidates.length)
|
|
1971
|
+
return null;
|
|
1972
|
+
const chosen = candidates[0].url;
|
|
1973
|
+
updateProxyStore((s) => {
|
|
1974
|
+
s.assignments[accountId] = chosen;
|
|
1975
|
+
});
|
|
1976
|
+
return chosen;
|
|
1977
|
+
}
|
|
1978
|
+
// pick a proxy for login traffic before an account exists (no id to bind yet);
|
|
1979
|
+
// returns the best globally-available proxy, or null when none/disabled
|
|
1980
|
+
pickForLogin() {
|
|
1981
|
+
const store = this.load();
|
|
1982
|
+
if (store.mode === "disabled")
|
|
1983
|
+
return null;
|
|
1984
|
+
const candidates = store.proxies.filter((p) => !p.owner && countAssignments(store, p.url) < MAX_ACCOUNTS_PER_PROXY).sort((a, b) => scoreOf(store, a) - scoreOf(store, b));
|
|
1985
|
+
return candidates.length ? candidates[0].url : null;
|
|
1986
|
+
}
|
|
1987
|
+
// stick the login proxy to the account so refresh + requests reuse it; in manual
|
|
1988
|
+
// mode also record it in the account's selection so selectForAccount keeps it
|
|
1989
|
+
bindAccountProxy(accountId, url) {
|
|
1990
|
+
if (!url)
|
|
1991
|
+
return;
|
|
1992
|
+
updateProxyStore((s) => {
|
|
1993
|
+
if (s.mode === "manual") {
|
|
1994
|
+
const selection = s.manualSelection[accountId] || [];
|
|
1995
|
+
if (!selection.includes(url))
|
|
1996
|
+
selection.push(url);
|
|
1997
|
+
s.manualSelection[accountId] = selection;
|
|
1998
|
+
}
|
|
1999
|
+
s.assignments[accountId] = url;
|
|
2000
|
+
});
|
|
2001
|
+
}
|
|
2002
|
+
reportRateLimit(url) {
|
|
2003
|
+
updateProxyStore((s) => {
|
|
2004
|
+
const p = s.proxies.find((x) => x.url === url);
|
|
2005
|
+
if (p) {
|
|
2006
|
+
p.stats = p.stats || {};
|
|
2007
|
+
p.stats.ipRateLimitHits = (p.stats.ipRateLimitHits || 0) + 1;
|
|
2008
|
+
p.stats.lastRateLimitAt = Date.now();
|
|
2009
|
+
}
|
|
2010
|
+
for (const [acc, u] of Object.entries(s.assignments))
|
|
2011
|
+
if (u === url)
|
|
2012
|
+
delete s.assignments[acc];
|
|
2013
|
+
});
|
|
2014
|
+
}
|
|
2015
|
+
reportResult(url, ok, latencyMs) {
|
|
2016
|
+
updateProxyStore((s) => {
|
|
2017
|
+
const p = s.proxies.find((x) => x.url === url);
|
|
2018
|
+
if (!p)
|
|
2019
|
+
return;
|
|
2020
|
+
const st = p.stats = p.stats || { checks: 0, failures: 0, avgLatencyMs: 0, ipRateLimitHits: 0 };
|
|
2021
|
+
st.checks = (st.checks || 0) + 1;
|
|
2022
|
+
if (!ok)
|
|
2023
|
+
st.failures = (st.failures || 0) + 1;
|
|
2024
|
+
else {
|
|
2025
|
+
st.lastOkAt = Date.now();
|
|
2026
|
+
if (typeof latencyMs === "number")
|
|
2027
|
+
st.avgLatencyMs = st.avgLatencyMs ? Math.round(st.avgLatencyMs * 0.7 + latencyMs * 0.3) : latencyMs;
|
|
2028
|
+
}
|
|
2029
|
+
});
|
|
2030
|
+
}
|
|
2031
|
+
async refresh() {
|
|
2032
|
+
const fetched = await fetchEnabledProxies(this.providersConfig());
|
|
2033
|
+
updateProxyStore((s) => {
|
|
2034
|
+
const have = new Set(s.proxies.map((p) => p.url));
|
|
2035
|
+
for (const f of fetched)
|
|
2036
|
+
if (!have.has(f.url)) {
|
|
2037
|
+
s.proxies.push({ url: f.url, provider: f.provider, addedAt: Date.now(), stats: { checks: 0, failures: 0, avgLatencyMs: 0, ipRateLimitHits: 0, lastOkAt: 0 } });
|
|
2038
|
+
have.add(f.url);
|
|
2039
|
+
}
|
|
2040
|
+
});
|
|
2041
|
+
return fetched.length;
|
|
2042
|
+
}
|
|
2043
|
+
};
|
|
2044
|
+
var proxyManager = new ProxyManager();
|
|
2045
|
+
|
|
2046
|
+
// core-auth/dist/oauth.js
|
|
2047
|
+
var ACCESS_TOKEN_EXPIRY_BUFFER_MS = 60 * 1e3;
|
|
2048
|
+
|
|
2049
|
+
// core-auth/dist/server.js
|
|
2050
|
+
import { createServer } from "node:http";
|
|
2051
|
+
import { readFileSync as readFileSync3, existsSync as existsSync4 } from "node:fs";
|
|
2052
|
+
function isOrbStackDockerHost() {
|
|
2053
|
+
if (!existsSync4("/.dockerenv"))
|
|
2054
|
+
return false;
|
|
2055
|
+
try {
|
|
2056
|
+
if (existsSync4("/proc/version") && readFileSync3("/proc/version", "utf8").toLowerCase().includes("orbstack"))
|
|
2057
|
+
return true;
|
|
2058
|
+
const hostname = process.env.HOSTNAME || "";
|
|
2059
|
+
if (hostname.startsWith("orbstack-") || hostname.endsWith(".orb") || hostname === "orbstack")
|
|
2060
|
+
return true;
|
|
2061
|
+
if (existsSync4("/etc/resolv.conf")) {
|
|
2062
|
+
const resolv = readFileSync3("/etc/resolv.conf", "utf8");
|
|
2063
|
+
if (resolv.includes("orb.local") || resolv.includes("orbstack"))
|
|
2064
|
+
return true;
|
|
2065
|
+
}
|
|
2066
|
+
if (process.platform === "linux" && existsSync4("/run/host-services"))
|
|
2067
|
+
return true;
|
|
2068
|
+
} catch {
|
|
2069
|
+
}
|
|
2070
|
+
return false;
|
|
2071
|
+
}
|
|
2072
|
+
function isWSL() {
|
|
2073
|
+
if (process.platform !== "linux")
|
|
2074
|
+
return false;
|
|
2075
|
+
try {
|
|
2076
|
+
const release = readFileSync3("/proc/version", "utf8").toLowerCase();
|
|
2077
|
+
return release.includes("microsoft") || release.includes("wsl");
|
|
2078
|
+
} catch {
|
|
2079
|
+
return false;
|
|
2080
|
+
}
|
|
2081
|
+
}
|
|
2082
|
+
function isRemoteEnvironment() {
|
|
2083
|
+
return !!(process.env.SSH_CLIENT || process.env.SSH_TTY || process.env.SSH_CONNECTION || process.env.REMOTE_CONTAINERS || process.env.CODESPACES);
|
|
2084
|
+
}
|
|
2085
|
+
function getBindAddress() {
|
|
2086
|
+
if (process.env.HUB_OAUTH_BIND)
|
|
2087
|
+
return process.env.HUB_OAUTH_BIND;
|
|
2088
|
+
if (isOrbStackDockerHost())
|
|
2089
|
+
return "127.0.0.1";
|
|
2090
|
+
if (isWSL() || isRemoteEnvironment())
|
|
2091
|
+
return "0.0.0.0";
|
|
2092
|
+
return "127.0.0.1";
|
|
2093
|
+
}
|
|
2094
|
+
function successPage() {
|
|
2095
|
+
return `<!DOCTYPE html><html lang="en"><head><meta charset="utf-8"/><meta name="viewport" content="width=device-width, initial-scale=1"><title>Authentication Successful</title><style>body{margin:0;min-height:100vh;display:flex;align-items:center;justify-content:center;font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Helvetica,Arial,sans-serif;background:#0b0f17;color:#f9fafb}.card{background:#1f2937;border:1px solid #374151;border-radius:16px;padding:3rem 2rem;max-width:400px;text-align:center}.dot{width:64px;height:64px;background:rgba(52,211,153,.12);border-radius:50%;display:flex;align-items:center;justify-content:center;margin:0 auto 1.5rem;color:#34d399;font-size:32px}h1{font-size:1.5rem;margin:0 0 .5rem}p{color:#9ca3af;margin:0}</style></head><body><div class="card"><div class="dot">✓</div><h1>All set!</h1><p>Authentication succeeded. You can close this tab and return to your terminal.</p></div></body></html>`;
|
|
2096
|
+
}
|
|
2097
|
+
async function startOAuthListener(redirectUriString, opts) {
|
|
2098
|
+
const options = opts || {};
|
|
2099
|
+
const timeoutMs = options.timeoutMs || 5 * 60 * 1e3;
|
|
2100
|
+
const redirectUri = new URL(redirectUriString);
|
|
2101
|
+
const callbackPath = redirectUri.pathname || "/";
|
|
2102
|
+
const port = redirectUri.port ? parseInt(redirectUri.port, 10) : redirectUri.protocol === "https:" ? 443 : 80;
|
|
2103
|
+
const origin = redirectUri.protocol + "//" + redirectUri.host;
|
|
2104
|
+
let settled = false;
|
|
2105
|
+
let resolveCallback, rejectCallback, timeoutHandle;
|
|
2106
|
+
const callbackPromise = new Promise((resolve, reject) => {
|
|
2107
|
+
resolveCallback = (url) => {
|
|
2108
|
+
if (settled)
|
|
2109
|
+
return;
|
|
2110
|
+
settled = true;
|
|
2111
|
+
if (timeoutHandle)
|
|
2112
|
+
clearTimeout(timeoutHandle);
|
|
2113
|
+
resolve(url);
|
|
2114
|
+
};
|
|
2115
|
+
rejectCallback = (error) => {
|
|
2116
|
+
if (settled)
|
|
2117
|
+
return;
|
|
2118
|
+
settled = true;
|
|
2119
|
+
if (timeoutHandle)
|
|
2120
|
+
clearTimeout(timeoutHandle);
|
|
2121
|
+
reject(error);
|
|
2122
|
+
};
|
|
2123
|
+
});
|
|
2124
|
+
timeoutHandle = setTimeout(() => rejectCallback(new Error("Timed out waiting for OAuth callback")), timeoutMs);
|
|
2125
|
+
if (timeoutHandle.unref)
|
|
2126
|
+
timeoutHandle.unref();
|
|
2127
|
+
const server = createServer((request, response) => {
|
|
2128
|
+
if (!request.url) {
|
|
2129
|
+
response.writeHead(400, { "Content-Type": "text/plain" });
|
|
2130
|
+
response.end("Invalid request");
|
|
2131
|
+
return;
|
|
2132
|
+
}
|
|
2133
|
+
const url = new URL(request.url, origin);
|
|
2134
|
+
if (url.pathname !== callbackPath) {
|
|
2135
|
+
response.writeHead(404, { "Content-Type": "text/plain" });
|
|
2136
|
+
response.end("Not found");
|
|
2137
|
+
return;
|
|
2138
|
+
}
|
|
2139
|
+
response.writeHead(200, { "Content-Type": "text/html; charset=utf-8" });
|
|
2140
|
+
response.end(successPage());
|
|
2141
|
+
resolveCallback(url);
|
|
2142
|
+
setImmediate(() => server.close());
|
|
2143
|
+
});
|
|
2144
|
+
await new Promise((resolve, reject) => {
|
|
2145
|
+
const handleError = (error) => {
|
|
2146
|
+
server.off("error", handleError);
|
|
2147
|
+
if (error && error.code === "EADDRINUSE") {
|
|
2148
|
+
reject(new Error("Port " + port + " is already in use."));
|
|
2149
|
+
return;
|
|
2150
|
+
}
|
|
2151
|
+
reject(error);
|
|
2152
|
+
};
|
|
2153
|
+
server.once("error", handleError);
|
|
2154
|
+
server.listen(port, getBindAddress(), () => {
|
|
2155
|
+
server.off("error", handleError);
|
|
2156
|
+
resolve();
|
|
2157
|
+
});
|
|
2158
|
+
});
|
|
2159
|
+
server.on("error", (error) => rejectCallback(error instanceof Error ? error : new Error(String(error))));
|
|
2160
|
+
return {
|
|
2161
|
+
waitForCallback: () => callbackPromise,
|
|
2162
|
+
close: () => new Promise((resolve, reject) => {
|
|
2163
|
+
server.close((error) => {
|
|
2164
|
+
if (error && error.code !== "ERR_SERVER_NOT_RUNNING") {
|
|
2165
|
+
reject(error);
|
|
2166
|
+
return;
|
|
2167
|
+
}
|
|
2168
|
+
if (!settled)
|
|
2169
|
+
rejectCallback(new Error("OAuth listener closed before callback"));
|
|
2170
|
+
resolve();
|
|
2171
|
+
});
|
|
2172
|
+
})
|
|
2173
|
+
};
|
|
2174
|
+
}
|
|
2175
|
+
|
|
2176
|
+
// src/driver/login.ts
|
|
2177
|
+
import { spawn } from "child_process";
|
|
2178
|
+
import { appendFileSync } from "fs";
|
|
2179
|
+
import { homedir as homedir3 } from "os";
|
|
2180
|
+
import { join as join5 } from "path";
|
|
2181
|
+
import { createInterface as createInterface3 } from "node:readline";
|
|
2182
|
+
|
|
2183
|
+
// node_modules/jose/dist/node/esm/runtime/base64url.js
|
|
2184
|
+
import { Buffer as Buffer2 } from "node:buffer";
|
|
2185
|
+
|
|
2186
|
+
// node_modules/jose/dist/node/esm/lib/buffer_utils.js
|
|
2187
|
+
var encoder = new TextEncoder();
|
|
2188
|
+
var decoder = new TextDecoder();
|
|
2189
|
+
var MAX_INT32 = 2 ** 32;
|
|
2190
|
+
|
|
2191
|
+
// node_modules/jose/dist/node/esm/runtime/base64url.js
|
|
2192
|
+
function normalize(input) {
|
|
2193
|
+
let encoded = input;
|
|
2194
|
+
if (encoded instanceof Uint8Array) {
|
|
2195
|
+
encoded = decoder.decode(encoded);
|
|
2196
|
+
}
|
|
2197
|
+
return encoded;
|
|
2198
|
+
}
|
|
2199
|
+
var encode = (input) => Buffer2.from(input).toString("base64url");
|
|
2200
|
+
var decode = (input) => new Uint8Array(Buffer2.from(normalize(input), "base64url"));
|
|
2201
|
+
|
|
2202
|
+
// node_modules/jose/dist/node/esm/util/base64url.js
|
|
2203
|
+
var base64url_exports = {};
|
|
2204
|
+
__export(base64url_exports, {
|
|
2205
|
+
decode: () => decode2,
|
|
2206
|
+
encode: () => encode2
|
|
2207
|
+
});
|
|
2208
|
+
var encode2 = encode;
|
|
2209
|
+
var decode2 = decode;
|
|
2210
|
+
|
|
2211
|
+
// node_modules/@openauthjs/openauth/dist/esm/pkce.js
|
|
2212
|
+
function generateVerifier(length) {
|
|
2213
|
+
const buffer = new Uint8Array(length);
|
|
2214
|
+
crypto.getRandomValues(buffer);
|
|
2215
|
+
return base64url_exports.encode(buffer);
|
|
2216
|
+
}
|
|
2217
|
+
async function generateChallenge(verifier, method) {
|
|
2218
|
+
if (method === "plain")
|
|
2219
|
+
return verifier;
|
|
2220
|
+
const encoder2 = new TextEncoder();
|
|
2221
|
+
const data = encoder2.encode(verifier);
|
|
2222
|
+
const hash = await crypto.subtle.digest("SHA-256", data);
|
|
2223
|
+
return base64url_exports.encode(new Uint8Array(hash));
|
|
2224
|
+
}
|
|
2225
|
+
async function generatePKCE(length = 64) {
|
|
2226
|
+
if (length < 43 || length > 128) {
|
|
2227
|
+
throw new Error("Code verifier length must be between 43 and 128 characters");
|
|
2228
|
+
}
|
|
2229
|
+
const verifier = generateVerifier(length);
|
|
2230
|
+
const challenge = await generateChallenge(verifier, "S256");
|
|
2231
|
+
return {
|
|
2232
|
+
verifier,
|
|
2233
|
+
challenge,
|
|
2234
|
+
method: "S256"
|
|
2235
|
+
};
|
|
2236
|
+
}
|
|
2237
|
+
|
|
2238
|
+
// src/constants.ts
|
|
2239
|
+
var ANTIGRAVITY_CLIENT_ID = "1071006060591-tmhssin2h21lcre235vtolojh4g403ep.apps.googleusercontent.com";
|
|
2240
|
+
var ANTIGRAVITY_CLIENT_SECRET = "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";
|
|
2241
|
+
var ANTIGRAVITY_SCOPES = [
|
|
2242
|
+
"https://www.googleapis.com/auth/cloud-platform",
|
|
2243
|
+
"https://www.googleapis.com/auth/userinfo.email",
|
|
2244
|
+
"https://www.googleapis.com/auth/userinfo.profile",
|
|
2245
|
+
"https://www.googleapis.com/auth/cclog",
|
|
2246
|
+
"https://www.googleapis.com/auth/experimentsandconfigs"
|
|
2247
|
+
];
|
|
2248
|
+
var ANTIGRAVITY_REDIRECT_URI = "http://localhost:51121/oauth-callback";
|
|
2249
|
+
var ANTIGRAVITY_ENDPOINT_DAILY = "https://daily-cloudcode-pa.sandbox.googleapis.com";
|
|
2250
|
+
var ANTIGRAVITY_ENDPOINT_AUTOPUSH = "https://autopush-cloudcode-pa.sandbox.googleapis.com";
|
|
2251
|
+
var ANTIGRAVITY_ENDPOINT_PROD = "https://cloudcode-pa.googleapis.com";
|
|
2252
|
+
var ANTIGRAVITY_ENDPOINT_FALLBACKS = [
|
|
2253
|
+
ANTIGRAVITY_ENDPOINT_PROD,
|
|
2254
|
+
ANTIGRAVITY_ENDPOINT_DAILY,
|
|
2255
|
+
ANTIGRAVITY_ENDPOINT_AUTOPUSH
|
|
2256
|
+
];
|
|
2257
|
+
var ANTIGRAVITY_LOAD_ENDPOINTS = [
|
|
2258
|
+
ANTIGRAVITY_ENDPOINT_PROD,
|
|
2259
|
+
ANTIGRAVITY_ENDPOINT_DAILY,
|
|
2260
|
+
ANTIGRAVITY_ENDPOINT_AUTOPUSH
|
|
2261
|
+
];
|
|
2262
|
+
var ANTIGRAVITY_VERSION_FALLBACK = "1.18.3";
|
|
2263
|
+
var antigravityVersion = ANTIGRAVITY_VERSION_FALLBACK;
|
|
2264
|
+
function getAntigravityVersion() {
|
|
2265
|
+
return antigravityVersion;
|
|
2266
|
+
}
|
|
2267
|
+
var ANTIGRAVITY_VERSION = ANTIGRAVITY_VERSION_FALLBACK;
|
|
2268
|
+
function getAntigravityHeaders() {
|
|
2269
|
+
return {
|
|
2270
|
+
"User-Agent": `Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Antigravity/${getAntigravityVersion()} Chrome/138.0.7204.235 Electron/37.3.1 Safari/537.36`,
|
|
2271
|
+
"X-Goog-Api-Client": "google-cloud-sdk vscode_cloudshelleditor/0.1",
|
|
2272
|
+
"Client-Metadata": `{"ideType":"ANTIGRAVITY","platform":"${process.platform === "win32" ? "WINDOWS" : "MACOS"}","pluginType":"GEMINI"}`
|
|
2273
|
+
};
|
|
2274
|
+
}
|
|
2275
|
+
var ANTIGRAVITY_HEADERS = {
|
|
2276
|
+
"User-Agent": `Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Antigravity/${ANTIGRAVITY_VERSION} Chrome/138.0.7204.235 Electron/37.3.1 Safari/537.36`,
|
|
2277
|
+
"X-Goog-Api-Client": "google-cloud-sdk vscode_cloudshelleditor/0.1",
|
|
2278
|
+
"Client-Metadata": `{"ideType":"ANTIGRAVITY","platform":"${process.platform === "win32" ? "WINDOWS" : "MACOS"}","pluginType":"GEMINI"}`
|
|
2279
|
+
};
|
|
2280
|
+
var GEMINI_CLI_HEADERS = {
|
|
2281
|
+
"User-Agent": "google-api-nodejs-client/9.15.1",
|
|
2282
|
+
"X-Goog-Api-Client": "gl-node/22.17.0",
|
|
2283
|
+
"Client-Metadata": "ideType=IDE_UNSPECIFIED,platform=PLATFORM_UNSPECIFIED,pluginType=GEMINI"
|
|
2284
|
+
};
|
|
2285
|
+
|
|
2286
|
+
// src/plugin/debug.ts
|
|
2287
|
+
import { createWriteStream, mkdirSync as mkdirSync3, readdirSync, statSync as statSync2, unlinkSync as unlinkSync2 } from "node:fs";
|
|
2288
|
+
import { join as join4 } from "node:path";
|
|
2289
|
+
import { env } from "node:process";
|
|
2290
|
+
import { homedir as homedir2 } from "node:os";
|
|
2291
|
+
|
|
2292
|
+
// src/plugin/logging-utils.ts
|
|
2293
|
+
function isTruthyFlag(flag) {
|
|
2294
|
+
return flag === "1" || flag?.toLowerCase() === "true";
|
|
2295
|
+
}
|
|
2296
|
+
function parseDebugLevel(flag) {
|
|
2297
|
+
const trimmed = flag.trim();
|
|
2298
|
+
if (trimmed === "2" || trimmed === "verbose") return 2;
|
|
2299
|
+
if (trimmed === "1" || trimmed === "true") return 1;
|
|
2300
|
+
return 0;
|
|
2301
|
+
}
|
|
2302
|
+
function deriveDebugPolicy(input) {
|
|
2303
|
+
const envDebugFlag = input.envDebugFlag ?? "";
|
|
2304
|
+
const debugLevel = input.configDebug ? envDebugFlag === "2" || envDebugFlag === "verbose" ? 2 : 1 : parseDebugLevel(envDebugFlag);
|
|
2305
|
+
const debugEnabled = debugLevel >= 1;
|
|
2306
|
+
const verboseEnabled = debugLevel >= 2;
|
|
2307
|
+
const debugTuiEnabled = debugEnabled && (input.configDebugTui || isTruthyFlag(input.envDebugTuiFlag));
|
|
2308
|
+
return {
|
|
2309
|
+
debugLevel,
|
|
2310
|
+
debugEnabled,
|
|
2311
|
+
debugTuiEnabled,
|
|
2312
|
+
verboseEnabled
|
|
2313
|
+
};
|
|
2314
|
+
}
|
|
2315
|
+
function writeConsoleLog(level, ...args) {
|
|
2316
|
+
switch (level) {
|
|
2317
|
+
case "debug":
|
|
2318
|
+
console.debug(...args);
|
|
2319
|
+
break;
|
|
2320
|
+
case "info":
|
|
2321
|
+
console.info(...args);
|
|
2322
|
+
break;
|
|
2323
|
+
case "warn":
|
|
2324
|
+
console.warn(...args);
|
|
2325
|
+
break;
|
|
2326
|
+
case "error":
|
|
2327
|
+
console.error(...args);
|
|
2328
|
+
break;
|
|
2329
|
+
}
|
|
2330
|
+
}
|
|
2331
|
+
|
|
2332
|
+
// src/plugin/storage.ts
|
|
2333
|
+
var import_proper_lockfile = __toESM(require_proper_lockfile(), 1);
|
|
2334
|
+
var log2 = createLogger("storage");
|
|
2335
|
+
|
|
2336
|
+
// src/plugin/debug.ts
|
|
2337
|
+
var debugState = null;
|
|
2338
|
+
function getConfigDir2() {
|
|
2339
|
+
const platform = process.platform;
|
|
2340
|
+
if (platform === "win32") {
|
|
2341
|
+
return join4(env.APPDATA || join4(homedir2(), "AppData", "Roaming"), "opencode");
|
|
2342
|
+
}
|
|
2343
|
+
const xdgConfig = env.XDG_CONFIG_HOME || join4(homedir2(), ".config");
|
|
2344
|
+
return join4(xdgConfig, "opencode");
|
|
2345
|
+
}
|
|
2346
|
+
function getLogsDir(customLogDir) {
|
|
2347
|
+
const logsDir = customLogDir || join4(getConfigDir2(), "antigravity-logs");
|
|
2348
|
+
try {
|
|
2349
|
+
mkdirSync3(logsDir, { recursive: true });
|
|
2350
|
+
} catch {
|
|
2351
|
+
}
|
|
2352
|
+
return logsDir;
|
|
2353
|
+
}
|
|
2354
|
+
function createLogFilePath(customLogDir) {
|
|
2355
|
+
const logsDir = getLogsDir(customLogDir);
|
|
2356
|
+
cleanupOldLogs(logsDir, 25);
|
|
2357
|
+
const timestamp = (/* @__PURE__ */ new Date()).toISOString().replace(/[:.]/g, "-");
|
|
2358
|
+
return join4(logsDir, `antigravity-debug-${timestamp}.log`);
|
|
2359
|
+
}
|
|
2360
|
+
function cleanupOldLogs(logsDir, maxFiles) {
|
|
2361
|
+
try {
|
|
2362
|
+
const files = readdirSync(logsDir).filter((file) => file.startsWith("antigravity-debug-") && file.endsWith(".log")).map((file) => join4(logsDir, file));
|
|
2363
|
+
if (files.length <= maxFiles) {
|
|
2364
|
+
return;
|
|
2365
|
+
}
|
|
2366
|
+
const sortedFiles = files.map((file) => ({
|
|
2367
|
+
file,
|
|
2368
|
+
mtime: statSync2(file).mtimeMs
|
|
2369
|
+
})).sort((a, b) => b.mtime - a.mtime);
|
|
2370
|
+
for (let i = maxFiles; i < sortedFiles.length; i++) {
|
|
2371
|
+
try {
|
|
2372
|
+
unlinkSync2(sortedFiles[i].file);
|
|
2373
|
+
} catch {
|
|
2374
|
+
}
|
|
2375
|
+
}
|
|
2376
|
+
} catch {
|
|
2377
|
+
}
|
|
2378
|
+
}
|
|
2379
|
+
function createLogWriter(filePath) {
|
|
2380
|
+
if (!filePath) {
|
|
2381
|
+
return () => {
|
|
2382
|
+
};
|
|
2383
|
+
}
|
|
2384
|
+
try {
|
|
2385
|
+
const stream = createWriteStream(filePath, { flags: "a" });
|
|
2386
|
+
stream.on("error", () => {
|
|
2387
|
+
});
|
|
2388
|
+
return (line) => {
|
|
2389
|
+
const timestamp = (/* @__PURE__ */ new Date()).toISOString();
|
|
2390
|
+
const formatted = `[${timestamp}] ${line}`;
|
|
2391
|
+
stream.write(`${formatted}
|
|
2392
|
+
`);
|
|
2393
|
+
};
|
|
2394
|
+
} catch {
|
|
2395
|
+
return () => {
|
|
2396
|
+
};
|
|
2397
|
+
}
|
|
2398
|
+
}
|
|
2399
|
+
function getDebugState() {
|
|
2400
|
+
if (!debugState) {
|
|
2401
|
+
const { debugEnabled } = deriveDebugPolicy({
|
|
2402
|
+
configDebug: false,
|
|
2403
|
+
configDebugTui: false,
|
|
2404
|
+
envDebugFlag: env.OPENCODE_ANTIGRAVITY_DEBUG,
|
|
2405
|
+
envDebugTuiFlag: env.OPENCODE_ANTIGRAVITY_DEBUG_TUI
|
|
2406
|
+
});
|
|
2407
|
+
const debugTuiEnabled = isTruthyFlag(env.OPENCODE_ANTIGRAVITY_DEBUG_TUI);
|
|
2408
|
+
const logFilePath = debugEnabled ? createLogFilePath() : void 0;
|
|
2409
|
+
const logWriter = createLogWriter(logFilePath);
|
|
2410
|
+
debugState = {
|
|
2411
|
+
debugEnabled,
|
|
2412
|
+
debugTuiEnabled,
|
|
2413
|
+
logFilePath,
|
|
2414
|
+
logWriter
|
|
2415
|
+
};
|
|
2416
|
+
}
|
|
2417
|
+
return debugState;
|
|
2418
|
+
}
|
|
2419
|
+
function isDebugTuiEnabled() {
|
|
2420
|
+
return getDebugState().debugTuiEnabled;
|
|
2421
|
+
}
|
|
2422
|
+
|
|
2423
|
+
// src/plugin/logger.ts
|
|
2424
|
+
var ENV_CONSOLE_LOG = "OPENCODE_ANTIGRAVITY_CONSOLE_LOG";
|
|
2425
|
+
var _client = null;
|
|
2426
|
+
function isConsoleLogEnabled() {
|
|
2427
|
+
return isTruthyFlag(process.env[ENV_CONSOLE_LOG]);
|
|
2428
|
+
}
|
|
2429
|
+
function createLogger(module) {
|
|
2430
|
+
const service = `antigravity.${module}`;
|
|
2431
|
+
const log4 = (level, message, extra) => {
|
|
2432
|
+
if (isDebugTuiEnabled()) {
|
|
2433
|
+
const app = _client?.app;
|
|
2434
|
+
if (app && typeof app.log === "function") {
|
|
2435
|
+
app.log({
|
|
2436
|
+
body: { service, level, message, extra }
|
|
2437
|
+
}).catch(() => {
|
|
2438
|
+
});
|
|
2439
|
+
}
|
|
2440
|
+
}
|
|
2441
|
+
if (isConsoleLogEnabled()) {
|
|
2442
|
+
const prefix = `[${service}]`;
|
|
2443
|
+
const args = extra ? [prefix, message, extra] : [prefix, message];
|
|
2444
|
+
writeConsoleLog(level, ...args);
|
|
2445
|
+
}
|
|
2446
|
+
};
|
|
2447
|
+
return {
|
|
2448
|
+
debug: (message, extra) => log4("debug", message, extra),
|
|
2449
|
+
info: (message, extra) => log4("info", message, extra),
|
|
2450
|
+
warn: (message, extra) => log4("warn", message, extra),
|
|
2451
|
+
error: (message, extra) => log4("error", message, extra)
|
|
2452
|
+
};
|
|
2453
|
+
}
|
|
2454
|
+
|
|
2455
|
+
// src/plugin/auth.ts
|
|
2456
|
+
var ACCESS_TOKEN_EXPIRY_BUFFER_MS2 = 60 * 1e3;
|
|
2457
|
+
function parseRefreshParts(refresh) {
|
|
2458
|
+
const [refreshToken = "", projectId = "", managedProjectId = ""] = (refresh ?? "").split("|");
|
|
2459
|
+
return {
|
|
2460
|
+
refreshToken,
|
|
2461
|
+
projectId: projectId || void 0,
|
|
2462
|
+
managedProjectId: managedProjectId || void 0
|
|
2463
|
+
};
|
|
2464
|
+
}
|
|
2465
|
+
function calculateTokenExpiry2(requestTimeMs, expiresInSeconds) {
|
|
2466
|
+
const seconds = typeof expiresInSeconds === "number" ? expiresInSeconds : 3600;
|
|
2467
|
+
if (isNaN(seconds) || seconds <= 0) {
|
|
2468
|
+
return requestTimeMs;
|
|
2469
|
+
}
|
|
2470
|
+
return requestTimeMs + seconds * 1e3;
|
|
2471
|
+
}
|
|
2472
|
+
|
|
2473
|
+
// src/antigravity/oauth.ts
|
|
2474
|
+
var log3 = createLogger("oauth");
|
|
2475
|
+
function encodeState(payload) {
|
|
2476
|
+
return Buffer.from(JSON.stringify(payload), "utf8").toString("base64url");
|
|
2477
|
+
}
|
|
2478
|
+
function decodeState(state) {
|
|
2479
|
+
const normalized = state.replace(/-/g, "+").replace(/_/g, "/");
|
|
2480
|
+
const padded = normalized.padEnd(normalized.length + (4 - normalized.length % 4) % 4, "=");
|
|
2481
|
+
const json = Buffer.from(padded, "base64").toString("utf8");
|
|
2482
|
+
const parsed = JSON.parse(json);
|
|
2483
|
+
if (typeof parsed.verifier !== "string") {
|
|
2484
|
+
throw new Error("Missing PKCE verifier in state");
|
|
2485
|
+
}
|
|
2486
|
+
return {
|
|
2487
|
+
verifier: parsed.verifier,
|
|
2488
|
+
projectId: typeof parsed.projectId === "string" ? parsed.projectId : ""
|
|
2489
|
+
};
|
|
2490
|
+
}
|
|
2491
|
+
async function authorizeAntigravity(projectId = "") {
|
|
2492
|
+
const pkce = await generatePKCE();
|
|
2493
|
+
const url = new URL("https://accounts.google.com/o/oauth2/v2/auth");
|
|
2494
|
+
url.searchParams.set("client_id", ANTIGRAVITY_CLIENT_ID);
|
|
2495
|
+
url.searchParams.set("response_type", "code");
|
|
2496
|
+
url.searchParams.set("redirect_uri", ANTIGRAVITY_REDIRECT_URI);
|
|
2497
|
+
url.searchParams.set("scope", ANTIGRAVITY_SCOPES.join(" "));
|
|
2498
|
+
url.searchParams.set("code_challenge", pkce.challenge);
|
|
2499
|
+
url.searchParams.set("code_challenge_method", "S256");
|
|
2500
|
+
url.searchParams.set(
|
|
2501
|
+
"state",
|
|
2502
|
+
encodeState({ verifier: pkce.verifier, projectId: projectId || "" })
|
|
2503
|
+
);
|
|
2504
|
+
url.searchParams.set("access_type", "offline");
|
|
2505
|
+
url.searchParams.set("prompt", "consent");
|
|
2506
|
+
return {
|
|
2507
|
+
url: url.toString(),
|
|
2508
|
+
verifier: pkce.verifier,
|
|
2509
|
+
projectId: projectId || ""
|
|
2510
|
+
};
|
|
2511
|
+
}
|
|
2512
|
+
var FETCH_TIMEOUT_MS = 1e4;
|
|
2513
|
+
async function fetchWithTimeout(url, options, timeoutMs = FETCH_TIMEOUT_MS) {
|
|
2514
|
+
const controller = new AbortController();
|
|
2515
|
+
const timeout = setTimeout(() => controller.abort(), timeoutMs);
|
|
2516
|
+
try {
|
|
2517
|
+
return await fetch(url, { ...options, signal: controller.signal });
|
|
2518
|
+
} finally {
|
|
2519
|
+
clearTimeout(timeout);
|
|
2520
|
+
}
|
|
2521
|
+
}
|
|
2522
|
+
async function fetchProjectID(accessToken, proxy) {
|
|
2523
|
+
const errors = [];
|
|
2524
|
+
const loadHeaders = {
|
|
2525
|
+
Authorization: `Bearer ${accessToken}`,
|
|
2526
|
+
"Content-Type": "application/json",
|
|
2527
|
+
"User-Agent": GEMINI_CLI_HEADERS["User-Agent"],
|
|
2528
|
+
"Client-Metadata": getAntigravityHeaders()["Client-Metadata"]
|
|
2529
|
+
};
|
|
2530
|
+
const loadEndpoints = Array.from(
|
|
2531
|
+
/* @__PURE__ */ new Set([...ANTIGRAVITY_LOAD_ENDPOINTS, ...ANTIGRAVITY_ENDPOINT_FALLBACKS])
|
|
2532
|
+
);
|
|
2533
|
+
for (const baseEndpoint of loadEndpoints) {
|
|
2534
|
+
try {
|
|
2535
|
+
const url = `${baseEndpoint}/v1internal:loadCodeAssist`;
|
|
2536
|
+
const response = await fetchWithTimeout(url, {
|
|
2537
|
+
method: "POST",
|
|
2538
|
+
headers: loadHeaders,
|
|
2539
|
+
proxy,
|
|
2540
|
+
body: JSON.stringify({
|
|
2541
|
+
metadata: {
|
|
2542
|
+
ideType: "ANTIGRAVITY",
|
|
2543
|
+
platform: process.platform === "win32" ? "WINDOWS" : "MACOS",
|
|
2544
|
+
pluginType: "GEMINI"
|
|
2545
|
+
}
|
|
2546
|
+
})
|
|
2547
|
+
});
|
|
2548
|
+
if (!response.ok) {
|
|
2549
|
+
const message = await response.text().catch(() => "");
|
|
2550
|
+
errors.push(
|
|
2551
|
+
`loadCodeAssist ${response.status} at ${baseEndpoint}${message ? `: ${message}` : ""}`
|
|
2552
|
+
);
|
|
2553
|
+
continue;
|
|
2554
|
+
}
|
|
2555
|
+
const data = await response.json();
|
|
2556
|
+
if (typeof data.cloudaicompanionProject === "string" && data.cloudaicompanionProject) {
|
|
2557
|
+
return data.cloudaicompanionProject;
|
|
2558
|
+
}
|
|
2559
|
+
if (data.cloudaicompanionProject && typeof data.cloudaicompanionProject.id === "string" && data.cloudaicompanionProject.id) {
|
|
2560
|
+
return data.cloudaicompanionProject.id;
|
|
2561
|
+
}
|
|
2562
|
+
errors.push(`loadCodeAssist missing project id at ${baseEndpoint}`);
|
|
2563
|
+
} catch (e) {
|
|
2564
|
+
errors.push(
|
|
2565
|
+
`loadCodeAssist error at ${baseEndpoint}: ${e instanceof Error ? e.message : String(e)}`
|
|
2566
|
+
);
|
|
2567
|
+
}
|
|
2568
|
+
}
|
|
2569
|
+
if (errors.length) {
|
|
2570
|
+
log3.warn("Failed to resolve Antigravity project via loadCodeAssist", { errors: errors.join("; ") });
|
|
2571
|
+
}
|
|
2572
|
+
return "";
|
|
2573
|
+
}
|
|
2574
|
+
async function exchangeAntigravity(code, state, options = {}) {
|
|
2575
|
+
const proxy = options.proxy;
|
|
2576
|
+
try {
|
|
2577
|
+
const { verifier, projectId } = decodeState(state);
|
|
2578
|
+
const startTime = Date.now();
|
|
2579
|
+
const tokenResponse = await fetch("https://oauth2.googleapis.com/token", {
|
|
2580
|
+
method: "POST",
|
|
2581
|
+
proxy,
|
|
2582
|
+
headers: {
|
|
2583
|
+
"Content-Type": "application/x-www-form-urlencoded;charset=UTF-8",
|
|
2584
|
+
"Accept": "*/*",
|
|
2585
|
+
"Accept-Encoding": "gzip, deflate, br",
|
|
2586
|
+
"User-Agent": GEMINI_CLI_HEADERS["User-Agent"]
|
|
2587
|
+
},
|
|
2588
|
+
body: new URLSearchParams({
|
|
2589
|
+
client_id: ANTIGRAVITY_CLIENT_ID,
|
|
2590
|
+
client_secret: ANTIGRAVITY_CLIENT_SECRET,
|
|
2591
|
+
code,
|
|
2592
|
+
grant_type: "authorization_code",
|
|
2593
|
+
redirect_uri: ANTIGRAVITY_REDIRECT_URI,
|
|
2594
|
+
code_verifier: verifier
|
|
2595
|
+
})
|
|
2596
|
+
});
|
|
2597
|
+
if (!tokenResponse.ok) {
|
|
2598
|
+
const errorText = await tokenResponse.text();
|
|
2599
|
+
return { type: "failed", error: errorText };
|
|
2600
|
+
}
|
|
2601
|
+
const tokenPayload = await tokenResponse.json();
|
|
2602
|
+
const userInfoResponse = await fetch(
|
|
2603
|
+
"https://www.googleapis.com/oauth2/v1/userinfo?alt=json",
|
|
2604
|
+
{
|
|
2605
|
+
proxy,
|
|
2606
|
+
headers: {
|
|
2607
|
+
Authorization: `Bearer ${tokenPayload.access_token}`,
|
|
2608
|
+
"User-Agent": GEMINI_CLI_HEADERS["User-Agent"]
|
|
2609
|
+
}
|
|
2610
|
+
}
|
|
2611
|
+
);
|
|
2612
|
+
const userInfo = userInfoResponse.ok ? await userInfoResponse.json() : {};
|
|
2613
|
+
const refreshToken = tokenPayload.refresh_token;
|
|
2614
|
+
if (!refreshToken) {
|
|
2615
|
+
return { type: "failed", error: "Missing refresh token in response" };
|
|
2616
|
+
}
|
|
2617
|
+
let effectiveProjectId = projectId;
|
|
2618
|
+
if (!effectiveProjectId) {
|
|
2619
|
+
effectiveProjectId = await fetchProjectID(tokenPayload.access_token, proxy);
|
|
2620
|
+
}
|
|
2621
|
+
const storedRefresh = `${refreshToken}|${effectiveProjectId || ""}`;
|
|
2622
|
+
return {
|
|
2623
|
+
type: "success",
|
|
2624
|
+
refresh: storedRefresh,
|
|
2625
|
+
access: tokenPayload.access_token,
|
|
2626
|
+
expires: calculateTokenExpiry2(startTime, tokenPayload.expires_in),
|
|
2627
|
+
email: userInfo.email,
|
|
2628
|
+
projectId: effectiveProjectId || ""
|
|
2629
|
+
};
|
|
2630
|
+
} catch (error) {
|
|
2631
|
+
return {
|
|
2632
|
+
type: "failed",
|
|
2633
|
+
error: error instanceof Error ? error.message : "Unknown error"
|
|
2634
|
+
};
|
|
2635
|
+
}
|
|
2636
|
+
}
|
|
2637
|
+
|
|
2638
|
+
// src/plugin/fingerprint.ts
|
|
2639
|
+
import * as crypto2 from "node:crypto";
|
|
2640
|
+
var OS_VERSIONS = {
|
|
2641
|
+
darwin: ["10.15.7", "11.6.8", "12.6.3", "13.5.2", "14.2.1", "14.5"],
|
|
2642
|
+
win32: ["10.0.19041", "10.0.19042", "10.0.19043", "10.0.22000", "10.0.22621", "10.0.22631"],
|
|
2643
|
+
linux: ["5.15.0", "5.19.0", "6.1.0", "6.2.0", "6.5.0", "6.6.0"]
|
|
2644
|
+
};
|
|
2645
|
+
var ARCHITECTURES = ["x64", "arm64"];
|
|
2646
|
+
var IDE_TYPES = [
|
|
2647
|
+
"ANTIGRAVITY"
|
|
2648
|
+
];
|
|
2649
|
+
var SDK_CLIENTS = [
|
|
2650
|
+
"google-cloud-sdk vscode_cloudshelleditor/0.1",
|
|
2651
|
+
"google-cloud-sdk vscode/1.86.0",
|
|
2652
|
+
"google-cloud-sdk vscode/1.87.0",
|
|
2653
|
+
"google-cloud-sdk vscode/1.96.0"
|
|
2654
|
+
];
|
|
2655
|
+
var PLATFORM_CHOICES = ["darwin", "win32"];
|
|
2656
|
+
function randomFrom(arr) {
|
|
2657
|
+
return arr[Math.floor(Math.random() * arr.length)];
|
|
2658
|
+
}
|
|
2659
|
+
function platformToDisplayName(platform) {
|
|
2660
|
+
return platform === "win32" ? "WINDOWS" : "MACOS";
|
|
2661
|
+
}
|
|
2662
|
+
function generateDeviceId() {
|
|
2663
|
+
return crypto2.randomUUID();
|
|
2664
|
+
}
|
|
2665
|
+
function generateSessionToken() {
|
|
2666
|
+
return crypto2.randomBytes(16).toString("hex");
|
|
2667
|
+
}
|
|
2668
|
+
function generateFingerprint() {
|
|
2669
|
+
const platform = randomFrom(PLATFORM_CHOICES);
|
|
2670
|
+
const arch = randomFrom(ARCHITECTURES);
|
|
2671
|
+
const osVersion = randomFrom(OS_VERSIONS[platform] ?? OS_VERSIONS.darwin);
|
|
2672
|
+
return {
|
|
2673
|
+
deviceId: generateDeviceId(),
|
|
2674
|
+
sessionToken: generateSessionToken(),
|
|
2675
|
+
userAgent: `antigravity/${getAntigravityVersion()} ${platform}/${arch}`,
|
|
2676
|
+
apiClient: randomFrom(SDK_CLIENTS),
|
|
2677
|
+
clientMetadata: {
|
|
2678
|
+
ideType: randomFrom(IDE_TYPES),
|
|
2679
|
+
platform: platformToDisplayName(platform),
|
|
2680
|
+
pluginType: "GEMINI"
|
|
2681
|
+
},
|
|
2682
|
+
createdAt: Date.now()
|
|
2683
|
+
};
|
|
2684
|
+
}
|
|
2685
|
+
|
|
2686
|
+
// src/driver/login.ts
|
|
2687
|
+
var PROVIDER_ID = "antigravity";
|
|
2688
|
+
var LOGIN_TIMEOUT_MS = 5 * 60 * 1e3;
|
|
2689
|
+
function dbg(message) {
|
|
2690
|
+
try {
|
|
2691
|
+
const base = process.env.XDG_CONFIG_HOME || join5(homedir3(), ".config");
|
|
2692
|
+
appendFileSync(join5(base, "opencode", "antigravity-login.log"), "[" + (/* @__PURE__ */ new Date()).toISOString() + "] " + message + "\n");
|
|
2693
|
+
} catch {
|
|
2694
|
+
}
|
|
2695
|
+
}
|
|
2696
|
+
function isConnectError(message) {
|
|
2697
|
+
return /unable to connect|failed to connect|could not connect|fetch failed|ECONNREFUSED|ECONNRESET|ETIMEDOUT|ENOTFOUND|EHOSTUNREACH|EAI_AGAIN|socket|proxy|tunnel|network/i.test(String(message || ""));
|
|
2698
|
+
}
|
|
2699
|
+
function parsePastedCallback(input) {
|
|
2700
|
+
const text = (input || "").trim();
|
|
2701
|
+
if (!text) return null;
|
|
2702
|
+
const codeMatch = text.match(/[?&]code=([^&\s]+)/);
|
|
2703
|
+
if (codeMatch) {
|
|
2704
|
+
const stateMatch = text.match(/[?&]state=([^&\s]+)/);
|
|
2705
|
+
return { code: decodeURIComponent(codeMatch[1]), state: stateMatch ? decodeURIComponent(stateMatch[1]) : null };
|
|
2706
|
+
}
|
|
2707
|
+
return { code: text, state: null };
|
|
2708
|
+
}
|
|
2709
|
+
function tryOpenBrowser(url) {
|
|
2710
|
+
try {
|
|
2711
|
+
const platform = process.platform;
|
|
2712
|
+
const command = platform === "win32" ? "cmd" : platform === "darwin" ? "open" : "xdg-open";
|
|
2713
|
+
const args = platform === "win32" ? ["/c", "start", "", url] : [url];
|
|
2714
|
+
const child = spawn(command, args, { detached: true, stdio: "ignore" });
|
|
2715
|
+
child.on("error", () => {
|
|
2716
|
+
});
|
|
2717
|
+
child.unref();
|
|
2718
|
+
} catch {
|
|
2719
|
+
}
|
|
2720
|
+
}
|
|
2721
|
+
function toCoreAccount(result) {
|
|
2722
|
+
const parts = parseRefreshParts(result.refresh);
|
|
2723
|
+
const account = {
|
|
2724
|
+
id: result.email || parts.refreshToken.slice(0, 16),
|
|
2725
|
+
email: result.email,
|
|
2726
|
+
refresh: parts.refreshToken,
|
|
2727
|
+
access: result.access,
|
|
2728
|
+
expires: result.expires,
|
|
2729
|
+
addedAt: Date.now(),
|
|
2730
|
+
lastUsed: 0,
|
|
2731
|
+
enabled: true,
|
|
2732
|
+
rateLimitResetTimes: {},
|
|
2733
|
+
meta: { projectId: result.projectId || parts.projectId, managedProjectId: parts.managedProjectId }
|
|
2734
|
+
};
|
|
2735
|
+
try {
|
|
2736
|
+
account.meta.fingerprint = generateFingerprint();
|
|
2737
|
+
} catch {
|
|
2738
|
+
}
|
|
2739
|
+
return account;
|
|
2740
|
+
}
|
|
2741
|
+
async function loginFlow() {
|
|
2742
|
+
const proxy = proxyManager.pickForLogin();
|
|
2743
|
+
const authorization = await authorizeAntigravity();
|
|
2744
|
+
const listener = await startOAuthListener(ANTIGRAVITY_REDIRECT_URI, { timeoutMs: LOGIN_TIMEOUT_MS });
|
|
2745
|
+
let settled = false;
|
|
2746
|
+
const closeListener = () => {
|
|
2747
|
+
try {
|
|
2748
|
+
listener.close();
|
|
2749
|
+
} catch {
|
|
2750
|
+
}
|
|
2751
|
+
};
|
|
2752
|
+
const finish = async (cb) => {
|
|
2753
|
+
if (settled) return null;
|
|
2754
|
+
if (!cb || !cb.code) {
|
|
2755
|
+
dbg("finish: no code -> returning null");
|
|
2756
|
+
return null;
|
|
2757
|
+
}
|
|
2758
|
+
settled = true;
|
|
2759
|
+
try {
|
|
2760
|
+
const state = cb.state || encodeState({ verifier: authorization.verifier, projectId: authorization.projectId });
|
|
2761
|
+
let boundProxy = proxy;
|
|
2762
|
+
let result = await exchangeAntigravity(cb.code, state, { proxy });
|
|
2763
|
+
if (result.type !== "success" && proxy && isConnectError(result.error)) {
|
|
2764
|
+
dbg("finish: proxied exchange could not connect via " + proxy + " \u2014 retrying directly");
|
|
2765
|
+
process.stderr.write("antigravity: login proxy " + proxy + " unreachable \u2014 retrying token exchange without a proxy.\n");
|
|
2766
|
+
boundProxy = null;
|
|
2767
|
+
result = await exchangeAntigravity(cb.code, state, {});
|
|
2768
|
+
}
|
|
2769
|
+
dbg("finish: token exchange -> " + result.type + (result.type !== "success" ? " | error: " + (result.error || "unknown") : " | email: " + (result.email || "?")) + " | proxy=" + (boundProxy || "direct"));
|
|
2770
|
+
if (result.type !== "success") {
|
|
2771
|
+
process.stderr.write("antigravity login failed \u2014 token exchange error: " + (result.error || "unknown") + "\n");
|
|
2772
|
+
return null;
|
|
2773
|
+
}
|
|
2774
|
+
const account = toCoreAccount(result);
|
|
2775
|
+
addAccount(PROVIDER_ID, account);
|
|
2776
|
+
dbg("finish: addAccount done id=" + account.id);
|
|
2777
|
+
if (boundProxy) proxyManager.bindAccountProxy(account.id, boundProxy);
|
|
2778
|
+
return account;
|
|
2779
|
+
} catch (error) {
|
|
2780
|
+
dbg("finish: THREW " + (error && error.stack || error));
|
|
2781
|
+
throw error;
|
|
2782
|
+
} finally {
|
|
2783
|
+
closeListener();
|
|
2784
|
+
}
|
|
2785
|
+
};
|
|
2786
|
+
return {
|
|
2787
|
+
url: authorization.url,
|
|
2788
|
+
instructions: "Sign in with Google \u2014 approve in your browser and we'll detect it automatically. In a container the localhost redirect won't load, so copy the full URL from your address bar (or just the code) and paste it here instead.",
|
|
2789
|
+
// paste fallback: opencode's "code" method + the in-tab paste both pass text
|
|
2790
|
+
complete: (input) => finish(parsePastedCallback(input)),
|
|
2791
|
+
// primary: the loopback listener fires when the browser reaches our localhost
|
|
2792
|
+
loopback: listener.waitForCallback().then((url) => {
|
|
2793
|
+
dbg("loopback: listener fired");
|
|
2794
|
+
return finish({ code: url.searchParams.get("code"), state: url.searchParams.get("state") });
|
|
2795
|
+
}).catch((e) => {
|
|
2796
|
+
dbg("loopback: listener rejected/closed: " + (e && e.message || e));
|
|
2797
|
+
return null;
|
|
2798
|
+
}),
|
|
2799
|
+
cancel: closeListener
|
|
2800
|
+
};
|
|
2801
|
+
}
|
|
2802
|
+
async function login(opts) {
|
|
2803
|
+
const log4 = opts && opts.log || ((message) => process.stderr.write(message + "\n"));
|
|
2804
|
+
const flow = await loginFlow();
|
|
2805
|
+
log4("Open this URL in your browser to sign in with Google:\n\n " + flow.url + "\n\nApprove in your browser \u2014 we'll detect it automatically. In a container the localhost page won't load; copy the full URL from your address bar and paste it below.\n");
|
|
2806
|
+
tryOpenBrowser(flow.url);
|
|
2807
|
+
let account = null;
|
|
2808
|
+
if (isTTY()) {
|
|
2809
|
+
const rl = createInterface3({ input: process.stdin, output: process.stdout });
|
|
2810
|
+
const pasteP = rl.question("Paste the full redirect URL from your browser (or just the code), then Enter: ").then((a) => flow.complete(a)).catch(() => null);
|
|
2811
|
+
account = await Promise.race([flow.loopback, pasteP]);
|
|
2812
|
+
try {
|
|
2813
|
+
rl.close();
|
|
2814
|
+
} catch {
|
|
2815
|
+
}
|
|
2816
|
+
} else {
|
|
2817
|
+
account = await flow.loopback;
|
|
2818
|
+
}
|
|
2819
|
+
try {
|
|
2820
|
+
flow.cancel();
|
|
2821
|
+
} catch {
|
|
2822
|
+
}
|
|
2823
|
+
if (!account) throw new Error("login failed");
|
|
2824
|
+
log4("Logged in" + (account.email ? " as " + account.email : "") + " and saved to the antigravity account pool.");
|
|
2825
|
+
return account;
|
|
2826
|
+
}
|
|
2827
|
+
|
|
2828
|
+
// src/cli.ts
|
|
2829
|
+
var PROVIDER_ID2 = "antigravity";
|
|
2830
|
+
function printUsage() {
|
|
2831
|
+
process.stderr.write("usage: antigravity <login|list|remove <email>>\n");
|
|
2832
|
+
}
|
|
2833
|
+
async function main() {
|
|
2834
|
+
const [command, argument] = process.argv.slice(2);
|
|
2835
|
+
switch (command) {
|
|
2836
|
+
case "login":
|
|
2837
|
+
await login({ log: (message) => process.stdout.write(message + "\n") });
|
|
2838
|
+
return;
|
|
2839
|
+
case "list": {
|
|
2840
|
+
const accounts = listAccounts(PROVIDER_ID2);
|
|
2841
|
+
if (accounts.length === 0) {
|
|
2842
|
+
process.stdout.write("No antigravity accounts. Run `antigravity login`.\n");
|
|
2843
|
+
return;
|
|
2844
|
+
}
|
|
2845
|
+
for (const account of accounts) {
|
|
2846
|
+
const state = account.enabled === false ? " (disabled)" : "";
|
|
2847
|
+
process.stdout.write("- " + (account.email || account.id) + state + "\n");
|
|
2848
|
+
}
|
|
2849
|
+
return;
|
|
2850
|
+
}
|
|
2851
|
+
case "remove":
|
|
2852
|
+
if (!argument) {
|
|
2853
|
+
printUsage();
|
|
2854
|
+
process.exitCode = 1;
|
|
2855
|
+
return;
|
|
2856
|
+
}
|
|
2857
|
+
removeAccount(PROVIDER_ID2, argument);
|
|
2858
|
+
process.stdout.write("Removed " + argument + ".\n");
|
|
2859
|
+
return;
|
|
2860
|
+
default:
|
|
2861
|
+
printUsage();
|
|
2862
|
+
process.exitCode = 1;
|
|
2863
|
+
}
|
|
2864
|
+
}
|
|
2865
|
+
main().catch((error) => {
|
|
2866
|
+
process.stderr.write("Error: " + (error && error.message ? error.message : String(error)) + "\n");
|
|
2867
|
+
process.exitCode = 1;
|
|
2868
|
+
});
|