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
feat(cli): provide Deno.info() API #10758
Conversation
Shouldn't it also support usage without a specifier, just like the |
I'm not personally convinced of that. What would be a legitimate use case for having that type of information available programatically? |
One use case is together with #10589, so one could get access to the location of the localstorage file (and other apis that would store data based on the origin) |
What's your opinion on #10628, and maybe representing that change in advance with the runtime API? It would solve needing read permission to |
Knowing a location isn't a use case... 😄 What problem does that solve having that information available via an API.
Maybe. I get the reasoning for it, but it complicates the API surface and as noted in the issue, it isn't something to be considered until 2.0 and I would then expect the Deno APIs to reflect the subcommands. My opinion is we shouldn't wait until 2.0 to introduce this API (it already has quite a few real world use cases, especially with those using Deno as an on the fly transpiler/bundler). |
Well one example would be that one could make a backup by copying the file (useful for indexeddb) |
I have an example use-case with Docuraptor. |
I think any info provided under However I wouldn't be surprised if the runtime equivalents for |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry for slow review @kitsonk, I completely missed the request 🤦
I have only minor comments
* In order to resolve relative modules, import maps need a "base" which is | ||
* the import map itself. When an object is passed as a value the current | ||
* working directory for the Deno process will be used. */ | ||
importMap?: string | URL | ImportMap; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In case this is ImportMap
type - what is the "base URL" used for that import map?
* Similar to the command line functionality `deno info --json`, the API | ||
* provides information about a module and its dependencies. | ||
* | ||
* Requires `allow/read` permissions to access local modules and cached |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nitpick: change allow/read
to --allow-read
to keep consistent with other docs?
* checksums: true, | ||
* paths: true, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not provide these things by default?
#[serde(default)] | ||
checksums: bool, | ||
import_map: Option<StringOrImportMap>, | ||
#[serde(default)] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider adding Default
to derive instead?
let custom_root = std::env::var("DENO_DIR").map(String::into).ok(); | ||
let deno_dir = DenoDir::new(custom_root)?; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Skip reading env variable and use dir
field from ProgramState
instead?
match &options.import_map { | ||
Some(StringOrImportMap::ImportMap(value)) => { | ||
let cwd = std::env::current_dir()?; | ||
let base_url = resolve_path(cwd.to_string_lossy().as_ref())?; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To answer myself to previous question - in case of passing "object" import map it uses CWD as default URL, could you please add it to the JSDoc on the API?
Just as an input: instead of a enum DependencyType {
Import,
Export,
DynamicImport
} I ran into problems having just a dynamic flag when creating bundler. If one wants to add "Fetch" or some other type in the future, DependencyType can easily be extended. |
Closing due to https://deno.land/x/deno_graph/ being available. |
Resolves #2096
This is a work in progress PR. There are a couple of items still to address:
Deno.emit()
, but no one is happy with theDeno.emit()
solution, so we need to debate the best way to allow an import-map to be provided.I have implemented the import map in a more straight forward way and my opinion is that we should change
Deno.emit()
to follow. In addition I added two options that are off by default that suppress some sensitive data from being returned and documented the whole security implications of using the API. Flexing all the features looks something like this:Or with an import object literal, something like this: