@dcloudio/uni-cli-shared 3.0.0-alpha-3021120211020001 → 3.0.0-alpha-3021220211102002

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 (70) hide show
  1. package/dist/constants.d.ts +1 -0
  2. package/dist/constants.js +2 -1
  3. package/dist/easycom.d.ts +3 -0
  4. package/dist/easycom.js +22 -2
  5. package/dist/env/define.d.ts +2 -0
  6. package/dist/env/define.js +5 -0
  7. package/dist/exports.d.ts +1 -0
  8. package/dist/exports.js +8 -0
  9. package/dist/filter.d.ts +16 -0
  10. package/dist/filter.js +60 -0
  11. package/dist/index.d.ts +4 -2
  12. package/dist/index.js +4 -2
  13. package/dist/json/app/pages/nvue.js +1 -1
  14. package/dist/json/manifest.d.ts +1 -1
  15. package/dist/json/manifest.js +9 -3
  16. package/dist/json/mp/index.d.ts +1 -0
  17. package/dist/json/mp/index.js +11 -0
  18. package/dist/json/mp/jsonFile.d.ts +7 -6
  19. package/dist/json/mp/jsonFile.js +56 -13
  20. package/dist/json/mp/pages.d.ts +1 -0
  21. package/dist/json/mp/pages.js +13 -3
  22. package/dist/json/mp/types.d.ts +1 -0
  23. package/dist/messages/index.d.ts +2 -0
  24. package/dist/messages/index.js +2 -0
  25. package/dist/mp/constants.d.ts +2 -0
  26. package/dist/mp/constants.js +5 -0
  27. package/dist/mp/event.d.ts +2 -1
  28. package/dist/mp/event.js +18 -3
  29. package/dist/mp/imports.d.ts +5 -0
  30. package/dist/mp/imports.js +63 -0
  31. package/dist/mp/index.d.ts +5 -0
  32. package/dist/mp/index.js +7 -0
  33. package/dist/mp/nvue.d.ts +1 -0
  34. package/dist/mp/nvue.js +18 -0
  35. package/dist/mp/style.d.ts +1 -0
  36. package/dist/mp/style.js +10 -0
  37. package/dist/mp/template.d.ts +49 -0
  38. package/dist/mp/template.js +73 -0
  39. package/dist/mp/transformImports.d.ts +14 -0
  40. package/dist/mp/transformImports.js +175 -0
  41. package/dist/postcss/plugins/uniapp.js +49 -19
  42. package/dist/utils.d.ts +6 -1
  43. package/dist/utils.js +39 -8
  44. package/dist/vite/index.d.ts +2 -3
  45. package/dist/vite/plugins/vitejs/plugins/asset.d.ts +1 -1
  46. package/dist/vite/plugins/vitejs/plugins/asset.js +28 -21
  47. package/dist/vite/plugins/vitejs/plugins/css.d.ts +3 -3
  48. package/dist/vite/plugins/vitejs/plugins/css.js +13 -22
  49. package/dist/vite/utils/plugin.d.ts +3 -3
  50. package/dist/vite/utils/plugin.js +2 -2
  51. package/dist/vue/index.d.ts +2 -0
  52. package/dist/vue/index.js +14 -0
  53. package/dist/vue/transforms/index.d.ts +8 -0
  54. package/dist/vue/transforms/index.js +29 -0
  55. package/dist/vue/transforms/transformComponent.d.ts +3 -0
  56. package/dist/vue/transforms/transformComponent.js +26 -0
  57. package/dist/vue/transforms/transformEvent.d.ts +2 -0
  58. package/dist/vue/transforms/transformEvent.js +22 -0
  59. package/dist/vue/transforms/transformPageHead.d.ts +2 -0
  60. package/dist/vue/transforms/transformPageHead.js +11 -0
  61. package/dist/vue/transforms/transformRef.d.ts +2 -0
  62. package/dist/vue/transforms/transformRef.js +32 -0
  63. package/dist/vue/transforms/transformTag.d.ts +3 -0
  64. package/dist/vue/transforms/transformTag.js +45 -0
  65. package/dist/vue/utils.d.ts +9 -0
  66. package/dist/vue/utils.js +65 -0
  67. package/lib/nvue.css +1 -0
  68. package/package.json +7 -4
  69. package/dist/renderjs.d.ts +0 -16
  70. package/dist/renderjs.js +0 -44
@@ -3,6 +3,7 @@ export declare const EXTNAME_JS: string[];
3
3
  export declare const EXTNAME_VUE: string[];
4
4
  export declare const EXTNAME_VUE_RE: RegExp;
5
5
  export declare const EXTNAME_JS_RE: RegExp;
