LearnNewsExamplesConnect
Frontmatter
assigneesneo-opus-vega
createdAtNov 17, 2026, 4:17 AM
updatedAtNov 18, 2026, 12:46 AM
githubUrlhttps://github.com/neomjs/neo/issues/21211
authorneo-fable-mnemosyne
commentsCount1
parentIssue21213
subIssues[]
subIssuesCompleted0
subIssuesTotal0
contentTrust
projected
quarantined0
signals[]
blockedBy[]
blocking[]
closedAtNov 18, 2026, 12:46 AM

The highlight.js bundle builds from the installed package, not a clone

Closed v14.0.0/archive-v14-0-0-chunk-3 bugaiperformancebuildsecurity
neo-fable-mnemosyne
neo-fable-mnemosyne commented on Nov 17, 2026, 4:17 AM

No curated labels: this changes what runs on every user's machine and should be on dev before the Engine 14 cut on Mon Nov 23.

Context

Found while measuring the first run of npx neo-app (2026-11-17, neo-app@13.4.1, neo.mjs@13.4.0, empty npm cache, Apple M5 Max). The highlight.js step of build-all took 23.9 s of 64.4 s, the largest single phase; 6.8 s with a warm cache. One run per condition.

The Problem

buildScripts/build/highlightJs.mjs builds dist/highlight/highlight.custom.js and highlight.custom.min.js in three steps:

  1. git clone --depth 1 https://github.com/highlightjs/highlight.js.git, with no tag and no commit,
  2. npm install in the clone: 447 packages, upstream's development dependencies,
  3. node tools/build.js -n <languages>: upstream's build script, run from that clone.

So every workspace build, every first run of the generator and every CI job that builds the bundle executes whatever is on a third-party repository's default branch that day, along with its unlocked development tree. Three consequences, each observed:

  • Supply chain. Nothing pins what runs. The lockfile that pins the engine's other dependencies does not cover it.
  • The bundle depends on the build day. Upstream's head and the 11.12.0 release both report version 11.12.0, and they highlight a bash sample differently.
  • First impression. The step prints the clone's audit to the user: "20 vulnerabilities (1 low, 9 moderate, 9 high, 1 critical)". It also needs git and network access at build time.

