Skip to content

Commit

Permalink
add test for empty dependencies in package.json
Browse files Browse the repository at this point in the history
  • Loading branch information
garysassano committed Apr 12, 2024
1 parent d5ab3e9 commit d80f68f
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 3 deletions.
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": {}
}
42 changes: 42 additions & 0 deletions apps/wing/src/commands/pack.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,48 @@ describe("wing pack", () => {
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:
// {
// ...
// "files": [
// "**/*.ts"
// ]
// }

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

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

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

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

// check package.json has `dependencies`
if (pkgJson.dependencies) {
// 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.`
);
Expand Down

0 comments on commit d80f68f

Please sign in to comment.