Skip to content

Commit

Permalink
feat(plugin-utils): support dynamic artifactName by bundle results
Browse files Browse the repository at this point in the history
  • Loading branch information
DomonJi committed Feb 6, 2023
1 parent 963fa24 commit fe4fe35
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
11 changes: 8 additions & 3 deletions packages/plugins/utils/src/build-upload-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ export class BuildUploadClient {
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) {
unlinkSync(statsPath)
Expand Down Expand Up @@ -194,20 +194,25 @@ export class BuildUploadClient {
})
}

private async uploadPack(packPath: string) {
private async uploadPack(packPath: string, stats: PerfseeReportStats) {
const git = await getBuildEnv().git
if (!git?.host) {
console.error(chalk.red('[perfsee] Did not find relative codebase host for current project.'))
return
}

const artifactName =
typeof this.options.artifactName === 'function'
? this.options.artifactName(stats)
: this.options.artifactName ?? 'test'

const params: BuildUploadParams = {
...git,
projectId: this.options.project!,
commitHash: git.commit,
commitMessage: git.commitMessage,
pr: git.pr,
artifactName: this.options.artifactName ?? 'test',
artifactName,
nodeVersion: process.version,
appVersion: this.appVersion,
toolkit: this.options.toolkit ?? 'webpack',
Expand Down
4 changes: 2 additions & 2 deletions packages/plugins/utils/src/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ limitations under the License.

import { merge } from 'lodash'

import { BundleResult } from '@perfsee/bundle-analyzer'
import { BundleResult, PerfseeReportStats } from '@perfsee/bundle-analyzer'

import { getBuildEnv } from './build-env'
import { ServerOptions } from './viewer'
Expand All @@ -41,7 +41,7 @@ export interface CommonPluginOptions {
*
* @default 'main'
*/
artifactName?: string
artifactName?: string | ((stats: PerfseeReportStats) => string)

/**
* Which toolkit used. e.g. webpack/rollup/esbuild
Expand Down

0 comments on commit fe4fe35

Please sign in to comment.