-
-
Notifications
You must be signed in to change notification settings - Fork 202
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: Lars Kappert <lars@webpro.nl>
- Loading branch information
Showing
16 changed files
with
225 additions
and
4 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import { type GlobalProvider } from "@ladle/react"; | ||
import React from "react"; | ||
|
||
// For details see https://ladle.dev/docs/providers | ||
export const Provider: GlobalProvider = ({ children }) => <div>{children}</div>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
// For details see https://ladle.dev/docs/config | ||
/** @type {import('@ladle/react').UserConfig} */ | ||
export default { | ||
stories: "app/**/*.stories.{tsx,mdx}", | ||
viteConfig: "./.ladle/vite.config.ts", | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { defineConfig } from "vite"; | ||
|
||
export default defineConfig({ | ||
server: { | ||
open: false, | ||
}, | ||
}); |
39 changes: 39 additions & 0 deletions
39
packages/knip/fixtures/plugins/ladle/app/basic.stories.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
export const Hello = () => <h2>Simple Story</h2>; | ||
|
||
export const Responsive = () => { | ||
return ( | ||
<> | ||
<div | ||
style={{ | ||
width: '100', | ||
background: '#000', | ||
color: '#FFF', | ||
padding: '32px 32px', | ||
border: '1px solid black', | ||
fontFamily: 'arial', | ||
fontSize: 28, | ||
}} | ||
> | ||
Header | ||
</div> | ||
<button | ||
style={{ | ||
padding: '16px 102px', | ||
fontFamily: 'arial', | ||
fontSize: 22, | ||
margin: 32, | ||
borderRadius: 8, | ||
color: '#174291', | ||
border: '2px solid #174291', | ||
background: '#FFF', | ||
}} | ||
> | ||
Ladle v4 | ||
</button> | ||
</> | ||
); | ||
}; | ||
Responsive.meta = { | ||
width: 'xsmall', | ||
}; | ||
|
37 changes: 37 additions & 0 deletions
37
packages/knip/fixtures/plugins/ladle/app/control.stories.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import type { Story } from "@ladle/react"; | ||
|
||
export const Controls: Story<{ | ||
label: string; | ||
disabled: boolean; | ||
count: number; | ||
colors: string[]; | ||
variant: string; | ||
size: string; | ||
}> = ({ count, disabled, label, colors, variant, size }) => ( | ||
<> | ||
<p>Count: {count}</p> | ||
<p>Disabled: {disabled ? "yes" : "no"}</p> | ||
<p>Label: {label}</p> | ||
<p>Colors: {colors.join(",")}</p> | ||
<p>Variant: {variant}</p> | ||
<p>Size: {size}</p> | ||
</> | ||
); | ||
|
||
Controls.args = { | ||
label: "Hello world", | ||
disabled: false, | ||
count: 2, | ||
colors: ["Red", "Blue"], | ||
}; | ||
Controls.argTypes = { | ||
variant: { | ||
options: ["primary", "secondary"], | ||
control: { type: "radio" }, | ||
defaultValue: "primary", | ||
}, | ||
size: { | ||
options: ["small", "medium", "big", "huuuuge"], | ||
control: { type: "select" }, | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
{ | ||
"name": "@fixtures/ladle", | ||
"type": "module", | ||
"scripts": { | ||
"dev": "ladle serve --port 4123", | ||
"build": "ladle build" | ||
}, | ||
"dependencies": { | ||
"@ladle/react": "*", | ||
"react": "*", | ||
"react-dom": "*" | ||
}, | ||
"devDependencies": { | ||
"@types/node": "*", | ||
"@types/react": "*", | ||
"@types/react-dom": "*", | ||
"typescript": "*" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
{ | ||
"compilerOptions": { | ||
"target": "ESNext", | ||
"useDefineForClassFields": true, | ||
"lib": ["DOM", "DOM.Iterable", "ESNext"], | ||
"allowJs": false, | ||
"skipLibCheck": false, | ||
"esModuleInterop": false, | ||
"allowSyntheticDefaultImports": true, | ||
"strict": true, | ||
"forceConsistentCasingInFileNames": true, | ||
"module": "ESNext", | ||
"moduleResolution": "node", | ||
"resolveJsonModule": true, | ||
"isolatedModules": true, | ||
"noEmit": true, | ||
"jsx": "react-jsx" | ||
}, | ||
"include": ["src"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import type { EnablerPatterns } from '#p/types/config.js'; | ||
import type { IsPluginEnabled, Plugin, ResolveConfig, ResolveEntryPaths } from '#p/types/plugins.js'; | ||
import { toAbsolute } from '#p/util/path.js'; | ||
import { hasDependency, load } from '#p/util/plugin.js'; | ||
import { toEntryPattern } from '../../util/protocols.js'; | ||
import { resolveConfig as resolveVitestConfig } from '../vitest/index.js'; | ||
import type { LadleConfig } from './types.js'; | ||
|
||
// https://ladle.dev/docs/config | ||
|
||
const title = 'Ladle'; | ||
|
||
const enablers: EnablerPatterns = ['@ladle/react']; | ||
|
||
const isEnabled: IsPluginEnabled = ({ dependencies }) => hasDependency(dependencies, enablers); | ||
|
||
const config = ['.ladle/config.{mjs,js,ts}']; | ||
|
||
const stories = ['src/**/*.stories.{js,jsx,ts,tsx,mdx}']; | ||
const restEntry = ['.ladle/components.{js,jsx,ts,tsx}']; | ||
const entry = [...restEntry, ...stories]; | ||
|
||
const project = ['.ladle/**/*.{js,jsx,ts,tsx}']; | ||
|
||
const resolveEntryPaths: ResolveEntryPaths<LadleConfig> = (localConfig, options) => { | ||
const localStories = typeof localConfig.stories === 'string' ? [localConfig.stories] : localConfig.stories; | ||
const viteConfig = localConfig.viteConfig ? [toAbsolute(localConfig.viteConfig, options.cwd)] : []; | ||
const patterns = [...restEntry, ...(localStories ?? stories), ...viteConfig]; | ||
return patterns.map(toEntryPattern); | ||
}; | ||
|
||
const resolveConfig: ResolveConfig<LadleConfig> = async (localConfig, options) => { | ||
if (localConfig.viteConfig) { | ||
const viteConfigPath = toAbsolute(localConfig.viteConfig, options.cwd); | ||
const viteConfig = await load(viteConfigPath); | ||
return resolveVitestConfig(viteConfig, options); | ||
} | ||
return []; | ||
}; | ||
|
||
export default { | ||
title, | ||
enablers, | ||
isEnabled, | ||
config, | ||
entry, | ||
project, | ||
resolveEntryPaths, | ||
resolveConfig, | ||
} satisfies Plugin; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
export type LadleConfig = { | ||
stories?: string | string[]; | ||
viteConfig?: string; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
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']['react-dom']); | ||
assert(issues.devDependencies['package.json']['@types/react-dom']); | ||
assert(issues.binaries['package.json']['ladle']); | ||
assert(issues.unlisted['.ladle/vite.config.ts']['vite']); | ||
|
||
assert.deepEqual(counters, { | ||
...baseCounters, | ||
binaries: 1, | ||
dependencies: 1, | ||
devDependencies: 1, | ||
unlisted: 1, | ||
processed: 5, | ||
total: 5, | ||
}); | ||
}); |