Add @pretextbook/schema package with upstream change detection#163
Draft
Add @pretextbook/schema package with upstream change detection#163
Conversation
…ge detection Co-authored-by: oscarlevin <6504596+oscarlevin@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Add package to store PreTeXt schema as JSON or TypeScript
Add @pretextbook/schema package with upstream change detection
Mar 18, 2026
There was a problem hiding this comment.
Pull request overview
This PR introduces a new shared @pretextbook/schema package to centralize the generated PreTeXt dev schema data (from pretext-dev.rng), and updates @pretextbook/completions to consume it instead of maintaining a duplicated generated schema file. It also adds GitHub Actions workflows to detect upstream schema changes and to publish the schema package.
Changes:
- Added
packages/schemawith types, generated schema data, and an RNG→TS generation script. - Updated
packages/completionsto re-export the schema from@pretextbook/schemaand removed its schema-refresh/build wiring. - Added workflows for weekly upstream schema change detection and manual schema package publishing; updated root scripts/tsconfig references accordingly.
Reviewed changes
Copilot reviewed 14 out of 18 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description |
|---|---|
| tsconfig.json | Adds packages/schema to TS project references. |
| packages/schema/tsconfig.json | Introduces TS config for the schema package. |
| packages/schema/tsconfig.lib.json | Adds library build config for schema package. |
| packages/schema/src/types.ts | Defines exported schema-related TypeScript types. |
| packages/schema/src/index.ts | Re-exports public API from types and generated schema. |
| packages/schema/src/schema.ts | Adds generated pretextDevSchema data (large generated file). |
| packages/schema/scripts/generate-schema.mjs | Adds schema generation script from RNG to TS. |
| packages/schema/README.md | Documents the new package and update process. |
| packages/schema/project.json | Adds Nx targets for build/typecheck/refresh-schema. |
| packages/schema/package.json | Adds schema package metadata and scripts. |
| packages/completions/src/default-dev-schema.ts | Replaces huge generated schema with re-export from new package. |
| packages/completions/scripts/generate-default-schema.mjs | Deprecates old generator and delegates to schema generator. |
| packages/completions/project.json | Removes completions’ schema refresh target/dependency. |
| packages/completions/package.json | Drops schema scripts and adds dependency on @pretextbook/schema. |
| package.json | Updates refresh:schemas to run the new schema generator. |
| package-lock.json | Adds workspace link for @pretextbook/schema and updates dependency graph. |
| .github/workflows/publish-schema.yml | Adds manual publish workflow for schema package. |
| .github/workflows/check-pretext-schema.yml | Adds weekly/manual upstream change detection and issue filing. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
You can also share your feedback on Copilot code review. Take the survey.
| }; | ||
| // Re-exported from @pretextbook/schema for backwards compatibility. | ||
| // The canonical schema data lives in packages/schema/src/schema.ts. | ||
| export { pretextDevSchema as defaultDevSchema } from "@pretextbook/schema"; |
Comment on lines
+9
to
+15
| "build": { | ||
| "executor": "nx:run-commands", | ||
| "dependsOn": ["refresh-schema", "^build"], | ||
| "options": { | ||
| "cwd": "packages/schema", | ||
| "command": "tsc --build tsconfig.lib.json" | ||
| }, |
Comment on lines
+17
to
+28
| "main": "./src/index.ts", | ||
| "module": "./src/index.ts", | ||
| "types": "./src/index.ts", | ||
| "exports": { | ||
| ".": { | ||
| "types": "./src/index.ts", | ||
| "import": "./src/index.ts", | ||
| "default": "./src/index.ts" | ||
| } | ||
| }, | ||
| "files": [ | ||
| "src/**/*", |
Comment on lines
+46
to
+55
| ## Updating the Schema | ||
|
|
||
| The schema data in `src/schema.ts` is generated automatically from the official PreTeXt RelaxNG schema. To regenerate it: | ||
|
|
||
| ```bash | ||
| npm run fetch:dev-schema # Download latest pretext-dev.rng | ||
| npm run generate:schema # Regenerate src/schema.ts | ||
| ``` | ||
|
|
||
| A GitHub Actions workflow (`check-pretext-schema.yml`) runs weekly to detect upstream schema changes and file an issue when the schema should be updated. |
Comment on lines
+82
to
+87
| 1. Run \`npm run refresh:schemas\` from the workspace root to download the latest schema and regenerate \`packages/schema/src/schema.ts\`. | ||
| 2. Review the diff to understand what changed in the schema. | ||
| 3. Update any element descriptions or extra metadata in \`packages/schema/src/schema.ts\` as needed. | ||
| 4. Commit the updated \`extension/assets/schema/pretext-dev.rng\` and \`packages/schema/src/schema.ts\`. | ||
|
|
||
| This issue was created automatically by the [check-pretext-schema workflow](https://github.com/${{ github.repository }}/actions/workflows/check-pretext-schema.yml)." |
| }, | ||
| "scripts": {}, | ||
| "dependencies": { | ||
| "@pretextbook/schema": "*", |
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.
Multiple packages need PreTeXt schema data for completions, validation, etc. Previously each package maintained its own copy; this introduces a shared
@pretextbook/schemapackage as the canonical source.New
packages/schemapackagesrc/types.ts—PretextSchema,PretextSchemaElementChildren,PretextSchemaElement(with optionaldescriptionfor future metadata beyond the official schema)src/schema.ts— GeneratedpretextDevSchemafrompretext-dev.rng; includes all elements with allowed child elements and attributesscripts/generate-schema.mjs— RNG → TypeScript conversion (consolidated from the completions package)packages/completionsupdatedefault-dev-schema.tsreplaced with a single re-export from@pretextbook/schema— removes ~9,400 lines of duplication while keepingdefaultDevSchemaas a backwards-compatible alias@pretextbook/schema: "*"added as a workspace dependencyGitHub Actions
check-pretext-schema.yml— Weekly (+ manual) workflow; SHA-256-diffs the storedpretext-dev.rngagainst upstream and files aschema-update-labeled issue when a change is detectedpublish-schema.yml— Manual publish workflow for@pretextbook/schemato npm (mirrors the existing completions publish pattern)Root-level
refresh:schemasscript now invokespackages/schema/scripts/generate-schema.mjstsconfig.jsonaddspackages/schemato project referencesWarning
Firewall rules blocked me from connecting to one or more addresses (expand for details)
I tried to connect to the following addresses, but was blocked by firewall rules:
cloud.nx.app/home/REDACTED/work/_temp/ghcca-node/node/bin/node node ./bin/post-install(dns block)If you need me to access, download, or install something from one of these locations, you can either:
Original prompt
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.