@simplysm/sd-cli 11.1.46 → 11.1.52
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/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 +115 -104
- package/dist/build-tools/SdNgBundler.js.map +1 -1
- package/dist/build-tools/SdNgBundlerContext.d.ts +1 -0
- package/dist/build-tools/SdNgBundlerContext.js +11 -3
- package/dist/build-tools/SdNgBundlerContext.js.map +1 -1
- package/dist/build-tools/SdTsCompiler.d.ts +23 -10
- package/dist/build-tools/SdTsCompiler.js +262 -221
- package/dist/build-tools/SdTsCompiler.js.map +1 -1
- package/dist/build-tools/SdTsLibBundler.d.ts +13 -0
- package/dist/build-tools/SdTsLibBundler.js +51 -0
- package/dist/build-tools/SdTsLibBundler.js.map +1 -0
- 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 +4 -1
- package/dist/entry/SdCliProject.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +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/SdLinter.ts +4 -4
- package/src/build-tools/SdNgBundler.ts +133 -114
- package/src/build-tools/SdNgBundlerContext.ts +14 -3
- package/src/build-tools/SdTsCompiler.ts +375 -214
- package/src/build-tools/SdTsLibBundler.ts +70 -0
- 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 +4 -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
|
@@ -42,48 +42,46 @@ import {MemoryLoadResultCache} from "@angular-devkit/build-angular/src/tools/esb
|
|
|
42
42
|
import ts from "typescript";
|
|
43
43
|
|
|
44
44
|
export class SdNgBundler {
|
|
45
|
+
readonly #logger = Logger.get(["simplysm", "sd-cli", "SdNgBundler"]);
|
|
46
|
+
|
|
45
47
|
// private readonly _sourceFileCache = new SourceFileCache(
|
|
46
|
-
// path.resolve(this.
|
|
48
|
+
// path.resolve(this.#opt.pkgPath, ".cache")
|
|
47
49
|
// );
|
|
48
50
|
|
|
49
|
-
#modifiedFileSet = new Set<string>();
|
|
50
|
-
#ngResultCache: INgPluginResultCache = {
|
|
51
|
+
readonly #modifiedFileSet = new Set<string>();
|
|
52
|
+
readonly #ngResultCache: INgPluginResultCache = {
|
|
51
53
|
affectedFileSet: new Set<string>(),
|
|
52
54
|
watchFileSet: new Set<string>()
|
|
53
55
|
};
|
|
54
|
-
#styleLoadResultCache = new MemoryLoadResultCache();
|
|
56
|
+
readonly #styleLoadResultCache = new MemoryLoadResultCache();
|
|
57
|
+
|
|
58
|
+
#contexts: SdNgBundlerContext[] | undefined;
|
|
55
59
|
|
|
56
|
-
|
|
60
|
+
readonly #outputCache = new Map<string, string | number>();
|
|
57
61
|
|
|
58
|
-
|
|
62
|
+
readonly #opt: IOptions;
|
|
59
63
|
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
64
|
+
readonly #pkgNpmConf: INpmConfig;
|
|
65
|
+
readonly #mainFilePath: string;
|
|
66
|
+
readonly #tsConfigFilePath: string;
|
|
67
|
+
readonly #swConfFilePath: string;
|
|
68
|
+
readonly #browserTarget: string[];
|
|
69
|
+
readonly #indexHtmlFilePath: string;
|
|
70
|
+
readonly #pkgName: string;
|
|
71
|
+
readonly #baseHref: string;
|
|
68
72
|
|
|
69
73
|
// #loadFilePathSet = new Set<string>();
|
|
70
74
|
|
|
71
|
-
public constructor(
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
pkgPath
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
this
|
|
80
|
-
this
|
|
81
|
-
this._tsConfigFilePath = path.resolve(this._opt.pkgPath, "tsconfig.json");
|
|
82
|
-
this._swConfFilePath = path.resolve(this._opt.pkgPath, "ngsw-config.json");
|
|
83
|
-
this._browserTarget = transformSupportedBrowsersToTargets(browserslist("defaults and fully supports es6-module"));
|
|
84
|
-
this._indexHtmlFilePath = path.resolve(this._opt.pkgPath, "src/index.html");
|
|
85
|
-
this._pkgName = path.basename(this._opt.pkgPath);
|
|
86
|
-
this._baseHref = this._opt.builderType === "web" ? `/${this._pkgName}/` : this._opt.dev ? `/${this._pkgName}/${this._opt.builderType}/` : ``;
|
|
75
|
+
public constructor(opt: IOptions) {
|
|
76
|
+
this.#opt = opt;
|
|
77
|
+
this.#pkgNpmConf = FsUtil.readJson(path.resolve(opt.pkgPath, "package.json"));
|
|
78
|
+
this.#mainFilePath = path.resolve(opt.pkgPath, "src/main.ts");
|
|
79
|
+
this.#tsConfigFilePath = path.resolve(opt.pkgPath, "tsconfig.json");
|
|
80
|
+
this.#swConfFilePath = path.resolve(opt.pkgPath, "ngsw-config.json");
|
|
81
|
+
this.#browserTarget = transformSupportedBrowsersToTargets(browserslist("defaults and fully supports es6-module"));
|
|
82
|
+
this.#indexHtmlFilePath = path.resolve(opt.pkgPath, "src/index.html");
|
|
83
|
+
this.#pkgName = path.basename(opt.pkgPath);
|
|
84
|
+
this.#baseHref = opt.builderType === "web" ? `/${this.#pkgName}/` : opt.dev ? `/${this.#pkgName}/${opt.builderType}/` : ``;
|
|
87
85
|
}
|
|
88
86
|
|
|
89
87
|
public markForChanges(filePaths: string[]): void {
|
|
@@ -100,25 +98,27 @@ export class SdNgBundler {
|
|
|
100
98
|
affectedFileSet: Set<string>,
|
|
101
99
|
results: ISdCliPackageBuildResult[]
|
|
102
100
|
}> {
|
|
103
|
-
|
|
101
|
+
this.#debug(`get contexts...`);
|
|
104
102
|
|
|
105
|
-
if (!this
|
|
106
|
-
this
|
|
103
|
+
if (!this.#contexts) {
|
|
104
|
+
this.#contexts = [
|
|
107
105
|
await this._getAppContextAsync(),
|
|
108
106
|
this._getStyleContext(),
|
|
109
|
-
...this.
|
|
107
|
+
...this.#opt.builderType === "electron" ? [
|
|
110
108
|
this._getElectronMainContext()
|
|
111
109
|
] : []
|
|
112
110
|
];
|
|
113
111
|
}
|
|
114
112
|
|
|
115
|
-
|
|
116
|
-
|
|
113
|
+
this.#debug(`build...`);
|
|
114
|
+
|
|
115
|
+
const bundlingResults = await this.#contexts.mapAsync(async (ctx, i) => await ctx.bundleAsync());
|
|
117
116
|
|
|
118
117
|
//-- results
|
|
119
118
|
const results = bundlingResults.mapMany(bundlingResult => bundlingResult.results);
|
|
120
119
|
|
|
121
|
-
|
|
120
|
+
this.#debug(`convert result...`);
|
|
121
|
+
|
|
122
122
|
const outputFiles: BuildOutputFile[] = bundlingResults.mapMany(item => item.outputFiles?.map(file => convertOutputFile(file, BuildOutputFileType.Root)) ?? []);
|
|
123
123
|
const initialFiles = new Map<string, InitialFileRecord>();
|
|
124
124
|
const metafile: {
|
|
@@ -136,11 +136,11 @@ export class SdNgBundler {
|
|
|
136
136
|
const assetFiles: { source: string; destination: string }[] = [];
|
|
137
137
|
|
|
138
138
|
//-- cordova empty
|
|
139
|
-
if (this.
|
|
139
|
+
if (this.#opt.builderType === "cordova" && this.#opt.cordovaConfig?.plugins) {
|
|
140
140
|
outputFiles.push(createOutputFileFromText("cordova-empty.js", "export default {};", BuildOutputFileType.Root));
|
|
141
141
|
}
|
|
142
142
|
|
|
143
|
-
|
|
143
|
+
this.#debug(`create index.html...`);
|
|
144
144
|
|
|
145
145
|
const genIndexHtmlResult = await this._genIndexHtmlAsync(outputFiles, initialFiles);
|
|
146
146
|
for (const warning of genIndexHtmlResult.warnings) {
|
|
@@ -171,12 +171,14 @@ export class SdNgBundler {
|
|
|
171
171
|
assetFiles.push(...(await this._copyAssetsAsync()));
|
|
172
172
|
|
|
173
173
|
//-- extract 3rdpartylicenses
|
|
174
|
-
if (!this.
|
|
175
|
-
outputFiles.push(createOutputFileFromText('3rdpartylicenses.txt', await extractLicenses(metafile, this.
|
|
174
|
+
if (!this.#opt.dev) {
|
|
175
|
+
outputFiles.push(createOutputFileFromText('3rdpartylicenses.txt', await extractLicenses(metafile, this.#opt.pkgPath), BuildOutputFileType.Root));
|
|
176
176
|
}
|
|
177
177
|
|
|
178
178
|
//-- service worker
|
|
179
|
-
if (FsUtil.exists(this
|
|
179
|
+
if (FsUtil.exists(this.#swConfFilePath)) {
|
|
180
|
+
this.#debug(`prepare service worker...`);
|
|
181
|
+
|
|
180
182
|
try {
|
|
181
183
|
const serviceWorkerResult = await this._genServiceWorkerAsync(outputFiles, assetFiles);
|
|
182
184
|
outputFiles.push(createOutputFileFromText('ngsw.json', serviceWorkerResult.manifest, BuildOutputFileType.Root));
|
|
@@ -196,24 +198,26 @@ export class SdNgBundler {
|
|
|
196
198
|
}
|
|
197
199
|
|
|
198
200
|
//-- write
|
|
201
|
+
this.#debug(`write output files...(${outputFiles.length})`);
|
|
202
|
+
|
|
199
203
|
for (const outputFile of outputFiles) {
|
|
200
|
-
const distFilePath = path.resolve(this.
|
|
201
|
-
const prev = this.
|
|
204
|
+
const distFilePath = path.resolve(this.#opt.outputPath, outputFile.path);
|
|
205
|
+
const prev = this.#outputCache.get(distFilePath);
|
|
202
206
|
if (prev !== Buffer.from(outputFile.contents).toString("base64")) {
|
|
203
207
|
await FsUtil.writeFileAsync(distFilePath, outputFile.contents);
|
|
204
|
-
this.
|
|
208
|
+
this.#outputCache.set(distFilePath, Buffer.from(outputFile.contents).toString("base64"));
|
|
205
209
|
}
|
|
206
210
|
}
|
|
207
211
|
for (const assetFile of assetFiles) {
|
|
208
|
-
const prev = this.
|
|
212
|
+
const prev = this.#outputCache.get(assetFile.source);
|
|
209
213
|
const curr = FsUtil.lstat(assetFile.source).mtime.getTime();
|
|
210
214
|
if (prev !== curr) {
|
|
211
|
-
await FsUtil.copyAsync(assetFile.source, path.resolve(this.
|
|
212
|
-
this.
|
|
215
|
+
await FsUtil.copyAsync(assetFile.source, path.resolve(this.#opt.outputPath, assetFile.destination));
|
|
216
|
+
this.#outputCache.set(assetFile.source, curr);
|
|
213
217
|
}
|
|
214
218
|
}
|
|
215
219
|
|
|
216
|
-
|
|
220
|
+
this.#debug(`번들링중 영향받은 파일`, Array.from(this.#ngResultCache.affectedFileSet!));
|
|
217
221
|
|
|
218
222
|
return {
|
|
219
223
|
program: this.#ngResultCache.program,
|
|
@@ -241,22 +245,22 @@ export class SdNgBundler {
|
|
|
241
245
|
};
|
|
242
246
|
|
|
243
247
|
const indexHtmlGenerator = new IndexHtmlGenerator({
|
|
244
|
-
indexPath: this
|
|
248
|
+
indexPath: this.#indexHtmlFilePath,
|
|
245
249
|
entrypoints: [
|
|
246
250
|
['runtime', true],
|
|
247
251
|
['polyfills', true],
|
|
248
252
|
['styles', false],
|
|
249
253
|
['vendor', true],
|
|
250
254
|
['main', true],
|
|
251
|
-
...this.
|
|
255
|
+
...this.#opt.builderType === "cordova" ? [
|
|
252
256
|
["cordova-entry", true] as Entrypoint
|
|
253
257
|
] : []
|
|
254
258
|
],
|
|
255
259
|
optimization: {
|
|
256
|
-
scripts: !this.
|
|
257
|
-
fonts: {inline: !this.
|
|
260
|
+
scripts: !this.#opt.dev,
|
|
261
|
+
fonts: {inline: !this.#opt.dev},
|
|
258
262
|
styles: {
|
|
259
|
-
minify: !this.
|
|
263
|
+
minify: !this.#opt.dev,
|
|
260
264
|
inlineCritical: false
|
|
261
265
|
},
|
|
262
266
|
},
|
|
@@ -265,7 +269,7 @@ export class SdNgBundler {
|
|
|
265
269
|
indexHtmlGenerator.readAsset = readAsset;
|
|
266
270
|
|
|
267
271
|
const hints: { url: string; mode: HintMode; as?: string; }[] = [];
|
|
268
|
-
if (!this.
|
|
272
|
+
if (!this.#opt.dev) {
|
|
269
273
|
for (const [key, value] of initialFiles) {
|
|
270
274
|
if (value.entrypoint) {
|
|
271
275
|
continue;
|
|
@@ -274,6 +278,7 @@ export class SdNgBundler {
|
|
|
274
278
|
if (value.type === 'script') {
|
|
275
279
|
hints.push({url: key, mode: 'modulepreload' as const});
|
|
276
280
|
}
|
|
281
|
+
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
|
277
282
|
else if (value.type === 'style') {
|
|
278
283
|
hints.push({url: key, mode: 'preload' as const, as: 'style'});
|
|
279
284
|
}
|
|
@@ -281,7 +286,7 @@ export class SdNgBundler {
|
|
|
281
286
|
}
|
|
282
287
|
|
|
283
288
|
const transformResult = await indexHtmlGenerator.process({
|
|
284
|
-
baseHref: this
|
|
289
|
+
baseHref: this.#baseHref,
|
|
285
290
|
lang: undefined,
|
|
286
291
|
outputPath: "/",
|
|
287
292
|
files: [...initialFiles].map(([file, record]) => ({
|
|
@@ -292,7 +297,7 @@ export class SdNgBundler {
|
|
|
292
297
|
hints,
|
|
293
298
|
});
|
|
294
299
|
|
|
295
|
-
if (this.
|
|
300
|
+
if (this.#opt.dev) {
|
|
296
301
|
return transformResult;
|
|
297
302
|
}
|
|
298
303
|
else {
|
|
@@ -321,7 +326,7 @@ export class SdNgBundler {
|
|
|
321
326
|
{input: 'src', glob: 'favicon.ico', output: ''},
|
|
322
327
|
{input: 'src', glob: 'manifest.webmanifest', output: ''},
|
|
323
328
|
{input: 'src/assets', glob: '**/*', output: 'assets'},
|
|
324
|
-
...this.
|
|
329
|
+
...this.#opt.dev && this.#opt.builderType === "cordova" ? Object.keys(this.#opt.cordovaConfig?.platform ?? {browser: {}}).mapMany((platform) => [
|
|
325
330
|
{
|
|
326
331
|
input: `.cordova/platforms/${platform}/platform_www/plugins`,
|
|
327
332
|
glob: '**/*',
|
|
@@ -343,7 +348,7 @@ export class SdNgBundler {
|
|
|
343
348
|
output: `cordova-${platform}`
|
|
344
349
|
},
|
|
345
350
|
]) : []
|
|
346
|
-
], [], this.
|
|
351
|
+
], [], this.#opt.pkgPath);
|
|
347
352
|
}
|
|
348
353
|
|
|
349
354
|
private async _genServiceWorkerAsync(
|
|
@@ -360,9 +365,9 @@ export class SdNgBundler {
|
|
|
360
365
|
}[];
|
|
361
366
|
}> {
|
|
362
367
|
return await augmentAppWithServiceWorkerEsbuild(
|
|
363
|
-
this.
|
|
364
|
-
this
|
|
365
|
-
this
|
|
368
|
+
this.#opt.pkgPath,
|
|
369
|
+
this.#swConfFilePath,
|
|
370
|
+
this.#baseHref,
|
|
366
371
|
"index.html",
|
|
367
372
|
outputFiles,
|
|
368
373
|
assetFiles
|
|
@@ -370,8 +375,8 @@ export class SdNgBundler {
|
|
|
370
375
|
}
|
|
371
376
|
|
|
372
377
|
private async _getAppContextAsync(): Promise<SdNgBundlerContext> {
|
|
373
|
-
return new SdNgBundlerContext(this.
|
|
374
|
-
absWorkingDir: this.
|
|
378
|
+
return new SdNgBundlerContext(this.#opt.pkgPath, {
|
|
379
|
+
absWorkingDir: this.#opt.pkgPath,
|
|
375
380
|
bundle: true,
|
|
376
381
|
keepNames: true,
|
|
377
382
|
format: 'esm',
|
|
@@ -379,45 +384,45 @@ export class SdNgBundler {
|
|
|
379
384
|
conditions: ['es2020', 'es2015', 'module'],
|
|
380
385
|
resolveExtensions: ['.ts', '.tsx', '.mjs', '.js'],
|
|
381
386
|
metafile: true,
|
|
382
|
-
legalComments: this.
|
|
387
|
+
legalComments: this.#opt.dev ? 'eof' : 'none',
|
|
383
388
|
logLevel: 'silent',
|
|
384
|
-
minifyIdentifiers: !this.
|
|
385
|
-
minifySyntax: !this.
|
|
386
|
-
minifyWhitespace: !this.
|
|
389
|
+
minifyIdentifiers: !this.#opt.dev,
|
|
390
|
+
minifySyntax: !this.#opt.dev,
|
|
391
|
+
minifyWhitespace: !this.#opt.dev,
|
|
387
392
|
pure: ['forwardRef'],
|
|
388
|
-
outdir: this.
|
|
393
|
+
outdir: this.#opt.pkgPath,
|
|
389
394
|
outExtension: undefined,
|
|
390
|
-
sourcemap: true, //this.
|
|
395
|
+
sourcemap: true, //this.#opt.dev,
|
|
391
396
|
splitting: true,
|
|
392
|
-
chunkNames: '
|
|
393
|
-
tsconfig: this
|
|
397
|
+
chunkNames: 'chunks/[name]-[hash]',
|
|
398
|
+
tsconfig: this.#tsConfigFilePath,
|
|
394
399
|
write: false,
|
|
395
400
|
preserveSymlinks: false,
|
|
396
401
|
define: {
|
|
397
|
-
|
|
402
|
+
ngDevMode: this.#opt.dev ? "true" : "false",
|
|
398
403
|
ngJitMode: 'false',
|
|
399
404
|
global: 'global',
|
|
400
405
|
process: 'process',
|
|
401
406
|
Buffer: 'Buffer',
|
|
402
|
-
'process.env.SD_VERSION': JSON.stringify(this.
|
|
403
|
-
"process.env.NODE_ENV": JSON.stringify(this.
|
|
404
|
-
...this.
|
|
407
|
+
'process.env.SD_VERSION': JSON.stringify(this.#pkgNpmConf.version),
|
|
408
|
+
"process.env.NODE_ENV": JSON.stringify(this.#opt.dev ? "development" : "production"),
|
|
409
|
+
...this.#opt.env ? Object.keys(this.#opt.env).toObject(
|
|
405
410
|
key => `process.env.${key}`,
|
|
406
|
-
key => JSON.stringify(this.
|
|
411
|
+
key => JSON.stringify(this.#opt.env![key])
|
|
407
412
|
) : {}
|
|
408
413
|
},
|
|
409
414
|
platform: 'browser',
|
|
410
415
|
mainFields: ['es2020', 'es2015', 'browser', 'module', 'main'],
|
|
411
416
|
entryNames: '[name]',
|
|
412
417
|
entryPoints: {
|
|
413
|
-
main: this
|
|
418
|
+
main: this.#mainFilePath,
|
|
414
419
|
// polyfills: 'angular:polyfills',
|
|
415
|
-
polyfills: path.resolve(this.
|
|
416
|
-
...this.
|
|
420
|
+
polyfills: path.resolve(this.#opt.pkgPath, "src/polyfills.ts"),
|
|
421
|
+
...this.#opt.builderType === "cordova" ? {
|
|
417
422
|
"cordova-entry": path.resolve(path.dirname(fileURLToPath(import.meta.url)), `../../lib/cordova-entry.js`)
|
|
418
423
|
} : {}
|
|
419
424
|
},
|
|
420
|
-
target: this
|
|
425
|
+
target: this.#browserTarget,
|
|
421
426
|
supported: {'async-await': false, 'object-rest-spread': false},
|
|
422
427
|
loader: {
|
|
423
428
|
".png": "file",
|
|
@@ -445,10 +450,10 @@ export class SdNgBundler {
|
|
|
445
450
|
},
|
|
446
451
|
inject: [PathUtil.posix(fileURLToPath(await import.meta.resolve!("node-stdlib-browser/helpers/esbuild/shim")))],
|
|
447
452
|
plugins: [
|
|
448
|
-
...this.
|
|
453
|
+
...this.#opt.builderType === "cordova" && this.#opt.cordovaConfig?.plugins ? [{
|
|
449
454
|
name: "cordova:plugin-empty",
|
|
450
455
|
setup: ({onResolve}) => {
|
|
451
|
-
onResolve({filter: new RegExp("(" + this.
|
|
456
|
+
onResolve({filter: new RegExp("(" + this.#opt.cordovaConfig!.plugins!.join("|") + ")")}, () => {
|
|
452
457
|
return {
|
|
453
458
|
path: `./cordova-empty.js`,
|
|
454
459
|
external: true
|
|
@@ -461,18 +466,18 @@ export class SdNgBundler {
|
|
|
461
466
|
// loadContent: () => ({
|
|
462
467
|
// contents: `import "./src/polyfills.ts";`,
|
|
463
468
|
// loader: 'js',
|
|
464
|
-
// resolveDir: this.
|
|
469
|
+
// resolveDir: this.#opt.pkgPath
|
|
465
470
|
// })
|
|
466
471
|
// }) as esbuild.Plugin,
|
|
467
472
|
createSourcemapIgnorelistPlugin(),
|
|
468
473
|
sdNgPlugin({
|
|
469
474
|
modifiedFileSet: this.#modifiedFileSet,
|
|
470
|
-
dev: this.
|
|
471
|
-
pkgPath: this.
|
|
475
|
+
dev: this.#opt.dev,
|
|
476
|
+
pkgPath: this.#opt.pkgPath,
|
|
472
477
|
result: this.#ngResultCache
|
|
473
478
|
}),
|
|
474
479
|
// createCompilerPlugin({
|
|
475
|
-
// sourcemap: this.
|
|
480
|
+
// sourcemap: this.#opt.dev,
|
|
476
481
|
// tsconfig: this._tsConfigFilePath,
|
|
477
482
|
// jit: false,
|
|
478
483
|
// advancedOptimizations: true,
|
|
@@ -480,11 +485,11 @@ export class SdNgBundler {
|
|
|
480
485
|
// fileReplacements: undefined,
|
|
481
486
|
// sourceFileCache: this._sourceFileCache,
|
|
482
487
|
// loadResultCache: this._sourceFileCache.loadResultCache,
|
|
483
|
-
// incremental: this.
|
|
488
|
+
// incremental: this.#opt.dev
|
|
484
489
|
// }, {
|
|
485
|
-
// workspaceRoot: this.
|
|
486
|
-
// optimization: !this.
|
|
487
|
-
// sourcemap: this.
|
|
490
|
+
// workspaceRoot: this.#opt.pkgPath,
|
|
491
|
+
// optimization: !this.#opt.dev,
|
|
492
|
+
// sourcemap: this.#opt.dev ? 'inline' : false,
|
|
488
493
|
// outputNames: {bundles: '[name]', media: 'media/[name]'},
|
|
489
494
|
// includePaths: [],
|
|
490
495
|
// externalDependencies: [],
|
|
@@ -510,33 +515,33 @@ export class SdNgBundler {
|
|
|
510
515
|
private _getStyleContext(): SdNgBundlerContext {
|
|
511
516
|
const pluginFactory = new StylesheetPluginFactory(
|
|
512
517
|
{
|
|
513
|
-
sourcemap: true, //this.
|
|
518
|
+
sourcemap: true, //this.#opt.dev,
|
|
514
519
|
includePaths: []
|
|
515
520
|
},
|
|
516
521
|
this.#styleLoadResultCache,
|
|
517
522
|
);
|
|
518
523
|
|
|
519
|
-
return new SdNgBundlerContext(this.
|
|
520
|
-
absWorkingDir: this.
|
|
524
|
+
return new SdNgBundlerContext(this.#opt.pkgPath, {
|
|
525
|
+
absWorkingDir: this.#opt.pkgPath,
|
|
521
526
|
bundle: true,
|
|
522
527
|
entryNames: '[name]',
|
|
523
528
|
assetNames: 'media/[name]',
|
|
524
529
|
logLevel: 'silent',
|
|
525
|
-
minify: !this.
|
|
530
|
+
minify: !this.#opt.dev,
|
|
526
531
|
metafile: true,
|
|
527
|
-
sourcemap: true, //this.
|
|
528
|
-
outdir: this.
|
|
532
|
+
sourcemap: true, //this.#opt.dev,
|
|
533
|
+
outdir: this.#opt.pkgPath,
|
|
529
534
|
write: false,
|
|
530
535
|
platform: 'browser',
|
|
531
|
-
target: this
|
|
536
|
+
target: this.#browserTarget,
|
|
532
537
|
preserveSymlinks: false,
|
|
533
538
|
external: [],
|
|
534
539
|
conditions: ['style', 'sass'],
|
|
535
540
|
mainFields: ['style', 'sass'],
|
|
536
|
-
legalComments: !this.
|
|
541
|
+
legalComments: !this.#opt.dev ? "none" : "eof",
|
|
537
542
|
entryPoints: {
|
|
538
543
|
// styles: 'angular:styles/global;styles'
|
|
539
|
-
styles: path.resolve(this.
|
|
544
|
+
styles: path.resolve(this.#opt.pkgPath, "src/styles.scss")
|
|
540
545
|
},
|
|
541
546
|
plugins: [
|
|
542
547
|
// createVirtualModulePlugin({
|
|
@@ -545,7 +550,7 @@ export class SdNgBundler {
|
|
|
545
550
|
// loadContent: () => ({
|
|
546
551
|
// contents: `@import 'src/styles.scss';`,
|
|
547
552
|
// loader: 'css',
|
|
548
|
-
// resolveDir: this.
|
|
553
|
+
// resolveDir: this.#opt.pkgPath
|
|
549
554
|
// }),
|
|
550
555
|
// }) as esbuild.Plugin,
|
|
551
556
|
pluginFactory.create(SassStylesheetLanguage) as esbuild.Plugin,
|
|
@@ -556,36 +561,50 @@ export class SdNgBundler {
|
|
|
556
561
|
}
|
|
557
562
|
|
|
558
563
|
private _getElectronMainContext() {
|
|
559
|
-
return new SdNgBundlerContext(this.
|
|
560
|
-
absWorkingDir: this.
|
|
564
|
+
return new SdNgBundlerContext(this.#opt.pkgPath, {
|
|
565
|
+
absWorkingDir: this.#opt.pkgPath,
|
|
561
566
|
bundle: true,
|
|
562
567
|
entryNames: '[name]',
|
|
563
568
|
assetNames: 'media/[name]',
|
|
564
569
|
conditions: ['es2020', 'es2015', 'module'],
|
|
565
570
|
resolveExtensions: ['.ts', '.tsx', '.mjs', '.js'],
|
|
566
571
|
metafile: true,
|
|
567
|
-
legalComments: this.
|
|
572
|
+
legalComments: this.#opt.dev ? 'eof' : 'none',
|
|
568
573
|
logLevel: 'silent',
|
|
569
|
-
minify: !this.
|
|
570
|
-
outdir: this.
|
|
571
|
-
sourcemap: true, //this.
|
|
572
|
-
tsconfig: this
|
|
574
|
+
minify: !this.#opt.dev,
|
|
575
|
+
outdir: this.#opt.pkgPath,
|
|
576
|
+
sourcemap: true, //this.#opt.dev,
|
|
577
|
+
tsconfig: this.#tsConfigFilePath,
|
|
573
578
|
write: false,
|
|
574
579
|
preserveSymlinks: false,
|
|
575
580
|
external: ["electron"],
|
|
576
581
|
define: {
|
|
577
|
-
...!this.
|
|
578
|
-
'process.env.SD_VERSION': JSON.stringify(this.
|
|
579
|
-
"process.env.NODE_ENV": JSON.stringify(this.
|
|
580
|
-
...this.
|
|
582
|
+
...!this.#opt.dev ? {ngDevMode: 'false'} : {},
|
|
583
|
+
'process.env.SD_VERSION': JSON.stringify(this.#pkgNpmConf.version),
|
|
584
|
+
"process.env.NODE_ENV": JSON.stringify(this.#opt.dev ? "development" : "production"),
|
|
585
|
+
...this.#opt.env ? Object.keys(this.#opt.env).toObject(
|
|
581
586
|
key => `process.env.${key}`,
|
|
582
|
-
key => JSON.stringify(this.
|
|
587
|
+
key => JSON.stringify(this.#opt.env![key])
|
|
583
588
|
) : {}
|
|
584
589
|
},
|
|
585
590
|
platform: 'node',
|
|
586
591
|
entryPoints: {
|
|
587
|
-
"electron-main": path.resolve(this.
|
|
592
|
+
"electron-main": path.resolve(this.#opt.pkgPath, "src/electron-main.ts"),
|
|
588
593
|
}
|
|
589
594
|
});
|
|
590
595
|
}
|
|
596
|
+
|
|
597
|
+
|
|
598
|
+
#debug(...msg: any[]): void {
|
|
599
|
+
this.#logger.debug(`[${path.basename(this.#opt.pkgPath)}]`, ...msg);
|
|
600
|
+
}
|
|
601
|
+
}
|
|
602
|
+
|
|
603
|
+
interface IOptions {
|
|
604
|
+
dev: boolean;
|
|
605
|
+
outputPath: string;
|
|
606
|
+
pkgPath: string;
|
|
607
|
+
builderType: string;
|
|
608
|
+
env: Record<string, string> | undefined;
|
|
609
|
+
cordovaConfig: ISdCliClientBuilderCordovaConfig | undefined;
|
|
591
610
|
}
|
|
@@ -2,8 +2,11 @@ import esbuild from "esbuild";
|
|
|
2
2
|
import path from "path";
|
|
3
3
|
import {InitialFileRecord} from "@angular-devkit/build-angular/src/tools/esbuild/bundler-context";
|
|
4
4
|
import {ISdCliPackageBuildResult} from "../commons";
|
|
5
|
+
import {Logger} from "@simplysm/sd-core-node";
|
|
5
6
|
|
|
6
7
|
export class SdNgBundlerContext {
|
|
8
|
+
readonly #logger = Logger.get(["simplysm", "sd-cli", "SdNgBundlerContext"]);
|
|
9
|
+
|
|
7
10
|
private _context?: esbuild.BuildContext;
|
|
8
11
|
|
|
9
12
|
public constructor(private readonly _pkgPath: string,
|
|
@@ -18,7 +21,9 @@ export class SdNgBundlerContext {
|
|
|
18
21
|
let buildResult: esbuild.BuildResult;
|
|
19
22
|
|
|
20
23
|
try {
|
|
24
|
+
this.#debug(`rebuild...`);
|
|
21
25
|
buildResult = await this._context.rebuild();
|
|
26
|
+
this.#debug(`rebuild completed`);
|
|
22
27
|
}
|
|
23
28
|
catch (err) {
|
|
24
29
|
if ("warnings" in err || "errors" in err) {
|
|
@@ -29,6 +34,8 @@ export class SdNgBundlerContext {
|
|
|
29
34
|
}
|
|
30
35
|
}
|
|
31
36
|
|
|
37
|
+
this.#debug(`convert results...`);
|
|
38
|
+
|
|
32
39
|
const results = [
|
|
33
40
|
...buildResult.warnings.map((warn) => ({
|
|
34
41
|
filePath: warn.location?.file !== undefined ? path.resolve(this._pkgPath, warn.location.file) : undefined,
|
|
@@ -36,16 +43,16 @@ export class SdNgBundlerContext {
|
|
|
36
43
|
char: warn.location?.column,
|
|
37
44
|
code: warn.text.slice(0, warn.text.indexOf(":")),
|
|
38
45
|
severity: "warning",
|
|
39
|
-
message: `${warn.pluginName
|
|
46
|
+
message: `${warn.pluginName ? `(${warn.pluginName}) ` : ""} ${warn.text.slice(warn.text.indexOf(":") + 1)}`,
|
|
40
47
|
type: "build"
|
|
41
48
|
})),
|
|
42
|
-
...buildResult.errors
|
|
49
|
+
...buildResult.errors.map((err) => ({
|
|
43
50
|
filePath: err.location?.file !== undefined ? path.resolve(this._pkgPath, err.location.file) : undefined,
|
|
44
51
|
line: err.location?.line,
|
|
45
52
|
char: err.location?.column !== undefined ? err.location.column + 1 : undefined,
|
|
46
53
|
code: err.text.slice(0, err.text.indexOf(":")),
|
|
47
54
|
severity: "error",
|
|
48
|
-
message: `${err.pluginName
|
|
55
|
+
message: `${err.pluginName ? `(${err.pluginName}) ` : ""} ${err.text.slice(err.text.indexOf(":") + 1)}`,
|
|
49
56
|
type: "build"
|
|
50
57
|
}))
|
|
51
58
|
] as ISdCliPackageBuildResult[];
|
|
@@ -115,4 +122,8 @@ export class SdNgBundlerContext {
|
|
|
115
122
|
metafile: buildResult.metafile
|
|
116
123
|
};
|
|
117
124
|
}
|
|
125
|
+
|
|
126
|
+
#debug(...msg: any[]): void {
|
|
127
|
+
this.#logger.debug(`[${path.basename(this._pkgPath)}] (${Object.keys(this._esbuildOptions.entryPoints as Record<string, any>).join(", ")})`, ...msg);
|
|
128
|
+
}
|
|
118
129
|
}
|