Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
quarto-dev
GitHub Repository: quarto-dev/quarto-cli
Path: blob/main/package/src/common/dependencies/esbuild.ts
6451 views
1
/*
2
* esbuild.ts
3
*
4
* Copyright (C) 2020-2022 Posit Software, PBC
5
*/
6
import { ensureDirSync, existsSync } from "../../../../src/deno_ral/fs.ts";
7
import { dirname, join } from "../../../../src/deno_ral/path.ts";
8
9
import { unTar } from "../../util/tar.ts";
10
import { Dependency } from "./dependencies.ts";
11
import { which } from "../../../../src/core/path.ts";
12
import { Configuration } from "../config.ts";
13
14
export function esBuild(version: string): Dependency {
15
// Handle the configuration for this dependency
16
const esBuildRelease = (
17
platformstr: string,
18
) => {
19
return {
20
filename: `esbuild-${platformstr}.tgz`,
21
url:
22
`https://registry.npmjs.org/@esbuild/${platformstr}/-/${platformstr}-${version}.tgz`,
23
configure: async (config: Configuration, path: string) => {
24
const file = config.os === "windows" ? "esbuild.exe" : "esbuild";
25
const vendor = Deno.env.get("QUARTO_VENDOR_BINARIES");
26
if (vendor === undefined || vendor === "true") {
27
// Remove existing dir
28
const dir = dirname(path);
29
30
const targetDir = join(dir, config.arch);
31
ensureDirSync(targetDir);
32
33
// extracts to package/bin
34
const esbuildDir = join(dir, `package`);
35
if (existsSync(esbuildDir)) {
36
Deno.removeSync(esbuildDir, { recursive: true });
37
}
38
39
// Expand
40
await unTar(path);
41
42
try {
43
// Move the file and cleanup
44
const intialPath = config.os === "windows"
45
? join(esbuildDir, file)
46
: join(esbuildDir, "bin", file);
47
48
Deno.renameSync(
49
intialPath,
50
join(targetDir, file),
51
);
52
} finally {
53
if (existsSync(esbuildDir)) {
54
Deno.removeSync(esbuildDir, { recursive: true });
55
}
56
}
57
} else {
58
// verify that the binary is on PATH, but otherwise don't do anything
59
if (which(file) === undefined) {
60
throw new Error(
61
`${file} is not on PATH. Please install it and add it to PATH.`,
62
);
63
}
64
}
65
},
66
};
67
};
68
69
return {
70
name: "esbuild javascript bundler",
71
bucket: "esbuild",
72
version,
73
architectureDependencies: {
74
"x86_64": {
75
"windows": esBuildRelease("win32-x64"),
76
"linux": esBuildRelease("linux-x64"),
77
"darwin": esBuildRelease("darwin-x64"),
78
},
79
"aarch64": {
80
"linux": esBuildRelease("linux-arm64"),
81
"darwin": esBuildRelease("darwin-arm64"),
82
},
83
},
84
};
85
}
86
87