@dcloudio/uni-cli-shared 3.0.0-5020420260813003 → 3.0.0-5020620260917001

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (62) hide show
  1. package/dist/dom2/fontFamily.js +2 -2
  2. package/dist/dom2/index.d.ts +1 -0
  3. package/dist/dom2/index.js +1 -0
  4. package/dist/dom2/script.d.ts +8 -0
  5. package/dist/dom2/script.js +25 -0
  6. package/dist/hbx/env.d.ts +0 -3
  7. package/dist/hbx/env.js +104 -1
  8. package/dist/index.d.ts +2 -0
  9. package/dist/index.js +2 -0
  10. package/dist/json/mp/pages.d.ts +1 -1
  11. package/dist/json/mp/types.d.ts +1 -0
  12. package/dist/json/mp/utils.d.ts +1 -1
  13. package/dist/json/mp/utils.js +13 -1
  14. package/dist/json/uni-x/index.d.ts +5 -0
  15. package/dist/json/uni-x/index.js +17 -8
  16. package/dist/mp/externalClasses.d.ts +17 -0
  17. package/dist/mp/externalClasses.js +77 -1
  18. package/dist/mp/index.d.ts +1 -1
  19. package/dist/mp/index.js +10 -1
  20. package/dist/postcss/plugins/stylePluginExternal.js +46 -0
  21. package/dist/resolve.d.ts +1 -1
  22. package/dist/resolve.js +32 -7
  23. package/dist/uasm.d.ts +75 -0
  24. package/dist/uasm.js +466 -0
  25. package/dist/utils.d.ts +1 -0
  26. package/dist/utils.js +13 -1
  27. package/dist/uts/extApi.d.ts +7 -0
  28. package/dist/uts/extApi.js +34 -0
  29. package/dist/vite/cloud.js +7 -1
  30. package/dist/vite/index.d.ts +10 -0
  31. package/dist/vite/plugins/uts/uni_modules.js +6 -1
  32. package/dist/vite/plugins/uts/uvue.js +122 -19
  33. package/dist/vue/transforms/x/transformMPBuiltInTag.js +3 -0
  34. package/dist/workers.d.ts +1 -0
  35. package/dist/workers.js +23 -5
  36. package/lib/dom2/app/@vitejs/plugin-vue/dist/index.cjs +230 -91
  37. package/lib/dom2/app/@vitejs/plugin-vue/dist/index.d.cts +27 -0
  38. package/lib/dom2/app/@vitejs/plugin-vue/dist/index.d.mts +27 -0
  39. package/lib/dom2/app/@vitejs/plugin-vue/dist/index.d.ts +27 -0
  40. package/lib/dom2/app/@vitejs/plugin-vue/dist/index.mjs +230 -91
  41. package/lib/dom2/app/@vue/compiler-core/dist/compiler-core.cjs.js +54 -15
  42. package/lib/dom2/app/@vue/compiler-core/dist/compiler-core.cjs.prod.js +54 -15
  43. package/lib/dom2/app/@vue/compiler-core/dist/compiler-core.d.ts +7 -8
  44. package/lib/dom2/app/@vue/compiler-core/dist/compiler-core.esm-bundler.js +54 -15
  45. package/lib/dom2/app/@vue/compiler-dom/dist/compiler-dom.cjs.js +12 -3
  46. package/lib/dom2/app/@vue/compiler-dom/dist/compiler-dom.cjs.prod.js +12 -3
  47. package/lib/dom2/app/@vue/compiler-dom/dist/compiler-dom.esm-browser.js +63 -16
  48. package/lib/dom2/app/@vue/compiler-dom/dist/compiler-dom.esm-browser.prod.js +7 -7
  49. package/lib/dom2/app/@vue/compiler-dom/dist/compiler-dom.esm-bundler.js +10 -2
  50. package/lib/dom2/app/@vue/compiler-dom/dist/compiler-dom.global.js +63 -16
  51. package/lib/dom2/app/@vue/compiler-dom/dist/compiler-dom.global.prod.js +7 -7
  52. package/lib/dom2/app/@vue/compiler-sfc/dist/compiler-sfc.cjs.js +383 -3203
  53. package/lib/dom2/app/@vue/compiler-sfc/dist/compiler-sfc.esm-browser.js +984 -498
  54. package/lib/dom2/app/@vue/compiler-vapor/dist/compiler-vapor.cjs.js +370 -268
  55. package/lib/dom2/app/@vue/compiler-vapor/dist/compiler-vapor.d.ts +143 -132
  56. package/lib/dom2/app/@vue/compiler-vapor/dist/compiler-vapor.esm-browser.js +393 -258
  57. package/lib/dom2/app/@vue/compiler-vapor-dom2/dist/compiler-vapor-dom2.cjs.js +1 -1
  58. package/lib/dom2/app/@vue/shared/dist/shared.cjs.js +14 -5
  59. package/lib/dom2/app/@vue/shared/dist/shared.cjs.prod.js +14 -5
  60. package/lib/dom2/app/@vue/shared/dist/shared.d.ts +7 -5
  61. package/lib/dom2/app/@vue/shared/dist/shared.esm-bundler.js +14 -5
  62. package/package.json +5 -5
package/dist/resolve.js CHANGED
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.resolveComponentsLibDirs = exports.resolveComponentsLibPath = exports.resolveVueI18nRuntimeAlias = exports.resolvePiniaAlias = exports.resolvePiniaDependencies = exports.resolveProjectPinia = exports.resolvePinia = exports.resolveVueI18nDependencies = exports.resolveProjectVueI18n = exports.resolveVueI18n = exports.resolveVueI18nRuntime = exports.resolveBuiltIn = exports.getBuiltInPaths = exports.resolveMainPathOnce = exports.relativeFile = exports.resolveMainUtsName = exports.requireResolve = void 0;
6
+ exports.resolveComponentsLibDirs = exports.resolveComponentsLibPath = exports.resolveVueI18nAlias = exports.resolvePiniaAlias = exports.resolvePiniaDependencies = exports.resolveProjectPinia = exports.resolvePinia = exports.resolveVueI18nDependencies = exports.resolveProjectVueI18n = exports.resolveVueI18n = exports.resolveVueI18nRuntime = exports.resolveBuiltIn = exports.getBuiltInPaths = exports.resolveMainPathOnce = exports.relativeFile = exports.resolveMainUtsName = exports.requireResolve = void 0;
7
7
  const fs_1 = __importDefault(require("fs"));
8
8
  const path_1 = __importDefault(require("path"));
9
9
  const debug_1 = __importDefault(require("debug"));
@@ -110,11 +110,13 @@ function resolveBuiltIn(module) {
110
110
  }
111
111
  exports.resolveBuiltIn = resolveBuiltIn;
112
112
  function resolveVueI18nRuntime() {
113
- return path_1.default.resolve(__dirname, '../lib/vue-i18n/dist/vue-i18n.runtime.esm-bundler.js');
113
+ return path_1.default.resolve(__dirname, process.env.UNI_APP_X === 'true'
114
+ ? '../lib/dom2/vue-i18n/dist/vue-i18n.runtime.esm-bundler.js'
115
+ : '../lib/vue-i18n/dist/vue-i18n.runtime.esm-bundler.js');
114
116
  }
115
117
  exports.resolveVueI18nRuntime = resolveVueI18nRuntime;
116
118
  function resolveVueI18n() {
117
- return path_1.default.resolve(__dirname, '../lib/vue-i18n/dist/vue-i18n.runtime.esm-bundler.js');
119
+ return path_1.default.resolve(__dirname, '../lib/dom2/vue-i18n/dist/vue-i18n.esm-bundler.js');
118
120
  }
119
121
  exports.resolveVueI18n = resolveVueI18n;
