Skip to content

[Package] Exclude unused dependencies when building package.json files#3232

Draft
mho22 wants to merge 2 commits intotrunkfrom
exclude-unused-dependencies-when-building-package-json-files
Draft

[Package] Exclude unused dependencies when building package.json files#3232
mho22 wants to merge 2 commits intotrunkfrom
exclude-unused-dependencies-when-building-package-json-files

Conversation

@mho22
Copy link
Collaborator

@mho22 mho22 commented Feb 2, 2026

Motivation for the change, related issues

This is based on this issue

While working on #3093, I found out @php-wasm/node was installed alongside @php-wasm/web. While looking deeper into it, I found in the package-lock.json file that fs-journal had @php-wasm/node as an unused dependency, since it was only used in fs-journal test files.

Implementation details

Adding a new excludedDependencies option in build:package-json target inside project.json files.

Testing Instructions (or ideally a Blueprint)

CI

🧪 test-built-npm-packages/commonjs-and-jest/tests/php-wasm.spec.ts
🧪 test-built-npm-packages/es-modules-and-vitest/tests/php-wasm.spec.ts

@mho22 mho22 added [Type] Bug An existing feature does not function as intended [Feature] PHP.wasm dependencies Pull requests that update a dependency file labels Feb 2, 2026
@mho22 mho22 marked this pull request as draft February 2, 2026 12:38
@mho22
Copy link
Collaborator Author

mho22 commented Feb 2, 2026

@adamziel @php-wasm/fs-journal package.json file isn't listing the @php-wasm/node package anymore but it still lists this :

  "dependencies": {
    "express": "4.22.0",
    "ini": "4.1.2",
    "wasm-feature-detect": "1.8.0",
    "ws": "8.18.3",
    "yargs": "17.7.2",
    "@php-wasm/universal": "3.0.46",
    "@php-wasm/util": "3.0.46",
    "@php-wasm/logger": "3.0.46"
  },

I can reliably say wasm-feature-detect comes from @php-wasm/node-builds here. So even if I removed the @php-wasm/node dependency from the package.json file, it still adds the dependencies that are needed inside excluded dependencies.

That is expected since I only indicate which dependency should be ignored. Two solutions :

- "excludedDependencies": ["@php-wasm/node"]
+ "excludedDependencies": ["@php-wasm/node", "express", "ini", "wasm-feature-detect", "ws", "yargs"]

Or we should find another way to ignore these subdependencies.

Maybe this :

packages/nx-extensions/src/executors/package-json/executor.ts on line 139 :

- if (!packageJson.dependencies) {
        packageJson.dependencies = {};
- }

for (const dep of monorepoDependencies) {
	packageJson.dependencies[dep.name] = dep.version;
}

I expect having to clean each package.json file from their unused dependencies.

@mho22
Copy link
Collaborator Author

mho22 commented Feb 2, 2026

I may have a better suggestion here. Instead of excludedDependecies we could have filteredDependencies which list the dependencies we actually need.

For example @php-wasm/fs-journal needs :

  "dependencies": {
-    "express": "4.22.0",
-    "ini": "4.1.2",
-    "wasm-feature-detect": "1.8.0",
-    "ws": "8.18.3",
-    "yargs": "17.7.2",
    "@php-wasm/universal": "3.0.46",
    "@php-wasm/util": "3.0.46",
    "@php-wasm/logger": "3.0.46"
-    "@php-wasm/node": "3.0.46"
  },

So filteredDependencies could be:

"filteredDependencies": ["@php-wasm/universal", "@php-wasm/util", "@php-wasm/logger"]

Same with @php-wasm/node-builds/8-5 which needs :

  "dependencies": {
-  "ini": "4.1.2",
    "wasm-feature-detect": "1.8.0",
-  "ws": "8.18.3",
    "@php-wasm/universal": "3.0.46"
  },

So :

"filteredDependencies": ["@php-wasm/universal", "wasm-feature-detect"]

ini is used in @php-wasm/universal while ws from, well, I don't know yet.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

dependencies Pull requests that update a dependency file [Feature] PHP.wasm [Type] Bug An existing feature does not function as intended

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant