@alauda-fe/dynamic-plugin-sdk-rspack 0.0.1-alpha.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.
package/README.md ADDED
@@ -0,0 +1,7 @@
1
+ # dynamic-plugin-sdk-rspack
2
+
3
+ This library was generated with [Nx](https://nx.dev).
4
+
5
+ ## Building
6
+
7
+ Run `nx build dynamic-plugin-sdk-rspack` to build the library.
package/index.js ADDED
@@ -0,0 +1,218 @@
1
+ // libs/dynamic-plugin-sdk-rspack/src/lib/mfe-config-utils.ts
2
+ var isCoreModules = (packageName) => {
3
+ const coreModules = [
4
+ "rxjs",
5
+ "zone.js",
6
+ "tslib",
7
+ "lodash-es",
8
+ "ramda",
9
+ "dayjs",
10
+ "pluralize",
11
+ "dompurify"
12
+ ];
13
+ if (coreModules.includes(packageName)) {
14
+ return true;
15
+ }
16
+ return packageName === "@alauda-fe/dynamic-plugin-sdk" || packageName.startsWith("@alauda/") || packageName.startsWith("@angular/") || packageName === "rxjs/operators" || // Explicit operators path
17
+ packageName.startsWith("rxjs/") || packageName.startsWith("dayjs/");
18
+ };
19
+ var isCommonjsModules = (packageName) => {
20
+ return packageName === "lottie-web" || packageName === "xterm" || packageName.startsWith("xterm-addon-");
21
+ };
22
+ var isStandaloneModules = (packageName) => {
23
+ return packageName === "@alauda-fe/plugin-sdk/remote";
24
+ };
25
+ var mfe_config_utils_default = {
26
+ shared: (packageName, config) => {
27
+ if (packageName && !isStandaloneModules(packageName) && (isCoreModules(packageName) || isCommonjsModules(packageName))) {
28
+ return { ...config, singleton: true, strictVersion: false };
29
+ }
30
+ return false;
31
+ }
32
+ };
33
+
34
+ // libs/dynamic-plugin-sdk-rspack/src/lib/with-alauda-console.ts
35
+ function loadEsmModule(modulePath) {
36
+ return new Function("modulePath", `return import(modulePath);`)(modulePath);
37
+ }
38
+ async function loadModule(path) {
39
+ const module = await loadEsmModule(path);
40
+ return module.default || module;
41
+ }
42
+ var with_alauda_console_default = async (options) => {
43
+ const customWebpack = await loadModule("@alauda/custom-webpack");
44
+ return (config) => {
45
+ config.resolve ??= {};
46
+ config.resolve.alias ??= {};
47
+ config.plugins ??= [];
48
+ return customWebpack(config, options);
49
+ };
50
+ };
51
+
52
+ // libs/dynamic-plugin-sdk-rspack/src/lib/with-base-config.ts
53
+ import { merge } from "rspack-merge";
54
+ var with_base_config_default = () => (config) => {
55
+ return merge(config, {
56
+ module: {
57
+ rules: [
58
+ {
59
+ test: /\.css$/i,
60
+ resourceQuery: { not: [/ngGlobalStyle/, /ngResource/] },
61
+ issuer: /\.[jt]sx?$|\.[cm]js$/,
62
+ use: [
63
+ "style-loader",
64
+ {
65
+ loader: "css-loader",
66
+ options: {
67
+ // https://github.com/webpack/webpack-dev-server/issues/1815#issuecomment-1181720815
68
+ url: false
69
+ }
70
+ }
71
+ ]
72
+ }
73
+ ]
74
+ },
75
+ ignoreWarnings: [
76
+ {
77
+ module: /monaco-(editor|yaml)/
78
+ },
79
+ /Failed to parse source map from/
80
+ ],
81
+ resolve: {
82
+ alias: {
83
+ dayjs: "dayjs/esm"
84
+ }
85
+ }
86
+ });
87
+ };
88
+
89
+ // libs/dynamic-plugin-sdk-rspack/src/lib/with-host-mfe-config.ts
90
+ import { withModuleFederation } from "@nx/module-federation/rspack";
91
+ import { merge as merge2 } from "rspack-merge";
92
+ var proxy = "http://localhost:8080/";
93
+ function createRemoteProxy({ disableDevPluginProxy = false } = {}) {
94
+ const remoteProxy = [
95
+ {
96
+ context: ["/clusters-rewrite/"],
97
+ target: proxy,
98
+ timeout: 5e3,
99
+ secure: false,
100
+ changeOrigin: true
101
+ },
102
+ {
103
+ context: ["/console-assets/"],
104
+ target: proxy,
105
+ timeout: 5e3,
106
+ secure: false,
107
+ changeOrigin: true
108
+ },
109
+ {
110
+ context: ["/console-i18n/"],
111
+ target: proxy,
112
+ timeout: 5e3,
113
+ secure: false,
114
+ changeOrigin: true
115
+ }
116
+ ];
117
+ if (!disableDevPluginProxy) {
118
+ remoteProxy.unshift({
119
+ context: ["/dev-plugin/"],
120
+ target: "http://localhost:5000/",
121
+ timeout: 5e3,
122
+ secure: false,
123
+ changeOrigin: true,
124
+ pathRewrite: {
125
+ "/dev-plugin/": "/"
126
+ }
127
+ });
128
+ }
129
+ return remoteProxy;
130
+ }
131
+ var with_host_mfe_config_default = async (mfeConfig, overrideConfig, options = {}) => {
132
+ const mfe = await withModuleFederation(mfeConfig, overrideConfig);
133
+ const { disableDevPluginProxy = false } = options;
134
+ return (config) => merge2(mfe(config, { context: config.context }), {
135
+ devServer: {
136
+ proxy: createRemoteProxy({ disableDevPluginProxy })
137
+ }
138
+ });
139
+ };
140
+
141
+ // libs/dynamic-plugin-sdk-rspack/src/lib/with-monaco-editor.ts
142
+ import MonacoWebpackPlugin from "monaco-editor-webpack-plugin";
143
+ import { merge as merge3 } from "rspack-merge";
144
+ var with_monaco_editor_default = () => (config) => {
145
+ return merge3(config, {
146
+ plugins: [
147
+ new MonacoWebpackPlugin({
148
+ globalAPI: true,
149
+ languages: ["yaml"],
150
+ customLanguages: [
151
+ {
152
+ label: "yaml",
153
+ entry: "monaco-yaml",
154
+ worker: {
155
+ id: "monaco-yaml/yamlWorker",
156
+ entry: "monaco-yaml/yaml.worker"
157
+ }
158
+ }
159
+ ]
160
+ })
161
+ ]
162
+ });
163
+ };
164
+
165
+ // libs/dynamic-plugin-sdk-rspack/src/lib/with-remote-mfe-config.ts
166
+ import { execSync } from "child_process";
167
+ import { withModuleFederation as withModuleFederation2 } from "@nx/module-federation/rspack";
168
+ import { merge as merge4 } from "rspack-merge";
169
+ var generateName = (name) => {
170
+ const commitID = execSync("git rev-parse --short HEAD").toString().trim();
171
+ return `${name}__${commitID}`;
172
+ };
173
+ var with_remote_mfe_config_default = async (mfeConfig, overrideConfig) => {
174
+ const mfe = await withModuleFederation2(mfeConfig, overrideConfig);
175
+ return (config) => {
176
+ return merge4(mfe(config, { context: config.context }), {
177
+ output: { uniqueName: generateName(mfeConfig.name) },
178
+ devServer: {
179
+ headers: {
180
+ "Access-Control-Allow-Origin": "*"
181
+ }
182
+ }
183
+ });
184
+ };
185
+ };
186
+
187
+ // libs/dynamic-plugin-sdk-rspack/src/lib/with-yaml-loader.ts
188
+ import { merge as merge5 } from "rspack-merge";
189
+ var with_yaml_loader_default = () => (config) => {
190
+ return merge5(config, {
191
+ module: {
192
+ rules: [
193
+ {
194
+ test: /\.ya?ml$/,
195
+ use: "yaml-loader"
196
+ }
197
+ ]
198
+ }
199
+ });
200
+ };
201
+
202
+ // libs/dynamic-plugin-sdk-rspack/src/lib/utils.ts
203
+ var compose = (...fns) => (v) => fns.reduceRight((acc, curr) => curr(acc), v);
204
+ var log = (v, ...messages) => {
205
+ console.log(v, ...messages);
206
+ return v;
207
+ };
208
+ export {
209
+ compose,
210
+ log,
211
+ mfe_config_utils_default as mfeConfigUtils,
212
+ with_alauda_console_default as withAlaudaConsole,
213
+ with_base_config_default as withBaseConfig,
214
+ with_host_mfe_config_default as withHostMfeConfig,
215
+ with_monaco_editor_default as withMonacoEditor,
216
+ with_remote_mfe_config_default as withRemoteMfeConfig,
217
+ with_yaml_loader_default as withYamlLoader
218
+ };
@@ -0,0 +1,177 @@
1
+ /* eslint-disable jsdoc/require-returns, jsdoc/require-returns-description */
2
+
3
+ import fs from 'node:fs';
4
+ import path from 'node:path';
5
+
6
+ /**
7
+ * @param {string[]} argv
8
+ */
9
+ function parseArgs(argv) {
10
+ let configPath = 'i18n.config.js';
11
+
12
+ for (let i = 0; i < argv.length; i += 1) {
13
+ const arg = argv[i];
14
+
15
+ if (arg === '-c' || arg === '--config') {
16
+ const next = argv[i + 1];
17
+ if (!next || next.startsWith('-')) {
18
+ throw new Error('Missing value for -c/--config');
19
+ }
20
+ configPath = next;
21
+ i += 1;
22
+ continue;
23
+ }
24
+
25
+ if (arg.startsWith('--config=')) {
26
+ configPath = arg.slice('--config='.length);
27
+ continue;
28
+ }
29
+
30
+ if (arg === '-h' || arg === '--help') {
31
+ console.log('Usage: node lib/i18n-merge.js -c i18n.config.js');
32
+ // eslint-disable-next-line n/no-process-exit
33
+ process.exit(0);
34
+ }
35
+ }
36
+
37
+ return configPath;
38
+ }
39
+
40
+ /**
41
+ * @param {unknown} value
42
+ * @returns {value is object}
43
+ */
44
+ function isPlainObject(value) {
45
+ return value && typeof value === 'object' && !Array.isArray(value);
46
+ }
47
+
48
+ /**
49
+ * @param {object} source
50
+ */
51
+ function removeEmptyKeys(source) {
52
+ const result = {};
53
+
54
+ Object.keys(source).forEach(key => {
55
+ if (key.trim().length === 0) {
56
+ return;
57
+ }
58
+
59
+ const value = source[key];
60
+ if (isPlainObject(value)) {
61
+ result[key] = removeEmptyKeys(value);
62
+ return;
63
+ }
64
+
65
+ result[key] = value;
66
+ });
67
+
68
+ return result;
69
+ }
70
+
71
+ /**
72
+ * @param {object} target
73
+ * @param {object} source
74
+ */
75
+ function deepMerge(target, source) {
76
+ const result = { ...target };
77
+
78
+ Object.keys(source).forEach(key => {
79
+ const sourceValue = source[key];
80
+ const targetValue = result[key];
81
+
82
+ if (isPlainObject(targetValue) && isPlainObject(sourceValue)) {
83
+ result[key] = deepMerge(targetValue, sourceValue);
84
+ return;
85
+ }
86
+
87
+ result[key] = sourceValue;
88
+ });
89
+
90
+ return result;
91
+ }
92
+
93
+ /**
94
+ * @template T
95
+ * @param {string} filePath
96
+ * @returns {T}
97
+ */
98
+ function readJson(filePath) {
99
+ const content = fs.readFileSync(filePath, 'utf8');
100
+ return JSON.parse(content);
101
+ }
102
+
103
+ /**
104
+ * @param {string} cwd
105
+ * @param {string} configDir
106
+ * @param {string} inputPath
107
+ */
108
+ function resolveInputFile(cwd, configDir, inputPath) {
109
+ if (path.isAbsolute(inputPath)) {
110
+ return inputPath;
111
+ }
112
+
113
+ const fromCwd = path.resolve(cwd, inputPath);
114
+ if (fs.existsSync(fromCwd)) {
115
+ return fromCwd;
116
+ }
117
+
118
+ return path.resolve(configDir, inputPath);
119
+ }
120
+
121
+ async function run() {
122
+ const cwd = process.cwd();
123
+ const configArg = parseArgs(process.argv.slice(2));
124
+ const configPath = path.resolve(cwd, configArg);
125
+
126
+ if (!fs.existsSync(configPath)) {
127
+ throw new Error(`Config file not found: ${configPath}`);
128
+ }
129
+
130
+ const config = await import(configPath);
131
+ const inputs = config?.input;
132
+ const output = config?.output;
133
+
134
+ if (!Array.isArray(inputs) || inputs.length === 0) {
135
+ throw new Error('Config "input" must be a non-empty array');
136
+ }
137
+
138
+ if (typeof output !== 'string' || output.length === 0) {
139
+ throw new Error('Config "output" must be a non-empty string');
140
+ }
141
+
142
+ const configDir = path.dirname(configPath);
143
+ const merged = inputs.reduce((acc, item) => {
144
+ if (typeof item !== 'string' || item.length === 0) {
145
+ throw new Error('Each "input" item must be a non-empty string');
146
+ }
147
+
148
+ const inputFile = resolveInputFile(cwd, configDir, item);
149
+ if (!fs.existsSync(inputFile)) {
150
+ throw new Error(`Input file not found: ${inputFile}`);
151
+ }
152
+
153
+ const json = readJson(inputFile);
154
+ if (!isPlainObject(json)) {
155
+ throw new Error(`Input file must contain a JSON object: ${inputFile}`);
156
+ }
157
+
158
+ return deepMerge(acc, removeEmptyKeys(json));
159
+ }, {});
160
+
161
+ const outputFile = path.isAbsolute(output)
162
+ ? output
163
+ : path.resolve(cwd, output);
164
+
165
+ fs.mkdirSync(path.dirname(outputFile), { recursive: true });
166
+ fs.writeFileSync(outputFile, `${JSON.stringify(merged, null, 2)}\n`, 'utf8');
167
+
168
+ console.log(`Merged ${inputs.length} files -> ${outputFile}`);
169
+ }
170
+
171
+ try {
172
+ run();
173
+ } catch (error) {
174
+ console.error(error);
175
+ // eslint-disable-next-line n/no-process-exit
176
+ process.exit(1);
177
+ }
package/package.json ADDED
@@ -0,0 +1,24 @@
1
+ {
2
+ "name": "@alauda-fe/dynamic-plugin-sdk-rspack",
3
+ "version": "0.0.1-alpha.1",
4
+ "type": "module",
5
+ "main": "./index.js",
6
+ "sideEffects": false,
7
+ "publishConfig": {
8
+ "access": "public"
9
+ },
10
+ "peerDependencies": {
11
+ "css-loader": ">=6.0.0",
12
+ "monaco-editor-webpack-plugin": "^7.1.1",
13
+ "style-loader": ">=3.0.0"
14
+ },
15
+ "dependencies": {
16
+ "@rspack/core": "1.6.8",
17
+ "@rspack/dev-server": "1.2.1"
18
+ },
19
+ "packageManager": "yarn@4.16.0",
20
+ "resolutions": {
21
+ "bin-wrapper": "npm:bin-wrapper-china@latest"
22
+ },
23
+ "module": "./index.js"
24
+ }
package/src/index.d.ts ADDED
@@ -0,0 +1,9 @@
1
+ import mfeConfigUtils from './lib/mfe-config-utils';
2
+ import withAlaudaConsole from './lib/with-alauda-console';
3
+ import withBaseConfig from './lib/with-base-config';
4
+ import withHostMfeConfig from './lib/with-host-mfe-config';
5
+ import withMonacoEditor from './lib/with-monaco-editor';
6
+ import withRemoteMfeConfig from './lib/with-remote-mfe-config';
7
+ import withYamlLoader from './lib/with-yaml-loader';
8
+ export { compose, log } from './lib/utils';
9
+ export { mfeConfigUtils, withAlaudaConsole, withBaseConfig, withHostMfeConfig, withMonacoEditor, withRemoteMfeConfig, withYamlLoader, };
@@ -0,0 +1,10 @@
1
+ import type { SharedLibraryConfig } from '@nx/module-federation';
2
+ declare const _default: {
3
+ shared: (packageName: string, config: SharedLibraryConfig) => false | {
4
+ singleton: boolean;
5
+ strictVersion: boolean;
6
+ requiredVersion?: false | string;
7
+ eager?: boolean;
8
+ };
9
+ };
10
+ export default _default;
@@ -0,0 +1,4 @@
1
+ import { type Configuration } from '@rspack/core';
2
+ declare const compose: (...fns: Array<(config: Configuration) => Configuration>) => (v: Configuration) => import("@rspack/core").RspackOptions;
3
+ declare const log: <T>(v: T, ...messages: unknown[]) => T;
4
+ export { compose, log };
@@ -0,0 +1,4 @@
1
+ import { type BuildOptions } from '@alauda/custom-webpack';
2
+ import type { Configuration } from '@rspack/core';
3
+ declare const _default: (options?: BuildOptions) => Promise<(config: Configuration) => import("@rspack/core").RspackOptions>;
4
+ export default _default;
@@ -0,0 +1,3 @@
1
+ import type { Configuration } from '@rspack/core';
2
+ declare const _default: () => (config: Configuration) => import("@rspack/core").RspackOptions;
3
+ export default _default;
@@ -0,0 +1,6 @@
1
+ import type { ModuleFederationConfig, NxModuleFederationConfigOverride } from '@nx/module-federation';
2
+ import type { Configuration } from '@rspack/core';
3
+ declare const _default: (mfeConfig: ModuleFederationConfig, overrideConfig?: NxModuleFederationConfigOverride, options?: {
4
+ disableDevPluginProxy?: boolean;
5
+ }) => Promise<(config: Configuration) => import("@rspack/core").RspackOptions>;
6
+ export default _default;
@@ -0,0 +1,3 @@
1
+ import type { Configuration } from '@rspack/core';
2
+ declare const _default: () => (config: Configuration) => import("@rspack/core").RspackOptions;
3
+ export default _default;
@@ -0,0 +1,4 @@
1
+ import type { ModuleFederationConfig, NxModuleFederationConfigOverride } from '@nx/module-federation';
2
+ import type { Configuration } from '@rspack/core';
3
+ declare const _default: (mfeConfig: ModuleFederationConfig, overrideConfig?: NxModuleFederationConfigOverride) => Promise<(config: Configuration) => import("@rspack/core").RspackOptions>;
4
+ export default _default;
@@ -0,0 +1,2 @@
1
+ declare const _default: () => (config: any) => any;
2
+ export default _default;