@dcloudio/uni-cli-shared 3.0.0-4050720250324001 → 3.0.0-4060420250429001

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 (52) hide show
  1. package/dist/easycom.d.ts +1 -1
  2. package/dist/easycom.js +32 -10
  3. package/dist/i18n.js +1 -1
  4. package/dist/index.d.ts +2 -0
  5. package/dist/json/json.d.ts +1 -1
  6. package/dist/json/json.js +3 -3
  7. package/dist/json/manifest.js +1 -1
  8. package/dist/json/mp/jsonFile.js +3 -0
  9. package/dist/json/mp/pages.js +1 -1
  10. package/dist/json/mp/project.js +1 -1
  11. package/dist/json/mp/types.d.ts +1 -1
  12. package/dist/json/pages.js +2 -2
  13. package/dist/json/theme.js +2 -2
  14. package/dist/json/uni-x/index.js +2 -2
  15. package/dist/logs/console.d.ts +2 -0
  16. package/dist/logs/console.js +35 -1
  17. package/dist/mp/plugin.js +2 -2
  18. package/dist/mp/usingComponents.d.ts +1 -3
  19. package/dist/mp/usingComponents.js +2 -6
  20. package/dist/platform.d.ts +1 -1
  21. package/dist/platform.js +3 -0
  22. package/dist/preprocess/index.d.ts +6 -6
  23. package/dist/preprocess/index.js +88 -15
  24. package/dist/resolve.js +1 -1
  25. package/dist/uni_modules.cloud.d.ts +5 -2
  26. package/dist/uni_modules.cloud.js +4 -2
  27. package/dist/uni_modules.d.ts +2 -0
  28. package/dist/uts.d.ts +25 -0
  29. package/dist/uts.js +183 -4
  30. package/dist/vite/autoImport.js +28 -0
  31. package/dist/vite/cloud.js +2 -0
  32. package/dist/vite/extApi.js +1 -1
  33. package/dist/vite/index.d.ts +1 -0
  34. package/dist/vite/plugins/copy.d.ts +3 -1
  35. package/dist/vite/plugins/cssScoped.js +3 -7
  36. package/dist/vite/plugins/easycom.js +24 -3
  37. package/dist/vite/plugins/inject.js +1 -3
  38. package/dist/vite/plugins/json.js +1 -1
  39. package/dist/vite/plugins/pre.js +2 -2
  40. package/dist/vite/plugins/sfc.js +1 -1
  41. package/dist/vite/plugins/uts/uni_modules.js +39 -11
  42. package/dist/vite/plugins/vitejs/plugins/css.d.ts +1 -1
  43. package/dist/vite/plugins/vitejs/plugins/css.js +6 -11
  44. package/dist/vite/plugins/vitejs/plugins/static.js +1 -1
  45. package/dist/vue/transforms/transformUTSComponent.d.ts +1 -0
  46. package/dist/vue/transforms/transformUTSComponent.js +10 -2
  47. package/lib/es-module-lexer/LICENSE +10 -0
  48. package/lib/es-module-lexer/lib/lexer.cjs +1 -0
  49. package/lib/es-module-lexer/lib/lexer.js +2 -0
  50. package/lib/es-module-lexer/package.json +57 -0
  51. package/lib/es-module-lexer/types/lexer.d.ts +184 -0
  52. package/package.json +6 -6
package/dist/easycom.d.ts CHANGED
@@ -19,7 +19,7 @@ export declare function initEasycoms(inputDir: string, { dirs, platform, isX, }:
19
19
  platform: UniApp.PLATFORM;
20
20
  isX?: boolean;
21
21
  }): {
22
- options: EasycomOption;
22
+ easyComOptions: EasycomOption;
23
23
  filter: (id: unknown) => boolean;
24
24
  refresh(): void;
25
25
  easycoms: EasycomMatcher[];
package/dist/easycom.js CHANGED
@@ -48,7 +48,7 @@ function initEasycoms(inputDir, { dirs, platform, isX, }) {
48
48
  debugEasycom(easycomOptions);
49
49
  return easycomOptions;
50
50
  };
51
- const options = initEasycomOptions((0, pages_1.parsePagesJsonOnce)(inputDir, platform));
51
+ const easyComOptions = initEasycomOptions((0, pages_1.parsePagesJsonOnce)(inputDir, platform));
52
52
  const initUTSEasycom = () => {
53
53
  (0, uts_1.initUTSComponents)(inputDir, platform).forEach((item) => {
54
54
  const index = easycoms.findIndex((easycom) => item.name === easycom.name);
@@ -64,26 +64,46 @@ function initEasycoms(inputDir, { dirs, platform, isX, }) {
64
64
  globalThis.uts2jsSourceCodeMap.initUts2jsEasycom(easycoms);
65
65
  }
66
66
  };
67
+ const initUTSEasycomCustomElements = () => {
68
+ (0, uts_1.initUTSCustomElements)(inputDir, platform).forEach((item) => {
69
+ const index = easycoms.findIndex((easycom) => item.name === easycom.name);
70
+ if (index > -1) {
71
+ easycoms.splice(index, 1, item);
72
+ }
73
+ else {
74
+ easycoms.push(item);
75
+ }
76
+ });
77
+ };
67
78
  // ext-api 模式下,不存在 easycom 特性
68
79
  if (process.env.UNI_COMPILE_TARGET !== 'ext-api') {
69
- initEasycom(options);
80
+ clearEasycom();
81
+ (0, uts_1.clearUTSComponents)();
82
+ (0, uts_1.clearUTSCustomElements)();
83
+ initEasycom(easyComOptions);
84
+ initUTSEasycomCustomElements();
70
85
  initUTSEasycom();
71
86
  }
72
87
  const componentExtNames = isX ? 'uvue|vue' : 'vue';
73
88
  const res = {
74
- options,
89
+ easyComOptions,
75
90
  filter: (0, pluginutils_1.createFilter)([
76
91
  'components/*/*.(' + componentExtNames + '|jsx|tsx)',
77
92
  'uni_modules/*/components/*/*.(' + componentExtNames + '|jsx|tsx)',
78
93
  'utssdk/*/**/*.(' + componentExtNames + ')',
79
94
  'uni_modules/*/utssdk/*/*.(' + componentExtNames + ')',
95
+ 'uni_modules/*/customElements/*/*.uts',
80
96
  ], [], {
81
97
  resolve: inputDir,
82
98
  }),
83
99
  refresh() {
84
- res.options = initEasycomOptions();
100
+ res.easyComOptions = initEasycomOptions();
85
101
  if (process.env.UNI_COMPILE_TARGET !== 'ext-api') {
86
- initEasycom(res.options);
102
+ clearEasycom();
103
+ (0, uts_1.clearUTSComponents)();
104
+ (0, uts_1.clearUTSCustomElements)();
105
+ initEasycom(easyComOptions);
106
+ initUTSEasycomCustomElements();
87
107
  initUTSEasycom();
88
108
  }
89
109
  },
@@ -93,14 +113,14 @@ function initEasycoms(inputDir, { dirs, platform, isX, }) {
93
113
  }
94
114
  exports.initEasycoms = initEasycoms;
95
115
  exports.initEasycomsOnce = (0, uni_shared_1.once)(initEasycoms);
96
- function initUniModulesEasycomDirs(uniModulesDir) {
116
+ function initUniModulesEasycomDirs(uniModulesDir, componentsDir = 'components') {
97
117
  if (!fs_1.default.existsSync(uniModulesDir)) {
98
118
  return [];
99
119
  }
100
120
  return fs_1.default
101
121
  .readdirSync(uniModulesDir)
102
122
  .map((uniModuleDir) => {
103
- const uniModuleComponentsDir = path_1.default.resolve(uniModulesDir, uniModuleDir, 'components');
123
+ const uniModuleComponentsDir = path_1.default.resolve(uniModulesDir, uniModuleDir, componentsDir);
104
124
  if (fs_1.default.existsSync(uniModuleComponentsDir)) {
105
125
  return uniModuleComponentsDir;
106
126
  }
@@ -108,7 +128,6 @@ function initUniModulesEasycomDirs(uniModulesDir) {
108
128
  .filter(Boolean);
109
129
  }
110
130
  function initEasycom({ isX, dirs, rootDir, custom, extensions, }) {
111
- clearEasycom();
112
131
  rootDir = (0, utils_1.normalizePath)(rootDir);
113
132
  const easycomsObj = Object.create(null);
114
133
  if (dirs && dirs.length && rootDir) {
@@ -258,10 +277,13 @@ function addImportDeclaration(importDeclarations, local, source, imported) {
258
277
  }
259
278
  exports.addImportDeclaration = addImportDeclaration;
260
279
  function createImportDeclaration(local, source, imported) {
261
- if (imported) {
280
+ if (imported && local) {
262
281
  return `import { ${imported} as ${local} } from '${source}';`;
263
282
  }
264
- return `import ${local} from '${source}';`;
283
+ if (local) {
284
+ return `import ${local} from '${source}';`;
285
+ }
286
+ return `import '${source}';`;
265
287
  }
266
288
  const RESOLVE_EASYCOM_IMPORT_CODE = `import { resolveDynamicComponent as __resolveDynamicComponent } from 'vue';import { resolveEasycom } from '@dcloudio/uni-app';`;
267
289
  function genResolveEasycomCode(importDeclarations, code, name) {
package/dist/i18n.js CHANGED
@@ -44,7 +44,7 @@ function isUniAppLocaleFile(filepath) {
44
44
  }
45
45
  exports.isUniAppLocaleFile = isUniAppLocaleFile;
46
46
  function parseLocaleJson(filepath) {
47
- let jsonObj = (0, json_1.parseJson)(fs_1.default.readFileSync(filepath, 'utf8'));
47
+ let jsonObj = (0, json_1.parseJson)(fs_1.default.readFileSync(filepath, 'utf8'), false, filepath);
48
48
  if (isUniAppLocaleFile(filepath)) {
49
49
  jsonObj = jsonObj.common || {};
50
50
  }
package/dist/index.d.ts CHANGED
@@ -24,6 +24,8 @@ export * from './platform';
24
24
  export * from './utsUtils';
25
25
  export { parseUniExtApi, parseUniExtApis, parseInjects, Define, DefineOptions, Defines, getUniExtApiProviderRegisters, formatExtApiProviderName, } from './uni_modules';
26
26
  export { parseUniModulesArtifacts, resolveEncryptUniModule, } from './uni_modules.cloud';
27
+ import type { EncryptPackageJson } from './uni_modules.cloud';
28
+ export type EncryptArtifacts = EncryptPackageJson['uni_modules']['artifacts'];
27
29
  export { M } from './messages';
28
30
  export * from './exports';
29
31
  export { checkUpdate } from './checkUpdate';
@@ -1 +1 @@
1
- export declare function parseJson(jsonStr: string, shouldPre?: boolean): any;
1
+ export declare function parseJson(jsonStr: string, shouldPre: boolean | undefined, filename: string): any;
package/dist/json/json.js CHANGED
@@ -3,11 +3,11 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.parseJson = void 0;
4
4
  const jsonc_parser_1 = require("jsonc-parser");
5
5
  const preprocess_1 = require("../preprocess");
6
- function parseJson(jsonStr, shouldPre = false) {
6
+ function parseJson(jsonStr, shouldPre = false, filename) {
7
7
  return (0, jsonc_parser_1.parse)(shouldPre
8
8
  ? process.env.UNI_APP_X === 'true'
9
- ? (0, preprocess_1.preUVueJson)(jsonStr)
10
- : (0, preprocess_1.preJson)(jsonStr)
9
+ ? (0, preprocess_1.preUVueJson)(jsonStr, filename)
10
+ : (0, preprocess_1.preJson)(jsonStr, filename)
11
11
  : jsonStr);
12
12
  }
13
13
  exports.parseJson = parseJson;
@@ -17,7 +17,7 @@ const parseManifestJson = (inputDir) => {
17
17
  return {};
18
18
  }
19
19
  }
20
- return (0, json_1.parseJson)(fs_1.default.readFileSync(path_1.default.join(inputDir, 'manifest.json'), 'utf8'));
20
+ return (0, json_1.parseJson)(fs_1.default.readFileSync(manifestFilename, 'utf8'), false, manifestFilename);
21
21
  };
22
22
  exports.parseManifestJson = parseManifestJson;
23
23
  exports.parseManifestJsonOnce = (0, uni_shared_1.once)(exports.parseManifestJson);
@@ -162,6 +162,9 @@ function findMiniProgramUsingComponent(usingComponents, componentsDir) {
162
162
  else if (componentsDir && path.includes(componentsDir + '/')) {
163
163
  res[name] = 'component';
164
164
  }
165
+ else if (path.startsWith('weui-miniprogram')) {
166
+ res[name] = 'weui';
167
+ }
165
168
  return res;
166
169
  }, {});
167
170
  }
@@ -57,7 +57,7 @@ function parsePagesJson(jsonStr, platform, { debug, darkmode, networkTimeout, su
57
57
  let pageJsons = {};
58
58
  let nvuePages = [];
59
59
  // preprocess
60
- const pagesJson = (0, json_1.parseJson)(jsonStr, true);
60
+ const pagesJson = (0, json_1.parseJson)(jsonStr, true, 'pages.json');
61
61
  if (!pagesJson) {
62
62
  throw new Error(`[vite] Error: pages.json parse failed.\n`);
63
63
  }
@@ -25,7 +25,7 @@ function isMiniProgramProjectJsonKey(name) {
25
25
  exports.isMiniProgramProjectJsonKey = isMiniProgramProjectJsonKey;
26
26
  function parseMiniProgramProjectJson(jsonStr, platform, { template, pagesJson }) {
27
27
  const projectJson = JSON.parse(JSON.stringify(template));
28
- const manifestJson = (0, json_1.parseJson)(jsonStr);
28
+ const manifestJson = (0, json_1.parseJson)(jsonStr, false, '');
29
29
  if (manifestJson) {
30
30
  projectJson.projectname = manifestJson.name;
31
31
  // 用户的平台配置
@@ -119,5 +119,5 @@ export interface AppJson {
119
119
  restartStrategy?: RestartStrategy;
120
120
  [name: string]: unknown;
121
121
  }
122
- export type MiniProgramComponentsType = 'plugin' | 'component' | 'dynamicLib' | 'ext' | 'xr-frame';
122
+ export type MiniProgramComponentsType = 'plugin' | 'component' | 'dynamicLib' | 'ext' | 'xr-frame' | 'weui';
123
123
  export {};
@@ -64,7 +64,7 @@ const parsePagesJson = (inputDir, platform, normalize = true) => {
64
64
  if (normalize) {
65
65
  return normalizePagesJson(jsonStr, platform);
66
66
  }
67
- return (0, json_1.parseJson)(jsonStr, true);
67
+ return (0, json_1.parseJson)(jsonStr, true, pagesFilename);
68
68
  };
69
69
  exports.parsePagesJson = parsePagesJson;
70
70
  /**
@@ -87,7 +87,7 @@ function normalizePagesJson(jsonStr, platform, { subpackages, } = { subpackages:
87
87
  };
88
88
  // preprocess
89
89
  try {
90
- pagesJson = (0, json_1.parseJson)(jsonStr, true);
90
+ pagesJson = (0, json_1.parseJson)(jsonStr, true, 'pages.json');
91
91
  }
92
92
  catch (e) {
93
93
  console.error(`[vite] Error: pages.json parse failed.\n`, jsonStr, e);
@@ -25,7 +25,7 @@ const parseThemeJson = (themeLocation = 'theme.json') => {
25
25
  return {};
26
26
  }
27
27
  const jsonStr = fs_1.default.readFileSync(themeLocation, 'utf8');
28
- return (0, json_1.parseJson)(jsonStr, true);
28
+ return (0, json_1.parseJson)(jsonStr, true, themeLocation);
29
29
  };
30
30
  exports.parseThemeJson = parseThemeJson;
31
31
  const SCHEME_RE = /^([a-z-]+:)?\/\//i;
@@ -74,7 +74,7 @@ const getPagesJson = (inputDir) => {
74
74
  };
75
75
  }
76
76
  const jsonStr = fs_1.default.readFileSync(pagesFilename, 'utf8');
77
- return (0, json_1.parseJson)(jsonStr, true);
77
+ return (0, json_1.parseJson)(jsonStr, true, pagesFilename);
78
78
  };
79
79
  exports.normalizeThemeConfigOnce = (0, uni_shared_1.once)((manifestJsonPlatform = {}) => {
80
80
  const themeConfig = (0, exports.parseThemeJson)(manifestJsonPlatform.themeLocation);
@@ -147,7 +147,7 @@ function walkNode(node, pagePathNodes) {
147
147
  }
148
148
  function normalizeUniAppXAppPagesJson(jsonStr) {
149
149
  // 先条件编译
150
- jsonStr = (0, preprocess_1.preUVueJson)(jsonStr);
150
+ jsonStr = (0, preprocess_1.preUVueJson)(jsonStr, 'pages.json');
151
151
  checkPagesJson(jsonStr, process.env.UNI_INPUT_DIR);
152
152
  const pagesJson = {
153
153
  pages: [],
@@ -159,7 +159,7 @@ function normalizeUniAppXAppPagesJson(jsonStr) {
159
159
  };
160
160
  try {
161
161
  // 此处不需要条件编译了
162
- userPagesJson = (0, json_1.parseJson)(jsonStr, false);
162
+ userPagesJson = (0, json_1.parseJson)(jsonStr, false, 'pages.json');
163
163
  }
164
164
  catch (e) {
165
165
  console.error(`[vite] Error: pages.json parse failed.\n`, jsonStr, e);
@@ -1,3 +1,5 @@
1
1
  import type { TransformResult } from 'vite';
2
+ import type * as tsTypes from 'typescript';
2
3
  export declare function rewriteConsoleExpr(method: string, id: string, filename: string, code: string, sourceMap?: boolean): TransformResult;
3
4
  export declare function restoreConsoleExpr(code: string): string;
5
+ export declare function appendConsoleExpr(filename: string, code: string, ts: typeof tsTypes): string;
@@ -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.restoreConsoleExpr = exports.rewriteConsoleExpr = void 0;
6
+ exports.appendConsoleExpr = exports.restoreConsoleExpr = exports.rewriteConsoleExpr = void 0;
7
7
  const magic_string_1 = __importDefault(require("magic-string"));
8
8
  const utils_1 = require("../utils");
9
9
  function rewriteConsoleExpr(method, id, filename, code, sourceMap = false) {
@@ -53,3 +53,37 @@ function getLocator(source) {
53
53
  return { line, column };
54
54
  };
55
55
  }
56
+ const methods = ['log', 'info', 'debug', 'warn', 'error'];
57
+ function appendConsoleExpr(filename, code, ts) {
58
+ if (!ts) {
59
+ return code;
60
+ }
61
+ const s = new magic_string_1.default(code);
62
+ const sourceFile = ts.createSourceFile(filename, code, ts.ScriptTarget.Latest);
63
+ // 遍历sourceFile,查找console的方法调用
64
+ const traverse = (node) => {
65
+ ts.forEachChild(node, (node) => traverse(node));
66
+ if (ts.isCallExpression(node) &&
67
+ node.arguments.length > 0 &&
68
+ ts.isPropertyAccessExpression(node.expression)) {
69
+ const propertyAccess = node.expression;
70
+ if (ts.isIdentifier(propertyAccess.expression) &&
71
+ propertyAccess.expression.text === 'console' &&
72
+ ts.isIdentifier(propertyAccess.name) &&
73
+ methods.includes(propertyAccess.name.text)) {
74
+ const lastArg = node.arguments[node.arguments.length - 1];
75
+ if (lastArg) {
76
+ const { line } = sourceFile.getLineAndCharacterOfPosition(propertyAccess.name.end);
77
+ // 重要,需要用双引号,因为混编的kt,swift,java不能用单引号(char类型)
78
+ s.prependRight(lastArg.getEnd(), `, " at ${filename}:${line + 1}"`);
79
+ }
80
+ }
81
+ }
82
+ };
83
+ traverse(sourceFile);
84
+ if (s.hasChanged()) {
85
+ return s.toString();
86
+ }
87
+ return code;
88
+ }
89
+ exports.appendConsoleExpr = appendConsoleExpr;
package/dist/mp/plugin.js CHANGED
@@ -14,7 +14,7 @@ exports.copyMiniProgramPluginJson = {
14
14
  return process.env.UNI_OUTPUT_DIR;
15
15
  },
16
16
  transform(source) {
17
- const pluginJson = (0, json_1.parseJson)(source.toString(), true);
17
+ const pluginJson = (0, json_1.parseJson)(source.toString(), true, 'plugin.json');
18
18
  if (process.env.UNI_APP_X === 'true') {
19
19
  const pluginMainJs = pluginJson.main;
20
20
  if (pluginMainJs && pluginMainJs.endsWith('.uts')) {
@@ -38,7 +38,7 @@ const copyMiniProgramThemeJson = () => {
38
38
  return process.env.UNI_OUTPUT_DIR;
39
39
  },
40
40
  transform(source) {
41
- return JSON.stringify((0, json_1.parseJson)(source.toString(), true), null, 2);
41
+ return JSON.stringify((0, json_1.parseJson)(source.toString(), true, themeLocation), null, 2);
42
42
  },
43
43
  },
44
44
  ];
@@ -62,8 +62,6 @@ export declare function transformDynamicImports(code: string, imports: ImportDec
62
62
  dynamicImport: (name: string, source: string) => string;
63
63
  }): Promise<{
64
64
  code: string;
65
- map: {
66
- mappings: '';
67
- };
65
+ map: null;
68
66
  }>;
69
67
  export {};
@@ -390,9 +390,7 @@ async function transformDynamicImports(code, imports, { id, sourceMap, dynamicIm
390
390
  if (!imports.length) {
391
391
  return {
392
392
  code,
393
- map: {
394
- mappings: '',
395
- },
393
+ map: null,
396
394
  };
397
395
  }
398
396
  const s = new magic_string_1.default(code);
@@ -402,9 +400,7 @@ async function transformDynamicImports(code, imports, { id, sourceMap, dynamicIm
402
400
  }
403
401
  return {
404
402
  code: s.toString(),
405
- map: {
406
- mappings: '',
407
- },
403
+ map: null,
408
404
  };
409
405
  }
410
406
  exports.transformDynamicImports = transformDynamicImports;
@@ -1,4 +1,4 @@
1
1
  export declare function registerPlatform(platform: string): void;
2
2
  export declare function getPlatforms(): string[];
3
- export declare function getPlatformDir(): "quickapp-webview-huawei" | "quickapp-webview-union";
3
+ export declare function getPlatformDir(): keyof UniApp.PagesJsonPagePlatformStyle | "app-ios" | "app-android";
4
4
  export declare function isMiniProgramPlatform(): boolean;
package/dist/platform.js CHANGED
@@ -38,6 +38,9 @@ function getPlatforms() {
38
38
  }
39
39
  exports.getPlatforms = getPlatforms;
40
40
  function getPlatformDir() {
41
+ if (process.env.UNI_APP_X && process.env.UNI_PLATFORM === 'app') {
42
+ return process.env.UNI_UTS_PLATFORM;
43
+ }
41
44
  return process.env.UNI_SUB_PLATFORM || process.env.UNI_PLATFORM;
42
45
  }
43
46
  exports.getPlatformDir = getPlatformDir;
@@ -1,13 +1,13 @@
1
1
  export { initPreContext } from './context';
2
- export declare function preJs(jsCode: string): any;
3
- export declare function preHtml(htmlCode: string): any;
2
+ export declare function preJs(jsCode: string, filename: string): any;
3
+ export declare function preHtml(htmlCode: string, filename: string): any;
4
4
  export declare const preCss: typeof preJs;
5
5
  export declare const preJson: typeof preJs;
6
- export declare function preNVueJs(jsCode: string): any;
7
- export declare function preNVueHtml(htmlCode: string): any;
6
+ export declare function preNVueJs(jsCode: string, filename: string): any;
7
+ export declare function preNVueHtml(htmlCode: string, filename: string): any;
8
8
  export declare const preNVueCss: typeof preNVueJs;
9
9
  export declare const preNVueJson: typeof preNVueJs;
10
- export declare function preUVueJs(jsCode: string): any;
11
- export declare function preUVueHtml(htmlCode: string): any;
10
+ export declare function preUVueJs(jsCode: string, filename: string): any;
11
+ export declare function preUVueHtml(htmlCode: string, filename: string): any;
12
12
  export declare const preUVueCss: typeof preUVueJs;
13
13
  export declare const preUVueJson: typeof preUVueJs;
@@ -1,44 +1,117 @@
1
1
  "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
2
5
  Object.defineProperty(exports, "__esModule", { value: true });
3
6
  exports.preUVueJson = exports.preUVueCss = exports.preUVueHtml = exports.preUVueJs = exports.preNVueJson = exports.preNVueCss = exports.preNVueHtml = exports.preNVueJs = exports.preJson = exports.preCss = exports.preHtml = exports.preJs = exports.initPreContext = void 0;
7
+ const path_1 = __importDefault(require("path"));
8
+ const utils_1 = require("../utils");
4
9
  const context_1 = require("./context");
5
10
  /* eslint-disable no-restricted-globals */
6
- const { preprocess } = require('../../lib/preprocess');
11
+ const { preprocess: preprocessLib } = require('../../lib/preprocess');
7
12
  var context_2 = require("./context");
8
13
  Object.defineProperty(exports, "initPreContext", { enumerable: true, get: function () { return context_2.initPreContext; } });
9
- function preJs(jsCode) {
14
+ function normalizeFilename(filename) {
15
+ return () => {
16
+ if (filename && process.env.UNI_INPUT_DIR) {
17
+ const inputDir = (0, utils_1.normalizePath)(process.env.UNI_INPUT_DIR);
18
+ filename = (0, utils_1.normalizePath)(filename.split('?')[0]);
19
+ if (filename.startsWith(inputDir)) {
20
+ return 'at ' + (0, utils_1.normalizePath)(path_1.default.relative(inputDir, filename)) + ':1';
21
+ }
22
+ return 'at ' + filename + ':1';
23
+ }
24
+ };
25
+ }
26
+ function preJs(jsCode, filename) {
10
27
  if (process.env.UNI_APP_X === 'true') {
11
- return preUVueJs(jsCode);
28
+ return preUVueJs(jsCode, filename);
12
29
  }
13
- return preprocess(jsCode, (0, context_1.getPreVueContext)(), { type: 'js' });
30
+ return preprocess(jsCode, (0, context_1.getPreVueContext)(), {
31
+ type: 'js',
32
+ filename: normalizeFilename(filename),
33
+ });
14
34
  }
15
35
  exports.preJs = preJs;
16
- function preHtml(htmlCode) {
36
+ function preHtml(htmlCode, filename) {
17
37
  if (process.env.UNI_APP_X === 'true') {
18
- return preUVueHtml(htmlCode);
38
+ return preUVueHtml(htmlCode, filename);
19
39
  }
20
- return preprocess(htmlCode, (0, context_1.getPreVueContext)(), { type: 'html' });
40
+ return preprocess(htmlCode, (0, context_1.getPreVueContext)(), {
41
+ type: 'html',
42
+ filename: normalizeFilename(filename),
43
+ });
21
44
  }
22
45
  exports.preHtml = preHtml;
23
46
  exports.preCss = preJs;
24
47
  exports.preJson = preJs;
25
- function preNVueJs(jsCode) {
26
- return preprocess(jsCode, (0, context_1.getPreNVueContext)(), { type: 'js' });
48
+ function preNVueJs(jsCode, filename) {
49
+ return preprocess(jsCode, (0, context_1.getPreNVueContext)(), {
50
+ type: 'js',
51
+ filename: normalizeFilename(filename),
52
+ });
27
53
  }
28
54
  exports.preNVueJs = preNVueJs;
29
- function preNVueHtml(htmlCode) {
30
- return preprocess(htmlCode, (0, context_1.getPreNVueContext)(), { type: 'html' });
55
+ function preNVueHtml(htmlCode, filename) {
56
+ return preprocess(htmlCode, (0, context_1.getPreNVueContext)(), {
57
+ type: 'html',
58
+ filename: normalizeFilename(filename),
59
+ });
31
60
  }
32
61
  exports.preNVueHtml = preNVueHtml;
33
62
  exports.preNVueCss = preNVueJs;
34
63
  exports.preNVueJson = preNVueJs;
35
- function preUVueJs(jsCode) {
36
- return preprocess(jsCode, (0, context_1.getPreUVueContext)(), { type: 'js' });
64
+ function preUVueJs(jsCode, filename) {
65
+ return preprocess(jsCode, (0, context_1.getPreUVueContext)(), {
66
+ type: 'js',
67
+ filename: normalizeFilename(filename),
68
+ });
37
69
  }
38
70
  exports.preUVueJs = preUVueJs;
39
- function preUVueHtml(htmlCode) {
40
- return preprocess(htmlCode, (0, context_1.getPreUVueContext)(), { type: 'html' });
71
+ function preUVueHtml(htmlCode, filename) {
72
+ return preprocess(htmlCode, (0, context_1.getPreUVueContext)(), {
73
+ type: 'html',
74
+ filename: normalizeFilename(filename),
75
+ });
41
76
  }
42
77
  exports.preUVueHtml = preUVueHtml;
43
78
  exports.preUVueCss = preUVueJs;
44
79
  exports.preUVueJson = preUVueJs;
80
+ const ERRORS = {
81
+ html: `条件编译失败
82
+ %FILENAME%
83
+ 参考示例(注意 ifdef 与 endif 必须配对使用):
84
+ <!-- #ifdef %PLATFORM% -->
85
+ 模板代码
86
+ <!-- #endif -->
87
+ `,
88
+ js: `条件编译失败
89
+ %FILENAME%
90
+ 参考示例(注意 ifdef 与 endif 必须配对使用):
91
+ // #ifdef %PLATFORM%
92
+ 代码
93
+ // #endif
94
+ `,
95
+ css: `条件编译失败
96
+ %FILENAME%
97
+ 参考示例(注意 ifdef 与 endif 必须配对使用):
98
+ /* #ifdef %PLATFORM% */
99
+ 代码
100
+ /* #endif */
101
+ `,
102
+ };
103
+ function preprocess(code, context, options) {
104
+ try {
105
+ return preprocessLib(code, context, options);
106
+ }
107
+ catch (e) {
108
+ const msg = ERRORS[options.type];
109
+ if (msg) {
110
+ console.error(msg.replace('%FILENAME%', options.filename?.() || ''));
111
+ }
112
+ else {
113
+ throw e;
114
+ }
115
+ }
116
+ return code;
117
+ }
package/dist/resolve.js CHANGED
@@ -97,7 +97,7 @@ function resolveBuiltIn(module) {
97
97
  if (process.env.UNI_COMPILE_TARGET === 'ext-api' &&
98
98
  process.env.UNI_APP_NEXT_WORKSPACE &&
99
99
  module.startsWith('@dcloudio/')) {
100
- return path_1.default.resolve(process.env.UNI_APP_NEXT_WORKSPACE, 'packages', module);
100
+ return path_1.default.resolve(process.env.UNI_APP_NEXT_WORKSPACE, 'packages', module.replace('@dcloudio/', ''));
101
101
  }
102
102
  return require.resolve(module, { paths: getBuiltInPaths() });
103
103
  }
@@ -14,7 +14,7 @@ export declare function packUploadEncryptUniModules(uniModules: Record<string, E
14
14
  zipFile: string;
15
15
  modules: string[];
16
16
  };
17
- interface EncryptPackageJson {
17
+ export interface EncryptPackageJson {
18
18
  id: string;
19
19
  version: string;
20
20
  uni_modules: {
@@ -26,6 +26,10 @@ interface EncryptPackageJson {
26
26
  apis: string[];
27
27
  components: string[];
28
28
  scopedSlots: string[];
29
+ customElements: {
30
+ name: string;
31
+ class: string;
32
+ }[];
29
33
  declaration: string;
30
34
  };
31
35
  };
@@ -47,4 +51,3 @@ export declare function parseUniModulesArtifacts(): {
47
51
  scopedSlots: string[];
48
52
  declaration: string;
49
53
  }[];
50
- export {};
@@ -212,7 +212,8 @@ function findEncryptUniModuleCache(uniModuleId, cacheDir, options) {
212
212
  const pkg = require(path_1.default.resolve(uniModuleCacheDir, 'package.json'));
213
213
  // 插件版本以及各种环境一致
214
214
  if (pkg.version === options.version &&
215
- !isEnvExpired(pkg.uni_modules?.artifacts?.env || {}, options.env)) {
215
+ (options.env.compilerVersion === '4.17-test' ||
216
+ !isEnvExpired(pkg.uni_modules?.artifacts?.env || {}, options.env))) {
216
217
  const declaration = path_1.default.resolve(uniModuleCacheDir, 'utssdk/app-android/index.d.uts');
217
218
  pkg.uni_modules.artifacts.declaration = fs_extra_1.default.existsSync(declaration)
218
219
  ? declaration
@@ -284,7 +285,8 @@ function resolveEncryptUniModule(id, platform, isX = true) {
284
285
  if (index !== -1) {
285
286
  const uniModuleId = parts[index + 1];
286
287
  if (uniModuleId in encryptUniModules) {
287
- if (parts[index + 2]) {
288
+ if (parts[index + 2] &&
289
+ (platform === 'app-android' || platform === 'app-ios')) {
288
290
  console.warn(messages_1.M['uni_modules.import']
289
291
  .replace('{0}', uniModuleId)
290
292
  .replace('{1}', uniModuleId)
@@ -5,6 +5,8 @@ export type DefineOptions = {
5
5
  js?: boolean;
6
6
  kotlin?: boolean;
7
7
  swift?: boolean;
8
+ arkts?: boolean;
9
+ ['x-arkts']?: boolean;
8
10
  };
9
11
  [key: string]: any;
10
12
  };
package/dist/uts.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  /// <reference types="node" />
2
2
  /// <reference types="node" />
3
+ import { type Import, type Unimport } from 'unimport';
3
4
  import type * as UTSCompiler from '@dcloudio/uni-uts-v1';
4
5
  import type { EasycomMatcher } from './easycom';
5
6
  /**
@@ -12,14 +13,37 @@ export declare function resolveUTSAppModule(platform: typeof process.env.UNI_UTS
12
13
  export declare function resolveUTSModule(id: string, importer: string, includeUTSSDK?: boolean): string | undefined;
13
14
  export declare function resolveUTSCompiler(throwError?: boolean): typeof UTSCompiler;
14
15
  export declare function resolveUTSCompilerVersion(): string;
16
+ interface UTSComponentMeta {
17
+ source: string;
18
+ kotlinPackage: string;
19
+ swiftModule: string;
20
+ }
21
+ interface UTSCustomElementMeta extends UTSComponentMeta {
22
+ exports: [string][];
23
+ }
24
+ export declare function getUTSCustomElementsExports(): Map<string, UTSCustomElementMeta>;
25
+ export declare function clearUTSComponents(): void;
15
26
  export declare function isUTSComponent(name: string): boolean;
27
+ export declare function clearUTSCustomElements(): void;
28
+ export declare function getUTSCustomElements(): Map<string, UTSComponentMeta>;
29
+ export declare function getUTSPluginCustomElements(): Record<string, Set<string>>;
30
+ export declare function isUTSCustomElement(name: string): boolean;
31
+ export declare function getUTSCustomElement(name: string): UTSComponentMeta | undefined;
16
32
  export declare function getUTSComponentAutoImports(language: 'kotlin' | 'swift'): Record<string, [[string]]>;
33
+ export declare function getUTSCustomElementAutoImports(language: 'kotlin' | 'swift'): Record<string, [string][]>;
17
34
  export declare function parseUTSComponent(name: string, type: 'kotlin' | 'swift'): {
18
35
  className: string;
19
36
  namespace: string;
20
37
  source: string;
21
38
  } | undefined;
39
+ export declare function parseUTSCustomElement(name: string, type: 'kotlin' | 'swift'): {
40
+ className: string;
41
+ namespace: string;
42
+ source: string;
43
+ } | undefined;
22
44
  export declare function initUTSComponents(inputDir: string, platform: UniApp.PLATFORM): EasycomMatcher[];
45
+ export declare function initUTSCustomElements(inputDir: string, platform: UniApp.PLATFORM): EasycomMatcher[];
46
+ export declare function parseCustomElementExports(filePath: string, unimport?: Unimport): Promise<Import[]>;
23
47
  export declare function parseKotlinPackageWithPluginId(id: string, is_uni_modules: boolean): string;
24
48
  export declare function parseSwiftPackageWithPluginId(id: string, is_uni_modules: boolean): string;
25
49
  export type UTSTargetLanguage = typeof process.env.UNI_UTS_TARGET_LANGUAGE;
@@ -33,3 +57,4 @@ export declare function uvueOutDir(platform: 'app-android' | 'app-ios' | 'app-ha
33
57
  export declare function tscOutDir(platform: 'app-android' | 'app-ios' | 'app-harmony'): string;
34
58
  export declare function isUTSProxy(id: string): boolean;
35
59
  export declare function isUniHelpers(id: string): boolean;
60
+ export {};