Skip to content

Commit

Permalink
Merge pull request #5089 from alibaba/release-next
Browse files Browse the repository at this point in the history
Release/2.4.3
  • Loading branch information
ClarkXia authored Dec 30, 2021
2 parents b0766cd + 43b9245 commit 0cb077d
Show file tree
Hide file tree
Showing 24 changed files with 132 additions and 76 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
name: CI

env:
NODE_OPTIONS: --max-old-space-size=6144

on: [push]

jobs:
Expand Down
1 change: 0 additions & 1 deletion examples/basic-auth/build.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
{
"plugins": [
"build-plugin-ice-auth"
]
}
14 changes: 11 additions & 3 deletions examples/basic-auth/src/app.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import React from 'react';
import { runApp, IAppConfig } from 'ice';
import { runApp, IAppConfig, Link } from 'ice';

const appConfig: IAppConfig = {
app: {
getInitialData: async () => {
// 模拟服务端返回的数据
const data = {
role: 'admin',
role: 'guest',
starPermission: true,
followPermission: true
};
Expand All @@ -25,7 +25,15 @@ const appConfig: IAppConfig = {
},
auth: {
// 可选的,设置无权限时的展示组件,默认为 null
NoAuthFallback: () => <div>没有权限...</div>,
NoAuthFallback: (props) => {
console.log('NoAuthFallback props', props);
return (
<div>
没有权限...
<Link to="/">返回首页</Link>
</div>
);
}
},
};

Expand Down
14 changes: 14 additions & 0 deletions examples/basic-auth/src/pages/About/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/* eslint jsx-a11y/aria-role: 0 */
import React from 'react';
import { Link } from 'ice';

const About = () => {
return (
<div>
<h2>About Page</h2>
<Link to="/">Back Home</Link>
</div>
);
};

export default About;
8 changes: 5 additions & 3 deletions examples/basic-auth/src/pages/Home/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* eslint jsx-a11y/aria-role: 0 */
import React from 'react';
import { useAuth, withAuth } from 'ice';
import { Link, useAuth, withAuth } from 'ice';
import Auth from '@/components/Auth';

const Demo1 = withAuth(({ auth }) => {
Expand Down Expand Up @@ -63,10 +63,12 @@ const Demo2 = () => {
);
};

const HomePage = () => {
const HomePage = (props) => {
console.log('home page props', props);
return (
<div>
<h2>Home Page</h2>
<Link to="/about">Go To About</Link><br />
<Demo1 />
<Demo2 />
</div>
Expand All @@ -75,7 +77,7 @@ const HomePage = () => {

HomePage.pageConfig = {
title: 'test',
auth: ['admin'],
auth: ['guest'],
};

export default HomePage;
10 changes: 10 additions & 0 deletions examples/basic-auth/src/routes.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,21 @@
import { lazy } from 'ice';

const Home = lazy(() => import('@/pages/Home'));
const About = lazy(() => import('@/pages/About'));

export default [
{
path: '/',
exact: true,
component: Home,
},
{
path: '/about',
exact: true,
component: About,
pageConfig: {
auth: ['admin'],
title: 'about',
},
}
];
5 changes: 5 additions & 0 deletions examples/basic-spa/build.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@
},
"plugins": [],
"tsChecker": true,
"devServer": {
"historyApiFallback": {
"disableDotRule": true
}
},
"sassLoaderOptions": {
"prependData": ".test{color:red}"
},
Expand Down
8 changes: 8 additions & 0 deletions examples/basic-spa/src/routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,14 @@ const routes: IRouterConfig[] = [
exact: true,
component: About
},
{
path: '/a.html',
exact: true,
component: Home,
getInitialProps: async () => {
return { count: 1 };
},
},
{
path: '/',
exact: true,
Expand Down
6 changes: 3 additions & 3 deletions packages/icejs/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ice.js",
"version": "2.4.2",
"version": "2.4.3",
"description": "command line interface and builtin plugin for icejs",
"author": "[email protected]",
"homepage": "",
Expand All @@ -24,9 +24,9 @@
"dependencies": {
"@builder/pack": "^0.5.0",
"build-scripts": "^1.1.0",
"build-plugin-app-core": "2.1.0",
"build-plugin-app-core": "2.1.1",
"build-plugin-helmet": "1.0.2",
"build-plugin-ice-auth": "2.0.0",
"build-plugin-ice-auth": "2.0.1",
"build-plugin-ice-config": "2.0.2",
"build-plugin-ice-logger": "2.0.0",
"build-plugin-ice-mpa": "2.0.4",
Expand Down
4 changes: 4 additions & 0 deletions packages/plugin-app-core/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## 2.1.1

- [fix] circular dependence of lazy when run test

## 2.1.0

- [feat] register `router`&`request` to userConfig
Expand Down
2 changes: 1 addition & 1 deletion packages/plugin-app-core/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "build-plugin-app-core",
"version": "2.1.0",
"version": "2.1.1",
"description": "the core plugin for icejs and raxjs.",
"author": "[email protected]",
"homepage": "",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@

export * from './core/routerAPI';
export * from './core/publicAPI';
export * from './core/runApp';
<% if (isReact) {%>
export { lazy } from './core/lazy';
<% } %>
export * from './core/runApp';
export * from './types';
5 changes: 5 additions & 0 deletions packages/plugin-auth/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Changelog

## 2.0.1

- [feat] pass page props to NoAuthFallback
- [chore] optimize unless withAuth

## 2.0.0

- [feat] migrate runtime api
Expand Down
7 changes: 3 additions & 4 deletions packages/plugin-auth/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "build-plugin-ice-auth",
"version": "2.0.0",
"version": "2.0.1",
"description": "",
"author": "[email protected]",
"homepage": "https://github.com/alibaba/ice#readme",
Expand All @@ -16,9 +16,8 @@
"react-dom": ">16.0.0"
},
"files": [
"src",
"lib",
"template",
"src/runtime.tsx",
"!lib/**/*.map"
],
"repository": {
Expand All @@ -31,4 +30,4 @@
"bugs": {
"url": "https://github.com/alibaba/ice/issues"
}
}
}
19 changes: 4 additions & 15 deletions packages/plugin-auth/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,27 +1,16 @@
import * as path from 'path';
import { IPluginAPI } from 'build-scripts';

const PLUGIN_AUTH_DIR = 'auth';

export default async function (api: IPluginAPI) {
const { getValue, onGetWebpackConfig, applyMethod } = api;
const iceTemp = getValue<string>('TEMP_PATH');

// 复制模板到 .ice/auth 目录下
const templateSourceDir = path.join(__dirname, '../template');
applyMethod('addPluginTemplate', templateSourceDir);

onGetWebpackConfig((config) => {
config.resolve.alias.set('$ice/auth', path.join(iceTemp, 'plugins', PLUGIN_AUTH_DIR, 'index.tsx'));
});
const { applyMethod } = api;

const distPath = 'plugins/auth/pluginRuntime/runtime';
// 导出接口
// import { useAuth, withAuth } from 'ice';
applyMethod('addExport', { source: './plugins/auth', importSource: '$$ice/plugins/auth', exportMembers: ['withAuth', 'useAuth'] });
applyMethod('addExport', { source: `./${distPath}/Auth`, importSource: `$$ice/${distPath}/Auth`, exportMembers: ['withAuth', 'useAuth'] });

// 设置类型
// export interface IAppConfig {
// auth?: IAuth;
// }
applyMethod('addAppConfigTypes', { source: '../plugins/auth/types', specifier: '{ IAuth }', exportName: 'auth?: IAuth' });
applyMethod('addAppConfigTypes', { source: `../${distPath}/types`, specifier: '{ IAuth }', exportName: 'auth?: IAuth' });
}
15 changes: 6 additions & 9 deletions packages/plugin-auth/src/runtime.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
import * as React from 'react';
// @ts-ignore
import { Provider, withAuth, IAuth } from '$ice/auth';
import { Provider, useAuth, IAuth } from './runtime/Auth';

const wrapperComponentFn = (authConfig: IAuth) => (PageComponent) => {
const { pageConfig = {} } = PageComponent;

const AuthWrappedComponent = (props) => {
// filter setAuth
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const { auth, setAuth, ...rest } = props;
const [ auth ] = useAuth();
const pageConfigAuth = pageConfig.auth;

if (pageConfigAuth && !Array.isArray(pageConfigAuth)) {
Expand All @@ -25,15 +22,15 @@ const wrapperComponentFn = (authConfig: IAuth) => (PageComponent) => {
if (!hasAuth) {
if (authConfig.NoAuthFallback) {
if (typeof authConfig.NoAuthFallback === 'function') {
return <authConfig.NoAuthFallback />;
return <authConfig.NoAuthFallback {...Object.assign({}, props, {pageConfig})} />;
}
return authConfig.NoAuthFallback;
}
return null;
return <>No Auth</>;
}
return <PageComponent {...rest} />;
return <PageComponent {...props} />;
};
return withAuth(AuthWrappedComponent);
return AuthWrappedComponent;
};

export default ({ context, appConfig, addProvider, wrapperPageComponent }) => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
<% if(!hasJsxRuntime) { %>
import * as React from 'react';
<% } %>
import * as React from 'react';
import { FC, createContext, useState, useContext } from 'react';
import { ContextType, AuthType, IAuth } from './types';

const Context = createContext<any>(null);

interface Props {
interface ProviderProps {
value: AuthType;
}

Expand All @@ -15,12 +13,12 @@ interface InjectProps {
useAuth: ContextType[1];
}

const Provider: FC<Props> = ({ value = {}, children }) => {
const Provider: FC<ProviderProps> = ({ value = {}, children }) => {
const [state, setState] = useState<AuthType>(value);
const updateState: InjectProps['useAuth'] = (value = {}) => {
const updateState: InjectProps['useAuth'] = (newState = {}) => {
setState({
...state,
...value,
...newState,
});
};
return <Context.Provider value={[state, updateState]}>{children}</Context.Provider>;
Expand All @@ -38,9 +36,9 @@ function withAuth<Props extends InjectProps>(Component: React.ComponentType<Prop
const [auth, setAuth] = useAuth();
const WrappedComponent = Component as React.ComponentType<OriginalProps>;
return <WrappedComponent {...props} auth={auth} setAuth={setAuth} />;
}
};
return AuthWrapped;
};
}

export { useAuth, withAuth, Provider };

Expand Down
File renamed without changes.
5 changes: 1 addition & 4 deletions packages/plugin-auth/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,5 @@
"paths": {
"$ice/authStore": ["./src/_authStore"]
}
},
"exclude": [
"template/*"
]
}
}
5 changes: 5 additions & 0 deletions packages/vite-service/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# CHANGELOG

## 2.0.3

- [fix] open both `about:blank` page and `localhost:3333` page
- [fix] `after.start.devServer` callback function has been called before the devServer is ready

## 2.0.2

- [feat] pass `context.rootDir` to `viteConfig.root`
Expand Down
6 changes: 3 additions & 3 deletions packages/vite-service/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@builder/vite-service",
"version": "2.0.2",
"version": "2.0.3",
"description": "vite implementation",
"author": "[email protected]",
"homepage": "",
Expand All @@ -26,7 +26,6 @@
"@rollup/pluginutils": "^4.1.1",
"@vitejs/plugin-legacy": "^1.5.0",
"@vitejs/plugin-react": "^1.0.7",
"build-scripts": "^1.1.0",
"chalk": "^2.4.1",
"cheerio": "^1.0.0-rc.10",
"connect-history-api-fallback": "^1.6.0",
Expand All @@ -44,6 +43,7 @@
},
"devDependencies": {
"@types/connect-history-api-fallback": "^1.3.5",
"@types/lodash": "^4.14.147"
"@types/lodash": "^4.14.147",
"build-scripts": "^1.2.1"
}
}
Loading

0 comments on commit 0cb077d

Please sign in to comment.