Repository navigation
fix: support projects that use pnpm for their formatters - #146
Draft
yuyuyuyuyu-dev wants to merge 8 commits into
Draft
yuyuyuyuyu-dev wants to merge 8 commits into
yuyuyuyuyu-dev wants to merge 8 commits into
Conversation
npm stops with EBADDEVENGINES when the nearest package.json names pnpm in devEngines.packageManager, so both npmInstall and npx failed there. Look for the nearest package.json up to the root project. If it names pnpm in devEngines.packageManager, run workbox-cli with pnpm dlx. Otherwise keep npx. Also drop the unused npmInstall dependency and skip pnpmSetup unless node-gradle downloads Node.js. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Look past the Gradle root, stop at a node_modules folder, and follow npm workspaces, so the plugin reads the same package.json that npx reads. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Drop the pnpm path and the package.json detection. The plugin now runs `npm exec --prefix <empty dir> -- workbox-cli`, so npm does not read the project's package.json, .npmrc or node_modules. This avoids EBADDEVENGINES in pnpm projects without a second package manager. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
`--prefix` also moves where npm looks for the global npmrc, so settings such as a proxy or a private registry in it were lost. Ask npm for that file first and pass it with `--globalconfig`. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
`--prefix` also moves where npm looks for the global npmrc, so settings such as a proxy or a private registry in it were lost. Ask npm for that file first and pass it with `--globalconfig`. The previous commit has the wrong message: it only reverts the README. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Development machines rarely rely on it, so the extra logic is not worth the risk. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Projects that install formatters (for README.md, GitHub Actions files, and so on) with pnpm could not run this plugin.
Cause
pnpm initwritesdevEngines.packageManager: { "name": "pnpm" }into package.json. npm reads it and stops withEBADDEVENGINESfor bothnpm installandnpx. The plugin ran both:npmInstallbefore the build, andnpx workbox-cli generateSWafter it.Changes
npm exec --prefix <empty dir> -- workbox-cli generateSW <config>. The empty folder isbuild/composepwa/empty-npm-prefixof the module. With--prefix, npm treats that folder as the project, so it does not read the project's package.json,.npmrc, ornode_modules. The command itself still runs in the module folder..npmrcis ignored on purpose, so a project cannot change how the plugin behaves. The user's~/.npmrcstill applies, because it holds settings such as a proxy or a private registry, without which npm cannot reach the registry at all.--prefixalso moves where npm looks for the global npmrc (<global prefix>/etc/npmrc), so that file is not read. This is accepted: it is meant for machines shared by many users, and on a development machine Node.js is usually installed per user (Volta, nvm), where such settings go in~/.npmrc. Passing it back with--globalconfigwould need another npm process to find the file, which is not worth the risk.npmInstall. workbox-cli is fetched bynpm exec, so installing the project's own dependencies was never needed.Why npm only, and not pnpm for pnpm projects
An earlier version of this PR ran
pnpm dlx workbox-cliwhen package.json named pnpm. It was dropped because:npx/npm execalso reuses one cached copy of workbox-cli (~/.npm/_npx/<hash>) across all projects.--forcewas also tried instead of--prefix. It turns the error into a warning, but it disables other npm protections, and npm still looks at the project'snode_modules: an old workbox-cli installed there is used instead of the latest one, and one installed only inside another package makes the command fail with "workbox: command not found".--prefixfixes both.Checks
test-projects/web-appwith Gradle 9.8.2 and npm 12.2.2, wasm and js, with a package.json that names pnpm indevEngines.packageManager(plainnpxfails there withEBADDEVENGINES) and a fake workbox-cli in itsnode_modules: both service workers were generated with the real workbox-cli, nopackage-lock.jsonwas created, and the empty folder stayed empty..npmrcpointing to a fake registry (ignored, build passes).clean, and again with the configuration cache reused.Not fixed here
packageManagerfield (for example"pnpm@12.18.0"), the Kotlin Gradle plugin's ownkotlinNpmInstall/kotlinWasmNpmInstallfails, because the Yarn 1 it downloads reads that field. This happens without ComposePWA too.🤖 Generated with Claude Code