Skip to content

Commit 83cdba3

Browse files
committed
add provide shared module plugin
1 parent a468cbb commit 83cdba3

File tree

4 files changed

+98
-6
lines changed

4 files changed

+98
-6
lines changed

declarations/plugins/sharing/ProvideSharedPlugin.d.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ export interface ProvideSharedPluginOptions {
1919
*/
2020
provides: Provides;
2121
/**
22-
* Share context name used for all provided modules (defaults to 'default').
22+
* Share scope name used for all provided modules (defaults to 'default').
2323
*/
2424
shareScope?: string;
2525
}
@@ -41,7 +41,7 @@ export interface ProvidesConfig {
4141
*/
4242
import: ProvidesItem;
4343
/**
44-
* Share context name.
44+
* Share scope name.
4545
*/
4646
shareScope?: string;
4747
version?: (number | string)[] | string;

lib/sharing/ShareRuntimeModule.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ class ShareRuntimeModule extends RuntimeModule {
7171
"for(var i = 0; i < version.length; i++) {",
7272
Template.indent([
7373
"if(i === v.length) break;",
74-
"if(v[i] !== version[i]) {",
74+
"if(v[i] != version[i]) { // loose equal is intentional to match string and number",
7575
Template.indent([
7676
'if(typeof v[i] === "string" || typeof version[i] === "string") return versionConflict();',
7777
"if(v[i] > version[i]) return;",

schemas/plugins/sharing/ProvideSharedPlugin.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
"$ref": "#/definitions/ProvidesItem"
3232
},
3333
"shareScope": {
34-
"description": "Share context name.",
34+
"description": "Share scope name.",
3535
"type": "string",
3636
"minLength": 1
3737
},
@@ -90,7 +90,7 @@
9090
"$ref": "#/definitions/Provides"
9191
},
9292
"shareScope": {
93-
"description": "Share context name used for all provided modules (defaults to 'default').",
93+
"description": "Share scope name used for all provided modules (defaults to 'default').",
9494
"type": "string",
9595
"minLength": 1
9696
}

types.d.ts

+93-1
Original file line numberDiff line numberDiff line change
@@ -839,6 +839,11 @@ declare interface CodeGenerationResult {
839839
*/
840840
sources: Map<string, Source>;
841841

842+
/**
843+
* the resulting data for all source types
844+
*/
845+
data?: Map<string, any>;
846+
842847
/**
843848
* the runtime requirements
844849
*/
@@ -1024,6 +1029,7 @@ declare class Compilation {
10241029
*/
10251030
creatingModuleDuringBuild: WeakMap<Module, Set<Module>>;
10261031
entries: Map<string, EntryData>;
1032+
globalEntry: EntryData;
10271033
entrypoints: Map<string, Entrypoint>;
10281034
chunks: Set<Chunk>;
10291035
chunkGroups: ChunkGroup[];
@@ -1108,6 +1114,15 @@ declare class Compilation {
11081114
>),
11091115
callback: (err?: WebpackError, result?: Module) => void
11101116
): void;
1117+
addInclude(
1118+
context: string,
1119+
dependency: Dependency,
1120+
options: { name: string } & Pick<
1121+
EntryDescriptionNormalized,
1122+
"filename" | "dependOn" | "library"
1123+
>,
1124+
callback: (err?: WebpackError, result?: Module) => void
1125+
): void;
11111126
rebuildModule(
11121127
module: Module,
11131128
callback: (err?: WebpackError, result?: Module) => void
@@ -2001,10 +2016,15 @@ type Entry =
20012016
| [string, ...string[]];
20022017
declare interface EntryData {
20032018
/**
2004-
* dependencies of the entrypoint
2019+
* dependencies of the entrypoint that should be evaluated at startup
20052020
*/
20062021
dependencies: Dependency[];
20072022

2023+
/**
2024+
* dependencies of the entrypoint that should be included by not evaluated
2025+
*/
2026+
includeDependencies: Dependency[];
2027+
20082028
/**
20092029
* options of the entrypoint
20102030
*/
@@ -5390,6 +5410,49 @@ declare class ProvidePlugin {
53905410
*/
53915411
apply(compiler: Compiler): void;
53925412
}
5413+
declare class ProvideSharedPlugin {
5414+
constructor(options: ProvideSharedPluginOptions);
5415+
5416+
/**
5417+
* Apply the plugin
5418+
*/
5419+
apply(compiler: Compiler): void;
5420+
}
5421+
declare interface ProvideSharedPluginOptions {
5422+
/**
5423+
* Modules that should be provided as shared modules to the share scope. When provided, property name is used as share key, otherwise share key is automatically inferred from request.
5424+
*/
5425+
provides: Provides;
5426+
5427+
/**
5428+
* Share scope name used for all provided modules (defaults to 'default').
5429+
*/
5430+
shareScope?: string;
5431+
}
5432+
type Provides = (string | ProvidesObject)[] | ProvidesObject;
5433+
5434+
/**
5435+
* Advanced configuration for modules that should be provided as shared modules to the share scope.
5436+
*/
5437+
declare interface ProvidesConfig {
5438+
/**
5439+
* Request to a module that should be provided as shared module to the share scope.
5440+
*/
5441+
import: string;
5442+
5443+
/**
5444+
* Share scope name.
5445+
*/
5446+
shareScope?: string;
5447+
version?: string | (string | number)[];
5448+
}
5449+
5450+
/**
5451+
* Modules that should be provided as shared modules to the share scope. Property names are used as share keys.
5452+
*/
5453+
declare interface ProvidesObject {
5454+
[index: string]: string | ProvidesConfig;
5455+
}
53935456
type PublicPath =
53945457
| string
53955458
| ((pathData: PathData, assetInfo: AssetInfo) => string);
@@ -6299,6 +6362,24 @@ declare abstract class RuntimeTemplate {
62996362
*/
63006363
runtimeRequirements: Set<string>;
63016364
}): string;
6365+
asyncModuleFactory(__0: {
6366+
/**
6367+
* the async block
6368+
*/
6369+
block: AsyncDependenciesBlock;
6370+
/**
6371+
* the chunk graph
6372+
*/
6373+
chunkGraph: ChunkGraph;
6374+
/**
6375+
* if set, will be filled with runtime requirements
6376+
*/
6377+
runtimeRequirements: Set<string>;
6378+
/**
6379+
* request string used originally
6380+
*/
6381+
request?: string;
6382+
}): string;
63026383
defineEsModuleFlagStatement(__0: {
63036384
/**
63046385
* the name of the exports object
@@ -7444,6 +7525,8 @@ declare namespace exports {
74447525
export let interceptModuleExecution: string;
74457526
export let global: string;
74467527
export let overrides: string;
7528+
export let shareScopeMap: string;
7529+
export let initializeSharing: string;
74477530
export let getUpdateManifestFilename: string;
74487531
export let hmrDownloadManifest: string;
74497532
export let hmrDownloadUpdateHandlers: string;
@@ -7529,6 +7612,15 @@ declare namespace exports {
75297612
OverridablesPlugin
75307613
};
75317614
}
7615+
export namespace sharing {
7616+
export const scope: <T>(
7617+
scope: string,
7618+
options:
7619+
| Record<string, string | string[] | T>
7620+
| (string | Record<string, string | string[] | T>)[]
7621+
) => Record<string, string | string[] | T>;
7622+
export { ProvideSharedPlugin };
7623+
}
75327624
export namespace debug {
75337625
export { ProfilingPlugin };
75347626
}

0 commit comments

Comments
 (0)