@dcloudio/uni-cli-shared 0.0.1-nvue3.3030820220125001

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 (236) hide show
  1. package/dist/checkUpdate.d.ts +30 -0
  2. package/dist/checkUpdate.js +243 -0
  3. package/dist/constants.d.ts +19 -0
  4. package/dist/constants.js +43 -0
  5. package/dist/deps.d.ts +19 -0
  6. package/dist/deps.js +39 -0
  7. package/dist/easycom.d.ts +29 -0
  8. package/dist/easycom.js +202 -0
  9. package/dist/env/define.d.ts +15 -0
  10. package/dist/env/define.js +45 -0
  11. package/dist/env/index.d.ts +2 -0
  12. package/dist/env/index.js +8 -0
  13. package/dist/env/provide.d.ts +9 -0
  14. package/dist/env/provide.js +24 -0
  15. package/dist/esbuild.d.ts +3 -0
  16. package/dist/esbuild.js +42 -0
  17. package/dist/exports.d.ts +1 -0
  18. package/dist/exports.js +8 -0
  19. package/dist/filter.d.ts +16 -0
  20. package/dist/filter.js +60 -0
  21. package/dist/fs.d.ts +1 -0
  22. package/dist/fs.js +25 -0
  23. package/dist/hbx/alias.d.ts +5 -0
  24. package/dist/hbx/alias.js +75 -0
  25. package/dist/hbx/env.d.ts +6 -0
  26. package/dist/hbx/env.js +44 -0
  27. package/dist/hbx/index.d.ts +3 -0
  28. package/dist/hbx/index.js +36 -0
  29. package/dist/hbx/log.d.ts +6 -0
  30. package/dist/hbx/log.js +99 -0
  31. package/dist/i18n.d.ts +10 -0
  32. package/dist/i18n.js +94 -0
  33. package/dist/index.d.ts +25 -0
  34. package/dist/index.js +40 -0
  35. package/dist/json/app/index.d.ts +3 -0
  36. package/dist/json/app/index.js +17 -0
  37. package/dist/json/app/manifest/arguments.d.ts +2 -0
  38. package/dist/json/app/manifest/arguments.js +36 -0
  39. package/dist/json/app/manifest/confusion.d.ts +4 -0
  40. package/dist/json/app/manifest/confusion.js +77 -0
  41. package/dist/json/app/manifest/defaultManifestJson.d.ts +1 -0
  42. package/dist/json/app/manifest/defaultManifestJson.js +41 -0
  43. package/dist/json/app/manifest/env.d.ts +3 -0
  44. package/dist/json/app/manifest/env.js +24 -0
  45. package/dist/json/app/manifest/i18n.d.ts +1 -0
  46. package/dist/json/app/manifest/i18n.js +14 -0
  47. package/dist/json/app/manifest/index.d.ts +4 -0
  48. package/dist/json/app/manifest/index.js +49 -0
  49. package/dist/json/app/manifest/launchwebview.d.ts +1 -0
  50. package/dist/json/app/manifest/launchwebview.js +32 -0
  51. package/dist/json/app/manifest/merge.d.ts +1 -0
  52. package/dist/json/app/manifest/merge.js +17 -0
  53. package/dist/json/app/manifest/nvue.d.ts +4 -0
  54. package/dist/json/app/manifest/nvue.js +43 -0
  55. package/dist/json/app/manifest/plus.d.ts +1 -0
  56. package/dist/json/app/manifest/plus.js +83 -0
  57. package/dist/json/app/manifest/safearea.d.ts +1 -0
  58. package/dist/json/app/manifest/safearea.js +28 -0
  59. package/dist/json/app/manifest/splashscreen.d.ts +5 -0
  60. package/dist/json/app/manifest/splashscreen.js +44 -0
  61. package/dist/json/app/manifest/statusbar.d.ts +1 -0
  62. package/dist/json/app/manifest/statusbar.js +14 -0
  63. package/dist/json/app/manifest/tabBar.d.ts +1 -0
  64. package/dist/json/app/manifest/tabBar.js +27 -0
  65. package/dist/json/app/manifest/uniApp.d.ts +1 -0
  66. package/dist/json/app/manifest/uniApp.js +19 -0
  67. package/dist/json/app/pages/code.d.ts +3 -0
  68. package/dist/json/app/pages/code.js +44 -0
  69. package/dist/json/app/pages/definePage.d.ts +2 -0
  70. package/dist/json/app/pages/definePage.js +42 -0
  71. package/dist/json/app/pages/index.d.ts +3 -0
  72. package/dist/json/app/pages/index.js +28 -0
  73. package/dist/json/app/pages/uniConfig.d.ts +1 -0
  74. package/dist/json/app/pages/uniConfig.js +69 -0
  75. package/dist/json/app/pages/uniRoutes.d.ts +1 -0
  76. package/dist/json/app/pages/uniRoutes.js +8 -0
  77. package/dist/json/index.d.ts +5 -0
  78. package/dist/json/index.js +17 -0
  79. package/dist/json/json.d.ts +1 -0
  80. package/dist/json/json.js +9 -0
  81. package/dist/json/manifest.d.ts +28 -0
  82. package/dist/json/manifest.js +64 -0
  83. package/dist/json/mp/index.d.ts +4 -0
  84. package/dist/json/mp/index.js +19 -0
  85. package/dist/json/mp/jsonFile.d.ts +23 -0
  86. package/dist/json/mp/jsonFile.js +127 -0
  87. package/dist/json/mp/pages.d.ts +17 -0
  88. package/dist/json/mp/pages.js +126 -0
  89. package/dist/json/mp/project.d.ts +14 -0
  90. package/dist/json/mp/project.js +81 -0
  91. package/dist/json/mp/types.d.ts +118 -0
  92. package/dist/json/mp/types.js +2 -0
  93. package/dist/json/mp/utils.d.ts +3 -0
  94. package/dist/json/mp/utils.js +66 -0
  95. package/dist/json/pages.d.ts +30 -0
  96. package/dist/json/pages.js +383 -0
  97. package/dist/logs/console.d.ts +4 -0
  98. package/dist/logs/console.js +49 -0
  99. package/dist/logs/format.d.ts +11 -0
  100. package/dist/logs/format.js +82 -0
  101. package/dist/logs/index.d.ts +1 -0
  102. package/dist/logs/index.js +7 -0
  103. package/dist/messages/index.d.ts +20 -0
  104. package/dist/messages/index.js +23 -0
  105. package/dist/mp/ast.d.ts +4 -0
  106. package/dist/mp/ast.js +12 -0
  107. package/dist/mp/constants.d.ts +5 -0
  108. package/dist/mp/constants.js +8 -0
  109. package/dist/mp/event.d.ts +5 -0
  110. package/dist/mp/event.js +35 -0
  111. package/dist/mp/externalClasses.d.ts +5 -0
  112. package/dist/mp/externalClasses.js +42 -0
  113. package/dist/mp/imports.d.ts +12 -0
  114. package/dist/mp/imports.js +72 -0
  115. package/dist/mp/index.d.ts +11 -0
  116. package/dist/mp/index.js +38 -0
  117. package/dist/mp/nvue.d.ts +1 -0
  118. package/dist/mp/nvue.js +18 -0
  119. package/dist/mp/plugin.d.ts +2 -0
  120. package/dist/mp/plugin.js +13 -0
  121. package/dist/mp/style.d.ts +1 -0
  122. package/dist/mp/style.js +9 -0
  123. package/dist/mp/tags.d.ts +1 -0
  124. package/dist/mp/tags.js +117 -0
  125. package/dist/mp/template.d.ts +73 -0
  126. package/dist/mp/template.js +73 -0
  127. package/dist/mp/usingComponents.d.ts +65 -0
  128. package/dist/mp/usingComponents.js +402 -0
  129. package/dist/mp/wxs.d.ts +2 -0
  130. package/dist/mp/wxs.js +55 -0
  131. package/dist/platform.d.ts +2 -0
  132. package/dist/platform.js +31 -0
  133. package/dist/postcss/index.d.ts +10 -0
  134. package/dist/postcss/index.js +19 -0
  135. package/dist/postcss/plugins/stylePluginScoped.d.ts +3 -0
  136. package/dist/postcss/plugins/stylePluginScoped.js +176 -0
  137. package/dist/postcss/plugins/uniapp.d.ts +11 -0
  138. package/dist/postcss/plugins/uniapp.js +110 -0
  139. package/dist/preprocess/context.d.ts +3 -0
  140. package/dist/preprocess/context.js +81 -0
  141. package/dist/preprocess/index.d.ts +9 -0
  142. package/dist/preprocess/index.js +28 -0
  143. package/dist/resolve.d.ts +6 -0
  144. package/dist/resolve.js +102 -0
  145. package/dist/scripts.d.ts +10 -0
  146. package/dist/scripts.js +44 -0
  147. package/dist/ssr.d.ts +4 -0
  148. package/dist/ssr.js +20 -0
  149. package/dist/url.d.ts +2 -0
  150. package/dist/url.js +15 -0
  151. package/dist/utils.d.ts +13 -0
  152. package/dist/utils.js +80 -0
  153. package/dist/vite/features.d.ts +41 -0
  154. package/dist/vite/features.js +191 -0
  155. package/dist/vite/index.d.ts +36 -0
  156. package/dist/vite/index.js +17 -0
  157. package/dist/vite/plugins/console.d.ts +8 -0
  158. package/dist/vite/plugins/console.js +42 -0
  159. package/dist/vite/plugins/copy.d.ts +11 -0
  160. package/dist/vite/plugins/copy.js +51 -0
  161. package/dist/vite/plugins/cssScoped.d.ts +6 -0
  162. package/dist/vite/plugins/cssScoped.js +54 -0
  163. package/dist/vite/plugins/dynamicImportPolyfill.d.ts +2 -0
  164. package/dist/vite/plugins/dynamicImportPolyfill.js +15 -0
  165. package/dist/vite/plugins/index.d.ts +10 -0
  166. package/dist/vite/plugins/index.js +32 -0
  167. package/dist/vite/plugins/inject.d.ts +12 -0
  168. package/dist/vite/plugins/inject.js +207 -0
  169. package/dist/vite/plugins/jsonJs.d.ts +3 -0
  170. package/dist/vite/plugins/jsonJs.js +52 -0
  171. package/dist/vite/plugins/mainJs.d.ts +2 -0
  172. package/dist/vite/plugins/mainJs.js +29 -0
  173. package/dist/vite/plugins/vitejs/config.d.ts +1 -0
  174. package/dist/vite/plugins/vitejs/config.js +2 -0
  175. package/dist/vite/plugins/vitejs/constants.d.ts +8 -0
  176. package/dist/vite/plugins/vitejs/constants.js +11 -0
  177. package/dist/vite/plugins/vitejs/index.d.ts +1 -0
  178. package/dist/vite/plugins/vitejs/index.js +2 -0
  179. package/dist/vite/plugins/vitejs/plugin.d.ts +1 -0
  180. package/dist/vite/plugins/vitejs/plugin.js +2 -0
  181. package/dist/vite/plugins/vitejs/plugins/asset.d.ts +40 -0
  182. package/dist/vite/plugins/vitejs/plugins/asset.js +270 -0
  183. package/dist/vite/plugins/vitejs/plugins/css.d.ts +48 -0
  184. package/dist/vite/plugins/vitejs/plugins/css.js +760 -0
  185. package/dist/vite/plugins/vitejs/server/moduleGraph.d.ts +1 -0
  186. package/dist/vite/plugins/vitejs/server/moduleGraph.js +2 -0
  187. package/dist/vite/plugins/vitejs/utils.d.ts +29 -0
  188. package/dist/vite/plugins/vitejs/utils.js +129 -0
  189. package/dist/vite/utils/ast.d.ts +17 -0
  190. package/dist/vite/utils/ast.js +85 -0
  191. package/dist/vite/utils/index.d.ts +7 -0
  192. package/dist/vite/utils/index.js +23 -0
  193. package/dist/vite/utils/plugin.d.ts +11 -0
  194. package/dist/vite/utils/plugin.js +45 -0
  195. package/dist/vite/utils/url.d.ts +28 -0
  196. package/dist/vite/utils/url.js +69 -0
  197. package/dist/vite/utils/utils.d.ts +3 -0
  198. package/dist/vite/utils/utils.js +14 -0
  199. package/dist/vue/babel.d.ts +3 -0
  200. package/dist/vue/babel.js +17 -0
  201. package/dist/vue/index.d.ts +4 -0
  202. package/dist/vue/index.js +19 -0
  203. package/dist/vue/transforms/index.d.ts +13 -0
  204. package/dist/vue/transforms/index.js +48 -0
  205. package/dist/vue/transforms/templateTransformAssetUrl.d.ts +33 -0
  206. package/dist/vue/transforms/templateTransformAssetUrl.js +150 -0
  207. package/dist/vue/transforms/templateTransformSrcset.d.ts +4 -0
  208. package/dist/vue/transforms/templateTransformSrcset.js +122 -0
  209. package/dist/vue/transforms/templateUtils.d.ts +9 -0
  210. package/dist/vue/transforms/templateUtils.js +41 -0
  211. package/dist/vue/transforms/transformComponent.d.ts +3 -0
  212. package/dist/vue/transforms/transformComponent.js +26 -0
  213. package/dist/vue/transforms/transformEvent.d.ts +2 -0
  214. package/dist/vue/transforms/transformEvent.js +28 -0
  215. package/dist/vue/transforms/transformPageHead.d.ts +2 -0
  216. package/dist/vue/transforms/transformPageHead.js +11 -0
  217. package/dist/vue/transforms/transformRef.d.ts +2 -0
  218. package/dist/vue/transforms/transformRef.js +32 -0
  219. package/dist/vue/transforms/transformTag.d.ts +2 -0
  220. package/dist/vue/transforms/transformTag.js +18 -0
  221. package/dist/vue/transforms/vModel.d.ts +12 -0
  222. package/dist/vue/transforms/vModel.js +33 -0
  223. package/dist/vue/transforms/vOn.d.ts +15 -0
  224. package/dist/vue/transforms/vOn.js +88 -0
  225. package/dist/vue/utils.d.ts +31 -0
  226. package/dist/vue/utils.js +120 -0
  227. package/dist/watcher.d.ts +30 -0
  228. package/dist/watcher.js +92 -0
  229. package/lib/crypto.js +65 -0
  230. package/lib/nvue.css +34 -0
  231. package/lib/preprocess/LICENSE +13 -0
  232. package/lib/preprocess/README.md +410 -0
  233. package/lib/preprocess/lib/preprocess.js +437 -0
  234. package/lib/preprocess/lib/regexrules.js +121 -0
  235. package/lib/preprocess/package.json +68 -0
  236. package/package.json +68 -0
