Skip to content

feat(autolink): add autolink codegen package#2601

Merged
jianliang00 merged 1 commit into
lynx-family:mainfrom
jianliang00:p/wangjianliang/autolink-codegen-package
May 12, 2026
Merged

feat(autolink): add autolink codegen package#2601
jianliang00 merged 1 commit into
lynx-family:mainfrom
jianliang00:p/wangjianliang/autolink-codegen-package

Conversation

@jianliang00
Copy link
Copy Markdown
Contributor

@jianliang00 jianliang00 commented May 11, 2026

Summary

  • Add the @lynx-js/autolink-codegen package for Native Autolink code generation.
  • Generate JS facades, Android specs, and iOS specs from @lynxmodule declarations and lynx.ext.json.
  • Wire the package into workspace references, Vitest discovery, lockfile, and changeset.

Validation

  • pnpm --filter @lynx-js/autolink-codegen test
  • pnpm --filter @lynx-js/autolink-codegen build
  • pnpm exec tsc --build packages/lynx/autolink-codegen/tsconfig.json --pretty false
  • pnpm dprint check .changeset/native-autolink-codegen.md packages/lynx/autolink-codegen packages/lynx/tsconfig.json vitest.config.ts

Summary by CodeRabbit

  • New Features
    • Introduced @lynx-js/autolink-codegen package for native autolink code generation.
    • Added a CLI to generate native Android/iOS specs and TypeScript facades from type declarations.
  • Documentation
    • Added package README and changelog with usage and examples.
  • Tests
    • Added comprehensive tests for parsing, generation, security checks, and file output.
  • Chores
    • Expanded test discovery to include all lynx subpackages and added package build/test configs.

Copilot AI review requested due to automatic review settings May 11, 2026 10:43
@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented May 11, 2026

🦋 Changeset detected

Latest commit: c932220

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

This PR includes changesets to release 1 package
Name Type
@lynx-js/autolink-codegen Minor

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

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 11, 2026

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

This PR adds @lynx-js/autolink-codegen, a new package that parses @lynxmodule TypeScript declarations, reads lynx.ext.json, and generates TypeScript facades plus Android and iOS native spec/header/impl files; it includes a CLI, tests, and workspace integration.

Changes

Native Autolink Codegen Package

