@simplysm/sd-cli 12.8.20 → 12.8.22
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/sd-cli-cordova.d.ts +30 -0
- package/dist/entry/sd-cli-cordova.js +307 -246
- package/dist/entry/sd-cli-cordova.js.map +1 -1
- package/dist/entry/sd-cli-project.d.ts +1 -1
- package/dist/entry/sd-cli-project.js +8 -9
- package/dist/entry/sd-cli-project.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/pkg-builders/client/sd-ng.bundler.d.ts +15 -1
- package/dist/pkg-builders/client/sd-ng.bundler.js +60 -70
- package/dist/pkg-builders/client/sd-ng.bundler.js.map +1 -1
- package/dist/pkg-builders/client/sd-ng.plugin-creator.js +49 -29
- package/dist/pkg-builders/client/sd-ng.plugin-creator.js.map +1 -1
- package/dist/pkg-builders/lib/sd-ts-lib.builder.js +7 -4
- package/dist/pkg-builders/lib/sd-ts-lib.builder.js.map +1 -1
- package/dist/pkg-builders/server/sd-server.bundler.js +11 -10
- package/dist/pkg-builders/server/sd-server.bundler.js.map +1 -1
- package/dist/ts-compiler/sd-ts-compiler.d.ts +25 -2
- package/dist/ts-compiler/sd-ts-compiler.js +306 -575
- package/dist/ts-compiler/sd-ts-compiler.js.map +1 -1
- package/dist/ts-compiler/sd-ts-dependency-analyzer.d.ts +6 -0
- package/dist/ts-compiler/sd-ts-dependency-analyzer.js +141 -0
- package/dist/ts-compiler/sd-ts-dependency-analyzer.js.map +1 -0
- package/dist/types/ts-compiler.types.d.ts +12 -7
- package/dist/types/worker.types.d.ts +13 -0
- package/dist/utils/sd-cli-performance-time.js +1 -1
- package/package.json +6 -8
- package/src/entry/sd-cli-cordova.ts +393 -280
- package/src/entry/sd-cli-project.ts +11 -23
- package/src/index.ts +1 -0
- package/src/pkg-builders/client/sd-ng.bundler.ts +67 -69
- package/src/pkg-builders/client/sd-ng.plugin-creator.ts +47 -27
- package/src/pkg-builders/lib/sd-ts-lib.builder.ts +14 -7
- package/src/pkg-builders/server/sd-server.bundler.ts +22 -12
- package/src/ts-compiler/sd-ts-compiler.ts +379 -704
- package/src/ts-compiler/sd-ts-dependency-analyzer.ts +185 -0
- package/src/types/ts-compiler.types.ts +11 -6
- package/src/types/worker.types.ts +7 -6
- package/src/utils/sd-cli-performance-time.ts +1 -1
|
@@ -2,10 +2,9 @@ import path from "path";
|
|
|
2
2
|
import { FsUtils, PathUtils, SdLogger, SdProcess } from "@simplysm/sd-core-node";
|
|
3
3
|
import { pathToFileURL } from "url";
|
|
4
4
|
import semver from "semver";
|
|
5
|
-
import { NeverEntryError, StringUtils, Wait } from "@simplysm/sd-core-common";
|
|
5
|
+
import { NeverEntryError, StringUtils, Wait, XmlConvert } from "@simplysm/sd-core-common";
|
|
6
6
|
import { SdStorage } from "@simplysm/sd-storage";
|
|
7
7
|
import { SdCliLocalUpdate } from "./sd-cli-local-update";
|
|
8
|
-
import xml2js from "xml2js";
|
|
9
8
|
import { SdMultiBuildRunner } from "../pkg-builders/sd-multi.build-runner";
|
|
10
9
|
import { SdCliConvertMessageUtils } from "../utils/sd-cli-convert-message.utils";
|
|
11
10
|
import { ISdProjectConfig, TSdPackageConfig } from "../types/config.types";
|
|
@@ -22,13 +21,9 @@ export class SdCliProject {
|
|
|
22
21
|
const logger = SdLogger.get(["simplysm", "sd-cli", "SdCliProject", "watchAsync"]);
|
|
23
22
|
|
|
24
23
|
logger.debug("프로젝트 설정 가져오기...");
|
|
25
|
-
const projConf = (
|
|
26
|
-
process.cwd(),
|
|
27
|
-
|
|
28
|
-
)).href)).default(
|
|
29
|
-
true,
|
|
30
|
-
opt.optNames,
|
|
31
|
-
) as ISdProjectConfig;
|
|
24
|
+
const projConf = (
|
|
25
|
+
await import(pathToFileURL(path.resolve(process.cwd(), opt.confFileRelPath)).href)
|
|
26
|
+
).default(true, opt.optNames) as ISdProjectConfig;
|
|
32
27
|
|
|
33
28
|
if (projConf.localUpdates) {
|
|
34
29
|
logger.debug("로컬 라이브러리 업데이트 변경감지 시작...");
|
|
@@ -111,7 +106,7 @@ export class SdCliProject {
|
|
|
111
106
|
}
|
|
112
107
|
|
|
113
108
|
logger.debug("프로젝트 및 패키지 버전 설정...");
|
|
114
|
-
|
|
109
|
+
this._upgradeVersion(projNpmConf, allPkgPaths);
|
|
115
110
|
|
|
116
111
|
logger.debug("빌드 프로세스 시작...");
|
|
117
112
|
const multiBuildRunner = new SdMultiBuildRunner();
|
|
@@ -176,7 +171,7 @@ export class SdCliProject {
|
|
|
176
171
|
|
|
177
172
|
if (!opt.noBuild) {
|
|
178
173
|
logger.debug("프로젝트 및 패키지 버전 설정...");
|
|
179
|
-
|
|
174
|
+
this._upgradeVersion(projNpmConf, allPkgPaths);
|
|
180
175
|
|
|
181
176
|
// 빌드
|
|
182
177
|
try {
|
|
@@ -312,10 +307,7 @@ export class SdCliProject {
|
|
|
312
307
|
process.stdout.clearLine(0);
|
|
313
308
|
}
|
|
314
309
|
|
|
315
|
-
private static
|
|
316
|
-
projNpmConf: INpmConfig,
|
|
317
|
-
allPkgPaths: string[],
|
|
318
|
-
): Promise<void> {
|
|
310
|
+
private static _upgradeVersion(projNpmConf: INpmConfig, allPkgPaths: string[]) {
|
|
319
311
|
// 작업공간 package.json 버전 설정
|
|
320
312
|
const newVersion = semver.inc(projNpmConf.version, "patch")!;
|
|
321
313
|
projNpmConf.version = newVersion;
|
|
@@ -342,7 +334,7 @@ export class SdCliProject {
|
|
|
342
334
|
FsUtils.writeJson(projNpmConfFilePath, projNpmConf, { space: 2 });
|
|
343
335
|
|
|
344
336
|
// 각 패키지 package.json 버전 설정
|
|
345
|
-
|
|
337
|
+
for (const pkgPath of allPkgPaths) {
|
|
346
338
|
const pkgNpmConfFilePath = path.resolve(pkgPath, "package.json");
|
|
347
339
|
const pkgNpmConf = FsUtils.readJson(pkgNpmConfFilePath);
|
|
348
340
|
pkgNpmConf.version = newVersion;
|
|
@@ -356,16 +348,12 @@ export class SdCliProject {
|
|
|
356
348
|
|
|
357
349
|
if (FsUtils.exists(path.resolve(pkgPath, "plugin.xml"))) {
|
|
358
350
|
const cordovaPluginConfFilePath = path.resolve(pkgPath, "plugin.xml");
|
|
359
|
-
const cordovaPluginConfXml =
|
|
360
|
-
cordovaPluginConfFilePath));
|
|
351
|
+
const cordovaPluginConfXml = XmlConvert.parse(FsUtils.readFile(cordovaPluginConfFilePath));
|
|
361
352
|
cordovaPluginConfXml.plugin.$.version = newVersion;
|
|
362
353
|
|
|
363
|
-
FsUtils.writeFile(
|
|
364
|
-
cordovaPluginConfFilePath,
|
|
365
|
-
new xml2js.Builder().buildObject(cordovaPluginConfXml),
|
|
366
|
-
);
|
|
354
|
+
FsUtils.writeFile(cordovaPluginConfFilePath, XmlConvert.stringify(cordovaPluginConfXml));
|
|
367
355
|
}
|
|
368
|
-
}
|
|
356
|
+
}
|
|
369
357
|
}
|
|
370
358
|
|
|
371
359
|
static #logging(buildResults: ISdBuildMessage[], logger: SdLogger): void {
|
package/src/index.ts
CHANGED
|
@@ -20,6 +20,7 @@ export * from "./pkg-builders/server/sd-server.bundler";
|
|
|
20
20
|
export * from "./pkg-builders/server/sd-server.plugin-creator";
|
|
21
21
|
import "./sd-cli";
|
|
22
22
|
export * from "./ts-compiler/sd-ts-compiler";
|
|
23
|
+
export * from "./ts-compiler/sd-ts-dependency-analyzer";
|
|
23
24
|
export * from "./types/build-plugin.types";
|
|
24
25
|
export * from "./types/build-runner.types";
|
|
25
26
|
export * from "./types/build.types";
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import path from "path";
|
|
2
2
|
import esbuild, { Metafile } from "esbuild";
|
|
3
|
-
import { FsUtils, PathUtils, SdLogger, TNormPath } from "@simplysm/sd-core-node";
|
|
3
|
+
import { FsUtils, HashUtils, PathUtils, SdLogger, TNormPath } from "@simplysm/sd-core-node";
|
|
4
4
|
import { fileURLToPath } from "url";
|
|
5
5
|
import nodeStdLibBrowser from "node-stdlib-browser";
|
|
6
6
|
import nodeStdLibBrowserPlugin from "node-stdlib-browser/helpers/esbuild/plugin";
|
|
@@ -47,27 +47,27 @@ import { ISdBuildMessage } from "../../types/build.types";
|
|
|
47
47
|
import nodeModule from "node:module";
|
|
48
48
|
|
|
49
49
|
export class SdNgBundler {
|
|
50
|
-
readonly
|
|
50
|
+
private readonly _logger = SdLogger.get(["simplysm", "sd-cli", "SdNgBundler"]);
|
|
51
51
|
|
|
52
|
-
readonly
|
|
53
|
-
readonly
|
|
52
|
+
private readonly _modifiedFileSet = new Set<TNormPath>();
|
|
53
|
+
private readonly _ngResultCache: ISdCliNgPluginResultCache = {
|
|
54
54
|
affectedFileSet: new Set<TNormPath>(),
|
|
55
55
|
watchFileSet: new Set<TNormPath>(),
|
|
56
56
|
};
|
|
57
|
-
readonly
|
|
57
|
+
private readonly _styleLoadResultCache = new MemoryLoadResultCache();
|
|
58
58
|
|
|
59
|
-
|
|
59
|
+
private _contexts: SdNgBundlerContext[] | undefined;
|
|
60
60
|
|
|
61
|
-
readonly
|
|
61
|
+
private readonly _outputHashCache = new Map<TNormPath, string>();
|
|
62
62
|
|
|
63
|
-
readonly
|
|
64
|
-
readonly
|
|
65
|
-
readonly
|
|
66
|
-
readonly
|
|
67
|
-
readonly
|
|
68
|
-
readonly
|
|
69
|
-
readonly
|
|
70
|
-
readonly
|
|
63
|
+
private readonly _pkgNpmConf: INpmConfig;
|
|
64
|
+
private readonly _mainFilePath: string;
|
|
65
|
+
private readonly _tsConfigFilePath: string;
|
|
66
|
+
private readonly _swConfFilePath: string;
|
|
67
|
+
private readonly _browserTarget: string[];
|
|
68
|
+
private readonly _indexHtmlFilePath: string;
|
|
69
|
+
private readonly _pkgName: string;
|
|
70
|
+
private readonly _baseHref: string;
|
|
71
71
|
|
|
72
72
|
public constructor(
|
|
73
73
|
private _opt: {
|
|
@@ -81,25 +81,25 @@ export class SdNgBundler {
|
|
|
81
81
|
watchScopePaths: TNormPath[];
|
|
82
82
|
},
|
|
83
83
|
) {
|
|
84
|
-
this
|
|
85
|
-
this
|
|
86
|
-
this
|
|
87
|
-
this
|
|
88
|
-
this
|
|
89
|
-
this
|
|
90
|
-
this
|
|
91
|
-
this
|
|
84
|
+
this._pkgNpmConf = FsUtils.readJson(path.resolve(this._opt.pkgPath, "package.json"));
|
|
85
|
+
this._mainFilePath = path.resolve(this._opt.pkgPath, "src/main.ts");
|
|
86
|
+
this._tsConfigFilePath = path.resolve(this._opt.pkgPath, "tsconfig.json");
|
|
87
|
+
this._swConfFilePath = path.resolve(this._opt.pkgPath, "ngsw-config.json");
|
|
88
|
+
this._browserTarget = transformSupportedBrowsersToTargets(browserslist(["Chrome > 78"]));
|
|
89
|
+
this._indexHtmlFilePath = path.resolve(this._opt.pkgPath, "src/index.html");
|
|
90
|
+
this._pkgName = path.basename(this._opt.pkgPath);
|
|
91
|
+
this._baseHref =
|
|
92
92
|
this._opt.builderType === "web"
|
|
93
|
-
? `/${this
|
|
93
|
+
? `/${this._pkgName}/`
|
|
94
94
|
: this._opt.dev
|
|
95
|
-
? `/${this
|
|
95
|
+
? `/${this._pkgName}/${this._opt.builderType}/`
|
|
96
96
|
: ``;
|
|
97
97
|
}
|
|
98
98
|
|
|
99
99
|
public markForChanges(filePaths: string[]): void {
|
|
100
100
|
for (const filePath of filePaths) {
|
|
101
|
-
this
|
|
102
|
-
this
|
|
101
|
+
this._modifiedFileSet.add(PathUtils.norm(filePath));
|
|
102
|
+
this._styleLoadResultCache.invalidate(PathUtils.norm(filePath));
|
|
103
103
|
}
|
|
104
104
|
// this._sourceFileCache.invalidate(filePaths);
|
|
105
105
|
}
|
|
@@ -112,10 +112,10 @@ export class SdNgBundler {
|
|
|
112
112
|
}> {
|
|
113
113
|
const perf = new SdCliPerformanceTimer("ng bundle");
|
|
114
114
|
|
|
115
|
-
this
|
|
115
|
+
this._debug(`get contexts...`);
|
|
116
116
|
|
|
117
|
-
if (!this
|
|
118
|
-
this
|
|
117
|
+
if (!this._contexts) {
|
|
118
|
+
this._contexts = perf.run("get contexts", () => [
|
|
119
119
|
this._getAppContext(),
|
|
120
120
|
...FsUtils.exists(path.resolve(this._opt.pkgPath, "src/styles.scss")) ? [
|
|
121
121
|
this._getStyleContext(),
|
|
@@ -124,16 +124,16 @@ export class SdNgBundler {
|
|
|
124
124
|
]);
|
|
125
125
|
}
|
|
126
126
|
|
|
127
|
-
this
|
|
127
|
+
this._debug(`build...`);
|
|
128
128
|
|
|
129
129
|
const bundlingResults = await perf.run("build", async () => {
|
|
130
|
-
return await this
|
|
130
|
+
return await this._contexts!.mapAsync(async (ctx) => await ctx.bundleAsync());
|
|
131
131
|
});
|
|
132
132
|
|
|
133
133
|
//-- results
|
|
134
134
|
const results = bundlingResults.mapMany((bundlingResult) => bundlingResult.results);
|
|
135
135
|
|
|
136
|
-
this
|
|
136
|
+
this._debug(`convert result...`);
|
|
137
137
|
|
|
138
138
|
const outputFiles: BuildOutputFile[] = bundlingResults.mapMany(
|
|
139
139
|
(item) => item.outputFiles?.map((file) => convertOutputFile(file, BuildOutputFileType.Root))
|
|
@@ -159,7 +159,7 @@ export class SdNgBundler {
|
|
|
159
159
|
outputFiles.push(createOutputFile("cordova-empty.js", "export default {};", BuildOutputFileType.Root));
|
|
160
160
|
}*/
|
|
161
161
|
|
|
162
|
-
this
|
|
162
|
+
this._debug(`create index.html...`);
|
|
163
163
|
await perf.run("create index.html", async () => {
|
|
164
164
|
const genIndexHtmlResult = await this._genIndexHtmlAsync(outputFiles, initialFiles);
|
|
165
165
|
for (const warning of genIndexHtmlResult.warnings) {
|
|
@@ -208,8 +208,8 @@ export class SdNgBundler {
|
|
|
208
208
|
});
|
|
209
209
|
|
|
210
210
|
//-- service worker
|
|
211
|
-
if (FsUtils.exists(this
|
|
212
|
-
this
|
|
211
|
+
if (FsUtils.exists(this._swConfFilePath)) {
|
|
212
|
+
this._debug(`prepare service worker...`);
|
|
213
213
|
|
|
214
214
|
await perf.run("prepare service worker", async () => {
|
|
215
215
|
try {
|
|
@@ -236,40 +236,41 @@ export class SdNgBundler {
|
|
|
236
236
|
}
|
|
237
237
|
|
|
238
238
|
//-- write
|
|
239
|
-
this
|
|
239
|
+
this._debug(`write output files...(${outputFiles.length})`);
|
|
240
240
|
|
|
241
241
|
const emitFileSet = new Set<TNormPath>();
|
|
242
242
|
perf.run("write output file", () => {
|
|
243
243
|
for (const outputFile of outputFiles) {
|
|
244
244
|
const distFilePath = PathUtils.norm(this._opt.outputPath, outputFile.path);
|
|
245
|
-
const
|
|
246
|
-
|
|
245
|
+
const prevHash = this._outputHashCache.get(distFilePath);
|
|
246
|
+
const currHash = HashUtils.get(outputFile.contents);
|
|
247
|
+
if (prevHash !== currHash) {
|
|
247
248
|
FsUtils.writeFile(distFilePath, outputFile.contents);
|
|
248
|
-
this
|
|
249
|
+
this._outputHashCache.set(distFilePath, currHash);
|
|
249
250
|
emitFileSet.add(PathUtils.norm(outputFile.path));
|
|
250
251
|
}
|
|
251
252
|
}
|
|
252
253
|
for (const assetFile of assetFiles) {
|
|
253
|
-
const
|
|
254
|
-
const
|
|
255
|
-
if (
|
|
254
|
+
const prevHash = this._outputHashCache.get(PathUtils.norm(assetFile.source));
|
|
255
|
+
const currHash = FsUtils.hash(assetFile.source);
|
|
256
|
+
if (prevHash !== currHash) {
|
|
256
257
|
FsUtils.copy(assetFile.source, path.resolve(this._opt.outputPath, assetFile.destination));
|
|
257
|
-
this
|
|
258
|
+
this._outputHashCache.set(PathUtils.norm(assetFile.source), currHash);
|
|
258
259
|
emitFileSet.add(PathUtils.norm(assetFile.destination));
|
|
259
260
|
}
|
|
260
261
|
}
|
|
261
262
|
});
|
|
262
263
|
|
|
263
|
-
this
|
|
264
|
+
this._debug(perf.toString());
|
|
264
265
|
|
|
265
266
|
return {
|
|
266
267
|
watchFileSet: new Set([
|
|
267
|
-
...this
|
|
268
|
-
...this
|
|
268
|
+
...this._ngResultCache.watchFileSet!,
|
|
269
|
+
...this._styleLoadResultCache.watchFiles.map((item) => PathUtils.norm(item)),
|
|
269
270
|
...assetFiles.map((item) => PathUtils.norm(item.source)),
|
|
270
|
-
PathUtils.norm(this
|
|
271
|
+
PathUtils.norm(this._indexHtmlFilePath),
|
|
271
272
|
]),
|
|
272
|
-
affectedFileSet: this
|
|
273
|
+
affectedFileSet: this._ngResultCache.affectedFileSet!,
|
|
273
274
|
results,
|
|
274
275
|
emitFileSet: emitFileSet,
|
|
275
276
|
};
|
|
@@ -290,7 +291,7 @@ export class SdNgBundler {
|
|
|
290
291
|
};
|
|
291
292
|
|
|
292
293
|
const indexHtmlGenerator = new IndexHtmlGenerator({
|
|
293
|
-
indexPath: this
|
|
294
|
+
indexPath: this._indexHtmlFilePath,
|
|
294
295
|
entrypoints: [
|
|
295
296
|
["polyfills", true],
|
|
296
297
|
["styles", false],
|
|
@@ -335,7 +336,7 @@ export class SdNgBundler {
|
|
|
335
336
|
}
|
|
336
337
|
|
|
337
338
|
return await indexHtmlGenerator.process({
|
|
338
|
-
baseHref: this
|
|
339
|
+
baseHref: this._baseHref,
|
|
339
340
|
lang: undefined,
|
|
340
341
|
outputPath: "/",
|
|
341
342
|
files: [...initialFiles].map(([file, record]) => ({
|
|
@@ -402,8 +403,8 @@ export class SdNgBundler {
|
|
|
402
403
|
}> {
|
|
403
404
|
return await augmentAppWithServiceWorkerEsbuild(
|
|
404
405
|
this._opt.pkgPath,
|
|
405
|
-
this
|
|
406
|
-
this
|
|
406
|
+
this._swConfFilePath,
|
|
407
|
+
this._baseHref,
|
|
407
408
|
"index.html",
|
|
408
409
|
outputFiles,
|
|
409
410
|
assetFiles,
|
|
@@ -434,7 +435,7 @@ export class SdNgBundler {
|
|
|
434
435
|
outExtension: undefined,
|
|
435
436
|
sourcemap: this._opt.dev,
|
|
436
437
|
chunkNames: "[name]-[hash]",
|
|
437
|
-
tsconfig: this
|
|
438
|
+
tsconfig: this._tsConfigFilePath,
|
|
438
439
|
write: false,
|
|
439
440
|
preserveSymlinks: false,
|
|
440
441
|
define: {
|
|
@@ -443,7 +444,7 @@ export class SdNgBundler {
|
|
|
443
444
|
"global": "global",
|
|
444
445
|
"process": "process",
|
|
445
446
|
"Buffer": "Buffer",
|
|
446
|
-
"process.env.SD_VERSION": JSON.stringify(this
|
|
447
|
+
"process.env.SD_VERSION": JSON.stringify(this._pkgNpmConf.version),
|
|
447
448
|
"process.env.NODE_ENV": JSON.stringify(this._opt.dev ? "development" : "production"),
|
|
448
449
|
...(this._opt.env
|
|
449
450
|
? Object.keys(this._opt.env).toObject(
|
|
@@ -455,8 +456,7 @@ export class SdNgBundler {
|
|
|
455
456
|
mainFields: ["es2020", "es2015", "browser", "module", "main"],
|
|
456
457
|
entryNames: "[dir]/[name]",
|
|
457
458
|
entryPoints: {
|
|
458
|
-
main: this
|
|
459
|
-
// TODO: Polyfills Bundler 분리
|
|
459
|
+
main: this._mainFilePath,
|
|
460
460
|
...FsUtils.exists(path.resolve(this._opt.pkgPath, "src/polyfills.ts")) ? {
|
|
461
461
|
polyfills: path.resolve(this._opt.pkgPath, "src/polyfills.ts"),
|
|
462
462
|
} : {},
|
|
@@ -469,8 +469,6 @@ export class SdNgBundler {
|
|
|
469
469
|
),
|
|
470
470
|
}
|
|
471
471
|
: {}),
|
|
472
|
-
|
|
473
|
-
// TODO: Workers Bundler 분리
|
|
474
472
|
...workerEntries,
|
|
475
473
|
},
|
|
476
474
|
supported: { "async-await": false, "object-rest-spread": false },
|
|
@@ -509,7 +507,7 @@ export class SdNgBundler {
|
|
|
509
507
|
}
|
|
510
508
|
: {
|
|
511
509
|
platform: "browser",
|
|
512
|
-
target: this
|
|
510
|
+
target: this._browserTarget,
|
|
513
511
|
format: "esm",
|
|
514
512
|
splitting: true,
|
|
515
513
|
inject: [
|
|
@@ -520,10 +518,10 @@ export class SdNgBundler {
|
|
|
520
518
|
plugins: [
|
|
521
519
|
createSourcemapIgnorelistPlugin(),
|
|
522
520
|
createSdNgPlugin({
|
|
523
|
-
modifiedFileSet: this
|
|
521
|
+
modifiedFileSet: this._modifiedFileSet,
|
|
524
522
|
dev: this._opt.dev,
|
|
525
523
|
pkgPath: this._opt.pkgPath,
|
|
526
|
-
result: this
|
|
524
|
+
result: this._ngResultCache,
|
|
527
525
|
watchScopePaths: this._opt.watchScopePaths,
|
|
528
526
|
}),
|
|
529
527
|
...(this._opt.builderType === "electron"
|
|
@@ -550,7 +548,7 @@ export class SdNgBundler {
|
|
|
550
548
|
sourcemap: this._opt.dev,
|
|
551
549
|
includePaths: [],
|
|
552
550
|
},
|
|
553
|
-
this
|
|
551
|
+
this._styleLoadResultCache,
|
|
554
552
|
);
|
|
555
553
|
|
|
556
554
|
return new SdNgBundlerContext(this._opt.pkgPath, {
|
|
@@ -565,7 +563,7 @@ export class SdNgBundler {
|
|
|
565
563
|
outdir: this._opt.pkgPath,
|
|
566
564
|
write: false,
|
|
567
565
|
platform: "browser",
|
|
568
|
-
target: this
|
|
566
|
+
target: this._browserTarget,
|
|
569
567
|
preserveSymlinks: false,
|
|
570
568
|
external: [],
|
|
571
569
|
conditions: ["style", "sass"],
|
|
@@ -577,7 +575,7 @@ export class SdNgBundler {
|
|
|
577
575
|
plugins: [
|
|
578
576
|
pluginFactory.create(SassStylesheetLanguage),
|
|
579
577
|
pluginFactory.create(CssStylesheetLanguage),
|
|
580
|
-
createCssResourcePlugin(this
|
|
578
|
+
createCssResourcePlugin(this._styleLoadResultCache),
|
|
581
579
|
],
|
|
582
580
|
});
|
|
583
581
|
}
|
|
@@ -596,13 +594,13 @@ export class SdNgBundler {
|
|
|
596
594
|
minify: !this._opt.dev,
|
|
597
595
|
outdir: this._opt.pkgPath,
|
|
598
596
|
sourcemap: this._opt.dev,
|
|
599
|
-
tsconfig: this
|
|
597
|
+
tsconfig: this._tsConfigFilePath,
|
|
600
598
|
write: false,
|
|
601
599
|
preserveSymlinks: false,
|
|
602
600
|
external: ["electron"],
|
|
603
601
|
define: {
|
|
604
602
|
...(!this._opt.dev ? { ngDevMode: "false" } : {}),
|
|
605
|
-
"process.env.SD_VERSION": JSON.stringify(this
|
|
603
|
+
"process.env.SD_VERSION": JSON.stringify(this._pkgNpmConf.version),
|
|
606
604
|
"process.env.NODE_ENV": JSON.stringify(this._opt.dev ? "development" : "production"),
|
|
607
605
|
...(this._opt.env
|
|
608
606
|
? Object.keys(this._opt.env).toObject(
|
|
@@ -618,7 +616,7 @@ export class SdNgBundler {
|
|
|
618
616
|
});
|
|
619
617
|
}
|
|
620
618
|
|
|
621
|
-
|
|
622
|
-
this
|
|
619
|
+
private _debug(...msg: any[]): void {
|
|
620
|
+
this._logger.debug(`[${path.basename(this._opt.pkgPath)}]`, ...msg);
|
|
623
621
|
}
|
|
624
622
|
}
|
|
@@ -2,7 +2,7 @@ import esbuild from "esbuild";
|
|
|
2
2
|
import path from "path";
|
|
3
3
|
import os from "os";
|
|
4
4
|
import { JavaScriptTransformer } from "@angular/build/src/tools/esbuild/javascript-transformer";
|
|
5
|
-
import {
|
|
5
|
+
import { PathUtils, SdLogger, TNormPath } from "@simplysm/sd-core-node";
|
|
6
6
|
import { SdCliPerformanceTimer } from "../../utils/sd-cli-performance-time";
|
|
7
7
|
import { SdCliConvertMessageUtils } from "../../utils/sd-cli-convert-message.utils";
|
|
8
8
|
import { ISdCliNgPluginResultCache } from "../../types/build-plugin.types";
|
|
@@ -16,7 +16,7 @@ export function createSdNgPlugin(conf: {
|
|
|
16
16
|
result: ISdCliNgPluginResultCache;
|
|
17
17
|
watchScopePaths: TNormPath[];
|
|
18
18
|
}): esbuild.Plugin {
|
|
19
|
-
let webWorkerResultMap = new Map<
|
|
19
|
+
/*let webWorkerResultMap = new Map<
|
|
20
20
|
TNormPath,
|
|
21
21
|
{
|
|
22
22
|
outputFiles: esbuild.OutputFile[];
|
|
@@ -24,7 +24,7 @@ export function createSdNgPlugin(conf: {
|
|
|
24
24
|
errors?: esbuild.Message[];
|
|
25
25
|
warnings?: esbuild.Message[];
|
|
26
26
|
}
|
|
27
|
-
>()
|
|
27
|
+
>();*/
|
|
28
28
|
|
|
29
29
|
// let workerRevDepMap = new Map<TNormPath, Set<TNormPath>>();
|
|
30
30
|
|
|
@@ -147,18 +147,18 @@ export function createSdNgPlugin(conf: {
|
|
|
147
147
|
...Array.from(tsCompileResult.stylesheetBundlingResultMap.values())
|
|
148
148
|
.flatMap((item) => item.errors)
|
|
149
149
|
.filterExists(),
|
|
150
|
-
|
|
150
|
+
/*...Array.from(webWorkerResultMap.values())
|
|
151
151
|
.flatMap((item) => item.errors)
|
|
152
|
-
.filterExists()
|
|
152
|
+
.filterExists(),*/
|
|
153
153
|
].filterExists(),
|
|
154
154
|
warnings: [
|
|
155
155
|
...tsEsbuildResult.warnings,
|
|
156
156
|
...Array.from(tsCompileResult.stylesheetBundlingResultMap.values())
|
|
157
157
|
.flatMap((item) => item.warnings)
|
|
158
158
|
.filterExists(),
|
|
159
|
-
|
|
159
|
+
/*...Array.from(webWorkerResultMap.values())
|
|
160
160
|
.flatMap((item) => item.warnings)
|
|
161
|
-
.filterExists()
|
|
161
|
+
.filterExists(),*/
|
|
162
162
|
],
|
|
163
163
|
};
|
|
164
164
|
});
|
|
@@ -173,7 +173,8 @@ export function createSdNgPlugin(conf: {
|
|
|
173
173
|
return { contents: output, loader: "js" };
|
|
174
174
|
}
|
|
175
175
|
|
|
176
|
-
const emittedJsFile = tsCompileResult.emittedFilesCacheMap.get(PathUtils.norm(args.path))
|
|
176
|
+
const emittedJsFile = tsCompileResult.emittedFilesCacheMap.get(PathUtils.norm(args.path))
|
|
177
|
+
?.last();
|
|
177
178
|
if (!emittedJsFile) {
|
|
178
179
|
return {
|
|
179
180
|
errors: [
|
|
@@ -191,7 +192,12 @@ export function createSdNgPlugin(conf: {
|
|
|
191
192
|
resolveDir: build.initialOptions.absWorkingDir ?? "",
|
|
192
193
|
});
|
|
193
194
|
|
|
194
|
-
const newContents = await javascriptTransformer.transformData(
|
|
195
|
+
const newContents = await javascriptTransformer.transformData(
|
|
196
|
+
args.path,
|
|
197
|
+
contents,
|
|
198
|
+
true,
|
|
199
|
+
sideEffects,
|
|
200
|
+
);
|
|
195
201
|
|
|
196
202
|
outputContentsCacheMap.set(PathUtils.norm(args.path), newContents);
|
|
197
203
|
|
|
@@ -211,24 +217,36 @@ export function createSdNgPlugin(conf: {
|
|
|
211
217
|
resolveDir: build.initialOptions.absWorkingDir ?? "",
|
|
212
218
|
});
|
|
213
219
|
|
|
214
|
-
|
|
220
|
+
try {
|
|
221
|
+
const newContents = await javascriptTransformer.transformFile(
|
|
222
|
+
args.path,
|
|
223
|
+
false,
|
|
224
|
+
sideEffects,
|
|
225
|
+
);
|
|
215
226
|
|
|
216
|
-
|
|
227
|
+
outputContentsCacheMap.set(PathUtils.norm(args.path), newContents);
|
|
217
228
|
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
229
|
+
return {
|
|
230
|
+
contents: newContents,
|
|
231
|
+
loader: "js",
|
|
232
|
+
};
|
|
233
|
+
}
|
|
234
|
+
catch (err) {
|
|
235
|
+
return {
|
|
236
|
+
contents: `console.error(${JSON.stringify(err.message)});`,
|
|
237
|
+
loader: "js",
|
|
238
|
+
};
|
|
239
|
+
}
|
|
222
240
|
});
|
|
223
241
|
|
|
224
242
|
build.onLoad(
|
|
225
243
|
{
|
|
226
244
|
filter: new RegExp(
|
|
227
245
|
"(" +
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
246
|
+
Object.keys(build.initialOptions.loader!)
|
|
247
|
+
.map((item) => "\\" + item)
|
|
248
|
+
.join("|") +
|
|
249
|
+
")$",
|
|
232
250
|
),
|
|
233
251
|
},
|
|
234
252
|
(args) => {
|
|
@@ -241,17 +259,19 @@ export function createSdNgPlugin(conf: {
|
|
|
241
259
|
perf.end("transform & bundling");
|
|
242
260
|
debug(perf.toString());
|
|
243
261
|
|
|
244
|
-
for (const
|
|
245
|
-
|
|
246
|
-
|
|
262
|
+
for (const stylesheetBundlingResult of tsCompileResult.stylesheetBundlingResultMap.values()) {
|
|
263
|
+
if ("outputFiles" in stylesheetBundlingResult) {
|
|
264
|
+
result.outputFiles ??= [];
|
|
265
|
+
result.outputFiles.push(...stylesheetBundlingResult.outputFiles);
|
|
247
266
|
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
267
|
+
if (result.metafile) {
|
|
268
|
+
result.metafile.inputs = { ...result.metafile.inputs, ...stylesheetBundlingResult.metafile.inputs };
|
|
269
|
+
result.metafile.outputs = { ...result.metafile.outputs, ...stylesheetBundlingResult.metafile.outputs };
|
|
270
|
+
}
|
|
251
271
|
}
|
|
252
272
|
}
|
|
253
273
|
|
|
254
|
-
for (const { outputFiles, metafile } of webWorkerResultMap.values()) {
|
|
274
|
+
/*for (const { outputFiles, metafile } of webWorkerResultMap.values()) {
|
|
255
275
|
result.outputFiles ??= [];
|
|
256
276
|
result.outputFiles.push(...outputFiles);
|
|
257
277
|
|
|
@@ -259,7 +279,7 @@ export function createSdNgPlugin(conf: {
|
|
|
259
279
|
result.metafile.inputs = { ...result.metafile.inputs, ...metafile.inputs };
|
|
260
280
|
result.metafile.outputs = { ...result.metafile.outputs, ...metafile.outputs };
|
|
261
281
|
}
|
|
262
|
-
}
|
|
282
|
+
}*/
|
|
263
283
|
|
|
264
284
|
conf.result.outputFiles = result.outputFiles;
|
|
265
285
|
conf.result.metafile = result.metafile;
|
|
@@ -42,10 +42,16 @@ export class SdTsLibBuilder {
|
|
|
42
42
|
}
|
|
43
43
|
}
|
|
44
44
|
|
|
45
|
-
const globalStylesheetBundlingResult = tsCompileResult
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
45
|
+
const globalStylesheetBundlingResult = tsCompileResult
|
|
46
|
+
.stylesheetBundlingResultMap
|
|
47
|
+
.get(emitFile);
|
|
48
|
+
if (globalStylesheetBundlingResult && "outputFiles" in globalStylesheetBundlingResult) {
|
|
49
|
+
for (const outputFile of globalStylesheetBundlingResult.outputFiles) {
|
|
50
|
+
const distPath = PathUtils.norm(
|
|
51
|
+
this._pkgPath,
|
|
52
|
+
"dist",
|
|
53
|
+
path.relative(this._pkgPath, outputFile.path),
|
|
54
|
+
);
|
|
49
55
|
if (PathUtils.isChildPath(distPath, path.resolve(this._pkgPath, "dist"))) {
|
|
50
56
|
FsUtils.writeFile(distPath, outputFile.text);
|
|
51
57
|
emitFileSet.add(distPath);
|
|
@@ -54,9 +60,10 @@ export class SdTsLibBuilder {
|
|
|
54
60
|
}
|
|
55
61
|
}
|
|
56
62
|
|
|
57
|
-
const styleResults = Array.from(tsCompileResult.stylesheetBundlingResultMap.values())
|
|
58
|
-
|
|
59
|
-
|
|
63
|
+
const styleResults = Array.from(tsCompileResult.stylesheetBundlingResultMap.values())
|
|
64
|
+
.mapMany((item) =>
|
|
65
|
+
SdCliConvertMessageUtils.convertToBuildMessagesFromEsbuild(item, this._pkgPath),
|
|
66
|
+
);
|
|
60
67
|
|
|
61
68
|
return {
|
|
62
69
|
watchFileSet: tsCompileResult.watchFileSet,
|