@next-core/brick-container 2.61.0 → 2.62.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@next-core/brick-container",
3
- "version": "2.61.0",
3
+ "version": "2.62.2",
4
4
  "description": "Brick Container Server",
5
5
  "homepage": "https://github.com/easyops-cn/next-core/tree/master/packages/brick-container",
6
6
  "license": "GPL-3.0",
@@ -44,7 +44,7 @@
44
44
  "@next-core/brick-dll": "^2.28.8",
45
45
  "@next-core/brick-icons": "^2.26.1",
46
46
  "@next-core/color-theme": "^0.4.0",
47
- "@next-core/custom-antd-styles": "^1.22.0",
47
+ "@next-core/custom-antd-styles": "^1.23.0",
48
48
  "@next-core/illustrations": "^0.4.6",
49
49
  "@next-core/less-plugin-css-variables": "^0.2.1",
50
50
  "@next-core/webpack-config-factory": "^2.15.2",
@@ -72,5 +72,5 @@
72
72
  "webpack-dev-server": "^4.6.0",
73
73
  "webpack-merge": "^5.8.0"
74
74
  },
75
- "gitHead": "e1a468cbc8dd5695d1fa87cfe45d68e4a43a5765"
75
+ "gitHead": "099019b8dd2764acc6b122b0d574f0f0694f14c4"
76
76
  }
@@ -1,5 +1,8 @@
1
- const modifyResponse = require("./modifyResponse");
1
+ const fs = require("fs");
2
+ const path = require("path");
2
3
  const chalk = require("chalk");
