autosnippet 1.2.2 → 1.2.3

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/bin/injection.js CHANGED
@@ -17,18 +17,42 @@ const headerMark = '// ahead ';
17
17
  const importReg = /^\#import\s*<\w+\/\w+.h>$/;
18
18
 
19
19
  function createHeader(headerLine) {
20
- const header = headerLine.split(headerMark)[1].trim();
21
- const headerArray = header.split('/');
22
- const moduleName = headerArray[0].substr(1);
23
- const headerName = headerArray[1].substr(0, headerArray[1].length - 1);
24
-
20
+ // 格式:// ahead <Module/Header.h> [relative/path/to/Header.h]
21
+ // 或:// ahead &lt;Module/Header.h&gt; [relative/path/to/Header.h] (转义格式)
22
+ const content = headerLine.split(headerMark)[1].trim();
23
+
24
+ // 匹配 <Module/Header.h> 或 &lt;Module/Header.h&gt; 以及可选的相对路径
25
+ const match = content.match(/^(?:&lt;|<)(\w+)\/(\w+\.h)(?:&gt;|>)(?:\s+(.+))?$/);
26
+
27
+ if (!match) {
28
+ // 兼容旧格式:直接解析
29
+ const headerArray = content.split('/');
30
+ const moduleName = headerArray[0].substr(1);
31
+ const headerName = headerArray[1].substr(0, headerArray[1].length - 1);
32
+
33
+ return {
34
+ name: content,
35
+ specName: headerArray[0] + '/' + headerArray[0].substr(1) + '.h>',
36
+ moduleName: moduleName,
37
+ headerName: headerName,
38
+ moduleStrName: '"' + moduleName + '.h"',
39
+ headerStrName: '"' + headerName + '"',
40
+ headRelativePathFromMark: null,
41
+ };
42
+ }
43
+
44
+ const moduleName = match[1];
45
+ const headerName = match[2];
46
+ const headRelativePathFromMark = match[3] || null; // 相对路径(如果有)
47
+
25
48
  return {
26
- name: header,
27
- specName: headerArray[0] + '/' + headerArray[0].substr(1) + '.h>',
49
+ name: `<${moduleName}/${headerName}>`,
50
+ specName: `<${moduleName}/${headerName}>`,
28
51
  moduleName: moduleName,
29
52
  headerName: headerName,
30
- moduleStrName: '"' + moduleName + '.h"',
31
- headerStrName: '"' + headerName + '"',
53
+ moduleStrName: `"${moduleName}.h"`,
54
+ headerStrName: `"${headerName}"`,
55
+ headRelativePathFromMark: headRelativePathFromMark, // 从标记中提取的相对路径
32
56
  };
33
57
  }
34
58
 
package/bin/watch.js CHANGED
@@ -13,7 +13,8 @@ const alinkMark = 'alink';
13
13
  const wellMark = '#';
14
14
  const atMark = '@';
15
15
 
16
- const headerReg = /^\/\/ ahead <\w+\/\w+.h>(\s+.+)?$/;
16
+ // 匹配原始格式和转义格式:// ahead <Module/Header.h> 或 // ahead &lt;Module/Header.h&gt;
17
+ const headerReg = /^\/\/ ahead\s+(?:&lt;|<)(\w+)\/(\w+\.h)(?:&gt;|>)(\s+.+)?$/;
17
18
  const headerSwiftReg = /^\/\/ ahead \w+$/;
18
19
  const importReg = /^\#import\s*<\w+\/\w+.h>$/;
19
20
  const importSwiftReg = /^import\s*\w+$/;
@@ -148,14 +149,22 @@ function processFileChange(specFile, updateFile, relativePath) {
148
149
  }
149
150
 
150
151
  if (headerLine) {
151
- const isMatch = currHeaderReg.test(headerLine);
152
- console.log(`📋 检查 // ahead 标记: ${headerLine}, 匹配: ${isMatch}`);
152
+ // 先解码 HTML 实体(&lt; -> <, &gt; -> >, &amp; -> &)
153
+ let decodedHeaderLine = headerLine
154
+ .replace(/&lt;/g, '<')
155
+ .replace(/&gt;/g, '>')
156
+ .replace(/&amp;/g, '&');
157
+
158
+ const isMatch = currHeaderReg.test(decodedHeaderLine);
159
+ console.log(`📋 检查 // ahead 标记: ${headerLine}`);
160
+ console.log(`📋 解码后: ${decodedHeaderLine}, 匹配: ${isMatch}`);
153
161
 
154
162
  if (isMatch) {
155
163
  console.log(`✅ 触发头文件注入: ${updateFile}`);
156
164
  clearTimeout(timeoutHead);
157
165
  timeoutHead = setTimeout(() => {
158
- checkAnotherFile(specFile, updateFile, headerLine, importArray, isSwift);
166
+ // 传递解码后的 headerLine
167
+ checkAnotherFile(specFile, updateFile, decodedHeaderLine, importArray, isSwift);
159
168
  }, DEBOUNCE_DELAY);
160
169
  } else {
161
170
  console.log(`⚠️ // ahead 标记格式不匹配,期望格式: // ahead <Module/Header.h> [相对路径]`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "autosnippet",
3
- "version": "1.2.2",
3
+ "version": "1.2.3",
4
4
  "description": "A iOS module management tool.",
5
5
  "main": "index.js",
6
6
  "scripts": {