fix(author): the command line as one file prints its versions
Closes #198.
What changes
bin/h5p-author.mjs:--versiontakes this package's version fromownVersion(). It reads../package.jsonas before, but only if that file names this package. Otherwise it usesimport('../package.json', { with: { type: 'json' } }).lib/node.mjs:packVersion()reads the libraries package'spackage.jsonas 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:unitpasses, 183 tests, including the existing-vtest, andtypecheckpasses.--versionand 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 ranpnpm build. The resultingh5p-author.mjs:- prints
@missing-elements/h5p-author 0.9.7, library pack 1.1.0alone 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.zipwith--libraries parts, and the package plays in the verifier.
- prints
- Size: the file grows from 612,494 to 621,229 bytes, because both
package.jsonobjects 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.jsonand 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.