Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .changeset/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Changesets

Hello and welcome! This folder has been automatically generated by `@changesets/cli`, a build tool that works
with multi-package repos, or single-package repos to help you version and publish your code. You can
find the full documentation for it [in our repository](https://github.com/changesets/changesets)

We have a quick list of common questions to get you started engaging with this project in
[our documentation](https://github.com/changesets/changesets/blob/main/docs/common-questions.md)
17 changes: 17 additions & 0 deletions .changeset/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"$schema": "https://unpkg.com/@changesets/config@2.3.0/schema.json",
"changelog": [
"@changesets/changelog-github",
{ "repo": "hashicorp/nextjs-bundle-analysis" }
],
"commit": false,
"linked": [],
"access": "public",
"baseBranch": "main",
"updateInternalDependencies": "patch",
"ignore": [],
"___experimentalUnsafeOptions_WILL_CHANGE_IN_PATCH": {
"useCalculatedVersionForSnapshots": true,
"onlyUpdatePeerDependentsWhenOutOfRange": true
}
}
5 changes: 5 additions & 0 deletions .changeset/poor-bats-notice.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'nextjs-bundle-analysis': minor
---

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.
16 changes: 16 additions & 0 deletions .github/workflows/canary-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
name: Canary Release

on:
pull_request:
types:
- opened
- synchronize
- reopened
- labeled

jobs:
release-canary:
uses: hashicorp/web-platform-packages/.github/workflows/canary-release.yml@8f20ba3ccb4ffe9a9bc0b14060af00929e6655f1
secrets:
PUBLISH_GITHUB_TOKEN: ${{ secrets.CHANGESETS_PAT }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ For example, if you build to `dist`, you should:

(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.

### `skipCommentIfEmpty (boolean)`

(Optional, defaults to `false`) When set to `true`, if no pages have changed size the generated comment will be an empty string.

## Caveats

- 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.
Expand Down
20 changes: 14 additions & 6 deletions compare.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
* SPDX-License-Identifier: MPL-2.0
*/


const originalFilesize = require('filesize')
const numberToWords = require('number-to-words')
const fs = require('fs')
Expand All @@ -28,6 +27,8 @@ const BUDGET_PERCENT_INCREASE_RED = options.budgetPercentIncreaseRed
const SHOW_DETAILS =
options.showDetails === undefined ? true : options.showDetails
const BUILD_OUTPUT_DIRECTORY = getBuildOutputDirectory(options)
const PACKAGE_NAME = options.name
const SKIP_COMMENT_IF_EMPTY = options.skipCommentIfEmpty

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

// kick it off
let output = `## 📦 Next.js Bundle Analysis
let output = `## 📦 Next.js Bundle Analysis for ${PACKAGE_NAME}

This analysis was generated by the [next.js bundle analysis action](https://github.com/hashicorp/nextjs-bundle-analysis) 🤖
This analysis was generated by the [Next.js Bundle Analysis action](https://github.com/hashicorp/nextjs-bundle-analysis). 🤖

`

Expand Down Expand Up @@ -185,13 +186,20 @@ ${
}

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

// we add this tag so that our action can be able to easily and consistently find the
// right comment to edit as more commits are pushed.
output += '<!-- __NEXTJS_BUNDLE -->'
output += `<!-- __NEXTJS_BUNDLE_${PACKAGE_NAME} -->`

// however, if ignoreIfEmpty is true, set output to an empty string
if (hasNoChanges && SKIP_COMMENT_IF_EMPTY) {
output = ''
}

// log the output, mostly for testing and debugging. this will show up in the
// github actions console.
Expand Down
Loading