Skip to content

fix(author): the command line as one file prints its versions - #199

Merged
alekswebnet merged 1 commit into
mainfrom
fix/author-one-file-version
Nov 13, 2026
Merged

alekswebnet merged 1 commit into
mainfrom
fix/author-one-file-version

Conversation

@alekswebnet

@alekswebnet alekswebnet commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

Closes #198.

What changes

  • bin/h5p-author.mjs: --version takes this package's version from ownVersion(). It reads ../package.json as before, but only if that file names this package. Otherwise it uses import('../package.json', { with: { type: 'json' } }).
  • lib/node.mjs: packVersion() reads the libraries package's package.json as before, and falls back to the same kind of import.

Where the package is installed from npm, the files are read and nothing changes. The site's Vite bundles the command line into one file, and there it writes both imports into the file, so the single file carries its versions.

The file is read first because Node before 22.12 warns on every JSON import: "ExperimentalWarning: Importing JSON modules is an experimental feature", checked on Node 22.11. A model reading the output could take that warning as a fault.

  • design/author.md: the bundle rule records the crash and the fix.

Checked

  • npm package: test:unit passes, 183 tests, including the existing -v test, and typecheck passes. --version and a build print the same as before on Node 22.11.0 and 23.11.1, with no warning on 22.11.
  • The site's single file: I packed this branch, installed it into a scratch copy of the site at main (pin 0.9.7), and ran pnpm build. The resulting h5p-author.mjs:
    • prints @missing-elements/h5p-author 0.9.7, library pack 1.1.0 alone in an empty folder, on Node 22.11 and 23.11, where the live file crashes;
    • prints the same from a folder whose parent has another package's package.json;
    • still builds a Question Set from the site's H5P.QuestionSet.zip with --libraries parts, and the package plays in the verifier.
  • Size: the file grows from 612,494 to 621,229 bytes, because both package.json objects are written into it.

Not covered by a test here: only a bundler produces the single file, and this package has none. After the release, the site's pin bump can check it at build time: run the bundled tool's --version and compare it with /h5p/bundles/index.json. The comment in the site's vite.config.ts that says the tool cannot read its versions changes then too.


Summary by cubic

Fixes --version crashing when the command line is bundled into a single file, as the site serves it.

  • The single file previously read this package's package.json and the pack's from disk, neither of which sits beside it.
  • Each version is now also imported as JSON, which the bundler writes into the file; the disk reads remain first where the packages are installed, so Node before 22.12 does not warn on JSON imports.

Written for commit dc5bc35. Summary will update on new commits.

View guided diff Turn on auto-fix

The site serves the command line bundled into one file, h5p-author.mjs, and
its --version crashed: it read this package's package.json and the pack's as
files, and neither is beside the one file. Each version is now also a JSON
import, which the bundler writes into the file. The files are still read
first where the packages are installed, since Node before 22.12 warns on a
JSON import, and a package.json above the one file that is not this
package's is passed over.

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

No issues found across 3 files

Tip: cubic could auto-approve low-risk PRs like this, if it thinks it's safe to merge. Learn more

View guided diff | Turn on auto-fix | Re-trigger cubic

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.

The single-file build tool crashes on --version

1 participant