Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Init logic bundle the compiler logic instead of shelling out to some random client #6086

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
break when loading templates
  • Loading branch information
timotheeguerin committed Feb 20, 2025
commit a0459800957a342252362c1c37b43930e1cf40f6
4 changes: 2 additions & 2 deletions packages/compiler/src/init/core-templates.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { CompilerPackageRoot } from "../core/node-host.js";
import { resolvePath } from "../core/path-utils.js";
import { CompilerHost } from "../index.js";
import type { SystemHost } from "../index.js";

export const templatesDir = resolvePath(CompilerPackageRoot, "templates");
export interface LoadedCoreTemplates {
@@ -9,7 +9,7 @@ export interface LoadedCoreTemplates {
}

let typeSpecCoreTemplates: LoadedCoreTemplates | undefined;
export async function getTypeSpecCoreTemplates(host: CompilerHost): Promise<LoadedCoreTemplates> {
export async function getTypeSpecCoreTemplates(host: SystemHost): Promise<LoadedCoreTemplates> {
if (typeSpecCoreTemplates === undefined) {
const file = await host.readFile(resolvePath(templatesDir, "scaffolding.json"));
const content = JSON.parse(file.text);
2 changes: 1 addition & 1 deletion packages/compiler/src/internals/init.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
// export { getTypeSpecCoreTemplates } from "../init/core-templates.js";
export { NodeSystemHost } from "../core/node-system-host.js";
export { getTypeSpecCoreTemplates } from "../init/core-templates.js";
export { scaffoldNewProject } from "../init/scaffold.js";
19 changes: 18 additions & 1 deletion packages/typespec-vscode/src/vscode-cmd/create-tsp-project.ts
Original file line number Diff line number Diff line change
@@ -4,7 +4,11 @@ import {
type InitProjectTemplateEmitterTemplate,
type InitProjectTemplateLibrarySpec,
} from "@typespec/compiler";
import { NodeSystemHost, scaffoldNewProject } from "@typespec/compiler/internals/init";
import {
getTypeSpecCoreTemplates,
NodeSystemHost,
scaffoldNewProject,
} from "@typespec/compiler/internals/init";
import { readdir } from "fs/promises";
import * as semver from "semver";
import vscode, { OpenDialogOptions, QuickPickItem } from "vscode";
@@ -559,6 +563,19 @@ async function loadInitTemplates(): Promise<Map<string, InitTemplateInfo[]>> {
logger.info("Loading init templates from compiler...");
const templateInfoMap: Map<string, InitTemplateInfo[]> = new Map();
logger.info("Loading init templates from config...");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this log is for the next step.

const templates = await getTypeSpecCoreTemplates(NodeSystemHost);
templateInfoMap.set(
COMPILER_CORE_TEMPLATES,
Object.entries(templates.templates)
.filter(([_key, value]) => value !== undefined)
.map(([key, value]) => ({
source: COMPILER_CORE_TEMPLATES,
sourceType: "compiler",
baseUrl: templates.baseUri,
name: key,
template: value,
})),
);
const settings = vscode.workspace
.getConfiguration()
.get<InitTemplatesUrlSetting[]>(SettingName.InitTemplatesUrls);
3 changes: 3 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Oops, something went wrong.