@simplysm/sd-cli 12.15.39 → 12.15.41
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.
- package/dist/entry/SdCliCordova.d.ts +33 -1
- package/dist/entry/SdCliCordova.js +84 -88
- package/dist/entry/SdCliElectron.d.ts +5 -1
- package/dist/entry/SdCliElectron.js +21 -21
- package/dist/entry/SdCliLocalUpdate.d.ts +1 -1
- package/dist/entry/SdCliLocalUpdate.js +3 -3
- package/dist/entry/SdCliProject.d.ts +4 -1
- package/dist/entry/SdCliProject.js +11 -11
- package/dist/pkg-builders/SdProjectBuildRunner.d.ts +6 -1
- package/dist/pkg-builders/SdProjectBuildRunner.js +27 -27
- package/dist/pkg-builders/client/SdClientBuildRunner.d.ts +2 -1
- package/dist/pkg-builders/client/SdClientBuildRunner.js +8 -10
- package/dist/pkg-builders/client/SdNgBundler.d.ts +22 -1
- package/dist/pkg-builders/client/SdNgBundler.js +70 -80
- package/dist/pkg-builders/client/SdNgBundlerContext.d.ts +3 -1
- package/dist/pkg-builders/client/SdNgBundlerContext.js +9 -10
- package/dist/pkg-builders/lib/SdCliIndexFileGenerator.d.ts +2 -1
- package/dist/pkg-builders/lib/SdCliIndexFileGenerator.js +5 -5
- package/dist/pkg-builders/lib/SdJsLibBuildRunner.d.ts +1 -1
- package/dist/pkg-builders/lib/SdJsLibBuildRunner.js +2 -2
- package/dist/pkg-builders/lib/SdTsLibBuildRunner.d.ts +1 -1
- package/dist/pkg-builders/lib/SdTsLibBuildRunner.js +2 -3
- package/dist/pkg-builders/lib/SdTsLibBuilder.d.ts +2 -1
- package/dist/pkg-builders/lib/SdTsLibBuilder.js +7 -8
- package/dist/pkg-builders/server/SdServerBuildRunner.d.ts +3 -1
- package/dist/pkg-builders/server/SdServerBuildRunner.js +6 -7
- package/dist/pkg-builders/server/SdServerBundler.d.ts +6 -1
- package/dist/pkg-builders/server/SdServerBundler.js +21 -23
- package/dist/ts-compiler/ScopePathSet.d.ts +1 -1
- package/dist/ts-compiler/ScopePathSet.js +3 -4
- package/dist/ts-compiler/SdDepCache.d.ts +45 -1
- package/dist/ts-compiler/SdDepCache.js +71 -69
- package/dist/ts-compiler/SdStyleBundler.d.ts +5 -1
- package/dist/ts-compiler/SdStyleBundler.js +25 -26
- package/dist/ts-compiler/SdTsCompiler.d.ts +20 -1
- package/dist/ts-compiler/SdTsCompiler.js +122 -129
- package/dist/utils/SdCliPerformanceTimer.d.ts +2 -1
- package/dist/utils/SdCliPerformanceTimer.js +9 -9
- package/package.json +8 -8
- package/src/entry/SdCliCordova.ts +89 -89
- package/src/entry/SdCliElectron.ts +21 -21
- package/src/entry/SdCliLocalUpdate.ts +3 -3
- package/src/entry/SdCliProject.ts +11 -11
- package/src/pkg-builders/SdProjectBuildRunner.ts +27 -27
- package/src/pkg-builders/client/SdClientBuildRunner.ts +10 -10
- package/src/pkg-builders/client/SdNgBundler.ts +78 -78
- package/src/pkg-builders/client/SdNgBundlerContext.ts +10 -10
- package/src/pkg-builders/lib/SdCliIndexFileGenerator.ts +5 -5
- package/src/pkg-builders/lib/SdJsLibBuildRunner.ts +2 -2
- package/src/pkg-builders/lib/SdTsLibBuildRunner.ts +3 -3
- package/src/pkg-builders/lib/SdTsLibBuilder.ts +8 -8
- package/src/pkg-builders/server/SdServerBuildRunner.ts +7 -7
- package/src/pkg-builders/server/SdServerBundler.ts +23 -23
- package/src/ts-compiler/ScopePathSet.ts +4 -4
- package/src/ts-compiler/SdDepCache.ts +47 -47
- package/src/ts-compiler/SdStyleBundler.ts +26 -26
- package/src/ts-compiler/SdTsCompiler.ts +130 -130
- package/src/utils/SdCliPerformanceTimer.ts +9 -9
|
@@ -8,10 +8,11 @@ interface InitialFileRecord {
|
|
|
8
8
|
depth: number;
|
|
9
9
|
}
|
|
10
10
|
export declare class SdNgBundlerContext {
|
|
11
|
-
#private;
|
|
12
11
|
private readonly _pkgPath;
|
|
13
12
|
private readonly _watch;
|
|
14
13
|
private readonly _esbuildOptions;
|
|
14
|
+
private readonly _logger;
|
|
15
|
+
private _context?;
|
|
15
16
|
constructor(_pkgPath: string, _watch: boolean, _esbuildOptions: esbuild.BuildOptions);
|
|
16
17
|
bundleAsync(): Promise<{
|
|
17
18
|
results: import("../../types/build/ISdBuildMessage").ISdBuildMessage[];
|
|
@@ -19,5 +20,6 @@ export declare class SdNgBundlerContext {
|
|
|
19
20
|
outputFiles: esbuild.OutputFile[] | undefined;
|
|
20
21
|
metafile: esbuild.Metafile | undefined;
|
|
21
22
|
}>;
|
|
23
|
+
private _debug;
|
|
22
24
|
}
|
|
23
25
|
export {};
|
|
@@ -3,22 +3,21 @@ import path from "path";
|
|
|
3
3
|
import { SdLogger } from "@simplysm/sd-core-node";
|
|
4
4
|
import { SdCliConvertMessageUtils } from "../../utils/SdCliConvertMessageUtils";
|
|
5
5
|
export class SdNgBundlerContext {
|
|
6
|
-
#logger = SdLogger.get(["simplysm", "sd-cli", "SdNgBundlerContext"]);
|
|
7
|
-
#context;
|
|
8
6
|
constructor(_pkgPath, _watch, _esbuildOptions) {
|
|
9
7
|
this._pkgPath = _pkgPath;
|
|
10
8
|
this._watch = _watch;
|
|
11
9
|
this._esbuildOptions = _esbuildOptions;
|
|
10
|
+
this._logger = SdLogger.get(["simplysm", "sd-cli", "SdNgBundlerContext"]);
|
|
12
11
|
}
|
|
13
12
|
async bundleAsync() {
|
|
14
13
|
let esbuildResult;
|
|
15
|
-
this
|
|
14
|
+
this._debug(`Building...`);
|
|
16
15
|
if (this._watch) {
|
|
17
|
-
if (this
|
|
18
|
-
this
|
|
16
|
+
if (this._context == null) {
|
|
17
|
+
this._context = await esbuild.context(this._esbuildOptions);
|
|
19
18
|
}
|
|
20
19
|
try {
|
|
21
|
-
esbuildResult = await this
|
|
20
|
+
esbuildResult = await this._context.rebuild();
|
|
22
21
|
}
|
|
23
22
|
catch (err) {
|
|
24
23
|
if ("warnings" in err || "errors" in err) {
|
|
@@ -42,8 +41,8 @@ export class SdNgBundlerContext {
|
|
|
42
41
|
}
|
|
43
42
|
}
|
|
44
43
|
}
|
|
45
|
-
this
|
|
46
|
-
this
|
|
44
|
+
this._debug(`Build completed`);
|
|
45
|
+
this._debug(`Converting results...`);
|
|
47
46
|
const results = SdCliConvertMessageUtils.convertToBuildMessagesFromEsbuild(esbuildResult, this._pkgPath);
|
|
48
47
|
const initialFiles = new Map();
|
|
49
48
|
for (const outputFile of esbuildResult.outputFiles ?? []) {
|
|
@@ -99,7 +98,7 @@ export class SdNgBundlerContext {
|
|
|
99
98
|
metafile: esbuildResult.metafile,
|
|
100
99
|
};
|
|
101
100
|
}
|
|
102
|
-
|
|
103
|
-
this
|
|
101
|
+
_debug(...msg) {
|
|
102
|
+
this._logger.debug(`[${path.basename(this._pkgPath)}] (${Object.keys(this._esbuildOptions.entryPoints).join(", ")})`, ...msg);
|
|
104
103
|
}
|
|
105
104
|
}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
export declare class SdCliIndexFileGenerator {
|
|
2
|
-
#private;
|
|
3
2
|
cachedHash?: string;
|
|
4
3
|
watchAsync(pkgPath: string, polyfills?: string[], excludes?: string[]): Promise<void>;
|
|
5
4
|
runAsync(pkgPath: string, polyfills?: string[], excludes?: string[]): Promise<{
|
|
@@ -7,4 +6,6 @@ export declare class SdCliIndexFileGenerator {
|
|
|
7
6
|
filePath: string;
|
|
8
7
|
content: string;
|
|
9
8
|
}>;
|
|
9
|
+
private _getFilePathsAsync;
|
|
10
|
+
private _getExcludesAsync;
|
|
10
11
|
}
|
|
@@ -7,7 +7,7 @@ export class SdCliIndexFileGenerator {
|
|
|
7
7
|
? HashUtils.get(await FsUtils.readFileAsync(indexFilePath))
|
|
8
8
|
: undefined;
|
|
9
9
|
const watcher = await SdFsWatcher.watchAsync([path.resolve(pkgPath, "src")], {
|
|
10
|
-
ignored: await this
|
|
10
|
+
ignored: await this._getExcludesAsync(pkgPath, excludes),
|
|
11
11
|
});
|
|
12
12
|
watcher.onChange({ delay: 50 }, async (changeInfos) => {
|
|
13
13
|
if (changeInfos.some((item) => ["add", "addDir", "unlink", "unlinkDir"].includes(item.event)))
|
|
@@ -25,7 +25,7 @@ export class SdCliIndexFileGenerator {
|
|
|
25
25
|
}
|
|
26
26
|
}
|
|
27
27
|
// 내부 파일들 import
|
|
28
|
-
const filePaths = await this
|
|
28
|
+
const filePaths = await this._getFilePathsAsync(pkgPath, excludes);
|
|
29
29
|
for (const filePath of filePaths.orderBy()) {
|
|
30
30
|
const requirePath = PathUtils.posix(path.relative(path.dirname(indexFilePath), filePath))
|
|
31
31
|
.replace(/\.tsx?$/, "")
|
|
@@ -49,7 +49,7 @@ export class SdCliIndexFileGenerator {
|
|
|
49
49
|
return { changed: false, filePath: indexFilePath, content };
|
|
50
50
|
}
|
|
51
51
|
}
|
|
52
|
-
async
|
|
52
|
+
async _getFilePathsAsync(pkgPath, excludes) {
|
|
53
53
|
/*const indexFilePath = path.resolve(pkgPath, "src/index.ts");
|
|
54
54
|
|
|
55
55
|
const tsconfig = await FsUtils.readJsonAsync(path.resolve(pkgPath, "tsconfig.json"));
|
|
@@ -57,10 +57,10 @@ export class SdCliIndexFileGenerator {
|
|
|
57
57
|
tsconfig.files?.map((item) => path.resolve(pkgPath, item)) ?? [];*/
|
|
58
58
|
return await FsUtils.globAsync(path.resolve(pkgPath, "src/**/*{.ts,.tsx}"), {
|
|
59
59
|
nodir: true,
|
|
60
|
-
ignore: await this
|
|
60
|
+
ignore: await this._getExcludesAsync(pkgPath, excludes),
|
|
61
61
|
});
|
|
62
62
|
}
|
|
63
|
-
async
|
|
63
|
+
async _getExcludesAsync(pkgPath, excludes) {
|
|
64
64
|
const indexFilePath = path.resolve(pkgPath, "src/index.ts");
|
|
65
65
|
const tsconfig = await FsUtils.readJsonAsync(path.resolve(pkgPath, "tsconfig.json"));
|
|
66
66
|
return [
|
|
@@ -2,7 +2,7 @@ import { SdLogger, TNormPath } from "@simplysm/sd-core-node";
|
|
|
2
2
|
import { SdBuildRunnerBase } from "../SdBuildRunnerBase";
|
|
3
3
|
import { ISdBuildResult } from "../../types/build/ISdBuildResult";
|
|
4
4
|
export declare class SdJsLibBuildRunner extends SdBuildRunnerBase<"library"> {
|
|
5
|
-
#private;
|
|
6
5
|
protected _logger: SdLogger;
|
|
7
6
|
protected _runAsync(modifiedFileSet?: Set<TNormPath>): Promise<ISdBuildResult>;
|
|
7
|
+
private _lintAsync;
|
|
8
8
|
}
|
|
@@ -20,7 +20,7 @@ export class SdJsLibBuildRunner extends SdBuildRunnerBase {
|
|
|
20
20
|
const filePathSet = modifiedFileSet ??
|
|
21
21
|
new Set(FsUtils.glob(path.resolve(this._opt.pkgPath, "src/**/*.js")).map((item) => PathUtils.norm(item)));
|
|
22
22
|
this._debug("LINT...");
|
|
23
|
-
const lintResults = await this
|
|
23
|
+
const lintResults = await this._lintAsync(filePathSet);
|
|
24
24
|
const messages = SdCliConvertMessageUtils.convertToBuildMessagesFromEslint(lintResults);
|
|
25
25
|
this._debug(`LINT 완료`);
|
|
26
26
|
return {
|
|
@@ -30,7 +30,7 @@ export class SdJsLibBuildRunner extends SdBuildRunnerBase {
|
|
|
30
30
|
emitFileSet: new Set(),
|
|
31
31
|
};
|
|
32
32
|
}
|
|
33
|
-
async
|
|
33
|
+
async _lintAsync(fileSet) {
|
|
34
34
|
const lintFilePaths = Array.from(fileSet)
|
|
35
35
|
.filter((item) => PathUtils.isChildPath(item, path.resolve(this._opt.pkgPath, "src")))
|
|
36
36
|
.filter((item) => item.endsWith(".js"))
|
|
@@ -2,7 +2,7 @@ import { SdLogger, TNormPath } from "@simplysm/sd-core-node";
|
|
|
2
2
|
import { SdBuildRunnerBase } from "../SdBuildRunnerBase";
|
|
3
3
|
import { ISdBuildResult } from "../../types/build/ISdBuildResult";
|
|
4
4
|
export declare class SdTsLibBuildRunner extends SdBuildRunnerBase<"library"> {
|
|
5
|
-
#private;
|
|
6
5
|
protected _logger: SdLogger;
|
|
6
|
+
private _builder?;
|
|
7
7
|
protected _runAsync(modifiedFileSet?: Set<TNormPath>): Promise<ISdBuildResult>;
|
|
8
8
|
}
|
|
@@ -8,7 +8,6 @@ export class SdTsLibBuildRunner extends SdBuildRunnerBase {
|
|
|
8
8
|
super(...arguments);
|
|
9
9
|
this._logger = SdLogger.get(["simplysm", "sd-cli", "SdTsLibBuildRunner"]);
|
|
10
10
|
}
|
|
11
|
-
#builder;
|
|
12
11
|
async _runAsync(modifiedFileSet) {
|
|
13
12
|
// 최초한번
|
|
14
13
|
if (!modifiedFileSet) {
|
|
@@ -25,10 +24,10 @@ export class SdTsLibBuildRunner extends SdBuildRunnerBase {
|
|
|
25
24
|
}
|
|
26
25
|
}
|
|
27
26
|
this._debug(`BUILD 준비...`);
|
|
28
|
-
this
|
|
27
|
+
this._builder = new SdTsLibBuilder(this._opt);
|
|
29
28
|
}
|
|
30
29
|
this._debug(`BUILD...`);
|
|
31
|
-
const buildResult = await this
|
|
30
|
+
const buildResult = await this._builder.buildAsync(modifiedFileSet);
|
|
32
31
|
this._debug(`빌드 완료`);
|
|
33
32
|
return buildResult;
|
|
34
33
|
}
|
|
@@ -2,8 +2,9 @@ import { TNormPath } from "@simplysm/sd-core-node";
|
|
|
2
2
|
import { ISdBuildResult } from "../../types/build/ISdBuildResult";
|
|
3
3
|
import { ISdTsCompilerOptions } from "../../types/build/ISdTsCompilerOptions";
|
|
4
4
|
export declare class SdTsLibBuilder {
|
|
5
|
-
#private;
|
|
6
5
|
private readonly _opt;
|
|
6
|
+
private readonly _tsCompiler;
|
|
7
|
+
private readonly _outputHashCache;
|
|
7
8
|
constructor(_opt: ISdTsCompilerOptions);
|
|
8
9
|
buildAsync(modifiedFileSet?: Set<TNormPath>): Promise<ISdBuildResult>;
|
|
9
10
|
}
|
|
@@ -3,14 +3,13 @@ import { SdCliConvertMessageUtils } from "../../utils/SdCliConvertMessageUtils";
|
|
|
3
3
|
import { FsUtils, HashUtils, PathUtils } from "@simplysm/sd-core-node";
|
|
4
4
|
import { SdTsCompiler } from "../../ts-compiler/SdTsCompiler";
|
|
5
5
|
export class SdTsLibBuilder {
|
|
6
|
-
#tsCompiler;
|
|
7
|
-
#outputHashCache = new Map();
|
|
8
6
|
constructor(_opt) {
|
|
9
7
|
this._opt = _opt;
|
|
10
|
-
this
|
|
8
|
+
this._outputHashCache = new Map();
|
|
9
|
+
this._tsCompiler = new SdTsCompiler(_opt, false);
|
|
11
10
|
}
|
|
12
11
|
async buildAsync(modifiedFileSet) {
|
|
13
|
-
const tsCompileResult = await this
|
|
12
|
+
const tsCompileResult = await this._tsCompiler.compileAsync(modifiedFileSet ?? new Set());
|
|
14
13
|
const emitFileSet = new Set();
|
|
15
14
|
for (const emitFile of tsCompileResult.emitFileSet) {
|
|
16
15
|
const emitFileInfos = tsCompileResult.emittedFilesCacheMap.get(emitFile);
|
|
@@ -18,11 +17,11 @@ export class SdTsLibBuilder {
|
|
|
18
17
|
for (const emitFileInfo of emitFileInfos) {
|
|
19
18
|
if (emitFileInfo.outAbsPath != null) {
|
|
20
19
|
const emitFilePath = PathUtils.norm(emitFileInfo.outAbsPath);
|
|
21
|
-
const prevHash = this
|
|
20
|
+
const prevHash = this._outputHashCache.get(emitFilePath);
|
|
22
21
|
const currHash = HashUtils.get(Buffer.from(emitFileInfo.text));
|
|
23
22
|
if (prevHash !== currHash) {
|
|
24
23
|
FsUtils.writeFile(emitFilePath, emitFileInfo.text);
|
|
25
|
-
this
|
|
24
|
+
this._outputHashCache.set(emitFilePath, currHash);
|
|
26
25
|
emitFileSet.add(emitFilePath);
|
|
27
26
|
}
|
|
28
27
|
}
|
|
@@ -33,11 +32,11 @@ export class SdTsLibBuilder {
|
|
|
33
32
|
for (const outputFile of globalStylesheetBundlingResult.outputFiles) {
|
|
34
33
|
const distPath = PathUtils.norm(this._opt.pkgPath, "dist", path.relative(this._opt.pkgPath, outputFile.path));
|
|
35
34
|
if (PathUtils.isChildPath(distPath, path.resolve(this._opt.pkgPath, "dist"))) {
|
|
36
|
-
const prevHash = this
|
|
35
|
+
const prevHash = this._outputHashCache.get(distPath);
|
|
37
36
|
const currHash = HashUtils.get(Buffer.from(outputFile.text));
|
|
38
37
|
if (prevHash !== currHash) {
|
|
39
38
|
FsUtils.writeFile(distPath, outputFile.text);
|
|
40
|
-
this
|
|
39
|
+
this._outputHashCache.set(distPath, currHash);
|
|
41
40
|
emitFileSet.add(distPath);
|
|
42
41
|
}
|
|
43
42
|
}
|
|
@@ -2,7 +2,9 @@ import { SdLogger, TNormPath } from "@simplysm/sd-core-node";
|
|
|
2
2
|
import { SdBuildRunnerBase } from "../SdBuildRunnerBase";
|
|
3
3
|
import { ISdBuildResult } from "../../types/build/ISdBuildResult";
|
|
4
4
|
export declare class SdServerBuildRunner extends SdBuildRunnerBase<"server"> {
|
|
5
|
-
#private;
|
|
6
5
|
protected _logger: SdLogger;
|
|
6
|
+
private _serverBundler?;
|
|
7
7
|
protected _runAsync(modifiedFileSet?: Set<TNormPath>): Promise<ISdBuildResult>;
|
|
8
|
+
private _generateProductionFiles;
|
|
9
|
+
private _getExternalModules;
|
|
8
10
|
}
|
|
@@ -8,13 +8,12 @@ export class SdServerBuildRunner extends SdBuildRunnerBase {
|
|
|
8
8
|
super(...arguments);
|
|
9
9
|
this._logger = SdLogger.get(["simplysm", "sd-cli", "SdServerBuildRunner"]);
|
|
10
10
|
}
|
|
11
|
-
#serverBundler;
|
|
12
11
|
async _runAsync(modifiedFileSet) {
|
|
13
12
|
// 최초
|
|
14
13
|
if (!modifiedFileSet) {
|
|
15
|
-
const externalModules = this
|
|
14
|
+
const externalModules = this._getExternalModules();
|
|
16
15
|
if (!this._opt.watch?.dev) {
|
|
17
|
-
this
|
|
16
|
+
this._generateProductionFiles(externalModules.filter((item) => item.exists).map((item) => item.name));
|
|
18
17
|
}
|
|
19
18
|
if (!this._opt.watch?.noEmit) {
|
|
20
19
|
this._debug("GEN .config...");
|
|
@@ -22,16 +21,16 @@ export class SdServerBuildRunner extends SdBuildRunnerBase {
|
|
|
22
21
|
FsUtils.writeFile(confDistPath, JSON.stringify(this._pkgConf.configs ?? {}, undefined, 2));
|
|
23
22
|
}
|
|
24
23
|
this._debug(`BUILD 준비...`);
|
|
25
|
-
this
|
|
24
|
+
this._serverBundler = new SdServerBundler(this._opt, {
|
|
26
25
|
external: externalModules.map((item) => item.name),
|
|
27
26
|
});
|
|
28
27
|
}
|
|
29
28
|
this._debug(`BUILD...`);
|
|
30
|
-
const bundleResult = await this
|
|
29
|
+
const bundleResult = await this._serverBundler.bundleAsync(modifiedFileSet);
|
|
31
30
|
this._debug(`빌드 완료`);
|
|
32
31
|
return bundleResult;
|
|
33
32
|
}
|
|
34
|
-
|
|
33
|
+
_generateProductionFiles(externals) {
|
|
35
34
|
const npmConf = FsUtils.readJson(path.resolve(this._opt.pkgPath, "package.json"));
|
|
36
35
|
this._debug("GEN package.json...");
|
|
37
36
|
{
|
|
@@ -150,7 +149,7 @@ Options = UnsafeLegacyRenegotiation`.trim());
|
|
|
150
149
|
</configuration>`.trim());
|
|
151
150
|
}
|
|
152
151
|
}
|
|
153
|
-
|
|
152
|
+
_getExternalModules() {
|
|
154
153
|
const loadedModuleNames = [];
|
|
155
154
|
const results = [];
|
|
156
155
|
const npmConfigMap = new Map();
|
|
@@ -2,9 +2,14 @@ import { TNormPath } from "@simplysm/sd-core-node";
|
|
|
2
2
|
import { ISdBuildResult } from "../../types/build/ISdBuildResult";
|
|
3
3
|
import { ISdTsCompilerOptions } from "../../types/build/ISdTsCompilerOptions";
|
|
4
4
|
export declare class SdServerBundler {
|
|
5
|
-
#private;
|
|
6
5
|
private readonly _opt;
|
|
7
6
|
private readonly _conf;
|
|
7
|
+
private readonly _logger;
|
|
8
|
+
private _context?;
|
|
9
|
+
private readonly _modifiedFileSet;
|
|
10
|
+
private readonly _resultCache;
|
|
11
|
+
private readonly _outputHashCache;
|
|
12
|
+
private readonly _esbuildOptions;
|
|
8
13
|
constructor(_opt: ISdTsCompilerOptions, _conf: {
|
|
9
14
|
external: string[];
|
|
10
15
|
});
|
|
@@ -8,16 +8,14 @@ import { convertOutputFile } from "@angular/build/src/tools/esbuild/utils";
|
|
|
8
8
|
import { resolveAssets } from "@angular/build/src/utils/resolve-assets";
|
|
9
9
|
import { SdWorkerPathPlugin } from "../commons/SdWorkerPathPlugin";
|
|
10
10
|
export class SdServerBundler {
|
|
11
|
-
#logger = SdLogger.get(["simplysm", "sd-cli", "SdServerBundler"]);
|
|
12
|
-
#context;
|
|
13
|
-
#modifiedFileSet = new Set();
|
|
14
|
-
#resultCache = {};
|
|
15
|
-
#outputHashCache = new Map();
|
|
16
|
-
#esbuildOptions;
|
|
17
11
|
constructor(_opt, _conf) {
|
|
18
12
|
this._opt = _opt;
|
|
19
13
|
this._conf = _conf;
|
|
20
|
-
this
|
|
14
|
+
this._logger = SdLogger.get(["simplysm", "sd-cli", "SdServerBundler"]);
|
|
15
|
+
this._modifiedFileSet = new Set();
|
|
16
|
+
this._resultCache = {};
|
|
17
|
+
this._outputHashCache = new Map();
|
|
18
|
+
this._esbuildOptions = {
|
|
21
19
|
entryPoints: [
|
|
22
20
|
path.resolve(this._opt.pkgPath, "src/main.ts"),
|
|
23
21
|
// ...FsUtils.glob(path.resolve(this._opt.pkgPath, "src/workers/*.ts")),
|
|
@@ -80,23 +78,23 @@ const __filename = __fileURLToPath__(import.meta.url);
|
|
|
80
78
|
const __dirname = __path__.dirname(__filename);`.trim(),
|
|
81
79
|
},
|
|
82
80
|
plugins: [
|
|
83
|
-
createSdServerPlugin(this._opt, this
|
|
81
|
+
createSdServerPlugin(this._opt, this._modifiedFileSet, this._resultCache),
|
|
84
82
|
SdWorkerPathPlugin(path.resolve(this._opt.pkgPath, "dist")),
|
|
85
83
|
],
|
|
86
84
|
};
|
|
87
85
|
}
|
|
88
86
|
async bundleAsync(modifiedFileSet) {
|
|
89
|
-
this
|
|
87
|
+
this._modifiedFileSet.clear();
|
|
90
88
|
if (modifiedFileSet) {
|
|
91
|
-
this
|
|
89
|
+
this._modifiedFileSet.adds(...modifiedFileSet);
|
|
92
90
|
}
|
|
93
91
|
let esbuildResult;
|
|
94
92
|
if (this._opt.watch) {
|
|
95
|
-
if (this
|
|
96
|
-
this
|
|
93
|
+
if (this._context == null) {
|
|
94
|
+
this._context = await esbuild.context(this._esbuildOptions);
|
|
97
95
|
}
|
|
98
96
|
try {
|
|
99
|
-
esbuildResult = await this
|
|
97
|
+
esbuildResult = await this._context.rebuild();
|
|
100
98
|
}
|
|
101
99
|
catch (err) {
|
|
102
100
|
if ("warnings" in err || "errors" in err) {
|
|
@@ -109,7 +107,7 @@ const __dirname = __path__.dirname(__filename);`.trim(),
|
|
|
109
107
|
}
|
|
110
108
|
else {
|
|
111
109
|
try {
|
|
112
|
-
esbuildResult = await esbuild.build(this
|
|
110
|
+
esbuildResult = await esbuild.build(this._esbuildOptions);
|
|
113
111
|
}
|
|
114
112
|
catch (err) {
|
|
115
113
|
if ("warnings" in err || "errors" in err) {
|
|
@@ -123,8 +121,8 @@ const __dirname = __path__.dirname(__filename);`.trim(),
|
|
|
123
121
|
if (this._opt.watch?.noEmit) {
|
|
124
122
|
return {
|
|
125
123
|
buildMessages: SdCliConvertMessageUtils.convertToBuildMessagesFromEsbuild(esbuildResult, this._opt.pkgPath),
|
|
126
|
-
watchFileSet: this
|
|
127
|
-
affectedFileSet: this
|
|
124
|
+
watchFileSet: this._resultCache.watchFileSet,
|
|
125
|
+
affectedFileSet: this._resultCache.affectedFileSet,
|
|
128
126
|
emitFileSet: new Set(),
|
|
129
127
|
};
|
|
130
128
|
}
|
|
@@ -134,11 +132,11 @@ const __dirname = __path__.dirname(__filename);`.trim(),
|
|
|
134
132
|
const outputFiles = esbuildResult.outputFiles?.map((file) => convertOutputFile(file, BuildOutputFileType.Root)) ?? [];
|
|
135
133
|
for (const outputFile of outputFiles) {
|
|
136
134
|
const distFilePath = PathUtils.norm(this._opt.pkgPath, outputFile.path);
|
|
137
|
-
const prevHash = this
|
|
135
|
+
const prevHash = this._outputHashCache.get(distFilePath);
|
|
138
136
|
const currHash = HashUtils.get(Buffer.from(outputFile.contents));
|
|
139
137
|
if (prevHash !== currHash) {
|
|
140
138
|
FsUtils.writeFile(distFilePath, outputFile.contents);
|
|
141
|
-
this
|
|
139
|
+
this._outputHashCache.set(distFilePath, currHash);
|
|
142
140
|
emitFileSet.add(distFilePath);
|
|
143
141
|
}
|
|
144
142
|
}
|
|
@@ -148,11 +146,11 @@ const __dirname = __path__.dirname(__filename);`.trim(),
|
|
|
148
146
|
...(this._opt.watch?.dev ? [{ input: "public-dev", glob: "**/*", output: "." }] : []),
|
|
149
147
|
], this._opt.pkgPath);
|
|
150
148
|
for (const assetFile of assetFiles) {
|
|
151
|
-
const prevHash = this
|
|
149
|
+
const prevHash = this._outputHashCache.get(PathUtils.norm(assetFile.source));
|
|
152
150
|
const currHash = HashUtils.get(FsUtils.readFileBuffer(assetFile.source));
|
|
153
151
|
if (prevHash !== currHash) {
|
|
154
152
|
FsUtils.copy(assetFile.source, path.resolve(this._opt.pkgPath, "dist", assetFile.destination));
|
|
155
|
-
this
|
|
153
|
+
this._outputHashCache.set(PathUtils.norm(assetFile.source), currHash);
|
|
156
154
|
emitFileSet.add(PathUtils.norm(this._opt.pkgPath, "dist", assetFile.destination));
|
|
157
155
|
}
|
|
158
156
|
}
|
|
@@ -161,14 +159,14 @@ const __dirname = __path__.dirname(__filename);`.trim(),
|
|
|
161
159
|
esbuildResult = err;
|
|
162
160
|
for (const e of err.errors) {
|
|
163
161
|
if (e.detail != null) {
|
|
164
|
-
this
|
|
162
|
+
this._logger.error(e.detail);
|
|
165
163
|
}
|
|
166
164
|
}
|
|
167
165
|
}
|
|
168
166
|
return {
|
|
169
167
|
buildMessages: SdCliConvertMessageUtils.convertToBuildMessagesFromEsbuild(esbuildResult, this._opt.pkgPath),
|
|
170
|
-
watchFileSet: this
|
|
171
|
-
affectedFileSet: this
|
|
168
|
+
watchFileSet: this._resultCache.watchFileSet,
|
|
169
|
+
affectedFileSet: this._resultCache.affectedFileSet,
|
|
172
170
|
emitFileSet: emitFileSet,
|
|
173
171
|
};
|
|
174
172
|
}
|
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
import { PathUtils } from "@simplysm/sd-core-node";
|
|
2
2
|
export class ScopePathSet {
|
|
3
|
-
#data;
|
|
4
3
|
constructor(arrOrSet) {
|
|
5
|
-
this
|
|
4
|
+
this._data = arrOrSet instanceof Set ? arrOrSet : new Set(arrOrSet);
|
|
6
5
|
}
|
|
7
6
|
inScope(filePath) {
|
|
8
|
-
return Array.from(this
|
|
7
|
+
return Array.from(this._data).some((scope) => PathUtils.isChildPath(filePath, scope));
|
|
9
8
|
}
|
|
10
9
|
toArray() {
|
|
11
|
-
return Array.from(this
|
|
10
|
+
return Array.from(this._data);
|
|
12
11
|
}
|
|
13
12
|
}
|
|
@@ -1,6 +1,38 @@
|
|
|
1
1
|
import { TNormPath } from "@simplysm/sd-core-node";
|
|
2
2
|
export declare class SdDepCache {
|
|
3
|
-
|
|
3
|
+
/**
|
|
4
|
+
* 각 파일이 export한 심볼 집합 (예: export const A → "A")
|
|
5
|
+
*/
|
|
6
|
+
private readonly _exportCache;
|
|
7
|
+
/**
|
|
8
|
+
* import한 타겟과 그 심볼 정보
|
|
9
|
+
* - 값이 0이면 전체 import(import * 또는 리소스 import)
|
|
10
|
+
* - 값이 Set이면 선택적 심볼 import (예: import { A } ...)
|
|
11
|
+
*/
|
|
12
|
+
private readonly _importCache;
|
|
13
|
+
/**
|
|
14
|
+
* re-export한 타겟과 그 심볼 정보
|
|
15
|
+
* - export * from ...
|
|
16
|
+
* - export { A as B } from ...
|
|
17
|
+
* - 값이 0이면 전체 reexport(export * from ...)
|
|
18
|
+
*/
|
|
19
|
+
private readonly _reexportCache;
|
|
20
|
+
/**
|
|
21
|
+
* 역의존 정보 (revDep)
|
|
22
|
+
* - 특정 파일이 어떤 파일에게 의존(참조)되는지
|
|
23
|
+
* - symbol 기반 추적
|
|
24
|
+
*/
|
|
25
|
+
private readonly _revDepCache;
|
|
26
|
+
/**
|
|
27
|
+
* 분석이 완료된 파일 경로
|
|
28
|
+
*/
|
|
29
|
+
private readonly _collectedCache;
|
|
30
|
+
private readonly _exportSymbolCache;
|
|
31
|
+
/**
|
|
32
|
+
* .d.ts 또는 .js가 입력되었을 때 쌍으로 존재하는 파일 경로를 반환
|
|
33
|
+
* 예: "/a.d.ts" → ["/a.d.ts", "/a.js"]
|
|
34
|
+
*/
|
|
35
|
+
private _getRelatedNPaths;
|
|
4
36
|
/**
|
|
5
37
|
* 분석이 완료된 파일로 표시
|
|
6
38
|
*/
|
|
@@ -25,9 +57,21 @@ export declare class SdDepCache {
|
|
|
25
57
|
importSymbol: string;
|
|
26
58
|
exportSymbol: string;
|
|
27
59
|
} | 0): void;
|
|
60
|
+
/**
|
|
61
|
+
* 역의존 관계 등록 (revDep)
|
|
62
|
+
*/
|
|
63
|
+
private _addRevDep;
|
|
28
64
|
getAffectedFileMap(modifiedNPathSet: Set<TNormPath>): Map<TNormPath, Set<TNormPath>>;
|
|
29
65
|
/**
|
|
30
66
|
* 주어진 파일들 및 그 영향 범위에 해당하는 모든 캐시를 무효화
|
|
31
67
|
*/
|
|
32
68
|
invalidates(fileNPathSet: Set<TNormPath>): void;
|
|
69
|
+
/**
|
|
70
|
+
* reexport된 경우 importSymbol → exportSymbol로 변환
|
|
71
|
+
*/
|
|
72
|
+
private _convertImportSymbolToExportSymbol;
|
|
73
|
+
/**
|
|
74
|
+
* 해당 파일에서 export된 모든 심볼 (직접 + 재export 포함)
|
|
75
|
+
*/
|
|
76
|
+
private _getExportSymbols;
|
|
33
77
|
}
|