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

Vitest #637

Merged
merged 6 commits into from
Aug 17, 2024
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
9 changes: 9 additions & 0 deletions .changeset/sweet-dancers-doubt.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
"mdsvex": patch
"svast-stringify": patch
"svast-utils": patch
"svast": patch
"svelte-parse": patch
---

fix layout path resolution
6 changes: 5 additions & 1 deletion .github/workflows/mdsvex.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,13 @@ name: mdsvex

on:
push:
branches:
- main
paths-ignore:
- 'site/**'
pull_request:
branches:
- main
paths-ignore:
- 'site/**'

Expand Down Expand Up @@ -43,7 +47,7 @@ jobs:
cache: 'pnpm'
cache-dependency-path: '**/pnpm-lock.yaml'
- run: pnpm i --frozen-lockfile
- run: pnpm test
- run: pnpm test:run
- run: pnpm -r build
env:
CI: true
Expand Down
21 changes: 13 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@
"version": "0.8.5",
"description": "Markdown preprocessor for Svelte",
"repository": "https://github.com/pngwn/MDsveX",
"type": "module",
"scripts": {
"lint": "prettier --check .",
"format": "prettier --write .",
"test": "pnpm -r --filter=!site test",
"test:filter": "uvu -r ts-node/register",
"test:run": "vitest run . **/*.spec.ts ",
"release": "pnpm -r build && changeset publish",
"changeset:add": "changeset add",
"changeset:version": "changeset version && pnpm i --lockfile-only",
Expand All @@ -26,19 +27,23 @@
"devDependencies": {
"@changesets/changelog-github": "^0.4.0",
"@changesets/cli": "^2.16.0",
"@rollup/plugin-typescript": "^8.2.1",
"@rollup/plugin-typescript": "^11.1.6",
"@types/node": "^14.14.44",
"esm": "^3.2.25",
"prettier": "^2.2.1",
"rollup": "^2.77.4-1",
"rollup-plugin-dts": "^3.0.1",
"ts-node": "^9.1.1",
"rollup": "^4.20.0",
"rollup-plugin-dts": "^6.1.1",
"typescript": "^4.2.4",
"uvu": "^0.5.1",
"watchlist": "^0.2.3"
},
"dependencies": {
"tslib": "^2.3.1"
"@rollup/plugin-commonjs": "^26.0.1",
"@rollup/plugin-json": "^6.1.0",
"@rollup/plugin-node-resolve": "^15.2.3",
"@rollup/plugin-replace": "^5.0.7",
"@rollup/plugin-sucrase": "^5.0.2",
"rollup-plugin-node-globals": "^1.4.0",
"tslib": "^2.3.1",
"vitest": "^2.0.5"
},
"engines": {
"pnpm": "^9.1.0"
Expand Down
13 changes: 4 additions & 9 deletions packages/mdsvex/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,20 @@
"name": "mdsvex",
"version": "0.12.2",
"description": "Markdown preprocessor for Svelte",
"type": "module",
"exports": {
".": {
"require": "./dist/main.cjs",
"default": "./dist/main.mjs"
}
},
"./package.json": "./package.json"
},
"main": "dist/main.cjs",
"module": "dist/main.mjs",
"repository": "https://github.com/pngwn/MDsveX",
"scripts": {
"build": "rollup -c",
"test": "uvu -r ts-node/register test test.ts$"
"test": "vitest . **/*.spec.ts"
},
"files": [
"dist/*",
Expand All @@ -29,10 +31,6 @@
"author": "pngwn <[email protected]>",
"license": "MIT",
"devDependencies": {
"@rollup/plugin-commonjs": "^25.0.7",
"@rollup/plugin-node-resolve": "^15.2.3",
"@rollup/plugin-replace": "^2.4.2",
"@rollup/plugin-sucrase": "^5.0.2",
"@starptech/prettyhtml-hast-to-html": "^0.10.0",
"@types/acorn": "^4.0.5",
"@types/escape-html": "^1.0.0",
Expand All @@ -54,9 +52,6 @@
"remark-slug": "^6.0.0",
"retext": "^7.0.1",
"retext-smartypants": "^4.0.0",
"rollup-plugin-json": "^4.0.0",
"rollup-plugin-node-builtins": "^2.1.2",
"rollup-plugin-node-globals": "^1.4.0",
"rollup-plugin-svelte": "^5.1.1",
"shiki": "^0.9.3",
"svelte": "^4.0.0",
Expand Down
13 changes: 6 additions & 7 deletions packages/mdsvex/rollup.config.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
import resolve from '@rollup/plugin-node-resolve';
import node from '@rollup/plugin-node-resolve';
import commonjs from '@rollup/plugin-commonjs';
import json from 'rollup-plugin-json';
import builtins from 'rollup-plugin-node-builtins';
import globals from 'rollup-plugin-node-globals';
import json from '@rollup/plugin-json';
import sucrase from '@rollup/plugin-sucrase';
import dts from 'rollup-plugin-dts';
import replace from '@rollup/plugin-replace';
import { readFileSync } from 'fs';
import { resolve } from 'path';

import pkg from './package.json';
const pkg = JSON.parse(readFileSync(resolve('package.json'), 'utf-8'));

export default [
{
plugins: [
resolve({ preferBuiltins: true }),
node({ preferBuiltins: true }),
commonjs({ namedExports: { 'svelte/compiler': ['parse'] } }),
json(),
sucrase({ transforms: ['typescript'] }),
Expand Down
7 changes: 5 additions & 2 deletions packages/mdsvex/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import extract_frontmatter from 'remark-frontmatter';
import remark2rehype from 'remark-rehype';
//@ts-ignore
import hast_to_html from '@starptech/prettyhtml-hast-to-html';
import { createRequire } from 'module';

import { mdsvex_parser } from './parsers';
import {
Expand Down Expand Up @@ -126,13 +127,15 @@ function to_posix(_path: string): string {
return _path.replace(/\\/g, '/');
}

const _require = import.meta.url ? createRequire(import.meta.url) : require;

function resolve_layout(layout_path: string): string {
try {
return to_posix(require.resolve(layout_path));
return to_posix(_require.resolve(layout_path));
} catch (e) {
try {
const _path = join(process.cwd(), layout_path);
return to_posix(require.resolve(_path));
return to_posix(_require.resolve(_path));
} catch (e) {
throw new Error(
`The layout path you provided couldn't be found at either ${layout_path} or ${join(
Expand Down
Loading