@module-federation/sdk 0.3.0 → 0.3.1

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 (40) hide show
  1. package/README.md +99 -0
  2. package/dist/LICENSE +21 -0
  3. package/dist/index.cjs.js +749 -0
  4. package/dist/index.esm.js +701 -0
  5. package/dist/normalize-webpack-path.cjs.js +48 -0
  6. package/dist/normalize-webpack-path.esm.js +39 -0
  7. package/dist/package.json +44 -0
  8. package/{src → dist/src}/constant.d.ts +9 -0
  9. package/dist/src/dom.d.ts +30 -0
  10. package/{src → dist/src}/generateSnapshotFromManifest.d.ts +1 -0
  11. package/dist/src/index.d.ts +9 -0
  12. package/dist/src/node.d.ts +5 -0
  13. package/{src → dist/src}/normalize-webpack-path.d.ts +3 -1
  14. package/dist/src/normalizeOptions.d.ts +1 -0
  15. package/{src → dist/src}/types/index.d.ts +1 -0
  16. package/dist/src/types/plugins/ContainerPlugin.d.ts +159 -0
  17. package/dist/src/types/plugins/ContainerReferencePlugin.d.ts +52 -0
  18. package/dist/src/types/plugins/ModuleFederationPlugin.d.ts +334 -0
  19. package/dist/src/types/plugins/SharePlugin.d.ts +71 -0
  20. package/dist/src/types/plugins/index.d.ts +4 -0
  21. package/{src → dist/src}/types/snapshot.d.ts +7 -0
  22. package/{src → dist/src}/types/stats.d.ts +15 -5
  23. package/{src → dist/src}/utils.d.ts +1 -1
  24. package/package.json +14 -11
  25. package/index.cjs.default.js +0 -1
  26. package/index.cjs.js +0 -793
  27. package/index.cjs.mjs +0 -2
  28. package/index.esm.js +0 -761
  29. package/normalize-webpack-path.cjs.default.js +0 -1
  30. package/normalize-webpack-path.cjs.js +0 -42
  31. package/normalize-webpack-path.cjs.mjs +0 -2
  32. package/normalize-webpack-path.esm.js +0 -33
  33. package/src/dom.d.ts +0 -10
  34. package/src/index.d.ts +0 -7
  35. /package/{index.cjs.d.ts → dist/index.cjs.d.ts} +0 -0
  36. /package/{normalize-webpack-path.cjs.d.ts → dist/normalize-webpack-path.cjs.d.ts} +0 -0
  37. /package/{src → dist/src}/env.d.ts +0 -0
  38. /package/{src → dist/src}/logger.d.ts +0 -0
  39. /package/{src → dist/src}/types/common.d.ts +0 -0
  40. /package/{src → dist/src}/types/manifest.d.ts +0 -0
