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

feat(cli): easycom

上级 a72ef657
......@@ -43,7 +43,10 @@ module.exports = {
},
// Packages targeting Node
{
files: ['packages/{vue-cli-plugin-uni,vue-cli-plugin-hbuilderx}/**'],
files: [
'packages/{vue-cli-plugin-uni,vue-cli-plugin-hbuilderx}/**',
'packages/*/vite.config.ts'
],
rules: {
'no-restricted-globals': ['error', ...DOMGlobals],
'no-restricted-syntax': 'off'
......
{
"$schema": "https://developer.microsoft.com/json-schemas/api-extractor/v7/api-extractor.schema.json",
"apiReport": {
"enabled": true,
"reportFolder": "<projectFolder>/temp/"
},
"docModel": {
"enabled": true
},
"dtsRollup": {
"enabled": true
},
"tsdocMetadata": {
"enabled": false
},
"messages": {
"compilerMessageReporting": {
"default": {
"logLevel": "warning"
}
},
"extractorMessageReporting": {
"default": {
"logLevel": "warning",
"addToApiReportFile": true
},
"ae-missing-release-tag": {
"logLevel": "none"
}
},
"tsdocMessageReporting": {
"default": {
"logLevel": "warning"
},
"tsdoc-undefined-tag": {
"logLevel": "none"
}
}
}
}
......@@ -7,7 +7,7 @@
"scripts": {
"dev": "node scripts/dev.js",
"build": "node scripts/build.js",
"lint": "eslint --ext .ts packages/*/src/**",
"lint": "eslint packages/**/*.ts",
"format": "prettier --write --parser typescript \"packages/**/*.ts?(x)\"",
"ls-lint": "ls-lint",
"test": "jest",
......
import path from 'path'
import { initEasycoms, matchEasycom } from '../src/easycom'
const rootDir = path.resolve(__dirname, 'example')
const dirs = [
path.resolve(__dirname, 'example/components'),
path.resolve(__dirname, 'example/uni_modules/plugin/components')
]
describe('easycom', () => {
test('initEasycoms with dirs', () => {
expect(initEasycoms({ dirs, rootDir })).toEqual([
{
pattern: new RegExp('^test$'),
replacement: '@/components/test/test'
},
{
pattern: new RegExp('^test1$'),
replacement: '@/components/test1/test1'
},
{
pattern: new RegExp('^test2$'),
replacement: '@/uni_modules/plugin/components/test2/test2'
}
])
expect(matchEasycom('test')).toBe('@/components/test/test')
expect(matchEasycom('test1')).toBe('@/components/test1/test1')
expect(matchEasycom('test2')).toBe(
'@/uni_modules/plugin/components/test2/test2'
)
})
test('initEasycoms with custom', () => {
expect(
initEasycoms({ custom: { '^uni-(.*)': '@/components/uni-$1.vue' } })
).toEqual([
{
pattern: new RegExp('^uni-(.*)'),
replacement: '@/components/uni-$1.vue'
}
])
expect(matchEasycom('test')).toBe(false)
expect(matchEasycom('uni-test1')).toBe('@/components/uni-test1.vue')
})
test('initEasycoms with dirs and custom', () => {
expect(
initEasycoms({
dirs,
rootDir,
custom: { '^test$': '@/components/uni-test.vue' }
})
).toEqual([
{
pattern: new RegExp('^test$'),
replacement: '@/components/uni-test.vue'
},
{
pattern: new RegExp('^test1$'),
replacement: '@/components/test1/test1'
},
{
pattern: new RegExp('^test2$'),
replacement: '@/uni_modules/plugin/components/test2/test2'
}
])
expect(matchEasycom('test')).toBe('@/components/uni-test.vue')
})
})
......@@ -6,7 +6,8 @@
"types": "dist/index.d.ts",
"files": [
"dist/**/*.js",
"dist/**/*.d.ts"
"dist/**/*.d.ts",
"lib"
],
"buildOptions": {
"bundler": "tsc"
......@@ -21,6 +22,8 @@
"url": "https://github.com/dcloudio/uni-app/issues"
},
"dependencies": {
"@dcloudio/uni-shared": "^3.0.0",
"@vue/compiler-core": "^3.0.4",
"strip-json-comments": "^3.1.1",
"xregexp": "3.1.0"
}
......
import fs from 'fs'
import path from 'path'
interface EasycomOption {
dirs?: string[]
rootDir?: string
custom?: EasycomCustom
}
interface EasycomMatcher {
pattern: RegExp
replacement: string
}
interface EasycomCustom {
[key: string]: string
}
const easycoms: EasycomMatcher[] = []
const easycomsCache = new Map<string, string>()
const easycomsInvalidCache = new Set<string>()
function clearEasycoms() {
easycoms.length = 0
easycomsCache.clear()
easycomsInvalidCache.clear()
}
export function initEasycoms({ dirs, rootDir, custom }: EasycomOption) {
clearEasycoms()
const easycomsObj = Object.create(null)
if (dirs && rootDir) {
Object.assign(easycomsObj, initAutoScanEasycoms(dirs, rootDir))
}
if (custom) {
Object.assign(easycomsObj, custom)
}
Object.keys(easycomsObj).forEach(name => {
easycoms.push({
pattern: new RegExp(name),
replacement: easycomsObj[name]
})
})
return easycoms
}
export function matchEasycom(tag: string) {
let source = easycomsCache.get(tag)
if (source) {
return source
}
if (easycomsInvalidCache.has(tag)) {
return false
}
const matcher = easycoms.find(matcher => matcher.pattern.test(tag))
if (!matcher) {
easycomsInvalidCache.add(tag)
return false
}
source = tag.replace(matcher.pattern, matcher.replacement)
easycomsCache.set(tag, source)
return source
}
const isDir = (path: string) => fs.lstatSync(path).isDirectory()
function initAutoScanEasycom(
dir: string,
rootDir: string
): Record<string, string> {
const easycoms = Object.create(null)
if (!fs.existsSync(dir)) {
return easycoms
}
fs.readdirSync(dir).forEach(name => {
const folder = path.resolve(dir, name)
if (!isDir(folder)) {
return
}
const importDir = path.relative(rootDir, folder)
const files = fs.readdirSync(folder)
if (files.find(file => path.parse(file).name === name)) {
easycoms[`^${name}$`] = `@/${importDir}/${name}`
}
})
return easycoms
}
function initAutoScanEasycoms(dirs: string[], rootDir: string) {
return dirs.reduce<Record<string, string>>(
(easycoms: Record<string, string>, dir: string) => {
const curEasycoms = initAutoScanEasycom(dir, rootDir)
Object.keys(curEasycoms).forEach(name => {
// Use the first component when name conflict
if (!easycoms[name]) {
easycoms[name] = curEasycoms[name]
}
})
return easycoms
},
Object.create(null)
)
}
export * from './json'
export * from './transforms/transformBuiltInComponent'
export * from './transforms/transformEasycom'
type Data = Record<string, any>
interface Customizer {
(a: unknown, b: unknown, k: string): unknown
}
const isArray = Array.isArray
function isPlainObject(a: unknown): a is Data {
if (a === null) {
return false
}
return typeof a === 'object'
}
function mergeWith(objects: Data[], customizer: Customizer) {
const [first, ...rest] = objects
let ret = first
rest.forEach(a => {
ret = mergeTo(ret, a, customizer)
})
return ret
}
function mergeTo(a: Data, b: Data, customizer: Customizer) {
const ret: Data = {}
Object.keys(a)
.concat(Object.keys(b))
.forEach(k => {
const v = customizer(a[k], b[k], k)
ret[k] = typeof v === 'undefined' ? a[k] : v
})
return ret
}
function mergeWithRule(a: Data[], b: Data[], k: string, matchField: string) {
if (!isArray(a)) {
return a
}
const bMatchItems: Data[] = []
const ret = a.map(aItem => {
if (!matchField) {
return aItem
}
// 暂不考虑重复
const bMatchItem = b.find(bItem => aItem[matchField] === bItem[matchField])
if (bMatchItem) {
bMatchItems.push(bMatchItem)
return mergeWith([aItem, bMatchItem], createCustomizer(k))
}
return aItem
})
return ret.concat(b.filter(bItem => !bMatchItems.includes(bItem)))
}
function customizeArray(a: any[], b: any[], k: string) {
if (k === 'pages' || k === 'subPackages.pages') {
return mergeWithRule(a, b, k, 'path')
} else if (k === 'subPackages') {
return mergeWithRule(a, b, k, 'root')
}
return b
}
function customizeObject(a: Data, b: Data, k: string) {
return mergeWith([a, b], createCustomizer(k))
}
function createCustomizer(key?: string): Customizer {
return function customizer(a: unknown, b: unknown, k: string) {
const newKey = key ? `${key}.${k}` : k
if (isArray(a) && isArray(b)) {
return customizeArray(a, b, newKey)
}
if (isPlainObject(a) && isPlainObject(b)) {
return customizeObject(a, b, newKey)
}
return b
}
}
export default function merge(pagesJsons: any[]) {
return mergeWith(pagesJsons, createCustomizer())
}
import {
ElementNode,
ConstantTypes,
TransformContext,
createSimpleExpression
} from '@vue/compiler-core'
export function addImport(
path: string,
node: ElementNode,
context: TransformContext
) {
// remove resolveComponent
context.components.delete(node.tag)
// add import
const importsArray = Array.from(context.imports)
const existing = importsArray.find(i => i.path === path)
if (existing) {
return
}
context.imports.add({
path,
exp: createSimpleExpression(name, false, node.loc, ConstantTypes.CAN_HOIST)
})
}
import { NodeTypes, NodeTransform } from '@vue/compiler-core'
import { isBuiltInComponent } from '@dcloudio/uni-shared'
import { addImport } from './addImport'
const COMPONENTS_PATH = '@dcloudio/uni-h5/lib/'
export const transformBuiltInComponent: NodeTransform = (node, context) => {
if (node.type !== NodeTypes.ELEMENT) {
return
}
const tag = node.tag
if (isBuiltInComponent(tag)) {
addImport(COMPONENTS_PATH + tag + '/index.js', node, context)
}
}
import { NodeTypes, NodeTransform } from '@vue/compiler-core'
import { matchEasycom } from '../easycom'
import { addImport } from './addImport'
export const transformEasycom: NodeTransform = (node, context) => {
if (node.type !== NodeTypes.ELEMENT) {
return
}
if (node.tag === 'match-media' && process.env.UNI_PLATFORM !== 'mp-weixin') {
node.tag = 'uni-match-media'
}
const path = matchEasycom(node.tag)
if (path) {
addImport(path, node, context)
}
}
{
"compilerOptions": {
"rootDir": "src",
"baseUrl": "./",
"target": "esnext",
"moduleResolution": "node",
"strict": true,
"declaration": true,
"noUnusedLocals": true,
"esModuleInterop": true,
"outDir": "./dist",
"module": "commonjs",
"lib": ["ESNext", "DOM"],
"sourceMap": false
}
}
\ No newline at end of file
"extends": "../../tsconfig.node.json",
"compilerOptions": {
"outDir": "dist"
},
"include": ["src"]
}
......@@ -538,7 +538,7 @@ function render(_ctx, _cache, $props, $setup, $data, $options) {
}, [
createVNode("div", {
class: [{play: !$data.playing, pause: $data.playing}, "uni-audio-button"],
onClick: _cache[1] || (_cache[1] = (...args) => $options.trigger(...args))
onClick: _cache[1] || (_cache[1] = (...args) => $options.trigger && $options.trigger(...args))
}, null, 2)
], 4),
createVNode("div", _hoisted_2, [
......@@ -1302,7 +1302,7 @@ var script$2 = {
const _hoisted_1$2 = {class: "uni-checkbox-wrapper"};
function render$2(_ctx, _cache, $props, $setup, $data, $options) {
return openBlock(), createBlock("uni-checkbox", mergeProps({disabled: $props.disabled}, _ctx.$attrs, {
onClick: _cache[1] || (_cache[1] = (...args) => $options._onClick(...args))
onClick: _cache[1] || (_cache[1] = (...args) => $options._onClick && $options._onClick(...args))
}), [
createVNode("div", _hoisted_1$2, [
createVNode("div", {
......@@ -2561,12 +2561,12 @@ function render$8(_ctx, _cache, $props, $setup, $data, $options) {
autofocus: $props.focus,
class: "uni-input-input",
autocomplete: "off",
onFocus: _cache[2] || (_cache[2] = (...args) => $options._onFocus(...args)),
onBlur: _cache[3] || (_cache[3] = (...args) => $options._onBlur(...args)),
onInput: _cache[4] || (_cache[4] = withModifiers((...args) => $options._onInput(...args), ["stop"])),
onCompositionstart: _cache[5] || (_cache[5] = (...args) => $options._onComposition(...args)),
onCompositionend: _cache[6] || (_cache[6] = (...args) => $options._onComposition(...args)),
onKeyup: _cache[7] || (_cache[7] = withModifiers((...args) => $options._onKeyup(...args), ["stop"]))
onFocus: _cache[2] || (_cache[2] = (...args) => $options._onFocus && $options._onFocus(...args)),
onBlur: _cache[3] || (_cache[3] = (...args) => $options._onBlur && $options._onBlur(...args)),
onInput: _cache[4] || (_cache[4] = withModifiers((...args) => $options._onInput && $options._onInput(...args), ["stop"])),
onCompositionstart: _cache[5] || (_cache[5] = (...args) => $options._onComposition && $options._onComposition(...args)),
onCompositionend: _cache[6] || (_cache[6] = (...args) => $options._onComposition && $options._onComposition(...args)),
onKeyup: _cache[7] || (_cache[7] = withModifiers((...args) => $options._onKeyup && $options._onKeyup(...args), ["stop"]))
}, null, 40, ["disabled", "type", "maxlength", "step", "autofocus"]), [
[vModelDynamic, _ctx.valueSync]
])
......@@ -2609,7 +2609,7 @@ function render$9(_ctx, _cache, $props, $setup, $data, $options) {
return openBlock(), createBlock("uni-label", mergeProps({
class: {"uni-label-pointer": $options.pointer}
}, _ctx.$attrs, {
onClick: _cache[1] || (_cache[1] = (...args) => $options._onClick(...args))
onClick: _cache[1] || (_cache[1] = (...args) => $options._onClick && $options._onClick(...args))
}), [
renderSlot(_ctx.$slots, "default")
], 16);
......@@ -3752,15 +3752,15 @@ function render$b(_ctx, _cache, $props, $setup, $data, $options) {
return $props.hoverClass && $props.hoverClass !== "none" ? (openBlock(), createBlock("uni-navigator", mergeProps({
key: 0,
class: [_ctx.hovering ? $props.hoverClass : ""],
onTouchstart: _cache[1] || (_cache[1] = (...args) => _ctx._hoverTouchStart(...args)),
onTouchend: _cache[2] || (_cache[2] = (...args) => _ctx._hoverTouchEnd(...args)),
onTouchcancel: _cache[3] || (_cache[3] = (...args) => _ctx._hoverTouchCancel(...args)),
onClick: _cache[4] || (_cache[4] = (...args) => $options._onClick(...args))
onTouchstart: _cache[1] || (_cache[1] = (...args) => _ctx._hoverTouchStart && _ctx._hoverTouchStart(...args)),
onTouchend: _cache[2] || (_cache[2] = (...args) => _ctx._hoverTouchEnd && _ctx._hoverTouchEnd(...args)),
onTouchcancel: _cache[3] || (_cache[3] = (...args) => _ctx._hoverTouchCancel && _ctx._hoverTouchCancel(...args)),
onClick: _cache[4] || (_cache[4] = (...args) => $options._onClick && $options._onClick(...args))
}, _ctx.$attrs), [
renderSlot(_ctx.$slots, "default")
], 16)) : (openBlock(), createBlock("uni-navigator", mergeProps({
key: 1,
onClick: _cache[5] || (_cache[5] = (...args) => $options._onClick(...args))
onClick: _cache[5] || (_cache[5] = (...args) => $options._onClick && $options._onClick(...args))
}, _ctx.$attrs), [
renderSlot(_ctx.$slots, "default")
], 16));
......@@ -3971,7 +3971,7 @@ var script$d = {
const _hoisted_1$5 = {class: "uni-radio-wrapper"};
function render$d(_ctx, _cache, $props, $setup, $data, $options) {
return openBlock(), createBlock("uni-radio", mergeProps({disabled: $props.disabled}, _ctx.$attrs, {
onClick: _cache[1] || (_cache[1] = (...args) => $options._onClick(...args))
onClick: _cache[1] || (_cache[1] = (...args) => $options._onClick && $options._onClick(...args))
}), [
createVNode("div", _hoisted_1$5, [
createVNode("div", {
......@@ -5721,7 +5721,7 @@ const _hoisted_1$8 = {class: "uni-slider-wrapper"};
const _hoisted_2$3 = {class: "uni-slider-tap-area"};
function render$h(_ctx, _cache, $props, $setup, $data, $options) {
return openBlock(), createBlock("uni-slider", mergeProps({ref: "uni-slider"}, _ctx.$attrs, {
onClick: _cache[1] || (_cache[1] = (...args) => $options._onClick(...args))
onClick: _cache[1] || (_cache[1] = (...args) => $options._onClick && $options._onClick(...args))
}), [
createVNode("div", _hoisted_1$8, [
createVNode("div", _hoisted_2$3, [
......@@ -5860,7 +5860,7 @@ var script$k = {
const _hoisted_1$9 = {class: "uni-switch-wrapper"};
function render$j(_ctx, _cache, $props, $setup, $data, $options) {
return openBlock(), createBlock("uni-switch", mergeProps({disabled: $props.disabled}, _ctx.$attrs, {
onClick: _cache[1] || (_cache[1] = (...args) => $options._onClick(...args))
onClick: _cache[1] || (_cache[1] = (...args) => $options._onClick && $options._onClick(...args))
}), [
createVNode("div", _hoisted_1$9, [
withDirectives(createVNode("div", {
......@@ -6143,12 +6143,12 @@ function render$k(_ctx, _cache, $props, $setup, $data, $options) {
autofocus: $props.autoFocus || $props.focus,
class: [{"uni-textarea-textarea-fix-margin": $data.fixMargin}, "uni-textarea-textarea"],
style: {"overflow-y": $props.autoHeight ? "hidden" : "auto"},
onCompositionstart: _cache[2] || (_cache[2] = (...args) => $options._compositionstart(...args)),
onCompositionend: _cache[3] || (_cache[3] = (...args) => $options._compositionend(...args)),
onInput: _cache[4] || (_cache[4] = withModifiers((...args) => $options._input(...args), ["stop"])),
onFocus: _cache[5] || (_cache[5] = (...args) => $options._focus(...args)),
onBlur: _cache[6] || (_cache[6] = (...args) => $options._blur(...args)),
onTouchstartPassive: _cache[7] || (_cache[7] = (...args) => $options._touchstart(...args))
onCompositionstart: _cache[2] || (_cache[2] = (...args) => $options._compositionstart && $options._compositionstart(...args)),
onCompositionend: _cache[3] || (_cache[3] = (...args) => $options._compositionend && $options._compositionend(...args)),
onInput: _cache[4] || (_cache[4] = withModifiers((...args) => $options._input && $options._input(...args), ["stop"])),
onFocus: _cache[5] || (_cache[5] = (...args) => $options._focus && $options._focus(...args)),
onBlur: _cache[6] || (_cache[6] = (...args) => $options._blur && $options._blur(...args)),
onTouchstartPassive: _cache[7] || (_cache[7] = (...args) => $options._touchstart && $options._touchstart(...args))
}, null, 46, ["disabled", "maxlength", "autofocus"]), [
[vModelText, _ctx.valueSync]
])
......@@ -6167,9 +6167,9 @@ function render$l(_ctx, _cache, $props, $setup, $data, $options) {
return _ctx.hoverClass && _ctx.hoverClass !== "none" ? (openBlock(), createBlock("uni-view", mergeProps({
key: 0,
class: [_ctx.hovering ? _ctx.hoverClass : ""],
onTouchstart: _cache[1] || (_cache[1] = (...args) => _ctx._hoverTouchStart(...args)),
onTouchend: _cache[2] || (_cache[2] = (...args) => _ctx._hoverTouchEnd(...args)),
onTouchcancel: _cache[3] || (_cache[3] = (...args) => _ctx._hoverTouchCancel(...args))
onTouchstart: _cache[1] || (_cache[1] = (...args) => _ctx._hoverTouchStart && _ctx._hoverTouchStart(...args)),
onTouchend: _cache[2] || (_cache[2] = (...args) => _ctx._hoverTouchEnd && _ctx._hoverTouchEnd(...args)),
onTouchcancel: _cache[3] || (_cache[3] = (...args) => _ctx._hoverTouchCancel && _ctx._hoverTouchCancel(...args))
}, _ctx.$attrs), [
renderSlot(_ctx.$slots, "default")
], 16)) : (openBlock(), createBlock("uni-view", mergeProps({key: 1}, _ctx.$attrs), [
......@@ -6177,4 +6177,4 @@ function render$l(_ctx, _cache, $props, $setup, $data, $options) {
], 16));
}
script$m.render = render$l;
export {script as Audio, script$1 as Canvas, script$2 as Checkbox, script$3 as CheckboxGroup, script$4 as Editor, script$5 as Form, script$6 as Icon, script$7 as Image, script$8 as Input, script$9 as Label, script$a as MovableView, script$b as Navigator, script$c as Progress, script$d as Radio, script$e as RadioGroup, script$f as ResizeSensor, script$g as RichText, script$h as ScrollView, script$i as Slider, script$j as SwiperItem, script$k as Switch, script$l as Textarea, script$m as View, passiveOptions, supportsPassive$1 as supportsPassive};
export {script as Audio, script$1 as Canvas, script$2 as Checkbox, script$3 as CheckboxGroup, script$4 as Editor, script$5 as Form, script$6 as Icon, script$7 as Image, script$8 as Input, script$9 as Label, script$a as MovableView, script$b as Navigator, script$c as Progress, script$d as Radio, script$e as RadioGroup, script$f as ResizeSensor, script$g as RichText, script$h as ScrollView, script$i as Slider, script$j as SwiperItem, script$k as Switch, script$l as Textarea, script$m as View};
uni-audio{
display:none;
}
uni-audio[controls]{
display:inline-block;
}
uni-audio[hidden]{
display:none;
}
.uni-audio-default{
max-width:100%;
min-width:302px;
height:65px;
background:#fcfcfc;
border:1px solid #e0e0e0;
border-radius:2.5px;
display:inline-block;
overflow:hidden;
}
.uni-audio-left{
width:65px;
height:65px;
float:left;
background-color:#e6e6e6;
background-size:100% 100%;
background-position:50% 50%;
}
.uni-audio-button{
width:24px;
height:24px;
margin:20.5px;
background-size:cover;
}
.uni-audio-button.play{
background-image:url(data:image/png;base64,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);
}
.uni-audio-button.pause{
background-image:url(data:image/png;base64,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);
}
.uni-audio-right{
box-sizing:border-box;
height:65px;
margin-left:65px;
padding:11px 16.5px 13.5px 15px;
overflow:hidden;
}
.uni-audio-time{
margin-top:3.5px;
height:16.5px;
font-size:12px;
color:#888888;
float:right;
}
.uni-audio-info{
margin-right:70px;
overflow:hidden;
}
.uni-audio-name{
height:22.5px;
line-height:22.5px;
margin-bottom:3.5px;
font-size:14px;
color:#353535;
overflow:hidden;
white-space:nowrap;
text-overflow:ellipsis;
}
.uni-audio-author{
height:14.5px;
line-height:14.5px;
font-size:12px;
color:#888888;
overflow:hidden;
white-space:nowrap;
text-overflow:ellipsis;
}
import {isFunction} from "@vue/shared";
import {openBlock, createBlock, mergeProps, createVNode, toDisplayString} from "vue";
var subscriber = {
mounted() {
this._toggleListeners("subscribe", this.id);
this.$watch("id", (newId, oldId) => {
this._toggleListeners("unsubscribe", oldId, true);
this._toggleListeners("subscribe", newId, true);
});
},
beforeDestroy() {
this._toggleListeners("unsubscribe", this.id);
if (this._contextId) {
this._toggleListeners("unsubscribe", this._contextId);
}
},
methods: {
_toggleListeners(type, id, watch) {
if (watch && !id) {
return;
}
if (!isFunction(this._handleSubscribe)) {
return;
}
UniViewJSBridge[type](this.$page.id + "-" + this.$options.name.replace(/VUni([A-Z])/, "$1").toLowerCase() + "-" + id, this._handleSubscribe);
},
_getContextInfo() {
const id = `context-${this._uid}`;
if (!this._contextId) {
this._toggleListeners("subscribe", id);
this._contextId = id;
}
return {
name: this.$options.name.replace(/VUni([A-Z])/, "$1").toLowerCase(),
id,
page: this.$page.id
};
}
}
};
var script = {
name: "Audio",
mixins: [subscriber],
props: {
id: {
type: String,
default: ""
},
src: {
type: String,
default: ""
},
loop: {
type: [Boolean, String],
default: false
},
controls: {
type: [Boolean, String],
default: false
},
poster: {
type: String,
default: ""
},
name: {
type: String,
default: ""
},
author: {
type: String,
default: ""
}
},
data() {
return {
playing: false,
currentTime: this.getTime(0)
};
},
watch: {
src(val) {
if (this.$refs.audio) {
this.$refs.audio.src = this.$getRealPath(val);
}
}
},
mounted() {
const audio = this.$refs.audio;
audio.addEventListener("error", ($event) => {
this.playing = false;
this.$trigger("error", $event, {});
});
audio.addEventListener("play", ($event) => {
this.playing = true;
this.$trigger("play", $event, {});
});
audio.addEventListener("pause", ($event) => {
this.playing = false;
this.$trigger("pause", $event, {});
});
audio.addEventListener("ended", ($event) => {
this.playing = false;
this.$trigger("ended", $event, {});
});
audio.addEventListener("timeupdate", ($event) => {
var currentTime = audio.currentTime;
this.currentTime = this.getTime(currentTime);
var duration = audio.duration;
this.$trigger("timeupdate", $event, {
currentTime,
duration
});
});
audio.src = this.$getRealPath(this.src);
},
methods: {
_handleSubscribe({
type,
data = {}
}) {
var audio = this.$refs.audio;
switch (type) {
case "setSrc":
audio.src = this.$getRealPath(data.src);
this.$emit("update:src", data.src);
break;
case "play":
audio.play();
break;
case "pause":
audio.pause();
break;
case "seek":
audio.currentTime = data.position;
break;
}
},
trigger() {
if (this.playing) {
this.$refs.audio.pause();
} else {
this.$refs.audio.play();
}
},
getTime(time) {
var h = Math.floor(time / 3600);
var m = Math.floor(time % 3600 / 60);
var s = Math.floor(time % 3600 % 60);
h = (h < 10 ? "0" : "") + h;
m = (m < 10 ? "0" : "") + m;
s = (s < 10 ? "0" : "") + s;
var str = m + ":" + s;
if (h !== "00") {
str = h + ":" + str;
}
return str;
}
}
};
const _hoisted_1 = {class: "uni-audio-default"};
const _hoisted_2 = {class: "uni-audio-right"};
const _hoisted_3 = {class: "uni-audio-time"};
const _hoisted_4 = {class: "uni-audio-info"};
const _hoisted_5 = {class: "uni-audio-name"};
const _hoisted_6 = {class: "uni-audio-author"};
function render(_ctx, _cache, $props, $setup, $data, $options) {
return openBlock(), createBlock("uni-audio", mergeProps({
id: $props.id,
controls: !!$props.controls
}, _ctx.$attrs), [
createVNode("audio", {
ref: "audio",
loop: $props.loop,
style: {display: "none"}
}, null, 8, ["loop"]),
createVNode("div", _hoisted_1, [
createVNode("div", {
style: "background-image: url(" + _ctx.$getRealPath($props.poster) + ");",
class: "uni-audio-left"
}, [
createVNode("div", {
class: [{play: !$data.playing, pause: $data.playing}, "uni-audio-button"],
onClick: _cache[1] || (_cache[1] = (...args) => $options.trigger && $options.trigger(...args))
}, null, 2)
], 4),
createVNode("div", _hoisted_2, [
createVNode("div", _hoisted_3, toDisplayString($data.currentTime), 1),
createVNode("div", _hoisted_4, [
createVNode("div", _hoisted_5, toDisplayString($props.name), 1),
createVNode("div", _hoisted_6, toDisplayString($props.author), 1)
])
])
])
], 16, ["id", "controls"]);
}
script.render = render;
export default script;
export * from './components'
export { supportsPassive, passiveOptions } from './helpers'
import fs from 'fs'
import path from 'path'
import { isCustomElement } from '../uni-shared'
export default {
......@@ -25,4 +28,33 @@ export default {
return 'assets/[name]-[hash][extname]'
}
}
// configureBuild: buildComponents
}
const components = fs
.readdirSync(path.resolve(__dirname, 'src/components'))
.filter(item => !/(^|\/)\.[^/.]/g.test(item))
function buildComponents(_config, builds) {
return once(() => {
const mainBuild = builds[0]
components.forEach(name => {
builds.push({
// eslint-disabled no-restricted-syntax
...mainBuild,
input: `src/components/${name}/index.vue`,
output: {
dir: `dist/${name}`,
file: `${name}.js`
},
plugins: [...mainBuild.plugins]
})
})
console.log('builds.length', builds.length)
})
}
function once(fn) {
let called = false
return () => (!called && fn(), (called = true))
}
import { passiveOptions } from '@dcloudio/uni-components'
const LONGPRESS_TIMEOUT = 350
const LONGPRESS_THRESHOLD = 10
const passiveOptions = { passive: true } // TODO caniuse?
let longPressTimer = 0
function clearLongPressTimer() {
......
import {isFunction, extend, isPlainObject, isPromise, isArray, hasOwn} from "@vue/shared";
import {injectHook, openBlock, createBlock, createVNode, Fragment, renderList, toDisplayString, createCommentVNode, createTextVNode, Transition, withCtx, withModifiers, withDirectives, vShow, resolveComponent, KeepAlive, resolveDynamicComponent, mergeProps, renderSlot} from "vue";
import {passiveOptions, Input} from "@dcloudio/uni-components";
export * from "@dcloudio/uni-components";
import {TABBAR_HEIGHT, COMPONENT_NAME_PREFIX, isCustomElement, NAVBAR_HEIGHT} from "@dcloudio/uni-shared";
import {createWebHistory, createWebHashHistory, createRouter} from "vue-router";
import {Input} from "@dcloudio/uni-components";
export * from "@dcloudio/uni-components";
function applyOptions(options, instance2, publicThis) {
Object.keys(options).forEach((name) => {
if (name.indexOf("on") === 0) {
......@@ -90,6 +90,7 @@ function initBridge(namespace) {
const ViewJSBridge = initBridge("view");
const LONGPRESS_TIMEOUT = 350;
const LONGPRESS_THRESHOLD = 10;
const passiveOptions = {passive: true};
let longPressTimer = 0;
function clearLongPressTimer() {
if (longPressTimer) {
......@@ -2243,7 +2244,7 @@ function render$5(_ctx, _cache, $props, $setup, $data, $options) {
createVNode("div", _hoisted_1$4, [
withDirectives(createVNode("div", {
class: "uni-page-head-btn",
onClick: _cache[1] || (_cache[1] = (...args) => $options._back(...args))
onClick: _cache[1] || (_cache[1] = (...args) => $options._back && $options._back(...args))
}, [
createVNode("i", {
style: {color: _ctx.color, fontSize: "27px"},
......@@ -2808,7 +2809,7 @@ var script$9 = {
function render$9(_ctx, _cache, $props, $setup, $data, $options) {
return openBlock(), createBlock("div", {
class: "uni-async-error",
onClick: _cache[1] || (_cache[1] = (...args) => $options._onClick(...args))
onClick: _cache[1] || (_cache[1] = (...args) => $options._onClick && $options._onClick(...args))
}, " \u8FDE\u63A5\u670D\u52A1\u5668\u8D85\u65F6\uFF0C\u70B9\u51FB\u5C4F\u5E55\u91CD\u8BD5 ");
}
script$9.render = render$9;
......
import { defineComponent } from 'vue'
import { initHooks, initUnknownHooks } from '../src/componentHooks'
import { initHooks, initUnknownHooks } from '../src/runtime/componentHooks'
const vueBasicOptions = defineComponent({
onLoad() {},
......
{
"extends": "../../api-extractor.json",
"mainEntryPointFilePath": "./dist/packages/<unscopedPackageName>/src/index.d.ts",
"dtsRollup": {
"publicTrimmedFilePath": "./dist/<unscopedPackageName>.d.ts"
}
}
\ No newline at end of file
{
"input": {
"src/index.ts": "dist/uni.shared.esm.js"
"src/index.ts": ["dist/uni-shared.esm.js", "dist/uni-shared.cjs.js"]
},
"compilerOptions": {
"declaration": true
}
}
'use strict';
Object.defineProperty(exports, '__esModule', { value: true });
var shared = require('@vue/shared');
const NAVBAR_HEIGHT = 44;
const TABBAR_HEIGHT = 50;
const COMPONENT_NAME_PREFIX = 'VUni';
function debounce(fn, delay) {
let timeout;
const newFn = function () {
clearTimeout(timeout);
const timerFn = () => fn.apply(this, arguments);
timeout = setTimeout(timerFn, delay);
};
newFn.cancel = function () {
clearTimeout(timeout);
};
return newFn;
}
function plusReady(callback) {
if (typeof callback !== 'function') {
return;
}
if (window.plus) {
return callback();
}
document.addEventListener('plusready', callback);
}
const encode = encodeURIComponent;
function stringifyQuery(obj, encodeStr = encode) {
const res = obj
? Object.keys(obj)
.map(key => {
let val = obj[key];
if (typeof val === undefined || val === null) {
val = '';
}
else if (shared.isPlainObject(val)) {
val = JSON.stringify(val);
}
return encodeStr(key) + '=' + encodeStr(val);
})
.filter(x => x.length > 0)
.join('&')
: null;
return res ? `?${res}` : '';
}
const BUILT_IN_TAGS = [
'uni-ad',
'uni-audio',
'uni-button',
'uni-camera',
'uni-canvas',
'uni-checkbox',
'uni-checkbox-group',
'uni-cover-image',
'uni-cover-view',
'uni-editor',
'uni-form',
'uni-functional-page-navigator',
'uni-icon',
'uni-image',
'uni-input',
'uni-label',
'uni-live-player',
'uni-live-pusher',
'uni-map',
'uni-movable-area',
'uni-movable-view',
'uni-navigator',
'uni-official-account',
'uni-open-data',
'uni-picker',
'uni-picker-view',
'uni-picker-view-column',
'uni-progress',
'uni-radio',
'uni-radio-group',
'uni-rich-text',
'uni-scroll-view',
'uni-slider',
'uni-swiper',
'uni-swiper-item',
'uni-switch',
'uni-text',
'uni-textarea',
'uni-video',
'uni-view',
'uni-web-view'
];
const TAGS = [
'uni-app',
'uni-layout',
'uni-content',
'uni-main',
'uni-top-window',
'uni-left-window',
'uni-right-window',
'uni-tabbar',
'uni-page',
'uni-page-head',
'uni-page-wrapper',
'uni-page-body',
'uni-page-refresh',
'uni-actionsheet',
'uni-modal',
'uni-toast',
'uni-resize-sensor',
'uni-shadow-root'
];
function isBuiltInComponent(tag) {
return BUILT_IN_TAGS.indexOf('uni-' + tag) !== -1;
}
function isCustomElement(tag) {
return TAGS.indexOf(tag) !== -1 || BUILT_IN_TAGS.indexOf(tag) !== -1;
}
exports.BUILT_IN_TAGS = BUILT_IN_TAGS;
exports.COMPONENT_NAME_PREFIX = COMPONENT_NAME_PREFIX;
exports.NAVBAR_HEIGHT = NAVBAR_HEIGHT;
exports.TABBAR_HEIGHT = TABBAR_HEIGHT;
exports.TAGS = TAGS;
exports.debounce = debounce;
exports.isBuiltInComponent = isBuiltInComponent;
exports.isCustomElement = isCustomElement;
exports.plusReady = plusReady;
exports.stringifyQuery = stringifyQuery;
export declare const BUILT_IN_TAGS: string[];
export declare const COMPONENT_NAME_PREFIX = "VUni";
export declare function debounce(fn: Function, delay: number): {
(this: any): void;
cancel(): void;
};
export declare function isBuiltInComponent(tag: string): boolean;
export declare function isCustomElement(tag: string): boolean;
export declare const NAVBAR_HEIGHT = 44;
export declare function plusReady(callback: () => void): void;
export declare function stringifyQuery(obj?: Record<string, any>, encodeStr?: typeof encodeURIComponent): string;
export declare const TABBAR_HEIGHT = 50;
export declare const TAGS: string[];
export { }
......@@ -47,25 +47,7 @@ function stringifyQuery(obj, encodeStr = encode) {
return res ? `?${res}` : '';
}
const TAGS = [
'uni-app',
'uni-layout',
'uni-content',
'uni-main',
'uni-top-window',
'uni-left-window',
'uni-right-window',
'uni-tabbar',
'uni-page',
'uni-page-head',
'uni-page-wrapper',
'uni-page-body',
'uni-page-refresh',
'uni-actionsheet',
'uni-modal',
'uni-toast',
'uni-resize-sensor',
'uni-shadow-root',
const BUILT_IN_TAGS = [
'uni-ad',
'uni-audio',
'uni-button',
......@@ -108,8 +90,31 @@ const TAGS = [
'uni-view',
'uni-web-view'
];
const TAGS = [
'uni-app',
'uni-layout',
'uni-content',
'uni-main',
'uni-top-window',
'uni-left-window',
'uni-right-window',
'uni-tabbar',
'uni-page',
'uni-page-head',
'uni-page-wrapper',
'uni-page-body',
'uni-page-refresh',
'uni-actionsheet',
'uni-modal',
'uni-toast',
'uni-resize-sensor',
'uni-shadow-root'
];
function isBuiltInComponent(tag) {
return BUILT_IN_TAGS.indexOf('uni-' + tag) !== -1;
}
function isCustomElement(tag) {
return TAGS.indexOf(tag) !== -1;
return TAGS.indexOf(tag) !== -1 || BUILT_IN_TAGS.indexOf(tag) !== -1;
}
export { COMPONENT_NAME_PREFIX, NAVBAR_HEIGHT, TABBAR_HEIGHT, TAGS, debounce, isCustomElement, plusReady, stringifyQuery };
export { BUILT_IN_TAGS, COMPONENT_NAME_PREFIX, NAVBAR_HEIGHT, TABBAR_HEIGHT, TAGS, debounce, isBuiltInComponent, isCustomElement, plusReady, stringifyQuery };
......@@ -2,8 +2,9 @@
"name": "@dcloudio/uni-shared",
"version": "3.0.0",
"description": "@dcloudio/uni-shared",
"main": "dist/uni.shared.esm.js",
"module": "dist/uni.shared.esm.js",
"main": "dist/uni-shared.cjs.js",
"module": "dist/uni-shared.esm.js",
"types": "dist/uni-shared.d.ts",
"files": [
"dist"
],
......
export function debounce(fn: Function, delay: number) {
let timeout: number
let timeout: any
const newFn = function(this: any) {
clearTimeout(timeout)
const timerFn = () => fn.apply(this, arguments)
......
export const TAGS = [
'uni-app',
'uni-layout',
'uni-content',
'uni-main',
'uni-top-window',
'uni-left-window',
'uni-right-window',
'uni-tabbar',
'uni-page',
'uni-page-head',
'uni-page-wrapper',
'uni-page-body',
'uni-page-refresh',
'uni-actionsheet',
'uni-modal',
'uni-toast',
'uni-resize-sensor',
'uni-shadow-root',
export const BUILT_IN_TAGS = [
'uni-ad',
'uni-audio',
'uni-button',
......@@ -61,6 +42,31 @@ export const TAGS = [
'uni-web-view'
]
export const TAGS = [
'uni-app',
'uni-layout',
'uni-content',
'uni-main',
'uni-top-window',
'uni-left-window',
'uni-right-window',
'uni-tabbar',
'uni-page',
'uni-page-head',
'uni-page-wrapper',
'uni-page-body',
'uni-page-refresh',
'uni-actionsheet',
'uni-modal',
'uni-toast',
'uni-resize-sensor',
'uni-shadow-root'
]
export function isBuiltInComponent(tag: string) {
return BUILT_IN_TAGS.indexOf('uni-' + tag) !== -1
}
export function isCustomElement(tag: string) {
return TAGS.indexOf(tag) !== -1
return TAGS.indexOf(tag) !== -1 || BUILT_IN_TAGS.indexOf(tag) !== -1
}
{
"compilerOptions": {
"outDir": "dist",
"sourceMap": false,
"target": "esnext",
"module": "esnext",
"moduleResolution": "node",
"allowJs": false,
"strict": true,
"noUnusedLocals": true,
"experimentalDecorators": true,
"resolveJsonModule": true,
"esModuleInterop": true,
"removeComments": false,
"lib": ["ESNext", "DOM"]
},
"include": ["src"]
}
......@@ -21,7 +21,8 @@
},
"license": "Apache-2.0",
"dependencies": {
"@rollup/pluginutils": "^4.0.0",
"@dcloudio/uni-cli-shared": "^3.0.0",
"@rollup/pluginutils": "^4.1.0",
"estree-walker": "^2.0.1",
"magic-string": "^0.25.7",
"slash": "^3.0.0"
......
......@@ -3,3 +3,4 @@ export * from './resolvers'
export * from './optimizeDeps'
export * from './configureServer'
export * from './rollupInputOptions'
export * from './vueCompilerOptions'
import { CompilerOptions } from '@vue/compiler-sfc'
import {
transformEasycom,
transformBuiltInComponent
} from '@dcloudio/uni-cli-shared'
export const vueCompilerOptions: CompilerOptions = {
nodeTransforms: [transformEasycom, transformBuiltInComponent]
}
{
"extends": "../../tsconfig.node.json",
"compilerOptions": {
"rootDir": "src",
"baseUrl": "./",
"target": "esnext",
"moduleResolution": "node",
"strict": true,
"declaration": true,
"noUnusedLocals": true,
"esModuleInterop": true,
"outDir": "./dist",
"module": "commonjs",
"lib": ["ESNext", "DOM"],
"sourceMap": false,
"paths": {
"@dcloudio/uni-cli-shared": ["../uni-cli-shared"]
}
}
"outDir": "dist"
},
"include": ["src"]
}
......@@ -15,23 +15,38 @@ const packageDir = path.resolve(packagesDir, process.env.TARGET)
const resolve = p => path.resolve(packageDir, p)
const pkg = require(resolve(`package.json`))
// ensure TS checks only once for each build
let hasTSChecked = false
const configs = []
const buildOptions = require(resolve(`build.json`))
Object.keys(buildOptions.input).forEach(name => {
configs.push(
createConfig(name, {
file: resolve(buildOptions.input[name]),
format: `es`
const files = buildOptions.input[name]
if (Array.isArray(files)) {
files.forEach(file => {
configs.push(
createConfig(name, {
file: resolve(file),
format: file.includes('.cjs.') ? 'cjs' : 'es'
})
)
})
)
} else {
configs.push(
createConfig(name, {
file: resolve(buildOptions.input[name]),
format: (buildOptions.output && buildOptions.output.format) || `es`
})
)
}
})
export default configs
function createConfig(entryFile, output, plugins = []) {
const shouldEmitDeclarations = process.env.TYPES != null
const shouldEmitDeclarations = process.env.TYPES != null && !hasTSChecked
const tsPlugin = ts({
check: process.env.NODE_ENV === 'production',
check: process.env.NODE_ENV === 'production' && !hasTSChecked,
tsconfig: path.resolve(__dirname, 'tsconfig.json'),
cacheRoot: path.resolve(__dirname, 'node_modules/.rts2_cache'),
tsconfigOverride: {
......@@ -44,10 +59,16 @@ function createConfig(entryFile, output, plugins = []) {
}
})
// we only need to check TS and generate declarations once for each build.
// it also seems to run into weird issues when checking multiple times
// during a single build.
hasTSChecked = true
const external = [
'@vue/shared',
...Object.keys(pkg.dependencies || {}),
...Object.keys(pkg.peerDependencies || {})
...Object.keys(pkg.peerDependencies || {}),
...(buildOptions.external || [])
]
return {
......
const fs = require('fs-extra')
const path = require('path')
const chalk = require('chalk')
exports.extract = async function extract(target) {
const pkgDir = path.resolve(`packages/${target}`)
console.log()
console.log(
chalk.bold(chalk.yellow(`Rolling up type definitions for ${target}...`))
)
// build types
const { Extractor, ExtractorConfig } = require('@microsoft/api-extractor')
const extractorConfigPath = path.resolve(pkgDir, `api-extractor.json`)
const extractorConfig = ExtractorConfig.loadFileAndPrepare(
extractorConfigPath
)
const extractorResult = Extractor.invoke(extractorConfig, {
localBuild: true,
showVerboseMessages: true
})
if (extractorResult.succeeded) {
console.log(
chalk.bold(chalk.green(`API Extractor completed successfully.`))
)
} else {
console.error(
`API Extractor completed with ${extractorResult.errorCount} errors` +
` and ${extractorResult.warningCount} warnings`
)
process.exitCode = 1
}
await fs.remove(`${pkgDir}/dist/packages`)
}
......@@ -4,6 +4,9 @@ const chalk = require('chalk')
const execa = require('execa')
const { gzipSync } = require('zlib')
const { compress } = require('brotli')
const { extract } = require('./apiExtractor')
const { targets: allTargets, fuzzyMatchTarget } = require('./utils')
const args = require('minimist')(process.argv.slice(2))
......@@ -11,6 +14,7 @@ const targets = args._
const formats = args.formats || args.f
const devOnly = args.devOnly || args.d
const isRelease = args.release
const buildTypes = args.t || args.types || isRelease
const buildAllMatching = args.all || args.a
run()
......@@ -42,7 +46,7 @@ async function build(target) {
}
const bundler = pkg.buildOptions && pkg.buildOptions.bundler
const types = buildTypes && pkg.types
// if building a specific format, do not remove dist.
if (!formats && bundler !== 'vite') {
await fs.remove(`${pkgDir}/dist`)
......@@ -59,9 +63,13 @@ async function build(target) {
}
)
} else if (bundler === 'tsc') {
return await execa('tsc', ['--listEmittedFiles', '-p', pkgDir], {
stdio: 'inherit'
})
return await execa(
'tsc',
['--listEmittedFiles', types ? `--declaration` : '', '-p', pkgDir],
{
stdio: 'inherit'
}
)
}
await execa(
......@@ -69,10 +77,15 @@ async function build(target) {
[
'-c',
'--environment',
[`NODE_ENV:${env}`, `TARGET:${target}`].filter(Boolean).join(',')
[`NODE_ENV:${env}`, types ? `TYPES:true` : ``, `TARGET:${target}`]
.filter(Boolean)
.join(',')
],
{ stdio: 'inherit' }
)
if (types) {
await extract(target)
}
}
function checkAllSizes(targets) {
......
{
"compilerOptions": {
"target": "esnext",
"moduleResolution": "node",
"strict": true,
"declaration": false,
"noUnusedLocals": true,
"esModuleInterop": true,
"outDir": "dist",
"module": "commonjs",
"lib": ["ESNext", "DOM"],
"sourceMap": false
}
}
此差异已折叠。
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册