Skip to content

Commit 2c52030

Browse files
feat(enhanced): implement multiple share scope support (#3524)
Co-authored-by: Hanric <[email protected]>
1 parent 42bf94c commit 2c52030

File tree

87 files changed

+13289
-1328
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

87 files changed

+13289
-1328
lines changed

.cursorignore

Lines changed: 0 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -1,77 +0,0 @@
1-
# Cache and temporary files
2-
**/.cache/
3-
**/.temp/
4-
**/coverage/
5-
**/dist/
6-
7-
# Documentation and config files
8-
**/*.md
9-
**/*.yaml
10-
**/*.yml
11-
**/.eslintrc*
12-
**/.prettierrc*
13-
**/.swcrc
14-
**/jest.config.*
15-
**/tsconfig.*
16-
**/*/stats.json
17-
18-
# First ignore everything
19-
*
20-
21-
# Then allow specific packages and their contents
22-
!packages/webpack-bundler-runtime/
23-
!packages/webpack-bundler-runtime/**/*
24-
!packages/sdk/
25-
!packages/sdk/**/*
26-
!packages/enhanced/
27-
!packages/enhanced/**/*
28-
29-
# Allow package.json files
30-
!package.json
31-
!packages/*/package.json
32-
!**/package.json
33-
34-
# Explicitly ignore specific packages
35-
packages/dts-plugin/
36-
packages/typescript/
37-
packages/native-*
38-
packages/core/
39-
packages/assemble-release-plan/
40-
packages/native-federation-typescript/
41-
packages/esbuild/
42-
43-
# Ignore specific directories
44-
apps/
45-
webpack/tooling/
46-
webpack/setup/
47-
webpack/test/
48-
webpack/benchmark/
49-
tools/
50-
.husky/
51-
.github/
52-
.vscode/
53-
.verdaccio/
54-
55-
!apps/manifest-demo/*.ts
56-
57-
# Ignore specific files
58-
.cursorignore
59-
jest.preset.js
60-
babel.config.json
61-
nx.json
62-
LICENSE
63-
.nxignore
64-
netlify.toml
65-
renovate.json
66-
.npmrc
67-
.cursorrules
68-
.prettierignore
69-
.editorconfig
70-
ai-lint-fix.js
71-
manifest.json
72-
typedoc.json
73-
typedoc.base.json
74-
commitlint.config.js
75-
.eslintignore
76-
commit-gen.js
77-
main.py

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
"commit": "cz",
2424
"docs": "typedoc",
2525
"f": "nx format:write",
26-
"enhanced:jest": "pnpm build && cd packages/enhanced && NODE_OPTIONS=--experimental-vm-modules npx jest test/ConfigTestCases.basictest.js",
26+
"enhanced:jest": "pnpm build && cd packages/enhanced && NODE_OPTIONS=--experimental-vm-modules npx jest test/ConfigTestCases.basictest.js test/unit",
2727
"lint": "nx run-many --target=lint",
2828
"test": "nx run-many --target=test",
2929
"build": "nx run-many --target=build --parallel=5 --projects=tag:type:pkg",

packages/enhanced/jest.config.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,10 @@ export default {
3333
moduleFileExtensions: ['ts', 'js', 'html'],
3434
coverageDirectory: '../../coverage/packages/enhanced',
3535
rootDir: __dirname,
36-
testMatch: ['<rootDir>/test/*.basictest.js'],
36+
testMatch: [
37+
'<rootDir>/test/*.basictest.js',
38+
'<rootDir>/test/unit/**/*.test.ts',
39+
],
3740

3841
testEnvironment: path.resolve(__dirname, './test/patch-node-env.js'),
3942
setupFilesAfterEnv: ['<rootDir>/test/setupTestFramework.js'],

