Skip to content

Commit 958d438

Browse files
Fix create/create-project commands to initialize engines before validation
- Fix timing issues where both create commands attempted to use engines before they were registered. - Move engine initialization to start of action handlers and fix create-project to use current directory (not non-existent project directory) when initializing engine registry. Co-Authored-By: Claude <[email protected]>
1 parent a8d9e76 commit 958d438

5 files changed

Lines changed: 29 additions & 7 deletions

File tree

src/command/create-project/cmd.ts

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { basename } from "../../deno_ral/path.ts";
99
import { Command } from "cliffy/command/mod.ts";
1010

1111
import { executionEngine, executionEngines } from "../../execute/engine.ts";
12+
import { initializeProjectContextAndEngines } from "../command-utils.ts";
1213

1314
import { projectCreate } from "../../project/project-create.ts";
1415
import {
@@ -26,7 +27,6 @@ const kProjectTypes = projectTypes();
2627
const kProjectTypeAliases = projectTypeAliases();
2728
const kProjectTypesAndAliases = [...kProjectTypes, ...kProjectTypeAliases];
2829

29-
const kExecutionEngines = executionEngines().reverse();
3030
const kEditorTypes = ["source", "visual"];
3131

3232
export const createProjectCommand = new Command()
@@ -48,15 +48,11 @@ export const createProjectCommand = new Command()
4848
)
4949
.option(
5050
"--engine <engine:string>",
51-
`Use execution engine (${kExecutionEngines.join(", ")})`,
51+
"Use execution engine (jupyter, knitr, markdown, ...)",
5252
{
5353
value: (value: string): string[] => {
5454
value = value || kMarkdownEngine;
55-
const engine = executionEngine(value.split(":")[0]);
56-
if (!engine) {
57-
throw new Error(`Unknown --engine: ${value}`);
58-
}
59-
// check for kernel
55+
// Parse engine:kernel syntax
6056
const match = value.match(/(\w+)(:(.+))?$/);
6157
if (match) {
6258
return [match[1], match[3]];
@@ -132,12 +128,28 @@ export const createProjectCommand = new Command()
132128
)
133129
// deno-lint-ignore no-explicit-any
134130
.action(async (options: any, dir?: string) => {
131+
// Initialize project context and register engines (including external ones)
132+
await initializeProjectContextAndEngines();
133+
135134
if (dir === undefined || dir === ".") {
136135
dir = Deno.cwd();
137136
}
138137

139138
const engine = options.engine || [];
140139

140+
// Validate the engine (after engines are initialized)
141+
if (engine[0]) {
142+
const engineInstance = executionEngine(engine[0]);
143+
if (!engineInstance) {
144+
throw new Error(
145+
`Unknown execution engine: ${engine[0]}. ` +
146+
`Available engines: ${
147+
executionEngines().map((e) => e.name).join(", ")
148+
}`,
149+
);
150+
}
151+
}
152+
141153
const envPackages = typeof (options.withVenv) === "string"
142154
? options.withVenv.split(",").map((pkg: string) => pkg.trim())
143155
: typeof (options.withCondaenv) === "string"

src/command/create/cmd.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import {
1313
isPositWorkbench,
1414
} from "../../core/platform.ts";
1515
import { runningInCI } from "../../core/ci-info.ts";
16+
import { initializeProjectContextAndEngines } from "../command-utils.ts";
1617

1718
import { Command } from "cliffy/command/mod.ts";
1819
import { prompt, Select, SelectValueOptions } from "cliffy/prompt/mod.ts";
@@ -52,6 +53,9 @@ export const createCommand = new Command()
5253
type?: string,
5354
...commands: string[]
5455
) => {
56+
// Initialize engines before any artifact creation
57+
await initializeProjectContextAndEngines();
58+
5559
if (options.json) {
5660
await createFromStdin();
5761
} else {
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
/.quarto/
22
*_cache/
3+
4+
**/*.quarto_ipynb

tests/docs/project/site/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
/.quarto/
22
*_cache/
3+
4+
**/*.quarto_ipynb
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
11
/.quarto/
2+
3+
**/*.quarto_ipynb

0 commit comments

Comments
 (0)