Skip to content

prune event is not triggered when removing the last import of the parent module #20781

@hi-ogawa

Description

@hi-ogawa

Describe the bug

Related #20769, #20768

Even after #20768, the prune event is missed when removing the only import from the parent module since import analysis plugin bails out when es-module-lexer detects imports.length === 0 .

if (
!imports.length &&
!(this as unknown as TransformPluginContext)._addedImports
) {
importerModule.isSelfAccepting = false
debug?.(
`${timeFrom(msAtStart)} ${colors.dim(
`[no imports] ${prettifyUrl(importer, root)}`,
)}`,
)
return source
}

The reproduction below uses pkg.pr.new from #20768

Reproduction

https://stackblitz.com/edit/github-oc2husn5?file=src%2Fdep.js

Steps to reproduce

  • run pnpm run
  • open http://localhost:5173/
    • observe orange text
  • comment out import "./test.css" from src/dep.js
    • observe text is still orange
  • reload browser
    • observe text is not orange

System Info

System:
    OS: Linux 5.0 undefined
    CPU: (8) x64 Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz
    Memory: 0 Bytes / 0 Bytes
    Shell: 1.0 - /bin/jsh
  Binaries:
    Node: 20.19.1 - /usr/local/bin/node
    Yarn: 1.22.19 - /usr/local/bin/yarn
    npm: 10.8.2 - /usr/local/bin/npm
    pnpm: 8.15.6 - /usr/local/bin/pnpm
  npmPackages:
    @vitejs/plugin-react: ^5.0.0 => 5.0.2 
    vite: https://pkg.pr.new/vite@2c47acc => 7.1.5

Used Package Manager

pnpm

Logs

No response

Validations

Metadata

Metadata

Assignees

No one assigned

    Labels

    feat: hmrp2-edge-caseBug, but has workaround or limited in scope (priority)

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions