@simplysm/sd-cli 11.0.3 → 11.0.5

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 (50) hide show
  1. package/dist/build-cluster.js +1 -1
  2. package/dist/build-cluster.js.map +1 -1
  3. package/dist/build-tools/SdLinter.js +2 -2
  4. package/dist/build-tools/SdLinter.js.map +1 -1
  5. package/dist/build-tools/SdNgBundler.d.ts +23 -0
  6. package/dist/build-tools/SdNgBundler.js +331 -0
  7. package/dist/build-tools/SdNgBundler.js.map +1 -0
  8. package/dist/build-tools/SdTsBundler.d.ts +15 -0
  9. package/dist/build-tools/SdTsBundler.js +96 -0
  10. package/dist/build-tools/SdTsBundler.js.map +1 -0
  11. package/dist/build-tools/SdTsCompiler.d.ts +28 -0
  12. package/dist/build-tools/SdTsCompiler.js +212 -0
  13. package/dist/build-tools/SdTsCompiler.js.map +1 -0
  14. package/dist/builders/SdCliClientBuilder.d.ts +4 -2
  15. package/dist/builders/SdCliClientBuilder.js +60 -297
  16. package/dist/builders/SdCliClientBuilder.js.map +1 -1
  17. package/dist/builders/SdCliServerBuilder.js +79 -216
  18. package/dist/builders/SdCliServerBuilder.js.map +1 -1
  19. package/dist/builders/SdCliTsLibBuilder.d.ts +0 -1
  20. package/dist/builders/SdCliTsLibBuilder.js +35 -33
  21. package/dist/builders/SdCliTsLibBuilder.js.map +1 -1
  22. package/dist/commons.d.ts +7 -0
  23. package/dist/entry/SdCliProject.js +13 -10
  24. package/dist/entry/SdCliProject.js.map +1 -1
  25. package/dist/index.d.ts +3 -1
  26. package/dist/index.js +3 -1
  27. package/dist/index.js.map +1 -1
  28. package/dist/server-worker.js +3 -0
  29. package/dist/server-worker.js.map +1 -1
  30. package/dist/utils/SdCliBuildResultUtil.d.ts +1 -1
  31. package/dist/utils/SdCliBuildResultUtil.js +4 -4
  32. package/dist/utils/SdCliBuildResultUtil.js.map +1 -1
  33. package/package.json +14 -12
  34. package/src/build-cluster.ts +1 -1
  35. package/src/build-tools/SdLinter.ts +2 -2
  36. package/src/build-tools/SdNgBundler.ts +404 -0
  37. package/src/build-tools/SdTsBundler.ts +106 -0
  38. package/src/build-tools/SdTsCompiler.ts +304 -0
  39. package/src/builders/SdCliClientBuilder.ts +75 -322
  40. package/src/builders/SdCliServerBuilder.ts +95 -243
  41. package/src/builders/SdCliTsLibBuilder.ts +39 -40
  42. package/src/commons.ts +6 -0
  43. package/src/entry/SdCliProject.ts +17 -12
  44. package/src/index.ts +3 -1
  45. package/src/server-worker.ts +3 -0
  46. package/src/utils/SdCliBuildResultUtil.ts +4 -4
  47. package/dist/build-tools/SdTsIncrementalBuilder.d.ts +0 -31
  48. package/dist/build-tools/SdTsIncrementalBuilder.js +0 -126
  49. package/dist/build-tools/SdTsIncrementalBuilder.js.map +0 -1
  50. package/src/build-tools/SdTsIncrementalBuilder.ts +0 -207
@@ -1,126 +0,0 @@
1
- import path from "path";
2
- import ts from "typescript";
3
- import { SdCliBuildResultUtil } from "../utils/SdCliBuildResultUtil";
4
- import { FsUtil, Logger, PathUtil } from "@simplysm/sd-core-node";
5
- import { NgtscProgram } from "@angular/compiler-cli";
6
- import { createHash } from "crypto";
7
- export class SdTsIncrementalBuilder {
8
- constructor(_pkgPath, _compilerOptions, _host, _opt) {
9
- this._pkgPath = _pkgPath;
10
- this._compilerOptions = _compilerOptions;
11
- this._host = _host;
12
- this._opt = _opt;
13
- this._writeFileCache = new Map();
14
- }
15
- static async createAsync(pkgPath, optFn) {
16
- const tsConfigFilePath = path.resolve(pkgPath, "tsconfig.json");
17
- const tsConfig = await FsUtil.readJsonAsync(tsConfigFilePath);
18
- const parsedTsConfig = ts.parseJsonConfigFileContent(await FsUtil.readJsonAsync(tsConfigFilePath), ts.sys, pkgPath, tsConfig["angularCompilerOptions"]);
19
- const opt = optFn(parsedTsConfig.options);
20
- const compilerOptions = {
21
- ...parsedTsConfig.options,
22
- ...opt?.compilerOptions
23
- };
24
- const host = ts.createIncrementalCompilerHost(compilerOptions);
25
- return new SdTsIncrementalBuilder(pkgPath, compilerOptions, host, opt);
26
- }
27
- async buildAsync() {
28
- const logger = Logger.get(["simplysm", "sd-cli", "SdTsIncrementalBuilder", "buildAsync"]);
29
- const distPath = this._compilerOptions.outDir ?? path.resolve(this._pkgPath, "dist");
30
- const srcGlobPath = path.resolve(this._pkgPath, "src/**/*.{ts,tsx}");
31
- const srcFilePaths = await FsUtil.globAsync(srcGlobPath);
32
- if (this._compilerOptions["strictTemplates"] === true) {
33
- this._ngProgram = new NgtscProgram(srcFilePaths, this._compilerOptions, this._host, this._ngProgram);
34
- this._program = this._ngProgram.getTsProgram();
35
- }
36
- else {
37
- this._program = ts.createProgram(srcFilePaths, this._compilerOptions, this._host, this._program);
38
- }
39
- const baseGetSourceFiles = this._program.getSourceFiles;
40
- this._program.getSourceFiles = function (...parameters) {
41
- const files = baseGetSourceFiles(...parameters);
42
- for (const file of files) {
43
- if (file.version === undefined) {
44
- file.version = createHash("sha256").update(file.text).digest("hex");
45
- }
46
- }
47
- return files;
48
- };
49
- this.builderProgram = ts.createSemanticDiagnosticsBuilderProgram(this._program, this._host, this.builderProgram);
50
- const diagnostics = [];
51
- const affectedFilePaths = [];
52
- if (this._ngProgram) {
53
- diagnostics.push(...this._ngProgram.compiler.getOptionDiagnostics());
54
- }
55
- diagnostics.push(...this.builderProgram.getOptionsDiagnostics(), ...this.builderProgram.getGlobalDiagnostics());
56
- if (this._ngProgram) {
57
- await this._ngProgram.compiler.analyzeAsync();
58
- }
59
- const program = this.builderProgram.getProgram();
60
- logger.debug(`[${path.basename(this._pkgPath)}] 영향받는 파일 확인 및 처리중...`);
61
- const srcFilePathSet = new Set(srcFilePaths);
62
- while (true) {
63
- let affectedSourceFile;
64
- const semanticResult = this.builderProgram.getSemanticDiagnosticsOfNextAffectedFile(undefined, (sourceFile) => {
65
- //-- ngtypecheck의 org파일 포함 (ngtypecheck 파일는 무시)
66
- if (this._ngProgram?.compiler.ignoreForDiagnostics.has(sourceFile) && sourceFile.fileName.endsWith(".ngtypecheck.ts")) {
67
- const orgFileName = sourceFile.fileName.slice(0, -15) + ".ts";
68
- const orgSourceFile = this.builderProgram.getSourceFile(orgFileName);
69
- if (orgSourceFile) {
70
- affectedSourceFile = orgSourceFile;
71
- }
72
- return true;
73
- }
74
- //-- 소스폴더 파일 포함
75
- else if (srcFilePathSet.has(path.resolve(sourceFile.fileName))) {
76
- affectedSourceFile = sourceFile;
77
- return false;
78
- }
79
- //-- 나머지 무시
80
- else {
81
- return true;
82
- }
83
- });
84
- if (!semanticResult || !affectedSourceFile)
85
- break;
86
- diagnostics.push(...semanticResult.result);
87
- if ("fileName" in affectedSourceFile) {
88
- const emitResult = this.builderProgram.emit(affectedSourceFile, (filePath, data, writeByteOrderMark) => {
89
- let realFilePath = filePath;
90
- let realData = data;
91
- if (PathUtil.isChildPath(realFilePath, path.resolve(distPath, path.basename(this._pkgPath), "src"))) {
92
- realFilePath = path.resolve(distPath, path.relative(path.resolve(distPath, path.basename(this._pkgPath), "src"), realFilePath));
93
- if (filePath.endsWith(".js.map")) {
94
- const sourceMapContents = JSON.parse(realData);
95
- // remove "../../"
96
- sourceMapContents.sources[0] = sourceMapContents.sources[0].slice(6);
97
- realData = JSON.stringify(sourceMapContents);
98
- }
99
- }
100
- if (this._writeFileCache.get(realFilePath) !== realData) {
101
- this._host.writeFile(realFilePath, realData, writeByteOrderMark);
102
- }
103
- this._writeFileCache.set(realFilePath, realData);
104
- }, undefined, Array.isArray(this._opt.emitJs) ? !this._opt.emitJs.includes(path.resolve(affectedSourceFile.fileName)) : !this._opt.emitJs, this._opt.transforms ? {
105
- before: this._opt.transforms.map((item) => typeof item.fn === "function" ? item.fn(program, item.args) : item.fn["default"](program, item.args))
106
- } : undefined);
107
- diagnostics.push(...emitResult.diagnostics);
108
- diagnostics.push(...this.builderProgram.getSyntacticDiagnostics(affectedSourceFile));
109
- if (this._ngProgram &&
110
- !affectedSourceFile.isDeclarationFile &&
111
- !this._ngProgram.compiler.ignoreForEmit.has(affectedSourceFile) &&
112
- !this._ngProgram.compiler.incrementalCompilation.safeToSkipEmit(affectedSourceFile)) {
113
- diagnostics.push(...this._ngProgram.compiler.getDiagnosticsForFile(affectedSourceFile, 1));
114
- }
115
- affectedFilePaths.push(path.resolve(affectedSourceFile.fileName));
116
- }
117
- }
118
- logger.debug(`[${path.basename(this._pkgPath)}] 영향받는 파일 확인 및 처리 완료`, affectedFilePaths);
119
- const buildResults = diagnostics.map((item) => SdCliBuildResultUtil.convertFromTsDiag(item));
120
- return {
121
- affectedFilePaths,
122
- results: buildResults
123
- };
124
- }
125
- }
126
- //# sourceMappingURL=SdTsIncrementalBuilder.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"SdTsIncrementalBuilder.js","sourceRoot":"","sources":["../../src/build-tools/SdTsIncrementalBuilder.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,MAAM,YAAY,CAAC;AAC5B,OAAO,EAAC,oBAAoB,EAAC,MAAM,+BAA+B,CAAC;AACnE,OAAO,EAAC,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAC,MAAM,wBAAwB,CAAC;AAEhE,OAAO,EAAC,YAAY,EAAC,MAAM,uBAAuB,CAAC;AACnD,OAAO,EAAC,UAAU,EAAC,MAAM,QAAQ,CAAC;AAQlC,MAAM,OAAO,sBAAsB;IAOjC,YAAoC,QAAgB,EAChB,gBAAoC,EACpC,KAAsB,EACtB,IAIhB;QAPgB,aAAQ,GAAR,QAAQ,CAAQ;QAChB,qBAAgB,GAAhB,gBAAgB,CAAoB;QACpC,UAAK,GAAL,KAAK,CAAiB;QACtB,SAAI,GAAJ,IAAI,CAIpB;QATH,oBAAe,GAAG,IAAI,GAAG,EAAkB,CAAC;IAU7D,CAAC;IAEM,MAAM,CAAC,KAAK,CAAC,WAAW,CAAC,OAAe,EAAE,KAIhD;QACC,MAAM,gBAAgB,GAAG,IAAI,CAAC,OAAO,CAA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IAAI,CAAC,UAAU,CAAC,QAAQ,CAAC,qBAAqB,CAAC,kBAAkB,EAAE,CAAC,CAAC,CACzE,CAAC;iBACH;gBAED,iBAAiB,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,kBAAkB,CAAC,QAAQ,CAAC,CAAC,CAAC;aACnE;SACF;QACD,MAAM,CAAC,KAAK,CAAC,IAAI,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,QAAQ,CAAC,sBAAsB,EAAE,iBAAiB,CAAC,CAAC;QAExF,MAAM,YAAY,GAAG,WAAW,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,oBAAoB,CAAC,iBAAiB,CAAC,IAAI,CAAC,CAAC,CAAC;QAE7F,OAAO;YACL,iBAAiB;YACjB,OAAO,EAAE,YAAY;SACtB,CAAC;IACJ,CAAC;CACF"}
@@ -1,207 +0,0 @@
1
- import path from "path";
2
- import ts from "typescript";
3
- import {SdCliBuildResultUtil} from "../utils/SdCliBuildResultUtil";
4
- import {FsUtil, Logger, PathUtil} from "@simplysm/sd-core-node";
5
- import {ISdCliPackageBuildResult} from "../commons";
6
- import {NgtscProgram} from "@angular/compiler-cli";
7
- import {createHash} from "crypto";
8
-
9
-
10
- interface IOptTransform<T> {
11
- fn: (_: ts.Program, arg: T) => ts.TransformerFactory<ts.SourceFile>,
12
- args: T
13
- }
14
-
15
- export class SdTsIncrementalBuilder {
16
- public builderProgram?: ts.SemanticDiagnosticsBuilderProgram;
17
-
18
- private _program?: ts.Program;
19
- private _ngProgram?: NgtscProgram;
20
- private readonly _writeFileCache = new Map<string, string>();
21
-
22
- public constructor(private readonly _pkgPath: string,
23
- private readonly _compilerOptions: ts.CompilerOptions,
24
- private readonly _host: ts.CompilerHost,
25
- private readonly _opt: {
26
- emitJs: boolean | string[],
27
- compilerOptions?: ts.CompilerOptions,
28
- transforms?: IOptTransform<any>[]
29
- }) {
30
- }
31
-
32
- public static async createAsync(pkgPath: string, optFn: (compilerOptions: ts.CompilerOptions) => {
33
- emitJs: boolean | string[],
34
- compilerOptions?: ts.CompilerOptions,
35
- transforms?: IOptTransform<any>[]
36
- }): Promise<SdTsIncrementalBuilder> {
37
- const tsConfigFilePath = path.resolve(pkgPath, "tsconfig.json");
38
- const tsConfig = await FsUtil.readJsonAsync(tsConfigFilePath);
39
- const parsedTsConfig = ts.parseJsonConfigFileContent(
40
- await FsUtil.readJsonAsync(tsConfigFilePath),
41
- ts.sys,
42
- pkgPath,
43
- tsConfig["angularCompilerOptions"]
44
- );
45
- const opt = optFn(parsedTsConfig.options);
46
- const compilerOptions = {
47
- ...parsedTsConfig.options,
48
- ...opt?.compilerOptions
49
- };
50
- const host = ts.createIncrementalCompilerHost(compilerOptions);
51
- return new SdTsIncrementalBuilder(
52
- pkgPath,
53
- compilerOptions,
54
- host,
55
- opt
56
- );
57
- }
58
-
59
- public async buildAsync(): Promise<{
60
- affectedFilePaths: string[];
61
- results: ISdCliPackageBuildResult[];
62
- }> {
63
- const logger = Logger.get(["simplysm", "sd-cli", "SdTsIncrementalBuilder", "buildAsync"]);
64
-
65
- const distPath = this._compilerOptions.outDir ?? path.resolve(this._pkgPath, "dist");
66
- const srcGlobPath = path.resolve(this._pkgPath, "src/**/*.{ts,tsx}");
67
- const srcFilePaths = await FsUtil.globAsync(srcGlobPath);
68
-
69
- if (this._compilerOptions["strictTemplates"] === true) {
70
- this._ngProgram = new NgtscProgram(
71
- srcFilePaths,
72
- this._compilerOptions,
73
- this._host,
74
- this._ngProgram
75
- );
76
- this._program = this._ngProgram.getTsProgram();
77
- }
78
- else {
79
- this._program = ts.createProgram(
80
- srcFilePaths,
81
- this._compilerOptions,
82
- this._host,
83
- this._program
84
- );
85
- }
86
-
87
- const baseGetSourceFiles = this._program.getSourceFiles;
88
- this._program.getSourceFiles = function (...parameters) {
89
- const files: readonly (ts.SourceFile & { version?: string })[] = baseGetSourceFiles(...parameters);
90
-
91
- for (const file of files) {
92
- if (file.version === undefined) {
93
- file.version = createHash("sha256").update(file.text).digest("hex");
94
- }
95
- }
96
-
97
- return files;
98
- };
99
-
100
- this.builderProgram = ts.createSemanticDiagnosticsBuilderProgram(
101
- this._program,
102
- this._host,
103
- this.builderProgram
104
- );
105
-
106
- const diagnostics: ts.Diagnostic[] = [];
107
- const affectedFilePaths: string[] = [];
108
-
109
- if (this._ngProgram) {
110
- diagnostics.push(...this._ngProgram.compiler.getOptionDiagnostics());
111
- }
112
-
113
- diagnostics.push(
114
- ...this.builderProgram.getOptionsDiagnostics(),
115
- ...this.builderProgram.getGlobalDiagnostics(),
116
- );
117
-
118
- if (this._ngProgram) {
119
- await this._ngProgram.compiler.analyzeAsync();
120
- }
121
-
122
- const program = this.builderProgram.getProgram();
123
-
124
- logger.debug(`[${path.basename(this._pkgPath)}] 영향받는 파일 확인 및 처리중...`);
125
- const srcFilePathSet = new Set<string>(srcFilePaths);
126
- while (true) {
127
- let affectedSourceFile: ts.SourceFile | undefined;
128
-
129
- const semanticResult = this.builderProgram.getSemanticDiagnosticsOfNextAffectedFile(undefined, (sourceFile) => {
130
- //-- ngtypecheck의 org파일 포함 (ngtypecheck 파일는 무시)
131
- if (this._ngProgram?.compiler.ignoreForDiagnostics.has(sourceFile) && sourceFile.fileName.endsWith(".ngtypecheck.ts")) {
132
- const orgFileName = sourceFile.fileName.slice(0, -15) + ".ts";
133
- const orgSourceFile = this.builderProgram!.getSourceFile(orgFileName);
134
- if (orgSourceFile) {
135
- affectedSourceFile = orgSourceFile;
136
- }
137
- return true;
138
- }
139
- //-- 소스폴더 파일 포함
140
- else if (srcFilePathSet.has(path.resolve(sourceFile.fileName))) {
141
- affectedSourceFile = sourceFile;
142
- return false;
143
- }
144
- //-- 나머지 무시
145
- else {
146
- return true;
147
- }
148
- });
149
- if (!semanticResult || !affectedSourceFile) break;
150
- diagnostics.push(...semanticResult.result);
151
-
152
- if ("fileName" in affectedSourceFile) {
153
- const emitResult = this.builderProgram.emit
154
- (affectedSourceFile,
155
- (filePath, data, writeByteOrderMark) => {
156
- let realFilePath = filePath;
157
- let realData = data;
158
- if (PathUtil.isChildPath(realFilePath, path.resolve(distPath, path.basename(this._pkgPath), "src"))) {
159
- realFilePath = path.resolve(distPath, path.relative(path.resolve(distPath, path.basename(this._pkgPath), "src"), realFilePath));
160
-
161
- if (filePath.endsWith(".js.map")) {
162
- const sourceMapContents = JSON.parse(realData);
163
- // remove "../../"
164
- sourceMapContents.sources[0] = sourceMapContents.sources[0].slice(6);
165
- realData = JSON.stringify(sourceMapContents);
166
- }
167
- }
168
-
169
- if (this._writeFileCache.get(realFilePath) !== realData) {
170
- this._host.writeFile(realFilePath, realData, writeByteOrderMark);
171
- }
172
- this._writeFileCache.set(realFilePath, realData);
173
- },
174
- undefined,
175
- Array.isArray(this._opt.emitJs) ? !this._opt.emitJs.includes(path.resolve(affectedSourceFile.fileName)) : !this._opt.emitJs,
176
- this._opt.transforms ? {
177
- before: this._opt.transforms.map((item) => typeof item.fn === "function" ? item.fn(program, item.args) : (item.fn["default"] as any)(program, item.args))
178
- } : undefined
179
- );
180
- diagnostics.push(...emitResult.diagnostics);
181
-
182
- diagnostics.push(...this.builderProgram.getSyntacticDiagnostics(affectedSourceFile));
183
-
184
- if (
185
- this._ngProgram &&
186
- !affectedSourceFile.isDeclarationFile &&
187
- !this._ngProgram.compiler.ignoreForEmit.has(affectedSourceFile) &&
188
- !this._ngProgram.compiler.incrementalCompilation.safeToSkipEmit(affectedSourceFile)
189
- ) {
190
- diagnostics.push(
191
- ...this._ngProgram.compiler.getDiagnosticsForFile(affectedSourceFile, 1)
192
- );
193
- }
194
-
195
- affectedFilePaths.push(path.resolve(affectedSourceFile.fileName));
196
- }
197
- }
198
- logger.debug(`[${path.basename(this._pkgPath)}] 영향받는 파일 확인 및 처리 완료`, affectedFilePaths);
199
-
200
- const buildResults = diagnostics.map((item) => SdCliBuildResultUtil.convertFromTsDiag(item));
201
-
202
- return {
203
- affectedFilePaths,
204
- results: buildResults
205
- };
206
- }
207
- }