@lark-apaas/miaoda-presets 1.0.6 → 1.0.8

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.
@@ -170,22 +170,6 @@ async function copyToClipboard(text) {
170
170
  return fallbackCopyToClipboard(text);
171
171
  }
172
172
  }
173
- // 获取父窗口 origin
174
- function getPreviewParentOrigin() {
175
- const { origin } = window.location;
176
- // 线上环境
177
- if (origin.includes('feishuapp.cn') ||
178
- origin.includes('miaoda.feishuapp.net')) {
179
- return 'https://miaoda.feishu.cn';
180
- }
181
- // PRE 环境
182
- if (origin.includes('fsapp.kundou.cn') ||
183
- origin.includes('miaoda-pre.feishuapp.net')) {
184
- return 'https://miaoda.feishu-pre.cn';
185
- }
186
- // BOE 环境
187
- return 'https://miaoda.feishu-boe.cn';
188
- }
189
173
  /**
190
174
  * Creates the main `div` element for the overlay to render.
191
175
  * @returns {void}
@@ -193,11 +177,40 @@ function getPreviewParentOrigin() {
193
177
  function render() {
194
178
  ensureRootExists(function () {
195
179
  removeAllChildren(root);
180
+ const getEnvOrigin = () => {
181
+ return typeof process !== 'undefined' && process.env
182
+ ? process.env.FORCE_FRAMEWORK_DOMAIN_MAIN
183
+ : undefined;
184
+ };
185
+ const getLegacyParentOrigin = () => {
186
+ const currentOrigin = window.location?.origin || '';
187
+ if (currentOrigin.includes('force.feishuapp.net')) {
188
+ return 'https://force.feishu.cn';
189
+ }
190
+ if (currentOrigin.includes('force-pre.feishuapp.net')) {
191
+ return 'https://force.feishu-pre.cn';
192
+ }
193
+ if (currentOrigin.includes('force.byted.org')) {
194
+ return 'https://force.feishu-boe.cn';
195
+ }
196
+ if (currentOrigin.includes('feishuapp.cn') || currentOrigin.includes('miaoda.feishuapp.net')) {
197
+ return 'https://miaoda.feishu.cn';
198
+ }
199
+ if (currentOrigin.includes('fsapp.kundou.cn') || currentOrigin.includes('miaoda-pre.feishuapp.net')) {
200
+ return 'https://miaoda.feishu-pre.cn';
201
+ }
202
+ return 'https://miaoda.feishu-boe.cn';
203
+ };
196
204
  // 发送 postMessage
197
205
  const sendPostMessage = (message, targetOrigin) => {
198
- const origin = targetOrigin || getPreviewParentOrigin();
206
+ const parentOrigin = getEnvOrigin() || getLegacyParentOrigin();
207
+ const origin = targetOrigin || parentOrigin;
199
208
  window.parent.postMessage(message, origin);
200
209
  };
210
+ // 通知前端,渲染错误页面已准备就绪
211
+ sendPostMessage({
212
+ type: 'PreviewReady'
213
+ });
201
214
  // 通知主应用存在自定义 overlay
202
215
  sendPostMessage({
203
216
  type: 'app-features',
@@ -119,6 +119,7 @@ function createRecommendRspackConfig(options) {
119
119
  'process.env.NODE_ENV': JSON.stringify(isDev ? 'development' : 'production'),
120
120
  'process.env.CWD': JSON.stringify(process.cwd()),
121
121
  'process.env.runtimeMode': JSON.stringify(runtimeMode),
122
+ 'process.env.FORCE_FRAMEWORK_DOMAIN_MAIN': JSON.stringify(process.env.FORCE_FRAMEWORK_DOMAIN_MAIN ?? ''),
122
123
  }),
123
124
  new core_1.default.optimize.LimitChunkCountPlugin({
124
125
  maxChunks: 1,
@@ -180,22 +181,13 @@ function createRecommendRspackConfig(options) {
180
181
  },
181
182
  devtool: isDev ? 'source-map' : false, // 对应vite的sourcemap配置
182
183
  devServer: {
183
- headers: req => {
184
- // 获取请求的Origin头
185
- const requestOrigin = req.headers.origin ?? '';
186
- // 定义允许的域名白名单
187
- const allowedOrigins = [
188
- 'https://miaoda.feishu.cn',
189
- 'https://miaoda.feishu-boe.cn',
190
- 'https://miaoda.feishu-pre.cn',
191
- ];
192
- // 检查请求的Origin是否在允许的列表中
193
- const allowedOrigin = allowedOrigins.includes(requestOrigin)
194
- ? requestOrigin
195
- : allowedOrigins[0]; // 默认返回第一个允许的域名
196
- return {
197
- 'Access-Control-Allow-Origin': allowedOrigin,
198
- };
184
+ headers: _req => {
185
+ const headers = {};
186
+ const allowedOrigin = process.env.FORCE_FRAMEWORK_DOMAIN_MAIN;
187
+ if (!allowedOrigin)
188
+ return headers;
189
+ headers['Access-Control-Allow-Origin'] = allowedOrigin;
190
+ return headers;
199
191
  },
200
192
  onListening(server) {
201
193
  if (runtimeMode === 'fullstack') {
@@ -50,7 +50,8 @@ function createRecommendTailwindConfig(options) {
50
50
  }
51
51
  }
52
52
  return {
53
- darkMode: 'class',
53
+ // 从当前 妙搭 场景来看: 禁用掉 darkMode 保持一套主题
54
+ darkMode: false,
54
55
  content: [
55
56
  pkgPath,
56
57
  ].filter(Boolean),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lark-apaas/miaoda-presets",
3
- "version": "1.0.6",
3
+ "version": "1.0.8",
4
4
  "files": [
5
5
  "lib"
6
6
  ],
@@ -61,5 +61,6 @@
61
61
  "peerDependencies": {
62
62
  "react": ">=16.14.0",
63
63
  "react-dom": ">=16.14.0"
64
- }
64
+ },
65
+ "gitHead": "68657b650e5f2343843850323db2b3beae697ace"
65
66
  }
@@ -1,262 +0,0 @@
1
- "use strict";
2
- /**
3
- * Webpack HMR 耗时计算插件 JavaScript 版本
4
- * 在浏览器 Console 打印热更文件和耗时信息
5
- */
6
- class HMRTimingPlugin {
7
- constructor(options = {}) {
8
- this.options = {
9
- threshold: options.threshold || 1000
10
- };
11
- this.hmrStartTime = null;
12
- this.changedFiles = new Set();
13
- this.devServer = null;
14
- }
15
- apply(compiler) {
16
- const pluginName = 'HMRTimingPlugin';
17
- // 在 devServer 启动后保存引用
18
- if (compiler.options.devServer) {
19
- const originalSetupMiddlewares = compiler.options.devServer.setupMiddlewares;
20
- const self = this;
21
- compiler.options.devServer.setupMiddlewares = function (middlewares, devServer) {
22
- // 保存 devServer 实例的引用
23
- self.devServer = devServer;
24
- global.__webpack_dev_server__ = devServer;
25
- if (originalSetupMiddlewares) {
26
- return originalSetupMiddlewares(middlewares, devServer);
27
- }
28
- return middlewares;
29
- };
30
- }
31
- // 监听文件变化
32
- compiler.hooks.invalid.tap(pluginName, (fileName) => {
33
- this.hmrStartTime = Date.now();
34
- this.changedFiles.clear();
35
- if (fileName) {
36
- this.changedFiles.add(fileName);
37
- }
38
- });
39
- // 监听 watch 运行开始
40
- compiler.hooks.watchRun.tapAsync(pluginName, (compiler, callback) => {
41
- if (!this.hmrStartTime) {
42
- this.hmrStartTime = Date.now();
43
- }
44
- // 收集变化的文件
45
- if (compiler.modifiedFiles) {
46
- compiler.modifiedFiles.forEach(file => this.changedFiles.add(file));
47
- }
48
- if (compiler.removedFiles) {
49
- compiler.removedFiles.forEach(file => this.changedFiles.add(file));
50
- }
51
- callback();
52
- });
53
- // 监听编译完成
54
- compiler.hooks.done.tap(pluginName, (stats) => {
55
- if (this.hmrStartTime === null)
56
- return;
57
- const totalTime = Date.now() - this.hmrStartTime;
58
- // 获取实际更新的模块
59
- const updatedModules = new Set();
60
- stats.compilation.modules.forEach(module => {
61
- const identifier = module.resource || module.identifier?.();
62
- if (identifier && typeof identifier === 'string') {
63
- // 过滤掉 node_modules 中的模块
64
- if (!identifier.includes('node_modules')) {
65
- updatedModules.add(identifier);
66
- }
67
- }
68
- });
69
- // 合并文件列表
70
- const allChangedFiles = new Set([
71
- ...Array.from(this.changedFiles),
72
- ...Array.from(updatedModules)
73
- ]);
74
- // 简化文件路径
75
- const simplifiedFiles = Array.from(allChangedFiles)
76
- .map(file => {
77
- // 移除项目根路径
78
- const relativePath = file.replace(compiler.context || '', '');
79
- // 移除开头的斜杠
80
- return relativePath.replace(/^[\/\\]/, '');
81
- })
82
- .filter(file => file && file.length > 0)
83
- .slice(0, 10); // 最多显示10个文件
84
- const timingInfo = {
85
- totalTime,
86
- changedFiles: simplifiedFiles,
87
- modules: stats.compilation.modules.size,
88
- isOverThreshold: totalTime > this.options.threshold,
89
- threshold: this.options.threshold
90
- };
91
- // 通过 WebSocket 发送到浏览器
92
- this.sendToBrowser(compiler, timingInfo);
93
- // 重置
94
- this.changedFiles.clear();
95
- });
96
- // 注入客户端代码
97
- this.injectClientScript(compiler);
98
- }
99
- sendToBrowser(compiler, timingInfo) {
100
- // 使用 done hook 确保在编译完成后发送
101
- const server = this.getDevServer(compiler);
102
- if (server) {
103
- if (server.sockWrite) {
104
- // webpack-dev-server 3.x
105
- server.sockWrite(server.sockets, 'hmr-timing', timingInfo);
106
- }
107
- else if (server.sendMessage) {
108
- // webpack-dev-server 4.x/5.x
109
- const clients = server.webSocketServer?.clients || server.clients;
110
- server.sendMessage(clients, 'hmr-timing', timingInfo);
111
- }
112
- }
113
- }
114
- getDevServer(compiler) {
115
- // 尝试多种方式获取 devServer 实例
116
- // 方式1: 从 compiler.options.devServer 存储的引用
117
- if (compiler.options.devServer && compiler.options.devServer.__instance) {
118
- return compiler.options.devServer.__instance;
119
- }
120
- // 方式2: 从全局变量
121
- if (global.__webpack_dev_server__) {
122
- return global.__webpack_dev_server__;
123
- }
124
- // 方式3: 从 compiler 上挂载的引用
125
- if (compiler.__webpack_dev_server__) {
126
- return compiler.__webpack_dev_server__;
127
- }
128
- // 方式4: 在 infrastructure 日志中查找
129
- if (compiler.infrastructureLogger) {
130
- const logger = compiler.infrastructureLogger;
131
- if (logger.__devServer) {
132
- return logger.__devServer;
133
- }
134
- }
135
- return null;
136
- }
137
- injectClientScript(compiler) {
138
- const clientScript = `
139
- ;(function() {
140
- if (typeof window === 'undefined' || !module.hot) return;
141
-
142
- const threshold = ${this.options.threshold};
143
-
144
- // 显示 HMR 耗时和变化文件
145
- function logHMRTiming(data) {
146
- const color = data.isOverThreshold ? '#ff9800' : '#4caf50';
147
-
148
- // 主要信息
149
- console.log(
150
- '%c🔥 HMR 更新完成 - 耗时: %c' + data.totalTime + 'ms',
151
- 'color: ' + color + '; font-weight: bold; font-size: 14px;',
152
- 'color: ' + color + '; font-weight: bold; font-size: 16px;'
153
- );
154
-
155
- // 热更文件列表
156
- if (data.changedFiles && data.changedFiles.length > 0) {
157
- console.group('📝 热更文件 (' + data.changedFiles.length + ')');
158
- data.changedFiles.forEach(function(file) {
159
- console.log(' •', file);
160
- });
161
- console.groupEnd();
162
- }
163
-
164
- // 超过阈值警告
165
- if (data.isOverThreshold) {
166
- console.warn('⚠️ HMR 耗时超过阈值 ' + threshold + 'ms');
167
- }
168
-
169
- console.log(''); // 空行分隔
170
- }
171
-
172
- // 监听 webpack-dev-server 的 WebSocket 消息
173
- if (typeof __webpack_dev_server_client__ !== 'undefined') {
174
- // webpack-dev-server 4.x/5.x
175
- const originalOnMessage = __webpack_dev_server_client__.onMessage;
176
- __webpack_dev_server_client__.onMessage = function(message) {
177
- if (message.type === 'hmr-timing') {
178
- logHMRTiming(message.data);
179
- }
180
- if (originalOnMessage) {
181
- return originalOnMessage.apply(this, arguments);
182
- }
183
- };
184
- } else {
185
- // 备用方案:监听 WebSocket
186
- setTimeout(function() {
187
- const ws = window.__webpack_dev_server_ws__;
188
- if (ws && ws.addEventListener) {
189
- ws.addEventListener('message', function(event) {
190
- try {
191
- const message = JSON.parse(event.data);
192
- if (message.type === 'hmr-timing') {
193
- logHMRTiming(message.data);
194
- }
195
- } catch (e) {}
196
- });
197
- }
198
- }, 1000);
199
- }
200
- })();
201
- `;
202
- compiler.hooks.compilation.tap('HMRTimingPlugin', (compilation) => {
203
- compilation.hooks.processAssets.tap({
204
- name: 'HMRTimingPlugin',
205
- stage: compilation.constructor.PROCESS_ASSETS_STAGE_ADDITIONAL,
206
- }, () => {
207
- // 注入到主入口文件
208
- const mainAssets = Object.keys(compilation.assets).filter(name => name.match(/^(main|index|app|bundle).*\.js$/) && !name.includes('hot-update'));
209
- if (mainAssets.length > 0) {
210
- const assetName = mainAssets[0];
211
- const asset = compilation.assets[assetName];
212
- const source = asset.source();
213
- const newSource = clientScript + '\n' + source;
214
- compilation.assets[assetName] = {
215
- source: () => newSource,
216
- size: () => newSource.length,
217
- map: () => asset.map ? asset.map() : null
218
- };
219
- }
220
- });
221
- });
222
- }
223
- }
224
- module.exports = HMRTimingPlugin;
225
- /**
226
- * 使用示例:
227
- *
228
- * // webpack.config.js
229
- * const HMRTimingPlugin = require('./HMRTimingPlugin');
230
- *
231
- * module.exports = {
232
- * mode: 'development',
233
- * devServer: {
234
- * hot: true,
235
- * },
236
- * plugins: [
237
- * new HMRTimingPlugin({
238
- * threshold: 1000 // 超过1秒会显示警告
239
- * })
240
- * ]
241
- * };
242
- *
243
- * 浏览器控制台输出示例:
244
- *
245
- * 🔥 HMR 更新完成 - 耗时: 523ms
246
- * 📝 热更文件 (2)
247
- * • src/components/App.jsx
248
- * • src/styles/main.css
249
- *
250
- * 🔥 HMR 更新完成 - 耗时: 1250ms
251
- * 📝 热更文件 (1)
252
- * • src/utils/helper.js
253
- * ⚠️ HMR 耗时超过阈值 1000ms
254
- *
255
- * 功能特性:
256
- * - 显示 HMR 耗时(带颜色提示)
257
- * - 显示热更新的文件列表(可折叠)
258
- * - 超过阈值时显示警告
259
- * - 通过 DevServer WebSocket 通信
260
- * - 自动过滤 node_modules
261
- * - 简化文件路径显示
262
- */