rspkify 0.0.0-beta.0

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.
@@ -0,0 +1,100 @@
1
+ 'use strict';
2
+
3
+ var index = require('./index.cjs');
4
+ require('path');
5
+ require('node:path');
6
+ require('@rspack/core');
7
+ require('node:module');
8
+ require('net');
9
+ require('child_process');
10
+ require('fs');
11
+ require('module');
12
+ require('node:fs');
13
+ require('node:os');
14
+ require('node:url');
15
+ require('node:fs/promises');
16
+ require('node:events');
17
+ require('node:stream');
18
+ require('node:string_decoder');
19
+ require('url');
20
+ require('os');
21
+ require('crypto');
22
+
23
+ var SUPPORTED_FRAMEWORKS = ['react', 'preact', 'vue', 'h5'];
24
+ var SUPPORTED_APP_TYPES = ['spa', 'mpa'];
25
+ var SUPPORTED_BUILD_MODES = ['development', 'production', 'none'];
26
+ /**
27
+ * 验证 Rsify 配置文件
28
+ */
29
+ var validateConfig = /*#__PURE__*/function () {
30
+ var _ref = index._asyncToGenerator(/*#__PURE__*/index._regenerator().m(function _callee(config) {
31
+ var _config$build, _config$dev;
32
+ var errors, warnings, outputPath, port;
33
+ return index._regenerator().w(function (_context) {
34
+ while (1) switch (_context.n) {
35
+ case 0:
36
+ errors = [];
37
+ warnings = [];
38
+ if (config) {
39
+ _context.n = 1;
40
+ break;
41
+ }
42
+ errors.push('配置对象不能为空');
43
+ return _context.a(2, {
44
+ valid: false,
45
+ errors: errors,
46
+ warnings: warnings
47
+ });
48
+ case 1:
49
+ if (!(index._typeof(config) !== 'object' || Array.isArray(config))) {
50
+ _context.n = 2;
51
+ break;
52
+ }
53
+ errors.push('配置必须是一个对象');
54
+ return _context.a(2, {
55
+ valid: false,
56
+ errors: errors,
57
+ warnings: warnings
58
+ });
59
+ case 2:
60
+ if (!config.entry) {
61
+ warnings.push('未配置 entry,将使用默认入口 ./src/index.tsx');
62
+ }
63
+ if (config.framework && !SUPPORTED_FRAMEWORKS.includes(config.framework)) {
64
+ warnings.push("\u6846\u67B6 \"".concat(config.framework, "\" \u53EF\u80FD\u4E0D\u53D7\u652F\u6301\uFF0C\u63A8\u8350\u4F7F\u7528 ").concat(SUPPORTED_FRAMEWORKS.join('、')));
65
+ }
66
+ if (config.appType && !SUPPORTED_APP_TYPES.includes(config.appType)) {
67
+ errors.push("\u4E0D\u652F\u6301\u7684\u5E94\u7528\u7C7B\u578B: ".concat(config.appType, "\uFF0C\u652F\u6301\u7684\u7C7B\u578B: ").concat(SUPPORTED_APP_TYPES.join(', ')));
68
+ }
69
+ if ((_config$build = config.build) !== null && _config$build !== void 0 && _config$build.mode && !SUPPORTED_BUILD_MODES.includes(config.build.mode)) {
70
+ errors.push("\u4E0D\u652F\u6301\u7684\u6784\u5EFA\u6A21\u5F0F: ".concat(config.build.mode, "\uFF0C\u652F\u6301\u7684\u6A21\u5F0F: ").concat(SUPPORTED_BUILD_MODES.join(', ')));
71
+ }
72
+ if (config.output && index._typeof(config.output) === 'object' && 'path' in config.output) {
73
+ outputPath = config.output.path;
74
+ if (outputPath && typeof outputPath !== 'string') {
75
+ errors.push('output.path 必须是字符串');
76
+ }
77
+ }
78
+ if (((_config$dev = config.dev) === null || _config$dev === void 0 ? void 0 : _config$dev.port) !== undefined) {
79
+ port = Number(config.dev.port);
80
+ if (isNaN(port) || port < 0 || port > 65535) {
81
+ errors.push("\u65E0\u6548\u7684\u7AEF\u53E3\u53F7: ".concat(config.dev.port, "\uFF0C\u7AEF\u53E3\u8303\u56F4\u5E94\u4E3A 0-65535"));
82
+ }
83
+ }
84
+ if (config.moduleFederation && !config.moduleFederation.name) {
85
+ warnings.push('模块联邦未配置 name,将尝试从 package.json 读取');
86
+ }
87
+ return _context.a(2, {
88
+ valid: errors.length === 0,
89
+ errors: errors,
90
+ warnings: warnings
91
+ });
92
+ }
93
+ }, _callee);
94
+ }));
95
+ return function validateConfig(_x) {
96
+ return _ref.apply(this, arguments);
97
+ };
98
+ }();
99
+
100
+ exports.validateConfig = validateConfig;
@@ -0,0 +1,98 @@
1
+ import { d as _asyncToGenerator, e as _regenerator, h as _typeof } from './index.mjs';
2
+ import 'path';
3
+ import 'node:path';
4
+ import '@rspack/core';
5
+ import 'node:module';
6
+ import 'net';
7
+ import 'child_process';
8
+ import 'fs';
9
+ import 'module';
10
+ import 'node:fs';
11
+ import 'node:os';
12
+ import 'node:url';
13
+ import 'node:fs/promises';
14
+ import 'node:events';
15
+ import 'node:stream';
16
+ import 'node:string_decoder';
17
+ import 'url';
18
+ import 'os';
19
+ import 'crypto';
20
+
21
+ var SUPPORTED_FRAMEWORKS = ['react', 'preact', 'vue', 'h5'];
22
+ var SUPPORTED_APP_TYPES = ['spa', 'mpa'];
23
+ var SUPPORTED_BUILD_MODES = ['development', 'production', 'none'];
24
+ /**
25
+ * 验证 Rsify 配置文件
26
+ */
27
+ var validateConfig = /*#__PURE__*/function () {
28
+ var _ref = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(config) {
29
+ var _config$build, _config$dev;
30
+ var errors, warnings, outputPath, port;
31
+ return _regenerator().w(function (_context) {
32
+ while (1) switch (_context.n) {
33
+ case 0:
34
+ errors = [];
35
+ warnings = [];
36
+ if (config) {
37
+ _context.n = 1;
38
+ break;
39
+ }
40
+ errors.push('配置对象不能为空');
41
+ return _context.a(2, {
42
+ valid: false,
43
+ errors: errors,
44
+ warnings: warnings
45
+ });
46
+ case 1:
47
+ if (!(_typeof(config) !== 'object' || Array.isArray(config))) {
48
+ _context.n = 2;
49
+ break;
50
+ }
51
+ errors.push('配置必须是一个对象');
52
+ return _context.a(2, {
53
+ valid: false,
54
+ errors: errors,
55
+ warnings: warnings
56
+ });
57
+ case 2:
58
+ if (!config.entry) {
59
+ warnings.push('未配置 entry,将使用默认入口 ./src/index.tsx');
60
+ }
61
+ if (config.framework && !SUPPORTED_FRAMEWORKS.includes(config.framework)) {
62
+ warnings.push("\u6846\u67B6 \"".concat(config.framework, "\" \u53EF\u80FD\u4E0D\u53D7\u652F\u6301\uFF0C\u63A8\u8350\u4F7F\u7528 ").concat(SUPPORTED_FRAMEWORKS.join('、')));
63
+ }
64
+ if (config.appType && !SUPPORTED_APP_TYPES.includes(config.appType)) {
65
+ errors.push("\u4E0D\u652F\u6301\u7684\u5E94\u7528\u7C7B\u578B: ".concat(config.appType, "\uFF0C\u652F\u6301\u7684\u7C7B\u578B: ").concat(SUPPORTED_APP_TYPES.join(', ')));
66
+ }
67
+ if ((_config$build = config.build) !== null && _config$build !== void 0 && _config$build.mode && !SUPPORTED_BUILD_MODES.includes(config.build.mode)) {
68
+ errors.push("\u4E0D\u652F\u6301\u7684\u6784\u5EFA\u6A21\u5F0F: ".concat(config.build.mode, "\uFF0C\u652F\u6301\u7684\u6A21\u5F0F: ").concat(SUPPORTED_BUILD_MODES.join(', ')));
69
+ }
70
+ if (config.output && _typeof(config.output) === 'object' && 'path' in config.output) {
71
+ outputPath = config.output.path;
72
+ if (outputPath && typeof outputPath !== 'string') {
73
+ errors.push('output.path 必须是字符串');
74
+ }
75
+ }
76
+ if (((_config$dev = config.dev) === null || _config$dev === void 0 ? void 0 : _config$dev.port) !== undefined) {
77
+ port = Number(config.dev.port);
78
+ if (isNaN(port) || port < 0 || port > 65535) {
79
+ errors.push("\u65E0\u6548\u7684\u7AEF\u53E3\u53F7: ".concat(config.dev.port, "\uFF0C\u7AEF\u53E3\u8303\u56F4\u5E94\u4E3A 0-65535"));
80
+ }
81
+ }
82
+ if (config.moduleFederation && !config.moduleFederation.name) {
83
+ warnings.push('模块联邦未配置 name,将尝试从 package.json 读取');
84
+ }
85
+ return _context.a(2, {
86
+ valid: errors.length === 0,
87
+ errors: errors,
88
+ warnings: warnings
89
+ });
90
+ }
91
+ }, _callee);
92
+ }));
93
+ return function validateConfig(_x) {
94
+ return _ref.apply(this, arguments);
95
+ };
96
+ }();
97
+
98
+ export { validateConfig };
package/bin/index.cjs ADDED
@@ -0,0 +1,247 @@
1
+ 'use strict';
2
+
3
+ var index = require('./common/index.cjs');
4
+ require('path');
5
+ require('node:path');
6
+ require('@rspack/core');
7
+ require('node:module');
8
+ require('net');
9
+ require('child_process');
10
+ require('fs');
11
+ require('module');
12
+ require('node:fs');
13
+ require('node:os');
14
+ require('node:url');
15
+ require('node:fs/promises');
16
+ require('node:events');
17
+ require('node:stream');
18
+ require('node:string_decoder');
19
+ require('url');
20
+ require('os');
21
+ require('crypto');
22
+
23
+ /**
24
+ * 创建远程模块配置
25
+ *
26
+ * @example
27
+ * const remotes = createRemotes({
28
+ * app1: 'http://localhost:3001/remoteEntry.js',
29
+ * app2: 'http://localhost:3002/remoteEntry.js'
30
+ * })
31
+ * // => { app1: 'app1@http://localhost:3001/remoteEntry.js', ... }
32
+ */
33
+ function createRemotes(remotes) {
34
+ var result = {};
35
+ Object.entries(remotes).forEach(function (_ref) {
36
+ var _ref2 = index._slicedToArray(_ref, 2),
37
+ name = _ref2[0],
38
+ url = _ref2[1];
39
+ // 如果 URL 已经包含 name@,直接使用
40
+ if (url.includes('@')) {
41
+ result[name] = url;
42
+ } else {
43
+ // 否则添加 name@ 前缀
44
+ result[name] = "".concat(name, "@").concat(url);
45
+ }
46
+ });
47
+ return result;
48
+ }
49
+ /**
50
+ * 创建暴露模块配置
51
+ *
52
+ * @example
53
+ * const exposes = createExposes({
54
+ * './Button': './src/components/Button',
55
+ * './utils': './src/utils/index'
56
+ * })
57
+ */
58
+ function createExposes(exposes) {
59
+ return exposes;
60
+ }
61
+ /**
62
+ * 创建共享依赖配置
63
+ *
64
+ * @example
65
+ * const shared = createShared({
66
+ * react: { singleton: true },
67
+ * 'react-dom': { singleton: true }
68
+ * })
69
+ */
70
+ function createShared(shared) {
71
+ return shared;
72
+ }
73
+ /**
74
+ * 创建常用的 React 共享依赖配置
75
+ *
76
+ * @param version - React 版本,默认 '*'
77
+ * @param options - 配置选项
78
+ *
79
+ * @example
80
+ * const shared = createReactShared('^18.0.0')
81
+ */
82
+ function createReactShared(version, options) {
83
+ var _ref3 = options || {},
84
+ _ref3$singleton = _ref3.singleton,
85
+ singleton = _ref3$singleton === void 0 ? true : _ref3$singleton,
86
+ _ref3$strictVersion = _ref3.strictVersion,
87
+ strictVersion = _ref3$strictVersion === void 0 ? false : _ref3$strictVersion,
88
+ _ref3$eager = _ref3.eager,
89
+ eager = _ref3$eager === void 0 ? false : _ref3$eager;
90
+ return {
91
+ react: {
92
+ singleton: singleton,
93
+ strictVersion: strictVersion,
94
+ eager: eager,
95
+ requiredVersion: version || '*'
96
+ },
97
+ 'react-dom': {
98
+ singleton: singleton,
99
+ strictVersion: strictVersion,
100
+ eager: eager,
101
+ requiredVersion: version || '*'
102
+ }
103
+ };
104
+ }
105
+ /**
106
+ * 创建常用的 Vue 共享依赖配置
107
+ *
108
+ * @param version - Vue 版本,默认 '*'
109
+ * @param options - 配置选项
110
+ *
111
+ * @example
112
+ * const shared = createVueShared('^3.0.0')
113
+ */
114
+ function createVueShared(version, options) {
115
+ var _ref4 = options || {},
116
+ _ref4$singleton = _ref4.singleton,
117
+ singleton = _ref4$singleton === void 0 ? true : _ref4$singleton,
118
+ _ref4$strictVersion = _ref4.strictVersion,
119
+ strictVersion = _ref4$strictVersion === void 0 ? false : _ref4$strictVersion,
120
+ _ref4$eager = _ref4.eager,
121
+ eager = _ref4$eager === void 0 ? false : _ref4$eager;
122
+ return {
123
+ vue: {
124
+ singleton: singleton,
125
+ strictVersion: strictVersion,
126
+ eager: eager,
127
+ requiredVersion: version || '*'
128
+ }
129
+ };
130
+ }
131
+ /**
132
+ * 从环境变量创建远程模块配置
133
+ *
134
+ * @example
135
+ * // .env 文件
136
+ * REMOTE_APP1=http://localhost:3001/remoteEntry.js
137
+ * REMOTE_APP2=http://localhost:3002/remoteEntry.js
138
+ *
139
+ * // 使用
140
+ * const remotes = createRemotesFromEnv('REMOTE_')
141
+ */
142
+ function createRemotesFromEnv() {
143
+ var prefix = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'REMOTE_';
144
+ var remotes = {};
145
+ Object.keys(process.env).forEach(function (key) {
146
+ if (key.startsWith(prefix)) {
147
+ var name = key.replace(prefix, '').toLowerCase();
148
+ var url = process.env[key];
149
+ if (url) {
150
+ remotes[name] = "".concat(name, "@").concat(url);
151
+ }
152
+ }
153
+ });
154
+ return remotes;
155
+ }
156
+ /**
157
+ * 合并多个共享依赖配置
158
+ *
159
+ * @description
160
+ * 当同一个依赖在多个配置中出现时,后面的配置会覆盖前面的
161
+ *
162
+ * @example
163
+ * const shared = mergeShared(
164
+ * createReactShared('^18.0.0'),
165
+ * { lodash: { singleton: false } }
166
+ * )
167
+ */
168
+ function mergeShared() {
169
+ var result = {};
170
+ for (var _len = arguments.length, sharedObjects = new Array(_len), _key = 0; _key < _len; _key++) {
171
+ sharedObjects[_key] = arguments[_key];
172
+ }
173
+ sharedObjects.forEach(function (obj) {
174
+ if (obj) {
175
+ Object.assign(result, obj);
176
+ }
177
+ });
178
+ return result;
179
+ }
180
+ /**
181
+ * 快速创建共享依赖配置(简化版)
182
+ *
183
+ * @description
184
+ * 快速创建单例模式的共享依赖配置
185
+ *
186
+ * @example
187
+ * const shared = createQuickShared(['react', 'react-dom', 'lodash'])
188
+ * // => {
189
+ * // react: { singleton: true, requiredVersion: '*' },
190
+ * // 'react-dom': { singleton: true, requiredVersion: '*' },
191
+ * // lodash: { singleton: true, requiredVersion: '*' }
192
+ * // }
193
+ */
194
+ function createQuickShared(packages, options) {
195
+ var _ref5 = options || {},
196
+ _ref5$singleton = _ref5.singleton,
197
+ singleton = _ref5$singleton === void 0 ? true : _ref5$singleton,
198
+ _ref5$strictVersion = _ref5.strictVersion,
199
+ strictVersion = _ref5$strictVersion === void 0 ? false : _ref5$strictVersion,
200
+ _ref5$eager = _ref5.eager,
201
+ eager = _ref5$eager === void 0 ? false : _ref5$eager,
202
+ _ref5$requiredVersion = _ref5.requiredVersion,
203
+ requiredVersion = _ref5$requiredVersion === void 0 ? '*' : _ref5$requiredVersion;
204
+ var shared = {};
205
+ packages.forEach(function (pkg) {
206
+ shared[pkg] = {
207
+ singleton: singleton,
208
+ strictVersion: strictVersion,
209
+ eager: eager,
210
+ requiredVersion: requiredVersion
211
+ };
212
+ });
213
+ return shared;
214
+ }
215
+
216
+ // ============================================================================
217
+ // Rsify 主入口文件
218
+ // ============================================================================
219
+ /**
220
+ * Rspack 配置生成器
221
+ */
222
+ /**
223
+ * defineConfig 辅助函数(类型提示)
224
+ */
225
+ var defineConfig = function defineConfig(config) {
226
+ return config;
227
+ };
228
+
229
+ exports.RspackRunner = index.RspackRunner;
230
+ exports.createRspackConfig = index.rspackConfigPlugin;
231
+ exports.createSharedFromPackage = index.createSharedFromPackage;
232
+ exports.createWebpackConfig = index.rspackConfigPlugin;
233
+ exports.rspackConfigPlugin = index.rspackConfigPlugin;
234
+ exports.runRspackBuild = index.runRspackBuild;
235
+ exports.runWebpackBuild = index.runWebpackBuild;
236
+ exports.setCSSInTSPlugin = index.setCSSInTSPlugin;
237
+ exports.webpackConfigPlugin = index.rspackConfigPlugin;
238
+ exports.webpckConfigPlugin = index.webpckConfigPlugin;
239
+ exports.createExposes = createExposes;
240
+ exports.createQuickShared = createQuickShared;
241
+ exports.createReactShared = createReactShared;
242
+ exports.createRemotes = createRemotes;
243
+ exports.createRemotesFromEnv = createRemotesFromEnv;
244
+ exports.createShared = createShared;
245
+ exports.createVueShared = createVueShared;
246
+ exports.defineConfig = defineConfig;
247
+ exports.mergeShared = mergeShared;