Skip to content

Commit 14ad73f

Browse files
authored
Replace process polyfill with something that isn't ridiculous (#714)
* fix fs failure * fix * Create shiny-parrots-fly.md * ensure it works with v5 syntax * Create popular-donuts-think.md * Update shiny-parrots-fly.md * asd
1 parent 1ac1a94 commit 14ad73f

11 files changed

Lines changed: 96 additions & 100 deletions

File tree

‎.changeset/popular-donuts-think.md‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"mdsvex": patch
3+
---
4+
5+
Ensure that mdsvex files and layouts can contain Svelte 5 syntax.

‎.changeset/shiny-parrots-fly.md‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"mdsvex": patch
3+
---
4+
5+
Replace process polyfill with something that isn't ridiculous

‎package.json‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,12 @@
4949
"tslib": "^2.3.1"
5050
},
5151
"engines": {
52-
"pnpm": "^9.1.0"
52+
"pnpm": "^9.1.4"
5353
},
5454
"pnpm": {
5555
"onlyBuiltDependencies": [
5656
"esbuild"
5757
]
5858
},
59-
"packageManager": "pnpm@9.1.0"
59+
"packageManager": "pnpm@9.1.4"
6060
}

‎packages/mdsvex/package.json‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,9 @@
5959
"remark-slug": "^6.0.0",
6060
"retext": "^7.0.1",
6161
"retext-smartypants": "^4.0.0",
62-
"rollup-plugin-polyfill-node": "^0.13.0",
6362
"rollup-plugin-svelte": "^5.1.1",
6463
"shiki": "^0.9.3",
65-
"svelte": "^4.0.0",
64+
"svelte": "^5.0.0",
6665
"toml": "^3.0.0",
6766
"unified": "^9.1.0",
6867
"vfile": "^4.2.0"

‎packages/mdsvex/rollup.config.js‎

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,10 @@ import sucrase from '@rollup/plugin-sucrase';
55
import dts from 'rollup-plugin-dts';
66
import { readFileSync } from 'fs';
77
import { resolve } from 'path';
8-
import polyfillNode from 'rollup-plugin-polyfill-node';
9-
10-
const pkg = JSON.parse(readFileSync(resolve('package.json'), 'utf-8'));
118

129
export default [
1310
{
1411
plugins: [
15-
polyfillNode({
16-
include: ['process'],
17-
}),
1812
node({ preferBuiltins: true }),
1913
commonjs(),
2014
json(),

‎packages/mdsvex/src/index.ts‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ import type {
1414
} from './types';
1515
export * from './types';
1616

17-
// import { join } from 'path';
18-
// import fs from 'fs';
17+
import { make_process } from './utils';
18+
1919
import { parse } from 'svelte/compiler';
2020
import unified from 'unified';
2121
import markdown from 'remark-parse';
@@ -371,8 +371,8 @@ const _compile = async (
371371
opts?: MdsvexCompileOptions
372372
): Promise<PreprocessorReturn> => {
373373
if (is_browser) {
374-
const process = await import('process');
375-
globalThis.process = process;
374+
// @ts-ignore
375+
globalThis.process = make_process();
376376
}
377377

378378
const preprocessor = mdsvex(opts);

‎packages/mdsvex/src/transformers/index.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,7 @@ function extract_parts(nodes: Array<Element | Text>): Parts {
188188
module?: any;
189189
};
190190
try {
191+
// @ts-ignore
191192
result = parse(nodes[i].value as string);
192193
} catch (e) {
193194
parts.html.push(nodes[i]);

‎packages/mdsvex/src/utils.ts‎

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,57 @@ export function to_posix(_path: string): string {
88

99
return _path.replace(/\\/g, '/');
1010
}
11+
12+
export function make_process() {
13+
const process = {
14+
title: 'browser',
15+
argv: [],
16+
version: '', // empty string to avoid regexp issues
17+
versions: {
18+
http_parser: '',
19+
node: '',
20+
v8: '',
21+
ares: '',
22+
uv: '',
23+
zlib: '',
24+
brotli: '',
25+
modules: '',
26+
nghttp2: '',
27+
napi: '',
28+
llhttp: '',
29+
openssl: '',
30+
icu: '',
31+
tz: '',
32+
unicode: '',
33+
},
34+
env: {
35+
NODE_ENV: 'production',
36+
},
37+
stdout: {
38+
isTTY: false,
39+
},
40+
binding() {
41+
return;
42+
},
43+
cwd() {
44+
return '/';
45+
},
46+
chdir() {
47+
return;
48+
},
49+
umask() {
50+
return 0;
51+
},
52+
on: noop,
53+
addListener: noop,
54+
once: noop,
55+
off: noop,
56+
removeListener: noop,
57+
removeAllListeners: noop,
58+
emit: noop,
59+
};
60+
61+
function noop() {}
62+
63+
return process;
64+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<script lang="ts">
2+
const { children, ...rest } = $props();
3+
</script>
4+
5+
<p>am layout</p>
6+
<p>metadata title: {rest.title}</p>
7+
{@render children()}

‎packages/test-app/svelte.config.js‎

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,15 @@
11
import adapter from '@sveltejs/adapter-auto';
22
import { vitePreprocess } from '@sveltejs/vite-plugin-svelte';
33
import { mdsvex } from 'mdsvex';
4+
5+
import { join, dirname } from 'path';
6+
import { fileURLToPath } from 'url';
7+
8+
const __filename = fileURLToPath(import.meta.url);
9+
const __dirname = dirname(__filename);
10+
11+
const path_to_layout = join(__dirname, './src/lib/Layout.svelte');
12+
413
/** @type {import('@sveltejs/kit').Config} */
514
const config = {
615
// Consult https://svelte.dev/docs/kit/integrations
@@ -14,7 +23,9 @@ const config = {
1423
adapter: adapter(),
1524
},
1625
extensions: ['.svx', '.svelte'],
17-
preprocess: mdsvex(),
26+
preprocess: mdsvex({
27+
layout: path_to_layout,
28+
}),
1829
};
1930

2031
export default config;

0 commit comments

Comments
 (0)