@@ -29,21 +29,16 @@ export default async function run(args?: string[]) {
29
29
return ;
30
30
}
31
31
32
- const globalDocument = globalThis . document ;
33
- globalThis . document = new JSDOM ( ) . window . document ;
34
- try {
35
- for ( const positional of positionals ) {
36
- let url = new URL ( positional , "https://observablehq.com" ) ;
37
- if ( url . origin === "https://observablehq.com" ) {
38
- url = new URL ( `/document${ url . pathname . replace ( / ^ \/ d \/ / , "/" ) } ` , "https://api.observablehq.com" ) ;
39
- }
40
- const response = await fetch ( url ) ;
41
- if ( ! response . ok ) throw new Error ( `unable to fetch: ${ url } ` ) ;
42
- const { title , nodes } = await response . json ( ) ;
43
- for ( const node of nodes ) if ( node . mode === "js ") node . mode = "ojs ";
44
- process . stdout . write ( serialize ( toNotebook ( { title, cells : nodes } ) ) ) ;
32
+ const document = new JSDOM ( ) . window . document ;
33
+ for ( const positional of positionals ) {
34
+ let url = new URL ( positional , "https://observablehq.com" ) ;
35
+ if ( url . origin === "https://observablehq.com" ) {
36
+ url = new URL ( `/document${ url . pathname . replace ( / ^ \/ d \/ / , "/" ) } ` , "https://api.observablehq.com" ) ;
45
37
}
46
- } finally {
47
- globalThis. document = globalDocument ;
38
+ const response = await fetch ( url ) ;
39
+ if ( ! response . ok ) throw new Error ( `unable to fetch: ${ url } ` ) ;
40
+ const { title , nodes } = await response . json ( ) ;
41
+ for ( const node of nodes ) if ( node . mode === "js ") node . mode = "ojs ";
42
+ process . stdout . write ( serialize ( toNotebook ( { title, cells : nodes } ) , { document} ) ) ;
48
43
}
49
44
}
0 commit comments