Skip to content

Commit d44da61

Browse files
authored
Ship highlight.js verbatim from @highlightjs/cdn-assets (#112)
AMO's review of 1.9.4 is blocked on reproducing the minification of lib/highlight.min.js. That is unwinnable as long as we ship a custom build: there is no official artifact to checksum against, so the reviewer has to reproduce a build, and reproducing ours was never possible anyway -- package.json pinned highlight.js to a bare GitHub URL with no ref, the workflow re-resolved it with `npm install --package-lock-only` before clean-install, `npm audit fix` ran immediately before the build, and package-lock.json was stripped from the release archive. Nothing in the submitted zip identified a fixed version. Consume the project's own published distribution instead, pinned exactly, and copy the files without modification. @highlightjs/cdn-assets is highlight.js' own npm package rather than a third-party CDN rehost, so package-lock.json records the tarball URL and its SHA-512 integrity hash: a reviewer verifies the shipped files with `npm ci` and `diff`, with no build to reproduce. The es/ modules give core plus only the xml, http and properties grammars -- about 24 KB, slightly smaller than the custom build. A first-party shim registers them and exposes hljs as a global so the page's classic scripts are unchanged; every hljs call site is event-driven, so the deferred module script is not a timing hazard. cdn-assets has no 11.11.1 successor yet, so this pins one patch behind the 11.11.2 the lock-file previously resolved to. A documentable downgrade is worth more than an unreproducible build. Refs #109
1 parent dc8b0a1 commit d44da61

7 files changed

Lines changed: 49 additions & 27 deletions

File tree

.gitattributes

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@ lib/.gitkeep export-ignore
22
node_modules/ export-ignore
33
test/ export-ignore
44
vendor/ export-ignore
5-
package-lock.json export-ignore
5+
# package-lock.json is deliberately kept in the release archive: it is the provenance record
6+
# for the third-party files in lib/, and AMO reviewers need it to verify them.

.github/workflows/build-release.yml

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -29,24 +29,23 @@ jobs:
2929
with:
3030
node-version: 24
3131

32-
- name: Install & build assets
33-
run: |
34-
# Make sure the lock-file is up to date before we run clean-install
35-
npm install --package-lock-only
36-
npm clean-install
37-
npm audit fix
38-
39-
- name: Build custom (minimum) release of highlight.js
40-
run: |
41-
cd node_modules/highlight.js
42-
npm install --package-lock-only
43-
npm clean-install
44-
npm run build
45-
node tools/build.js xml properties http
32+
- name: Install assets
33+
# Deliberately a plain clean-install: package-lock.json is authoritative, so the
34+
# published build is reproducible from the committed lock-file alone. Do not add
35+
# `npm install --package-lock-only` or `npm audit fix` here -- both mutate the
36+
# dependency tree at build time, which makes the shipped third-party files
37+
# impossible for AMO reviewers to verify.
38+
run: npm clean-install
4639

4740
- name: Copy third-party dependencies to lib/ directory
41+
# Copied verbatim from the @highlightjs/cdn-assets package, which is highlight.js'
42+
# own published distribution. The files are byte-identical to that release, so a
43+
# reviewer can verify them with `npm ci` and `diff` rather than reproducing a build.
4844
run: |
49-
cp node_modules/highlight.js/build/highlight.min.js lib/highlight.min.js
45+
cp node_modules/@highlightjs/cdn-assets/es/core.min.js lib/core.min.js
46+
cp node_modules/@highlightjs/cdn-assets/es/languages/xml.min.js lib/xml.min.js
47+
cp node_modules/@highlightjs/cdn-assets/es/languages/http.min.js lib/http.min.js
48+
cp node_modules/@highlightjs/cdn-assets/es/languages/properties.min.js lib/properties.min.js
5049
cp node_modules/pako/dist/pako_inflate.min.js lib/pako_inflate.min.js
5150
5251
- name: Clean release

attribution.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@ License type: BSD 3-clause "New" or "Revised" License
1515

1616
Project URL: https://github.com/highlightjs/highlight.js
1717

18+
Distribution: the files in `lib/` are copied verbatim, without modification, from the
19+
project's own published distribution package `@highlightjs/cdn-assets`, pinned to version
20+
11.11.1 in `package.json`. The exact tarball and its SHA-512 integrity hash are recorded in
21+
`package-lock.json`, so the shipped files can be verified with `npm ci` followed by `diff`.
22+
1823
Original license text:
1924

2025
```

package-lock.json

Lines changed: 10 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"test": "jest"
77
},
88
"dependencies": {
9-
"highlight.js": "github:highlightjs/highlight.js",
9+
"@highlightjs/cdn-assets": "11.11.1",
1010
"pako": "~2.2"
1111
},
1212
"devDependencies": {

src/TraceWindow.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
</div>
4040

4141
<script type="text/javascript" src="../lib/pako_inflate.min.js"></script>
42-
<script type="text/javascript" src="../lib/highlight.min.js"></script>
42+
<script type="module" src="hljs-init.js"></script>
4343
<script type="text/javascript" src="splitter.js"></script>
4444
<script type="text/javascript" src="hash.js"></script>
4545
<script type="text/javascript" src="SAMLTrace.js"></script>

src/hljs-init.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// Registers the highlight.js grammars SAML-tracer uses and exposes hljs as a global,
2+
// so the classic (non-module) scripts on this page can keep calling hljs.highlightElement().
3+
//
4+
// The imported files are unmodified artifacts from the @highlightjs/cdn-assets package,
5+
// copied verbatim during the release build -- see .github/workflows/build-release.yml.
6+
// Only this wrapper is first-party code.
7+
import hljs from '../lib/core.min.js';
8+
import xml from '../lib/xml.min.js';
9+
import http from '../lib/http.min.js';
10+
import properties from '../lib/properties.min.js';
11+
12+
hljs.registerLanguage('xml', xml);
13+
hljs.registerLanguage('http', http);
14+
hljs.registerLanguage('properties', properties);
15+
16+
window.hljs = hljs;

0 commit comments

Comments
 (0)