Skip to content

Selective typst package staging with typst-gather#14174

Draft
gordonwoodhull wants to merge 3 commits intodeps/typst-gather-0.2.2from
bugfix/13983
Draft

Selective typst package staging with typst-gather#14174
gordonwoodhull wants to merge 3 commits intodeps/typst-gather-0.2.2from
bugfix/13983

Conversation

@gordonwoodhull
Copy link
Contributor

@gordonwoodhull gordonwoodhull commented Mar 7, 2026

Stacked on #14173 — merge that PR first (registers the typst-gather binary dependency with archiveOnly).

Fixes

Summary

Replace copy-all-packages behavior with selective staging using typst-gather analyze. When rendering a typst document in a project, only the packages actually imported are staged to .quarto/typst/packages/, rather than copying every package from every extension.

Changes

Remove in-tree Rust project, activate binary dependency

  • Remove package/typst-gather/ Rust source tree (~4500 lines)
  • Remove archiveOnly flag to enable download during configure
  • Remove cargo build from configure.sh/configure.cmd
  • Remove manual binary staging from prepare-dist.ts
  • Remove Cargo cache step from CI workflow
  • Add QUARTO_TYPST_GATHER env var override support

Use typst-gather analyze/gather subcommands

  • Update quarto call typst-gather to use analyze and gather subcommands
  • Extract shared binary path + analyze logic to src/core/typst-gather.ts
  • Update --init-config to use analyze for import discovery
  • 15 unit tests for config generation

Selective package staging during render

  • analyzeNeededPackages() runs typst-gather analyze on the generated .typ file
  • stageSelectedPackages() copies only needed packages (vs all)
  • Falls back to stage-everything if binary missing or analyze fails
  • Last-write-wins semantics: extensions override built-in packages
  • 15 unit tests for staging functions
  • 13 smoke tests including:
    • No packages staged for import-free documents
    • Only marginalia staged when using .column-margin
    • Fallback behavior when binary missing or returns non-zero
    • Error paths for --init-config

Test plan

  • All 30 unit tests pass (typst-gather.test.ts + typst-staging.test.ts)
  • All 13 smoke tests pass (typst-gather/typst-gather.test.ts)
  • Verified selective staging end-to-end: orange-book → 6 packages, empty doc → 0, marginalia-only → 1
  • CI passes on all platforms (requires Add typst-gather 0.2.2 binary dependency #14173 merged + S3 archive first)

Remove the Rust source tree at package/typst-gather/ and switch to the
downloaded binary registered in the previous commit.

- Remove archiveOnly flag to enable download during configure
- Remove cargo build from configure.sh and configure.cmd
- Remove typst-gather staging from prepare-dist.ts
- Remove Cargo cache step from CI workflow
- Add QUARTO_TYPST_GATHER env var override support
…mand for gathering

Replace the TypeScript regex-based import scanning with a call to
`typst-gather analyze`, which uses Typst's own parser for robust import
discovery including nested imports and transitive @Local dependencies.

- Remove parseSimpleToml(), discoverImportsFromFiles(), and related types
- Add runAnalyze() that pipes TOML config to `typst-gather analyze -` on stdin
- Rewrite generateConfigFromAnalysis() to consume structured JSON output
- Pipe config on stdin for auto-detected gather (no temp files)
- Use `gather` subcommand for all gather invocations
- Add QUARTO_TYPST_GATHER env var override to call version
- Extract typstGatherBinaryPath() shared helper
- Add 12 unit tests for generateConfigFromAnalysis()
Instead of copying ALL packages from built-in resources and extensions
into the scratch directory, use typst-gather analyze to determine the
exact set of packages needed (including transitive deps), then stage
only those.

- Create src/core/typst-gather.ts shared module (moved from cmd.ts)
- Decompose stageTypstPackages into collectPackageSources,
  analyzeNeededPackages, stageSelectedPackages, stageAllPackages
- Change from first-write-wins to last-write-wins so extensions can
  override built-in packages
- Falls back to staging everything if typst-gather binary is missing
  or analyze fails
- 14 unit tests for staging functions and TOML building
- 1 smoke test verifying no packages staged for import-free documents

Fixes #14157
@posit-snyk-bot
Copy link
Collaborator

posit-snyk-bot commented Mar 7, 2026

Snyk checks have passed. No issues have been found so far.

Status Scanner Critical High Medium Low Total (0)
Open Source Security 0 0 0 0 0 issues
Licenses 0 0 0 0 0 issues

💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse.

@gordonwoodhull gordonwoodhull added this to the v1.10 milestone Mar 7, 2026
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.

2 participants