Skip to content

Commit 83e6fd3

Browse files
committed
refactor single-file field
1 parent 5ac6f42 commit 83e6fd3

File tree

4 files changed

+7
-40
lines changed

4 files changed

+7
-40
lines changed

src/core/jupyter/jupyter-embed.ts

+2-4
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,7 @@ export async function replaceNotebookPlaceholders(
355355

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

src/project/project-context.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ export async function projectContext(
287287
force,
288288
);
289289
},
290-
projectType: "multi-file",
290+
isSingleFile: false,
291291
};
292292
if (type.formatExtras) {
293293
result.formatExtras = async (
@@ -327,7 +327,7 @@ export async function projectContext(
327327
);
328328
},
329329
notebookContext,
330-
projectType: "multi-file",
330+
isSingleFile: false,
331331
};
332332
return result;
333333
}
@@ -366,7 +366,7 @@ export async function projectContext(
366366
force,
367367
);
368368
},
369-
projectType: "multi-file",
369+
isSingleFile: false,
370370
};
371371
if (Deno.statSync(path).isDirectory) {
372372
const { files, engines } = projectInputFiles(originalDir);

src/project/types.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ export interface ProjectContext {
7676

7777
environment: () => Promise<ProjectEnvironment>;
7878

79-
projectType: "single-file" | "multi-file";
79+
isSingleFile: boolean;
8080
}
8181

8282
export interface ProjectFiles {

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

+1-32
Original file line numberDiff line numberDiff line change
@@ -49,38 +49,7 @@ export function singleFileProjectContext(
4949
force,
5050
);
5151
},
52-
projectType: "single-file",
52+
isSingleFile: true,
5353
};
5454
return result;
5555
}
56-
57-
// export interface ProjectContext {
58-
// dir: string;
59-
// engines: string[];
60-
// files: ProjectFiles;
61-
// config?: ProjectConfig;
62-
// notebookContext: NotebookContext;
63-
// outputNameIndex?: Map<string, { file: string; format: Format } | undefined>;
64-
65-
// // This is a cache of the engine and target for a given filename
66-
// engineAndTargetCache?: Map<
67-
// string,
68-
// { engine: ExecutionEngine; target: ExecutionTarget }
69-
// >;
70-
71-
// formatExtras?: (
72-
// source: string,
73-
// flags: PandocFlags,
74-
// format: Format,
75-
// services: RenderServices,
76-
// ) => Promise<FormatExtras>;
77-
78-
// renderFormats: (
79-
// file: string,
80-
// services: RenderServices,
81-
// to?: string,
82-
// project?: ProjectContext,
83-
// ) => Promise<Record<string, Format>>;
84-
85-
// environment: () => Promise<ProjectEnvironment>;
86-
// }

0 commit comments

Comments
 (0)