-
Notifications
You must be signed in to change notification settings - Fork 75
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
⬆️ Add simple upgrade/downgrade package for MyST AST #1802
Merged
Merged
Changes from all commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
a79745a
wip: initial myst-compat package
agoose77 520eff3
wip: ast up and downgrading
agoose77 4942a0a
test: add simple test
agoose77 be7268e
chore: run linter
agoose77 83b1a91
fix: get tests working
agoose77 c974aea
fix: try to copy children where there is only one "output" object
agoose77 6cdcf9f
fix: allow missing children
agoose77 04cbe19
fix: improve types, support placeholders
agoose77 f6568bf
fix: add label and identifier information to outputs
agoose77 5f91e42
wip: footnotes
agoose77 115770a
chore: add changeset
agoose77 d948b1f
fix: update tests
agoose77 7772fec
test: test upgrade
agoose77 a226703
chore: remove utils
agoose77 10c1bd4
feat: add export for spec version
agoose77 f56357b
wip: prepare to upgrade documents
agoose77 b0526d7
fix: update tests
agoose77 6beb975
fix: plumb-in SPEC_VERSION to file writing
agoose77 930f47d
fix: add missing file
agoose77 4172275
chore: run linter
agoose77 02fb6f8
chore: run linter
agoose77 d90645d
📦
rowanc1 fcfdf97
change to myst-migrate
rowanc1 4ae0e1d
update package name
rowanc1 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
--- | ||
"myst-transforms": patch | ||
"myst-spec-ext": patch | ||
"myst-to-docx": patch | ||
"myst-config": patch | ||
"myst-cli": patch | ||
--- | ||
|
||
Change footnotes to use enumerator over number |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"myst-config": patch | ||
--- | ||
|
||
Add version to config file |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"myst-cli": patch | ||
--- | ||
|
||
Add version to site content outputs |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'myst-migrate': patch | ||
--- | ||
|
||
Add myst-migrate package |
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
--- | ||
title: MyST Content Versions | ||
--- | ||
|
||
The following page describes changes to the MyST content that is served from the `.json` endpoint of a MyST Site. The `myst-compat` package can be used to translate between versions by upgrading and downgrading between versions. | ||
|
||
The version is a string integer (i.e. `'1'` or `'2'`) and is incremented with every change to the content of a MyST page, which includes metadata as well as the MyST AST. | ||
|
||
# MyST Versions | ||
|
||
## Version 1 - 2025-02-07 - Footnote Numbering | ||
|
||
The footnotes have dropped backwards compatibility with `number`, instead using `enumerator` on both the `FootnoteReference` and `FootnoteDefinition` nodes. | ||
Previous versions of the AST had both of these defined. The `enumerator` property is used in all other numberings of figures, sections, equations, etc. | ||
|
||
## Version 0 - Pre 2025-02-01 | ||
|
||
This is the first version of MyST AST considered to be versioned, subsequent releases will have changes for migrating the content between versions. |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export const SPEC_VERSION = 1; |
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
module.exports = { | ||
root: true, | ||
extends: ['curvenote'], | ||
}; |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# myst-migrate | ||
|
||
Utilities for upgrading and downgrading MyST ASTs |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
{ | ||
"name": "myst-migrate", | ||
"sideEffects": false, | ||
"version": "0.0.0", | ||
"type": "module", | ||
"exports": "./dist/index.js", | ||
"types": "./dist/index.d.ts", | ||
"files": [ | ||
"dist" | ||
], | ||
"license": "MIT", | ||
"scripts": { | ||
"clean": "rimraf dist", | ||
"lint": "eslint \"src/**/!(*.spec).ts\" -c ./.eslintrc.cjs", | ||
"lint:format": "prettier --check \"src/**/*.{ts,tsx,md}\"", | ||
"test": "vitest run", | ||
"test:watch": "vitest watch", | ||
"build:esm": "tsc", | ||
"build": "npm-run-all -l clean -p build:esm" | ||
}, | ||
"dependencies": { | ||
"unist-util-select": "^4.0.3", | ||
"unist-util-visit": "^4.1.2", | ||
"vfile": "^5.0.0", | ||
"vfile-message": "^3.0.0" | ||
}, | ||
"devDependencies": { | ||
"@jupyterlab/nbformat": "^3.5.2" | ||
} | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import type { IFile, Options } from './types.js'; | ||
import { MIGRATIONS } from './migrations.js'; | ||
|
||
export { MIGRATIONS } from './migrations.js'; | ||
|
||
/** | ||
* Migrate function: | ||
* @param src - The page to be migrated | ||
* @param options - to: desired target version, log: Logger | ||
*/ | ||
export async function migrate(src: IFile, opts?: Options): Promise<IFile> { | ||
const to = opts?.to ?? MIGRATIONS.length; | ||
let currentVersion = src.version || 0; | ||
|
||
// If the current version is already at the target, do nothing | ||
if (currentVersion === to) { | ||
opts?.log?.debug(`Already at version ${to}. No migration needed.`); | ||
return src; | ||
} | ||
|
||
// If currentVersion < toVersion, apply upgrades forward | ||
while (currentVersion < to) { | ||
if (currentVersion >= MIGRATIONS.length) { | ||
throw new Error( | ||
`No migration available to go from version ${currentVersion} to ${currentVersion + 1}`, | ||
); | ||
} | ||
const migration = MIGRATIONS[currentVersion]; | ||
opts?.log?.debug(`Upgrading from v${currentVersion} to v${currentVersion + 1}...`); | ||
await migration.upgrade(src); | ||
currentVersion++; | ||
src.version = currentVersion; | ||
} | ||
|
||
// If currentVersion > toVersion, apply downgrades backward | ||
while (currentVersion > to) { | ||
if (currentVersion - 1 >= MIGRATIONS.length) { | ||
throw new Error( | ||
`No migration available to go from version ${currentVersion} down to ${currentVersion - 1}`, | ||
); | ||
} | ||
const migration = MIGRATIONS[currentVersion - 1]; | ||
opts?.log?.debug(`Downgrading from v${currentVersion} to v${currentVersion - 1}...`); | ||
await migration.downgrade(src); | ||
currentVersion--; | ||
src.version = currentVersion; | ||
} | ||
|
||
return src; | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import type { Migration } from './types.js'; | ||
import * as v1 from './v1_footnotes.js'; | ||
|
||
export const MIGRATIONS: Migration[] = [v1]; | ||
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This types each module for an upgrade/downgrade/description, and we then just put it in an array.