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

--footer esbuild & rollup style! #14396

Merged
merged 7 commits into from
Oct 8, 2024

Conversation

versecafe
Copy link
Contributor

@versecafe versecafe commented Oct 8, 2024

What does this PR do?

This implements the --footer flag for bun build adds the footer field to bun.d.ts BuildOptions, implements footer additions into the bundler and shifting the source-map start point to work correctly with footers

  • Documentation
  • Types changes
  • Code changes

How did you verify your code works?

Automated tests in + hand testing of sourcemap compatibility

  • I included a test for the new code, or existing tests cover it
  • I checked the lifetime of memory allocated to verify it's (1) freed and (2) only freed when it should be
  • I wrote TypeScript/JavaScript tests and they pass locally (bun-debug test test-file-name.test)

Examples

const enum LogLevel {
  INFO,
  WARN,
  ERROR,
}

function log(data: string, level: LogLevel) {
  switch (level) {
    case LogLevel.INFO:
      console.log(data);
      break;
    case LogLevel.WARN:
      console.warn(data);
      break;
    case LogLevel.ERROR:
      console.error(data);
      break;
  }
}

log("Hey what's good, not this it's broken", LogLevel.ERROR);
bun build index.ts --outdir=./dist --minify --footer="// made with love in SF" --sourcemap="external"
await Bun.build({
  entrypoints: ["./index.ts"],
  outdir: "./dist",
  minify: true,
  sourcemap: "linked",
  footer: "// made with love in SF",
});

Both of these result in

function e(o,s){switch(s){case 0:console.log(o);break;case 1:console.warn(o);break;case 2:console.error(o);break}}e("Hey what's good, not this it's broken",2);

// made with love in SF

//# debugId=D6C4F8A4A7CB8B9F64756E2164756E21
//# sourceMappingURL=index.js.map
{
  "version": 3,
  "sources": ["../index.ts"],
  "sourcesContent": [
    "const enum LogLevel {\n  INFO,\n  WARN,\n  ERROR,\n}\n\nfunction log(data: string, level: LogLevel) {\n  switch (level) {\n    case LogLevel.INFO:\n      console.log(data);\n      break;\n    case LogLevel.WARN:\n      console.warn(data);\n      break;\n    case LogLevel.ERROR:\n      console.error(data);\n      break;\n  }\n}\n\nlog(\"Hey what's good, not this it's broken\", LogLevel.ERROR);\n"
  ],
  "mappings": "AAMA,SAAS,CAAG,CAAC,EAAc,EAAiB,CAC1C,OAAQ,OACD,GACH,QAAQ,IAAI,CAAI,EAChB,UACG,GACH,QAAQ,KAAK,CAAI,EACjB,UACG,GACH,QAAQ,MAAM,CAAI,EAClB,OAIN,EAAI,wCAAyC,CAAc",
  "debugId": "D6C4F8A4A7CB8B9F64756E2164756E21",
  "names": []
}

This also allows nice things like automatic copyright statements

await Bun.build({
  entrypoints: ["./index.ts"],
  outdir: "./dist",
  minify: true,
  sourcemap: "linked",
  footer: `/**
 * This is copyright of [...] ${new Date().getFullYear()}
 * do not redistribute without consent of [...]
*/`,
});
function e(o,s){switch(s){case 0:console.log(o);break;case 1:console.warn(o);break;case 2:console.error(o);break}}e("Hey what's good, not this it's broken",2);

/**
 * This is copyright of [...] 2024
 * do not redistribute without consent of [...]
*/

//# debugId=49D4166E8D5C94DD64756E2164756E21
//# sourceMappingURL=index.js.map

test/bundler/bundler_footer.test.ts Outdated Show resolved Hide resolved
@Jarred-Sumner Jarred-Sumner merged commit 7996d06 into oven-sh:main Oct 8, 2024
23 of 25 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants