Skip to content

Commit

Permalink
Hide circular dependency warnings (#59)
Browse files Browse the repository at this point in the history
* Update Rollup config to hide known circular dependency warnings.

* Format fixes

* Add changeset file
  • Loading branch information
okaycj authored Oct 16, 2024
1 parent 888be3d commit b111054
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 0 deletions.
9 changes: 9 additions & 0 deletions .changeset/nice-hats-sing.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
"@lookit/lookit-initjspsych": patch
"@lookit/surveys": patch
"@lookit/record": patch
"@lookit/style": patch
"@lookit/data": patch
---

Update rollup config to hide known circular warnings
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 b111054

Please sign in to comment.