@dcloudio/uni-cli-shared 3.0.0-alpha-3030220211217007 → 3.0.0-alpha-3030220211217012

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.
@@ -8,6 +8,7 @@ function initDefine(stringifyBoolean = false) {
8
8
  const isRunByHBuilderX = (0, env_1.runByHBuilderX)();
9
9
  const isDebug = !!manifestJson.debug;
10
10
  return {
11
+ ...initCustomDefine(),
11
12
  'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV),
12
13
  'process.env.UNI_DEBUG': stringifyBoolean
13
14
  ? JSON.stringify(isDebug)
@@ -29,3 +30,16 @@ function initDefine(stringifyBoolean = false) {
29
30
  };
30
31
  }
31
32
  exports.initDefine = initDefine;
33
+ function initCustomDefine() {
34
+ let define = {};
35
+ if (process.env.UNI_CUSTOM_DEFINE) {
36
+ try {
37
+ define = JSON.parse(process.env.UNI_CUSTOM_DEFINE);
38
+ }
39
+ catch (e) { }
40
+ }
41
+ return Object.keys(define).reduce((res, name) => {
42
+ res['process.env.' + name] = JSON.stringify(define[name]);
43
+ return res;
44
+ }, {});
45
+ }
package/dist/index.d.ts CHANGED
@@ -18,6 +18,7 @@ export * from './postcss';
18
18
  export * from './filter';
19
19
  export * from './esbuild';
20
20
  export * from './resolve';
21
+ export * from './scripts';
21
22
  export { M } from './messages';
22
23
  export * from './exports';
23
24
  export { checkUpdate } from './checkUpdate';
package/dist/index.js CHANGED
@@ -31,6 +31,7 @@ __exportStar(require("./postcss"), exports);
31
31
  __exportStar(require("./filter"), exports);
32
32
  __exportStar(require("./esbuild"), exports);
33
33
  __exportStar(require("./resolve"), exports);
34
+ __exportStar(require("./scripts"), exports);
34
35
  var messages_1 = require("./messages");
35
36
  Object.defineProperty(exports, "M", { enumerable: true, get: function () { return messages_1.M; } });
36
37
  __exportStar(require("./exports"), exports);
@@ -3,6 +3,7 @@ export declare function isMiniProgramPageFile(file: string, inputDir?: string):
3
3
  export declare function isMiniProgramPageSfcFile(file: string, inputDir?: string): boolean;
4
4
  export declare function hasJsonFile(filename: string): boolean;
5
5
  export declare function findJsonFile(filename: string): Record<string, any> | undefined;
6
+ export declare function findUsingComponents(filename: string): UsingComponents | undefined;
6
7
  export declare function normalizeJsonFilename(filename: string): string;
7
8
  export declare function findChangedJsonFiles(): Map<string, string>;
8
9
  export declare function addMiniProgramAppJson(appJson: Record<string, any>): void;
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.findMiniProgramUsingComponents = exports.isMiniProgramUsingComponent = exports.addMiniProgramUsingComponents = exports.addMiniProgramComponentJson = exports.addMiniProgramPageJson = exports.addMiniProgramAppJson = exports.findChangedJsonFiles = exports.normalizeJsonFilename = exports.findJsonFile = exports.hasJsonFile = exports.isMiniProgramPageSfcFile = exports.isMiniProgramPageFile = void 0;
6
+ exports.findMiniProgramUsingComponents = exports.isMiniProgramUsingComponent = exports.addMiniProgramUsingComponents = exports.addMiniProgramComponentJson = exports.addMiniProgramPageJson = exports.addMiniProgramAppJson = exports.findChangedJsonFiles = exports.normalizeJsonFilename = exports.findUsingComponents = exports.findJsonFile = exports.hasJsonFile = exports.isMiniProgramPageSfcFile = exports.isMiniProgramPageFile = void 0;
7
7
  const path_1 = __importDefault(require("path"));
8
8
  const shared_1 = require("@vue/shared");
9
9
  const utils_1 = require("../../utils");
@@ -38,6 +38,10 @@ function findJsonFile(filename) {
38
38
  return jsonPagesCache.get(filename) || jsonComponentsCache.get(filename);
39
39
  }
40
40
  exports.findJsonFile = findJsonFile;
41
+ function findUsingComponents(filename) {
42
+ return jsonUsingComponentsCache.get(filename);
43
+ }
44
+ exports.findUsingComponents = findUsingComponents;
41
45
  function normalizeJsonFilename(filename) {
42
46
  return (0, utils_1.normalizeNodeModules)(filename);
43
47
  }
@@ -15,7 +15,7 @@ const initErrFormattersOnce = (0, uni_shared_1.once)(() => {
15
15
  errFormatters.push(log_1.errorFormatter);
16
16
  });
17
17
  const initInfoFormattersOnce = (0, uni_shared_1.once)(() => {
18
- if ((0, env_1.isInHBuilderX)()) {
18
+ if ((0, env_1.runByHBuilderX)()) {
19
19
  if (
20
20
  // 开发模式下
21
21
  process.env.UNI_PLATFORM === 'h5' &&
@@ -5,4 +5,4 @@ export * from './template';
5
5
  export * from './constants';
6
6
  export { HTML_TO_MINI_PROGRAM_TAGS } from './tags';
7
7
  export { copyMiniProgramPluginJson } from './plugin';
8
- export { transformVueComponentImports } from './transformImports';
8
+ export { parseProgram, parseMainDescriptor, parseScriptDescriptor, parseTemplateDescriptor, transformDynamicImports, updateMiniProgramGlobalComponents, updateMiniProgramComponentsByMainFilename, updateMiniProgramComponentsByScriptFilename, updateMiniProgramComponentsByTemplateFilename, } from './usingComponents';
package/dist/mp/index.js CHANGED
@@ -10,7 +10,7 @@ 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 = exports.copyMiniProgramPluginJson = exports.HTML_TO_MINI_PROGRAM_TAGS = void 0;
13
+ exports.updateMiniProgramComponentsByTemplateFilename = exports.updateMiniProgramComponentsByScriptFilename = exports.updateMiniProgramComponentsByMainFilename = exports.updateMiniProgramGlobalComponents = exports.transformDynamicImports = exports.parseTemplateDescriptor = exports.parseScriptDescriptor = exports.parseMainDescriptor = exports.parseProgram = exports.copyMiniProgramPluginJson = exports.HTML_TO_MINI_PROGRAM_TAGS = void 0;
14
14
  __exportStar(require("./nvue"), exports);
15
15
  __exportStar(require("./event"), exports);
16
16
  __exportStar(require("./style"), exports);
@@ -20,5 +20,13 @@ var tags_1 = require("./tags");
20
20
  Object.defineProperty(exports, "HTML_TO_MINI_PROGRAM_TAGS", { enumerable: true, get: function () { return tags_1.HTML_TO_MINI_PROGRAM_TAGS; } });
21
21
  var plugin_1 = require("./plugin");
22
22
  Object.defineProperty(exports, "copyMiniProgramPluginJson", { enumerable: true, get: function () { return plugin_1.copyMiniProgramPluginJson; } });
23
- var transformImports_1 = require("./transformImports");
24
- Object.defineProperty(exports, "transformVueComponentImports", { enumerable: true, get: function () { return transformImports_1.transformVueComponentImports; } });
23
+ var usingComponents_1 = require("./usingComponents");
24
+ Object.defineProperty(exports, "parseProgram", { enumerable: true, get: function () { return usingComponents_1.parseProgram; } });
25
+ Object.defineProperty(exports, "parseMainDescriptor", { enumerable: true, get: function () { return usingComponents_1.parseMainDescriptor; } });
26
+ Object.defineProperty(exports, "parseScriptDescriptor", { enumerable: true, get: function () { return usingComponents_1.parseScriptDescriptor; } });
27
+ Object.defineProperty(exports, "parseTemplateDescriptor", { enumerable: true, get: function () { return usingComponents_1.parseTemplateDescriptor; } });
28
+ Object.defineProperty(exports, "transformDynamicImports", { enumerable: true, get: function () { return usingComponents_1.transformDynamicImports; } });
29
+ Object.defineProperty(exports, "updateMiniProgramGlobalComponents", { enumerable: true, get: function () { return usingComponents_1.updateMiniProgramGlobalComponents; } });
30
+ Object.defineProperty(exports, "updateMiniProgramComponentsByMainFilename", { enumerable: true, get: function () { return usingComponents_1.updateMiniProgramComponentsByMainFilename; } });
31
+ Object.defineProperty(exports, "updateMiniProgramComponentsByScriptFilename", { enumerable: true, get: function () { return usingComponents_1.updateMiniProgramComponentsByScriptFilename; } });
32
+ Object.defineProperty(exports, "updateMiniProgramComponentsByTemplateFilename", { enumerable: true, get: function () { return usingComponents_1.updateMiniProgramComponentsByTemplateFilename; } });
@@ -0,0 +1,62 @@
1
+ import { ImportDeclaration, Program } from '@babel/types';
2
+ import { ParserPlugin } from '@babel/parser';
3
+ import type { PluginContext } from 'rollup';
4
+ declare type BindingComponents = Record<string, {
5
+ tag: string;
6
+ type: 'unknown' | 'setup' | 'self';
7
+ }>;
8
+ export declare function parseProgram(code: string, importer: string, { babelParserPlugins }: {
9
+ babelParserPlugins?: ParserPlugin[];
10
+ }): Program;
11
+ interface MainDescriptor {
12
+ imports: ImportDeclaration[];
13
+ script: string;
14
+ template: string;
15
+ }
16
+ export declare function parseMainDescriptor(filename: string, ast: Program, resolve: ParseDescriptor['resolve']): Promise<MainDescriptor>;
17
+ export declare function updateMiniProgramComponentsByScriptFilename(scriptFilename: string, inputDir: string): void;
18
+ export declare function updateMiniProgramComponentsByTemplateFilename(templateFilename: string, inputDir: string): void;
19
+ export declare function updateMiniProgramGlobalComponents(filename: string, ast: Program, { inputDir, resolve, }: {
20
+ inputDir: string;
21
+ resolve: ParseDescriptor['resolve'];
22
+ }): Promise<{
23
+ imports: ImportDeclaration[];
24
+ }>;
25
+ export declare function updateMiniProgramComponentsByMainFilename(mainFilename: string, inputDir: string): void;
26
+ export interface TemplateDescriptor {
27
+ bindingComponents: BindingComponents;
28
+ imports: ImportDeclaration[];
29
+ }
30
+ /**
31
+ * 解析 template
32
+ * @param filename
33
+ * @param code
34
+ * @param ast
35
+ * @param options
36
+ * @returns
37
+ */
38
+ export declare function parseTemplateDescriptor(filename: string, ast: Program, options: ParseDescriptor): Promise<TemplateDescriptor>;
39
+ interface ParseDescriptor {
40
+ resolve: PluginContext['resolve'];
41
+ isExternal: boolean;
42
+ }
43
+ export interface ScriptDescriptor extends TemplateDescriptor {
44
+ }
45
+ /**
46
+ * 解析 script
47
+ * @param filename
48
+ * @param code
49
+ * @param ast
50
+ * @param options
51
+ * @returns
52
+ */
53
+ export declare function parseScriptDescriptor(filename: string, ast: Program, options: ParseDescriptor): Promise<ScriptDescriptor>;
54
+ /**
55
+ * static import => dynamic import
56
+ * @param code
57
+ * @param imports
58
+ * @param dynamicImport
59
+ * @returns
60
+ */
61
+ export declare function transformDynamicImports(code: string, imports: ImportDeclaration[], dynamicImport: (name: string, source: string) => string): Promise<string>;
62
+ export {};
@@ -0,0 +1,390 @@
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 = exports.parseProgram = void 0;
7
+ const types_1 = require("@babel/types");
8
+ const parser_1 = require("@babel/parser");
9
+ const estree_walker_1 = require("estree-walker");
10
+ const magic_string_1 = __importDefault(require("magic-string"));
11
+ const shared_1 = require("@vue/shared");
12
+ const uni_shared_1 = require("@dcloudio/uni-shared");
13
+ const messages_1 = require("../messages");
14
+ const constants_1 = require("../constants");
15
+ const utils_1 = require("../utils");
16
+ const utils_2 = require("../vite/utils");
17
+ const jsonFile_1 = require("../json/mp/jsonFile");
18
+ function parseProgram(code, importer, { babelParserPlugins }) {
19
+ return (0, parser_1.parse)(code, {
20
+ plugins: (0, utils_1.normalizeParsePlugins)(importer, babelParserPlugins),
21
+ sourceType: 'module',
22
+ }).program;
23
+ }
24
+ exports.parseProgram = parseProgram;
25
+ const mainDescriptors = new Map();
26
+ const scriptDescriptors = new Map();
27
+ const templateDescriptors = new Map();
28
+ function findImportTemplateSource(ast) {
29
+ const importDeclaration = ast.body.find((node) => (0, types_1.isImportDeclaration)(node) &&
30
+ node.source.value.includes('vue&type=template'));
31
+ if (importDeclaration) {
32
+ return importDeclaration.source.value;
33
+ }
34
+ }
35
+ function findImportScriptSource(ast) {
36
+ const importDeclaration = ast.body.find((node) => (0, types_1.isImportDeclaration)(node) && node.source.value.includes('vue&type=script'));
37
+ if (importDeclaration) {
38
+ return importDeclaration.source.value;
39
+ }
40
+ }
41
+ async function resolveSource(filename, source, resolve) {
42
+ if (!source) {
43
+ return;
44
+ }
45
+ const resolveId = await resolve(source, filename);
46
+ if (resolveId) {
47
+ return resolveId.id;
48
+ }
49
+ }
50
+ async function parseMainDescriptor(filename, ast, resolve) {
51
+ const script = await resolveSource(filename, findImportScriptSource(ast), resolve);
52
+ const template = await resolveSource(filename, findImportTemplateSource(ast), resolve);
53
+ const imports = await parseVueComponentImports(filename, ast.body.filter((node) => (0, types_1.isImportDeclaration)(node)), resolve);
54
+ if (!script) {
55
+ // inline script
56
+ await parseScriptDescriptor(filename, ast, { resolve, isExternal: false });
57
+ }
58
+ if (!template) {
59
+ // inline template
60
+ await parseTemplateDescriptor(filename, ast, { resolve, isExternal: false });
61
+ }
62
+ const descriptor = {
63
+ imports,
64
+ script: script ? (0, utils_2.parseVueRequest)(script).filename : filename,
65
+ template: template ? (0, utils_2.parseVueRequest)(template).filename : filename,
66
+ };
67
+ mainDescriptors.set(filename, descriptor);
68
+ return descriptor;
69
+ }
70
+ exports.parseMainDescriptor = parseMainDescriptor;
71
+ function updateMiniProgramComponentsByScriptFilename(scriptFilename, inputDir) {
72
+ const mainFilename = findMainFilenameByScriptFilename(scriptFilename);
73
+ if (mainFilename) {
74
+ updateMiniProgramComponentsByMainFilename(mainFilename, inputDir);
75
+ }
76
+ }
77
+ exports.updateMiniProgramComponentsByScriptFilename = updateMiniProgramComponentsByScriptFilename;
78
+ function updateMiniProgramComponentsByTemplateFilename(templateFilename, inputDir) {
79
+ const mainFilename = findMainFilenameByTemplateFilename(templateFilename);
80
+ if (mainFilename) {
81
+ updateMiniProgramComponentsByMainFilename(mainFilename, inputDir);
82
+ }
83
+ }
84
+ exports.updateMiniProgramComponentsByTemplateFilename = updateMiniProgramComponentsByTemplateFilename;
85
+ function findMainFilenameByScriptFilename(scriptFilename) {
86
+ const keys = [...mainDescriptors.keys()];
87
+ return keys.find((key) => mainDescriptors.get(key).script === scriptFilename);
88
+ }
89
+ function findMainFilenameByTemplateFilename(templateFilename) {
90
+ const keys = [...mainDescriptors.keys()];
91
+ return keys.find((key) => mainDescriptors.get(key).template === templateFilename);
92
+ }
93
+ async function updateMiniProgramGlobalComponents(filename, ast, { inputDir, resolve, }) {
94
+ const { bindingComponents, imports } = await parseGlobalDescriptor(filename, ast, resolve);
95
+ (0, jsonFile_1.addMiniProgramUsingComponents)('app', createUsingComponents(bindingComponents, imports, inputDir));
96
+ return {
97
+ imports,
98
+ };
99
+ }
100
+ exports.updateMiniProgramGlobalComponents = updateMiniProgramGlobalComponents;
101
+ function createUsingComponents(bindingComponents, imports, inputDir) {
102
+ const usingComponents = {};
103
+ imports.forEach(({ source: { value }, specifiers: [specifier] }) => {
104
+ const { name } = specifier.local;
105
+ if (!bindingComponents[name]) {
106
+ return;
107
+ }
108
+ const componentName = (0, shared_1.hyphenate)(bindingComponents[name].tag);
109
+ if (!usingComponents[componentName]) {
110
+ usingComponents[componentName] = (0, uni_shared_1.addLeadingSlash)((0, utils_1.removeExt)((0, utils_1.normalizeMiniProgramFilename)(value, inputDir)));
111
+ }
112
+ });
113
+ return usingComponents;
114
+ }
115
+ function updateMiniProgramComponentsByMainFilename(mainFilename, inputDir) {
116
+ const mainDescriptor = mainDescriptors.get(mainFilename);
117
+ if (!mainDescriptor) {
118
+ return;
119
+ }
120
+ const templateDescriptor = templateDescriptors.get(mainDescriptor.template);
121
+ if (!templateDescriptor) {
122
+ return;
123
+ }
124
+ const scriptDescriptor = scriptDescriptors.get(mainDescriptor.script);
125
+ if (!scriptDescriptor) {
126
+ return;
127
+ }
128
+ const bindingComponents = parseBindingComponents(templateDescriptor.bindingComponents, scriptDescriptor.bindingComponents);
129
+ const imports = parseImports(mainDescriptor.imports, scriptDescriptor.imports, templateDescriptor.imports);
130
+ (0, jsonFile_1.addMiniProgramUsingComponents)((0, utils_1.removeExt)((0, utils_1.normalizeMiniProgramFilename)(mainFilename, inputDir)), createUsingComponents(bindingComponents, imports, inputDir));
131
+ }
132
+ exports.updateMiniProgramComponentsByMainFilename = updateMiniProgramComponentsByMainFilename;
133
+ function findBindingComponent(tag, bindingComponents) {
134
+ return Object.keys(bindingComponents).find((name) => {
135
+ const componentTag = bindingComponents[name].tag;
136
+ const camelName = (0, shared_1.camelize)(componentTag);
137
+ const PascalName = (0, shared_1.capitalize)(camelName);
138
+ return tag === componentTag || tag === camelName || tag === PascalName;
139
+ });
140
+ }
141
+ function parseBindingComponents(templateBindingComponents, scriptBindingComponents) {
142
+ const bindingComponents = { ...templateBindingComponents };
143
+ Object.keys(scriptBindingComponents).forEach((id) => {
144
+ const { tag } = scriptBindingComponents[id];
145
+ const name = findBindingComponent(tag, templateBindingComponents);
146
+ if (name) {
147
+ bindingComponents[id] = bindingComponents[name];
148
+ }
149
+ });
150
+ return bindingComponents;
151
+ }
152
+ function parseImports(mainImports, scriptImports, templateImports) {
153
+ const imports = [...mainImports, ...templateImports, ...scriptImports];
154
+ return imports;
155
+ }
156
+ /**
157
+ * 解析 template
158
+ * @param filename
159
+ * @param code
160
+ * @param ast
161
+ * @param options
162
+ * @returns
163
+ */
164
+ async function parseTemplateDescriptor(filename, ast, options) {
165
+ // 外置时查找所有 vue component import
166
+ const imports = options.isExternal
167
+ ? await parseVueComponentImports(filename, ast.body.filter((node) => (0, types_1.isImportDeclaration)(node)), options.resolve)
168
+ : [];
169
+ const descriptor = {
170
+ bindingComponents: findBindingComponents(ast.body),
171
+ imports,
172
+ };
173
+ templateDescriptors.set(filename, descriptor);
174
+ return descriptor;
175
+ }
176
+ exports.parseTemplateDescriptor = parseTemplateDescriptor;
177
+ async function parseGlobalDescriptor(filename, ast, resolve) {
178
+ // 外置时查找所有 vue component import
179
+ 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'));
180
+ return {
181
+ bindingComponents: parseGlobalComponents(ast),
182
+ imports,
183
+ };
184
+ }
185
+ /**
186
+ * 解析 script
187
+ * @param filename
188
+ * @param code
189
+ * @param ast
190
+ * @param options
191
+ * @returns
192
+ */
193
+ async function parseScriptDescriptor(filename, ast, options) {
194
+ // 外置时查找所有 vue component import
195
+ const imports = options.isExternal
196
+ ? await parseVueComponentImports(filename, ast.body.filter((node) => (0, types_1.isImportDeclaration)(node)), options.resolve)
197
+ : [];
198
+ const descriptor = {
199
+ bindingComponents: parseComponents(ast),
200
+ imports,
201
+ };
202
+ scriptDescriptors.set(filename, descriptor);
203
+ return descriptor;
204
+ }
205
+ exports.parseScriptDescriptor = parseScriptDescriptor;
206
+ /**
207
+ * 解析编译器生成的 bindingComponents
208
+ * @param ast
209
+ * @returns
210
+ */
211
+ function findBindingComponents(ast) {
212
+ const mapping = findUnpluginComponents(ast);
213
+ for (const node of ast) {
214
+ if (!(0, types_1.isVariableDeclaration)(node)) {
215
+ continue;
216
+ }
217
+ const declarator = node.declarations[0];
218
+ if ((0, types_1.isIdentifier)(declarator.id) &&
219
+ declarator.id.name === constants_1.BINDING_COMPONENTS) {
220
+ const bindingComponents = JSON.parse(declarator.init.value);
221
+ return Object.keys(bindingComponents).reduce((bindings, tag) => {
222
+ const { name, type } = bindingComponents[tag];
223
+ bindings[mapping[name] || name] = {
224
+ tag,
225
+ type: type,
226
+ };
227
+ return bindings;
228
+ }, {});
229
+ }
230
+ }
231
+ return {};
232
+ }
233
+ /**
234
+ * 兼容:unplugin_components
235
+ * https://github.com/dcloudio/uni-app/issues/3057
236
+ * @param ast
237
+ * @returns
238
+ */
239
+ function findUnpluginComponents(ast) {
240
+ const res = Object.create(null);
241
+ // if(!Array){}
242
+ const ifStatement = ast.find((statement) => (0, types_1.isIfStatement)(statement) &&
243
+ (0, types_1.isUnaryExpression)(statement.test) &&
244
+ statement.test.operator === '!' &&
245
+ (0, types_1.isIdentifier)(statement.test.argument) &&
246
+ statement.test.argument.name === 'Array');
247
+ if (!ifStatement) {
248
+ return res;
249
+ }
250
+ if (!(0, types_1.isBlockStatement)(ifStatement.consequent)) {
251
+ return res;
252
+ }
253
+ for (const node of ifStatement.consequent.body) {
254
+ if (!(0, types_1.isVariableDeclaration)(node)) {
255
+ continue;
256
+ }
257
+ const { id, init } = node.declarations[0];
258
+ if ((0, types_1.isIdentifier)(id) &&
259
+ (0, types_1.isIdentifier)(init) &&
260
+ init.name.includes('unplugin_components')) {
261
+ res[id.name] = init.name;
262
+ }
263
+ }
264
+ return res;
265
+ }
266
+ /**
267
+ * 查找全局组件定义:app.component('component-a',{})
268
+ * @param ast
269
+ * @returns
270
+ */
271
+ function parseGlobalComponents(ast) {
272
+ const bindingComponents = {};
273
+ estree_walker_1.walk(ast, {
274
+ enter(child) {
275
+ if (!(0, types_1.isCallExpression)(child)) {
276
+ return;
277
+ }
278
+ const { callee } = child;
279
+ // .component
280
+ if (!(0, types_1.isMemberExpression)(callee) ||
281
+ !(0, types_1.isIdentifier)(callee.property) ||
282
+ callee.property.name !== 'component') {
283
+ return;
284
+ }
285
+ // .component('component-a',{})
286
+ const args = child.arguments;
287
+ if (args.length !== 2) {
288
+ return;
289
+ }
290
+ const [name, value] = args;
291
+ if (!(0, types_1.isStringLiteral)(name)) {
292
+ return console.warn(messages_1.M['mp.component.args[0]']);
293
+ }
294
+ if (!(0, types_1.isIdentifier)(value)) {
295
+ return console.warn(messages_1.M['mp.component.args[1]']);
296
+ }
297
+ bindingComponents[value.name] = {
298
+ tag: name.value,
299
+ type: 'unknown',
300
+ };
301
+ },
302
+ });
303
+ return bindingComponents;
304
+ }
305
+ /**
306
+ * 从 components 中查找定义的组件
307
+ * @param ast
308
+ * @param bindingComponents
309
+ */
310
+ function parseComponents(ast) {
311
+ const bindingComponents = {};
312
+ estree_walker_1.walk(ast, {
313
+ enter(child) {
314
+ if (!(0, types_1.isObjectExpression)(child)) {
315
+ return;
316
+ }
317
+ const componentsProp = child.properties.find((prop) => (0, types_1.isObjectProperty)(prop) &&
318
+ (0, types_1.isIdentifier)(prop.key) &&
319
+ prop.key.name === 'components');
320
+ if (!componentsProp) {
321
+ return;
322
+ }
323
+ const componentsExpr = componentsProp.value;
324
+ if (!(0, types_1.isObjectExpression)(componentsExpr)) {
325
+ return;
326
+ }
327
+ componentsExpr.properties.forEach((prop) => {
328
+ if (!(0, types_1.isObjectProperty)(prop)) {
329
+ return;
330
+ }
331
+ if (!(0, types_1.isIdentifier)(prop.key) && !(0, types_1.isStringLiteral)(prop.key)) {
332
+ return;
333
+ }
334
+ if (!(0, types_1.isIdentifier)(prop.value)) {
335
+ return;
336
+ }
337
+ bindingComponents[prop.value.name] = {
338
+ tag: (0, types_1.isIdentifier)(prop.key) ? prop.key.name : prop.key.value,
339
+ type: 'unknown',
340
+ };
341
+ });
342
+ },
343
+ });
344
+ return bindingComponents;
345
+ }
346
+ /**
347
+ * vue component imports
348
+ * @param filename
349
+ * @param imports
350
+ * @param resolve
351
+ * @returns
352
+ */
353
+ async function parseVueComponentImports(importer, imports, resolve) {
354
+ const vueComponentImports = [];
355
+ for (let i = 0; i < imports.length; i++) {
356
+ const { source } = imports[i];
357
+ if ((0, utils_2.parseVueRequest)(source.value).query.vue) {
358
+ continue;
359
+ }
360
+ const resolveId = await resolve(source.value, importer);
361
+ if (!resolveId) {
362
+ continue;
363
+ }
364
+ const { filename } = (0, utils_2.parseVueRequest)(resolveId.id);
365
+ if (constants_1.EXTNAME_VUE_RE.test(filename)) {
366
+ source.value = resolveId.id;
367
+ vueComponentImports.push(imports[i]);
368
+ }
369
+ }
370
+ return vueComponentImports;
371
+ }
372
+ /**
373
+ * static import => dynamic import
374
+ * @param code
375
+ * @param imports
376
+ * @param dynamicImport
377
+ * @returns
378
+ */
379
+ async function transformDynamicImports(code, imports, dynamicImport) {
380
+ if (!imports.length) {
381
+ return code;
382
+ }
383
+ const s = new magic_string_1.default(code);
384
+ for (let i = 0; i < imports.length; i++) {
385
+ const { start, end, specifiers: [specifier], source, } = imports[i];
386
+ s.overwrite(start, end, dynamicImport(specifier.local.name, source.value) + ';');
387
+ }
388
+ return s.toString();
389
+ }
390
+ exports.transformDynamicImports = transformDynamicImports;
@@ -1,3 +1,3 @@
1
1
  export declare function getPreVueContext(): any;
2
2
  export declare function getPreNVueContext(): any;
3
- export declare function initPreContext(platform: UniApp.PLATFORM, userPreContext?: Record<string, boolean>): void;
3
+ export declare function initPreContext(platform: UniApp.PLATFORM, userPreContext?: Record<string, boolean> | string): void;
@@ -60,9 +60,17 @@ function initPreContext(platform, userPreContext) {
60
60
  defaultContext.QUICKAPP_WEBVIEW = true;
61
61
  }
62
62
  if (userPreContext) {
63
- Object.keys(userPreContext).forEach((key) => {
64
- defaultContext[normalizeKey(key)] = !!userPreContext[key];
65
- });
63
+ if ((0, shared_1.isString)(userPreContext)) {
64
+ try {
65
+ userPreContext = JSON.parse(userPreContext);
66
+ }
67
+ catch (e) { }
68
+ }
69
+ if ((0, shared_1.isPlainObject)(userPreContext)) {
70
+ Object.keys(userPreContext).forEach((key) => {
71
+ defaultContext[normalizeKey(key)] = !!userPreContext[key];
72
+ });
73
+ }
66
74
  }
67
75
  (0, shared_1.extend)(preVueContext, defaultContext, vueContext);
68
76
  (0, shared_1.extend)(preNVueContext, defaultContext, nvueContext);
@@ -0,0 +1,10 @@
1
+ export declare function parseScripts(name: string, pkgPath: string): {
2
+ name: string;
3
+ platform: keyof UniApp.PagesJsonPagePlatformStyle;
4
+ define: {
5
+ [name: string]: string;
6
+ };
7
+ context: {
8
+ [name: string]: boolean;
9
+ };
10
+ } | undefined;
@@ -0,0 +1,30 @@
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.parseScripts = void 0;
7
+ const fs_1 = __importDefault(require("fs"));
8
+ function parseScripts(name, pkgPath) {
9
+ var _a, _b, _c;
10
+ if (!fs_1.default.existsSync(pkgPath)) {
11
+ return;
12
+ }
13
+ const pkg = JSON.parse(fs_1.default.readFileSync(pkgPath, 'utf8'));
14
+ const options = (_b = (_a = pkg['uni-app']) === null || _a === void 0 ? void 0 : _a.scripts) === null || _b === void 0 ? void 0 : _b[name];
15
+ if (!options) {
16
+ return;
17
+ }
18
+ if (!((_c = options.env) === null || _c === void 0 ? void 0 : _c.UNI_PLATFORM)) {
19
+ console.error(`package.json->uni-app->scripts->${name}->env->UNI_PLATFORM is required`);
20
+ process.exit(0);
21
+ }
22
+ const { UNI_PLATFORM, ...define } = options.env;
23
+ return {
24
+ name: name,
25
+ platform: UNI_PLATFORM,
26
+ define,
27
+ context: options.define || {},
28
+ };
29
+ }
30
+ exports.parseScripts = parseScripts;
@@ -1,7 +1,7 @@
1
1
  /// <reference types="node" />
2
2
  import { Plugin } from '../plugin';
3
3
  import { ResolvedConfig } from '../config';
4
- import { PluginContext, RenderedChunk } from 'rollup';
4
+ import type { OutputOptions, PluginContext, RenderedChunk } from 'rollup';
5
5
  export declare const assetUrlRE: RegExp;
6
6
  export declare const chunkToEmittedAssetsMap: WeakMap<RenderedChunk, Set<string>>;
7
7
  /**
@@ -12,5 +12,29 @@ export declare function registerAssetToChunk(chunk: RenderedChunk, file: string)
12
12
  export declare function checkPublicFile(url: string, { publicDir }: ResolvedConfig): string | undefined;
13
13
  export declare function fileToUrl(id: string, config: ResolvedConfig, ctx: PluginContext, canInline?: boolean): string;
14
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;
15
39
  export declare function getAssetHash(content: Buffer): string;
16
40
  export declare function urlToBuiltUrl(url: string, importer: string, config: ResolvedConfig, pluginContext: PluginContext): string;
@@ -22,7 +22,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
22
22
  return (mod && mod.__esModule) ? mod : { "default": mod };
23
23
  };
24
24
  Object.defineProperty(exports, "__esModule", { value: true });
25
- exports.urlToBuiltUrl = exports.getAssetHash = exports.getAssetFilename = exports.fileToUrl = exports.checkPublicFile = exports.registerAssetToChunk = exports.assetPlugin = exports.chunkToEmittedAssetsMap = exports.assetUrlRE = void 0;
25
+ exports.urlToBuiltUrl = exports.getAssetHash = exports.assetFileNamesToFileName = exports.getAssetFilename = exports.fileToUrl = exports.checkPublicFile = exports.registerAssetToChunk = exports.assetPlugin = exports.chunkToEmittedAssetsMap = exports.assetUrlRE = void 0;
26
26
  const path_1 = __importDefault(require("path"));
27
27
  const url_1 = require("url");
28
28
  const lite_1 = __importDefault(require("mime/lite"));
@@ -142,6 +142,66 @@ function getAssetFilename(hash, config) {
142
142
  return (_a = assetHashToFilenameMap.get(config)) === null || _a === void 0 ? void 0 : _a.get(hash);
143
143
  }
144
144
  exports.getAssetFilename = getAssetFilename;
145
+ /**
146
+ * converts the source filepath of the asset to the output filename based on the assetFileNames option. \
147
+ * this function imitates the behavior of rollup.js. \
148
+ * https://rollupjs.org/guide/en/#outputassetfilenames
149
+ *
150
+ * @example
151
+ * ```ts
152
+ * const content = Buffer.from('text');
153
+ * const fileName = assetFileNamesToFileName(
154
+ * 'assets/[name].[hash][extname]',
155
+ * '/path/to/file.txt',
156
+ * getAssetHash(content),
157
+ * content
158
+ * )
159
+ * // fileName: 'assets/file.982d9e3e.txt'
160
+ * ```
161
+ *
162
+ * @param assetFileNames filename pattern. e.g. `'assets/[name].[hash][extname]'`
163
+ * @param file filepath of the asset
164
+ * @param contentHash hash of the asset. used for `'[hash]'` placeholder
165
+ * @param content content of the asset. passed to `assetFileNames` if `assetFileNames` is a function
166
+ * @returns output filename
167
+ */
168
+ function assetFileNamesToFileName(assetFileNames, file, contentHash, content) {
169
+ const basename = path_1.default.basename(file);
170
+ // placeholders for `assetFileNames`
171
+ // `hash` is slightly different from the rollup's one
172
+ const extname = path_1.default.extname(basename);
173
+ const ext = extname.substring(1);
174
+ const name = basename.slice(0, -extname.length);
175
+ const hash = contentHash;
176
+ if (typeof assetFileNames === 'function') {
177
+ assetFileNames = assetFileNames({
178
+ name: file,
179
+ source: content,
180
+ type: 'asset',
181
+ });
182
+ if (typeof assetFileNames !== 'string') {
183
+ throw new TypeError('assetFileNames must return a string');
184
+ }
185
+ }
186
+ else if (typeof assetFileNames !== 'string') {
187
+ throw new TypeError('assetFileNames must be a string or a function');
188
+ }
189
+ const fileName = assetFileNames.replace(/\[\w+\]/g, (placeholder) => {
190
+ switch (placeholder) {
191
+ case '[ext]':
192
+ return ext;
193
+ case '[extname]':
194
+ return extname;
195
+ case '[hash]':
196
+ return hash;
197
+ case '[name]':
198
+ return name;
199
+ }
200
+ throw new Error(`invalid placeholder ${placeholder} in assetFileNames "${assetFileNames}"`);
201
+ });
202
+ return fileName;
203
+ }
204
+ exports.assetFileNamesToFileName = assetFileNamesToFileName;
145
205
  /**
146
206
  * Register an asset to be emitted as part of the bundle (if necessary)
147
207
  * and returns the resolved public URL
@@ -167,7 +227,10 @@ function fileToBuiltUrl(id, config, pluginContext, skipPublicCheck = false, canI
167
227
  const contentHash = getAssetHash(content);
168
228
  const { search, hash } = (0, url_1.parse)(id);
169
229
  const postfix = (search || '') + (hash || '');
170
- const fileName = path_1.default.posix.relative((0, utils_1.normalizePath)(process.env.UNI_INPUT_DIR), file);
230
+ const inputDir = (0, utils_1.normalizePath)(process.env.UNI_INPUT_DIR);
231
+ let fileName = file.startsWith(inputDir)
232
+ ? path_1.default.posix.relative(inputDir, file)
233
+ : assetFileNamesToFileName(path_1.default.posix.join(config.build.assetsDir, '[name].[hash][extname]'), file, contentHash, content);
171
234
  if (!map.has(contentHash)) {
172
235
  map.set(contentHash, fileName);
173
236
  }
@@ -381,9 +381,13 @@ function getTestTemplate(test) {
381
381
  return new Function("context", "with (context||{}){ return ( " + test + " ); }");
382
382
  }
383
383
 
384
- function testPasses(test,context) {
385
- var testFn = getTestTemplate(test);
386
- return testFn(context, getDeepPropFromObj);
384
+ // fixed by xxxxxx
385
+ function testPasses(test, context) {
386
+ var testFn = getTestTemplate(test)
387
+ try {
388
+ return testFn(context, getDeepPropFromObj)
389
+ } catch (e) {}
390
+ return false
387
391
  }
388
392
 
389
393
  function getFileContents(path, failSilent, requesterPath) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dcloudio/uni-cli-shared",
3
- "version": "3.0.0-alpha-3030220211217007",
3
+ "version": "3.0.0-alpha-3030220211217012",
4
4
  "description": "@dcloudio/uni-cli-shared",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -20,9 +20,9 @@
20
20
  "dependencies": {
21
21
  "@babel/parser": "^7.16.4",
22
22
  "@babel/types": "^7.16.0",
23
- "@dcloudio/uni-i18n": "3.0.0-alpha-3030220211217007",
24
- "@dcloudio/uni-shared": "3.0.0-alpha-3030220211217007",
25
- "@rollup/pluginutils": "^4.1.1",
23
+ "@dcloudio/uni-i18n": "3.0.0-alpha-3030220211217012",
24
+ "@dcloudio/uni-shared": "3.0.0-alpha-3030220211217012",
25
+ "@rollup/pluginutils": "^4.1.2",
26
26
  "@vue/compiler-core": "3.2.26",
27
27
  "@vue/compiler-dom": "3.2.26",
28
28
  "@vue/compiler-sfc": "3.2.26",
@@ -61,6 +61,6 @@
61
61
  "@types/mime": "^2.0.3",
62
62
  "@types/module-alias": "^2.0.1",
63
63
  "@types/stylus": "^0.48.36",
64
- "postcss": "^8.3.8"
64
+ "postcss": "^8.4.5"
65
65
  }
66
66
  }
@@ -1,14 +0,0 @@
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 {};
@@ -1,203 +0,0 @@
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.transformVueComponentImports = void 0;
7
- const parser_1 = require("@babel/parser");
8
- const types_1 = require("@babel/types");
9
- const shared_1 = require("@vue/shared");
10
- const estree_walker_1 = require("estree-walker");
11
- const magic_string_1 = __importDefault(require("magic-string"));
12
- const uni_shared_1 = require("@dcloudio/uni-shared");
13
- const messages_1 = require("../messages");
14
- const constants_1 = require("../constants");
15
- const utils_1 = require("../utils");
16
- async function transformVueComponentImports(code, importer, { root, resolve, global, dynamicImport, babelParserPlugins, }) {
17
- if (!global && !code.includes(constants_1.BINDING_COMPONENTS)) {
18
- return { code, usingComponents: {} };
19
- }
20
- const s = new magic_string_1.default(code);
21
- const scriptAst = (0, parser_1.parse)(code, {
22
- plugins: (0, utils_1.normalizeParsePlugins)(importer, babelParserPlugins),
23
- sourceType: 'module',
24
- }).program;
25
- const imports = findVueComponentImports(scriptAst.body, global
26
- ? parseGlobalComponents(scriptAst)
27
- : parseComponents(scriptAst, findBindingComponents(scriptAst.body)));
28
- const usingComponents = {};
29
- for (let i = 0; i < imports.length; i++) {
30
- const { tag, import: { start, end, specifiers: [specifier], source, }, } = imports[i];
31
- const resolveId = await resolve(source.value, importer);
32
- if (resolveId) {
33
- s.overwrite(start, end, dynamicImport(specifier.local.name, resolveId.id) + ';');
34
- const componentName = (0, shared_1.hyphenate)(tag);
35
- if (!usingComponents[componentName]) {
36
- usingComponents[componentName] = (0, uni_shared_1.addLeadingSlash)((0, utils_1.removeExt)((0, utils_1.normalizeMiniProgramFilename)(resolveId.id, root)));
37
- }
38
- }
39
- }
40
- return { code: s.toString(), usingComponents };
41
- }
42
- exports.transformVueComponentImports = transformVueComponentImports;
43
- /**
44
- * 解析编译器生成的 bindingComponents
45
- * @param ast
46
- * @returns
47
- */
48
- function findBindingComponents(ast) {
49
- const mapping = findUnpluginComponents(ast);
50
- for (const node of ast) {
51
- if (!(0, types_1.isVariableDeclaration)(node)) {
52
- continue;
53
- }
54
- const declarator = node.declarations[0];
55
- if ((0, types_1.isIdentifier)(declarator.id) &&
56
- declarator.id.name === constants_1.BINDING_COMPONENTS) {
57
- const bindingComponents = JSON.parse(declarator.init.value);
58
- return Object.keys(bindingComponents).reduce((bindings, tag) => {
59
- const { name, type } = bindingComponents[tag];
60
- bindings[mapping[name] || name] = {
61
- tag,
62
- type: type,
63
- };
64
- return bindings;
65
- }, {});
66
- }
67
- }
68
- return {};
69
- }
70
- function findUnpluginComponents(ast) {
71
- const res = Object.create(null);
72
- // if(!Array){}
73
- const ifStatement = ast.find((statement) => (0, types_1.isIfStatement)(statement) &&
74
- (0, types_1.isUnaryExpression)(statement.test) &&
75
- statement.test.operator === '!' &&
76
- (0, types_1.isIdentifier)(statement.test.argument) &&
77
- statement.test.argument.name === 'Array');
78
- if (!ifStatement) {
79
- return res;
80
- }
81
- if (!(0, types_1.isBlockStatement)(ifStatement.consequent)) {
82
- return res;
83
- }
84
- for (const node of ifStatement.consequent.body) {
85
- if (!(0, types_1.isVariableDeclaration)(node)) {
86
- continue;
87
- }
88
- const { id, init } = node.declarations[0];
89
- if ((0, types_1.isIdentifier)(id) &&
90
- (0, types_1.isIdentifier)(init) &&
91
- init.name.includes('unplugin_components')) {
92
- res[id.name] = init.name;
93
- }
94
- }
95
- return res;
96
- }
97
- /**
98
- * 查找全局组件定义:app.component('component-a',{})
99
- * @param ast
100
- * @returns
101
- */
102
- function parseGlobalComponents(ast) {
103
- const bindingComponents = {};
104
- estree_walker_1.walk(ast, {
105
- enter(child) {
106
- if (!(0, types_1.isCallExpression)(child)) {
107
- return;
108
- }
109
- const { callee } = child;
110
- // .component
111
- if (!(0, types_1.isMemberExpression)(callee) ||
112
- !(0, types_1.isIdentifier)(callee.property) ||
113
- callee.property.name !== 'component') {
114
- return;
115
- }
116
- // .component('component-a',{})
117
- const args = child.arguments;
118
- if (args.length !== 2) {
119
- return;
120
- }
121
- const [name, value] = args;
122
- if (!(0, types_1.isStringLiteral)(name)) {
123
- return console.warn(messages_1.M['mp.component.args[0]']);
124
- }
125
- if (!(0, types_1.isIdentifier)(value)) {
126
- return console.warn(messages_1.M['mp.component.args[1]']);
127
- }
128
- bindingComponents[value.name] = {
129
- tag: name.value,
130
- type: 'unknown',
131
- };
132
- },
133
- });
134
- return bindingComponents;
135
- }
136
- /**
137
- * 从 components 中查找定义的组件,修改 bindingComponents
138
- * @param ast
139
- * @param bindingComponents
140
- */
141
- function parseComponents(ast, bindingComponents) {
142
- ;
143
- estree_walker_1.walk(ast, {
144
- enter(child) {
145
- if (!(0, types_1.isObjectExpression)(child)) {
146
- return;
147
- }
148
- const componentsProp = child.properties.find((prop) => (0, types_1.isObjectProperty)(prop) &&
149
- (0, types_1.isIdentifier)(prop.key) &&
150
- prop.key.name === 'components');
151
- if (!componentsProp) {
152
- return;
153
- }
154
- const componentsExpr = componentsProp.value;
155
- if (!(0, types_1.isObjectExpression)(componentsExpr)) {
156
- return;
157
- }
158
- componentsExpr.properties.forEach((prop) => {
159
- if (!(0, types_1.isObjectProperty)(prop)) {
160
- return;
161
- }
162
- if (!(0, types_1.isIdentifier)(prop.key) && !(0, types_1.isStringLiteral)(prop.key)) {
163
- return;
164
- }
165
- if (!(0, types_1.isIdentifier)(prop.value)) {
166
- return;
167
- }
168
- const tag = (0, types_1.isIdentifier)(prop.key) ? prop.key.name : prop.key.value;
169
- const name = findBindingComponent(tag, bindingComponents);
170
- if (name) {
171
- bindingComponents[prop.value.name] = bindingComponents[name];
172
- }
173
- });
174
- },
175
- });
176
- return bindingComponents;
177
- }
178
- function findBindingComponent(tag, bindingComponents) {
179
- return Object.keys(bindingComponents).find((name) => {
180
- const componentTag = bindingComponents[name].tag;
181
- const camelName = (0, shared_1.camelize)(componentTag);
182
- const PascalName = (0, shared_1.capitalize)(camelName);
183
- return tag === componentTag || tag === camelName || tag === PascalName;
184
- });
185
- }
186
- function findVueComponentImports(ast, bindingComponents) {
187
- const imports = [];
188
- for (let i = 0; i < ast.length; i++) {
189
- const node = ast[i];
190
- if (!(0, types_1.isImportDeclaration)(node)) {
191
- continue;
192
- }
193
- if (node.specifiers.length !== 1) {
194
- continue;
195
- }
196
- const { name } = node.specifiers[0].local;
197
- if (!bindingComponents[name]) {
198
- continue;
199
- }
200
- imports.push({ tag: bindingComponents[name].tag, import: node });
201
- }
202
- return imports;
203
- }