Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(utils): delete the renderless/common directory and adjust all reference paths. #2849

Merged
merged 28 commits into from
Feb 7, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
00dd4c5
fix(utils): 调整sha256, 移除 getWindow, isWeb
shenjunjian Jan 26, 2025
39901e7
fix(utils): 移除isSerer到globalConfig, 删除isBrowser函数
shenjunjian Jan 26, 2025
6e7aacd
fix(utils): 移除 prop-util 包
shenjunjian Jan 26, 2025
dba8c92
fix(utils): 更新date, calendar,date-utils, type四个引用
shenjunjian Jan 27, 2025
538736f
fix(utils): 更新string包路径
shenjunjian Feb 5, 2025
ed9307f
fix(utils): 更新 object路径
shenjunjian Feb 5, 2025
10f847f
fix(utils): 添加'@opentiny/utils' 依赖
shenjunjian Feb 5, 2025
97c1f84
fix(utils): 添加'@opentiny/utils' 依赖
shenjunjian Feb 5, 2025
cb2d4b7
fix(utils): 更新 dataset 路径
shenjunjian Feb 5, 2025
3119781
fix(utils): 更新 array 路径
shenjunjian Feb 5, 2025
ea19a56
fix(utils): 更新 array 路径
shenjunjian Feb 5, 2025
63ec0f0
fix(utils): 更新 dataset 路径
shenjunjian Feb 5, 2025
19c771b
fix(utils): 删除所有的renderless/common中的文件
shenjunjian Feb 5, 2025
338eef3
fix(utils): 替换路径
shenjunjian Feb 5, 2025
1ca41ba
fix(utils): 替换路径
shenjunjian Feb 6, 2025
5586ff3
fix(utils): 替换路径
shenjunjian Feb 6, 2025
7302c1c
fix(utils): 替换路径
shenjunjian Feb 6, 2025
ba298b5
fix(utils): 替换路径
shenjunjian Feb 6, 2025
d249b84
fix(utils): 替换路径
shenjunjian Feb 6, 2025
54e95a7
fix(utils): 替换路径
shenjunjian Feb 6, 2025
035da89
Merge branch 'dev' of github.com:opentiny/tiny-vue into refactor-util…
shenjunjian Feb 6, 2025
0b0c263
fix(utils): fix
shenjunjian Feb 7, 2025
c6d2cc6
fix(utils): remove time-line-new
shenjunjian Feb 7, 2025
aaacca6
fix(utils): adjust import orders
shenjunjian Feb 7, 2025
7064e5b
Merge branch 'dev' of github.com:opentiny/tiny-vue into refactor-util…
shenjunjian Feb 7, 2025
1baade3
fix(utils): 替换路径
shenjunjian Feb 7, 2025
6f68ab9
Merge branch 'dev' of github.com:opentiny/tiny-vue into refactor-util…
shenjunjian Feb 7, 2025
44b3da9
fix(utils): add popup-manager file
shenjunjian Feb 7, 2025
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
3 changes: 1 addition & 2 deletions examples/nuxt/playground/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,11 @@
"@opentiny/vue-vite-import": "workspace:~",
"@tiptap/vue-3": "^2.1.0",
"@vitejs/plugin-vue-jsx": "^3.0.0",
"js-sha256": "^0.9.0",
"onigasm": "^2.2.5",
"postcss": "^8.4.16",
"typescript": "^5.0.0",
"vite-plugin-checker": "^0.5.2",
"vite-plugin-dynamic-import": "^1.2.4",
"vite-svg-loader": "^3.6.0"
}
}
}
3 changes: 1 addition & 2 deletions examples/vue2/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
"@vue/composition-api": "1.7.2",
"@vue/runtime-dom": "^3.2.31",
"@vue/test-utils": "^1.3.3",
"js-sha256": "^0.9.0",
"jsdom": "^21.0.0",
"onigasm": "^2.2.5",
"postcss": "^8.4.16",
Expand All @@ -60,4 +59,4 @@
"vue-template-compiler": "2.6.14",
"vue-tsc": "^1.0.16"
}
}
}
3 changes: 1 addition & 2 deletions examples/vue3/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@
"@vitest/ui": "^0.31.0",
"@vue/runtime-core": "3.2.31",
"@vue/test-utils": "^2.2.7",
"js-sha256": "^0.9.0",
"jsdom": "^21.0.0",
"onigasm": "^2.2.5",
"postcss": "^8.4.16",
Expand All @@ -59,4 +58,4 @@
"vue": "^3.3.9",
"vue-i18n": "^9.1.7"
}
}
}
6 changes: 3 additions & 3 deletions packages/renderless/src/file-upload/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import type {
} from '@/types'

