@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,207 @@
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.uniViteInjectPlugin = void 0;
7
+ const path_1 = require("path");
8
+ const debug_1 = __importDefault(require("debug"));
9
+ const pluginutils_1 = require("@rollup/pluginutils");
10
+ const estree_walker_1 = require("estree-walker");
11
+ const shared_1 = require("@vue/shared");
12
+ const magic_string_1 = __importDefault(require("magic-string"));
13
+ const utils_1 = require("../utils");
14
+ const debugInject = (0, debug_1.default)('uni:inject');
15
+ const debugInjectTry = (0, debug_1.default)('uni:inject-try');
16
+ function uniViteInjectPlugin(name, options) {
17
+ if (!options)
18
+ throw new Error('Missing options');
19
+ const filter = (0, pluginutils_1.createFilter)(options.include, options.exclude);
20
+ const modules = (0, shared_1.extend)({}, options);
21
+ delete modules.include;
22
+ delete modules.exclude;
23
+ delete modules.sourceMap;
24
+ delete modules.callback;
25
+ const reassignments = new Set();
26
+ const modulesMap = new Map();
27
+ const namespaceModulesMap = new Map();
28
+ Object.keys(modules).forEach((name) => {
29
+ if (name.endsWith('.')) {
30
+ namespaceModulesMap.set(name, modules[name]);
31
+ }
32
+ modulesMap.set(name, modules[name]);
33
+ });
34
+ const hasNamespace = namespaceModulesMap.size > 0;
35
+ // Fix paths on Windows
36
+ if (path_1.sep !== '/') {
37
+ normalizeModulesMap(modulesMap);
38
+ normalizeModulesMap(namespaceModulesMap);
39
+ }
40
+ const firstpass = new RegExp(`(?:${Array.from(modulesMap.keys()).map(escape).join('|')})`, 'g');
41
+ const sourceMap = options.sourceMap !== false;
42
+ const callback = options.callback;
43
+ return {
44
+ name,
45
+ // 确保在 commonjs 之后,否则会混合 es6 module 与 cjs 的代码,导致 commonjs 失效
46
+ enforce: 'post',
47
+ transform(code, id) {
48
+ if (!filter(id))
49
+ return null;
50
+ if (!(0, utils_1.isJsFile)(id))
51
+ return null;
52
+ debugInjectTry(id);
53
+ if (code.search(firstpass) === -1)
54
+ return null;
55
+ if (path_1.sep !== '/')
56
+ id = id.split(path_1.sep).join('/');
57
+ let ast = null;
58
+ try {
59
+ ast = this.parse(code);
60
+ }
61
+ catch (err) {
62
+ this.warn({
63
+ code: 'PARSE_ERROR',
64
+ message: `plugin-inject: failed to parse ${id}. Consider restricting the plugin to particular files via options.include`,
65
+ });
66
+ }
67
+ if (!ast) {
68
+ return null;
69
+ }
70
+ const imports = new Set();
71
+ ast.body.forEach((node) => {
72
+ if (node.type === 'ImportDeclaration') {
73
+ node.specifiers.forEach((specifier) => {
74
+ imports.add(specifier.local.name);
75
+ });
76
+ }
77
+ });
78
+ // analyse scopes
79
+ let scope = (0, pluginutils_1.attachScopes)(ast, 'scope');
80
+ const magicString = new magic_string_1.default(code);
81
+ const newImports = new Map();
82
+ function handleReference(node, name, keypath, parent) {
83
+ let mod = modulesMap.get(keypath);
84
+ if (!mod && hasNamespace) {
85
+ const mods = keypath.split('.');
86
+ if (mods.length === 2) {
87
+ mod = namespaceModulesMap.get(mods[0] + '.');
88
+ if (mod) {
89
+ if (Array.isArray(mod)) {
90
+ const testFn = mod[1];
91
+ if (testFn(mods[1])) {
92
+ mod = [mod[0], mods[1]];
93
+ }
94
+ else {
95
+ mod = undefined;
96
+ }
97
+ }
98
+ else {
99
+ mod = [mod, mods[1]];
100
+ }
101
+ }
102
+ }
103
+ }
104
+ if (mod && !imports.has(name) && !scope.contains(name)) {
105
+ if (typeof mod === 'string')
106
+ mod = [mod, 'default'];
107
+ if (mod[0] === id)
108
+ return false;
109
+ const hash = `${keypath}:${mod[0]}:${mod[1]}`;
110
+ // 当 API 被覆盖定义后,不再摇树
111
+ if (reassignments.has(hash)) {
112
+ return false;
113
+ }
114
+ if (parent &&
115
+ (0, utils_1.isAssignmentExpression)(parent) &&
116
+ parent.left === node) {
117
+ reassignments.add(hash);
118
+ return false;
119
+ }
120
+ const importLocalName = name === keypath ? name : (0, pluginutils_1.makeLegalIdentifier)(`$inject_${keypath}`);
121
+ if (!newImports.has(hash)) {
122
+ if (mod[1] === '*') {
123
+ newImports.set(hash, `import * as ${importLocalName} from '${mod[0]}';`);
124
+ }
125
+ else {
126
+ newImports.set(hash, `import { ${mod[1]} as ${importLocalName} } from '${mod[0]}';`);
127
+ callback && callback(newImports, mod);
128
+ }
129
+ }
130
+ if (name !== keypath) {
131
+ magicString.overwrite(node.start, node.end, importLocalName, {
132
+ storeName: true,
133
+ });
134
+ }
135
+ return true;
136
+ }
137
+ return false;
138
+ }
139
+ (0, estree_walker_1.walk)(ast, {
140
+ enter(node, parent) {
141
+ if (sourceMap) {
142
+ magicString.addSourcemapLocation(node.start);
143
+ magicString.addSourcemapLocation(node.end);
144
+ }
145
+ if (node.scope) {
146
+ scope = node.scope;
147
+ }
148
+ if ((0, utils_1.isProperty)(node) && node.shorthand) {
149
+ const { name } = node.key;
150
+ handleReference(node, name, name);
151
+ this.skip();
152
+ return;
153
+ }
154
+ if ((0, utils_1.isReference)(node, parent)) {
155
+ const { name, keypath } = flatten(node);
156
+ const handled = handleReference(node, name, keypath, parent);
157
+ if (handled) {
158
+ this.skip();
159
+ }
160
+ }
161
+ },
162
+ leave(node) {
163
+ if (node.scope) {
164
+ scope = scope.parent;
165
+ }
166
+ },
167
+ });
168
+ debugInject(id, newImports.size);
169
+ if (newImports.size === 0) {
170
+ return {
171
+ code,
172
+ // 不能返回 ast ,否则会导致代码不能被再次修改
173
+ // 比如 App.vue 中,console.log('uniCloud') 触发了 inject 检测,检测完,发现不需要
174
+ // 此时返回 ast,会导致 import { setupApp } from '@dcloudio/uni-h5' 不会被编译
175
+ // ast
176
+ map: sourceMap ? magicString.generateMap({ hires: true }) : null,
177
+ };
178
+ }
179
+ const importBlock = Array.from(newImports.values()).join('\n\n');
180
+ magicString.prepend(`${importBlock}\n\n`);
181
+ return {
182
+ code: magicString.toString(),
183
+ map: sourceMap ? magicString.generateMap({ hires: true }) : null,
184
+ };
185
+ },
186
+ };
187
+ }
188
+ exports.uniViteInjectPlugin = uniViteInjectPlugin;
189
+ const escape = (str) => str.replace(/[-[\]/{}()*+?.\\^$|]/g, '\\$&');
190
+ const flatten = (startNode) => {
191
+ const parts = [];
192
+ let node = startNode;
193
+ while ((0, utils_1.isMemberExpression)(node)) {
194
+ parts.unshift(node.property.name);
195
+ node = node.object;
196
+ }
197
+ const { name } = node;
198
+ parts.unshift(name);
199
+ return { name, keypath: parts.join('.') };
200
+ };
201
+ function normalizeModulesMap(modulesMap) {
202
+ modulesMap.forEach((mod, key) => {
203
+ modulesMap.set(key, Array.isArray(mod)
204
+ ? [mod[0].split(path_1.sep).join('/'), mod[1]]
205
+ : mod.split(path_1.sep).join('/'));
206
+ });
207
+ }
@@ -0,0 +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;
@@ -0,0 +1,52 @@
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.defineUniManifestJsonPlugin = exports.defineUniPagesJsonPlugin = void 0;
7
+ const fs_1 = __importDefault(require("fs"));
8
+ const path_1 = __importDefault(require("path"));
9
+ const utils_1 = require("../../utils");
10
+ exports.defineUniPagesJsonPlugin = createDefineJsonJsPlugin('pages.json');
11
+ exports.defineUniManifestJsonPlugin = createDefineJsonJsPlugin('manifest.json');
12
+ function createDefineJsonJsPlugin(name) {
13
+ const JSON_JS = name + '.js';
14
+ return function (createVitePlugin) {
15
+ const opts = {
16
+ resolvedConfig: {},
17
+ filter(id) {
18
+ return id.endsWith(JSON_JS);
19
+ },
20
+ };
21
+ const plugin = createVitePlugin(opts);
22
+ const origLoad = plugin.load;
23
+ const origResolveId = plugin.resolveId;
24
+ const origConfigResolved = plugin.configResolved;
25
+ let jsonPath = '';
26
+ plugin.resolveId = function (id, importer, options) {
27
+ const res = origResolveId && origResolveId.call(this, id, importer, options);
28
+ if (res) {
29
+ return res;
30
+ }
31
+ if (id.endsWith(JSON_JS)) {
32
+ return jsonPath + '.js';
33
+ }
34
+ };
35
+ plugin.configResolved = function (config) {
36
+ opts.resolvedConfig = config;
37
+ jsonPath = (0, utils_1.normalizePath)(path_1.default.join(process.env.UNI_INPUT_DIR, name));
38
+ return origConfigResolved && origConfigResolved(config);
39
+ };
40
+ plugin.load = function (id, ssr) {
41
+ const res = origLoad && origLoad.call(this, id, ssr);
42
+ if (res) {
43
+ return res;
44
+ }
45
+ if (!opts.filter(id)) {
46
+ return;
47
+ }
48
+ return fs_1.default.readFileSync(jsonPath, 'utf8');
49
+ };
50
+ return plugin;
51
+ };
52
+ }
@@ -0,0 +1,2 @@
1
+ import { CreateUniViteFilterPlugin } from '../utils/plugin';
2
+ export declare function defineUniMainJsPlugin(createUniMainJsPlugin: CreateUniViteFilterPlugin): import("vite").Plugin;
@@ -0,0 +1,29 @@
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.defineUniMainJsPlugin = void 0;
7
+ const path_1 = __importDefault(require("path"));
8
+ const utils_1 = require("../../utils");
9
+ function defineUniMainJsPlugin(createUniMainJsPlugin) {
10
+ const opts = {
11
+ resolvedConfig: {},
12
+ filter(id) {
13
+ return id === mainJsPath || id === mainTsPath;
14
+ },
15
+ };
16
+ const plugin = createUniMainJsPlugin(opts);
17
+ const origConfigResolved = plugin.configResolved;
18
+ let mainJsPath = '';
19
+ let mainTsPath = '';
20
+ plugin.configResolved = function (config) {
21
+ opts.resolvedConfig = config;
22
+ const mainPath = (0, utils_1.normalizePath)(path_1.default.resolve(process.env.UNI_INPUT_DIR, 'main'));
23
+ mainJsPath = mainPath + '.js';
24
+ mainTsPath = mainPath + '.ts';
25
+ return origConfigResolved && origConfigResolved(config);
26
+ };
27
+ return plugin;
28
+ }
29
+ exports.defineUniMainJsPlugin = defineUniMainJsPlugin;
@@ -0,0 +1 @@
1
+ export type { ResolvedConfig } from 'vite';
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,8 @@
1
+ /**
2
+ * https://github.com/vitejs/vite/blob/main/packages/vite/src/node/constants.ts
3
+ */
4
+ /**
5
+ * Prefix for resolved fs paths, since windows paths may not be valid as URLs.
6
+ */
7
+ export declare const FS_PREFIX = "/@fs/";
8
+ export declare const CLIENT_PUBLIC_PATH = "/@vite/client";
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.CLIENT_PUBLIC_PATH = exports.FS_PREFIX = void 0;
4
+ /**
5
+ * https://github.com/vitejs/vite/blob/main/packages/vite/src/node/constants.ts
6
+ */
7
+ /**
8
+ * Prefix for resolved fs paths, since windows paths may not be valid as URLs.
9
+ */
10
+ exports.FS_PREFIX = `/@fs/`;
11
+ exports.CLIENT_PUBLIC_PATH = `/@vite/client`;
@@ -0,0 +1 @@
1
+ export type { ResolveFn, ViteDevServer } from 'vite';
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1 @@
1
+ export type { Plugin } from 'vite';
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,40 @@
1
+ /// <reference types="node" />
2
+ import type { OutputOptions, PluginContext, RenderedChunk } from 'rollup';
3
+ import { Plugin } from '../plugin';
4
+ import { ResolvedConfig } from '../config';
5
+ export declare const assetUrlRE: RegExp;
6
+ export declare const chunkToEmittedAssetsMap: WeakMap<RenderedChunk, Set<string>>;
7
+ /**
8
+ * Also supports loading plain strings with import text from './foo.txt?raw'
9
+ */
10
+ export declare function assetPlugin(config: ResolvedConfig): Plugin;
11
+ export declare function registerAssetToChunk(chunk: RenderedChunk, file: string): void;
12
+ export declare function checkPublicFile(url: string, { publicDir }: ResolvedConfig): string | undefined;
13
+ export declare function fileToUrl(id: string, config: ResolvedConfig, ctx: PluginContext, canInline?: boolean): string;
14
+ export declare function getAssetFilename(hash: string, config: ResolvedConfig): string | undefined;
15
+ /**
16
+ * converts the source filepath of the asset to the output filename based on the assetFileNames option. \
17
+ * this function imitates the behavior of rollup.js. \
18
+ * https://rollupjs.org/guide/en/#outputassetfilenames
19
+ *
20
+ * @example
21
+ * ```ts
22
+ * const content = Buffer.from('text');
23
+ * const fileName = assetFileNamesToFileName(
24
+ * 'assets/[name].[hash][extname]',
25
+ * '/path/to/file.txt',
26
+ * getAssetHash(content),
27
+ * content
28
+ * )
29
+ * // fileName: 'assets/file.982d9e3e.txt'
30
+ * ```
31
+ *
32
+ * @param assetFileNames filename pattern. e.g. `'assets/[name].[hash][extname]'`
33
+ * @param file filepath of the asset
34
+ * @param contentHash hash of the asset. used for `'[hash]'` placeholder
35
+ * @param content content of the asset. passed to `assetFileNames` if `assetFileNames` is a function
36
+ * @returns output filename
37
+ */
38
+ export declare function assetFileNamesToFileName(assetFileNames: Exclude<OutputOptions['assetFileNames'], undefined>, file: string, contentHash: string, content: string | Buffer): string;
39
+ export declare function getAssetHash(content: Buffer): string;
40
+ export declare function urlToBuiltUrl(url: string, importer: string, config: ResolvedConfig, pluginContext: PluginContext): string;
@@ -0,0 +1,270 @@
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 __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
10
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
11
+ }) : function(o, v) {
12
+ o["default"] = v;
13
+ });
14
+ var __importStar = (this && this.__importStar) || function (mod) {
15
+ if (mod && mod.__esModule) return mod;
16
+ var result = {};
17
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
18
+ __setModuleDefault(result, mod);
19
+ return result;
20
+ };
21
+ var __importDefault = (this && this.__importDefault) || function (mod) {
22
+ return (mod && mod.__esModule) ? mod : { "default": mod };
23
+ };
24
+ Object.defineProperty(exports, "__esModule", { value: true });
25
+ exports.urlToBuiltUrl = exports.getAssetHash = exports.assetFileNamesToFileName = exports.getAssetFilename = exports.fileToUrl = exports.checkPublicFile = exports.registerAssetToChunk = exports.assetPlugin = exports.chunkToEmittedAssetsMap = exports.assetUrlRE = void 0;
26
+ const path_1 = __importDefault(require("path"));
27
+ const url_1 = require("url");
28
+ const lite_1 = __importDefault(require("mime/lite"));
29
+ const fs_1 = __importStar(require("fs"));
30
+ const magic_string_1 = __importDefault(require("magic-string"));
31
+ const crypto_1 = require("crypto");
32
+ const utils_1 = require("../utils");
33
+ const utils_2 = require("../../../../vite/utils/utils");
34
+ exports.assetUrlRE = /__VITE_ASSET__([a-z\d]{8})__(?:\$_(.*?)__)?/g;
35
+ // urls in JS must be quoted as strings, so when replacing them we need
36
+ // a different regex
37
+ const assetUrlQuotedRE = /"__VITE_ASSET__([a-z\d]{8})__(?:\$_(.*?)__)?"/g;
38
+ const rawRE = /(\?|&)raw(?:&|$)/;
39
+ const urlRE = /(\?|&)url(?:&|$)/;
40
+ exports.chunkToEmittedAssetsMap = new WeakMap();
41
+ const assetCache = new WeakMap();
42
+ const assetHashToFilenameMap = new WeakMap();
43
+ // save hashes of the files that has been emitted in build watch
44
+ const emittedHashMap = new WeakMap();
45
+ /**
46
+ * Also supports loading plain strings with import text from './foo.txt?raw'
47
+ */
48
+ function assetPlugin(config) {
49
+ // assetHashToFilenameMap initialization in buildStart causes getAssetFilename to return undefined
50
+ assetHashToFilenameMap.set(config, new Map());
51
+ return {
52
+ name: 'vite:asset',
53
+ buildStart() {
54
+ assetCache.set(config, new Map());
55
+ emittedHashMap.set(config, new Set());
56
+ },
57
+ resolveId(id) {
58
+ if (!config.assetsInclude((0, utils_1.cleanUrl)(id))) {
59
+ return;
60
+ }
61
+ // imports to absolute urls pointing to files in /public
62
+ // will fail to resolve in the main resolver. handle them here.
63
+ const publicFile = checkPublicFile(id, config);
64
+ if (publicFile) {
65
+ return id;
66
+ }
67
+ },
68
+ async load(id) {
69
+ if (id.startsWith('\0')) {
70
+ // Rollup convention, this id should be handled by the
71
+ // plugin that marked it with \0
72
+ return;
73
+ }
74
+ // raw requests, read from disk
75
+ if (rawRE.test(id)) {
76
+ const file = checkPublicFile(id, config) || (0, utils_1.cleanUrl)(id);
77
+ // raw query, read file and return as string
78
+ return `export default ${JSON.stringify(await fs_1.promises.readFile(file, 'utf-8'))}`;
79
+ }
80
+ if (!config.assetsInclude((0, utils_1.cleanUrl)(id)) && !urlRE.test(id)) {
81
+ return;
82
+ }
83
+ id = id.replace(urlRE, '$1').replace(/[\?&]$/, '');
84
+ const url = await fileToUrl(id, config, this);
85
+ return `export default ${JSON.stringify(url)}`;
86
+ },
87
+ renderChunk(code, chunk) {
88
+ let match;
89
+ let s;
90
+ while ((match = assetUrlQuotedRE.exec(code))) {
91
+ s = s || (s = new magic_string_1.default(code));
92
+ const [full, hash, postfix = ''] = match;
93
+ // some internal plugins may still need to emit chunks (e.g. worker) so
94
+ // fallback to this.getFileName for that.
95
+ const file = getAssetFilename(hash, config) || this.getFileName(hash);
96
+ registerAssetToChunk(chunk, file);
97
+ const outputFilepath = config.base + file + postfix;
98
+ s.overwrite(match.index, match.index + full.length, JSON.stringify(outputFilepath));
99
+ }
100
+ if (s) {
101
+ return {
102
+ code: s.toString(),
103
+ map: (0, utils_2.withSourcemap)(config) ? s.generateMap({ hires: true }) : null,
104
+ };
105
+ }
106
+ else {
107
+ return null;
108
+ }
109
+ },
110
+ };
111
+ }
112
+ exports.assetPlugin = assetPlugin;
113
+ function registerAssetToChunk(chunk, file) {
114
+ let emitted = exports.chunkToEmittedAssetsMap.get(chunk);
115
+ if (!emitted) {
116
+ emitted = new Set();
117
+ exports.chunkToEmittedAssetsMap.set(chunk, emitted);
118
+ }
119
+ emitted.add((0, utils_1.cleanUrl)(file));
120
+ }
121
+ exports.registerAssetToChunk = registerAssetToChunk;
122
+ function checkPublicFile(url, { publicDir }) {
123
+ // note if the file is in /public, the resolver would have returned it
124
+ // as-is so it's not going to be a fully resolved path.
125
+ if (!publicDir || !url.startsWith('/')) {
126
+ return;
127
+ }
128
+ const publicFile = path_1.default.join(publicDir, (0, utils_1.cleanUrl)(url));
129
+ if (fs_1.default.existsSync(publicFile)) {
130
+ return publicFile;
131
+ }
132
+ else {
133
+ return;
134
+ }
135
+ }
136
+ exports.checkPublicFile = checkPublicFile;
137
+ function fileToUrl(id, config, ctx, canInline = false) {
138
+ return fileToBuiltUrl(id, config, ctx, false, canInline);
139
+ }
140
+ exports.fileToUrl = fileToUrl;
141
+ function getAssetFilename(hash, config) {
142
+ var _a;
143
+ return (_a = assetHashToFilenameMap.get(config)) === null || _a === void 0 ? void 0 : _a.get(hash);
144
+ }
145
+ exports.getAssetFilename = getAssetFilename;
146
+ /**
147
+ * converts the source filepath of the asset to the output filename based on the assetFileNames option. \
148
+ * this function imitates the behavior of rollup.js. \
149
+ * https://rollupjs.org/guide/en/#outputassetfilenames
150
+ *
151
+ * @example
152
+ * ```ts
153
+ * const content = Buffer.from('text');
154
+ * const fileName = assetFileNamesToFileName(
155
+ * 'assets/[name].[hash][extname]',
156
+ * '/path/to/file.txt',
157
+ * getAssetHash(content),
158
+ * content
159
+ * )
160
+ * // fileName: 'assets/file.982d9e3e.txt'
161
+ * ```
162
+ *
163
+ * @param assetFileNames filename pattern. e.g. `'assets/[name].[hash][extname]'`
164
+ * @param file filepath of the asset
165
+ * @param contentHash hash of the asset. used for `'[hash]'` placeholder
166
+ * @param content content of the asset. passed to `assetFileNames` if `assetFileNames` is a function
167
+ * @returns output filename
168
+ */
169
+ function assetFileNamesToFileName(assetFileNames, file, contentHash, content) {
170
+ const basename = path_1.default.basename(file);
171
+ // placeholders for `assetFileNames`
172
+ // `hash` is slightly different from the rollup's one
173
+ const extname = path_1.default.extname(basename);
174
+ const ext = extname.substring(1);
175
+ const name = basename.slice(0, -extname.length);
176
+ const hash = contentHash;
177
+ if (typeof assetFileNames === 'function') {
178
+ assetFileNames = assetFileNames({
179
+ name: file,
180
+ source: content,
181
+ type: 'asset',
182
+ });
183
+ if (typeof assetFileNames !== 'string') {
184
+ throw new TypeError('assetFileNames must return a string');
185
+ }
186
+ }
187
+ else if (typeof assetFileNames !== 'string') {
188
+ throw new TypeError('assetFileNames must be a string or a function');
189
+ }
190
+ const fileName = assetFileNames.replace(/\[\w+\]/g, (placeholder) => {
191
+ switch (placeholder) {
192
+ case '[ext]':
193
+ return ext;
194
+ case '[extname]':
195
+ return extname;
196
+ case '[hash]':
197
+ return hash;
198
+ case '[name]':
199
+ return name;
200
+ }
201
+ throw new Error(`invalid placeholder ${placeholder} in assetFileNames "${assetFileNames}"`);
202
+ });
203
+ return fileName;
204
+ }
205
+ exports.assetFileNamesToFileName = assetFileNamesToFileName;
206
+ /**
207
+ * Register an asset to be emitted as part of the bundle (if necessary)
208
+ * and returns the resolved public URL
209
+ */
210
+ function fileToBuiltUrl(id, config, pluginContext, skipPublicCheck = false, canInline = false) {
211
+ if (!skipPublicCheck && checkPublicFile(id, config)) {
212
+ return config.base + id.slice(1);
213
+ }
214
+ const cache = assetCache.get(config);
215
+ const cached = cache.get(id);
216
+ if (cached) {
217
+ return cached;
218
+ }
219
+ const file = (0, utils_1.cleanUrl)(id);
220
+ const content = fs_1.default.readFileSync(file);
221
+ let url;
222
+ if (canInline && content.length < Number(config.build.assetsInlineLimit)) {
223
+ // base64 inlined as a string
224
+ url = `data:${lite_1.default.getType(file)};base64,${content.toString('base64')}`;
225
+ }
226
+ else {
227
+ const map = assetHashToFilenameMap.get(config);
228
+ const contentHash = getAssetHash(content);
229
+ const { search, hash } = (0, url_1.parse)(id);
230
+ const postfix = (search || '') + (hash || '');
231
+ const inputDir = (0, utils_1.normalizePath)(process.env.UNI_INPUT_DIR);
232
+ let fileName = file.startsWith(inputDir)
233
+ ? path_1.default.posix.relative(inputDir, file)
234
+ : assetFileNamesToFileName(path_1.default.posix.join(config.build.assetsDir, '[name].[hash][extname]'), file, contentHash, content);
235
+ if (!map.has(contentHash)) {
236
+ map.set(contentHash, fileName);
237
+ }
238
+ if (!fileName.includes('/static/')) {
239
+ const emittedSet = emittedHashMap.get(config);
240
+ if (!emittedSet.has(contentHash)) {
241
+ pluginContext.emitFile({
242
+ name: fileName,
243
+ fileName,
244
+ type: 'asset',
245
+ source: content,
246
+ });
247
+ emittedSet.add(contentHash);
248
+ }
249
+ }
250
+ url = `__VITE_ASSET__${contentHash}__${postfix ? `$_${postfix}__` : ``}`;
251
+ }
252
+ cache.set(id, url);
253
+ return url;
254
+ }
255
+ function getAssetHash(content) {
256
+ return (0, crypto_1.createHash)('sha256').update(content).digest('hex').slice(0, 8);
257
+ }
258
+ exports.getAssetHash = getAssetHash;
259
+ function urlToBuiltUrl(url, importer, config, pluginContext) {
260
+ if (checkPublicFile(url, config)) {
261
+ return config.base + url.slice(1);
262
+ }
263
+ const file = url.startsWith('/')
264
+ ? path_1.default.join(config.root, url)
265
+ : path_1.default.join(path_1.default.dirname(importer), url);
266
+ return fileToBuiltUrl(file, config, pluginContext,
267
+ // skip public check since we just did it above
268
+ true);
269
+ }
270
+ exports.urlToBuiltUrl = urlToBuiltUrl;