Skip to content

Commit 235245a

Browse files
stevejpurvesrowanc1
authored andcommitted
🚛 migrate xrefs
1 parent d45faf3 commit 235245a

File tree

3 files changed

+39
-1
lines changed

3 files changed

+39
-1
lines changed

.changeset/whole-taxis-follow.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'myst-cli': patch
3+
---
4+
5+
Applies the `myst-migrate` functions to embedded xref content

packages/myst-cli/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@
7171
"myst-cli-utils": "^2.0.12",
7272
"myst-common": "^1.9.2",
7373
"myst-config": "^1.9.2",
74+
"myst-migrate": "^1.7.0",
7475
"myst-execute": "^0.3.2",
7576
"myst-ext-button": "^0.0.1",
7677
"myst-ext-card": "^1.0.9",

packages/myst-cli/src/transforms/crossReferences.ts

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ import type { CrossReference, Dependency, Link, SourceFileKind } from 'myst-spec
99
import type { ISession } from '../session/types.js';
1010
import { loadFromCache, writeToCache } from '../session/cache.js';
1111
import type { SiteAction, SiteExport } from 'myst-config';
12+
import { migrate } from 'myst-migrate';
13+
import { SPEC_VERSION } from '../spec-version.js';
1214

1315
export const XREF_MAX_AGE = 1; // in days
1416

@@ -58,6 +60,7 @@ async function fetchMystData(
5860
if (cacheData) {
5961
return JSON.parse(cacheData) as MystData;
6062
}
63+
6164
let data: MystData;
6265
try {
6366
const resp = await session.fetch(dataUrl);
@@ -67,7 +70,36 @@ async function fetchMystData(
6770
data = (await resp.json()) as MystData;
6871
} catch {
6972
return onError('Could not load fetched data');
70-
// data is unset
73+
}
74+
75+
// Migrate external content if version differs from current
76+
if (data.mdast && data.version !== undefined && data.version !== SPEC_VERSION) {
77+
session.log.info(
78+
`Migrating external content from v${data.version} to v${SPEC_VERSION} for ${urlSource}`,
79+
);
80+
try {
81+
const migrateFile = {
82+
version: data.version,
83+
mdast: data.mdast,
84+
};
85+
86+
const migrated = await migrate(migrateFile, {
87+
to: SPEC_VERSION,
88+
log: session.log,
89+
});
90+
91+
data.mdast = migrated.mdast;
92+
data.version = migrated.version;
93+
94+
session.log.debug(
95+
`Migrated external content from v${migrateFile.version} to v${SPEC_VERSION} for ${urlSource}`,
96+
);
97+
} catch (error) {
98+
session.log.warn(
99+
`Failed to migrate external content from v${data.version} to v${SPEC_VERSION}: ${error}`,
100+
);
101+
// Continue with original content if migration fails
102+
}
71103
}
72104

73105
writeToCache(session, filename, JSON.stringify(data));

0 commit comments

Comments
 (0)