Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release 1.17.7 #4279

Merged
merged 6 commits into from
Apr 29, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions packages/build-mpa-config/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## 3.2.5

- feat add `props.pageConfig` in Rax App MPA page component

## 3.2.4

- fix: generate mpa entries when app.ts is entry in rax-app
2 changes: 1 addition & 1 deletion packages/build-mpa-config/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@builder/mpa-config",
"version": "3.2.4",
"version": "3.2.5",
"description": "enable mpa project for framework",
"author": "ice-admin@alibaba-inc.com",
"homepage": "",
5 changes: 3 additions & 2 deletions packages/build-mpa-config/src/generateEntry.ts
Original file line number Diff line number Diff line change
@@ -2,7 +2,7 @@ import * as path from 'path';
import * as globby from 'globby';
import { formatPath } from '@builder/app-helpers';

function generateEntry(api, { framework, targetDir, pageEntry, entryName }) {
function generateEntry(api, { framework, targetDir, pageEntry, entryName, pageConfig = {} }) {
const { context: { userConfig: { web: webConfig = {} }, rootDir }, getValue } = api;
const entryFolder = path.join(targetDir, 'mpaEntry');
const entryPath = path.join(entryFolder, `${entryName}.tsx`);
@@ -16,7 +16,8 @@ function generateEntry(api, { framework, targetDir, pageEntry, entryName }) {
resourcePath: `${formatPath(path.extname(pageEntry) ? pageEntry.split('.').slice(0, -1).join('.') : pageEntry)}`,
customTabBarPath,
needCustomTabBar,
globalStyle: globalStyles.length && formatPath(path.join(rootDir, globalStyles[0]))
globalStyle: globalStyles.length && formatPath(path.join(rootDir, globalStyles[0])),
pageConfig: JSON.stringify(pageConfig),
});
return entryPath;
}
5 changes: 3 additions & 2 deletions packages/build-mpa-config/src/index.ts
Original file line number Diff line number Diff line change
@@ -29,12 +29,13 @@ export const generateMPAEntries = (api, options: IConfigOptions) => {

const parsedEntries = {};
entries.forEach((entry) => {
const { entryName, entryPath, source } = entry;
const { entryName, entryPath, ...pageConfig } = entry;
const { source } = pageConfig;
const useOriginEntry = /app(\.(t|j)sx?)?$/.test(entryPath);
// icejs will config entry by api modifyUserConfig
// when the entry has no export default declaration or is app.ts, do not generate entry
const finalEntry = !useOriginEntry && checkExportDefaultDeclarationExists(path.join(rootDir, 'src', source)) ?
generateEntry(api, { framework, targetDir, pageEntry: entryPath, entryName }) :
generateEntry(api, { framework, targetDir, pageEntry: entryPath, entryName, pageConfig }) :
entryPath;

parsedEntries[entryName] = {
19 changes: 14 additions & 5 deletions packages/build-mpa-config/src/template/rax.ts.ejs
Original file line number Diff line number Diff line change
@@ -36,18 +36,27 @@ class PageWrapper extends Component {


if (!isNode) {
const isSSR = window.__INITIAL_DATA__ && window.__INITIAL_DATA__.__SSR_ENABLED__;
const isSSR = (window as any).__INITIAL_DATA__ && (window as any).__INITIAL_DATA__.__SSR_ENABLED__;

if (isWeex || isKraken) {
render(<PageWrapper />, null, { driver: DriverUniversal });
render(<PageWrapper pageConfig={<%- pageConfig %> } />, null, { driver: DriverUniversal });
} else {
const renderApp = async function() {
let comProps = {};
let comProps = {
pageConfig: <%- pageConfig %>,
};
// process App.getInitialProps
if (isSSR && window.__INITIAL_DATA__.pageInitialProps !== null) {
comProps = window.__INITIAL_DATA__.pageInitialProps;
comProps = {
...comProps,
...window.__INITIAL_DATA__.pageInitialProps,
};
} else if (PageComponent.getInitialProps) {
comProps = await PageComponent.getInitialProps();
const initialProps = await PageComponent.getInitialProps();
comProps = {
...comProps,
...initialProps,
};
}

render(<PageWrapper {...comProps} />, document.getElementById('root'), { driver: DriverUniversal, hydrate: <%- hydrate %> });
4 changes: 4 additions & 0 deletions packages/build-user-config/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## 0.3.5

- [feat] add `props.pageConfig` in Rax App SPA page component

## 0.3.4

- [fix] remove deprecated api of esbuild-loader
2 changes: 1 addition & 1 deletion packages/build-user-config/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@builder/user-config",
"version": "0.3.4",
"version": "0.3.5",
"description": "Includes methods which are releated to set base user config for framework",
"homepage": "",
"license": "MIT",
18 changes: 13 additions & 5 deletions packages/build-user-config/src/loaders/AppConfigLoader/index.js
Original file line number Diff line number Diff line change
@@ -46,22 +46,30 @@ module.exports = function (appJSON) {
const reference = mod.default;
function Component(props) {
${routeTitle ? `document.title="${routeTitle}"` : ''}
return createElement(reference, Object.assign({}, routeProps, props));
return createElement(reference, { pageConfig: ${JSON.stringify(route)}, ...routeProps, ...props });
}
Component.__path = '${route.path}';
Component.getInitialProps = reference.getInitialProps;
return Component;
})
`;
const importComponentInClient = `() => () => require('${formatPath(pageSource)}').default`;
// without useRouter
const importComponentInServer = `() => require('${formatPath(pageSource)}').default`;

const importComponentDirectly = `() => {
function Component(props) {
return createElement(require('${formatPath(pageSource)}').default, { pageConfig: ${JSON.stringify(route)}, ...props })
}
return Component;
}`;

// For rax-use-router lazy load page component
const importComponentInClient = `() => ${importComponentDirectly}`;

let importComponent;
if (target === 'web') {
importComponent = dynamicImportComponent;
} else if (target === 'ssr') {
importComponent = importComponentInServer;
// without useRouter
importComponent = importComponentDirectly;
} else {
importComponent = importComponentInClient;
}
4 changes: 2 additions & 2 deletions packages/icejs/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ice.js",
"version": "1.17.6",
"version": "1.17.7",
"description": "command line interface and builtin plugin for icejs",
"author": "ice-admin@alibaba-inc.com",
"homepage": "",
@@ -30,7 +30,7 @@
"build-plugin-ice-logger": "1.7.4",
"build-plugin-ice-mpa": "1.8.6",
"build-plugin-ice-request": "1.7.6",
"build-plugin-ice-router": "1.9.5",
"build-plugin-ice-router": "1.9.6",
"build-plugin-ice-ssr": "2.1.2",
"build-plugin-ice-store": "1.9.7",
"build-plugin-react-app": "1.8.3",
5 changes: 5 additions & 0 deletions packages/plugin-fusion/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Changelog

## 0.1.15

- [fix] remove useless string in calculated colors
- [chore] remove err stack when config slient

## 0.1.14

- [feat] support `cssVariable` to enable css variables
4 changes: 2 additions & 2 deletions packages/plugin-fusion/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "build-plugin-fusion",
"version": "0.1.14",
"version": "0.1.15",
"description": "plugin for build scripts while use fusion component",
"main": "lib/index.js",
"scripts": {
@@ -35,4 +35,4 @@
"type": "http",
"url": "https://github.com/alibaba/ice/tree/master/packages/plugin-fusion"
}
}
}
1 change: 0 additions & 1 deletion packages/plugin-fusion/src/index.js
Original file line number Diff line number Diff line change
@@ -47,7 +47,6 @@ function getVariablesPath({
try {
filePath = require.resolve(variables);
} catch (err) {
console.log(err);
if (!slient) {
console.log('[ERROR]', `fail to resolve ${variables}`);
}
3 changes: 2 additions & 1 deletion packages/plugin-fusion/src/utils/getCalcVars.js
Original file line number Diff line number Diff line change
@@ -56,9 +56,10 @@ ${calcKeys.map((key) => {
const calcVars = {};
const calcCss = cssContent.match(CSS_REGEX);
if (calcCss) {
// parse `.color-calculate-mask-background{color: #000}` as `calcVars['calculate-color-mask-background'] = '#000'`
calcCss.forEach((item) => {
const [key, value] = item.split('{');
calcVars[key.replace(/\.|\{/g, '').trim()] = value.replace(/;|\}/g, '').trim();
calcVars[key.replace(/\.|\{/g, '').trim()] = value.replace(/;|\}/g, '').replace('color:', '').trim();
});
}
return calcVars;
7 changes: 2 additions & 5 deletions packages/plugin-fusion/src/utils/getThemeCode.js
Original file line number Diff line number Diff line change
@@ -30,12 +30,9 @@ function changeTheme(currentTheme) {
// Get current theme
const theme = themesData[currentTheme];
if (theme) {
// Declare the style element
const styles = \`\${theme}\`;
// Function call
appendStyle(styles);
appendStyle(theme);
} else {
console.warn(\`can not find theme: \${currentTheme}\`);
console.warn('can not find theme:' + currentTheme);
}
}
${defaultTheme ? `changeTheme('${defaultTheme}');` : ''}
4 changes: 4 additions & 0 deletions packages/plugin-router/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## 1.9.6

- [fix] router path is invalid after using `path.join` function

## 1.9.5

- [fix] support customRouterProps of renderRouter
3 changes: 2 additions & 1 deletion packages/plugin-router/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "build-plugin-ice-router",
"version": "1.9.5",
"version": "1.9.6",
"description": "build-plugin-ice-router",
"author": "ice-admin@alibaba-inc.com",
"homepage": "",
@@ -27,6 +27,7 @@
"@types/glob": "^7.1.1",
"@types/history": "^4.7.5",
"@types/node": "^12.12.12",
"path-to-regexp": "^6.2.0",
"typescript": "^4.0.0"
},
"files": [
6 changes: 3 additions & 3 deletions packages/plugin-router/src/runtime/formatRoutes.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import * as React from 'react';
import * as path from 'path';
import * as queryString from 'query-string';
import { IRouterConfig } from '../types';
import joinPath from '../utils/joinPath';

const { useEffect, useState } = React;

export default function formatRoutes(routes: IRouterConfig[], parentPath: string) {
return routes.map((item) => {
if (item.path) {
const joinPath = path.join(parentPath || '', item.path);
item.path = joinPath === '/' ? '/' : joinPath.replace(/\/$/, '');
const routePath = joinPath(parentPath || '', item.path);
item.path = routePath === '/' ? '/' : routePath.replace(/\/$/, '');
}
if (item.children) {
item.children = formatRoutes(item.children, item.path);
77 changes: 77 additions & 0 deletions packages/plugin-router/src/utils/__tests__/joinPath.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
import { pathToRegexp } from 'path-to-regexp';
import joinPath from '../joinPath';

const joinTests: [string[], string][] = [
[[], ''],
[['', '/'], '/'],
[[' ', '/'], ' /'],
[['', 'foo'], 'foo'],
[['foo', '/bar', 'aa'], 'foo/bar/aa'],
[['', '/foo'], '/foo'],
[['', '', '/foo'], '/foo'],
[['', '', 'foo'], 'foo'],
[['foo', ''], 'foo'],
[['foo/', ''], 'foo/'],
[['foo', '', '/bar'], 'foo/bar'],
[['/'], '/'],
[[' /foo'], ' /foo'],
[[' ', 'foo'], ' /foo'],
[[' ', ''], ' '],
[['/', 'foo'], '/foo'],
[['/', '/foo'], '/foo'],
[['/', '//foo'], '/foo'],
[['/', '', '/foo'], '/foo'],
[['', '/', 'foo'], '/foo'],
[['', '/', '/foo'], '/foo'],

[['/', '/:id'], '/:id'],
[['/user', '/:id'], '/user/:id'],
[['/user', '/:test(\\d+)+'], '/user/:test(\\d+)+']
];

describe('path join', () => {
joinTests.forEach(p => {
test(`input: ${JSON.stringify(p[0])} expected: ${p[1]}`, () => {
const actual = joinPath(...p[0]);
expect(actual).toStrictEqual(p[1]);
});
});

test('will throw Error', () => {
expect(() => joinPath(null)).toThrowError();
});
});

const regexpPathTests: [string[], string, string[] | null][] = [
[['/', '/:id'], '/123', ['/123', '123']],
[['/user', '/:id'], '/user/123', ['/user/123', '123']],
[['/user', '/:id', '/abc'], '/user/123/abc', ['/user/123/abc', '123']],
[['/:uid', '/:id'], '/12345/123', ['/12345/123', '12345', '123']],
[['/login', '/:test(\\d+)+'], '/abc/123/456/789', null],
[['/login', '/:test(\\d+)+'], '/login/123/456/789', ['/login/123/456/789', '123/456/789']],
[['/login', '/:path(abc|xyz)*'], '/login/abc', ['/login/abc', 'abc']],
[['/login', '/:path(abc|xyz)*'], '/login/xyz', ['/login/xyz', 'xyz']],
[['/login', '/:path(abc|xyz)*'], '/login/abc/abc', ['/login/abc/abc', 'abc/abc']],
[['/login', '/:path(abc|xyz)*'], '/login/xxx', null],
[['/login', '/(.*)'], '/login/xxx', ['/login/xxx', 'xxx']],
[['/abc', '/:test((?!login)[^/]+)'], '/abc/xxx', ['/abc/xxx', 'xxx']],
[['/abc', '/:test((?!login)[^/]+)'], '/abc/login', null],
[['/abc', '/user(s)?/:user'], '/abc/user/123', ['/abc/user/123', undefined, '123']],
[['/abc', '/user(s)?/:user'], '/abc/users/123', ['/abc/users/123', 's', '123']],
];

describe('path-to-regexp', () => {
regexpPathTests.forEach(p => {
const [pathJoinArray, input, expected] = p;
test(`pathArray: ${JSON.stringify(pathJoinArray)} input: ${input} expected: ${JSON.stringify(expected)}`, () => {
const re = pathToRegexp(joinPath(...pathJoinArray));
expect(exec(re, input)).toStrictEqual(expected);
});
});
});

function exec(re: RegExp, str: string) {
const match = re.exec(str);

return match && Array.prototype.slice.call(match);
}
33 changes: 33 additions & 0 deletions packages/plugin-router/src/utils/joinPath.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/**
* Join the route paths.
* @param strArray
* @returns string
*/
function joinPath(...strArray: string[]): string {
if (strArray.length === 0) {
return '';
}
const resultArray = [];
const filterStrArray = strArray.filter(str => str !== '');
filterStrArray.forEach((str, index) => {
if (typeof str !== 'string') {
throw new Error(`Path must be a string. Received ${str}`);
}
let routePath = str;
// Fork from https://github.com/jfromaniello/url-join@4.0.1
if (index > 0) {
routePath = routePath.replace(/^[/]+/, '');
}
if (index < filterStrArray.length - 1) {
// Removing the ending slashes for each component but the last.
routePath = routePath.replace(/[/]+$/, '');
} else {
// For the last component we will combine multiple slashes to a single one.
routePath = routePath.replace(/[/]+$/, '/');
}
resultArray.push(routePath);
});
return resultArray.join('/');
}

export default joinPath;
3 changes: 2 additions & 1 deletion packages/plugin-router/tsconfig.json
Original file line number Diff line number Diff line change
@@ -9,6 +9,7 @@
},
},
"exclude": [
"templates"
"templates",
"src/utils/__tests__"
]
}
5 changes: 5 additions & 0 deletions packages/plugin-webpack5/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Changelog

## 1.2.4

- [fix] add next.css after global style
- [fix] do not detect package when remote runtime is disabled

## 1.2.3

- [feat] support `cacheLog` for file system info
2 changes: 1 addition & 1 deletion packages/plugin-webpack5/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "build-plugin-webpack5",
"version": "1.2.3",
"version": "1.2.4",
"description": "build-scripts plugin for compatible with webpack 5",
"main": "lib/index.js",
"scripts": {
2 changes: 1 addition & 1 deletion packages/plugin-webpack5/src/index.ts
Original file line number Diff line number Diff line change
@@ -53,7 +53,7 @@ const plugin: IPlugin = async (api, options = {}) => {
externals.push(externalMap);
}
// filter dependencies
let compileKeys = await filterPackages(Object.keys(pkgDeps), context.rootDir, typeof remoteRuntime !== 'boolean' ? remoteRuntime : {});
let compileKeys = activeRemoteRuntime ? await filterPackages(Object.keys(pkgDeps), context.rootDir, typeof remoteRuntime !== 'boolean' ? remoteRuntime : {}) : [];
let needCompile = false;

if (activeRemoteRuntime) {
5 changes: 3 additions & 2 deletions packages/plugin-webpack5/src/remoteConfig.ts
Original file line number Diff line number Diff line change
@@ -47,11 +47,12 @@ export default (api: IPluginAPI, { remoteName, compileKeys, runtimeFolder, injec
.tap(([args]) => {
const templateContent = fse.readFileSync(args.template);
const $ = cheerio.load(templateContent);
injectBundles.forEach((bundleUrl) => {
injectBundles.forEach((bundleUrl: string) => {
if (path.extname(bundleUrl) === '.js') {
$('head').append(`<script src="${bundleUrl}"></script>`);
} else {
$('head').append(`<link rel="stylesheet" type="text/css" href="${bundleUrl}">`);
// global css such as next.css should been added after global style
$('body').append(`<link rel="stylesheet" type="text/css" href="${bundleUrl}">`);
}
});
delete args.template;
6 changes: 6 additions & 0 deletions packages/react-app-renderer/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Changelog

## 2.0.2

- [fix] throw error when not setting route type
- [feat] throw error when not using the BrowserRouter
4 changes: 2 additions & 2 deletions packages/react-app-renderer/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react-app-renderer",
"version": "2.0.1",
"version": "2.0.2",
"description": "",
"author": "ice-admin@alibaba-inc.com",
"homepage": "https://github.com/alibaba/ice#readme",
@@ -34,4 +34,4 @@
"bugs": {
"url": "https://github.com/alibaba/ice/issues"
}
}
}
4 changes: 4 additions & 0 deletions packages/react-app-renderer/src/server.tsx
Original file line number Diff line number Diff line change
@@ -35,6 +35,10 @@ function renderInServer(context, options) {

export default function reactAppRendererWithSSR(context, options) {
const { appConfig } = options || {};
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';
return renderInServer(context, options);
}