Skip to content
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Format debug build using prettier
  • Loading branch information
andrewiggins committed Oct 24, 2025
commit bf19e48f0db72a41d76adc9d1dc967142a7caaf3
6 changes: 2 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@
"lodash.merge": "^4.6.2",
"magic-string": "^0.25.9",
"postcss": "^8.2.1",
"prettier": "^2.2.1",
"pretty-bytes": "^5.4.1",
"rollup": "^2.35.1",
"rollup-plugin-bundle-size": "^1.0.3",
Expand Down Expand Up @@ -131,7 +132,6 @@
"jest": "^26.6.3",
"lint-staged": "^10.5.3",
"npm-merge-driver-install": "^1.1.1",
"prettier": "^2.2.1",
"regenerator-runtime": "^0.13.7",
"rimraf": "^3.0.2",
"shell-quote": "^1.7.2",
Expand Down
15 changes: 14 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import { shouldCssModules, cssModulesConfig } from './lib/css-modules';
import { EOL } from 'os';
import MagicString from 'magic-string';
import prettier from 'prettier';

// Extensions to use when resolving modules
const EXTENSIONS = ['.ts', '.tsx', '.js', '.jsx', '.es6', '.es', '.mjs'];
Expand Down Expand Up @@ -72,7 +73,7 @@
options.pkg.name = pkgName;

if (options.sourcemap === 'inline') {
console.log(

Check warning on line 76 in src/index.js

View workflow job for this annotation

GitHub Actions / build (14.x)

Unexpected console statement

Check warning on line 76 in src/index.js

View workflow job for this annotation

GitHub Actions / build (12.x)

Unexpected console statement
'Warning: inline sourcemaps should only be used for debugging purposes.',
);
} else if (options.sourcemap === 'false') {
Expand Down Expand Up @@ -653,14 +654,26 @@
options.visualize && visualizer(),
// NOTE: OMT only works with amd and esm
// Source: https://github.com/surma/rollup-plugin-off-main-thread#config
useWorkerLoader && (format === 'es' || modern) && OMT(),

Check warning on line 657 in src/index.js

View workflow job for this annotation

GitHub Actions / build (14.x)

A function with a name starting with an uppercase letter should only be used as a constructor

Check warning on line 657 in src/index.js

View workflow job for this annotation

GitHub Actions / build (12.x)

A function with a name starting with an uppercase letter should only be used as a constructor
/** @type {import('rollup').Plugin} */
({
name: 'postprocessing',
// Rollup 2 injects globalThis, which is nice, but doesn't really make sense for Microbundle.
// Only ESM environments necessitate globalThis, and UMD bundles can't be properly loaded as ESM.
// So we remove the globalThis check, replacing it with `this||self` to match Rollup 1's output:
renderChunk(code, chunk, opts) {
async renderChunk(code, chunk, opts) {
// Format debug builds with Prettier for better readability
if (format === 'debug') {
const formatted = prettier.format(code, {
parser: 'babel',
...pkg.prettier,
});
return {
code: formatted,
map: null,
};
}

if (opts.format === 'umd') {
// Can swap this out with MagicString.replace() when we bump it:
// https://github.com/developit/microbundle/blob/f815a01cb63d90b9f847a4dcad2a64e6b2f8596f/src/index.js#L657-L671
Expand Down
9 changes: 5 additions & 4 deletions test/__snapshots__/index.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -1750,8 +1750,8 @@ Build \\"debug-lib\\" to dist:
279 B: debug-lib.esm.mjs.br
415 B: debug-lib.umd.js.gz
343 B: debug-lib.umd.js.br
385 B: debug-lib.debug.js.gz
320 B: debug-lib.debug.js.br"
389 B: debug-lib.debug.js.gz
323 B: debug-lib.debug.js.br"
`;

exports[`fixtures build debug with microbundle 2`] = `8`;
Expand Down Expand Up @@ -1779,10 +1779,11 @@ class UserManager {
}

async loadUsers() {
const allUsers = await Promise.all(this.users.map(u => fetchUserData(u.id)));
const allUsers = await Promise.all(
this.users.map((u) => fetchUserData(u.id))
);
return allUsers;
}

}

export { UserManager, createGreeting, fetchUserData };
Expand Down