Skip to content

Commit 981ac24

Browse files
refactor(enhanced): clean up sharing plugins and improve filtering
- Remove unnecessary wrapper functions in ConsumeSharedPlugin and ProvideSharedPlugin - Use createLookupKeyForSharing utility function directly - Remove singleton warnings for request include/exclude filters - Keep singleton warnings only for version include/exclude filters - Sync devtools.yml with main branch
1 parent ea2a08a commit 981ac24

File tree

3 files changed

+15
-76
lines changed

3 files changed

+15
-76
lines changed

.github/workflows/devtools.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ jobs:
5353
run: npx cypress install
5454

5555
- name: Run Affected Build
56-
run: npx nx run-many --targets=build --projects=tag:type:pkg --parallel=1 --skip-nx-cache
56+
run: npx nx run-many --targets=build --projects=tag:type:pkg --skip-nx-cache
5757

5858
- name: Configuration xvfb
5959
shell: bash

packages/enhanced/src/lib/sharing/ConsumeSharedPlugin.ts

Lines changed: 1 addition & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -67,14 +67,6 @@ const RESOLVE_OPTIONS: ResolveOptionsWithDependencyType = {
6767
};
6868
const PLUGIN_NAME = 'ConsumeSharedPlugin';
6969

70-
// Helper function to create composite key
71-
function createLookupKey(
72-
request: string,
73-
contextInfo: ModuleFactoryCreateDataContextInfo,
74-
): string {
75-
return createLookupKeyForSharing(request, contextInfo.issuerLayer);
76-
}
77-
7870
class ConsumeSharedPlugin {
7971
private _consumes: [string, ConsumeOptions][];
8072

@@ -408,7 +400,7 @@ class ConsumeSharedPlugin {
408400
return;
409401
}
410402
const match = unresolvedConsumes.get(
411-
createLookupKey(request, contextInfo),
403+
createLookupKeyForSharing(request, contextInfo.issuerLayer),
412404
);
413405

414406
if (match !== undefined) {
@@ -432,30 +424,6 @@ class ConsumeSharedPlugin {
432424

433425
const shareKey = options.shareKey + remainder;
434426

435-
// Check singleton warning for request filters
436-
if (options.singleton) {
437-
if (options.include?.request) {
438-
addSingletonFilterWarning(
439-
compilation,
440-
shareKey,
441-
'include',
442-
'request',
443-
options.include.request,
444-
request,
445-
);
446-
}
447-
if (options.exclude?.request) {
448-
addSingletonFilterWarning(
449-
compilation,
450-
shareKey,
451-
'exclude',
452-
'request',
453-
options.exclude.request,
454-
request,
455-
);
456-
}
457-
}
458-
459427
return createConsumeSharedModule(context, request, {
460428
...options,
461429
import: options.import

packages/enhanced/src/lib/sharing/ProvideSharedPlugin.ts

Lines changed: 13 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -65,14 +65,6 @@ const validate = createSchemaValidation(
6565

6666
/** @typedef {Map<string, { config: ProvideOptions, version: string | undefined | false }>} ResolvedProvideMap */
6767

68-
// Helper function to create composite key
69-
function createLookupKey(
70-
request: string,
71-
config: { layer?: string | null },
72-
): string {
73-
return createLookupKeyForSharing(request, config.layer);
74-
}
75-
7668
class ProvideSharedPlugin {
7769
private _provides: [string, ProvidesConfig][];
7870

@@ -146,7 +138,10 @@ class ProvideSharedPlugin {
146138
const prefixMatchProvides: Map<string, ProvidesConfig> = new Map();
147139
for (const [request, config] of this._provides) {
148140
const actualRequest = config.request || request;
149-
const lookupKey = createLookupKey(actualRequest, config);
141+
const lookupKey = createLookupKeyForSharing(
142+
actualRequest,
143+
config.layer,
144+
);
150145
if (/^(\/|[A-Za-z]:\\|\\\\|\.\.?(\/|$))/.test(actualRequest)) {
151146
// relative request - apply filtering if include/exclude are defined
152147
if (this.shouldProvideSharedModule(config)) {
@@ -177,18 +172,20 @@ class ProvideSharedPlugin {
177172
'ProvideSharedPlugin',
178173
(module, { resource, resourceResolveData }, resolveData) => {
179174
const moduleLayer = module.layer;
180-
const lookupKey = createLookupKey(resource || '', {
181-
layer: moduleLayer || undefined,
182-
});
175+
const lookupKey = createLookupKeyForSharing(
176+
resource || '',
177+
moduleLayer || undefined,
178+
);
183179

184180
if (resource && resolvedProvideMap.has(lookupKey)) {
185181
return module;
186182
}
187183
const { request } = resolveData;
188184
{
189-
const requestKey = createLookupKey(request, {
190-
layer: moduleLayer || undefined,
191-
});
185+
const requestKey = createLookupKeyForSharing(
186+
request,
187+
moduleLayer || undefined,
188+
);
192189
const config = matchProvides.get(requestKey);
193190
if (config !== undefined && resource) {
194191
this.provideSharedModule(
@@ -220,32 +217,6 @@ class ProvideSharedPlugin {
220217

221218
const shareKey = config.shareKey + remainder;
222219

223-
// Check singleton warning for request filters
224-
if (config.singleton) {
225-
if (config.include?.request) {
226-
addSingletonFilterWarning(
227-
compilation,
228-
shareKey,
229-
'include',
230-
'request',
231-
config.include.request,
232-
request,
233-
resource,
234-
);
235-
}
236-
if (config.exclude?.request) {
237-
addSingletonFilterWarning(
238-
compilation,
239-
shareKey,
240-
'exclude',
241-
'request',
242-
config.exclude.request,
243-
request,
244-
resource,
245-
);
246-
}
247-
}
248-
249220
this.provideSharedModule(
250221
compilation,
251222
resolvedProvideMap,
@@ -431,7 +402,7 @@ class ProvideSharedPlugin {
431402
}
432403
}
433404

434-
const lookupKey = createLookupKey(resource, config);
405+
const lookupKey = createLookupKeyForSharing(resource, config.layer);
435406
resolvedProvideMap.set(lookupKey, {
436407
config,
437408
version,

0 commit comments

Comments
 (0)