Skip to content

Commit

Permalink
Update Rollup config to hide known circular dependency warnings.
Browse files Browse the repository at this point in the history
  • Loading branch information
okaycj committed Oct 10, 2024
1 parent 1142a94 commit 118a3e8
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions rollup.mjs
Original file line number Diff line number Diff line change
@@ -1,8 +1,51 @@
/* eslint-disable func-style */

import { makeRollupConfig as jsPsychMakeRollupConfig } from "@jspsych/config/rollup";
import { iifeNameData } from "./packages/data/rollup.config.mjs";

/**
* Create rollup config for any package.
*
* @param iifeName - IIFE Name for this package
* @returns Rollup config
*/
export function makeRollupConfig(iifeName) {
const dataPackageName = "@lookit/data";

const knownCircularDeps = [
"@smithy/util-stream/dist-es/blob/Uint8ArrayBlobAdapter.js",
"@smithy/util-endpoints/dist-es/utils/callFunction.js",
"@smithy/util-endpoints/dist-es/utils/getEndpointProperties.js",
"@smithy/util-endpoints/dist-es/utils/evaluateRules.js",
"@aws-crypto/crc32/build/module/index.js",
"@aws-crypto/crc32c/build/module/index.js",
];

/**
* Change warnings into errors. This will help us catch build concerns before
* they are in production. Also, hide known circular dependency warnings. This is
* copied from Rollup's documentation:
* https://rollupjs.org/configuration-options/#onlog
*
* @param level - Message level
* @param log - Log object containing location, frame, and message.
* @param handler - Function called to record log.
*/
const onLog = (level, log, handler) => {
// Don't log known circular dependencies with the data package.
if (log.code === "CIRCULAR_DEPENDENCY" && iifeName === "chsData") {
if (knownCircularDeps.some((value) => log.message.includes(value))) {
return;
}
}

if (level === "warn") {
handler("error", log);
} else {
handler(level, log);
}
};

return jsPsychMakeRollupConfig(iifeName).map((config) => {
return {
...config,
Expand All @@ -18,6 +61,7 @@ export function makeRollupConfig(iifeName) {
},
};
}),
onLog,
};
});
}

0 comments on commit 118a3e8

Please sign in to comment.