Giter Site home page Giter Site logo

dum's Introduction






dum replaces npm run and npx.
Instead of waiting 200ms for your npm client to start, it will start immediately.
💛 You can help the author become a full-time open-source maintainer by sponsoring him on GitHub.


CleanShot 2021-11-20 at 15 23 54@2x




How

This is written in Rust! (Or any compile-to-native language).

Benchmark (hyperfine "dum foo" "npm run foo" --warmup 10):

Command Mean [ms] Min [ms] Max [ms] Relative
dum foo 41.7 ± 1.2 39.8 44.6 1.00
npm run foo 333.7 ± 2.0 330.0 336.0 8.01 ± 0.23

Install

Homebrew

brew install egoist/tap/dum

Shell

curl -sSL https://bina.egoist.sh/egoist/dum | sh

Cargo

cargo install dum

Scoop

scoop install dum

GitHub Releases

Download a release manually and move it to /usr/local/bin manually.

Usage

dum <npm_script|bin_script> [...args_to_forward]: Run npm scripts or scripts in node_modules/.bin, like yarn run, npm run, npx.

If you want to pass flags to dum itself, like the -c flag to change directory, you should put it before the script name, like dum -c another/directory script_name --forward some_flag.

Examples:

dum some-npm-script

dum some-npm-script --flags will --be forwarded
# Like npx, but mush faster
dum some-npm-package-cli-name --flags will --be forwarded

# Change working directory
dum -c packages/sub-package build

# More
dum --help

Install Packages

Dum is not a package manager yet, but we forward install, add, remove commands to npm, pnpm and yarn automatically:

# Run `npm i` or `yarn` or `pnpm i` depending on the project
dum install # or `dum i`
# Like above but add packages
dum add react vue -D

dum remove react vue

Limitations

Inspiration

I want to try and learn Rust so I made this. Inspired by bun.

Sponsors

sponsors

License

MIT © EGOIST

dum's People

Contributors

beetcb avatar egoist avatar fannheyward avatar kocal avatar renovate[bot] avatar sachinraja avatar tmkx avatar vardrop avatar ycjcl868 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

dum's Issues

Support running multiple scripts, both in parallel or sequential

I don't know if this is out-of-scope for dum, but I find that it could be a perfect (and faster) alternative for npm-run-all (that, at this point, I don't even think it's maintained anymore).

I'd love it if dum could run multiple scripts in one command, e.g. dum clean build, and, with a flag, run them in parallel, so something like dum --parallel build:ts build:dts.

Another impressive feature of npm-run-all is its glob-like script-name resolution (e.g. build:*). It would be chef's kiss if this could be implemented and translated to "run every script that matches this pattern in parallel." This would make it very easy to have one script, dum clean build:*, that cleans the output directory, and, after that, runs both build:ts and build:dts in parallel.

PATH should be dynamic

Hi,

I was trying out dum and noticed that there is one mistake (?) it does in how it interprets the PATH environment variable. Pasting some logs below to give a clearer picture.

$ cat file.js
Object.entries(process.env).forEach(([key, value]) => {
  if (key.startsWith("npm_")) {
    // Skip the npm related envs as those are not supported yet by `dum`.
    return;
  }
  console.log(`${key}: ${value}`);
});

The following are the results from npm and dum respectively. I'm only pasting the differences in output here.

$ npm run env
NODE: /usr/local/lib/node_modules/node/bin/node
INIT_CWD: /Users/faizaan.m/Developer/webpro-frontend
PATH: /usr/local/lib/node_modules/npm/node_modules/npm-lifecycle/node-gyp-bin:/Users/faizaan.m/Developer/webpro-frontend/node_modules/.bin:/Users/faizaan.m/.cargo/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Applications/Postgres.app/Contents/Versions/latest/bin:/Users/faizaan.m/.cargo/bin
_: /usr/local/bin/node
$ dum env
PATH: /Users/faizaan.m/.cargo/bin:/Users/faizaan.m/.cargo/bin:/Users/faizaan.m/.cargo/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Applications/Postgres.app/Contents/Versions/latest/bin:/Users/faizaan.m/.cargo/bin:/Users/faizaan.m/Developer/webpro-frontend/node_modules/.bin
_: /usr/local/bin/node

As you can see there are a couple of differences,

  1. INIT_CWD is missing from dum but this is easily fixable by adding current_dir to the envs Map.
  2. NODE is missing from dum, but I think using the result of which node might fix this (or we can evaluate if this is needed)
  3. PATH is different in both versions - npm injects it own internal binary into the PATH. While one could argue that this is not necessary for dum to support, there's one more bigger issue.

Let's say we start with the following PATH value

$ echo $PATH
/Users/faizaan.m/.cargo/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Applications/Postgres.app/Contents/Versions/latest/bin

