Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
quarto-dev
GitHub Repository: quarto-dev/quarto-cli
Path: blob/main/package/src/util/deno.ts
6450 views
1
/*
2
* deno.ts
3
*
4
* Copyright (C) 2020-2022 Posit Software, PBC
5
*
6
*/
7
import { execProcess } from "../../../src/core/process.ts";
8
import { info } from "../../../src/deno_ral/log.ts";
9
import { isWindows } from "../../../src/deno_ral/platform.ts";
10
import { Configuration } from "../common/config.ts";
11
12
// TODO in we only use the bundler for quarto.ts
13
// so we hardcode it in the new esbuild-based bundler
14
export async function bundle(
15
configuration: Configuration,
16
) {
17
// Bundle source code
18
const denoBundleCmd: string[] = [];
19
const denoExecPath = Deno.env.get("QUARTO_DENO");
20
if (!denoExecPath) {
21
throw Error("QUARTO_DENO is not defined");
22
}
23
denoBundleCmd.push("run");
24
denoBundleCmd.push("--allow-all");
25
denoBundleCmd.push("../tools/deno-esbuild-bundle.ts");
26
/*
27
denoBundleCmd.push("--log-level");
28
denoBundleCmd.push("debug");
29
*/
30
// denoBundleCmd.push(input);
31
// denoBundleCmd.push(output);
32
33
const status = await execProcess({
34
cmd: denoExecPath,
35
args: denoBundleCmd,
36
cwd: configuration.directoryInfo.src,
37
});
38
if (status.code !== 0) {
39
throw Error(`Failure to bundle src/quarto.ts`);
40
}
41
}
42
43
export async function compile(
44
input: string,
45
output: string,
46
flags: string[],
47
configuration: Configuration,
48
) {
49
const denoBundleCmd: string[] = [];
50
const denoExecPath = Deno.env.get("QUARTO_DENO");
51
if (!denoExecPath) {
52
throw Error("QUARTO_DENO is not defined");
53
}
54
denoBundleCmd.push("compile");
55
denoBundleCmd.push("--unstable-kv");
56
denoBundleCmd.push("--unstable-ffi");
57
// --enable-experimental-regexp-engine is required for /regex/l, https://github.com/quarto-dev/quarto-cli/issues/9737
58
denoBundleCmd.push("--v8-flags=--enable-experimental-regexp-engine,--stack-trace-limit=100");
59
denoBundleCmd.push(
60
"--importmap=" + configuration.importmap,
61
);
62
denoBundleCmd.push("--output");
63
denoBundleCmd.push(output);
64
denoBundleCmd.push(...flags);
65
66
denoBundleCmd.push(input);
67
68
const status = await execProcess({
69
cmd: denoExecPath,
70
args: denoBundleCmd,
71
});
72
if (status.code !== 0) {
73
throw Error(`Failure to compile ${input}`);
74
}
75
}
76
export async function install(
77
input: string,
78
flags: string[],
79
configuration: Configuration,
80
) {
81
const denoBundleCmd: string[] = [];
82
const denoExecPath = Deno.env.get("QUARTO_DENO");
83
if (!denoExecPath) {
84
throw Error("QUARTO_DENO is not defined");
85
}
86
denoBundleCmd.push("install");
87
denoBundleCmd.push("--unstable-kv");
88
denoBundleCmd.push("--unstable-ffi");
89
denoBundleCmd.push(
90
"--importmap=" + configuration.importmap,
91
);
92
denoBundleCmd.push(...flags);
93
94
denoBundleCmd.push(input);
95
96
const status = await execProcess({
97
cmd: denoExecPath,
98
args: denoBundleCmd,
99
stdout: "piped",
100
});
101
if (status.code !== 0) {
102
throw Error(`Failure to install ${input}`);
103
}
104
if (status.stdout) {
105
// Forward the output
106
info(status.stdout);
107
108
const match = status.stdout.match(/Successfully installed.*\n(.*)/);
109
if (match) {
110
return match[1];
111
}
112
}
113
114
return undefined;
115
}
116
117
export function updateDenoPath(installPath: string, _config: Configuration) {
118
// Fix up the path to deno
119
if (installPath) {
120
info("Updating install script deno path");
121
const installTxt = Deno.readTextFileSync(installPath);
122
const denoExecPath = Deno.env.get("QUARTO_DENO");
123
if (!denoExecPath) {
124
throw Error("QUARTO_DENO is not defined");
125
}
126
const finalTxt = isWindows
127
? installTxt.replace(
128
/deno.exe /g,
129
denoExecPath + " ",
130
)
131
: installTxt.replace(
132
/deno /g,
133
denoExecPath + " ",
134
);
135
Deno.writeTextFileSync(
136
installPath,
137
finalTxt,
138
);
139
}
140
}
141
142