@dcloudio/uni-cli-shared 3.0.0-4000820240401001 → 3.0.0-4010420240430002

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 (98) hide show
  1. package/dist/deps.d.ts +2 -0
  2. package/dist/deps.js +3 -0
  3. package/dist/easycom.js +4 -3
  4. package/dist/hbx/alias.js +26 -5
  5. package/dist/hbx/index.d.ts +1 -1
  6. package/dist/hbx/log.d.ts +1 -1
  7. package/dist/hbx/log.js +2 -1
  8. package/dist/index.d.ts +2 -1
  9. package/dist/index.js +3 -2
  10. package/dist/json/app/pages/code.d.ts +1 -1
  11. package/dist/json/mp/index.d.ts +1 -1
  12. package/dist/json/mp/jsonFile.d.ts +1 -1
  13. package/dist/json/mp/pages.d.ts +1 -1
  14. package/dist/json/mp/project.js +2 -2
  15. package/dist/json/mp/types.d.ts +1 -1
  16. package/dist/json/mp/utils.d.ts +1 -1
  17. package/dist/json/uni-x/uniConfig.js +4 -0
  18. package/dist/logs/console.d.ts +2 -4
  19. package/dist/logs/console.js +7 -4
  20. package/dist/logs/format.d.ts +1 -1
  21. package/dist/mp/ast.d.ts +1 -1
  22. package/dist/mp/externalClasses.d.ts +1 -1
  23. package/dist/mp/imports.d.ts +2 -2
  24. package/dist/mp/plugin.d.ts +1 -1
  25. package/dist/mp/tags.js +5 -6
  26. package/dist/mp/usingComponents.d.ts +1 -1
  27. package/dist/postcss/index.d.ts +1 -1
  28. package/dist/uni_modules.d.ts +23 -0
  29. package/dist/uni_modules.js +80 -12
  30. package/dist/utils.d.ts +3 -5
  31. package/dist/utils.js +7 -7
  32. package/dist/uts.d.ts +3 -4
  33. package/dist/uts.js +28 -42
  34. package/dist/utsUtils.d.ts +2 -0
  35. package/dist/utsUtils.js +44 -0
  36. package/dist/vite/autoImport.d.ts +1 -1
  37. package/dist/vite/autoImport.js +1 -0
  38. package/dist/vite/features.d.ts +1 -0
  39. package/dist/vite/features.js +31 -28
  40. package/dist/vite/index.d.ts +2 -1
  41. package/dist/vite/plugins/console.d.ts +2 -2
  42. package/dist/vite/plugins/copy.d.ts +1 -1
  43. package/dist/vite/plugins/easycom.d.ts +2 -2
  44. package/dist/vite/plugins/index.d.ts +1 -0
  45. package/dist/vite/plugins/index.js +3 -1
  46. package/dist/vite/plugins/inject.d.ts +1 -1
  47. package/dist/vite/plugins/inject.js +2 -2
  48. package/dist/vite/plugins/jsonJs.d.ts +3 -3
  49. package/dist/vite/plugins/mainJs.d.ts +2 -2
  50. package/dist/vite/plugins/sfc.d.ts +6 -0
  51. package/dist/vite/plugins/sfc.js +136 -0
  52. package/dist/vite/plugins/uts/ext-api.d.ts +2 -1
  53. package/dist/vite/plugins/uts/ext-api.js +4 -5
  54. package/dist/vite/plugins/uts/uni_modules.d.ts +1 -1
  55. package/dist/vite/plugins/uts/uni_modules.js +20 -7
  56. package/dist/vite/plugins/uts/uvue.js +1 -1
  57. package/dist/vite/plugins/vitejs/plugins/asset.d.ts +2 -2
  58. package/dist/vite/plugins/vitejs/plugins/asset.js +1 -1
  59. package/dist/vite/plugins/vitejs/plugins/css.d.ts +4 -4
  60. package/dist/vite/plugins/vitejs/plugins/css.js +10 -2
  61. package/dist/vite/plugins/vitejs/utils.d.ts +1 -1
  62. package/dist/vite/utils/ast.d.ts +2 -2
  63. package/dist/vite/utils/ast.js +7 -6
  64. package/dist/vite/utils/utils.d.ts +2 -2
  65. package/dist/vue/babel.d.ts +1 -1
  66. package/dist/vue/parse.d.ts +1 -1
  67. package/dist/vue/parse.js +8 -7
  68. package/dist/vue/transforms/index.d.ts +1 -0
  69. package/dist/vue/transforms/index.js +1 -0
  70. package/dist/vue/transforms/templateTransformAssetUrl.d.ts +1 -1
  71. package/dist/vue/transforms/templateTransformAssetUrl.js +8 -8
  72. package/dist/vue/transforms/templateTransformSrcset.d.ts +2 -2
  73. package/dist/vue/transforms/templateTransformSrcset.js +7 -7
  74. package/dist/vue/transforms/templateUtils.d.ts +1 -1
  75. package/dist/vue/transforms/transformComponent.d.ts +2 -2
  76. package/dist/vue/transforms/transformComponent.js +7 -3
  77. package/dist/vue/transforms/transformEvent.d.ts +1 -1
  78. package/dist/vue/transforms/transformPageHead.d.ts +1 -1
  79. package/dist/vue/transforms/transformRef.d.ts +1 -1
  80. package/dist/vue/transforms/transformRef.js +1 -1
  81. package/dist/vue/transforms/transformRefresherSlot.d.ts +8 -0
  82. package/dist/vue/transforms/transformRefresherSlot.js +58 -0
  83. package/dist/vue/transforms/transformTag.d.ts +1 -1
  84. package/dist/vue/transforms/transformUTSComponent.d.ts +1 -1
  85. package/dist/vue/transforms/transformUTSComponent.js +2 -2
  86. package/dist/vue/transforms/vModel.d.ts +1 -1
  87. package/dist/vue/transforms/vOn.d.ts +1 -1
  88. package/dist/vue/transforms/vOn.js +4 -4
  89. package/dist/vue/utils.d.ts +4 -1
  90. package/dist/vue/utils.js +47 -8
  91. package/dist/watcher.d.ts +1 -1
  92. package/lib/@vue/compiler-sfc/LICENSE +21 -0
  93. package/lib/@vue/compiler-sfc/README.md +80 -0
  94. package/lib/@vue/compiler-sfc/dist/compiler-sfc.cjs.js +20665 -0
  95. package/lib/@vue/compiler-sfc/dist/compiler-sfc.d.ts +543 -0
  96. package/lib/@vue/compiler-sfc/dist/compiler-sfc.esm-browser.js +48237 -0
  97. package/lib/@vue/compiler-sfc/package.json +67 -0
  98. package/package.json +20 -18
