Skip to content

Commit

Permalink
Merge of #6218
Browse files Browse the repository at this point in the history
  • Loading branch information
mergify[bot] authored Apr 12, 2024
2 parents 71e8fc7 + 01d0ab5 commit c50e81a
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 1 deletion.
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;
}
3 changes: 2 additions & 1 deletion apps/wing/fixtures/valid1/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@
"license": "MIT",
"files": [
"**/*.ts"
]
],
"dependencies": {}
}
35 changes: 35 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,41 @@ 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(
/Cannot create package with "dependencies" in package.json. Use "peerDependencies" instead./
);

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

it("includes empty dependencies in package.json", async () => {
// valid1's package.json contains this:
// {
// ...
// "dependencies": {}
// }

// GIVEN
const projectDir = join(fixturesDir, "valid1");
const outdir = await generateTmpDir();
process.chdir(projectDir);

// WHEN
await expect(pack({ outFile: join(outdir, "tarball.tgz") })).resolves.not.toThrow();

// THEN
const tarballContents = await extractTarball(join(outdir, "tarball.tgz"), outdir);
expect(tarballContents).toBeDefined();
});

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 if package.json has non-empty "dependencies"
if (pkgJson.dependencies && Object.keys(pkgJson.dependencies).length > 0) {
throw new Error(
`Cannot create package with "dependencies" in package.json. Use "peerDependencies" instead.`
);
}

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

Expand Down

0 comments on commit c50e81a

Please sign in to comment.