autosnippet 1.2.3 → 1.2.4

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.
Files changed (2) hide show
  1. package/bin/injection.js +27 -5
  2. package/package.json +1 -1
package/bin/injection.js CHANGED
@@ -133,15 +133,37 @@ async function handleHeaderLine(specFile, updateFile, headerLine, importArray, i
133
133
  header.headRelativePath = headerInfo.headRelativePath; // 相对于模块根目录的相对路径
134
134
  header.specName = '<' + headerInfo.moduleName + '/' + header.headerName + '>';
135
135
 
136
+ // ✅ 优先检查:如果头文件路径和当前文件在同一个目录下,直接使用文件名
137
+ const headRelativePathFromInfo = headerInfo.headRelativePath;
138
+ let isSameDirectory = false;
139
+
140
+ if (headRelativePathFromInfo) {
141
+ // 从头文件相对路径构造完整路径
142
+ const headFullPath = path.join(currentPackageInfo.path, headRelativePathFromInfo);
143
+ const headDir = path.dirname(headFullPath);
144
+
145
+ // 检查是否在同一个目录
146
+ if (updateFileDir === headDir) {
147
+ isSameDirectory = true;
148
+ // 如果同目录,直接使用文件名
149
+ header.relativePathToCurrentFile = header.headerName;
150
+ }
151
+ }
152
+
136
153
  // ✅ 判断是否为同一模块
137
154
  const isSameModule = currentModuleName === headerInfo.moduleName;
155
+
156
+ // 如果同目录,视为同一模块,使用相对路径
157
+ const shouldUseRelativePath = isSameDirectory || isSameModule;
158
+
159
+ console.log(`🔍 模块识别: 当前模块=${currentModuleName}, 头文件模块=${headerInfo.moduleName}, 同一模块=${isSameModule}, 同目录=${isSameDirectory}`);
138
160
 
139
- // ✅ 如果是同一模块,计算相对于当前文件的相对路径
140
- if (isSameModule && headerInfo.headRelativePath) {
161
+ // ✅ 如果是同一模块且不同目录,计算相对于当前文件的相对路径
162
+ if (isSameModule && headRelativePathFromInfo && !isSameDirectory) {
141
163
  // 当前文件相对于模块根目录的路径
142
164
  const currentFileRelativeToModuleRoot = path.relative(currentPackageInfo.path, updateFile);
143
165
  // 头文件相对于模块根目录的路径
144
- const headRelativeToModuleRoot = headerInfo.headRelativePath;
166
+ const headRelativeToModuleRoot = headRelativePathFromInfo;
145
167
 
146
168
  // 计算从当前文件到头文件的相对路径
147
169
  const currentFileDir = path.dirname(currentFileRelativeToModuleRoot);
@@ -150,8 +172,8 @@ async function handleHeaderLine(specFile, updateFile, headerLine, importArray, i
150
172
  header.relativePathToCurrentFile = relativePathToHeader;
151
173
  }
152
174
 
153
- // 如果是同一模块,使用相对路径;否则使用 <> 格式
154
- handleModuleHeader(specFile, updateFile, header, importArray, !isSameModule);
175
+ // 如果同目录或同一模块,使用相对路径;否则使用 <> 格式
176
+ handleModuleHeader(specFile, updateFile, header, importArray, !shouldUseRelativePath);
155
177
  }
156
178
 
157
179
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "autosnippet",
3
- "version": "1.2.3",
3
+ "version": "1.2.4",
4
4
  "description": "A iOS module management tool.",
5
5
  "main": "index.js",
6
6
  "scripts": {