8000 Optimize speed of `npm run dev` by NWylynko · Pull Request #2296 · clerk/clerk-docs · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Optimize speed of npm run dev #22 8000 96

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

Merged
merged 6 commits into from
Jun 11, 2025
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
225 changes: 222 additions & 3 deletions scripts/build-docs.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,6 @@ const baseConfig = {
},
flags: {
skipGit: true,
clean: true,
skipApiErrors: true,
},
} satisfies Partial<Parameters<typeof createConfig>[0]>
Expand Down Expand Up @@ -205,7 +204,6 @@ Testing with a simple page.`,
validSdks: ['nextjs', 'react'],
flags: {
skipGit: false,
clean: true,
skipApiErrors: true,
},
}),
Expand Down Expand Up @@ -3263,10 +3261,232 @@ title: Updated Title

// Check updated content
const updatedContent = await readFile(pathJoin('./dist/cached-doc.mdx'))

expect(updatedContent).toContain('Updated Title')
expect(updatedContent).toContain('Updated Content')
})

test('should invalidate linked pages when the markdown changes', async () => {
const { tempDir, pathJoin } = await createTempFiles([
{
path: './docs/manifest.json',
content: JSON.stringify({
navigation: [
[
{ title: 'Cached Doc', href: '/docs/cached-doc' },
{ title: 'Linked Doc', href: '/docs/linked-doc' },
],
],
}),
},
{
path: './docs/cached-doc.mdx',
content: `---
title: Original Title
---

[Link to Linked Doc](/docs/linked-doc)`,
},
{
path: './docs/linked-doc.mdx',
content: `---
title: Linked Doc
sdk: react, nextjs
---

# Linked Doc`,
},
])

// Create store to maintain cache across builds
const store = createBlankStore()
const config = await createConfig({
...baseConfig,
basePath: tempDir,
validSdks: ['react', 'nextjs', 'astro'],
})
const invalidate = invalidateFile(store, config)

// First build
await build(config, store)

expect(await readFile(pathJoin('./dist/cached-doc.mdx'))).toContain(
'<SDKLink href="/docs/:sdk:/linked-doc" sdks={["react","nextjs"]}>Link to Linked Doc</SDKLink>',
)

// Update file content
await fs.writeFile(
pathJoin('./docs/linked-doc.mdx'),
`---
title: Linked Doc
sdk: react, nextjs, astro
---

# Linked Doc`,
'utf-8',
)

invalidate(pathJoin('./docs/linked-doc.mdx'))

// Second build with same store (should detect changes)
await build(config, store)

// Check updated content
expect(await readFile(pathJoin('./dist/cached-doc.mdx'))).toContain(
'<SDKLink href="/docs/:sdk:/linked-doc" sdks={["react","nextjs","astro"]}>Link to Linked Doc</SDKLink>',
)
})

test('should invalidate linked pages when the partial changes', async () => {
const { tempDir, pathJoin } = await createTempFiles([
{
path: './docs/manifest.json',
content: JSON.stringify({
navigation: [
[
{ title: 'Cached Doc', href: '/docs/cached-doc' },
{ title: 'Linked Doc', href: '/docs/linked-doc' },
],
],
}),
},
{
path: './docs/_partials/partial.mdx',
content: `[Link to Linked Doc](/docs/linked-doc)`,
},
{
path: './docs/cached-doc.mdx',
content: `---
title: Original Title
---

<Include src="_partials/partial" />`,
},
{
path: './docs/linked-doc.mdx',
content: `---
title: Linked Doc
sdk: react, nextjs
---

# Linked Doc`,
},
])

// Create store to maintain cache across builds
const store = createBlankStore()
const config = await createConfig({
...baseConfig,
basePath: tempDir,
validSdks: ['react', 'nextjs', 'astro'],
})
const invalidate = invalidateFile(store, config)

// First build
await build(config, store)

expect(await readFile(pathJoin('./dist/cached-doc.mdx'))).toContain(
'<SDKLink href="/docs/:sdk:/linked-doc" sdks={["react","nextjs"]}>Link to Linked Doc</SDKLink>',
)

// Update file content
await fs.writeFile(
pathJoin('./docs/linked-doc.mdx'),
`---
title: Linked Doc
sdk: react, nextjs, astro
---

# Linked Doc`,
'utf-8',
)

invalidate(pathJoin('./docs/linked-doc.mdx'))

// Second build with same store (should detect changes)
await build(config, store)

// Check updated content
expect(await readFile(pathJoin('./dist/cached-doc.mdx'))).toContain(
'<SDKLink href="/docs/:sdk:/linked-doc" sdks={["react","nextjs","astro"]}>Link to Linked Doc</SDKLink>',
)
})

test('should invalidate linked pages when the typedoc changes', async () => {
const { tempDir, pathJoin } = await createTempFiles([
{
path: './docs/manifest.json',
content: JSON.stringify({
navigation: [
[
{ title: 'Cached Doc', href: '/docs/cached-doc' },
{ title: 'Linked Doc', href: '/docs/linked-doc' },
],
],
}),
},
{
path: './typedoc/component.mdx',
content: `[Link to Linked Doc](/docs/linked-doc)`,
},
{
path: './docs/cached-doc.mdx',
content: `---
title: Original Title
---

<Typedoc src="component" />`,
},
{
path: './docs/linked-doc.mdx',
content: `---
title: Linked Doc
sdk: react, nextjs
---

# Linked Doc`,
},
])

// Create store to maintain cache across builds
const store = createBlankStore()
const config = await createConfig({
...baseConfig,
basePath: tempDir,
validSdks: ['react', 'nextjs', 'astro'],
})
const invalidate = invalidateFile(store, config)

// First build
await build(config, store)

expect(await readFile(pathJoin('./dist/cached-doc.mdx'))).toContain(
'<SDKLink href="/docs/:sdk:/linked-doc" sdks={["react","nextjs"]}>Link to Linked Doc</SDKLink>',
)

// Update file content
await fs.writeFile(
pathJoin('./docs/linked-doc.mdx'),
`---
title: Linked Doc
sdk: react, nextjs, astro
---

# Linked Doc`,
'utf-8',
)

invalidate(pathJoin('./docs/linked-doc.mdx'))

// Second build with same store (should detect changes)
await build(config, store)

// Check updated content
expect(await readFile(pathJoin('./dist/cached-doc.mdx'))).toContain(
'<SDKLink href="/docs/:sdk:/linked-doc" sdks={["react","nextjs","astro"]}>Link to Linked Doc</SDKLink>',
)
})

test('should update doc content when the partial changes in a sdk scoped doc', async () => {
const { tempDir, pathJoin } = await createTempFiles([
{
Expand Down Expand Up @@ -4309,7 +4529,6 @@ describe('API Errors Generation', () => {
flags: {
skipApiErrors: false,
skipGit: true,
clean: true,
},
}),
)
Expand Down
Loading
0