Mirror: Rollup plugin to automatically check the exports of a library for cjs-module-lexer compatibility.

Add filter depending on Rollup output format

Changed files
+18 -3
src
+18 -3
src/index.mjs
···
return {
name: "cjs-check",
async renderChunk(code, chunk) {
-
if (!filter(chunk.fileName)) {
return null;
-
} else if (!/\.c?js$/g.test(chunk.fileName)) {
return null;
}
await init()
-
const output = parse(code);
const missingReexports = [];
const missingExports = [];
···
return {
name: "cjs-check",
+
outputOptions(output) {
+
this.enabled = output.format === 'cjs' || output.format === 'umd';
+
return null;
+
},
+
async renderChunk(code, chunk) {
+
if (!this.enabled) {
+
return null;
+
} else if (!filter(chunk.fileName)) {
return null;
+
} else if (!chunk.exports || !chunk.exports.length) {
return null;
}
await init()
+
+
let output;
+
try {
+
output = parse(code);
+
} catch (error) {
+
this.warn(error);
+
return null;
+
}
+
const missingReexports = [];
const missingExports = [];