feat(bundler): CJS wrapping with __commonJS runtime helper#249
Merged
Conversation
CJS interop PR2: CJS 모듈을 __commonJS 팩토리 함수로 래핑. - types.zig: WrapKind enum (none/cjs) + makeRequireVarName 유틸 - module.zig: wrap_kind 필드 추가 - graph.zig: exports_kind=commonjs → wrap_kind=cjs 자동 설정 - emitter.zig: __commonJS 런타임 헬퍼 주입 + CJS 모듈 래핑 + preamble 삽입 - linker.zig: CJS 모듈 스코프 호이스팅 스킵 + ESM→CJS import preamble 생성 - default/namespace: var <local> = require_<target>(); - named: var <local> = require_<target>().<imported>; 테스트 6개 추가 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
- fix: preamble + final_exports 동시 존재 시 중간 concat 메모리 누수 수정 → 단일 concat으로 합침 - perf: makeRequireVarName 캐시 (같은 CJS 모듈에서 여러 named import 시 중복 생성 방지) - test: CJS 테스트 7개 추가 (namespace, multiple named, aliased, minified, special chars, ESM+CJS 혼합, empty CJS) Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
CJS interop PR2: CJS 모듈을 esbuild 방식
__commonJS팩토리 함수로 래핑.WrapKindenum (none/cjs) +makeRequireVarName유틸var require_lib = __commonJS({ "lib.cjs"(exports, module) { ... } });으로 래핑var lib = require_lib();preamble 자동 생성__commonJS런타임 헬퍼 자동 주입 (CJS 모듈 존재 시에만)Changes
WrapKindenum,makeRequireVarNamewrap_kind필드exports_kind=commonjs→wrap_kind=cjsTest plan
__commonJS래핑🤖 Generated with Claude Code