@@ -0,0 +1,48 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var path = require('path');
6
+
7
+ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
8
+
9
+ var path__default = /*#__PURE__*/_interopDefaultLegacy(path);
10
+
11
+ function getWebpackPath(compiler, options = {
12
+ framework: 'other'
13
+ }) {
14
+ try {
15
+ // @ts-ignore just throw err
16
+ compiler.webpack();
17
+ return '';
18
+ } catch (err) {
19
+ var _err_stack;
20
+ const trace = ((_err_stack = err.stack) == null ? void 0 : _err_stack.split('\n')) || [];
21
+ const webpackErrLocation = trace.find((item)=>item.includes('at webpack')) || '';
22
+ const webpackLocationWithDetail = webpackErrLocation.replace(/[^\(\)]+/, '').slice(1, -1);
23
+ const webpackPath = webpackLocationWithDetail.split(':').slice(0, -2).join(':');
24
+ if ((options == null ? void 0 : options.framework) === 'nextjs') {
25
+ if (webpackPath.endsWith('webpack.js')) {
26
+ return webpackPath.replace('webpack.js', 'index.js');
27
+ }
28
+ return '';
29
+ }
30
+ return require.resolve('webpack', {
31
+ paths: [
32
+ webpackPath
33
+ ]
34
+ });
35
+ }
36
+ }
37
+ const normalizeWebpackPath = (fullPath)=>{
38
+ if (fullPath === 'webpack') {
39
+ return process.env['FEDERATION_WEBPACK_PATH'] || fullPath;
40
+ }
41
+ if (process.env['FEDERATION_WEBPACK_PATH']) {
42
+ return path__default["default"].resolve(process.env['FEDERATION_WEBPACK_PATH'], fullPath.replace('webpack', '../../'));
43
+ }
44
+ return fullPath;
45
+ };
46
+
47
+ exports.getWebpackPath = getWebpackPath;
48
+ exports.normalizeWebpackPath = normalizeWebpackPath;
@@ -0,0 +1,39 @@
1
+ import path from 'path';
2
+
3
+ function getWebpackPath(compiler, options = {
4
+ framework: 'other'
5
+ }) {
6
+ try {
7
+ // @ts-ignore just throw err
8
+ compiler.webpack();
9
+ return '';
10
+ } catch (err) {
11
+ var _err_stack;
12
+ const trace = ((_err_stack = err.stack) == null ? void 0 : _err_stack.split('\n')) || [];
13
+ const webpackErrLocation = trace.find((item)=>item.includes('at webpack')) || '';
14
+ const webpackLocationWithDetail = webpackErrLocation.replace(/[^\(\)]+/, '').slice(1, -1);
15
+ const webpackPath = webpackLocationWithDetail.split(':').slice(0, -2).join(':');
16
+ if ((options == null ? void 0 : options.framework) === 'nextjs') {
17
+ if (webpackPath.endsWith('webpack.js')) {
18
+ return webpackPath.replace('webpack.js', 'index.js');
19
+ }
20
+ return '';
21
+ }
22
+ return require.resolve('webpack', {
23
+ paths: [
24
+ webpackPath
25
+ ]
26
+ });
27
+ }
28
+ }
29
+ const normalizeWebpackPath = (fullPath)=>{
30
+ if (fullPath === 'webpack') {
31
+ return process.env['FEDERATION_WEBPACK_PATH'] || fullPath;
32
+ }
33
+ if (process.env['FEDERATION_WEBPACK_PATH']) {
34
+ return path.resolve(process.env['FEDERATION_WEBPACK_PATH'], fullPath.replace('webpack', '../../'));
35
+ }
36
+ return fullPath;
37
+ };
38
+
39
+ export { getWebpackPath, normalizeWebpackPath };
@@ -0,0 +1,44 @@
1
+ {
2
+ "name": "@module-federation/sdk",
3
+ "version": "0.3.1",
4
+ "license": "MIT",
5
+ "description": "A sdk for support module federation",
6
+ "keywords": [
7
+ "Module Federation",
8
+ "sdk"
9
+ ],
10
+ "files": [
11
+ "dist/",
12
+ "README.md"
13
+ ],
14
+ "publishConfig": {
15
+ "access": "public"
16
+ },
17
+ "author": "zhanghang <hanric.zhang@gmail.com>",
18
+ "sideEffects": false,
19
+ "main": "./index.cjs.js",
20
+ "module": "./index.esm.js",
21
+ "types": "./dist/index.cjs.d.ts",
22
+ "exports": {
23
+ ".": {
24
+ "types": "./dist/index.cjs.d.ts",
25
+ "import": "./dist/index.esm.js",
26
+ "require": "./dist/index.cjs.js"
27
+ },
28
+ "./normalize-webpack-path": {
29
+ "types": "./dist/normalize-webpack-path.cjs.d.ts",
30
+ "import": "./dist/normalize-webpack-path.esm.js",
31
+ "require": "./dist/normalize-webpack-path.cjs.js"
32
+ }
33
+ },
34
+ "typesVersions": {
35
+ "*": {
36
+ ".": [
37
+ "./dist/index.cjs.d.ts"
38
+ ],
39
+ "normalize-webpack-path": [
40
+ "./dist/normalize-webpack-path.cjs.d.ts"
41
+ ]
42
+ }
43
+ }
44
+ }
@@ -14,3 +14,12 @@ export declare const EncodedNameTransformMap: {
14
14
  [x: string]: string;
15
15
  };
16
16
  export declare const SEPARATOR = ":";
