Skip to content

Audit and document Vite optimizeDeps declarations#140

Open
sneridagh wants to merge 6 commits into
optimize_vite_depsfrom
vite-optimize-deps-audit-followup
Open

Audit and document Vite optimizeDeps declarations#140
sneridagh wants to merge 6 commits into
optimize_vite_depsfrom
vite-optimize-deps-audit-followup

Conversation

@sneridagh

Copy link
Copy Markdown
Member

Summary

  • expand the optimizeDeps declarations to cover the runtime imports currently used by Aurora workspace packages
  • add a repo script to audit optimizeDeps drift and document when to run it
  • align the related news entries and docs wording with the actual behavior of the change

Validation

  • node packages/scripts/check-vite-optimize-deps.js
  • git diff --check origin/optimize_vite_deps..HEAD

Stacked on top of #134.

@arybakov05 arybakov05 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I'm not very familiar with all the TypeScript AST wizardry, so I had the AI explain the script to me. Together, we noticed some small issues. Apart from that, the script seems to work fine for missing client optimizeDeps entries. What I did notice, however, is that it doesn't pick up missing entries in the ssr.optimizeDeps.

ssr: {
optimizeDeps: {
include: ['i18next-fs-backend/cjs', 'remix-i18next/server'],
include: ['i18next-fs-backend/cjs', 'isbot', 'remix-i18next/server'],

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I tried running from this feature branch locally, and it seems that Vite is still picking up the i18next-fs-backend/cjs and remix-i18next/server dependencies for the client optimizer.

Image

The fix is to explicitly exclude them in the client optimizeDeps as such:

optimizeDeps: {
      exclude: [
        'i18next-fs-backend',
        'i18next-fs-backend/cjs',
        'remix-i18next/server',
      ],
      include: [
       ...
      ]
Image

if (node.text.startsWith(prefix)) {
declared.add(node.text.slice(prefix.length));
}
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This is broad and would also catch dependencies declared in the optimizeDeps.exclude, which would falsely mark excluded dependencies as declared


if (
ts.isExportDeclaration(node) &&
!node.isTypeOnly &&

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This only checks isTypeOnly per node, but not per element. Something like export { type Foo } from 'bar' would be a false positive

- Declare typescript as an explicit devDependency of @plone/scripts
  instead of relying on it being hoisted from the repo root
- Fix incorrect @openai attribution in the audit script news fragment
- Dedupe the "OK" output line when multiple targets share a config file
- Wire pnpm check:vite-optimize-deps into the Code Analysis CI workflow
  so drift between runtime imports and optimizeDeps declarations is
  caught automatically
- Exclude i18next-fs-backend and remix-i18next/server from the client
  optimizeDeps bundle: Vite's client-side scanner was still picking
  them up even though they were only declared under
  ssr.optimizeDeps.include
- Scope check-vite-optimize-deps.js's declared-entries scan to actual
  `include` arrays instead of any string literal in the config file,
  so entries listed under `optimizeDeps.exclude` are no longer
  mistaken for satisfied declarations
- Check named re-exports per-element for `isTypeOnly` instead of only
  at the export-statement level, so `export { type Foo } from 'pkg'`
  is no longer treated as a runtime dependency
- Split expected specifiers into client vs. server-only (based on
  `*.server.*` filenames) and diff them against optimizeDeps.include
  and ssr.optimizeDeps.include separately, so drift in the SSR-only
  list is now actually caught
- Document the client-exclude gotcha in vite-optimize-deps.md
@sneridagh
sneridagh requested a review from arybakov05 July 20, 2026 17:11
@sneridagh

Copy link
Copy Markdown
Member Author

@arybakov05 I worked on this a bit more, and created a CI workflow for check the introduction of new deps. Despite the fact that I don't know much either about AST parsing (let the machine take care of it), looks good and I think it's a great addition/fix.

@pnicolli what do you think? If you both give me your blessing, I will merge #134 and this one.

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.

2 participants