Skip to content

Install Wrangler and project dependencies with the site's package manager - #54

Open
SylvainDruaux wants to merge 5 commits into
flowtricks:mainfrom
SylvainDruaux:publish-dependency-install
Open

SylvainDruaux wants to merge 5 commits into
flowtricks:mainfrom
SylvainDruaux:publish-dependency-install

Conversation

@SylvainDruaux

Copy link
Copy Markdown
Contributor

Cloudflare sign-in installed a missing Wrangler with npm regardless of the
site, so pnpm, Yarn and Bun sites ended up with a second lockfile, and
cancelling could leave node_modules half installed. On pnpm 11 and later,
both the Wrangler install and the dependency install on project open also
failed, because pnpm exits with an error when it blocks a build script.

Commits:

  • Share one exhaustive sign-in pending check between the service and the
    dialog, so a new sign-in state fails to compile until classified.
  • Read the package manager from package.json's packageManager field first,
    then the lockfile, then npm.
  • Install Wrangler with the site's package manager. Cancelling skips sign-in
    but lets the install finish. The Cloudflare dialog stays on one screen from
    installation to browser sign-in or Try again, and says when the site's
    dependencies changed. A Wrangler removed while Stacki runs is detected as
    missing again instead of failing to start.
  • Remove project:hasNodeModules and project:install, which nothing called
    since dependency installs moved to the main process.
  • Keep pnpm's build scripts blocked without failing the install
    (--config.strict-dep-builds=false), for both installs.

Tested: full gate (377/377) on top of 0.1.73, plus manual checks on macOS
with a pnpm site (Wrangler install, cancel, reinstall after removal, project
open without node_modules) and new Lumos and empty Astro projects.

Known limitation: on Windows, a native Bun install (bun.exe) is not found by
the tool lookup, so Bun sites get a clear "Could not run Bun" error instead
of installing Wrangler.

The account service and the sign-in dialog each kept their own list of
pending states, so a new state could silently be treated as finished.
Both now use accountSignInPending from the shared contract, a switch
with a never check, so a new state fails to compile until classified.
A project can name its package manager in package.json's packageManager
field (e.g. "pnpm@9.12.0"), which is more reliable than guessing from a
lockfile. Detection now checks that field first, then the lockfile, then
falls back to npm. An unknown or unreadable field falls back the same way.
Cloudflare sign-in installed a missing Wrangler always with npm, so
sites using pnpm, Yarn or Bun ended up with a second lockfile, and
cancelling could leave node_modules half installed.

It now installs with the site's package manager, and cancelling skips
sign-in but lets the install finish. The dialog stays on one screen
from installation to browser sign-in or Try again, and says when the
site's dependencies changed. A Wrangler removed while Stacki runs is
detected as missing again instead of failing to start.
Opening and creating projects install dependencies in the main process,
so nothing called project:hasNodeModules or project:install any more.
Removing them with their preload methods and renderer bridges leaves the
renderer one fewer way to start an install.
pnpm 11 and later exit with an error when they block a dependency's
build script, such as Astro's esbuild, even though everything else is
installed, so opening or creating a pnpm project failed. Installs now
keep those scripts blocked without failing, as the Wrangler install
does. The missing-manager error no longer claims a lockfile was found,
since the manager can also come from package.json.
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.

1 participant