import { extend } from '../common/object'
import { xss, logger, crypt } from '@opentiny/utils'
import { xss, logger, sha256 } from '@opentiny/utils'
import uploadAjax from '../common/deps/upload-ajax'
import { isObject } from '../common/type'
import { isEmptyObject } from '../common/type'
Expand Down Expand Up @@ -513,7 +513,7 @@ export const getFileHash =
reader.readAsArrayBuffer(file.raw)
reader.onload = async (e) => {
if (file.status === constants.FILE_STATUS.FAIL) return
const hash = await crypt.sha256(e.target && e.target.result)
const hash = sha256(e.target && e.target.result)
file.hash = file.raw.hash = hash
resolve(hash)
emit('hash-progress', 100)
Expand Down Expand Up @@ -2046,7 +2046,7 @@ export const segmentUpload =
reader.readAsArrayBuffer(file)
reader.onload = async (e) => {
if (props.edm.isCheckCode === true) {
const hash = await crypt.sha256(e.target && e.target.result)
const hash = sha256(e.target && e.target.result)
file.hash = hash
}
resolve(file)
Expand Down
8 changes: 2 additions & 6 deletions packages/utils/src/crypt/index.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
import { getWindow } from '../globalConfig'

/** 生成字节流或字符串的sha256编码 */
export async function sha256(message: ArrayBuffer | string) {
export function sha256(message: ArrayBuffer | string) {
const isArrayBuffer = Object.prototype.toString.call(message) === '[object ArrayBuffer]'
const msgUint8 = isArrayBuffer ? message : new TextEncoder().encode(message as string) // 编码为(utf-8)Uint8Array
const hashBuffer = await getWindow().crypto.subtle.digest('SHA-256', msgUint8) // 计算消息的哈希值
const hashBuffer = globalThis.crypto.subtle.digest('SHA-256', msgUint8) // 计算消息的哈希值
const hashArray = Array.from(new Uint8Array(hashBuffer)) // 将缓冲区转换为字节数组

Choose a reason for hiding this comment

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

The removal of await from the sha256 function suggests that crypto.subtle.digest is now expected to be synchronous, which is incorrect. crypto.subtle.digest returns a Promise, so the function should remain asynchronous, and await should be used here.

const hashHex = hashArray.map((b) => b.toString(16).padStart(2, '0')).join('') // 将字节数组转换为十六进制字符串

return hashHex
}

export default { sha256 }
8 changes: 0 additions & 8 deletions packages/utils/src/globalConfig/index.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,3 @@
export const isWeb = () =>
typeof window !== 'undefined' && typeof document !== 'undefined' && window.document === document

/** 获取globalThis. 在web上, window===globalThis 在node.js中, global=== globalThis。
* 所以该函数没必要存在,待移除
*/
export const getWindow = () => (isWeb() ? window : global)

// 需要微前端的用户传入该变量
export const globalConfig = {
viewportWindow: null // 获取真实视口的window,解决在微前端中某些bug
Expand Down
8 changes: 5 additions & 3 deletions packages/utils/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import xss from './xss'
import logger from './logger'
import crypt from './crypt'
import ResizeObserver from './resize-observer'

export { xss, logger, crypt, ResizeObserver }
export { xss, logger, ResizeObserver }

export { sha256 } from './crypt'
export { globalConfig, getViewportWindow } from './globalConfig'
Copy link

Choose a reason for hiding this comment

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

💡 Codebase verification

Breaking change detected in mobile utils

The export reorganization is properly implemented, but there's one breaking change that needs to be addressed:

  • Update packages/mobile/utils/xss.ts to use getViewportWindow() instead of getWindow() in the line: let log = { logger: getWindow().console }
🔗 Analysis chain

Export reorganization looks good but needs documentation.

The reorganization of exports and separation of sha256 from the crypt module improves modularity. However, since this is a breaking change, it should be documented.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for potential breaking changes impact

# Search for direct imports of the removed crypt module
echo "Checking for imports of the removed crypt module..."
rg "import.*from ['\"]@opentiny/vue-utils/crypt['\"]" || echo "No direct crypt imports found"

# Search for destructured imports of getWindow and isWeb
echo -e "\nChecking for imports of removed getWindow and isWeb utilities..."
rg "import.*\{.*(getWindow|isWeb).*\}.*from ['\"]@opentiny/vue-utils['\"]" || echo "No getWindow/isWeb imports found"

Length of output: 542


Script:

#!/bin/bash
# Check for TypeScript references and indirect usages

# Check for type references
echo "Checking for TypeScript type references..."
rg "import type.*\{.*(getWindow|isWeb).*\}.*from ['\"]@opentiny/vue-utils['\"]" || echo "No type references found"

# Check implementation of new exports
echo -e "\nVerifying new exports implementation..."
ast-grep --pattern 'export { sha256 } from "./crypt"'
ast-grep --pattern 'export { globalConfig, getViewportWindow } from "./globalConfig"'

# Check for any references to these functions in the codebase
echo -e "\nChecking for any function references..."
rg "getWindow\s*\(" || echo "No getWindow function calls found"
rg "isWeb\s*\(" || echo "No isWeb function calls found"

Length of output: 753


Script:

#!/bin/bash
# Verify the actual implementation files

echo "Checking crypt.ts content..."
fd -e ts crypt.ts --exec cat {}

echo -e "\nChecking globalConfig.ts content..."
fd -e ts globalConfig.ts --exec cat {}

echo -e "\nChecking if getViewportWindow is the replacement for getWindow..."
rg "getViewportWindow" -A 3

Length of output: 3041


export { getWindow, isWeb, globalConfig, getViewportWindow } from './globalConfig'
export { getDays, getWeek, lastMonth, nextMonth, getCalendar, transformArray, parseDate } from './calendar'

export {
isLeapYear,
toDate,
Expand Down
4 changes: 1 addition & 3 deletions packages/utils/src/logger/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import { getWindow } from '../globalConfig'

const _win: any = getWindow()
const _win: any = globalThis
/** 使用 logger.xxx 代替 window.console.xxx, 避免语法警告 */
export const logger = _win.console as Console

Expand Down
Loading