mirror of
https://github.com/RGBCube/nu_scripts
synced 2025-07-30 13:47:46 +00:00
fix(npm): update incompatible npm scripts (#1137)
I use Nushell and npm, and noticed that the npm section hasn't been updated for a long time, to the point where it no longer works with current npm versions. In fact, the current script produces the following result:  So I've updated the npm-related scripts to fix this issue. Now it works correctly:  Additionally, since npm -l | lines generates over 900 lines of output, this causes each run to take a long time (at least on my machine). Therefore, I've implemented caching using stor to store the results, which significantly reduces the execution time for subsequent calls. With caching enabled, the delay is now barely noticeable.
This commit is contained in:
parent
32cdc96414
commit
156a0110c7
1 changed files with 21 additions and 9 deletions
|
@ -1,11 +1,22 @@
|
|||
def "nu-complete npm" [] {
|
||||
^npm -l
|
||||
|lines
|
||||
|find 'Run "'
|
||||
|str trim
|
||||
|split column -c ' '
|
||||
|get column4
|
||||
|str replace '"' ''
|
||||
let db = stor open
|
||||
|
||||
try {
|
||||
# query commanders from in-mem db
|
||||
$db | query db "SELECT * FROM npm_commanders_table"
|
||||
} catch {
|
||||
# if catched error, create table and insert all data
|
||||
stor create --table-name npm_commanders_table --columns { value: str, description: str }
|
||||
|
||||
let npm_commanders = ^npm -l
|
||||
| lines
|
||||
| where $it =~ '\s{4}[a-z\-]+.*\s{4,}'
|
||||
| parse -r '\s*(?P<value>[^ ]+)\s*(?P<description>\w.*)'
|
||||
|
||||
$npm_commanders | stor insert --table-name npm_commanders_table
|
||||
|
||||
$npm_commanders
|
||||
}
|
||||
}
|
||||
|
||||
export extern "npm" [
|
||||
|
@ -14,8 +25,9 @@ export extern "npm" [
|
|||
|
||||
def "nu-complete npm run" [] {
|
||||
open ./package.json
|
||||
|get scripts
|
||||
|columns
|
||||
| get scripts
|
||||
| transpose
|
||||
| rename value description
|
||||
}
|
||||
|
||||
export extern "npm run" [
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue