Skip to content

Commit

Permalink
chore: Cleanup bundle analyzer for release (#173)
Browse files Browse the repository at this point in the history
  • Loading branch information
suejung-sentry authored Sep 11, 2024
1 parent a251183 commit 8bdad73
Show file tree
Hide file tree
Showing 30 changed files with 280 additions and 180 deletions.
2 changes: 1 addition & 1 deletion .changeset/eleven-deers-divide.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
"@codecov/bundle-analyzer": minor
---

Add support for no-bundler through new Bundle Analyzer library and CLI
Add support for setups without a standard bundler through new Bundle Analyzer library and CLI
18 changes: 12 additions & 6 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,9 @@ jobs:
matrix:
example:
[
"bundle-analyzer-cli",
"bundle-analyzer-lib-cjs",
"bundle-analyzer-lib-esm",
"next-js",
"next-js-15",
"nuxt",
Expand Down Expand Up @@ -343,6 +346,8 @@ jobs:
env:
HEAD_SHA: ${{ github.event.pull_request.head.sha }}
BASE_SHA: ${{ github.event.pull_request.base.sha }}
BUNDLE_ANALYZER_UPLOAD_TOKEN: ${{ secrets.CODECOV_ORG_TOKEN }}
BUNDLE_ANALYZER_API_URL: ${{ secrets.CODECOV_API_URL }}
NEXT_UPLOAD_TOKEN: ${{ secrets.CODECOV_ORG_TOKEN }}
NEXT_API_URL: ${{ secrets.CODECOV_API_URL }}
NUXT_UPLOAD_TOKEN: ${{ secrets.CODECOV_ORG_TOKEN }}
Expand All @@ -354,8 +359,6 @@ jobs:
ROLLUP_API_URL: ${{ secrets.CODECOV_API_URL }}
SOLIDSTART_UPLOAD_TOKEN: ${{ secrets.CODECOV_ORG_TOKEN }}
SOLIDSTART_API_URL: ${{ secrets.CODECOV_API_URL }}
BUNDLE_ANALYZER_UPLOAD_TOKEN: ${{ secrets.CODECOV_ORG_TOKEN }}
BUNDLE_ANALYZER_API_URL: ${{ secrets.CODECOV_API_URL }}
SVELTEKIT_UPLOAD_TOKEN: ${{ secrets.CODECOV_ORG_TOKEN }}
SVELTEKIT_API_URL: ${{ secrets.CODECOV_API_URL }}
VITE_UPLOAD_TOKEN: ${{ secrets.CODECOV_ORG_TOKEN }}
Expand All @@ -375,6 +378,9 @@ jobs:
matrix:
example:
[
"bundle-analyzer-cli",
"bundle-analyzer-lib-cjs",
"bundle-analyzer-lib-esm",
"next-js",
"next-js-15",
"nuxt",
Expand Down Expand Up @@ -434,6 +440,8 @@ jobs:
env:
HEAD_SHA: ${{ github.event.pull_request.head.sha }}
BASE_SHA: ${{ github.event.pull_request.base.sha }}
BUNDLE_ANALYZER_UPLOAD_TOKEN: ${{ secrets.CODECOV_ORG_TOKEN }}
BUNDLE_ANALYZER_API_URL: ${{ secrets.CODECOV_API_URL }}
NEXT_UPLOAD_TOKEN: ${{ secrets.CODECOV_ORG_TOKEN_STAGING }}
NEXT_API_URL: ${{ secrets.CODECOV_STAGING_API_URL }}
NUXT_UPLOAD_TOKEN: ${{ secrets.CODECOV_ORG_TOKEN }}
Expand All @@ -445,8 +453,6 @@ jobs:
ROLLUP_API_URL: ${{ secrets.CODECOV_STAGING_API_URL }}
SOLIDSTART_UPLOAD_TOKEN: ${{ secrets.CODECOV_ORG_TOKEN }}
SOLIDSTART_API_URL: ${{ secrets.CODECOV_API_URL }}
BUNDLE_ANALYZER_UPLOAD_TOKEN: ${{ secrets.CODECOV_ORG_TOKEN }}
BUNDLE_ANALYZER_API_URL: ${{ secrets.CODECOV_API_URL }}
SVELTEKIT_UPLOAD_TOKEN: ${{ secrets.CODECOV_ORG_TOKEN }}
SVELTEKIT_API_URL: ${{ secrets.CODECOV_API_URL }}
VITE_UPLOAD_TOKEN: ${{ secrets.CODECOV_ORG_TOKEN_STAGING }}
Expand All @@ -466,6 +472,7 @@ jobs:
matrix:
package:
[
"bundle-analyzer",
"bundler-plugin-core",
"nextjs-webpack-plugin",
"nuxt-plugin",
Expand All @@ -475,7 +482,6 @@ jobs:
"vite-plugin",
"webpack-plugin",
"solidstart-plugin",
"bundle-analyzer",
]
steps:
- name: Checkout
Expand Down Expand Up @@ -535,6 +541,7 @@ jobs:
matrix:
package:
[
"bundle-analyzer",
"bundler-plugin-core",
"nextjs-webpack-plugin",
"nuxt-plugin",
Expand All @@ -544,7 +551,6 @@ jobs:
"vite-plugin",
"webpack-plugin",
"solidstart-plugin",
"bundle-analyzer",
]
steps:
- name: Checkout
Expand Down
3 changes: 3 additions & 0 deletions examples/bundle-analyzer-cli/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Bundle Analyzer CLI Example

This directory includes an example calling the Codecov CLI for bundle analysis using the bundle-analyzer.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@
"./lib/c.js": "./src/c.js",
"./package.json": "./package.json"
},
"type": "module",
"scripts": {
"build": "rollup -c",
"analyze": "pnpm bundle-analyzer ./dist --bundle-name=test-cli --upload-token=abcd --dry-run"
"build": "rollup -c && pnpm bundle-analyzer ./dist --bundle-name=@codecov/example-bundle-analyzer-cli --upload-token=$BUNDLE_ANALYZER_UPLOAD_TOKEN"
},
"devDependencies": {
"@codecov/bundle-analyzer": "workspace:^",
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
const { createAndUploadReport } = require("@codecov/bundle-analyzer");

const buildDirs = ["../../../examples/bundle-analyzer/cli/dist"];
const buildDirs = ["../../../examples/bundle-analyzer-lib-cjs/example-dist"];

const coreOpts = {
dryRun: true,
uploadToken: "your-upload-token",
dryRun: false,
uploadToken: process.env.BUNDLE_ANALYZER_UPLOAD_TOKEN,
retryCount: 3,
apiUrl: "https://api.codecov.io",
bundleName: "@codecov/example-bundle-analyzer-cjs",
Expand All @@ -14,6 +14,8 @@ const coreOpts = {

const bundleAnalyzerOpts = {
beforeReportUpload: async (original) => original,
ignorePatterns: ["*.map"],
normalizeAssetsPattern: "[name]-[hash].js",
};

createAndUploadReport(buildDirs, coreOpts, bundleAnalyzerOpts)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
(function () {
const t = document.createElement("link").relList;
if (t && t.supports && t.supports("modulepreload")) return;
for (const e of document.querySelectorAll('link[rel="modulepreload"]')) i(e);
new MutationObserver((e) => {
for (const r of e)
if (r.type === "childList")
for (const o of r.addedNodes)
o.tagName === "LINK" && o.rel === "modulepreload" && i(o);
}).observe(document, { childList: !0, subtree: !0 });
function n(e) {
const r = {};
return (
e.integrity && (r.integrity = e.integrity),
e.referrerPolicy && (r.referrerPolicy = e.referrerPolicy),
e.crossOrigin === "use-credentials"
? (r.credentials = "include")
: e.crossOrigin === "anonymous"
? (r.credentials = "omit")
: (r.credentials = "same-origin"),
r
);
}
function i(e) {
if (e.ep) return;
e.ep = !0;
const r = n(e);
fetch(e.href, r);
}
})();
document.querySelector("#app").innerHTML = `
Hello ${{}.VITE_HELLO}.
`;
14 changes: 14 additions & 0 deletions examples/bundle-analyzer-lib-cjs/example-dist/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Vite + TS</title>
<script type="module" crossorigin src="/assets/index-1dca144e.js"></script>
</head>
<body>
<div id="app"></div>

</body>
</html>
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"private": true,
"main": "analyze.js",
"scripts": {
"start": "node analyze.js"
"build": "node analyze.js"
},
"devDependencies": {
"@codecov/bundle-analyzer": "workspace:^"
Expand Down
5 changes: 5 additions & 0 deletions examples/bundle-analyzer-lib-esm/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Bundle Analyzer Library Import (ESM) Example

This directory includes an example calling the bundle-analyzer exported library for bundle analysis.

This example runs in an ESM environment.
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { createAndUploadReport } from "@codecov/bundle-analyzer";

const buildDirs = ["../../../examples/bundle-analyzer/cli/dist"];
const buildDirs = ["../../../examples/bundle-analyzer-lib-esm/example-dist"];

const coreOpts = {
dryRun: true,
uploadToken: "your-upload-token",
dryRun: false,
uploadToken: process.env.BUNDLE_ANALYZER_UPLOAD_TOKEN,
retryCount: 3,
apiUrl: "https://api.codecov.io",
bundleName: "@codecov/example-bundle-analyzer-esm",
Expand All @@ -14,6 +14,8 @@ const coreOpts = {

const bundleAnalyzerOpts = {
beforeReportUpload: async (original) => original,
ignorePatterns: ["*.map"],
normalizeAssetsPattern: "[name]-[hash].js",
};

createAndUploadReport(buildDirs, coreOpts, bundleAnalyzerOpts)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
(function () {
const t = document.createElement("link").relList;
if (t && t.supports && t.supports("modulepreload")) return;
for (const e of document.querySelectorAll('link[rel="modulepreload"]')) i(e);
new MutationObserver((e) => {
for (const r of e)
if (r.type === "childList")
for (const o of r.addedNodes)
o.tagName === "LINK" && o.rel === "modulepreload" && i(o);
}).observe(document, { childList: !0, subtree: !0 });
function n(e) {
const r = {};
return (
e.integrity && (r.integrity = e.integrity),
e.referrerPolicy && (r.referrerPolicy = e.referrerPolicy),
e.crossOrigin === "use-credentials"
? (r.credentials = "include")
: e.crossOrigin === "anonymous"
? (r.credentials = "omit")
: (r.credentials = "same-origin"),
r
);
}
function i(e) {
if (e.ep) return;
e.ep = !0;
const r = n(e);
fetch(e.href, r);
}
})();
document.querySelector("#app").innerHTML = `
Hello ${{}.VITE_HELLO}.
`;
14 changes: 14 additions & 0 deletions examples/bundle-analyzer-lib-esm/example-dist/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Vite + TS</title>
<script type="module" crossorigin src="/assets/index-1dca144e.js"></script>
</head>
<body>
<div id="app"></div>

</body>
</html>
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"main": "analyze.js",
"type": "module",
"scripts": {
"start": "node analyze.js"
"build": "node analyze.js"
},
"devDependencies": {
"@codecov/bundle-analyzer": "workspace:^"
Expand Down
30 changes: 0 additions & 30 deletions examples/bundle-analyzer/cli/README.md

This file was deleted.

39 changes: 0 additions & 39 deletions examples/bundle-analyzer/library-import-cjs/README.md

This file was deleted.

39 changes: 0 additions & 39 deletions examples/bundle-analyzer/library-import-esm/README.md

This file was deleted.

Loading

0 comments on commit 8bdad73

Please sign in to comment.