diff --git a/.github/workflows/build-rust-binding.yml b/.github/workflows/build-rust-binding.yml index 6f5201990377..871c2d97f697 100644 --- a/.github/workflows/build-rust-binding.yml +++ b/.github/workflows/build-rust-binding.yml @@ -16,7 +16,7 @@ jobs: matrix: node-version: [18.x] settings: - - host: macos-12 + - host: macos-13 target: x86_64-apple-darwin build: | pnpm build:binding:release @@ -35,7 +35,7 @@ jobs: target: x86_64-unknown-linux-musl docker: ghcr.io/napi-rs/napi-rs/nodejs-rust:lts-alpine build: set -e && pnpm build:binding:release && strip crates/native_binding/*.node - - host: macos-12 + - host: macos-13 target: aarch64-apple-darwin build: | pnpm build:binding:release --target aarch64-apple-darwin diff --git a/.github/workflows/nodejs.yml b/.github/workflows/nodejs.yml index 39a3dba4d750..b55bef9e5c0c 100644 --- a/.github/workflows/nodejs.yml +++ b/.github/workflows/nodejs.yml @@ -37,9 +37,9 @@ jobs: fail-fast: false matrix: node-version: [18.x, 20.x] - host: [macos-12, windows-latest, ubuntu-latest] + host: [macos-13, windows-latest, ubuntu-latest] include: - - host: macos-12 + - host: macos-13 target: x86_64-apple-darwin - host: windows-latest target: x86_64-pc-windows-msvc @@ -49,11 +49,11 @@ jobs: target: x86_64-unknown-linux-musl exclude: - node-version: 18.x - host: macos-12 + host: macos-13 - node-version: 18.x host: windows-latest - node-version: 20.x - host: macos-12 + host: macos-13 - node-version: 20.x host: windows-latest diff --git a/README.md b/README.md index 14d32db0dba1..dc4d67ffe43c 100644 --- a/README.md +++ b/README.md @@ -83,9 +83,10 @@ Taro 1/2 迁移至 Taro 3,请阅读[《Taro 版本升级权威指南》](https | -------------------------------------------------- | ----------------------------------------------- | -------------------------------------------------------- | ---------- | ----------------------------------------- | | [taro-ui](https://github.com/NervJS/taro-ui) | https://taro-ui.jd.com/#/ | 一套基于 Taro 框架开发的多端 UI 组件库 | React | Taro 1/2/3 | | [NutUI](https://github.com/jdf2e/nutui) | https://nutui.jd.com/#/ | 京东风格的轻量级移动端 Vue 组件库 | Vue3 | Taro 3 | -| [taroify](https://github.com/mallfoundry/taroify) | https://taroify.gitee.io/taroify.com/introduce/ | 轻量、可靠的小程序端 Taro 组件库(Vant 的 Taro 版本) | React | Taro 3 | +| [taroify](https://github.com/mallfoundry/taroify) | https://taroify.github.io/taroify.com/introduce/ | 轻量、可靠的小程序端 Taro 组件库(Vant 的 Taro 版本) | React | Taro 3 | | [@antmjs/vantui](https://github.com/AntmJS/vantui) | https://antmjs.github.io/vantui/#/home | 基于有赞 VantWeapp 开发的同时支持 Taro 和 React 的 UI 库 | React | Taro 3 | | [Tard](https://github.com/jd-antelope/tard) | https://tard-ui.selling.cn/ | 一套基于 Taro 框架开发的多端 React UI 组件库 | React | Taro 3 | +| [duxui](https://github.com/duxapp/duxui) | https://duxapp.cn/docs/duxui/start/ | 一套能同时兼容小程序、React Native、鸿蒙、H5的移动端ui组件库| React | Taro 4 | ## 项目状态 diff --git a/README_EN.md b/README_EN.md index 56f7ac87e0b3..259904d7e024 100644 --- a/README_EN.md +++ b/README_EN.md @@ -86,7 +86,7 @@ Juejin book: [Taro Cross-platform Development in Action](https://juejin.im/book/ | ---- | ---- | ---- | ---- | ---- | | [taro-ui](https://github.com/NervJS/taro-ui) | https://taro-ui.jd.com/#/ | A cross-platform UI library based on Taro | React | Taro 1/2/3 | | [NutUI](https://github.com/jdf2e/nutui) | https://nutui.jd.com/#/ | A JD-style light-weighted Vue library | Vue3 | Taro 3 | -| [taroify](https://github.com/mallfoundry/taroify) | https://taroify.gitee.io/taroify.com/introduce/ | A light-weighted and reliable Taro library for mini-programs (Vant's Taro version) | React | Taro 3 | +| [taroify](https://github.com/mallfoundry/taroify) | https://taroify.github.io/taroify.com/introduce/ | A light-weighted and reliable Taro library for mini-programs (Vant's Taro version) | React | Taro 3 | | [@antmjs/vantui](https://github.com/AntmJS/vantui) | https://antmjs.github.io/vantui/#/home | A UI library that supports Taro and React, based on Youzan VantWeapp | React | Taro 3 | ## Status diff --git a/crates/native_binding/package.json b/crates/native_binding/package.json index c2f1b21bb21d..8213b5de3cf1 100644 --- a/crates/native_binding/package.json +++ b/crates/native_binding/package.json @@ -1,6 +1,6 @@ { "name": "@tarojs/binding", - "version": "4.0.8", + "version": "4.0.9-beta.2", "description": "Node binding for taro", "main": "binding.js", "typings": "binding.d.ts", diff --git a/crates/swc_plugin_define_config/src/lib.rs b/crates/swc_plugin_define_config/src/lib.rs index e3d5c9840986..4c8f536eb582 100644 --- a/crates/swc_plugin_define_config/src/lib.rs +++ b/crates/swc_plugin_define_config/src/lib.rs @@ -11,6 +11,7 @@ use swc_core::{ struct DefineConfigVisitor { fn_name: Option, + imp_name: Option, } impl VisitMut for DefineConfigVisitor { @@ -20,6 +21,8 @@ impl VisitMut for DefineConfigVisitor { if let Expr::Ident(ident) = &**expr { if ident.sym == "defineAppConfig" || ident.sym == "definePageConfig" { self.fn_name = Some(ident.clone()); + } else if ident.sym == "importNativeComponent" { + self.imp_name = Some(ident.clone()); } } } @@ -30,9 +33,12 @@ pub struct TransformVisitor; impl VisitMut for TransformVisitor { fn visit_mut_module_items(&mut self, items: &mut Vec) { - let mut folder = DefineConfigVisitor { fn_name: None }; + let mut folder = DefineConfigVisitor { + fn_name: None, + imp_name: None, + }; - let is_found = items.iter_mut().any(|item| { + let mut is_found = items.iter_mut().any(|item| { item.visit_mut_with(&mut folder); folder.fn_name.is_some() }); @@ -64,6 +70,66 @@ impl VisitMut for TransformVisitor { ModuleItem::Stmt(Stmt::Decl(Decl::Fn(func.into_fn_decl(fn_name)))), ); } + + is_found = items.iter_mut().any(|item| { + item.visit_mut_with(&mut folder); + folder.imp_name.is_some() + }); + + if is_found { + let imp_name = folder.imp_name.take().unwrap(); + let func = Function { + span, + decorators: Default::default(), + params: vec![ + // path 参数,默认值为空字符串 + Param { + span, + decorators: Default::default(), + pat: Pat::Assign(AssignPat { + span, + left: Box::new(Pat::Ident(quote_ident!("path").into())), + right: Box::new(Expr::Lit(Lit::Str("".into()))), + }), + }, + // name 参数,默认值为空字符串 + Param { + span, + decorators: Default::default(), + pat: Pat::Assign(AssignPat { + span, + left: Box::new(Pat::Ident(quote_ident!("name").into())), + right: Box::new(Expr::Lit(Lit::Str("".into()))), + }), + }, + // exportName 参数,默认值为 'default' + Param { + span, + decorators: Default::default(), + pat: Pat::Assign(AssignPat { + span, + left: Box::new(Pat::Ident(quote_ident!("exportName").into())), + right: Box::new(Expr::Lit(Lit::Str("default".into()))), + }), + }, + ], + body: Some(BlockStmt { + span, + stmts: vec![Stmt::Return(ReturnStmt { + span, + arg: Some(Box::new(quote_ident!("name").into())), + })], + }), + is_async: false, + is_generator: false, + type_params: None, + return_type: None, + }; + prepend_stmt( + items, + ModuleItem::Stmt(Stmt::Decl(Decl::Fn(func.into_fn_decl(imp_name)))), + ); + } } } diff --git a/examples/swiper-effect/tsconfig.json b/examples/swiper-effect/tsconfig.json index 1a4753bef3fa..bc1966dc6a2a 100644 --- a/examples/swiper-effect/tsconfig.json +++ b/examples/swiper-effect/tsconfig.json @@ -17,9 +17,7 @@ "jsx": "react-jsx", "allowJs": true, "resolveJsonModule": true, - "typeRoots": [ - "node_modules/@types" - ], + "typeRoots": ["node_modules/@types"], "paths": { // TS5090 leading './' "@/*": ["./src/*"] diff --git a/npm/darwin-arm64/package.json b/npm/darwin-arm64/package.json index 5a88358492f2..144bb33667c0 100644 --- a/npm/darwin-arm64/package.json +++ b/npm/darwin-arm64/package.json @@ -1,7 +1,7 @@ { "name": "@tarojs/binding-darwin-arm64", "description": "Native binding for taro", - "version": "4.0.8", + "version": "4.0.9-beta.2", "os": [ "darwin" ], diff --git a/npm/darwin-x64/package.json b/npm/darwin-x64/package.json index d54d880129ec..730a043ad667 100644 --- a/npm/darwin-x64/package.json +++ b/npm/darwin-x64/package.json @@ -1,7 +1,7 @@ { "name": "@tarojs/binding-darwin-x64", "description": "Native binding for taro", - "version": "4.0.8", + "version": "4.0.9-beta.2", "os": [ "darwin" ], diff --git a/npm/linux-x64-gnu/package.json b/npm/linux-x64-gnu/package.json index cfa2be8614b6..bc2149a4bb25 100644 --- a/npm/linux-x64-gnu/package.json +++ b/npm/linux-x64-gnu/package.json @@ -1,7 +1,7 @@ { "name": "@tarojs/binding-linux-x64-gnu", "description": "Native binding for taro", - "version": "4.0.8", + "version": "4.0.9-beta.2", "os": [ "linux" ], diff --git a/npm/linux-x64-musl/package.json b/npm/linux-x64-musl/package.json index bc31aa30d2dd..c308eeb70e8f 100644 --- a/npm/linux-x64-musl/package.json +++ b/npm/linux-x64-musl/package.json @@ -1,6 +1,6 @@ { "name": "@tarojs/binding-linux-x64-musl", - "version": "4.0.8", + "version": "4.0.9-beta.2", "os": [ "linux" ], diff --git a/npm/win32-x64-msvc/package.json b/npm/win32-x64-msvc/package.json index 498c55e89c84..8ce95443a2e4 100644 --- a/npm/win32-x64-msvc/package.json +++ b/npm/win32-x64-msvc/package.json @@ -1,7 +1,7 @@ { "name": "@tarojs/binding-win32-x64-msvc", "description": "Native binding for taro", - "version": "4.0.8", + "version": "4.0.9-beta.2", "os": [ "win32" ], diff --git a/package.json b/package.json index a0507f971ad0..da817346d73d 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "taro", - "version": "4.0.8", + "version": "4.0.9-beta.2", "description": "开放式跨端跨框架开发解决方案", "homepage": "https://github.com/NervJS/taro#readme", "author": "O2Team", diff --git a/packages/babel-plugin-transform-react-jsx-to-rn-stylesheet/package.json b/packages/babel-plugin-transform-react-jsx-to-rn-stylesheet/package.json index b5a8e9e83e43..006220518c3e 100644 --- a/packages/babel-plugin-transform-react-jsx-to-rn-stylesheet/package.json +++ b/packages/babel-plugin-transform-react-jsx-to-rn-stylesheet/package.json @@ -1,6 +1,6 @@ { "name": "babel-plugin-transform-react-jsx-to-rn-stylesheet", - "version": "4.0.8", + "version": "4.0.9-beta.2", "description": "Transform stylesheet selector to style in JSX Elements.", "author": "O2Team", "license": "MIT", diff --git a/packages/babel-plugin-transform-solid-jsx/package.json b/packages/babel-plugin-transform-solid-jsx/package.json index f0c9ebaa0b96..6b461adf68a4 100644 --- a/packages/babel-plugin-transform-solid-jsx/package.json +++ b/packages/babel-plugin-transform-solid-jsx/package.json @@ -1,7 +1,7 @@ { "name": "babel-plugin-transform-solid-jsx", "description": "A JSX to DOM plugin that wraps expressions for fine grained change detection", - "version": "4.0.8", + "version": "4.0.9-beta.2", "license": "MIT", "repository": { "type": "git", diff --git a/packages/babel-plugin-transform-taroapi/package.json b/packages/babel-plugin-transform-taroapi/package.json index 83eb1acb47fb..51022906f4cd 100644 --- a/packages/babel-plugin-transform-taroapi/package.json +++ b/packages/babel-plugin-transform-taroapi/package.json @@ -1,6 +1,6 @@ { "name": "babel-plugin-transform-taroapi", - "version": "4.0.8", + "version": "4.0.9-beta.2", "author": "O2Team", "license": "MIT", "main": "dist/index.js", diff --git a/packages/babel-preset-taro/package.json b/packages/babel-preset-taro/package.json index d2cac713e3fb..d991e8899954 100644 --- a/packages/babel-preset-taro/package.json +++ b/packages/babel-preset-taro/package.json @@ -1,6 +1,6 @@ { "name": "babel-preset-taro", - "version": "4.0.8", + "version": "4.0.9-beta.2", "description": "Taro babel preset", "author": "O2Team", "license": "MIT", diff --git a/packages/create-app/package.json b/packages/create-app/package.json index 0985474d3c3e..f47d14491a43 100644 --- a/packages/create-app/package.json +++ b/packages/create-app/package.json @@ -1,6 +1,6 @@ { "name": "@tarojs/create-app", - "version": "4.0.8", + "version": "4.0.9-beta.2", "description": "create taro app with one command", "author": "O2Team", "license": "MIT", diff --git a/packages/css-to-react-native/package.json b/packages/css-to-react-native/package.json index e6e8e4957096..ccdcdf59019a 100644 --- a/packages/css-to-react-native/package.json +++ b/packages/css-to-react-native/package.json @@ -1,7 +1,7 @@ { "name": "taro-css-to-react-native", "description": "Convert CSS text to a React Native stylesheet object", - "version": "4.0.8", + "version": "4.0.9-beta.2", "author": "O2Team", "license": "MIT", "main": "dist/index.js", diff --git a/packages/eslint-config-taro/package.json b/packages/eslint-config-taro/package.json index 932b8d206e8c..8768c5e69ee7 100644 --- a/packages/eslint-config-taro/package.json +++ b/packages/eslint-config-taro/package.json @@ -1,6 +1,6 @@ { "name": "eslint-config-taro", - "version": "4.0.8", + "version": "4.0.9-beta.2", "description": "Taro specific linting rules for ESLint", "author": "O2Team", "license": "MIT", diff --git a/packages/jest-helper/package.json b/packages/jest-helper/package.json index 0b20e3d01f16..f89f07f13b7f 100644 --- a/packages/jest-helper/package.json +++ b/packages/jest-helper/package.json @@ -1,6 +1,6 @@ { "name": "jest-taro-helper", - "version": "4.0.8", + "version": "4.0.9-beta.2", "description": "jest helper for taro", "private": true, "author": "O2Team", diff --git a/packages/postcss-html-transform/package.json b/packages/postcss-html-transform/package.json index 60d6d971f518..8b99e0c69469 100644 --- a/packages/postcss-html-transform/package.json +++ b/packages/postcss-html-transform/package.json @@ -1,6 +1,6 @@ { "name": "postcss-html-transform", - "version": "4.0.8", + "version": "4.0.9-beta.2", "description": "transform html tag name selector", "author": "O2Team", "license": "MIT", diff --git a/packages/postcss-plugin-constparse/package.json b/packages/postcss-plugin-constparse/package.json index 6cb77ea13470..a3641f7a90f7 100644 --- a/packages/postcss-plugin-constparse/package.json +++ b/packages/postcss-plugin-constparse/package.json @@ -1,6 +1,6 @@ { "name": "postcss-plugin-constparse", - "version": "4.0.8", + "version": "4.0.9-beta.2", "description": "parse constants defined in config", "author": "O2Team", "license": "MIT", diff --git a/packages/postcss-pxtransform/package.json b/packages/postcss-pxtransform/package.json index 5ed16c7b352e..efdbed1f6d77 100644 --- a/packages/postcss-pxtransform/package.json +++ b/packages/postcss-pxtransform/package.json @@ -1,6 +1,6 @@ { "name": "postcss-pxtransform", - "version": "4.0.8", + "version": "4.0.9-beta.2", "description": "PostCSS plugin px 转小程序 rpx及h5 rem 单位", "author": "O2Team", "license": "MIT", diff --git a/packages/postcss-unit-transform/package.json b/packages/postcss-unit-transform/package.json index 605a0c376a40..92acebe75174 100644 --- a/packages/postcss-unit-transform/package.json +++ b/packages/postcss-unit-transform/package.json @@ -1,6 +1,6 @@ { "name": "postcss-taro-unit-transform", - "version": "4.0.8", + "version": "4.0.9-beta.2", "description": "小程序单位转换", "author": "O2Team", "license": "MIT", diff --git a/packages/rollup-plugin-copy/package.json b/packages/rollup-plugin-copy/package.json index 3e5879bc81c3..6737c0e6c6c3 100644 --- a/packages/rollup-plugin-copy/package.json +++ b/packages/rollup-plugin-copy/package.json @@ -1,6 +1,6 @@ { "name": "rollup-plugin-copy", - "version": "4.0.8", + "version": "4.0.9-beta.2", "description": "rollup-plugin-copy for taro", "private": true, "author": "O2Team", diff --git a/packages/shared/package.json b/packages/shared/package.json index 8f8e51435aa1..ddfd3b36c0e1 100644 --- a/packages/shared/package.json +++ b/packages/shared/package.json @@ -1,6 +1,6 @@ { "name": "@tarojs/shared", - "version": "4.0.8", + "version": "4.0.9-beta.2", "description": "Taro utils internal use.", "author": "O2Team", "license": "MIT", diff --git a/packages/stylelint-config-taro-rn/package.json b/packages/stylelint-config-taro-rn/package.json index b01b8d273ba0..efb7df55148d 100644 --- a/packages/stylelint-config-taro-rn/package.json +++ b/packages/stylelint-config-taro-rn/package.json @@ -1,6 +1,6 @@ { "name": "stylelint-config-taro-rn", - "version": "4.0.8", + "version": "4.0.9-beta.2", "description": "Shareable stylelint config for React Native CSS modules", "author": "O2Team", "license": "MIT", diff --git a/packages/stylelint-taro-rn/package.json b/packages/stylelint-taro-rn/package.json index e3f4208bf21f..b74e4fe88e32 100644 --- a/packages/stylelint-taro-rn/package.json +++ b/packages/stylelint-taro-rn/package.json @@ -1,6 +1,6 @@ { "name": "stylelint-taro-rn", - "version": "4.0.8", + "version": "4.0.9-beta.2", "description": "A collection of React Native specific rules for stylelint", "author": "O2Team", "license": "MIT", diff --git a/packages/stylelint-taro/package.json b/packages/stylelint-taro/package.json index 94ce0c84d1f9..21dd680b649e 100644 --- a/packages/stylelint-taro/package.json +++ b/packages/stylelint-taro/package.json @@ -1,6 +1,6 @@ { "name": "stylelint-taro", - "version": "4.0.8", + "version": "4.0.9-beta.2", "description": "Taro stylelint 规则集合", "author": "O2Team", "license": "MIT", diff --git a/packages/taro-api/package.json b/packages/taro-api/package.json index 00cf7551105e..9f419b90d0a5 100644 --- a/packages/taro-api/package.json +++ b/packages/taro-api/package.json @@ -1,6 +1,6 @@ { "name": "@tarojs/api", - "version": "4.0.8", + "version": "4.0.9-beta.2", "description": "Taro common API", "author": "O2Team", "license": "MIT", diff --git a/packages/taro-cli-convertor/package.json b/packages/taro-cli-convertor/package.json index e4b443c232ad..c33c1e2de785 100644 --- a/packages/taro-cli-convertor/package.json +++ b/packages/taro-cli-convertor/package.json @@ -1,6 +1,6 @@ { "name": "@tarojs/cli-convertor", - "version": "4.0.8", + "version": "4.0.9-beta.2", "description": "cli tool for taro-convert", "author": "O2Team", "license": "MIT", diff --git a/packages/taro-cli/package.json b/packages/taro-cli/package.json index 4dfec96e10a7..db3e577009bc 100644 --- a/packages/taro-cli/package.json +++ b/packages/taro-cli/package.json @@ -1,6 +1,6 @@ { "name": "@tarojs/cli", - "version": "4.0.8", + "version": "4.0.9-beta.2", "description": "cli tool for taro", "author": "O2Team", "license": "MIT", diff --git a/packages/taro-components-advanced/package.json b/packages/taro-components-advanced/package.json index c6cf28f064b0..c6b22cd75654 100644 --- a/packages/taro-components-advanced/package.json +++ b/packages/taro-components-advanced/package.json @@ -1,6 +1,6 @@ { "name": "@tarojs/components-advanced", - "version": "4.0.8", + "version": "4.0.9-beta.2", "description": "", "author": "O2Team", "license": "MIT", diff --git a/packages/taro-components-library-react/package.json b/packages/taro-components-library-react/package.json index a3915e0773f8..e069d2571789 100644 --- a/packages/taro-components-library-react/package.json +++ b/packages/taro-components-library-react/package.json @@ -1,6 +1,6 @@ { "name": "@tarojs/components-library-react", - "version": "4.0.8", + "version": "4.0.9-beta.2", "description": "Taro 组件库 React 版本库", "private": true, "author": "O2Team", diff --git a/packages/taro-components-library-solid/package.json b/packages/taro-components-library-solid/package.json index 06fe69c93703..faa108bf002a 100644 --- a/packages/taro-components-library-solid/package.json +++ b/packages/taro-components-library-solid/package.json @@ -1,6 +1,6 @@ { "name": "@tarojs/components-library-solid", - "version": "4.0.8", + "version": "4.0.9-beta.2", "description": "Taro 组件库 Solid 版本库", "private": true, "main": "index.js", diff --git a/packages/taro-components-library-vue3/package.json b/packages/taro-components-library-vue3/package.json index b1a1b3b0a73b..ea9d7e069a78 100644 --- a/packages/taro-components-library-vue3/package.json +++ b/packages/taro-components-library-vue3/package.json @@ -1,6 +1,6 @@ { "name": "@tarojs/components-library-vue3", - "version": "4.0.8", + "version": "4.0.9-beta.2", "description": "Taro 组件库 Vue3 版本库", "private": true, "author": "O2Team", diff --git a/packages/taro-components-react/package.json b/packages/taro-components-react/package.json index 6ea728e4d9cf..52cfe2f15255 100644 --- a/packages/taro-components-react/package.json +++ b/packages/taro-components-react/package.json @@ -1,6 +1,6 @@ { "name": "@tarojs/components-react", - "version": "4.0.8", + "version": "4.0.9-beta.2", "description": "", "main:h5": "dist/index.js", "main": "dist/index.js", diff --git a/packages/taro-components-rn/package.json b/packages/taro-components-rn/package.json index 9de58802ca12..d9fabb2ff996 100644 --- a/packages/taro-components-rn/package.json +++ b/packages/taro-components-rn/package.json @@ -1,6 +1,6 @@ { "name": "@tarojs/components-rn", - "version": "4.0.8", + "version": "4.0.9-beta.2", "description": "React Native 基础组件", "author": "O2Team", "license": "MIT", diff --git a/packages/taro-components/__tests__/__snapshots__/picker-view.spec.tsx.snap b/packages/taro-components/__tests__/__snapshots__/picker-view.spec.tsx.snap index 13da27f54cd3..1dc67ea61e0f 100644 --- a/packages/taro-components/__tests__/__snapshots__/picker-view.spec.tsx.snap +++ b/packages/taro-components/__tests__/__snapshots__/picker-view.spec.tsx.snap @@ -108,6 +108,9 @@ exports[`PickerView props valid 1`] = ` 2024年 + + 2025年 +
diff --git a/packages/taro-components/package.json b/packages/taro-components/package.json index 00c5022b37c6..0a62ebb99014 100644 --- a/packages/taro-components/package.json +++ b/packages/taro-components/package.json @@ -1,6 +1,6 @@ { "name": "@tarojs/components", - "version": "4.0.8", + "version": "4.0.9-beta.2", "description": "Taro 组件库", "browser": "dist/index.js", "main:h5": "dist/index.js", diff --git a/packages/taro-extend/package.json b/packages/taro-extend/package.json index 356b140abb21..52741dc01ab4 100644 --- a/packages/taro-extend/package.json +++ b/packages/taro-extend/package.json @@ -1,6 +1,6 @@ { "name": "@tarojs/extend", - "version": "4.0.8", + "version": "4.0.9-beta.2", "description": "Taro extend functionality", "author": "O2Team", "license": "MIT", diff --git a/packages/taro-framework-react/package.json b/packages/taro-framework-react/package.json index ea143ab8651f..62636497e743 100644 --- a/packages/taro-framework-react/package.json +++ b/packages/taro-framework-react/package.json @@ -1,6 +1,6 @@ { "name": "@tarojs/plugin-framework-react", - "version": "4.0.8", + "version": "4.0.9-beta.2", "description": "React/Preact 框架插件", "author": "O2Team", "homepage": "https://github.com/nervjs/taro", diff --git a/packages/taro-framework-solid/package.json b/packages/taro-framework-solid/package.json index a05d3161767f..555b0fedb098 100644 --- a/packages/taro-framework-solid/package.json +++ b/packages/taro-framework-solid/package.json @@ -1,6 +1,6 @@ { "name": "@tarojs/plugin-framework-solid", - "version": "4.0.8", + "version": "4.0.9-beta.2", "description": "Solid 框架插件", "author": "drchan", "homepage": "https://github.com/nervjs/taro", diff --git a/packages/taro-framework-vue3/package.json b/packages/taro-framework-vue3/package.json index c53c6b068986..40d58ff2bf5c 100644 --- a/packages/taro-framework-vue3/package.json +++ b/packages/taro-framework-vue3/package.json @@ -1,6 +1,6 @@ { "name": "@tarojs/plugin-framework-vue3", - "version": "4.0.8", + "version": "4.0.9-beta.2", "description": "Vue3 框架插件", "author": "O2Team", "homepage": "https://github.com/nervjs/taro", diff --git a/packages/taro-h5/package.json b/packages/taro-h5/package.json index 3124978ac953..1a75a560bfe8 100644 --- a/packages/taro-h5/package.json +++ b/packages/taro-h5/package.json @@ -1,6 +1,6 @@ { "name": "@tarojs/taro-h5", - "version": "4.0.8", + "version": "4.0.9-beta.2", "description": "Taro h5 framework", "browser": "dist/index.js", "main:h5": "dist/index.esm.js", diff --git a/packages/taro-helper/package.json b/packages/taro-helper/package.json index 57f73178af19..90d7bafbbb0a 100644 --- a/packages/taro-helper/package.json +++ b/packages/taro-helper/package.json @@ -1,6 +1,6 @@ { "name": "@tarojs/helper", - "version": "4.0.8", + "version": "4.0.9-beta.2", "description": "Taro Helper", "author": "O2Team", "license": "MIT", diff --git a/packages/taro-helper/src/babelRegister.ts b/packages/taro-helper/src/babelRegister.ts index c583357ff947..c081f96e2417 100644 --- a/packages/taro-helper/src/babelRegister.ts +++ b/packages/taro-helper/src/babelRegister.ts @@ -9,6 +9,7 @@ import type { NodePath, parse, PluginItem } from '@babel/core' export function injectDefineConfigHeader (babel: { parse: typeof parse }): PluginItem { const appConfig = 'function defineAppConfig(config) { return config }' const pageConfig = 'function definePageConfig(config) { return config }' + const importNative = "function importNativeComponent(path = '', name = '', exportName = '') { return name }" const prependHeader = (nodePath: NodePath, header: string) => { const parsedHeader = babel.parse(header, { filename: '' })?.program.body[0] @@ -27,6 +28,9 @@ export function injectDefineConfigHeader (babel: { parse: typeof parse }): Plugi return prependHeader(nodePath, appConfig) case 'definePageConfig': return prependHeader(nodePath, pageConfig) + case 'importNativeComponent': + return prependHeader(nodePath, importNative) + default: } } }) diff --git a/packages/taro-helper/swc-backup/swc_plugin_define_config.wasm b/packages/taro-helper/swc-backup/swc_plugin_define_config.wasm old mode 100644 new mode 100755 index 85cb7d7310d0..b2d2e34f2528 Binary files a/packages/taro-helper/swc-backup/swc_plugin_define_config.wasm and b/packages/taro-helper/swc-backup/swc_plugin_define_config.wasm differ diff --git a/packages/taro-loader/package.json b/packages/taro-loader/package.json index fc9ccbd84203..fa2b85f22e8f 100644 --- a/packages/taro-loader/package.json +++ b/packages/taro-loader/package.json @@ -1,6 +1,6 @@ { "name": "@tarojs/taro-loader", - "version": "4.0.8", + "version": "4.0.9-beta.2", "description": "Taro runner use webpack loader", "author": "O2Team", "license": "MIT", diff --git a/packages/taro-platform-alipay/package.json b/packages/taro-platform-alipay/package.json index ef8df22e8728..6abda15286e0 100644 --- a/packages/taro-platform-alipay/package.json +++ b/packages/taro-platform-alipay/package.json @@ -1,6 +1,6 @@ { "name": "@tarojs/plugin-platform-alipay", - "version": "4.0.8", + "version": "4.0.9-beta.2", "description": "支付宝小程序平台插件", "author": "O2Team", "license": "MIT", diff --git a/packages/taro-platform-h5/package.json b/packages/taro-platform-h5/package.json index dfb80aecfeb8..9d85a6f42f98 100644 --- a/packages/taro-platform-h5/package.json +++ b/packages/taro-platform-h5/package.json @@ -1,6 +1,6 @@ { "name": "@tarojs/plugin-platform-h5", - "version": "4.0.8", + "version": "4.0.9-beta.2", "description": "Web 端平台插件", "author": "O2Team", "license": "MIT", diff --git a/packages/taro-platform-harmony-hybrid/build/config/harmony-definition.json b/packages/taro-platform-harmony-hybrid/build/config/harmony-definition.json index 32222d2a421c..e6341301337c 100644 --- a/packages/taro-platform-harmony-hybrid/build/config/harmony-definition.json +++ b/packages/taro-platform-harmony-hybrid/build/config/harmony-definition.json @@ -2176,7 +2176,7 @@ }, "custom-wrapper": true, "double-tap-gesture-handler": { - "should-response-on-move-worklet": false + "tag": false }, "draggable-sheet": { "initial-child-size": false, @@ -2193,7 +2193,9 @@ "show-img-resize": false }, "follow-swan": false, - "force-press-gesture-handler": false, + "force-press-gesture-handler": { + "tag": false + }, "form": { "report-submit": false, "report-submit-timeout": false @@ -2236,7 +2238,7 @@ "padding": false }, "horizontal-drag-gesture-handler": { - "should-response-on-move-worklet": false + "tag": false }, "icon": { "type": { @@ -2461,7 +2463,7 @@ }, "login": false, "long-press-gesture-handler": { - "should-response-on-move-worklet": false + "tag": false }, "lottie": false, "map": { @@ -2640,7 +2642,7 @@ "page-orientation": false }, "pan-gesture-handler": { - "should-response-on-move-worklet": false + "tag": false }, "picker": { "mode": { @@ -2742,7 +2744,7 @@ "rtc-room": false, "rtc-room-item": false, "scale-gesture-handler": { - "should-response-on-move-worklet": false + "tag": false }, "script": { "src": false, @@ -2899,7 +2901,7 @@ "tab-item": false, "tabs": false, "tap-gesture-handler": { - "should-response-on-move-worklet": false + "tag": false }, "text": { "selectable": false, @@ -2950,7 +2952,7 @@ "default-value": false }, "vertical-drag-gesture-handler": { - "should-response-on-move-worklet": false + "tag": false }, "video": { "src": true, diff --git a/packages/taro-platform-harmony-hybrid/package.json b/packages/taro-platform-harmony-hybrid/package.json index 477ab2f61a96..24b1ff63719a 100644 --- a/packages/taro-platform-harmony-hybrid/package.json +++ b/packages/taro-platform-harmony-hybrid/package.json @@ -1,6 +1,6 @@ { "name": "@tarojs/plugin-platform-harmony-hybrid", - "version": "4.0.8", + "version": "4.0.9-beta.2", "description": "Harmony 端平台插件", "author": "O2Team", "license": "MIT", diff --git a/packages/taro-platform-harmony/package.json b/packages/taro-platform-harmony/package.json index 3c998f88d683..726c0fa9d347 100644 --- a/packages/taro-platform-harmony/package.json +++ b/packages/taro-platform-harmony/package.json @@ -1,6 +1,6 @@ { "name": "@tarojs/plugin-platform-harmony-ets", - "version": "4.0.8", + "version": "4.0.9-beta.2", "description": "OpenHarmony & 鸿蒙系统插件", "author": "O2Team", "homepage": "https://gitee.com/openharmony-sig/taro", diff --git a/packages/taro-platform-harmony/src/runtime-ets/dom/element/element.ts b/packages/taro-platform-harmony/src/runtime-ets/dom/element/element.ts index 1d595da1255c..a5790700ea0a 100644 --- a/packages/taro-platform-harmony/src/runtime-ets/dom/element/element.ts +++ b/packages/taro-platform-harmony/src/runtime-ets/dom/element/element.ts @@ -33,14 +33,13 @@ export class TaroElement< > extends TaroNode { public _innerHTML = '' public _nodeInfo: TaroAny = { - layer: 0 // 渲染层级 + layer: 0, // 渲染层级 } public _hm_instance: TaroAny public weak_hm_instance: WeakRef public use_weak_hm_instance: boolean = true - public get hm_instance(): TaroAny { if (this.use_weak_hm_instance && this.weak_hm_instance) { return this.weak_hm_instance?.deref() @@ -56,17 +55,16 @@ export class TaroElement< this._hm_instance = instance } - - public get _instance () { + public get _instance() { return this.hm_instance } - public set _instance (value) { + public set _instance(value) { this.hm_instance = value if (this._nodeInfo.aboutToAppear) { let task // eslint-disable-next-line no-cond-assign - while (task = this._nodeInfo.aboutToAppear.shift()) { + while ((task = this._nodeInfo.aboutToAppear.shift())) { task() } } @@ -159,7 +157,7 @@ export class TaroElement< id: this._nid, tagName: this.tagName, attribute: name, - value + value, }) } else { const attributeTriggerValue: TaroAny = ATTRIBUTES_CALLBACK_TRIGGER_MAP[name] @@ -266,7 +264,7 @@ export class TaroElement< if (!this._pseudo_before) { this._pseudo_before = new StyleSheet() } - Object.keys(value).forEach(key => { + Object.keys(value).forEach((key) => { this._pseudo_before!.hmStyle[key] = value[key] }) } else { @@ -281,7 +279,7 @@ export class TaroElement< if (!this._pseudo_after) { this._pseudo_after = new StyleSheet() } - Object.keys(value).forEach(key => { + Object.keys(value).forEach((key) => { this._pseudo_after!.hmStyle[key] = value[key] }) } else { @@ -299,7 +297,7 @@ export class TaroElement< if (!this._pseudo_class[name]) { this._pseudo_class[name] = new StyleSheet() } - Object.keys(value).forEach(key => { + Object.keys(value).forEach((key) => { this._pseudo_class[name]!.hmStyle[key] = value[key] }) } else { @@ -307,7 +305,7 @@ export class TaroElement< } } - get currentLayerNode () { + get currentLayerNode() { if (!this._page) return null if (typeof this._page.tabBarCurrentIndex !== 'undefined') { this._page.layerNode ||= [] @@ -320,7 +318,7 @@ export class TaroElement< } } - get currentLayerParents () { + get currentLayerParents() { if (!this._page) return null if (typeof this._page.tabBarCurrentIndex !== 'undefined') { this._page.layerParents ||= {} @@ -337,7 +335,7 @@ export class TaroElement< // 1、appendChild的时候会判断是否需要设置层级 // 2、taro-react的setProperty,在处理属性变化的时候,会判断是否需要设置层级 // 3、removeChild的时候,会判断是否需要移除层级 - public setLayer (value: number) { + public setLayer(value: number) { if (!this.parentNode) return // 没有父节点,不需要设置层级关系 const currentPage = getPageById(this.getAttribute('__fixed')) @@ -359,7 +357,7 @@ export class TaroElement< generateLayerParentIds(_parentRecord, this) currentLayerParents[this.getStrNid()] = _parentRecord } else { - const idx = currentLayerNode.childNodes.findIndex(n => n.getStrNid() === this.getStrNid()) + const idx = currentLayerNode.childNodes.findIndex((n) => n.getStrNid() === this.getStrNid()) currentLayerNode.childNodes.splice(idx, 1) currentLayerNode.notifyDataDelete(idx) @@ -385,7 +383,7 @@ export class TaroElement< delete currentLayerParents[this.getStrNid()] this.setLayer(0) } else { - Object.keys(currentLayerParents).forEach(fixedId => { + Object.keys(currentLayerParents).forEach((fixedId) => { const parentIds = currentLayerParents[fixedId] if (parentIds[this.getStrNid()]) { // 需要移除fixedId @@ -401,7 +399,7 @@ export class TaroElement< } // 设置动画 - public setAnimation (playing) { + public setAnimation(playing) { if (!this._instance) { if (!this._nodeInfo.aboutToAppear) { this._nodeInfo.aboutToAppear = [] @@ -436,41 +434,50 @@ export class TaroElement< this.parentNode.notifyDataDelete(idx) // 下一帧播放,等实例被移除掉,再重新插入 - setTimeout(() => { - // insert - this.parentNode?.childNodes.splice(idx, 0, this) - this.parentNode?.notifyDataAdd(idx) - - // 执行动画 - if (playing) { - this.playAnimation() - } - }, playing ? 0 : 100) + setTimeout( + () => { + // insert + this.parentNode?.childNodes.splice(idx, 0, this) + this.parentNode?.notifyDataAdd(idx) + + // 执行动画 + if (playing) { + this.playAnimation() + } + }, + playing ? 0 : 100 + ) } } - private playAnimation () { + private playAnimation() { const { - animationDuration = 0, animationDelay = 0, animationIterationCount = 1, animationName: keyframes, - animationTimingFunction + animationDuration = 0, + animationDelay = 0, + animationIterationCount = 1, + animationName: keyframes, + animationTimingFunction, } = this._st.hmStyle if (keyframes) { let cur_percentage = 0 - this._instance.getUIContext()?.keyframeAnimateTo({ - delay: animationDelay, - iterations: animationIterationCount, - }, keyframes.map(item => { - const duration = (item.percentage - cur_percentage) * animationDuration - cur_percentage = item.percentage - return { - duration: duration, - curve: item.event.animationTimingFunction || animationTimingFunction, - event: () => { - this._instance.overwriteStyle = item.event + this._instance.getUIContext()?.keyframeAnimateTo( + { + delay: animationDelay, + iterations: animationIterationCount, + }, + keyframes.map((item) => { + const duration = (item.percentage - cur_percentage) * animationDuration + cur_percentage = item.percentage + return { + duration: duration, + curve: item.event.animationTimingFunction || animationTimingFunction, + event: () => { + this._instance.overwriteStyle = item.event + }, } - } - })) + }) + ) } } } diff --git a/packages/taro-platform-jd/package.json b/packages/taro-platform-jd/package.json index cdb7d7e218b3..0f4f922160ba 100644 --- a/packages/taro-platform-jd/package.json +++ b/packages/taro-platform-jd/package.json @@ -1,6 +1,6 @@ { "name": "@tarojs/plugin-platform-jd", - "version": "4.0.8", + "version": "4.0.9-beta.2", "description": "京东小程序平台插件", "author": "O2Team", "license": "MIT", diff --git a/packages/taro-platform-qq/package.json b/packages/taro-platform-qq/package.json index d009e86d0472..e73d832c10d0 100644 --- a/packages/taro-platform-qq/package.json +++ b/packages/taro-platform-qq/package.json @@ -1,6 +1,6 @@ { "name": "@tarojs/plugin-platform-qq", - "version": "4.0.8", + "version": "4.0.9-beta.2", "description": "QQ 小程序平台插件", "author": "O2Team", "license": "MIT", diff --git a/packages/taro-platform-swan/package.json b/packages/taro-platform-swan/package.json index 5fa00d75abf0..9e43c6f66770 100644 --- a/packages/taro-platform-swan/package.json +++ b/packages/taro-platform-swan/package.json @@ -1,6 +1,6 @@ { "name": "@tarojs/plugin-platform-swan", - "version": "4.0.8", + "version": "4.0.9-beta.2", "description": "百度小程序平台插件", "author": "O2Team", "license": "MIT", diff --git a/packages/taro-platform-tt/package.json b/packages/taro-platform-tt/package.json index c7e77a331ee7..2f8cafecf52f 100644 --- a/packages/taro-platform-tt/package.json +++ b/packages/taro-platform-tt/package.json @@ -1,6 +1,6 @@ { "name": "@tarojs/plugin-platform-tt", - "version": "4.0.8", + "version": "4.0.9-beta.2", "description": "头条小程序平台插件", "author": "O2Team", "license": "MIT", diff --git a/packages/taro-platform-weapp/package.json b/packages/taro-platform-weapp/package.json index 8d9f2825f774..6473434f2124 100644 --- a/packages/taro-platform-weapp/package.json +++ b/packages/taro-platform-weapp/package.json @@ -1,6 +1,6 @@ { "name": "@tarojs/plugin-platform-weapp", - "version": "4.0.8", + "version": "4.0.9-beta.2", "description": "微信小程序平台插件", "author": "O2Team", "license": "MIT", diff --git a/packages/taro-plugin-html/package.json b/packages/taro-plugin-html/package.json index db877ef03a45..358e2b9984d1 100644 --- a/packages/taro-plugin-html/package.json +++ b/packages/taro-plugin-html/package.json @@ -1,6 +1,6 @@ { "name": "@tarojs/plugin-html", - "version": "4.0.8", + "version": "4.0.9-beta.2", "description": "Taro 小程序端支持使用 HTML 标签的插件", "author": "O2Team", "license": "MIT", diff --git a/packages/taro-plugin-http/package.json b/packages/taro-plugin-http/package.json index f7e948b61009..8f9477b6839f 100644 --- a/packages/taro-plugin-http/package.json +++ b/packages/taro-plugin-http/package.json @@ -1,6 +1,6 @@ { "name": "@tarojs/plugin-http", - "version": "4.0.8", + "version": "4.0.9-beta.2", "description": "Taro 小程序端支持使用 web 请求 的插件", "author": "O2Team", "license": "MIT", diff --git a/packages/taro-plugin-inject/package.json b/packages/taro-plugin-inject/package.json index 0d48a42e9964..a1d28ceeb378 100644 --- a/packages/taro-plugin-inject/package.json +++ b/packages/taro-plugin-inject/package.json @@ -1,6 +1,6 @@ { "name": "@tarojs/plugin-inject", - "version": "4.0.8", + "version": "4.0.9-beta.2", "description": "Taro 小程序端平台中间层插件", "author": "O2Team", "homepage": "https://github.com/nervjs/taro", diff --git a/packages/taro-plugin-mini-ci/package.json b/packages/taro-plugin-mini-ci/package.json index b5d3b3722d87..7b24ddade88e 100644 --- a/packages/taro-plugin-mini-ci/package.json +++ b/packages/taro-plugin-mini-ci/package.json @@ -1,6 +1,6 @@ { "name": "@tarojs/plugin-mini-ci", - "version": "4.0.8", + "version": "4.0.9-beta.2", "description": "Taro 小程序端构建后支持CI(持续集成)的插件", "keywords": [ "Taro", diff --git a/packages/taro-plugin-react-devtools/package.json b/packages/taro-plugin-react-devtools/package.json index 9a6839a9f257..8c9b7dd74bb7 100644 --- a/packages/taro-plugin-react-devtools/package.json +++ b/packages/taro-plugin-react-devtools/package.json @@ -1,6 +1,6 @@ { "name": "@tarojs/plugin-react-devtools", - "version": "4.0.8", + "version": "4.0.9-beta.2", "description": "Taro 小程序端支持使用 React DevTools 的插件", "author": "O2Team", "license": "MIT", diff --git a/packages/taro-plugin-vue-devtools/package.json b/packages/taro-plugin-vue-devtools/package.json index 7cbf2e38865f..cd58817f2673 100644 --- a/packages/taro-plugin-vue-devtools/package.json +++ b/packages/taro-plugin-vue-devtools/package.json @@ -1,6 +1,6 @@ { "name": "@tarojs/plugin-vue-devtools", - "version": "4.0.8", + "version": "4.0.9-beta.2", "description": "Taro 小程序端支持使用 Vue DevTools 的插件", "author": "O2Team", "license": "MIT", diff --git a/packages/taro-react/package.json b/packages/taro-react/package.json index 6ddbc07893e4..d86f0f733df3 100644 --- a/packages/taro-react/package.json +++ b/packages/taro-react/package.json @@ -1,6 +1,6 @@ { "name": "@tarojs/react", - "version": "4.0.8", + "version": "4.0.9-beta.2", "description": "like react-dom, but for mini apps.", "author": "O2Team", "license": "MIT", diff --git a/packages/taro-rn-runner/package.json b/packages/taro-rn-runner/package.json index b40584eb9daf..1eecbf0beda8 100644 --- a/packages/taro-rn-runner/package.json +++ b/packages/taro-rn-runner/package.json @@ -1,6 +1,6 @@ { "name": "@tarojs/rn-runner", - "version": "4.0.8", + "version": "4.0.9-beta.2", "description": "ReactNative build tool for taro", "author": "O2Team", "license": "MIT", diff --git a/packages/taro-rn-style-transformer/package.json b/packages/taro-rn-style-transformer/package.json index b2b718b6a113..c4b82152a734 100644 --- a/packages/taro-rn-style-transformer/package.json +++ b/packages/taro-rn-style-transformer/package.json @@ -1,6 +1,6 @@ { "name": "@tarojs/rn-style-transformer", - "version": "4.0.8", + "version": "4.0.9-beta.2", "description": "提供 Taro RN 统一处理样式文件能力", "author": "O2Team", "license": "MIT", diff --git a/packages/taro-rn-supporter/package.json b/packages/taro-rn-supporter/package.json index b09fc4899249..96de5557cefe 100644 --- a/packages/taro-rn-supporter/package.json +++ b/packages/taro-rn-supporter/package.json @@ -1,6 +1,6 @@ { "name": "@tarojs/rn-supporter", - "version": "4.0.8", + "version": "4.0.9-beta.2", "description": "Taro rn supporter", "author": "O2Team", "license": "MIT", diff --git a/packages/taro-rn-transformer/package.json b/packages/taro-rn-transformer/package.json index eeeed97c78ee..fc133927a48d 100644 --- a/packages/taro-rn-transformer/package.json +++ b/packages/taro-rn-transformer/package.json @@ -1,6 +1,6 @@ { "name": "@tarojs/rn-transformer", - "version": "4.0.8", + "version": "4.0.9-beta.2", "description": "Taro RN 入口文件处理", "author": "O2Team", "license": "MIT", diff --git a/packages/taro-rn/package.json b/packages/taro-rn/package.json index 9f6259ad51ea..417badb17baf 100644 --- a/packages/taro-rn/package.json +++ b/packages/taro-rn/package.json @@ -1,6 +1,6 @@ { "name": "@tarojs/taro-rn", - "version": "4.0.8", + "version": "4.0.9-beta.2", "description": "Taro RN framework", "author": "O2Team", "license": "MIT", diff --git a/packages/taro-router-rn/package.json b/packages/taro-router-rn/package.json index 13f1bb899dbf..0544c4e20f90 100644 --- a/packages/taro-router-rn/package.json +++ b/packages/taro-router-rn/package.json @@ -1,6 +1,6 @@ { "name": "@tarojs/router-rn", - "version": "4.0.8", + "version": "4.0.9-beta.2", "description": "Taro-router-rn", "author": "O2Team", "license": "MIT", diff --git a/packages/taro-router/package.json b/packages/taro-router/package.json index 794081252268..0ae059a48ab7 100644 --- a/packages/taro-router/package.json +++ b/packages/taro-router/package.json @@ -1,6 +1,6 @@ { "name": "@tarojs/router", - "version": "4.0.8", + "version": "4.0.9-beta.2", "description": "Taro-router", "author": "O2Team", "license": "MIT", diff --git a/packages/taro-runner-utils/package.json b/packages/taro-runner-utils/package.json index a33f16d3dca7..adeaf3d8b28a 100644 --- a/packages/taro-runner-utils/package.json +++ b/packages/taro-runner-utils/package.json @@ -1,6 +1,6 @@ { "name": "@tarojs/runner-utils", - "version": "4.0.8", + "version": "4.0.9-beta.2", "description": "Taro runner utilities.", "author": "O2Team", "license": "MIT", diff --git a/packages/taro-runtime-rn/package.json b/packages/taro-runtime-rn/package.json index a51f06615789..e35186a0916e 100644 --- a/packages/taro-runtime-rn/package.json +++ b/packages/taro-runtime-rn/package.json @@ -1,6 +1,6 @@ { "name": "@tarojs/runtime-rn", - "version": "4.0.8", + "version": "4.0.9-beta.2", "description": "taro-runtime-rn", "author": "O2Team", "license": "MIT", diff --git a/packages/taro-runtime/package.json b/packages/taro-runtime/package.json index 0086ac99dce2..d160e06c9fc7 100644 --- a/packages/taro-runtime/package.json +++ b/packages/taro-runtime/package.json @@ -1,6 +1,6 @@ { "name": "@tarojs/runtime", - "version": "4.0.8", + "version": "4.0.9-beta.2", "description": "taro runtime for mini apps.", "author": "O2Team", "license": "MIT", diff --git a/packages/taro-service/package.json b/packages/taro-service/package.json index c55c821a98a2..0fb8fc8643cc 100644 --- a/packages/taro-service/package.json +++ b/packages/taro-service/package.json @@ -1,6 +1,6 @@ { "name": "@tarojs/service", - "version": "4.0.8", + "version": "4.0.9-beta.2", "description": "Taro Service", "author": "O2Team", "license": "MIT", diff --git a/packages/taro-transformer-wx/package.json b/packages/taro-transformer-wx/package.json index 06b94cf49c6c..c3a3011fb7cd 100644 --- a/packages/taro-transformer-wx/package.json +++ b/packages/taro-transformer-wx/package.json @@ -1,6 +1,6 @@ { "name": "@tarojs/transformer-wx", - "version": "4.0.8", + "version": "4.0.9-beta.2", "description": "Transfrom Nerv Component to Wechat mini program.", "author": "O2Team", "license": "MIT", diff --git a/packages/taro-vite-runner/package.json b/packages/taro-vite-runner/package.json index 84cd1a13d2d5..8a26d679d36e 100644 --- a/packages/taro-vite-runner/package.json +++ b/packages/taro-vite-runner/package.json @@ -1,6 +1,6 @@ { "name": "@tarojs/vite-runner", - "version": "4.0.8", + "version": "4.0.9-beta.2", "main": "index.js", "license": "MIT", "files": [ diff --git a/packages/taro-vite-runner/src/common/babel-plugin-import-native-component.ts b/packages/taro-vite-runner/src/common/babel-plugin-import-native-component.ts new file mode 100644 index 000000000000..3c13c71fb9c2 --- /dev/null +++ b/packages/taro-vite-runner/src/common/babel-plugin-import-native-component.ts @@ -0,0 +1,66 @@ +import { resolveMainFilePath } from '@tarojs/helper' +import path from 'path' + +import type * as BabelCore from '@babel/core' +import type { ViteHarmonyCompilerContext, ViteMiniCompilerContext } from '@tarojs/taro/types/compile/viteCompilerContext' + +const IMPORT_COMPONENT_NAME = 'importNativeComponent' + +type TCallback = (path: string | false, name?: string, exportName?: string) => string +export default (compiler: ViteHarmonyCompilerContext | ViteMiniCompilerContext, id: string, cb: TCallback) => { + return function pluginImportNativeComponent (babel: typeof BabelCore): BabelCore.PluginObj { + const t = babel.types + let enableImportComponent = true + + return { + name: 'plugin:import-native-component', + visitor: { + CallExpression(ast) { + // 识别所有 importNativeComponent 函数调用, 并替换为对应的组件名 + if (t.isIdentifier(ast.node.callee, { name: IMPORT_COMPONENT_NAME })) { + const pathArg = resolveMainFilePath( + path.resolve( + path.dirname(id), + compiler.resolvePageImportPath(id, t.isStringLiteral(ast.node.arguments[0]) ? ast.node.arguments[0].value : '') + ) + ) + const nameArg = t.isStringLiteral(ast.node.arguments[1]) ? ast.node.arguments[1].value : '' + const exportNameArg = t.isStringLiteral(ast.node.arguments[2]) ? ast.node.arguments[2].value : 'default' + + if (enableImportComponent) { + const nativeName = cb(pathArg, nameArg, exportNameArg) + ast.replaceWith(t.stringLiteral(nativeName)) + } + } + }, + FunctionDeclaration(ast) { + if (t.isIdentifier(ast.node.id, { name: IMPORT_COMPONENT_NAME })) { + enableImportComponent = false + cb(false) + } + }, + ImportDeclaration(ast) { + ast.node.specifiers.forEach(specifier => { + if ( + (t.isImportSpecifier(specifier) || t.isImportDefaultSpecifier(specifier)) && + specifier.local.name === IMPORT_COMPONENT_NAME + ) { + enableImportComponent = false + cb(false) + } + }) + }, + VariableDeclarator(ast) { + if ( + t.isIdentifier(ast.node.id, { name: IMPORT_COMPONENT_NAME }) && + (t.isArrowFunctionExpression(ast.node.init) || + t.isFunctionExpression(ast.node.init)) + ) { + enableImportComponent = false + cb(false) + } + } + } + } + } +} diff --git a/packages/taro-vite-runner/src/common/babel-plugin-remove-config.ts b/packages/taro-vite-runner/src/common/babel-plugin-remove-config.ts new file mode 100644 index 000000000000..715db8286ad5 --- /dev/null +++ b/packages/taro-vite-runner/src/common/babel-plugin-remove-config.ts @@ -0,0 +1,22 @@ +import type * as BabelCore from '@babel/core' + +export default (id = '') => { + return function pluginRemovePageConfig (babel: typeof BabelCore): BabelCore.PluginObj { + const { types: t } = babel + + return { + name: 'plugin:remove_pageconfig', + visitor: { + CallExpression (nodePath, state) { + if (!/\.config\.(t|j)sx?$/.test(state.filename || id)) return + + const { callee } = nodePath.node + if (!t.isIdentifier(callee)) return + if (!['defineAppConfig', 'definePageConfig'].includes(callee.name)) return + + nodePath.remove() + } + } + } + } +} diff --git a/packages/taro-vite-runner/src/common/rollup-increment-plugin.ts b/packages/taro-vite-runner/src/common/rollup-plugin-increment.ts similarity index 100% rename from packages/taro-vite-runner/src/common/rollup-increment-plugin.ts rename to packages/taro-vite-runner/src/common/rollup-plugin-increment.ts diff --git a/packages/taro-vite-runner/src/common/assets.ts b/packages/taro-vite-runner/src/common/vite-plugin-assets.ts similarity index 97% rename from packages/taro-vite-runner/src/common/assets.ts rename to packages/taro-vite-runner/src/common/vite-plugin-assets.ts index c016a46c2c32..9ead395e69aa 100644 --- a/packages/taro-vite-runner/src/common/assets.ts +++ b/packages/taro-vite-runner/src/common/vite-plugin-assets.ts @@ -42,7 +42,7 @@ export default function (viteCompilerContext: ViteH5CompilerContext | ViteMiniCo return cachedValue } - const source = await fs.readFile(id) + const source = fs.readFileSync(id) const { imageUrlLoaderOption = {}, @@ -78,7 +78,7 @@ export default function (viteCompilerContext: ViteH5CompilerContext | ViteMiniCo const referenceId = this.emitFile({ type: 'asset', fileName, - source + source: Uint8Array.from(source) }) url = `__VITE_ASSET__${referenceId}__` } diff --git a/packages/taro-vite-runner/src/common/multi-platform-plugin.ts b/packages/taro-vite-runner/src/common/vite-plugin-multi-platform.ts similarity index 97% rename from packages/taro-vite-runner/src/common/multi-platform-plugin.ts rename to packages/taro-vite-runner/src/common/vite-plugin-multi-platform.ts index 5aa6de35958f..5ac71391d83b 100644 --- a/packages/taro-vite-runner/src/common/multi-platform-plugin.ts +++ b/packages/taro-vite-runner/src/common/vite-plugin-multi-platform.ts @@ -19,8 +19,8 @@ function isViteDepsPath(filePath: string) { return isViteDeps } -export default function (complier: ViteH5CompilerContext | ViteHarmonyCompilerContext | ViteMiniCompilerContext): PluginOption { - const { taroConfig } = complier +export default function (compiler: ViteH5CompilerContext | ViteHarmonyCompilerContext | ViteMiniCompilerContext): PluginOption { + const { taroConfig } = compiler return { name: 'taro:vite-multi-platform-plugin', diff --git a/packages/taro-vite-runner/src/h5/entry.ts b/packages/taro-vite-runner/src/h5/entry.ts index ecf28e14e940..cd8f030464d8 100644 --- a/packages/taro-vite-runner/src/h5/entry.ts +++ b/packages/taro-vite-runner/src/h5/entry.ts @@ -69,7 +69,7 @@ export default function (viteCompilerContext: ViteH5CompilerContext): PluginOpti this.emitFile({ type: 'asset', fileName, - source: await fs.readFile(filePath) + source: Uint8Array.from(fs.readFileSync(filePath)) }) this.addWatchFile(filePath) } diff --git a/packages/taro-vite-runner/src/h5/index.ts b/packages/taro-vite-runner/src/h5/index.ts index 74dce9b0c6f2..51bc260cb5af 100644 --- a/packages/taro-vite-runner/src/h5/index.ts +++ b/packages/taro-vite-runner/src/h5/index.ts @@ -1,5 +1,5 @@ -import assets from '../common/assets' -import multiPlatformPlugin from '../common/multi-platform-plugin' +import assets from '../common/vite-plugin-assets' +import multiPlatformPlugin from '../common/vite-plugin-multi-platform' import { getMode } from '../utils' import configPlugin from './config' import entryPlugin from './entry' diff --git a/packages/taro-vite-runner/src/harmony/config.ts b/packages/taro-vite-runner/src/harmony/config.ts index 48e5a917b9b4..43d4a38e389d 100644 --- a/packages/taro-vite-runner/src/harmony/config.ts +++ b/packages/taro-vite-runner/src/harmony/config.ts @@ -7,7 +7,7 @@ import { defaultMainFields, fs, PLATFORMS, recursiveMerge, REG_NODE_MODULES_DIR, import { getSassLoaderOption } from '@tarojs/runner-utils' import { isArray, PLATFORM_TYPE } from '@tarojs/shared' -import increment from '../common/rollup-increment-plugin' +import increment from '../common/rollup-plugin-increment' import { getDefaultPostcssConfig } from '../postcss/postcss.harmony' import { getBabelOption, getCSSModulesOptions, getMinify, getMode, getPostcssPlugins, isVirtualModule, stripMultiPlatformExt, stripVirtualModulePrefix, virtualModulePrefixREG } from '../utils' import { DEFAULT_TERSER_OPTIONS, HARMONY_SCOPES } from '../utils/constants' @@ -251,7 +251,7 @@ export default function (viteCompilerContext: ViteHarmonyCompilerContext): Plugi taroConfig, { babelOption: { - extensions: ['.js', '.jsx', '.ts', '.tsx', '.mjs', '.mts', '.es6', '.es', '.ets'], + extensions: ['.js', '.jsx', '.ts', '.tsx', '.es6', '.es', '.mjs', '.mts', '.ets'], }, } )), diff --git a/packages/taro-vite-runner/src/harmony/entry.ts b/packages/taro-vite-runner/src/harmony/entry.ts index 9029c5cbbb85..8056de9c1f64 100644 --- a/packages/taro-vite-runner/src/harmony/entry.ts +++ b/packages/taro-vite-runner/src/harmony/entry.ts @@ -29,7 +29,7 @@ export default function (viteCompilerContext: ViteHarmonyCompilerContext): Plugi } return null }, - load (id) { + async load (id) { if (viteCompilerContext && id.endsWith(ENTRY_SUFFIX)) { const rawId = stripVirtualModulePrefix(id).replace(ENTRY_SUFFIX, '') const { taroConfig, cwd: appPath, app } = viteCompilerContext @@ -49,7 +49,7 @@ export default function (viteCompilerContext: ViteHarmonyCompilerContext): Plugi const tabbar = appConfig.tabBar const parse = new AppParser(appPath, appConfig, taroConfig, viteCompilerContext.loaderMeta) // emit pages - viteCompilerContext.pages.forEach(page => { + await Promise.all(viteCompilerContext.pages.map(async page => { if (page.isNative) { const { sourceDir, nativeExt } = viteCompilerContext as ViteHarmonyCompilerContext const nativePath = resolveMainFilePath(path.join(sourceDir, page.name), nativeExt) @@ -67,19 +67,16 @@ export default function (viteCompilerContext: ViteHarmonyCompilerContext): Plugi fileName: viteCompilerContext.getScriptPath(page.name + TARO_COMP_SUFFIX), implicitlyLoadedAfterOneOf: [rawId] }) + await this.load({ + id: page.scriptPath, + resolveDependencies: true + }) } - }) + })) // native components for (const comp of viteCompilerContext.nativeComponents.values()) { - if (!comp.isPackage) { - this.emitFile({ - type: 'chunk', - id: comp.templatePath + QUERY_IS_NATIVE_SCRIPT, - fileName: path.relative(viteCompilerContext.sourceDir, comp.templatePath) + QUERY_IS_NATIVE_SCRIPT, - implicitlyLoadedAfterOneOf: [rawId] - }) - } + viteCompilerContext.generateNativeComponent(this, comp, [rawId]) } // emit tabbar @@ -94,7 +91,7 @@ export default function (viteCompilerContext: ViteHarmonyCompilerContext): Plugi this.emitFile({ type: 'asset', fileName: removePathPrefix(iconPath), - source: await fs.readFile(filePath) + source: Uint8Array.from(fs.readFileSync(filePath)) }) if (!isFinished) { this.addWatchFile(filePath) @@ -106,7 +103,7 @@ export default function (viteCompilerContext: ViteHarmonyCompilerContext): Plugi this.emitFile({ type: 'asset', fileName: removePathPrefix(selectedIconPath), - source: await fs.readFile(filePath) + source: Uint8Array.from(fs.readFileSync(filePath)) }) if (!isFinished) { this.addWatchFile(filePath) @@ -121,7 +118,7 @@ export default function (viteCompilerContext: ViteHarmonyCompilerContext): Plugi this.emitFile({ type: 'asset', fileName: appConfig.themeLocation, - source: fs.readFileSync(themePath) + source: Uint8Array.from(fs.readFileSync(themePath)) }) if (!isFinished) { this.addWatchFile(themePath) @@ -134,6 +131,10 @@ export default function (viteCompilerContext: ViteHarmonyCompilerContext): Plugi code: parse.parse(rawId, name, this.resolve), exports: ['default'], }) + await this.load({ + id: rawId, + resolveDependencies: true + }) return parse.parseEntry(rawId, appConfig) } }, diff --git a/packages/taro-vite-runner/src/harmony/index.ts b/packages/taro-vite-runner/src/harmony/index.ts index 4b79c94c2d6b..a194e8e926a3 100644 --- a/packages/taro-vite-runner/src/harmony/index.ts +++ b/packages/taro-vite-runner/src/harmony/index.ts @@ -1,4 +1,4 @@ -import multiPlatformPlugin from '../common/multi-platform-plugin' +import multiPlatformPlugin from '../common/vite-plugin-multi-platform' import { assetPlugin } from './asset' import importPlugin from './babel' import { compileModePrePlugin } from './compile' diff --git a/packages/taro-vite-runner/src/harmony/page.ts b/packages/taro-vite-runner/src/harmony/page.ts index c17f53f6589f..371200fca0dd 100644 --- a/packages/taro-vite-runner/src/harmony/page.ts +++ b/packages/taro-vite-runner/src/harmony/page.ts @@ -1,23 +1,50 @@ import path from 'node:path' +import { transformSync } from '@babel/core' import { removeHeadSlash } from '@tarojs/helper' -import { addLeadingSlash, appendVirtualModulePrefix, stripVirtualModulePrefix, virtualModulePrefixREG } from '../utils' +import pluginImportNativeComponent from '../common/babel-plugin-import-native-component' +import pluginRemovePageConfig from '../common/babel-plugin-remove-config' +import { addLeadingSlash, appendVirtualModulePrefix, escapePath, stripVirtualModulePrefix, virtualModulePrefixREG } from '../utils' +import { createFilterWithCompileOptions } from '../utils/createFilter' +import { UniqueKeyMap } from '../utils/map' import { PageParser } from './template' import type { ViteHarmonyCompilerContext } from '@tarojs/taro/types/compile/viteCompilerContext' -import type { PluginOption } from 'vite' +import type { PluginOption, ResolvedConfig } from 'vite' import type { TaroHarmonyPageMeta } from './template/page' export const PAGE_SUFFIX = '?page-loader=true' export const TARO_TABBAR_PAGE_PATH = 'taro_tabbar' +const nativeComponentMapCache = new WeakMap>>() +const nativeUniqueKeyMap = new WeakMap>() export default function (viteCompilerContext: ViteHarmonyCompilerContext): PluginOption { const name = 'taro:vite-harmony-page' + const { taroConfig, sourceDir } = viteCompilerContext + const filter = createFilterWithCompileOptions(taroConfig.compile, [sourceDir, /(?<=node_modules[\\/]).*taro/], []) + + let viteConfig: ResolvedConfig + let nCompCache: Map> + let nCompUniqueKeyMap: UniqueKeyMap return { name, enforce: 'pre', + configResolved(config) { + viteConfig = config + }, + buildStart() { + if (nativeComponentMapCache.has(viteConfig)) { + nCompCache = nativeComponentMapCache.get(viteConfig)! + nCompUniqueKeyMap = nativeUniqueKeyMap.get(viteConfig)! + } else { + nCompCache = new Map>() + nativeComponentMapCache.set(viteConfig, nCompCache) + nCompUniqueKeyMap = new UniqueKeyMap() + nativeUniqueKeyMap.set(viteConfig, nCompUniqueKeyMap) + } + }, resolveId (source, importer, options) { if ((viteCompilerContext?.isPage(source) || viteCompilerContext?.isComponent(source)) && options.isEntry) { if (viteCompilerContext.getPageById(source)?.isNative) return null @@ -73,6 +100,28 @@ export default function (viteCompilerContext: ViteHarmonyCompilerContext): Plugi code: parse.parse(tabbarId, tabbarPages as TaroHarmonyPageMeta[], name, this.resolve), exports: ['default'], }) + tabbarPages.forEach(async page => { + const deps = await viteCompilerContext.collectedDeps(this, escapePath(page.scriptPath), filter) + const ncObj: Record = {} + deps.forEach(dep => { + Object.entries(nCompCache.get(dep) || {}).forEach(([key, value]) => { + const absPath = value[0] + const ext = path.extname(absPath) + const basename = path.basename(absPath, ext) + ncObj[key] = [path.join(path.dirname(path.relative(path.dirname(rawId), absPath)), basename), value[1]] + }) + }) + if (!page.isNative) { + page.config.usingComponents = { + ...page.config.usingComponents, + ...ncObj, + } + } + const nativeComps = viteCompilerContext.collectNativeComponents(page) + nativeComps.forEach(comp => { + viteCompilerContext.generateNativeComponent(this, comp, [rawId]) + }) + }) } } else { const list: string[] = [] @@ -105,10 +154,69 @@ export default function (viteCompilerContext: ViteHarmonyCompilerContext): Plugi code: parse.parse(path.resolve(appRoot, pageName), page_, name, this.resolve), exports: ['default'], }) + viteCompilerContext.collectedDeps(this, escapePath(rawId), filter).then(deps => { + const ncObj: Record = {} + deps.forEach(dep => { + Object.entries(nCompCache.get(dep) || {}).forEach(([key, value]) => { + const absPath = value[0] + const ext = path.extname(absPath) + const basename = path.basename(absPath, ext) + ncObj[key] = [path.join(path.dirname(path.relative(path.dirname(rawId), absPath)), basename), value[1]] + }) + }) + if (!page.isNative) { + page.config.usingComponents = { + ...page.config.usingComponents, + ...ncObj, + } + } + const nativeComps = viteCompilerContext.collectNativeComponents(page) + nativeComps.forEach(comp => { + viteCompilerContext.generateNativeComponent(this, comp, [rawId]) + }) + }) }) } return parse.parseEntry(rawId, page as TaroHarmonyPageMeta) } }, + transform(code, id) { + if (/\.m?[jt]sx?$/.test(id) && filter(id)) { + const scopeNativeComp = new Map() + let enableImportComponent = true + + const result = transformSync(code, { + filename: id, + parserOpts: { + plugins: [ + 'jsx', + 'typescript', + ], + }, + plugins: [ + pluginRemovePageConfig(id), + pluginImportNativeComponent(viteCompilerContext, id, (path, name = '', exportName = '') => { + if (path === false) { + enableImportComponent = false + return '' + } + + let key = `${name}${exportName !== 'default' ? `_${exportName}` : ''}`.toLowerCase() + key = nCompUniqueKeyMap.add(key, path) + scopeNativeComp.set(key, [path, exportName]) + return key + }), + ] + }) + + if (enableImportComponent) { + nCompCache.set(id, Object.fromEntries(scopeNativeComp)) + return { + code: result?.code || code, + map: result?.map || null, + } + } + } + } } } diff --git a/packages/taro-vite-runner/src/harmony/template/render.ts b/packages/taro-vite-runner/src/harmony/template/render.ts index 64129d4355e9..8f59644d4330 100644 --- a/packages/taro-vite-runner/src/harmony/template/render.ts +++ b/packages/taro-vite-runner/src/harmony/template/render.ts @@ -113,12 +113,16 @@ export default class RenderParser extends BaseParser { }) this.context.nativeComponents.forEach((meta) => { + const name = meta.exportName === 'default' ? meta.name : `{ ${meta.exportName} as ${meta.name} }` if (meta.isPackage) { - importList.push(`import ${meta.name} from '${meta.scriptPath}'`) + importList.push(`import ${name} from '${meta.scriptPath}'`) } else { - const nativePath = path.posix.relative(this.context.sourceDir, meta.scriptPath) - .replace(/[\\/]+/g, '/').replace(/\.ets$/, '') - importList.push(`import ${meta.name} from './${nativePath}'`) + const etx = path.extname(meta.scriptPath) + const nativePath = path.posix + .relative(this.context.sourceDir, meta.scriptPath) + .replace(/[\\/]+/g, '/') + .replace(new RegExp(`\\${etx}$`), '') + importList.push(`import ${name} from './${nativePath}'`) } }) @@ -280,13 +284,13 @@ export default class RenderParser extends BaseParser { name: 'StickySection', condition: `item.tagName === 'STICKY-SECTION'`, type: 'TaroViewElement', - extra: '.reuseId(item._nid.toString())' + extra: '.reuseId(item._nid.toString())', }, { name: 'ListView', condition: `item.tagName === 'LIST-VIEW'`, type: 'TaroViewElement', - extra: '.reuseId(item._nid.toString())' + extra: '.reuseId(item._nid.toString())', }, { name: 'View', @@ -309,7 +313,7 @@ export default class RenderParser extends BaseParser { name, condition: `item.tagName === '${name.replace(new RegExp('(?<=.)([A-Z])', 'g'), '-$1').toUpperCase()}'`, args: [], - fullArgument: 'item._attrs as TaroAny' + fullArgument: 'item._attrs as TaroAny', }) }) diff --git a/packages/taro-vite-runner/src/mini/entry.ts b/packages/taro-vite-runner/src/mini/entry.ts index 10b870791cad..4eb0136afd84 100644 --- a/packages/taro-vite-runner/src/mini/entry.ts +++ b/packages/taro-vite-runner/src/mini/entry.ts @@ -5,7 +5,7 @@ import { isString } from '@tarojs/shared' import { appendVirtualModulePrefix, escapePath, prettyPrintJson, stripVirtualModulePrefix } from '../utils' import { baseCompName, customWrapperName } from '../utils/constants' -import { miniTemplateLoader, QUERY_IS_NATIVE_COMP, QUERY_IS_NATIVE_PAGE } from './native-support' +import { miniTemplateLoader, QUERY_IS_NATIVE_PAGE } from './native-support' import type { ViteMiniCompilerContext } from '@tarojs/taro/types/compile/viteCompilerContext' import type { PluginOption } from 'vite' @@ -22,7 +22,7 @@ export default function (viteCompilerContext: ViteMiniCompilerContext): PluginOp } return null }, - load (id) { + async load (id) { if (viteCompilerContext && id.endsWith(ENTRY_SUFFIX)) { const rawId = stripVirtualModulePrefix(id).replace(ENTRY_SUFFIX, '') const { taroConfig, app } = viteCompilerContext @@ -56,7 +56,7 @@ export default function (viteCompilerContext: ViteMiniCompilerContext): PluginOp } // pages - viteCompilerContext.pages.forEach(page => { + viteCompilerContext.pages.forEach(async page => { // 小程序原生页面 if (page.isNative) { if (page.templatePath) { @@ -79,19 +79,7 @@ export default function (viteCompilerContext: ViteMiniCompilerContext): PluginOp // native components for (const comp of viteCompilerContext.nativeComponents.values()) { - this.emitFile({ - type: 'chunk', - id: comp.scriptPath + QUERY_IS_NATIVE_COMP, - fileName: viteCompilerContext.getScriptPath(comp.name), - implicitlyLoadedAfterOneOf: [rawId] - }) - const source = miniTemplateLoader(this, comp.templatePath, viteCompilerContext.sourceDir) - this.emitFile({ - type: 'asset', - fileName: viteCompilerContext.getTemplatePath(comp.name), - source - }) - comp.cssPath && this.addWatchFile(comp.cssPath) + viteCompilerContext.generateNativeComponent(this, comp, [rawId]) } // comp' script @@ -123,7 +111,7 @@ export default function (viteCompilerContext: ViteMiniCompilerContext): PluginOp this.emitFile({ type: 'asset', fileName: removePathPrefix(iconPath), - source: await fs.readFile(filePath) + source: Uint8Array.from(fs.readFileSync(filePath)) }) this.addWatchFile(filePath) } @@ -133,7 +121,7 @@ export default function (viteCompilerContext: ViteMiniCompilerContext): PluginOp this.emitFile({ type: 'asset', fileName: removePathPrefix(selectedIconPath), - source: await fs.readFile(filePath) + source: Uint8Array.from(fs.readFileSync(filePath)) }) this.addWatchFile(filePath) } @@ -146,7 +134,7 @@ export default function (viteCompilerContext: ViteMiniCompilerContext): PluginOp this.emitFile({ type: 'asset', fileName: appConfig.themeLocation, - source: fs.readFileSync(themePath) + source: Uint8Array.from(fs.readFileSync(themePath)) }) this.addWatchFile(themePath) } diff --git a/packages/taro-vite-runner/src/mini/index.ts b/packages/taro-vite-runner/src/mini/index.ts index b70e847a693a..700081d08415 100644 --- a/packages/taro-vite-runner/src/mini/index.ts +++ b/packages/taro-vite-runner/src/mini/index.ts @@ -1,5 +1,5 @@ -import assetsPlugin from '../common/assets' -import multiPlatformPlugin from '../common/multi-platform-plugin' +import assetsPlugin from '../common/vite-plugin-assets' +import multiPlatformPlugin from '../common/vite-plugin-multi-platform' import configPlugin from './config' import emitPlugin from './emit' import entryPlugin from './entry' diff --git a/packages/taro-vite-runner/src/mini/native-support.ts b/packages/taro-vite-runner/src/mini/native-support.ts index 074dc0f67e76..f742a25cde68 100644 --- a/packages/taro-vite-runner/src/mini/native-support.ts +++ b/packages/taro-vite-runner/src/mini/native-support.ts @@ -71,7 +71,7 @@ export default function (viteCompilerContext: ViteMiniCompilerContext | undefine } else if (IS_NATIVE_STYLE_REG.test(id)) { let source = id.replace(new RegExp(`\\${QUERY_IS_NATIVE_STYLE}`), '') source = viteCompilerContext.getTargetFilePath(source, viteCompilerContext.fileType.style) - const code = await fs.readFile(source, 'utf-8') + const code = fs.readFileSync(source, 'utf-8') return { code } @@ -157,7 +157,7 @@ export function miniTemplateLoader (ctx: PluginContext, templatePath: string, so ctx.emitFile({ type: 'asset', fileName: requests[i].replace(sourceDir, '').replace(/^\//, ''), - source: await fs.readFile(requests[i]) + source: Uint8Array.from(fs.readFileSync(requests[i])) }) ctx.addWatchFile(requests[i]) } diff --git a/packages/taro-vite-runner/src/mini/page.ts b/packages/taro-vite-runner/src/mini/page.ts index d0a73450ca29..dd774b852554 100644 --- a/packages/taro-vite-runner/src/mini/page.ts +++ b/packages/taro-vite-runner/src/mini/page.ts @@ -1,14 +1,45 @@ +import path from 'node:path' + +import { transformSync } from '@babel/core' + +import pluginImportNativeComponent from '../common/babel-plugin-import-native-component' +import pluginRemovePageConfig from '../common/babel-plugin-remove-config' import { appendVirtualModulePrefix, escapePath, prettyPrintJson, stripVirtualModulePrefix } from '../utils' +import { createFilterWithCompileOptions } from '../utils/createFilter' +import { UniqueKeyMap } from '../utils/map' import type { ViteMiniCompilerContext } from '@tarojs/taro/types/compile/viteCompilerContext' -import type { PluginOption } from 'vite' +import type { PluginOption, ResolvedConfig } from 'vite' -const PAGE_SUFFIX = '?page-loader=true' +export const PAGE_SUFFIX = '?page-loader=true' +const nativeComponentMapCache = new WeakMap>>() +const nativeUniqueKeyMap = new WeakMap>() export default function (viteCompilerContext: ViteMiniCompilerContext): PluginOption { + const { taroConfig, sourceDir } = viteCompilerContext + const filter = createFilterWithCompileOptions(taroConfig.compile, [sourceDir, /(?<=node_modules[\\/]).*taro/], []) + + let viteConfig: ResolvedConfig + let nCompCache: Map> + let nCompUniqueKeyMap: UniqueKeyMap + return { name: 'taro:vite-mini-page', enforce: 'pre', + configResolved(config) { + viteConfig = config + }, + buildStart() { + if (nativeComponentMapCache.has(viteConfig)) { + nCompCache = nativeComponentMapCache.get(viteConfig)! + nCompUniqueKeyMap = nativeUniqueKeyMap.get(viteConfig)! + } else { + nCompCache = new Map>() + nativeComponentMapCache.set(viteConfig, nCompCache) + nCompUniqueKeyMap = new UniqueKeyMap() + nativeUniqueKeyMap.set(viteConfig, nCompUniqueKeyMap) + } + }, resolveId (source, _importer, options) { if (viteCompilerContext?.isPage(source) && options.isEntry) { if (viteCompilerContext.getPageById(source)?.isNative) return null @@ -34,6 +65,28 @@ export default function (viteCompilerContext: ViteMiniCompilerContext): PluginOp instantiatePage = viteCompilerContext.loaderMeta.modifyInstantiate(instantiatePage, 'page') } + viteCompilerContext.collectedDeps(this, escapePath(rawId), filter).then(deps => { + const ncObj: Record = {} + deps.forEach(dep => { + Object.entries(nCompCache.get(dep) || {}).forEach(([key, value]) => { + const absPath = value + const ext = path.extname(absPath) + const basename = path.basename(absPath, ext) + ncObj[key] = path.join(path.dirname(path.relative(path.dirname(rawId), absPath)), basename) + }) + }) + if (!page.isNative) { + page.config.usingComponents = { + ...page.config.usingComponents, + ...ncObj, + } + } + const nativeComps = viteCompilerContext.collectNativeComponents(page) + nativeComps.forEach(comp => { + viteCompilerContext.generateNativeComponent(this, comp, [rawId]) + }) + }) + return [ 'import { createPageConfig } from "@tarojs/runtime"', `import component from "${escapePath(rawId)}"`, @@ -43,6 +96,44 @@ export default function (viteCompilerContext: ViteMiniCompilerContext): PluginOp instantiatePage, ].join('\n') } + }, + transform(code, id) { + if (/\.m?[jt]sx?$/.test(id) && filter(id)) { + const scopeNativeComp = new Map() + let enableImportComponent = true + + const result = transformSync(code, { + filename: id, + parserOpts: { + plugins: [ + 'jsx', + 'typescript', + ], + }, + plugins: [ + pluginRemovePageConfig(id), + pluginImportNativeComponent(viteCompilerContext, id, (path, name = '', exportName = '') => { + if (path === false) { + enableImportComponent = false + return '' + } + + let key = `${name}${exportName !== 'default' ? `_${exportName}` : ''}`.toLowerCase() + key = nCompUniqueKeyMap.add(key, path) + scopeNativeComp.set(key, path) + return key + }), + ] + }) + + if (enableImportComponent) { + nCompCache.set(id, Object.fromEntries(scopeNativeComp)) + return { + code: result?.code || code, + map: result?.map || null, + } + } + } } } } diff --git a/packages/taro-vite-runner/src/utils/compiler/base.ts b/packages/taro-vite-runner/src/utils/compiler/base.ts index 81162889a0bd..4c6846607b2d 100644 --- a/packages/taro-vite-runner/src/utils/compiler/base.ts +++ b/packages/taro-vite-runner/src/utils/compiler/base.ts @@ -54,6 +54,22 @@ export class CompilerContext ()): Promise> { + if (!/\.m?[jt]sx?$/.test(id) || !filter(id) || cache.has(id)) return cache + + cache.add(id) + const moduleInfo = await rollupCtx.load({ + id, + resolveDependencies: true, + }) + + await Promise.all(moduleInfo.importedIds.map(async (importedId) => { + return this.collectedDeps(rollupCtx, importedId, filter, cache) + })) + + return cache + } + watchConfigFile (rollupCtx: PluginContext) { this.configFileList.forEach((configFile) => rollupCtx.addWatchFile(configFile)) } diff --git a/packages/taro-vite-runner/src/utils/compiler/harmony.ts b/packages/taro-vite-runner/src/utils/compiler/harmony.ts index 8e2da1822881..092140b7ab5e 100644 --- a/packages/taro-vite-runner/src/utils/compiler/harmony.ts +++ b/packages/taro-vite-runner/src/utils/compiler/harmony.ts @@ -14,6 +14,7 @@ import { isArray, isFunction } from '@tarojs/shared' import JSON5 from 'json5' import defaultConfig from '../../defaultConfig/defaultConfig.harmony' +import { QUERY_IS_NATIVE_SCRIPT } from '../../harmony/ets' import { TARO_TABBAR_PAGE_PATH } from '../../harmony/page' import { componentConfig } from '../../utils/component' import { parseRelativePath } from '..' @@ -28,6 +29,7 @@ import type { ViteNativeCompMeta, VitePageMeta, } from '@tarojs/taro/types/compile/viteCompilerContext' +import type { PluginContext } from 'rollup' export function readJsonSync(file: string) { const ext = path.extname(file) @@ -120,24 +122,31 @@ export class TaroCompilerContext extends CompilerContext return pageMeta } - collectNativeComponents(meta: ViteAppMeta | VitePageMeta | ViteNativeCompMeta) { + resolvePageImportPath (scriptPath: string, importPath: string) { + const alias = this.taroConfig.alias + if (isAliasPath(importPath, alias)) { + importPath = replaceAliasPath(scriptPath, importPath, alias) + } + return importPath + } + + collectNativeComponents(meta: ViteAppMeta | VitePageMeta | ViteNativeCompMeta): ViteNativeCompMeta[] { const { name, scriptPath, config } = meta const { usingComponents } = config - if (!usingComponents) return + const list: ViteNativeCompMeta[] = [] + if (!usingComponents) return list - Object.entries(usingComponents).forEach(([compName, compPath]) => { - const alias = this.taroConfig.alias - - if (isAliasPath(compPath, alias)) { - compPath = replaceAliasPath(scriptPath, compPath, alias) - usingComponents[compName] = compPath - } + Object.entries(usingComponents).forEach(([compName, value]) => { + const compPath = value instanceof Array ? value[0] : value + const exportName = value instanceof Array ? value[1] : 'default' + usingComponents[compName] = this.resolvePageImportPath(scriptPath, compPath) // 如果是鸿蒙的包 if (this.ohpmPackageList?.length && new RegExp(`^(${this.ohpmPackageList.join('|')})`).test(compPath)) { const nativeCompMeta: ViteNativeCompMeta = { name: compName, + exportName, scriptPath: compPath, config: {}, configPath: '', @@ -163,6 +172,7 @@ export class TaroCompilerContext extends CompilerContext name: compName.replace(/(\w)-(\w)/g, (_, p1, p2) => { return p1 + p2.toUpperCase() }), + exportName, scriptPath: compScriptPath, config: {}, configPath: '', @@ -174,8 +184,21 @@ export class TaroCompilerContext extends CompilerContext componentConfig.thirdPartyComponents.set(compName, new Set()) } - this.collectNativeComponents(nativeCompMeta) + list.push(...this.collectNativeComponents(nativeCompMeta), nativeCompMeta) + }) + return list + } + + generateNativeComponent (rollupCtx: PluginContext, meta: ViteNativeCompMeta, implicitlyLoadedAfterOneOf: string[] = []) { + if (meta.isGenerated || meta.isPackage) return + + rollupCtx.emitFile({ + type: 'chunk', + id: meta.templatePath + QUERY_IS_NATIVE_SCRIPT, + fileName: path.relative(this.sourceDir, meta.templatePath) + QUERY_IS_NATIVE_SCRIPT, + implicitlyLoadedAfterOneOf }) + meta.isGenerated = true } modifyHarmonyResources(id = '', data: any = {}) { diff --git a/packages/taro-vite-runner/src/utils/compiler/mini.ts b/packages/taro-vite-runner/src/utils/compiler/mini.ts index 4a8a6349c834..dfa146b2c82e 100644 --- a/packages/taro-vite-runner/src/utils/compiler/mini.ts +++ b/packages/taro-vite-runner/src/utils/compiler/mini.ts @@ -11,6 +11,7 @@ import { import { isArray, isFunction } from '@tarojs/shared' import defaultConfig from '../../defaultConfig/defaultConfig.mini' +import { miniTemplateLoader, QUERY_IS_NATIVE_COMP } from '../../mini/native-support' import { getComponentName } from '../../utils' import { componentConfig } from '../../utils/component' import { CompilerContext } from './base' @@ -24,6 +25,7 @@ import type { ViteNativeCompMeta, VitePageMeta } from '@tarojs/taro/types/compile/viteCompilerContext' +import type { PluginContext } from 'rollup' export class TaroCompilerContext extends CompilerContext implements ViteMiniCompilerContext { fileType: ViteFileType @@ -87,21 +89,25 @@ export class TaroCompilerContext extends CompilerContext im return pageMeta } - collectNativeComponents (meta: ViteAppMeta | VitePageMeta | ViteNativeCompMeta) { + resolvePageImportPath (scriptPath: string, importPath: string) { + const alias = this.taroConfig.alias + if (isAliasPath(importPath, alias)) { + importPath = replaceAliasPath(scriptPath, importPath, alias) + } + return importPath + } + + collectNativeComponents (meta: ViteAppMeta | VitePageMeta | ViteNativeCompMeta): ViteNativeCompMeta[] { const { name, scriptPath, config } = meta const { usingComponents } = config - if (!usingComponents) return - Object.entries(usingComponents).forEach(([compName, compPath]) => { - const alias = this.taroConfig.alias - - if (isAliasPath(compPath, alias)) { - compPath = replaceAliasPath(scriptPath, compPath, alias) - usingComponents[compName] = compPath - } + const list: ViteNativeCompMeta[] = [] + if (!usingComponents) return list + Object.entries(usingComponents).forEach(([compName, value]) => { + const compPath = value instanceof Array ? value[0] : value + usingComponents[compName] = this.resolvePageImportPath(scriptPath, compPath) const compScriptPath = resolveMainFilePath(path.resolve(path.dirname(scriptPath), compPath)) - if (this.nativeComponents.has(compScriptPath)) return const configPath = this.getConfigPath(compScriptPath) @@ -114,6 +120,7 @@ export class TaroCompilerContext extends CompilerContext im const nativeCompMeta: ViteNativeCompMeta = { name: getComponentName(this, compScriptPath), + exportName: 'default', scriptPath: compScriptPath, configPath, config: readConfig(configPath) || {}, @@ -132,8 +139,28 @@ export class TaroCompilerContext extends CompilerContext im componentConfig.thirdPartyComponents.set(compName, new Set()) } - this.collectNativeComponents(nativeCompMeta) + list.push(...this.collectNativeComponents(nativeCompMeta), nativeCompMeta) + }) + return list + } + + generateNativeComponent (rollupCtx: PluginContext, meta: ViteNativeCompMeta, implicitlyLoadedAfterOneOf: string[] = []) { + if (meta.isGenerated) return + + rollupCtx.emitFile({ + type: 'chunk', + id: meta.scriptPath + QUERY_IS_NATIVE_COMP, + fileName: this.getScriptPath(meta.name), + implicitlyLoadedAfterOneOf, + }) + const source = miniTemplateLoader(rollupCtx, meta.templatePath, this.sourceDir) + rollupCtx.emitFile({ + type: 'asset', + fileName: this.getTemplatePath(meta.name), + source }) + meta.cssPath && rollupCtx.addWatchFile(meta.cssPath) + meta.isGenerated = true } /** 工具函数 */ diff --git a/packages/taro-vite-runner/src/utils/createFilter.ts b/packages/taro-vite-runner/src/utils/createFilter.ts index e69e9561ed7b..d1a6f56a221c 100644 --- a/packages/taro-vite-runner/src/utils/createFilter.ts +++ b/packages/taro-vite-runner/src/utils/createFilter.ts @@ -5,7 +5,7 @@ */ import path from 'node:path' -import { isArray } from '@tarojs/shared' +import { isArray, isFunction } from '@tarojs/shared' import pm from 'picomatch' function ensureArray(thing) { @@ -75,3 +75,25 @@ export default function createFilter(include, exclude, options?) { return !includeMatchers.length } } + +export function createFilterWithCompileOptions(compile: { + exclude?: any[] + include?: any[] + /** 对应 @rollup/plugin-babel 插件的 filter 配置。只在 vite 编译模式下有效 */ + filter?: (filename: string) => boolean +} = {}, defaultInclude: any[] = [], defaultExclude: any[] = []) { + if (isFunction(compile.filter)) { + return compile.filter + } else { + let exclude: (string | RegExp)[] = [...defaultInclude] + const include: (string | RegExp)[] = [...defaultExclude] + if (Array.isArray(compile.include)) { + include.unshift(...compile.include) + } + // Note:如果 compile 有 传递exclude,那么就进行覆盖,与 webpack5 逻辑保持一致 + if (Array.isArray(compile.exclude)) { + exclude = [...compile.exclude] + } + return createFilter(include, exclude) + } +} diff --git a/packages/taro-vite-runner/src/utils/index.ts b/packages/taro-vite-runner/src/utils/index.ts index c7668601201f..09c720582c85 100644 --- a/packages/taro-vite-runner/src/utils/index.ts +++ b/packages/taro-vite-runner/src/utils/index.ts @@ -5,7 +5,7 @@ import { isNpmPkg, normalizePath, recursiveMerge, REG_NODE_MODULES, resolveSync import { isFunction, isString } from '@tarojs/shared' import { backSlashRegEx, MINI_EXCLUDE_POSTCSS_PLUGIN_NAME, needsEscapeRegEx, quoteNewlineRegEx } from './constants' -import createFilter from './createFilter' +import { createFilterWithCompileOptions } from './createFilter' import { logger } from './logger' import type { RollupBabelInputPluginOptions } from '@rollup/plugin-babel' @@ -207,25 +207,7 @@ export function getBabelOption ( compact: false, ...babelOption, } - const filter = compile.filter - if (isFunction(filter)) { - opts.filter = filter - } else { - let exclude: (string | RegExp)[] = [...defaultExclude] - const include: (string | RegExp)[] = [...defaultInclude] - - if (Array.isArray(compile.include)) { - include.unshift(...compile.include) - } - - // Note:如果 compile 有 传递exclude,那么就进行覆盖,与 webpack5 逻辑保持一致 - if (Array.isArray(compile.exclude)) { - exclude = [...compile.exclude] - } - - const filter = createFilter(include, exclude) - opts.filter = filter - } + opts.filter = createFilterWithCompileOptions(compile, defaultInclude, defaultExclude) return opts } diff --git a/packages/taro-vite-runner/src/utils/map.ts b/packages/taro-vite-runner/src/utils/map.ts new file mode 100644 index 000000000000..eb46df8cd51e --- /dev/null +++ b/packages/taro-vite-runner/src/utils/map.ts @@ -0,0 +1,44 @@ +import { isEqual } from 'lodash' + +export class UniqueKeyMap { + store: Map + counters: Map + + constructor() { + this.store = new Map() + this.counters = new Map() + } + + add(key: string, value: T) { + if (!this.store.has(key)) { + this.store.set(key, value) + return key + } else if (isEqual(this.store.get(key), value)) { + return key + } + + let counter = this.counters.get(key) || 1 + let newKey = `${key}_${counter++}` + + while (this.store.has(newKey)) { + newKey = `${key}_${counter++}` + } + + this.counters.set(key, counter) + this.store.set(newKey, value) + return newKey + } + + get(key: string) { + return this.store.get(key) + } + + has(key: string) { + return this.store.has(key) + } + + // 获取所有存储的内容 + getAll() { + return Object.fromEntries(this.store) + } +} diff --git a/packages/taro-webpack5-prebundle/package.json b/packages/taro-webpack5-prebundle/package.json index ce7cf6ee8280..8f7306650825 100644 --- a/packages/taro-webpack5-prebundle/package.json +++ b/packages/taro-webpack5-prebundle/package.json @@ -1,6 +1,6 @@ { "name": "@tarojs/webpack5-prebundle", - "version": "4.0.8", + "version": "4.0.9-beta.2", "description": "Taro app webpack5 prebundle", "author": "O2Team", "license": "MIT", diff --git a/packages/taro-webpack5-runner/package.json b/packages/taro-webpack5-runner/package.json index 71b69c709104..fbdee1f82422 100644 --- a/packages/taro-webpack5-runner/package.json +++ b/packages/taro-webpack5-runner/package.json @@ -1,6 +1,6 @@ { "name": "@tarojs/webpack5-runner", - "version": "4.0.8", + "version": "4.0.9-beta.2", "description": "Taro app runner", "author": "O2Team", "license": "MIT", diff --git a/packages/taro-webpack5-runner/src/plugins/HarmonyPlugin.ts b/packages/taro-webpack5-runner/src/plugins/HarmonyPlugin.ts index 959bb26f726b..0fdfee9389b5 100644 --- a/packages/taro-webpack5-runner/src/plugins/HarmonyPlugin.ts +++ b/packages/taro-webpack5-runner/src/plugins/HarmonyPlugin.ts @@ -823,10 +823,11 @@ export default class TaroHarmonyPlugin { if (!usingComponents) return for (const [key, value] of Object.entries(usingComponents)) { - if (!value.includes(NODE_MODULES)) return + const compPath = value instanceof Array ? value[0] : value + if (!compPath.includes(NODE_MODULES)) return - const match = value.replace(NODE_MODULES, 'npm').match(/npm.*/) - usingComponents[key] = match ? `${path.sep}${match[0]}` : value + const match = compPath.replace(NODE_MODULES, 'npm').match(/npm.*/) + usingComponents[key] = match ? `${path.sep}${match[0]}` : compPath } } diff --git a/packages/taro-webpack5-runner/src/plugins/MiniPlugin.ts b/packages/taro-webpack5-runner/src/plugins/MiniPlugin.ts index 26b59f4c9ba2..eaaf55d0e95d 100644 --- a/packages/taro-webpack5-runner/src/plugins/MiniPlugin.ts +++ b/packages/taro-webpack5-runner/src/plugins/MiniPlugin.ts @@ -1109,10 +1109,11 @@ export default class TaroMiniPlugin { if (!usingComponents || this.options.skipProcessUsingComponents) return for (const [key, value] of Object.entries(usingComponents)) { - if (!value.includes(NODE_MODULES)) return + const compPath = value instanceof Array ? value[0] : value + if (!compPath.includes(NODE_MODULES)) return - const match = value.replace(NODE_MODULES, 'npm').match(/npm.*/) - usingComponents[key] = match ? `${path.sep}${match[0]}` : value + const match = compPath.replace(NODE_MODULES, 'npm').match(/npm.*/) + usingComponents[key] = match ? `${path.sep}${match[0]}` : compPath } } diff --git a/packages/taro-with-weapp/package.json b/packages/taro-with-weapp/package.json index d36ef3b24eed..ce7649d05f3a 100644 --- a/packages/taro-with-weapp/package.json +++ b/packages/taro-with-weapp/package.json @@ -1,6 +1,6 @@ { "name": "@tarojs/with-weapp", - "version": "4.0.8", + "version": "4.0.9-beta.2", "description": "taroize 之后的运行时", "author": "O2Team", "license": "MIT", diff --git a/packages/taro/package.json b/packages/taro/package.json index 33c99d3a302f..4e773b7623dc 100644 --- a/packages/taro/package.json +++ b/packages/taro/package.json @@ -1,6 +1,6 @@ { "name": "@tarojs/taro", - "version": "4.0.8", + "version": "4.0.9-beta.2", "description": "Taro framework", "author": "O2Team", "license": "MIT", diff --git a/packages/taro/types/api/media/audio.d.ts b/packages/taro/types/api/media/audio.d.ts index 0d8eedcac9f0..3a938cc0d168 100644 --- a/packages/taro/types/api/media/audio.d.ts +++ b/packages/taro/types/api/media/audio.d.ts @@ -740,7 +740,11 @@ declare module '../../index' { * ``` * @see https://developers.weixin.qq.com/miniprogram/dev/api/media/audio/WebAudioContext.decodeAudioData.html */ - decodeAudioData(): AudioBuffer + decodeAudioData( + audioData: ArrayBuffer, + successCallback: (buffer: AudioBuffer) => void, + errorCallback: (error: any) => void + ): Promise } namespace WebAudioContext { diff --git a/packages/taro/types/compile/viteCompilerContext.d.ts b/packages/taro/types/compile/viteCompilerContext.d.ts index 48f11ede8203..25e66ab27f29 100644 --- a/packages/taro/types/compile/viteCompilerContext.d.ts +++ b/packages/taro/types/compile/viteCompilerContext.d.ts @@ -9,6 +9,7 @@ import type { AppConfig, PageConfig } from '../index' export interface ViteNativeCompMeta { name: string + exportName: string scriptPath: string configPath: string config: PageConfig @@ -16,6 +17,7 @@ export interface ViteNativeCompMeta { templatePath: string cssPath?: string isPackage?: boolean + isGenerated?: boolean } export interface ViteFileType { @@ -109,6 +111,7 @@ export interface ViteCompilerContext { configFileList: string[] compilePage: (pageName: string) => VitePageMeta watchConfigFile: (rollupCtx: PluginContext) => void + collectedDeps: (rollupCtx: PluginContext, id: string, filter, cache: Set = new Set()) => Promise> getAppScriptPath: () => string getApp: () => ViteAppMeta getPages: () => VitePageMeta[] @@ -140,7 +143,9 @@ export interface ViteHarmonyCompilerContext extends ViteCompilerContext string[] modifyHarmonyConfig: (config: Partial) => void modifyHostPackage: (deps?: Record, devDeps?: Record) => Exclude - collectNativeComponents: (meta: ViteAppMeta | VitePageMeta | ViteNativeCompMeta) => void + resolvePageImportPath: (scriptPath: string, pageName: string) => string + collectNativeComponents: (meta: ViteAppMeta | VitePageMeta | ViteNativeCompMeta) => ViteNativeCompMeta[] + generateNativeComponent: (rollupCtx: PluginContext, meta: ViteNativeCompMeta, implicitlyLoadedAfterOneOf: string[] = []) => void getScriptPath: (filePath: string) => string getStylePath: (filePath: string) => string getConfigPath: (filePath: string) => string @@ -151,7 +156,9 @@ export interface ViteMiniCompilerContext extends ViteCompilerContext getCommonChunks: () => string[] - collectNativeComponents: (meta: ViteAppMeta | VitePageMeta | ViteNativeCompMeta) => void + resolvePageImportPath: (scriptPath: string, pageName: string) => string + collectNativeComponents: (meta: ViteAppMeta | VitePageMeta | ViteNativeCompMeta) => ViteNativeCompMeta[] + generateNativeComponent: (rollupCtx: PluginContext, meta: ViteNativeCompMeta, implicitlyLoadedAfterOneOf: string[] = []) => void getScriptPath: (filePath: string) => string getTemplatePath: (filePath: string) => string getStylePath: (filePath: string) => string diff --git a/packages/taro/types/index.d.ts b/packages/taro/types/index.d.ts index da8ec8360884..de679c27cfe1 100644 --- a/packages/taro/types/index.d.ts +++ b/packages/taro/types/index.d.ts @@ -192,4 +192,5 @@ declare namespace Taro { declare global { const defineAppConfig: (config: Taro.AppConfig) => Taro.AppConfig const definePageConfig: (config: Taro.PageConfig) => Taro.Config + const importNativeComponent: (path: string, name = '', exportName = 'default') => Awaited } diff --git a/packages/taro/types/taro.config.d.ts b/packages/taro/types/taro.config.d.ts index 1bae7fbde63f..5113b2b18d4f 100644 --- a/packages/taro/types/taro.config.d.ts +++ b/packages/taro/types/taro.config.d.ts @@ -193,7 +193,7 @@ declare module './index' { /** 页面自定义组件配置 * @see https://developers.weixin.qq.com/miniprogram/dev/framework/custom-component/ */ - usingComponents?: Record + usingComponents?: Record /** 指定使用升级后的 weui 样式 * - v2: 可表明启用新版的组件样式 * @default default diff --git a/packages/taroize/package.json b/packages/taroize/package.json index 711addcf9441..5a18df538318 100644 --- a/packages/taroize/package.json +++ b/packages/taroize/package.json @@ -1,6 +1,6 @@ { "name": "@tarojs/taroize", - "version": "4.0.8", + "version": "4.0.9-beta.2", "description": "转换原生微信小程序代码为 Taro 代码", "author": "O2Team", "license": "MIT",