Skip to content

Commit

Permalink
Merge branch 'master' into fix-replace-yaml-dash-with-underscore
Browse files Browse the repository at this point in the history
  • Loading branch information
pngwn authored Aug 15, 2024
2 parents 8c7bdd7 + eeab8af commit 8c14e09
Show file tree
Hide file tree
Showing 40 changed files with 4,816 additions and 3,480 deletions.
2 changes: 1 addition & 1 deletion .changeset/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@
"access": "public",
"baseBranch": "master",
"updateInternalDependencies": "patch",
"ignore": ["mdsvex-playground"]
"ignore": ["@mdsvex/site"]
}
20 changes: 20 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# To get started with Dependabot version updates, you'll need to specify which
# package ecosystems to update and where the package manifests are located.
# Please see the documentation for all configuration options:
# https://docs.github.com/code-security/dependabot/dependabot-version-updates/configuration-options-for-the-dependabot.yml-file

version: 2
updates:
- package-ecosystem: "pnpm"
directories:
- "packages/*"
schedule:
interval: "weekly"
commit-message:
prefix: "[npm] "
- package-ecosystem: "github-actions"
directory: "/" # dependsabot magically works this out for actions
schedule:
interval: "weekly"
commit-message:
prefix: "[gha] "
18 changes: 9 additions & 9 deletions .github/workflows/mdsvex.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@ jobs:
name: lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- run: npm i -g pnpm@8
- uses: actions/setup-node@v3
- uses: actions/checkout@v4
- run: npm i -g pnpm@9
- uses: actions/setup-node@v4
with:
node-version: 16
node-version: 18
cache: 'pnpm'
cache-dependency-path: '**/pnpm-lock.yaml'
- run: pnpm i --frozen-lockfile
- run: pnpm format
- run: pnpm lint
# type-check here as well when it is working
env:
CI: true
Expand All @@ -32,12 +32,12 @@ jobs:
runs-on: ${{ matrix.os }}
strategy:
matrix:
node-version: [16, 18]
node-version: [18, 20, 22]
os: [ubuntu-latest, macOS-latest, windows-latest]
steps:
- uses: actions/checkout@v3
- run: npm i -g pnpm@8
- uses: actions/setup-node@v3
- uses: actions/checkout@v4
- run: npm i -g pnpm@9.1
- uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
cache: 'pnpm'
Expand Down
24 changes: 24 additions & 0 deletions .github/workflows/npm-previews.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: npm-previews

on:
pull_request:
paths-ignore:
- 'site/**'

jobs:
preview:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- run: npm i -g [email protected]
- uses: actions/setup-node@v4
with:
node-version: 22
cache: 'pnpm'
cache-dependency-path: '**/pnpm-lock.yaml'
- run: pnpm i --frozen-lockfile
- run: pnpm -r build
env:
CI: true
name: mdsvex
- run: pnpx pkg-pr-new publish './packages/*'
10 changes: 5 additions & 5 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout Repo
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
fetch-depth: 0
- run: npm i -g pnpm@8
- name: Setup Node.js 16
uses: actions/setup-node@v3
- run: npm i -g pnpm@9.1
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 16
node-version: 22
cache: 'pnpm'
cache-dependency-path: '**/pnpm-lock.yaml'
- name: Creating .npmrc
Expand Down
12 changes: 9 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,15 @@
"description": "Markdown preprocessor for Svelte",
"repository": "https://github.com/pngwn/MDsveX",
"scripts": {
"format": "prettier --check .",
"lint": "prettier --check .",
"format": "prettier --write .",
"test": "uvu -r ts-node/register packages test.ts$",
"test:filter": "uvu -r ts-node/register",
"release": "pnpm -r build && changeset publish",
"changeset:add": "changeset add",
"changeset:version": "changeset version && pnpm i --lockfile-only"
"changeset:version": "changeset version && pnpm i --lockfile-only",
"site:dev": "pnpm --filter @mdsvex/site dev",
"site:build": "pnpm --filter @mdsvex/site build"
},
"keywords": [
"test",
Expand All @@ -27,7 +30,7 @@
"@types/node": "^14.14.44",
"esm": "^3.2.25",
"prettier": "^2.2.1",
"rollup": "^2.47.0",
"rollup": "^2.77.4-1",
"rollup-plugin-dts": "^3.0.1",
"ts-node": "^9.1.1",
"typescript": "^4.2.4",
Expand All @@ -36,5 +39,8 @@
},
"dependencies": {
"tslib": "^2.3.1"
},
"engines": {
"pnpm": "^9.1.0"
}
}
28 changes: 28 additions & 0 deletions packages/mdsvex/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,33 @@
# mdsvex

