Skip to content
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

🐛 Pass projectPath to loadFile whenever possible #805

Merged
merged 1 commit into from
Dec 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/forty-donkeys-care.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'myst-cli': patch
---

Pass projectPath to loadFile whenever possible
2 changes: 1 addition & 1 deletion packages/myst-cli/src/build/meca/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ async function copyDependentFiles(
) {
const cache = castSession(session);
if (!cache.$getMdast(sourceFile)) {
await loadFile(session, sourceFile);
await loadFile(session, sourceFile, projectPath);
}
const pre = cache.$getMdast(sourceFile)?.pre;
if (!pre) return;
Expand Down
2 changes: 1 addition & 1 deletion packages/myst-cli/src/build/utils/collectExportOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ async function prepareExportOptions(
if (projectPath && sourceFile === selectors.selectLocalConfigFile(state, projectPath)) {
rawFrontmatter = selectors.selectLocalProjectConfig(state, projectPath);
} else {
rawFrontmatter = await getRawFrontmatterFromFile(session, sourceFile);
rawFrontmatter = await getRawFrontmatterFromFile(session, sourceFile, projectPath);
}
let exportOptions = getExportListFromRawFrontmatter(session, formats, rawFrontmatter, sourceFile);
// If no export options are provided in frontmatter, instantiate default options
Expand Down
8 changes: 6 additions & 2 deletions packages/myst-cli/src/frontmatter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,13 @@ export function prepareToWrite(frontmatter: { license?: Licenses }) {
return { ...frontmatter, license: licensesToString(frontmatter.license) };
}

export async function getRawFrontmatterFromFile(session: ISession, file: string) {
export async function getRawFrontmatterFromFile(
session: ISession,
file: string,
projectPath?: string,
) {
const cache = castSession(session);
if (!cache.$getMdast(file)) await loadFile(session, file);
if (!cache.$getMdast(file)) await loadFile(session, file, projectPath);
const result = cache.$getMdast(file);
if (!result || !result.pre) return undefined;
const vfile = new VFile();
Expand Down
Loading