-
Notifications
You must be signed in to change notification settings - Fork 252
Additional actions #30
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
Comments
I think this is great. For I wonder if [
{
"action": "replace",
"find": "foo",
"replace": "bar",
"files": ["src/**/*", "package.json"]
}
] |
+1. Maybe |
Ya. Or maybe also support for HTMLx template |
I have made a project scaffolding project that I use all the time when I need to test something quickly. It contains the set of tools that I find myself always copying around anyway. It's already really useful, but I've had to include a self removing script into it, to do the bootstrapping. It can be seen here: https://github.com/gustavnikolaj/template-node That means that I have to run it like so:
All I do in that script is to run some actions that execute npm commands to configure test and linting tools etc. As an example; I don't want to depend on a fixed version of say eslint, so instead of including it in a package.json file in the The same thing goes for package.json - if I include it in the repo, I'd have to go in and update it after setting it up - but running The obvious way of integrating this behavior would be to allow an action type that allowed the module to include such a boostrap script. I understand why you might not want to allow arbitrary command execution, but maybe it would be okay if we required the user to answer Another solution could be to add an action that would allow you to execute commands in the context of the directory. [
{
"action": "shell",
"shell": "git init"
},
{
"action": "shell",
"shell": "npm init -y"
},
{
"action": "shell",
"shell": "npm install --save-dev eslint ..."
}
] That would cover most of my use cases. I would also like a way to transform files after the fact though. Something that would allow me to define a script target in the package.json file that got created after running the I don't know how to do that with declarative actions, but maybe someone else has an idea? :-) I'm happy to contribute PRs for any of these features if we can reach something that would work for us. I use my template project enough to justify improving it a little, and removing some of the ugly hacks :-) |
This is great @gustavnikolaj . Led me think about generic custom scripts too, maybe something like
..if project has some special needs. This means degit could only have common actions, while specific ones would be customized by the repo itself. |
@bernardoadc That's a neat idea. I think the main problem with a solution like that is security and trust. If you look at something like sveltejs/template's README If Instead of being a simple tool that is safe to run for everyone, it basically becomes equivalent to the I completely understand if @Rich-Harris is not comfortable with a change like that, as the primary use case is to help people get going quickly - adding support for code-execution as we have asked for here would make it much less safe. |
Keeping the above in mind, I think that a shell action which prompts the user for confirmation before execution is about as far as we can reasonably push it. You would be able to use it to invoke custom code through node or any other available interpreter on the system, but at least the user would be aware. I completely understand if even that is pushing it too far btw. |
How can we handle security properly when allowing to run custom scripts? |
I guess the pedantic answer is that we can't. Prompting the user (y/N) to confirm before executing a shell command is about as good as we can get, but it will still open the door for some dark-patterns, e.g. hiding malicious code in a bash script or non-obvious hooks. Consider this:
It looks pretty benign on the surface. But with that in place, I could add a You wouldn't know unless you read through the code before running the That could be pretty disastrous if a malicious actor gets control of a repo that is frequently used as a |
You're right @gustavnikolaj, I hadn't thought about security at all (so innocent of me). I agree we cannot make it more secure than to prompt the user, and that is not reasonably safe also. (thinking out loud) what if a simple action would be to display custom text/show post-actions? Examples explain better:
This way nothing is done, it only shows what to do, in an easy copy paste operation. Would that be safer? Would people open scripts to see it's contents? Are we already unsafe today with postinstall scripts? (npm just runs them, it doesn't give me a chance to see what is going to do). Is it less safe a bootstrap.js file than a npm script? (which could call bootstrap.js anyway) So, basically, how far should we worry? |
That looks a lot like what @Rich-Harris suggested in #6 (although that predates the whole action concept).
Yes, we are. This is not only a theory, it has been done already: https://eslint.org/blog/2018/07/postmortem-for-malicious-package-publishes (eslint-scope was taken over and had a new version released that harvested
People already run npm's postinstall hooks all the time without caring about it. And more often than not they will run |
You're right, did not see #6 . The only difference being: do it with actions and not a YAML file (seems better to me). Shell and/or script actions with prompts for safety |
I know I'm super late to this thread but, +1 on the "replace" action. Does anyone by any chance already have that action in a branch? |
This is cool but I've been thinking it's awesome how minimal degit is. Perhaps you could make a new project with a different name and add the additional functionality to it? |
I also like the idea of being able to define custom-script to be run, but I understand the security concerns. I agree that it would probable be better to create a differente project like The use case I have in mind is to have a degit.yml on any folder defining scripts, pretty similar to package.json, and that you could run something like : npx degit user/repo/folder run script-name param1 param2 param3 You could ask user for confirmation and also support a --force parameter. |
Was reading another issue on a totally different project, nonetheless the node_modules safety concern was also raised and I thought it would be good to quote them here (opinion from more people is good, hope you agree): |
the only action I think we really need is {
"action": "exec",
"command": "npm",
"args": ["install"]
} because we can do any templating in pre and post install steps. You could fire off a full-on make command if you wanted to (npm even provides a lightweight cross-platform make cli), or just do some light m4-like templating with npm's own replace. example:
postinstall.js
|
Regarding the it doesn't necessary follow that But given its potential as a footgun, let alone malicious acts, an Prompting the user to accept |
I was in need of this for rapidly creating some packages, so I made a wrapper over degit for this purpose specifically. it doesn't have the "exec" action proposed here to avoid the security issues mentioned, thought it might be useful to some other people checking this thread (like me). |
2.1.0 brings the concept of actions — see #28.
So far we have
clone
andremove
. I can think of a few others that might be useful:rename
— for moving files out of the way to prevent them being clobbered by clonereplace
— for replacing placeholder stuff in particular files, such as this TODO. Would need to come after a...prompt
— get some user input. terkelg/prompts has some nice conventions we could adopt.So you could do this sort of thing:
then if you had a package.json like
it would get filled in. Not fully baked (maybe the
replace
action should run in the context of the prompt?) but you get the idea. cc @mhkeller if you have thoughtsThe text was updated successfully, but these errors were encountered: