CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-dcloudio--uni-cli-shared

Shared CLI utilities and tools for the uni-app cross-platform development framework

Pending

Quality

Pending

Does it follow best practices?

Impact

Pending

No eval scenarios have been run

SecuritybySnyk

Pending

The risk profile of this skill

Overview
Eval results
Files

uts.mddocs/

UTS Language Support

UniScript (UTS) language compilation, module resolution, and platform-specific transformations for native functionality in uni-app development. UTS enables developers to write native modules using TypeScript-like syntax that compiles to native code for Android and iOS platforms.

Capabilities

Module Resolution

Core UTS module resolution for different platforms with SDK integration.

/**
 * Resolves UTS app modules for specified platform with optional UTS SDK inclusion
 * @param platform - UTS platform target (Android, iOS, etc.)
 * @param id - Module identifier or path
 * @param importer - File path of the importing module
 * @param includeUTSSDK - Whether to include UTS SDK in resolution (defaults to true)
 * @returns Resolved module information or null if not found
 */
function resolveUTSAppModule(
  platform: UTSPlatform,
  id: string, 
  importer: string, 
  includeUTSSDK?: boolean
): UTSModuleResolution | null;

type UTSPlatform = 'android' | 'ios' | 'web' | 'harmony';

interface UTSModuleResolution {
  /** Resolved module path */
  resolvedPath: string;
  /** Platform-specific metadata */
  platformMeta?: Record<string, any>;
  /** Whether this is an SDK module */
  isSDK?: boolean;
}

Usage Example:

import { resolveUTSAppModule } from "@dcloudio/uni-cli-shared";

// Resolve UTS module for Android platform
const androidModule = resolveUTSAppModule(
  'android',
  '@/uni_modules/test-module',
  './src/pages/index.vue'
);

if (androidModule) {
  console.log('Android module path:', androidModule.resolvedPath);
  console.log('Is SDK module:', androidModule.isSDK);
}

// Resolve UTS module for iOS without SDK
const iosModule = resolveUTSAppModule(
  'ios',
  './utils/native-helper',
  './src/components/camera.vue',
  false // Exclude UTS SDK
);

// Resolve cross-platform UTS module
const webModule = resolveUTSAppModule(
  'web',
  'uni-native-bridge',
  './src/hybrid/webview.vue'
);

UTS Utils Module

Extended UTS utilities and helper functions for advanced UTS development.

// UTS utility functions (from ./utsUtils module)
// Comprehensive UTS development utilities available through main export

The utsUtils module provides additional utilities for:

  • UTS code transformations
  • Platform-specific compilation
  • Native bridge generation
  • Type checking and validation

UTS Development Workflow

Module Structure

UTS modules follow a specific structure for cross-platform compatibility:

uni_modules/
  my-uts-module/
    utssdk/
      app-android/
        index.uts          // Android implementation
        native.kt          // Kotlin native code
      app-ios/
        index.uts          // iOS implementation  
        native.swift       // Swift native code
      web/
        index.uts          // Web implementation
      interface.uts        // Cross-platform interface

Platform Resolution

import { resolveUTSAppModule } from "@dcloudio/uni-cli-shared";

// Build system integration
function buildUTSModule(modulePath: string, targetPlatform: string) {
  const resolution = resolveUTSAppModule(
    targetPlatform as UTSPlatform,
    modulePath,
    './src/main.ts',
    true // Include UTS SDK for native APIs
  );
  
  if (resolution) {
    if (resolution.isSDK) {
      // Handle UTS SDK module
      return compileUTSSDKModule(resolution);
    } else {
      // Handle user-defined UTS module
      return compileUTSUserModule(resolution);
    }
  } else {
    throw new Error(`UTS module not found: ${modulePath}`);
  }
}

Native Bridge Generation

import { resolveUTSAppModule } from "@dcloudio/uni-cli-shared";

// Generate native bridge code for UTS modules
async function generateNativeBridge(
  moduleId: string, 
  platforms: UTSPlatform[]
) {
  const bridges = {};
  
  for (const platform of platforms) {
    const module = resolveUTSAppModule(
      platform,
      moduleId,
      './src/app.vue'
    );
    
    if (module) {
      bridges[platform] = {
        path: module.resolvedPath,
        bridgeCode: await generatePlatformBridge(module, platform)
      };
    }
  }
  
  return bridges;
}

