@simplysm/sd-cli 7.0.303 → 7.1.1

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 (46) hide show
  1. package/README.md +4 -4
  2. package/dist/builder/SdCliClientBuilder.mjs +65 -7
  3. package/dist/builder/SdCliTsLibBuilder.mjs +2 -2
  4. package/dist/commons.d.ts +2 -0
  5. package/dist/entry-points/SdCliPrepare.mjs +53 -22
  6. package/dist/entry-points/SdCliProjectGenerator.mjs +34 -26
  7. package/dist/entry-points/file/base/fc_package_npmconfig.mjs +2 -1
  8. package/dist/entry-points/file/project/fc_project_gitignore.mjs +12 -2
  9. package/dist/entry-points/file/project/fc_project_npmconfig.mjs +9 -7
  10. package/dist/entry-points/file/project/fc_project_yarnrc.d.ts +1 -0
  11. package/dist/entry-points/file/project/fc_project_yarnrc.mjs +19 -0
  12. package/dist/entry-points/file/server/fc_package_server_main.d.ts +1 -0
  13. package/dist/entry-points/file/server/fc_package_server_main.mjs +2 -2
  14. package/dist/index.d.ts +1 -0
  15. package/dist/index.mjs +2 -1
  16. package/dist/ng-tools/SdCliNgModuleGenerator.d.ts +2 -1
  17. package/dist/ng-tools/SdCliNgModuleGenerator.mjs +41 -21
  18. package/dist/ng-tools/babel/SdCliBbFileMetadata.mjs +33 -13
  19. package/dist/ng-tools/babel/SdCliBbRootMetadata.d.ts +2 -2
  20. package/dist/ng-tools/babel/SdCliBbRootMetadata.mjs +66 -19
  21. package/dist/ng-tools/babel/SdCliBbUtil.d.ts +2 -2
  22. package/dist/ng-tools/babel/SdCliBbUtil.mjs +3 -3
  23. package/dist/ng-tools/babel/TSdCliBbTypeMetadata.d.ts +13 -2
  24. package/dist/ng-tools/babel/TSdCliBbTypeMetadata.mjs +25 -1
  25. package/dist/ng-tools/typescript/SdCliTsFileMetadata.mjs +3 -3
  26. package/dist/utils/SdCliBuildResultUtil.mjs +3 -3
  27. package/docs/conf-orm.md +1 -1
  28. package/package.json +46 -41
  29. package/src/builder/SdCliClientBuilder.ts +71 -6
  30. package/src/builder/SdCliTsLibBuilder.ts +1 -1
  31. package/src/commons.ts +2 -0
  32. package/src/entry-points/SdCliPrepare.ts +52 -21
  33. package/src/entry-points/SdCliProjectGenerator.ts +36 -26
  34. package/src/entry-points/file/base/fc_package_npmconfig.ts +1 -0
  35. package/src/entry-points/file/project/fc_project_gitignore.ts +11 -1
  36. package/src/entry-points/file/project/fc_project_npmconfig.ts +8 -6
  37. package/src/entry-points/file/project/fc_project_yarnrc.ts +18 -0
  38. package/src/entry-points/file/server/fc_package_server_main.ts +2 -2
  39. package/src/index.ts +1 -0
  40. package/src/ng-tools/SdCliNgModuleGenerator.ts +53 -20
  41. package/src/ng-tools/babel/SdCliBbFileMetadata.ts +32 -10
  42. package/src/ng-tools/babel/SdCliBbRootMetadata.ts +74 -21
  43. package/src/ng-tools/babel/SdCliBbUtil.ts +4 -4
  44. package/src/ng-tools/babel/TSdCliBbTypeMetadata.ts +36 -1
  45. package/src/ng-tools/typescript/SdCliTsFileMetadata.ts +2 -2
  46. package/src/utils/SdCliBuildResultUtil.ts +3 -2
