-
Notifications
You must be signed in to change notification settings - Fork 433
Expand file tree
/
Copy pathvalidate-bundle.ts
More file actions
80 lines (67 loc) · 2.07 KB
/
validate-bundle.ts
File metadata and controls
80 lines (67 loc) · 2.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
/*
* prepare-dist.ts
*
* Copyright (C) 2020-2022 Posit Software, PBC
*
*/
import { join } from "../../../src/deno_ral/path.ts";
import { info } from "../../../src/deno_ral/log.ts";
import { Configuration } from "../common/config.ts";
import { execProcess } from "../../../src/core/process.ts";
export async function validateBundle(
config: Configuration,
) {
const bugFinderDir = join(config.directoryInfo.tools, "bundle-bug-finder");
// Move the JS file
const targetJs = join(config.directoryInfo.pkgWorking.bin, "quarto.js");
const moveScriptDest = join(bugFinderDir, "quarto.js");
Deno.copyFileSync(targetJs, moveScriptDest);
const outFile = join(bugFinderDir, "bundle.js");
// Set the working dir to bug finder
Deno.chdir(bugFinderDir);
try {
// NPM Install
info("Installing Dependencies");
const npm = await execProcess({
cmd: "npm",
args: ["install"],
stderr: "piped"
});
if (!npm.success) {
throw new Error(npm.stderr);
}
info("");
// Create a new bundled output
info("Creating Test Bundle");
const files = [join(bugFinderDir, "_prelude.js"), targetJs];
files.forEach((file) => {
const text = Deno.readTextFileSync(file);
Deno.writeTextFileSync(outFile, text, {create: true, append: true});
})
info("");
// Test the bundled output
info("Testing Bundled output");
const npx = await execProcess({
cmd: "npx",
args: ["eslint", "bundle.js"],
stderr: "piped"
});
if (!npx.success) {
throw new Error(npx.stderr);
}
info("TEST: OK");
} finally {
const cleanupFiles = [moveScriptDest, outFile, "package-lock.json", "node_modules"];
cleanupFiles.forEach((file) => {
try {
Deno.removeSync(file, {recursive: true});
} catch (e) {
if (e instanceof Deno.errors.NotFound) {
// File may not exist if validation failed early
} else {
info(`Failed to remove cleanup file '${file}': ${e instanceof Error ? e.message : String(e)}`);
}
}
})
}
}