@eriche/webpack 4.47.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +20 -0
- package/README.md +784 -0
- package/SECURITY.md +9 -0
- package/bin/webpack.js +171 -0
- package/buildin/amd-define.js +3 -0
- package/buildin/amd-options.js +2 -0
- package/buildin/global.js +20 -0
- package/buildin/harmony-module.js +24 -0
- package/buildin/module.js +22 -0
- package/buildin/system.js +7 -0
- package/declarations/WebpackOptions.d.ts +1466 -0
- package/declarations/plugins/BannerPlugin.d.ts +49 -0
- package/declarations/plugins/DllPlugin.d.ts +32 -0
- package/declarations/plugins/DllReferencePlugin.d.ts +126 -0
- package/declarations/plugins/HashedModuleIdsPlugin.d.ts +24 -0
- package/declarations/plugins/IgnorePlugin.d.ts +27 -0
- package/declarations/plugins/LoaderOptionsPlugin.d.ts +27 -0
- package/declarations/plugins/ProgressPlugin.d.ts +42 -0
- package/declarations/plugins/SourceMapDevToolPlugin.d.ts +94 -0
- package/declarations/plugins/WatchIgnorePlugin.d.ts +10 -0
- package/declarations/plugins/debug/ProfilingPlugin.d.ts +12 -0
- package/declarations/plugins/optimize/AggressiveSplittingPlugin.d.ts +24 -0
- package/declarations/plugins/optimize/LimitChunkCountPlugin.d.ts +16 -0
- package/declarations/plugins/optimize/MinChunkSizePlugin.d.ts +12 -0
- package/declarations/plugins/optimize/OccurrenceOrderChunkIdsPlugin.d.ts +12 -0
- package/declarations/plugins/optimize/OccurrenceOrderModuleIdsPlugin.d.ts +12 -0
- package/hot/dev-server.js +61 -0
- package/hot/emitter.js +2 -0
- package/hot/log-apply-result.js +44 -0
- package/hot/log.js +59 -0
- package/hot/only-dev-server.js +102 -0
- package/hot/poll.js +37 -0
- package/hot/signal.js +62 -0
- package/lib/APIPlugin.js +84 -0
- package/lib/AbstractMethodError.js +43 -0
- package/lib/AmdMainTemplatePlugin.js +106 -0
- package/lib/AsyncDependenciesBlock.js +110 -0
- package/lib/AsyncDependencyToInitialChunkError.js +31 -0
- package/lib/AutomaticPrefetchPlugin.js +57 -0
- package/lib/BannerPlugin.js +122 -0
- package/lib/BasicEvaluatedExpression.js +248 -0
- package/lib/CachePlugin.js +100 -0
- package/lib/CaseSensitiveModulesWarning.js +67 -0
- package/lib/Chunk.js +875 -0
- package/lib/ChunkGroup.js +513 -0
- package/lib/ChunkRenderError.js +32 -0
- package/lib/ChunkTemplate.js +87 -0
- package/lib/CommentCompilationWarning.js +32 -0
- package/lib/CommonJsStuffPlugin.js +116 -0
- package/lib/CompatibilityPlugin.js +70 -0
- package/lib/Compilation.js +2327 -0
- package/lib/Compiler.js +735 -0
- package/lib/ConcurrentCompilationError.js +19 -0
- package/lib/ConstPlugin.js +348 -0
- package/lib/ContextExclusionPlugin.js +28 -0
- package/lib/ContextModule.js +872 -0
- package/lib/ContextModuleFactory.js +262 -0
- package/lib/ContextReplacementPlugin.js +133 -0
- package/lib/DefinePlugin.js +289 -0
- package/lib/DelegatedModule.js +114 -0
- package/lib/DelegatedModuleFactoryPlugin.js +95 -0
- package/lib/DelegatedPlugin.js +39 -0
- package/lib/DependenciesBlock.js +124 -0
- package/lib/DependenciesBlockVariable.js +72 -0
- package/lib/Dependency.js +89 -0
- package/lib/DllEntryPlugin.js +54 -0
- package/lib/DllModule.js +60 -0
- package/lib/DllModuleFactory.js +29 -0
- package/lib/DllPlugin.js +49 -0
- package/lib/DllReferencePlugin.js +156 -0
- package/lib/DynamicEntryPlugin.js +94 -0
- package/lib/EntryModuleNotFoundError.js +21 -0
- package/lib/EntryOptionPlugin.js +46 -0
- package/lib/Entrypoint.js +64 -0
- package/lib/EnvironmentPlugin.js +72 -0
- package/lib/ErrorHelpers.js +60 -0
- package/lib/EvalDevToolModulePlugin.js +27 -0
- package/lib/EvalDevToolModuleTemplatePlugin.js +61 -0
- package/lib/EvalSourceMapDevToolModuleTemplatePlugin.js +120 -0
- package/lib/EvalSourceMapDevToolPlugin.js +41 -0
- package/lib/ExportPropertyMainTemplatePlugin.js +53 -0
- package/lib/ExtendedAPIPlugin.js +88 -0
- package/lib/ExternalModule.js +179 -0
- package/lib/ExternalModuleFactoryPlugin.js +110 -0
- package/lib/ExternalsPlugin.js +23 -0
- package/lib/FlagAllModulesAsUsedPlugin.js +38 -0
- package/lib/FlagDependencyExportsPlugin.js +174 -0
- package/lib/FlagDependencyUsagePlugin.js +116 -0
- package/lib/FlagInitialModulesAsUsedPlugin.js +36 -0
- package/lib/FunctionModulePlugin.js +19 -0
- package/lib/FunctionModuleTemplatePlugin.js +102 -0
- package/lib/Generator.js +60 -0
- package/lib/GraphHelpers.js +65 -0
- package/lib/HarmonyLinkingError.js +17 -0
- package/lib/HashedModuleIdsPlugin.js +63 -0
- package/lib/HotModuleReplacement.runtime.js +721 -0
- package/lib/HotModuleReplacementPlugin.js +425 -0
- package/lib/HotUpdateChunk.js +17 -0
- package/lib/HotUpdateChunkTemplate.js +78 -0
- package/lib/IgnorePlugin.js +91 -0
- package/lib/JavascriptGenerator.js +229 -0
- package/lib/JavascriptModulesPlugin.js +185 -0
- package/lib/JsonGenerator.js +57 -0
- package/lib/JsonModulesPlugin.js +30 -0
- package/lib/JsonParser.js +27 -0
- package/lib/LibManifestPlugin.js +90 -0
- package/lib/LibraryTemplatePlugin.js +186 -0
- package/lib/LoaderOptionsPlugin.js +58 -0
- package/lib/LoaderTargetPlugin.js +24 -0
- package/lib/MainTemplate.js +568 -0
- package/lib/MemoryOutputFileSystem.js +5 -0
- package/lib/Module.js +435 -0
- package/lib/ModuleBuildError.js +52 -0
- package/lib/ModuleDependencyError.js +35 -0
- package/lib/ModuleDependencyWarning.js +25 -0
- package/lib/ModuleError.js +36 -0
- package/lib/ModuleFilenameHelpers.js +179 -0
- package/lib/ModuleNotFoundError.js +23 -0
- package/lib/ModuleParseError.js +67 -0
- package/lib/ModuleReason.js +48 -0
- package/lib/ModuleTemplate.js +93 -0
- package/lib/ModuleWarning.js +36 -0
- package/lib/MultiCompiler.js +290 -0
- package/lib/MultiEntryPlugin.js +80 -0
- package/lib/MultiModule.js +87 -0
- package/lib/MultiModuleFactory.js +23 -0
- package/lib/MultiStats.js +92 -0
- package/lib/MultiWatching.js +50 -0
- package/lib/NamedChunksPlugin.js +29 -0
- package/lib/NamedModulesPlugin.js +58 -0
- package/lib/NoEmitOnErrorsPlugin.js +20 -0
- package/lib/NoModeWarning.js +23 -0
- package/lib/NodeStuffPlugin.js +118 -0
- package/lib/NormalModule.js +582 -0
- package/lib/NormalModuleFactory.js +528 -0
- package/lib/NormalModuleReplacementPlugin.js +51 -0
- package/lib/NullFactory.js +12 -0
- package/lib/OptionsApply.js +10 -0
- package/lib/OptionsDefaulter.js +141 -0
- package/lib/Parser.js +2454 -0
- package/lib/ParserHelpers.js +103 -0
- package/lib/PrefetchPlugin.js +37 -0
- package/lib/ProgressPlugin.js +307 -0
- package/lib/ProvidePlugin.js +86 -0
- package/lib/RawModule.js +56 -0
- package/lib/RecordIdsPlugin.js +236 -0
- package/lib/RemovedPluginError.js +11 -0
- package/lib/RequestShortener.js +83 -0
- package/lib/RequireJsStuffPlugin.js +66 -0
- package/lib/ResolverFactory.js +74 -0
- package/lib/RuleSet.js +567 -0
- package/lib/RuntimeTemplate.js +336 -0
- package/lib/SetVarMainTemplatePlugin.js +69 -0
- package/lib/SingleEntryPlugin.js +63 -0
- package/lib/SizeFormatHelpers.js +24 -0
- package/lib/SourceMapDevToolModuleOptionsPlugin.js +49 -0
- package/lib/SourceMapDevToolPlugin.js +418 -0
- package/lib/Stats.js +1685 -0
- package/lib/SystemMainTemplatePlugin.js +137 -0
- package/lib/Template.js +291 -0
- package/lib/TemplatedPathPlugin.js +188 -0
- package/lib/UmdMainTemplatePlugin.js +305 -0
- package/lib/UnsupportedFeatureWarning.js +30 -0
- package/lib/UseStrictPlugin.js +54 -0
- package/lib/WarnCaseSensitiveModulesPlugin.js +37 -0
- package/lib/WarnNoModeSetPlugin.js +17 -0
- package/lib/WatchIgnorePlugin.js +106 -0
- package/lib/Watching.js +211 -0
- package/lib/WebpackError.js +31 -0
- package/lib/WebpackOptionsApply.js +546 -0
- package/lib/WebpackOptionsDefaulter.js +391 -0
- package/lib/WebpackOptionsValidationError.js +390 -0
- package/lib/buildChunkGraph.js +712 -0
- package/lib/compareLocations.js +52 -0
- package/lib/debug/ProfilingPlugin.js +442 -0
- package/lib/dependencies/AMDDefineDependency.js +137 -0
- package/lib/dependencies/AMDDefineDependencyParserPlugin.js +336 -0
- package/lib/dependencies/AMDPlugin.js +249 -0
- package/lib/dependencies/AMDRequireArrayDependency.js +49 -0
- package/lib/dependencies/AMDRequireContextDependency.js +20 -0
- package/lib/dependencies/AMDRequireDependenciesBlock.js +47 -0
- package/lib/dependencies/AMDRequireDependenciesBlockParserPlugin.js +274 -0
- package/lib/dependencies/AMDRequireDependency.js +135 -0
- package/lib/dependencies/AMDRequireItemDependency.js +22 -0
- package/lib/dependencies/CommonJsPlugin.js +158 -0
- package/lib/dependencies/CommonJsRequireContextDependency.js +23 -0
- package/lib/dependencies/CommonJsRequireDependency.js +22 -0
- package/lib/dependencies/CommonJsRequireDependencyParserPlugin.js +138 -0
- package/lib/dependencies/ConstDependency.js +33 -0
- package/lib/dependencies/ContextDependency.js +68 -0
- package/lib/dependencies/ContextDependencyHelpers.js +232 -0
- package/lib/dependencies/ContextDependencyTemplateAsId.js +43 -0
- package/lib/dependencies/ContextDependencyTemplateAsRequireCall.js +39 -0
- package/lib/dependencies/ContextElementDependency.js +21 -0
- package/lib/dependencies/CriticalDependencyWarning.js +20 -0
- package/lib/dependencies/DelegatedExportsDependency.js +33 -0
- package/lib/dependencies/DelegatedSourceDependency.js +18 -0
- package/lib/dependencies/DependencyReference.js +64 -0
- package/lib/dependencies/DllEntryDependency.js +20 -0
- package/lib/dependencies/HarmonyAcceptDependency.js +48 -0
- package/lib/dependencies/HarmonyAcceptImportDependency.js +23 -0
- package/lib/dependencies/HarmonyCompatibilityDependency.js +31 -0
- package/lib/dependencies/HarmonyDetectionParserPlugin.js +96 -0
- package/lib/dependencies/HarmonyExportDependencyParserPlugin.js +154 -0
- package/lib/dependencies/HarmonyExportExpressionDependency.js +58 -0
- package/lib/dependencies/HarmonyExportHeaderDependency.js +30 -0
- package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +659 -0
- package/lib/dependencies/HarmonyExportSpecifierDependency.js +54 -0
- package/lib/dependencies/HarmonyImportDependency.js +109 -0
- package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +222 -0
- package/lib/dependencies/HarmonyImportSideEffectDependency.js +31 -0
- package/lib/dependencies/HarmonyImportSpecifierDependency.js +163 -0
- package/lib/dependencies/HarmonyInitDependency.js +60 -0
- package/lib/dependencies/HarmonyModulesPlugin.js +143 -0
- package/lib/dependencies/HarmonyTopLevelThisParserPlugin.js +26 -0
- package/lib/dependencies/ImportContextDependency.js +23 -0
- package/lib/dependencies/ImportDependenciesBlock.js +18 -0
- package/lib/dependencies/ImportDependency.js +34 -0
- package/lib/dependencies/ImportEagerDependency.js +32 -0
- package/lib/dependencies/ImportParserPlugin.js +248 -0
- package/lib/dependencies/ImportPlugin.js +79 -0
- package/lib/dependencies/ImportWeakDependency.js +34 -0
- package/lib/dependencies/JsonExportsDependency.js +26 -0
- package/lib/dependencies/LoaderDependency.js +21 -0
- package/lib/dependencies/LoaderPlugin.js +115 -0
- package/lib/dependencies/LocalModule.js +23 -0
- package/lib/dependencies/LocalModuleDependency.js +28 -0
- package/lib/dependencies/LocalModulesHelpers.js +52 -0
- package/lib/dependencies/ModuleDependency.js +23 -0
- package/lib/dependencies/ModuleDependencyTemplateAsId.js +17 -0
- package/lib/dependencies/ModuleDependencyTemplateAsRequireId.js +17 -0
- package/lib/dependencies/ModuleHotAcceptDependency.js +23 -0
- package/lib/dependencies/ModuleHotDeclineDependency.js +23 -0
- package/lib/dependencies/MultiEntryDependency.js +25 -0
- package/lib/dependencies/NullDependency.js +20 -0
- package/lib/dependencies/PrefetchDependency.js +18 -0
- package/lib/dependencies/RequireContextDependency.js +22 -0
- package/lib/dependencies/RequireContextDependencyParserPlugin.js +56 -0
- package/lib/dependencies/RequireContextPlugin.js +143 -0
- package/lib/dependencies/RequireEnsureDependenciesBlock.js +33 -0
- package/lib/dependencies/RequireEnsureDependenciesBlockParserPlugin.js +116 -0
- package/lib/dependencies/RequireEnsureDependency.js +58 -0
- package/lib/dependencies/RequireEnsureItemDependency.js +21 -0
- package/lib/dependencies/RequireEnsurePlugin.js +74 -0
- package/lib/dependencies/RequireHeaderDependency.js +26 -0
- package/lib/dependencies/RequireIncludeDependency.js +39 -0
- package/lib/dependencies/RequireIncludeDependencyParserPlugin.js +23 -0
- package/lib/dependencies/RequireIncludePlugin.js +61 -0
- package/lib/dependencies/RequireResolveContextDependency.js +23 -0
- package/lib/dependencies/RequireResolveDependency.js +22 -0
- package/lib/dependencies/RequireResolveDependencyParserPlugin.js +86 -0
- package/lib/dependencies/RequireResolveHeaderDependency.js +26 -0
- package/lib/dependencies/SingleEntryDependency.js +21 -0
- package/lib/dependencies/SystemPlugin.js +122 -0
- package/lib/dependencies/UnsupportedDependency.js +27 -0
- package/lib/dependencies/WebAssemblyExportImportedDependency.js +31 -0
- package/lib/dependencies/WebAssemblyImportDependency.js +54 -0
- package/lib/dependencies/WebpackMissingModule.js +20 -0
- package/lib/dependencies/getFunctionExpression.js +52 -0
- package/lib/formatLocation.js +75 -0
- package/lib/logging/Logger.js +128 -0
- package/lib/logging/createConsoleLogger.js +210 -0
- package/lib/logging/runtime.js +36 -0
- package/lib/logging/truncateArgs.js +76 -0
- package/lib/node/NodeChunkTemplatePlugin.js +31 -0
- package/lib/node/NodeEnvironmentPlugin.js +44 -0
- package/lib/node/NodeHotUpdateChunkTemplatePlugin.js +36 -0
- package/lib/node/NodeMainTemplate.runtime.js +32 -0
- package/lib/node/NodeMainTemplateAsync.runtime.js +50 -0
- package/lib/node/NodeMainTemplatePlugin.js +321 -0
- package/lib/node/NodeOutputFileSystem.js +22 -0
- package/lib/node/NodeSourcePlugin.js +141 -0
- package/lib/node/NodeTargetPlugin.js +19 -0
- package/lib/node/NodeTemplatePlugin.js +31 -0
- package/lib/node/NodeWatchFileSystem.js +109 -0
- package/lib/node/ReadFileCompileWasmTemplatePlugin.js +61 -0
- package/lib/node/nodeConsole.js +135 -0
- package/lib/optimize/AggressiveMergingPlugin.js +87 -0
- package/lib/optimize/AggressiveSplittingPlugin.js +294 -0
- package/lib/optimize/ChunkModuleIdRangePlugin.js +66 -0
- package/lib/optimize/ConcatenatedModule.js +1477 -0
- package/lib/optimize/EnsureChunkConditionsPlugin.js +70 -0
- package/lib/optimize/FlagIncludedChunksPlugin.js +99 -0
- package/lib/optimize/LimitChunkCountPlugin.js +231 -0
- package/lib/optimize/MergeDuplicateChunksPlugin.js +78 -0
- package/lib/optimize/MinChunkSizePlugin.js +82 -0
- package/lib/optimize/MinMaxSizeWarning.js +29 -0
- package/lib/optimize/ModuleConcatenationPlugin.js +485 -0
- package/lib/optimize/NaturalChunkOrderPlugin.js +41 -0
- package/lib/optimize/OccurrenceChunkOrderPlugin.js +66 -0
- package/lib/optimize/OccurrenceModuleOrderPlugin.js +112 -0
- package/lib/optimize/OccurrenceOrderPlugin.js +135 -0
- package/lib/optimize/RemoveEmptyChunksPlugin.js +42 -0
- package/lib/optimize/RemoveParentModulesPlugin.js +127 -0
- package/lib/optimize/RuntimeChunkPlugin.js +41 -0
- package/lib/optimize/SideEffectsFlagPlugin.js +352 -0
- package/lib/optimize/SplitChunksPlugin.js +971 -0
- package/lib/performance/AssetsOverSizeLimitWarning.js +30 -0
- package/lib/performance/EntrypointsOverSizeLimitWarning.js +30 -0
- package/lib/performance/NoAsyncChunksWarning.js +21 -0
- package/lib/performance/SizeLimitsPlugin.js +125 -0
- package/lib/util/LazyBucketSortedSet.js +235 -0
- package/lib/util/Queue.js +46 -0
- package/lib/util/Semaphore.js +53 -0
- package/lib/util/SetHelpers.js +48 -0
- package/lib/util/SortableSet.js +140 -0
- package/lib/util/StackedSetMap.js +142 -0
- package/lib/util/TrackingSet.js +35 -0
- package/lib/util/cachedMerge.js +35 -0
- package/lib/util/cleverMerge.js +77 -0
- package/lib/util/createHash.js +174 -0
- package/lib/util/deterministicGrouping.js +274 -0
- package/lib/util/hash/BatchedHash.js +71 -0
- package/lib/util/hash/md4.js +25 -0
- package/lib/util/hash/wasm-hash.js +174 -0
- package/lib/util/identifier.js +127 -0
- package/lib/util/objectToMap.js +16 -0
- package/lib/validateSchema.js +67 -0
- package/lib/wasm/UnsupportedWebAssemblyFeatureError.js +17 -0
- package/lib/wasm/WasmFinalizeExportsPlugin.js +69 -0
- package/lib/wasm/WasmMainTemplatePlugin.js +341 -0
- package/lib/wasm/WebAssemblyGenerator.js +458 -0
- package/lib/wasm/WebAssemblyInInitialChunkError.js +88 -0
- package/lib/wasm/WebAssemblyJavascriptGenerator.js +152 -0
- package/lib/wasm/WebAssemblyModulesPlugin.js +128 -0
- package/lib/wasm/WebAssemblyParser.js +175 -0
- package/lib/wasm/WebAssemblyUtils.js +59 -0
- package/lib/web/FetchCompileWasmTemplatePlugin.js +37 -0
- package/lib/web/JsonpChunkTemplatePlugin.js +71 -0
- package/lib/web/JsonpExportMainTemplatePlugin.js +50 -0
- package/lib/web/JsonpHotUpdateChunkTemplatePlugin.js +39 -0
- package/lib/web/JsonpMainTemplate.runtime.js +71 -0
- package/lib/web/JsonpMainTemplatePlugin.js +615 -0
- package/lib/web/JsonpTemplatePlugin.js +23 -0
- package/lib/web/WebEnvironmentPlugin.js +18 -0
- package/lib/webpack.js +206 -0
- package/lib/webpack.web.js +31 -0
- package/lib/webworker/WebWorkerChunkTemplatePlugin.js +35 -0
- package/lib/webworker/WebWorkerHotUpdateChunkTemplatePlugin.js +40 -0
- package/lib/webworker/WebWorkerMainTemplate.runtime.js +73 -0
- package/lib/webworker/WebWorkerMainTemplatePlugin.js +192 -0
- package/lib/webworker/WebWorkerTemplatePlugin.js +25 -0
- package/package.json +211 -0
- package/schemas/WebpackOptions.json +2285 -0
- package/schemas/ajv.absolutePath.js +57 -0
- package/schemas/plugins/BannerPlugin.json +101 -0
- package/schemas/plugins/DllPlugin.json +36 -0
- package/schemas/plugins/DllReferencePlugin.json +205 -0
- package/schemas/plugins/HashedModuleIdsPlugin.json +26 -0
- package/schemas/plugins/IgnorePlugin.json +37 -0
- package/schemas/plugins/LoaderOptionsPlugin.json +27 -0
- package/schemas/plugins/ProgressPlugin.json +52 -0
- package/schemas/plugins/SourceMapDevToolPlugin.json +185 -0
- package/schemas/plugins/WatchIgnorePlugin.json +18 -0
- package/schemas/plugins/debug/ProfilingPlugin.json +13 -0
- package/schemas/plugins/optimize/AggressiveSplittingPlugin.json +23 -0
- package/schemas/plugins/optimize/LimitChunkCountPlugin.json +16 -0
- package/schemas/plugins/optimize/MinChunkSizePlugin.json +12 -0
- package/schemas/plugins/optimize/OccurrenceOrderChunkIdsPlugin.json +11 -0
- package/schemas/plugins/optimize/OccurrenceOrderModuleIdsPlugin.json +11 -0
- package/web_modules/node-libs-browser.js +0 -0
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/*
|
|
2
|
+
MIT License http://www.opensource.org/licenses/mit-license.php
|
|
3
|
+
Author Sean Larkin @thelarkinn
|
|
4
|
+
*/
|
|
5
|
+
"use strict";
|
|
6
|
+
|
|
7
|
+
const WebpackError = require("../WebpackError");
|
|
8
|
+
const SizeFormatHelpers = require("../SizeFormatHelpers");
|
|
9
|
+
|
|
10
|
+
module.exports = class AssetsOverSizeLimitWarning extends WebpackError {
|
|
11
|
+
constructor(assetsOverSizeLimit, assetLimit) {
|
|
12
|
+
const assetLists = assetsOverSizeLimit
|
|
13
|
+
.map(
|
|
14
|
+
asset =>
|
|
15
|
+
`\n ${asset.name} (${SizeFormatHelpers.formatSize(asset.size)})`
|
|
16
|
+
)
|
|
17
|
+
.join("");
|
|
18
|
+
|
|
19
|
+
super(`asset size limit: The following asset(s) exceed the recommended size limit (${SizeFormatHelpers.formatSize(
|
|
20
|
+
assetLimit
|
|
21
|
+
)}).
|
|
22
|
+
This can impact web performance.
|
|
23
|
+
Assets: ${assetLists}`);
|
|
24
|
+
|
|
25
|
+
this.name = "AssetsOverSizeLimitWarning";
|
|
26
|
+
this.assets = assetsOverSizeLimit;
|
|
27
|
+
|
|
28
|
+
Error.captureStackTrace(this, this.constructor);
|
|
29
|
+
}
|
|
30
|
+
};
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/*
|
|
2
|
+
MIT License http://www.opensource.org/licenses/mit-license.php
|
|
3
|
+
Author Sean Larkin @thelarkinn
|
|
4
|
+
*/
|
|
5
|
+
"use strict";
|
|
6
|
+
|
|
7
|
+
const WebpackError = require("../WebpackError");
|
|
8
|
+
const SizeFormatHelpers = require("../SizeFormatHelpers");
|
|
9
|
+
|
|
10
|
+
module.exports = class EntrypointsOverSizeLimitWarning extends WebpackError {
|
|
11
|
+
constructor(entrypoints, entrypointLimit) {
|
|
12
|
+
const entrypointList = entrypoints
|
|
13
|
+
.map(
|
|
14
|
+
entrypoint =>
|
|
15
|
+
`\n ${entrypoint.name} (${SizeFormatHelpers.formatSize(
|
|
16
|
+
entrypoint.size
|
|
17
|
+
)})\n${entrypoint.files.map(asset => ` ${asset}`).join("\n")}`
|
|
18
|
+
)
|
|
19
|
+
.join("");
|
|
20
|
+
super(`entrypoint size limit: The following entrypoint(s) combined asset size exceeds the recommended limit (${SizeFormatHelpers.formatSize(
|
|
21
|
+
entrypointLimit
|
|
22
|
+
)}). This can impact web performance.
|
|
23
|
+
Entrypoints:${entrypointList}\n`);
|
|
24
|
+
|
|
25
|
+
this.name = "EntrypointsOverSizeLimitWarning";
|
|
26
|
+
this.entrypoints = entrypoints;
|
|
27
|
+
|
|
28
|
+
Error.captureStackTrace(this, this.constructor);
|
|
29
|
+
}
|
|
30
|
+
};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/*
|
|
2
|
+
MIT License http://www.opensource.org/licenses/mit-license.php
|
|
3
|
+
Author Sean Larkin @thelarkinn
|
|
4
|
+
*/
|
|
5
|
+
"use strict";
|
|
6
|
+
|
|
7
|
+
const WebpackError = require("../WebpackError");
|
|
8
|
+
|
|
9
|
+
module.exports = class NoAsyncChunksWarning extends WebpackError {
|
|
10
|
+
constructor() {
|
|
11
|
+
super(
|
|
12
|
+
"webpack performance recommendations: \n" +
|
|
13
|
+
"You can limit the size of your bundles by using import() or require.ensure to lazy load some parts of your application.\n" +
|
|
14
|
+
"For more info visit https://webpack.js.org/guides/code-splitting/"
|
|
15
|
+
);
|
|
16
|
+
|
|
17
|
+
this.name = "NoAsyncChunksWarning";
|
|
18
|
+
|
|
19
|
+
Error.captureStackTrace(this, this.constructor);
|
|
20
|
+
}
|
|
21
|
+
};
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
/*
|
|
2
|
+
MIT License http://www.opensource.org/licenses/mit-license.php
|
|
3
|
+
Author Sean Larkin @thelarkinn
|
|
4
|
+
*/
|
|
5
|
+
"use strict";
|
|
6
|
+
const EntrypointsOverSizeLimitWarning = require("./EntrypointsOverSizeLimitWarning");
|
|
7
|
+
const AssetsOverSizeLimitWarning = require("./AssetsOverSizeLimitWarning");
|
|
8
|
+
const NoAsyncChunksWarning = require("./NoAsyncChunksWarning");
|
|
9
|
+
|
|
10
|
+
/** @typedef {import("../Compiler")} Compiler */
|
|
11
|
+
/** @typedef {import("../Entrypoint")} Entrypoint */
|
|
12
|
+
|
|
13
|
+
module.exports = class SizeLimitsPlugin {
|
|
14
|
+
constructor(options) {
|
|
15
|
+
this.hints = options.hints;
|
|
16
|
+
this.maxAssetSize = options.maxAssetSize;
|
|
17
|
+
this.maxEntrypointSize = options.maxEntrypointSize;
|
|
18
|
+
this.assetFilter = options.assetFilter;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* @param {Compiler} compiler webpack compiler
|
|
23
|
+
* @returns {void}
|
|
24
|
+
*/
|
|
25
|
+
apply(compiler) {
|
|
26
|
+
const entrypointSizeLimit = this.maxEntrypointSize;
|
|
27
|
+
const assetSizeLimit = this.maxAssetSize;
|
|
28
|
+
const hints = this.hints;
|
|
29
|
+
const assetFilter =
|
|
30
|
+
this.assetFilter || ((name, source, info) => !info.development);
|
|
31
|
+
|
|
32
|
+
compiler.hooks.afterEmit.tap("SizeLimitsPlugin", compilation => {
|
|
33
|
+
const warnings = [];
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* @param {Entrypoint} entrypoint an entrypoint
|
|
37
|
+
* @returns {number} the size of the entrypoint
|
|
38
|
+
*/
|
|
39
|
+
const getEntrypointSize = entrypoint =>
|
|
40
|
+
entrypoint.getFiles().reduce((currentSize, file) => {
|
|
41
|
+
const asset = compilation.getAsset(file);
|
|
42
|
+
if (
|
|
43
|
+
asset &&
|
|
44
|
+
assetFilter(asset.name, asset.source, asset.info) &&
|
|
45
|
+
asset.source
|
|
46
|
+
) {
|
|
47
|
+
return currentSize + (asset.info.size || asset.source.size());
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
return currentSize;
|
|
51
|
+
}, 0);
|
|
52
|
+
|
|
53
|
+
const assetsOverSizeLimit = [];
|
|
54
|
+
for (const { name, source, info } of compilation.getAssets()) {
|
|
55
|
+
if (!assetFilter(name, source, info) || !source) {
|
|
56
|
+
continue;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
const size = info.size || source.size();
|
|
60
|
+
if (size > assetSizeLimit) {
|
|
61
|
+
assetsOverSizeLimit.push({
|
|
62
|
+
name,
|
|
63
|
+
size
|
|
64
|
+
});
|
|
65
|
+
/** @type {any} */ (source).isOverSizeLimit = true;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
const fileFilter = name => {
|
|
70
|
+
const asset = compilation.getAsset(name);
|
|
71
|
+
return asset && assetFilter(asset.name, asset.source, asset.info);
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
const entrypointsOverLimit = [];
|
|
75
|
+
for (const [name, entry] of compilation.entrypoints) {
|
|
76
|
+
const size = getEntrypointSize(entry);
|
|
77
|
+
|
|
78
|
+
if (size > entrypointSizeLimit) {
|
|
79
|
+
entrypointsOverLimit.push({
|
|
80
|
+
name: name,
|
|
81
|
+
size: size,
|
|
82
|
+
files: entry.getFiles().filter(fileFilter)
|
|
83
|
+
});
|
|
84
|
+
/** @type {any} */ (entry).isOverSizeLimit = true;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
if (hints) {
|
|
89
|
+
// 1. Individual Chunk: Size < 250kb
|
|
90
|
+
// 2. Collective Initial Chunks [entrypoint] (Each Set?): Size < 250kb
|
|
91
|
+
// 3. No Async Chunks
|
|
92
|
+
// if !1, then 2, if !2 return
|
|
93
|
+
if (assetsOverSizeLimit.length > 0) {
|
|
94
|
+
warnings.push(
|
|
95
|
+
new AssetsOverSizeLimitWarning(assetsOverSizeLimit, assetSizeLimit)
|
|
96
|
+
);
|
|
97
|
+
}
|
|
98
|
+
if (entrypointsOverLimit.length > 0) {
|
|
99
|
+
warnings.push(
|
|
100
|
+
new EntrypointsOverSizeLimitWarning(
|
|
101
|
+
entrypointsOverLimit,
|
|
102
|
+
entrypointSizeLimit
|
|
103
|
+
)
|
|
104
|
+
);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
if (warnings.length > 0) {
|
|
108
|
+
const hasAsyncChunks =
|
|
109
|
+
compilation.chunks.filter(chunk => !chunk.canBeInitial()).length >
|
|
110
|
+
0;
|
|
111
|
+
|
|
112
|
+
if (!hasAsyncChunks) {
|
|
113
|
+
warnings.push(new NoAsyncChunksWarning());
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
if (hints === "error") {
|
|
117
|
+
compilation.errors.push(...warnings);
|
|
118
|
+
} else {
|
|
119
|
+
compilation.warnings.push(...warnings);
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
};
|
|
@@ -0,0 +1,235 @@
|
|
|
1
|
+
/*
|
|
2
|
+
MIT License http://www.opensource.org/licenses/mit-license.php
|
|
3
|
+
Author Tobias Koppers @sokra
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
"use strict";
|
|
7
|
+
|
|
8
|
+
const SortableSet = require("./SortableSet");
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* @template T
|
|
12
|
+
* @template K
|
|
13
|
+
* Multi layer bucket sorted set
|
|
14
|
+
* Supports adding non-existing items (DO NOT ADD ITEM TWICE)
|
|
15
|
+
* Supports removing exiting items (DO NOT REMOVE ITEM NOT IN SET)
|
|
16
|
+
* Supports popping the first items according to defined order
|
|
17
|
+
* Supports iterating all items without order
|
|
18
|
+
* Supports updating an item in an efficient way
|
|
19
|
+
* Supports size property, which is the number of items
|
|
20
|
+
* Items are lazy partially sorted when needed
|
|
21
|
+
*/
|
|
22
|
+
class LazyBucketSortedSet {
|
|
23
|
+
/**
|
|
24
|
+
* @param {function(T): K} getKey function to get key from item
|
|
25
|
+
* @param {function(K, K): number} comparator comparator to sort keys
|
|
26
|
+
* @param {...((function(T): any) | (function(any, any): number))} args more pairs of getKey and comparator plus optional final comparator for the last layer
|
|
27
|
+
*/
|
|
28
|
+
constructor(getKey, comparator, ...args) {
|
|
29
|
+
this._getKey = getKey;
|
|
30
|
+
this._innerArgs = args;
|
|
31
|
+
this._leaf = args.length <= 1;
|
|
32
|
+
this._keys = new SortableSet(undefined, comparator);
|
|
33
|
+
/** @type {Map<K, LazyBucketSortedSet<T, any> | SortableSet<T>>} */
|
|
34
|
+
this._map = new Map();
|
|
35
|
+
this._unsortedItems = new Set();
|
|
36
|
+
this.size = 0;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* @param {T} item an item
|
|
41
|
+
* @returns {void}
|
|
42
|
+
*/
|
|
43
|
+
add(item) {
|
|
44
|
+
this.size++;
|
|
45
|
+
this._unsortedItems.add(item);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* @param {K} key key of item
|
|
50
|
+
* @param {T} item the item
|
|
51
|
+
* @returns {void}
|
|
52
|
+
*/
|
|
53
|
+
_addInternal(key, item) {
|
|
54
|
+
let entry = this._map.get(key);
|
|
55
|
+
if (entry === undefined) {
|
|
56
|
+
entry = this._leaf
|
|
57
|
+
? new SortableSet(undefined, this._innerArgs[0])
|
|
58
|
+
: new /** @type {any} */ (LazyBucketSortedSet)(...this._innerArgs);
|
|
59
|
+
this._keys.add(key);
|
|
60
|
+
this._map.set(key, entry);
|
|
61
|
+
}
|
|
62
|
+
entry.add(item);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* @param {T} item an item
|
|
67
|
+
* @returns {void}
|
|
68
|
+
*/
|
|
69
|
+
delete(item) {
|
|
70
|
+
this.size--;
|
|
71
|
+
if (this._unsortedItems.has(item)) {
|
|
72
|
+
this._unsortedItems.delete(item);
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
const key = this._getKey(item);
|
|
76
|
+
const entry = this._map.get(key);
|
|
77
|
+
entry.delete(item);
|
|
78
|
+
if (entry.size === 0) {
|
|
79
|
+
this._deleteKey(key);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* @param {K} key key to be removed
|
|
85
|
+
* @returns {void}
|
|
86
|
+
*/
|
|
87
|
+
_deleteKey(key) {
|
|
88
|
+
this._keys.delete(key);
|
|
89
|
+
this._map.delete(key);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* @returns {T | undefined} an item
|
|
94
|
+
*/
|
|
95
|
+
popFirst() {
|
|
96
|
+
if (this.size === 0) return undefined;
|
|
97
|
+
this.size--;
|
|
98
|
+
if (this._unsortedItems.size > 0) {
|
|
99
|
+
for (const item of this._unsortedItems) {
|
|
100
|
+
const key = this._getKey(item);
|
|
101
|
+
this._addInternal(key, item);
|
|
102
|
+
}
|
|
103
|
+
this._unsortedItems.clear();
|
|
104
|
+
}
|
|
105
|
+
this._keys.sort();
|
|
106
|
+
const key = this._keys.values().next().value;
|
|
107
|
+
const entry = this._map.get(key);
|
|
108
|
+
if (this._leaf) {
|
|
109
|
+
const leafEntry = /** @type {SortableSet<T>} */ (entry);
|
|
110
|
+
leafEntry.sort();
|
|
111
|
+
const item = leafEntry.values().next().value;
|
|
112
|
+
leafEntry.delete(item);
|
|
113
|
+
if (leafEntry.size === 0) {
|
|
114
|
+
this._deleteKey(key);
|
|
115
|
+
}
|
|
116
|
+
return item;
|
|
117
|
+
} else {
|
|
118
|
+
const nodeEntry = /** @type {LazyBucketSortedSet<T, any>} */ (entry);
|
|
119
|
+
const item = nodeEntry.popFirst();
|
|
120
|
+
if (nodeEntry.size === 0) {
|
|
121
|
+
this._deleteKey(key);
|
|
122
|
+
}
|
|
123
|
+
return item;
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* @param {T} item to be updated item
|
|
129
|
+
* @returns {function(true=): void} finish update
|
|
130
|
+
*/
|
|
131
|
+
startUpdate(item) {
|
|
132
|
+
if (this._unsortedItems.has(item)) {
|
|
133
|
+
return remove => {
|
|
134
|
+
if (remove) {
|
|
135
|
+
this._unsortedItems.delete(item);
|
|
136
|
+
this.size--;
|
|
137
|
+
return;
|
|
138
|
+
}
|
|
139
|
+
};
|
|
140
|
+
}
|
|
141
|
+
const key = this._getKey(item);
|
|
142
|
+
if (this._leaf) {
|
|
143
|
+
const oldEntry = /** @type {SortableSet<T>} */ (this._map.get(key));
|
|
144
|
+
return remove => {
|
|
145
|
+
if (remove) {
|
|
146
|
+
this.size--;
|
|
147
|
+
oldEntry.delete(item);
|
|
148
|
+
if (oldEntry.size === 0) {
|
|
149
|
+
this._deleteKey(key);
|
|
150
|
+
}
|
|
151
|
+
return;
|
|
152
|
+
}
|
|
153
|
+
const newKey = this._getKey(item);
|
|
154
|
+
if (key === newKey) {
|
|
155
|
+
// This flags the sortable set as unordered
|
|
156
|
+
oldEntry.add(item);
|
|
157
|
+
} else {
|
|
158
|
+
oldEntry.delete(item);
|
|
159
|
+
if (oldEntry.size === 0) {
|
|
160
|
+
this._deleteKey(key);
|
|
161
|
+
}
|
|
162
|
+
this._addInternal(newKey, item);
|
|
163
|
+
}
|
|
164
|
+
};
|
|
165
|
+
} else {
|
|
166
|
+
const oldEntry = /** @type {LazyBucketSortedSet<T, any>} */ (this._map.get(
|
|
167
|
+
key
|
|
168
|
+
));
|
|
169
|
+
const finishUpdate = oldEntry.startUpdate(item);
|
|
170
|
+
return remove => {
|
|
171
|
+
if (remove) {
|
|
172
|
+
this.size--;
|
|
173
|
+
finishUpdate(true);
|
|
174
|
+
if (oldEntry.size === 0) {
|
|
175
|
+
this._deleteKey(key);
|
|
176
|
+
}
|
|
177
|
+
return;
|
|
178
|
+
}
|
|
179
|
+
const newKey = this._getKey(item);
|
|
180
|
+
if (key === newKey) {
|
|
181
|
+
finishUpdate();
|
|
182
|
+
} else {
|
|
183
|
+
finishUpdate(true);
|
|
184
|
+
if (oldEntry.size === 0) {
|
|
185
|
+
this._deleteKey(key);
|
|
186
|
+
}
|
|
187
|
+
this._addInternal(newKey, item);
|
|
188
|
+
}
|
|
189
|
+
};
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
/**
|
|
194
|
+
* @param {Iterator<T>[]} iterators list of iterators to append to
|
|
195
|
+
* @returns {void}
|
|
196
|
+
*/
|
|
197
|
+
_appendIterators(iterators) {
|
|
198
|
+
if (this._unsortedItems.size > 0)
|
|
199
|
+
iterators.push(this._unsortedItems[Symbol.iterator]());
|
|
200
|
+
for (const key of this._keys) {
|
|
201
|
+
const entry = this._map.get(key);
|
|
202
|
+
if (this._leaf) {
|
|
203
|
+
const leafEntry = /** @type {SortableSet<T>} */ (entry);
|
|
204
|
+
const iterator = leafEntry[Symbol.iterator]();
|
|
205
|
+
iterators.push(iterator);
|
|
206
|
+
} else {
|
|
207
|
+
const nodeEntry = /** @type {LazyBucketSortedSet<T, any>} */ (entry);
|
|
208
|
+
nodeEntry._appendIterators(iterators);
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
/**
|
|
214
|
+
* @returns {Iterator<T>} the iterator
|
|
215
|
+
*/
|
|
216
|
+
[Symbol.iterator]() {
|
|
217
|
+
const iterators = [];
|
|
218
|
+
this._appendIterators(iterators);
|
|
219
|
+
iterators.reverse();
|
|
220
|
+
let currentIterator = iterators.pop();
|
|
221
|
+
return {
|
|
222
|
+
next: () => {
|
|
223
|
+
const res = currentIterator.next();
|
|
224
|
+
if (res.done) {
|
|
225
|
+
if (iterators.length === 0) return res;
|
|
226
|
+
currentIterator = iterators.pop();
|
|
227
|
+
return currentIterator.next();
|
|
228
|
+
}
|
|
229
|
+
return res;
|
|
230
|
+
}
|
|
231
|
+
};
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
module.exports = LazyBucketSortedSet;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @template T
|
|
5
|
+
*/
|
|
6
|
+
class Queue {
|
|
7
|
+
/**
|
|
8
|
+
* @param {Iterable<T>=} items The initial elements.
|
|
9
|
+
*/
|
|
10
|
+
constructor(items) {
|
|
11
|
+
/** @private @type {Set<T>} */
|
|
12
|
+
this.set = new Set(items);
|
|
13
|
+
/** @private @type {Iterator<T>} */
|
|
14
|
+
this.iterator = this.set[Symbol.iterator]();
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Returns the number of elements in this queue.
|
|
19
|
+
* @returns {number} The number of elements in this queue.
|
|
20
|
+
*/
|
|
21
|
+
get length() {
|
|
22
|
+
return this.set.size;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Appends the specified element to this queue.
|
|
27
|
+
* @param {T} item The element to add.
|
|
28
|
+
* @returns {void}
|
|
29
|
+
*/
|
|
30
|
+
enqueue(item) {
|
|
31
|
+
this.set.add(item);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Retrieves and removes the head of this queue.
|
|
36
|
+
* @returns {T | undefined} The head of the queue of `undefined` if this queue is empty.
|
|
37
|
+
*/
|
|
38
|
+
dequeue() {
|
|
39
|
+
const result = this.iterator.next();
|
|
40
|
+
if (result.done) return undefined;
|
|
41
|
+
this.set.delete(result.value);
|
|
42
|
+
return result.value;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
module.exports = Queue;
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/*
|
|
2
|
+
MIT License http://www.opensource.org/licenses/mit-license.php
|
|
3
|
+
Author Tobias Koppers @sokra
|
|
4
|
+
*/
|
|
5
|
+
"use strict";
|
|
6
|
+
|
|
7
|
+
class Semaphore {
|
|
8
|
+
/**
|
|
9
|
+
* Creates an instance of Semaphore.
|
|
10
|
+
*
|
|
11
|
+
* @param {number} available the amount available number of "tasks"
|
|
12
|
+
* in the Semaphore
|
|
13
|
+
*/
|
|
14
|
+
constructor(available) {
|
|
15
|
+
this.available = available;
|
|
16
|
+
/** @type {(function(): void)[]} */
|
|
17
|
+
this.waiters = [];
|
|
18
|
+
/** @private */
|
|
19
|
+
this._continue = this._continue.bind(this);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* @param {function(): void} callback function block to capture and run
|
|
24
|
+
* @returns {void}
|
|
25
|
+
*/
|
|
26
|
+
acquire(callback) {
|
|
27
|
+
if (this.available > 0) {
|
|
28
|
+
this.available--;
|
|
29
|
+
callback();
|
|
30
|
+
} else {
|
|
31
|
+
this.waiters.push(callback);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
release() {
|
|
36
|
+
this.available++;
|
|
37
|
+
if (this.waiters.length > 0) {
|
|
38
|
+
process.nextTick(this._continue);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
_continue() {
|
|
43
|
+
if (this.available > 0) {
|
|
44
|
+
if (this.waiters.length > 0) {
|
|
45
|
+
this.available--;
|
|
46
|
+
const callback = this.waiters.pop();
|
|
47
|
+
callback();
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
module.exports = Semaphore;
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* intersect creates Set containing the intersection of elements between all sets
|
|
5
|
+
* @param {Set[]} sets an array of sets being checked for shared elements
|
|
6
|
+
* @returns {Set<TODO>} returns a new Set containing the intersecting items
|
|
7
|
+
*/
|
|
8
|
+
const intersect = sets => {
|
|
9
|
+
if (sets.length === 0) return new Set();
|
|
10
|
+
if (sets.length === 1) return new Set(sets[0]);
|
|
11
|
+
let minSize = Infinity;
|
|
12
|
+
let minIndex = -1;
|
|
13
|
+
for (let i = 0; i < sets.length; i++) {
|
|
14
|
+
const size = sets[i].size;
|
|
15
|
+
if (size < minSize) {
|
|
16
|
+
minIndex = i;
|
|
17
|
+
minSize = size;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
const current = new Set(sets[minIndex]);
|
|
21
|
+
for (let i = 0; i < sets.length; i++) {
|
|
22
|
+
if (i === minIndex) continue;
|
|
23
|
+
const set = sets[i];
|
|
24
|
+
for (const item of current) {
|
|
25
|
+
if (!set.has(item)) {
|
|
26
|
+
current.delete(item);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
return current;
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Checks if a set is the subset of another set
|
|
35
|
+
* @param {Set<TODO>} bigSet a Set which contains the original elements to compare against
|
|
36
|
+
* @param {Set<TODO>} smallSet the set whos elements might be contained inside of bigSet
|
|
37
|
+
* @returns {boolean} returns true if smallSet contains all elements inside of the bigSet
|
|
38
|
+
*/
|
|
39
|
+
const isSubset = (bigSet, smallSet) => {
|
|
40
|
+
if (bigSet.size < smallSet.size) return false;
|
|
41
|
+
for (const item of smallSet) {
|
|
42
|
+
if (!bigSet.has(item)) return false;
|
|
43
|
+
}
|
|
44
|
+
return true;
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
exports.intersect = intersect;
|
|
48
|
+
exports.isSubset = isSubset;
|