@@ -0,0 +1,402 @@
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.transformDynamicImports = exports.parseScriptDescriptor = exports.parseTemplateDescriptor = exports.updateMiniProgramComponentsByMainFilename = exports.updateMiniProgramGlobalComponents = exports.updateMiniProgramComponentsByTemplateFilename = exports.updateMiniProgramComponentsByScriptFilename = exports.parseMainDescriptor = void 0;
7
+ const types_1 = require("@babel/types");
8
+ const estree_walker_1 = require("estree-walker");
9
+ const magic_string_1 = __importDefault(require("magic-string"));
10
+ const shared_1 = require("@vue/shared");
11
+ const uni_shared_1 = require("@dcloudio/uni-shared");
12
+ const messages_1 = require("../messages");
13
+ const constants_1 = require("../constants");
14
+ const utils_1 = require("../utils");
15
+ const utils_2 = require("../vite/utils");
16
+ const jsonFile_1 = require("../json/mp/jsonFile");
17
+ const mainDescriptors = new Map();
18
+ const scriptDescriptors = new Map();
19
+ const templateDescriptors = new Map();
20
+ function findImportTemplateSource(ast) {
21
+ const importDeclaration = ast.body.find((node) => (0, types_1.isImportDeclaration)(node) &&
22
+ node.source.value.includes('vue&type=template'));
23
+ if (importDeclaration) {
24
+ return importDeclaration.source.value;
25
+ }
26
+ }
27
+ function findImportScriptSource(ast) {
28
+ const importDeclaration = ast.body.find((node) => (0, types_1.isImportDeclaration)(node) && node.source.value.includes('vue&type=script'));
29
+ if (importDeclaration) {
30
+ return importDeclaration.source.value;
31
+ }
32
+ }
33
+ async function resolveSource(filename, source, resolve) {
34
+ if (!source) {
35
+ return;
36
+ }
37
+ const resolveId = await resolve(source, filename);
38
+ if (resolveId) {
39
+ return resolveId.id;
40
+ }
41
+ }
42
+ async function parseMainDescriptor(filename, ast, resolve) {
43
+ const script = await resolveSource(filename, findImportScriptSource(ast), resolve);
44
+ const template = await resolveSource(filename, findImportTemplateSource(ast), resolve);
45
+ const imports = await parseVueComponentImports(filename, ast.body.filter((node) => (0, types_1.isImportDeclaration)(node)), resolve);
46
+ if (!script) {
47
+ // inline script
48
+ await parseScriptDescriptor(filename, ast, { resolve, isExternal: false });
49
+ }
50
+ if (!template) {
51
+ // inline template
52
+ await parseTemplateDescriptor(filename, ast, { resolve, isExternal: false });
53
+ }
54
+ const descriptor = {
55
+ imports,
56
+ script: script ? (0, utils_2.parseVueRequest)(script).filename : filename,
57
+ template: template ? (0, utils_2.parseVueRequest)(template).filename : filename,
58
+ };
59
+ mainDescriptors.set(filename, descriptor);
60
+ return descriptor;
61
+ }
62
+ exports.parseMainDescriptor = parseMainDescriptor;
63
+ function updateMiniProgramComponentsByScriptFilename(scriptFilename, inputDir) {
64
+ const mainFilename = findMainFilenameByScriptFilename(scriptFilename);
65
+ if (mainFilename) {
66
+ updateMiniProgramComponentsByMainFilename(mainFilename, inputDir);
67
+ }
68
+ }
69
+ exports.updateMiniProgramComponentsByScriptFilename = updateMiniProgramComponentsByScriptFilename;
70
+ function updateMiniProgramComponentsByTemplateFilename(templateFilename, inputDir) {
71
+ const mainFilename = findMainFilenameByTemplateFilename(templateFilename);
72
+ if (mainFilename) {
73
+ updateMiniProgramComponentsByMainFilename(mainFilename, inputDir);
74
+ }
75
+ }
76
+ exports.updateMiniProgramComponentsByTemplateFilename = updateMiniProgramComponentsByTemplateFilename;
77
+ function findMainFilenameByScriptFilename(scriptFilename) {
78
+ const keys = [...mainDescriptors.keys()];
79
+ return keys.find((key) => mainDescriptors.get(key).script === scriptFilename);
80
+ }
81
+ function findMainFilenameByTemplateFilename(templateFilename) {
82
+ const keys = [...mainDescriptors.keys()];
83
+ return keys.find((key) => mainDescriptors.get(key).template === templateFilename);
84
+ }
85
+ async function updateMiniProgramGlobalComponents(filename, ast, { inputDir, resolve, }) {
86
+ const { bindingComponents, imports } = await parseGlobalDescriptor(filename, ast, resolve);
87
+ (0, jsonFile_1.addMiniProgramUsingComponents)('app', createUsingComponents(bindingComponents, imports, inputDir));
88
+ return {
89
+ imports,
90
+ };
91
+ }
92
+ exports.updateMiniProgramGlobalComponents = updateMiniProgramGlobalComponents;
93
+ function createUsingComponents(bindingComponents, imports, inputDir) {
94
+ const usingComponents = {};
95
+ imports.forEach(({ source: { value }, specifiers: [specifier] }) => {
96
+ const { name } = specifier.local;
97
+ if (!bindingComponents[name]) {
98
+ return;
99
+ }
100
+ const componentName = (0, shared_1.hyphenate)(bindingComponents[name].tag);
101
+ if (!usingComponents[componentName]) {
102
+ usingComponents[componentName] = (0, uni_shared_1.addLeadingSlash)((0, utils_1.removeExt)((0, utils_1.normalizeMiniProgramFilename)(value, inputDir)));
103
+ }
104
+ });
105
+ return usingComponents;
106
+ }
107
+ function updateMiniProgramComponentsByMainFilename(mainFilename, inputDir) {
108
+ const mainDescriptor = mainDescriptors.get(mainFilename);
109
+ if (!mainDescriptor) {
110
+ return;
111
+ }
112
+ const templateDescriptor = templateDescriptors.get(mainDescriptor.template);
113
+ if (!templateDescriptor) {
114
+ return;
115
+ }
116
+ const scriptDescriptor = scriptDescriptors.get(mainDescriptor.script);
117
+ if (!scriptDescriptor) {
118
+ return;
119
+ }
120
+ const bindingComponents = parseBindingComponents(templateDescriptor.bindingComponents, scriptDescriptor.bindingComponents);
121
+ const imports = parseImports(mainDescriptor.imports, scriptDescriptor.imports, templateDescriptor.imports);
122
+ (0, jsonFile_1.addMiniProgramUsingComponents)((0, utils_1.removeExt)((0, utils_1.normalizeMiniProgramFilename)(mainFilename, inputDir)), createUsingComponents(bindingComponents, imports, inputDir));
123
+ }
124
+ exports.updateMiniProgramComponentsByMainFilename = updateMiniProgramComponentsByMainFilename;
125
+ function findBindingComponent(tag, bindingComponents) {
126
+ return Object.keys(bindingComponents).find((name) => {
127
+ const componentTag = bindingComponents[name].tag;
128
+ const camelName = (0, shared_1.camelize)(componentTag);
129
+ const PascalName = (0, shared_1.capitalize)(camelName);
130
+ return tag === componentTag || tag === camelName || tag === PascalName;
131
+ });
132
+ }
133
+ function normalizeComponentId(id) {
134
+ // _unref(test) => test
135
+ if (id.includes('_unref(')) {
136
+ return id.replace('_unref(', '').replace(')', '');
137
+ }
138
+ // $setup["test"] => test
139
+ if (id.includes('$setup[')) {
140
+ return id.replace('$setup["', '').replace('"', '');
141
+ }
142
+ return id;
143
+ }
144
+ function parseBindingComponents(templateBindingComponents, scriptBindingComponents) {
145
+ const bindingComponents = {};
146
+ Object.keys(templateBindingComponents).forEach((id) => {
147
+ bindingComponents[normalizeComponentId(id)] = templateBindingComponents[id];
148
+ });
149
+ Object.keys(scriptBindingComponents).forEach((id) => {
150
+ const { tag } = scriptBindingComponents[id];
151
+ const name = findBindingComponent(tag, templateBindingComponents);
152
+ if (name) {
153
+ bindingComponents[id] = bindingComponents[name];
154
+ }
155
+ });
156
+ return bindingComponents;
157
+ }
158
+ function parseImports(mainImports, scriptImports, templateImports) {
159
+ const imports = [...mainImports, ...templateImports, ...scriptImports];
160
+ return imports;
161
+ }
162
+ /**
163
+ * 解析 template
164
+ * @param filename
165
+ * @param code
166
+ * @param ast
167
+ * @param options
168
+ * @returns
169
+ */
170
+ async function parseTemplateDescriptor(filename, ast, options) {
171
+ // 外置时查找所有 vue component import
172
+ const imports = options.isExternal
173
+ ? await parseVueComponentImports(filename, ast.body.filter((node) => (0, types_1.isImportDeclaration)(node)), options.resolve)
174
+ : [];
175
+ const descriptor = {
176
+ bindingComponents: findBindingComponents(ast.body),
177
+ imports,
178
+ };
179
+ templateDescriptors.set(filename, descriptor);
180
+ return descriptor;
181
+ }
182
+ exports.parseTemplateDescriptor = parseTemplateDescriptor;
183
+ async function parseGlobalDescriptor(filename, ast, resolve) {
184
+ // 外置时查找所有 vue component import
185
+ const imports = (await parseVueComponentImports(filename, ast.body.filter((node) => (0, types_1.isImportDeclaration)(node)), resolve)).filter((item) => !(0, utils_2.cleanUrl)(item.source.value).endsWith('App.vue'));
186
+ return {
187
+ bindingComponents: parseGlobalComponents(ast),
188
+ imports,
189
+ };
190
+ }
191
+ /**
192
+ * 解析 script
193
+ * @param filename
194
+ * @param code
195
+ * @param ast
196
+ * @param options
197
+ * @returns
198
+ */
199
+ async function parseScriptDescriptor(filename, ast, options) {
200
+ // 外置时查找所有 vue component import
201
+ const imports = options.isExternal
202
+ ? await parseVueComponentImports(filename, ast.body.filter((node) => (0, types_1.isImportDeclaration)(node)), options.resolve)
203
+ : [];
204
+ const descriptor = {
205
+ bindingComponents: parseComponents(ast),
206
+ imports,
207
+ };
208
+ scriptDescriptors.set(filename, descriptor);
209
+ return descriptor;
210
+ }
211
+ exports.parseScriptDescriptor = parseScriptDescriptor;
212
+ /**
213
+ * 解析编译器生成的 bindingComponents
214
+ * @param ast
215
+ * @returns
216
+ */
217
+ function findBindingComponents(ast) {
218
+ const mapping = findUnpluginComponents(ast);
219
+ for (const node of ast) {
220
+ if (!(0, types_1.isVariableDeclaration)(node)) {
221
+ continue;
222
+ }
223
+ const declarator = node.declarations[0];
224
+ if ((0, types_1.isIdentifier)(declarator.id) &&
225
+ declarator.id.name === constants_1.BINDING_COMPONENTS) {
226
+ const bindingComponents = JSON.parse(declarator.init.value);
227
+ return Object.keys(bindingComponents).reduce((bindings, tag) => {
228
+ const { name, type } = bindingComponents[tag];
229
+ bindings[mapping[name] || name] = {
230
+ tag,
231
+ type: type,
232
+ };
233
+ return bindings;
234
+ }, {});
235
+ }
236
+ }
237
+ return {};
238
+ }
239
+ /**
240
+ * 兼容:unplugin_components
241
+ * https://github.com/dcloudio/uni-app/issues/3057
242
+ * @param ast
243
+ * @returns
244
+ */
245
+ function findUnpluginComponents(ast) {
246
+ const res = Object.create(null);
247
+ // if(!Array){}
248
+ const ifStatement = ast.find((statement) => (0, types_1.isIfStatement)(statement) &&
249
+ (0, types_1.isUnaryExpression)(statement.test) &&
250
+ statement.test.operator === '!' &&
251
+ (0, types_1.isIdentifier)(statement.test.argument) &&
252
+ statement.test.argument.name === 'Array');
253
+ if (!ifStatement) {
254
+ return res;
255
+ }
256
+ if (!(0, types_1.isBlockStatement)(ifStatement.consequent)) {
257
+ return res;
258
+ }
259
+ for (const node of ifStatement.consequent.body) {
260
+ if (!(0, types_1.isVariableDeclaration)(node)) {
261
+ continue;
262
+ }
263
+ const { id, init } = node.declarations[0];
264
+ if ((0, types_1.isIdentifier)(id) &&
265
+ (0, types_1.isIdentifier)(init) &&
266
+ init.name.includes('unplugin_components')) {
267
+ res[id.name] = init.name;
268
+ }
269
+ }
270
+ return res;
271
+ }
272
+ /**
273
+ * 查找全局组件定义:app.component('component-a',{})
274
+ * @param ast
275
+ * @returns
276
+ */
277
+ function parseGlobalComponents(ast) {
278
+ const bindingComponents = {};
279
+ estree_walker_1.walk(ast, {
280
+ enter(child) {
281
+ if (!(0, types_1.isCallExpression)(child)) {
282
+ return;
283
+ }
284
+ const { callee } = child;
285
+ // .component
286
+ if (!(0, types_1.isMemberExpression)(callee) ||
287
+ !(0, types_1.isIdentifier)(callee.property) ||
288
+ callee.property.name !== 'component') {
289
+ return;
290
+ }
291
+ // .component('component-a',{})
292
+ const args = child.arguments;
293
+ if (args.length !== 2) {
294
+ return;
295
+ }
296
+ const [name, value] = args;
297
+ if (!(0, types_1.isStringLiteral)(name)) {
298
+ return console.warn(messages_1.M['mp.component.args[0]']);
299
+ }
300
+ if (!(0, types_1.isIdentifier)(value)) {
301
+ return console.warn(messages_1.M['mp.component.args[1]']);
302
+ }
303
+ bindingComponents[value.name] = {
304
+ tag: name.value,
305
+ type: 'unknown',
306
+ };
307
+ },
308
+ });
309
+ return bindingComponents;
310
+ }
311
+ /**
312
+ * 从 components 中查找定义的组件
313
+ * @param ast
314
+ * @param bindingComponents
315
+ */
316
+ function parseComponents(ast) {
317
+ const bindingComponents = {};
318
+ estree_walker_1.walk(ast, {
319
+ enter(child) {
320
+ if (!(0, types_1.isObjectExpression)(child)) {
321
+ return;
322
+ }
323
+ const componentsProp = child.properties.find((prop) => (0, types_1.isObjectProperty)(prop) &&
324
+ (0, types_1.isIdentifier)(prop.key) &&
325
+ prop.key.name === 'components');
326
+ if (!componentsProp) {
327
+ return;
328
+ }
329
+ const componentsExpr = componentsProp.value;
330
+ if (!(0, types_1.isObjectExpression)(componentsExpr)) {
331
+ return;
332
+ }
333
+ componentsExpr.properties.forEach((prop) => {
334
+ if (!(0, types_1.isObjectProperty)(prop)) {
335
+ return;
336
+ }
337
+ if (!(0, types_1.isIdentifier)(prop.key) && !(0, types_1.isStringLiteral)(prop.key)) {
338
+ return;
339
+ }
340
+ if (!(0, types_1.isIdentifier)(prop.value)) {
341
+ return;
342
+ }
343
+ bindingComponents[prop.value.name] = {
344
+ tag: (0, types_1.isIdentifier)(prop.key) ? prop.key.name : prop.key.value,
345
+ type: 'unknown',
346
+ };
347
+ });
348
+ },
349
+ });
350
+ return bindingComponents;
351
+ }
352
+ /**
353
+ * vue component imports
354
+ * @param filename
355
+ * @param imports
356
+ * @param resolve
357
+ * @returns
358
+ */
359
+ async function parseVueComponentImports(importer, imports, resolve) {
360
+ const vueComponentImports = [];
361
+ for (let i = 0; i < imports.length; i++) {
362
+ const { source } = imports[i];
363
+ if ((0, utils_2.parseVueRequest)(source.value).query.vue) {
364
+ continue;
365
+ }
366
+ const resolveId = await resolve(source.value, importer);
367
+ if (!resolveId) {
368
+ continue;
369
+ }
370
+ const { filename } = (0, utils_2.parseVueRequest)(resolveId.id);
371
+ if (constants_1.EXTNAME_VUE_RE.test(filename)) {
372
+ source.value = resolveId.id;
373
+ vueComponentImports.push(imports[i]);
374
+ }
375
+ }
376
+ return vueComponentImports;
377
+ }
378
+ /**
379
+ * static import => dynamic import
380
+ * @param code
381
+ * @param imports
382
+ * @param dynamicImport
383
+ * @returns
384
+ */
385
+ async function transformDynamicImports(code, imports, { id, sourceMap, dynamicImport, }) {
386
+ if (!imports.length) {
387
+ return {
388
+ code,
389
+ map: null,
390
+ };
391
+ }
392
+ const s = new magic_string_1.default(code);
393
+ for (let i = 0; i < imports.length; i++) {
394
+ const { start, end, specifiers: [specifier], source, } = imports[i];
395
+ s.overwrite(start, end, dynamicImport(specifier.local.name, source.value) + ';');
396
+ }
397
+ return {
398
+ code: s.toString(),
399
+ map: null,
400
+ };
401
+ }
402
+ exports.transformDynamicImports = transformDynamicImports;
@@ -0,0 +1,2 @@
1
+ export declare function parseWxsCallMethods(code: string): string[];
2
+ export declare function genWxsCallMethodsCode(code: string): string;
package/dist/mp/wxs.js ADDED
@@ -0,0 +1,55 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.genWxsCallMethodsCode = exports.parseWxsCallMethods = void 0;
4
+ const types_1 = require("@babel/types");
5
+ const estree_walker_1 = require("estree-walker");
6
+ const ast_1 = require("./ast");
7
+ function parseWxsCallMethods(code) {
8
+ if (!code.includes('callMethod')) {
9
+ return [];
10
+ }
11
+ const ast = (0, ast_1.parseProgram)(code, '', {});
12
+ const wxsCallMethods = new Set();
13
+ estree_walker_1.walk(ast, {
14
+ enter(child) {
15
+ if (!(0, types_1.isCallExpression)(child)) {
16
+ return;
17
+ }
18
+ const { callee } = child;
19
+ // .callMethod
20
+ if (!(0, types_1.isMemberExpression)(callee) ||
21
+ !(0, types_1.isIdentifier)(callee.property) ||
22
+ callee.property.name !== 'callMethod') {
23
+ return;
24
+ }
25
+ // .callMethod('test',...)
26
+ const args = child.arguments;
27
+ if (!args.length) {
28
+ return;
29
+ }
30
+ const [name] = args;
31
+ if (!(0, types_1.isStringLiteral)(name)) {
32
+ return;
33
+ }
34
+ wxsCallMethods.add(name.value);
35
+ },
36
+ });
37
+ return [...wxsCallMethods];
38
+ }
39
+ exports.parseWxsCallMethods = parseWxsCallMethods;
40
+ function genWxsCallMethodsCode(code) {
41
+ const wxsCallMethods = parseWxsCallMethods(code);
42
+ if (!wxsCallMethods.length) {
43
+ return `export default {}`;
44
+ }
45
+ return `export default (Component) => {
46
+ if(!Component.wxsCallMethods){
47
+ Component.wxsCallMethods = []
48
+ }
49
+ Component.wxsCallMethods.push(${wxsCallMethods
50
+ .map((m) => `'${m}'`)
51
+ .join(', ')})
52
+ }
53
+ `;
54
+ }
55
+ exports.genWxsCallMethodsCode = genWxsCallMethodsCode;
@@ -0,0 +1,2 @@
1
+ export declare function registerPlatform(platform: string): void;
2
+ export declare function getPlatforms(): string[];
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getPlatforms = exports.registerPlatform = void 0;
4
+ const BUILT_IN_PLATFORMS = [
5
+ 'app',
6
+ 'app-plus',
7
+ 'h5',
8
+ 'mp-360',
9
+ 'mp-alipay',
10
+ 'mp-baidu',
11
+ 'mp-jd',
12
+ 'mp-kuaishou',
13
+ 'mp-lark',
14
+ 'mp-qq',
15
+ 'mp-toutiao',
16
+ 'mp-weixin',
17
+ 'quickapp-webview',
18
+ 'quickapp-webview-huawei',
19
+ 'quickapp-webview-union',
20
+ ];
21
+ const platforms = [...BUILT_IN_PLATFORMS];
22
+ function registerPlatform(platform) {
23
+ if (!platforms.includes(platform)) {
24
+ platforms.push(platform);
25
+ }
26
+ }
27
+ exports.registerPlatform = registerPlatform;
28
+ function getPlatforms() {
29
+ return platforms;
30
+ }
31
+ exports.getPlatforms = getPlatforms;
@@ -0,0 +1,10 @@
1
+ import type { Plugin } from 'postcss';
2
+ import type { Options } from 'autoprefixer';
3
+ import uniPostcssScopedPlugin from './plugins/stylePluginScoped';
4
+ import uniPostcssPlugin, { UniAppCssProcessorOptions } from './plugins/uniapp';
5
+ export { uniPostcssPlugin };
6
+ export { uniPostcssScopedPlugin };
7
+ export declare function initPostcssPlugin({ uniApp, autoprefixer, }?: {
8
+ uniApp?: UniAppCssProcessorOptions;
9
+ autoprefixer?: Options | false;
10
+ }): Plugin[];
@@ -0,0 +1,19 @@
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.initPostcssPlugin = exports.uniPostcssScopedPlugin = exports.uniPostcssPlugin = void 0;
7
+ const stylePluginScoped_1 = __importDefault(require("./plugins/stylePluginScoped"));
8
+ exports.uniPostcssScopedPlugin = stylePluginScoped_1.default;
9
+ const uniapp_1 = __importDefault(require("./plugins/uniapp"));
10
+ exports.uniPostcssPlugin = uniapp_1.default;
11
+ function initPostcssPlugin({ uniApp, autoprefixer, } = {}) {
12
+ const plugins = [(0, uniapp_1.default)(uniApp)];
13
+ // nvue 不需要 autoprefixer
14
+ if (autoprefixer !== false) {
15
+ plugins.push(require('autoprefixer')(autoprefixer));
16
+ }
17
+ return plugins;
18
+ }
19
+ exports.initPostcssPlugin = initPostcssPlugin;
@@ -0,0 +1,3 @@
1
+ import type { PluginCreator } from 'postcss';
2
+ declare const scopedPlugin: PluginCreator<string>;
3
+ export default scopedPlugin;