Skip to content

Commit

Permalink
Refactor binary resolver & referenced dependency handling
Browse files Browse the repository at this point in the history
  • Loading branch information
webpro committed Oct 15, 2024
1 parent e31cb49 commit f1349c2
Show file tree
Hide file tree
Showing 229 changed files with 2,712 additions and 1,506 deletions.
5 changes: 2 additions & 3 deletions .github/workflows/integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,5 @@ jobs:
sparse-checkout: ${{ matrix.project.sparse-checkout }}

- name: Run Knip in ${{ matrix.project.repo }}
run: |
cd ${{ matrix.project.name }}
${{ matrix.project.commands }}
working-directory: ${{ matrix.project.name }}
run: ${{ matrix.project.commands }}
Binary file modified bun.lockb
Binary file not shown.
31 changes: 21 additions & 10 deletions packages/docs/scripts/generate-plugin-docs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import remarkStringify from 'remark-stringify';
import { unified } from 'unified';
import type { Node } from 'unist';
import { u } from 'unist-builder';
import type { Plugin } from '../../knip/src/types/plugins.js';
import type { Plugin } from '../../knip/src/types/config.js';

const rootDir = path.join(path.dirname(fileURLToPath(import.meta.url)), '..');
const referenceDocsDir = path.join(rootDir, 'src/content/docs/reference');
Expand Down Expand Up @@ -47,7 +47,7 @@ for await (const dir of directories) {
const pluginDir = path.join(pluginsDir, pluginName);
const plugin: Plugin = (await import(path.join(pluginDir, 'index.ts'))).default;

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

plugins.push([title, pluginName]);

Expand All @@ -59,6 +59,8 @@ for await (const dir of directories) {
if (production && production.length > 0) defaults.entry = [...(defaults.entry ?? []), ...production];
if (project && project.length > 0) defaults.project = project;

const hasDefaultConfig = Object.values(defaults).some(v => v.length > 0);

const en =
Array.isArray(enablers) && enablers.length > 0
? [
Expand All @@ -78,19 +80,28 @@ for await (const dir of directories) {

const n = note ? [u('heading', { depth: 2 }, [u('text', 'Note')]), ...parseFragment(note)] : [];

const def = hasDefaultConfig
? [
u('heading', { depth: 2 }, [u('text', 'Default configuration')]),
...parseFragment('This configuration is added automatically if the plugin is enabled:'),
u('code', {
lang: 'json title="knip.json"', // TODO How to set attributes/properties/props properly?
value: JSON.stringify({ [pluginName]: defaults }, null, 2),
}),
...parseFragment('Your custom `config` or `entry` options override default values, they are not merged.'),
...parseFragment('See [Plugins](../../explanations/plugins) for more details.'),
]
: [];

const argsText = args ? parseFragment('## Shell commands\n\nThis plugin enables argument parsing') : [];

const tree = u('root', [
frontmatter,
u('heading', { depth: 2 }, [u('text', 'Enabled')]),
...en,
...n,
u('heading', { depth: 2 }, [u('text', 'Default configuration')]),
...parseFragment('This configuration is added automatically if the plugin is enabled:'),
u('code', {
lang: 'json title="knip.json"', // TODO How to set attributes/properties/props properly?
value: JSON.stringify({ [pluginName]: defaults }, null, 2),
}),
...parseFragment('Your custom `config` or `entry` options override default values, they are not merged.'),
...parseFragment('See [Plugins](../../explanations/plugins) for more details.'),
...def,
...argsText,
]);

console.log(`Writing ${pluginName} docs to plugins/${pluginName}.md`);
Expand Down
4 changes: 2 additions & 2 deletions packages/docs/src/content/docs/guides/writing-a-plugin.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,9 @@ configuration object.
Here's the full source code of the `nyc` plugin:

```ts
import { hasDependency } from '#p/util/plugin.js';
import { hasDependency } from '../../util/plugin.js';
import type { NycConfig } from './types.js';
import type { ResolveConfig, IsPluginEnabled } from '#p/types/plugins.js';
import type { ResolveConfig, IsPluginEnabled } from '../../types/config.js';

const title = 'nyc';

Expand Down
1 change: 1 addition & 0 deletions packages/knip/fixtures/npm-scripts/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
dist
Empty file.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 5 additions & 7 deletions packages/knip/fixtures/npm-scripts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@
"ignore-artifact": "node dist/ignore.js",
"start": "package",
"go": "runnable",
"go-live": "deploy -r repo_name"
"go-live": "deploy -r repo_name",
"tsup": "tsup -c tsup.cool.json",
"tsuppy": "tsup --config tsup.cool.json"
},
"dependencies": {
"express": "*",
Expand All @@ -24,6 +26,7 @@
"devDependencies": {
"pm2": "*",
"nx": "*",
"tsup": "*",
"unused": "*",
"eslint": "8.28.0",
"eslint-v6": "npm:[email protected]",
Expand All @@ -34,11 +37,6 @@
},
"knip": {
"ignore": "ignore.js",
"ignoreBinaries": [
"rm",
"bash",
"deploy",
"eslint"
]
"ignoreBinaries": ["rm", "bash", "deploy", "eslint"]
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
name: CI

on: push

jobs:
stylelint:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Run stylelint check
run: yarn stylelint
working-directory: packages/app
Empty file.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Empty file.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Empty file.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"name": "@fixtures/github-actions-workspaces",
"workspaces": ["packages/*"],
"scripts": {
"hello-app": "yarn run --cwd packages/app goodbye"
},
"dependencies": {
"hello": "*"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"name": "@github-actions-workspaces/app",
"scripts": {
"stylelint": "stylelint",
"hello-world": "yarn run --top-level hello"
},
"devDependencies": {
"stylelint": "*",
"goodbye": "*"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"name": "@github-actions-workspaces/lib"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: CI

on: push

jobs:
job1:
runs-on: ubuntu-latest
name: work

steps:
- uses: actions/checkout@d632683dd7b4114ad314bca15554477dd762a938

- run: node scripts/no-working-dir

job2:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@4
with:
path: some-dir

- run: node scripts/from-working-dir-with-path
working-directory: ./some-dir

job3:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@4

- run: node from-working-dir
working-directory: scripts
Empty file.
Empty file.
Empty file.
4 changes: 4 additions & 0 deletions packages/knip/fixtures/plugins/node/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"name": "@fixtures/node",
"version": "*"
}
4 changes: 4 additions & 0 deletions packages/knip/fixtures/plugins/nodemon/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"name": "@fixtures/nodemon",
"version": "*"
}
Empty file.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 12 additions & 1 deletion packages/knip/fixtures/plugins/tsup/package.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,15 @@
{
"name": "@fixtures/tsup",
"version": "*"
"version": "*",
"devDependencies": {
"tsup": "*"
},
"scripts": {
"build": "tsup",
"build-3": "tsup --config tsup.config-3.ts",
"build-4": "tsup -c tsup.config-4.ts"
},
"tsup": {
"entry": ["entry-5.ts"]
}
}
5 changes: 5 additions & 0 deletions packages/knip/fixtures/plugins/tsup/tsup.config-3.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { defineConfig } from 'tsup';

export default defineConfig({
entry: ['entry-3.ts'],
});
5 changes: 5 additions & 0 deletions packages/knip/fixtures/plugins/tsup/tsup.config-4.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { defineConfig } from 'tsup';

export default defineConfig({
entry: ['entry-4.ts'],
});
3 changes: 3 additions & 0 deletions packages/knip/fixtures/plugins/tsup/tsup.config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"entry": ["entry-1.ts"]
}
5 changes: 5 additions & 0 deletions packages/knip/fixtures/plugins/tsup/tsup.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { defineConfig } from 'tsup';

export default defineConfig({
entry: ['entry-2.ts'],
});
7 changes: 7 additions & 0 deletions packages/knip/fixtures/plugins/typescript/package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
{
"name": "@fixtures/typescript",
"scripts": {
"build-base": "tsc -p tsconfig.base.json",
"build-ext": "tsc -p tsconfig.ext.json",
"build-preact": "tsc -p tsconfig.jsx-import-source-preact.json",
"build-react": "tsc -p tsconfig.jsx-import-source-react.json",
"build-jsx": "tsc -p tsconfig.jsx-preserve.json"
},
"devDependencies": {
"typescript": "*"
}
Expand Down
9 changes: 9 additions & 0 deletions packages/knip/fixtures/plugins/vitest6/config/fiep.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { defineConfig } from 'vitest/config';

export default defineConfig({
test: {
root: '../tests',
include: ['*.test.ts'],
setupFiles: ['./setup.ts'],
},
});

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Empty file.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions packages/knip/fixtures/plugins/vitest6/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"name": "@fixtures/vitest6",
"scripts": {
"test": "vitest -c config/fiep.ts"
},
"devDependencies": {
"vitest": "*"
}
}
5 changes: 5 additions & 0 deletions packages/knip/fixtures/plugins/vitest6/src/unused.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { expect, test } from 'vitest';

test('Unit A', () => {
expect(true).toBe(!false);
});
5 changes: 5 additions & 0 deletions packages/knip/fixtures/plugins/vitest6/tests/adder.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { expect, test } from 'vitest';

test('Unit A', () => {
expect(true).toBe(!false);
});
1 change: 1 addition & 0 deletions packages/knip/fixtures/plugins/vitest6/tests/setup.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default {};
Empty file.
Empty file.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { defineConfig } from 'vitest/config';

export default defineConfig({
test: {
root: '..',
include: ['**/*.vitest.ts'],
environment: 'node',
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { defineProject } from 'vitest/config';

export default defineProject({
test: {
root: '..',
include: ['**/*.vitest.ts'],
environment: 'jsdom',
},
Expand Down
7 changes: 2 additions & 5 deletions packages/knip/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,6 @@
},
"type": "module",
"types": "./dist/index.d.ts",
"imports": {
"#p/*.ts": "./src/*.ts",
"#p/*.js": "./dist/*.js"
},
"scripts": {
"knip": "node ./dist/cli.js --directory ../..",
"knip:production": "node ./dist/cli.js --directory ../.. --production --strict",
Expand All @@ -52,7 +48,8 @@
"qa": "bun lint && bun run build && bun knip && bun knip:production && bun run test",
"release": "release-it",
"create-plugin": "bun ./scripts/create-new-plugin.ts",
"postcreate-plugin": "biome format --write schema.json schema-jsonc.json src/ConfigurationValidator.ts"
"postcreate-plugin": "biome format --write schema.json schema-jsonc.json src/ConfigurationValidator.ts",
"generate-plugin-types": "bun ./scripts/generate-plugin-types.ts"
},
"files": [
"dist",
Expand Down
Loading

0 comments on commit f1349c2

Please sign in to comment.