Skip to content

Commit 5ac6f42

Browse files
committed
explicitly encode single-file vs multi-file to allow disambiguating at usage site
1 parent b0c1d97 commit 5ac6f42

File tree

4 files changed

+14
-5
lines changed

4 files changed

+14
-5
lines changed

src/core/jupyter/jupyter-embed.ts

+7-4
Original file line numberDiff line numberDiff line change
@@ -353,9 +353,9 @@ export async function replaceNotebookPlaceholders(
353353
};
354354
}
355355

356-
function resolveNbPath(input: string, path: string, context?: ProjectContext) {
356+
function resolveNbPath(input: string, path: string, context: ProjectContext) {
357357
// If this is a project, absolute means project relative
358-
if (context) {
358+
if (context.projectType === "multi-file") {
359359
const projectMatch = path.match(/^[\\/](.*)/);
360360
if (projectMatch) {
361361
return join(context.dir, projectMatch[1]);
@@ -368,8 +368,11 @@ function resolveNbPath(input: string, path: string, context?: ProjectContext) {
368368
if (isAbsolute(input)) {
369369
return join(dirname(input), path);
370370
} else {
371-
const baseDir = context ? context.dir : Deno.cwd();
372-
return join(baseDir, dirname(input), path);
371+
const baseDir = context.projectType === "multi-file"
372+
? context.dir
373+
: Deno.cwd();
374+
const result = join(baseDir, dirname(input), path);
375+
return result;
373376
}
374377
}
375378
}

src/project/project-context.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,7 @@ export async function projectContext(
287287
force,
288288
);
289289
},
290+
projectType: "multi-file",
290291
};
291292
if (type.formatExtras) {
292293
result.formatExtras = async (
@@ -300,7 +301,7 @@ export async function projectContext(
300301
} else {
301302
const { files, engines } = projectInputFiles(dir);
302303
debug(`projectContext: Found Quarto project in ${dir}`);
303-
const result = {
304+
const result: ProjectContext = {
304305
dir,
305306
engines,
306307
config: projectConfig,
@@ -326,6 +327,7 @@ export async function projectContext(
326327
);
327328
},
328329
notebookContext,
330+
projectType: "multi-file",
329331
};
330332
return result;
331333
}
@@ -364,6 +366,7 @@ export async function projectContext(
364366
force,
365367
);
366368
},
369+
projectType: "multi-file",
367370
};
368371
if (Deno.statSync(path).isDirectory) {
369372
const { files, engines } = projectInputFiles(originalDir);

src/project/types.ts

+2
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,8 @@ export interface ProjectContext {
7575
) => Promise<Record<string, Format>>;
7676

7777
environment: () => Promise<ProjectEnvironment>;
78+
79+
projectType: "single-file" | "multi-file";
7880
}
7981

8082
export interface ProjectFiles {

src/project/types/single-file/single-file.ts

+1
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ export function singleFileProjectContext(
4949
force,
5050
);
5151
},
52+
projectType: "single-file",
5253
};
5354
return result;
5455
}

0 commit comments

Comments
 (0)