@alauda/dynamic-plugin-pack 0.1.0-next.20260722.1784710868

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/README.md ADDED
@@ -0,0 +1,7 @@
1
+ # `@alauda/dynamic-plugin-pack`
2
+
3
+ Build helpers for ACP Console Module Federation plugins.
4
+
5
+ The package provides the shared singleton configuration and composable Rsbuild
6
+ configuration transforms used by plugin projects. Rsbuild and Module
7
+ Federation remain package dependencies of the consuming build.
package/index.d.ts ADDED
@@ -0,0 +1,79 @@
1
+ import { pluginModuleFederation } from '@module-federation/rsbuild-plugin';
2
+ import type { RsbuildConfig } from '@rsbuild/core';
3
+
4
+ /**
5
+ * Compose config transforms right-to-left, like the console SDK's `compose`:
6
+ * `compose(withMfe, withBase)` applies `withBase` first (the base), then layers
7
+ * `withMfe` on top. Start from `{}` (or a partial config) to build the final
8
+ * Rsbuild config.
9
+ */
10
+ export declare function compose(...transforms: ConfigTransform[]): ConfigTransform;
11
+
12
+ /** A composable Rsbuild config transform: takes a config and returns it merged. */
13
+ export declare type ConfigTransform = (config: RsbuildConfig) => RsbuildConfig;
14
+
15
+ /** Shallow-merge two Rsbuild configs, concatenating `plugins` and merging the
16
+ * common nested sections so transforms layer cleanly. */
17
+ export declare function mergeConfig(base: RsbuildConfig, extra: RsbuildConfig): RsbuildConfig;
18
+
19
+ /** The Module Federation options a host/remote declares (see its
20
+ * `module-federation.config`). Matches the rsbuild MF plugin's option shape. */
21
+ export declare type MfeConfig = Parameters<typeof pluginModuleFederation>[0];
22
+
23
+ export declare interface RemoteOptions {
24
+ /** Dev server port; also used to derive the asset prefix. */
25
+ port: number;
26
+ /** Standalone dev entry (the local harness, not the federated surface). */
27
+ devEntry?: string;
28
+ /** Override the asset prefix (defaults to `http://localhost:<port>`). */
29
+ assetPrefix?: string;
30
+ }
31
+
32
+ export declare const shared: {
33
+ react: {
34
+ readonly singleton: true;
35
+ readonly requiredVersion: false;
36
+ };
37
+ 'react-dom': {
38
+ readonly singleton: true;
39
+ readonly requiredVersion: false;
40
+ };
41
+ 'react-router-dom': {
42
+ readonly singleton: true;
43
+ readonly requiredVersion: false;
44
+ };
45
+ '@alauda/core-plugin-sdk': {
46
+ readonly singleton: true;
47
+ readonly requiredVersion: false;
48
+ };
49
+ '@mui/material': {
50
+ readonly singleton: true;
51
+ readonly requiredVersion: false;
52
+ };
53
+ '@emotion/react': {
54
+ readonly singleton: true;
55
+ readonly requiredVersion: false;
56
+ };
57
+ '@emotion/styled': {
58
+ readonly singleton: true;
59
+ readonly requiredVersion: false;
60
+ };
61
+ };
62
+
63
+ /** Common base: the React plugin (and any future shared defaults). */
64
+ export declare function withBaseConfig(): ConfigTransform;
65
+
66
+ /**
67
+ * A host: consumes remotes (registered at runtime, so none are declared here)
68
+ * and shares the same singletons. `dts` is disabled to avoid the MF type server.
69
+ */
70
+ export declare function withHostMfeConfig(mfe: MfeConfig): ConfigTransform;
71
+
72
+ /**
73
+ * A remote (a plugin built as an MF remote): exposes its surface and serves the
74
+ * remote entry cross-origin so the host can load it. `dts` is disabled — the
75
+ * host consumes the plugin via its runtime brand, not types.
76
+ */
77
+ export declare function withRemoteMfeConfig(mfe: MfeConfig, options: RemoteOptions): ConfigTransform;
78
+
79
+ export { }
package/index.js ADDED
@@ -0,0 +1,100 @@
1
+ import { pluginReact } from "@rsbuild/plugin-react";
2
+ import { pluginModuleFederation } from "@module-federation/rsbuild-plugin";
3
+ //#region packages/engine/dynamic-plugin-pack/src/shared.ts
4
+ const singleton = {
5
+ singleton: true,
6
+ requiredVersion: false
7
+ };
8
+ const shared = {
9
+ react: singleton,
10
+ "react-dom": singleton,
11
+ "react-router-dom": singleton,
12
+ "@alauda/core-plugin-sdk": singleton,
13
+ "@mui/material": singleton,
14
+ "@emotion/react": singleton,
15
+ "@emotion/styled": singleton
16
+ };
17
+ //#endregion
18
+ //#region packages/engine/dynamic-plugin-pack/src/compose.ts
19
+ /**
20
+ * Compose config transforms right-to-left, like the console SDK's `compose`:
21
+ * `compose(withMfe, withBase)` applies `withBase` first (the base), then layers
22
+ * `withMfe` on top. Start from `{}` (or a partial config) to build the final
23
+ * Rsbuild config.
24
+ */
25
+ function compose(...transforms) {
26
+ return (config) => transforms.reduceRight((acc, transform) => transform(acc), config);
27
+ }
28
+ /** Shallow-merge two Rsbuild configs, concatenating `plugins` and merging the
29
+ * common nested sections so transforms layer cleanly. */
30
+ function mergeConfig(base, extra) {
31
+ return {
32
+ ...base,
33
+ ...extra,
34
+ plugins: [...base.plugins ?? [], ...extra.plugins ?? []],
35
+ source: {
36
+ ...base.source,
37
+ ...extra.source
38
+ },
39
+ server: {
40
+ ...base.server,
41
+ ...extra.server
42
+ },
43
+ dev: {
44
+ ...base.dev,
45
+ ...extra.dev
46
+ },
47
+ output: {
48
+ ...base.output,
49
+ ...extra.output
50
+ },
51
+ html: {
52
+ ...base.html,
53
+ ...extra.html
54
+ }
55
+ };
56
+ }
57
+ //#endregion
58
+ //#region packages/engine/dynamic-plugin-pack/src/mfe.ts
59
+ /** Common base: the React plugin (and any future shared defaults). */
60
+ function withBaseConfig() {
61
+ return (config) => mergeConfig(config, {
62
+ plugins: [pluginReact()],
63
+ tools: { rspack: { ignoreWarnings: [(warning) => /Critical dependency: require function is used/.test(String(warning?.message))] } }
64
+ });
65
+ }
66
+ /**
67
+ * A remote (a plugin built as an MF remote): exposes its surface and serves the
68
+ * remote entry cross-origin so the host can load it. `dts` is disabled — the
69
+ * host consumes the plugin via its runtime brand, not types.
70
+ */
71
+ function withRemoteMfeConfig(mfe, options) {
72
+ const assetPrefix = options.assetPrefix ?? `http://localhost:${options.port}`;
73
+ return (config) => mergeConfig(config, {
74
+ plugins: [pluginModuleFederation({
75
+ ...mfe,
76
+ dts: false
77
+ })],
78
+ ...options.devEntry ? { source: { entry: { index: options.devEntry } } } : {},
79
+ server: { port: options.port },
80
+ dev: {
81
+ assetPrefix,
82
+ lazyCompilation: false
83
+ },
84
+ output: { assetPrefix }
85
+ });
86
+ }
87
+ /**
88
+ * A host: consumes remotes (registered at runtime, so none are declared here)
89
+ * and shares the same singletons. `dts` is disabled to avoid the MF type server.
90
+ */
91
+ function withHostMfeConfig(mfe) {
92
+ return (config) => mergeConfig(config, { plugins: [pluginModuleFederation({
93
+ ...mfe,
94
+ dts: false
95
+ })] });
96
+ }
97
+ //#endregion
98
+ export { compose, mergeConfig, shared, withBaseConfig, withHostMfeConfig, withRemoteMfeConfig };
99
+
100
+ //# sourceMappingURL=index.js.map
package/index.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","names":[],"sources":["../../src/shared.ts","../../src/compose.ts","../../src/mfe.ts"],"sourcesContent":["/*\n * Module Federation `shared` config for ACP Console hosts and remotes.\n *\n * These identity-critical packages MUST resolve to a single shared instance so\n * the host recognises a remote's plugin (its `$$type` brand), agrees on the\n * same ApiRef identities, and uses one React/router/style runtime.\n */\nconst singleton = { singleton: true, requiredVersion: false } as const;\n\nexport const shared = {\n react: singleton,\n 'react-dom': singleton,\n 'react-router-dom': singleton,\n '@alauda/core-plugin-sdk': singleton,\n '@mui/material': singleton,\n '@emotion/react': singleton,\n '@emotion/styled': singleton,\n};\n","import type { RsbuildConfig } from '@rsbuild/core';\n\n/** A composable Rsbuild config transform: takes a config and returns it merged. */\nexport type ConfigTransform = (config: RsbuildConfig) => RsbuildConfig;\n\n/**\n * Compose config transforms right-to-left, like the console SDK's `compose`:\n * `compose(withMfe, withBase)` applies `withBase` first (the base), then layers\n * `withMfe` on top. Start from `{}` (or a partial config) to build the final\n * Rsbuild config.\n */\nexport function compose(...transforms: ConfigTransform[]): ConfigTransform {\n return config =>\n transforms.reduceRight((acc, transform) => transform(acc), config);\n}\n\n/** Shallow-merge two Rsbuild configs, concatenating `plugins` and merging the\n * common nested sections so transforms layer cleanly. */\nexport function mergeConfig(\n base: RsbuildConfig,\n extra: RsbuildConfig,\n): RsbuildConfig {\n return {\n ...base,\n ...extra,\n plugins: [...(base.plugins ?? []), ...(extra.plugins ?? [])],\n source: { ...base.source, ...extra.source },\n server: { ...base.server, ...extra.server },\n dev: { ...base.dev, ...extra.dev },\n output: { ...base.output, ...extra.output },\n html: { ...base.html, ...extra.html },\n };\n}\n","/*\n * Rsbuild config transforms for Module Federation hosts and remotes — the\n * Rsbuild analogue of the console SDK's `withHostMfeConfig` / `withRemoteMfeConfig`\n * / `withBaseConfig`. Compose them with `compose(...)` (see ./compose).\n */\nimport { pluginReact } from '@rsbuild/plugin-react';\nimport { pluginModuleFederation } from '@module-federation/rsbuild-plugin';\nimport { ConfigTransform, mergeConfig } from './compose';\n\n/** The Module Federation options a host/remote declares (see its\n * `module-federation.config`). Matches the rsbuild MF plugin's option shape. */\nexport type MfeConfig = Parameters<typeof pluginModuleFederation>[0];\n\nexport interface RemoteOptions {\n /** Dev server port; also used to derive the asset prefix. */\n port: number;\n /** Standalone dev entry (the local harness, not the federated surface). */\n devEntry?: string;\n /** Override the asset prefix (defaults to `http://localhost:<port>`). */\n assetPrefix?: string;\n}\n\n/** Common base: the React plugin (and any future shared defaults). */\nexport function withBaseConfig(): ConfigTransform {\n return config =>\n mergeConfig(config, {\n plugins: [pluginReact()],\n tools: {\n rspack: {\n // monaco-editor's `editorSimpleWorker` has an AMD `require([id])` in a\n // dead `if (!isESM)` branch the bundler can't statically analyse,\n // producing a benign \"Critical dependency\" warning. That branch never\n // runs in the bundled ESM build, so silence just this warning.\n ignoreWarnings: [\n (warning: { message?: string }) =>\n /Critical dependency: require function is used/.test(\n String(warning?.message),\n ),\n ],\n },\n },\n });\n}\n\n/**\n * A remote (a plugin built as an MF remote): exposes its surface and serves the\n * remote entry cross-origin so the host can load it. `dts` is disabled — the\n * host consumes the plugin via its runtime brand, not types.\n */\nexport function withRemoteMfeConfig(\n mfe: MfeConfig,\n options: RemoteOptions,\n): ConfigTransform {\n const assetPrefix =\n options.assetPrefix ?? `http://localhost:${options.port}`;\n return config =>\n mergeConfig(config, {\n plugins: [pluginModuleFederation({ ...mfe, dts: false })],\n ...(options.devEntry\n ? { source: { entry: { index: options.devEntry } } }\n : {}),\n server: { port: options.port },\n // `lazyCompilation: false` is required for Module Federation: rsbuild's\n // on-demand dev compilation serves a proxy for dynamically-imported\n // modules and compiles them only when requested, but that round-trip\n // cannot complete across the host↔remote MF boundary — a lazily-imported\n // remote page would hang on its proxy and only ever show a spinner.\n dev: { assetPrefix, lazyCompilation: false },\n output: { assetPrefix },\n });\n}\n\n/**\n * A host: consumes remotes (registered at runtime, so none are declared here)\n * and shares the same singletons. `dts` is disabled to avoid the MF type server.\n */\nexport function withHostMfeConfig(mfe: MfeConfig): ConfigTransform {\n return config =>\n mergeConfig(config, {\n plugins: [pluginModuleFederation({ ...mfe, dts: false })],\n });\n}\n"],"mappings":";;;AAOA,MAAM,YAAY;CAAE,WAAW;CAAM,iBAAiB;AAAM;AAE5D,MAAa,SAAS;CACpB,OAAO;CACP,aAAa;CACb,oBAAoB;CACpB,2BAA2B;CAC3B,iBAAiB;CACjB,kBAAkB;CAClB,mBAAmB;AACrB;;;;;;;;;ACNA,SAAgB,QAAQ,GAAG,YAAgD;CACzE,QAAO,WACL,WAAW,aAAa,KAAK,cAAc,UAAU,GAAG,GAAG,MAAM;AACrE;;;AAIA,SAAgB,YACd,MACA,OACe;CACf,OAAO;EACL,GAAG;EACH,GAAG;EACH,SAAS,CAAC,GAAI,KAAK,WAAW,CAAC,GAAI,GAAI,MAAM,WAAW,CAAC,CAAE;EAC3D,QAAQ;GAAE,GAAG,KAAK;GAAQ,GAAG,MAAM;EAAO;EAC1C,QAAQ;GAAE,GAAG,KAAK;GAAQ,GAAG,MAAM;EAAO;EAC1C,KAAK;GAAE,GAAG,KAAK;GAAK,GAAG,MAAM;EAAI;EACjC,QAAQ;GAAE,GAAG,KAAK;GAAQ,GAAG,MAAM;EAAO;EAC1C,MAAM;GAAE,GAAG,KAAK;GAAM,GAAG,MAAM;EAAK;CACtC;AACF;;;;ACTA,SAAgB,iBAAkC;CAChD,QAAO,WACL,YAAY,QAAQ;EAClB,SAAS,CAAC,YAAY,CAAC;EACvB,OAAO,EACL,QAAQ,EAKN,gBAAgB,EACb,YACC,gDAAgD,KAC9C,OAAO,SAAS,OAAO,CACzB,CACJ,EACF,EACF;CACF,CAAC;AACL;;;;;;AAOA,SAAgB,oBACd,KACA,SACiB;CACjB,MAAM,cACJ,QAAQ,eAAe,oBAAoB,QAAQ;CACrD,QAAO,WACL,YAAY,QAAQ;EAClB,SAAS,CAAC,uBAAuB;GAAE,GAAG;GAAK,KAAK;EAAM,CAAC,CAAC;EACxD,GAAI,QAAQ,WACR,EAAE,QAAQ,EAAE,OAAO,EAAE,OAAO,QAAQ,SAAS,EAAE,EAAE,IACjD,CAAC;EACL,QAAQ,EAAE,MAAM,QAAQ,KAAK;EAM7B,KAAK;GAAE;GAAa,iBAAiB;EAAM;EAC3C,QAAQ,EAAE,YAAY;CACxB,CAAC;AACL;;;;;AAMA,SAAgB,kBAAkB,KAAiC;CACjE,QAAO,WACL,YAAY,QAAQ,EAClB,SAAS,CAAC,uBAAuB;EAAE,GAAG;EAAK,KAAK;CAAM,CAAC,CAAC,EAC1D,CAAC;AACL"}
package/package.json ADDED
@@ -0,0 +1,30 @@
1
+ {
2
+ "name": "@alauda/dynamic-plugin-pack",
3
+ "version": "0.1.0-next.20260722.1784710868",
4
+ "description": "Build helpers for ACP Console Module Federation plugins.",
5
+ "type": "module",
6
+ "main": "./index.js",
7
+ "module": "./index.js",
8
+ "types": "./index.d.ts",
9
+ "exports": {
10
+ ".": {
11
+ "types": "./index.d.ts",
12
+ "import": "./index.js",
13
+ "default": "./index.js"
14
+ }
15
+ },
16
+ "files": [
17
+ "index.js",
18
+ "index.js.map",
19
+ "index.d.ts",
20
+ "README.md"
21
+ ],
22
+ "dependencies": {
23
+ "@module-federation/rsbuild-plugin": "^2.5.1",
24
+ "@rsbuild/core": "^1.1.13",
25
+ "@rsbuild/plugin-react": "^1.1.0"
26
+ },
27
+ "publishConfig": {
28
+ "access": "public"
29
+ }
30
+ }