From d80f68f8817045d1541ddcdb27df2dcbb708a142 Mon Sep 17 00:00:00 2001 From: Gary Sassano <10464497+garysassano@users.noreply.github.com> Date: Fri, 12 Apr 2024 19:36:08 +0200 Subject: [PATCH] add test for empty `dependencies` in `package.json` --- apps/wing/fixtures/valid1/package.json | 3 +- apps/wing/src/commands/pack.test.ts | 42 ++++++++++++++++++++++++++ apps/wing/src/commands/pack.ts | 4 +-- 3 files changed, 46 insertions(+), 3 deletions(-) diff --git a/apps/wing/fixtures/valid1/package.json b/apps/wing/fixtures/valid1/package.json index f9ac31ccc0d..f5beb574ad2 100644 --- a/apps/wing/fixtures/valid1/package.json +++ b/apps/wing/fixtures/valid1/package.json @@ -6,5 +6,6 @@ "license": "MIT", "files": [ "**/*.ts" - ] + ], + "dependencies": {} } diff --git a/apps/wing/src/commands/pack.test.ts b/apps/wing/src/commands/pack.test.ts index 6be0b240367..5c8cf38c303 100644 --- a/apps/wing/src/commands/pack.test.ts +++ b/apps/wing/src/commands/pack.test.ts @@ -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: // { diff --git a/apps/wing/src/commands/pack.ts b/apps/wing/src/commands/pack.ts index a9bce0cc718..3929a82e17b 100644 --- a/apps/wing/src/commands/pack.ts +++ b/apps/wing/src/commands/pack.ts @@ -120,8 +120,8 @@ export async function pack(options: PackageOptions = {}): Promise { } } - // 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.` );