MCPcopy Index your code
hub / github.com/darkreader/darkreader / createBundleCSSTask

Function createBundleCSSTask

tasks/bundle-css.js:75–138  ·  view source on GitHub ↗
(cssEntries)

Source from the content-addressed store, hash-verified

73 * @returns {ReturnType<typeof createTask>}
74 */
75export function createBundleCSSTask(cssEntries) {
76 /** @type {string[]} */
77 let currentWatchFiles;
78
79 const getWatchFiles = () => {
80 const watchFiles = new Set();
81 cssEntries.forEach((entry) => {
82 entry.watchFiles?.forEach((file) => watchFiles.add(file));
83 const entryFile = getEntryFile(entry);
84 if (!watchFiles.has(entryFile)) {
85 watchFiles.add(entryFile);
86 }
87 });
88 currentWatchFiles = Array.from(watchFiles);
89 return currentWatchFiles;
90 };
91
92 const bundleCSS = async ({platforms, debug}) => {
93 for (const entry of cssEntries) {
94 for (const platform in platforms) {
95 if (!platforms[platform]) {
96 continue;
97 }
98 const css = await bundleCSSEntry(entry, platform === PLATFORM.CHROMIUM_MV2_PLUS);
99 await writeFiles(entry.dest, {[platform]: true}, debug, css);
100 }
101 }
102 };
103
104 /** @type {(changedFiles: string[], watcher: FSWatcher, platforms: any) => Promise<void>} */
105 const onChange = async (changedFiles, watcher, platforms) => {
106 const entries = cssEntries.filter((entry) => {
107 const entryFile = getEntryFile(entry);
108 return changedFiles.some((changed) => {
109 return entry.watchFiles?.includes(changed) || changed === entryFile;
110 });
111 });
112 for (const entry of entries) {
113 const css = await bundleCSSEntry(entry, true);
114 await writeFiles(entry.dest, platforms, true, css);
115 }
116
117 const newWatchFiles = getWatchFiles();
118 watcher.unwatch(
119 currentWatchFiles.filter((oldFile) => !newWatchFiles.includes(oldFile))
120 );
121 watcher.add(
122 newWatchFiles.filter((newFile) => currentWatchFiles.includes(newFile))
123 );
124
125 reload.reload({type: reload.CSS});
126 };
127
128 return createTask(
129 'bundle-css',
130 bundleCSS,
131 ).addWatcher(
132 () => {

Callers 1

bundle-css.jsFile · 0.85

Calls 3

createTaskFunction · 0.90
getWatchFilesFunction · 0.85
addWatcherMethod · 0.80

Tested by

no test coverage detected