@vite-hub/sandbox 0.1.0 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (54) hide show
  1. package/README.md +118 -53
  2. package/dist/abortable-CR01hzfi.js +57 -0
  3. package/dist/cloudflare-Cog_r2Me.js +910 -0
  4. package/dist/cloudflare-env-lookup-DzI6Xv1Y.js +16 -0
  5. package/dist/cloudflare-failure-CFQhalfh.js +50 -0
  6. package/dist/container-CqfD8yuE.js +868 -0
  7. package/dist/{crabbox-BFCdf41h.js → crabbox-sbV3Zjuo.js} +10 -6
  8. package/dist/error-diagnostics-5QT_BjbQ.js +354 -0
  9. package/dist/error-diagnostics-BJtLRL9w.js +536 -0
  10. package/dist/{file-listing-DECFTdSl.js → file-listing-CHtRrfo1.js} +1 -1
  11. package/dist/{file-lock-CxyVl4Cv.js → file-lock-D0-XPogS.js} +3 -2
  12. package/dist/{index-CXej1Bt0.d.ts → index-DsoQAUb7.d.ts} +94 -19
  13. package/dist/index.d.ts +2 -2
  14. package/dist/index.js +15 -10
  15. package/dist/internal/cloudflare.d.ts +173 -1
  16. package/dist/internal/cloudflare.js +4 -12
  17. package/dist/internal/host-toolchain.d.ts +1 -1
  18. package/dist/internal/host-toolchain.js +6 -7
  19. package/dist/internal/vercel.d.ts +1 -1
  20. package/dist/internal/vercel.js +3 -11
  21. package/dist/invariant-DolT9EEx.js +22 -0
  22. package/dist/module-types-B0LQ5H2S.js +7 -0
  23. package/dist/module-types-DCeJbS9Z.d.ts +110 -0
  24. package/dist/process-sweep-CMaujWE5.js +33 -0
  25. package/dist/provider-resolution-C6AQzuFG.js +133 -0
  26. package/dist/{remote-1Jz2oUMK.js → remote-70ZVZZlq.js} +32 -14
  27. package/dist/runtime-type-Deo4qzxN.js +9 -0
  28. package/dist/{session-DD0S1PDC.js → session-e0lyzjJ3.js} +2 -1
  29. package/dist/size-7AkVwGZb.js +118 -0
  30. package/dist/ssh.d.ts +8 -0
  31. package/dist/ssh.js +107 -40
  32. package/dist/task/index.d.ts +19 -17
  33. package/dist/task/index.js +92 -201
  34. package/dist/task/runtime/provider-loader.d.ts +7 -9
  35. package/dist/task/runtime/provider-loader.js +2 -5
  36. package/dist/task/runtime/providers/cloudflare.d.ts +5 -19
  37. package/dist/task/runtime/providers/cloudflare.js +7 -6
  38. package/dist/task/runtime/providers/vercel.d.ts +3 -3
  39. package/dist/task/runtime/providers/vercel.js +35 -4
  40. package/dist/task/runtime/state.d.ts +4 -1
  41. package/dist/task/runtime/state.js +11 -2
  42. package/dist/task/vite.d.ts +143 -17
  43. package/dist/task/vite.js +723 -400
  44. package/dist/{toolchain-BUVXtQ2m.js → toolchain-BIVGMRty.js} +12 -11
  45. package/dist/{trusted-host-DNMJ-Oig.js → trusted-host-kxkpaQcs.js} +21 -179
  46. package/dist/{vercel-Jtxa9TJx.js → vercel-BGGrNpza.js} +107 -34
  47. package/package.json +15 -12
  48. package/dist/cloudflare-DO0h3Ncf.js +0 -281
  49. package/dist/cloudflare-env-BBJaBbuQ.js +0 -39
  50. package/dist/error-diagnostics-BSysPv-D.js +0 -166
  51. package/dist/error-diagnostics-dGQqfgLt.js +0 -99
  52. package/dist/module-types-BfyRBaiP.js +0 -7
  53. package/dist/module-types-Cis4hrF1.d.ts +0 -95
  54. package/dist/runtime-type-DrmrW5m5.js +0 -42
