Skip to content

Commit

Permalink
馃攢 Move MystPlugin to common types
Browse files Browse the repository at this point in the history
  • Loading branch information
rowanc1 committed Sep 26, 2023
1 parent 60cf9a5 commit 86c7895
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 18 deletions.
6 changes: 6 additions & 0 deletions .changeset/odd-pots-peel.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'myst-common': patch
'myst-cli': patch
---

Add MySTPlugin to common exported types
11 changes: 3 additions & 8 deletions packages/myst-cli/src/plugins.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,12 @@
import fs from 'node:fs';
import type { ISession } from './session/types.js';
import { selectCurrentProjectConfig } from './store/selectors.js';
import type { DirectiveSpec, RoleSpec } from 'myst-common';
import type { MystPlugin } from 'myst-common';

type MystPlugins = {
directives: DirectiveSpec[];
roles: RoleSpec[];
};

export async function loadPlugins(session: ISession): Promise<MystPlugins> {
export async function loadPlugins(session: ISession): Promise<MystPlugin> {
const config = selectCurrentProjectConfig(session.store.getState());

const plugins: MystPlugins = {
const plugins: MystPlugin = {
directives: [],
roles: [],
};
Expand Down
5 changes: 3 additions & 2 deletions packages/myst-cli/src/session/session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { chalkLogger, LogLevel } from 'myst-cli-utils';
import type { Logger } from 'myst-cli-utils';
import { config, rootReducer, selectors } from '../store/index.js';
import type { RootState } from '../store/index.js';
import type { ISession, MystPlugins } from './types.js';
import type { ISession } from './types.js';
import {
findCurrentProjectAndLoad,
findCurrentSiteAndLoad,
Expand All @@ -16,6 +16,7 @@ import boxen from 'boxen';
import chalk from 'chalk';
import version from '../version.js';
import { loadPlugins } from '../plugins.js';
import type { MystPlugin } from 'myst-common';

const CONFIG_FILES = ['myst.yml'];
const API_URL = 'https://api.mystmd.org';
Expand Down Expand Up @@ -101,7 +102,7 @@ export class Session implements ISession {
return this;
}

plugins: MystPlugins | undefined;
plugins: MystPlugin | undefined;

async loadPlugins() {
this.plugins = await loadPlugins(this);
Expand Down
11 changes: 3 additions & 8 deletions packages/myst-cli/src/session/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,7 @@ import type { Store } from 'redux';

import type { RootState } from '../store/index.js';
import type { PreRendererData, RendererData, SingleCitationRenderer } from '../transforms/types.js';
import type { DirectiveSpec, RoleSpec } from 'myst-common';

export type MystPlugins = {
directives: DirectiveSpec[];
roles: RoleSpec[];
};
import type { MystPlugin } from 'myst-common';

export type ISession = {
API_URL: string;
Expand All @@ -26,8 +21,8 @@ export type ISession = {
contentPath(): string;
publicPath(): string;
showUpgradeNotice(): void;
plugins: MystPlugins | undefined;
loadPlugins(): Promise<MystPlugins>;
plugins: MystPlugin | undefined;
loadPlugins(): Promise<MystPlugin>;
};

export type ISessionWithCache = ISession & {
Expand Down
1 change: 1 addition & 0 deletions packages/myst-common/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,5 @@ export type {
DirectiveSpec,
RoleSpec,
ParseTypes,
MystPlugin,
} from './types.js';
8 changes: 8 additions & 0 deletions packages/myst-common/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,14 @@ export type RoleSpec = {
run: (data: RoleData, vfile: VFile) => GenericNode[];
};

/**
* Create MyST plugins that export this from a file,
* or combine multiple plugins to a single object. */
export type MystPlugin = {
directives: DirectiveSpec[];
roles: RoleSpec[];
};

export enum TargetKind {
heading = 'heading',
equation = 'equation',
Expand Down

0 comments on commit 86c7895

Please sign in to comment.