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

🪟 Fix plugin loading on Windows #1841

Merged
merged 4 commits into from
Feb 6, 2025
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
6 changes: 6 additions & 0 deletions .changeset/sixty-peas-do.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"myst-cli": patch
"mystmd": patch
---

Fix imports of plugins on Windows
4 changes: 3 additions & 1 deletion packages/myst-cli/src/plugins.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import fs from 'node:fs';
import { pathToFileURL } from 'node:url';
import type { ISession } from './session/types.js';
import { selectors } from './store/index.js';
import { RuleId, plural, type MystPlugin, type ValidatedMystPlugin } from 'myst-common';
Expand Down Expand Up @@ -97,8 +98,9 @@ export async function loadPlugins(session: ISession): Promise<ValidatedMystPlugi
return null;
}
let module: any;
const pathURL = pathToFileURL(path);
try {
module = await import(path);
module = await import(pathURL.toString());
} catch (error) {
session.log.debug(`\n\n${(error as Error)?.stack}\n\n`);
addWarningForFile(session, path, `Error reading plugin: ${error}`, 'error', {
Expand Down
7 changes: 7 additions & 0 deletions packages/mystmd/tests/basic-plugin/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
title: Basic Test
---

# Lorem Ipsum

Set {red}`this text` to a class of red.
24 changes: 24 additions & 0 deletions packages/mystmd/tests/basic-plugin/myst.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# See docs at: https://mystmd.org/guide/frontmatter
version: 1
project:
id: 22c218e1-66c6-428f-9df9-a7f2c6a3bd76
# title:
# description:
keywords: []
authors: []
github: https://github.com/jupyter-book/mystmd
# bibliography: []
#
plugins:
- plugin.mjs
site:
template: ../templates/site/myst/book-theme
# title:
# options:
# favicon: favicon.ico
# logo: site_logo.png
nav: []
actions:
- title: Learn More
url: https://mystmd.org/guide
domains: []
19 changes: 19 additions & 0 deletions packages/mystmd/tests/basic-plugin/plugin.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
const redRole = {
name: 'red',
doc: 'An example role that sets a custom class.',
body: {
type: 'myst',
required: true,
},
run(data) {
const children = data.body;
children.forEach((child) => {
child.class = child.class ? `${child.class} red` : 'red';
});
return children;
},
};

const plugin = { name: 'Example role', roles: [redRole] };

export default plugin;
7 changes: 7 additions & 0 deletions packages/mystmd/tests/exports.yml
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,13 @@ cases:
content: outputs/basic-site-config.json
- path: basic-site/_build/site/myst.xref.json
content: outputs/basic-site-myst.xref.json
- title: Basic plugin build
cwd: basic-plugin
command: myst build
outputs:
- path: basic-plugin/_build/site/content/index.json
# Keys and file hashes are removed from this output file
content: outputs/basic-plugin-content.json
- title: XRef site build
cwd: site-xrefs
command: myst build
Expand Down
127 changes: 127 additions & 0 deletions packages/mystmd/tests/outputs/basic-plugin-content.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
{
"kind": "Article",
"sha256": "900eec73ecdfd1641367698dab8e7727ce2a81122ba0cd641c61c4f0f3b30694",
"slug": "index",
"location": "/index.md",
"dependencies": [],
"frontmatter": {
"title": "Basic Test",
"github": "https://github.com/jupyter-book/mystmd",
"keywords": [],
"exports": [
{
"format": "md",
"filename": "index.md",
"url": "/index-827a0078d531c946c69925141436e783.md"
}
]
},
"mdast": {
"type": "root",
"children": [
{
"type": "block",
"children": [
{
"type": "heading",
"depth": 2,
"position": {
"start": {
"line": 5,
"column": 1
},
"end": {
"line": 5,
"column": 1
}
},
"children": [
{
"type": "text",
"value": "Lorem Ipsum",
"position": {
"start": {
"line": 5,
"column": 1
},
"end": {
"line": 5,
"column": 1
}
}
}
],
"identifier": "lorem-ipsum",
"label": "Lorem Ipsum",
"html_id": "lorem-ipsum",
"implicit": true
},
{
"type": "paragraph",
"position": {
"start": {
"line": 7,
"column": 1
},
"end": {
"line": 7,
"column": 1
}
},
"children": [
{
"type": "text",
"value": "Set ",
"position": {
"start": {
"line": 7,
"column": 1
},
"end": {
"line": 7,
"column": 1
}
}
},
{
"type": "text",
"value": "this text",
"position": {
"start": {
"line": 7,
"column": 1
},
"end": {
"line": 7,
"column": 1
}
},
"class": "red"
},
{
"type": "text",
"value": " to a class of red.",
"position": {
"start": {
"line": 7,
"column": 1
},
"end": {
"line": 7,
"column": 1
}
}
}
]
}
]
}
]
},
"references": {
"cite": {
"order": [],
"data": {}
}
}
}
Loading