Repository navigation
feat!: remove Next/Nuxt nested bag API and expose/shared aliases - #1929
Conversation
Drop the deprecated nested arkenv({ server, client, shared, runtimeEnv })
overload and expose/shared option aliases from @arkenv/nextjs and
@arkenv/nuxt. Flat arkenv(schema, { exposeToClient }) is the only path;
legacy callers get a migration-oriented error. @arkenv/build extractKeys
rejects nested schema source the same way.
Fixes #1910
Co-authored-by: Yam Borodetsky <[email protected]>
🦋 Changeset detectedLatest commit: 672db1b The changes in this PR will be included in the next version bump. This PR includes changesets to release 6 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
@arkenv/agent-plugin
arkenv
@arkenv/build
@arkenv/bun-plugin
@arkenv/core
@arkenv/fumadocs-ui
@arkenv/nextjs
@arkenv/nuxt
@arkenv/rsbuild-plugin
@arkenv/standard
@arkenv/tanstack-addon
@arkenv/vite-plugin
commit: |
Deduplicate the Next/Nuxt/build helpers into @repo/utils/nested-bag-migration-error (from PR #1928), keeping value-aware detection so flat keys named server are not misclassified. Co-authored-by: Yam Borodetsky <[email protected]>
There was a problem hiding this comment.
ℹ️ No critical issues — two rough edges worth a look.
Reviewed changes
@arkenv/nextjsflat-only — nested overloads and theexpose/sharedalias fields are gone;index.ts,react-server.ts, andstandard/index.tsnow call a value-awareassertNotRemovedNestedBag(schema)beforearkenvInternal, and codegen always usesgenerateFlatFactoryCode.@arkenv/nuxtflat-only — the same cut across the ArkType/Standard entries,parseSchemaShape,capture, andthin-accessor;ParsedSchemaShape.isLegacyis dropped.@arkenv/buildrejects nested source —extractKeysis flat-only, throwsREMOVED_NESTED_BAG_MESSAGEon nested bag source, drops theisLegacyfield, and stops matching theexpose/sharedoption aliases; the new detection helpers are exported.- Docs, changeset, tests — the migration guide gains a "Removed in v1" section, the Next/Nuxt references note the flat-only shape, and nested/alias tests are replaced with flat plus rejection cases; major changesets for the three packages.
ℹ️ Nested buckets that are a single validator slip past the detector
isRemovedNestedBag treats a server / client / shared value as a bag only when it is a plain object without ~standard, so a nested call whose bucket is a single validator is not rejected: ArkType type({...}) returns a function (fails isPlainObject), and Zod z.object({...}) / Valibot v.object({...}) are plain objects that carry ~standard. The removed config.test.ts case "should extract keys when using ArkType type({...}) wrapper" shows this source form existed, so arkenv({ server: type({...}), client: type({...}) }) now falls through to the flat path and produces a downstream validation error instead of the migration message. This is a deliberate trade-off — flat env keys literally named server must keep working — so it is a judgment call whether to tighten detection or document the boundary.
Technical details
# Nested single-validator buckets bypass the migration detector
## Affected sites
- `packages/nextjs/src/removed-nested.ts:40` (`isSchemaBag`) and `:58` (bucket loop)
- `packages/nuxt/src/removed-nested.ts` — byte-identical copy, same lines
- Call sites: `packages/nextjs/src/index.ts:61`, `packages/nextjs/src/react-server.ts:33`, `packages/nextjs/src/standard/index.ts:47`, `packages/nuxt/src/thin-accessor.ts:23`, `packages/nuxt/src/schema-shape.ts:55`
## Required outcome
- Decide whether the migration guard should also catch nested buckets whose value is a single Standard Schema validator or an ArkType `type(...)` instance, or explicitly document that only record-shaped buckets are detected.
## Open questions for the human
- Was `server: type({...})` / `server: z.object({...})` ever a runtime-supported nested shape, or only ever handled by the static extractor?ℹ️ Nitpicks
packages/nextjs/src/removed-nested.tsandpackages/nuxt/src/removed-nested.tsare byte-identical 85-line copies, andREMOVED_NESTED_BAG_MESSAGEis a third copy in@arkenv/build/src/removed-nested.ts; hoisting the value-aware detector and message into a shared internal module would remove the drift risk.hasRemovedNestedBagSource(packages/build/src/removed-nested.ts:21) is a raw-text regex with no comment or string awareness, so a schema file containingserver: {inside a comment or string default would throw a spurious migration error during codegen/build. Latent only — no in-repo fixture triggers it.
DeepSeek Flash (free via Pullfrog for OSS) | 𝕏
There was a problem hiding this comment.
ℹ️ Incremental review — the
@repo/utilsrefactor is clean; no new issues.
Reviewed changes
- Shared migration helper moved to
@repo/utils— the value-aware detector, source regex, and message now live inpackages/internal/utils/src/utils/nested-bag-migration-error.tsbehind a new./nested-bag-migration-errorsubpath export, with its own unit tests; the three per-packagesrc/removed-nested.tscopies are deleted. @arkenv/buildconsumes the shared helper —core.tsimportshasNestedBagSource/assertNotNestedBagSource/nestedBagMigrationErrorMessagefrom@repo/utils, and the build index no longer re-exports them.- Call sites pass the second argument —
assertNotNestedBag(schema, options)in the Next.js and Nuxt entries;isNestedBagCalladditionally rejects a boolean second argument, covered by the new tests.
The two findings from the initial review — the migration guide's runtime-error claim for the expose / shared aliases, and nested buckets that are a single validator slipping past the detector — are unchanged by this commit and still stand.
DeepSeek Flash (free via Pullfrog for OSS) | 𝕏
Address review: option aliases now throw a migration error at runtime and during static extraction (matching the migration guide), ArkType type() bucket wrappers are detected, and source regex covers `server: type(` forms. Co-authored-by: Yam Borodetsky <[email protected]>
|
Addressed the open review findings in 12b83ee:
|
There was a problem hiding this comment.
ℹ️ No critical issues — one minor documentation/regex mismatch inline.
Reviewed changes
expose/sharedaliases now throw —assertNotNestedBagdetects the removed option keys on the second argument and throwsremovedExposeAliasErrorMessage(), andassertNotRemovedExposeAliasSourcerejects them during@arkenv/buildextraction and Next.js codegen. This closes the gap where the aliases were silently ignored.- ArkType
type()buckets now detected —isSchemaBagtreats any function as a nested bag, andhasNestedBagSourcematches baretype(wrapper calls in source. - Migration guide wording tightened — the "Removed in v1" section now states that call sites still using the removed shapes throw at runtime and that static key extraction rejects the same shapes in schema source, matching the new behavior.
DeepSeek Flash (free via Pullfrog for OSS) | 𝕏
Extend hasNestedBagSource so at.type({…}) / z.object({…}) match, while
flat server: z.string() still does not. Align the JSDoc with the regex.
Co-authored-by: Yam Borodetsky <[email protected]>
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes
This run re-reviewed the single commit pushed since the last pullfrog review (bfd77e4, fix: detect dotted nested bag wrappers in source).
- Source guard now catches dotted object wrappers —
hasNestedBagSourceallows dotted call targets and requires(immediately followed by{, soclient: at.type({…})andserver: z.object({…})now throw during static extraction while a flat single-validator key such asserver: z.string()no longer false-positives. - JSDoc and tests updated to match — the doc comment documents the
(+{wrapper requirement, and the unit test addsat.type/z.objectpositives plus az.string()negative, so the assertion fails if the regex regresses. - Prior thread resolved — the earlier inline concern about
z.object(/at.type(not matching is addressed by this commit.
The remaining known boundary (a wrapper that takes a variable rather than an inline object, e.g. server: type(serverSchema), is caught at runtime but not by the static guard) is documented in the JSDoc and was already surfaced in the initial review, so it is not re-raised here.
DeepSeek Flash (free via Pullfrog for OSS) | 𝕏
Resolve conflicts with ArkEnvScript removal: keep both migration sections, drop script/__arkenv_env__ tests, retain nested-bag throw coverage and flat codegen assertions. Co-authored-by: Yam Borodetsky <[email protected]>
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes
This run re-reviewed the single commit pushed since the last pullfrog review — 672db1b, the merge of origin/v1 into the branch, whose only authored delta is the conflict resolution.
- Migration guide conflict resolved —
apps/www/content/docs/guides/migrating-to-v1.mdxkeeps v1's new "Next.jsArkEnvScriptremoved" section directly above the PR's "Removed in v1" section, so both the ArkEnvScript cut and the nested-bag/alias removal are documented and the#removed-in-v1anchor linked from the Next/Nuxt references still resolves. new-features.test.tsxconflict resolved — the obsoleteArkEnvScript/__arkenv_env__/ dynamic-client-lookup tests and theviimport are dropped (matching v1's removal), while the nested-bag throw test and the flat codegen assertion are retained; the assertion now expectsNEXT_PUBLIC_VAL: process.env.NEXT_PUBLIC_VAL,plusnot.toContain("__arkenv_env__"), matchinggenerateFlatFactoryCode.- Consistency verified — no dangling
ArkEnvScript,__arkenv_env__,isLegacy,LegacyNestedSchema, orgenerateFactoryCodereferences remain in source;@arkenv/nextjs(48 tests) and@arkenv/nuxt(48 tests) pass after building the affected packages.
The previously flagged known boundary (a nested bucket that is a single Zod/Valibot validator slips the runtime detector; the static source guard now catches it) is unchanged by this commit and remains a documented judgment call, not re-raised.
DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

Summary
arkenv({ server, client, shared, runtimeEnv })overload andexpose/sharedoption aliases from@arkenv/nextjsand@arkenv/nuxt.arkenv(schema, { exposeToClient, runtimeEnv })is the only supported path; legacy callers throw a migration-oriented error at runtime, and@arkenv/build/ static extraction reject the same shapes in schema source.@repo/utils/nested-bag-migration-error(value-aware nested detection, dotted wrappers likeat.type({…})/z.object({…}),expose/sharedthrow).v1.Fixes #1910
Test plan
origin/v1and resolve conflicts (migration guide +new-features.test.tsx)