Skip to content

Commit f82b3d9

Browse files
committed
tolerate empty _quarto.yml file
1 parent e832bf6 commit f82b3d9

File tree

4 files changed

+18
-3
lines changed

4 files changed

+18
-3
lines changed

src/core/schema/validated-yaml.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ export async function readAndValidateYamlFromFile(
2323
file: string,
2424
schema: Schema,
2525
errorMessage: string,
26+
defaultContents?: string,
2627
): Promise<unknown> {
2728
if (!existsSync(file)) {
2829
throw new Error(`YAML file ${file} not found.`);
@@ -33,8 +34,13 @@ export async function readAndValidateYamlFromFile(
3334
shortFileName = relative(Deno.cwd(), shortFileName);
3435
}
3536

37+
let fileContents = Deno.readTextFileSync(file).trimEnd();
38+
if ((fileContents.trim().length === 0) && defaultContents) {
39+
fileContents = defaultContents;
40+
}
41+
3642
const contents = asMappedString(
37-
Deno.readTextFileSync(file).trimEnd(),
43+
fileContents,
3844
shortFileName,
3945
);
4046
const {

src/project/project-context.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ import { readAndValidateYamlFromFile } from "../core/schema/validated-yaml.ts";
7676

7777
import { getProjectConfigSchema } from "../core/lib/yaml-schema/project-config.ts";
7878
import { getFrontMatterSchema } from "../core/lib/yaml-schema/front-matter.ts";
79+
import { kDefaultProjectFileContents } from "./types/project-default.ts";
7980

8081
export function deleteProjectMetadata(metadata: Metadata) {
8182
// see if the active project type wants to filter the config printed
@@ -123,6 +124,7 @@ export async function projectContext(
123124
configFile,
124125
configSchema,
125126
errMsg,
127+
kDefaultProjectFileContents,
126128
)) as ProjectConfig;
127129
projectConfig.project = projectConfig.project || {};
128130
const includedMeta = await includedMetadata(

src/project/project-index.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,13 @@ import { fileExecutionEngine } from "../execute/engine.ts";
2727
import { projectConfigFile, projectOutputDir } from "./project-shared.ts";
2828
import { projectScratchPath } from "./project-scratch.ts";
2929
import { parsePandocTitle } from "../core/pandoc/pandoc-partition.ts";
30-
import { readYaml } from "../core/yaml.ts";
30+
import { readYamlFromString } from "../core/yaml.ts";
3131
import { formatKeys } from "../config/metadata.ts";
3232
import {
3333
formatsPreferHtml,
3434
normalizeWebsiteFormat,
3535
} from "./types/website/website-config.ts";
36+
import { kDefaultProjectFileContents } from "./types/project-default.ts";
3637

3738
export interface InputTargetIndex extends Metadata {
3839
title?: string;
@@ -119,7 +120,11 @@ export function readInputTargetIndex(
119120
const formats = Object.keys(index.formats);
120121
const projConfigFile = projectConfigFile(projectDir);
121122
if (projConfigFile) {
122-
const config = readYaml(projConfigFile) as Metadata;
123+
let contents = Deno.readTextFileSync(projConfigFile);
124+
if (contents.trim().length === 0) {
125+
contents = kDefaultProjectFileContents;
126+
}
127+
const config = readYamlFromString(contents) as Metadata;
123128
const projFormats = formatKeys(config);
124129
if (ld.isEqual(formats, projFormats)) {
125130
return index;

src/project/types/project-default.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ import { kJupyterEngine } from "../../execute/types.ts";
1212

1313
import { ProjectCreate, ProjectScaffoldFile, ProjectType } from "./types.ts";
1414

15+
export const kDefaultProjectFileContents = "{ project: { type: 'default' } }";
16+
1517
export const defaultProjectType: ProjectType = {
1618
type: "default",
1719

0 commit comments

Comments
 (0)