Layer / File(s) Summary
Package Setup & Build Configuration
packages/lynx/autolink-codegen/package.json, rslib.config.ts, tsconfig.build.json, tsconfig.json, tsconfig.test.json, turbo.json, vitest.config.ts
ESM package manifest with exports, CLI bin lynx-autolink-codegen, rslib build config, TypeScript project configs, Turbo tasks, and Vitest project config.
Documentation & Changelog
packages/lynx/autolink-codegen/README.md, CHANGELOG.md, .changeset/native-autolink-codegen.md
README describing generator inputs (types/**/*.d.ts with /** @lynxmodule */ and lynx.ext.json), outputs (TS/Android/iOS), CLI usage, changelog and changeset for a minor release.
Core Type Definitions & Parsing Models
packages/lynx/autolink-codegen/src/index.ts (lines 1–55)
TypeScript interfaces for CodegenOptions, GeneratedFile, native-module models, and regex/constants to locate @lynxmodule declarations.
TypeScript Declaration Parsing
packages/lynx/autolink-codegen/src/index.ts (lines 59–205)
parseNativeModules plus brace-matching extracts @lynxmodule classes and class bodies while handling comments/strings and detecting duplicates.
Method Parsing & Comment Handling
packages/lynx/autolink-codegen/src/index.ts (lines 284–418)
Comment stripping, buffering, and method parsing with completeness checks and signature extraction.
Parameter & Type Validation
packages/lynx/autolink-codegen/src/index.ts (lines 502–623)
parseParams and parseType accept only `void
Filesystem Scan & Manifest Parsing
packages/lynx/autolink-codegen/src/index.ts (lines 628–790)
Deterministic walk of types/ to read .d.ts files and readManifest parsing lynx.ext.json for Android/iOS source dirs and required Android packageName.
Code Generation Orchestration
packages/lynx/autolink-codegen/src/index.ts (lines 206–263, 791–950)
generate aggregates module specs, de-duplicates names, and assembles generated TS facade, Android Java spec, iOS header, and iOS implementation shim; includes type conversion helpers.
Path Security & Disk Output
packages/lynx/autolink-codegen/src/index.ts (lines 559–573, 268–279)
resolveInside validates targets stay within package root; runCodegen writes files to disk, creating directories, and rejects escapes.
CLI Argument Parsing & Help
packages/lynx/autolink-codegen/src/cli.ts (lines 18–45, 50–59)
parseArgs handles --help/-h and --root/-r <dir> with validation; printHelp emits usage text.
CLI Entry Point & Error Handling
packages/lynx/autolink-codegen/src/cli.ts (lines 64–83, 85–90)
main resolves --root, invokes runCodegen, logs output paths, and normalizes error reporting with non-zero exit codes.
Comprehensive Test Suite
packages/lynx/autolink-codegen/test/codegen.test.ts
Vitest tests validating parsing (with/without semicolons), comment handling, generation outputs for TS/Android/iOS, runCodegen writing, path-escape prevention, manifest validations, unsupported types, duplicate-module detection, and fixture helpers with cleanup.
Workspace Configuration Updates
packages/lynx/tsconfig.json, vitest.config.ts
Register autolink-codegen/tsconfig.build.json in parent packages/lynx/tsconfig.json references and generalize Vitest projects to packages/lynx/*/vitest.config.ts.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

Suggested reviewers

  • colinaaa
  • luhc228
  • HuJean

Poem

🐰 I nibble types from d.ts shelves,
I stitch Java, ObjC, and TS themselves.
A CLI hop, a generated stride,
Tests tumble in the rabbit’s pride.
Hooray — native bindings multiply!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The pull request title clearly and concisely describes the main change: adding a new autolink codegen package to the codebase, which aligns with all the files and features introduced.
Docstring Coverage ✅ Passed Docstring coverage is 91.43% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Tip

💬 Introducing Slack Agent: The best way for teams to turn conversations into code.

Slack Agent is built on CodeRabbit's deep understanding of your code, so your team can collaborate across the entire SDLC without losing context.

  • Generate code and open pull requests
  • Plan features and break down work
  • Investigate incidents and troubleshoot customer tickets together
  • Automate recurring tasks and respond to alerts with triggers
  • Summarize progress and report instantly

Built for teams:

  • Shared memory across your entire org—no repeating context
  • Per-thread sandboxes to safely plan and execute work
  • Governance built-in—scoped access, auditability, and budget controls

One agent for your entire SDLC. Right inside Slack.

👉 Get started


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@packages/lynx/autolink-codegen/package.json`:
- Around line 1-40: Add a top-level "packageManager" field to this package.json
for `@lynx-js/autolink-codegen` using the repo's standard pnpm version string
(e.g. "pnpm@<repo-pnpm-version>"); place it alongside the existing top-level
fields (near "engines" or "type") so installs use a consistent pnpm across the
workspace and satisfy the workspace package policy.

In `@packages/lynx/autolink-codegen/src/index.ts`:
- Around line 338-345: The parser currently allows parameters whose parsed type
is void, which later breaks emitters (e.g., toObjCParamType throws and
toJavaType produces invalid signatures); update parseParams so that after
calling parseType (the same call shown in the returned object creation) it
checks the resolved type for a void-kind and rejects it by throwing a clear
error that includes the parameter name and context (use the same
`${moduleName}.${methodName}.${name}` context string). Ensure the validation
references parseType's result and is applied for each parameter before returning
from parseParams so void parameters are rejected at parse time rather than
during codegen.

In `@packages/lynx/autolink-codegen/test/codegen.test.ts`:
- Around line 107-112: The test currently asserts exact ordering of generated
file paths by calling expect(files.map((file) => file.path)).toEqual([...]),
which is order-sensitive; update the assertion to be order-insensitive by either
sorting the array returned by files.map((file) => file.path) before comparing or
using an order-insensitive matcher (e.g.,
expect(...).toEqual(expect.arrayContaining(...)) and also assert lengths).
Locate the assertion in packages/lynx/autolink-codegen/test/codegen.test.ts (the
files variable and the map callback) and change the assertion to compare sorted
arrays or use arrayContaining with a length check so generate() can return paths
in any order.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 79001243-7113-4631-8db2-cdfb0a259ac8

📥 Commits

