Skip to content

Commit

Permalink
wip(uts): 加密插件
Browse files Browse the repository at this point in the history
  • Loading branch information
fxy060608 committed Jan 20, 2025
1 parent 6756963 commit 9599fba
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 3 deletions.
5 changes: 4 additions & 1 deletion packages/uni-cli-shared/src/uni_modules.cloud.ts
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,10 @@ export function resolveEncryptUniModule(
if (index !== -1) {
const uniModuleId = parts[index + 1]
if (uniModuleId in encryptUniModules) {
if (parts[index + 2]) {
if (
parts[index + 2] &&
(platform === 'app-android' || platform === 'app-ios')
) {
console.warn(
M['uni_modules.import']
.replace('{0}', uniModuleId)
Expand Down
29 changes: 27 additions & 2 deletions packages/uni-cli-shared/src/uts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,17 +113,42 @@ export function resolveUTSModule(
let index = resolveUTSFile(
resolvePlatformDir(process.env.UNI_UTS_PLATFORM)
)
const pluginId =
parentDir === 'uni_modules' ? parts[parts.length - 1] : ''
if (index) {
return index
return resolveUTSEncryptFile(pluginId, index) || index
}
index = path.resolve(id, basedir, 'index.uts')
if (fs.existsSync(index)) {
return index
return resolveUTSEncryptFile(pluginId, index) || index
}
}
}
}

function resolveUTSEncryptFile(pluginId: string, index: string) {
if (!pluginId) {
return
}
const cacheDir = process.env.UNI_MODULES_ENCRYPT_CACHE_DIR
if (!cacheDir) {
return
}
// 仅支持 uts 加密解析
if (!index.endsWith('.uts')) {
return
}
const cacheFile = path.resolve(
cacheDir,
'uni_modules',
pluginId,
'index.module.js'
)
if (fs.existsSync(cacheFile)) {
return cacheFile
}
}

function resolveUTSFile(
dir: string,
extensions: string[] = ['.uts', '.ts', '.js']
Expand Down

0 comments on commit 9599fba

Please sign in to comment.