@simplysm/sd-cli 11.1.46 → 11.1.51
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-tools/SdLibBundler.d.ts +13 -0
- package/dist/build-tools/SdLibBundler.js +51 -0
- package/dist/build-tools/SdLibBundler.js.map +1 -0
- package/dist/build-tools/SdLinter.js +4 -4
- package/dist/build-tools/SdLinter.js.map +1 -1
- package/dist/build-tools/SdNgBundler.d.ts +10 -19
- package/dist/build-tools/SdNgBundler.js +103 -99
- package/dist/build-tools/SdNgBundler.js.map +1 -1
- package/dist/build-tools/SdTsCompiler.d.ts +23 -10
- package/dist/build-tools/SdTsCompiler.js +250 -220
- package/dist/build-tools/SdTsCompiler.js.map +1 -1
- package/dist/builders/SdCliTsLibBuilder.d.ts +2 -6
- package/dist/builders/SdCliTsLibBuilder.js +26 -21
- package/dist/builders/SdCliTsLibBuilder.js.map +1 -1
- package/dist/bundle-plugins/sdNgPlugin.js +2 -2
- package/dist/bundle-plugins/sdNgPlugin.js.map +1 -1
- package/dist/bundle-plugins/sdServerPlugin.js +2 -2
- package/dist/bundle-plugins/sdServerPlugin.js.map +1 -1
- package/dist/entry/SdCliProject.js +3 -1
- package/dist/entry/SdCliProject.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/sd-cli.d.ts +1 -1
- package/dist/sd-cli.js +1 -1
- package/package.json +5 -5
- package/src/build-tools/SdLibBundler.ts +70 -0
- package/src/build-tools/SdLinter.ts +4 -4
- package/src/build-tools/SdNgBundler.ts +114 -109
- package/src/build-tools/SdTsCompiler.ts +355 -214
- package/src/builders/SdCliTsLibBuilder.ts +29 -22
- package/src/bundle-plugins/sdNgPlugin.ts +2 -2
- package/src/bundle-plugins/sdServerPlugin.ts +2 -2
- package/src/entry/SdCliProject.ts +3 -1
- package/src/index.ts +1 -1
- package/src/sd-cli.ts +1 -1
- package/dist/build-tools2/SdTsCompiler2.d.ts +0 -26
- package/dist/build-tools2/SdTsCompiler2.js +0 -280
- package/dist/build-tools2/SdTsCompiler2.js.map +0 -1
- package/src/build-tools2/SdTsCompiler2.ts +0 -427
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { ISdCliPackageBuildResult } from "../commons";
|
|
2
|
+
import ts from "typescript";
|
|
3
|
+
export declare class SdLibBundler {
|
|
4
|
+
#private;
|
|
5
|
+
constructor(pkgPath: string, dev: boolean);
|
|
6
|
+
markChanges(modifiedFileSet: Set<string>): void;
|
|
7
|
+
buildAsync(): Promise<{
|
|
8
|
+
program: ts.Program;
|
|
9
|
+
watchFileSet: Set<string>;
|
|
10
|
+
affectedFileSet: Set<string>;
|
|
11
|
+
results: ISdCliPackageBuildResult[];
|
|
12
|
+
}>;
|
|
13
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { SdCliBuildResultUtil } from "../utils/SdCliBuildResultUtil";
|
|
2
|
+
import { SdTsCompiler } from "./SdTsCompiler";
|
|
3
|
+
import path from "path";
|
|
4
|
+
import { FsUtil, PathUtil } from "@simplysm/sd-core-node";
|
|
5
|
+
export class SdLibBundler {
|
|
6
|
+
#compiler;
|
|
7
|
+
#pkgPath;
|
|
8
|
+
constructor(pkgPath, dev) {
|
|
9
|
+
this.#pkgPath = pkgPath;
|
|
10
|
+
this.#compiler = new SdTsCompiler(pkgPath, { declaration: true }, dev, path.resolve(pkgPath, "src/styles.scss"));
|
|
11
|
+
}
|
|
12
|
+
markChanges(modifiedFileSet) {
|
|
13
|
+
this.#compiler.invalidate(modifiedFileSet);
|
|
14
|
+
}
|
|
15
|
+
async buildAsync() {
|
|
16
|
+
const buildResult = await this.#compiler.buildAsync();
|
|
17
|
+
for (const affectedFilePath of buildResult.affectedFileSet) {
|
|
18
|
+
const emittedFiles = buildResult.emittedFilesCacheMap.get(affectedFilePath) ?? [];
|
|
19
|
+
for (const emittedFile of emittedFiles) {
|
|
20
|
+
if (emittedFile.outRelPath != null) {
|
|
21
|
+
const distPath = path.resolve(this.#pkgPath, "dist", emittedFile.outRelPath);
|
|
22
|
+
if (PathUtil.isChildPath(distPath, path.resolve(this.#pkgPath, "dist"))) {
|
|
23
|
+
await FsUtil.writeFileAsync(distPath, emittedFile.text);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
const globalStylesheetResult = buildResult.stylesheetResultMap.get(affectedFilePath);
|
|
28
|
+
if (globalStylesheetResult) {
|
|
29
|
+
for (const outputFile of globalStylesheetResult.outputFiles) {
|
|
30
|
+
const distPath = path.resolve(this.#pkgPath, "dist", path.relative(this.#pkgPath, outputFile.path));
|
|
31
|
+
if (PathUtil.isChildPath(distPath, path.resolve(this.#pkgPath, "dist"))) {
|
|
32
|
+
await FsUtil.writeFileAsync(distPath, outputFile.text);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
return {
|
|
38
|
+
program: buildResult.program,
|
|
39
|
+
watchFileSet: buildResult.watchFileSet,
|
|
40
|
+
affectedFileSet: buildResult.affectedFileSet,
|
|
41
|
+
results: [
|
|
42
|
+
...buildResult.typescriptDiagnostics.map((item) => SdCliBuildResultUtil.convertFromTsDiag(item, "build")),
|
|
43
|
+
...Array.from(buildResult.stylesheetResultMap.values()).mapMany(item => item.errors ?? [])
|
|
44
|
+
.map(err => SdCliBuildResultUtil.convertFromEsbuildResult(err, "build", "error")),
|
|
45
|
+
/*...Array.from(buildResult.stylesheetResultMap.values()).mapMany(item => item.warnings!)
|
|
46
|
+
.map(warn => SdCliBuildResultUtil.convertFromEsbuildResult(warn, "build", "warning"))*/
|
|
47
|
+
]
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
//# sourceMappingURL=SdLibBundler.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SdLibBundler.js","sourceRoot":"","sources":["../../src/build-tools/SdLibBundler.ts"],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oBAAoB,CAAC,wBAAwB,CAAC,GAAG,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC;gBACnF;yGACyF;aAC1F;SACF,CAAC;IACJ,CAAC;CACF"}
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import { ESLint } from "eslint";
|
|
2
2
|
export class SdLinter {
|
|
3
3
|
static async lintAsync(fileSet, tsProgram) {
|
|
4
|
-
const
|
|
4
|
+
const lintFilePaths = Array.from(fileSet).filter((item) => (!item.endsWith(".d.ts") && item.endsWith(".ts")) ||
|
|
5
5
|
item.endsWith(".js") ||
|
|
6
6
|
item.endsWith(".cjs") ||
|
|
7
7
|
item.endsWith(".mjs"));
|
|
8
|
-
if (
|
|
8
|
+
if (lintFilePaths.length === 0) {
|
|
9
9
|
return [];
|
|
10
10
|
}
|
|
11
|
-
const linter = new ESLint(tsProgram
|
|
11
|
+
const linter = new ESLint(tsProgram != null ? {
|
|
12
12
|
cache: false,
|
|
13
13
|
overrideConfig: {
|
|
14
14
|
overrides: [
|
|
@@ -31,7 +31,7 @@ export class SdLinter {
|
|
|
31
31
|
]
|
|
32
32
|
}
|
|
33
33
|
} : undefined);
|
|
34
|
-
const lintResults = await linter.lintFiles(
|
|
34
|
+
const lintResults = await linter.lintFiles(lintFilePaths);
|
|
35
35
|
return lintResults.mapMany((lintResult) => lintResult.messages.map((msg) => ({
|
|
36
36
|
filePath: lintResult.filePath,
|
|
37
37
|
line: msg.line,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SdLinter.js","sourceRoot":"","sources":["../../src/build-tools/SdLinter.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,MAAM,EAAC,MAAM,QAAQ,CAAC;AAG9B,MAAM,OAAgB,QAAQ;IAC5B,MAAM,CAAC,KAAK,CAAC,SAAS,CAAC,OAAyB,EAAE,SAAiC;QACjF,MAAM,
|
|
1
|
+
{"version":3,"file":"SdLinter.js","sourceRoot":"","sources":["../../src/build-tools/SdLinter.ts"],"names":[],"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AU,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC;YAC3E,QAAQ,EAAE,UAAU,CAAC,QAAQ;YAC7B,IAAI,EAAE,GAAG,CAAC,IAAI;YACd,IAAI,EAAE,GAAG,CAAC,MAAM;YAChB,IAAI,EAAE,GAAG,CAAC,SAAS;YACnB,QAAQ,EAAE,GAAG,CAAC,QAAQ,KAAK,CAAC,CAAC,CAAC,CAAC,SAAkB,CAAC,CAAC,CAAC,OAAgB;YACpE,OAAO,EAAE,GAAG,CAAC,OAAO,GAAG,CAAC,GAAG,CAAC,MAAM,IAAI,IAAI,CAAC,CAAC,CAAC,KAAK,GAAG,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC;YACrE,IAAI,EAAE,MAAe;SACtB,CAAC,CAAC,CAAC,CAAC;IACP,CAAC;CACF"}
|
|
@@ -2,25 +2,7 @@ import { ISdCliClientBuilderCordovaConfig, ISdCliPackageBuildResult } from "../c
|
|
|
2
2
|
import ts from "typescript";
|
|
3
3
|
export declare class SdNgBundler {
|
|
4
4
|
#private;
|
|
5
|
-
|
|
6
|
-
private _contexts;
|
|
7
|
-
private readonly _outputCache;
|
|
8
|
-
private readonly _pkgNpmConf;
|
|
9
|
-
private readonly _mainFilePath;
|
|
10
|
-
private readonly _tsConfigFilePath;
|
|
11
|
-
private readonly _swConfFilePath;
|
|
12
|
-
private readonly _browserTarget;
|
|
13
|
-
private readonly _indexHtmlFilePath;
|
|
14
|
-
private readonly _pkgName;
|
|
15
|
-
private readonly _baseHref;
|
|
16
|
-
constructor(_opt: {
|
|
17
|
-
dev: boolean;
|
|
18
|
-
outputPath: string;
|
|
19
|
-
pkgPath: string;
|
|
20
|
-
builderType: string;
|
|
21
|
-
env: Record<string, string> | undefined;
|
|
22
|
-
cordovaConfig: ISdCliClientBuilderCordovaConfig | undefined;
|
|
23
|
-
});
|
|
5
|
+
constructor(opt: IOptions);
|
|
24
6
|
markForChanges(filePaths: string[]): void;
|
|
25
7
|
bundleAsync(): Promise<{
|
|
26
8
|
program?: ts.Program;
|
|
@@ -35,3 +17,12 @@ export declare class SdNgBundler {
|
|
|
35
17
|
private _getStyleContext;
|
|
36
18
|
private _getElectronMainContext;
|
|
37
19
|
}
|
|
20
|
+
interface IOptions {
|
|
21
|
+
dev: boolean;
|
|
22
|
+
outputPath: string;
|
|
23
|
+
pkgPath: string;
|
|
24
|
+
builderType: string;
|
|
25
|
+
env: Record<string, string> | undefined;
|
|
26
|
+
cordovaConfig: ISdCliClientBuilderCordovaConfig | undefined;
|
|
27
|
+
}
|
|
28
|
+
export {};
|
|
@@ -22,32 +22,36 @@ import { sdNgPlugin } from "../bundle-plugins/sdNgPlugin";
|
|
|
22
22
|
import { MemoryLoadResultCache } from "@angular-devkit/build-angular/src/tools/esbuild/load-result-cache";
|
|
23
23
|
export class SdNgBundler {
|
|
24
24
|
// private readonly _sourceFileCache = new SourceFileCache(
|
|
25
|
-
// path.resolve(this.
|
|
25
|
+
// path.resolve(this.#opt.pkgPath, ".cache")
|
|
26
26
|
// );
|
|
27
|
-
#modifiedFileSet;
|
|
28
|
-
#ngResultCache
|
|
29
|
-
|
|
27
|
+
#modifiedFileSet = new Set();
|
|
28
|
+
#ngResultCache = {
|
|
29
|
+
affectedFileSet: new Set(),
|
|
30
|
+
watchFileSet: new Set()
|
|
31
|
+
};
|
|
32
|
+
#styleLoadResultCache = new MemoryLoadResultCache();
|
|
33
|
+
#contexts;
|
|
34
|
+
#outputCache = new Map();
|
|
35
|
+
#opt;
|
|
36
|
+
#pkgNpmConf;
|
|
37
|
+
#mainFilePath;
|
|
38
|
+
#tsConfigFilePath;
|
|
39
|
+
#swConfFilePath;
|
|
40
|
+
#browserTarget;
|
|
41
|
+
#indexHtmlFilePath;
|
|
42
|
+
#pkgName;
|
|
43
|
+
#baseHref;
|
|
30
44
|
// #loadFilePathSet = new Set<string>();
|
|
31
|
-
constructor(
|
|
32
|
-
this
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
this.#
|
|
37
|
-
this.#
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
}
|
|
41
|
-
this.#styleLoadResultCache = new MemoryLoadResultCache();
|
|
42
|
-
this._outputCache = new Map();
|
|
43
|
-
this._pkgNpmConf = FsUtil.readJson(path.resolve(this._opt.pkgPath, "package.json"));
|
|
44
|
-
this._mainFilePath = path.resolve(this._opt.pkgPath, "src/main.ts");
|
|
45
|
-
this._tsConfigFilePath = path.resolve(this._opt.pkgPath, "tsconfig.json");
|
|
46
|
-
this._swConfFilePath = path.resolve(this._opt.pkgPath, "ngsw-config.json");
|
|
47
|
-
this._browserTarget = transformSupportedBrowsersToTargets(browserslist("defaults and fully supports es6-module"));
|
|
48
|
-
this._indexHtmlFilePath = path.resolve(this._opt.pkgPath, "src/index.html");
|
|
49
|
-
this._pkgName = path.basename(this._opt.pkgPath);
|
|
50
|
-
this._baseHref = this._opt.builderType === "web" ? `/${this._pkgName}/` : this._opt.dev ? `/${this._pkgName}/${this._opt.builderType}/` : ``;
|
|
45
|
+
constructor(opt) {
|
|
46
|
+
this.#opt = opt;
|
|
47
|
+
this.#pkgNpmConf = FsUtil.readJson(path.resolve(opt.pkgPath, "package.json"));
|
|
48
|
+
this.#mainFilePath = path.resolve(opt.pkgPath, "src/main.ts");
|
|
49
|
+
this.#tsConfigFilePath = path.resolve(opt.pkgPath, "tsconfig.json");
|
|
50
|
+
this.#swConfFilePath = path.resolve(opt.pkgPath, "ngsw-config.json");
|
|
51
|
+
this.#browserTarget = transformSupportedBrowsersToTargets(browserslist("defaults and fully supports es6-module"));
|
|
52
|
+
this.#indexHtmlFilePath = path.resolve(opt.pkgPath, "src/index.html");
|
|
53
|
+
this.#pkgName = path.basename(opt.pkgPath);
|
|
54
|
+
this.#baseHref = opt.builderType === "web" ? `/${this.#pkgName}/` : opt.dev ? `/${this.#pkgName}/${opt.builderType}/` : ``;
|
|
51
55
|
}
|
|
52
56
|
markForChanges(filePaths) {
|
|
53
57
|
for (const filePath of filePaths) {
|
|
@@ -58,17 +62,17 @@ export class SdNgBundler {
|
|
|
58
62
|
}
|
|
59
63
|
async bundleAsync() {
|
|
60
64
|
const logger = Logger.get(["simplysm", "sd-cli", "SdNgBundler", "bundleAsync"]);
|
|
61
|
-
if (!this
|
|
62
|
-
this
|
|
65
|
+
if (!this.#contexts) {
|
|
66
|
+
this.#contexts = [
|
|
63
67
|
await this._getAppContextAsync(),
|
|
64
68
|
this._getStyleContext(),
|
|
65
|
-
...this.
|
|
69
|
+
...this.#opt.builderType === "electron" ? [
|
|
66
70
|
this._getElectronMainContext()
|
|
67
71
|
] : []
|
|
68
72
|
];
|
|
69
73
|
}
|
|
70
74
|
//-- build
|
|
71
|
-
const bundlingResults = await this.
|
|
75
|
+
const bundlingResults = await this.#contexts.mapAsync(async (ctx) => await ctx.bundleAsync());
|
|
72
76
|
//-- results
|
|
73
77
|
const results = bundlingResults.mapMany(bundlingResult => bundlingResult.results);
|
|
74
78
|
//-- executionResult
|
|
@@ -85,7 +89,7 @@ export class SdNgBundler {
|
|
|
85
89
|
}
|
|
86
90
|
const assetFiles = [];
|
|
87
91
|
//-- cordova empty
|
|
88
|
-
if (this.
|
|
92
|
+
if (this.#opt.builderType === "cordova" && this.#opt.cordovaConfig?.plugins) {
|
|
89
93
|
outputFiles.push(createOutputFileFromText("cordova-empty.js", "export default {};", BuildOutputFileType.Root));
|
|
90
94
|
}
|
|
91
95
|
//-- index
|
|
@@ -116,11 +120,11 @@ export class SdNgBundler {
|
|
|
116
120
|
//-- copy assets
|
|
117
121
|
assetFiles.push(...(await this._copyAssetsAsync()));
|
|
118
122
|
//-- extract 3rdpartylicenses
|
|
119
|
-
if (!this.
|
|
120
|
-
outputFiles.push(createOutputFileFromText('3rdpartylicenses.txt', await extractLicenses(metafile, this.
|
|
123
|
+
if (!this.#opt.dev) {
|
|
124
|
+
outputFiles.push(createOutputFileFromText('3rdpartylicenses.txt', await extractLicenses(metafile, this.#opt.pkgPath), BuildOutputFileType.Root));
|
|
121
125
|
}
|
|
122
126
|
//-- service worker
|
|
123
|
-
if (FsUtil.exists(this
|
|
127
|
+
if (FsUtil.exists(this.#swConfFilePath)) {
|
|
124
128
|
try {
|
|
125
129
|
const serviceWorkerResult = await this._genServiceWorkerAsync(outputFiles, assetFiles);
|
|
126
130
|
outputFiles.push(createOutputFileFromText('ngsw.json', serviceWorkerResult.manifest, BuildOutputFileType.Root));
|
|
@@ -140,22 +144,22 @@ export class SdNgBundler {
|
|
|
140
144
|
}
|
|
141
145
|
//-- write
|
|
142
146
|
for (const outputFile of outputFiles) {
|
|
143
|
-
const distFilePath = path.resolve(this.
|
|
144
|
-
const prev = this.
|
|
147
|
+
const distFilePath = path.resolve(this.#opt.outputPath, outputFile.path);
|
|
148
|
+
const prev = this.#outputCache.get(distFilePath);
|
|
145
149
|
if (prev !== Buffer.from(outputFile.contents).toString("base64")) {
|
|
146
150
|
await FsUtil.writeFileAsync(distFilePath, outputFile.contents);
|
|
147
|
-
this.
|
|
151
|
+
this.#outputCache.set(distFilePath, Buffer.from(outputFile.contents).toString("base64"));
|
|
148
152
|
}
|
|
149
153
|
}
|
|
150
154
|
for (const assetFile of assetFiles) {
|
|
151
|
-
const prev = this.
|
|
155
|
+
const prev = this.#outputCache.get(assetFile.source);
|
|
152
156
|
const curr = FsUtil.lstat(assetFile.source).mtime.getTime();
|
|
153
157
|
if (prev !== curr) {
|
|
154
|
-
await FsUtil.copyAsync(assetFile.source, path.resolve(this.
|
|
155
|
-
this.
|
|
158
|
+
await FsUtil.copyAsync(assetFile.source, path.resolve(this.#opt.outputPath, assetFile.destination));
|
|
159
|
+
this.#outputCache.set(assetFile.source, curr);
|
|
156
160
|
}
|
|
157
161
|
}
|
|
158
|
-
logger.debug(`[${path.basename(this.
|
|
162
|
+
logger.debug(`[${path.basename(this.#opt.pkgPath)}] 번들링중 영향받은 파일`, Array.from(this.#ngResultCache.affectedFileSet));
|
|
159
163
|
return {
|
|
160
164
|
program: this.#ngResultCache.program,
|
|
161
165
|
watchFileSet: new Set([
|
|
@@ -176,22 +180,22 @@ export class SdNgBundler {
|
|
|
176
180
|
throw new Error(`Output file does not exist: ${relFilePath}`);
|
|
177
181
|
};
|
|
178
182
|
const indexHtmlGenerator = new IndexHtmlGenerator({
|
|
179
|
-
indexPath: this
|
|
183
|
+
indexPath: this.#indexHtmlFilePath,
|
|
180
184
|
entrypoints: [
|
|
181
185
|
['runtime', true],
|
|
182
186
|
['polyfills', true],
|
|
183
187
|
['styles', false],
|
|
184
188
|
['vendor', true],
|
|
185
189
|
['main', true],
|
|
186
|
-
...this.
|
|
190
|
+
...this.#opt.builderType === "cordova" ? [
|
|
187
191
|
["cordova-entry", true]
|
|
188
192
|
] : []
|
|
189
193
|
],
|
|
190
194
|
optimization: {
|
|
191
|
-
scripts: !this.
|
|
192
|
-
fonts: { inline: !this.
|
|
195
|
+
scripts: !this.#opt.dev,
|
|
196
|
+
fonts: { inline: !this.#opt.dev },
|
|
193
197
|
styles: {
|
|
194
|
-
minify: !this.
|
|
198
|
+
minify: !this.#opt.dev,
|
|
195
199
|
inlineCritical: false
|
|
196
200
|
},
|
|
197
201
|
},
|
|
@@ -199,7 +203,7 @@ export class SdNgBundler {
|
|
|
199
203
|
});
|
|
200
204
|
indexHtmlGenerator.readAsset = readAsset;
|
|
201
205
|
const hints = [];
|
|
202
|
-
if (!this.
|
|
206
|
+
if (!this.#opt.dev) {
|
|
203
207
|
for (const [key, value] of initialFiles) {
|
|
204
208
|
if (value.entrypoint) {
|
|
205
209
|
continue;
|
|
@@ -213,7 +217,7 @@ export class SdNgBundler {
|
|
|
213
217
|
}
|
|
214
218
|
}
|
|
215
219
|
const transformResult = await indexHtmlGenerator.process({
|
|
216
|
-
baseHref: this
|
|
220
|
+
baseHref: this.#baseHref,
|
|
217
221
|
lang: undefined,
|
|
218
222
|
outputPath: "/",
|
|
219
223
|
files: [...initialFiles].map(([file, record]) => ({
|
|
@@ -223,7 +227,7 @@ export class SdNgBundler {
|
|
|
223
227
|
})),
|
|
224
228
|
hints,
|
|
225
229
|
});
|
|
226
|
-
if (this.
|
|
230
|
+
if (this.#opt.dev) {
|
|
227
231
|
return transformResult;
|
|
228
232
|
}
|
|
229
233
|
else {
|
|
@@ -244,7 +248,7 @@ export class SdNgBundler {
|
|
|
244
248
|
{ input: 'src', glob: 'favicon.ico', output: '' },
|
|
245
249
|
{ input: 'src', glob: 'manifest.webmanifest', output: '' },
|
|
246
250
|
{ input: 'src/assets', glob: '**/*', output: 'assets' },
|
|
247
|
-
...this.
|
|
251
|
+
...this.#opt.dev && this.#opt.builderType === "cordova" ? Object.keys(this.#opt.cordovaConfig?.platform ?? { browser: {} }).mapMany((platform) => [
|
|
248
252
|
{
|
|
249
253
|
input: `.cordova/platforms/${platform}/platform_www/plugins`,
|
|
250
254
|
glob: '**/*',
|
|
@@ -266,14 +270,14 @@ export class SdNgBundler {
|
|
|
266
270
|
output: `cordova-${platform}`
|
|
267
271
|
},
|
|
268
272
|
]) : []
|
|
269
|
-
], [], this.
|
|
273
|
+
], [], this.#opt.pkgPath);
|
|
270
274
|
}
|
|
271
275
|
async _genServiceWorkerAsync(outputFiles, assetFiles) {
|
|
272
|
-
return await augmentAppWithServiceWorkerEsbuild(this.
|
|
276
|
+
return await augmentAppWithServiceWorkerEsbuild(this.#opt.pkgPath, this.#swConfFilePath, this.#baseHref, "index.html", outputFiles, assetFiles);
|
|
273
277
|
}
|
|
274
278
|
async _getAppContextAsync() {
|
|
275
|
-
return new SdNgBundlerContext(this.
|
|
276
|
-
absWorkingDir: this.
|
|
279
|
+
return new SdNgBundlerContext(this.#opt.pkgPath, {
|
|
280
|
+
absWorkingDir: this.#opt.pkgPath,
|
|
277
281
|
bundle: true,
|
|
278
282
|
keepNames: true,
|
|
279
283
|
format: 'esm',
|
|
@@ -281,42 +285,42 @@ export class SdNgBundler {
|
|
|
281
285
|
conditions: ['es2020', 'es2015', 'module'],
|
|
282
286
|
resolveExtensions: ['.ts', '.tsx', '.mjs', '.js'],
|
|
283
287
|
metafile: true,
|
|
284
|
-
legalComments: this.
|
|
288
|
+
legalComments: this.#opt.dev ? 'eof' : 'none',
|
|
285
289
|
logLevel: 'silent',
|
|
286
|
-
minifyIdentifiers: !this.
|
|
287
|
-
minifySyntax: !this.
|
|
288
|
-
minifyWhitespace: !this.
|
|
290
|
+
minifyIdentifiers: !this.#opt.dev,
|
|
291
|
+
minifySyntax: !this.#opt.dev,
|
|
292
|
+
minifyWhitespace: !this.#opt.dev,
|
|
289
293
|
pure: ['forwardRef'],
|
|
290
|
-
outdir: this.
|
|
294
|
+
outdir: this.#opt.pkgPath,
|
|
291
295
|
outExtension: undefined,
|
|
292
|
-
sourcemap: true, //this.
|
|
296
|
+
sourcemap: true, //this.#opt.dev,
|
|
293
297
|
splitting: true,
|
|
294
298
|
chunkNames: 'chunk-[hash]',
|
|
295
|
-
tsconfig: this
|
|
299
|
+
tsconfig: this.#tsConfigFilePath,
|
|
296
300
|
write: false,
|
|
297
301
|
preserveSymlinks: false,
|
|
298
302
|
define: {
|
|
299
|
-
...!this.
|
|
303
|
+
...!this.#opt.dev ? { ngDevMode: 'false' } : {},
|
|
300
304
|
ngJitMode: 'false',
|
|
301
305
|
global: 'global',
|
|
302
306
|
process: 'process',
|
|
303
307
|
Buffer: 'Buffer',
|
|
304
|
-
'process.env.SD_VERSION': JSON.stringify(this.
|
|
305
|
-
"process.env.NODE_ENV": JSON.stringify(this.
|
|
306
|
-
...this.
|
|
308
|
+
'process.env.SD_VERSION': JSON.stringify(this.#pkgNpmConf.version),
|
|
309
|
+
"process.env.NODE_ENV": JSON.stringify(this.#opt.dev ? "development" : "production"),
|
|
310
|
+
...this.#opt.env ? Object.keys(this.#opt.env).toObject(key => `process.env.${key}`, key => JSON.stringify(this.#opt.env[key])) : {}
|
|
307
311
|
},
|
|
308
312
|
platform: 'browser',
|
|
309
313
|
mainFields: ['es2020', 'es2015', 'browser', 'module', 'main'],
|
|
310
314
|
entryNames: '[name]',
|
|
311
315
|
entryPoints: {
|
|
312
|
-
main: this
|
|
316
|
+
main: this.#mainFilePath,
|
|
313
317
|
// polyfills: 'angular:polyfills',
|
|
314
|
-
polyfills: path.resolve(this.
|
|
315
|
-
...this.
|
|
318
|
+
polyfills: path.resolve(this.#opt.pkgPath, "src/polyfills.ts"),
|
|
319
|
+
...this.#opt.builderType === "cordova" ? {
|
|
316
320
|
"cordova-entry": path.resolve(path.dirname(fileURLToPath(import.meta.url)), `../../lib/cordova-entry.js`)
|
|
317
321
|
} : {}
|
|
318
322
|
},
|
|
319
|
-
target: this
|
|
323
|
+
target: this.#browserTarget,
|
|
320
324
|
supported: { 'async-await': false, 'object-rest-spread': false },
|
|
321
325
|
loader: {
|
|
322
326
|
".png": "file",
|
|
@@ -344,10 +348,10 @@ export class SdNgBundler {
|
|
|
344
348
|
},
|
|
345
349
|
inject: [PathUtil.posix(fileURLToPath(await import.meta.resolve("node-stdlib-browser/helpers/esbuild/shim")))],
|
|
346
350
|
plugins: [
|
|
347
|
-
...this.
|
|
351
|
+
...this.#opt.builderType === "cordova" && this.#opt.cordovaConfig?.plugins ? [{
|
|
348
352
|
name: "cordova:plugin-empty",
|
|
349
353
|
setup: ({ onResolve }) => {
|
|
350
|
-
onResolve({ filter: new RegExp("(" + this.
|
|
354
|
+
onResolve({ filter: new RegExp("(" + this.#opt.cordovaConfig.plugins.join("|") + ")") }, () => {
|
|
351
355
|
return {
|
|
352
356
|
path: `./cordova-empty.js`,
|
|
353
357
|
external: true
|
|
@@ -360,18 +364,18 @@ export class SdNgBundler {
|
|
|
360
364
|
// loadContent: () => ({
|
|
361
365
|
// contents: `import "./src/polyfills.ts";`,
|
|
362
366
|
// loader: 'js',
|
|
363
|
-
// resolveDir: this.
|
|
367
|
+
// resolveDir: this.#opt.pkgPath
|
|
364
368
|
// })
|
|
365
369
|
// }) as esbuild.Plugin,
|
|
366
370
|
createSourcemapIgnorelistPlugin(),
|
|
367
371
|
sdNgPlugin({
|
|
368
372
|
modifiedFileSet: this.#modifiedFileSet,
|
|
369
|
-
dev: this.
|
|
370
|
-
pkgPath: this.
|
|
373
|
+
dev: this.#opt.dev,
|
|
374
|
+
pkgPath: this.#opt.pkgPath,
|
|
371
375
|
result: this.#ngResultCache
|
|
372
376
|
}),
|
|
373
377
|
// createCompilerPlugin({
|
|
374
|
-
// sourcemap: this.
|
|
378
|
+
// sourcemap: this.#opt.dev,
|
|
375
379
|
// tsconfig: this._tsConfigFilePath,
|
|
376
380
|
// jit: false,
|
|
377
381
|
// advancedOptimizations: true,
|
|
@@ -379,11 +383,11 @@ export class SdNgBundler {
|
|
|
379
383
|
// fileReplacements: undefined,
|
|
380
384
|
// sourceFileCache: this._sourceFileCache,
|
|
381
385
|
// loadResultCache: this._sourceFileCache.loadResultCache,
|
|
382
|
-
// incremental: this.
|
|
386
|
+
// incremental: this.#opt.dev
|
|
383
387
|
// }, {
|
|
384
|
-
// workspaceRoot: this.
|
|
385
|
-
// optimization: !this.
|
|
386
|
-
// sourcemap: this.
|
|
388
|
+
// workspaceRoot: this.#opt.pkgPath,
|
|
389
|
+
// optimization: !this.#opt.dev,
|
|
390
|
+
// sourcemap: this.#opt.dev ? 'inline' : false,
|
|
387
391
|
// outputNames: {bundles: '[name]', media: 'media/[name]'},
|
|
388
392
|
// includePaths: [],
|
|
389
393
|
// externalDependencies: [],
|
|
@@ -407,30 +411,30 @@ export class SdNgBundler {
|
|
|
407
411
|
}
|
|
408
412
|
_getStyleContext() {
|
|
409
413
|
const pluginFactory = new StylesheetPluginFactory({
|
|
410
|
-
sourcemap: true, //this.
|
|
414
|
+
sourcemap: true, //this.#opt.dev,
|
|
411
415
|
includePaths: []
|
|
412
416
|
}, this.#styleLoadResultCache);
|
|
413
|
-
return new SdNgBundlerContext(this.
|
|
414
|
-
absWorkingDir: this.
|
|
417
|
+
return new SdNgBundlerContext(this.#opt.pkgPath, {
|
|
418
|
+
absWorkingDir: this.#opt.pkgPath,
|
|
415
419
|
bundle: true,
|
|
416
420
|
entryNames: '[name]',
|
|
417
421
|
assetNames: 'media/[name]',
|
|
418
422
|
logLevel: 'silent',
|
|
419
|
-
minify: !this.
|
|
423
|
+
minify: !this.#opt.dev,
|
|
420
424
|
metafile: true,
|
|
421
|
-
sourcemap: true, //this.
|
|
422
|
-
outdir: this.
|
|
425
|
+
sourcemap: true, //this.#opt.dev,
|
|
426
|
+
outdir: this.#opt.pkgPath,
|
|
423
427
|
write: false,
|
|
424
428
|
platform: 'browser',
|
|
425
|
-
target: this
|
|
429
|
+
target: this.#browserTarget,
|
|
426
430
|
preserveSymlinks: false,
|
|
427
431
|
external: [],
|
|
428
432
|
conditions: ['style', 'sass'],
|
|
429
433
|
mainFields: ['style', 'sass'],
|
|
430
|
-
legalComments: !this.
|
|
434
|
+
legalComments: !this.#opt.dev ? "none" : "eof",
|
|
431
435
|
entryPoints: {
|
|
432
436
|
// styles: 'angular:styles/global;styles'
|
|
433
|
-
styles: path.resolve(this.
|
|
437
|
+
styles: path.resolve(this.#opt.pkgPath, "src/styles.scss")
|
|
434
438
|
},
|
|
435
439
|
plugins: [
|
|
436
440
|
// createVirtualModulePlugin({
|
|
@@ -439,7 +443,7 @@ export class SdNgBundler {
|
|
|
439
443
|
// loadContent: () => ({
|
|
440
444
|
// contents: `@import 'src/styles.scss';`,
|
|
441
445
|
// loader: 'css',
|
|
442
|
-
// resolveDir: this.
|
|
446
|
+
// resolveDir: this.#opt.pkgPath
|
|
443
447
|
// }),
|
|
444
448
|
// }) as esbuild.Plugin,
|
|
445
449
|
pluginFactory.create(SassStylesheetLanguage),
|
|
@@ -449,32 +453,32 @@ export class SdNgBundler {
|
|
|
449
453
|
});
|
|
450
454
|
}
|
|
451
455
|
_getElectronMainContext() {
|
|
452
|
-
return new SdNgBundlerContext(this.
|
|
453
|
-
absWorkingDir: this.
|
|
456
|
+
return new SdNgBundlerContext(this.#opt.pkgPath, {
|
|
457
|
+
absWorkingDir: this.#opt.pkgPath,
|
|
454
458
|
bundle: true,
|
|
455
459
|
entryNames: '[name]',
|
|
456
460
|
assetNames: 'media/[name]',
|
|
457
461
|
conditions: ['es2020', 'es2015', 'module'],
|
|
458
462
|
resolveExtensions: ['.ts', '.tsx', '.mjs', '.js'],
|
|
459
463
|
metafile: true,
|
|
460
|
-
legalComments: this.
|
|
464
|
+
legalComments: this.#opt.dev ? 'eof' : 'none',
|
|
461
465
|
logLevel: 'silent',
|
|
462
|
-
minify: !this.
|
|
463
|
-
outdir: this.
|
|
464
|
-
sourcemap: true, //this.
|
|
465
|
-
tsconfig: this
|
|
466
|
+
minify: !this.#opt.dev,
|
|
467
|
+
outdir: this.#opt.pkgPath,
|
|
468
|
+
sourcemap: true, //this.#opt.dev,
|
|
469
|
+
tsconfig: this.#tsConfigFilePath,
|
|
466
470
|
write: false,
|
|
467
471
|
preserveSymlinks: false,
|
|
468
472
|
external: ["electron"],
|
|
469
473
|
define: {
|
|
470
|
-
...!this.
|
|
471
|
-
'process.env.SD_VERSION': JSON.stringify(this.
|
|
472
|
-
"process.env.NODE_ENV": JSON.stringify(this.
|
|
473
|
-
...this.
|
|
474
|
+
...!this.#opt.dev ? { ngDevMode: 'false' } : {},
|
|
475
|
+
'process.env.SD_VERSION': JSON.stringify(this.#pkgNpmConf.version),
|
|
476
|
+
"process.env.NODE_ENV": JSON.stringify(this.#opt.dev ? "development" : "production"),
|
|
477
|
+
...this.#opt.env ? Object.keys(this.#opt.env).toObject(key => `process.env.${key}`, key => JSON.stringify(this.#opt.env[key])) : {}
|
|
474
478
|
},
|
|
475
479
|
platform: 'node',
|
|
476
480
|
entryPoints: {
|
|
477
|
-
"electron-main": path.resolve(this.
|
|
481
|
+
"electron-main": path.resolve(this.#opt.pkgPath, "src/electron-main.ts"),
|
|
478
482
|
}
|
|
479
483
|
});
|
|
480
484
|
}
|