diff --git a/packages/uni-cli-shared/src/utils.ts b/packages/uni-cli-shared/src/utils.ts index 6ff76d7d517..ad34212f667 100644 --- a/packages/uni-cli-shared/src/utils.ts +++ b/packages/uni-cli-shared/src/utils.ts @@ -107,10 +107,16 @@ export function normalizeMiniProgramFilename( filename: string, inputDir?: string ) { - if (!inputDir || !path.isAbsolute(filename)) { - return normalizeNodeModules(filename) + let relativeFilename = filename + if (inputDir && path.isAbsolute(filename)) { + relativeFilename = path.relative(inputDir, filename) } - return normalizeNodeModules(path.relative(inputDir, filename)) + if (/^\.\.(\/|\\)/.test(relativeFilename)) { + const level = `_${relativeFilename.match(/\.\.(\/|\\)/g)!.length}` + relativeFilename = relativeFilename.replace(/\.\.(\/|\\)/g, '') + relativeFilename = path.join('_symlinks', level, relativeFilename) + } + return normalizeNodeModules(relativeFilename) } export function normalizeParsePlugins(