Skip to content

Commit bfff0aa

Browse files
authored
Merge 91a2446 into 0dab332
2 parents 0dab332 + 91a2446 commit bfff0aa

File tree

9 files changed

+8845
-3961
lines changed

9 files changed

+8845
-3961
lines changed

.changeset/README.md

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Changesets
2+
3+
Hello and welcome! This folder has been automatically generated by `@changesets/cli`, a build tool that works
4+
with multi-package repos, or single-package repos to help you version and publish your code. You can
5+
find the full documentation for it [in our repository](https://github.com/changesets/changesets)
6+
7+
We have a quick list of common questions to get you started engaging with this project in
8+
[our documentation](https://github.com/changesets/changesets/blob/main/docs/common-questions.md)

.changeset/config.json

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"$schema": "https://unpkg.com/@changesets/[email protected]/schema.json",
3+
"changelog": [
4+
"@changesets/changelog-github",
5+
{ "repo": "hashicorp/nextjs-bundle-analysis" }
6+
],
7+
"commit": false,
8+
"linked": [],
9+
"access": "public",
10+
"baseBranch": "main",
11+
"updateInternalDependencies": "patch",
12+
"ignore": [],
13+
"___experimentalUnsafeOptions_WILL_CHANGE_IN_PATCH": {
14+
"useCalculatedVersionForSnapshots": true,
15+
"onlyUpdatePeerDependentsWhenOutOfRange": true
16+
}
17+
}

.changeset/poor-bats-notice.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'nextjs-bundle-analysis': minor
3+
---
4+
5+
Improve monorepo support by adding the `name` from `package.json` to the generated comment. Add support for a `skipCommentIfEmpty` configuration option that will set the comment to an empty string when no pages have changed size.

.github/workflows/canary-release.yml

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
name: Canary Release
2+
3+
on:
4+
pull_request:
5+
types:
6+
- opened
7+
- synchronize
8+
- reopened
9+
- labeled
10+
11+
jobs:
12+
release-canary:
13+
uses: hashicorp/web-platform-packages/.github/workflows/canary-release.yml@8f20ba3ccb4ffe9a9bc0b14060af00929e6655f1
14+
secrets:
15+
PUBLISH_GITHUB_TOKEN: ${{ secrets.CHANGESETS_PAT }}
16+
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}

README.md

+4
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,10 @@ For example, if you build to `dist`, you should:
4343

4444
(Optional, defaults to `0`) The threshold under which pages will be considered unchanged. For example, if `minimumChangeThreshold` was set to `500` and a page's size increased by `300 B`, it will be considered unchanged.
4545

46+
### `skipCommentIfEmpty (boolean)`
47+
48+
(Optional, defaults to `false`) When set to `true`, if no pages have changed size the generated comment will be an empty string.
49+
4650
## Caveats
4751

4852
- This plugin only analyzes the direct bundle output from next.js. If you have added any other scripts via the `<script>` tag, especially third party scripts and things like analytics or other tracking scripts, these are not included in the analysis. Scripts of this nature should _probably_ be loaded in behind a consent manager and should not make an impact on your initial load, and as long as this is how you handle them it should make no difference, but it's important to be aware of this and account for the extra size added by these scripts if they are present in your app.

compare.js

+14-6
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
* SPDX-License-Identifier: MPL-2.0
55
*/
66

7-
87
const originalFilesize = require('filesize')
98
const numberToWords = require('number-to-words')
109
const fs = require('fs')
@@ -28,6 +27,8 @@ const BUDGET_PERCENT_INCREASE_RED = options.budgetPercentIncreaseRed
2827
const SHOW_DETAILS =
2928
options.showDetails === undefined ? true : options.showDetails
3029
const BUILD_OUTPUT_DIRECTORY = getBuildOutputDirectory(options)
30+
const PACKAGE_NAME = options.name
31+
const SKIP_COMMENT_IF_EMPTY = options.skipCommentIfEmpty
3132

3233
// import the current and base branch bundle stats
3334
const currentBundle = require(path.join(
@@ -42,9 +43,9 @@ const baseBundle = require(path.join(
4243
))
4344

4445
// kick it off
45-
let output = `## 📦 Next.js Bundle Analysis
46+
let output = `## 📦 Next.js Bundle Analysis for ${PACKAGE_NAME}
4647
47-
This analysis was generated by the [next.js bundle analysis action](https://github.com/hashicorp/nextjs-bundle-analysis) 🤖
48+
This analysis was generated by the [Next.js Bundle Analysis action](https://github.com/hashicorp/nextjs-bundle-analysis). 🤖
4849
4950
`
5051

@@ -185,13 +186,20 @@ ${
185186
}
186187

187188
// and finally, if there are no changes at all, we try to be clear about that
188-
if (!newPages.length && !changedPages.length && !globalBundleChanges) {
189-
output += 'This PR introduced no changes to the javascript bundle 🙌'
189+
const hasNoChanges =
190+
!newPages.length && !changedPages.length && !globalBundleChanges
191+
if (hasNoChanges) {
192+
output += 'This PR introduced no changes to the JavaScript bundle! 🙌'
190193
}
191194

192195
// we add this tag so that our action can be able to easily and consistently find the
193196
// right comment to edit as more commits are pushed.
194-
output += '<!-- __NEXTJS_BUNDLE -->'
197+
output += `<!-- __NEXTJS_BUNDLE_${PACKAGE_NAME} -->`
198+
199+
// however, if ignoreIfEmpty is true, set output to an empty string
200+
if (hasNoChanges && SKIP_COMMENT_IF_EMPTY) {
201+
output = ''
202+
}
195203

196204
// log the output, mostly for testing and debugging. this will show up in the
197205
// github actions console.

0 commit comments

Comments
 (0)