@vite-hub/sandbox 0.4.1 → 0.5.1

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 (55) hide show
  1. package/dist/{abortable-CR01hzfi.js → abortable-DrHeTo1e.js} +1 -2
  2. package/dist/{cloudflare-Cog_r2Me.js → cloudflare-DrNRQPeh.js} +13 -27
  3. package/dist/{cloudflare-env-lookup-DzI6Xv1Y.js → cloudflare-env-lookup-BNbNil7g.js} +1 -2
  4. package/dist/{cloudflare-failure-CFQhalfh.js → cloudflare-failure-f-3P3ul-.js} +1 -2
  5. package/dist/{container-CqfD8yuE.js → container-DOadzngt.js} +7 -13
  6. package/dist/{crabbox-sbV3Zjuo.js → crabbox-C7KeIKnH.js} +7 -12
  7. package/dist/{error-diagnostics-BJtLRL9w.js → error-diagnostics-CApUyzzu.js} +1 -2
  8. package/dist/{error-diagnostics-BNQwU9yq.js → error-diagnostics-ClSiUwCm.js} +1 -2
  9. package/dist/{file-listing-CHtRrfo1.js → file-listing-BF122soX.js} +3 -4
  10. package/dist/{file-lock-D0-XPogS.js → file-lock-CqA7b491.js} +3 -4
  11. package/dist/{index-DsoQAUb7.d.ts → index-D9DogaoF.d.ts} +0 -15
  12. package/dist/index.d.ts +1 -1
  13. package/dist/index.js +12 -14
  14. package/dist/internal/cloudflare.d.ts +2 -5
  15. package/dist/internal/cloudflare.js +3 -4
  16. package/dist/internal/host-toolchain.d.ts +2 -4
  17. package/dist/internal/host-toolchain.js +4 -5
  18. package/dist/internal/vercel.d.ts +2 -4
  19. package/dist/internal/vercel.js +3 -4
  20. package/dist/{invariant-DolT9EEx.js → invariant-Dj2R1eMr.js} +1 -2
  21. package/dist/{module-types-BoOZiNN4.d.ts → module-types-B3uJG1po.d.ts} +1 -9
  22. package/dist/{module-types-B0LQ5H2S.js → module-types-CWcBHyEs.js} +1 -2
  23. package/dist/{process-sweep-CMaujWE5.js → process-sweep-DVaTb2pO.js} +1 -2
  24. package/dist/{provider-loader-BDgDJ6bX.d.ts → provider-loader-CNKHrWXG.d.ts} +2 -6
  25. package/dist/{provider-resolution-BrQfEQo0.js → provider-resolution-Cl2NKhRP.js} +5 -8
  26. package/dist/{remote-70ZVZZlq.js → remote-DlyX1drC.js} +5 -10
  27. package/dist/{rolldown-runtime-8H4AJuhK.js → rolldown-runtime-BJohB4LM.js} +1 -2
  28. package/dist/{runtime-DHp6ImeP.js → runtime-EtWFVKud.js} +1 -2
  29. package/dist/{runtime-type-Deo4qzxN.js → runtime-type-Dk-rJXlr.js} +1 -2
  30. package/dist/{session-e0lyzjJ3.js → session-DmUiyj4O.js} +5 -8
  31. package/dist/{shell-quote-Q3u3plif.js → shell-quote-MrD49m3N.js} +1 -2
  32. package/dist/ssh.d.ts +1 -3
  33. package/dist/ssh.js +11 -9
  34. package/dist/task/index.d.ts +1 -16
  35. package/dist/task/index.js +23 -44
  36. package/dist/task/runtime/empty-registry.d.ts +0 -2
  37. package/dist/task/runtime/empty-registry.js +1 -2
  38. package/dist/task/runtime/provider-loader.d.ts +1 -1
  39. package/dist/task/runtime/provider-loader.js +2 -3
  40. package/dist/task/runtime/providers/cloudflare.d.ts +3 -4
  41. package/dist/task/runtime/providers/cloudflare.js +3 -4
  42. package/dist/task/runtime/providers/local.d.ts +2 -4
  43. package/dist/task/runtime/providers/local.js +3 -4
  44. package/dist/task/runtime/providers/vercel.d.ts +3 -4
  45. package/dist/task/runtime/providers/vercel.js +9 -16
  46. package/dist/task/runtime/state.d.ts +3 -4
  47. package/dist/task/runtime/state.js +2 -3
  48. package/dist/task/vite.d.ts +24 -23
  49. package/dist/task/vite.js +108 -116
  50. package/dist/{toolchain-BIVGMRty.js → toolchain-DFFxmw3N.js} +6 -13
  51. package/dist/{trusted-host-RanFsFSB.js → trusted-host-CwMs64h1.js} +39 -24
  52. package/dist/{trusted-host-environment-CWKJ7DD_.js → trusted-host-environment-BJE5hGtQ.js} +1 -2
  53. package/dist/{vercel-BGGrNpza.js → vercel-DT74kDyI.js} +33 -29
  54. package/dist/{size-DJNpXeAt.js → vercel-credentials-BGuXoKxG.js} +18 -4
  55. package/package.json +10 -10
