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

Expose a module's function names in modulemeta #2837

Merged
merged 2 commits into from
Aug 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion docs/content/manual/manual.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3633,7 +3633,8 @@ sections:

Takes a module name as input and outputs the module's metadata
as an object, with the module's imports (including metadata)
as an array value for the `deps` key.
as an array value for the `deps` key and the module's defined
functions as an array value for the `defs` key.

Programs can use this to query a module's metadata, which they
could then use to, for example, search for, download, and
Expand Down
2 changes: 1 addition & 1 deletion jq.1.prebuilt

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions src/linker.c
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,7 @@ jv load_module_meta(jq_state *jq, jv mod_relpath) {
if (jv_get_kind(meta) == JV_KIND_NULL)
meta = jv_object();
meta = jv_object_set(meta, jv_string("deps"), block_take_imports(&program));
meta = jv_object_set(meta, jv_string("defs"), block_list_funcs(program, 0));
}
locfile_free(src);
block_free(program);
Expand Down
10 changes: 7 additions & 3 deletions tests/jq.test
Original file line number Diff line number Diff line change
Expand Up @@ -1624,11 +1624,15 @@ jq: error: Import path must be constant at <top-level>, line 1:

modulemeta
"c"
{"whatever":null,"deps":[{"as":"foo","is_data":false,"relpath":"a"},{"search":"./","as":"d","is_data":false,"relpath":"d"},{"search":"./","as":"d2","is_data":false,"relpath":"d"},{"search":"./../lib/jq","as":"e","is_data":false,"relpath":"e"},{"search":"./../lib/jq","as":"f","is_data":false,"relpath":"f"},{"as":"d","is_data":true,"relpath":"data"}]}
{"whatever":null,"deps":[{"as":"foo","is_data":false,"relpath":"a"},{"search":"./","as":"d","is_data":false,"relpath":"d"},{"search":"./","as":"d2","is_data":false,"relpath":"d"},{"search":"./../lib/jq","as":"e","is_data":false,"relpath":"e"},{"search":"./../lib/jq","as":"f","is_data":false,"relpath":"f"},{"as":"d","is_data":true,"relpath":"data"}],"defs":["a/0","c/0"]}

modulemeta | .deps |= length
modulemeta | .deps | length
"c"
{"whatever":null,"deps":6}
6

modulemeta | .defs | length
"c"
2

%%FAIL IGNORE MSG
import "syntaxerror" as e; .
Expand Down