Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
quarto-dev
GitHub Repository: quarto-dev/quarto-cli
Path: blob/main/package/src/common/validate-bundle.ts
6450 views
1
/*
2
* prepare-dist.ts
3
*
4
* Copyright (C) 2020-2022 Posit Software, PBC
5
*
6
*/
7
8
9
import { join } from "../../../src/deno_ral/path.ts";
10
import { info } from "../../../src/deno_ral/log.ts";
11
import { Configuration } from "../common/config.ts";
12
import { execProcess } from "../../../src/core/process.ts";
13
14
export async function validateBundle(
15
config: Configuration,
16
) {
17
const bugFinderDir = join(config.directoryInfo.tools, "bundle-bug-finder");
18
19
// Move the JS file
20
const targetJs = join(config.directoryInfo.pkgWorking.bin, "quarto.js");
21
22
const moveScriptDest = join(bugFinderDir, "quarto.js");
23
Deno.copyFileSync(targetJs, moveScriptDest);
24
25
const outFile = join(bugFinderDir, "bundle.js");
26
27
// Set the working dir to bug finder
28
Deno.chdir(bugFinderDir);
29
30
try {
31
32
// NPM Install
33
info("Installing Dependencies");
34
const npm = await execProcess({
35
cmd: "npm",
36
args: ["install"],
37
stderr: "piped"
38
});
39
if (!npm.success) {
40
throw new Error(npm.stderr);
41
}
42
info("");
43
44
// Create a new bundled output
45
info("Creating Test Bundle");
46
47
const files = [join(bugFinderDir, "_prelude.js"), targetJs];
48
files.forEach((file) => {
49
const text = Deno.readTextFileSync(file);
50
Deno.writeTextFileSync(outFile, text, {create: true, append: true});
51
})
52
info("");
53
54
// Test the bundled output
55
info("Testing Bundled output");
56
const npx = await execProcess({
57
cmd: "npx",
58
args: ["eslint", "bundle.js"],
59
stderr: "piped"
60
61
});
62
if (!npx.success) {
63
throw new Error(npx.stderr);
64
}
65
info("TEST: OK");
66
} finally {
67
const cleanupFiles = [moveScriptDest, outFile, "package-lock.json", "node_modules"];
68
cleanupFiles.forEach((file) => {
69
Deno.removeSync(file, {recursive: true});
70
})
71
72
}
73
}
74
75