Skip to content

Commit

Permalink
get tests passing
Browse files Browse the repository at this point in the history
  • Loading branch information
benmccann committed Aug 16, 2024
1 parent b3a7bc7 commit 57ffc79
Show file tree
Hide file tree
Showing 12 changed files with 408 additions and 177 deletions.
15 changes: 3 additions & 12 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
{
"name": "mdsvex",
"version": "0.8.5",
"description": "Markdown preprocessor for Svelte",
"repository": "https://github.com/pngwn/MDsveX",
"name": "mdsvex-monorepo",
"scripts": {
"lint": "prettier --check .",
"format": "prettier --write .",
Expand All @@ -14,13 +11,6 @@
"site:dev": "pnpm --filter @mdsvex/site dev",
"site:build": "pnpm --filter @mdsvex/site build"
},
"keywords": [
"test",
"preprocessor",
"mdx",
"markdown",
"svelte"
],
"author": "pngwn <[email protected]>",
"license": "MIT",
"devDependencies": {
Expand All @@ -33,8 +23,9 @@
"rollup": "^2.77.4-1",
"rollup-plugin-dts": "^3.0.1",
"ts-node": "^9.1.1",
"tsm": "^2.3.0",
"typescript": "^4.2.4",
"uvu": "^0.5.1",
"uvu": "^0.5.6",
"watchlist": "^0.2.3"
},
"dependencies": {
Expand Down
3 changes: 2 additions & 1 deletion packages/mdsvex/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"name": "mdsvex",
"version": "0.12.2",
"description": "Markdown preprocessor for Svelte",
"type": "module",
"exports": {
".": {
"require": "./dist/main.cjs",
Expand All @@ -13,7 +14,7 @@
"repository": "https://github.com/pngwn/MDsveX",
"scripts": {
"build": "rollup -c",
"test": "uvu -r ts-node/register test test.ts$"
"test": "tsm ../../node_modules/uvu/bin.js test test.ts$"
},
"files": [
"dist/*",
Expand Down
9 changes: 5 additions & 4 deletions packages/mdsvex/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export * from './types';

import { join } from 'path';
import fs from 'fs';
import { fileURLToPath } from 'url';
import { parse } from 'svelte/compiler';
import unified from 'unified';
import markdown from 'remark-parse';
Expand All @@ -26,7 +27,7 @@ import remark2rehype from 'remark-rehype';
//@ts-ignore
import hast_to_html from '@starptech/prettyhtml-hast-to-html';

import { mdsvex_parser } from './parsers';
import { mdsvex_parser } from './parsers/index';
import {
default_frontmatter,
parse_frontmatter,
Expand All @@ -35,7 +36,7 @@ import {
smartypants_transformer,
highlight_blocks,
code_highlight,
} from './transformers';
} from './transformers/index';

function stringify(this: Processor, options = {}) {
this.Compiler = compiler;
Expand Down Expand Up @@ -128,11 +129,11 @@ function to_posix(_path: string): string {

function resolve_layout(layout_path: string): string {
try {
return to_posix(require.resolve(layout_path));
return to_posix(fileURLToPath(import.meta.resolve(layout_path)));
} catch (e) {
try {
const _path = join(process.cwd(), layout_path);
return to_posix(require.resolve(_path));
return to_posix(fileURLToPath(import.meta.resolve(_path)));
} catch (e) {
throw new Error(
`The layout path you provided couldn't be found at either ${layout_path} or ${join(
Expand Down
8 changes: 4 additions & 4 deletions packages/mdsvex/test/it/code_highlighting.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import * as assert from 'uvu/assert';
import { lines } from '../utils';
import * as shiki from 'shiki';

import { mdsvex } from '../../src';
import { mdsvex } from '../../src/index';

const highlight = suite('code-highlighting');

Expand Down Expand Up @@ -220,7 +220,7 @@ highlight(
code: string,
lang: string | undefined
): Promise<string> {
// const shiki = require('shiki');
// const shiki = await import('shiki');
const highlighter = await shiki.getHighlighter({
theme: 'material-theme-palenight',
});
Expand Down Expand Up @@ -347,8 +347,8 @@ highlight(
highlight(
'Should be possible to add additional highlighting grammars',
async () => {
require('prismjs');
require('prism-svelte');
await import('prismjs');
await import('prism-svelte');
const output = await mdsvex({
highlight: { alias: { beeboo: 'html' } },
}).markup({
Expand Down
7 changes: 5 additions & 2 deletions packages/mdsvex/test/it/mdsvex.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@ import { suite } from 'uvu';
import * as assert from 'uvu/assert';
import { Node, Parent } from 'unist';

import { join } from 'path';
import { dirname, join } from 'path';
import { fileURLToPath } from 'url';
import { lines } from '../utils';
import { to_posix } from '../../src/utils';

import { mdsvex, compile } from '../../src';
import { mdsvex, compile } from '../../src/index';
import containers from 'remark-containers';
import headings from 'remark-autolink-headings';
import slug from 'remark-slug';
Expand All @@ -17,6 +18,8 @@ import VMessage, { VFileMessage } from 'vfile-message';
import { Transformer } from 'unified';

const mdsvex_it = suite('mdsvex');

const __dirname = dirname(fileURLToPath(import.meta.url));
const fix_dir = join(__dirname, '..', '_fixtures');

mdsvex_it('it should work', async () => {
Expand Down
7 changes: 5 additions & 2 deletions packages/mdsvex/test/it/pure-markdown.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@ import { suite } from 'uvu';
import * as assert from 'uvu/assert';

import { readdirSync, readFileSync } from 'fs';
import { join, basename } from 'path';
import { basename, dirname, join } from 'path';
import { fileURLToPath } from 'url';
import { lines } from '../utils';
import { transform } from '../../src';
import { transform } from '../../src/index';

const __dirname = dirname(fileURLToPath(import.meta.url));

const PATH = join(__dirname, '../_fixtures/markdown');
const INPUT_PATH = join(PATH, 'input');
Expand Down
6 changes: 4 additions & 2 deletions packages/mdsvex/test/it/pure-svelte.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@ import { suite } from 'uvu';
import * as assert from 'uvu/assert';

import { readdirSync, readFileSync, existsSync, lstatSync } from 'fs';
import { join, extname } from 'path';
import { dirname, extname, join } from 'path';
import { fileURLToPath } from 'url';
import { lines } from '../utils';

import { transform } from '../../src';
import { transform } from '../../src/index';

const __dirname = dirname(fileURLToPath(import.meta.url));
const PATH = join(__dirname, '../_fixtures/svelte');

const is_dir = (path: string): boolean =>
Expand Down
6 changes: 4 additions & 2 deletions packages/mdsvex/test/it/svelte-markdown.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@ import { suite } from 'uvu';
import * as assert from 'uvu/assert';

import { readdirSync, readFileSync } from 'fs';
import { join, basename } from 'path';
import { basename, dirname, join } from 'path';
import { fileURLToPath } from 'url';
import { lines } from '../utils';

import { mdsvex } from '../../src';
import { mdsvex } from '../../src/index';

const __dirname = dirname(fileURLToPath(import.meta.url));
const PATH = join(__dirname, '../_fixtures/hybrid');
const INPUT_PATH = join(PATH, 'input');
const OUTPUT_PATH = join(PATH, 'output');
Expand Down
2 changes: 1 addition & 1 deletion packages/mdsvex/test/parsers/svelte_blocks.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { suite } from 'uvu';
import * as assert from 'uvu/assert';

import { parse_svelte_block } from '../../src/parsers';
import { parse_svelte_block } from '../../src/parsers/index';

const blocks = suite('svelte-blocks');

Expand Down
2 changes: 1 addition & 1 deletion packages/mdsvex/test/parsers/svelte_tags.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { suite } from 'uvu';
import * as assert from 'uvu/assert';

import { parse_svelte_tag } from '../../src/parsers';
import { parse_svelte_tag } from '../../src/parsers/index';

const tags = suite('svelte-tags');

Expand Down
1 change: 1 addition & 0 deletions packages/svelte-parse/test/samples.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import * as path from 'path';
import * as fs from 'fs';
import { fileURLToPath } from 'url';

import { parse } from '../src/main';

Expand Down
Loading

0 comments on commit 57ffc79

Please sign in to comment.