@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
@@ -0,0 +1 @@
1
+ export * from "./src/normalize-webpack-path";
@@ -0,0 +1,42 @@
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) {
12
+ try {
13
+ // @ts-ignore just throw err
14
+ compiler.webpack();
15
+ return "";
16
+ } catch (err) {
17
+ var _err_stack;
18
+ var trace = ((_err_stack = err.stack) === null || _err_stack === void 0 ? void 0 : _err_stack.split("\n")) || [];
19
+ var webpackErrLocation = trace.find(function(item) {
20
+ return item.includes("at webpack");
21
+ }) || "";
22
+ var webpackLocationWithDetail = webpackErrLocation.replace(/[^\(\)]+/, "").slice(1, -1);
23
+ var webpackPath = webpackLocationWithDetail.split(":").slice(0, -2)[0];
24
+ return require.resolve("webpack", {
25
+ paths: [
26
+ webpackPath
27
+ ]
28
+ });
29
+ }
30
+ }
31
+ var normalizeWebpackPath = function(fullPath) {
32
+ if (fullPath === "webpack") {
33
+ return process.env["FEDERATION_WEBPACK_PATH"] || fullPath;
34
+ }
35
+ if (process.env["FEDERATION_WEBPACK_PATH"]) {
36
+ return path__default["default"].resolve(process.env["FEDERATION_WEBPACK_PATH"], fullPath.replace("webpack", "../../"));
37
+ }
38
+ return fullPath;
39
+ };
40
+
41
+ exports.getWebpackPath = getWebpackPath;
42
+ exports.normalizeWebpackPath = normalizeWebpackPath;
@@ -0,0 +1,33 @@
1
+ import path from 'path';
2
+
3
+ function getWebpackPath(compiler) {
4
+ try {
5
+ // @ts-ignore just throw err
6
+ compiler.webpack();
7
+ return "";
8
+ } catch (err) {
9
+ var _err_stack;
10
+ var trace = ((_err_stack = err.stack) === null || _err_stack === void 0 ? void 0 : _err_stack.split("\n")) || [];
11
+ var webpackErrLocation = trace.find(function(item) {
12
+ return item.includes("at webpack");
13
+ }) || "";
14
+ var webpackLocationWithDetail = webpackErrLocation.replace(/[^\(\)]+/, "").slice(1, -1);
15
+ var webpackPath = webpackLocationWithDetail.split(":").slice(0, -2)[0];
16
+ return require.resolve("webpack", {
17
+ paths: [
18
+ webpackPath
19
+ ]
20
+ });
21
+ }
22
+ }
23
+ var normalizeWebpackPath = function(fullPath) {
24
+ if (fullPath === "webpack") {
25
+ return process.env["FEDERATION_WEBPACK_PATH"] || fullPath;
26
+ }
27
+ if (process.env["FEDERATION_WEBPACK_PATH"]) {
28
+ return path.resolve(process.env["FEDERATION_WEBPACK_PATH"], fullPath.replace("webpack", "../../"));
29
+ }
30
+ return fullPath;
31
+ };
32
+
33
+ export { getWebpackPath, normalizeWebpackPath };
@@ -0,0 +1,44 @@
1
+ {
2
+ "name": "@module-federation/sdk",
3
+ "version": "0.0.3",
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
+ "import": "./dist/index.esm.js",
25
+ "require": "./dist/index.cjs.js",
26
+ "types": "./dist/index.cjs.d.ts"
27
+ },
28
+ "./normalize-webpack-path": {
29
+ "import": "./dist/normalize-webpack-path.esm.js",
30
+ "require": "./dist/normalize-webpack-path.cjs.js",
31
+ "types": "./dist/src/normalize-webpack-path.cjs.d.ts"
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
+ }
@@ -0,0 +1,16 @@
1
+ export declare const FederationModuleManifest = "federation-manifest.json";
2
+ export declare const MANIFEST_EXT = ".json";
3
+ export declare const BROWSER_LOG_KEY = "FEDERATION_DEBUG";
4
+ export declare const BROWSER_LOG_VALUE = "1";
5
+ export declare const NameTransformSymbol: {
6
+ AT: string;
7
+ HYPHEN: string;
8
+ SLASH: string;
9
+ };
10
+ export declare const NameTransformMap: {
11
+ [x: string]: string;
12
+ };
13
+ export declare const EncodedNameTransformMap: {
14
+ [x: string]: string;
15
+ };
16
+ export declare const SEPARATOR = ":";
@@ -0,0 +1,10 @@
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 declare function createScript(url: string, cb: (value: void | PromiseLike<void>) => void, attrs?: Record<string, any>, createScriptHook?: (url: string) => HTMLScriptElement | void): {
4
+ script: HTMLScriptElement;
5
+ needAttach: boolean;
6
+ };
7
+ export declare function loadScript(url: string, info: {
8
+ attrs?: Record<string, any>;
9
+ createScriptHook?: (url: string) => HTMLScriptElement | void;
10
+ }): Promise<void>;
@@ -0,0 +1,7 @@
1
+ declare global {
2
+ var FEDERATION_DEBUG: string | undefined;
3
+ }
4
+ declare function isBrowserEnv(): boolean;
5
+ declare function isDebugMode(): boolean;
6
+ declare const getProcessEnv: () => Record<string, string | undefined>;
7
+ export { isBrowserEnv, isDebugMode, getProcessEnv };
@@ -0,0 +1,10 @@
1
+ import { Manifest, ProviderModuleInfo, ModuleInfo, ManifestProvider } from './types';
2
+ interface IOptions {
3
+ remotes?: Record<string, string>;
4
+ overrides?: Record<string, string>;
5
+ version?: string;
6
+ }
7
+ export declare const simpleJoinRemoteEntry: (rPath: string, rName: string) => string;
8
+ export declare function generateSnapshotFromManifest(manifest: Manifest, options?: IOptions): ProviderModuleInfo;
9
+ export declare function isManifestProvider(moduleInfo: ModuleInfo | ManifestProvider): moduleInfo is ManifestProvider;
10
+ export {};
@@ -1,10 +1,7 @@
1
1
  export * from './constant';
