-
-
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.
- Loading branch information
Showing
21 changed files
with
139 additions
and
0 deletions.
There are no files selected for viewing
Empty file.
16 changes: 16 additions & 0 deletions
16
packages/knip/fixtures/plugins/react-cosmos/cosmos.config.json
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,16 @@ | ||
{ | ||
"$schema": "http://json.schemastore.org/cosmos-config", | ||
"plugins": [ | ||
"react-cosmos-plugin-open-fixture", | ||
"react-cosmos-plugin-boolean-input", | ||
"react-cosmos-plugin-webpack", | ||
"./src/my-cosmos-plugin.ts" | ||
], | ||
"webpack": { | ||
"configPath": "./webpack.config.cosmos.js", | ||
"overridePath": "./webpack.override.js" | ||
}, | ||
"vite": { | ||
"configPath": "./tools/vite.config.js" | ||
} | ||
} |
Empty file.
6 changes: 6 additions & 0 deletions
6
packages/knip/fixtures/plugins/react-cosmos/node_modules/react-cosmos-native/package.json
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Empty file.
4 changes: 4 additions & 0 deletions
4
...fixtures/plugins/react-cosmos/node_modules/react-cosmos-plugin-boolean-input/package.json
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Empty file.
4 changes: 4 additions & 0 deletions
4
.../fixtures/plugins/react-cosmos/node_modules/react-cosmos-plugin-open-fixture/package.json
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Empty file.
4 changes: 4 additions & 0 deletions
4
.../knip/fixtures/plugins/react-cosmos/node_modules/react-cosmos-plugin-webpack/package.json
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Empty file.
7 changes: 7 additions & 0 deletions
7
packages/knip/fixtures/plugins/react-cosmos/node_modules/react-cosmos/package.json
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
{ | ||
"name": "@fixtures/react-cosmos", | ||
"version": "*", | ||
"scripts": { | ||
"cosmos": "cosmos", | ||
"cosmos-export": "cosmos-export", | ||
"cosmos-native": "cosmos-native" | ||
}, | ||
"devDependencies": { | ||
"react-cosmos": "*", | ||
"react-cosmos-native": "*", | ||
"react-cosmos-plugin-boolean-input": "*", | ||
"react-cosmos-plugin-open-fixture": "*", | ||
"react-cosmos-plugin-webpack": "*" | ||
} | ||
} |
1 change: 1 addition & 0 deletions
1
packages/knip/fixtures/plugins/react-cosmos/src/cosmos.decorator.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 @@ | ||
export default function MyDecorator() {} |
Empty file.
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,49 @@ | ||
import type { EnablerPatterns } from '#p/types/config.js'; | ||
import type { IsPluginEnabled, Plugin, ResolveConfig, ResolveEntryPaths } from '#p/types/plugins.js'; | ||
import { hasDependency, resolveEntry } from '#p/util/plugin.js'; | ||
import { join } from '../../util/path.js'; | ||
import { toEntryPattern } from '../../util/protocols.js'; | ||
import type { ReactCosmosConfig } from './types.js'; | ||
|
||
// https://reactcosmos.org/docs | ||
|
||
const title = 'React Cosmos'; | ||
|
||
const enablers: EnablerPatterns = ['react-cosmos']; | ||
|
||
const isEnabled: IsPluginEnabled = ({ dependencies }) => hasDependency(dependencies, enablers); | ||
|
||
const config = ['cosmos.config.json']; | ||
|
||
const ext = '{js,jsx,ts,tsx,md,mdx}'; | ||
|
||
const fixtureEntry = [`**/*.fixture.${ext}`, `__fixtures__/**/*.${ext}`, `**/fixture.${ext}`]; | ||
|
||
const decoratorEntry = ['**/cosmos.decorator.{jsx,tsx}']; | ||
|
||
const entry = [...fixtureEntry, ...decoratorEntry]; | ||
|
||
const resolveEntryPaths: ResolveEntryPaths<ReactCosmosConfig> = async localConfig => { | ||
const { fixturesDir, fixtureFileSuffix } = localConfig; | ||
const entries = [ | ||
join(fixturesDir ?? '__fixtures__', `**/*.${ext}`), | ||
join(fixturesDir ?? '', `**/*.${fixtureFileSuffix ?? 'fixture'}.${ext}`), | ||
join(fixturesDir ?? '', `**/${fixtureFileSuffix ?? 'fixture'}.${ext}`), | ||
]; | ||
return [...entries, ...decoratorEntry].map(toEntryPattern); | ||
}; | ||
|
||
const resolveConfig: ResolveConfig<ReactCosmosConfig> = async (localConfig, options) => { | ||
const dependencies = (localConfig?.plugins ?? []).map(specifier => resolveEntry(options, specifier)); | ||
return [...dependencies]; | ||
}; | ||
|
||
export default { | ||
title, | ||
enablers, | ||
isEnabled, | ||
config, | ||
entry, | ||
resolveConfig, | ||
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,5 @@ | ||
export type ReactCosmosConfig = { | ||
plugins?: string[]; | ||
fixtureFileSuffix?: string; | ||
fixturesDir?: 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,21 @@ | ||
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/react-cosmos'); | ||
|
||
test('Find dependencies with the react-cosmos plugin', async () => { | ||
const { counters } = await main({ | ||
...baseArguments, | ||
cwd, | ||
}); | ||
|
||
assert.deepEqual(counters, { | ||
...baseCounters, | ||
processed: 2, | ||
total: 2, | ||
}); | ||
}); |