@dcloudio/uni-cli-shared
Advanced tools
Comparing version 3.0.0-alpha-4020820240920001 to 3.0.0-alpha-4030120240925001
@@ -25,5 +25,6 @@ export * from './fs'; | ||
export * from './utsUtils'; | ||
export { parseUniExtApi, parseUniExtApis, parseInjects, parseUniModulesArtifacts, Define, DefineOptions, Defines, getUniExtApiProviderRegisters, resolveEncryptUniModule, formatExtApiProviderName, } from './uni_modules'; | ||
export { parseUniExtApi, parseUniExtApis, parseInjects, Define, DefineOptions, Defines, getUniExtApiProviderRegisters, formatExtApiProviderName, } from './uni_modules'; | ||
export { parseUniModulesArtifacts, resolveEncryptUniModule, } from './uni_modules.cloud'; | ||
export { M } from './messages'; | ||
export * from './exports'; | ||
export { checkUpdate } from './checkUpdate'; |
@@ -17,3 +17,3 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.checkUpdate = exports.M = exports.formatExtApiProviderName = exports.resolveEncryptUniModule = exports.getUniExtApiProviderRegisters = exports.parseUniModulesArtifacts = exports.parseInjects = exports.parseUniExtApis = exports.parseUniExtApi = void 0; | ||
exports.checkUpdate = exports.M = exports.resolveEncryptUniModule = exports.parseUniModulesArtifacts = exports.formatExtApiProviderName = exports.getUniExtApiProviderRegisters = exports.parseInjects = exports.parseUniExtApis = exports.parseUniExtApi = void 0; | ||
__exportStar(require("./fs"), exports); | ||
@@ -47,6 +47,7 @@ __exportStar(require("./mp"), exports); | ||
Object.defineProperty(exports, "parseInjects", { enumerable: true, get: function () { return uni_modules_1.parseInjects; } }); | ||
Object.defineProperty(exports, "parseUniModulesArtifacts", { enumerable: true, get: function () { return uni_modules_1.parseUniModulesArtifacts; } }); | ||
Object.defineProperty(exports, "getUniExtApiProviderRegisters", { enumerable: true, get: function () { return uni_modules_1.getUniExtApiProviderRegisters; } }); | ||
Object.defineProperty(exports, "resolveEncryptUniModule", { enumerable: true, get: function () { return uni_modules_1.resolveEncryptUniModule; } }); | ||
Object.defineProperty(exports, "formatExtApiProviderName", { enumerable: true, get: function () { return uni_modules_1.formatExtApiProviderName; } }); | ||
var uni_modules_cloud_1 = require("./uni_modules.cloud"); | ||
Object.defineProperty(exports, "parseUniModulesArtifacts", { enumerable: true, get: function () { return uni_modules_cloud_1.parseUniModulesArtifacts; } }); | ||
Object.defineProperty(exports, "resolveEncryptUniModule", { enumerable: true, get: function () { return uni_modules_cloud_1.resolveEncryptUniModule; } }); | ||
var messages_1 = require("./messages"); | ||
@@ -53,0 +54,0 @@ Object.defineProperty(exports, "M", { enumerable: true, get: function () { return messages_1.M; } }); |
@@ -29,3 +29,3 @@ "use strict"; | ||
"useragent": { | ||
"value": "uni-app appservice", | ||
"value": "", | ||
"concatenate": true | ||
@@ -32,0 +32,0 @@ }, |
@@ -17,3 +17,13 @@ "use strict"; | ||
} | ||
manifestJson.plus.useragent.value = 'uni-app'; | ||
if (manifestJson.plus.useragent.concatenate) { | ||
if (manifestJson.plus.useragent.value) { | ||
manifestJson.plus.useragent.value = [ | ||
'uni-app', | ||
manifestJson.plus.useragent.value, | ||
].join(' '); | ||
} | ||
else { | ||
manifestJson.plus.useragent.value = 'uni-app'; | ||
} | ||
} | ||
(0, shared_1.extend)(manifestJson.plus.launchwebview, { | ||
@@ -20,0 +30,0 @@ id: '1', |
@@ -39,2 +39,4 @@ "use strict"; | ||
themeConfig: (0, theme_1.normalizeThemeConfigOnce)(platformConfig), | ||
// @ts-expect-error | ||
qqMapKey: platformConfig?.distribute?.sdkConfigs?.maps?.qqmap?.key, | ||
}; | ||
@@ -41,0 +43,0 @@ // TODO 待支持分包 |
@@ -12,6 +12,7 @@ "use strict"; | ||
const json_1 = require("./json"); | ||
const utils_1 = require("../utils"); | ||
const parseManifestJson = (inputDir) => { | ||
const manifestFilename = path_1.default.join(inputDir, 'manifest.json'); | ||
if (!fs_1.default.existsSync(manifestFilename)) { | ||
if (process.env.UNI_COMPILE_TARGET === 'uni_modules') { | ||
if (!(0, utils_1.isNormalCompileTarget)()) { | ||
return {}; | ||
@@ -18,0 +19,0 @@ } |
@@ -48,3 +48,3 @@ "use strict"; | ||
if (!fs_1.default.existsSync(pagesFilename)) { | ||
if (process.env.UNI_COMPILE_TARGET === 'uni_modules') { | ||
if (!(0, utils_1.isNormalCompileTarget)()) { | ||
return { | ||
@@ -51,0 +51,0 @@ pages: [], |
import type { EmittedAsset } from 'rollup'; | ||
import type { ElementNode } from '@vue/compiler-core'; | ||
import type { AttributeNode, DirectiveNode, ElementNode } from '@vue/compiler-core'; | ||
import type { MiniProgramComponentsType } from '../json/mp/types'; | ||
@@ -14,2 +14,6 @@ type LazyElementFn = (node: ElementNode, context: { | ||
/** | ||
* 检查属性名称是否符合平台要求,比如华为快应用不允许使用 key 属性等 | ||
*/ | ||
checkPropName?: (name: string, prop: AttributeNode | DirectiveNode, node: ElementNode) => boolean; | ||
/** | ||
* 需要延迟渲染的组件,通常是某个组件的某个事件会立刻触发,需要延迟到首次 render 之后,比如微信 editor 的 ready 事件,快手 switch 的 change | ||
@@ -16,0 +20,0 @@ */ |
@@ -21,2 +21,3 @@ "use strict"; | ||
'mp-weixin', | ||
'mp-xhs', | ||
'quickapp-webview', | ||
@@ -23,0 +24,0 @@ 'quickapp-webview-huawei', |
export declare function getPreVueContext(): any; | ||
export declare function getPreNVueContext(): any; | ||
export declare function getPreUVueContext(): any; | ||
export declare function initScopedPreContext(platform: UniApp.PLATFORM, userPreContext?: Record<string, boolean> | string, utsPlatform?: typeof process.env.UNI_UTS_PLATFORM, isX?: boolean): { | ||
preVueContext: any; | ||
preNVueContext: any; | ||
preUVueContext: any; | ||
}; | ||
export declare function initPreContext(platform: UniApp.PLATFORM, userPreContext?: Record<string, boolean> | string, utsPlatform?: typeof process.env.UNI_UTS_PLATFORM, isX?: boolean): void; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.initPreContext = exports.getPreUVueContext = exports.getPreNVueContext = exports.getPreVueContext = void 0; | ||
exports.initPreContext = exports.initScopedPreContext = exports.getPreUVueContext = exports.getPreNVueContext = exports.getPreVueContext = void 0; | ||
const extend = Object.assign; | ||
@@ -54,3 +54,3 @@ const isString = (val) => typeof val === 'string'; | ||
exports.getPreUVueContext = getPreUVueContext; | ||
function initPreContext(platform, userPreContext, utsPlatform, isX) { | ||
function initScopedPreContext(platform, userPreContext, utsPlatform, isX) { | ||
const vueContext = Object.create(null); | ||
@@ -116,6 +116,15 @@ const nvueContext = Object.create(null); | ||
} | ||
extend(preVueContext, defaultContext, vueContext); | ||
extend(preNVueContext, defaultContext, nvueContext); | ||
extend(preUVueContext, defaultContext, uvueContext); | ||
return { | ||
preVueContext: extend({}, defaultContext, vueContext), | ||
preNVueContext: extend({}, defaultContext, nvueContext), | ||
preUVueContext: extend({}, defaultContext, uvueContext), | ||
}; | ||
} | ||
exports.initScopedPreContext = initScopedPreContext; | ||
function initPreContext(platform, userPreContext, utsPlatform, isX) { | ||
const { preVueContext: scopedPreVueContext, preNVueContext: scopedPreNVueContext, preUVueContext: scopedPreUVueContext, } = initScopedPreContext(platform, userPreContext, utsPlatform, isX); | ||
extend(preVueContext, scopedPreVueContext); | ||
extend(preNVueContext, scopedPreNVueContext); | ||
extend(preUVueContext, scopedPreUVueContext); | ||
} | ||
exports.initPreContext = initPreContext; | ||
@@ -122,0 +131,0 @@ function normalizeKey(name) { |
@@ -5,4 +5,5 @@ export declare function requireResolve(filename: string, basedir: string): string; | ||
export declare function getBuiltInPaths(): string[]; | ||
export declare function resolveBuiltIn(path: string): string; | ||
export declare function resolveBuiltIn(module: string): string; | ||
export declare function resolveVueI18nRuntime(): string; | ||
export declare function resolveComponentsLibPath(): string; | ||
export declare function resolveComponentsLibDirs(): string[]; |
@@ -6,3 +6,3 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.resolveComponentsLibPath = exports.resolveVueI18nRuntime = exports.resolveBuiltIn = exports.getBuiltInPaths = exports.resolveMainPathOnce = exports.relativeFile = exports.requireResolve = void 0; | ||
exports.resolveComponentsLibDirs = exports.resolveComponentsLibPath = exports.resolveVueI18nRuntime = exports.resolveBuiltIn = exports.getBuiltInPaths = exports.resolveMainPathOnce = exports.relativeFile = exports.requireResolve = void 0; | ||
const fs_1 = __importDefault(require("fs")); | ||
@@ -97,4 +97,9 @@ const path_1 = __importDefault(require("path")); | ||
exports.getBuiltInPaths = getBuiltInPaths; | ||
function resolveBuiltIn(path) { | ||
return require.resolve(path, { paths: getBuiltInPaths() }); | ||
function resolveBuiltIn(module) { | ||
if (process.env.UNI_COMPILE_TARGET === 'ext-api' && | ||
process.env.UNI_APP_NEXT_WORKSPACE && | ||
module.startsWith('@dcloudio/')) { | ||
return path_1.default.resolve(process.env.UNI_APP_NEXT_WORKSPACE, 'packages', module); | ||
} | ||
return require.resolve(module, { paths: getBuiltInPaths() }); | ||
} | ||
@@ -130,1 +135,7 @@ exports.resolveBuiltIn = resolveBuiltIn; | ||
exports.resolveComponentsLibPath = resolveComponentsLibPath; | ||
function resolveComponentsLibDirs() { | ||
return process.env.UNI_COMPILE_TARGET === 'ext-api' | ||
? [] | ||
: [resolveComponentsLibPath()]; | ||
} | ||
exports.resolveComponentsLibDirs = resolveComponentsLibDirs; |
@@ -76,50 +76,1 @@ import type { UTSTargetLanguage } from './uts'; | ||
export declare function parseUTSModuleDeps(deps: string[], inputDir: string): string[]; | ||
export declare function genEncryptEasyComModuleIndex(platform: typeof process.env.UNI_UTS_PLATFORM, components: Record<string, '.vue' | '.uvue'>): string; | ||
export declare function parseUniModulesWithComponents(inputDir: string): Record<string, Record<string, ".vue" | ".uvue">>; | ||
/** | ||
* 解析 easyCom 组件列表 | ||
* @param pluginId | ||
* @param inputDir | ||
* @returns | ||
*/ | ||
export declare function parseEasyComComponents(pluginId: string, inputDir: string, detectBinary?: boolean): Record<string, ".vue" | ".uvue">; | ||
export declare function findEncryptUniModules(inputDir: string, cacheDir?: string): Record<string, EncryptPackageJson | undefined>; | ||
export declare function findUploadEncryptUniModulesFiles(uniModules: Record<string, EncryptPackageJson | undefined>, platform: typeof process.env.UNI_UTS_PLATFORM, inputDir: string): Record<string, string[]>; | ||
export declare function packUploadEncryptUniModules(uniModules: Record<string, EncryptPackageJson | undefined>, platform: typeof process.env.UNI_UTS_PLATFORM, inputDir: string, cacheDir: string): { | ||
zipFile: string; | ||
modules: string[]; | ||
}; | ||
interface EncryptPackageJson { | ||
id: string; | ||
version: string; | ||
uni_modules: { | ||
dependencies: string[]; | ||
artifacts: { | ||
env: { | ||
compilerVersion: string; | ||
} & Record<string, any>; | ||
apis: string[]; | ||
components: string[]; | ||
scopedSlots: string[]; | ||
declaration: string; | ||
}; | ||
}; | ||
} | ||
export declare function initCheckEnv(): Record<string, string>; | ||
export declare function resolveEncryptUniModule(id: string, platform: typeof process.env.UNI_UTS_PLATFORM, isX?: boolean): string | undefined; | ||
export declare function checkEncryptUniModules(inputDir: string, params: { | ||
mode: 'development' | 'production'; | ||
packType: 'debug' | 'release'; | ||
compilerVersion: string; | ||
appid: string; | ||
appname: string; | ||
platform: typeof process.env.UNI_UTS_PLATFORM; | ||
'uni-app-x': boolean; | ||
}): Promise<{} | undefined>; | ||
export declare function parseUniModulesArtifacts(): { | ||
name: string; | ||
package: string; | ||
scopedSlots: string[]; | ||
declaration: string; | ||
}[]; | ||
export {}; |
@@ -6,10 +6,6 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.parseUniModulesArtifacts = exports.checkEncryptUniModules = exports.resolveEncryptUniModule = exports.initCheckEnv = exports.packUploadEncryptUniModules = exports.findUploadEncryptUniModulesFiles = exports.findEncryptUniModules = exports.parseEasyComComponents = exports.parseUniModulesWithComponents = exports.genEncryptEasyComModuleIndex = exports.parseUTSModuleDeps = exports.capitalize = exports.camelize = exports.parseInjects = exports.parseUniExtApi = exports.parseUniExtApis = exports.getUniExtApiProviderRegisters = exports.formatExtApiProviderName = exports.getUniExtApiPlugins = exports.getUniExtApiProviders = void 0; | ||
exports.parseUTSModuleDeps = exports.capitalize = exports.camelize = exports.parseInjects = exports.parseUniExtApi = exports.parseUniExtApis = exports.getUniExtApiProviderRegisters = exports.formatExtApiProviderName = exports.getUniExtApiPlugins = exports.getUniExtApiProviders = void 0; | ||
// 重要:此文件编译后的js,需同步至 vue2 编译器中 uni-cli-shared/lib/uts/uni_modules.js | ||
const path_1 = __importDefault(require("path")); | ||
const fs_extra_1 = __importDefault(require("fs-extra")); | ||
const fast_glob_1 = require("fast-glob"); | ||
const utils_1 = require("./utils"); | ||
const easycom_1 = require("./easycom"); | ||
const messages_1 = require("./messages"); | ||
const extApiProviders = []; | ||
@@ -285,321 +281,1 @@ const extApiPlugins = new Set(); | ||
exports.parseUTSModuleDeps = parseUTSModuleDeps; | ||
function genEncryptEasyComModuleIndex(platform, components) { | ||
const imports = []; | ||
const ids = []; | ||
Object.keys(components).forEach((component) => { | ||
const id = (0, exports.capitalize)((0, exports.camelize)(component)); | ||
ids.push(id); | ||
let instance = ''; | ||
if (platform === 'app-android') { | ||
instance = (0, easycom_1.genUTSComponentPublicInstanceIdent)(component); | ||
// 类型 | ||
ids.push(instance); | ||
} | ||
imports.push(`import ${id}${instance ? `, { ${instance} }` : ''} from './components/${component}/${component}${components[component]}'`); | ||
}); | ||
return ` | ||
${imports.join('\n')} | ||
export { | ||
${ids.join(',\n ')} | ||
} | ||
`; | ||
} | ||
exports.genEncryptEasyComModuleIndex = genEncryptEasyComModuleIndex; | ||
// 目前该函数仅在云端使用(目前仅限iOS/web),云端编译时,提交上来的uni_modules是过滤好的 | ||
function parseUniModulesWithComponents(inputDir) { | ||
const modulesDir = path_1.default.resolve(inputDir, 'uni_modules'); | ||
const uniModules = {}; | ||
if (fs_extra_1.default.existsSync(modulesDir)) { | ||
fs_extra_1.default.readdirSync(modulesDir).forEach((uniModuleDir) => { | ||
if (!fs_extra_1.default.existsSync(path_1.default.resolve(modulesDir, uniModuleDir, 'package.json'))) { | ||
return; | ||
} | ||
// 解析加密的 easyCom 插件列表 | ||
const components = parseEasyComComponents(uniModuleDir, inputDir, false); | ||
uniModules[uniModuleDir] = components; | ||
}); | ||
} | ||
return uniModules; | ||
} | ||
exports.parseUniModulesWithComponents = parseUniModulesWithComponents; | ||
/** | ||
* 解析 easyCom 组件列表 | ||
* @param pluginId | ||
* @param inputDir | ||
* @returns | ||
*/ | ||
function parseEasyComComponents(pluginId, inputDir, detectBinary = true) { | ||
const componentsDir = path_1.default.resolve(inputDir, 'uni_modules', pluginId, 'components'); | ||
const components = {}; | ||
if (fs_extra_1.default.existsSync(componentsDir)) { | ||
fs_extra_1.default.readdirSync(componentsDir).forEach((componentDir) => { | ||
const componentFile = path_1.default.resolve(componentsDir, componentDir, componentDir); | ||
const extname = ['.vue', '.uvue'].find((extname) => { | ||
const filename = componentFile + extname; | ||
// 探测 filename 是否是二进制文件 | ||
if (fs_extra_1.default.existsSync(filename)) { | ||
if (detectBinary) { | ||
// 延迟require,这个是新增的依赖,无法及时同步到内部测试版本HBuilderX中,导致报错,所以延迟require吧 | ||
if (require('isbinaryfile').isBinaryFileSync(filename)) { | ||
return true; | ||
} | ||
} | ||
else { | ||
return true; | ||
} | ||
} | ||
}); | ||
if (extname) { | ||
components[componentDir] = extname; | ||
} | ||
}); | ||
} | ||
return components; | ||
} | ||
exports.parseEasyComComponents = parseEasyComComponents; | ||
// 查找所有普通加密插件 uni_modules | ||
function findEncryptUniModules(inputDir, cacheDir = '') { | ||
const modulesDir = path_1.default.resolve(inputDir, 'uni_modules'); | ||
const uniModules = {}; | ||
if (fs_extra_1.default.existsSync(modulesDir)) { | ||
fs_extra_1.default.readdirSync(modulesDir).forEach((uniModuleDir) => { | ||
const uniModuleRootDir = path_1.default.resolve(modulesDir, uniModuleDir); | ||
if (!fs_extra_1.default.existsSync(path_1.default.resolve(uniModuleRootDir, 'encrypt'))) { | ||
return; | ||
} | ||
// 仅扫描普通加密插件,无需依赖 | ||
if (fs_extra_1.default.existsSync(path_1.default.resolve(uniModuleRootDir, 'utssdk'))) { | ||
return; | ||
} | ||
const pkg = require(path_1.default.resolve(uniModuleRootDir, 'package.json')); | ||
uniModules[uniModuleDir] = findEncryptUniModuleCache(uniModuleDir, cacheDir, { version: pkg.version, env: initCheckEnv() }); | ||
}); | ||
} | ||
return uniModules; | ||
} | ||
exports.findEncryptUniModules = findEncryptUniModules; | ||
function findUploadEncryptUniModulesFiles(uniModules, platform, inputDir) { | ||
const modules = {}; | ||
Object.keys(uniModules).forEach((uniModuleId) => { | ||
if (!uniModules[uniModuleId]) { | ||
modules[uniModuleId] = findUniModuleFiles(platform, uniModuleId, inputDir); | ||
} | ||
}); | ||
return modules; | ||
} | ||
exports.findUploadEncryptUniModulesFiles = findUploadEncryptUniModulesFiles; | ||
function packUploadEncryptUniModules(uniModules, platform, inputDir, cacheDir) { | ||
const modules = findUploadEncryptUniModulesFiles(uniModules, platform, inputDir); | ||
const uploadModuleIds = Object.keys(modules); | ||
if (uploadModuleIds.length) { | ||
// 延迟 require,避免 vue2 编译器需要安装此依赖,目前该方法仅在 vite 编译器中使用 | ||
const AdmZip = require('adm-zip'); | ||
const zip = new AdmZip(); | ||
uploadModuleIds.forEach((moduleId) => { | ||
modules[moduleId].forEach((file) => { | ||
zip.addLocalFile(file, path_1.default.dirname(path_1.default.relative(inputDir, file))); | ||
}); | ||
}); | ||
const zipFile = path_1.default.resolve(cacheDir, 'cloud-compile-plugins.zip'); | ||
zip.writeZip(zipFile); | ||
return { | ||
zipFile, | ||
modules: uploadModuleIds, | ||
}; | ||
} | ||
return { | ||
zipFile: '', | ||
modules: [], | ||
}; | ||
} | ||
exports.packUploadEncryptUniModules = packUploadEncryptUniModules; | ||
function isEnvExpired(value, other) { | ||
const valueKeys = Object.keys(value); | ||
const otherKeys = Object.keys(other); | ||
if (valueKeys.length !== otherKeys.length) { | ||
return true; | ||
} | ||
if (valueKeys.find((name) => value[name] !== other[name])) { | ||
return true; | ||
} | ||
return false; | ||
} | ||
function findEncryptUniModuleCache(uniModuleId, cacheDir, options) { | ||
if (!cacheDir) { | ||
return; | ||
} | ||
const uniModuleCacheDir = path_1.default.resolve(cacheDir, 'uni_modules', uniModuleId); | ||
if (fs_extra_1.default.existsSync(uniModuleCacheDir)) { | ||
const pkg = require(path_1.default.resolve(uniModuleCacheDir, 'package.json')); | ||
// 插件版本以及各种环境一致 | ||
if (pkg.version === options.version && | ||
!isEnvExpired(pkg.uni_modules?.artifacts?.env || {}, options.env)) { | ||
const declaration = path_1.default.resolve(uniModuleCacheDir, 'utssdk/app-android/index.d.uts'); | ||
pkg.uni_modules.artifacts.declaration = fs_extra_1.default.existsSync(declaration) | ||
? declaration | ||
: ''; | ||
return pkg; | ||
} | ||
console.log(`插件${uniModuleId} 缓存已过期,需要重新云编译。`); | ||
// 已过期的插件,删除缓存 | ||
fs_extra_1.default.rmSync(uniModuleCacheDir, { recursive: true }); | ||
} | ||
} | ||
const KNOWN_ASSET_TYPES = [ | ||
// images | ||
'png', | ||
'jpe?g', | ||
'gif', | ||
'svg', | ||
'ico', | ||
'webp', | ||
'avif', | ||
// media | ||
'mp4', | ||
'webm', | ||
'ogg', | ||
'mp3', | ||
'wav', | ||
'flac', | ||
'aac', | ||
// fonts | ||
'woff2?', | ||
'eot', | ||
'ttf', | ||
'otf', | ||
// other | ||
'pdf', | ||
'txt', | ||
]; | ||
function findUniModuleFiles(platform, id, inputDir) { | ||
return (0, fast_glob_1.sync)(`uni_modules/${id}/**/*`, { | ||
cwd: inputDir, | ||
absolute: true, | ||
ignore: [ | ||
'**/*.md', | ||
...(platform !== 'app-android' // 非 android 平台不需要扫描 assets | ||
? [`**/*.{${KNOWN_ASSET_TYPES.join(',')}}`] | ||
: []), | ||
], | ||
}); | ||
} | ||
function initCheckEnv() { | ||
return { | ||
// 云端编译的版本号不带日期及小版本 | ||
compilerVersion: process.env.UNI_COMPILER_VERSION, | ||
}; | ||
} | ||
exports.initCheckEnv = initCheckEnv; | ||
function findLastIndex(array, predicate) { | ||
for (let i = array.length - 1; i >= 0; i--) { | ||
if (predicate(array[i], i, array)) { | ||
return i; | ||
} | ||
} | ||
return -1; | ||
} | ||
let encryptUniModules = {}; | ||
function resolveEncryptUniModule(id, platform, isX = true) { | ||
const parts = id.split('?', 2)[0].split('/'); | ||
const index = findLastIndex(parts, (part) => part === 'uni_modules'); | ||
if (index !== -1) { | ||
const uniModuleId = parts[index + 1]; | ||
if (uniModuleId in encryptUniModules) { | ||
if (parts[index + 2]) { | ||
console.warn(messages_1.M['uni_modules.import'] | ||
.replace('{0}', uniModuleId) | ||
.replace('{1}', uniModuleId) | ||
.replace('{2}', parts.slice(index + 2).join('/'))); | ||
} | ||
// 原生平台走旧的uts-proxy | ||
return (0, utils_1.normalizePath)(path_1.default.join(process.env.UNI_INPUT_DIR, `uni_modules/${uniModuleId}?${isX && platform === 'app-android' ? 'uts-proxy' : 'uni_helpers'}`)); | ||
} | ||
} | ||
} | ||
exports.resolveEncryptUniModule = resolveEncryptUniModule; | ||
async function checkEncryptUniModules(inputDir, params) { | ||
// 扫描加密插件云编译 | ||
encryptUniModules = findEncryptUniModules(inputDir, process.env.UNI_MODULES_ENCRYPT_CACHE_DIR); | ||
if (!Object.keys(encryptUniModules).length) { | ||
return {}; | ||
} | ||
if (!process.env.UNI_HBUILDERX_PLUGINS) { | ||
return {}; | ||
} | ||
const cacheDir = process.env.UNI_MODULES_ENCRYPT_CACHE_DIR; | ||
const { zipFile, modules } = packUploadEncryptUniModules(encryptUniModules, process.env.UNI_UTS_PLATFORM, inputDir, cacheDir); | ||
if (zipFile) { | ||
const downloadFile = path_1.default.resolve(cacheDir, 'uni_modules.download.zip'); | ||
const { C, D, R, U } = (0, utils_1.requireUniHelpers)(); | ||
try { | ||
const isLogin = await C(); | ||
const tips = process.env.UNI_UTS_PLATFORM !== 'app-android' | ||
? '(此过程耗时较长)' | ||
: ''; | ||
console.log(`正在云编译插件${isLogin ? '' : '(请先登录)'}${tips}:${modules.join(',')}...`); | ||
let downloadUrl = ''; | ||
try { | ||
downloadUrl = await U({ | ||
params, | ||
attachment: zipFile, | ||
}); | ||
} | ||
catch (e) { | ||
if (e.message && e.message === '{"error":"UserNotLogin"}') { | ||
console.log('当前项目包含需要云编译的付费插件,需要您先登录HBuilderX账号。'); | ||
} | ||
else { | ||
console.error(e); | ||
} | ||
process.exit(0); | ||
} | ||
await D(downloadUrl, downloadFile); | ||
// unzip | ||
const AdmZip = require('adm-zip'); | ||
const zip = new AdmZip(downloadFile); | ||
zip.extractAllTo(cacheDir, true); | ||
fs_extra_1.default.unlinkSync(zipFile); | ||
fs_extra_1.default.unlinkSync(downloadFile); | ||
R({ | ||
dir: process.env.UNI_INPUT_DIR, | ||
cacheDir: process.env.UNI_MODULES_ENCRYPT_CACHE_DIR, | ||
}); | ||
console.log(`云编译已完成`); | ||
console.log(`正在编译中...`); | ||
} | ||
catch (e) { | ||
fs_extra_1.default.existsSync(zipFile) && fs_extra_1.default.unlinkSync(zipFile); | ||
fs_extra_1.default.existsSync(downloadFile) && fs_extra_1.default.unlinkSync(downloadFile); | ||
console.error(e); | ||
process.exit(0); | ||
} | ||
} | ||
else { | ||
// android 平台需要在这里初始化 | ||
if (params.platform === 'app-android') { | ||
const { R } = (0, utils_1.requireUniHelpers)(); | ||
R({ | ||
dir: process.env.UNI_INPUT_DIR, | ||
cacheDir: process.env.UNI_MODULES_ENCRYPT_CACHE_DIR, | ||
}); | ||
} | ||
} | ||
encryptUniModules = findEncryptUniModules(inputDir, process.env.UNI_MODULES_ENCRYPT_CACHE_DIR); | ||
} | ||
exports.checkEncryptUniModules = checkEncryptUniModules; | ||
function parseUniModulesArtifacts() { | ||
const res = []; | ||
Object.keys(encryptUniModules).forEach((uniModuleId) => { | ||
const pkg = encryptUniModules[uniModuleId]; | ||
if (pkg?.uni_modules?.artifacts) { | ||
res.push({ | ||
name: uniModuleId, | ||
package: `uts.sdk.modules.${(0, exports.camelize)(uniModuleId)}`, | ||
scopedSlots: pkg.uni_modules.artifacts.scopedSlots || [], | ||
declaration: pkg.uni_modules.artifacts.declaration, | ||
}); | ||
} | ||
}); | ||
return res; | ||
} | ||
exports.parseUniModulesArtifacts = parseUniModulesArtifacts; |
@@ -38,1 +38,2 @@ export { default as hash } from 'hash-sum'; | ||
export declare function createShadowImageUrl(cdn: number, type?: string): string; | ||
export declare function isNormalCompileTarget(): boolean; |
@@ -6,3 +6,3 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.createShadowImageUrl = exports.normalizeEmitAssetFileName = exports.requireUniHelpers = exports.enableSourceMap = exports.createResolveErrorMsg = exports.parseImporter = exports.resolveAppVue = exports.isAppVue = exports.installDepTips = exports.resolveSourceMapPath = exports.pathToGlob = exports.normalizeParsePlugins = exports.normalizeMiniProgramFilename = exports.normalizeNodeModules = exports.removeExt = exports.normalizePagePath = exports.normalizeIdentifier = exports.checkElementNodeTag = exports.normalizePath = exports.isWindows = exports.isArray = exports.capitalize = exports.camelize = exports.hash = void 0; | ||
exports.isNormalCompileTarget = exports.createShadowImageUrl = exports.normalizeEmitAssetFileName = exports.requireUniHelpers = exports.enableSourceMap = exports.createResolveErrorMsg = exports.parseImporter = exports.resolveAppVue = exports.isAppVue = exports.installDepTips = exports.resolveSourceMapPath = exports.pathToGlob = exports.normalizeParsePlugins = exports.normalizeMiniProgramFilename = exports.normalizeNodeModules = exports.removeExt = exports.normalizePagePath = exports.normalizeIdentifier = exports.checkElementNodeTag = exports.normalizePath = exports.isWindows = exports.isArray = exports.capitalize = exports.camelize = exports.hash = void 0; | ||
const fs_1 = __importDefault(require("fs")); | ||
@@ -173,4 +173,9 @@ const os_1 = __importDefault(require("os")); | ||
function enableSourceMap() { | ||
return (process.env.NODE_ENV === 'development' && | ||
process.env.UNI_COMPILE_TARGET !== 'uni_modules'); | ||
if (process.env.UNI_APP_SOURCEMAP === 'true') { | ||
return true; | ||
} | ||
if (process.env.UNI_APP_SOURCEMAP === 'false') { | ||
return false; | ||
} | ||
return process.env.NODE_ENV === 'development' && isNormalCompileTarget(); | ||
} | ||
@@ -218,1 +223,6 @@ exports.enableSourceMap = enableSourceMap; | ||
exports.createShadowImageUrl = createShadowImageUrl; | ||
function isNormalCompileTarget() { | ||
// 目前有特殊编译目标 uni_modules 和 ext-api | ||
return !process.env.UNI_COMPILE_TARGET; | ||
} | ||
exports.isNormalCompileTarget = isNormalCompileTarget; |
@@ -15,3 +15,3 @@ /// <reference types="node" /> | ||
export declare function isUTSComponent(name: string): boolean; | ||
export declare function getUTSComponentAutoImports(): Record<string, [[string]]>; | ||
export declare function getUTSComponentAutoImports(language: 'kotlin' | 'swift'): Record<string, [[string]]>; | ||
export declare function parseUTSComponent(name: string, type: 'kotlin' | 'swift'): { | ||
@@ -29,1 +29,8 @@ className: string; | ||
export declare function resolveUniTypeScript(): any; | ||
export declare function initUTSKotlinAutoImportsOnce(): Promise<Record<string, [string, (string | undefined)?][]>>; | ||
export declare function initUTSSwiftAutoImportsOnce(): Promise<Record<string, [string, (string | undefined)?][]>>; | ||
export declare const genUniExtApiDeclarationFileOnce: (tscInputDir: string) => void; | ||
export declare function uvueOutDir(platform: 'app-android' | 'app-ios' | 'app-harmony'): string; | ||
export declare function tscOutDir(platform: 'app-android' | 'app-ios' | 'app-harmony'): string; | ||
export declare function isUTSProxy(id: string): boolean; | ||
export declare function isUniHelpers(id: string): boolean; |
194
dist/uts.js
@@ -6,5 +6,5 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.resolveUniTypeScript = exports.parseUniExtApiNamespacesJsOnce = exports.parseUniExtApiNamespacesOnce = exports.parseSwiftPackageWithPluginId = exports.parseKotlinPackageWithPluginId = exports.initUTSComponents = exports.parseUTSComponent = exports.getUTSComponentAutoImports = exports.isUTSComponent = exports.resolveUTSCompiler = exports.resolveUTSModule = exports.resolveUTSAppModule = void 0; | ||
exports.isUniHelpers = exports.isUTSProxy = exports.tscOutDir = exports.uvueOutDir = exports.genUniExtApiDeclarationFileOnce = exports.initUTSSwiftAutoImportsOnce = exports.initUTSKotlinAutoImportsOnce = exports.resolveUniTypeScript = exports.parseUniExtApiNamespacesJsOnce = exports.parseUniExtApiNamespacesOnce = exports.parseSwiftPackageWithPluginId = exports.parseKotlinPackageWithPluginId = exports.initUTSComponents = exports.parseUTSComponent = exports.getUTSComponentAutoImports = exports.isUTSComponent = exports.resolveUTSCompiler = exports.resolveUTSModule = exports.resolveUTSAppModule = void 0; | ||
// 重要,该文件编译后的 js 需要同步到 vue2 编译器 uni-cli-shared/lib/uts | ||
const fs_1 = __importDefault(require("fs")); | ||
const fs_extra_1 = __importDefault(require("fs-extra")); | ||
const path_1 = __importDefault(require("path")); | ||
@@ -43,3 +43,3 @@ const fast_glob_1 = __importDefault(require("fast-glob")); | ||
const appJsIndex = path_1.default.resolve(id, basedir, 'app-js', 'index.uts'); | ||
if (fs_1.default.existsSync(appJsIndex)) { | ||
if (fs_extra_1.default.existsSync(appJsIndex)) { | ||
return appJsIndex; | ||
@@ -49,3 +49,3 @@ } | ||
} | ||
if (fs_1.default.existsSync(path_1.default.resolve(id, basedir, 'index.uts'))) { | ||
if (fs_extra_1.default.existsSync(path_1.default.resolve(id, basedir, 'index.uts'))) { | ||
return id; | ||
@@ -96,3 +96,3 @@ } | ||
index = path_1.default.resolve(id, basedir, 'index.uts'); | ||
if (fs_1.default.existsSync(index)) { | ||
if (fs_extra_1.default.existsSync(index)) { | ||
return index; | ||
@@ -107,3 +107,3 @@ } | ||
const indexFile = path_1.default.join(dir, 'index' + extensions[i]); | ||
if (fs_1.default.existsSync(indexFile)) { | ||
if (fs_extra_1.default.existsSync(indexFile)) { | ||
return indexFile; | ||
@@ -115,2 +115,6 @@ } | ||
let compilerPath = ''; | ||
if (process.env.UNI_COMPILE_TARGET === 'ext-api' && | ||
process.env.UNI_APP_NEXT_WORKSPACE) { | ||
return require(path_1.default.resolve(process.env.UNI_APP_NEXT_WORKSPACE, 'packages/uni-uts-v1')); | ||
} | ||
if ((0, hbx_1.isInHBuilderX)()) { | ||
@@ -125,3 +129,3 @@ try { | ||
compilerPath = require.resolve('@dcloudio/uni-uts-v1', { | ||
paths: [process.env.UNI_CLI_CONTEXT], | ||
paths: [process.env.UNI_CLI_CONTEXT || process.cwd()], | ||
}); | ||
@@ -156,12 +160,13 @@ } | ||
exports.isUTSComponent = isUTSComponent; | ||
function getUTSComponentAutoImports() { | ||
function getUTSComponentAutoImports(language) { | ||
const utsComponentAutoImports = {}; | ||
utsComponents.forEach(({ kotlinPackage }, name) => { | ||
utsComponents.forEach(({ kotlinPackage, swiftModule }, name) => { | ||
const source = language === 'kotlin' ? kotlinPackage : swiftModule; | ||
const className = (0, utils_1.capitalize)((0, utils_1.camelize)(name)) + 'Element'; | ||
if (!utsComponentAutoImports[kotlinPackage]) { | ||
utsComponentAutoImports[kotlinPackage] = [[className]]; | ||
if (!utsComponentAutoImports[source]) { | ||
utsComponentAutoImports[source] = [[className]]; | ||
} | ||
else { | ||
if (!utsComponentAutoImports[kotlinPackage].find((item) => item[0] === className)) { | ||
utsComponentAutoImports[kotlinPackage].push([className]); | ||
if (!utsComponentAutoImports[source].find((item) => item[0] === className)) { | ||
utsComponentAutoImports[source].push([className]); | ||
} | ||
@@ -245,17 +250,19 @@ } | ||
const uniModulesDir = path_1.default.resolve(inputDir, 'uni_modules'); | ||
return fast_glob_1.default | ||
.sync('*', { | ||
cwd: utssdkDir, | ||
absolute: true, | ||
onlyDirectories: true, | ||
}) | ||
.concat(fast_glob_1.default.sync('*/utssdk', { | ||
cwd: uniModulesDir, | ||
absolute: true, | ||
onlyDirectories: true, | ||
})); | ||
return (fs_extra_1.default.existsSync(utssdkDir) | ||
? fast_glob_1.default.sync('*', { | ||
cwd: utssdkDir, | ||
absolute: true, | ||
onlyDirectories: true, | ||
}) | ||
: []).concat(fs_extra_1.default.existsSync(uniModulesDir) | ||
? fast_glob_1.default.sync('*/utssdk', { | ||
cwd: uniModulesDir, | ||
absolute: true, | ||
onlyDirectories: true, | ||
}) | ||
: []); | ||
} | ||
const nameRE = /name\s*:\s*['|"](.*)['|"]/; | ||
function parseVueComponentName(file) { | ||
const content = fs_1.default.readFileSync(file, 'utf8'); | ||
const content = fs_extra_1.default.readFileSync(file, 'utf8'); | ||
const matches = content.match(nameRE); | ||
@@ -283,2 +290,50 @@ if (matches) { | ||
exports.parseSwiftPackageWithPluginId = parseSwiftPackageWithPluginId; | ||
async function parseUniExtApiAutoImports(uniExtApiAutoImports, extApis, parseSource) { | ||
if (Object.keys(extApis).length) { | ||
const { parseExportIdentifiers } = resolveUTSCompiler(); | ||
for (const name in extApis) { | ||
const options = extApis[name]; | ||
if ((0, utils_1.isArray)(options) && options.length >= 2) { | ||
const pluginId = path_1.default.basename(options[0]); | ||
const source = parseSource(pluginId); | ||
if (uniExtApiAutoImports[source]) { | ||
continue; | ||
} | ||
uniExtApiAutoImports[source] = []; | ||
const filename = `uni_modules/${pluginId}/utssdk/interface.uts`; | ||
const interfaceFileName = path_1.default.resolve(process.env.UNI_INPUT_DIR, filename); | ||
if (fs_extra_1.default.existsSync(interfaceFileName)) { | ||
const ids = await parseExportIdentifiers(interfaceFileName); | ||
ids | ||
// 过滤掉 Uni | ||
.filter((id) => id !== 'Uni') | ||
.forEach((id) => { | ||
uniExtApiAutoImports[source].push([id]); | ||
}); | ||
} | ||
} | ||
} | ||
} | ||
return uniExtApiAutoImports; | ||
} | ||
let uniExtApiKotlinAutoImports = null; | ||
async function parseUniExtApiKotlinAutoImportsOnce(extApis) { | ||
if (uniExtApiKotlinAutoImports) { | ||
return uniExtApiKotlinAutoImports; | ||
} | ||
uniExtApiKotlinAutoImports = {}; | ||
return parseUniExtApiAutoImports(uniExtApiKotlinAutoImports, extApis, (pluginId) => { | ||
return parseKotlinPackageWithPluginId(pluginId, true); | ||
}); | ||
} | ||
let uniExtApiSwiftAutoImports = null; | ||
async function parseUniExtApiSwiftAutoImportsOnce(extApis) { | ||
if (uniExtApiSwiftAutoImports) { | ||
return uniExtApiSwiftAutoImports; | ||
} | ||
uniExtApiSwiftAutoImports = {}; | ||
return parseUniExtApiAutoImports(uniExtApiSwiftAutoImports, extApis, (pluginId) => { | ||
return parseSwiftPackageWithPluginId(pluginId, true); | ||
}); | ||
} | ||
exports.parseUniExtApiNamespacesOnce = once((platform, language) => { | ||
@@ -319,1 +374,90 @@ const extApis = (0, exports.parseUniExtApiNamespacesJsOnce)(platform, language); | ||
exports.resolveUniTypeScript = resolveUniTypeScript; | ||
async function initUTSAutoImports(autoImports, platform, language) { | ||
const utsComponents = getUTSComponentAutoImports(language); | ||
Object.keys(utsComponents).forEach((source) => { | ||
if (autoImports[source]) { | ||
autoImports[source].push(...utsComponents[source]); | ||
} | ||
else { | ||
autoImports[source] = utsComponents[source]; | ||
} | ||
}); | ||
const extApis = (0, uni_modules_1.parseUniExtApis)(true, platform, language); | ||
const extApiImports = await (language === 'kotlin' | ||
? parseUniExtApiKotlinAutoImportsOnce | ||
: parseUniExtApiSwiftAutoImportsOnce)(extApis); | ||
Object.keys(extApiImports).forEach((source) => { | ||
if (autoImports[source]) { | ||
autoImports[source].push(...extApiImports[source]); | ||
} | ||
else { | ||
autoImports[source] = extApiImports[source]; | ||
} | ||
}); | ||
return autoImports; | ||
} | ||
let autoKotlinImports = null; | ||
async function initUTSKotlinAutoImportsOnce() { | ||
if (autoKotlinImports) { | ||
return autoKotlinImports; | ||
} | ||
autoKotlinImports = {}; | ||
return initUTSAutoImports(autoKotlinImports, 'app-android', 'kotlin'); | ||
} | ||
exports.initUTSKotlinAutoImportsOnce = initUTSKotlinAutoImportsOnce; | ||
let autoSwiftImports = null; | ||
async function initUTSSwiftAutoImportsOnce() { | ||
if (autoSwiftImports) { | ||
return autoSwiftImports; | ||
} | ||
autoSwiftImports = {}; | ||
return initUTSAutoImports(autoSwiftImports, 'app-ios', 'swift'); | ||
} | ||
exports.initUTSSwiftAutoImportsOnce = initUTSSwiftAutoImportsOnce; | ||
exports.genUniExtApiDeclarationFileOnce = once((tscInputDir) => { | ||
const extApis = (0, uni_modules_1.parseUniExtApis)(true, 'app-android', 'kotlin'); | ||
// 之所以往上一级写,是因为 tscInputDir 会被 empty,目前时机有问题,比如先生成了d.ts,又被empty | ||
const fileName = path_1.default.resolve(tscInputDir, '../uni-ext-api.d.ts'); | ||
if (fs_extra_1.default.existsSync(fileName)) { | ||
try { | ||
// 先删除 | ||
fs_extra_1.default.unlinkSync(fileName); | ||
} | ||
catch (e) { } | ||
} | ||
if (Object.keys(extApis).length) { | ||
const apis = []; | ||
for (const name in extApis) { | ||
const options = extApis[name]; | ||
if ((0, utils_1.isArray)(options) && options.length >= 2) { | ||
const api = name.replace('uni.', ''); | ||
apis.push(' ' + api + `: typeof import("${options[0]}")["${options[1]}"]`); | ||
} | ||
} | ||
if (apis.length) { | ||
fs_extra_1.default.outputFileSync(fileName, ` | ||
interface Uni { | ||
${apis.join('\n')} | ||
} | ||
`); | ||
} | ||
} | ||
}); | ||
function uvueOutDir(platform) { | ||
return path_1.default.join(process.env.UNI_APP_X_UVUE_DIR, platform); | ||
} | ||
exports.uvueOutDir = uvueOutDir; | ||
function tscOutDir(platform) { | ||
return path_1.default.join(process.env.UNI_APP_X_TSC_DIR, platform); | ||
} | ||
exports.tscOutDir = tscOutDir; | ||
const UTSProxyRE = /\?uts-proxy$/; | ||
const UniHelpersRE = /\?uni_helpers$/; | ||
function isUTSProxy(id) { | ||
return UTSProxyRE.test(id); | ||
} | ||
exports.isUTSProxy = isUTSProxy; | ||
function isUniHelpers(id) { | ||
return UniHelpersRE.test(id); | ||
} | ||
exports.isUniHelpers = isUniHelpers; |
@@ -88,3 +88,3 @@ "use strict"; | ||
const cloudPreset = { | ||
'@dcloudio/uni-cloud': [['default', 'uniCloud']], | ||
'@dcloudio/uni-cloud': [['default', 'uniCloud'], 'UniCloudError'], | ||
}; | ||
@@ -91,0 +91,0 @@ const vuePreset = { |
@@ -7,1 +7,2 @@ import type { Plugin, ResolveFn } from 'vite'; | ||
export declare function addUniModulesExtApiComponents(relativeFilename: string, components: string[]): void; | ||
export declare function compileCloudUniModuleWithTsc(platform: 'app-android' | 'app-ios' | 'app-harmony', pluginDir: string): Promise<void>; |
@@ -6,6 +6,6 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.addUniModulesExtApiComponents = exports.uniEncryptUniModulesPlugin = exports.uniEncryptUniModulesAssetsPlugin = exports.createEncryptCssUrlReplacer = void 0; | ||
exports.compileCloudUniModuleWithTsc = exports.addUniModulesExtApiComponents = exports.uniEncryptUniModulesPlugin = exports.uniEncryptUniModulesAssetsPlugin = exports.createEncryptCssUrlReplacer = void 0; | ||
const path_1 = __importDefault(require("path")); | ||
const fs_extra_1 = __importDefault(require("fs-extra")); | ||
const uni_modules_1 = require("../uni_modules"); | ||
const uni_modules_cloud_1 = require("../uni_modules.cloud"); | ||
const utils_1 = require("./plugins/vitejs/utils"); | ||
@@ -15,2 +15,3 @@ const uts_1 = require("../uts"); | ||
const easycom_1 = require("../easycom"); | ||
const uni_modules_1 = require("./plugins/uts/uni_modules"); | ||
function createEncryptCssUrlReplacer(resolve) { | ||
@@ -122,5 +123,6 @@ return async (url, importer) => { | ||
name: pkg, | ||
originalFileName: null, | ||
needsCodeReference: false, | ||
source: genUniModulesPackageJson(uniModuleId, process.env.UNI_INPUT_DIR, { | ||
env: (0, uni_modules_1.initCheckEnv)(), | ||
env: (0, uni_modules_cloud_1.initCheckEnv)(), | ||
}), | ||
@@ -135,4 +137,20 @@ }; | ||
} | ||
const uniXKotlinCompiler = process.env.UNI_APP_X_TSC === 'true' | ||
? (0, uts_1.resolveUTSCompiler)().createUniXKotlinCompilerOnce() | ||
: null; | ||
if (uniXKotlinCompiler) { | ||
const tscOutputDir = tscOutDir('app-android'); | ||
const uniModulesDir = path_1.default.resolve(tscOutputDir, 'uni_modules'); | ||
if (fs_extra_1.default.existsSync(uniModulesDir)) { | ||
for (const plugin of fs_extra_1.default.readdirSync(uniModulesDir)) { | ||
const indexFileName = path_1.default.join(uniModulesDir, plugin, 'index.module.uts.ts'); | ||
if (fs_extra_1.default.existsSync(indexFileName)) { | ||
await uniXKotlinCompiler.addRootFile(indexFileName); | ||
} | ||
} | ||
} | ||
await uniXKotlinCompiler.close(); | ||
} | ||
// 编译所有 uni_modules 插件 | ||
const tempOutputDir = uvueOutDir(); | ||
const tempOutputDir = uvueOutDir('app-android'); | ||
const tempUniModulesDir = path_1.default.join(tempOutputDir, 'uni_modules'); | ||
@@ -189,4 +207,4 @@ const tempUniModules = []; | ||
const modules = (0, uts_1.resolveUTSCompiler)().parseInjectModules(apis, {}, components); | ||
fs_extra_1.default.writeFileSync(path_1.default.resolve(process.env.UNI_OUTPUT_DIR, 'uni_modules', uniModule, 'package.json'), genUniModulesPackageJson(uniModule, tempOutputDir, { | ||
env: (0, uni_modules_1.initCheckEnv)(), | ||
fs_extra_1.default.writeFileSync(path_1.default.resolve(process.env.UNI_OUTPUT_DIR, 'uni_modules', uniModule, 'package.json'), genUniModulesPackageJson(uniModule, process.env.UNI_INPUT_DIR, { | ||
env: (0, uni_modules_cloud_1.initCheckEnv)(), | ||
apis, | ||
@@ -203,5 +221,8 @@ components, | ||
exports.uniEncryptUniModulesPlugin = uniEncryptUniModulesPlugin; | ||
function uvueOutDir() { | ||
return path_1.default.join(process.env.UNI_OUTPUT_DIR, '../.uvue'); | ||
function tscOutDir(platform) { | ||
return path_1.default.join(process.env.UNI_APP_X_TSC_DIR, platform); | ||
} | ||
function uvueOutDir(platform) { | ||
return path_1.default.join(process.env.UNI_APP_X_UVUE_DIR, platform); | ||
} | ||
function createExternal(config) { | ||
@@ -235,2 +256,6 @@ return function external(source) { | ||
} | ||
// 'virtual:uno.css' | ||
if (source.includes(':')) { | ||
return false; | ||
} | ||
// android 系统库,三方库,iOS 的库呢?一般不包含. | ||
@@ -256,3 +281,3 @@ if (source.includes('.')) { | ||
function initEncryptUniModulesBuildOptions(platform, inputDir) { | ||
const modules = (0, uni_modules_1.parseUniModulesWithComponents)(inputDir); | ||
const modules = (0, uni_modules_cloud_1.parseUniModulesWithComponents)(inputDir); | ||
const moduleNames = Object.keys(modules); | ||
@@ -273,3 +298,3 @@ if (!moduleNames.length) { | ||
if (modules[module] && Object.keys(modules[module]).length) { | ||
codes.push((0, uni_modules_1.genEncryptEasyComModuleIndex)(platform, modules[module])); | ||
codes.push((0, uni_modules_cloud_1.genEncryptEasyComModuleIndex)(platform, modules[module])); | ||
} | ||
@@ -339,1 +364,18 @@ if (codes.length) { | ||
} | ||
function compileCloudUniModuleWithTsc(platform, pluginDir) { | ||
const { compileUniModuleWithTsc, createUniXKotlinCompilerOnce, createUniXSwiftCompilerOnce, createUniXArkTSCompilerOnce, } = (0, uts_1.resolveUTSCompiler)(); | ||
const isX = process.env.UNI_APP_X === 'true'; | ||
return compileUniModuleWithTsc(platform, pluginDir, platform === 'app-android' | ||
? createUniXKotlinCompilerOnce() | ||
: platform === 'app-harmony' | ||
? createUniXArkTSCompilerOnce() | ||
: createUniXSwiftCompilerOnce(), { | ||
rootFiles: [], | ||
preprocessor: platform === 'app-android' | ||
? (0, uni_modules_1.createAppAndroidUniModulesSyncFilePreprocessorOnce)(isX) | ||
: platform === 'app-harmony' | ||
? (0, uni_modules_1.createAppHarmonyUniModulesSyncFilePreprocessorOnce)(isX) | ||
: (0, uni_modules_1.createAppIosUniModulesSyncFilePreprocessorOnce)(isX), | ||
}); | ||
} | ||
exports.compileCloudUniModuleWithTsc = compileCloudUniModuleWithTsc; |
@@ -41,2 +41,3 @@ import type { Plugin } from 'vite'; | ||
export * from './cloud'; | ||
export * from './extApi'; | ||
export declare function rewriteExistsSyncHasRootFile(): void; |
@@ -31,2 +31,3 @@ "use strict"; | ||
__exportStar(require("./cloud"), exports); | ||
__exportStar(require("./extApi"), exports); | ||
// https://github.com/vitejs/vite/blob/aac2ef77521f66ddd908f9d97020b8df532148cf/packages/vite/src/node/server/searchRoot.ts#L38 | ||
@@ -33,0 +34,0 @@ // vite 在初始化阶段会执行 initTSConfck,此时会 searchForWorkspaceRoot,如果找到了 pnpm-workspace.yaml 文件,会将其作为 root |
import type { Plugin } from 'vite'; | ||
import type { SyncUniModulesFilePreprocessor } from '@dcloudio/uni-uts-v1'; | ||
export declare function createAppAndroidUniModulesSyncFilePreprocessorOnce(isX: boolean): SyncUniModulesFilePreprocessor; | ||
export declare function createAppIosUniModulesSyncFilePreprocessorOnce(isX: boolean): SyncUniModulesFilePreprocessor; | ||
export declare function createAppHarmonyUniModulesSyncFilePreprocessorOnce(isX: boolean): SyncUniModulesFilePreprocessor; | ||
interface UniUTSPluginOptions { | ||
@@ -3,0 +7,0 @@ x?: boolean; |
@@ -6,19 +6,90 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.uniDecryptUniModulesPlugin = exports.resolveExtApiProvider = exports.buildUniExtApis = exports.uniUTSAppUniModulesPlugin = exports.getCurrentCompiledUTSPlugins = void 0; | ||
const fs_1 = __importDefault(require("fs")); | ||
exports.uniDecryptUniModulesPlugin = exports.resolveExtApiProvider = exports.buildUniExtApis = exports.uniUTSAppUniModulesPlugin = exports.getCurrentCompiledUTSPlugins = exports.createAppHarmonyUniModulesSyncFilePreprocessorOnce = exports.createAppIosUniModulesSyncFilePreprocessorOnce = exports.createAppAndroidUniModulesSyncFilePreprocessorOnce = void 0; | ||
const fs_extra_1 = __importDefault(require("fs-extra")); | ||
const path_1 = __importDefault(require("path")); | ||
const uni_shared_1 = require("@dcloudio/uni-shared"); | ||
const pluginutils_1 = require("@rollup/pluginutils"); | ||
const uts_1 = require("../../../uts"); | ||
const utils_1 = require("../../utils"); | ||
const uni_modules_1 = require("../../../uni_modules"); | ||
const uni_modules_cloud_1 = require("../../../uni_modules.cloud"); | ||
const utils_2 = require("../../../utils"); | ||
const json_1 = require("../../../json"); | ||
const UTSProxyRE = /\?uts-proxy$/; | ||
const UniHelpersRE = /\?uni_helpers$/; | ||
function isUTSProxy(id) { | ||
return UTSProxyRE.test(id); | ||
const fs_1 = require("../../../fs"); | ||
const context_1 = require("../../../preprocess/context"); | ||
/* eslint-disable no-restricted-globals */ | ||
const { preprocess } = require('../../../../lib/preprocess'); | ||
function createUniModulesSyncFilePreprocessor(platform, utsPlatform, isX) { | ||
const { preVueContext, preUVueContext } = (0, context_1.initScopedPreContext)(platform, undefined, utsPlatform, isX); | ||
const preContext = isX ? preUVueContext : preVueContext; | ||
if (!isX) { | ||
if (utsPlatform === 'app-android') { | ||
preContext.APP_ANDROID = true; | ||
} | ||
if (utsPlatform === 'app-ios') { | ||
preContext.APP_IOS = true; | ||
} | ||
if (utsPlatform === 'app-harmony') { | ||
preContext.APP_HARMONY = true; | ||
} | ||
} | ||
function preJs(jsCode) { | ||
return preprocess(jsCode, preContext, { type: 'js' }); | ||
} | ||
function preHtml(htmlCode) { | ||
return preprocess(htmlCode, preContext, { type: 'html' }); | ||
} | ||
return async (content, fileName) => { | ||
const extname = path_1.default.extname(fileName); | ||
if (extname === '.json') { | ||
return (0, pluginutils_1.dataToEsm)(JSON.parse(preJs(content)), { | ||
namedExports: true, | ||
preferConst: true, | ||
}); | ||
} | ||
else if (extname === '.uts' || extname === '.ts') { | ||
return preJs(content); | ||
} | ||
else if (extname === '.uvue' || extname === '.vue') { | ||
return preJs(preHtml(content)); | ||
} | ||
return content; | ||
}; | ||
} | ||
function isUniHelpers(id) { | ||
return UniHelpersRE.test(id); | ||
function createAppAndroidUniModulesSyncFilePreprocessorOnce(isX) { | ||
return isX | ||
? createUniXAppAndroidUniModulesSyncFilePreprocessorOnce() | ||
: createUniAppAndroidUniModulesSyncFilePreprocessorOnce(); | ||
} | ||
exports.createAppAndroidUniModulesSyncFilePreprocessorOnce = createAppAndroidUniModulesSyncFilePreprocessorOnce; | ||
function createAppIosUniModulesSyncFilePreprocessorOnce(isX) { | ||
return isX | ||
? createUniXAppIosUniModulesSyncFilePreprocessorOnce() | ||
: createUniAppIosUniModulesSyncFilePreprocessorOnce(); | ||
} | ||
exports.createAppIosUniModulesSyncFilePreprocessorOnce = createAppIosUniModulesSyncFilePreprocessorOnce; | ||
function createAppHarmonyUniModulesSyncFilePreprocessorOnce(isX) { | ||
return isX | ||
? createUniXAppHarmonyUniModulesSyncFilePreprocessorOnce() | ||
: createUniAppHarmonyUniModulesSyncFilePreprocessorOnce(); | ||
} | ||
exports.createAppHarmonyUniModulesSyncFilePreprocessorOnce = createAppHarmonyUniModulesSyncFilePreprocessorOnce; | ||
const createUniAppAndroidUniModulesSyncFilePreprocessorOnce = (0, uni_shared_1.once)(() => { | ||
return createUniModulesSyncFilePreprocessor('app', 'app-android', false); | ||
}); | ||
const createUniAppIosUniModulesSyncFilePreprocessorOnce = (0, uni_shared_1.once)(() => { | ||
return createUniModulesSyncFilePreprocessor('app', 'app-ios', false); | ||
}); | ||
const createUniAppHarmonyUniModulesSyncFilePreprocessorOnce = (0, uni_shared_1.once)(() => { | ||
return createUniModulesSyncFilePreprocessor('app', 'app-harmony', false); | ||
}); | ||
const createUniXAppAndroidUniModulesSyncFilePreprocessorOnce = (0, uni_shared_1.once)(() => { | ||
return createUniModulesSyncFilePreprocessor('app', 'app-android', true); | ||
}); | ||
const createUniXAppIosUniModulesSyncFilePreprocessorOnce = (0, uni_shared_1.once)(() => { | ||
return createUniModulesSyncFilePreprocessor('app', 'app-ios', true); | ||
}); | ||
const createUniXAppHarmonyUniModulesSyncFilePreprocessorOnce = (0, uni_shared_1.once)(() => { | ||
return createUniModulesSyncFilePreprocessor('app', 'app-harmony', true); | ||
}); | ||
const utsModuleCaches = new Map(); | ||
@@ -31,8 +102,114 @@ const utsPlugins = new Set(); | ||
let uniExtApiCompiler = async () => { }; | ||
function emptyCacheDir(platform) { | ||
const uvueOutputDir = (0, uts_1.uvueOutDir)(platform); | ||
const tscOutputDir = (0, uts_1.tscOutDir)(platform); | ||
function emptyUVueDir() { | ||
if (fs_extra_1.default.existsSync(uvueOutputDir)) { | ||
(0, fs_1.emptyDir)(uvueOutputDir); | ||
} | ||
} | ||
emptyUVueDir(); | ||
function emptyTscDir() { | ||
if (fs_extra_1.default.existsSync(tscOutputDir)) { | ||
(0, fs_1.emptyDir)(tscOutputDir); | ||
} | ||
} | ||
emptyTscDir(); | ||
} | ||
const emptyKotlinCacheDirOnce = (0, uni_shared_1.once)(() => { | ||
emptyCacheDir('app-android'); | ||
}); | ||
const emptySwiftCacheDirOnce = (0, uni_shared_1.once)(() => { | ||
emptyCacheDir('app-ios'); | ||
}); | ||
const emptyHarmonyCacheDirOnce = (0, uni_shared_1.once)(() => { | ||
emptyCacheDir('app-harmony'); | ||
}); | ||
// 该插件仅限app-android、app-ios、app-harmony | ||
function uniUTSAppUniModulesPlugin(options = {}) { | ||
const isX = process.env.UNI_APP_X === 'true'; | ||
const inputDir = process.env.UNI_INPUT_DIR; | ||
process.env.UNI_UTS_USING_ROLLUP = 'true'; | ||
const uniModulesDir = (0, utils_2.normalizePath)(path_1.default.resolve(inputDir, 'uni_modules')); | ||
const { createUniXKotlinCompilerOnce, createUniXSwiftCompilerOnce, createUniXArkTSCompilerOnce, syncUniModuleFilesByCompiler, resolveTscUniModuleIndexFileName, } = (0, uts_1.resolveUTSCompiler)(); | ||
const uniXKotlinCompiler = process.env.UNI_APP_X_TSC === 'true' && | ||
(process.env.UNI_UTS_PLATFORM === 'app-android' || | ||
process.env.UNI_UTS_PLATFORM === 'app') | ||
? createUniXKotlinCompilerOnce() | ||
: null; | ||
const uniXSwiftCompiler = process.env.UNI_APP_X_TSC === 'true' && | ||
(process.env.UNI_UTS_PLATFORM === 'app-ios' || | ||
process.env.UNI_UTS_PLATFORM === 'app') | ||
? createUniXSwiftCompilerOnce() | ||
: null; | ||
const uniXArkTSCompiler = process.env.UNI_APP_X_TSC === 'true' && | ||
process.env.UNI_UTS_PLATFORM === 'app-harmony' | ||
? createUniXArkTSCompilerOnce() | ||
: null; | ||
if (uniXKotlinCompiler) { | ||
emptyKotlinCacheDirOnce(); | ||
(0, uts_1.genUniExtApiDeclarationFileOnce)((0, uts_1.tscOutDir)('app-android')); | ||
} | ||
if (uniXSwiftCompiler) { | ||
emptySwiftCacheDirOnce(); | ||
(0, uts_1.genUniExtApiDeclarationFileOnce)((0, uts_1.tscOutDir)('app-ios')); | ||
} | ||
if (uniXArkTSCompiler) { | ||
emptyHarmonyCacheDirOnce(); | ||
(0, uts_1.genUniExtApiDeclarationFileOnce)((0, uts_1.tscOutDir)('app-harmony')); | ||
} | ||
const changedFiles = new Map(); | ||
const compilePlugin = async (pluginDir) => { | ||
utsPlugins.add(path_1.default.basename(pluginDir)); | ||
const pluginId = path_1.default.basename(pluginDir); | ||
if (uniXKotlinCompiler) { | ||
const platform = 'app-android'; | ||
await syncUniModuleFilesByCompiler(platform, uniXKotlinCompiler, pluginDir, createAppAndroidUniModulesSyncFilePreprocessorOnce(isX)); | ||
} | ||
if (uniXSwiftCompiler) { | ||
const platform = 'app-ios'; | ||
await syncUniModuleFilesByCompiler(platform, uniXSwiftCompiler, pluginDir, createAppIosUniModulesSyncFilePreprocessorOnce(isX)); | ||
} | ||
if (uniXArkTSCompiler) { | ||
const platform = 'app-harmony'; | ||
await syncUniModuleFilesByCompiler(platform, uniXArkTSCompiler, pluginDir, createAppHarmonyUniModulesSyncFilePreprocessorOnce(isX)); | ||
} | ||
if (!utsPlugins.has(pluginId)) { | ||
utsPlugins.add(pluginId); | ||
if (uniXKotlinCompiler) { | ||
const platform = 'app-android'; | ||
const indexFileName = resolveTscUniModuleIndexFileName(platform, pluginDir); | ||
if (indexFileName) { | ||
await uniXKotlinCompiler.addRootFile(indexFileName); | ||
} | ||
} | ||
if (uniXSwiftCompiler) { | ||
const platform = 'app-ios'; | ||
const indexFileName = resolveTscUniModuleIndexFileName(platform, pluginDir); | ||
if (indexFileName) { | ||
await uniXSwiftCompiler.addRootFile(indexFileName); | ||
} | ||
} | ||
if (uniXArkTSCompiler) { | ||
const platform = 'app-harmony'; | ||
const indexFileName = resolveTscUniModuleIndexFileName(platform, pluginDir); | ||
if (indexFileName) { | ||
await uniXArkTSCompiler.addRootFile(indexFileName); | ||
} | ||
} | ||
} | ||
// 处理uni_modules中的文件变更 | ||
const files = changedFiles.get(pluginId); | ||
if (files) { | ||
// 仅限watch模式是会生效 | ||
changedFiles.delete(pluginId); | ||
if (uniXKotlinCompiler) { | ||
await uniXKotlinCompiler.invalidate(files); | ||
} | ||
if (uniXSwiftCompiler) { | ||
await uniXSwiftCompiler.invalidate(files); | ||
} | ||
if (uniXArkTSCompiler) { | ||
await uniXArkTSCompiler.invalidate(files); | ||
} | ||
} | ||
const pkgJson = require(path_1.default.join(pluginDir, 'package.json')); | ||
@@ -44,3 +221,3 @@ const isExtApi = !!pkgJson.uni_modules?.['uni-ext-api']; | ||
if (extApiProvider?.servicePlugin) { | ||
if (fs_1.default.existsSync(path_1.default.resolve(inputDir, 'uni_modules', extApiProvider.servicePlugin))) { | ||
if (fs_extra_1.default.existsSync(path_1.default.resolve(inputDir, 'uni_modules', extApiProvider.servicePlugin))) { | ||
uniExtApiProviderServicePlugin = extApiProvider.servicePlugin; | ||
@@ -51,2 +228,3 @@ } | ||
// 处理依赖的 uts 插件 | ||
// TODO 当本地有ext-api时,也应该自动加入deps,不然uts内部使用了该api,也会导致编译失败 | ||
const deps = (0, uni_modules_1.parseUTSModuleDeps)(pkgJson.uni_modules?.dependencies || [], inputDir); | ||
@@ -69,2 +247,14 @@ if (deps.length) { | ||
} | ||
function filterAutoImports(autoImports, source) { | ||
if (autoImports[source]) { | ||
// 移除 source | ||
return Object.keys(autoImports).reduce((imports, key) => { | ||
if (key !== source) { | ||
imports[key] = autoImports[key]; | ||
} | ||
return imports; | ||
}, {}); | ||
} | ||
return autoImports; | ||
} | ||
return compiler.compile(pluginDir, { | ||
@@ -83,2 +273,12 @@ isX: !!options.x, | ||
}, | ||
async kotlinAutoImports() { | ||
return (0, uts_1.initUTSKotlinAutoImportsOnce)().then((autoImports) => { | ||
return filterAutoImports(autoImports, (0, uts_1.parseKotlinPackageWithPluginId)(pluginId, true)); | ||
}); | ||
}, | ||
async swiftAutoImports() { | ||
return (0, uts_1.initUTSSwiftAutoImportsOnce)().then((autoImports) => { | ||
return filterAutoImports(autoImports, (0, uts_1.parseSwiftPackageWithPluginId)(pluginId, true)); | ||
}); | ||
}, | ||
}); | ||
@@ -93,3 +293,3 @@ }; | ||
if (process.env.UNI_APP_X_UVUE_SCRIPT_ENGINE === 'js') { | ||
if (fs_1.default.existsSync(path_1.default.resolve(pluginDir, 'utssdk', 'app-js', 'index.uts'))) { | ||
if (fs_extra_1.default.existsSync(path_1.default.resolve(pluginDir, 'utssdk', 'app-js', 'index.uts'))) { | ||
continue; | ||
@@ -111,4 +311,15 @@ } | ||
enforce: 'pre', | ||
async configResolved() { | ||
if (uniXKotlinCompiler) { | ||
await uniXKotlinCompiler.init(); | ||
} | ||
if (uniXSwiftCompiler) { | ||
await uniXSwiftCompiler.init(); | ||
} | ||
if (uniXArkTSCompiler) { | ||
await uniXArkTSCompiler.init(); | ||
} | ||
}, | ||
resolveId(id, importer) { | ||
if (isUTSProxy(id) || isUniHelpers(id)) { | ||
if ((0, uts_1.isUTSProxy)(id) || (0, uts_1.isUniHelpers)(id)) { | ||
return id; | ||
@@ -131,9 +342,36 @@ } | ||
load(id) { | ||
if (isUTSProxy(id)) { | ||
if ((0, uts_1.isUTSProxy)(id)) { | ||
return ''; | ||
} | ||
}, | ||
buildEnd() { | ||
async buildEnd() { | ||
utsModuleCaches.clear(); | ||
changedFiles.clear(); | ||
if (process.env.NODE_ENV !== 'development' || !(0, utils_2.isNormalCompileTarget)()) { | ||
if (uniXKotlinCompiler) { | ||
await uniXKotlinCompiler.close(); | ||
} | ||
if (uniXSwiftCompiler) { | ||
await uniXSwiftCompiler.close(); | ||
} | ||
} | ||
}, | ||
watchChange(fileName, change) { | ||
if (uniXKotlinCompiler || uniXSwiftCompiler || uniXArkTSCompiler) { | ||
fileName = (0, utils_2.normalizePath)(fileName); | ||
if (fileName.startsWith(uniModulesDir)) { | ||
// 仅处理uni_modules中的文件 | ||
const plugin = fileName.slice(uniModulesDir.length + 1).split('/')[0]; | ||
if (utsPlugins.has(plugin)) { | ||
const changeFile = { fileName, event: change.event }; | ||
if (!changedFiles.has(plugin)) { | ||
changedFiles.set(plugin, [changeFile]); | ||
} | ||
else { | ||
changedFiles.get(plugin).push(changeFile); | ||
} | ||
} | ||
} | ||
} | ||
}, | ||
async transform(_, id, opts) { | ||
@@ -143,8 +381,9 @@ if (opts && opts.ssr) { | ||
} | ||
if (!isUTSProxy(id)) { | ||
if (!(0, uts_1.isUTSProxy)(id)) { | ||
return; | ||
} | ||
const { filename: pluginDir } = (0, utils_1.parseVueRequest)(id.replace('\0', '')); | ||
const { filename } = (0, utils_1.parseVueRequest)(id.replace('\0', '')); | ||
// 当 vue 和 nvue 均引用了相同 uts 插件,解决两套编译器会编译两次 uts 插件的问题 | ||
// 通过缓存,保证同一个 uts 插件只编译一次 | ||
const pluginDir = (0, utils_2.normalizePath)(filename); | ||
if (utsModuleCaches.get(pluginDir)) { | ||
@@ -206,5 +445,5 @@ return utsModuleCaches.get(pluginDir)().then((result) => { | ||
async configResolved() { | ||
if (isX && process.env.UNI_COMPILE_TARGET !== 'uni_modules') { | ||
if (isX && (0, utils_2.isNormalCompileTarget)()) { | ||
const manifest = (0, json_1.parseManifestJsonOnce)(inputDir); | ||
await (0, uni_modules_1.checkEncryptUniModules)(inputDir, { | ||
await (0, uni_modules_cloud_1.checkEncryptUniModules)(inputDir, { | ||
mode: process.env.NODE_ENV !== 'development' | ||
@@ -224,9 +463,7 @@ ? 'production' | ||
resolveId(id) { | ||
if (isUTSProxy(id) || isUniHelpers(id)) { | ||
if ((0, uts_1.isUTSProxy)(id) || (0, uts_1.isUniHelpers)(id)) { | ||
return id; | ||
} | ||
if (isX && | ||
process.env.UNI_COMPILE_TARGET !== 'uni_modules' && | ||
!id.endsWith('.css')) { | ||
const resolvedId = (0, uni_modules_1.resolveEncryptUniModule)(id, process.env.UNI_UTS_PLATFORM, process.env.UNI_APP_X === 'true'); | ||
if (isX && (0, utils_2.isNormalCompileTarget)() && !id.endsWith('.css')) { | ||
const resolvedId = (0, uni_modules_cloud_1.resolveEncryptUniModule)(id, process.env.UNI_UTS_PLATFORM, process.env.UNI_APP_X === 'true'); | ||
if (resolvedId) { | ||
@@ -233,0 +470,0 @@ return resolvedId; |
@@ -58,3 +58,3 @@ "use strict"; | ||
buildStart() { | ||
assetCache.set(config, new Map()); | ||
assetCache.set(config, [new Map(), new Map()]); | ||
emittedHashMap.set(config, new Set()); | ||
@@ -223,2 +223,3 @@ }, | ||
name: file, | ||
originalFileName: null, | ||
source: content, | ||
@@ -271,3 +272,4 @@ type: 'asset', | ||
} | ||
const cache = assetCache.get(config); | ||
const [cacheForUrl, cacheForBase64] = assetCache.get(config); | ||
const cache = canInline ? cacheForBase64 : cacheForUrl; | ||
const cached = cache.get(id); | ||
@@ -274,0 +276,0 @@ if (cached) { |
@@ -235,3 +235,5 @@ "use strict"; | ||
if (platform === 'app' && | ||
(filename === 'app.css' || filename.startsWith('App.style'))) { | ||
(filename === 'app.css' || | ||
filename.startsWith('App.style') || | ||
filename.startsWith('App.uvue.style'))) { | ||
// 获取 unocss 的样式文件信息 | ||
@@ -264,7 +266,12 @@ const ids = Object.keys(chunk.modules).filter((id) => styles.has(id) && | ||
if (cssChunks.has(filename)) { | ||
cssChunks.get(filename).forEach((id) => { | ||
ids.add(id); | ||
const oldIds = cssChunks.get(filename); | ||
ids.forEach((id) => { | ||
if (!oldIds.includes(id)) { | ||
oldIds.push(id); | ||
} | ||
}); | ||
} | ||
cssChunks.set(filename, [...ids]); | ||
else { | ||
cssChunks.set(filename, Array.from(ids)); | ||
} | ||
} | ||
@@ -271,0 +278,0 @@ }); |
@@ -18,2 +18,3 @@ "use strict"; | ||
exports.isCombineBuiltInCss = exports.buildInCssSet = void 0; | ||
const utils_1 = require("../../utils"); | ||
__exportStar(require("./ast"), exports); | ||
@@ -26,3 +27,3 @@ __exportStar(require("./url"), exports); | ||
function isCombineBuiltInCss(config) { | ||
if (process.env.UNI_COMPILE_TARGET === 'uni_modules') { | ||
if (!(0, utils_1.isNormalCompileTarget)()) { | ||
return false; | ||
@@ -29,0 +30,0 @@ } |
@@ -7,10 +7,16 @@ "use strict"; | ||
const utils_1 = require("../plugins/vitejs/utils"); | ||
const utils_2 = require("../../utils"); | ||
function withSourcemap(config) { | ||
if (process.env.UNI_COMPILE_TARGET === 'uni_modules') { | ||
return false; | ||
if (!process.env.UNI_APP_SOURCEMAP) { | ||
if ((0, shared_1.hasOwn)(config.build, 'sourcemap')) { | ||
if (!!config.build.sourcemap) { | ||
process.env.UNI_APP_SOURCEMAP = 'true'; | ||
} | ||
else { | ||
// vite 的 build 模式默认是false,而非web端的dev也是用build模式,所以不能这样判断 | ||
// process.env.UNI_APP_SOURCEMAP = 'false' | ||
} | ||
} | ||
} | ||
if (config.command === 'serve') { | ||
return true; | ||
} | ||
return !!config.build.sourcemap; | ||
return (0, utils_2.enableSourceMap)(); | ||
} | ||
@@ -17,0 +23,0 @@ exports.withSourcemap = withSourcemap; |
@@ -72,7 +72,17 @@ "use strict"; | ||
if (content) { | ||
fs_extra_1.default.outputFileSync(to, content); | ||
try { | ||
fs_extra_1.default.outputFileSync(to, content); | ||
} | ||
catch (e) { | ||
// noop | ||
} | ||
this.onChange && this.onChange(); | ||
return; | ||
} | ||
fs_extra_1.default.copySync(this.from(from), to, { overwrite: true }); | ||
try { | ||
fs_extra_1.default.copySync(this.from(from), to, { overwrite: true }); | ||
} | ||
catch (e) { | ||
// noop | ||
} | ||
this.onChange && this.onChange(); | ||
@@ -83,3 +93,8 @@ } | ||
this.info('remove', from + '=>' + to); | ||
fs_extra_1.default.removeSync(to); | ||
try { | ||
fs_extra_1.default.removeSync(to); | ||
} | ||
catch (e) { | ||
// noop | ||
} | ||
this.onChange && this.onChange(); | ||
@@ -86,0 +101,0 @@ } |
{ | ||
"name": "@dcloudio/uni-cli-shared", | ||
"version": "3.0.0-alpha-4020820240920001", | ||
"version": "3.0.0-alpha-4030120240925001", | ||
"description": "@dcloudio/uni-cli-shared", | ||
@@ -29,4 +29,4 @@ "main": "dist/index.js", | ||
"@babel/types": "^7.20.7", | ||
"@dcloudio/uni-i18n": "3.0.0-alpha-4020820240920001", | ||
"@dcloudio/uni-shared": "3.0.0-alpha-4020820240920001", | ||
"@dcloudio/uni-i18n": "3.0.0-alpha-4030120240925001", | ||
"@dcloudio/uni-shared": "3.0.0-alpha-4030120240925001", | ||
"@intlify/core-base": "9.1.9", | ||
@@ -70,3 +70,3 @@ "@intlify/shared": "9.1.9", | ||
"tapable": "^2.2.0", | ||
"unplugin-auto-import": "^0.16.7", | ||
"unplugin-auto-import": "^0.18.2", | ||
"xregexp": "3.1.0" | ||
@@ -76,3 +76,3 @@ }, | ||
"devDependencies": { | ||
"@dcloudio/uni-uts-v1": "3.0.0-alpha-4020820240920001", | ||
"@dcloudio/uni-uts-v1": "3.0.0-alpha-4030120240925001", | ||
"@types/adm-zip": "^0.5.5", | ||
@@ -93,5 +93,5 @@ "@types/babel__code-frame": "^7.0.6", | ||
"postcss": "^8.4.21", | ||
"unimport": "^3.9.0", | ||
"unimport": "^3.11.1", | ||
"vue": "3.4.21" | ||
} | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 4 instances in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
3022467
297
83111
314
+ Added@dcloudio/uni-i18n@3.0.0-alpha-4030120240925001(transitive)
+ Added@dcloudio/uni-shared@3.0.0-alpha-4030120240925001(transitive)
+ Addedunplugin-auto-import@0.18.6(transitive)
- Removed@dcloudio/uni-i18n@3.0.0-alpha-4020820240920001(transitive)
- Removed@dcloudio/uni-shared@3.0.0-alpha-4020820240920001(transitive)
- Removedunplugin-auto-import@0.16.7(transitive)
Updatedunplugin-auto-import@^0.18.2