Skip to content

Resolve tree-shaking issues with inlineConst - #87

Merged
nstepien merged 4 commits into
mainfrom
inlineConst
Sep 6, 2026
Merged

nstepien merged 4 commits into
mainfrom
inlineConst

Conversation

@nstepien

@nstepien nstepien commented Sep 5, 2026

Copy link
Copy Markdown
Owner

No description provided.

@nstepien nstepien self-assigned this Sep 5, 2026
@coderabbitai

coderabbitai Bot commented Sep 5, 2026 •

Copy link
Copy Markdown

Important

  • 🔍 Trigger review

This repository does not receive automatic reviews because it has fewer than 10 stars.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Team

Run ID: 91dbc80b-ac5f-49b1-9824-8b4b31ca7e27


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.

nstepien and others added 3 commits September 6, 2026 00:03
`optimization.inlineConst` replaces imported class name constants with their
values at the call site, which can leave the module that declared them without
a single used export. The whole module is then dropped — injected stylesheet
import included — as soon as anything declares it side-effect free, be it
`sideEffects: false` in the nearest `package.json` (as in this repo, which the
fixtures inherit) or a `treeshake.moduleSideEffects` setting, and the build
silently ships unstyled markup.

Report the injected import for what it is by returning `moduleSideEffects: true`
from `transform`, which outranks both of those, and declare the same on the
virtual stylesheet modules in `resolveId`, where the existing comment already
claimed it.

The `resolveId` branch that re-resolved source files with extractions never
fired: the hook receives import specifiers, never the absolute ids the parse
cache is keyed by. It is dropped rather than kept alongside the above.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
`moduleSideEffects` now keeps those modules in the bundle, so the stale comment
credited these imports with work they no longer do. Disabling them and running
the suite shows what they are actually still worth: no CSS goes missing, but the
dependency's stylesheet moves after the CSS that references it, because ecij
prepends its imports above the module's own.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
`optimization.inlineConst` inlines string constants into the modules using them,
which leaves the module that declared a class name with no used export. Under a
`sideEffects: false` package it is then dropped along with its prepended
stylesheet import, and the build silently ships unstyled markup.

A template literal with no substitutions is not treated as an inlinable
constant, so the binding survives tree-shaking; minification folds it back to a
plain string, leaving production output unchanged.

This replaces the `moduleSideEffects: true` marking, which only covered a direct
import. Rolldown discards a plugin's `moduleSideEffects` across a re-export hop
once inlining empties the chain — reproducible in plain rolldown with no ecij —
so a class name reached through a barrel still lost its CSS. The marking also
over-retained, making a barrel that declares its own class ship every
re-exported module's CSS. Both are covered by the new barrel test.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
@nstepien
nstepien marked this pull request as ready for review September 6, 2026 02:52
@nstepien
nstepien merged commit 1f268a7 into main Sep 6, 2026
5 checks passed
@nstepien
nstepien deleted the inlineConst branch September 6, 2026 02:52
nstepien added a commit that referenced this pull request Oct 17, 2026
main took in the first slice of this PR (#79) and solved several of its
other problems differently since August, so the merge ports the rest of
this branch onto main's design instead of keeping both:

- Values, class names included, come from the parse of each module, and
  const initializers resolve lazily (#79). Re-exports, `export *`,
  default and namespace imports, and `export default` resolve through the
  same evaluator, with ESM precedence and ambiguity.
- Cycles are handled by main's pendingLoads and isWaitingFor (#102), so
  the wait graph, the deferred same-file passes, and the import-last
  ordering are gone, along with the guard against inlining the class
  names of skipped templates, which needed the imported modules'
  transforms.
- Class names are IIFEs (#87, #98), so `moduleSideEffects: true` is gone.
- Vite's dev server keeps main's behavior (#104) and does not transform
  imported modules through transformRequest. There, the code of modules
  that no file holds comes from their `load` hooks.
- UNREADABLE_MODULE and UNPARSEABLE_MODULE are gone: a module whose code
  cannot be read exports nothing, and modules are parsed as the language
  Rolldown assigned them.
- Kept: raw TypeScript bindings, `meta.moduleType` parsing,
  prologue-safe imports, query-variant module identity, skipping
  external modules, and resolving each import once per transform.

Tests: main's suite, plus this branch's tests of the kept features, with
new cases for the paths that no fixture reached. The tests of the removed
behavior, and the cycle test that main already has, are dropped.
basic.input.ts is restored for main's inlineConst tests, and this
branch's barrel.ts is now barrel-index.ts.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
nstepien added a commit that referenced this pull request Oct 17, 2026
)

Removing the `main` field in #85 also dropped `index.js` from the
tarball, as `files` only lists `dist` and `index.d.ts`. The plugin
leaves the `ecij` import in place, so builds still resolve it. Packing
`main` and installing it in react-data-grid breaks `vp build`:

```
Error: [vite+]: Rolldown failed to resolve import "ecij" from ".../website/routes/ColumnSpanning.tsx".
```

This adds `index.js` to `files` and adds [publint](https://publint.dev/)
as `node --run lint:package` (`publint --strict`), which checks every
file referenced by `package.json` against the files `npm pack` would
publish. CI and the release workflow run it after the build, so a
missing entry point now fails CI and stops a release.

## Verification

- `npm pack --dry-run` lists `index.js` again (7 files).
- Without the `files` change, publint fails with
`pkg.exports["."].default is ./index.js but the file is not published.
Is it specified in pkg.files?`, with both npm 11 and npm 12. With it,
publint reports `All good!`.
- With the packed tarball installed in react-data-grid (`f7d4e272`), `vp
pack` and `vp build` pass, and all of its tests pass (544 passed, 3
skipped).
- Compared with ecij 0.5.0, the CSS is byte-identical and the class
names are the same. The only JS change is the IIFE class names from #87
in the unminified `lib/index.js`, which minifiers fold back into
strings.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

---------

Co-authored-by: Claude Opus 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant