@dcloudio/uni-cli-shared 3.0.0-5000720260410001 → 3.0.0-5010420260703001

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 (90) hide show
  1. package/dist/constants.d.ts +1 -3
  2. package/dist/constants.js +2 -6
  3. package/dist/deps.d.ts +1 -0
  4. package/dist/deps.js +22 -13
  5. package/dist/dom2/fontFamily.d.ts +4 -0
  6. package/dist/dom2/fontFamily.js +21 -0
  7. package/dist/dom2/index.d.ts +3 -0
  8. package/dist/dom2/index.js +3 -0
  9. package/dist/dom2/rootScrollView.d.ts +47 -0
  10. package/dist/dom2/rootScrollView.js +283 -0
  11. package/dist/dom2/sharedData.d.ts +4 -0
  12. package/dist/dom2/sharedData.js +40 -5
  13. package/dist/dom2/vue.d.ts +17 -0
  14. package/dist/dom2/vue.js +50 -0
  15. package/dist/easycom.d.ts +1 -0
  16. package/dist/easycom.js +23 -9
  17. package/dist/env/define.d.ts +0 -1
  18. package/dist/env/define.js +3 -11
  19. package/dist/hbx/alias.js +66 -10
  20. package/dist/hbx/log.js +9 -2
  21. package/dist/index.d.ts +2 -1
  22. package/dist/index.js +3 -1
  23. package/dist/json/app/manifest/plus.js +9 -1
  24. package/dist/json/index.d.ts +1 -1
  25. package/dist/json/index.js +2 -1
  26. package/dist/json/uni-x/index.d.ts +6 -0
  27. package/dist/json/uni-x/index.js +54 -1
  28. package/dist/json/uni-x/manifest.d.ts +1 -1
  29. package/dist/json/uni-x/manifest.js +2 -1
  30. package/dist/json/utils.js +24 -0
  31. package/dist/messages/en.d.ts +10 -2
  32. package/dist/messages/en.js +10 -2
  33. package/dist/messages/index.d.ts +20 -4
  34. package/dist/messages/zh_CN.d.ts +10 -2
  35. package/dist/messages/zh_CN.js +10 -2
  36. package/dist/mp/style.js +6 -2
  37. package/dist/postcss/plugins/stylePluginExternal.d.ts +9 -10
  38. package/dist/postcss/plugins/stylePluginExternal.js +51 -45
  39. package/dist/uni_modules.cloud.d.ts +7 -1
  40. package/dist/uni_modules.cloud.js +131 -14
  41. package/dist/uni_modules.js +3 -2
  42. package/dist/utils.js +5 -0
  43. package/dist/uts.d.ts +1 -0
  44. package/dist/uts.js +90 -6
  45. package/dist/vite/autoImport.js +7 -4
  46. package/dist/vite/cloud.js +13 -6
  47. package/dist/vite/extApi.js +4 -1
  48. package/dist/vite/plugins/inject.js +4 -1
  49. package/dist/vite/plugins/json.js +2 -69
  50. package/dist/vite/plugins/pre.js +2 -0
  51. package/dist/vite/plugins/stats.d.ts +5 -1
  52. package/dist/vite/plugins/stats.js +74 -3
  53. package/dist/vite/plugins/uts/uni_modules.d.ts +1 -1
  54. package/dist/vite/plugins/uts/uni_modules.js +30 -12
  55. package/dist/vite/plugins/vitejs/plugins/css.d.ts +2 -2
  56. package/dist/vite/plugins/vitejs/plugins/css.js +10 -5
  57. package/dist/vue/transforms/index.d.ts +1 -0
  58. package/dist/vue/transforms/index.js +1 -0
  59. package/dist/vue/transforms/transformTeleport.d.ts +2 -0
  60. package/dist/vue/transforms/transformTeleport.js +68 -0
  61. package/dist/vue/transforms/x/transformDirection.js +33 -4
  62. package/dist/workers.d.ts +1 -0
  63. package/dist/workers.js +12 -5
  64. package/dist/x.d.ts +10 -0
  65. package/dist/x.js +39 -0
  66. package/lib/dom2/app/@vitejs/plugin-vue/dist/index.cjs +0 -7
  67. package/lib/dom2/app/@vitejs/plugin-vue/dist/index.mjs +0 -7
  68. package/lib/dom2/app/@vue/compiler-core/dist/compiler-core.cjs.js +58 -63
  69. package/lib/dom2/app/@vue/compiler-core/dist/compiler-core.cjs.prod.js +58 -63
  70. package/lib/dom2/app/@vue/compiler-core/dist/compiler-core.d.ts +7 -1
  71. package/lib/dom2/app/@vue/compiler-core/dist/compiler-core.esm-bundler.js +22 -47
  72. package/lib/dom2/app/@vue/compiler-dom/dist/compiler-dom.cjs.js +12 -23
  73. package/lib/dom2/app/@vue/compiler-dom/dist/compiler-dom.cjs.prod.js +12 -22
  74. package/lib/dom2/app/@vue/compiler-dom/dist/compiler-dom.esm-browser.js +23 -74
  75. package/lib/dom2/app/@vue/compiler-dom/dist/compiler-dom.esm-browser.prod.js +5 -5
  76. package/lib/dom2/app/@vue/compiler-dom/dist/compiler-dom.esm-bundler.js +3 -20
  77. package/lib/dom2/app/@vue/compiler-dom/dist/compiler-dom.global.js +310 -363
  78. package/lib/dom2/app/@vue/compiler-dom/dist/compiler-dom.global.prod.js +5 -5
  79. package/lib/dom2/app/@vue/compiler-sfc/dist/compiler-sfc.cjs.js +810 -579
  80. package/lib/dom2/app/@vue/compiler-sfc/dist/compiler-sfc.d.ts +33 -11114
  81. package/lib/dom2/app/@vue/compiler-sfc/dist/compiler-sfc.esm-browser.js +1638 -1250
  82. package/lib/dom2/app/@vue/compiler-vapor/dist/compiler-vapor.cjs.js +1031 -599
  83. package/lib/dom2/app/@vue/compiler-vapor/dist/compiler-vapor.d.ts +470 -328
  84. package/lib/dom2/app/@vue/compiler-vapor/dist/compiler-vapor.esm-browser.js +1154 -709
  85. package/lib/dom2/app/@vue/compiler-vapor-dom2/dist/compiler-vapor-dom2.cjs.js +1 -1
  86. package/lib/dom2/app/@vue/shared/dist/shared.cjs.js +16 -25
  87. package/lib/dom2/app/@vue/shared/dist/shared.cjs.prod.js +16 -25
  88. package/lib/dom2/app/@vue/shared/dist/shared.d.ts +5 -0
  89. package/lib/dom2/app/@vue/shared/dist/shared.esm-bundler.js +11 -23
  90. package/package.json +6 -6
