diff --git a/apps/wing/fixtures/invalid6/lib.w b/apps/wing/fixtures/invalid6/lib.w new file mode 100644 index 00000000000..e69de29bb2d diff --git a/apps/wing/fixtures/invalid6/package.json b/apps/wing/fixtures/invalid6/package.json new file mode 100644 index 00000000000..8ce3fa12dca --- /dev/null +++ b/apps/wing/fixtures/invalid6/package.json @@ -0,0 +1,13 @@ +{ + "name": "invalid6", + "version": "0.0.0", + "description": "description", + "author": "author", + "license": "MIT", + "files": [ + "**/*.ts" + ], + "dependencies": { + "some-dependency": "^1.0.0" + } +} diff --git a/apps/wing/fixtures/invalid6/util.ts b/apps/wing/fixtures/invalid6/util.ts new file mode 100644 index 00000000000..11dd2c2f1d5 --- /dev/null +++ b/apps/wing/fixtures/invalid6/util.ts @@ -0,0 +1,3 @@ +export function add(x: number, y: number): number { + return x + y; +} 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 189a5081522..2b658d27ae7 100644 --- a/apps/wing/src/commands/pack.test.ts +++ b/apps/wing/src/commands/pack.test.ts @@ -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: // { diff --git a/apps/wing/src/commands/pack.ts b/apps/wing/src/commands/pack.ts index 72193eb6b22..3929a82e17b 100644 --- a/apps/wing/src/commands/pack.ts +++ b/apps/wing/src/commands/pack.ts @@ -120,6 +120,13 @@ export async function pack(options: PackageOptions = {}): Promise { } } + // 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));