Skip to content

Commit

Permalink
enforce peerDependencies for winglibs
Browse files Browse the repository at this point in the history
  • Loading branch information
garysassano committed Apr 12, 2024
1 parent 1b71ae3 commit 1576729
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 0 deletions.
Empty file.
13 changes: 13 additions & 0 deletions apps/wing/fixtures/invalid6/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"name": "invalid6",
"version": "0.0.0",
"description": "description",
"author": "author",
"license": "MIT",
"files": [
"**/*.ts"
],
"dependencies": {
"some-dependency": "^1.0.0"
}
}
3 changes: 3 additions & 0 deletions apps/wing/fixtures/invalid6/util.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export function add(x: number, y: number): number {
return x + y;
}
15 changes: 15 additions & 0 deletions apps/wing/src/commands/pack.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,21 @@ describe("wing pack", () => {
await expectNoTarball(outdir);
});

it("throws an error if package.json uses dependencies instead of peerDependencies", async () => {
// GIVEN
const projectDir = join(fixturesDir, "invalid6");
const outdir = await generateTmpDir();
process.chdir(projectDir);

// WHEN
await expect(pack({ outFile: join(outdir, "tarball.tgz") })).rejects.toThrow(
/Wing libraries should use "peerDependencies" instead of "dependencies" in package.json/
);

// THEN
await expectNoTarball(outdir);
});

it("includes extra files specified by package.json", async () => {
// valid1's package.json contains this:
// {
Expand Down
7 changes: 7 additions & 0 deletions apps/wing/src/commands/pack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,13 @@ export async function pack(options: PackageOptions = {}): Promise<string> {
}
}

// check package.json has `dependencies`
if (pkgJson.dependencies) {
throw new Error(
`Wing libraries should use "peerDependencies" instead of "dependencies" in package.json.`
);
}

// move compiler output
await fs.rename(compilerOutputDir, path.join(workdir, compilerOutputFolder));

Expand Down

0 comments on commit 1576729

Please sign in to comment.