@@ -12,6 +12,7 @@ const uts_1 = require("../../../uts");
12
12
  const utils_1 = require("../../utils");
13
13
  const uni_modules_1 = require("../../../uni_modules");
14
14
  const uni_modules_cloud_1 = require("../../../uni_modules.cloud");
15
+ const x_1 = require("../../../x");
15
16
  const utils_2 = require("../../../utils");
16
17
  const json_1 = require("../../../json");
17
18
  const fs_1 = require("../../../fs");
@@ -19,6 +20,7 @@ const context_1 = require("../../../preprocess/context");
19
20
  const hbx_1 = require("../../../hbx");
20
21
  const console_1 = require("../../../logs/console");
21
22
  const workers_1 = require("../../../workers");
23
+ const dom2_1 = require("../../../dom2");
22
24
  /* eslint-disable no-restricted-globals */
23
25
  const { preprocess } = require('../../../../lib/preprocess');
24
26
  function rewriteUniModulesConsoleExpr(fileName, content) {
@@ -160,7 +162,7 @@ function getCurrentCompiledUTSProviders() {
160
162
  return utsProviders;
161
163
  }
162
164
  exports.getCurrentCompiledUTSProviders = getCurrentCompiledUTSProviders;
163
- let uniExtApiCompiler = async () => { };
165
+ let uniExtApiCompiler = async (providerOnly = false) => { };
164
166
  let nonTreeShakingUniModulesCompiler = async () => { };
165
167
  function emptyCacheDir(platform) {
166
168
  const uvueOutputDir = (0, uts_1.uvueOutDir)(platform);
@@ -242,7 +244,10 @@ function uniUTSAppUniModulesPlugin(options = {}) {
242
244
  const uniXKotlinCompiler = process.env.UNI_APP_X_TSC === 'true' &&
243
245
  (process.env.UNI_UTS_PLATFORM === 'app-android' ||
244
246
  process.env.UNI_UTS_PLATFORM === 'app')
245
- ? createUniXKotlinCompilerOnce({ resolveWorkers })
247
+ ? createUniXKotlinCompilerOnce({
248
+ resolveWorkers,
249
+ sourceFileCallback: (0, dom2_1.initSourceFileCallback)(),
250
+ })
246
251
  : null;
247
252
  const uniXSwiftCompiler = process.env.UNI_APP_X_TSC === 'true' &&
248
253
  (process.env.UNI_UTS_PLATFORM === 'app-ios' ||
@@ -418,16 +423,20 @@ function uniUTSAppUniModulesPlugin(options = {}) {
418
423
  return filterAutoImports(autoImports, (0, uts_1.parseSwiftModuleWithPluginId)(pluginId, true));
419
424
  });
420
425
  },
426
+ iosPreprocessor: createAppIosUniModulesSyncFilePreprocessorOnce(!!options.x),
427
+ androidPreprocessor: createAppAndroidUniModulesSyncFilePreprocessorOnce(!!options.x),
428
+ // harmonyPreprocessor: createAppHarmonyUniModulesSyncFilePreprocessorOnce(!!options.x),
421
429
  });
