Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: remove special handling for rntaro's environment configuration and component #2934

Merged
merged 1 commit into from
Jan 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
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
130 changes: 0 additions & 130 deletions gulpfile.js

This file was deleted.

4 changes: 1 addition & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,9 @@
"checked:taro": "npm run generate:file:taro && tsc --project ./tsconfig.taro.json --noEmit",
"changelog": "node ./scripts/generate-changelog.js",
"clone:jdharmony": "node ./scripts/harmony/clone-jdharmony.js",
"clone:rn": "pnpm run update:taro:entry && node ./scripts/rn/copy-file.js",
"dev": "vite --open --force",
"dev:rtl": "VITE_RTL=rtl vite --open --force",
"dev:jrkf": "VITE_APP_PROJECT_ID=jrkf vite --open --force",
"dev:taro:jdrn": "pnpm run clone:rn && pnpm --dir ./packages/nutui-taro-demo dev:jdrn",
"dev:taro:rn:dark": "THEME=dark pnpm dev:taro:rn",
"dev:taro": "pnpm run update:taro:entry && pnpm --dir ./packages/nutui-taro-demo dev",
"dev:taro:h5": "pnpm dev:taro h5",
Expand Down Expand Up @@ -93,7 +91,7 @@
"e2e:open:h5": "start-server-and-test dev http://localhost:5173/ cypress:open",
"e2e:run:taro": "start-server-and-test dev:taro:h5 http://localhost:10086 cypress:run:taro",
"e2e:open:taro": "start-server-and-test dev:taro:h5 http://localhost:10086 cypress:open:taro",
"update:taro:entry": "node ./scripts/rn/update-taro-entry",
"update:taro:entry": "node ./scripts/harmony/update-taro-entry",
Copy link

Choose a reason for hiding this comment

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

💡 Codebase verification

需要完整清理 React Native 相关代码

检测发现多处遗留的 RN 相关引用:

  • package.json 中仍保留 dev:taro:rn:dark 脚本命令
  • 多个构建脚本(包括新的 harmony 脚本)中存在 RN 相关代码
  • scripts 目录下约 30 个文件仍包含 RN 引用

建议进行全面清理,确保完全移除 React Native 支持。

🔗 Analysis chain

脚本路径更新符合架构调整

将 Taro 入口更新脚本从 RN 目录迁移到 harmony 目录,与移除 React Native 支持的目标一致。建议确保相关的构建和测试流程都已更新。

运行以下脚本验证相关脚本和配置:

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# 描述:检查是否还有遗留的 RN 相关文件
fd -t f "rn" ./scripts

Length of output: 22


Script:

#!/bin/bash
# 检查新的 harmony 脚本是否存在
echo "=== 检查 harmony 脚本 ==="
fd -t f "update-taro-entry" ./scripts/harmony

# 使用 ripgrep 搜索脚本目录中的 RN/React Native 引用
echo -e "\n=== 检查脚本中的 RN 引用 ==="
rg -i "react.?native|rn" ./scripts -l

# 检查 package.json 中的 RN 相关配置
echo -e "\n=== 检查 package.json 中的 RN 配置 ==="
rg "react.?native|rn" package.json

Length of output: 1458

