starlight icon indicating copy to clipboard operation
starlight copied to clipboard

Pagefind forces the use of npx to run which may not be available

Open Mikescops opened this issue 2 months ago • 4 comments

What version of starlight are you using?

0.36.1

What version of astro are you using?

5.14.6

What package manager are you using?

pnpm

What operating system are you using?

Linux

What browser are you using?

Chrome

Describe the Bug

Hello,

When using pagefind (which is the default) the hook forces the use of npx. See https://github.com/withastro/starlight/blob/5018793b5c03d6d22eaec4c7174b5fe1c0aeace5/packages/starlight/index.ts#L162C6-L162C17

I'm in a constrained environment (bazel) where I only have access to pnpm so it would be great to be able to choose the specific env package manager.

Link to Minimal Reproducible Example

none

Participation

  • [ ] I am willing to submit a pull request for this issue.

Mikescops avatar Oct 24 '25 12:10 Mikescops

Thanks for the issue @Mikescops!

I remember looking into this briefly a while ago and it being tricky, but we should definitely try to find a solution. I wonder whether it would be possible to find and execute the pagefind binary directly rather than relying on the package manager to find it 🤔

delucis avatar Nov 03 '25 12:11 delucis

I wonder whether it would be possible to find and execute the pagefind binary directly rather than relying on the package manager to find it 🤔

Would that work consistently on all OSs? I could image that there might be problems with binaries as well, but I'm more thinking about dotnet development and I'm not sure how this works in JS tbh...

trueberryless avatar Nov 03 '25 13:11 trueberryless

I'd rather not depend on an extra dependency but this seems like a way to solve the issue: https://github.com/egoist/detect-package-manager/blob/main/src/index.ts

Otherwise i'd be in favor of adding an option in starlight config to set the pagefind command we want, it's simpler / safer.

Mikescops avatar Nov 03 '25 14:11 Mikescops

I don’t think we’d need something as complex as detect-package-manager in this case because we should be able to detect how the command was run, e.g. using something like the logic from which-pm-runs.

Would that work consistently on all OSs? I could image that there might be problems with binaries as well, but I'm more thinking about dotnet development and I'm not sure how this works in JS tbh...

Ah, I may have confused you with the word “binary”. We already run the binary, we just use npx pagefind to find it (whenever you do npx <package-name> it runs that package’s “binary”, which can also be a JS file, it just means it’s executable). The point was just that if we resolved the path ourselves, we could run e.g. ./node_modules/pagefind/cli (made-up path) instead of npx pagefind. But in any case detecting the PM is probably a less risky strategy.

delucis avatar Nov 03 '25 15:11 delucis

+1 since using npx is problematic when using bun as well :)

/edit: this may be a solution: https://pagefind.app/docs/node-api/ /edit2: nevermind, I just saw the linked PR doing exactly that

mervyn-mccreight avatar Nov 20 '25 16:11 mervyn-mccreight