120
122
  function resolveProjectModule(module) {
@@ -136,7 +138,17 @@ function resolveDevtoolsApi(libDir) {
136
138
  return path_1.default.resolve(libDir, '@vue/devtools-api/dist/index.js');
137
139
  }
138
140
  function resolveVueI18nDependencies() {
139
- return {};
141
+ if (process.env.UNI_APP_X !== 'true' ||
142
+ resolveProjectVueI18n() !== undefined) {
143
+ return {};
144
+ }
145
+ const libDir = path_1.default.resolve(__dirname, '../lib/dom2');
146
+ return {
147
+ '@intlify/core-base': path_1.default.resolve(libDir, '@intlify/core-base/dist/core-base.mjs'),
148
+ '@intlify/message-compiler': path_1.default.resolve(libDir, '@intlify/message-compiler/dist/message-compiler.mjs'),
149
+ '@intlify/shared': path_1.default.resolve(libDir, '@intlify/shared/dist/shared.mjs'),
150
+ '@vue/devtools-api': resolveDevtoolsApi(libDir),
151
+ };
140
152
  }
141
153
  exports.resolveVueI18nDependencies = resolveVueI18nDependencies;
142
154
  function resolvePinia() {
@@ -162,17 +174,30 @@ function resolvePiniaAlias() {
162
174
  }
163
175
  return {
164
176
  ...resolvePiniaDependencies(),
177
+ 'pinia/package.json': path_1.default.resolve(__dirname, '../lib/dom2/pinia/package.json'),
165
178
  pinia: resolvePinia(),
166
179
  };
167
180
  }
168
181
  exports.resolvePiniaAlias = resolvePiniaAlias;
169
- function resolveVueI18nRuntimeAlias() {
182
+ function resolveVueI18nAlias() {
183
+ if (process.env.UNI_APP_X === 'true' &&
184
+ resolveProjectVueI18n() !== undefined) {
185
+ return {};
186
+ }
170
187
  return {
171
188
  ...resolveVueI18nDependencies(),
172
- 'vue-i18n': resolveVueI18nRuntime(),
189
+ ...(process.env.UNI_APP_X === 'true'
190
+ ? {
191
+ 'vue-i18n/package.json': path_1.default.resolve(__dirname, '../lib/dom2/vue-i18n/package.json'),
192
+ }
193
+ : {}),
194
+ 'vue-i18n/runtime': resolveVueI18nRuntime(),
195
+ 'vue-i18n': process.env.UNI_APP_X === 'true'
196
+ ? resolveVueI18n()
197
+ : resolveVueI18nRuntime(),
173
198
  };
174
199
  }
175
- exports.resolveVueI18nRuntimeAlias = resolveVueI18nRuntimeAlias;
200
+ exports.resolveVueI18nAlias = resolveVueI18nAlias;
176
201
  let componentsLibPath = '';
177
202
  function resolveComponentsLibPath() {
178
203
  if (!componentsLibPath) {
package/dist/uasm.d.ts ADDED
@@ -0,0 +1,75 @@
1
+ import type { DiagnosticWithLocation, SourceFile, TransformationContext, TransformerFactory } from 'typescript';
2
+ import type { Plugin } from 'vite';
3
+ type TypeScriptCompiler = typeof import('typescript');
4
+ export interface UasmSourceEdit {
5
+ start: number;
6
+ end: number;
7
+ content: string;
8
+ }
9
+ export interface LoadUasmTransformOptions {
10
+ targetArchs?: string[];
11
+ resolve(modulePath: string): ResolvedUasmLoad | undefined;
12
+ }
13
+ export interface LoadUasmTransformerOptions extends LoadUasmTransformOptions {
14
+ typescript: TypeScriptCompiler;
15
+ resolveLoader?: (modulePath: string) => ResolvedUasmLoader | undefined;
16
+ onSourceEdit?: (edit: UasmSourceEdit) => void;
17
+ resolveError?: (modulePath: string) => string;
18
+ reportDiagnostic(context: TransformationContext, diagnostic: DiagnosticWithLocation): void;
19
+ }
20
+ export interface UasmTransformOptions extends LoadUasmTransformOptions {
21
+ createLoadUasmTransformer: typeof createLoadUasmTransformer;
22
+ }
23
+ export type UasmTransformerFactoryCreator = (typescript: TypeScriptCompiler) => {
24
+ before: TransformerFactory<SourceFile>;
25
+ };
26
+ export type UasmPlatform = 'app-android' | 'app-ios' | 'app-harmony';
27
+ export interface UasmArchResources {
28
+ dir: string;
29
+ file: string;
30
+ }
31
+ export interface UasmPlatformResources {
32
+ dir: string;
33
+ archs: Record<string, UasmArchResources>;
34
+ }
35
+ export interface UasmModule {
36
+ name: string;
37
+ platforms: Partial<Record<UasmPlatform, UasmPlatformResources>>;
38
+ web?: UasmWebResources;
39
+ }
40
+ export interface UasmWebResources {
41
+ entry: string;
42
+ }
43
+ export interface UasmWebLoadDescriptor {
44
+ id: string;
45
+ entry: string;
46
+ }
47
+ export type ResolvedUasmLoad = string | UasmWebLoadDescriptor;
48
+ export interface UasmLoaderDescriptor {
49
+ type: string;
50
+ value: string;
51
+ imports?: string[];
52
+ }
53
+ export type ResolvedUasmLoader = string | UasmLoaderDescriptor;
54
+ export interface ResolvedUasmModule {
55
+ name: string;
56
+ platform: UasmPlatform;
57
+ arch?: string;
58
+ dir: string;
59
+ file?: string;
60
+ }
61
+ export declare function parseUniAppXTargetArchs(value?: string | undefined): string[];
62
+ export declare function initUasmTransformOptions(platform: UasmPlatform): UasmTransformOptions;
63
+ export declare function initUasmTransformerCreator(platform: UasmPlatform): UasmTransformerFactoryCreator | undefined;
64
+ export declare function initUasmWebTransformOptions(): UasmTransformOptions;
65
+ export declare function createLoadUasmTransformer(options: LoadUasmTransformerOptions): TransformerFactory<SourceFile>;
66
+ export declare function initUasmModules(inputDir: string): Record<string, UasmModule>;
67
+ export declare function uniUasmPlugin(inputDir?: string): Plugin;
68
+ export declare function getUasmModules(): Record<string, UasmModule>;
69
+ export declare function resolveUasmTargetArch(moduleName: string, platform: UasmPlatform, targetArchs?: string[]): string | undefined;
70
+ export declare function resolveUasmModule(moduleName: string, platform: UasmPlatform, targetArchs?: string[]): ResolvedUasmModule | undefined;
71
+ export declare function parseUasmModuleName(modulePath: string): string | undefined;
72
+ export declare function resolveUasmWebLoad(modulePath: string): UasmWebLoadDescriptor | undefined;
73
+ export declare function resolveUasmLoadPath(modulePath: string, platform: UasmPlatform, isProduction?: boolean, targetArchs?: string[]): string | undefined;
74
+ export declare function resolveUasmCopyAssets(platform: UasmPlatform, isProduction: boolean, targetArchs?: string[]): string[];
75
+ export {};
package/dist/uasm.js ADDED
@@ -0,0 +1,466 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.resolveUasmCopyAssets = exports.resolveUasmLoadPath = exports.resolveUasmWebLoad = exports.parseUasmModuleName = exports.resolveUasmModule = exports.resolveUasmTargetArch = exports.getUasmModules = exports.uniUasmPlugin = exports.initUasmModules = exports.createLoadUasmTransformer = exports.initUasmWebTransformOptions = exports.initUasmTransformerCreator = exports.initUasmTransformOptions = exports.parseUniAppXTargetArchs = void 0;
7
+ const fs_extra_1 = __importDefault(require("fs-extra"));
8
+ const node_path_1 = __importDefault(require("node:path"));
9
+ const fast_glob_1 = require("fast-glob");
10
+ const utils_1 = require("./utils");
11
+ const uts_1 = require("./uts");
12
+ const UASM_PLATFORMS = ['app-android', 'app-ios', 'app-harmony'];
13
+ const UASM_IOS_MANIFEST_VERSION = 1;
14
+ let uasmModules = Object.create(null);
15
+ function parseUniAppXTargetArchs(value = process.env.UNI_APP_X_TARGET_ARCHS) {
16
+ if (!value) {
17
+ return [];
18
+ }
19
+ try {
20
+ const targetArchs = JSON.parse(value);
21
+ return Array.isArray(targetArchs)
22
+ ? targetArchs.filter((arch) => typeof arch === 'string' && !!arch)
23
+ : [];
24
+ }
25
+ catch {
26
+ return [];
27
+ }
28
+ }
29
+ exports.parseUniAppXTargetArchs = parseUniAppXTargetArchs;
30
+ function initUasmTransformOptions(platform) {
31
+ return {
32
+ targetArchs: parseUniAppXTargetArchs(),
33
+ resolve: (modulePath) => resolveUasmLoadPath(modulePath, platform),
34
+ createLoadUasmTransformer,
35
+ };
36
+ }
37
+ exports.initUasmTransformOptions = initUasmTransformOptions;
38
+ function initUasmTransformerCreator(platform) {
39
+ if (process.env.UNI_APP_X_DOM2 !== 'true') {
40
+ return;
41
+ }
42
+ const options = initUasmTransformOptions(platform);
43
+ return (typescript) => ({
44
+ before: options.createLoadUasmTransformer({
45
+ ...options,
46
+ typescript,
47
+ resolveLoader: platform === 'app-android'
48
+ ? resolveUasmAndroidLoader
49
+ : platform === 'app-ios'
50
+ ? resolveUasmIOSLoader
51
+ : undefined,
52
+ reportDiagnostic(context, diagnostic) {
53
+ const utsContext = context;
54
+ if (utsContext.error) {
55
+ utsContext.error(diagnostic);
56
+ }
57
+ else {
58
+ throw new Error(diagnostic.messageText.toString());
59
+ }
60
+ },
61
+ }),
62
+ });
63
+ }
64
+ exports.initUasmTransformerCreator = initUasmTransformerCreator;
65
+ function initUasmWebTransformOptions() {
66
+ return {
67
+ resolve: resolveUasmWebLoad,
68
+ createLoadUasmTransformer(options) {
69
+ return createLoadUasmTransformer({
70
+ ...options,
71
+ resolveError(modulePath) {
72
+ const moduleName = parseUasmModuleName(modulePath);
73
+ const entry = moduleName
74
+ ? `uni_modules/${moduleName}/uasm/web/${moduleName}.js`
75
+ : 'uni_modules/<插件ID>/uasm/web/<插件ID>.js';
76
+ return `无法加载 uasm 插件[${modulePath}],请确认插件路径正确,且插件已提供入口文件 ${entry}`;
77
+ },
78
+ });
79
+ },
80
+ };
81
+ }
82
+ exports.initUasmWebTransformOptions = initUasmWebTransformOptions;
83
+ function createUasmDiagnostic(options, sourceFile, node, messageText) {
84
+ return {
85
+ file: sourceFile,
86
+ start: node.getStart(sourceFile),
87
+ length: node.getWidth(sourceFile),
88
+ code: 0,
89
+ category: options.typescript.DiagnosticCategory.Error,
90
+ messageText,
91
+ };
92
+ }
93
+ function createLoadUasmTransformer(options) {
94
+ const { typescript, resolve, reportDiagnostic } = options;
95
+ const targetArchs = options.targetArchs?.join(', ') || '未指定';
96
+ return (context) => {
97
+ const { factory } = context;
98
+ return (sourceFile) => {
99
+ const imports = new Set();
100
+ const visitor = (node) => {
101
+ if (typescript.isCallExpression(node) &&
102
+ node.arguments.length >= 1 &&
103
+ typescript.isPropertyAccessExpression(node.expression) &&
104
+ node.expression.name.escapedText === 'loadUASM' &&
105
+ typescript.isIdentifier(node.expression.expression) &&
106
+ node.expression.expression.escapedText === 'uni') {
107
+ const firstArg = node.arguments[0];
108
+ if (!typescript.isStringLiteral(firstArg) &&
109
+ !typescript.isNoSubstitutionTemplateLiteral(firstArg)) {
110
+ reportDiagnostic(context, createUasmDiagnostic(options, sourceFile, firstArg, 'uni.loadUASM(modulePath) 的 modulePath 参数必须是字符串字面量'));
111
+ return node;
112
+ }
113
+ const resolved = resolve(firstArg.text);
114
+ if (!resolved) {
115
+ reportDiagnostic(context, createUasmDiagnostic(options, sourceFile, firstArg, options.resolveError?.(firstArg.text) ||
116
+ `无法加载 uasm 插件[${firstArg.text}],当前设备支持的 ABI:${targetArchs}。请确认插件路径正确,且插件已提供匹配的库文件`));
117
+ return node;
118
+ }
119
+ const loader = options.resolveLoader?.(firstArg.text);
120
+ if (loader && typeof loader !== 'string') {
121
+ loader.imports?.forEach((module) => imports.add(module));
122
+ }
123
+ options.onSourceEdit?.({
124
+ start: firstArg.getStart(sourceFile),
125
+ end: firstArg.getEnd(),
126
+ content: resolveUasmSourceEdit(resolved),
127
+ });
128
+ return factory.updateCallExpression(node, node.expression, node.typeArguments, [
129
+ typeof resolved === 'string'
130
+ ? factory.createStringLiteral(resolved)
131
+ : factory.createObjectLiteralExpression([
132
+ factory.createPropertyAssignment('id', factory.createStringLiteral(resolved.id)),
133
+ factory.createPropertyAssignment('loader', factory.createArrowFunction(undefined, undefined, [], undefined, factory.createToken(typescript.SyntaxKind.EqualsGreaterThanToken), factory.createCallExpression(factory.createToken(typescript.SyntaxKind.ImportKeyword), undefined, [factory.createStringLiteral(resolved.entry)]))),
134
+ ], false),
135
+ ...(loader
136
+ ? [createUasmLoader(factory, loader, typescript)]
137
+ : []),
138
+ ...node.arguments.slice(1),
139
+ ]);
140
+ }
141
+ return typescript.visitEachChild(node, visitor, context);
142
+ };
143
+ const transformed = typescript.visitNode(sourceFile, visitor);
144
+ if (!imports.size) {
145
+ return transformed;
146
+ }
147
+ return factory.updateSourceFile(transformed, [
148
+ ...Array.from(imports).map((module) => factory.createImportDeclaration(undefined, undefined, factory.createStringLiteral(module))),
149
+ ...transformed.statements,
150
+ ]);
151
+ };
152
+ };
153
+ }
154
+ exports.createLoadUasmTransformer = createLoadUasmTransformer;
155
+ function resolveUasmAndroidLoader(modulePath) {
156
+ const moduleName = parseUasmModuleName(modulePath);
157
+ if (!moduleName) {
158
+ return;
159
+ }
160
+ const packageName = (0, uts_1.parseKotlinPackageWithPluginId)(moduleName, true);
161
+ const className = (0, utils_1.capitalize)((0, utils_1.camelize)(moduleName));
162
+ return `${packageName}.${className}`;
163
+ }
164
+ function resolveUasmIOSLoader(modulePath) {
165
+ const moduleName = parseUasmModuleName(modulePath);
166
+ if (!moduleName) {
167
+ return;
168
+ }
169
+ const swiftModule = (0, uts_1.parseSwiftModuleWithPluginId)(moduleName, true);
170
+ const className = (0, utils_1.capitalize)((0, utils_1.camelize)(moduleName));
171
+ const type = `${swiftModule}.${className}`;
172
+ return {
173
+ type: `${type}.Type`,
174
+ value: `${type}.self`,
175
+ imports: [swiftModule],
176
+ };
177
+ }
178
+ function createUasmLoader(factory, loader, typescript) {
179
+ const descriptor = typeof loader === 'string' ? { type: loader, value: loader } : loader;
180
+ const [firstType, ...restType] = descriptor.type.split('.');
181
+ const typeName = restType.reduce((typeName, name) => factory.createQualifiedName(typeName, name), factory.createIdentifier(firstType));
182
+ const [firstValue, ...restValue] = descriptor.value.split('.');
183
+ const expression = restValue.reduce((expression, name) => factory.createPropertyAccessExpression(expression, name), factory.createIdentifier(firstValue));
184
+ return factory.createArrowFunction(undefined, undefined, [], factory.createTypeReferenceNode(typeName), factory.createToken(typescript.SyntaxKind.EqualsGreaterThanToken), expression);
185
+ }
186
+ function resolveUasmSourceEdit(resolved) {
187
+ if (typeof resolved === 'string') {
188
+ return JSON.stringify(resolved);
189
+ }
190
+ return `{ id: ${JSON.stringify(resolved.id)}, loader: () => import(${JSON.stringify(resolved.entry)}) }`;
191
+ }
192
+ function initUasmModules(inputDir) {
193
+ uasmModules = scanUasmModules(inputDir, UASM_PLATFORMS);
194
+ return uasmModules;
195
+ }
196
+ exports.initUasmModules = initUasmModules;
197
+ function uniUasmPlugin(inputDir = process.env.UNI_INPUT_DIR) {
198
+ let processed = false;
199
+ initUasmModules(inputDir);
200
+ return {
201
+ name: 'uni:uasm',
202
+ apply: 'build',
203
+ enforce: 'post',
204
+ writeBundle() {
205
+ if (processed || !shouldCopyUasmIOSFrameworks()) {
206
+ return;
207
+ }
208
+ copyUasmIOSFrameworks(inputDir);
209
+ processed = true;
210
+ },
211
+ };
212
+ }
213
+ exports.uniUasmPlugin = uniUasmPlugin;
214
+ function shouldCopyUasmIOSFrameworks() {
215
+ return (process.env.UNI_UTS_PLATFORM === 'app-ios' &&
216
+ (process.env.UNI_NODE_ENV || process.env.NODE_ENV) === 'development' &&
217
+ process.env.UNI_APP_X_DOM2 === 'true' &&
218
+ !process.env.UNI_COMPILE_TARGET);
219
+ }
220
+ function copyUasmIOSFrameworks(inputDir) {
221
+ const dependenciesDir = process.env.HX_DEPENDENCIES_DIR;
222
+ if (!dependenciesDir) {
223
+ return;
224
+ }
225
+ const libraryIdentifier = process.env.HX_RUN_DEVICE_TYPE === 'ios_simulator'
226
+ ? 'ios-arm64-simulator'
227
+ : 'ios-arm64';
228
+ const targetDir = node_path_1.default.resolve(dependenciesDir, 'modules');
229
+ for (const module of Object.values(uasmModules)) {
230
+ const resources = module.platforms['app-ios'];
231
+ if (!resources) {
232
+ continue;
233
+ }
234
+ const frameworksDir = node_path_1.default.resolve(inputDir, resources.dir);
235
+ const pluginRelativeDir = node_path_1.default.join('uni_modules', module.name, 'uasm');
236
+ const manifestFile = node_path_1.default.resolve(dependenciesDir, 'app-ios', 'uasm', pluginRelativeDir, 'manifest.json');
237
+ const sourceDirs = fs_extra_1.default
238
+ .readdirSync(frameworksDir, { withFileTypes: true })
239
+ .filter((entry) => isDirectoryEntry(frameworksDir, entry) &&
240
+ entry.name.endsWith('.xcframework'))
241
+ .map((entry) => ({
242
+ name: entry.name,
243
+ dir: node_path_1.default.resolve(frameworksDir, entry.name, libraryIdentifier),
244
+ }))
245
+ .filter(({ dir }) => fs_extra_1.default.existsSync(dir))
246
+ .sort((a, b) => a.name.localeCompare(b.name));
247
+ const manifest = resolveUasmIOSCopyManifest(sourceDirs, libraryIdentifier);
248
+ const oldManifest = readUasmIOSCopyManifest(manifestFile);
249
+ if (JSON.stringify(oldManifest) === JSON.stringify(manifest)) {
250
+ continue;
251
+ }
252
+ sourceDirs.forEach(({ dir }) => fs_extra_1.default.copySync(dir, targetDir, { overwrite: true }));
253
+ fs_extra_1.default.outputJsonSync(manifestFile, manifest, { spaces: 2 });
254
+ }
255
+ }
256
+ function resolveUasmIOSCopyManifest(sourceDirs, libraryIdentifier) {
257
+ const manifest = {
258
+ version: UASM_IOS_MANIFEST_VERSION,
259
+ libraryIdentifier,
260
+ files: Object.create(null),
261
+ };
262
+ sourceDirs.forEach(({ name, dir }) => {
263
+ (0, fast_glob_1.sync)('**/*', {
264
+ cwd: dir,
265
+ dot: true,
266
+ onlyFiles: false,
267
+ followSymbolicLinks: false,
268
+ })
269
+ .sort()
270
+ .forEach((file) => {
271
+ const absoluteFile = node_path_1.default.resolve(dir, file);
272
+ const stat = fs_extra_1.default.lstatSync(absoluteFile);
273
+ if (!stat.isFile() && !stat.isSymbolicLink()) {
274
+ return;
275
+ }
276
+ const manifestFile = {
277
+ size: stat.size,
278
+ mtimeMs: stat.mtimeMs,
279
+ mode: stat.mode,
280
+ };
281
+ if (stat.isSymbolicLink()) {
282
+ manifestFile.link = fs_extra_1.default.readlinkSync(absoluteFile);
283
+ }
284
+ manifest.files[(0, utils_1.normalizePath)(node_path_1.default.join(name, file))] = manifestFile;
285
+ });
286
+ });
287
+ return manifest;
288
+ }
289
+ function readUasmIOSCopyManifest(file) {
290
+ try {
291
+ return fs_extra_1.default.readJsonSync(file);
292
+ }
293
+ catch { }
294
+ }
295
+ function scanUasmModules(inputDir, platformsToScan) {
296
+ const modules = Object.create(null);
297
+ const uniModulesDir = node_path_1.default.resolve(inputDir, 'uni_modules');
298
+ if (!fs_extra_1.default.existsSync(uniModulesDir)) {
299
+ return modules;
300
+ }
301
+ fs_extra_1.default.readdirSync(uniModulesDir, { withFileTypes: true }).forEach((entry) => {
302
+ if (!isDirectoryEntry(uniModulesDir, entry)) {
303
+ return;
304
+ }
305
+ const platforms = {};
306
+ for (const platform of platformsToScan) {
307
+ const resources = scanUasmPlatform(inputDir, entry.name, platform);
308
+ if (resources) {
309
+ platforms[platform] = resources;
310
+ }
311
+ }
312
+ const web = scanUasmWeb(inputDir, entry.name);
313
+ if (Object.keys(platforms).length || web) {
314
+ modules[entry.name] = {
315
+ name: entry.name,
316
+ platforms,
317
+ ...(web ? { web } : {}),
318
+ };
319
+ }
320
+ });
321
+ return modules;
322
+ }
323
+ function getUasmModules() {
324
+ return uasmModules;
325
+ }
326
+ exports.getUasmModules = getUasmModules;
327
+ function resolveUasmTargetArch(moduleName, platform, targetArchs = parseUniAppXTargetArchs()) {
328
+ const archs = uasmModules[moduleName]?.platforms[platform]?.archs;
329
+ return archs && targetArchs.find((arch) => archs[arch]);
330
+ }
331
+ exports.resolveUasmTargetArch = resolveUasmTargetArch;
332
+ function resolveUasmModule(moduleName, platform, targetArchs = parseUniAppXTargetArchs()) {
333
+ return resolveUasmModuleFrom(uasmModules, moduleName, platform, targetArchs);
334
+ }
335
+ exports.resolveUasmModule = resolveUasmModule;
336
+ function parseUasmModuleName(modulePath) {
337
+ const normalized = modulePath.replace(/^@?\//, '');
338
+ return /^uni_modules\/([^/]+)$/.exec(normalized)?.[1];
339
+ }
340
+ exports.parseUasmModuleName = parseUasmModuleName;
341
+ function resolveUasmWebLoad(modulePath) {
342
+ const moduleName = parseUasmModuleName(modulePath);
343
+ const entry = moduleName && uasmModules[moduleName]?.web?.entry;
344
+ if (!moduleName || !entry) {
345
+ return;
346
+ }
347
+ return {
348
+ id: moduleName,
349
+ entry: `@/${entry}`,
350
+ };
351
+ }
352
+ exports.resolveUasmWebLoad = resolveUasmWebLoad;
353
+ function resolveUasmLoadPath(modulePath, platform, isProduction = (process.env.UNI_NODE_ENV || process.env.NODE_ENV) !==
354
+ 'development', targetArchs = parseUniAppXTargetArchs()) {
355
+ const moduleName = parseUasmModuleName(modulePath);
356
+ if (!moduleName || !uasmModules[moduleName]?.platforms[platform]) {
357
+ return;
358
+ }
359
+ if (platform === 'app-ios') {
360
+ return moduleName;
361
+ }
362
+ const libraryName = `lib${moduleName}.so`;
363
+ if (isProduction) {
364
+ return libraryName;
365
+ }
366
+ const file = resolveUasmModule(moduleName, platform, targetArchs)?.file;
367
+ if (!file) {
368
+ return;
369
+ }
370
+ return platform === 'app-harmony' ? libraryName : file;
371
+ }
372
+ exports.resolveUasmLoadPath = resolveUasmLoadPath;
373
+ function resolveUasmModuleFrom(modules, moduleName, platform, targetArchs) {
374
+ const resources = modules[moduleName]?.platforms[platform];
375
+ if (!resources) {
376
+ return;
377
+ }
378
+ if (platform === 'app-ios') {
379
+ return {
380
+ name: moduleName,
381
+ platform,
382
+ dir: resources.dir,
383
+ };
384
+ }
385
+ const arch = targetArchs.find((arch) => resources.archs[arch]);
386
+ if (!arch) {
387
+ return;
388
+ }
389
+ const archResources = resources.archs[arch];
390
+ return {
391
+ name: moduleName,
392
+ platform,
393
+ arch,
394
+ dir: archResources.dir,
395
+ file: archResources.file,
396
+ };
397
+ }
398
+ function resolveUasmCopyAssets(platform, isProduction, targetArchs = parseUniAppXTargetArchs()) {
399
+ const resourceDir = platform === 'app-ios' ? 'frameworks' : 'libs';
400
+ if (isProduction) {
401
+ return [`uni_modules/*/uasm/${platform}/${resourceDir}/**/*`];
402
+ }
403
+ if (platform === 'app-ios' || !targetArchs.length) {
404
+ return [];
405
+ }
406
+ return Object.keys(uasmModules).reduce((assets, moduleName) => {
407
+ const resolved = resolveUasmModule(moduleName, platform, targetArchs);
408
+ if (resolved) {
409
+ assets.push(`${resolved.dir}/**/*`);
410
+ }
411
+ return assets;
412
+ }, []);
413
+ }
414
+ exports.resolveUasmCopyAssets = resolveUasmCopyAssets;
415
+ function scanUasmPlatform(inputDir, moduleName, platform) {
416
+ const resourceDir = platform === 'app-ios' ? 'frameworks' : 'libs';
417
+ const relativeDir = (0, utils_1.normalizePath)(node_path_1.default.join('uni_modules', moduleName, 'uasm', platform, resourceDir));
418
+ const absoluteDir = node_path_1.default.resolve(inputDir, relativeDir);
419
+ if (!fs_extra_1.default.existsSync(absoluteDir)) {
420
+ return;
421
+ }
422
+ const resources = {
423
+ dir: relativeDir,
424
+ archs: Object.create(null),
425
+ };
426
+ if (platform !== 'app-ios') {
427
+ fs_extra_1.default.readdirSync(absoluteDir, { withFileTypes: true }).forEach((entry) => {
428
+ if (!isDirectoryEntry(absoluteDir, entry)) {
429
+ return;
430
+ }
431
+ const relativeArchDir = (0, utils_1.normalizePath)(node_path_1.default.join(relativeDir, entry.name));
432
+ const file = (0, utils_1.normalizePath)(node_path_1.default.join(relativeArchDir, `lib${moduleName}.so`));
433
+ if (!fs_extra_1.default.existsSync(node_path_1.default.resolve(inputDir, file))) {
434
+ return;
435
+ }
436
+ resources.archs[entry.name] = {
437
+ dir: relativeArchDir,
438
+ file,
439
+ };
440
+ });
441
+ if (!Object.keys(resources.archs).length) {
442
+ return;
443
+ }
444
+ }
445
+ return resources;
446
+ }
447
+ function scanUasmWeb(inputDir, moduleName) {
448
+ const entry = (0, utils_1.normalizePath)(node_path_1.default.join('uni_modules', moduleName, 'uasm', 'web', `${moduleName}.js`));
449
+ if (fs_extra_1.default.existsSync(node_path_1.default.resolve(inputDir, entry))) {
450
+ return { entry };
451
+ }
452
+ }
453
+ function isDirectoryEntry(parentDir, entry) {
454
+ if (entry.isDirectory()) {
455
+ return true;
456
+ }
457
+ if (!entry.isSymbolicLink()) {
458
+ return false;
459
+ }
460
+ try {
461
+ return fs_extra_1.default.statSync(node_path_1.default.resolve(parentDir, entry.name)).isDirectory();
462
+ }
463
+ catch {
464
+ return false;
465
+ }
466
+ }
package/dist/utils.d.ts CHANGED
@@ -44,3 +44,4 @@ export declare function isNormalCompileTarget(): boolean;
44
44
  * @returns
45
45
  */
46
46
  export declare function getEscaper(regex: RegExp, map: Map<number, string>): (data: string) => string;
47
+ export declare function getHarmonyRuntimePackageName(isX: boolean, isDom2: boolean): string;
package/dist/utils.js CHANGED
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.getEscaper = exports.isNormalCompileTarget = exports.createShadowImageUrl = exports.getShadowImagePath = 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;
6
+ exports.getHarmonyRuntimePackageName = exports.getEscaper = exports.isNormalCompileTarget = exports.createShadowImageUrl = exports.getShadowImagePath = 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;
7
7
  const fs_1 = __importDefault(require("fs"));
8
8
  const os_1 = __importDefault(require("os"));
9
9
  const path_1 = __importDefault(require("path"));
@@ -268,3 +268,15 @@ function getEscaper(regex, map) {
268
268
  };
269
269
  }
270
270
  exports.getEscaper = getEscaper;
271
+ function getHarmonyRuntimePackageName(isX, isDom2) {
272
+ if (!isX) {
273
+ return '@dcloudio/uni-app-runtime';
274
+ }
275
+ else if (!isDom2) {
276
+ return '@dcloudio/uni-app-x-runtime';
277
+ }
278
+ else {
279
+ return '@dcloudio/uni-app-x-vapor-runtime';
280
+ }
281
+ }
282
+ exports.getHarmonyRuntimePackageName = getHarmonyRuntimePackageName;
@@ -0,0 +1,7 @@
1
+ import type { SourceFile } from 'typescript';
2
+ type TypeScriptCompiler = typeof import('typescript');
3
+ export declare function initUts2jsExtApiOptions(): {
4
+ collectExtApiUsageAst: typeof collectExtApiUsageAst;
5
+ };
6
+ export declare function collectExtApiUsageAst(sourceFile: SourceFile, typescript: TypeScriptCompiler): string[] | undefined;
7
+ export {};