@module-federation/sdk 0.0.0-next-20231220075820 → 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.
Files changed (47) hide show
  1. package/dist/LICENSE +21 -0
  2. package/dist/index.cjs.d.ts +1 -0
  3. package/dist/index.cjs.js +793 -0
  4. package/dist/index.esm.js +761 -0
  5. package/dist/normalize-webpack-path.cjs.d.ts +1 -0
  6. package/dist/normalize-webpack-path.cjs.js +42 -0
  7. package/dist/normalize-webpack-path.esm.js +33 -0
  8. package/dist/package.json +44 -0
  9. package/dist/src/constant.d.ts +16 -0
  10. package/dist/src/dom.d.ts +10 -0
  11. package/dist/src/env.d.ts +7 -0
  12. package/dist/src/generateSnapshotFromManifest.d.ts +10 -0
  13. package/{src/index.ts → dist/src/index.d.ts} +1 -4
  14. package/dist/src/logger.d.ts +8 -0
  15. package/dist/src/normalize-webpack-path.d.ts +3 -0
  16. package/{src/types/common.ts → dist/src/types/common.d.ts} +4 -12
  17. package/dist/src/types/manifest.d.ts +26 -0
  18. package/dist/src/types/snapshot.d.ts +62 -0
  19. package/dist/src/types/stats.d.ts +79 -0
  20. package/dist/src/utils.d.ts +17 -0
  21. package/package.json +5 -1
  22. package/CHANGELOG.md +0 -2190
  23. package/__tests__/decodeName.spec.ts +0 -11
  24. package/__tests__/encodeName.spec.ts +0 -10
  25. package/__tests__/generateSnapshotFromManifest.spec.ts +0 -147
  26. package/__tests__/parseEntry.spec.ts +0 -36
  27. package/__tests__/resources/constant.ts +0 -6
  28. package/__tests__/resources/getId.ts +0 -5
  29. package/__tests__/resources/manifestSnapshotMap.ts +0 -1541
  30. package/__tests__/simpleJoinRemoteEntry.spec.ts +0 -53
  31. package/jest.config.js +0 -27
  32. package/project.json +0 -65
  33. package/rollup.config.js +0 -11
  34. package/src/constant.ts +0 -24
  35. package/src/dom.ts +0 -115
  36. package/src/env.ts +0 -25
  37. package/src/generateSnapshotFromManifest.ts +0 -176
  38. package/src/logger.ts +0 -59
  39. package/src/normalize-webpack-path.ts +0 -33
  40. package/src/types/manifest.ts +0 -44
  41. package/src/types/snapshot.ts +0 -87
  42. package/src/types/stats.ts +0 -101
  43. package/src/utils.ts +0 -213
  44. package/tsconfig.json +0 -29
  45. package/tsconfig.lib.json +0 -10
  46. package/tsconfig.spec.json +0 -14
  47. /package/{src/types/index.ts → dist/src/types/index.d.ts} +0 -0
