From 982ef9adb80a9058b2bec81034af98673195868a Mon Sep 17 00:00:00 2001 From: Sarangan Rajamanickam Date: Fri, 12 Jul 2024 10:36:31 -0700 Subject: [PATCH] Move @typespec/compiler from dependencies to peerDependencies (#3699) Per the requirement in Issue: https://github.com/microsoft/typespec/issues/3632, the dependency of `@typespec/compiler` has to be moved from `dependencies` to `peerDependencies`. This PR moves the dependency. --- .chronus/changes/Issue3632-2024-6-12-17-16-46.md | 7 +++++++ packages/compiler/src/init/scaffold.ts | 12 ++++++++---- packages/compiler/test/init/init-template.test.ts | 12 +++++++++--- 3 files changed, 24 insertions(+), 7 deletions(-) create mode 100644 .chronus/changes/Issue3632-2024-6-12-17-16-46.md diff --git a/.chronus/changes/Issue3632-2024-6-12-17-16-46.md b/.chronus/changes/Issue3632-2024-6-12-17-16-46.md new file mode 100644 index 0000000000..0919a14885 --- /dev/null +++ b/.chronus/changes/Issue3632-2024-6-12-17-16-46.md @@ -0,0 +1,7 @@ +--- +changeKind: feature +packages: + - "@typespec/compiler" +--- + +Moved compiler dependencies to peer and dev for scaffolded projects. \ No newline at end of file diff --git a/packages/compiler/src/init/scaffold.ts b/packages/compiler/src/init/scaffold.ts index f89e43e5ca..01ff047663 100644 --- a/packages/compiler/src/init/scaffold.ts +++ b/packages/compiler/src/init/scaffold.ts @@ -104,21 +104,25 @@ async function writePackageJson(host: CompilerHost, config: ScaffoldingConfig) { if (isFileSkipGeneration("package.json", config.template.files ?? [])) { return; } - const dependencies: Record = {}; + const peerDependencies: Record = {}; + const devDependencies: Record = {}; if (!config.template.skipCompilerPackage) { - dependencies["@typespec/compiler"] = "latest"; + peerDependencies["@typespec/compiler"] = "latest"; + devDependencies["@typespec/compiler"] = "latest"; } for (const library of config.libraries) { - dependencies[library.name] = await getLibraryVersion(library); + peerDependencies[library.name] = await getLibraryVersion(library); + devDependencies[library.name] = await getLibraryVersion(library); } const packageJson: NodePackage = { name: config.name, version: "0.1.0", type: "module", - dependencies, + peerDependencies, + devDependencies, private: true, }; diff --git a/packages/compiler/test/init/init-template.test.ts b/packages/compiler/test/init/init-template.test.ts index d76f430223..0cc94165b9 100644 --- a/packages/compiler/test/init/init-template.test.ts +++ b/packages/compiler/test/init/init-template.test.ts @@ -2,11 +2,11 @@ import { deepStrictEqual, strictEqual } from "assert"; import { beforeEach, describe, it } from "vitest"; import { InitTemplate } from "../../src/init/init-template.js"; import { - makeScaffoldingConfig, ScaffoldingConfig, + makeScaffoldingConfig, scaffoldNewProject, } from "../../src/init/scaffold.js"; -import { createTestHost, resolveVirtualPath, TestHost } from "../../src/testing/index.js"; +import { TestHost, createTestHost, resolveVirtualPath } from "../../src/testing/index.js"; describe("compiler: init: templates", () => { let testHost: TestHost; @@ -44,7 +44,13 @@ describe("compiler: init: templates", () => { libraries: [{ name: "foo", version: "~1.2.3" }, { name: "bar" }], }); - deepStrictEqual(JSON.parse(getOutputFile("package.json")!).dependencies, { + deepStrictEqual(JSON.parse(getOutputFile("package.json")!).peerDependencies, { + "@typespec/compiler": "latest", + foo: "~1.2.3", + bar: "latest", + }); + + deepStrictEqual(JSON.parse(getOutputFile("package.json")!).devDependencies, { "@typespec/compiler": "latest", foo: "~1.2.3", bar: "latest",