Skip to content

Hide typescript import from consumer bundlers - #422

Open
freekh wants to merge 3327 commits into
mainfrom
fix/typescript-bundle-source-map-error
Open

Hide typescript import from consumer bundlers#422
freekh wants to merge 3327 commits into
mainfrom
fix/typescript-bundle-source-map-error

Conversation

@freekh

@freekh freekh commented May 13, 2026

Copy link
Copy Markdown
Contributor

@valbuild/server's built ESM bundle previously opened with a static import ts from 'typescript'. When a Next.js consumer (e.g. via @valbuild/next) ran next build --webpack or Turbopack, the bundler walked the import graph through @valbuild/server → typescript and landed inside lib/typescript.js, where TypeScript's optional require("source-map-support").install() is buried in a try/catch. The require is harmless at runtime, but the bundler's static analysis emitted "Module not found: Can't resolve 'source-map-support'" warnings on every consumer build.

Centralize the runtime typescript import in
packages/server/src/internal/typescript.ts via createRequire(import.meta.url). Bundlers can't statically follow createRequire, so they no longer trace into typescript's distribution. Each consumer file now imports the namespace type-only (import type * as ts from "typescript" — erased at compile time, also invisible to bundlers) and the runtime value through the wrapper as tsLib. Module augmentation in patch/ts/ops.ts is preserved through the type-only side.

Rollup auto-transforms import.meta.url for Preconstruct's CJS bundle, so both CJS and ESM consumers work unchanged at runtime. Jest evaluates sources as CJS and would reject the literal import.meta token, so the package's jest.config.js maps the wrapper import to typescript directly for tests.

freekh added 30 commits January 24, 2026 10:50
RemirrorError: `getRootProps` has been attached to the DOM more than once.
It should only be attached to the dom once per editor.
Called 2 times For more information visit https://remirror.io/docs/errors#rmr0201

See: remirror/remirror#2260
Use worker thread for searching
... unvibing it a bit
freekh and others added 27 commits April 27, 2026 18:13
Adds experimental AI features (disabled by default) to Val
Co-authored-by: Copilot <copilot@github.com>
Co-authored-by: Copilot <copilot@github.com>
…gration

Co-authored-by: Copilot <copilot@github.com>
…operations and update validation for non-file operations

Co-authored-by: Copilot <copilot@github.com>
…oving error reporting

Co-authored-by: Copilot <copilot@github.com>
- Renamed `convert_session_image_to_patch` to `convert_session_image_field` and added new tools: `convert_session_image_richtext` and `convert_session_image_gallery`.
- Updated the `TOOL_DISPLAY` record in `AIChat.tsx` to reflect the new tool names and descriptions.
- Created `aiImageToolPatches.ts` to handle patch building for image fields, richtext, and galleries.
- Added tests for the new patch building functions in `aiImageToolPatches.test.ts`.
- Refactored `useAI.ts` to utilize the new tools and handle image patching more effectively.
- Updated tool names in `toolNames.ts` to match the new naming conventions.
- Add `expandSessionKeysInPatch` function to handle session key transformations in patches.
- Introduce `planSessionKeyExpansion` to plan and validate session key usage in patches.
- Create tests for session key expansion scenarios in `expandSessionKeysInPatch.test.ts`.
- Update `useAI` hook to integrate session key expansion and handle related errors.
- Replace deprecated tools for session image handling with a new tool `add_session_image_to_gallery`.
- Update tool descriptions and documentation to reflect changes in session key handling.
…improve metadata processing

Co-authored-by: Copilot <copilot@github.com>
…o manage auth states

Co-authored-by: Copilot <copilot@github.com>
Co-authored-by: Copilot <copilot@github.com>
AI chat support for images
@valbuild/server's built ESM bundle previously opened with a static
`import ts from 'typescript'`. When a Next.js consumer (e.g. via
@valbuild/next) ran `next build --webpack` or Turbopack, the bundler
walked the import graph through @valbuild/server → typescript and
landed inside lib/typescript.js, where TypeScript's optional
`require("source-map-support").install()` is buried in a try/catch.
The require is harmless at runtime, but the bundler's static analysis
emitted "Module not found: Can't resolve 'source-map-support'" warnings
on every consumer build.

Centralize the runtime `typescript` import in
packages/server/src/internal/typescript.ts via `createRequire(import.meta.url)`.
Bundlers can't statically follow createRequire, so they no longer trace
into typescript's distribution. Each consumer file now imports the
namespace type-only (`import type * as ts from "typescript"` — erased at
compile time, also invisible to bundlers) and the runtime value through
the wrapper as `tsLib`. Module augmentation in patch/ts/ops.ts is
preserved through the type-only side.

Rollup auto-transforms `import.meta.url` for Preconstruct's CJS bundle,
so both CJS and ESM consumers work unchanged at runtime. Jest evaluates
sources as CJS and would reject the literal `import.meta` token, so the
package's jest.config.js maps the wrapper import to `typescript`
directly for tests.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
@changeset-bot

changeset-bot Bot commented May 13, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 15bd779

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 3 packages
Name Type
@valbuild/server Patch
@valbuild/next Patch
@valbuild/cli Patch

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

@freekh
freekh force-pushed the main branch 2 times, most recently from a72dec0 to 9a45969 Compare May 19, 2026 19:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant