Skip to content

feat(treeshake-checker): treeshake checker package#623

Draft
ryanbas21 wants to merge 14 commits intomainfrom
treeshake-check-main
Draft

feat(treeshake-checker): treeshake checker package#623
ryanbas21 wants to merge 14 commits intomainfrom
treeshake-check-main

Conversation

@ryanbas21
Copy link
Copy Markdown
Collaborator

JIRA Ticket

N/A

Description

I don't know the company rules around packages that I write on the computer computers, so i'll ask if we want it here. It's what I demo'd on Friday that shows how to check if a package is treeshakeable, and can aid you in what is causing it to not be treeshakeable.

There's a few optional things I could add to it, but i'll leave it here for now.

@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented May 5, 2026

⚠️ No Changeset found

Latest commit: 8a8cefe

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 5, 2026

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: e8ebb260-331f-4f42-a965-6b7b72ef7d53

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch treeshake-check-main

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@ryanbas21 ryanbas21 changed the title Treeshake check main feat(treeshake-checker): treeshake checker package May 5, 2026
@nx-cloud
Copy link
Copy Markdown
Contributor

nx-cloud Bot commented May 5, 2026

View your CI Pipeline Execution ↗ for commit 8a8cefe

Command Status Duration Result
nx run-many -t build --no-agents ✅ Succeeded <1s View ↗
nx affected -t build lint test typecheck e2e-ci ✅ Succeeded 2m 33s View ↗

☁️ Nx Cloud last updated this comment at 2026-05-05 22:53:33 UTC

@@ -0,0 +1,97 @@
// tools/treeshake-check/src/lib/treeshake-check.test.ts
import { describe, expect, it, layer } from '@effect/vitest';
ryanbas21 added 12 commits May 5, 2026 14:41
…wing and error path

Replace if-guard narrowing with vitest assert() so type narrowing doubles as
a hard assertion. Add hints assertions on the clean-package test. Replace the
duplicate clean-package test with a BundleFailed error-path test backed by a
bad-syntax fixture.
Replaces the regex heuristic for top-level call detection with an acorn
AST walk so import statements and variable-assigned calls no longer
false-positive as UnannotatedCall. Regex remains as fallback for
unparseable code.
Adds resolveEntry() which reads the exports field (subpath map, flat
conditions, or bare string) before falling back to module/main.
Conditions priority: import > module > default. require-only exports
correctly return MissingEntryPoint rather than silently using a CJS path.
@ryanbas21 ryanbas21 force-pushed the treeshake-check-main branch from 3c2fdea to 99ffed1 Compare May 5, 2026 20:41
Copy link
Copy Markdown
Contributor

@nx-cloud nx-cloud Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Important

At least one additional CI pipeline execution has run since the conclusion below was written and it may no longer be applicable.

Nx Cloud is proposing a fix for your failed CI:

We add the missing dist/index.js fixture files for the enum-only and mixed packages, along with a __fixtures__/.gitignore override to allow tracking them despite the root **/dist ignore rule. Without these files, rollup silently treated the unresolvable paths as external imports, producing empty chunk.modules and incorrectly returning FullyTreeshakeable instead of HasSideEffects.

Warning

We could not verify this fix.

Suggested Fix changes
diff --git a/tools/treeshake-check/src/__fixtures__/.gitignore b/tools/treeshake-check/src/__fixtures__/.gitignore
new file mode 100644
index 0000000..afe1555
--- /dev/null
+++ b/tools/treeshake-check/src/__fixtures__/.gitignore
@@ -0,0 +1,2 @@
+!dist/
+!dist/**
diff --git a/tools/treeshake-check/src/__fixtures__/enum-only/dist/index.js b/tools/treeshake-check/src/__fixtures__/enum-only/dist/index.js
new file mode 100644
index 0000000..445195c
--- /dev/null
+++ b/tools/treeshake-check/src/__fixtures__/enum-only/dist/index.js
@@ -0,0 +1,7 @@
+var Status;
+(function (Status) {
+  Status[Status["Active"] = 0] = "Active";
+  Status[Status["Inactive"] = 1] = "Inactive";
+})(Status || (Status = {}));
+
+export { Status };
diff --git a/tools/treeshake-check/src/__fixtures__/mixed/dist/index.js b/tools/treeshake-check/src/__fixtures__/mixed/dist/index.js
new file mode 100644
index 0000000..02e230d
--- /dev/null
+++ b/tools/treeshake-check/src/__fixtures__/mixed/dist/index.js
@@ -0,0 +1,11 @@
+var Status;
+(function (Status) {
+  Status[Status["Active"] = 0] = "Active";
+})(Status || (Status = {}));
+
+function Widget() {}
+Widget.prototype.render = function () {
+  return 'widget';
+};
+
+export { Status, Widget };

Apply fix via Nx Cloud  Reject fix via Nx Cloud


Or Apply changes locally with:

npx nx-cloud apply-locally wTLF-9EdP

Apply fix locally with your editor ↗   View interactive diff ↗



🎓 Learn more about Self-Healing CI on nx.dev

The root .gitignore's **/dist rule was silently excluding the fixture
dist files from git. In CI these files didn't exist, so rollup treated
the entry as external and returned FullyTreeshakeable for enum-only and
mixed, failing their HasSideEffects assertions.

