-
Notifications
You must be signed in to change notification settings - Fork 5.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(cli): set npm_config_user_agent
when running npm packages or tasks
#26639
Conversation
@nathanwhit , I had a look at adding deno to the solid-cli just now, but it's quite tricky to work on with deno specifically. This is because I keep hitting errors with missing "node:" prefixes when testing the package locally. All the deno node-compat that takes effect when running e.g. Repro of this:
➜ deno run ./packages/create-solid/src/index.ts
error: Relative import path "fs" not prefixed with / or ./ or ../
hint: If you want to use a built-in Node module, add a "node:" prefix (ex. "node:fs").
at file:///Users/admin/repos/solid-cli/packages/commands/dist/handlers/new.mjs:1:485 |
@birkskyum try running with |
@bartlomieju , it's a good idea to have it in the hint - am I using it correctly? (deno 2.0.3) ➜ deno run --unstable-sloppy-imports ./packages/create-solid/dist/index.mjs
error: Relative import path "zlib" not prefixed with / or ./ or ../
hint: If you want to use a built-in Node module, add a "node:" prefix (ex. "node:zlib").
at file:///Users/admin/repos/solid-cli/packages/create-solid/dist/index.mjs:28:16
➜ deno run --unstable-sloppy-imports ./packages/create-solid/src/index.ts
error: Relative import path "fs" not prefixed with / or ./ or ../
hint: If you want to use a built-in Node module, add a "node:" prefix (ex. "node:fs").
at file:///Users/admin/repos/solid-cli/packages/commands/dist/handlers/new.mjs:1:485 |
@birkskyum I was close :D it's actually |
That works better, is there a trick for allowing importing .json files (such as package.json) too? This runs Gives: ➜ deno run --unstable-bare-node-builtins ./packages/create-solid/src/index.ts
Warning Resolving "fs" as "node:fs" at file:///Users/admin/repos/solid-cli/packages/commands/dist/handlers/new.mjs:1:485. If you want to use a built-in Node module, add a "node:" prefix.
Warning Resolving "util" as "node:util" at file:///Users/admin/repos/solid-cli/packages/utils/dist/index.mjs:5:158. If you want to use a built-in Node module, add a "node:" prefix.
error: Expected a JavaScript or TypeScript module, but identified a Json module. Consider importing Json modules with an import attribute with the type of "json".
Specifier: file:///Users/admin/repos/solid-cli/packages/create-solid/package.json
at file:///Users/admin/repos/solid-cli/packages/create-solid/src/index.ts:5:25 Because of
I tried adding the
|
No, I don't think we have a trick for that, it's strange that it allows to destructure JSON imports, I don't think it's supported in Node either. Shouldn't this code be somehow handled by a bundler first? |
You're right - node, like deno, don't support the named json export, but bun does which I had tried prior:
If I instead bundle, and run the dist/index.mjs with deno, I then get this issue with ➜ deno run -A --unstable-bare-node-builtins ./packages/create-solid/dist/index.mjs
Warning Resolving "module" as "node:module" at file:///Users/admin/repos/solid-cli/packages/create-solid/dist/index.mjs:2:31. If you want to use a built-in Node module, add a "node:" prefix.
Warning Resolving "fs" as "node:fs" at file:///Users/admin/repos/solid-cli/packages/create-solid/dist/index.mjs:16:150. If you want to use a built-in Node module, add a "node:" prefix.
Warning Resolving "path" as "node:path" at file:///Users/admin/repos/solid-cli/packages/create-solid/dist/index.mjs:17:57. If you want to use a built-in Node module, add a "node:" prefix.
Warning Resolving "fs/promises" as "node:fs/promises" at file:///Users/admin/repos/solid-cli/packages/create-solid/dist/index.mjs:18:42. If you want to use a built-in Node module, add a "node:" prefix.
Warning Resolving "stream" as "node:stream" at file:///Users/admin/repos/solid-cli/packages/create-solid/dist/index.mjs:19:26. If you want to use a built-in Node module, add a "node:" prefix.
Warning Resolving "stream/promises" as "node:stream/promises" at file:///Users/admin/repos/solid-cli/packages/create-solid/dist/index.mjs:20:26. If you want to use a built-in Node module, add a "node:" prefix.
Warning Resolving "os" as "node:os" at file:///Users/admin/repos/solid-cli/packages/create-solid/dist/index.mjs:21:24. If you want to use a built-in Node module, add a "node:" prefix.
Warning Resolving "events" as "node:events" at file:///Users/admin/repos/solid-cli/packages/create-solid/dist/index.mjs:22:34. If you want to use a built-in Node module, add a "node:" prefix.
Warning Resolving "assert" as "node:assert" at file:///Users/admin/repos/solid-cli/packages/create-solid/dist/index.mjs:26:16. If you want to use a built-in Node module, add a "node:" prefix.
Warning Resolving "buffer" as "node:buffer" at file:///Users/admin/repos/solid-cli/packages/create-solid/dist/index.mjs:27:36. If you want to use a built-in Node module, add a "node:" prefix.
Warning Resolving "zlib" as "node:zlib" at file:///Users/admin/repos/solid-cli/packages/create-solid/dist/index.mjs:28:16. If you want to use a built-in Node module, add a "node:" prefix.
error: Uncaught (in promise) ReferenceError: global is not defined
at file:///Users/admin/repos/solid-cli/packages/create-solid/dist/index.mjs:33:4663
at file:///Users/admin/repos/solid-cli/packages/create-solid/dist/index.mjs:33:459
at file:///Users/admin/repos/solid-cli/packages/create-solid/dist/index.mjs:33:5290
at file:///Users/admin/repos/solid-cli/packages/create-solid/dist/index.mjs:33:459
at file:///Users/admin/repos/solid-cli/packages/create-solid/dist/index.mjs:33:6869
at file:///Users/admin/repos/solid-cli/packages/create-solid/dist/index.mjs:33:459
at file:///Users/admin/repos/solid-cli/packages/create-solid/dist/index.mjs:33:8070
at file:///Users/admin/repos/solid-cli/packages/create-solid/dist/index.mjs:33:459
at file:///Users/admin/repos/solid-cli/packages/create-solid/dist/index.mjs:33:9542
at file:///Users/admin/repos/solid-cli/packages/create-solid/dist/index.mjs:33:459 |
@bartlomieju , if I add
and just use then deno can run the index.ts 🎉 ➜ deno run -A --unstable-bare-node-builtins ../packages/create-solid/src/index.ts
Warning Resolving "fs" as "node:fs" at file:///Users/admin/repos/solid-cli/packages/commands/dist/handlers/new.mjs:1:485. If you want to use a built-in Node module, add a "node:" prefix.
Warning Resolving "util" as "node:util" at file:///Users/admin/repos/solid-cli/packages/utils/dist/index.mjs:5:158. If you want to use a built-in Node module, add a "node:" prefix.
┌
Create-Solid v0.5.13
│
◇ Project Name
│ solid-start-created-with-deno The bundled dist/index.mjs still gives the error about |
@birkskyum no flag yet to enable |
0a75502
to
cc43288
Compare
Just realized it's a lot easier to work on adding support for deno in the various cli's after this pr is merged. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM 👍
@@ -204,7 +210,7 @@ impl ShellCommand for NpmCommand { | |||
mut context: ShellCommandContext, | |||
) -> LocalBoxFuture<'static, ExecuteResult> { | |||
if context.args.first().map(|s| s.as_str()) == Some("run") | |||
&& context.args.len() > 2 | |||
&& context.args.len() >= 2 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is it now >=
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Turned out this code wasn't triggering. context.args
doesn't include the command name (npm
), so the first arg is run
and the second arg is the name of the script. So npm run foo
was missing this branch.
Opened a PR to |
Hmm, with canary deno 2.0.4+4774eab, the commit after this, I still see:
|
It’s only set when running |
@nathanwhit , ah that explains it, thanks So this doesn't work
And this does work:configure package.json {
"scripts": {
"runwithagent": "deno run --unstable-bare-node-builtins -A ./packages/create-solid/src/index.ts",
}
}
|
Hm, I'm not sure. Maybe it should also be set if there's a local |
…sks (#26639) Fixes #25342. Still not sure on the exact user agent to set (should it include `node`?). After this PR, here's the state of running some `create-*` packages (just ones I could think of off the top of my head): | package | prints/runs/suggests deno install | notes | | ---------------- | ------------- | ------ | | `create-next-app` | ❌ | falls back to npm, needs a PR ([code](https://github.com/vercel/next.js/blob/c32e2802097c03fd9f95b1dae228d6e0257569c0/packages/create-next-app/helpers/get-pkg-manager.ts#L3)) | `sv create` | ❌ | uses `package-manager-detector`, needs a PR ([code](https://github.com/antfu-collective/package-manager-detector/tree/main)) | `create-qwik` | ✅ | runs `deno install` but suggests `deno start` which doesn't work (should be `deno task start` or `deno run start`) | `create-astro` | ✅ | runs `deno install` but suggests `npm run dev` later in output, probably needs a PR | `nuxi init` | ❌ | deno not an option in dialog, needs a PR ([code](https://github.com/nuxt/cli/blob/f04e2e894446f597da9d971b7eb03191d5a0da7e/src/commands/init.ts#L96-L102)) | `create-react-app` | ❌ | uses npm | `ng new` (`@angular/cli`) | ❌ | uses npm | `create-vite` | ✅ | suggests working deno commands 🎉 | `create-solid` | ❌ | suggests npm commands, needs PR It's possible that fixing `package-manager-detector` or other packages might make some of these just work, but haven't looked too carefully at each
Fixes #25342.
Still not sure on the exact user agent to set (should it include
node
?).After this PR, here's the state of running some
create-*
packages (just ones I could think of off the top of my head):create-next-app
sv create
package-manager-detector
, needs a PR (code)create-qwik
deno install
but suggestsdeno start
which doesn't work (should bedeno task start
ordeno run start
)create-astro
deno install
but suggestsnpm run dev
later in output, probably needs a PRnuxi init
create-react-app
ng new
(@angular/cli
)create-vite
create-solid
It's possible that fixing
package-manager-detector
or other packages might make some of these just work, but haven't looked too carefully at each