@omnia/tooling-vue 8.0.103-dev → 8.0.104-dev

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.
@@ -10,17 +10,39 @@ export type OutputInfo = {
10
10
  };
11
11
  };
12
12
  };
13
+ type ComponentPropInfo = {
14
+ type: string;
15
+ description?: string;
16
+ required?: boolean;
17
+ defaultValue?: any;
18
+ };
19
+ type ComponentInfo = {
20
+ functionSignature?: boolean;
21
+ props: {
22
+ [name: string]: ComponentPropInfo;
23
+ };
24
+ models: {
25
+ [name: string]: ComponentPropInfo;
26
+ };
27
+ slots: {
28
+ [name: string]: ComponentPropInfo;
29
+ };
30
+ emits: {
31
+ [name: string]: ComponentPropInfo;
32
+ };
33
+ };
13
34
  export declare const isExtensionEnv: boolean;
14
- export declare function getBuildOption(): import("@omnia/tooling-composers").BuildOptions;
15
- export declare function registerOutputInfo(info: OutputInfo): void;
16
- export declare function transformVueComponent(content: string, filePath: string): string;
17
- export declare function convertManifestPathToEntryPath(pathToManifest: any, pathsInManifest: Array<string>): string[];
18
35
  export declare const buildContext: {
19
36
  isManifestsChanged: boolean;
20
37
  };