17
+ export declare const ManifestFileName = "mf-manifest.json";
18
+ export declare const StatsFileName = "mf-stats.json";
19
+ export declare const MFModuleType: {
20
+ NPM: string;
21
+ APP: string;
22
+ };
23
+ export declare const MODULE_DEVTOOL_IDENTIFIER = "__MF_DEVTOOLS_MODULE_INFO__";
24
+ export declare const ENCODE_NAME_PREFIX = "ENCODE_NAME_PREFIX";
25
+ export declare const TEMP_DIR = ".federation";
@@ -0,0 +1,30 @@
1
+ export declare function safeWrapper<T extends (...args: Array<any>) => any>(callback: T, disableWarn?: boolean): Promise<ReturnType<T> | undefined>;
2
+ export declare function isStaticResourcesEqual(url1: string, url2: string): boolean;
3
+ export type CreateScriptHookReturn = HTMLScriptElement | {
4
+ script?: HTMLScriptElement;
5
+ timeout?: number;
6
+ } | void;
7
+ export declare function createScript(info: {
8
+ url: string;
9
+ cb?: (value: void | PromiseLike<void>) => void;
10
+ attrs?: Record<string, any>;
11
+ needDeleteScript?: boolean;
12
+ createScriptHook?: (url: string, attrs?: Record<string, any> | undefined) => CreateScriptHookReturn;
13
+ }): {
14
+ script: HTMLScriptElement;
15
+ needAttach: boolean;
16
+ };
17
+ export declare function createLink(info: {
18
+ url: string;
19
+ cb: (value: void | PromiseLike<void>) => void;
20
+ attrs: Record<string, string>;
21
+ needDeleteLink?: boolean;
22
+ createLinkHook?: (url: string) => HTMLLinkElement | void;
23
+ }): {
24
+ link: HTMLLinkElement;
25
+ needAttach: boolean;
26
+ };
27
+ export declare function loadScript(url: string, info: {
28
+ attrs?: Record<string, any>;
29
+ createScriptHook?: (url: string, attrs?: Record<string, any> | undefined) => CreateScriptHookReturn;
30
+ }): Promise<void>;
@@ -5,6 +5,7 @@ interface IOptions {
5
5
  version?: string;
6
6
  }
7
7
  export declare const simpleJoinRemoteEntry: (rPath: string, rName: string) => string;
8
+ export declare function inferAutoPublicPath(url: string): string;
8
9
  export declare function generateSnapshotFromManifest(manifest: Manifest, options?: IOptions): ProviderModuleInfo;
9
10
  export declare function isManifestProvider(moduleInfo: ModuleInfo | ManifestProvider): moduleInfo is ManifestProvider;
10
11
  export {};
@@ -0,0 +1,9 @@
1
+ export * from './constant';
2
+ export * from './types';
3
+ export * from './utils';
4
+ export { generateSnapshotFromManifest, isManifestProvider, simpleJoinRemoteEntry, inferAutoPublicPath, } from './generateSnapshotFromManifest';
5
+ export * from './logger';
6
+ export * from './env';
7
+ export * from './dom';
8
+ export * from './node';
9
+ export * from './normalizeOptions';
@@ -0,0 +1,5 @@
1
+ export declare function createScriptNode(url: string, cb: (error?: Error, scriptContext?: any) => void, attrs?: Record<string, any>, createScriptHook?: (url: string) => any | void): void;
2
+ export declare function loadScriptNode(url: string, info: {
3
+ attrs?: Record<string, any>;
4
+ createScriptHook?: (url: string) => void;
5
+ }): Promise<void>;
@@ -1,3 +1,5 @@
1
1
  import type webpack from 'webpack';
2
- export declare function getWebpackPath(compiler: webpack.Compiler): string;
2
+ export declare function getWebpackPath(compiler: webpack.Compiler, options?: {
3
+ framework: 'nextjs' | 'other';
4
+ }): string;
3
5
  export declare const normalizeWebpackPath: (fullPath: string) => string;
@@ -0,0 +1 @@
1
+ export declare function normalizeOptions<T>(enableDefault: boolean, defaultOptions: T, key: string): <U extends boolean | undefined | T>(options: U) => T | false;
@@ -2,3 +2,4 @@ export * from './common';
2
2
  export * from './manifest';
3
3
  export * from './stats';
4
4
  export * from './snapshot';
