Skip to content

Commit

Permalink
incorporate PR comments
Browse files Browse the repository at this point in the history
  • Loading branch information
suejung-sentry committed Sep 5, 2024
1 parent ffc5596 commit c317b76
Show file tree
Hide file tree
Showing 22 changed files with 285 additions and 443 deletions.
2 changes: 1 addition & 1 deletion .changeset/eleven-deers-divide.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
"@codecov/standalone-analyzer": patch
"@codecov/standalone-analyzer": minor
---

Add support for no-bundler through new Standalone Analyzer library and CLI
2 changes: 2 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,8 @@ jobs:
ROLLUP_API_URL: ${{ secrets.CODECOV_STAGING_API_URL }}
SOLIDSTART_UPLOAD_TOKEN: ${{ secrets.CODECOV_ORG_TOKEN }}
SOLIDSTART_API_URL: ${{ secrets.CODECOV_API_URL }}
STANDALONE_UPLOAD_TOKEN: ${{ secrets.CODECOV_ORG_TOKEN }}
STANDALONE_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 Down
2 changes: 1 addition & 1 deletion examples/standalone/cli/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ For example:
pnpm standalone-analyzer ./dist --bundle-name=test-cli --upload-token=abcd --dry-run
```

generates a bundle stats report and prints to console:
Generates a bundle stats report and prints to console:

```
{"version":"2","builtAt":1725365190149,"duration":7,"bundleName":"test-cli","plugin":{"name":"@codecov/standalone-analyzer","version":"0.0.1-beta.12"},"assets":[{"name":"main.js","size":511,"gzipSize":301,"normalized":"main.js"},{"name":"main.js.map","size":732,"gzipSize":null,"normalized":"main.js.map"}],"chunks":[],"modules":[]}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
# Standalone Analyzer Library Import Example
# Standalone Analyzer Library Import (CJS) Example

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

This example runs in a CJS environment.

To run:

```
Expand Down Expand Up @@ -29,9 +31,9 @@ For example:
pnpm run start
```

generates a bundle stats report and prints to console:
Generates a bundle stats report and prints to console:

```
Dry run output: {"version":"2","builtAt":1725381817642,"duration":6,"bundleName":"my-bundle","plugin":{"name":"@codecov/standalone-analyzer","version":"0.0.1-beta.12"},"assets":[{"name":"main.js","size":511,"gzipSize":301,"normalized":"main.js"},{"name":"main.js.map","size":732,"gzipSize":null,"normalized":"main.js.map"}],"chunks":[],"modules":[]}
Report successfully generated and handled.
Report successfully generated and uploaded.
```
25 changes: 25 additions & 0 deletions examples/standalone/library-import-cjs/analyze.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
const { createAndUploadReport } = require("@codecov/standalone-analyzer");

const buildDir = "../../../examples/standalone/cli/dist";

const coreOpts = {
dryRun: true,
uploadToken: "your-upload-token",
retryCount: 3,
apiUrl: "https://api.codecov.io",
bundleName: "my-bundle", // bundle identifier in Codecov
enableBundleAnalysis: true,
debug: true,
};

const standaloneOpts = {
beforeReportUpload: async (original) => original,
};

createAndUploadReport(buildDir, coreOpts, standaloneOpts)
.then((reportAsJson) =>
console.log(`Report successfully generated and uploaded: ${reportAsJson}`),
)
.catch((error) =>
console.error("Failed to generate or upload report:", error),
);
18 changes: 18 additions & 0 deletions examples/standalone/library-import-cjs/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"name": "@codecov/example-standalone-analyzer-library",
"version": "1.0.0",
"private": true,
"main": "analyze.js",
"scripts": {
"start": "node analyze.js"
},
"devDependencies": {
"@codecov/standalone-analyzer": "workspace:^"
},
"volta": {
"extends": "../../package.json"
},
"engines": {
"node": ">=18.0.0"
}
}
39 changes: 39 additions & 0 deletions examples/standalone/library-import-esm/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# Standalone Analyzer Library Import (ESM) Example

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

This example runs in an ESM environment.

To run:

```
# build the library
cd packages/standalone-analyzer
pnpm install
pnpm run build
# create an example build to analyze
cd examples/standalone/cli
pnpm install
pnpm run build
# run the node program
cd examples/standalone/library-import
pnpm install
pnpm run start
```

This will call the imported function. Note a Codecov API server (e.g., that at `test-api`) needs to be running for any uploads (i.e., not dry-run) to succeed.

For example:

```
pnpm run start
```

Generates a bundle stats report and prints to console:

```
Dry run output: {"version":"2","builtAt":1725381817642,"duration":6,"bundleName":"my-bundle","plugin":{"name":"@codecov/standalone-analyzer","version":"0.0.1-beta.12"},"assets":[{"name":"main.js","size":511,"gzipSize":301,"normalized":"main.js"},{"name":"main.js.map","size":732,"gzipSize":null,"normalized":"main.js.map"}],"chunks":[],"modules":[]}
Report successfully generated and uploaded.
```
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { CreateAndHandleReport } from "@codecov/standalone-analyzer";
import { createAndUploadReport } from "@codecov/standalone-analyzer";