2
2
  export * from './types';
3
3
  export * from './utils';
4
- export {
5
- generateSnapshotFromManifest,
6
- isManifestProvider,
7
- } from './generateSnapshotFromManifest';
4
+ export { generateSnapshotFromManifest, isManifestProvider, } from './generateSnapshotFromManifest';
8
5
  export * from './logger';
9
6
  export * from './env';
10
7
  export * from './dom';
@@ -0,0 +1,8 @@
1
+ declare class Logger {
2
+ enable: boolean;
3
+ identifier: string;
4
+ constructor(identifier?: string);
5
+ info(msg: string, info?: any): void;
6
+ logOriginalInfo(...args: unknown[]): void;
7
+ }
8
+ export { Logger };
@@ -0,0 +1,3 @@
1
+ import type webpack from 'webpack';
2
+ export declare function getWebpackPath(compiler: webpack.Compiler): string;
3
+ export declare const normalizeWebpackPath: (fullPath: string) => string;
@@ -1,18 +1,10 @@
1
1
  export interface RemoteWithEntry {
2
- name: string;
3
- entry: string;
2
+ name: string;
3
+ entry: string;
4
4
  }
5
-
6
5
  export interface RemoteWithVersion {
7
- name: string;
8
- version: string;
6
+ name: string;
7
+ version: string;
9
8
  }
10
-
11
9
  export type RemoteEntryInfo = RemoteWithEntry | RemoteWithVersion;
12
10
  export type Module = any;