6
+ export declare const BINDING_COMPONENTS = "__BINDING_COMPONENTS__";
6
7
  export declare const PAGE_EXTNAME_APP: string[];
7
8
  export declare const PAGE_EXTNAME: string[];
8
9
  export declare const H5_API_STYLE_PATH = "@dcloudio/uni-h5/style/api/";
package/dist/constants.js CHANGED
@@ -1,11 +1,12 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.COMMON_EXCLUDE = exports.BASE_COMPONENTS_STYLE_PATH = exports.H5_COMPONENTS_STYLE_PATH = exports.H5_FRAMEWORK_STYLE_PATH = exports.H5_API_STYLE_PATH = exports.PAGE_EXTNAME = exports.PAGE_EXTNAME_APP = exports.EXTNAME_JS_RE = exports.EXTNAME_VUE_RE = exports.EXTNAME_VUE = exports.EXTNAME_JS = exports.PUBLIC_DIR = void 0;
3
+ exports.COMMON_EXCLUDE = exports.BASE_COMPONENTS_STYLE_PATH = exports.H5_COMPONENTS_STYLE_PATH = exports.H5_FRAMEWORK_STYLE_PATH = exports.H5_API_STYLE_PATH = exports.PAGE_EXTNAME = exports.PAGE_EXTNAME_APP = exports.BINDING_COMPONENTS = exports.EXTNAME_JS_RE = exports.EXTNAME_VUE_RE = exports.EXTNAME_VUE = exports.EXTNAME_JS = exports.PUBLIC_DIR = void 0;
4
4
  exports.PUBLIC_DIR = 'static';
5
5
  exports.EXTNAME_JS = ['.js', '.ts', '.jsx', '.tsx'];
6
6
  exports.EXTNAME_VUE = ['.vue', '.nvue'];
7
7
  exports.EXTNAME_VUE_RE = /\.(vue|nvue)$/;
8
8
  exports.EXTNAME_JS_RE = /\.[jt]sx?$/;
9
+ exports.BINDING_COMPONENTS = '__BINDING_COMPONENTS__';
9
10
  // APP 平台解析页面后缀的优先级
10
11
  exports.PAGE_EXTNAME_APP = ['.nvue', '.vue', '.tsx', '.jsx', '.js'];
11
12
  // 其他平台解析页面后缀的优先级
package/dist/easycom.d.ts CHANGED
@@ -20,4 +20,7 @@ export declare function initEasycoms(inputDir: string, platform: UniApp.PLATFORM
20
20
  };
21
21
  export declare const initEasycomsOnce: typeof initEasycoms;
22
22
  export declare function matchEasycom(tag: string): string | false | undefined;
23
+ export declare function addImportDeclaration(importDeclarations: string[], local: string, source: string, imported?: string): string;
24
+ export declare function genResolveEasycomCode(importDeclarations: string[], code: string, name: string): string;
25
+ export declare const UNI_EASYCOM_EXCLUDE: RegExp[];
23
26
  export {};
package/dist/easycom.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.matchEasycom = exports.initEasycomsOnce = exports.initEasycoms = void 0;
6
+ exports.UNI_EASYCOM_EXCLUDE = exports.genResolveEasycomCode = exports.addImportDeclaration = exports.matchEasycom = exports.initEasycomsOnce = exports.initEasycoms = void 0;
7
7
  const fs_1 = __importDefault(require("fs"));
8
8
  const path_1 = __importDefault(require("path"));
9
9
  const debug_1 = __importDefault(require("debug"));
@@ -13,7 +13,7 @@ const uni_shared_1 = require("@dcloudio/uni-shared");
13
13
  const utils_1 = require("./utils");
14
14
  const pages_1 = require("./json/pages");
15
15
  const messages_1 = require("./messages");
16
- const debugEasycom = (0, debug_1.default)('uni:easycom');
16
+ const debugEasycom = (0, debug_1.default)('vite:uni:easycom');
17
17
  const easycoms = [];
18
18
  const easycomsCache = new Map();
19
19
  const easycomsInvalidCache = new Set();