package/dist/uts.js CHANGED
@@ -3,15 +3,14 @@ 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.genUTSClassName = exports.matchUTSComponent = exports.parseUniExtApiNamespacesJsOnce = exports.parseUniExtApiNamespacesOnce = exports.parseSwiftPackageWithPluginId = exports.parseKotlinPackageWithPluginId = exports.initUTSComponents = exports.parseUTSComponent = exports.isUTSComponent = exports.resolveUTSCompiler = exports.resolveUTSModule = exports.resolveUTSAppModule = void 0;
6
+ exports.resolveUniTypeScript = exports.parseUniExtApiNamespacesJsOnce = exports.parseUniExtApiNamespacesOnce = exports.parseSwiftPackageWithPluginId = exports.parseKotlinPackageWithPluginId = exports.initUTSComponents = exports.parseUTSComponent = exports.isUTSComponent = exports.resolveUTSCompiler = exports.resolveUTSModule = exports.resolveUTSAppModule = void 0;
7
+ // 重要,该文件编译后的 js 需要同步到 vue2 编译器 uni-cli-shared/lib/uts
7
8
  const fs_1 = __importDefault(require("fs"));
8
9
  const path_1 = __importDefault(require("path"));
9
10
  const fast_glob_1 = __importDefault(require("fast-glob"));
10
11
  const hbx_1 = require("./hbx");
11
12
  const utils_1 = require("./utils");
12
- const easycom_1 = require("./easycom");
13
13
  const uni_modules_1 = require("./uni_modules");
