Path: blob/main/package/src/common/dependencies/esbuild.ts
6451 views
/*1* esbuild.ts2*3* Copyright (C) 2020-2022 Posit Software, PBC4*/5import { ensureDirSync, existsSync } from "../../../../src/deno_ral/fs.ts";6import { dirname, join } from "../../../../src/deno_ral/path.ts";78import { unTar } from "../../util/tar.ts";9import { Dependency } from "./dependencies.ts";10import { which } from "../../../../src/core/path.ts";11import { Configuration } from "../config.ts";1213export function esBuild(version: string): Dependency {14// Handle the configuration for this dependency15const esBuildRelease = (16platformstr: string,17) => {18return {19filename: `esbuild-${platformstr}.tgz`,20url:21`https://registry.npmjs.org/@esbuild/${platformstr}/-/${platformstr}-${version}.tgz`,22configure: async (config: Configuration, path: string) => {23const file = config.os === "windows" ? "esbuild.exe" : "esbuild";24const vendor = Deno.env.get("QUARTO_VENDOR_BINARIES");25if (vendor === undefined || vendor === "true") {26// Remove existing dir27const dir = dirname(path);2829const targetDir = join(dir, config.arch);30ensureDirSync(targetDir);3132// extracts to package/bin33const esbuildDir = join(dir, `package`);34if (existsSync(esbuildDir)) {35Deno.removeSync(esbuildDir, { recursive: true });36}3738// Expand39await unTar(path);4041try {42// Move the file and cleanup43const intialPath = config.os === "windows"44? join(esbuildDir, file)45: join(esbuildDir, "bin", file);4647Deno.renameSync(48intialPath,49join(targetDir, file),50);51} finally {52if (existsSync(esbuildDir)) {53Deno.removeSync(esbuildDir, { recursive: true });54}55}56} else {57// verify that the binary is on PATH, but otherwise don't do anything58if (which(file) === undefined) {59throw new Error(60`${file} is not on PATH. Please install it and add it to PATH.`,61);62}63}64},65};66};6768return {69name: "esbuild javascript bundler",70bucket: "esbuild",71version,72architectureDependencies: {73"x86_64": {74"windows": esBuildRelease("win32-x64"),75"linux": esBuildRelease("linux-x64"),76"darwin": esBuildRelease("darwin-x64"),77},78"aarch64": {79"linux": esBuildRelease("linux-arm64"),80"darwin": esBuildRelease("darwin-arm64"),81},82},83};84}858687