You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This commit improves the ergonomics aroud importing/requiring scripts from
other files or blocks, while remaining backwards compatible with the existing
functionality in Datacore. The specifics of the changes are:
- Paths and wikilink-like strings passed to `dc.require()` will be checked
against all elements in the `scriptRoots` Setting if the path fails to resolve
against the vault root
- The `imports` transform is now enabled on the Sucrase `transform` operations. This
causes `import { foo } from "bar"` syntax to be transformed in to `const _foo = require("bar")` during
transpiling.
- The script transpilation pass will convert any `foo = require("bar")` statements in to the form
`foo = await dc.require("bar")` before evaluation. This covers both explicitly authored CommonJS require
syntax, as well as the output of the Sucrase transformation for ES Module imports.
- The script transpilation pass will resolve relative paths (e.g. `./foo`) against the script that called
`dc.require()`, allowing for relative imports to now be utilized. This happens as part of the same new
transform sa the one above that converts all `require` statements in to `dc.require` statements.
- The `imports` transform also allows for the use of the `export` keyword in scripts, which gets
transformed in to keys on an `exports` object.
- The `exports` object is injected via the context used to construct the `Function` evaluator.
- Scripts can now choose to either `return { ... }`, as is the current pattern, *or* they can use
`export`.
- Returned values take precedence over the exports object.
- Datacore code blocks that return a View to be rendered can now use `export default` by leveraging
the same effects introduced by the `imports` transform.
- Similarly to scripts loaded with `dc.require()`, the `return function ...` form is still supported.
- Also similarly to the above, the `return function ...` form is given precedence over the `export default` form.
0 commit comments