Skip to content

Commit

Permalink
Merge branch 'main' into pr/bhvngt/402
Browse files Browse the repository at this point in the history
  • Loading branch information
Akryum committed Dec 19, 2022
2 parents 1663382 + 5008ecb commit 526d726
Show file tree
Hide file tree
Showing 27 changed files with 1,192 additions and 1,115 deletions.
12 changes: 12 additions & 0 deletions docs/reference/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -429,3 +429,15 @@ export default defineConfig({
],
})
```

## `collectMaxThreads`

`number` - Default: available cpus

Number of maximum threads used to collect stories (both for development and building). Threads count will never go above this limit but might be lower.

```ts
export default defineConfig({
collectMaxThreads: 4,
})
```
6 changes: 3 additions & 3 deletions examples/svelte3/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@
},
"type": "module",
"dependencies": {
"svelte": "^3.49.0"
"svelte": "^3.54.0"
},
"devDependencies": {
"@histoire/plugin-svelte": "workspace:*",
"@sveltejs/vite-plugin-svelte": "^1.0.1",
"@sveltejs/vite-plugin-svelte": "^2.0.0",
"cypress": "^10.8.0",
"histoire": "workspace:*",
"start-server-and-test": "^1.14.0",
"svelte-preprocess": "^4.10.7",
"vite": "^3.0.5"
"vite": "^4.0.0"
}
}
2 changes: 1 addition & 1 deletion examples/sveltekit/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"@sveltejs/kit": "^1.0.0",
"@types/cookie": "^0.5.1",
"histoire": "workspace:*",
"svelte": "^3.49.0",
"svelte": "^3.54.0",
"svelte-check": "^2.7.1",
"svelte-preprocess": "^4.10.7",
"tslib": "^2.3.1",
Expand Down
4 changes: 2 additions & 2 deletions examples/vue2/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
},
"devDependencies": {
"@histoire/plugin-vue2": "workspace:*",
"@vitejs/plugin-vue2": "^1.1.2",
"@vitejs/plugin-vue2": "^2.1.0",
"histoire": "workspace:*",
"vite": "^3.0.5",
"vite": "^4.0.0",
"vue-template-compiler": "^2.7.8"
}
}
4 changes: 2 additions & 2 deletions examples/vue3-percy/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
"devDependencies": {
"@histoire/plugin-percy": "workspace:*",
"@histoire/plugin-vue": "workspace:*",
"@vitejs/plugin-vue": "^3.0.1",
"@vitejs/plugin-vue": "^4.0.0",
"histoire": "workspace:*",
"vite": "^3.0.5"
"vite": "^4.0.0"
}
}
4 changes: 2 additions & 2 deletions examples/vue3-screenshot/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
"devDependencies": {
"@histoire/plugin-screenshot": "workspace:*",
"@histoire/plugin-vue": "workspace:*",
"@vitejs/plugin-vue": "^3.0.1",
"@vitejs/plugin-vue": "^4.0.0",
"histoire": "workspace:*",
"vite": "^3.0.5"
"vite": "^4.0.0"
}
}
4 changes: 2 additions & 2 deletions examples/vue3-themed/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
"vue": "^3.2.31"
},
"devDependencies": {
"@vitejs/plugin-vue": "^3.0.1",
"@vitejs/plugin-vue": "^4.0.0",
"@histoire/plugin-vue": "workspace:*",
"histoire": "workspace:*",
"vite": "^3.0.5"
"vite": "^4.0.0"
}
}
4 changes: 2 additions & 2 deletions examples/vue3/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@
"@histoire/app": "workspace:*",
"@histoire/plugin-vue": "workspace:*",
"@histoire/vendors": "workspace:*",
"@vitejs/plugin-vue": "^3.0.1",
"@vitejs/plugin-vue": "^4.0.0",
"cypress": "^9.5.3",
"histoire": "workspace:*",
"sass": "^1.50.0",
"start-server-and-test": "^1.14.0",
"vite": "^3.0.5"
"vite": "^4.0.0"
}
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
"eslint": "*",
"eslint-plugin-promise": "*",
"eslint-plugin-vue": "*",
"vite": "^2.9.0 || ^3.0.0",
"vite": "^2.9.0 || ^3.0.0 || ^4.0.0",
"vue": "*"
}
}
Expand Down
4 changes: 2 additions & 2 deletions packages/histoire-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
"@tailwindcss/typography": "^0.5.2",
"@types/fs-extra": "^9.0.13",
"@types/node": "^17.0.32",
"@vitejs/plugin-vue": "^3.1.2",
"@vitejs/plugin-vue": "^4.0.0",
"autoprefixer": "^10.4.4",
"chokidar": "^3.5.3",
"concurrently": "^7.1.0",
Expand All @@ -51,7 +51,7 @@
"postcss-import": "^14.1.0",
"tailwindcss": "^3.0.23",
"typescript": "^4.7.4",
"vite": "^3.1.4",
"vite": "^4.0.0",
"vue": "^3.2.31"
}
}
4 changes: 2 additions & 2 deletions packages/histoire-controls-stories/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
},
"devDependencies": {
"@histoire/plugin-vue": "workspace:*",
"@vitejs/plugin-vue": "^3.1.2",
"@vitejs/plugin-vue": "^4.0.0",
"histoire": "workspace:*",
"vite": "^3.1.4"
"vite": "^4.0.0"
}
}
4 changes: 2 additions & 2 deletions packages/histoire-controls/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
"@peeky/server": "^0.14.0",
"@peeky/test": "^0.14.1",
"@types/node": "^17.0.32",
"@vitejs/plugin-vue": "^2.3.1",
"@vitejs/plugin-vue": "^4.0.0",
"@vue/test-utils": "^2.0.0-rc.19",
"@vueuse/core": "^8.2.5",
"autoprefixer": "^10.4.4",
Expand All @@ -63,7 +63,7 @@
"postcss-import": "^14.1.0",
"tailwindcss": "^3.0.23",
"typescript": "^4.7.4",
"vite": "^3.1.4",
"vite": "^4.0.0",
"vue": "^3.2.31",
"vue-tsc": "^0.35.2"
}
Expand Down
2 changes: 1 addition & 1 deletion packages/histoire-plugin-nuxt/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
"@nuxt/schema": "^3.0.0-rc.11",
"histoire": "workspace:*",
"typescript": "^4.7.4",
"vite": "^3.1.4"
"vite": "^4.0.0"
},
"peerDependencies": {
"@histoire/plugin-vue": "^0.11.9",
Expand Down
2 changes: 1 addition & 1 deletion packages/histoire-plugin-svelte/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
"histoire": "workspace:*",
"svelte": "^3.49.0",
"svelte-preprocess": "^4.10.7",
"vite": "^3.0.5"
"vite": "^4.0.0"
},
"peerDependencies": {
"histoire": "^0.11.9",
Expand Down
3 changes: 2 additions & 1 deletion packages/histoire-plugin-vue/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,10 @@
"@types/node": "^17.0.32",
"change-case": "^4.1.2",
"concurrently": "^7.1.0",
"globby": "^13.1.1",
"typescript": "^4.7.4",
"histoire": "workspace:*",
"vite": "^3.1.4",
"vite": "^4.0.0",
"vue": "^3.2.31"
},
"peerDependencies": {
Expand Down
29 changes: 29 additions & 0 deletions packages/histoire-plugin-vue/vite.config.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,35 @@
import { defineConfig } from 'vite'
import fs from 'node:fs'
import { globbySync } from 'globby'

export default defineConfig({
plugins: [
{
name: 'histoire:preserve:import.dynamic',
enforce: 'pre',
transform (code) {
if (code.includes('import(')) {
return {
code: code.replace(/import\(/g, 'import__dyn('),
}
}
},
closeBundle () {
try {
const files = globbySync('./dist/**/*.js')
for (const file of files) {
const content = fs.readFileSync(file, 'utf-8')
if (content.includes('import__dyn')) {
fs.writeFileSync(file, content.replace(/import__dyn\(/g, 'import(/* @vite-ignore */'), 'utf-8')
}
}
} catch (e) {
console.error(e)
}
},
},
],

build: {
emptyOutDir: false,
outDir: 'dist/bundled',
Expand Down
3 changes: 2 additions & 1 deletion packages/histoire-plugin-vue2/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,10 @@
"@types/node": "^17.0.32",
"change-case": "^4.1.2",
"concurrently": "^7.1.0",
"globby": "^13.1.1",
"histoire": "workspace:*",
"typescript": "^4.7.4",
"vite": "^3.1.4",
"vite": "^4.0.0",
"vue": "^2.7.8"
},
"peerDependencies": {
Expand Down
29 changes: 29 additions & 0 deletions packages/histoire-plugin-vue2/vite.config.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,35 @@
import { defineConfig } from 'vite'
import fs from 'node:fs'
import { globbySync } from 'globby'

export default defineConfig({
plugins: [
{
name: 'histoire:preserve:import.dynamic',
enforce: 'pre',
transform (code) {
if (code.includes('import(')) {
return {
code: code.replace(/import\(/g, 'import__dyn('),
}
}
},
closeBundle () {
try {
const files = globbySync('./dist/**/*.js')
for (const file of files) {
const content = fs.readFileSync(file, 'utf-8')
if (content.includes('import__dyn')) {
fs.writeFileSync(file, content.replace(/import__dyn\(/g, 'import(/* @vite-ignore */'), 'utf-8')
}
}
} catch (e) {
console.error(e)
}
},
},
],

build: {
emptyOutDir: false,
outDir: 'dist/bundled',
Expand Down
4 changes: 2 additions & 2 deletions packages/histoire-shared/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@
"picocolors": "^1.0.0"
},
"peerDependencies": {
"vite": "^2.9.0 || ^3.0.0"
"vite": "^2.9.0 || ^3.0.0 || ^4.0.0"
},
"devDependencies": {
"typescript": "^4.7.4",
"vite": "^3.0.5"
"vite": "^4.0.0"
}
}
5 changes: 5 additions & 0 deletions packages/histoire-shared/src/types/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,11 @@ export interface HistoireConfig {
*/
web?: RegExp[]
}
/**
* Maximum number of threads used to collect stories.
* By default based on available number of cores.
*/
collectMaxThreads?: number
}

export type ConfigMode = 'build' | 'dev'
8 changes: 4 additions & 4 deletions packages/histoire-vendors/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,17 @@
},
"devDependencies": {
"@iconify/vue": "^3.2.1",
"@rollup/plugin-commonjs": "^22.0.1",
"@rollup/plugin-node-resolve": "^13.3.0",
"@rollup/plugin-commonjs": "^23.0.3",
"@rollup/plugin-node-resolve": "^15.0.1",
"@types/node": "^18.0.3",
"@vueuse/core": "^8.2.5",
"execa": "^6.1.0",
"floating-vue": "^2.0.0-beta.19",
"fs-extra": "^10.0.1",
"globby": "^13.1.1",
"pinia": "^2.0.13",
"rollup": "^2.75.7",
"rollup-plugin-typescript2": "^0.32.1",
"rollup": "^3.5.1",
"rollup-plugin-typescript2": "^0.34.1",
"scroll-into-view-if-needed": "^2.2.29",
"typescript": "^4.7.4",
"vue-router": "^4.0.14",
Expand Down
10 changes: 5 additions & 5 deletions packages/histoire/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,13 @@
"pathe": "^0.2.0",
"picocolors": "^1.0.0",
"sade": "^1.8.1",
"shiki": "0.11.1",
"shiki-es": "^0.1.2",
"sirv": "^2.0.2",
"tinypool": "^0.1.2",
"vite-node": "0.23.4"
"vite-node": "0.26.0"
},
"peerDependencies": {
"vite": "^2.9.0 || ^3.0.0"
"vite": "^2.9.0 || ^3.0.0 || ^4.0.0"
},
"devDependencies": {
"@peeky/server": "^0.14.0",
Expand All @@ -81,8 +81,8 @@
"@types/markdown-it": "^12.2.3",
"@types/micromatch": "^4.0.2",
"@types/node": "^17.0.32",
"rollup": "^2.59.0",
"rollup": "^3.5.1",
"typescript": "^4.7.4",
"vite": "^3.0.5"
"vite": "^4.0.0"
}
}
2 changes: 1 addition & 1 deletion packages/histoire/src/node/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ import type {
BuildEndCallback,
PreviewStoryCallback,
} from '@histoire/shared'
import type { RollupOutput } from 'rollup'
import { APP_PATH } from './alias.js'
import { Context } from './context.js'
import { getViteConfigWithPlugins } from './vite.js'
import { findAllStories } from './stories.js'
import type { RollupOutput } from 'rollup'
import { useCollectStories } from './collect/index.js'
import { BuildPluginApi } from './plugin.js'
import { useModuleLoader } from './load.js'
Expand Down
6 changes: 4 additions & 2 deletions packages/histoire/src/node/collect/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,11 @@ export function useCollectStories (options: UseCollectStoriesOptions, ctx: Conte
transformMode: ctx.config.viteNodeTransformMode,
})

const maxThreads = ctx.config.collectMaxThreads ?? cpus().length

const threadsCount = ctx.mode === 'dev'
? Math.max(cpus().length / 2, 1)
: Math.max(cpus().length - 1, 1)
? Math.max(Math.min(maxThreads, cpus().length / 2), 1)
: Math.max(Math.min(maxThreads, cpus().length - 1), 1)
console.log(pc.blue(`Using ${threadsCount} threads for story collection`))

const threadPool = new Tinypool({
Expand Down
4 changes: 2 additions & 2 deletions packages/histoire/src/node/markdown.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import MarkdownIt from 'markdown-it'
import matter from 'gray-matter'
import shiki from 'shiki'
import { getHighlighter } from 'shiki-es'
import anchor from 'markdown-it-anchor'
import attrs from 'markdown-it-attrs'
import emoji from 'markdown-it-emoji'
Expand Down Expand Up @@ -28,7 +28,7 @@ function notifyMarkdownListChange () {
}

export async function createMarkdownRenderer (ctx: Context) {
const highlighter = await shiki.getHighlighter({
const highlighter = await getHighlighter({
theme: 'github-dark',
})

Expand Down

0 comments on commit 526d726

Please sign in to comment.