package/dist/task/vite.js CHANGED
@@ -1,7 +1,7 @@
1
- import { n as invariantError, t as invariant } from "../invariant-DolT9EEx.js";
2
- import { t as sandboxTaskErrorDiagnostics } from "../error-diagnostics-BNQwU9yq.js";
3
- import { t as getSandboxTaskFeatureDriver } from "../module-types-B0LQ5H2S.js";
4
- import { a as resolveVercelSandboxTaskVcpus, i as resolveCloudflareSandboxTaskInstanceType, n as describeCloudflareInstanceType, r as readSandboxTaskSize, t as assertCloudflareInstanceTypeFits } from "../size-DJNpXeAt.js";
1
+ import { t as sandboxTaskErrorDiagnostics } from "../error-diagnostics-ClSiUwCm.js";
2
+ import { a as resolveCloudflareSandboxTaskInstanceType, i as readSandboxTaskSize, n as assertCloudflareInstanceTypeFits, o as resolveVercelSandboxTaskVcpus, r as describeCloudflareInstanceType, t as vercelCredentialEnv } from "../vercel-credentials-BGuXoKxG.js";
3
+ import { n as invariantError, t as invariant } from "../invariant-Dj2R1eMr.js";
4
+ import { t as getSandboxTaskFeatureDriver } from "../module-types-CWcBHyEs.js";
5
5
  import { builtinModules, createRequire, isBuiltin } from "node:module";
6
6
  import { createHash, randomUUID } from "node:crypto";
7
7
  import { copyFile, glob, lstat, mkdir, mkdtemp, open, readFile, readdir, readlink, realpath, rename, rm, stat, symlink, writeFile } from "node:fs/promises";
@@ -16,7 +16,7 @@ import { findDynamicImports, resolvePathSync } from "mlly";
16
16
  import { resolveModule } from "local-pkg";
17
17
  import { dirname as dirname$2, join as join$2, normalize as normalize$1 } from "node:path/posix";
18
18
  import picomatch from "picomatch";
19
- //#region ../internal/src/build/paths.ts
19
+ // ../internal/src/build/paths.ts
20
20
  function generatedDirSegments(productName) {
21
21
  return [".vitehub", productName];
22
22
  }
@@ -36,16 +36,14 @@ function realpathIfExists(path) {
36
36
  return resolve$1(path);
37
37
  }
38
38
  }
39
- //#endregion
40
- //#region ../internal/src/inspect.ts
39
+ // ../internal/src/inspect.ts
41
40
  function relativeDefinitionFile(projectRoot, file) {
42
41
  return relative$1(projectRoot, file).replaceAll("\\", "/");
43
42
  }
44
43
  const secretKeyPattern = /secret|token|passw(?:or)?d|credential|api[-_\s]?key|private[-_\s]?key|authorization|cookie|signature|dsn|connection[-_\s]?string/i;
45
44
  new RegExp(String.raw`\b([\w-]*authorization[\w-]*["']?\s*[:=]\s*)(?!\[redacted\](?=$|[\s,;}&]))(?:"(?:\\[^\r\n]|[^"\\\r\n])*"|'(?:\\[^\r\n]|[^'\\\r\n])*'|[^\r\n]+?(?=\s*(?:[,;])?\s*(?:${secretKeyPattern.source})[\w-]*\s*[:=]|\s+rejected\b|$))`, "gi");
46
45
  new RegExp(String.raw`\b([\w-]*(?:${secretKeyPattern.source})[\w-]*["']?\s*[:=]\s*)(?!\[redacted\](?=$|[\s,;}&]))(?:"(?:\\[^\r\n]|[^"\\\r\n])*"|'(?:\\[^\r\n]|[^'\\\r\n])*'|[^\s,;&#&]+)`, "gi");
47
- //#endregion
48
- //#region ../internal/src/error-diagnostics.ts
46
+ // ../internal/src/error-diagnostics.ts
49
47
  const dynamicError = { why: ({ message }) => message === void 0 ? "" : String(message) };