And then I change the PATH

$ export PATH=$PATH:/opt/new-tool

Then, if I rerun the above commands, this is the output I see. Again, pasting only the differences.

$ npm run env
PATH: /usr/local/lib/node_modules/npm/node_modules/npm-lifecycle/node-gyp-bin:/Users/faizaan.m/Developer/webpro-frontend/node_modules/.bin:/Users/faizaan.m/.cargo/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Applications/Postgres.app/Contents/Versions/latest/bin:/Users/faizaan.m/.cargo/bin:/opt/new-tool
$ dum env
PATH: /Users/faizaan.m/.cargo/bin:/Users/faizaan.m/.cargo/bin:/Users/faizaan.m/.cargo/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Applications/Postgres.app/Contents/Versions/latest/bin:/Users/faizaan.m/.cargo/bin:/Users/faizaan.m/Developer/webpro-frontend/node_modules/.bin

You can see that /opt/new-tool is missing when running via dum. I believe this is because env! is injecting the value when compiling dum thereby hardcoding the value into the binary.

What is the secret?

Can you add a brief explanation of the trick that you've done to the Readme? Is that just the general supremacy of a compiled binary over a script?

List scripts in package

I often forget which scripts are available in a project if I'm using it infrequently and then have to go look inside package.json to refresh my memory.

Do you think a dum -l to list available scripts would be useful? If so happy to create a PR.

bun support

Hi. Currently, I'm using https://github.com/antfu/ni and it supports all 4 package managers: npm, yarn, pnpm and bun. So I wish that dum it can detect bun.lockb file and have bun option when you do dum i :)

`dum` could default to install

Currently running dum prints out help message. Instead, it could do dum install. This is how yarn works and I personally love it.

Btw. I love this project, I want to use it not only as a faster alternative to npm run but as a tool unifying CLIs for different package managers. Switching between projects using different PMs is such a PITA.

thread 'main' panicked at 'failed to parse package.json

thread 'main' panicked at 'failed to parse package.json: Error("trailing comma", line: 21, column: 3)', /Users/Vaughan/.cargo/registry/src/github.com-1ecc6299db9ec823/dum-0.1.19/src/run.rs:144:52
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

Should handle this error instead of a panic.

support forwarding flags without `--`

one of the commands I tried to run with dum:

dum test test/internal/fetch.ts -w=@magnetarjs/core

didn't work

But just npm run does work.

npm run test test/internal/fetch.ts -w=@magnetarjs/core

PS: I use npm 7.14+ workspaces

Dependency Dashboard

This issue provides visibility into Renovate updates and their statuses. Learn more

Open

These updates have all been created already. Click a checkbox below to force a retry/rebase of any.

Detected dependencies

cargo
Cargo.toml
  • serde_json 1.0
  • dialoguer 0.9.0
  • ansi_term 0.12.1
  • ctrlc 3.2.1
  • log 0.4.14
  • env_logger 0.9.0
  • path-absolutize 3.0.11
  • anyhow 1.0.52
github-actions
.github/workflows/release.yml
  • actions/checkout v2
  • FranzDiebold/github-env-vars-action v2.3.1
  • actions/cache v2.1.7
  • actions-rs/toolchain v1
  • actions-rs/cargo v1
  • actions/upload-artifact v2
  • actions/upload-artifact v2
  • svenstaro/upload-release-action v2
  • svenstaro/upload-release-action v2

  • Check this box to trigger a request for Renovate to run again on this repository

fix: spreading quoted, multi-word arguments instead of forwarding them to script

Description

Program currently spreading/expanding quoted, multi-word arguments instead of forwarding them to script.

How to reproduce bug

Run the following command after cloning the repository:

dum run foo 'first arg' 'second'

Expected behavior

from example [ 'first arg', 'second' ]

Actual behavior

from example [ 'first', 'arg', 'second' ]

Use `script-shell` from npm config to run the `package.json` scripts

It's a common practice on projects to use shell syntax in package.json scripts and developers on Windows use script-shell config in .npmrc:

script-shell=C:\Program Files\git\bin\bash.exe

or case-insensitive env:

npm_config_script_shell=C:\Program Files\git\bin\bash.exe 

Without that dum on Windows fails to run many scripts on our projects.

Willing to learn Rust and make a PR if you like :)

Silent flag

It'd be nice if there was a --silent flag (like yarn has) that would suppress all dum output, leaving only output from the commands being run.

CleanShot 2022-09-08 at 17 39 10@2x

Allow running Node with env vars

I find I have to pass a lot of flags via NODE_OPTIONS to get ESM and other experimental features to work.

This Node package allows you to pass env vars to Node: https://github.com/toddbluhm/env-cmd

But it adds 300ms to startup time - toddbluhm/env-cmd#349

I would love to use dum instead.

a. Support running a cross-platform script (.sh / .ps1 / .bat)

Essentially just doing the following (maybe reading location of script files from package.json or another env var):

I would be sharing script files from <package>/node_modules/my-scripts/scripts/(run-win.ps1|run-nix.sh).

https://stackoverflow.com/a/68934424/130910

{
    "scripts": {
        "build": "( Write-Output 'Powershell' && ./tools/build-ps.ps1 ) || 
                  ( CALL ./tools/build-cmd.bat ) || 
                  ( bash -c 'uname -a | grep -q -i Linux' && bash -c ./tools/build-linux.sh ) ||
                  ( bash -c 'uname -a | grep -q -i Darwin' && bash -c ./tools/build-mac.sh )"
        }
}

b. Support .env, etc.

This is lower priority for me. Replicates the functionality of https://www.npmjs.com/package/env-cmd

`dum install`

I have no plan to reinvent a package installer (for now), but we can add an install command that runs npm i, yarn or pnpm i depending on the project type.

Send script info to stderr

Currently dum outputs which commands it's going to execute, eg on

dum some-package-script

I'd like to be able to pipe the script output to something else easily without including the dum messages, eg.

dum some-script-producing-json | jq .

I'd suggest to either

  1. Print dum own messages to stderr by default
  2. Detect a tty/pipe situation and avoid printing messages (or use stderr in that case)

I'd be happy to make a pull request if you're interested

Broken Install link

The readme lists this URL: https://bina.egoist.sh/egoist/dum which is not hosting a shell script one could pipe to sh as is indicated by the readme.

❯ curl -sSL https://bina.egoist.sh/egoist/dum
<html><head><title>Loading...</title></head><body><script type='text/javascript'>window.location.replace('https://bina.egoist.sh/egoist/dum?ch=1&js=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhdWQiOiJKb2tlbiIsImV4cCI6MTY3OTM0NTM3OCwiaWF0IjoxNjc5MzM4MTc4LCJpc3MiOiJKb2tlbiIsImpzIjoxLCJqdGkiOiIydDczYWI4cTFoNGVmc2xsN2sxMXFkY2EiLCJuYmYiOjE2NzkzMzgxNzgsInRzIjoxNjc5MzM4MTc4ODgyNTM5fQ.SKwqmhbvxR0rAAZnV5n9vWLuJgYxHwftkvKXVdCgyjg&sid=f79a49be-c74f-11ed-9973-99ae3de8c258');</script></body></html>%

❯ curl -sSL https://bina.egoist.sh/egoist/dum\?ch\=1\&js\=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhdWQiOiJKb2tlbiIsImV4cCI6MTY3OTM0NTM3OCwiaWF0IjoxNjc5MzM4MTc4LCJpc3MiOiJKb2tlbiIsImpzIjoxLCJqdGkiOiIydDczYWI4cTFoNGVmc2xsN2sxMXFkY2EiLCJuYmYiOjE2NzkzMzgxNzgsInRzIjoxNjc5MzM4MTc4ODgyNTM5fQ.SKwqmhbvxR0rAAZnV5n9vWLuJgYxHwftkvKXVdCgyjg\&sid\=f79a49be-c74f-11ed-9973-99ae3de8c258
<html>
<head><title>403 Forbidden</title></head>
<body>
<center><h1>403 Forbidden</h1></center>
<hr><center>nginx</center>
</body>
</html>

Error: dum: SHA256 mismatch

Hello,

I want to try the project, However, when I try to install via brew it fails:

❯ brew install egoist/tap/dum
==> Downloading https://github.com/egoist/dum/releases/download/v0.1.17/dum-x86_64-apple-darwin.zip
Already downloaded: /Users/user/Library/Caches/Homebrew/downloads/8e4695b0182bc89ad7024c06a32bc9c1e081158bd8bc2f996077da3b478f9a4c--dum-x86_64-apple-darwin.zip
Error: dum: SHA256 mismatch
Expected: d5bfdacc793444a35c3840b23e5716d97502360288ffee7b155a77cec019c740
  Actual: 0b2d80fbcfc8aed439c8da30a539fa390e1f9ce4f4b59926f62a457e92ff46ec
    File: /Users/user/Library/Caches/Homebrew/downloads/8e4695b0182bc89ad7024c06a32bc9c1e081158bd8bc2f996077da3b478f9a4c--dum-x86_64-apple-darwin.zip
To retry an incomplete download, remove the file above.

Replace `install` command with `add` for Yarn

yarn install doesn't allow specifying a list of packages, while npm and pnpm does, so dum install <some-package> does not work universally.

We can simply replace install with add when a list of packages is specified and the package manager is Yarn.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.