feat(author): build the one-file tool in the package, not on the organisation's site
Closes #247.
Route 3 runs h5p-author.mjs, the command line as one file. Until now the organisation's site built that file with its own Vite when it built itself. So the site's build tools and their Dependabot updates were in the path of every byte a chat runs, and nothing published covered the file. With this PR, the author package builds the file and ships it, so the npm package covers it, and its provenance will once #246 is in. From the first release that ships it, the site's pin copies it instead of building it.
What changes
scripts/build-tool.mjsbuildsdist/h5p-author.mjsanddist/h5p-author-LICENSES.txt. Its Vite build is the site's, unchanged: a server-side build ofbin/h5p-author.mjs, everything bundled in, not minified, one file, with Vite's licence list. It then checks that the tool's--versionnames this package's version and its pack's.node scripts/build-tool.mjs <folder>writes the two files elsewhere.package.json:build:toolbuilds the player's plan, which the tool imports, then runs the script.prepackends with it.filesgainsdist.- Vite 8.3.8, the player's and the site's version, becomes a devDependency. The lockfile gains its three importer lines and nothing else.
exportsnames the two files,./dist/h5p-author.mjsand./dist/h5p-author-LICENSES.txt, so they resolve by the package's name.
- Node: packing on Node before 22.12 stops with a message before Vite fails to load. The package's
enginesstays>=22, since installing it runs none of this, and raising it would make an unversionednpxon Node 22.0 to 22.11 quietly install an older release. - Comments:
ownVersionandpackVersionno longer say the site builds the file. - Docs:
design/author.mdhas a new rule with its reason: when the site switches, why packing needs Node 22.12 whileenginesstays, and why the skill names no hash of the file.- The tool's size is now 756 kB, up from the 575 kB the design file gave.
- The author README and
design/layout.mdname the two files and the script.
Tested
-
The new test builds the tool into a temporary folder, unzips a Question Set bundle where no
package.jsonis above and nothing is installed, as a chat's sandbox has it, and checks two things:- The tool prints both versions from the copies bundled into it.
- It builds a quiz with
--libraries parts.
It also checks that the licence list names zip.js under BSD-3-Clause, and resolves both files by the package's name through
exports. -
Suites:
pnpm typecheckand the author's node suite (266 tests) pass. -
The packed package:
pnpm packranprepackthrough to the tool. The tarball holds the two files (94 entries, 383 kB packed), and its tool, extracted alone, prints@missing-elements/h5p-author 0.13.0, library pack 1.1.0. -
Sizes: the tool is 756 kB, 213 kB gzipped. The package grows from 0.60 MB unpacked to about 1.36 MB.
After the next release
The site's pin PR replaces its Vite build of the tool (bundles() in vite.config.ts) with a copy of the two files from node_modules/@missing-elements/h5p-author/dist/, and keeps its --version check. Until then it builds the tool as before, from 0.13.0, which does not ship it.
Summary by cubic
Closes #247. The author package now builds the one-file command-line tool and ships it in dist/, so the npm package covers the bytes route 3 runs and the organisation's site will serve the file as shipped instead of building it with its own Vite.
scripts/build-tool.mjsbundles the command line and everything it imports intodist/h5p-author.mjs, writesdist/h5p-author-LICENSES.txtbeside it, and checks that--versionnames this package's and its pack's versions;prepackruns it.- The two files are exported by their paths, and a test resolves them by the package's name.
- Packing on Node before 22.12 stops with a message before Vite fails to load;
enginesstays>=22since installing runs none of this. - The tool is 756 kB (213 kB gzipped); the packed package grows from 0.60 MB to about 1.36 MB unpacked.
- A new test builds the tool and runs it from an unzipped bundle with nothing installed, as a chat's sandbox has it.
Migration
After the next release, the site's pin PR replaces its Vite build of the tool with a copy of the two files from node_modules/@missing-elements/h5p-author/dist/ and keeps its --version check; until then it builds from 0.13.0, which does not ship them.