Reviewing files that changed from the base of the PR and between ad1f90f and 23515a8.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (15)
  • .changeset/native-autolink-codegen.md
  • packages/lynx/autolink-codegen/CHANGELOG.md
  • packages/lynx/autolink-codegen/README.md
  • packages/lynx/autolink-codegen/package.json
  • packages/lynx/autolink-codegen/rslib.config.ts
  • packages/lynx/autolink-codegen/src/cli.ts
  • packages/lynx/autolink-codegen/src/index.ts
  • packages/lynx/autolink-codegen/test/codegen.test.ts
  • packages/lynx/autolink-codegen/tsconfig.build.json
  • packages/lynx/autolink-codegen/tsconfig.json
  • packages/lynx/autolink-codegen/tsconfig.test.json
  • packages/lynx/autolink-codegen/turbo.json
  • packages/lynx/autolink-codegen/vitest.config.ts
  • packages/lynx/tsconfig.json
  • vitest.config.ts

Comment thread packages/lynx/autolink-codegen/package.json
Comment thread packages/lynx/autolink-codegen/src/index.ts Outdated
Comment thread packages/lynx/autolink-codegen/test/codegen.test.ts Outdated
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds the new @lynx-js/autolink-codegen package (split out of #2587) and wires it into the monorepo so it can be built/tested as part of the workspace. The package provides a Native-only code generator (TS facade + Android + iOS specs) with a CLI and Vitest coverage.

Changes:

  • Introduce packages/lynx/autolink-codegen with codegen implementation, CLI entrypoint, and Vitest tests.
  • Register the package in workspace tooling (Vitest projects glob + packages/lynx TS project references) and lockfile.
  • Add a Changeset + package README/CHANGELOG metadata.

Reviewed changes

Copilot reviewed 15 out of 16 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
vitest.config.ts Expands Lynx Vitest workspace discovery to include all packages/lynx/*/vitest.config.ts.
pnpm-lock.yaml Adds the new workspace importer for packages/lynx/autolink-codegen.
packages/lynx/tsconfig.json Adds TS project reference for the new package build config.
packages/lynx/autolink-codegen/vitest.config.ts Defines Vitest configuration for the new package tests.
packages/lynx/autolink-codegen/turbo.json Declares Turbo tasks/outputs for build and test in the new package.
packages/lynx/autolink-codegen/tsconfig.test.json Adds TS config for typechecking tests.
packages/lynx/autolink-codegen/tsconfig.json Adds project references for build + test TS configs.
packages/lynx/autolink-codegen/tsconfig.build.json Adds TS build config for the package source.
packages/lynx/autolink-codegen/test/codegen.test.ts Adds unit tests for parsing, generation, error cases, and path safety.
packages/lynx/autolink-codegen/src/index.ts Implements parsing + generation + filesystem writing for JS/Android/iOS specs.
packages/lynx/autolink-codegen/src/cli.ts Adds the lynx-autolink-codegen CLI wrapper around runCodegen.
packages/lynx/autolink-codegen/rslib.config.ts Configures rslib build entries for library + CLI bundles.
packages/lynx/autolink-codegen/README.md Documents usage, inputs (types/**/*.d.ts, lynx.ext.json), and outputs.
packages/lynx/autolink-codegen/package.json Declares package metadata, exports, and CLI binary mapping.
packages/lynx/autolink-codegen/CHANGELOG.md Introduces initial changelog entry for the new package.
.changeset/native-autolink-codegen.md Adds changeset to release the new package as a minor bump.
Files not reviewed (1)
  • pnpm-lock.yaml: Language not supported

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread packages/lynx/autolink-codegen/src/index.ts
@codecov
Copy link
Copy Markdown

codecov Bot commented May 11, 2026

Codecov Report

❌ Patch coverage is 80.41096% with 143 lines in your changes missing coverage. Please review.
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
packages/lynx/autolink-codegen/src/index.ts 86.19% 94 Missing ⚠️
packages/lynx/autolink-codegen/src/cli.ts 0.00% 49 Missing ⚠️

📢 Thoughts on this report? Let us know!

@codspeed-hq
Copy link
Copy Markdown

codspeed-hq Bot commented May 11, 2026

Merging this PR will degrade performance by 16.12%

⚠️ Different runtime environments detected

Some benchmarks with significant performance changes were compared across different runtime environments,
which may affect the accuracy of the results.

Open the report in CodSpeed to investigate

