Open ieedan opened 1 day ago
when using resolveCommand even if we aren't using detect it will fail when deploying because node doesn't exist in that environment
In what way does it fail? What's requiring Node?
The ideal structure would add package-manager-detector/types to the exports in package.json so that you could have all the types without having to load index.ts and therefore all modules.
You want just the TypeScript types without any functionality? What are you trying to accomplish?
Basically I would need types to make use of the package without importing anything from index.ts
. But I am not sure if this will allow me get around this.
The svelte-cloudflare adapter fails when resolving dependencies because node doesn't exist in that environment: https://github.com/huntabyte/shadcn-svelte/actions/runs/11856989238/job/33044398976?pr=1491
@ieedan can you try with the code here https://github.com/antfu-collective/package-manager-detector/pull/27#issuecomment-2479967304 ?
@ieedan can you try with the code here https://github.com/antfu-collective/package-manager-detector/pull/27#issuecomment-2479967304 ?
Ah that looks like it makes more sense I just left for the day but I can try this on Monday!
Clear and concise description of the problem
resolveCommand
is really awesome for CLI apps but also can be really useful for buildingsnippet
blocks in front end applications when you want the user to be able to choose their package manager.The problem is that they way this package is structured you must be in an environment that has access to node. So for instance in Cloudflare Pages there is no access to node so when using
resolveCommand
even if we aren't usingdetect
it will fail when deploying because node doesn't exist in that environment.Suggested solution
Would changing the way you import things make a difference to this?
The ideal structure would add
package-manager-detector/types
to the exports inpackage.json
so that you could have all the types without having to loadindex.ts
and therefore all modules.This way you would import from
package-manager-detector/types
andpackage-manager-detector/commands
and that would hopefully avoid needingnode:fs
sincedetect.ts
would not be loaded.Example:
Alternative
No response
Additional context
It's pretty simple to prove/disprove this we would just need to add:
package.json:
and
build.config.ts:
Validations
Willing to open a PR for this if you think this is a good idea!