-
-
Notifications
You must be signed in to change notification settings - Fork 322
Add ladle plugin #728
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
Add ladle plugin #728
Changes from 1 commit
733e0a7
8beeb70
66f9edb
1bfc42d
4025e7f
c813e69
67c4e87
cfefa56
0f5ae20
1bf1838
c8c051e
452c099
00c7af2
fff5023
52b34c7
9ca4e9a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| { | ||
| "name": "@fixtures/ladle", | ||
| "scripts": { | ||
| "dev": "ladle serve --port 4123", | ||
| "build": "ladle build" | ||
| }, | ||
| "dependencies": { | ||
| "@ladle/react": "*", | ||
| "react": "*", | ||
| "react-dom": "*" | ||
| }, | ||
| "devDependencies": { | ||
| "@types/node": "*", | ||
| "@types/react": "*", | ||
| "@types/react-dom": "*", | ||
| "typescript": "*" | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| import type { EnablerPatterns } from '#p/types/config.js'; | ||
| import type { IsPluginEnabled, Plugin, ResolveEntryPaths } from '#p/types/plugins.js'; | ||
| import { hasDependency } from '#p/util/plugin.js'; | ||
| import type { LadleConfig } from './types.js'; | ||
| import { toEntryPattern } from '../../util/protocols.js'; | ||
|
|
||
| // https://ladle.dev/docs/config | ||
|
|
||
| const title = 'ladle'; | ||
|
|
||
| const enablers: EnablerPatterns = [/^@ladle\//]; | ||
|
|
||
| const isEnabled: IsPluginEnabled = ({ dependencies }) => hasDependency(dependencies, enablers); | ||
|
|
||
| const config = ['.ladle/config.{mjs,js,ts}']; | ||
|
|
||
| const stories: string[] = ['**/*.@(stories.@(mdx|js|jsx|mjs|ts|tsx))']; | ||
| const restEntry: string[] = ['.ladle/components.{js,jsx,ts,tsx}', 'head.html']; | ||
justb3a marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| const entry: string[] = [...restEntry, ...stories]; | ||
|
|
||
| const project = ['.ladle/**/*.{js,jsx,ts,tsx}']; | ||
|
|
||
| const resolveEntryPaths: ResolveEntryPaths<LadleConfig> = async localConfig => { | ||
| const localStories = typeof localConfig.stories === 'string' ? [localConfig.stories] : localConfig.stories; | ||
| const localViteConfig = localConfig.viteConfig ? [localConfig.viteConfig] : []; | ||
|
||
|
|
||
| const patterns = [...restEntry, ...(localStories ?? stories), ...localViteConfig]; | ||
|
|
||
| return patterns.map(toEntryPattern); | ||
| }; | ||
|
|
||
| export default { | ||
| title, | ||
| enablers, | ||
| isEnabled, | ||
| config, | ||
| entry, | ||
| project, | ||
| resolveEntryPaths, | ||
| } satisfies Plugin; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| export type LadleConfig = { | ||
| stories?: string | string[]; | ||
| viteConfig?: string; | ||
| }; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| import { test } from 'bun:test'; | ||
| import assert from 'node:assert/strict'; | ||
| import { main } from '../../src/index.js'; | ||
| import { resolve } from '../../src/util/path.js'; | ||
| import baseArguments from '../helpers/baseArguments.js'; | ||
| import baseCounters from '../helpers/baseCounters.js'; | ||
|
|
||
| const cwd = resolve('fixtures/plugins/ladle'); | ||
|
|
||
| test('Find dependencies with the ladle plugin', async () => { | ||
| const { issues, counters } = await main({ | ||
| ...baseArguments, | ||
| cwd, | ||
| }); | ||
|
|
||
| assert(issues.dependencies['package.json']['@ladle/react']); | ||
| assert(issues.dependencies['package.json']['react']); | ||
| assert(issues.dependencies['package.json']['react-dom']); | ||
| assert(issues.devDependencies['package.json']['@types/react']); | ||
| assert(issues.devDependencies['package.json']['@types/react-dom']); | ||
| assert(issues.binaries['package.json']['ladle']); | ||
|
|
||
| assert.deepEqual(counters, { | ||
| ...baseCounters, | ||
| binaries: 1, | ||
| dependencies: 3, | ||
| devDependencies: 2, | ||
| processed: 0, | ||
| total: 0, | ||
| }); | ||
| }); |
Uh oh!
There was an error while loading. Please reload this page.