❌ 1 regressed benchmark
✅ 80 untouched benchmarks
⏩ 26 skipped benchmarks1

⚠️ Please fix the performance issues or acknowledge them on CodSpeed.

Performance Changes

Benchmark BASE HEAD Efficiency
008-many-use-state-destroyBackground 8 ms 9.5 ms -16.12%

Comparing jianliang00:p/wangjianliang/autolink-codegen-package (c932220) with main (1e1257e)2

Open in CodSpeed

Footnotes

  1. 26 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

  2. No successful run was found on main (47bb2ff) during the generation of this report, so 1e1257e was used instead as the comparison base. There might be some changes unrelated to this pull request in this report.

@relativeci
Copy link
Copy Markdown

relativeci Bot commented May 11, 2026

Web Explorer

#9670 Bundle Size — 901.38KiB (0%).

c932220(current) vs f8a3cbd main#9669(baseline)

Bundle metrics  Change 2 changes
                 Current
#9670
     Baseline
#9669
No change  Initial JS 45.06KiB 45.06KiB
No change  Initial CSS 2.22KiB 2.22KiB
Change  Cache Invalidation 0% 1.53%
No change  Chunks 9 9
No change  Assets 11 11
Change  Modules 230(+0.44%) 229
No change  Duplicate Modules 11 11
Change  Duplicate Code 27.21%(-0.04%) 27.22%
No change  Packages 10 10
No change  Duplicate Packages 0 0
Bundle size by type  no changes
                 Current
#9670
     Baseline
#9669
No change  JS 497.1KiB 497.1KiB
No change  Other 402.06KiB 402.06KiB
No change  CSS 2.22KiB 2.22KiB

Bundle analysis reportBranch jianliang00:p/wangjianliang/auto...Project dashboard


Generated by RelativeCIDocumentationReport issue

@relativeci
Copy link
Copy Markdown

relativeci Bot commented May 11, 2026

React MTF Example

#1228 Bundle Size — 207.46KiB (0%).

c932220(current) vs f8a3cbd main#1227(baseline)

Bundle metrics  no changes
                 Current
#1228
     Baseline
#1227
No change  Initial JS 0B 0B
No change  Initial CSS 0B 0B
No change  Cache Invalidation 0% 0%
No change  Chunks 0 0
No change  Assets 3 3
No change  Modules 192 192
No change  Duplicate Modules 77 77
No change  Duplicate Code 44.38% 44.38%
No change  Packages 2 2
No change  Duplicate Packages 0 0
Bundle size by type  no changes
                 Current
#1228
     Baseline
#1227
No change  IMG 111.23KiB 111.23KiB
No change  Other 96.23KiB 96.23KiB

Bundle analysis reportBranch jianliang00:p/wangjianliang/auto...Project dashboard


Generated by RelativeCIDocumentationReport issue

@relativeci
Copy link
Copy Markdown

relativeci Bot commented May 11, 2026

React External

#1210 Bundle Size — 693.04KiB (0%).

c932220(current) vs f8a3cbd main#1209(baseline)

Bundle metrics  no changes
                 Current
#1210
     Baseline
#1209
No change  Initial JS 0B 0B
No change  Initial CSS 0B 0B
No change  Cache Invalidation 0% 0%
No change  Chunks 0 0
No change  Assets 3 3
No change  Modules 17 17
No change  Duplicate Modules 5 5
No change  Duplicate Code 8.59% 8.59%
No change  Packages 0 0
No change  Duplicate Packages 0 0
Bundle size by type  no changes
                 Current
#1210
     Baseline
#1209
No change  Other 693.04KiB 693.04KiB

Bundle analysis reportBranch jianliang00:p/wangjianliang/auto...Project dashboard


Generated by RelativeCIDocumentationReport issue

@relativeci
Copy link
Copy Markdown

relativeci Bot commented May 11, 2026

React Example

#8096 Bundle Size — 236.51KiB (0%).

c932220(current) vs f8a3cbd main#8095(baseline)

Bundle metrics  no changes
                 Current
#8096
     Baseline
#8095
No change  Initial JS 0B 0B
No change  Initial CSS 0B 0B
No change  Cache Invalidation 0% 0%
No change  Chunks 0 0
No change  Assets 4 4
No change  Modules 197 197
No change  Duplicate Modules 80 80
No change  Duplicate Code 44.87% 44.87%
No change  Packages 2 2
No change  Duplicate Packages 0 0
Bundle size by type  no changes
                 Current
