Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,17 @@ import type * as BabelCore from '@babel/core'
import type { PluginOption } from 'vite'
import type Harmony from '..'

export default function (platform: Harmony): PluginOption {
export default function (this: Harmony): PluginOption {
const that = this
const packageName = '@tarojs/taro'
const bindingName = 'Taro'
const businessId = platform.getConfig().defineConstants?.LOCATION_APIKEY?.replace(/^['"]|['"]$/g, '')
const businessId = that.getConfig().defineConstants?.LOCATION_APIKEY?.replace(/^['"]|['"]$/g, '')

return {
name: 'taro:vite-add-method-env',
transform (code, id) {
const pluginContext = this
const { runnerUtils } = platform.context
const { runnerUtils } = that.context
const { getViteHarmonyCompilerContext } = runnerUtils
const compiler = getViteHarmonyCompilerContext(pluginContext)
const exts = Array.from(new Set(compiler?.frameworkExts.concat(SCRIPT_EXT)))
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

潜在崩溃:compiler?.frameworkExts 可能为 undefined,直接 concat 会抛异常

compilerundefined 或未提供 frameworkExts 时,undefined.concat(...) 会直接中断构建。建议使用空数组回退。

-      const exts = Array.from(new Set(compiler?.frameworkExts.concat(SCRIPT_EXT)))
+      const exts = Array.from(new Set([...(compiler?.frameworkExts ?? []), ...SCRIPT_EXT]))
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const exts = Array.from(new Set(compiler?.frameworkExts.concat(SCRIPT_EXT)))
const exts = Array.from(new Set([...(compiler?.frameworkExts ?? []), ...SCRIPT_EXT]))
🤖 Prompt for AI Agents
In packages/taro-platform-harmony-cpp/src/program/vite/inject-env.ts around line
21, using compiler?.frameworkExts.concat(SCRIPT_EXT) can throw if compiler or
frameworkExts is undefined; change to concatenate against a safe default (e.g.
use (compiler?.frameworkExts ?? []) or an empty array fallback) so concat always
operates on an array and avoid build crash.

Expand Down
Loading