Skip to content

build!: Modernise build to ANTLR 4.13.2 / antlr4 runtime; bump to 2.0.0-SNAPSHOT#8

Merged
nawforce merged 5 commits into
mainfrom
6-modernise-npm-build
Apr 26, 2026
Merged

build!: Modernise build to ANTLR 4.13.2 / antlr4 runtime; bump to 2.0.0-SNAPSHOT#8
nawforce merged 5 commits into
mainfrom
6-modernise-npm-build

Conversation

@kjonescertinia

@kjonescertinia kjonescertinia commented Apr 25, 2026

Copy link
Copy Markdown
Contributor

Combines the JVM and npm modernisation into a single PR — they're tightly coupled (the grammar split has no value without the npm overlay that consumes it), so splitting hurt more than it helped.

Tracked in #6.

Summary

  • JVM: ANTLR 4.13.2 runtime + exec-maven-plugin generation, all Maven plugins current, JUnit 5.14.3, <release>8</release>, switched from legacy nexus-staging-maven-plugin (OSSRH s01) to central-publishing-maven-plugin (Sonatype Central Portal). CI JDK 8 → 11; PublishMaven.yml server-id: ossrhcentral.
  • Grammars: split into language-neutral /antlr/BaseVF{Lexer,Parser}.g4 + per-target overlays under jvm/antlr/ and npm/antlr/. Java clearCache() helper now lives only in the JVM overlay (apex-ls's API surface preserved); TypeScript output is no longer polluted with embedded Java.
  • npm: antlr4ts 0.5.0-alpha.4 → bundled antlr4 4.13.2. Generation driven by the same Java tool the JVM uses, via npm/pom.xml. ESM-only (type: module, exports map, dist/src layout), Node 20+, ESLint v10 flat config, patch-package + patches/antlr4+4.13.2.patch (lifted from apex-parser) replaces the bespoke shelljs sed.
  • Version: both halves bump to 2.0.0-SNAPSHOT to reflect the breaking surface (ESM, new ThrowingErrorListener API, Node engines, exports).

Breaking changes (npm consumers)

  • ThrowingErrorListener extends ErrorListener<Token | number> from antlr4 (was implements ANTLRErrorListener<Token> from antlr4ts).
  • SyntaxException is now an Error subclass.
  • ESM-only with an exports map; Node engines ^20.19 || ^22.13 || >=24.
  • VFLexer / VFParser exported as default classes via subpath ./antlr/*.
  • node-dir dependency removed; check() uses node:fs/promises.

Commits

  1. Modernise JVM build — pom + Maven plugin overhaul, Sonatype Central, CI JDK bump.
  2. Split grammars for per-target action injectionBase*.g4 + per-target overlays.
  3. Modernise npm side — antlr4 runtime, ESM, ESLint flat, version bump.

Test plan

  • rm -rf npm/{node_modules,dist,src/antlr} jvm/target && npm run init && npm run build — green
  • npm test --prefix npm — 2/2 passing
  • JVM tests — 2/2 passing; clearCache() present on generated VFLexer.java/VFParser.java
  • npm run lint --prefix npm — clean
  • CI Build workflow green
  • (Manual) apex-ls builds against a local 2.0.0-SNAPSHOT package — out of scope

Notes for the next release

  • MAVEN_USERNAME / MAVEN_TOKEN GitHub secrets need to be a Sonatype Central Portal user token (not the legacy OSSRH one) when the next release fires.
  • npm's 2.0.0-SNAPSHOT is Maven-style; npm itself prefers 2.0.0-beta.1. Worth aligning before any actual npm publish.

Closes #7 (superseded). Refs #6.

Replace antlr4-maven-plugin with exec-maven-plugin + build-helper-maven-plugin
running ANTLR 4.13.2 directly, so the JVM and (eventually) npm sides share a
single generator. ANTLR runtime bumped 4.9.1 -> 4.13.2 to match apex-parser
and unblock downstream apex-ls.

Maven plugins, JUnit, and Java toolchain all brought current; publishing
switched from the legacy nexus-staging-maven-plugin (OSSRH s01) to
central-publishing-maven-plugin (Sonatype Central Portal). CI Java bumped
8 -> 11 since <release>8</release> requires JDK 9+ to compile.

Refs #6
ANTLR copies @lexer::members and @parser::members blocks verbatim into
generated sources, so the existing Java clearCache() helper breaks the
TypeScript target. Split each grammar into a language-neutral base file
and a per-target overlay (mirroring apex-parser):

- /antlr/BaseVF{Lexer,Parser}.g4: shared rules, no embedded actions
- /jvm/antlr/VF{Lexer,Parser}.g4: thin overlays adding the Java helper
  via @members and importing the base

The npm side will add its own (action-free) overlays in a follow-up.
clearCache() still appears on both VFLexer and VFParser on the JVM side,
preserving the apex-ls API surface.

Refs #6
Replaces the abandoned antlr4ts 0.5.0-alpha.4 fork with the official
antlr4 4.13.2 runtime (bundled). Generation is now driven by the same
Java ANTLR tool used by the JVM side, via a new npm/pom.xml that runs
exec-maven-plugin with -Dlanguage=TypeScript against the npm/antlr
overlay (which imports the shared BaseVF*.g4 files).

This is a breaking change for consumers — hence the major bump on both
artifacts:

- ThrowingErrorListener now extends antlr4's ErrorListener<Token | number>
  (was: implements ANTLRErrorListener<Token>); SyntaxException is now
  an Error subclass.
- Package is ESM-only ("type": "module"), with an exports map and
  dist/src layout. Node engines bumped to ^20.19 / ^22.13 / >=24.
- Lexer/Parser are exported as default classes via subpath /antlr/*.
- node-dir dropped; check() now uses node:fs/promises recursive readdir.

Tooling bumps:
- patch-package + patches/antlr4+4.13.2.patch (lifted from apex-parser)
  replaces the bespoke shelljs sed in npm/patch.
- ESLint v10 flat config (typescript-eslint v8) replaces the legacy
  .eslintrc.js.
- tsconfig: es2022 / node20 / strict.
- jest regex points at dist/test/, and npm/.npmrc enables the
  experimental-vm-modules flag so jest can load the ESM build.

Root package.json scripts switched to apex-parser's
init / build / build:jvm / build:npm layout; init:npm now runs
mvn exec:exec rather than copying .g4 files into per-target dirs.

Refs #6
@kjonescertinia kjonescertinia changed the title build!: Modernise npm side and bump to 2.0.0-SNAPSHOT build!: Modernise build to ANTLR 4.13.2 / antlr4 runtime; bump to 2.0.0-SNAPSHOT Apr 25, 2026
@kjonescertinia kjonescertinia changed the base branch from 6-modernise-jvm-build to main April 25, 2026 21:33
The new npm/package.json declares node engines ^20.19 || ^22.13 || >=24,
which Node 14 can't satisfy. Build.yml also needs to populate
node_modules before the build step now that the npm side is rewritten
around npm ci + patch-package.

PublishMaven.yml and PublishNPM.yml were still calling the old
init-jvm / build-npm script names; renamed to init:jvm / build:npm.
@nawforce

Copy link
Copy Markdown
Contributor

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: c769ef29af

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread npm/package.json Outdated
"antlr": "mvn exec:exec",
"build": "npm run clean && npm run antlr && tsc",
"build:test": "npm run build && npm test",
"check": "node -e 'require(\"./dist/src/index.js\").check()'",

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Replace CommonJS require in ESM check script

The package is now explicitly ESM ("type": "module"), but the check script still invokes require("./dist/src/index.js"). On Node 20+ this throws ERR_REQUIRE_ESM, so npm run check fails before parsing any files. This regression affects anyone using the maintained smoke-check command after building the package.

Useful? React with 👍 / 👎.

The npm package is "type": "module", so the existing CommonJS require()
in the check script throws ERR_REQUIRE_ESM on Node 20+. Switch to
import() — works in both CJS and ESM contexts without --input-type.

Caught by Codex review on #8.
@nawforce nawforce merged commit c4ce05f into main Apr 26, 2026
1 check passed
@nawforce nawforce deleted the 6-modernise-npm-build branch April 26, 2026 08:15
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