UTS Compilation Integration

// Vite plugin integration for UTS compilation
import { resolveUTSAppModule } from "@dcloudio/uni-cli-shared";

const utsPlugin = () => ({
  name: 'uts-resolver',
  resolveId(id: string, importer?: string) {
    if (id.startsWith('uni_modules/') && id.includes('.uts')) {
      const platform = this.meta?.platform || 'web';
      const resolution = resolveUTSAppModule(
        platform,
        id,
        importer || '',
        true
      );
      
      return resolution?.resolvedPath || null;
    }
  },
  
  load(id: string) {
    if (id.endsWith('.uts')) {
      // Compile UTS to target platform
      return compileUTSSource(id);
    }
  }
});

Platform-Specific Features

Android UTS Support

// Android-specific UTS module resolution
const androidModule = resolveUTSAppModule(
  'android',
  '@/uni_modules/camera-plugin/utssdk/app-android',
  './src/pages/camera.vue'
);

// Typical Android UTS structure:
// - index.uts (TypeScript-like syntax)
// - native.kt (Kotlin implementation)  
// - AndroidManifest.xml (permissions)

iOS UTS Support

// iOS-specific UTS module resolution
const iosModule = resolveUTSAppModule(
  'ios',
  '@/uni_modules/camera-plugin/utssdk/app-ios', 
  './src/pages/camera.vue'
);

// Typical iOS UTS structure:
// - index.uts (TypeScript-like syntax)
// - native.swift (Swift implementation)
// - Info.plist (capabilities)

Web UTS Support

// Web fallback UTS module resolution
const webModule = resolveUTSAppModule(
  'web',
  '@/uni_modules/camera-plugin/utssdk/web',
  './src/pages/camera.vue'
);

// Web UTS provides JavaScript fallbacks for native functionality

HarmonyOS UTS Support

// HarmonyOS UTS module resolution
const harmonyModule = resolveUTSAppModule(
  'harmony',
  '@/uni_modules/system-plugin/utssdk/app-harmony',
  './src/pages/system.vue'
);

UTS SDK Integration

Including UTS SDK

import { resolveUTSAppModule } from "@dcloudio/uni-cli-shared";

// Resolve with UTS SDK (default behavior)
const moduleWithSDK = resolveUTSAppModule(
  'android',
  'device-info',
  './src/utils/device.ts',
  true // Include UTS SDK APIs
);

// UTS SDK provides:
// - Device information APIs
// - File system access
// - Network capabilities  
// - UI component access
// - Platform-specific services

Excluding UTS SDK

// Resolve without UTS SDK for lightweight modules
const lightweightModule = resolveUTSAppModule(
  'ios', 
  './utils/pure-logic',
  './src/calculations.ts',
  false // Exclude UTS SDK
);

// Use when module only contains:
// - Pure computation logic
// - Data transformation
// - Business logic without platform APIs

Advanced UTS Features

Type Safety

UTS provides TypeScript-compatible type checking:

// UTS interface definition (interface.uts)
interface CameraOptions {
  quality?: number;
  allowEdit?: boolean;
  encodingType?: 'JPEG' | 'PNG';
}

// Platform implementation maintains type safety
function openCamera(options: CameraOptions): Promise<string> {
  // Implementation varies by platform
  // But interface remains consistent
}

Cross-Platform Compatibility

import { resolveUTSAppModule } from "@dcloudio/uni-cli-shared";

// Ensure module is available on all target platforms
function validateUTSModule(moduleId: string): boolean {
  const platforms: UTSPlatform[] = ['android', 'ios', 'web'];
  
  return platforms.every(platform => {
    const resolution = resolveUTSAppModule(
      platform,
      moduleId,
      './src/main.ts'
    );
    return resolution !== null;
  });
}

// Usage in build validation
const isModuleComplete = validateUTSModule('@/uni_modules/my-plugin');
if (!isModuleComplete) {
  console.warn('UTS module missing platform implementations');
}

UTS language support enables powerful native functionality while maintaining uni-app's cross-platform development philosophy, allowing developers to access platform-specific APIs through a unified TypeScript-like interface.

Install with Tessl CLI

npx tessl i tessl/npm-dcloudio--uni-cli-shared

docs

build-tools.md

constants-types.md

development-tools.md

filesystem.md

index.md

miniprogram.md

plugin-system.md

uts.md

vue-integration.md

tile.json