@@ -6,6 +6,7 @@ import {
6
6
  isAssignmentExpression,
7
7
  isCallExpression,
8
8
  isClassDeclaration,
9
+ isConditionalExpression,
9
10
  isExportDeclaration,
10
11
  isExportDefaultDeclaration,
11
12
  isExportNamedDeclaration,
@@ -34,6 +35,7 @@ import { TSdCliBbMetadata } from "./SdCliBbRootMetadata";
34
35
  import {
35
36
  SdCliBbArrayMetadata,
36
37
  SdCliBbClassMetadata,
38
+ SdCliBbConditionMetadata,
37
39
  SdCliBbFunctionMetadata,
38
40
  SdCliBbObjectMetadata,
39
41
  SdCliBbVariableMetadata
@@ -58,7 +60,12 @@ export class SdCliBbFileMetadata {
58
60
  }
59
61
 
60
62
  const fileContent = FsUtil.readFile(realFilePath);
61
- this.ast = babelParser.parse(fileContent, { sourceType: "module" });
63
+ try {
64
+ this.ast = babelParser.parse(fileContent, { sourceType: "module" });
65
+ }
66
+ catch (err) {
67
+ throw SdCliBbUtil.error(err.message, this.filePath, err.loc);
68
+ }
62
69
  this.rawMetas = this.ast.program.body;
63
70
  }
64
71
 
@@ -116,7 +123,7 @@ export class SdCliBbFileMetadata {
116
123
  }
117
124
 
118
125
  if (rawMeta.source) {
119
- if (rawMeta.source.value.includes(".")) {
126
+ if (rawMeta.source.value.startsWith(".")) {
120
127
  const moduleFilePath = path.resolve(path.dirname(this.filePath), rawMeta.source.value);
121
128
  result.push({
122
129
  exportedName,
@@ -155,7 +162,7 @@ export class SdCliBbFileMetadata {
155
162
  });
156
163
  }
157
164
  else {
158
- if (rawMeta.source.value.includes(".")) {
165
+ if (rawMeta.source.value.startsWith(".")) {
159
166
  const moduleFilePath = path.resolve(path.dirname(this.filePath), rawMeta.source.value);
160
167
  result.push({
161
168
  exportedName: "*",
@@ -167,7 +174,11 @@ export class SdCliBbFileMetadata {
167
174
  });
168
175
  }
169
176
  else {
170
- throw SdCliBbUtil.error("예상치 못한 방식의 코드가 발견되었습니다.", this.filePath, rawMeta);
177
+ const moduleName = rawMeta.source.value;
178
+ result.push({
179
+ exportedName: "*",
180
+ target: { moduleName, name: "*", __TSdCliMetaRef__: "__TSdCliMetaRef__" }
181
+ });
171
182
  }
172
183
  }
173
184
  }
@@ -231,7 +242,7 @@ export class SdCliBbFileMetadata {
231
242
  }
232
243
  else if (exportedName === name) {
233
244
  if (rawMeta.source) {
234
- if (rawMeta.source.value.includes(".")) {
245
+ if (rawMeta.source.value.startsWith(".")) {
235
246
  const moduleFilePath = path.resolve(path.dirname(this.filePath), rawMeta.source.value);
236
247
  const result = {
237
248
  filePath: moduleFilePath,
@@ -295,7 +306,7 @@ export class SdCliBbFileMetadata {
295
306
  }
296
307
  else if (exportedName === localName) {
297
308
  if (rawMeta.source) {
298
- if (rawMeta.source.value.includes(".")) {
309
+ if (rawMeta.source.value.startsWith(".")) {
299
310
  const moduleFilePath = path.resolve(path.dirname(this.filePath), rawMeta.source.value);
300
311
  const result = {
301
312
  filePath: moduleFilePath,
@@ -354,7 +365,7 @@ export class SdCliBbFileMetadata {
354
365
  }
355
366
  else if (impLocalName === localName) {
356
367
  if (isIdentifier(specifier.imported)) {
357
- if (rawMeta.source.value.includes(".")) {
368
+ if (rawMeta.source.value.startsWith(".")) {
358
369
  const moduleFilePath = path.resolve(path.dirname(this.filePath), rawMeta.source.value);
359
370
  const result = {
360
371
  filePath: moduleFilePath,
@@ -382,7 +393,7 @@ export class SdCliBbFileMetadata {
382
393
  }
383
394
  else if (isImportDefaultSpecifier(specifier)) {
384
395
  if (specifier.local.name === localName) {
385
- if (rawMeta.source.value.includes(".")) {
396
+ if (rawMeta.source.value.startsWith(".")) {
386
397
  const moduleFilePath = path.resolve(path.dirname(this.filePath), rawMeta.source.value);
387
398
  const result = {
388
399
  filePath: moduleFilePath,
@@ -406,7 +417,7 @@ export class SdCliBbFileMetadata {
406
417
  }
407
418
  else if (isImportNamespaceSpecifier(specifier)) {
408
419
  if (specifier.local.name === localName) {
409
- if (rawMeta.source.value.includes(".")) {
420
+ if (rawMeta.source.value.startsWith(".")) {
410
421
  const moduleFilePath = path.resolve(path.dirname(this.filePath), rawMeta.source.value);
411
422
  const result = {
412
423
  filePath: moduleFilePath,
@@ -417,7 +428,15 @@ export class SdCliBbFileMetadata {
417
428
  return result;
418
429
  }
419
430
  else {
420
- throw SdCliBbUtil.error("예상치 못한 방식의 코드가 발견되었습니다.", this.filePath, rawMeta);
431
+ const moduleName = rawMeta.source.value;
432
+ const result = {
433
+ moduleName,
434
+ name: "*",
435
+ __TSdCliMetaRef__: "__TSdCliMetaRef__" as const
436
+ };
437
+ this._findMetaFromInsideCache.set(localName, result);
438
+ return result;
439
+ // throw SdCliBbUtil.error("예상치 못한 방식의 코드가 발견되었습니다.", this.filePath, rawMeta);
421
440
  }
422
441
  }
423
442
  }
@@ -476,6 +495,9 @@ export class SdCliBbFileMetadata {
476
495
  else if (isSpreadElement(rawMeta)) {
477
496
  return this.getMetaFromRaw(rawMeta.argument);
478
497
  }
498
+ else if (isConditionalExpression(rawMeta)) {
499
+ return new SdCliBbConditionMetadata(this, rawMeta);
500
+ }
479
501
 
480
502
  throw SdCliBbUtil.error("예상치 못한 방식의 코드가 발견되었습니다.", this.filePath, rawMeta);
481
503
  }
@@ -8,12 +8,12 @@ import { TSdCliBbTypeMetadata } from "./TSdCliBbTypeMetadata";
8
8
  import { TSdCliMetaRef } from "../commons";
9
9
 
10
10
  export class SdCliBbRootMetadata {
11
- private readonly _entryMap: Map<string, string>;
11
+ private readonly _depMap: Map<string, { rootPath: string; entryFilePath?: string }>;
12
12
  private readonly _fileMetaCache = new Map<string, SdCliBbFileMetadata>();
13
13
 
14
14
  public constructor(packagePath: string) {
15
15
  const allDepPaths = this._getAllDepPaths(packagePath);
16
- this._entryMap = this._getEntryMap(allDepPaths);
16
+ this._depMap = this._getDepMap(allDepPaths);
17
17
  // const ngDepPaths = this._getNgDepPaths(allDepPaths);
18
18
  // this._entryMap = this._getEntryMap(ngDepPaths);
19
19
  }
@@ -26,19 +26,35 @@ export class SdCliBbRootMetadata {
26
26
 
27
27
  public getEntryFileMetaRecord(): Record<string, SdCliBbFileMetadata> {
28
28
  const result: Record<string, SdCliBbFileMetadata> = {};
29
- for (const moduleName of this._entryMap.keys()) {
30
- const entryFilePath = this._entryMap.get(moduleName)!;
31
- result[moduleName] = this._fileMetaCache.getOrCreate(entryFilePath, () => new SdCliBbFileMetadata(entryFilePath))!;
29
+ for (const moduleName of this._depMap.keys()) {
30
+ const entryFilePath = this._depMap.get(moduleName)?.entryFilePath;
31
+ if (entryFilePath !== undefined) {
32
+ result[moduleName] = this._fileMetaCache.getOrCreate(entryFilePath, () => new SdCliBbFileMetadata(entryFilePath))!;
33
+ }
32
34
  }
33
35
  return result;
34
36
  }
35
37
 
36
38
  public findMeta(ref: TSdCliMetaRef): TSdCliBbMetadata | TSdCliBbMetadata[] {
37
- const filePath = "moduleName" in ref ? this._entryMap.get(ref.moduleName) : ref.filePath;
39
+ let filePath: string | undefined;
40
+ if ("moduleName" in ref) {
41
+ filePath = this._depMap.get(ref.moduleName)?.entryFilePath;
42
+ if (filePath === undefined) {
43
+ const fileRootPath = this._depMap.get(ref.moduleName.split("/")[0])?.rootPath;
44
+ if (fileRootPath !== undefined) {
45
+ filePath = path.resolve(fileRootPath, ref.moduleName.split("/").slice(1).join("/"));
46
+ }
47
+ }
48
+ }
49
+ else {
50
+ filePath = ref.filePath;
51
+ }
52
+
38
53
  if (filePath === undefined) {
39
54
  throw new NeverEntryError();
40
55
  }
41
- const fileMeta = this._fileMetaCache.getOrCreate(filePath, () => new SdCliBbFileMetadata(filePath));
56
+
57
+ const fileMeta = this._fileMetaCache.getOrCreate(filePath, () => new SdCliBbFileMetadata(filePath!));
42
58
  if (ref.name === "*") {
43
59
  const result: TSdCliBbMetadata[] = [];
44
60
  for (const exp of fileMeta.exports) {
@@ -137,16 +153,44 @@ export class SdCliBbRootMetadata {
137
153
  // return results;
138
154
  // }
139
155
 
140
- private _getEntryMap(ngDepPaths: string[]): Map<string, string> {
141
- const entryMap = new Map<string, string>();
156
+ private _getDepMap(ngDepPaths: string[]): Map<string, { rootPath: string; entryFilePath?: string }> {
157
+ const entryMap = new Map<string, { rootPath: string; entryFilePath?: string }>();
142
158
  for (const ngDepPath of ngDepPaths) {
143
159
  const npmConfig = FsUtil.readJson(path.resolve(ngDepPath, "package.json")) as INpmConfig;
144
160
 
145
- const entryFilePath = npmConfig["es2015"] ?? npmConfig["browser"] ?? npmConfig["module"] ?? npmConfig["main"] ?? npmConfig["default"];
146
- if (typeof entryFilePath === "string") {
161
+ const entryFilePath = npmConfig["es2020"] ?? npmConfig["es2015"] ?? npmConfig["browser"] ?? npmConfig["module"] ?? npmConfig["main"] ?? npmConfig["default"];
162
+ if (entryFilePath === undefined) {
163
+ entryMap.set(npmConfig.name, {
164
+ rootPath: ngDepPath,
165
+ entryFilePath: undefined
166
+ });
167
+ }
168
+ else if (typeof entryFilePath === "string") {
147
169
  const realPath = this._getRealFilePath(path.resolve(ngDepPath, entryFilePath));
148
- if (realPath != null) {
149
- entryMap.set(npmConfig.name, realPath);
170
+ if (realPath?.endsWith(".json")) {
171
+ continue;
172
+ }
173
+
174
+ entryMap.set(npmConfig.name, {
175
+ rootPath: ngDepPath,
176
+ entryFilePath: realPath
177
+ });
178
+ }
179
+ else {
180
+ for (const key of Object.keys(entryMap)) {
181
+ const exportPath = path.resolve(ngDepPath, key);
182
+ const exportResult = this._getGlobExportResult(PathUtil.posix(npmConfig.name, key), exportPath);
183
+ for (const exportResultItem of exportResult) {
184
+ const exportRealPath = this._getRealFilePath(exportResultItem.target);
185
+ if (exportResultItem.target.endsWith(".json")) {
186
+ continue;
187
+ }
188
+
189
+ entryMap.set(exportResultItem.name, {
190
+ rootPath: ngDepPath,
191
+ entryFilePath: exportRealPath
192
+ });
193
+ }
150
194
  }
151
195
  }
152
196
 
@@ -154,27 +198,36 @@ export class SdCliBbRootMetadata {
154
198
  const exportKeys = Object.keys(npmConfig.exports);
155
199
  for (const exportKey of exportKeys) {
156
200
  if (
157
- exportKey.includes("/locales") ||
158
- exportKey.endsWith(".json") ||
159
- exportKey.endsWith("/testing") ||
160
- exportKey.endsWith("/upgrade")
201
+ exportKey.startsWith("./locales") ||
202
+ exportKey.startsWith("./testing") ||
203
+ exportKey.startsWith("./upgrade")
161
204
  ) {
162
205
  continue;
163
206
  }
164
207
 
165
- const expEntryFilePath = npmConfig.exports[exportKey]["es2015"] ??
208
+ const expEntryFilePath = npmConfig.exports[exportKey]["es2020"] ??
209
+ npmConfig.exports[exportKey]["es2015"] ??
166
210
  npmConfig.exports[exportKey]["browser"] ??
167
211
  npmConfig.exports[exportKey]["module"] ??
168
212
  npmConfig.exports[exportKey]["main"] ??
169
213
  npmConfig.exports[exportKey]["default"];
170
214
  if (typeof expEntryFilePath === "string") {
215
+ if (expEntryFilePath.endsWith(".json")) {
216
+ continue;
217
+ }
218
+
171
219
  const exportPath = path.resolve(ngDepPath, expEntryFilePath);
172
220
  const exportResult = this._getGlobExportResult(PathUtil.posix(npmConfig.name, exportKey), exportPath);
173
221
  for (const exportResultItem of exportResult) {
174
- const realPath = this._getRealFilePath(exportResultItem.target);
175
- if (realPath != null) {
176
- entryMap.set(exportResultItem.name, realPath);
222
+ if (exportResultItem.target.endsWith(".json")) {
223
+ continue;
177
224
  }
225
+
226
+ const exportRealPath = this._getRealFilePath(exportResultItem.target);
227
+ entryMap.set(exportResultItem.name, {
228
+ rootPath: ngDepPath,
229
+ entryFilePath: exportRealPath
230
+ });
178
231
  }
179
232
  }
180
233
  }
@@ -1,12 +1,12 @@
1
- import { Node } from "@babel/types";
1
+ import { Node, SourceLocation } from "@babel/types";
2
2
  import { SdCliBuildResultError } from "../../SdCliBuildResultError";
3
3
 
4
4
  export class SdCliBbUtil {
5
- public static error(message: string, filePath?: string, meta?: Node): SdCliBuildResultError {
5
+ public static error(message: string, filePath?: string, meta?: Node | SourceLocation["start"]): SdCliBuildResultError {
6
6
  return new SdCliBuildResultError({
7
7
  filePath,
8
- line: meta?.loc?.start.line,
9
- char: meta?.loc?.start.column,
8
+ line: meta && "loc" in meta ? meta.loc?.start.line : meta && "line" in meta ? meta.line : undefined,
9
+ char: meta && "loc" in meta ? meta.loc?.start.column : meta && "column" in meta ? meta.column : undefined,
10
10
  code: undefined,
11
11
  severity: "error",
12
12
  message: message
@@ -1,6 +1,7 @@
1
1
  import {
2
2
  ArrayExpression,
3
3
  ClassDeclaration,
4
+ ConditionalExpression,
4
5
  FunctionDeclaration,
5
6
  isAssignmentExpression,
6
7
  isExpressionStatement,
@@ -26,7 +27,8 @@ export type TSdCliBbTypeMetadata = SdCliBbClassMetadata |
26
27
  SdCliBbVariableMetadata |
27
28
  SdCliBbFunctionMetadata |
28
29
  SdCliBbObjectMetadata |
29
- SdCliBbArrayMetadata;
30
+ SdCliBbArrayMetadata |
31
+ SdCliBbConditionMetadata;
30
32
 
31
33
  export class SdCliBbClassMetadata {
32
34
  public constructor(private readonly _fileMeta: SdCliBbFileMetadata,
@@ -175,3 +177,36 @@ export class SdCliBbArrayMetadata {
175
177
  return this._valueCache;
176
178
  }
177
179
  }
180
+
181
+ export class SdCliBbConditionMetadata {
182
+ public constructor(private readonly _fileMeta: SdCliBbFileMetadata,
183
+ private readonly _metadata: ConditionalExpression) {
184
+ }
185
+
186
+ private _testCache?: TSdCliBbMetadata | undefined;
187
+
188
+ public get test(): TSdCliBbMetadata | undefined {
189
+ if (this._testCache === undefined) {
190
+ this._testCache = this._fileMeta.getMetaFromRaw(this._metadata.test);
191
+ }
192
+ return this._testCache;
193
+ }
194
+
195
+ private _consequentCache?: TSdCliBbMetadata | undefined;
196
+
197
+ public get consequent(): TSdCliBbMetadata | undefined {
198
+ if (this._consequentCache === undefined) {
199
+ this._consequentCache = this._fileMeta.getMetaFromRaw(this._metadata.consequent);
200
+ }
201
+ return this._consequentCache;
202
+ }
203
+
204
+ private _alternateCache?: TSdCliBbMetadata | undefined;
205
+
206
+ public get alternate(): TSdCliBbMetadata | undefined {
207
+ if (this._alternateCache === undefined) {
208
+ this._alternateCache = this._fileMeta.getMetaFromRaw(this._metadata.alternate);
209
+ }
210
+ return this._alternateCache;
211
+ }
212
+ }
@@ -38,7 +38,7 @@ export class SdCliTsFileMetadata {
38
38
  if (ts.isImportDeclaration(node)) {
39
39
  if (ts.isStringLiteral(node.moduleSpecifier)) {
40
40
  if (node.importClause) {
41
- if (node.moduleSpecifier.text.includes(".")) {
41
+ if (node.moduleSpecifier.text.startsWith(".")) {
42
42
  const moduleFilePath = path.resolve(path.dirname(this.filePath), node.moduleSpecifier.text);
43
43
 
44
44
  if (node.importClause.namedBindings) {
@@ -116,7 +116,7 @@ export class SdCliTsFileMetadata {
116
116
  node.moduleSpecifier &&
117
117
  ts.isStringLiteral(node.moduleSpecifier)
118
118
  ) {
119
- if (node.moduleSpecifier.text.includes(".")) {
119
+ if (node.moduleSpecifier.text.startsWith(".")) {
120
120
  const moduleFilePath = path.resolve(path.dirname(this.filePath), node.moduleSpecifier.text);
121
121
  for (const el of node.exportClause.elements) {
122
122
  if (el.propertyName && el.name.text !== el.propertyName.text) {
@@ -49,8 +49,8 @@ export class SdCliBuildResultUtil {
49
49
  private static _convertFromWebpackError(severity: "warning" | "error", err: webpack.WebpackError): ISdCliPackageBuildResult {
50
50
  return {
51
51
  filePath: (err.file as string | undefined) ?? (err.module as webpack.Module | undefined)?.["request"],
52
- line: err.file ? err.loc["start"]?.line : undefined,
53
- char: err.file ? err.loc["start"]?.column : undefined,
52
+ line: err.file ? err.loc?.["start"]?.line : undefined, // eslint-disable-line
53
+ char: err.file ? err.loc?.["start"]?.column : undefined, // eslint-disable-line
54
54
  code: err.name,
55
55
  severity,
56
56
  message: err.message
@@ -71,6 +71,7 @@ export class SdCliBuildResultUtil {
71
71
  str += `${result.code}: `;
72
72
  }
73
73
  str += `${result.severity} ${result.message}`;
74
+
74
75
  return str;
75
76
  }
76
77
  }