4
+ const { escapeRegExp } = require("lodash");
5
+ const modifyResponse = require("./modifyResponse");
3
6
  const {
4
7
  getSingleBrickPackage,
5
8
  getSingleStoryboard,
@@ -11,8 +14,6 @@ const {
11
14
  appendLiveReloadScript,
12
15
  tryFiles,
13
16
  } = require("./utils");
14
- const fs = require("fs");
15
- const path = require("path");
16
17
 
17
18
  module.exports = (env) => {
18
19
  const {
@@ -33,6 +34,8 @@ module.exports = (env) => {
33
34
  brickPackagesDir,
34
35
  alternativeBrickPackagesDir,
35
36
  useLegacyBootstrap,
37
+ standaloneMicroApps,
38
+ standaloneAppDir,
36
39
  } = env;
37
40
 
38
41
  const pathRewriteFactory = (seg) =>
@@ -49,19 +52,34 @@ module.exports = (env) => {
49
52
  },
50
53
  };
51
54
  if (useRemote) {
52
- proxyPaths.push("bricks", "micro-apps", "templates");
55
+ const assetRoot = standaloneMicroApps ? `${standaloneAppDir}-/` : "";
56
+ if (standaloneMicroApps) {
57
+ // 在「独立应用」模式中,静态资源路径在 `your-app/-/` 目录下。
58
+ proxyPaths.push(assetRoot);
59
+ }
60
+
61
+ const assetPaths = ["bricks", "micro-apps", "templates"];
62
+ proxyPaths.push(...assetPaths.map((p) => `${assetRoot}${p}`));
63
+
53
64
  apiProxyOptions.onProxyRes = (proxyRes, req, res) => {
54
65
  // 设定透传远端请求时,可以指定特定的 brick-packages, micro-apps, templates 使用本地文件。
55
66
  if (
56
67
  req.path === "/next/api/auth/bootstrap" ||
57
- req.path === "/next/api/auth/v2/bootstrap"
68
+ req.path === "/next/api/auth/v2/bootstrap" ||
69
+ (standaloneMicroApps &&
70
+ new RegExp(
71
+ `^${escapeRegExp(
72
+ // 匹配 `/next/your-app/-/bootstrap.[hash].json`
73
+ `/next/${standaloneAppDir}-/bootstrap.`
74
+ )}[^.]+\\.json$`
75
+ ).test(req.path))
58
76
  ) {
59
77
  modifyResponse(res, proxyRes, (raw) => {
60
78
  if (res.statusCode !== 200) {
61
79
  return raw;
62
80
  }
63
81
  const result = JSON.parse(raw);
64
- const { data } = result;
82
+ const data = standaloneMicroApps ? result : result.data;
65
83
  if (localMicroApps.length > 0 || mockedMicroApps.length > 0) {
66
84
  data.storyboards = mockedMicroApps
67
85
  .map((id) =>
@@ -306,7 +324,7 @@ module.exports = (env) => {
306
324
  secure: false,
307
325
  changeOrigin: true,
308
326
  pathRewrite: pathRewriteFactory(seg),
309
- ...(seg === "api"
327
+ ...(seg === "api" || seg.endsWith("/-")
310
328
  ? apiProxyOptions
311
329
  : seg === ""
312
330
  ? rootProxyOptions
@@ -32,13 +32,17 @@ module.exports = (env, app) => {
32
32
  } = env;
33
33
  let username;
34
34
 
35
+ const publicRoot = standaloneMicroApps
36
+ ? `${baseHref}${standaloneAppDir}-/`
37
+ : baseHref;
38
+
35
39
  // 开发时默认拦截 bootstrap 请求。
36
40
  // 如果设定 `REMOTE=true`,则透传远端请求。
37
41
  if (useRemote) {
38
42
  // 设定透传远端请求时,可以指定特定的 brick packages, micro apps, template packages 使用本地文件。
39
43
  localEditorPackages.forEach((pkgId) => {
40
44
  // 直接返回本地构件库编辑器相关文件。
41
- app.get(`${baseHref}bricks/${pkgId}/dist/editors/*`, (req, res) => {
45
+ app.get(`${publicRoot}bricks/${pkgId}/dist/editors/*`, (req, res) => {
42
46
  tryServeFiles(
43
47
  [
44
48
  path.join(brickPackagesDir, pkgId, "dist-editors", req.params[0]),
@@ -67,7 +71,7 @@ module.exports = (env, app) => {
67
71
  app.get(
68
72
  new RegExp(
69
73
  `^${escapeRegExp(
70
- `${baseHref}bricks/${pkgId}/`
74
+ `${publicRoot}bricks/${pkgId}/`
71
75
  )}(?!dist\\/editors\\/)(.+)`
72
76
  ),
73
77
  (req, res) => {
@@ -83,50 +87,50 @@ module.exports = (env, app) => {
83
87
  );
84
88
  });
85
89
 
86
- localMicroApps.forEach((appId) => {
87
- // 直接返回本地小产品相关文件。
88
- app.get(`${baseHref}micro-apps/${appId}/*`, (req, res) => {
89
- const filePath = path.join(microAppsDir, appId, req.params[0]);
90
- tryServeFiles(filePath, req, res);
90
+ standaloneMicroApps ||
91
+ localMicroApps.forEach((appId) => {
92
+ // 直接返回本地小产品相关文件。
93
+ app.get(`${baseHref}micro-apps/${appId}/*`, (req, res) => {
94
+ const filePath = path.join(microAppsDir, appId, req.params[0]);
95
+ tryServeFiles(filePath, req, res);
96
+ });
91
97
  });
92
- });
93
98
  localTemplates.forEach((pkgId) => {
94
99
  // 直接返回本地模板相关文件。
95
- app.get(`${baseHref}templates/${pkgId}/*`, (req, res) => {
100
+ app.get(`${publicRoot}templates/${pkgId}/*`, (req, res) => {
96
101
  const filePath = path.join(templatePackagesDir, pkgId, req.params[0]);
97
102
  tryServeFiles(filePath, req, res);
98
103
  });
99
104
  });
100
- mockedMicroApps.forEach((appId) => {
101
- // 直接返回本地小产品相关文件。
102
- app.get(`${baseHref}micro-apps/${appId}/*`, (req, res) => {
103
- const filePath = path.join(mockedMicroAppsDir, appId, req.params[0]);
104
- tryServeFiles(filePath, req, res);
105
- });
106
- app.get(`${baseHref}api/auth(/v2)?/bootstrap/${appId}`, (req, res) => {
107
- res.json({
108
- code: 0,
109
- data: getSingleStoryboard(env, appId, true),
105
+ standaloneMicroApps ||
106
+ mockedMicroApps.forEach((appId) => {
107
+ // 直接返回本地小产品相关文件。
108
+ app.get(`${baseHref}micro-apps/${appId}/*`, (req, res) => {
109
+ const filePath = path.join(mockedMicroAppsDir, appId, req.params[0]);
110
+ tryServeFiles(filePath, req, res);
111
+ });
112
+ app.get(`${baseHref}api/auth(/v2)?/bootstrap/${appId}`, (req, res) => {
113
+ res.json({
114
+ code: 0,
115
+ data: getSingleStoryboard(env, appId, true),
116
+ });
110
117
  });
111
118
  });
112
- });
113
119
  // API to fulfil the active storyboard.
114
- localMicroApps.concat(mockedMicroApps).forEach((appId) => {
115
- app.get(`${baseHref}api/auth(/v2)?/bootstrap/${appId}`, (req, res) => {
116
- res.json({
117
- code: 0,
118
- data: getSingleStoryboard(
119
- env,
120
- appId,
121
- mockedMicroApps.includes(appId)
122
- ),
120
+ standaloneMicroApps ||
121
+ localMicroApps.concat(mockedMicroApps).forEach((appId) => {
122
+ app.get(`${baseHref}api/auth(/v2)?/bootstrap/${appId}`, (req, res) => {
123
+ res.json({
124
+ code: 0,
125
+ data: getSingleStoryboard(
126
+ env,
127
+ appId,
128
+ mockedMicroApps.includes(appId)
129
+ ),
130
+ });
123
131
  });
124
132
  });
125
- });
126
133
  } else {
127
- const publicRoot = standaloneMicroApps
128
- ? `${baseHref}${standaloneAppDir}-/`
129
- : baseHref;
130
134
  if (standaloneMicroApps) {
131
135
  app.get(`${publicRoot}bootstrap.hash.json`, (req, res) => {
132
136
  res.json({
package/serve/utils.js CHANGED
@@ -198,7 +198,15 @@ function getSingleTemplatePackage(env, templatePackageName) {
198
198
  }
199
199
  }
200
200
 
201
- function mergeSettings(defaultSettings, userSettings) {
201
+ function mergeSettings(
202
+ defaultSettings = {
203
+ featureFlags: {},
204
+ homepage: "/",
205
+ brand: {},
206
+ misc: {},
207
+ },
208
+ userSettings
209
+ ) {
202
210
  const { featureFlags, homepage, brand, misc } = userSettings;
203
211
  if (!defaultSettings.misc) {
204
212
  defaultSettings.misc = {};