antfu-collective / ni Goto Github PK
View Code? Open in Web Editor NEW💡 Use the right package manager
License: MIT License
💡 Use the right package manager
License: MIT License
What ni
command that similiar to pnpm i --shamefully-hoist
?
Do you think the package could be extended to abstract common commands for frameworks like vue:
e.g.
nc bulid
nr build
nr build
nr build
nc start
nr start
# no prod versionnr serve
nr start
nc dev
nr start
nr dev
nr start:dev
Cant install ni
on a machine with global nx
cli installed (https://nx.dev/latest/angular/getting-started/nx-cli).
EEXIST
npm ERR! path C:\Users\###\AppData\Roaming\npm\node_modules\@antfu\ni\bin\nx.js
npm ERR! dest C:\Users\###\AppData\Roaming\npm\nx.cmd
npm ERR! EEXIST: file already exists, cmd shim 'C:\Users\###\AppData\Roaming\npm\node_modules\@antfu\ni\bin\nx.js' -> 'C:\Users\###\AppData\Roaming\npm\nx.cmd'
npm ERR! File exists: C:\Users\###\AppData\Roaming\npm\nx.cmd
npm ERR! Remove the existing file and try again, or run npm
npm ERR! with --force to overwrite files recklessly.
npm ERR! A complete log of this run can be found in:
While trying to use ni in powershell/windows terminal, a conflict occurs.
The "ni" command belongs to the "New-Item" command of powershell.
Is there a way to fix it?
https://nodejs.org/api/packages.html#packages_packagemanager
With this, we could do more accurate package manager detection also enables version-specific features like #23.
nx
could serve as the ni
version of npx
, dlx
, and pnpx
.
https://volta.sh sets custom paths per project. NI does not respect these paths, and uses the global node/npm/yarn installed by volta not the project specific one.
Ni command conflicts with cmdlet New-Item commands on Windows
As described in the title.
My system is window 10 20h2.
My ni version is 0.10.1.
The output after executing ni is as follows.
`PS C:\Users\xxxxx> ni
位于命令管道位置 1 的 cmdlet New-Item
请为以下参数提供值:
Path[0]:`
Would you be open to the idea of having a single ni
binary to avoid things like #20 ?
Maybe something like:
ni
ni add
ni remove
ni run
ni dlx
ni update
...etc
ni
is a shorthand for New-Item
in PowerShell. It can be aliased to npx @antfu/ni
though.
I noticed when I do pnpm -i --latest
I get the following output:
❯ pnpm up -i --latest
? Choose which packages to update (Press <space> to select, <a> to toggle all, <i> to invert selection) …
❯ ○ @vueuse/core 6.9.2 ❯ 7.0.0
○ lint-staged (dev) 11.2.6 ❯ 12.1.1
Enter to start updating. Ctrl-c to cancel.
But with nu -i --latest
I see:
❯ nu -i --latest
All of your dependencies are already up-to-date inside the specified ranges. Use the --latest option to update the ranges in package.json
Seem like --latest
is not respected.
When I get a chance I'll try to debug and maybe send a PR.
First of all, thank you very much for this project, it has been very convenient for me, but of course I also encountered the problem of nrm
naming conflicts, whenever I want to uninstall a package, I still need to determine the current package manager, considering how often npm uninstall
is used, I think I need to discuss this issue.
When I read #33, my first thought was to customize the alias in .nirc
, but that didn't seem to work when I tried to dynamically generate the bin file.
idea: read the configuration before install and generate the bin file, add it to directories.bin
.
Reference:
preinstall
: https://docs.npmjs.com/cli/v8/using-npm/scripts#life-cycle-scripts
directories.bin
: https://docs.npmjs.com/cli/v8/configuring-npm/package-json#directoriesbin
bin-links
: https://github.com/npm/bin-links
Similar Questions: https://stackoverflow.com/questions/67665230/can-i-add-files-to-directories-bin-dynamically-through-npm-script-before-npm-pro
After I researched and tried the above options with no results, I had to post the question to the community for further discussion.
If there is no other solution, is it possible to change nrm
to nun
or some other name ...😂...
"scripts": {
"renderer": "ts-node .tauri-vite/runner.js",
"main": "tauri dev",
"dev": "concurrently \"nr renderer\" \"nr main\""
},
when use nr dev
main process is exit
"scripts": {
"renderer": "ts-node .tauri-vite/runner.js",
"main": "tauri dev",
"dev": "concurrently \"yarn renderer\" \"yarn main\""
},
nr dev
is ok
As with nu -i
, add an option for listing outdated packages.
This would be an alias for npm outdated
, pnpm outdated
and yarn outdated
.
Example: nu -o
Thank you for this very helpful tool! ❤️
I love this tool so much. It makes my life easier but It would be great if there was a command to uninstall a package
nr后,可供选择的环境,方向键切换没反应
Just view https://stackoverflow.com/questions/58482655/what-is-the-closest-to-npm-ci-in-yarn
Unfortunately, because of the way yarn module resolution works, just doing yarn install --frozen-lockfile is sometimes not enough. You can still be left with transitive deps that are invalid.
To truly get the same behavior as npm ci you must do:
rm -rf node_modules && yarn install --frozen-lockfile
Does ni --frozen
need to support rimraf? Or there are other considerations
Looks like it does not work on Windows.
pnpm -v # => 5.13.4
ni
Result
'command' is not recognized as an internal or external command,
operable program or batch file.
Detected pnpm but it doesn't seem to be installed.
Hey, what about npm uninstall
/ yarn remove
command? Is it available?
View current PowerShell version: run get-host | select version
Version: 5.x
Open folder: C:\Windows\System32\WindowsPowerShell\v1.0
Edit file: Microsoft.PowerShell_profile.ps1
- If the file does not exist, create a new one.
Add the following line to the end of the file: Del alias:ni -Force
Restart the terminal.
Version: 7.x
Open folder: C:\Program Files\PowerShell\7
Edit file: Microsoft.PowerShell_profile.ps1
- If the file does not exist, create a new one.
Add the following line to the end of the file: Remove-Alias -Name ni -Force
Restart the terminal.
I tried out the solution described at the bottom of the README. It didn't work.
By running following command in PowerShell 7, I could get rid of the system alias:
del alias:ni -Force
The -Force
flag is needed because it is a system alias that is protected.
Edit: the solution above is only valid for the current session.
The following solution worked:
New-Item $profile -force -itemtype file
notepad $profile
remove-item alias:ni -Force
I have a .nirc
file in the same directory as my package.json, but the globalAgent
is ignored when installing global packages, and is using npm
instead of pnpm
.
Here is the contents of my .nirc
file:
defaultAgent=pnpm
globalAgent=pnpm
After install ni
globally, I found nrm instruction is substituted by ni
feature.
Usually, I use nrm as managing npm registries tools.
So, can we rename nrm to other name? From the download size of nrm, it was commonly used.
Hey, the solution is to add Remove-Alias -Name ni -Force
to your PowerShell profile. Your profile file path is stored in $PROFILE
and if you need to create a new one, you can follow the documentation. Hope that helps.
Originally posted by @innocenzi in #21 (comment)
Which is available in recent nodejs versions
NPM registry manager, fast switch between different registries: npm, cnpm, nj, taobao https://github.com/Pana/nrm
感谢大佬的工具,对我们非常有帮助!
在我们的 CI 环境中使用 ni 提示
ERR_PNPM_OUTDATED_LOCKFILE Cannot install with "frozen-loackfile" beacause pnpm-lock.yaml is not up-to-date with package.json
Note that in CI enviroments this setting is true by default. If you still need to run install in such cases, use "pnpm install --no-frozen-lockfile"
但是我看了下,好像并不支持 --no-frozen-lockfile
求大佬帮助 🙏
pnpm
is also equivalent to pnpm exec
I use the package manager Ni in webstorm. When there is @ in the directory folder, I can't recognize it, as shown in the following figure
My current solution is to copy all the files under @ antfu / Ni to the Ni folder so that they can be used
But this is only a temporary solution. It is not convenient for me to manage it (such as future upgrade and other operations)
I can't determine whether this is a webstorm problem or a Ni problem, but what I want is if the released package doesn't bring @. That is, the released package is not private. Can this problem be solved?
Hello ! :)
A command that allow to init a projet based on the package manager specified in the config file ? :p
Add nid
alias for npm install --dev
or yarn add --dev
I hope can use nui xxx
to uninstall a module, insteading of use npm uninstall
or yarn remove
, Thanks~~
nr
add additional --
in src/agents.ts
and therefore npm config env is lost.
➜ nr dev --report
✔ Choose the agent › npm
> [email protected] dev
> node ./index.js "--report"
npm_config_report undefined
➜ npm run dev --report
> [email protected] dev
> node ./index.js
npm_config_report true
npx
will try to load local package bins from ./node_modules/.bin
, if not match, then download (to tmp dir?) and execute.
nx
seems skipped the search on local package bins, it will always download (to tmp dir?) and execute. For some packages, the results is different as well.
# install
ni -D jest ts-jest
# run
nx ts-jest config:init
I am using pnpm, the echo is like this:
Progress: resolved 11, reused 7, downloaded 2, added 0
......
But if run npx ts-jest config:init
, it just run, without an extra installation.
有这么一个场景,假设有一个文件目录为这样:
| ~
├── react-project
│ ├── .nirc (content: yarn) #不支持
│ ├── bar
│ └── foo
└── vue-project
├── .nirc (content: pnpm) #不支持
└── vite-project
我希望在 react-project
目录下使用 yarn
, 在 vue-project
目录中使用 pnpm
;
这个时候我有以下几种方案:
"packageManager": "[email protected]"
;NI_CONFIG_FILE
环境变量,指定 .nirc
文件路径;上述方案的一些顾虑:
方案1: 如果是三方开源项目,需要手动去添加记录,产生不必要的 git 变更。
方案2: 可能需写一些 shell 脚本来支持目录变更后修改环境变量或者覆盖 .nirc
文件内容,如借助 .zshrc
的 hooks
方案3: 如果实现则会存在一个问题是配置文件混乱,使用者不知道执行命令后使用的是那个包管理器,当其实可以丰富一下帮助文档,比如 ni "?"
目前只是一个 debugger 功能,但可以在这个上面输出更多的内容, config 信息等等等
如上树形目录图,在没有明确包管理器时,递归向父目录查找配置文件。
Additional command that installs the package as dev dependency, without manually doing the -D, --save-dev etc.
I personally have such a zsh alias and i use it a lot, so i guess it can be useful for others too.
Can do the PR
nrm axios
# npm uninstall axios
# yarn remove axios
# pnpm remove axios
I use https://github.com/antfu/taze quite frequently and just thought it would quite fall under the scope of this project, that is, managing dependencies easily with one tool and unified syntax.
One could argue that ni
's scope should stay limited. I won't open the debate but I wanted to submit the idea. A nt
command would be pretty cool.
I always wanted to install a package with its corresponding type package if it exists.
I wonder if ni
could introduce one command or an argument to the ni
command to install both packages.
Same issue as yarn-or-npm
, see discussions in camacho/yarn-or-npm#6.
New command no
for npm outdated
/ yarn outdated
As a developer, I always use link to test some projects.But use incorrect xxx link, it will bring other lockfile.
So I think it's useful.
For command simplest, may it can call nlnk.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.