Skip to content

Commit

Permalink
merge: 合并鸿蒙分支 (#16740)
Browse files Browse the repository at this point in the history
* fix: 支持关闭 jsx 样式注入,并提供 css map

* chore(release): publish 4.0.0-alpha.24 --tag=alpha

* fix(vite): 修复组件模式配置缺失问题

* chore(release): publish 4.0.0-alpha.25 --tag=alpha

* feat: update from ets runtime

* chore(release): publish 4.0.0-alpha.26 --tag=alpha

* feat(harmony): add terser plugin

* chore(release): publish 4.0.0-alpha.27 --tag=alpha

* fix: 移除废弃插件

* feat(ets): 调整运行时导出

* feat: 更新 capi 版本 runtime

* feat(harmony): add cpp style

* fix: 修复导出路径

* chore(release): publish 4.0.0-alpha.36 --tag=alpha

* fix(harmony): update runtime

* fix: 修复cssmodules匹配不到的问题

* feat: comp.js 支持路由重命名

* feat: 去掉console

* fix: uid types

* fix(harmony): 修复常量替换问题

* fix(harmony): 调整 api 依赖引用

* chore(release): publish 4.0.0-alpha.44 --tag=alpha

* fix(harmony): 移除 onpm 不能装载的类型

* fix: 修复 input 事件错误逻辑

* fix: 修复 form 元素移除属性错误

* fix(react): env shake

* fix: 修复stickySection没有渲染list-item的问题

* chore(release): publish 4.0.0-beta.119 --tag=beta

* fix: 修复list-view问题

* chore(release): publish 4.0.0-beta.120 --tag=beta

* fix: 修复sticky-section没有被复用

* chore(release): publish 4.0.0-beta.121 --tag=beta

* fix: 修复错误引入taro的问题

* chore(release): publish 4.0.0-beta.122 --tag=beta

* chore(release): publish 4.0.0-beta.122 --tag=beta

* fix: 修复cssmodule样式不生效

* chore(release): publish 4.0.0-beta.123 --tag=beta

* fix: 临时修复 harmony 不能编译 ts 的问题

* chore(release): publish 4.0.0-beta.124 --tag=beta

* fix: 兼容找不到页面情况

* fix(harmony): 优化 contextPromise 设置

* fix(harmony): 修复读取配置时缺少常量注入

* chore(release): publish 4.0.0-beta.125 --tag=beta

* fix: code

* feat(harmony): 修复图片等资源注入引用问题

* chore(release): publish 4.0.0-beta.126 --tag=beta

* fix: 修复 readConfig 时引入 babel 导致的问题

* fix: 更新 lint 问题

* chore(release): publish 4.0.0-beta.127 --tag=beta

* fix: 修复 readConfig 时引入 babel 导致问题

* chore(release): publish 4.0.0-beta.128 --tag=beta

* fix: 修复scroll无法禁止滚动的bug

* chore(release): publish 4.0.0-beta.129 --tag=beta

* feat: 在style的opacity设置成空字符串里把他设置成1,避免harmony beta2把opacity的默认值设置成0的情况

* chore(release): publish 4.0.0-beta.130 --tag=beta

* fix: 修复鸿蒙端的pagaName获取不到的问题和ets的类型问题

* fix: 修改readConfig方法

* chore(release): publish 4.0.0-beta.131 --tag=beta

* fix: 修复beta2文本不更新的问题

* chore(release): publish 4.0.0-beta.132 --tag=beta

* fix: 修复 overflow 是 scroll 和 auto 情况下 scrollview 不能滚动的问题

* chore(release): publish 4.0.0-beta.133 --tag=beta

* fix(types): update picker region data

* fix(runner): 整理 page entry 参数

* fix(runner): word spelling

* feat(runner): add modifyEntryFile func

* chore(release): publish 4.0.0-beta.134 --tag=beta

* fix: update runner hooks

* chore(release): publish 4.0.0-beta.135 --tag=beta

* fix(harmony): 对齐 page 各生命周期中使用的对象实例

* chore(release): publish 4.0.0-beta.136 --tag=beta

* fix(harmony): 对齐 custom 路由判断

* chore(release): publish 4.0.0-beta.137 --tag=beta

* fix(runner): for wins path

* chore(release): publish 4.0.0-beta.138 --tag=beta

* chore: 升级 pnpm 版本

* feat(vite): 修复 wins 路径问题

* chore(release): publish 4.0.0-beta.139 --tag=beta

* test: update snapshoot

---------

Co-authored-by: ZakaryCode <[email protected]>
Co-authored-by: mayintao3 <[email protected]>
Co-authored-by: zhuminghui2 <[email protected]>
Co-authored-by: xuanzebin <[email protected]>
Co-authored-by: liuzejia <[email protected]>
  • Loading branch information
6 people authored Oct 25, 2024
1 parent a262dcb commit 4713319
Show file tree
Hide file tree
Showing 28 changed files with 16,927 additions and 12,350 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build-rust-binding.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ jobs:
- name: Setup pnpm
uses: pnpm/[email protected]
with:
version: 8
version: 9
- name: Setup Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v4
if: ${{ !matrix.settings.docker }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/nodejs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ jobs:
- name: Setup pnpm
uses: pnpm/[email protected]
with:
version: 8
version: 9
- name: Setup Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v4
with:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ jobs:
- name: Setup pnpm
uses: pnpm/[email protected]
with:
version: 8
version: 9
- name: Setup Node 18
uses: actions/setup-node@v4
with:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/sync-components-types.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ jobs:
- name: install
uses: pnpm/[email protected]
with:
version: 8
version: 9
run_install: |
- recursive: true
args: [--frozen-lockfile, --strict-peer-dependencies]
Expand Down
2 changes: 1 addition & 1 deletion packages/taro-helper/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -631,8 +631,8 @@ export function readPageConfig(configPath: string) {
}

interface IReadConfigOptions {
defineConstants?: Record<string, any>
alias?: Record<string, any>
defineConstants?: Record<string, any>
}

export function readConfig<T extends IReadConfigOptions> (configPath: string, options: T = {} as T) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ function getAttributes (node: TaroScrollViewElement): ScrollViewAttrs {

function getScrollable (node: TaroScrollViewElement) {
const _attrs = node._attrs
if (node?.hmStyle?.overflow === "scroll" || node?.hmStyle?.overflow === "auto") {
return ScrollDirection.Vertical
}
if (_attrs.scrollX) {
return ScrollDirection.Horizontal
} else if (_attrs.scrollY) {
Expand All @@ -47,11 +50,11 @@ function getScrollable (node: TaroScrollViewElement) {

function handleScrollEvent (node: TaroScrollViewElement, eventName = 'scroll', xOffset?: number, yOffset?: number) {
if (!node || !node.scroller) return

const currentOffset = node.scroller.currentOffset() as ScrollViewCurrentOffset

if (!currentOffset) return

const currentXOffset = currentOffset.xOffset
const currentYOffset = currentOffset.yOffset
const value: ScrollViewEvent = {
Expand Down
5 changes: 5 additions & 0 deletions packages/taro-platform-harmony/src/runtime-ets/dom/node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,11 @@ export class TaroNode extends TaroDataSourceElement {
this.childNodes.push(child)
this.notifyDataAdd(this.childNodes.length - 1)

if (this.nodeName === 'TEXT') {
// 修复beta2版本文字从undefined -> 有值时的 不更新问题
this.updateComponent()
}

// @ts-ignore
child.toggleLayer?.(true)

Expand Down
5 changes: 4 additions & 1 deletion packages/taro-vite-runner/src/harmony/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import type { RollupInjectOptions } from '@rollup/plugin-inject'
import type { ViteHarmonyCompilerContext } from '@tarojs/taro/types/compile/viteCompilerContext'
import type { InputPluginOption, OutputOptions } from 'rollup'
import type { Plugin, PluginOption } from 'vite'
import type { TaroHarmonyPageMeta } from './template/page'

export default function (viteCompilerContext: ViteHarmonyCompilerContext): PluginOption {
const { taroConfig, cwd: appPath } = viteCompilerContext
Expand Down Expand Up @@ -200,7 +201,9 @@ export default function (viteCompilerContext: ViteHarmonyCompilerContext): Plugi
name = name.replace(/[\\/]+/g, '/')

const appId = viteCompilerContext.app.config.appId || 'app'
const isTaroComp = appId === name || viteCompilerContext.pages.some(page => page.name === name) || viteCompilerContext.components?.some(comp => comp.name === name)
const isTaroComp = appId === name ||
viteCompilerContext.pages.some((page: TaroHarmonyPageMeta) => [page.name, page.originName].includes(name)) ||
viteCompilerContext.components?.some((comp: TaroHarmonyPageMeta) => [comp.name, comp.originName].includes(name))
// 如果同时存在app.ets和app.js,因为鸿蒙IDE编译会把app.ets编译成app.ts,会跟app.js冲突,识别都是/app,导致app.js被app.ts覆盖了,所以需要名字
const suffix = isTaroComp ? virtualModulePrefixREG.test(chunkInfo.facadeModuleId || '') ? TARO_COMP_SUFFIX : '_comp' : ''
name = stripMultiPlatformExt(`${name}${suffix}`) + taroConfig.fileType.script
Expand Down
14 changes: 9 additions & 5 deletions packages/taro-vite-runner/src/harmony/emit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { componentConfig } from '../utils/component'

import type { ViteHarmonyCompilerContext } from '@tarojs/taro/types/compile/viteCompilerContext'
import type { PluginOption } from 'vite'
import type { TaroHarmonyPageMeta } from './template/page'

export default function (viteCompilerContext: ViteHarmonyCompilerContext): PluginOption {
const { taroConfig } = viteCompilerContext
Expand Down Expand Up @@ -104,18 +105,21 @@ export default function (viteCompilerContext: ViteHarmonyCompilerContext): Plugi
const comps = viteCompilerContext.getComponents() || []

const lines: string[] = []
comps.forEach(comp => {
const key = Object.keys(taroConfig.router?.customRoutes || {}).find(e => [comp.name, addLeadingSlash(comp.name)].includes(e))
comps.forEach((comp: TaroHarmonyPageMeta) => {
const key = Object.keys(taroConfig.router?.customRoutes || {}).find(e => {
const name = comp.originName || comp.name
return [name, addLeadingSlash(name)].includes(e)
})

if (key) {
const alias = taroConfig.router?.customRoutes![key]
if (alias instanceof Array) {
alias.forEach(item => lines.push(`export * from './${path.join('src/main', 'ets', item)}'`))
alias.forEach(item => lines.push(`export * from './${path.posix.join('src/main', 'ets', item)}'`))
} else if (typeof alias === 'string') {
lines.push(`export * from './${path.join('src/main', 'ets', alias)}'`)
lines.push(`export * from './${path.posix.join('src/main', 'ets', alias)}'`)
}
} else {
lines.push(`export * from './${path.join('src/main', 'ets', comp.name)}'`)
lines.push(`export * from './${path.posix.join('src/main', 'ets', comp.name)}'`)
}
})
lines.push('')
Expand Down
12 changes: 6 additions & 6 deletions packages/taro-vite-runner/src/harmony/page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,15 +94,15 @@ export default function (viteCompilerContext: ViteHarmonyCompilerContext): Plugi
pageName = 'index'
}

const page_ = page as TaroHarmonyPageMeta
page_.id = id
page_.originName = page.name
page_.name = pageName

this.emitFile({
type: 'prebuilt-chunk',
fileName: viteCompilerContext.getTargetFilePath(pageName, '.ets'),
code: parse.parse(path.resolve(appRoot, pageName), {
...page,
originName: page.name,
name: pageName,
id,
} as TaroHarmonyPageMeta, name, this.resolve),
code: parse.parse(path.resolve(appRoot, pageName), page_, name, this.resolve),
exports: ['default'],
})
})
Expand Down
13 changes: 8 additions & 5 deletions packages/taro-vite-runner/src/harmony/template/app.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import path from 'node:path'

import { isFunction } from '@tarojs/shared'

import { escapePath, resolveAbsoluteRequire } from '../../utils'
import { TARO_COMP_SUFFIX } from '../entry'
import { TARO_TABBAR_PAGE_PATH } from '../page'
Expand Down Expand Up @@ -116,8 +118,8 @@ export default class Parser extends BaseParser {
}
`

if (typeof modifyInstantiate === 'function') {
instantiateApp = modifyInstantiate(instantiateApp, 'app')
if (isFunction(modifyInstantiate)) {
instantiateApp = modifyInstantiate.call(this, instantiateApp, 'app')
}

return instantiateApp
Expand Down Expand Up @@ -156,10 +158,9 @@ export default class Parser extends BaseParser {
}

parseEntry (rawId: string, config = {}) {
const { creator, creatorLocation, frameworkArgs, importFrameworkStatement } = this.loaderMeta
const { creator, creatorLocation, frameworkArgs, importFrameworkStatement, modifyEntryFile } = this.loaderMeta
const createApp = `${creator}(component, ${frameworkArgs})`

return this.transArr2Str([
const rawCode = this.transArr2Str([
'import { initPxTransform } from "@tarojs/taro"',
`import { ${creator} } from "${creatorLocation}"`,
`import component from "${escapePath(rawId)}"`,
Expand All @@ -168,5 +169,7 @@ export default class Parser extends BaseParser {
this.getInitPxTransform(),
`export default () => ${createApp}`,
])

return isFunction(modifyEntryFile) ? modifyEntryFile.call(this, 'app', rawId, rawCode, config) : rawCode
}
}
40 changes: 21 additions & 19 deletions packages/taro-vite-runner/src/harmony/template/page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export interface TaroHarmonyPageMeta extends VitePageMeta {

modifyPageAppear?: (this: Parser, appearStr: string, page: TaroHarmonyPageMeta | TaroHarmonyPageMeta[]) => string

modifyPageDisAppear?: (this: Parser, appearStr: string, page: TaroHarmonyPageMeta | TaroHarmonyPageMeta[]) => string
modifyPageDisappear?: (this: Parser, appearStr: string, page: TaroHarmonyPageMeta | TaroHarmonyPageMeta[]) => string

modifyPageBuild?: (this: Parser, buildStr: string, page: TaroHarmonyPageMeta | TaroHarmonyPageMeta[]) => string

Expand Down Expand Up @@ -705,7 +705,7 @@ for (let i = 0; i < taskQueen.length; i++) {

let instantiatePage = this.transArr2Str(structCodeArray)
if (isFunction(modifyInstantiate)) {
instantiatePage = modifyInstantiate(instantiatePage, 'page')
instantiatePage = modifyInstantiate.call(this, instantiatePage, 'page', page)
}

return instantiatePage
Expand Down Expand Up @@ -944,20 +944,20 @@ ${this.transArr2Str(pageStr.split('\n'), 6)}
}

generatePageAboutToDisAppear (page: TaroHarmonyPageMeta | TaroHarmonyPageMeta[]) {
const modifyPageDisAppear = page instanceof Array ? page[0].modifyPageDisAppear : page.modifyPageDisAppear
const modifyPageDisappear = page instanceof Array ? page[0].modifyPageDisappear : page.modifyPageDisappear

// 生成 aboutToDisAppear 函数内容
let disAppearStr = this.transArr2Str([
// 生成 aboutToDisappear 函数内容
let disappearStr = this.transArr2Str([
this.isTabbarPage ? `this.pageList?.forEach(item => {
callFn(item?.onUnload, this)
})
this.removeTabBarEvent()` : 'callFn(this.page?.onUnload, this)'])

if (isFunction(modifyPageDisAppear)) {
disAppearStr = modifyPageDisAppear.call(this, disAppearStr, page)
if (isFunction(modifyPageDisappear)) {
disappearStr = modifyPageDisappear.call(this, disappearStr, page)
}

return disAppearStr
return disappearStr
}

generatePageShown () {
Expand Down Expand Up @@ -1078,21 +1078,21 @@ this.removeTabBarEvent()` : 'callFn(this.page?.onUnload, this)'])
}

parseEntry (rawId: string, page: TaroHarmonyPageMeta) {
const { creatorLocation, importFrameworkStatement } = this.loaderMeta
const { creatorLocation, frameworkArgs, importFrameworkStatement, modifyEntryFile } = this.loaderMeta
const entryOption = page instanceof Array ? page[0].entryOption : page.entryOption
const isBlended = this.buildConfig.blended || this.buildConfig.isBuildNativeComp
let createFn = isBlended ? 'createNativePageConfig' : 'createPageConfig'
// FIXME: pure 参数应该使用 page.entryOption 替代
const createFn = this.isPure
? 'createNativeComponentConfig'
: isBlended
? 'createNativePageConfig' : 'createPageConfig'
const pageName = entryOption?.routeName || page.name
const nativeCreatePage = `createNativePageConfig(component, '${pageName}', React, ReactDOM, config)`
let createPageOrComponent = isBlended ? nativeCreatePage : `createPageConfig(component, '${pageName}', config)`
const createPageOrComponent = `${createFn}(component, ${this.isPure
? `${frameworkArgs}`
: isBlended
? `'${pageName}', ${frameworkArgs}` : `'${pageName}', config`})`

// 如果是pure,说明不是一个页面,而是一个组件,这个时候修改import和createPage
if (this.isPure) {
createFn = 'createNativeComponentConfig'
createPageOrComponent = `createNativeComponentConfig(component, React, ReactDOM, config)`
}

return this.transArr2Str([
const rawCode = this.transArr2Str([
`import { ${createFn} } from '${creatorLocation}'`,
`import component from "${escapePath(rawId)}"`,
isBlended ? 'import { initPxTransform } from "@tarojs/taro"' : null,
Expand All @@ -1103,5 +1103,7 @@ this.removeTabBarEvent()` : 'callFn(this.page?.onUnload, this)'])
page?.config.enableShareAppMessage ? 'component.enableShareAppMessage = true' : null,
`export default () => ${createPageOrComponent}`,
])

return isFunction(modifyEntryFile) ? modifyEntryFile.call(this, 'page', rawId, rawCode, page) : rawCode
}
}
3 changes: 2 additions & 1 deletion packages/taro-vite-runner/src/harmony/template/render.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,8 @@ export default class RenderParser extends BaseParser {
if (meta.isPackage) {
importList.push(`import ${meta.name} from '${meta.scriptPath}'`)
} else {
const nativePath = path.relative(this.context.sourceDir, meta.scriptPath).replace(/\.ets$/, '')
const nativePath = path.posix.relative(this.context.sourceDir, meta.scriptPath)
.replace(/[\\/]+/g, '/').replace(/\.ets$/, '')
importList.push(`import ${meta.name} from './${nativePath}'`)
}
})
Expand Down
Loading

0 comments on commit 4713319

Please sign in to comment.