diff options
author | 2023-05-17 13:25:56 -0400 | |
---|---|---|
committer | 2023-05-17 10:25:56 -0700 | |
commit | f1b16cd36ade829c6b914086b49c83920bef5fb1 (patch) | |
tree | 558206af47c220c2f741e0581f1c46915bb5c105 | |
parent | bf1216021e77323a37872f3e58bad980660ea971 (diff) | |
download | bun-f1b16cd36ade829c6b914086b49c83920bef5fb1.tar.gz bun-f1b16cd36ade829c6b914086b49c83920bef5fb1.tar.zst bun-f1b16cd36ade829c6b914086b49c83920bef5fb1.zip |
do not fail bundles on warnings (#2920)
-rw-r--r-- | src/bundler/bundle_v2.zig | 8 | ||||
-rw-r--r-- | src/cli/build_command.zig | 2 | ||||
-rw-r--r-- | test/bundler/__snapshots__/api.test.ts.snap (renamed from test/bundler/__snapshots__/build.test.ts.snap) | 20 | ||||
-rw-r--r-- | test/bundler/api.test.ts (renamed from test/bundler/build.test.ts) | 49 | ||||
-rw-r--r-- | test/bundler/cli.test.ts | 16 | ||||
-rw-r--r-- | test/bundler/fixtures/jsx-warning/index.jsx | 1 |
6 files changed, 65 insertions, 31 deletions
diff --git a/src/bundler/bundle_v2.zig b/src/bundler/bundle_v2.zig index 7f2437619..dbf2025ba 100644 --- a/src/bundler/bundle_v2.zig +++ b/src/bundler/bundle_v2.zig @@ -1015,13 +1015,13 @@ pub const BundleV2 = struct { var this = try BundleV2.init(bundler, allocator, event_loop, enable_reloading, null, null); this.unique_key = unique_key; - if (this.bundler.log.msgs.items.len > 0) { + if (this.bundler.log.hasErrors()) { return error.BuildFailed; } this.graph.pool.pool.schedule(try this.enqueueEntryPoints(this.bundler.options.entry_points)); - if (this.bundler.log.msgs.items.len > 0) { + if (this.bundler.log.hasErrors()) { return error.BuildFailed; } @@ -1031,7 +1031,7 @@ pub const BundleV2 = struct { source_code_size.* = this.source_code_length; if (this.graph.use_directive_entry_points.len > 0) { - if (this.bundler.log.msgs.items.len > 0) { + if (this.bundler.log.hasErrors()) { return error.BuildFailed; } @@ -1039,7 +1039,7 @@ pub const BundleV2 = struct { this.waitForParse(); } - if (this.bundler.log.msgs.items.len > 0) { + if (this.bundler.log.hasErrors()) { return error.BuildFailed; } diff --git a/src/cli/build_command.zig b/src/cli/build_command.zig index 6609facac..957cbc9b7 100644 --- a/src/cli/build_command.zig +++ b/src/cli/build_command.zig @@ -232,7 +232,7 @@ pub const BuildCommand = struct { ctx.args, ); - if (log.msgs.items.len > 0) { + if (log.hasErrors()) { try log.printForLogLevel(Output.errorWriter()); if (result.errors.len > 0 or result.output_files.len == 0) { diff --git a/test/bundler/__snapshots__/build.test.ts.snap b/test/bundler/__snapshots__/api.test.ts.snap index e8ed56034..a91436aa3 100644 --- a/test/bundler/__snapshots__/build.test.ts.snap +++ b/test/bundler/__snapshots__/api.test.ts.snap @@ -42,7 +42,15 @@ NS.then(({ fn: fn2 }) => { " `; -exports[`Bun.build new Response(BuildArtifact): response text 1`] = ` +exports[`Bun.build BuildArtifact properties: hash 1`] = `"0b00cce4004e6308"`; + +exports[`Bun.build BuildArtifact properties + entry.naming: hash 1`] = `"0aa19aefb10c4ad2"`; + +exports[`Bun.build BuildArtifact properties sourcemap: hash index.js 1`] = `"0b00cce4004e6308"`; + +exports[`Bun.build BuildArtifact properties sourcemap: hash index.js.map 1`] = `"0000000000000000"`; + +exports[`Bun.build Bun.write(BuildArtifact) 1`] = ` "var __create = Object.create; var __descs = Object.getOwnPropertyDescriptors; var __defProp = Object.defineProperty; @@ -84,15 +92,7 @@ NS.then(({ fn: fn2 }) => { " `; -exports[`Bun.build BuildArtifact properties: hash 1`] = `"0b00cce4004e6308"`; - -exports[`Bun.build BuildArtifact properties + entry.naming: hash 1`] = `"0aa19aefb10c4ad2"`; - -exports[`Bun.build BuildArtifact properties sourcemap: hash index.js 1`] = `"0b00cce4004e6308"`; - -exports[`Bun.build BuildArtifact properties sourcemap: hash index.js.map 1`] = `"0000000000000000"`; - -exports[`Bun.build Bun.write(BuildArtifact) 1`] = ` +exports[`Bun.build new Response(BuildArtifact) sets content type: response text 1`] = ` "var __create = Object.create; var __descs = Object.getOwnPropertyDescriptors; var __defProp = Object.defineProperty; diff --git a/test/bundler/build.test.ts b/test/bundler/api.test.ts index 921481a4b..dee37dad5 100644 --- a/test/bundler/build.test.ts +++ b/test/bundler/api.test.ts @@ -198,15 +198,20 @@ describe("Bun.build", () => { Bun.gc(true); }); - test.skip("new Response(BuildArtifact)", async () => { + test("new Response(BuildArtifact) sets content type", async () => { const x = await Bun.build({ entrypoints: [join(import.meta.dir, "./fixtures/trivial/index.js")], }); - const response = new Response(x.outputs.values().next().value!); - expect(await response.text()).toMatchSnapshot("response text"); + const response = new Response(x.outputs[0]); expect(response.headers.get("content-type")).toBe("text/javascript;charset=utf-8"); - expect(response.headers.get("content-length")).toBeGreaterThan(1); - expect(response.headers.get("content-length")).toMatchSnapshot("content-length"); + expect(await response.text()).toMatchSnapshot("response text"); + }); + + test("new Response(BuildArtifact) sets etag", async () => { + const x = await Bun.build({ + entrypoints: [join(import.meta.dir, "./fixtures/trivial/index.js")], + }); + const response = new Response(x.outputs[0]); expect(response.headers.get("etag")).toBeTruthy(); expect(response.headers.get("etag")).toMatchSnapshot("content-etag"); }); @@ -234,15 +239,27 @@ describe("Bun.build", () => { // throw new Error("test was not fully written"); // }); - // test("errors are returned as an array", async () => { - // const x = await Bun.build({ - // entrypoints: [join(import.meta.dir, "does-not-exist.ts")], - // }); - // expect(x.errors).toHaveLength(1); - // expect(x.errors[0].message).toMatch(/ModuleNotFound/); - // expect(x.errors[0].name).toBe("BuildMessage"); - // expect(x.errors[0].position).toEqual(null); - // expect(x.warnings).toHaveLength(0); - // expect(x.logs).toHaveLength(0); - // }); + test("errors are returned as an array", async () => { + const x = await Bun.build({ + entrypoints: [join(import.meta.dir, "does-not-exist.ts")], + }); + expect(x.success).toBe(false); + expect(x.logs).toHaveLength(1); + expect(x.logs[0].message).toMatch(/ModuleNotFound/); + expect(x.logs[0].name).toBe("BuildMessage"); + expect(x.logs[0].position).toEqual(null); + }); + + test("warnings do not fail a build", async () => { + const x = await Bun.build({ + entrypoints: [join(import.meta.dir, "./fixtures/jsx-warning/index.jsx")], + }); + expect(x.success).toBe(true); + expect(x.logs).toHaveLength(1); + expect(x.logs[0].message).toBe( + '"key" prop before a {...spread} is deprecated in JSX. Falling back to classic runtime.', + ); + expect(x.logs[0].name).toBe("BuildMessage"); + expect(x.logs[0].position).toBeTruthy(); + }); }); diff --git a/test/bundler/cli.test.ts b/test/bundler/cli.test.ts new file mode 100644 index 000000000..e2f99a9ed --- /dev/null +++ b/test/bundler/cli.test.ts @@ -0,0 +1,16 @@ +import { bunEnv, bunExe } from "harness"; +import path from "path"; +import { describe, expect, test } from "bun:test"; + +describe("bun build", () => { + test("warnings dont return exit code 1", () => { + const { stderr, exitCode } = Bun.spawnSync({ + cmd: [bunExe(), "build", path.join(import.meta.dir, "./fixtures/jsx-warning/index.jsx")], + env: bunEnv, + }); + expect(exitCode).toBe(0); + expect(stderr.toString("utf8")).toContain( + 'warn: "key" prop before a {...spread} is deprecated in JSX. Falling back to classic runtime.', + ); + }); +}); diff --git a/test/bundler/fixtures/jsx-warning/index.jsx b/test/bundler/fixtures/jsx-warning/index.jsx new file mode 100644 index 000000000..22f02712d --- /dev/null +++ b/test/bundler/fixtures/jsx-warning/index.jsx @@ -0,0 +1 @@ +console.log(<div key={"123"} {...props} />); |