@perfsee/plugin-utils
Advanced tools
Comparing version 1.1.1 to 1.3.0
@@ -6,2 +6,20 @@ # Change Log | ||
# [1.3.0](https://github.com/perfsee/perfsee/compare/v1.2.0...v1.3.0) (2023-02-27) | ||
### Bug Fixes | ||
- add options to specify platform by plugin options ([6fc85da](https://github.com/perfsee/perfsee/commit/6fc85da6ed791c3421fc8f48cabac388d04e7177)) | ||
- **plugin-utils:** missing commit message ([1acc033](https://github.com/perfsee/perfsee/commit/1acc0335018a62de122648a97da28b2e501b1cef)) | ||
### Features | ||
- **platform,platform-server:** show commit message ([b3ea2fd](https://github.com/perfsee/perfsee/commit/b3ea2fd65f67b8fec22369e69b07dfc0ec47d2ff)) | ||
- **plugin-utils:** support dynamic `artifactName` by bundle results ([fe4fe35](https://github.com/perfsee/perfsee/commit/fe4fe35f26e2f8d25b4377ceaf58b7adf7c40d22)) | ||
# [1.2.0](https://github.com/perfsee/perfsee/compare/v1.1.1...v1.2.0) (2022-12-19) | ||
### Features | ||
- **plugins, bundle-analyzer:** stream serialize ([3055b96](https://github.com/perfsee/perfsee/commit/3055b96efd2141ad461cb23f5ff4402162a0cfa3)) | ||
# [1.1.0](https://github.com/perfsee/perfsee/compare/v1.0.0...v1.1.0) (2022-11-04) | ||
@@ -8,0 +26,0 @@ |
@@ -16,2 +16,7 @@ import { PerfseeReportStats } from '@perfsee/bundle-analyzer'; | ||
toolkit?: string; | ||
pr?: { | ||
number: number; | ||
baseHash: string; | ||
headHash: string; | ||
}; | ||
} | ||
@@ -18,0 +23,0 @@ export declare class BuildUploadClient { |
@@ -25,3 +25,3 @@ "use strict"; | ||
const zlib_1 = require("zlib"); | ||
const msgpack_1 = require("@msgpack/msgpack"); | ||
const msgpack_stream_1 = require("@eyhn/msgpack-stream"); | ||
const chalk_1 = tslib_1.__importDefault(require("chalk")); | ||
@@ -33,27 +33,30 @@ const node_fetch_1 = tslib_1.__importDefault(require("node-fetch")); | ||
const build_env_1 = require("./build-env"); | ||
const msgpackExtensionCodec = new msgpack_stream_1.ExtensionCodec(); | ||
const filteredFields = [ | ||
'identifier', | ||
'issuerPath', | ||
'issuer', | ||
'moduleIdentifier', | ||
'parents', | ||
'siblings', | ||
'origins', | ||
'module', | ||
]; | ||
msgpackExtensionCodec.register({ | ||
type: 0, | ||
encode: (object) => { | ||
if (object instanceof Object && !(object instanceof Array)) { | ||
for (const field of filteredFields) { | ||
delete object[field]; | ||
} | ||
} | ||
return null; | ||
}, | ||
decode: () => null, | ||
}); | ||
function encodeStatsJsonStream(stats) { | ||
return (0, msgpack_stream_1.encodeStream)(stats, { extensionCodec: msgpackExtensionCodec }); | ||
} | ||
function encodeStatsJson(stats) { | ||
const extensionCodec = new msgpack_1.ExtensionCodec(); | ||
const filteredFields = [ | ||
'identifier', | ||
'issuerPath', | ||
'issuer', | ||
'moduleIdentifier', | ||
'parents', | ||
'siblings', | ||
'origins', | ||
'module', | ||
]; | ||
extensionCodec.register({ | ||
type: 0, | ||
encode: (object) => { | ||
if (object instanceof Object && !(object instanceof Array)) { | ||
for (const field of filteredFields) { | ||
delete object[field]; | ||
} | ||
} | ||
return null; | ||
}, | ||
decode: () => null, | ||
}); | ||
const encoded = (0, msgpack_1.encode)(stats, { extensionCodec }); | ||
const encoded = (0, msgpack_stream_1.encode)(stats, { extensionCodec: msgpackExtensionCodec }); | ||
return Buffer.from(encoded, encoded.byteOffset, encoded.byteLength); | ||
@@ -77,7 +80,7 @@ } | ||
// firstly write stats json down to disk in output path. | ||
const statsPath = await this.writeStats(stats); | ||
const statsPath = await this.writeStats(stats, !!this.options.useExperimentalStreamEncoder); | ||
// then pack the assets in output path | ||
const packPath = await this.pack(statsPath, stats); | ||
// then upload the pack to platform | ||
await this.uploadPack(packPath); | ||
await this.uploadPack(packPath, stats); | ||
if (!process.env.KEEP_STATS) { | ||
@@ -97,15 +100,27 @@ (0, fs_1.unlinkSync)(statsPath); | ||
*/ | ||
async writeStats(stats) { | ||
async writeStats(stats, stream) { | ||
const statsFile = (0, path_1.join)(this.outputPath, `webpack-stats-${(0, uuid_1.v4)()}.mp.gz`); | ||
return new Promise((resolve, reject) => { | ||
const source$ = new stream_1.PassThrough(); | ||
(0, stream_1.pipeline)(source$, (0, zlib_1.createGzip)(), (0, fs_1.createWriteStream)(statsFile), (err) => { | ||
if (err) { | ||
reject(err); | ||
} | ||
else { | ||
resolve(statsFile); | ||
} | ||
}); | ||
source$.end(encodeStatsJson(stats)); | ||
if (stream) { | ||
(0, stream_1.pipeline)(encodeStatsJsonStream(stats), (0, zlib_1.createGzip)(), (0, fs_1.createWriteStream)(statsFile), (err) => { | ||
if (err) { | ||
reject(err); | ||
} | ||
else { | ||
resolve(statsFile); | ||
} | ||
}); | ||
} | ||
else { | ||
const source$ = new stream_1.PassThrough(); | ||
(0, stream_1.pipeline)(source$, (0, zlib_1.createGzip)(), (0, fs_1.createWriteStream)(statsFile), (err) => { | ||
if (err) { | ||
reject(err); | ||
} | ||
else { | ||
resolve(statsFile); | ||
} | ||
}); | ||
source$.end(encodeStatsJson(stats)); | ||
} | ||
}); | ||
@@ -145,3 +160,3 @@ } | ||
} | ||
async uploadPack(packPath) { | ||
async uploadPack(packPath, stats) { | ||
const git = await (0, build_env_1.getBuildEnv)().git; | ||
@@ -152,2 +167,5 @@ if (!git?.host) { | ||
} | ||
const artifactName = typeof this.options.artifactName === 'function' | ||
? this.options.artifactName(stats) | ||
: this.options.artifactName ?? 'test'; | ||
const params = { | ||
@@ -158,3 +176,4 @@ ...git, | ||
commitMessage: git.commitMessage, | ||
artifactName: this.options.artifactName ?? 'test', | ||
pr: git.pr, | ||
artifactName, | ||
nodeVersion: process.version, | ||
@@ -174,3 +193,4 @@ appVersion: this.appVersion, | ||
.join('&'); | ||
const res = await (0, node_fetch_1.default)(`${(0, build_env_1.getBuildEnv)().platform}/api/v1/artifacts?${query}`, { | ||
const platform = this.options.platform ?? (0, build_env_1.getBuildEnv)().platform; | ||
const res = await (0, node_fetch_1.default)(`${platform}/api/v1/artifacts?${query}`, { | ||
method: 'POST', | ||
@@ -177,0 +197,0 @@ body: stream, |
@@ -41,12 +41,21 @@ "use strict"; | ||
return await (0, simple_git_1.default)() | ||
.log({ from: commitHash, n: 1 }) | ||
.then((stats) => { | ||
if (!stats.latest) { | ||
throw new Error('No commit found'); | ||
} | ||
return stats.latest.message.replace(/\n.*/g, '').substring(0, 255); | ||
.show([commitHash, '--format=%s']) | ||
.then((commitMessage) => { | ||
return commitMessage.replace(/\n.*/g, '').substring(0, 255); | ||
}); | ||
} | ||
catch { | ||
return undefined; | ||
try { | ||
// in github action, the commit maybe not in local | ||
console.info(`Fetching commit '${commitHash}' information from origin.`); | ||
await (0, simple_git_1.default)().fetch(['origin', commitHash, '--depth', '1']); | ||
return await (0, simple_git_1.default)() | ||
.show([commitHash, '--format=%s']) | ||
.then((commitMessage) => { | ||
return commitMessage.replace(/\n.*/g, '').substring(0, 255); | ||
}); | ||
} | ||
catch { | ||
return undefined; | ||
} | ||
} | ||
@@ -53,0 +62,0 @@ }; |
@@ -1,2 +0,2 @@ | ||
import { BundleResult } from '@perfsee/bundle-analyzer'; | ||
import { BundleResult, PerfseeReportStats } from '@perfsee/bundle-analyzer'; | ||
import { ServerOptions } from './viewer'; | ||
@@ -11,2 +11,6 @@ export interface CommonPluginOptions { | ||
/** | ||
* Your Perfsee platform url. | ||
*/ | ||
platform?: string; | ||
/** | ||
* Give a uniq name for the bundled artifact. | ||
@@ -23,3 +27,3 @@ * | ||
*/ | ||
artifactName?: string; | ||
artifactName?: string | ((stats: PerfseeReportStats) => string); | ||
/** | ||
@@ -74,4 +78,11 @@ * Which toolkit used. e.g. webpack/rollup/esbuild | ||
token?: string; | ||
/** | ||
* Use streaming to encode data, reducing memory usage. | ||
* | ||
* @default false | ||
* @experimental | ||
*/ | ||
useExperimentalStreamEncoder?: boolean; | ||
} | ||
export declare function getDefaultOptions(): Required<Pick<CommonPluginOptions, 'artifactName' | 'enableAudit' | 'token' | 'toolkit'>>; | ||
export declare function getDefaultOptions(): Required<Pick<CommonPluginOptions, 'artifactName' | 'enableAudit' | 'token' | 'toolkit' | 'useExperimentalStreamEncoder'>>; | ||
export declare function initOptions(userOptions: CommonPluginOptions): CommonPluginOptions; |
@@ -27,2 +27,3 @@ "use strict"; | ||
toolkit: 'webpack', | ||
useExperimentalStreamEncoder: false, | ||
}; | ||
@@ -29,0 +30,0 @@ } |
{ | ||
"name": "@perfsee/plugin-utils", | ||
"version": "1.1.1", | ||
"version": "1.3.0", | ||
"description": "pertsuite plugin utilities", | ||
@@ -23,5 +23,5 @@ "repository": "https://github.com/perfsee/perfsee", | ||
"dependencies": { | ||
"@msgpack/msgpack": "^2.7.2", | ||
"@perfsee/bundle-analyzer": "1.1.0", | ||
"@perfsee/utils": "1.1.0", | ||
"@eyhn/msgpack-stream": "^2.8.4", | ||
"@perfsee/bundle-analyzer": "1.3.0", | ||
"@perfsee/utils": "1.3.0", | ||
"chalk": "^4.1.2", | ||
@@ -34,3 +34,3 @@ "debug": "4.3.4", | ||
"query-string": "^7.1.1", | ||
"simple-git": "^3.10.0", | ||
"simple-git": "^3.15.0", | ||
"table": "^6.8.0", | ||
@@ -45,5 +45,5 @@ "tar": "^6.1.11", | ||
"@types/table": "^6.3.2", | ||
"@types/uuid": "^8.3.4" | ||
"@types/uuid": "^9.0.0" | ||
}, | ||
"gitHead": "2fa8665e2a60c20786c6811c106a427e5209a1c6" | ||
"gitHead": "10319d51ec9cdd2bdcfa4470ce770227fa26161f" | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
2004942
8400
+ Added@eyhn/msgpack-stream@^2.8.4
+ Added@eyhn/msgpack-stream@2.8.4(transitive)
+ Added@perfsee/bundle-analyzer@1.3.0(transitive)
+ Added@perfsee/utils@1.3.0(transitive)
- Removed@msgpack/msgpack@^2.7.2
- Removed@msgpack/msgpack@2.8.0(transitive)
- Removed@perfsee/bundle-analyzer@1.1.0(transitive)
- Removed@perfsee/utils@1.1.0(transitive)
Updated@perfsee/utils@1.3.0
Updatedsimple-git@^3.15.0