@simplysm/sd-cli 12.13.13 → 12.13.15
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-electron.js +1 -1
- package/dist/entry/sd-cli-electron.js.map +1 -1
- package/dist/entry/sd-cli-project.d.ts +2 -0
- package/dist/entry/sd-cli-project.js +11 -3
- package/dist/entry/sd-cli-project.js.map +1 -1
- package/dist/pkg-builders/client/sd-client.build-runner.d.ts +1 -1
- package/dist/pkg-builders/client/sd-client.build-runner.js +74 -50
- package/dist/pkg-builders/client/sd-client.build-runner.js.map +1 -1
- package/dist/pkg-builders/client/sd-ng.bundler.d.ts +2 -0
- package/dist/pkg-builders/client/sd-ng.bundler.js +19 -20
- package/dist/pkg-builders/client/sd-ng.bundler.js.map +1 -1
- package/dist/pkg-builders/client/sd-ng.plugin-creator.d.ts +2 -0
- package/dist/pkg-builders/client/sd-ng.plugin-creator.js +94 -33
- package/dist/pkg-builders/client/sd-ng.plugin-creator.js.map +1 -1
- package/dist/pkg-builders/commons/build-runner.base.d.ts +4 -2
- package/dist/pkg-builders/commons/build-runner.base.js +45 -25
- package/dist/pkg-builders/commons/build-runner.base.js.map +1 -1
- package/dist/pkg-builders/lib/sd-js-lib.build-runner.d.ts +1 -1
- package/dist/pkg-builders/lib/sd-js-lib.build-runner.js +14 -4
- package/dist/pkg-builders/lib/sd-js-lib.build-runner.js.map +1 -1
- package/dist/pkg-builders/lib/sd-ts-lib.build-runner.d.ts +1 -1
- package/dist/pkg-builders/lib/sd-ts-lib.build-runner.js +21 -40
- package/dist/pkg-builders/lib/sd-ts-lib.build-runner.js.map +1 -1
- package/dist/pkg-builders/lib/sd-ts-lib.builder.d.ts +1 -1
- package/dist/pkg-builders/lib/sd-ts-lib.builder.js +3 -1
- package/dist/pkg-builders/lib/sd-ts-lib.builder.js.map +1 -1
- package/dist/pkg-builders/sd-multi.build-runner.js +116 -86
- package/dist/pkg-builders/sd-multi.build-runner.js.map +1 -1
- package/dist/pkg-builders/server/sd-server.build-runner.d.ts +1 -1
- package/dist/pkg-builders/server/sd-server.build-runner.js +9 -5
- package/dist/pkg-builders/server/sd-server.build-runner.js.map +1 -1
- package/dist/pkg-builders/server/sd-server.bundler.d.ts +2 -0
- package/dist/pkg-builders/server/sd-server.bundler.js +3 -1
- package/dist/pkg-builders/server/sd-server.bundler.js.map +1 -1
- package/dist/pkg-builders/server/sd-server.plugin-creator.d.ts +2 -0
- package/dist/pkg-builders/server/sd-server.plugin-creator.js +4 -1
- package/dist/pkg-builders/server/sd-server.plugin-creator.js.map +1 -1
- package/dist/sd-cli-entry.js +10 -0
- package/dist/sd-cli-entry.js.map +1 -1
- package/dist/sd-cli.js +8 -6
- package/dist/sd-cli.js.map +1 -1
- package/dist/ts-compiler/sd-dependency-analyzer.d.ts +8 -1
- package/dist/ts-compiler/sd-dependency-analyzer.js +128 -63
- package/dist/ts-compiler/sd-dependency-analyzer.js.map +1 -1
- package/dist/ts-compiler/sd-dependency-cache.d.ts +0 -34
- package/dist/ts-compiler/sd-dependency-cache.js +73 -119
- package/dist/ts-compiler/sd-dependency-cache.js.map +1 -1
- package/dist/ts-compiler/sd-style-bundler.d.ts +16 -0
- package/dist/ts-compiler/sd-style-bundler.js +118 -0
- package/dist/ts-compiler/sd-style-bundler.js.map +1 -0
- package/dist/ts-compiler/sd-ts-compiler.js +418 -235
- package/dist/ts-compiler/sd-ts-compiler.js.map +1 -1
- package/dist/types/build-runner.types.d.ts +2 -0
- package/dist/types/config.types.d.ts +2 -0
- package/dist/types/ts-compiler.types.d.ts +2 -0
- package/dist/types/worker.types.d.ts +1 -1
- package/dist/workers/build-runner.worker.js +1 -1
- package/dist/workers/build-runner.worker.js.map +1 -1
- package/dist/workers/server.worker.js +2 -2
- package/dist/workers/server.worker.js.map +1 -1
- package/package.json +13 -12
- package/src/entry/sd-cli-electron.ts +2 -1
- package/src/entry/sd-cli-project.ts +13 -3
- package/src/pkg-builders/client/sd-client.build-runner.ts +93 -54
- package/src/pkg-builders/client/sd-ng.bundler.ts +79 -85
- package/src/pkg-builders/client/sd-ng.plugin-creator.ts +119 -39
- package/src/pkg-builders/commons/build-runner.base.ts +78 -33
- package/src/pkg-builders/lib/sd-js-lib.build-runner.ts +24 -7
- package/src/pkg-builders/lib/sd-ts-lib.build-runner.ts +36 -42
- package/src/pkg-builders/lib/sd-ts-lib.builder.ts +4 -0
- package/src/pkg-builders/sd-multi.build-runner.ts +137 -108
- package/src/pkg-builders/server/sd-server.build-runner.ts +10 -4
- package/src/pkg-builders/server/sd-server.bundler.ts +5 -1
- package/src/pkg-builders/server/sd-server.plugin-creator.ts +10 -5
- package/src/sd-cli-entry.ts +10 -0
- package/src/sd-cli.ts +8 -6
- package/src/ts-compiler/sd-dependency-analyzer.ts +161 -86
- package/src/ts-compiler/sd-dependency-cache.ts +118 -99
- package/src/ts-compiler/sd-style-bundler.ts +150 -0
- package/src/ts-compiler/sd-ts-compiler.ts +559 -296
- package/src/types/build-runner.types.ts +2 -0
- package/src/types/config.types.ts +3 -0
- package/src/types/ts-compiler.types.ts +15 -11
- package/src/types/worker.types.ts +7 -10
- package/src/workers/build-runner.worker.ts +9 -5
- package/src/workers/server.worker.ts +2 -2
- package/tests/deps/sd-dependency-cache.spec.ts +1 -1
|
@@ -26,17 +26,11 @@ import {
|
|
|
26
26
|
import { Entrypoint } from "@angular/build/src/utils/index-file/augment-index-html";
|
|
27
27
|
import { CrossOrigin } from "@angular/build/src/builders/application/schema";
|
|
28
28
|
import { augmentAppWithServiceWorkerEsbuild } from "@angular/build/src/utils/service-worker";
|
|
29
|
-
import {
|
|
30
|
-
|
|
31
|
-
} from "@angular/build/src/tools/esbuild/sourcemap-ignorelist-plugin";
|
|
32
|
-
import {
|
|
33
|
-
StylesheetPluginFactory,
|
|
34
|
-
} from "@angular/build/src/tools/esbuild/stylesheets/stylesheet-plugin-factory";
|
|
29
|
+
import { createSourcemapIgnorelistPlugin } from "@angular/build/src/tools/esbuild/sourcemap-ignorelist-plugin";
|
|
30
|
+
import { StylesheetPluginFactory } from "@angular/build/src/tools/esbuild/stylesheets/stylesheet-plugin-factory";
|
|
35
31
|
import { SassStylesheetLanguage } from "@angular/build/src/tools/esbuild/stylesheets/sass-language";
|
|
36
32
|
import { CssStylesheetLanguage } from "@angular/build/src/tools/esbuild/stylesheets/css-language";
|
|
37
|
-
import {
|
|
38
|
-
createCssResourcePlugin,
|
|
39
|
-
} from "@angular/build/src/tools/esbuild/stylesheets/css-resource-plugin";
|
|
33
|
+
import { createCssResourcePlugin } from "@angular/build/src/tools/esbuild/stylesheets/css-resource-plugin";
|
|
40
34
|
import { resolveAssets } from "@angular/build/src/utils/resolve-assets";
|
|
41
35
|
import { createSdNgPlugin } from "./sd-ng.plugin-creator";
|
|
42
36
|
import { SdCliPerformanceTimer } from "../../utils/sd-cli-performance-time";
|
|
@@ -73,6 +67,8 @@ export class SdNgBundler {
|
|
|
73
67
|
constructor(
|
|
74
68
|
private readonly _opt: {
|
|
75
69
|
dev: boolean;
|
|
70
|
+
emitOnly: boolean;
|
|
71
|
+
noEmit: boolean;
|
|
76
72
|
outputPath: TNormPath;
|
|
77
73
|
pkgPath: TNormPath;
|
|
78
74
|
builderType: string;
|
|
@@ -118,9 +114,9 @@ export class SdNgBundler {
|
|
|
118
114
|
if (!this.#contexts) {
|
|
119
115
|
this.#contexts = perf.run("get contexts", () => [
|
|
120
116
|
this.#getAppContext(),
|
|
121
|
-
...FsUtils.exists(path.resolve(this._opt.pkgPath, "src/styles.scss"))
|
|
122
|
-
this.#getStyleContext()
|
|
123
|
-
|
|
117
|
+
...(FsUtils.exists(path.resolve(this._opt.pkgPath, "src/styles.scss"))
|
|
118
|
+
? [this.#getStyleContext()]
|
|
119
|
+
: []),
|
|
124
120
|
...(this._opt.builderType === "electron" ? [this.#getElectronMainContext()] : []),
|
|
125
121
|
]);
|
|
126
122
|
}
|
|
@@ -137,8 +133,8 @@ export class SdNgBundler {
|
|
|
137
133
|
this.#debug(`convert result...`);
|
|
138
134
|
|
|
139
135
|
const outputFiles: BuildOutputFile[] = bundlingResults.mapMany(
|
|
140
|
-
(item) =>
|
|
141
|
-
?? [],
|
|
136
|
+
(item) =>
|
|
137
|
+
item.outputFiles?.map((file) => convertOutputFile(file, BuildOutputFileType.Root)) ?? [],
|
|
142
138
|
);
|
|
143
139
|
const initialFiles = new Map<string, InitialFileRecord>();
|
|
144
140
|
const metafile: {
|
|
@@ -185,11 +181,9 @@ export class SdNgBundler {
|
|
|
185
181
|
type: "gen-index",
|
|
186
182
|
});
|
|
187
183
|
}
|
|
188
|
-
outputFiles.push(
|
|
189
|
-
"index.html",
|
|
190
|
-
|
|
191
|
-
BuildOutputFileType.Root,
|
|
192
|
-
));
|
|
184
|
+
outputFiles.push(
|
|
185
|
+
createOutputFile("index.html", genIndexHtmlResult.csrContent, BuildOutputFileType.Root),
|
|
186
|
+
);
|
|
193
187
|
});
|
|
194
188
|
|
|
195
189
|
await perf.run("assets", async () => {
|
|
@@ -215,14 +209,11 @@ export class SdNgBundler {
|
|
|
215
209
|
await perf.run("prepare service worker", async () => {
|
|
216
210
|
try {
|
|
217
211
|
const serviceWorkerResult = await this.#genServiceWorkerAsync(outputFiles, assetFiles);
|
|
218
|
-
outputFiles.push(
|
|
219
|
-
"ngsw.json",
|
|
220
|
-
|
|
221
|
-
BuildOutputFileType.Root,
|
|
222
|
-
));
|
|
212
|
+
outputFiles.push(
|
|
213
|
+
createOutputFile("ngsw.json", serviceWorkerResult.manifest, BuildOutputFileType.Root),
|
|
214
|
+
);
|
|
223
215
|
assetFiles.push(...serviceWorkerResult.assetFiles);
|
|
224
|
-
}
|
|
225
|
-
catch (err) {
|
|
216
|
+
} catch (err) {
|
|
226
217
|
results.push({
|
|
227
218
|
filePath: undefined,
|
|
228
219
|
line: undefined,
|
|
@@ -248,7 +239,7 @@ export class SdNgBundler {
|
|
|
248
239
|
if (prevHash !== currHash) {
|
|
249
240
|
FsUtils.writeFile(distFilePath, outputFile.contents);
|
|
250
241
|
this.#outputHashCache.set(distFilePath, currHash);
|
|
251
|
-
emitFileSet.add(
|
|
242
|
+
emitFileSet.add(distFilePath);
|
|
252
243
|
}
|
|
253
244
|
}
|
|
254
245
|
for (const assetFile of assetFiles) {
|
|
@@ -257,7 +248,7 @@ export class SdNgBundler {
|
|
|
257
248
|
if (prevHash !== currHash) {
|
|
258
249
|
FsUtils.copy(assetFile.source, path.resolve(this._opt.outputPath, assetFile.destination));
|
|
259
250
|
this.#outputHashCache.set(PathUtils.norm(assetFile.source), currHash);
|
|
260
|
-
emitFileSet.add(PathUtils.norm(assetFile.destination));
|
|
251
|
+
emitFileSet.add(PathUtils.norm(this._opt.outputPath, assetFile.destination));
|
|
261
252
|
}
|
|
262
253
|
}
|
|
263
254
|
});
|
|
@@ -297,9 +288,7 @@ export class SdNgBundler {
|
|
|
297
288
|
["polyfills", true],
|
|
298
289
|
["styles", false],
|
|
299
290
|
["main", true],
|
|
300
|
-
...(this._opt.builderType === "cordova" ? [
|
|
301
|
-
["cordova-entry", true] as Entrypoint,
|
|
302
|
-
] : []),
|
|
291
|
+
...(this._opt.builderType === "cordova" ? [["cordova-entry", true] as Entrypoint] : []),
|
|
303
292
|
],
|
|
304
293
|
sri: false,
|
|
305
294
|
optimization: {
|
|
@@ -360,29 +349,30 @@ export class SdNgBundler {
|
|
|
360
349
|
{ input: "public", glob: "**/*", output: "." },
|
|
361
350
|
...(this._opt.dev ? [{ input: "public-dev", glob: "**/*", output: "." }] : []),
|
|
362
351
|
...(this._opt.dev && this._opt.builderType === "cordova"
|
|
363
|
-
? Object.keys(this._opt.cordovaConfig?.platform ?? { browser: {} })
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
352
|
+
? Object.keys(this._opt.cordovaConfig?.platform ?? { browser: {} }).mapMany(
|
|
353
|
+
(platform) => [
|
|
354
|
+
{
|
|
355
|
+
input: `.cordova/platforms/${platform}/platform_www/plugins`,
|
|
356
|
+
glob: "**/*",
|
|
357
|
+
output: `cordova-${platform}/plugins`,
|
|
358
|
+
},
|
|
359
|
+
{
|
|
360
|
+
input: `.cordova/platforms/${platform}/platform_www`,
|
|
361
|
+
glob: "cordova.js",
|
|
362
|
+
output: `cordova-${platform}`,
|
|
363
|
+
},
|
|
364
|
+
{
|
|
365
|
+
input: `.cordova/platforms/${platform}/platform_www`,
|
|
366
|
+
glob: "cordova_plugins.js",
|
|
367
|
+
output: `cordova-${platform}`,
|
|
368
|
+
},
|
|
369
|
+
{
|
|
370
|
+
input: `.cordova/platforms/${platform}/www`,
|
|
371
|
+
glob: "config.xml",
|
|
372
|
+
output: `cordova-${platform}`,
|
|
373
|
+
},
|
|
374
|
+
],
|
|
375
|
+
)
|
|
386
376
|
: []),
|
|
387
377
|
],
|
|
388
378
|
this._opt.pkgPath,
|
|
@@ -413,10 +403,9 @@ export class SdNgBundler {
|
|
|
413
403
|
}
|
|
414
404
|
|
|
415
405
|
#getAppContext() {
|
|
416
|
-
const workerEntries = FsUtils.glob(
|
|
417
|
-
.
|
|
418
|
-
|
|
419
|
-
);
|
|
406
|
+
const workerEntries = FsUtils.glob(
|
|
407
|
+
path.resolve(this._opt.pkgPath, "src/workers/*.ts"),
|
|
408
|
+
).toObject((p) => "workers/" + path.basename(p, path.extname(p)));
|
|
420
409
|
|
|
421
410
|
return new SdNgBundlerContext(this._opt.pkgPath, {
|
|
422
411
|
absWorkingDir: this._opt.pkgPath,
|
|
@@ -449,26 +438,28 @@ export class SdNgBundler {
|
|
|
449
438
|
"process.env.NODE_ENV": JSON.stringify(this._opt.dev ? "development" : "production"),
|
|
450
439
|
...(this._opt.env
|
|
451
440
|
? Object.keys(this._opt.env).toObject(
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
441
|
+
(key) => `process.env.${key}`,
|
|
442
|
+
(key) => JSON.stringify(this._opt.env![key]),
|
|
443
|
+
)
|
|
455
444
|
: {}),
|
|
456
445
|
},
|
|
457
446
|
mainFields: ["es2020", "es2015", "browser", "module", "main"],
|
|
458
447
|
entryNames: "[dir]/[name]",
|
|
459
448
|
entryPoints: {
|
|
460
449
|
main: this.#mainFilePath,
|
|
461
|
-
...FsUtils.exists(path.resolve(this._opt.pkgPath, "src/polyfills.ts"))
|
|
462
|
-
|
|
463
|
-
|
|
450
|
+
...(FsUtils.exists(path.resolve(this._opt.pkgPath, "src/polyfills.ts"))
|
|
451
|
+
? {
|
|
452
|
+
polyfills: path.resolve(this._opt.pkgPath, "src/polyfills.ts"),
|
|
453
|
+
}
|
|
454
|
+
: {}),
|
|
464
455
|
|
|
465
456
|
...(this._opt.builderType === "cordova"
|
|
466
457
|
? {
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
458
|
+
"cordova-entry": path.resolve(
|
|
459
|
+
path.dirname(fileURLToPath(import.meta.url)),
|
|
460
|
+
`../../../lib/cordova-entry.js`,
|
|
461
|
+
),
|
|
462
|
+
}
|
|
472
463
|
: {}),
|
|
473
464
|
...workerEntries,
|
|
474
465
|
},
|
|
@@ -502,25 +493,28 @@ export class SdNgBundler {
|
|
|
502
493
|
},
|
|
503
494
|
...(this._opt.builderType === "electron"
|
|
504
495
|
? {
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
496
|
+
platform: "node",
|
|
497
|
+
target: "node20",
|
|
498
|
+
external: ["electron", ...nodeModule.builtinModules, ...this._opt.external],
|
|
499
|
+
}
|
|
509
500
|
: {
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
501
|
+
platform: "browser",
|
|
502
|
+
target: this.#browserTarget,
|
|
503
|
+
format: "esm",
|
|
504
|
+
splitting: true,
|
|
505
|
+
inject: [
|
|
506
|
+
PathUtils.posix(
|
|
507
|
+
fileURLToPath(import.meta.resolve("node-stdlib-browser/helpers/esbuild/shim")),
|
|
508
|
+
),
|
|
509
|
+
],
|
|
510
|
+
}),
|
|
519
511
|
plugins: [
|
|
520
512
|
createSourcemapIgnorelistPlugin(),
|
|
521
513
|
createSdNgPlugin({
|
|
522
514
|
modifiedFileSet: this.#modifiedFileSet,
|
|
523
515
|
dev: this._opt.dev,
|
|
516
|
+
emitOnly: this._opt.emitOnly,
|
|
517
|
+
noEmit: this._opt.noEmit,
|
|
524
518
|
pkgPath: this._opt.pkgPath,
|
|
525
519
|
result: this.#ngResultCache,
|
|
526
520
|
watchScopePathSet: this._opt.watchScopePathSet,
|
|
@@ -605,9 +599,9 @@ export class SdNgBundler {
|
|
|
605
599
|
"process.env.NODE_ENV": JSON.stringify(this._opt.dev ? "development" : "production"),
|
|
606
600
|
...(this._opt.env
|
|
607
601
|
? Object.keys(this._opt.env).toObject(
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
602
|
+
(key) => `process.env.${key}`,
|
|
603
|
+
(key) => JSON.stringify(this._opt.env![key]),
|
|
604
|
+
)
|
|
611
605
|
: {}),
|
|
612
606
|
},
|
|
613
607
|
platform: "node",
|
|
@@ -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 { PathUtils, SdLogger, TNormPath } from "@simplysm/sd-core-node";
|
|
5
|
+
import { FsUtils, 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";
|
|
@@ -13,6 +13,8 @@ import { ScopePathSet } from "../commons/scope-path";
|
|
|
13
13
|
export function createSdNgPlugin(conf: {
|
|
14
14
|
pkgPath: TNormPath;
|
|
15
15
|
dev: boolean;
|
|
16
|
+
emitOnly: boolean;
|
|
17
|
+
noEmit: boolean;
|
|
16
18
|
modifiedFileSet: Set<TNormPath>;
|
|
17
19
|
result: ISdCliNgPluginResultCache;
|
|
18
20
|
watchScopePathSet: ScopePathSet;
|
|
@@ -32,6 +34,8 @@ export function createSdNgPlugin(conf: {
|
|
|
32
34
|
additionalOptions: { declaration: false },
|
|
33
35
|
isDevMode: conf.dev,
|
|
34
36
|
isForBundle: true,
|
|
37
|
+
isEmitOnly: conf.emitOnly,
|
|
38
|
+
isNoEmit: conf.noEmit,
|
|
35
39
|
watchScopePathSet: conf.watchScopePathSet,
|
|
36
40
|
});
|
|
37
41
|
|
|
@@ -41,14 +45,16 @@ export function createSdNgPlugin(conf: {
|
|
|
41
45
|
//-- js babel transformer
|
|
42
46
|
const javascriptTransformer = new JavaScriptTransformer(
|
|
43
47
|
{
|
|
44
|
-
thirdPartySourcemaps: conf.dev,
|
|
48
|
+
thirdPartySourcemaps: false, //conf.dev,
|
|
45
49
|
sourcemap: conf.dev,
|
|
46
50
|
jit: false,
|
|
47
|
-
advancedOptimizations:
|
|
51
|
+
advancedOptimizations: !conf.dev,
|
|
48
52
|
},
|
|
49
|
-
os.cpus().length,
|
|
53
|
+
Math.floor((os.cpus().length * 2) / 3),
|
|
50
54
|
);
|
|
51
55
|
|
|
56
|
+
let cssStore = new Map<TNormPath, Buffer>();
|
|
57
|
+
|
|
52
58
|
//---------------------------
|
|
53
59
|
|
|
54
60
|
build.onStart(async () => {
|
|
@@ -61,6 +67,8 @@ export function createSdNgPlugin(conf: {
|
|
|
61
67
|
|
|
62
68
|
tsCompileResult = await tsCompiler.compileAsync(conf.modifiedFileSet);
|
|
63
69
|
|
|
70
|
+
cssStore.clear();
|
|
71
|
+
|
|
64
72
|
conf.result.watchFileSet = tsCompileResult.watchFileSet;
|
|
65
73
|
conf.result.affectedFileSet = tsCompileResult.affectedFileSet;
|
|
66
74
|
|
|
@@ -85,36 +93,90 @@ export function createSdNgPlugin(conf: {
|
|
|
85
93
|
};
|
|
86
94
|
});
|
|
87
95
|
|
|
88
|
-
perf.start("transform & bundling");
|
|
96
|
+
perf.start("esbuild transform & bundling");
|
|
89
97
|
return res;
|
|
90
98
|
});
|
|
91
99
|
|
|
100
|
+
build.onResolve({ filter: /\.css$/ }, (args) => {
|
|
101
|
+
if (args.path.startsWith("sd-css-asset:")) return;
|
|
102
|
+
return {
|
|
103
|
+
path: path.resolve(args.resolveDir, args.path),
|
|
104
|
+
namespace: "sd-css",
|
|
105
|
+
};
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
build.onLoad({ filter: /\.css$/, namespace: "sd-css" }, async (args) => {
|
|
109
|
+
const code = /* language=javascript */ `
|
|
110
|
+
import href from "sd-css-asset:${PathUtils.posix(args.path)}"
|
|
111
|
+
(function __sdEnsureStyle(href) {
|
|
112
|
+
let link = document.querySelector('link[data-sd-style="' + href + '"]');
|
|
113
|
+
if (link) return;
|
|
114
|
+
link = document.createElement('link');
|
|
115
|
+
link.rel = 'stylesheet';
|
|
116
|
+
link.setAttribute('data-sd-style', href);
|
|
117
|
+
link.href = href;
|
|
118
|
+
document.head.appendChild(link);
|
|
119
|
+
})(href);`;
|
|
120
|
+
|
|
121
|
+
if (FsUtils.exists(args.path)) {
|
|
122
|
+
const css = await FsUtils.readFileBufferAsync(args.path);
|
|
123
|
+
cssStore.set(PathUtils.norm(args.path), css);
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
return { contents: code, loader: "js", resolveDir: path.dirname(args.path) };
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
build.onResolve({ filter: /^sd-css-asset:/ }, (args) => {
|
|
130
|
+
const real = args.path.replace(/^sd-css-asset:/, "");
|
|
131
|
+
return { path: real, namespace: "sd-css-asset" };
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
build.onLoad({ filter: /\.css$/, namespace: "sd-css-asset" }, (args) => {
|
|
135
|
+
const cssContent = cssStore.get(
|
|
136
|
+
PathUtils.norm(args.path.replace(/[\\\/]src[\\\/]/, "\\dist\\")),
|
|
137
|
+
);
|
|
138
|
+
if (cssContent == null) {
|
|
139
|
+
return { errors: [{ text: `Missing CSS for ${PathUtils.norm(args.path)}` }] };
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
return {
|
|
143
|
+
contents: cssContent,
|
|
144
|
+
loader: "file",
|
|
145
|
+
resolveDir: path.dirname(args.path),
|
|
146
|
+
};
|
|
147
|
+
});
|
|
148
|
+
|
|
92
149
|
build.onLoad({ filter: /\.ts$/ }, async (args) => {
|
|
150
|
+
const emittedFiles = tsCompileResult.emittedFilesCacheMap.get(PathUtils.norm(args.path));
|
|
151
|
+
|
|
152
|
+
try {
|
|
153
|
+
const css = emittedFiles?.single((item) => Boolean(item.outAbsPath?.endsWith(".css")));
|
|
154
|
+
if (css) {
|
|
155
|
+
cssStore.set(PathUtils.norm(css.outAbsPath!), Buffer.from(css.text));
|
|
156
|
+
}
|
|
157
|
+
} catch (err) {
|
|
158
|
+
console.error(
|
|
159
|
+
emittedFiles?.map((item) => item.outAbsPath),
|
|
160
|
+
err,
|
|
161
|
+
);
|
|
162
|
+
return { errors: [{ text: err?.message ?? String(err) }] };
|
|
163
|
+
}
|
|
164
|
+
|
|
93
165
|
const output = outputContentsCacheMap.get(PathUtils.norm(args.path));
|
|
94
166
|
if (output != null) {
|
|
95
167
|
return { contents: output, loader: "js" };
|
|
96
168
|
}
|
|
97
169
|
|
|
98
|
-
const
|
|
99
|
-
/*if (!emittedJsFile) {
|
|
100
|
-
return {
|
|
101
|
-
errors: [
|
|
102
|
-
{
|
|
103
|
-
text: `ts 빌더 결과 emit 파일이 존재하지 않습니다. ${args.path}`,
|
|
104
|
-
},
|
|
105
|
-
],
|
|
106
|
-
};
|
|
107
|
-
}
|
|
108
|
-
const contents = emittedJsFile.text;*/
|
|
109
|
-
|
|
110
|
-
const contents = emittedJsFile?.text ?? "";
|
|
170
|
+
const contents = emittedFiles?.last()?.text ?? "";
|
|
111
171
|
|
|
112
172
|
const { sideEffects } = await build.resolve(args.path, {
|
|
113
173
|
kind: "import-statement",
|
|
114
174
|
resolveDir: build.initialOptions.absWorkingDir ?? "",
|
|
115
175
|
});
|
|
116
176
|
|
|
117
|
-
const newContents = await
|
|
177
|
+
const newContents = await perf.run("esbuild transform:js:*.ts", async () => {
|
|
178
|
+
return await javascriptTransformer.transformData(args.path, contents, true, sideEffects);
|
|
179
|
+
});
|
|
118
180
|
|
|
119
181
|
outputContentsCacheMap.set(PathUtils.norm(args.path), newContents);
|
|
120
182
|
|
|
@@ -135,7 +197,22 @@ export function createSdNgPlugin(conf: {
|
|
|
135
197
|
});
|
|
136
198
|
|
|
137
199
|
try {
|
|
138
|
-
const newContents = await
|
|
200
|
+
const newContents = await perf.run("esbuild transform:js:*.js", async () => {
|
|
201
|
+
/*return /\.min\.[cm]?js$/.test(args.path)
|
|
202
|
+
? await FsUtils.readFileBufferAsync(args.path)
|
|
203
|
+
: await javascriptTransformer.transformFile(args.path, false, sideEffects);*/
|
|
204
|
+
|
|
205
|
+
const contents = await FsUtils.readFileBufferAsync(args.path);
|
|
206
|
+
|
|
207
|
+
return args.path.includes("node_modules") && !args.path.includes("angular")
|
|
208
|
+
? contents
|
|
209
|
+
: await javascriptTransformer.transformData(
|
|
210
|
+
args.path,
|
|
211
|
+
contents.toString(),
|
|
212
|
+
false,
|
|
213
|
+
sideEffects,
|
|
214
|
+
);
|
|
215
|
+
});
|
|
139
216
|
|
|
140
217
|
outputContentsCacheMap.set(PathUtils.norm(args.path), newContents);
|
|
141
218
|
|
|
@@ -144,31 +221,28 @@ export function createSdNgPlugin(conf: {
|
|
|
144
221
|
loader: "js",
|
|
145
222
|
};
|
|
146
223
|
} catch (err) {
|
|
147
|
-
return {
|
|
224
|
+
return { errors: [{ text: err?.message ?? String(err) }] };
|
|
225
|
+
/*return {
|
|
148
226
|
contents: `console.error(${JSON.stringify(err.message)});`,
|
|
149
227
|
loader: "js",
|
|
150
|
-
}
|
|
228
|
+
};*/
|
|
151
229
|
}
|
|
152
230
|
});
|
|
153
231
|
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
.join("|") +
|
|
161
|
-
")$",
|
|
162
|
-
),
|
|
163
|
-
},
|
|
164
|
-
(args) => {
|
|
165
|
-
conf.result.watchFileSet!.add(PathUtils.norm(args.path));
|
|
166
|
-
return null;
|
|
167
|
-
},
|
|
232
|
+
const otherLoaderFilter = new RegExp(
|
|
233
|
+
"(" +
|
|
234
|
+
Object.keys(build.initialOptions.loader ?? {})
|
|
235
|
+
.map((ext) => "\\" + ext)
|
|
236
|
+
.join("|") +
|
|
237
|
+
")$",
|
|
168
238
|
);
|
|
239
|
+
build.onLoad({ filter: otherLoaderFilter }, (args) => {
|
|
240
|
+
conf.result.watchFileSet!.add(PathUtils.norm(args.path));
|
|
241
|
+
return null;
|
|
242
|
+
});
|
|
169
243
|
|
|
170
244
|
build.onEnd((result) => {
|
|
171
|
-
perf.end("transform & bundling");
|
|
245
|
+
perf.end("esbuild transform & bundling");
|
|
172
246
|
debug(perf.toString());
|
|
173
247
|
|
|
174
248
|
for (const stylesheetBundlingResult of tsCompileResult.stylesheetBundlingResultMap.values()) {
|
|
@@ -177,8 +251,14 @@ export function createSdNgPlugin(conf: {
|
|
|
177
251
|
result.outputFiles.push(...stylesheetBundlingResult.outputFiles);
|
|
178
252
|
|
|
179
253
|
if (result.metafile) {
|
|
180
|
-
result.metafile.inputs = {
|
|
181
|
-
|
|
254
|
+
result.metafile.inputs = {
|
|
255
|
+
...result.metafile.inputs,
|
|
256
|
+
...stylesheetBundlingResult.metafile.inputs,
|
|
257
|
+
};
|
|
258
|
+
result.metafile.outputs = {
|
|
259
|
+
...result.metafile.outputs,
|
|
260
|
+
...stylesheetBundlingResult.metafile.outputs,
|
|
261
|
+
};
|
|
182
262
|
}
|
|
183
263
|
}
|
|
184
264
|
}
|