提交 0a8cff40 编写于 作者: 雪洛's avatar 雪洛

Revert "wip(uvue): 重构 uts ext api 的 auto import"

This reverts commit ff87e1ef.
上级 14d8f440
import { parseInjects } from '../src/uni_modules' import { parseInjects } from '../src/uni_modules'
import { injectsToAutoImports } from '../src/vite'
describe('uni_modules:uni-ext-api', () => { describe('uni_modules:uni-ext-api', () => {
test('parseInjects', () => { test('parseInjects', () => {
...@@ -216,28 +215,4 @@ describe('uni_modules:uni-ext-api', () => { ...@@ -216,28 +215,4 @@ describe('uni_modules:uni-ext-api', () => {
], ],
}) })
}) })
test(`injectsToAutoImports`, () => {
expect(
injectsToAutoImports(
parseInjects(
true,
'app-android',
'kotlin',
`@/uni_modules/uni-getbatteryinfo`,
'',
{
uni: ['getBatteryInfo', 'getBatteryInfoSync'],
}
)
)
).toEqual([
{
from: '@/uni_modules/uni-getbatteryinfo',
imports: [
['getBatteryInfo', 'uni_getBatteryInfo'],
['getBatteryInfoSync', 'uni_getBatteryInfoSync'],
],
},
])
})
}) })
...@@ -6,7 +6,7 @@ export const EXTNAME_VUE = ['.vue', '.nvue', '.uvue'] ...@@ -6,7 +6,7 @@ export const EXTNAME_VUE = ['.vue', '.nvue', '.uvue']
export const X_EXTNAME_VUE = ['.uvue', '.vue'] export const X_EXTNAME_VUE = ['.uvue', '.vue']
export const EXTNAME_VUE_TEMPLATE = ['.vue', '.nvue', '.uvue', '.jsx', '.tsx'] export const EXTNAME_VUE_TEMPLATE = ['.vue', '.nvue', '.uvue', '.jsx', '.tsx']
export const EXTNAME_VUE_RE = /\.(vue|nvue|uvue)$/ export const EXTNAME_VUE_RE = /\.(vue|nvue|uvue)$/
export const EXTNAME_JS_RE = /\.(js|jsx|ts|uts|tsx|mjs)$/ export const EXTNAME_JS_RE = /\.(js|jsx|ts|tsx|mjs)$/
export const EXTNAME_TS_RE = /\.tsx?$/ export const EXTNAME_TS_RE = /\.tsx?$/
const COMMON_EXTENSIONS = [ const COMMON_EXTENSIONS = [
......
...@@ -2,7 +2,6 @@ ...@@ -2,7 +2,6 @@
import path from 'path' import path from 'path'
import fs from 'fs-extra' import fs from 'fs-extra'
import type { UTSTargetLanguage } from './uts' import type { UTSTargetLanguage } from './uts'
import { once } from '@dcloudio/uni-shared'
export type DefineOptions = { export type DefineOptions = {
name?: string name?: string
...@@ -29,13 +28,11 @@ export interface Exports { ...@@ -29,13 +28,11 @@ export interface Exports {
[name: string]: Define | Defines | false [name: string]: Define | Defines | false
} }
export const parseUniExtApisOnce = once(parseUniExtApis)
export function parseUniExtApis( export function parseUniExtApis(
vite = true, vite = true,
platform: typeof process.env.UNI_UTS_PLATFORM, platform: typeof process.env.UNI_UTS_PLATFORM,
language: UTSTargetLanguage = 'javascript' language: UTSTargetLanguage = 'javascript'
): Injects { ) {
if (!process.env.UNI_INPUT_DIR) { if (!process.env.UNI_INPUT_DIR) {
return {} return {}
} }
...@@ -78,7 +75,7 @@ export function parseUniExtApis( ...@@ -78,7 +75,7 @@ export function parseUniExtApis(
} }
type Inject = string | string[] type Inject = string | string[]
export type Injects = { type Injects = {
[name: string]: [name: string]:
| string | string
| [string, string] | [string, string]
......
import { Options } from 'unplugin-auto-import/types' import { Options } from 'unplugin-auto-import/types'
import { injectsToAutoImports } from './plugins/uts/ext-api'
import { parseUniExtApisOnce } from '../uni_modules'
export type AutoImportOptions = Options export type AutoImportOptions = Options
...@@ -113,18 +111,9 @@ export function initAutoImportOptions( ...@@ -113,18 +111,9 @@ export function initAutoImportOptions(
if (platform === 'web') { if (platform === 'web') {
autoImport.push(uniH5Preset) autoImport.push(uniH5Preset)
} }
if (platform !== 'app-android') {
// 非 android 平台,注入 uts ext-api
injectsToAutoImports(
parseUniExtApisOnce(true, platform, 'javascript')
).forEach(
// @ts-expect-error
(item) => autoImport.push(item)
)
}
return { return {
...userOptions, ...userOptions,
include: [/\.[u]?ts$/, /\.[u]?vue/], include: [/\.[u]?ts$/, /\.[u]?vue$/, /\.[u]?vue\?vue/],
exclude: [/[\\/]\.git[\\/]/], exclude: [/[\\/]\.git[\\/]/],
imports: (imports as any[]).concat( imports: (imports as any[]).concat(
// app-android 平台暂不注入其他 // app-android 平台暂不注入其他
......
import type { Plugin } from 'vite' import type { Plugin } from 'vite'
import { isArray } from '@vue/shared'
import { Injects, parseUniExtApisOnce } from '../../../uni_modules' import { parseUniExtApis } from '../../../uni_modules'
import { isJsFile } from '../../utils/url' import { InjectOptions, uniViteInjectPlugin } from '../inject'
const escape = (str: string) => str.replace(/[-[\]/{}()*+?.\\^$|]/g, '\\$&') export function uniUTSExtApi(): Plugin {
export function uniUTSExtApiReplace(): Plugin {
const injects = parseUniExtApisOnce(
true,
process.env.UNI_UTS_PLATFORM,
'javascript'
)
const injectApis = Object.keys(injects)
const firstPass = new RegExp(`(?:${injectApis.map(escape).join('|')})`, 'g')
return { return {
name: 'uni:uts-ext-api-replace', name: 'uni:uts-ext-api',
transform(code, id) { configResolved(config) {
if (!injectApis.length) { // 在 uts 之前插入 ext-api-inject
return const index = config.plugins.findIndex((p) => p.name === 'uts')
} if (index > -1) {
if (!isJsFile(id)) { const injects = parseUniExtApis(
return true,
} process.env.UNI_UTS_PLATFORM,
if (code.search(firstPass) === -1) { 'javascript'
return )
} if (Object.keys(injects).length) {
injectApis.forEach((api) => { // @ts-expect-error
code = code.replaceAll(api, api.replace('.', '_')) config.plugins.splice(
}) index,
return { 0,
code, uniViteInjectPlugin('uni:ext-api-inject', injects as InjectOptions)
map: { mappings: '' }, )
}
} }
}, },
} }
} }
/**
* { 'uni.getBatteryInfo': ['@/uni_modules/uni-getbatteryinfo/utssdk/web/index.uts','getBatteryInfo'] }
* { '@/uni_modules/uni-getbatteryinfo/utssdk/web/index.ts': [['getBatteryInfo', 'uni_getBatteryInfo']] }
* @param injects
*/
export function injectsToAutoImports(
injects: Injects
): { from: string; imports: [string, string][] }[] {
const autoImports: Record<string, [string, string][]> = {}
Object.keys(injects).forEach((api) => {
const options = injects[api]
if (isArray(options) && options.length === 2) {
const source = options[0]
const name = options[1]
if (!autoImports[source]) {
autoImports[source] = []
}
autoImports[source].push([name, api.replace('.', '_')])
}
})
return Object.keys(autoImports).map((source) => {
return {
from: source,
imports: autoImports[source],
}
})
}
...@@ -11,220 +11,6 @@ const shared = require("@vue/shared"); ...@@ -11,220 +11,6 @@ const shared = require("@vue/shared");
const uniShared = require("@dcloudio/uni-shared"); const uniShared = require("@dcloudio/uni-shared");
const uniI18n = require("@dcloudio/uni-i18n"); const uniI18n = require("@dcloudio/uni-i18n");
const vueRouter = require("vue-router"); const vueRouter = require("vue-router");
class UniError extends Error {
constructor(errSubject, errCode, errMsg) {
super(errMsg);
this.name = "UniError";
this.errSubject = errSubject;
this.errCode = errCode;
this.errMsg = errMsg;
}
toString() {
return this.errMsg;
}
toJSON() {
return {
errSubject: this.errSubject,
errCode: this.errCode,
errMsg: this.errMsg,
data: this.data,
cause: this.cause && typeof this.cause.toJSON === "function" ? this.cause.toJSON() : this.cause
};
}
}
function getType$1(val) {
return Object.prototype.toString.call(val).slice(8, -1).toLowerCase();
}
function isPlainObject(val) {
if (val == null || typeof val !== "object") {
return false;
}
const proto = Object.getPrototypeOf(val);
return proto === Object.prototype || proto === null;
}
function initUTSJSONObjectProperties(obj) {
const propertyList = [
"_resolveKeyPath",
"_getValue",
"toJSON",
"get",
"set",
"getAny",
"getString",
"getNumber",
"getBoolean",
"getJSON",
"getArray",
"toMap",
"forEach"
];
const propertyDescriptorMap = {};
for (let i = 0; i < propertyList.length; i++) {
const property = propertyList[i];
propertyDescriptorMap[property] = {
enumerable: false,
value: obj[property]
};
}
Object.defineProperties(obj, propertyDescriptorMap);
}
class UTSJSONObject {
constructor(content = {}) {
for (const key in content) {
if (Object.prototype.hasOwnProperty.call(content, key)) {
const value = content[key];
if (isPlainObject(value)) {
this[key] = new UTSJSONObject(value);
} else if (getType$1(value) === "array") {
this[key] = value.map((item) => {
if (isPlainObject(item)) {
return new UTSJSONObject(item);
} else {
return item;
}
});
} else {
this[key] = value;
}
}
}
initUTSJSONObjectProperties(this);
}
_resolveKeyPath(keyPath) {
let token = "";
const keyPathArr = [];
let inOpenParentheses = false;
for (let i = 0; i < keyPath.length; i++) {
const word = keyPath[i];
switch (word) {
case ".":
if (token.length > 0) {
keyPathArr.push(token);
token = "";
}
break;
case "[": {
inOpenParentheses = true;
if (token.length > 0) {
keyPathArr.push(token);
token = "";
}
break;
}
case "]":
if (inOpenParentheses) {
if (token.length > 0) {
const tokenFirstChar = token[0];
const tokenLastChar = token[token.length - 1];
if (tokenFirstChar === '"' && tokenLastChar === '"' || tokenFirstChar === "'" && tokenLastChar === "'" || tokenFirstChar === "`" && tokenLastChar === "`") {
if (token.length > 2) {
token = token.slice(1, -1);
} else {
return [];
}
} else if (!/^\d+$/.test(token)) {
return [];
}
keyPathArr.push(token);
token = "";
} else {
return [];
}
inOpenParentheses = false;
} else {
return [];
}
break;
default:
token += word;
break;
}
if (i === keyPath.length - 1) {
if (token.length > 0) {
keyPathArr.push(token);
token = "";
}
}
}
return keyPathArr;
}
_getValue(keyPath) {
const keyPathArr = this._resolveKeyPath(keyPath);
if (keyPathArr.length === 0) {
return null;
}
let value = this;
for (let key of keyPathArr) {
if (value instanceof Object) {
value = value[key];
} else {
return null;
}
}
return value;
}
get(key) {
return this._getValue(key);
}
set(key, value) {
this[key] = value;
}
getAny(key) {
return this._getValue(key);
}
getString(key) {
const value = this._getValue(key);
if (typeof value === "string") {
return value;
} else {
return null;
}
}
getNumber(key) {
const value = this._getValue(key);
if (typeof value === "number") {
return value;
} else {
return null;
}
}
getBoolean(key) {
const boolean = this._getValue(key);
if (typeof boolean === "boolean") {
return boolean;
} else {
return null;
}
}
getJSON(key) {
let value = this._getValue(key);
if (value instanceof Object) {
return new UTSJSONObject(value);
} else {
return null;
}
}
getArray(key) {
let value = this._getValue(key);
if (value instanceof Array) {
return value;
} else {
return null;
}
}
toMap() {
let map = /* @__PURE__ */ new Map();
for (let key in this) {
map.set(key, this[key]);
}
return map;
}
forEach(callback) {
for (let key in this) {
callback(this[key], key);
}
}
}
const isEnableLocale = /* @__PURE__ */ uniShared.once( const isEnableLocale = /* @__PURE__ */ uniShared.once(
() => typeof __uniConfig !== "undefined" && __uniConfig.locales && !!Object.keys(__uniConfig.locales).length () => typeof __uniConfig !== "undefined" && __uniConfig.locales && !!Object.keys(__uniConfig.locales).length
); );
...@@ -12866,27 +12652,6 @@ function createPageBodyVNode(ctx) { ...@@ -12866,27 +12652,6 @@ function createPageBodyVNode(ctx) {
} }
); );
} }
function getGlobal() {
if (typeof globalThis !== "undefined") {
return globalThis;
}
if (typeof self !== "undefined") {
return self;
}
if (typeof window !== "undefined") {
return window;
}
if (typeof global !== "undefined") {
return global;
}
throw new Error("unable to locate global object");
}
const realGlobal = getGlobal();
if (!realGlobal.globalThis) {
realGlobal.globalThis = realGlobal;
}
globalThis.UTSJSONObject = UTSJSONObject;
globalThis.UniError = UniError;
exports.Ad = index$6; exports.Ad = index$6;
exports.AdContentPage = index$5; exports.AdContentPage = index$5;
exports.AdDraw = index$4; exports.AdDraw = index$4;
......
...@@ -5,225 +5,11 @@ var __publicField = (obj, key, value) => { ...@@ -5,225 +5,11 @@ var __publicField = (obj, key, value) => {
return value; return value;
}; };
import { withModifiers, createVNode, getCurrentInstance, ref, defineComponent, openBlock, createElementBlock, onMounted, provide, computed, watch, onUnmounted, inject, onBeforeUnmount, mergeProps, injectHook, reactive, onActivated, nextTick, onBeforeMount, withDirectives, vModelDynamic, vShow, shallowRef, watchEffect, isVNode, Fragment, markRaw, Comment, h, createTextVNode, isReactive, Transition, createApp, createBlock, onBeforeActivate, onBeforeDeactivate, renderList, effectScope, withCtx, KeepAlive, resolveDynamicComponent, createElementVNode, normalizeStyle, renderSlot } from "vue"; import { withModifiers, createVNode, getCurrentInstance, ref, defineComponent, openBlock, createElementBlock, onMounted, provide, computed, watch, onUnmounted, inject, onBeforeUnmount, mergeProps, injectHook, reactive, onActivated, nextTick, onBeforeMount, withDirectives, vModelDynamic, vShow, shallowRef, watchEffect, isVNode, Fragment, markRaw, Comment, h, createTextVNode, isReactive, Transition, createApp, createBlock, onBeforeActivate, onBeforeDeactivate, renderList, effectScope, withCtx, KeepAlive, resolveDynamicComponent, createElementVNode, normalizeStyle, renderSlot } from "vue";
import { isArray, isString, extend, remove, stringifyStyle, parseStringStyle, isPlainObject as isPlainObject$1, isFunction, capitalize, camelize, hasOwn, isObject, toRawType, makeMap as makeMap$1, isPromise, hyphenate, invokeArrayFns as invokeArrayFns$1 } from "@vue/shared"; import { isArray, isString, extend, remove, stringifyStyle, parseStringStyle, isPlainObject, isFunction, capitalize, camelize, hasOwn, isObject, toRawType, makeMap as makeMap$1, isPromise, hyphenate, invokeArrayFns as invokeArrayFns$1 } from "@vue/shared";
import { once, UNI_STORAGE_LOCALE, I18N_JSON_DELIMITERS, Emitter, passive, initCustomDatasetOnce, resolveComponentInstance, normalizeStyles, addLeadingSlash, invokeArrayFns, removeLeadingSlash, resolveOwnerVm, resolveOwnerEl, ON_WXS_INVOKE_CALL_METHOD, ON_RESIZE, ON_APP_ENTER_FOREGROUND, ON_APP_ENTER_BACKGROUND, ON_SHOW, ON_HIDE, ON_PAGE_SCROLL, ON_REACH_BOTTOM, EventChannel, SCHEME_RE, DATA_RE, getCustomDataset, LINEFEED, ON_ERROR, callOptions, ON_UNHANDLE_REJECTION, ON_PAGE_NOT_FOUND, PRIMARY_COLOR, getLen, debounce, isUniLifecycleHook, ON_LOAD, UniLifecycleHooks, invokeCreateErrorHandler, invokeCreateVueAppHook, parseQuery, NAVBAR_HEIGHT, ON_UNLOAD, ON_REACH_BOTTOM_DISTANCE, ON_THEME_CHANGE, decodedQuery, WEB_INVOKE_APPSERVICE, ON_WEB_INVOKE_APP_SERVICE, sortObject, OFF_THEME_CHANGE, updateElementStyle, ON_BACK_PRESS, parseUrl, addFont, ON_NAVIGATION_BAR_CHANGE, scrollTo, RESPONSIVE_MIN_WIDTH, onCreateVueApp, formatDateTime, ON_NAVIGATION_BAR_BUTTON_TAP, ON_NAVIGATION_BAR_SEARCH_INPUT_CLICKED, ON_NAVIGATION_BAR_SEARCH_INPUT_FOCUS_CHANGED, ON_NAVIGATION_BAR_SEARCH_INPUT_CHANGED, ON_NAVIGATION_BAR_SEARCH_INPUT_CONFIRMED, ON_PULL_DOWN_REFRESH } from "@dcloudio/uni-shared"; import { once, UNI_STORAGE_LOCALE, I18N_JSON_DELIMITERS, Emitter, passive, initCustomDatasetOnce, resolveComponentInstance, normalizeStyles, addLeadingSlash, invokeArrayFns, removeLeadingSlash, resolveOwnerVm, resolveOwnerEl, ON_WXS_INVOKE_CALL_METHOD, ON_RESIZE, ON_APP_ENTER_FOREGROUND, ON_APP_ENTER_BACKGROUND, ON_SHOW, ON_HIDE, ON_PAGE_SCROLL, ON_REACH_BOTTOM, EventChannel, SCHEME_RE, DATA_RE, getCustomDataset, LINEFEED, ON_ERROR, callOptions, ON_UNHANDLE_REJECTION, ON_PAGE_NOT_FOUND, PRIMARY_COLOR, getLen, debounce, isUniLifecycleHook, ON_LOAD, UniLifecycleHooks, invokeCreateErrorHandler, invokeCreateVueAppHook, parseQuery, NAVBAR_HEIGHT, ON_UNLOAD, ON_REACH_BOTTOM_DISTANCE, ON_THEME_CHANGE, decodedQuery, WEB_INVOKE_APPSERVICE, ON_WEB_INVOKE_APP_SERVICE, sortObject, OFF_THEME_CHANGE, updateElementStyle, ON_BACK_PRESS, parseUrl, addFont, ON_NAVIGATION_BAR_CHANGE, scrollTo, RESPONSIVE_MIN_WIDTH, onCreateVueApp, formatDateTime, ON_NAVIGATION_BAR_BUTTON_TAP, ON_NAVIGATION_BAR_SEARCH_INPUT_CLICKED, ON_NAVIGATION_BAR_SEARCH_INPUT_FOCUS_CHANGED, ON_NAVIGATION_BAR_SEARCH_INPUT_CHANGED, ON_NAVIGATION_BAR_SEARCH_INPUT_CONFIRMED, ON_PULL_DOWN_REFRESH } from "@dcloudio/uni-shared";
import { onCreateVueApp as onCreateVueApp2 } from "@dcloudio/uni-shared"; import { onCreateVueApp as onCreateVueApp2 } from "@dcloudio/uni-shared";
import { initVueI18n, isI18nStr, LOCALE_EN, LOCALE_ES, LOCALE_FR, LOCALE_ZH_HANS, LOCALE_ZH_HANT } from "@dcloudio/uni-i18n"; import { initVueI18n, isI18nStr, LOCALE_EN, LOCALE_ES, LOCALE_FR, LOCALE_ZH_HANS, LOCALE_ZH_HANT } from "@dcloudio/uni-i18n";
import { useRoute, createRouter, createWebHistory, createWebHashHistory, useRouter, isNavigationFailure, RouterView } from "vue-router"; import { useRoute, createRouter, createWebHistory, createWebHashHistory, useRouter, isNavigationFailure, RouterView } from "vue-router";
class UniError extends Error {
constructor(errSubject, errCode, errMsg) {
super(errMsg);
this.name = "UniError";
this.errSubject = errSubject;
this.errCode = errCode;
this.errMsg = errMsg;
}
toString() {
return this.errMsg;
}
toJSON() {
return {
errSubject: this.errSubject,
errCode: this.errCode,
errMsg: this.errMsg,
data: this.data,
cause: this.cause && typeof this.cause.toJSON === "function" ? this.cause.toJSON() : this.cause
};
}
}
function getType$1(val) {
return Object.prototype.toString.call(val).slice(8, -1).toLowerCase();
}
function isPlainObject(val) {
if (val == null || typeof val !== "object") {
return false;
}
const proto = Object.getPrototypeOf(val);
return proto === Object.prototype || proto === null;
}
function initUTSJSONObjectProperties(obj) {
const propertyList = [
"_resolveKeyPath",
"_getValue",
"toJSON",
"get",
"set",
"getAny",
"getString",
"getNumber",
"getBoolean",
"getJSON",
"getArray",
"toMap",
"forEach"
];
const propertyDescriptorMap = {};
for (let i = 0; i < propertyList.length; i++) {
const property = propertyList[i];
propertyDescriptorMap[property] = {
enumerable: false,
value: obj[property]
};
}
Object.defineProperties(obj, propertyDescriptorMap);
}
class UTSJSONObject {
constructor(content = {}) {
for (const key in content) {
if (Object.prototype.hasOwnProperty.call(content, key)) {
const value = content[key];
if (isPlainObject(value)) {
this[key] = new UTSJSONObject(value);
} else if (getType$1(value) === "array") {
this[key] = value.map((item) => {
if (isPlainObject(item)) {
return new UTSJSONObject(item);
} else {
return item;
}
});
} else {
this[key] = value;
}
}
}
initUTSJSONObjectProperties(this);
}
_resolveKeyPath(keyPath) {
let token = "";
const keyPathArr = [];
let inOpenParentheses = false;
for (let i = 0; i < keyPath.length; i++) {
const word = keyPath[i];
switch (word) {
case ".":
if (token.length > 0) {
keyPathArr.push(token);
token = "";
}
break;
case "[": {
inOpenParentheses = true;
if (token.length > 0) {
keyPathArr.push(token);
token = "";
}
break;
}
case "]":
if (inOpenParentheses) {
if (token.length > 0) {
const tokenFirstChar = token[0];
const tokenLastChar = token[token.length - 1];
if (tokenFirstChar === '"' && tokenLastChar === '"' || tokenFirstChar === "'" && tokenLastChar === "'" || tokenFirstChar === "`" && tokenLastChar === "`") {
if (token.length > 2) {
token = token.slice(1, -1);
} else {
return [];
}
} else if (!/^\d+$/.test(token)) {
return [];
}
keyPathArr.push(token);
token = "";
} else {
return [];
}
inOpenParentheses = false;
} else {
return [];
}
break;
default:
token += word;
break;
}
if (i === keyPath.length - 1) {
if (token.length > 0) {
keyPathArr.push(token);
token = "";
}
}
}
return keyPathArr;
}
_getValue(keyPath) {
const keyPathArr = this._resolveKeyPath(keyPath);
if (keyPathArr.length === 0) {
return null;
}
let value = this;
for (let key of keyPathArr) {
if (value instanceof Object) {
value = value[key];
} else {
return null;
}
}
return value;
}
get(key) {
return this._getValue(key);
}
set(key, value) {
this[key] = value;
}
getAny(key) {
return this._getValue(key);
}
getString(key) {
const value = this._getValue(key);
if (typeof value === "string") {
return value;
} else {
return null;
}
}
getNumber(key) {
const value = this._getValue(key);
if (typeof value === "number") {
return value;
} else {
return null;
}
}
getBoolean(key) {
const boolean = this._getValue(key);
if (typeof boolean === "boolean") {
return boolean;
} else {
return null;
}
}
getJSON(key) {
let value = this._getValue(key);
if (value instanceof Object) {
return new UTSJSONObject(value);
} else {
return null;
}
}
getArray(key) {
let value = this._getValue(key);
if (value instanceof Array) {
return value;
} else {
return null;
}
}
toMap() {
let map = /* @__PURE__ */ new Map();
for (let key in this) {
map.set(key, this[key]);
}
return map;
}
forEach(callback) {
for (let key in this) {
callback(this[key], key);
}
}
}
const isEnableLocale = /* @__PURE__ */ once( const isEnableLocale = /* @__PURE__ */ once(
() => typeof __uniConfig !== "undefined" && __uniConfig.locales && !!Object.keys(__uniConfig.locales).length () => typeof __uniConfig !== "undefined" && __uniConfig.locales && !!Object.keys(__uniConfig.locales).length
); );
...@@ -1586,7 +1372,7 @@ class ComponentDescriptor { ...@@ -1586,7 +1372,7 @@ class ComponentDescriptor {
if (isString(style)) { if (isString(style)) {
style = parseStringStyle(style); style = parseStringStyle(style);
} }
if (isPlainObject$1(style)) { if (isPlainObject(style)) {
this.$el.__wxsStyle = style; this.$el.__wxsStyle = style;
this.forceUpdate("style"); this.forceUpdate("style");
} }
...@@ -2505,7 +2291,7 @@ function _addListeners(id2, listeners2, watch2) { ...@@ -2505,7 +2291,7 @@ function _addListeners(id2, listeners2, watch2) {
if (watch2 && !id2) { if (watch2 && !id2) {
return; return;
} }
if (!isPlainObject$1(listeners2)) { if (!isPlainObject(listeners2)) {
return; return;
} }
Object.keys(listeners2).forEach((name) => { Object.keys(listeners2).forEach((name) => {
...@@ -2527,7 +2313,7 @@ function _removeListeners(id2, listeners2, watch2) { ...@@ -2527,7 +2313,7 @@ function _removeListeners(id2, listeners2, watch2) {
if (watch2 && !id2) { if (watch2 && !id2) {
return; return;
} }
if (!isPlainObject$1(listeners2)) { if (!isPlainObject(listeners2)) {
return; return;
} }
Object.keys(listeners2).forEach((name) => { Object.keys(listeners2).forEach((name) => {
...@@ -3019,7 +2805,7 @@ function validateProtocols(name, args, protocol, onFail) { ...@@ -3019,7 +2805,7 @@ function validateProtocols(name, args, protocol, onFail) {
} }
} }
function validateProp(name, value, prop, isAbsent) { function validateProp(name, value, prop, isAbsent) {
if (!isPlainObject$1(prop)) { if (!isPlainObject(prop)) {
prop = { type: prop }; prop = { type: prop };
} }
const { type, required, validator: validator2 } = prop; const { type, required, validator: validator2 } = prop;
...@@ -3191,7 +2977,7 @@ function normalizeErrMsg$1(errMsg, name) { ...@@ -3191,7 +2977,7 @@ function normalizeErrMsg$1(errMsg, name) {
return name + errMsg.substring(errMsg.indexOf(":fail")); return name + errMsg.substring(errMsg.indexOf(":fail"));
} }
function createAsyncApiCallback(name, args = {}, { beforeAll, beforeSuccess } = {}) { function createAsyncApiCallback(name, args = {}, { beforeAll, beforeSuccess } = {}) {
if (!isPlainObject$1(args)) { if (!isPlainObject(args)) {
args = {}; args = {};
} }
const { success, fail, complete } = getApiCallbacks(args); const { success, fail, complete } = getApiCallbacks(args);
...@@ -3318,7 +3104,7 @@ function invokeApi(method, api2, options, params) { ...@@ -3318,7 +3104,7 @@ function invokeApi(method, api2, options, params) {
return api2(options, ...params); return api2(options, ...params);
} }
function hasCallback(args) { function hasCallback(args) {
if (isPlainObject$1(args) && [API_SUCCESS, API_FAIL, API_COMPLETE].find( if (isPlainObject(args) && [API_SUCCESS, API_FAIL, API_COMPLETE].find(
(cb) => isFunction(args[cb]) (cb) => isFunction(args[cb])
)) { )) {
return true; return true;
...@@ -3350,7 +3136,7 @@ function promisify(name, fn) { ...@@ -3350,7 +3136,7 @@ function promisify(name, fn) {
} }
function formatApiArgs(args, options) { function formatApiArgs(args, options) {
const params = args[0]; const params = args[0];
if (!options || !isPlainObject$1(options.formatArgs) && isPlainObject$1(params)) { if (!options || !isPlainObject(options.formatArgs) && isPlainObject(params)) {
return; return;
} }
const formatArgs = options.formatArgs; const formatArgs = options.formatArgs;
...@@ -3653,12 +3439,12 @@ function dedupeHooks(hooks) { ...@@ -3653,12 +3439,12 @@ function dedupeHooks(hooks) {
const addInterceptor = /* @__PURE__ */ defineSyncApi( const addInterceptor = /* @__PURE__ */ defineSyncApi(
API_ADD_INTERCEPTOR, API_ADD_INTERCEPTOR,
(method, interceptor) => { (method, interceptor) => {
if (isString(method) && isPlainObject$1(interceptor)) { if (isString(method) && isPlainObject(interceptor)) {
mergeInterceptorHook( mergeInterceptorHook(
scopedInterceptors[method] || (scopedInterceptors[method] = {}), scopedInterceptors[method] || (scopedInterceptors[method] = {}),
interceptor interceptor
); );
} else if (isPlainObject$1(method)) { } else if (isPlainObject(method)) {
mergeInterceptorHook(globalInterceptors, method); mergeInterceptorHook(globalInterceptors, method);
} }
}, },
...@@ -3668,12 +3454,12 @@ const removeInterceptor = /* @__PURE__ */ defineSyncApi( ...@@ -3668,12 +3454,12 @@ const removeInterceptor = /* @__PURE__ */ defineSyncApi(
API_REMOVE_INTERCEPTOR, API_REMOVE_INTERCEPTOR,
(method, interceptor) => { (method, interceptor) => {
if (isString(method)) { if (isString(method)) {
if (isPlainObject$1(interceptor)) { if (isPlainObject(interceptor)) {
removeInterceptorHook(scopedInterceptors[method], interceptor); removeInterceptorHook(scopedInterceptors[method], interceptor);
} else { } else {
delete scopedInterceptors[method]; delete scopedInterceptors[method];
} }
} else if (isPlainObject$1(method)) { } else if (isPlainObject(method)) {
removeInterceptorHook(globalInterceptors, method); removeInterceptorHook(globalInterceptors, method);
} }
}, },
...@@ -4489,7 +4275,7 @@ class CanvasContext { ...@@ -4489,7 +4275,7 @@ class CanvasContext {
}); });
} }
set font(value) { set font(value) {
var self2 = this; var self = this;
this.state.font = value; this.state.font = value;
var fontFormat = value.match( var fontFormat = value.match(
/^(([\w\-]+\s)*)(\d+r?px)(\/(\d+\.?\d*(r?px)?))?\s+(.*)/ /^(([\w\-]+\s)*)(\d+r?px)(\/(\d+\.?\d*(r?px)?))?\s+(.*)/
...@@ -4505,19 +4291,19 @@ class CanvasContext { ...@@ -4505,19 +4291,19 @@ class CanvasContext {
method: "setFontStyle", method: "setFontStyle",
data: [value2] data: [value2]
}); });
self2.state.fontStyle = value2; self.state.fontStyle = value2;
} else if (["bold", "normal"].indexOf(value2) > -1) { } else if (["bold", "normal"].indexOf(value2) > -1) {
actions.push({ actions.push({
method: "setFontWeight", method: "setFontWeight",
data: [value2] data: [value2]
}); });
self2.state.fontWeight = value2; self.state.fontWeight = value2;
} else if (index2 === 0) { } else if (index2 === 0) {
actions.push({ actions.push({
method: "setFontStyle", method: "setFontStyle",
data: ["normal"] data: ["normal"]
}); });
self2.state.fontStyle = "normal"; self.state.fontStyle = "normal";
} else if (index2 === 1) { } else if (index2 === 1) {
pushAction(); pushAction();
} }
...@@ -4542,7 +4328,7 @@ class CanvasContext { ...@@ -4542,7 +4328,7 @@ class CanvasContext {
method: "setFontWeight", method: "setFontWeight",
data: ["normal"] data: ["normal"]
}); });
self2.state.fontWeight = "normal"; self.state.fontWeight = "normal";
} }
} }
get font() { get font() {
...@@ -5978,7 +5764,7 @@ function stringifyQuery(url, data) { ...@@ -5978,7 +5764,7 @@ function stringifyQuery(url, data) {
let v2 = data[key]; let v2 = data[key];
if (typeof v2 === "undefined" || v2 === null) { if (typeof v2 === "undefined" || v2 === null) {
v2 = ""; v2 = "";
} else if (isPlainObject$1(v2)) { } else if (isPlainObject(v2)) {
v2 = JSON.stringify(v2); v2 = JSON.stringify(v2);
} }
params[encode(key)] = encode(v2); params[encode(key)] = encode(v2);
...@@ -6011,7 +5797,7 @@ const RequestOptions = { ...@@ -6011,7 +5797,7 @@ const RequestOptions = {
params.data = value || ""; params.data = value || "";
}, },
url(value, params) { url(value, params) {
if (params.method === HTTP_METHODS[0] && isPlainObject$1(params.data) && Object.keys(params.data).length) { if (params.method === HTTP_METHODS[0] && isPlainObject(params.data) && Object.keys(params.data).length) {
params.url = stringifyQuery(value, params.data); params.url = stringifyQuery(value, params.data);
} }
}, },
...@@ -13388,7 +13174,7 @@ function processClickEvent(node, triggerItemClick) { ...@@ -13388,7 +13174,7 @@ function processClickEvent(node, triggerItemClick) {
} }
} }
function normalizeAttrs(tagName, attrs2) { function normalizeAttrs(tagName, attrs2) {
if (!isPlainObject$1(attrs2)) if (!isPlainObject(attrs2))
return; return;
for (const key in attrs2) { for (const key in attrs2) {
if (hasOwn(attrs2, key)) { if (hasOwn(attrs2, key)) {
...@@ -13402,7 +13188,7 @@ const nodeList2VNode = (scopeId, triggerItemClick, nodeList) => { ...@@ -13402,7 +13188,7 @@ const nodeList2VNode = (scopeId, triggerItemClick, nodeList) => {
if (!nodeList || isArray(nodeList) && !nodeList.length) if (!nodeList || isArray(nodeList) && !nodeList.length)
return []; return [];
return nodeList.map((node) => { return nodeList.map((node) => {
if (!isPlainObject$1(node)) { if (!isPlainObject(node)) {
return; return;
} }
if (!hasOwn(node, "type") || node.type === "node") { if (!hasOwn(node, "type") || node.type === "node") {
...@@ -17370,7 +17156,7 @@ function onResize() { ...@@ -17370,7 +17156,7 @@ function onResize() {
}); });
} }
function onMessage(evt) { function onMessage(evt) {
if (isPlainObject$1(evt.data) && evt.data.type === WEB_INVOKE_APPSERVICE) { if (isPlainObject(evt.data) && evt.data.type === WEB_INVOKE_APPSERVICE) {
UniServiceJSBridge.emit( UniServiceJSBridge.emit(
ON_WEB_INVOKE_APP_SERVICE, ON_WEB_INVOKE_APP_SERVICE,
evt.data.data, evt.data.data,
...@@ -26200,27 +25986,6 @@ function createPageBodyVNode(ctx) { ...@@ -26200,27 +25986,6 @@ function createPageBodyVNode(ctx) {
} }
); );
} }
function getGlobal() {
if (typeof globalThis !== "undefined") {
return globalThis;
}
if (typeof self !== "undefined") {
return self;
}
if (typeof window !== "undefined") {
return window;
}
if (typeof window !== "undefined") {
return window;
}
throw new Error("unable to locate window object");
}
const realGlobal = getGlobal();
if (!realGlobal.globalThis) {
realGlobal.globalThis = realGlobal;
}
globalThis.UTSJSONObject = UTSJSONObject;
globalThis.UniError = UniError;
export { export {
$emit, $emit,
$off, $off,
......
import path from 'path' import path from 'path'
import { extend, isArray, isFunction } from '@vue/shared' import { extend, isFunction } from '@vue/shared'
import type { RPT2Options } from 'rollup-plugin-typescript2' import type { RPT2Options } from 'rollup-plugin-typescript2'
import { isInHBuilderX } from '../../shared' import { isInHBuilderX } from '../../shared'
interface UTS2JavaScriptOptions extends Omit<RPT2Options, 'transformers'> { interface UTS2JavaScriptOptions extends Omit<RPT2Options, 'transformers'> {
...@@ -85,14 +85,5 @@ export const uts2js: uts2js = (options) => { ...@@ -85,14 +85,5 @@ export const uts2js: uts2js = (options) => {
// @ts-expect-error // @ts-expect-error
return globalThis.uts2js(options) return globalThis.uts2js(options)
} }
const plugins = require('../../../lib/javascript').uts2js(options) return require('../../../lib/javascript').uts2js(options)
if (isArray(plugins)) {
plugins.forEach((p) => {
if (p.name === 'uts') {
// 强制放到 auto import 之后执行
p.enforce = 'post'
}
})
}
return plugins
} }
...@@ -18,7 +18,7 @@ import { ...@@ -18,7 +18,7 @@ import {
initPreContext, initPreContext,
parseUniExtApis, parseUniExtApis,
resolveSourceMapPath, resolveSourceMapPath,
uniUTSExtApiReplace, uniUTSExtApi,
uniViteInjectPlugin, uniViteInjectPlugin,
} from '@dcloudio/uni-cli-shared' } from '@dcloudio/uni-cli-shared'
...@@ -130,9 +130,9 @@ export default function uniPlugin( ...@@ -130,9 +130,9 @@ export default function uniPlugin(
function createPlugins(options: VitePluginUniResolvedOptions) { function createPlugins(options: VitePluginUniResolvedOptions) {
const plugins: Plugin[] = [] const plugins: Plugin[] = []
// uni x 调整了,由 uniUTSExtApiReplace 实现 uni.getBatteryInfo => uni_getBatterInfo,然后交由 auto import 处理 // uni x 需要插入到指定位置,此插件执行太早,又会引发 vue 文件的不支持,该插件是解析ast的,所以必须是合法的js或ts代码
if (process.env.UNI_APP_X === 'true') { if (process.env.UNI_APP_X === 'true') {
plugins.push(uniUTSExtApiReplace()) plugins.push(uniUTSExtApi())
} else { } else {
const injects = parseUniExtApis( const injects = parseUniExtApis(
true, true,
......
此差异已折叠。
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册