diff --git a/packages/taro-components-rn/dep.js b/packages/taro-components-rn/dep.js new file mode 100644 index 000000000000..6bba4b471951 --- /dev/null +++ b/packages/taro-components-rn/dep.js @@ -0,0 +1,49 @@ +/* eslint-disable @typescript-eslint/no-var-requires */ +const { parseDependencyTree } = require('dpdm') +const { peerDependencies } = require('./package.json') + +const hiddenDependenciesMap = { + '@ant-design/react-native/lib/picker': ['@react-native-picker/picker'] +} + +const componentReg = /^src\/components\/(\w+)\/index.tsx$/ + +function parseDependencyCircular(dep = [], tree = {}) { + dep.forEach(d => { + const item = tree[d.id] + if (item) { + dep = dep.concat(parseDependencyCircular(item, tree)) + } + }) + return dep +} + +parseDependencyTree('./src/index.ts', {}).then((tree) => { + const result = {} + Object.keys(tree).map(key => { + const match = key.match(componentReg) + if (match) { + const name = match[1] + parseDependencyCircular(tree[key], tree).map(dependency => { + const dep = dependency.id + if (dep) { + [...Object.keys(peerDependencies), ...Object.keys(hiddenDependenciesMap)].forEach(value => { + if (dep.match(`node_modules/${value}`)) { + result[name] = result[name] || new Set() + if (hiddenDependenciesMap[value]) { + hiddenDependenciesMap[value].forEach(value => { + const showName = peerDependencies[value] ? `${value}@${peerDependencies[value]}` : value + result[name].add(showName) + }) + } else { + const showName = peerDependencies[value] ? `${value}@${peerDependencies[value]}` : value + result[name].add(showName) + } + } + }) + } + }) + } + }) + console.log(result) +}) diff --git a/packages/taro-components-rn/package.json b/packages/taro-components-rn/package.json index 81f69f886a77..5199ccac6bb5 100644 --- a/packages/taro-components-rn/package.json +++ b/packages/taro-components-rn/package.json @@ -41,11 +41,12 @@ "devDependencies": { "@babel/core": "^7.14.5", "@babel/preset-env": "^7.14.5", - "@react-native/babel-preset": "^0.73.18", "@react-native-camera-roll/camera-roll": "~7.2.0", "@react-native-community/segmented-control": "^2.2.2", + "@react-native/babel-preset": "^0.73.18", "@testing-library/jest-native": "^5.4.2", "@testing-library/react-native": "^12.4.1", + "dpdm": "^3.14.0", "expo": "~50.0.2", "jest": "^29.3.1", "jest-cli": "^29.3.1", diff --git a/packages/taro-rn/dep.js b/packages/taro-rn/dep.js new file mode 100644 index 000000000000..5b056e3d22bd --- /dev/null +++ b/packages/taro-rn/dep.js @@ -0,0 +1,49 @@ +/* eslint-disable @typescript-eslint/no-var-requires */ +const { parseDependencyTree } = require('dpdm') +const { peerDependencies } = require('./package.json') + +const hiddenDependenciesMap = { + '@ant-design/react-native/lib/picker': ['@react-native-picker/picker'] +} + +const componentReg = /^src\/lib\/(\w+)\/index.tsx?$/ + +function parseDependencyCircular(dep = [], tree = {}) { + dep.forEach(d => { + const item = tree[d.id] + if (item) { + dep = dep.concat(parseDependencyCircular(item, tree)) + } + }) + return dep +} + +parseDependencyTree('./src/lib/index.ts', {}).then((tree) => { + const result = {} + Object.keys(tree).map(key => { + const match = key.match(componentReg) + if (match) { + const name = match[1] + parseDependencyCircular(tree[key], tree).map(dependency => { + const dep = dependency.id + if (dep) { + [...Object.keys(peerDependencies), ...Object.keys(hiddenDependenciesMap)].forEach(value => { + if (dep.match(`node_modules/${value}`)) { + result[name] = result[name] || new Set() + if (hiddenDependenciesMap[value]) { + hiddenDependenciesMap[value].forEach(value => { + const showName = peerDependencies[value] ? `${value}@${peerDependencies[value]}` : value + result[name].add(showName) + }) + } else { + const showName = peerDependencies[value] ? `${value}@${peerDependencies[value]}` : value + result[name].add(showName) + } + } + }) + } + }) + } + }) + console.log(result) +}) diff --git a/packages/taro-rn/package.json b/packages/taro-rn/package.json index f739c251ba12..f50f5422d34c 100644 --- a/packages/taro-rn/package.json +++ b/packages/taro-rn/package.json @@ -67,6 +67,7 @@ "@testing-library/jest-native": "^5.4.2", "@testing-library/react-native": "^12.4.1", "@types/jest": "^27.4.1", + "dpdm": "^3.14.0", "expo": "~50.0.2", "fbjs-scripts": "^3.0.1", "jest": "^29.3.1", diff --git a/packages/taro-rn/src/lib/getLocation/index.ts b/packages/taro-rn/src/lib/getLocation/index.ts index bd088f3ac9d6..042421bd6ef2 100644 --- a/packages/taro-rn/src/lib/getLocation/index.ts +++ b/packages/taro-rn/src/lib/getLocation/index.ts @@ -1,14 +1,18 @@ import Geolocation from '@react-native-community/geolocation' -import { requestForegroundPermissionsAsync } from 'expo-location' import { errorHandler } from '../../utils' export async function getLocation(opts: Taro.getLocation.Option = {}): Promise { const { isHighAccuracy = false, highAccuracyExpireTime = 3000, success, fail, complete } = opts - + const requestAuthorization = () => { + return new Promise((resolve, reject) => { + Geolocation.requestAuthorization(()=>resolve({granted: true}), (err)=>reject(err)) + }) + } + try { // @ts-ignore // todo: fix types - const { granted } = await requestForegroundPermissionsAsync() + const {granted} = await requestAuthorization() if (!granted) { const res = { errMsg: 'Permissions denied!' } return errorHandler(fail, complete)(res)