From e9179a42724d95dbd08c556ae8c2d01eefe656c9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=82=A3=E5=90=92?= Date: Mon, 29 Nov 2021 15:22:18 +0800 Subject: [PATCH 1/9] tests/format routes (#4946) --- jest.config.js | 15 ++- .../plugin-router/tests/formatRoutes.spec.ts | 113 ++++++++++++++++++ .../__tests__ => tests}/joinPath.spec.ts | 2 +- packages/plugin-router/tsconfig.json | 2 +- .../cases/absolute-path/webpack.config.js | 4 +- .../test/cases/default-path/webpack.config.js | 4 +- .../cases/relative-path/webpack.config.js | 4 +- .../test/cases/root-path/webpack.config.js | 4 +- .../test/cases/timeout-path/webpack.config.js | 4 +- .../test/cases/url-path/webpack.config.js | 4 +- .../test/cases/weird-path/webpack.config.js | 4 +- 11 files changed, 141 insertions(+), 19 deletions(-) create mode 100644 packages/plugin-router/tests/formatRoutes.spec.ts rename packages/plugin-router/{src/utils/__tests__ => tests}/joinPath.spec.ts (98%) diff --git a/jest.config.js b/jest.config.js index 38e3101e5a..1a764bc8fa 100644 --- a/jest.config.js +++ b/jest.config.js @@ -9,12 +9,14 @@ module.exports = { moduleNameMapper, // 'testRunner': 'jest-circus/runner', 'coverageDirectory': './coverage/', - 'testEnvironment': 'node', 'collectCoverage': true, 'collectCoverageFrom': ['packages/*/lib/*.{js,jsx}'], 'coveragePathIgnorePatterns': [ '/node_modules/' ], + // copy from jest config + + 'testEnvironment': 'node', 'transform': { '^.+\\.jsx?$': 'babel-jest', '^.+\\.tsx?$': 'ts-jest' @@ -26,8 +28,15 @@ module.exports = { 'testPathIgnorePatterns': [ '/node_modules/', '/lib/', - 'create-cli-utils/', + 'create-cli-utils/' ], - // copy from jest config 'testMatch': [ '**/__tests__/**/*.[jt]s?(x)', '**/?(*.)+(spec|test).[jt]s?(x)' ], + // For ts-jest use rootDir's tsconfig.json, while unable to resolve references. + // The following strategy maybe not the best, but it works. + // https://github.com/kulshekhar/ts-jest/issues/1648 + 'globals': { + 'ts-jest': { + 'tsconfig': 'tsconfig.settings.json', + }, + }, }; diff --git a/packages/plugin-router/tests/formatRoutes.spec.ts b/packages/plugin-router/tests/formatRoutes.spec.ts new file mode 100644 index 0000000000..61115eabf5 --- /dev/null +++ b/packages/plugin-router/tests/formatRoutes.spec.ts @@ -0,0 +1,113 @@ +import formatRoutes from '../src/runtime/formatRoutes'; +import { IRouterConfig } from '../src/types'; + +let mockComponentA = null; +let mockComponentB = null; +let mockComponentC = null; + +describe('format-routes', () => { + beforeEach(() => { + mockComponentA = () => {} + mockComponentB = () => {} + mockComponentC = () => {} + }); + + test('one level', () => { + const routes: IRouterConfig[] = [ + { + path: '/', + exact: true, + component: mockComponentA as any, + }, + { + path: '/test', + component: mockComponentB as any, + }, + ]; + const formatedRoutes = formatRoutes(routes); + + expect(formatedRoutes[0].path).toBe('/'); + expect(formatedRoutes[1].path).toBe('/test'); + + expect((formatedRoutes[0].component as any).pageConfig).toEqual({ + componentName: 'mockComponentA' + }); + + expect((formatedRoutes[1].component as any).pageConfig).toEqual({ + componentName: 'mockComponentB' + }); + + }) + + test('multi level', () => { + const routes: IRouterConfig[] = [ + { + path: '/', + exact: true, + component: mockComponentA as any, + }, + { + path: '/test', + children: [ + { + exact: true, + path: '/plan', + children: [{ + path: '/a', + component: mockComponentB as any, + }] + }, + { + path: '/', + component: mockComponentC as any, + }, + ], + }, + ]; + const formatedRoutes = formatRoutes(routes); + + expect(formatedRoutes[0].path).toBe('/'); + expect(formatedRoutes[1].path).toBe('/test'); + + expect(formatedRoutes[1].children[0].path).toBe('/test/plan'); + expect(formatedRoutes[1].children[1].path).toBe('/test'); + + expect(formatedRoutes[1].children[0].children[0].path).toBe('/test/plan/a'); + expect((formatedRoutes[1].children[0].children[0].component as any).pageConfig).toEqual({ + componentName: 'mockComponentB' + }); + + expect(formatedRoutes[1].children[1].children).toBeUndefined(); + + }) + + test('childrens priority', () => { + const routes: IRouterConfig[] = [ + { + path: '/test', + component: mockComponentA as any, + children: [ + { + exact: true, + path: '/plan', + component: mockComponentB as any, + }, + { + path: '/', + component: mockComponentC as any, + }, + ], + }, + ]; + + const formatedRoutes = formatRoutes(routes); + + expect((formatedRoutes[0].component as any).pageConfig).toBeUndefined(); + expect((formatedRoutes[0].children[0].component as any).pageConfig).toEqual({ + componentName: 'mockComponentB' + }); + expect((formatedRoutes[0].children[1].component as any).pageConfig).toEqual({ + componentName: 'mockComponentC' + }); + }) +}) \ No newline at end of file diff --git a/packages/plugin-router/src/utils/__tests__/joinPath.spec.ts b/packages/plugin-router/tests/joinPath.spec.ts similarity index 98% rename from packages/plugin-router/src/utils/__tests__/joinPath.spec.ts rename to packages/plugin-router/tests/joinPath.spec.ts index 2ef0fe2091..e04907ed35 100644 --- a/packages/plugin-router/src/utils/__tests__/joinPath.spec.ts +++ b/packages/plugin-router/tests/joinPath.spec.ts @@ -1,5 +1,5 @@ import * as pathToRegexp from 'path-to-regexp'; -import joinPath from '../joinPath'; +import joinPath from '../src/utils/joinPath'; const joinTests: [string[], string][] = [ [[], ''], diff --git a/packages/plugin-router/tsconfig.json b/packages/plugin-router/tsconfig.json index 02d3ffd936..acda58e63c 100644 --- a/packages/plugin-router/tsconfig.json +++ b/packages/plugin-router/tsconfig.json @@ -10,6 +10,6 @@ }, "exclude": [ "templates", - "src/utils/__tests__" + "tests" ] } diff --git a/packages/webpack-plugin-extract-css-assets/test/cases/absolute-path/webpack.config.js b/packages/webpack-plugin-extract-css-assets/test/cases/absolute-path/webpack.config.js index 2edee0a293..47d67c7db2 100644 --- a/packages/webpack-plugin-extract-css-assets/test/cases/absolute-path/webpack.config.js +++ b/packages/webpack-plugin-extract-css-assets/test/cases/absolute-path/webpack.config.js @@ -1,5 +1,5 @@ const MiniCssExtractPlugin = require('mini-css-extract-plugin'); -const ExtractCssAssetsPlugin = require('../../../src/cjs'); +const ExtractCssAssetsPlugin = require('../../../src/index'); module.exports = { entry: './index', @@ -31,7 +31,7 @@ module.exports = { filename: 'css/[name].css', chunkFilename: 'css/[id].css', }), - new ExtractCssAssetsPlugin({ + new ExtractCssAssetsPlugin.default({ outputPath: 'cssassets/', relativeCssPath: '../' }), diff --git a/packages/webpack-plugin-extract-css-assets/test/cases/default-path/webpack.config.js b/packages/webpack-plugin-extract-css-assets/test/cases/default-path/webpack.config.js index e0d589cf17..f82793473d 100644 --- a/packages/webpack-plugin-extract-css-assets/test/cases/default-path/webpack.config.js +++ b/packages/webpack-plugin-extract-css-assets/test/cases/default-path/webpack.config.js @@ -1,5 +1,5 @@ const MiniCssExtractPlugin = require('mini-css-extract-plugin'); -const ExtractCssAssetsPlugin = require('../../../src/cjs'); +const ExtractCssAssetsPlugin = require('../../../src/index'); module.exports = { entry: './index', @@ -29,7 +29,7 @@ module.exports = { filename: '[name].css', chunkFilename: '[id].css', }), - new ExtractCssAssetsPlugin({ + new ExtractCssAssetsPlugin.default({ outputPath: 'cssassets/', }), ], diff --git a/packages/webpack-plugin-extract-css-assets/test/cases/relative-path/webpack.config.js b/packages/webpack-plugin-extract-css-assets/test/cases/relative-path/webpack.config.js index 8cafbc2656..660d00ab63 100644 --- a/packages/webpack-plugin-extract-css-assets/test/cases/relative-path/webpack.config.js +++ b/packages/webpack-plugin-extract-css-assets/test/cases/relative-path/webpack.config.js @@ -1,5 +1,5 @@ const MiniCssExtractPlugin = require('mini-css-extract-plugin'); -const ExtractCssAssetsPlugin = require('../../../src/cjs'); +const ExtractCssAssetsPlugin = require('../../../src/index'); module.exports = { entry: './index', @@ -31,7 +31,7 @@ module.exports = { filename: '[name].css', chunkFilename: '[id].css', }), - new ExtractCssAssetsPlugin({ + new ExtractCssAssetsPlugin.default({ outputPath: 'cssassets/', }), ], diff --git a/packages/webpack-plugin-extract-css-assets/test/cases/root-path/webpack.config.js b/packages/webpack-plugin-extract-css-assets/test/cases/root-path/webpack.config.js index fff4ab9d7c..732b85b9e1 100644 --- a/packages/webpack-plugin-extract-css-assets/test/cases/root-path/webpack.config.js +++ b/packages/webpack-plugin-extract-css-assets/test/cases/root-path/webpack.config.js @@ -1,5 +1,5 @@ const MiniCssExtractPlugin = require('mini-css-extract-plugin'); -const ExtractCssAssetsPlugin = require('../../../src/cjs'); +const ExtractCssAssetsPlugin = require('../../../src/index'); module.exports = { entry: './index', @@ -31,7 +31,7 @@ module.exports = { filename: '[name].css', chunkFilename: '[id].css', }), - new ExtractCssAssetsPlugin({ + new ExtractCssAssetsPlugin.default({ outputPath: 'cssassets/', }), ], diff --git a/packages/webpack-plugin-extract-css-assets/test/cases/timeout-path/webpack.config.js b/packages/webpack-plugin-extract-css-assets/test/cases/timeout-path/webpack.config.js index e0d589cf17..f82793473d 100644 --- a/packages/webpack-plugin-extract-css-assets/test/cases/timeout-path/webpack.config.js +++ b/packages/webpack-plugin-extract-css-assets/test/cases/timeout-path/webpack.config.js @@ -1,5 +1,5 @@ const MiniCssExtractPlugin = require('mini-css-extract-plugin'); -const ExtractCssAssetsPlugin = require('../../../src/cjs'); +const ExtractCssAssetsPlugin = require('../../../src/index'); module.exports = { entry: './index', @@ -29,7 +29,7 @@ module.exports = { filename: '[name].css', chunkFilename: '[id].css', }), - new ExtractCssAssetsPlugin({ + new ExtractCssAssetsPlugin.default({ outputPath: 'cssassets/', }), ], diff --git a/packages/webpack-plugin-extract-css-assets/test/cases/url-path/webpack.config.js b/packages/webpack-plugin-extract-css-assets/test/cases/url-path/webpack.config.js index 3fb867726b..d0f21db7cd 100644 --- a/packages/webpack-plugin-extract-css-assets/test/cases/url-path/webpack.config.js +++ b/packages/webpack-plugin-extract-css-assets/test/cases/url-path/webpack.config.js @@ -1,5 +1,5 @@ const MiniCssExtractPlugin = require('mini-css-extract-plugin'); -const ExtractCssAssetsPlugin = require('../../../src/cjs'); +const ExtractCssAssetsPlugin = require('../../../src/index'); module.exports = { entry: './index', @@ -31,7 +31,7 @@ module.exports = { filename: '[name].css', chunkFilename: '[id].css', }), - new ExtractCssAssetsPlugin({ + new ExtractCssAssetsPlugin.default({ outputPath: 'cssassets/', }), ], diff --git a/packages/webpack-plugin-extract-css-assets/test/cases/weird-path/webpack.config.js b/packages/webpack-plugin-extract-css-assets/test/cases/weird-path/webpack.config.js index b7a60f7b45..2871eacf1e 100644 --- a/packages/webpack-plugin-extract-css-assets/test/cases/weird-path/webpack.config.js +++ b/packages/webpack-plugin-extract-css-assets/test/cases/weird-path/webpack.config.js @@ -1,5 +1,5 @@ const MiniCssExtractPlugin = require('mini-css-extract-plugin'); -const ExtractCssAssetsPlugin = require('../../../src/cjs'); +const ExtractCssAssetsPlugin = require('../../../src/index'); module.exports = { entry: './index', @@ -31,7 +31,7 @@ module.exports = { filename: '[name].css', chunkFilename: '[id].css', }), - new ExtractCssAssetsPlugin({ + new ExtractCssAssetsPlugin.default({ outputPath: 'cssassets/', }), ], From 0607b7256e28c37c02c38aa77a0bbd04f1e44450 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8B=92=E7=8B=92=E7=A5=9E?= Date: Tue, 30 Nov 2021 18:36:35 +0800 Subject: [PATCH 2/9] chore: avoid show tabbar in every page (#4974) Co-authored-by: ClarkXia --- .../src/template/rax/TabBar.tsx.ejs | 45 +++++++-- yarn.lock | 99 ++++++------------- 2 files changed, 69 insertions(+), 75 deletions(-) diff --git a/packages/build-mpa-config/src/template/rax/TabBar.tsx.ejs b/packages/build-mpa-config/src/template/rax/TabBar.tsx.ejs index 8ceb94c383..f117bf7f22 100644 --- a/packages/build-mpa-config/src/template/rax/TabBar.tsx.ejs +++ b/packages/build-mpa-config/src/template/rax/TabBar.tsx.ejs @@ -1,31 +1,64 @@ import { createElement, Component, Fragment } from 'rax'; -import { isNode, isWeb } from 'universal-env'; +import { isWeb } from 'universal-env'; import TabBar from '<%= tabBarPath %>'; +declare const my:any; + const currentPageName = '<%= entryName %>'; const isPHA = isWeb && (window as any).pha; const isFRM = isWeb && typeof my !== 'undefined' && my.isFRM === true; -const shouldRenderTabBar = isNode || (!isPHA && !isFRM); + +interface ITabItem { + path?: string; + pageName?: string; + name?: string; + icon?: string; + activeIcon?: string; +} + +interface ITabBarConfig { + textColor?: string; + selectedColor?: string; + backgroundColor?: string; + items?: ITabItem[]; + list?: string[]; + [key: string]: unknown; +} export default class TabBarWrapper extends Component { + __shouldRenderTabBar = false; + config: ITabBarConfig = <%- JSON.stringify(tabBarConfig) %> + + constructor(props) { + super(props); + + if (isPHA || isFRM) { + this.__shouldRenderTabBar = false; + } else if (this.config.list) { + this.__shouldRenderTabBar = this.config.list.includes(currentPageName); + } else { + this.__shouldRenderTabBar = this.config.items.some(item => item.pageName === currentPageName); + } + } + handleTabItemClick = ({ path, pageName }) => { if (path) { (window as any).location.href = path; } else { - (window as any).location.href = `./${pageName}.html`; + (window as any).location.href = `/${pageName}.html`; } } render() { - if (!shouldRenderTabBar) return null; + if (!this.__shouldRenderTabBar) return null; return <% if (tabBarPath.indexOf('src') > -1) {%>
- } currentPageName={currentPageName} /> +
<% } else { %> - } onClick={this.handleTabItemClick} currentPageName={currentPageName} /> + <% } %>
; } diff --git a/yarn.lock b/yarn.lock index 794edc7450..50fbff7d19 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1316,6 +1316,18 @@ resolved "https://registry.yarnpkg.com/@builder/swc-win32-x64-msvc/-/swc-win32-x64-msvc-0.1.2.tgz#49734c9e853b697871a62165d3e967525a4a33d6" integrity sha512-ug9991/8sIJ0TqaiWmMEEnZvVcdeFMfdQFOU3OegWkxJRHMxK40BHJmEgXcOK2fznuvSKrIOZt4ghvfYRLECig== +"@builder/swc@^0.1.0": + version "0.1.3" + resolved "https://registry.yarnpkg.com/@builder/swc/-/swc-0.1.3.tgz#c3337e3a896d22dd179224674e58d062235da16e" + integrity sha512-faikwN1YjtS3JdLV8QMM7angXZuXhBPFnmgkXWP8iBh/wk+DGOWUkcybrgCt7B0rgceWHyZv/l2eNlAJI3bKfg== + dependencies: + "@napi-rs/triples" "^1.0.3" + optionalDependencies: + "@builder/swc-darwin-arm64" "^0.1.0" + "@builder/swc-darwin-x64" "^0.1.0" + "@builder/swc-linux-x64-gnu" "^0.1.0" + "@builder/swc-win32-x64-msvc" "^0.1.0" + "@cnakazawa/watch@^1.0.3": version "1.0.4" resolved "https://registry.yarnpkg.com/@cnakazawa/watch/-/watch-1.0.4.tgz#f864ae85004d0fcab6f50be9141c4da368d1656a" @@ -2990,13 +3002,6 @@ call-me-maybe "^1.0.1" glob-to-regexp "^0.3.0" -"@napi-rs/cli@^1.1.0": - version "1.3.5" - resolved "https://registry.yarnpkg.com/@napi-rs/cli/-/cli-1.3.5.tgz#89e4d97127edc4ed10a06637a43d27a1ed3c288d" - integrity sha512-Z0KZIciemioYODTyO908v2AtL8Zg4sohQDD+dyHeHmOiOfaez/y/xQ8XnpOHc2W5fRidKUW+MVWyTtpLTbKsqw== - dependencies: - inquirer "^8.1.3" - "@napi-rs/triples@^1.0.3": version "1.0.3" resolved "https://registry.yarnpkg.com/@napi-rs/triples/-/triples-1.0.3.tgz#76d6d0c3f4d16013c61e45dfca5ff1e6c31ae53c" @@ -4855,7 +4860,7 @@ bindings@^1.5.0: dependencies: file-uri-to-path "1.0.0" -bl@^4.0.3, bl@^4.1.0: +bl@^4.0.3: version "4.1.0" resolved "https://registry.yarnpkg.com/bl/-/bl-4.1.0.tgz#451535264182bec2fbbc83a62ab98cf11d9f7b3a" integrity sha512-1W07cM9gS6DcLperZfFSj+bWLtaPGSOHWhPiGzXmvVJbRLdG82sH/Kn8EtW1VqWVA54AKf2h5k5BbnIbwF3h6w== @@ -5008,6 +5013,22 @@ buffer@^5.2.1, buffer@^5.5.0: base64-js "^1.3.1" ieee754 "^1.1.13" +build-plugin-ice-router@2.0.3: + version "2.0.3" + resolved "https://registry.yarnpkg.com/build-plugin-ice-router/-/build-plugin-ice-router-2.0.3.tgz#e846fe052db186c01975426911a5d0521ca14081" + integrity sha512-GM4BhpwzYSSThh509OgDKMk4175tGKxj8zECJBkemu2egy5ytBwIJK9pTBqNwKsyTDBaIUW500ymKuL0JR4Mmw== + dependencies: + "@builder/app-helpers" "^2.0.2" + "@builder/pack" "^0.4.0" + "@types/react-router-dom" "^5.1.4" + fs-extra "^8.1.0" + glob "^7.1.6" + history "^4.10.1" + query-string "^6.12.1" + react "^16.12.0" + react-dom "^16.12.0" + react-router-dom "^5.1.2" + build-scripts-config@^3.0.0: version "3.0.3" resolved "https://registry.yarnpkg.com/build-scripts-config/-/build-scripts-config-3.0.3.tgz#bd97743a87f7f19fc36e799a2de06168352cd046" @@ -5505,7 +5526,7 @@ cli-cursor@^3.1.0: dependencies: restore-cursor "^3.1.0" -cli-spinners@^2.2.0, cli-spinners@^2.5.0: +cli-spinners@^2.2.0: version "2.6.1" resolved "https://registry.yarnpkg.com/cli-spinners/-/cli-spinners-2.6.1.tgz#adc954ebe281c37a6319bfa401e6dd2488ffb70d" integrity sha512-x/5fWmGMnbKQAaNwN+UZlV79qBLM9JFnJuJ03gIi5whrob0xV0ofNVHy9DhwGdsMJQc2OKv0oGmLzvaqvAVv+g== @@ -9247,26 +9268,6 @@ inquirer@^7.0.4, inquirer@^7.1.0: strip-ansi "^6.0.0" through "^2.3.6" -inquirer@^8.1.3: - version "8.2.0" - resolved "https://registry.yarnpkg.com/inquirer/-/inquirer-8.2.0.tgz#f44f008dd344bbfc4b30031f45d984e034a3ac3a" - integrity sha512-0crLweprevJ02tTuA6ThpoAERAGyVILC4sS74uib58Xf/zSr1/ZWtmm7D5CI+bSQEaA04f0K7idaHpQbSWgiVQ== - dependencies: - ansi-escapes "^4.2.1" - chalk "^4.1.1" - cli-cursor "^3.1.0" - cli-width "^3.0.0" - external-editor "^3.0.3" - figures "^3.0.0" - lodash "^4.17.21" - mute-stream "0.0.8" - ora "^5.4.1" - run-async "^2.4.0" - rxjs "^7.2.0" - string-width "^4.1.0" - strip-ansi "^6.0.0" - through "^2.3.6" - inspector-dom@^0.1.1: version "0.1.1" resolved "https://registry.yarnpkg.com/inspector-dom/-/inspector-dom-0.1.1.tgz#08146b2db7c347d5e28737244b47f3eabe95686f" @@ -9754,11 +9755,6 @@ is-unc-path@^1.0.0: dependencies: unc-path-regex "^0.1.2" -is-unicode-supported@^0.1.0: - version "0.1.0" - resolved "https://registry.yarnpkg.com/is-unicode-supported/-/is-unicode-supported-0.1.0.tgz#3f26c76a809593b52bfa2ecb5710ed2779b522a7" - integrity sha512-knxG2q4UC3u8stRGyAVJCOdxFmv5DZiRcdlIaAQXAbSfJya+OhopNotLQrstBhququ4ZpuKbDc/8S6mgXgPFPw== - is-utf8@^0.2.0: version "0.2.1" resolved "https://registry.yarnpkg.com/is-utf8/-/is-utf8-0.2.1.tgz#4b0da1442104d1b336340e80797e865cf39f7d72" @@ -11350,14 +11346,6 @@ log-symbols@^3.0.0: dependencies: chalk "^2.4.2" -log-symbols@^4.1.0: - version "4.1.0" - resolved "https://registry.yarnpkg.com/log-symbols/-/log-symbols-4.1.0.tgz#3fbdbb95b4683ac9fc785111e792e558d4abd503" - integrity sha512-8XPvpAA8uyhfteu8pIvQxpJZ7SYYdpUivZpGy6sFsBuKRY/7rQGavedeB8aK+Zkyq6upMFVL/9AW6vOYzfRyLg== - dependencies: - chalk "^4.1.0" - is-unicode-supported "^0.1.0" - lolex@^5.0.0: version "5.1.2" resolved "https://registry.yarnpkg.com/lolex/-/lolex-5.1.2.tgz#953694d098ce7c07bc5ed6d0e42bc6c0c6d5a367" @@ -12555,21 +12543,6 @@ ora@^4.0.3: strip-ansi "^6.0.0" wcwidth "^1.0.1" -ora@^5.4.1: - version "5.4.1" - resolved "https://registry.yarnpkg.com/ora/-/ora-5.4.1.tgz#1b2678426af4ac4a509008e5e4ac9e9959db9e18" - integrity sha512-5b6Y85tPxZZ7QytO+BQzysW31HJku27cRIlkbAXaNx+BdcVi+LlRFmVXzeF6a7JCwJpyw5c4b+YSVImQIrBpuQ== - dependencies: - bl "^4.1.0" - chalk "^4.1.0" - cli-cursor "^3.1.0" - cli-spinners "^2.5.0" - is-interactive "^1.0.0" - is-unicode-supported "^0.1.0" - log-symbols "^4.1.0" - strip-ansi "^6.0.0" - wcwidth "^1.0.1" - os-homedir@^1.0.0: version "1.0.2" resolved "https://registry.yarnpkg.com/os-homedir/-/os-homedir-1.0.2.tgz#ffbc4988336e0e833de0c168c7ef152121aa7fb3" @@ -15017,13 +14990,6 @@ rxjs@^6.4.0, rxjs@^6.6.0: dependencies: tslib "^1.9.0" -rxjs@^7.2.0: - version "7.4.0" - resolved "https://registry.yarnpkg.com/rxjs/-/rxjs-7.4.0.tgz#a12a44d7eebf016f5ff2441b87f28c9a51cebc68" - integrity sha512-7SQDi7xeTMCJpqViXh8gL/lebcwlp3d831F05+9B44A4B0WfsEwUQHR64gsH1kvJ+Ep/J9K2+n1hVl1CsGN23w== - dependencies: - tslib "~2.1.0" - safe-buffer@5.1.2, safe-buffer@~5.1.0, safe-buffer@~5.1.1: version "5.1.2" resolved "https://registry.yarnpkg.com/safe-buffer/-/safe-buffer-5.1.2.tgz#991ec69d296e0313747d59bdfd2b745c35f8828d" @@ -16679,11 +16645,6 @@ tslib@^2.0.3, tslib@^2.2.0, tslib@^2.3.0: resolved "https://registry.yarnpkg.com/tslib/-/tslib-2.3.1.tgz#e8a335add5ceae51aa261d32a490158ef042ef01" integrity sha512-77EbyPPpMz+FRFRuAFlWMtmgUWGe9UOG2Z25NqCwiIjRhOf5iKGuzSe5P2w1laq+FkRy4p+PCuVkJSGkzTEKVw== -tslib@~2.1.0: - version "2.1.0" - resolved "https://registry.yarnpkg.com/tslib/-/tslib-2.1.0.tgz#da60860f1c2ecaa5703ab7d39bc05b6bf988b97a" - integrity sha512-hcVC3wYEziELGGmEEXue7D75zbwIIVUMWAVbHItGPx0ziyXxrOMQx4rQEVEV45Ut/1IotuEvwqPopzIOkDMf0A== - tsscmp@1.0.6: version "1.0.6" resolved "https://registry.yarnpkg.com/tsscmp/-/tsscmp-1.0.6.tgz#85b99583ac3589ec4bfef825b5000aa911d605eb" From e275696cc95c8ef86d45cb729c43b2cb21c9174c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8B=92=E7=8B=92=E7=A5=9E?= Date: Tue, 30 Nov 2021 18:36:47 +0800 Subject: [PATCH 3/9] chore: avoid render error when add el to body (#4959) * chore: avoid render error when add el to body * chore: add comment Co-authored-by: ClarkXia --- packages/miniapp-renderer/src/miniappRenderer.tsx | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/packages/miniapp-renderer/src/miniappRenderer.tsx b/packages/miniapp-renderer/src/miniappRenderer.tsx index f282c172bc..fca2e79b27 100644 --- a/packages/miniapp-renderer/src/miniappRenderer.tsx +++ b/packages/miniapp-renderer/src/miniappRenderer.tsx @@ -17,7 +17,7 @@ function miniappRenderer( initAppLifeCycles(); const { app = {} } = appConfig; - const { ErrorBoundaryFallback, onErrorBoundaryHander, onErrorBoundaryHandler, errorBoundary } = app; + const { ErrorBoundaryFallback, onErrorBoundaryHander, onErrorBoundaryHandler, errorBoundary, rootId = 'root' } = app; ErrorBoundary = errorBoundary ? ErrorBoundary : null; const onError = onErrorBoundaryHander || onErrorBoundaryHandler; @@ -37,13 +37,18 @@ function miniappRenderer( // Add page config to page component const Page = component(); Page.__pageConfig = route; + // Deprecate in rax-app v4.0 + // miniapp root element is the root node, which avoid developer render extra element to document.body, it will override the page component + const rootEl = document.createElement('div'); + rootEl.setAttribute('id', rootId); const appInstance = mount(getRenderApp(Page, runtime, { ErrorBoundary, ErrorBoundaryFallback, onError, - }), document.body); + }), rootEl); - (document as any).__unmount = unmount(appInstance, document.body); + document.body.appendChild(rootEl); + (document as any).__unmount = unmount(appInstance, rootEl); }, setDocument(value) { // eslint-disable-next-line no-global-assign From 3fea90072edba8234af4b612235345b419a0bb78 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=82=BD=E7=BF=8E?= <45777252+wjq990112@users.noreply.github.com> Date: Thu, 2 Dec 2021 10:37:16 +0800 Subject: [PATCH 4/9] fix: postcss plugin resolve (#4967) * fix: resolve postcss plugin * fix: concat plugins from `build.json` when `postcss-loader` is v3.0.0 * feat: compact postcss options in different version of postcss-loader * chore: bump version & add changelog * fix: code style --- package.json | 4 +- packages/build-user-config/CHANGELOG.md | 7 +- .../__snapshots__/postcssOptions.test.js.snap | 81 +++++++ .../__tests__/postcssOptions.test.js | 215 ++++++++++++++++++ packages/build-user-config/package.json | 10 +- .../src/userConfig/postcssOptions.js | 185 ++++++++++----- packages/build-user-config/tsconfig.json | 1 + yarn.lock | 12 +- 8 files changed, 446 insertions(+), 69 deletions(-) create mode 100644 packages/build-user-config/__tests__/__snapshots__/postcssOptions.test.js.snap create mode 100644 packages/build-user-config/__tests__/postcssOptions.test.js diff --git a/package.json b/package.json index 6160c1d1c8..a1c3a0b440 100644 --- a/package.json +++ b/package.json @@ -44,6 +44,7 @@ "devDependencies": { "@commitlint/cli": "^8.2.0", "@ice/spec": "^1.0.0", + "@napi-rs/cli": "^1.1.0", "@testing-library/react-hooks": "^3.2.1", "@types/dts-bundle": "^0.0.32", "@types/jest": "^25.2.1", @@ -74,8 +75,7 @@ "simple-git": "^1.132.0", "ts-jest": "^26.0.0", "ts-node": "^9.0.0", - "typescript": "^4.0.0", - "@napi-rs/cli": "^1.1.0" + "typescript": "^4.0.0" }, "dependencies": { "core-js": "^3.6.4" diff --git a/packages/build-user-config/CHANGELOG.md b/packages/build-user-config/CHANGELOG.md index f7df1a6d46..a5e3fd03ad 100644 --- a/packages/build-user-config/CHANGELOG.md +++ b/packages/build-user-config/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog +## 1.1.9 + +- [feat] compact compact postcss options in different version of postcss-loader + ## 1.1.8 - [fix] re-calculate webpack cache id when config `disableRuntime` @@ -43,7 +47,6 @@ - [feat] refactor config of eslint - [feat] support active minify in dev - ## 1.0.2 - [fix] add dependency of eslint-reporting-webpack-plugin @@ -82,7 +85,7 @@ ## 0.3.7 -- [feat] add `devServer.host` to https cert +- [feat] add `devServer.host` to https cert - [chore] `tabItem.path` => `tabItem.pageName`/ `tabItem.name` => `tabItem.text` - [fix] compatible with no loader specified when using `postcssrc: true` in ssr app diff --git a/packages/build-user-config/__tests__/__snapshots__/postcssOptions.test.js.snap b/packages/build-user-config/__tests__/__snapshots__/postcssOptions.test.js.snap new file mode 100644 index 0000000000..d0e6fda7ee --- /dev/null +++ b/packages/build-user-config/__tests__/__snapshots__/postcssOptions.test.js.snap @@ -0,0 +1,81 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`merge postcss options when postcss-loader is v3 should convert default options in rax correctly 1`] = ` +Object { + "plugins": Array [ + [Function], + [Function], + [Function], + ], + "sourceMap": true, +} +`; + +exports[`merge postcss options when postcss-loader is v3 should convert root options correctly 1`] = ` +Object { + "config": Object {}, + "exec": true, + "parser": "sugarss", + "plugins": Array [ + [Function], + [Function], + [Function], + ], + "sourceMap": false, + "stringifier": "midas", + "syntax": "sugarss", +} +`; + +exports[`merge postcss options when postcss-loader is v3 should merge plugin correctly 1`] = ` +Object { + "plugins": Array [ + [Function], + [Function], + ], + "sourceMap": true, +} +`; + +exports[`merge postcss options when postcss-loader is v5 should convert default options in rax correctly 1`] = ` +Object { + "postcssOptions": Object { + "plugins": Array [ + [Function], + [Function], + [Function], + ], + }, + "sourceMap": true, +} +`; + +exports[`merge postcss options when postcss-loader is v5 should convert root options correctly 1`] = ` +Object { + "execute": true, + "postcssOptions": Object { + "map": false, + "parser": "sugarss", + "plugins": Array [ + [Function], + [Function], + [Function], + ], + "stringifier": "midas", + "syntax": "sugarss", + }, + "sourceMap": false, +} +`; + +exports[`merge postcss options when postcss-loader is v5 should merge plugin correctly 1`] = ` +Object { + "postcssOptions": Object { + "plugins": Array [ + [Function], + [Function], + ], + }, + "sourceMap": true, +} +`; diff --git a/packages/build-user-config/__tests__/postcssOptions.test.js b/packages/build-user-config/__tests__/postcssOptions.test.js new file mode 100644 index 0000000000..a25f9f0e0c --- /dev/null +++ b/packages/build-user-config/__tests__/postcssOptions.test.js @@ -0,0 +1,215 @@ +import Config from 'webpack-chain'; +import postcssOptions from '../src/userConfig/postcssOptions'; + +let config = null; +let consoleWarn = console.warn; + +// silent warn of postcss plugin +beforeAll(() => { + console.warn = jest.fn(); +}); + +afterAll(() => { + console.warn = consoleWarn; +}); + +describe('merge postcss options when postcss-loader is v3', () => { + beforeEach(() => { + config = new Config(); + + config.module + .rule('css') + .use('postcss-loader') + .loader(require.resolve('postcss-loader')) + .options({ + sourceMap: true, + plugins: [ + 'postcss-import', + [ + 'postcss-preset-env', + { + autoprefixer: { + flexbox: 'no-2009', + }, + stage: 3, + }, + ], + 'postcss-plugin-rpx2vw', + ], + }); + }); + + afterEach(() => { + config = null; + }); + + it('should convert default options in rax correctly', () => { + const outerOptions = {}; + postcssOptions(config, outerOptions); + + const { options: innerOptions } = config.module + .rule('css') + .use('postcss-loader') + // @ts-ignore + .toConfig(); + + expect(innerOptions.sourceMap).toEqual(true); + expect(innerOptions.plugins).toHaveLength(3); + expect(innerOptions.postcssOptions).toBeUndefined(); + + expect(innerOptions).toMatchSnapshot(); + }); + + // see: https://github.com/webpack-contrib/postcss-loader/tree/v3.0.0#options + it('should convert root options correctly', () => { + const outerOptions = { + exec: true, + sourceMap: false, + parser: 'sugarss', + syntax: 'sugarss', + stringifier: 'midas', + config: {}, + plugins: [], + }; + postcssOptions(config, outerOptions); + + const { options: innerOptions } = config.module + .rule('css') + .use('postcss-loader') + // @ts-ignore + .toConfig(); + + expect(innerOptions.exec).toEqual(true); + expect(innerOptions.sourceMap).toEqual(false); + expect(innerOptions.parser).toEqual('sugarss'); + expect(innerOptions.syntax).toEqual('sugarss'); + expect(innerOptions.stringifier).toEqual('midas'); + expect(innerOptions.config).toMatchObject({}); + expect(innerOptions.plugins).toHaveLength(3); + + expect(innerOptions).toMatchSnapshot(); + }); + + it('should merge plugin correctly', () => { + const outerOptions = { + plugins: { + 'postcss-plugin-rpx2vw': false, + }, + }; + postcssOptions(config, outerOptions); + + const { options: innerOptions } = config.module + .rule('css') + .use('postcss-loader') + // @ts-ignore + .toConfig(); + + expect(innerOptions.sourceMap).toEqual(true); + expect(innerOptions.plugins).toHaveLength(2); + + expect(innerOptions).toMatchSnapshot(); + }); +}); + +describe('merge postcss options when postcss-loader is v5', () => { + beforeEach(() => { + config = new Config(); + + config.module + .rule('css') + .use('postcss-loader') + .loader(require.resolve('postcss-loader')) + .options({ + sourceMap: true, + postcssOptions: { + plugins: [ + 'postcss-import', + [ + 'postcss-preset-env', + { + autoprefixer: { + flexbox: 'no-2009', + }, + stage: 3, + }, + ], + 'postcss-plugin-rpx2vw', + ], + }, + }); + }); + + afterEach(() => { + config = null; + }); + + it('should convert default options in rax correctly', () => { + const outerOptions = {}; + postcssOptions(config, outerOptions); + + const { options: innerOptions } = config.module + .rule('css') + .use('postcss-loader') + // @ts-ignore + .toConfig(); + + expect(innerOptions.sourceMap).toEqual(true); + expect(innerOptions.plugins).toBeUndefined(); + expect(innerOptions.postcssOptions).toBeDefined(); + expect(innerOptions.postcssOptions.plugins).toHaveLength(3); + + expect(innerOptions).toMatchSnapshot(); + }); + + // see: https://github.com/webpack-contrib/postcss-loader/tree/v5.3.0#options + it('should convert root options correctly', () => { + const outerOptions = { + exec: true, + sourceMap: false, + parser: 'sugarss', + syntax: 'sugarss', + stringifier: 'midas', + plugins: [], + map: false, + }; + + postcssOptions(config, outerOptions); + + const { options: innerOptions } = config.module + .rule('css') + .use('postcss-loader') + // @ts-ignore + .toConfig(); + + expect(innerOptions.execute).toEqual(true); + expect(innerOptions.exec).toBeUndefined(); + expect(innerOptions.sourceMap).toEqual(false); + expect(innerOptions.postcssOptions.parser).toEqual('sugarss'); + expect(innerOptions.postcssOptions.syntax).toEqual('sugarss'); + expect(innerOptions.postcssOptions.stringifier).toEqual('midas'); + expect(innerOptions.postcssOptions.plugins).toHaveLength(3); + expect(innerOptions.postcssOptions.map).toEqual(false); + + expect(innerOptions).toMatchSnapshot(); + }); + + it('should merge plugin correctly', () => { + const outerOptions = { + plugins: { + 'postcss-plugin-rpx2vw': false, + }, + }; + postcssOptions(config, outerOptions); + + const { options: innerOptions } = config.module + .rule('css') + .use('postcss-loader') + // @ts-ignore + .toConfig(); + + expect(innerOptions.sourceMap).toEqual(true); + expect(innerOptions.postcssOptions.plugins).toHaveLength(2); + + expect(innerOptions).toMatchSnapshot(); + }); +}); diff --git a/packages/build-user-config/package.json b/packages/build-user-config/package.json index b980385d38..2d1d615865 100644 --- a/packages/build-user-config/package.json +++ b/packages/build-user-config/package.json @@ -1,6 +1,6 @@ { "name": "@builder/user-config", - "version": "1.1.8", + "version": "1.1.9", "description": "Includes methods which are releated to set base user config for framework", "homepage": "", "license": "MIT", @@ -26,6 +26,12 @@ "trusted-cert": "^1.0.0", "@builder/webpack-plugin-swc": "^1.0.0" }, + "devDependencies": { + "postcss-import": "^12.0.1", + "postcss-plugin-rpx2vw": "^0.0.2", + "postcss-preset-env": "^6.7.0", + "webpack-chain": "^6.5.1" + }, "files": [ "lib", "!lib/**/*.map" @@ -40,4 +46,4 @@ "bugs": { "url": "https://github.com/alibaba/ice/issues" } -} \ No newline at end of file +} diff --git a/packages/build-user-config/src/userConfig/postcssOptions.js b/packages/build-user-config/src/userConfig/postcssOptions.js index 8be505ae1e..c500e121a3 100644 --- a/packages/build-user-config/src/userConfig/postcssOptions.js +++ b/packages/build-user-config/src/userConfig/postcssOptions.js @@ -1,100 +1,161 @@ -const checkPostcssLoader = (config, ruleName) => config.module.rules.has(ruleName) && config.module.rule(ruleName).uses.has('postcss-loader'); +const checkPostcssLoader = (config, ruleName) => + config.module.rules.has(ruleName) && + config.module.rule(ruleName).uses.has('postcss-loader'); -module.exports = (config, postcssOptions) => { - if (postcssOptions) { - const styleRules = ['css', 'css-module', 'css-global', 'scss', 'scss-module', 'scss-global', 'less', 'less-module', 'less-global']; - let finalPostcssOptions = {}; - let restLoaderOptions = {}; - // get default post css config - if (checkPostcssLoader(config, 'css')) { - const builtInOptions = config.module.rule('css').use('postcss-loader').get('options'); - if (builtInOptions) { - const { config: optionConfig, ...restOptions } = builtInOptions; - if (restOptions) { - restLoaderOptions = restOptions; - } - if (builtInOptions.config && builtInOptions.config.path) { - try { - const postcssFile = `${optionConfig.path}/defaultPostcssConfig`; - finalPostcssOptions = { - // eslint-disable-next-line - postcssOptions: (optionConfig.ctx ? require(postcssFile)(optionConfig.ctx) : require(postcssFile)) || {} - }; - } catch(err) { - console.log('[Error] fail to load default postcss config'); - } - } else { - // compatible with rax config - finalPostcssOptions = builtInOptions || { - postcssOptions: { - plugins: [] - } - }; - } +module.exports = (config, postcssOptions, context) => { + if (!postcssOptions) { + return; + } + + const customPostcssOptions = { ...postcssOptions }; + + const styleRules = [ + 'css', + 'css-module', + 'css-global', + 'scss', + 'scss-module', + 'scss-global', + 'less', + 'less-module', + 'less-global', + ]; + const { rootDir = '' } = context || {}; + let finalPostcssOptions = {}; + + // get default postcss config + if (checkPostcssLoader(config, 'css')) { + const builtInOptions = + config.module.rule('css').use('postcss-loader').get('options') || {}; + const { config: loaderConfigOptions } = builtInOptions; + if (loaderConfigOptions && loaderConfigOptions.path) { + try { + const postcssFile = `${loaderConfigOptions.path}/defaultPostcssConfig`; + finalPostcssOptions = { + postcssOptions: + (loaderConfigOptions.ctx + ? // eslint-disable-next-line + require(postcssFile)(loaderConfigOptions.ctx) + : // eslint-disable-next-line + require(postcssFile)) || {}, + }; + } catch (err) { + console.log('[Error] fail to load default postcss config'); } + } else { + finalPostcssOptions = builtInOptions; } + + // get plugins in different versions of postcss-loader + let builtInPlugins = []; if (!finalPostcssOptions.postcssOptions) { - // set default plugin value - finalPostcssOptions.postcssOptions = { - plugins: [], - }; + // get plugins in v3 + builtInPlugins = [...(finalPostcssOptions.plugins || [])]; + } else { + // get plugins in v5 + builtInPlugins = [...(finalPostcssOptions.postcssOptions.plugins || [])]; } // merge plugins - const { plugins = [] } = finalPostcssOptions.postcssOptions; - const finalPlugins = [...plugins]; - Object.keys(postcssOptions.plugins || {}).forEach((pluginName) => { + const finalPlugins = [...builtInPlugins]; + Object.keys(customPostcssOptions.plugins || {}).forEach((pluginName) => { let pluginOptions = {}; - const targetIndex = plugins.findIndex((pluginConfig) => { - const [name, options] = Array.isArray(pluginConfig) ? pluginConfig : [pluginConfig]; + const targetIndex = builtInPlugins.findIndex((pluginConfig) => { + const [name, options] = Array.isArray(pluginConfig) + ? pluginConfig + : [pluginConfig]; if (options) { pluginOptions = options; } return typeof name === 'string' && name.indexOf(pluginName) > -1; }); - const options = postcssOptions.plugins[pluginName]; + const options = customPostcssOptions.plugins[pluginName]; if (targetIndex > -1) { if (options === false) { // delete builtIn plugin finalPlugins.splice(targetIndex, 1); } else { // shallow merge for options - const mergedOptions = {...pluginOptions, ...options}; + const mergedOptions = { ...pluginOptions, ...options }; finalPlugins.splice(targetIndex, 1, [pluginName, mergedOptions]); } } else { finalPlugins.push([pluginName, options]); } }); + delete customPostcssOptions.plugins; + const postcssPlugins = finalPlugins.map((pluginInfo) => { - const [name, options] = Array.isArray(pluginInfo) ? pluginInfo : [pluginInfo]; + const [name, options] = Array.isArray(pluginInfo) + ? pluginInfo + : [pluginInfo]; if (typeof name === 'string') { + const resolvePath = require.resolve(name, { paths: [rootDir] }); // eslint-disable-next-line - return require(name)(options); + return require(resolvePath)(options); } else { return pluginInfo; } }); - // remove k-v plugins options - const originalPostcssOptions = { - ...postcssOptions, - }; - delete originalPostcssOptions.plugins; + + if (!finalPostcssOptions.postcssOptions) { + // set final postcss options in v3 + finalPostcssOptions = { + ...finalPostcssOptions, + ...customPostcssOptions, + plugins: [...postcssPlugins], + }; + } else { + // set default value + customPostcssOptions.postcssOptions = + customPostcssOptions.postcssOptions || {}; + + // modify option name `exec` to `execute` in v5 + if (customPostcssOptions.exec) { + customPostcssOptions.execute = customPostcssOptions.exec; + delete customPostcssOptions.exec; + } + + const shouldMoveToPostcssOptionsKeys = [ + 'parser', + 'syntax', + 'stringifier', + 'from', + 'to', + 'map', + ]; + + // move options to postcssOptions + Object.keys(customPostcssOptions || {}).forEach((optionName) => { + if (shouldMoveToPostcssOptionsKeys.includes(optionName)) { + customPostcssOptions.postcssOptions[optionName] = + customPostcssOptions[optionName]; + delete customPostcssOptions[optionName]; + } + }); + + // set final postcss options in v5 + finalPostcssOptions = { + ...finalPostcssOptions, + ...customPostcssOptions, + postcssOptions: { + ...finalPostcssOptions.postcssOptions, + ...customPostcssOptions.postcssOptions, + plugins: [...postcssPlugins], + }, + }; + } + // modify css rules styleRules.forEach((ruleName) => { if (checkPostcssLoader(config, ruleName)) { - config.module.rule(ruleName).use('postcss-loader').tap(() => { - // merge postcss-loader options - return { - ...restLoaderOptions, - ...finalPostcssOptions, - postcssOptions: { - ...finalPostcssOptions.postcssOptions, - ...originalPostcssOptions, - plugins: postcssPlugins, - } - }; - }); + config.module + .rule(ruleName) + .use('postcss-loader') + .tap(() => { + // merge postcss-loader options + return finalPostcssOptions; + }); } }); } diff --git a/packages/build-user-config/tsconfig.json b/packages/build-user-config/tsconfig.json index 1ba6ca74d5..7e91380009 100644 --- a/packages/build-user-config/tsconfig.json +++ b/packages/build-user-config/tsconfig.json @@ -5,4 +5,5 @@ "rootDir": "src", "outDir": "lib" }, + "include": ["src"] } diff --git a/yarn.lock b/yarn.lock index 50fbff7d19..d6c8529d9a 100644 --- a/yarn.lock +++ b/yarn.lock @@ -13265,6 +13265,16 @@ postcss-image-set-function@^3.0.1: postcss "^7.0.2" postcss-values-parser "^2.0.0" +postcss-import@^12.0.1: + version "12.0.1" + resolved "https://registry.yarnpkg.com/postcss-import/-/postcss-import-12.0.1.tgz#cf8c7ab0b5ccab5649024536e565f841928b7153" + integrity sha512-3Gti33dmCjyKBgimqGxL3vcV8w9+bsHwO5UrBawp796+jdardbcFl4RP5w/76BwNL7aGzpKstIfF9I+kdE8pTw== + dependencies: + postcss "^7.0.1" + postcss-value-parser "^3.2.3" + read-cache "^1.0.0" + resolve "^1.1.7" + postcss-import@^14.0.2: version "14.0.2" resolved "https://registry.yarnpkg.com/postcss-import/-/postcss-import-14.0.2.tgz#60eff77e6be92e7b67fe469ec797d9424cae1aa1" @@ -13789,7 +13799,7 @@ postcss-unique-selectors@^4.0.1: postcss "^7.0.0" uniqs "^2.0.0" -postcss-value-parser@^3.0.0, postcss-value-parser@^3.3.0: +postcss-value-parser@^3.0.0, postcss-value-parser@^3.2.3, postcss-value-parser@^3.3.0: version "3.3.1" resolved "https://registry.yarnpkg.com/postcss-value-parser/-/postcss-value-parser-3.3.1.tgz#9ff822547e2893213cf1c30efa51ac5fd1ba8281" integrity sha512-pISE66AbVkp4fDQ7VHBwRNXzAAKJjw4Vw7nWI/+Q3vuly7SNfgYXvm6i5IgFylHGK5sP/xHAbB7N49OS4gWNyQ== From 32a56a2ee5f2940f5207dbdfadd2694165d0b331 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A4=A7=E6=9E=9C?= Date: Thu, 2 Dec 2021 10:44:03 +0800 Subject: [PATCH 5/9] refactor: optimize router (#4814) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * chore: add useful log for router * fix: renderComponent -> app.renderComponent * fix: renderComponent -> app.renderComponent * feat: spa support renderComponent * chore: add example * chore: build-plugin-app-core remove npmlog * feat: support disable request plugin * feat: wrapper page in plugin-app-core(not yet plugin-router) * chore: optimize examples * chore: move wrapper page to plugin-react-app * chore: optimize router log * feat: register enableRouter in runtime * fix: enableRouter typo error * feat: add mpa to runtime buildConfig * chore: runtime buildConfig.router -> enableRouter * chore: optimize example * chore: bump version and add changelog * fix: ts type * fix: example app.renderComponent * fix: eslint and remove log * test: add icestark-layout test case * chore: try test case * fix: addProvider not work * chore: add store test case * chore: try test case * chore: try test case * chore: try test case * chore: add npm install before test * chore: enable all test * chore: fix test install * feat: ssr search params (#4987) * feat: ssr search params * feat: support renderComponent ssr * chore: add comment * feat: add enableRouter to context * chore: add changelog * fix: ssr error Co-authored-by: ClarkXia Co-authored-by: 狒狒神 --- examples/basic-mpa/build.json | 1 - examples/basic-mpa/src/pages/About/app.tsx | 12 ++ examples/basic-mpa/src/pages/About/index.tsx | 11 ++ .../basic-mpa/src/pages/Dashboard/app.tsx | 2 +- examples/basic-mpa/src/pages/Profile/app.tsx | 18 ++ .../basic-mpa/src/pages/Profile/index.tsx | 9 +- .../src/pages/Profile/models/counter.ts | 14 ++ examples/basic-mpa/src/pages/Profile/store.ts | 6 + examples/basic-spa/build.json | 1 + examples/basic-spa/src/app.tsx | 4 +- .../src/pages/About/components/Child.tsx | 2 +- .../src/pages/About/components/Todo.tsx | 2 +- examples/icestark-layout/build.json | 1 - examples/icestark-layout/src/app.tsx | 9 +- examples/icestark-layout/src/pages/index.tsx | 5 + examples/spa-renderComponent/build.json | 7 + examples/spa-renderComponent/package.json | 15 ++ .../spa-renderComponent/public/favicon.png | Bin 0 -> 4943 bytes .../spa-renderComponent/public/index.html | 13 ++ .../spa-renderComponent/sandbox.config.json | 6 + examples/spa-renderComponent/src/Test.tsx | 27 +++ .../src/app.tsx} | 7 +- .../spa-renderComponent/src/models/counter.ts | 14 ++ examples/spa-renderComponent/src/store.ts | 6 + examples/spa-renderComponent/tsconfig.json | 38 +++++ .../src/pages/About/app.tsx | 4 +- .../src/pages/Home/app.tsx | 4 +- packages/build-app-templates/CHANGELOG.md | 7 +- packages/build-app-templates/package.json | 2 +- .../src/templates/rax/routerAPI.ts.ejs | 2 + .../src/templates/rax/runApp.ts.ejs | 21 ++- .../src/templates/react/routerAPI.ts.ejs | 2 + .../src/templates/react/runApp.ts.ejs | 16 +- packages/build-mpa-config/CHANGELOG.md | 5 + packages/build-mpa-config/package.json | 4 +- .../src/generate/BaseGenerator.ts | 7 +- .../src/template/rax/index.tsx.ejs | 4 +- .../src/template/react/index.tsx.ejs | 4 +- packages/build-user-config/README.md | 3 - packages/create-app-shared/CHANGELOG.md | 6 + packages/create-app-shared/package.json | 2 +- .../create-app-shared/src/createBaseApp.ts | 1 + .../create-app-shared/src/getSearchParams.ts | 13 +- .../src/miniapp/getSearchParams.ts | 2 +- .../create-app-shared/src/runtimeModule.ts | 31 +++- packages/create-app-shared/src/types.ts | 7 +- packages/create-app-shared/src/web/history.ts | 3 +- packages/icejs/package.json | 2 +- packages/icejs/src/getBuiltInPlugins.ts | 13 +- packages/plugin-app-core/CHANGELOG.md | 7 + packages/plugin-app-core/package.json | 7 +- packages/plugin-app-core/src/constant.ts | 8 + .../generator/templates/types/index.ts.ejs | 2 + packages/plugin-app-core/src/index.ts | 5 + packages/plugin-app-core/src/runtime.tsx | 7 - .../src/utils/getBuildConfig.ts | 6 +- packages/plugin-ice-ssr/CHANGELOG.md | 4 + packages/plugin-ice-ssr/package.json | 4 +- packages/plugin-ice-ssr/src/server.ts.ejs | 52 ++++-- packages/plugin-react-app/CHANGELOG.md | 5 + packages/plugin-react-app/package.json | 9 +- packages/plugin-react-app/src/index.js | 3 + packages/plugin-react-app/src/runtime.tsx | 154 ++++++++++++++++++ packages/plugin-router/CHANGELOG.md | 4 + packages/plugin-router/package.json | 7 +- packages/plugin-router/src/index.ts | 131 +++++++-------- packages/plugin-router/src/runtime.tsx | 39 +---- packages/plugin-router/src/runtime/_routes.ts | 1 - .../src/runtime/formatRoutes.tsx | 60 ------- packages/react-app-renderer/CHANGELOG.md | 4 + packages/react-app-renderer/package.json | 2 +- packages/react-app-renderer/src/server.tsx | 10 +- packages/react-app-renderer/src/types.ts | 5 +- test/basic-icestark-layout.test.ts | 47 ++++++ test/utils/build.ts | 1 + test/utils/executeCommand.ts | 9 + test/utils/start.ts | 3 +- yarn.lock | 10 ++ 78 files changed, 727 insertions(+), 274 deletions(-) create mode 100644 examples/basic-mpa/src/pages/About/app.tsx create mode 100644 examples/basic-mpa/src/pages/About/index.tsx create mode 100644 examples/basic-mpa/src/pages/Profile/app.tsx create mode 100644 examples/basic-mpa/src/pages/Profile/models/counter.ts create mode 100644 examples/basic-mpa/src/pages/Profile/store.ts create mode 100644 examples/icestark-layout/src/pages/index.tsx create mode 100644 examples/spa-renderComponent/build.json create mode 100644 examples/spa-renderComponent/package.json create mode 100644 examples/spa-renderComponent/public/favicon.png create mode 100644 examples/spa-renderComponent/public/index.html create mode 100644 examples/spa-renderComponent/sandbox.config.json create mode 100644 examples/spa-renderComponent/src/Test.tsx rename examples/{basic-mpa/src/pages/Profile/app.ts => spa-renderComponent/src/app.tsx} (53%) create mode 100644 examples/spa-renderComponent/src/models/counter.ts create mode 100644 examples/spa-renderComponent/src/store.ts create mode 100644 examples/spa-renderComponent/tsconfig.json delete mode 100644 packages/plugin-app-core/src/runtime.tsx create mode 100644 packages/plugin-react-app/src/runtime.tsx create mode 100644 test/basic-icestark-layout.test.ts create mode 100644 test/utils/executeCommand.ts diff --git a/examples/basic-mpa/build.json b/examples/basic-mpa/build.json index 2c76fe5216..514788a6cc 100644 --- a/examples/basic-mpa/build.json +++ b/examples/basic-mpa/build.json @@ -1,5 +1,4 @@ { - "router": false, "vite": true, "mpa": { "openPage": "Dashboard", diff --git a/examples/basic-mpa/src/pages/About/app.tsx b/examples/basic-mpa/src/pages/About/app.tsx new file mode 100644 index 0000000000..bcbbb57280 --- /dev/null +++ b/examples/basic-mpa/src/pages/About/app.tsx @@ -0,0 +1,12 @@ +import React from 'react'; +import { runApp, IAppConfig } from 'ice'; +import Index from './index'; + +const appConfig: IAppConfig = { + router: { + type: 'hash', + routes: [{ path: '/', component: Index }], + }, +}; + +runApp(appConfig); diff --git a/examples/basic-mpa/src/pages/About/index.tsx b/examples/basic-mpa/src/pages/About/index.tsx new file mode 100644 index 0000000000..ea759ec365 --- /dev/null +++ b/examples/basic-mpa/src/pages/About/index.tsx @@ -0,0 +1,11 @@ +import React from 'react'; + +const About = () => { + return ( + <> +

About Page...

+ + ); +}; + +export default About; diff --git a/examples/basic-mpa/src/pages/Dashboard/app.tsx b/examples/basic-mpa/src/pages/Dashboard/app.tsx index 784d3e8e0b..97d6cf42e2 100644 --- a/examples/basic-mpa/src/pages/Dashboard/app.tsx +++ b/examples/basic-mpa/src/pages/Dashboard/app.tsx @@ -7,7 +7,7 @@ const Provider = store.Provider; const appConfig: IAppConfig = { router: { - routes + routes, }, app: { addProvider({ children }) { diff --git a/examples/basic-mpa/src/pages/Profile/app.tsx b/examples/basic-mpa/src/pages/Profile/app.tsx new file mode 100644 index 0000000000..c383d9529f --- /dev/null +++ b/examples/basic-mpa/src/pages/Profile/app.tsx @@ -0,0 +1,18 @@ +import * as React from 'react'; +import { runApp, IAppConfig } from 'ice'; +import Page from './index'; +import store from './store'; + +const Provider = store.Provider; + +const appConfig: IAppConfig = { + app: { + rootId: 'custom-container', + renderComponent: Page, + addProvider: ({ children }) => { + return {children}; + } + }, +}; + +runApp(appConfig); diff --git a/examples/basic-mpa/src/pages/Profile/index.tsx b/examples/basic-mpa/src/pages/Profile/index.tsx index e8aa055275..8c602c179b 100644 --- a/examples/basic-mpa/src/pages/Profile/index.tsx +++ b/examples/basic-mpa/src/pages/Profile/index.tsx @@ -1,9 +1,16 @@ import React from 'react'; +import store from './store'; const Profile = () => { + const [pageState, pageActions] = store.useModel('counter'); return ( <> -

Profile Page

+

Profile Page...

+
+ + {pageState.count} + +
); }; diff --git a/examples/basic-mpa/src/pages/Profile/models/counter.ts b/examples/basic-mpa/src/pages/Profile/models/counter.ts new file mode 100644 index 0000000000..4f1567bc2d --- /dev/null +++ b/examples/basic-mpa/src/pages/Profile/models/counter.ts @@ -0,0 +1,14 @@ +export default { + state: { + count: 0 + }, + + reducers: { + increment (prevState) { + return { count: prevState.count + 1 }; + }, + decrement (prevState) { + return { count: prevState.count - 1 }; + } + } +}; diff --git a/examples/basic-mpa/src/pages/Profile/store.ts b/examples/basic-mpa/src/pages/Profile/store.ts new file mode 100644 index 0000000000..fd399d4f11 --- /dev/null +++ b/examples/basic-mpa/src/pages/Profile/store.ts @@ -0,0 +1,6 @@ +import { createStore } from 'ice'; +import counter from './models/counter'; + +const store = createStore({ counter }); + +export default store; diff --git a/examples/basic-spa/build.json b/examples/basic-spa/build.json index 68e20e8bdf..e522191acc 100644 --- a/examples/basic-spa/build.json +++ b/examples/basic-spa/build.json @@ -1,4 +1,5 @@ { + // "router": false, "remoteRuntime": true, "polyfill": false, "ignoreHtmlTemplate": false, diff --git a/examples/basic-spa/src/app.tsx b/examples/basic-spa/src/app.tsx index af0aaab331..d50b580a06 100644 --- a/examples/basic-spa/src/app.tsx +++ b/examples/basic-spa/src/app.tsx @@ -10,6 +10,7 @@ const appConfig: IAppConfig = { rootId: 'ice-container', errorBoundary: true, parseSearchParams: true, + // renderComponent: () => <>HELLO, getInitialData: async() => { // const result = await request('/repo'); const result = { @@ -33,7 +34,8 @@ const appConfig: IAppConfig = { router: { basename: '/ice', type: 'hash', - fallback:
加载中...
+ fallback:
加载中...
, + // routes: [{path: '/home', component: () => <>He}] }, request: { timeout: 5000, diff --git a/examples/basic-spa/src/pages/About/components/Child.tsx b/examples/basic-spa/src/pages/About/components/Child.tsx index d1f089ace7..13fef92bf8 100644 --- a/examples/basic-spa/src/pages/About/components/Child.tsx +++ b/examples/basic-spa/src/pages/About/components/Child.tsx @@ -2,7 +2,7 @@ import React, { useEffect } from 'react'; const Child = () => { function getData() { - throw new Error('test Error'); + throw new Error('Child Error'); } useEffect(() => { diff --git a/examples/basic-spa/src/pages/About/components/Todo.tsx b/examples/basic-spa/src/pages/About/components/Todo.tsx index f7ea8a8476..7cee8dad0e 100644 --- a/examples/basic-spa/src/pages/About/components/Todo.tsx +++ b/examples/basic-spa/src/pages/About/components/Todo.tsx @@ -3,7 +3,7 @@ import React, { PureComponent } from 'react'; class Todo extends PureComponent { componentDidMount() { - throw new Error('test error boundary'); + throw new Error('Todo Error'); } render() { diff --git a/examples/icestark-layout/build.json b/examples/icestark-layout/build.json index e70018dd1e..f33a0bf0be 100644 --- a/examples/icestark-layout/build.json +++ b/examples/icestark-layout/build.json @@ -4,7 +4,6 @@ "plugins": [ "build-plugin-icestark", ["build-plugin-fusion", { - "themePackage": "@icedesign/theme", "themeConfig": { "nextPrefix": "next-fd-" } diff --git a/examples/icestark-layout/src/app.tsx b/examples/icestark-layout/src/app.tsx index 68d748f19d..7bdcc579f1 100644 --- a/examples/icestark-layout/src/app.tsx +++ b/examples/icestark-layout/src/app.tsx @@ -6,12 +6,9 @@ import { ConfigProvider } from '@alifd/next'; const appConfig: IAppConfig = { app: { rootId: 'ice-container', - addProvider: ({ children }) => ( - {children} - ), - }, - logger: { - level: 'warn' + addProvider: ({ children }) => { + return {children}; + }, }, router: { type: 'browser', diff --git a/examples/icestark-layout/src/pages/index.tsx b/examples/icestark-layout/src/pages/index.tsx new file mode 100644 index 0000000000..00cc799784 --- /dev/null +++ b/examples/icestark-layout/src/pages/index.tsx @@ -0,0 +1,5 @@ +import * as React from 'react'; + +export default function Home() { + return

Index Page

; +} diff --git a/examples/spa-renderComponent/build.json b/examples/spa-renderComponent/build.json new file mode 100644 index 0000000000..c1c73d2116 --- /dev/null +++ b/examples/spa-renderComponent/build.json @@ -0,0 +1,7 @@ +{ + // "vite": true, + "store": true, + "router": false, + "plugins": [], + "ssr": true +} diff --git a/examples/spa-renderComponent/package.json b/examples/spa-renderComponent/package.json new file mode 100644 index 0000000000..c799f862e1 --- /dev/null +++ b/examples/spa-renderComponent/package.json @@ -0,0 +1,15 @@ +{ + "name": "example-simple", + "dependencies": { + "react": "^16.4.1", + "react-dom": "^16.4.1" + }, + "devDependencies": { + "@types/react": "^16.9.20", + "@types/react-dom": "^16.9.5" + }, + "scripts": { + "start": "../../packages/icejs/bin/ice-cli.js start --mode dev", + "build": "../../packages/icejs/bin/ice-cli.js build --mode prod" + } +} diff --git a/examples/spa-renderComponent/public/favicon.png b/examples/spa-renderComponent/public/favicon.png new file mode 100644 index 0000000000000000000000000000000000000000..cff1ee57cfc4c3968735eb2bb2be07aff37c44f4 GIT binary patch literal 4943 zcmbVQ`A^&D9X4PNlYmWtn2>Nd0TTnp1{{vWfQt>m+*iYq03i@=3?Y;=*xIG2+9}#j ztCVbO*JawY?T2bvm#JNUXwtRSlBG)*rCOtCtEy?6wEPQu9zJirc1eHORz08dJ-+Yz zIbNJTe*3M?_LE78nTa}`F3I2I>xO*%_FKXe;zYtRY1iozC;Yx=de>k9vvWP?GayIO z8^jUiP1_iS`oVAZf+v8SaWUX!9*K6Xp_#Qc$uCnLTzi4(B26uvZe^;}Pqmj^=I9P4>Xii7BI^yQq#5}x*!%KL$ z;;6F8#-gMmnXk{DX|bB2r>c0Zr$rC~2^ z$z~R5b@oTEL9~R=#Li>sod5y3peoftH47`=$FF=1p6(eL6~1;B(#zKjU^)b>&G)}* z&D0-)GM(|+&tKrB4CP&en*o^-$>XD*TMVzoNCD`QHsd{pm=`|=;-LgN5PYH+G*1;P z^dzslkcq}vq*%>-g`Vv_3SJMokU2QWgA9UJKmZ>Mf&C<;O8K&{#0E?4CgVO| zYHT!AZaV;)WFh3Vg8`>N8BC=iI*NP5oHBx^#I(Kteahs}T1?KM-wxfRE}IiPmdgMX zg8)l%Xz@IxBQ5h_xH@G_&49?_6anwSdjUZnDb_#H-BzIYm5EQ|wW9GjtIJ?a+X~xy z`T$r~Dvwhbztj5mvRgNbSeL*a&??AVYWw6RwWm4yFg(1m1GEK-L=%jS-@m3FJO1I; zfQ5{hYH)iqbRGrRCj#7;2*z^(7e#<4F&5m?`0!WY!S}8@)TOO3|MF$m7R12d-S0vG zO)KgzY6b6WNE+t*0`!V-yL(QVyR2DamEYRl=@_vhdAsf2^+-E=3fAb(?X4r)z~aZ; zT0`oZsI~@?t<{i5OYV}oRE@ZKZlFs9OW6P5hb+#+Ax6+-;xaxr^}P1j=_%VnGed6T zYsXt1G2OkA$^@)~fEKS0yo$*J>O+g7nBBB)J`c`SPuh7vb!KfRoRv+@GZ2D=YC}G> zMQ$z7>s@RQ9_AvOqXy)kW-PfQ5bXbuqgP4s4<9nl_+-=}PQG8)P zxGMSsP*rV0bEl}M#T1=c#)|4=ke$cD1gx3jO0P$Aa2pm@S6TuSw8k4nA{|B_Xu=%n z{p|WTixOktNfNJWw{<_v)YMidgr40vCc~D8KZer4eE=Rgj}K@hCQ=e?Lly8?AHEpi zAp-2%Wtn2-z8Z?T^UZBm9x%#K=d117GZL&Ruw6@^`)Q+6D+|Df4K_{Jly%-`7dpln z&uKZAhlSTL6Y}$av z(?>$(gx_I=`vYS$)gkj)1G@7DSW`(4O9D9aBRm$SJyA7ENVtAj% z!o4@e$r8ywBKo~+ke`0(1*Tw%F?E3&Q!X-Ad|DX=0V6rY^Z^C4IZK_Q8iqvn^bL!` z=A7U9@P=5Ce8Om%y%?J1SAgTIRrW4XDGVUqIlkw#$`gwT$k~7Q2dad{q4A)q265O$ zuy09wxT$)9*d=*pR&f3>-(?`nItZTaInCN$;_sR-gysI%BmL~((7UgL^NcL=)jH;~{2Um-P;e3uF9MvC`^B13DIbNY)MBVi@(|xd14DZIYPrKW9lg@QCqcs{ zTD6*KEaRJ`A#;uA3s}KS3t*vSR$cEOSn*#7cAXit3Mw)@{MitsI^>edS9%sd7ffxj zcNm}mcdmd{j!%Mbm6r8z{yd2LB-_E3v%xlReUDd3%$RczEU!QLcQxk$&29_7$O-Bd zW4Khvx}iEig3>5w88jAr6R7pizXVq`m<9C=Xcr1Jdk-rM=x%o%;4Y6|6q~QYqn|QX zf&j$M4=25+5-O*b%E%rUFEh_};C+EcP$g?>$rX + + + + + + icejs · icestark child example + + + +
+ + diff --git a/examples/spa-renderComponent/sandbox.config.json b/examples/spa-renderComponent/sandbox.config.json new file mode 100644 index 0000000000..19b69053c1 --- /dev/null +++ b/examples/spa-renderComponent/sandbox.config.json @@ -0,0 +1,6 @@ +{ + "template": "node", + "container": { + "port": 3333 + } +} diff --git a/examples/spa-renderComponent/src/Test.tsx b/examples/spa-renderComponent/src/Test.tsx new file mode 100644 index 0000000000..75f8f3792b --- /dev/null +++ b/examples/spa-renderComponent/src/Test.tsx @@ -0,0 +1,27 @@ +import * as React from 'react'; +import { getSearchParams } from 'ice'; +import store from './store'; + +export default function Test(props) { + console.log('Test props', props); + console.log('search params', getSearchParams()); + + const [counterState, counterAction] = store.useModel('counter'); + + return <> + Hello: {props.name} +
Count: {counterState.count}
+
+
+
-
+ ; +} + +Test.pageConfig = { + title: '哈哈' +}; + +Test.getInitialProps = async (ctx) => { + return { + name: 'React(getInitialProps)' + }; +}; diff --git a/examples/basic-mpa/src/pages/Profile/app.ts b/examples/spa-renderComponent/src/app.tsx similarity index 53% rename from examples/basic-mpa/src/pages/Profile/app.ts rename to examples/spa-renderComponent/src/app.tsx index 975f0e49aa..b4ede753b4 100644 --- a/examples/basic-mpa/src/pages/Profile/app.ts +++ b/examples/spa-renderComponent/src/app.tsx @@ -1,11 +1,12 @@ import { runApp, IAppConfig } from 'ice'; -import Page from './index'; +import Test from './Test'; const appConfig: IAppConfig = { app: { - rootId: 'custom-container', + rootId: 'ice-container', + renderComponent: Test, }, - renderComponent: Page, + // router: {} }; runApp(appConfig); diff --git a/examples/spa-renderComponent/src/models/counter.ts b/examples/spa-renderComponent/src/models/counter.ts new file mode 100644 index 0000000000..c27747e341 --- /dev/null +++ b/examples/spa-renderComponent/src/models/counter.ts @@ -0,0 +1,14 @@ +export default { + state: { + count: 0, + }, + + reducers: { + increment(prevState) { + prevState.count += 1; + }, + decrement(prevState) { + prevState.count -= 1; + } + } +}; diff --git a/examples/spa-renderComponent/src/store.ts b/examples/spa-renderComponent/src/store.ts new file mode 100644 index 0000000000..fd399d4f11 --- /dev/null +++ b/examples/spa-renderComponent/src/store.ts @@ -0,0 +1,6 @@ +import { createStore } from 'ice'; +import counter from './models/counter'; + +const store = createStore({ counter }); + +export default store; diff --git a/examples/spa-renderComponent/tsconfig.json b/examples/spa-renderComponent/tsconfig.json new file mode 100644 index 0000000000..ed32230671 --- /dev/null +++ b/examples/spa-renderComponent/tsconfig.json @@ -0,0 +1,38 @@ +{ + "compileOnSave": false, + "buildOnSave": false, + "compilerOptions": { + "baseUrl": ".", + "outDir": "build", + "module": "esnext", + "target": "es6", + "jsx": "react", + "moduleResolution": "node", + "allowSyntheticDefaultImports": true, + "lib": [ + "es6", + "dom" + ], + "sourceMap": true, + "allowJs": true, + "rootDir": "./", + "forceConsistentCasingInFileNames": true, + "noImplicitReturns": true, + "noImplicitThis": true, + "noImplicitAny": false, + "importHelpers": true, + "strictNullChecks": true, + "suppressImplicitAnyIndexErrors": true, + "noUnusedLocals": true, + "skipLibCheck": true, + "types": ["node"], + "paths": { + "@/*": [ + "./src/*" + ], + "ice": [ + ".ice/index.ts" + ], + } + } +} diff --git a/examples/without-react-router/src/pages/About/app.tsx b/examples/without-react-router/src/pages/About/app.tsx index 20ef9e5b8c..81501b2b44 100644 --- a/examples/without-react-router/src/pages/About/app.tsx +++ b/examples/without-react-router/src/pages/About/app.tsx @@ -3,9 +3,9 @@ import Main from './index'; const appConfig: IAppConfig = { app: { - rootId: 'ice-container' + rootId: 'ice-container', + renderComponent: Main, }, - renderComponent: Main, }; runApp(appConfig); diff --git a/examples/without-react-router/src/pages/Home/app.tsx b/examples/without-react-router/src/pages/Home/app.tsx index 20ef9e5b8c..81501b2b44 100644 --- a/examples/without-react-router/src/pages/Home/app.tsx +++ b/examples/without-react-router/src/pages/Home/app.tsx @@ -3,9 +3,9 @@ import Main from './index'; const appConfig: IAppConfig = { app: { - rootId: 'ice-container' + rootId: 'ice-container', + renderComponent: Main, }, - renderComponent: Main, }; runApp(appConfig); diff --git a/packages/build-app-templates/CHANGELOG.md b/packages/build-app-templates/CHANGELOG.md index 1ae163f5d1..c6858328a0 100644 --- a/packages/build-app-templates/CHANGELOG.md +++ b/packages/build-app-templates/CHANGELOG.md @@ -1,5 +1,10 @@ # Changelog +## 1.1.0 + +- [chore] use `enableRouter` replace `buildConfig.router` +- [feat] add `runtimeValue.enableRouter` when createBaseApp + ## 1.0.2 - [fix] add default static config of rax app render @@ -8,4 +13,4 @@ - [fix] add rax template of render - [fix] remove getSearchParams of rax template -- [fix] import ErrorBoundary in template \ No newline at end of file +- [fix] import ErrorBoundary in template diff --git a/packages/build-app-templates/package.json b/packages/build-app-templates/package.json index b20f9c59cd..4bc441a57c 100644 --- a/packages/build-app-templates/package.json +++ b/packages/build-app-templates/package.json @@ -1,6 +1,6 @@ { "name": "@builder/app-templates", - "version": "1.0.2", + "version": "1.1.0", "description": "App templates for ice.js and rax-app", "author": "ice-admin@alibaba-inc.com", "homepage": "", diff --git a/packages/build-app-templates/src/templates/rax/routerAPI.ts.ejs b/packages/build-app-templates/src/templates/rax/routerAPI.ts.ejs index 501660b1f5..87ac62659c 100644 --- a/packages/build-app-templates/src/templates/rax/routerAPI.ts.ejs +++ b/packages/build-app-templates/src/templates/rax/routerAPI.ts.ejs @@ -2,6 +2,7 @@ import { withRouter } from 'rax-use-router'; import { history, getHistory, + setHistory, } from 'create-app-shared'; // router api @@ -9,4 +10,5 @@ export { withRouter, history, getHistory, + setHistory, }; diff --git a/packages/build-app-templates/src/templates/rax/runApp.ts.ejs b/packages/build-app-templates/src/templates/rax/runApp.ts.ejs index 717d3a90d6..d76b4f646a 100644 --- a/packages/build-app-templates/src/templates/rax/runApp.ts.ejs +++ b/packages/build-app-templates/src/templates/rax/runApp.ts.ejs @@ -3,7 +3,7 @@ import { createBaseApp, initAppLifeCycles, emitLifeCycles, -<% if (buildConfig.router !== false) {%> +<% if (enableRouter !== false) {%> initHistory, createHistory, <% } %> @@ -40,11 +40,16 @@ if (!inMiniApp) { runtimeValue.tabBarConfig = <%- isMPA ? JSON.stringify('') : 'staticConfig?.tabBar' %>; } <% } %> + +<% if(enableRouter){ %> + runtimeValue.enableRouter = true; +<% } %> + const frameworkAppBase = createBaseApp({ loadRuntimeModules, createElement, runtimeAPI: { - <% if (buildConfig.router !== false) {%> + <% if (enableRouter !== false) {%> createHistory, <% } %> }, @@ -55,24 +60,26 @@ const frameworkAppBase = createBaseApp({ const pageConfig = <%- JSON.stringify(pageConfig) %>; <% } %> -export function runApp(appConfig?: IAppConfig, <% if (buildConfig.router !== false) {%>customStaticConfig?: IStaticConfig<% } %>) { +export function runApp(appConfig?: IAppConfig, <% if (enableRouter !== false) {%>customStaticConfig?: IStaticConfig<% } %>) { // server bundle will to get appConfig after run runApp setAppConfig(appConfig as IAppConfig); // load static modules before init runtime such as request loadStaticModules(appConfig as IAppConfig); - if (process.env.__IS_SERVER__ || isNode) return; + <% if (typeof pageConfig !== 'undefined' && !enableRouter) { %> + appConfig.app.renderComponent.__pageConfig = pageConfig; + <% } %> - <% if (buildConfig.router !== false) {%> + <% if (enableRouter !== false) {%> if (customStaticConfig) { staticConfig = customStaticConfig; } // set History before GID initHistory && initHistory(appConfig as any, { staticConfig }); - <% } else if (typeof pageConfig !== 'undefined') { %> - appConfig.renderComponent.__pageConfig = pageConfig; <% } %> + if (process.env.__IS_SERVER__ || isNode) return; + let renderer; if (inMiniApp) { renderer = miniappRenderer; diff --git a/packages/build-app-templates/src/templates/react/routerAPI.ts.ejs b/packages/build-app-templates/src/templates/react/routerAPI.ts.ejs index a6f3c0ce40..7da6aeb361 100644 --- a/packages/build-app-templates/src/templates/react/routerAPI.ts.ejs +++ b/packages/build-app-templates/src/templates/react/routerAPI.ts.ejs @@ -2,6 +2,7 @@ import { withRouter } from 'react-router'; import { history, getHistory, + setHistory, } from 'create-app-shared'; // router api @@ -9,4 +10,5 @@ export { withRouter, history, getHistory, + setHistory, }; diff --git a/packages/build-app-templates/src/templates/react/runApp.ts.ejs b/packages/build-app-templates/src/templates/react/runApp.ts.ejs index 855ad236a7..0f86d1e118 100644 --- a/packages/build-app-templates/src/templates/react/runApp.ts.ejs +++ b/packages/build-app-templates/src/templates/react/runApp.ts.ejs @@ -4,7 +4,7 @@ import { initAppLifeCycles, emitLifeCycles, getSearchParams, -<% if (buildConfig.router !== false) {%> +<% if (enableRouter !== false) {%> initHistory, createHistory, <% } %> @@ -23,15 +23,23 @@ import ErrorBoundary from '<%- relativeCorePath %>/ErrorBoundary'; import { IAppConfig, IBuildConfig } from '<%- typesPath %>'; const buildConfig: IBuildConfig = <%- JSON.stringify(buildConfig) %>; +const runtimeValue: any = {}; + +<% if(enableRouter){ %> + runtimeValue.enableRouter = true; +<% } %> + +// TODO: createBaseApp() 返回一个 createBaseApp,命名需要优化下 const frameworkAppBase = createBaseApp({ loadRuntimeModules, createElement, runtimeAPI: { - <% if (buildConfig.router !== false) {%> + <% if (enableRouter !== false) {%> createHistory, <% } %> getSearchParams, }, + runtimeValue, }); export function runApp(appConfig?: IAppConfig) { @@ -40,11 +48,11 @@ export function runApp(appConfig?: IAppConfig) { setAppConfig(appConfig as IAppConfig); // load static modules before init runtime such as request loadStaticModules(appConfig as IAppConfig); - if (process.env.__IS_SERVER__) return; - <% if (buildConfig.router !== false) {%> + <% if (enableRouter !== false) {%> // set History before GID initHistory && initHistory(appConfig as any); <% } %> + if (process.env.__IS_SERVER__) return; reactAppRenderer({ appConfig: appConfig as RenderAppConfig, buildConfig, diff --git a/packages/build-mpa-config/CHANGELOG.md b/packages/build-mpa-config/CHANGELOG.md index d8e3caed69..95e093c555 100644 --- a/packages/build-mpa-config/CHANGELOG.md +++ b/packages/build-mpa-config/CHANGELOG.md @@ -1,5 +1,10 @@ # Changelog +## 4.1.0 + +- [chore] remove `buildConfig.router` and add `enableRouter` to generator +- [fix] `renderComponent` -> `app.renderComponent` + ## 4.0.5 - fix: `TabBar` resolve path diff --git a/packages/build-mpa-config/package.json b/packages/build-mpa-config/package.json index 6badb6ca5b..2507bea38d 100644 --- a/packages/build-mpa-config/package.json +++ b/packages/build-mpa-config/package.json @@ -1,6 +1,6 @@ { "name": "@builder/mpa-config", - "version": "4.0.5", + "version": "4.1.0", "description": "enable mpa project for framework", "author": "ice-admin@alibaba-inc.com", "homepage": "", @@ -30,4 +30,4 @@ "devDependencies": { "build-scripts": "^1.1.0" } -} \ No newline at end of file +} diff --git a/packages/build-mpa-config/src/generate/BaseGenerator.ts b/packages/build-mpa-config/src/generate/BaseGenerator.ts index 8de2525bae..455b9983c8 100644 --- a/packages/build-mpa-config/src/generate/BaseGenerator.ts +++ b/packages/build-mpa-config/src/generate/BaseGenerator.ts @@ -46,11 +46,15 @@ export default class BaseGenerator { this.runAppPath = path.join(this.entryFolder, 'runApp'); } + /** + * MPA 生成单个页面的 runApp.tsx + */ public generateRunAppFile(userConfig) { const { framework } = this.options; const { applyMethod } = this.builtInMethods; const globalStyles = globby.sync(['src/global.@(scss|less|css)'], { cwd: this.rootDir }); const routesFilePath = this.getRoutesFilePath(); + const renderData = { ...this.runAppRenderData, globalStyle: globalStyles.length && relative(this.entryFolder, path.join(this.rootDir, globalStyles[0])), @@ -58,10 +62,10 @@ export default class BaseGenerator { typesPath: relative(this.entryFolder, path.join(this.targetDir, 'types')), buildConfig: { ...applyMethod('getBuildConfig', userConfig), - router: Boolean(routesFilePath), }, routesFilePath: routesFilePath && relative(this.entryFolder, routesFilePath), isMPA: true, + enableRouter: Boolean(routesFilePath), }; applyMethod('addRenderFile', getTemplate('runApp.ts', framework), `${this.runAppPath}.ts`, renderData); @@ -87,6 +91,7 @@ export default class BaseGenerator { , (renderData) => { let { runtimeModules } = renderData; if (!routesFilePath) { + // MPA 某个 page 下面没有 routes.[j|t]s 文件,禁用 plugin-router 运行时能力 runtimeModules = runtimeModules.filter(({ name }) => { return !this.disableRuntimeList.includes(name); }); diff --git a/packages/build-mpa-config/src/template/rax/index.tsx.ejs b/packages/build-mpa-config/src/template/rax/index.tsx.ejs index 49cf6993d5..8cccb5a022 100644 --- a/packages/build-mpa-config/src/template/rax/index.tsx.ejs +++ b/packages/build-mpa-config/src/template/rax/index.tsx.ejs @@ -10,7 +10,9 @@ runApp(appConfig, staticConfig); import Page from '<%- resourcePath %>'; const appConfig: IAppConfig = { - renderComponent: Page, + app: { + renderComponent: Page, + }, }; runApp(appConfig); diff --git a/packages/build-mpa-config/src/template/react/index.tsx.ejs b/packages/build-mpa-config/src/template/react/index.tsx.ejs index 264f77597c..672abba863 100644 --- a/packages/build-mpa-config/src/template/react/index.tsx.ejs +++ b/packages/build-mpa-config/src/template/react/index.tsx.ejs @@ -12,7 +12,9 @@ const appConfig: IAppConfig = { import Page from '<%- resourcePath %>'; const appConfig: IAppConfig = { - renderComponent: Page, + app: { + renderComponent: Page, + }, }; <% } %> diff --git a/packages/build-user-config/README.md b/packages/build-user-config/README.md index 50d4fc1403..bacbf4a360 100644 --- a/packages/build-user-config/README.md +++ b/packages/build-user-config/README.md @@ -1,11 +1,8 @@ # `build-webpack-config` -> TODO: description ## Usage ``` const buildWebpackConfig = require('build-webpack-config'); - -// TODO: DEMONSTRATE API ``` diff --git a/packages/create-app-shared/CHANGELOG.md b/packages/create-app-shared/CHANGELOG.md index fec7e92484..cb54655319 100644 --- a/packages/create-app-shared/CHANGELOG.md +++ b/packages/create-app-shared/CHANGELOG.md @@ -1,5 +1,11 @@ # Changelog +## 1.2.0 + +- [chore] use `runtimeValue.enableRouter` check router status +- [feat] support pass pageConfig&getInitialProps when use renderComponent +- [fix] `renderComponent` -> `app.renderComponent` + ## 1.1.0 - [feat] support runtime value diff --git a/packages/create-app-shared/package.json b/packages/create-app-shared/package.json index 271e746467..4f99cc8fc1 100644 --- a/packages/create-app-shared/package.json +++ b/packages/create-app-shared/package.json @@ -1,6 +1,6 @@ { "name": "create-app-shared", - "version": "1.1.0", + "version": "1.2.0", "description": "", "author": "ice-admin@alibaba-inc.com", "homepage": "https://github.com/alibaba/ice#readme", diff --git a/packages/create-app-shared/src/createBaseApp.ts b/packages/create-app-shared/src/createBaseApp.ts index 8803e65d70..f81f7eb252 100644 --- a/packages/create-app-shared/src/createBaseApp.ts +++ b/packages/create-app-shared/src/createBaseApp.ts @@ -20,6 +20,7 @@ export default ({ loadRuntimeModules, createElement, runtimeAPI = {}, runtimeVal // Merge default appConfig to user appConfig appConfig = mergeDefaultConfig(DEFAULT_APP_CONFIG, appConfig) as T; (context as Context).createElement = createElement; + (context as Context).enableRouter = (runtimeValue as any).enableRouter; // Load runtime modules const runtime = new RuntimeModule(appConfig, buildConfig, context, staticConfig); diff --git a/packages/create-app-shared/src/getSearchParams.ts b/packages/create-app-shared/src/getSearchParams.ts index 8b4695d354..a44fe682f2 100644 --- a/packages/create-app-shared/src/getSearchParams.ts +++ b/packages/create-app-shared/src/getSearchParams.ts @@ -2,11 +2,12 @@ import * as queryString from 'query-string'; import { getHistory } from './storage'; export default function(history = getHistory()) { - if (!history && typeof window !== 'undefined' && window.history) { - history = (window as any).history; - } - if (history && history.location && history.location.search) { - return queryString.parse(history.location.search); + // SSR 会在渲染前通过 setHistory 设置通过 request 信息模拟的 history + let search = history?.location?.search; + + if (!search && typeof window !== 'undefined') { + search = window.location.search; } - return {}; + + return queryString.parse(search); } diff --git a/packages/create-app-shared/src/miniapp/getSearchParams.ts b/packages/create-app-shared/src/miniapp/getSearchParams.ts index ce525a1fde..d6108439ca 100644 --- a/packages/create-app-shared/src/miniapp/getSearchParams.ts +++ b/packages/create-app-shared/src/miniapp/getSearchParams.ts @@ -1,5 +1,5 @@ import { getHistory } from '../storage'; export default function(history = getHistory()) { - return (history.location as any)._currentPageOptions; + return (history?.location as any)?._currentPageOptions || {}; } diff --git a/packages/create-app-shared/src/runtimeModule.ts b/packages/create-app-shared/src/runtimeModule.ts index 9dd4a85ab3..91d946c093 100644 --- a/packages/create-app-shared/src/runtimeModule.ts +++ b/packages/create-app-shared/src/runtimeModule.ts @@ -92,6 +92,7 @@ class RuntimeModule { this.appConfig = appConfig; this.buildConfig = buildConfig; this.context = context; + // Rax App 里的 app.json this.staticConfig = staticConfig; this.modifyDOMRender = null; this.apiRegistration = {}; @@ -104,7 +105,7 @@ class RuntimeModule { } public loadModule(module: RuntimePlugin | CommonJsRuntime) { - const enabledRouter = !this.appConfig.renderComponent; + const enableRouter = this.getRuntimeValue('enableRouter'); let runtimeAPI: RuntimeAPI = { addProvider: this.addProvider, addDOMRender: this.addDOMRender, @@ -117,7 +118,8 @@ class RuntimeModule { staticConfig: this.staticConfig, getRuntimeValue: this.getRuntimeValue, }; - if (enabledRouter) { + + if (enableRouter) { runtimeAPI = { ...runtimeAPI, modifyRoutes: this.modifyRoutes, @@ -173,10 +175,12 @@ class RuntimeModule { return this.internalValue[key]; } + // plugin-router 会调用 private setRenderApp: SetRenderApp = (renderRouter) => { this.renderApp = renderRouter; } + // plugin-icestark 会调用 private wrapperRouterRender: WrapperRouterRender = (wrapper) => { // pass origin router render for custom requirement this.renderApp = wrapper(this.renderApp); @@ -218,15 +222,30 @@ class RuntimeModule { } public getAppComponent: GetAppComponent = () => { - if (this.modifyRoutesRegistration.length > 0) { + // 表示是否启用 pluin-router runtime,何时不启用:1. SPA + router: false 2. MPA + 对应 pages 文件下面没有 routes.[j|t]s 这个文件 + const enableRouter = this.getRuntimeValue('enableRouter'); + + if (enableRouter) { const routes = this.wrapperRoutes(this.modifyRoutesRegistration.reduce((acc: IPage, curr) => { return curr(acc); }, [])); + // renderApp define by plugin-router return this.renderApp(routes, this.routesComponent); + } else { + // 通过 appConfig.app.renderComponent 渲染 + const renderComponent = this.appConfig.app?.renderComponent; + // default renderApp + return this.renderApp(this.wrapperPageRegistration.reduce((acc: any, curr: any) => { + const compose = curr(acc); + if (acc.pageConfig) { + compose.pageConfig = acc.pageConfig; + } + if (acc.getInitialProps) { + compose.getInitialProps = acc.getInitialProps; + } + return compose; + }, renderComponent)); } - return this.renderApp(this.wrapperPageRegistration.reduce((acc, curr) => { - return curr(acc); - }, this.appConfig.renderComponent)); } } diff --git a/packages/create-app-shared/src/types.ts b/packages/create-app-shared/src/types.ts index a1f52f069d..76b3e73bf9 100644 --- a/packages/create-app-shared/src/types.ts +++ b/packages/create-app-shared/src/types.ts @@ -3,7 +3,10 @@ import type { createElement, ComponentType } from 'react'; type VoidFunction = () => void; -type App = Partial<{ rootId: string } & Record<'onShow' | 'onHide' | 'onPageNotFound' | 'onShareAppMessage' | 'onUnhandledRejection' | 'onLaunch' | 'onError' | 'onTabItemClick', VoidFunction>>; +type App = Partial<{ + rootId: string, + renderComponent?: ComponentType, +} & Record<'onShow' | 'onHide' | 'onPageNotFound' | 'onShareAppMessage' | 'onUnhandledRejection' | 'onLaunch' | 'onError' | 'onTabItemClick', VoidFunction>>; export interface AppConfig { app?: App, @@ -12,7 +15,6 @@ export interface AppConfig { history?: History; basename?: string; }, - renderComponent?: ComponentType } export type BuildConfig = Record; @@ -29,4 +31,5 @@ export type WithPageLifeCycle =

(Component: React.ComponentClass

) => React export interface Context { createElement?: ReactCreateElement; + enableRouter?: boolean; } diff --git a/packages/create-app-shared/src/web/history.ts b/packages/create-app-shared/src/web/history.ts index 29ac258eff..e07fa32169 100644 --- a/packages/create-app-shared/src/web/history.ts +++ b/packages/create-app-shared/src/web/history.ts @@ -8,8 +8,7 @@ const createHistory: CreateHistory = ({ type, basename, location }) => { if (process.env.__IS_SERVER__) { history = createMemoryHistory(); (history as any).location = location; - } - if (type === 'hash') { + } else if (type === 'hash') { history = createHashHistory({ basename }); } else if (type === 'browser') { history = createBrowserHistory({ basename }); diff --git a/packages/icejs/package.json b/packages/icejs/package.json index 5439e79668..ae87c03d0c 100644 --- a/packages/icejs/package.json +++ b/packages/icejs/package.json @@ -49,4 +49,4 @@ "npm": ">=3.0.0" }, "gitHead": "cf40d079714b437417e77b444b078cf83286f2fc" -} \ No newline at end of file +} diff --git a/packages/icejs/src/getBuiltInPlugins.ts b/packages/icejs/src/getBuiltInPlugins.ts index 87edfd6406..75d82586b5 100644 --- a/packages/icejs/src/getBuiltInPlugins.ts +++ b/packages/icejs/src/getBuiltInPlugins.ts @@ -12,6 +12,7 @@ const getDynamicPlugins = (userConfig: IUserConfig) => { ['build-plugin-ice-store', 'store', true], ['build-plugin-ice-auth', 'auth', true], ['build-plugin-pwa', 'pwa', false], + ['build-plugin-ice-request', 'request', true], ]; const checkPluginExist = (name: string) => { @@ -61,7 +62,7 @@ const getBuiltInPlugins: IGetBuiltInPlugins = (userConfig) => { 'framework': 'react', 'alias': process.env.__FRAMEWORK_NAME__ || 'ice' } as Json; - const plugins: IPluginList = [ + let plugins: IPluginList = [ // common plugins ['build-plugin-app-core', coreOptions], 'build-plugin-ice-logger', @@ -73,10 +74,18 @@ const getBuiltInPlugins: IGetBuiltInPlugins = (userConfig) => { 'build-plugin-ice-router', 'build-plugin-ice-config', 'build-plugin-ice-mpa', - 'build-plugin-ice-request', 'build-plugin-helmet' ]; + if (userConfig.mpa && userConfig.router === false) { + console.warn('Warning:', 'MPA 模式下 router: false 选项没有意义,建议移除该选项。'); + } + + if (!userConfig.mpa && userConfig.router === false) { + // SPA 并且设置了 router: false 则过滤 router 插件 + plugins = plugins.filter((name) => name !== 'build-plugin-ice-router'); + } + const dynamicPlugins = getDynamicPlugins(userConfig); return plugins.concat(dynamicPlugins); diff --git a/packages/plugin-app-core/CHANGELOG.md b/packages/plugin-app-core/CHANGELOG.md index 0eb91b477b..141b01333d 100644 --- a/packages/plugin-app-core/CHANGELOG.md +++ b/packages/plugin-app-core/CHANGELOG.md @@ -1,5 +1,12 @@ # Changelog +## 2.1.0 + +- [feat] register `router`&`request` to userConfig +- [chore] pass `enableRouter` to generator +- [feat] remove runtime addProvider and move to react-app/rax-app +- [feat] add `mpa` to runtime buildConfig + ## 2.0.3 - [feat] format rax plugin name diff --git a/packages/plugin-app-core/package.json b/packages/plugin-app-core/package.json index 9cbc7de4d9..334128cf56 100644 --- a/packages/plugin-app-core/package.json +++ b/packages/plugin-app-core/package.json @@ -1,6 +1,6 @@ { "name": "build-plugin-app-core", - "version": "2.0.3", + "version": "2.1.0", "description": "the core plugin for icejs and raxjs.", "author": "ice-admin@alibaba-inc.com", "homepage": "", @@ -29,8 +29,7 @@ "lodash.debounce": "^4.0.8", "miniapp-builder-shared": "^0.2.2", "object-hash": "^2.2.0", - "prettier": "^2.0.2", - "query-string": "^6.13.1" + "prettier": "^2.0.2" }, "repository": { "type": "http", @@ -40,4 +39,4 @@ "devDependencies": { "@types/object-hash": "^2.2.1" } -} \ No newline at end of file +} diff --git a/packages/plugin-app-core/src/constant.ts b/packages/plugin-app-core/src/constant.ts index 8ae741bd6e..6758c87ab7 100644 --- a/packages/plugin-app-core/src/constant.ts +++ b/packages/plugin-app-core/src/constant.ts @@ -15,6 +15,14 @@ export const USER_CONFIG = [ name: 'auth', validation: 'boolean' }, + { + name: 'request', + validation: 'boolean' + }, + { + name: 'router', + validation: 'object|boolean' + }, { name: 'sourceDir', validation: 'string', diff --git a/packages/plugin-app-core/src/generator/templates/types/index.ts.ejs b/packages/plugin-app-core/src/generator/templates/types/index.ts.ejs index 1b1a852b42..d20b52832c 100644 --- a/packages/plugin-app-core/src/generator/templates/types/index.ts.ejs +++ b/packages/plugin-app-core/src/generator/templates/types/index.ts.ejs @@ -38,12 +38,14 @@ export interface IBuildConfig { store?: boolean | IStoreConfig; icestarkType?: 'es' | 'umd' | 'normal'; web?: object; + mpa?: boolean; } export interface IApp { rootId?: string; mountNode?: HTMLElement; addProvider?: ({ children }: { children: FrameworkNode }) => FrameworkElement; + renderComponent?: FrameworkComponentType; getInitialData?: (ctx?: IContext) => Promise; errorBoundary?: boolean; ErrorBoundaryFallback?: FrameworkComponentType, diff --git a/packages/plugin-app-core/src/index.ts b/packages/plugin-app-core/src/index.ts index 735a2c1fea..c117d03ac3 100644 --- a/packages/plugin-app-core/src/index.ts +++ b/packages/plugin-app-core/src/index.ts @@ -60,6 +60,7 @@ export default (api, options) => { // register api method const generator = initGenerator(api, { ...options, hasJsxRuntime }); + setRegisterMethod(api, { generator }); // add core template for framework @@ -134,6 +135,8 @@ function getDefaultRenderData(api, options) { isMPA: false, tabBarPath: '', // avoid ejs error routesFilePath: './staticConfig', + // MPA 下会覆盖 + enableRouter: true, }; } else { return { @@ -141,6 +144,8 @@ function getDefaultRenderData(api, options) { isReact: true, isRax: false, ssr, + // MPA 下会覆盖 + enableRouter: (!userConfig.mpa && userConfig.router !== false), }; } } diff --git a/packages/plugin-app-core/src/runtime.tsx b/packages/plugin-app-core/src/runtime.tsx deleted file mode 100644 index 27f79ced85..0000000000 --- a/packages/plugin-app-core/src/runtime.tsx +++ /dev/null @@ -1,7 +0,0 @@ -const module = ({ addProvider, appConfig }) => { - if (appConfig.app && appConfig.app.addProvider) { - addProvider(appConfig.app.addProvider); - } -}; - -export default module; diff --git a/packages/plugin-app-core/src/utils/getBuildConfig.ts b/packages/plugin-app-core/src/utils/getBuildConfig.ts index 87f1892c8b..eae4fef82e 100644 --- a/packages/plugin-app-core/src/utils/getBuildConfig.ts +++ b/packages/plugin-app-core/src/utils/getBuildConfig.ts @@ -3,11 +3,15 @@ interface IBuildConfig { store?: boolean; icestarkType?: 'es' | 'umd' | 'normal'; web?: object; + mpa?: boolean; } function getBuildConfig(userConfig): IBuildConfig{ const { plugins, vite } = userConfig; - const buildConfig: IBuildConfig = {}; + const buildConfig: IBuildConfig = { + mpa: Boolean(userConfig.mpa), + }; + // filter userConfig ['router', 'store', 'web'].forEach((configKey) => { if (Object.prototype.hasOwnProperty.call(userConfig, configKey)) { diff --git a/packages/plugin-ice-ssr/CHANGELOG.md b/packages/plugin-ice-ssr/CHANGELOG.md index 3bbf059f0d..271055f532 100644 --- a/packages/plugin-ice-ssr/CHANGELOG.md +++ b/packages/plugin-ice-ssr/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog +## 3.0.5 + +- [feat] support no router mode ssr + ## 3.0.4 - [fix] compatible with special charts in html content diff --git a/packages/plugin-ice-ssr/package.json b/packages/plugin-ice-ssr/package.json index 4434c9a5fc..879cca6604 100644 --- a/packages/plugin-ice-ssr/package.json +++ b/packages/plugin-ice-ssr/package.json @@ -1,6 +1,6 @@ { "name": "build-plugin-ice-ssr", - "version": "3.0.4", + "version": "3.0.5", "description": "ssr plugin", "author": "ice-admin@alibaba-inc.com", "homepage": "", @@ -35,4 +35,4 @@ "@ice/runtime": "^0.1.0", "query-string": "^6.13.7" } -} \ No newline at end of file +} diff --git a/packages/plugin-ice-ssr/src/server.ts.ejs b/packages/plugin-ice-ssr/src/server.ts.ejs index dc85f38ab1..224b8ebb56 100644 --- a/packages/plugin-ice-ssr/src/server.ts.ejs +++ b/packages/plugin-ice-ssr/src/server.ts.ejs @@ -11,8 +11,13 @@ import { InitialContext, ServerContext } from 'react-app-renderer/lib/types'; import { getAppConfig } from '../../core/appConfig'; import loadStaticModules from '../../core/loadStaticModules'; import { emitLifeCycles } from '../../core/publicAPI'; +import { setHistory } from '../../core/routerAPI'; import app from '../../core/runApp'; +<% if (enableRouter) { %> import routes from '<%- routesPath %>/routes'; +<% } else { %> +const routes = []; +<% } %> import loadable from '@loadable/component'; const chalk = require('chalk'); @@ -67,13 +72,17 @@ const serverRender = async (context: ServerContext, opts = {}) => { if (req) { const { search, hash, path, pathname } = parseurl(req); const parsedQuery = queryString.parse(search); + const history = { + location: { pathname, search, hash, state: null }, + }; + setHistory(history); initialContext = { req, res, pathname, query: parsedQuery, path, - location: { pathname, search, hash, state: null }, + location: history.location, }; } @@ -134,6 +143,7 @@ export async function renderStatic({ htmlTemplateContent, initialContext, initia const { bundleContent, loadableComponentExtractor } = reactAppRendererWithSSR( { + enableRouter: <%- enableRouter %>, initialContext, initialData, pageInitialProps, @@ -204,22 +214,34 @@ export function generateHtml({ } export async function getComponentByPath(routes, currPath) { - async function findMatchRoute(routeList) { - let matchedRoute = routeList.find(route => { - return matchPath(currPath, route); - }); - if (matchedRoute?.component?.__LOADABLE__) { - matchedRoute.component = loadable(matchedRoute.component.dynamicImport); + <% if (enableRouter) { %> + async function findMatchRoute(routeList) { + let matchedRoute = routeList.find(route => { + return matchPath(currPath, route); + }); + if (matchedRoute?.component?.__LOADABLE__) { + matchedRoute.component = loadable(matchedRoute.component.dynamicImport); + } + if (matchedRoute) { + return matchedRoute.children ? await findMatchRoute(matchedRoute.children) : matchedRoute; + } } - if (matchedRoute) { - return matchedRoute.children ? await findMatchRoute(matchedRoute.children) : matchedRoute; + const routeData = await findMatchRoute(routes) + return { + component: routeData?.component, + getInitialProps: routeData?.getInitialProps || routeData?.component?.getInitialProps + }; + <% } else { %> + const matchedComponent = appConfig?.app?.renderComponent; + + if (!matchedComponent) { + throw new Error('未指定需要渲染的页面组件!'); } - } - const routeData = await findMatchRoute(routes) - return { - component: routeData?.component, - getInitialProps: routeData?.getInitialProps || routeData?.component?.getInitialProps - }; + return { + component: matchedComponent, + getInitialProps: matchedComponent.getInitialProps + } + <% } %> } function logError(msg) { diff --git a/packages/plugin-react-app/CHANGELOG.md b/packages/plugin-react-app/CHANGELOG.md index 6af7d5a95e..f2f4fe6595 100644 --- a/packages/plugin-react-app/CHANGELOG.md +++ b/packages/plugin-react-app/CHANGELOG.md @@ -1,5 +1,10 @@ # Changelog +## 2.1.0 + +- [feat] add runtime abilities: addProvider/WrapperErrorBoundary/WrapperCSR/WrapperSSR/WrapperSearchParams (move from plugin-router) +- [feat] add runtime router options check and log warning + ## 2.0.4 - [fix] error occurred when config externals and remoteRuntime diff --git a/packages/plugin-react-app/package.json b/packages/plugin-react-app/package.json index 0c7c3ece1b..b73dbda892 100644 --- a/packages/plugin-react-app/package.json +++ b/packages/plugin-react-app/package.json @@ -1,6 +1,6 @@ { "name": "build-plugin-react-app", - "version": "2.0.4", + "version": "2.1.0", "description": "The basic webpack configuration for ice project", "author": "ice-admin@alibaba-inc.com", "main": "lib/index.js", @@ -31,13 +31,14 @@ "path-browserify": "^1.0.1", "path-exists": "^4.0.0", "process": "^0.11.10", + "query-loader-webpack-plugin": "^1.0.0", + "query-string": "^7.0.1", "react-app-renderer": "^3.0.0", "react-dev-utils": "^11.0.0", "react-refresh": "^0.10.0", - "react-router-dom": "^5.1.2", "react-router": "^5.2.1", + "react-router-dom": "^5.1.2", "vite-plugin-component-style": "^1.0.0", - "query-loader-webpack-plugin": "^1.0.0", "webpack-plugin-import": "^0.3.0" }, "devDependencies": { @@ -56,4 +57,4 @@ "lib", "!lib/**/*.map" ] -} \ No newline at end of file +} diff --git a/packages/plugin-react-app/src/index.js b/packages/plugin-react-app/src/index.js index 9151139ea0..4aecfd7443 100644 --- a/packages/plugin-react-app/src/index.js +++ b/packages/plugin-react-app/src/index.js @@ -13,6 +13,7 @@ module.exports = async (api) => { const { onGetWebpackConfig, context, registerTask, getValue, modifyUserConfig, log } = api; const { command, rootDir, userConfig, originalUserConfig } = context; const mode = command === 'start' ? 'development' : 'production'; + const iceTempPath = getValue('TEMP_PATH'); const invalidMsg = getInvalidMessage(originalUserConfig); if (invalidMsg) { @@ -43,6 +44,8 @@ module.exports = async (api) => { onGetWebpackConfig(chainConfig => { // add resolve modules of project node_modules chainConfig.resolve.modules.add(path.join(rootDir, 'node_modules')); + + chainConfig.resolve.alias.set('$ice/ErrorBoundary', path.join(iceTempPath, 'core' ,'ErrorBoundary')); }); const taskName = 'web'; diff --git a/packages/plugin-react-app/src/runtime.tsx b/packages/plugin-react-app/src/runtime.tsx new file mode 100644 index 0000000000..d78007ccc9 --- /dev/null +++ b/packages/plugin-react-app/src/runtime.tsx @@ -0,0 +1,154 @@ +/* eslint-disable no-lonely-if */ +import * as React from 'react'; +import { useState, useEffect } from 'react'; +import * as queryString from 'query-string'; +// @ts-ignore +import ErrorBoundary from '$ice/ErrorBoundary'; + +export default ({ appConfig, wrapperPageComponent, buildConfig, context, applyRuntimeAPI, getRuntimeValue, addProvider }) => { + const { app = {} } = appConfig; + const { ErrorBoundaryFallback, onErrorBoundaryHandler, renderComponent, addProvider: customAddProvider } = app; + + if (customAddProvider) { + addProvider(customAddProvider); + } + + const { parseSearchParams = true } = app; + if (parseSearchParams) { + wrapperPageComponent(wrapperPageWithSearchParams(applyRuntimeAPI)); + } + + wrapperPageComponent(process.env.__IS_SERVER__ ? wrapperPageWithSSR(context) : wrapperPageWithCSR()); + + wrapperPageComponent(wrapperPageWithErrorBoundary(ErrorBoundaryFallback, onErrorBoundaryHandler)); + + const enableRouter = getRuntimeValue('enableRouter'); + if (process.env.NODE_ENV !== 'production') { + if (buildConfig.mpa) { + if (enableRouter) { + // MPA 启用路由 + if (renderComponent) { + console.warn('[icejs]', '当前 MPA 页面已启用配置路由,app.renderComponent 将失效,建议移除 app.js 对应字段'); + } + if (!appConfig.router?.routes) { + throw new Error('当前 MPA 页面已启用配置路由但没有设置 routes 字段,请在 app.js 中引入 routes.js 并赋值给 router.routes 字段'); + } + } else { + // MPA 未启用路由 + if (!renderComponent) { + throw new Error('当前 MPA 页面没有启用路由,需要结合 app.renderComponent 渲染应用,请在 app.js 中补充相关逻辑'); + } + // TODO: appConfig.router 受 DEFAULT_APP_CONFIG 影响 + // if (appConfig.router) { + // console.warn('[icejs]', '当前 MPA 页面没有启用路由,router 配置失效,建议移除 app.js 对应字段'); + // } + } + } else { + if (enableRouter) { + // SPA 启用路由 + if (renderComponent) { + console.warn('[icejs]', '当前 SPA 应用已启用配置路由,app.renderComponent 将失效,建议移除 app.js 对应字段'); + } + if (appConfig.router?.routes) { + // 手动配置了 routes 字段 + console.warn('[icejs]', '当前 SPA 应用手动配置了 router.routes 字段,配置路由/文件约定路由可能失效'); + } + } else { + // SPA 关闭路由 + if (!renderComponent) { + throw new Error('当前 SPA 应用已通过 router: false 禁用路由,需要结合 app.renderComponent 渲染应用,请在 app.js 中补充相关逻辑'); + } + // TODO: appConfig.router 受 DEFAULT_APP_CONFIG 影响 + // if (appConfig.router) { + // console.warn('[icejs]', '当前 SPA 应用已通过 router: false 禁用路由,router 配置失效,建议移除 app.js 对应字段'); + // } + } + } + } +}; + +function wrapperPageWithSearchParams(applyRuntimeAPI) { + const WrapperPageFn = (PageComponent) => { + const SearchParamsWrapper = (props) => { + const searchParams = applyRuntimeAPI('getSearchParams'); + return ; + }; + return SearchParamsWrapper; + }; + return WrapperPageFn; +} + +function wrapperPageWithErrorBoundary(ErrorBoundaryFallback, onErrorBoundaryHandler) { + const WrapperPageFn = (PageComponent) => { + const { pageConfig = {} } = PageComponent; + const ErrorBoundaryWrapper = (props) => { + if (pageConfig.errorBoundary) { + return ( + + + + ); + } + return ; + }; + return ErrorBoundaryWrapper; + }; + return WrapperPageFn; +} + +function wrapperPageWithSSR(context) { + const pageInitialProps = { ...context.pageInitialProps }; + const WrapperPageFn = (PageComponent) => { + const ServerWrapper = (props) => { + return ; + }; + return ServerWrapper; + }; + return WrapperPageFn; +} + +function wrapperPageWithCSR() { + const wrapperPage = (PageComponent) => { + const { pageConfig } = PageComponent; + const { title, scrollToTop } = pageConfig || {}; + + const ClientWrapper = (props) => { + const [data, setData] = useState((window as any).__ICE_PAGE_PROPS__); + useEffect(() => { + if (title) { + document.title = title; + } + + if (scrollToTop) { + window.scrollTo(0, 0); + } + + // When enter the page for the first time, need to use window.__ICE_PAGE_PROPS__ as props + // And don't need to re-request to switch routes + // Set the data to null after use, otherwise other pages will use + if ((window as any).__ICE_PAGE_PROPS__) { + (window as any).__ICE_PAGE_PROPS__ = null; + } else if (PageComponent.getInitialProps) { + // When the server does not return data, the client calls getinitialprops + (async () => { + const { href, origin, pathname, search } = window.location; + const curPath = href.replace(origin, ''); + const query = queryString.parse(search); + const ssrError = (window as any).__ICE_SSR_ERROR__; + const initialContext = { + pathname, + path: curPath, + query, + ssrError + }; + const result = await PageComponent.getInitialProps(initialContext); + setData(result); + })(); + } + }, []); + return ; + }; + return ClientWrapper; + }; + return wrapperPage; +} diff --git a/packages/plugin-router/CHANGELOG.md b/packages/plugin-router/CHANGELOG.md index 43b73d8089..9598de439b 100644 --- a/packages/plugin-router/CHANGELOG.md +++ b/packages/plugin-router/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog +## 2.1.0 + +- [chore] migrate wrapper ErrorBoundary/SearchParams/SSR/CSR to plugin-react-app + ## 2.0.4 - [fix] support config `devSever.historyApiFallback` diff --git a/packages/plugin-router/package.json b/packages/plugin-router/package.json index eb303158db..93f5e64dd4 100644 --- a/packages/plugin-router/package.json +++ b/packages/plugin-router/package.json @@ -1,6 +1,6 @@ { "name": "build-plugin-ice-router", - "version": "2.0.4", + "version": "2.1.0", "description": "build-plugin-ice-router", "author": "ice-admin@alibaba-inc.com", "homepage": "", @@ -17,17 +17,16 @@ "fs-extra": "^8.1.0", "glob": "^7.1.6", "history": "^4.10.1", - "query-string": "^6.12.1", "react": "^16.12.0", "react-dom": "^16.12.0", "react-router-dom": "^5.1.2" }, "devDependencies": { - "build-scripts": "^1.1.0", "@types/fs-extra": "^8.0.1", "@types/glob": "^7.1.1", "@types/history": "^4.7.5", "@types/node": "^12.12.12", + "build-scripts": "^1.1.0", "path-to-regexp": "^1.7.0", "typescript": "^4.0.0", "vite": "^2.3.4" @@ -46,4 +45,4 @@ "test": "echo \"Error: run tests from root\" && exit 1" }, "gitHead": "6bbf8de986f2e6d4820c2dc7f92fa87d917b23f7" -} \ No newline at end of file +} diff --git a/packages/plugin-router/src/index.ts b/packages/plugin-router/src/index.ts index fca0c4cb85..f2b9392721 100644 --- a/packages/plugin-router/src/index.ts +++ b/packages/plugin-router/src/index.ts @@ -1,5 +1,4 @@ import * as path from 'path'; -import { validation } from '@builder/app-helpers'; import { IRouterOptions } from './types/router'; import walker from './collector/walker'; import vitePluginLazy from './vitePluginLazy'; @@ -8,19 +7,9 @@ import vitePluginLazy from './vitePluginLazy'; const TEM_ROUTER_COMPATIBLE = '$ice/routes'; const TEM_ROUTER_SETS = [TEM_ROUTER_COMPATIBLE]; -const plugin = ({ context, onGetWebpackConfig, modifyUserConfig, getValue, applyMethod, registerUserConfig }) => { +const plugin = ({ context, onGetWebpackConfig, modifyUserConfig, getValue, applyMethod, log }) => { const { rootDir, userConfig, command } = context; - // register router in build.json - registerUserConfig({ - name: 'router', - validation: (value) => { - return validation('router', value, 'object|boolean'); - }, - }); - - const disableRouter = userConfig.router === false; - // [enum] js or ts const projectType = getValue('PROJECT_TYPE'); @@ -31,15 +20,20 @@ const plugin = ({ context, onGetWebpackConfig, modifyUserConfig, getValue, apply const { mpa: isMpa } = userConfig; const routesTempPath = path.join(iceTempPath, `routes.${projectType}`); const srcDir = applyMethod('getSourceDir', userConfig.entry); + // MPA 下 isConfigRoutes 永远是 true const { routesPath, isConfigRoutes } = applyMethod('getRoutes', { rootDir, tempPath: iceTempPath, configPath, projectType, - isMpa: isMpa || disableRouter, + isMpa, srcDir }); + if (!isConfigRoutes) { + log.info('开启文件约定式路由能力'); + } + // modify webpack config onGetWebpackConfig((config) => { // add alias @@ -52,9 +46,6 @@ const plugin = ({ context, onGetWebpackConfig, modifyUserConfig, getValue, apply // alias for runtime/history config.resolve.alias.set('$ice/history', path.join(iceTempPath, 'plugins/router/history.ts')); - // alias for runtime/ErrorBoundary - config.resolve.alias.set('$ice/ErrorBoundary', path.join(iceTempPath, 'core' ,'ErrorBoundary')); - // alias for react-router-dom const routerName = 'react-router-dom'; const packagePath = require.resolve(`${routerName}/package.json`); @@ -83,64 +74,64 @@ const plugin = ({ context, onGetWebpackConfig, modifyUserConfig, getValue, apply exportMembers: ['IAppRouterProps', 'IRouterConfig'], }); - if (!disableRouter) { - // add babel plugins for ice lazy - modifyUserConfig('babelPlugins', + // add babel plugins for ice lazy + modifyUserConfig('babelPlugins', + [ + ...(userConfig.babelPlugins as [] || []), [ - ...(userConfig.babelPlugins as [] || []), - [ - require.resolve('./babelPluginLazy'), - { routesPath } - ] - ]); - - // if mode vite, add vite plugin for transform lazy - if (userConfig.vite) { - modifyUserConfig('vite.plugins', [vitePluginLazy(routesPath)], { deepmerge: true }); - } - - // copy templates and export react-router-dom/history apis to ice - const routerTemplatesPath = path.join(__dirname, '../templates'); - applyMethod('addPluginTemplate', routerTemplatesPath); - applyMethod('addExport', { - source: './plugins/router', - importSource: '$$ice/plugins/router', - exportMembers: [ - 'createBrowserHistory', - 'createHashHistory', - 'createMemoryHistory', - // react-router-dom - 'Link', - 'NavLink', - 'Prompt', - 'Redirect', - 'Route', - 'Switch', - 'matchPath', - 'generatePath', - // hooks - 'useHistory', - 'useLocation', - 'useParams', - 'useRouteMatch' + require.resolve('./babelPluginLazy'), + { routesPath } ] - }); + ] + ); + + // if mode vite, add vite plugin for transform lazy + if (userConfig.vite) { + modifyUserConfig('vite.plugins', [vitePluginLazy(routesPath)], { deepmerge: true }); + } + + // copy templates and export react-router-dom/history apis to ice + const routerTemplatesPath = path.join(__dirname, '../templates'); + applyMethod('addPluginTemplate', routerTemplatesPath); + applyMethod('addExport', { + source: './plugins/router', + importSource: '$$ice/plugins/router', + exportMembers: [ + 'createBrowserHistory', + 'createHashHistory', + 'createMemoryHistory', + // react-router-dom + 'Link', + 'NavLink', + 'Prompt', + 'Redirect', + 'Route', + 'Switch', + 'matchPath', + 'generatePath', + // hooks + 'useHistory', + 'useLocation', + 'useParams', + 'useRouteMatch' + ] + }); - // do not watch folder pages when route config is exsits - if (!isConfigRoutes) { - const routerMatch = 'src/pages'; - const pagesDir = path.join(rootDir, routerMatch); - const walkerOptions = { rootDir, routerOptions, routesTempPath, pagesDir }; - walker(walkerOptions); - if (command === 'start') { - // watch folder change when dev - applyMethod('watchFileChange', routerMatch, () => { - walker(walkerOptions); - }); - } + if (!isConfigRoutes) { + // 文件约定路由 + const routerMatch = 'src/pages'; + const pagesDir = path.join(rootDir, routerMatch); + const walkerOptions = { rootDir, routerOptions, routesTempPath, pagesDir }; + walker(walkerOptions); + log.verbose('根据 src/pages 结构生成路由配置:', routesTempPath); + + if (command === 'start') { + // watch folder change when dev + applyMethod('watchFileChange', routerMatch, () => { + walker(walkerOptions); + log.verbose('监听到 src/pages 目录变化,重新生成路由配置:', routesTempPath); + }); } - } else { - applyMethod('addAppConfigTypes', { exportName: 'renderComponent?: FrameworkComponentType' }); } }; diff --git a/packages/plugin-router/src/runtime.tsx b/packages/plugin-router/src/runtime.tsx index 958e0af7d8..1c0cce279f 100644 --- a/packages/plugin-router/src/runtime.tsx +++ b/packages/plugin-router/src/runtime.tsx @@ -1,29 +1,14 @@ import * as React from 'react'; // @ts-ignore -import ErrorBoundary from '$ice/ErrorBoundary'; -// @ts-ignore import defaultRoutes from '$ice/routes'; import { IceRouter, Routes, parseRoutes } from './runtime/Router'; -import formatRoutes, { wrapperPageWithCSR, wrapperPageWithSSR } from './runtime/formatRoutes'; +import formatRoutes from './runtime/formatRoutes'; import { RouteItemProps } from './types/base'; import { IRouterConfig } from './types'; -const module = ({ setRenderApp, appConfig, modifyRoutes, wrapperPageComponent, modifyRoutesComponent, buildConfig, context, applyRuntimeAPI }) => { - const { router: appConfigRouter = {}, app = {} } = appConfig; - const { ErrorBoundaryFallback, onErrorBoundaryHandler } = app; - - const { parseSearchParams = true } = app; - const WrappedPageComponent = (PageComponent) => { - const InnerWrappedPageComponent = (props) => { - const searchParams = parseSearchParams && applyRuntimeAPI('getSearchParams'); - return ; - }; - return InnerWrappedPageComponent; - }; - - wrapperPageComponent(WrappedPageComponent); +const module = ({ setRenderApp, appConfig, modifyRoutes, modifyRoutesComponent, buildConfig, context, applyRuntimeAPI }) => { + const { router: appConfigRouter = {} } = appConfig; - // plugin-router 内置确保了 defaultRoutes 最先被添加 modifyRoutes(() => { return formatRoutes(appConfigRouter.routes || defaultRoutes, ''); }); @@ -31,24 +16,6 @@ const module = ({ setRenderApp, appConfig, modifyRoutes, wrapperPageComponent, m // add default RoutesComponent modifyRoutesComponent(() => Routes); - const wrapperPageErrorBoundary = (PageComponent) => { - const { pageConfig = {} } = PageComponent; - const WrappedPageErrorBoundary = (props) => { - if (pageConfig.errorBoundary) { - return ( - - - - ); - } - return ; - }; - return WrappedPageErrorBoundary; - }; - - const wrapperPageFn = process.env.__IS_SERVER__ ? wrapperPageWithSSR(context) : wrapperPageWithCSR(); - wrapperPageComponent(wrapperPageFn); - wrapperPageComponent(wrapperPageErrorBoundary); if (appConfigRouter.modifyRoutes) { modifyRoutes(appConfigRouter.modifyRoutes); } diff --git a/packages/plugin-router/src/runtime/_routes.ts b/packages/plugin-router/src/runtime/_routes.ts index 22aac30b30..604716f1b7 100644 --- a/packages/plugin-router/src/runtime/_routes.ts +++ b/packages/plugin-router/src/runtime/_routes.ts @@ -1,3 +1,2 @@ -// 注释: // 该文件仅用于 module.tsx 中引用 $ice/routes 的编译问题 export default []; diff --git a/packages/plugin-router/src/runtime/formatRoutes.tsx b/packages/plugin-router/src/runtime/formatRoutes.tsx index 3ed79ba09e..54d46526fa 100644 --- a/packages/plugin-router/src/runtime/formatRoutes.tsx +++ b/packages/plugin-router/src/runtime/formatRoutes.tsx @@ -1,6 +1,3 @@ -import * as React from 'react'; -import { useEffect, useState } from 'react'; -import * as queryString from 'query-string'; import { IRouterConfig } from '../types'; import joinPath from '../utils/joinPath'; @@ -29,60 +26,3 @@ export default function formatRoutes(routes: IRouterConfig[], parentPath?: strin }); } - -export function wrapperPageWithSSR(context) { - const pageInitialProps = { ...context.pageInitialProps }; - const WrapperPageFn = (PageComponent) => { - const ServerWrapperedPage = (props) => { - return ; - }; - return ServerWrapperedPage; - }; - return WrapperPageFn; -} - -export function wrapperPageWithCSR() { - const wrapperPage = (PageComponent) => { - const { pageConfig } = PageComponent; - const { title, scrollToTop } = pageConfig || {}; - - const RouterWrapperedPage = (props) => { - const [data, setData] = useState((window as any).__ICE_PAGE_PROPS__); - useEffect(() => { - if (title) { - document.title = title; - } - - if (scrollToTop) { - window.scrollTo(0, 0); - } - - // When enter the page for the first time, need to use window.__ICE_PAGE_PROPS__ as props - // And don't need to re-request to switch routes - // Set the data to null after use, otherwise other pages will use - if ((window as any).__ICE_PAGE_PROPS__) { - (window as any).__ICE_PAGE_PROPS__ = null; - } else if (PageComponent.getInitialProps) { - // When the server does not return data, the client calls getinitialprops - (async () => { - const { href, origin, pathname, search } = window.location; - const curPath = href.replace(origin, ''); - const query = queryString.parse(search); - const ssrError = (window as any).__ICE_SSR_ERROR__; - const initialContext = { - pathname, - path: curPath, - query, - ssrError - }; - const result = await PageComponent.getInitialProps(initialContext); - setData(result); - })(); - } - }, []); - return ; - }; - return RouterWrapperedPage; - }; - return wrapperPage; -} diff --git a/packages/react-app-renderer/CHANGELOG.md b/packages/react-app-renderer/CHANGELOG.md index 2dfa5c78fd..5e23e9844d 100644 --- a/packages/react-app-renderer/CHANGELOG.md +++ b/packages/react-app-renderer/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog +## 3.0.2 + +- [fix]: `renderComponent` -> `app.renderComponent` + ## 3.0.1 - [fix] build with es module diff --git a/packages/react-app-renderer/package.json b/packages/react-app-renderer/package.json index 99b3b76125..c8604754dc 100644 --- a/packages/react-app-renderer/package.json +++ b/packages/react-app-renderer/package.json @@ -1,6 +1,6 @@ { "name": "react-app-renderer", - "version": "3.0.1", + "version": "3.0.2", "description": "", "author": "ice-admin@alibaba-inc.com", "homepage": "https://github.com/alibaba/ice#readme", diff --git a/packages/react-app-renderer/src/server.tsx b/packages/react-app-renderer/src/server.tsx index 2703bf5dfe..d1b99becda 100644 --- a/packages/react-app-renderer/src/server.tsx +++ b/packages/react-app-renderer/src/server.tsx @@ -33,11 +33,13 @@ function renderInServer(context: Context, options: RenderOptions) { export default function reactAppRendererWithSSR(context: Context, options: RenderOptions) { const cloneOptions = deepClone(options); const { appConfig } = cloneOptions || {}; - appConfig.router = appConfig.router || {}; - if (appConfig.router.type !== 'browser') { - throw new Error('[SSR]: Only support BrowserRouter when using SSR. You should set the router type to "browser". For more detail, please visit https://ice.work/docs/guide/basic/router'); + if (context.enableRouter) { + appConfig.router = appConfig.router || {}; + if (appConfig.router.type !== 'browser') { + throw new Error('[SSR]: Only support BrowserRouter when using SSR. You should set the router type to "browser". For more detail, please visit https://ice.work/docs/guide/basic/router'); + } + appConfig.router.type = 'static'; } - appConfig.router.type = 'static'; return renderInServer(context, cloneOptions); } diff --git a/packages/react-app-renderer/src/types.ts b/packages/react-app-renderer/src/types.ts index c6ea01225d..5f6e9cc908 100644 --- a/packages/react-app-renderer/src/types.ts +++ b/packages/react-app-renderer/src/types.ts @@ -6,7 +6,8 @@ export type OnError = (err: Error, componentStack: string) => void export interface Context { initialContext: InitialContext, initialData: { [k: string]: any }, - pageInitialProps: { [k: string]: any } + pageInitialProps: { [k: string]: any }, + enableRouter?: boolean, } export interface ServerContext { @@ -37,8 +38,8 @@ export type RenderAppConfig = { ErrorBoundaryFallback?: React.ComponentType; errorBoundary?: boolean; getInitialData?: (context: InitialContext) => Promise; + renderComponent?: React.ComponentType; }, - renderComponent?: React.ComponentType }; export type AppLifecycle = { createBaseApp: (appConfig: T, buildConfig: any, context: any) => { runtime: RuntimeModule; appConfig: T }; diff --git a/test/basic-icestark-layout.test.ts b/test/basic-icestark-layout.test.ts new file mode 100644 index 0000000000..1644c9ea3f --- /dev/null +++ b/test/basic-icestark-layout.test.ts @@ -0,0 +1,47 @@ +import * as path from 'path'; +import { buildFixture, setupBrowser } from './utils/build'; +import { startFixture, setupStartBrowser } from './utils/start'; +import { IPage } from './utils/browser'; +import executeCommand from './utils/executeCommand'; + +const example = 'icestark-layout'; +const rootDir = path.join(__dirname, `../examples/${example}`); + +executeCommand('npm install', rootDir); + +describe(`build ${example}`, () => { + let page: IPage = null; + let browser = null; + + buildFixture(example); + + test('test SPA addProvider', async () => { + const res = await setupBrowser({ example }); + page = res.page; + browser = res.browser; + const length = (await page.$$('.next-fd-shell')).length; + expect(length).toBeGreaterThan(0); + }); + + afterAll(async () => { + await browser.close(); + }); +}); + +describe(`start ${example}`, () => { + let page: IPage = null; + let browser = null; + + test('test SPA addProvider', async () => { + const { devServer, port } = await startFixture(example); + const res = await setupStartBrowser({ server: devServer, port }); + page = res.page; + browser = res.browser; + const length = (await page.$$('.next-fd-shell')).length; + expect(length).toBeGreaterThan(0); + }, 120000); + + afterAll(async () => { + await browser.close(); + }); +}); diff --git a/test/utils/build.ts b/test/utils/build.ts index 874de8e185..d047042f40 100644 --- a/test/utils/build.ts +++ b/test/utils/build.ts @@ -25,6 +25,7 @@ export const buildFixture = function(example: string) { const processCwdSpy = jest.spyOn(process, 'cwd'); processCwdSpy.mockReturnValue(rootDir); process.env.DISABLE_FS_CACHE = 'true'; + await build({ args: { config: path.join(rootDir, 'build.json'), diff --git a/test/utils/executeCommand.ts b/test/utils/executeCommand.ts new file mode 100644 index 0000000000..fe83aceaf8 --- /dev/null +++ b/test/utils/executeCommand.ts @@ -0,0 +1,9 @@ +import { spawnSync } from 'child_process'; + +export default (order: string, cwd: string) => { + const [command, ...args] = order.split(' '); + spawnSync(command, args, { + stdio: 'inherit', + cwd, + }); +} diff --git a/test/utils/start.ts b/test/utils/start.ts index 7a08142b2c..a311a55ddf 100644 --- a/test/utils/start.ts +++ b/test/utils/start.ts @@ -21,6 +21,7 @@ export const startFixture = async function (example: string) { const processCwdSpy = jest.spyOn(process, 'cwd'); processCwdSpy.mockReturnValue(rootDir); process.env.DISABLE_FS_CACHE = 'true'; + const devServer = await start({ args: { config: path.join(rootDir, 'build.json'), @@ -47,4 +48,4 @@ export const setupStartBrowser: ISetupBrowser = async (options) => { browser, page, }; -}; \ No newline at end of file +}; diff --git a/yarn.lock b/yarn.lock index d6c8529d9a..d5b1335f1e 100644 --- a/yarn.lock +++ b/yarn.lock @@ -14067,6 +14067,16 @@ query-string@^6.12.1, query-string@^6.13.1, query-string@^6.13.7, query-string@^ split-on-first "^1.0.0" strict-uri-encode "^2.0.0" +query-string@^7.0.1: + version "7.0.1" + resolved "https://registry.yarnpkg.com/query-string/-/query-string-7.0.1.tgz#45bd149cf586aaa582dffc7ec7a8ad97dd02f75d" + integrity sha512-uIw3iRvHnk9to1blJCG3BTc+Ro56CBowJXKmNNAm3RulvPBzWLRqKSiiDk+IplJhsydwtuNMHi8UGQFcCLVfkA== + dependencies: + decode-uri-component "^0.2.0" + filter-obj "^1.1.0" + split-on-first "^1.0.0" + strict-uri-encode "^2.0.0" + querystring@0.2.0: version "0.2.0" resolved "https://registry.yarnpkg.com/querystring/-/querystring-0.2.0.tgz#b209849203bb25df820da756e747005878521620" From bdb306f8b728405d41965b2309f912f7939ec6e0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8B=92=E7=8B=92=E7=A5=9E?= Date: Thu, 2 Dec 2021 11:30:27 +0800 Subject: [PATCH 6/9] chore: export enableRouter (#4990) * chore: export enableRouter * chore: typo --- packages/build-app-templates/src/templates/rax/runApp.ts.ejs | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/build-app-templates/src/templates/rax/runApp.ts.ejs b/packages/build-app-templates/src/templates/rax/runApp.ts.ejs index d76b4f646a..15777189a2 100644 --- a/packages/build-app-templates/src/templates/rax/runApp.ts.ejs +++ b/packages/build-app-templates/src/templates/rax/runApp.ts.ejs @@ -114,4 +114,5 @@ export default { <% if (typeof pageConfig !== 'undefined') {%> pageConfig, <% } %> + enableRouter: <%- enableRouter %>, } From 61a3e037efbc453a4100739dc4263c82b6e5382a Mon Sep 17 00:00:00 2001 From: ClarkXia Date: Thu, 2 Dec 2021 11:38:58 +0800 Subject: [PATCH 7/9] chore: update dependencies version (#4986) --- packages/plugin-app-core/CHANGELOG.md | 1 + packages/plugin-app-core/package.json | 4 ++-- packages/plugin-ice-ssr/CHANGELOG.md | 1 + packages/plugin-ice-ssr/package.json | 4 ++-- packages/plugin-mpa/CHANGELOG.md | 4 ++++ packages/plugin-mpa/package.json | 6 +++--- packages/plugin-react-app/CHANGELOG.md | 1 + packages/plugin-react-app/package.json | 8 ++++---- packages/plugin-router/package.json | 2 +- packages/plugin-store/CHANGELOG.md | 4 ++++ packages/plugin-store/package.json | 4 ++-- scripts/tag-version.ts | 4 +--- 12 files changed, 26 insertions(+), 17 deletions(-) diff --git a/packages/plugin-app-core/CHANGELOG.md b/packages/plugin-app-core/CHANGELOG.md index 141b01333d..48c5227137 100644 --- a/packages/plugin-app-core/CHANGELOG.md +++ b/packages/plugin-app-core/CHANGELOG.md @@ -6,6 +6,7 @@ - [chore] pass `enableRouter` to generator - [feat] remove runtime addProvider and move to react-app/rax-app - [feat] add `mpa` to runtime buildConfig +- [fix] update dependencies version ## 2.0.3 diff --git a/packages/plugin-app-core/package.json b/packages/plugin-app-core/package.json index 334128cf56..3c6445ec01 100644 --- a/packages/plugin-app-core/package.json +++ b/packages/plugin-app-core/package.json @@ -19,8 +19,8 @@ "test": "echo \"Error: run tests from root\" && exit 1" }, "dependencies": { - "@builder/app-helpers": "^2.0.0", - "@builder/app-templates": "^1.0.0", + "@builder/app-helpers": "^2.4.1", + "@builder/app-templates": "^1.0.2", "chokidar": "^3.4.1", "ejs": "^3.0.1", "fs-extra": "^8.1.0", diff --git a/packages/plugin-ice-ssr/CHANGELOG.md b/packages/plugin-ice-ssr/CHANGELOG.md index 271055f532..524aaf1595 100644 --- a/packages/plugin-ice-ssr/CHANGELOG.md +++ b/packages/plugin-ice-ssr/CHANGELOG.md @@ -2,6 +2,7 @@ ## 3.0.5 +- [fix] update dependencies version - [feat] support no router mode ssr ## 3.0.4 diff --git a/packages/plugin-ice-ssr/package.json b/packages/plugin-ice-ssr/package.json index 879cca6604..8615bde267 100644 --- a/packages/plugin-ice-ssr/package.json +++ b/packages/plugin-ice-ssr/package.json @@ -23,8 +23,8 @@ "test": "echo \"Error: run tests from root\" && exit 1" }, "dependencies": { - "@builder/app-helpers": "^2.3.4", - "@builder/webpack-config": "^1.0.0", + "@builder/app-helpers": "^2.4.1", + "@builder/webpack-config": "^1.0.4", "@loadable/babel-plugin": "^5.13.2", "@loadable/webpack-plugin": "^5.14.0", "chalk": "^4.0.0", diff --git a/packages/plugin-mpa/CHANGELOG.md b/packages/plugin-mpa/CHANGELOG.md index e67ec162d4..62618c0952 100644 --- a/packages/plugin-mpa/CHANGELOG.md +++ b/packages/plugin-mpa/CHANGELOG.md @@ -1,5 +1,9 @@ # changelog +## 2.0.3 + +- [fix] update dependencies version + ## 2.0.2 - [fix] compatible with the situation when config both `disableRuntime` and `mpa` diff --git a/packages/plugin-mpa/package.json b/packages/plugin-mpa/package.json index 8decc2766f..4032ebcd3c 100644 --- a/packages/plugin-mpa/package.json +++ b/packages/plugin-mpa/package.json @@ -1,6 +1,6 @@ { "name": "build-plugin-ice-mpa", - "version": "2.0.2", + "version": "2.0.3", "description": "enable mpa project for icejs framework", "author": "ice-admin@alibaba-inc.com", "homepage": "", @@ -24,8 +24,8 @@ "build-scripts": "^1.1.0" }, "dependencies": { - "@builder/app-helpers": "^2.0.0", - "@builder/mpa-config": "^4.0.0", + "@builder/app-helpers": "^2.4.1", + "@builder/mpa-config": "^4.0.5", "fs-extra": "^8.1.0" } } \ No newline at end of file diff --git a/packages/plugin-react-app/CHANGELOG.md b/packages/plugin-react-app/CHANGELOG.md index f2f4fe6595..9e02ac22c5 100644 --- a/packages/plugin-react-app/CHANGELOG.md +++ b/packages/plugin-react-app/CHANGELOG.md @@ -4,6 +4,7 @@ - [feat] add runtime abilities: addProvider/WrapperErrorBoundary/WrapperCSR/WrapperSSR/WrapperSearchParams (move from plugin-router) - [feat] add runtime router options check and log warning +- [fix] update dependencies version ## 2.0.4 diff --git a/packages/plugin-react-app/package.json b/packages/plugin-react-app/package.json index b73dbda892..b44acac12f 100644 --- a/packages/plugin-react-app/package.json +++ b/packages/plugin-react-app/package.json @@ -13,11 +13,11 @@ ], "license": "MIT", "dependencies": { - "@builder/app-helpers": "^2.0.0", - "@builder/jest-config": "^1.0.0", + "@builder/app-helpers": "^2.4.1", + "@builder/jest-config": "^1.0.2", "@builder/pack": "^0.4.0", - "@builder/user-config": "^1.0.0", - "@builder/webpack-config": "^1.0.0", + "@builder/user-config": "^1.1.8", + "@builder/webpack-config": "^1.0.4", "chalk": "^4.0.0", "debug": "^4.1.1", "deepmerge": "^4.2.2", diff --git a/packages/plugin-router/package.json b/packages/plugin-router/package.json index 93f5e64dd4..baba2bd9cf 100644 --- a/packages/plugin-router/package.json +++ b/packages/plugin-router/package.json @@ -11,7 +11,7 @@ "test": "__tests__" }, "dependencies": { - "@builder/app-helpers": "^2.0.2", + "@builder/app-helpers": "^2.4.1", "@builder/pack": "^0.4.0", "@types/react-router-dom": "^5.1.4", "fs-extra": "^8.1.0", diff --git a/packages/plugin-store/CHANGELOG.md b/packages/plugin-store/CHANGELOG.md index 1c094ac65e..ddb25f05d9 100644 --- a/packages/plugin-store/CHANGELOG.md +++ b/packages/plugin-store/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog +## 2.0.6 + +- [fix] update dependencies version + ## 2.0.5 - [fix] remove unnecessary import redirection diff --git a/packages/plugin-store/package.json b/packages/plugin-store/package.json index d360fff3d4..ab5277ba78 100644 --- a/packages/plugin-store/package.json +++ b/packages/plugin-store/package.json @@ -1,6 +1,6 @@ { "name": "build-plugin-ice-store", - "version": "2.0.5", + "version": "2.0.6", "description": "builtin `@ice/store` in icejs", "author": "ice-admin@alibaba-inc.com", "homepage": "https://github.com/alibaba/ice#readme", @@ -24,7 +24,7 @@ "test": "echo \"Error: run tests from root\" && exit 1" }, "dependencies": { - "@builder/app-helpers": "^2.0.0", + "@builder/app-helpers": "^2.4.1", "@ice/store": "^2.0.0-3", "chalk": "^4.1.0", "enhanced-resolve": "^4.3.0", diff --git a/scripts/tag-version.ts b/scripts/tag-version.ts index 7e0837e884..6125ceb505 100644 --- a/scripts/tag-version.ts +++ b/scripts/tag-version.ts @@ -15,9 +15,7 @@ function updatePackageVersion(publishPackages: IPackageInfo[]) { const dependenceVersion = publishPackages[i].publishVersion; if (packageInfo.dependencies && packageInfo.dependencies[dependenceName]) { - if (!semver.satisfies(dependenceVersion, packageInfo.dependencies[dependenceName])) { - packageInfo.dependencies[dependenceName] = `${getVersionPrefix(packageInfo.dependencies[dependenceName])}${dependenceVersion}`; - } + packageInfo.dependencies[dependenceName] = `${getVersionPrefix(packageInfo.dependencies[dependenceName])}${dependenceVersion}`; } else if (packageInfo.devDependencies && packageInfo.devDependencies[dependenceName]) { if (!semver.satisfies(dependenceVersion, packageInfo.devDependencies[dependenceName])) { packageInfo.devDependencies[dependenceName] = `${getVersionPrefix(packageInfo.devDependencies[dependenceName])}${dependenceVersion}`; From 0a2f2f051de5af5d834c6a51c527e7deda201199 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8B=92=E7=8B=92=E7=A5=9E?= Date: Thu, 2 Dec 2021 15:01:15 +0800 Subject: [PATCH 8/9] chore: add changelog (#4994) --- packages/miniapp-renderer/CHANGELOG.md | 4 ++++ packages/miniapp-renderer/package.json | 4 ++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/packages/miniapp-renderer/CHANGELOG.md b/packages/miniapp-renderer/CHANGELOG.md index 65a22790d9..3addbba021 100644 --- a/packages/miniapp-renderer/CHANGELOG.md +++ b/packages/miniapp-renderer/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog +## 0.2.2 + +- [Fix] avoid rootEl override `document.body` + ## 0.2.1 - [Refactor] miniapp page component diff --git a/packages/miniapp-renderer/package.json b/packages/miniapp-renderer/package.json index 977ad2eb10..867981a5c5 100644 --- a/packages/miniapp-renderer/package.json +++ b/packages/miniapp-renderer/package.json @@ -1,6 +1,6 @@ { "name": "miniapp-renderer", - "version": "0.2.1", + "version": "0.2.2", "description": "", "author": "ice-admin@alibaba-inc.com", "homepage": "https://github.com/alibaba/ice#readme", @@ -31,4 +31,4 @@ "bugs": { "url": "https://github.com/alibaba/ice/issues" } -} \ No newline at end of file +} From 1871a53296910e896584d0dceac9fe09a041df54 Mon Sep 17 00:00:00 2001 From: ClarkXia Date: Thu, 2 Dec 2021 15:09:37 +0800 Subject: [PATCH 9/9] chore: version (#4992) * chore: version * chore: publish files * fix: update publish files --- packages/build-app-templates/package.json | 4 ++-- packages/build-mpa-config/package.json | 4 ++-- packages/build-user-config/package.json | 2 +- packages/create-app-shared/package.json | 2 +- packages/icejs/package.json | 16 ++++++++-------- packages/plugin-app-core/package.json | 4 ++-- packages/plugin-ice-ssr/package.json | 2 +- packages/plugin-mpa/package.json | 2 +- packages/plugin-react-app/package.json | 9 +++++---- packages/plugin-router/package.json | 2 +- packages/react-app-renderer/package.json | 2 +- 11 files changed, 25 insertions(+), 24 deletions(-) diff --git a/packages/build-app-templates/package.json b/packages/build-app-templates/package.json index 4bc441a57c..f84b39bf60 100644 --- a/packages/build-app-templates/package.json +++ b/packages/build-app-templates/package.json @@ -10,7 +10,7 @@ "lib": "lib" }, "dependencies": { - "create-app-shared": "^1.0.0" + "create-app-shared": "^1.2.0" }, "files": [ "lib", @@ -20,4 +20,4 @@ "type": "http", "url": "https://github.com/alibaba/ice/tree/master/packages/build-app-templates" } -} +} \ No newline at end of file diff --git a/packages/build-mpa-config/package.json b/packages/build-mpa-config/package.json index 2507bea38d..3f91dd32f7 100644 --- a/packages/build-mpa-config/package.json +++ b/packages/build-mpa-config/package.json @@ -25,9 +25,9 @@ "fs-extra": "^8.1.0", "loader-utils": "^2.0.0", "globby": "^11.0.2", - "@builder/app-templates": "^1.0.0" + "@builder/app-templates": "^1.1.0" }, "devDependencies": { "build-scripts": "^1.1.0" } -} +} \ No newline at end of file diff --git a/packages/build-user-config/package.json b/packages/build-user-config/package.json index 2d1d615865..b362ffdbfb 100644 --- a/packages/build-user-config/package.json +++ b/packages/build-user-config/package.json @@ -46,4 +46,4 @@ "bugs": { "url": "https://github.com/alibaba/ice/issues" } -} +} \ No newline at end of file diff --git a/packages/create-app-shared/package.json b/packages/create-app-shared/package.json index 4f99cc8fc1..98c6ef7399 100644 --- a/packages/create-app-shared/package.json +++ b/packages/create-app-shared/package.json @@ -45,4 +45,4 @@ "@types/rax": "^1.0.6", "react": "^17.0.2" } -} +} \ No newline at end of file diff --git a/packages/icejs/package.json b/packages/icejs/package.json index ae87c03d0c..5534ed0916 100644 --- a/packages/icejs/package.json +++ b/packages/icejs/package.json @@ -1,6 +1,6 @@ { "name": "ice.js", - "version": "2.2.3", + "version": "2.3.0", "description": "command line interface and builtin plugin for icejs", "author": "ice-admin@alibaba-inc.com", "homepage": "", @@ -24,17 +24,17 @@ "dependencies": { "@builder/pack": "^0.4.0", "build-scripts": "^1.1.0", - "build-plugin-app-core": "2.0.3", + "build-plugin-app-core": "2.1.0", "build-plugin-helmet": "1.0.2", "build-plugin-ice-auth": "2.0.0", "build-plugin-ice-config": "2.0.1", "build-plugin-ice-logger": "2.0.0", - "build-plugin-ice-mpa": "2.0.2", + "build-plugin-ice-mpa": "2.0.3", "build-plugin-ice-request": "2.0.0", - "build-plugin-ice-router": "2.0.4", - "build-plugin-ice-ssr": "3.0.4", - "build-plugin-ice-store": "2.0.5", - "build-plugin-react-app": "2.0.4", + "build-plugin-ice-router": "2.1.0", + "build-plugin-ice-ssr": "3.0.5", + "build-plugin-ice-store": "2.0.6", + "build-plugin-react-app": "2.1.0", "build-plugin-pwa": "1.0.1", "chalk": "^4.1.0", "chokidar": "^3.3.1", @@ -49,4 +49,4 @@ "npm": ">=3.0.0" }, "gitHead": "cf40d079714b437417e77b444b078cf83286f2fc" -} +} \ No newline at end of file diff --git a/packages/plugin-app-core/package.json b/packages/plugin-app-core/package.json index 3c6445ec01..765f8bc15d 100644 --- a/packages/plugin-app-core/package.json +++ b/packages/plugin-app-core/package.json @@ -20,7 +20,7 @@ }, "dependencies": { "@builder/app-helpers": "^2.4.1", - "@builder/app-templates": "^1.0.2", + "@builder/app-templates": "^1.1.0", "chokidar": "^3.4.1", "ejs": "^3.0.1", "fs-extra": "^8.1.0", @@ -39,4 +39,4 @@ "devDependencies": { "@types/object-hash": "^2.2.1" } -} +} \ No newline at end of file diff --git a/packages/plugin-ice-ssr/package.json b/packages/plugin-ice-ssr/package.json index 8615bde267..b2663b47f5 100644 --- a/packages/plugin-ice-ssr/package.json +++ b/packages/plugin-ice-ssr/package.json @@ -35,4 +35,4 @@ "@ice/runtime": "^0.1.0", "query-string": "^6.13.7" } -} +} \ No newline at end of file diff --git a/packages/plugin-mpa/package.json b/packages/plugin-mpa/package.json index 4032ebcd3c..1327918516 100644 --- a/packages/plugin-mpa/package.json +++ b/packages/plugin-mpa/package.json @@ -25,7 +25,7 @@ }, "dependencies": { "@builder/app-helpers": "^2.4.1", - "@builder/mpa-config": "^4.0.5", + "@builder/mpa-config": "^4.1.0", "fs-extra": "^8.1.0" } } \ No newline at end of file diff --git a/packages/plugin-react-app/package.json b/packages/plugin-react-app/package.json index b44acac12f..61fec58b4d 100644 --- a/packages/plugin-react-app/package.json +++ b/packages/plugin-react-app/package.json @@ -16,7 +16,7 @@ "@builder/app-helpers": "^2.4.1", "@builder/jest-config": "^1.0.2", "@builder/pack": "^0.4.0", - "@builder/user-config": "^1.1.8", + "@builder/user-config": "^1.1.9", "@builder/webpack-config": "^1.0.4", "chalk": "^4.0.0", "debug": "^4.1.1", @@ -33,7 +33,7 @@ "process": "^0.11.10", "query-loader-webpack-plugin": "^1.0.0", "query-string": "^7.0.1", - "react-app-renderer": "^3.0.0", + "react-app-renderer": "^3.0.2", "react-dev-utils": "^11.0.0", "react-refresh": "^0.10.0", "react-router": "^5.2.1", @@ -55,6 +55,7 @@ "gitHead": "07ac7bb07162aac8c90778dd1de4a2060f8df498", "files": [ "lib", - "!lib/**/*.map" + "!lib/**/*.map", + "src/runtime.tsx" ] -} +} \ No newline at end of file diff --git a/packages/plugin-router/package.json b/packages/plugin-router/package.json index baba2bd9cf..75f9c76cf2 100644 --- a/packages/plugin-router/package.json +++ b/packages/plugin-router/package.json @@ -45,4 +45,4 @@ "test": "echo \"Error: run tests from root\" && exit 1" }, "gitHead": "6bbf8de986f2e6d4820c2dc7f92fa87d917b23f7" -} +} \ No newline at end of file diff --git a/packages/react-app-renderer/package.json b/packages/react-app-renderer/package.json index c8604754dc..0ab56408b2 100644 --- a/packages/react-app-renderer/package.json +++ b/packages/react-app-renderer/package.json @@ -36,4 +36,4 @@ "bugs": { "url": "https://github.com/alibaba/ice/issues" } -} +} \ No newline at end of file