Skip to content

Commit

Permalink
removing hard coded references to tsc.config.json
Browse files Browse the repository at this point in the history
  • Loading branch information
David Turissini authored and David Turissini committed Dec 10, 2024
1 parent fe6533f commit 98c09a5
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 9 deletions.
8 changes: 5 additions & 3 deletions packages/router-cli/src/watch.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import path from 'node:path'
import chokidar from 'chokidar'
import { generator, getConfig } from '@tanstack/router-generator'
import { generator, getConfig, resolveConfigPath } from '@tanstack/router-generator'

export function watch(root: string) {
const configWatcher = chokidar.watch(path.resolve(root, 'tsr.config.json'))
const configPath = resolveConfigPath({
configDirectory: root,
});
const configWatcher = chokidar.watch(configPath)

let watcher = new chokidar.FSWatcher({})

Expand Down
10 changes: 9 additions & 1 deletion packages/router-generator/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,14 +67,22 @@ export const configSchema = z.object({

export type Config = z.infer<typeof configSchema>

type ResolveParams = {
configDirectory: string;
}

export function resolveConfigPath({ configDirectory }: ResolveParams) {
return path.resolve(configDirectory, 'tsr.config.json');
}

export function getConfig(
inlineConfig: Partial<Config> = {},
configDirectory?: string,
): Config {
if (configDirectory === undefined) {
configDirectory = process.cwd()
}
const configFilePathJson = path.resolve(configDirectory, 'tsr.config.json')
const configFilePathJson = resolveConfigPath({ configDirectory });
const exists = existsSync(configFilePathJson)

let config: Config
Expand Down
2 changes: 1 addition & 1 deletion packages/router-generator/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export { configSchema, getConfig } from './config'
export { configSchema, getConfig, resolveConfigPath } from './config'
export type { Config } from './config'

export {
Expand Down
1 change: 0 additions & 1 deletion packages/router-plugin/src/core/constants.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
export const CONFIG_FILE_NAME = 'tsr.config.json'
export const splitPrefix = 'tsr-split'
5 changes: 2 additions & 3 deletions packages/router-plugin/src/core/router-generator-plugin.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { isAbsolute, join, normalize, resolve } from 'node:path'
import { generator } from '@tanstack/router-generator'
import { generator, resolveConfigPath } from '@tanstack/router-generator'

import { getConfig } from './config'
import { CONFIG_FILE_NAME } from './constants'
import type { UnpluginFactory } from 'unplugin'
import type { Config } from './config'

Expand Down Expand Up @@ -49,7 +48,7 @@ export const unpluginRouterGeneratorFactory: UnpluginFactory<
) => {
const filePath = normalize(file)

if (filePath === join(ROOT, CONFIG_FILE_NAME)) {
if (filePath === resolveConfigPath({ configDirectory: ROOT })) {
userConfig = getConfig(options, ROOT)
return
}
Expand Down

0 comments on commit 98c09a5

Please sign in to comment.