#8096
     Baseline
#8095
No change  IMG 145.76KiB 145.76KiB
No change  Other 90.75KiB 90.75KiB

Bundle analysis reportBranch jianliang00:p/wangjianliang/auto...Project dashboard


Generated by RelativeCIDocumentationReport issue

@relativeci
Copy link
Copy Markdown

relativeci Bot commented May 11, 2026

React Example with Element Template

#363 Bundle Size — 197.79KiB (0%).

c932220(current) vs f8a3cbd main#362(baseline)

Bundle metrics  Change 2 changes
                 Current
#363
     Baseline
#362
No change  Initial JS 0B 0B
No change  Initial CSS 0B 0B
No change  Cache Invalidation 0% 0%
No change  Chunks 0 0
No change  Assets 4 4
Change  Modules 79(-2.47%) 81
No change  Duplicate Modules 23 23
Change  Duplicate Code 40.32%(+0.07%) 40.29%
No change  Packages 2 2
No change  Duplicate Packages 0 0
Bundle size by type  no changes
                 Current
#363
     Baseline
#362
No change  IMG 145.76KiB 145.76KiB
No change  Other 52.03KiB 52.03KiB

Bundle analysis reportBranch jianliang00:p/wangjianliang/auto...Project dashboard


Generated by RelativeCIDocumentationReport issue