50
48
  const internalErrorDiagnostics = /*#__PURE__*/ defineDiagnostics({
51
49
  docsBase: "https://vitehub.dev/docs/development/diagnostics",
@@ -71,7 +69,7 @@ const internalErrorDiagnostics = /*#__PURE__*/ defineDiagnostics({
71
69
  why: ({ message }) => message === void 0 ? "" : String(message)
72
70
  },
73
71
  INTERNAL_R0022: {
74
- fix: "Send input that matches the schema of the operation. `vitehub <namespace> <command> --help` shows the fields.",
72
+ fix: "Send input that matches the schema of the operation. `vitehub <namespace> <command> --help` shows the fields, and the list_operations tool of the ViteHub MCP gives the input schema of each operation.",
75
73
  why: ({ message }) => message === void 0 ? "" : String(message)
76
74
  },
77
75
  INTERNAL_R0024: {
@@ -290,6 +288,10 @@ const internalErrorDiagnostics = /*#__PURE__*/ defineDiagnostics({
290
288
  why: ({ owner }) => `[vitehub] ${owner} extends tuple requires [preset, options] with an options object.`,
291
289
  fix: "Set `extends` to a preset, or to a two-item tuple `[preset, { ...options }]` whose second item is a plain object."
292
290
  },
291
+ INTERNAL_RUNTIME_PACKAGE_VERSION_CONFLICT: {
292
+ why: ({ first, name, second }) => `[vitehub] One server function needs ${name} from two installations: ${first} and ${second}.`,
293
+ fix: "Install one version of the package that the message names, for example with `pnpm dedupe` or an `overrides` entry in `package.json`, then build again."
294
+ },
293
295
  INTERNAL_SECRET_PURPOSE_MISSING: {
294
296
  why: "[vitehub] A derived secret requires a purpose.",
295
297
  fix: "Pass a non-empty purpose to `deriveSecret()`, such as `deriveSecret(\"my-module:session\")`."
@@ -298,6 +300,10 @@ const internalErrorDiagnostics = /*#__PURE__*/ defineDiagnostics({
298
300
  why: ({ minimum }) => `[vitehub] VITEHUB_SECRET must be at least ${minimum} characters. Generate one with \`openssl rand -base64 32\`.`,
299
301
  fix: "Set `VITEHUB_SECRET` to the output of `openssl rand -base64 32`, which has 44 characters."
300
302
  },
303
+ INTERNAL_SITE_TOKEN_TOO_LONG: {
304
+ why: ({ length, maximum }) => `The Site access token is ${length} characters, and an app accepts ${maximum}.`,
305
+ fix: "Open the app with a shorter path, or give the person and the project shorter names, so that the Site access token fits."
306
+ },
301
307
  INTERNAL_SQLITE_ARGUMENT_INVALID: {
302
308
  why: ({ value }) => value === "undefined" ? "undefined cannot be passed as argument to the database" : "Only finite numbers (not Infinity or NaN) can be passed as arguments",
303
309
  fix: "Pass query arguments as finite numbers, strings, booleans, bigints, dates, byte arrays, or null. Replace undefined with null, and check numbers with `Number.isFinite()` before the query."
@@ -312,8 +318,7 @@ const internalErrorDiagnostics = /*#__PURE__*/ defineDiagnostics({
312
318
  }
313
319
  }
314
320
  });
315
- //#endregion
316
- //#region ../internal/src/object.ts
321
+ // ../internal/src/object.ts
317
322
  /** A non-null object that is not an array. Functions do not pass. */
318
323
  function isRecord(value) {
319
324
  return typeof value === "object" && value !== null && !Array.isArray(value);
@@ -324,8 +329,7 @@ function isPlainRecord(value) {
324
329
  if (prototype === null) return true;
325
330
  return Object.getPrototypeOf(prototype) === null && Object.hasOwn(prototype, "constructor") && prototype.constructor?.name === "Object";
326
331
  }
327
- //#endregion
328
- //#region ../internal/src/build/vite.ts
332
+ // ../internal/src/build/vite.ts
329
333
  const projectRootDirectoryMarkers = [
330
334
  ["server", "agents"],
331
335
  ["server", "channels"],
@@ -365,6 +369,11 @@ function getResolvedFeatureOptions(config, feature) {
365
369
  if (!features || typeof features !== "object") return void 0;
366
370
  return Reflect.get(features, feature);
367
371
  }
372
+ /**
373
+ * Set by `vite-hub/nuxt` when it replays Vite config hooks for `nuxt prepare`. Prepare uses `command: "build"` to write
374
+ * the same types as the build, but it builds nothing.
375
+ */
376
+ const VITEHUB_PREPARE = "__vitehubPrepare";
368
377
  function includesNitroVitePlugin(value) {
369
378
  if (Array.isArray(value)) return value.some(includesNitroVitePlugin);
370
379
  if (!value || typeof value !== "object") return false;
@@ -400,7 +409,7 @@ function hasProjectRootDirectoryMarker(root) {
400
409
  for (const marker of projectRootDirectoryMarkers) try {
401
410
  if (statSync(resolve(root, ...marker)).isDirectory()) return true;
402
411
  } catch (error) {
403
- if (error.code !== "ENOENT") throw error;
412
+ if (!isMissingProjectMarker(error)) throw error;
404
413
  }
405
414
  return false;
406
415
  }
@@ -414,11 +423,15 @@ function hasProjectRootFileMarker(root, markers) {
414
423
  try {
415
424
  if (statSync(resolve(root, ...path)).isFile()) return true;
416
425
  } catch (error) {
417
- if (error.code !== "ENOENT") throw error;
426
+ if (!isMissingProjectMarker(error)) throw error;
418
427
  }
419
428
  }
420
429
  return false;
421
430
  }
431
+ function isMissingProjectMarker(error) {
432
+ const code = error.code;
433
+ return code === "ENOENT" || code === "ENOTDIR";
434
+ }
422
435
  /** Maps a host name or a Nitro preset name, such as `cloudflare-module` or `node-server`, to its ViteHub host. */
423
436
  function hostFromNitroPreset(value) {
424
437
  const normalized = value?.trim().toLowerCase().replaceAll("_", "-");
@@ -429,8 +442,7 @@ function hostFromNitroPreset(value) {
429
442
  if (normalized === "node" || normalized.startsWith("node-")) return "node";
430
443
  if (normalized.startsWith("vercel")) return "vercel";
431
444
  }
432
- //#endregion
433
- //#region ../internal/src/hosting.ts
445
+ // ../internal/src/hosting.ts
434
446
  /**
435
447
  * Returns the Nitro preset name that this build targets, as the developer wrote it.
436
448
  * The order is `nitro.preset`, `hosting`, `NITRO_PRESET`, `SERVER_PRESET`, then `VITEHUB_HOST`.
@@ -462,8 +474,7 @@ function getSupportedHostingProvider(hosting, supportedProviders) {
462
474
  if (!provider || !supportedProviders.includes(provider)) return void 0;
463
475
  return provider;
464
476
  }
465
- //#endregion
466
- //#region ../internal/src/definition-catalog.ts
477
+ // ../internal/src/definition-catalog.ts
467
478
  const sourceFilePattern = /\.(?:c|m)?[jt]sx?$/i;
468
479
  const declarationFilePattern = /\.d\.(?:c|m)?[jt]sx?$/i;
469
480
  const testFilePattern = /\.(?:test|spec)\.(?:c|m)?[jt]sx?$/i;
@@ -595,8 +606,8 @@ async function writeFileIfChanged(file, contents) {
595
606
  await mkdir(resolve$1(file, ".."), { recursive: true });
596
607
  await writeFile(file, contents, "utf8");
597
608
  }
598
- //#endregion
599
- //#region ../internal/src/nitro-kit.ts
609
+ Object.freeze({ vitehubAuthAccess: "handler" });
610
+ Object.freeze({ vitehubOwnAccess: true });
600
611
  /** Add one module id to a Nitro or Rollup `external` option, in each form that option takes. */
601
612
  function mergeNitroExternal(value, addition) {
602
613
  if (typeof value === "undefined") return [addition];
@@ -605,8 +616,7 @@ function mergeNitroExternal(value, addition) {
605
616
  if (typeof value === "function") return (source, importer, isResolved) => source === addition || Boolean(value(source, importer, isResolved));
606
617
  return value;
607
618
  }
608
- //#endregion
609
- //#region src/task/internal/shared/cloudflare-wrangler.ts
619
+ // src/task/internal/shared/cloudflare-wrangler.ts
610
620
  function compareNumericStrings(left, right) {
611
621
  return left.localeCompare(right, void 0, { numeric: true });
612
622
  }
@@ -705,13 +715,12 @@ function finalizeCloudflareWranglerConfig(target) {
705
715
  wrangler.migrations = mergeMigrations(wrangler.migrations);
706
716
  validateDurableObjectMigrations(wrangler);
707
717
  }
708
- //#endregion
709
- //#region src/task/cloudflare.ts
718
+ // src/task/cloudflare.ts
710
719
  const defaultCloudflareSandboxBinding = "SANDBOX";
711
720
  const defaultCloudflareSandboxClassName = "Sandbox";
712
721
  const defaultCloudflareSandboxMaxInstances = 12;
713
722
  const cloudflareSandboxNodeImage = "24-bookworm-slim";
714
- const cloudflareSandboxPackages = "ca-certificates curl file git jq procps tini unzip wget zip";
723
+ const cloudflareSandboxPackages = "ca-certificates git procps tini";
715
724
  const durableObjectModule = "@vite-hub/sandbox/internal/cloudflare";
716
725
  function resolveModule$1(id) {
717
726
  return resolvePathSync(id, {
@@ -727,8 +736,11 @@ function resolveModule$1(id) {
727
736
  function resolveCloudflareSandboxEntrypoint() {
728
737
  try {
729
738
  return resolveModule$1("@cloudflare/sandbox");
730
- } catch {
731
- throw sandboxTaskErrorDiagnostics.SANDBOX_TASK_R0003({ message: "[vitehub] The Cloudflare Sandbox provider requires @cloudflare/sandbox. Install a supported version before building." });
739
+ } catch (cause) {
740
+ throw sandboxTaskErrorDiagnostics.SANDBOX_TASK_R0003({
741
+ cause,
742
+ message: "[vitehub] The Cloudflare Sandbox provider requires @cloudflare/sandbox. Install a supported version before building."
743
+ });
732
744
  }
733
745
  }
734
746
  function resolveCloudflareSandboxVersion() {
@@ -901,8 +913,7 @@ async function configureCloudflareSandboxNitro(targetValue, rootDir, options = {
901
913
  if (finalizeWrangler) finalizeCloudflareWranglerConfig(target);
902
914
  return target;
903
915
  }
904
- //#endregion
905
- //#region src/task/internal/typescript.ts
916
+ // src/task/internal/typescript.ts
906
917
  const require = createRequire(import.meta.url);
907
918
  function loadTypeScript() {
908
919
  try {
@@ -912,8 +923,7 @@ function loadTypeScript() {
912
923
  throw sandboxTaskErrorDiagnostics.SANDBOX_TASK_C0013({ message: "[vitehub] Sandbox Tasks read their definitions with TypeScript. Install `typescript` in the app." });
913
924
  }
914
925
  }
915
- //#endregion
916
- //#region src/task/internal/shared/discovered-definition/ast.ts
926
+ // src/task/internal/shared/discovered-definition/ast.ts
917
927
  const filesystemModuleSpecifiers = /* @__PURE__ */ new Set([
918
928
  "child_process",
919
929
  "fs",
@@ -1417,23 +1427,17 @@ async function injectTypeImportsFromUnimport(source, id, imports) {
1417
1427
  }
1418
1428
  return injectTypeImports(source, pendingImports, id);
1419
1429
  }
1420
- //#endregion
1421
- //#region src/task/internal/shared/server-imports.ts
1430
+ // src/task/internal/shared/server-imports.ts
1422
1431
  function isServerAutoImportEnabled(imports) {
1423
1432
  return imports !== false && imports?.autoImport !== false;
1424
1433
  }
1425
- //#endregion
1426
- //#region src/task/internal/shared/discovered-definition/bundler.ts
1434
+ // src/task/internal/shared/discovered-definition/bundler.ts
1427
1435
  function isJsxDefinition(filename) {
1428
1436
  return filename.endsWith(".tsx") || filename.endsWith(".jsx");
1429
1437
  }
1430
1438
  function isBareSpecifier(id) {
1431
1439
  return !/^(?:\.{1,2}(?:\/|$)|\/|[A-Za-z]:[\\/]|\0)/.test(id);
1432
1440
  }
1433
- /**
1434
- * Vite 8 bundles with Rolldown, so the app already has it. Load the copy next to `vite`, or `vite/rolldown` with
1435
- * Vite+, instead of installing a second bundler.
1436
- */
1437
1441
  async function importRolldown() {
1438
1442
  let entry;
1439
1443
  try {
@@ -1496,8 +1500,7 @@ async function bundleDiscoveredDefinitionModuleGraph(options) {
1496
1500
  modules
1497
1501
  };
1498
1502
  }
1499
- //#endregion
1500
- //#region src/task/internal/shared/discovered-definition.ts
1503
+ // src/task/internal/shared/discovered-definition.ts
1501
1504
  function normalizeDir(rootDir, dir) {
1502
1505
  if (typeof dir === "string") return isAbsolute$1(dir) ? dir : resolve$1(rootDir, dir);
1503
1506
  return {
@@ -1583,18 +1586,15 @@ async function createDiscoveredDefinitionCompiler(options = {}) {
1583
1586
  return await injectSource(await readFile(id, "utf8"), id);
1584
1587
  } };
1585
1588
  }
1586
- //#endregion
1587
- //#region src/task/internal/shared/feature-definitions.ts
1589
+ // src/task/internal/shared/feature-definitions.ts
1588
1590
  function toTemplateSafeName(name) {
1589
1591
  return name.replace(/[^a-z0-9/_:-]/gi, "_").replace(/\//g, "__").replace(/:/g, "__");
1590
1592
  }
1591
- //#endregion
1592
- //#region src/task/internal/shared/file-import-specifier.ts
1593
+ // src/task/internal/shared/file-import-specifier.ts
1593
1594
  function createFileImportSpecifier(file, platform = process.platform) {
1594
1595
  return pathToFileURL(file, { windows: platform === "win32" }).href;
1595
1596
  }
1596
- //#endregion
1597
- //#region src/task/internal/shared/module-resolve.ts
1597
+ // src/task/internal/shared/module-resolve.ts
1598
1598
  function normalizePaths(paths) {
1599
1599
  if (paths?.length) return paths;
1600
1600
  if (typeof process !== "undefined") return [process.cwd()];
@@ -1623,8 +1623,7 @@ function tryResolveModule(id, options = {}) {
1623
1623
  continue;
1624
1624
  }
1625
1625
  }
1626
- //#endregion
1627
- //#region src/task/internal/shared/feature-runtime-path.ts
1626
+ // src/task/internal/shared/feature-runtime-path.ts
1628
1627
  function resolveExistingModulePath(path) {
1629
1628
  if (existsSync(path)) return path;
1630
1629
  for (const extension of [
@@ -1656,8 +1655,7 @@ function resolveFeatureRuntimePath(importMetaUrl, packageId, sourceRelativePath,
1656
1655
  if (packagePath) return join$1(dirname$1(packagePath), distRelativePath);
1657
1656
  return sourcePath;
1658
1657
  }
1659
- //#endregion
1660
- //#region src/task/project.ts
1658
+ // src/task/project.ts
1661
1659
  const sandboxTaskProjectSourceFiles = /* @__PURE__ */ new WeakMap();
1662
1660
  function getSandboxTaskProjectSourceFiles(project) {
1663
1661
  return sandboxTaskProjectSourceFiles.get(project) || [];
@@ -1919,8 +1917,7 @@ async function findLockfile(directories, root, manager) {
1919
1917
  };
1920
1918
  }
1921
1919
  }
1922
- //#endregion
1923
- //#region src/task/internal/package-entry.ts
1920
+ // src/task/internal/package-entry.ts
1924
1921
  const runtimeExportConditions = /* @__PURE__ */ new Set([
1925
1922
  "default",
1926
1923
  "import",
@@ -2257,8 +2254,7 @@ function prepareExecutablePackageProject(project, entry) {
2257
2254
  }
2258
2255
  };
2259
2256
  }
2260
- //#endregion
2261
- //#region src/task/bundle.ts
2257
+ // src/task/bundle.ts
2262
2258
  const SHIM_NAMESPACE = "vitehub-sandbox-task-runtime-shim";
2263
2259
  const SHIM_ID = `\0${SHIM_NAMESPACE}`;
2264
2260
  const builtinModuleSet$1 = /* @__PURE__ */ new Set([...builtinModules, ...builtinModules.map((name) => `node:${name}`)]);
@@ -2408,8 +2404,7 @@ async function bundleSandboxTaskDefinition(source, file, options = {}) {
2408
2404
  }
2409
2405
  };
2410
2406
  }
2411
- //#endregion
2412
- //#region src/task/definition-options.ts
2407
+ // src/task/definition-options.ts
2413
2408
  const sandboxTaskDefinitionSyntax = "`defineSandboxTask({ handler, ...options })`";
2414
2409
  function readStaticValue(node) {
2415
2410
  const ts = loadTypeScript();
@@ -2545,8 +2540,8 @@ async function extractSandboxTaskDefinitionMetadata(file) {
2545
2540
  ...project !== void 0 ? { project } : {}
2546
2541
  } : void 0;
2547
2542
  }
2548
- //#endregion
2549
- //#region src/task/type-template.ts
2543
+ // src/task/type-template.ts
2544
+ const sandboxTaskTypeTemplateFilename = "runtime/sandbox-task.d.ts";
2550
2545
  function createDefinitionContract(definition) {
2551
2546
  const module = `typeof import(${JSON.stringify(definition.handler)})`;
2552
2547
  if (definition.kind === "definition") return `{ payload: Parameters<${module}['default']['handler']>[0], result: Awaited<ReturnType<${module}['default']['handler']>> }`;
@@ -2569,8 +2564,7 @@ function createSandboxTaskTypeTemplateContents(definitions) {
2569
2564
  ``
2570
2565
  ].join("\n");
2571
2566
  }
2572
- //#endregion
2573
- //#region src/task/feature.ts
2567
+ // src/task/feature.ts
2574
2568
  const sandboxTaskRuntimeStateSpecifier = "@vite-hub/sandbox/task/runtime/state";
2575
2569
  const sandboxTaskRuntimeSpecifier = "@vite-hub/sandbox/internal/task/runtime";
2576
2570
  const sandboxTaskRuntimeProviderSpecifiers = {
@@ -2642,7 +2636,7 @@ function createSandboxTaskManifest(aliasPath, typeTemplate) {
2642
2636
  }
2643
2637
  ],
2644
2638
  typeTemplate: {
2645
- filename: "runtime/sandbox-task.d.ts",
2639
+ filename: sandboxTaskTypeTemplateFilename,
2646
2640
  contents: typeTemplate
2647
2641
  }
2648
2642
  };
@@ -2735,13 +2729,7 @@ async function createSandboxTaskFeaturePlan(sandboxTaskConfig, definitions, path
2735
2729
  }
2736
2730
  const definitionMetadata = await loadSandboxTaskDefinitionMetadata(definitions, discoveredDefinitionOptions.rootDir || process.cwd());
2737
2731
  const metadataByName = new Map(definitionMetadata.map((definition) => [definition.name, definition]));
2738
- const manifest = createSandboxTaskManifest(paths.aliasPath, createSandboxTaskTypeTemplateContents(definitions.map((definition) => {
2739
- return {
2740
- handler: definition.handler,
2741
- kind: definition.kind,
2742
- name: definition.name
2743
- };
2744
- })));
2732
+ const manifest = createSandboxTaskManifest(paths.aliasPath, createSandboxTaskTypeTemplateContents(definitions));
2745
2733
  const { bundleAlias, featureImports = manifest.imports, ...definitionCompilerOptions } = discoveredDefinitionOptions;
2746
2734
  const definitionCompiler = await createDiscoveredDefinitionCompiler({
2747
2735
  ...definitionCompilerOptions,
@@ -2812,8 +2800,7 @@ async function createSandboxTaskFeaturePlan(sandboxTaskConfig, definitions, path
2812
2800
  cloudflare: cloudflareOptions
2813
2801
  };
2814
2802
  }
2815
- //#endregion
2816
- //#region src/task/discovery.ts
2803
+ // src/task/discovery.ts
2817
2804
  const sandboxTaskSuffixPattern = /\.sandbox-task\.(?:c|m)?[jt]s$/i;
2818
2805
  const sandboxTaskEntrypointFilenames = [
2819
2806
  "index.ts",
@@ -2884,8 +2871,7 @@ function discoverSandboxTaskDefinitions(options) {
2884
2871
  const serverScanDirs = roots.map((root) => resolve$1(root, "server"));
2885
2872
  return mergeDefinitions("Sandbox Task", discoverDefinitions("Sandbox Task", [createSuffixDefinitionSource("vite-suffix", roots, sandboxTaskSuffixPattern, normalizeSuffixSandboxTaskName, { createDefinition: createDiscoveredSandboxTaskDefinition("vite-suffix", "definition") })]), discoverServerSandboxTaskDefinitions(serverScanDirs));
2886
2873
  }
2887
- //#endregion
2888
- //#region src/task/internal/runtime-generation.ts
2874
+ // src/task/internal/runtime-generation.ts
2889
2875
  const generationMarker = "// vitehub-sandbox-task-generation: ";
2890
2876
  const generationLockClaimStaleMs = 3e4;
2891
2877
  const generationLockInitializationStaleMs = 5e3;
@@ -3241,8 +3227,7 @@ async function pruneSandboxTaskRuntimeGeneration(path, remove = rm) {
3241
3227
  force: true
3242
3228
  }).catch(() => {});
3243
3229
  }
3244
- //#endregion
3245
- //#region src/task/internal/runtime-preparation.ts
3230
+ // src/task/internal/runtime-preparation.ts
3246
3231
  const SANDBOX_PACKAGE_ID$1 = "@vite-hub/sandbox/task";
3247
3232
  const SANDBOX_REGISTRY_ID = "#vitehub-sandbox-task-registry";
3248
3233
  const builtinModuleSet = /* @__PURE__ */ new Set([...builtinModules, ...builtinModules.map((name) => `node:${name}`)]);
@@ -3522,17 +3507,32 @@ async function prepareSandboxTaskRuntime(options) {
3522
3507
  root: rootDir
3523
3508
  }, options.env, definitions.length > 0);
3524
3509
  const stateModule = createSandboxTaskStateModuleContents(context);
3525
- if (!context.config) return {
3526
- aliases: {},
3527
- definitions: [],
3528
- files: [],
3529
- hosting: context.hosting,
3530
- localDev: false,
3531
- provider: void 0,
3532
- rootDir,
3533
- stateModule,
3534
- watchFiles: []
3535
- };
3510
+ const prepareOnly = options.userConfig[VITEHUB_PREPARE] === true;
3511
+ if (!context.config || prepareOnly) {
3512
+ const files = [];
3513
+ if (context.config && options.writeArtifacts !== false) {
3514
+ const generatedDir = ensureGeneratedDir(rootDir, "sandbox-task");
3515
+ const file = resolve$1(generatedDir, sandboxTaskTypeTemplateFilename);
3516
+ const contents = createSandboxTaskTypeTemplateContents(definitions);
3517
+ await mkdir(generatedDir, { recursive: true });
3518
+ await withSandboxTaskRuntimeGenerationLock(generatedDir, (lease) => lease.publish(async () => {
3519
+ await mkdir(dirname$1(file), { recursive: true });
3520
+ await writeStableSandboxTaskRuntimeFile(file, contents, lease);
3521
+ }));
3522
+ files.push(file);
3523
+ }
3524
+ return {
3525
+ aliases: {},
3526
+ definitions,
3527
+ files,
3528
+ hosting: context.hosting,
3529
+ localDev: false,
3530
+ provider: void 0,
3531
+ rootDir,
3532
+ stateModule,
3533
+ watchFiles: []
3534
+ };
3535
+ }
3536
3536
  const localDev = context.command === "serve" && !context.config.remote;
3537
3537
  if (localDev && process.platform === "win32") throw sandboxTaskErrorDiagnostics.SANDBOX_TASK_LOCAL_WINDOWS();
3538
3538
  const facadeFile = resolve$1(ensureGeneratedDir(rootDir, "sandbox-task"), "runtime/sandbox-task.mjs");
@@ -3573,8 +3573,7 @@ async function prepareSandboxTaskRuntime(options) {
3573
3573
  watchFiles: plan.watchFiles || []
3574
3574
  };
3575
3575
  }
3576
- //#endregion
3577
- //#region src/task/inspect.ts
3576
+ // src/task/inspect.ts
3578
3577
  /** Lists Sandbox Task Definitions and package entries as serializable inspection summaries. */
3579
3578
  function inspectSandboxTaskDefinitions(options) {
3580
3579
  return discoverSandboxTaskDefinitions({ rootDir: options.rootDir }).map((definition) => ({
@@ -3587,7 +3586,6 @@ function inspectSandboxTaskDefinitions(options) {
3587
3586
  source: definition.source
3588
3587
  }));
3589
3588
  }
3590
- /** The Cloudflare instance type and instance limit, as the Container resource reports them. */
3591
3589
  function describeCloudflareSandboxTaskSize(options) {
3592
3590
  const instanceType = options.instanceType === void 0 ? void 0 : describeCloudflareInstanceType(options.instanceType)?.label ?? JSON.stringify(options.instanceType);
3593
3591
  return [instanceType ? `Instance type ${instanceType}` : "", options.maxInstances ? `at most ${options.maxInstances} instances` : ""].filter(Boolean).join(", ");
@@ -3628,23 +3626,8 @@ const sandboxTaskConsoleSection = {
3628
3626
  notice: "Running Sandbox Tasks, files, processes, logs, ports, and lifecycle state are not included in this build-time catalog."
3629
3627
  }
3630
3628
  };
3631
- //#endregion
3632
- //#region src/task/deployment-env.ts
3629
+ // src/task/deployment-env.ts
3633
3630
  const owners = ["sandbox"];
3634
- const vercelCredentialNames = {
3635
- token: {
3636
- names: ["VITE_SANDBOX_TOKEN", "VERCEL_TOKEN"],
3637
- secret: true
3638
- },
3639
- teamId: {
3640
- names: ["VITE_SANDBOX_TEAM_ID", "VERCEL_TEAM_ID"],
3641
- secret: false
3642
- },
3643
- projectId: {
3644
- names: ["VITE_SANDBOX_PROJECT_ID", "VERCEL_PROJECT_ID"],
3645
- secret: false
3646
- }
3647
- };
3648
3631
  /**
3649
3632
  * The variables that Sandbox Tasks read on the deployed host. A Vercel Sandbox reads its token, team, and project from
3650
3633
  * env when the config leaves them out. On Vercel they are optional, since the Sandbox SDK then uses the OIDC token of
@@ -3659,26 +3642,27 @@ function sandboxDeploymentEnv(config, driver, context) {
3659
3642
  "teamId",
3660
3643
  "projectId"
3661
3644
  ].flatMap((option) => configured?.[option]?.trim() ? [] : [{
3662
- names: vercelCredentialNames[option].names,
3645
+ names: vercelCredentialEnv[option].names,
3663
3646
  required,
3664
- secret: vercelCredentialNames[option].secret,
3647
+ secret: vercelCredentialEnv[option].secret,
3665
3648
  hasDefault: false,
3666
3649
  owners
3667
3650
  }]);
3668
3651
  }
3669
- //#endregion
3670
- //#region src/task/vite.ts
3652
+ // src/task/vite.ts
3671
3653
  const SANDBOX_PACKAGE_ID = "@vite-hub/sandbox/task";
3672
3654
  const SANDBOX_PACKAGE_NAME = "@vite-hub/sandbox";
3673
3655
  const SANDBOX_PROVIDER_LOADER_ID = "vitehub-sandbox-task-provider-loader";
3674
3656
  const SANDBOX_STATE_ID = "#vitehub/sandbox-task";
3675
3657
  const RESOLVED_SANDBOX_STATE_ID = "\0vitehub:sandbox-task:state";
3676
3658
  const SANDBOX_STATE_ID_PATTERN = /^(?:#vitehub\/sandbox-task|\0vitehub:sandbox-task:state)$/;
3677
- function mergeSandboxTaskNitroProviderAliases(nitro, aliases) {
3659
+ function mergeSandboxTaskNitroProviderAliases(nitro, aliases, frameworkSpecifier) {
3678
3660
  const providerAliases = Object.fromEntries(sandboxTaskProviderLoaderSpecifiers.flatMap((specifier) => {
3679
3661
  const replacement = aliases[specifier];
3680
3662
  return replacement ? [[specifier, replacement]] : [];
3681
3663
  }));
3664
+ const facade = aliases[SANDBOX_PACKAGE_ID];
3665
+ if (frameworkSpecifier && facade) providerAliases[frameworkSpecifier] = facade;
3682
3666
  if (!Object.keys(providerAliases).length) return;
3683
3667
  nitro.alias = {
3684
3668
  ...isRecord(nitro.alias) ? nitro.alias : {},
@@ -3808,14 +3792,23 @@ function hubSandboxTask(options) {
3808
3792
  if (localDev && nitroOptions?.dev && runner === "miniflare") throw sandboxTaskErrorDiagnostics.SANDBOX_TASK_LOCAL_NITRO_RUNNER();
3809
3793
  }
3810
3794
  const sandboxTaskNitroModule = (nitro) => {
3811
- const options = nitro.options;
3795
+ const { options } = nitro;
3812
3796
  nitroOptions = options;
3813
3797
  assertLocalDevRunner();
3814
3798
  mergeSandboxTaskNitroNoExternals(options, selectedProvider);
3815
- if (selectedProvider) mergeSandboxTaskNitroProviderAliases(options, generatedAliases);
3799
+ if (selectedProvider) mergeSandboxTaskNitroProviderAliases(options, generatedAliases, internalOptions?.providerImportSpecifier);
3816
3800
  nitro.hooks.hook("build:before", () => {
3817
3801
  mergeSandboxTaskNitroNoExternals(options, selectedProvider);
3818
- if (selectedProvider) mergeSandboxTaskNitroProviderAliases(options, generatedAliases);
3802
+ if (selectedProvider) mergeSandboxTaskNitroProviderAliases(options, generatedAliases, internalOptions?.providerImportSpecifier);
3803
+ });
3804
+ if (options.dev) nitro.hooks.hook("build:config", (_nitro, config) => {
3805
+ const resolver = config.builder === "rolldown" ? config.rolldown?.resolve : void 0;
3806
+ const specifier = internalOptions?.providerImportSpecifier;
3807
+ const facade = generatedAliases[SANDBOX_PACKAGE_ID];
3808
+ if (resolver && selectedProvider && specifier && facade) resolver.alias = {
3809
+ ...resolver.alias,
3810
+ [specifier]: facade
3811
+ };
3819
3812
  });
3820
3813
  };
3821
3814
  function cloneConfigValue(value) {
@@ -3985,5 +3978,4 @@ function hubSandboxTask(options) {
3985
3978
  }
3986
3979
  };
3987
3980
  }
3988
- //#endregion
3989
3981
  export { discoverSandboxTaskDefinitions, hubSandboxTask, inspectSandboxTaskDefinitions, sandboxTaskConsoleSection, sandboxTaskRuntimeStateModule };
@@ -1,11 +1,11 @@
1
- import { t as __exportAll } from "./rolldown-runtime-8H4AJuhK.js";
2
- import { t as sandboxErrorDiagnostics } from "./error-diagnostics-BJtLRL9w.js";
3
- import { t as shellQuote } from "./shell-quote-Q3u3plif.js";
4
- import { t as abortable } from "./abortable-CR01hzfi.js";
5
- import { t as runtimeRecord } from "./runtime-type-Deo4qzxN.js";
1
+ import { t as __exportAll } from "./rolldown-runtime-BJohB4LM.js";
2
+ import { t as sandboxErrorDiagnostics } from "./error-diagnostics-CApUyzzu.js";
3
+ import { t as abortable } from "./abortable-DrHeTo1e.js";
4
+ import { t as runtimeRecord } from "./runtime-type-Dk-rJXlr.js";
5
+ import { t as shellQuote } from "./shell-quote-MrD49m3N.js";
6
6
  import { createHash, randomUUID } from "node:crypto";
7
7
  import { maxSatisfying, minVersion, rcompare, valid, validRange } from "semver";
8
- //#region src/internal/toolchain.ts
8
+ // src/internal/toolchain.ts
9
9
  var toolchain_exports = /* @__PURE__ */ __exportAll({
10
10
  nodeDistribution: () => nodeDistribution,
11
11
  normalizeToolchain: () => normalizeToolchain,
@@ -153,7 +153,6 @@ function parsePackageManager(value, source) {
153
153
  version
154
154
  };
155
155
  }
156
- /** Detect the target OS, architecture, and C library with POSIX tools. */
157
156
  async function detectToolchainPlatform(target) {
158
157
  const result = await target.run([
159
158
  "uname -s",
@@ -385,10 +384,6 @@ async function installEntry(target, key, prepare) {
385
384
  await release?.();
386
385
  }
387
386
  }
388
- /**
389
- * Extract into a private staging directory, then publish with an atomic
390
- * symbolic link. A concurrent installer that loses the race keeps the winner.
391
- */
392
387
  function installScript(options) {
393
388
  const final = joinPath(options.cacheRoot, options.key);
394
389
  const lines = [
@@ -419,7 +414,6 @@ async function verifyPackageManagerHash(pin, name, tarball) {
419
414
  const actual = contents ? createHash(algorithm).update(contents).digest("hex") : void 0;
420
415
  if (actual !== expected) throw sandboxErrorDiagnostics.SANDBOX_R0153({ message: `[vitehub] ${pin.name}@${pin.version} does not match the ${algorithm} hash from ${pin.source}: expected ${expected}, received ${actual ?? "<missing>"}.` });
421
416
  }
422
- /** Read one regular file from a gzipped npm package tarball. */
423
417
  async function tarEntry(gzipped, path) {
424
418
  const stream = new Blob([Uint8Array.from(gzipped)]).stream().pipeThrough(new DecompressionStream("gzip"));
425
419
  const bytes = new Uint8Array(await new Response(stream).arrayBuffer());
@@ -524,5 +518,4 @@ function trimSlash(value) {
524
518
  function processEnvironment() {
525
519
  return globalThis.process?.env ?? {};
526
520
  }
527
- //#endregion
528
521
  export { verifyToolchain as a, toolchain_exports as i, provisionToolchain as n, toolchainProjectFiles as r, normalizeToolchain as t };