@module-federation/sdk 0.0.0-next-20231220075455 → 0.0.0-next-20231220081137
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/dist/LICENSE +21 -0
- package/dist/index.cjs.d.ts +1 -0
- package/dist/index.cjs.js +793 -0
- package/dist/index.esm.js +761 -0
- package/dist/normalize-webpack-path.cjs.d.ts +1 -0
- package/dist/normalize-webpack-path.cjs.js +42 -0
- package/dist/normalize-webpack-path.esm.js +33 -0
- package/dist/package.json +44 -0
- package/dist/src/constant.d.ts +16 -0
- package/dist/src/dom.d.ts +10 -0
- package/dist/src/env.d.ts +7 -0
- package/dist/src/generateSnapshotFromManifest.d.ts +10 -0
- package/{src/index.ts → dist/src/index.d.ts} +1 -4
- package/dist/src/logger.d.ts +8 -0
- package/dist/src/normalize-webpack-path.d.ts +3 -0
- package/{src/types/common.ts → dist/src/types/common.d.ts} +4 -12
- package/dist/src/types/manifest.d.ts +26 -0
- package/dist/src/types/snapshot.d.ts +62 -0
- package/dist/src/types/stats.d.ts +79 -0
- package/dist/src/utils.d.ts +17 -0
- package/package.json +5 -1
- package/CHANGELOG.md +0 -2190
- package/__tests__/decodeName.spec.ts +0 -11
- package/__tests__/encodeName.spec.ts +0 -10
- package/__tests__/generateSnapshotFromManifest.spec.ts +0 -147
- package/__tests__/parseEntry.spec.ts +0 -36
- package/__tests__/resources/constant.ts +0 -6
- package/__tests__/resources/getId.ts +0 -5
- package/__tests__/resources/manifestSnapshotMap.ts +0 -1541
- package/__tests__/simpleJoinRemoteEntry.spec.ts +0 -53
- package/jest.config.js +0 -27
- package/project.json +0 -65
- package/rollup.config.js +0 -11
- package/src/constant.ts +0 -24
- package/src/dom.ts +0 -115
- package/src/env.ts +0 -25
- package/src/generateSnapshotFromManifest.ts +0 -176
- package/src/logger.ts +0 -59
- package/src/normalize-webpack-path.ts +0 -33
- package/src/types/manifest.ts +0 -44
- package/src/types/snapshot.ts +0 -87
- package/src/types/stats.ts +0 -101
- package/src/utils.ts +0 -213
- package/tsconfig.json +0 -29
- package/tsconfig.lib.json +0 -10
- package/tsconfig.spec.json +0 -14
- /package/{src/types/index.ts → dist/src/types/index.d.ts} +0 -0
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
import { simpleJoinRemoteEntry } from '../src/generateSnapshotFromManifest';
|
|
2
|
-
|
|
3
|
-
describe('simpleJoinRemoteEntry', () => {
|
|
4
|
-
it('return remoteEntryName while remoteEntryPath is empty', () => {
|
|
5
|
-
const remoteEntry = {
|
|
6
|
-
name: 'vmok-remote-entry.js',
|
|
7
|
-
path: '',
|
|
8
|
-
};
|
|
9
|
-
expect(simpleJoinRemoteEntry(remoteEntry.path, remoteEntry.name)).toEqual(
|
|
10
|
-
remoteEntry.name,
|
|
11
|
-
);
|
|
12
|
-
});
|
|
13
|
-
|
|
14
|
-
it('normalize remoteEntryPath while remoteEntryPath startsWith "."', () => {
|
|
15
|
-
const remoteEntry = {
|
|
16
|
-
name: 'vmok-remote-entry.js',
|
|
17
|
-
path: '.',
|
|
18
|
-
};
|
|
19
|
-
expect(simpleJoinRemoteEntry(remoteEntry.path, remoteEntry.name)).toEqual(
|
|
20
|
-
remoteEntry.name,
|
|
21
|
-
);
|
|
22
|
-
});
|
|
23
|
-
|
|
24
|
-
it('normalize remoteEntryPath while remoteEntryPath startsWith "./"', () => {
|
|
25
|
-
const remoteEntry = {
|
|
26
|
-
name: 'vmok-remote-entry.js',
|
|
27
|
-
path: './dist/vmok',
|
|
28
|
-
};
|
|
29
|
-
expect(simpleJoinRemoteEntry(remoteEntry.path, remoteEntry.name)).toEqual(
|
|
30
|
-
`dist/vmok/${remoteEntry.name}`,
|
|
31
|
-
);
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
it('normalize remoteEntryPath while remoteEntryPath startsWith "/"', () => {
|
|
35
|
-
const remoteEntry = {
|
|
36
|
-
name: 'vmok-remote-entry.js',
|
|
37
|
-
path: '/dist/vmok',
|
|
38
|
-
};
|
|
39
|
-
expect(simpleJoinRemoteEntry(remoteEntry.path, remoteEntry.name)).toEqual(
|
|
40
|
-
`dist/vmok/${remoteEntry.name}`,
|
|
41
|
-
);
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
it('normalize remoteEntryPath while remoteEntryPath endsWith "/"', () => {
|
|
45
|
-
const remoteEntry = {
|
|
46
|
-
name: 'vmok-remote-entry.js',
|
|
47
|
-
path: '/dist/vmok/',
|
|
48
|
-
};
|
|
49
|
-
expect(simpleJoinRemoteEntry(remoteEntry.path, remoteEntry.name)).toEqual(
|
|
50
|
-
`dist/vmok/${remoteEntry.name}`,
|
|
51
|
-
);
|
|
52
|
-
});
|
|
53
|
-
});
|
package/jest.config.js
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
// For a detailed explanation regarding each configuration property, visit:
|
|
2
|
-
// https://jestjs.io/docs/en/configuration.html
|
|
3
|
-
|
|
4
|
-
module.exports = {
|
|
5
|
-
clearMocks: true,
|
|
6
|
-
testEnvironment: 'jsdom',
|
|
7
|
-
coveragePathIgnorePatterns: ['__tests__', '/node_modules/'],
|
|
8
|
-
coverageProvider: 'v8',
|
|
9
|
-
coverageReporters: ['cobertura', 'clover', 'json', 'lcov', 'text'],
|
|
10
|
-
globals: {
|
|
11
|
-
__DEV__: true,
|
|
12
|
-
__TEST__: true,
|
|
13
|
-
__BROWSER__: false,
|
|
14
|
-
__VERSION__: '"unknow"',
|
|
15
|
-
},
|
|
16
|
-
preset: 'ts-jest',
|
|
17
|
-
transformIgnorePatterns: [
|
|
18
|
-
// Change MODULE_NAME_HERE to your module that isn't being compiled
|
|
19
|
-
'/node_modules/(?!((@byted/garfish-)|(byted-tea-sdk))).+\\.js$',
|
|
20
|
-
],
|
|
21
|
-
transform: {
|
|
22
|
-
'^.+\\.(t|j)sx?$': ['@swc/jest'],
|
|
23
|
-
},
|
|
24
|
-
rootDir: __dirname,
|
|
25
|
-
testMatch: ['<rootDir>__tests__/**/**.spec.[jt]s?(x)'],
|
|
26
|
-
testPathIgnorePatterns: ['/node_modules/'],
|
|
27
|
-
};
|
package/project.json
DELETED
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "sdk",
|
|
3
|
-
"$schema": "../../node_modules/nx/schemas/project-schema.json",
|
|
4
|
-
"sourceRoot": "packages/sdk/src",
|
|
5
|
-
"projectType": "library",
|
|
6
|
-
"targets": {
|
|
7
|
-
"build": {
|
|
8
|
-
"executor": "@nx/rollup:rollup",
|
|
9
|
-
"outputs": ["{options.outputPath}"],
|
|
10
|
-
"options": {
|
|
11
|
-
"outputPath": "packages/sdk/dist",
|
|
12
|
-
"main": "packages/sdk/src/index.ts",
|
|
13
|
-
"tsConfig": "packages/sdk/tsconfig.lib.json",
|
|
14
|
-
"assets": [],
|
|
15
|
-
"external": ["@module-federation/*"],
|
|
16
|
-
"project": "packages/sdk/package.json",
|
|
17
|
-
"additionalEntryPoints": ["packages/sdk/src/normalize-webpack-path.ts"],
|
|
18
|
-
"rollupConfig": "packages/sdk/rollup.config.js",
|
|
19
|
-
"compiler": "swc",
|
|
20
|
-
"format": ["cjs", "esm"]
|
|
21
|
-
}
|
|
22
|
-
},
|
|
23
|
-
"lint": {
|
|
24
|
-
"executor": "@nx/linter:eslint",
|
|
25
|
-
"outputs": ["{options.outputFile}"],
|
|
26
|
-
"options": {
|
|
27
|
-
"lintFilePatterns": [
|
|
28
|
-
"packages/sdk/**/*.ts",
|
|
29
|
-
"packages/sdk/package.json"
|
|
30
|
-
]
|
|
31
|
-
}
|
|
32
|
-
},
|
|
33
|
-
"test": {
|
|
34
|
-
"executor": "@nx/jest:jest",
|
|
35
|
-
"outputs": ["{workspaceRoot}/coverage/{projectRoot}"],
|
|
36
|
-
"options": {
|
|
37
|
-
"jestConfig": "packages/sdk/jest.config.js",
|
|
38
|
-
"passWithNoTests": true
|
|
39
|
-
},
|
|
40
|
-
"configurations": {
|
|
41
|
-
"ci": {
|
|
42
|
-
"ci": true,
|
|
43
|
-
"codeCoverage": true
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
},
|
|
47
|
-
"pre-release": {
|
|
48
|
-
"executor": "nx:run-commands",
|
|
49
|
-
"options": {
|
|
50
|
-
"parallel": false,
|
|
51
|
-
"commands": [
|
|
52
|
-
{
|
|
53
|
-
"command": "nx run sdk:test",
|
|
54
|
-
"forwardAllArgs": false
|
|
55
|
-
},
|
|
56
|
-
{
|
|
57
|
-
"command": "nx run sdk:build",
|
|
58
|
-
"forwardAllArgs": false
|
|
59
|
-
}
|
|
60
|
-
]
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
},
|
|
64
|
-
"tags": ["package"]
|
|
65
|
-
}
|
package/rollup.config.js
DELETED
package/src/constant.ts
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
export const FederationModuleManifest = 'federation-manifest.json';
|
|
2
|
-
export const MANIFEST_EXT = '.json';
|
|
3
|
-
|
|
4
|
-
export const BROWSER_LOG_KEY = 'FEDERATION_DEBUG';
|
|
5
|
-
export const BROWSER_LOG_VALUE = '1';
|
|
6
|
-
|
|
7
|
-
export const NameTransformSymbol = {
|
|
8
|
-
AT: '@',
|
|
9
|
-
HYPHEN: '-',
|
|
10
|
-
SLASH: '/',
|
|
11
|
-
};
|
|
12
|
-
export const NameTransformMap = {
|
|
13
|
-
[NameTransformSymbol.AT]: 'scope_',
|
|
14
|
-
[NameTransformSymbol.HYPHEN]: '_',
|
|
15
|
-
[NameTransformSymbol.SLASH]: '__',
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
export const EncodedNameTransformMap = {
|
|
19
|
-
[NameTransformMap[NameTransformSymbol.AT]]: NameTransformSymbol.AT,
|
|
20
|
-
[NameTransformMap[NameTransformSymbol.HYPHEN]]: NameTransformSymbol.HYPHEN,
|
|
21
|
-
[NameTransformMap[NameTransformSymbol.SLASH]]: NameTransformSymbol.SLASH,
|
|
22
|
-
};
|
|
23
|
-
|
|
24
|
-
export const SEPARATOR = ':';
|
package/src/dom.ts
DELETED
|
@@ -1,115 +0,0 @@
|
|
|
1
|
-
import { warn } from './utils';
|
|
2
|
-
|
|
3
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
4
|
-
export async function safeWrapper<T extends (...args: Array<any>) => any>(
|
|
5
|
-
callback: T,
|
|
6
|
-
disableWarn?: boolean,
|
|
7
|
-
): Promise<ReturnType<T> | undefined> {
|
|
8
|
-
try {
|
|
9
|
-
const res = await callback();
|
|
10
|
-
return res;
|
|
11
|
-
} catch (e) {
|
|
12
|
-
!disableWarn && warn(e);
|
|
13
|
-
return;
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
export function isStaticResourcesEqual(url1: string, url2: string): boolean {
|
|
18
|
-
const REG_EXP = /^(https?:)?\/\//i;
|
|
19
|
-
// Transform url1 and url2 into relative paths
|
|
20
|
-
const relativeUrl1 = url1.replace(REG_EXP, '').replace(/\/$/, '');
|
|
21
|
-
const relativeUrl2 = url2.replace(REG_EXP, '').replace(/\/$/, '');
|
|
22
|
-
// Check if the relative paths are identical
|
|
23
|
-
return relativeUrl1 === relativeUrl2;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
export function createScript(
|
|
27
|
-
url: string,
|
|
28
|
-
cb: (value: void | PromiseLike<void>) => void,
|
|
29
|
-
attrs?: Record<string, any>,
|
|
30
|
-
createScriptHook?: (url: string) => HTMLScriptElement | void,
|
|
31
|
-
): { script: HTMLScriptElement; needAttach: boolean } {
|
|
32
|
-
// Retrieve the existing script element by its src attribute
|
|
33
|
-
let script: HTMLScriptElement | null = null;
|
|
34
|
-
let needAttach = true;
|
|
35
|
-
const scripts = document.getElementsByTagName('script');
|
|
36
|
-
for (let i = 0; i < scripts.length; i++) {
|
|
37
|
-
const s = scripts[i];
|
|
38
|
-
const scriptSrc = s.getAttribute('src');
|
|
39
|
-
if (scriptSrc && isStaticResourcesEqual(scriptSrc, url)) {
|
|
40
|
-
script = s;
|
|
41
|
-
needAttach = false;
|
|
42
|
-
break;
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
if (!script) {
|
|
47
|
-
script = document.createElement('script');
|
|
48
|
-
script.type = 'text/javascript';
|
|
49
|
-
script.src = url;
|
|
50
|
-
if (createScriptHook) {
|
|
51
|
-
const createScriptRes = createScriptHook(url);
|
|
52
|
-
if (createScriptRes instanceof HTMLScriptElement) {
|
|
53
|
-
script = createScriptRes;
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
if (attrs) {
|
|
59
|
-
Object.keys(attrs).forEach((name) => {
|
|
60
|
-
if (script) {
|
|
61
|
-
if (name === 'async' || name === 'defer') {
|
|
62
|
-
script[name] = attrs[name];
|
|
63
|
-
} else {
|
|
64
|
-
script.setAttribute(name, attrs[name]);
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
});
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
const onScriptComplete = (
|
|
71
|
-
prev: OnErrorEventHandler | GlobalEventHandlers['onload'] | null,
|
|
72
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
73
|
-
event: any,
|
|
74
|
-
): void => {
|
|
75
|
-
// Prevent memory leaks in IE.
|
|
76
|
-
if (script) {
|
|
77
|
-
script.onerror = null;
|
|
78
|
-
script.onload = null;
|
|
79
|
-
safeWrapper(() => {
|
|
80
|
-
script?.parentNode && script.parentNode.removeChild(script);
|
|
81
|
-
});
|
|
82
|
-
if (prev) {
|
|
83
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
84
|
-
const res = (prev as any)(event);
|
|
85
|
-
cb();
|
|
86
|
-
return res;
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
cb();
|
|
90
|
-
};
|
|
91
|
-
|
|
92
|
-
script.onerror = onScriptComplete.bind(null, script.onerror);
|
|
93
|
-
script.onload = onScriptComplete.bind(null, script.onload);
|
|
94
|
-
|
|
95
|
-
return { script, needAttach };
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
export function loadScript(
|
|
99
|
-
url: string,
|
|
100
|
-
info: {
|
|
101
|
-
attrs?: Record<string, any>;
|
|
102
|
-
createScriptHook?: (url: string) => HTMLScriptElement | void;
|
|
103
|
-
},
|
|
104
|
-
) {
|
|
105
|
-
const { attrs, createScriptHook } = info;
|
|
106
|
-
return new Promise<void>((resolve, _reject) => {
|
|
107
|
-
const { script, needAttach } = createScript(
|
|
108
|
-
url,
|
|
109
|
-
resolve,
|
|
110
|
-
attrs,
|
|
111
|
-
createScriptHook,
|
|
112
|
-
);
|
|
113
|
-
needAttach && document.getElementsByTagName('head')[0].appendChild(script);
|
|
114
|
-
});
|
|
115
|
-
}
|
package/src/env.ts
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
declare global {
|
|
2
|
-
// eslint-disable-next-line no-var
|
|
3
|
-
var FEDERATION_DEBUG: string | undefined;
|
|
4
|
-
}
|
|
5
|
-
|
|
6
|
-
function isBrowserEnv(): boolean {
|
|
7
|
-
return typeof window !== 'undefined';
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
function isDebugMode(): boolean {
|
|
11
|
-
if (
|
|
12
|
-
typeof process !== 'undefined' &&
|
|
13
|
-
process.env &&
|
|
14
|
-
process.env['FEDERATION_DEBUG']
|
|
15
|
-
) {
|
|
16
|
-
return Boolean(process.env['FEDERATION_DEBUG']);
|
|
17
|
-
}
|
|
18
|
-
return typeof FEDERATION_DEBUG !== 'undefined' && Boolean(FEDERATION_DEBUG);
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
const getProcessEnv = function (): Record<string, string | undefined> {
|
|
22
|
-
return typeof process !== 'undefined' && process.env ? process.env : {};
|
|
23
|
-
};
|
|
24
|
-
|
|
25
|
-
export { isBrowserEnv, isDebugMode, getProcessEnv };
|
|
@@ -1,176 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
Manifest,
|
|
3
|
-
ProviderModuleInfo,
|
|
4
|
-
ModuleInfo,
|
|
5
|
-
BasicProviderModuleInfo,
|
|
6
|
-
ConsumerModuleInfo,
|
|
7
|
-
ManifestProvider,
|
|
8
|
-
} from './types';
|
|
9
|
-
import { MANIFEST_EXT } from './constant';
|
|
10
|
-
|
|
11
|
-
interface IOptions {
|
|
12
|
-
remotes?: Record<string, string>;
|
|
13
|
-
overrides?: Record<string, string>;
|
|
14
|
-
version?: string;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
export const simpleJoinRemoteEntry = (rPath: string, rName: string): string => {
|
|
18
|
-
if (!rPath) {
|
|
19
|
-
return rName;
|
|
20
|
-
}
|
|
21
|
-
const transformPath = (str: string) => {
|
|
22
|
-
if (str === '.') {
|
|
23
|
-
return '';
|
|
24
|
-
}
|
|
25
|
-
if (str.startsWith('./')) {
|
|
26
|
-
return str.replace('./', '');
|
|
27
|
-
}
|
|
28
|
-
if (str.startsWith('/')) {
|
|
29
|
-
const strWithoutSlash = str.slice(1);
|
|
30
|
-
if (strWithoutSlash.endsWith('/')) {
|
|
31
|
-
return strWithoutSlash.slice(0, -1);
|
|
32
|
-
}
|
|
33
|
-
return strWithoutSlash;
|
|
34
|
-
}
|
|
35
|
-
return str;
|
|
36
|
-
};
|
|
37
|
-
|
|
38
|
-
const transformedPath = transformPath(rPath);
|
|
39
|
-
|
|
40
|
-
if (!transformedPath) {
|
|
41
|
-
return rName;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
if (transformedPath.endsWith('/')) {
|
|
45
|
-
return `${transformedPath}${rName}`;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
return `${transformedPath}/${rName}`;
|
|
49
|
-
};
|
|
50
|
-
|
|
51
|
-
// Priority: overrides > remotes
|
|
52
|
-
// eslint-disable-next-line max-lines-per-function
|
|
53
|
-
export function generateSnapshotFromManifest(
|
|
54
|
-
manifest: Manifest,
|
|
55
|
-
options: IOptions = {},
|
|
56
|
-
): ProviderModuleInfo {
|
|
57
|
-
const { remotes = {}, overrides = {}, version } = options;
|
|
58
|
-
let remoteSnapshot: ProviderModuleInfo;
|
|
59
|
-
|
|
60
|
-
const getPublicPath = (): string => {
|
|
61
|
-
if ('publicPath' in manifest.metaData) {
|
|
62
|
-
return manifest.metaData.publicPath;
|
|
63
|
-
} else {
|
|
64
|
-
return manifest.metaData.getPublicPath;
|
|
65
|
-
}
|
|
66
|
-
};
|
|
67
|
-
|
|
68
|
-
const overridesKeys = Object.keys(overrides);
|
|
69
|
-
|
|
70
|
-
let remotesInfo: ConsumerModuleInfo['remotesInfo'] = {};
|
|
71
|
-
|
|
72
|
-
// If remotes are not provided, only the remotes in the manifest will be read
|
|
73
|
-
if (!Object.keys(remotes).length) {
|
|
74
|
-
remotesInfo =
|
|
75
|
-
manifest.remotes?.reduce(
|
|
76
|
-
(res, next) => {
|
|
77
|
-
let matchedVersion: string;
|
|
78
|
-
const name = next.federationContainerName;
|
|
79
|
-
// overrides have higher priority
|
|
80
|
-
if (overridesKeys.includes(name)) {
|
|
81
|
-
matchedVersion = overrides[name];
|
|
82
|
-
} else {
|
|
83
|
-
if ('version' in next) {
|
|
84
|
-
matchedVersion = next.version;
|
|
85
|
-
} else {
|
|
86
|
-
matchedVersion = next.entry;
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
res[name] = {
|
|
90
|
-
matchedVersion,
|
|
91
|
-
};
|
|
92
|
-
return res;
|
|
93
|
-
},
|
|
94
|
-
{} as ConsumerModuleInfo['remotesInfo'],
|
|
95
|
-
) || {};
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
// If remotes (deploy scenario) are specified, they need to be traversed again
|
|
99
|
-
Object.keys(remotes).forEach(
|
|
100
|
-
(key) =>
|
|
101
|
-
(remotesInfo[key] = {
|
|
102
|
-
// overrides will override dependencies
|
|
103
|
-
matchedVersion: overridesKeys.includes(key)
|
|
104
|
-
? overrides[key]
|
|
105
|
-
: remotes[key],
|
|
106
|
-
}),
|
|
107
|
-
);
|
|
108
|
-
|
|
109
|
-
const {
|
|
110
|
-
remoteEntry: {
|
|
111
|
-
path: remoteEntryPath,
|
|
112
|
-
name: remoteEntryName,
|
|
113
|
-
type: remoteEntryType,
|
|
114
|
-
},
|
|
115
|
-
types: remoteTypes,
|
|
116
|
-
buildInfo: { buildVersion },
|
|
117
|
-
globalName,
|
|
118
|
-
} = manifest.metaData;
|
|
119
|
-
const { exposes } = manifest;
|
|
120
|
-
|
|
121
|
-
let basicRemoteSnapshot: BasicProviderModuleInfo = {
|
|
122
|
-
version: version ? version : '',
|
|
123
|
-
buildVersion,
|
|
124
|
-
globalName,
|
|
125
|
-
remoteEntry: simpleJoinRemoteEntry(remoteEntryPath, remoteEntryName),
|
|
126
|
-
remoteEntryType,
|
|
127
|
-
remoteTypes: simpleJoinRemoteEntry(remoteTypes.path, remoteTypes.name),
|
|
128
|
-
remotesInfo,
|
|
129
|
-
shared: manifest?.shared.map((item) => ({
|
|
130
|
-
assets: item.assets,
|
|
131
|
-
sharedName: item.name,
|
|
132
|
-
})),
|
|
133
|
-
modules: exposes?.map((expose) => ({
|
|
134
|
-
moduleName: expose.name,
|
|
135
|
-
modulePath: expose.path,
|
|
136
|
-
assets: expose.assets,
|
|
137
|
-
})),
|
|
138
|
-
};
|
|
139
|
-
|
|
140
|
-
if (manifest.metaData?.prefetchEntry) {
|
|
141
|
-
const { path, name, type } = manifest.metaData.prefetchEntry;
|
|
142
|
-
|
|
143
|
-
basicRemoteSnapshot = {
|
|
144
|
-
...basicRemoteSnapshot,
|
|
145
|
-
prefetchEntry: simpleJoinRemoteEntry(path, name),
|
|
146
|
-
prefetchEntryType: type,
|
|
147
|
-
};
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
if ('publicPath' in manifest.metaData) {
|
|
151
|
-
remoteSnapshot = {
|
|
152
|
-
...basicRemoteSnapshot,
|
|
153
|
-
publicPath: getPublicPath(),
|
|
154
|
-
};
|
|
155
|
-
} else {
|
|
156
|
-
remoteSnapshot = {
|
|
157
|
-
...basicRemoteSnapshot,
|
|
158
|
-
getPublicPath: getPublicPath(),
|
|
159
|
-
};
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
return remoteSnapshot;
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
export function isManifestProvider(
|
|
166
|
-
moduleInfo: ModuleInfo | ManifestProvider,
|
|
167
|
-
): moduleInfo is ManifestProvider {
|
|
168
|
-
if (
|
|
169
|
-
'remoteEntry' in moduleInfo &&
|
|
170
|
-
moduleInfo.remoteEntry.endsWith(MANIFEST_EXT)
|
|
171
|
-
) {
|
|
172
|
-
return true;
|
|
173
|
-
} else {
|
|
174
|
-
return false;
|
|
175
|
-
}
|
|
176
|
-
}
|
package/src/logger.ts
DELETED
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
import { BROWSER_LOG_KEY, BROWSER_LOG_VALUE } from './constant';
|
|
2
|
-
import { isBrowserEnv, isDebugMode } from './env';
|
|
3
|
-
|
|
4
|
-
function safeToString(info: any): string {
|
|
5
|
-
try {
|
|
6
|
-
return JSON.stringify(info, null, 2);
|
|
7
|
-
} catch (e) {
|
|
8
|
-
return '';
|
|
9
|
-
}
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
const DEBUG_LOG = '[ FEDERATION DEBUG ]';
|
|
13
|
-
|
|
14
|
-
class Logger {
|
|
15
|
-
enable = false;
|
|
16
|
-
identifier: string;
|
|
17
|
-
constructor(identifier?: string) {
|
|
18
|
-
this.identifier = identifier || DEBUG_LOG;
|
|
19
|
-
if (
|
|
20
|
-
isBrowserEnv() &&
|
|
21
|
-
localStorage.getItem(BROWSER_LOG_KEY) === BROWSER_LOG_VALUE
|
|
22
|
-
) {
|
|
23
|
-
this.enable = true;
|
|
24
|
-
} else if (isDebugMode()) {
|
|
25
|
-
this.enable = true;
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
info(msg: string, info?: any): void {
|
|
29
|
-
if (this.enable) {
|
|
30
|
-
const argsToString = safeToString(info) || '';
|
|
31
|
-
if (isBrowserEnv()) {
|
|
32
|
-
console.info(
|
|
33
|
-
`%c ${this.identifier}: ${msg} ${argsToString}`,
|
|
34
|
-
'color:#3300CC',
|
|
35
|
-
);
|
|
36
|
-
} else {
|
|
37
|
-
console.info(
|
|
38
|
-
'\x1b[34m%s',
|
|
39
|
-
`${this.identifier}: ${msg} ${
|
|
40
|
-
argsToString ? `\n${argsToString}` : ''
|
|
41
|
-
}`,
|
|
42
|
-
);
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
logOriginalInfo(...args: unknown[]) {
|
|
47
|
-
if (this.enable) {
|
|
48
|
-
if (isBrowserEnv()) {
|
|
49
|
-
console.info(`%c ${this.identifier}: OriginalInfo`, 'color:#3300CC');
|
|
50
|
-
console.log(...args);
|
|
51
|
-
} else {
|
|
52
|
-
console.info(`%c ${this.identifier}: OriginalInfo`, 'color:#3300CC');
|
|
53
|
-
console.log(...args);
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
export { Logger };
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import type webpack from 'webpack';
|
|
2
|
-
import path from 'path';
|
|
3
|
-
export function getWebpackPath(compiler: webpack.Compiler): string {
|
|
4
|
-
try {
|
|
5
|
-
// @ts-ignore just throw err
|
|
6
|
-
compiler.webpack();
|
|
7
|
-
return '';
|
|
8
|
-
} catch (err) {
|
|
9
|
-
const trace = (err as Error).stack?.split('\n') || [];
|
|
10
|
-
const webpackErrLocation =
|
|
11
|
-
trace.find((item) => item.includes('at webpack')) || '';
|
|
12
|
-
const webpackLocationWithDetail = webpackErrLocation
|
|
13
|
-
.replace(/[^\(\)]+/, '')
|
|
14
|
-
.slice(1, -1);
|
|
15
|
-
const webpackPath = webpackLocationWithDetail.split(':').slice(0, -2)[0];
|
|
16
|
-
return require.resolve('webpack', { paths: [webpackPath] });
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
export const normalizeWebpackPath = (fullPath: string): string => {
|
|
21
|
-
if (fullPath === 'webpack') {
|
|
22
|
-
return process.env['FEDERATION_WEBPACK_PATH'] || fullPath;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
if (process.env['FEDERATION_WEBPACK_PATH']) {
|
|
26
|
-
return path.resolve(
|
|
27
|
-
process.env['FEDERATION_WEBPACK_PATH'],
|
|
28
|
-
fullPath.replace('webpack', '../../'),
|
|
29
|
-
);
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
return fullPath;
|
|
33
|
-
};
|
package/src/types/manifest.ts
DELETED
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
StatsMetaData,
|
|
3
|
-
StatsAssets,
|
|
4
|
-
StatsExpose,
|
|
5
|
-
BasicStatsMetaData,
|
|
6
|
-
} from './stats';
|
|
7
|
-
import { RemoteWithEntry, RemoteWithVersion } from './common';
|
|
8
|
-
|
|
9
|
-
export interface ManifestShared {
|
|
10
|
-
id: string;
|
|
11
|
-
name: string;
|
|
12
|
-
version: string;
|
|
13
|
-
singleton: boolean;
|
|
14
|
-
requiredVersion: string;
|
|
15
|
-
hash: string;
|
|
16
|
-
assets: StatsAssets;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
export interface ManifestRemoteCommonInfo {
|
|
20
|
-
federationContainerName: string;
|
|
21
|
-
moduleName: string;
|
|
22
|
-
alias: string;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
export type ManifestRemote<T = ManifestRemoteCommonInfo> =
|
|
26
|
-
| (Omit<RemoteWithEntry, 'name'> & T)
|
|
27
|
-
| (Omit<RemoteWithVersion, 'name'> & T);
|
|
28
|
-
|
|
29
|
-
export type ManifestExpose = Pick<
|
|
30
|
-
StatsExpose,
|
|
31
|
-
'assets' | 'id' | 'name' | 'path'
|
|
32
|
-
>;
|
|
33
|
-
|
|
34
|
-
export interface Manifest<
|
|
35
|
-
T = BasicStatsMetaData,
|
|
36
|
-
K = ManifestRemoteCommonInfo,
|
|
37
|
-
> {
|
|
38
|
-
id: string;
|
|
39
|
-
name: string;
|
|
40
|
-
metaData: StatsMetaData<T>;
|
|
41
|
-
shared: ManifestShared[];
|
|
42
|
-
remotes: ManifestRemote<K>[];
|
|
43
|
-
exposes: ManifestExpose[];
|
|
44
|
-
}
|