21
- export declare var cacheKeys: {
38
+ export declare const cacheKeys: {
22
39
  bundleManifests: string;
23
40
  };
41
+ export declare function getBuildOption(): import("@omnia/tooling-composers").BuildOptions;
42
+ export declare function registerOutputInfo(info: OutputInfo): void;
43
+ export declare function transformDefineVueComponent(content: string, filePath: string): string;
44
+ export declare function extractVueComponentInfo(filePath: string): ComponentInfo;
45
+ export declare function convertManifestPathToEntryPath(pathToManifest: any, pathsInManifest: Array<string>): string[];
24
46
  export declare class ConfigurationManager {
25
47
  private static _webComponentTypings;
26
48
  private static _outputInfoManagaer;
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ConfigurationManager = exports.cacheKeys = exports.buildContext = exports.convertManifestPathToEntryPath = exports.transformVueComponent = exports.registerOutputInfo = exports.getBuildOption = exports.isExtensionEnv = void 0;
3
+ exports.ConfigurationManager = exports.convertManifestPathToEntryPath = exports.extractVueComponentInfo = exports.transformDefineVueComponent = exports.registerOutputInfo = exports.getBuildOption = exports.cacheKeys = exports.buildContext = exports.isExtensionEnv = void 0;
4
4
  const tslib_1 = require("tslib");
5
5
  const globby_1 = require("globby");
6
6
  const path_1 = tslib_1.__importDefault(require("path"));
@@ -8,32 +8,304 @@ const fsExtra = tslib_1.__importStar(require("fs-extra"));
8
8
  const del_1 = tslib_1.__importDefault(require("del"));
9
9
  const fs_1 = tslib_1.__importDefault(require("fs"));
10
10
  const tooling_composers_1 = require("@omnia/tooling-composers");
11
- const _outputInfos = [];
11
+ const core_1 = require("@swc/core");
12
+ const tooling_1 = require("@omnia/tooling");
13
+ var DefineVueType;
14
+ (function (DefineVueType) {
15
+ DefineVueType[DefineVueType["Prop"] = 0] = "Prop";
16
+ DefineVueType[DefineVueType["Model"] = 1] = "Model";
17
+ DefineVueType[DefineVueType["Slot"] = 2] = "Slot";
18
+ DefineVueType[DefineVueType["Emit"] = 3] = "Emit";
19
+ })(DefineVueType || (DefineVueType = {}));
20
+ const outputInfos = [];
12
21
  const basePathProcess = process.cwd();
22
+ const componentInfos = {};
13
23
  exports.isExtensionEnv = fs_1.default.existsSync(basePathProcess + "/node_modules/@omnia/tooling/package.json");
24
+ exports.buildContext = {
25
+ isManifestsChanged: false
26
+ };
27
+ exports.cacheKeys = {
28
+ //buildManifestMetadatas: "buildManifestMetadatas",
29
+ bundleManifests: "bundleManifests"
30
+ };
14
31
  function getBuildOption() {
15
32
  return tooling_composers_1.BuildConfigurationRegistry.getBuildOptions();
16
33
  }
17
34
  exports.getBuildOption = getBuildOption;
18
35
  function registerOutputInfo(info) {
19
- _outputInfos.push(info);
36
+ outputInfos.push(info);
20
37
  }
21
38
  exports.registerOutputInfo = registerOutputInfo;
22
- function transformVueComponent(content, filePath) {
39
+ function transformDefineVueComponent(content, filePath) {
23
40
  let result = content;
24
41
  const ext = path_1.default.extname(filePath);
25
42
  if (ext === ".tsx") {
26
- result = replaceWebComponentNamespaceMapping(content);
43
+ result = replaceComponentNamespace(content);
44
+ const componentInfo = extractVueComponentInfo(filePath);
27
45
  const wcs = tooling_composers_1.ComponentRegistry.getComponentRegistrations();
28
46
  if (wcs.find(wc => filePath.indexOf(wc.componentOptions.entryPointPath) > -1)) {
29
- result = result.replace(/defineVueComponent/g, "defineVueWebComponent");
47
+ if (componentInfo.functionSignature) {
48
+ result = result.replace(/defineVueComponent/g, "internalDVWCByFS");
49
+ result = result.replace(/internalDVWCByFS(\s*)\(/g, `internalDVWCByFS(${convertComponentOptionsToString(componentInfo)},`);
50
+ // console.log(result)
51
+ }
52
+ else {
53
+ result = result.replace(/defineVueComponent/g, "defineVueWebComponent");
54
+ }
55
+ }
56
+ else if (componentInfo.functionSignature) {
57
+ result = result.replace(/defineVueComponent/g, "internalDVCByFS");
58
+ result = result.replace(/internalDVCByFS(\s*)\(/g, `internalDVCByFS(${convertComponentOptionsToString(componentInfo)},`);
59
+ }
60
+ }
61
+ return result;
62
+ }
63
+ exports.transformDefineVueComponent = transformDefineVueComponent;
64
+ function extractVueComponentInfo(filePath) {
65
+ if (!tooling_1.isServing && componentInfos[filePath]) {
66
+ return componentInfos[filePath];
67
+ }
68
+ const componentInfo = {
69
+ emits: {},
70
+ models: {},
71
+ props: {},
72
+ slots: {}
73
+ };
74
+ componentInfos[filePath] = componentInfo;
75
+ const wcParseResult = (0, core_1.parseFileSync)(filePath, {
76
+ syntax: 'typescript',
77
+ target: 'es2020',
78
+ tsx: true,
79
+ decorators: true,
80
+ dynamicImport: true
81
+ });
82
+ let foundDefineVueComponent = false;
83
+ wcParseResult.body.forEach(b => {
84
+ if (b?.expression?.callee?.value === "defineVueComponent") {
85
+ if (foundDefineVueComponent) {
86
+ throw new Error(`${filePath}: have more than once call defineVueComponent -> Only support define once vue component on each .tsx file.`);
87
+ }
88
+ foundDefineVueComponent = true;
89
+ const callExpression = b.expression;
90
+ if (callExpression.arguments[0].expression.type === "ArrowFunctionExpression") {
91
+ componentInfo.functionSignature = true;
92
+ const params = callExpression.arguments[0].expression.params;
93
+ const typeParams = params[0].typeAnnotation.typeAnnotation.typeParams.params;
94
+ const props = typeParams[0];
95
+ props.types.forEach((t) => {
96
+ const typeName = t.typeName.value;
97
+ if (typeName === "DefineProp" || typeName === "DefineVModel") {
98
+ const params = t.typeParams.params;
99
+ const name = extractTypeValue(params[0]) || "modelValue";
100
+ const type = extractTypeValue(params[1]);
101
+ const required = params.length > 2 ? extractTypeValue(params[2]) : false;
102
+ const defaultValue = params.length > 3 ? extractTypeValue(params[3], true) : undefined;
103
+ const description = params.length > 4 ? extractTypeValue(params[4]) : "";
104
+ const info = {
105
+ type: type,
106
+ description: description,
107
+ required: required.toString().toLowerCase() === "true" ? true : false
108
+ };
109
+ if (defaultValue !== undefined) {
110
+ info.defaultValue = defaultValue;
111
+ }
112
+ if (typeName === "DefineVModel") {
113
+ componentInfo.models[name] = info;
114
+ }
115
+ else { // props
116
+ componentInfo.props[name] = info;
117
+ }
118
+ }
119
+ });
120
+ if (typeParams.length > 1) {
121
+ const emits = typeParams[1];
122
+ emits.types.forEach((t) => {
123
+ const typeName = t.typeName.value;
124
+ if (typeName === "DefineEmit") {
125
+ const params = t.typeParams.params;
126
+ const name = extractTypeValue(params[0]);
127
+ const type = extractTypeValue(params[1]);
128
+ const description = params.length > 2 ? extractTypeValue(params[2]) : "";
129
+ componentInfo.emits[name] = {
130
+ type: type,
131
+ description: description,
132
+ };
133
+ }
134
+ });
135
+ }
136
+ if (typeParams.length > 2) {
137
+ const slots = typeParams[2];
138
+ slots.types.forEach((t) => {
139
+ const typeName = t.typeName.value;
140
+ if (typeName === "DefineSlot") {
141
+ const params = t.typeParams.params;
142
+ const name = extractTypeValue(params[0]);
143
+ const type = extractTypeValue(params[1]);
144
+ const description = params.length > 2 ? extractTypeValue(params[2]) : "";
145
+ componentInfo.slots[name] = {
146
+ type: type,
147
+ description: description,
148
+ };
149
+ }
150
+ });
151
+ }
152
+ }
153
+ else {
154
+ callExpression.arguments[0].expression
155
+ .properties?.filter(p => p.key.value === "props"
156
+ || p.key.value === "emits")
157
+ ?.forEach(propsIdentifier => {
158
+ if (propsIdentifier) {
159
+ propsIdentifier.value
160
+ .properties?.forEach(p => {
161
+ const em = p.arguments;
162
+ if (em?.callee?.property?.value === "doc$") {
163
+ const PropertyResult = {
164
+ type: null,
165
+ propertyTypeAsString: "",
166
+ name: ""
167
+ };
168
+ getPropertyInfo(em, PropertyResult);
169
+ switch (PropertyResult.type) {
170
+ case DefineVueType.Prop:
171
+ componentInfo.props[PropertyResult.name] = {
172
+ type: PropertyResult.propertyTypeAsString,
173
+ description: em.arguments[0].expression.value
174
+ };
175
+ break;
176
+ case DefineVueType.Model:
177
+ componentInfo.models[PropertyResult.name] = {
178
+ type: PropertyResult.propertyTypeAsString,
179
+ description: em.arguments[0].expression.value
180
+ };
181
+ break;
182
+ case DefineVueType.Emit:
183
+ componentInfo.emits[PropertyResult.name] = {
184
+ type: PropertyResult.propertyTypeAsString,
185
+ description: em.arguments[0].expression.value
186
+ };
187
+ break;
188
+ case DefineVueType.Slot:
189
+ em.arguments[0].expression
190
+ .properties
191
+ .forEach(p => {
192
+ const slotName = p.key.value;
193
+ componentInfo.slots[slotName] = {
194
+ type: PropertyResult.propertyTypeAsObject[slotName],
195
+ description: p.value.value
196
+ };
197
+ });
198
+ break;
199
+ default:
200
+ break;
201
+ }
202
+ }
203
+ });
204
+ }
205
+ });
206
+ }
30
207
  }
208
+ });
209
+ return componentInfo;
210
+ }
211
+ exports.extractVueComponentInfo = extractVueComponentInfo;
212
+ function convertComponentOptionsToString(component) {
213
+ function getEmits() {
214
+ let result = "";
215
+ Object.keys(component.emits).forEach(name => {
216
+ result = `${result} "${name}",`;
217
+ });
218
+ return result;
219
+ }
220
+ function getProps() {
221
+ let result = "";
222
+ Object.keys(component.props).forEach(name => {
223
+ result = `${result} ${name}:${component.props[name].defaultValue !== undefined && component.props[name].defaultValue !== "null" ? `{default: ${component.props[name].defaultValue}},` : "{},"}`;
224
+ });
225
+ Object.keys(component.models).forEach(name => {
226
+ result = `${result} ${name}:${component.models[name].defaultValue !== undefined && component.models[name].defaultValue !== "null" ? `{default: ${component.models[name].defaultValue}},` : "{},"}`;
227
+ });
228
+ return result;
229
+ }
230
+ return `{ emits: [${getEmits()}], props: {${getProps()}} }`;
231
+ }
232
+ function extractTypeValue(tsType, rawValue = false) {
233
+ let result = "";
234
+ if (tsType.type === "TsTypeAnnotation") {
235
+ return extractTypeValue(tsType.typeAnnotation);
236
+ }
237
+ switch (tsType.type) {
238
+ case "TsLiteralType":
239
+ if (rawValue && tsType.literal.type === "StringLiteral") {
240
+ result = tsType.literal.raw;
241
+ }
242
+ else {
243
+ result = tsType.literal.value;
244
+ }
245
+ break;
246
+ case "TsKeywordType":
247
+ result = tsType.kind;
248
+ break;
249
+ case "TsTypeReference":
250
+ result = tsType.typeName.value;
251
+ break;
252
+ case "TsTypeQuery":
253
+ result = tsType.exprName.value;
254
+ break;
255
+ case "TsFunctionType":
256
+ result = getPropertyFunctionTypeAsString(tsType);
257
+ break;
258
+ default:
259
+ break;
31
260
  }
32
261
  return result;
33
262
  }
34
- exports.transformVueComponent = transformVueComponent;
35
- function replaceWebComponentNamespaceMapping(content) {
36
- const infos = _outputInfos.concat(ConfigurationManager.outputInfo.get());
263
+ function getPropertyFunctionTypeAsString(type) {
264
+ let params = "";
265
+ if (type.params?.length > 0) {
266
+ type.params.forEach(p => {
267
+ params += `${p.value}:${extractTypeValue(p.typeAnnotation)}, `;
268
+ });
269
+ params = params.replace(/,\s*$/, "");
270
+ }
271
+ return `(${params}) => ${extractTypeValue(type.typeAnnotation)}`;
272
+ }
273
+ function getPropertyInfo(ce, result) {
274
+ const identifier = ce.callee?.property?.value;
275
+ if (identifier) {
276
+ switch (identifier) {
277
+ case "name":
278
+ result.name = ce.arguments[0].expression.value;
279
+ getPropertyInfo(ce.callee.object, result);
280
+ break;
281
+ case "vModel":
282
+ result.type = DefineVueType.Model;
283
+ result.propertyTypeAsString = extractTypeValue(ce.typeArguments.params[0]);
284
+ result.name = result.name ? `v-model:${result.name}` : result.name;
285
+ break;
286
+ case "slots":
287
+ result.type = DefineVueType.Slot;
288
+ result.propertyTypeAsObject = {};
289
+ ce.typeArguments.params[0].members
290
+ .forEach(m => {
291
+ result.propertyTypeAsObject[m.key.value] = extractTypeValue(m.typeAnnotation);
292
+ });
293
+ break;
294
+ case "prop":
295
+ result.type = DefineVueType.Prop;
296
+ result.propertyTypeAsString = extractTypeValue(ce.typeArguments.params[0]);
297
+ break;
298
+ case "emit":
299
+ result.type = DefineVueType.Emit;
300
+ result.propertyTypeAsString = extractTypeValue(ce.typeArguments.params[0]);
301
+ break;
302
+ default:
303
+ getPropertyInfo(ce.callee.object, result);
304
+ }
305
+ }
306
+ }
307
+ function replaceComponentNamespace(content) {
308
+ const infos = outputInfos.concat(ConfigurationManager.outputInfo.get());
37
309
  infos.forEach(info => {
38
310
  if (info.wc?.namespaces) {
39
311
  info.wc.namespaces.forEach(namespace => {
@@ -65,13 +337,6 @@ function convertManifestPathToEntryPath(pathToManifest, pathsInManifest) {
65
337
  return result;
66
338
  }
67
339
  exports.convertManifestPathToEntryPath = convertManifestPathToEntryPath;
68
- exports.buildContext = {
69
- isManifestsChanged: false
70
- };
71
- exports.cacheKeys = {
72
- //buildManifestMetadatas: "buildManifestMetadatas",
73
- bundleManifests: "bundleManifests"
74
- };
75
340
  class ConfigurationManager {
76
341
  static get webComponentTypings() {
77
342
  if (!this._webComponentTypings) {