5
+ export * from './plugins';
@@ -0,0 +1,159 @@
1
+ /**
2
+ * Modules that should be exposed by this container. When provided, property name is used as public name, otherwise public name is automatically inferred from request.
3
+ */
4
+ export type Exposes = (ExposesItem | ExposesObject)[] | ExposesObject;
5
+ /**
6
+ * Module that should be exposed by this container.
7
+ */
8
+ export type ExposesItem = string;
9
+ /**
10
+ * Modules that should be exposed by this container.
11
+ */
12
+ export type ExposesItems = ExposesItem[];
13
+ /**
14
+ * Add a container for define/require functions in the AMD module.
15
+ */
16
+ export type AmdContainer = string;
17
+ /**
18
+ * Add a comment in the UMD wrapper.
19
+ */
20
+ export type AuxiliaryComment = string | LibraryCustomUmdCommentObject;
21
+ /**
22
+ * Specify which export should be exposed as library.
23
+ */
24
+ export type LibraryExport = string[] | string;
25
+ /**
26
+ * The name of the library (some types allow unnamed libraries too).
27
+ */
28
+ export type LibraryName = string[] | string | LibraryCustomUmdObject;
29
+ /**
30
+ * Type of library (types included by default are 'var', 'module', 'assign', 'assign-properties', 'this', 'window', 'self', 'global', 'commonjs', 'commonjs2', 'commonjs-module', 'commonjs-static', 'amd', 'amd-require', 'umd', 'umd2', 'jsonp', 'system', but others might be added by plugins).
31
+ */
32
+ export type LibraryType = ('var' | 'module' | 'assign' | 'assign-properties' | 'this' | 'window' | 'self' | 'global' | 'commonjs' | 'commonjs2' | 'commonjs-module' | 'commonjs-static' | 'amd' | 'amd-require' | 'umd' | 'umd2' | 'jsonp' | 'system') | string;
33
+ /**
34
+ * If `output.libraryTarget` is set to umd and `output.library` is set, setting this to true will name the AMD module.
35
+ */
36
+ export type UmdNamedDefine = boolean;
37
+ /**
38
+ * The name of the runtime chunk. If set a runtime chunk with this name is created or an existing entrypoint is used as runtime.
39
+ */
40
+ export type EntryRuntime = false | string;
41
+ export interface ContainerPluginOptions {
42
+ /**
43
+ * Modules that should be exposed by this container. When provided, property name is used as public name, otherwise public name is automatically inferred from request.
44
+ */
45
+ exposes: Exposes;
46
+ /**
47
+ * The filename for this container relative path inside the `output.path` directory.
48
+ */
49
+ filename?: string;
50
+ /**
51
+ * Options for library.
52
+ */
53
+ library?: LibraryOptions;
54
+ /**
55
+ * The name for this container.
56
+ */
57
+ name: string;
58
+ /**
59
+ * The name of the runtime chunk. If set a runtime chunk with this name is created or an existing entrypoint is used as runtime.
60
+ */
61
+ runtime?: EntryRuntime;
62
+ /**
63
+ * The name of the share scope which is shared with the host (defaults to 'default').
64
+ */
65
+ shareScope?: string;
66
+ /**
67
+ * Runtime plugin file paths or package name.
68
+ */
69
+ runtimePlugins?: string[];
70
+ }
71
+ /**
72
+ * Modules that should be exposed by this container. Property names are used as public paths.
73
+ */
74
+ export interface ExposesObject {
75
+ /**
76
+ * Modules that should be exposed by this container.
77
+ */
78
+ [k: string]: ExposesConfig | ExposesItem | ExposesItems;
79
+ }
80
+ /**
81
+ * Advanced configuration for modules that should be exposed by this container.
82
+ */
83
+ export interface ExposesConfig {
84
+ /**
85
+ * Request to a module that should be exposed by this container.
86
+ */
87
+ import: ExposesItem | ExposesItems;
88
+ /**
89
+ * Custom chunk name for the exposed module.
90
+ */
91
+ name?: string;
92
+ }
93
+ /**
94
+ * Options for library.
95
+ */
96
+ export interface LibraryOptions {
97
+ /**
98
+ * Add a container for define/require functions in the AMD module.
99
+ */
100
+ amdContainer?: AmdContainer;
101
+ /**
102
+ * Add a comment in the UMD wrapper.
103
+ */
104
+ auxiliaryComment?: AuxiliaryComment;
105
+ /**
106
+ * Specify which export should be exposed as library.
107
+ */
108
+ export?: LibraryExport;
109
+ /**
110
+ * The name of the library (some types allow unnamed libraries too).
111
+ */
112
+ name?: LibraryName;
113
+ /**
114
+ * Type of library (types included by default are 'var', 'module', 'assign', 'assign-properties', 'this', 'window', 'self', 'global', 'commonjs', 'commonjs2', 'commonjs-module', 'commonjs-static', 'amd', 'amd-require', 'umd', 'umd2', 'jsonp', 'system', but others might be added by plugins).
115
+ */
116
+ type: LibraryType;
117
+ /**
118
+ * If `output.libraryTarget` is set to umd and `output.library` is set, setting this to true will name the AMD module.
119
+ */
120
+ umdNamedDefine?: UmdNamedDefine;
121
+ }
122
+ /**
123
+ * Set explicit comments for `commonjs`, `commonjs2`, `amd`, and `root`.
124
+ */
125
+ export interface LibraryCustomUmdCommentObject {
126
+ /**
127
+ * Set comment for `amd` section in UMD.
128
+ */
129
+ amd?: string;
130
+ /**
131
+ * Set comment for `commonjs` (exports) section in UMD.
132
+ */
133
+ commonjs?: string;
134
+ /**
135
+ * Set comment for `commonjs2` (module.exports) section in UMD.
136
+ */
137
+ commonjs2?: string;
138
+ /**
139
+ * Set comment for `root` (global variable) section in UMD.
140
+ */
141
+ root?: string;
142
+ }
143
+ /**
144
+ * Description object for all UMD variants of the library name.
145
+ */
146
+ export interface LibraryCustomUmdObject {
147
+ /**
148
+ * Name of the exposed AMD library in the UMD.
149
+ */
150
+ amd?: string;
151
+ /**
152
+ * Name of the exposed commonjs export in the UMD.
153
+ */
154
+ commonjs?: string;
155
+ /**
156
+ * Name of the property exposed globally by a UMD library.
157
+ */
158
+ root?: string[] | string;
159
+ }
@@ -0,0 +1,52 @@
1
+ /**
2
+ * Specifies the default type of externals ('amd*', 'umd*', 'system' and 'jsonp' depend on output.libraryTarget set to the same value).
3
+ */
4
+ export type ExternalsType = 'var' | 'module' | 'assign' | 'this' | 'window' | 'self' | 'global' | 'commonjs' | 'commonjs2' | 'commonjs-module' | 'commonjs-static' | 'amd' | 'amd-require' | 'umd' | 'umd2' | 'jsonp' | 'system' | 'promise' | 'import' | 'script' | 'node-commonjs';
5
+ /**
6
+ * Container locations and request scopes from which modules should be resolved and loaded at runtime. When provided, property name is used as request scope, otherwise request scope is automatically inferred from container location.
7
+ */
8
+ export type Remotes = (RemotesItem | RemotesObject)[] | RemotesObject;
9
+ /**
10
+ * Container location from which modules should be resolved and loaded at runtime.
11
+ */
12
+ export type RemotesItem = string;
13
+ /**
14
+ * Container locations from which modules should be resolved and loaded at runtime.
15
+ */
16
+ export type RemotesItems = RemotesItem[];
17
+ export interface ContainerReferencePluginOptions {
18
+ /**
19
+ * The external type of the remote containers.
20
+ */
21
+ remoteType: ExternalsType;
22
+ /**
23
+ * Container locations and request scopes from which modules should be resolved and loaded at runtime. When provided, property name is used as request scope, otherwise request scope is automatically inferred from container location.
24
+ */
25
+ remotes: Remotes;
26
+ /**
27
+ * The name of the share scope shared with all remotes (defaults to 'default').
28
+ */
29
+ shareScope?: string;
30
+ }
31
+ /**
32
+ * Container locations from which modules should be resolved and loaded at runtime. Property names are used as request scopes.
33
+ */
34
+ export interface RemotesObject {
35
+ /**
36
+ * Container locations from which modules should be resolved and loaded at runtime.
37
+ */
38
+ [k: string]: RemotesConfig | RemotesItem | RemotesItems;
39
+ }
40
+ /**
41
+ * Advanced configuration for container locations from which modules should be resolved and loaded at runtime.
42
+ */
43
+ export interface RemotesConfig {
44
+ /**
45
+ * Container locations from which modules should be resolved and loaded at runtime.
46
+ */
47
+ external: RemotesItem | RemotesItems;
48
+ /**
49
+ * The name of the share scope shared with this remote.
50
+ */
51
+ shareScope?: string;
52
+ }