422
430
  };
423
- uniExtApiCompiler = async () => {
431
+ uniExtApiCompiler = async (providerOnly = false) => {
424
432
  // 此方法为兜底方法,确保uni_modules中的所有插件都会编译,目前仅用于编译provider
425
433
  // 获取 provider 扩展(编译所有uni)
426
434
  const plugins = (0, uni_modules_1.getUniExtApiPlugins)().filter((provider) => !utsPlugins.has(provider.plugin));
435
+ const providers = (0, uni_modules_1.getUniExtApiProviders)();
427
436
  for (const plugin of plugins) {
428
437
  const pluginDir = path_1.default.resolve(inputDir, 'uni_modules', plugin.plugin);
429
438
  // 如果是 app-js 环境
430
- if (process.env.UNI_APP_X_UVUE_SCRIPT_ENGINE === 'js') {
439
+ if ((0, x_1.isUniAppXJsEngine)()) {
431
440
  if (fs_extra_1.default.existsSync(path_1.default.resolve(pluginDir, 'utssdk', 'app-js', 'index.uts'))) {
432
441
  continue;
433
442
  }
@@ -440,14 +449,18 @@ function uniUTSAppUniModulesPlugin(options = {}) {
440
449
  continue;
441
450
  }
442
451
  }
452
+ const isProvider = providers.some((p) => p.plugin === plugin.plugin);
443
453
  utsProviders.add(plugin.plugin);
444
- const result = await compilePlugin(pluginDir);
445
- if (result) {
446
- // 时机不对,不能addWatch
447
- // result.deps.forEach((dep) => {
448
- // this.addWatchFile(dep)
449
- // })
454
+ if ((providerOnly && isProvider) || !providerOnly) {
455
+ await compilePlugin(pluginDir);
450
456
  }
457
+ // const result = await compilePlugin(pluginDir)
458
+ // if (result) {
459
+ // // 时机不对,不能addWatch
460
+ // // result.deps.forEach((dep) => {
461
+ // // this.addWatchFile(dep)
462
+ // // })
463
+ // }
451
464
  }
452
465
  };
453
466
  nonTreeShakingUniModulesCompiler = async () => {
@@ -570,8 +583,8 @@ function uniUTSAppUniModulesPlugin(options = {}) {
570
583
  };
571
584
  }
572
585
  exports.uniUTSAppUniModulesPlugin = uniUTSAppUniModulesPlugin;
573
- async function buildUniExtApis() {
574
- await uniExtApiCompiler();
586
+ async function buildUniExtApis(providerOnly = false) {
587
+ await uniExtApiCompiler(providerOnly);
575
588
  }
576
589
  exports.buildUniExtApis = buildUniExtApis;
577
590
  async function buildNonTreeShakingUniModules() {
@@ -610,8 +623,13 @@ function uniDecryptUniModulesPlugin() {
610
623
  appname: manifest.name,
611
624
  platform: process.env.UNI_UTS_PLATFORM,
612
625
  'uni-app-x': isX,
626
+ vapor: process.env.UNI_APP_X_DOM2 === 'true',
613
627
  env,
614
628
  };
629
+ if (options.vapor) {
630
+ options.vaporRenderTarget =
631
+ process.env.UNI_APP_X_VAPOR_RENDER_TARGET || 'bytecode';
632
+ }
615
633
  // 鸿蒙平台需要拆分两次云编译
616
634
  if (process.env.UNI_UTS_PLATFORM === 'app-harmony') {
617
635
  const harmonyEnv = {
@@ -47,9 +47,9 @@ export declare function cssPostPlugin(config: ResolvedConfig, { platform, isJsCo
47
47
  isJsCode?: boolean;
48
48
  preserveModules?: boolean;
49
49
  chunkCssFilename: (id: string) => string | void;
50
- chunkCssCode: (filename: string, cssCode: string) => Promise<string> | string;
50
+ chunkCssCode: (filename: string, cssCode: string) => Promise<string | Uint8Array> | string;
51
51
  includeComponentCss?: boolean;
52
- emitFile?: (filename: string, cssCode: string) => void;
52
+ emitFile?: (filename: string, cssCode: string | Uint8Array) => void;
53
53
  }): Plugin;
54
54
  export declare function formatPostcssSourceMap(rawMap: ExistingRawSourceMap, file: string): ExistingRawSourceMap;
55
55
  export type CssUrlReplacer = (url: string, importer?: string, source?: PostCSS.Source) => string | Promise<string>;
@@ -43,6 +43,7 @@ const preprocess_1 = require("../../../../preprocess");
43
43
  const uniapp_1 = require("../../../../postcss/plugins/uniapp");
44
44
  const cleanString_1 = require("../cleanString");
45
45
  const constants_1 = require("../../../../constants");
46
+ const fontFamily_1 = require("../../../../dom2/fontFamily");
46
47
  const utils_2 = require("../../../utils/utils");
47
48
  const compiler_core_1 = require("@vue/compiler-core");
48
49
  const utils_3 = require("../../../../utils");
@@ -223,7 +224,8 @@ function cssPostPlugin(config, { platform, isJsCode, preserveModules, chunkCssFi
223
224
  // styles initialization in buildStart causes a styling loss in watch
224
225
  const styles = new Map();
225
226
  let cssChunks;
226
- const isDom2Harmony = process.env.UNI_APP_X_DOM2 === 'true' && platform === 'app-harmony';
227
+ const isDom2 = process.env.UNI_APP_X_DOM2 === 'true';
228
+ const isDom2App = isDom2 && platform.startsWith('app');
227
229
  return {
228
230
  name: 'vite:css-post',
229
231
  buildStart() {
@@ -240,8 +242,8 @@ function cssPostPlugin(config, { platform, isJsCode, preserveModules, chunkCssFi
240
242
  return {
241
243
  code: modulesCode ||
242
244
  (isJsCode
243
- ? isDom2Harmony
244
- ? `export default ${constants_1.JS_STYLE_PLACEHOLDER_STR}`
245
+ ? isDom2App
246
+ ? `export default ${(0, fontFamily_1.createJsStylePlaceholder)(id)}`
245
247
  : 'export default {}'
246
248
  : ''),
247
249
  map: { mappings: '' },
@@ -251,7 +253,7 @@ function cssPostPlugin(config, { platform, isJsCode, preserveModules, chunkCssFi
251
253
  };
252
254
  },
253
255
  async renderChunk(_code, chunk, _opts) {
254
- if (isDom2Harmony) {
256
+ if (isDom2) {
255
257
  // 通过 generateBundle 实现
256
258
  return null;
257
259
  }
@@ -372,7 +374,10 @@ function cssPostPlugin(config, { platform, isJsCode, preserveModules, chunkCssFi
372
374
  inlined: false,
373
375
  minify: true,
374
376
  });
375
- if (source.trim()) {
377
+ if (typeof source === 'string') {
378
+ source = source.trim();
379
+ }
380
+ if (source) {
376
381
  emitFile
377
382
  ? emitFile(filename, source)
378
383
  : this.emitFile({
@@ -16,3 +16,4 @@ export declare const transformTapToClick: import("@vue/compiler-core").NodeTrans
16
16
  export declare const transformComponentLink: (node: import("@vue/compiler-core").RootNode | import("@vue/compiler-core").TemplateChildNode, context: import("@vue/compiler-core").TransformContext) => void;
17
17
  export * from './x/transformMPBuiltInTag';
18
18
  export * from './x/transformDirection';
19
+ export * from './transformTeleport';
@@ -56,3 +56,4 @@ exports.transformTapToClick = (0, transformEvent_1.createTransformEvent)({
56
56
  exports.transformComponentLink = (0, transformComponent_1.createTransformComponentLink)(constants_1.COMPONENT_BIND_LINK);
57
57
  __exportStar(require("./x/transformMPBuiltInTag"), exports);
58
58
  __exportStar(require("./x/transformDirection"), exports);
59
+ __exportStar(require("./transformTeleport"), exports);
@@ -0,0 +1,2 @@
1
+ import { type RootNode, type TemplateChildNode } from '@vue/compiler-core';
2
+ export declare const transformTeleport: (node: RootNode | TemplateChildNode) => void;
@@ -0,0 +1,68 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.transformTeleport = void 0;
4
+ const utils_1 = require("../utils");
5
+ const vite_1 = require("../../vite");
6
+ const compiler_core_1 = require("@vue/compiler-core");
7
+ const shared_1 = require("@vue/shared");
8
+ const transformTeleport = function (node) {
9
+ if (!(0, vite_1.isElementNode)(node)) {
10
+ return;
11
+ }
12
+ if (node.tag !== 'teleport') {
13
+ return;
14
+ }
15
+ node.tag = 'root-portal';
16
+ node.tagType = compiler_core_1.ElementTypes.ELEMENT;
17
+ const disabledProp = (0, compiler_core_1.findProp)(node, 'disabled', false, true);
18
+ if (disabledProp) {
19
+ // transform `disabled` prop to `enable` prop with inverse value
20
+ if ((0, vite_1.isAttributeNode)(disabledProp)) {
21
+ const disabledPropIndex = node.props.indexOf(disabledProp);
22
+ node.props.splice(disabledPropIndex, 1, (0, utils_1.createBindDirectiveNode)('enable', (0, compiler_core_1.createSimpleExpression)('false', false)));
23
+ }
24
+ else if ((0, vite_1.isDirectiveNode)(disabledProp)) {
25
+ disabledProp.arg = (0, compiler_core_1.createSimpleExpression)('enable', true);
26
+ disabledProp.exp = createEnableExpression(disabledProp.exp);
27
+ }
28
+ }
29
+ const toProp = (0, compiler_core_1.findProp)(node, 'to');
30
+ if (toProp) {
31
+ // delete `to` prop since it is not supported in mini program
32
+ node.props.splice(node.props.indexOf(toProp), 1);
33
+ }
34
+ const deferProp = (0, compiler_core_1.findProp)(node, 'defer', false, true);
35
+ if (deferProp) {
36
+ // delete `defer` prop since it is not supported in mini program
37
+ node.props.splice(node.props.indexOf(deferProp), 1);
38
+ }
39
+ };
40
+ exports.transformTeleport = transformTeleport;
41
+ function createEnableExpression(exp) {
42
+ const content = exp && stringifyExpression(exp);
43
+ return (0, compiler_core_1.createSimpleExpression)(content ? `!(${content})` : 'true', false);
44
+ }
45
+ function stringifyExpression(exp) {
46
+ if ((0, vite_1.isSimpleExpressionNode)(exp)) {
47
+ return exp.content;
48
+ }
49
+ if ((0, vite_1.isCompoundExpressionNode)(exp)) {
50
+ const children = [];
51
+ for (const child of exp.children) {
52
+ if ((0, shared_1.isString)(child)) {
53
+ children.push(child);
54
+ }
55
+ else if ((0, shared_1.isSymbol)(child)) {
56
+ return;
57
+ }
58
+ else {
59
+ const content = stringifyExpression(child);
60
+ if (content === undefined) {
61
+ return;
62
+ }
63
+ children.push(content);
64
+ }
65
+ }
66
+ return children.join('');
67
+ }
68
+ }
@@ -4,6 +4,7 @@ exports.transformDirection = void 0;
4
4
  const vite_1 = require("../../../vite");
5
5
  const utils_1 = require("../../utils");
6
6
  const compiler_core_1 = require("@vue/compiler-core");
7
+ const shared_1 = require("@vue/shared");
7
8
  /**
8
9
  * 将direction属性转化为scroll-x和scroll-y
9
10
  * 注意transformMPBuiltInTag内会讲list-view转化为scroll-view,所以此transform应该在transformMPBuiltInTag之后执行
@@ -27,7 +28,7 @@ const transformDirection = function (node, context) {
27
28
  return;
28
29
  }
29
30
  const directionProp = node.props[directionPropIndex];
30
- if (directionProp.type === compiler_core_1.NodeTypes.ATTRIBUTE) {
31
+ if ((0, vite_1.isAttributeNode)(directionProp)) {
31
32
  const directionValue = directionProp.value?.content;
32
33
  const scrollX = directionValue === 'horizontal' || directionValue === 'all';
33
34
  const scrollY = !directionValue ||
@@ -39,12 +40,16 @@ const transformDirection = function (node, context) {
39
40
  }
40
41
  else if (directionProp.type === compiler_core_1.NodeTypes.DIRECTIVE) {
41
42
  if (!directionProp.arg ||
42
- directionProp.arg.type !== compiler_core_1.NodeTypes.SIMPLE_EXPRESSION ||
43
+ !(0, vite_1.isSimpleExpressionNode)(directionProp.arg) ||
43
44
  !directionProp.exp ||
44
- directionProp.exp.type !== compiler_core_1.NodeTypes.SIMPLE_EXPRESSION) {
45
+ !((0, vite_1.isSimpleExpressionNode)(directionProp.exp) ||
46
+ (0, vite_1.isCompoundExpressionNode)(directionProp.exp))) {
47
+ return;
48
+ }
49
+ const exp = stringifyExpression(directionProp.exp);
50
+ if (!exp) {
45
51
  return;
46
52
  }
47
- const exp = directionProp.exp.content;
48
53
  const scrollX = `(${exp}) === 'horizontal' || (${exp}) === 'all'`;
49
54
  const scrollY = `!(${exp}) || (${exp}) === 'vertical' || (${exp}) === 'all'`;
50
55
  node.props.splice(directionPropIndex, 1);
@@ -53,3 +58,27 @@ const transformDirection = function (node, context) {
53
58
  }
54
59
  };
55
60
  exports.transformDirection = transformDirection;
61
+ function stringifyExpression(exp) {
62
+ if ((0, vite_1.isSimpleExpressionNode)(exp)) {
63
+ return exp.content;
64
+ }
65
+ if ((0, vite_1.isCompoundExpressionNode)(exp)) {
66
+ const children = [];
67
+ for (const child of exp.children) {
68
+ if ((0, shared_1.isString)(child)) {
69
+ children.push(child);
70
+ }
71
+ else if ((0, shared_1.isSymbol)(child)) {
72
+ return;
73
+ }
74
+ else {
75
+ const content = stringifyExpression(child);
76
+ if (content === undefined) {
77
+ return;
78
+ }
79
+ children.push(content);
80
+ }
81
+ }
82
+ return children.join('');
83
+ }
84
+ }
package/dist/workers.d.ts CHANGED
@@ -11,5 +11,6 @@ export declare function getWorkersRootDirs(): string[];
11
11
  export declare function initWorkers(workersDirs: string[], rootDir: string): Record<string, string>;
12
12
  export declare function uniWorkersPlugin(): Plugin;
13
13
  export declare function resolveWorkersDir(inputDir: string): Array<string>;
14
+ export declare function normalizeJavaScriptWorkerSource(content: string): string;
14
15
  export declare function uniJavaScriptWorkersPlugin(): Plugin;
15
16
  export declare function initUniXCompilerRootWorkers(rootDir: string, compiler: UniXCompiler): Promise<void>;
package/dist/workers.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.initUniXCompilerRootWorkers = exports.uniJavaScriptWorkersPlugin = exports.resolveWorkersDir = exports.uniWorkersPlugin = exports.initWorkers = exports.getWorkersRootDirs = exports.resolveWorkersRootDir = exports.getWorkers = void 0;
6
+ exports.initUniXCompilerRootWorkers = exports.uniJavaScriptWorkersPlugin = exports.normalizeJavaScriptWorkerSource = exports.resolveWorkersDir = exports.uniWorkersPlugin = exports.initWorkers = exports.getWorkersRootDirs = exports.resolveWorkersRootDir = exports.getWorkers = void 0;
7
7
  const path_1 = __importDefault(require("path"));
8
8
  const fs_extra_1 = __importDefault(require("fs-extra"));
9
9
  const debug_1 = __importDefault(require("debug"));
@@ -13,6 +13,7 @@ const json_1 = require("./json");
13
13
  const uts_1 = require("./uts");
14
14
  const uni_modules_1 = require("./vite/plugins/uts/uni_modules");
15
15
  const resolve_1 = require("./resolve");
16
+ const dom2_1 = require("./dom2");
16
17
  const debugWorkers = (0, debug_1.default)('uni:workers');
17
18
  let workersRootDir = null;
18
19
  let workersRootDirs = [];
@@ -76,6 +77,7 @@ function uniWorkersPlugin() {
76
77
  const uniXKotlinCompiler = platform === 'app-android'
77
78
  ? (0, uts_1.resolveUTSCompiler)().createUniXKotlinCompilerOnce({
78
79
  resolveWorkers,
80
+ sourceFileCallback: (0, dom2_1.initSourceFileCallback)(),
79
81
  })
80
82
  : null;
81
83
  const uniXSwiftCompiler = platform === 'app-ios'
@@ -154,6 +156,14 @@ function resolveWorkersDir(inputDir) {
154
156
  return workersDirs;
155
157
  }
156
158
  exports.resolveWorkersDir = resolveWorkersDir;
159
+ function normalizeJavaScriptWorkerSource(content) {
160
+ const code = content
161
+ // 移除 export,worker 入口按普通脚本加载,不需要导出任务类。
162
+ .replace(/export\s+class\s+(.*)\s+extends\s+WorkerTaskImpl\s*{/, 'class $1 extends WorkerTaskImpl {');
163
+ // 保持模块语义,避免 uts2js 同时登记 .uts/.ts 快照时把任务类放到全局作用域导致重复声明。
164
+ return /(^|\n)\s*(import|export)\s/m.test(code) ? code : `${code}\nexport {}`;
165
+ }
166
+ exports.normalizeJavaScriptWorkerSource = normalizeJavaScriptWorkerSource;
157
167
  function uniJavaScriptWorkersPlugin() {
158
168
  // 仅小程序平台外置uni-worker.mp.js
159
169
  const external = (process.env.UNI_UTS_PLATFORM || '').startsWith('mp-');
@@ -220,10 +230,7 @@ function uniJavaScriptWorkersPlugin() {
220
230
  }
221
231
  if (fs_extra_1.default.existsSync(filename)) {
222
232
  let code = (viteServer ? `import '${workerPolyfillPath}';` : '') +
223
- fs_extra_1.default
224
- .readFileSync(filename, 'utf-8')
225
- // 移除 export
226
- .replace(/export\s+class\s+(.*)\s+extends\s+WorkerTaskImpl\s*{/, 'class $1 extends WorkerTaskImpl {');
233
+ normalizeJavaScriptWorkerSource(fs_extra_1.default.readFileSync(filename, 'utf-8'));
227
234
  // 如果是入口文件,需要追加初始化代码
228
235
  if (workerClass) {
229
236
  code += `\n;new ${workerClass}().entry()`;
package/dist/x.d.ts ADDED
@@ -0,0 +1,10 @@
1
+ type AppXPlatform = typeof process.env.UNI_UTS_PLATFORM;
2
+ export declare function isUniAppX(): boolean;
3
+ export declare function isUniAppXAndroid(platform?: AppXPlatform): boolean;
4
+ export declare function isUniAppXIOS(platform?: AppXPlatform): boolean;
5
+ export declare function isUniAppXVapor(): boolean;
6
+ export declare function isUniAppXAndroidVapor(platform?: AppXPlatform): boolean;
7
+ export declare function isUniAppXJsEngine(): boolean;
8
+ export declare function isUniAppXAndroidJsEngine(platform?: AppXPlatform): boolean;
9
+ export declare function isUniAppXAndroidNative(platform?: AppXPlatform): boolean;
10
+ export {};
package/dist/x.js ADDED
@@ -0,0 +1,39 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isUniAppXAndroidNative = exports.isUniAppXAndroidJsEngine = exports.isUniAppXJsEngine = exports.isUniAppXAndroidVapor = exports.isUniAppXVapor = exports.isUniAppXIOS = exports.isUniAppXAndroid = exports.isUniAppX = void 0;
4
+ function isUniAppX() {
5
+ return process.env.UNI_APP_X === 'true';
6
+ }
7
+ exports.isUniAppX = isUniAppX;
8
+ function isUniAppXAndroid(platform = process.env.UNI_UTS_PLATFORM) {
9
+ return isUniAppX() && platform === 'app-android';
10
+ }
11
+ exports.isUniAppXAndroid = isUniAppXAndroid;
12
+ function isUniAppXIOS(platform = process.env.UNI_UTS_PLATFORM) {
13
+ return isUniAppX() && platform === 'app-ios';
14
+ }
15
+ exports.isUniAppXIOS = isUniAppXIOS;
16
+ function isUniAppXVapor() {
17
+ return isUniAppX() && process.env.UNI_APP_X_DOM2 === 'true';
18
+ }
19
+ exports.isUniAppXVapor = isUniAppXVapor;
20
+ function isUniAppXAndroidVapor(platform = process.env.UNI_UTS_PLATFORM) {
21
+ return isUniAppXAndroid(platform) && process.env.UNI_APP_X_DOM2 === 'true';
22
+ }
23
+ exports.isUniAppXAndroidVapor = isUniAppXAndroidVapor;
24
+ function isUniAppXJsEngine() {
25
+ return isUniAppX() && process.env.UNI_APP_X_UVUE_SCRIPT_ENGINE === 'js';
26
+ }
27
+ exports.isUniAppXJsEngine = isUniAppXJsEngine;
28
+ function isUniAppXAndroidJsEngine(platform = process.env.UNI_UTS_PLATFORM) {
29
+ return (isUniAppXAndroid(platform) &&
30
+ process.env.UNI_APP_X_UVUE_SCRIPT_ENGINE === 'js');
31
+ }
32
+ exports.isUniAppXAndroidJsEngine = isUniAppXAndroidJsEngine;
33
+ function isUniAppXAndroidNative(platform = process.env.UNI_UTS_PLATFORM) {
34
+ return (isUniAppXAndroid(platform) &&
35
+ // 非 Vapor 或者 Vapor 但使用 native 引擎
36
+ (process.env.UNI_APP_X_DOM2 !== 'true' ||
37
+ process.env.UNI_APP_X_UVUE_SCRIPT_ENGINE === 'native'));
38
+ }
39
+ exports.isUniAppXAndroidNative = isUniAppXAndroidNative;
@@ -320,13 +320,6 @@ function resolveTemplateCompilerOptions(descriptor, options, ssr) {
320
320
  expressionPlugins.push("typescript");
321
321
  }
322
322
  const extraOptions = options.template?.compilerOptions?.extraOptions?.(descriptor);
323
- if (extraOptions.helper) {
324
- extraOptions.className = extraOptions.helper.GCN(
325
- descriptor.filename,
326
- process.env.UNI_INPUT_DIR
327
- );
328
- extraOptions.r = extraOptions.helper.K;
329
- }
330
323
  return {
331
324
  ...options.template,
332
325
  // @ts-expect-error TODO remove when 3.6 is out
@@ -307,13 +307,6 @@ function resolveTemplateCompilerOptions(descriptor, options, ssr) {
307
307
  expressionPlugins.push("typescript");
308
308
  }
309
309
  const extraOptions = options.template?.compilerOptions?.extraOptions?.(descriptor);
310
- if (extraOptions.helper) {
311
- extraOptions.className = extraOptions.helper.GCN(
312
- descriptor.filename,
313
- process.env.UNI_INPUT_DIR
314
- );
315
- extraOptions.r = extraOptions.helper.K;
316
- }
317
310
  return {
318
311
  ...options.template,
319
312
  // @ts-expect-error TODO remove when 3.6 is out