-
Notifications
You must be signed in to change notification settings - Fork 5.4k
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
proposal: support a comprehensive meta-data file #3179
Comments
This comment has been minimized.
This comment has been minimized.
1 similar comment
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
@kitsonk Do you mean the I'm wondering how the permission system would work when running, e.g.:
with
More specifically, what would this mean:
Would it:
Edit - other options that come to mind:
|
Some other use cases:
|
The issue with this is that directories will end up looking like this:
As there isn't much info that would be provided in such a file, I'd like to propose that this information is instead embedded in the |
@brandonkal I agree. For the private artifactories, we definitely need a separate file for authentication and config purposes like Also, repeating the remote module URI in every single file is against DRY principle. So, I propose to have a different file to assign an alias name to each remote module. This way, we can have different implementation of each functionality as well. For instance:
instead of
Having this, modules can easily get replaced with the compatible ones just by keeping the alias name and changing the URI in the manifest file. (Like a dependency injection) We need to have a
|
@aliabolhassani You agree but then you suggest using a manifest file. I don't understand. What you describe is already possible with a importmap. |
@brandonkal The top module, exports the manifests to Deno. Since any application only needs one configuration like permission and artifactory, no need to have manifest files for every single Although, your suggestion in #3675, seems to be smart, but presenting configs as comments looks odd. An alternate way would be to behave configs using Triple-Slash Directives in TypeScript, like:
|
Is this metadata file supposed to be written by human? If it is, then I suggest Deno should support formats other than JSON file. |
@KSXGitHub I agree. The JSON regime has been a pain for so many. I would strongly advocate supporting the hjson file format. Relaxed syntax, fewer mistakes, more comments. See http://hjson.org. there is a rust implementation at https://crates.io/crates/serde-hjson An alternative is json5 from http://json5.org (https://crates.io/crates/json5) or even a .yml file (even if the indent things is a bit error-prone in my opinion) I guess it really depends on the speed of each implementation. |
@mathiasrw HJSON is not as complicated as YAML while supporting proper string indentation. Good choice. 👍 |
toml is another obvious candidate. IMO the way forward here is for someone to make a proof of concept as a deno installable script/separate repo, that way it could be battle tested prior to anything being included in mainline deno (I don't think we're close to that yet). |
I'm not a fan of this proposal for reasons stated above. This should really be implemented in userland. However if Deno implements this it should be JSON. HJSON doesn't really add much value. Write the config in whatever language you want and have it compile down to JSON before feeding it to the system. |
@hayd I'm not a big fan of TOML. It is quite obvious that this metadata file would have nested object, which is TOML weakness. Aside from that, indentation of multi-line string is not properly handled like in YAML and HJSON. |
I disagree. Deno supports TypeScript to avoid intermediate compilation steps. |
While TOML is preferable for some people, I believe there's still a lot of javascript users that aren't familiar with the syntax. I think JSON5 would be a great option. It's more flexible and robust than JSON while still remaining intuitive for javascript users. |
So write it in TypeScript... |
@KSXGitHub Good point regarding TOML. I must say I also like the idea that you can cenerate the file as regular .json, save it and it just works. @brandonkal I disagree. A config file like this will act like the package.json does for node - it will be hand edited often and removing dumb problems for users must be a goal for a new ecosystem. Why limit people from commenting in the config file? Why refusing to run because you added an extra Valid json is both valid hjson and json5 |
This first and then we can bike shed about which exts/syntax to support... |
The first step would be to consider what such a file would contain:
That about sums it up. That can all be contained in a 3-line comment at the top of my application code. So again, there is no value in duplicating package.json here. We don't need that. |
@brandonkal That is short-sighted. Config file is not for only Deno to read, but also for all kind of tools in the ecosystem to work with. Just like in Node.js, Config file is not read-only either, it can be modified by machine. Embed them as comments in code would lead to all kinds of problem, such as code style not being preserved. Furthermore, comments were never meant to be read. Using comments as config would be clumsy.
So you duplicate package.json 3 times instead? (importmap, tsconfig.json, |
Other tools have their own config files. Deno doesn't need a config file. You can try to have 10-20 tools reading and writing to the same config file, but that isn't scalable. It also encourages copy-and-paste. You are better off linking to your tsconfig.json which is required for other tools such as VSCode. package.json isn't scalable. It's the reason we have a seperate tsconfig.json. I understand you are familiar with package.json, but it is not something you should look to model. So that just leaves run arguments. It is trivial to write a tool that parses JSDoc and extracts Deno run arguments. Do you really want to litter your projects with yet another file, |
Please don't tell me you would use RegExp. |
Also, your suggestion would lock user to a particular file type: JavaScript/TypeScript while Deno can also run WASM. |
Nice try. I don't have anything more to add here. My point still stands: #3179 (comment)
Also, placing metadata in the entrypoint module does not lock people out of using WASM. |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
Goals:
Non-Goals:
|
I am against these. The former sounds like it will "break the current freedom and flexibility", as people can structure their projects however they want. Even if this is just a guideline and not a rule, people will feel coerced to use it over what they want, especially as the CLI itself is suggesting the structure. Also this will make people request a lot for an entry point, and at that point we might as well be package.json. We should add a generate subcommand that generates a meta-data file from given flags |
We want to take a step in the direction of a config file, but there is a lot of controversy. Therefore proposing the following minimal possible config:
|
@ry That would be a good minimal first pass, although I'd like to propose having a {
"compilerOptions": {
"jsxFactory": "h"
},
"lint": {
"ignore": ["testdata/"],
"rules": {
"tags": ["recommended"],
"include": [
"ban-untagged-todo"
]
}
},
"permissions": {
// it can take an allow list or a boolean, boolean is just to enable it for everything, allow list is self explanatory
"allow-run": "allow-list-goes-here",
"allow-read": true,
}
} This would be helpful as trying to run with as strict permissions as possible can make a command get pretty long, i.e deno run --allow-run="./testfiles/*" --allow-net="localhost:4044/api/*" --allow-hrtime --allow-plugins --allow-read="./logs/*" |
Some thoughts on the automatic-resolution.
I get this is probably coming from an "it should be easy to use" point of view, which is an understandable concern but I also think this has the potential to become problematic down the line.
|
@grian32 We're interested in solving this problem too, but we can't come to an agreement yet about how this would look. For example, what if you had two different programs |
@caspervonb There's no change to the module resolution in the MVP above. I agree about the permissions - but there's still some controversy about how they should be specified (especially when a project contains multiple entry points) - so I'd prefer to punt on that now and just nail down what we can agree on. |
Alright sounds good! On the different entrypoints, you could always just have two different |
Not really, because it leads to a situation described in: #3179 (comment) and then you'd have to configure |
Beeing able to write comments in this file would be great. (so not a strict json I hope) |
It will be strict, but you'll be able to use |
Oops, bad choice of words to use resolution in this context. I just meant "magically resolving a file" in general which in this case the default configuration file. Fair enough on punting 👍
Just throwing it out there, one option that is familiar to many is to do tsc style composable configurations. |
Please reconsider resolving implicit dependencies. If a file is not in the program’s input chain or cli call it should not be automatically pulled in. It will break a lot of Deno’s original promises for little benefit. If you look at the majority of programs, input comes from command-line arguments, environment variables and specific absolute config filepaths. Build tools are the exception but deno run is not that. I’ve found Deno to be most useful as a general scripting runtime. It’s enabled me to write one-off scripts and also build CI systems for non-JavaScript projects. A lot of power in a single TypeScript file. A lot less portable if I have to worry about a json file in any given directory. That’s just one example of a workflow that breaks if a file is automatically pulled into context. A breaking change.
This makes sense. |
Isn't there something of an attack vector here: a program run with write permissions could edit the |
write permissions can be granular; this would be in the user's hands to give the permissions they intend and want to give. |
It is definitely attack surface area though. |
I was generally thinking of dev experience and the fact that I just end up using |
The main goal of having a single config file has been achieved, and ideas like providing permissions in it have their own issues (like #12763). |
There is discussion around "lockfiles" and sub-resource integrity (see: #200).
There are also other "external" data that might be needed to describe a workload in Deno, like what the main module is, a custom TypeScript configuration, permissions and other command line options, import-maps, etc. While Deno should always just work without a meta data file, there are lots of use cases where external meta data is necessary or desired.
Providing a single file way of describing that meta data would be a desirable feature.
I propose the following:
.json
.json
file, it assumes that it adheres to the meta-data schema, meaning thatdeno run app.json
would read the meta data file and utilise that to determine how to cache and execute the app. This would also mean something likedeno run https://example.com/app.json
would also just work.As this proposal evolves, the definition of the schema would be detailed, but would include all the functional areas mentioned above. Specifically for the "lockfile" mechanism, if an application is loaded and the
.json
file is writable (local) and there is no cache of the hashes of the modules, then Deno will write out the hashes of all dependent modules to the file. Upon subsequent invocations where the cache of the hashes is present, Deno will validate that all modules loaded match that cache, and if they don't they will throw and the workload would terminate.Support a command like
deno write main.ts app.json
would scaffold out the meta data file, but not run the workload. Any arguments passed on the CLI could be automatically written to the file as well.The text was updated successfully, but these errors were encountered: