@langgenius/nodwork-linux-arm64 0.0.0-bootstrap.0 → 0.0.1-beta

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.
@@ -0,0 +1 @@
1
+ import{t as e}from"./chunk-BwDYZCav.js";import{t}from"./token-error-CxiWEZm9.js";import{t as n}from"./token-util-Cscbk5az.js";var r=e(((e,r)=>{var i=Object.defineProperty,a=Object.getOwnPropertyDescriptor,o=Object.getOwnPropertyNames,s=Object.prototype.hasOwnProperty,c=(e,t)=>{for(var n in t)i(e,n,{get:t[n],enumerable:!0})},l=(e,t,n,r)=>{if(t&&typeof t==`object`||typeof t==`function`)for(let c of o(t))!s.call(e,c)&&c!==n&&i(e,c,{get:()=>t[c],enumerable:!(r=a(t,c))||r.enumerable});return e},u=e=>l(i({},`__esModule`,{value:!0}),e),d={};c(d,{refreshToken:()=>m}),r.exports=u(d);var f=t(),p=n();async function m(){let{projectId:e,teamId:t}=(0,p.findProjectInfo)(),n=(0,p.loadToken)(e);if(!n||(0,p.isExpired)((0,p.getTokenPayload)(n.token))){let r=await(0,p.getVercelCliToken)();if(!r)throw new f.VercelOidcTokenError("Failed to refresh OIDC token: Log in to Vercel CLI and link your project with `vc link`");if(!e)throw new f.VercelOidcTokenError("Failed to refresh OIDC token: Try re-linking your project with `vc link`");if(n=await(0,p.getVercelOidcToken)(r,e,t),!n)throw new f.VercelOidcTokenError(`Failed to refresh OIDC token`);(0,p.saveToken)(n,e)}process.env.VERCEL_OIDC_TOKEN=n.token}}));export default r();export{};
@@ -0,0 +1 @@
1
+ import{t as e}from"./chunk-BwDYZCav.js";var t=e(((e,t)=>{var n=Object.defineProperty,r=Object.getOwnPropertyDescriptor,i=Object.getOwnPropertyNames,a=Object.prototype.hasOwnProperty,o=(e,t)=>{for(var r in t)n(e,r,{get:t[r],enumerable:!0})},s=(e,t,o,s)=>{if(t&&typeof t==`object`||typeof t==`function`)for(let c of i(t))!a.call(e,c)&&c!==o&&n(e,c,{get:()=>t[c],enumerable:!(s=r(t,c))||s.enumerable});return e},c=e=>s(n({},`__esModule`,{value:!0}),e),l={};o(l,{VercelOidcTokenError:()=>u}),t.exports=c(l);var u=class extends Error{constructor(e,t){super(e),this.name=`VercelOidcTokenError`,this.cause=t}toString(){return this.cause?`${this.name}: ${this.message}: ${this.cause}`:`${this.name}: ${this.message}`}}}));export{t};
@@ -0,0 +1 @@
1
+ import"./token-error-CxiWEZm9.js";import{t as e}from"./token-util-Cscbk5az.js";export default e();export{};
@@ -0,0 +1 @@
1
+ import{r as e,t}from"./chunk-BwDYZCav.js";import{t as n}from"./token-error-CxiWEZm9.js";var r=t(((t,r)=>{var i=Object.create,a=Object.defineProperty,o=Object.getOwnPropertyDescriptor,s=Object.getOwnPropertyNames,c=Object.getPrototypeOf,l=Object.prototype.hasOwnProperty,u=(e,t)=>{for(var n in t)a(e,n,{get:t[n],enumerable:!0})},d=(e,t,n,r)=>{if(t&&typeof t==`object`||typeof t==`function`)for(let i of s(t))!l.call(e,i)&&i!==n&&a(e,i,{get:()=>t[i],enumerable:!(r=o(t,i))||r.enumerable});return e},f=(e,t,n)=>(n=e==null?{}:i(c(e)),d(t||!e||!e.__esModule?a(n,`default`,{value:e,enumerable:!0}):n,e)),p=e=>d(a({},`__esModule`,{value:!0}),e),m={};u(m,{findRootDir:()=>y,getUserDataDir:()=>b}),r.exports=p(m);var h=f(e(`path`)),g=f(e(`fs`)),_=f(e(`os`)),v=n();function y(){try{let e=process.cwd();for(;e!==h.default.dirname(e);){let t=h.default.join(e,`.vercel`);if(g.default.existsSync(t))return e;e=h.default.dirname(e)}}catch{throw new v.VercelOidcTokenError(`Token refresh only supported in node server environments`)}return null}function b(){if(process.env.XDG_DATA_HOME)return process.env.XDG_DATA_HOME;switch(_.default.platform()){case`darwin`:return h.default.join(_.default.homedir(),`Library/Application Support`);case`linux`:return h.default.join(_.default.homedir(),`.local/share`);case`win32`:return process.env.LOCALAPPDATA?process.env.LOCALAPPDATA:null;default:return null}}})),i=t(((t,n)=>{var r=Object.create,i=Object.defineProperty,a=Object.getOwnPropertyDescriptor,s=Object.getOwnPropertyNames,c=Object.getPrototypeOf,l=Object.prototype.hasOwnProperty,u=(e,t)=>{for(var n in t)i(e,n,{get:t[n],enumerable:!0})},d=(e,t,n,r)=>{if(t&&typeof t==`object`||typeof t==`function`)for(let o of s(t))!l.call(e,o)&&o!==n&&i(e,o,{get:()=>t[o],enumerable:!(r=a(t,o))||r.enumerable});return e},f=(e,t,n)=>(n=e==null?{}:r(c(e)),d(t||!e||!e.__esModule?i(n,`default`,{value:e,enumerable:!0}):n,e)),p=e=>d(i({},`__esModule`,{value:!0}),e),m={};u(m,{isValidAccessToken:()=>x,readAuthConfig:()=>y,writeAuthConfig:()=>b}),n.exports=p(m);var h=f(e(`fs`)),g=f(e(`path`)),_=o();function v(){let e=(0,_.getVercelDataDir)();if(!e)throw Error(`Unable to find Vercel CLI data directory. Your platform: ${process.platform}. Supported: darwin, linux, win32.`);return g.join(e,`auth.json`)}function y(){try{let e=v();if(!h.existsSync(e))return null;let t=h.readFileSync(e,`utf8`);return t?JSON.parse(t):null}catch{return null}}function b(e){let t=v(),n=g.dirname(t);h.existsSync(n)||h.mkdirSync(n,{mode:504,recursive:!0}),h.writeFileSync(t,JSON.stringify(e,null,2),{mode:384})}function x(e){if(!e.token)return!1;if(typeof e.expiresAt!=`number`)return!0;let t=Math.floor(Date.now()/1e3);return e.expiresAt>=t}})),a=t(((t,n)=>{var r=Object.defineProperty,i=Object.getOwnPropertyDescriptor,a=Object.getOwnPropertyNames,o=Object.prototype.hasOwnProperty,s=(e,t)=>{for(var n in t)r(e,n,{get:t[n],enumerable:!0})},c=(e,t,n,s)=>{if(t&&typeof t==`object`||typeof t==`function`)for(let c of a(t))!o.call(e,c)&&c!==n&&r(e,c,{get:()=>t[c],enumerable:!(s=i(t,c))||s.enumerable});return e},l=e=>c(r({},`__esModule`,{value:!0}),e),u={};s(u,{processTokenResponse:()=>g,refreshTokenRequest:()=>h}),n.exports=l(u);var d=e(`os`);let f=`@vercel/oidc node-${process.version} ${(0,d.platform)()} (${(0,d.arch)()}) ${(0,d.hostname)()}`,p=null;async function m(){if(p)return p;let e=await fetch(`https://vercel.com/.well-known/openid-configuration`,{headers:{"user-agent":f}});if(!e.ok)throw Error(`Failed to discover OAuth endpoints`);let t=await e.json();if(!t||typeof t.token_endpoint!=`string`)throw Error(`Invalid OAuth discovery response`);let n=t.token_endpoint;return p=n,n}async function h(e){let t=await m();return await fetch(t,{method:`POST`,headers:{"Content-Type":`application/x-www-form-urlencoded`,"user-agent":f},body:new URLSearchParams({client_id:`cl_HYyOPBNtFMfHhaUn9L4QPfTZz6TP47bp`,grant_type:`refresh_token`,...e})})}async function g(e){let t=await e.json();if(!e.ok){let e=typeof t==`object`&&t&&`error`in t?String(t.error):`Token refresh failed`;return[Error(e)]}return typeof t!=`object`||!t?[Error(`Invalid token response`)]:typeof t.access_token==`string`?t.token_type===`Bearer`?typeof t.expires_in==`number`?[null,t]:[Error(`Missing expires_in in response`)]:[Error(`Invalid token_type in response`)]:[Error(`Missing access_token in response`)]}})),o=t(((t,o)=>{var s=Object.create,c=Object.defineProperty,l=Object.getOwnPropertyDescriptor,u=Object.getOwnPropertyNames,d=Object.getPrototypeOf,f=Object.prototype.hasOwnProperty,p=(e,t)=>{for(var n in t)c(e,n,{get:t[n],enumerable:!0})},m=(e,t,n,r)=>{if(t&&typeof t==`object`||typeof t==`function`)for(let i of u(t))!f.call(e,i)&&i!==n&&c(e,i,{get:()=>t[i],enumerable:!(r=l(t,i))||r.enumerable});return e},h=(e,t,n)=>(n=e==null?{}:s(d(e)),m(t||!e||!e.__esModule?c(n,`default`,{value:e,enumerable:!0}):n,e)),g=e=>m(c({},`__esModule`,{value:!0}),e),_={};p(_,{assertVercelOidcTokenResponse:()=>D,findProjectInfo:()=>O,getTokenPayload:()=>j,getVercelCliToken:()=>T,getVercelDataDir:()=>w,getVercelOidcToken:()=>E,isExpired:()=>M,loadToken:()=>A,saveToken:()=>k}),o.exports=g(_);var v=h(e(`path`)),y=h(e(`fs`)),b=n(),x=r(),S=i(),C=a();function w(){let e=(0,x.getUserDataDir)();return e?v.join(e,`com.vercel.cli`):null}async function T(){let e=(0,S.readAuthConfig)();if(!e)return null;if((0,S.isValidAccessToken)(e))return e.token||null;if(!e.refreshToken)return(0,S.writeAuthConfig)({}),null;try{let t=await(0,C.refreshTokenRequest)({refresh_token:e.refreshToken}),[n,r]=await(0,C.processTokenResponse)(t);if(n||!r)return(0,S.writeAuthConfig)({}),null;let i={token:r.access_token,expiresAt:Math.floor(Date.now()/1e3)+r.expires_in};return r.refresh_token&&(i.refreshToken=r.refresh_token),(0,S.writeAuthConfig)(i),i.token??null}catch{return(0,S.writeAuthConfig)({}),null}}async function E(e,t,n){let r=`https://api.vercel.com/v1/projects/${t}/token?source=vercel-oidc-refresh${n?`&teamId=${n}`:``}`,i=await fetch(r,{method:`POST`,headers:{Authorization:`Bearer ${e}`}});if(!i.ok)throw new b.VercelOidcTokenError(`Failed to refresh OIDC token: ${i.statusText}`);let a=await i.json();return D(a),a}function D(e){if(!e||typeof e!=`object`)throw TypeError("Vercel OIDC token is malformed. Expected an object. Please run `vc env pull` and try again");if(!(`token`in e)||typeof e.token!=`string`)throw TypeError("Vercel OIDC token is malformed. Expected a string-valued token property. Please run `vc env pull` and try again")}function O(){let e=(0,x.findRootDir)();if(!e)throw new b.VercelOidcTokenError("Unable to find project root directory. Have you linked your project with `vc link?`");let t=v.join(e,`.vercel`,`project.json`);if(!y.existsSync(t))throw new b.VercelOidcTokenError("project.json not found, have you linked your project with `vc link?`");let n=JSON.parse(y.readFileSync(t,`utf8`));if(typeof n.projectId!=`string`&&typeof n.orgId!=`string`)throw TypeError("Expected a string-valued projectId property. Try running `vc link` to re-link your project.");return{projectId:n.projectId,teamId:n.orgId}}function k(e,t){let n=(0,x.getUserDataDir)();if(!n)throw new b.VercelOidcTokenError(`Unable to find user data directory. Please reach out to Vercel support.`);let r=v.join(n,`com.vercel.token`,`${t}.json`),i=JSON.stringify(e);y.mkdirSync(v.dirname(r),{mode:504,recursive:!0}),y.writeFileSync(r,i),y.chmodSync(r,432)}function A(e){let t=(0,x.getUserDataDir)();if(!t)throw new b.VercelOidcTokenError(`Unable to find user data directory. Please reach out to Vercel support.`);let n=v.join(t,`com.vercel.token`,`${e}.json`);if(!y.existsSync(n))return null;let r=JSON.parse(y.readFileSync(n,`utf8`));return D(r),r}function j(e){let t=e.split(`.`);if(t.length!==3)throw new b.VercelOidcTokenError("Invalid token. Please run `vc env pull` and try again");let n=t[1].replace(/-/g,`+`).replace(/_/g,`/`),r=n.padEnd(n.length+(4-n.length%4)%4,`=`);return JSON.parse(Buffer.from(r,`base64`).toString(`utf8`))}function M(e){return e.exp*1e3<Date.now()}}));export{o as t};
@@ -0,0 +1,54 @@
1
+ {
2
+ "name": "echo-cli",
3
+ "type": "module",
4
+ "version": "0.0.1-beta",
5
+ "private": true,
6
+ "files": [
7
+ ".env.example",
8
+ "README.md",
9
+ "dist",
10
+ "package.json"
11
+ ],
12
+ "scripts": {
13
+ "build": "tsdown",
14
+ "build:watch": "tsdown --watch --no-clean",
15
+ "dev": "tsx ./scripts/dev-cli.ts",
16
+ "dev:build": "turbo watch build --filter=echo-cli... --ui stream --output-logs errors-only --log-prefix none",
17
+ "cli": "pnpm build && node ./dist/cli.js",
18
+ "lint": "eslint . --config eslint.config.mjs",
19
+ "lint:fix": "eslint . --config eslint.config.mjs --fix",
20
+ "package:local": "node ../../scripts/build/run-with-package-profile.mjs --profile local -- pnpm run build",
21
+ "package:test": "node ../../scripts/build/run-with-package-profile.mjs --profile test -- pnpm run build",
22
+ "package:release": "node ../../scripts/build/run-with-package-profile.mjs --profile release -- pnpm run build",
23
+ "type-check": "tsc -p tsconfig.json --noEmit",
24
+ "test": "vitest run"
25
+ },
26
+ "dependencies": {
27
+ "@echo/acp-integration": "workspace:*",
28
+ "@echo/entities": "workspace:*",
29
+ "@echo/host-runtime-core": "workspace:*",
30
+ "@echo/http-client": "workspace:*",
31
+ "@echo/i18n": "workspace:*",
32
+ "@echo/network-core": "workspace:*",
33
+ "@echo/reviews-core": "workspace:*",
34
+ "cac": "catalog:",
35
+ "dotenv": "catalog:",
36
+ "ink": "catalog:",
37
+ "node-pty": "catalog:",
38
+ "react": "catalog:",
39
+ "zod": "catalog:",
40
+ "zustand": "catalog:"
41
+ },
42
+ "devDependencies": {
43
+ "@echo/eslint-config": "workspace:*",
44
+ "@echo/tsconfig": "workspace:*",
45
+ "@types/node": "catalog:",
46
+ "@types/react": "catalog:",
47
+ "eslint": "catalog:",
48
+ "ink-testing-library": "catalog:",
49
+ "tsdown": "catalog:",
50
+ "tsx": "catalog:",
51
+ "typescript": "catalog:",
52
+ "vitest": "catalog:"
53
+ }
54
+ }
@@ -0,0 +1,69 @@
1
+ Copyright (c) 2012-2015, Christopher Jeffrey (https://github.com/chjj/)
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ of this software and associated documentation files (the "Software"), to deal
5
+ in the Software without restriction, including without limitation the rights
6
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ copies of the Software, and to permit persons to whom the Software is
8
+ furnished to do so, subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in
11
+ all copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
+ THE SOFTWARE.
20
+
21
+
22
+
23
+ The MIT License (MIT)
24
+
25
+ Copyright (c) 2016, Daniel Imms (http://www.growingwiththeweb.com)
26
+
27
+ Permission is hereby granted, free of charge, to any person obtaining a copy
28
+ of this software and associated documentation files (the "Software"), to deal
29
+ in the Software without restriction, including without limitation the rights
30
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
31
+ copies of the Software, and to permit persons to whom the Software is
32
+ furnished to do so, subject to the following conditions:
33
+
34
+ The above copyright notice and this permission notice shall be included in all
35
+ copies or substantial portions of the Software.
36
+
37
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
38
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
39
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
40
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
41
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
42
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
43
+ SOFTWARE.
44
+
45
+
46
+
47
+ MIT License
48
+
49
+ Copyright (c) 2018 - present Microsoft Corporation
50
+
51
+ All rights reserved.
52
+
53
+ Permission is hereby granted, free of charge, to any person obtaining a copy
54
+ of this software and associated documentation files (the "Software"), to deal
55
+ in the Software without restriction, including without limitation the rights
56
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
57
+ copies of the Software, and to permit persons to whom the Software is
58
+ furnished to do so, subject to the following conditions:
59
+
60
+ The above copyright notice and this permission notice shall be included in all
61
+ copies or substantial portions of the Software.
62
+
63
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
64
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
65
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
66
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
67
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
68
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
69
+ SOFTWARE.
@@ -0,0 +1,46 @@
1
+ "use strict";
2
+ /**
3
+ * Copyright (c) 2019, Microsoft Corporation (MIT License).
4
+ */
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.EventEmitter2 = void 0;
7
+ var EventEmitter2 = /** @class */ (function () {
8
+ function EventEmitter2() {
9
+ this._listeners = [];
10
+ }
11
+ Object.defineProperty(EventEmitter2.prototype, "event", {
12
+ get: function () {
13
+ var _this = this;
14
+ if (!this._event) {
15
+ this._event = function (listener) {
16
+ _this._listeners.push(listener);
17
+ var disposable = {
18
+ dispose: function () {
19
+ for (var i = 0; i < _this._listeners.length; i++) {
20
+ if (_this._listeners[i] === listener) {
21
+ _this._listeners.splice(i, 1);
22
+ return;
23
+ }
24
+ }
25
+ }
26
+ };
27
+ return disposable;
28
+ };
29
+ }
30
+ return this._event;
31
+ },
32
+ enumerable: false,
33
+ configurable: true
34
+ });
35
+ EventEmitter2.prototype.fire = function (data) {
36
+ var queue = [];
37
+ for (var i = 0; i < this._listeners.length; i++) {
38
+ queue.push(this._listeners[i]);
39
+ }
40
+ for (var i = 0; i < queue.length; i++) {
41
+ queue[i].call(undefined, data);
42
+ }
43
+ };
44
+ return EventEmitter2;
45
+ }());
46
+ exports.EventEmitter2 = EventEmitter2;
@@ -0,0 +1,51 @@
1
+ "use strict";
2
+ /**
3
+ * Copyright (c) 2012-2015, Christopher Jeffrey, Peter Sunde (MIT License)
4
+ * Copyright (c) 2016, Daniel Imms (MIT License).
5
+ * Copyright (c) 2018, Microsoft Corporation (MIT License).
6
+ */
7
+ Object.defineProperty(exports, "__esModule", { value: true });
8
+ exports.native = exports.open = exports.createTerminal = exports.fork = exports.spawn = void 0;
9
+ var utils_1 = require("./utils");
10
+ var terminalCtor;
11
+ if (process.platform === 'win32') {
12
+ terminalCtor = require('./windowsTerminal').WindowsTerminal;
13
+ }
14
+ else {
15
+ terminalCtor = require('./unixTerminal').UnixTerminal;
16
+ }
17
+ /**
18
+ * Forks a process as a pseudoterminal.
19
+ * @param file The file to launch.
20
+ * @param args The file's arguments as argv (string[]) or in a pre-escaped
21
+ * CommandLine format (string). Note that the CommandLine option is only
22
+ * available on Windows and is expected to be escaped properly.
23
+ * @param options The options of the terminal.
24
+ * @throws When the file passed to spawn with does not exists.
25
+ * @see CommandLineToArgvW https://msdn.microsoft.com/en-us/library/windows/desktop/bb776391(v=vs.85).aspx
26
+ * @see Parsing C++ Comamnd-Line Arguments https://msdn.microsoft.com/en-us/library/17w5ykft.aspx
27
+ * @see GetCommandLine https://msdn.microsoft.com/en-us/library/windows/desktop/ms683156.aspx
28
+ */
29
+ function spawn(file, args, opt) {
30
+ return new terminalCtor(file, args, opt);
31
+ }
32
+ exports.spawn = spawn;
33
+ /** @deprecated */
34
+ function fork(file, args, opt) {
35
+ return new terminalCtor(file, args, opt);
36
+ }
37
+ exports.fork = fork;
38
+ /** @deprecated */
39
+ function createTerminal(file, args, opt) {
40
+ return new terminalCtor(file, args, opt);
41
+ }
42
+ exports.createTerminal = createTerminal;
43
+ function open(options) {
44
+ return terminalCtor.open(options);
45
+ }
46
+ exports.open = open;
47
+ /**
48
+ * Expose the native API when not Windows, note that this is not public API and
49
+ * could be removed at any time.
50
+ */
51
+ exports.native = (process.platform !== 'win32' ? utils_1.loadNativeModule('pty').module : null);
@@ -0,0 +1,189 @@
1
+ "use strict";
2
+ /**
3
+ * Copyright (c) 2012-2015, Christopher Jeffrey (MIT License)
4
+ * Copyright (c) 2016, Daniel Imms (MIT License).
5
+ * Copyright (c) 2018, Microsoft Corporation (MIT License).
6
+ */
7
+ Object.defineProperty(exports, "__esModule", { value: true });
8
+ exports.Terminal = exports.DEFAULT_ROWS = exports.DEFAULT_COLS = void 0;
9
+ var events_1 = require("events");
10
+ var eventEmitter2_1 = require("./eventEmitter2");
11
+ exports.DEFAULT_COLS = 80;
12
+ exports.DEFAULT_ROWS = 24;
13
+ /**
14
+ * Default messages to indicate PAUSE/RESUME for automatic flow control.
15
+ * To avoid conflicts with rebound XON/XOFF control codes (such as on-my-zsh),
16
+ * the sequences can be customized in `IPtyForkOptions`.
17
+ */
18
+ var FLOW_CONTROL_PAUSE = '\x13'; // defaults to XOFF
19
+ var FLOW_CONTROL_RESUME = '\x11'; // defaults to XON
20
+ var Terminal = /** @class */ (function () {
21
+ function Terminal(opt) {
22
+ this._pid = 0;
23
+ this._fd = 0;
24
+ this._cols = 0;
25
+ this._rows = 0;
26
+ this._readable = false;
27
+ this._writable = false;
28
+ this._onData = new eventEmitter2_1.EventEmitter2();
29
+ this._onExit = new eventEmitter2_1.EventEmitter2();
30
+ // for 'close'
31
+ this._internalee = new events_1.EventEmitter();
32
+ // setup flow control handling
33
+ this.handleFlowControl = !!(opt === null || opt === void 0 ? void 0 : opt.handleFlowControl);
34
+ this._flowControlPause = (opt === null || opt === void 0 ? void 0 : opt.flowControlPause) || FLOW_CONTROL_PAUSE;
35
+ this._flowControlResume = (opt === null || opt === void 0 ? void 0 : opt.flowControlResume) || FLOW_CONTROL_RESUME;
36
+ if (!opt) {
37
+ return;
38
+ }
39
+ // Do basic type checks here in case node-pty is being used within JavaScript. If the wrong
40
+ // types go through to the C++ side it can lead to hard to diagnose exceptions.
41
+ this._checkType('name', opt.name ? opt.name : undefined, 'string');
42
+ this._checkType('cols', opt.cols ? opt.cols : undefined, 'number');
43
+ this._checkType('rows', opt.rows ? opt.rows : undefined, 'number');
44
+ this._checkType('cwd', opt.cwd ? opt.cwd : undefined, 'string');
45
+ this._checkType('env', opt.env ? opt.env : undefined, 'object');
46
+ this._checkType('uid', opt.uid ? opt.uid : undefined, 'number');
47
+ this._checkType('gid', opt.gid ? opt.gid : undefined, 'number');
48
+ this._checkType('encoding', opt.encoding ? opt.encoding : undefined, 'string');
49
+ }
50
+ Object.defineProperty(Terminal.prototype, "onData", {
51
+ get: function () { return this._onData.event; },
52
+ enumerable: false,
53
+ configurable: true
54
+ });
55
+ Object.defineProperty(Terminal.prototype, "onExit", {
56
+ get: function () { return this._onExit.event; },
57
+ enumerable: false,
58
+ configurable: true
59
+ });
60
+ Object.defineProperty(Terminal.prototype, "pid", {
61
+ get: function () { return this._pid; },
62
+ enumerable: false,
63
+ configurable: true
64
+ });
65
+ Object.defineProperty(Terminal.prototype, "cols", {
66
+ get: function () { return this._cols; },
67
+ enumerable: false,
68
+ configurable: true
69
+ });
70
+ Object.defineProperty(Terminal.prototype, "rows", {
71
+ get: function () { return this._rows; },
72
+ enumerable: false,
73
+ configurable: true
74
+ });
75
+ Terminal.prototype.write = function (data) {
76
+ if (this.handleFlowControl) {
77
+ // PAUSE/RESUME messages are not forwarded to the pty
78
+ if (data === this._flowControlPause) {
79
+ this.pause();
80
+ return;
81
+ }
82
+ if (data === this._flowControlResume) {
83
+ this.resume();
84
+ return;
85
+ }
86
+ }
87
+ // everything else goes to the real pty
88
+ this._write(data);
89
+ };
90
+ Terminal.prototype._forwardEvents = function () {
91
+ var _this = this;
92
+ this.on('data', function (e) { return _this._onData.fire(e); });
93
+ this.on('exit', function (exitCode, signal) { return _this._onExit.fire({ exitCode: exitCode, signal: signal }); });
94
+ };
95
+ Terminal.prototype._checkType = function (name, value, type, allowArray) {
96
+ if (allowArray === void 0) { allowArray = false; }
97
+ if (value === undefined) {
98
+ return;
99
+ }
100
+ if (allowArray) {
101
+ if (Array.isArray(value)) {
102
+ value.forEach(function (v, i) {
103
+ if (typeof v !== type) {
104
+ throw new Error(name + "[" + i + "] must be a " + type + " (not a " + typeof v[i] + ")");
105
+ }
106
+ });
107
+ return;
108
+ }
109
+ }
110
+ if (typeof value !== type) {
111
+ throw new Error(name + " must be a " + type + " (not a " + typeof value + ")");
112
+ }
113
+ };
114
+ /** See net.Socket.end */
115
+ Terminal.prototype.end = function (data) {
116
+ this._socket.end(data);
117
+ };
118
+ /** See stream.Readable.pipe */
119
+ Terminal.prototype.pipe = function (dest, options) {
120
+ return this._socket.pipe(dest, options);
121
+ };
122
+ /** See net.Socket.pause */
123
+ Terminal.prototype.pause = function () {
124
+ return this._socket.pause();
125
+ };
126
+ /** See net.Socket.resume */
127
+ Terminal.prototype.resume = function () {
128
+ return this._socket.resume();
129
+ };
130
+ /** See net.Socket.setEncoding */
131
+ Terminal.prototype.setEncoding = function (encoding) {
132
+ if (this._socket._decoder) {
133
+ delete this._socket._decoder;
134
+ }
135
+ if (encoding) {
136
+ this._socket.setEncoding(encoding);
137
+ }
138
+ };
139
+ Terminal.prototype.addListener = function (eventName, listener) { this.on(eventName, listener); };
140
+ Terminal.prototype.on = function (eventName, listener) {
141
+ if (eventName === 'close') {
142
+ this._internalee.on('close', listener);
143
+ return;
144
+ }
145
+ this._socket.on(eventName, listener);
146
+ };
147
+ Terminal.prototype.emit = function (eventName) {
148
+ var args = [];
149
+ for (var _i = 1; _i < arguments.length; _i++) {
150
+ args[_i - 1] = arguments[_i];
151
+ }
152
+ if (eventName === 'close') {
153
+ return this._internalee.emit.apply(this._internalee, arguments);
154
+ }
155
+ return this._socket.emit.apply(this._socket, arguments);
156
+ };
157
+ Terminal.prototype.listeners = function (eventName) {
158
+ return this._socket.listeners(eventName);
159
+ };
160
+ Terminal.prototype.removeListener = function (eventName, listener) {
161
+ this._socket.removeListener(eventName, listener);
162
+ };
163
+ Terminal.prototype.removeAllListeners = function (eventName) {
164
+ this._socket.removeAllListeners(eventName);
165
+ };
166
+ Terminal.prototype.once = function (eventName, listener) {
167
+ this._socket.once(eventName, listener);
168
+ };
169
+ Terminal.prototype._close = function () {
170
+ this._socket.readable = false;
171
+ this.write = function () { };
172
+ this.end = function () { };
173
+ this._writable = false;
174
+ this._readable = false;
175
+ };
176
+ Terminal.prototype._parseEnv = function (env) {
177
+ var keys = Object.keys(env || {});
178
+ var pairs = [];
179
+ for (var i = 0; i < keys.length; i++) {
180
+ if (keys[i] === undefined) {
181
+ continue;
182
+ }
183
+ pairs.push(keys[i] + '=' + env[keys[i]]);
184
+ }
185
+ return pairs;
186
+ };
187
+ return Terminal;
188
+ }());
189
+ exports.Terminal = Terminal;