-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Closed
Description
Feature Use Case
When we write plugins or build tools using the JS API of Rollup, it would be nice to write in-memory e2e tests to check what is generated from a certain input. Now the Rollup codebase is hardwired with the node:fs
module, therefore we cannot replace it with an in-memory implementation like memfs
, to run our tools with in-memory representation of files, then verify the results.
Feature Proposal
Extend the InputOptions
interface with an optional fs
property, where it is possible to specify the file system module used for file operations in Rollup.
import { rollup } from 'rollup';
import { Volume } from 'memfs';
import assert from 'assert';
// Create an in-memory file system
const vol = Volume.fromJSON({
'/input.js': "export const message = 'Hello, Rollup!';"
});
async function build() {
// Create a Rollup bundle with custom fs
const bundle = await rollup({
input: '/input.js',
fs: vol // Hypothetical fs option
});
// Write bundle output to memory
await bundle.write({
file: '/output.js',
format: 'esm'
});
// Read from in-memory file system
const generatedCode = vol.readFileSync('/output.js', 'utf8');
console.log('Generated code:', generatedCode);
// Assert that the output is as expected
assert.strictEqual(generatedCode.trim(), "export const message = 'Hello, Rollup!';");
console.log('Assertion passed: Output is correct.');
}
build()