-
Notifications
You must be signed in to change notification settings - Fork 87
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
⬆️ Add simple upgrade/downgrade package for MyST AST (#1802)
Co-authored-by: Rowan Cockett <[email protected]>
- Loading branch information
Showing
28 changed files
with
719 additions
and
20 deletions.
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.