Skip to content

chore(cli): Drop jsdom and w3c-xmlserializer in favor of @xmldom/xmldom - #2393

Open
dividedmind wants to merge 1 commit into
mainfrom
chore/maven-no-jsdom
Open

chore(cli): Drop jsdom and w3c-xmlserializer in favor of @xmldom/xmldom#2393
dividedmind wants to merge 1 commit into
mainfrom
chore/maven-no-jsdom

Conversation

@dividedmind

Copy link
Copy Markdown
Collaborator

Remove the heavy 'jsdom' and 'w3c-xmlserializer' dependencies from the CLI package, replacing them with '@xmldom/xmldom' to streamline and secure our runtime footprint.

Refactor mavenInstaller.ts to programmatically parse and build the DOM with standard, namespace-agnostic DOM APIs. Auto-detect the file's original indentation and trailing whitespace formatting to ensure the result is beautifully formatted and preserves the developer's original style.

Update the maven installer unit tests to assert exact, high-fidelity indentation and layout. Add new test cases verifying correct handling of empty plugins sections and four-space file indentation.

Assisted-by: Claude:claude-opus-5
Assisted-by: Gemini CLI:gemini-3.5-flash

@dividedmind
dividedmind requested review from kgilpin and a lite review from Copilot September 1, 2026 14:08
@dividedmind dividedmind self-assigned this Sep 1, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🔵 Needs a closer look

It changes core pom.xml parsing/rewriting behavior and XML serialization dependencies in a way that can affect real user projects beyond the covered fixtures and should get final human validation.

Pull request overview

This PR reduces the CLI package’s runtime footprint by removing jsdom and w3c-xmlserializer, replacing them with @xmldom/xmldom, and refactors the Maven installer to rewrite pom.xml via standard DOM APIs while preserving indentation and trailing whitespace. Unit tests and XML fixtures are updated to assert exact output formatting, and new fixture scenarios are added (four-space indentation and empty <plugins></plugins> handling).

Changes:

  • Replace jsdom + w3c-xmlserializer with @xmldom/xmldom in the CLI package and lockfile.
  • Refactor MavenInstaller to parse/update the DOM, detect indentation, and preserve trailing whitespace when serializing.
  • Tighten MavenInstaller unit tests to compare full XML (modulo EOL) and expand fixture coverage for formatting edge cases.
File summaries
File Description
yarn.lock Removes jsdom/w3c-xmlserializer entries and adds @xmldom/xmldom resolution.
packages/cli/package.json Drops jsdom + related @types/* deps and adds @xmldom/xmldom.
packages/cli/src/cmds/agentInstaller/mavenInstaller.ts Replaces JSDOM-based XML editing with @xmldom/xmldom parsing/serialization and indentation-aware DOM insertion.
packages/cli/tests/unit/agentInstall/mavenInstaller.spec.ts Compares exact fixture XML output (ignoring only CRLF vs LF) instead of collapsing whitespace.
packages/cli/tests/unit/fixtures/java/maven/data/plugins.expected.xml Updates expected formatting and comment layout for rewritten output.
packages/cli/tests/unit/fixtures/java/maven/data/plugins.actual.xml Updates input fixture comment content/layout used as the pre-install source file.
packages/cli/tests/unit/fixtures/java/maven/data/no-plugins.expected.xml Updates expected output formatting for the “no plugins” scenario.
packages/cli/tests/unit/fixtures/java/maven/data/no-plugins.actual.xml Updates input fixture comment content/layout used as the pre-install source file.
packages/cli/tests/unit/fixtures/java/maven/data/no-build.expected.xml Updates expected output formatting for the “no build” scenario.
packages/cli/tests/unit/fixtures/java/maven/data/no-build.actual.xml Updates input fixture comment content/layout used as the pre-install source file.
packages/cli/tests/unit/fixtures/java/maven/data/four-space-indent.expected.xml Adds a new expected output fixture verifying 4-space indentation is preserved for inserted content.
packages/cli/tests/unit/fixtures/java/maven/data/four-space-indent.actual.xml Adds a new input fixture for the 4-space indentation case.
packages/cli/tests/unit/fixtures/java/maven/data/existing.expected.xml Updates expected output formatting for an existing-plugin case.
packages/cli/tests/unit/fixtures/java/maven/data/existing-no-version.expected.xml Updates expected output to reflect version insertion and normalized layout.
packages/cli/tests/unit/fixtures/java/maven/data/empty-plugins.expected.xml Adds expected output fixture ensuring <plugins></plugins> is expanded and properly indented.
packages/cli/tests/unit/fixtures/java/maven/data/empty-plugins.actual.xml Adds input fixture containing a one-line empty <plugins></plugins> section.
Review details
  • Files reviewed: 15/16 changed files
  • Comments generated: 0
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Remove the heavy 'jsdom' and 'w3c-xmlserializer' dependencies from the
CLI package, replacing them with '@xmldom/xmldom' to streamline and
secure our runtime footprint.

Refactor mavenInstaller.ts to programmatically parse and build the DOM
with standard, namespace-agnostic DOM APIs. Auto-detect the file's
original indentation and trailing whitespace formatting to ensure the
result is nicely formatted and preserves the developer's original style.

Update the maven installer unit tests to assert exact, high-fidelity
indentation and layout. Add new test cases verifying correct handling of
empty plugins sections and four-space file indentation.

Note jsdom remains as a dependency of mermaid. @types/jsdom dev
dependency had to be added to navie (the build used to consume it
implicitly from the hoisted instance).

Assisted-by: Claude:claude-opus-5
Assisted-by: Gemini CLI:gemini-3.5-flash
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