@next-core/build-next-bricks 1.12.0 → 1.13.0

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.
Files changed (2) hide show
  1. package/package.json +2 -2
  2. package/src/build.js +55 -1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@next-core/build-next-bricks",
3
- "version": "1.12.0",
3
+ "version": "1.13.0",
4
4
  "description": "Build next bricks",
5
5
  "homepage": "https://github.com/easyops-cn/next-core/tree/v3/packages/build-next-bricks",
6
6
  "license": "GPL-3.0",
@@ -51,5 +51,5 @@
51
51
  "devDependencies": {
52
52
  "@next-core/brick-manifest": "^0.5.0"
53
53
  },
54
- "gitHead": "fbd30ceaf3abd9c99c5dc2085a81413c68e367e0"
54
+ "gitHead": "06fca79a3a3b63a995d92729cfbed8e312cfdccd"
55
55
  }
package/src/build.js CHANGED
@@ -1,4 +1,5 @@
1
1
  import path from "node:path";
2
+ import { existsSync } from "node:fs";
2
3
  import { readFile } from "node:fs/promises";
3
4
  import { createRequire } from "node:module";
4
5
  import webpack from "webpack";
@@ -6,6 +7,7 @@ import MiniCssExtractPlugin from "mini-css-extract-plugin";
6
7
  import postcssPresetEnv from "postcss-preset-env";
7
8
  import cssnano from "cssnano";
8
9
  import cssnanoPresetLite from "cssnano-preset-lite";
10
+ import _ from "lodash";
9
11
  import EmitBricksJsonPlugin from "./EmitBricksJsonPlugin.js";
10
12
  import getCamelPackageName from "./getCamelPackageName.js";
11
13
  import getSvgrLoaders from "./getSvgrLoaders.js";
@@ -65,13 +67,48 @@ async function getWebpackConfig(config) {
65
67
 
66
68
  const packageJsonFile = await readFile(
67
69
  path.join(packageDir, "package.json"),
68
- { encoding: "utf-8" }
70
+ "utf-8"
69
71
  );
70
72
  const packageJson = JSON.parse(packageJsonFile);
71
73
  const packageName = packageJson.name.split("/").pop();
72
74
  const camelPackageName = getCamelPackageName(packageName);
73
75
  const libName = isBricks ? `bricks/${packageName}` : config.type;
74
76
 
77
+ /** @type {string[]} */
78
+ let commonBricks;
79
+ const commonBricksJsonFile = path.join(
80
+ packageDir,
81
+ "../../shared/common-bricks/common-bricks.json"
82
+ );
83
+ if (existsSync(commonBricksJsonFile)) {
84
+ const commonBricksJson = JSON.parse(
85
+ await readFile(commonBricksJsonFile, "utf-8")
86
+ );
87
+
88
+ /** @type {Set<string, string>} */
89
+ const commonBricksMap = new Map();
90
+ for (const [pkg, bricks] of Object.entries(commonBricksJson)) {
91
+ for (const brick of bricks) {
92
+ const existedPkg = commonBricksMap.get(brick);
93
+ if (existedPkg && existedPkg !== pkg) {
94
+ throw new Error(
95
+ `Conflicted common brick: "${brick}" in package "${existedPkg}" and "${pkg}"`
96
+ );
97
+ }
98
+ commonBricksMap.set(brick, pkg);
99
+ }
100
+ }
101
+
102
+ commonBricks = Object.prototype.hasOwnProperty.call(
103
+ commonBricksJson,
104
+ packageName
105
+ )
106
+ ? commonBricksJson[packageName]
107
+ : [];
108
+ } else {
109
+ commonBricks = [];
110
+ }
111
+
75
112
  const sharedSingletonPackages = [
76
113
  "history",
77
114
  "i18next",
@@ -181,6 +218,23 @@ async function getWebpackConfig(config) {
181
218
  }
182
219
  }
183
220
 
221
+ const invalidElements = _.difference(elements, commonBricks);
222
+ if (invalidElements.length > 0) {
223
+ throw new Error(
224
+ `Find common bricks in \`${packageName}\` which are not in common-bricks.json: ${invalidElements.join(
225
+ ", "
226
+ )}`
227
+ );
228
+ }
229
+ const missingElements = _.difference(commonBricks, elements);
230
+ if (missingElements.length > 0) {
231
+ throw new Error(
232
+ `Missing common bricks in \`${packageName}\`: ${missingElements.join(
233
+ ", "
234
+ )}`
235
+ );
236
+ }
237
+
184
238
  /** @type {Record<string, { import: string; name: string; }>} */
185
239
  const extraExposes = {};
186
240