@front10/danger-plugins 2.0.0 → 3.0.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/dist/index.d.ts +4 -3
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +3 -8
- package/dist/plugin-bundle-size.d.ts +23 -25
- package/dist/plugin-bundle-size.d.ts.map +1 -0
- package/dist/plugin-bundle-size.js +143 -0
- package/dist/plugin-lighthouse.d.ts +2 -1
- package/dist/plugin-lighthouse.d.ts.map +1 -0
- package/dist/plugin-lighthouse.js +20 -0
- package/dist/plugin-netlify.d.ts +10 -9
- package/dist/plugin-netlify.d.ts.map +1 -0
- package/dist/plugin-netlify.js +21 -0
- package/package.json +12 -15
- package/src/index.ts +7 -3
- package/src/plugin-bundle-size.ts +8 -31
- package/src/plugin-lighthouse.ts +2 -2
- package/dist/danger-plugins.cjs.development.js +0 -1089
- package/dist/danger-plugins.cjs.development.js.map +0 -1
- package/dist/danger-plugins.cjs.production.min.js +0 -2
- package/dist/danger-plugins.cjs.production.min.js.map +0 -1
- package/dist/danger-plugins.esm.js +0 -1079
- package/dist/danger-plugins.esm.js.map +0 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
-
export * as netlify from "./plugin-netlify";
|
|
2
|
-
export { bundleSize, BundleSizeOptions, bundleSizeResults } from "./plugin-bundle-size";
|
|
3
|
-
export { lighthouse } from "./plugin-lighthouse";
|
|
1
|
+
export * as netlify from "./plugin-netlify.js";
|
|
2
|
+
export { bundleSize, BundleSizeOptions, bundleSizeResults, } from "./plugin-bundle-size.js";
|
|
3
|
+
export { lighthouse } from "./plugin-lighthouse.js";
|
|
4
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,OAAO,MAAM,qBAAqB,CAAC;AAC/C,OAAO,EACL,UAAU,EACV,iBAAiB,EACjB,iBAAiB,GAClB,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,8 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
if (process.env.NODE_ENV === 'production') {
|
|
5
|
-
module.exports = require('./danger-plugins.cjs.production.min.js')
|
|
6
|
-
} else {
|
|
7
|
-
module.exports = require('./danger-plugins.cjs.development.js')
|
|
8
|
-
}
|
|
1
|
+
export * as netlify from "./plugin-netlify.js";
|
|
2
|
+
export { bundleSize, bundleSizeResults, } from "./plugin-bundle-size.js";
|
|
3
|
+
export { lighthouse } from "./plugin-lighthouse.js";
|
|
@@ -1,25 +1,23 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
export declare function bundleSize(options: BundleSizeOptions): Promise<void>;
|
|
25
|
-
export {};
|
|
1
|
+
type CompressionFormats = "gzip" | "brotli";
|
|
2
|
+
export interface BundleSizeOptions {
|
|
3
|
+
title?: string;
|
|
4
|
+
formats?: CompressionFormats[];
|
|
5
|
+
bundlesDir: string;
|
|
6
|
+
getBundlesFn?: (bundleDir: string) => string[];
|
|
7
|
+
renameFn?: (filename: string) => string;
|
|
8
|
+
reportPath?: string;
|
|
9
|
+
baseBundleJob?: string;
|
|
10
|
+
}
|
|
11
|
+
interface BundleInfo {
|
|
12
|
+
filename: string;
|
|
13
|
+
sizes: number[];
|
|
14
|
+
}
|
|
15
|
+
interface BundleSizeResult {
|
|
16
|
+
gzip: boolean;
|
|
17
|
+
brotli: boolean;
|
|
18
|
+
bundles: BundleInfo[];
|
|
19
|
+
}
|
|
20
|
+
export declare function bundleSizeResults({ formats, bundlesDir, renameFn, getBundlesFn, reportPath, }: BundleSizeOptions): BundleSizeResult;
|
|
21
|
+
export declare function bundleSize(options: BundleSizeOptions): Promise<void>;
|
|
22
|
+
export {};
|
|
23
|
+
//# sourceMappingURL=plugin-bundle-size.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plugin-bundle-size.d.ts","sourceRoot":"","sources":["../src/plugin-bundle-size.ts"],"names":[],"mappings":"AAOA,KAAK,kBAAkB,GAAG,MAAM,GAAG,QAAQ,CAAC;AAiB5C,MAAM,WAAW,iBAAiB;IAChC,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,OAAO,CAAC,EAAE,kBAAkB,EAAE,CAAC;IAC/B,UAAU,EAAE,MAAM,CAAC;IACnB,YAAY,CAAC,EAAE,CAAC,SAAS,EAAE,MAAM,KAAK,MAAM,EAAE,CAAC;IAC/C,QAAQ,CAAC,EAAE,CAAC,QAAQ,EAAE,MAAM,KAAK,MAAM,CAAC;IACxC,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB;AAyBD,UAAU,UAAU;IAClB,QAAQ,EAAE,MAAM,CAAC;IACjB,KAAK,EAAE,MAAM,EAAE,CAAC;CACjB;AAED,UAAU,gBAAgB;IACxB,IAAI,EAAE,OAAO,CAAC;IACd,MAAM,EAAE,OAAO,CAAC;IAChB,OAAO,EAAE,UAAU,EAAE,CAAC;CACvB;AAED,wBAAgB,iBAAiB,CAAC,EAChC,OAAkB,EAClB,UAAU,EACV,QAA0B,EAC1B,YAAkC,EAClC,UAAU,GACX,EAAE,iBAAiB,GAAG,gBAAgB,CA8BtC;AAiBD,wBAAsB,UAAU,CAAC,OAAO,EAAE,iBAAiB,iBA+E1D"}
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
import fs, { existsSync, lstatSync, readdirSync, readFileSync } from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import zlib from "node:zlib";
|
|
4
|
+
/**
|
|
5
|
+
* Generates a Markdown table
|
|
6
|
+
* @param {string[]} headers
|
|
7
|
+
* @param {string[][]} body
|
|
8
|
+
*/
|
|
9
|
+
function generateMDTable(headers, body) {
|
|
10
|
+
const tableHeaders = [
|
|
11
|
+
headers.join(" | "),
|
|
12
|
+
headers.map(() => " --- ").join(" | "),
|
|
13
|
+
];
|
|
14
|
+
const tableBody = body.map((r) => r.join(" | "));
|
|
15
|
+
return `${tableHeaders.join("\n")}\n${tableBody.join("\n")}`;
|
|
16
|
+
}
|
|
17
|
+
function getWidgetsGetBundlesFn(bundlePrefix) {
|
|
18
|
+
return function defaultGetBundlesFn(bundlesDir) {
|
|
19
|
+
return readdirSync(bundlesDir)
|
|
20
|
+
.map((name) => path.join(bundlesDir, name))
|
|
21
|
+
.filter((dirName) => lstatSync(dirName).isDirectory())
|
|
22
|
+
.map((dirName) => path.join(dirName, path.basename(dirName).replace(bundlePrefix, "") + ".bundle.js"));
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
function defaultGetBundlesFn(bundlesDir) {
|
|
26
|
+
return readdirSync(bundlesDir)
|
|
27
|
+
.filter((file) => file.endsWith(".js"))
|
|
28
|
+
.map((file) => path.join(bundlesDir, file));
|
|
29
|
+
}
|
|
30
|
+
function defaultRenameFn(filePath) {
|
|
31
|
+
return path.basename(filePath).replace(".min.js", "").replace(".js", "");
|
|
32
|
+
}
|
|
33
|
+
export function bundleSizeResults({ formats = ["gzip"], bundlesDir, renameFn = defaultRenameFn, getBundlesFn = defaultGetBundlesFn, reportPath, }) {
|
|
34
|
+
const files = getBundlesFn(bundlesDir).filter(existsSync);
|
|
35
|
+
const formatFilter = new Set(formats);
|
|
36
|
+
const gzip = formatFilter.has("gzip");
|
|
37
|
+
const brotli = formatFilter.has("brotli");
|
|
38
|
+
const results = {
|
|
39
|
+
gzip,
|
|
40
|
+
brotli,
|
|
41
|
+
bundles: files.map((filePath) => {
|
|
42
|
+
const jsFile = readFileSync(filePath);
|
|
43
|
+
const fileSizes = [
|
|
44
|
+
jsFile,
|
|
45
|
+
...(gzip ? [zlib.gzipSync(jsFile)] : []),
|
|
46
|
+
...(brotli ? [zlib.brotliCompressSync(jsFile)] : []),
|
|
47
|
+
];
|
|
48
|
+
return {
|
|
49
|
+
filename: renameFn(filePath),
|
|
50
|
+
sizes: fileSizes.map((file) => file.length),
|
|
51
|
+
};
|
|
52
|
+
}),
|
|
53
|
+
};
|
|
54
|
+
if (reportPath) {
|
|
55
|
+
fs.writeFileSync(reportPath, JSON.stringify(results, null, 2));
|
|
56
|
+
}
|
|
57
|
+
return results;
|
|
58
|
+
}
|
|
59
|
+
function formatDiff(value) {
|
|
60
|
+
let sizeString = (value / 1000).toFixed(1);
|
|
61
|
+
if (sizeString === "-0.0") {
|
|
62
|
+
sizeString = "0.0";
|
|
63
|
+
}
|
|
64
|
+
const size = Number(sizeString);
|
|
65
|
+
let icon = "";
|
|
66
|
+
if (size > 0) {
|
|
67
|
+
icon = "🔺+";
|
|
68
|
+
}
|
|
69
|
+
else if (size < 0) {
|
|
70
|
+
icon = "🔻";
|
|
71
|
+
}
|
|
72
|
+
return `${icon}${sizeString}k`;
|
|
73
|
+
}
|
|
74
|
+
export async function bundleSize(options) {
|
|
75
|
+
const results = bundleSizeResults(options);
|
|
76
|
+
const { reportPath, baseBundleJob = "publish" } = options;
|
|
77
|
+
let baseResults;
|
|
78
|
+
if (reportPath) {
|
|
79
|
+
const projectId = process.env.CI_MERGE_REQUEST_PROJECT_ID;
|
|
80
|
+
const authToken = process.env.DANGER_GITLAB_API_TOKEN;
|
|
81
|
+
const targetBranch = process.env.CI_MERGE_REQUEST_TARGET_BRANCH_NAME || "main";
|
|
82
|
+
const baseBundlesUrl = `https://gitlab.com/api/v4/projects/${projectId}/jobs/artifacts/${targetBranch}/raw/${reportPath}?job=${baseBundleJob}`;
|
|
83
|
+
const headers = new Headers();
|
|
84
|
+
if (authToken) {
|
|
85
|
+
headers.set("PRIVATE-TOKEN", authToken);
|
|
86
|
+
}
|
|
87
|
+
const baseBundlesResponse = await fetch(baseBundlesUrl, {
|
|
88
|
+
headers,
|
|
89
|
+
});
|
|
90
|
+
if (baseBundlesResponse.ok) {
|
|
91
|
+
baseResults = (await baseBundlesResponse.json());
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
let baseBundles = new Map();
|
|
95
|
+
let diffHeaders = [];
|
|
96
|
+
if (baseResults) {
|
|
97
|
+
const { bundles, brotli, gzip } = baseResults;
|
|
98
|
+
if (bundles) {
|
|
99
|
+
bundles.forEach((bundle) => {
|
|
100
|
+
baseBundles.set(bundle.filename, bundle.sizes);
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
diffHeaders = [
|
|
104
|
+
"Filesize diff",
|
|
105
|
+
...(gzip ? ["Gzip diff"] : []),
|
|
106
|
+
...(brotli ? ["Brotli diff"] : []),
|
|
107
|
+
];
|
|
108
|
+
}
|
|
109
|
+
const headers = [
|
|
110
|
+
"Module",
|
|
111
|
+
"Filesize",
|
|
112
|
+
...(results.gzip ? ["Gzip size"] : []),
|
|
113
|
+
...(results.brotli ? ["Brotli size"] : []),
|
|
114
|
+
...diffHeaders,
|
|
115
|
+
];
|
|
116
|
+
const body = results.bundles.map((bundle) => {
|
|
117
|
+
let diff = [];
|
|
118
|
+
if (baseResults) {
|
|
119
|
+
const { brotli, gzip } = baseResults;
|
|
120
|
+
const baseBrotliIndex = brotli && !gzip ? 1 : 2;
|
|
121
|
+
const brotliIndex = results.brotli && !results.gzip ? 1 : 2;
|
|
122
|
+
if (baseBundles.has(bundle.filename)) {
|
|
123
|
+
const baseBundle = baseBundles.get(bundle.filename);
|
|
124
|
+
diff = [
|
|
125
|
+
bundle.sizes[0] - baseBundle[0],
|
|
126
|
+
...(gzip && results.gzip ? [bundle.sizes[1] - baseBundle[1]] : []),
|
|
127
|
+
...(brotli && results.brotli
|
|
128
|
+
? [bundle.sizes[brotliIndex] - baseBundle[baseBrotliIndex]]
|
|
129
|
+
: []),
|
|
130
|
+
];
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
return [
|
|
134
|
+
bundle.filename,
|
|
135
|
+
...bundle.sizes.map((size) => `${(size / 1000).toFixed(1)}k`),
|
|
136
|
+
...diff.map((size) => formatDiff(size)),
|
|
137
|
+
];
|
|
138
|
+
});
|
|
139
|
+
markdown([
|
|
140
|
+
"## " + (options.title ?? "Bundle size"),
|
|
141
|
+
generateMDTable(headers, body),
|
|
142
|
+
].join("\n\n"));
|
|
143
|
+
}
|
|
@@ -1 +1,2 @@
|
|
|
1
|
-
export declare function lighthouse(): Promise<void>;
|
|
1
|
+
export declare function lighthouse(): Promise<void>;
|
|
2
|
+
//# sourceMappingURL=plugin-lighthouse.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plugin-lighthouse.d.ts","sourceRoot":"","sources":["../src/plugin-lighthouse.ts"],"names":[],"mappings":"AAMA,wBAAsB,UAAU,kBAwB/B"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import * as fs from "node:fs";
|
|
2
|
+
import { promisify } from "node:util";
|
|
3
|
+
const readFile = promisify(fs.readFile);
|
|
4
|
+
export async function lighthouse() {
|
|
5
|
+
const content = await readFile(".lighthouseci/links.json");
|
|
6
|
+
const links = JSON.parse(content.toString());
|
|
7
|
+
const urlsToCheck = Object.entries(links);
|
|
8
|
+
if (urlsToCheck.length === 0) {
|
|
9
|
+
return;
|
|
10
|
+
}
|
|
11
|
+
markdown([
|
|
12
|
+
"## Lighthouse report",
|
|
13
|
+
urlsToCheck
|
|
14
|
+
.map(([pageUrl, reportUrl]) => {
|
|
15
|
+
const pageDisplay = pageUrl.replace(/http:\/\/localhost:[0-9]*\//, "");
|
|
16
|
+
return `- [${pageDisplay}](${reportUrl})`;
|
|
17
|
+
})
|
|
18
|
+
.join("\n"),
|
|
19
|
+
].join("\n\n"));
|
|
20
|
+
}
|
package/dist/plugin-netlify.d.ts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
label?: string;
|
|
3
|
-
site_name: string;
|
|
4
|
-
deploy_id: string;
|
|
5
|
-
deploy_url: string;
|
|
6
|
-
logs: string;
|
|
7
|
-
};
|
|
8
|
-
export declare function deployment(configs: Options[]): Promise<void>;
|
|
9
|
-
export {};
|
|
1
|
+
type Options = {
|
|
2
|
+
label?: string;
|
|
3
|
+
site_name: string;
|
|
4
|
+
deploy_id: string;
|
|
5
|
+
deploy_url: string;
|
|
6
|
+
logs: string;
|
|
7
|
+
};
|
|
8
|
+
export declare function deployment(configs: Options[]): Promise<void>;
|
|
9
|
+
export {};
|
|
10
|
+
//# sourceMappingURL=plugin-netlify.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plugin-netlify.d.ts","sourceRoot":"","sources":["../src/plugin-netlify.ts"],"names":[],"mappings":"AAMA,KAAK,OAAO,GAAG;IACb,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;IAClB,UAAU,EAAE,MAAM,CAAC;IACnB,IAAI,EAAE,MAAM,CAAC;CACd,CAAC;AAEF,wBAAsB,UAAU,CAAC,OAAO,EAAE,OAAO,EAAE,iBAuBlD"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export async function deployment(configs) {
|
|
2
|
+
const authToken = process.env.NETLIFY_AUTH_TOKEN;
|
|
3
|
+
if (!authToken) {
|
|
4
|
+
fail(`Couldn't get deploy information. You need to set up an authentication
|
|
5
|
+
token in your environment variables.
|
|
6
|
+
See: https://gitlab.com/help/ci/variables/README#variables`);
|
|
7
|
+
}
|
|
8
|
+
try {
|
|
9
|
+
const lastCommit = danger.git.commits[0];
|
|
10
|
+
markdown([
|
|
11
|
+
"## Deploy preview",
|
|
12
|
+
"The deploy preview is ready!",
|
|
13
|
+
`Built with commit ${lastCommit.sha}`,
|
|
14
|
+
...configs.map((result) => `${result.label}: ${result.deploy_url}`),
|
|
15
|
+
].join(`\n\n`));
|
|
16
|
+
}
|
|
17
|
+
catch (e) {
|
|
18
|
+
console.error(e);
|
|
19
|
+
fail(`Couldn't get deploy information.`);
|
|
20
|
+
}
|
|
21
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "
|
|
2
|
+
"version": "3.0.0",
|
|
3
3
|
"license": "MIT",
|
|
4
|
+
"type": "module",
|
|
4
5
|
"main": "dist/index.js",
|
|
5
6
|
"typings": "dist/index.d.ts",
|
|
6
7
|
"files": [
|
|
@@ -8,28 +9,24 @@
|
|
|
8
9
|
"src"
|
|
9
10
|
],
|
|
10
11
|
"engines": {
|
|
11
|
-
"node": ">=
|
|
12
|
+
"node": ">=22.22.0"
|
|
12
13
|
},
|
|
13
14
|
"volta": {
|
|
14
|
-
"node": "
|
|
15
|
+
"node": "22.22.0"
|
|
15
16
|
},
|
|
16
17
|
"scripts": {
|
|
17
|
-
"
|
|
18
|
-
"
|
|
19
|
-
"
|
|
20
|
-
"lint": "tsdx lint",
|
|
21
|
-
"prepublishOnly": "tsdx build"
|
|
18
|
+
"build": "tsc",
|
|
19
|
+
"test": "node --test",
|
|
20
|
+
"prepublishOnly": "npm run build"
|
|
22
21
|
},
|
|
23
22
|
"name": "@front10/danger-plugins",
|
|
24
23
|
"author": "Rainer Martínez Fraga",
|
|
25
24
|
"module": "dist/danger-plugins.esm.js",
|
|
26
25
|
"devDependencies": {
|
|
27
|
-
"
|
|
28
|
-
"
|
|
29
|
-
"
|
|
30
|
-
"
|
|
31
|
-
|
|
32
|
-
"dependencies": {
|
|
33
|
-
"undici": "^4.16.0"
|
|
26
|
+
"@tsconfig/node22": "^22.0.5",
|
|
27
|
+
"@types/node": "^22.19.11",
|
|
28
|
+
"danger": "^13.0.5",
|
|
29
|
+
"tslib": "^2.8.1",
|
|
30
|
+
"typescript": "^6.0.2"
|
|
34
31
|
}
|
|
35
32
|
}
|
package/src/index.ts
CHANGED
|
@@ -1,3 +1,7 @@
|
|
|
1
|
-
export * as netlify from "./plugin-netlify";
|
|
2
|
-
export {
|
|
3
|
-
|
|
1
|
+
export * as netlify from "./plugin-netlify.js";
|
|
2
|
+
export {
|
|
3
|
+
bundleSize,
|
|
4
|
+
BundleSizeOptions,
|
|
5
|
+
bundleSizeResults,
|
|
6
|
+
} from "./plugin-bundle-size.js";
|
|
7
|
+
export { lighthouse } from "./plugin-lighthouse.js";
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import { MarkdownString } from "danger";
|
|
2
|
-
import fs, { existsSync, lstatSync, readdirSync, readFileSync } from "fs";
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import zlib from "zlib";
|
|
2
|
+
import fs, { existsSync, lstatSync, readdirSync, readFileSync } from "node:fs";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import zlib from "node:zlib";
|
|
6
5
|
|
|
7
6
|
declare function markdown(message: MarkdownString): void;
|
|
8
7
|
|
|
@@ -23,18 +22,14 @@ function generateMDTable(headers: string[], body: string[][]): string {
|
|
|
23
22
|
return `${tableHeaders.join("\n")}\n${tableBody.join("\n")}`;
|
|
24
23
|
}
|
|
25
24
|
|
|
26
|
-
type Preset = "widgets";
|
|
27
|
-
|
|
28
25
|
export interface BundleSizeOptions {
|
|
29
26
|
title?: string;
|
|
30
27
|
formats?: CompressionFormats[];
|
|
31
28
|
bundlesDir: string;
|
|
32
29
|
getBundlesFn?: (bundleDir: string) => string[];
|
|
33
30
|
renameFn?: (filename: string) => string;
|
|
34
|
-
bundlePrefix?: string;
|
|
35
31
|
reportPath?: string;
|
|
36
32
|
baseBundleJob?: string;
|
|
37
|
-
preset?: Preset;
|
|
38
33
|
}
|
|
39
34
|
|
|
40
35
|
function getWidgetsGetBundlesFn(bundlePrefix: string) {
|
|
@@ -57,18 +52,8 @@ function defaultGetBundlesFn(bundlesDir: string) {
|
|
|
57
52
|
.map((file) => path.join(bundlesDir, file));
|
|
58
53
|
}
|
|
59
54
|
|
|
60
|
-
function
|
|
61
|
-
return
|
|
62
|
-
.split(".bundle.js")[0]
|
|
63
|
-
.replace(/--/g, "-")
|
|
64
|
-
.split("-")
|
|
65
|
-
.map((e) => e[0].toUpperCase() + e.slice(1))
|
|
66
|
-
.join(" ")
|
|
67
|
-
.replace("Mobile", "(mobile)");
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
function defaultRenameFn(filename: string) {
|
|
71
|
-
return filename.replace(".min.js", "").replace(".js", "");
|
|
55
|
+
function defaultRenameFn(filePath: string) {
|
|
56
|
+
return path.basename(filePath).replace(".min.js", "").replace(".js", "");
|
|
72
57
|
}
|
|
73
58
|
interface BundleInfo {
|
|
74
59
|
filename: string;
|
|
@@ -86,17 +71,9 @@ export function bundleSizeResults({
|
|
|
86
71
|
bundlesDir,
|
|
87
72
|
renameFn = defaultRenameFn,
|
|
88
73
|
getBundlesFn = defaultGetBundlesFn,
|
|
89
|
-
bundlePrefix = "cmp-mc-",
|
|
90
74
|
reportPath,
|
|
91
|
-
preset,
|
|
92
75
|
}: BundleSizeOptions): BundleSizeResult {
|
|
93
|
-
|
|
94
|
-
let rename = renameFn;
|
|
95
|
-
if (preset === "widgets") {
|
|
96
|
-
getBundles = getWidgetsGetBundlesFn(bundlePrefix);
|
|
97
|
-
rename = widgetsRenameFn;
|
|
98
|
-
}
|
|
99
|
-
const files = getBundles(bundlesDir).filter(existsSync);
|
|
76
|
+
const files = getBundlesFn(bundlesDir).filter(existsSync);
|
|
100
77
|
|
|
101
78
|
const formatFilter = new Set(formats);
|
|
102
79
|
const gzip = formatFilter.has("gzip");
|
|
@@ -114,7 +91,7 @@ export function bundleSizeResults({
|
|
|
114
91
|
];
|
|
115
92
|
|
|
116
93
|
return {
|
|
117
|
-
filename:
|
|
94
|
+
filename: renameFn(filePath),
|
|
118
95
|
sizes: fileSizes.map((file) => file.length),
|
|
119
96
|
};
|
|
120
97
|
}),
|
|
@@ -217,7 +194,7 @@ export async function bundleSize(options: BundleSizeOptions) {
|
|
|
217
194
|
|
|
218
195
|
markdown(
|
|
219
196
|
[
|
|
220
|
-
"## " + options.title ?? "Bundle size",
|
|
197
|
+
"## " + (options.title ?? "Bundle size"),
|
|
221
198
|
generateMDTable(headers, body),
|
|
222
199
|
].join("\n\n")
|
|
223
200
|
);
|
package/src/plugin-lighthouse.ts
CHANGED