13
-
14
- declare namespace NodeJS {
15
- interface ProcessEnv {
16
- FEDERATION_WEBPACK_PATH?: string;
17
- }
18
- }
@@ -0,0 +1,26 @@
1
+ import { StatsMetaData, StatsAssets, StatsExpose, BasicStatsMetaData } from './stats';
2
+ import { RemoteWithEntry, RemoteWithVersion } from './common';
3
+ export interface ManifestShared {
4
+ id: string;
5
+ name: string;
6
+ version: string;
7
+ singleton: boolean;
8
+ requiredVersion: string;
9
+ hash: string;
10
+ assets: StatsAssets;
11
+ }
12
+ export interface ManifestRemoteCommonInfo {
13
+ federationContainerName: string;
14
+ moduleName: string;
15
+ alias: string;
16
+ }
17
+ export type ManifestRemote<T = ManifestRemoteCommonInfo> = (Omit<RemoteWithEntry, 'name'> & T) | (Omit<RemoteWithVersion, 'name'> & T);
18
+ export type ManifestExpose = Pick<StatsExpose, 'assets' | 'id' | 'name' | 'path'>;
19
+ export interface Manifest<T = BasicStatsMetaData, K = ManifestRemoteCommonInfo> {
20
+ id: string;
21
+ name: string;
22
+ metaData: StatsMetaData<T>;
23
+ shared: ManifestShared[];
24
+ remotes: ManifestRemote<K>[];
25
+ exposes: ManifestExpose[];
26
+ }
@@ -0,0 +1,62 @@
1
+ import { RemoteEntryType, StatsAssets } from './stats';
2
+ interface BasicModuleInfo {
3
+ dev?: {
4
+ version?: string;
5
+ remotes?: {
6
+ [nameWithType: string]: string;
7
+ };
8
+ };
9
+ version: string;
10
+ buildVersion: string;
11
+ remoteTypes: string;
12
+ remotesInfo: Record<string, {
13
+ matchedVersion: string;
14
+ }>;
15
+ shared: Array<{
16
+ sharedName: string;
17
+ assets: StatsAssets;
18
+ }>;
19
+ }
20
+ export interface BasicProviderModuleInfo extends BasicModuleInfo {
21
+ remoteEntry: string;
22
+ remoteEntryType: RemoteEntryType;
23
+ remoteManifest?: string;
24
+ globalName: string;
25
+ modules: Array<{
26
+ moduleName: string;
27
+ modulePath?: string;
28
+ assets: StatsAssets;
29
+ }>;
30
+ prefetchEntry?: string;
31
+ prefetchEntryType?: RemoteEntryType;
32
+ }
33
+ interface BasicProviderModuleInfoWithPublicPath extends BasicProviderModuleInfo {
34
+ publicPath: string;
35
+ }
36
+ interface BasicProviderModuleInfoWithGetPublicPath extends BasicProviderModuleInfo {
37
+ getPublicPath: string;
38
+ }
39
+ export interface ManifestProvider {
40
+ remoteEntry: string;
41
+ version?: string;
42
+ }
43
+ export interface PureEntryProvider extends ManifestProvider {
44
+ globalName: string;
45
+ }
46
+ interface BasicConsumerModuleInfo extends BasicModuleInfo {
47
+ consumerList: Array<string>;
48
+ }
49
+ export interface ConsumerModuleInfoWithPublicPath extends BasicConsumerModuleInfo, BasicProviderModuleInfo {
50
+ publicPath: string;
51
+ }
52
+ interface ConsumerModuleInfoWithGetPublicPath extends BasicConsumerModuleInfo, BasicProviderModuleInfo {
53
+ getPublicPath: string;
54
+ }
55
+ export type PureConsumerModuleInfo = Omit<BasicConsumerModuleInfo, 'remoteTypes'>;
56
+ export type ConsumerModuleInfo = ConsumerModuleInfoWithPublicPath | ConsumerModuleInfoWithGetPublicPath;
57
+ export type ProviderModuleInfo = BasicProviderModuleInfoWithPublicPath | BasicProviderModuleInfoWithGetPublicPath;
58
+ export type ModuleInfo = ConsumerModuleInfo | PureConsumerModuleInfo | ProviderModuleInfo;
59
+ export type GlobalModuleInfo = {
60
+ [key: string]: ModuleInfo | ManifestProvider | PureEntryProvider | undefined;
61
+ };
62
+ export {};
@@ -0,0 +1,79 @@
1
+ import type { RemoteWithEntry, RemoteWithVersion } from './common';
2
+ export type RemoteEntryType = 'esm' | 'global';
3
+ interface ResourceInfo {
4
+ path: string;
5
+ name: string;
6
+ type: RemoteEntryType;
7
+ }
8
+ export interface StatsBuildInfo {
9
+ buildVersion: string;
10
+ buildName: string;
11
+ }
12
+ export interface BasicStatsMetaData {
13
+ name: string;
14
+ globalName: string;
15
+ buildInfo: StatsBuildInfo;
16
+ remoteEntry: ResourceInfo;
17
+ prefetchEntry: ResourceInfo;
18
+ types: Omit<ResourceInfo, 'type'>;
19
+ }
20
+ type StatsMetaDataWithGetPublicPath<T = BasicStatsMetaData> = T & {
21
+ getPublicPath: string;
22
+ };
23
+ type StatsMetaDataWithPublicPath<T = BasicStatsMetaData> = T & {
24
+ publicPath: string;
25
+ };
26
+ export type StatsMetaData<T = BasicStatsMetaData> = StatsMetaDataWithGetPublicPath<T> | StatsMetaDataWithPublicPath<T>;
27
+ export interface StatsAssets {
28
+ js: StatsAssetsInfo;
29
+ css: StatsAssetsInfo;
30
+ }
31
+ interface StatsAssetsInfo {
32
+ sync: string[];
33
+ async: string[];
34
+ }
35
+ export interface StatsShared {
36
+ id: string;
37
+ name: string;
38
+ version: string;
39
+ singleton: boolean;
40
+ requiredVersion: string;
41
+ hash: string;
42
+ assets: StatsAssets;
43
+ deps: string[];
44
+ usedIn: string[];
45
+ }
46
+ export interface StatsRemoteVal {
47
+ moduleName: string;
48
+ federationContainerName: string;
49
+ consumingFederationContainerName: string;
50
+ alias: string;
51
+ usedIn: string[];
52
+ }
53
+ export type StatsRemoteWithEntry<T = StatsRemoteVal> = T & Omit<RemoteWithEntry, 'name'>;
54
+ export type StatsRemoteWithVersion<T = StatsRemoteVal> = T & Omit<RemoteWithVersion, 'name'>;
55
+ export type StatsRemote<T = StatsRemoteVal> = StatsRemoteWithEntry<T> | StatsRemoteWithVersion<T>;
56
+ export interface StatsModuleInfo {
57
+ name: string;
58
+ file: string;
59
+ }
60
+ export interface ManifestModuleInfos {
61
+ [exposeModuleName: string]: StatsModuleInfo;
62
+ }
63
+ export interface StatsExpose {
64
+ id: string;
65
+ name: string;
66
+ path?: string;
67
+ file: string;
68
+ requires: string[];
69
+ assets: StatsAssets;
70
+ }
71
+ export interface Stats<T = BasicStatsMetaData, K = StatsRemoteVal> {
72
+ id: string;
73
+ name: string;
74
+ metaData: StatsMetaData<T>;
75
+ shared: StatsShared[];
76
+ remotes: StatsRemote<K>[];
77
+ exposes: StatsExpose[];
78
+ }
79
+ export {};
@@ -0,0 +1,17 @@
1
+ import { RemoteEntryInfo, ModuleInfo } from './types';
2
+ import { Logger } from './logger';
3
+ declare const parseEntry: (str: string, devVerOrUrl?: string) => RemoteEntryInfo;
4
+ declare global {
5
+ var FEDERATION_DEBUG: string | undefined;
6
+ }
7
+ declare const logger: Logger;
8
+ declare const composeKeyWithSeparator: (...args: (string | undefined)[]) => string;
9
+ declare const encodeName: (name: string, prefix?: string, withExt?: boolean) => string;
10
+ declare const decodeName: (name: string, prefix?: string, withExt?: boolean) => string;
11
+ declare const generateExposeFilename: (exposeName: string, withExt: boolean) => string;
12
+ declare const generateShareFilename: (pkgName: string, withExt: boolean) => string;
13
+ declare const getResourceUrl: (module: ModuleInfo, sourceUrl: string) => string;
14
+ declare const assert: (condition: any, msg: string) => asserts condition;
15
+ declare const error: (msg: string | Error | unknown) => never;
16
+ declare const warn: (msg: Parameters<typeof console.warn>[0]) => void;
17
+ export { parseEntry, logger, decodeName, encodeName, composeKeyWithSeparator, generateExposeFilename, generateShareFilename, getResourceUrl, assert, error, warn, };
package/package.json CHANGED
@@ -1,12 +1,16 @@
1
1
  {
2
2
  "name": "@module-federation/sdk",
3
- "version": "0.0.0-next-20231220075820",
3
+ "version": "0.0.0-next-20231220081137",
4
4
  "license": "MIT",
5
5
  "description": "A sdk for support module federation",
6
6
  "keywords": [
7
7
  "Module Federation",
8
8
  "sdk"
9
9
  ],
10
+ "files": [
11
+ "dist/",
12
+ "README.md"
13
+ ],
10
14
  "publishConfig": {
11
15
  "access": "public"
12
16
  },