@simplysm/sd-cli 10.0.66 → 11.0.4
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/build-cluster.js +16 -15
- package/dist/build-cluster.js.map +1 -1
- package/dist/build-tools/SdNgBundler.d.ts +20 -0
- package/dist/build-tools/SdNgBundler.js +312 -0
- package/dist/build-tools/SdNgBundler.js.map +1 -0
- package/dist/build-tools/SdTsBundler.d.ts +15 -0
- package/dist/build-tools/SdTsBundler.js +96 -0
- package/dist/build-tools/SdTsBundler.js.map +1 -0
- package/dist/build-tools/SdTsCompiler.d.ts +28 -0
- package/dist/build-tools/SdTsCompiler.js +212 -0
- package/dist/build-tools/SdTsCompiler.js.map +1 -0
- package/dist/builders/SdCliClientBuilder.d.ts +5 -7
- package/dist/builders/SdCliClientBuilder.js +75 -267
- package/dist/builders/SdCliClientBuilder.js.map +1 -1
- package/dist/builders/SdCliServerBuilder.d.ts +4 -3
- package/dist/builders/SdCliServerBuilder.js +82 -218
- package/dist/builders/SdCliServerBuilder.js.map +1 -1
- package/dist/builders/SdCliTsLibBuilder.d.ts +3 -4
- package/dist/builders/SdCliTsLibBuilder.js +37 -87
- package/dist/builders/SdCliTsLibBuilder.js.map +1 -1
- package/dist/commons.d.ts +11 -5
- package/dist/entry/SdCliProject.js +22 -18
- package/dist/entry/SdCliProject.js.map +1 -1
- package/dist/index.d.ts +3 -11
- package/dist/index.js +3 -11
- package/dist/index.js.map +1 -1
- package/dist/sd-cli.js +0 -19
- package/dist/sd-cli.js.map +1 -1
- package/dist/server-worker.js +3 -0
- package/dist/server-worker.js.map +1 -1
- package/package.json +17 -19
- package/src/build-cluster.ts +16 -15
- package/src/build-tools/SdNgBundler.ts +381 -0
- package/src/build-tools/SdTsBundler.ts +106 -0
- package/src/build-tools/SdTsCompiler.ts +304 -0
- package/src/builders/SdCliClientBuilder.ts +93 -312
- package/src/builders/SdCliServerBuilder.ts +99 -242
- package/src/builders/SdCliTsLibBuilder.ts +41 -111
- package/src/commons.ts +11 -5
- package/src/entry/SdCliElectron.ts +3 -3
- package/src/entry/SdCliLocalUpdate.ts +3 -3
- package/src/entry/SdCliProject.ts +33 -26
- package/src/index.ts +3 -11
- package/src/sd-cli.ts +0 -23
- package/src/server-worker.ts +3 -0
- package/dist/build-tools/SdTsIncrementalBuilder.d.ts +0 -29
- package/dist/build-tools/SdTsIncrementalBuilder.js +0 -75
- package/dist/build-tools/SdTsIncrementalBuilder.js.map +0 -1
- package/dist/entry/SdCliPwaAssets.d.ts +0 -6
- package/dist/entry/SdCliPwaAssets.js +0 -39
- package/dist/entry/SdCliPwaAssets.js.map +0 -1
- package/dist/utils/SdCliViteElectronMainPlugin.d.ts +0 -6
- package/dist/utils/SdCliViteElectronMainPlugin.js +0 -96
- package/dist/utils/SdCliViteElectronMainPlugin.js.map +0 -1
- package/dist/utils/SdCliViteExternalPlugin.d.ts +0 -6
- package/dist/utils/SdCliViteExternalPlugin.js +0 -85
- package/dist/utils/SdCliViteExternalPlugin.js.map +0 -1
- package/dist/utils/SdCliViteLazyImportPlugin.d.ts +0 -2
- package/dist/utils/SdCliViteLazyImportPlugin.js +0 -23
- package/dist/utils/SdCliViteLazyImportPlugin.js.map +0 -1
- package/dist/utils/SdCliViteLoggerPlugin.d.ts +0 -6
- package/dist/utils/SdCliViteLoggerPlugin.js +0 -24
- package/dist/utils/SdCliViteLoggerPlugin.js.map +0 -1
- package/dist/utils/SdCliViteNodeGlobalPlugin.d.ts +0 -2
- package/dist/utils/SdCliViteNodeGlobalPlugin.js +0 -29
- package/dist/utils/SdCliViteNodeGlobalPlugin.js.map +0 -1
- package/dist/utils/SdCliViteReactSwcPlugin.d.ts +0 -2
- package/dist/utils/SdCliViteReactSwcPlugin.js +0 -139
- package/dist/utils/SdCliViteReactSwcPlugin.js.map +0 -1
- package/dist/utils/SdCliViteServeOptimizeExcludePlugin.d.ts +0 -2
- package/dist/utils/SdCliViteServeOptimizeExcludePlugin.js +0 -36
- package/dist/utils/SdCliViteServeOptimizeExcludePlugin.js.map +0 -1
- package/dist/utils/getElectronReactExternals.d.ts +0 -1
- package/dist/utils/getElectronReactExternals.js +0 -17
- package/dist/utils/getElectronReactExternals.js.map +0 -1
- package/dist/utils/sdCliTsDefineTransformer.d.ts +0 -4
- package/dist/utils/sdCliTsDefineTransformer.js +0 -26
- package/dist/utils/sdCliTsDefineTransformer.js.map +0 -1
- package/src/build-tools/SdTsIncrementalBuilder.ts +0 -125
- package/src/entry/SdCliPwaAssets.ts +0 -50
- package/src/utils/SdCliViteElectronMainPlugin.ts +0 -102
- package/src/utils/SdCliViteExternalPlugin.ts +0 -98
- package/src/utils/SdCliViteLazyImportPlugin.ts +0 -26
- package/src/utils/SdCliViteLoggerPlugin.ts +0 -29
- package/src/utils/SdCliViteNodeGlobalPlugin.ts +0 -31
- package/src/utils/SdCliViteReactSwcPlugin.ts +0 -153
- package/src/utils/SdCliViteServeOptimizeExcludePlugin.ts +0 -42
- package/src/utils/getElectronReactExternals.ts +0 -19
- package/src/utils/sdCliTsDefineTransformer.ts +0 -33
package/package.json
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@simplysm/sd-cli",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "11.0.4",
|
|
4
4
|
"description": "심플리즘 패키지 - CLI",
|
|
5
5
|
"author": "김석래",
|
|
6
6
|
"repository": {
|
|
7
7
|
"type": "git",
|
|
8
|
-
"url": "https://github.com/kslhunter/
|
|
8
|
+
"url": "https://github.com/kslhunter/simplysm11.git",
|
|
9
9
|
"directory": "packages/sd-cli"
|
|
10
10
|
},
|
|
11
11
|
"license": "MIT",
|
|
@@ -17,33 +17,31 @@
|
|
|
17
17
|
"node": "^16"
|
|
18
18
|
},
|
|
19
19
|
"dependencies": {
|
|
20
|
+
"@angular-devkit/build-angular": "^16.2.5",
|
|
21
|
+
"@angular/common": "^16.2.8",
|
|
22
|
+
"@angular/compiler": "^16.2.8",
|
|
23
|
+
"@angular/compiler-cli": "^16.2.8",
|
|
24
|
+
"@angular/core": "^16.2.8",
|
|
20
25
|
"@electron/rebuild": "^3.3.0",
|
|
21
|
-
"@
|
|
22
|
-
"@simplysm/sd-core-
|
|
23
|
-
"@simplysm/sd-
|
|
24
|
-
"@simplysm/sd-
|
|
25
|
-
"
|
|
26
|
-
"@swc/core": "^1.3.91",
|
|
27
|
-
"@vite-pwa/assets-generator": "^0.0.10",
|
|
28
|
-
"@vitejs/plugin-react-swc": "^3.4.0",
|
|
26
|
+
"@simplysm/sd-core-common": "11.0.4",
|
|
27
|
+
"@simplysm/sd-core-node": "11.0.4",
|
|
28
|
+
"@simplysm/sd-service-server": "11.0.4",
|
|
29
|
+
"@simplysm/sd-storage": "11.0.4",
|
|
30
|
+
"browserslist": "^4.22.1",
|
|
29
31
|
"electron": "^26.2.4",
|
|
30
32
|
"electron-builder": "^24.7.0",
|
|
31
|
-
"esbuild": "
|
|
33
|
+
"esbuild": "0.18.17",
|
|
32
34
|
"esbuild-plugin-tsc": "^0.4.0",
|
|
33
35
|
"eslint": "^8.50.0",
|
|
34
|
-
"less": "^4.2.0",
|
|
35
|
-
"lib-esm": "^0.4.1",
|
|
36
36
|
"node-stdlib-browser": "^1.2.0",
|
|
37
|
+
"rxjs": "^7.8.1",
|
|
38
|
+
"sass": "^1.69.0",
|
|
37
39
|
"semver": "^7.5.4",
|
|
38
|
-
"
|
|
39
|
-
"
|
|
40
|
-
"vite-plugin-pwa": "^0.16.5",
|
|
41
|
-
"vite-tsconfig-paths": "^4.2.1",
|
|
42
|
-
"yargs": "^17.7.2"
|
|
40
|
+
"yargs": "^17.7.2",
|
|
41
|
+
"zone.js": "~0.13.0"
|
|
43
42
|
},
|
|
44
43
|
"devDependencies": {
|
|
45
44
|
"@types/eslint": "^8.44.3",
|
|
46
|
-
"@types/less": "^3.0.4",
|
|
47
45
|
"@types/yargs": "^17.0.26"
|
|
48
46
|
},
|
|
49
47
|
"peerDependencies": {
|
package/src/build-cluster.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import cluster from "node:cluster";
|
|
2
|
-
import {SdCliTsLibBuilder} from "./builders/SdCliTsLibBuilder";
|
|
3
2
|
import {FsUtil, Logger, LoggerSeverity} from "@simplysm/sd-core-node";
|
|
4
3
|
import path from "path";
|
|
5
4
|
import {SdCliJsLibLinter} from "./builders/SdCliJsLibLinter";
|
|
@@ -8,6 +7,7 @@ import {ISdCliBuildClusterReqMessage, ISdCliBuildClusterResMessage} from "./comm
|
|
|
8
7
|
import {NeverEntryError} from "@simplysm/sd-core-common";
|
|
9
8
|
import {SdCliServerBuilder} from "./builders/SdCliServerBuilder";
|
|
10
9
|
import {SdCliClientBuilder} from "./builders/SdCliClientBuilder";
|
|
10
|
+
import {SdCliTsLibBuilder} from "./builders/SdCliTsLibBuilder";
|
|
11
11
|
|
|
12
12
|
Error.stackTraceLimit = Infinity;
|
|
13
13
|
EventEmitter.defaultMaxListeners = 0;
|
|
@@ -48,10 +48,11 @@ if (cluster.isPrimary) {
|
|
|
48
48
|
}
|
|
49
49
|
else {
|
|
50
50
|
const message = JSON.parse(process.env["SD_CLUSTER_MESSAGE"]!) as ISdCliBuildClusterReqMessage;
|
|
51
|
+
const pkgConf = message.projConf.packages[path.basename(message.pkgPath)]!;
|
|
51
52
|
|
|
52
53
|
if (message.cmd === "watch") {
|
|
53
54
|
// [library] javascript
|
|
54
|
-
if (
|
|
55
|
+
if (pkgConf.type === "library" && !FsUtil.exists(path.resolve(message.pkgPath, "tsconfig.json"))) {
|
|
55
56
|
if (message.withLint) {
|
|
56
57
|
await new SdCliJsLibLinter(message.pkgPath)
|
|
57
58
|
.on("change", () => {
|
|
@@ -75,8 +76,8 @@ else {
|
|
|
75
76
|
});
|
|
76
77
|
}
|
|
77
78
|
// [library] typescript
|
|
78
|
-
else if (
|
|
79
|
-
await new SdCliTsLibBuilder(message.
|
|
79
|
+
else if (pkgConf.type === "library" && FsUtil.exists(path.resolve(message.pkgPath, "tsconfig.json"))) {
|
|
80
|
+
await new SdCliTsLibBuilder(message.projConf, message.pkgPath, message.withLint)
|
|
80
81
|
.on("change", () => {
|
|
81
82
|
sendMessage({
|
|
82
83
|
type: "change",
|
|
@@ -97,8 +98,8 @@ else {
|
|
|
97
98
|
});
|
|
98
99
|
}
|
|
99
100
|
// [server]
|
|
100
|
-
else if (
|
|
101
|
-
await new SdCliServerBuilder(message.
|
|
101
|
+
else if (pkgConf.type === "server") {
|
|
102
|
+
await new SdCliServerBuilder(message.projConf, message.pkgPath, message.withLint)
|
|
102
103
|
.on("change", () => {
|
|
103
104
|
sendMessage({
|
|
104
105
|
type: "change",
|
|
@@ -119,8 +120,8 @@ else {
|
|
|
119
120
|
});
|
|
120
121
|
}
|
|
121
122
|
// [client]
|
|
122
|
-
else if (
|
|
123
|
-
await new SdCliClientBuilder(message.
|
|
123
|
+
else if (pkgConf.type === "client") {
|
|
124
|
+
await new SdCliClientBuilder(message.projConf, message.pkgPath)
|
|
124
125
|
.on("change", () => {
|
|
125
126
|
sendMessage({
|
|
126
127
|
type: "change",
|
|
@@ -146,7 +147,7 @@ else {
|
|
|
146
147
|
}
|
|
147
148
|
else { // build
|
|
148
149
|
// [library] javascript
|
|
149
|
-
if (
|
|
150
|
+
if (pkgConf.type === "library" && !FsUtil.exists(path.resolve(message.pkgPath, "tsconfig.json"))) {
|
|
150
151
|
if (message.withLint) {
|
|
151
152
|
const result = await new SdCliJsLibLinter(message.pkgPath).buildAsync();
|
|
152
153
|
sendMessage({
|
|
@@ -164,8 +165,8 @@ else {
|
|
|
164
165
|
}
|
|
165
166
|
}
|
|
166
167
|
// [library] typescript
|
|
167
|
-
else if (
|
|
168
|
-
const result = await new SdCliTsLibBuilder(message.
|
|
168
|
+
else if (pkgConf.type === "library" && FsUtil.exists(path.resolve(message.pkgPath, "tsconfig.json"))) {
|
|
169
|
+
const result = await new SdCliTsLibBuilder(message.projConf, message.pkgPath, message.withLint).buildAsync();
|
|
169
170
|
sendMessage({
|
|
170
171
|
type: "complete",
|
|
171
172
|
result,
|
|
@@ -173,8 +174,8 @@ else {
|
|
|
173
174
|
});
|
|
174
175
|
}
|
|
175
176
|
// [server]
|
|
176
|
-
else if (
|
|
177
|
-
const result = await new SdCliServerBuilder(message.
|
|
177
|
+
else if (pkgConf.type === "server") {
|
|
178
|
+
const result = await new SdCliServerBuilder(message.projConf, message.pkgPath, message.withLint).buildAsync();
|
|
178
179
|
sendMessage({
|
|
179
180
|
type: "complete",
|
|
180
181
|
result,
|
|
@@ -182,8 +183,8 @@ else {
|
|
|
182
183
|
});
|
|
183
184
|
}
|
|
184
185
|
// [client]
|
|
185
|
-
else if (
|
|
186
|
-
const result = await new SdCliClientBuilder(message.
|
|
186
|
+
else if (pkgConf.type === "client") {
|
|
187
|
+
const result = await new SdCliClientBuilder(message.projConf, message.pkgPath).buildAsync();
|
|
187
188
|
sendMessage({
|
|
188
189
|
type: "complete",
|
|
189
190
|
result,
|
|
@@ -0,0 +1,381 @@
|
|
|
1
|
+
import {
|
|
2
|
+
createCompilerPlugin,
|
|
3
|
+
SourceFileCache
|
|
4
|
+
} from "@angular-devkit/build-angular/src/tools/esbuild/angular/compiler-plugin";
|
|
5
|
+
import {NormalizedApplicationBuildOptions} from "@angular-devkit/build-angular/src/builders/application/options";
|
|
6
|
+
import path from "path";
|
|
7
|
+
import {CrossOrigin} from "@angular-devkit/build-angular/src/builders/application/schema";
|
|
8
|
+
import {BundlerContext} from "@angular-devkit/build-angular/src/tools/esbuild/bundler-context";
|
|
9
|
+
import esbuild from "esbuild";
|
|
10
|
+
import {createCompilerPluginOptions} from "@angular-devkit/build-angular/src/tools/esbuild/compiler-plugin-options";
|
|
11
|
+
import {FsUtil, Logger, PathUtil} from "@simplysm/sd-core-node";
|
|
12
|
+
import {fileURLToPath} from "url";
|
|
13
|
+
import {createVirtualModulePlugin} from "@angular-devkit/build-angular/src/tools/esbuild/virtual-module-plugin";
|
|
14
|
+
import {
|
|
15
|
+
createSourcemapIgnorelistPlugin
|
|
16
|
+
} from "@angular-devkit/build-angular/src/tools/esbuild/sourcemap-ignorelist-plugin";
|
|
17
|
+
import nodeStdLibBrowser from "node-stdlib-browser";
|
|
18
|
+
import nodeStdLibBrowserPlugin from "node-stdlib-browser/helpers/esbuild/plugin";
|
|
19
|
+
import {ExecutionResult} from "@angular-devkit/build-angular/src/tools/esbuild/bundler-execution-result";
|
|
20
|
+
import {INpmConfig, ISdCliPackageBuildResult} from "../commons";
|
|
21
|
+
import {generateIndexHtml} from "@angular-devkit/build-angular/src/tools/esbuild/index-html-generator";
|
|
22
|
+
import {copyAssets} from "@angular-devkit/build-angular/src/utils/copy-assets";
|
|
23
|
+
import {extractLicenses} from "@angular-devkit/build-angular/src/tools/esbuild/license-extractor";
|
|
24
|
+
import {augmentAppWithServiceWorkerEsbuild} from "@angular-devkit/build-angular/src/utils/service-worker";
|
|
25
|
+
import {createGlobalStylesBundleOptions} from "@angular-devkit/build-angular/src/tools/esbuild/global-styles";
|
|
26
|
+
|
|
27
|
+
export class SdNgBundler {
|
|
28
|
+
private readonly _logger = Logger.get(["simplysm", "sd-cli", "SdNgEsbuildBuilder"]);
|
|
29
|
+
|
|
30
|
+
private readonly _sourceFileCache = new SourceFileCache();
|
|
31
|
+
private readonly _options: NormalizedApplicationBuildOptions;
|
|
32
|
+
|
|
33
|
+
private _contexts: BundlerContext[] | undefined;
|
|
34
|
+
|
|
35
|
+
private readonly _outputCache = new Map<string, string | number>();
|
|
36
|
+
|
|
37
|
+
public constructor(private readonly _opt: { dev: boolean, builderType: string, pkgPath: string }) {
|
|
38
|
+
this._options = this._getOptions(_opt);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
public removeCache(filePaths: string[]): void {
|
|
42
|
+
this._sourceFileCache.invalidate(filePaths);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
public async bundleAsync(): Promise<ISdCliPackageBuildResult[]> {
|
|
46
|
+
if (!this._contexts) {
|
|
47
|
+
this._contexts = [];
|
|
48
|
+
this._contexts.push(await this._getAppContextAsync());
|
|
49
|
+
this._contexts.push(this._getStyleContext());
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
//-- build
|
|
53
|
+
const bundlingResult = await BundlerContext.bundleAll(this._contexts);
|
|
54
|
+
|
|
55
|
+
const results = [
|
|
56
|
+
...bundlingResult.warnings.map((warn) => ({
|
|
57
|
+
filePath: warn.location?.file !== undefined ? path.resolve(warn.location.file) : undefined,
|
|
58
|
+
line: warn.location?.line,
|
|
59
|
+
char: warn.location?.column,
|
|
60
|
+
code: undefined,
|
|
61
|
+
severity: "warning" as const,
|
|
62
|
+
message: warn.text,
|
|
63
|
+
type: "build" as const
|
|
64
|
+
})),
|
|
65
|
+
...bundlingResult.errors?.map((err) => ({
|
|
66
|
+
filePath: err.location?.file !== undefined ? path.resolve(err.location.file) : undefined,
|
|
67
|
+
line: err.location?.line,
|
|
68
|
+
char: err.location?.column !== undefined ? err.location.column + 1 : undefined,
|
|
69
|
+
code: undefined,
|
|
70
|
+
severity: "warning" as const,
|
|
71
|
+
message: err.text,
|
|
72
|
+
type: "build" as const
|
|
73
|
+
})) ?? []
|
|
74
|
+
];
|
|
75
|
+
if (bundlingResult.errors) {
|
|
76
|
+
return results;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
const executionResult = new ExecutionResult(this._contexts, this._sourceFileCache);
|
|
80
|
+
executionResult.outputFiles.push(...bundlingResult.outputFiles);
|
|
81
|
+
|
|
82
|
+
//-- index
|
|
83
|
+
if (this._options.indexHtmlOptions) {
|
|
84
|
+
const genIndexHtmlResult = await generateIndexHtml(
|
|
85
|
+
bundlingResult.initialFiles,
|
|
86
|
+
executionResult,
|
|
87
|
+
this._options
|
|
88
|
+
);
|
|
89
|
+
if (genIndexHtmlResult.warnings.length > 0) {
|
|
90
|
+
this._logger.warn(...genIndexHtmlResult.warnings);
|
|
91
|
+
}
|
|
92
|
+
if (genIndexHtmlResult.errors.length > 0) {
|
|
93
|
+
this._logger.warn(...genIndexHtmlResult.errors);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
executionResult.addOutputFile(this._options.indexHtmlOptions!.output, genIndexHtmlResult.content);
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
//-- copy assets
|
|
100
|
+
if (this._options.assets) {
|
|
101
|
+
executionResult.assetFiles.push(...(await copyAssets(this._options.assets!, [], this._options.workspaceRoot)));
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
//-- extract 3rdpartylicenses
|
|
105
|
+
if (this._options.extractLicenses) {
|
|
106
|
+
executionResult.addOutputFile('3rdpartylicenses.txt', await extractLicenses(bundlingResult.metafile, this._options.workspaceRoot));
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
//-- service worker
|
|
110
|
+
if (this._options.serviceWorker !== undefined) {
|
|
111
|
+
try {
|
|
112
|
+
const serviceWorkerResult = await augmentAppWithServiceWorkerEsbuild(
|
|
113
|
+
this._options.workspaceRoot,
|
|
114
|
+
this._options.serviceWorker,
|
|
115
|
+
this._options.baseHref ?? '/',
|
|
116
|
+
executionResult.outputFiles,
|
|
117
|
+
executionResult.assetFiles
|
|
118
|
+
);
|
|
119
|
+
executionResult.addOutputFile('ngsw.json', serviceWorkerResult.manifest);
|
|
120
|
+
executionResult.assetFiles.push(...serviceWorkerResult.assetFiles);
|
|
121
|
+
}
|
|
122
|
+
catch (error) {
|
|
123
|
+
this._logger.error(error instanceof Error ? error.message : `${error}`);
|
|
124
|
+
return results;
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
//-- write
|
|
129
|
+
|
|
130
|
+
const distPath = path.resolve(this._options.outputPath, "dist", ...(this._opt.builderType === "web" ? [] : [this._opt.builderType]));
|
|
131
|
+
for (const outputFile of executionResult.outputFiles) {
|
|
132
|
+
const distFilePath = path.resolve(distPath, outputFile.path);
|
|
133
|
+
|
|
134
|
+
const prev = this._outputCache.get(distFilePath);
|
|
135
|
+
if (prev !== Buffer.from(outputFile.contents).toString("base64")) {
|
|
136
|
+
await FsUtil.writeFileAsync(distFilePath, outputFile.contents);
|
|
137
|
+
this._outputCache.set(distFilePath, Buffer.from(outputFile.contents).toString("base64"));
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
for (const assetFile of executionResult.assetFiles) {
|
|
141
|
+
const prev = this._outputCache.get(assetFile.source);
|
|
142
|
+
const curr = FsUtil.lstat(assetFile.source).mtime.getTime();
|
|
143
|
+
if (prev !== curr) {
|
|
144
|
+
await FsUtil.copyAsync(assetFile.source, path.resolve(distPath, assetFile.destination));
|
|
145
|
+
this._outputCache.set(assetFile.source, curr);
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
return results;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
private async _getAppContextAsync(): Promise<BundlerContext> {
|
|
153
|
+
const esbuildOption = await this._getEsBuildOptionsAsync();
|
|
154
|
+
|
|
155
|
+
return new BundlerContext(
|
|
156
|
+
this._options.workspaceRoot,
|
|
157
|
+
true,
|
|
158
|
+
esbuildOption
|
|
159
|
+
);
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
private _getStyleContext(): BundlerContext {
|
|
163
|
+
const esbuildOptions = createGlobalStylesBundleOptions(
|
|
164
|
+
this._options,
|
|
165
|
+
[
|
|
166
|
+
'chrome117.0', 'chrome116.0',
|
|
167
|
+
'edge117.0', 'edge116.0',
|
|
168
|
+
'firefox118.0', 'firefox115.0',
|
|
169
|
+
'ios17.0', 'ios16.6',
|
|
170
|
+
'ios16.5', 'ios16.4',
|
|
171
|
+
'ios16.3', 'ios16.2',
|
|
172
|
+
'ios16.1', 'ios16.0',
|
|
173
|
+
'safari17.0', 'safari16.6',
|
|
174
|
+
'safari16.5', 'safari16.4',
|
|
175
|
+
'safari16.3', 'safari16.2',
|
|
176
|
+
'safari16.1', 'safari16.0'
|
|
177
|
+
],
|
|
178
|
+
true,
|
|
179
|
+
this._sourceFileCache.loadResultCache
|
|
180
|
+
);
|
|
181
|
+
|
|
182
|
+
return new BundlerContext(
|
|
183
|
+
this._options.workspaceRoot,
|
|
184
|
+
true,
|
|
185
|
+
esbuildOptions!,
|
|
186
|
+
() => true
|
|
187
|
+
);
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
private async _getEsBuildOptionsAsync(): Promise<esbuild.BuildOptions> {
|
|
191
|
+
const pkgNpmConf: INpmConfig = FsUtil.readJson(path.resolve(this._options.workspaceRoot, "package.json"));
|
|
192
|
+
|
|
193
|
+
const {pluginOptions, styleOptions} = createCompilerPluginOptions(
|
|
194
|
+
this._options,
|
|
195
|
+
[
|
|
196
|
+
'chrome117.0', 'chrome116.0',
|
|
197
|
+
'edge117.0', 'edge116.0',
|
|
198
|
+
'firefox118.0', 'firefox115.0',
|
|
199
|
+
'ios17.0', 'ios16.6',
|
|
200
|
+
'ios16.5', 'ios16.4',
|
|
201
|
+
'ios16.3', 'ios16.2',
|
|
202
|
+
'ios16.1', 'ios16.0',
|
|
203
|
+
'safari17.0', 'safari16.6',
|
|
204
|
+
'safari16.5', 'safari16.4',
|
|
205
|
+
'safari16.3', 'safari16.2',
|
|
206
|
+
'safari16.1', 'safari16.0'
|
|
207
|
+
],
|
|
208
|
+
this._sourceFileCache,
|
|
209
|
+
);
|
|
210
|
+
|
|
211
|
+
return {
|
|
212
|
+
absWorkingDir: this._options.workspaceRoot,
|
|
213
|
+
bundle: true,
|
|
214
|
+
format: 'esm',
|
|
215
|
+
assetNames: 'media/[name]',
|
|
216
|
+
conditions: ['es2020', 'es2015', 'module'],
|
|
217
|
+
resolveExtensions: ['.ts', '.tsx', '.mjs', '.js'],
|
|
218
|
+
metafile: true,
|
|
219
|
+
legalComments: this._options.watch ? 'eof' : 'none',
|
|
220
|
+
logLevel: 'silent',
|
|
221
|
+
minifyIdentifiers: !this._options.watch,
|
|
222
|
+
minifySyntax: !this._options.watch,
|
|
223
|
+
minifyWhitespace: !this._options.watch,
|
|
224
|
+
pure: ['forwardRef'],
|
|
225
|
+
outdir: this._options.outputPath,
|
|
226
|
+
outExtension: undefined,
|
|
227
|
+
sourcemap: this._options.watch,
|
|
228
|
+
splitting: true,
|
|
229
|
+
chunkNames: 'chunk-[hash]',
|
|
230
|
+
tsconfig: this._options.tsconfig,
|
|
231
|
+
external: [],
|
|
232
|
+
write: false,
|
|
233
|
+
preserveSymlinks: false,
|
|
234
|
+
define: {
|
|
235
|
+
...!this._options.watch ? {ngDevMode: 'false'} : {},
|
|
236
|
+
ngJitMode: 'false',
|
|
237
|
+
global: 'global',
|
|
238
|
+
process: 'process',
|
|
239
|
+
Buffer: 'Buffer',
|
|
240
|
+
'process.env.SD_VERSION': JSON.stringify(pkgNpmConf.version),
|
|
241
|
+
},
|
|
242
|
+
platform: 'browser',
|
|
243
|
+
mainFields: ['es2020', 'es2015', 'browser', 'module', 'main'],
|
|
244
|
+
entryNames: '[name]',
|
|
245
|
+
entryPoints: {
|
|
246
|
+
...this._options.entryPoints,
|
|
247
|
+
polyfills: 'angular:polyfills'
|
|
248
|
+
},
|
|
249
|
+
target: [
|
|
250
|
+
'chrome117.0', 'chrome116.0',
|
|
251
|
+
'edge117.0', 'edge116.0',
|
|
252
|
+
'firefox118.0', 'firefox115.0',
|
|
253
|
+
'ios17.0', 'ios16.6',
|
|
254
|
+
'ios16.5', 'ios16.4',
|
|
255
|
+
'ios16.3', 'ios16.2',
|
|
256
|
+
'ios16.1', 'ios16.0',
|
|
257
|
+
'safari17.0', 'safari16.6',
|
|
258
|
+
'safari16.5', 'safari16.4',
|
|
259
|
+
'safari16.3', 'safari16.2',
|
|
260
|
+
'safari16.1', 'safari16.0'
|
|
261
|
+
],
|
|
262
|
+
supported: {'async-await': false, 'object-rest-spread': false},
|
|
263
|
+
loader: {
|
|
264
|
+
".png": "file",
|
|
265
|
+
".jpeg": "file",
|
|
266
|
+
".jpg": "file",
|
|
267
|
+
".jfif": "file",
|
|
268
|
+
".gif": "file",
|
|
269
|
+
".svg": "file",
|
|
270
|
+
".woff": "file",
|
|
271
|
+
".woff2": "file",
|
|
272
|
+
".ttf": "file",
|
|
273
|
+
".eot": "file",
|
|
274
|
+
".ico": "file",
|
|
275
|
+
".otf": "file",
|
|
276
|
+
".csv": "file",
|
|
277
|
+
".xlsx": "file",
|
|
278
|
+
".xls": "file",
|
|
279
|
+
".pptx": "file",
|
|
280
|
+
".ppt": "file",
|
|
281
|
+
".docx": "file",
|
|
282
|
+
".doc": "file",
|
|
283
|
+
".zip": "file",
|
|
284
|
+
".pfx": "file",
|
|
285
|
+
".pkl": "file"
|
|
286
|
+
},
|
|
287
|
+
inject: [PathUtil.posix(fileURLToPath(await import.meta.resolve!("node-stdlib-browser/helpers/esbuild/shim")))],
|
|
288
|
+
plugins: [
|
|
289
|
+
createVirtualModulePlugin({
|
|
290
|
+
namespace: "angular:polyfills",
|
|
291
|
+
loadContent: () => ({
|
|
292
|
+
contents: `import "./src/polyfills.ts";`,
|
|
293
|
+
loader: 'js',
|
|
294
|
+
resolveDir: this._options.workspaceRoot
|
|
295
|
+
})
|
|
296
|
+
}) as esbuild.Plugin,
|
|
297
|
+
createSourcemapIgnorelistPlugin(),
|
|
298
|
+
createCompilerPlugin(
|
|
299
|
+
pluginOptions,
|
|
300
|
+
styleOptions
|
|
301
|
+
) as esbuild.Plugin,
|
|
302
|
+
nodeStdLibBrowserPlugin(nodeStdLibBrowser)
|
|
303
|
+
]
|
|
304
|
+
};
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
private _getOptions(opt: { dev: boolean, builderType: string, pkgPath: string }): NormalizedApplicationBuildOptions {
|
|
308
|
+
const mainFilePath = path.resolve(opt.pkgPath, "src/main.ts");
|
|
309
|
+
const tsconfigFilePath = path.resolve(opt.pkgPath, "tsconfig.json");
|
|
310
|
+
const indexHtmlFilePath = path.resolve(opt.pkgPath, "src/index.html");
|
|
311
|
+
const swFilePath = path.resolve(opt.pkgPath, "ngsw-config.json");
|
|
312
|
+
|
|
313
|
+
const cacheBasePath = path.resolve(opt.pkgPath, ".cache");
|
|
314
|
+
|
|
315
|
+
const pkgName = path.basename(opt.pkgPath);
|
|
316
|
+
|
|
317
|
+
return {
|
|
318
|
+
advancedOptimizations: true,
|
|
319
|
+
allowedCommonJsDependencies: [],
|
|
320
|
+
baseHref: `/${pkgName}/`,
|
|
321
|
+
cacheOptions: {
|
|
322
|
+
enabled: true,
|
|
323
|
+
basePath: cacheBasePath,
|
|
324
|
+
path: path.resolve(cacheBasePath, opt.builderType)
|
|
325
|
+
},
|
|
326
|
+
crossOrigin: CrossOrigin.None,
|
|
327
|
+
deleteOutputPath: true,
|
|
328
|
+
externalDependencies: [],
|
|
329
|
+
extractLicenses: !opt.dev,
|
|
330
|
+
inlineStyleLanguage: 'scss',
|
|
331
|
+
jit: false,
|
|
332
|
+
stats: false,
|
|
333
|
+
polyfills: ["./src/polyfills.ts"],
|
|
334
|
+
poll: undefined,
|
|
335
|
+
progress: true,
|
|
336
|
+
externalPackages: opt.dev ? true : undefined,
|
|
337
|
+
preserveSymlinks: false,
|
|
338
|
+
stylePreprocessorOptions: {includePaths: []},
|
|
339
|
+
subresourceIntegrity: false,
|
|
340
|
+
serverEntryPoint: undefined,
|
|
341
|
+
prerenderOptions: undefined,
|
|
342
|
+
appShellOptions: undefined,
|
|
343
|
+
ssrOptions: undefined,
|
|
344
|
+
verbose: false,
|
|
345
|
+
watch: opt.dev,
|
|
346
|
+
workspaceRoot: opt.pkgPath,
|
|
347
|
+
entryPoints: {main: mainFilePath},
|
|
348
|
+
optimizationOptions: {
|
|
349
|
+
scripts: !opt.dev,
|
|
350
|
+
styles: {minify: !opt.dev, inlineCritical: !opt.dev},
|
|
351
|
+
fonts: {inline: !opt.dev}
|
|
352
|
+
},
|
|
353
|
+
outputPath: opt.pkgPath,
|
|
354
|
+
outExtension: undefined,
|
|
355
|
+
sourcemapOptions: {vendor: false, hidden: false, scripts: opt.dev, styles: opt.dev},
|
|
356
|
+
tsconfig: tsconfigFilePath,
|
|
357
|
+
projectRoot: opt.pkgPath,
|
|
358
|
+
assets: [
|
|
359
|
+
{glob: 'favicon.ico', input: 'src', output: ''},
|
|
360
|
+
{glob: '**/*', input: 'src\\assets', output: 'assets'}
|
|
361
|
+
],
|
|
362
|
+
outputNames: {bundles: '[name]', media: 'media/[name]'},
|
|
363
|
+
fileReplacements: undefined,
|
|
364
|
+
globalStyles: [{name: 'styles', files: ["src/styles.scss"], initial: true}],
|
|
365
|
+
globalScripts: [],
|
|
366
|
+
serviceWorker: FsUtil.exists(swFilePath) ? swFilePath : undefined,
|
|
367
|
+
indexHtmlOptions: {
|
|
368
|
+
input: indexHtmlFilePath,
|
|
369
|
+
output: 'index.html',
|
|
370
|
+
insertionOrder: [
|
|
371
|
+
['runtime', true],
|
|
372
|
+
['polyfills', true],
|
|
373
|
+
['styles', false],
|
|
374
|
+
['vendor', true],
|
|
375
|
+
['main', true]
|
|
376
|
+
]
|
|
377
|
+
},
|
|
378
|
+
tailwindConfiguration: undefined
|
|
379
|
+
};
|
|
380
|
+
}
|
|
381
|
+
}
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import {ISdCliPackageBuildResult} from "../commons";
|
|
2
|
+
import esbuild from "esbuild";
|
|
3
|
+
import path from "path";
|
|
4
|
+
import esbuildPluginTsc from "esbuild-plugin-tsc";
|
|
5
|
+
|
|
6
|
+
export class SdTsBundler {
|
|
7
|
+
private _context?: esbuild.BuildContext;
|
|
8
|
+
|
|
9
|
+
public constructor(private readonly _opt: {
|
|
10
|
+
dev: boolean;
|
|
11
|
+
pkgPath: string;
|
|
12
|
+
entryPoints: string[];
|
|
13
|
+
external?: string[];
|
|
14
|
+
}) {
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
public async bundleAsync(): Promise<ISdCliPackageBuildResult[]> {
|
|
18
|
+
if (!this._context) {
|
|
19
|
+
const options = this.getOptions();
|
|
20
|
+
this._context = await esbuild.context(options);
|
|
21
|
+
}
|
|
22
|
+
const results = await this._context.rebuild();
|
|
23
|
+
return this._convertResults(results);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
public getOptions(): esbuild.BuildOptions {
|
|
27
|
+
return {
|
|
28
|
+
entryPoints: this._opt.entryPoints,
|
|
29
|
+
keepNames: true,
|
|
30
|
+
bundle: true,
|
|
31
|
+
sourcemap: this._opt.dev,
|
|
32
|
+
target: "node16",
|
|
33
|
+
mainFields: ['es2020', 'es2015', 'module', 'main'],
|
|
34
|
+
conditions: ["es2020", "es2015", "module"],
|
|
35
|
+
tsconfig: path.resolve(this._opt.pkgPath, "tsconfig.json"),
|
|
36
|
+
write: true,
|
|
37
|
+
outdir: path.resolve(this._opt.pkgPath, "dist"),
|
|
38
|
+
format: "esm",
|
|
39
|
+
resolveExtensions: [".js", ".mjs", ".cjs", ".ts"],
|
|
40
|
+
preserveSymlinks: false,
|
|
41
|
+
loader: {
|
|
42
|
+
".png": "file",
|
|
43
|
+
".jpeg": "file",
|
|
44
|
+
".jpg": "file",
|
|
45
|
+
".jfif": "file",
|
|
46
|
+
".gif": "file",
|
|
47
|
+
".svg": "file",
|
|
48
|
+
".woff": "file",
|
|
49
|
+
".woff2": "file",
|
|
50
|
+
".ttf": "file",
|
|
51
|
+
".eot": "file",
|
|
52
|
+
".ico": "file",
|
|
53
|
+
".otf": "file",
|
|
54
|
+
".csv": "file",
|
|
55
|
+
".xlsx": "file",
|
|
56
|
+
".xls": "file",
|
|
57
|
+
".pptx": "file",
|
|
58
|
+
".ppt": "file",
|
|
59
|
+
".docx": "file",
|
|
60
|
+
".doc": "file",
|
|
61
|
+
".zip": "file",
|
|
62
|
+
".pfx": "file",
|
|
63
|
+
".pkl": "file"
|
|
64
|
+
},
|
|
65
|
+
platform: "node",
|
|
66
|
+
logLevel: "silent",
|
|
67
|
+
external: this._opt.external,
|
|
68
|
+
banner: {
|
|
69
|
+
js: `
|
|
70
|
+
import __path__ from 'path';
|
|
71
|
+
import { fileURLToPath as __fileURLToPath__ } from 'url';
|
|
72
|
+
import { createRequire as __createRequire__ } from 'module';
|
|
73
|
+
|
|
74
|
+
const require = __createRequire__(import.meta.url);
|
|
75
|
+
const __filename = __fileURLToPath__(import.meta.url);
|
|
76
|
+
const __dirname = __path__.dirname(__filename);`.trim()
|
|
77
|
+
},
|
|
78
|
+
plugins: [
|
|
79
|
+
esbuildPluginTsc()
|
|
80
|
+
]
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
private _convertResults(result: esbuild.BuildResult): ISdCliPackageBuildResult[] {
|
|
85
|
+
return [
|
|
86
|
+
...result.warnings.map((warn) => ({
|
|
87
|
+
type: "build" as const,
|
|
88
|
+
filePath: warn.location?.file !== undefined ? path.resolve(warn.location.file) : undefined,
|
|
89
|
+
line: warn.location?.line,
|
|
90
|
+
char: warn.location?.column,
|
|
91
|
+
code: undefined,
|
|
92
|
+
severity: "warning" as const,
|
|
93
|
+
message: warn.text
|
|
94
|
+
})),
|
|
95
|
+
...result.errors.map((err) => ({
|
|
96
|
+
type: "build" as const,
|
|
97
|
+
filePath: err.location?.file !== undefined ? path.resolve(err.location.file) : undefined,
|
|
98
|
+
line: err.location?.line,
|
|
99
|
+
char: err.location?.column !== undefined ? err.location.column + 1 : undefined,
|
|
100
|
+
code: undefined,
|
|
101
|
+
severity: "error" as const,
|
|
102
|
+
message: err.text
|
|
103
|
+
}))
|
|
104
|
+
];
|
|
105
|
+
}
|
|
106
|
+
}
|