14
- // 重要,该文件编译后的 js 需要同步到 vue2 编译器 uni-cli-shared/lib/uts
15
14
  function once(fn, ctx = null) {
16
15
  let res;
17
16
  return ((...args) => {
@@ -36,6 +35,15 @@ function resolveUTSAppModule(id, importer, includeUTSSDK = true) {
36
35
  if (parentDir === 'uni_modules' ||
37
36
  (includeUTSSDK && parentDir === 'utssdk')) {
38
37
  const basedir = parentDir === 'uni_modules' ? 'utssdk' : '';
38
+ if (process.env.UNI_APP_X_UVUE_SCRIPT_ENGINE === 'js') {
39
+ // js engine
40
+ if (parentDir === 'uni_modules') {
41
+ const appJsIndex = path_1.default.resolve(id, basedir, 'app-js', 'index.uts');
42
+ if (fs_1.default.existsSync(appJsIndex)) {
43
+ return appJsIndex;
44
+ }
45
+ }
46
+ }
39
47
  if (fs_1.default.existsSync(path_1.default.resolve(id, basedir, 'index.uts'))) {
40
48
  return id;
41
49
  }
@@ -104,8 +112,18 @@ function resolveUTSCompiler() {
104
112
  });
105
113
  }
106
114
  catch (e) {
107
- let utsCompilerVersion = utils_1.version;
108
- if (utils_1.version.startsWith('2.0.')) {
115
+ let utsCompilerVersion = '';
116
+ try {
117
+ utsCompilerVersion = require('../package.json').version;
118
+ }
119
+ catch (e) {
120
+ try {
121
+ // vue2
122
+ utsCompilerVersion = require('../../package.json').version;
123
+ }
124
+ catch (e) { }
125
+ }
126
+ if (utsCompilerVersion.startsWith('2.0.')) {
109
127
  utsCompilerVersion = '^3.0.0-alpha-3060920221117001';
110
128
  }
111
129
  console.error((0, utils_1.installDepTips)('devDependencies', '@dcloudio/uni-uts-v1', utsCompilerVersion));
@@ -254,42 +272,10 @@ exports.parseUniExtApiNamespacesJsOnce = once((platform, language) => {
254
272
  });
255
273
  return namespaces;
256
274
  });
257
- function matchUTSComponent(tag) {
258
- const source = (0, easycom_1.matchEasycom)(tag);
259
- return !!(source && source.includes('uts-proxy'));
260
- }
261
- exports.matchUTSComponent = matchUTSComponent;
262
- function genUTSClassName(fileName, prefix = 'Gen') {
263
- return (prefix +
264
- (0, utils_1.capitalize)((0, utils_1.camelize)(verifySymbol((0, utils_1.removeExt)((0, utils_1.normalizeNodeModules)(fileName)
265
- .replace(/[\/|_]/g, '-')
266
- .replace(/-+/g, '-'))))));
267
- }
268
- exports.genUTSClassName = genUTSClassName;
269
- function isValidStart(c) {
270
- return !!c.match(/^[A-Za-z_-]$/);
271
- }
272
- function isValidContinue(c) {
273
- return !!c.match(/^[A-Za-z0-9_-]$/);
274
- }
275
- function verifySymbol(s) {
276
- const chars = Array.from(s);
277
- if (isValidStart(chars[0]) && chars.slice(1).every(isValidContinue)) {
278
- return s;
279
- }
280
- const buf = [];
281
- let hasStart = false;
282
- for (const c of chars) {
283
- if (!hasStart && isValidStart(c)) {
284
- hasStart = true;
285
- buf.push(c);
286
- }
287
- else if (isValidContinue(c)) {
288
- buf.push(c);
289
- }
290
- }
291
- if (buf.length === 0) {
292
- buf.push('_');
275
+ function resolveUniTypeScript() {
276
+ if ((0, hbx_1.isInHBuilderX)()) {
277
+ return require(path_1.default.resolve(process.env.UNI_HBUILDERX_PLUGINS, 'uniapp-uts-v1', 'node_modules', '@dcloudio', 'uni-uts-v1', 'lib', 'typescript'));
293
278
  }
294
- return buf.join('');
279
+ return require('@dcloudio/uni-uts-v1/lib/typescript');
295
280
  }
281
+ exports.resolveUniTypeScript = resolveUniTypeScript;
@@ -0,0 +1,2 @@
1
+ export declare function matchUTSComponent(tag: string): boolean;
2
+ export declare function genUTSClassName(fileName: string, prefix?: string): string;
@@ -0,0 +1,44 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.genUTSClassName = exports.matchUTSComponent = void 0;
4
+ const easycom_1 = require("./easycom");
5
+ const utils_1 = require("./utils");
6
+ function matchUTSComponent(tag) {
7
+ const source = (0, easycom_1.matchEasycom)(tag);
8
+ return !!(source && source.includes('uts-proxy'));
9
+ }
10
+ exports.matchUTSComponent = matchUTSComponent;
11
+ function genUTSClassName(fileName, prefix = 'Gen') {
12
+ return (prefix +
13
+ (0, utils_1.capitalize)((0, utils_1.camelize)(verifySymbol((0, utils_1.removeExt)((0, utils_1.normalizeNodeModules)(fileName)
14
+ .replace(/[\/|_]/g, '-')
15
+ .replace(/-+/g, '-'))))));
16
+ }
17
+ exports.genUTSClassName = genUTSClassName;
18
+ function isValidStart(c) {
19
+ return !!c.match(/^[A-Za-z_-]$/);
20
+ }
21
+ function isValidContinue(c) {
22
+ return !!c.match(/^[A-Za-z0-9_-]$/);
23
+ }
24
+ function verifySymbol(s) {
25
+ const chars = Array.from(s);
26
+ if (isValidStart(chars[0]) && chars.slice(1).every(isValidContinue)) {
27
+ return s;
28
+ }
29
+ const buf = [];
30
+ let hasStart = false;
31
+ for (const c of chars) {
32
+ if (!hasStart && isValidStart(c)) {
33
+ hasStart = true;
34
+ buf.push(c);
35
+ }
36
+ else if (isValidContinue(c)) {
37
+ buf.push(c);
38
+ }
39
+ }
40
+ if (buf.length === 0) {
41
+ buf.push('_');
42
+ }
43
+ return buf.join('');
44
+ }
@@ -1,3 +1,3 @@
1
- import { Options } from 'unplugin-auto-import/types';
1
+ import type { Options } from 'unplugin-auto-import/types';
2
2
  export type AutoImportOptions = Options;
3
3
  export declare function initAutoImportOptions(platform: typeof process.env.UNI_UTS_PLATFORM, { imports, ...userOptions }: AutoImportOptions): AutoImportOptions;
@@ -132,6 +132,7 @@ const vuePreset = {
132
132
  'provide',
133
133
  'useCssModule',
134
134
  'createApp',
135
+ 'hasInjectionContext',
135
136
  // effect scope
136
137
  'effectScope',
137
138
  'EffectScope',
@@ -11,6 +11,7 @@ interface InitFeaturesOptions {
11
11
  export declare function initFeatures(options: InitFeaturesOptions): {
12
12
  __VUE_OPTIONS_API__: boolean;
13
13
  __VUE_PROD_DEVTOOLS__: boolean;
14
+ __VUE_PROD_HYDRATION_MISMATCH_DETAILS__: boolean;
14
15
  __UNI_FEATURE_WX__: boolean;
15
16
  __UNI_FEATURE_WXS__: boolean;
16
17
  __UNI_FEATURE_RPX__: boolean;
@@ -128,6 +128,7 @@ function initManifestFeature({ manifestJson, command, platform, }) {
128
128
  routerMode: '"hash"',
129
129
  vueOptionsApi: true,
130
130
  vueProdDevTools: false,
131
+ vueProdHydrationMismatchDetails: false,
131
132
  };
132
133
  if (command === 'build') {
133
134
  // TODO 需要预编译一遍?
@@ -143,38 +144,40 @@ function initManifestFeature({ manifestJson, command, platform, }) {
143
144
  return features;
144
145
  }
145
146
  function initFeatures(options) {
146
- const { wx, wxs, rpx, nvue, uniCloud, i18nEn, i18nEs, i18nFr, i18nZhHans, i18nZhHant, i18nLocale, vueOptionsApi, vueProdDevTools, pages, tabBar, tabBarMidButton, promise, longpress, routerMode, topWindow, leftWindow, rightWindow, navigationBar, pullDownRefresh, navigationBarButtons, navigationBarSearchInput, navigationBarTransparent, } = (0, shared_1.extend)(initManifestFeature(options), initPagesFeature(options), initProjectFeature(options));
147
+ const { wx, wxs, rpx, nvue, uniCloud, i18nEn, i18nEs, i18nFr, i18nZhHans, i18nZhHant, i18nLocale, vueOptionsApi, vueProdDevTools, vueProdHydrationMismatchDetails, pages, tabBar, tabBarMidButton, promise, longpress, routerMode, topWindow, leftWindow, rightWindow, navigationBar, pullDownRefresh, navigationBarButtons, navigationBarSearchInput, navigationBarTransparent, } = (0, shared_1.extend)(initManifestFeature(options), initPagesFeature(options), initProjectFeature(options));
148
+ // uni-app-x运行时可调用$setPageStyle,需启用相关特性方可支持。否则$setPageStyle无效果
147
149
  const features = {
148
150
  // vue
149
- __VUE_OPTIONS_API__: vueOptionsApi,
150
- __VUE_PROD_DEVTOOLS__: vueProdDevTools,
151
+ __VUE_OPTIONS_API__: vueOptionsApi, // enable/disable Options API support, default: true
152
+ __VUE_PROD_DEVTOOLS__: vueProdDevTools, // enable/disable devtools support in production, default: false
153
+ __VUE_PROD_HYDRATION_MISMATCH_DETAILS__: vueProdHydrationMismatchDetails,
151
154
  // uni
152
- __UNI_FEATURE_WX__: wx,
153
- __UNI_FEATURE_WXS__: wxs,
154
- __UNI_FEATURE_RPX__: rpx,
155
- __UNI_FEATURE_PROMISE__: promise,
156
- __UNI_FEATURE_LONGPRESS__: longpress,
157
- __UNI_FEATURE_I18N_EN__: i18nEn,
158
- __UNI_FEATURE_I18N_ES__: i18nEs,
159
- __UNI_FEATURE_I18N_FR__: i18nFr,
160
- __UNI_FEATURE_I18N_ZH_HANS__: i18nZhHans,
161
- __UNI_FEATURE_I18N_ZH_HANT__: i18nZhHant,
155
+ __UNI_FEATURE_WX__: wx, // 是否启用小程序的组件实例 API,如:selectComponent 等(uni-core/src/service/plugin/appConfig)
156
+ __UNI_FEATURE_WXS__: wxs, // 是否启用 wxs 支持,如:getComponentDescriptor 等(uni-core/src/view/plugin/appConfig)
157
+ __UNI_FEATURE_RPX__: rpx, // 是否启用运行时 rpx 支持
158
+ __UNI_FEATURE_PROMISE__: promise, // 是否启用旧版本的 promise 支持(即返回[err,res]的格式),默认返回标准
159
+ __UNI_FEATURE_LONGPRESS__: longpress, // 是否启用longpress
160
+ __UNI_FEATURE_I18N_EN__: i18nEn, // 是否启用en
161
+ __UNI_FEATURE_I18N_ES__: i18nEs, // 是否启用es
162
+ __UNI_FEATURE_I18N_FR__: i18nFr, // 是否启用fr
163
+ __UNI_FEATURE_I18N_ZH_HANS__: i18nZhHans, // 是否启用zh_Hans
164
+ __UNI_FEATURE_I18N_ZH_HANT__: i18nZhHant, // 是否启用zh_Hant
162
165
  // 以下特性,编译器已自动识别是否需要启用
163
- __UNI_FEATURE_UNI_CLOUD__: uniCloud,
164
- __UNI_FEATURE_I18N_LOCALE__: i18nLocale,
165
- __UNI_FEATURE_NVUE__: nvue,
166
- __UNI_FEATURE_ROUTER_MODE__: routerMode,
167
- __UNI_FEATURE_PAGES__: pages,
168
- __UNI_FEATURE_TABBAR__: tabBar,
169
- __UNI_FEATURE_TABBAR_MIDBUTTON__: tabBarMidButton,
170
- __UNI_FEATURE_TOPWINDOW__: topWindow,
171
- __UNI_FEATURE_LEFTWINDOW__: leftWindow,
172
- __UNI_FEATURE_RIGHTWINDOW__: rightWindow,
173
- __UNI_FEATURE_RESPONSIVE__: topWindow || leftWindow || rightWindow,
174
- __UNI_FEATURE_NAVIGATIONBAR__: navigationBar,
175
- __UNI_FEATURE_PULL_DOWN_REFRESH__: pullDownRefresh,
176
- __UNI_FEATURE_NAVIGATIONBAR_BUTTONS__: navigationBarButtons,
177
- __UNI_FEATURE_NAVIGATIONBAR_SEARCHINPUT__: navigationBarSearchInput,
166
+ __UNI_FEATURE_UNI_CLOUD__: uniCloud, // 是否启用uniCloud
167
+ __UNI_FEATURE_I18N_LOCALE__: i18nLocale, // 是否启用i18n
168
+ __UNI_FEATURE_NVUE__: nvue, // 是否启用nvue
169
+ __UNI_FEATURE_ROUTER_MODE__: routerMode, // 路由模式
170
+ __UNI_FEATURE_PAGES__: pages, // 是否多页面
171
+ __UNI_FEATURE_TABBAR__: tabBar, // 是否包含tabBar
172
+ __UNI_FEATURE_TABBAR_MIDBUTTON__: tabBarMidButton, // 是否包含midButton
173
+ __UNI_FEATURE_TOPWINDOW__: topWindow, // 是否包含topWindow
174
+ __UNI_FEATURE_LEFTWINDOW__: leftWindow, // 是否包含leftWindow
175
+ __UNI_FEATURE_RIGHTWINDOW__: rightWindow, // 是否包含rightWindow
176
+ __UNI_FEATURE_RESPONSIVE__: topWindow || leftWindow || rightWindow, // 是否启用响应式
177
+ __UNI_FEATURE_NAVIGATIONBAR__: navigationBar, // 是否启用标题栏
178
+ __UNI_FEATURE_PULL_DOWN_REFRESH__: pullDownRefresh, // 是否启用下拉刷新
179
+ __UNI_FEATURE_NAVIGATIONBAR_BUTTONS__: navigationBarButtons, // 是否启用标题栏按钮
180
+ __UNI_FEATURE_NAVIGATIONBAR_SEARCHINPUT__: navigationBarSearchInput, // 是否启用标题栏搜索框
178
181
  __UNI_FEATURE_NAVIGATIONBAR_TRANSPARENT__: navigationBarTransparent, // 是否启用透明标题栏
179
182
  };
180
183
  // ssr nodejs features
@@ -2,7 +2,7 @@ import type { Plugin } from 'vite';
2
2
  import type { EmittedAsset } from 'rollup';
3
3
  import type { ParserOptions } from '@vue/compiler-core';
4
4
  import type { CompilerOptions, SFCStyleCompileOptions, TemplateCompiler } from '@vue/compiler-sfc';
5
- import { UniViteCopyPluginOptions } from './plugins/copy';
5
+ import type { UniViteCopyPluginOptions } from './plugins/copy';
6
6
  export declare const cssTarget = "chrome53";
7
7
  export interface CopyOptions {
8
8
  /**
@@ -22,6 +22,7 @@ interface UniVitePluginUniOptions {
22
22
  isCustomElement?: ParserOptions['isCustomElement'];
23
23
  directiveTransforms?: CompilerOptions['directiveTransforms'];
24
24
  nodeTransforms?: CompilerOptions['nodeTransforms'];
25
+ whitespace?: CompilerOptions['whitespace'];
25
26
  };
26
27
  jsxOptions?: {
27
28
  babelPlugins?: any[];
@@ -1,5 +1,5 @@
1
- import { Plugin } from 'vite';
2
- import { FilterPattern } from '@rollup/pluginutils';
1
+ import type { Plugin } from 'vite';
2
+ import { type FilterPattern } from '@rollup/pluginutils';
3
3
  export interface ConsoleOptions {
4
4
  method: string;
5
5
  filename?: (filename: string) => string;
@@ -1,6 +1,6 @@
1
1
  import type { WatchOptions } from 'chokidar';
2
2
  import type { Plugin } from 'vite';
3
- import { FileWatcherOptions } from '../../watcher';
3
+ import { type FileWatcherOptions } from '../../watcher';
4
4
  export type UniViteCopyPluginTarget = Omit<FileWatcherOptions, 'verbose'> & {
5
5
  watchOptions?: WatchOptions;
6
6
  };
@@ -1,5 +1,5 @@
1
- import { Plugin } from 'vite';
2
- import { FilterPattern } from '@rollup/pluginutils';
1
+ import type { Plugin } from 'vite';
2
+ import { type FilterPattern } from '@rollup/pluginutils';
3
3
  interface UniEasycomPluginOptions {
4
4
  include?: FilterPattern;
5
5
  exclude?: FilterPattern;
@@ -9,6 +9,7 @@ export * from './uts/uni_modules';
9
9
  export * from './uts/uvue';
10
10
  export * from './uts/ext-api';
11
11
  export * from './easycom';
12
+ export { uniViteSfcSrcImportPlugin } from './sfc';
12
13
  export { assetPlugin, parseAssets, getAssetHash } from './vitejs/plugins/asset';
13
14
  export { isCSSRequest, cssPlugin, cssPostPlugin, minifyCSS, cssLangRE, commonjsProxyRE, rewriteScssReadFileSync, } from './vitejs/plugins/css';
14
15
  export { generateCodeFrame, locToStartAndEnd, offsetToStartAndEnd, } from './vitejs/utils';
@@ -14,7 +14,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
- exports.offsetToStartAndEnd = exports.locToStartAndEnd = exports.generateCodeFrame = exports.rewriteScssReadFileSync = exports.commonjsProxyRE = exports.cssLangRE = exports.minifyCSS = exports.cssPostPlugin = exports.cssPlugin = exports.isCSSRequest = exports.getAssetHash = exports.parseAssets = exports.assetPlugin = void 0;
17
+ exports.offsetToStartAndEnd = exports.locToStartAndEnd = exports.generateCodeFrame = exports.rewriteScssReadFileSync = exports.commonjsProxyRE = exports.cssLangRE = exports.minifyCSS = exports.cssPostPlugin = exports.cssPlugin = exports.isCSSRequest = exports.getAssetHash = exports.parseAssets = exports.assetPlugin = exports.uniViteSfcSrcImportPlugin = void 0;
18
18
  __exportStar(require("./cssScoped"), exports);
19
19
  __exportStar(require("./copy"), exports);
20
20
  __exportStar(require("./inject"), exports);
@@ -26,6 +26,8 @@ __exportStar(require("./uts/uni_modules"), exports);
26
26
  __exportStar(require("./uts/uvue"), exports);
27
27
  __exportStar(require("./uts/ext-api"), exports);
28
28
  __exportStar(require("./easycom"), exports);
29
+ var sfc_1 = require("./sfc");
30
+ Object.defineProperty(exports, "uniViteSfcSrcImportPlugin", { enumerable: true, get: function () { return sfc_1.uniViteSfcSrcImportPlugin; } });
29
31
  var asset_1 = require("./vitejs/plugins/asset");
30
32
  Object.defineProperty(exports, "assetPlugin", { enumerable: true, get: function () { return asset_1.assetPlugin; } });
31
33
  Object.defineProperty(exports, "parseAssets", { enumerable: true, get: function () { return asset_1.parseAssets; } });
@@ -1,5 +1,5 @@
1
1
  import type { Plugin } from 'vite';
2
- import { FilterPattern } from '@rollup/pluginutils';
2
+ import { type FilterPattern } from '@rollup/pluginutils';
3
3
  type Injectment = string | [string, string];
4
4
  export interface InjectOptions {
5
5
  enforce?: 'pre' | 'post';
@@ -12,7 +12,7 @@ const shared_1 = require("@vue/shared");
12
12
  const magic_string_1 = __importDefault(require("magic-string"));
13
13
  const utils_1 = require("../utils");
14
14
  const debugInject = (0, debug_1.default)('uni:inject');
15
- const debugInjectTry = (0, debug_1.default)('uni:inject-try');
15
+ // const debugInjectTry = debug('uni:inject-try')
16
16
  function uniViteInjectPlugin(name, options) {
17
17
  if (!options)
18
18
  throw new Error('Missing options');
@@ -49,7 +49,7 @@ function uniViteInjectPlugin(name, options) {
49
49
  return null;
50
50
  if (!(0, utils_1.isJsFile)(id))
51
51
  return null;
52
- debugInjectTry(id);
52
+ // debugInjectTry(id)
53
53
  if (code.search(firstpass) === -1)
54
54
  return null;
55
55
  if (path_1.sep !== '/')
@@ -1,3 +1,3 @@
1
- import { CreateUniViteFilterPlugin } from '../utils/plugin';
2
- export declare const defineUniPagesJsonPlugin: (createVitePlugin: CreateUniViteFilterPlugin) => import("vite").Plugin;
3
- export declare const defineUniManifestJsonPlugin: (createVitePlugin: CreateUniViteFilterPlugin) => import("vite").Plugin;
1
+ import type { CreateUniViteFilterPlugin } from '../utils/plugin';
2
+ export declare const defineUniPagesJsonPlugin: (createVitePlugin: CreateUniViteFilterPlugin) => import("vite").Plugin<any>;
3
+ export declare const defineUniManifestJsonPlugin: (createVitePlugin: CreateUniViteFilterPlugin) => import("vite").Plugin<any>;
@@ -1,2 +1,2 @@
1
- import { CreateUniViteFilterPlugin } from '../utils/plugin';
2
- export declare function defineUniMainJsPlugin(createUniMainJsPlugin: CreateUniViteFilterPlugin): import("vite").Plugin;
1
+ import type { CreateUniViteFilterPlugin } from '../utils/plugin';
2
+ export declare function defineUniMainJsPlugin(createUniMainJsPlugin: CreateUniViteFilterPlugin): import("vite").Plugin<any>;
@@ -0,0 +1,6 @@
1
+ import type { Plugin } from 'vite';
2
+ export declare function isSrcImport(code: string): boolean;
3
+ export declare function isSrcImportVue(code: string): boolean;
4
+ export declare function uniViteSfcSrcImportPlugin({ onlyVue }?: {
5
+ onlyVue: boolean;
6
+ }): Plugin;
@@ -0,0 +1,136 @@
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.uniViteSfcSrcImportPlugin = exports.isSrcImportVue = exports.isSrcImport = void 0;
7
+ const fs_extra_1 = __importDefault(require("fs-extra"));
8
+ const magic_string_1 = __importDefault(require("magic-string"));
9
+ const vue_1 = require("../../vue");
10
+ const utils_1 = require("../utils");
11
+ const preprocess_1 = require("../../preprocess");
12
+ const SRC_IMPORT_RE = /<(template|script|style)[^>]*src\s*=\s*["']([^"']+)["'][^>]*>/;
13
+ const SRC_IMPORT_VUE_RE = /<(template|script|style)[^>]*src\s*=\s*["'](.*\.uvue|.*\.vue)["'][^>]*>/;
14
+ function isSrcImport(code) {
15
+ return SRC_IMPORT_RE.test(code);
16
+ }
17
+ exports.isSrcImport = isSrcImport;
18
+ function isSrcImportVue(code) {
19
+ return SRC_IMPORT_VUE_RE.test(code);
20
+ }
21
+ exports.isSrcImportVue = isSrcImportVue;
22
+ function uniViteSfcSrcImportPlugin({ onlyVue } = { onlyVue: true }) {
23
+ const { parse } = require('@vue/compiler-sfc');
24
+ const hasImport = onlyVue ? isSrcImportVue : isSrcImport;
25
+ const isValidSrc = onlyVue ? vue_1.isVueSfcFile : () => true;
26
+ return {
27
+ name: 'uni:sfc-src-import',
28
+ async transform(code, id) {
29
+ if (!(0, vue_1.isVueSfcFile)(id)) {
30
+ return;
31
+ }
32
+ if (!hasImport(code)) {
33
+ return;
34
+ }
35
+ const s = new magic_string_1.default(code);
36
+ const sourceMap = process.env.NODE_ENV === 'development';
37
+ const createDescriptor = (filename, code, from) => {
38
+ if (from === 'vue' || (0, vue_1.isVueSfcFile)(filename)) {
39
+ const { descriptor, errors } = parse(code, {
40
+ filename,
41
+ sourceMap,
42
+ });
43
+ errors.forEach((error) => this.error((0, utils_1.createRollupError)('', filename, error, code)));
44
+ return descriptor;
45
+ }
46
+ else {
47
+ const descriptor = {
48
+ filename,
49
+ source: fs_extra_1.default.readFileSync(filename, 'utf-8'),
50
+ template: null,
51
+ script: null,
52
+ scriptSetup: null,
53
+ styles: [],
54
+ customBlocks: [],
55
+ };
56
+ if (from === 'template') {
57
+ descriptor.template = {
58
+ content: descriptor.source,
59
+ };
60
+ }
61
+ else if (from === 'script') {
62
+ descriptor.script = {
63
+ content: descriptor.source,
64
+ };
65
+ }
66
+ else if (from === 'style') {
67
+ descriptor.styles = [
68
+ {
69
+ content: descriptor.source,
70
+ },
71
+ ];
72
+ }
73
+ return descriptor;
74
+ }
75
+ };
76
+ const descriptor = createDescriptor(id, code, 'vue');
77
+ const cache = new Map();
78
+ const getSrcDescriptor = async (src, from) => {
79
+ if (cache.has(src)) {
80
+ return cache.get(src);
81
+ }
82
+ const resolved = await this.resolve(src, descriptor.filename);
83
+ if (resolved) {
84
+ const filename = resolved.id;
85
+ const srcDescriptor = createDescriptor(filename, (0, preprocess_1.preUVueJs)((0, preprocess_1.preUVueHtml)(fs_extra_1.default.readFileSync(filename, 'utf-8'))), from);
86
+ cache.set(src, srcDescriptor);
87
+ this.addWatchFile(filename);
88
+ return srcDescriptor;
89
+ }
90
+ };
91
+ if (descriptor.template?.src && isValidSrc(descriptor.template.src)) {
92
+ const srcDescriptor = await getSrcDescriptor(descriptor.template.src, 'template');
93
+ if (srcDescriptor && srcDescriptor.template?.content) {
94
+ overwriteContent(s, descriptor.template.loc, srcDescriptor.template.content);
95
+ }
96
+ }
97
+ if (descriptor.script?.src && isValidSrc(descriptor.script.src)) {
98
+ const srcDescriptor = await getSrcDescriptor(descriptor.script.src, 'script');
99
+ if (srcDescriptor && srcDescriptor.script?.content) {
100
+ overwriteContent(s, descriptor.script.loc, srcDescriptor.script.content);
101
+ }
102
+ }
103
+ for (const style of descriptor.styles) {
104
+ if (style.src && isValidSrc(style.src)) {
105
+ const srcDescriptor = await getSrcDescriptor(style.src, 'style');
106
+ if (srcDescriptor && srcDescriptor.styles[0]) {
107
+ overwriteContent(s, style.loc, srcDescriptor.styles[0].content);
108
+ }
109
+ }
110
+ }
111
+ if (!s.hasChanged()) {
112
+ return;
113
+ }
114
+ // 移除所有的 src 属性
115
+ const regex = /(<(template|script|style)[^>]*)src\s*=\s*["']([^"']+)["']([^>]*>)/g;
116
+ let match;
117
+ while ((match = regex.exec(code))) {
118
+ const [_, start, _tag, _src, end] = match;
119
+ s.overwrite(match.index, match.index + _.length, `${start}${end}`);
120
+ }
121
+ return {
122
+ code: s.toString(),
123
+ map: sourceMap ? s.generateMap({ hires: true }) : { mappings: '' },
124
+ };
125
+ },
126
+ };
127
+ }
128
+ exports.uniViteSfcSrcImportPlugin = uniViteSfcSrcImportPlugin;
129
+ function overwriteContent(s, loc, content) {
130
+ if (loc.start.offset === loc.end.offset) {
131
+ s.appendRight(loc.start.offset, content);
132
+ }
133
+ else {
134
+ s.overwrite(loc.start.offset, loc.end.offset, content);
135
+ }
136
+ }
@@ -1,5 +1,6 @@
1
1
  import type { Plugin } from 'vite';
2
- import { Injects } from '../../../uni_modules';
2
+ import { type Injects, parseUniExtApis } from '../../../uni_modules';
3
+ export declare const parseUniExtApisOnce: typeof parseUniExtApis;
3
4
  export declare function uniUTSExtApiReplace(): Plugin;
4
5
  /**
5
6
  * { 'uni.getBatteryInfo': ['@/uni_modules/uni-getbatteryinfo/utssdk/web/index.uts','getBatteryInfo'] }
@@ -3,16 +3,16 @@ 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.injectsToAutoImports = exports.uniUTSExtApiReplace = void 0;
6
+ exports.injectsToAutoImports = exports.uniUTSExtApiReplace = exports.parseUniExtApisOnce = void 0;
7
7
  const shared_1 = require("@vue/shared");
8
8
  const uni_shared_1 = require("@dcloudio/uni-shared");
9
9
  const vite_1 = __importDefault(require("unplugin-auto-import/vite"));
10
10
  const uni_modules_1 = require("../../../uni_modules");
11
11
  const url_1 = require("../../utils/url");
12
12
  const escape = (str) => str.replace(/[-[\]/{}()*+?.\\^$|]/g, '\\$&');
13
- const parseUniExtApisOnce = (0, uni_shared_1.once)(uni_modules_1.parseUniExtApis);
13
+ exports.parseUniExtApisOnce = (0, uni_shared_1.once)(uni_modules_1.parseUniExtApis);
14
14
  function uniUTSExtApiReplace() {
15
- const injects = parseUniExtApisOnce(true, process.env.UNI_UTS_PLATFORM, 'javascript');
15
+ const injects = (0, exports.parseUniExtApisOnce)(true, process.env.UNI_UTS_PLATFORM, process.env.UNI_UTS_TARGET_LANGUAGE);
16
16
  const injectApis = Object.keys(injects);
17
17
  const firstPass = new RegExp(`(?:${injectApis.map(escape).join('|')})`, 'g');
18
18
  return {
@@ -20,13 +20,12 @@ function uniUTSExtApiReplace() {
20
20
  configResolved(config) {
21
21
  const index = config.plugins.findIndex((p) => p.name === 'uts');
22
22
  if (index > -1) {
23
- const injects = parseUniExtApisOnce(true, process.env.UNI_UTS_PLATFORM, 'javascript');
24
23
  if (Object.keys(injects).length) {
25
24
  // @ts-expect-error
26
25
  config.plugins.splice(index, 0, (0, vite_1.default)({
27
26
  include: [/\.[u]?ts$/, /\.[u]?vue/],
28
27
  exclude: [/[\\/]\.git[\\/]/],
29
- imports: injectsToAutoImports(parseUniExtApisOnce(true, process.env.UNI_UTS_PLATFORM, 'javascript')),
28
+ imports: injectsToAutoImports(injects),
30
29
  dts: false,
31
30
  }));
32
31
  }
@@ -6,7 +6,7 @@ interface UniUTSPluginOptions {
6
6
  }
7
7
  export declare const utsPlugins: Set<string>;
8
8
  export declare function uniUTSUniModulesPlugin(options?: UniUTSPluginOptions): Plugin;
9
- export declare function buildUniExtApiProviders(): Promise<void>;
9
+ export declare function buildUniExtApis(): Promise<void>;
10
10
  export declare function resolveExtApiProvider(pkg: Record<string, any>): {
11
11
  name?: string | undefined;
12
12
  plugin?: string | undefined;
@@ -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.resolveExtApiProvider = exports.buildUniExtApiProviders = exports.uniUTSUniModulesPlugin = exports.utsPlugins = void 0;
6
+ exports.resolveExtApiProvider = exports.buildUniExtApis = exports.uniUTSUniModulesPlugin = exports.utsPlugins = void 0;
7
7
  const fs_1 = __importDefault(require("fs"));
8
8
  const path_1 = __importDefault(require("path"));
9
9
  const uni_shared_1 = require("@dcloudio/uni-shared");
@@ -19,7 +19,7 @@ exports.utsPlugins = new Set();
19
19
  let uniExtApiCompiler = async () => { };
20
20
  function uniUTSUniModulesPlugin(options = {}) {
21
21
  process.env.UNI_UTS_USING_ROLLUP = 'true';
22
- const compilePlugin = (pluginDir) => {
22
+ const compilePlugin = async (pluginDir) => {
23
23
  exports.utsPlugins.add(path_1.default.basename(pluginDir));
24
24
  const pkgJson = require(path_1.default.join(pluginDir, 'package.json'));
25
25
  const extApiProvider = resolveExtApiProvider(pkgJson);
@@ -30,12 +30,21 @@ function uniUTSUniModulesPlugin(options = {}) {
30
30
  uniExtApiProviderServicePlugin = extApiProvider.servicePlugin;
31
31
  }
32
32
  }
33
- return (0, uts_1.resolveUTSCompiler)().compile(pluginDir, {
33
+ const compiler = (0, uts_1.resolveUTSCompiler)();
34
+ // 处理依赖的 uts 插件
35
+ const deps = (0, uni_modules_1.parseUTSModuleDeps)(pkgJson.uni_modules?.dependencies || [], process.env.UNI_INPUT_DIR);
36
+ if (deps.length) {
37
+ for (const dep of deps) {
38
+ await compilePlugin(path_1.default.resolve(process.env.UNI_INPUT_DIR, 'uni_modules', dep));
39
+ }
40
+ }
41
+ return compiler.compile(pluginDir, {
34
42
  isX: !!options.x,
35
43
  isSingleThread: !!options.isSingleThread,
36
44
  isPlugin: true,
37
45
  extApis: options.extApis,
38
46
  sourceMap: process.env.NODE_ENV === 'development',
47
+ uni_modules: deps,
39
48
  transform: {
40
49
  uniExtApiProviderName: extApiProvider?.name,
41
50
  uniExtApiProviderService: extApiProvider?.service,
@@ -44,8 +53,8 @@ function uniUTSUniModulesPlugin(options = {}) {
44
53
  });
45
54
  };
46
55
  uniExtApiCompiler = async () => {
47
- // 获取 provider 扩展
48
- const plugins = (0, uni_modules_1.getUniExtApiProviders)().filter((provider) => !exports.utsPlugins.has(provider.plugin));
56
+ // 获取 provider 扩展(编译所有uni)
57
+ const plugins = (0, uni_modules_1.getUniExtApiPlugins)().filter((provider) => !exports.utsPlugins.has(provider.plugin));
49
58
  for (const plugin of plugins) {
50
59
  const result = await compilePlugin(path_1.default.resolve(process.env.UNI_INPUT_DIR, 'uni_modules', plugin.plugin));
51
60
  if (result) {
@@ -66,6 +75,10 @@ function uniUTSUniModulesPlugin(options = {}) {
66
75
  }
67
76
  const module = (0, uts_1.resolveUTSAppModule)(id, importer ? path_1.default.dirname(importer) : process.env.UNI_INPUT_DIR, options.x !== true);
68
77
  if (module) {
78
+ // app-js 会直接返回 index.uts 路径,不需要 uts-proxy
79
+ if (module.endsWith('.uts')) {
80
+ return module;
81
+ }
69
82
  // prefix the polyfill id with \0 to tell other plugins not to try to load or transform it
70
83
  return module + '?uts-proxy';
71
84
  }
@@ -124,10 +137,10 @@ function uniUTSUniModulesPlugin(options = {}) {
124
137
  };
125
138
  }
126
139
  exports.uniUTSUniModulesPlugin = uniUTSUniModulesPlugin;
127
- async function buildUniExtApiProviders() {
140
+ async function buildUniExtApis() {
128
141
  await uniExtApiCompiler();
129
142
  }
130
- exports.buildUniExtApiProviders = buildUniExtApiProviders;
143
+ exports.buildUniExtApis = buildUniExtApis;
131
144
  function resolveExtApiProvider(pkg) {
132
145
  const provider = pkg.uni_modules?.['uni-ext-api']?.provider;
133
146
  if (provider?.service) {