@jianliang00 jianliang00 force-pushed the p/wangjianliang/autolink-codegen-package branch 2 times, most recently from 46e94a5 to 3f96789 Compare May 11, 2026 11:29
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@packages/lynx/autolink-codegen/src/index.ts`:
- Around line 684-689: The packageName read via readRequiredString is not
validated as a Java package identifier; add a validation step after the current
read (for the packageName variable) that enforces Java package-name rules
(dot-separated identifiers, each starting with a letter/underscore, containing
only letters/digits/underscores, no empty segments) — implement a helper like
isValidJavaPackageName(packageName) and if invalid throw a clear manifest reader
error mentioning platforms.android.packageName; integrate this check before any
use (e.g., before the generated package declaration "package
${packageName}.generated;" and before the code that splits on '.' to build
output directories) so malformed names fail fast with a helpful message.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 3cac2c89-b28c-4c37-ae14-3ce7ab501d8a

📥 Commits

Reviewing files that changed from the base of the PR and between e5ce6f7 and 46e94a5.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (15)
  • .changeset/native-autolink-codegen.md
  • packages/lynx/autolink-codegen/CHANGELOG.md
  • packages/lynx/autolink-codegen/README.md
  • packages/lynx/autolink-codegen/package.json
  • packages/lynx/autolink-codegen/rslib.config.ts
  • packages/lynx/autolink-codegen/src/cli.ts
  • packages/lynx/autolink-codegen/src/index.ts
  • packages/lynx/autolink-codegen/test/codegen.test.ts
  • packages/lynx/autolink-codegen/tsconfig.build.json
  • packages/lynx/autolink-codegen/tsconfig.json
  • packages/lynx/autolink-codegen/tsconfig.test.json
  • packages/lynx/autolink-codegen/turbo.json
  • packages/lynx/autolink-codegen/vitest.config.ts
  • packages/lynx/tsconfig.json
  • vitest.config.ts
✅ Files skipped from review due to trivial changes (7)
  • packages/lynx/autolink-codegen/CHANGELOG.md
  • packages/lynx/autolink-codegen/README.md
  • packages/lynx/autolink-codegen/tsconfig.json
  • .changeset/native-autolink-codegen.md
  • packages/lynx/autolink-codegen/tsconfig.build.json
  • vitest.config.ts
  • packages/lynx/autolink-codegen/tsconfig.test.json
🚧 Files skipped from review as they are similar to previous changes (7)
  • packages/lynx/tsconfig.json
  • packages/lynx/autolink-codegen/vitest.config.ts
  • packages/lynx/autolink-codegen/package.json
  • packages/lynx/autolink-codegen/src/cli.ts
  • packages/lynx/autolink-codegen/turbo.json
  • packages/lynx/autolink-codegen/rslib.config.ts
  • packages/lynx/autolink-codegen/test/codegen.test.ts

Comment thread packages/lynx/autolink-codegen/src/index.ts
@jianliang00 jianliang00 force-pushed the p/wangjianliang/autolink-codegen-package branch from 3f96789 to aa798a9 Compare May 11, 2026 11:31
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (1)
packages/lynx/autolink-codegen/src/index.ts (1)

880-884: 💤 Low value

Verify the generated .m shim is intentional — it contains no @implementation.

generateIosImplementation emits an Objective-C source file whose only content is #import "${module.name}Spec.h". Since ${module.name}Spec.h declares a @protocol, this .m produces an empty translation unit — it has no class/category/protocol implementation, so the file contributes nothing at link time but still adds to build inputs. If the intent is a stub for user-provided extension code, consider either:

  • skipping .m generation entirely (protocol declarations live in the header), or
  • emitting an @implementation stub or a clear comment indicating that consumers must provide their own implementation conforming to the spec.

Could you confirm whether downstream Lynx iOS tooling (CocoaPods spec, SwiftPM, or the Xcode build) expects this .m file to exist? If yes, a short justification comment in the generator would help future maintainers.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@packages/lynx/autolink-codegen/src/index.ts` around lines 880 - 884, The
generated .m currently only imports "${module.name}Spec.h" (see
generateIosImplementation) producing an empty translation unit; update the
generator to either stop emitting the .m at all when no implementation is
needed, or emit a clear stub (an `@implementation` block or an explanatory
comment) so the file has intent — choose one approach and apply it consistently
for generateIosImplementation: if you keep the file, add a concise justification
comment at the top and an empty `@implementation/`${module.name}Spec placeholder;
if you remove it, ensure callers of generateIosImplementation handle the absence
of an Objective-C implementation file.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@packages/lynx/autolink-codegen/src/index.ts`:
- Around line 268-279: The loop in runCodegen writes files as it resolves each
target, so a later resolveInside failure can leave partially written output;
change runCodegen to first iterate over the generated files from generate({ root
}) and call resolveInside for every file.path (using the same 'package root'
context) to produce and validate all target paths up front, collecting the
resolved targets into an array, and only after all resolves succeed perform the
mkdirSync+writeFileSync phase using the already-resolved targets; keep function
names generate, resolveInside and runCodegen to locate the change.

---

Nitpick comments:
In `@packages/lynx/autolink-codegen/src/index.ts`:
- Around line 880-884: The generated .m currently only imports
"${module.name}Spec.h" (see generateIosImplementation) producing an empty
translation unit; update the generator to either stop emitting the .m at all
when no implementation is needed, or emit a clear stub (an `@implementation` block
or an explanatory comment) so the file has intent — choose one approach and
apply it consistently for generateIosImplementation: if you keep the file, add a
concise justification comment at the top and an empty
`@implementation/`${module.name}Spec placeholder; if you remove it, ensure callers
of generateIosImplementation handle the absence of an Objective-C implementation
file.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: e52d17dc-15d8-490a-9f2c-9566dfba5644

📥 Commits

Reviewing files that changed from the base of the PR and between 46e94a5 and aa798a9.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (15)
  • .changeset/native-autolink-codegen.md
  • packages/lynx/autolink-codegen/CHANGELOG.md
  • packages/lynx/autolink-codegen/README.md
  • packages/lynx/autolink-codegen/package.json
  • packages/lynx/autolink-codegen/rslib.config.ts
  • packages/lynx/autolink-codegen/src/cli.ts
  • packages/lynx/autolink-codegen/src/index.ts
  • packages/lynx/autolink-codegen/test/codegen.test.ts
  • packages/lynx/autolink-codegen/tsconfig.build.json
  • packages/lynx/autolink-codegen/tsconfig.json
  • packages/lynx/autolink-codegen/tsconfig.test.json
  • packages/lynx/autolink-codegen/turbo.json
  • packages/lynx/autolink-codegen/vitest.config.ts
  • packages/lynx/tsconfig.json
  • vitest.config.ts
✅ Files skipped from review due to trivial changes (8)
  • packages/lynx/autolink-codegen/turbo.json
  • .changeset/native-autolink-codegen.md
  • packages/lynx/autolink-codegen/CHANGELOG.md
  • vitest.config.ts
  • packages/lynx/autolink-codegen/vitest.config.ts
  • packages/lynx/autolink-codegen/README.md
  • packages/lynx/tsconfig.json
  • packages/lynx/autolink-codegen/tsconfig.test.json
🚧 Files skipped from review as they are similar to previous changes (5)
  • packages/lynx/autolink-codegen/tsconfig.build.json
  • packages/lynx/autolink-codegen/tsconfig.json
  • packages/lynx/autolink-codegen/rslib.config.ts
  • packages/lynx/autolink-codegen/package.json
  • packages/lynx/autolink-codegen/src/cli.ts

Comment thread packages/lynx/autolink-codegen/src/index.ts
@jianliang00 jianliang00 force-pushed the p/wangjianliang/autolink-codegen-package branch from aa798a9 to 725805b Compare May 11, 2026 11:50
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

♻️ Duplicate comments (1)
packages/lynx/autolink-codegen/test/codegen.test.ts (1)

140-155: ⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Resolve generated files by path before asserting content.

The path assertion is order-insensitive now, but Lines 140-155 still assume files[0], files[1], and files[2] stay in a fixed order. A harmless emitter reordering would still make this test fail.

Suggested test hardening
     expect(files.map((file) => file.path).sort()).toEqual([
       'generated/StorageModule.ts',
       'android/src/main/java/com/example/storage/generated/StorageModuleSpec.java',
       'ios/src/generated/StorageModuleSpec.h',
       'ios/src/generated/StorageModuleSpec.m',
     ].sort());
-    expect(files[0]?.content).toContain('NativeModules.StorageModule');
-    expect(files[1]?.content).toContain(
+    const filesByPath = new Map(files.map((file) => [file.path, file.content]));
+    expect(filesByPath.get('generated/StorageModule.ts')).toContain(
+      'NativeModules.StorageModule',
+    );
+    expect(
+      filesByPath.get(
+        'android/src/main/java/com/example/storage/generated/StorageModuleSpec.java',
+      ),
+    ).toContain(
       'package com.example.storage.generated;',
     );
-    expect(files[1]?.content).toContain(
+    expect(
+      filesByPath.get(
+        'android/src/main/java/com/example/storage/generated/StorageModuleSpec.java',
+      ),
+    ).toContain(
       'import com.lynx.jsbridge.LynxContextModule;',
     );
-    expect(files[1]?.content).toContain('import com.lynx.jsbridge.LynxMethod;');
-    expect(files[1]?.content).toContain(
+    expect(
+      filesByPath.get(
+        'android/src/main/java/com/example/storage/generated/StorageModuleSpec.java',
+      ),
+    ).toContain('import com.lynx.jsbridge.LynxMethod;');
+    expect(
+      filesByPath.get(
+        'android/src/main/java/com/example/storage/generated/StorageModuleSpec.java',
+      ),
+    ).toContain(
       'import com.lynx.tasm.behavior.LynxContext;',
     );
-    expect(files[1]?.content).toContain('public abstract void setValue');
-    expect(files[2]?.content).toContain('@protocol StorageModuleSpec');
-    expect(files[2]?.content).toContain(
+    expect(
+      filesByPath.get(
+        'android/src/main/java/com/example/storage/generated/StorageModuleSpec.java',
+      ),
+    ).toContain('public abstract void setValue');
+    expect(filesByPath.get('ios/src/generated/StorageModuleSpec.h')).toContain(
+      '@protocol StorageModuleSpec',
+    );
+    expect(filesByPath.get('ios/src/generated/StorageModuleSpec.h')).toContain(
       '- (nullable NSString *)getValue:(NSString *)key;',
     );
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@packages/lynx/autolink-codegen/test/codegen.test.ts` around lines 140 - 155,
The test assumes a stable order of the generated files (using files[0],
files[1], files[2]) which is brittle; change the assertions to resolve files by
their path/name before checking content (e.g., build a lookup from files[].path
to file and use that lookup for expectations). Update the assertions that
reference files[0], files[1], files[2] to instead find the correct file by path
(or sort by path) and then assert on that file's .content; keep the existing
assertion strings (e.g., 'NativeModules.StorageModule', 'package
com.example.storage.generated;', '@protocol StorageModuleSpec') and use the
lookup when calling expect(...).toContain(...).
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@packages/lynx/autolink-codegen/src/index.ts`:
- Around line 272-275: resolveInside only validates the lexical path; to prevent
escaping the package root via existing symlinks you must add a helper (e.g.,
assertNoSymlinkTraversal(root, target)) and call it for each computed target
before fs.mkdirSync and fs.writeFileSync. The helper should resolve root,
iterate path.relative(root, target) segments, join them incrementally, and throw
if fs.existsSync(current) && fs.lstatSync(current).isSymbolicLink() so any
symlink on the path from root to target is rejected; invoke this check in the
loop that computes target right before creating directories or writing files
(references: resolveInside, target, assertNoSymlinkTraversal).
- Around line 514-522: The parameter parser in the code that does
trimmed.split(',').map(...) for NativeModuleParam throws on trailing commas
because split produces an empty string segment; update the parsing pipeline (the
trimmed.split(',') usage inside this block that constructs NativeModuleParam for
moduleName/methodName in index.ts) to filter out empty or whitespace-only
segments (e.g., filter before map) so trailing commas are ignored and only
non-empty normalizedParam values are validated and mapped.

---

Duplicate comments:
In `@packages/lynx/autolink-codegen/test/codegen.test.ts`:
- Around line 140-155: The test assumes a stable order of the generated files
(using files[0], files[1], files[2]) which is brittle; change the assertions to
resolve files by their path/name before checking content (e.g., build a lookup
from files[].path to file and use that lookup for expectations). Update the
assertions that reference files[0], files[1], files[2] to instead find the
correct file by path (or sort by path) and then assert on that file's .content;
keep the existing assertion strings (e.g., 'NativeModules.StorageModule',
'package com.example.storage.generated;', '@protocol StorageModuleSpec') and use
the lookup when calling expect(...).toContain(...).
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 102362de-1794-4aa9-9bb0-a20ea9f22f97

📥 Commits

Reviewing files that changed from the base of the PR and between aa798a9 and 725805b.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (15)
  • .changeset/native-autolink-codegen.md
  • packages/lynx/autolink-codegen/CHANGELOG.md
  • packages/lynx/autolink-codegen/README.md
  • packages/lynx/autolink-codegen/package.json
  • packages/lynx/autolink-codegen/rslib.config.ts
  • packages/lynx/autolink-codegen/src/cli.ts
  • packages/lynx/autolink-codegen/src/index.ts
  • packages/lynx/autolink-codegen/test/codegen.test.ts
  • packages/lynx/autolink-codegen/tsconfig.build.json
  • packages/lynx/autolink-codegen/tsconfig.json
  • packages/lynx/autolink-codegen/tsconfig.test.json
  • packages/lynx/autolink-codegen/turbo.json
  • packages/lynx/autolink-codegen/vitest.config.ts
  • packages/lynx/tsconfig.json
  • vitest.config.ts
✅ Files skipped from review due to trivial changes (9)
  • packages/lynx/autolink-codegen/CHANGELOG.md
  • packages/lynx/autolink-codegen/README.md
  • packages/lynx/autolink-codegen/tsconfig.test.json
  • packages/lynx/tsconfig.json
  • packages/lynx/autolink-codegen/turbo.json
  • packages/lynx/autolink-codegen/package.json
  • packages/lynx/autolink-codegen/vitest.config.ts
  • packages/lynx/autolink-codegen/tsconfig.json
  • .changeset/native-autolink-codegen.md
🚧 Files skipped from review as they are similar to previous changes (4)
  • packages/lynx/autolink-codegen/tsconfig.build.json
  • vitest.config.ts
  • packages/lynx/autolink-codegen/src/cli.ts
  • packages/lynx/autolink-codegen/rslib.config.ts

Comment thread packages/lynx/autolink-codegen/src/index.ts Outdated
Comment thread packages/lynx/autolink-codegen/src/index.ts Outdated
@jianliang00 jianliang00 force-pushed the p/wangjianliang/autolink-codegen-package branch from 725805b to 79f0b68 Compare May 12, 2026 07:51
@jianliang00 jianliang00 force-pushed the p/wangjianliang/autolink-codegen-package branch from 79f0b68 to 9df60d7 Compare May 12, 2026 11:49
@jianliang00 jianliang00 force-pushed the p/wangjianliang/autolink-codegen-package branch from 9df60d7 to c932220 Compare May 12, 2026 11:53
@jianliang00 jianliang00 merged commit 0543b01 into lynx-family:main May 12, 2026
38 of 41 checks passed
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.

3 participants