Visitar URL original
Improve react-router `appDir` + fix glob escaper · webpro-nl/knip@f993591 · GitHub
Skip to content

Commit f993591

Browse files
committed
Improve react-router appDir + fix glob escaper
1 parent b9dc80e commit f993591

4 files changed

Lines changed: 8 additions & 5 deletions

File tree

‎packages/knip/fixtures/plugins/react-router/app/routes.ts‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,7 @@ export default [
1313
{
1414
file: 'routes/$.tsx',
1515
},
16+
{
17+
file: 'routes/main+/nested+/_index.tsx',
18+
},
1619
];

‎packages/knip/fixtures/plugins/react-router/app/routes/main+/nested+/_index.tsx‎

Whitespace-only changes.

‎packages/knip/src/plugins/react-router/index.ts‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import os from 'node:os';
33
import type { IsPluginEnabled, Plugin, ResolveConfig } from '../../types/config.js';
44
import { _glob } from '../../util/glob.js';
55
import { toEntry, toProductionDependency, toProductionEntry } from '../../util/input.js';
6-
import { join } from '../../util/path.js';
6+
import { isAbsolute, join, toAbsolute } from '../../util/path.js';
77
import { hasDependency, load } from '../../util/plugin.js';
88
import vite from '../vite/index.js';
99
import type { PluginConfig, RouteConfigEntry } from './types.js';
@@ -23,7 +23,7 @@ const config = ['react-router.config.{js,ts}', ...viteConfig];
2323
const resolveConfig: ResolveConfig<PluginConfig> = async (localConfig, options) => {
2424
const { configFileDir } = options;
2525
const appDirectory = localConfig.appDirectory ?? 'app';
26-
const appDir = join(configFileDir, appDirectory);
26+
const appDir = toAbsolute(appDirectory, configFileDir);
2727

2828
// If using flatRoutes from @react-router/fs-routes it will throw an error if this variable is not defined
2929
// @ts-expect-error
@@ -51,7 +51,7 @@ const resolveConfig: ResolveConfig<PluginConfig> = async (localConfig, options)
5151
// See:
5252
// - https://reactrouter.com/how-to/file-route-conventions#optional-segments
5353
// - https://www.npmjs.com/package/fast-glob#advanced-syntax
54-
.map(route => (isWindows ? route : route.replace(/[\^*+?()[\]]/g, '\\$&')));
54+
.map(route => (isWindows ? route : route.replace(/[\^*?()[\]]/g, '\\$&')));
5555

5656
const resolved = [
5757
// routes.{ts,js} is only used as input to the bundler build system

‎packages/knip/test/plugins/react-router.test.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ test('Find dependencies with the react-router plugin', async () => {
1515

1616
assert.deepEqual(counters, {
1717
...baseCounters,
18-
processed: 9,
19-
total: 9,
18+
processed: 10,
19+
total: 10,
2020
// There is a bug with routes that include () on Windows so they will not be found there, revert when
2121
// the bug is fixed
2222
files: isWindows ? 1 : 0,

0 commit comments

Comments
 (0)