Repository navigation
feat(h5p-author): build in a page, from ./browser, with the core at ./core (#108) - #115
Merged
Merged
Conversation
…/core (#108) The package has three entries now: `.` for Node, `./core` for what needs neither Node nor a page, and `./browser`, the core and a page's `openPack` and `buildPackage`. One build runs in both: lib/build.mjs composes and writes what a package holds, lib/node.mjs is the only module that imports `node:` (the pack from disk, files beside the source, the output path, the normalizer), and lib/browser.mjs reads the pack a page can reach, takes `File`s by name and returns a `Blob`. - A part is read whole and hashed with crypto.subtle in Node too; the range reader went. - A page's pack is the `pack` export as emitted, or a parts folder's address, whose index is held to the player's shape by `packLibrariesIn`, which the player's ./plan now exports. - Media are stored with their size and CRC in their local headers, as embed's SCORM writer stores its entries. The CRC is the normalizer's, exported as ./crc32 (zlib's for Node, a table elsewhere); embed's copy went, and both publish guards check that ./crc32 is on npm. - Ids come from globalThis.crypto, so the generator runs in a page. Tests: the page's build in Node against Node's build, and in Chromium, its packages played untrusted by the verifier through a Vitest command. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… a partial replace The page build's first test compared two builds' 138 files with toEqual, byte by byte through Vitest's deep equality: 3.6 s here, 9.6 s on CI, past the 5 s default. It compares each file's SHA-256 now, in 0.24 s, and a difference still names the file. CodeQL's js/incomplete-sanitization on embed's publish guard: the package name's slash is replaced with replaceAll. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #108.
What it adds
The author package gets three entries:
.buildPackage,openPackandschemaOf, as before./coreloadLibraries,packageLibraries,checkContent, the text rules,SourceError./browseropenPackandbuildPackageThey are subpaths, not the
browsercondition. TypeScript ignores conditions unless a project setscustomConditions, so a page importing.would get the page's code typed by Node's declarations. The twobuildPackages also take different arguments.One build, two environments
lib/build.mjsnow holds what both builds do.composePackageis the oldbuildPackagebody, moved unchanged except that it is handed a media store.writePackagewrites the manifest, the libraries and the content into a zip.js writer.lib/node.mjsis the only module that importsnode:: the pack from disk, a source's files beside it, downloads in a temporary folder, the output path and the normalizer.lib/browser.mjsis the page's. A test holds the entries' imports to that.Three things follow:
crypto.subtle, in Node too. Node's reader by range went: the largest part is 2.8 MB, and the hash already read every byte. A page can't read by range anyway: SHA-256 needs every byte,crypto.subtle.digesttakes no stream, and jsDelivr cuts ranges from its compressed copy.packexport is taken as the page's bundler emitted it. An address of aparts/folder has itsindex.jsonheld to the player's shape bypackLibrariesIn, which the player's./plannow exports. That rule is http(s) only, as the player reads a copy, so a Tauri window on macOS (tauri://) gives the export instead.Files orBlobs, by the names the source gives them. They are stored with their size and CRC in their local headers, through zip.js's pass-through, as embed's SCORM writer has done since h5p-embed --scorm: SCORM Cloud cannot import the zip (data descriptors on stored entries) #92. Written into a stream, zip.js would put them in a data descriptor instead. An mp4 goes in as given: moving its index to the front stays the normalizer's, in Node.A page needs a secure context for
crypto.subtleandcrypto.randomUUID. The generator now takes ids fromglobalThis.crypto.openPackandbuildPackagerefuse outside a secure context with a message that says so. A failed download of a file named by address in a page gets a CORS hint, since most image hosts send noAccess-Control-Allow-Origin.Reused, not copied
./plan:packLibrariesIn, extended to export it../crc32: Node resolves it to zlib's, anything else to a table with no Node import (lib/crc32-table.mjs). Embed's SCORM writer imports it now, and its copy is gone../crc32is added to docs/compatibility.md, since embed and h5p-author take it through a^range.Where this differs from the issue
./coreexports what.exported before minus Node's build and pack. The issue also listedtranslateDefaults,quizSourceandquizProblems. They stay internal:loadLibrariesalready gives the translated defaults, andbuildPackagetakes the quiz format itself.authoring.test.tspassing, is in embed-my/creator. It can be done once this is released.Release
The order becomes player (
./planwithpackLibrariesIn), then normalizer (./crc32, a minor), then embed and h5p-author. Both publish guards check the normalizer's./crc32on npm. Embed's guard is renamedscripts/check-published.mjs, since it checks two packages now.Checked
tests/browser/page.test.ts): H5P.Blanks and a Question Set with a picture drawn on a canvas, built in the page (0.9 and 1.3 MB). The bytes go to Node through a Vitest command, whereverifyPackageplays each untrusted against the pack: a pass, no warnings, and nothing changed by the content check (contentCheck{ notes: [], changes: [] }).tests/page.test.ts, 9 tests):MediaStoredirectly.generator.mjschanged (ids fromglobalThis.crypto).The author package's
testscript now builds the player and runs the Chromium project too.test:unitruns the Node project alone. CI'stestjob and the weekly pack refresh already install Chromium before it.🤖 Generated with Claude Code