What happened?
When a package imports a workspace package only through a package.json imports (#...) alias, the import resolves correctly and the imported export is treated as used, but the workspace package itself is reported as an unused dependency.
Possible cause
In try_package_imports_fallback in v3.30.0, external targets become NpmPackage, while internal targets become InternalPackageModule using the importing manifest's name. This appears to lose the target workspace package identity needed to credit the dependency.
Additional context
We import every workspace package through an imports alias ("#acme/log/*": "@acme/lib-log/*") so that application code does not depend on package names. In our monorepo this reports 99 workspace dependencies as unused. The workaround is to list each package in ignoreDependencies, which only accepts exact names.
We are also requesting glob support in ignoreDependencies in #2953 to reduce the maintenance cost of this workaround. That is a separate configuration enhancement; this issue asks for the used workspace dependency to be recognized without an ignore.
Related: #56 (support for package.json imports aliases; resolution itself works in this reproduction).
Reproduction
Create the following files in a new directory:
package.json
{ "name": "root", "private": true }
pnpm-workspace.yaml
packages: ["packages/*"]
packages/lib/package.json
{ "name": "@repro/lib", "type": "module", "exports": { "./*": "./src/*.ts" } }
packages/lib/src/hello.ts
export const hello = () => "hello";
packages/app/package.json
{
"name": "@repro/app",
"type": "module",
"private": true,
"imports": { "#lib/*": "@repro/lib/*" },
"dependencies": { "@repro/lib": "workspace:*" },
"exports": { ".": "./src/index.ts" }
}
packages/app/src/index.ts
import { hello } from "#lib/hello";
console.log(hello());
Run from the root directory:
$ pnpm install
$ fallow dead-code
● Unused dependencies (1)
@repro/lib (packages/app/package.json)
Expected behavior
@repro/lib is credited as used by @repro/app, the same as when an imports alias points to an external npm package. hello is already treated as used, so only the dependency credit is missing.
Fallow version
3.30.0
Operating system
Linux
Configuration
What happened?
When a package imports a workspace package only through a package.json
imports(#...) alias, the import resolves correctly and the imported export is treated as used, but the workspace package itself is reported as an unused dependency.Possible cause
In
try_package_imports_fallbackin v3.30.0, external targets becomeNpmPackage, while internal targets becomeInternalPackageModuleusing the importing manifest's name. This appears to lose the target workspace package identity needed to credit the dependency.Additional context
We import every workspace package through an
importsalias ("#acme/log/*": "@acme/lib-log/*") so that application code does not depend on package names. In our monorepo this reports 99 workspace dependencies as unused. The workaround is to list each package inignoreDependencies, which only accepts exact names.We are also requesting glob support in
ignoreDependenciesin #2953 to reduce the maintenance cost of this workaround. That is a separate configuration enhancement; this issue asks for the used workspace dependency to be recognized without an ignore.Related: #56 (support for package.json
importsaliases; resolution itself works in this reproduction).Reproduction
Create the following files in a new directory:
Run from the root directory:
Expected behavior
@repro/libis credited as used by@repro/app, the same as when animportsalias points to an external npm package.hellois already treated as used, so only the dependency credit is missing.Fallow version
3.30.0
Operating system
Linux
Configuration
None (default config).