-
-
Notifications
You must be signed in to change notification settings - Fork 177
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
99 additions
and
0 deletions.
There are no files selected for viewing
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,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": "*" | ||
} | ||
} |
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,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']; | ||
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; |
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,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, | ||
}); | ||
}); |