Skip to content

armgit / E2B

Public Imported from GitHub
0

Open-source, secure environment with real-world tools for enterprise-grade agents.

CLI basic commands (#130)

Pavel 'Strajk' Dolecekbdb4d3575939
diff --git a/package-lock.json b/package-lock.json
index 81d654cc8..404fd7a6b 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -592,6 +592,11 @@
"node": ">=6.9.0"
}
},
+ "node_modules/@balena/dockerignore": {
+ "version": "1.0.2",
+ "resolved": "https://registry.npmjs.org/@balena/dockerignore/-/dockerignore-1.0.2.tgz",
+ "integrity": "sha512-wMue2Sy4GAVTk6Ic4tJVcnfdau+gx2EnG7S+uAEe+TWJFqE4YoWN4/H8MSLj4eYJKxGg26lZwboEniNiNwZQ6Q=="
+ },
"node_modules/@changesets/apply-release-plan": {
"version": "6.1.4",
"resolved": "https://registry.npmjs.org/@changesets/apply-release-plan/-/apply-release-plan-6.1.4.tgz",
@@ -2419,6 +2424,12 @@
"@types/chai": "*"
}
},
+ "node_modules/@types/common-tags": {
+ "version": "1.8.2",
+ "resolved": "https://registry.npmjs.org/@types/common-tags/-/common-tags-1.8.2.tgz",
+ "integrity": "sha512-Z5UcOnlqxFm0tCCTEhkcVOfSihWOMyKypIWHtQNSYh6fMdPUIVpNdLBYutDpDXVHsMUrYzI2IczUHXIzpUovmQ==",
+ "dev": true
+ },
"node_modules/@types/configstore": {
"version": "6.0.0",
"resolved": "https://registry.npmjs.org/@types/configstore/-/configstore-6.0.0.tgz",
@@ -2488,9 +2499,18 @@
"version": "20.5.2",
"resolved": "https://registry.npmjs.org/@types/node/-/node-20.5.2.tgz",
"integrity": "sha512-5j/lXt7unfPOUlrKC34HIaedONleyLtwkKggiD/0uuMfT8gg2EOpg0dz4lCD15Ga7muC+1WzJZAjIB9simWd6Q==",
- "dev": true,
"license": "MIT"
},
+ "node_modules/@types/node-fetch": {
+ "version": "2.6.5",
+ "resolved": "https://registry.npmjs.org/@types/node-fetch/-/node-fetch-2.6.5.tgz",
+ "integrity": "sha512-OZsUlr2nxvkqUFLSaY2ZbA+P1q22q+KrlxWOn/38RX+u5kTkYL2mTujEpzUhGkS+K/QCYp9oagfXG39XOzyySg==",
+ "dev": true,
+ "dependencies": {
+ "@types/node": "*",
+ "form-data": "^4.0.0"
+ }
+ },
"node_modules/@types/normalize-package-data": {
"version": "2.4.1",
"resolved": "https://registry.npmjs.org/@types/normalize-package-data/-/normalize-package-data-2.4.1.tgz",
@@ -2535,6 +2555,23 @@
"integrity": "sha512-G8hZ6XJiHnuhQKR7ZmysCeJWE08o8T0AXtk5darsCaTVsYZhhgUrq53jizaR2FvsoeCwJhlmwTjkXBY5Pn/ZHw==",
"license": "MIT"
},
+ "node_modules/@types/tar-fs": {
+ "version": "2.0.2",
+ "resolved": "https://registry.npmjs.org/@types/tar-fs/-/tar-fs-2.0.2.tgz",
+ "integrity": "sha512-XuZRAvdo7FbDfgQCNkc8NOdSae5XtG+of2mTSgJ85G4OG0miN4E8BTGT+JBTLO87RQ7iCwsIDCqCsHnf2IaSXA==",
+ "dependencies": {
+ "@types/node": "*",
+ "@types/tar-stream": "*"
+ }
+ },
+ "node_modules/@types/tar-stream": {
+ "version": "2.2.3",
+ "resolved": "https://registry.npmjs.org/@types/tar-stream/-/tar-stream-2.2.3.tgz",
+ "integrity": "sha512-if3mugZfjVkXOMZdFjIHySxY13r6GXPpyOlsDmLffvyI7tLz9wXE8BFjNivXsvUeyJ1KNlOpfLnag+ISmxgxPw==",
+ "dependencies": {
+ "@types/node": "*"
+ }
+ },
"node_modules/@types/through": {
"version": "0.0.30",
"resolved": "https://registry.npmjs.org/@types/through/-/through-0.0.30.tgz",
@@ -3286,6 +3323,12 @@
"node": ">= 14"
}
},
+ "node_modules/asynckit": {
+ "version": "0.4.0",
+ "resolved": "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz",
+ "integrity": "sha512-Oei9OH4tRh0YqU3GxhX79dM/mwVgvbZJaSNaRk+bshkj0S5cfHcgYakreBjrHwatXKbz+IoIdYLxrKim2MjW0Q==",
+ "dev": true
+ },
"node_modules/available-typed-arrays": {
"version": "1.0.5",
"resolved": "https://registry.npmjs.org/available-typed-arrays/-/available-typed-arrays-1.0.5.tgz",
@@ -3297,6 +3340,11 @@
"url": "https://github.com/sponsors/ljharb"
}
},
+ "node_modules/b4a": {
+ "version": "1.6.4",
+ "resolved": "https://registry.npmjs.org/b4a/-/b4a-1.6.4.tgz",
+ "integrity": "sha512-fpWrvyVHEKyeEvbKZTVOeZF3VSKKWtJxFIxX/jaVPf+cLbGUSitjb49pHLqPV2BUNNZ0LcoeEGfE/YCpyDYHIw=="
+ },
"node_modules/balanced-match": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.2.tgz",
@@ -4003,6 +4051,18 @@
"integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==",
"license": "MIT"
},
+ "node_modules/combined-stream": {
+ "version": "1.0.8",
+ "resolved": "https://registry.npmjs.org/combined-stream/-/combined-stream-1.0.8.tgz",
+ "integrity": "sha512-FQN4MRfuJeHf7cBbBMJFXhKSDq+2kAArBlmRBvcvFE5BB1HZKXtSFASDhdlz9zOYwxh8lDdnvmMOe/+5cdoEdg==",
+ "dev": true,
+ "dependencies": {
+ "delayed-stream": "~1.0.0"
+ },
+ "engines": {
+ "node": ">= 0.8"
+ }
+ },
"node_modules/commander": {
"version": "9.5.0",
"resolved": "https://registry.npmjs.org/commander/-/commander-9.5.0.tgz",
@@ -4012,6 +4072,14 @@
"node": "^12.20.0 || >=14"
}
},
+ "node_modules/common-tags": {
+ "version": "1.8.2",
+ "resolved": "https://registry.npmjs.org/common-tags/-/common-tags-1.8.2.tgz",
+ "integrity": "sha512-gk/Z852D2Wtb//0I+kRFNKKE9dIIVirjoqPoA1wJU+XePVXZfGeBpk45+A1rKO4Q43prqWBNY/MiIeRLbPWUaA==",
+ "engines": {
+ "node": ">=4.0.0"
+ }
+ },
"node_modules/commondir": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/commondir/-/commondir-1.0.1.tgz",
@@ -4112,6 +4180,14 @@
"resolved": "https://registry.npmjs.org/csv-stringify/-/csv-stringify-5.6.5.tgz",
"integrity": "sha512-PjiQ659aQ+fUTQqSrd1XEDnOr52jh30RBurfzkscaE2tPaFsDH5wOAHJiw8XAHphRknCwMUE9KRayc4K/NbO8A=="
},
+ "node_modules/data-uri-to-buffer": {
+ "version": "4.0.1",
+ "resolved": "https://registry.npmjs.org/data-uri-to-buffer/-/data-uri-to-buffer-4.0.1.tgz",
+ "integrity": "sha512-0R9ikRb668HB7QDxT1vkpuUBtqc53YyAwMwGeUFKRojY/NWKvdZ+9UYtRfGmhqNbRkTSVpMbmyhXipFFv2cb/A==",
+ "engines": {
+ "node": ">= 12"
+ }
+ },
"node_modules/debug": {
"version": "4.3.4",
"resolved": "https://registry.npmjs.org/debug/-/debug-4.3.4.tgz",
@@ -4244,6 +4320,15 @@
"url": "https://github.com/sponsors/ljharb"
}
},
+ "node_modules/delayed-stream": {
+ "version": "1.0.0",
+ "resolved": "https://registry.npmjs.org/delayed-stream/-/delayed-stream-1.0.0.tgz",
+ "integrity": "sha512-ZySD7Nf91aLB0RxL4KGrKHBXl7Eds1DAmEdcoVawXnLD7SDhpNgtuII2aAkg7a7QS41jxPSZ17p4VdGnMHk3MQ==",
+ "dev": true,
+ "engines": {
+ "node": ">=0.4.0"
+ }
+ },
"node_modules/detect-indent": {
"version": "6.1.0",
"resolved": "https://registry.npmjs.org/detect-indent/-/detect-indent-6.1.0.tgz",
@@ -5192,6 +5277,11 @@
"dev": true,
"license": "Apache-2.0"
},
+ "node_modules/fast-fifo": {
+ "version": "1.3.2",
+ "resolved": "https://registry.npmjs.org/fast-fifo/-/fast-fifo-1.3.2.tgz",
+ "integrity": "sha512-/d9sfos4yxzpwkDkuN7k2SqFKtYNmCTzgfEpz82x34IM9/zc8KGxQoXg1liNC/izpRM/MBdt44Nmx41ZWqk+FQ=="
+ },
"node_modules/fast-glob": {
"version": "3.3.1",
"resolved": "https://registry.npmjs.org/fast-glob/-/fast-glob-3.3.1.tgz",
@@ -5231,6 +5321,28 @@
"reusify": "^1.0.4"
}
},
+ "node_modules/fetch-blob": {
+ "version": "3.2.0",
+ "resolved": "https://registry.npmjs.org/fetch-blob/-/fetch-blob-3.2.0.tgz",
+ "integrity": "sha512-7yAQpD2UMJzLi1Dqv7qFYnPbaPx7ZfFK6PiIxQ4PfkGPyNyl2Ugx+a/umUonmKqjhM4DnfbMvdX6otXq83soQQ==",
+ "funding": [
+ {
+ "type": "github",
+ "url": "https://github.com/sponsors/jimmywarting"
+ },
+ {
+ "type": "paypal",
+ "url": "https://paypal.me/jimmywarting"
+ }
+ ],
+ "dependencies": {
+ "node-domexception": "^1.0.0",
+ "web-streams-polyfill": "^3.0.3"
+ },
+ "engines": {
+ "node": "^12.20 || >= 14.13"
+ }
+ },
"node_modules/figures": {
"version": "3.2.0",
"resolved": "https://registry.npmjs.org/figures/-/figures-3.2.0.tgz",
@@ -5343,6 +5455,31 @@
"is-callable": "^1.1.3"
}
},
+ "node_modules/form-data": {
+ "version": "4.0.0",
+ "resolved": "https://registry.npmjs.org/form-data/-/form-data-4.0.0.tgz",
+ "integrity": "sha512-ETEklSGi5t0QMZuiXoA/Q6vcnxcLQP5vdugSpuAyi6SVGi2clPPp+xgEhuMaHC+zGgn31Kd235W35f7Hykkaww==",
+ "dev": true,
+ "dependencies": {
+ "asynckit": "^0.4.0",
+ "combined-stream": "^1.0.8",
+ "mime-types": "^2.1.12"
+ },
+ "engines": {
+ "node": ">= 6"
+ }
+ },
+ "node_modules/formdata-polyfill": {
+ "version": "4.0.10",
+ "resolved": "https://registry.npmjs.org/formdata-polyfill/-/formdata-polyfill-4.0.10.tgz",
+ "integrity": "sha512-buewHzMvYL29jdeQTVILecSaZKnt/RJWjoZCF5OW60Z67/GmSLBkOFM7qh1PI3zFNtJbaZL5eQu1vLfazOwj4g==",
+ "dependencies": {
+ "fetch-blob": "^3.1.2"
+ },
+ "engines": {
+ "node": ">=12.20.0"
+ }
+ },
"node_modules/fs-extra": {
"version": "10.1.0",
"resolved": "https://registry.npmjs.org/fs-extra/-/fs-extra-10.1.0.tgz",
@@ -6314,6 +6451,31 @@
"node": ">=0.10.0"
}
},
+ "node_modules/is-wsl": {
+ "version": "2.2.0",
+ "resolved": "https://registry.npmjs.org/is-wsl/-/is-wsl-2.2.0.tgz",
+ "integrity": "sha512-fKzAra0rGJUUBwGBgNkHZuToZcn+TtXHpeCgmkMJMMYx1sQDYaCSyjJBSCa2nH1DGm7s3n1oBnohoVTBaN7Lww==",
+ "dependencies": {
+ "is-docker": "^2.0.0"
+ },
+ "engines": {
+ "node": ">=8"
+ }
+ },
+ "node_modules/is-wsl/node_modules/is-docker": {
+ "version": "2.2.1",
+ "resolved": "https://registry.npmjs.org/is-docker/-/is-docker-2.2.1.tgz",
+ "integrity": "sha512-F+i2BKsFrH66iaUFc0woD8sLy8getkwTwtOBjvs56Cx4CgJDeKQeqfz8wAYiSb8JOprWhHH5p77PbmYCvvUuXQ==",
+ "bin": {
+ "is-docker": "cli.js"
+ },
+ "engines": {
+ "node": ">=8"
+ },
+ "funding": {
+ "url": "https://github.com/sponsors/sindresorhus"
+ }
+ },
"node_modules/is-yarn-global": {
"version": "0.3.0",
"resolved": "https://registry.npmjs.org/is-yarn-global/-/is-yarn-global-0.3.0.tgz",
@@ -6828,6 +6990,27 @@
"node": ">=10.0.0"
}
},
+ "node_modules/mime-db": {
+ "version": "1.52.0",
+ "resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.52.0.tgz",
+ "integrity": "sha512-sPU4uV7dYlvtWJxwwxHD0PuihVNiE7TyAbQ5SWxDCB9mUYvOgroQOwYQQOKPJ8CIbE+1ETVlOoK1UC2nU3gYvg==",
+ "dev": true,
+ "engines": {
+ "node": ">= 0.6"
+ }
+ },
+ "node_modules/mime-types": {
+ "version": "2.1.35",
+ "resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.35.tgz",
+ "integrity": "sha512-ZDY+bPm5zTTF+YpCrAU9nK0UgICYPT0QtT1NZWFv4s++TNkcgVaT0g6+4R2uI4MjQjzysHB1zxuWL50hzaeXiw==",
+ "dev": true,
+ "dependencies": {
+ "mime-db": "1.52.0"
+ },
+ "engines": {
+ "node": ">= 0.6"
+ }
+ },
"node_modules/mimic-fn": {
"version": "2.1.0",
"resolved": "https://registry.npmjs.org/mimic-fn/-/mimic-fn-2.1.0.tgz",
@@ -6905,6 +7088,11 @@
"node": ">= 8.0.0"
}
},
+ "node_modules/mkdirp-classic": {
+ "version": "0.5.3",
+ "resolved": "https://registry.npmjs.org/mkdirp-classic/-/mkdirp-classic-0.5.3.tgz",
+ "integrity": "sha512-gKLcREMhtuZRwRAfqP3RFW+TK4JqApVBtOIftVgjuABpAtpxhPGaDcfvbhNvD0B8iD1oUr/txX35NjcaY6Ns/A=="
+ },
"node_modules/mlly": {
"version": "1.4.1",
"resolved": "https://registry.npmjs.org/mlly/-/mlly-1.4.1.tgz",
@@ -6981,6 +7169,24 @@
"dev": true,
"license": "MIT"
},
+ "node_modules/node-domexception": {
+ "version": "1.0.0",
+ "resolved": "https://registry.npmjs.org/node-domexception/-/node-domexception-1.0.0.tgz",
+ "integrity": "sha512-/jKZoMpw0F8GRwl4/eLROPA3cfcXtLApP0QzLmUT/HuPCZWyB7IY9ZrMeKw2O/nFIqPQB3PVM9aYm0F312AXDQ==",
+ "funding": [
+ {
+ "type": "github",
+ "url": "https://github.com/sponsors/jimmywarting"
+ },
+ {
+ "type": "github",
+ "url": "https://paypal.me/jimmywarting"
+ }
+ ],
+ "engines": {
+ "node": ">=10.5.0"
+ }
+ },
"node_modules/node-fetch": {
"version": "2.6.13",
"resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.13.tgz",
@@ -7732,6 +7938,11 @@
],
"license": "MIT"
},
+ "node_modules/queue-tick": {
+ "version": "1.0.1",
+ "resolved": "https://registry.npmjs.org/queue-tick/-/queue-tick-1.0.1.tgz",
+ "integrity": "sha512-kJt5qhMxoszgU/62PLP1CJytzd2NKetjSRnyuj31fDd3Rlcz3fzlFdFLD1SItunPwyqEOkca6GbV612BWfaBag=="
+ },
"node_modules/quick-lru": {
"version": "4.0.1",
"resolved": "https://registry.npmjs.org/quick-lru/-/quick-lru-4.0.1.tgz",
@@ -8769,6 +8980,15 @@
"node": ">=10.0.0"
}
},
+ "node_modules/streamx": {
+ "version": "2.15.1",
+ "resolved": "https://registry.npmjs.org/streamx/-/streamx-2.15.1.tgz",
+ "integrity": "sha512-fQMzy2O/Q47rgwErk/eGeLu/roaFWV0jVsogDmrszM9uIw8L5OA+t+V93MgYlufNptfjmYR1tOMWhei/Eh7TQA==",
+ "dependencies": {
+ "fast-fifo": "^1.1.0",
+ "queue-tick": "^1.0.1"
+ }
+ },
"node_modules/string_decoder": {
"version": "1.3.0",
"resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-1.3.0.tgz",
@@ -8958,6 +9178,26 @@
"url": "https://github.com/sponsors/ljharb"
}
},
+ "node_modules/tar-fs": {
+ "version": "3.0.4",
+ "resolved": "https://registry.npmjs.org/tar-fs/-/tar-fs-3.0.4.tgz",
+ "integrity": "sha512-5AFQU8b9qLfZCX9zp2duONhPmZv0hGYiBPJsyUdqMjzq/mqVpy/rEUSeHk1+YitmxugaptgBh5oDGU3VsAJq4w==",
+ "dependencies": {
+ "mkdirp-classic": "^0.5.2",
+ "pump": "^3.0.0",
+ "tar-stream": "^3.1.5"
+ }
+ },
+ "node_modules/tar-fs/node_modules/tar-stream": {
+ "version": "3.1.6",
+ "resolved": "https://registry.npmjs.org/tar-stream/-/tar-stream-3.1.6.tgz",
+ "integrity": "sha512-B/UyjYwPpMBv+PaFSWAmtYjwdrlEaZQEhMIBFNC5oEG8lpiW8XjcSdmEaClj28ArfKScKHs2nshz3k2le6crsg==",
+ "dependencies": {
+ "b4a": "^1.6.4",
+ "fast-fifo": "^1.2.0",
+ "streamx": "^2.15.0"
+ }
+ },
"node_modules/term-size": {
"version": "2.2.1",
"resolved": "https://registry.npmjs.org/term-size/-/term-size-2.2.1.tgz",
@@ -9869,6 +10109,14 @@
"defaults": "^1.0.3"
}
},
+ "node_modules/web-streams-polyfill": {
+ "version": "3.2.1",
+ "resolved": "https://registry.npmjs.org/web-streams-polyfill/-/web-streams-polyfill-3.2.1.tgz",
+ "integrity": "sha512-e0MO3wdXWKrLbL0DgGnUV7WHVuw9OUvL4hjgnPkIeEvESk74gAITi5G606JtZPp39cd8HA9VQzCIvA49LpPN5Q==",
+ "engines": {
+ "node": ">= 8"
+ }
+ },
"node_modules/webidl-conversions": {
"version": "3.0.1",
"resolved": "https://registry.npmjs.org/webidl-conversions/-/webidl-conversions-3.0.1.tgz",
@@ -10129,21 +10377,28 @@
},
"packages/cli": {
"name": "@e2b/cli",
- "version": "0.0.1",
+ "version": "0.0.8",
"license": "SEE LICENSE IN LICENSE",
"dependencies": {
+ "@balena/dockerignore": "^1.0.2",
"@devbookhq/sdk": "^2.6.88",
"@iarna/toml": "^2.2.5",
"@nodelib/fs.walk": "^1.2.8",
+ "@types/tar-fs": "^2.0.2",
"async-listen": "^3.0.1",
"boxen": "^7.0.0",
"chalk": "^5.1.2",
"chokidar": "^3.5.3",
"commander": "^9.4.1",
+ "common-tags": "^1.8.2",
"docker-names": "^1.2.1",
"get-port": "^7.0.0",
+ "ignore": "^5.2.4",
"inquirer": "^8.0.0",
+ "node-fetch": "^3.3.2",
+ "open": "^8.4.2",
"parse-gitignore": "^2.0.0",
+ "tar-fs": "^3.0.4",
"update-notifier": "5.1.0",
"yup": "^0.32.11"
},
@@ -10152,9 +10407,12 @@
},
"devDependencies": {
"@trivago/prettier-plugin-sort-imports": "^3.3.0",
+ "@types/common-tags": "^1.8.2",
"@types/inquirer": "^8.0.0",
"@types/node": "16.11",
+ "@types/node-fetch": "^2.6.5",
"@types/parse-gitignore": "^1.0.0",
+ "@types/platform": "^1.3.4",
"@types/update-notifier": "5.1.0",
"@typescript-eslint/eslint-plugin": "^5.38.1",
"@typescript-eslint/parser": "^5.38.1",
@@ -10162,12 +10420,13 @@
"eslint-config-prettier": "^8.5.0",
"eslint-plugin-prettier": "^4.2.1",
"eslint-plugin-unused-imports": "^2.0.0",
+ "platform": "^1.3.6",
"prettier": "^2.7.1",
"tsup": "^6.5.0",
"typescript": "^4.9.3"
},
"engines": {
- "node": "~16"
+ "node": ">=16"
}
},
"packages/cli/node_modules/@types/node": {
@@ -10189,9 +10448,64 @@
"url": "https://github.com/chalk/chalk?sponsor=1"
}
},
+ "packages/cli/node_modules/define-lazy-prop": {
+ "version": "2.0.0",
+ "resolved": "https://registry.npmjs.org/define-lazy-prop/-/define-lazy-prop-2.0.0.tgz",
+ "integrity": "sha512-Ds09qNh8yw3khSjiJjiUInaGX9xlqZDY7JVryGxdxV7NPeuqQfplOpQ66yJFZut3jLa5zOwkXw1g9EI2uKh4Og==",
+ "engines": {
+ "node": ">=8"
+ }
+ },
+ "packages/cli/node_modules/is-docker": {
+ "version": "2.2.1",
+ "resolved": "https://registry.npmjs.org/is-docker/-/is-docker-2.2.1.tgz",
+ "integrity": "sha512-F+i2BKsFrH66iaUFc0woD8sLy8getkwTwtOBjvs56Cx4CgJDeKQeqfz8wAYiSb8JOprWhHH5p77PbmYCvvUuXQ==",
+ "bin": {
+ "is-docker": "cli.js"
+ },
+ "engines": {
+ "node": ">=8"
+ },
+ "funding": {
+ "url": "https://github.com/sponsors/sindresorhus"
+ }
+ },
+ "packages/cli/node_modules/node-fetch": {
+ "version": "3.3.2",
+ "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-3.3.2.tgz",
+ "integrity": "sha512-dRB78srN/l6gqWulah9SrxeYnxeddIG30+GOqK/9OlLVyLg3HPnr6SqOWTWOXKRwC2eGYCkZ59NNuSgvSrpgOA==",
+ "dependencies": {
+ "data-uri-to-buffer": "^4.0.0",
+ "fetch-blob": "^3.1.4",
+ "formdata-polyfill": "^4.0.10"
+ },
+ "engines": {
+ "node": "^12.20.0 || ^14.13.1 || >=16.0.0"
+ },
+ "funding": {
+ "type": "opencollective",
+ "url": "https://opencollective.com/node-fetch"
+ }
+ },
+ "packages/cli/node_modules/open": {
+ "version": "8.4.2",
+ "resolved": "https://registry.npmjs.org/open/-/open-8.4.2.tgz",
+ "integrity": "sha512-7x81NCL719oNbsq/3mh+hVrAWmFuEYUqrq/Iw3kUzH8ReypT9QQ0BLoJS7/G9k6N81XjW4qHWtjWwe/9eLy1EQ==",
+ "dependencies": {
+ "define-lazy-prop": "^2.0.0",
+ "is-docker": "^2.1.1",
+ "is-wsl": "^2.2.0"
+ },
+ "engines": {
+ "node": ">=12"
+ },
+ "funding": {
+ "url": "https://github.com/sponsors/sindresorhus"
+ }
+ },
"packages/js-sdk": {
"name": "@e2b/sdk",
- "version": "0.2.5",
+ "version": "0.2.6",
"license": "MIT",
"dependencies": {
"bufferutil": "^4.0.7",
@@ -10226,6 +10540,9 @@
"vitest": "^0.34.2"
}
},
+ "packages/js-sdk/dist": {
+ "extraneous": true
+ },
"packages/js-sdk/node_modules/@types/node": {
"version": "18.17.7",
"resolved": "https://registry.npmjs.org/@types/node/-/node-18.17.7.tgz",
@@ -10584,6 +10901,11 @@
"to-fast-properties": "^2.0.0"
}
},
+ "@balena/dockerignore": {
+ "version": "1.0.2",
+ "resolved": "https://registry.npmjs.org/@balena/dockerignore/-/dockerignore-1.0.2.tgz",
+ "integrity": "sha512-wMue2Sy4GAVTk6Ic4tJVcnfdau+gx2EnG7S+uAEe+TWJFqE4YoWN4/H8MSLj4eYJKxGg26lZwboEniNiNwZQ6Q=="
+ },
"@changesets/apply-release-plan": {
"version": "6.1.4",
"resolved": "https://registry.npmjs.org/@changesets/apply-release-plan/-/apply-release-plan-6.1.4.tgz",
@@ -11232,13 +11554,18 @@
"@e2b/cli": {
"version": "file:packages/cli",
"requires": {
+ "@balena/dockerignore": "^1.0.2",
"@devbookhq/sdk": "^2.6.88",
"@iarna/toml": "^2.2.5",
"@nodelib/fs.walk": "^1.2.8",
"@trivago/prettier-plugin-sort-imports": "^3.3.0",
+ "@types/common-tags": "^1.8.2",
"@types/inquirer": "^8.0.0",
"@types/node": "16.11",
+ "@types/node-fetch": "^2.6.5",
"@types/parse-gitignore": "^1.0.0",
+ "@types/platform": "1.3.4",
+ "@types/tar-fs": "^2.0.2",
"@types/update-notifier": "5.1.0",
"@typescript-eslint/eslint-plugin": "^5.38.1",
"@typescript-eslint/parser": "^5.38.1",
@@ -11247,15 +11574,21 @@
"chalk": "^5.1.2",
"chokidar": "^3.5.3",
"commander": "^9.4.1",
+ "common-tags": "^1.8.2",
"docker-names": "^1.2.1",
"eslint": "^8.24.0",
"eslint-config-prettier": "^8.5.0",
"eslint-plugin-prettier": "^4.2.1",
"eslint-plugin-unused-imports": "^2.0.0",
"get-port": "^7.0.0",
+ "ignore": "^5.2.4",
"inquirer": "^8.0.0",
+ "node-fetch": "^3.3.2",
+ "open": "^8.4.2",
"parse-gitignore": "^2.0.0",
+ "platform": "^1.3.6",
"prettier": "^2.7.1",
+ "tar-fs": "^3.0.4",
"tsup": "^6.5.0",
"typescript": "^4.9.3",
"update-notifier": "5.1.0",
@@ -11272,6 +11605,36 @@
"version": "5.3.0",
"resolved": "https://registry.npmjs.org/chalk/-/chalk-5.3.0.tgz",
"integrity": "sha512-dLitG79d+GV1Nb/VYcCDFivJeK1hiukt9QjRNVOsUtTy1rR1YJsmpGGTZ3qJos+uw7WmWF4wUwBd9jxjocFC2w=="
+ },
+ "define-lazy-prop": {
+ "version": "2.0.0",
+ "resolved": "https://registry.npmjs.org/define-lazy-prop/-/define-lazy-prop-2.0.0.tgz",
+ "integrity": "sha512-Ds09qNh8yw3khSjiJjiUInaGX9xlqZDY7JVryGxdxV7NPeuqQfplOpQ66yJFZut3jLa5zOwkXw1g9EI2uKh4Og=="
+ },
+ "is-docker": {
+ "version": "2.2.1",
+ "resolved": "https://registry.npmjs.org/is-docker/-/is-docker-2.2.1.tgz",
+ "integrity": "sha512-F+i2BKsFrH66iaUFc0woD8sLy8getkwTwtOBjvs56Cx4CgJDeKQeqfz8wAYiSb8JOprWhHH5p77PbmYCvvUuXQ=="
+ },
+ "node-fetch": {
+ "version": "3.3.2",
+ "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-3.3.2.tgz",
+ "integrity": "sha512-dRB78srN/l6gqWulah9SrxeYnxeddIG30+GOqK/9OlLVyLg3HPnr6SqOWTWOXKRwC2eGYCkZ59NNuSgvSrpgOA==",
+ "requires": {
+ "data-uri-to-buffer": "^4.0.0",
+ "fetch-blob": "^3.1.4",
+ "formdata-polyfill": "^4.0.10"
+ }
+ },
+ "open": {
+ "version": "8.4.2",
+ "resolved": "https://registry.npmjs.org/open/-/open-8.4.2.tgz",
+ "integrity": "sha512-7x81NCL719oNbsq/3mh+hVrAWmFuEYUqrq/Iw3kUzH8ReypT9QQ0BLoJS7/G9k6N81XjW4qHWtjWwe/9eLy1EQ==",
+ "requires": {
+ "define-lazy-prop": "^2.0.0",
+ "is-docker": "^2.1.1",
+ "is-wsl": "^2.2.0"
+ }
}
}
},
@@ -11287,7 +11650,7 @@
"@types/node": "^18.7.23",
"@types/normalize-path": "^3.0.0",
"@types/platform": "^1.3.4",
- "@types/utf-8-validate": "5.0.0",
+ "@types/utf-8-validate": "^5.0.0",
"@typescript-eslint/eslint-plugin": "^5.38.1",
"@typescript-eslint/parser": "^5.38.1",
"bufferutil": "^4.0.7",
@@ -11990,6 +12353,12 @@
"@types/chai": "*"
}
},
+ "@types/common-tags": {
+ "version": "1.8.2",
+ "resolved": "https://registry.npmjs.org/@types/common-tags/-/common-tags-1.8.2.tgz",
+ "integrity": "sha512-Z5UcOnlqxFm0tCCTEhkcVOfSihWOMyKypIWHtQNSYh6fMdPUIVpNdLBYutDpDXVHsMUrYzI2IczUHXIzpUovmQ==",
+ "dev": true
+ },
"@types/configstore": {
"version": "6.0.0",
"resolved": "https://registry.npmjs.org/@types/configstore/-/configstore-6.0.0.tgz",
@@ -12046,8 +12415,17 @@
"@types/node": {
"version": "20.5.2",
"resolved": "https://registry.npmjs.org/@types/node/-/node-20.5.2.tgz",
- "integrity": "sha512-5j/lXt7unfPOUlrKC34HIaedONleyLtwkKggiD/0uuMfT8gg2EOpg0dz4lCD15Ga7muC+1WzJZAjIB9simWd6Q==",
- "dev": true
+ "integrity": "sha512-5j/lXt7unfPOUlrKC34HIaedONleyLtwkKggiD/0uuMfT8gg2EOpg0dz4lCD15Ga7muC+1WzJZAjIB9simWd6Q=="
+ },
+ "@types/node-fetch": {
+ "version": "2.6.5",
+ "resolved": "https://registry.npmjs.org/@types/node-fetch/-/node-fetch-2.6.5.tgz",
+ "integrity": "sha512-OZsUlr2nxvkqUFLSaY2ZbA+P1q22q+KrlxWOn/38RX+u5kTkYL2mTujEpzUhGkS+K/QCYp9oagfXG39XOzyySg==",
+ "dev": true,
+ "requires": {
+ "@types/node": "*",
+ "form-data": "^4.0.0"
+ }
},
"@types/normalize-package-data": {
"version": "2.4.1",
@@ -12089,6 +12467,23 @@
"resolved": "https://registry.npmjs.org/@types/semver/-/semver-7.5.0.tgz",
"integrity": "sha512-G8hZ6XJiHnuhQKR7ZmysCeJWE08o8T0AXtk5darsCaTVsYZhhgUrq53jizaR2FvsoeCwJhlmwTjkXBY5Pn/ZHw=="
},
+ "@types/tar-fs": {
+ "version": "2.0.2",
+ "resolved": "https://registry.npmjs.org/@types/tar-fs/-/tar-fs-2.0.2.tgz",
+ "integrity": "sha512-XuZRAvdo7FbDfgQCNkc8NOdSae5XtG+of2mTSgJ85G4OG0miN4E8BTGT+JBTLO87RQ7iCwsIDCqCsHnf2IaSXA==",
+ "requires": {
+ "@types/node": "*",
+ "@types/tar-stream": "*"
+ }
+ },
+ "@types/tar-stream": {
+ "version": "2.2.3",
+ "resolved": "https://registry.npmjs.org/@types/tar-stream/-/tar-stream-2.2.3.tgz",
+ "integrity": "sha512-if3mugZfjVkXOMZdFjIHySxY13r6GXPpyOlsDmLffvyI7tLz9wXE8BFjNivXsvUeyJ1KNlOpfLnag+ISmxgxPw==",
+ "requires": {
+ "@types/node": "*"
+ }
+ },
"@types/through": {
"version": "0.0.30",
"resolved": "https://registry.npmjs.org/@types/through/-/through-0.0.30.tgz",
@@ -12591,11 +12986,22 @@
"resolved": "https://registry.npmjs.org/async-listen/-/async-listen-3.0.1.tgz",
"integrity": "sha512-cWMaNwUJnf37C/S5TfCkk/15MwbPRwVYALA2jtjkbHjCmAPiDXyNJy2q3p1KAZzDLHAWyarUWSujUoHR4pEgrA=="
},
+ "asynckit": {
+ "version": "0.4.0",
+ "resolved": "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz",
+ "integrity": "sha512-Oei9OH4tRh0YqU3GxhX79dM/mwVgvbZJaSNaRk+bshkj0S5cfHcgYakreBjrHwatXKbz+IoIdYLxrKim2MjW0Q==",
+ "dev": true
+ },
"available-typed-arrays": {
"version": "1.0.5",
"resolved": "https://registry.npmjs.org/available-typed-arrays/-/available-typed-arrays-1.0.5.tgz",
"integrity": "sha512-DMD0KiN46eipeziST1LPP/STfDU0sufISXmjSgvVsoU2tqxctQeASejWcfNtxYKqETM1UxQ8sp2OrSBWpHY6sw=="
},
+ "b4a": {
+ "version": "1.6.4",
+ "resolved": "https://registry.npmjs.org/b4a/-/b4a-1.6.4.tgz",
+ "integrity": "sha512-fpWrvyVHEKyeEvbKZTVOeZF3VSKKWtJxFIxX/jaVPf+cLbGUSitjb49pHLqPV2BUNNZ0LcoeEGfE/YCpyDYHIw=="
+ },
"balanced-match": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.2.tgz",
@@ -13023,11 +13429,25 @@
"resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.4.tgz",
"integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA=="
},
+ "combined-stream": {
+ "version": "1.0.8",
+ "resolved": "https://registry.npmjs.org/combined-stream/-/combined-stream-1.0.8.tgz",
+ "integrity": "sha512-FQN4MRfuJeHf7cBbBMJFXhKSDq+2kAArBlmRBvcvFE5BB1HZKXtSFASDhdlz9zOYwxh8lDdnvmMOe/+5cdoEdg==",
+ "dev": true,
+ "requires": {
+ "delayed-stream": "~1.0.0"
+ }
+ },
"commander": {
"version": "9.5.0",
"resolved": "https://registry.npmjs.org/commander/-/commander-9.5.0.tgz",
"integrity": "sha512-KRs7WVDKg86PWiuAqhDrAQnTXZKraVcCc6vFdL14qrZ/DcWwuRo7VoiYXalXO7S5GKpqYiVEwCbgFDfxNHKJBQ=="
},
+ "common-tags": {
+ "version": "1.8.2",
+ "resolved": "https://registry.npmjs.org/common-tags/-/common-tags-1.8.2.tgz",
+ "integrity": "sha512-gk/Z852D2Wtb//0I+kRFNKKE9dIIVirjoqPoA1wJU+XePVXZfGeBpk45+A1rKO4Q43prqWBNY/MiIeRLbPWUaA=="
+ },
"commondir": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/commondir/-/commondir-1.0.1.tgz",
@@ -13109,6 +13529,11 @@
"resolved": "https://registry.npmjs.org/csv-stringify/-/csv-stringify-5.6.5.tgz",
"integrity": "sha512-PjiQ659aQ+fUTQqSrd1XEDnOr52jh30RBurfzkscaE2tPaFsDH5wOAHJiw8XAHphRknCwMUE9KRayc4K/NbO8A=="
},
+ "data-uri-to-buffer": {
+ "version": "4.0.1",
+ "resolved": "https://registry.npmjs.org/data-uri-to-buffer/-/data-uri-to-buffer-4.0.1.tgz",
+ "integrity": "sha512-0R9ikRb668HB7QDxT1vkpuUBtqc53YyAwMwGeUFKRojY/NWKvdZ+9UYtRfGmhqNbRkTSVpMbmyhXipFFv2cb/A=="
+ },
"debug": {
"version": "4.3.4",
"resolved": "https://registry.npmjs.org/debug/-/debug-4.3.4.tgz",
@@ -13195,6 +13620,12 @@
"object-keys": "^1.1.1"
}
},
+ "delayed-stream": {
+ "version": "1.0.0",
+ "resolved": "https://registry.npmjs.org/delayed-stream/-/delayed-stream-1.0.0.tgz",
+ "integrity": "sha512-ZySD7Nf91aLB0RxL4KGrKHBXl7Eds1DAmEdcoVawXnLD7SDhpNgtuII2aAkg7a7QS41jxPSZ17p4VdGnMHk3MQ==",
+ "dev": true
+ },
"detect-indent": {
"version": "6.1.0",
"resolved": "https://registry.npmjs.org/detect-indent/-/detect-indent-6.1.0.tgz",
@@ -13771,6 +14202,11 @@
"integrity": "sha512-VxPP4NqbUjj6MaAOafWeUn2cXWLcCtljklUtZf0Ind4XQ+QPtmA0b18zZy0jIQx+ExRVCR/ZQpBmik5lXshNsw==",
"dev": true
},
+ "fast-fifo": {
+ "version": "1.3.2",
+ "resolved": "https://registry.npmjs.org/fast-fifo/-/fast-fifo-1.3.2.tgz",
+ "integrity": "sha512-/d9sfos4yxzpwkDkuN7k2SqFKtYNmCTzgfEpz82x34IM9/zc8KGxQoXg1liNC/izpRM/MBdt44Nmx41ZWqk+FQ=="
+ },
"fast-glob": {
"version": "3.3.1",
"resolved": "https://registry.npmjs.org/fast-glob/-/fast-glob-3.3.1.tgz",
@@ -13803,6 +14239,15 @@
"reusify": "^1.0.4"
}
},
+ "fetch-blob": {
+ "version": "3.2.0",
+ "resolved": "https://registry.npmjs.org/fetch-blob/-/fetch-blob-3.2.0.tgz",
+ "integrity": "sha512-7yAQpD2UMJzLi1Dqv7qFYnPbaPx7ZfFK6PiIxQ4PfkGPyNyl2Ugx+a/umUonmKqjhM4DnfbMvdX6otXq83soQQ==",
+ "requires": {
+ "node-domexception": "^1.0.0",
+ "web-streams-polyfill": "^3.0.3"
+ }
+ },
"figures": {
"version": "3.2.0",
"resolved": "https://registry.npmjs.org/figures/-/figures-3.2.0.tgz",
@@ -13881,6 +14326,25 @@
"is-callable": "^1.1.3"
}
},
+ "form-data": {
+ "version": "4.0.0",
+ "resolved": "https://registry.npmjs.org/form-data/-/form-data-4.0.0.tgz",
+ "integrity": "sha512-ETEklSGi5t0QMZuiXoA/Q6vcnxcLQP5vdugSpuAyi6SVGi2clPPp+xgEhuMaHC+zGgn31Kd235W35f7Hykkaww==",
+ "dev": true,
+ "requires": {
+ "asynckit": "^0.4.0",
+ "combined-stream": "^1.0.8",
+ "mime-types": "^2.1.12"
+ }
+ },
+ "formdata-polyfill": {
+ "version": "4.0.10",
+ "resolved": "https://registry.npmjs.org/formdata-polyfill/-/formdata-polyfill-4.0.10.tgz",
+ "integrity": "sha512-buewHzMvYL29jdeQTVILecSaZKnt/RJWjoZCF5OW60Z67/GmSLBkOFM7qh1PI3zFNtJbaZL5eQu1vLfazOwj4g==",
+ "requires": {
+ "fetch-blob": "^3.1.2"
+ }
+ },
"fs-extra": {
"version": "10.1.0",
"resolved": "https://registry.npmjs.org/fs-extra/-/fs-extra-10.1.0.tgz",
@@ -14499,6 +14963,21 @@
"resolved": "https://registry.npmjs.org/is-windows/-/is-windows-1.0.2.tgz",
"integrity": "sha512-eXK1UInq2bPmjyX6e3VHIzMLobc4J94i4AWn+Hpq3OU5KkrRC96OAcR3PRJ/pGu6m8TRnBHP9dkXQVsT/COVIA=="
},
+ "is-wsl": {
+ "version": "2.2.0",
+ "resolved": "https://registry.npmjs.org/is-wsl/-/is-wsl-2.2.0.tgz",
+ "integrity": "sha512-fKzAra0rGJUUBwGBgNkHZuToZcn+TtXHpeCgmkMJMMYx1sQDYaCSyjJBSCa2nH1DGm7s3n1oBnohoVTBaN7Lww==",
+ "requires": {
+ "is-docker": "^2.0.0"
+ },
+ "dependencies": {
+ "is-docker": {
+ "version": "2.2.1",
+ "resolved": "https://registry.npmjs.org/is-docker/-/is-docker-2.2.1.tgz",
+ "integrity": "sha512-F+i2BKsFrH66iaUFc0woD8sLy8getkwTwtOBjvs56Cx4CgJDeKQeqfz8wAYiSb8JOprWhHH5p77PbmYCvvUuXQ=="
+ }
+ }
+ },
"is-yarn-global": {
"version": "0.3.0",
"resolved": "https://registry.npmjs.org/is-yarn-global/-/is-yarn-global-0.3.0.tgz",
@@ -14861,6 +15340,21 @@
"integrity": "sha512-jSCU7/VB1loIWBZe14aEYHU/+1UMEHoaO7qxCOVJOw9GgH72VAWppxNcjU+x9a2k3GSIBXNKxXQFqRvvZ7vr3A==",
"dev": true
},
+ "mime-db": {
+ "version": "1.52.0",
+ "resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.52.0.tgz",
+ "integrity": "sha512-sPU4uV7dYlvtWJxwwxHD0PuihVNiE7TyAbQ5SWxDCB9mUYvOgroQOwYQQOKPJ8CIbE+1ETVlOoK1UC2nU3gYvg==",
+ "dev": true
+ },
+ "mime-types": {
+ "version": "2.1.35",
+ "resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.35.tgz",
+ "integrity": "sha512-ZDY+bPm5zTTF+YpCrAU9nK0UgICYPT0QtT1NZWFv4s++TNkcgVaT0g6+4R2uI4MjQjzysHB1zxuWL50hzaeXiw==",
+ "dev": true,
+ "requires": {
+ "mime-db": "1.52.0"
+ }
+ },
"mimic-fn": {
"version": "2.1.0",
"resolved": "https://registry.npmjs.org/mimic-fn/-/mimic-fn-2.1.0.tgz",
@@ -14912,6 +15406,11 @@
"resolved": "https://registry.npmjs.org/mixme/-/mixme-0.5.9.tgz",
"integrity": "sha512-VC5fg6ySUscaWUpI4gxCBTQMH2RdUpNrk+MsbpCYtIvf9SBJdiUey4qE7BXviJsJR4nDQxCZ+3yaYNW3guz/Pw=="
},
+ "mkdirp-classic": {
+ "version": "0.5.3",
+ "resolved": "https://registry.npmjs.org/mkdirp-classic/-/mkdirp-classic-0.5.3.tgz",
+ "integrity": "sha512-gKLcREMhtuZRwRAfqP3RFW+TK4JqApVBtOIftVgjuABpAtpxhPGaDcfvbhNvD0B8iD1oUr/txX35NjcaY6Ns/A=="
+ },
"mlly": {
"version": "1.4.1",
"resolved": "https://registry.npmjs.org/mlly/-/mlly-1.4.1.tgz",
@@ -14969,6 +15468,11 @@
"integrity": "sha512-Tj+HTDSJJKaZnfiuw+iaF9skdPpTo2GtEly5JHnWV/hfv2Qj/9RKsGISQtLh2ox3l5EAGw487hnBee0sIJ6v2g==",
"dev": true
},
+ "node-domexception": {
+ "version": "1.0.0",
+ "resolved": "https://registry.npmjs.org/node-domexception/-/node-domexception-1.0.0.tgz",
+ "integrity": "sha512-/jKZoMpw0F8GRwl4/eLROPA3cfcXtLApP0QzLmUT/HuPCZWyB7IY9ZrMeKw2O/nFIqPQB3PVM9aYm0F312AXDQ=="
+ },
"node-fetch": {
"version": "2.6.13",
"resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.13.tgz",
@@ -15440,6 +15944,11 @@
"resolved": "https://registry.npmjs.org/queue-microtask/-/queue-microtask-1.2.3.tgz",
"integrity": "sha512-NuaNSa6flKT5JaSYQzJok04JzTL1CA6aGhv5rfLW3PgqA+M2ChpZQnAC8h8i4ZFkBS8X5RqkDBHA7r4hej3K9A=="
},
+ "queue-tick": {
+ "version": "1.0.1",
+ "resolved": "https://registry.npmjs.org/queue-tick/-/queue-tick-1.0.1.tgz",
+ "integrity": "sha512-kJt5qhMxoszgU/62PLP1CJytzd2NKetjSRnyuj31fDd3Rlcz3fzlFdFLD1SItunPwyqEOkca6GbV612BWfaBag=="
+ },
"quick-lru": {
"version": "4.0.1",
"resolved": "https://registry.npmjs.org/quick-lru/-/quick-lru-4.0.1.tgz",
@@ -16200,6 +16709,15 @@
"integrity": "sha512-Mcc5wHehp9aXz1ax6bZUyY5afg9u2rv5cqQI3mRrYkGC8rW2hM02jWuwjtL++LS5qinSyhj2QfLyNsuc+VsExg==",
"dev": true
},
+ "streamx": {
+ "version": "2.15.1",
+ "resolved": "https://registry.npmjs.org/streamx/-/streamx-2.15.1.tgz",
+ "integrity": "sha512-fQMzy2O/Q47rgwErk/eGeLu/roaFWV0jVsogDmrszM9uIw8L5OA+t+V93MgYlufNptfjmYR1tOMWhei/Eh7TQA==",
+ "requires": {
+ "fast-fifo": "^1.1.0",
+ "queue-tick": "^1.0.1"
+ }
+ },
"string_decoder": {
"version": "1.3.0",
"resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-1.3.0.tgz",
@@ -16326,6 +16844,28 @@
"resolved": "https://registry.npmjs.org/supports-preserve-symlinks-flag/-/supports-preserve-symlinks-flag-1.0.0.tgz",
"integrity": "sha512-ot0WnXS9fgdkgIcePe6RHNk1WA8+muPa6cSjeR3V8K27q9BB1rTE3R1p7Hv0z1ZyAc8s6Vvv8DIyWf681MAt0w=="
},
+ "tar-fs": {
+ "version": "3.0.4",
+ "resolved": "https://registry.npmjs.org/tar-fs/-/tar-fs-3.0.4.tgz",
+ "integrity": "sha512-5AFQU8b9qLfZCX9zp2duONhPmZv0hGYiBPJsyUdqMjzq/mqVpy/rEUSeHk1+YitmxugaptgBh5oDGU3VsAJq4w==",
+ "requires": {
+ "mkdirp-classic": "^0.5.2",
+ "pump": "^3.0.0",
+ "tar-stream": "^3.1.5"
+ },
+ "dependencies": {
+ "tar-stream": {
+ "version": "3.1.6",
+ "resolved": "https://registry.npmjs.org/tar-stream/-/tar-stream-3.1.6.tgz",
+ "integrity": "sha512-B/UyjYwPpMBv+PaFSWAmtYjwdrlEaZQEhMIBFNC5oEG8lpiW8XjcSdmEaClj28ArfKScKHs2nshz3k2le6crsg==",
+ "requires": {
+ "b4a": "^1.6.4",
+ "fast-fifo": "^1.2.0",
+ "streamx": "^2.15.0"
+ }
+ }
+ }
+ },
"term-size": {
"version": "2.2.1",
"resolved": "https://registry.npmjs.org/term-size/-/term-size-2.2.1.tgz",
@@ -16897,6 +17437,11 @@
"defaults": "^1.0.3"
}
},
+ "web-streams-polyfill": {
+ "version": "3.2.1",
+ "resolved": "https://registry.npmjs.org/web-streams-polyfill/-/web-streams-polyfill-3.2.1.tgz",
+ "integrity": "sha512-e0MO3wdXWKrLbL0DgGnUV7WHVuw9OUvL4hjgnPkIeEvESk74gAITi5G606JtZPp39cd8HA9VQzCIvA49LpPN5Q=="
+ },
"webidl-conversions": {
"version": "3.0.1",
"resolved": "https://registry.npmjs.org/webidl-conversions/-/webidl-conversions-3.0.1.tgz",
diff --git a/packages/cli/README.md b/packages/cli/README.md
index df003f006..b944e2aca 100644
--- a/packages/cli/README.md
+++ b/packages/cli/README.md
@@ -1,172 +1,55 @@
-# Devbook CLI
-CLI for managing Devbook environments.
-
-An environment is a virtual machine image that you can customize through our CLI. You can add files, install dependencies, and set env vars in the environment. Then with Devbook, every user visiting your website will get a new copy of the environment they can use.
-
-* [Installation](#installation)
-* [Quickstart](#quickstart)
-* [Commands](#commands)
- + [`devbook env create`](#devbook-env-create)
- + [`devbook env push`](#devbook-env-push)
- + [`devbook env publish`](#devbook-env-publish)
- + [`devbook env delete`](#devbook-env-delete)
- + [`devbook env use`](#devbook-env-use)
- + [`devbook env set`](#devbook-env-set)
- + [`devbook env connect`](#devbook-env-connect)
- + [`devbook env list`](#devbook-env-list)
-* [`dbk.toml` config](#dbktoml-config)
- + [`id`](#id)
- + [`template`](#template)
- + [`title`](#title)
- + [`filesystem.local_root`](#filesystemlocal_root)
-* [FAQ](#faq)
- + [Inspect how a published environment looks like](#inspect-how-a-published-environment-looks-like)
- + [Delete files from an environment](#delete-files-from-an-environment)
- + [Inspect files in an environment](#inspect-files-in-an-environment)
- + [Install dependencies in an environment](#install-dependencies-in-an-environment)
- + [Upload local files to an environment](#upload-local-files-to-an-environment)
+# e2b CLI (WIP)
+Command line interface for [e2b](https://e2b.dev/).
## Installation
+
```sh
-npm install -g @devbookhq/cli
+npm install -g @e2b/cli
```
Then you can use the CLI with
+
```sh
-devbook env --help
+e2b --help
```
-You will need an API key to use the Devbook CLI — you can get it [here](https://dash.usedevbook.com/settings) after signing up.
-After you get the API key set the `DEVBOOK_KEY` env var in your terminal, or call the CLI with the env var directly
+You will need to authenticate to use the e2b CLI.
```sh
-DEVBOOK_KEY=<your-api-key> devbook env ...
+e2b login
```
-## Quickstart
-```sh
-# Create an environment and a dbk.toml config for the environment
-devbook env create
-
-# Create a directory for files you want to be in the environment
-mkdir ./files
+<details>
+<summary>Authenticate without the ability to open browser</summary>
-# Upload files from the ./files directory to the environment
-devbook env push
-# Connect terminal to the environment so you can install dependencies.
-# You quit this terminal with Ctrl+D or by `exit` command
-devbook env connect
+To authenticate without the ability to open browser, you can provide E2B_ACCESS_TOKEN as an environment variable.
+Obtain your E2B_ACCESS_TOKEN from at [e2b.dev/docs](https://e2b.dev/docs).
-# All changes you made to the environment so far are not published —
-# users that use this environment on your website cannot see the changes.
-# To make all the changes you just made published, call the following command
-devbook env publish
+```sh
+E2B_ACCESS_TOKEN=sk_e2b_... e2b login
```
-## Commands
-By default, commands are referring to an environment defined by a `dbk.toml` in a directory where you called the commands.
-
-All commands can be called with a `--path <path-to-dir>` flag that changes the directory where the command will be called, without the need to call `cd`.
-
-
-The Devbook CLI has following commands
-
-### `devbook env create`
-Create a new environment and `dbk.toml` config.
-
-You can specify another environment as a template with `--template <existing-environment-id>` flag. This existing environment will be a base of the new environment — all files, env vars and dependencies from the existing environment will be present in the new environment.
-
-
-### `devbook env push`
-Upload files from a local directory to an environment. The local directory to upload from is defined by the `filesystem.local_root` field in the `dbk.toml` config (`./files` by default).
-Path of uploaded files in the environment will reflect their paths in the `./files` directory — file `./files/index.ts` will become `/index.ts` in the environment.
-
-> Use `devbook env publish --all` to push all environments in subdirectories.
-
-
-### `devbook env publish`
-Publish changes you made in an environment (uploaded files, installed depedencies, set env vars).
-Users on your website that use the environment cannot see the new changes you made to the environment until you run `devbook env publish` command.
-
-> Use `devbook env publish --all` to publish all environments in subdirectories.
-
-
-### `devbook env delete`
-Delete an environment and a `dbk.toml` config for the environment.
-
-
-### `devbook env use`
-Create a `dbk.toml` for an existing environment. You can use this to start version tracking environments created through Devbook dashboard.
-
-
-### `devbook env set`
-Set env vars inside of an environment.
-For example, to set `FOO` and `BAR` call `devbook env set FOO=1 BAR=2`.
-
-> You must set all env vars in one `devbook env set --env-vars <KEY=VALUE...>` call — variables from the previous `devbook env set` calls will be overwritten.
-
-
-### `devbook env connect`
-Open a terminal connected to an environment that you can use to configure and inspect the environment.
+</details>
-> The environments are based on Alpine Linux that uses `apk add` and `apk del` for managing packages.
-
-
-### `devbook env list`
-List all environments and paths to their `dbk.toml` configs (if the configs are in subdirectories of the current directory).
-
-
-## `dbk.toml` config
-The `dbk.toml` config is used for tracking an environment in version control. It is created automatically by `devbook env create` command.
-
-The following fields are in each `dbk.toml` config
-
-### `id`
-You **should not edit this field** manually.
-The id of this environment.
-
-
-### `template`
-You **should not edit this field** manually.
-The id of the environment that was used as a template for this environment.
-
-
-### `title`
-Title of the environment. The title is used for easier navigation and to distinguish between environments.
-
-By default the title is the name of the directory where you called `devbook env create` command.
-You can change this field and use `devbook env push` to save the changes.
-
-
-### `filesystem.local_root`
-A directory containing files that will be uploaded with `devbook env push` command.
-By default it is `./files` — that means that the `./files` directory next to this `dbk.toml` will be uploaded to the environment when you use `devbook env push`.
-
-For example, if you have a `./files/index.ts` file locally and run `devbook env push` the file `/index.ts` will be created and saved in the environment.
-
-
-## FAQ
-
-### Inspect how a published environment looks like
-Use `devbook env connect --published` to open a terminal connected to a new instace of the environment.
-
-
-### Delete files from an environment
-Use `devbook env connect` to open a terminal connected to the environment. Then you can delete the files from the environment with `rm` shell command.
-
-
-### Inspect files in an environment
-Use `devbook env connect` to connect your terminal with the environment then use terminal commands like `ls`, `cd`, `cat`, etc. to inspect files.
+## Commands
+🔜 All commands can be called with a `--path <path-to-dir>` flag that changes the directory where the command will be called, without the need to call `cd`.
-### Install dependencies in an environment
-Use `devbook env connect` to open a terminal connected to the environment. Then you can install dependencies as you would on any other Linux machine.
+```
+-V, --version Display e2b CLI version
+-h, --help display help for command
+```
-> The environments are running on Alpine Linux that uses `apk add` and `apk del` for managing packages.
+```
+help [command] display help for command
+login Login to e2b
+logout Logout of e2b
-### Upload local files to an environment
-Create `./files` directory next to the `dbk.toml` and put the files you want in the environment there.
-After you call `devbook env push` files from the `./files` directory will be uploaded to the environment. Their path in the environment will reflect the path in the `./files` directory — file `./files/index.ts` will become `/index.ts` in the environment.
+env|environment Manage e2b environments
+ create|cr [options] Create new environment and e2b.json config
+ list|ls List environments
+ shell|cn [options] [id] Connect terminal to environment
+```
diff --git a/packages/cli/package.json b/packages/cli/package.json
index de2eceda2..ed966d30f 100644
--- a/packages/cli/package.json
+++ b/packages/cli/package.json
@@ -1,7 +1,6 @@
{
"name": "@e2b/cli",
- "private": true,
- "version": "0.0.1",
+ "version": "0.0.8",
"description": "CLI for managing e2b environments",
"homepage": "https://usedevbook.com",
"license": "SEE LICENSE IN LICENSE",
@@ -29,9 +28,12 @@
},
"devDependencies": {
"@trivago/prettier-plugin-sort-imports": "^3.3.0",
+ "@types/common-tags": "^1.8.2",
"@types/inquirer": "^8.0.0",
"@types/node": "16.11",
+ "@types/node-fetch": "^2.6.5",
"@types/parse-gitignore": "^1.0.0",
+ "@types/platform": "^1.3.4",
"@types/update-notifier": "5.1.0",
"@typescript-eslint/eslint-plugin": "^5.38.1",
"@typescript-eslint/parser": "^5.38.1",
@@ -39,6 +41,7 @@
"eslint-config-prettier": "^8.5.0",
"eslint-plugin-prettier": "^4.2.1",
"eslint-plugin-unused-imports": "^2.0.0",
+ "platform": "^1.3.6",
"prettier": "^2.7.1",
"tsup": "^6.5.0",
"typescript": "^4.9.3"
@@ -53,22 +56,29 @@
"e2b": "dist/index.js"
},
"dependencies": {
+ "@balena/dockerignore": "^1.0.2",
"@devbookhq/sdk": "^2.6.88",
"@iarna/toml": "^2.2.5",
"@nodelib/fs.walk": "^1.2.8",
+ "@types/tar-fs": "^2.0.2",
"async-listen": "^3.0.1",
"boxen": "^7.0.0",
"chalk": "^5.1.2",
"chokidar": "^3.5.3",
"commander": "^9.4.1",
+ "common-tags": "^1.8.2",
"docker-names": "^1.2.1",
"get-port": "^7.0.0",
+ "ignore": "^5.2.4",
"inquirer": "^8.0.0",
+ "node-fetch": "^3.3.2",
+ "open": "^8.4.2",
"parse-gitignore": "^2.0.0",
+ "tar-fs": "^3.0.4",
"update-notifier": "5.1.0",
"yup": "^0.32.11"
},
"engines": {
- "node": "~16"
+ "node": ">=16"
}
}
diff --git a/packages/cli/src/api.ts b/packages/cli/src/api.ts
index 58a884d82..e801109be 100644
--- a/packages/cli/src/api.ts
+++ b/packages/cli/src/api.ts
@@ -1,36 +1,61 @@
-import * as sdk from '@devbookhq/sdk'
import * as boxen from 'boxen'
+import { getUserConfig } from './commands/auth'
import { asBold } from './utils/format'
-const client: sdk.ClientType = sdk.api
+// const client: sdk.ClientType = sdk.api
// client.configure({
-// baseUrl: 'http://localhost:3000',
+// baseUrl: 'http://localhost:3003',
// })
-const apiKey = process.env.DEVBOOK_KEY
+export const apiBaseDefault = 'https://api.e2b.dev'
+export const apiBaseUrl = process.env.E2B_API_BASE ?? apiBaseDefault
+export let apiKey = process.env.E2B_API_KEY
+export let accessToken = process.env.E2B_ACCESS_TOKEN
+
+if (apiBaseUrl !== apiBaseDefault) {
+ console.warn(`\nBeware: Using custom API base URL: ${asBold(apiBaseUrl)}\n`)
+}
+
+const authErrorBox = boxen.default(
+ `You must be logged in to use this command. Run ${asBold(`e2b login`)}.`,
+ {
+ width: 70,
+ float: 'center',
+ padding: 0.5,
+ margin: 1,
+ borderStyle: 'round',
+ borderColor: 'redBright',
+ },
+)
export function ensureAPIKey() {
+ // If apiKey is not already set (either from env var or from user config), try to get it from config file
+ if (!apiKey) {
+ const userConfig = getUserConfig()
+ apiKey = userConfig?.defaultTeamApiKey
+ }
+
if (!apiKey) {
- const errorBox = boxen.default(
- `Cannot find env var ${asBold(
- 'DEVBOOK_KEY',
- )}\n\nVisit https://dash.usedevbook.com/settings to get your API key then run this CLI with the env var set.`,
- {
- width: 70,
- float: 'center',
- padding: 0.5,
- margin: 1,
- borderStyle: 'round',
- borderColor: 'redBright',
- },
- )
- console.error(errorBox)
+ console.error(authErrorBox)
process.exit(1)
} else {
return apiKey
}
}
-export { client, apiKey }
+export function ensureAccessToken() {
+ // If accessToken is not already set (either from env var or from user config), try to get it from config file
+ if (!accessToken) {
+ const userConfig = getUserConfig()
+ accessToken = userConfig?.accessToken
+ }
+
+ if (!accessToken) {
+ console.error(authErrorBox)
+ process.exit(1)
+ } else {
+ return accessToken
+ }
+}
diff --git a/packages/cli/src/commands/auth.ts b/packages/cli/src/commands/auth.ts
index 2b70857b5..7f289f1bd 100644
--- a/packages/cli/src/commands/auth.ts
+++ b/packages/cli/src/commands/auth.ts
@@ -45,6 +45,7 @@ export const loginCommand = new commander.Command('login')
fs.writeFileSync(USER_CONFIG_PATH, JSON.stringify(userConfig, null, 2))
}
console.log(`Logged in as ${asBold(userConfig.email)}`)
+ process.exit(0)
})
export const logoutCommand = new commander.Command('logout')
diff --git a/packages/cli/src/commands/env/create.ts b/packages/cli/src/commands/env/create.ts
index 5b2c6ea44..c6f4848a5 100644
--- a/packages/cli/src/commands/env/create.ts
+++ b/packages/cli/src/commands/env/create.ts
@@ -1,150 +1,203 @@
-import * as chalk from 'chalk'
import * as commander from 'commander'
+import { stripIndent } from 'common-tags'
import * as fs from 'fs'
-import * as path from 'path'
-
-import { client, ensureAPIKey } from 'src/api'
-import {
- configName,
- configSchema,
- DevbookConfig,
- getConfigPath,
- randomTitle,
- saveConfig,
-} from 'src/config'
-import { templates } from 'src/config/template'
+import fsPromise from 'fs/promises'
+import fetch from 'node-fetch'
+import { apiBaseUrl, ensureAccessToken } from 'src/api'
+import { configName } from 'src/config'
import { pathOption } from 'src/options'
-import { ensureDir, getRoot } from 'src/utils/filesystem'
+import { getFiles, getRoot, packToTar } from 'src/utils/filesystem'
import {
- asTemplate,
asBold,
asFormattedEnvironment,
asFormattedError,
asLocal,
asLocalRelative,
} from 'src/utils/format'
+import * as yup from 'yup'
export const createCommand = new commander.Command('create')
.description(`Create new environment and ${asLocal(configName)} config`)
.option(
- '-T, --template <template>',
- `Use ${asBold('<template>')} as a base for the environment`,
+ '-id, --id <id>',
+ `Use ${asBold(
+ '<id>',
+ )} to override already existing environment, otherwise new environment will be created`,
)
- .option('-t, --title <title>', `Use ${asBold('<title>')} as environment title`)
- .option('-n, --no-config', `Skip creating ${asLocal(configName)} config`)
+ .option('--respect-gitignore', 'Respect .gitignore file in the root directory', true)
+ .option(
+ '--respect-dockerignore',
+ 'Respect .dockerignore file in the root directory',
+ true,
+ )
+ // TODO: Future
+ // .option(
+ // '-t, --title <title>',
+ // `Use ${asBold('<title>')} as environment title`
+ // )
+ // .option(
+ // '-n, --no-config',
+ // `Skip creating ${asLocal(configName)} config`
+ // )
.addOption(pathOption)
.alias('cr')
.action(async opts => {
try {
- const apiKey = ensureAPIKey()
+ const accessToken = ensureAccessToken()
process.stdout.write('\n')
const root = getRoot(opts.path)
- const configPath = getConfigPath(root)
-
- let template = opts.template as string | undefined
- let title = opts.title as string | undefined
-
- if (opts.config) {
- if (fs.existsSync(configPath)) {
- throw new Error(
- `Devbook config on path ${asLocalRelative(
- configPath,
- )} already exists - cannot create new config`,
- )
- }
- }
+ // const configPath = getConfigPath(root) // TODO: Future
- const inquirer = await import('inquirer')
- if (!template) {
- const envsAnwsers = await inquirer.default.prompt([
- {
- name: 'template',
- message: chalk.default.underline('Choose base template for environment'),
- type: 'list',
- choices: templates,
- },
- ])
- template = envsAnwsers['template'] as string
- }
+ // TODO: Future
+ // let title = opts.title as string | undefined
+ // const inquirer = await import('inquirer')
+ // if (!title) {
+ // title = randomTitle() // TODO: Infer from path
+ // }
- if (!title) {
- const envsAnwsers = await inquirer.default.prompt([
- {
- name: 'title',
- message: chalk.default.underline('Choose title for environment'),
- type: 'input',
- default: path.basename(root),
- },
- ])
- title = (envsAnwsers['title'] as string | undefined) || randomTitle()
+ const filePaths = await getFiles(root, {
+ respectGitignore: opts.respectGitignore,
+ respectDockerignore: opts.respectDockerignore,
+ })
+ if (!filePaths.length) {
+ console.log(stripIndent`
+ No files found in ${asLocalRelative(root)}.
+ Note that .gitignore and .dockerignore files are respected by default,
+ use --respect-gitignore=false and --respect-dockerignore=false to override.
+ `)
+ return
}
- if (opts.config) {
- console.log(
- `Creating new environment titled "${title}" from ${asTemplate`[${template}]`} template with config ${asLocalRelative(
- configPath,
- )}`,
- )
- } else {
- console.log(
- `Creating new environment titled "${title}" from ${asTemplate`[${template}]`} template`,
- )
- }
+ // const hash = getFilesHash(files) // TODO: Future
+ console.log('📦 Files to be uploaded to create environment:')
+ filePaths.map(filePath => {
+ console.log(`• ${filePath.rootPath}`)
+ })
+
+ // TODO: Create in temp dir
+ const tarPath = 'env.tar.gz'
- const config = await createEnvironment({
- template,
- title,
- apiKey,
+ await packToTar(
root,
- shouldSaveConfig: opts.config,
- })
- console.log(
- `Environment ${asFormattedEnvironment(
- config,
- opts.config ? configPath : undefined,
- )} created\n`,
+ filePaths.map(({ rootPath }) => rootPath),
+ tarPath,
)
- } catch (err: any) {
- console.error(asFormattedError(err.message))
+
+ if (!fs.existsSync(tarPath)) throw new Error(`Tar file ${tarPath} does not exist`)
+
+ const buildContextBlob = new Blob([fs.readFileSync(tarPath)], {
+ type: 'application/gzip',
+ })
+ let dockerfileContent
+ if (fs.existsSync(`${root}/Dockerfile`)) {
+ dockerfileContent = fs.readFileSync(`${root}/Dockerfile`, 'utf-8')
+ }
+
+ // TODO: Use SDK client
+ // client.path('/envs').method('post').create(...)
+
+ const formData = new FormData()
+ formData.append('buildContext', buildContextBlob, 'env.tar.gz.e2b')
+ if (dockerfileContent) formData.append('dockerfile', dockerfileContent)
+ // if (envID) formData.append('envID', envID); // TODO: Future
+
+ const apiRes = await fetch(`${apiBaseUrl}/envs`, {
+ method: 'POST',
+ headers: { Authorization: `Bearer ${accessToken}` },
+ body: formData,
+ })
+
+ if (!apiRes.ok) {
+ const resJson = (await apiRes.json()) as { message: string }
+ throw new Error(`API request failed: ${apiRes.statusText}, ${resJson?.message ?? 'no message'}`)
+ }
+ const resJson = (await apiRes.json()) as { envID: string, Public: boolean, Status: 'building' | 'error' | 'ready' }
+ console.log(`✅ Env created: ${resJson?.envID}, waiting for build to finish...`)
+
+ let startedAt = new Date()
+ let completed = false
+ while (!completed) {
+ await wait(5000)
+ const apiResPoll = await fetch(`${apiBaseUrl}/envs/${resJson?.envID}`, {
+ method: 'GET',
+ headers: { Authorization: `Bearer ${accessToken}` },
+ })
+ if (!apiResPoll.ok) throw new Error(`API request failed: ${apiResPoll.statusText}`)
+ const env = (await apiResPoll.json()) as { status: string, created_at: string }
+ if (env.status === 'building') {
+ const now = new Date()
+ const elapsed = now.getTime() - startedAt.getTime()
+ const elapsedStr = `${Math.floor(elapsed / 1000)}s`
+ console.log(`⏳ Building… (started ${elapsedStr} ago)`) // nicer
+ if (elapsed > 1000 * 60 * 2) { // TODO
+ console.log(stripIndent`
+ ⚠️ Build taking longer than 2 minutes, something might be wrong.\n
+ Stopping to wait for result, but it might still finish -\n
+ Check by yourself by running ${asLocal(`e2b env list`)}\n
+ `)
+ completed = true
+ }
+ } else if (env.status === 'completed') {
+ completed = true
+ console.log(`✅ Build completed at ${env.created_at}`) // TODO: Nicer
+ }
+
+ }
+
+ // if (shouldSaveConfig) {
+ // await ensureDir(root)
+ // const configPath = getConfigPath(root)
+ // await saveConfig(configPath, config)
+ // }
+ } catch (err: unknown) {
+ console.error(asFormattedError((err as Error).message))
process.exit(1)
}
})
-export async function createEnvironment({
- template,
- title,
- apiKey,
- root,
- shouldSaveConfig,
-}: {
- template: string
- title?: string
- root: string
- apiKey: string
- shouldSaveConfig: boolean
-}): Promise<DevbookConfig> {
- const env = await createEnv({
- template,
- title,
- api_key: apiKey,
- })
+// TODO: Move to config/index.ts after refactoring
+// ===
+const envConfigSchema = yup.object({
+ id: yup.string().required(),
+ // TODO: Not MVP
+ // title: yup.string().default(randomTitle),
+ // filesystem: yup.object({
+ // change_hash: yup.string(),
+ // local_root: yup.string().required().default('./files'),
+ // }),
+})
- if (!env.ok) {
- throw new Error(
- `Failed to create new environment for template ${asTemplate`[${template}]`}`,
- )
- }
+export type EnvConfig = yup.InferType<typeof envConfigSchema>
- const config = configSchema.cast(env.data) as DevbookConfig
+async function saveConfig(configPath: string, config: EnvConfig, overwrite?: boolean) {
+ try {
+ if (!overwrite) {
+ const configExists = fs.existsSync(configPath)
+ if (configExists)
+ throw new Error(`Config already exists on path ${asLocalRelative(configPath)}`)
+ }
- if (shouldSaveConfig) {
- await ensureDir(root)
- const configPath = getConfigPath(root)
- await saveConfig(configPath, config)
+ const validatedConfig: any = await envConfigSchema.validate(config, {
+ stripUnknown: true,
+ })
+ const jsonRaw = JSON.stringify(validatedConfig, null, 2)
+ await fsPromise.writeFile(configPath, jsonRaw)
+ } catch (err: any) {
+ throw new Error(
+ `e2b environment config ${asFormattedEnvironment(
+ config,
+ configPath,
+ )} cannot be saved: ${err.message}`,
+ )
}
+}
- return config
+// TODO: Move to utils after refactoring
+// ===
+const deleteFile = async (filePath: string) => {
+ const stat = await fs.promises.stat(filePath)
+ if (stat.isFile()) await fs.promises.unlink(filePath)
}
-const createEnv = client.path('/envs').method('post').create({ api_key: true })
+const wait = (ms: number) => new Promise(resolve => setTimeout(resolve, ms))
diff --git a/packages/cli/src/commands/env/delete.ts b/packages/cli/src/commands/env/delete.ts
deleted file mode 100644
index a2fd53e50..000000000
--- a/packages/cli/src/commands/env/delete.ts
+++ /dev/null
@@ -1,115 +0,0 @@
-import * as commander from 'commander'
-import * as sdk from '@devbookhq/sdk'
-import * as chalk from 'chalk'
-
-import { client, ensureAPIKey } from 'src/api'
-import { confirm } from 'src/interactions/confirm'
-import { getPromptEnvs } from 'src/interactions/envs'
-import { listEnvironments } from './list'
-import {
- asFormattedEnvironment,
- asFormattedError,
- asLocal,
- asLocalRelative,
-} from 'src/utils/format'
-import { allOption, pathOption, selectMultipleOption } from 'src/options'
-import { configName, deleteConfig, loadConfigs } from 'src/config'
-import { getRoot } from 'src/utils/filesystem'
-import { idsArgument } from 'src/arguments'
-
-export const deleteCommand = new commander.Command('delete')
- .description(`Delete environment and ${asLocal(configName)} config`)
- .addArgument(idsArgument)
- .addOption(selectMultipleOption)
- .addOption(pathOption)
- .addOption(allOption)
- .alias('dl')
- .option(
- '-k, --keep-config',
- `Keep ${asLocal(configName)} config in local filesystem after deleting environment`,
- )
- .option('-y, --yes', 'Skip manual delete confirmation')
- .action(async (ids, opts) => {
- try {
- const apiKey = ensureAPIKey()
-
- const root = getRoot(opts.path)
-
- let envs:
- | (sdk.components['schemas']['Environment'] & { configPath?: string })[]
- | undefined
-
- if (ids.length > 0) {
- envs = ids.map((id: string) => ({ id }))
-
- if (!envs || envs.length === 0) {
- console.log('No environments selected')
- return
- }
- } else if (opts.select) {
- const allEnvs = await listEnvironments({ apiKey })
- envs = await getPromptEnvs(allEnvs, 'Select environments to delete')
-
- if (!envs || envs.length === 0) {
- console.log('No environments selected')
- return
- }
- } else {
- const localConfigs = await loadConfigs(root, opts.all)
- if (localConfigs.length > 0) {
- envs = localConfigs
- }
- if (!envs || envs.length === 0) {
- console.log(
- `No environments found in ${asLocalRelative(root)}${
- opts.all ? ' and its subdirectories' : ''
- }`,
- )
- return
- }
- }
-
- console.log(chalk.default.red(chalk.default.underline('\nEnvironments to delete')))
- envs.forEach(e => console.log(asFormattedEnvironment(e, e.configPath)))
- process.stdout.write('\n')
-
- if (!opts.yes) {
- const confirmed = await confirm(
- `Do you really want to delete ${
- envs.length === 1 ? 'this environment' : 'these environments'
- }?`,
- )
-
- if (!confirmed) {
- console.log('Canceled')
- return
- }
- }
-
- await Promise.all(
- envs.map(async e => {
- console.log(`- Deleting environment ${asFormattedEnvironment(e, e.configPath)}`)
- await deleteEnvironment({ apiKey, id: e.id })
- if (!opts.keepConfig && e.configPath) {
- await deleteConfig(e.configPath)
- }
- }),
- )
- process.stdout.write('\n')
- } catch (err: any) {
- console.error(asFormattedError(err.message))
- process.exit(1)
- }
- })
-
-export async function deleteEnvironment({ id, apiKey }: { id: string; apiKey: string }) {
- await deleteEnv({
- api_key: apiKey,
- codeSnippetID: id,
- })
-}
-
-const deleteEnv = client
- .path('/envs/{codeSnippetID}')
- .method('delete')
- .create({ api_key: true })
diff --git a/packages/cli/src/commands/env/index.ts b/packages/cli/src/commands/env/index.ts
index 2a53e7618..0ca72dc47 100644
--- a/packages/cli/src/commands/env/index.ts
+++ b/packages/cli/src/commands/env/index.ts
@@ -1,24 +1,12 @@
import * as commander from 'commander'
-import { deleteCommand } from './delete'
import { createCommand } from './create'
import { listCommand } from './list'
-import { publishCommand } from './publish'
-import { pushCommand } from './push'
-import { connectCommand } from './connect'
-import { useCommand } from './use'
-import { asLocal } from 'src/utils/format'
-import { configName } from 'src/config'
-import { setCommand } from './set'
+import { shellCommand } from './shell'
export const envCommand = new commander.Command('env')
- .description(`Manage e2b environments and their ${asLocal(configName)} configs`)
+ .description(`Manage e2b environments`)
.addCommand(createCommand)
- .addCommand(pushCommand)
- .addCommand(publishCommand)
- .addCommand(deleteCommand)
- .addCommand(useCommand)
- .addCommand(connectCommand)
.addCommand(listCommand)
- .addCommand(setCommand)
+ .addCommand(shellCommand)
.alias('environment')
diff --git a/packages/cli/src/commands/env/list.ts b/packages/cli/src/commands/env/list.ts
index 5ec461a94..4d8b9e2cf 100644
--- a/packages/cli/src/commands/env/list.ts
+++ b/packages/cli/src/commands/env/list.ts
@@ -1,87 +1,38 @@
import * as chalk from 'chalk'
import * as commander from 'commander'
-
-import { client, ensureAPIKey } from 'src/api'
-import { configName, getNestedConfigs, loadConfig } from 'src/config'
-import { pathOption } from 'src/options'
-import { getRoot } from 'src/utils/filesystem'
-import { asFormattedEnvironment, asFormattedError, asLocal } from 'src/utils/format'
-import { assertFulfilled, assertRejected } from 'src/utils/promise'
+import { apiBaseUrl, ensureAccessToken } from 'src/api'
+import { asFormattedError } from 'src/utils/format'
import { sortEnvs } from 'src/utils/sort'
export const listCommand = new commander.Command('list')
- .description('List available environments')
- .addOption(pathOption)
- .option(
- '-n, --no-local',
- `Don't scan local filesystem for environment ${asLocal(configName)} configs`,
- )
+ .description('List environments')
.alias('ls')
- .action(async opts => {
+ .action(async () => {
try {
- const apiKey = ensureAPIKey()
+ const accessToken = ensureAccessToken()
process.stdout.write('\n')
- const root = getRoot(opts.path)
-
- const envsPromise = listEnvironments({ apiKey })
- const configsPromise = opts.local
- ? getNestedConfigs(root).then(configPaths =>
- Promise.allSettled(
- configPaths.map(async c => ({
- config: await loadConfig(c.path),
- configPath: c.path,
- })),
- ),
- )
- : Promise.resolve([])
-
- const [envs, configs] = await Promise.all([envsPromise, configsPromise])
-
- const fulfilledConfigs = configs.filter(assertFulfilled)
-
- console.log(chalk.default.underline(chalk.default.green('Environments')))
-
- envs.sort(sortEnvs).forEach(env => {
- const configIdx = fulfilledConfigs.findIndex(c => c.value.config.id === env.id)
-
- const config =
- configIdx > -1 ? fulfilledConfigs.splice(configIdx, 1).pop() : undefined
-
- console.log(asFormattedEnvironment(env, config?.value.configPath))
+ // TODO: Use client
+ // const envs = await client.path('/envs').method('get').create()({ accessToken }).data
+ const apiRes = await fetch(`${apiBaseUrl}/envs`, {
+ method: 'GET',
+ headers: { Authorization: `Bearer ${accessToken}` },
})
+ const envs = await apiRes.json()
- const rejectedConfigs = configs.filter(assertRejected)
- if (rejectedConfigs.length > 0) {
- rejectedConfigs.forEach(c => {
- console.error(asFormattedError(c.reason))
- })
- }
-
- if (fulfilledConfigs.length > 0) {
- console.log(
- chalk.default.underline(
- chalk.default.red('\nConfigs without existing environments'),
- ),
- )
- fulfilledConfigs.forEach(c => {
- console.log(asFormattedEnvironment(c.value.config, c.value.configPath))
+ console.log(chalk.default.underline(chalk.default.green('Environments')))
+
+ if (!envs?.length) {
+ console.log('No environments found')
+ } else {
+ envs.sort(sortEnvs).forEach((env: { envID: string }) => {
+ console.log(env.envID)
})
}
process.stdout.write('\n')
- } catch (err: any) {
- console.error(asFormattedError(err.message))
+ } catch (err: unknown) {
+ console.error(asFormattedError((err as Error).message))
process.exit(1)
}
})
-
-export async function listEnvironments({ apiKey }: { apiKey: string }) {
- const result = await listEnvs({
- api_key: apiKey,
- })
-
- return result.data
-}
-
-const listEnvs = client.path('/envs').method('get').create()
diff --git a/packages/cli/src/commands/env/publish.ts b/packages/cli/src/commands/env/publish.ts
deleted file mode 100644
index feb669650..000000000
--- a/packages/cli/src/commands/env/publish.ts
+++ /dev/null
@@ -1,90 +0,0 @@
-import * as sdk from '@devbookhq/sdk'
-import * as commander from 'commander'
-
-import { client, ensureAPIKey } from 'src/api'
-import { idsArgument } from 'src/arguments'
-import { loadConfigs } from 'src/config'
-import { getPromptEnvs } from 'src/interactions/envs'
-import { allOption, pathOption, selectMultipleOption } from 'src/options'
-import { getRoot } from 'src/utils/filesystem'
-import {
- asFormattedEnvironment,
- asFormattedError,
- asLocalRelative,
-} from 'src/utils/format'
-import { listEnvironments } from './list'
-
-export const publishCommand = new commander.Command('publish')
- .description('Make latest version of environment publicly available')
- .addArgument(idsArgument)
- .addOption(selectMultipleOption)
- .addOption(pathOption)
- .addOption(allOption)
- .alias('pb')
- .action(async (ids, opts) => {
- try {
- const apiKey = ensureAPIKey()
- process.stdout.write('\n')
-
- const root = getRoot(opts.path)
-
- let envs:
- | (sdk.components['schemas']['Environment'] & { configPath?: string })[]
- | undefined
-
- if (ids.length > 0) {
- envs = ids.map((id: string) => ({ id }))
-
- if (!envs || envs.length === 0) {
- console.log('No environments selected')
- return
- }
- } else if (opts.select) {
- const allEnvs = await listEnvironments({ apiKey })
- envs = await getPromptEnvs(allEnvs, 'Select environments to publish')
-
- if (!envs || envs.length === 0) {
- console.log('No environments selected')
- return
- }
- } else {
- const localConfigs = await loadConfigs(root, opts.all)
- if (localConfigs.length > 0) {
- envs = localConfigs
- }
- if (!envs || envs.length === 0) {
- console.log(
- `No environments found in ${asLocalRelative(root)}${
- opts.all ? ' and its subdirectories' : ''
- }`,
- )
- return
- }
- }
-
- await Promise.all(
- envs.map(async e => {
- console.log(
- `- Publishing environment ${asFormattedEnvironment(e, e.configPath)}`,
- )
- await publishEnvironment({ apiKey, id: e.id })
- }),
- )
- process.stdout.write('\n')
- } catch (err: any) {
- console.error(asFormattedError(err.message))
- process.exit(1)
- }
- })
-
-export async function publishEnvironment({ id, apiKey }: { id: string; apiKey: string }) {
- await publishEnv({
- api_key: apiKey,
- codeSnippetID: id,
- })
-}
-
-const publishEnv = client
- .path('/envs/{codeSnippetID}')
- .method('patch')
- .create({ api_key: true })
diff --git a/packages/cli/src/commands/env/push.ts b/packages/cli/src/commands/env/push.ts
deleted file mode 100644
index 3af5ffb24..000000000
--- a/packages/cli/src/commands/env/push.ts
+++ /dev/null
@@ -1,189 +0,0 @@
-import * as sdk from '@devbookhq/sdk'
-import * as chalk from 'chalk'
-import * as commander from 'commander'
-import { existsSync } from 'fs'
-import * as fsPromise from 'fs/promises'
-import * as path from 'path'
-
-import { client, ensureAPIKey } from 'src/api'
-import { DevbookConfig, configName, saveConfig, loadConfigs } from 'src/config'
-import { allOption, pathOption } from 'src/options'
-import { getFiles, getRoot } from 'src/utils/filesystem'
-import {
- asDim,
- asFormattedEnvironment,
- asFormattedError,
- asEnv,
- asLocal,
- asLocalRelative,
-} from 'src/utils/format'
-import { getFilesHash } from 'src/utils/hashing'
-
-export const pushCommand = new commander.Command('push')
- .description(`Update files in environment according to ${asLocal(configName)} config`)
- .addOption(allOption)
- .addOption(pathOption)
- .option('-h, --hash', 'Update files only if their hash changed since last push')
- .alias('ps')
- .action(async opts => {
- try {
- const apiKey = ensureAPIKey()
- process.stdout.write('\n')
-
- const root = getRoot(opts.path)
-
- const configs = await loadConfigs(root, opts.all)
-
- if (configs.length === 0) {
- console.log(
- `No environments found in ${asLocalRelative(root)}${
- opts.all ? ' and its subdirectories' : ''
- }`,
- )
- return
- }
-
- await Promise.all(
- configs.map(async config => {
- console.log(
- `- Pushing environment ${asFormattedEnvironment(config, config.configPath)}`,
- )
- await pushEnvironment({
- apiKey,
- root: path.dirname(config.configPath),
- config,
- configPath: config.configPath,
- hash: opts.hash,
- })
- }),
- )
- process.stdout.write('\n')
- // We explicitly call exit because the session is keeping the program alive.
- // We also don't want to call session.close because that would disconnect other users from the edit session.
- process.exit(0)
- } catch (err: any) {
- console.error(asFormattedError(err.message))
- process.exit(1)
- }
- })
-
-export async function pushEnvironment({
- apiKey,
- root,
- config,
- hash,
- configPath,
-}: {
- apiKey: string
- root: string
- configPath: string
- config: DevbookConfig
- hash?: boolean
-}): Promise<DevbookConfig> {
- try {
- await updateEnvTitle({
- api_key: apiKey,
- codeSnippetID: config.id,
- title: config.title,
- })
- } catch (err: any) {
- throw new Error(
- `Error updating environment from config ${asLocalRelative(configPath)}: ${
- err.message
- }`,
- )
- }
-
- try {
- const envFilesDir = path.join(root, config.filesystem.local_root)
-
- if (!existsSync(envFilesDir)) {
- throw new Error(
- `Directory ${asLocalRelative(
- envFilesDir,
- )} defined in "filesystem.local_root" field in ${asLocalRelative(
- configPath,
- )} config does not exist`,
- )
- }
-
- const filePaths = await getFiles(envFilesDir)
-
- let newChangeHash: string | undefined
-
- if (filePaths.length > 0) {
- console.log(
- ' ',
- chalk.default.underline(
- `Syncing ${filePaths.length} ${
- filePaths.length === 1 ? 'file' : 'files'
- } from ${asLocalRelative(envFilesDir)} directory`,
- ),
- )
-
- const files = await Promise.all(
- filePaths.map(async f => {
- const content = await fsPromise.readFile(f.path, 'utf-8')
- return {
- ...f,
- content,
- }
- }),
- )
-
- if (hash) {
- newChangeHash = getFilesHash(files)
-
- if (config.filesystem.change_hash === newChangeHash) {
- console.log(` Directory ${asLocalRelative(envFilesDir)} is already in sync`)
- return config
- }
- }
-
- const session = new sdk.Session({
- apiKey,
- editEnabled: true,
- id: config.id,
- })
-
- // TODO: Delete files that should not be in the final destination
-
- await session.open()
- await Promise.all(
- files.map(async f => {
- const content = await fsPromise.readFile(f.path, 'utf-8')
- console.log(
- ` - ${asLocalRelative(f.path)} ${asDim('(local)')} ${asDim('-->')} ${asEnv(
- f.rootPath,
- )} ${asDim('(env)')}`,
- )
- await session.filesystem?.makeDir(path.dirname(f.rootPath))
- await session.filesystem?.write(f.rootPath, content)
- }),
- )
- }
-
- const newConfig = {
- ...config,
- filesystem: {
- ...config.filesystem,
- change_hash: config.filesystem.change_hash || newChangeHash,
- },
- }
-
- await saveConfig(configPath, newConfig, true)
-
- return newConfig
- } catch (err: any) {
- throw new Error(
- `Error updating environment from config ${asLocalRelative(configPath)}: ${
- err.message
- }`,
- )
- }
-}
-
-const updateEnvTitle = client
- .path('/envs/{codeSnippetID}/title')
- .method('put')
- .create({ api_key: true })
diff --git a/packages/cli/src/commands/env/set.ts b/packages/cli/src/commands/env/set.ts
deleted file mode 100644
index 399f6ee19..000000000
--- a/packages/cli/src/commands/env/set.ts
+++ /dev/null
@@ -1,131 +0,0 @@
-import * as sdk from '@devbookhq/sdk'
-import * as chalk from 'chalk'
-import * as commander from 'commander'
-
-import { ensureAPIKey } from 'src/api'
-import { idArgument } from 'src/arguments'
-import { getPromptEnv, getRootEnv } from 'src/interactions/envs'
-import { pathOption, selectOption } from 'src/options'
-import { getRoot } from 'src/utils/filesystem'
-import {
- asBold,
- asFormattedEnvironment,
- asFormattedError,
- asLocalRelative,
-} from 'src/utils/format'
-import { listEnvironments } from './list'
-
-const envVarScriptPath = '/etc/profile.d/env-vars.sh'
-
-export const setCommand = new commander.Command('set')
- .description('Set env vars in environment')
- .addArgument(idArgument)
- .addOption(selectOption)
- .addOption(pathOption)
- .option(
- '-e, --env-vars <KEY=VALUE...>',
- `Set provided ${asBold('<KEY=VALUE...>')} pairs as env vars in environment`,
- )
- .alias('st')
- .action(async (id, opts) => {
- try {
- const apiKey = ensureAPIKey()
- process.stdout.write('\n')
-
- const root = getRoot(opts.path)
- let isLocal = false
-
- let env: sdk.components['schemas']['Environment'] | undefined
- if (id) {
- env = { id }
- } else if (opts.select) {
- const envs = await listEnvironments({ apiKey })
- env = await getPromptEnv(envs, 'Select environment to set vars in')
- } else {
- env = await getRootEnv(root)
- if (env) {
- isLocal = true
- }
- }
-
- if (!env) {
- console.log(`No environments found in ${asLocalRelative(root)}`)
- return
- }
-
- if (!opts.envVars || opts.envVars.length === 0) {
- console.log('No env vars provided')
- return
- }
-
- const invalidEnvVars = (opts.envVars as string[]).filter(e => e.indexOf('=') === -1)
- if (invalidEnvVars.length > 0) {
- console.log(
- chalk.default.underline(
- `The following ${
- invalidEnvVars.length === 1 ? 'env var is' : 'env vars are'
- } missing ${asBold('=')} betwen the ${asBold('KEY')} and ${asBold('VALUE')}:`,
- ),
- )
-
- invalidEnvVars.forEach(e =>
- console.log('- ' + chalk.default.bold(chalk.default.red(e)) + '\n'),
- )
-
- return
- }
-
- console.log(
- `Setting ${opts.envVars.length} env ${
- opts.envVars.length === 1 ? 'var' : 'vars'
- } in environment ${asFormattedEnvironment(env, isLocal ? root : undefined)}`,
- )
-
- await setEnvVars({
- apiKey,
- config: env,
- published: !!opts.published,
- envVars: opts.envVars,
- })
-
- console.log(
- `${opts.envVars.length} env ${
- opts.envVars.length === 1 ? 'var' : 'vars'
- } in environment ${asFormattedEnvironment(
- env,
- isLocal ? root : undefined,
- )} set\n`,
- )
-
- // We explicitly call exit because the session is keeping the program alive.
- // We also don't want to call session.close because that would disconnect other users from the edit session.
- process.exit(0)
- } catch (err: any) {
- console.error(asFormattedError(err.message))
- process.exit(1)
- }
- })
-
-export async function setEnvVars({
- apiKey,
- config,
- envVars,
- published,
-}: {
- envVars: string[]
- apiKey: string
- config: sdk.components['schemas']['Environment']
- published: boolean
-}) {
- const session = new sdk.Session({
- apiKey,
- editEnabled: !published,
- id: config.id,
- })
-
- await session.open()
-
- const envsString = envVars.map(envVar => `export ${envVar}`).join('\n')
-
- await session.filesystem?.write(envVarScriptPath, envsString)
-}
diff --git a/packages/cli/src/commands/env/connect.ts b/packages/cli/src/commands/env/shell.ts
similarity index 71%
rename from packages/cli/src/commands/env/connect.ts
rename to packages/cli/src/commands/env/shell.ts
index d5c3a984b..652e9e49a 100644
--- a/packages/cli/src/commands/env/connect.ts
+++ b/packages/cli/src/commands/env/shell.ts
@@ -1,10 +1,9 @@
-import * as sdk from '@devbookhq/sdk'
+import * as sdk from '@e2b/sdk'
import * as commander from 'commander'
-
import { ensureAPIKey } from 'src/api'
import { idArgument } from 'src/arguments'
-import { getPromptEnv, getRootEnv } from 'src/interactions/envs'
import { pathOption, selectOption } from 'src/options'
+import { spawnConnectedTerminal } from 'src/terminal'
import { getRoot } from 'src/utils/filesystem'
import {
asBold,
@@ -12,39 +11,39 @@ import {
asFormattedError,
asLocalRelative,
} from 'src/utils/format'
-import { spawnConnectedTerminal } from 'src/terminal'
-import { listEnvironments } from './list'
-export const connectCommand = new commander.Command('connect')
+export const shellCommand = new commander.Command('shell')
.description('Connect terminal to environment')
.addArgument(idArgument)
.addOption(selectOption)
.addOption(pathOption)
.alias('cn')
- .option('-P, --published', 'Connect to new instance of published environment')
.option(
'-L, --local-debug',
'Connect to existing local environment instance for debugging',
)
.action(async (id, opts) => {
try {
- const apiKey = opts.published ? undefined : ensureAPIKey()
+ const apiKey = ensureAPIKey()
const root = getRoot(opts.path)
if (opts.localDebug) {
- await connectEnvironment({ local: true, config: { id: 'local-debug' } })
+ await connectEnvironment({ apiKey, local: true, config: { id: 'local-debug' } })
return
}
- let env: sdk.components['schemas']['Environment'] | undefined
+ // let env: sdk.components['schemas']['Environment'] | undefined
+ let env: any
if (id) {
env = { id }
} else if (opts.select) {
- const apiKey = ensureAPIKey()
- const envs = await listEnvironments({ apiKey })
- env = await getPromptEnv(envs, 'Select environment to connect to')
+ throw new Error('Selecting is not yet implemented')
+ // const apiKey = ensureAPIKey()
+ // const envs = await listEnvironments({ apiKey })
+ // env = await getPromptEnv(envs, 'Select environment to connect to')
} else {
- env = await getRootEnv(root)
+ throw new Error(`No environment ID provided, use "e2b env shell --id <envID>"`)
+ // env = await getRootEnv(root)
}
if (!env) {
@@ -52,7 +51,7 @@ export const connectCommand = new commander.Command('connect')
return
}
- await connectEnvironment({ apiKey, config: env, published: !!opts.published })
+ await connectEnvironment({ apiKey, config: env })
// We explicitly call exit because the session is keeping the program alive.
// We also don't want to call session.close because that would disconnect other users from the edit session.
process.exit(0)
@@ -65,17 +64,14 @@ export const connectCommand = new commander.Command('connect')
export async function connectEnvironment({
apiKey,
config,
- published,
local,
}: {
- apiKey?: string
+ apiKey: string
local?: boolean
config: sdk.components['schemas']['Environment']
- published?: boolean
}) {
const session = new sdk.Session({
apiKey,
- editEnabled: !published,
id: config.id,
...(local
? {
@@ -86,7 +82,7 @@ export async function connectEnvironment({
: {}),
})
- await session.open()
+ await session.open({})
if (session.terminal) {
const { exited } = await spawnConnectedTerminal(
diff --git a/packages/cli/src/commands/env/use.ts b/packages/cli/src/commands/env/use.ts
deleted file mode 100644
index 91a1c4549..000000000
--- a/packages/cli/src/commands/env/use.ts
+++ /dev/null
@@ -1,91 +0,0 @@
-import * as sdk from '@devbookhq/sdk'
-import * as commander from 'commander'
-import * as fs from 'fs'
-
-import { ensureAPIKey } from 'src/api'
-import {
- configSchema,
- DevbookConfig,
- saveConfig,
- configName,
- getConfigPath,
-} from 'src/config'
-import { listEnvironments } from './list'
-import { getRoot, ensureDir } from 'src/utils/filesystem'
-import { pathOption, selectOption } from 'src/options'
-import { getPromptEnv } from 'src/interactions/envs'
-import {
- asFormattedEnvironment,
- asFormattedError,
- asLocal,
- asLocalRelative,
-} from 'src/utils/format'
-import { idArgument } from 'src/arguments'
-
-export const useCommand = new commander.Command('use')
- .description(`Create ${asLocal(configName)} config for existing environment`)
- .addArgument(idArgument)
- .addOption(selectOption)
- .alias('us')
- .addOption(pathOption)
- .action(async (id, opts) => {
- try {
- const apiKey = ensureAPIKey()
- process.stdout.write('\n')
-
- const root = getRoot(opts.path)
-
- const configPath = getConfigPath(root)
- if (fs.existsSync(configPath)) {
- throw new Error(
- `Devbook config ${asLocalRelative(
- configPath,
- )} already exists - cannot create config`,
- )
- }
-
- let env: sdk.components['schemas']['Environment'] | undefined
- const envs = await listEnvironments({ apiKey })
- if (id) {
- env = envs.find(e => e.id === id)
- } else {
- env = await getPromptEnv(
- envs,
- `Select environment to create ${asLocalRelative(configPath)} config for`,
- )
- }
-
- if (!env) {
- console.log('No environments found')
- return
- }
-
- console.log(
- `Creating config for environment ${asFormattedEnvironment(env, configPath)}`,
- )
-
- await ensureDir(root)
- await useEnvironment({
- configPath,
- env,
- })
- console.log(
- `Config for environment ${asFormattedEnvironment(env, configPath)} created`,
- )
- process.stdout.write('\n')
- } catch (err: any) {
- console.error(asFormattedError(err.message))
- process.exit(1)
- }
- })
-
-export async function useEnvironment({
- configPath,
- env,
-}: {
- configPath: string
- env: sdk.components['schemas']['Environment']
-}) {
- const configWithDefaults = configSchema.cast(env) as DevbookConfig
- await saveConfig(configPath, configWithDefaults)
-}
diff --git a/packages/cli/src/commands/index.ts b/packages/cli/src/commands/index.ts
index fe8952649..74d5d3a32 100644
--- a/packages/cli/src/commands/index.ts
+++ b/packages/cli/src/commands/index.ts
@@ -1,12 +1,10 @@
import * as commander from 'commander'
-// import { envCommand } from './env'
-// import { runCommand } from './run'
import { loginCommand, logoutCommand } from './auth'
+import { envCommand } from './env'
export const program = new commander.Command()
.description('Tool for interacting with e2b from command line')
- // .addCommand(envCommand, { isDefault: true }) // Re-enable later
- // .addCommand(runCommand, { hidden: true }) // Re-enable later
+ .addCommand(envCommand)
.addCommand(loginCommand)
.addCommand(logoutCommand)
diff --git a/packages/cli/src/commands/run.ts b/packages/cli/src/commands/run.ts
deleted file mode 100644
index 18c0af5bd..000000000
--- a/packages/cli/src/commands/run.ts
+++ /dev/null
@@ -1,244 +0,0 @@
-import * as sdk from '@devbookhq/sdk'
-import * as commander from 'commander'
-import chokidar from 'chokidar'
-import fs from 'fs/promises'
-import path from 'path'
-import parseGitignore from 'parse-gitignore'
-
-import { DevbookConfig } from 'src/config'
-import { pathOption } from 'src/options'
-import { spawnConnectedTerminal } from 'src/terminal'
-import { getRoot } from 'src/utils/filesystem'
-import { asFormattedEnvironment, asFormattedError, asBold } from 'src/utils/format'
-import { createDeferredPromise } from 'src/utils/promise'
-
-const rootdir = '/code'
-const envID = 'QFNlQVCzcKxD'
-
-export const runCommand = new commander.Command('run')
- .description('Start remote development')
- .addOption(pathOption)
- .alias('rn')
- .action(async opts => {
- let stopSyncing: (() => Promise<void>) | undefined
- try {
- process.stdout.write('\n')
-
- const root = getRoot(opts.path)
- const config: Pick<DevbookConfig, 'id'> = { id: envID }
-
- const session = new sdk.Session({
- id: config.id,
- })
-
- await session.open()
-
- stopSyncing = await keepEnvironmentInSync({
- root,
- filesystem: session.filesystem,
- })
-
- await startDevelopment({ session, config })
-
- process.stdout.write('\n')
- // We explicitly call exit because the session is keeping the program alive.
- // We also don't want to call session.close because that would disconnect other users from the edit session.
- await stopSyncing?.()
- process.exit(0)
- } catch (err: any) {
- console.error(asFormattedError(err.message))
- await stopSyncing?.()
- process.exit(1)
- }
- })
-
-export async function startDevelopment({
- session,
- config,
-}: {
- session: sdk.Session
- config: Pick<DevbookConfig, 'id'>
-}) {
- if (session.terminal) {
- const { exited } = await spawnConnectedTerminal(
- session.terminal,
- `Terminal connected to environment ${asFormattedEnvironment(
- config,
- )}\nwith session URL ${asBold(`https://${session.getHostname()}`)}`,
- `Disconnecting terminal from environment ${asFormattedEnvironment(config)}`,
- )
-
- await exited
- console.log(
- `Closing terminal connection to environment ${asFormattedEnvironment(config)}`,
- )
- } else {
- throw new Error('Cannot start terminal - no session')
- }
-}
-
-const defaultIgnoredPaths = [
- 'node_modules',
- '.venv',
- '.git',
- '__pycache__',
- '.DS_Store',
- '.vscode',
- '.idea',
-]
-
-async function ensureDirPath({
- root,
- dirPath,
- filesystem,
-}: {
- root: string
- dirPath: string
- filesystem: sdk.FilesystemManager
-}) {
- const dirs = dirPath
- .split(path.delimiter)
- .reduce(
- (paths, dirName) => {
- paths.push(path.join(paths[paths.length - 1], dirName))
- return paths
- },
- [root],
- )
- .slice(1)
-
- for (const dir of dirs) {
- await filesystem.makeDir(dir)
- }
-}
-
-export async function keepEnvironmentInSync({
- root,
- filesystem,
-}: {
- root: string
- filesystem?: sdk.FilesystemManager
-}) {
- if (!filesystem) {
- throw new Error('Session filesystem is not available')
- }
-
- let ignored = defaultIgnoredPaths
-
- try {
- const gitignore = await fs.readFile(path.join(root, '.gitignore'), 'utf-8')
- const patterns = parseGitignore(gitignore)
- ignored = (patterns as any).patterns
- } catch (err) {
- console.error(err)
- }
-
- const initialized = createDeferredPromise()
-
- const fsStack: (() => Promise<void>)[] = []
-
- async function processStackItem() {
- const item = fsStack.shift()
- console.log('processing stack item', item)
- if (item) {
- await item()
- }
- }
-
- const watcher = chokidar
- .watch('.', {
- persistent: true,
- ignored,
- // Upload the initial files (chokidar has option for this)
- ignoreInitial: false,
- followSymlinks: true,
- cwd: root,
- disableGlobbing: false,
-
- usePolling: false,
- interval: 100,
- binaryInterval: 300,
- alwaysStat: false,
- depth: 99,
- awaitWriteFinish: {
- stabilityThreshold: 2000,
- pollInterval: 100,
- },
- ignorePermissionErrors: false,
- atomic: true, // or a custom 'atomicity delay', in milliseconds (default 100)
- })
- .on('ready', () => {
- console.log('ready')
- initialized.resolve()
- })
- .on('change', async p => {
- console.log('change', p)
- const handleChange = async () => {
- try {
- const content = await fs.readFile(path.join(root, p), 'utf-8')
- await ensureDirPath({ root: rootdir, dirPath: path.dirname(p), filesystem })
- await filesystem.write(path.join(rootdir, p), content)
- } catch (err) {
- console.error(err)
- }
- }
- fsStack.push(handleChange)
- processStackItem()
- })
- .on('add', async p => {
- console.log('add', p)
-
- const handleAdd = async () => {
- try {
- const content = await fs.readFile(path.join(root, p), 'utf-8')
- await ensureDirPath({ root: rootdir, dirPath: path.dirname(p), filesystem })
- await filesystem.write(path.join(rootdir, p), content)
- } catch (err) {
- console.error(err)
- }
- }
- fsStack.push(handleAdd)
- processStackItem()
- })
- .on('addDir', async p => {
- console.log('addDir', p)
- const handleAddDir = async () => {
- try {
- await ensureDirPath({ root, dirPath: path.dirname(p), filesystem })
- await filesystem.makeDir(path.join(rootdir, p))
- } catch (err) {
- console.error(err)
- }
- }
- fsStack.push(handleAddDir)
- processStackItem()
- })
- .on('unlink', async p => {
- console.log('unlink', p)
- const handleUnlink = async () => {
- try {
- await filesystem.remove(path.join(rootdir, p))
- } catch (err) {
- console.error(err)
- }
- }
- fsStack.push(handleUnlink)
- processStackItem()
- })
- .on('unlinkDir', async p => {
- console.log('unlinkDir', p)
- const handleUnlinkDir = async () => {
- try {
- await filesystem.remove(path.join(rootdir, p))
- } catch (err) {
- console.error(err)
- }
- }
- fsStack.push(handleUnlinkDir)
- processStackItem()
- })
-
- await initialized.promise
-
- return () => watcher.close()
-}
diff --git a/packages/cli/src/config/index.ts b/packages/cli/src/config/index.ts
index ec2ee07e1..baf9649f4 100644
--- a/packages/cli/src/config/index.ts
+++ b/packages/cli/src/config/index.ts
@@ -10,11 +10,9 @@ const dockerNames = require('docker-names')
import { getFiles } from '../utils/filesystem'
import { asFormattedEnvironment, asLocalRelative } from 'src/utils/format'
-export const configName = 'e2b.toml'
+export const configName = 'e2b.json'
-const configCommentHeader = `# This is a config for a e2b environment
-
-`
+const configCommentHeader = `# This is a config for a e2b environment`
export function randomTitle() {
return dockerNames.getRandomName().replace('_', '-')
diff --git a/packages/cli/src/terminal.ts b/packages/cli/src/terminal.ts
index 63bd6a992..7a5143334 100644
--- a/packages/cli/src/terminal.ts
+++ b/packages/cli/src/terminal.ts
@@ -1,4 +1,4 @@
-import * as sdk from '@devbookhq/sdk'
+import * as sdk from '@e2b/sdk'
import { createDeferredPromise } from './utils/promise'
@@ -10,7 +10,7 @@ function getStdoutSize() {
}
export async function spawnConnectedTerminal(
- manager: sdk.TerminalManager,
+ terminal: sdk.TerminalManager,
introText: string,
exitText: string,
) {
@@ -21,8 +21,8 @@ export async function spawnConnectedTerminal(
console.log(introText)
- const terminal = await manager.createSession({
- onData: data => process.stdout.write(data),
+ const terminalSession = await terminal.start({
+ onData: (data: any) => process.stdout.write(data),
size: getStdoutSize(),
onExit,
envVars: {
@@ -36,11 +36,11 @@ export async function spawnConnectedTerminal(
process.stdout.setEncoding('utf8')
const resizeListener = process.stdout.on('resize', () =>
- terminal.resize(getStdoutSize()),
+ terminalSession.resize(getStdoutSize()),
)
const stdinListener = process.stdin.on('data', data =>
- terminal.sendData(data.toString('utf8')),
+ terminalSession.sendData(data.toString('utf8')),
)
exited.then(() => {
@@ -50,7 +50,7 @@ export async function spawnConnectedTerminal(
})
return {
- destroy: terminal.destroy.bind(terminal),
+ // destroy: terminalSession.destroy.bind(terminalSession), FIXME
exited,
}
}
diff --git a/packages/cli/src/utils/filesystem.ts b/packages/cli/src/utils/filesystem.ts
index 7ea0c928a..e03f98a85 100644
--- a/packages/cli/src/utils/filesystem.ts
+++ b/packages/cli/src/utils/filesystem.ts
@@ -3,20 +3,57 @@ import * as path from 'path'
import * as util from 'util'
import * as fsPromise from 'fs/promises'
import * as fs from 'fs'
+import gitIgnore, { Ignore } from 'ignore';
+import dockerIgnore from "@balena/dockerignore";
+import tar from "tar-fs";
const walk = util.promisify(fsWalk.walk)
+/**
+ * Asynchronously retrieves files from a specified root path.
+ *
+ * @param rootPath - The root directory from which to retrieve files.
+ * @param opts - Optional parameters to filter the files by extension and/or name.
+ * @param opts.extension - If specified, only files with this extension will be returned.
+ * @param opts.name - If specified, only a file with this name will be returned.
+ * @param opts.respectGitignore - If true, files that are ignored by .gitignore will be excluded.
+ * @param opts.respectDockerignore - If true, files that are ignored by .dockerignore will be excluded.
+ */
export async function getFiles(
rootPath: string,
- opts?: { extension?: string; name?: string },
-) {
+ opts?: {
+ extension?: string;
+ name?: string;
+ respectGitignore?: boolean;
+ respectDockerignore?: boolean;
+}) {
+ let gitignore: Ignore | undefined;
+ if (opts?.respectGitignore) {
+ const gitignorePath = path.join(rootPath, '.gitignore');
+ if (fs.existsSync(gitignorePath)) {
+ gitignore = gitIgnore().add(fs.readFileSync(gitignorePath).toString());
+ }
+ }
+
+ let dockerignore: { ignores: (path: string) => boolean } | undefined;
+ if (opts?.respectDockerignore) {
+ const dockerignorePath = path.join(rootPath, '.dockerignore');
+ if (fs.existsSync(dockerignorePath)) {
+ const dockerIgnoreContent = fs.readFileSync(dockerignorePath, 'utf-8');
+ const dockerIgnoreLines = dockerIgnoreContent.split('\n').map(line => line.trim());
+ dockerignore = dockerIgnore().add(dockerIgnoreLines)
+ }
+ }
+
const entries = await walk(rootPath, {
entryFilter: e => {
- return (
- !!e.stats?.isFile() &&
- (opts?.extension ? e.name.endsWith(opts.extension) : true) &&
- (opts?.name ? e.name === opts.name : true)
- )
+ return [
+ !!e.stats?.isFile(),
+ opts?.extension ? e.name.endsWith(opts.extension) : true,
+ opts?.name ? e.name === opts.name : true,
+ !(gitignore && gitignore.ignores(path.relative(rootPath, e.path))),
+ !(dockerignore && dockerignore.ignores(path.relative(rootPath, e.path)))
+ ].every(Boolean)
},
stats: true,
})
@@ -34,15 +71,8 @@ export async function getFiles(
export function getRoot(envPath?: string) {
const defaultPath = process.cwd()
-
- if (!envPath) {
- return defaultPath
- }
-
- if (path.isAbsolute(envPath)) {
- return envPath
- }
-
+ if (!envPath) return defaultPath
+ if (path.isAbsolute(envPath)) return envPath
return path.resolve(defaultPath, envPath)
}
@@ -55,3 +85,15 @@ export async function ensureDir(dirPath: string) {
export function cwdRelative(absolutePath: string) {
return path.relative(process.cwd(), absolutePath)
}
+
+export const packToTar = (
+ rootPath: string,
+ filePaths: string[],
+ tarPath: string | Buffer | URL,
+) => new Promise((resolve, reject) => {
+ tar
+ .pack(rootPath, { entries: filePaths })
+ .pipe(fs.createWriteStream(tarPath))
+ .on('error', reject)
+ .on('finish', resolve);
+});
diff --git a/packages/cli/test/filesystem.test.ts b/packages/cli/test/filesystem.test.ts
new file mode 100644
index 000000000..38f0a5e62
--- /dev/null
+++ b/packages/cli/test/filesystem.test.ts
@@ -0,0 +1,11 @@
+import path from 'path'
+import { expect, test } from 'vitest'
+import * as e2bFs from '../src/utils/filesystem'
+
+test('getFiles(): empty-dir', async () => {
+ const files = await e2bFs.getFiles(
+ path.join(process.cwd(), 'test/fixtures/empty-dir'),
+ { respectGitignore: true, respectDockerignore: true }
+ )
+ expect(files).toEqual([])
+})
diff --git a/packages/cli/test/fixtures/complementing-ignore-files/.dockerignore b/packages/cli/test/fixtures/complementing-ignore-files/.dockerignore
new file mode 100644
index 000000000..539121bdb
--- /dev/null
+++ b/packages/cli/test/fixtures/complementing-ignore-files/.dockerignore
@@ -0,0 +1,5 @@
+.dockerignore
+.gitignore
+Dockerfile
+README.md
+assets-to-be-ignored
diff --git a/packages/cli/testground/demo-basic/.dockerignore b/packages/cli/testground/demo-basic/.dockerignore
new file mode 100644
index 000000000..ef4f590db
--- /dev/null
+++ b/packages/cli/testground/demo-basic/.dockerignore
@@ -0,0 +1 @@
+assets-to-be-ignored
diff --git a/packages/cli/testground/demo-basic/.gitignore b/packages/cli/testground/demo-basic/.gitignore
new file mode 100644
index 000000000..7f1083a69
--- /dev/null
+++ b/packages/cli/testground/demo-basic/.gitignore
@@ -0,0 +1,2 @@
+assets-to-be-ignored
+*.tar
diff --git a/packages/cli/testground/demo-basic/Dockerfile b/packages/cli/testground/demo-basic/Dockerfile
new file mode 100644
index 000000000..75375145f
--- /dev/null
+++ b/packages/cli/testground/demo-basic/Dockerfile
@@ -0,0 +1,19 @@
+FROM ubuntu:22.04
+
+# avoid asking for input
+ARG DEBIAN_FRONTEND=noninteractive
+
+# Update default packages
+RUN apt-get update
+
+# Get Ubuntu packages
+RUN apt-get install -y \
+ build-essential \
+ curl socat util-linux openssh-server git chrony nano sudo htop
+
+RUN curl -sL https://deb.nodesource.com/setup_16.x | bash -
+RUN apt-get install -y nodejs
+
+WORKDIR /code
+
+RUN npm init -y
diff --git a/packages/cli/testground/demo-basic/assets-to-be-ignored/cool-doge.gif b/packages/cli/testground/demo-basic/assets-to-be-ignored/cool-doge.gif
new file mode 100644
index 000000000..b0f776755
Binary files /dev/null and b/packages/cli/testground/demo-basic/assets-to-be-ignored/cool-doge.gif differ
diff --git a/packages/cli/testground/demo-basic/main.mjs b/packages/cli/testground/demo-basic/main.mjs
new file mode 100644
index 000000000..9c7f02af1
--- /dev/null
+++ b/packages/cli/testground/demo-basic/main.mjs
@@ -0,0 +1,4 @@
+// Console log current time with date-fns
+import { format } from 'date-fns';
+
+console.log(`Current time is ${format(new Date(), 'HH:mm:ss')}`);
diff --git a/packages/cli/testground/demo-basic/package.json b/packages/cli/testground/demo-basic/package.json
new file mode 100644
index 000000000..419ad013e
--- /dev/null
+++ b/packages/cli/testground/demo-basic/package.json
@@ -0,0 +1,5 @@
+{
+ "dependencies": {
+ "date-fns": "^2.30.0"
+ }
+}
diff --git a/packages/cli/tsconfig.json b/packages/cli/tsconfig.json
index 0162d76b7..2163e907a 100644
--- a/packages/cli/tsconfig.json
+++ b/packages/cli/tsconfig.json
@@ -2,7 +2,8 @@
"compilerOptions": {
"target": "ES2020",
"lib": [
- "ES2020"
+ "ES2020",
+ "webworker"
],
"module": "CommonJS",
"allowJs": true,
@@ -26,7 +27,10 @@
"outDir": "dist",
"baseUrl": ".",
"rootDirs": [
- "src",
+ "src"
],
+ "paths": {
+ "@e2b/sdk": ["../js-sdk/src"],
+ }
}
-}
\ No newline at end of file
+}
diff --git a/packages/cli/tsup.config.js b/packages/cli/tsup.config.js
index aa4ccf06a..b42c766ff 100644
--- a/packages/cli/tsup.config.js
+++ b/packages/cli/tsup.config.js
@@ -6,6 +6,7 @@ const excludedPackages = ['inquirer', 'update-notifier']
export default defineConfig({
entry: ['src/index.ts'],
+ shims: true, // Needed for "open" package, as it uses import.meta.url and we are building for cjs
target: 'node16',
platform: 'node',
format: 'cjs',
diff --git a/packages/cli/vitest.config.ts b/packages/cli/vitest.config.ts
new file mode 100644
index 000000000..049e466b9
--- /dev/null
+++ b/packages/cli/vitest.config.ts
@@ -0,0 +1,12 @@
+import { defineConfig } from 'vitest/config'
+
+export default defineConfig({
+ test: {
+ globals: false,
+ environment: 'node',
+ server: {},
+ deps: {
+ interopDefault: true,
+ },
+ },
+})
diff --git a/packages/js-sdk/src/index.ts b/packages/js-sdk/src/index.ts
index 458a27fc7..3a5f9e63d 100644
--- a/packages/js-sdk/src/index.ts
+++ b/packages/js-sdk/src/index.ts
@@ -1,3 +1,6 @@
+export { default as api } from './api'
+export type { ClientType, components } from './api'
+
export { Session } from './session'
export type { Environment } from './session'
export type { SessionOpts } from './session'