@next-core/build-next-bricks 1.13.0 → 1.13.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/index.d.ts +4 -2
- package/package.json +2 -2
- package/src/build.js +26 -1
- package/src/getSvgrLoaders.js +2 -2
- package/src/isDeprecatedV2Packages.js +39 -0
- package/src/scanBricks.js +7 -5
package/index.d.ts
CHANGED
|
@@ -2,7 +2,9 @@ import type { Compiler, Configuration, RuleSetRule, container } from "webpack";
|
|
|
2
2
|
|
|
3
3
|
export declare function build(config: BuildNextBricksConfig): Compiler;
|
|
4
4
|
export declare function getSvgrLoaders(options?: {
|
|
5
|
-
/** Set it to true for font
|
|
5
|
+
/** Set it to true for icon font, defaults to false. */
|
|
6
|
+
icon?: boolean | string | number;
|
|
7
|
+
/** Defaults to true when `icon` is truthy, otherwise defaults to false. */
|
|
6
8
|
convertCurrentColor?: boolean;
|
|
7
9
|
}): RuleSetRule["use"];
|
|
8
10
|
|
|
@@ -77,7 +79,7 @@ export interface BuildNextBricksConfig {
|
|
|
77
79
|
svgAsReactComponent?: boolean;
|
|
78
80
|
/** Customize rules for svg, this will take precedence over `svgAsReactComponent` */
|
|
79
81
|
svgRules?: RuleSetRule[];
|
|
80
|
-
/** By default the image assets are named `images/[hash][ext]
|
|
82
|
+
/** By default the image assets are named `images/[hash][ext]` */
|
|
81
83
|
imageAssetFilename?: string | ((pathData: any, assetInfo: any) => string);
|
|
82
84
|
plugins?: Configuration["plugins"];
|
|
83
85
|
moduleRules?: RuleSetRule[];
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@next-core/build-next-bricks",
|
|
3
|
-
"version": "1.13.
|
|
3
|
+
"version": "1.13.2",
|
|
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": "
|
|
54
|
+
"gitHead": "cc0e5b06fda9e78855dfbc23357f6a0a6728fd09"
|
|
55
55
|
}
|
package/src/build.js
CHANGED
|
@@ -241,6 +241,8 @@ async function getWebpackConfig(config) {
|
|
|
241
241
|
const outputPath = path.join(packageDir, config.outputPath ?? "dist");
|
|
242
242
|
const chunksDir = isBricks ? "chunks/" : "";
|
|
243
243
|
|
|
244
|
+
const imageAssetFilename = config.imageAssetFilename ?? "images/[hash][ext]";
|
|
245
|
+
|
|
244
246
|
return {
|
|
245
247
|
entry: config.entry || {
|
|
246
248
|
main: "./src/index",
|
|
@@ -321,7 +323,7 @@ async function getWebpackConfig(config) {
|
|
|
321
323
|
),
|
|
322
324
|
type: "asset/resource",
|
|
323
325
|
generator: {
|
|
324
|
-
filename:
|
|
326
|
+
filename: imageAssetFilename,
|
|
325
327
|
},
|
|
326
328
|
},
|
|
327
329
|
...(config.svgRules ??
|
|
@@ -329,6 +331,29 @@ async function getWebpackConfig(config) {
|
|
|
329
331
|
? [
|
|
330
332
|
{
|
|
331
333
|
test: /\.svg$/i,
|
|
334
|
+
type: "asset/resource",
|
|
335
|
+
// Match `xxx.svg?url`
|
|
336
|
+
resourceQuery: /url/,
|
|
337
|
+
generator: {
|
|
338
|
+
filename: imageAssetFilename,
|
|
339
|
+
},
|
|
340
|
+
},
|
|
341
|
+
{
|
|
342
|
+
test: /\.svg$/i,
|
|
343
|
+
// Exclude issuer of js files
|
|
344
|
+
issuer: {
|
|
345
|
+
not: /\.[jt]sx?$/,
|
|
346
|
+
},
|
|
347
|
+
type: "asset/resource",
|
|
348
|
+
generator: {
|
|
349
|
+
filename: imageAssetFilename,
|
|
350
|
+
},
|
|
351
|
+
},
|
|
352
|
+
{
|
|
353
|
+
test: /\.svg$/i,
|
|
354
|
+
issuer: /\.[jt]sx?$/,
|
|
355
|
+
// Exclude `xxx.svg?url`
|
|
356
|
+
resourceQuery: { not: /url/ },
|
|
332
357
|
use: getSvgrLoaders(),
|
|
333
358
|
},
|
|
334
359
|
]
|
package/src/getSvgrLoaders.js
CHANGED
|
@@ -10,7 +10,7 @@ export default function getSvgrLoaders(options = {}) {
|
|
|
10
10
|
loader: "@svgr/webpack",
|
|
11
11
|
options: {
|
|
12
12
|
babel: false,
|
|
13
|
-
icon:
|
|
13
|
+
icon: options.icon ?? false,
|
|
14
14
|
svgoConfig: {
|
|
15
15
|
plugins: [
|
|
16
16
|
{
|
|
@@ -21,7 +21,7 @@ export default function getSvgrLoaders(options = {}) {
|
|
|
21
21
|
removeViewBox: false,
|
|
22
22
|
|
|
23
23
|
convertColors: {
|
|
24
|
-
currentColor: options.convertCurrentColor ??
|
|
24
|
+
currentColor: options.convertCurrentColor ?? !!options.icon,
|
|
25
25
|
},
|
|
26
26
|
},
|
|
27
27
|
},
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
const V2_NEXT_CORE_PACKAGES = new Set([
|
|
3
|
+
"brick-dll",
|
|
4
|
+
"brick-kit",
|
|
5
|
+
"brick-utils",
|
|
6
|
+
"brick-types",
|
|
7
|
+
"brick-http",
|
|
8
|
+
"rollup-config-factory",
|
|
9
|
+
"webpack-config-factory",
|
|
10
|
+
"build-config-factory",
|
|
11
|
+
"jest-config-factory",
|
|
12
|
+
"custom-antd-styles",
|
|
13
|
+
"editor-bricks-helper",
|
|
14
|
+
"fontawesome-library",
|
|
15
|
+
]);
|
|
16
|
+
|
|
17
|
+
const V2_PREFIXES = new Set([
|
|
18
|
+
"@next-dll",
|
|
19
|
+
"@next-libs",
|
|
20
|
+
"@next-sdk",
|
|
21
|
+
"@dll",
|
|
22
|
+
"@libs",
|
|
23
|
+
"@sdk",
|
|
24
|
+
]);
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* @param {string} pkg
|
|
28
|
+
* @return {boolean}
|
|
29
|
+
*/
|
|
30
|
+
export default function isDeprecatedV2Packages(pkg) {
|
|
31
|
+
if (!pkg.startsWith("@")) {
|
|
32
|
+
return false;
|
|
33
|
+
}
|
|
34
|
+
const [prefix, name] = pkg.split("/");
|
|
35
|
+
if (prefix === "@next-core" || prefix === "@easyops") {
|
|
36
|
+
return V2_NEXT_CORE_PACKAGES.has(name);
|
|
37
|
+
}
|
|
38
|
+
return V2_PREFIXES.has(prefix);
|
|
39
|
+
}
|
package/src/scanBricks.js
CHANGED
|
@@ -14,6 +14,7 @@ import {
|
|
|
14
14
|
isImportSpecifier,
|
|
15
15
|
} from "@babel/types";
|
|
16
16
|
import getTypeDeclaration from "./getTypeDeclaration.js";
|
|
17
|
+
import isDeprecatedV2Packages from "./isDeprecatedV2Packages.js";
|
|
17
18
|
|
|
18
19
|
/**
|
|
19
20
|
*
|
|
@@ -91,10 +92,6 @@ export default async function scanBricks(packageDir) {
|
|
|
91
92
|
*/
|
|
92
93
|
async function scanByFile(filePath, overrideImport) {
|
|
93
94
|
if (processedFiles.has(filePath)) {
|
|
94
|
-
console.warn(
|
|
95
|
-
"[scan-bricks] warn: the file has already been scanned:",
|
|
96
|
-
filePath
|
|
97
|
-
);
|
|
98
95
|
return;
|
|
99
96
|
}
|
|
100
97
|
processedFiles.add(filePath);
|
|
@@ -534,7 +531,6 @@ export default async function scanBricks(packageDir) {
|
|
|
534
531
|
ImportDeclaration({ node: { source, importKind } }) {
|
|
535
532
|
// Match `import "..."`
|
|
536
533
|
if (
|
|
537
|
-
source.type === "StringLiteral" &&
|
|
538
534
|
// Ignore import from node modules.
|
|
539
535
|
(source.value.startsWith("./") || source.value.startsWith("../")) &&
|
|
540
536
|
// Ignore `import type {...} from "..."`
|
|
@@ -562,6 +558,12 @@ export default async function scanBricks(packageDir) {
|
|
|
562
558
|
addImportFile(importPath, "index");
|
|
563
559
|
}
|
|
564
560
|
}
|
|
561
|
+
|
|
562
|
+
if (isDeprecatedV2Packages(source.value)) {
|
|
563
|
+
throw new Error(
|
|
564
|
+
`Using deprecated v2 packages is prohibited in v3: "${source.value}"`
|
|
565
|
+
);
|
|
566
|
+
}
|
|
565
567
|
},
|
|
566
568
|
TSInterfaceDeclaration({ node }) {
|
|
567
569
|
const usedReferences = new Set();
|