Best JavaScript code snippet using storybook-root
ProgressPlugin.js
Source:ProgressPlugin.js
1/*2 MIT License http://www.opensource.org/licenses/mit-license.php3 Author Tobias Koppers @sokra4*/5"use strict";6const { validate } = require("schema-utils");7const schema = require("../schemas/plugins/ProgressPlugin.json");8const Compiler = require("./Compiler");9const MultiCompiler = require("./MultiCompiler");10const NormalModule = require("./NormalModule");11const { contextify } = require("./util/identifier");12/** @typedef {import("../declarations/plugins/ProgressPlugin").HandlerFunction} HandlerFunction */13/** @typedef {import("../declarations/plugins/ProgressPlugin").ProgressPluginArgument} ProgressPluginArgument */14/** @typedef {import("../declarations/plugins/ProgressPlugin").ProgressPluginOptions} ProgressPluginOptions */15const median3 = (a, b, c) => {16 return a + b + c - Math.max(a, b, c) - Math.min(a, b, c);17};18const createDefaultHandler = (profile, logger) => {19 /** @type {{ value: string, time: number }[]} */20 const lastStateInfo = [];21 const defaultHandler = (percentage, msg, ...args) => {22 if (profile) {23 if (percentage === 0) {24 lastStateInfo.length = 0;25 }26 const fullState = [msg, ...args];27 const state = fullState.map(s => s.replace(/\d+\/\d+ /g, ""));28 const now = Date.now();29 const len = Math.max(state.length, lastStateInfo.length);30 for (let i = len; i >= 0; i--) {31 const stateItem = i < state.length ? state[i] : undefined;32 const lastStateItem =33 i < lastStateInfo.length ? lastStateInfo[i] : undefined;34 if (lastStateItem) {35 if (stateItem !== lastStateItem.value) {36 const diff = now - lastStateItem.time;37 if (lastStateItem.value) {38 let reportState = lastStateItem.value;39 if (i > 0) {40 reportState = lastStateInfo[i - 1].value + " > " + reportState;41 }42 const stateMsg = `${" | ".repeat(i)}${diff} ms ${reportState}`;43 const d = diff;44 // This depends on timing so we ignore it for coverage45 /* istanbul ignore next */46 {47 if (d > 10000) {48 logger.error(stateMsg);49 } else if (d > 1000) {50 logger.warn(stateMsg);51 } else if (d > 10) {52 logger.info(stateMsg);53 } else if (d > 5) {54 logger.log(stateMsg);55 } else {56 logger.debug(stateMsg);57 }58 }59 }60 if (stateItem === undefined) {61 lastStateInfo.length = i;62 } else {63 lastStateItem.value = stateItem;64 lastStateItem.time = now;65 lastStateInfo.length = i + 1;66 }67 }68 } else {69 lastStateInfo[i] = {70 value: stateItem,71 time: now72 };73 }74 }75 }76 logger.status(`${Math.floor(percentage * 100)}%`, msg, ...args);77 if (percentage === 1 || (!msg && args.length === 0)) logger.status();78 };79 return defaultHandler;80};81/**82 * @callback ReportProgress83 * @param {number} p84 * @param {...string[]} [args]85 * @returns {void}86 */87/** @type {WeakMap<Compiler,ReportProgress>} */88const progressReporters = new WeakMap();89class ProgressPlugin {90 /**91 * @param {Compiler} compiler the current compiler92 * @returns {ReportProgress} a progress reporter, if any93 */94 static getReporter(compiler) {95 return progressReporters.get(compiler);96 }97 /**98 * @param {ProgressPluginArgument} options options99 */100 constructor(options = {}) {101 if (typeof options === "function") {102 options = {103 handler: options104 };105 }106 validate(schema, options, {107 name: "Progress Plugin",108 baseDataPath: "options"109 });110 options = { ...ProgressPlugin.defaultOptions, ...options };111 this.profile = options.profile;112 this.handler = options.handler;113 this.modulesCount = options.modulesCount;114 this.dependenciesCount = options.dependenciesCount;115 this.showEntries = options.entries;116 this.showModules = options.modules;117 this.showDependencies = options.dependencies;118 this.showActiveModules = options.activeModules;119 this.percentBy = options.percentBy;120 }121 /**122 * @param {Compiler | MultiCompiler} compiler webpack compiler123 * @returns {void}124 */125 apply(compiler) {126 const handler =127 this.handler ||128 createDefaultHandler(129 this.profile,130 compiler.getInfrastructureLogger("webpack.Progress")131 );132 if (compiler instanceof MultiCompiler) {133 this._applyOnMultiCompiler(compiler, handler);134 } else if (compiler instanceof Compiler) {135 this._applyOnCompiler(compiler, handler);136 }137 }138 /**139 * @param {MultiCompiler} compiler webpack multi-compiler140 * @param {HandlerFunction} handler function that executes for every progress step141 * @returns {void}142 */143 _applyOnMultiCompiler(compiler, handler) {144 const states = compiler.compilers.map(145 () => /** @type {[number, ...string[]]} */ ([0])146 );147 compiler.compilers.forEach((compiler, idx) => {148 new ProgressPlugin((p, msg, ...args) => {149 states[idx] = [p, msg, ...args];150 let sum = 0;151 for (const [p] of states) sum += p;152 handler(sum / states.length, `[${idx}] ${msg}`, ...args);153 }).apply(compiler);154 });155 }156 /**157 * @param {Compiler} compiler webpack compiler158 * @param {HandlerFunction} handler function that executes for every progress step159 * @returns {void}160 */161 _applyOnCompiler(compiler, handler) {162 const showEntries = this.showEntries;163 const showModules = this.showModules;164 const showDependencies = this.showDependencies;165 const showActiveModules = this.showActiveModules;166 let lastActiveModule = "";167 let currentLoader = "";168 let lastModulesCount = 0;169 let lastDependenciesCount = 0;170 let lastEntriesCount = 0;171 let modulesCount = 0;172 let dependenciesCount = 0;173 let entriesCount = 1;174 let doneModules = 0;175 let doneDependencies = 0;176 let doneEntries = 0;177 const activeModules = new Set();178 let lastUpdate = 0;179 const updateThrottled = () => {180 if (lastUpdate + 500 < Date.now()) update();181 };182 const update = () => {183 /** @type {string[]} */184 const items = [];185 const percentByModules =186 doneModules /187 Math.max(lastModulesCount || this.modulesCount || 1, modulesCount);188 const percentByEntries =189 doneEntries /190 Math.max(lastEntriesCount || this.dependenciesCount || 1, entriesCount);191 const percentByDependencies =192 doneDependencies /193 Math.max(lastDependenciesCount || 1, dependenciesCount);194 let percentageFactor;195 switch (this.percentBy) {196 case "entries":197 percentageFactor = percentByEntries;198 break;199 case "dependencies":200 percentageFactor = percentByDependencies;201 break;202 case "modules":203 percentageFactor = percentByModules;204 break;205 default:206 percentageFactor = median3(207 percentByModules,208 percentByEntries,209 percentByDependencies210 );211 }212 const percentage = 0.1 + percentageFactor * 0.55;213 if (currentLoader) {214 items.push(215 `import loader ${contextify(216 compiler.context,217 currentLoader,218 compiler.root219 )}`220 );221 } else {222 const statItems = [];223 if (showEntries) {224 statItems.push(`${doneEntries}/${entriesCount} entries`);225 }226 if (showDependencies) {227 statItems.push(228 `${doneDependencies}/${dependenciesCount} dependencies`229 );230 }231 if (showModules) {232 statItems.push(`${doneModules}/${modulesCount} modules`);233 }234 if (showActiveModules) {235 statItems.push(`${activeModules.size} active`);236 }237 if (statItems.length > 0) {238 items.push(statItems.join(" "));239 }240 if (showActiveModules) {241 items.push(lastActiveModule);242 }243 }244 handler(percentage, "building", ...items);245 lastUpdate = Date.now();246 };247 const factorizeAdd = () => {248 dependenciesCount++;249 if (dependenciesCount < 50 || dependenciesCount % 100 === 0)250 updateThrottled();251 };252 const factorizeDone = () => {253 doneDependencies++;254 if (doneDependencies < 50 || doneDependencies % 100 === 0)255 updateThrottled();256 };257 const moduleAdd = () => {258 modulesCount++;259 if (modulesCount < 50 || modulesCount % 100 === 0) updateThrottled();260 };261 // only used when showActiveModules is set262 const moduleBuild = module => {263 const ident = module.identifier();264 if (ident) {265 activeModules.add(ident);266 lastActiveModule = ident;267 update();268 }269 };270 const entryAdd = (entry, options) => {271 entriesCount++;272 if (entriesCount < 5 || entriesCount % 10 === 0) updateThrottled();273 };274 const moduleDone = module => {275 doneModules++;276 if (showActiveModules) {277 const ident = module.identifier();278 if (ident) {279 activeModules.delete(ident);280 if (lastActiveModule === ident) {281 lastActiveModule = "";282 for (const m of activeModules) {283 lastActiveModule = m;284 }285 update();286 return;287 }288 }289 }290 if (doneModules < 50 || doneModules % 100 === 0) updateThrottled();291 };292 const entryDone = (entry, options) => {293 doneEntries++;294 update();295 };296 const cache = compiler297 .getCache("ProgressPlugin")298 .getItemCache("counts", null);299 let cacheGetPromise;300 compiler.hooks.beforeCompile.tap("ProgressPlugin", () => {301 if (!cacheGetPromise) {302 cacheGetPromise = cache.getPromise().then(303 data => {304 if (data) {305 lastModulesCount = lastModulesCount || data.modulesCount;306 lastDependenciesCount =307 lastDependenciesCount || data.dependenciesCount;308 }309 return data;310 },311 err => {312 // Ignore error313 }314 );315 }316 });317 compiler.hooks.afterCompile.tapPromise("ProgressPlugin", compilation => {318 if (compilation.compiler.isChild()) return Promise.resolve();319 return cacheGetPromise.then(async oldData => {320 if (321 !oldData ||322 oldData.modulesCount !== modulesCount ||323 oldData.dependenciesCount !== dependenciesCount324 ) {325 await cache.storePromise({ modulesCount, dependenciesCount });326 }327 });328 });329 compiler.hooks.compilation.tap("ProgressPlugin", compilation => {330 if (compilation.compiler.isChild()) return;331 lastModulesCount = modulesCount;332 lastEntriesCount = entriesCount;333 lastDependenciesCount = dependenciesCount;334 modulesCount = dependenciesCount = entriesCount = 0;335 doneModules = doneDependencies = doneEntries = 0;336 compilation.factorizeQueue.hooks.added.tap(337 "ProgressPlugin",338 factorizeAdd339 );340 compilation.factorizeQueue.hooks.result.tap(341 "ProgressPlugin",342 factorizeDone343 );344 compilation.addModuleQueue.hooks.added.tap("ProgressPlugin", moduleAdd);345 compilation.processDependenciesQueue.hooks.result.tap(346 "ProgressPlugin",347 moduleDone348 );349 if (showActiveModules) {350 compilation.hooks.buildModule.tap("ProgressPlugin", moduleBuild);351 }352 compilation.hooks.addEntry.tap("ProgressPlugin", entryAdd);353 compilation.hooks.failedEntry.tap("ProgressPlugin", entryDone);354 compilation.hooks.succeedEntry.tap("ProgressPlugin", entryDone);355 // avoid dynamic require if bundled with webpack356 // @ts-expect-error357 if (typeof __webpack_require__ !== "function") {358 const requiredLoaders = new Set();359 NormalModule.getCompilationHooks(compilation).beforeLoaders.tap(360 "ProgressPlugin",361 loaders => {362 for (const loader of loaders) {363 if (364 loader.type !== "module" &&365 !requiredLoaders.has(loader.loader)366 ) {367 requiredLoaders.add(loader.loader);368 currentLoader = loader.loader;369 update();370 require(loader.loader);371 }372 }373 if (currentLoader) {374 currentLoader = "";375 update();376 }377 }378 );379 }380 const hooks = {381 finishModules: "finish module graph",382 seal: "plugins",383 optimizeDependencies: "dependencies optimization",384 afterOptimizeDependencies: "after dependencies optimization",385 beforeChunks: "chunk graph",386 afterChunks: "after chunk graph",387 optimize: "optimizing",388 optimizeModules: "module optimization",389 afterOptimizeModules: "after module optimization",390 optimizeChunks: "chunk optimization",391 afterOptimizeChunks: "after chunk optimization",392 optimizeTree: "module and chunk tree optimization",393 afterOptimizeTree: "after module and chunk tree optimization",394 optimizeChunkModules: "chunk modules optimization",395 afterOptimizeChunkModules: "after chunk modules optimization",396 reviveModules: "module reviving",397 beforeModuleIds: "before module ids",398 moduleIds: "module ids",399 optimizeModuleIds: "module id optimization",400 afterOptimizeModuleIds: "module id optimization",401 reviveChunks: "chunk reviving",402 beforeChunkIds: "before chunk ids",403 chunkIds: "chunk ids",404 optimizeChunkIds: "chunk id optimization",405 afterOptimizeChunkIds: "after chunk id optimization",406 recordModules: "record modules",407 recordChunks: "record chunks",408 beforeModuleHash: "module hashing",409 beforeCodeGeneration: "code generation",410 beforeRuntimeRequirements: "runtime requirements",411 beforeHash: "hashing",412 afterHash: "after hashing",413 recordHash: "record hash",414 beforeModuleAssets: "module assets processing",415 beforeChunkAssets: "chunk assets processing",416 processAssets: "asset processing",417 afterProcessAssets: "after asset optimization",418 record: "recording",419 afterSeal: "after seal"420 };421 const numberOfHooks = Object.keys(hooks).length;422 Object.keys(hooks).forEach((name, idx) => {423 const title = hooks[name];424 const percentage = (idx / numberOfHooks) * 0.25 + 0.7;425 compilation.hooks[name].intercept({426 name: "ProgressPlugin",427 call() {428 handler(percentage, "sealing", title);429 },430 done() {431 progressReporters.set(compiler, undefined);432 handler(percentage, "sealing", title);433 },434 result() {435 handler(percentage, "sealing", title);436 },437 error() {438 handler(percentage, "sealing", title);439 },440 tap(tap) {441 // p is percentage from 0 to 1442 // args is any number of messages in a hierarchical matter443 progressReporters.set(compilation.compiler, (p, ...args) => {444 handler(percentage, "sealing", title, tap.name, ...args);445 });446 handler(percentage, "sealing", title, tap.name);447 }448 });449 });450 });451 compiler.hooks.make.intercept({452 name: "ProgressPlugin",453 call() {454 handler(0.1, "building");455 },456 done() {457 handler(0.65, "building");458 }459 });460 const interceptHook = (hook, progress, category, name) => {461 hook.intercept({462 name: "ProgressPlugin",463 call() {464 handler(progress, category, name);465 },466 done() {467 progressReporters.set(compiler, undefined);468 handler(progress, category, name);469 },470 result() {471 handler(progress, category, name);472 },473 error() {474 handler(progress, category, name);475 },476 tap(tap) {477 progressReporters.set(compiler, (p, ...args) => {478 handler(progress, category, name, tap.name, ...args);479 });480 handler(progress, category, name, tap.name);481 }482 });483 };484 compiler.cache.hooks.endIdle.intercept({485 name: "ProgressPlugin",486 call() {487 handler(0, "");488 }489 });490 interceptHook(compiler.cache.hooks.endIdle, 0.01, "cache", "end idle");491 compiler.hooks.initialize.intercept({492 name: "ProgressPlugin",493 call() {494 handler(0, "");495 }496 });497 interceptHook(compiler.hooks.initialize, 0.01, "setup", "initialize");498 interceptHook(compiler.hooks.beforeRun, 0.02, "setup", "before run");499 interceptHook(compiler.hooks.run, 0.03, "setup", "run");500 interceptHook(compiler.hooks.watchRun, 0.03, "setup", "watch run");501 interceptHook(502 compiler.hooks.normalModuleFactory,503 0.04,504 "setup",505 "normal module factory"506 );507 interceptHook(508 compiler.hooks.contextModuleFactory,509 0.05,510 "setup",511 "context module factory"512 );513 interceptHook(514 compiler.hooks.beforeCompile,515 0.06,516 "setup",517 "before compile"518 );519 interceptHook(compiler.hooks.compile, 0.07, "setup", "compile");520 interceptHook(compiler.hooks.thisCompilation, 0.08, "setup", "compilation");521 interceptHook(compiler.hooks.compilation, 0.09, "setup", "compilation");522 interceptHook(compiler.hooks.finishMake, 0.69, "building", "finish");523 interceptHook(compiler.hooks.emit, 0.95, "emitting", "emit");524 interceptHook(compiler.hooks.afterEmit, 0.98, "emitting", "after emit");525 interceptHook(compiler.hooks.done, 0.99, "done", "plugins");526 compiler.hooks.done.intercept({527 name: "ProgressPlugin",528 done() {529 handler(0.99, "");530 }531 });532 interceptHook(533 compiler.cache.hooks.storeBuildDependencies,534 0.99,535 "cache",536 "store build dependencies"537 );538 interceptHook(compiler.cache.hooks.shutdown, 0.99, "cache", "shutdown");539 interceptHook(compiler.cache.hooks.beginIdle, 0.99, "cache", "begin idle");540 interceptHook(541 compiler.hooks.watchClose,542 0.99,543 "end",544 "closing watch compilation"545 );546 compiler.cache.hooks.beginIdle.intercept({547 name: "ProgressPlugin",548 done() {549 handler(1, "");550 }551 });552 compiler.cache.hooks.shutdown.intercept({553 name: "ProgressPlugin",554 done() {555 handler(1, "");556 }557 });558 }559}560ProgressPlugin.defaultOptions = {561 profile: false,562 modulesCount: 5000,563 dependenciesCount: 10000,564 modules: true,565 dependencies: true,566 activeModules: false,567 entries: true568};...
form.js
Source:form.js
1function addNewModule(){2 var newModule = document.createElement("div"); 3 var modulesCount = document.querySelectorAll(".module-container").length;4 if(document.getElementById("module-id-" + modulesCount)){5 modulesCount++;6 }7 newModule.setAttribute("class", "card p-3 mb-2 module-container"); 8 newModule.setAttribute("id", "module-id-" + modulesCount); 9 newModule.innerHTML = `10 <div class="row pl-3 d-flex justify-content-between"> 11 <a class="col-10 p-0 text-secondary" style="text-decoration:none" data-toggle="collapse" href="#module_collapse_${modulesCount}" role="button" aria-expanded="false" aria-controls="module_collapse_${modulesCount}">12 <h5 class="col-12 p-0" id="module-title-${modulesCount}">Módulo ${modulesCount +1}</h5> 13 </a>14 <button onclick="removeModule(${modulesCount})" type="button" class="btn btn-outline-secondary mr-2">Remover</button>15 </div>16 <div class="collapse show" id="module_collapse_${modulesCount}">17 <div class="form-group">18 <label for="modules[${modulesCount}][title]">TÃtulo do Módulo</label>19 <input type="text" class="form-control" id="modules[${modulesCount}][title]" name="modules[${modulesCount}][title]" placeholder="Introdução" onblur="changeModuleTitle(${modulesCount})" required> 20 </div>21 <div class="form-group">22 <label for="modules[${modulesCount}][description]">Descrição</label>23 <textarea class="form-control" id="modules[${modulesCount}][description]" name="modules[${modulesCount}][description]" rows="2" required></textarea>24 </div>25 <!-- Content Data -->26 <div id="content-list-${modulesCount}"> 27 <div class="container bg-light p-3 rounded content-container-${modulesCount}" id="content-id-${modulesCount}-0">28 <a class="col-12 p-0 text-dark" style="text-decoration:none" data-toggle="collapse" href="#content_collapse_${modulesCount}_0" role="button" aria-expanded="false" aria-controls="content_collapse_${modulesCount}_0">29 <h5 class="col-12 p-0" id="content-title-${modulesCount}-0">Conteúdo 1</h5>30 </a>31 <div class="collapse show" id="content_collapse_${modulesCount}_0">32 <div class="form-group">33 <label for="modules[${modulesCount}][contents][0][title]">TÃtulo</label>34 <input type="text" class="form-control" id="modules[${modulesCount}][contents][0][title]" name="modules[${modulesCount}][contents][0][title]" onblur="changeContentTitle(${modulesCount}, 0)" required> 35 </div>36 <div class="form-group">37 <label for="modules[${modulesCount}][contents][0][content]">Conteúdo</label>38 <textarea class="form-control" id="modules[${modulesCount}][contents][0][content]" name="modules[${modulesCount}][contents][0][content]" rows="5" required></textarea>39 </div>40 </div>41 </div>42 </div>43 <button onclick="addNewContent(${modulesCount})" type="button" class="btn btn-outline-secondary mt-2">Adicionar Conteúdo</button>44 </div> 45 `;46 document.getElementById("modules-list").append(newModule);47};48function addNewContent(id){49 var newContent = document.createElement("div"); 50 var contentCount = document.querySelectorAll(".content-container-"+id).length;51 if(document.getElementById("content-id-" + id + "-" + contentCount)){52 contentCount++;53 }54 newContent.setAttribute("class", "container bg-light p-3 rounded content-container-"+id); 55 newContent.setAttribute("id", "content-id-" + id + "-" + contentCount);56 newContent.innerHTML = `57 <div class="row pl-3 d-flex justify-content-between">58 <a class="col-10 p-0 text-dark" style="text-decoration:none" data-toggle="collapse" href="#content_collapse_${id}_${contentCount}" role="button" aria-expanded="false" aria-controls="content_collapse_${id}_${contentCount}">59 <h5 class="col-12 p-0" id="content-title-${id}-${contentCount}">Conteúdo ${contentCount + 1}</h5> 60 </a>61 <button onclick="removeContent(${id},${contentCount})" type="button" class="btn btn-outline-secondary mr-2">Remover</button>62 </div>63 <div class="collapse show" id="content_collapse_${id}_${contentCount}">64 <div class="form-group">65 <label for="modules[${id}][contents][0][title]">TÃtulo</label>66 <input type="text" class="form-control" id="modules[${id}][contents][${contentCount}][title]" name="modules[${id}][contents][${contentCount}][title]" onblur="changeContentTitle(${id}, ${contentCount})" required> 67 </div>68 <div class="form-group">69 <label for="modules[${id}][contents][${contentCount}][content]">Conteúdo</label>70 <textarea class="form-control" id="modules[${id}][contents][${contentCount}][content]" name="modules[${id}][contents][${contentCount}][content]" rows="5" required></textarea>71 </div>72 </div> 73 `; 74 document.getElementById("content-list-"+id).append(newContent);75}76function removeContent(moduleIndex, contentIndex){77 var module = document.getElementById("content-id-" + moduleIndex + "-" + contentIndex);78 module.remove();79}80function removeModule(index){81 var module = document.getElementById("module-id-" + index); 82 module.remove();83}84function changeModuleTitle(index){85 var module = document.getElementById("module-title-" + index);86 var moduleTitle = document.getElementById("modules["+index+"][title]").value;87 module.innerHTML = "Módulo: " + moduleTitle; 88}89function changeContentTitle(moduleIndex, contentIndex){90 var content = document.getElementById("content-title-" + moduleIndex + "-" + contentIndex);91 var contentTitle = document.getElementById("modules["+moduleIndex+"][contents]["+contentIndex+"][title]").value;92 console.log(contentTitle);93 content.innerHTML = "Conteúdo: " + contentTitle;...
FlagIncludedChunksPlugin.js
Source:FlagIncludedChunksPlugin.js
1/*2 MIT License http://www.opensource.org/licenses/mit-license.php3 Author Tobias Koppers @sokra4*/5"use strict";6class FlagIncludedChunksPlugin {7 apply(compiler) {8 compiler.hooks.compilation.tap("FlagIncludedChunksPlugin", compilation => {9 compilation.hooks.optimizeChunkIds.tap(10 "FlagIncludedChunksPlugin",11 chunks => {12 // prepare two bit integers for each module13 // 2^31 is the max number represented as SMI in v814 // we want the bits distributed this way:15 // the bit 2^31 is pretty rar and only one module should get it16 // so it has a probability of 1 / modulesCount17 // the first bit (2^0) is the easiest and every module could get it18 // if it doesn't get a better bit19 // from bit 2^n to 2^(n+1) there is a probability of p20 // so 1 / modulesCount == p^3121 // <=> p = sqrt31(1 / modulesCount)22 // so we use a modulo of 1 / sqrt31(1 / modulesCount)23 const moduleBits = new WeakMap();24 const modulesCount = compilation.modules.length;25 // precalculate the modulo values for each bit26 const modulo = 1 / Math.pow(1 / modulesCount, 1 / 31);27 const modulos = Array.from(28 { length: 31 },29 (x, i) => Math.pow(modulo, i) | 030 );31 // iterate all modules to generate bit values32 let i = 0;33 for (const module of compilation.modules) {34 let bit = 30;35 while (i % modulos[bit] !== 0) {36 bit--;37 }38 moduleBits.set(module, 1 << bit);39 i++;40 }41 // interate all chunks to generate bitmaps42 const chunkModulesHash = new WeakMap();43 for (const chunk of chunks) {44 let hash = 0;45 for (const module of chunk.modulesIterable) {46 hash |= moduleBits.get(module);47 }48 chunkModulesHash.set(chunk, hash);49 }50 for (const chunkA of chunks) {51 const chunkAHash = chunkModulesHash.get(chunkA);52 const chunkAModulesCount = chunkA.getNumberOfModules();53 if (chunkAModulesCount === 0) continue;54 let bestModule = undefined;55 for (const module of chunkA.modulesIterable) {56 if (57 bestModule === undefined ||58 bestModule.getNumberOfChunks() > module.getNumberOfChunks()59 )60 bestModule = module;61 }62 loopB: for (const chunkB of bestModule.chunksIterable) {63 // as we iterate the same iterables twice64 // skip if we find ourselves65 if (chunkA === chunkB) continue;66 const chunkBModulesCount = chunkB.getNumberOfModules();67 // ids for empty chunks are not included68 if (chunkBModulesCount === 0) continue;69 // instead of swapping A and B just bail70 // as we loop twice the current A will be B and B then A71 if (chunkAModulesCount > chunkBModulesCount) continue;72 // is chunkA in chunkB?73 // we do a cheap check for the hash value74 const chunkBHash = chunkModulesHash.get(chunkB);75 if ((chunkBHash & chunkAHash) !== chunkAHash) continue;76 // compare all modules77 for (const m of chunkA.modulesIterable) {78 if (!chunkB.containsModule(m)) continue loopB;79 }80 chunkB.ids.push(chunkA.id);81 }82 }83 }84 );85 });86 }87}...
Using AI Code Generation
1import {modulesCount} from 'storybook-root';2console.log(modulesCount);3import {modulesCount as count} from 'storybook-root';4console.log(count);5import {modulesCount as count, modules} from 'storybook-root';6console.log(count);7console.log(modules);8import {modulesCount as count, modules as mod} from 'storybook-root';9console.log(count);10console.log(mod);11import {modulesCount as count, modules as mod, modulesList} from 'storybook-root';12console.log(count);13console.log(mod);14console.log(modulesList);15import {modulesCount as count, modules as mod, modulesList as list} from 'storybook-root';16console.log(count);17console.log(mod);18console.log(list);19import {modulesCount as count, modules as mod, modulesList as list, modulesList} from 'storybook-root';20console.log(count);21console.log(mod);22console.log(list);23console.log(modulesList);24import {modulesCount as count, modules as mod, modulesList as list, modulesList as modList} from 'storybook-root';25console.log(count);26console.log(mod);27console.log(list);28console.log(modList);29import {modulesCount as count, modules as mod, modulesList as list, modulesList as modList, modulesList} from 'storybook-root';30console.log(count);31console.log(mod);32console.log(list);33console.log(modList);34console.log(modulesList);35import {modulesCount as count, modules as mod, modulesList as list, modulesList as
Using AI Code Generation
1var storybookRoot = require("storybook-root");2var modulesCount = storybookRoot.modulesCount();3console.log(modulesCount);4import storybookRoot from "storybook-root";5const modulesCount = storybookRoot.modulesCount();6console.log(modulesCount);7import { modulesCount } from "storybook-root";8console.log(modulesCount);9const { modulesCount } = require("storybook-root");10console.log(modulesCount);11const { modulesCount } = require("storybook-root");12console.log(modulesCount);13import * as storybookRoot from "storybook-root";14const modulesCount = storybookRoot.modulesCount();15console.log(modulesCount);16const storybookRoot = require("storybook-root");17const modulesCount = storybookRoot.modulesCount();18console.log(modulesCount);19const storybookRoot = require("storybook-root");20const modulesCount = storybookRoot.modulesCount();21console.log(modulesCount);22const storybookRoot = require("storybook-root");23const modulesCount = storybookRoot.modulesCount();24console.log(modulesCount);25const storybookRoot = require("storybook-root");26const modulesCount = storybookRoot.modulesCount();27console.log(modulesCount);28const storybookRoot = require("storybook-root");29const modulesCount = storybookRoot.modulesCount();30console.log(modulesCount);31const storybookRoot = require("storybook-root");32const modulesCount = storybookRoot.modulesCount();33console.log(modulesCount);
Using AI Code Generation
1import { modulesCount } from 'storybook-root';2console.log(modulesCount);3import { modulesCount } from './test';4export { modulesCount };5{6}
Using AI Code Generation
1var storybook = require('storybook-root');2console.log(storybook.modulesCount());3module.exports = {4 modulesCount: function() {5 return 5;6 }7};8In case the storybook-root module is installed in a different directory, we can use the require() method as follows:9var storybook = require('storybook-root/storybook-root.js');10console.log(storybook.modulesCount());11In case the storybook-root module is installed in a different directory, we can use the require() method as follows:12var storybook = require('storybook-root/storybook-root.js');13console.log(storybook.modulesCount());14In case the storybook-root module is installed in a different directory, we can use the require() method as follows:15var storybook = require('storybook-root/storybook-root.js');16console.log(storybook.modulesCount());17In case the storybook-root module is installed in a different directory, we can use the require() method as follows:18var storybook = require('storybook-root/storybook-root.js');19console.log(storybook.modulesCount());20In case the storybook-root module is installed in a different directory, we can use the require() method as follows:21var storybook = require('storybook-root/storybook-root.js');22console.log(storybook.modulesCount());23In case the storybook-root module is installed in a different directory, we can use the require() method as follows:24var storybook = require('storybook-root/storybook-root.js');25console.log(storybook.modulesCount());
Using AI Code Generation
1const { modulesCount } = require('storybook-root');2const { add } = require('storybook-root/math');3console.log(modulesCount());4console.log(add(2, 2));5import React from 'react';6import { modulesCount } from 'storybook-root';7const Counter = () => {8 return <div>{modulesCount()}</div>;9};10export default Counter;11 <div>{{ count }}</div>12import { modulesCount } from 'storybook-root';13export default {14 data() {15 return {16 count: modulesCount(),17 };18 },19};20import { Component, OnInit } from '@angular/core';21import { modulesCount } from 'storybook-root';22@Component({23})24export class CounterComponent implements OnInit {25 count = modulesCount();26 constructor() {}27 ngOnInit(): void {}28}
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!