Skip to content

Commit 049772b

Browse files
committed
document quarto run workarounds for 1.6
1 parent 52f824d commit 049772b

File tree

2 files changed

+34
-3
lines changed

2 files changed

+34
-3
lines changed

docs/advanced/environment-vars.qmd

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,4 +68,7 @@ ENV["QUARTO_DOCUMENT_PATH"]
6868
| `QUARTO_PROFILE` | Profile used, e.g `QUARTO_PROFILE=advanced,production` for `quarto render --profile advanced,production` |
6969
+--------------------------------------------+----------------------------------------------------------------------------------------------------------+
7070
| `QUARTO_FIG_WIDTH` and `QUARTO_FIG_HEIGHT` | Values for `fig-width` and `fig-height` as set in the document metadata |
71-
+--------------------------------------------+----------------------------------------------------------------------------------------------------------+
71+
+--------------------------------------------+----------------------------------------------------------------------------------------------------------+
72+
| `QUARTO_RUN_NO_NETWORK` | When `true`, Quarto project scripts written in TypeScript won't be allowed to use the network to |
73+
| | download sources. In this setting, those scripts will not have access to the standard library. |
74+
+--------------------------------------------+----------------------------------------------------------------------------------------------------------+

docs/projects/scripts.qmd

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,8 @@ declared file as the destination of the file list that would have been written i
114114

115115
If you want to create project scripts with TypeScript, `quarto run` enables you to use the [Deno](https://deno.land/) TypeScript interpreter bundled with Quarto. This interpreter also includes much of Deno's [standard library](https://docs.deno.com/runtime/manual/basics/standard_library). For example, to use the Deno YAML parser you would do this:
116116

117+
### Quarto 1.6 breaking changes
118+
117119
::: callout-warning
118120

119121
Quarto 1.6 includes updates to Deno and Deno's standard library which forced us to make breaking changes to the import syntax. We apologize for the inconvenience.
@@ -127,7 +129,13 @@ import { parse } from "https://deno.land/std/yaml/mod.ts"; // Quarto 1.5 and ear
127129
const config = parse(Deno.readTextFileSync("_quarto.yml"));
128130
```
129131

130-
Although Deno hosts its standard library online, it's important to note that in both Quarto 1.6 and 1.5, the library is *not downloaded from a remote server* (in fact, importing from remote servers is disabled entirely in the Quarto Deno interpreter). Rather, the Deno standard library is shipped with Quarto, making standard library URLs available in an offline cache.
132+
Although Deno hosts its standard library online, it's important to note that in Quarto 1.5, the library is *not downloaded from a remote server* (in fact, importing from remote servers is disabled entirely in the Quarto Deno interpreter).
133+
Quarto 1.6 ships with a version of Deno that has an unfortunate interaction between its standard library and the feature that disables downloading the library from the remote servers.
134+
As a result, Quarto 1.6 might download some files (once, and then cache them) when the standard library is invoked.
135+
Future versions of Quarto will ship with Deno 2, which does not suffer from this issue.
136+
137+
If you want to enforce the behavior from Quarto 1.5, you can set the [environment variable](/docs/advanced/environment-vars.qmd) `QUARTO_RUN_NO_NETWORK` to `true`.
138+
Note that this means that the imports from `stdlib/` will not work in general.
131139

132140
You may come across example code that embeds versions directly in Deno library imports. For example:
133141

@@ -142,4 +150,24 @@ These version-bound imports **will not work** with Quarto (as its local standard
142150
import { format } from "stdlib/datetime";
143151
```
144152

145-
You may also see examples of Deno code that imports 3rd party libraries directly from URLs. As noted above, this functionality is not available in Quarto Deno scripts. Rather, you should download any external libraries you wish to use, include them with your project source code, and import them using relative file paths.
153+
You may also see examples of Deno code that imports 3rd party libraries directly from URLs.
154+
As noted above, this functionality is generally not available in Quarto Deno scripts.
155+
Rather, you should download any external libraries you wish to use, include them with your project source code, and import them using relative file paths.
156+
157+
### Making `.ts` scripts portable across multiple versions of Quarto
158+
159+
If you need your project or extension to both include TypeScript project scripts and work with Quarto 1.5 and 1.6, use the following technique:
160+
161+
``` typescript
162+
const multiImport = async (...sources: string[]) => {
163+
for (const source of sources) {
164+
try {
165+
return await import(source);
166+
} catch (e) {}
167+
}
168+
}
169+
const { readLines } = await multiImport(
170+
"stdlib/io", // Quarto 1.6 syntax
171+
"https://deno.land/std/io/mod.ts", // Quarto 1.5 syntax
172+
);
173+
```

0 commit comments

Comments
 (0)