@@ -1,87 +0,0 @@
1
- import { RemoteEntryType, StatsAssets } from './stats';
2
-
3
- interface BasicModuleInfo {
4
- dev?: {
5
- version?: string;
6
- remotes?: { [nameWithType: string]: string };
7
- };
8
- version: string;
9
- buildVersion: string;
10
- remoteTypes: string;
11
- remotesInfo: Record<string, { matchedVersion: string }>;
12
- shared: Array<{
13
- sharedName: string;
14
- assets: StatsAssets;
15
- }>;
16
- }
17
-
18
- export interface BasicProviderModuleInfo extends BasicModuleInfo {
19
- remoteEntry: string;
20
- remoteEntryType: RemoteEntryType;
21
- remoteManifest?: string;
22
- globalName: string;
23
- modules: Array<{
24
- moduleName: string;
25
- modulePath?: string;
26
- assets: StatsAssets;
27
- }>;
28
- prefetchEntry?: string;
29
- prefetchEntryType?: RemoteEntryType;
30
- }
31
-
32
- interface BasicProviderModuleInfoWithPublicPath
33
- extends BasicProviderModuleInfo {
34
- publicPath: string;
35
- }
36
-
37
- interface BasicProviderModuleInfoWithGetPublicPath
38
- extends BasicProviderModuleInfo {
39
- getPublicPath: string;
40
- }
41
-
42
- export interface ManifestProvider {
43
- remoteEntry: string;
44
- version?: string;
45
- }
46
-
47
- export interface PureEntryProvider extends ManifestProvider {
48
- globalName: string;
49
- }
50
-
51
- interface BasicConsumerModuleInfo extends BasicModuleInfo {
52
- consumerList: Array<string>;
53
- }
54
-
55
- export interface ConsumerModuleInfoWithPublicPath
56
- extends BasicConsumerModuleInfo,
57
- BasicProviderModuleInfo {
58
- publicPath: string;
59
- }
60
-
61
- interface ConsumerModuleInfoWithGetPublicPath
62
- extends BasicConsumerModuleInfo,
63
- BasicProviderModuleInfo {
64
- getPublicPath: string;
65
- }
66
-
67
- export type PureConsumerModuleInfo = Omit<
68
- BasicConsumerModuleInfo,
69
- 'remoteTypes'
70
- >;
71
-
72
- export type ConsumerModuleInfo =
73
- | ConsumerModuleInfoWithPublicPath
74
- | ConsumerModuleInfoWithGetPublicPath;
75
-
76
- export type ProviderModuleInfo =
77
- | BasicProviderModuleInfoWithPublicPath
78
- | BasicProviderModuleInfoWithGetPublicPath;
79
-
80
- export type ModuleInfo =
81
- | ConsumerModuleInfo
82
- | PureConsumerModuleInfo
83
- | ProviderModuleInfo;
84
-
85
- export type GlobalModuleInfo = {
86
- [key: string]: ModuleInfo | ManifestProvider | PureEntryProvider | undefined;
87
- };
@@ -1,101 +0,0 @@
1
- import type { RemoteWithEntry, RemoteWithVersion } from './common';
2
-
3
- export type RemoteEntryType = 'esm' | 'global';
4
-
5
- interface ResourceInfo {
6
- path: string;
7
- name: string;
8
- type: RemoteEntryType;
9
- }
10
-
11
- export interface StatsBuildInfo {
12
- buildVersion: string;
13
- buildName: string;
14
- }
15
-
16
- export interface BasicStatsMetaData {
17
- name: string;
18
- globalName: string;
19
- buildInfo: StatsBuildInfo;
20
- remoteEntry: ResourceInfo;
21
- prefetchEntry: ResourceInfo;
22
- types: Omit<ResourceInfo, 'type'>;
23
- }
24
-
25
- type StatsMetaDataWithGetPublicPath<T = BasicStatsMetaData> = T & {
26
- getPublicPath: string;
27
- };
28
-
29
- type StatsMetaDataWithPublicPath<T = BasicStatsMetaData> = T & {
30
- publicPath: string;
31
- };
32
-
33
- export type StatsMetaData<T = BasicStatsMetaData> =
34
- | StatsMetaDataWithGetPublicPath<T>
35
- | StatsMetaDataWithPublicPath<T>;
36
-
37
- export interface StatsAssets {
38
- js: StatsAssetsInfo;
39
- css: StatsAssetsInfo;
40
- }
41
-
42
- interface StatsAssetsInfo {
43
- sync: string[];
44
- async: string[];
45
- }
46
-
47
- export interface StatsShared {
48
- id: string;
49
- name: string;
50
- version: string;
51
- singleton: boolean;
52
- requiredVersion: string;
53
- hash: string;
54
- assets: StatsAssets;
55
- deps: string[];
56
- usedIn: string[];
57
- }
58
- // extends Omit<RemoteEntryInfo, 'name'>
59
- export interface StatsRemoteVal {
60
- moduleName: string;
61
- federationContainerName: string;
62
- consumingFederationContainerName: string;
63
- alias: string;
64
- usedIn: string[];
65
- }
66
-
67
- export type StatsRemoteWithEntry<T = StatsRemoteVal> = T &
68
- Omit<RemoteWithEntry, 'name'>;
69
- export type StatsRemoteWithVersion<T = StatsRemoteVal> = T &
70
- Omit<RemoteWithVersion, 'name'>;
71
-
72
- export type StatsRemote<T = StatsRemoteVal> =
73
- | StatsRemoteWithEntry<T>
74
- | StatsRemoteWithVersion<T>;
75
-
76
- export interface StatsModuleInfo {
77
- name: string;
78
- file: string;
79
- }
80
-
81
- export interface ManifestModuleInfos {
82
- [exposeModuleName: string]: StatsModuleInfo;
83
- }
84
-
85
- export interface StatsExpose {
86
- id: string;
87
- name: string;
88
- path?: string; // 对线上已有数据兼容过渡至 2023-05-26
89
- file: string;
90
- requires: string[];
91
- assets: StatsAssets;
92
- }
93
-
94
- export interface Stats<T = BasicStatsMetaData, K = StatsRemoteVal> {
95
- id: string;
96
- name: string;
97
- metaData: StatsMetaData<T>;
98
- shared: StatsShared[];
99
- remotes: StatsRemote<K>[];
100
- exposes: StatsExpose[];
101
- }
package/src/utils.ts DELETED
@@ -1,213 +0,0 @@
1
- import { RemoteEntryInfo, ModuleInfo } from './types';
2
- import {
3
- NameTransformMap,
4
- NameTransformSymbol,
5
- EncodedNameTransformMap,
6
- SEPARATOR,
7
- MANIFEST_EXT,
8
- } from './constant';
9
- import { Logger } from './logger';
10
- import { getProcessEnv } from './env';
11
-
12
- const LOG_CATEGORY = '[ Federation Runtime ]';
13
-
14
- // entry: name:version version : 1.0.0 | ^1.2.3
15
- // entry: name:entry entry: https://localhost:9000/federation-manifest.json
16
- const parseEntry = (str: string, devVerOrUrl?: string): RemoteEntryInfo => {
17
- const strSplit = str.split(SEPARATOR);
18
- const devVersionOrUrl =
19
- getProcessEnv()['NODE_ENV'] === 'development' && devVerOrUrl;
20
- const defaultVersion = '*';
21
- const isEntry = (s: string) =>
22
- s.startsWith('http') || s.endsWith(MANIFEST_EXT);
23
-
24
- // Check if the string starts with a type
25
- if (strSplit.length >= 2) {
26
- const [name, ...versionOrEntryArr] = strSplit;
27
- const versionOrEntry = devVersionOrUrl || versionOrEntryArr.join(SEPARATOR);
28
- if (isEntry(versionOrEntry)) {
29
- return {
30
- name,
31
- entry: versionOrEntry,
32
- };
33
- } else {
34
- // Apply version rule
35
- // devVersionOrUrl => inputVersion => defaultVersion
36
- return {
37
- name,
38
- version: versionOrEntry || defaultVersion,
39
- };
40
- }
41
- } else if (strSplit.length === 1) {
42
- const [name] = strSplit;
43
- if (devVersionOrUrl && isEntry(devVersionOrUrl)) {
44
- return {
45
- name,
46
- entry: devVersionOrUrl,
47
- };
48
- }
49
- return {
50
- name,
51
- version: devVersionOrUrl || defaultVersion,
52
- };
53
- } else {
54
- throw `Invalid entry value: ${str}`;
55
- }
56
- };
57
-
58
- declare global {
59
- // eslint-disable-next-line no-var
60
- var FEDERATION_DEBUG: string | undefined;
61
- }
62
-
63
- const logger = new Logger();
64
-
65
- const composeKeyWithSeparator = /* @__PURE__ */ function (
66
- ...args: (string | undefined)[]
67
- ): string {
68
- if (!args.length) {
69
- return '';
70
- }
71
-
72
- return args.reduce((sum, cur) => {
73
- if (!cur) {
74
- return sum;
75
- }
76
- if (!sum) {
77
- return cur;
78
- }
79
-
80
- return `${sum}${SEPARATOR}${cur}`;
81
- }, '') as string;
82
- };
83
-
84
- const encodeName = /* @__PURE__ */ function (
85
- name: string,
86
- prefix = '',
87
- withExt = false,
88
- ): string {
89
- try {
90
- const ext = withExt ? '.js' : '';
91
- return `${prefix}${name
92
- .replace(
93
- new RegExp(`${NameTransformSymbol.AT}`, 'g'),
94
- NameTransformMap[NameTransformSymbol.AT],
95
- )
96
- .replace(
97
- new RegExp(`${NameTransformSymbol.HYPHEN}`, 'g'),
98
- NameTransformMap[NameTransformSymbol.HYPHEN],
99
- )
100
- .replace(
101
- new RegExp(`${NameTransformSymbol.SLASH}`, 'g'),
102
- NameTransformMap[NameTransformSymbol.SLASH],
103
- )}${ext}`;
104
- } catch (err) {
105
- throw err;
106
- }
107
- };
108
-
109
- const decodeName = /* @__PURE__ */ function (
110
- name: string,
111
- prefix?: string,
112
- withExt?: boolean,
113
- ): string {
114
- try {
115
- let decodedName = name;
116
- if (prefix) {
117
- decodedName = decodedName.replace(new RegExp(prefix, 'g'), '');
118
- }
119
- decodedName = decodedName
120
- .replace(
121
- new RegExp(`${NameTransformMap[NameTransformSymbol.AT]}`, 'g'),
122
- EncodedNameTransformMap[NameTransformMap[NameTransformSymbol.AT]],
123
- )
124
- .replace(
125
- new RegExp(`${NameTransformMap[NameTransformSymbol.SLASH]}`, 'g'),
126
- EncodedNameTransformMap[NameTransformMap[NameTransformSymbol.SLASH]],
127
- )
128
- .replace(
129
- new RegExp(`${NameTransformMap[NameTransformSymbol.HYPHEN]}`, 'g'),
130
- EncodedNameTransformMap[NameTransformMap[NameTransformSymbol.HYPHEN]],
131
- );
132
- if (withExt) {
133
- decodedName = decodedName.replace('.js', '');
134
- }
135
- return decodedName;
136
- } catch (err) {
137
- throw err;
138
- }
139
- };
140
-
141
- const generateExposeFilename = /* @__PURE__ */ (
142
- exposeName: string,
143
- withExt: boolean,
144
- ): string => {
145
- if (!exposeName) {
146
- return '';
147
- }
148
-
149
- let expose = exposeName;
150
- if (expose === '.') {
151
- expose = 'default_export';
152
- }
153
- if (expose.startsWith('./')) {
154
- expose = expose.replace('./', '');
155
- }
156
-
157
- return encodeName(expose, '__federation_expose_', withExt);
158
- };
159
-
160
- const generateShareFilename = /* @__PURE__ */ (
161
- pkgName: string,
162
- withExt: boolean,
163
- ): string => {
164
- if (!pkgName) {
165
- return '';
166
- }
167
- return encodeName(pkgName, '__federation_shared_', withExt);
168
- };
169
-
170
- const getResourceUrl = (module: ModuleInfo, sourceUrl: string): string => {
171
- if ('getPublicPath' in module) {
172
- const publicPath = new Function(module.getPublicPath)();
173
- return `${publicPath}${sourceUrl}`;
174
- } else if ('publicPath' in module) {
175
- return `${module.publicPath}${sourceUrl}`;
176
- } else {
177
- console.warn(
178
- 'Can not get resource url, if in debug mode, please ignore',
179
- module,
180
- sourceUrl,
181
- );
182
- return '';
183
- }
184
- };
185
-
186
- // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
187
- const assert = (condition: any, msg: string): asserts condition => {
188
- if (!condition) {
189
- error(msg);
190
- }
191
- };
192
-
193
- const error = (msg: string | Error | unknown): never => {
194
- throw new Error(`${LOG_CATEGORY}: ${msg}`);
195
- };
196
-
197
- const warn = (msg: Parameters<typeof console.warn>[0]): void => {
198
- console.warn(`${LOG_CATEGORY}: ${msg}`);
199
- };
200
-
201
- export {
202
- parseEntry,
203
- logger,
204
- decodeName,
205
- encodeName,
206
- composeKeyWithSeparator,
207
- generateExposeFilename,
208
- generateShareFilename,
209
- getResourceUrl,
210
- assert,
211
- error,
212
- warn,
213
- };
package/tsconfig.json DELETED
@@ -1,29 +0,0 @@
1
- {
2
- "extends": "../../tsconfig.base.json",
3
- "compilerOptions": {
4
- "module": "commonjs",
5
- "forceConsistentCasingInFileNames": true,
6
- "strict": true,
7
- "noImplicitOverride": true,
8
- "noPropertyAccessFromIndexSignature": true,
9
- "noImplicitReturns": true,
10
- "noFallthroughCasesInSwitch": true,
11
- "moduleResolution": "node",
12
- "resolveJsonModule": true,
13
- "esModuleInterop": true,
14
- "skipLibCheck": true,
15
- "skipDefaultLibCheck": true,
16
- "declaration": true
17
- },
18
- "files": [],
19
- "include": [],
20
- "exclude": ["node_modules"],
21
- "references": [
22
- {
23
- "path": "./tsconfig.lib.json"
24
- },
25
- {
26
- "path": "./tsconfig.spec.json"
27
- }
28
- ]
29
- }
package/tsconfig.lib.json DELETED
@@ -1,10 +0,0 @@
1
- {
2
- "extends": "./tsconfig.json",
3
- "compilerOptions": {
4
- "outDir": "../../dist/out-tsc",
5
- "declaration": true,
6
- "types": ["node"]
7
- },
8
- "include": ["src/**/*.ts"],
9
- "exclude": ["jest.config.ts", "src/**/*.spec.ts", "src/**/*.test.ts"]
10
- }
@@ -1,14 +0,0 @@
1
- {
2
- "extends": "./tsconfig.json",
3
- "compilerOptions": {
4
- "outDir": "../../dist/out-tsc",
5
- "module": "commonjs",
6
- "types": ["jest", "node"]
7
- },
8
- "include": [
9
- "jest.config.ts",
10
- "src/**/*.test.ts",
11
- "src/**/*.spec.ts",
12
- "src/**/*.d.ts"
13
- ]
14
- }