@next-core/build-next-bricks 1.15.0 → 1.16.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.
package/bin/build-next-bricks.js
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
import path from "node:path";
|
|
3
3
|
import { existsSync } from "node:fs";
|
|
4
4
|
import { mkdir, rm, writeFile } from "node:fs/promises";
|
|
5
|
+
import { pathToFileURL } from "node:url";
|
|
5
6
|
import build from "../src/build.js";
|
|
6
7
|
import scanBricks from "../src/scanBricks.js";
|
|
7
8
|
import generatePkgBuild from "../src/generatePkgBuild.js";
|
|
@@ -24,7 +25,7 @@ try {
|
|
|
24
25
|
/** @type {MaybeArray<BuildNextBricksConfig>} */
|
|
25
26
|
let rawConfig = {};
|
|
26
27
|
if (existsSync(configJs)) {
|
|
27
|
-
rawConfig = (await import(configJs)).default;
|
|
28
|
+
rawConfig = (await import(pathToFileURL(configJs))).default;
|
|
28
29
|
}
|
|
29
30
|
|
|
30
31
|
/** @type {Array<BuildNextBricksConfig>} */
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { existsSync } from "node:fs";
|
|
4
|
+
import { copyFile, readdir, rm } from "node:fs/promises";
|
|
5
|
+
|
|
6
|
+
const bricksDir = path.join(process.cwd(), "bricks");
|
|
7
|
+
|
|
8
|
+
try {
|
|
9
|
+
const dirents = await readdir(bricksDir, { withFileTypes: true });
|
|
10
|
+
|
|
11
|
+
await Promise.all(
|
|
12
|
+
dirents.map(async (item) => {
|
|
13
|
+
if (!item.isDirectory()) {
|
|
14
|
+
return;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
const packageDir = path.join(bricksDir, item.name);
|
|
18
|
+
const packageJsonPath = path.join(packageDir, "package.json");
|
|
19
|
+
const packageJsonBakPath = path.join(packageDir, "package.json.bak");
|
|
20
|
+
if (!existsSync(packageJsonBakPath)) {
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
// Resume backed-up package.json.
|
|
25
|
+
await copyFile(packageJsonBakPath, packageJsonPath);
|
|
26
|
+
await rm(packageJsonBakPath);
|
|
27
|
+
})
|
|
28
|
+
);
|
|
29
|
+
} catch (e) {
|
|
30
|
+
console.error(e);
|
|
31
|
+
process.exitCode = 1;
|
|
32
|
+
}
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { copyFile, readFile, readdir, writeFile } from "node:fs/promises";
|
|
4
|
+
import { existsSync } from "node:fs";
|
|
5
|
+
import * as prettier from "prettier";
|
|
6
|
+
|
|
7
|
+
const bricksDir = path.join(process.cwd(), "bricks");
|
|
8
|
+
|
|
9
|
+
const matchBrickPackages = (key) => /^@(?:next-)?bricks\//.test(key);
|
|
10
|
+
|
|
11
|
+
try {
|
|
12
|
+
const dirents = await readdir(bricksDir, { withFileTypes: true });
|
|
13
|
+
|
|
14
|
+
await Promise.all(
|
|
15
|
+
dirents.map(async (item) => {
|
|
16
|
+
if (!item.isDirectory()) {
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const packageDir = path.join(bricksDir, item.name);
|
|
21
|
+
const packageJsonPath = path.join(packageDir, "package.json");
|
|
22
|
+
if (!existsSync(packageJsonPath)) {
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const packageJson = JSON.parse(await readFile(packageJsonPath, "utf-8"));
|
|
27
|
+
|
|
28
|
+
const dependencies = packageJson.dependencies || {};
|
|
29
|
+
const devDependencies = packageJson.devDependencies || {};
|
|
30
|
+
const peerDependencies = packageJson.peerDependencies || {};
|
|
31
|
+
|
|
32
|
+
// If error was thrown when building, thus pre-build was performed but post-build wasn't,
|
|
33
|
+
// so we handle this situation: remove deps that is copied when pre-building.
|
|
34
|
+
let changed = false;
|
|
35
|
+
for (const [dep, version] of Object.entries(peerDependencies)) {
|
|
36
|
+
if (dependencies[dep] === version) {
|
|
37
|
+
delete dependencies[dep];
|
|
38
|
+
changed = true;
|
|
39
|
+
}
|
|
40
|
+
if (devDependencies[dep] === version) {
|
|
41
|
+
delete devDependencies[dep];
|
|
42
|
+
changed = true;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
if (changed) {
|
|
46
|
+
await writeFile(
|
|
47
|
+
packageJsonPath,
|
|
48
|
+
await prettier.format(JSON.stringify(packageJson, null, 2), {
|
|
49
|
+
filepath: packageJsonPath,
|
|
50
|
+
})
|
|
51
|
+
);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
// If there were still "@next-bricks/*" in dependencies or devDependencies,
|
|
55
|
+
// throw an error. Should put them into peerDependencies.
|
|
56
|
+
if (
|
|
57
|
+
Object.keys(dependencies)
|
|
58
|
+
.concat(Object.keys(devDependencies))
|
|
59
|
+
.some(matchBrickPackages)
|
|
60
|
+
) {
|
|
61
|
+
throw new Error(
|
|
62
|
+
`Please put other "@next-bricks/*" into peerDependencies instead of dependencies or devDependencies for your brick package: ${packageJson.name}`
|
|
63
|
+
);
|
|
64
|
+
}
|
|
65
|
+
})
|
|
66
|
+
);
|
|
67
|
+
|
|
68
|
+
await Promise.all(
|
|
69
|
+
dirents.map(async (item) => {
|
|
70
|
+
if (!item.isDirectory()) {
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
const packageDir = path.join(bricksDir, item.name);
|
|
75
|
+
const packageJsonPath = path.join(packageDir, "package.json");
|
|
76
|
+
const packageJsonBakPath = path.join(packageDir, "package.json.bak");
|
|
77
|
+
if (!existsSync(packageJsonPath)) {
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
const packageJson = JSON.parse(await readFile(packageJsonPath, "utf-8"));
|
|
82
|
+
|
|
83
|
+
const peerDependencies = packageJson.peerDependencies || {};
|
|
84
|
+
const bricksPeerDependencies =
|
|
85
|
+
Object.keys(peerDependencies).filter(matchBrickPackages);
|
|
86
|
+
if (bricksPeerDependencies.length === 0) {
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
// Make a copy as backup file.
|
|
90
|
+
await copyFile(packageJsonPath, packageJsonBakPath);
|
|
91
|
+
|
|
92
|
+
// Copy "@next-bricks/*" from peerDependencies to devDependencies.
|
|
93
|
+
const devDependencies = (packageJson.devDependencies ??= {});
|
|
94
|
+
for (const dep of bricksPeerDependencies) {
|
|
95
|
+
devDependencies[dep] = peerDependencies[dep];
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
await writeFile(
|
|
99
|
+
packageJsonPath,
|
|
100
|
+
await prettier.format(JSON.stringify(packageJson, null, 2), {
|
|
101
|
+
filepath: packageJsonPath,
|
|
102
|
+
})
|
|
103
|
+
);
|
|
104
|
+
})
|
|
105
|
+
);
|
|
106
|
+
} catch (e) {
|
|
107
|
+
console.error(e);
|
|
108
|
+
process.exitCode = 1;
|
|
109
|
+
}
|
package/package.json
CHANGED
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@next-core/build-next-bricks",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.16.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",
|
|
7
7
|
"type": "module",
|
|
8
8
|
"typings": "./index.d.ts",
|
|
9
9
|
"bin": {
|
|
10
|
-
"build-next-bricks": "./bin/build-next-bricks.js"
|
|
10
|
+
"build-next-bricks": "./bin/build-next-bricks.js",
|
|
11
|
+
"pre-build-next-bricks": "./bin/pre-build-next-bricks.js",
|
|
12
|
+
"post-build-next-bricks": "./bin/post-build-next-bricks.js"
|
|
11
13
|
},
|
|
12
14
|
"files": [
|
|
13
15
|
"bin",
|
|
@@ -46,6 +48,7 @@
|
|
|
46
48
|
"postcss": "^8.4.31",
|
|
47
49
|
"postcss-loader": "^7.3.3",
|
|
48
50
|
"postcss-preset-env": "^9.3.0",
|
|
51
|
+
"prettier": "^3.0.3",
|
|
49
52
|
"style-loader": "^3.3.3",
|
|
50
53
|
"typescript": "^5.2.2",
|
|
51
54
|
"webpack": "^5.89.0"
|
|
@@ -53,5 +56,5 @@
|
|
|
53
56
|
"devDependencies": {
|
|
54
57
|
"@next-core/brick-manifest": "^0.6.0"
|
|
55
58
|
},
|
|
56
|
-
"gitHead": "
|
|
59
|
+
"gitHead": "9b12a33070872352be49c4a04a63fe5e48a5e7f8"
|
|
57
60
|
}
|