Skip to content

Commit

Permalink
build uni runtime(caniuse)
Browse files Browse the repository at this point in the history
  • Loading branch information
fxy060608 committed Apr 29, 2019
1 parent 6014676 commit 8690a6b
Show file tree
Hide file tree
Showing 8 changed files with 81 additions and 41 deletions.
41 changes: 24 additions & 17 deletions packages/uni-mp-alipay/dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ const camelize = cached((str) => {
return str.replace(camelizeRE, (_, c) => c ? c.toUpperCase() : '')
});

const SYNC_API_RE = /requireNativePlugin|upx2px|hideKeyboard|canIUse|^create|Sync$|Manager$/;
const SYNC_API_RE = /subNVue|requireNativePlugin|upx2px|hideKeyboard|canIUse|^create|Sync$|Manager$/;

const CONTEXT_API_RE = /^create|Manager$/;

Expand Down Expand Up @@ -145,7 +145,7 @@ function upx2px (number, newDeviceWidth) {
}

// 不支持的 API 列表
const TODOS = [
const todos = [
'saveImageToPhotosAlbum',
'getRecorderManager',
'getBackgroundAudioManager',
Expand All @@ -170,7 +170,6 @@ const TODOS = [
'hideTabBarRedDot',
'setBackgroundColor',
'setBackgroundTextStyle',
'startPullDownRefresh',
'createIntersectionObserver',
'authorize',
'openSetting',
Expand All @@ -191,6 +190,11 @@ const TODOS = [
'offWindowResize'
];

// 存在兼容性的 API 列表
const canIUses = [
'startPullDownRefresh'
];

function _handleNetworkInfo (result) {
switch (result.networkType) {
case 'NOTREACHABLE':
Expand Down Expand Up @@ -462,7 +466,7 @@ const protocols = { // 需要做转换的 API 列表
requestPayment: {
name: 'tradePay',
args: {
orderInfo: 'orderStr'
orderInfo: 'tradeNO'
}
},
getBLEDeviceServices: {
Expand Down Expand Up @@ -503,11 +507,7 @@ const protocols = { // 需要做转换的 API 列表
brightness: 'value'
}
}
};

TODOS.forEach(todoApi => {
protocols[todoApi] = false;
});
};

const CALLBACKS = ['success', 'fail', 'cancel', 'complete'];

Expand Down Expand Up @@ -586,7 +586,7 @@ function wrapper (methodName, method) {

const todoApis = Object.create(null);

const TODOS$1 = [
const TODOS = [
'subscribePush',
'unsubscribePush',
'onPush',
Expand All @@ -607,7 +607,7 @@ function createTodoApi (name) {
}
}

TODOS$1.forEach(function (name) {
TODOS.forEach(function (name) {
todoApis[name] = createTodoApi(name);
});

Expand Down Expand Up @@ -655,12 +655,8 @@ function getStorageSync (key) {
const result = my.getStorageSync({
key
});
// 不知道会不会出现 success 为 false 情况,暂时这样处理下。
if (result.success) {
return result.data || ''
} else {
return ''
}
// 支付宝平台会返回一个 success 值,但是目前测试的结果这个始终是 true。当没有存储数据的时候,其它平台会返回空字符串。
return result.data !== null ? result.data : ''
}
function removeStorageSync (key) {
return my.removeStorageSync({
Expand Down Expand Up @@ -1547,6 +1543,17 @@ function createComponent (vueOptions) {
return initComponent(componentOptions, vueOptions)
}

todos.forEach(todoApi => {
protocols[todoApi] = false;
});

canIUses.forEach(canIUseApi => {
const apiName = protocols[canIUseApi] && protocols[canIUseApi].name ? protocols[canIUseApi].name : canIUseApi;
if (!my.canIUse(apiName)) {
protocols[canIUseApi] = false;
}
});

let uni = {};

if (typeof Proxy !== 'undefined') {
Expand Down
2 changes: 1 addition & 1 deletion packages/uni-mp-alipay/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@dcloudio/uni-mp-alipay",
"version": "0.0.801",
"version": "0.0.802",
"description": "uni-app mp-alipay",
"main": "dist/index.js",
"scripts": {
Expand Down
28 changes: 19 additions & 9 deletions packages/uni-mp-baidu/dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ const camelize = cached((str) => {
return str.replace(camelizeRE, (_, c) => c ? c.toUpperCase() : '')
});

const SYNC_API_RE = /requireNativePlugin|upx2px|hideKeyboard|canIUse|^create|Sync$|Manager$/;
const SYNC_API_RE = /subNVue|requireNativePlugin|upx2px|hideKeyboard|canIUse|^create|Sync$|Manager$/;

const CONTEXT_API_RE = /^create|Manager$/;

Expand Down Expand Up @@ -145,7 +145,7 @@ function upx2px (number, newDeviceWidth) {
}

// 不支持的 API 列表
const TODOS = [
const todos = [
'hideKeyboard',
'onGyroscopeChange',
'startGyroscope',
Expand Down Expand Up @@ -178,6 +178,9 @@ const TODOS = [
'offWindowResize'
];

// 存在兼容性的 API 列表
const canIUses = [];

function createTodoMethod (contextName, methodName) {
return function unsupported () {
console.error(`百度小程序 ${contextName}暂不支持${methodName}`);
Expand Down Expand Up @@ -237,11 +240,7 @@ const protocols = {
showShareMenu: {
name: 'openShare'
}
};

TODOS.forEach(todoApi => {
protocols[todoApi] = false;
});
};

const CALLBACKS = ['success', 'fail', 'cancel', 'complete'];

Expand Down Expand Up @@ -320,7 +319,7 @@ function wrapper (methodName, method) {

const todoApis = Object.create(null);

const TODOS$1 = [
const TODOS = [
'subscribePush',
'unsubscribePush',
'onPush',
Expand All @@ -341,7 +340,7 @@ function createTodoApi (name) {
}
}

TODOS$1.forEach(function (name) {
TODOS.forEach(function (name) {
todoApis[name] = createTodoApi(name);
});

Expand Down Expand Up @@ -1159,6 +1158,17 @@ function createComponent (vueOptions) {
return initComponent$1(componentOptions, vueOptions)
}

todos.forEach(todoApi => {
protocols[todoApi] = false;
});

canIUses.forEach(canIUseApi => {
const apiName = protocols[canIUseApi] && protocols[canIUseApi].name ? protocols[canIUseApi].name : canIUseApi;
if (!swan.canIUse(apiName)) {
protocols[canIUseApi] = false;
}
});

let uni = {};

if (typeof Proxy !== 'undefined') {
Expand Down
2 changes: 1 addition & 1 deletion packages/uni-mp-baidu/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@dcloudio/uni-mp-baidu",
"version": "0.0.827",
"version": "0.0.828",
"description": "uni-app mp-baidu",
"main": "dist/index.js",
"scripts": {
Expand Down
28 changes: 19 additions & 9 deletions packages/uni-mp-toutiao/dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ const camelize = cached((str) => {
return str.replace(camelizeRE, (_, c) => c ? c.toUpperCase() : '')
});

const SYNC_API_RE = /requireNativePlugin|upx2px|hideKeyboard|canIUse|^create|Sync$|Manager$/;
const SYNC_API_RE = /subNVue|requireNativePlugin|upx2px|hideKeyboard|canIUse|^create|Sync$|Manager$/;

const CONTEXT_API_RE = /^create|Manager$/;

Expand Down Expand Up @@ -145,7 +145,7 @@ function upx2px (number, newDeviceWidth) {
}

// 不支持的 API 列表
const TODOS = [
const todos = [
'hideKeyboard',
'onSocketOpen',
'onSocketError',
Expand Down Expand Up @@ -227,6 +227,9 @@ const TODOS = [
'offWindowResize'
];

// 存在兼容性的 API 列表
const canIUses = [];

// 需要做转换的 API 列表
const protocols = {
chooseImage: {
Expand Down Expand Up @@ -298,11 +301,7 @@ const protocols = {
requestPayment: {
orderInfo: 'data'
}
};

TODOS.forEach(todoApi => {
protocols[todoApi] = false;
});
};

const CALLBACKS = ['success', 'fail', 'cancel', 'complete'];

Expand Down Expand Up @@ -381,7 +380,7 @@ function wrapper (methodName, method) {

const todoApis = Object.create(null);

const TODOS$1 = [
const TODOS = [
'subscribePush',
'unsubscribePush',
'onPush',
Expand All @@ -402,7 +401,7 @@ function createTodoApi (name) {
}
}

TODOS$1.forEach(function (name) {
TODOS.forEach(function (name) {
todoApis[name] = createTodoApi(name);
});

Expand Down Expand Up @@ -1166,6 +1165,17 @@ function createComponent (vueOptions) {
return initComponent$1(componentOptions, vueOptions)
}

todos.forEach(todoApi => {
protocols[todoApi] = false;
});

canIUses.forEach(canIUseApi => {
const apiName = protocols[canIUseApi] && protocols[canIUseApi].name ? protocols[canIUseApi].name : canIUseApi;
if (!tt.canIUse(apiName)) {
protocols[canIUseApi] = false;
}
});

let uni = {};

if (typeof Proxy !== 'undefined') {
Expand Down
2 changes: 1 addition & 1 deletion packages/uni-mp-toutiao/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@dcloudio/uni-mp-toutiao",
"version": "0.0.325",
"version": "0.0.326",
"description": "uni-app mp-toutiao",
"main": "dist/index.js",
"scripts": {
Expand Down
17 changes: 15 additions & 2 deletions packages/uni-mp-weixin/dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ const camelize = cached((str) => {
return str.replace(camelizeRE, (_, c) => c ? c.toUpperCase() : '')
});

const SYNC_API_RE = /requireNativePlugin|upx2px|hideKeyboard|canIUse|^create|Sync$|Manager$/;
const SYNC_API_RE = /subNVue|requireNativePlugin|upx2px|hideKeyboard|canIUse|^create|Sync$|Manager$/;

const CONTEXT_API_RE = /^create|Manager$/;

Expand Down Expand Up @@ -144,7 +144,9 @@ function upx2px (number, newDeviceWidth) {
return number < 0 ? -result : result
}

var protocols = {};
const protocols = {};
const todos = [];
const canIUses = [];

const CALLBACKS = ['success', 'fail', 'cancel', 'complete'];

Expand Down Expand Up @@ -1004,6 +1006,17 @@ function createComponent (vueOptions) {
return initComponent(componentOptions, vueOptions)
}

todos.forEach(todoApi => {
protocols[todoApi] = false;
});

canIUses.forEach(canIUseApi => {
const apiName = protocols[canIUseApi] && protocols[canIUseApi].name ? protocols[canIUseApi].name : canIUseApi;
if (!wx.canIUse(apiName)) {
protocols[canIUseApi] = false;
}
});

let uni = {};

if (typeof Proxy !== 'undefined') {
Expand Down
2 changes: 1 addition & 1 deletion packages/uni-mp-weixin/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@dcloudio/uni-mp-weixin",
"version": "0.0.949",
"version": "0.0.950",
"description": "uni-app mp-weixin",
"main": "dist/index.js",
"scripts": {
Expand Down

0 comments on commit 8690a6b

Please sign in to comment.