@@ -178,3 +178,23 @@ function initAutoScanEasycoms(dirs, rootDir, extensions) {
178
178
  function normalizeCompath(compath, rootDir) {
179
179
  return (0, utils_1.normalizePath)(path_1.default.relative(rootDir, compath));
180
180
  }
181
+ function addImportDeclaration(importDeclarations, local, source, imported) {
182
+ importDeclarations.push(createImportDeclaration(local, source, imported));
183
+ return local;
184
+ }
185
+ exports.addImportDeclaration = addImportDeclaration;
186
+ function createImportDeclaration(local, source, imported) {
187
+ if (imported) {
188
+ return `import {${imported} as ${local}} from '${source}';`;
189
+ }
190
+ return `import ${local} from '${source}';`;
191
+ }
192
+ const RESOLVE_EASYCOM_IMPORT_CODE = `import { resolveDynamicComponent as __resolveDynamicComponent } from 'vue';import { resolveEasycom } from '@dcloudio/uni-app';`;
193
+ function genResolveEasycomCode(importDeclarations, code, name) {
194
+ if (!importDeclarations.includes(RESOLVE_EASYCOM_IMPORT_CODE)) {
195
+ importDeclarations.push(RESOLVE_EASYCOM_IMPORT_CODE);
196
+ }
197
+ return `resolveEasycom(${code.replace('_resolveComponent', '__resolveDynamicComponent')}, ${name})`;
198
+ }
199
+ exports.genResolveEasycomCode = genResolveEasycomCode;
200
+ exports.UNI_EASYCOM_EXCLUDE = [/App.vue$/, /@dcloudio\/uni-h5/];
@@ -1,8 +1,10 @@
1
1
  export declare function initDefine(stringifyBoolean?: boolean): {
2
2
  'process.env.NODE_ENV': string;
3
+ 'process.env.UNI_DEBUG': string | boolean;
3
4
  'process.env.UNI_APP_ID': string;
4
5
  'process.env.UNI_APP_NAME': string;
5
6
  'process.env.UNI_PLATFORM': string;
7
+ 'process.env.UNI_COMPILER_VERSION': string;
6
8
  'process.env.RUN_BY_HBUILDERX': string | boolean;
7
9
  'process.env.UNI_AUTOMATOR_WS_ENDPOINT': string;
8
10
  'process.env.UNI_CLOUD_PROVIDER': string;
@@ -6,11 +6,16 @@ const json_1 = require("../json");
6
6
  function initDefine(stringifyBoolean = false) {
7
7
  const manifestJson = (0, json_1.parseManifestJsonOnce)(process.env.UNI_INPUT_DIR);
8
8
  const isRunByHBuilderX = (0, env_1.runByHBuilderX)();
9
+ const isDebug = !!manifestJson.debug;
9
10
  return {
10
11
  'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV),
12
+ 'process.env.UNI_DEBUG': stringifyBoolean
13
+ ? JSON.stringify(isDebug)
14
+ : isDebug,
11
15
  'process.env.UNI_APP_ID': JSON.stringify(manifestJson.appid || ''),
12
16
  'process.env.UNI_APP_NAME': JSON.stringify(manifestJson.name || ''),
13
17
  'process.env.UNI_PLATFORM': JSON.stringify(process.env.UNI_PLATFORM),
18
+ 'process.env.UNI_COMPILER_VERSION': JSON.stringify(process.env.UNI_COMPILER_VERSION),
14
19
  'process.env.RUN_BY_HBUILDERX': stringifyBoolean
15
20
  ? JSON.stringify(isRunByHBuilderX)
16
21
  : isRunByHBuilderX,
@@ -0,0 +1 @@
1
+ export { default as chokidar } from 'chokidar';
@@ -0,0 +1,8 @@
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.chokidar = void 0;
7
+ var chokidar_1 = require("chokidar");
8
+ Object.defineProperty(exports, "chokidar", { enumerable: true, get: function () { return __importDefault(chokidar_1).default; } });
@@ -0,0 +1,16 @@
1
+ export declare function isWxs(id: string): boolean;
2
+ export declare function isSjs(id: string): boolean;
3
+ export declare function isRenderjs(id: string): boolean;
4
+ declare type FilterType = 'wxs' | 'renderjs' | 'sjs';
5
+ export declare function parseRenderjs(id: string): {
6
+ type: FilterType;
7
+ name: string;
8
+ filename: string;
9
+ } | {
10
+ readonly type: "";
11
+ readonly name: "";
12
+ readonly filename: "";
13
+ };
14
+ export declare function missingModuleName(type: FilterType, code: string): string;
15
+ export declare function parseFilterNames(lang: string, code: string): string[];
16
+ export {};
package/dist/filter.js ADDED
@@ -0,0 +1,60 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.parseFilterNames = exports.missingModuleName = exports.parseRenderjs = exports.isRenderjs = exports.isSjs = exports.isWxs = void 0;
4
+ const url_1 = require("./vite/utils/url");
5
+ const WXS_RE = /vue&type=wxs/;
6
+ function isWxs(id) {
7
+ return WXS_RE.test(id);
8
+ }
9
+ exports.isWxs = isWxs;
10
+ const SJS_RE = /vue&type=sjs/;
11
+ function isSjs(id) {
12
+ return SJS_RE.test(id);
13
+ }
14
+ exports.isSjs = isSjs;
15
+ const RENDERJS_RE = /vue&type=renderjs/;
16
+ function isRenderjs(id) {
17
+ return RENDERJS_RE.test(id);
18
+ }
19
+ exports.isRenderjs = isRenderjs;
20
+ function parseRenderjs(id) {
21
+ if (isWxs(id) || isRenderjs(id) || isSjs(id)) {
22
+ const { query, filename } = (0, url_1.parseVueRequest)(id);
23
+ return {
24
+ type: query.type,
25
+ name: query.name,
26
+ filename,
27
+ };
28
+ }
29
+ return {
30
+ type: '',
31
+ name: '',
32
+ filename: '',
33
+ };
34
+ }
35
+ exports.parseRenderjs = parseRenderjs;
36
+ function missingModuleName(type, code) {
37
+ return `<script module="missing module name" lang="${type}">
38
+ ${code}
39
+ </script>`;
40
+ }
41
+ exports.missingModuleName = missingModuleName;
42
+ const moduleRE = /module=["'](.*?)["']/;
43
+ function parseFilterNames(lang, code) {
44
+ const names = [];
45
+ const scriptTags = code.match(/<script\b[^>]*>/gm);
46
+ if (!scriptTags) {
47
+ return names;
48
+ }
49
+ const langRE = new RegExp(`lang=["']${lang}["']`);
50
+ scriptTags.forEach((scriptTag) => {
51
+ if (langRE.test(scriptTag)) {
52
+ const matches = scriptTag.match(moduleRE);
53
+ if (matches) {
54
+ names.push(matches[1]);
55
+ }
56
+ }
57
+ });
58
+ return names;
59
+ }
60
+ exports.parseFilterNames = parseFilterNames;
package/dist/index.d.ts CHANGED
@@ -2,8 +2,9 @@ export * from './fs';
2
2
  export * from './mp';
3
3
  export * from './env';
4
4
  export * from './hbx';
5
- export * from './logs';
6
5
  export * from './ssr';
6
+ export * from './vue';
7
+ export * from './logs';
7
8
  export * from './i18n';
8
9
  export * from './deps';
9
10
  export * from './json';
@@ -13,7 +14,8 @@ export * from './easycom';
13
14
  export * from './constants';
14
15
  export * from './preprocess';
15
16
  export * from './postcss';
16
- export * from './renderjs';
17
+ export * from './filter';
17
18
  export * from './esbuild';
18
19
  export { M } from './messages';
20
+ export * from './exports';
19
21
  export { checkUpdate } from './checkUpdate';
package/dist/index.js CHANGED
@@ -15,8 +15,9 @@ __exportStar(require("./fs"), exports);
15
15
  __exportStar(require("./mp"), exports);
16
16
  __exportStar(require("./env"), exports);
17
17
  __exportStar(require("./hbx"), exports);
18
- __exportStar(require("./logs"), exports);
19
18
  __exportStar(require("./ssr"), exports);
19
+ __exportStar(require("./vue"), exports);
20
+ __exportStar(require("./logs"), exports);
20
21
  __exportStar(require("./i18n"), exports);
21
22
  __exportStar(require("./deps"), exports);
22
23
  __exportStar(require("./json"), exports);
@@ -26,9 +27,10 @@ __exportStar(require("./easycom"), exports);
26
27
  __exportStar(require("./constants"), exports);
27
28
  __exportStar(require("./preprocess"), exports);
28
29
  __exportStar(require("./postcss"), exports);
29
- __exportStar(require("./renderjs"), exports);
30
+ __exportStar(require("./filter"), exports);
30
31
  __exportStar(require("./esbuild"), exports);
31
32
  var messages_1 = require("./messages");
32
33
  Object.defineProperty(exports, "M", { enumerable: true, get: function () { return messages_1.M; } });
34
+ __exportStar(require("./exports"), exports);
33
35
  var checkUpdate_1 = require("./checkUpdate");
34
36
  Object.defineProperty(exports, "checkUpdate", { enumerable: true, get: function () { return checkUpdate_1.checkUpdate; } });
@@ -20,7 +20,7 @@ function initWebpackNVueEntry(pages) {
20
20
  if (!path) {
21
21
  return;
22
22
  }
23
- const subNVuePath = (0, utils_1.removeExt)(path.split('?')[0]);
23
+ const subNVuePath = (0, utils_1.removeExt)((0, utils_1.normalizePath)(path.split('?')[0]));
24
24
  process.UNI_NVUE_ENTRY[subNVuePath] = genWebpackBase64Code(genNVueEntryCode(subNVuePath));
25
25
  });
26
26
  });
@@ -1,6 +1,6 @@
1
1
  export declare const parseManifestJson: (inputDir: string) => any;
2
2
  export declare const parseManifestJsonOnce: (inputDir: string) => any;
3
- export declare const parseRpx2UnitOnce: (inputDir: string) => any;
3
+ export declare const parseRpx2UnitOnce: (inputDir: string, platform?: UniApp.PLATFORM) => any;
4
4
  interface CompilerCompatConfig {
5
5
  MODE?: 2 | 3;
6
6
  }
@@ -14,9 +14,15 @@ const parseManifestJson = (inputDir) => {
14
14
  };
15
15
  exports.parseManifestJson = parseManifestJson;
16
16
  exports.parseManifestJsonOnce = (0, uni_shared_1.once)(exports.parseManifestJson);
17
- exports.parseRpx2UnitOnce = (0, uni_shared_1.once)((inputDir) => {
18
- const { h5 } = (0, exports.parseManifestJsonOnce)(inputDir);
19
- return (0, shared_1.extend)({}, uni_shared_1.defaultRpx2Unit, (h5 && h5.rpx) || {});
17
+ exports.parseRpx2UnitOnce = (0, uni_shared_1.once)((inputDir, platform = 'h5') => {
18
+ const rpx2unit = platform === 'h5' || platform === 'app'
19
+ ? uni_shared_1.defaultRpx2Unit
20
+ : uni_shared_1.defaultMiniProgramRpx2Unit;
21
+ const platformOptions = (0, exports.parseManifestJsonOnce)(inputDir)[platform];
22
+ if (platformOptions && platformOptions.rpx) {
23
+ return (0, shared_1.extend)({}, rpx2unit, platformOptions);
24
+ }
25
+ return (0, shared_1.extend)({}, rpx2unit);
20
26
  });
21
27
  function parseCompatConfig(_inputDir) {
22
28
  // 不支持 mode:2
@@ -1,3 +1,4 @@
1
+ export * from './jsonFile';
1
2
  export { AppJson } from './types';
2
3
  export { parseMiniProgramPagesJson } from './pages';
3
4
  export { parseMiniProgramProjectJson } from './project';
@@ -1,6 +1,17 @@
1
1
  "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
+ }) : (function(o, m, k, k2) {
6
+ if (k2 === undefined) k2 = k;
7
+ o[k2] = m[k];
8
+ }));
9
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
10
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
11
+ };
2
12
  Object.defineProperty(exports, "__esModule", { value: true });
3
13
  exports.parseMiniProgramProjectJson = exports.parseMiniProgramPagesJson = void 0;
14
+ __exportStar(require("./jsonFile"), exports);
4
15
  var pages_1 = require("./pages");
5
16
  Object.defineProperty(exports, "parseMiniProgramPagesJson", { enumerable: true, get: function () { return pages_1.parseMiniProgramPagesJson; } });
6
17
  var project_1 = require("./project");
@@ -1,7 +1,8 @@
1
1
  import { ComponentJson, PageWindowOptions, UsingComponents } from './types';
2
- export declare const jsonPagesCache: Map<string, PageWindowOptions>;
3
- export declare const jsonComponentsCache: Map<string, ComponentJson>;
4
- export declare const jsonUsingComponentsCache: Map<string, UsingComponents>;
5
- export declare function addPageJson(filename: string, json: PageWindowOptions): void;
6
- export declare function addComponentJson(filename: string, json: ComponentJson): void;
7
- export declare function addUsingComponents(filename: string, json: UsingComponents): void;
2
+ export declare function hasJsonFile(filename: string): boolean;
3
+ export declare function normalizeJsonFilename(filename: string): string;
4
+ export declare function findChangedJsonFiles(): Map<string, string>;
5
+ export declare function addMiniProgramAppJson(appJson: Record<string, any>): void;
6
+ export declare function addMiniProgramPageJson(filename: string, json: PageWindowOptions): void;
7
+ export declare function addMiniProgramComponentJson(filename: string, json: ComponentJson): void;
8
+ export declare function addMiniProgramUsingComponents(filename: string, json: UsingComponents): void;
@@ -1,18 +1,61 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.addUsingComponents = exports.addComponentJson = exports.addPageJson = exports.jsonUsingComponentsCache = exports.jsonComponentsCache = exports.jsonPagesCache = void 0;
4
- exports.jsonPagesCache = new Map();
5
- exports.jsonComponentsCache = new Map();
6
- exports.jsonUsingComponentsCache = new Map();
7
- function addPageJson(filename, json) {
8
- exports.jsonPagesCache.set(filename, json);
3
+ exports.addMiniProgramUsingComponents = exports.addMiniProgramComponentJson = exports.addMiniProgramPageJson = exports.addMiniProgramAppJson = exports.findChangedJsonFiles = exports.normalizeJsonFilename = exports.hasJsonFile = void 0;
4
+ const shared_1 = require("@vue/shared");
5
+ const utils_1 = require("../../utils");
6
+ let appJsonCache = {};
7
+ const jsonFilesCache = new Map();
8
+ const jsonPagesCache = new Map();
9
+ const jsonComponentsCache = new Map();
10
+ const jsonUsingComponentsCache = new Map();
11
+ function hasJsonFile(filename) {
12
+ return (filename === 'app' ||
13
+ jsonPagesCache.has(filename) ||
14
+ jsonComponentsCache.has(filename));
9
15
  }
10
- exports.addPageJson = addPageJson;
11
- function addComponentJson(filename, json) {
12
- exports.jsonComponentsCache.set(filename, json);
16
+ exports.hasJsonFile = hasJsonFile;
17
+ function normalizeJsonFilename(filename) {
18
+ return (0, utils_1.normalizeNodeModules)(filename);
13
19
  }
14
- exports.addComponentJson = addComponentJson;
15
- function addUsingComponents(filename, json) {
16
- exports.jsonUsingComponentsCache.set(filename, json);
20
+ exports.normalizeJsonFilename = normalizeJsonFilename;
21
+ function findChangedJsonFiles() {
22
+ const changedJsonFiles = new Map();
23
+ function findChangedFile(name, json) {
24
+ const newJson = (0, shared_1.extend)({}, json);
25
+ if (!newJson.usingComponents) {
26
+ newJson.usingComponents = {};
27
+ }
28
+ (0, shared_1.extend)(newJson.usingComponents, jsonUsingComponentsCache.get(name));
29
+ const jsonStr = JSON.stringify(newJson, null, 2);
30
+ if (jsonFilesCache.get(name) !== jsonStr) {
31
+ changedJsonFiles.set(name, jsonStr);
32
+ jsonFilesCache.set(name, jsonStr);
33
+ }
34
+ }
35
+ function findChangedFiles(jsonsCache) {
36
+ for (const name of jsonsCache.keys()) {
37
+ findChangedFile(name, jsonsCache.get(name));
38
+ }
39
+ }
40
+ findChangedFile('app', appJsonCache);
41
+ findChangedFiles(jsonPagesCache);
42
+ findChangedFiles(jsonComponentsCache);
43
+ return changedJsonFiles;
17
44
  }
18
- exports.addUsingComponents = addUsingComponents;
45
+ exports.findChangedJsonFiles = findChangedJsonFiles;
46
+ function addMiniProgramAppJson(appJson) {
47
+ appJsonCache = appJson;
48
+ }
49
+ exports.addMiniProgramAppJson = addMiniProgramAppJson;
50
+ function addMiniProgramPageJson(filename, json) {
51
+ jsonPagesCache.set(filename, json);
52
+ }
53
+ exports.addMiniProgramPageJson = addMiniProgramPageJson;
54
+ function addMiniProgramComponentJson(filename, json) {
55
+ jsonComponentsCache.set(filename, json);
56
+ }
57
+ exports.addMiniProgramComponentJson = addMiniProgramComponentJson;
58
+ function addMiniProgramUsingComponents(filename, json) {
59
+ jsonUsingComponentsCache.set(filename, json);
60
+ }
61
+ exports.addMiniProgramUsingComponents = addMiniProgramUsingComponents;
@@ -11,5 +11,6 @@ interface ParsePagesJsonOptions {
11
11
  export declare function parseMiniProgramPagesJson(jsonStr: string, platform: UniApp.PLATFORM, options?: ParsePagesJsonOptions): {
12
12
  appJson: AppJson;
13
13
  pageJsons: Record<string, PageWindowOptions>;
14
+ nvuePages: string[];
14
15
  };
15
16
  export {};
@@ -4,6 +4,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.parseMiniProgramPagesJson = void 0;
7
+ const fs_1 = __importDefault(require("fs"));
7
8
  const path_1 = __importDefault(require("path"));
8
9
  const shared_1 = require("@vue/shared");
9
10
  const json_1 = require("../json");
@@ -14,20 +15,28 @@ function parseMiniProgramPagesJson(jsonStr, platform, options = { subpackages: f
14
15
  return parsePagesJson(jsonStr, platform, options);
15
16
  }
16
17
  exports.parseMiniProgramPagesJson = parseMiniProgramPagesJson;
17
- function parsePagesJson(jsonStr, platform, { debug, darkmode, networkTimeout, subpackages, windowOptionsMap, } = {
18
+ function parsePagesJson(jsonStr, platform, { debug, darkmode, networkTimeout, subpackages, windowOptionsMap, tabBarOptionsMap, tabBarItemOptionsMap, } = {
18
19
  subpackages: false,
19
20
  }) {
20
21
  const appJson = {
21
22
  pages: [],
22
23
  };
23
24
  const pageJsons = {};
25
+ const nvuePages = [];
24
26
  // preprocess
25
27
  const pagesJson = (0, json_1.parseJson)(jsonStr, true);
26
28
  if (!pagesJson) {
27
29
  throw new Error(`[vite] Error: pages.json parse failed.\n`);
28
30
  }
29
31
  function addPageJson(pagePath, style) {
30
- pageJsons[pagePath] = (0, utils_1.parseWindowOptions)(style, platform, windowOptionsMap);
32
+ const filename = path_1.default.join(process.env.UNI_INPUT_DIR, pagePath);
33
+ if (fs_1.default.existsSync(filename + '.nvue') &&
34
+ !fs_1.default.existsSync(filename + '.vue')) {
35
+ nvuePages.push(pagePath);
36
+ }
37
+ pageJsons[pagePath] = (0, shared_1.extend)({
38
+ component: true,
39
+ }, (0, utils_1.parseWindowOptions)(style, platform, windowOptionsMap));
31
40
  }
32
41
  // pages
33
42
  (0, pages_1.validatePages)(pagesJson, jsonStr);
@@ -65,7 +74,7 @@ function parsePagesJson(jsonStr, platform, { debug, darkmode, networkTimeout, su
65
74
  }
66
75
  // tabBar
67
76
  if (pagesJson.tabBar) {
68
- const tabBar = (0, utils_1.parseTabBar)(pagesJson.tabBar, platform);
77
+ const tabBar = (0, utils_1.parseTabBar)(pagesJson.tabBar, platform, tabBarOptionsMap, tabBarItemOptionsMap);
69
78
  if (tabBar) {
70
79
  appJson.tabBar = tabBar;
71
80
  }
@@ -89,5 +98,6 @@ function parsePagesJson(jsonStr, platform, { debug, darkmode, networkTimeout, su
89
98
  return {
90
99
  appJson,
91
100
  pageJsons,
101
+ nvuePages,
92
102
  };
93
103
  }
@@ -18,6 +18,7 @@ interface ShareWindowOptions {
18
18
  declare type Style = 'v2' | string;
19
19
  declare type RestartStrategy = 'homePage' | 'homePageAndLatestPage' | string;
20
20
  export interface PageWindowOptions extends ShareWindowOptions {
21
+ component: true;
21
22
  disableScroll?: boolean;
22
23
  usingComponents?: UsingComponents;
23
24
  initialRenderingCache?: 'static' | string;
@@ -13,4 +13,6 @@ export declare const M: {
13
13
  'i18n.fallbackLocale.default': string;
14
14
  'i18n.fallbackLocale.missing': string;
15
15
  'easycom.conflict': string;
16
+ 'mp.component.args[0]': string;
17
+ 'mp.component.args[1]': string;
16
18
  };
@@ -16,4 +16,6 @@ exports.M = {
16
16
  'i18n.fallbackLocale.default': '当前应用未在 manifest.json 配置 fallbackLocale,默认使用:{locale}',
17
17
  'i18n.fallbackLocale.missing': '当前应用配置的 fallbackLocale 或 locale 为:{locale},但 locale 目录缺少该语言文件',
18
18
  'easycom.conflict': 'easycom组件冲突:',
19
+ 'mp.component.args[0]': '{0}的第一个参数必须为静态字符串',
20
+ 'mp.component.args[1]': '{0}需要两个参数',
19
21
  };
@@ -0,0 +1,2 @@
1
+ export declare const COMPONENT_ON_LINK = "onVI";
2
+ export declare const COMPONENT_BIND_LINK = "__l";
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.COMPONENT_BIND_LINK = exports.COMPONENT_ON_LINK = void 0;
4
+ exports.COMPONENT_ON_LINK = 'onVI';
5
+ exports.COMPONENT_BIND_LINK = '__l';
@@ -1,4 +1,5 @@
1
- export declare function formatMiniProgramEvent(eventName: string, { isCatch, isCapture, }: {
1
+ export declare function formatMiniProgramEvent(eventName: string, { isCatch, isCapture, isComponent, }: {
2
2
  isCatch?: boolean;
3
3
  isCapture?: boolean;
4
+ isComponent?: boolean;
4
5
  }): string;
package/dist/mp/event.js CHANGED
@@ -1,7 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.formatMiniProgramEvent = void 0;
4
- function formatMiniProgramEvent(eventName, { isCatch, isCapture, }) {
4
+ function formatMiniProgramEvent(eventName, { isCatch, isCapture, isComponent, }) {
5
+ if (!isComponent && eventName === 'click') {
6
+ eventName = 'tap';
7
+ }
5
8
  let eventType = 'bind';
6
9
  if (isCatch) {
7
10
  eventType = 'catch';
@@ -9,7 +12,19 @@ function formatMiniProgramEvent(eventName, { isCatch, isCapture, }) {
9
12
  if (isCapture) {
10
13
  return `capture-${eventType}:${eventName}`;
11
14
  }
12
- // 原生组件不支持 bind:input 等写法,统一使用 bindinput
13
- return `${eventType}${eventName}`;
15
+ // bind:foo-bar
16
+ return eventType + (isSimpleExpr(eventName) ? '' : ':') + eventName;
14
17
  }
15
18
  exports.formatMiniProgramEvent = formatMiniProgramEvent;
19
+ function isSimpleExpr(name) {
20
+ if (name.startsWith('_')) {
21
+ return false;
22
+ }
23
+ if (name.indexOf('-') > -1) {
24
+ return false;
25
+ }
26
+ if (name.indexOf(':') > -1) {
27
+ return false;
28
+ }
29
+ return true;
30
+ }
@@ -0,0 +1,5 @@
1
+ import { PluginContext } from 'rollup';
2
+ import { ImportSpecifier } from 'es-module-lexer';
3
+ export declare function findVueComponentImports(source: string, importer: string, resolve: PluginContext['resolve']): Promise<(ImportSpecifier & {
4
+ i: string;
5
+ })[]>;
@@ -0,0 +1,63 @@
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.findVueComponentImports = void 0;
7
+ const path_1 = __importDefault(require("path"));
8
+ const es_module_lexer_1 = require("es-module-lexer");
9
+ const shared_1 = require("@vue/shared");
10
+ const types_1 = require("@babel/types");
11
+ const parser_1 = require("@babel/parser");
12
+ const constants_1 = require("../constants");
13
+ async function findVueComponentImports(source, importer, resolve) {
14
+ await es_module_lexer_1.init;
15
+ let imports = [];
16
+ // strip UTF-8 BOM
17
+ if (source.charCodeAt(0) === 0xfeff) {
18
+ source = source.slice(1);
19
+ }
20
+ try {
21
+ imports = (0, es_module_lexer_1.parse)(source)[0];
22
+ }
23
+ catch (e) {
24
+ console.error(e);
25
+ }
26
+ if (!imports.length) {
27
+ return [];
28
+ }
29
+ const rewriteImports = [];
30
+ for (let i = 0; i < imports.length; i++) {
31
+ const importSpecifier = imports[i];
32
+ const { n } = importSpecifier;
33
+ if (!n) {
34
+ continue;
35
+ }
36
+ const extname = path_1.default.extname(n);
37
+ // 仅处理没有后缀,或后缀是.vue,.nvue的文件
38
+ if (extname && !constants_1.EXTNAME_VUE.includes(extname)) {
39
+ continue;
40
+ }
41
+ const res = await resolve(n, importer);
42
+ if (!res) {
43
+ continue;
44
+ }
45
+ if (constants_1.EXTNAME_VUE_RE.test(res.id)) {
46
+ const expr = (0, parser_1.parse)(source.slice(importSpecifier.ss, importSpecifier.se), {
47
+ sourceType: 'module',
48
+ }).program.body[0];
49
+ if ((0, types_1.isImportDeclaration)(expr) && expr.specifiers.length === 1) {
50
+ const importDefaultSpecifier = expr.specifiers[0];
51
+ if (!(0, types_1.isImportDefaultSpecifier)(importDefaultSpecifier)) {
52
+ continue;
53
+ }
54
+ rewriteImports.push((0, shared_1.extend)(importSpecifier, {
55
+ n: res.id,
56
+ i: importDefaultSpecifier.local.name,
57
+ }));
58
+ }
59
+ }
60
+ }
61
+ return rewriteImports;
62
+ }
63
+ exports.findVueComponentImports = findVueComponentImports;
@@ -1 +1,6 @@
1
+ export * from './nvue';
1
2
  export * from './event';
3
+ export * from './style';
4
+ export * from './template';
5
+ export * from './constants';
6
+ export { transformVueComponentImports } from './transformImports';
package/dist/mp/index.js CHANGED
@@ -10,4 +10,11 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
10
10
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
11
11
  };
12
12
  Object.defineProperty(exports, "__esModule", { value: true });
13
+ exports.transformVueComponentImports = void 0;
14
+ __exportStar(require("./nvue"), exports);
13
15
  __exportStar(require("./event"), exports);
16
+ __exportStar(require("./style"), exports);
17
+ __exportStar(require("./template"), exports);
18
+ __exportStar(require("./constants"), exports);
19
+ var transformImports_1 = require("./transformImports");
20
+ Object.defineProperty(exports, "transformVueComponentImports", { enumerable: true, get: function () { return transformImports_1.transformVueComponentImports; } });
@@ -0,0 +1 @@
1
+ export declare function genNVueCssCode(manifestJson: Record<string, any>): string;