Skip to content

Commit 2595fed

Browse files
authored
Merge pull request #481 from Simon-He95/codex/perf-size-six-pack
perf: optimize streaming renderer defaults
2 parents 54aea35 + e9db3c8 commit 2595fed

25 files changed

Lines changed: 2754 additions & 297 deletions

package.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@
144144
"check:ssr": "vitest --run test/ssr-import.test.ts test/ssr-render-to-string.test.ts",
145145
"release:verify": "pnpm run build:parser && pnpm run build:core && pnpm lint && pnpm typecheck && pnpm exec vitest --run --testTimeout=10000 && pnpm run test:api:strict && MARKSTREAM_SMOKE_SKIP_BUILD=1 pnpm run test:smoke:pack && MARKSTREAM_SMOKE_SKIP_BUILD=1 pnpm run test:smoke:pack:optional",
146146
"release:verify:e2e": "pnpm run release:verify && pnpm run test:e2e:virtual-scroll && pnpm run test:e2e:virtual-scroll:stress",
147-
"prepublishOnly": "pnpm run build:parser && npm run build && pnpm run check:workspace-deps-published && MARKSTREAM_SMOKE_SKIP_BUILD=1 pnpm run test:smoke:pack && MARKSTREAM_SMOKE_SKIP_BUILD=1 pnpm run test:smoke:pack:optional",
147+
"prepublishOnly": "pnpm run build:parser && npm run build:pack && pnpm run check:workspace-deps-published && MARKSTREAM_SMOKE_SKIP_BUILD=1 pnpm run test:smoke:pack && MARKSTREAM_SMOKE_SKIP_BUILD=1 pnpm run test:smoke:pack:optional",
148148
"play": "pnpm run -C playground dev",
149149
"play:angular": "pnpm run -C playground-angular dev",
150150
"play:vue2": "pnpm run -C playground-vue2 dev",
@@ -175,6 +175,7 @@
175175
"build:parser": "pnpm run -C packages/markdown-parser build",
176176
"build:core": "pnpm run -C packages/markstream-core build",
177177
"build": "pnpm run build:core && vite build --mode npm && node scripts/write-tailwind-types.mjs && vite build --config vite.config.tailwind.ts --mode npm && node scripts/copy-tailwind-css.mjs && node scripts/generate-px-css.mjs && pnpm run build:dts",
178+
"build:pack": "pnpm run build:core && vite build --mode npm && node scripts/write-tailwind-types.mjs && vite build --config vite.config.tailwind.ts --mode npm && node scripts/copy-tailwind-css.mjs && node scripts/generate-px-css.mjs && pnpm run build:dts:pack",
178179
"build:analyze": "ANALYZE=true pnpm build",
179180
"size:check": "node scripts/check-package-size.mjs",
180181
"docs:dev": "vitepress dev docs",
@@ -195,7 +196,8 @@
195196
"prompts:list": "node ./bin/markstream-vue.mjs prompts list",
196197
"prompts:dir": "node ./bin/markstream-vue.mjs prompts dir",
197198
"prebuild:dts": "node ./scripts/prepare-dts-entry.cjs",
198-
"build:dts": "rollup -c ./scripts/rollup.dts.config.mjs && node ./scripts/clean-dts.cjs",
199+
"build:dts": "rollup -c ./scripts/rollup.dts.config.mjs && node ./scripts/clean-dts.cjs --strip-comments",
200+
"build:dts:pack": "rollup -c ./scripts/rollup.dts.config.mjs && node ./scripts/clean-dts.cjs --strip-comments",
199201
"build:demo": "vite build",
200202
"build:view": "vite preview",
201203
"changelog": "conventional-changelog -p angular --tag-prefix markstream-vue@ -i CHANGELOG.md -s -r 1",

scripts/clean-dts.cjs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ const process = require('node:process')
44

55
const distDir = path.resolve(__dirname, '..', 'dist')
66
const typesDir = path.join(distDir, 'types')
7+
const STRIP_DTS_COMMENTS = process.env.STRIP_DTS_COMMENTS === '1'
8+
|| process.argv.includes('--strip-comments')
79

810
function rewriteTypesEntry(content) {
911
return content
@@ -15,12 +17,42 @@ function referencesTypesDir(content) {
1517
return /from\s+['"]\.\/types\/|import\(['"]\.\/types\//.test(content)
1618
}
1719

20+
function stripDeclarationComments(content) {
21+
if (!STRIP_DTS_COMMENTS)
22+
return content
23+
24+
return content.replace(/\/\*\*[\s\S]*?\*\//g, (comment) => {
25+
return /@(?:deprecated|default|see|example|public|remarks)\b/.test(comment)
26+
? comment
27+
: ''
28+
})
29+
}
30+
31+
function stripDistDeclarationComments(dir = distDir) {
32+
for (const entry of fs.readdirSync(dir, { withFileTypes: true })) {
33+
const fullPath = path.join(dir, entry.name)
34+
if (entry.isDirectory()) {
35+
stripDistDeclarationComments(fullPath)
36+
continue
37+
}
38+
39+
if (!entry.name.endsWith('.d.ts'))
40+
continue
41+
42+
const content = fs.readFileSync(fullPath, 'utf8')
43+
const stripped = stripDeclarationComments(content)
44+
if (stripped !== content)
45+
fs.writeFileSync(fullPath, stripped)
46+
}
47+
}
48+
1849
const sourcePath = path.join(typesDir, 'exports.d.ts')
1950
const targetPath = path.join(distDir, 'index.d.ts')
2051

2152
if (fs.existsSync(targetPath)) {
2253
const bundledContent = fs.readFileSync(targetPath, 'utf8')
2354
if (!referencesTypesDir(bundledContent)) {
55+
stripDistDeclarationComments()
2456
if (fs.existsSync(typesDir))
2557
fs.rmSync(typesDir, { recursive: true, force: true })
2658
console.log('Keeping bundled', targetPath)
@@ -31,5 +63,6 @@ if (fs.existsSync(targetPath)) {
3163
if (fs.existsSync(sourcePath)) {
3264
const content = rewriteTypesEntry(fs.readFileSync(sourcePath, 'utf8'))
3365
fs.writeFileSync(targetPath, content)
66+
stripDistDeclarationComments()
3467
console.log('Rewrote', targetPath, 'from', sourcePath)
3568
}

src/components/MarkdownCodeBlockNode/MarkdownCodeBlockNode.vue

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,12 @@ import { computed, nextTick, onBeforeUnmount, onMounted, ref, watch } from 'vue'
44
import { useSafeI18n } from '../../composables/useSafeI18n'
55
import { hideTooltip, showTooltipForAnchor } from '../../composables/useSingletonTooltip'
66
import { useViewportPriority } from '../../composables/viewportPriority'
7-
import { getLanguageIcon, languageIconsRevision, languageMap, normalizeLanguageIdentifier } from '../../utils'
7+
import {
8+
getLanguageIcon,
9+
languageIconsRevision,
10+
languageMap,
11+
normalizeLanguageIdentifier,
12+
} from '../../utils/languageIcon'
813
import CodeBlockShell from '../CodeBlockNode/CodeBlockShell.vue'
914
1015
const props = withDefaults(

0 commit comments

Comments
 (0)