Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@
options.pkg.name = pkgName;

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

Check warning on line 75 in src/index.js

View workflow job for this annotation

GitHub Actions / build (12.x)

Unexpected console statement

Check warning on line 75 in src/index.js

View workflow job for this annotation

GitHub Actions / build (14.x)

Unexpected console statement
'Warning: inline sourcemaps should only be used for debugging purposes.',
);
} else if (options.sourcemap === 'false') {
Expand Down Expand Up @@ -218,7 +218,7 @@
(await jsOrTs(cwd, 'index')) ||
module,
)
.map(file => glob(file))
.map(file => glob(file, { cwd }))
.forEach(file => input.push(...file));

return input;
Expand Down Expand Up @@ -645,7 +645,7 @@
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 648 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

Check warning on line 648 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
/** @type {import('rollup').Plugin} */
({
name: 'postprocessing',
Expand Down
48 changes: 48 additions & 0 deletions test/__snapshots__/index.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -1280,6 +1280,54 @@ exports[`fixtures build class-properties with microbundle 5`] = `
"
`;

exports[`fixtures build cli-entry-with-cwd with microbundle 1`] = `
"Used script: microbundle

Directory tree:

cli-entry
dist
cli-entry.esm.mjs
cli-entry.esm.mjs.map
cli-entry.js
cli-entry.js.map
cli-entry.umd.js
cli-entry.umd.js.map
package.json
src
one.js
two.js


Build \\"cli-entry\\" to dist:
187 B: cli-entry.js.gz
138 B: cli-entry.js.br
188 B: cli-entry.esm.mjs.gz
139 B: cli-entry.esm.mjs.br
272 B: cli-entry.umd.js.gz
202 B: cli-entry.umd.js.br"
`;

exports[`fixtures build cli-entry-with-cwd with microbundle 2`] = `6`;

exports[`fixtures build cli-entry-with-cwd with microbundle 3`] = `
"var r=function(){try{var r=arguments;return Promise.resolve([].slice.call(r).reduce(function(r,e){return r+e},0))}catch(r){return Promise.reject(r)}};export default function(){try{var e=arguments,t=[].slice.call(e);return Promise.resolve(r.apply(void 0,t)).then(function(e){return Promise.resolve(r.apply(void 0,t)).then(function(r){return[e,r]})})}catch(r){return Promise.reject(r)}}
//# sourceMappingURL=cli-entry.esm.mjs.map
"
`;

exports[`fixtures build cli-entry-with-cwd with microbundle 4`] = `
"var r=function(){try{var r=arguments;return Promise.resolve([].slice.call(r).reduce(function(r,e){return r+e},0))}catch(r){return Promise.reject(r)}};module.exports=function(){try{var e=arguments,t=[].slice.call(e);return Promise.resolve(r.apply(void 0,t)).then(function(e){return Promise.resolve(r.apply(void 0,t)).then(function(r){return[e,r]})})}catch(r){return Promise.reject(r)}};
//# sourceMappingURL=cli-entry.js.map
"
`;

exports[`fixtures build cli-entry-with-cwd with microbundle 5`] = `
"!function(e,r){\\"object\\"==typeof exports&&\\"undefined\\"!=typeof module?module.exports=r():\\"function\\"==typeof define&&define.amd?define(r):(e||self).cliEntry=r()}(this,function(){var e=function(){try{var e=arguments;return Promise.resolve([].slice.call(e).reduce(function(e,r){return e+r},0))}catch(e){return Promise.reject(e)}};return function(){try{var r=arguments,n=[].slice.call(r);return Promise.resolve(e.apply(void 0,n)).then(function(r){return Promise.resolve(e.apply(void 0,n)).then(function(e){return[r,e]})})}catch(e){return Promise.reject(e)}}});
//# sourceMappingURL=cli-entry.umd.js.map
"
`;

exports[`fixtures build css-modules--false with microbundle 1`] = `
"Used script: microbundle --no-sourcemap --css-modules false

Expand Down
3 changes: 3 additions & 0 deletions test/fixtures/cli-entry-with-cwd/cli-entry/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"name": "cli-entry"
}
5 changes: 5 additions & 0 deletions test/fixtures/cli-entry-with-cwd/cli-entry/src/one.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { two } from './two';

export default async function (...args) {
return [await two(...args), await two(...args)];
}
3 changes: 3 additions & 0 deletions test/fixtures/cli-entry-with-cwd/cli-entry/src/two.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export async function two(...args) {
return args.reduce((total, value) => total + value, 0);
}
6 changes: 6 additions & 0 deletions test/fixtures/cli-entry-with-cwd/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"name": "cli-entry-with-cwd",
"scripts": {
"build": "microbundle src/one.js --cwd ./cli-entry"
}
}
4 changes: 4 additions & 0 deletions tools/build-fixture.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ export const buildDirectory = async fixtureDir => {
await rimraf(resolve(`${fixturePath}/.rts2_cache_es`));
await rimraf(resolve(`${fixturePath}/.rts2_cache_umd`));

// Now that dirs have been cleared, reset the fixturePath back to the parent dir
if (fixtureDir.endsWith('-with-cwd')) {
fixturePath = resolve(FIXTURES_DIR, fixtureDir);
}
Comment on lines +59 to +62
Copy link
Collaborator Author

@rschristian rschristian Oct 24, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was super broken & went unnoticed for a long time.

Basically we make the assumption that a test fixture foo-with-cwd is testing --cwd ./foo, and to make sure we were clearing out past runs, set the fixture path to fixtures/foo-with-cwd/foo so that rimraf would clear out all test cases the same way. However, we never set this path back!

When it came time to get the build script & execute it, the CWD was /foo-with-cwd/foo... none of these nested directories actually had a build script defined, as it was meant to come from the parent, and so all of the -with-cwd tests were just running plain microbundle. The build script we provided for our tests was entirely ignored as the test was always ran from the incorrect working dir.

Easy fix though, we just have to reset it.

const script = await getBuildScript(fixturePath, DEFAULT_SCRIPT);

const prevDir = process.cwd();
Expand Down