Skip to content

Commit

Permalink
Merge pull request #964 from raxjs/hotfix/3.8.10
Browse files Browse the repository at this point in the history
fix: manifest.json need includes the scripts which injected by API
  • Loading branch information
SoloJiang authored Jan 14, 2022
2 parents bdff3ef + 0cd29ec commit ca159fe
Show file tree
Hide file tree
Showing 15 changed files with 89 additions and 49 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
## Changelog

## 3.8.10

- Fix: manifest.json need includes the scripts which injected by API

## 3.8.9

- Fix: compat with `window.location`
Expand Down
38 changes: 38 additions & 0 deletions __tests__/build-cases/with-rax-pha.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import * as path from 'path';
import * as fs from 'fs-extra';
import { buildFixture } from '../utils/build';

const example = 'with-rax-pha';

buildFixture(example, true);

describe('should build manifest.json: ', () => {
test('manifest.json content', async () => {
const manifestJSON = fs.readJSONSync(path.join(process.cwd(), 'examples', example, 'build/web/manifest.json'));
expect(manifestJSON).toEqual({
app_worker: { url: 'pha-worker.js' },
links: [],
metas: ['<meta name="release-info" content="version=12,app-id=123" />'],
pages: [
{
frames: [
{ name: 'home', path: '/', source: 'pages/Home/index', title: 'home', url: 'https://m.taobao.com' },
{ name: 'about', path: '/about', source: 'pages/About/index' },
],
tab_header: { height: 150, source: 'pages/Header/index' },
},
{
name: 'about-single',
path: '/about-single',
source: 'pages/About-Single/index',
url: 'https://m.taobao.com',
},
],
scripts: [
'<script src="https://g.alicdn.com/mtb/lib-promise/3.1.3/polyfillB.js" crossorigin="anonymous" ></script>',
],
tab_bar: { custom: true, list: ['home', 'about-single'], source: '/components/CustomTabBar/index' },
title: 'PHA Demo',
});
});
});
4 changes: 2 additions & 2 deletions __tests__/dev-cases/basic-mpa-store.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ describe('should start web devServer: ', () => {
});

afterAll(async () => {
await browser.close();
await devServer.close();
await browser?.close();
await devServer?.close();
});

4 changes: 2 additions & 2 deletions __tests__/dev-cases/basic-mpa-with-document.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ describe('should build kraken result: ', () => {
});

afterAll(async () => {
await browser.close();
await devServer.close();
await browser?.close();
await devServer?.close();
});

4 changes: 2 additions & 2 deletions __tests__/dev-cases/basic-spa-ssr.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,6 @@ describe('should start web devServer: ', () => {


afterAll(async () => {
await browser.close();
await devServer.close();
await browser?.close();
await devServer?.close();
});
2 changes: 1 addition & 1 deletion __tests__/dev-cases/basic-spa.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,5 +120,5 @@ describe(`should build wechat-miniprogram result: `, () => {

afterAll(async () => {
await browser?.close?.();
await devServer.close();
await devServer?.close();
});
2 changes: 1 addition & 1 deletion __tests__/dev-cases/basic-ssr-with-document.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,6 @@ describe('should start web devServer: ', () => {

afterAll(async () => {
await browser?.close?.();
await devServer.close();
await devServer?.close();
});

File renamed without changes.
3 changes: 2 additions & 1 deletion examples/with-rax-pha/build.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@
},
"inlineStyle": {
"forceEnableCSS": true
}
},
"plugins": ["./plugin"]
}
11 changes: 11 additions & 0 deletions examples/with-rax-pha/plugin.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
module.exports = ({ applyMethod }) => {
// For test cases
applyMethod('rax.injectHTML', 'meta', [`<meta name="release-info" content="version=12,app-id=123" />`]);

applyMethod('rax.insertScriptsByInfo', [
{
src: 'https://g.alicdn.com/mtb/lib-promise/3.1.3/polyfillB.js',
crossorigin: 'anonymous',
},
]);
};
30 changes: 0 additions & 30 deletions examples/with-rax-pha/src/document/index.tsx

This file was deleted.

4 changes: 4 additions & 0 deletions packages/plugin-rax-pha/CHANELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## v2.0.1

- Fix: manifest.json need includes the scripts which injected by API

## v2.0.0

- Feat: upgrade dependencies for webpack 5
Expand Down
4 changes: 2 additions & 2 deletions packages/plugin-rax-pha/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "build-plugin-rax-pha",
"version": "2.0.0",
"version": "2.0.1",
"description": "Rax PHA plugins",
"license": "BSD-3-Clause",
"main": "lib/index.js",
Expand All @@ -15,7 +15,7 @@
"webpack-sources": "^1.4.3",
"@builder/app-helpers": "^2.1.0",
"@builder/compat-webpack4": "^1.0.0",
"lodash.clonedeep": "^4.5.0"
"@builder/pack": "^0.5.0"
},
"devDependencies": {
"webpack": ">=4.0.0"
Expand Down
24 changes: 18 additions & 6 deletions packages/plugin-rax-pha/src/plugins/AppToManifestPlugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

const webpackSources = require('webpack-sources');
const webpack = require('webpack');
const cloneDeep = require('lodash.clonedeep');
const { cloneDeep, union } = require('@builder/pack/deps/lodash');
const { getMpaEntries } = require('@builder/app-helpers');
const { emitAsset, processAssets } = require('@builder/compat-webpack4');
const { transformAppConfig, setRealUrlToManifest } = require('../manifestHelpers');
Expand All @@ -22,7 +22,7 @@ module.exports = class {
apply(compiler) {
const { api, builtInLibrary = [], appWorkerPath } = this.options;

const { context, getValue } = api;
const { context, getValue, applyMethod } = api;
const { command, userConfig = {} } = context;
const { inlineStyle, web = {} } = userConfig;
const {
Expand All @@ -44,6 +44,7 @@ module.exports = class {
}, ({ compilation, callback, assets }) => {
const assetNames = Object.keys(assets);
const appConfig = getValue('staticConfig');
const { scripts, metas, links } = applyMethod('rax.getInjectedHTML');
let manifestJSON = transformAppConfig(appConfig);
const devUrls = [];

Expand All @@ -55,10 +56,21 @@ module.exports = class {
}
}

manifestJSON.scripts = [
...builtInLibrary.map((url) => `<script crossorigin="anonymous" src="${url}"></script>`),
...(manifestJSON.scripts || []),
];
manifestJSON.metas = union(
metas,
manifestJSON.metas,
) || [];

manifestJSON.links = union(
links,
manifestJSON.links,
) || [];

manifestJSON.scripts = union(
scripts,
builtInLibrary.map((url) => `<script crossorigin="anonymous" src="${url}"></script>`),
manifestJSON.scripts,
) || [];

// if has tabBar, do not generate multiple manifest.json
if (manifestJSON.tab_bar) {
Expand Down
4 changes: 2 additions & 2 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.9",
"version": "3.8.10",
"description": "command line interface and builtin plugin for rax app",
"author": "Rax Team",
"homepage": "https://github.com/alibaba/ice#readme",
Expand All @@ -21,7 +21,7 @@
"build-plugin-rax-app": "7.0.6",
"build-plugin-rax-kraken": "2.0.0",
"build-plugin-rax-miniapp": "2.0.0",
"build-plugin-rax-pha": "2.0.0",
"build-plugin-rax-pha": "2.0.1",
"build-plugin-rax-store": "2.0.0",
"build-plugin-rax-web": "2.0.6",
"build-plugin-rax-weex": "2.0.0",
Expand Down

0 comments on commit ca159fe

Please sign in to comment.