Skip to content

Commit

Permalink
wip: uni_modules 编译
Browse files Browse the repository at this point in the history
  • Loading branch information
fxy060608 committed Apr 30, 2024
1 parent 1a8f631 commit 776f595
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 2 deletions.
1 change: 1 addition & 0 deletions packages/shims-node.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ declare namespace NodeJS {
UNI_APP_X_UVUE_SCRIPT_ENGINE?: 'native' | 'js'

UNI_COMPILE_TARGET?: 'uni_modules'
UNI_COMPILE_CLOUD_DIR?: string
}
}

Expand Down
10 changes: 9 additions & 1 deletion packages/uni-cli-shared/src/easycom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,12 @@ function initAutoScanEasycom(
if (!fs.existsSync(dir)) {
return easycoms
}
const is_uni_modules =
path.basename(path.resolve(dir, '../..')) === 'uni_modules'
const is_encrypt_uni_modules =
is_uni_modules && fs.existsSync(path.resolve(dir, '../encrypt'))
const uni_modules_plugin_id =
is_encrypt_uni_modules && path.basename(path.resolve(dir, '..'))
fs.readdirSync(dir).forEach((name) => {
const folder = path.resolve(dir, name)
if (!isDir(folder)) {
Expand All @@ -233,7 +239,9 @@ function initAutoScanEasycom(
for (let i = 0; i < extensions.length; i++) {
const ext = extensions[i]
if (files.includes(name + ext)) {
easycoms[`^${name}$`] = `${importDir}/${name}${ext}`
easycoms[`^${name}$`] = is_encrypt_uni_modules
? `@/uni_modules/${uni_modules_plugin_id}?uni_helpers`
: `${importDir}/${name}${ext}`
break
}
}
Expand Down
9 changes: 9 additions & 0 deletions packages/uni-cli-shared/src/hbx/log.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,11 +139,20 @@ function buildErrorMessage(
includeStack = true
): string {
if (err.plugin) {
const otherMsgs: string[] = []
if (err.message.includes(': [plugin ')) {
const messages = err.message.split(': [plugin ')
err.message = messages[0]
messages.slice(1).forEach((msg) => {
otherMsgs.push(`[plugin:${msg}`)
})
}
args.push(
`${colors.magenta('[plugin:' + err.plugin + ']')} ${colors.red(
err.message
)}`
)
args.push(...otherMsgs)
if (
err.loc &&
err.hook === 'transform' &&
Expand Down
11 changes: 11 additions & 0 deletions packages/vite-plugin-uni/src/cli/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,17 @@ export function initEnv(
path.resolve(process.env.UNI_OUTPUT_DIR, options.subpackage)
}
}
const baseOutDir = path.basename(process.env.UNI_OUTPUT_DIR)

process.env.UNI_APP_X_CACHE_DIR =
process.env.UNI_APP_X_CACHE_DIR ||
path.resolve(process.env.UNI_OUTPUT_DIR, '../cache/' + baseOutDir)

process.env.UNI_COMPILE_CLOUD_DIR = path.resolve(
process.env.UNI_APP_X_CACHE_DIR,
'.cloud',
process.env.NODE_ENV === 'production' ? 'build' : 'dev'
)

initAutomator(options)

Expand Down
10 changes: 9 additions & 1 deletion packages/vite-plugin-uni/src/configResolved/plugins/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,15 @@ export function initPlugins(
process.env.UNI_HBUILDERX_PLUGINS,
'uni_helpers'
))
addPlugin(plugins, V({ dir: process.env.UNI_INPUT_DIR }), 0, 'pre')
addPlugin(
plugins,
V({
dir: process.env.UNI_INPUT_DIR,
cloudDir: process.env.UNI_COMPILE_CLOUD_DIR,
}),
0,
'pre'
)
} catch (e) {}
}

Expand Down

0 comments on commit 776f595

Please sign in to comment.