Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,20 @@ import type { PickerRef, SharedTimeProps } from './interface';
import RangePicker, { type RangePickerProps } from './PickerInput/RangePicker';
import Picker, { type BasePickerProps, type PickerProps } from './PickerInput/SinglePicker';
import PickerPanel, { type BasePickerPanelProps, type PickerPanelProps } from './PickerPanel';
import momentGenerateConfig from './generate/moment';
import dayjsGenerateConfig from './generate/dayjs';
import dateFnsGenerateConfig from './generate/dateFns';
import luxonGenerateConfig from './generate/luxon';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

To improve modularity and keep the main entry point (src/index.tsx) cleaner, consider creating a barrel file (src/generate/index.ts) to aggregate all generateConfig exports. This centralizes the generator configurations and simplifies imports.

You would first create src/generate/index.ts with the following content:

export { default as dateFnsGenerateConfig } from './dateFns';
export { default as dayjsGenerateConfig } from './dayjs';
export { default as luxonGenerateConfig } from './luxon';
export { default as momentGenerateConfig } from './moment';

Then, you can simplify the imports in this file as suggested.

import {
  dateFnsGenerateConfig,
  dayjsGenerateConfig,
  luxonGenerateConfig,
  momentGenerateConfig,
} from './generate';


export { Picker, RangePicker, PickerPanel };
export {
Picker,
RangePicker,
PickerPanel,
momentGenerateConfig,
dayjsGenerateConfig,
dateFnsGenerateConfig,
luxonGenerateConfig,
};
Comment on lines 36 to 44
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

For consistency and better readability, it's good practice to keep exports sorted alphabetically. This makes it easier to locate specific exports as the list grows.

export {
  dateFnsGenerateConfig,
  dayjsGenerateConfig,
  luxonGenerateConfig,
  momentGenerateConfig,
  Picker,
  PickerPanel,
  RangePicker,
};

Comment on lines 36 to 44
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

🧩 Analysis chain

导出结构正确,解决了 pnpm 深层导入问题。考虑同时导出 GenerateConfig 类型。

这些导出正确地解决了 issue #949 中提到的 pnpm 模块解析问题。将 generateConfig 助手函数作为公共 API 的一部分导出,使用户可以使用稳定的顶级导入:import { momentGenerateConfig } from '@rc-component/picker';,而不是容易出错的深层导入。

但是,TypeScript 用户可能还需要 GenerateConfig 类型来正确地对他们的代码进行类型检查。建议验证 GenerateConfig 类型是否已经导出,如果没有,考虑在类型导出块(第 48-56 行)中添加它。

运行以下脚本检查 GenerateConfig 类型是否已导出:


🏁 Script executed:

#!/bin/bash
# 描述:检查 GenerateConfig 类型定义和导出

# 查找 GenerateConfig 类型定义
echo "=== 查找 GenerateConfig 类型定义 ==="
rg -n "type\s+GenerateConfig|interface\s+GenerateConfig" --type ts --type tsx

# 检查当前的类型导出
echo -e "\n=== 检查 src/index.tsx 中的类型导出 ==="
cat src/index.tsx | sed -n '/export type {/,/};/p'

# 搜索 GenerateConfig 在导出语句中的使用
echo -e "\n=== 检查 GenerateConfig 是否已被导出 ==="
rg -n "export.*GenerateConfig" src/index.tsx

Length of output: 272


🏁 Script executed:

#!/bin/bash
# 重新搜索 GenerateConfig 类型定义,使用正确的文件类型

echo "=== 搜索 GenerateConfig 类型定义 ==="
rg -n "type\s+GenerateConfig|interface\s+GenerateConfig" --type typescript

echo -e "\n=== 检查 GenerateConfig 在源代码中的使用 ==="
rg -n "GenerateConfig" --type typescript -B2 -A2

echo -e "\n=== 查看 src/index.tsx 的完整导出 ==="
cat src/index.tsx | tail -20

Length of output: 486


🏁 Script executed:

#!/bin/bash
# 搜索 GenerateConfig 类型定义,不使用 --type 标志

echo "=== 查找包含 GenerateConfig 的文件 ==="
fd -e ts -e tsx | head -30 | xargs grep -l "GenerateConfig" 2>/dev/null | head -10

echo -e "\n=== 在找到的文件中搜索 GenerateConfig 定义 ==="
fd -e ts -e tsx -x grep -n "type.*GenerateConfig\|interface.*GenerateConfig\|export.*GenerateConfig" {} \; 2>/dev/null | head -20

echo -e "\n=== 查找 generateConfig 函数的定义 ==="
fd -e ts -e tsx -x grep -n "GenerateConfig\|generateConfig" {} \; 2>/dev/null | grep -E "(export|function|const).*[Gg]enerate" | head -20

Length of output: 2789


🏁 Script executed:

#!/bin/bash
# 查找 GenerateConfig 的导出位置

echo "=== 查找 GenerateConfig 的定义文件 ==="
find src -name "*.ts" -o -name "*.tsx" | xargs grep -l "export type GenerateConfig" 2>/dev/null

echo -e "\n=== 查看 GenerateConfig 的完整定义 ==="
find src -name "*.ts" -o -name "*.tsx" | xargs grep -A5 "export type GenerateConfig" 2>/dev/null | head -20

Length of output: 442


导出结构正确,建议添加 GenerateConfig 类型导出。

这些导出正确地解决了 issue #949 中提到的 pnpm 模块解析问题。将 generateConfig 助手函数作为公共 API 的一部分导出,使用户可以使用稳定的顶级导入:import { momentGenerateConfig } from '@rc-component/picker';,而不是容易出错的深层导入。

验证确认 GenerateConfig 类型定义于 src/generate/index.ts 中,但尚未在 src/index.tsx 的类型导出块中导出。建议在第 48-56 行的类型导出中添加 GenerateConfig,以便 TypeScript 用户能够正确地为使用这些 generateConfig 对象的代码进行类型注解。

🤖 Prompt for AI Agents
In src/index.tsx around lines 39 to 47 (and the type export block at ~48-56),
the runtime exports include the various generateConfig helpers but the
GenerateConfig TypeScript type from src/generate/index.ts is not re-exported;
update the type export block to include GenerateConfig by importing/
re-exporting it from src/generate/index.ts (add GenerateConfig to the named type
exports) so consumers can type-annotate generateConfig objects via top-level
imports.

export type {
RangePickerProps,
PickerProps,
Expand Down