Skip to content

Commit

Permalink
Add wrangler plugin (#572)
Browse files Browse the repository at this point in the history
* Add wrangler plugin

* Clean up wrangler plugin

* Add wrangler script

* Add wrangler pkg + bin

* Wrap up

---------

Co-authored-by: Lars Kappert <[email protected]>
  • Loading branch information
DaniFoldi and webpro authored Mar 26, 2024
1 parent 2a23fed commit 82c84be
Show file tree
Hide file tree
Showing 10 changed files with 71 additions and 0 deletions.
Empty file.

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

10 changes: 10 additions & 0 deletions packages/knip/fixtures/plugins/wrangler/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"name": "@fixtures/wrangler",
"version": "*",
"scripts": {
"dev": "wrangler dev"
},
"dependencies": {
"wrangler": "^3.37.0"
}
}
2 changes: 2 additions & 0 deletions packages/knip/fixtures/plugins/wrangler/wrangler.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
name = 'test'
main = 'worker-test-entry.ts'
4 changes: 4 additions & 0 deletions packages/knip/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -491,6 +491,10 @@
"title": "Wireit plugin configuration (https://github.com/webpro/knip/blob/main/src/plugins/wireit/README.md)",
"$ref": "#/definitions/plugin"
},
"wrangler": {
"title": "wrangler plugin configuration (https://github.com/webpro/knip/blob/main/src/plugins/wrangler/README.md)",
"$ref": "#/definitions/plugin"
},
"yorkie": {
"title": "yorkie plugin configuration (https://github.com/webpro/knip/blob/main/src/plugins/yorkie/README.md)",
"$ref": "#/definitions/plugin"
Expand Down
1 change: 1 addition & 0 deletions packages/knip/src/ConfigurationValidator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ const pluginsSchema = z.object({
vitest: pluginSchema,
webpack: pluginSchema,
wireit: pluginSchema,
wrangler: pluginSchema,
yorkie: pluginSchema,
});

Expand Down
1 change: 1 addition & 0 deletions packages/knip/src/plugins/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,5 @@ export { default as vitest } from './vitest/index.js';
export { default as vue } from './vue/index.js';
export { default as webpack } from './webpack/index.js';
export { default as wireit } from './wireit/index.js';
export { default as wrangler } from './wrangler/index.js';
export { default as yorkie } from './yorkie/index.js';
25 changes: 25 additions & 0 deletions packages/knip/src/plugins/wrangler/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { hasDependency } from '#p/util/plugin.js';
import type { IsPluginEnabled, Plugin, ResolveEntryPaths } from '#p/types/plugins.js';
import type { WranglerConfig } from './types.js';

// https://developers.cloudflare.com/workers/wrangler/configuration/

const title = 'Wrangler';

const enablers = ['wrangler'];

const isEnabled: IsPluginEnabled = ({ dependencies }) => hasDependency(dependencies, enablers);

const config = ['wrangler.{json,toml}'];

const resolveEntryPaths: ResolveEntryPaths<WranglerConfig> = async config => {
return config.main ? [config.main] : [];
};

export default {
title,
enablers,
isEnabled,
config,
resolveEntryPaths,
} satisfies Plugin;
3 changes: 3 additions & 0 deletions packages/knip/src/plugins/wrangler/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export type WranglerConfig = {
main?: string;
};
21 changes: 21 additions & 0 deletions packages/knip/test/plugins/wrangler.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import assert from 'node:assert/strict';
import test from 'node:test';
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/wrangler');

test('Find dependencies with the wrangler plugin', async () => {
const { counters } = await main({
...baseArguments,
cwd,
});

assert.deepEqual(counters, {
...baseCounters,
processed: 0,
total: 0,
});
});

0 comments on commit 82c84be

Please sign in to comment.