Skip to content

Commit 842a335

Browse files
committed
feat: just better compilation
1 parent fe87384 commit 842a335

File tree

14 files changed

+276
-558
lines changed

14 files changed

+276
-558
lines changed

npm-shrinkwrap.json

Lines changed: 86 additions & 353 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@
5959
"globals": "^16.4.0",
6060
"hast-util-to-string": "^3.0.1",
6161
"hastscript": "^9.0.1",
62-
"idb-keyval": "^6.2.2",
6362
"lightningcss": "^1.30.1",
6463
"mdast-util-slice-markdown": "^2.0.1",
6564
"preact": "^10.27.2",
@@ -73,18 +72,16 @@
7372
"remark-parse": "^11.0.0",
7473
"remark-rehype": "^11.1.2",
7574
"remark-stringify": "^11.0.0",
76-
"rolldown": "^1.0.0-beta.40",
75+
"rolldown": "^1.0.0-beta.47",
7776
"semver": "^7.7.2",
7877
"shiki": "^3.15.0",
79-
"twoslash-cdn": "^0.3.4",
8078
"unified": "^11.0.5",
8179
"unist-builder": "^4.0.0",
8280
"unist-util-find-after": "^5.0.0",
8381
"unist-util-position": "^5.0.0",
8482
"unist-util-remove": "^4.0.0",
8583
"unist-util-select": "^5.1.0",
8684
"unist-util-visit": "^5.0.0",
87-
"unstorage": "^1.17.2",
8885
"vfile": "^6.0.3",
8986
"yaml": "^2.8.1"
9087
}

src/generators/legacy-html/index.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ import HTMLMinifier from '@minify-html/node';
77

88
import buildContent from './utils/buildContent.mjs';
99
import dropdowns from './utils/buildDropdowns.mjs';
10-
import { safeCopy } from './utils/safeCopy.mjs';
1110
import tableOfContents from './utils/tableOfContents.mjs';
1211
import { groupNodesByModule } from '../../utils/generators.mjs';
1312
import { getRemarkRehype } from '../../utils/remark.mjs';
13+
import { safeCopy } from '../../utils/safeCopy.mjs';
1414

1515
/**
1616
* @typedef {{

src/generators/web-twoslash/client.mjs

Lines changed: 0 additions & 107 deletions
This file was deleted.

src/generators/web-twoslash/index.mjs

Lines changed: 0 additions & 41 deletions
This file was deleted.

src/generators/web/index.mjs

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
import { readFile, writeFile } from 'node:fs/promises';
1+
import { readFile } from 'node:fs/promises';
22
import { createRequire } from 'node:module';
33
import { join } from 'node:path';
44

5-
import webTwoslashGenerator from '../web-twoslash/index.mjs';
65
import createASTBuilder from './utils/generate.mjs';
76
import { processJSXEntry } from './utils/processing.mjs';
7+
import { safeWrite } from '../../utils/safeWrite.mjs';
88

99
/**
1010
* This generator transforms JSX AST (Abstract Syntax Tree) entries into a complete
@@ -34,16 +34,17 @@ export default {
3434
);
3535

3636
const astBuilders = createASTBuilder();
37-
const requireFn = createRequire(import.meta.url);
3837

39-
await webTwoslashGenerator.generate(null, { output });
38+
const requireFn = createRequire(import.meta.url);
4039

4140
const results = [];
4241

4342
let mainCss = '';
4443

44+
const writtenChunks = new Set();
45+
4546
for (const entry of entries) {
46-
const { html, css } = await processJSXEntry(
47+
const { html, css, jsChunks } = await processJSXEntry(
4748
entry,
4849
template,
4950
astBuilders,
@@ -60,13 +61,22 @@ export default {
6061

6162
// Write HTML file if output directory is specified
6263
if (output) {
63-
await writeFile(join(output, `${entry.data.api}.html`), html, 'utf-8');
64+
safeWrite(join(output, `${entry.data.api}.html`), html, 'utf-8');
65+
66+
// Write JS chunks (only once per unique chunk)
67+
for (const chunk of jsChunks) {
68+
if (!writtenChunks.has(chunk.fileName)) {
69+
safeWrite(join(output, chunk.fileName), chunk.code, 'utf-8');
70+
71+
writtenChunks.add(chunk.fileName);
72+
}
73+
}
6474
}
6575
}
6676

67-
// Write CSS file
77+
// Write the main CSS file once after processing all entries
6878
if (output && mainCss) {
69-
await writeFile(join(output, 'styles.css'), mainCss, 'utf-8');
79+
safeWrite(join(output, 'styles.css'), mainCss, 'utf-8');
7080
}
7181

7282
return results;

src/generators/web/template.html

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,12 @@
1515

1616
<!-- Apply theme before paint to avoid Flash of Unstyled Content -->
1717
<script>document.documentElement.setAttribute("data-theme",localStorage.getItem("theme")||(matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light"));</script>
18+
19+
{{importMap}}
1820
</head>
1921

2022
<body>
2123
<div id="root">{{dehydrated}}</div>
22-
<script>{{clientBundleJs}}</script>
23-
<script type="module" src="twoslash.js?hash={{cacheHash}}"></script>
24+
<script type="module">{{mainJsCode}}</script>
2425
</body>
2526
</html>

src/generators/web/ui/components/CodeBox.jsx

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,9 @@ export const getLanguageDisplayName = language => {
2020
};
2121

2222
/** @param {import('react').PropsWithChildren<{ className: string }>} props */
23-
export default ({ className, ...props }) => {
23+
export default ({ className, children, ...props }) => {
2424
const matches = className?.match(/language-(?<language>[a-zA-Z]+)/);
25+
2526
const language = matches?.groups?.language ?? '';
2627

2728
const notify = useNotification();
@@ -30,7 +31,7 @@ export default ({ className, ...props }) => {
3031
await navigator.clipboard.writeText(text);
3132

3233
notify({
33-
duration: 300,
34+
duration: 3000,
3435
message: (
3536
<div className="flex items-center gap-3">
3637
<CodeBracketIcon className={styles.icon} />
@@ -41,12 +42,16 @@ export default ({ className, ...props }) => {
4142
};
4243

4344
return (
44-
<BaseCodeBox
45-
onCopy={onCopy}
46-
language={getLanguageDisplayName(language)}
47-
{...props}
48-
className={className}
49-
buttonText="Copy to clipboard"
50-
/>
45+
<>
46+
<BaseCodeBox
47+
onCopy={onCopy}
48+
language={getLanguageDisplayName(language)}
49+
{...props}
50+
className={className}
51+
buttonText="Copy to clipboard"
52+
>
53+
{children}
54+
</BaseCodeBox>
55+
</>
5156
);
5257
};

src/generators/web/ui/index.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
@import '@node-core/ui-components/styles/index.css';
2-
@import '@shikijs/twoslash/style-rich.css';
2+
@import '@node-core/rehype-shiki/index.css';
33

44
/* Fonts */
55
:root {

0 commit comments

Comments
 (0)