mirror of
https://github.com/modernweb-dev/rocket.git
synced 2026-03-10 08:51:24 +00:00
feat(@mdjs/core): move to ESM
This commit is contained in:
committed by
Thomas Allmer
parent
2555a8698d
commit
35ed64dca1
5
.changeset/chatty-turtles-explode.md
Normal file
5
.changeset/chatty-turtles-explode.md
Normal file
@@ -0,0 +1,5 @@
|
||||
---
|
||||
'@rocket/engine': patch
|
||||
---
|
||||
|
||||
Update es-module-lexer, small typecast fix because koa.context.body isn't always a string.
|
||||
5
.changeset/hot-peas-marry.md
Normal file
5
.changeset/hot-peas-marry.md
Normal file
@@ -0,0 +1,5 @@
|
||||
---
|
||||
'@mdjs/core': minor
|
||||
---
|
||||
|
||||
BREAKING: Refactor @mdjs/core to ESM-only package, use latest rehype/remark/unified dependencies.
|
||||
@@ -38,7 +38,7 @@
|
||||
"glob": "^7.0.0",
|
||||
"minimatch": "^3.0.4",
|
||||
"sax-wasm": "^2.0.0",
|
||||
"slash": "^3.0.0"
|
||||
"slash": "^4.0.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/glob": "^7.0.0"
|
||||
|
||||
@@ -15,6 +15,9 @@
|
||||
{
|
||||
"path": "../plugins-manager/tsconfig.json"
|
||||
},
|
||||
{
|
||||
"path": "../mdjs-core/tsconfig.json"
|
||||
},
|
||||
{
|
||||
"path": "../engine/tsconfig.json"
|
||||
}
|
||||
|
||||
@@ -51,10 +51,11 @@
|
||||
"@mdjs/core": "^0.9.5",
|
||||
"@parcel/watcher": "^2.0.5",
|
||||
"@web/dev-server": "^0.1.4",
|
||||
"es-module-lexer": "^0.9.3",
|
||||
"es-module-lexer": "^0.10.5",
|
||||
"lit": "^2.2.5",
|
||||
"plugins-manager": "^0.3.0",
|
||||
"sax-wasm": "^2.1.3"
|
||||
"sax-wasm": "^2.1.3",
|
||||
"unist-util-visit": "^4.1.0"
|
||||
},
|
||||
"types": "./dist-types/src/index.d.ts",
|
||||
"typesVersions": {
|
||||
|
||||
@@ -11,7 +11,7 @@ import { readFile, writeFile } from 'fs/promises';
|
||||
import path from 'path';
|
||||
import { addPlugin } from 'plugins-manager';
|
||||
import markdown from 'remark-parse';
|
||||
import visit from 'unist-util-visit';
|
||||
import { visit } from 'unist-util-visit';
|
||||
|
||||
/**
|
||||
* @param {string} string
|
||||
|
||||
@@ -14,6 +14,9 @@
|
||||
"references": [
|
||||
{
|
||||
"path": "../plugins-manager/tsconfig.json"
|
||||
},
|
||||
{
|
||||
"path": "../mdjs-core/tsconfig.json"
|
||||
}
|
||||
],
|
||||
"include": [
|
||||
|
||||
@@ -15,6 +15,9 @@
|
||||
{
|
||||
"path": "../plugins-manager/tsconfig.json"
|
||||
},
|
||||
{
|
||||
"path": "../mdjs-core/tsconfig.json"
|
||||
},
|
||||
{
|
||||
"path": "../engine/tsconfig.json"
|
||||
},
|
||||
|
||||
@@ -2,18 +2,11 @@
|
||||
/** @typedef {import('./types/code.js').Story} Story */
|
||||
/** @typedef {import('./types/code.js').MdjsProcessPlugin} MdjsProcessPlugin */
|
||||
|
||||
const { mdjsParse } = require('./src/mdjsParse.js');
|
||||
const { mdjsSetupCode } = require('./src/mdjsSetupCode.js');
|
||||
const { mdjsStoryParse } = require('./src/mdjsStoryParse.js');
|
||||
const { mdjsDocPage } = require('./src/mdjsDocPage.js');
|
||||
const { mdjsProcess } = require('./src/mdjsProcess.js');
|
||||
const { isMdjsContent } = require('./src/isMdjsContent.js');
|
||||
import { mdjsParse } from './src/mdjsParse.js';
|
||||
import { mdjsSetupCode } from './src/mdjsSetupCode.js';
|
||||
import { mdjsStoryParse } from './src/mdjsStoryParse.js';
|
||||
import { mdjsDocPage } from './src/mdjsDocPage.js';
|
||||
import { mdjsProcess } from './src/mdjsProcess.js';
|
||||
import { isMdjsContent } from './src/isMdjsContent.js';
|
||||
|
||||
module.exports = {
|
||||
mdjsParse,
|
||||
mdjsStoryParse,
|
||||
mdjsDocPage,
|
||||
mdjsProcess,
|
||||
isMdjsContent,
|
||||
mdjsSetupCode,
|
||||
};
|
||||
export { mdjsParse, mdjsStoryParse, mdjsDocPage, mdjsProcess, isMdjsContent, mdjsSetupCode };
|
||||
|
||||
@@ -1,6 +0,0 @@
|
||||
import cjsEntrypoint from './index.js';
|
||||
|
||||
const { mdjsParse, mdjsStoryParse, mdjsDocPage, mdjsProcess, isMdjsContent, mdjsSetupCode } =
|
||||
cjsEntrypoint;
|
||||
|
||||
export { mdjsParse, mdjsStoryParse, mdjsDocPage, mdjsProcess, isMdjsContent, mdjsSetupCode };
|
||||
@@ -14,11 +14,11 @@
|
||||
"author": "Modern Web <hello@modern-web.dev> (https://modern-web.dev/)",
|
||||
"homepage": "https://rocket.modern-web.dev/docs/markdown-javascript/overview/",
|
||||
"main": "./index.js",
|
||||
"type": "module",
|
||||
"exports": {
|
||||
".": {
|
||||
"types": "./dist-types/index.d.ts",
|
||||
"require": "./index.js",
|
||||
"default": "./index.mjs"
|
||||
"default": "./index.js"
|
||||
}
|
||||
},
|
||||
"scripts": {
|
||||
@@ -46,32 +46,32 @@
|
||||
"remark"
|
||||
],
|
||||
"dependencies": {
|
||||
"@mdjs/mdjs-preview": "^0.5.8",
|
||||
"@mdjs/mdjs-preview": "^0.5.9",
|
||||
"@mdjs/mdjs-story": "^0.3.2",
|
||||
"@types/unist": "^2.0.3",
|
||||
"es-module-lexer": "^0.9.3",
|
||||
"github-markdown-css": "^4.0.0",
|
||||
"plugins-manager": "^0.3.0",
|
||||
"rehype-autolink-headings": "^5.0.1",
|
||||
"rehype-prism": "^1.0.1",
|
||||
"rehype-raw": "^5.0.0",
|
||||
"rehype-slug": "^4.0.1",
|
||||
"rehype-stringify": "^8.0.0",
|
||||
"remark": "^13.0.0",
|
||||
"remark-gfm": "^1.0.0",
|
||||
"remark-parse": "^9.0.0",
|
||||
"remark-rehype": "^8.0.0",
|
||||
"slash": "^3.0.0",
|
||||
"unified": "^9.2.0",
|
||||
"unist-util-remove": "^2.0.1",
|
||||
"unist-util-visit": "^2.0.3"
|
||||
"@types/unist": "^2.0.6",
|
||||
"es-module-lexer": "^0.10.5",
|
||||
"github-markdown-css": "^5.1.0",
|
||||
"plugins-manager": "^0.3.1",
|
||||
"rehype-autolink-headings": "^6.1.1",
|
||||
"rehype-prism": "^2.1.3",
|
||||
"rehype-raw": "^6.1.1",
|
||||
"rehype-slug": "^5.0.1",
|
||||
"rehype-stringify": "^9.0.3",
|
||||
"remark": "^14.0.2",
|
||||
"remark-gfm": "^3.0.1",
|
||||
"remark-parse": "^10.0.1",
|
||||
"remark-rehype": "^10.1.0",
|
||||
"slash": "^4.0.0",
|
||||
"unified": "^10.1.2",
|
||||
"unist-util-remove": "^3.1.0",
|
||||
"unist-util-visit": "^4.1.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"demo-wc-card": "^0.1.0",
|
||||
"remark-autolink-headings": "^6.0.1",
|
||||
"remark-html": "^13.0.2",
|
||||
"remark-slug": "^6.0.0",
|
||||
"remark-stringify": "^9.0.1"
|
||||
"remark-autolink-headings": "^7.0.1",
|
||||
"remark-html": "^15.0.1",
|
||||
"remark-slug": "^7.0.1",
|
||||
"remark-stringify": "^10.0.2"
|
||||
},
|
||||
"types": "dist-types/index.d.ts"
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
* @param {string} text
|
||||
* @returns {boolean}
|
||||
*/
|
||||
function isMdjsContent(text) {
|
||||
export function isMdjsContent(text) {
|
||||
if (!text) {
|
||||
return false;
|
||||
}
|
||||
@@ -18,7 +18,3 @@ function isMdjsContent(text) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
isMdjsContent,
|
||||
};
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
const { mdjsProcess } = require('./mdjsProcess.js');
|
||||
import { mdjsProcess } from './mdjsProcess.js';
|
||||
|
||||
/**
|
||||
*
|
||||
* @param {string} body
|
||||
* @returns {Promise<string>}
|
||||
*/
|
||||
async function mdjsDocPage(body) {
|
||||
export async function mdjsDocPage(body) {
|
||||
const data = await mdjsProcess(body);
|
||||
return `
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
@@ -92,7 +92,3 @@ async function mdjsDocPage(body) {
|
||||
</div>
|
||||
`;
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
mdjsDocPage,
|
||||
};
|
||||
|
||||
@@ -1,12 +1,10 @@
|
||||
/* eslint-disable @typescript-eslint/ban-ts-comment */
|
||||
const visit = require('unist-util-visit');
|
||||
// @ts-ignore
|
||||
const remove = require('unist-util-remove');
|
||||
import { visit } from 'unist-util-visit';
|
||||
import { remove } from 'unist-util-remove';
|
||||
|
||||
/** @typedef {import('vfile').VFileOptions} VFileOptions */
|
||||
/** @typedef {import('unist').Node} Node */
|
||||
|
||||
function mdjsParse() {
|
||||
export function mdjsParse() {
|
||||
let jsCode = '';
|
||||
|
||||
/**
|
||||
@@ -14,26 +12,37 @@ function mdjsParse() {
|
||||
* @param {VFileOptions} file
|
||||
*/
|
||||
function transformer(tree, file) {
|
||||
visit(tree, 'code', node => {
|
||||
if (node.lang === 'js' && node.meta === 'script') {
|
||||
jsCode += node.value;
|
||||
}
|
||||
if (node.lang === 'js' && node.meta === 'client') {
|
||||
jsCode += node.value;
|
||||
}
|
||||
});
|
||||
visit(
|
||||
tree,
|
||||
'code',
|
||||
/** @param {Node & {[key: string]: unknown;}} node */ node => {
|
||||
if (node.lang === 'js' && node.meta === 'script') {
|
||||
jsCode += node.value;
|
||||
}
|
||||
if (node.lang === 'js' && node.meta === 'client') {
|
||||
jsCode += node.value;
|
||||
}
|
||||
},
|
||||
);
|
||||
// we can only return/modify the tree but jsCode should not be part of the tree
|
||||
// so we attach it globally to the file.data
|
||||
// eslint-disable-next-line no-param-reassign
|
||||
if (!file.data) {
|
||||
file.data = {};
|
||||
}
|
||||
file.data.jsCode = jsCode;
|
||||
|
||||
/**
|
||||
* @param {Node} node
|
||||
*/
|
||||
const removeFunction = node =>
|
||||
node.type === 'code' &&
|
||||
node.lang === 'js' &&
|
||||
(node.meta === 'script' || node.meta === 'client');
|
||||
const removeFunction = node => {
|
||||
const _node = /** @type {Node & {[key: string]: unknown;}} */ (node);
|
||||
return (
|
||||
_node.type === 'code' &&
|
||||
_node.lang === 'js' &&
|
||||
(_node.meta === 'script' || _node.meta === 'client')
|
||||
);
|
||||
};
|
||||
remove(tree, removeFunction);
|
||||
|
||||
return tree;
|
||||
@@ -41,7 +50,3 @@ function mdjsParse() {
|
||||
|
||||
return transformer;
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
mdjsParse,
|
||||
};
|
||||
|
||||
@@ -4,21 +4,23 @@
|
||||
/** @typedef {import('../types/code').ProcessResult} ProcessResult */
|
||||
/** @typedef {import('../types/code').MdjsProcessPlugin} MdjsProcessPlugin */
|
||||
|
||||
const unified = require('unified');
|
||||
const markdown = require('remark-parse');
|
||||
const gfm = require('remark-gfm');
|
||||
const remark2rehype = require('remark-rehype');
|
||||
const raw = require('rehype-raw');
|
||||
const htmlStringify = require('rehype-stringify');
|
||||
const htmlSlug = require('rehype-slug');
|
||||
const htmlHeading = require('rehype-autolink-headings');
|
||||
import { unified } from 'unified';
|
||||
import markdown from 'remark-parse';
|
||||
import gfm from 'remark-gfm';
|
||||
import remark2rehype from 'remark-rehype';
|
||||
import raw from 'rehype-raw';
|
||||
import htmlSlug from 'rehype-slug';
|
||||
import htmlHeading from 'rehype-autolink-headings';
|
||||
import htmlStringify from 'rehype-stringify';
|
||||
// @ts-ignore
|
||||
const { executeSetupFunctions } = require('plugins-manager');
|
||||
const loadLanguages = require('prismjs/components/');
|
||||
import { executeSetupFunctions } from 'plugins-manager';
|
||||
import { mdjsParse } from './mdjsParse.js';
|
||||
import { mdjsStoryParse } from './mdjsStoryParse.js';
|
||||
import { mdjsSetupCode } from './mdjsSetupCode.js';
|
||||
|
||||
const { mdjsParse } = require('./mdjsParse.js');
|
||||
const { mdjsStoryParse } = require('./mdjsStoryParse.js');
|
||||
const { mdjsSetupCode } = require('./mdjsSetupCode.js');
|
||||
import { createRequire } from 'module';
|
||||
const require = createRequire(import.meta.url);
|
||||
const loadLanguages = require('prismjs/components/');
|
||||
|
||||
let prismLoaded = false;
|
||||
|
||||
@@ -52,7 +54,7 @@ const defaultMetaPlugins = [
|
||||
* @param {function[]} [options.setupUnifiedPlugins]
|
||||
* @param {MdjsProcessPlugin[]} [options.plugins] deprecated option use setupUnifiedPlugins instead
|
||||
*/
|
||||
async function mdjsProcess(mdjs, { setupUnifiedPlugins = [] } = {}) {
|
||||
export async function mdjsProcess(mdjs, { setupUnifiedPlugins = [] } = {}) {
|
||||
const parser = unified();
|
||||
if (!prismLoaded) {
|
||||
prismLoaded = true;
|
||||
@@ -74,9 +76,5 @@ async function mdjsProcess(mdjs, { setupUnifiedPlugins = [] } = {}) {
|
||||
|
||||
const { stories, setupJsCode } = result.data;
|
||||
|
||||
return { stories, jsCode: setupJsCode, html: result.contents };
|
||||
return { stories, jsCode: setupJsCode, html: result.value };
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
mdjsProcess,
|
||||
};
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
const path = require('path');
|
||||
const slash = require('slash');
|
||||
import path from 'path';
|
||||
import slash from 'slash';
|
||||
|
||||
/** @typedef {import('vfile').VFileOptions} VFileOptions */
|
||||
/** @typedef {import('unist').Node} Node */
|
||||
@@ -22,7 +22,7 @@ const slash = require('slash');
|
||||
* @param {rocketConfig} [options.rocketConfig]
|
||||
* @returns
|
||||
*/
|
||||
function mdjsSetupCode({
|
||||
export function mdjsSetupCode({
|
||||
rootNodeQueryCode = 'document',
|
||||
simulationSettings = {},
|
||||
rocketConfig = {},
|
||||
@@ -43,11 +43,13 @@ function mdjsSetupCode({
|
||||
* @param {VFileOptions} file
|
||||
*/
|
||||
async function transformer(tree, file) {
|
||||
if (!file.data) {
|
||||
file.data = {};
|
||||
}
|
||||
const { stories, jsCode } = file.data;
|
||||
|
||||
file.data.setupJsCode = jsCode;
|
||||
|
||||
if (stories && stories.length > 0) {
|
||||
if (Array.isArray(stories) && stories.length > 0) {
|
||||
const storiesCode = stories.map(/** @param {Story} story */ story => story.code).join('\n');
|
||||
|
||||
const invokeStoriesCode = [];
|
||||
@@ -86,7 +88,3 @@ function mdjsSetupCode({
|
||||
|
||||
return transformer;
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
mdjsSetupCode,
|
||||
};
|
||||
|
||||
@@ -6,8 +6,8 @@
|
||||
/** @typedef {import('unist').Parent} UnistParent */
|
||||
/** @typedef {import('vfile').VFileOptions} VFileOptions */
|
||||
|
||||
const visit = require('unist-util-visit');
|
||||
const { init, parse } = require('es-module-lexer');
|
||||
import { visit } from 'unist-util-visit';
|
||||
import { init, parse } from 'es-module-lexer';
|
||||
|
||||
/**
|
||||
* @typedef {object} MDJSNodeProperties
|
||||
@@ -50,7 +50,7 @@ function defaultPreviewStoryTag(name) {
|
||||
* @param {TagFunction} [arg.previewStoryTag]
|
||||
* @param {number} [arg.counter]
|
||||
*/
|
||||
function mdjsStoryParse({
|
||||
export function mdjsStoryParse({
|
||||
storyTag = defaultStoryTag,
|
||||
previewStoryTag = defaultPreviewStoryTag,
|
||||
} = {}) {
|
||||
@@ -61,11 +61,12 @@ function mdjsStoryParse({
|
||||
/* eslint-disable no-param-reassign */
|
||||
|
||||
/**
|
||||
* @param {UnistNode} node
|
||||
* @param {UnistNode} _node
|
||||
* @param {number} index
|
||||
* @param {UnistParent} parent
|
||||
*/
|
||||
const nodeCodeVisitor = (node, index, parent) => {
|
||||
const nodeCodeVisitor = (_node, index, parent) => {
|
||||
let node = /** @type {UnistNode & {[key: string]: unknown}} */ (_node);
|
||||
if (node.lang === 'js' && node.meta === 'story' && typeof node.value === 'string') {
|
||||
const storyData = extractStoryData(node.value);
|
||||
node.type = 'html';
|
||||
@@ -80,12 +81,17 @@ function mdjsStoryParse({
|
||||
|
||||
const inside = [node];
|
||||
let skipAmount = 1;
|
||||
const next = parent.children[index + 1];
|
||||
|
||||
const next = /** @type {UnistNode & {[key: string]: unknown}} */ (
|
||||
parent.children[index + 1]
|
||||
);
|
||||
if (next && next.type === 'code' && next.meta === 'story-code') {
|
||||
inside.push(next);
|
||||
skipAmount += 1;
|
||||
|
||||
const next2 = parent.children[index + 2];
|
||||
const next2 = /** @type {UnistNode & {[key: string]: unknown}} */ (
|
||||
parent.children[index + 2]
|
||||
);
|
||||
if (next2 && next2.type === 'code' && next2.meta === 'story-code') {
|
||||
inside.push(next2);
|
||||
skipAmount += 1;
|
||||
@@ -132,12 +138,16 @@ function mdjsStoryParse({
|
||||
const tagParts = newValue.split('[[CODE SLOT]]');
|
||||
const inside = [node];
|
||||
let skipAmount = 1;
|
||||
const next = parent.children[index + 1];
|
||||
const next = /** @type {UnistNode & {[key: string]: unknown}} */ (
|
||||
parent.children[index + 1]
|
||||
);
|
||||
if (next && next.type === 'code' && next.meta === 'story-code') {
|
||||
inside.push(next);
|
||||
skipAmount += 1;
|
||||
|
||||
const next2 = parent.children[index + 2];
|
||||
const next2 = /** @type {UnistNode & {[key: string]: unknown}} */ (
|
||||
parent.children[index + 2]
|
||||
);
|
||||
if (next2 && next2.type === 'code' && next2.meta === 'story-code') {
|
||||
inside.push(next2);
|
||||
skipAmount += 1;
|
||||
@@ -176,6 +186,9 @@ function mdjsStoryParse({
|
||||
visit(tree, 'code', nodeCodeVisitor);
|
||||
// we can only return/modify the tree but stories should not be part of the tree
|
||||
// so we attach it globally to the file.data
|
||||
if (!file.data) {
|
||||
file.data = {};
|
||||
}
|
||||
file.data.stories = stories;
|
||||
|
||||
return tree;
|
||||
@@ -184,7 +197,3 @@ function mdjsStoryParse({
|
||||
return transformer;
|
||||
/* eslint-enable no-param-reassign */
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
mdjsStoryParse,
|
||||
};
|
||||
|
||||
@@ -1,22 +1,20 @@
|
||||
/* eslint-disable no-template-curly-in-string */
|
||||
|
||||
const unified = require('unified');
|
||||
const markdown = require('remark-parse');
|
||||
const remark2rehype = require('remark-rehype');
|
||||
const htmlStringify = require('rehype-stringify');
|
||||
const htmlSlug = require('rehype-slug');
|
||||
const htmlHeading = require('rehype-autolink-headings');
|
||||
const raw = require('rehype-raw');
|
||||
import { unified } from 'unified';
|
||||
import markdown from 'remark-parse';
|
||||
import remark2rehype from 'remark-rehype';
|
||||
import htmlStringify from 'rehype-stringify';
|
||||
import htmlSlug from 'rehype-slug';
|
||||
import htmlHeading from 'rehype-autolink-headings';
|
||||
import raw from 'rehype-raw';
|
||||
|
||||
const mdSlug = require('remark-slug');
|
||||
const mdHeadings = require('remark-autolink-headings');
|
||||
const mdStringify = require('remark-html');
|
||||
import mdSlug from 'remark-slug';
|
||||
import mdHeadings from 'remark-autolink-headings';
|
||||
import mdStringify from 'remark-html';
|
||||
|
||||
const chai = require('chai');
|
||||
const { mdjsParse } = require('../src/mdjsParse.js');
|
||||
const { mdjsStoryParse } = require('../src/mdjsStoryParse.js');
|
||||
|
||||
const { expect } = chai;
|
||||
import { expect } from 'chai';
|
||||
import { mdjsParse } from '../src/mdjsParse.js';
|
||||
import { mdjsStoryParse } from '../src/mdjsStoryParse.js';
|
||||
|
||||
/** @typedef {import("../src/mdjsParse.js").MDJSVFileData} MDJSVFileData */
|
||||
|
||||
@@ -67,8 +65,8 @@ describe('Integration', () => {
|
||||
.use(htmlHeading)
|
||||
.use(htmlStringify);
|
||||
const result = await parser.process(input);
|
||||
if (result.contents instanceof Buffer) throw new Error('contents should not be a buffer');
|
||||
expect(result.contents.split('\n')).to.deep.equal(expected);
|
||||
if (result.value instanceof Buffer) throw new Error('contents should not be a buffer');
|
||||
expect(result.value.split('\n')).to.deep.equal(expected);
|
||||
expect(/** @type {MDJSVFileData} */ (result.data).jsCode).to.equal('const bar = 22;');
|
||||
});
|
||||
|
||||
@@ -108,7 +106,7 @@ describe('Integration', () => {
|
||||
.use(mdHeadings)
|
||||
.use(mdStringify, { sanitize: false });
|
||||
const result = await parser.process(input);
|
||||
expect(result.contents).to.equal(expected);
|
||||
expect(result.value).to.equal(expected);
|
||||
expect(/** @type {MDJSVFileData} */ (result.data).stories).to.deep.equal([
|
||||
{
|
||||
key: 'fooStory',
|
||||
|
||||
@@ -1,12 +1,10 @@
|
||||
/* eslint-disable no-template-curly-in-string */
|
||||
import { adjustPluginOptions } from 'plugins-manager';
|
||||
import { mdjsProcess } from '../src/mdjsProcess.js';
|
||||
import { mdjsSetupCode } from '../src/mdjsSetupCode.js';
|
||||
import { mdjsStoryParse } from '../src/mdjsStoryParse.js';
|
||||
|
||||
const chai = require('chai');
|
||||
const { adjustPluginOptions } = require('plugins-manager');
|
||||
const { mdjsProcess } = require('../src/mdjsProcess.js');
|
||||
const { mdjsSetupCode } = require('../src/mdjsSetupCode.js');
|
||||
const { mdjsStoryParse } = require('../src/mdjsStoryParse.js');
|
||||
|
||||
const { expect } = chai;
|
||||
import { expect } from 'chai';
|
||||
|
||||
describe('mdjsProcess', () => {
|
||||
const input = [
|
||||
@@ -68,7 +66,6 @@ describe('mdjsProcess', () => {
|
||||
].join('\n');
|
||||
|
||||
const result = await mdjsProcess(input);
|
||||
|
||||
expect(result.html).to.equal(expected);
|
||||
expect(result.jsCode).to.equal(expectedJsCode);
|
||||
});
|
||||
|
||||
@@ -1,11 +1,9 @@
|
||||
const unified = require('unified');
|
||||
const markdown = require('remark-parse');
|
||||
const html = require('remark-html');
|
||||
import { unified } from 'unified';
|
||||
import markdown from 'remark-parse';
|
||||
import html from 'remark-html';
|
||||
import { mdjsParse } from '../src/mdjsParse.js';
|
||||
|
||||
const chai = require('chai');
|
||||
const { mdjsParse } = require('../src/mdjsParse.js');
|
||||
|
||||
const { expect } = chai;
|
||||
import { expect } from 'chai';
|
||||
|
||||
/** @typedef {import("../src/mdjsParse.js").MDJSVFileData} MDJSVFileData */
|
||||
|
||||
@@ -22,7 +20,7 @@ describe('mdjsParse', () => {
|
||||
].join('\n');
|
||||
const parser = unified().use(markdown).use(mdjsParse).use(html, { sanitize: false });
|
||||
const result = await parser.process(input);
|
||||
expect(result.contents).to.equal(
|
||||
expect(result.value).to.equal(
|
||||
'<h2>Intro</h2>\n<pre><code class="language-js">const foo = 1;\n</code></pre>\n',
|
||||
);
|
||||
expect(/** @type {MDJSVFileData} */ (result.data).jsCode).to.equal('const bar = 22;');
|
||||
@@ -40,7 +38,7 @@ describe('mdjsParse', () => {
|
||||
].join('\n');
|
||||
const parser = unified().use(markdown).use(mdjsParse).use(html, { sanitize: false });
|
||||
const result = await parser.process(input);
|
||||
expect(result.contents).to.equal(
|
||||
expect(result.value).to.equal(
|
||||
'<h2>Intro</h2>\n<pre><code class="language-js">const foo = 1;\n</code></pre>\n',
|
||||
);
|
||||
expect(/** @type {MDJSVFileData} */ (result.data).jsCode).to.equal('const bar = 22;');
|
||||
@@ -56,7 +54,7 @@ describe('mdjsParse', () => {
|
||||
].join('\n');
|
||||
const parser = unified().use(markdown).use(mdjsParse).use(html, { sanitize: false });
|
||||
const result = await parser.process(input);
|
||||
expect(result.contents).to.equal('');
|
||||
expect(result.value).to.equal('');
|
||||
expect(/** @type {MDJSVFileData} */ (result.data).jsCode).to.equal('const bar = 22;');
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,13 +1,11 @@
|
||||
/* eslint-disable no-template-curly-in-string */
|
||||
|
||||
const unified = require('unified');
|
||||
const markdown = require('remark-parse');
|
||||
const html = require('remark-html');
|
||||
import { unified } from 'unified';
|
||||
import markdown from 'remark-parse';
|
||||
import html from 'remark-html';
|
||||
import { mdjsStoryParse } from '../src/mdjsStoryParse.js';
|
||||
|
||||
const chai = require('chai');
|
||||
const { mdjsStoryParse } = require('../src/mdjsStoryParse.js');
|
||||
|
||||
const { expect } = chai;
|
||||
import { expect } from 'chai';
|
||||
|
||||
/** @typedef {import("../src/mdjsParse.js").MDJSVFileData} MDJSVFileData */
|
||||
|
||||
@@ -63,7 +61,7 @@ describe('mdjsStoryParse', () => {
|
||||
|
||||
const parser = unified().use(markdown).use(mdjsStoryParse).use(html, { sanitize: false });
|
||||
const result = await parser.process(input);
|
||||
expect(result.contents).to.equal(expected);
|
||||
expect(result.value).to.equal(expected);
|
||||
expect(/** @type {MDJSVFileData} */ (result.data).stories).to.deep.equal([
|
||||
{
|
||||
key: 'fooStory',
|
||||
@@ -112,7 +110,7 @@ describe('mdjsStoryParse', () => {
|
||||
})
|
||||
.use(html, { sanitize: false });
|
||||
const result = await parser.process(input);
|
||||
expect(result.contents).to.equal(expected);
|
||||
expect(result.value).to.equal(expected);
|
||||
});
|
||||
|
||||
it('will wrap following story-code blocks', async () => {
|
||||
@@ -150,7 +148,7 @@ describe('mdjsStoryParse', () => {
|
||||
|
||||
const parser = unified().use(markdown).use(mdjsStoryParse).use(html, { sanitize: false });
|
||||
const result = await parser.process(input);
|
||||
expect(result.contents).to.equal(expected);
|
||||
expect(result.value).to.equal(expected);
|
||||
});
|
||||
|
||||
it('will wrap following story-code blocks also for html stories', async () => {
|
||||
@@ -188,7 +186,7 @@ describe('mdjsStoryParse', () => {
|
||||
|
||||
const parser = unified().use(markdown).use(mdjsStoryParse).use(html, { sanitize: false });
|
||||
const result = await parser.process(input);
|
||||
expect(result.contents).to.equal(expected);
|
||||
expect(result.value).to.equal(expected);
|
||||
});
|
||||
|
||||
it('will wrap only following story-code blocks', async () => {
|
||||
@@ -244,6 +242,6 @@ describe('mdjsStoryParse', () => {
|
||||
|
||||
const parser = unified().use(markdown).use(mdjsStoryParse).use(html, { sanitize: false });
|
||||
const result = await parser.process(input);
|
||||
expect(result.contents).to.equal(expected);
|
||||
expect(result.value).to.equal(expected);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
{
|
||||
"extends": "../../tsconfig.node-base.json",
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"module": "ESNext",
|
||||
"outDir": "./dist-types",
|
||||
"rootDir": ".",
|
||||
"composite": true,
|
||||
|
||||
2
packages/mdjs-core/types/code.d.ts
vendored
2
packages/mdjs-core/types/code.d.ts
vendored
@@ -23,7 +23,7 @@ export interface ProcessResult {
|
||||
}
|
||||
|
||||
export interface ParseResult {
|
||||
contents: string;
|
||||
value: string;
|
||||
data: {
|
||||
stories: Story[];
|
||||
jsCode: string;
|
||||
|
||||
8
packages/mdjs-core/types/remark.d.ts
vendored
8
packages/mdjs-core/types/remark.d.ts
vendored
@@ -27,11 +27,3 @@ declare module 'rehype-autolink-headings' {
|
||||
|
||||
export = unified.Plugin;
|
||||
}
|
||||
|
||||
declare module 'unist-util-remove' {
|
||||
import unified from 'unified';
|
||||
|
||||
function remove(ast: unified.Node, opts: any, test?: any): unified.Node;
|
||||
|
||||
export = remove;
|
||||
}
|
||||
|
||||
@@ -15,6 +15,9 @@
|
||||
{
|
||||
"path": "../plugins-manager/tsconfig.json"
|
||||
},
|
||||
{
|
||||
"path": "../mdjs-core/tsconfig.json"
|
||||
},
|
||||
{
|
||||
"path": "../engine/tsconfig.json"
|
||||
},
|
||||
|
||||
@@ -7,6 +7,9 @@
|
||||
{
|
||||
"path": "./packages/plugins-manager/tsconfig.json"
|
||||
},
|
||||
{
|
||||
"path": "./packages/mdjs-core/tsconfig.json"
|
||||
},
|
||||
{
|
||||
"path": "./packages/engine/tsconfig.json"
|
||||
},
|
||||
|
||||
@@ -6,7 +6,7 @@ const packages = [
|
||||
{ name: 'search', type: 'js', environment: 'node-esm' },
|
||||
// { name: 'check-html-links', type: 'js', environment: 'node-esm' },
|
||||
// { name: 'drawer', type: 'js', environment: 'browser' },
|
||||
// { name: 'mdjs-core', type: 'js', environment: 'node' },
|
||||
{ name: 'mdjs-core', type: 'js', environment: 'node-esm' },
|
||||
// { name: 'mdjs-preview', type: 'js', environment: 'browser' },
|
||||
// { name: 'mdjs-story', type: 'js', environment: 'browser' },
|
||||
];
|
||||
|
||||
Reference in New Issue
Block a user