diff --git a/.eslintignore b/.eslintignore index 8c511519b182..a8d074bc5e20 100644 --- a/.eslintignore +++ b/.eslintignore @@ -1,6 +1,7 @@ dist dist-h5 lib +!**/src/lib node_modules *.d.ts *.ets @@ -15,14 +16,7 @@ packages/taro-components/loader packages/taro-components/src/components packages/taro-components-library-react/components.ts packages/taro-components-library-vue3/components.ts -packages/taro-components-library-vue3/components.ts - -packages/taro-webpack-runner/src/__tests__/__snapshots__ -packages/taro-webpack-runner/src/__tests__/fixtures -packages/taro-mini-runner/src/__tests__/__snapshots__ -packages/taro-mini-runner/src/__tests__/fixtures -packages/taro-mini-runner/src/quickapp packages/taro-webpack5-runner/src/__tests__/__snapshots__ packages/taro-webpack5-runner/src/__tests__/fixtures packages/taro-webpack5-runner/src/__tests__/bundled @@ -32,6 +26,7 @@ packages/taro/types packages/taro-router/__tests__ packages/taro-rn-style-transformer/src/transforms/StyleSheet +packages/taro-rn/src/lib/index.ts packages/taro-rn/src/__tests__ packages/taro-runtime/src/polyfill diff --git a/.github/workflows/nodejs.yml b/.github/workflows/nodejs.yml index 41af1bc5e212..783fb7b81dd2 100644 --- a/.github/workflows/nodejs.yml +++ b/.github/workflows/nodejs.yml @@ -133,7 +133,7 @@ jobs: with: move_coverage_to_trash: true flags: taro-runner - files: ./packages/taro-webpack5-runner/coverage/clover.xml,./packages/taro-webpack-runner/coverage/clover.xml,./packages/taro-mini-runner/coverage/clover.xml + files: ./packages/taro-webpack5-runner/coverage/clover.xml token: ${{ secrets.CODECOV_TOKEN }} - name: Upload [taro-runtime] coverage to Codecov uses: codecov/codecov-action@v4 diff --git a/.pnpmfile.cjs b/.pnpmfile.cjs new file mode 100644 index 000000000000..b325287da3e4 --- /dev/null +++ b/.pnpmfile.cjs @@ -0,0 +1,14 @@ +module.exports = { + hooks: { + readPackage: (pkg) => { + // @stencil/core 没有锁住 jest 的版本,所以需要手动锁住 + if (pkg.name === '@stencil/core') { + pkg.dependencies = { + 'jest-runner': '27.5.1', + 'jest-environment-node': '27.5.1', + } + } + return pkg + }, + }, +}; diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 6ca77940c05a..67574c6f0615 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -114,7 +114,7 @@ $ npm run clear-all **注意:** -`@tarojs/mini-runner`、`@tarojs/webpack-runner`、`@tarojs/webpack5-runner` 使用了 `snapshot`(测试结果快照)。在修改这两个包或其它一些包时,有可能导致这些快照失效,从而通过不了测试。当你修改了这两个包、或 Github CI 提示这些包的测试用例出错时,请运行 `pnpm --filter [package-name] runupdateSnapshot` 更新 snapshot 后重新提交。 +`@tarojs/webpack5-runner` 使用了 `snapshot`(测试结果快照)。在修改这两个包或其它一些包时,有可能导致这些快照失效,从而通过不了测试。当你修改了这两个包、或 Github CI 提示这些包的测试用例出错时,请运行 `pnpm --filter [package-name] runupdateSnapshot` 更新 snapshot 后重新提交。 ### 5. 代码风格 diff --git a/LICENSE b/LICENSE index d8572bc88d6f..e35a8840acfa 100644 --- a/LICENSE +++ b/LICENSE @@ -154,15 +154,8 @@ See `/LICENSE` for details of the license. ================== -MIT (stencil-vue2-output-target): -The following files embed [stencil-vue2-output-target](https://github.com/diondree/stencil-vue2-output-target) MIT: -`/packages/taro-components-library-vue2/src/vue-component-lib/utils.ts` -See `/LICENSE` for details of the license. - -================== - MIT (weui): -The following files embed [stencil-vue2-output-target](https://github.com/Tencent/weui) MIT: +The following files embed [weui](https://github.com/Tencent/weui) MIT: `/packages/taro-components/src/components/*.scss` See `/LICENSE.txt` for details of the license. diff --git a/codecov.yml b/codecov.yml index 5e0e45b7ea60..05d1fcb37246 100644 --- a/codecov.yml +++ b/codecov.yml @@ -35,8 +35,6 @@ flag_management: - name: taro-runner paths: - packages/taro-webpack5-runner/ - - packages/taro-webpack-runner/ - - packages/taro-mini-runner/ - name: taro-runtime paths: - packages/taro-runtime/ diff --git a/crates/native_binding/binding.d.ts b/crates/native_binding/binding.d.ts index 5750126ae14c..810348734478 100644 --- a/crates/native_binding/binding.d.ts +++ b/crates/native_binding/binding.d.ts @@ -51,7 +51,6 @@ export const enum CSSType { export const enum FrameworkType { React = 'React', Preact = 'Preact', - Vue = 'Vue', Vue3 = 'Vue3' } diff --git a/crates/native_binding/package.json b/crates/native_binding/package.json index 8cddf34c5c43..72f9dcd847d1 100644 --- a/crates/native_binding/package.json +++ b/crates/native_binding/package.json @@ -1,6 +1,6 @@ { "name": "@tarojs/binding", - "version": "4.0.0-beta.75", + "version": "4.0.0-alpha.4", "description": "Node binding for taro", "main": "binding.js", "typings": "binding.d.ts", diff --git a/crates/taro_init/src/constants.rs b/crates/taro_init/src/constants.rs index 6f827261b927..a14168329150 100644 --- a/crates/taro_init/src/constants.rs +++ b/crates/taro_init/src/constants.rs @@ -29,7 +29,6 @@ pub static FRAMEWORK_TYPE_MAP: Lazy> = Lazy::new(| let mut map = HashMap::new(); map.insert(&FrameworkType::Preact, "preact"); map.insert(&FrameworkType::React, "react"); - map.insert(&FrameworkType::Vue, "vue"); map.insert(&FrameworkType::Vue3, "vue3"); map }); @@ -95,7 +94,6 @@ pub enum CSSType { pub enum FrameworkType { React, Preact, - Vue, Vue3, } diff --git a/crates/taro_init/src/creator.rs b/crates/taro_init/src/creator.rs index 9072201fa432..a01a7cac72a1 100644 --- a/crates/taro_init/src/creator.rs +++ b/crates/taro_init/src/creator.rs @@ -206,11 +206,7 @@ impl Creator { for file in files { let file_relative_path = normalize_path_str(file.replace(template_path, "").as_str()); let framework = options.framework; - let is_vue_framework = if let Some(framework) = framework { - framework == FrameworkType::Vue || framework == FrameworkType::Vue3 - } else { - false - }; + let is_vue_framework = framework.is_some_and(|framework| framework == FrameworkType::Vue3); if is_vue_framework && file_relative_path.ends_with(".jsx") { continue; } diff --git a/examples/blended-taro-component-vue3/taro-project/package.json b/examples/blended-taro-component-vue3/taro-project/package.json index e034a17ec9fe..65ac859a9f12 100644 --- a/examples/blended-taro-component-vue3/taro-project/package.json +++ b/examples/blended-taro-component-vue3/taro-project/package.json @@ -62,7 +62,6 @@ "eslint-plugin-vue": "^8.0.0", "jest": "^29.3.1", "jest-environment-jsdom": "^29.5.0", - "postcss": "^8.4.18", "style-loader": "1.3.0", "stylelint": "^14.4.0", "ts-node": "^10.9.1", diff --git a/examples/external-prebundle/package.json b/examples/external-prebundle/package.json index e96554b9b096..a70b6dc8518a 100644 --- a/examples/external-prebundle/package.json +++ b/examples/external-prebundle/package.json @@ -38,7 +38,7 @@ "jest-resolve": "^27.4.2", "jest-watch-typeahead": "^1.0.0", "mini-css-extract-plugin": "^2.4.5", - "postcss": "^8.4.4", + "postcss": "^8.4.38", "postcss-flexbugs-fixes": "^5.0.2", "postcss-loader": "^6.2.1", "postcss-normalize": "^10.0.1", diff --git a/examples/mini-program-example/package.json b/examples/mini-program-example/package.json index 018d091f750d..c195a08b9d28 100644 --- a/examples/mini-program-example/package.json +++ b/examples/mini-program-example/package.json @@ -79,7 +79,7 @@ "@typescript-eslint/parser": "^5.20.0", "@typescript-eslint/eslint-plugin": "^5.20.0", "typescript": "^4.1.0", - "postcss": "^8.4.18", + "postcss": "^8.4.38", "ts-node": "^10.9.1", "@types/node": "^18.15.11" } diff --git a/examples/taro-list/package.json b/examples/taro-list/package.json index de778e0d38e3..976d3371ebbc 100644 --- a/examples/taro-list/package.json +++ b/examples/taro-list/package.json @@ -80,7 +80,7 @@ "@typescript-eslint/eslint-plugin": "^6.2.0", "typescript": "^5.1.0", "tsconfig-paths-webpack-plugin": "^4.1.0", - "postcss": "^8.4.18", + "postcss": "^8.4.38", "ts-node": "^10.9.1", "@types/node": "^18.15.11", "@types/jest": "^29.3.1", diff --git a/npm/darwin-arm64/package.json b/npm/darwin-arm64/package.json index 45cee17d6bf3..24e88ca0c918 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.0-beta.75", + "version": "4.0.0-alpha.4", "os": [ "darwin" ], diff --git a/npm/darwin-x64/package.json b/npm/darwin-x64/package.json index ba9e818ab3b0..a18e8e33866b 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.0-beta.75", + "version": "4.0.0-alpha.4", "os": [ "darwin" ], diff --git a/npm/linux-x64-gnu/package.json b/npm/linux-x64-gnu/package.json index 7554a32d592c..5bb9fbb6ed61 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.0-beta.75", + "version": "4.0.0-alpha.4", "os": [ "linux" ], diff --git a/npm/linux-x64-musl/package.json b/npm/linux-x64-musl/package.json index 1cbc26787e6b..9eb5e377a299 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.0-beta.75", + "version": "4.0.0-alpha.4", "os": [ "linux" ], diff --git a/npm/win32-x64-msvc/package.json b/npm/win32-x64-msvc/package.json index 1d740bfd502a..f7c6c0fe57c9 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.0-beta.75", + "version": "4.0.0-alpha.4", "os": [ "win32" ], diff --git a/package.json b/package.json index ebdf568e4fd3..c4bf28c64fab 100644 --- a/package.json +++ b/package.json @@ -1,13 +1,12 @@ { "name": "taro", - "version": "4.0.0-beta.75", + "version": "4.0.0-alpha.4", "description": "开放式跨端跨框架开发解决方案", "homepage": "https://github.com/NervJS/taro#readme", "author": "O2Team", "private": true, "license": "MIT", "keywords": [ - "nerv", "taro" ], "bugs": { @@ -21,7 +20,7 @@ "scripts": { "preinstall": "npx only-allow pnpm", "prepare": "husky install", - "build": "pnpm -r --filter=./packages/* build", + "build": "pnpm -r --filter=./packages/* prod", "build:binding:debug": "pnpm --filter @tarojs/binding run build:debug", "build:binding:release": "pnpm --filter @tarojs/binding run build", "format::rs": "cargo fmt --all", @@ -47,85 +46,73 @@ "prettier --write" ] }, + "taroTemp": [ + "@types/babel__core", + "@types/babel-types", + "@types/babel__traverse", + "@babel/cli", + "@babel/core", + "@babel/helper-plugin-utils", + "@babel/parser", + "@babel/plugin-proposal-class-properties", + "@babel/plugin-proposal-decorators", + "@babel/plugin-proposal-do-expressions", + "@babel/plugin-proposal-object-rest-spread", + "@babel/plugin-syntax-dynamic-import", + "@babel/plugin-transform-react-jsx", + "@babel/plugin-transform-runtime", + "@babel/preset-env", + "@babel/preset-react", + "@babel/preset-typescript", + "@babel/runtime", + "@babel/traverse", + "@babel/types", + "babel-plugin-syntax-jsx", + "babel-preset-power-assert", + "'@types/react': '^18.0.0',", + "'@types/react-dom': '^18.0.0',", + "'@types/react-reconciler': '0.28.1'," + ], "devDependencies": { - "@babel/cli": "^7.14.5", - "@babel/core": "^7.14.5", - "@babel/helper-plugin-utils": "^7.14.5", - "@babel/parser": "^7.14.5", - "@babel/plugin-proposal-class-properties": "^7.14.5", - "@babel/plugin-proposal-decorators": "^7.14.5", - "@babel/plugin-proposal-do-expressions": "^7.14.5", - "@babel/plugin-proposal-object-rest-spread": "^7.14.5", - "@babel/plugin-syntax-dynamic-import": "7.8.3", - "@babel/plugin-transform-react-jsx": "^7.14.5", - "@babel/plugin-transform-runtime": "^7.14.5", - "@babel/preset-env": "^7.14.5", - "@babel/preset-react": "^7.22.15", - "@babel/preset-typescript": "^7.14.5", - "@babel/runtime": "^7.14.5", - "@babel/traverse": "^7.14.5", - "@babel/types": "^7.14.5", + "@babel/cli": "^7.24.1", + "@babel/core": "^7.24.4", + "@babel/preset-env": "^7.24.4", + "@babel/runtime": "^7.24.4", "@commitlint/cli": "^17.6.6", "@commitlint/config-conventional": "^17.6.6", - "@tarojs/components": "workspace:*", - "@tarojs/helper": "workspace:*", - "@tarojs/mini-runner": "workspace:*", - "@tarojs/plugin-framework-react": "workspace:*", - "@tarojs/plugin-framework-vue2": "workspace:*", - "@tarojs/plugin-framework-vue3": "workspace:*", - "@tarojs/plugin-platform-alipay": "workspace:*", - "@tarojs/plugin-platform-h5": "workspace:*", - "@tarojs/plugin-platform-harmony-hybrid": "workspace:*", - "@tarojs/plugin-platform-jd": "workspace:*", - "@tarojs/plugin-platform-qq": "workspace:*", - "@tarojs/plugin-platform-swan": "workspace:*", - "@tarojs/plugin-platform-tt": "workspace:*", - "@tarojs/plugin-platform-weapp": "workspace:*", - "@tarojs/router": "workspace:*", - "@tarojs/runner-utils": "workspace:*", - "@tarojs/runtime": "workspace:*", - "@tarojs/shared": "workspace:*", - "@tarojs/taro": "workspace:*", - "@tarojs/taro-h5": "workspace:*", + "@rollup/plugin-babel": "^6.0.4", + "@rollup/plugin-commonjs": "^25.0.7", + "@rollup/plugin-json": "^6.1.0", + "@rollup/plugin-node-resolve": "^15.2.3", + "@rollup/plugin-replace": "^4.0.0", + "@rollup/plugin-typescript": "^11.1.6", "@tarojs/taro-loader": "workspace:*", - "@tarojs/taro-rn": "workspace:*", - "@tarojs/webpack-runner": "workspace:*", - "@tarojs/webpack5-runner": "workspace:*", - "@types/babel-types": "^7.0.7", - "@types/babel__core": "^7.1.14", - "@types/babel__traverse": "^7.0.7", "@types/debug": "^4.1.5", - "@types/detect-port": "1.3.0", "@types/fs-extra": "^8.0.1", "@types/history": "^4.7.5", "@types/inquirer": "^8.2.1", - "@types/jest": "^29.4.0", + "@types/jest": "^29.5.0", "@types/less": "^3.0.2", - "@types/lodash": "^4.14.142", - "@types/lodash-es": "^4.17.6", - "@types/node": "^18.19.12", + "@types/node": "^18", "@types/postcss-import": "^14.0.0", "@types/postcss-url": "^10.0.0", - "@types/react": "^18.0.0", - "@types/react-dom": "^18.0.0", - "@types/react-reconciler": "0.28.1", - "@types/request": "^2.48.1", "@types/resolve": "^1.20.6", "@types/sass": "1.43.1", "@types/tapable": "^1", "@types/webpack": "^4.41.26", "@types/webpack-dev-server": "^3.11.3", - "@typescript-eslint/eslint-plugin": "^6.2.0", - "@typescript-eslint/parser": "^6.2.0", + "@typescript-eslint/eslint-plugin": "^7.8.0", + "@typescript-eslint/parser": "^7.8.0", + "@vitest/coverage-v8": "^1.6.0", + "babel-jest": "^29.7.0", "babel-plugin-syntax-jsx": "6.18.0", "babel-preset-power-assert": "3.0.0", "babel-preset-taro": "workspace:*", "conventional-changelog-cli": "^2.0.1", "core-js": "^3.6.5", - "cpy-cli": "^4.1.0", "cross-env": "^7.0.2", "escodegen": "^2.0.0", - "eslint": "^8.12.0", + "eslint": "^8.57.0", "eslint-config-prettier": "^6.4.0", "eslint-config-standard": "^14.1.1", "eslint-config-taro": "workspace:*", @@ -138,38 +125,35 @@ "eslint-plugin-simple-import-sort": "^7.0.0", "eslint-plugin-standard": "^4.0.1", "husky": "^8.0.1", - "jest": "^27.4.5", - "jest-cli": "^27.4.5", - "jest-environment-node": "^27.4.4", + "jest": "^29.7.0", + "jest-cli": "^29.7.0", + "jest-environment-jsdom": "^29.6.4", + "jest-environment-node": "^29.7.0", + "jest-light-runner": "^0.6.0", + "jest-preset-stylelint": "^7.0.0", + "jest-taro-helper": "workspace:*", + "jsdom": "^24.0.0", "lint-staged": "^13.0.2", "mkdirp": "^3.0.1", - "nervjs": "^1.4.6", "npm-run-all": "^4.1.2", - "postcss": "^8.4.18", + "postcss": "^8.4.38", + "postcss-less": "^6.0.0", "postcss-scss": "^4.0.3", "power-assert": "^1.6.1", - "preact": "^10.5.15", "prettier": "^2.7.1", "prop-types": "^15.7.2", - "react": "^18.2.0", - "react-dom": "^18.2.0", - "react-test-renderer": "^18.2.0", "rimraf": "^5.0.0", - "rollup": "^3.8.1", - "stylelint": "^14.6.1", - "stylelint-config-standard-scss": "^3.0.0", - "stylelint-config-taro-rn": "workspace:*", - "stylelint-order": "^6.0.3", - "stylelint-taro-rn": "workspace:*", + "rollup": "^4.16.4", + "rollup-plugin-node-externals": "^7.1.1", + "rollup-plugin-postcss": "^4.0.2", + "stylelint": "^16.4.0", + "stylelint-config-standard-scss": "^13.1.0", + "stylelint-order": "^6.0.4", + "ts-jest": "^29.1.2", "tslib": "^2.6.2", - "typescript": "^4.7.4", - "vue": "~2.6.11", - "vue-loader": "^17.0.0", - "vue-template-compiler": "~2.6.11", - "webpack": "5.78.0", - "webpack-chain": "6.5.1", - "webpack-dev-server": "4.11.1", - "webpack-sources": "^3.2.3" + "ts-node": "^10.9.1", + "typescript": "^5.4.5", + "vitest": "^1.6.0" }, "pnpm": { "packageExtensions": { 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 6a98eb9d1cc7..1e6ff2858b93 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,14 +1,14 @@ { "name": "babel-plugin-transform-react-jsx-to-rn-stylesheet", - "version": "4.0.0-beta.75", + "version": "4.0.0-alpha.4", "description": "Transform stylesheet selector to style in JSX Elements.", + "author": "O2Team", "license": "MIT", "main": "dist/index.js", - "repository": { - "type": "git", - "url": "git+https://github.com/NervJS/taro.git" - }, "scripts": { + "prod": "pnpm run build", + "prebuild": "pnpm run clean", + "clean": "rimraf --impl=move-remove ./dist", "test": "jest", "test:ci": "jest --ci -i --coverage --silent", "dev": "tsc -w", @@ -17,21 +17,24 @@ "bugs": { "url": "https://github.com/NervJS/taro/issues" }, + "repository": { + "type": "git", + "url": "git+https://github.com/NervJS/taro.git" + }, "homepage": "https://github.com/NervJS/taro#readme", "engines": { - "node": ">= 18", - "npm": ">= 6" + "node": ">= 18" }, "dependencies": { - "camelize": "^1.0.0", + "camelize": "^1.0.1", "taro-css-to-react-native": "workspace:*" }, "devDependencies": { - "@babel/core": "^7.14.5", - "babel-jest": "^29.7.0", - "jest": "^29.3.1", - "jest-cli": "^29.3.1", - "ts-jest": "^29.0.5", - "typescript": "^4.7.4" + "@babel/core": "7.24.4", + "@types/babel__core": "7.20.5", + "babel-plugin-syntax-jsx": "6.18.0" + }, + "peerDependencies": { + "@babel/core": "^7.0.0" } } diff --git a/packages/babel-plugin-transform-react-jsx-to-rn-stylesheet/src/index.ts b/packages/babel-plugin-transform-react-jsx-to-rn-stylesheet/src/index.ts index 13de9c997dac..87d3bb64e9da 100644 --- a/packages/babel-plugin-transform-react-jsx-to-rn-stylesheet/src/index.ts +++ b/packages/babel-plugin-transform-react-jsx-to-rn-stylesheet/src/index.ts @@ -1,9 +1,9 @@ -import { PluginObj, template as Template, types as Types } from 'babel__core' import camelize from 'camelize' import * as path from 'path' import { transformCSS } from 'taro-css-to-react-native' -import { ConvertPluginPass as PluginPass } from './types' +import type { PluginObj, template as Template, types as Types } from '@babel/core' +import type { ConvertPluginPass as PluginPass } from './types' const STYLE_SHEET_NAME = '_styleSheet' const GET_STYLE_FUNC_NAME = '_getStyle' diff --git a/packages/babel-plugin-transform-taroapi/__tests__/index.spec.ts b/packages/babel-plugin-transform-taroapi/__tests__/index.spec.ts index feecca114cce..834ecdde1d88 100644 --- a/packages/babel-plugin-transform-taroapi/__tests__/index.spec.ts +++ b/packages/babel-plugin-transform-taroapi/__tests__/index.spec.ts @@ -1,7 +1,7 @@ import * as babel from '@babel/core' import * as t from '@babel/types' -import * as definition from '@tarojs/plugin-platform-h5/dist/definition.json' +import * as definition from '../../taro-platform-h5/dist/definition.json' import plugin from '../src' type ImportType = babel.types.ImportSpecifier | babel.types.ImportDefaultSpecifier | babel.types.ImportNamespaceSpecifier diff --git a/packages/babel-plugin-transform-taroapi/package.json b/packages/babel-plugin-transform-taroapi/package.json index bb9ed74002fe..b6493ccc2c60 100644 --- a/packages/babel-plugin-transform-taroapi/package.json +++ b/packages/babel-plugin-transform-taroapi/package.json @@ -1,8 +1,13 @@ { "name": "babel-plugin-transform-taroapi", - "version": "4.0.0-beta.75", + "version": "4.0.0-alpha.4", + "author": "O2Team", + "license": "MIT", "main": "dist/index.js", "scripts": { + "prod": "pnpm run build", + "prebuild": "pnpm run clean", + "clean": "rimraf --impl=move-remove ./dist", "build": "tsc", "test": "cross-env NODE_ENV=jest jest", "test:ci": "cross-env NODE_ENV=jest jest --ci -i --coverage --silent", @@ -10,17 +15,18 @@ "test:coverage": "cross-env NODE_ENV=jest jest --coverage", "updateSnapshot": "cross-env NODE_ENV=jest jest --updateSnapshot" }, + "engines": { + "node": ">= 18" + }, "dependencies": { "lodash": "^4.17.21" }, "devDependencies": { - "@babel/core": "^7.23.0", - "@babel/types": "^7.23.0", - "babel-jest": "^29.7.0", - "jest": "^29.3.1", - "jest-cli": "^29.3.1", - "ts-jest": "^29.0.5", - "typescript": "^4.7.4" + "@babel/core": "7.24.4", + "@babel/types": "7.24.0", + "@types/babel__core": "7.20.5" }, - "license": "MIT" + "peerDependencies": { + "@babel/core": "^7.0.0" + } } diff --git a/packages/babel-preset-taro/README.md b/packages/babel-preset-taro/README.md index 6f528de67734..33fd18f1d0cf 100644 --- a/packages/babel-preset-taro/README.md +++ b/packages/babel-preset-taro/README.md @@ -43,13 +43,7 @@ module.exports = { - `react-refresh/babel` -#### 3. Vue - -##### presetes - -- `@vue/babel-preset-jsx` - -#### 4. Vue3 +#### 3. Vue3 ##### plugins @@ -80,16 +74,16 @@ module.exports = { ### vueJsx :::note -只在使用 **Vue/Vue3** 时生效。 +只在使用 **Vue3** 时生效。 ::: **默认值**:`true` **类型**:`true` | `false` | `object` -是否使用 `@vue/babel-preset-jsx`(Vue)或 `@vue/babel-plugin-jsx`(Vue3)来支持使用 `jsx`。 +是否使用 `@vue/babel-plugin-jsx` 来支持使用 `jsx`。 -当传入一个 `object` 时,等同于设置为 `true`,且该 `object` 将会作为 `@vue/babel-preset-jsx`(Vue)或 `@vue/babel-plugin-jsx`(Vue3)的参数。 +当传入一个 `object` 时,等同于设置为 `true`,且该 `object` 将会作为 `@vue/babel-plugin-jsx` 的参数。 ### targets diff --git a/packages/babel-preset-taro/__tests__/index.spec.js b/packages/babel-preset-taro/__tests__/index.spec.js index 9ebfffff16dd..6702adb31a30 100644 --- a/packages/babel-preset-taro/__tests__/index.spec.js +++ b/packages/babel-preset-taro/__tests__/index.spec.js @@ -2,20 +2,6 @@ const babelPresetTaro = require('..') describe('babel-preset-taro', () => { - it('nerv', () => { - const config = babelPresetTaro({}, { - framework: 'nerv' - }) - - expect(config.sourceType).toBe('unambiguous') - - const [override] = config.overrides - - const [, [_, reactConfig]] = override.presets - expect(reactConfig.pragma).toBe('Nerv.createElement') - expect(reactConfig.pragmaFrag).toBe('Nerv.Fragment') - }) - it('react', () => { const config = babelPresetTaro({}, { framework: 'react' @@ -24,20 +10,6 @@ describe('babel-preset-taro', () => { expect(config.sourceType).toBe('unambiguous') }) - it('vue', () => { - const config = babelPresetTaro({}, { - framework: 'vue' - }) - - expect(config.sourceType).toBe('unambiguous') - - const [override] = config.overrides - - const [, [jsxPreset, jsxOptions]] = override.presets - expect(jsxPreset === require('@vue/babel-preset-jsx')).toBeTruthy() - expect(jsxOptions).toEqual({}) - }) - it('vue3', () => { const config = babelPresetTaro({}, { framework: 'vue3' @@ -52,20 +24,6 @@ describe('babel-preset-taro', () => { expect(jsxOptions).toEqual({}) }) - it('vue without jsx', () => { - const config = babelPresetTaro({}, { - framework: 'vue', - vueJsx: false - }) - - expect(config.sourceType).toBe('unambiguous') - - const [override] = config.overrides - - const [, jsxPreset] = override.presets - expect(jsxPreset).toBeUndefined() - }) - it('vue3 without jsx', () => { const config = babelPresetTaro({}, { framework: 'vue3', @@ -95,30 +53,19 @@ describe('babel-preset-taro', () => { expect(tsconfig.jsxPragma === 'React').toBeTruthy() }) - it('typescript nerv', () => { - const config = babelPresetTaro({}, { - framework: 'nerv', - ts: true - }) - - const [override] = config.overrides - - const [, , [ts, tsconfig]] = override.presets - expect(typeof ts.default === 'function').toBeTruthy() - expect(tsconfig.jsxPragma === 'Nerv').toBeTruthy() - }) - - it('typescript vue', () => { + it('typescript vue3', () => { const config = babelPresetTaro({}, { - framework: 'vue', + framework: 'vue3', ts: true }) - const [override, vueOverride] = config.overrides - const [, , [ts, tsconfig]] = override.presets + const [, vueOverride] = config.overrides + const [[ts, tsConfig]] = vueOverride.presets expect(typeof ts.default === 'function').toBeTruthy() - expect(tsconfig.hasOwnProperty('jsxPragma') === false).toBeTruthy() + expect(tsConfig.hasOwnProperty('jsxPragma') === false).toBeTruthy() + expect(tsConfig.allExtensions).toBeTruthy() + expect(tsConfig.isTSX).toBeTruthy() expect(vueOverride.include.test('a.vue')).toBeTruthy() }) diff --git a/packages/babel-preset-taro/index.js b/packages/babel-preset-taro/index.js index 2bd3f05b6be0..aabe030028f5 100644 --- a/packages/babel-preset-taro/index.js +++ b/packages/babel-preset-taro/index.js @@ -31,21 +31,11 @@ module.exports = (_, options = {}) => { const isVite = options.compiler === 'vite' const isReact = options.framework === 'react' || options.framework === 'preact' && !isVite const isSolid = options.framework === 'solid' - const isNerv = options.framework === 'nerv' && !isVite - const isVue = options.framework === 'vue' && !isVite const isVue3 = options.framework === 'vue3' && !isVite const isTs = options.ts && !isVite const moduleName = options.framework.charAt(0).toUpperCase() + options.framework.slice(1) const presetReactConfig = options.react || {} - if (isNerv) { - presets.push([require('@babel/preset-react'), { - pragma: `${moduleName}.createElement`, - pragmaFrag: `${moduleName}.Fragment`, - ...presetReactConfig - }]) - } - if (isReact) { presets.push([require('@babel/preset-react'), { runtime: options.reactJsxRuntime || 'automatic', @@ -68,23 +58,19 @@ module.exports = (_, options = {}) => { }]) } - if (isVue || isVue3) { + if (isVue3) { if (options.vueJsx !== false) { const jsxOptions = typeof options.vueJsx === 'object' ? options.vueJsx : {} - if (isVue) { - presets.push([require('@vue/babel-preset-jsx'), jsxOptions]) - } else { - plugins.push([require('@vue/babel-plugin-jsx'), jsxOptions]) - } + plugins.push([require('@vue/babel-plugin-jsx'), jsxOptions]) } } if (isTs) { const config = typeof options.ts === 'object' ? options.ts : {} - if (isNerv || isReact) { + if (isReact) { config.jsxPragma = moduleName } - if (isVue || isVue3) { + if (isVue3) { overrides.push({ include: /\.vue$/, presets: [[require('@babel/preset-typescript'), { allExtensions: true, isTSX: true }]] @@ -174,7 +160,7 @@ module.exports = (_, options = {}) => { decoratorsBeforeExport, legacy: decoratorsLegacy !== false }], - [require('@babel/plugin-proposal-class-properties'), { loose }] + [require('@babel/plugin-transform-class-properties'), { loose }] ) plugins.push([require('@babel/plugin-transform-runtime'), { diff --git a/packages/babel-preset-taro/package.json b/packages/babel-preset-taro/package.json index 6d72c98c0f9b..138bf7efa2b9 100644 --- a/packages/babel-preset-taro/package.json +++ b/packages/babel-preset-taro/package.json @@ -1,10 +1,10 @@ { "name": "babel-preset-taro", - "version": "4.0.0-beta.75", + "version": "4.0.0-alpha.4", "description": "Taro babel preset", - "author": "yuche ", - "homepage": "https://github.com/nervjs/taro/tree/master/packages/babel-preset-taro#readme", + "author": "O2Team", "license": "MIT", + "homepage": "https://github.com/nervjs/taro/tree/main/packages/babel-preset-taro#readme", "main": "index.js", "files": [ "rn/", @@ -16,44 +16,70 @@ "url": "git+https://github.com/NervJS/taro.git" }, "scripts": { - "test": "jest --collectCoverage", + "test": "jest", "test:ci": "jest --ci -i --coverage --silent" }, "bugs": { "url": "https://github.com/NervJS/taro/issues" }, + "engines": { + "node": ">= 18" + }, "dependencies": { - "@babel/plugin-proposal-class-properties": "^7.14.5", - "@babel/plugin-proposal-decorators": "^7.14.5", - "@babel/plugin-syntax-jsx": "^7.14.5", - "@babel/plugin-transform-runtime": "^7.14.5", - "@babel/preset-env": "^7.20.0", - "@babel/preset-react": "^7.22.15", - "@babel/preset-typescript": "^7.14.5", - "@babel/runtime": "^7.14.5", - "@babel/runtime-corejs3": "^7.14.5", - "@react-native/babel-preset": "^0.73.18", + "@babel/plugin-transform-class-properties": "^7.24.1", + "@babel/plugin-proposal-decorators": "^7.24.1", + "@babel/plugin-transform-runtime": "^7.24.3", + "@babel/preset-env": "^7.24.4", + "@babel/preset-typescript": "^7.24.1", + "@babel/runtime": "^7.24.4", + "@babel/runtime-corejs3": "^7.24.4", "@tarojs/helper": "workspace:*", - "babel-plugin-dynamic-import-node": "2.3.3", + "babel-plugin-dynamic-import-node": "^2.3.3", "babel-plugin-minify-dead-code-elimination": "^0.5.2", - "babel-plugin-transform-imports-api": "1.0.0", - "babel-preset-solid": "^1.8.15", - "core-js": "^3.6.5", - "react-refresh": "^0.11.0" + "babel-plugin-transform-imports-api": "^1.0.0", + "core-js": "^3.36.1" }, "devDependencies": { - "@babel/core": "^7.23.0", - "@prefresh/babel-plugin": "^0.4.1", - "@tarojs/shared": "workspace:*", - "@vue/babel-plugin-jsx": "^1.0.6", - "@vue/babel-preset-jsx": "^1.2.4", - "jest": "^29.3.1", - "jest-cli": "^29.3.1", - "jest-environment-node": "^29.5.0", - "ts-jest": "^29.0.5", - "typescript": "^4.7.4" + "@babel/core": "^7.24.4", + "@babel/preset-react": "^7.24.1", + "react-refresh": "^0.14.0", + "@prefresh/babel-plugin": "^0.5.1", + "babel-preset-solid": "^1.8.16", + "@vue/babel-plugin-jsx": "^1.2.2", + "@react-native/babel-preset": "^0.74.83", + "@tarojs/taro-rn": "workspace:*" }, "peerDependencies": { - "@babel/core": "*" + "@babel/core": "^7.0.0", + "@babel/preset-react": "^7.24.1", + "react-refresh": "^0.14.0", + "@prefresh/babel-plugin": "^0.5.1", + "babel-preset-solid": "^1.8.16", + "@vue/babel-plugin-jsx": "^1.2.2", + "@react-native/babel-preset": "^0.74.0", + "@tarojs/taro-rn": "workspace:*" + }, + "peerDependenciesMeta": { + "@babel/preset-react": { + "optional": true + }, + "react-refresh": { + "optional": true + }, + "@prefresh/babel-plugin": { + "optional": true + }, + "babel-preset-solid": { + "optional": true + }, + "@vue/babel-plugin-jsx": { + "optional": true + }, + "@react-native/babel-preset": { + "optional": true + }, + "@tarojs/taro-rn": { + "optional": true + } } } diff --git a/packages/create-app/package.json b/packages/create-app/package.json index ad1619ad7dce..0a6396fb8f4c 100644 --- a/packages/create-app/package.json +++ b/packages/create-app/package.json @@ -1,16 +1,16 @@ { "name": "@tarojs/create-app", - "version": "4.0.0-beta.75", + "version": "4.0.0-alpha.4", "description": "create taro app with one command", - "author": "VincentW ", - "homepage": "https://github.com/nervjs/taro/tree/master/packages/create-app#readme", + "author": "O2Team", "license": "MIT", "main": "./dist/index.js", "scripts": { + "prod": "pnpm run build", + "prebuild": "pnpm run clean", + "clean": "rimraf --impl=move-remove ./dist", "dev": "tsc -w", - "prod": "tsc", - "build": "run-s clean prod", - "clean": "rimraf --impl=move-remove dist" + "build": "tsc" }, "files": [ "dist" diff --git a/packages/css-to-react-native/package.json b/packages/css-to-react-native/package.json index c9382b32ce0e..7209ee28f3e7 100644 --- a/packages/css-to-react-native/package.json +++ b/packages/css-to-react-native/package.json @@ -1,17 +1,20 @@ { "name": "taro-css-to-react-native", "description": "Convert CSS text to a React Native stylesheet object", - "version": "4.0.0-beta.75", - "main": "dist/index.js", + "version": "4.0.0-alpha.4", + "author": "O2Team", "license": "MIT", + "main": "dist/index.js", + "types": "index.d.ts", "files": [ "dist", "src", - "index.d.ts", - "CHANGELOG.md", - "README.md" + "index.d.ts" ], "scripts": { + "prod": "pnpm run build", + "prebuild": "pnpm run clean", + "clean": "rimraf --impl=move-remove ./dist", "build": "babel src --ignore *.spec.js --out-dir ./dist", "test": "jest" }, @@ -47,17 +50,14 @@ "/node_modules" ] }, + "engines": { + "node": ">= 18" + }, "dependencies": { - "camelize": "^1.0.0", + "camelize": "^1.0.1", "css": "^3.0.0", "css-color-keywords": "^1.0.0", "css-mediaquery": "^0.1.2", - "postcss-value-parser": "^3.3.0" - }, - "devDependencies": { - "@babel/core": "^7.14.5", - "babel-jest": "^29.7.0", - "jest": "^29.3.1", - "jest-cli": "^29.3.1" + "postcss-value-parser": "^4.2.0" } } diff --git a/packages/eslint-config-taro/nerv.js b/packages/eslint-config-taro/nerv.js deleted file mode 100644 index d7c3858e5527..000000000000 --- a/packages/eslint-config-taro/nerv.js +++ /dev/null @@ -1,8 +0,0 @@ -module.exports = Object.assign({}, require('./index'), { - settings: { - react: { - pragma: 'Nerv', - version: '15.0' - } - } -}) diff --git a/packages/eslint-config-taro/package.json b/packages/eslint-config-taro/package.json index 3177de04d52c..e4cc40a18bbb 100644 --- a/packages/eslint-config-taro/package.json +++ b/packages/eslint-config-taro/package.json @@ -1,7 +1,9 @@ { "name": "eslint-config-taro", - "version": "4.0.0-beta.75", + "version": "4.0.0-alpha.4", "description": "Taro specific linting rules for ESLint", + "author": "O2Team", + "license": "MIT", "main": "index.js", "files": [ "rules", @@ -9,10 +11,7 @@ "html-tags.js", "react.js", "preact.js", - "nerv.js", - "vue.js", - "vue3.js", - "README.md" + "vue3.js" ], "repository": { "type": "git", @@ -23,23 +22,30 @@ "react", "jsx" ], - "dependencies": { - "@babel/eslint-parser": "^7.17.0", - "@typescript-eslint/parser": "^6.2.0" + "engines": { + "node": ">= 18" }, - "devDependencies": { - "@babel/core": "^7.14.5", + "dependencies": { + "@babel/eslint-parser": "^7.24.1", + "@typescript-eslint/parser": "^6.2.0", "@typescript-eslint/eslint-plugin": "^6.2.0", - "eslint": "^8.12.0", - "eslint-plugin-import": "^2.26.0", - "eslint-plugin-react": "^7.33.2", - "eslint-plugin-react-hooks": "^4.4.0", - "eslint-plugin-vue": "^9.17.0", - "typescript": "^4.7.4" + "eslint-plugin-import": "^2.29.1" }, "peerDependencies": { - "eslint": "*" + "eslint": "^8", + "eslint-plugin-react": "^7.33.2", + "eslint-plugin-react-hooks": "^4.4.0", + "eslint-plugin-vue": "^9.17.0" }, - "author": "O2Team", - "license": "MIT" + "peerDependenciesMeta": { + "eslint-plugin-react": { + "optional": true + }, + "eslint-plugin-react-hooks": { + "optional": true + }, + "eslint-plugin-vue": { + "optional": true + } + } } diff --git a/packages/eslint-config-taro/vue.js b/packages/eslint-config-taro/vue.js deleted file mode 100644 index 1fe40f9a77bf..000000000000 --- a/packages/eslint-config-taro/vue.js +++ /dev/null @@ -1,10 +0,0 @@ -module.exports = { - extends: [ - // add more generic rulesets here, such as: - // 'eslint:recommended', - 'plugin:vue/recommended' - ], - parserOptions: { - parser: require.resolve('@babel/eslint-parser') - } -} diff --git a/packages/jest-helper/package.json b/packages/jest-helper/package.json index 658db4a307a9..1e9f8688b196 100644 --- a/packages/jest-helper/package.json +++ b/packages/jest-helper/package.json @@ -1,24 +1,28 @@ { "name": "jest-taro-helper", - "version": "4.0.0-beta.75", + "version": "4.0.0-alpha.4", "description": "jest helper for taro", "private": true, + "author": "O2Team", + "license": "MIT", "main": "index.js", "files": [ "lib" ], "scripts": { + "prod": "pnpm run build", + "prebuild": "pnpm run clean", + "clean": "rimraf --impl=move-remove ./lib", "build": "tsc", "dev": "tsc -w" }, "keywords": [], - "author": "", - "license": "ISC", - "devDependencies": { - "@jest/test-sequencer": "^29.5.0", - "jest-resolve": "^29.5.0", - "jest-runner": "^29.5.0", - "pretty-format": "^29.5.0", - "typescript": "^4.7.4" + "engines": { + "node": ">= 18" + }, + "dependencies": { + "@jest/test-sequencer": "^29.7.0", + "jest-resolve": "^29.7.0", + "jest-runner": "^29.7.0" } } diff --git a/packages/postcss-html-transform/package.json b/packages/postcss-html-transform/package.json index dbe7f8032c15..c640f50b2b66 100644 --- a/packages/postcss-html-transform/package.json +++ b/packages/postcss-html-transform/package.json @@ -1,10 +1,10 @@ { "name": "postcss-html-transform", - "version": "4.0.0-beta.75", + "version": "4.0.0-alpha.4", "description": "transform html tag name selector", - "main": "index.js", - "author": "drchan", + "author": "O2Team", "license": "MIT", + "main": "index.js", "files": [ "index.js", "dist" @@ -14,16 +14,19 @@ "url": "git+https://github.com/NervJS/taro.git" }, "scripts": { + "prod": "pnpm run build", + "prebuild": "pnpm run clean", + "clean": "rimraf --impl=move-remove ./dist", "build": "tsc", "dev": "tsc -w" }, "bugs": { "url": "https://github.com/NervJS/taro/issues" }, - "devDependencies": { - "postcss": "^8.4.18" + "engines": { + "node": ">= 18" }, "peerDependencies": { - "postcss": "^8.4.18" + "postcss": "^8" } } diff --git a/packages/postcss-plugin-constparse/package.json b/packages/postcss-plugin-constparse/package.json index 09e22e761b9b..0c2b0e3d6d04 100644 --- a/packages/postcss-plugin-constparse/package.json +++ b/packages/postcss-plugin-constparse/package.json @@ -1,14 +1,14 @@ { "name": "postcss-plugin-constparse", - "version": "4.0.0-beta.75", + "version": "4.0.0-alpha.4", "description": "parse constants defined in config", - "main": "index.js", - "author": "Simba", + "author": "O2Team", "license": "MIT", - "devDependencies": { - "postcss": "^8.4.18" + "main": "index.js", + "engines": { + "node": ">= 18" }, "peerDependencies": { - "postcss": "^8.4.18" + "postcss": "^8" } } diff --git a/packages/postcss-pxtransform/package.json b/packages/postcss-pxtransform/package.json index 461b7def52ad..1db7e178b8f9 100644 --- a/packages/postcss-pxtransform/package.json +++ b/packages/postcss-pxtransform/package.json @@ -1,7 +1,9 @@ { "name": "postcss-pxtransform", - "version": "4.0.0-beta.75", + "version": "4.0.0-alpha.4", "description": "PostCSS plugin px 转小程序 rpx及h5 rem 单位", + "author": "O2Team", + "license": "MIT", "main": "index.js", "keywords": [ "postcss", @@ -9,8 +11,10 @@ "postcss-plugin", "pxtransform" ], - "author": "Pines-Cheng ", - "license": "MIT", + "files": [ + "lib", + "index.js" + ], "repository": { "type": "git", "url": "git+https://github.com/NervJS/taro.git" @@ -18,7 +22,7 @@ "bugs": { "url": "https://github.com/NervJS/taro/issues" }, - "homepage": "https://github.com/NervJS/taro/tree/next/packages/postcss-pxtransform#readme", + "homepage": "https://github.com/NervJS/taro/tree/main/packages/postcss-pxtransform#readme", "scripts": { "test": "jest" }, @@ -26,12 +30,10 @@ "testEnvironment": "node", "testEnvironmentOptions": {} }, - "devDependencies": { - "jest": "^29.3.1", - "jest-cli": "^29.3.1", - "postcss": "^8.4.18" + "engines": { + "node": ">= 18" }, "peerDependencies": { - "postcss": "^8.4.18" + "postcss": "^8" } } diff --git a/packages/postcss-unit-transform/.eslintrc.js b/packages/postcss-unit-transform/.eslintrc.js deleted file mode 100644 index e26be85ae2b8..000000000000 --- a/packages/postcss-unit-transform/.eslintrc.js +++ /dev/null @@ -1,19 +0,0 @@ -const config = require('../../.eslintrc.js') - -module.exports = { - parser: config.parser, - plugins: [ - '@typescript-eslint' - ], - parserOptions: { }, - extends: [ - 'eslint:recommended', - 'standard', - 'plugin:@typescript-eslint/recommended', - 'prettier' - ], - rules: { - '@typescript-eslint/no-unused-vars': 0, - '@typescript-eslint/no-var-requires': 0 - } -} diff --git a/packages/postcss-unit-transform/__tests__/index.test.ts b/packages/postcss-unit-transform/__tests__/index.test.ts index 3b4bec9a31c0..a11b421b78c5 100644 --- a/packages/postcss-unit-transform/__tests__/index.test.ts +++ b/packages/postcss-unit-transform/__tests__/index.test.ts @@ -23,4 +23,4 @@ describe('wxss解析', () => { font-size: 0px; }`) }) -}) \ No newline at end of file +}) diff --git a/packages/postcss-unit-transform/index.js b/packages/postcss-unit-transform/index.js index c2f2edd85cf4..679baabfb4a6 100644 --- a/packages/postcss-unit-transform/index.js +++ b/packages/postcss-unit-transform/index.js @@ -1,17 +1,19 @@ -const postcss = require('postcss') - -module.exports = postcss.plugin('postcss-taro-unit-transform', plugin) - -function plugin (opts) { - return function (root) { - root.walkDecls(function (decl) { - let value = decl.value - value = value.replace(/\b-?(\d+(\.\d+)?)px\b/ig, function (match, size) { - return Number(size) === 0 ? '0px': parseFloat(size) * 2 + 'px' - }).replace(/\b-?(\d+(\.\d+)?)rpx\b/ig, function (match, size) { - return size + 'px' +function plugin () { + return { + postcssPlugin: 'postcss-taro-unit-transform', + Once (root) { + root.walkDecls(decl => { + let value = decl.value + value = value.replace(/\b-?(\d+(\.\d+)?)px\b/ig, function (_match, size) { + return Number(size) === 0 ? '0px' : parseFloat(size) * 2 + 'px' + }).replace(/\b-?(\d+(\.\d+)?)rpx\b/ig, function (_match, size) { + return size + 'px' + }) + decl.value = value }) - decl.value = value - }) + } } } +plugin.postcss = true + +module.exports = plugin diff --git a/packages/postcss-unit-transform/package.json b/packages/postcss-unit-transform/package.json index 950680bef702..d0d9ff5982e3 100644 --- a/packages/postcss-unit-transform/package.json +++ b/packages/postcss-unit-transform/package.json @@ -1,7 +1,9 @@ { "name": "postcss-taro-unit-transform", - "version": "4.0.0-beta.75", + "version": "4.0.0-alpha.4", "description": "小程序单位转换", + "author": "O2Team", + "license": "MIT", "main": "index.js", "scripts": { "test": "jest", @@ -28,14 +30,7 @@ "/node_modules/" ] }, - "author": "luckyadam", - "license": "MIT", - "dependencies": { - "postcss": "^6.0.21", - "typescript": "^4.7.4" - }, - "devDependencies": { - "jest": "^29.7.0", - "ts-jest": "^29.0.5" + "peerDependencies": { + "postcss": "^8" } } diff --git a/packages/rollup-plugin-copy/package.json b/packages/rollup-plugin-copy/package.json index 34688f04d7e9..c27d2e9ee699 100644 --- a/packages/rollup-plugin-copy/package.json +++ b/packages/rollup-plugin-copy/package.json @@ -1,22 +1,29 @@ { "name": "rollup-plugin-copy", - "version": "4.0.0-beta.75", + "version": "4.0.0-alpha.4", "description": "rollup-plugin-copy for taro", "private": true, + "author": "O2Team", + "license": "MIT", "main": "index.js", "files": [ "lib" ], "scripts": { + "prod": "pnpm run build", + "prebuild": "pnpm run clean", + "clean": "rimraf --impl=move-remove ./lib", "build": "tsc", "dev": "tsc -w" }, "keywords": [], - "author": "", - "license": "ISC", - "devDependencies": { - "@tarojs/helper": "workspace:*", - "rollup": "^3.8.1", - "typescript": "^4.7.4" + "engines": { + "node": ">= 18" + }, + "dependencies": { + "@tarojs/helper": "workspace:*" + }, + "peerDependencies": { + "rollup": "^4" } } diff --git a/packages/rollup-plugin-copy/src/index.ts b/packages/rollup-plugin-copy/src/index.ts index fc338f66559e..13abff494b59 100644 --- a/packages/rollup-plugin-copy/src/index.ts +++ b/packages/rollup-plugin-copy/src/index.ts @@ -15,14 +15,15 @@ interface IOptions { export default function handleRollupCopy ({ targets = [], - hook = 'buildEnd' + hook = 'buildEnd', }: IOptions) { - let isWatched = false - + // Note: 因为 rollup 的 watch 模式下,hook 会被多次调用,所以这里需要做一个标记 + let hasWatched = false + const isWatchMode = process.argv.includes('-w') || process.argv.includes('--watch') return { name: 'rollup-plugin:taro-copy', async [hook] () { - if (isWatched) return + if (hasWatched) return for (const item of targets) { try { @@ -42,13 +43,13 @@ export default function handleRollupCopy ({ const stat = fs.statSync(src) if (stat.isDirectory()) { fs.copySync(src, dest, { recursive: true }) - fs.watch(src, { recursive: true }, (_event, filename) => { + isWatchMode && fs.watch(src, { recursive: true }, (_event, filename) => { if (!filename) return fs.copyFileSync(path.join(src, filename), path.join(dest, filename)) }) } else if (stat.isFile()) { fs.copyFileSync(src, dest) - fs.watchFile(src, () => { + isWatchMode && fs.watchFile(src, () => { fs.copyFileSync(path.join(src), dest) }) } @@ -57,7 +58,7 @@ export default function handleRollupCopy ({ } } - isWatched = true + hasWatched = true } } } diff --git a/packages/shared/package.json b/packages/shared/package.json index 0d1c1539dc94..71597307f913 100644 --- a/packages/shared/package.json +++ b/packages/shared/package.json @@ -1,9 +1,8 @@ { "name": "@tarojs/shared", - "version": "4.0.0-beta.75", + "version": "4.0.0-alpha.4", "description": "Taro utils internal use.", - "author": "yuche ", - "homepage": "https://github.com/nervjs/taro/tree/master/packages/shared#readme", + "author": "O2Team", "license": "MIT", "browser": "dist/index.js", "main:h5": "dist/shared.esm.js", @@ -19,22 +18,21 @@ "url": "git+https://github.com/NervJS/taro.git" }, "scripts": { + "prod": "pnpm run build", + "prebuild": "pnpm run clean", + "clean": "rimraf --impl=move-remove ./dist", "build": "pnpm run rollup --environment NODE_ENV:production", "dev": "pnpm run rollup --environment NODE_ENV:development -w", - "rollup": "rollup --config rollup.config.ts --configPlugin @rollup/plugin-typescript --bundleConfigAsCjs", + "rollup": "rollup --config rollup.config.ts --configPlugin typescript", "test": "jest" }, "bugs": { "url": "https://github.com/NervJS/taro/issues" }, + "engines": { + "node": ">= 18" + }, "devDependencies": { - "@rollup/plugin-typescript": "^11.1.0", - "jest": "^29.3.1", - "jest-cli": "^29.3.1", - "lodash": "^4.17.21", - "rollup": "^3.8.1", - "rollup-plugin-ts": "^3.0.2", - "ts-jest": "^29.0.5", - "typescript": "^4.7.4" + "lodash": "^4.17.21" } } diff --git a/packages/shared/rollup.config.ts b/packages/shared/rollup.config.ts index 4ae7217ef295..ff358506033c 100644 --- a/packages/shared/rollup.config.ts +++ b/packages/shared/rollup.config.ts @@ -1,6 +1,6 @@ -import { mergeWith } from 'lodash' +import typescript from '@rollup/plugin-typescript' +import _ from 'lodash' import { defineConfig } from 'rollup' -import ts from 'rollup-plugin-ts' import type { RollupOptions } from 'rollup' @@ -10,11 +10,11 @@ const baseConfig: RollupOptions = { exports: 'named' }, plugins: [ - ts({ - tsconfig: e => ({ - ...e, + typescript({ + compilerOptions: { preserveConstEnums: true, - }) + }, + include: ['src/**/*'] }) ] } @@ -54,8 +54,8 @@ export default defineConfig(variesConfig.map(v => { return objValue.concat(srcValue) } if (typeof objValue === 'object') { - return mergeWith({}, objValue, srcValue, customizer) + return _.mergeWith({}, objValue, srcValue, customizer) } } - return mergeWith({}, baseConfig, v, customizer) + return _.mergeWith({}, baseConfig, v, customizer) })) diff --git a/packages/shared/src/runtime-hooks.ts b/packages/shared/src/runtime-hooks.ts index 851fc5f01881..756a23adaec7 100644 --- a/packages/shared/src/runtime-hooks.ts +++ b/packages/shared/src/runtime-hooks.ts @@ -196,7 +196,6 @@ type ITaroHooks = { getEventCenter: (EventsClass: typeof Events) => Events isBubbleEvents: (eventName: string) => boolean getSpecialNodes: () => string[] - /** 解决 Vue2 布尔值属性值的设置问题 */ onRemoveAttribute: (element, qualifiedName: string) => boolean /** 用于把 React 同一事件回调中的所有 setState 合并到同一个更新处理中 */ batchedEventUpdates: (cb: TFunc) => void diff --git a/packages/shared/tsconfig.json b/packages/shared/tsconfig.json index 2bb63bdf41d5..f1c03eb7ef66 100644 --- a/packages/shared/tsconfig.json +++ b/packages/shared/tsconfig.json @@ -4,8 +4,7 @@ "baseUrl": ".", "outDir": "dist", "module": "ESNext", - "declaration": true, - "sourceMap": true + "declaration": true }, "include": ["./src", "rollup.config.ts"] } diff --git a/packages/stylelint-config-taro-rn/__tests__/index.test.js b/packages/stylelint-config-taro-rn/__tests__/index.test.js index 1fce013d4ed9..26a7a70ffe8f 100644 --- a/packages/stylelint-config-taro-rn/__tests__/index.test.js +++ b/packages/stylelint-config-taro-rn/__tests__/index.test.js @@ -1,382 +1,174 @@ const stylelint = require('stylelint') describe('stylelint-config-react-native-css-modules', () => { - it('does not allow vendor prefixes in values', () => { + async function runStylelint (css) { + return stylelint.lint({ + code: css, + formatter: 'string', + config: { + extends: './index.js' + }, + }) + } + + it('does not allow vendor prefixes in values', async () => { const css = '.test { display: -webkit-flex; }' - expect.assertions(2) - - return stylelint - .lint({ - code: css, - formatter: 'string', - config: { - extends: './index' - } - }) - .then(result => { - expect(result.errored).toBe(true) - expect(result.output.includes('value-no-vendor-prefix')).toBe(true) - }) + const result = await runStylelint(css) + + expect(result.errored).toBe(true) + expect(result.report.includes('value-no-vendor-prefix')).toBe(true) }) - it('does not allow vendor prefixes in properties', () => { + it('does not allow vendor prefixes in properties', async () => { const css = '.test { -webkit-transform: scale(1); }' - expect.assertions(2) - - return stylelint - .lint({ - code: css, - formatter: 'string', - config: { - extends: './index' - } - }) - .then(result => { - expect(result.errored).toBe(true) - expect(result.output.includes('property-no-vendor-prefix')).toBe(true) - }) + const result = await runStylelint(css) + + expect(result.errored).toBe(true) + expect(result.report.includes('property-no-vendor-prefix')).toBe(true) }) - it('does not allow vendor prefixes in at-rules', () => { + it('does not allow vendor prefixes in at-rules', async () => { const css = '.test { @-webkit-keyframes() { 0% { color: blue } 100% { color: red; } } }' - expect.assertions(2) - - return stylelint - .lint({ - code: css, - formatter: 'string', - config: { - extends: './index' - } - }) - .then(result => { - expect(result.errored).toBe(true) - expect(result.output.includes('at-rule-no-vendor-prefix')).toBe(true) - }) + const result = await runStylelint(css) + + expect(result.errored).toBe(true) + expect(result.report.includes('at-rule-no-vendor-prefix')).toBe(true) }) - it('does not allow vendor prefixes in media features', () => { + it('does not allow vendor prefixes in media features', async () => { const css = '@media (-webkit-min-device-pixel-ratio: 1) { .foo { color: blue; } }' - expect.assertions(2) - - return stylelint - .lint({ - code: css, - formatter: 'string', - config: { - extends: './index' - } - }) - .then(result => { - expect(result.errored).toBe(true) - expect( - result.output.includes('media-feature-name-no-vendor-prefix') - ).toBe(true) - }) + const result = await runStylelint(css) + + expect(result.errored).toBe(true) + expect(result.report.includes('media-feature-name-no-vendor-prefix')).toBe(true) }) - it('does not allow unknown properties', () => { + it('does not allow unknown properties', async () => { const css = '.test { word-wrap: break-word; }' - expect.assertions(2) - - return stylelint - .lint({ - code: css, - formatter: 'string', - config: { - extends: './index' - } - }) - .then(result => { - expect(result.errored).toBe(true) - expect( - result.output.includes('taro-rn/css-property-no-unknown') - ).toBe(true) - }) + const result = await runStylelint(css) + + expect(result.errored).toBe(true) + expect(result.report.includes('taro-rn/css-property-no-unknown')).toBe(true) }) - it('warns for id selectors', () => { + it('warns for id selectors', async () => { const css = '#test { flex: 1 }' - expect.assertions(2) - - return stylelint - .lint({ - code: css, - formatter: 'string', - config: { - extends: './index' - } - }) - .then(result => { - expect(result.errored).toBe(false) - expect(result.output.includes('selector-max-id')).toBe(true) - }) + const result = await runStylelint(css) + + expect(result.errored).toBe(false) + expect(result.report.includes('selector-max-id')).toBe(true) }) - it('warns for type selectors', () => { + it('warns for type selectors', async () => { const css = 'input { flex: 1 }' - expect.assertions(2) - - return stylelint - .lint({ - code: css, - formatter: 'string', - config: { - extends: './index' - } - }) - .then(result => { - expect(result.errored).toBe(false) - expect(result.output.includes('selector-max-type')).toBe(true) - }) + const result = await runStylelint(css) + + expect(result.errored).toBe(false) + expect(result.output.includes('selector-max-type')).toBe(true) }) - it('warns for universal selectors', () => { + it('warns for universal selectors', async () => { const css = '* { flex: 1 }' - expect.assertions(2) - - return stylelint - .lint({ - code: css, - formatter: 'string', - config: { - extends: './index' - } - }) - .then(result => { - expect(result.errored).toBe(false) - expect(result.output.includes('selector-max-universal')).toBe( - true - ) - }) + const result = await runStylelint(css) + + expect(result.errored).toBe(false) + expect(result.output.includes('selector-max-universal')).toBe(true) }) - it('warns for combinator selectors', () => { + it('warns for combinator selectors', async () => { const css = '.foo + .bar { flex: 1 }' - expect.assertions(2) - - return stylelint - .lint({ - code: css, - formatter: 'string', - config: { - extends: './index' - } - }) - .then(result => { - expect(result.errored).toBe(false) - expect(result.output.includes('selector-max-combinators')).toBe( - true - ) - }) + const result = await runStylelint(css) + + expect(result.errored).toBe(false) + expect(result.output.includes('selector-max-combinators')).toBe(true) }) - it('warns for attribute selectors', () => { + it('warns for attribute selectors', async () => { const css = '[type=\'text\'] { flex: 1 }' - expect.assertions(2) - - return stylelint - .lint({ - code: css, - formatter: 'string', - config: { - extends: './index' - } - }) - .then(result => { - expect(result.errored).toBe(false) - expect(result.output.includes('selector-max-attribute')).toBe( - true - ) - }) + const result = await runStylelint(css) + + expect(result.errored).toBe(false) + expect(result.output.includes('selector-max-attribute')).toBe(true) }) - it('warns for qualifying type selectors', () => { + it('warns for qualifying type selectors', async () => { const css = 'a.link { flex: 1 }' - expect.assertions(2) - - return stylelint - .lint({ - code: css, - formatter: 'string', - config: { - extends: './index' - } - }) - .then(result => { - expect(result.errored).toBe(false) - expect(result.output.includes('selector-max-type')).toBe(true) - }) + const result = await runStylelint(css) + + expect(result.errored).toBe(false) + expect(result.output.includes('selector-max-type')).toBe(true) }) - it('warns for pseudo classes', () => { + it('warns for pseudo classes', async () => { const css = '.foo:before { flex: 1 }' - expect.assertions(2) - - return stylelint - .lint({ - code: css, - formatter: 'string', - config: { - extends: './index' - } - }) - .then(result => { - expect(result.errored).toBe(false) - expect( - result.output.includes('selector-pseudo-class-allowed-list') - ).toBe(true) - }) + const result = await runStylelint(css) + + expect(result.errored).toBe(false) + expect(result.output.includes('selector-pseudo-class-allowed-list')).toBe(true) }) - it('does not warn for ICSS :export pseudo-selector', () => { + it('does not warn for ICSS :export pseudo-selector', async () => { const css = ':export { color: red; }' - expect.assertions(2) - - return stylelint - .lint({ - code: css, - formatter: 'string', - config: { - extends: './index' - } - }) - .then(result => { - expect(result.errored).toBe(false) - expect(result.output).toBe('') - }) + const result = await runStylelint(css) + + expect(result.errored).toBe(false) + expect(result.output).toBe('') }) - it('does not warn for :root pseudo-selector', () => { + it('does not warn for :root pseudo-selector', async () => { const css = ':root { --my-color: red; }' - expect.assertions(2) - - return stylelint - .lint({ - code: css, - formatter: 'string', - config: { - extends: './index' - } - }) - .then(result => { - expect(result.errored).toBe(false) - expect(result.output).toBe('') - }) + const result = await runStylelint(css) + + expect(result.errored).toBe(false) + expect(result.output).toBe('') }) - it('warns for font-weights that are not compatible with Android', () => { + it('warns for font-weights that are not compatible with Android', async () => { const css = '.foo { font-weight: 300 }' - expect.assertions(2) - - return stylelint - .lint({ - code: css, - formatter: 'string', - config: { - extends: './index' - } - }) - .then(result => { - expect(result.errored).toBe(false) - expect(result.output.includes('taro-rn/font-weight-no-ignored-values')).toBe(true) - }) + const result = await runStylelint(css) + + expect(result.errored).toBe(false) + expect(result.output.includes('taro-rn/font-weight-no-ignored-values')).toBe(true) }) - it('does not allow for line-heights that are invalid', () => { + it('does not allow for line-heights that are invalid', async () => { const css = '.foo { line-height: 1 }' - expect.assertions(2) - - return stylelint - .lint({ - code: css, - formatter: 'string', - config: { - extends: './index' - } - }) - .then(result => { - expect(result.errored).toBe(true) - expect(result.output.includes('line-height "1"')).toBe(true) - }) + const result = await runStylelint(css) + + expect(result.errored).toBe(true) + expect(result.output.includes('line-height "1"')).toBe(true) }) - it('warns for incompatible @-rules', () => { - const css = - '.foo { @keyframes() { 0% { color: blue } 100% { color: red; } } }' - expect.assertions(2) - - return stylelint - .lint({ - code: css, - formatter: 'string', - config: { - extends: './index' - } - }) - .then(result => { - expect(result.errored).toBe(false) - expect(result.output.includes('at-rule-disallowed-list')).toBe(true) - }) + it('warns for incompatible @-rules', async () => { + const css = '.foo { @keyframes() { 0% { color: blue } 100% { color: red; } } }' + const result = await runStylelint(css) + + expect(result.errored).toBe(false) + expect(result.output.includes('at-rule-disallowed-list')).toBe(true) }) - it('warns for @charset', () => { + it('warns for @charset', async () => { const css = '@charset "utf-8";' - expect.assertions(2) - - return stylelint - .lint({ - code: css, - formatter: 'string', - config: { - extends: './index' - } - }) - .then(result => { - expect(result.errored).toBe(false) - expect(result.output.includes('at-rule-disallowed-list')).toBe(true) - }) + const result = await runStylelint(css) + + expect(result.errored).toBe(false) + expect(result.output.includes('at-rule-disallowed-list')).toBe(true) }) - it('warns for incompatible units', () => { + it('warns for incompatible units', async () => { const css = '.foo { font-size: 1ch; }' - expect.assertions(2) - - return stylelint - .lint({ - code: css, - formatter: 'string', - config: { - extends: './index' - } - }) - .then(result => { - expect(result.errored).toBe(false) - expect( - result.output.includes( - 'unit-allowed-list' - ) - ).toBe(true) - }) + const result = await runStylelint(css) + + expect(result.errored).toBe(false) + expect(result.output.includes('unit-allowed-list')).toBe(true) }) - it('allows pseudo and type selectors (ignored by React Native CSS modules, but can be used for web when creating hybrid apps)', () => { - const css = - '.test:hover { color: blue; } .test input[type=text] { color: red; }' - expect.assertions(1) - - return stylelint - .lint({ - code: css, - formatter: 'string', - config: { - extends: './index' - } - }) - .then(result => { - expect(result.errored).toBe(false) - }) + it('allows pseudo and type selectors (ignored by React Native CSS modules, but can be used for web when creating hybrid apps)', async () => { + const css = '.test:hover { color: blue; } .test input[type=text] { color: red; }' + const result = await runStylelint(css) + + expect(result.errored).toBe(false) }) }) diff --git a/packages/stylelint-config-taro-rn/index.js b/packages/stylelint-config-taro-rn/index.js index 15e170eb6644..8aefb6931174 100644 --- a/packages/stylelint-config-taro-rn/index.js +++ b/packages/stylelint-config-taro-rn/index.js @@ -1,3 +1,4 @@ +/** @type {import('stylelint').Config} */ module.exports = { plugins: ['stylelint-taro-rn'], rules: { diff --git a/packages/stylelint-config-taro-rn/jest.config.js b/packages/stylelint-config-taro-rn/jest.config.js index 45205086961e..de8b6ca13c12 100644 --- a/packages/stylelint-config-taro-rn/jest.config.js +++ b/packages/stylelint-config-taro-rn/jest.config.js @@ -1,29 +1,4 @@ -const path = require('path') - module.exports = { - moduleFileExtensions: ['js', 'jsx', 'ts', 'tsx', 'json', 'node'], - moduleNameMapper: { - '@tarojs/shared': path.join(__dirname, '..', '..', 'packages/shared/src') - }, - preset: 'ts-jest', - testEnvironment: 'node', - testEnvironmentOptions: { - url: 'http://localhost/' - }, - testMatch: ['**/__tests__/?(*.)+(spec|test).[jt]s?(x)'], - testPathIgnorePatterns: [ - 'node_modules', - 'utils' - ], - transform: { - '^.+\\.m?[tj]sx?$': ['ts-jest', { - diagnostics: false, - tsconfig: { - jsx: 'react', - allowJs: true, - esModuleInterop: true, - target: 'ES6' - } - }], - } + preset: 'jest-preset-stylelint', + runner: 'jest-light-runner', } diff --git a/packages/stylelint-config-taro-rn/package.json b/packages/stylelint-config-taro-rn/package.json index 70bd598a13be..74493dcf7e06 100644 --- a/packages/stylelint-config-taro-rn/package.json +++ b/packages/stylelint-config-taro-rn/package.json @@ -1,12 +1,12 @@ { "name": "stylelint-config-taro-rn", - "version": "4.0.0-beta.75", + "version": "4.0.0-alpha.4", "description": "Shareable stylelint config for React Native CSS modules", + "author": "O2Team", + "license": "MIT", "main": "index.js", "files": [ - "index.js", - "CHANGELOG.md", - "README.md" + "index.js" ], "keywords": [ "stylelint", @@ -18,16 +18,21 @@ "type": "git", "url": "git+https://github.com/NervJS/taro.git" }, - "author": "O2Team", - "license": "MIT", "scripts": { - "test": "jest" + "test": "cross-env NODE_OPTIONS=\"--experimental-vm-modules --no-warnings\" jest", + "lint": "eslint . --ext .js,.jsx,.ts,.tsx" + }, + "engines": { + "node": ">= 18" + }, + "dependencies": { + "stylelint-taro-rn": "workspace:*" }, "devDependencies": { - "jest": "^29.3.1", - "jest-cli": "^29.3.1", - "jest-environment-node": "^29.5.0", - "ts-jest": "^29.0.5", - "typescript": "^4.7.4" + "stylelint": "^16.4.0" + }, + "peerDependencies": { + "stylelint": "^16", + "stylelint-taro-rn": "workspace:*" } } diff --git a/packages/stylelint-taro-rn/babel.config.js b/packages/stylelint-taro-rn/babel.config.js deleted file mode 100644 index c76a0d028a82..000000000000 --- a/packages/stylelint-taro-rn/babel.config.js +++ /dev/null @@ -1,12 +0,0 @@ -module.exports = { - presets: [ - [ - '@babel/preset-env', - { - targets: { - node: 'current' - } - } - ] - ] -} diff --git a/packages/stylelint-taro-rn/jest.config.js b/packages/stylelint-taro-rn/jest.config.js new file mode 100644 index 000000000000..d6f822f244b7 --- /dev/null +++ b/packages/stylelint-taro-rn/jest.config.js @@ -0,0 +1,6 @@ +export default { + preset: 'jest-preset-stylelint', + runner: 'jest-light-runner', + setupFiles: ['./jest.setup.js'], + testMatch: ['**/src/**/__tests__/?(*.)+(spec|test).js'], +} diff --git a/packages/stylelint-taro-rn/jest-setup.js b/packages/stylelint-taro-rn/jest.setup.js similarity index 88% rename from packages/stylelint-taro-rn/jest-setup.js rename to packages/stylelint-taro-rn/jest.setup.js index 47991bcc13dc..0ddddaf00073 100644 --- a/packages/stylelint-taro-rn/jest-setup.js +++ b/packages/stylelint-taro-rn/jest.setup.js @@ -1,9 +1,7 @@ -"use strict"; // eslint-disable-line +import _ from 'lodash' +import stylelint from 'stylelint' -const _ = require('lodash') -const stylelint = require('stylelint') - -global.testRule = (rule, schema) => { +global.testRule = (schema) => { expect.extend({ toHaveMessage (testCase) { if (testCase.message === undefined) { @@ -25,7 +23,7 @@ global.testRule = (rule, schema) => { plugins: ['./src'], rules: { [schema.ruleName]: schema.config - } + }, } if (schema.accept && schema.accept.length) { @@ -33,7 +31,7 @@ global.testRule = (rule, schema) => { schema.accept.forEach(testCase => { const spec = testCase.only ? it.only : it - spec(testCase.description || 'no description', () => { + spec(testCase.description || 'no description', async () => { const options = { code: testCase.code, config: stylelintConfig, @@ -47,8 +45,7 @@ global.testRule = (rule, schema) => { } // Check the fix - return stylelint - .lint(Object.assign({ fix: true }, options)) + return stylelint.lint(Object.assign({ fix: true }, options)) .then(output2 => { const fixedCode = getOutputCss(output2) @@ -102,8 +99,7 @@ global.testRule = (rule, schema) => { } // Check the fix - return stylelint - .lint(Object.assign({ fix: true }, options)) + return stylelint.lint(Object.assign({ fix: true }, options)) .then(output2 => { const fixedCode = getOutputCss(output2) @@ -143,11 +139,10 @@ global.testConfig = input => { } } - return stylelint - .lint({ - code: '', - config - }) + return stylelint.lint({ + code: '', + config + }) .then(function (data) { const invalidOptionWarnings = data.results[0].invalidOptionWarnings diff --git a/packages/stylelint-taro-rn/package.json b/packages/stylelint-taro-rn/package.json index a06aa8f0783e..34e88267a459 100644 --- a/packages/stylelint-taro-rn/package.json +++ b/packages/stylelint-taro-rn/package.json @@ -1,14 +1,20 @@ { "name": "stylelint-taro-rn", + "version": "4.0.0-alpha.4", "description": "A collection of React Native specific rules for stylelint", - "version": "4.0.0-beta.75", - "main": "dist/index.js", + "author": "O2Team", + "license": "MIT", + "type": "module", + "main": "dist/index.cjs.js", + "module": "dist/index.esm.js", + "exports": { + ".": { + "import": "./dist/index.esm.js", + "require": "./dist/index.cjs.js" + } + }, "files": [ - "dist", - "src", - "CHANGELOG.md", - "README.md", - "!**/__tests__" + "dist" ], "keywords": [ "css", @@ -19,54 +25,29 @@ "stylelint-plugin" ], "scripts": { - "build": "babel src --out-dir ./dist", - "test": "jest" + "prod": "pnpm run build", + "prebuild": "pnpm run clean", + "clean": "rimraf --impl=move-remove ./dist", + "build": "pnpm run rollup --environment NODE_ENV:production", + "dev": "pnpm run rollup --environment NODE_ENV:development -w", + "rollup": "rollup --config rollup.config.ts --configPlugin typescript", + "test": "cross-env NODE_OPTIONS=\"--experimental-vm-modules --no-warnings\" jest", + "lint": "eslint src --ext .js,.jsx,.ts,.tsx" }, "repository": { "type": "git", "url": "git+https://github.com/NervJS/taro.git" }, - "author": "O2Team", - "license": "MIT", "engines": { - "node": ">=6" - }, - "jest": { - "clearMocks": true, - "collectCoverage": false, - "collectCoverageFrom": [ - "src/**/*.js" - ], - "coverageDirectory": "./.coverage/", - "coverageReporters": [ - "lcov", - "text" - ], - "coverageThreshold": { - "global": { - "branches": 75, - "functions": 75, - "lines": 75, - "statements": 75 - } - }, - "setupFiles": [ - "./jest-setup.js" - ], - "testEnvironment": "node", - "roots": [ - "src" - ], - "testRegex": ".*\\.test\\.js$|src/.*/__tests__/.*\\.js$" + "node": ">= 18" }, "dependencies": { - "react-native-known-styling-properties": "^1.0.4" + "react-native-known-styling-properties": "^1.3.0" }, "devDependencies": { - "jest": "^29.3.1", - "jest-cli": "^29.3.1", - "jest-environment-node": "^29.5.0", - "postcss": "^8.4.18", - "postcss-less": "^6.0.0" + "lodash": "^4.17.21" + }, + "peerDependencies": { + "stylelint": "^16" } } diff --git a/packages/stylelint-taro-rn/rollup.config.ts b/packages/stylelint-taro-rn/rollup.config.ts new file mode 100644 index 000000000000..1f2da090b166 --- /dev/null +++ b/packages/stylelint-taro-rn/rollup.config.ts @@ -0,0 +1,53 @@ +import typescript from '@rollup/plugin-typescript' +import _ from 'lodash' +import { defineConfig } from 'rollup' +import externals from 'rollup-plugin-node-externals' + +import type { RollupOptions } from 'rollup' + +const baseConfig = { + input: 'src/index.js', + output: { + sourcemap: true, + exports: 'named' + }, + plugins: [ + externals(), + typescript({ + allowJs: true, + allowSyntheticDefaultImports: true, + include: ['src/**/*'], + exclude: ['src/**/*/__tests__/**'], + }), + ] +} + +const variesConfig: RollupOptions[] = [{ + output: { + dir: 'dist', + preserveModules: true, + preserveModulesRoot: 'src', + }, +}, { + output: { + file: 'dist/index.cjs.js', + format: 'cjs', + }, +}, { + output: { + file: 'dist/index.esm.js', + format: 'es', + }, +}] + +export default defineConfig(variesConfig.map(v => { + const customizer = function (objValue, srcValue) { + if (Array.isArray(objValue)) { + return objValue.concat(srcValue) + } + if (typeof objValue === 'object') { + return _.mergeWith({}, objValue, srcValue, customizer) + } + } + return _.mergeWith({}, baseConfig, v, customizer) +})) diff --git a/packages/stylelint-taro-rn/src/index.js b/packages/stylelint-taro-rn/src/index.js index 0d929caecfab..ed929c6dd7bc 100644 --- a/packages/stylelint-taro-rn/src/index.js +++ b/packages/stylelint-taro-rn/src/index.js @@ -1,10 +1,10 @@ -import { createPlugin } from 'stylelint' +import stylelint from 'stylelint' -import rules from './rules' -import { namespace } from './utils' +import rules from './rules/index.js' +import { namespace } from './utils/index.js' const rulesPlugins = Object.keys(rules).map((ruleName) => { - return createPlugin(namespace(ruleName), rules[ruleName]) + return stylelint.createPlugin(namespace(ruleName), rules[ruleName]) }) export default rulesPlugins diff --git a/packages/stylelint-taro-rn/src/rules/css-property-no-unknown/__tests__/index.js b/packages/stylelint-taro-rn/src/rules/css-property-no-unknown/__tests__/index.spec.js similarity index 54% rename from packages/stylelint-taro-rn/src/rules/css-property-no-unknown/__tests__/index.js rename to packages/stylelint-taro-rn/src/rules/css-property-no-unknown/__tests__/index.spec.js index 7a797f6b317a..d82750646e3e 100644 --- a/packages/stylelint-taro-rn/src/rules/css-property-no-unknown/__tests__/index.js +++ b/packages/stylelint-taro-rn/src/rules/css-property-no-unknown/__tests__/index.spec.js @@ -1,8 +1,8 @@ -import rule, { messages, ruleName } from '..' +import { messages, ruleName } from '../index.js' -testRule(rule, { +testRule({ ruleName, - config: [true], + config: true, accept: [ { @@ -121,88 +121,88 @@ testRule(rule, { ] }) -testRule(rule, { - ruleName, - syntax: 'postcss-scss', - config: [true], +// testRule({ +// ruleName, +// syntax: 'postcss-scss', +// config: [true], - accept: [ - { - code: '.foo { $bgColor: white; }', - description: 'ignore SCSS variables' - }, - { - code: '.foo { #{$prop}: black; }', - description: 'ignore property interpolation' - }, - { - code: '.foo { border: { style: solid; } }', - description: 'ignore nested properties' - } - ] -}) +// accept: [ +// { +// code: '.foo { $bgColor: white; }', +// description: 'ignore SCSS variables' +// }, +// { +// code: '.foo { #{$prop}: black; }', +// description: 'ignore property interpolation' +// }, +// { +// code: '.foo { border: { style: solid; } }', +// description: 'ignore nested properties' +// } +// ] +// }) -testRule(rule, { - ruleName, - syntax: 'postcss-less', - config: [true], +// testRule({ +// ruleName, +// syntax: 'postcss-less', +// config: [true], - accept: [ - { - code: '.foo { @bgColor: white; }', - description: 'ignore LESS variables' - }, - { - code: '.foo { @{prop}: black; }', - description: 'ignore property interpolation' - }, - { - code: '.foo { transform+: rotate(15deg); }', - descritpion: 'Append property value with space usign +' - }, - { - code: '.foo { transform+_: rotate(15deg); }', - descritpion: 'Append property value with space using +_' - } - ] -}) +// accept: [ +// { +// code: '.foo { @bgColor: white; }', +// description: 'ignore LESS variables' +// }, +// { +// code: '.foo { @{prop}: black; }', +// description: 'ignore property interpolation' +// }, +// { +// code: '.foo { transform+: rotate(15deg); }', +// descritpion: 'Append property value with space usign +' +// }, +// { +// code: '.foo { transform+_: rotate(15deg); }', +// descritpion: 'Append property value with space using +_' +// } +// ] +// }) -testRule(rule, { - ruleName, - config: [ - true, - { - ignoreProperties: ['-moz-overflow-scrolling', '/^my-/'] - } - ], +// testRule({ +// ruleName, +// config: [ +// true, +// { +// ignoreProperties: ['-moz-overflow-scrolling', '/^my-/'] +// } +// ], - accept: [ - { - code: '.foo { -moz-overflow-scrolling: auto; }', - description: 'Ignores with a string property' - }, - { - code: '.foo { my-property: 1; }', - description: 'Ignores with a regex property' - }, - { - code: '.foo { my-other-property: 1; }', - description: 'Ignores with a regex property' - } - ], +// accept: [ +// { +// code: '.foo { -moz-overflow-scrolling: auto; }', +// description: 'Ignores with a string property' +// }, +// { +// code: '.foo { my-property: 1; }', +// description: 'Ignores with a regex property' +// }, +// { +// code: '.foo { my-other-property: 1; }', +// description: 'Ignores with a regex property' +// } +// ], - reject: [ - { - code: '.foo { overflow-scrolling: auto; }', - message: messages.rejected('overflow-scrolling'), - line: 1, - column: 8 - }, - { - code: '.foo { not-my-property: 1; }', - message: messages.rejected('not-my-property'), - line: 1, - column: 8 - } - ] -}) +// reject: [ +// { +// code: '.foo { overflow-scrolling: auto; }', +// message: messages.rejected('overflow-scrolling'), +// line: 1, +// column: 8 +// }, +// { +// code: '.foo { not-my-property: 1; }', +// message: messages.rejected('not-my-property'), +// line: 1, +// column: 8 +// } +// ] +// }) diff --git a/packages/stylelint-taro-rn/src/rules/css-property-no-unknown/index.js b/packages/stylelint-taro-rn/src/rules/css-property-no-unknown/index.js index 24b3879aeb5f..d5d57c3dc73d 100644 --- a/packages/stylelint-taro-rn/src/rules/css-property-no-unknown/index.js +++ b/packages/stylelint-taro-rn/src/rules/css-property-no-unknown/index.js @@ -1,5 +1,5 @@ import { allCSS2RNProps } from 'react-native-known-styling-properties' -import { utils } from 'stylelint' +import stylelint from 'stylelint' import { isCustomProperty, @@ -10,11 +10,11 @@ import { kebabCase, namespace, optionsMatches -} from '../../utils' +} from '../../utils/index.js' export const ruleName = namespace('css-property-no-unknown') -export const messages = utils.ruleMessages(ruleName, { +export const messages = stylelint.utils.ruleMessages(ruleName, { rejected: (property) => `无效的 React Native 样式属性 "${property}"` }) @@ -22,7 +22,7 @@ const props = allCSS2RNProps.map(kebabCase) export default function (actual, options) { return function (root, result) { - const validOptions = utils.validateOptions( + const validOptions = stylelint.utils.validateOptions( result, ruleName, { @@ -68,7 +68,7 @@ export default function (actual, options) { return } - utils.report({ + stylelint.utils.report({ message: messages.rejected(prop), node: decl, result, diff --git a/packages/stylelint-taro-rn/src/rules/font-weight-no-ignored-values/__tests__/index.js b/packages/stylelint-taro-rn/src/rules/font-weight-no-ignored-values/__tests__/index.spec.js similarity index 90% rename from packages/stylelint-taro-rn/src/rules/font-weight-no-ignored-values/__tests__/index.js rename to packages/stylelint-taro-rn/src/rules/font-weight-no-ignored-values/__tests__/index.spec.js index cdd8ab11b239..b6116b6ba13b 100644 --- a/packages/stylelint-taro-rn/src/rules/font-weight-no-ignored-values/__tests__/index.js +++ b/packages/stylelint-taro-rn/src/rules/font-weight-no-ignored-values/__tests__/index.spec.js @@ -1,9 +1,9 @@ -import rule, { messages, ruleName } from '..' +import { messages, ruleName } from '../index.js' const acceptedWeights = ['400', '700', 'normal', 'bold'] const rejectedWeights = ['100', '200', '300', '500', '600', '800', '900'] -testRule(rule, { +testRule({ ruleName, config: [true], diff --git a/packages/stylelint-taro-rn/src/rules/font-weight-no-ignored-values/index.js b/packages/stylelint-taro-rn/src/rules/font-weight-no-ignored-values/index.js index 7eeea55b0d52..ea40b152a772 100644 --- a/packages/stylelint-taro-rn/src/rules/font-weight-no-ignored-values/index.js +++ b/packages/stylelint-taro-rn/src/rules/font-weight-no-ignored-values/index.js @@ -1,12 +1,11 @@ -import { utils } from 'stylelint' +import stylelint from 'stylelint' +import declarationValueIndex from 'stylelint/lib/utils/declarationValueIndex.cjs' -import { namespace } from '../../utils' - -const declarationValueIndex = require('stylelint/lib/utils/declarationValueIndex') +import { namespace } from '../../utils/index.js' export const ruleName = namespace('font-weight-no-ignored-values') -export const messages = utils.ruleMessages(ruleName, { +export const messages = stylelint.utils.ruleMessages(ruleName, { rejected: (weight) => `Unexpected font-weight "${weight}"` }) @@ -14,7 +13,7 @@ const acceptedWeights = ['400', '700', 'normal', 'bold'] export default function (actual) { return function (root, result) { - const validOptions = utils.validateOptions(result, ruleName, { + const validOptions = stylelint.utils.validateOptions(result, ruleName, { actual }) @@ -30,7 +29,7 @@ export default function (actual) { const weightValueOffset = decl.value.indexOf(decl.value) const index = declarationValueIndex(decl) + weightValueOffset - utils.report({ + stylelint.utils.report({ message: messages.rejected(decl.value), node: decl, result, diff --git a/packages/stylelint-taro-rn/src/rules/index.js b/packages/stylelint-taro-rn/src/rules/index.js index c16ad8abab91..cd1044b4b694 100644 --- a/packages/stylelint-taro-rn/src/rules/index.js +++ b/packages/stylelint-taro-rn/src/rules/index.js @@ -1,7 +1,7 @@ -import cssPropertyNoUnknown from './css-property-no-unknown' -import fontWeightNoIgnoredValues from './font-weight-no-ignored-values' -import lineHeightNoValueWithoutUnit from './line-height-no-value-without-unit' -import stylePropertyNoUnknown from './style-property-no-unknown' +import cssPropertyNoUnknown from './css-property-no-unknown/index.js' +import fontWeightNoIgnoredValues from './font-weight-no-ignored-values/index.js' +import lineHeightNoValueWithoutUnit from './line-height-no-value-without-unit/index.js' +import stylePropertyNoUnknown from './style-property-no-unknown/index.js' export default { 'font-weight-no-ignored-values': fontWeightNoIgnoredValues, diff --git a/packages/stylelint-taro-rn/src/rules/line-height-no-value-without-unit/__tests__/index.js b/packages/stylelint-taro-rn/src/rules/line-height-no-value-without-unit/__tests__/index.spec.js similarity index 96% rename from packages/stylelint-taro-rn/src/rules/line-height-no-value-without-unit/__tests__/index.js rename to packages/stylelint-taro-rn/src/rules/line-height-no-value-without-unit/__tests__/index.spec.js index d46774a999e6..5843a24cd935 100644 --- a/packages/stylelint-taro-rn/src/rules/line-height-no-value-without-unit/__tests__/index.js +++ b/packages/stylelint-taro-rn/src/rules/line-height-no-value-without-unit/__tests__/index.spec.js @@ -1,6 +1,6 @@ -import rule, { messages, ruleName } from '..' +import { messages, ruleName } from '../index.js' -testRule(rule, { +testRule({ ruleName, config: [true], diff --git a/packages/stylelint-taro-rn/src/rules/line-height-no-value-without-unit/index.js b/packages/stylelint-taro-rn/src/rules/line-height-no-value-without-unit/index.js index 80bd6548e474..c8d1c2d0bcc7 100644 --- a/packages/stylelint-taro-rn/src/rules/line-height-no-value-without-unit/index.js +++ b/packages/stylelint-taro-rn/src/rules/line-height-no-value-without-unit/index.js @@ -1,12 +1,11 @@ -import { utils } from 'stylelint' +import stylelint from 'stylelint' +import declarationValueIndex from 'stylelint/lib/utils/declarationValueIndex.cjs' -import { namespace } from '../../utils' - -const declarationValueIndex = require('stylelint/lib/utils/declarationValueIndex') +import { namespace } from '../../utils/index.js' export const ruleName = namespace('line-height-no-value-without-unit') -export const messages = utils.ruleMessages(ruleName, { +export const messages = stylelint.utils.ruleMessages(ruleName, { rejected: (height) => `Unexpected line-height "${height}", expect a value with units` }) @@ -16,7 +15,7 @@ const viewportUnitRe = /^([+-]?[0-9.]+)(vh|vw|vmin|vmax)$/ export default function (actual) { return function (root, result) { - const validOptions = utils.validateOptions(result, ruleName, { + const validOptions = stylelint.utils.validateOptions(result, ruleName, { actual }) @@ -32,7 +31,7 @@ export default function (actual) { const valueOffset = decl.value.indexOf(decl.value) const index = declarationValueIndex(decl) + valueOffset - utils.report({ + stylelint.utils.report({ message: messages.rejected(decl.value), node: decl, result, diff --git a/packages/stylelint-taro-rn/src/rules/style-property-no-unknown/__tests__/index.js b/packages/stylelint-taro-rn/src/rules/style-property-no-unknown/__tests__/index.spec.js similarity index 97% rename from packages/stylelint-taro-rn/src/rules/style-property-no-unknown/__tests__/index.js rename to packages/stylelint-taro-rn/src/rules/style-property-no-unknown/__tests__/index.spec.js index 64a083df8576..46d30df81c88 100644 --- a/packages/stylelint-taro-rn/src/rules/style-property-no-unknown/__tests__/index.js +++ b/packages/stylelint-taro-rn/src/rules/style-property-no-unknown/__tests__/index.spec.js @@ -1,6 +1,6 @@ -import rule, { messages, ruleName } from '..' +import { messages, ruleName } from '../index.js' -testRule(rule, { +testRule({ ruleName, config: [true], @@ -97,7 +97,7 @@ testRule(rule, { ] }) -testRule(rule, { +testRule({ ruleName, syntax: 'postcss-scss', config: [true], @@ -118,7 +118,7 @@ testRule(rule, { ] }) -testRule(rule, { +testRule({ ruleName, syntax: 'postcss-less', config: [true], @@ -143,7 +143,7 @@ testRule(rule, { ] }) -testRule(rule, { +testRule({ ruleName, config: [ true, diff --git a/packages/stylelint-taro-rn/src/rules/style-property-no-unknown/index.js b/packages/stylelint-taro-rn/src/rules/style-property-no-unknown/index.js index b7eb41d2e9b0..15a737835960 100644 --- a/packages/stylelint-taro-rn/src/rules/style-property-no-unknown/index.js +++ b/packages/stylelint-taro-rn/src/rules/style-property-no-unknown/index.js @@ -1,5 +1,5 @@ import { allProps } from 'react-native-known-styling-properties' -import { utils } from 'stylelint' +import stylelint from 'stylelint' import { isCustomProperty, @@ -9,11 +9,11 @@ import { kebabCase, namespace, optionsMatches -} from '../../utils' +} from '../../utils/index.js' export const ruleName = namespace('style-property-no-unknown') -export const messages = utils.ruleMessages(ruleName, { +export const messages = stylelint.utils.ruleMessages(ruleName, { rejected: (property) => `无效的 React Native 样式属性 "${property}"` }) @@ -21,7 +21,7 @@ const props = allProps.map(kebabCase) export default function (actual, options) { return function (root, result) { - const validOptions = utils.validateOptions( + const validOptions = stylelint.utils.validateOptions( result, ruleName, { @@ -63,7 +63,7 @@ export default function (actual, options) { return } - utils.report({ + stylelint.utils.report({ message: messages.rejected(prop), node: decl, result, diff --git a/packages/stylelint-taro-rn/src/utils/hasInterpolation.js b/packages/stylelint-taro-rn/src/utils/hasInterpolation.js index fcf826c1e312..126d717b1ab0 100644 --- a/packages/stylelint-taro-rn/src/utils/hasInterpolation.js +++ b/packages/stylelint-taro-rn/src/utils/hasInterpolation.js @@ -1,13 +1,14 @@ -const hasLessInterpolation = require('../utils/hasLessInterpolation') -const hasPsvInterpolation = require('../utils/hasPsvInterpolation') -const hasScssInterpolation = require('../utils/hasScssInterpolation') +import { hasLessInterpolation } from './hasLessInterpolation.js' +import { hasPsvInterpolation } from './hasPsvInterpolation.js' +import { hasScssInterpolation } from './hasScssInterpolation.js' + /** * Check whether a string has interpolation * * @param {string} string * @return {boolean} If `true`, a string has interpolation */ -module.exports = function (string /*: string */) /*: boolean */ { +export function hasInterpolation (string /*: string */) /*: boolean */ { // SCSS or Less interpolation if ( hasLessInterpolation(string) || diff --git a/packages/stylelint-taro-rn/src/utils/hasLessInterpolation.js b/packages/stylelint-taro-rn/src/utils/hasLessInterpolation.js index 97a28f9d1625..f3664cef8dc2 100644 --- a/packages/stylelint-taro-rn/src/utils/hasLessInterpolation.js +++ b/packages/stylelint-taro-rn/src/utils/hasLessInterpolation.js @@ -4,7 +4,7 @@ * @param {string} string * @return {boolean} If `true`, a string has less interpolation */ -module.exports = function (string /*: string */) /*: boolean */ { +export function hasLessInterpolation (string /*: string */) /*: boolean */ { if (/@{.+?}/.test(string)) { return true } diff --git a/packages/stylelint-taro-rn/src/utils/hasPsvInterpolation.js b/packages/stylelint-taro-rn/src/utils/hasPsvInterpolation.js index 7f973b7d80de..c12856e530ff 100644 --- a/packages/stylelint-taro-rn/src/utils/hasPsvInterpolation.js +++ b/packages/stylelint-taro-rn/src/utils/hasPsvInterpolation.js @@ -1,7 +1,7 @@ /** * Check whether a string has postcss-simple-vars interpolation */ -module.exports = function (string /*: string */) /*: boolean */ { +export function hasPsvInterpolation (string /*: string */) /*: boolean */ { if (/\$\(.+?\)/.test(string)) { return true } diff --git a/packages/stylelint-taro-rn/src/utils/hasScssInterpolation.js b/packages/stylelint-taro-rn/src/utils/hasScssInterpolation.js index 06bb1f3845e7..1c998d65371c 100644 --- a/packages/stylelint-taro-rn/src/utils/hasScssInterpolation.js +++ b/packages/stylelint-taro-rn/src/utils/hasScssInterpolation.js @@ -1,7 +1,7 @@ /** * Check whether a string has scss interpolation */ -module.exports = function (string /*: string */) /*: boolean */ { +export function hasScssInterpolation (string /*: string */) /*: boolean */ { if (/#{.+?}/.test(string)) { return true } diff --git a/packages/stylelint-taro-rn/src/utils/index.js b/packages/stylelint-taro-rn/src/utils/index.js index fd815184a10f..5a821e497554 100644 --- a/packages/stylelint-taro-rn/src/utils/index.js +++ b/packages/stylelint-taro-rn/src/utils/index.js @@ -1,9 +1,13 @@ -export { endsWith } from './endsWith' -export { isCustomProperty } from './isCustomProperty' -export { isExportBlock } from './isExportBlock' -export { isStandardSyntaxDeclaration } from './isStandardSyntaxDeclaration' -export { isStandardSyntaxProperty } from './isStandardSyntaxProperty' -export { isString } from './isString' -export { kebabCase } from './kebabCase' -export { namespace } from './namespace' -export { optionsMatches } from './optionsMatches' +export { endsWith } from './endsWith.js' +export { hasInterpolation } from './hasInterpolation.js' +export { hasLessInterpolation } from './hasLessInterpolation.js' +export { hasPsvInterpolation } from './hasPsvInterpolation.js' +export { hasScssInterpolation } from './hasScssInterpolation.js' +export { isCustomProperty } from './isCustomProperty.js' +export { isExportBlock } from './isExportBlock.js' +export { isStandardSyntaxDeclaration } from './isStandardSyntaxDeclaration.js' +export { isStandardSyntaxProperty } from './isStandardSyntaxProperty.js' +export { isString } from './isString.js' +export { kebabCase } from './kebabCase.js' +export { namespace } from './namespace.js' +export { optionsMatches } from './optionsMatches.js' diff --git a/packages/stylelint-taro-rn/src/utils/isStandardSyntaxProperty.js b/packages/stylelint-taro-rn/src/utils/isStandardSyntaxProperty.js index 8ace7be8d396..0f6115a92911 100644 --- a/packages/stylelint-taro-rn/src/utils/isStandardSyntaxProperty.js +++ b/packages/stylelint-taro-rn/src/utils/isStandardSyntaxProperty.js @@ -1,6 +1,5 @@ -import { endsWith } from './endsWith' - -const hasInterpolation = require('../utils/hasInterpolation') +import { endsWith } from './endsWith.js' +import { hasInterpolation } from './hasInterpolation.js' /** * Check whether a property is standard diff --git a/packages/stylelint-taro-rn/src/utils/optionsMatches.js b/packages/stylelint-taro-rn/src/utils/optionsMatches.js index 4392e4c6a9b5..8dd3988ab178 100644 --- a/packages/stylelint-taro-rn/src/utils/optionsMatches.js +++ b/packages/stylelint-taro-rn/src/utils/optionsMatches.js @@ -1,4 +1,4 @@ -import { matchesStringOrRegExp } from './matchesStringOrRegExp' +import { matchesStringOrRegExp } from './matchesStringOrRegExp.js' /** * Check if an options object's propertyName contains a user-defined string or diff --git a/packages/stylelint-taro-rn/tsconfig.json b/packages/stylelint-taro-rn/tsconfig.json new file mode 100644 index 000000000000..8979ed10fc3d --- /dev/null +++ b/packages/stylelint-taro-rn/tsconfig.json @@ -0,0 +1,12 @@ +{ + "extends": "../../tsconfig.root.json", + "compilerOptions": { + "baseUrl": "./src", + "declaration": true, + "module": "ESNext", + "outDir": "./dist", + "target": "ES2017" + }, + "include": ["./src", "./rollup.config.ts"], + "exclude": ["./src/__tests__"] +} diff --git a/packages/stylelint-taro/.eslintrc.cjs b/packages/stylelint-taro/.eslintrc.cjs new file mode 100644 index 000000000000..339ee749b6c2 --- /dev/null +++ b/packages/stylelint-taro/.eslintrc.cjs @@ -0,0 +1,15 @@ +const config = require('../../.eslintrc.js') + +module.exports = { + ...config, + rules: { + ...config.rules, + 'no-use-before-define': 0, + '@typescript-eslint/ban-types': ['error', { + types: { + Function: false, + Object: false + } + }], + } +} diff --git a/packages/stylelint-taro/.gitignore b/packages/stylelint-taro/.gitignore deleted file mode 100644 index 8f65a743a6f1..000000000000 --- a/packages/stylelint-taro/.gitignore +++ /dev/null @@ -1,3 +0,0 @@ -lib/ -node_modules/ -.DS_Store diff --git a/packages/stylelint-taro/jest-setup.js b/packages/stylelint-taro/jest-setup.js deleted file mode 100644 index af9b76436012..000000000000 --- a/packages/stylelint-taro/jest-setup.js +++ /dev/null @@ -1,3 +0,0 @@ -const getTestRule = require('jest-preset-stylelint/getTestRule') - -global.testRule = getTestRule({ plugins: ['./lib'] }) diff --git a/packages/stylelint-taro/jest.config.js b/packages/stylelint-taro/jest.config.js new file mode 100644 index 000000000000..b610bed07133 --- /dev/null +++ b/packages/stylelint-taro/jest.config.js @@ -0,0 +1,16 @@ +// /** @type {import('jest').Config} */ +/** @type {import('ts-jest').JestConfigWithTsJest} */ +export default { + preset: 'jest-preset-stylelint', + runner: 'jest-light-runner', + setupFiles: ['./jest.setup.js'], + testMatch: ['**/src/**/__tests__/?(*.)+(spec|test).[jt]s?(x)'], + extensionsToTreatAsEsm: ['.ts'], + transform: { + '^.+\\.m?[tj]sx?$': ['ts-jest', { + useESM: true, + diagnostics: false, + tsconfig: 'tsconfig.test.json' + }], + }, +} diff --git a/packages/stylelint-taro/jest.setup.js b/packages/stylelint-taro/jest.setup.js new file mode 100644 index 000000000000..1de6f1161999 --- /dev/null +++ b/packages/stylelint-taro/jest.setup.js @@ -0,0 +1,8 @@ +import { getTestRule } from 'jest-preset-stylelint' + +import taroRulesPlugin from './src/index.ts' + +global.testRule = getTestRule({ + plugins: taroRulesPlugin, + // loadLint: () => Promise.resolve(require('stylelint').lint) +}) diff --git a/packages/stylelint-taro/package.json b/packages/stylelint-taro/package.json index 29ad7fcf449b..cdc1387ea3c6 100644 --- a/packages/stylelint-taro/package.json +++ b/packages/stylelint-taro/package.json @@ -1,18 +1,30 @@ { "name": "stylelint-taro", - "version": "4.0.0-beta.75", + "version": "4.0.0-alpha.4", "description": "Taro stylelint 规则集合", - "main": "lib/index.js", + "author": "O2Team", + "license": "MIT", + "type": "module", + "main": "dist/index.cjs.js", + "module": "dist/index.esm.js", + "exports": { + ".": { + "import": "./dist/index.esm.js", + "require": "./dist/index.cjs.js" + } + }, "scripts": { - "dev": "tsc -w", - "build": "tsc", - "test": "jest" + "prod": "pnpm run build", + "prebuild": "pnpm run clean", + "clean": "rimraf --impl=move-remove ./dist", + "build": "pnpm run rollup --environment NODE_ENV:production", + "dev": "pnpm run rollup --environment NODE_ENV:development -w", + "rollup": "rollup --config rollup.config.ts --configPlugin typescript", + "test": "cross-env NODE_OPTIONS=\"--experimental-vm-modules --no-warnings --loader ts-node/esm\" jest", + "lint": "eslint src --ext .js,.ts" }, "files": [ - "lib", - "src", - "README.md", - "!**/__tests__" + "dist" ], "keywords": [ "css", @@ -22,45 +34,13 @@ "stylelint", "stylelint-plugin" ], - "author": "O2Team", - "license": "MIT", + "engines": { + "node": ">= 18" + }, "dependencies": { "lodash": "^4.17.21" }, - "devDependencies": { - "@types/node": "^20.10.4", - "jest": "^29.3.1", - "jest-cli": "^29.3.1", - "jest-environment-node": "^29.5.0", - "jest-preset-stylelint": "^6.0.0", - "typescript": "^5.3.3" - }, - "jest": { - "clearMocks": true, - "collectCoverage": false, - "collectCoverageFrom": [ - "lib/**/*.js" - ], - "coverageDirectory": "./.coverage/", - "coverageReporters": [ - "lcov", - "text" - ], - "coverageThreshold": { - "global": { - "branches": 75, - "functions": 75, - "lines": 75, - "statements": 75 - } - }, - "setupFiles": [ - "./jest-setup.js" - ], - "testEnvironment": "node", - "roots": [ - "lib" - ], - "testRegex": ".*\\.test\\.js$|lib/.*/__tests__/.*\\.js$" + "peerDependencies": { + "stylelint": "^16" } } diff --git a/packages/stylelint-taro/rollup.config.ts b/packages/stylelint-taro/rollup.config.ts new file mode 100644 index 000000000000..6dc7c003f390 --- /dev/null +++ b/packages/stylelint-taro/rollup.config.ts @@ -0,0 +1,53 @@ +import typescript from '@rollup/plugin-typescript' +import _ from 'lodash' +import { defineConfig } from 'rollup' +import externals from 'rollup-plugin-node-externals' + +import type { RollupOptions } from 'rollup' + +const baseConfig = { + input: 'src/index.ts', + output: { + sourcemap: true, + exports: 'named' + }, + plugins: [ + externals(), + typescript({ + allowJs: true, + allowSyntheticDefaultImports: true, + include: ['src/**/*'], + exclude: ['src/**/*/__tests__/**'], + }), + ] +} + +const variesConfig: RollupOptions[] = [{ + output: { + dir: 'dist', + preserveModules: true, + preserveModulesRoot: 'src', + }, +}, { + output: { + file: 'dist/index.cjs.js', + format: 'cjs', + }, +}, { + output: { + file: 'dist/index.esm.js', + format: 'es', + }, +}] + +export default defineConfig(variesConfig.map(v => { + const customizer = function (objValue, srcValue) { + if (Array.isArray(objValue)) { + return objValue.concat(srcValue) + } + if (typeof objValue === 'object') { + return _.mergeWith({}, objValue, srcValue, customizer) + } + } + return _.mergeWith({}, baseConfig, v, customizer) +})) diff --git a/packages/stylelint-taro/src/index.ts b/packages/stylelint-taro/src/index.ts index 0829d8e94f6c..c737f9071d83 100644 --- a/packages/stylelint-taro/src/index.ts +++ b/packages/stylelint-taro/src/index.ts @@ -1,10 +1,10 @@ -import { createPlugin } from 'stylelint' +import stylelint from 'stylelint' -import rules from './rules' -import { nameSpace } from './utils' +import rules from './rules/index.ts' +import { nameSpace } from './utils/index.ts' const rulesPlugins = Object.keys(rules).map(ruleName => { - return createPlugin(nameSpace(ruleName), rules[ruleName]) + return stylelint.createPlugin(nameSpace(ruleName), rules[ruleName]) }) export default rulesPlugins diff --git a/packages/stylelint-taro/src/platform/type.ts b/packages/stylelint-taro/src/platform/type.ts index adf7d14354df..a9c666e4d91d 100644 --- a/packages/stylelint-taro/src/platform/type.ts +++ b/packages/stylelint-taro/src/platform/type.ts @@ -1,4 +1,11 @@ -import { ConfigPlugins, ConfigRules, CustomSyntax } from 'stylelint' +import type { CustomSyntax } from 'stylelint' +import type stylelint from 'stylelint' + +type ConfigRules = { + [ruleName: string]: stylelint.ConfigRuleSettings +} + +type ConfigPlugins = string | stylelint.Plugin | (string | stylelint.Plugin)[] export interface TaroStylelintConfig { disAllowedSelectors?: ConfigRules diff --git a/packages/stylelint-taro/src/rules/declaration-property-value-allowed-list/index.ts b/packages/stylelint-taro/src/rules/declaration-property-value-allowed-list/index.ts index 92ffc23846b7..8ee8a02b8896 100644 --- a/packages/stylelint-taro/src/rules/declaration-property-value-allowed-list/index.ts +++ b/packages/stylelint-taro/src/rules/declaration-property-value-allowed-list/index.ts @@ -1,13 +1,13 @@ import stylelint from 'stylelint' -import declarationValueIndex from 'stylelint/lib/utils/declarationValueIndex' -import matchesStringOrRegExp from 'stylelint/lib/utils/matchesStringOrRegExp' -import optionsMatches from 'stylelint/lib/utils/optionsMatches' -import validateObjectWithArrayProps from 'stylelint/lib/utils/validateObjectWithArrayProps' -import validateOptions from 'stylelint/lib/utils/validateOptions' -import { isBoolean, isRegExp, isString } from 'stylelint/lib/utils/validateTypes' -import vendor from 'stylelint/lib/utils/vendor' +import declarationValueIndex from 'stylelint/lib/utils/declarationValueIndex.cjs' +import matchesStringOrRegExp from 'stylelint/lib/utils/matchesStringOrRegExp.cjs' +import optionsMatches from 'stylelint/lib/utils/optionsMatches.cjs' +import validateObjectWithArrayProps from 'stylelint/lib/utils/validateObjectWithArrayProps.cjs' +import validateOptions from 'stylelint/lib/utils/validateOptions.cjs' +import { isBoolean, isRegExp, isString } from 'stylelint/lib/utils/validateTypes.cjs' +import vendor from 'stylelint/lib/utils/vendor.cjs' -import { findIntersection, log, nameSpace, report, taroDocsUrl } from '../../utils' +import { findIntersection, log, nameSpace, report, taroDocsUrl } from '../../utils/index.ts' import type { Rule } from 'stylelint' @@ -62,7 +62,7 @@ const rule: Rule = (primary) => { return } - const platforms = [] + const platforms: string[] = [] Object.keys(primary).forEach((platform) => { if (primary[platform]) { if (propPatterns.some((pattern) => { diff --git a/packages/stylelint-taro/src/rules/index.ts b/packages/stylelint-taro/src/rules/index.ts index 9a69cc22b713..6fdaebf5eaf4 100644 --- a/packages/stylelint-taro/src/rules/index.ts +++ b/packages/stylelint-taro/src/rules/index.ts @@ -1,6 +1,6 @@ -import declarationPropertyValueAllowedList from './declaration-property-value-allowed-list' -import noNestedSelectors from './no-nested-selectors' -import propertyAllowedList from './property-allowed-list' +import declarationPropertyValueAllowedList from './declaration-property-value-allowed-list/index.ts' +import noNestedSelectors from './no-nested-selectors/index.ts' +import propertyAllowedList from './property-allowed-list/index.ts' const rules = { 'no-nested-selectors': noNestedSelectors, diff --git a/packages/stylelint-taro/src/rules/no-nested-selectors/__tests__/index.ts b/packages/stylelint-taro/src/rules/no-nested-selectors/__tests__/index.spec.ts similarity index 94% rename from packages/stylelint-taro/src/rules/no-nested-selectors/__tests__/index.ts rename to packages/stylelint-taro/src/rules/no-nested-selectors/__tests__/index.spec.ts index 2f9ac92c6960..1e664192915d 100644 --- a/packages/stylelint-taro/src/rules/no-nested-selectors/__tests__/index.ts +++ b/packages/stylelint-taro/src/rules/no-nested-selectors/__tests__/index.spec.ts @@ -1,4 +1,4 @@ -import { messages, ruleName } from '../index' +import { messages, ruleName } from '../index.ts' // @ts-ignore testRule({ diff --git a/packages/stylelint-taro/src/rules/no-nested-selectors/index.ts b/packages/stylelint-taro/src/rules/no-nested-selectors/index.ts index 9176340091d4..61a0a511419f 100644 --- a/packages/stylelint-taro/src/rules/no-nested-selectors/index.ts +++ b/packages/stylelint-taro/src/rules/no-nested-selectors/index.ts @@ -1,6 +1,6 @@ -import stylelint, { utils } from 'stylelint' +import stylelint from 'stylelint' -import { log, nameSpace, report, taroDocsUrl } from '../../utils' +import { log, nameSpace, report, taroDocsUrl } from '../../utils/index.ts' import type { Rule } from 'stylelint' @@ -17,7 +17,7 @@ const meta = { const rule: Rule = (primary) => { return (root, result) => { - const validOptions = utils.validateOptions(result, ruleName, { + const validOptions = stylelint.utils.validateOptions(result, ruleName, { actual: primary }) if (!validOptions) { diff --git a/packages/stylelint-taro/src/rules/property-allowed-list/index.ts b/packages/stylelint-taro/src/rules/property-allowed-list/index.ts index 8320adb83383..d19ef89852aa 100644 --- a/packages/stylelint-taro/src/rules/property-allowed-list/index.ts +++ b/packages/stylelint-taro/src/rules/property-allowed-list/index.ts @@ -1,14 +1,14 @@ import _ from 'lodash' import stylelint from 'stylelint' -import isCustomProperty from 'stylelint/lib/utils/isCustomProperty' -import isStandardSyntaxProperty from 'stylelint/lib/utils/isStandardSyntaxProperty' -import matchesStringOrRegExp from 'stylelint/lib/utils/matchesStringOrRegExp' -import validateObjectWithArrayProps from 'stylelint/lib/utils/validateObjectWithArrayProps' -import validateOptions from 'stylelint/lib/utils/validateOptions' -import { isBoolean, isRegExp, isString } from 'stylelint/lib/utils/validateTypes' -import vendor from 'stylelint/lib/utils/vendor' +import isCustomProperty from 'stylelint/lib/utils/isCustomProperty.mjs' +import isStandardSyntaxProperty from 'stylelint/lib/utils/isStandardSyntaxProperty.mjs' +import matchesStringOrRegExp from 'stylelint/lib/utils/matchesStringOrRegExp.mjs' +import validateObjectWithArrayProps from 'stylelint/lib/utils/validateObjectWithArrayProps.mjs' +import validateOptions from 'stylelint/lib/utils/validateOptions.mjs' +import { isBoolean, isRegExp, isString } from 'stylelint/lib/utils/validateTypes.mjs' +import vendor from 'stylelint/lib/utils/vendor.mjs' -import { log, nameSpace, report, taroDocsUrl } from '../../utils' +import { log, nameSpace, report, taroDocsUrl } from '../../utils/index.ts' import type { Rule } from 'stylelint' @@ -39,7 +39,7 @@ const rule: Rule = (primary) => { return } - const _arr = [] + const _arr: string[] = [] Object.keys(primary).forEach(key => { _arr.push(...Object.keys(primary[key])) }) @@ -62,7 +62,7 @@ const rule: Rule = (primary) => { return } - const platform = [] + const platform: string[] = [] Object.keys(primary).forEach(key => { if (primary[key]) { const platformKeys = Object.keys(primary[key]) diff --git a/packages/stylelint-taro/src/utils/index.ts b/packages/stylelint-taro/src/utils/index.ts index 3b1b33b10644..7e1593e80b25 100644 --- a/packages/stylelint-taro/src/utils/index.ts +++ b/packages/stylelint-taro/src/utils/index.ts @@ -1,4 +1,4 @@ -import { utils } from 'stylelint' +import stylelint from 'stylelint' import type { Problem } from 'stylelint' @@ -11,11 +11,11 @@ export function nameSpace(ruleName: string) { return `taro/${ruleName}` } export function newMessage(ruleName: string, options) { - return utils.ruleMessages(ruleName, options) + return stylelint.utils.ruleMessages(ruleName, options) } export function report(problem: Problem) { - return utils.report(problem) + return stylelint.utils.report(problem) } export function log(text: string) { diff --git a/packages/stylelint-taro/tsconfig.json b/packages/stylelint-taro/tsconfig.json index f0fe810bc027..2549c59b259c 100644 --- a/packages/stylelint-taro/tsconfig.json +++ b/packages/stylelint-taro/tsconfig.json @@ -1,109 +1,14 @@ { + "extends": "../../tsconfig.root.json", "compilerOptions": { - /* Visit https://aka.ms/tsconfig to read more about this file */ - - /* Projects */ - // "incremental": true, /* Save .tsbuildinfo files to allow for incremental compilation of projects. */ - // "composite": true, /* Enable constraints that allow a TypeScript project to be used with project references. */ - // "tsBuildInfoFile": "./.tsbuildinfo", /* Specify the path to .tsbuildinfo incremental compilation file. */ - // "disableSourceOfProjectReferenceRedirect": true, /* Disable preferring source files instead of declaration files when referencing composite projects. */ - // "disableSolutionSearching": true, /* Opt a project out of multi-project reference checking when editing. */ - // "disableReferencedProjectLoad": true, /* Reduce the number of projects loaded automatically by TypeScript. */ - - /* Language and Environment */ - "target": "es2016", /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */ - // "lib": [], /* Specify a set of bundled library declaration files that describe the target runtime environment. */ - // "jsx": "preserve", /* Specify what JSX code is generated. */ - // "experimentalDecorators": true, /* Enable experimental support for legacy experimental decorators. */ - // "emitDecoratorMetadata": true, /* Emit design-type metadata for decorated declarations in source files. */ - // "jsxFactory": "", /* Specify the JSX factory function used when targeting React JSX emit, e.g. 'React.createElement' or 'h'. */ - // "jsxFragmentFactory": "", /* Specify the JSX Fragment reference used for fragments when targeting React JSX emit e.g. 'React.Fragment' or 'Fragment'. */ - // "jsxImportSource": "", /* Specify module specifier used to import the JSX factory functions when using 'jsx: react-jsx*'. */ - // "reactNamespace": "", /* Specify the object invoked for 'createElement'. This only applies when targeting 'react' JSX emit. */ - // "noLib": true, /* Disable including any library files, including the default lib.d.ts. */ - // "useDefineForClassFields": true, /* Emit ECMAScript-standard-compliant class fields. */ - // "moduleDetection": "auto", /* Control what method is used to detect module-format JS files. */ - - /* Modules */ - "module": "commonjs", /* Specify what module code is generated. */ - "rootDir": "./src", /* Specify the root folder within your source files. */ - "moduleResolution": "node10", /* Specify how TypeScript looks up a file from a given module specifier. */ - // "baseUrl": "./", /* Specify the base directory to resolve non-relative module names. */ - // "paths": {}, /* Specify a set of entries that re-map imports to additional lookup locations. */ - // "rootDirs": [], /* Allow multiple folders to be treated as one when resolving modules. */ - // "typeRoots": [], /* Specify multiple folders that act like './node_modules/@types'. */ - // "types": [], /* Specify type package names to be included without being referenced in a source file. */ - // "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */ - // "moduleSuffixes": [], /* List of file name suffixes to search when resolving a module. */ - // "allowImportingTsExtensions": true, /* Allow imports to include TypeScript file extensions. Requires '--moduleResolution bundler' and either '--noEmit' or '--emitDeclarationOnly' to be set. */ - // "resolvePackageJsonExports": true, /* Use the package.json 'exports' field when resolving package imports. */ - // "resolvePackageJsonImports": true, /* Use the package.json 'imports' field when resolving imports. */ - // "customConditions": [], /* Conditions to set in addition to the resolver-specific defaults when resolving imports. */ - // "resolveJsonModule": true, /* Enable importing .json files. */ - // "allowArbitraryExtensions": true, /* Enable importing files with any extension, provided a declaration file is present. */ - // "noResolve": true, /* Disallow 'import's, 'require's or ''s from expanding the number of files TypeScript should add to a project. */ - - /* JavaScript Support */ - // "allowJs": true, /* Allow JavaScript files to be a part of your program. Use the 'checkJS' option to get errors from these files. */ - // "checkJs": true, /* Enable error reporting in type-checked JavaScript files. */ - // "maxNodeModuleJsDepth": 1, /* Specify the maximum folder depth used for checking JavaScript files from 'node_modules'. Only applicable with 'allowJs'. */ - - /* Emit */ - // "declaration": true, /* Generate .d.ts files from TypeScript and JavaScript files in your project. */ - // "declarationMap": true, /* Create sourcemaps for d.ts files. */ - // "emitDeclarationOnly": true, /* Only d.ts files and not JavaScript files. */ - // "sourceMap": true, /* Create source map files for emitted JavaScript files. */ - // "inlineSourceMap": true, /* Include sourcemap files inside the emitted JavaScript. */ - // "outFile": "./", /* Specify a file that bundles all outputs into one JavaScript file. If 'declaration' is true, also designates a file that bundles all .d.ts output. */ - "outDir": "./lib", /* Specify an output folder for all emitted files. */ - // "removeComments": true, /* Disable emitting comments. */ - // "noEmit": true, /* Disable emitting files from a compilation. */ - // "importHelpers": true, /* Allow importing helper functions from tslib once per project, instead of including them per-file. */ - // "importsNotUsedAsValues": "remove", /* Specify emit/checking behavior for imports that are only used for types. */ - // "downlevelIteration": true, /* Emit more compliant, but verbose and less performant JavaScript for iteration. */ - // "sourceRoot": "", /* Specify the root path for debuggers to find the reference source code. */ - // "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */ - // "inlineSources": true, /* Include source code in the sourcemaps inside the emitted JavaScript. */ - // "emitBOM": true, /* Emit a UTF-8 Byte Order Mark (BOM) in the beginning of output files. */ - // "newLine": "crlf", /* Set the newline character for emitting files. */ - // "stripInternal": true, /* Disable emitting declarations that have '@internal' in their JSDoc comments. */ - // "noEmitHelpers": true, /* Disable generating custom helper functions like '__extends' in compiled output. */ - // "noEmitOnError": true, /* Disable emitting files if any type checking errors are reported. */ - // "preserveConstEnums": true, /* Disable erasing 'const enum' declarations in generated code. */ - // "declarationDir": "./", /* Specify the output directory for generated declaration files. */ - // "preserveValueImports": true, /* Preserve unused imported values in the JavaScript output that would otherwise be removed. */ - - /* Interop Constraints */ - // "isolatedModules": true, /* Ensure that each file can be safely transpiled without relying on other imports. */ - // "verbatimModuleSyntax": true, /* Do not transform or elide any imports or exports not marked as type-only, ensuring they are written in the output file's format based on the 'module' setting. */ - // "allowSyntheticDefaultImports": true, /* Allow 'import x from y' when a module doesn't have a default export. */ - "esModuleInterop": true, /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility. */ - // "preserveSymlinks": true, /* Disable resolving symlinks to their realpath. This correlates to the same flag in node. */ - "forceConsistentCasingInFileNames": true, /* Ensure that casing is correct in imports. */ - - /* Type Checking */ - // "strict": true, /* Enable all strict type-checking options. */ - // "noImplicitAny": true, /* Enable error reporting for expressions and declarations with an implied 'any' type. */ - // "strictNullChecks": true, /* When type checking, take into account 'null' and 'undefined'. */ - // "strictFunctionTypes": true, /* When assigning functions, check to ensure parameters and the return values are subtype-compatible. */ - // "strictBindCallApply": true, /* Check that the arguments for 'bind', 'call', and 'apply' methods match the original function. */ - // "strictPropertyInitialization": true, /* Check for class properties that are declared but not set in the constructor. */ - // "noImplicitThis": true, /* Enable error reporting when 'this' is given the type 'any'. */ - // "useUnknownInCatchVariables": true, /* Default catch clause variables as 'unknown' instead of 'any'. */ - // "alwaysStrict": true, /* Ensure 'use strict' is always emitted. */ - // "noUnusedLocals": true, /* Enable error reporting when local variables aren't read. */ - // "noUnusedParameters": true, /* Raise an error when a function parameter isn't read. */ - // "exactOptionalPropertyTypes": true, /* Interpret optional property types as written, rather than adding 'undefined'. */ - // "noImplicitReturns": true, /* Enable error reporting for codepaths that do not explicitly return in a function. */ - // "noFallthroughCasesInSwitch": true, /* Enable error reporting for fallthrough cases in switch statements. */ - // "noUncheckedIndexedAccess": true, /* Add 'undefined' to a type when accessed using an index. */ - // "noImplicitOverride": true, /* Ensure overriding members in derived classes are marked with an override modifier. */ - // "noPropertyAccessFromIndexSignature": true, /* Enforces using indexed accessors for keys declared using an indexed type. */ - // "allowUnusedLabels": true, /* Disable error reporting for unused labels. */ - // "allowUnreachableCode": true, /* Disable error reporting for unreachable code. */ - - /* Completeness */ - // "skipDefaultLibCheck": true, /* Skip type checking .d.ts files that are included with TypeScript. */ - "skipLibCheck": true /* Skip type checking all .d.ts files. */ - } + "baseUrl": "./src", + "declaration": true, + "allowImportingTsExtensions": true, + "noEmit": true, + "module": "ESNext", + "outDir": "./dist", + "target": "ES2017" + }, + "include": ["./src", "./rollup.config.ts"], + "exclude": ["./src/__tests__"] } diff --git a/packages/taro-webpack5-runner/tsconfig.test.json b/packages/stylelint-taro/tsconfig.test.json similarity index 82% rename from packages/taro-webpack5-runner/tsconfig.test.json rename to packages/stylelint-taro/tsconfig.test.json index 6172d3c0fa89..07ac3c011116 100644 --- a/packages/taro-webpack5-runner/tsconfig.test.json +++ b/packages/stylelint-taro/tsconfig.test.json @@ -1,7 +1,6 @@ { "extends": "../../tsconfig.root.json", "compilerOptions": { - "jsx": "react", "allowJs": true } } diff --git a/packages/taro-alipay/.gitignore b/packages/taro-alipay/.gitignore deleted file mode 100644 index ac2a27206373..000000000000 --- a/packages/taro-alipay/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -types -!types/shims-* diff --git a/packages/taro-api/jest.config.js b/packages/taro-api/jest.config.js index 16ccf63f68d4..f0d4c4067f31 100644 --- a/packages/taro-api/jest.config.js +++ b/packages/taro-api/jest.config.js @@ -12,6 +12,7 @@ module.exports = { }, moduleFileExtensions: ['js', 'jsx', 'ts', 'tsx', 'json', 'node'], moduleNameMapper: { + '@tarojs/taro': '/src/index.ts', '@tarojs/api': '/src/index.ts', '@tarojs/shared': path.resolve(__dirname, '..', '..', 'packages/shared/src/index.ts'), '@tarojs/runtime': path.resolve(__dirname, '..', '..', 'packages/taro-runtime/dist/runtime.esm.js') diff --git a/packages/taro-api/package.json b/packages/taro-api/package.json index 4b1992d01c50..17f92b15af0d 100644 --- a/packages/taro-api/package.json +++ b/packages/taro-api/package.json @@ -1,9 +1,8 @@ { "name": "@tarojs/api", - "version": "4.0.0-beta.75", + "version": "4.0.0-alpha.4", "description": "Taro common API", - "author": "yuche ", - "homepage": "https://github.com/nervjs/taro/tree/master/packages/api#readme", + "author": "O2Team", "license": "MIT", "browser": "dist/index.js", "main:h5": "dist/index.esm.js", @@ -22,11 +21,12 @@ "url": "git+https://github.com/NervJS/taro.git" }, "scripts": { + "prod": "pnpm run build", "prebuild": "pnpm run clean", "build": "pnpm run rollup --environment NODE_ENV:production", "clean": "rimraf ./dist", "dev": "pnpm run rollup --environment NODE_ENV:development -w", - "rollup": "rollup --config rollup.config.ts --configPlugin @rollup/plugin-typescript --bundleConfigAsCjs", + "rollup": "rollup --config rollup.config.ts --configPlugin typescript", "test": "cross-env NODE_ENV=test jest", "test:ci": "cross-env NODE_ENV=test jest --ci -i --coverage --silent", "test:dev": "cross-env NODE_ENV=test jest --watch" @@ -34,24 +34,16 @@ "bugs": { "url": "https://github.com/NervJS/taro/issues" }, - "dependencies": { - "@babel/runtime": "^7.14.5", - "@tarojs/runtime": "workspace:*", - "@tarojs/shared": "workspace:*" + "engines": { + "node": ">= 18" }, "devDependencies": { - "@babel/core": "^7.14.5", - "@rollup/plugin-babel": "^6.0.4", - "@rollup/plugin-commonjs": "^25.0.7", - "@rollup/plugin-node-resolve": "^15.2.3", - "@rollup/plugin-typescript": "^11.1.0", - "jest": "^29.3.1", - "jest-cli": "^29.3.1", - "jest-environment-node": "^29.5.0", - "rollup": "^3.8.1", - "rollup-plugin-node-externals": "^5.0.0", - "rollup-plugin-ts": "^3.0.2", - "ts-jest": "^29.0.5", - "typescript": "^4.7.4" + "@tarojs/runtime": "workspace:*", + "@tarojs/shared": "workspace:*", + "lodash": "4.17.21" + }, + "peerDependencies": { + "@tarojs/runtime": "workspace:*", + "@tarojs/shared": "workspace:*" } } diff --git a/packages/taro-api/rollup.config.ts b/packages/taro-api/rollup.config.ts index 6dcf1e0e9929..d1e98fada443 100644 --- a/packages/taro-api/rollup.config.ts +++ b/packages/taro-api/rollup.config.ts @@ -1,9 +1,7 @@ -import babel from '@rollup/plugin-babel' -import commonjs from '@rollup/plugin-commonjs' -import { nodeResolve } from '@rollup/plugin-node-resolve' +import typescript from '@rollup/plugin-typescript' +import _ from 'lodash' import { defineConfig } from 'rollup' import externals from 'rollup-plugin-node-externals' -import ts from 'rollup-plugin-ts' import type { RollupOptions } from 'rollup' @@ -15,23 +13,10 @@ const baseConfig: RollupOptions = { }, plugins: [ externals({ - deps: true, - devDeps: false, + peerDeps: true, }), - nodeResolve({ - preferBuiltins: false - }), - ts({ - tsconfig: e => ({ - ...e, - sourceMap: true - }) - }), - commonjs({ - extensions: ['.js', '.ts'], - }), - babel({ - babelHelpers: 'runtime' + typescript({ + include: ['src/**/*'] // 必须添加这行,否则会打包出 rollup.config.d.ts }) ] } @@ -60,7 +45,8 @@ const variesConfig: RollupOptions[] = [{ '@babel/runtime/helpers/classCallCheck': '_classCallCheck', '@babel/runtime/helpers/createClass': '_createClass', '@babel/runtime/helpers/defineProperty': '_defineProperty', - '@tarojs/runtime': 'runtime' + '@tarojs/runtime': 'runtime', + '@tarojs/shared': 'shared', } } }, @@ -73,5 +59,5 @@ const variesConfig: RollupOptions[] = [{ }] export default defineConfig(variesConfig.map(v => { - return Object.assign({}, baseConfig, v) + return _.mergeWith({}, baseConfig, v) })) diff --git a/packages/taro-api/src/tools.ts b/packages/taro-api/src/tools.ts index 9380dce327d5..d229569f09c7 100644 --- a/packages/taro-api/src/tools.ts +++ b/packages/taro-api/src/tools.ts @@ -5,7 +5,7 @@ export function Behavior (options) { } export function getPreload (current) { - return function (key: string | Record, val: unknown) { + return function (key: any, val: unknown) { current.preloadData = isObject(key) ? key : { diff --git a/packages/taro-api/tsconfig.json b/packages/taro-api/tsconfig.json index 865095e81750..5ca5710de71f 100644 --- a/packages/taro-api/tsconfig.json +++ b/packages/taro-api/tsconfig.json @@ -5,8 +5,7 @@ "declaration": true, "esModuleInterop": true, "module": "ESNext", - "outDir": "dist", - "sourceMap": false + "outDir": "dist" }, - "include": ["./src", "./types", "./rollup.config.ts"] + "include": ["./src", "./rollup.config.ts"] } diff --git a/packages/taro-cli-convertor/__tests__/__snapshots__/config.test.ts.snap b/packages/taro-cli-convertor/__tests__/__snapshots__/config.test.ts.snap index 5a0b450afb99..feea5b4d1181 100644 --- a/packages/taro-cli-convertor/__tests__/__snapshots__/config.test.ts.snap +++ b/packages/taro-cli-convertor/__tests__/__snapshots__/config.test.ts.snap @@ -1,7 +1,7 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP exports[`日志 生成日志 1`] = ` -"INFO [taro-cli-convertor] parseAst - 入参 +INFO [taro-cli-convertor] parseAst - 入参 {"sourceFilePath":"/wxProject/app.js","outputFilePath":"/wxProject/taroConvert/src/app.js","importStylePath":null,"imports":[]} INFO [taro-cli-convertor] parseAst - 解析ImportDeclaration import { Block } from "@tarojs/components"; @@ -243,13 +243,13 @@ INFO [taro-cli-convertor] parseAst - 解析VariableDeclaration const { motto } = this.data; -" + `; exports[`转换报告 生成转换报告文件 1`] = ` Map { - "/wxProject/taroConvert/.convert" => "", - "/wxProject/taroConvert/.convert/convert.log" => "INFO [taro-cli-convertor] parseAst - 入参 + /wxProject/taroConvert/.convert => , + /wxProject/taroConvert/.convert/convert.log => INFO [taro-cli-convertor] parseAst - 入参 {"sourceFilePath":"/wxProject/app.js","outputFilePath":"/wxProject/taroConvert/src/app.js","importStylePath":null,"imports":[]} INFO [taro-cli-convertor] parseAst - 解析ImportDeclaration import { Block } from "@tarojs/components"; @@ -491,8 +491,8 @@ INFO [taro-cli-convertor] parseAst - 解析VariableDeclaration const { motto } = this.data; -", - "/wxProject/taroConvert/src/app.js" => "import withWeapp, { cacheOptions } from "@tarojs/with-weapp"; +, + /wxProject/taroConvert/src/app.js => import withWeapp, { cacheOptions } from "@tarojs/with-weapp"; import { Block } from "@tarojs/components"; import React from "react"; import Taro from "@tarojs/taro"; @@ -503,10 +503,10 @@ class App extends React.Component { return this.props.children; } } -export default App;", - "/wxProject/taroConvert/src/app.config.js" => "export default { pages: ['pages/index/index'] } -", - "/wxProject/taroConvert/src/pages/index/index.js" => "import withWeapp, { cacheOptions } from '@tarojs/with-weapp' +export default App;, + /wxProject/taroConvert/src/app.config.js => export default { pages: ['pages/index/index'] } +, + /wxProject/taroConvert/src/pages/index/index.js => import withWeapp, { cacheOptions } from '@tarojs/with-weapp' import { Block, View, Text } from '@tarojs/components' import React from 'react' import Taro from '@tarojs/taro' @@ -529,13 +529,13 @@ class _C extends React.Component { } } export default _C -", - "/wxProject/taroConvert/src/pages/index/index.config.js" => "export default {} -", - "/wxProject/taroConvert/report" => "", - "/wxProject/taroConvert/report/index.html" => "convert report
", - "/wxProject/taroConvert/report/static/js" => "", - "/wxProject/taroConvert/report/static/js/bundle.js" => "/******/ (function() { // webpackBootstrap +, + /wxProject/taroConvert/src/pages/index/index.config.js => export default {} +, + /wxProject/taroConvert/report => , + /wxProject/taroConvert/report/index.html => convert report
, + /wxProject/taroConvert/report/static/js => , + /wxProject/taroConvert/report/static/js/bundle.js => /******/ (function() { / webpackBootstrap /******/ var __webpack_modules__ = ({ /***/ 270: @@ -544,7 +544,7 @@ export default _C var __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_DEFINE_RESULT__;/*! Copyright (c) 2018 Jed Watson. Licensed under the MIT License (MIT), see - http://jedwatson.github.io/classnames + http:/jedwatson.github.io/classnames */ /* global define */ @@ -586,7 +586,7 @@ var __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_DEFINE_RESULT__;/*! classNames.default = classNames; module.exports = classNames; } else if (true) { - // register as 'classnames', consistent with npm package name + / register as 'classnames', consistent with npm package name !(__WEBPACK_AMD_DEFINE_ARRAY__ = [], __WEBPACK_AMD_DEFINE_RESULT__ = (function () { return classNames; }).apply(exports, __WEBPACK_AMD_DEFINE_ARRAY__), @@ -752,7 +752,7 @@ if (true) { var aa = __webpack_require__(519), ca = __webpack_require__(514); function p(a) { - for (var b = "https://reactjs.org/docs/error-decoder.html?invariant=" + a, c = 1; c < arguments.length; c++) b += "&args[]=" + encodeURIComponent(arguments[c]); + for (var b = "https:/reactjs.org/docs/error-decoder.html?invariant=" + a, c = 1; c < arguments.length; c++) b += "&args[]=" + encodeURIComponent(arguments[c]); return "Minified React error #" + a + "; visit " + b + " for the full message or use the non-minified dev environment for full errors and additional helpful warnings."; } var da = new Set(), @@ -767,7 +767,7 @@ function ha(a, b) { } var ia = !("undefined" === typeof window || "undefined" === typeof window.document || "undefined" === typeof window.document.createElement), ja = Object.prototype.hasOwnProperty, - ka = /^[:A-Z_a-z\\u00C0-\\u00D6\\u00D8-\\u00F6\\u00F8-\\u02FF\\u0370-\\u037D\\u037F-\\u1FFF\\u200C-\\u200D\\u2070-\\u218F\\u2C00-\\u2FEF\\u3001-\\uD7FF\\uF900-\\uFDCF\\uFDF0-\\uFFFD][:A-Z_a-z\\u00C0-\\u00D6\\u00D8-\\u00F6\\u00F8-\\u02FF\\u0370-\\u037D\\u037F-\\u1FFF\\u200C-\\u200D\\u2070-\\u218F\\u2C00-\\u2FEF\\u3001-\\uD7FF\\uF900-\\uFDCF\\uFDF0-\\uFFFD\\-.0-9\\u00B7\\u0300-\\u036F\\u203F-\\u2040]*$/, + ka = /^[:A-Z_a-z/u00C0-/u00D6/u00D8-/u00F6/u00F8-/u02FF/u0370-/u037D/u037F-/u1FFF/u200C-/u200D/u2070-/u218F/u2C00-/u2FEF/u3001-/uD7FF/uF900-/uFDCF/uFDF0-/uFFFD][:A-Z_a-z/u00C0-/u00D6/u00D8-/u00F6/u00F8-/u02FF/u0370-/u037D/u037F-/u1FFF/u200C-/u200D/u2070-/u218F/u2C00-/u2FEF/u3001-/uD7FF/uF900-/uFDCF/uFDF0-/uFFFD/-.0-9/u00B7/u0300-/u036F/u203F-/u2040]*$/, la = {}, ma = {}; function oa(a) { @@ -846,7 +846,7 @@ var z = {}; ["rowSpan", "start"].forEach(function (a) { z[a] = new v(a, 5, !1, a.toLowerCase(), null, !1, !1); }); -var ra = /[\\-:]([a-z])/g; +var ra = /[/-:]([a-z])/g; function sa(a) { return a[1].toUpperCase(); } @@ -856,16 +856,16 @@ function sa(a) { }); "xlink:actuate xlink:arcrole xlink:role xlink:show xlink:title xlink:type".split(" ").forEach(function (a) { var b = a.replace(ra, sa); - z[b] = new v(b, 1, !1, a, "http://www.w3.org/1999/xlink", !1, !1); + z[b] = new v(b, 1, !1, a, "http:/www.w3.org/1999/xlink", !1, !1); }); ["xml:base", "xml:lang", "xml:space"].forEach(function (a) { var b = a.replace(ra, sa); - z[b] = new v(b, 1, !1, a, "http://www.w3.org/XML/1998/namespace", !1, !1); + z[b] = new v(b, 1, !1, a, "http:/www.w3.org/XML/1998/namespace", !1, !1); }); ["tabIndex", "crossOrigin"].forEach(function (a) { z[a] = new v(a, 1, !1, a.toLowerCase(), null, !1, !1); }); -z.xlinkHref = new v("xlinkHref", 1, !1, "xlink:href", "http://www.w3.org/1999/xlink", !0, !1); +z.xlinkHref = new v("xlinkHref", 1, !1, "xlink:href", "http:/www.w3.org/1999/xlink", !0, !1); ["src", "href", "action", "formAction"].forEach(function (a) { z[a] = new v(a, 1, !1, a.toLowerCase(), null, !0, !0); }); @@ -904,10 +904,10 @@ function Ma(a) { if (void 0 === La) try { throw Error(); } catch (c) { - var b = c.stack.trim().match(/\\n( *(at )?)/); + var b = c.stack.trim().match(/n( *(at )?)/); La = b && b[1] || ""; } - return "\\n" + La + a; + return "/n" + La + a; } var Na = !1; function Oa(a, b) { @@ -948,11 +948,11 @@ function Oa(a, b) { } } catch (l) { if (l && d && "string" === typeof l.stack) { - for (var e = l.stack.split("\\n"), f = d.stack.split("\\n"), g = e.length - 1, h = f.length - 1; 1 <= g && 0 <= h && e[g] !== f[h];) h--; + for (var e = l.stack.split("/n"), f = d.stack.split("/n"), g = e.length - 1, h = f.length - 1; 1 <= g && 0 <= h && e[g] !== f[h];) h--; for (; 1 <= g && 0 <= h; g--, h--) if (e[g] !== f[h]) { if (1 !== g || 1 !== h) { do if (g--, h--, 0 > h || e[g] !== f[h]) { - var k = "\\n" + e[g].replace(" at new ", " at "); + var k = "/n" + e[g].replace(" at new ", " at "); a.displayName && k.includes("") && (k = k.replace("", a.displayName)); return k; } while (1 <= g && 0 <= h); @@ -1265,15 +1265,15 @@ function jb(a) { function kb(a) { switch (a) { case "svg": - return "http://www.w3.org/2000/svg"; + return "http:/www.w3.org/2000/svg"; case "math": - return "http://www.w3.org/1998/Math/MathML"; + return "http:/www.w3.org/1998/Math/MathML"; default: - return "http://www.w3.org/1999/xhtml"; + return "http:/www.w3.org/1999/xhtml"; } } function lb(a, b) { - return null == a || "http://www.w3.org/1999/xhtml" === a ? kb(b) : "http://www.w3.org/2000/svg" === a && "foreignObject" === b ? "http://www.w3.org/1999/xhtml" : a; + return null == a || "http:/www.w3.org/1999/xhtml" === a ? kb(b) : "http:/www.w3.org/2000/svg" === a && "foreignObject" === b ? "http:/www.w3.org/1999/xhtml" : a; } var mb, nb = function (a) { @@ -1283,7 +1283,7 @@ var mb, }); } : a; }(function (a, b) { - if ("http://www.w3.org/2000/svg" !== a.namespaceURI || "innerHTML" in a) a.innerHTML = b;else { + if ("http:/www.w3.org/2000/svg" !== a.namespaceURI || "innerHTML" in a) a.innerHTML = b;else { mb = mb || document.createElement("div"); mb.innerHTML = "" + b.valueOf().toString() + ""; for (b = mb.firstChild; a.firstChild;) a.removeChild(a.firstChild); @@ -3021,10 +3021,10 @@ function wf(a, b, c, d, e) { listeners: g }); } -var xf = /\\r\\n?/g, - yf = /\\u0000|\\uFFFD/g; +var xf = /r/n?/g, + yf = /u0000|/uFFFD/g; function zf(a) { - return ("string" === typeof a ? a : "" + a).replace(xf, "\\n").replace(yf, ""); + return ("string" === typeof a ? a : "" + a).replace(xf, "/n").replace(yf, ""); } function Af(a, b, c) { b = zf(b); @@ -4627,7 +4627,7 @@ function Ki(a, b) { do c += Pa(d), d = d.return; while (d); var e = c; } catch (f) { - e = "\\nError generating stack: " + f.message + "\\n" + f.stack; + e = "/nError generating stack: " + f.message + "/n" + f.stack; } return { value: a, @@ -5396,8 +5396,8 @@ function Fj(a, b, c) { null !== d && (b.flags |= 4); } else { g = 9 === e.nodeType ? e : e.ownerDocument; - "http://www.w3.org/1999/xhtml" === a && (a = kb(c)); - "http://www.w3.org/1999/xhtml" === a ? "script" === c ? (a = g.createElement("div"), a.innerHTML = " - ` - config.parser = 'vue' - config.semi = false - config.htmlWhitespaceSensitivity = 'ignore' - } return prettier.format(code, config) } diff --git a/packages/taro-cli-convertor/src/util/index.ts b/packages/taro-cli-convertor/src/util/index.ts index d6212c13abad..dd3eda9809aa 100644 --- a/packages/taro-cli-convertor/src/util/index.ts +++ b/packages/taro-cli-convertor/src/util/index.ts @@ -1,3 +1,5 @@ +import * as path from 'node:path' + import generate from '@babel/generator' import { chalk, @@ -11,7 +13,6 @@ import { resolveScriptPath, SCRIPT_EXT, } from '@tarojs/helper' -import * as path from 'path' import * as prettier from 'prettier' import { globals } from './global' diff --git a/packages/taro-cli/package.json b/packages/taro-cli/package.json index 894e1b6363a7..ee7d25267974 100644 --- a/packages/taro-cli/package.json +++ b/packages/taro-cli/package.json @@ -1,24 +1,25 @@ { "name": "@tarojs/cli", - "version": "4.0.0-beta.75", + "version": "4.0.0-alpha.4", "description": "cli tool for taro", + "author": "O2Team", + "license": "MIT", "main": "index.js", "types": "dist/index.d.ts", "scripts": { + "prod": "pnpm run build", "test": "cross-env NODE_ENV=test jest", "test:ci": "cross-env NODE_ENV=test jest --ci -i --coverage --silent", "test:dev": "cross-env NODE_ENV=test jest --watch", "test:coverage": "cross-env NODE_ENV=test jest --coverage", "updateSnapshot": "cross-env NODE_ENV=test jest --updateSnapshot", - "build": "pnpm run clean && pnpm run prod", + "prebuild": "pnpm run clean", + "build": "tsc", "dev": "tsc -w", - "prod": "tsc", "clean": "rimraf --impl=move-remove dist" }, "files": [ "bin", - "__tests__", - "scripts", "src", "dist", "templates", @@ -39,41 +40,33 @@ "engines": { "node": ">= 18" }, - "author": "O2Team", - "license": "MIT", "dependencies": { "@tarojs/binding": "workspace:*", "@tarojs/helper": "workspace:*", "@tarojs/service": "workspace:*", "@tarojs/shared": "workspace:*", - "@tarojs/plugin-doctor": "^0.0.11", - "adm-zip": "^0.4.13", + "@tarojs/plugin-doctor": "^0.0.13", + "adm-zip": "^0.5.12", + "axios": "^1.6.8", "cli-highlight": "^2.1.11", - "download-git-repo": "^2.0.0", - "envinfo": "^7.8.1", - "eslint": "^8.12.0", - "glob": "^7.1.2", - "inquirer": "^8.0.0", + "download-git-repo": "^3.0.2", + "envinfo": "^7.12.0", + "inquirer": "^8.2.6", "latest-version": "^5.1.0", - "lodash": "^4.17.21", "minimist": "^1.2.8", - "npm-check": "^6.0.1", - "ora": "^5.0.0", - "request": "^2.88.0", - "semver": "^7.3.8", - "validate-npm-package-name": "^5.0.0", - "xml2js": "^0.5.0" + "ora": "^5.4.1", + "semver": "^7.6.0", + "validate-npm-package-name": "^5.0.0" }, "devDependencies": { - "@babel/core": "^7.23.0", - "@babel/traverse": "^7.23.0", - "@babel/types": "^7.24.5", - "@types/babel__traverse": "^7.20.5", - "babel-jest": "^29.7.0", - "jest": "^29.3.1", - "jest-cli": "^29.3.1", - "jest-environment-node": "^29.5.0", - "ts-jest": "^29.0.5", - "typescript": "^4.7.4" + "@babel/types": "^7.24.0", + "@tarojs/taro": "workspace:*", + "@tarojs/plugin-platform-weapp": "workspace:*", + "@tarojs/plugin-platform-h5": "workspace:*", + "@tarojs/webpack5-runner": "workspace:*", + "@types/babel__traverse": "^7.20.2", + "babel-preset-taro": "workspace:*", + "eslint-plugin-react": "^7.34.1", + "eslint-plugin-react-hooks": "^4.4.0" } } diff --git a/packages/taro-cli/src/__tests__/doctor-eslint.spec.ts b/packages/taro-cli/src/__tests__/doctor-eslint.spec.ts index 2be785880adf..97ae032cf1cd 100644 --- a/packages/taro-cli/src/__tests__/doctor-eslint.spec.ts +++ b/packages/taro-cli/src/__tests__/doctor-eslint.spec.ts @@ -27,31 +27,4 @@ describe('eslint validator of doctor', () => { expect(isValid).toBe(true) expect(messages.length).toBe(2) }) - - it('should lint for nerv', async () => { - process.chdir(path.join(__dirname, 'fixtures/nerv')) - const { isValid, messages } = await validator({ - projectConfig: { - framework: 'nerv', - sourceRoot: 'src' - }, - chalk - }) - expect(isValid).toBe(false) - expect(messages[1].content.includes('\'a\' is assigned a value but never used')) - }) - - it('should lint for vue', async () => { - process.chdir(path.join(__dirname, 'fixtures/vue')) - const { isValid, messages } = await validator({ - projectConfig: { - framework: 'vue', - sourceRoot: 'src' - }, - chalk - }) - - expect(isValid).toBe(true) - expect(messages.length).toBe(2) - }) }) diff --git a/packages/taro-cli/src/__tests__/fixtures/default/config/index.js b/packages/taro-cli/src/__tests__/fixtures/default/config/index.js index ea835b8a9adf..15f82727d6d0 100644 --- a/packages/taro-cli/src/__tests__/fixtures/default/config/index.js +++ b/packages/taro-cli/src/__tests__/fixtures/default/config/index.js @@ -19,6 +19,12 @@ const config = { } }, framework: 'react', + compiler: { + type: 'webpack5', + prebundle: { + enable: false + } + }, mini: { output: { clean: { diff --git a/packages/taro-cli/src/__tests__/fixtures/nerv/babel.config.js b/packages/taro-cli/src/__tests__/fixtures/nerv/babel.config.js deleted file mode 100644 index f3acb812f5a9..000000000000 --- a/packages/taro-cli/src/__tests__/fixtures/nerv/babel.config.js +++ /dev/null @@ -1,10 +0,0 @@ -// babel-preset-taro 更多选项和默认值: -// https://github.com/NervJS/taro/blob/next/packages/babel-preset-taro/README.md -module.exports = { - presets: [ - ['taro', { - framework: 'react', - ts: true - }] - ] -} diff --git a/packages/taro-cli/src/__tests__/fixtures/nerv/config/dev.js b/packages/taro-cli/src/__tests__/fixtures/nerv/config/dev.js deleted file mode 100644 index 6821bf8e47d4..000000000000 --- a/packages/taro-cli/src/__tests__/fixtures/nerv/config/dev.js +++ /dev/null @@ -1,9 +0,0 @@ -module.exports = { - env: { - NODE_ENV: '"development"' - }, - defineConstants: { - }, - mini: {}, - h5: {} -} diff --git a/packages/taro-cli/src/__tests__/fixtures/nerv/config/index.js b/packages/taro-cli/src/__tests__/fixtures/nerv/config/index.js deleted file mode 100644 index 2e3d59654a69..000000000000 --- a/packages/taro-cli/src/__tests__/fixtures/nerv/config/index.js +++ /dev/null @@ -1,70 +0,0 @@ -const config = { - projectName: 't3', - date: '2020-5-28', - designWidth: 750, - deviceRatio: { - 640: 2.34 / 2, - 750: 1, - 828: 1.81 / 2 - }, - sourceRoot: 'src', - outputRoot: 'dist', - plugins: [], - defineConstants: { - }, - copy: { - patterns: [ - ], - options: { - } - }, - framework: 'nerv', - mini: { - postcss: { - pxtransform: { - enable: true, - config: { - - } - }, - url: { - enable: true, - config: { - limit: 1024 // 设定转换尺寸上限 - } - }, - cssModules: { - enable: false, // 默认为 false,如需使用 css modules 功能,则设为 true - config: { - namingPattern: 'module', // 转换模式,取值为 global/module - generateScopedName: '[name]__[local]___[hash:base64:5]' - } - } - } - }, - h5: { - publicPath: '/', - staticDirectory: 'static', - postcss: { - autoprefixer: { - enable: true, - config: { - } - }, - cssModules: { - enable: false, // 默认为 false,如需使用 css modules 功能,则设为 true - config: { - namingPattern: 'module', // 转换模式,取值为 global/module - generateScopedName: '[name]__[local]___[hash:base64:5]' - } - } - } - } -} - -module.exports = function (merge) { - if (process.env.NODE_ENV === 'development') { - return merge({}, config, require('./dev')) - } - return merge({}, config, require('./prod')) -} diff --git a/packages/taro-cli/src/__tests__/fixtures/nerv/config/prod.js b/packages/taro-cli/src/__tests__/fixtures/nerv/config/prod.js deleted file mode 100644 index 31497d73e2a8..000000000000 --- a/packages/taro-cli/src/__tests__/fixtures/nerv/config/prod.js +++ /dev/null @@ -1,18 +0,0 @@ -module.exports = { - env: { - NODE_ENV: '"production"' - }, - defineConstants: { - }, - mini: {}, - h5: { - /** - * 如果h5端编译后体积过大,可以使用webpack-bundle-analyzer插件对打包体积进行分析。 - * 参考代码如下: - * webpackChain (chain) { - * chain.plugin('analyzer') - * .use(require('webpack-bundle-analyzer').BundleAnalyzerPlugin, []) - * } - */ - } -} diff --git a/packages/taro-cli/src/__tests__/fixtures/nerv/package.json b/packages/taro-cli/src/__tests__/fixtures/nerv/package.json deleted file mode 100644 index be501b44f621..000000000000 --- a/packages/taro-cli/src/__tests__/fixtures/nerv/package.json +++ /dev/null @@ -1,59 +0,0 @@ -{ - "name": "t3", - "version": "1.0.0", - "private": true, - "description": "", - "templateInfo": { - "name": "default", - "typescript": true, - "css": "none" - }, - "scripts": { - "build:weapp": "taro build --type weapp", - "build:swan": "taro build --type swan", - "build:alipay": "taro build --type alipay", - "build:tt": "taro build --type tt", - "build:h5": "taro build --type h5", - "build:rn": "taro build --type rn", - "build:qq": "taro build --type qq", - "build:quickapp": "taro build --type quickapp", - "dev:weapp": "npm run build:weapp -- --watch", - "dev:swan": "npm run build:swan -- --watch", - "dev:alipay": "npm run build:alipay -- --watch", - "dev:tt": "npm run build:tt -- --watch", - "dev:h5": "npm run build:h5 -- --watch", - "dev:rn": "npm run build:rn -- --watch", - "dev:qq": "npm run build:qq -- --watch", - "dev:quickapp": "npm run build:quickapp -- --watch" - }, - "browserslist": [ - "last 3 versions", - "Android >= 4.1", - "ios >= 8" - ], - "author": "", - "dependencies": { - "@babel/runtime": "^7.7.7", - "@tarojs/components": "3.0.0-rc.0", - "@tarojs/runtime": "3.0.0-rc.0", - "@tarojs/taro": "3.0.0-rc.0", - "nervjs": "^1.5.0" - }, - "devDependencies": { - "@types/webpack-env": "^1.13.6", - "@types/react": "^16.0.0", - "@tarojs/mini-runner": "3.0.0-rc.0", - "@babel/core": "^7.8.0", - "@tarojs/webpack-runner": "3.0.0-rc.0", - "babel-preset-taro": "3.0.0-rc.0", - "eslint-config-taro": "3.0.0-rc.0", - "eslint": "^8.12.0", - "eslint-plugin-react": "^7.33.2", - "eslint-plugin-import": "^2.12.0", - "eslint-plugin-react-hooks": "^1.6.1", - "stylelint": "9.3.0", - "@typescript-eslint/parser": "^2.x", - "@typescript-eslint/eslint-plugin": "^2.x", - "typescript": "^3.7.0" - } -} diff --git a/packages/taro-cli/src/__tests__/fixtures/nerv/src/app.tsx b/packages/taro-cli/src/__tests__/fixtures/nerv/src/app.tsx deleted file mode 100644 index ec067310ffb7..000000000000 --- a/packages/taro-cli/src/__tests__/fixtures/nerv/src/app.tsx +++ /dev/null @@ -1,10 +0,0 @@ -import { Component } from 'nervjs' - -class App extends Component { - // this.props.children 是将要会渲染的页面 - render () { - return this.props.children - } -} - -export default App diff --git a/packages/taro-cli/src/__tests__/fixtures/nerv/src/pages/index/index.tsx b/packages/taro-cli/src/__tests__/fixtures/nerv/src/pages/index/index.tsx deleted file mode 100644 index 5e4cbbe19109..000000000000 --- a/packages/taro-cli/src/__tests__/fixtures/nerv/src/pages/index/index.tsx +++ /dev/null @@ -1,25 +0,0 @@ -import Nerv, { Component } from 'nervjs' -import { View, Text } from '@tarojs/components' - -const a = 1 - -export default class Index extends Component { - - componentWillMount () { } - - componentDidMount () { } - - componentWillUnmount () { } - - componentDidShow () { } - - componentDidHide () { } - - render () { - return ( - - Hello world! - - ) - } -} diff --git a/packages/taro-cli/src/__tests__/fixtures/vue/babel.config.js b/packages/taro-cli/src/__tests__/fixtures/vue/babel.config.js deleted file mode 100644 index 92f6a21dadda..000000000000 --- a/packages/taro-cli/src/__tests__/fixtures/vue/babel.config.js +++ /dev/null @@ -1,10 +0,0 @@ -// babel-preset-taro 更多选项和默认值: -// https://github.com/NervJS/taro/blob/next/packages/babel-preset-taro/README.md -module.exports = { - presets: [ - ['taro', { - framework: 'vue', - ts: false - }] - ] -} diff --git a/packages/taro-cli/src/__tests__/fixtures/vue/config/dev.js b/packages/taro-cli/src/__tests__/fixtures/vue/config/dev.js deleted file mode 100644 index 6821bf8e47d4..000000000000 --- a/packages/taro-cli/src/__tests__/fixtures/vue/config/dev.js +++ /dev/null @@ -1,9 +0,0 @@ -module.exports = { - env: { - NODE_ENV: '"development"' - }, - defineConstants: { - }, - mini: {}, - h5: {} -} diff --git a/packages/taro-cli/src/__tests__/fixtures/vue/config/index.js b/packages/taro-cli/src/__tests__/fixtures/vue/config/index.js deleted file mode 100644 index 9436f289a2ba..000000000000 --- a/packages/taro-cli/src/__tests__/fixtures/vue/config/index.js +++ /dev/null @@ -1,70 +0,0 @@ -const config = { - projectName: 't4', - date: '2020-5-28', - designWidth: 750, - deviceRatio: { - 640: 2.34 / 2, - 750: 1, - 828: 1.81 / 2 - }, - sourceRoot: 'src', - outputRoot: 'dist', - plugins: [], - defineConstants: { - }, - copy: { - patterns: [ - ], - options: { - } - }, - framework: 'vue', - mini: { - postcss: { - pxtransform: { - enable: true, - config: { - - } - }, - url: { - enable: true, - config: { - limit: 1024 // 设定转换尺寸上限 - } - }, - cssModules: { - enable: false, // 默认为 false,如需使用 css modules 功能,则设为 true - config: { - namingPattern: 'module', // 转换模式,取值为 global/module - generateScopedName: '[name]__[local]___[hash:base64:5]' - } - } - } - }, - h5: { - publicPath: '/', - staticDirectory: 'static', - postcss: { - autoprefixer: { - enable: true, - config: { - } - }, - cssModules: { - enable: false, // 默认为 false,如需使用 css modules 功能,则设为 true - config: { - namingPattern: 'module', // 转换模式,取值为 global/module - generateScopedName: '[name]__[local]___[hash:base64:5]' - } - } - } - } -} - -module.exports = function (merge) { - if (process.env.NODE_ENV === 'development') { - return merge({}, config, require('./dev')) - } - return merge({}, config, require('./prod')) -} diff --git a/packages/taro-cli/src/__tests__/fixtures/vue/config/prod.js b/packages/taro-cli/src/__tests__/fixtures/vue/config/prod.js deleted file mode 100644 index 31497d73e2a8..000000000000 --- a/packages/taro-cli/src/__tests__/fixtures/vue/config/prod.js +++ /dev/null @@ -1,18 +0,0 @@ -module.exports = { - env: { - NODE_ENV: '"production"' - }, - defineConstants: { - }, - mini: {}, - h5: { - /** - * 如果h5端编译后体积过大,可以使用webpack-bundle-analyzer插件对打包体积进行分析。 - * 参考代码如下: - * webpackChain (chain) { - * chain.plugin('analyzer') - * .use(require('webpack-bundle-analyzer').BundleAnalyzerPlugin, []) - * } - */ - } -} diff --git a/packages/taro-cli/src/__tests__/fixtures/vue/package.json b/packages/taro-cli/src/__tests__/fixtures/vue/package.json deleted file mode 100644 index 6ac1401bef71..000000000000 --- a/packages/taro-cli/src/__tests__/fixtures/vue/package.json +++ /dev/null @@ -1,54 +0,0 @@ -{ - "name": "t4", - "version": "1.0.0", - "private": true, - "description": "", - "templateInfo": { - "name": "default", - "typescript": false, - "css": "none" - }, - "scripts": { - "build:weapp": "taro build --type weapp", - "build:swan": "taro build --type swan", - "build:alipay": "taro build --type alipay", - "build:tt": "taro build --type tt", - "build:h5": "taro build --type h5", - "build:rn": "taro build --type rn", - "build:qq": "taro build --type qq", - "build:quickapp": "taro build --type quickapp", - "dev:weapp": "npm run build:weapp -- --watch", - "dev:swan": "npm run build:swan -- --watch", - "dev:alipay": "npm run build:alipay -- --watch", - "dev:tt": "npm run build:tt -- --watch", - "dev:h5": "npm run build:h5 -- --watch", - "dev:rn": "npm run build:rn -- --watch", - "dev:qq": "npm run build:qq -- --watch", - "dev:quickapp": "npm run build:quickapp -- --watch" - }, - "browserslist": [ - "last 3 versions", - "Android >= 4.1", - "ios >= 8" - ], - "author": "", - "dependencies": { - "@babel/runtime": "^7.7.7", - "@tarojs/components": "3.0.0-rc.0", - "@tarojs/runtime": "3.0.0-rc.0", - "@tarojs/taro": "3.0.0-rc.0", - "vue-template-compiler": "^2.5.0", - "vue": "^2.5.0" - }, - "devDependencies": { - "@types/webpack-env": "^1.13.6", - "@tarojs/mini-runner": "3.0.0-rc.0", - "@babel/core": "^7.8.0", - "@tarojs/webpack-runner": "3.0.0-rc.0", - "babel-preset-taro": "3.0.0-rc.0", - "eslint": "^8.12.0", - "eslint-config-taro": "3.0.0-rc.0", - "eslint-plugin-vue": "^9.x", - "stylelint": "9.3.0" - } -} diff --git a/packages/taro-cli/src/__tests__/fixtures/vue/src/app.js b/packages/taro-cli/src/__tests__/fixtures/vue/src/app.js deleted file mode 100644 index befbfe96693b..000000000000 --- a/packages/taro-cli/src/__tests__/fixtures/vue/src/app.js +++ /dev/null @@ -1,12 +0,0 @@ -import Vue from 'vue' - -const App = new Vue({ - onShow (options) { - }, - render(h) { - // this.$slots.default 是将要会渲染的页面 - return h('block', this.$slots.default) - } -}) - -export default App diff --git a/packages/taro-cli/src/__tests__/fixtures/vue/src/pages/index/index.vue b/packages/taro-cli/src/__tests__/fixtures/vue/src/pages/index/index.vue deleted file mode 100644 index e3170d2a0aa4..000000000000 --- a/packages/taro-cli/src/__tests__/fixtures/vue/src/pages/index/index.vue +++ /dev/null @@ -1,15 +0,0 @@ - - - diff --git a/packages/taro-cli/src/__tests__/info.spec.ts b/packages/taro-cli/src/__tests__/info.spec.ts index 38688ef137cb..4c762adee332 100644 --- a/packages/taro-cli/src/__tests__/info.spec.ts +++ b/packages/taro-cli/src/__tests__/info.spec.ts @@ -59,7 +59,6 @@ describe('info', () => { // Note: 环境内可能不包括 Yarn expect(Object.keys(info.Binaries)).toEqual(expect.arrayContaining(['Node', 'npm'])) // expect(info.npmPackages.hasOwnProperty('@tarojs/helper')).toBeTruthy() - // expect(info.npmPackages.hasOwnProperty('@tarojs/mini-runner')).toBeTruthy() // expect(info.npmPackages.hasOwnProperty('@tarojs/service')).toBeTruthy() // expect(info.npmPackages.hasOwnProperty('@tarojs/taro')).toBeTruthy() // expect(info.npmPackages.hasOwnProperty('@tarojs/taroize')).toBeTruthy() diff --git a/packages/taro-cli/src/__tests__/inspect.spec.ts b/packages/taro-cli/src/__tests__/inspect.spec.ts index 3145aaf2672c..586f97fc3056 100644 --- a/packages/taro-cli/src/__tests__/inspect.spec.ts +++ b/packages/taro-cli/src/__tests__/inspect.spec.ts @@ -32,6 +32,10 @@ const runInspect = run('inspect', [ ]) describe('inspect', () => { + beforeEach(() => { + jest.resetModules() + }) + it('should exit because there isn\'t a Taro project', async () => { const exitSpy = jest.spyOn(process, 'exit') as jest.SpyInstance const logSpy = jest.spyOn(console, 'log') @@ -74,7 +78,7 @@ describe('inspect', () => { it('should log config', async () => { const exitSpy = jest.spyOn(process, 'exit') as jest.SpyInstance - const logSpy = jest.spyOn(console, 'log') + const logSpy = jest.spyOn(console, 'info') exitSpy.mockImplementation(() => { throw new Error() @@ -99,7 +103,7 @@ describe('inspect', () => { it('should log specific config', async () => { const exitSpy = jest.spyOn(process, 'exit') as jest.SpyInstance - const logSpy = jest.spyOn(console, 'log') + const logSpy = jest.spyOn(console, 'info') const errorSpy = jest.spyOn(console, 'error') exitSpy.mockImplementation(() => { diff --git a/packages/taro-cli/src/__tests__/update.spec.ts b/packages/taro-cli/src/__tests__/update.spec.ts index 2a68e9848df5..e7da99456418 100644 --- a/packages/taro-cli/src/__tests__/update.spec.ts +++ b/packages/taro-cli/src/__tests__/update.spec.ts @@ -79,13 +79,11 @@ function updatePkg (pkgPath: string, version: string) { '@tarojs/taro-h5': version, '@tarojs/helper': version, '@tarojs/taro-loader': version, - '@tarojs/mini-runner': version, '@tarojs/react': version, '@tarojs/router': version, '@tarojs/runner-utils': version, '@tarojs/runtime': version, '@tarojs/service': version, - '@tarojs/webpack-runner': version, '@tarojs/with-weapp': version, '@tarojs/taroize': version, '@tarojs/plugin-platform-weapp': version, diff --git a/packages/taro-cli/src/config/babylon.ts b/packages/taro-cli/src/config/babylon.ts deleted file mode 100644 index e0cf4ed31199..000000000000 --- a/packages/taro-cli/src/config/babylon.ts +++ /dev/null @@ -1,16 +0,0 @@ -import type { ParserOptions } from '@babel/parser' - -const config: ParserOptions = { - sourceType: 'module', - plugins: [ - 'typescript', - 'classProperties', - 'jsx', - 'asyncGenerators', - 'objectRestSpread', - 'decorators', - 'dynamicImport' - ] -} - -export default config diff --git a/packages/taro-cli/src/create/fetchTemplate.ts b/packages/taro-cli/src/create/fetchTemplate.ts index e2c5b3efa5b9..43b421e7b96f 100644 --- a/packages/taro-cli/src/create/fetchTemplate.ts +++ b/packages/taro-cli/src/create/fetchTemplate.ts @@ -1,9 +1,9 @@ import { chalk, fs } from '@tarojs/helper' import * as AdmZip from 'adm-zip' +import axios from 'axios' import * as download from 'download-git-repo' import * as ora from 'ora' import * as path from 'path' -import * as request from 'request' import { getTemplateSourceType, readDirWithFileTypes } from '../util' import { TEMPLATE_CREATOR } from './constants' @@ -48,31 +48,34 @@ export default function fetchTemplate (templateSource: string, templateRootPath: name = 'from-remote-url' const zipPath = path.join(tempPath, name + '.zip') const unZipPath = path.join(tempPath, name) - request - .get(templateSource) - .pipe(fs.createWriteStream(zipPath)) - .on('close', () => { - // unzip - const zip = new AdmZip(zipPath) - zip.extractAllTo(unZipPath, true) - const files = readDirWithFileTypes(unZipPath).filter( - file => !file.name.startsWith('.') && file.isDirectory && file.name !== '__MACOSX' - ) - - if (files.length !== 1) { - spinner.color = 'red' - spinner.fail(chalk.red(`拉取远程模板仓库失败!\n${new Error('远程模板源组织格式错误')}`)) - return resolve() - } - name = path.join(name, files[0].name) - - spinner.color = 'green' - spinner.succeed(`${chalk.grey('拉取远程模板仓库成功!')}`) - resolve() + axios.get(templateSource, { responseType: 'stream' }) + .then(response => { + const ws = fs.createWriteStream(zipPath) + response.data.pipe(ws) + ws.on('finish', () => { + // unzip + const zip = new AdmZip(zipPath) + zip.extractAllTo(unZipPath, true) + const files = readDirWithFileTypes(unZipPath).filter( + file => !file.name.startsWith('.') && file.isDirectory && file.name !== '__MACOSX' + ) + + if (files.length !== 1) { + spinner.color = 'red' + spinner.fail(chalk.red(`拉取远程模板仓库失败!\n${new Error('远程模板源组织格式错误')}`)) + return resolve() + } + name = path.join(name, files[0].name) + + spinner.color = 'green' + spinner.succeed(`${chalk.grey('拉取远程模板仓库成功!')}`) + resolve() + }) + ws.on('error', error => { throw error }) }) - .on('error', async err => { + .catch(async error => { spinner.color = 'red' - spinner.fail(chalk.red(`拉取远程模板仓库失败!\n${err}`)) + spinner.fail(chalk.red(`拉取远程模板仓库失败!\n${error}`)) await fs.remove(tempPath) return resolve() }) diff --git a/packages/taro-cli/src/create/page.ts b/packages/taro-cli/src/create/page.ts index 00de684d3c1c..1110f59e3580 100644 --- a/packages/taro-cli/src/create/page.ts +++ b/packages/taro-cli/src/create/page.ts @@ -1,9 +1,8 @@ import { CompilerType, createPage as createPageBinding, CSSType, FrameworkType, NpmType, PeriodType } from '@tarojs/binding' import { babelKit, chalk, DEFAULT_TEMPLATE_SRC, fs, getUserHomeDir, resolveScriptPath, TARO_BASE_CONFIG, TARO_CONFIG_FOLDER } from '@tarojs/helper' -import { isNil } from 'lodash' import * as path from 'path' -import { getPkgVersion, getRootPath } from '../util' +import { getPkgVersion, getRootPath, isNil } from '../util' import { modifyPagesOrSubPackages } from '../util/createPage' import { TEMPLATE_CREATOR } from './constants' import Creator from './creator' diff --git a/packages/taro-cli/src/create/project.ts b/packages/taro-cli/src/create/project.ts index cf60c72bb10a..e4b537ef20dc 100644 --- a/packages/taro-cli/src/create/project.ts +++ b/packages/taro-cli/src/create/project.ts @@ -10,10 +10,10 @@ import { TARO_CONFIG_FOLDER } from '@tarojs/helper' import { isArray } from '@tarojs/shared' +import axios from 'axios' import * as inquirer from 'inquirer' import * as ora from 'ora' import * as path from 'path' -import * as request from 'request' import * as semver from 'semver' import { clearConsole, getPkgVersion, getRootPath } from '../util' @@ -59,9 +59,9 @@ export default class Project extends Creator { constructor (options: IProjectConfOptions) { super(options.sourceRoot) - const unSupportedVer = semver.lt(process.version, 'v7.6.0') + const unSupportedVer = semver.lt(process.version, 'v18.0.0') if (unSupportedVer) { - throw new Error('Node.js 版本过低,推荐升级 Node.js 至 v8.0.0+') + throw new Error('Node.js 版本过低,推荐升级 Node.js 至 v18.0.0+') } this.rootPath = this._rootPath @@ -212,10 +212,6 @@ export default class Project extends Creator { name: 'Webpack5', value: CompilerType.Webpack5 }, - { - name: 'Webpack4', - value: CompilerType.Webpack4 - }, { name: 'Vite', value: CompilerType.Vite @@ -242,14 +238,6 @@ export default class Project extends Creator { name: 'PReact', value: FrameworkType.Preact }, - // { - // name: 'Nerv', - // value: 'nerv' - // }, - { - name: 'Vue', - value: FrameworkType.Vue - }, { name: 'Vue3', value: FrameworkType.Vue3 @@ -414,10 +402,11 @@ export default class Project extends Creator { const templateChoices = await fetchTemplate(this.conf.templateSource, this.templatePath(''), isClone) const filterFramework = (_framework) => { + const current = framework.toLowerCase() if (typeof _framework === 'string' && _framework) { - return framework === _framework + return current === _framework.toLowerCase() } else if (isArray(_framework)) { - return _framework?.includes(framework) + return _framework?.map(name => name.toLowerCase()).includes(current) } else { return true } @@ -468,27 +457,23 @@ export default class Project extends Creator { } } -function getOpenSourceTemplates (platform) { +function getOpenSourceTemplates (platform: string) { return new Promise((resolve, reject) => { const spinner = ora({ text: '正在拉取开源模板列表...', discardStdin: false }).start() - request.get('https://gitee.com/NervJS/awesome-taro/raw/next/index.json', (error, _response, body) => { - if (error) { + axios.get('https://gitee.com/NervJS/awesome-taro/raw/next/index.json') + .then(response => { + spinner.succeed(`${chalk.grey('拉取开源模板列表成功!')}`) + const collection = response.data + switch (platform.toLowerCase()) { + case 'react': + return resolve(collection.react) + default: + return resolve([NONE_AVAILABLE_TEMPLATE]) + } + }) + .catch(_error => { spinner.fail(chalk.red('拉取开源模板列表失败!')) return reject(new Error()) - } - - spinner.succeed(`${chalk.grey('拉取开源模板列表成功!')}`) - - const collection = JSON.parse(body) - - switch (platform) { - case 'react': - return resolve(collection.react) - case 'vue': - return resolve(collection.vue) - default: - return resolve([NONE_AVAILABLE_TEMPLATE]) - } - }) + }) }) } diff --git a/packages/taro-cli/src/presets/commands/inspect.ts b/packages/taro-cli/src/presets/commands/inspect.ts index c150ab407ea7..b86dde3257db 100644 --- a/packages/taro-cli/src/presets/commands/inspect.ts +++ b/packages/taro-cli/src/presets/commands/inspect.ts @@ -74,7 +74,7 @@ export default (ctx: IPluginContext) => { if (mode === 'console') { const highlight = require('cli-highlight').default - console.log(highlight(res, { language: 'js' })) + console.info(highlight(res, { language: 'js' })) } else if (mode === 'output' && outputPath) { fs.writeFileSync(outputPath, res) } diff --git a/packages/taro-cli/src/util/index.ts b/packages/taro-cli/src/util/index.ts index bd98722a5d57..983de20abe69 100644 --- a/packages/taro-cli/src/util/index.ts +++ b/packages/taro-cli/src/util/index.ts @@ -120,3 +120,7 @@ export function getPkgNameByFilterVersion (pkgString: string) { const versionFlagIndex = pkgString.lastIndexOf('@') return versionFlagIndex === 0 ? pkgString : pkgString.slice(0, versionFlagIndex) } + +export function isNil (value: any): value is null | undefined { + return value === null || value === undefined +} diff --git a/packages/taro-cli/templates/default/__tests__/index.test.js.tmpl b/packages/taro-cli/templates/default/__tests__/index.test.js.tmpl index 9663bfe1e61d..e5e39426979c 100644 --- a/packages/taro-cli/templates/default/__tests__/index.test.js.tmpl +++ b/packages/taro-cli/templates/default/__tests__/index.test.js.tmpl @@ -1,4 +1,4 @@ -{{#if (includes "React" "Preact" s=framework)}}import TestUtils from '@tarojs/test-utils-react'{{/if}}{{#if (eq framework "Vue3") }}import TestUtils from '@tarojs/test-utils-vue3'{{/if}}{{#if (eq framework "Vue") }}import TestUtils from '@tarojs/test-utils-vue'{{/if}} +{{#if (includes "React" "Preact" s=framework)}}import TestUtils from '@tarojs/test-utils-react'{{/if}}{{#if (eq framework "Vue3") }}import TestUtils from '@tarojs/test-utils-vue3'{{/if}} describe('Testing', () => { diff --git a/packages/taro-cli/templates/default/_env.development b/packages/taro-cli/templates/default/_env.development index a3f1b48d3651..0a4b7898f6e7 100644 --- a/packages/taro-cli/templates/default/_env.development +++ b/packages/taro-cli/templates/default/_env.development @@ -1,2 +1,2 @@ # 配置文档参考 https://taro-docs.jd.com/docs/next/env-mode-config -# TARO_APP_ID="开发环境下的小程序appid" \ No newline at end of file +# TARO_APP_ID="开发环境下的小程序 AppID" diff --git a/packages/taro-cli/templates/default/_env.production b/packages/taro-cli/templates/default/_env.production index be6f45ea6c55..eb3c3a17a874 100644 --- a/packages/taro-cli/templates/default/_env.production +++ b/packages/taro-cli/templates/default/_env.production @@ -1 +1 @@ -# TARO_APP_ID="生产环境下的小程序appid" \ No newline at end of file +# TARO_APP_ID="生产环境下的小程序 AppID" diff --git a/packages/taro-cli/templates/default/_env.test b/packages/taro-cli/templates/default/_env.test index 0215b61e17d2..194e8295a67a 100644 --- a/packages/taro-cli/templates/default/_env.test +++ b/packages/taro-cli/templates/default/_env.test @@ -1 +1 @@ -# TARO_APP_ID="测试环境下的小程序appid" \ No newline at end of file +# TARO_APP_ID="测试环境下的小程序 AppID" diff --git a/packages/taro-cli/templates/default/_eslintrc b/packages/taro-cli/templates/default/_eslintrc index 399160e9d650..93c8ebc29732 100644 --- a/packages/taro-cli/templates/default/_eslintrc +++ b/packages/taro-cli/templates/default/_eslintrc @@ -1,4 +1,4 @@ -{{#if (includes "Vue" "Vue3" s=framework)}} +{{#if (includes "Vue3" s=framework)}} // ESLint 检查 .vue 文件需要单独配置编辑器: // https://eslint.vuejs.org/user-guide/#editor-integrations {{/if}} diff --git a/packages/taro-cli/templates/default/jest.config.js b/packages/taro-cli/templates/default/jest.config.js index c82ad48702b3..9a07444579e0 100644 --- a/packages/taro-cli/templates/default/jest.config.js +++ b/packages/taro-cli/templates/default/jest.config.js @@ -1,4 +1,4 @@ -{{#if (includes "React" "Preact" s=framework)}}const defineJestConfig = require('@tarojs/test-utils-react/dist/jest.js').default{{/if}}{{#if (eq framework "Vue3") }}const defineJestConfig = require('@tarojs/test-utils-vue3/dist/jest.js').default{{/if}}{{#if (eq framework "Vue") }}const defineJestConfig = require('@tarojs/test-utils-vue/dist/jest.js').default{{/if}} +{{#if (includes "React" "Preact" s=framework)}}const defineJestConfig = require('@tarojs/test-utils-react/dist/jest.js').default{{/if}}{{#if (eq framework "Vue3") }}const defineJestConfig = require('@tarojs/test-utils-vue3/dist/jest.js').default{{/if}} module.exports = defineJestConfig({ testEnvironment: 'jsdom', diff --git a/packages/taro-cli/templates/default/package.json.tmpl b/packages/taro-cli/templates/default/package.json.tmpl index ed1f96413a14..779f7525ebf3 100644 --- a/packages/taro-cli/templates/default/package.json.tmpl +++ b/packages/taro-cli/templates/default/package.json.tmpl @@ -18,7 +18,6 @@ "build:rn": "taro build --type rn", "build:qq": "taro build --type qq", "build:jd": "taro build --type jd", - "build:quickapp": "taro build --type quickapp", "build:harmony-hybrid": "taro build --type harmony-hybrid", "dev:weapp": "npm run build:weapp -- --watch", "dev:swan": "npm run build:swan -- --watch", @@ -28,7 +27,6 @@ "dev:rn": "npm run build:rn -- --watch", "dev:qq": "npm run build:qq -- --watch", "dev:jd": "npm run build:jd -- --watch", - "dev:quickapp": "npm run build:quickapp -- --watch", "dev:harmony-hybrid": "npm run build:harmony-hybrid -- --watch", "test": "jest" }, @@ -38,7 +36,7 @@ ], "author": "", "dependencies": { - "@babel/runtime": "^7.21.5", + "@babel/runtime": "^7.24.4", "@tarojs/components": "{{ version }}", "@tarojs/helper": "{{ version }}", "@tarojs/plugin-platform-weapp": "{{ version }}", @@ -56,92 +54,77 @@ "@tarojs/react": "{{ version }}", "react-dom": "^18.0.0", "react": "^18.0.0"{{/if}}{{#if (eq framework "Preact") }} - "preact": "^10.5.15"{{/if}}{{#if (eq framework "Vue") }} - "@tarojs/plugin-framework-vue2": "{{ version }}", - "vue-template-compiler": "^2.5.0", - "vue": "^2.5.0"{{/if}}{{#if (eq framework "Vue3") }} + "preact": "^10.5.15"{{/if}}{{#if (eq framework "Vue3") }} "@tarojs/plugin-framework-vue3": "{{ version }}", "vue": "^3.0.0"{{/if}} - },{{#if (includes "Webpack4" "Webpack5" s=compiler)}} + },{{#if (includes "Webpack5" s=compiler)}} "devDependencies": { - "@babel/core": "^7.8.0", + "@babel/core": "^7.24.4", "@tarojs/cli": "{{ version }}", "@types/webpack-env": "^1.13.6",{{#if (includes "React" "Preact" s=framework)}} "@tarojs/test-utils-react": "^0.1.1", - "@types/react": "^18.0.0",{{/if}}{{#if (eq compiler "Webpack4") }} - "@tarojs/mini-runner": "{{ version }}", - "@tarojs/webpack-runner": "{{ version }}", - "webpack": "4.46.0",{{/if}}{{#if (eq compiler "Webpack5") }} - "webpack": "5.78.0", + "@types/react": "^18.0.0",{{/if}}{{#if (eq compiler "Webpack5") }} + "webpack": "5.91.0", "@tarojs/taro-loader": "{{ version }}", - "@tarojs/webpack5-runner": "{{ version }}",{{/if}} - "babel-preset-taro": "{{ version }}",{{#if (includes "Vue" "Vue3" s=framework)}} - "css-loader": "3.4.2", - "style-loader": "1.3.0",{{/if}}{{#if (eq framework "Vue") }} - "@tarojs/test-utils-vue": "^0.1.1", - "@vue/babel-preset-jsx": "^1.2.4", - "vue-loader": "^15.9.2", - "eslint-plugin-vue": "^8.x",{{/if}}{{#if (eq framework "Vue3") }} + "@tarojs/webpack5-runner": "{{ version }}",{{/if}}{{#if (eq css "Sass") }} + "sass": "^1.75.0",{{/if}}{{#if (eq css "Less") }} + "less": "^4.2.0",{{/if}}{{#if (eq css "Stylus") }} + "stylus": "^0.63.0",{{/if}} + "babel-preset-taro": "{{ version }}",{{#if (eq framework "Vue3") }} + "css-loader": "^7.1.1", + "style-loader": "^3.3.4", "@tarojs/test-utils-vue3": "^0.1.1", - "@vue/babel-plugin-jsx": "^1.0.6", + "@vue/babel-plugin-jsx": "^1.2.2", "@vue/compiler-sfc": "^3.0.0", - "vue-loader": "^17.1.0", - "eslint-plugin-vue": "^8.0.0",{{/if}} + "vue-loader": "^17.4.2", + "eslint-plugin-vue": "^9.17.0",{{/if}} "eslint-config-taro": "{{ version }}", - "eslint": "^8.12.0",{{#if (eq framework "React") }} + "eslint": "^8.57.0",{{#if (eq framework "React") }} + "@babel/preset-react": "^7.24.1", "@pmmmwh/react-refresh-webpack-plugin": "^0.5.5", - "react-refresh": "^0.11.0",{{/if}}{{#if (eq framework "Preact") }} - "@prefresh/webpack": "^3.2.3", - "@prefresh/core": "^1.3.4", - "@prefresh/babel-plugin": "^0.4.1",{{/if}}{{#if (includes "React" "Preact" s=framework)}} - "eslint-plugin-react": "^7.8.2", - "eslint-plugin-import": "^2.12.0", - "eslint-plugin-react-hooks": "^4.2.0",{{/if}} - "stylelint": "^14.4.0"{{#if typescript }}, - "@typescript-eslint/parser": "^6.2.0", - "@typescript-eslint/eslint-plugin": "^6.2.0", - "typescript": "^5.1.0", + "react-refresh": "^0.14.0",{{/if}}{{#if (eq framework "Preact") }} + "@prefresh/webpack": "^4", + "@prefresh/core": "^1.5.2", + "@prefresh/babel-plugin": "^0.5.1",{{/if}}{{#if (includes "React" "Preact" s=framework)}} + "eslint-plugin-react": "^7.34.1", + "eslint-plugin-react-hooks": "^4.4.0",{{/if}} + "stylelint": "^16.4.0"{{#if typescript }}, + "typescript": "^5.4.5", "tsconfig-paths-webpack-plugin": "^4.1.0"{{/if}}, - "postcss": "^8.4.18", - "ts-node": "^10.9.1", - "@types/node": "^18.15.11", - "@types/jest": "^29.3.1", - "jest": "^29.3.1", - "jest-environment-jsdom": "^29.5.0" + "postcss": "^8.4.38", + "@types/node": "^18", + "@types/jest": "^29.5.0", + "jest": "^29.7.0", + "jest-environment-jsdom": "^29.6.4" }{{/if}}{{#if (eq compiler "Vite") }} "devDependencies": { - "@babel/core": "^7.8.0", + "@babel/core": "^7.24.4", "@tarojs/cli": "{{ version }}", "@tarojs/vite-runner": "{{ version }}", "babel-preset-taro": "{{ version }}", "eslint-config-taro": "{{ version }}", - "eslint": "^8.12.0", - "stylelint": "^14.4.0", - "terser": "^5.16.8", - "vite": "^4.2.0",{{#if (includes "React" "Preact" s=framework)}} + "eslint": "^8.57.0", + "stylelint": "^16.4.0", + "terser": "^5.30.4", + "vite": "^5.2.10",{{#if (includes "React" "Preact" s=framework)}} "@tarojs/test-utils-react": "^0.1.1", "@types/react": "^18.0.0", - "@vitejs/plugin-react": "^4.1.0", - "eslint-plugin-react": "^7.8.2", - "eslint-plugin-import": "^2.12.0", - "eslint-plugin-react-hooks": "^4.2.0",{{/if}}{{#if (eq framework "Preact") }} - "@preact/preset-vite": "^2.5.0", - "@prefresh/core": "^1.3.4", - "@prefresh/babel-plugin": "^0.4.1",{{/if}}{{#if (eq framework "React") }} - "react-refresh": "^0.11.0",{{/if}}{{#if (eq framework "Vue") }} - "@vitejs/plugin-vue2": "^2.2.0", - "eslint-plugin-vue": "^8.x",{{/if}}{{#if (eq framework "Vue3") }} - "@vitejs/plugin-vue": "^4.0.0", - "@vitejs/plugin-vue-jsx": "^3.0.0", - "eslint-plugin-vue": "^8.0.0",{{/if}}{{#if (eq css "Sass") }} - "sass": "^1.60.0",{{/if}}{{#if (eq css "Less") }} - "less": "^4.1.3",{{/if}}{{#if (eq css "Stylus") }} - "stylus": "^0.59.0",{{/if}}{{#if typescript }} - "@typescript-eslint/parser": "^6.2.0", - "@typescript-eslint/eslint-plugin": "^6.2.0", - "typescript": "^5.1.0",{{/if}} - "postcss": "^8.4.18", - "jest-environment-jsdom": "^29.5.0" + "@vitejs/plugin-react": "^4.3.0", + "eslint-plugin-react": "^7.34.1", + "eslint-plugin-react-hooks": "^4.4.0",{{/if}}{{#if (eq framework "Preact") }} + "@preact/preset-vite": "^2.8.2", + "@prefresh/core": "^1.5.2", + "@prefresh/babel-plugin": "^0.5.1",{{/if}}{{#if (eq framework "React") }} + "react-refresh": "^0.14.0",{{/if}}{{#if (eq framework "Vue3") }} + "@vitejs/plugin-vue": "^5.0.4", + "@vitejs/plugin-vue-jsx": "^3.1.0", + "eslint-plugin-vue": "^9.17.0",{{/if}}{{#if (eq css "Sass") }} + "sass": "^1.75.0",{{/if}}{{#if (eq css "Less") }} + "less": "^4.2.0",{{/if}}{{#if (eq css "Stylus") }} + "stylus": "^0.63.0",{{/if}}{{#if typescript }} + "typescript": "^5.4.5",{{/if}} + "postcss": "^8.4.38", + "jest-environment-jsdom": "^29.6.4" }{{/if}} } diff --git a/packages/taro-cli/templates/default/project.tt.json b/packages/taro-cli/templates/default/project.tt.json deleted file mode 100644 index 50acb68db198..000000000000 --- a/packages/taro-cli/templates/default/project.tt.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "miniprogramRoot": "./", - "projectname": "{{ projectName }}", - "appid": "testAppId", - "setting": { - "es6": false, - "minified": false - } -} diff --git a/packages/taro-cli/templates/default/src/app.js b/packages/taro-cli/templates/default/src/app.js index e699317b5bab..c58b3f60062f 100644 --- a/packages/taro-cli/templates/default/src/app.js +++ b/packages/taro-cli/templates/default/src/app.js @@ -1,8 +1,6 @@ {{#if (includes "React" "Preact" s=framework)}} {{#if typescript }}import { PropsWithChildren } from 'react'{{/if}} import { useLaunch } from '@tarojs/taro' -{{/if}}{{#if (eq framework 'Vue') }} -import Vue from 'vue' {{/if}}{{#if (eq framework 'Vue3') }} import { createApp } from 'vue' {{/if}} @@ -10,7 +8,6 @@ import './app.{{ cssExt }}' {{#if (includes "React" "Preact" s=framework)}} function App({ children }{{#if typescript }}: PropsWithChildren{{/if}}) { - useLaunch(() => { console.log('App launched.') }) @@ -19,17 +16,6 @@ function App({ children }{{#if typescript }}: PropsWithChildren{{/if}}) { return children } {{/if}} -{{#if (eq framework 'Vue') }} -const App = { - onShow (options) { - console.log('App onShow.') - }, - render(h) { - // this.$slots.default 是将要会渲染的页面 - return h('block', this.$slots.default) - } -} -{{/if}} {{#if (eq framework 'Vue3') }} const App = createApp({ onShow (options) { diff --git a/packages/taro-cli/templates/default/src/pages/index/index.jsx b/packages/taro-cli/templates/default/src/pages/index/index.jsx index 78edcb256717..653a60ef1569 100644 --- a/packages/taro-cli/templates/default/src/pages/index/index.jsx +++ b/packages/taro-cli/templates/default/src/pages/index/index.jsx @@ -2,8 +2,7 @@ import { View, Text } from '@tarojs/components' import { useLoad } from '@tarojs/taro' import './index.{{ cssExt }}' -export default function {{ to_pascal_case pageName }}() { - +export default function {{ to_pascal_case pageName }} () { useLoad(() => { console.log('Page loaded.') }) diff --git a/packages/taro-cli/templates/default/src/pages/index/index.vue b/packages/taro-cli/templates/default/src/pages/index/index.vue index 5ba48c0ac83f..bf5fddce3f52 100644 --- a/packages/taro-cli/templates/default/src/pages/index/index.vue +++ b/packages/taro-cli/templates/default/src/pages/index/index.vue @@ -11,13 +11,6 @@ import { ref } from 'vue' import './index.{{ cssExt }}' export default { -{{#if (eq framework 'Vue') }} - data () { - return { - msg: 'Hello world!' - } - } -{{/if}} {{#if (eq framework 'Vue3') }} setup () { const msg = ref('Hello world') diff --git a/packages/taro-cli/templates/default/template_creator.js b/packages/taro-cli/templates/default/template_creator.js index f9d2061e4e30..05cb76be44f5 100644 --- a/packages/taro-cli/templates/default/template_creator.js +++ b/packages/taro-cli/templates/default/template_creator.js @@ -15,30 +15,30 @@ const handler = { '/tsconfig.json': createWhenTs, '/types/global.d.ts': createWhenTs, '/types/vue.d.ts' (err, { framework, typescript }) { - return ['Vue', 'Vue3'].includes(framework) && !!typescript + return ['Vue3'].includes(framework) && !!typescript }, '/src/pages/index/index.jsx' (err, { pageDir = '', pageName = '', subPkg = '' }) { - return { + return { setPageName: normalizePath(path.join(PAGES_ENTRY, pageDir, pageName, 'index.jsx')), - setSubPkgName: normalizePath(path.join(SOURCE_ENTRY, subPkg, pageDir, pageName, 'index.jsx')) + setSubPkgName: normalizePath(path.join(SOURCE_ENTRY, subPkg, pageDir, pageName, 'index.jsx')) } }, '/src/pages/index/index.css' (err, { pageDir = '', pageName = '', subPkg = '' }) { - return { + return { setPageName: normalizePath(path.join(PAGES_ENTRY, pageDir, pageName, 'index.css')), - setSubPkgName: normalizePath(path.join(SOURCE_ENTRY, subPkg, pageDir, pageName, 'index.css')) + setSubPkgName: normalizePath(path.join(SOURCE_ENTRY, subPkg, pageDir, pageName, 'index.css')) } }, '/src/pages/index/index.vue' (err, { pageDir = '', pageName = '', subPkg = '' }) { - return { + return { setPageName: normalizePath(path.join(PAGES_ENTRY, pageDir, pageName, 'index.vue')), - setSubPkgName: normalizePath(path.join(SOURCE_ENTRY, subPkg, pageDir, pageName, 'index.vue')) + setSubPkgName: normalizePath(path.join(SOURCE_ENTRY, subPkg, pageDir, pageName, 'index.vue')) } }, '/src/pages/index/index.config.js' (err, { pageDir = '', pageName = '', subPkg = '' }) { - return { + return { setPageName: normalizePath(path.join(PAGES_ENTRY, pageDir, pageName, 'index.config.js')), - setSubPkgName: normalizePath(path.join(SOURCE_ENTRY, subPkg, pageDir, pageName, 'index.config.js')) + setSubPkgName: normalizePath(path.join(SOURCE_ENTRY, subPkg, pageDir, pageName, 'index.config.js')) } }, '/_editorconfig' () { diff --git a/packages/taro-cli/templates/default/tsconfig.json b/packages/taro-cli/templates/default/tsconfig.json index 2f19eb1c44db..4e7bf42205a7 100644 --- a/packages/taro-cli/templates/default/tsconfig.json +++ b/packages/taro-cli/templates/default/tsconfig.json @@ -14,7 +14,7 @@ "strictNullChecks": true, "sourceMap": true, "rootDir": ".", - "jsx": "{{#if (includes "Vue" "Vue3" s=framework)}}preserve{{else}}react-jsx{{/if}}",{{#if (eq framework "Preact") }} + "jsx": "{{#if (includes "Vue3" s=framework)}}preserve{{else}}react-jsx{{/if}}",{{#if (eq framework "Preact") }} "skipLibCheck": true,{{/if}} "allowJs": true, "resolveJsonModule": true, diff --git a/packages/taro-cli/templates/default/types/global.d.ts b/packages/taro-cli/templates/default/types/global.d.ts index a421664d8c29..898f75812e37 100644 --- a/packages/taro-cli/templates/default/types/global.d.ts +++ b/packages/taro-cli/templates/default/types/global.d.ts @@ -16,7 +16,7 @@ declare namespace NodeJS { /** NODE 内置环境变量, 会影响到最终构建生成产物 */ NODE_ENV: 'development' | 'production', /** 当前构建的平台 */ - TARO_ENV: 'weapp' | 'swan' | 'alipay' | 'h5' | 'rn' | 'tt' | 'quickapp' | 'qq' | 'jd' + TARO_ENV: 'weapp' | 'swan' | 'alipay' | 'h5' | 'rn' | 'tt' | 'qq' | 'jd' | 'harmony' | 'jdrn' /** * 当前构建的小程序 appid * @description 若不同环境有不同的小程序,可通过在 env 文件中配置环境变量`TARO_APP_ID`来方便快速切换 appid, 而不必手动去修改 dist/project.config.json 文件 @@ -26,7 +26,7 @@ declare namespace NodeJS { } } -{{#if (includes "Vue" "Vue3" s=framework)}} +{{#if (includes "Vue3" s=framework)}} declare module '@tarojs/components' { export * from '@tarojs/components/types/index.vue3' }{{/if}} diff --git a/packages/taro-cli/templates/plugin-compile/README.md b/packages/taro-cli/templates/plugin-compile/README.md index 38680e1e0118..503739e9a529 100644 --- a/packages/taro-cli/templates/plugin-compile/README.md +++ b/packages/taro-cli/templates/plugin-compile/README.md @@ -18,7 +18,7 @@ npm i {{ projectName }} -D * installPath: string 安装的路径 * css?: 'none' | 'sass' | 'stylus' | 'less' * typescript?: boolean - * compiler?: 'webpack4' | 'webpack5' | 'vite' + * compiler?: 'webpack5' | 'vite' * } * 这些参数后续会被模版文件解析所用 * 如果不传,会从 package.json 的 templateInfo diff --git a/packages/taro-cli/templates/plugin-compile/package.json.tmpl b/packages/taro-cli/templates/plugin-compile/package.json.tmpl index ed8ee2557560..7be4ab5aba37 100644 --- a/packages/taro-cli/templates/plugin-compile/package.json.tmpl +++ b/packages/taro-cli/templates/plugin-compile/package.json.tmpl @@ -31,14 +31,13 @@ "@tarojs/service": "^{{ version }}"{{#if (eq pluginType "plugin-build") }}, "webpack-chain": "^6.5.1"{{/if}}{{#if (eq pluginType "plugin-template") }}, "download": "^8.0.0", - "fs-extra": "^11.1.1", - "path": "^0.12.7", + "fs-extra": "^11.2.0", "unzip": "^0.1.11"{{/if}} }, "devDependencies": { - "@types/node": "^18.13.0" + "@types/node": "^18.15.11" }{{#if (eq pluginType "plugin-template") }}, "resolutions": { - "graceful-fs": "^4.2.10" + "graceful-fs": "^4.2.11" }{{/if}} } diff --git a/packages/taro-cli/templates/plugin-compile/src/index.ts b/packages/taro-cli/templates/plugin-compile/src/index.ts index f40154b2661b..e9d73227fd60 100644 --- a/packages/taro-cli/templates/plugin-compile/src/index.ts +++ b/packages/taro-cli/templates/plugin-compile/src/index.ts @@ -81,7 +81,7 @@ const unzip = require("unzip") interface ITemplateInfo { css: 'none' | 'sass' | 'stylus' | 'less' typescript?: boolean - compiler?: 'webpack4' | 'webpack5' | 'vite' + compiler?: 'webpack5' | 'vite' template?: string } diff --git a/packages/taro-components-advanced/package.json b/packages/taro-components-advanced/package.json index c6ded5e5a81b..06be5c02d79d 100644 --- a/packages/taro-components-advanced/package.json +++ b/packages/taro-components-advanced/package.json @@ -1,7 +1,9 @@ { "name": "@tarojs/components-advanced", - "version": "4.0.0-beta.75", + "version": "4.0.0-alpha.4", "description": "", + "author": "O2Team", + "license": "MIT", "main": "dist/index.js", "types": "dist/index.d.ts", "files": [ @@ -13,41 +15,26 @@ "*.css" ], "scripts": { + "prod": "pnpm run build", "prebuild": "pnpm run clean", "build": "rollup -c", "clean": "rimraf --impl=move-remove ./dist", "dev": "pnpm run build -w" }, "keywords": [], - "author": "ZakaryCode", - "license": "MIT", "dependencies": { "@tarojs/components": "workspace:*", "classnames": "^2.2.5", "csstype": "^3.1.1", "memoize-one": "^6.0.0", - "postcss": "^8.4.18", "tslib": "^2.6.2" }, "devDependencies": { - "@babel/cli": "^7.14.5", - "@babel/core": "^7.14.5", - "@babel/plugin-transform-typescript": "^7.20.2", - "@rollup/plugin-commonjs": "^25.0.7", - "@rollup/plugin-node-resolve": "^15.2.3", "@tarojs/runtime": "workspace:*", "@tarojs/shared": "workspace:*", "@tarojs/taro": "workspace:*", - "@types/node": "^18.19.12", - "babel-preset-taro": "workspace:*", - "postcss": "^8.4.18", "react": "^18.2.0", "react-dom": "^18.2.0", - "rollup": "^2.79.0", - "rollup-plugin-node-externals": "^5.0.0", - "rollup-plugin-postcss": "^4.0.2", - "rollup-plugin-ts": "^3.0.2", - "typescript": "^4.7.4", "vue": "3.2.47" }, "peerDependencies": { diff --git a/packages/taro-components-advanced/rollup.config.js b/packages/taro-components-advanced/rollup.config.mjs similarity index 93% rename from packages/taro-components-advanced/rollup.config.js rename to packages/taro-components-advanced/rollup.config.mjs index a4667b3fbe5a..62611cb37717 100644 --- a/packages/taro-components-advanced/rollup.config.js +++ b/packages/taro-components-advanced/rollup.config.mjs @@ -1,8 +1,8 @@ import commonjs from '@rollup/plugin-commonjs' import resolve from '@rollup/plugin-node-resolve' +import ts from '@rollup/plugin-typescript' import externals from 'rollup-plugin-node-externals' import postcss from 'rollup-plugin-postcss' -import ts from 'rollup-plugin-ts' export default { input: [ @@ -33,9 +33,7 @@ export default { preferBuiltins: false, mainFields: ['browser', 'module', 'jsnext:main', 'main'], }), - ts({ - sourceMap: true, - }), + ts(), commonjs(), postcss({ inject: { insertAt: 'top' }, diff --git a/packages/taro-components-advanced/src/components/virtual-list/vue/list.ts b/packages/taro-components-advanced/src/components/virtual-list/vue/list.ts index a78a87fadc03..47ddd2a28ce2 100644 --- a/packages/taro-components-advanced/src/components/virtual-list/vue/list.ts +++ b/packages/taro-components-advanced/src/components/virtual-list/vue/list.ts @@ -565,9 +565,9 @@ export default defineComponent({ return render(this.preset.outerElement, outerElementProps, [ this.getRenderExpandNodes(isHorizontal ? isRtl ? 'right' : 'left' : 'top'), - process.env.FRAMEWORK === 'vue3' ? this.$slots.top?.() : this.$slots.top, + this.$slots.top?.(), this.getRenderColumnNode(), - process.env.FRAMEWORK === 'vue3' ? this.$slots.bottom?.() : this.$slots.bottom, + this.$slots.bottom?.(), this.getRenderExpandNodes(isHorizontal ? isRtl ? 'left' : 'right' : 'bottom'), ]) } diff --git a/packages/taro-components-advanced/src/components/virtual-waterfall/index.ts b/packages/taro-components-advanced/src/components/virtual-waterfall/index.ts index eac4d9e76eda..2f675df53042 100644 --- a/packages/taro-components-advanced/src/components/virtual-waterfall/index.ts +++ b/packages/taro-components-advanced/src/components/virtual-waterfall/index.ts @@ -242,7 +242,7 @@ declare class VirtualWaterfallComponent extends Component } declare type VirtualWaterfall = VirtualWaterfallComponent -const VirtualWaterfall: typeof VirtualWaterfallComponent = (process.env.FRAMEWORK === 'vue' || process.env.FRAMEWORK === 'vue3') +const VirtualWaterfall: typeof VirtualWaterfallComponent = process.env.FRAMEWORK === 'vue3' ? require('./vue').default : require('./react').default diff --git a/packages/taro-components-advanced/src/components/virtual-waterfall/vue/waterfall.ts b/packages/taro-components-advanced/src/components/virtual-waterfall/vue/waterfall.ts index 5af99e55ee8c..b76df92d9764 100644 --- a/packages/taro-components-advanced/src/components/virtual-waterfall/vue/waterfall.ts +++ b/packages/taro-components-advanced/src/components/virtual-waterfall/vue/waterfall.ts @@ -454,7 +454,7 @@ export default defineComponent({ return render(this.preset.outerElement, outerElementProps, [ this.getRenderExpandNodes('top'), - process.env.FRAMEWORK === 'vue3' ? this.$slots.top?.() : this.$slots.top, + this.$slots.top?.(), render(this.preset.innerElement, { key: `${this.preset.id}-wrapper`, id: `${this.preset.id}-wrapper`, @@ -468,7 +468,7 @@ export default defineComponent({ width: '100%', }, } as any, columnNodes), - process.env.FRAMEWORK === 'vue3' ? this.$slots.bottom?.() : this.$slots.bottom, + this.$slots.bottom?.(), this.getRenderExpandNodes('bottom'), ]) } diff --git a/packages/taro-components-advanced/src/utils/vue-render.ts b/packages/taro-components-advanced/src/utils/vue-render.ts index ce92ada10815..4acdef39869b 100644 --- a/packages/taro-components-advanced/src/utils/vue-render.ts +++ b/packages/taro-components-advanced/src/utils/vue-render.ts @@ -2,13 +2,10 @@ import { h } from 'vue' export default function (componentName: string, options?: Record, children?: any) { const { attrs = {}, on = {}, props = {}, slots = {}, ...el } = options - if (process.env.FRAMEWORK === 'vue3') { - // Events - Object.keys(on).forEach(key => { - const name = `on${key.charAt(0).toUpperCase()}${key.slice(1)}` - el[name] = on[key] - }) - return h(componentName, { ...attrs, ...props, ...slots, ...el }, children) - } - return h(componentName, options, children) + // Events + Object.keys(on).forEach(key => { + const name = `on${key.charAt(0).toUpperCase()}${key.slice(1)}` + el[name] = on[key] + }) + return h(componentName, { ...attrs, ...props, ...slots, ...el }, children) } diff --git a/packages/taro-components-advanced/tsconfig.json b/packages/taro-components-advanced/tsconfig.json index 13aba29d3b04..18da2774618e 100644 --- a/packages/taro-components-advanced/tsconfig.json +++ b/packages/taro-components-advanced/tsconfig.json @@ -6,9 +6,9 @@ "emitDeclarationOnly": true, "module": "ESNext", "outDir": "dist", + "declarationDir": "dist", "skipLibCheck": true, "skipDefaultLibCheck": true, - "sourceMap": false, "strictNullChecks": false, "target": "ES2017", "typeRoots": ["./node_modules/@types"] diff --git a/packages/taro-components-library-react/package.json b/packages/taro-components-library-react/package.json index be3a3556ed58..0707919c11b5 100644 --- a/packages/taro-components-library-react/package.json +++ b/packages/taro-components-library-react/package.json @@ -1,37 +1,31 @@ { "name": "@tarojs/components-library-react", - "version": "4.0.0-beta.75", + "version": "4.0.0-alpha.4", "description": "Taro 组件库 React 版本库", "private": true, + "author": "O2Team", + "license": "MIT", "main": "index.js", "scripts": { - "build:ci": "run-s clean prod", + "prebuild": "pnpm run clean && node ./scripts/fix.js", + "build": "rollup -c", "clean": "rimraf --impl=move-remove ../taro-components/lib/react", - "dev": "pnpm run prod -w", - "preprod": "node ./scripts/fix.js", - "prod": "rollup -c" + "dev": "pnpm run build -w", + "prod": "pnpm run build" }, "keywords": [], - "author": "ZakaryCode", - "license": "MIT", + "engines": { + "node": ">= 18" + }, "dependencies": { - "@tarojs/components": "workspace:*", - "react-dom": "^18.2.0", - "tslib": "^2.6.2" + "@tarojs/components": "workspace:*" }, "devDependencies": { - "@babel/cli": "^7.14.5", - "@babel/core": "^7.14.5", - "@rollup/plugin-commonjs": "^25.0.7", - "@rollup/plugin-node-resolve": "^15.2.3", - "babel-preset-taro": "workspace:*", - "postcss": "^8.4.18", + "@tarojs/helper": "workspace:*", "react": "^18.2.0", - "react-dom": "^18.2.0", - "rollup": "^2.79.0", - "rollup-plugin-node-externals": "^5.0.0", - "rollup-plugin-postcss": "^4.0.2", - "rollup-plugin-ts": "^3.0.2", - "typescript": "^4.7.4" + "react-dom": "^18.2.0" + }, + "peerDependencies": { + "@tarojs/helper": "workspace:*" } } diff --git a/packages/taro-components-library-react/rollup.config.js b/packages/taro-components-library-react/rollup.config.mjs similarity index 92% rename from packages/taro-components-library-react/rollup.config.js rename to packages/taro-components-library-react/rollup.config.mjs index 911e62d2d6ff..cfd0b8d083b4 100644 --- a/packages/taro-components-library-react/rollup.config.js +++ b/packages/taro-components-library-react/rollup.config.mjs @@ -1,8 +1,8 @@ import commonjs from '@rollup/plugin-commonjs' import resolve from '@rollup/plugin-node-resolve' +import typescript from '@rollup/plugin-typescript' import externals from 'rollup-plugin-node-externals' import postcss from 'rollup-plugin-postcss' -import ts from 'rollup-plugin-ts' const config = { input: ['src/index.ts', 'src/component-lib/index.ts'], @@ -24,9 +24,7 @@ const config = { preferBuiltins: false, mainFields: ['browser', 'module', 'jsnext:main', 'main'], }), - ts({ - sourceMap: true, - }), + typescript(), commonjs({ transformMixedEsModules: true, dynamicRequireTargets: ['./src/**/*.js'], diff --git a/packages/taro-components-library-react/tsconfig.json b/packages/taro-components-library-react/tsconfig.json index 221161c30e50..18a6c4934d30 100644 --- a/packages/taro-components-library-react/tsconfig.json +++ b/packages/taro-components-library-react/tsconfig.json @@ -3,13 +3,13 @@ "compilerOptions": { "baseUrl": ".", "declaration": true, + "declarationDir": "../taro-components/lib/react", "jsx": "react", "jsxFactory": "React.createElement", "module": "ESNext", "noUnusedLocals": false, "skipLibCheck": true, "skipDefaultLibCheck": true, - "sourceMap": false, "strictNullChecks": false, "target": "ES2017", "typeRoots": ["./node_modules/@types"] diff --git a/packages/taro-components-library-vue2/.babelrc.json b/packages/taro-components-library-vue2/.babelrc.json deleted file mode 100644 index 590c81860efe..000000000000 --- a/packages/taro-components-library-vue2/.babelrc.json +++ /dev/null @@ -1,14 +0,0 @@ -{ - "presets": [ - [ - "taro", - { - "absoluteRuntime": false, - "framework": "vue", - "hot": false, - "modules": false, - "ts": true - } - ] - ] -} diff --git a/packages/taro-components-library-vue2/.gitignore b/packages/taro-components-library-vue2/.gitignore deleted file mode 100644 index 5580458adc44..000000000000 --- a/packages/taro-components-library-vue2/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -# Stencil autogenerated -src/components.ts diff --git a/packages/taro-components-library-vue2/package.json b/packages/taro-components-library-vue2/package.json deleted file mode 100644 index 967737f45a2c..000000000000 --- a/packages/taro-components-library-vue2/package.json +++ /dev/null @@ -1,36 +0,0 @@ -{ - "name": "@tarojs/components-library-vue2", - "version": "4.0.0-beta.75", - "description": "Taro 组件库 Vue2 版本库", - "private": true, - "main": "index.js", - "scripts": { - "build:ci": "run-s clean prod", - "clean": "rimraf --impl=move-remove ../taro-components/lib/vue2", - "dev": "pnpm run prod -w", - "preprod": "node ./scripts/fix.js", - "prod": "rollup -c" - }, - "keywords": [], - "author": "ZakaryCode", - "license": "MIT", - "dependencies": { - "@tarojs/components": "workspace:*", - "tslib": "^2.6.2", - "vue-fragment": "^1.6.0" - }, - "devDependencies": { - "@babel/cli": "^7.14.5", - "@babel/core": "^7.14.5", - "@rollup/plugin-commonjs": "^25.0.7", - "@rollup/plugin-node-resolve": "^15.2.3", - "babel-preset-taro": "workspace:*", - "postcss": "^8.4.18", - "rollup": "^2.79.0", - "rollup-plugin-node-externals": "^5.0.0", - "rollup-plugin-postcss": "^4.0.2", - "rollup-plugin-ts": "^3.0.2", - "typescript": "^4.7.4", - "vue": "^2.6.11" - } -} diff --git a/packages/taro-components-library-vue2/rollup.config.js b/packages/taro-components-library-vue2/rollup.config.js deleted file mode 100644 index a1a518090569..000000000000 --- a/packages/taro-components-library-vue2/rollup.config.js +++ /dev/null @@ -1,42 +0,0 @@ -import commonjs from '@rollup/plugin-commonjs' -import resolve from '@rollup/plugin-node-resolve' -import externals from 'rollup-plugin-node-externals' -import postcss from 'rollup-plugin-postcss' -import ts from 'rollup-plugin-ts' - -const config = { - input: ['src/index.ts', 'src/components-loader.ts', 'src/component-lib/index.ts'], - output: { - dir: '../taro-components/lib/vue2', - exports: 'named', - preserveModules: true, - preserveModulesRoot: 'src', - sourcemap: true, - }, - treeshake: false, - plugins: [ - externals({ - deps: true, - devDeps: false, - exclude: 'vue-fragment', - include: 'vue', - }), - resolve({ - preferBuiltins: false, - mainFields: ['browser', 'module', 'jsnext:main', 'main'], - }), - ts({ - sourceMap: true, - }), - commonjs({ - transformMixedEsModules: true, - dynamicRequireTargets: ['./src/**/*.js'], - }), - postcss({ - inject: { insertAt: 'top' }, - minimize: true, - }), - ], -} - -export default config diff --git a/packages/taro-components-library-vue2/scripts/fix.js b/packages/taro-components-library-vue2/scripts/fix.js deleted file mode 100644 index d358892495dc..000000000000 --- a/packages/taro-components-library-vue2/scripts/fix.js +++ /dev/null @@ -1,21 +0,0 @@ -const fs = require('@tarojs/helper').fs -const path = require('path') - -const componentsPath = path.resolve(__dirname, '..', 'src/components.ts') - -if (fs.existsSync(componentsPath)) { - const codeBuffer = fs.readFileSync(componentsPath) - let code = codeBuffer.toString().replace(/import\stype\s\{\s([^}]*)\s\}\sfrom\s'@tarojs\/components[^']*';/ig, `import type { $1 } from '@tarojs/components/dist/types/components';`) - code = code.replace(/const\sTaro([A-Za-z]+)\s=/g, 'const $1 =').replace(/const\s([A-Za-z]+)Core\s=/g, 'const $1 =') - - if (code.includes('defineCustomElement as define')) { - code = code.replace(/import\s\{\sdefineCustomElement\sas\sdefine([A-Za-z]+)\s.*/g, '// @ts-ignore\nimport { defineCustomElement$1 as define$1 } from \'@tarojs/components/dist/components\';') - } - - if (!code.includes('fragment')) { - const comps = ['block'] - code = code.replace(new RegExp(`'taro-(${comps.join('|')})-core'`, 'ig'), `'fragment'`) - } - - fs.writeFileSync(componentsPath, code) -} diff --git a/packages/taro-components-library-vue2/src/component-lib/components.ts b/packages/taro-components-library-vue2/src/component-lib/components.ts deleted file mode 100644 index 0d8eded4b76a..000000000000 --- a/packages/taro-components-library-vue2/src/component-lib/components.ts +++ /dev/null @@ -1,83 +0,0 @@ -import Icon from './icon' -import Image from './image' -import Picker from './picker' -import ScrollView from './scroll-view' -import Text from './text' - -const components = [ - // 视图容器 - 'taro-cover-image', - 'taro-cover-view', - 'taro-match-media', - 'taro-movable-area', - 'taro-movable-view', - 'taro-page-container', - 'taro-root-portal', - ['taro-scroll-view', { type: 'component', component: ScrollView }], - 'taro-share-element', - 'taro-swiper', - ['taro-swiper-item', { classNames: ['swiper-slide'] }], - 'taro-view', - - // 基础内容 - ['taro-icon', { type: 'component', component: Icon }], - ['taro-progress', { classNames: ['weui-progress'] }], - 'taro-rich-text', - ['taro-text', { type: 'component', component: Text }], - - // 表单组件 - 'taro-button', - ['taro-checkbox', { classNames: ['weui-cells_checkbox'] }], - 'taro-checkbox-group', - 'taro-editor', - 'taro-form', - ['taro-input', { type: 'forms', event: 'input' }], - 'taro-keyboard-accessory', - 'taro-label', - ['taro-picker', { type: 'component', component: Picker }], - 'taro-picker-view', - 'taro-picker-view-column', - ['taro-radio', { classNames: ['weui-cells_checkbox'] }], - ['taro-radio-group', { classNames: ['weui-cells_radiogroup'] }], - ['taro-slider', { type: 'forms', event: 'change', modelValue: 'value', classNames: ['weui-slider-box'] }], - ['taro-switch', { type: 'forms', event: 'change', modelValue: 'checked' }], - ['taro-textarea', { type: 'forms', event: 'input' }], - - // 导航 - 'taro-functional-page-navigator', - 'taro-navigator', - - // 媒体组件 - 'taro-audio', - 'taro-camera', - ['taro-image', { type: 'component', component: Image }], - 'taro-live-player', - ['taro-video', { classNames: ['taro-video-container'] }], - 'taro-voip-room', - - // 地图 - 'taro-map', - - // 画布 - 'taro-canvas', - - // 开放能力 - 'taro-web-view', - 'taro-ad', - 'taro-ad-custom', - 'taro-official-account', - 'taro-open-data', - - // 导航栏 - 'taro-navigation-bar', - - // 页面属性配置节点 - 'taro-page-meta', - - // 其他 - 'taro-block', - 'taro-custom-wrapper', - 'taro-slot' -] - -export default components diff --git a/packages/taro-components-library-vue2/src/component-lib/createComponent.ts b/packages/taro-components-library-vue2/src/component-lib/createComponent.ts deleted file mode 100644 index 9d12e120b9fe..000000000000 --- a/packages/taro-components-library-vue2/src/component-lib/createComponent.ts +++ /dev/null @@ -1,20 +0,0 @@ -import { listeners } from './mixins/listeners' -import { refs } from './mixins/refs' - -export default function createComponent (name, classNames = []) { - return { - name, - mixins: [listeners, refs], - props: ['nativeProps'], - render (createElement) { - return createElement(`${name}-core`, { - class: ['hydrated', ...classNames], - domProps: { - nativeProps: this.nativeProps - }, - attrs: this.$attrs, - on: this.listeners - }, this.$slots.default) - } - } -} diff --git a/packages/taro-components-library-vue2/src/component-lib/createFormsComponent.ts b/packages/taro-components-library-vue2/src/component-lib/createFormsComponent.ts deleted file mode 100644 index 8beaf1e101ea..000000000000 --- a/packages/taro-components-library-vue2/src/component-lib/createFormsComponent.ts +++ /dev/null @@ -1,54 +0,0 @@ -import { listeners } from './mixins/listeners' -import { refs } from './mixins/refs' - -export default function createFormsComponent (name, event, modelValue = 'value', classNames = []) { - const props: Record = { - nativeProps: { - type: Object - } - } - if (name === 'taro-input') { - props.focus = Boolean - } - - return { - name, - mixins: [listeners, refs], - model: { - prop: modelValue, - event: 'model' - }, - props, - methods: { - input (e) { - this.$emit('input', e) - this.$emit('model', e.target.value) - }, - change (e) { - this.$emit('change', e) - this.$emit('model', e.target.value) - } - }, - render (createElement) { - // eslint-disable-next-line - const self = this; - - const attrs = this.$attrs || {} - if (name === 'taro-input') { - attrs['auto-focus'] = self.focus - } - - const on = { ...self.listeners } - on[event] = self[event] - - return createElement(`${name}-core`, { - class: ['hydrated', ...classNames], - domProps: { - nativeProps: this.nativeProps - }, - attrs, - on - }, self.$slots.default) - } - } -} diff --git a/packages/taro-components-library-vue2/src/component-lib/icon.ts b/packages/taro-components-library-vue2/src/component-lib/icon.ts deleted file mode 100644 index e1e22c2fbdf3..000000000000 --- a/packages/taro-components-library-vue2/src/component-lib/icon.ts +++ /dev/null @@ -1,20 +0,0 @@ -import { listeners } from './mixins/listeners' -import { refs } from './mixins/refs' - -export default { - name: 'taro-icon', - mixins: [listeners, refs], - props: { - type: String - }, - render (createElement) { - const iconType = this.type.replace(/_/g, '-') - return createElement('taro-icon-core', { - class: ['hydrated', `weui-icon-${iconType}`], - attrs: { - type: this.type - }, - on: this.listeners - }, this.$slots.default) - } -} diff --git a/packages/taro-components-library-vue2/src/component-lib/image.ts b/packages/taro-components-library-vue2/src/component-lib/image.ts deleted file mode 100644 index 04da8aa52d5e..000000000000 --- a/packages/taro-components-library-vue2/src/component-lib/image.ts +++ /dev/null @@ -1,21 +0,0 @@ -import { listeners } from './mixins/listeners' -import { refs } from './mixins/refs' - -export default { - name: 'taro-image', - mixins: [listeners, refs], - props: { - mode: String - }, - render (createElement) { - return createElement('taro-image-core', { - class: ['hydrated', { - 'taro-img__widthfix': this.mode === 'widthFix' - }], - attrs: { - mode: this.mode - }, - on: this.listeners - }, this.$slots.default) - } -} diff --git a/packages/taro-components-library-vue2/src/component-lib/index.ts b/packages/taro-components-library-vue2/src/component-lib/index.ts deleted file mode 100644 index 073c21d6b979..000000000000 --- a/packages/taro-components-library-vue2/src/component-lib/index.ts +++ /dev/null @@ -1,23 +0,0 @@ -import Vue from 'vue' - -import components from './components' -import createComponent from './createComponent' -import createFormsComponent from './createFormsComponent' - -components.forEach(params => { - if (typeof params === 'string') { - Vue.component(params, createComponent(params)) - } else if (params instanceof Array) { - const [name, props] = params as [string, Record] - const { classNames, type = 'simple' } = props - - if (type === 'simple') { - Vue.component(name, createComponent(name, classNames)) - } else if (type === 'forms') { - const { event, modelValue } = props - Vue.component(name, createFormsComponent(name, event, modelValue, classNames)) - } else if (type === 'component') { - Vue.component(name, props.component) - } - } -}) diff --git a/packages/taro-components-library-vue2/src/component-lib/mixins/listeners.ts b/packages/taro-components-library-vue2/src/component-lib/mixins/listeners.ts deleted file mode 100644 index a77941c87d59..000000000000 --- a/packages/taro-components-library-vue2/src/component-lib/mixins/listeners.ts +++ /dev/null @@ -1,14 +0,0 @@ -export const listeners = { - computed: { - listeners () { - // eslint-disable-next-line - const vm = this - return { - ...vm.$listeners, - click (e) { - vm.$emit('tap', e) - } - } - } - } -} diff --git a/packages/taro-components-library-vue2/src/component-lib/mixins/refs.ts b/packages/taro-components-library-vue2/src/component-lib/mixins/refs.ts deleted file mode 100644 index 51068e052f04..000000000000 --- a/packages/taro-components-library-vue2/src/component-lib/mixins/refs.ts +++ /dev/null @@ -1,53 +0,0 @@ -export const refs = { - mounted () { - if ( - this.$parent && - typeof this.$parent.$refs === 'object' && - Object.keys(this.$parent.$refs).length - ) { - const refs = this.$parent.$refs - - if (this._refCacheKey) { - refs[this._refCacheKey] = this.$el - } else { - for (const key in refs) { - const ref = refs[key] - if (ref === this) { - this._refCacheKey = key - refs[key] = this.$el - break - } else if (Array.isArray(ref)) { - const index = ref.indexOf(this) - if (index > -1) { - ref[index] = this.$el - break - } - } - } - } - } - }, - beforeDestroy () { - if ( - this.$parent && - typeof this.$parent.$refs === 'object' && - Object.keys(this.$parent.$refs).length - ) { - const refs = this.$parent.$refs - - if (this._refCacheKey) { - refs[this._refCacheKey] = this - } else { - for (const key in refs) { - if (Array.isArray(refs[key])) { - const index = refs[key].indexOf(this.$el) - if (index > -1) { - refs[key][index] = this - break - } - } - } - } - } - } -} diff --git a/packages/taro-components-library-vue2/src/component-lib/picker.ts b/packages/taro-components-library-vue2/src/component-lib/picker.ts deleted file mode 100644 index 962a42d6e71e..000000000000 --- a/packages/taro-components-library-vue2/src/component-lib/picker.ts +++ /dev/null @@ -1,42 +0,0 @@ -import { listeners } from './mixins/listeners' -import { refs } from './mixins/refs' - -export default { - name: 'taro-picker', - mixins: [listeners, refs], - model: { - event: 'model' - }, - props: { - range: Array, - rangeKey: String, - value: [Number, String, Array] - }, - mounted () { - this.$el.value = this.value - }, - watch: { - value (newVal) { - this.$el.value = newVal - } - }, - render (createElement) { - // eslint-disable-next-line @typescript-eslint/no-this-alias - const self = this - - return createElement('taro-picker-core', { - class: 'hydrated', - domProps: { - range: self.range, - rangeKey: self.rangeKey - }, - on: { - ...self.listeners, - change (e) { - self.$emit('change', e) - self.$emit('model', e.target.value) - } - } - }, self.$slots.default) - } -} diff --git a/packages/taro-components-library-vue2/src/component-lib/scroll-view.ts b/packages/taro-components-library-vue2/src/component-lib/scroll-view.ts deleted file mode 100644 index 62333457990e..000000000000 --- a/packages/taro-components-library-vue2/src/component-lib/scroll-view.ts +++ /dev/null @@ -1,35 +0,0 @@ -import { listeners } from './mixins/listeners' -import { refs } from './mixins/refs' - -export default { - name: 'taro-scroll-view', - mixins: [listeners, refs], - props: { - scrollX: Boolean, - scrollY: Boolean - }, - render (createElement) { - // eslint-disable-next-line @typescript-eslint/no-this-alias - const self = this - - const attrs = {} - if (self.scrollX) attrs['scroll-x'] = true - if (self.scrollY) attrs['scroll-y'] = true - - return createElement('taro-scroll-view-core', { - class: ['hydrated', { - 'taro-scroll-view__scroll-x': self.scrollX, - 'taro-scroll-view__scroll-y': self.scrollY - }], - attrs, - on: { - ...self.listeners, - scroll (e) { - if (e instanceof CustomEvent) { - self.$emit('scroll', e) - } - } - } - }, self.$slots.default) - } -} diff --git a/packages/taro-components-library-vue2/src/component-lib/text.ts b/packages/taro-components-library-vue2/src/component-lib/text.ts deleted file mode 100644 index 35312b5d9c9b..000000000000 --- a/packages/taro-components-library-vue2/src/component-lib/text.ts +++ /dev/null @@ -1,21 +0,0 @@ -import { listeners } from './mixins/listeners' -import { refs } from './mixins/refs' - -export default { - name: 'taro-text', - mixins: [listeners, refs], - props: { - selectable: Boolean - }, - render (createElement) { - return createElement('taro-text-core', { - class: ['hydrated', { - 'taro-text__selectable': this.selectable - }], - attrs: { - selectable: this.selectable - }, - on: this.listeners - }, this.$slots.default) - } -} diff --git a/packages/taro-components-library-vue2/src/components-loader.ts b/packages/taro-components-library-vue2/src/components-loader.ts deleted file mode 100644 index fd23acdc93fe..000000000000 --- a/packages/taro-components-library-vue2/src/components-loader.ts +++ /dev/null @@ -1,18 +0,0 @@ -import Vue from 'vue' -import Fragment from 'vue-fragment' - -export function initVue2Components (components: Record = {}) { - const ignoredElements = [/^taro-/, 'root', 'block'] - if (!Vue.config.ignoredElements?.includes(ignoredElements[0])) { - Vue.config.ignoredElements = [...Vue.config.ignoredElements, ...ignoredElements] - } - - Vue.use(Fragment.Plugin) - Object.entries(components).forEach(([name, definition]) => { - if (typeof definition === 'function') { - const tagName = 'taro' + name.replace(new RegExp('([A-Z])', 'g'), '-$1').toLowerCase() - const comp = Vue.extend(definition) - Vue.component(tagName, comp) - } - }) -} diff --git a/packages/taro-components-library-vue2/src/index.ts b/packages/taro-components-library-vue2/src/index.ts deleted file mode 100644 index cb64ac1b52aa..000000000000 --- a/packages/taro-components-library-vue2/src/index.ts +++ /dev/null @@ -1 +0,0 @@ -export * from './components' diff --git a/packages/taro-components-library-vue2/src/vue-component-lib/utils.ts b/packages/taro-components-library-vue2/src/vue-component-lib/utils.ts deleted file mode 100644 index fb7a54f61326..000000000000 --- a/packages/taro-components-library-vue2/src/vue-component-lib/utils.ts +++ /dev/null @@ -1,76 +0,0 @@ -/** - * Modify from https://github.com/diondree/stencil-vue2-output-target/blob/master/vue-component-lib/utils.ts - * MIT License https://github.com/diondree/stencil-vue2-output-target/blob/master/LICENSE.md - */ -import Vue, { CreateElement, VNode } from 'vue' - -export const createCommonMethod = (methodName: string) => - function (...args: any[]) { - this.$refs.wc[methodName](...args) - } as unknown - -export const toLowerCase = (str: string) => str.toLowerCase() - -export const toDashCase = (str: string) => - toLowerCase( - str - .replace(/([A-Z0-9])/g, (g) => ' ' + g[0]) - .trim() - .replace(/ /g, '-') - ) - -export const createCommonRender = ( - tagName: string, - eventNames: string[] = [], - defineCustomElement: any, -) => { - /** - * Create a Vue component wrapper around a Web Component. - * Note: The `props` here are not all properties on a component. - * They refer to whatever properties are set on an instance of a component. - */ - - if (!DEPRECATED_ADAPTER_COMPONENT && defineCustomElement !== undefined) { - defineCustomElement() - } - - return function (createElement: CreateElement): VNode { - const vueElement = this as Vue - const allListeners = eventNames.reduce((listeners, eventName) => { - return { - ...listeners, - [eventName]: (event: CustomEvent) => { - vueElement.$emit(eventName, event) - // Note(taro): 优化 input、change 事件与 v-model 兼容性问题 - if (['input', 'change'].includes(eventName)) { - vueElement.$emit('update:modelValue', event.detail.value) - } - }, - } - }, vueElement.$listeners) - const attributes = vueElement.$props - ? Object.keys(vueElement.$props).reduce((attrs: any, prop: string) => { - const attributeName = toDashCase(prop) - attrs[attributeName] = vueElement.$props[prop] - return attrs - }, {}) - : {} - return createElement( - tagName, - { - ref: 'wc', - domProps: vueElement.$props, - on: { - ...allListeners, - // Note(taro): click 事件绑定 tap 事件触发 - click: (event) => { - typeof allListeners.click === 'function' && allListeners.click(event) - vueElement.$emit('tap', event) - } - }, - attrs: { ...attributes, 'data-testid': tagName }, - }, - [vueElement.$slots.default] - ) - } -} diff --git a/packages/taro-components-library-vue2/tsconfig.json b/packages/taro-components-library-vue2/tsconfig.json deleted file mode 100644 index 7d7cba0328f7..000000000000 --- a/packages/taro-components-library-vue2/tsconfig.json +++ /dev/null @@ -1,16 +0,0 @@ -{ - "extends": "../../tsconfig.root.json", - "compilerOptions": { - "baseUrl": ".", - "declaration": true, - "module": "ESNext", - "noUnusedLocals": false, - "skipLibCheck": true, - "skipDefaultLibCheck": true, - "sourceMap": false, - "strictNullChecks": false, - "target": "ES2017", - "typeRoots": ["./node_modules/@types"] - }, - "include": ["./src", "./types"] -} diff --git a/packages/taro-components-library-vue2/types/define.d.ts b/packages/taro-components-library-vue2/types/define.d.ts deleted file mode 100644 index 59b4eac98a9e..000000000000 --- a/packages/taro-components-library-vue2/types/define.d.ts +++ /dev/null @@ -1,2 +0,0 @@ -// NOTE: 启用旧版本适配器 -declare const DEPRECATED_ADAPTER_COMPONENT: boolean | undefined diff --git a/packages/taro-components-library-vue3/package.json b/packages/taro-components-library-vue3/package.json index 9b54df865d45..1d6db54b3e08 100644 --- a/packages/taro-components-library-vue3/package.json +++ b/packages/taro-components-library-vue3/package.json @@ -1,35 +1,30 @@ { "name": "@tarojs/components-library-vue3", - "version": "4.0.0-beta.75", + "version": "4.0.0-alpha.4", "description": "Taro 组件库 Vue3 版本库", "private": true, + "author": "O2Team", + "license": "MIT", "main": "index.js", "scripts": { - "build:ci": "run-s clean prod", + "prod": "pnpm run build", + "prebuild": "pnpm run clean && node ./scripts/fix.js", + "build": "rollup -c", "clean": "rimraf --impl=move-remove ../taro-components/lib/vue3", - "dev": "pnpm run prod -w", - "preprod": "node ./scripts/fix.js", - "prod": "rollup -c" + "dev": "pnpm run build -w" }, "keywords": [], - "author": "ZakaryCode", - "license": "MIT", + "engines": { + "node": ">= 18" + }, "dependencies": { - "@tarojs/components": "workspace:*", - "tslib": "^2.6.2" + "@tarojs/components": "workspace:*" }, "devDependencies": { - "@babel/cli": "^7.14.5", - "@babel/core": "^7.14.5", - "@rollup/plugin-commonjs": "^25.0.7", - "@rollup/plugin-node-resolve": "^15.2.3", - "babel-preset-taro": "workspace:*", - "postcss": "^8.4.18", - "rollup": "^2.79.0", - "rollup-plugin-node-externals": "^5.0.0", - "rollup-plugin-postcss": "^4.0.2", - "rollup-plugin-ts": "^3.0.2", - "typescript": "^4.7.4", + "@tarojs/helper": "workspace:*", "vue": "3.2.47" + }, + "peerDependencies": { + "@tarojs/helper": "workspace:*" } } diff --git a/packages/taro-components-library-vue3/rollup.config.js b/packages/taro-components-library-vue3/rollup.config.mjs similarity index 92% rename from packages/taro-components-library-vue3/rollup.config.js rename to packages/taro-components-library-vue3/rollup.config.mjs index 6095d43de3af..cca0d96295f1 100644 --- a/packages/taro-components-library-vue3/rollup.config.js +++ b/packages/taro-components-library-vue3/rollup.config.mjs @@ -1,8 +1,8 @@ import commonjs from '@rollup/plugin-commonjs' import resolve from '@rollup/plugin-node-resolve' +import typescript from '@rollup/plugin-typescript' import externals from 'rollup-plugin-node-externals' import postcss from 'rollup-plugin-postcss' -import ts from 'rollup-plugin-ts' const config = { input: ['src/index.ts', 'src/components-loader.ts', 'src/component-lib/index.ts'], @@ -10,8 +10,8 @@ const config = { dir: '../taro-components/lib/vue3', exports: 'named', preserveModules: true, - preserveModulesRoot: 'src', sourcemap: true, + preserveModulesRoot: 'src', }, treeshake: false, plugins: [ @@ -24,9 +24,7 @@ const config = { preferBuiltins: false, mainFields: ['browser', 'module', 'jsnext:main', 'main'], }), - ts({ - sourceMap: true, - }), + typescript(), commonjs({ transformMixedEsModules: true, dynamicRequireTargets: ['./src/**/*.js'], diff --git a/packages/taro-components-library-vue3/tsconfig.json b/packages/taro-components-library-vue3/tsconfig.json index 7d7cba0328f7..4b2c6fdbda75 100644 --- a/packages/taro-components-library-vue3/tsconfig.json +++ b/packages/taro-components-library-vue3/tsconfig.json @@ -3,11 +3,11 @@ "compilerOptions": { "baseUrl": ".", "declaration": true, + "declarationDir": "../taro-components/lib/vue3", "module": "ESNext", "noUnusedLocals": false, "skipLibCheck": true, "skipDefaultLibCheck": true, - "sourceMap": false, "strictNullChecks": false, "target": "ES2017", "typeRoots": ["./node_modules/@types"] diff --git a/packages/taro-components-react/package.json b/packages/taro-components-react/package.json index 15866aa559ba..54b2f03c25dc 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.0-beta.75", + "version": "4.0.0-alpha.4", "description": "", "main:h5": "dist/index.js", "main": "dist/index.js", @@ -17,11 +17,12 @@ "types" ], "scripts": { + "prod": "pnpm run build", "prebuild": "pnpm run clean", "build": "pnpm run rollup --environment NODE_ENV:production", "clean": "rimraf ./dist", "dev": "pnpm run rollup --environment NODE_ENV:development -w", - "rollup": "rollup --config rollup.config.ts --configPlugin @rollup/plugin-typescript --bundleConfigAsCjs" + "rollup": "rollup -c" }, "repository": { "type": "git", @@ -31,31 +32,21 @@ "author": "", "license": "MIT", "dependencies": { - "@babel/runtime": "^7.14.5", "@tarojs/taro": "workspace:*", + "@tarojs/shared": "workspace:*", "@tarojs/components": "workspace:*", + "@babel/runtime": "^7.24.4", "classnames": "^2.2.5", "swiper": "6.8.0", "tslib": "^2.6.2" }, "devDependencies": { - "@babel/core": "^7.14.5", - "@babel/preset-react": "^7.22.15", - "@rollup/plugin-babel": "^6.0.4", - "@rollup/plugin-commonjs": "^25.0.7", - "@rollup/plugin-node-resolve": "^15.2.3", - "@rollup/plugin-replace": "^4.0.0", - "@rollup/plugin-typescript": "^11.1.0", - "@types/node": "^18.19.12", + "@tarojs/helper": "workspace:*", + "@tarojs/runtime": "workspace:*", + "@babel/preset-react": "^7.24.1", "babel-preset-solid": "^1.8.15", - "postcss": "^8.4.18", "react": "^18.2.0", - "rollup": "^3.8.1", - "rollup-plugin-node-externals": "^5.0.0", - "rollup-plugin-postcss": "^4.0.2", - "rollup-plugin-ts": "^3.0.2", - "solid-js": "^1.8.16", - "typescript": "^4.7.4" + "solid-js": "^1.8.16" }, "peerDependencies": { "react": "*", diff --git a/packages/taro-components-react/rollup.config.ts b/packages/taro-components-react/rollup.config.mjs similarity index 73% rename from packages/taro-components-react/rollup.config.ts rename to packages/taro-components-react/rollup.config.mjs index 33bfcee2e556..9c7b21411a05 100644 --- a/packages/taro-components-react/rollup.config.ts +++ b/packages/taro-components-react/rollup.config.mjs @@ -1,40 +1,34 @@ -import babel, { type RollupBabelInputPluginOptions } from '@rollup/plugin-babel' +import babel from '@rollup/plugin-babel' import commonjs from '@rollup/plugin-commonjs' import { nodeResolve } from '@rollup/plugin-node-resolve' import replace from '@rollup/plugin-replace' +import ts from '@rollup/plugin-typescript' import { recursiveMerge } from '@tarojs/helper' import { defineConfig } from 'rollup' import externals from 'rollup-plugin-node-externals' import postcss from 'rollup-plugin-postcss' -import ts from 'rollup-plugin-ts' -import type { InputPluginOption, RollupOptions } from 'rollup' -const base: RollupOptions & { plugins: InputPluginOption[] } = { +const base = { input: 'src/index.ts', plugins: [ externals({ deps: true, devDeps: false, - }) as InputPluginOption, + }), nodeResolve({ preferBuiltins: false, mainFields: ['main:h5', 'browser', 'module', 'jsnext:main', 'main'] - }) as InputPluginOption, + }), postcss({ extract: true, inject: { insertAt: 'top' }, minimize: true, - }) as InputPluginOption, - ts({ - tsconfig: e => ({ - ...e, - sourceMap: true, - }) - }) as InputPluginOption, + }), + ts(), commonjs({ include: '../../node_modules/**' - }) as InputPluginOption, + }), ], treeshake: false, output: { @@ -48,13 +42,13 @@ const base: RollupOptions & { plugins: InputPluginOption[] } = { } } -const babelConfig: RollupBabelInputPluginOptions = { +const babelConfig = { extensions: ['.js', '.jsx', '.es6', '.es', '.mjs', 'ts', 'tsx'], babelHelpers: 'runtime', } const react = () => { - const config: typeof base = recursiveMerge({}, base) + const config = recursiveMerge({}, base) config.plugins.push( babel({ ...babelConfig, @@ -75,7 +69,7 @@ const react = () => { } const solid = () => { - const config: typeof base = recursiveMerge({}, base, { + const config = recursiveMerge({}, base, { output: { dir: 'dist/solid', }, diff --git a/packages/taro-components-react/tsconfig.json b/packages/taro-components-react/tsconfig.json index 314ee8e8489e..cc12c72ae44f 100644 --- a/packages/taro-components-react/tsconfig.json +++ b/packages/taro-components-react/tsconfig.json @@ -4,8 +4,7 @@ "baseUrl": ".", "jsx": "preserve", "module": "ESNext", - "sourceMap": false, "typeRoots": ["./node_modules/@types"] }, - "include": ["./src", "./types", "./rollup.config.ts"] + "include": ["./src", "./types"] } diff --git a/packages/taro-components-rn/.editorconfig b/packages/taro-components-rn/.editorconfig deleted file mode 100644 index cc1b5ccb8aa1..000000000000 --- a/packages/taro-components-rn/.editorconfig +++ /dev/null @@ -1,13 +0,0 @@ -root = true - -[*] -charset = utf-8 -indent_style = space -indent_size = 2 -end_of_line = lf -insert_final_newline = true -trim_trailing_whitespace = true - -[*.md] -max_line_length = 0 -trim_trailing_whitespace = false diff --git a/packages/taro-components-rn/.eslintrc.js b/packages/taro-components-rn/.eslintrc.js index 75abaf1b817b..d06718c8b021 100644 --- a/packages/taro-components-rn/.eslintrc.js +++ b/packages/taro-components-rn/.eslintrc.js @@ -1,32 +1,10 @@ +const config = require('../../.eslintrc.js') + module.exports = { - root: true, - extends: [ - 'standard', - 'plugin:react/recommended', - 'plugin:jest/recommended', - 'plugin:@typescript-eslint/recommended' - ], - parser: '@typescript-eslint/parser', - plugins: ['@typescript-eslint'], - env: { - node: true, - jest: true, - }, - settings: { - react: { - version: 'detect' - } - }, + ...config, rules: { - 'comma-dangle': [2, 'only-multiline'], - '@typescript-eslint/explicit-function-return-type': 0, - '@typescript-eslint/ban-ts-comment': 0, - 'space-before-function-paren': 0, + ...config.rules, + 'no-empty': 0, 'react/display-name': 0, - '@typescript-eslint/no-explicit-any': 0, - '@typescript-eslint/no-non-null-assertion': 0, - '@typescript-eslint/no-use-before-define': 2, - 'no-use-before-define': 0, - 'no-unused-expressions': 0 } } diff --git a/packages/taro-components-rn/.gitignore b/packages/taro-components-rn/.gitignore deleted file mode 100644 index 1871062b8774..000000000000 --- a/packages/taro-components-rn/.gitignore +++ /dev/null @@ -1,22 +0,0 @@ -# dependency -node_modules - -# macOS -.DS_Store - -# ide -.vs_code -.idea - -# build -dist -build - -# jest -coverage - -# tcr-testing -tcr-testing.sh - -TCRNExample/android/ -TCRNExample/ios/ diff --git a/packages/taro-components-rn/.watchmanconfig b/packages/taro-components-rn/.watchmanconfig deleted file mode 100644 index 0967ef424bce..000000000000 --- a/packages/taro-components-rn/.watchmanconfig +++ /dev/null @@ -1 +0,0 @@ -{} diff --git a/packages/taro-components-rn/dep.js b/packages/taro-components-rn/dep.js index 6bba4b471951..2fe501531e3e 100644 --- a/packages/taro-components-rn/dep.js +++ b/packages/taro-components-rn/dep.js @@ -1,4 +1,4 @@ -/* eslint-disable @typescript-eslint/no-var-requires */ +/* eslint-disable no-console */ const { parseDependencyTree } = require('dpdm') const { peerDependencies } = require('./package.json') diff --git a/packages/taro-components-rn/package.json b/packages/taro-components-rn/package.json index 852e72629904..6bf5453a2be2 100644 --- a/packages/taro-components-rn/package.json +++ b/packages/taro-components-rn/package.json @@ -1,13 +1,18 @@ { "name": "@tarojs/components-rn", - "version": "4.0.0-beta.75", - "description": "多端解决方案基础组件(RN)", + "version": "4.0.0-alpha.4", + "description": "React Native 基础组件", + "author": "O2Team", + "license": "MIT", "main": "./dist/index.js", "scripts": { + "prod": "pnpm run build", "assets": "cpy 'src/**/*.png' '!src/__tests__/*' dist", - "build": "rimraf --impl=move-remove ./dist && tsc && pnpm run assets", + "prebuild": "pnpm run clean", + "clean": "rimraf --impl=move-remove ./dist", + "build": "tsc && pnpm run assets", "dev": "pnpm run assets && tsc --watch", - "lint": "eslint .", + "lint": "eslint src --ext .js,.jsx,.ts,.tsx", "test": "jest --silent", "test:ci": "jest --ci -i --coverage --silent", "test:dev": "jest --watch", @@ -23,50 +28,49 @@ "keywords": [ "taro" ], - "author": "O2Team", - "license": "MIT", + "engines": { + "node": ">= 18" + }, "dependencies": { - "@ant-design/react-native": "^5.0.0", - "@react-native-community/slider": "~4.4.2", - "@react-native-picker/picker": "~2.6.1", + "@ant-design/react-native": "5.0.0", + "@react-native-community/slider": "4.5.2", + "@react-native-picker/picker": "2.7.5", + "@tarojs/components": "workspace:*", "@tarojs/router-rn": "workspace:*", - "expo-av": "~13.10.0", - "expo-barcode-scanner": "~12.9.0", - "expo-camera": "~14.0.0", - "prop-types": "^15.7.2", - "react-native-maps": "^1.3.2", - "react-native-pager-view": "~6.2.0", - "react-native-webview": "~13.6.3" + "expo-av": "13.10.0", + "expo-barcode-scanner": "13.0.1", + "expo-camera": "15.0.8", + "prop-types": "^15.8.1", + "react-native-maps": "1.3.2", + "react-native-pager-view": "6.2.3", + "react-native-webview": "13.10.2" }, "devDependencies": { - "@babel/core": "^7.23.0", - "@babel/preset-env": "^7.20.0", - "@react-native-camera-roll/camera-roll": "~7.2.0", - "@react-native-community/segmented-control": "^2.2.2", + "@babel/core": "^7.24.4", + "@babel/preset-env": "^7.24.4", "@react-native/babel-preset": "^0.73.18", "@testing-library/jest-native": "^5.4.2", "@testing-library/react-native": "^12.4.1", + "cpy-cli": "^5.0.0", "dpdm": "^3.14.0", - "expo": "~50.0.2", - "jest": "^29.3.1", - "jest-cli": "^29.3.1", - "jest-environment-node": "^29.5.0", - "jest-expo": "^50.0.0", - "react": "18.2.0", - "react-native": "^0.73.1", - "react-native-gesture-handler": "~2.14.0", - "react-native-svg": "~14.1.0", - "react-test-renderer": "18.2.0" + "expo": "~51.0.5", + "expo-module-scripts": "^3.5.1", + "jest-expo": "^51.0.1", + "react": "^18.2.0", + "react-native": "^0.72.3", + "react-native-svg": "14.1.0" }, "peerDependencies": { - "@react-native-community/slider": "~4.4.2", - "@react-native-picker/picker": "~2.6.1", - "expo": "~50.0.2", - "expo-av": "~13.10.0", - "expo-barcode-scanner": "~12.9.0", - "expo-camera": "~14.0.0", - "react-native-pager-view": "~6.2.0", - "react-native-svg": "~14.1.0", - "react-native-webview": "~13.6.3" + "@react-native-community/slider": ">= 4.5", + "@react-native-picker/picker": ">= 2.6", + "expo": ">= 51", + "expo-av": ">= 13.10.0", + "expo-barcode-scanner": ">= 13", + "expo-camera": ">= 15", + "react": ">= 18", + "react-native": ">= 0.63.0", + "react-native-pager-view": "~ 6.2", + "react-native-svg": ">= 14.1.0", + "react-native-webview": ">= 13.6.0" } } diff --git a/packages/taro-components-rn/src/__tests__/button.spec.tsx b/packages/taro-components-rn/src/__tests__/button.spec.tsx index 030d65498201..86fa8c32855a 100644 --- a/packages/taro-components-rn/src/__tests__/button.spec.tsx +++ b/packages/taro-components-rn/src/__tests__/button.spec.tsx @@ -1,5 +1,6 @@ +import { fireEvent, render } from '@testing-library/react-native' import * as React from 'react' -import { render, fireEvent } from '@testing-library/react-native' + import Button from '../components/Button' describe(' -