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/src/commands/pack.test.ts b/apps/wing/src/commands/pack.test.ts index 189a5081522..d65e0f0c323 100644 --- a/apps/wing/src/commands/pack.test.ts +++ b/apps/wing/src/commands/pack.test.ts @@ -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: // { diff --git a/apps/wing/src/commands/pack.ts b/apps/wing/src/commands/pack.ts index 72193eb6b22..c6566ad475b 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 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));