"upgradeTaro": "pnpm --dir ./packages/nutui-taro-demo upgradeTaro"
},
"lint-staged": {
Expand Down
5 changes: 1 addition & 4 deletions packages/nutui-taro-demo/babel.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,7 @@ module.exports = {
],
],
plugins: [
!(process.env.TARO_ENV === 'rn' || process.env.TARO_ENV === 'jdrn') && [
'@babel/plugin-transform-typescript',
{ allowDeclareFields: true },
],
['@babel/plugin-transform-typescript', { allowDeclareFields: true }],
projectID === 'jmapp' && [
replaceIcons({
sourceLibrary: ['@nutui/icons-react-taro', '@nutui/icons-react'],
Expand Down
23 changes: 1 addition & 22 deletions packages/nutui-taro-demo/config/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,14 @@ if (projectID) {
themeStr = `src/styles/theme-${projectID}.scss`
}

let plugins = !['harmony', 'jdharmony', 'rn', 'jdrn'].includes(
process.env.TARO_ENV
)
let plugins = !['harmony', 'jdharmony'].includes(process.env.TARO_ENV)
? ['@tarojs/plugin-html']
: []

if (process.env.TARO_ENV === 'harmony') {
plugins.push('@tarojs/plugin-platform-harmony-ets')
}

if ((process.env.TARO_ENV === 'rn' || process.env.TARO_ENV === 'jdrn') && JD) {
plugins.push('@jdtaro/plugin-platform-jdrn')
}

// 小程序、jd H5 通过此插件覆盖
if (
(process.env.TARO_ENV === 'weapp' ||
Expand Down Expand Up @@ -255,21 +249,6 @@ const config = {
},
},
},
rn: {
appName: 'JDReactAPIDemos',
postcss: {
'postcss-css-variables': {
enable: true,
config: {
// variables: {
// '--nutui-color-primary': '#000',
// '--nutui-color-primary-stop-1': '#000',
// '--nutui-color-primary-stop-2': '#000',
// },
},
},
},
},
isWatch: true,
}

Expand Down
2 changes: 0 additions & 2 deletions packages/nutui-taro-demo/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
"dev:jdharmony": "pnpm exec taro build native-components --type jdharmony",
"dev:jdharmonycpp": "pnpm exec taro build native-components --type jdharmony_cpp",
"dev:jdhybrid": "npm run build:jdhybrid -- --watch",
"dev:jdrn": "node ./scripts/taro/generate-nutui-taro.js && taro build --type jdrn --watch --reset-cache",
"dev:quickapp": "npm run build:quickapp -- --watch",
"dev:weapp:jmapp": "VITE_APP_PROJECT_ID=jmapp npm run build:weapp -- --watch ",
"dev:swan:jmapp": "VITE_APP_PROJECT_ID=jmapp npm run build:swan -- --watch",
Expand All @@ -59,7 +58,6 @@
"dependencies": {
"@babel/runtime": "^7.23.9",
"@dongdesign/inject-jd-platform-styles": "1.0.4",
"@jdreact/jdreact-jsbundle-commonpack": "1.0.425",
"@jdtaro/plugin-platform-jdhybrid": "0.2.1",
"@jdtaro/taro-platform-jdharmony": "2.0.70",
"@jdtaro/plugin-platform-jdharmony-cpp": "0.1.4-alpha.3",
Expand Down
82 changes: 0 additions & 82 deletions packages/nutui-taro-demo/scripts/taro/generate-nutui-taro.js

This file was deleted.

10 changes: 4 additions & 6 deletions packages/nutui-taro-demo/src/app.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
import { Component } from 'react'
import Taro from '@tarojs/taro'
import './app.scss'

if (Taro.getEnv() !== 'RN') {
import('@/sites/assets/styles/reset.scss');
import('@/packages/nutui.react.scss.taro');
import('@nutui/touch-emulator');
}
import('@/sites/assets/styles/reset.scss')
import('@/packages/nutui.react.scss.taro')
import('@nutui/touch-emulator')
Copy link

Choose a reason for hiding this comment

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

💡 Codebase verification

建议使用条件导入 touch-emulator

当前实现会在所有环境下加载 touch-emulator,建议参考以下方案优化:

  • 使用 web() 工具函数进行环境检测
  • 仅在 Web 环境下导入 touch-emulator

示例代码:

import { web } from '@/utils/platform-taro'

if (web()) {
  import('@nutui/touch-emulator')
}
🔗 Analysis chain

建议评估 touch-emulator 的必要性

由于移除了环境检查,touch-emulator 现在会在所有环境下加载。建议:

  • 评估在非触摸设备上是否需要此模块
  • 考虑是否可以通过其他方式按需加载

运行以下命令检查 touch-emulator 的使用情况:

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# 检查 touch-emulator 的使用范围
rg -g '*.{ts,tsx,js,jsx}' '@nutui/touch-emulator' -A 2

Length of output: 435


Script:

#!/bin/bash
# Check for environment detection utilities
rg -g '*.{ts,tsx,js,jsx}' 'isMobile|isH5|getEnv|ENV_TYPE' -A 2

Length of output: 32880


Script:

#!/bin/bash
# Check platform detection utilities
cat src/utils/platform-taro.ts

Length of output: 373


// console.log(NutUI)
class App extends Component {
render() {
Expand Down
File renamed without changes.
Loading
Loading