denoland / deno

A modern runtime for JavaScript and TypeScript.
https://deno.com
MIT License
93.4k stars 5.18k forks source link

map "deno run X" to "deno task X" if X is not a script #24307

Open ry opened 1 week ago

ry commented 1 week ago

will require changes across the stack to properly detect if module is not found. When I tried that before it didn't work well relying on just error message deno_graph and probably deno_npm need to return concrete error types and not be casted to a generic AnyError

yazan-abdalrahman commented 1 week ago

@ry

Hello, I'm trying to invistegate this featuer, maybe i can work on it. We need to see if the X 'deno execute X' is not a script by checking if it not has any endings with '.ts || .js' I will print a message to inform 'the X it was task not script' and then run 'deno task X', but from where it would search on task? I believe it should exist deno.json to specify the tasks.

do you have some behavior or expected logic of it task?

yazan-abdalrahman commented 1 week ago

@ry Can we modify the Custom Error in deno_core to return 'class' attribute that will help determine script not found? Then, if it is 'not found' and the flag it 'run', it will map it to task.

[cli\main.rs:347:7] &err = CustomError { class: "NotFound", message: "Module not found \"file:///D:/yad/deno/task/start\".", } ?

Please let me know whether I can use this solution or tell me what to expect.

BlackAsLight commented 1 week ago

We need to see if the X 'deno execute X' is not a script by checking if it not has any endings with '.ts || .js'

This method is flawed. A file doesn't need an extension or could have a different extension and still be valid JavaScript/TypeScript code.

then run 'deno task X', but from where it would search on task? I believe it should exist deno.json to specify the tasks.

Either deno.json or deno.jsonc

yazan-abdalrahman commented 1 week ago

We need to see if the X 'deno execute X' is not a script by checking if it not has any endings with '.ts || .js'

This method is flawed. A file doesn't need an extension or could have a different extension and still be valid JavaScript/TypeScript code.

then run 'deno task X', but from where it would search on task? I believe it should exist deno.json to specify the tasks.

Either deno.json or deno.jsonc

@BlackAsLight Hello, sure, I checked it yesterday and I know we can't use that method.

so,Can we modify the Custom Error in deno_core to return 'class' attribute that will help determine script not found? Then, if it is 'not found' and the flag it 'run', it will map it to task.

[cli\main.rs:347:7] &err = CustomError { class: "NotFound", message: "Module not found "file:///D:/yad/deno/task/start".", } ?

Please let me know whether I can use this solution or tell me what to expect.

wojpawlik commented 2 days ago

I'm against this. Letting deno run ignore permission flags and execute arbitrary shell commands undermines the sandbox. Why not just "Did you mean deno task <name>"?

yazan-abdalrahman commented 2 days ago

I'm against this. Letting deno run ignore permission flags and execute arbitrary shell commands undermines the sandbox. Why not just "Did you mean deno task <name>"?

The problem is that I have a task that is not a script. If there are no extensions, I will map it directly. or if this script does not exist, we will need to run it as a task, so we will try to run it first, and if we get a module not found error, we will try the task.?