Skip to content

PR8: SharePlugin - Unified API #3914

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 178 commits into from
Aug 11, 2025
Merged
Show file tree
Hide file tree
Changes from 177 commits
Commits
Show all changes
178 commits
Select commit Hold shift + click to select a range
b42ddf1
feat: enhance HoistContainerReferencesPlugin for better module hoisting
ScriptedAlchemy Jul 12, 2025
abaf4f5
Merge branch 'refactor/hook-renaming-cleanup-v2' into feat/enhanced-h…
ScriptedAlchemy Jul 12, 2025
93fb248
Merge branch 'refactor/hook-renaming-cleanup-v2' into feat/enhanced-h…
ScriptedAlchemy Jul 12, 2025
378c980
feat(enhanced): add include/exclude filtering support for shared modules
ScriptedAlchemy Jul 12, 2025
99ee49f
feat(enhanced): add include/exclude filtering support for shared modules
ScriptedAlchemy Jul 12, 2025
c84ddbe
ci: retrigger CI workflow
ScriptedAlchemy Jul 12, 2025
6dc979f
ci: retrigger CI workflow
ScriptedAlchemy Jul 12, 2025
8184a92
fix(modernjs): add explicit return type to SSRLiveReload function
ScriptedAlchemy Jul 12, 2025
f151c19
fix(modernjs): add explicit return type to SSRLiveReload function
ScriptedAlchemy Jul 12, 2025
ebb4268
chore: retrigger CI for infrastructure failure
ScriptedAlchemy Jul 13, 2025
dffe2c1
chore: retrigger CI for infrastructure failure
ScriptedAlchemy Jul 13, 2025
2840932
fix(rsbuild-plugin): correct build configuration
ScriptedAlchemy Jul 14, 2025
9b746dc
fix(rsbuild-plugin): correct build configuration
ScriptedAlchemy Jul 14, 2025
14b9c25
feat(enhanced): add include/exclude filtering support to share plugin
ScriptedAlchemy Jul 14, 2025
634901d
feat(enhanced): add include/exclude filtering support to share plugin
ScriptedAlchemy Jul 14, 2025
bd1f99c
feat(enhanced): implement version-based filtering for ProvideSharedPl…
ScriptedAlchemy Jul 14, 2025
281ffda
feat(enhanced): implement version-based filtering for ProvideSharedPl…
ScriptedAlchemy Jul 14, 2025
d525d7a
chore: remove consume-filters test directory that doesn't belong to s…
ScriptedAlchemy Jul 14, 2025
c86f6c0
chore: remove consume-filters test directory that doesn't belong to s…
ScriptedAlchemy Jul 14, 2025
9bab6fb
chore: remove utils
ScriptedAlchemy Jul 14, 2025
06ad87f
chore: remove utils
ScriptedAlchemy Jul 14, 2025
c1cb7e6
feat(enhanced): add request pattern filtering support for shared modules
ScriptedAlchemy Jul 15, 2025
3dda279
feat(enhanced): add request pattern filtering support for shared modules
ScriptedAlchemy Jul 15, 2025
e9bf9dc
feat: add fallback version support for share filtering
ScriptedAlchemy Jul 15, 2025
3757776
fix: add fallbackVersion to ConsumeOptions type definition
ScriptedAlchemy Jul 15, 2025
f2d0b3e
fix: add fallbackVersion support to ProvideSharedPlugin and fix unit …
ScriptedAlchemy Jul 15, 2025
ee9024a
test: enhance fallback version unit tests with comprehensive scenarios
ScriptedAlchemy Jul 15, 2025
15a6a4d
fix: add missing layer configuration for multi consume in layers-cons…
ScriptedAlchemy Jul 15, 2025
e4ef1b3
fix: add layer property to consumed module results from shareConfig
ScriptedAlchemy Jul 15, 2025
bdbf532
fix: align layers-consume-loader test expectations with share-filter …
ScriptedAlchemy Jul 15, 2025
41b60f3
fix: correct layers-consume-loader test expectations back to expect l…
ScriptedAlchemy Jul 15, 2025
eaa661e
fix: resolve provide-filters test failures by fixing fallback version…
ScriptedAlchemy Jul 15, 2025
eb8de60
fix: correct pattern matching in ProvideSharedPlugin for share filtering
ScriptedAlchemy Jul 15, 2025
918b2ec
fix: update warnings.js to match actual warning message format
ScriptedAlchemy Jul 15, 2025
3296fd4
fix: implement provide-filters functionality to match share-filter br…
ScriptedAlchemy Jul 15, 2025
5ac18a4
feat: implement nodeModulesReconstructedLookup feature for PR7
ScriptedAlchemy Jul 15, 2025
c1b3918
feat: enhance SharePlugin with unified API improvements for PR8
ScriptedAlchemy Jul 15, 2025
f9bcfac
Merge branch 'main' into feat/enhanced-hoist-container-refs
ScriptedAlchemy Jul 15, 2025
cee3718
Merge branch 'main' into feat/enhanced-hoist-container-refs
ScriptedAlchemy Jul 15, 2025
58c8093
feat(rsbuild-plugin): extend base tsconfig instead of standalone config
ScriptedAlchemy Jul 15, 2025
d57a45b
feat(rsbuild-plugin): extend base tsconfig instead of standalone config
ScriptedAlchemy Jul 15, 2025
3c03314
feat(rsbuild-plugin): remove unnecessary tsconfig files, use single e…
ScriptedAlchemy Jul 15, 2025
46b0eae
feat(rsbuild-plugin): remove unnecessary tsconfig files, use single e…
ScriptedAlchemy Jul 15, 2025
8c348f8
chore: fix tsconfig of rsbuild plugin
ScriptedAlchemy Jul 15, 2025
9233a33
chore: fix tsconfig of rsbuild plugin
ScriptedAlchemy Jul 15, 2025
a8efcfd
feat: improve devtools workflow with caching and parallel builds
ScriptedAlchemy Jul 15, 2025
43ac786
feat: improve devtools workflow with caching and parallel builds
ScriptedAlchemy Jul 15, 2025
1f3950a
feat: add missing remote dependency hook calls to RemoteModule
ScriptedAlchemy Jul 15, 2025
7d4ba71
feat: add missing remote dependency hook calls to RemoteModule
ScriptedAlchemy Jul 15, 2025
af01bf0
fix: configure rsbuild-plugin to build like other rollup packages
ScriptedAlchemy Jul 15, 2025
e4ca7be
fix: configure rsbuild-plugin to build like other rollup packages
ScriptedAlchemy Jul 15, 2025
d47ac89
fix: correct main entry path in rsbuild-plugin project.json
ScriptedAlchemy Jul 15, 2025
3d2368c
fix: correct main entry path in rsbuild-plugin project.json
ScriptedAlchemy Jul 15, 2025
674a5c8
fix: explicitly set external dependencies in rsbuild-plugin rollup co…
ScriptedAlchemy Jul 15, 2025
86ec17d
fix: explicitly set external dependencies in rsbuild-plugin rollup co…
ScriptedAlchemy Jul 15, 2025
907475a
fix: align rsbuild-plugin config with working packages
ScriptedAlchemy Jul 15, 2025
c72c73a
fix: align rsbuild-plugin config with working packages
ScriptedAlchemy Jul 15, 2025
01f3b2b
fix: use absolute paths in rsbuild-plugin rollup config
ScriptedAlchemy Jul 15, 2025
30561fa
fix: use absolute paths in rsbuild-plugin rollup config
ScriptedAlchemy Jul 15, 2025
cf7a9dd
fix: use relative paths in rsbuild-plugin rollup config
ScriptedAlchemy Jul 15, 2025
6c85317
fix: use relative paths in rsbuild-plugin rollup config
ScriptedAlchemy Jul 15, 2025
5c60cd4
fix: remove manual external override to fix workspace dependency reso…
ScriptedAlchemy Jul 15, 2025
2877f03
fix: remove manual external override to fix workspace dependency reso…
ScriptedAlchemy Jul 15, 2025
839a407
chore: remove generated dependency graph files
ScriptedAlchemy Jul 15, 2025
710fa31
chore: remove generated dependency graph files
ScriptedAlchemy Jul 15, 2025
627568f
fix: add TypeScript path mappings for workspace dependencies
ScriptedAlchemy Jul 16, 2025
aa67759
fix: add TypeScript path mappings for workspace dependencies
ScriptedAlchemy Jul 16, 2025
c13c924
fix: modify CI workflow to build SDK first without skip cache
ScriptedAlchemy Jul 16, 2025
693e30d
fix: modify CI workflow to build SDK first without skip cache
ScriptedAlchemy Jul 16, 2025
8610143
fix: add proper FederationModulesPlugin mocking in RemoteModule test
ScriptedAlchemy Jul 16, 2025
3b9f276
fix: add proper FederationModulesPlugin mocking in RemoteModule test
ScriptedAlchemy Jul 16, 2025
067708e
chore: force modernjs package rebuild
ScriptedAlchemy Jul 16, 2025
024ed28
chore: force modernjs package rebuild
ScriptedAlchemy Jul 16, 2025
51ba0c7
fix: add jest.resetModules() to RemoteModule test
ScriptedAlchemy Jul 16, 2025
f779f71
fix: add jest.resetModules() to RemoteModule test
ScriptedAlchemy Jul 16, 2025
2e36aab
fix: mock FederationModulesPlugin at module level in RemoteModule test
ScriptedAlchemy Jul 16, 2025
031511c
fix: mock FederationModulesPlugin at module level in RemoteModule test
ScriptedAlchemy Jul 16, 2025
52fd622
fix: correct FederationModulesPlugin mock export structure
ScriptedAlchemy Jul 16, 2025
c17f36f
fix: correct FederationModulesPlugin mock export structure
ScriptedAlchemy Jul 16, 2025
51109c6
chore: force modernjs rebuild for CI missing files
ScriptedAlchemy Jul 16, 2025
dc2a64d
chore: force modernjs rebuild for CI missing files
ScriptedAlchemy Jul 16, 2025
eb03698
fix: set devtools build to --parallel=1 for stability
ScriptedAlchemy Jul 16, 2025
db8017f
fix: set devtools build to --parallel=1 for stability
ScriptedAlchemy Jul 16, 2025
3898c67
fix: remove --skip-nx-cache from devtools warm cache step
ScriptedAlchemy Jul 16, 2025
ffb7564
fix: remove --skip-nx-cache from devtools warm cache step
ScriptedAlchemy Jul 16, 2025
3512dfd
fix: exclude modernjs package from publishing compatibility check
ScriptedAlchemy Jul 16, 2025
caff35e
fix: exclude modernjs package from publishing compatibility check
ScriptedAlchemy Jul 16, 2025
440216b
fix: resolve merge conflicts with feat/enhanced-hoist-container-refs
ScriptedAlchemy Jul 16, 2025
3063652
fix: resolve merge conflicts with feat/enhanced-hoist-container-refs
ScriptedAlchemy Jul 16, 2025
cad05e6
fix: prevent infinite recursion in importNodeModule functions
ScriptedAlchemy Jul 16, 2025
db0e3af
fix: prevent infinite recursion in importNodeModule functions
ScriptedAlchemy Jul 16, 2025
79db581
refactor: use importNodeModule directly with caching protection
ScriptedAlchemy Jul 16, 2025
661ee39
refactor: use importNodeModule directly with caching protection
ScriptedAlchemy Jul 16, 2025
c3824be
refactor: simplify importModuleDynamically to use cached importNodeMo…
ScriptedAlchemy Jul 16, 2025
8d9a534
refactor: simplify importModuleDynamically to use cached importNodeMo…
ScriptedAlchemy Jul 16, 2025
f69e51d
fix: restore preferred use of vm.constants.USE_MAIN_CONTEXT_DEFAULT_L…
ScriptedAlchemy Jul 16, 2025
6f3a4ff
fix: restore preferred use of vm.constants.USE_MAIN_CONTEXT_DEFAULT_L…
ScriptedAlchemy Jul 16, 2025
6dadff8
fix: clear nodeRuntimeImportCache between tests to prevent interference
ScriptedAlchemy Jul 16, 2025
141c809
fix: clear nodeRuntimeImportCache between tests to prevent interference
ScriptedAlchemy Jul 16, 2025
e06609a
refactor: normalize export pattern for nodeRuntimeImportCache
ScriptedAlchemy Jul 16, 2025
ac94c50
refactor: normalize export pattern for nodeRuntimeImportCache
ScriptedAlchemy Jul 16, 2025
e9c9122
Merge branch 'feat/basic-share-filtering' into pr5-request-pattern-fi…
ScriptedAlchemy Jul 16, 2025
b096e3e
Merge branch 'feat/basic-share-filtering' into pr5-request-pattern-fi…
ScriptedAlchemy Jul 16, 2025
e6f51d0
Merge branch 'pr5-request-pattern-filtering' into pr6-fallback-versio…
ScriptedAlchemy Jul 16, 2025
99037c6
Merge branch 'pr6-fallback-version-support' into pr7-enhanced-filtering
ScriptedAlchemy Jul 16, 2025
8795f8b
Merge branch 'pr7-enhanced-filtering' into pr8-unified-api
ScriptedAlchemy Jul 16, 2025
c22f4b7
Merge branch 'main' into feat/enhanced-hoist-container-refs
ScriptedAlchemy Jul 16, 2025
7311569
Merge branch 'feat/enhanced-hoist-container-refs' into feat/basic-sha…
ScriptedAlchemy Jul 16, 2025
dedb94c
Merge branch 'feat/basic-share-filtering' into pr5-request-pattern-fi…
ScriptedAlchemy Jul 16, 2025
ec474ee
chore: merge main branch and resolve conflicts
ScriptedAlchemy Jul 16, 2025
a212563
Merge branch 'feat/basic-share-filtering' into pr5-request-pattern-fi…
ScriptedAlchemy Jul 16, 2025
ea2a08a
Merge branch 'main' into feat/basic-share-filtering
ScriptedAlchemy Jul 18, 2025
981ac24
refactor(enhanced): clean up sharing plugins and improve filtering
ScriptedAlchemy Jul 19, 2025
6d718b2
Merge branch 'feat/basic-share-filtering' into pr5-request-pattern-fi…
ScriptedAlchemy Jul 19, 2025
cce0396
Merge branch 'main' into feat/basic-share-filtering
ScriptedAlchemy Jul 20, 2025
f273e64
Merge branch 'feat/basic-share-filtering' into pr5-request-pattern-fi…
ScriptedAlchemy Jul 20, 2025
76e707f
fix: resolve merge conflicts with feat/basic-share-filtering branch
ScriptedAlchemy Jul 21, 2025
696aae5
chore: add changeset for request pattern filtering feature
ScriptedAlchemy Jul 21, 2025
b307974
Merge pr5-request-pattern-filtering into pr7-enhanced-filtering
ScriptedAlchemy Jul 22, 2025
af0e778
chore: merge main into pr5-request-pattern-filtering branch
ScriptedAlchemy Jul 29, 2025
d09e52e
docs: add missing information in docs
ScriptedAlchemy Jul 30, 2025
ec12931
docs: add missing information in docs
ScriptedAlchemy Jul 30, 2025
d3ca385
chore: remove redundant changesets already merged in main
ScriptedAlchemy Jul 30, 2025
a646f22
chore: add changesets for unique features and clean up artifacts
ScriptedAlchemy Jul 31, 2025
ce61cb5
chore: remove unrelated changesets from request pattern filtering branch
ScriptedAlchemy Jul 31, 2025
a7b251e
chore: restore changesets for node/sdk recursion fix and rsbuild-plug…
ScriptedAlchemy Jul 31, 2025
4238938
Merge branch 'main' into pr5-request-pattern-filtering
ScriptedAlchemy Jul 31, 2025
9323bb3
fix: resolve merge conflicts in ConsumeSharedPlugin
ScriptedAlchemy Jul 31, 2025
8d2d117
chore: x
ScriptedAlchemy Jul 31, 2025
0220037
fix: resolve schema validation and prefix sharing issues
ScriptedAlchemy Aug 1, 2025
8cf0fe8
fix: correct test condition for webpack module detection
ScriptedAlchemy Aug 1, 2025
138fb56
fix: correct satisfy function import and parameter order
ScriptedAlchemy Aug 1, 2025
b28c814
fix: correct webpack semver usage with parseRange
ScriptedAlchemy Aug 1, 2025
6ba6bfa
fix: resolve sharing plugin prefix and schema issues
ScriptedAlchemy Aug 1, 2025
6c6ad1a
fix: remove debug logging from ProvideSharedPlugin
ScriptedAlchemy Aug 1, 2025
61f9445
Merge branch 'main' into pr7-enhanced-filtering
ScriptedAlchemy Aug 1, 2025
e6398c3
fix: checkout rsbuild-plugin from main branch
ScriptedAlchemy Aug 1, 2025
30c2c0e
fix(chrome-devtools): resolve TypeScript import errors causing CI fai…
ScriptedAlchemy Aug 1, 2025
86f956f
fix(chrome-devtools): correct __GLOBAL_PLUGIN__ type declaration to m…
ScriptedAlchemy Aug 1, 2025
7157642
chore: x
ScriptedAlchemy Aug 1, 2025
415b727
chore: x
ScriptedAlchemy Aug 1, 2025
2885681
fix: resolve merge conflicts with pr7-enhanced-filtering
ScriptedAlchemy Aug 2, 2025
8e354d2
fix(enhanced): resolve CI test failures and improve test assertions
ScriptedAlchemy Aug 2, 2025
b1fbf43
Merge branch 'main' into pr8-unified-api
ScriptedAlchemy Aug 6, 2025
ac33beb
fix: initialize _options property in SharePlugin constructor
ScriptedAlchemy Aug 6, 2025
c755482
fix: add proper validation for empty shared configuration in SharePlugin
ScriptedAlchemy Aug 6, 2025
ce58b46
fix: correct package.json exports for mfRuntimePlugins in modern-js p…
ScriptedAlchemy Aug 6, 2025
154516f
Apply suggested changes
ScriptedAlchemy Aug 6, 2025
a0baeb0
Merge branch 'main' into pr8-unified-api
ScriptedAlchemy Aug 8, 2025
eb887c2
Merge branch 'main' into pr8-unified-api
ScriptedAlchemy Aug 8, 2025
cec11f2
fix: resolve CI test failures in PR #3914
ScriptedAlchemy Aug 8, 2025
1b37825
feat: remove apps/website directory and update dependencies
ScriptedAlchemy Aug 8, 2025
258b8d4
Merge branch 'main' into pr8-unified-api
ScriptedAlchemy Aug 8, 2025
8213dd2
Apply suggested changes
ScriptedAlchemy Aug 8, 2025
ed88875
Apply suggested changes
ScriptedAlchemy Aug 8, 2025
80f510a
Apply suggested changes
ScriptedAlchemy Aug 8, 2025
a2a1ab1
Apply suggested changes
ScriptedAlchemy Aug 8, 2025
858ddb7
Update webpack.config.js
ScriptedAlchemy Aug 8, 2025
8d1e46f
Apply suggested changes
ScriptedAlchemy Aug 8, 2025
4eaf792
feat: enhance HoistContainerReferencesPlugin for better module hoisting
ScriptedAlchemy Jul 12, 2025
f542dc1
Merge remote-tracking branch 'origin/pr8-unified-api' into pr8-unifie…
ScriptedAlchemy Aug 8, 2025
508d818
chore: format
ScriptedAlchemy Aug 8, 2025
3d590a5
feat: enhance HoistContainerReferencesPlugin for better module hoisting
ScriptedAlchemy Jul 12, 2025
0b0cb45
Merge remote-tracking branch 'origin/pr8-unified-api' into pr8-unifie…
ScriptedAlchemy Aug 8, 2025
16265b2
fix: resolve test failures in SharePlugin and ProvideSharedModule
ScriptedAlchemy Aug 8, 2025
503fca6
fix: correct expected stage value in ShareRuntimeModule test
ScriptedAlchemy Aug 8, 2025
956c192
fix: correct Hash import statement to use require syntax for webpack …
ScriptedAlchemy Aug 8, 2025
319bc27
chore: format dependency-graph.json formatting
ScriptedAlchemy Aug 8, 2025
221c9b5
chore: remove useless test scripts from router-demo apps (#3991)
ScriptedAlchemy Aug 9, 2025
f935ac8
chore: reverse tsconfig change
ScriptedAlchemy Aug 9, 2025
1908940
Merge branch 'main' into pr8-unified-api
ScriptedAlchemy Aug 11, 2025
3f1f585
Apply suggested changes
ScriptedAlchemy Aug 11, 2025
d2738cc
Apply suggested changes
ScriptedAlchemy Aug 11, 2025
37c485c
Apply suggested changes
ScriptedAlchemy Aug 11, 2025
8b9be54
Apply suggested changes
ScriptedAlchemy Aug 11, 2025
0678784
style: remove extra blank lines in SharePlugin files
ScriptedAlchemy Aug 11, 2025
6d9fbda
chore: reverse tsconfig change
ScriptedAlchemy Aug 11, 2025
39e9e84
Apply suggested changes
ScriptedAlchemy Aug 11, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .claude/hooks/prompt-optimizer.js
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,9 @@ async function main() {
}

// Skip optimization for very short or simple prompts that don't need enhancement
const wordCount = prompt.trim().split(/\s+/).length;
if (
wordCount <= 4 ||
prompt.length < 10 ||
/^(hi|hello|hey|thanks|thank you)$/i.test(prompt.trim())
) {
Expand Down
15 changes: 0 additions & 15 deletions .claude/settings.json

This file was deleted.

4 changes: 3 additions & 1 deletion .github/workflows/build-and-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,9 @@ jobs:
run: nproc

- name: Run Build for All
run: npx nx run-many --targets=build --projects=tag:type:pkg --parallel=4
run: |
npx nx run-many --targets=build --projects=tag:type:pkg --parallel=4 --skip-nx-cache
npx nx run-many --targets=build --projects=tag:type:pkg --parallel=4

- name: Check Package Publishing Compatibility
run: |
Expand Down
1 change: 1 addition & 0 deletions apps/website/tmp/apps/website/tsconfig.tsbuildinfo

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@
"@pmmmwh/react-refresh-webpack-plugin": "0.5.15",
"@rollup/plugin-alias": "5.1.1",
"@rollup/plugin-replace": "6.0.1",
"@rslib/core": "^0.10.4",
"@rspack/core": "1.3.9",
"@rspack/dev-server": "1.1.1",
"@semantic-release/changelog": "^6.0.3",
Expand Down
23 changes: 23 additions & 0 deletions packages/enhanced/src/lib/sharing/ProvideSharedModule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ import type {
ResolverWithOptions,
ObjectDeserializerContext,
ObjectSerializerContext,
UpdateHashContext,
} from 'webpack/lib/Module';
import Hash = require('webpack/lib/util/Hash');
import ProvideForSharedDependency from './ProvideForSharedDependency';
import { WEBPACK_MODULE_TYPE_PROVIDE } from '../Constants';
import type { InputFileSystem } from 'webpack/lib/util/fs';
Expand Down Expand Up @@ -159,6 +161,27 @@ class ProvideSharedModule extends Module {
return 42;
}

/**
* @param {Hash} hash the hash used to track dependencies
* @param {UpdateHashContext} context context
* @returns {void}
*/
override updateHash(hash: Hash, context: UpdateHashContext): void {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove this method from module

hash.update(
JSON.stringify({
shareScope: this._shareScope,
name: this._name,
version: this._version,
request: this._request,
eager: this._eager,
requiredVersion: this._requiredVersion,
strictVersion: this._strictVersion,
singleton: this._singleton,
}),
);
super.updateHash(hash, context);
}

/**
* @returns {Set<string>} types available (do not mutate)
*/
Expand Down
5 changes: 4 additions & 1 deletion packages/enhanced/src/lib/sharing/SharePlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ class SharePlugin {
options.shared,
(item, key) => {
if (typeof item !== 'string')
throw new Error('Unexpected array in shared');
throw new Error(
`Unexpected array in shared configuration for key "${key}"`,
);
const config: SharedConfig =
item === key || !isRequiredVersion(item)
? {
Expand Down Expand Up @@ -112,6 +114,7 @@ class SharePlugin {
shareScope: this._shareScope,
consumes: this._consumes,
}).apply(compiler);

new ProvideSharedPlugin({
shareScope: this._shareScope,
provides: this._provides,
Expand Down
290 changes: 290 additions & 0 deletions packages/enhanced/test/compiler-unit/sharing/SharePlugin.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,290 @@
/*
* @jest-environment node
*/

import { createMockCompiler } from '../utils';
import webpack from 'webpack';
import path from 'path';
import SharePlugin from '../../../src/lib/sharing/SharePlugin';

// Mock the child plugins to prevent deep integration testing
jest.mock('../../../src/lib/sharing/ConsumeSharedPlugin', () => {
return jest.fn().mockImplementation(() => ({
apply: jest.fn(),
}));
});

jest.mock('../../../src/lib/sharing/ProvideSharedPlugin', () => {
return jest.fn().mockImplementation(() => ({
apply: jest.fn(),
}));
});

// Import mocked modules
import ConsumeSharedPlugin from '../../../src/lib/sharing/ConsumeSharedPlugin';
import ProvideSharedPlugin from '../../../src/lib/sharing/ProvideSharedPlugin';

describe('SharePlugin Compiler Integration', () => {
let mockCompiler: webpack.Compiler;
let mockCompilation: webpack.Compilation;

beforeEach(() => {
mockCompiler = createMockCompiler();
mockCompilation = {
hooks: {
afterOptimizeChunks: {
tap: jest.fn(),
},
additionalTreeRuntimeRequirements: {
tap: jest.fn(),
},
runtimeRequirementInTree: {
for: jest.fn().mockReturnValue({ tap: jest.fn() }),
},
},
compiler: mockCompiler,
options: {
context: path.resolve(__dirname, '../../../'),
},
dependencyFactories: new Map(),
dependencyTemplates: new Map(),
addRuntimeModule: jest.fn(),
resolverFactory: {
get: jest.fn().mockReturnValue({
resolve: jest.fn(),
}),
},
} as any;

// Clear mocks before each test
(ConsumeSharedPlugin as jest.Mock).mockClear();
(ProvideSharedPlugin as jest.Mock).mockClear();
});

it('should integrate with webpack compilation lifecycle', () => {
const plugin = new SharePlugin({
shared: {
react: '^17.0.0',
lodash: {
requiredVersion: '^4.17.0',
singleton: true,
},
},
});

// Apply the plugin
plugin.apply(mockCompiler);

// Verify both child plugins are created and applied
expect(ConsumeSharedPlugin).toHaveBeenCalledTimes(1);
expect(ProvideSharedPlugin).toHaveBeenCalledTimes(1);

// Verify the plugins are applied to the compiler
const consumeInstance = (ConsumeSharedPlugin as jest.Mock).mock.results[0]
.value;
const provideInstance = (ProvideSharedPlugin as jest.Mock).mock.results[0]
.value;

expect(consumeInstance.apply).toHaveBeenCalledWith(mockCompiler);
expect(provideInstance.apply).toHaveBeenCalledWith(mockCompiler);
});

it('should handle advanced configuration with filters', () => {
const plugin = new SharePlugin({
shareScope: 'custom-scope',
shared: {
'react/': {
include: {
request: /components/,
version: '^17.0.0',
},
nodeModulesReconstructedLookup: true,
},
lodash: {
version: '4.17.21',
singleton: true,
eager: true,
},
},
});

// Should not throw during plugin application
expect(() => plugin.apply(mockCompiler)).not.toThrow();
});

it('should handle fallback version configuration', () => {
const plugin = new SharePlugin({
shared: {
react: {
include: {
version: '^17.0.0',
fallbackVersion: '17.0.0',
},
},
'utils/': {
exclude: {
version: '^2.0.0',
fallbackVersion: '2.0.0',
},
},
},
});

// Should not throw during plugin application
expect(() => plugin.apply(mockCompiler)).not.toThrow();
});

it('should handle layer configuration', () => {
const plugin = new SharePlugin({
shared: {
react: {
layer: 'framework',
issuerLayer: 'application',
},
utilities: {
layer: 'utilities',
},
},
});

// Should not throw during plugin application
expect(() => plugin.apply(mockCompiler)).not.toThrow();
});

it('should support multiple shareScopes', () => {
const plugin = new SharePlugin({
shareScope: ['primary', 'secondary'],
shared: {
react: '^17.0.0',
lodash: {
shareScope: 'custom',
requiredVersion: '^4.17.0',
},
},
});

// Should not throw during plugin application
expect(() => plugin.apply(mockCompiler)).not.toThrow();
});

it('should handle import false configuration', () => {
const plugin = new SharePlugin({
shared: {
react: {
import: false, // Only consume, don't provide
requiredVersion: '^17.0.0',
},
lodash: {
import: 'lodash-es', // Provide different module
requiredVersion: '^4.17.0',
},
},
});

// Should not throw during plugin application
expect(() => plugin.apply(mockCompiler)).not.toThrow();
});

it('should handle experiments configuration', () => {
const plugin = new SharePlugin({
shared: {
react: '^17.0.0',
},
experiments: {
nodeModulesReconstructedLookup: true,
},
});

// Should not throw during plugin application
expect(() => plugin.apply(mockCompiler)).not.toThrow();
});

it('should pass through all filtering options to child plugins', () => {
const plugin = new SharePlugin({
shareScope: 'test-scope',
shared: {
'components/': {
include: {
request: /Button|Modal/,
version: '^1.0.0',
},
nodeModulesReconstructedLookup: true,
singleton: true,
eager: false,
},
react: {
version: '17.0.0',
strictVersion: true,
packageName: 'react',
layer: 'framework',
issuerLayer: 'application',
},
},
});

// Should create valid plugin instance
expect(plugin).toBeInstanceOf(SharePlugin);

// Should not throw during plugin application
expect(() => plugin.apply(mockCompiler)).not.toThrow();
});

describe('helper methods integration', () => {
it('should provide debugging information about shared modules', () => {
const plugin = new SharePlugin({
shareScope: 'debug-scope',
shared: {
react: '^17.0.0',
lodash: {
import: false,
requiredVersion: '^4.17.0',
},
'utils/': {
version: '1.0.0',
nodeModulesReconstructedLookup: true,
},
},
});

// Test all helper methods
const options = plugin.getOptions();
expect(options.shareScope).toBe('debug-scope');

const shareScope = plugin.getShareScope();
expect(shareScope).toBe('debug-scope');

const consumes = plugin.getConsumes();
expect(consumes).toHaveLength(3);

const provides = plugin.getProvides();
expect(provides).toHaveLength(2); // lodash excluded due to import: false

const sharedInfo = plugin.getSharedInfo();
expect(sharedInfo).toEqual({
totalShared: 3,
consumeOnly: 1,
provideAndConsume: 2,
shareScopes: ['debug-scope'],
});
});

it('should validate configurations during construction', () => {
expect(() => {
new SharePlugin({
shared: {},
});
}).not.toThrow();

expect(() => {
new SharePlugin({
shared: {
react: {
include: { version: '^17.0.0' },
exclude: { version: '^16.0.0' },
},
},
});
}).not.toThrow();
});
});
});
Loading