Skip to content

Commit 5fe4cb4

Browse files
committed
Plugin docs tweaks
1 parent 2bd03e0 commit 5fe4cb4

File tree

3 files changed

+20
-7
lines changed

3 files changed

+20
-7
lines changed

packages/docs/scripts/generate-plugin-docs.ts

+8-2
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,9 @@ for await (const dir of directories) {
4646
if (dir.isDirectory() && dir.name !== '_template') {
4747
const pluginName = dir.name;
4848
const pluginDir = path.join(pluginsDir, pluginName);
49-
const plugin: Plugin = (await import(path.join(pluginDir, 'index.ts'))).default;
49+
const mod = await import(path.join(pluginDir, 'index.ts'));
50+
const plugin: Plugin = mod.default;
51+
const docs: undefined | { entry?: string[]; production?: string[] } = mod.docs;
5052

5153
const { title, enablers, note, args, config, entry, production, project } = plugin;
5254

@@ -57,7 +59,10 @@ for await (const dir of directories) {
5759
const defaults: Record<string, string[]> = {};
5860
if (config && config.length > 0) defaults.config = config;
5961
if (entry && entry.length > 0) defaults.entry = entry;
62+
if (docs?.entry && docs.entry.length > 0) defaults.entry = [...(defaults.entry ?? []), ...docs.entry];
6063
if (production && production.length > 0) defaults.entry = [...(defaults.entry ?? []), ...production];
64+
if (docs?.production && docs.production.length > 0)
65+
defaults.entry = [...(defaults.entry ?? []), ...docs.production];
6166
if (project && project.length > 0) defaults.project = project;
6267

6368
const hasDefaultConfig = Object.values(defaults).some(v => v.length > 0);
@@ -84,11 +89,12 @@ for await (const dir of directories) {
8489
const defaultConfig = hasDefaultConfig
8590
? [
8691
u('heading', { depth: 2 }, [u('text', 'Default configuration')]),
87-
...parseFragment('If enabled, this configuration is added automatically:'),
92+
...parseFragment('If this plugin is enabled, the following configuration is added automatically:'),
8893
u('code', {
8994
lang: 'json', // TODO How to set attributes/properties/props properly?
9095
value: JSON.stringify({ [pluginName]: defaults }, null, 2),
9196
}),
97+
...parseFragment('Depending on local configuration, plugins may modify the defaults as shown.'),
9298
...parseFragment('Custom `config` or `entry` options override default values, they are not merged.'),
9399
...parseFragment(
94100
'See [Plugins](../../explanations/plugins) for more details about plugins and their `entry` and `config` options.'

packages/knip/src/plugins/expo/index.ts

+9-4
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,19 @@ const isEnabled: IsPluginEnabled = ({ dependencies }) => hasDependency(dependenc
1515

1616
const config = ['app.json', 'app.config.{ts,js}'];
1717

18+
const production = ['app/**/*.{js,jsx,ts,tsx}', 'src/app/**/*.{js,jsx,ts,tsx}'];
19+
20+
/** @public */
21+
export const docs = { production };
22+
1823
const resolveEntryPaths: ResolveEntryPaths<ExpoConfig> = async (expoConfig, { manifest }) => {
1924
const config = 'expo' in expoConfig ? expoConfig.expo : expoConfig;
2025

21-
let production: string[] = [];
26+
let patterns: string[] = [];
2227

2328
// https://docs.expo.dev/router/installation/#setup-entry-point
2429
if (manifest.main === 'expo-router/entry') {
25-
production = ['app/**/*.{js,jsx,ts,tsx}', 'src/app/**/*.{js,jsx,ts,tsx}'];
30+
patterns = [...production];
2631

2732
const normalizedPlugins =
2833
config.plugins?.map(plugin => (Array.isArray(plugin) ? plugin : ([plugin] as const))) ?? [];
@@ -32,12 +37,12 @@ const resolveEntryPaths: ResolveEntryPaths<ExpoConfig> = async (expoConfig, { ma
3237
const [, options] = expoRouterPlugin;
3338

3439
if (typeof options?.root === 'string') {
35-
production = [join(options.root, '**/*.{js,jsx,ts,tsx}')];
40+
patterns = [join(options.root, '**/*.{js,jsx,ts,tsx}')];
3641
}
3742
}
3843
}
3944

40-
return production.map(entry => toProductionEntry(entry));
45+
return patterns.map(entry => toProductionEntry(entry));
4146
};
4247

4348
const resolveConfig: ResolveConfig<ExpoConfig> = async (expoConfig, options) => getDependencies(expoConfig, options);

packages/knip/src/plugins/metro/index.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ const DEFAULT_EXTENSIONS = ['js', 'jsx', 'json', 'ts', 'tsx'];
2424

2525
const production = [`src/**/*.{${PLATFORMS.join(',')}}.{${DEFAULT_EXTENSIONS.join(',')}}`];
2626

27+
/** @public */
28+
export const docs = { production };
29+
2730
const resolveEntryPaths: ResolveEntryPaths<MetroConfig> = async config => {
2831
const platformEntryPatterns = compact(PLATFORMS.concat(config.resolver?.platforms ?? []));
2932
const sourceExts = config.resolver?.sourceExts ?? DEFAULT_EXTENSIONS;
@@ -56,7 +59,6 @@ export default {
5659
enablers,
5760
isEnabled,
5861
config,
59-
production,
6062
resolveEntryPaths,
6163
resolveConfig,
6264
} satisfies Plugin;

0 commit comments

Comments
 (0)