The Architectural Reality

  • buildScripts/build/highlightJs.mjs: buildCloneArgs() returns ['clone', '--depth', '1', HIGHLIGHT_JS_REPOSITORY, targetDir]; npm install and tools/build.js then run with cwd: tempDir. The built build/highlight.js gets export default hljs; appended, and Terser writes the minified variant.
  • Consumer: src/util/HighlightJs.mjs imports dist/highlight/highlight.custom.js (its debug config defaults to true) or highlight.custom.min.js with a dynamic import() and reads module.default. Both variants are load-bearing.
  • The step skips when both files exist; -f, --force rebuilds (#7823).
  • test/playwright/unit/buildScripts/highlightJs.spec.mjs covers the clone's argument vector and shell rule, the non-zero exit of a failed build, and the check for an existing bundle in the consumer's working directory.
  • Why a clone: #7790 says "The stock npm package is CommonJS and not suitable for direct browser ESM import." highlight.js@11.12.0 exports ES modules under the import condition, and a bundler step removes the objection either way. #17492 scoped "any rework of the highlight.js build beyond the exec call" out; no ticket ruled it out.
  • Design authority: "Bundles the installed parse5 package for browser and build-time consumers." (buildScripts/build/parse5.mjs, @summary). The four sibling producers build from the installed, lockfile-pinned package; highlight.js is the exception.

The Fix

highlight.js becomes a devDependency, and the script bundles the installed package with esbuild, as parse5.mjs does:

  • entry: highlight.js/lib/core plus highlight.js/lib/languages/<name> for bash, css, javascript, json, markdown, plaintext, scss, xml, yaml and ruby (upstream's build adds ruby because yaml requires it, so today's bundle registers it), each registered, then export default hljs;
  • output: the same two files at the same paths, unminified and minified;
  • deleted: the clone, the nested install, buildCloneArgs, requiresShell, HIGHLIGHT_JS_REPOSITORY, the temp directory handling, and the spec's tests for them.

Run before filing, against the bundle the current step produced:

current step esbuild from highlight.js@11.12.0
time 23.9 s cold, 6.8 s warm 0.36 s
languages bash, css, javascript, json, markdown, plaintext, ruby, scss, xml, yaml the same ten
minified size 56,719 bytes (19,522 gzip) 69,545 bytes (20,487 gzip)
markup on eight samples identical for javascript, scss, css, json, yaml, markdown, xml and for highlightAuto; bash differs, because upstream's head is past the release

A generated workspace resolves highlight.js from its own node_modules, so the generator's devDependency list gains it when it moves to the engine release that carries this (create-app #61). Its parity check does not catch the omission: findDrift() compares only the keys the scaffold declares.

Acceptance Criteria

  • highlightJs.mjs starts no git and no npm process and needs no network: the bundle comes from the installed highlight.js, listed in devDependencies and the lockfile.
  • dist/highlight/highlight.custom.js and highlight.custom.min.js are ES modules whose default export registers exactly bash, css, javascript, json, markdown, plaintext, ruby, scss, xml and yaml.
  • The skip when both files exist and -f, --force are unchanged.
  • A unit spec builds the bundle into a temp directory and asserts the language list and one highlight() call per language. The clone's tests are gone; the exit-status and existing-bundle tests stay.
  • npm run build-highlightjs -- -f takes under 2 s (0.36 s in the probe); the pull request states the time and the machine.
  • A code-fenced guide in the portal shows highlighted code in dev mode; the pull request states how it was checked.
  • Post-merge, with the release: the generator's devDependencies carry highlight.js (create-app #61), witnessed by a fresh workspace's package.json and its highlight.js bundle build.

Out of Scope

  • Whether the first run builds the highlight bundle at all: Discussion #21210, Axis 1. This ticket holds under every row there.
  • The nested install in generated workspaces and the generator's unused engine dependency (captured as defect notes on 2026-11-17).
  • The highlight themes and the line-number plugin (#3782).

Avoided Traps

  • Pinning the clone to a tag. It still installs 447 packages and still runs upstream's build script; only the day-dependence goes.
  • Shipping the built bundle in the npm package. #19470: the package ships sources and build scripts, never generated output.
  • Matching the old byte size. 12.8 kB more minified is 1 kB more gzipped; not worth a second minifier pass.

Related

  • Related: #21210
  • #7790, #7794, #7823, #17492, #18704, #19470; neomjs/create-app #61

Live latest-open + closed sweep: checked latest 20 open + open and closed search ("highlight.js", "highlight bundle", "highlightJs clone"; Out of Scope / Avoided Traps of #17492 read, bodies of #7790, #7794, #7823 read) at 2026-11-17T03:15Z; no equivalent or prior exclusion found. Backlog band: 82 open, red; no open ticket or epic owns the build scripts' bundle producers, so this is filed. MC sweep: "highlight.js custom bundle clone npm install during build, code blocks unhighlighted, build-all slow highlight step", 6 results, no prior decision on clone against package. Own-assignment sweep: 3 open, none overlapping. A2A sweep: latest 30 messages, no claim on this scope.

unowned-rationale: specified for a maintainer seat to take before the Engine 14 cut. The fix above is my draft, so its pull request gets no formal review from me.

Origin Session ID: b3758981-efde-4777-921c-8c57fe3a804e Retrieval Hint: "highlight.js bundle unpinned clone first run npx neo-app"

tobiu referenced in commit b53c690 - "fix(build): the highlight.js bundle builds from the installed package, not a clone (#21211) (#21281) on Nov 18, 2026, 12:46 AM
tobiu closed this issue on Nov 18, 2026, 12:46 AM