Skip to content

Commit

Permalink
🆙 Update mystjs and add more definitive return type (#57)
Browse files Browse the repository at this point in the history
  • Loading branch information
Yxwww authored Apr 19, 2022
1 parent bd9c3ff commit dd11eba
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 9 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
"katex": "^0.15.2",
"lodash.throttle": "^4.1.1",
"mime-types": "^2.1.35",
"mystjs": "^0.0.5",
"mystjs": "^0.0.6",
"nanoid": "^3.3.2",
"node-fetch": "^2.6.7",
"p-limit": "^3.1.0",
Expand Down
4 changes: 2 additions & 2 deletions src/web/transforms/keys.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { createId } from '@curvenote/schema';
import { GenericNode, map } from 'mystjs';
import { Root } from './types';
import { MapResult, Root } from './types';

function addKeys(node: GenericNode) {
node.key = createId();
Expand All @@ -13,6 +13,6 @@ function addKeys(node: GenericNode) {
* @param mdast
* @returns
*/
export function transformKeys<T extends GenericNode | Root>(mdast: T) {
export function transformKeys<T extends GenericNode | Root>(mdast: T): MapResult {
return map(mdast, addKeys);
}
2 changes: 1 addition & 1 deletion src/web/transforms/root.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { State, transform, unified } from 'mystjs';
import { Root } from './types';

export async function transformRoot(mdast: Root) {
export async function transformRoot(mdast: Root): Promise<Root> {
const state = new State();
mdast = await unified()
.use(transform, state, { addContainerCaptionNumbers: true })
Expand Down
3 changes: 2 additions & 1 deletion src/web/transforms/types.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { GenericNode, MyST, map } from 'mystjs';
import { CitationRenderer } from 'citation-js-utils';
import { GenericNode, MyST } from 'mystjs';
import { Frontmatter } from '../frontmatter';
import { IDocumentCache } from '../types';

export type Root = ReturnType<typeof MyST.prototype.parse>;
export type MapResult = ReturnType<typeof map>;

export type Citations = {
order: string[];
Expand Down
2 changes: 1 addition & 1 deletion src/web/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export function ensureBuildFolderExists(opts: Options) {
if (!exists(opts)) fs.mkdirSync(serverPath(opts), { recursive: true });
}

export function parseMyst(content: string) {
export function parseMyst(content: string): Root {
const myst = new MyST({
roles: { ...reactiveRoles },
directives: { ...directives },
Expand Down
15 changes: 12 additions & 3 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,28 @@
"target": "es6",
"noImplicitAny": true,
"strict": true,
"preserveSymlinks": true,
"moduleResolution": "node",
"lib": ["es2019"],
"lib": [
"es2019"
],
"sourceMap": true,
// outDir is overridden from the build:esm/build:cjs scripts
"outDir": "dist",
"baseUrl": ".",
// Type roots allows it to be included in a yarn workspace
"typeRoots": ["./types", "./node_modules/@types", "../../node_modules/@types"],
"typeRoots": [
"./types",
"./node_modules/@types",
"../../node_modules/@types"
],
"resolveJsonModule": true,
"declaration": true,
// Ignore node_modules, etc.
"skipLibCheck": true
},
"include": ["src/**/*"],
"include": [
"src/**/*"
],
"exclude": []
}

0 comments on commit dd11eba

Please sign in to comment.