packages/enhanced/src/declarations/plugins/sharing/ConsumeSharedModule.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export type ConsumeOptions = {
1818
/**
1919
* share scope
2020
*/
21-
shareScope: string;
21+
shareScope: string | string[];
2222
/**
2323
* version requirement
2424
*/

packages/enhanced/src/declarations/plugins/sharing/ConsumeSharedPlugin.d.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ export interface ConsumeSharedPluginOptions {
2424
/**
2525
* Share scope name used for all consumed modules (defaults to 'default').
2626
*/
27-
shareScope?: string;
27+
shareScope?: string | string[];
2828
}
2929
/**
3030
* Modules that should be consumed from share scope. Property names are used to match requested modules in this compilation. Relative requests are resolved, module requests are matched unresolved, absolute paths will match resolved requests. A trailing slash will match all requests with this prefix. In this case shareKey must also have a trailing slash.
@@ -62,7 +62,7 @@ export interface ConsumesConfig {
6262
/**
6363
* Share scope name.
6464
*/
65-
shareScope?: string;
65+
shareScope?: string | string[];
6666
/**
6767
* Allow only a single version of the shared module in share scope (disabled by default).
6868
*/

packages/enhanced/src/declarations/plugins/sharing/ProvideSharedPlugin.d.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ export interface ProvideSharedPluginOptions {
2121
/**
2222
* Share scope name used for all provided modules (defaults to 'default').
2323
*/
24-
shareScope?: string;
24+
shareScope?: string | string[];
2525
}
2626
/**
2727
* Modules that should be provided as shared modules to the share scope. Property names are used as share keys.
@@ -47,7 +47,7 @@ export interface ProvidesConfig {
4747
/**
4848
* Share scope name.
4949
*/
50-
shareScope?: string;
50+
shareScope?: string | string[];
5151
/**
5252
* Version of the provided module. Will replace lower matching versions, but not higher.
5353
*/

packages/enhanced/src/declarations/plugins/sharing/SharePlugin.d.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ export interface SharePluginOptions {
2020
/**
2121
* Share scope name used for all shared modules (defaults to 'default').
2222
*/
23-
shareScope?: string;
23+
shareScope?: string | string[];
2424
/**
2525
* Modules that should be shared in the share scope. When provided, property names are used to match requested modules in this compilation.
2626
*/
@@ -62,7 +62,7 @@ export interface SharedConfig {
6262
/**
6363
* Share scope name.
6464
*/
65-
shareScope?: string;
65+
shareScope?: string | string[];
6666
/**
6767
* Allow only a single version of the shared module in share scope (disabled by default).
6868
*/

packages/enhanced/src/lib/container/ContainerEntryDependency.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,21 +18,21 @@ const { Dependency } = require(
1818
class ContainerEntryDependency extends Dependency {
1919
public name: string;
2020
public exposes: [string, ExposeOptions][];
21-
public shareScope: string;
21+
public shareScope: string | string[];
2222
public injectRuntimeEntry: string;
2323
public dataPrefetch: containerPlugin.ContainerPluginOptions['dataPrefetch'];
2424

2525
/**
2626
* @param {string} name entry name
2727
* @param {[string, ExposeOptions][]} exposes list of exposed modules
28-
* @param {string} shareScope name of the share scope
28+
* @param {string|string[]} shareScope name of the share scope
2929
* @param {string[]} injectRuntimeEntry the path of injectRuntime file.
3030
* @param {containerPlugin.ContainerPluginOptions['dataPrefetch']} dataPrefetch whether enable dataPrefetch
3131
*/
3232
constructor(
3333
name: string,
3434
exposes: [string, ExposeOptions][],
35-
shareScope: string,
35+
shareScope: string | string[],
3636
injectRuntimeEntry: string,
3737
dataPrefetch: containerPlugin.ContainerPluginOptions['dataPrefetch'],
3838
) {

packages/enhanced/src/lib/container/ContainerEntryModule.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,21 +62,21 @@ export type ExposeOptions = {
6262
class ContainerEntryModule extends Module {
6363
private _name: string;
6464
private _exposes: [string, ExposeOptions][];
65-
private _shareScope: string;
65+
private _shareScope: string | string[];
6666
private _injectRuntimeEntry: string;
6767
private _dataPrefetch: containerPlugin.ContainerPluginOptions['dataPrefetch'];
6868

6969
/**
7070
* @param {string} name container entry name
7171
* @param {[string, ExposeOptions][]} exposes list of exposed modules
72-
* @param {string} shareScope name of the share scope
72+
* @param {string|string[]} shareScope name of the share scope
7373
* @param {string} injectRuntimeEntry the path of injectRuntime file.
7474
* @param {containerPlugin.ContainerPluginOptions['dataPrefetch']} dataPrefetch whether enable dataPrefetch
7575
*/
7676
constructor(
7777
name: string,
7878
exposes: [string, ExposeOptions][],
79-
shareScope: string,
79+
shareScope: string | string[],
8080
injectRuntimeEntry: string,
8181
dataPrefetch: containerPlugin.ContainerPluginOptions['dataPrefetch'],
8282
) {
@@ -115,7 +115,11 @@ class ContainerEntryModule extends Module {
115115
* @returns {string} a unique identifier of the module
116116
*/
117117
override identifier(): string {
118-
return `container entry (${this._shareScope}) ${JSON.stringify(
118+
const scopeStr = Array.isArray(this._shareScope)
119+
? this._shareScope.join('|')
120+
: this._shareScope;
121+
122+
return `container entry (${scopeStr}) ${JSON.stringify(
119123
this._exposes,
120124
)} ${this._injectRuntimeEntry} ${JSON.stringify(this._dataPrefetch)}`;
121125
}

packages/enhanced/src/lib/container/ContainerReferencePlugin.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ class ContainerReferencePlugin {
109109

110110
normalModuleFactory.hooks.factorize.tap(
111111
'ContainerReferencePlugin',
112-
// @ts-ignore
112+
//@ts-ignore
113113
(data) => {
114114
if (!data.request.includes('!')) {
115115
for (const [key, config] of remotes) {

0 commit comments

Comments
 (0)