Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

do not fail bundles on warnings #2920

Merged
merged 1 commit into from
May 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/bundler/bundle_v2.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -1031,15 +1031,15 @@ 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;
}

try this.enqueueShadowEntryPoints();
this.waitForParse();
}

if (this.bundler.log.msgs.items.len > 0) {
if (this.bundler.log.hasErrors()) {
return error.BuildFailed;
}

Expand Down
2 changes: 1 addition & 1 deletion src/cli/build_command.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
49 changes: 33 additions & 16 deletions test/bundler/build.test.ts → test/bundler/api.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@
entrypoints: [join(import.meta.dir, "./fixtures/trivial/index.js")],
outdir: "/tmp/bun-build-test-read-out",
});
expect(await x.outputs.values().next().value?.text()).toMatchSnapshot();

Check failure on line 90 in test/bundler/api.test.ts

View workflow job for this annotation

GitHub Actions / Tests linux-x64

expect(received).toMatchSnapshot(expected)

Check failure on line 90 in test/bundler/api.test.ts

View workflow job for this annotation

GitHub Actions / Tests linux-x64-baseline

expect(received).toMatchSnapshot(expected)

Check failure on line 90 in test/bundler/api.test.ts

View workflow job for this annotation

GitHub Actions / Tests bun-darwin-x64-baseline

expect(received).toMatchSnapshot(expected)
Bun.gc(true);
});

Expand All @@ -102,7 +102,7 @@
expect(blob.size).toBeGreaterThan(1);
expect(blob.path).toBe("./index.js");
expect(blob.hash).toBeTruthy();
expect(blob.hash).toMatchSnapshot("hash");

Check failure on line 105 in test/bundler/api.test.ts

View workflow job for this annotation

GitHub Actions / Tests linux-x64

expect(received).toMatchSnapshot(expected)

Check failure on line 105 in test/bundler/api.test.ts

View workflow job for this annotation

GitHub Actions / Tests linux-x64-baseline

expect(received).toMatchSnapshot(expected)

Check failure on line 105 in test/bundler/api.test.ts

View workflow job for this annotation

GitHub Actions / Tests bun-darwin-x64-baseline

expect(received).toMatchSnapshot(expected)
expect(blob.kind).toBe("entry-point");
expect(blob.loader).toBe("jsx");
expect(blob.sourcemap).toBe(null);
Expand All @@ -123,7 +123,7 @@
expect(blob.size).toBeGreaterThan(1);
expect(blob.path).toBe("./hello");
expect(blob.hash).toBeTruthy();
expect(blob.hash).toMatchSnapshot("hash");

Check failure on line 126 in test/bundler/api.test.ts

View workflow job for this annotation

GitHub Actions / Tests linux-x64

expect(received).toMatchSnapshot(expected)

Check failure on line 126 in test/bundler/api.test.ts

View workflow job for this annotation

GitHub Actions / Tests linux-x64-baseline

expect(received).toMatchSnapshot(expected)

Check failure on line 126 in test/bundler/api.test.ts

View workflow job for this annotation

GitHub Actions / Tests bun-darwin-x64-baseline

expect(received).toMatchSnapshot(expected)
expect(blob.kind).toBe("entry-point");
expect(blob.loader).toBe("jsx");
expect(blob.sourcemap).toBe(null);
Expand All @@ -141,7 +141,7 @@
expect(blob.size).toBeGreaterThan(1);
expect(blob.path).toBe("./index.js");
expect(blob.hash).toBeTruthy();
expect(blob.hash).toMatchSnapshot("hash index.js");

Check failure on line 144 in test/bundler/api.test.ts

View workflow job for this annotation

GitHub Actions / Tests linux-x64

expect(received).toMatchSnapshot(expected)

Check failure on line 144 in test/bundler/api.test.ts

View workflow job for this annotation

GitHub Actions / Tests linux-x64-baseline

expect(received).toMatchSnapshot(expected)

Check failure on line 144 in test/bundler/api.test.ts

View workflow job for this annotation

GitHub Actions / Tests bun-darwin-x64-baseline

expect(received).toMatchSnapshot(expected)
expect(blob.kind).toBe("entry-point");
expect(blob.loader).toBe("jsx");
expect(blob.sourcemap).toBe(map);
Expand Down Expand Up @@ -198,16 +198,21 @@
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");

Check failure on line 207 in test/bundler/api.test.ts

View workflow job for this annotation

GitHub Actions / Tests linux-x64

expect(received).toMatchSnapshot(expected)

Check failure on line 207 in test/bundler/api.test.ts

View workflow job for this annotation

GitHub Actions / Tests linux-x64-baseline

expect(received).toMatchSnapshot(expected)

Check failure on line 207 in test/bundler/api.test.ts

View workflow job for this annotation

GitHub Actions / Tests bun-darwin-x64-baseline

expect(received).toMatchSnapshot(expected)
});

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();

Check failure on line 215 in test/bundler/api.test.ts

View workflow job for this annotation

GitHub Actions / Tests linux-x64

expect(received).toBeTruthy()

Check failure on line 215 in test/bundler/api.test.ts

View workflow job for this annotation

GitHub Actions / Tests linux-x64-baseline

expect(received).toBeTruthy()

Check failure on line 215 in test/bundler/api.test.ts

View workflow job for this annotation

GitHub Actions / Tests bun-darwin-x64-baseline

expect(received).toBeTruthy()
expect(response.headers.get("etag")).toMatchSnapshot("content-etag");
});

Expand All @@ -234,15 +239,27 @@
// 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();
});
});
16 changes: 16 additions & 0 deletions test/bundler/cli.test.ts
Original file line number Diff line number Diff line change
@@ -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.',
);
});
});
1 change: 1 addition & 0 deletions test/bundler/fixtures/jsx-warning/index.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
console.log(<div key={"123"} {...props} />);