@dcloudio/uni-cli-shared 3.0.0-alpha-3021320211109002 → 3.0.0-alpha-3021320211115001

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 (107) hide show
  1. package/dist/constants.d.ts +3 -0
  2. package/dist/constants.js +4 -1
  3. package/dist/easycom.d.ts +7 -1
  4. package/dist/easycom.js +25 -6
  5. package/dist/env/define.d.ts +3 -0
  6. package/dist/env/define.js +6 -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/hbx/alias.js +9 -1
  12. package/dist/hbx/env.js +4 -1
  13. package/dist/hbx/index.js +0 -7
  14. package/dist/hbx/log.d.ts +2 -0
  15. package/dist/hbx/log.js +36 -2
  16. package/dist/index.d.ts +4 -2
  17. package/dist/index.js +4 -2
  18. package/dist/json/app/manifest/confusion.d.ts +3 -0
  19. package/dist/json/app/manifest/confusion.js +56 -14
  20. package/dist/json/app/manifest/env.d.ts +1 -1
  21. package/dist/json/app/manifest/index.d.ts +1 -0
  22. package/dist/json/app/manifest/index.js +5 -1
  23. package/dist/json/app/manifest/nvue.d.ts +3 -3
  24. package/dist/json/app/pages/index.d.ts +0 -1
  25. package/dist/json/app/pages/index.js +0 -11
  26. package/dist/json/manifest.d.ts +1 -1
  27. package/dist/json/manifest.js +9 -3
  28. package/dist/json/mp/index.d.ts +1 -0
  29. package/dist/json/mp/index.js +11 -0
  30. package/dist/json/mp/jsonFile.d.ts +8 -6
  31. package/dist/json/mp/jsonFile.js +68 -16
  32. package/dist/json/mp/pages.d.ts +1 -0
  33. package/dist/json/mp/pages.js +17 -3
  34. package/dist/json/mp/types.d.ts +1 -0
  35. package/dist/json/pages.js +0 -4
  36. package/dist/logs/console.js +5 -2
  37. package/dist/logs/format.js +6 -0
  38. package/dist/messages/index.d.ts +3 -0
  39. package/dist/messages/index.js +3 -0
  40. package/dist/mp/constants.d.ts +2 -0
  41. package/dist/mp/constants.js +5 -0
  42. package/dist/mp/event.d.ts +2 -1
  43. package/dist/mp/event.js +18 -3
  44. package/dist/mp/imports.d.ts +5 -0
  45. package/dist/mp/imports.js +63 -0
  46. package/dist/mp/index.d.ts +5 -0
  47. package/dist/mp/index.js +7 -0
  48. package/dist/mp/nvue.d.ts +1 -0
  49. package/dist/mp/nvue.js +18 -0
  50. package/dist/mp/style.d.ts +1 -0
  51. package/dist/mp/style.js +9 -0
  52. package/dist/mp/template.d.ts +55 -0
  53. package/dist/mp/template.js +73 -0
  54. package/dist/mp/transformImports.d.ts +14 -0
  55. package/dist/mp/transformImports.js +175 -0
  56. package/dist/postcss/plugins/stylePluginScoped.d.ts +1 -1
  57. package/dist/postcss/plugins/uniapp.d.ts +1 -1
  58. package/dist/postcss/plugins/uniapp.js +51 -21
  59. package/dist/preprocess/context.js +1 -0
  60. package/dist/utils.d.ts +9 -1
  61. package/dist/utils.js +93 -8
  62. package/dist/vite/features.d.ts +1 -1
  63. package/dist/vite/index.d.ts +2 -3
  64. package/dist/vite/plugins/copy.d.ts +1 -1
  65. package/dist/vite/plugins/cssScoped.d.ts +1 -1
  66. package/dist/vite/plugins/inject.d.ts +1 -1
  67. package/dist/vite/plugins/inject.js +2 -2
  68. package/dist/vite/plugins/vitejs/config.d.ts +1 -1
  69. package/dist/vite/plugins/vitejs/index.d.ts +1 -1
  70. package/dist/vite/plugins/vitejs/plugin.d.ts +1 -1
  71. package/dist/vite/plugins/vitejs/plugins/asset.d.ts +1 -1
  72. package/dist/vite/plugins/vitejs/plugins/asset.js +28 -21
  73. package/dist/vite/plugins/vitejs/plugins/css.d.ts +4 -4
  74. package/dist/vite/plugins/vitejs/plugins/css.js +15 -24
  75. package/dist/vite/plugins/vitejs/server/moduleGraph.d.ts +1 -1
  76. package/dist/vite/plugins/vitejs/server/moduleGraph.js +0 -3
  77. package/dist/vite/utils/ast.d.ts +1 -1
  78. package/dist/vite/utils/index.d.ts +1 -1
  79. package/dist/vite/utils/plugin.d.ts +4 -4
  80. package/dist/vite/utils/plugin.js +2 -2
  81. package/dist/vue/index.d.ts +2 -0
  82. package/dist/vue/index.js +14 -0
  83. package/dist/vue/transforms/index.d.ts +10 -0
  84. package/dist/vue/transforms/index.js +36 -0
  85. package/dist/vue/transforms/transformComponent.d.ts +3 -0
  86. package/dist/vue/transforms/transformComponent.js +26 -0
  87. package/dist/vue/transforms/transformEvent.d.ts +2 -0
  88. package/dist/vue/transforms/transformEvent.js +22 -0
  89. package/dist/vue/transforms/transformPageHead.d.ts +2 -0
  90. package/dist/vue/transforms/transformPageHead.js +11 -0
  91. package/dist/vue/transforms/transformRef.d.ts +2 -0
  92. package/dist/vue/transforms/transformRef.js +32 -0
  93. package/dist/vue/transforms/transformTag.d.ts +2 -0
  94. package/dist/vue/transforms/transformTag.js +18 -0
  95. package/dist/vue/transforms/vModel.d.ts +12 -0
  96. package/dist/vue/transforms/vModel.js +33 -0
  97. package/dist/vue/transforms/vOn.d.ts +15 -0
  98. package/dist/vue/transforms/vOn.js +88 -0
  99. package/dist/vue/utils.d.ts +9 -0
  100. package/dist/vue/utils.js +66 -0
  101. package/lib/nvue.css +34 -0
  102. package/package.json +27 -6
  103. package/LICENSE +0 -202
  104. package/dist/json/app/pages/nvue.d.ts +0 -1
  105. package/dist/json/app/pages/nvue.js +0 -88
  106. package/dist/renderjs.d.ts +0 -16
  107. package/dist/renderjs.js +0 -44
@@ -1,18 +1,70 @@
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);
9
- }
10
- exports.addPageJson = addPageJson;
11
- function addComponentJson(filename, json) {
12
- exports.jsonComponentsCache.set(filename, json);
13
- }
14
- exports.addComponentJson = addComponentJson;
15
- function addUsingComponents(filename, json) {
16
- exports.jsonUsingComponentsCache.set(filename, json);
17
- }
18
- exports.addUsingComponents = addUsingComponents;
3
+ exports.addMiniProgramUsingComponents = exports.addMiniProgramComponentJson = exports.addMiniProgramPageJson = exports.addMiniProgramAppJson = exports.findChangedJsonFiles = exports.normalizeJsonFilename = exports.hasJsonFile = exports.isPageFile = 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 isPageFile(file) {
12
+ return jsonPagesCache.has((0, utils_1.removeExt)(file));
13
+ }
14
+ exports.isPageFile = isPageFile;
15
+ function hasJsonFile(filename) {
16
+ return (filename === 'app' ||
17
+ jsonPagesCache.has(filename) ||
18
+ jsonComponentsCache.has(filename));
19
+ }
20
+ exports.hasJsonFile = hasJsonFile;
21
+ function normalizeJsonFilename(filename) {
22
+ return (0, utils_1.normalizeNodeModules)(filename);
23
+ }
24
+ exports.normalizeJsonFilename = normalizeJsonFilename;
25
+ function findChangedJsonFiles() {
26
+ const changedJsonFiles = new Map();
27
+ function findChangedFile(filename, json) {
28
+ const newJson = (0, shared_1.extend)({}, json);
29
+ if (!newJson.usingComponents) {
30
+ newJson.usingComponents = {};
31
+ }
32
+ (0, shared_1.extend)(newJson.usingComponents, jsonUsingComponentsCache.get(filename));
33
+ const usingComponents = newJson.usingComponents;
34
+ // 格式化为相对路径,这样作为分包也可以直接运行
35
+ Object.keys(usingComponents).forEach((name) => {
36
+ usingComponents[name] = (0, utils_1.relativeFile)(filename, usingComponents[name].slice(1));
37
+ });
38
+ const jsonStr = JSON.stringify(newJson, null, 2);
39
+ if (jsonFilesCache.get(filename) !== jsonStr) {
40
+ changedJsonFiles.set(filename, jsonStr);
41
+ jsonFilesCache.set(filename, jsonStr);
42
+ }
43
+ }
44
+ function findChangedFiles(jsonsCache) {
45
+ for (const name of jsonsCache.keys()) {
46
+ findChangedFile(name, jsonsCache.get(name));
47
+ }
48
+ }
49
+ findChangedFile('app', appJsonCache);
50
+ findChangedFiles(jsonPagesCache);
51
+ findChangedFiles(jsonComponentsCache);
52
+ return changedJsonFiles;
53
+ }
54
+ exports.findChangedJsonFiles = findChangedJsonFiles;
55
+ function addMiniProgramAppJson(appJson) {
56
+ appJsonCache = appJson;
57
+ }
58
+ exports.addMiniProgramAppJson = addMiniProgramAppJson;
59
+ function addMiniProgramPageJson(filename, json) {
60
+ jsonPagesCache.set(filename, json);
61
+ }
62
+ exports.addMiniProgramPageJson = addMiniProgramPageJson;
63
+ function addMiniProgramComponentJson(filename, json) {
64
+ jsonComponentsCache.set(filename, json);
65
+ }
66
+ exports.addMiniProgramComponentJson = addMiniProgramComponentJson;
67
+ function addMiniProgramUsingComponents(filename, json) {
68
+ jsonUsingComponentsCache.set(filename, json);
69
+ }
70
+ 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,32 @@ 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
+ const windowOptions = {};
38
+ if (platform === 'mp-baidu') {
39
+ // 仅百度小程序需要页面配置 component:true
40
+ // 快手小程序反而不能配置 component:true,故不能统一添加,目前硬编码处理
41
+ windowOptions.component = true;
42
+ }
43
+ pageJsons[pagePath] = (0, shared_1.extend)(windowOptions, (0, utils_1.parseWindowOptions)(style, platform, windowOptionsMap));
31
44
  }
32
45
  // pages
33
46
  (0, pages_1.validatePages)(pagesJson, jsonStr);
@@ -65,7 +78,7 @@ function parsePagesJson(jsonStr, platform, { debug, darkmode, networkTimeout, su
65
78
  }
66
79
  // tabBar
67
80
  if (pagesJson.tabBar) {
68
- const tabBar = (0, utils_1.parseTabBar)(pagesJson.tabBar, platform);
81
+ const tabBar = (0, utils_1.parseTabBar)(pagesJson.tabBar, platform, tabBarOptionsMap, tabBarItemOptionsMap);
69
82
  if (tabBar) {
70
83
  appJson.tabBar = tabBar;
71
84
  }
@@ -89,5 +102,6 @@ function parsePagesJson(jsonStr, platform, { debug, darkmode, networkTimeout, su
89
102
  return {
90
103
  appJson,
91
104
  pageJsons,
105
+ nvuePages,
92
106
  };
93
107
  }
@@ -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;
@@ -10,7 +10,6 @@ const shared_1 = require("@vue/shared");
10
10
  const uni_shared_1 = require("@dcloudio/uni-shared");
11
11
  const utils_1 = require("../utils");
12
12
  const json_1 = require("./json");
13
- const pages_1 = require("./app/pages");
14
13
  const parsePagesJson = (inputDir, platform, normalize = true) => {
15
14
  const jsonStr = fs_1.default.readFileSync(path_1.default.join(inputDir, 'pages.json'), 'utf8');
16
15
  if (normalize) {
@@ -55,9 +54,6 @@ function normalizePagesJson(jsonStr, platform, { subpackages, } = { subpackages:
55
54
  }
56
55
  // pageStyle
57
56
  normalizePages(pagesJson.pages, platform);
58
- if (platform === 'app' && process.env.UNI_NVUE_COMPILER !== 'vue') {
59
- (0, pages_1.initWebpackNVueEntry)(pagesJson.pages);
60
- }
61
57
  // globalStyle
62
58
  pagesJson.globalStyle = normalizePageStyle(null, pagesJson.globalStyle, platform);
63
59
  // tabBar
@@ -1,14 +1,17 @@
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.rewriteConsoleExpr = void 0;
4
- const compiler_sfc_1 = require("@vue/compiler-sfc");
7
+ const magic_string_1 = __importDefault(require("magic-string"));
5
8
  const utils_1 = require("../utils");
6
9
  const F = '__f__';
7
10
  function rewriteConsoleExpr(filename, code) {
8
11
  filename = (0, utils_1.normalizePath)(filename);
9
12
  const re = /(console\.(log|info|debug|warn|error))\(([^)]+)\)/g;
10
13
  const locate = getLocator(code);
11
- const s = new compiler_sfc_1.MagicString(code);
14
+ const s = new magic_string_1.default(code);
12
15
  let match;
13
16
  while ((match = re.exec(code))) {
14
17
  const [, expr, type] = match;
@@ -12,6 +12,12 @@ const initErrFormattersOnce = (0, uni_shared_1.once)(() => {
12
12
  if ((0, env_1.isInHBuilderX)()) {
13
13
  errFormatters.push(alias_1.moduleAliasFormatter);
14
14
  }
15
+ if ((0, env_1.runByHBuilderX)()) {
16
+ errFormatters.push(log_1.HBuilderXFileFormatter);
17
+ }
18
+ else {
19
+ errFormatters.push(log_1.FilenameFormatter);
20
+ }
15
21
  });
16
22
  const initInfoFormattersOnce = (0, uni_shared_1.once)(() => {
17
23
  if ((0, env_1.isInHBuilderX)()) {
@@ -13,4 +13,7 @@ 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;
18
+ 'mp.360.unsupported': string;
16
19
  };
@@ -16,4 +16,7 @@ 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}需要两个参数',
21
+ 'mp.360.unsupported': 'vue3暂不支持360小程序',
19
22
  };
@@ -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;
@@ -0,0 +1,18 @@
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.genNVueCssCode = void 0;
7
+ const fs_1 = __importDefault(require("fs"));
8
+ const path_1 = __importDefault(require("path"));
9
+ const nvue_1 = require("../json/app/manifest/nvue");
10
+ function genNVueCssCode(manifestJson) {
11
+ let nvueCssCode = fs_1.default.readFileSync(path_1.default.resolve(__dirname, '../../lib/nvue.css'), 'utf8');
12
+ const flexDirection = (0, nvue_1.getNVueFlexDirection)(manifestJson);
13
+ if (flexDirection !== 'column') {
14
+ nvueCssCode = nvueCssCode.replace('column', flexDirection);
15
+ }
16
+ return nvueCssCode;
17
+ }
18
+ exports.genNVueCssCode = genNVueCssCode;
@@ -0,0 +1 @@
1
+ export declare function transformScopedCss(cssCode: string): string;
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.transformScopedCss = void 0;
4
+ function transformScopedCss(cssCode) {
5
+ return cssCode.replace(/\[(data-v-[a-f0-9]{8})\]/gi, (_, scopedId) => {
6
+ return '.' + scopedId;
7
+ });
8
+ }
9
+ exports.transformScopedCss = transformScopedCss;
@@ -0,0 +1,55 @@
1
+ import { EmittedAsset } from 'rollup';
2
+ export interface MiniProgramCompilerOptions {
3
+ /**
4
+ * 需要延迟渲染的组件,通常是某个组件的某个事件会立刻触发,需要延迟到首次 render 之后,比如微信 editor 的 ready 事件,快手 switch 的 change
5
+ */
6
+ lazyElement?: {
7
+ [name: string]: string[];
8
+ };
9
+ event?: {
10
+ format(name: string, opts: {
11
+ isCatch?: boolean;
12
+ isCapture?: boolean;
13
+ isComponent?: boolean;
14
+ }): string;
15
+ };
16
+ class: {
17
+ /**
18
+ * 是否支持绑定 array 类型
19
+ */
20
+ array: boolean;
21
+ };
22
+ slot: {
23
+ /**
24
+ * 是否支持 $slots.default 访问
25
+ */
26
+ $slots?: boolean;
27
+ /**
28
+ * 是否支持后备内容
29
+ */
30
+ fallbackContent?: boolean;
31
+ /**
32
+ * 是否支持动态插槽名
33
+ */
34
+ dynamicSlotNames?: boolean;
35
+ };
36
+ filter?: {
37
+ lang: string;
38
+ };
39
+ directive: string;
40
+ emitFile?: (emittedFile: EmittedAsset) => string;
41
+ }
42
+ export interface MiniProgramFilterOptions {
43
+ id: string;
44
+ type: string;
45
+ name: string;
46
+ src?: string;
47
+ code: string;
48
+ }
49
+ declare type GenFilterFn = (filter: MiniProgramFilterOptions, filename: string) => string | void;
50
+ export declare function findMiniProgramTemplateFiles(genFilter?: GenFilterFn): Record<string, string>;
51
+ export declare function clearMiniProgramTemplateFiles(): void;
52
+ export declare function addMiniProgramTemplateFile(filename: string, code: string): void;
53
+ export declare function clearMiniProgramTemplateFilter(filename: string): void;
54
+ export declare function addMiniProgramTemplateFilter(filename: string, filter: MiniProgramFilterOptions): void;
55
+ export {};
@@ -0,0 +1,73 @@
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.addMiniProgramTemplateFilter = exports.clearMiniProgramTemplateFilter = exports.addMiniProgramTemplateFile = exports.clearMiniProgramTemplateFiles = exports.findMiniProgramTemplateFiles = void 0;
7
+ const path_1 = __importDefault(require("path"));
8
+ const uni_shared_1 = require("@dcloudio/uni-shared");
9
+ const utils_1 = require("../utils");
10
+ const templateFilesCache = new Map();
11
+ const templateFiltersCache = new Map();
12
+ function relativeFilterFilename(filename, filter) {
13
+ if (!filter.src) {
14
+ return '';
15
+ }
16
+ return ('./' +
17
+ (0, utils_1.normalizeMiniProgramFilename)(path_1.default.relative(path_1.default.dirname(filename), filter.src)));
18
+ }
19
+ function findMiniProgramTemplateFiles(genFilter) {
20
+ const files = Object.create(null);
21
+ templateFilesCache.forEach((code, filename) => {
22
+ if (!genFilter) {
23
+ files[filename] = code;
24
+ }
25
+ else {
26
+ const filters = getMiniProgramTemplateFilters(filename);
27
+ if (filters && filters.length) {
28
+ files[filename] =
29
+ filters
30
+ .map((filter) => genFilter(filter, relativeFilterFilename(filename, filter)))
31
+ .join(uni_shared_1.LINEFEED) +
32
+ uni_shared_1.LINEFEED +
33
+ code;
34
+ }
35
+ else {
36
+ files[filename] = code;
37
+ }
38
+ }
39
+ });
40
+ return files;
41
+ }
42
+ exports.findMiniProgramTemplateFiles = findMiniProgramTemplateFiles;
43
+ function clearMiniProgramTemplateFiles() {
44
+ templateFilesCache.clear();
45
+ }
46
+ exports.clearMiniProgramTemplateFiles = clearMiniProgramTemplateFiles;
47
+ function addMiniProgramTemplateFile(filename, code) {
48
+ templateFilesCache.set(filename, code);
49
+ }
50
+ exports.addMiniProgramTemplateFile = addMiniProgramTemplateFile;
51
+ function getMiniProgramTemplateFilters(filename) {
52
+ return templateFiltersCache.get(filename);
53
+ }
54
+ function clearMiniProgramTemplateFilter(filename) {
55
+ templateFiltersCache.delete(filename);
56
+ }
57
+ exports.clearMiniProgramTemplateFilter = clearMiniProgramTemplateFilter;
58
+ function addMiniProgramTemplateFilter(filename, filter) {
59
+ const filters = templateFiltersCache.get(filename);
60
+ if (filters) {
61
+ const filterIndex = filters.findIndex((f) => f.id === filter.id);
62
+ if (filterIndex > -1) {
63
+ filters.splice(filterIndex, 1, filter);
64
+ }
65
+ else {
66
+ filters.push(filter);
67
+ }
68
+ }
69
+ else {
70
+ templateFiltersCache.set(filename, [filter]);
71
+ }
72
+ }
73
+ exports.addMiniProgramTemplateFilter = addMiniProgramTemplateFilter;
@@ -0,0 +1,14 @@
1
+ import { ParserPlugin } from '@babel/parser';
2
+ import { PluginContext } from 'rollup';
3
+ interface TransformVueComponentImportsOptions {
4
+ root: string;
5
+ global?: boolean;
6
+ resolve: PluginContext['resolve'];
7
+ dynamicImport: (name: string, source: string) => string;
8
+ babelParserPlugins?: ParserPlugin[];
9
+ }
10
+ export declare function transformVueComponentImports(code: string, importer: string, { root, resolve, global, dynamicImport, babelParserPlugins, }: TransformVueComponentImportsOptions): Promise<{
11
+ code: string;
12
+ usingComponents: Record<string, string>;
13
+ }>;
14
+ export {};