const buildDir = "../../../examples/standalone/cli/dist";

Expand All @@ -13,13 +13,13 @@ const coreOpts = {
};

const standaloneOpts = {
dryRunner: async (report) =>
console.info("Dry run output: ", report.bundleStatsToJson()),
reportOverrider: async (original) => original,
};

CreateAndHandleReport(buildDir, coreOpts, standaloneOpts)
.then(() => console.log("Report successfully generated and handled."))
createAndUploadReport(buildDir, coreOpts, standaloneOpts)
.then((reportAsJson) =>
console.log(`Report successfully generated and uploaded: ${reportAsJson}`),
)
.catch((error) =>
console.error("Failed to generate or upload report:", error),
);
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ describe("Standalone Analyzer Integration Tests", () => {
await $`cd ${standaloneAnalyzerApp} && API_URL=${API_URL} pnpm run analyze`;

expect(stdout.toString()).toContain(
"Report successfully generated and handled.",
"Report successfully generated and uploaded",
);
expect(stderr.toString()).not.toContain("Failed to generate");

Expand Down
2 changes: 1 addition & 1 deletion integration-tests/test-api/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
```
pnpm install
pnpm run run
pnpm run start
```

```
Expand Down
72 changes: 0 additions & 72 deletions integration-tests/test-api/package-lock.json

This file was deleted.

4 changes: 1 addition & 3 deletions integration-tests/test-api/package.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
{
"scripts": {
"dev": "tsx watch src/index.ts",
"start": "tsx src/index.ts",
"run": "bun src/index.ts"
"start": "bun src/index.ts"
},
"dependencies": {
"hono": "^4.3.11"
Expand Down
12 changes: 6 additions & 6 deletions integration-tests/test-apps/standalone/dotenv-vercel/analyze.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { CreateAndHandleReport } from "@codecov/standalone-analyzer";
import { createAndUploadReport } from "@codecov/standalone-analyzer";

const buildDir =
"../../../integration-tests/test-apps/standalone/dotenv-vercel/dist";
Expand All @@ -16,13 +16,13 @@ const coreOpts = {
};

const standaloneOpts = {
dryRunner: async (report) =>
console.info("Dry run output: ", report.bundleStatsToJson()),
reportOverrider: async (original) => original,
beforeReportUpload: async (original) => original,
};

CreateAndHandleReport(buildDir, coreOpts, standaloneOpts)
.then(() => console.log("Report successfully generated and handled."))
createAndUploadReport(buildDir, coreOpts, standaloneOpts)
.then((reportAsJson) =>
console.log(`Report successfully generated and uploaded: ${reportAsJson}`),
)
.catch((error) =>
console.error("Failed to generate or upload report:", error),
);
20 changes: 14 additions & 6 deletions packages/standalone-analyzer/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,11 @@ pnpm add @codecov/standalone-analyzer --save-dev

## Example

This example shows how the package can be imported as a library.

```js
// analyze.js
import { CreateAndHandleReport } from "@codecov/standalone-analyzer";
import { createAndUploadReport } from "@codecov/standalone-analyzer";

const buildDir = "path/to/build";

Expand All @@ -52,18 +54,24 @@ const coreOpts = {
};

const standaloneOpts = {
dryRunner: async (report) =>
console.info("Dry run output: ", report.bundleStatsToJson()),
reportOverrider: async (original) => original,
beforeReportUpload: async (original) => original,
};

CreateAndHandleReport(buildDir, coreOpts, standaloneOpts)
.then(() => console.log("Report successfully generated and handled."))
createAndUploadReport(buildDir, coreOpts, standaloneOpts)
.then((reportAsJson) =>
console.log(`Report successfully generated and uploaded: ${reportAsJson}`),
)
.catch((error) =>
console.error("Failed to generate or upload report:", error),
);
```

This example shows how the package can be used as a CLI.

```
npx @codecov/standalone-analyzer ./dist --bundle-name=test-cli --upload-token=abcd --dry-run
```

## More information

- [Codecov Documentation](https://docs.codecov.com/docs)
Expand Down
4 changes: 3 additions & 1 deletion packages/standalone-analyzer/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,13 @@
"generate:typedoc": "typedoc --options ./typedoc.json"
},
"dependencies": {
"@codecov/bundler-plugin-core": "workspace:^"
"@codecov/bundler-plugin-core": "workspace:^",
"yargs": "^17.7.2"
},
"devDependencies": {
"@rollup/plugin-replace": "^5.0.5",
"@types/node": "^20.11.15",
"@types/yargs": "^17.0.33",
"@vitest/coverage-v8": "^1.5.0",
"codecovProdRollupPlugin": "npm:@codecov/[email protected]",
"msw": "^2.1.5",
Expand Down
Loading

0 comments on commit c317b76

Please sign in to comment.