- Adds a fixtures-scoped .gitignore negation (consistent with how
  bad-syntax/dist is already tracked)
- Commits the three missing dist/index.js fixture files
- Excludes __fixtures__/**/dist from the eslint plugin scan
- Adds the __fixtures__ pattern to nx.json eslint plugin exclude list
- Migrates integration tests from `live` to `layer + it.scoped` to
  align with the rest of the test suite and fix type compatibility
@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new Bot commented May 5, 2026

Open in StackBlitz

@forgerock/davinci-client

pnpm add https://pkg.pr.new/@forgerock/davinci-client@623

@forgerock/device-client

pnpm add https://pkg.pr.new/@forgerock/device-client@623

@forgerock/journey-client

pnpm add https://pkg.pr.new/@forgerock/journey-client@623

@forgerock/oidc-client

pnpm add https://pkg.pr.new/@forgerock/oidc-client@623

@forgerock/protect

pnpm add https://pkg.pr.new/@forgerock/protect@623

@forgerock/sdk-types

pnpm add https://pkg.pr.new/@forgerock/sdk-types@623

@forgerock/sdk-utilities

pnpm add https://pkg.pr.new/@forgerock/sdk-utilities@623

@forgerock/iframe-manager

pnpm add https://pkg.pr.new/@forgerock/iframe-manager@623

@forgerock/sdk-logger

pnpm add https://pkg.pr.new/@forgerock/sdk-logger@623

@forgerock/sdk-oidc

pnpm add https://pkg.pr.new/@forgerock/sdk-oidc@623

@forgerock/sdk-request-middleware

pnpm add https://pkg.pr.new/@forgerock/sdk-request-middleware@623

@forgerock/storage

pnpm add https://pkg.pr.new/@forgerock/storage@623

commit: 8a8cefe

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 5, 2026

Deployed a932535 to https://ForgeRock.github.io/ping-javascript-sdk/pr-623/a9325357a0ed3f593f18c0e81ca90936b0652183 branch gh-pages in ForgeRock/ping-javascript-sdk

@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented May 5, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 17.61%. Comparing base (5d6747a) to head (8a8cefe).
⚠️ Report is 94 commits behind head on main.

❌ Your project status has failed because the head coverage (17.61%) is below the target coverage (40.00%). You can increase the head coverage or adjust the target coverage.

Additional details and impacted files
@@             Coverage Diff             @@
##             main     #623       +/-   ##
===========================================
- Coverage   70.90%   17.61%   -53.29%     
===========================================
  Files          53      154      +101     
  Lines        2021    24243    +22222     
  Branches      377     1159      +782     
===========================================
+ Hits         1433     4271     +2838     
- Misses        588    19972    +19384     

see 101 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 5, 2026

📦 Bundle Size Analysis

📦 Bundle Size Analysis

🚨 Significant Changes

🔻 @forgerock/device-client - 0.0 KB (-10.0 KB, -100.0%)
🔻 @forgerock/journey-client - 0.0 KB (-91.9 KB, -100.0%)

📊 Minor Changes

📈 @forgerock/device-client - 10.0 KB (+0.0 KB)
📈 @forgerock/journey-client - 91.9 KB (+0.0 KB)

➖ No Changes

@forgerock/davinci-client - 48.9 KB
@forgerock/oidc-client - 25.2 KB
@forgerock/sdk-utilities - 11.2 KB
@forgerock/sdk-types - 7.9 KB
@forgerock/protect - 144.6 KB
@forgerock/storage - 1.5 KB
@forgerock/sdk-oidc - 4.8 KB
@forgerock/sdk-request-middleware - 4.5 KB
@forgerock/sdk-logger - 1.6 KB
@forgerock/iframe-manager - 2.4 KB


14 packages analyzed • Baseline from latest main build

Legend

🆕 New package
🔺 Size increased
🔻 Size decreased
➖ No change

ℹ️ How bundle sizes are calculated
  • Current Size: Total gzipped size of all files in the package's dist directory
  • Baseline: Comparison against the latest build from the main branch
  • Files included: All build outputs except source maps and TypeScript build cache
  • Exclusions: .map, .tsbuildinfo, and .d.ts.map files

🔄 Updated automatically on each push to this PR

Fixture JS files are hand-authored test data, not build output. Moving
them from dist/index.js to index.js avoids conflicts with the root
**/dist gitignore rule, which was silently excluding them from git.

In CI the files were missing, causing rollup to treat them as external
and return FullyTreeshakeable for enum-only and mixed, failing the
HasSideEffects assertions.

Also migrates integration tests from `live` to `layer + it.scoped` to
align with the rest of the test suite.
@ryanbas21 ryanbas21 force-pushed the treeshake-check-main branch from 19b6957 to 8a8cefe Compare May 5, 2026 22:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants