Skip to content
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

Feature Request : Add an option to skip script not found error #149

Open
jpolo opened this issue Aug 28, 2024 · 7 comments
Open

Feature Request : Add an option to skip script not found error #149

jpolo opened this issue Aug 28, 2024 · 7 comments

Comments

@jpolo
Copy link

jpolo commented Aug 28, 2024

Hi,

I am struggling with a problem when using wildcards ex: 'myscript:*'. At the moment if no script starting with myscript is found it throws an error.

The only workaround I found was to create an empty script but it is kind of hacky, and it creates noise in the package.json.

It would be nice to add an option to the cli to be able to ignore this kind of error.

Thanks in advance !

@bcomnes
Copy link
Owner

bcomnes commented Aug 28, 2024

Can you explain the use case further? Why do you have wildcards with no subscripts?

@voxpelli
Copy link
Collaborator

Essentially a if-present for npm-run-all2 then.

I myself have used --if-present for npm run in reusable GitHub Action workflows to enable automatically running eg build steps when build scripts are present.

If I instead of npm run would do npx npm-run-all2, then I could see the need, but I instead always do a foo for a foo:*, so that I can define in foo if it should be a run-p foo:* or run-s foo:* or even a run-s bar foo:* (eg. run-s clean build:* is a classic for me)

@bcomnes
Copy link
Owner

bcomnes commented Sep 3, 2024

Possibly open to the feature, but I don't have any interest in implementing it.

@jpolo
Copy link
Author

jpolo commented Sep 5, 2024

Can you explain the use case further? Why do you have wildcards with no subscripts?

Most of my projects are standardized / based on generators. When I generate the empty package, I generate a package.json script for all common tasks. for example "lint": "run-p 'lint:*'" (and for many tasks : lint, test, build, etc)

This is helpful and safe because I only have to add new lines when adding a new tool, I do not have to modify any line (open / close principle)

To sum up here are the cases when I have a wildcard considered as a success :

  • When I generate the new package, the CI should pass
  • For some cases such as shared configurations, some tasks are irrelevant (ex: test for a typescript configuration). Still I would like to keep my package.json standardized.

@bcomnes
Copy link
Owner

bcomnes commented Sep 5, 2024

What if we just change the default behavior? (similar to mapping over an empty array) Would that break anything?

@jpolo
Copy link
Author

jpolo commented Sep 6, 2024

So you mean that if the default behavior of the command would be : if no script is found the script shall exit with a 0 code ?

For me, it would be great, I do not know for other use cases of other apps.

Personally, I find this default behavior much more logic...

@bcomnes
Copy link
Owner

bcomnes commented Sep 6, 2024

I recently read "A Philosophy of Software Design" by John Ousterhout and have been mulling on some of the ideas in the book including:

Throwing exceptions is easy; handling them is hard. Thus, the complexity of exceptions comes from the exception handling code. The best way to reduce the complexity damage caused by exception handling is to reduce the number of places where exceptions have to be handled. The rest of this chapter will discuss four techniques for reducing the number of exception handlers.

A great chapter, and generally compelling argument in reducing errors when they can just be avoided.

I think handling empty run globs similar to empty array methods is probably an acceptable way to go. True, if you change your glob string on accident, and now your sub-scripts don't get run, it won't throw an error, but thats likely to manifest in other more important errors.

But either way, this is an old module and I'm sure there is someone out there who would disagree. I would rather change the behavior under a very minimal, easy to adapt breaking change that have to burden users with more flags.

Anyone care to implement?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants