Skip to content

Commit 759503d

Browse files
authored
yarn.config.cjs support (#864)
1 parent 7950bf3 commit 759503d

File tree

9 files changed

+74
-0
lines changed

9 files changed

+74
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"name": "@fixtures/yarn",
3+
"version": "*",
4+
"devDependencies": {
5+
"@yarnpkg/types": "latest"
6+
}
7+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// https://yarnpkg.com/features/constraints
2+
3+
/** @type {import('@yarnpkg/types')} */
4+
const { defineConfig } = require('@yarnpkg/types');
5+
6+
module.exports = defineConfig({
7+
async constraints({Yarn}) {
8+
// `Yarn` is now well-typed ✨
9+
},
10+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# This file is generated by running "yarn install" inside your project.
2+
# Manual changes might be lost - proceed with caution!
3+
4+
__metadata:
5+
version: 8
6+
cacheKey: 10

packages/knip/schema.json

+4
Original file line numberDiff line numberDiff line change
@@ -612,6 +612,10 @@
612612
"title": "xo plugin configuration (https://knip.dev/reference/plugins/xo)",
613613
"$ref": "#/definitions/plugin"
614614
},
615+
"yarn": {
616+
"title": "yarn plugin configuration (https://knip.dev/reference/plugins/yarn)",
617+
"$ref": "#/definitions/plugin"
618+
},
615619
"yorkie": {
616620
"title": "yorkie plugin configuration (https://knip.dev/reference/plugins/yorkie)",
617621
"$ref": "#/definitions/plugin"

packages/knip/src/plugins/index.ts

+2
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ import { default as webpack } from './webpack/index.js';
8484
import { default as wireit } from './wireit/index.js';
8585
import { default as wrangler } from './wrangler/index.js';
8686
import { default as xo } from './xo/index.js';
87+
import { default as yarn } from './yarn/index.js';
8788
import { default as yorkie } from './yorkie/index.js';
8889

8990
export const Plugins = {
@@ -172,5 +173,6 @@ export const Plugins = {
172173
wireit,
173174
wrangler,
174175
xo,
176+
yarn,
175177
yorkie,
176178
};
+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import type { IsPluginEnabled, Plugin } from '../../types/config.js';
2+
import { _firstGlob } from '../../util/glob.js';
3+
4+
// https://yarnpkg.com/features/constraints
5+
6+
const title = 'Yarn';
7+
8+
const enablers = 'This plugin is enabled when a `yarn.lock` file is found in the root folder.';
9+
10+
const isEnabled: IsPluginEnabled = async ({ cwd }) => Boolean(await _firstGlob({ cwd, patterns: ['yarn.lock'] }));
11+
12+
const entry: string[] = ['yarn.config.cjs'];
13+
14+
export default {
15+
title,
16+
enablers,
17+
isEnabled,
18+
entry,
19+
} satisfies Plugin;

packages/knip/src/schema/plugins.ts

+1
Original file line numberDiff line numberDiff line change
@@ -98,5 +98,6 @@ export const pluginsSchema = z.object({
9898
wireit: pluginSchema,
9999
wrangler: pluginSchema,
100100
xo: pluginSchema,
101+
yarn: pluginSchema,
101102
yorkie: pluginSchema,
102103
});

packages/knip/src/types/PluginNames.ts

+2
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ export type PluginName =
8585
| 'wireit'
8686
| 'wrangler'
8787
| 'xo'
88+
| 'yarn'
8889
| 'yorkie';
8990

9091
export const pluginNames = [
@@ -173,5 +174,6 @@ export const pluginNames = [
173174
'wireit',
174175
'wrangler',
175176
'xo',
177+
'yarn',
176178
'yorkie',
177179
] as const;
+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import { test } from 'bun:test';
2+
import assert from 'node:assert/strict';
3+
import { main } from '../../src/index.js';
4+
import { resolve } from '../../src/util/path.js';
5+
import baseArguments from '../helpers/baseArguments.js';
6+
import baseCounters from '../helpers/baseCounters.js';
7+
8+
const cwd = resolve('fixtures/plugins/yarn');
9+
10+
test('Find dependencies with the yarn plugin', async () => {
11+
const { issues, counters } = await main({
12+
...baseArguments,
13+
cwd,
14+
});
15+
16+
assert(issues.files.size === 0);
17+
18+
assert.deepEqual(counters, {
19+
...baseCounters,
20+
processed: 1,
21+
total: 1,
22+
});
23+
});

0 commit comments

Comments
 (0)