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

Crash with Bun.build()? #11079

Open
Valle12 opened this issue May 14, 2024 · 0 comments
Open

Crash with Bun.build()? #11079

Valle12 opened this issue May 14, 2024 · 0 comments
Labels
bundler Something to do with the bundler crash An issue that could cause a crash needs repro Needs an example to reproduce

Comments

@Valle12
Copy link

Valle12 commented May 14, 2024

How can we reproduce the crash?

If the parseBackground function is used, the crash appears

JavaScript/TypeScript code that reproduces the crash?

import manifestRead from "../manifest.config";
import packageJson from "../package.json";
import type { ContentScript, ManifestWrite } from "./types";
import { rm } from "fs/promises";
import * as path from "node:path";
const { version } = packageJson;

export class ManifestParser {
  constructor() {
    this.init();
  }

  async init() {
    this.clearDistFolder();

    let manifestWrite = manifestRead as ManifestWrite;
    this.addAttributes(manifestWrite);
    this.parseBackground(manifestWrite);
    this.parseContentScripts(manifestWrite);

    await Bun.write(
      "dist/manifest.json",
      JSON.stringify(manifestWrite, null, 2)
    );
  }

  addAttributes(manifest: ManifestWrite) {
    manifest.manifest_version = 3;
    manifest.version = version;

    let contentScript: ContentScript = {
      matches: ["<all_urls>"],
      js: ["src/reloader.ts"],
    };
    if (manifest.content_scripts == undefined) manifest.content_scripts = [];
    manifest.content_scripts.push(contentScript);
  }

  async parseBackground(manifest: ManifestWrite) {
    if (manifest.background == undefined) return;
    await Bun.build({
      entrypoints: [manifest.background.service_worker],
      minify: true,
      outdir: "dist/src",
      sourcemap: "external",
      target: "browser",
    });
  }

  async parseContentScripts(manifest: ManifestWrite) {
    if (manifest.content_scripts == undefined) return;
    for (let content_script of manifest.content_scripts) {
      if (content_script.js == undefined) continue;
      await Bun.build({
        entrypoints: content_script.js,
        minify: true,
        outdir: "dist/src",
        sourcemap: "external",
        target: "browser",
      });

      content_script.js = content_script.js.map((ele) =>
        ele.replace(".ts", ".js")
      );
    }
  }

  async clearDistFolder() {
    await rm("dist", {
      recursive: true,
      force: true,
    });
  }
}

Relevant log output

No response

Stack Trace (bun.report)

Bun v1.1.7 (b0b7db5) on windows x86_64 [RunCommand]

panic: attempt to use null value

@Valle12 Valle12 added the crash An issue that could cause a crash label May 14, 2024
@Electroid Electroid added needs repro Needs an example to reproduce bundler Something to do with the bundler labels May 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bundler Something to do with the bundler crash An issue that could cause a crash needs repro Needs an example to reproduce
Projects
None yet
Development

No branches or pull requests

2 participants