## 0.12.0

### Minor Changes

- [#617](https://github.com/pngwn/MDsveX/pull/617) [`623b182`](https://github.com/pngwn/MDsveX/commit/623b18277b867a7b088951609710af871c9b9e56) Thanks [@benmccann](https://github.com/benmccann)! - add exports map to package.json and cleanup build output.

### Patch Changes

- [#612](https://github.com/pngwn/MDsveX/pull/612) [`91ef99f`](https://github.com/pngwn/MDsveX/commit/91ef99f9e95f6014243deadbbdcc13aac24079f8) Thanks [@moiri-gamboni](https://github.com/moiri-gamboni)! - Fix typescript module declaration to resolve errors when importing markdown files as components

## 0.11.2

### Patch Changes

- [#604](https://github.com/pngwn/MDsveX/pull/604) [`82553e0`](https://github.com/pngwn/MDsveX/commit/82553e02ab06b40a1650632865e076d0ad4d6ea4) Thanks [@pngwn](https://github.com/pngwn)! - Update peerDeps for Svelte 5

## 0.11.1

### Patch Changes

- [#596](https://github.com/pngwn/MDsveX/pull/596) [`d238325`](https://github.com/pngwn/MDsveX/commit/d2383257d959c68ea5279fd3a8d22ec6d5a4504e) Thanks [@TheOnlyTails](https://github.com/TheOnlyTails)! - Infer the settings type when using unified plugins with settings

* [#591](https://github.com/pngwn/MDsveX/pull/591) [`1ff938c`](https://github.com/pngwn/MDsveX/commit/1ff938c9e9aa588486fb57f762a5356630549288) Thanks [@vnphanquang](https://github.com/vnphanquang)! - Allow more extensive extension filtering. For example, now `.md.svelte` is possible

- [#592](https://github.com/pngwn/MDsveX/pull/592) [`68c6df2`](https://github.com/pngwn/MDsveX/commit/68c6df2e97103119a2bb048588f43d4f0fad1493) Thanks [@vnphanquang](https://github.com/vnphanquang)! - Pass filename to highlighter

* [#603](https://github.com/pngwn/MDsveX/pull/603) [`ae41002`](https://github.com/pngwn/MDsveX/commit/ae410026fb51bcdb5577c324a4e4d87323a0e57b) Thanks [@pngwn](https://github.com/pngwn)! - Update peerDependencies to allow Svelte 5

## 0.11.0

### Minor Changes
Expand Down
18 changes: 8 additions & 10 deletions packages/mdsvex/globals.d.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
declare module '*.svx' {
import type { SvelteComponentDev } from 'svelte/internal';
import type { SvelteComponent } from 'svelte';

export default class Comp extends SvelteComponentDev {
$$prop_def: {};
}
export const metadata: Record<string, any>;
export default class Comp extends SvelteComponent {}

export const metadata: Record<string, unknown>;
}

declare module '*.svelte.md' {
import type { SvelteComponentDev } from 'svelte/internal';
import type { SvelteComponent } from 'svelte';

export default class Comp extends SvelteComponent {}

export default class Comp extends SvelteComponentDev {
$$prop_def: {};
}
export const metadata: Record<string, any>;
export const metadata: Record<string, unknown>;
}
21 changes: 13 additions & 8 deletions packages/mdsvex/package.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
{
"name": "mdsvex",
"version": "0.11.0",
"version": "0.12.0",
"description": "Markdown preprocessor for Svelte",
"main": "dist/main.cjs.js",
"module": "dist/main.es.js",
"browser": "dist/mdsvex.js",
"exports": {
".": {
"require": "dist/main.cjs",
"default": "dist/main.mjs"
}
},
"main": "dist/main.cjs",
"module": "dist/main.mjs",
"repository": "https://github.com/pngwn/MDsveX",
"scripts": {
"build": "rollup -c"
Expand All @@ -23,8 +28,10 @@
"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": "^3.1.0",
"@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 @@ -46,11 +53,9 @@
"remark-slug": "^6.0.0",
"retext": "^7.0.1",
"retext-smartypants": "^4.0.0",
"rollup-plugin-commonjs": "^10.1.0",
"rollup-plugin-json": "^4.0.0",
"rollup-plugin-node-builtins": "^2.1.2",
"rollup-plugin-node-globals": "^1.4.0",
"rollup-plugin-node-resolve": "^5.2.0",
"rollup-plugin-svelte": "^5.1.1",
"shiki": "^0.9.3",
"svelte": "^4.0.0",
Expand All @@ -59,7 +64,7 @@
"vfile": "^4.2.0"
},
"peerDependencies": {
"svelte": ">=3 <5"
"svelte": "^3.56.0 || ^4.0.0 || ^5.0.0-next.120"
},
"dependencies": {
"@types/unist": "^2.0.3",
Expand Down
52 changes: 2 additions & 50 deletions packages/mdsvex/rollup.config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import resolve from 'rollup-plugin-node-resolve';
import commonjs from 'rollup-plugin-commonjs';
import resolve 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';
Expand Down Expand Up @@ -33,52 +33,4 @@ export default [
{ file: 'dist/main.cjs.d.ts', format: 'cjs' },
],
},
{
plugins: [
replace({
'(process ).browser': true,
'(process as RollupProcess).browser': true,
delimiters: ['', ''],
}),
resolve({ browser: true }),
commonjs({ namedExports: { 'svelte/compiler': ['parse'] } }),
json(),
sucrase({ transforms: ['typescript'] }),
globals(),
builtins(),
],
input: 'src/main.ts',
output: [
{
file: 'dist/browser-umd.js',
name: 'mdsvex',
format: 'umd',
sourcemap: false,
},
],
},
{
plugins: [
replace({
'(process ).browser': true,
'(process as RollupProcess).browser': true,
delimiters: ['', ''],
}),
resolve({ browser: true }),
commonjs({ namedExports: { 'svelte/compiler': ['parse'] } }),
json(),
sucrase({ transforms: ['typescript'] }),
globals(),
builtins(),
],
input: 'src/main.ts',
output: [
{
file: 'dist/browser-es.js',
name: 'mdsvex',
format: 'es',
sourcemap: false,
},
],
},
];
4 changes: 2 additions & 2 deletions packages/mdsvex/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -287,9 +287,9 @@ export const mdsvex = (options: MdsvexOptions = defaults): Preprocessor => {
name: 'mdsvex',
markup: async ({ content, filename }) => {
const extensionsParts = (extensions || [extension]).map((ext) =>
ext.split('.').pop()
ext.startsWith('.') ? ext : '.' + ext
);
if (!extensionsParts.includes(filename.split('.').pop())) return;
if (!extensionsParts.some((ext) => filename.endsWith(ext))) return;

const parsed = await parser.process({ contents: content, filename });
return {
Expand Down
8 changes: 5 additions & 3 deletions packages/mdsvex/src/transformers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,7 @@ export function transform_hast({
// @ts-ignore
_module[0].value = _module[0].value.replace(
RE_MODULE_SCRIPT,
`$1${newline}\t${fm}`
(match: string) => `${match}${newline}\t${fm}`
);
}

Expand Down Expand Up @@ -547,7 +547,7 @@ export function highlight_blocks({
}
}

return async function (tree) {
return async function (tree, vFile) {
if (highlight_fn) {
const nodes: (Code | HTML)[] = [];
visit<Code>(tree, 'code', (node) => {
Expand All @@ -560,7 +560,9 @@ export function highlight_blocks({
node.value = await highlight_fn(
node.value,
(node as Code).lang,
(node as Code).meta
(node as Code).meta,
//@ts-ignore
vFile.filename
);
})
);
Expand Down
11 changes: 8 additions & 3 deletions packages/mdsvex/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,9 @@ export type Layout = Record<string, LayoutMeta>;

export type Highlighter = (
code: string,
lang: string | undefined,
metastring: string | undefined
lang: string | null | undefined,
metastring: string | null | undefined,
filename?: string
) => string | Promise<string>;
interface HighlightOptions {
/**
Expand Down Expand Up @@ -182,7 +183,11 @@ interface HighlightOptions {
alias?: Record<string, string>;
}

export type UnifiedPlugins = Array<[Plugin, Settings] | Plugin>;
export type PluginWithSettings<
S extends any[] = [Settings?],
P extends Plugin<S> = Plugin<S>
> = [P, ...S];
export type UnifiedPlugins = Array<PluginWithSettings | Plugin>;

export interface TransformOptions {
remarkPlugins?: UnifiedPlugins;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
price: '$10'
---
<script context="module">
</script>
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<script context="module">
export const metadata = {"price":"$10"};
const { price } = metadata;
</script>
Loading

0 comments on commit 8c14e09

Please sign in to comment.