Skip to content

Port JavaScript sources when their extensions are configured - #1

Merged
calvin-archastro merged 1 commit into
mainfrom
js-sources
Oct 7, 2026
Merged

calvin-archastro merged 1 commit into
mainfrom
js-sources

Conversation

@calvin-archastro

Copy link
Copy Markdown
Contributor

Problem and intent

rustify only sees .ts/.tsx. Projects with plain JavaScript modules, such as astroshots, whose astroshot CLI is bin/*.mjs, can't track those files in the port, so the CLI would be ported outside the graph, index, and ratchet.

Goal: let a project opt JavaScript files into the graph and port them exactly like TypeScript.

What changed

  • New extensions key in rustify.toml, default ["ts", "tsx"]. Existing configs behave as before.
  • With js/mjs/cjs/jsx added:
    • discovery picks them up under roots (.d.ts and dist/ are still never sources)
    • they parse with the TypeScript grammar (.jsx uses TSX)
    • an import of ./x.mjs resolves to x.ts/x.tsx first, then x.mjs. Bare imports also try .js/.mjs/.cjs/.jsx and index.*. Candidates whose extension isn't configured are ignored.
    • they map to Rust files with the extension stripped: bin/cli.mjs becomes bin/cli.rs
  • The UI golden checks also treat .jsx as a component.
  • rustify graph | head no longer prints a broken-pipe panic.
  • Docs: configuration.md, workflow.md, the README, and the example rustify.toml.

Scope: CLI only. Risk: low, because the default leaves current behavior unchanged. No user impact unless extensions is set.

Testing

  • Canonical end-to-end test: tests/porting_workflow.rs::ports_javascript_modules_when_their_extensions_are_configured. It runs the real binary against a temporary git repository with a .mjs CLI that imports another .mjs file and a TS module:
    • with the default config, the graph is empty
    • with mjs configured, all three files are in the graph and the brief maps bin/cli.mjs to bin/cli.rs / cli::bin::cli
    • the .mjs test is found
    • start and done record the symbol map
  • Unit test: packages::tests::a_javascript_import_falls_back_to_the_javascript_file_after_typescript, plus the existing candidate test, which now also asserts that dist/ never becomes a source.
  • cargo test (21 unit + 16 e2e), clippy -D warnings, and fmt --check all pass locally. CI runs them in the rustify workflow on this PR.

🤖 Generated with Claude Code

A new `extensions` key (default ["ts", "tsx"]) lists the source
extensions in the graph. With js/mjs/cjs/jsx added, those files are
discovered under roots, parsed with the TypeScript (or TSX) grammar,
resolved by their own names after TypeScript candidates, and mapped to
Rust files without the extension. Also exit quietly when stdout closes.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@calvin-archastro
calvin-archastro merged commit caac397 into main Oct 7, 2026
2 checks passed
@calvin-archastro
calvin-archastro deleted the js-sources branch October 7, 2026 14:05
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