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

feat(uts): init

上级 db371cb5
......@@ -48,7 +48,7 @@ module.exports = {
'jest.config.js',
'rollup.config.js',
'scripts/**',
'packages/{uni-cli-shared,uni-app-vite,uni-h5-vite,uni-mp-vite,uni-mp-compiler,vite-plugin-uni}/**',
'packages/{uni-cli-shared,uni-app-vite,uni-h5-vite,uni-mp-vite,uni-mp-compiler,vite-plugin-uni,uts}/**',
'packages/*/vite.config.ts',
],
rules: {
......
......@@ -2,13 +2,16 @@
"private": true,
"name": "@dcloudio/size-check",
"version": "3.0.0-alpha-3040820220424001",
"dependencies": {
"@dcloudio/uni-app": "3.0.0-alpha-3040820220424001",
"@dcloudio/uni-h5": "3.0.0-alpha-3040820220424001",
"vue": "^3.2.31",
"vue-i18n": "9.1.9",
"vuex": "^4.0.2"
},
"devDependencies": {
"@dcloudio/uni-cli-shared": "3.0.0-alpha-3040820220424001",
"@dcloudio/uni-components": "3.0.0-alpha-3040820220424001",
"@dcloudio/uni-h5": "3.0.0-alpha-3040820220424001",
"@dcloudio/uni-h5-vite": "3.0.0-alpha-3040820220424001",
"@dcloudio/uni-h5-vue": "3.0.0-alpha-3040820220424001",
"@dcloudio/uni-i18n": "3.0.0-alpha-3040820220424001",
"@dcloudio/vite-plugin-uni": "3.0.0-alpha-3040820220424001"
}
}
import path from 'path'
import { terser } from 'rollup-plugin-terser'
import uniH5VitePlugins from '@dcloudio/uni-h5-vite'
import uni from '@dcloudio/vite-plugin-uni'
import { UserConfig } from 'vite'
......@@ -21,5 +20,5 @@ export default {
},
},
plugins: [...uniH5VitePlugins, uni({ viteLegacyOptions: false })],
plugins: [uni({ viteLegacyOptions: false })],
} as UserConfig
#!/usr/bin/env node
require('../dist/uts/cli.js')
......@@ -2,9 +2,13 @@
"name": "@dcloudio/uni-app-vite",
"version": "3.0.0-alpha-3040820220424001",
"description": "uni-app-vite",
"bin": {
"uts": "bin/uts.js"
},
"main": "dist/index.js",
"types": "dist/index.d.ts",
"files": [
"bin",
"dist",
"lib"
],
......@@ -23,11 +27,15 @@
"@dcloudio/uni-cli-shared": "3.0.0-alpha-3040820220424001",
"@dcloudio/uni-i18n": "3.0.0-alpha-3040820220424001",
"@dcloudio/uni-shared": "3.0.0-alpha-3040820220424001",
"@dcloudio/uts": "3.0.0-alpha-3040820220424001",
"@rollup/pluginutils": "^4.2.0",
"@vitejs/plugin-vue": "^2.3.1",
"@vue/compiler-dom": "3.2.33",
"@vue/compiler-sfc": "3.2.33",
"cac": "6.7.9",
"chokidar": "^3.5.3",
"debug": "^4.3.3",
"fast-glob": "^3.2.11",
"fs-extra": "^10.0.0",
"picocolors": "^1.0.0",
"rollup": "^2.59.0"
......@@ -38,5 +46,8 @@
"@vue/compiler-core": "3.2.33",
"esbuild": "^0.14.27",
"postcss": "^8.4.13"
},
"optionalDependencies": {
"@dcloudio/uts-darwin-arm64": "3.0.0-alpha-3040820220424001"
}
}
import { cac } from 'cac'
import { toKotlin } from '.'
const cli = cac('uts')
export interface CliOptions {
target: 'kotlin' | 'swift'
output: string
sourcemap: boolean
watch: boolean
}
cli
.command('<root>')
.option('-t, --target <target>', '[string] kotlin | swift', {
default: 'kotlin',
})
.option('-o, --output <output>', `[string] output dir path`)
.option('-s, --sourcemap', `[boolean] output sourcemap`, {
default: false,
})
.option('-w, --watch', `[boolean] rebuilds when uts have changed on disk`, {
default: false,
})
.action((root, opts: CliOptions) => {
console.log('opts', root, opts)
if (opts.target === 'kotlin') {
toKotlin({
watch: opts.watch,
input: {
dir: root,
},
output: {
dir: opts.output,
sourceMap: opts.sourcemap,
},
})
}
})
cli.help()
cli.version(require('../../package.json').version)
cli.parse()
import fs from 'fs'
import path from 'path'
import glob from 'fast-glob'
// import { toKotlin } from '@dcloudio/uts'
import { normalizePath } from '@dcloudio/uni-cli-shared'
interface ToOptions {
watch?: boolean
input: {
dir: string
}
output: {
dir: string
sourceMap?: boolean
}
}
interface ToKotlinOptions extends ToOptions {}
function parseKotlinOptions(opts: Partial<ToKotlinOptions>) {
const { input, output } = opts
if (!input?.dir) {
throw new Error(`input.dir is required`)
}
if (!output?.dir) {
throw new Error(`output.dir is required`)
}
if (!fs.existsSync(input.dir)) {
throw new Error(`${input} is not found`)
}
return opts as ToKotlinOptions
}
function watchKotlin(opts: ToKotlinOptions) {}
function buildKotlin({ input: { dir: inputDir } }: ToKotlinOptions) {
const files = glob.sync(normalizePath(path.join(inputDir, '**/*.uts')))
console.log(files)
}
export function toKotlin(opts: ToKotlinOptions) {
opts = parseKotlinOptions(opts)
return opts.watch ? watchKotlin(opts) : buildKotlin(opts)
}
......@@ -60,12 +60,16 @@
},
"gitHead": "33e807d66e1fe47e2ee08ad9c59247e37b8884da",
"devDependencies": {
"@types/babel__core": "^7.1.19",
"@types/debug": "^4.1.7",
"@types/estree": "^0.0.51",
"@types/fs-extra": "^9.0.13",
"@types/hash-sum": "^1.0.0",
"@types/less": "^3.0.3",
"@types/mime": "^2.0.3",
"@types/module-alias": "^2.0.1",
"@types/resolve": "^1.20.2",
"@types/sass": "^1.43.1",
"@types/stylus": "^0.48.36",
"postcss": "^8.4.13"
}
......
......@@ -2,7 +2,7 @@ import { sep } from 'path'
import debug from 'debug'
import type { Plugin } from 'vite'
import { BaseNode, Program, Identifier } from 'estree'
import type { BaseNode, Program, Identifier } from 'estree'
import {
attachScopes,
......
......@@ -36,6 +36,7 @@
"@types/fs-extra": "^9.0.13",
"@types/mime": "^2.0.3",
"@types/module-alias": "^2.0.1",
"@types/resolve": "^1.20.2",
"@vue/compiler-core": "3.2.33",
"esbuild": "^0.14.27"
}
......
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports[Symbol.toStringTag] = "Module";
Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
var vue = require("vue");
var shared = require("@vue/shared");
var uniShared = require("@dcloudio/uni-shared");
......@@ -10078,9 +10077,8 @@ const setNavigationBarTitle = /* @__PURE__ */ defineAsyncApi(API_SET_NAVIGATION_
}, SetNavigationBarTitleProtocol);
require("localstorage-polyfill");
global.XMLHttpRequest = require("xmlhttprequest").XMLHttpRequest;
var api = {
var api = /* @__PURE__ */ Object.defineProperty({
__proto__: null,
[Symbol.toStringTag]: "Module",
setNavigationBarTitle,
request,
setStorageSync,
......@@ -10094,7 +10092,7 @@ var api = {
getStorageInfoSync,
getStorageInfo,
getSystemInfoSync
};
}, Symbol.toStringTag, { value: "Module" });
const uni$1 = api;
const UniServiceJSBridge$1 = /* @__PURE__ */ shared.extend(ServiceJSBridge, {
publishHandler(event, args, pageId) {
......
......@@ -1325,12 +1325,11 @@ function normalizeTouchEvent(touches, top) {
}
return res;
}
var instance = {
var instance = /* @__PURE__ */ Object.defineProperty({
__proto__: null,
[Symbol.toStringTag]: "Module",
$nne,
createNativeEvent
};
}, Symbol.toStringTag, { value: "Module" });
function initAppConfig$1(appConfig) {
const globalProperties = appConfig.globalProperties;
extend(globalProperties, instance);
......@@ -1450,15 +1449,14 @@ function selectComponent(selector) {
function selectAllComponents(selector) {
return querySelectorAll(this, selector);
}
var wxInstance = {
var wxInstance = /* @__PURE__ */ Object.defineProperty({
__proto__: null,
[Symbol.toStringTag]: "Module",
createSelectorQuery: createSelectorQuery$1,
createMediaQueryObserver: createMediaQueryObserver$1,
createIntersectionObserver: createIntersectionObserver$1,
selectComponent,
selectAllComponents
};
}, Symbol.toStringTag, { value: "Module" });
function getOpenerEventChannel() {
{
if (this.$route) {
......@@ -20088,9 +20086,8 @@ const API_LOGIN = "login";
const login = /* @__PURE__ */ defineAsyncApi(API_LOGIN, createUnsupportedAsyncApi(API_LOGIN));
const API_GET_PROVIDER = "getProvider";
const getProvider = /* @__PURE__ */ defineAsyncApi(API_GET_PROVIDER, createUnsupportedAsyncApi(API_GET_PROVIDER));
var api = {
var api = /* @__PURE__ */ Object.defineProperty({
__proto__: null,
[Symbol.toStringTag]: "Module",
upx2px,
addInterceptor,
removeInterceptor,
......@@ -20254,7 +20251,7 @@ var api = {
addPhoneContact,
login,
getProvider
};
}, Symbol.toStringTag, { value: "Module" });
const CONTEXT_ID = "MAP_LOCATION";
var MapLocation = /* @__PURE__ */ defineSystemComponent({
name: "MapLocation",
......
......@@ -30,6 +30,7 @@
"estree-walker": "^2.0.2"
},
"devDependencies": {
"@types/babel__generator": "^7.6.4",
"@vue/compiler-sfc": "3.2.33",
"source-map": "^0.6.1"
}
......
{
"name": "@dcloudio/uts-darwin-arm64",
"version": "3.0.0-alpha-3040820220424001",
"os": [
"darwin"
],
"cpu": [
"arm64"
],
"main": "uts.darwin-arm64.node",
"files": [
"uts.darwin-arm64.node"
],
"engines": {
"node": ">=10"
},
"repository": {
"type": "git",
"url": "git+https://github.com/dcloudio/uni-app.git",
"directory": "packages/uts-darwin-arm64"
}
}
declare const _default: any;
export default _default;
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const fs_1 = __importDefault(require("fs"));
function isMusl() {
// For Node 10
if (!process.report || typeof process.report.getReport !== 'function') {
try {
return fs_1.default.readFileSync('/usr/bin/ldd', 'utf8').includes('musl');
}
catch (e) {
return true;
}
}
else {
const { glibcVersionRuntime } = process.report.getReport().header;
return !glibcVersionRuntime;
}
}
function resolveNativeBinding() {
const { platform, arch } = process;
let nativeBinding = '';
switch (platform) {
case 'android':
switch (arch) {
case 'arm64':
nativeBinding = 'uts-android-arm64';
break;
case 'arm':
nativeBinding = 'uts-android-arm-eabi';
break;
default:
throw new Error(`Unsupported architecture on Android ${arch}`);
}
break;
case 'win32':
switch (arch) {
case 'x64':
nativeBinding = 'uts-win32-x64-msvc';
break;
case 'ia32':
nativeBinding = 'uts-win32-ia32-msvc';
break;
case 'arm64':
nativeBinding = 'uts-win32-arm64-msvc';
break;
default:
throw new Error(`Unsupported architecture on Windows: ${arch}`);
}
break;
case 'darwin':
switch (arch) {
case 'x64':
nativeBinding = 'uts-darwin-x64';
break;
case 'arm64':
nativeBinding = 'uts-darwin-arm64';
break;
default:
throw new Error(`Unsupported architecture on macOS: ${arch}`);
}
break;
case 'freebsd':
if (arch !== 'x64') {
throw new Error(`Unsupported architecture on FreeBSD: ${arch}`);
}
nativeBinding = 'uts-freebsd-x64';
break;
case 'linux':
switch (arch) {
case 'x64':
if (isMusl()) {
nativeBinding = 'uts-linux-x64-musl';
}
else {
nativeBinding = 'uts-linux-x64-gnu';
}
break;
case 'arm64':
if (isMusl()) {
nativeBinding = 'uts-linux-arm64-musl';
}
else {
nativeBinding = 'uts-linux-arm64-gnu';
}
break;
case 'arm':
nativeBinding = 'uts-linux-arm-gnueabihf';
break;
default:
throw new Error(`Unsupported architecture on Linux: ${arch}`);
}
break;
default:
throw new Error(`Unsupported OS: ${platform}, architecture: ${arch}`);
}
return require('@dcloudio/' + nativeBinding);
}
exports.default = resolveNativeBinding();
import { UtsKotlinOptions, UtsResult, UtsSwiftOptions } from './types';
export * from './types';
export declare function toKotlin(options: UtsKotlinOptions): Promise<UtsResult>;
export declare function toSwift(options: UtsSwiftOptions): Promise<UtsResult>;
"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __exportStar = (this && this.__exportStar) || function(m, exports) {
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.toSwift = exports.toKotlin = void 0;
const path_1 = require("path");
__exportStar(require("./types"), exports);
// Allow overrides to the location of the .node binding file
const bindingsOverride = process.env['UTS_BINARY_PATH'];
const bindings = !!bindingsOverride
? require((0, path_1.resolve)(bindingsOverride))
: require('./binding').default;
function toKotlin(options) {
const result = Promise.resolve({});
const { input, output } = options;
if (!(input === null || input === void 0 ? void 0 : input.root)) {
return result;
}
if (!(input === null || input === void 0 ? void 0 : input.filename)) {
return result;
}
if (!(output === null || output === void 0 ? void 0 : output.outDir)) {
return result;
}
return bindings.toKotlin(toBuffer(options));
}
exports.toKotlin = toKotlin;
function toSwift(options) {
return bindings.toSwift(toBuffer(options));
}
exports.toSwift = toSwift;
function toBuffer(t) {
return Buffer.from(JSON.stringify(t));
}
export declare type UtsTarget = 'es3' | 'es5' | 'es2015' | 'es2016' | 'es2017' | 'es2018' | 'es2019' | 'es2020' | 'es2021' | 'es2022';
export interface UtsParserConfig {
/**
* Defaults to `false`.
*/
tsx?: boolean;
/**
* Defaults to `false`.
*/
decorators?: boolean;
/**
* Defaults to `false`
*/
dynamicImport?: boolean;
}
export declare type UtsParseOptions = UtsParserConfig & {
filename?: string;
comments?: boolean;
/**
* default es2022
*/
target?: UtsTarget;
};
export declare type InputKotlinOptions = UtsParseOptions & {
root: string;
filename: string;
namespace?: string;
};
export declare type OutputKotlinOptions = {
outDir: string;
sourceMap: boolean | string;
};
export interface UtsKotlinOptions {
input: InputKotlinOptions;
output: OutputKotlinOptions;
}
export declare type InputSwiftOptions = UtsParseOptions;
export declare type OutputSwiftOptions = {};
export interface UtsSwiftOptions {
input: InputSwiftOptions;
output: OutputSwiftOptions;
}
export interface UtsResult {
}
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
{
"name": "@dcloudio/uts",
"version": "3.0.0-alpha-3040820220424001",
"description": "uts",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"files": [
"dist"
],
"repository": {
"type": "git",
"url": "git+https://github.com/dcloudio/uni-app.git",
"directory": "packages/uts"
}
}
import fs from 'fs'
function isMusl() {
// For Node 10
if (!process.report || typeof process.report.getReport !== 'function') {
try {
return fs.readFileSync('/usr/bin/ldd', 'utf8').includes('musl')
} catch (e) {
return true
}
} else {
const { glibcVersionRuntime } = (process.report.getReport() as any).header
return !glibcVersionRuntime
}
}
function resolveNativeBinding() {
const { platform, arch } = process
let nativeBinding: string = ''
switch (platform) {
case 'android':
switch (arch) {
case 'arm64':
nativeBinding = 'uts-android-arm64'
break
case 'arm':
nativeBinding = 'uts-android-arm-eabi'
break
default:
throw new Error(`Unsupported architecture on Android ${arch}`)
}
break
case 'win32':
switch (arch) {
case 'x64':
nativeBinding = 'uts-win32-x64-msvc'
break
case 'ia32':
nativeBinding = 'uts-win32-ia32-msvc'
break
case 'arm64':
nativeBinding = 'uts-win32-arm64-msvc'
break
default:
throw new Error(`Unsupported architecture on Windows: ${arch}`)
}
break
case 'darwin':
switch (arch) {
case 'x64':
nativeBinding = 'uts-darwin-x64'
break
case 'arm64':
nativeBinding = 'uts-darwin-arm64'
break
default:
throw new Error(`Unsupported architecture on macOS: ${arch}`)
}
break
case 'freebsd':
if (arch !== 'x64') {
throw new Error(`Unsupported architecture on FreeBSD: ${arch}`)
}
nativeBinding = 'uts-freebsd-x64'
break
case 'linux':
switch (arch) {
case 'x64':
if (isMusl()) {
nativeBinding = 'uts-linux-x64-musl'
} else {
nativeBinding = 'uts-linux-x64-gnu'
}
break
case 'arm64':
if (isMusl()) {
nativeBinding = 'uts-linux-arm64-musl'
} else {
nativeBinding = 'uts-linux-arm64-gnu'
}
break
case 'arm':
nativeBinding = 'uts-linux-arm-gnueabihf'
break
default:
throw new Error(`Unsupported architecture on Linux: ${arch}`)
}
break
default:
throw new Error(`Unsupported OS: ${platform}, architecture: ${arch}`)
}
return require('@dcloudio/' + nativeBinding)
}
export default resolveNativeBinding()
import { resolve } from 'path'
import { UtsKotlinOptions, UtsResult, UtsSwiftOptions } from './types'
export * from './types'
// Allow overrides to the location of the .node binding file
const bindingsOverride = process.env['UTS_BINARY_PATH']
const bindings = !!bindingsOverride
? require(resolve(bindingsOverride))
: require('./binding').default
export function toKotlin(options: UtsKotlinOptions): Promise<UtsResult> {
const result = Promise.resolve({})
const { input, output } = options
if (!input?.root) {
return result
}
if (!input?.filename) {
return result
}
if (!output?.outDir) {
return result
}
return bindings.toKotlin(toBuffer(options))
}
export function toSwift(options: UtsSwiftOptions): Promise<UtsResult> {
return bindings.toSwift(toBuffer(options))
}
function toBuffer(t: any): Buffer {
return Buffer.from(JSON.stringify(t))
}
export type UtsTarget =
| 'es3'
| 'es5'
| 'es2015'
| 'es2016'
| 'es2017'
| 'es2018'
| 'es2019'
| 'es2020'
| 'es2021'
| 'es2022'
export interface UtsParserConfig {
/**
* Defaults to `false`.
*/
tsx?: boolean
/**
* Defaults to `false`.
*/
decorators?: boolean
/**
* Defaults to `false`
*/
dynamicImport?: boolean
}
export type UtsParseOptions = UtsParserConfig & {
filename?: string
comments?: boolean
/**
* default es2022
*/
target?: UtsTarget
}
export type InputKotlinOptions = UtsParseOptions & {
root: string
filename: string
namespace?: string
}
export type OutputKotlinOptions = {
outDir: string
sourceMap: boolean | string
}
export interface UtsKotlinOptions {
input: InputKotlinOptions
output: OutputKotlinOptions
}
export type InputSwiftOptions = UtsParseOptions
export type OutputSwiftOptions = {}
export interface UtsSwiftOptions {
input: InputSwiftOptions
output: OutputSwiftOptions
}
export interface UtsResult {}
{
"extends": "../../tsconfig.node.json",
"compilerOptions": {
"outDir": "dist"
},
"include": ["src"]
}
......@@ -46,6 +46,7 @@
},
"devDependencies": {
"@types/debug": "^4.1.7",
"@types/estree": "^0.0.51",
"@types/express": "^4.17.12",
"@types/fs-extra": "^9.0.13",
"@types/sass": "^1.16.0",
......
......@@ -89,14 +89,18 @@ export function initExtraPlugins(
platform: UniApp.PLATFORM,
options: VitePluginUniResolvedOptions
) {
return initPlugins(resolvePlugins(cliRoot, platform), options)
return initPlugins(cliRoot, resolvePlugins(cliRoot, platform), options)
}
function initPlugin(
cliRoot: string,
{ id, config: { main } }: PluginConfig,
options: VitePluginUniResolvedOptions
): Plugin | void {
let plugin = require(path.join(id, main || '/lib/uni.plugin.js'))
let plugin = require(require.resolve(
path.join(id, main || '/lib/uni.plugin.js'),
{ paths: [cliRoot] }
))
plugin = plugin.default || plugin
if (isFunction(plugin)) {
plugin = plugin(options)
......@@ -105,11 +109,12 @@ function initPlugin(
}
function initPlugins(
cliRoot: string,
plugins: PluginConfig[],
options: VitePluginUniResolvedOptions
): Plugin[] {
return plugins
.map((plugin) => initPlugin(plugin, options))
.map((plugin) => initPlugin(cliRoot, plugin, options))
.flat()
.filter<Plugin>(Boolean as any)
.map((plugin) => {
......@@ -126,7 +131,9 @@ function resolvePlugins(cliRoot: string, platform: UniApp.PLATFORM) {
.concat(Object.keys(pkg.dependencies || {}))
.map<PluginConfig | void>((id) => {
try {
const pluginPkg = require(id + '/package.json')
const pluginPkg = require(require.resolve(id + '/package.json', {
paths: [cliRoot],
}))
const config = pluginPkg['uni-app'] as PluginConfig
if (!config || !config.name) {
return
......
此差异已折叠。
......@@ -31,6 +31,7 @@ const priority = {
'vite-plugin-uni': 20,
'uni-cloud': 10,
'uni-automator': 10,
uts: 10,
'size-check': 1,
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册