提交 8b87da13 编写于 作者: fxy060608's avatar fxy060608

chore(types): @dcloudio/uni-platform

上级 c3742945
......@@ -16,7 +16,7 @@ function checkDeviceWidth() {
const { platform, pixelRatio, windowWidth } = getBaseSystemInfo()
deviceWidth = windowWidth as number
deviceDPR = pixelRatio as number
isIOS = platform === 'ios'
isIOS = (platform as string) === 'ios'
}
function checkValue(value: unknown, defaultValue: number) {
......
......@@ -458,7 +458,7 @@ export class CanvasContext implements UniApp.CanvasContext {
.find((webview) => webview.getURL().endsWith('www/__uniappview.html'))
if (webview) {
width = Number(
webview.evalJSSync(
(webview as any).evalJSSync(
`(${measureText.toString()})(${JSON.stringify(
text
)},${JSON.stringify(font)})`
......
......@@ -6,15 +6,23 @@ import { EditorContext } from '../context/editor'
import { MapContext } from '../context/createMapContext'
import { VideoContext } from '../context/createVideoContext'
import { requestComponentInfo } from '@dcloudio/uni-platform'
import { getContextInfo } from '@dcloudio/uni-components'
type NodeField = UniApp.NodeField
type ContextType = 'canvas' | 'map' | 'video' | 'editor'
interface NodeInfo extends UniApp.NodeInfo {
contextInfo?: {
id: string
type: ContextType
page: number
}
export interface SelectorQueryNodeInfo
extends UniApp.NodeInfo,
Omit<
Partial<Record<keyof CSSStyleDeclaration, any>>,
'top' | 'bottom' | 'left' | 'right' | 'height' | 'width'
> {
contextInfo?: ReturnType<typeof getContextInfo>
}
export interface SelectorQueryRequest {
component: ComponentPublicInstance | undefined | null
selector: string
single: boolean
fields: NodeField
}
const ContextClasss = {
......@@ -24,9 +32,9 @@ const ContextClasss = {
editor: EditorContext,
}
function convertContext(result: NodeInfo | null) {
function convertContext(result: SelectorQueryNodeInfo | null) {
if (result && result.contextInfo) {
const { id, type, page } = (result as NodeInfo).contextInfo!
const { id, type, page } = (result as SelectorQueryNodeInfo).contextInfo!
const ContextClass = ContextClasss[type]
result.context = new ContextClass(id, page)
delete result.contextInfo
......@@ -50,7 +58,7 @@ class NodesRef implements UniApp.NodesRef {
this._single = single
}
boundingClientRect(callback: (result: NodeInfo) => void) {
boundingClientRect(callback: (result: SelectorQueryNodeInfo) => void) {
this._selectorQuery._push(
this._selector,
this._component,
......@@ -66,7 +74,7 @@ class NodesRef implements UniApp.NodesRef {
return this._selectorQuery
}
fields(fields: NodeField, callback: (result: NodeInfo) => void) {
fields(fields: NodeField, callback: (result: SelectorQueryNodeInfo) => void) {
this._selectorQuery._push(
this._selector,
this._component,
......@@ -77,7 +85,7 @@ class NodesRef implements UniApp.NodesRef {
return this._selectorQuery
}
scrollOffset(callback: (result: NodeInfo) => void) {
scrollOffset(callback: (result: SelectorQueryNodeInfo) => void) {
this._selectorQuery._push(
this._selector,
this._component,
......@@ -92,7 +100,7 @@ class NodesRef implements UniApp.NodesRef {
return this._selectorQuery
}
context(callback: (result: NodeInfo) => void) {
context(callback: (result: SelectorQueryNodeInfo) => void) {
this._selectorQuery._push(
this._selector,
this._component,
......@@ -108,12 +116,7 @@ class NodesRef implements UniApp.NodesRef {
class SelectorQuery implements UniApp.SelectorQuery {
private _page: ComponentPublicInstance
private _queue: Array<{
component: ComponentPublicInstance | undefined | null
selector: string
single: boolean
fields: NodeField
}>
private _queue: Array<SelectorQueryRequest>
private _component?: ComponentPublicInstance = undefined
private _queueCb: any[]
private _nodesRef?: NodesRef
......@@ -127,7 +130,7 @@ class SelectorQuery implements UniApp.SelectorQuery {
requestComponentInfo(
this._page,
this._queue,
(res: Array<NodeInfo | null>) => {
(res: Array<SelectorQueryNodeInfo | null>) => {
const queueCbs = this._queueCb
res.forEach((result, index) => {
if (Array.isArray(result)) {
......@@ -182,7 +185,7 @@ class SelectorQuery implements UniApp.SelectorQuery {
component: ComponentPublicInstance | undefined | null,
single: boolean,
fields: NodeField,
callback: (result: NodeInfo) => void
callback: (result: SelectorQueryNodeInfo) => void
) {
this._queue.push({
component,
......
......@@ -5,7 +5,7 @@
"output": {
"name": "serviceContext",
"format": "iife",
"banner": "export function createServiceContext(Vue, weex, plus, UniServiceJSBridge,instanceContext){\nconst setTimeout = instanceContext.setTimeout;\nconst clearTimeout = instanceContext.clearTimeout;\nconst setInterval = instanceContext.setInterval;\nconst clearInterval = instanceContext.clearInterval;\nconst __uniConfig = instanceContext.__uniConfig;\nconst __uniRoutes = instanceContext.__uniRoutes;\n",
"banner": "export function createServiceContext(Vue, weex, plus,instanceContext){\nconst setTimeout = instanceContext.setTimeout;\nconst clearTimeout = instanceContext.clearTimeout;\nconst setInterval = instanceContext.setInterval;\nconst clearInterval = instanceContext.clearInterval;\nconst __uniConfig = instanceContext.__uniConfig;\nconst __uniRoutes = instanceContext.__uniRoutes;\n",
"footer": "const uni = serviceContext.uni;\nconst getApp = serviceContext.getApp;\nconst getCurrentPages = serviceContext.getCurrentPages;\nconst __definePage = serviceContext.__definePage;\nconst __registerPage = serviceContext.__registerPage;\nreturn serviceContext;\n}"
},
"external": false
......
......@@ -17,6 +17,7 @@
"url": "https://github.com/dcloudio/uni-app/issues"
},
"dependencies": {
"@webcomponents/custom-elements": "^1.4.3",
"vue3-webcomponent-wrapper": "^0.1.4"
},
"gitHead": "56deaeb47d42e924d10282d7af418ccee6b139bf"
......
import { ComponentPublicInstance } from 'vue'
import {
AddIntersectionObserverArgs,
AddMediaQueryObserverArgs,
RemoveIntersectionObserverArgs,
RemoveMediaQueryObserverArgs,
SelectorQueryNodeInfo,
SelectorQueryRequest,
} from '@dcloudio/uni-api'
export function getBaseSystemInfo() {
return {}
// TODO
return {
platform: '',
pixelRatio: 1,
windowWidth: 750,
}
}
export { getRealPath } from './getRealPath'
export function operateVideoPlayer() {}
export function operateMap() {}
export function requestComponentInfo() {}
export function addIntersectionObserver() {}
export function removeIntersectionObserver() {}
export function addMediaQueryObserver() {}
export function removeMediaQueryObserver() {}
export function saveImage() {}
export function getSameOriginUrl() {}
export function operateVideoPlayer(
videoId: string,
pageId: number,
type: string,
data?: unknown
) {}
export function operateMap(
id: string,
pageId: number,
type: string,
data?: unknown
) {}
export function requestComponentInfo(
page: ComponentPublicInstance,
reqs: Array<SelectorQueryRequest>,
callback: (result: Array<SelectorQueryNodeInfo | null>) => void
) {}
export function addIntersectionObserver(
args: AddIntersectionObserverArgs,
pageId: number
) {}
export function removeIntersectionObserver(
args: RemoveIntersectionObserverArgs,
pageId: number
) {}
export function addMediaQueryObserver(
args: AddMediaQueryObserverArgs,
pageId: number
) {}
export function removeMediaQueryObserver(
args: RemoveMediaQueryObserverArgs,
pageId: number
) {}
export function saveImage(
base64: string,
dirname: string,
callback: (error: Error | null, tempFilePath: string) => void
) {}
export function getSameOriginUrl(url: string): Promise<string> {
return Promise.resolve(url)
}
export const TEMP_PATH = ''
import { extend } from '@vue/shared'
import { getRealPath } from '@dcloudio/uni-platform'
import {
API_CREATE_INNER_AUDIO_CONTEXT,
defineSyncApi,
......@@ -12,6 +11,8 @@ import {
innerAudioContextOffEventNames,
} from '@dcloudio/uni-api'
import { getRealPath } from '../../../platform/getRealPath'
type ExtendAudio = {
src?: string
volume?: number
......
......@@ -5,7 +5,7 @@ import {
API_TYPE_GET_BACKGROUND_AUDIO_MANAGER,
} from '@dcloudio/uni-api'
import { once } from '@dcloudio/uni-shared'
import { getRealPath } from '@dcloudio/uni-platform'
import { getRealPath } from '../../../platform/getRealPath'
type eventNames =
| 'canplay'
......
......@@ -6,7 +6,7 @@ import {
OpenDocumentOptions,
} from '@dcloudio/uni-api'
import { getRealPath } from '@dcloudio/uni-platform'
import { getRealPath } from '../../../platform/getRealPath'
export const openDocument = defineAsyncApi<API_TYPE_OPEN_DOCUMENT>(
API_OPEN_DOCUMENT,
({ filePath, fileType }, { resolve, reject }) => {
......
......@@ -6,12 +6,12 @@ import {
PreviewImageOptions,
} from '@dcloudio/uni-api'
import { getRealPath } from '@dcloudio/uni-platform'
import { isPlainObject } from '@vue/shared'
import { initI18nChooseImageMsgsOnce, useI18n } from '@dcloudio/uni-core'
import { getRealPath } from '../../../platform/getRealPath'
export const previewImage = <API_TYPE_PREVIEW_IMAGE>defineAsyncApi(
API_PREVIEW_IMAGE,
(
......
import * as uni from './api'
import { registerApp as __registerApp } from './framework/app'
import { registerPage as __registerPage } from './framework/page'
// ;(uni as any).__$wx__ = uni
export default {
uni,
__registerApp,
__registerPage,
}
import { initView } from '@dcloudio/uni-core'
import '@webcomponents/custom-elements'
import './components'
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"paths": {
"@dcloudio/*": ["packages/*/src"],
"@dcloudio/uni-platform": ["packages/uni-app-plus/src/platform/index.ts"]
}
}
}
......@@ -47,6 +47,10 @@ export default defineConfig({
},
resolve: {
alias: [
{
find: 'vue',
replacement: resolve('../uni-app-vue/dist/view.runtime.esm.js'),
},
{
find: '@dcloudio/uni-api',
replacement: resolve('../uni-api/src/index.ts'),
......@@ -88,21 +92,21 @@ export default defineConfig({
lib: {
name: 'uni-app-view',
fileName: 'uni-app-view',
entry: path.resolve(__dirname, 'src/view/components/index.ts'),
entry: path.resolve(__dirname, 'src/view/index.ts'),
formats: ['umd'],
},
assetsDir: '.',
rollupOptions: {
output: {
globals: {
vue: 'Vue',
},
},
external(source) {
if (['vue'].includes(source)) {
return true
}
},
// output: {
// globals: {
// vue: 'Vue',
// },
// },
// external(source) {
// if (['vue'].includes(source)) {
// return true
// }
// },
preserveEntrySignatures: 'strict',
plugins: rollupPlugins,
onwarn: (msg, warn) => {
......
{
"input": {
"src/index.ts": ["dist/vue.runtime.esm.js"]
[
{
"input": {
"src/service/index.ts": ["dist/service.runtime.esm.js"]
},
"output": {
"banner": "export default function vueFactory (exports) {\n",
"footer": "}"
},
"external": false
},
"output": {
"banner": "export default function vueFactory (exports) {\n",
"footer": "}"
},
"external": false
}
{
"input": {
"src/view/index.ts": ["dist/view.runtime.esm.js"]
},
"external": false
}
]
此差异已折叠。
此差异已折叠。
import * as Vue from '../lib/vue.runtime.esm'
exports.Vue = Vue
import * as Vue from '../../lib/service.runtime.esm'
exports.Vue = Vue
export * from '../../lib/view.runtime.esm'
......@@ -20,7 +20,7 @@ function addBase(filePath: string) {
export function getRealPath(filePath: string) {
// 相对路径模式对静态资源路径特殊处理
if (__uniConfig.router.base === './') {
if (__uniConfig.router!.base === './') {
filePath = filePath.replace(/^\.\/static\//, '/static/')
}
if (filePath.indexOf('/') === 0) {
......
......@@ -2,27 +2,12 @@ import { ComponentPublicInstance } from 'vue'
import { getCustomDataset } from '@dcloudio/uni-shared'
import { getWindowOffset } from '@dcloudio/uni-core'
import { getContextInfo } from '@dcloudio/uni-components'
import { SelectorQueryNodeInfo, SelectorQueryRequest } from '@dcloudio/uni-api'
type NodeField = UniApp.NodeField
interface NodeInfo
extends UniApp.NodeInfo,
Omit<
Partial<Record<keyof CSSStyleDeclaration, any>>,
'top' | 'bottom' | 'left' | 'right' | 'height' | 'width'
> {
contextInfo?: ReturnType<typeof getContextInfo>
}
export interface Request {
component: ComponentPublicInstance | undefined | null
selector: string
single: boolean
fields: NodeField
}
function getRootInfo(fields: NodeField) {
const info: NodeInfo = {}
const info: SelectorQueryNodeInfo = {}
if (fields.id) {
info.id = ''
}
......@@ -50,8 +35,11 @@ function getRootInfo(fields: NodeField) {
return info
}
function getNodeInfo(el: HTMLElement, fields: NodeField): NodeInfo {
const info: NodeInfo = {}
function getNodeInfo(
el: HTMLElement,
fields: NodeField
): SelectorQueryNodeInfo {
const info: SelectorQueryNodeInfo = {}
const { top } = getWindowOffset()
if (fields.id) {
info.id = el.id
......@@ -121,7 +109,7 @@ function getNodesInfo(
selector: string,
single: boolean,
fields: NodeField
): NodeInfo | NodeInfo[] | null {
): SelectorQueryNodeInfo | SelectorQueryNodeInfo[] | null {
const parentElement = findElm(component, pageVm).parentElement
if (!parentElement) {
return single ? null : []
......@@ -133,7 +121,7 @@ function getNodesInfo(
}
return null
} else {
let infos: NodeInfo[] = []
let infos: SelectorQueryNodeInfo[] = []
const nodeList = parentElement.querySelectorAll(selector)
if (nodeList && nodeList.length) {
;[].forEach.call(nodeList, (node) => {
......@@ -146,10 +134,10 @@ function getNodesInfo(
export function requestComponentInfo(
page: ComponentPublicInstance,
reqs: Array<Request>,
callback: (result: Array<NodeInfo | null>) => void
reqs: Array<SelectorQueryRequest>,
callback: (result: Array<SelectorQueryNodeInfo | null>) => void
) {
const result: Array<NodeInfo | null> = []
const result: Array<SelectorQueryNodeInfo | null> = []
reqs.forEach(({ component, selector, single, fields }) => {
if (component === null) {
result.push(getRootInfo(fields))
......
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"paths": {
"@dcloudio/*": ["packages/*/src"],
"@dcloudio/uni-platform": ["packages/uni-h5/src/platform/index.ts"]
}
}
}
......@@ -12,7 +12,8 @@
"resolveJsonModule": true,
"esModuleInterop": true,
"removeComments": false,
"lib": ["ESNext", "DOM"]
"lib": ["ESNext", "DOM"],
"types": ["node", "@dcloudio/types"]
},
"include": ["src"]
}
import { isArray, hasOwn, isString, isPlainObject, isObject, capitalize, toRawType, makeMap, isFunction, isPromise, extend } from '@vue/shared';
function getBaseSystemInfo() {
return my.getSystemInfoSync()
}
function validateProtocolFail(name, msg) {
console.warn(`${name}: ${msg}`);
}
......@@ -200,10 +204,6 @@ function defineSyncApi(name, fn, protocol, options) {
return wrapperSyncApi(name, fn, (process.env.NODE_ENV !== 'production') ? protocol : undefined, options);
}
function getBaseSystemInfo() {
return my.getSystemInfoSync()
}
const API_UPX2PX = 'upx2px';
const Upx2pxProtocol = [
{
......
export * from '@dcloudio/uni-mp-platform'
export function getBaseSystemInfo() {
return my.getSystemInfoSync()
}
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"paths": {
"@dcloudio/*": ["packages/*/src"],
"@dcloudio/uni-platform": [
"packages/uni-mp-alipay/src/platform/index.ts"
],
"@dcloudio/uni-mp-polyfill": ["packages/uni-mp-core/src/runtime/polyfill"]
}
}
}
import { isArray, hasOwn, isString, isPlainObject, isObject, capitalize, toRawType, makeMap, isFunction, isPromise, extend } from '@vue/shared';
function getBaseSystemInfo() {
return swan.getSystemInfoSync()
}
function validateProtocolFail(name, msg) {
console.warn(`${name}: ${msg}`);
}
......@@ -200,10 +204,6 @@ function defineSyncApi(name, fn, protocol, options) {
return wrapperSyncApi(name, fn, (process.env.NODE_ENV !== 'production') ? protocol : undefined, options);
}
function getBaseSystemInfo() {
return swan.getSystemInfoSync()
}
const API_UPX2PX = 'upx2px';
const Upx2pxProtocol = [
{
......
export * from '@dcloudio/uni-mp-platform'
export function getBaseSystemInfo() {
return swan.getSystemInfoSync()
}
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"paths": {
"@dcloudio/*": ["packages/*/src"],
"@dcloudio/uni-platform": ["packages/uni-mp-baidu/src/platform/index.ts"],
"@dcloudio/uni-mp-polyfill": ["packages/uni-mp-core/src/runtime/polyfill"]
}
}
}
import { hasOwn } from '@vue/shared'
import { upx2px, addInterceptor, removeInterceptor } from '@dcloudio/uni-api'
import { upx2px } from '@dcloudio/uni-api/src/service/base/upx2px'
import {
addInterceptor,
removeInterceptor,
} from '@dcloudio/uni-api/src/service/base/interceptor'
import { promisify } from './promise'
import { initWrapper } from './wrapper'
......
import { extend, isFunction } from '@vue/shared'
import { invokeApi, handlePromise, wrapperReturnValue } from '@dcloudio/uni-api'
import { handlePromise } from '@dcloudio/uni-api/src/helpers/api/promise'
import {
invokeApi,
wrapperReturnValue,
} from '@dcloudio/uni-api/src/helpers/interceptor'
const SYNC_API_RE =
/^\$|sendNativeEvent|restoreGlobal|getCurrentSubNVue|getMenuButtonBoundingClientRect|^report|interceptors|Interceptor$|getSubNVueById|requireNativePlugin|upx2px|hideKeyboard|canIUse|^create|Sync$|Manager$|base64ToArrayBuffer|arrayBufferToBase64/
......
export function getRealPath() {}
export function operateVideoPlayer() {}
export function operateMap() {}
export function requestComponentInfo() {}
export function addIntersectionObserver() {}
export function removeIntersectionObserver() {}
export function addMediaQueryObserver() {}
export function removeMediaQueryObserver() {}
export function saveImage() {}
export function getSameOriginUrl() {}
export const TEMP_PATH = ''
import { isArray, hasOwn, isString, isPlainObject, isObject, capitalize, toRawType, makeMap, isFunction, isPromise, extend } from '@vue/shared';
function getBaseSystemInfo() {
return qq.getSystemInfoSync()
}
function validateProtocolFail(name, msg) {
console.warn(`${name}: ${msg}`);
}
......@@ -200,10 +204,6 @@ function defineSyncApi(name, fn, protocol, options) {
return wrapperSyncApi(name, fn, (process.env.NODE_ENV !== 'production') ? protocol : undefined, options);
}
function getBaseSystemInfo() {
return qq.getSystemInfoSync()
}
const API_UPX2PX = 'upx2px';
const Upx2pxProtocol = [
{
......
export * from '@dcloudio/uni-mp-platform'
export function getBaseSystemInfo() {
return qq.getSystemInfoSync()
}
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"paths": {
"@dcloudio/*": ["packages/*/src"],
"@dcloudio/uni-platform": ["packages/uni-mp-qq/src/platform/index.ts"],
"@dcloudio/uni-mp-polyfill": ["packages/uni-mp-core/src/runtime/polyfill"]
}
}
}
import { isArray, hasOwn, isString, isPlainObject, isObject, capitalize, toRawType, makeMap, isFunction, isPromise, extend } from '@vue/shared';
function getBaseSystemInfo() {
return tt.getSystemInfoSync()
}
function validateProtocolFail(name, msg) {
console.warn(`${name}: ${msg}`);
}
......@@ -200,10 +204,6 @@ function defineSyncApi(name, fn, protocol, options) {
return wrapperSyncApi(name, fn, (process.env.NODE_ENV !== 'production') ? protocol : undefined, options);
}
function getBaseSystemInfo() {
return tt.getSystemInfoSync()
}
const API_UPX2PX = 'upx2px';
const Upx2pxProtocol = [
{
......
export * from '@dcloudio/uni-mp-platform'
export function getBaseSystemInfo() {
return tt.getSystemInfoSync()
}
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"paths": {
"@dcloudio/*": ["packages/*/src"],
"@dcloudio/uni-platform": [
"packages/uni-mp-toutiao/src/platform/index.ts"
],
"@dcloudio/uni-mp-polyfill": ["packages/uni-mp-core/src/runtime/polyfill"]
}
}
}
import { isArray, hasOwn, isString, isPlainObject, isObject, capitalize, toRawType, makeMap, isFunction, isPromise, extend } from '@vue/shared';
function getBaseSystemInfo() {
return wx.getSystemInfoSync()
}
function validateProtocolFail(name, msg) {
console.warn(`${name}: ${msg}`);
}
......@@ -200,10 +204,6 @@ function defineSyncApi(name, fn, protocol, options) {
return wrapperSyncApi(name, fn, (process.env.NODE_ENV !== 'production') ? protocol : undefined, options);
}
function getBaseSystemInfo() {
return wx.getSystemInfoSync()
}
const API_UPX2PX = 'upx2px';
const Upx2pxProtocol = [
{
......
export * from '@dcloudio/uni-mp-platform'
export function getBaseSystemInfo() {
return wx.getSystemInfoSync()
}
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"paths": {
"@dcloudio/*": ["packages/*/src"],
"@dcloudio/uni-platform": [
"packages/uni-mp-weixin/src/platform/index.ts"
],
"@dcloudio/uni-mp-polyfill": ["packages/uni-mp-core/src/runtime/polyfill"]
}
}
}
import { isArray, hasOwn, isString, isPlainObject, isObject, capitalize, toRawType, makeMap, isFunction, isPromise, extend } from '@vue/shared';
function getBaseSystemInfo() {
return qa.getSystemInfoSync()
}
function validateProtocolFail(name, msg) {
console.warn(`${name}: ${msg}`);
}
......@@ -200,10 +204,6 @@ function defineSyncApi(name, fn, protocol, options) {
return wrapperSyncApi(name, fn, (process.env.NODE_ENV !== 'production') ? protocol : undefined, options);
}
function getBaseSystemInfo() {
return qa.getSystemInfoSync()
}
const API_UPX2PX = 'upx2px';
const Upx2pxProtocol = [
{
......
export * from '@dcloudio/uni-mp-platform'
export function getBaseSystemInfo() {
return qa.getSystemInfoSync()
}
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"paths": {
"@dcloudio/*": ["packages/*/src"],
"@dcloudio/uni-platform": [
"packages/uni-quickapp-webview/src/platform/index.ts"
],
"@dcloudio/uni-mp-polyfill": ["packages/uni-mp-core/src/runtime/polyfill"]
}
}
}
......@@ -2,6 +2,8 @@
"compilerOptions": {
"outDir": "dist",
"sourceMap": false,
"declaration": true,
"declarationDir": "./dist/packages/uni-shared/src",
"target": "esnext",
"module": "esnext",
"moduleResolution": "node",
......
......@@ -41,7 +41,7 @@
"@types/sass": "^1.16.0"
},
"uni-app": {
"compilerVersion": "3.1.2"
"compilerVersion": "3.1.21"
},
"gitHead": "56deaeb47d42e924d10282d7af418ccee6b139bf"
}
import fs from 'fs'
import path from 'path'
import ts from 'rollup-plugin-typescript2'
import replace from '@rollup/plugin-replace'
......@@ -19,7 +20,8 @@ const pkg = require(resolve(`package.json`))
let hasTSChecked = false
const configs = []
const buildOptions = require(resolve(`build.json`))
let buildOptions = require(resolve(`build.json`))
function normalizeOutput(file, output = {}) {
return Object.assign(
......@@ -32,40 +34,64 @@ function normalizeOutput(file, output = {}) {
)
}
Object.keys(buildOptions.input).forEach((name) => {
const files = buildOptions.input[name]
if (Array.isArray(files)) {
files.forEach((file) => {
if (!Array.isArray(buildOptions)) {
buildOptions = [buildOptions]
}
buildOptions.forEach((buildOption) => {
Object.keys(buildOption.input).forEach((name) => {
const files = buildOption.input[name]
if (Array.isArray(files)) {
files.forEach((file) => {
configs.push(
createConfig(
name,
normalizeOutput(resolve(file), buildOption.output),
buildOption
)
)
})
} else {
configs.push(
createConfig(name, normalizeOutput(resolve(file), buildOptions.output))
)
})
} else {
configs.push(
createConfig(
name,
normalizeOutput(resolve(buildOptions.input[name]), buildOptions.output)
createConfig(
name,
normalizeOutput(resolve(buildOption.input[name]), buildOption.output),
buildOption
)
)
)
}
}
})
})
export default configs
function createConfig(entryFile, output, plugins = []) {
function resolveTsconfigJson() {
const tsconfigJsonPath = resolve('tsconfig.json')
if (
fs.existsSync(tsconfigJsonPath)
// &&
// require(tsconfigJsonPath).extends === '../../tsconfig.json'
) {
return tsconfigJsonPath
}
return path.resolve(__dirname, 'tsconfig.json')
}
function createConfig(entryFile, output, buildOption) {
const shouldEmitDeclarations = process.env.TYPES != null && !hasTSChecked
const tsPlugin = ts({
check:
!process.env.CI && process.env.NODE_ENV === 'production' && !hasTSChecked,
tsconfig: path.resolve(__dirname, 'tsconfig.json'),
tsconfig: resolveTsconfigJson(),
cacheRoot: path.resolve(__dirname, 'node_modules/.rts2_cache'),
tsconfigOverride: {
compilerOptions: {
sourceMap: output.sourcemap,
declaration: shouldEmitDeclarations,
declarationMap: shouldEmitDeclarations,
declarationMap: false,
},
exclude: ['**/__tests__', 'test-dts'],
},
useTsconfigDeclarationDir: true,
})
// we only need to check TS and generate declarations once for each build.
......@@ -74,29 +100,28 @@ function createConfig(entryFile, output, plugins = []) {
hasTSChecked = true
const external =
buildOptions.external === false
buildOption.external === false
? []
: [
'vue',
'@vue/shared',
...Object.keys(pkg.dependencies || {}),
...Object.keys(pkg.peerDependencies || {}),
...(buildOptions.external || []),
...(buildOption.external || []),
]
return {
input: resolve(entryFile),
external,
plugins: [
createAliasPlugin(buildOptions),
createAliasPlugin(buildOption),
nodeResolve(),
commonjs(),
json({
namedExports: false,
}),
tsPlugin,
createReplacePlugin(buildOptions, output.format),
...plugins,
createReplacePlugin(buildOption, output.format),
],
output,
onwarn: (msg, warn) => {
......@@ -105,7 +130,7 @@ function createConfig(entryFile, output, plugins = []) {
// }
},
treeshake:
buildOptions.treeshake === false
buildOption.treeshake === false
? false
: {
moduleSideEffects(id) {
......@@ -119,11 +144,11 @@ function createConfig(entryFile, output, plugins = []) {
}
}
function createAliasPlugin(buildOptions) {
return alias(buildOptions.alias || {})
function createAliasPlugin(buildOption) {
return alias(buildOption.alias || {})
}
function createReplacePlugin(buildOptions, format) {
function createReplacePlugin(buildOption, format) {
const replacements = {
global: format === 'cjs' ? 'global' : 'window',
__DEV__: `(process.env.NODE_ENV !== 'production')`,
......@@ -131,8 +156,8 @@ function createReplacePlugin(buildOptions, format) {
__PLATFORM__: JSON.stringify('h5'),
__NODE_JS__: format === 'cjs',
}
if (buildOptions.replacements) {
Object.assign(replacements, buildOptions.replacements)
if (buildOption.replacements) {
Object.assign(replacements, buildOption.replacements)
}
Object.keys(replacements).forEach((key) => {
......
......@@ -28,13 +28,7 @@
"rootDir": ".",
"paths": {
"@dcloudio/*": ["packages/*/src"],
"@dcloudio/uni-mp-polyfill": [
"packages/uni-mp-core/src/runtime/polyfill"
],
"@dcloudio/uni-platform": ["packages/uni-h5/src/platform/index.ts"],
"@dcloudio/uni-mp-platform": [
"packages/uni-mp-core/src/platform/index.ts"
]
"@dcloudio/uni-platform": ["packages/uni-h5/src/platform/index.ts"]
}
},
"include": [
......
......@@ -359,8 +359,8 @@
"@dcloudio/types@^2.2.15":
version "2.2.15"
resolved "https://registry.nlark.com/@dcloudio/types/download/@dcloudio/types-2.2.15.tgz?cache=0&sync_timestamp=1624605648994&other_urls=https%3A%2F%2Fregistry.nlark.com%2F%40dcloudio%2Ftypes%2Fdownload%2F%40dcloudio%2Ftypes-2.2.15.tgz#8e0cec74ba7880816a57d9c3315f18a4e6fc79ed"
integrity sha1-jgzsdLp4gIFqV9nDMV8YpOb8ee0=
resolved "https://registry.yarnpkg.com/@dcloudio/types/-/types-2.2.15.tgz#8e0cec74ba7880816a57d9c3315f18a4e6fc79ed"
integrity sha512-o0V2cyCDoFKpog380FJ1U7lPo3JGg1L8DOL6m60Z8H0+ufA1S/fzUp5gJYX6YwjJawV1F/TW9L8VfDSxVyC4TA==
"@eslint/eslintrc@^0.4.2":
version "0.4.2"
......@@ -1404,10 +1404,10 @@
"@octokit/types" "^6.0.3"
universal-user-agent "^6.0.0"
"@octokit/openapi-types@^7.3.3":
version "7.3.3"
resolved "https://registry.yarnpkg.com/@octokit/openapi-types/-/openapi-types-7.3.3.tgz#a7ab7bd16cea040b836521a5afaf08fa36085e5f"
integrity sha512-/tpvcWCjYUHtvdc/t/bX6pxaOoeYPhfPCyvUaSWP29YkRcdZmlhRaMsXudZhvXm8GBPBxmCOsf1Ye/FpkszOHw==
"@octokit/openapi-types@^7.3.4":
version "7.3.4"
resolved "https://registry.yarnpkg.com/@octokit/openapi-types/-/openapi-types-7.3.4.tgz#9f075e263d1d3c1ba7a789e0085a5ed75d6daad1"
integrity sha512-binmLrMQWBG0CvUE/jS3/XXrZbX3oN/6gF7ocSsb/ZJ0xfox2isJN4ZhGeL91SDJVzFK7XuUYBm2mlIDedkxsg==
"@octokit/plugin-enterprise-rest@^6.0.1":
version "6.0.1"
......@@ -1426,12 +1426,12 @@
resolved "https://registry.yarnpkg.com/@octokit/plugin-request-log/-/plugin-request-log-1.0.4.tgz#5e50ed7083a613816b1e4a28aeec5fb7f1462e85"
integrity sha512-mLUsMkgP7K/cnFEw07kWqXGF5LKrOkD+lhCrKvPHXWDywAwuDUeDwWBpc69XK3pNX0uKiVt8g5z96PJ6z9xCFA==
"@octokit/plugin-rest-endpoint-methods@5.3.2":
version "5.3.2"
resolved "https://registry.yarnpkg.com/@octokit/plugin-rest-endpoint-methods/-/plugin-rest-endpoint-methods-5.3.2.tgz#4426a06aca230df17e40a332dcbc348779d99569"
integrity sha512-vwsdLUC4TUohbHAqD0f/BjUw/kfKmNs1f0+Fkldzr7GKqMXjNku5U0jzZCmVUI6GcH7b/KcXd9WtbpVpofDehQ==
"@octokit/plugin-rest-endpoint-methods@5.3.3":
version "5.3.3"
resolved "https://registry.yarnpkg.com/@octokit/plugin-rest-endpoint-methods/-/plugin-rest-endpoint-methods-5.3.3.tgz#b447ed80126d36a9cf99daabb055bf0c157c8d89"
integrity sha512-xHlZK9gxVFP2YQYXOmR1ItCwl9k+0Z3cA40oGMQfpPbWIYY32FTM15Qj+V0V6oLJZr0E26Sz3VX6qYlM/ytfig==
dependencies:
"@octokit/types" "^6.16.5"
"@octokit/types" "^6.16.6"
deprecation "^2.3.1"
"@octokit/request-error@^2.0.5", "@octokit/request-error@^2.1.0":
......@@ -1456,21 +1456,21 @@
universal-user-agent "^6.0.0"
"@octokit/rest@^18.1.0":
version "18.6.1"
resolved "https://registry.yarnpkg.com/@octokit/rest/-/rest-18.6.1.tgz#82f0582fd7e1a6e2da3cee0a8e30c2647e242cb3"
integrity sha512-4NUr0sr8ZohvYoDVDT/P7lmamzeGrFjdfVxIuxW9Nz3xMp//MBmIKYxHhzMuMWGa8MHs69VT2HKsNYRJMCYyWA==
version "18.6.2"
resolved "https://registry.yarnpkg.com/@octokit/rest/-/rest-18.6.2.tgz#181ef6a23f1e5977569f439bd256041dc9d5a696"
integrity sha512-q6nrxhM+oXzPmbZlykNaBP1vG0+mU6URLBy9cl4XXrWcD0k0ShYiaXDaPewbllTxoMevqv+OABb+Q7ycUWkE2A==
dependencies:
"@octokit/core" "^3.5.0"
"@octokit/plugin-paginate-rest" "^2.6.2"
"@octokit/plugin-request-log" "^1.0.2"
"@octokit/plugin-rest-endpoint-methods" "5.3.2"
"@octokit/plugin-rest-endpoint-methods" "5.3.3"
"@octokit/types@^6.0.3", "@octokit/types@^6.13.0", "@octokit/types@^6.16.1", "@octokit/types@^6.16.5":
version "6.16.5"
resolved "https://registry.yarnpkg.com/@octokit/types/-/types-6.16.5.tgz#75f03ed0b48565fc7afb0e5ebd658e802ed0b7c1"
integrity sha512-2v30UzgezzVZNCZlEryr8ujqaFW0EEH0fyuNxz5QdE3rlkCG2SXz8RTCT1V4q7inEI2kd2xTcROlq9OkEvY0TQ==
"@octokit/types@^6.0.3", "@octokit/types@^6.13.0", "@octokit/types@^6.16.1", "@octokit/types@^6.16.6":
version "6.16.6"
resolved "https://registry.yarnpkg.com/@octokit/types/-/types-6.16.6.tgz#c113a0408a799ccb93c8749806733ad5d3edd142"
integrity sha512-PrEGjMnEhLlNttsuLadEWqXdMYJX3icHHaRs/ChJebRT79VDh/cNkk8bURx05BEEwr7QvaLsRzjt3hNxUJZfXA==
dependencies:
"@octokit/openapi-types" "^7.3.3"
"@octokit/openapi-types" "^7.3.4"
"@rollup/plugin-alias@^3.1.1":
version "3.1.2"
......@@ -2054,6 +2054,11 @@
resolved "https://registry.yarnpkg.com/@vue/shared/-/shared-3.1.2.tgz#1069c0bc7d6f4bd15ccf3a5f3be29450aca368f9"
integrity sha512-EmH/poaDWBPJaPILXNI/1fvUbArJQmmTyVCwvvyDYDFnkPoTclAbHRAtyIvqfez7jybTDn077HTNILpxlsoWhg==
"@webcomponents/custom-elements@^1.4.3":
version "1.4.3"
resolved "https://registry.yarnpkg.com/@webcomponents/custom-elements/-/custom-elements-1.4.3.tgz#1800d49f38bb4425ebfd160b50115e62776109d7"
integrity sha512-iD0YW46SreUQANGccywK/eC+gZELNHocZZrY2fGwrIlx/biQOTkAF9IohisibHbrmIHmA9pVCIdGwzfO+W0gig==
JSONStream@^1.0.4:
version "1.3.5"
resolved "https://registry.yarnpkg.com/JSONStream/-/JSONStream-1.3.5.tgz#3208c1f08d3a4d99261ab64f92302bc15e111ca0"
......@@ -3578,9 +3583,9 @@ ee-first@1.1.1:
integrity sha1-WQxhFWsK4vTwJVcyoViyZrxWsh0=
electron-to-chromium@^1.3.723:
version "1.3.756"
resolved "https://registry.yarnpkg.com/electron-to-chromium/-/electron-to-chromium-1.3.756.tgz#942cee59cd64d19f576d8d5804eef09cb423740c"
integrity sha512-WsmJym1TMeHVndjPjczTFbnRR/c4sbzg8fBFtuhlb2Sru3i/S1VGpzDSrv/It8ctMU2bj8G7g7/O3FzYMGw6eA==
version "1.3.757"
resolved "https://registry.yarnpkg.com/electron-to-chromium/-/electron-to-chromium-1.3.757.tgz#ff99436c99ca0fc5d120e11030a868401396e0e1"
integrity sha512-kP0ooyrvavDC+Y9UG6G/pUVxfRNM2VTJwtLQLvgsJeyf1V+7shMCb68Wj0/TETmfx8dWv9pToGkVT39udE87wQ==
elliptic@^6.5.3:
version "6.5.4"
......@@ -7327,9 +7332,9 @@ parse-path@^4.0.0:
query-string "^6.13.8"
parse-url@^5.0.0:
version "5.0.5"
resolved "https://registry.yarnpkg.com/parse-url/-/parse-url-5.0.5.tgz#06b7f6978b65cac7851bb768bec4e0b950714e1a"
integrity sha512-AwfVhXaQrNNI6UPUJq/GJN2qoY0L9gPgxhh9VbDP0bfBAJWaC/Zh8hjQ58YKTi4AagOT70fpadkYSKPo+eFb1w==
version "5.0.6"
resolved "https://registry.yarnpkg.com/parse-url/-/parse-url-5.0.6.tgz#9bc508b11f8844e0b8cd9b43ac511852a4e24ec3"
integrity sha512-nZp+U7NFVTsBXTh6oGxdwvd7ncz3hJCl74q0lC0pLc3ypXJMKFUpfUEAd4r1x8zVVF5UHFik+CBNOQKN0ayByA==
dependencies:
is-ssh "^1.3.0"
normalize-url "4.5.0"
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册