Skip to content

Commit b48c3d2

Browse files
committed
Warn and skip preview build when npm is missing during configure
Check for npm at the start of configure() instead of failing late in buildQuartoPreviewJs() after ~300MB of downloads. When npm is missing, emit a warning explaining that the quarto preview live-reload feature will not be available, then skip the quarto-preview.js build step. The rest of Quarto (render, pdf, publish) builds and runs normally.
1 parent d5c1f1d commit b48c3d2

1 file changed

Lines changed: 22 additions & 6 deletions

File tree

package/src/common/configure.ts

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,25 @@ import {
1818
configureDependency,
1919
kDependencies,
2020
} from "./dependencies/dependencies.ts";
21-
import { suggestUserBinPaths } from "../../../src/core/path.ts";
21+
import { suggestUserBinPaths, which } from "../../../src/core/path.ts";
2222
import { buildQuartoPreviewJs } from "./previewjs.ts";
2323
import { isWindows } from "../../../src/deno_ral/platform.ts";
2424

2525
export async function configure(
2626
config: Configuration,
2727
) {
28+
// npm is only required for building quarto-preview.js (used by `quarto preview`
29+
// for HTML/revealjs live-reload). Warn upfront so the user knows before the
30+
// long dependency downloads; the JS build is skipped below if npm is missing.
31+
const hasNpm = (await which("npm")) !== undefined;
32+
if (!hasNpm) {
33+
warning(
34+
"npm not found on PATH. The 'quarto preview' live-reload feature " +
35+
"will not be available. Install Node.js (which provides npm) and " +
36+
"re-run configure to enable it.",
37+
);
38+
}
39+
2840
// Download dependencies
2941
for (const dependency of kDependencies) {
3042
const targetDir = join(
@@ -34,12 +46,16 @@ export async function configure(
3446
await configureDependency(dependency, targetDir, config);
3547
}
3648

37-
info("Building quarto-preview.js...");
38-
const result = buildQuartoPreviewJs(config.directoryInfo.src);
39-
if (!result.success) {
40-
throw new Error();
49+
if (hasNpm) {
50+
info("Building quarto-preview.js...");
51+
const result = buildQuartoPreviewJs(config.directoryInfo.src);
52+
if (!result.success) {
53+
throw new Error();
54+
}
55+
info("Build completed.");
56+
} else {
57+
info("Skipping quarto-preview.js build (npm not found).");
4158
}
42-
info("Build completed.");
4359

4460
// Move the quarto script into place
4561
info("Placing Quarto script");

0 commit comments

Comments
 (0)