Skip to content

Commit

Permalink
Merge pull request #943 from raxjs/release-next
Browse files Browse the repository at this point in the history
release: v3.8.7
  • Loading branch information
SoloJiang authored Dec 30, 2021
2 parents 9cd71b3 + 584a28c commit 9e97708
Show file tree
Hide file tree
Showing 21 changed files with 100 additions and 63 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
## Changelog

## 3.8.7

- Fix: SPA SSR `getInitialProps` is invalid
- Feat: miniapp webview mode should modify app to MPA type
- Chore: add ssr test case
- Chore: remove DEF comment node

## 3.8.6

- Fix: page component import method in the env other than web
Expand Down
30 changes: 30 additions & 0 deletions __tests__/build-cases/basic-spa-ssr.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import * as path from 'path';
import * as cheerio from 'cheerio';
import { buildFixture } from '../utils/build';

const example = 'basic-spa-ssr';
const BUNDLE_URL = require.resolve(path.join(process.cwd(), `examples/${example}/build/node/index.js`));

describe('should build web result: ', () => {
buildFixture(example);

test('ssr render method', async () => {
const { render } = require(BUNDLE_URL);
const ctxReq = {
url: '/?a=1',
path: '/',
};

let html;
const ctxRes = {
setHeader() {},
send(result) {
html = result;
},
};
const ctx = { req: ctxReq, res: ctxRes };
await render(ctx);
const $ = cheerio.load(html, { decodeEntities: false });
expect($('.title').text()).toBe('Welcome to Your Rax App with SSR');
});
});
3 changes: 1 addition & 2 deletions examples/basic-spa-ssr/build.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,5 @@
"targets": ["web"],
"web": {
"ssr": true
},
"swc": true
}
}
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@
"simple-git": "^1.132.0",
"ts-jest": "^25.4.0",
"ts-node": "^8.6.1",
"typescript": "^3.7.4"
"typescript": "^4.0.0",
"cheerio": "1.0.0-rc.3"
},
"dependencies": {
"core-js": "^3.6.4",
Expand Down
8 changes: 4 additions & 4 deletions packages/babel-plugin-transform-jsx-to-html/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ module.exports = function () {

const result = [];

let html = `<${ tagName}`;
let html = `<${tagName}`;

let attrs = openingPath.node.attributes;
if (attrs.length) {
Expand Down Expand Up @@ -68,7 +68,7 @@ module.exports = function () {
}

if (path.node.closingElement || innerHTML) {
pushResult(t.stringLiteral(`</${ tagName }>`), result);
pushResult(t.stringLiteral(`</${tagName}>`), result);
}

if (result && result.length) {
Expand Down Expand Up @@ -197,7 +197,7 @@ function buildOpeningElementAttributes(attribs, file) {
name = 'class';
}
const value = prop.value.value.replace(/\n\s+/g, ' ');
staticAttrs = `${staticAttrs } ${ name }="${ value }"`;
staticAttrs = `${staticAttrs} ${name}="${value}"`;
} else {
_props.push(convertAttribute(prop));
}
Expand Down Expand Up @@ -260,7 +260,7 @@ function convertAttribute(node) {

if (t.isJSXNamespacedName(node.name)) {
node.name = t.stringLiteral(
`${node.name.namespace.name }:${ node.name.name.name}`,
`${node.name.namespace.name}:${node.name.name.name}`,
);
} else if (esutils.keyword.isIdentifierNameES6(node.name.name)) {
node.name.type = 'Identifier';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ export default function (resolver, hook, conditionNames) {
fragment,
};

resolver.doResolve(hook, obj, `using exports field: ${ p}`, resolveContext, forEachCallback);
resolver.doResolve(hook, obj, `using exports field: ${p}`, resolveContext, forEachCallback);
},
(err, result) => callback(err, result || null),
);
Expand Down
4 changes: 4 additions & 0 deletions packages/plugin-rax-app/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## 7.0.4

- Fix: Remove error message when using mpa mode with webview miniapp

## 7.0.3

- Fix: page component import method in the env other than web
Expand Down
2 changes: 1 addition & 1 deletion packages/plugin-rax-app/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "build-plugin-rax-app",
"version": "7.0.3",
"version": "7.0.4",
"description": "The basic webpack configuration for rax project",
"author": "Rax Team",
"main": "lib/index.js",
Expand Down
4 changes: 2 additions & 2 deletions packages/plugin-rax-app/src/userConfig/modify.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export default (api) => {
}

// Unify all targets mpa config
const hasMPA = newUserConfig.targets.some((target) => newUserConfig[target] && newUserConfig[target].mpa);
const hasMPA = newUserConfig.targets.some((target) => newUserConfig[target] && (newUserConfig[target].mpa || newUserConfig[target].buildType === 'webview'));
if (hasMPA) {
newUserConfig.targets
// Avoid miniapp runtime mode be became MPA
Expand All @@ -78,7 +78,7 @@ export default (api) => {

// Warning tip when use miniapp runtime mode with MPA
for (const target of newUserConfig.targets) {
if (MINIAPP_PLATFORMS.includes(target) && !newUserConfig[target]?.subpackages) {
if (MINIAPP_PLATFORMS.includes(target) && !newUserConfig[target]?.subpackages && newUserConfig[target]?.buildType !== 'webview') {
log.error('小程序非分包模式不推荐和 MPA 应用同时使用,下一个大版本将禁止该能力!');
}
}
Expand Down
5 changes: 5 additions & 0 deletions packages/plugin-rax-web/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Changelog

## v2.0.4

- Fix: not filter routes by target in document plugin
- Fix: DEF remove comment node check

## v2.0.3

- Chore: add logic protect
Expand Down
4 changes: 2 additions & 2 deletions packages/plugin-rax-web/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "build-plugin-rax-web",
"version": "2.0.3",
"version": "2.0.4",
"description": "rax web app plugin",
"main": "lib/index.js",
"scripts": {
Expand Down Expand Up @@ -37,4 +37,4 @@
"devDependencies": {
"webpack": ">=4.0.0"
}
}
}
14 changes: 11 additions & 3 deletions packages/plugin-rax-web/src/Plugins/DocumentPlugin.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as path from 'path';
import * as Module from 'module';
import * as cheerio from 'cheerio';
import { load } from 'cheerio';
import * as htmlparser2 from 'htmlparser2';
import { getEntriesByRoute } from '@builder/app-helpers';
import { registerListenTask, getAssets, getEnableStatus, updateEnableStatus } from '../utils/localBuildCache';
Expand Down Expand Up @@ -31,6 +31,7 @@ export default class DocumentPlugin {
},
documentPath,
insertScript,
target,
} = this.options;
const { mpa, doctype = '<!DOCTYPE html>', ssr, staticExport } = webConfig || {};
// DEF plugin will pass publicPath override compiler publicPath in Weex Type App
Expand Down Expand Up @@ -65,6 +66,7 @@ export default class DocumentPlugin {
entryName,
mpa,
rootDir,
target,
});
let html = '';
// PHA will consume document field
Expand All @@ -84,7 +86,7 @@ export default class DocumentPlugin {
}

const parserOptions = { decodeEntities: false };
const $ = cheerio.load(htmlparser2.parseDOM(html, parserOptions), parserOptions);
const $ = load(htmlparser2.parseDOM(html, parserOptions), parserOptions);
if (injectedHTML.comboScripts.length) {
// Insert comboed script
$('#root').after([genComboedScript(injectedHTML.comboScripts), ...injectedHTML.scripts]);
Expand Down Expand Up @@ -132,9 +134,15 @@ export default class DocumentPlugin {
}
}

function getTitleByStaticConfig(staticConfig, { entryName, mpa, rootDir }): string {
function getTitleByStaticConfig(staticConfig, { entryName, mpa, rootDir, target }): string {
if (!mpa) return staticConfig.window?.title;
const route = staticConfig.routes
.filter((r) => {
if (Array.isArray(r.targets) && !r.targets.includes(target)) {
return false;
}
return true;
})
.reduce((prev, curr) => {
return [...prev, ...getEntriesByRoute(curr, rootDir)];
}, [])
Expand Down
35 changes: 7 additions & 28 deletions packages/plugin-rax-web/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import getAppEntry from './utils/getAppEntry';

const { getMpaEntries } = appHelpers;
export default (api) => {
const { onGetWebpackConfig, getValue, context, registerTask, registerCliOption, applyMethod, onHook } = api;
const { onGetWebpackConfig, getValue, context, registerTask, registerCliOption, applyMethod } = api;

const getWebpackBase = getValue(GET_RAX_APP_WEBPACK_CONFIG);
const tempDir = getValue('TEMP_PATH');
Expand Down Expand Up @@ -45,9 +45,6 @@ export default (api) => {
}
});

// Web entries
let entries = [getAppEntry(rootDir)];

onGetWebpackConfig(target, (config) => {
// eslint-disable-next-line @typescript-eslint/no-shadow
const { command } = context;
Expand All @@ -58,7 +55,8 @@ export default (api) => {
api,
staticConfig,
documentPath,
pages: webConfig.mpa ? [] : entries,
pages: webConfig.mpa ? [] : [getAppEntry(rootDir)],
target,
},
]);
if (webConfig.snapshot) {
Expand All @@ -70,10 +68,6 @@ export default (api) => {
}

if (webConfig.mpa || webConfig.pha) {
entries = getMpaEntries(api, {
target,
appJsonContent: staticConfig,
});
// support --mpa-entry to specify mpa entry
registerCliOption({
name: 'mpa-entry',
Expand All @@ -83,7 +77,10 @@ export default (api) => {
type: 'web',
framework: 'rax',
targetDir: tempDir,
entries,
entries: getMpaEntries(api, {
target,
appJsonContent: staticConfig,
}),
});
}

Expand All @@ -101,24 +98,6 @@ export default (api) => {
}
setLocalBuilder(api);
}

// Remove comment node
let webBuildDir;

onHook('before.build.run', ({ config: configs }) => {
const config = configs.find((configItem) => configItem.name === 'web');
webBuildDir = config.output.path;
});

onHook('after.build.compile', () => {
entries.forEach(({ entryName }) => {
const htmlFilePath = path.join(webBuildDir, `${entryName}.html`);
if (fs.existsSync(htmlFilePath)) {
const html = fs.readFileSync(htmlFilePath, 'utf-8');
fs.writeFileSync(htmlFilePath, html.replace(/(\<\!--__INNER_ROOT__--\>|\<\!--__BEFORE_ROOT__--\>|\<\!--__AFTER_ROOT__--\>)/g, ''));
}
});
});
};

function getAbsolutePath(filepath: string): string | undefined {
Expand Down
4 changes: 2 additions & 2 deletions packages/plugin-rax-web/src/utils/htmlStructure.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,10 @@ export function getBuiltInHtmlTpl(htmlInfo: IHtmlInfo, ssr: boolean) {
${addLinksBySource(assetLinks)}
</head>
<body ${addSpmB(spmB)}>
${ ssr ? '<!--__BEFORE_ROOT__-->' : '' }
${ssr ? '<!--__BEFORE_ROOT__-->' : ''}
<div id="root">${initialHTML}</div>
${addStaticSource(customComboScripts.length ? [genComboedScript(customComboScripts), ...customScripts] : customScripts)}
${ ssr ? '<!--__AFTER_ROOT__-->' : '' }
${ssr ? '<!--__AFTER_ROOT__-->' : ''}
${addScriptsBySource(assetScripts)}
</body>
</html>
Expand Down
4 changes: 4 additions & 0 deletions packages/plugin-ssr/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## v2.0.6

- Fix: SPA SSR `getInitialProps` is invalid

## v2.0.5

- Fix: MPA runApp file path
Expand Down
2 changes: 1 addition & 1 deletion packages/plugin-ssr/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "build-plugin-ssr",
"version": "2.0.5",
"version": "2.0.6",
"description": "",
"author": "",
"homepage": "https://github.com/alibaba/ice#readme",
Expand Down
2 changes: 1 addition & 1 deletion packages/plugin-ssr/src/ssr/EntryLoader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ function addDefineInitialPage() {
let Page;
if (enableRouter) {
const route = staticConfig.routes.find(({ path }) => path === pathname);
Page = route.component;
Page = route.component();
} else {
Page = appConfig.app && appConfig.app.renderComponent;
}
Expand Down
8 changes: 4 additions & 4 deletions packages/rax-app/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "rax-app",
"version": "3.8.6",
"version": "3.8.7",
"description": "command line interface and builtin plugin for rax app",
"author": "Rax Team",
"homepage": "https://github.com/alibaba/ice#readme",
Expand All @@ -18,14 +18,14 @@
"build-scripts": "^1.1.0",
"build-plugin-app-core": "2.1.0",
"build-plugin-ice-config": "2.0.2",
"build-plugin-rax-app": "7.0.3",
"build-plugin-rax-app": "7.0.4",
"build-plugin-rax-kraken": "2.0.0",
"build-plugin-rax-miniapp": "2.0.0",
"build-plugin-rax-pha": "2.0.0",
"build-plugin-rax-store": "2.0.0",
"build-plugin-rax-web": "2.0.3",
"build-plugin-rax-web": "2.0.4",
"build-plugin-rax-weex": "2.0.0",
"build-plugin-ssr": "2.0.5",
"build-plugin-ssr": "2.0.6",
"build-plugin-rax-router": "1.0.3",
"build-plugin-ice-logger": "2.0.0",
"build-plugin-minify-classname": "0.2.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/stylesheet-loader/src/globalCSSVariable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export default function getGlobalCSSVariable(config) {
} else {
styleValue = styles[key][name];
}
globalCSSVariable += `__globalObject.__RootCSSVariable["${ name }"] = "${ styleValue }";`;
globalCSSVariable += `__globalObject.__RootCSSVariable["${name}"] = "${styleValue}";`;
}
}
}
Expand Down
Loading

0 comments on commit 9e97708

Please sign in to comment.