autosnippet 1.2.3 → 1.2.5
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 +74 -5
- package/package.json +1 -1
package/bin/injection.js
CHANGED
|
@@ -133,15 +133,84 @@ 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
|
+
// headRelativePathFromInfo 是相对于模块根目录的路径(如 Code/BDGlobalVideoPlayerManager.h)
|
|
143
|
+
// 当前文件路径:/Users/gaoxuefeng/Documents/github/BiliDemo/VideoPlayer/VideoPlayer/VideoPlayerViews/Code/BDVideoPlayerController.m
|
|
144
|
+
// 如果头文件路径是 Code/BDGlobalVideoPlayerManager.h,说明它在模块根目录下的 Code/ 目录中
|
|
145
|
+
|
|
146
|
+
// 方法:从当前文件路径向上查找,直到找到包含 headRelativePathFromInfo 的路径
|
|
147
|
+
let headFullPath = null;
|
|
148
|
+
let headDir = null;
|
|
149
|
+
|
|
150
|
+
// 方案1:尝试在当前文件所在目录直接查找
|
|
151
|
+
const headName = path.basename(headRelativePathFromInfo); // BDGlobalVideoPlayerManager.h
|
|
152
|
+
const headInCurrentDir = path.join(updateFileDir, headName);
|
|
153
|
+
if (fs.existsSync(headInCurrentDir)) {
|
|
154
|
+
headFullPath = headInCurrentDir;
|
|
155
|
+
headDir = updateFileDir;
|
|
156
|
+
} else {
|
|
157
|
+
// 方案2:尝试使用模块路径拼接
|
|
158
|
+
// 如果 headRelativePathFromInfo = "Code/BDGlobalVideoPlayerManager.h"
|
|
159
|
+
// 当前文件在 VideoPlayer/VideoPlayer/VideoPlayerViews/Code/ 目录
|
|
160
|
+
// 那么头文件应该在 VideoPlayer/VideoPlayer/VideoPlayerViews/Code/BDGlobalVideoPlayerManager.h
|
|
161
|
+
// 即:从当前文件所在目录,向上找到模块根目录,然后拼接相对路径
|
|
162
|
+
|
|
163
|
+
// 尝试多种可能的路径
|
|
164
|
+
const possiblePaths = [
|
|
165
|
+
path.join(updateFileDir, headName), // 当前目录
|
|
166
|
+
path.join(currentPackageInfo.path, headRelativePathFromInfo), // 当前模块根目录
|
|
167
|
+
];
|
|
168
|
+
|
|
169
|
+
// 如果当前文件在 Code/ 目录下,尝试向上查找模块根目录
|
|
170
|
+
if (updateFileDir.endsWith('Code')) {
|
|
171
|
+
const possibleModuleRoot = path.dirname(updateFileDir);
|
|
172
|
+
possiblePaths.push(path.join(possibleModuleRoot, headRelativePathFromInfo));
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
for (const possiblePath of possiblePaths) {
|
|
176
|
+
if (fs.existsSync(possiblePath)) {
|
|
177
|
+
headFullPath = possiblePath;
|
|
178
|
+
headDir = path.dirname(possiblePath);
|
|
179
|
+
break;
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
if (headDir) {
|
|
185
|
+
console.log(`🔍 目录比较: 当前目录=${updateFileDir}, 头文件目录=${headDir}, headRelativePath=${headRelativePathFromInfo}`);
|
|
186
|
+
|
|
187
|
+
// 检查是否在同一个目录(使用规范化路径比较)
|
|
188
|
+
const normalizedUpdateDir = path.normalize(updateFileDir);
|
|
189
|
+
const normalizedHeadDir = path.normalize(headDir);
|
|
190
|
+
|
|
191
|
+
if (normalizedUpdateDir === normalizedHeadDir) {
|
|
192
|
+
isSameDirectory = true;
|
|
193
|
+
// 如果同目录,直接使用文件名
|
|
194
|
+
header.relativePathToCurrentFile = header.headerName;
|
|
195
|
+
console.log(`✅ 识别为同目录,使用文件名: ${header.headerName}`);
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
|
|
136
200
|
// ✅ 判断是否为同一模块
|
|
137
201
|
const isSameModule = currentModuleName === headerInfo.moduleName;
|
|
202
|
+
|
|
203
|
+
// 如果同目录,视为同一模块,使用相对路径
|
|
204
|
+
const shouldUseRelativePath = isSameDirectory || isSameModule;
|
|
205
|
+
|
|
206
|
+
console.log(`🔍 模块识别: 当前模块=${currentModuleName}, 头文件模块=${headerInfo.moduleName}, 同一模块=${isSameModule}, 同目录=${isSameDirectory}`);
|
|
138
207
|
|
|
139
|
-
// ✅
|
|
140
|
-
if (isSameModule &&
|
|
208
|
+
// ✅ 如果是同一模块且不同目录,计算相对于当前文件的相对路径
|
|
209
|
+
if (isSameModule && headRelativePathFromInfo && !isSameDirectory) {
|
|
141
210
|
// 当前文件相对于模块根目录的路径
|
|
142
211
|
const currentFileRelativeToModuleRoot = path.relative(currentPackageInfo.path, updateFile);
|
|
143
212
|
// 头文件相对于模块根目录的路径
|
|
144
|
-
const headRelativeToModuleRoot =
|
|
213
|
+
const headRelativeToModuleRoot = headRelativePathFromInfo;
|
|
145
214
|
|
|
146
215
|
// 计算从当前文件到头文件的相对路径
|
|
147
216
|
const currentFileDir = path.dirname(currentFileRelativeToModuleRoot);
|
|
@@ -150,8 +219,8 @@ async function handleHeaderLine(specFile, updateFile, headerLine, importArray, i
|
|
|
150
219
|
header.relativePathToCurrentFile = relativePathToHeader;
|
|
151
220
|
}
|
|
152
221
|
|
|
153
|
-
//
|
|
154
|
-
handleModuleHeader(specFile, updateFile, header, importArray, !
|
|
222
|
+
// 如果同目录或同一模块,使用相对路径;否则使用 <> 格式
|
|
223
|
+
handleModuleHeader(specFile, updateFile, header, importArray, !shouldUseRelativePath);
|
|
155
224
|
}
|
|
156
225
|
|
|
157
226
|
/**
|