Path: blob/main/package/src/common/validate-bundle.ts
6450 views
/*1* prepare-dist.ts2*3* Copyright (C) 2020-2022 Posit Software, PBC4*5*/678import { join } from "../../../src/deno_ral/path.ts";9import { info } from "../../../src/deno_ral/log.ts";10import { Configuration } from "../common/config.ts";11import { execProcess } from "../../../src/core/process.ts";1213export async function validateBundle(14config: Configuration,15) {16const bugFinderDir = join(config.directoryInfo.tools, "bundle-bug-finder");1718// Move the JS file19const targetJs = join(config.directoryInfo.pkgWorking.bin, "quarto.js");2021const moveScriptDest = join(bugFinderDir, "quarto.js");22Deno.copyFileSync(targetJs, moveScriptDest);2324const outFile = join(bugFinderDir, "bundle.js");2526// Set the working dir to bug finder27Deno.chdir(bugFinderDir);2829try {3031// NPM Install32info("Installing Dependencies");33const npm = await execProcess({34cmd: "npm",35args: ["install"],36stderr: "piped"37});38if (!npm.success) {39throw new Error(npm.stderr);40}41info("");4243// Create a new bundled output44info("Creating Test Bundle");4546const files = [join(bugFinderDir, "_prelude.js"), targetJs];47files.forEach((file) => {48const text = Deno.readTextFileSync(file);49Deno.writeTextFileSync(outFile, text, {create: true, append: true});50})51info("");5253// Test the bundled output54info("Testing Bundled output");55const npx = await execProcess({56cmd: "npx",57args: ["eslint", "bundle.js"],58stderr: "piped"5960});61if (!npx.success) {62throw new Error(npx.stderr);63}64info("TEST: OK");65} finally {66const cleanupFiles = [moveScriptDest, outFile, "package-lock.json", "node_modules"];67cleanupFiles.forEach((file) => {68Deno.removeSync(file, {recursive: true});69})7071}72}737475