@@ -0,0 +1,16 @@
1
+ //#region ../internal/src/runtime/cloudflare-env-lookup.ts
2
+ /** The key of the AsyncLocalStorage store on `globalThis`. Every bundled copy of this module shares the store. */
3
+ const activeEnvStorageKey = Symbol.for("vitehub.cloudflare.env-storage");
4
+ let activeEnv;
5
+ /** The store of the current `runWithActiveCloudflareEnv()` call, or undefined outside one. */
6
+ function getScopedCloudflareEnv() {
7
+ return globalThis[activeEnvStorageKey]?.getStore();
8
+ }
9
+ function getActiveCloudflareEnv() {
10
+ const scoped = getScopedCloudflareEnv();
11
+ if (scoped) return scoped.env;
12
+ const host = globalThis;
13
+ return Object.hasOwn(host, "__env__") && host.__env__ !== void 0 ? host.__env__ : activeEnv;
14
+ }
15
+ //#endregion
16
+ export { getActiveCloudflareEnv as t };
@@ -0,0 +1,50 @@
1
+ //#region src/internal/cloudflare-failure.ts
2
+ /** Waits before each retry of a Cloudflare Sandbox request or Sandbox Task run. */
3
+ const cloudflareRetryDelays = [
4
+ 1e3,
5
+ 2e3,
6
+ 5e3,
7
+ 1e4,
8
+ 15e3
9
+ ];
10
+ const notStartedMessage = /container is starting|currently provisioning|retry in a moment|not listening in the tcp address|maximum number of running container instances exceeded|there is no container instance that can be provided to this durable object/i;
11
+ const transientMessage = /network connection lost|durable object reset|code was updated|aborterror|aborted/i;
12
+ /** Reads the Durable Object flags and the message from an error and its causes. */
13
+ function readCloudflareFailure(error) {
14
+ const chain = causeChain(error);
15
+ const message = chain.map((value, index) => value instanceof Error ? value.message : index === 0 ? String(value) : "").filter(Boolean).join("\n");
16
+ return {
17
+ coldStart: notStartedMessage.test(message),
18
+ message,
19
+ overloaded: chain.some((value) => errorFlag(value, "overloaded") === true),
20
+ retryable: chain.map((value) => errorFlag(value, "retryable")).find((value) => value !== void 0),
21
+ timedOut: chain.some((value) => errorProperty(value, "code") === "SANDBOX_R0090"),
22
+ transient: transientMessage.test(message)
23
+ };
24
+ }
25
+ /**
26
+ * Decides one retry. `idempotent` is true when a second call after a lost response has no other effect than the first.
27
+ * A request that may have started a command is not idempotent: it retries only on a cold start.
28
+ */
29
+ function canRetryCloudflareRequest(failure, idempotent) {
30
+ if (failure.overloaded) return false;
31
+ if (failure.retryable === false) return false;
32
+ if (failure.coldStart) return true;
33
+ if (!idempotent) return false;
34
+ if (failure.retryable !== void 0) return failure.retryable;
35
+ return failure.transient;
36
+ }
37
+ function causeChain(error) {
38
+ const chain = [];
39
+ for (let value = error; value !== void 0 && value !== null && !chain.includes(value) && chain.length < 4; value = errorProperty(value, "cause")) chain.push(value);
40
+ return chain;
41
+ }
42
+ function errorFlag(error, name) {
43
+ const value = errorProperty(error, name);
44
+ return typeof value === "boolean" ? value : void 0;
45
+ }
46
+ function errorProperty(error, name) {
47
+ return typeof error === "object" && error !== null && name in error ? Reflect.get(error, name) : void 0;
48
+ }
49
+ //#endregion
50
+ export { cloudflareRetryDelays as n, readCloudflareFailure as r, canRetryCloudflareRequest as t };