diff --git a/.commitlintrc.js b/.commitlintrc.js deleted file mode 100644 index a4f43697737c..000000000000 --- a/.commitlintrc.js +++ /dev/null @@ -1,3 +0,0 @@ -module.exports = { - extends: ['@commitlint/config-conventional'] -} diff --git a/.eslintrc.js b/.eslintrc.js index 8fa424b5e2c2..26aaef57d1ae 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -1,45 +1,58 @@ module.exports = { parser: '@typescript-eslint/parser', - plugins: ['@typescript-eslint', 'jest', 'react', 'simple-import-sort', 'import'], + plugins: [ + '@typescript-eslint', + 'import', + 'jest', + 'react', + 'simple-import-sort', + 'prettier' + ], extends: [ + 'eslint:recommended', 'standard', 'plugin:@typescript-eslint/recommended', - 'plugin:react/recommended' + 'plugin:react/jsx-runtime', + 'plugin:react/recommended', + 'prettier' ], rules: { - // 'camelcase': ['error', {allow: ['^internal_', '^unstable_']}] - camelcase: 0, - indent: 'off', - '@typescript-eslint/no-this-alias': 0, '@typescript-eslint/ban-ts-comment': 0, '@typescript-eslint/camelcase': 0, '@typescript-eslint/explicit-function-return-type': 0, '@typescript-eslint/explicit-module-boundary-types': 0, - '@typescript-eslint/indent': ['error', 2], + '@typescript-eslint/indent': [2, 2], '@typescript-eslint/interface-name-prefix': 0, - '@typescript-eslint/member-delimiter-style': ['warn', { multiline: { delimiter: 'none' }, singleline: { delimiter: 'comma' } }], + '@typescript-eslint/member-delimiter-style': [1, { multiline: { delimiter: 'none' }, singleline: { delimiter: 'comma' } }], '@typescript-eslint/no-empty-function': 0, '@typescript-eslint/no-explicit-any': 0, - '@typescript-eslint/no-unused-vars': ['error', { argsIgnorePattern: '^_', args: 'after-used' }], - '@typescript-eslint/no-use-before-define': ['warn', { functions: false, classes: false }], '@typescript-eslint/no-namespace': 0, '@typescript-eslint/no-non-null-assertion': 0, + '@typescript-eslint/no-this-alias': 0, + '@typescript-eslint/no-unused-vars': [2, { argsIgnorePattern: '^_', args: 'after-used' }], + '@typescript-eslint/no-use-before-define': [1, { functions: false, classes: false }], '@typescript-eslint/no-var-requires': 0, - 'import/first': 'error', - 'import/newline-after-import': 'error', - 'import/no-duplicates': 'error', - 'no-console': ['error', { allow: ['warn', 'error'] }], + camelcase: 0, + 'import/first': 2, + 'import/newline-after-import': 2, + 'import/no-duplicates': 2, + indent: 'off', + 'no-console': [2, { allow: ['warn', 'error'] }], 'no-prototype-builtins': 0, 'no-unused-expressions': 0, 'no-unused-vars': 'off', 'no-use-before-define': 0, + 'no-empty': 1, 'prefer-spread': 0, 'prefer-rest-params': 0, - 'react/jsx-uses-vars': 'warn', + 'react/jsx-uses-vars': 1, 'react/prop-types': 0, 'react/no-find-dom-node': 0, - 'simple-import-sort/imports': 'error', - 'simple-import-sort/exports': 'error', + quotes: [2, 'single', { avoidEscape: true, allowTemplateLiterals: true }], + semi: [2, 'never'], + 'simple-import-sort/imports': 2, + 'simple-import-sort/exports': 2, + 'space-before-function-paren': [2, 'always'], 'standard/no-callback-literal': 0 }, env: { @@ -66,5 +79,10 @@ module.exports = { ecmaFeatures: { jsx: true } + }, + settings: { + react: { + version: 'detect' + } } } diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 000000000000..79a85db5c23d --- /dev/null +++ b/.gitattributes @@ -0,0 +1,14 @@ +# Don't allow people to merge changes to these generated files, because the result +# may be invalid. You need to run "rush update" again. +pnpm-lock.yaml merge=text +shrinkwrap.yaml merge=binary +npm-shrinkwrap.json merge=binary +yarn.lock merge=binary + +# Rush's JSON config files use JavaScript-style code comments. The rule below prevents pedantic +# syntax highlighters such as GitHub's from highlighting these comments as errors. Your text editor +# may also require a special configuration to allow comments in JSON. +# +# For more information, see this issue: https://github.com/microsoft/rushstack/issues/1088 +# +*.json linguist-language=JSON-with-Comments diff --git a/.github/workflows/nodejs.yml b/.github/workflows/nodejs.yml index 2276a5d25311..7ece3940a7a2 100644 --- a/.github/workflows/nodejs.yml +++ b/.github/workflows/nodejs.yml @@ -4,7 +4,7 @@ on: push: branches: - next - - feat/use-h5 + - feat/** pull_request: branches: - next @@ -20,38 +20,35 @@ jobs: node-version: [14.x, 16.x] steps: - - uses: actions/checkout@v2 - - name: Use Node.js ${{ matrix.node-version }} - uses: actions/setup-node@v1 - with: - node-version: ${{ matrix.node-version }} - # - name: restore lerna - # uses: actions/cache@v2 - # with: - # path: | - # node_modules - # */*/node_modules - # key: ${{ runner.os }}-${{ hashFiles('**/yarn.lock') }} - - name: Get yarn cache directory path - id: yarn-cache-dir-path - run: echo "::set-output name=dir::$(yarn cache dir)" + - name: Checkout + uses: actions/checkout@v3 + with : + ref : ${{ github.head_ref }} + - name: Use Node.js ${{ matrix.node-version }} + uses: actions/setup-node@v1 + with: + node-version: ${{ matrix.node-version }} - - uses: actions/cache@v2 - id: yarn-cache # use this to check for `cache-hit` (`steps.yarn-cache.outputs.cache-hit != 'true'`) - with: - path: ${{ steps.yarn-cache-dir-path.outputs.dir }} - key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }} - restore-keys: | - ${{ runner.os }}-yarn- - - run: npm install -g yarn - - run: yarn config set registry https://registry.yarnpkg.com - - name: install - run: yarn - - name: lint - run: yarn run lint - - name: build - run: yarn run build - - name: test - run: yarn test - env: - CI: true + # Bootstrap project + - name: Cache pnpm modules + uses: actions/cache@v2 + with: + path: ~/.pnpm-store + key: ${{ runner.os }}-${{ hashFiles('**/pnpm-lock.yaml') }} + restore-keys: | + ${{ runner.os }}- + - name: install + uses: pnpm/action-setup@v2.2.2 + with: + version: 7 + run_install: | + - recursive: true + args: [--frozen-lockfile] + - name: lint + run: pnpm run lint + - name: build + run: pnpm run build + - name: test + run: pnpm run test + env: + CI: true diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 20516b47ec7b..2daacd956471 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -3,7 +3,7 @@ on: # When Release Pull Request is merged push: branches: - - '**' + - 'feat/**' pull_request: branches: - next @@ -11,6 +11,7 @@ on: env: CI: true + BRANCH_NAME: ${{ github.head_ref || github.ref_name }} jobs: publish: name: Publish @@ -18,7 +19,9 @@ jobs: steps: # Setup - name: Checkout - uses: actions/checkout@v2 + uses: actions/checkout@v3 + with : + ref : ${{ github.head_ref }} - name: Setup Node ${{ matrix.node_version }} uses: actions/setup-node@v1 with: @@ -42,43 +45,40 @@ jobs: - name: Get commit message run: | COMMIT_MESSAGE=$(git log --format=%s -n 1) - echo "commitmsg=${COMMIT_MESSAGE}" >> $GITHUB_ENV + echo "COMMIT_MESSAGE=${COMMIT_MESSAGE}" >> $GITHUB_ENV - name: Show commit message - run : echo "$commitmsg" + run : echo "$COMMIT_MESSAGE" - # ------------------ If commit message not satisfied, skip ------------- + - name: Commit message compliance verification + if: startsWith( env.COMMIT_MESSAGE , 'chore(release):' ) != true + uses: andymckay/cancel-action@0.2 - # Get & check npm publish dist-tag when event is push - - name: Get dist tag - if: startsWith( env.commitmsg , 'chore(release):' ) && github.event_name == 'push' && contains( env.commitmsg , '--tag=' ) - run: | - TEMP=`echo $commitmsg | grep -oP "\-\-tag=(\w+)"` - DIST_TAG=`echo ${TEMP:6}` - echo "disttag=${DIST_TAG}" >> $GITHUB_ENV - - name: Show dist tag - if: startsWith( env.commitmsg , 'chore(release):' ) && github.event_name == 'push' && contains( env.commitmsg , '--tag=' ) - run : echo "$disttag" - - name: Check dist tag - if: startsWith( env.commitmsg , 'chore(release):' ) && github.event_name == 'push' && !env.disttag - run: | - echo "Publish by pushing must provide parameter named tag, just like: chore(release): publish 1.0 --tag=beta" - - name: Cancelling - if: startsWith( env.commitmsg , 'chore(release):' ) && github.event_name == 'push' && !env.disttag + - name: Publish push tag verification + if: github.event_name == 'push' && contains( env.COMMIT_MESSAGE , '--tag=' ) != true uses: andymckay/cancel-action@0.2 - # ------------------ If event is push but there is no dist tag, exit ------------- + # ------------------ If event is push ------------- + + # Get & check npm publish + - name: Get publish params + if: github.event_name == 'push' + run: | + PUBLISH_PARAMS=`echo $COMMIT_MESSAGE | grep -oE "^chore\(release\): publish \S*\s(.*)" | cut -d " " -f 4-` + echo "PUBLISH_PARAMS=${PUBLISH_PARAMS}" >> $GITHUB_ENV + + - name: Show publish params + if: github.event_name == 'push' + run: echo "Publish pushing provide parameter [$PUBLISH_PARAMS]." # Define ${CURRENT_VERSION} - name: Set Current Version - if: startsWith( env.commitmsg , 'chore(release):' ) shell: bash -ex {0} run: | - CURRENT_VERSION=$(node -p 'require("./lerna.json").version') + CURRENT_VERSION=$(node -p 'require("./package.json").version') echo "CURRENT_VERSION=${CURRENT_VERSION}" >> $GITHUB_ENV # Check git tag - name: Tag Check - if: startsWith( env.commitmsg , 'chore(release):' ) id: tag_check shell: bash -ex {0} run: | @@ -95,24 +95,36 @@ jobs: # ------------------ If git tag already exists, skip ------------- + - name: Git tag verification + if: steps.tag_check.outputs.exists_tag == false + uses: andymckay/cancel-action@0.2 + # Bootstrap project + - name: Cache pnpm modules + uses: actions/cache@v2 + with: + path: ~/.pnpm-store + key: ${{ runner.os }}-${{ hashFiles('**/pnpm-lock.yaml') }} + restore-keys: | + ${{ runner.os }}- - name: install - if: startsWith( env.commitmsg , 'chore(release):' ) && steps.tag_check.outputs.exists_tag == 'false' - run: yarn + uses: pnpm/action-setup@v2.2.2 + with: + version: 7 + run_install: | + - recursive: true + args: [--frozen-lockfile] - name: build - if: startsWith( env.commitmsg , 'chore(release):' ) && steps.tag_check.outputs.exists_tag == 'false' - run: yarn build + run: pnpm run build # Git stash - name: Drop current changes - if: startsWith( env.commitmsg , 'chore(release):' ) && steps.tag_check.outputs.exists_tag == 'false' run: | git add . git stash # Create git tag - name: Create Git Tag - if: startsWith( env.commitmsg , 'chore(release):' ) && steps.tag_check.outputs.exists_tag == 'false' uses: azu/action-package-version-to-git-tag@v1 with: version: ${{ env.CURRENT_VERSION }} @@ -121,16 +133,14 @@ jobs: git_commit_sha: ${{ github.sha }} git_tag_prefix: "v" - # ------------------ Before publish ------------- + # ------------------ publish ------------- - # Publish - name: Publish - if: startsWith( env.commitmsg , 'chore(release):' ) && steps.tag_check.outputs.exists_tag == 'false' run: | if [ '${{ github.event_name }}' == 'pull_request' ] ; then - yarn lerna publish from-package --yes + pnpm publish --registry=https://registry.npmjs.org/ --publish-branch=${{ env.BRANCH_NAME }} -r elif [ '${{ github.event_name }}' == 'push' ] ; then - yarn lerna publish from-package --dist-tag ${{ env.disttag }} --yes + pnpm publish --registry=https://registry.npmjs.org/ --publish-branch=${{ env.BRANCH_NAME }} -r ${{ env.PUBLISH_PARAMS }} fi env: GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} @@ -138,10 +148,10 @@ jobs: # ------------------ After publish ------------- - # Create relase when event is PR + # Create release when event is PR - name: Create Release id: create_release - if: startsWith( env.commitmsg , 'chore(release):' ) && steps.tag_check.outputs.exists_tag == 'false' && github.event.pull_request.merged == true + if: github.event.pull_request.merged == true uses: actions/create-release@v1 env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} @@ -156,7 +166,7 @@ jobs: # Create PR page comment when event is PR - uses: actions/github-script@0.8.0 - if: startsWith( env.commitmsg , 'chore(release):' ) && steps.tag_check.outputs.exists_tag == 'false' && github.event.pull_request.merged == true + if: github.event.pull_request.merged == true with: github-token: ${{secrets.GITHUB_TOKEN}} script: | diff --git a/.gitignore b/.gitignore index f0d2473cc344..44404d6907dc 100644 --- a/.gitignore +++ b/.gitignore @@ -1,14 +1,74 @@ dist/ -node_modules -.cache -.DS_Store -lerna-debug.log -yarn-error.log _book .idea -temp -website/build -website/package.json + +# Logs & Lock +*.log +npm-debug.log* +yarn-debug.log* +yarn-error.log* packages/**/package-lock.json + +# Runtime data +*.pid +*.seed +*.pid.lock + +# Directory for instrumented libs generated by jscoverage/JSCover +lib-cov + +# Coverage directory used by tools like istanbul coverage + +# nyc test coverage +.nyc_output + +# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) +.grunt + +# Bower dependency directory (https://bower.io/) +bower_components + +# node-waf configuration +.lock-wscript + +# Compiled binary addons (https://nodejs.org/api/addons.html) +build/Release + +# Dependency directories +node_modules/ +jspm_packages/ + +# Cache & Temp +.cache +.eslintcache +.npm +temp + +# History .history/ +.node_repl_history + +# Output of 'npm pack' +*.tgz + +# Yarn Integrity file +.yarn-integrity + +# dotenv environment variables file +.env + +# next.js build output +.next + +# OS X temporary files +.DS_Store + +# Rush temporary files +common/deploy/ +common/temp/ +common/autoinstallers/*/.npmrc +**/.rush/temp/ + +# Heft +.heft diff --git a/.husky/commit-msg b/.husky/commit-msg new file mode 100755 index 000000000000..2101bef38c3c --- /dev/null +++ b/.husky/commit-msg @@ -0,0 +1,4 @@ +#!/bin/sh +. "$(dirname "$0")/_/husky.sh" + +pnpm commitlint --edit $1 --config commitlint.config.js diff --git a/.husky/pre-commit b/.husky/pre-commit new file mode 100755 index 000000000000..b385f5660b67 --- /dev/null +++ b/.husky/pre-commit @@ -0,0 +1,4 @@ +#!/bin/sh +. "$(dirname "$0")/_/husky.sh" + +pnpm lint-staged --allow-empty diff --git a/.npmrc b/.npmrc new file mode 100644 index 000000000000..1236a7f6baba --- /dev/null +++ b/.npmrc @@ -0,0 +1,12 @@ +always-auth=false +auto-install-peers=false +enable-pre-post-scripts=true +link-workspace-packages=true +public-hoist-pattern[]=@types/* +public-hoist-pattern[]=*eslint* +public-hoist-pattern[]=*jest* +public-hoist-pattern[]=*prettier* +registry="https://registry.yarnpkg.com/" +strict-peer-dependencies=true + +{SCOPE}:registry=https://npm.pkg.github.com diff --git a/.stylelintrc b/.stylelintrc index a2aeb6d34aea..2e1ca11f8cbe 100644 --- a/.stylelintrc +++ b/.stylelintrc @@ -6,12 +6,13 @@ "customSyntax": "postcss-scss", "rules": { "font-family-no-missing-generic-family-keyword": null, + "function-url-quotes": null, "max-line-length": 150, "no-descending-specificity": null, "number-max-precision": 10, "scss/at-import-partial-extension": null, "scss/dollar-variable-pattern": "^[a-z][a-zA-Z0-9]+$", - "selector-class-pattern": "^([a-z][a-z0-9]*)(-[a-z0-9]+)*(__[a-z0-9]+)*$", + "selector-class-pattern": "^([a-z][a-z0-9]*)([-_][a-z0-9]+)*(__[a-z0-9]+)*$", "selector-pseudo-class-no-unknown": [ true, { diff --git a/.vscode/settings.json b/.vscode/settings.json index a1e4aa74d882..c2ced72978a3 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -20,5 +20,8 @@ "jest.autoEnable": false, "typescript.tsdk": "node_modules/typescript/lib", "javascript.format.insertSpaceBeforeFunctionParenthesis": true, - "typescript.format.insertSpaceBeforeFunctionParenthesis": true + "typescript.format.insertSpaceBeforeFunctionParenthesis": true, + "files.associations": { + "*.json": "jsonc" + } } diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index edf7fcf78f9c..e3a434e0ac68 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -14,20 +14,20 @@ ### 安装依赖 -基于 yarn workspace。 +基于 pnpm workspace。 ```bash -$ yarn +$ pnpm install ``` ### 编译构建 ```bash # 全局编译 -$ yarn build # 等价于 lerna run build +$ pnpm run build # 等价于 pnpm -r --filter=./packages/* run build # 编译某个子包,如 `@tarojs/cli` -$ lerna run build --scope=@tarojs/cli +$ pnpm --filter @tarojs/cli run dev ``` ### 新增/删除依赖 @@ -41,36 +41,30 @@ $ lerna run build --scope=@tarojs/cli ```bash # 新增 -$ yarn add -W -D +$ pnpm add -wD # 删除 -$ yarn remove -W -D +$ pnpm remove -wD ``` #### 2. 操作某个子包 ```bash # 为某个子包(如 @tarojs/cli)新增一个依赖 -$ yarn workspace @tarojs/cli add +$ pnpm --filter @tarojs/cli add # 为某个子包(如 @tarojs/cli)删除一个依赖 -$ yarn workspace @tarojs/cli remove - -# 如遇到报错 "expected workspace package to exist for",请使用 yarn@1.18 再尝试。 -# 相关 issues: -# - https://github.com/yarnpkg/yarn/issues/7807 -# - https://github.com/yarnpkg/yarn/issues/7734 -$ npx yarn@1.18 workspace @tarojs/cli add +$ pnpm --filter @tarojs/cli remove ``` #### 3. 操作所有子包 ```bash # 新增 -$ yarn workspaces add +$ pnpm -r --filter=./packages/* add # 删除 -$ yarn workspaces remove +$ pnpm -r --filter=./packages/* remove ``` ### 清理所有依赖 @@ -88,11 +82,17 @@ $ lerna run --scope= --stream ### 提交发布 -```bash -$ yarn run version --lerna_version= -$ git add . -$ git commit -m "chore(release): publish " -``` +- PR 发布规则 + + ```bash + $ pnpm version + ``` + +- `feat/**` 分支发布规则 + + ```bash + $ pnpm version --tag= + ``` ## 提交 commit diff --git a/lerna.json b/lerna.json deleted file mode 100644 index 212759669927..000000000000 --- a/lerna.json +++ /dev/null @@ -1,17 +0,0 @@ -{ - "version": "3.5.0-beta.4", - "npmClient": "yarn", - "npmClientArgs": [ - "--ignore-engines" - ], - "command": { - "create": { - "homepage": "https://github.com/nervjs/taro", - "license": "MIT" - }, - "publish": { - "message": "chore(release): publish %s" - } - }, - "useWorkspaces": true -} diff --git a/package.json b/package.json index 7054e9c1849e..f9c391a9ff61 100644 --- a/package.json +++ b/package.json @@ -1,5 +1,6 @@ { "name": "taro", + "version": "3.5.0-theta.1", "description": "开放式跨端跨框架开发解决方案", "homepage": "https://github.com/NervJS/taro#readme", "author": "O2Team", @@ -18,14 +19,15 @@ }, "main": "index.js", "scripts": { - "build": "lerna run build", - "clear-all": "lerna clean -y && rimraf node_modules", - "lint": "eslint packages/ --ext .js --ext .ts --ext .tsx", + "preinstall": "npx only-allow pnpm", + "build": "pnpm -r --filter=./packages/* run build", + "clear-all": "rimraf **/node_modules", + "lint": "eslint packages/ --ext .js --ext .ts --ext .tsx", "lint:style": "stylelint ./packages/**/*.{css,scss}", - "test": "lerna run --scope @tarojs/cli --scope babel-preset-taro --scope @tarojs/components --scope @tarojs/taro-h5 --scope @tarojs/react --scope @tarojs/webpack-runner --scope @tarojs/mini-runner --scope @tarojs/runtime --scope @tarojs/taro-rn --scope @tarojs/components-rn test:ci --parallel", + "test": "pnpm --parallel -r --filter @tarojs/cli --filter babel-preset-taro --filter @tarojs/components --filter @tarojs/taro-h5 --filter @tarojs/react --filter @tarojs/webpack-runner --filter @tarojs/taro-rn --filter @tarojs/components-rn run test:ci", "version": "run-s version:*", - "version:lerna": "lerna version ${npm_config_lerna_version} --exact --no-git-tag-version --force-publish --yes", - "version:git": "git add . && git commit -m \"chore(release): publish ${npm_config_lerna_version}\"", + "version:release": "pnpm -r --filter=./packages/* exec npm version ${npm_package_version}", + "version:git": "git add . && git commit -m \"chore(release): publish ${npm_package_version}\"", "version:changelog": "conventional-changelog -p angular" }, "lint-staged": { @@ -33,20 +35,11 @@ "eslint --fix", "git add" ], - "*.{json}": [ + "*.json": [ "prettier --write", "git add -f" ] }, - "husky": { - "hooks": { - "commit-msg": "commitlint -E HUSKY_GIT_PARAMS --config commitlint.config.js", - "pre-commit": "lint-staged" - } - }, - "workspaces": [ - "packages/*" - ], "devDependencies": { "@babel/cli": "^7.14.5", "@babel/core": "^7.14.5", @@ -62,19 +55,44 @@ "@babel/preset-env": "^7.14.5", "@babel/preset-react": "^7.14.5", "@babel/preset-typescript": "^7.14.5", + "@babel/runtime": "^7.14.5", "@babel/traverse": "^7.14.5", "@babel/types": "^7.14.5", - "@commitlint/cli": "^7.2.1", - "@commitlint/config-conventional": "^9.0.1", + "@commitlint/cli": "^16.2.1", + "@commitlint/config-conventional": "^16.2.1", + "@jest/globals": "^26.6.2", "@rollup/plugin-babel": "^5.2.1", + "@rollup/plugin-buble": "^0.21.3", "@rollup/plugin-commonjs": "^20.0.0", "@rollup/plugin-node-resolve": "^8.0.0", "@rollup/plugin-replace": "^2.2.0", - "@rollup/plugin-typescript": "^8.3.1", + "@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-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:*", + "@tarojs/taro-loader": "workspace:*", + "@tarojs/taro-rn": "workspace:*", + "@tarojs/webpack-runner": "workspace:*", + "@testing-library/jest-dom": "^5.16.4", "@testing-library/jest-native": "^4.0.4", "@testing-library/react-native": "^9.0.0", "@types/autoprefixer": "9.7.0", "@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", @@ -82,13 +100,17 @@ "@types/history": "^4.7.5", "@types/inquirer": "^8.2.1", "@types/jest": "^27.4.1", + "@types/less": "^3.0.2", "@types/lodash": "^4.14.142", "@types/lodash-es": "^4.17.6", "@types/node": "^14.14.31", + "@types/postcss-import": "^12.0.0", "@types/react": "^18.0.0", "@types/react-reconciler": "0.26.1", "@types/request": "^2.48.1", "@types/resolve": "1.19.0", + "@types/sass": "^1.16.1", + "@types/sax": "^1.2.4", "@types/sinon": "^7.5.0", "@types/tapable": "^1", "@types/testing-library__jest-dom": "^5.14.3", @@ -104,15 +126,18 @@ "babel-jest": "24.9.0", "babel-plugin-syntax-jsx": "6.18.0", "babel-preset-power-assert": "3.0.0", + "babel-preset-taro": "workspace:*", "cli-highlight": "^2.1.4", "conventional-changelog-cli": "^2.0.1", "core-js": "^2.6.5", "cpy-cli": "^4.1.0", "cross-env": "^7.0.2", + "esbuild": "^0.14.27", "eslint": "^8.12.0", "eslint-config-prettier": "^6.4.0", "eslint-config-standard": "^14.1.1", "eslint-config-standard-jsx": "^8.1.0", + "eslint-config-taro": "workspace:*", "eslint-plugin-flowtype": "^3.2.0", "eslint-plugin-import": "^2.26.0", "eslint-plugin-jest": "26.1.3", @@ -125,15 +150,13 @@ "eslint-plugin-standard": "^4.0.1", "eslint-plugin-vue": "^8.6.0", "gh-pages": "^1.1.0", - "husky": "^1.2.0", + "husky": "^8.0.1", "jest": "26.4.2", - "jest-dom": "^1.3.1", "jest-expo": "^45.0.1", "jest-fetch-mock": "^3.0.3", "jest-localstorage-mock": "^2.4.0", "jest-mock-console": "^1.0.0", - "lerna": "4.0.0", - "lint-staged": "^10.2.11", + "lint-staged": "^13.0.2", "memfs": "^3.1.2", "memory-fs": "^0.5.0", "mock-socket": "^7.1.0", @@ -144,30 +167,31 @@ "postcss": "^8.4.12", "postcss-scss": "^4.0.3", "power-assert": "^1.6.1", - "prettier": "^1.18.2", + "prettier": "^2.7.1", + "prop-types": "^15.7.2", "react": "18.0.0", "react-dom": "18.0.0", "react-test-renderer": "18.0.0", "rimraf": "^3.0.0", "rollup": "^2.56.2", - "rollup-plugin-buble": "^0.19.8", "rollup-plugin-copy": "^3.4.0", "rollup-plugin-node-externals": "^4.0.0", "rollup-plugin-postcss": "^3.1.8", - "rollup-plugin-typescript2": "^0.24.3", + "rollup-plugin-ts": "^3.0.2", "shelljs": "^0.8.1", "sinon": "^7.5.0", "stylelint": "^14.6.1", "stylelint-config-standard-scss": "^3.0.0", "stylelint-order": "^5.0.0", "ts-jest": "26.5.5", + "tslib": "^1.9.3", "typescript": "4.6.3", "vue": "^2.6.11", "vue-loader": "^17.0.0", "vue-template-compiler": "^2.6.11", "webpack": "5.69.0", "webpack-chain": "6.5.1", - "webpack-dev-server": "4.7.4" - }, - "version": "3.5.0-beta.2" + "webpack-dev-server": "4.7.4", + "webpack-sources": "^3.2.3" + } } 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 1442f4ca662a..7f5232d5ea4a 100644 --- a/packages/babel-plugin-transform-react-jsx-to-rn-stylesheet/package.json +++ b/packages/babel-plugin-transform-react-jsx-to-rn-stylesheet/package.json @@ -1,6 +1,6 @@ { "name": "babel-plugin-transform-react-jsx-to-rn-stylesheet", - "version": "3.5.0-beta.4", + "version": "3.5.0-theta.1", "description": "Transform stylesheet selector to style in JSX Elements.", "license": "MIT", "main": "dist/index.js", @@ -24,9 +24,6 @@ }, "dependencies": { "camelize": "^1.0.0", - "taro-css-to-react-native": "3.5.0-beta.4" - }, - "devDependencies": { - "@types/babel__core": "^7.1.14" + "taro-css-to-react-native": "workspace:*" } } diff --git a/packages/babel-plugin-transform-taroapi/package.json b/packages/babel-plugin-transform-taroapi/package.json index a1c6846060a5..b7baa0886447 100644 --- a/packages/babel-plugin-transform-taroapi/package.json +++ b/packages/babel-plugin-transform-taroapi/package.json @@ -1,6 +1,6 @@ { "name": "babel-plugin-transform-taroapi", - "version": "3.5.0-beta.4", + "version": "3.5.0-theta.1", "main": "dist/index.js", "scripts": { "build": "tsc" diff --git a/packages/babel-plugin-transform-taroapi/src/index.ts b/packages/babel-plugin-transform-taroapi/src/index.ts index 750ef66e2a90..25653b6a747f 100644 --- a/packages/babel-plugin-transform-taroapi/src/index.ts +++ b/packages/babel-plugin-transform-taroapi/src/index.ts @@ -3,12 +3,12 @@ const plugin = function (babel: { }) { const t = babel.types - // 这些变量需要在每个programe里重置 + // 这些变量需要在每个 program 里重置 const invokedApis: Map = new Map() let taroName: string let needDefault: boolean - let referrencedTaros: any[] + let referTaro: any[] return { name: 'babel-plugin-transform-taro-api', @@ -31,12 +31,12 @@ const plugin = function (babel: { needDefault = true const localName = node.local.name const binding = ast.scope.getBinding(localName) - const iden = t.identifier(taroName) - referrencedTaros.push(iden) + const idn = t.identifier(taroName) + referTaro.push(idn) binding && binding.referencePaths.forEach(reference => { reference.replaceWith( t.memberExpression( - iden, + idn, t.identifier(propertyName) ) ) @@ -87,7 +87,7 @@ const plugin = function (babel: { Program: { enter (ast) { needDefault = false - referrencedTaros = [] + referTaro = [] invokedApis.clear() taroName = ast.scope.getBinding('Taro') @@ -97,7 +97,7 @@ const plugin = function (babel: { exit (ast, state) { // 防止重复引入 let isTaroApiImported = false - referrencedTaros.forEach(node => { + referTaro.forEach(node => { node.name = taroName }) diff --git a/packages/babel-preset-taro/package.json b/packages/babel-preset-taro/package.json index 441137cd0103..1e23fdf2ab93 100644 --- a/packages/babel-preset-taro/package.json +++ b/packages/babel-preset-taro/package.json @@ -1,6 +1,6 @@ { "name": "babel-preset-taro", - "version": "3.5.0-beta.4", + "version": "3.5.0-theta.1", "description": "> TODO: description", "author": "yuche ", "homepage": "https://github.com/nervjs/taro/tree/master/packages/babel-preset-taro#readme", @@ -35,15 +35,15 @@ "@babel/preset-typescript": "^7.14.5", "@babel/runtime": "^7.14.5", "@babel/runtime-corejs3": "^7.14.5", - "@tarojs/helper": "3.5.0-beta.4", - "@tarojs/taro-h5": "3.5.0-beta.4", + "@tarojs/helper": "workspace:*", + "@tarojs/taro-h5": "workspace:*", "babel-plugin-dynamic-import-node": "2.3.3", "babel-plugin-global-define": "1.0.3", "babel-plugin-jsx-attributes-array-to-object": "0.3.0", "babel-plugin-minify-dead-code-elimination": "^0.5.2", "babel-plugin-transform-imports-api": "1.0.0", - "babel-plugin-transform-react-jsx-to-rn-stylesheet": "3.5.0-beta.4", - "babel-plugin-transform-taroapi": "3.5.0-beta.4", + "babel-plugin-transform-react-jsx-to-rn-stylesheet": "workspace:*", + "babel-plugin-transform-taroapi": "workspace:*", "core-js": "^3.6.5", "metro-react-native-babel-preset": "^0.67.0" } diff --git a/packages/css-to-react-native/package.json b/packages/css-to-react-native/package.json index d550acb5aede..aa23d1bed32d 100644 --- a/packages/css-to-react-native/package.json +++ b/packages/css-to-react-native/package.json @@ -1,7 +1,7 @@ { "name": "taro-css-to-react-native", "description": "Convert CSS text to a React Native stylesheet object", - "version": "3.5.0-beta.4", + "version": "3.5.0-theta.1", "main": "dist/index.js", "license": "MIT", "dependencies": { @@ -47,15 +47,6 @@ "/node_modules" ] }, - "lint-staged": { - "*.{js,json,md}": [ - "prettier --write", - "git add" - ] - }, - "prettier": { - "trailingComma": "all" - }, "files": [ "dist", "src", diff --git a/packages/css-to-react-native/src/css-to-react-native/index.js b/packages/css-to-react-native/src/css-to-react-native/index.js index 2ac43591ff7c..24b469b0d0be 100644 --- a/packages/css-to-react-native/src/css-to-react-native/index.js +++ b/packages/css-to-react-native/src/css-to-react-native/index.js @@ -1,8 +1,9 @@ /* eslint-disable no-param-reassign */ -import parse from 'postcss-value-parser' import camelizeStyleName from 'camelize' -import transforms from './transforms/index' +import parse from 'postcss-value-parser' + import TokenStream from './TokenStream' +import transforms from './transforms/index' // Note if this is wrong, you'll need to change tokenTypes.js too const numberOrLengthRe = /^([+-]?(?:\d*\.)?\d+(?:[Ee][+-]?\d+)?)(?:px)?$/i @@ -11,7 +12,7 @@ const nullRe = /^null$/i const undefinedRe = /^undefined$/i // Undocumented export -export const transformRawValue = input => { +export const transformRawValue = (input) => { const value = input.trim() const numberMatch = value.match(numberOrLengthRe) @@ -47,7 +48,9 @@ const checkBaseTransformShorthandValue = (propName, inputValue) => { try { return baseTransformShorthandValue(propName, inputValue) } catch (e) { - throw new Error(`${e.message} Failed to parse declaration "${propName}: ${inputValue}"`) + throw new Error( + `${e.message} Failed to parse declaration "${propName}: ${inputValue}"`, + ) } } @@ -58,11 +61,15 @@ const transformShorthandValue = export const getStylesForProperty = (propName, inputValue, allowShorthand) => { const isRawValue = allowShorthand === false || !(propName in transforms) - const propValue = isRawValue ? transformRawValue(inputValue) : transformShorthandValue(propName, inputValue.trim()) - return propValue && propValue.$merge ? propValue.$merge : { [propName]: propValue } + const propValue = isRawValue + ? transformRawValue(inputValue) + : transformShorthandValue(propName, inputValue.trim()) + return propValue && propValue.$merge + ? propValue.$merge + : { [propName]: propValue } } -export const getPropertyName = propName => { +export const getPropertyName = (propName) => { const isCustomProp = /^--\w+/.test(propName) if (isCustomProp) { return propName @@ -75,5 +82,8 @@ export default (rules, shorthandBlacklist = []) => const propertyName = getPropertyName(rule[0]) const value = rule[1] const allowShorthand = shorthandBlacklist.indexOf(propertyName) === -1 - return Object.assign(accum, getStylesForProperty(propertyName, value, allowShorthand)) + return Object.assign( + accum, + getStylesForProperty(propertyName, value, allowShorthand), + ) }, {}) diff --git a/packages/css-to-react-native/src/css-to-react-native/tokenTypes.js b/packages/css-to-react-native/src/css-to-react-native/tokenTypes.js index 400e676b1661..a70c97e3c76d 100644 --- a/packages/css-to-react-native/src/css-to-react-native/tokenTypes.js +++ b/packages/css-to-react-native/src/css-to-react-native/tokenTypes.js @@ -1,20 +1,24 @@ -import { stringify } from 'postcss-value-parser' import cssColorKeywords from 'css-color-keywords' +import { stringify } from 'postcss-value-parser' -const matchString = node => { +const matchString = (node) => { if (node.type !== 'string') return null return node.value - .replace(/\\([0-9a-f]{1,6})(?:\s|$)/gi, (match, charCode) => String.fromCharCode(parseInt(charCode, 16))) + .replace(/\\([0-9a-f]{1,6})(?:\s|$)/gi, (match, charCode) => + String.fromCharCode(parseInt(charCode, 16)), + ) .replace(/\\/g, '') } const hexColorRe = /^(#(?:[0-9a-f]{3,4}){1,2})$/i const cssFunctionNameRe = /^(rgba?|hsla?|hwb|lab|lch|gray|color)$/ -const matchColor = node => { +const matchColor = (node) => { if ( node.type === 'word' && - (hexColorRe.test(node.value) || node.value in cssColorKeywords || node.value === 'transparent') + (hexColorRe.test(node.value) || + node.value in cssColorKeywords || + node.value === 'transparent') ) { return node.value } else if (node.type === 'function' && cssFunctionNameRe.test(node.value)) { @@ -29,22 +33,25 @@ const identRe = /(^-?[_a-z][_a-z0-9-]*$)/i // Note if these are wrong, you'll need to change index.js too const numberRe = /^([+-]?(?:\d*\.)?\d+(?:[Ee][+-]?\d+)?)$/ // Note lengthRe is sneaky: you can omit units for 0 -const lengthRe = /^(0$|(?:[+-]?(?:\d*\.)?\d+(?:[Ee][+-]?\d+)?)((?=px$)|(?=Px$)|(?=PX$)|(?=pX$)))/ -const unsupportedUnitRe = /^([+-]?(?:\d*\.)?\d+(?:[Ee][+-]?\d+)?(ch|em|ex|rem|vh|vw|vmin|vmax|cm|mm|in|pc|pt))$/ +const lengthRe = + /^(0$|(?:[+-]?(?:\d*\.)?\d+(?:[Ee][+-]?\d+)?)((?=px$)|(?=Px$)|(?=PX$)|(?=pX$)))/ +const unsupportedUnitRe = + /^([+-]?(?:\d*\.)?\d+(?:[Ee][+-]?\d+)?(ch|em|ex|rem|vh|vw|vmin|vmax|cm|mm|in|pc|pt))$/ const angleRe = /^([+-]?(?:\d*\.)?\d+(?:[Ee][+-]?\d+)?(?:deg|rad))$/ const percentRe = /^([+-]?(?:\d*\.)?\d+(?:[Ee][+-]?\d+)?%)$/ -const noopToken = predicate => node => (predicate(node) ? '' : null) +const noopToken = (predicate) => (node) => predicate(node) ? '' : null -const valueForTypeToken = type => node => (node.type === type ? node.value : null) +const valueForTypeToken = (type) => (node) => + node.type === type ? node.value : null -const functionValueForTypeToken = type => node => { +const functionValueForTypeToken = (type) => (node) => { if (node.type === type) { // handle rgb(a) function value if (/^rgba?$/i.test(node.value)) { const result = node.nodes - .filter(token => token.type === 'word') - .map(token => token.value) + .filter((token) => token.type === 'word') + .map((token) => token.value) return `${node.value}(${result.join(', ')})` } @@ -52,24 +59,26 @@ const functionValueForTypeToken = type => node => { return null } -export const regExpToken = (regExp, transform = String) => node => { - if (node.type !== 'word') return null +export const regExpToken = + (regExp, transform = String) => + (node) => { + if (node.type !== 'word') return null - const match = node.value.match(regExp) - if (match === null) return null + const match = node.value.match(regExp) + if (match === null) return null - const value = transform(match[1]) - if (/(\d+)px/.test(node.value)) { - return `scalePx2dp(${value})` - } else { - return value - } -} + const value = transform(match[1]) + if (/(\d+)px/.test(node.value)) { + return `scalePx2dp(${value})` + } else { + return value + } + } export const tokens = { - SPACE: noopToken(node => node.type === 'space'), - SLASH: noopToken(node => node.type === 'div' && node.value === '/'), - COMMA: noopToken(node => node.type === 'div' && node.value === ','), + SPACE: noopToken((node) => node.type === 'space'), + SLASH: noopToken((node) => node.type === 'div' && node.value === '/'), + COMMA: noopToken((node) => node.type === 'div' && node.value === ','), WORD: valueForTypeToken('word'), FUNC: functionValueForTypeToken('function'), NONE: regExpToken(noneRe), @@ -82,5 +91,5 @@ export const tokens = { IDENT: regExpToken(identRe), STRING: matchString, COLOR: matchColor, - LINE: regExpToken(/^(none|underline|line-through)$/i) + LINE: regExpToken(/^(none|underline|line-through)$/i), } diff --git a/packages/css-to-react-native/src/css-to-react-native/transforms/border.js b/packages/css-to-react-native/src/css-to-react-native/transforms/border.js index 0db8208c53a9..a68d92de8f74 100644 --- a/packages/css-to-react-native/src/css-to-react-native/transforms/border.js +++ b/packages/css-to-react-native/src/css-to-react-native/transforms/border.js @@ -1,29 +1,23 @@ import { regExpToken, tokens } from '../tokenTypes' -import { directionFactory, anyOrderFactory } from './util' +import { anyOrderFactory, directionFactory } from './util' -const { - WORD, - FUNC, - COLOR, - LENGTH, - UNSUPPORTED_LENGTH_UNIT -} = tokens +const { WORD, FUNC, COLOR, LENGTH, UNSUPPORTED_LENGTH_UNIT } = tokens function borderDirectionFactory (direction = '') { const prefix = `border${direction}` return anyOrderFactory({ [`${prefix}Width`]: { tokens: [LENGTH, UNSUPPORTED_LENGTH_UNIT], - default: 1 + default: 1, }, [`${prefix}Color`]: { tokens: [COLOR], - default: 'black' + default: 'black', }, [`${prefix}Style`]: { tokens: [regExpToken(/^(solid|dashed|dotted)$/)], - default: 'solid' - } + default: 'solid', + }, }) } @@ -37,13 +31,16 @@ export const borderLeft = borderDirectionFactory('Left') export const borderColor = directionFactory({ types: [WORD, FUNC], prefix: 'border', - suffix: 'Color' + suffix: 'Color', }) export const borderRadius = directionFactory({ directions: ['TopLeft', 'TopRight', 'BottomRight', 'BottomLeft'], prefix: 'border', - suffix: 'Radius' + suffix: 'Radius', }) -export const borderWidth = directionFactory({ prefix: 'border', suffix: 'Width' }) +export const borderWidth = directionFactory({ + prefix: 'border', + suffix: 'Width', +}) diff --git a/packages/css-to-react-native/src/css-to-react-native/transforms/font.js b/packages/css-to-react-native/src/css-to-react-native/transforms/font.js index 8f773a3662da..495ae1dd795a 100644 --- a/packages/css-to-react-native/src/css-to-react-native/transforms/font.js +++ b/packages/css-to-react-native/src/css-to-react-native/transforms/font.js @@ -1,5 +1,5 @@ -import parseFontFamily from './fontFamily' import { regExpToken, tokens } from '../tokenTypes' +import parseFontFamily from './fontFamily' const { SPACE, LENGTH, UNSUPPORTED_LENGTH_UNIT, NUMBER, SLASH } = tokens const NORMAL = regExpToken(/^(normal)$/) @@ -11,7 +11,7 @@ const defaultFontStyle = 'normal' const defaultFontWeight = 'normal' const defaultFontVariant = [] -export default tokenStream => { +export default (tokenStream) => { let fontStyle let fontWeight let fontVariant @@ -25,9 +25,15 @@ export default tokenStream => { /* pass */ } else if (typeof fontStyle === 'undefined' && tokenStream.matches(STYLE)) { fontStyle = tokenStream.lastValue - } else if (typeof fontWeight === 'undefined' && tokenStream.matches(WEIGHT)) { + } else if ( + typeof fontWeight === 'undefined' && + tokenStream.matches(WEIGHT) + ) { fontWeight = tokenStream.lastValue - } else if (typeof fontVariant === 'undefined' && tokenStream.matches(VARIANT)) { + } else if ( + typeof fontVariant === 'undefined' && + tokenStream.matches(VARIANT) + ) { fontVariant = [tokenStream.lastValue] } else { break @@ -41,7 +47,10 @@ export default tokenStream => { if (tokenStream.matches(SLASH)) { if (tokenStream.matches(NUMBER)) { - const size = typeof fontSize === 'string' ? fontSize.replace(/scalePx2dp\((\d+)\)/, '$1') : fontSize + const size = + typeof fontSize === 'string' + ? fontSize.replace(/scalePx2dp\((\d+)\)/, '$1') + : fontSize lineHeight = size * tokenStream.lastValue } else { lineHeight = tokenStream.expect(LENGTH, UNSUPPORTED_LENGTH_UNIT) diff --git a/packages/css-to-react-native/src/css-to-react-native/transforms/index.js b/packages/css-to-react-native/src/css-to-react-native/transforms/index.js index e55f52e9d72a..078e464dd9f1 100644 --- a/packages/css-to-react-native/src/css-to-react-native/transforms/index.js +++ b/packages/css-to-react-native/src/css-to-react-native/transforms/index.js @@ -1,45 +1,47 @@ import { regExpToken, tokens } from '../tokenTypes' +import { + border, + borderBottom, + borderColor, + borderLeft, + borderRadius, + borderRight, + borderTop, + borderWidth, +} from './border' import boxShadow from './boxShadow' import flex from './flex' import font from './font' import fontFamily from './fontFamily' -import textShadow from './textShadow' import textDecoration from './textDecoration' import textDecorationLine from './textDecorationLine' +import textShadow from './textShadow' import transform from './transform' -import { border, borderTop, borderRight, borderBottom, borderLeft, borderColor, borderRadius, borderWidth } from './border' -import { directionFactory, anyOrderFactory, shadowOffsetFactory } from './util' +import { anyOrderFactory, directionFactory, shadowOffsetFactory } from './util' -const { - IDENT, - WORD, - COLOR, - LENGTH, - UNSUPPORTED_LENGTH_UNIT, - PERCENT, - AUTO -} = tokens +const { IDENT, WORD, COLOR, LENGTH, UNSUPPORTED_LENGTH_UNIT, PERCENT, AUTO } = + tokens -const background = tokenStream => ({ - $merge: { backgroundColor: tokenStream.expect(COLOR) } +const background = (tokenStream) => ({ + $merge: { backgroundColor: tokenStream.expect(COLOR) }, }) const margin = directionFactory({ types: [LENGTH, UNSUPPORTED_LENGTH_UNIT, PERCENT, AUTO], - prefix: 'margin' + prefix: 'margin', }) const padding = directionFactory({ prefix: 'padding' }) const flexFlow = anyOrderFactory({ flexWrap: { tokens: [regExpToken(/(nowrap|wrap|wrap-reverse)/)], - default: 'nowrap' + default: 'nowrap', }, flexDirection: { tokens: [regExpToken(/(row|row-reverse|column|column-reverse)/)], - default: 'row' - } + default: 'row', + }, }) -const fontVariant = tokenStream => [tokenStream.expect(IDENT)] -const fontWeight = tokenStream => tokenStream.expect(WORD) // Also match numbers as strings +const fontVariant = (tokenStream) => [tokenStream.expect(IDENT)] +const fontWeight = (tokenStream) => tokenStream.expect(WORD) // Also match numbers as strings const shadowOffset = shadowOffsetFactory() const textShadowOffset = shadowOffsetFactory() @@ -67,5 +69,5 @@ export default { textShadowOffset, textDecoration, textDecorationLine, - transform + transform, } diff --git a/packages/css-to-react-native/src/index.js b/packages/css-to-react-native/src/index.js index 9f244b2f9cbb..79ecd12bee01 100644 --- a/packages/css-to-react-native/src/index.js +++ b/packages/css-to-react-native/src/index.js @@ -4,7 +4,7 @@ import mediaQuery from 'css-mediaquery' import transformCSS from './css-to-react-native' import { dimensionFeatures, - mediaQueryFeatures + mediaQueryFeatures, } from './transforms/media-queries/features' import { mediaQueryTypes } from './transforms/media-queries/types' import { remToPx } from './transforms/rem' @@ -16,12 +16,13 @@ import { values } from './utils/values' const lengthRe = /^(0$|(?:[+-]?(?:\d*\.)?\d+(?:[Ee][+-]?\d+)?)(?=px|rem$))/ const viewportUnitRe = /^([+-]?[0-9.]+)(vh|vw|vmin|vmax)$/ const percentRe = /^([+-]?(?:\d*\.)?\d+(?:[Ee][+-]?\d+)?%)$/ -const unsupportedUnitRe = /^([+-]?(?:\d*\.)?\d+(?:[Ee][+-]?\d+)?(ch|em|ex|cm|mm|in|pc|pt))$/ +const unsupportedUnitRe = + /^([+-]?(?:\d*\.)?\d+(?:[Ee][+-]?\d+)?(ch|em|ex|cm|mm|in|pc|pt))$/ const shorthandBorderProps = [ 'border-radius', 'border-width', 'border-color', - 'border-style' + 'border-style', ] const transformDecls = (styles, declarations, result, options = {}) => { @@ -104,7 +105,7 @@ const transform = (css, options) => { if (isAlreadyDefinedAsClass) { throw new Error( - `Failed to parse :export block because a CSS class in the same file is already using the name "${property}"` + `Failed to parse :export block because a CSS class in the same file is already using the name "${property}"`, ) } @@ -137,12 +138,12 @@ const transform = (css, options) => { ) { const parsed = mediaQuery.parse(rule.media) - parsed.forEach(mq => { + parsed.forEach((mq) => { if (mediaQueryTypes.indexOf(mq.type) === -1) { throw new Error(`Failed to parse media query type "${mq.type}"`) } - mq.expressions.forEach(e => { + mq.expressions.forEach((e) => { const mf = e.modifier ? `${e.modifier}-${e.feature}` : e.feature const val = e.value ? `: ${e.value}` : '' @@ -155,7 +156,7 @@ const transform = (css, options) => { lengthRe.test(e.value) === false ) { throw new Error( - `Failed to parse media query expression "(${mf}${val})"` + `Failed to parse media query expression "(${mf}${val})"`, ) } }) @@ -187,8 +188,6 @@ const transform = (css, options) => { return result } -export { - transformCSS -} +export { transformCSS } export default transform diff --git a/packages/css-to-react-native/src/utils/camelCase.js b/packages/css-to-react-native/src/utils/camelCase.js index 617790472011..621c77733eb4 100644 --- a/packages/css-to-react-native/src/utils/camelCase.js +++ b/packages/css-to-react-native/src/utils/camelCase.js @@ -7,7 +7,7 @@ export function camelCase (str) { .replace(/[-_]+/g, ' ') // Removes any non alphanumeric characters .replace(/[^\w\s]/g, '') - // Uppercases the first character in each group immediately following a space + // Uppercase the first character in each group immediately following a space // (delimited by spaces) .replace(/ (.)/g, function ($1) { return $1.toUpperCase() diff --git a/packages/eslint-config-taro/package.json b/packages/eslint-config-taro/package.json index dea5f3e7df66..a5129a80cb24 100644 --- a/packages/eslint-config-taro/package.json +++ b/packages/eslint-config-taro/package.json @@ -1,6 +1,6 @@ { "name": "eslint-config-taro", - "version": "3.5.0-beta.4", + "version": "3.5.0-theta.1", "description": "Taro specific linting rules for ESLint", "main": "index.js", "files": [ diff --git a/packages/postcss-html-transform/package.json b/packages/postcss-html-transform/package.json index 118af76349e2..8d24760852dd 100644 --- a/packages/postcss-html-transform/package.json +++ b/packages/postcss-html-transform/package.json @@ -1,6 +1,6 @@ { "name": "postcss-html-transform", - "version": "3.5.0-beta.4", + "version": "3.5.0-theta.1", "description": "transform html tag name selector", "main": "index.js", "author": "drchan", diff --git a/packages/postcss-plugin-constparse/package.json b/packages/postcss-plugin-constparse/package.json index 2ad702e3a0c6..ee86e3781e9f 100644 --- a/packages/postcss-plugin-constparse/package.json +++ b/packages/postcss-plugin-constparse/package.json @@ -1,6 +1,6 @@ { "name": "postcss-plugin-constparse", - "version": "3.5.0-beta.4", + "version": "3.5.0-theta.1", "description": "parse constants defined in config", "main": "index.js", "author": "Simba", diff --git a/packages/postcss-pxtransform/__tests__/index.test.js b/packages/postcss-pxtransform/__tests__/index.test.js index 4a2c1efd5ea7..5b1c7e7ea563 100644 --- a/packages/postcss-pxtransform/__tests__/index.test.js +++ b/packages/postcss-pxtransform/__tests__/index.test.js @@ -1,10 +1,3 @@ -// Jasmine unit tests -// To run tests, run these commands from the project root: -// 1. `npm install -g jasmine-node` -// 2. `jasmine-node spec` - -/* global describe, it, expect */ - 'use strict' const postcss = require('postcss') const px2rem = require('../index') @@ -15,7 +8,7 @@ const filterPropList = require('../lib/filter-prop-list') describe('px2rem', function () { it('1 should work on the readme example', function () { const input = 'h1 { margin: 0 0 20px; font-size: 32px; line-height: 1.2; letter-spacing: 1px; }' - const output = 'h1 { margin: 0 0 0.5rem; font-size: 0.8rem; line-height: 1.2; letter-spacing: 0.025rem; }' + const output = 'h1 { margin: 0 0 0.585rem; font-size: 0.936rem; line-height: 1.2; letter-spacing: 0.02925rem; }' const processed = postcss(px2rem({ platform: 'h5', designWidth: 640 })) .process(input).css @@ -25,7 +18,7 @@ describe('px2rem', function () { it('2 should replace the px unit with rem', function () { const processed = postcss(px2rem({ platform: 'h5', designWidth: 640 })) .process(basicCSS).css - const expected = '.rule { font-size: 0.375rem }' + const expected = '.rule { font-size: 0.43875rem }' expect(processed).toBe(expected) }) @@ -41,7 +34,7 @@ describe('px2rem', function () { it('4 should handle < 1 values and values without a leading 0 - legacy', function () { const rules = '.rule { margin: 0.5rem .5px -0.2px -.2em }' - const expected = '.rule { margin: 0.5rem 0.0125rem -0.005rem -.2em }' + const expected = '.rule { margin: 0.5rem 0.01463rem -0.00585rem -.2em }' const options = { platform: 'h5', designWidth: 640, @@ -54,7 +47,7 @@ describe('px2rem', function () { it('5 should handle < 1 values and values without a leading 0', function () { const rules = '.rule { margin: 0.5rem .5px -0.2px -.2em }' - const expected = '.rule { margin: 0.5rem 0.0125rem -0.005rem -.2em }' + const expected = '.rule { margin: 0.5rem 0.01463rem -0.00585rem -.2em }' const options = { platform: 'h5', designWidth: 640, @@ -67,7 +60,7 @@ describe('px2rem', function () { it('6 should not add properties that already exist', function () { const expected = '.rule { font-size: 40px; font-size: 1rem; }' - const processed = postcss(px2rem({ platform: 'h5', designWidth: 640 })) + const processed = postcss(px2rem({ platform: 'h5', designWidth: 750 })) .process(expected).css expect(processed).toBe(expected) @@ -90,7 +83,7 @@ describe('value parsing', function () { // propWhiteList: [] } const rules = '.rule { content: \'16px\'; font-family: "16px"; font-size: 16px; }' - const expected = '.rule { content: \'16px\'; font-family: "16px"; font-size: 0.4rem; }' + const expected = '.rule { content: \'16px\'; font-family: "16px"; font-size: 0.468rem; }' const processed = postcss(px2rem(options)).process(rules).css expect(processed).toBe(expected) @@ -104,7 +97,7 @@ describe('value parsing', function () { propList: ['*'] } const rules = '.rule { content: \'16px\'; font-family: "16px"; font-size: 16px; }' - const expected = '.rule { content: \'16px\'; font-family: "16px"; font-size: 0.4rem; }' + const expected = '.rule { content: \'16px\'; font-family: "16px"; font-size: 0.468rem; }' const processed = postcss(px2rem(options)).process(rules).css expect(processed).toBe(expected) @@ -117,7 +110,7 @@ describe('value parsing', function () { // propWhiteList: [] } const rules = '.rule { background: url(16px.jpg); font-size: 16px; }' - const expected = '.rule { background: url(16px.jpg); font-size: 0.4rem; }' + const expected = '.rule { background: url(16px.jpg); font-size: 0.468rem; }' const processed = postcss(px2rem(options)).process(rules).css expect(processed).toBe(expected) @@ -130,7 +123,7 @@ describe('value parsing', function () { propList: ['*'] } const rules = '.rule { background: url(16px.jpg); font-size: 16px; }' - const expected = '.rule { background: url(16px.jpg); font-size: 0.4rem; }' + const expected = '.rule { background: url(16px.jpg); font-size: 0.468rem; }' const processed = postcss(px2rem(options)).process(rules).css expect(processed).toBe(expected) @@ -143,7 +136,7 @@ describe('value parsing', function () { propList: ['*'] } const rules = '.rule { margin: 12px calc(100% - 14PX); height: calc(100% - 20px); font-size: 12Px; line-height: 16px; }' - const expected = '.rule { margin: 0.3rem calc(100% - 14PX); height: calc(100% - 0.5rem); font-size: 12Px; line-height: 0.4rem; }' + const expected = '.rule { margin: 0.351rem calc(100% - 14PX); height: calc(100% - 0.585rem); font-size: 12Px; line-height: 0.468rem; }' const processed = postcss(px2rem(options)).process(rules).css expect(processed).toBe(expected) @@ -153,7 +146,7 @@ describe('value parsing', function () { describe('unitPrecision', function () { // Deprecate it('1 should replace using a decimal of 2 places - legacy', function () { - const expected = '.rule { font-size: 0.38rem }' + const expected = '.rule { font-size: 0.44rem }' const options = { platform: 'h5', designWidth: 640, @@ -165,7 +158,7 @@ describe('unitPrecision', function () { }) it('2 should replace using a decimal of 2 places', function () { - const expected = '.rule { font-size: 0.38rem }' + const expected = '.rule { font-size: 0.44rem }' const options = { platform: 'h5', designWidth: 640, @@ -208,7 +201,7 @@ describe('propWhiteList', function () { it('5 should only replace properties in the white list - legacy', function () { const css = '.rule { margin: 16px; margin-left: 10px }' - const expected = '.rule { margin: 0.4rem; margin-left: 10px }' + const expected = '.rule { margin: 0.468rem; margin-left: 10px }' const options = { platform: 'h5', designWidth: 640, @@ -221,7 +214,7 @@ describe('propWhiteList', function () { it('6 should only replace properties in the prop list', function () { const css = '.rule { font-size: 16px; margin: 16px; margin-left: 5px; padding: 5px; padding-right: 16px }' - const expected = '.rule { font-size: 0.4rem; margin: 0.4rem; margin-left: 5px; padding: 5px; padding-right: 0.4rem }' + const expected = '.rule { font-size: 0.468rem; margin: 0.468rem; margin-left: 5px; padding: 5px; padding-right: 0.468rem }' const options = { platform: 'h5', designWidth: 640, @@ -235,7 +228,7 @@ describe('propWhiteList', function () { it('7 should only replace properties in the prop list with wildcard', function () { const css = '.rule { font-size: 16px; margin: 16px; margin-left: 5px; padding: 5px; padding-right: 16px }' - const expected = '.rule { font-size: 16px; margin: 0.4rem; margin-left: 5px; padding: 5px; padding-right: 16px }' + const expected = '.rule { font-size: 16px; margin: 0.468rem; margin-left: 5px; padding: 5px; padding-right: 16px }' const options = { platform: 'h5', designWidth: 640, @@ -248,7 +241,7 @@ describe('propWhiteList', function () { it('8 should replace all properties when white list is empty', function () { const rules = '.rule { margin: 16px; font-size: 15px }' - const expected = '.rule { margin: 0.4rem; font-size: 0.375rem }' + const expected = '.rule { margin: 0.468rem; font-size: 0.43875rem }' const options = { platform: 'h5', designWidth: 640 @@ -265,7 +258,7 @@ describe('selectorBlackList', function () { it('1 should ignore selectors in the selector black list - legacy', function () { const rules = '.rule { font-size: 15px } .rule2 { font-size: 15px }' - const expected = '.rule { font-size: 0.375rem } .rule2 { font-size: 15px }' + const expected = '.rule { font-size: 0.43875rem } .rule2 { font-size: 15px }' const options = { platform: 'h5', designWidth: 640, @@ -278,7 +271,7 @@ describe('selectorBlackList', function () { it('2 should ignore selectors in the selector black list', function () { const rules = '.rule { font-size: 15px } .rule2 { font-size: 15px }' - const expected = '.rule { font-size: 0.375rem } .rule2 { font-size: 15px }' + const expected = '.rule { font-size: 0.43875rem } .rule2 { font-size: 15px }' const options = { platform: 'h5', designWidth: 640, @@ -291,7 +284,7 @@ describe('selectorBlackList', function () { it('3 should ignore every selector with `body$`', function () { const rules = 'body { font-size: 16px; } .class-body$ { font-size: 16px; } .simple-class { font-size: 16px; }' - const expected = 'body { font-size: 0.4rem; } .class-body$ { font-size: 16px; } .simple-class { font-size: 0.4rem; }' + const expected = 'body { font-size: 0.468rem; } .class-body$ { font-size: 16px; } .simple-class { font-size: 0.468rem; }' const options = { platform: 'h5', designWidth: 640, @@ -304,7 +297,7 @@ describe('selectorBlackList', function () { it('4 should only ignore exactly `body`', function () { const rules = 'body { font-size: 16px; } .class-body { font-size: 16px; } .simple-class { font-size: 16px; }' - const expected = 'body { font-size: 16px; } .class-body { font-size: 0.4rem; } .simple-class { font-size: 0.4rem; }' + const expected = 'body { font-size: 16px; } .class-body { font-size: 0.468rem; } .simple-class { font-size: 0.468rem; }' const options = { platform: 'h5', designWidth: 640, @@ -324,7 +317,7 @@ describe('replace', function () { replace: false } const processed = postcss(px2rem(options)).process(basicCSS).css - const expected = '.rule { font-size: 15px; font-size: 0.375rem }' + const expected = '.rule { font-size: 15px; font-size: 0.43875rem }' expect(processed).toBe(expected) }) @@ -340,7 +333,7 @@ describe('mediaQuery', function () { } const processed = postcss(px2rem(options)) .process('@media (min-width: 500px) { .rule { font-size: 16px } }').css - const expected = '@media (min-width: 12.5rem) { .rule { font-size: 0.4rem } }' + const expected = '@media (min-width: 14.625rem) { .rule { font-size: 0.468rem } }' expect(processed).toBe(expected) }) @@ -353,7 +346,7 @@ describe('mediaQuery', function () { } const processed = postcss(px2rem(options)) .process('@media (min-width: 500px) { .rule { font-size: 16px } }').css - const expected = '@media (min-width: 12.5rem) { .rule { font-size: 0.4rem } }' + const expected = '@media (min-width: 14.625rem) { .rule { font-size: 0.468rem } }' expect(processed).toBe(expected) }) @@ -368,7 +361,7 @@ describe('minPixelValue', function () { minPixelValue: 2 } const rules = '.rule { border: 1px solid #000; font-size: 16px; margin: 1px 10px; }' - const expected = '.rule { border: 1px solid #000; font-size: 0.4rem; margin: 1px 0.25rem; }' + const expected = '.rule { border: 1px solid #000; font-size: 0.468rem; margin: 1px 0.2925rem; }' const processed = postcss(px2rem(options)).process(rules).css expect(processed).toBe(expected) @@ -538,7 +531,7 @@ describe('platform 为 h5', () => { it('{platform: \'h5\', designWidth: 640} ', () => { const rules = 'h1 {margin: 0 0 20px;font-size: 40Px;line-height: 1.2;}' - const expected = 'h1 {margin: 0 0 0.5rem;font-size: 40Px;line-height: 1.2;}' + const expected = 'h1 {margin: 0 0 0.585rem;font-size: 40Px;line-height: 1.2;}' const options = { platform: 'h5', designWidth: 640 @@ -637,6 +630,6 @@ describe('rpx 单位转换', () => { designWidth: 640 } const processed = postcss(px2rem(options)).process(rules).css - expect(processed).toBe('h1 {margin: 0 0 0.5rem;font-size: 40Px;line-height: 1.2;} .test{}') + expect(processed).toBe('h1 {margin: 0 0 0.585rem;font-size: 40Px;line-height: 1.2;} .test{}') }) }) diff --git a/packages/postcss-pxtransform/index.js b/packages/postcss-pxtransform/index.js index f332513a4162..03a8a25d52ce 100644 --- a/packages/postcss-pxtransform/index.js +++ b/packages/postcss-pxtransform/index.js @@ -41,17 +41,13 @@ module.exports = postcss.plugin('postcss-pxtransform', function (options = {}) { options = Object.assign({}, DEFAULT_WEAPP_OPTIONS, options) const transUnits = ['px'] - const baseFontSize = options.baseFontSize ?? options.mix >= 1 ? options.mix : 20 + const baseFontSize = options.baseFontSize ?? options.minRootSize >= 1 ? options.minRootSize : 20 const designWidth = input => typeof options.designWidth === 'function' ? options.designWidth(input) : options.designWidth switch (options.platform) { case 'h5': { - options.rootValue = input => { - const rv = 1 / options.deviceRatio[designWidth(input)] * baseFontSize - const val = Math.max(Math.min(rv, options.max ?? 40), options.mix ?? 20) - return val * 2 - } + options.rootValue = input => baseFontSize / options.deviceRatio[designWidth(input)] * 2 targetUnit = 'rem' transUnits.push('rpx') break diff --git a/packages/postcss-pxtransform/package.json b/packages/postcss-pxtransform/package.json index f99757e036cd..a71d65e54f3c 100644 --- a/packages/postcss-pxtransform/package.json +++ b/packages/postcss-pxtransform/package.json @@ -1,6 +1,6 @@ { "name": "postcss-pxtransform", - "version": "3.5.0-beta.4", + "version": "3.5.0-theta.1", "description": "PostCSS plugin px 转小程序 rpx及h5 rem 单位", "keywords": [ "postcss", diff --git a/packages/shared/package.json b/packages/shared/package.json index 3334568c39a2..cff9d6702e36 100644 --- a/packages/shared/package.json +++ b/packages/shared/package.json @@ -1,6 +1,6 @@ { "name": "@tarojs/shared", - "version": "3.5.0-beta.4", + "version": "3.5.0-theta.1", "description": "> TODO: description", "author": "yuche ", "homepage": "https://github.com/nervjs/taro/tree/master/packages/shared#readme", diff --git a/packages/shared/rollup.config.js b/packages/shared/rollup.config.js index 9077aeea76e2..b5fa2e0022f2 100644 --- a/packages/shared/rollup.config.js +++ b/packages/shared/rollup.config.js @@ -1,4 +1,4 @@ -import typescript from 'rollup-plugin-typescript2' +import ts from 'rollup-plugin-ts' const { join } = require('path') @@ -15,23 +15,22 @@ const baseConfig = { } ], plugins: [ - typescript({ - tsconfigOverride: { - compilerOptions: { - preserveConstEnums: true - } - } + ts({ + tsconfig: config => ({ + ...config, + preserveConstEnums: true + }) }) ] } const esmConfig = Object.assign({}, baseConfig, { - output: Object.assign({}, baseConfig.output, { + output: Object.assign({}, baseConfig.output[0], { sourcemap: true, format: 'es', file: join(cwd, 'dist/shared.esm.js') }), plugins: [ - typescript() + ts() ] }) @@ -47,7 +46,7 @@ const templateConfig = { } ], plugins: [ - typescript() + ts() ] } diff --git a/packages/shared/src/native-apis.ts b/packages/shared/src/native-apis.ts index 16df3afc2c1e..8f761d38c009 100644 --- a/packages/shared/src/native-apis.ts +++ b/packages/shared/src/native-apis.ts @@ -11,7 +11,7 @@ interface IProcessApisIOptions { noPromiseApis?: Set needPromiseApis?: Set handleSyncApis?: (key: string, global: IObject, args: any[]) => any - transformMeta?: (key: string, options: IObject) => { key: string, options: IObject }, + transformMeta?: (key: string, options: IObject) => { key: string, options: IObject } modifyApis?: (apis: Set) => void modifyAsyncResult?: (key: string, res) => void isOnlyPromisify?: boolean diff --git a/packages/shared/tsconfig.json b/packages/shared/tsconfig.json index fe84709ac041..7efe141edb14 100644 --- a/packages/shared/tsconfig.json +++ b/packages/shared/tsconfig.json @@ -2,12 +2,10 @@ "extends": "../../tsconfig.root.json", "compilerOptions": { "baseUrl": ".", - "outDir": "lib", + "outDir": "dist", "module": "ESNext", "declaration": true, "sourceMap": true }, - "include": [ - "src" - ] + "include": ["src"] } diff --git a/packages/stylelint-config-taro-rn/package.json b/packages/stylelint-config-taro-rn/package.json index f671f1770bd2..628b7cbdfa6c 100644 --- a/packages/stylelint-config-taro-rn/package.json +++ b/packages/stylelint-config-taro-rn/package.json @@ -1,6 +1,6 @@ { "name": "stylelint-config-taro-rn", - "version": "3.5.0-beta.4", + "version": "3.5.0-theta.1", "description": "Shareable stylelint config for React Native CSS modules", "main": "index.js", "files": [ diff --git a/packages/stylelint-taro-rn/package.json b/packages/stylelint-taro-rn/package.json index 18c392f78a2f..116cefe89b7d 100644 --- a/packages/stylelint-taro-rn/package.json +++ b/packages/stylelint-taro-rn/package.json @@ -1,7 +1,7 @@ { "name": "stylelint-taro-rn", "description": "A collection of React Native specific rules for stylelint", - "version": "3.5.0-beta.4", + "version": "3.5.0-theta.1", "main": "dist/index.js", "files": [ "dist", @@ -59,17 +59,6 @@ ], "testRegex": ".*\\.test\\.js$|src/.*/__tests__/.*\\.js$" }, - "lint-staged": { - "**/*.{js,json,md}": [ - "prettier --write", - "git add" - ] - }, - "prettier": { - "semi": true, - "singleQuote": false, - "trailingComma": "none" - }, "dependencies": { "react-native-known-styling-properties": "^1.0.4" } diff --git a/packages/stylelint-taro-rn/src/index.js b/packages/stylelint-taro-rn/src/index.js index 51ef402f778b..0d929caecfab 100644 --- a/packages/stylelint-taro-rn/src/index.js +++ b/packages/stylelint-taro-rn/src/index.js @@ -1,8 +1,9 @@ import { createPlugin } from 'stylelint' -import { namespace } from './utils' + import rules from './rules' +import { namespace } from './utils' -const rulesPlugins = Object.keys(rules).map(ruleName => { +const rulesPlugins = Object.keys(rules).map((ruleName) => { return createPlugin(namespace(ruleName), rules[ruleName]) }) 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 d32541bc791e..24b3879aeb5f 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,6 @@ import { allCSS2RNProps } from 'react-native-known-styling-properties' import { utils } from 'stylelint' + import { isCustomProperty, isExportBlock, @@ -14,7 +15,7 @@ import { export const ruleName = namespace('css-property-no-unknown') export const messages = utils.ruleMessages(ruleName, { - rejected: property => `无效的 React Native 样式属性 "${property}"` + rejected: (property) => `无效的 React Native 样式属性 "${property}"` }) const props = allCSS2RNProps.map(kebabCase) @@ -40,7 +41,7 @@ export default function (actual, options) { return } - root.walkDecls(decl => { + root.walkDecls((decl) => { const prop = decl.prop if (!isStandardSyntaxProperty(prop)) { 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 b786e8911dd9..7eeea55b0d52 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,4 +1,5 @@ import { utils } from 'stylelint' + import { namespace } from '../../utils' const declarationValueIndex = require('stylelint/lib/utils/declarationValueIndex') @@ -6,7 +7,7 @@ const declarationValueIndex = require('stylelint/lib/utils/declarationValueIndex export const ruleName = namespace('font-weight-no-ignored-values') export const messages = utils.ruleMessages(ruleName, { - rejected: weight => `Unexpected font-weight "${weight}"` + rejected: (weight) => `Unexpected font-weight "${weight}"` }) const acceptedWeights = ['400', '700', 'normal', 'bold'] @@ -21,7 +22,7 @@ export default function (actual) { return } - root.walkDecls(/^font-weight$/i, decl => { + root.walkDecls(/^font-weight$/i, (decl) => { if (acceptedWeights.indexOf(decl.value) > -1) { return } diff --git a/packages/stylelint-taro-rn/src/rules/index.js b/packages/stylelint-taro-rn/src/rules/index.js index 5f0dffdb8348..c16ad8abab91 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 stylePropertyNoUnknown from './style-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' export default { 'font-weight-no-ignored-values': fontWeightNoIgnoredValues, 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 4f08e6414552..80bd6548e474 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,4 +1,5 @@ import { utils } from 'stylelint' + import { namespace } from '../../utils' const declarationValueIndex = require('stylelint/lib/utils/declarationValueIndex') @@ -6,7 +7,8 @@ const declarationValueIndex = require('stylelint/lib/utils/declarationValueIndex export const ruleName = namespace('line-height-no-value-without-unit') export const messages = utils.ruleMessages(ruleName, { - rejected: height => `Unexpected line-height "${height}", expect a value with units` + rejected: (height) => + `Unexpected line-height "${height}", expect a value with units` }) const lengthRe = /^(0$|(?:[+-]?(?:\d*\.)?\d+(?:[Ee][+-]?\d+)?)(?=px|PX|rem$))/ @@ -22,11 +24,8 @@ export default function (actual) { return } - root.walkDecls(/^line-height$/i, decl => { - if ( - lengthRe.test(decl.value) || - viewportUnitRe.test(decl.value) - ) { + root.walkDecls(/^line-height$/i, (decl) => { + if (lengthRe.test(decl.value) || viewportUnitRe.test(decl.value)) { return } 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 9e732b611ee9..b7eb41d2e9b0 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,19 +1,20 @@ -import { utils } from 'stylelint' import { allProps } from 'react-native-known-styling-properties' +import { utils } from 'stylelint' + import { - kebabCase, - namespace, - isString, isCustomProperty, - isStandardSyntaxProperty, isStandardSyntaxDeclaration, + isStandardSyntaxProperty, + isString, + kebabCase, + namespace, optionsMatches } from '../../utils' export const ruleName = namespace('style-property-no-unknown') export const messages = utils.ruleMessages(ruleName, { - rejected: property => `无效的 React Native 样式属性 "${property}"` + rejected: (property) => `无效的 React Native 样式属性 "${property}"` }) const props = allProps.map(kebabCase) @@ -39,7 +40,7 @@ export default function (actual, options) { return } - root.walkDecls(decl => { + root.walkDecls((decl) => { const prop = decl.prop if (!isStandardSyntaxProperty(prop)) { diff --git a/packages/taro-alipay/index.js b/packages/taro-alipay/index.js index d347cc7109f9..ff96873bec61 100644 --- a/packages/taro-alipay/index.js +++ b/packages/taro-alipay/index.js @@ -1,3 +1,4 @@ module.exports = require('./dist/index.js').default + module.exports.default = module.exports module.exports.Alipay = require('./dist/index.js').Alipay diff --git a/packages/taro-alipay/package.json b/packages/taro-alipay/package.json index ecb1fd55c0a6..66346b6cb539 100644 --- a/packages/taro-alipay/package.json +++ b/packages/taro-alipay/package.json @@ -1,6 +1,6 @@ { "name": "@tarojs/plugin-platform-alipay", - "version": "3.5.0-beta.4", + "version": "3.5.0-theta.1", "description": "支付宝小程序平台插件", "author": "Chen-jj", "homepage": "https://github.com/nervjs/taro/tree/master/packages/taro-alipay#readme", @@ -27,8 +27,8 @@ "url": "https://github.com/NervJS/taro/issues" }, "dependencies": { - "@tarojs/components": "3.5.0-beta.4", - "@tarojs/service": "3.5.0-beta.4", - "@tarojs/shared": "3.5.0-beta.4" + "@tarojs/components": "workspace:*", + "@tarojs/service": "workspace:*", + "@tarojs/shared": "workspace:*" } } diff --git a/packages/taro-alipay/rollup.config.js b/packages/taro-alipay/rollup.config.js index 76800170fe4f..8b09a0aafa99 100644 --- a/packages/taro-alipay/rollup.config.js +++ b/packages/taro-alipay/rollup.config.js @@ -1,17 +1,15 @@ -import typescript from 'rollup-plugin-typescript2' import * as path from 'path' +import ts from 'rollup-plugin-ts' const cwd = __dirname const base = { external: ['@tarojs/shared', '@tarojs/service'], - plugins: [typescript({ - useTsconfigDeclarationDir: true - })] + plugins: [ts()] } // 供 CLI 编译时使用的 Taro 插件入口 -const comileConfig = { +const compileConfig = { input: path.join(cwd, 'src/index.ts'), output: { file: path.join(cwd, 'dist/index.js'), @@ -55,4 +53,4 @@ const otherConfig = { ...base } -module.exports = [comileConfig, runtimeConfig, runtimeUtilsConfig, otherConfig] +module.exports = [compileConfig, runtimeConfig, runtimeUtilsConfig, otherConfig] diff --git a/packages/taro-alipay/src/apis.ts b/packages/taro-alipay/src/apis.ts index 7f3d4c90d128..fb62f5a5cdcf 100644 --- a/packages/taro-alipay/src/apis.ts +++ b/packages/taro-alipay/src/apis.ts @@ -1,4 +1,5 @@ import { processApis } from '@tarojs/shared' + import { needPromiseApis } from './apis-list' declare const my: any diff --git a/packages/taro-alipay/src/program.ts b/packages/taro-alipay/src/program.ts index 63bdb6b6fb0d..ef616e4d2036 100644 --- a/packages/taro-alipay/src/program.ts +++ b/packages/taro-alipay/src/program.ts @@ -1,6 +1,7 @@ import { TaroPlatformBase } from '@tarojs/service' -import { Template } from './template' + import { components } from './components' +import { Template } from './template' const PACKAGE_NAME = '@tarojs/plugin-platform-alipay' diff --git a/packages/taro-alipay/src/runtime-utils.ts b/packages/taro-alipay/src/runtime-utils.ts index f245558ff8df..a2cd17b1ecd8 100644 --- a/packages/taro-alipay/src/runtime-utils.ts +++ b/packages/taro-alipay/src/runtime-utils.ts @@ -1,11 +1,11 @@ import { - initNativeApi, handleSyncApis, - transformMeta, + initNativeApi, modifyApis, modifyAsyncResult, - request + request, + transformMeta } from './apis' declare const my: any @@ -20,15 +20,15 @@ const BUBBLE_EVENTS = new Set([ ]) export { - initNativeApi, handleSyncApis, - transformMeta, + initNativeApi, modifyApis, modifyAsyncResult, - request + request, + transformMeta } -export * from './components' export * from './apis-list' +export * from './components' export const hostConfig = { initNativeApi, getEventCenter (Events) { diff --git a/packages/taro-alipay/src/runtime.ts b/packages/taro-alipay/src/runtime.ts index a106709f3fba..e7cd4acf7b87 100644 --- a/packages/taro-alipay/src/runtime.ts +++ b/packages/taro-alipay/src/runtime.ts @@ -1,5 +1,6 @@ -import { mergeReconciler, mergeInternalComponents } from '@tarojs/shared' -import { hostConfig, components } from './runtime-utils' +import { mergeInternalComponents, mergeReconciler } from '@tarojs/shared' + +import { components, hostConfig } from './runtime-utils' // 支付宝真机只有 navigator.swuserAgent const { userAgent } = navigator diff --git a/packages/taro-api/package.json b/packages/taro-api/package.json index fce0057fcdff..bd4ce72876cc 100644 --- a/packages/taro-api/package.json +++ b/packages/taro-api/package.json @@ -1,6 +1,6 @@ { "name": "@tarojs/api", - "version": "3.5.0-beta.4", + "version": "3.5.0-theta.1", "description": "Taro common API", "author": "yuche ", "homepage": "https://github.com/nervjs/taro/tree/master/packages/api#readme", @@ -30,6 +30,6 @@ }, "dependencies": { "@babel/runtime": "^7.14.5", - "@tarojs/runtime": "3.5.0-beta.4" + "@tarojs/runtime": "workspace:*" } } diff --git a/packages/taro-cli/package.json b/packages/taro-cli/package.json index c47ab6e6e955..6f9ac277d40d 100644 --- a/packages/taro-cli/package.json +++ b/packages/taro-cli/package.json @@ -1,6 +1,6 @@ { "name": "@tarojs/cli", - "version": "3.5.0-beta.4", + "version": "3.5.0-theta.1", "description": "cli tool for taro", "main": "index.js", "scripts": { @@ -9,7 +9,7 @@ "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": "npm run clean && npm run prod", + "build": "pnpm run clean && pnpm run prod", "dev": "tsc -w", "prod": "tsc", "clean": "rimraf dist" @@ -44,10 +44,10 @@ "@babel/template": "^7.14.5", "@babel/traverse": "^7.14.5", "@babel/types": "^7.14.5", - "@tarojs/helper": "3.5.0-beta.4", - "@tarojs/service": "3.5.0-beta.4", - "@tarojs/shared": "3.5.0-beta.4", - "@tarojs/taroize": "3.5.0-beta.4", + "@tarojs/helper": "workspace:*", + "@tarojs/service": "workspace:*", + "@tarojs/shared": "workspace:*", + "@tarojs/taroize": "workspace:*", "@tarojs/transformer-wx": "^2.0.4", "adm-zip": "^0.4.13", "babylon": "^6.18.0", @@ -71,8 +71,9 @@ "postcss": "^6.0.22", "postcss-taro-unit-transform": "1.2.15", "prettier": "^1.16.4", + "regenerator-runtime": "0.11", "request": "^2.88.0", - "resolve": "^1.6.0", + "resolve": "^1.22.0", "semver": "^5.5.0", "shelljs": "^0.8.1", "tapable": "^1.1.3", diff --git a/packages/taro-cli/src/__tests__/doctor.spec.ts b/packages/taro-cli/src/__tests__/doctor.spec.ts index 9fd495d6a524..1f7caf1cb5c8 100644 --- a/packages/taro-cli/src/__tests__/doctor.spec.ts +++ b/packages/taro-cli/src/__tests__/doctor.spec.ts @@ -1,4 +1,4 @@ -import chalk from 'chalk' +import { chalk } from '@tarojs/helper' import * as path from 'path' import { run } from './utils' diff --git a/packages/taro-cli/src/__tests__/info.spec.ts b/packages/taro-cli/src/__tests__/info.spec.ts index bb1078ffc84e..89def48a44cd 100644 --- a/packages/taro-cli/src/__tests__/info.spec.ts +++ b/packages/taro-cli/src/__tests__/info.spec.ts @@ -1,4 +1,4 @@ -import chalk from 'chalk' +import { chalk } from '@tarojs/helper' import * as path from 'path' import { getPkgVersion } from '../util' diff --git a/packages/taro-cli/src/__tests__/inspect.spec.ts b/packages/taro-cli/src/__tests__/inspect.spec.ts index fb97ba02138d..c1d293092f5b 100644 --- a/packages/taro-cli/src/__tests__/inspect.spec.ts +++ b/packages/taro-cli/src/__tests__/inspect.spec.ts @@ -1,5 +1,4 @@ -import { fs } from '@tarojs/helper' -import chalk from 'chalk' +import { chalk, fs } from '@tarojs/helper' import * as path from 'path' import { run } from './utils' diff --git a/packages/taro-cli/src/convertor/index.ts b/packages/taro-cli/src/convertor/index.ts index 67fa03c3df17..994d1dce8390 100644 --- a/packages/taro-cli/src/convertor/index.ts +++ b/packages/taro-cli/src/convertor/index.ts @@ -41,31 +41,31 @@ const OUTPUT_STYLE_EXTNAME = '.scss' const WX_GLOBAL_FN = new Set(['getApp', 'getCurrentPages', 'requirePlugin', 'Behavior']) interface IComponent { - name: string; - path: string; + name: string + path: string } interface IImport { - ast: t.File; - name: string; - wxs?: boolean; + ast: t.File + name: string + wxs?: boolean } interface IParseAstOptions { - ast: t.File; - sourceFilePath: string; - outputFilePath: string; - importStylePath?: string | null; - depComponents?: Set; - imports?: IImport[]; - isApp?: boolean; + ast: t.File + sourceFilePath: string + outputFilePath: string + importStylePath?: string | null + depComponents?: Set + imports?: IImport[] + isApp?: boolean } interface ITaroizeOptions { - json?: string; - script?: string; - wxml?: string; - path?: string; + json?: string + script?: string + wxml?: string + path?: string rootPath?: string } @@ -158,7 +158,7 @@ export default class Convertor { importStylePath, depComponents, imports = [] - }: IParseAstOptions): { ast: t.File; scriptFiles: Set } { + }: IParseAstOptions): { ast: t.File, scriptFiles: Set } { const scriptFiles = new Set() // eslint-disable-next-line @typescript-eslint/no-this-alias const self = this diff --git a/packages/taro-cli/src/create/creator.ts b/packages/taro-cli/src/create/creator.ts index db47239b6729..922511c4ecad 100644 --- a/packages/taro-cli/src/create/creator.ts +++ b/packages/taro-cli/src/create/creator.ts @@ -7,44 +7,44 @@ import * as path from 'path' import { getRootPath } from '../util' interface IFile { - contents: Buffer | NodeJS.ReadableStream | null; - cwd: string; - base: string | null | undefined; - history: string[]; - relative: string; - dirname: string; - basename: string; - stem: string; - extname: string; - symlink: string; - stat: fs.Stats | null; + contents: Buffer | NodeJS.ReadableStream | null + cwd: string + base: string | null | undefined + history: string[] + relative: string + dirname: string + basename: string + stem: string + extname: string + symlink: string + stat: fs.Stats | null } interface IReadOptions { - raw?: boolean; + raw?: boolean } interface IAppendOptions { - trimEnd?: boolean; - separator?: string; + trimEnd?: boolean + separator?: string } interface IMemFsEditor { store: { - [key: string]: IFile; - }; - read(filePath: string, options?: IReadOptions): string | Buffer; - readJSON(filePath: string, defaults?: JSON): JSON; - write(filePath: string, contents: string | Buffer): string; + [key: string]: IFile + } + read(filePath: string, options?: IReadOptions): string | Buffer + readJSON(filePath: string, defaults?: JSON): JSON + write(filePath: string, contents: string | Buffer): string writeJSON( filepath: string, contents: JSON, replacer?: ((key: string, value: any) => any) | undefined, space?: string | number | undefined - ): string; - append(filePath: string, contents: string | Buffer, options?: IAppendOptions): string | Buffer; - copyTpl(from: string, to: string, context: Record, templateOptions: Record); - commit(cb: () => void); + ): string + append(filePath: string, contents: string | Buffer, options?: IAppendOptions): string | Buffer + copyTpl(from: string, to: string, context: Record, templateOptions: Record) + commit(cb: () => void) } export default class Creator { diff --git a/packages/taro-cli/src/create/editTemplate.ts b/packages/taro-cli/src/create/editTemplate.ts index a3024badf271..ee3bc5fc4c9e 100644 --- a/packages/taro-cli/src/create/editTemplate.ts +++ b/packages/taro-cli/src/create/editTemplate.ts @@ -6,7 +6,7 @@ import { validateProjectName } from './validate' interface PlaceholderConfig { projectName: string - templatePath: string, + templatePath: string projectPath: string } diff --git a/packages/taro-cli/src/create/fetchTemplate.ts b/packages/taro-cli/src/create/fetchTemplate.ts index ddf524d0abd2..af04ce70cc7d 100644 --- a/packages/taro-cli/src/create/fetchTemplate.ts +++ b/packages/taro-cli/src/create/fetchTemplate.ts @@ -10,7 +10,7 @@ import { getTemplateSourceType, readDirWithFileTypes } from '../util' import { TEMPLATE_CREATOR } from './init' export interface ITemplates { - name: string, + name: string platforms?: string | string[] desc?: string } diff --git a/packages/taro-cli/src/doctor/interface.ts b/packages/taro-cli/src/doctor/interface.ts index b07031d3ad58..0d3ffea3349d 100644 --- a/packages/taro-cli/src/doctor/interface.ts +++ b/packages/taro-cli/src/doctor/interface.ts @@ -1,5 +1,5 @@ export interface IErrorLine { - desc: string; - valid: boolean; - solution?: string; + desc: string + valid: boolean + solution?: string } diff --git a/packages/taro-cli/src/presets/commands/build.ts b/packages/taro-cli/src/presets/commands/build.ts index 2f96d34501e4..d65af6077a17 100644 --- a/packages/taro-cli/src/presets/commands/build.ts +++ b/packages/taro-cli/src/presets/commands/build.ts @@ -1,4 +1,4 @@ -import { IPluginContext } from '@tarojs/service' +import type { IPluginContext } from '@tarojs/service' import configValidator from '../../doctor/configValidator' import * as hooks from '../constant' diff --git a/packages/taro-cli/src/presets/commands/update.ts b/packages/taro-cli/src/presets/commands/update.ts index 4119bea0bdae..92591f6db17e 100644 --- a/packages/taro-cli/src/presets/commands/update.ts +++ b/packages/taro-cli/src/presets/commands/update.ts @@ -22,7 +22,7 @@ export default (ctx: IPluginContext) => { }, async fn ({ _, options }) { const { npm } = options - const [, updateType, version] = _ as [string, ('self' | 'project')?, number?] + const [, updateType, version] = _ as [string, ('self' | 'project')?, string?] const { appPath, configPath } = ctx.paths const { chalk, diff --git a/packages/taro-cli/src/util/types.ts b/packages/taro-cli/src/util/types.ts index 0a0e61488af7..b78810a0ec80 100644 --- a/packages/taro-cli/src/util/types.ts +++ b/packages/taro-cli/src/util/types.ts @@ -1,33 +1,33 @@ export interface IInstallOptions { - dev: boolean; - peerDependencies?: boolean; + dev: boolean + peerDependencies?: boolean } export interface INpmConfig { - dir: string; - name: string; + dir: string + name: string } export interface IResolvedCache { [key: string]: { - main: string; - files: string[]; - }; + main: string + files: string[] + } } export interface IPrettierConfig { - printWidth?: number; - tabWidth?: number; - useTabs?: boolean; - semi?: boolean; - singleQuote?: boolean; - jsxSingleQuote?: boolean; - trailingComma?: 'none' | 'es5' | 'all'; - bracketSpacing?: boolean; - jsxBracketSameLine?: boolean; - arrowParens?: 'avoid' | 'always'; - rangeStart?: number; - rangeEnd?: number; + printWidth?: number + tabWidth?: number + useTabs?: boolean + semi?: boolean + singleQuote?: boolean + jsxSingleQuote?: boolean + trailingComma?: 'none' | 'es5' | 'all' + bracketSpacing?: boolean + jsxBracketSameLine?: boolean + arrowParens?: 'avoid' | 'always' + rangeStart?: number + rangeEnd?: number parser?: | 'babel' | 'babylon' @@ -45,37 +45,37 @@ export interface IPrettierConfig { | 'html' | 'vue' | 'angular' - | 'yaml'; - filepath?: string; - requirePragma?: boolean; - insertPragma?: boolean; - proseWrap?: 'always' | 'never' | 'preserve'; - htmlWhitespaceSensitivity?: 'css' | 'strict' | 'ignore'; - endOfLine?: 'auto' | 'lf' | 'crlf' | 'cr'; + | 'yaml' + filepath?: string + requirePragma?: boolean + insertPragma?: boolean + proseWrap?: 'always' | 'never' | 'preserve' + htmlWhitespaceSensitivity?: 'css' | 'strict' | 'ignore' + endOfLine?: 'auto' | 'lf' | 'crlf' | 'cr' } export interface IBuildOptions { - type?: string, - watch?: boolean, - platform?: string, - port?: number, - release?: boolean, - envHasBeenSet?: boolean, - page?: string, - component?: string, + type?: string + watch?: boolean + platform?: string + port?: number + release?: boolean + envHasBeenSet?: boolean + page?: string + component?: string uiIndex?: string } export interface IMiniAppBuildConfig { - adapter: string, - watch?: boolean, - envHasBeenSet?: boolean, - port?: number, - release?: boolean, - page?: string, + adapter: string + watch?: boolean + envHasBeenSet?: boolean + port?: number + release?: boolean + page?: string component?: string } export interface IOption { - [key: string]: any; + [key: string]: any } diff --git a/packages/taro-components-react/package.json b/packages/taro-components-react/package.json index 0cefdec12b9a..5c81bb7f9371 100644 --- a/packages/taro-components-react/package.json +++ b/packages/taro-components-react/package.json @@ -1,6 +1,6 @@ { "name": "@tarojs/components-react", - "version": "3.5.0-beta.4", + "version": "3.5.0-theta.1", "description": "", "main:h5": "src/index.js", "main": "dist/index.js", diff --git a/packages/taro-components-react/rollup.config.js b/packages/taro-components-react/rollup.config.js index d8bb06d76239..2819210d37d0 100644 --- a/packages/taro-components-react/rollup.config.js +++ b/packages/taro-components-react/rollup.config.js @@ -2,7 +2,7 @@ import babel from '@rollup/plugin-babel' import commonjs from '@rollup/plugin-commonjs' import resolve from '@rollup/plugin-node-resolve' import postcss from 'rollup-plugin-postcss' -import typescript from 'rollup-plugin-typescript2' +import ts from 'rollup-plugin-ts' // 供 Loader 使用的运行时入口 export default { @@ -18,7 +18,6 @@ export default { 'swiper/index': 'src/components/swiper/index.tsx' }, plugins: [ - typescript(), resolve({ preferBuiltins: false, mainFields: ['main:h5', 'browser', 'module', 'jsnext:main', 'main'] @@ -26,6 +25,12 @@ export default { postcss({ inject: { insertAt: 'top' } }), + ts({ + tsconfig: config => ({ + ...config, + sourceMap: true + }) + }), commonjs({ include: '../../node_modules/**' }), diff --git a/packages/taro-components-rn/jest.config.js b/packages/taro-components-rn/jest.config.js index 657ed5b9189e..d9035307fc07 100644 --- a/packages/taro-components-rn/jest.config.js +++ b/packages/taro-components-rn/jest.config.js @@ -3,10 +3,10 @@ module.exports = { verbose: true, setupFilesAfterEnv: ['/src/setup.ts'], transform: { - '^.+\\.js$': '/../../node_modules/react-native/jest/preprocessor.js', + '^.+\\.js$': '/node_modules/react-native/jest/preprocessor.js', '^.+\\.tsx?$': 'ts-jest' }, transformIgnorePatterns: [ - 'node_modules/(?!((jest-)?react-native|@react-native(-community)?)|expo(nent)?|@expo(nent)?/.*|@expo-google-fonts/.*|react-navigation|@react-navigation/.*|@unimodules/.*|unimodules|sentry-expo|native-base|react-native-svg)' + 'node_modules/(?!(.*(jest-)?react-native|.*@react-native(-community)?)|.*expo|.*@react-navigation/.*|.*react-native-svg)' ] } diff --git a/packages/taro-components-rn/package.json b/packages/taro-components-rn/package.json index e7c91a826713..40db4a9720f3 100644 --- a/packages/taro-components-rn/package.json +++ b/packages/taro-components-rn/package.json @@ -1,12 +1,12 @@ { "name": "@tarojs/components-rn", - "version": "3.5.0-beta.4", + "version": "3.5.0-theta.1", "description": "多端解决方案基础组件(RN)", "main": "./dist/index.js", "scripts": { "assets": "cpy 'src/**/*.png' '!src/__tests__/*' dist", - "build": "rimraf ./dist && tsc && yarn assets", - "dev": "yarn assets && tsc --watch", + "build": "rimraf ./dist && tsc && pnpm run assets", + "dev": "pnpm run assets && tsc --watch", "lint": "eslint .", "test": "jest --silent", "test:dev": "jest --watch", @@ -32,14 +32,13 @@ "expo-av": "~11.2.3", "expo-barcode-scanner": "~11.3.0", "expo-camera": "~12.2.0", - "prop-types": "^15.6.2", + "prop-types": "^15.7.2", "react-native-maps": "^0.25.0", "react-native-pager-view": "~5.4.9", "react-native-svg": "~12.1.1", "react-native-webview": "~11.14.3" }, "devDependencies": { - "@tarojs/components": "3.5.0-beta.4", "@types/react": "^17.0.0", "@types/react-native": "^0.67.7", "@unimodules/core": "^7.1.2", diff --git a/packages/taro-components/__tests__/style.spec.js b/packages/taro-components/__tests__/style.spec.js index 5f5d0a8ade9e..a83ae3260068 100644 --- a/packages/taro-components/__tests__/style.spec.js +++ b/packages/taro-components/__tests__/style.spec.js @@ -1,5 +1,6 @@ -import React from 'react' import * as assert from 'assert' +import React from 'react' + import { View } from '../h5/react' import { mount } from './test-tools' diff --git a/packages/taro-components/package.json b/packages/taro-components/package.json index 0284b3105808..251206a6ffea 100644 --- a/packages/taro-components/package.json +++ b/packages/taro-components/package.json @@ -1,6 +1,6 @@ { "name": "@tarojs/components", - "version": "3.5.0-beta.4", + "version": "3.5.0-theta.1", "description": "", "browser": "dist/index.js", "main:h5": "dist/index.js", @@ -24,7 +24,7 @@ "collection:main": "dist/collection/index.js", "scripts": { "build-h5": "babel -d dist-h5 h5", - "build": "npm run build-h5 & stencil build --config stencil.config.ts", + "build": "pnpm run build-h5 & stencil build --config stencil.config.ts", "dev": "stencil build --config stencil.config.ts --watch", "test": "karmatic --files '__tests__/setup.js,__tests__/**.spec.js' --coverage false", "test:ci": "karmatic --files '__tests__/setup.js,__tests__/**.spec.js' --coverage false", @@ -41,7 +41,7 @@ "dependencies": { "@stencil/core": "~2.13.0", "@stencil/sass": "1.5.2", - "@tarojs/taro": "3.5.0-beta.4", + "@tarojs/taro": "workspace:*", "better-scroll": "^1.14.1", "classnames": "^2.2.5", "hls.js": "^1.1.5", @@ -52,6 +52,7 @@ "weui": "^1.1.2" }, "devDependencies": { + "css-loader": "3.4.2", "jquery": "^3.4.1", "karmatic": "^2.1.0", "react": "^17.0.2", diff --git a/packages/taro-components/src/global.css b/packages/taro-components/src/global.css index 7027b3586e04..141ce1444e58 100644 --- a/packages/taro-components/src/global.css +++ b/packages/taro-components/src/global.css @@ -1,11 +1,11 @@ -@import url(../../../node_modules/weui/dist/style/weui.min.css); +@import url(../node_modules/weui/dist/style/weui.min.css); .taro_router { + overflow: hidden; + position: relative; width: 100%; height: 100%; min-height: 100vh; - position: relative; - overflow: hidden; } .taro-tabbar__container .taro_router { @@ -13,11 +13,11 @@ } .taro_page { + overflow-x: hidden; + overflow-y: scroll; width: 100%; height: 100%; max-height: 100vh; - overflow-x: hidden; - overflow-y: scroll; } .taro-tabbar__container .taro-tabbar__panel { diff --git a/packages/taro-extend/package.json b/packages/taro-extend/package.json index bfa8bf1ab934..17a3af0bee13 100644 --- a/packages/taro-extend/package.json +++ b/packages/taro-extend/package.json @@ -1,6 +1,6 @@ { "name": "@tarojs/extend", - "version": "3.5.0-beta.4", + "version": "3.5.0-theta.1", "description": "Taro extend functionality", "author": "yuche ", "homepage": "https://github.com/nervjs/taro/tree/master/packages/taro-extend#readme", diff --git a/packages/taro-h5/__tests__/ui/interaction/actionSheet.test.ts b/packages/taro-h5/__tests__/ui/interaction/actionSheet.test.ts index 72b863fc95e5..08f78dfd94e3 100644 --- a/packages/taro-h5/__tests__/ui/interaction/actionSheet.test.ts +++ b/packages/taro-h5/__tests__/ui/interaction/actionSheet.test.ts @@ -1,4 +1,4 @@ -import 'jest-dom/extend-expect' +import '@testing-library/jest-dom/extend-expect' import * as Taro from '@tarojs/taro-h5' diff --git a/packages/taro-h5/__tests__/ui/interaction/loading.test.ts b/packages/taro-h5/__tests__/ui/interaction/loading.test.ts index efb731a2293e..f583ab677b91 100644 --- a/packages/taro-h5/__tests__/ui/interaction/loading.test.ts +++ b/packages/taro-h5/__tests__/ui/interaction/loading.test.ts @@ -1,4 +1,4 @@ -import 'jest-dom/extend-expect' +import '@testing-library/jest-dom/extend-expect' import * as Taro from '@tarojs/taro-h5' diff --git a/packages/taro-h5/__tests__/ui/interaction/modal.test.ts b/packages/taro-h5/__tests__/ui/interaction/modal.test.ts index c39c3dca7eb2..3e44b2ed24b4 100644 --- a/packages/taro-h5/__tests__/ui/interaction/modal.test.ts +++ b/packages/taro-h5/__tests__/ui/interaction/modal.test.ts @@ -1,4 +1,4 @@ -import 'jest-dom/extend-expect' +import '@testing-library/jest-dom/extend-expect' import * as Taro from '@tarojs/taro-h5' @@ -303,8 +303,8 @@ describe('modal', () => { const title = modal.lastChild.firstChild const content = modal.lastChild.children[1] - expect(title).toHaveTextContent('') - expect(content).toHaveTextContent('') + expect(title).toBeEmptyDOMElement() + expect(content).toBeEmptyDOMElement() setTimeout(() => { expect(title).not.toBeVisible() diff --git a/packages/taro-h5/__tests__/ui/interaction/toast.test.ts b/packages/taro-h5/__tests__/ui/interaction/toast.test.ts index 8a09eb7bf8be..6631efc9a6ec 100644 --- a/packages/taro-h5/__tests__/ui/interaction/toast.test.ts +++ b/packages/taro-h5/__tests__/ui/interaction/toast.test.ts @@ -1,4 +1,4 @@ -import 'jest-dom/extend-expect' +import '@testing-library/jest-dom/extend-expect' import * as Taro from '@tarojs/taro-h5' diff --git a/packages/taro-h5/package.json b/packages/taro-h5/package.json index 268fc67e4ce0..d8463cd39a71 100644 --- a/packages/taro-h5/package.json +++ b/packages/taro-h5/package.json @@ -1,6 +1,6 @@ { "name": "@tarojs/taro-h5", - "version": "3.5.0-beta.4", + "version": "3.5.0-theta.1", "description": "Taro h5 framework", "browser": "dist/index.esm.js", "main:h5": "dist/index.js", @@ -15,8 +15,8 @@ "sideEffects": false, "scripts": { "assets": "cpy 'src/**/*.css' dist", - "build": "rimraf ./dist && tsc && npm run assets && rollup -c", - "predev": "npm run assets", + "build": "rimraf ./dist && tsc && pnpm run assets && rollup -c", + "predev": "pnpm run assets", "dev": "tsc -w", "test": "jest", "test:ci": "jest -i --coverage false", @@ -33,9 +33,9 @@ "author": "O2Team", "license": "MIT", "dependencies": { - "@tarojs/api": "3.5.0-beta.4", - "@tarojs/router": "3.5.0-beta.4", - "@tarojs/runtime": "3.5.0-beta.4", + "@tarojs/api": "workspace:*", + "@tarojs/router": "workspace:*", + "@tarojs/runtime": "workspace:*", "base64-js": "^1.3.0", "jsonp-retry": "^1.0.3", "mobile-detect": "^1.4.2", diff --git a/packages/taro-h5/rollup.config.js b/packages/taro-h5/rollup.config.js index 832e5091511e..26fa0ad580cc 100644 --- a/packages/taro-h5/rollup.config.js +++ b/packages/taro-h5/rollup.config.js @@ -1,9 +1,9 @@ import commonjs from '@rollup/plugin-commonjs' import resolve from '@rollup/plugin-node-resolve' -import typescript from '@rollup/plugin-typescript' import { mergeWith } from 'lodash' import externals from 'rollup-plugin-node-externals' import postcss from 'rollup-plugin-postcss' +import ts from 'rollup-plugin-ts' import exportNameOnly from './build/rollup-plugin-export-name-only' @@ -22,9 +22,11 @@ const baseConfig = { preferBuiltins: false, mainFields: ['main:h5', 'browser', 'module', 'jsnext:main', 'main'] }), - typescript({ - tsconfig: './tsconfig.json', - sourceMap: true + ts({ + tsconfig: config => ({ + ...config, + sourceMap: true + }) }), commonjs(), postcss({ diff --git a/packages/taro-h5/src/api/ui/interaction/modal.ts b/packages/taro-h5/src/api/ui/interaction/modal.ts index 1e5b99542bde..2179162d522c 100644 --- a/packages/taro-h5/src/api/ui/interaction/modal.ts +++ b/packages/taro-h5/src/api/ui/interaction/modal.ts @@ -182,6 +182,7 @@ export default class Modal { this.title.style.display = 'block' this.text.setAttribute('style', inlineStyle(textStyle)) } else { + this.title.textContent = '' // block => none this.title.style.display = 'none' const textCSS = { diff --git a/packages/taro-h5/src/api/wxml/selectorQuery.ts b/packages/taro-h5/src/api/wxml/selectorQuery.ts index b7880c7463b8..5fa37de769d6 100644 --- a/packages/taro-h5/src/api/wxml/selectorQuery.ts +++ b/packages/taro-h5/src/api/wxml/selectorQuery.ts @@ -38,7 +38,7 @@ function filter (fields, dom?: HTMLElement, selector?: string) { res.node = null } } else { - // TODO https://developers.weixin.qq.com/miniprogram/dev/component/scroll-view.html + // TODO https://developers.weixin.qq.com/miniprogram/dev/api/ui/scroll/ScrollViewContext.html // if (/^taro-scroll-view-core/i.test(tagName)) res.nodeCanvasType = '' res.node = dom diff --git a/packages/taro-h5/tsconfig.json b/packages/taro-h5/tsconfig.json index e742ea9778b6..377aa72b9606 100644 --- a/packages/taro-h5/tsconfig.json +++ b/packages/taro-h5/tsconfig.json @@ -4,8 +4,7 @@ "baseUrl": ".", "outDir": "dist", "module": "ESNext", - "sourceMap": false, - "typeRoots": ["./node_modules/@types"], + "sourceMap": false }, - "include": ["./src", "./types"], + "include": ["./src", "./types"] } diff --git a/packages/taro-h5/types/api.d.ts b/packages/taro-h5/types/api.d.ts index 81f0c24bf309..6abc269e20a6 100644 --- a/packages/taro-h5/types/api.d.ts +++ b/packages/taro-h5/types/api.d.ts @@ -1,4 +1,4 @@ declare module '@tarojs/api' { - import Taro from "@tarojs/taro" + import Taro from '@tarojs/taro' export = Taro } diff --git a/packages/taro-helper/index.js b/packages/taro-helper/index.js index 437a6d4788f4..9d6907c2ac2f 100644 --- a/packages/taro-helper/index.js +++ b/packages/taro-helper/index.js @@ -1,2 +1,3 @@ -module.exports = require('./dist/index.js').default +module.exports = require('./dist/index.js') + module.exports.default = module.exports diff --git a/packages/taro-helper/package.json b/packages/taro-helper/package.json index 517de2fe4f43..77efb8fb8dfa 100644 --- a/packages/taro-helper/package.json +++ b/packages/taro-helper/package.json @@ -1,15 +1,15 @@ { "name": "@tarojs/helper", - "version": "3.5.0-beta.4", + "version": "3.5.0-theta.1", "description": "Taro Helper", "main": "index.js", - "types": "types/index.d.ts", + "types": "dist/index.d.ts", "scripts": { "build": "run-s clean prod", "dev": "tsc -w", "prod": "tsc", "clean": "rimraf dist", - "prepack": "npm run build", + "prepack": "pnpm run build", "test": "jest", "test:dev": "jest --watch" }, @@ -42,7 +42,7 @@ "@babel/runtime": "^7.14.5", "@swc/core": "^1.2.204", "@swc/register": "^0.1.10", - "@tarojs/taro": "3.5.0-beta.4", + "ansi-escapes": "^4.3.2", "chalk": "3.0.0", "chokidar": "^3.3.1", "cross-spawn": "^7.0.3", @@ -50,7 +50,8 @@ "find-yarn-workspace-root": "2.0.0", "fs-extra": "^8.0.1", "lodash": "^4.17.21", - "resolve": "^1.6.0", + "resolve": "^1.22.0", + "supports-hyperlinks": "^2.2.0", "yauzl": "2.10.0" } } diff --git a/packages/taro-helper/src/babelRegister.ts b/packages/taro-helper/src/babelRegister.ts index 3b7957f864ce..ebc2bf943a0a 100644 --- a/packages/taro-helper/src/babelRegister.ts +++ b/packages/taro-helper/src/babelRegister.ts @@ -1,7 +1,6 @@ +import type { NodePath, PluginItem } from '@babel/core' import * as path from 'path' -import type { PluginItem, NodePath } from '@babel/core' - /** * Inject `defineAppConfig` and `definePageConfig` * require header at the top of a config file, diff --git a/packages/taro-helper/src/constants.ts b/packages/taro-helper/src/constants.ts index 8226d5ed82b0..7b3336f995e9 100644 --- a/packages/taro-helper/src/constants.ts +++ b/packages/taro-helper/src/constants.ts @@ -1,6 +1,7 @@ -import * as chalk from 'chalk' import * as os from 'os' +import { chalk } from './terminal' + // eslint-disable-next-line dot-notation export const PLATFORMS = global['PLATFORMS'] = global['PLATFORMS'] || {} diff --git a/packages/taro-helper/src/index.ts b/packages/taro-helper/src/index.ts index b0737ce49ef9..9aefe1c82e01 100644 --- a/packages/taro-helper/src/index.ts +++ b/packages/taro-helper/src/index.ts @@ -1,24 +1,11 @@ -import * as fs from 'fs-extra' -import * as chalk from 'chalk' -import * as chokidar from 'chokidar' +export * as chokidar from 'chokidar' +export * as fs from 'fs-extra' -import * as constants from './constants' -import * as utils from './utils' -import * as npm from './npm' -import createBabelRegister, { injectDefineConfigHeader } from './babelRegister' -import createSwcRegister from './swcRegister' +export const createDebug = (id: string) => require('debug')(id) -export const helper = { - ...constants, - ...utils, - npm, - createBabelRegister, - injectDefineConfigHeader, - createSwcRegister, - fs, - chalk, - chokidar, - createDebug: id => require('debug')(id) -} - -export default helper +export { default as createBabelRegister, injectDefineConfigHeader } from './babelRegister' +export * from './constants' +export * as npm from './npm' +export { default as createSwcRegister } from './swcRegister' +export * from './terminal' +export * from './utils' diff --git a/packages/taro-helper/src/npm.ts b/packages/taro-helper/src/npm.ts index 38fe321b6063..5664b2d5b50f 100644 --- a/packages/taro-helper/src/npm.ts +++ b/packages/taro-helper/src/npm.ts @@ -1,5 +1,4 @@ -import * as chalk from 'chalk' - +import { chalk } from './terminal' import * as Util from './utils' const PEERS = /UNMET PEER DEPENDENCY ([a-z\-0-9.]+)@(.+)/gm @@ -9,7 +8,7 @@ const erroneous: string[] = [] type pluginFunction = (pluginName: string, content: string | null, file: string, config: Record, root: string) => any export interface IInstallOptions { - dev: boolean, + dev: boolean peerDependencies?: boolean } diff --git a/packages/taro-helper/src/swcRegister.ts b/packages/taro-helper/src/swcRegister.ts index 74fed411eed5..a42c07cc05cf 100644 --- a/packages/taro-helper/src/swcRegister.ts +++ b/packages/taro-helper/src/swcRegister.ts @@ -16,7 +16,12 @@ export class InjectDefineConfigHeader extends Visitor { } } -export default function createSwcRegister ({ only, plugin }) { +interface ICreateSwcRegisterParam { + only + plugin? +} + +export default function createSwcRegister ({ only, plugin }: ICreateSwcRegisterParam) { const config: Record = { only: Array.from(new Set([...only])), jsc: { diff --git a/packages/taro-helper/src/terminal.ts b/packages/taro-helper/src/terminal.ts new file mode 100644 index 000000000000..4c87591638fe --- /dev/null +++ b/packages/taro-helper/src/terminal.ts @@ -0,0 +1,25 @@ +import ansiEscapes from 'ansi-escapes' +import chalk from 'chalk' +import supportsHyperlinks from 'supports-hyperlinks' + +interface ITerminalLinkOptions { + target?: 'stdout' | 'stderr' + fallback?: boolean | ((text: string, url: string) => string) + [key: string]: unknown +} + +function terminalLink (text: string, url: string, { target = 'stdout', fallback }: ITerminalLinkOptions = {}) { + if (!supportsHyperlinks[target]) { + if (fallback === false) return text + + return typeof fallback === 'function' ? fallback(text, url) : `${text} (\u200B${url}\u200B)` + } + + return ansiEscapes.link(text, url) +} + +terminalLink.isSupported = supportsHyperlinks.stdout +terminalLink.stderr = ((text: string, url: string, options = {}) => terminalLink(text, url, { target: 'stderr', ...options })) as typeof terminalLink +terminalLink.stderr.isSupported = supportsHyperlinks.stderr + +export { chalk, terminalLink } diff --git a/packages/taro-helper/src/utils.ts b/packages/taro-helper/src/utils.ts index 9394fea457be..5f2cebe5cede 100644 --- a/packages/taro-helper/src/utils.ts +++ b/packages/taro-helper/src/utils.ts @@ -1,4 +1,3 @@ -import * as chalk from 'chalk' import * as child_process from 'child_process' import * as fs from 'fs-extra' import { camelCase, flatMap, isPlainObject, mergeWith } from 'lodash' @@ -17,6 +16,7 @@ import { TARO_CONFIG_FOLDER } from './constants' import createSwcRegister, { InjectDefineConfigHeader } from './swcRegister' +import { chalk } from './terminal' const execSync = child_process.execSync diff --git a/packages/taro-helper/tsconfig.json b/packages/taro-helper/tsconfig.json index a8555932b84f..19cd062787b7 100644 --- a/packages/taro-helper/tsconfig.json +++ b/packages/taro-helper/tsconfig.json @@ -2,12 +2,12 @@ "extends": "../../tsconfig.root.json", "compilerOptions": { "baseUrl": ".", + "declaration": true, + "esModuleInterop": true, "outDir": "dist", "rootDir": "./src", "module": "commonjs", - "preserveConstEnums": true, + "preserveConstEnums": true }, - "include": [ - "./src", - ] + "include": ["./src"] } diff --git a/packages/taro-helper/types/babelRegister.d.ts b/packages/taro-helper/types/babelRegister.d.ts deleted file mode 100644 index fd08b4080ebb..000000000000 --- a/packages/taro-helper/types/babelRegister.d.ts +++ /dev/null @@ -1,6 +0,0 @@ -import type { PluginItem } from '@babel/core' - -export default function createBabelRegister({ only }: { - only: any; -}): void; -export function injectDefineConfigHeader (babel: any): PluginItem; diff --git a/packages/taro-helper/types/constants.d.ts b/packages/taro-helper/types/constants.d.ts deleted file mode 100644 index 7a06a34b3e92..000000000000 --- a/packages/taro-helper/types/constants.d.ts +++ /dev/null @@ -1,84 +0,0 @@ -import * as chalk from 'chalk'; -export declare const PLATFORMS: {}; -export declare const enum processTypeEnum { - START = "start", - CREATE = "create", - COMPILE = "compile", - CONVERT = "convert", - COPY = "copy", - GENERATE = "generate", - MODIFY = "modify", - ERROR = "error", - WARNING = "warning", - UNLINK = "unlink", - REFERENCE = "reference", - REMIND = "remind" -} -export interface IProcessTypeMap { - [key: string]: { - name: string; - color: string | chalk.Chalk; - }; -} -export declare const processTypeMap: IProcessTypeMap; -export declare const CSS_EXT: string[]; -export declare const SCSS_EXT: string[]; -export declare const JS_EXT: string[]; -export declare const TS_EXT: string[]; -export declare const UX_EXT: string[]; -export declare const SCRIPT_EXT: string[]; -export declare const VUE_EXT: string[]; -export declare const REG_JS: RegExp; -export declare const REG_SCRIPT: RegExp; -export declare const REG_TYPESCRIPT: RegExp; -export declare const REG_SCRIPTS: RegExp; -export declare const REG_VUE: RegExp; -export declare const REG_SASS: RegExp; -export declare const REG_SASS_SASS: RegExp; -export declare const REG_SASS_SCSS: RegExp; -export declare const REG_LESS: RegExp; -export declare const REG_STYLUS: RegExp; -export declare const REG_STYLE: RegExp; -export declare const REG_CSS: RegExp; -export declare const REG_MEDIA: RegExp; -export declare const REG_IMAGE: RegExp; -export declare const REG_FONT: RegExp; -export declare const REG_JSON: RegExp; -export declare const REG_UX: RegExp; -export declare const REG_TEMPLATE: RegExp; -export declare const REG_WXML_IMPORT: RegExp; -export declare const REG_URL: RegExp; -export declare const CSS_IMPORT_REG: RegExp; -export declare const NODE_MODULES = "node_modules"; -export declare const NODE_MODULES_REG: RegExp; -export declare const PROJECT_CONFIG = "config/index"; -export declare const DEVICE_RATIO: { - 640: number; - 750: number; - 828: number; -}; -export declare const FILE_PROCESSOR_MAP: { - '.js': string; - '.scss': string; - '.sass': string; - '.less': string; - '.styl': string; -}; -export declare const UPDATE_PACKAGE_LIST: string[]; -export declare const taroJsComponents = "@tarojs/components"; -export declare const taroJsQuickAppComponents = "@tarojs/components-qa"; -export declare const taroJsFramework = "@tarojs/taro"; -export declare const taroJsRedux = "@tarojs/redux"; -export declare const taroJsMobx = "@tarojs/mobx"; -export declare const taroJsMobxCommon = "@tarojs/mobx-common"; -export declare const DEVICE_RATIO_NAME = "deviceRatio"; -export declare const isWindows: boolean; -export declare const DEFAULT_TEMPLATE_SRC = "github:NervJS/taro-project-templates#v3.5"; -export declare const DEFAULT_TEMPLATE_SRC_GITEE = "direct:https://gitee.com/o2team/taro-project-templates.git#v3.5"; -export declare const TARO_CONFIG_FOLDER = ".taro3.5"; -export declare const TARO_BASE_CONFIG = "index.json"; -export declare const OUTPUT_DIR = "dist"; -export declare const SOURCE_DIR = "src"; -export declare const TEMP_DIR = ".temp"; -export declare const NPM_DIR = "npm"; -export declare const ENTRY = "app"; diff --git a/packages/taro-helper/types/index.d.ts b/packages/taro-helper/types/index.d.ts deleted file mode 100644 index c48ee77683ce..000000000000 --- a/packages/taro-helper/types/index.d.ts +++ /dev/null @@ -1,154 +0,0 @@ -import fs from 'fs-extra' -import * as chokidar from 'chokidar' -import createDebug from 'debug' -import chalk from 'chalk' - -import { processTypeEnum, IProcessTypeMap } from './constants' -import * as utils from './utils' -import * as npm from './npm' -import createBabelRegister, { injectDefineConfigHeader } from './babelRegister' -import createSwcRegister from './swcRegister' - -export declare enum META_TYPE { - ENTRY = 'ENTRY', - PAGE = 'PAGE', - COMPONENT = 'COMPONENT', - NORMAL = 'NORMAL', - STATIC = 'STATIC', - CONFIG = 'CONFIG', - EXPORTS = 'EXPORTS' -} - -export declare enum FRAMEWORK_MAP { - VUE = 'vue', - VUE3 = 'vue3', - REACT = 'react', - NERV = 'nerv' -} - -declare interface helper { - npm: typeof npm - createSwcRegister: typeof createSwcRegister - createBabelRegister: typeof createBabelRegister - injectDefineConfigHeader: typeof injectDefineConfigHeader - fs: typeof fs - chokidar: typeof chokidar - chalk: typeof chalk - createDebug: createDebug.Debug & { - debug: createDebug.Debug - default: createDebug.Debug - } - normalizePath(path: string): string - isNpmPkg(name: string): boolean - isQuickAppPkg(name: string): boolean - isAliasPath(name: string, pathAlias?: object): boolean - replaceAliasPath(filePath: string, name: string, pathAlias?: object): string - promoteRelativePath(fPath: string): string - resolveStylePath(p: string): string - printLog(type: processTypeEnum, tag: string, filePath?: string | undefined): void - recursiveFindNodeModules(filePath: string): string - getUserHomeDir(): string - getTaroPath(): string - getConfig(): object - getSystemUsername(): string - shouldUseYarn(): boolean - shouldUseCnpm(): boolean - isEmptyObject(obj: any): boolean - resolveScriptPath(p: string): string - resolveMainFilePath(p: string, extArrs?: string[]): string - generateEnvList(env: object): object - generateConstantsList(constants: object): object - cssImports(content: string): string[] - emptyDirectory( - dirPath: string, - opts?: { - excludes: string[] - } - ): void - getInstalledNpmPkgPath(pkgName: string, basedir: string): string | null - getInstalledNpmPkgVersion(pkgName: string, basedir: string): string | null - unzip(zipPath: any): Promise - getBabelConfig(babel: any): any - readDirWithFileTypes(folder: string): utils.FileStat[] - extnameExpRegOf(filePath: string): RegExp - addPlatforms(platform: string): void - isNodeModule: (filename: string) => boolean - pascalCase: (str: string) => string - recursiveMerge: (src: Partial, ...args: (Partial | undefined)[]) => any - mergeVisitors: (src: any, ...args: any[]) => any - applyArrayedVisitors: (obj: any) => any - getAllFilesInFolder: (folder: string, filter?: string[]) => Promise - getModuleDefaultExport: (exports: any) => any - removeHeadSlash: (str: string) => string - readConfig: (configPath: string) => any - readPageConfig: (configPath: string) => any - PLATFORMS: any - processTypeEnum: typeof processTypeEnum - processTypeMap: IProcessTypeMap - CSS_EXT: string[] - SCSS_EXT: string[] - JS_EXT: string[] - TS_EXT: string[] - UX_EXT: string[] - SCRIPT_EXT: string[] - VUE_EXT: string[] - REG_JS: RegExp - REG_SCRIPT: RegExp - REG_TYPESCRIPT: RegExp - REG_SCRIPTS: RegExp - REG_VUE: RegExp - REG_SASS: RegExp - REG_SASS_SASS: RegExp - REG_SASS_SCSS: RegExp - REG_LESS: RegExp - REG_STYLUS: RegExp - REG_STYLE: RegExp - REG_CSS: RegExp - REG_MEDIA: RegExp - REG_IMAGE: RegExp - REG_FONT: RegExp - REG_JSON: RegExp - REG_UX: RegExp - REG_TEMPLATE: RegExp - REG_WXML_IMPORT: RegExp - REG_URL: RegExp - CSS_IMPORT_REG: RegExp - NODE_MODULES: 'node_modules' - NODE_MODULES_REG: RegExp - PROJECT_CONFIG: 'config/index' - DEVICE_RATIO: { - 640: number - 750: number - 828: number - } - FILE_PROCESSOR_MAP: { - '.js': string - '.scss': string - '.sass': string - '.less': string - '.styl': string - } - META_TYPE: typeof META_TYPE - FRAMEWORK_MAP: typeof FRAMEWORK_MAP - UPDATE_PACKAGE_LIST: string[] - taroJsComponents: '@tarojs/components' - taroJsQuickAppComponents: '@tarojs/components-qa' - taroJsFramework: '@tarojs/taro' - taroJsRedux: '@tarojs/redux' - taroJsMobx: '@tarojs/mobx' - taroJsMobxCommon: '@tarojs/mobx-common' - DEVICE_RATIO_NAME: 'deviceRatio' - isWindows: boolean - DEFAULT_TEMPLATE_SRC: 'github:NervJS/taro-project-templates#v3.5' - DEFAULT_TEMPLATE_SRC_GITEE: 'direct:https://gitee.com/o2team/taro-project-templates.git#v3.5' - TARO_CONFIG_FOLDER: '.taro3.5' - TARO_BASE_CONFIG: 'index.json' - OUTPUT_DIR: 'dist' - SOURCE_DIR: 'src' - TEMP_DIR: '.temp' - NPM_DIR: 'npm' - ENTRY: 'app' -} -declare const helper: helper -// @ts-ignore -export = helper diff --git a/packages/taro-helper/types/npm.d.ts b/packages/taro-helper/types/npm.d.ts deleted file mode 100644 index 73fb7383b847..000000000000 --- a/packages/taro-helper/types/npm.d.ts +++ /dev/null @@ -1,14 +0,0 @@ -declare type pluginFunction = (pluginName: string, content: string | null, file: string, config: object, root: string) => any; -export interface IInstallOptions { - dev: boolean; - peerDependencies?: boolean; -} -export declare const taroPluginPrefix = "@tarojs/plugin-"; -export declare function resolveNpm(pluginName: string, root: any): Promise; -export declare function resolveNpmSync(pluginName: string, root: any): string; -export declare function installNpmPkg(pkgList: string[] | string, options: IInstallOptions): any; -export declare const callPlugin: pluginFunction; -export declare const callPluginSync: pluginFunction; -export declare function getNpmPkgSync(npmName: string, root: string): any; -export declare function getNpmPkg(npmName: string, root: string): Promise; -export {}; diff --git a/packages/taro-helper/types/swcRegister.d.ts b/packages/taro-helper/types/swcRegister.d.ts deleted file mode 100644 index af1107f6336f..000000000000 --- a/packages/taro-helper/types/swcRegister.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -export default function createSwcRegister({ only }: { - only: any; -}): void; diff --git a/packages/taro-helper/types/utils.d.ts b/packages/taro-helper/types/utils.d.ts deleted file mode 100644 index 63693074cd27..000000000000 --- a/packages/taro-helper/types/utils.d.ts +++ /dev/null @@ -1,46 +0,0 @@ -import { processTypeEnum } from './constants'; -export declare function normalizePath(path: string): string; -export declare const isNodeModule: (filename: string) => boolean; -export declare function isNpmPkg(name: string): boolean; -export declare function isQuickAppPkg(name: string): boolean; -export declare function isAliasPath(name: string, pathAlias?: object): boolean; -export declare function replaceAliasPath(filePath: string, name: string, pathAlias?: object): string; -export declare function promoteRelativePath(fPath: string): string; -export declare function resolveStylePath(p: string): string; -export declare function printLog(type: processTypeEnum, tag: string, filePath?: string): void; -export declare function recursiveFindNodeModules(filePath: string): string; -export declare function getUserHomeDir(): string; -export declare function getTaroPath(): string; -export declare function getConfig(): object; -export declare function getSystemUsername(): string; -export declare function shouldUseYarn(): boolean; -export declare function shouldUseCnpm(): boolean; -export declare function isEmptyObject(obj: any): boolean; -export declare function resolveScriptPath(p: string): string; -export declare function generateEnvList(env: object): object; -export declare function generateConstantsList(constants: object): object; -export declare function cssImports(content: string): string[]; -export declare function emptyDirectory(dirPath: string, opts?: { - excludes: string[]; -}): void; -export declare const pascalCase: (str: string) => string; -export declare function getInstalledNpmPkgPath(pkgName: string, basedir: string): string | null; -export declare function getInstalledNpmPkgVersion(pkgName: string, basedir: string): string | null; -export declare const recursiveMerge: (src: Partial, ...args: (Partial | undefined)[]) => any; -export declare const mergeVisitors: (src: any, ...args: any[]) => any; -export declare const applyArrayedVisitors: (obj: any) => any; -export declare function unzip(zipPath: any): Promise; -export declare function getBabelConfig(babel: any): any; -export declare const getAllFilesInFolder: (folder: string, filter?: string[]) => Promise; -export interface FileStat { - name: string; - isDirectory: boolean; - isFile: boolean; -} -export declare function readDirWithFileTypes(folder: string): FileStat[]; -export declare function extnameExpRegOf(filePath: string): RegExp; -export declare function addPlatforms(platform: string): void; -export declare const getModuleDefaultExport: (exports: any) => any; -export declare const removeHeadSlash: (str: string) => string; -export declare const readConfig: (configPath: string) => any; -export declare const readPageConfig: (configPath: string) => any; diff --git a/packages/taro-jd/index.js b/packages/taro-jd/index.js index d10e007191bd..cfeaee0c0595 100644 --- a/packages/taro-jd/index.js +++ b/packages/taro-jd/index.js @@ -1,3 +1,4 @@ module.exports = require('./dist/index.js').default + module.exports.default = module.exports module.exports.JD = require('./dist/index.js').JD diff --git a/packages/taro-jd/package.json b/packages/taro-jd/package.json index 72a2efd40fda..e20cfa26f6c7 100644 --- a/packages/taro-jd/package.json +++ b/packages/taro-jd/package.json @@ -1,6 +1,6 @@ { "name": "@tarojs/plugin-platform-jd", - "version": "3.5.0-beta.4", + "version": "3.5.0-theta.1", "description": "京东小程序平台插件", "author": "Chen-jj", "homepage": "https://github.com/nervjs/taro/tree/master/packages/taro-jd#readme", @@ -27,7 +27,7 @@ "url": "https://github.com/NervJS/taro/issues" }, "dependencies": { - "@tarojs/service": "3.5.0-beta.4", - "@tarojs/shared": "3.5.0-beta.4" + "@tarojs/service": "workspace:*", + "@tarojs/shared": "workspace:*" } } diff --git a/packages/taro-jd/rollup.config.js b/packages/taro-jd/rollup.config.js index d7c5f52f6a64..74869c1f1828 100644 --- a/packages/taro-jd/rollup.config.js +++ b/packages/taro-jd/rollup.config.js @@ -1,17 +1,15 @@ -import typescript from 'rollup-plugin-typescript2' import * as path from 'path' +import ts from 'rollup-plugin-ts' const cwd = __dirname const base = { external: ['@tarojs/shared', '@tarojs/service'], - plugins: [typescript({ - useTsconfigDeclarationDir: true - })] + plugins: [ts()] } // 供 CLI 编译时使用的 Taro 插件入口 -const comileConfig = { +const compileConfig = { input: path.join(cwd, 'src/index.ts'), output: { file: path.join(cwd, 'dist/index.js'), @@ -44,4 +42,4 @@ const runtimeUtilsConfig = { ...base } -module.exports = [comileConfig, runtimeConfig, runtimeUtilsConfig] +module.exports = [compileConfig, runtimeConfig, runtimeUtilsConfig] diff --git a/packages/taro-jd/src/index.ts b/packages/taro-jd/src/index.ts index f51f18c632e1..77698fa7c769 100644 --- a/packages/taro-jd/src/index.ts +++ b/packages/taro-jd/src/index.ts @@ -1,6 +1,7 @@ -import JD from './program' import type { IPluginContext } from '@tarojs/service' +import JD from './program' + // 让其它平台插件可以继承此平台 export { JD } diff --git a/packages/taro-jd/src/program.ts b/packages/taro-jd/src/program.ts index f13bf216c4f8..1ca46698e4ba 100644 --- a/packages/taro-jd/src/program.ts +++ b/packages/taro-jd/src/program.ts @@ -1,6 +1,7 @@ import { TaroPlatformBase } from '@tarojs/service' -import { Template } from './template' + import { components } from './components' +import { Template } from './template' const PACKAGE_NAME = '@tarojs/plugin-platform-jd' diff --git a/packages/taro-jd/src/runtime.ts b/packages/taro-jd/src/runtime.ts index d8cccb2f4fb4..257d42bbce48 100644 --- a/packages/taro-jd/src/runtime.ts +++ b/packages/taro-jd/src/runtime.ts @@ -1,5 +1,6 @@ -import { mergeReconciler, mergeInternalComponents } from '@tarojs/shared' -import { hostConfig, components } from './runtime-utils' +import { mergeInternalComponents, mergeReconciler } from '@tarojs/shared' + +import { components, hostConfig } from './runtime-utils' mergeReconciler(hostConfig) mergeInternalComponents(components) diff --git a/packages/taro-loader/package.json b/packages/taro-loader/package.json index 7e1513dfa3a8..12c192d0f0e6 100644 --- a/packages/taro-loader/package.json +++ b/packages/taro-loader/package.json @@ -1,6 +1,6 @@ { "name": "@tarojs/taro-loader", - "version": "3.5.0-beta.4", + "version": "3.5.0-theta.1", "description": "> TODO: description", "author": "yuche ", "homepage": "https://github.com/nervjs/taro/tree/master/packages/taro-loader#readme", @@ -26,8 +26,8 @@ "url": "https://github.com/NervJS/taro/issues" }, "dependencies": { - "@tarojs/helper": "3.5.0-beta.4", - "@tarojs/taro": "3.5.0-beta.4", + "@tarojs/helper": "workspace:*", + "@tarojs/taro": "workspace:*", "loader-utils": "^1.2.3" }, "publishConfig": { diff --git a/packages/taro-mini-runner/index.js b/packages/taro-mini-runner/index.js index 437a6d4788f4..20d08ce23ee3 100644 --- a/packages/taro-mini-runner/index.js +++ b/packages/taro-mini-runner/index.js @@ -1,2 +1,3 @@ module.exports = require('./dist/index.js').default + module.exports.default = module.exports diff --git a/packages/taro-mini-runner/jest.config.js b/packages/taro-mini-runner/jest.config.js index 548b86af1eb9..338ed12d98e1 100644 --- a/packages/taro-mini-runner/jest.config.js +++ b/packages/taro-mini-runner/jest.config.js @@ -1,13 +1,24 @@ +const { jsWithTs: tsjPreset } = require('ts-jest/presets') + module.exports = { - preset: 'ts-jest', - testEnvironment: 'node', - moduleFileExtensions: ['ts', 'tsx', 'js', 'json', 'jsx', 'node'], - setupFilesAfterEnv: ['./src/__tests__/setup/index.ts'], - testMatch: ['**/__tests__/?(*.)+(spec|test).[jt]s?(x)'], globals: { 'ts-jest': { - diagnostics: false + diagnostics: false, + tsconfig: 'tsconfig.test.json' } }, - testTimeout: 60000 + moduleFileExtensions: ['ts', 'tsx', 'js', 'json', 'jsx', 'node'], + preset: 'ts-jest', + setupFilesAfterEnv: ['./src/__tests__/setup/index.ts'], + testEnvironment: 'node', + testMatch: ['**/__tests__/?(*.)+(spec|test).[jt]s?(x)'], + testTimeout: 60000, + transform: { + '^.+\\.jsx?$': 'babel-jest', + '^.+\\.tsx?$': 'ts-jest', + ...tsjPreset.transform + }, + transformIgnorePatterns: [ + 'node_modules', + ], } diff --git a/packages/taro-mini-runner/package.json b/packages/taro-mini-runner/package.json index 46646ca1b52c..abedc481be58 100644 --- a/packages/taro-mini-runner/package.json +++ b/packages/taro-mini-runner/package.json @@ -1,12 +1,12 @@ { "name": "@tarojs/mini-runner", - "version": "3.5.0-beta.4", + "version": "3.5.0-theta.1", "description": "Mini app runner for taro", "main": "index.js", "scripts": { - "build": "npm run clean && npm run prod", - "dev": "npm run mv:comp && tsc -w", - "prod": "tsc && npm run mv:comp", + "build": "pnpm run clean && pnpm run prod", + "dev": "pnpm run mv:comp && tsc -w", + "prod": "tsc && pnpm run mv:comp", "mv:comp": "node ./mv-comp.js", "clean": "rimraf dist", "test": "cross-env NODE_ENV=jest jest", @@ -34,22 +34,23 @@ "homepage": "https://github.com/NervJS/taro#readme", "dependencies": { "@babel/core": "^7.14.5", - "@tarojs/components": "3.5.0-beta.4", - "@tarojs/helper": "3.5.0-beta.4", - "@tarojs/plugin-platform-alipay": "3.5.0-beta.4", - "@tarojs/plugin-platform-jd": "3.5.0-beta.4", - "@tarojs/plugin-platform-qq": "3.5.0-beta.4", - "@tarojs/plugin-platform-swan": "3.5.0-beta.4", - "@tarojs/plugin-platform-tt": "3.5.0-beta.4", - "@tarojs/plugin-platform-weapp": "3.5.0-beta.4", - "@tarojs/react": "3.5.0-beta.4", - "@tarojs/runner-utils": "3.5.0-beta.4", - "@tarojs/runtime": "3.5.0-beta.4", - "@tarojs/shared": "3.5.0-beta.4", - "@tarojs/taro": "3.5.0-beta.4", - "@tarojs/taro-loader": "3.5.0-beta.4", + "@tarojs/components": "workspace:*", + "@tarojs/helper": "workspace:*", + "@tarojs/plugin-platform-alipay": "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/react": "workspace:*", + "@tarojs/runner-utils": "workspace:*", + "@tarojs/runtime": "workspace:*", + "@tarojs/shared": "workspace:*", + "@tarojs/taro": "workspace:*", + "@tarojs/taro-loader": "workspace:*", + "acorn-walk": "^8.0.0", "babel-loader": "8.2.1", - "babel-preset-taro": "3.5.0-beta.4", + "babel-preset-taro": "workspace:*", "copy-webpack-plugin": "5.1.2", "css-loader": "3.4.2", "csso-webpack-plugin": "2.0.0-beta.1", @@ -68,13 +69,13 @@ "mkdirp": "^1.0.4", "ora": "4.0.3", "postcss": "8.3.5", - "postcss-html-transform": "3.5.0-beta.4", + "postcss-html-transform": "workspace:*", "postcss-import": "12.0.1", "postcss-loader": "4.3.0", - "postcss-pxtransform": "3.5.0-beta.4", + "postcss-pxtransform": "workspace:*", "postcss-url": "8.0.0", "regenerator-runtime": "0.11", - "resolve": "^1.6.0", + "resolve": "^1.22.0", "resolve-url-loader": "4.0.0", "sass": "1.50.0", "sass-loader": "10.2.0", @@ -88,9 +89,11 @@ "vue-loader": "^15.9.3", "webpack": "4.46.0", "webpack-chain": "4.9.0", + "webpack-sources": "^3.2.3", "webpack-format-messages": "^2.0.5" }, "devDependencies": { - "@types/webpack": "4" + "@types/webpack": "4", + "webpack-merge": "^4.2.2" } } diff --git a/packages/taro-mini-runner/src/__tests__/__snapshots__/alipay.spec.ts.snap b/packages/taro-mini-runner/src/__tests__/__snapshots__/alipay.spec.ts.snap index 19bc8e25910d..46807874599e 100644 --- a/packages/taro-mini-runner/src/__tests__/__snapshots__/alipay.spec.ts.snap +++ b/packages/taro-mini-runner/src/__tests__/__snapshots__/alipay.spec.ts.snap @@ -1,6 +1,6 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`alipay should build alipay app 1`] = `16`; +exports[`alipay should build alipay app 1`] = `17`; exports[`alipay should build alipay app 2`] = ` " @@ -663,7 +663,7 @@ require(\\"./taro\\"); }).call(this, __webpack_require__(0)[\\"navigator\\"]); }, 14: function(module, exports, __webpack_require__) {}, - 18: function(module, __webpack_exports__, __webpack_require__) { + 17: function(module, __webpack_exports__, __webpack_require__) { \\"use strict\\"; __webpack_require__.r(__webpack_exports__); var runtime = __webpack_require__(13); @@ -1406,7 +1406,7 @@ require(\\"./taro\\"); } }); } -}, [ [ 18, 0, 1, 3, 2 ] ] ]); +}, [ [ 17, 0, 1, 3, 2 ] ] ]); @@ -1606,17 +1606,316 @@ require(\\"./taro\\");