Skip to content

Commit

Permalink
Move @typespec/compiler from dependencies to peerDependencies (#3699)
Browse files Browse the repository at this point in the history
Per the requirement in Issue:
#3632, the dependency of
`@typespec/compiler` has to be moved from `dependencies` to
`peerDependencies`. This PR moves the dependency.
  • Loading branch information
sarangan12 authored Jul 12, 2024
1 parent ba65f90 commit 982ef9a
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 7 deletions.
7 changes: 7 additions & 0 deletions .chronus/changes/Issue3632-2024-6-12-17-16-46.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
changeKind: feature
packages:
- "@typespec/compiler"
---

Moved compiler dependencies to peer and dev for scaffolded projects.
12 changes: 8 additions & 4 deletions packages/compiler/src/init/scaffold.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,21 +104,25 @@ async function writePackageJson(host: CompilerHost, config: ScaffoldingConfig) {
if (isFileSkipGeneration("package.json", config.template.files ?? [])) {
return;
}
const dependencies: Record<string, string> = {};
const peerDependencies: Record<string, string> = {};
const devDependencies: Record<string, string> = {};

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,
};

Expand Down
12 changes: 9 additions & 3 deletions packages/compiler/test/init/init-template.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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",
Expand Down

0 comments on commit 982ef9a

Please sign in to comment.