@simplysm/sd-cli 14.0.42 → 14.0.44
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/angular/angular-compiler.d.ts +0 -35
- package/dist/angular/angular-compiler.d.ts.map +1 -1
- package/dist/angular/angular-compiler.js +0 -374
- package/dist/angular/angular-compiler.js.map +1 -1
- package/dist/angular/hmr-candidates.d.ts +13 -0
- package/dist/angular/hmr-candidates.d.ts.map +1 -0
- package/dist/angular/hmr-candidates.js +230 -0
- package/dist/angular/hmr-candidates.js.map +1 -0
- package/dist/angular/ngtsc-build-core.d.ts +41 -37
- package/dist/angular/ngtsc-build-core.d.ts.map +1 -1
- package/dist/angular/ngtsc-build-core.js +155 -52
- package/dist/angular/ngtsc-build-core.js.map +1 -1
- package/dist/angular/vite-angular-plugin.d.ts +1 -1
- package/dist/angular/vite-angular-plugin.d.ts.map +1 -1
- package/dist/angular/vite-angular-plugin.js +63 -56
- package/dist/angular/vite-angular-plugin.js.map +1 -1
- package/dist/angular/web-worker-transformer.d.ts +9 -0
- package/dist/angular/web-worker-transformer.d.ts.map +1 -0
- package/dist/angular/web-worker-transformer.js +73 -0
- package/dist/angular/web-worker-transformer.js.map +1 -0
- package/dist/capacitor/capacitor.d.ts.map +1 -1
- package/dist/capacitor/capacitor.js +6 -4
- package/dist/capacitor/capacitor.js.map +1 -1
- package/dist/commands/check.d.ts +1 -1
- package/dist/commands/check.d.ts.map +1 -1
- package/dist/commands/check.js +15 -65
- package/dist/commands/check.js.map +1 -1
- package/dist/commands/publish/deployment-phase.d.ts.map +1 -1
- package/dist/commands/publish/deployment-phase.js +13 -5
- package/dist/commands/publish/deployment-phase.js.map +1 -1
- package/dist/commands/publish/npm-publisher.js +1 -1
- package/dist/commands/publish/npm-publisher.js.map +1 -1
- package/dist/commands/publish/publish-command.js +1 -1
- package/dist/commands/publish/publish-command.js.map +1 -1
- package/dist/commands/publish/version-upgrade.d.ts.map +1 -1
- package/dist/commands/publish/version-upgrade.js +16 -13
- package/dist/commands/publish/version-upgrade.js.map +1 -1
- package/dist/commands/replace-deps.d.ts.map +1 -1
- package/dist/commands/replace-deps.js +2 -1
- package/dist/commands/replace-deps.js.map +1 -1
- package/dist/deps/replace-deps/collect-deps.d.ts.map +1 -1
- package/dist/deps/replace-deps/collect-deps.js +5 -2
- package/dist/deps/replace-deps/collect-deps.js.map +1 -1
- package/dist/deps/replace-deps/replace-deps-resolve.d.ts.map +1 -1
- package/dist/deps/replace-deps/replace-deps-resolve.js +6 -7
- package/dist/deps/replace-deps/replace-deps-resolve.js.map +1 -1
- package/dist/deps/replace-deps/replace-deps.d.ts +21 -3
- package/dist/deps/replace-deps/replace-deps.d.ts.map +1 -1
- package/dist/deps/replace-deps/replace-deps.js +175 -66
- package/dist/deps/replace-deps/replace-deps.js.map +1 -1
- package/dist/electron/electron.js +7 -7
- package/dist/electron/electron.js.map +1 -1
- package/dist/engines/BaseEngine.d.ts.map +1 -1
- package/dist/engines/BaseEngine.js +2 -5
- package/dist/engines/BaseEngine.js.map +1 -1
- package/dist/engines/EsbuildClientEngine.d.ts.map +1 -1
- package/dist/engines/EsbuildClientEngine.js +16 -9
- package/dist/engines/EsbuildClientEngine.js.map +1 -1
- package/dist/engines/NgtscEngine.d.ts +4 -4
- package/dist/engines/NgtscEngine.d.ts.map +1 -1
- package/dist/engines/NgtscEngine.js +5 -5
- package/dist/engines/NgtscEngine.js.map +1 -1
- package/dist/engines/TscEngine.d.ts.map +1 -1
- package/dist/engines/TscEngine.js +0 -2
- package/dist/engines/TscEngine.js.map +1 -1
- package/dist/engines/types.d.ts +2 -0
- package/dist/engines/types.d.ts.map +1 -1
- package/dist/esbuild/esbuild-angular-compiler-plugin.d.ts +36 -0
- package/dist/esbuild/esbuild-angular-compiler-plugin.d.ts.map +1 -0
- package/dist/esbuild/esbuild-angular-compiler-plugin.js +464 -0
- package/dist/esbuild/esbuild-angular-compiler-plugin.js.map +1 -0
- package/dist/esbuild/esbuild-client-config.d.ts +8 -2
- package/dist/esbuild/esbuild-client-config.d.ts.map +1 -1
- package/dist/esbuild/esbuild-client-config.js +48 -33
- package/dist/esbuild/esbuild-client-config.js.map +1 -1
- package/dist/esbuild/esbuild-postcss-plugin.d.ts.map +1 -1
- package/dist/esbuild/esbuild-postcss-plugin.js +9 -6
- package/dist/esbuild/esbuild-postcss-plugin.js.map +1 -1
- package/dist/esbuild/esbuild-tsc-plugin.d.ts +4 -1
- package/dist/esbuild/esbuild-tsc-plugin.d.ts.map +1 -1
- package/dist/esbuild/esbuild-tsc-plugin.js +27 -23
- package/dist/esbuild/esbuild-tsc-plugin.js.map +1 -1
- package/dist/esbuild/file-reference-tracker.d.ts +24 -0
- package/dist/esbuild/file-reference-tracker.d.ts.map +1 -0
- package/dist/esbuild/file-reference-tracker.js +57 -0
- package/dist/esbuild/file-reference-tracker.js.map +1 -0
- package/dist/esbuild/lmdb-cache-store.d.ts +18 -0
- package/dist/esbuild/lmdb-cache-store.d.ts.map +1 -0
- package/dist/esbuild/lmdb-cache-store.js +41 -0
- package/dist/esbuild/lmdb-cache-store.js.map +1 -0
- package/dist/esbuild/load-result-cache.d.ts +17 -0
- package/dist/esbuild/load-result-cache.d.ts.map +1 -0
- package/dist/esbuild/load-result-cache.js +61 -0
- package/dist/esbuild/load-result-cache.js.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/dist/lint/lint-core.js +7 -7
- package/dist/lint/lint-core.js.map +1 -1
- package/dist/orchestrators/BaseOrchestrator.js +2 -2
- package/dist/orchestrators/BaseOrchestrator.js.map +1 -1
- package/dist/orchestrators/BuildOrchestrator.d.ts.map +1 -1
- package/dist/orchestrators/BuildOrchestrator.js +5 -19
- package/dist/orchestrators/BuildOrchestrator.js.map +1 -1
- package/dist/orchestrators/DevOrchestrator.js +5 -5
- package/dist/orchestrators/DevOrchestrator.js.map +1 -1
- package/dist/orchestrators/WatchOrchestrator.js +6 -6
- package/dist/orchestrators/WatchOrchestrator.js.map +1 -1
- package/dist/runtime/ResultCollector.d.ts +1 -0
- package/dist/runtime/ResultCollector.d.ts.map +1 -1
- package/dist/runtime/ResultCollector.js.map +1 -1
- package/dist/runtime/engine-watch-events.d.ts.map +1 -1
- package/dist/runtime/engine-watch-events.js +3 -0
- package/dist/runtime/engine-watch-events.js.map +1 -1
- package/dist/runtime/rebuild-manager.js +1 -1
- package/dist/runtime/rebuild-manager.js.map +1 -1
- package/dist/runtime/worker-utils.js +1 -1
- package/dist/runtime/worker-utils.js.map +1 -1
- package/dist/sd-cli-entry.d.ts.map +1 -1
- package/dist/sd-cli-entry.js +4 -3
- package/dist/sd-cli-entry.js.map +1 -1
- package/dist/sd-cli.js +3 -3
- package/dist/sd-cli.js.map +1 -1
- package/dist/ts-compiler/SdTsCompiler.d.ts +39 -0
- package/dist/ts-compiler/SdTsCompiler.d.ts.map +1 -0
- package/dist/ts-compiler/SdTsCompiler.js +593 -0
- package/dist/ts-compiler/SdTsCompiler.js.map +1 -0
- package/dist/ts-compiler/sd-ts-compiler-options.d.ts +40 -0
- package/dist/ts-compiler/sd-ts-compiler-options.d.ts.map +1 -0
- package/dist/ts-compiler/sd-ts-compiler-options.js +2 -0
- package/dist/ts-compiler/sd-ts-compiler-options.js.map +1 -0
- package/dist/ts-compiler/sd-ts-compiler-result.d.ts +34 -0
- package/dist/ts-compiler/sd-ts-compiler-result.d.ts.map +1 -0
- package/dist/ts-compiler/sd-ts-compiler-result.js +2 -0
- package/dist/ts-compiler/sd-ts-compiler-result.js.map +1 -0
- package/dist/utils/copy-public.d.ts +6 -4
- package/dist/utils/copy-public.d.ts.map +1 -1
- package/dist/utils/copy-public.js +9 -7
- package/dist/utils/copy-public.js.map +1 -1
- package/dist/utils/diagnostic-utils.d.ts +2 -3
- package/dist/utils/diagnostic-utils.d.ts.map +1 -1
- package/dist/utils/diagnostic-utils.js +8 -9
- package/dist/utils/diagnostic-utils.js.map +1 -1
- package/dist/utils/output-utils.d.ts +8 -2
- package/dist/utils/output-utils.d.ts.map +1 -1
- package/dist/utils/output-utils.js +32 -8
- package/dist/utils/output-utils.js.map +1 -1
- package/dist/workers/client.worker.d.ts +1 -1
- package/dist/workers/client.worker.d.ts.map +1 -1
- package/dist/workers/client.worker.js +115 -110
- package/dist/workers/client.worker.js.map +1 -1
- package/dist/workers/incremental-mtime-tracker.d.ts +13 -0
- package/dist/workers/incremental-mtime-tracker.d.ts.map +1 -0
- package/dist/workers/incremental-mtime-tracker.js +65 -0
- package/dist/workers/incremental-mtime-tracker.js.map +1 -0
- package/dist/workers/library-build.worker.d.ts +0 -2
- package/dist/workers/library-build.worker.d.ts.map +1 -1
- package/dist/workers/library-build.worker.js +169 -70
- package/dist/workers/library-build.worker.js.map +1 -1
- package/dist/workers/server-build.worker.d.ts.map +1 -1
- package/dist/workers/server-build.worker.js +30 -57
- package/dist/workers/server-build.worker.js.map +1 -1
- package/dist/workers/server-esbuild-context.d.ts +7 -0
- package/dist/workers/server-esbuild-context.d.ts.map +1 -1
- package/dist/workers/server-esbuild-context.js +11 -2
- package/dist/workers/server-esbuild-context.js.map +1 -1
- package/package.json +5 -4
- package/src/angular/angular-compiler.ts +0 -502
- package/src/angular/hmr-candidates.ts +295 -0
- package/src/angular/ngtsc-build-core.ts +192 -91
- package/src/angular/vite-angular-plugin.ts +71 -65
- package/src/angular/web-worker-transformer.ts +117 -0
- package/src/capacitor/capacitor.ts +6 -4
- package/src/commands/check.ts +17 -76
- package/src/commands/publish/deployment-phase.ts +11 -7
- package/src/commands/publish/npm-publisher.ts +1 -1
- package/src/commands/publish/publish-command.ts +1 -1
- package/src/commands/publish/version-upgrade.ts +44 -35
- package/src/commands/replace-deps.ts +3 -1
- package/src/deps/replace-deps/collect-deps.ts +4 -2
- package/src/deps/replace-deps/replace-deps-resolve.ts +12 -7
- package/src/deps/replace-deps/replace-deps.ts +191 -69
- package/src/electron/electron.ts +7 -7
- package/src/engines/BaseEngine.ts +2 -6
- package/src/engines/EsbuildClientEngine.ts +16 -10
- package/src/engines/NgtscEngine.ts +7 -7
- package/src/engines/TscEngine.ts +0 -2
- package/src/engines/types.ts +2 -0
- package/src/esbuild/esbuild-angular-compiler-plugin.ts +647 -0
- package/src/esbuild/esbuild-client-config.ts +57 -41
- package/src/esbuild/esbuild-postcss-plugin.ts +9 -6
- package/src/esbuild/esbuild-tsc-plugin.ts +33 -23
- package/src/esbuild/file-reference-tracker.ts +61 -0
- package/src/esbuild/lmdb-cache-store.ts +46 -0
- package/src/esbuild/load-result-cache.ts +85 -0
- package/src/index.ts +5 -0
- package/src/lint/lint-core.ts +7 -7
- package/src/orchestrators/BaseOrchestrator.ts +2 -2
- package/src/orchestrators/BuildOrchestrator.ts +5 -24
- package/src/orchestrators/DevOrchestrator.ts +5 -5
- package/src/orchestrators/WatchOrchestrator.ts +6 -6
- package/src/runtime/ResultCollector.ts +1 -0
- package/src/runtime/engine-watch-events.ts +3 -0
- package/src/runtime/rebuild-manager.ts +1 -1
- package/src/runtime/worker-utils.ts +1 -1
- package/src/sd-cli-entry.ts +5 -3
- package/src/sd-cli.ts +4 -4
- package/src/ts-compiler/SdTsCompiler.ts +815 -0
- package/src/ts-compiler/sd-ts-compiler-options.ts +46 -0
- package/src/ts-compiler/sd-ts-compiler-result.ts +34 -0
- package/src/utils/copy-public.ts +9 -6
- package/src/utils/diagnostic-utils.ts +8 -9
- package/src/utils/output-utils.ts +38 -8
- package/src/workers/client.worker.ts +141 -126
- package/src/workers/incremental-mtime-tracker.ts +68 -0
- package/src/workers/library-build.worker.ts +214 -75
- package/src/workers/server-build.worker.ts +31 -61
- package/src/workers/server-esbuild-context.ts +14 -2
- package/tests/angular/fixtures/packages/basic-app/dist/styles.css +3 -0
- package/tests/angular/fixtures/packages/basic-app/scss/styles.scss +5 -0
- package/tests/angular/ngtsc-build-core.acc.spec.ts +210 -0
- package/tests/angular/ngtsc-build-core.spec.ts +52 -0
- package/tests/angular/vite-angular-plugin-sdtscompiler.verify.md +13 -0
- package/tests/angular/web-worker-transformer.spec.ts +154 -0
- package/tests/capacitor/capacitor-build.spec.ts +1 -1
- package/tests/capacitor/capacitor-icon.spec.ts +1 -1
- package/tests/capacitor/capacitor-init.spec.ts +1 -1
- package/tests/commands/check.spec.ts +90 -104
- package/tests/commands/publish.spec.ts +12 -4
- package/tests/commands/slice3-severity-cleanup.verify.md +12 -0
- package/tests/commands/version-upgrade.acc.spec.ts +210 -0
- package/tests/commands/version-upgrade.spec.ts +148 -0
- package/tests/deps/replace-deps/collect-deps.acc.spec.ts +62 -0
- package/tests/deps/replace-deps/collect-deps.spec.ts +49 -0
- package/tests/deps/replace-deps/replace-deps-filter.spec.ts +103 -0
- package/tests/deps/replace-deps/replace-deps-perf.verify.md +15 -0
- package/tests/deps/replace-deps/replace-deps-resolve.acc.spec.ts +124 -0
- package/tests/deps/replace-deps/replace-deps-setup.acc.spec.ts +156 -0
- package/tests/electron/electron.spec.ts +4 -1
- package/tests/engines/engine-adapter-isolation.spec.ts +5 -6
- package/tests/engines/engine-duplicate-output-removal.verify.md +10 -0
- package/tests/engines/esbuild-client-engine.acc.spec.ts +79 -0
- package/tests/engines/esbuild-client-engine.spec.ts +73 -3
- package/tests/esbuild/esbuild-angular-compiler-plugin-hmr.verify.md +23 -0
- package/tests/esbuild/esbuild-angular-compiler-plugin-onload.verify.md +21 -0
- package/tests/esbuild/esbuild-angular-compiler-plugin-onstart-extraction.verify.md +16 -0
- package/tests/esbuild/esbuild-angular-compiler-plugin-sdtscompiler.verify.md +15 -0
- package/tests/esbuild/esbuild-angular-compiler-plugin-stylesheet.verify.md +31 -0
- package/tests/esbuild/esbuild-angular-compiler-plugin-worker.verify.md +31 -0
- package/tests/esbuild/esbuild-angular-compiler-plugin.spec.ts +397 -0
- package/tests/esbuild/esbuild-angular-compiler-plugin.verify.md +21 -0
- package/tests/esbuild/esbuild-postcss-plugin-chunking.verify.md +17 -0
- package/tests/esbuild/esbuild-postcss-plugin.acc.spec.ts +152 -0
- package/tests/esbuild/esbuild-tsc-plugin-imports.verify.md +13 -0
- package/tests/esbuild/esbuild-tsc-plugin.acc.spec.ts +56 -111
- package/tests/esbuild/esbuild-tsc-plugin.spec.ts +116 -52
- package/tests/esbuild/file-reference-tracker.spec.ts +99 -0
- package/tests/esbuild/lmdb-cache-store.spec.ts +58 -0
- package/tests/esbuild/load-result-cache.acc.spec.ts +55 -0
- package/tests/esbuild/load-result-cache.spec.ts +133 -0
- package/tests/orchestrators/build-orchestrator.spec.ts +4 -3
- package/tests/orchestrators/dev-orchestrator.spec.ts +5 -5
- package/tests/orchestrators/slice1-stdout-to-consola.verify.md +10 -0
- package/tests/orchestrators/typecheck-orchestrator.spec.ts +1 -1
- package/tests/orchestrators/watch-orchestrator.spec.ts +7 -7
- package/tests/runtime/result-collector.spec.ts +64 -0
- package/tests/sd-cli-entry.spec.ts +3 -4
- package/tests/sd-cli-log-tag.verify.md +11 -0
- package/tests/ts-compiler/SdTsCompiler-affected-files.verify.md +8 -0
- package/tests/ts-compiler/SdTsCompiler-diagnostics.verify.md +12 -0
- package/tests/ts-compiler/SdTsCompiler-emit.verify.md +9 -0
- package/tests/ts-compiler/SdTsCompiler.acc.spec.ts +603 -0
- package/tests/ts-compiler/SdTsCompiler.spec.ts +265 -0
- package/tests/ts-compiler/SdTsCompiler.verify.md +41 -0
- package/tests/ts-compiler/fixtures/non-angular-pkg/.cache/typecheck-browser.tsbuildinfo +1 -0
- package/tests/ts-compiler/fixtures/non-angular-pkg/.cache/typecheck-node.tsbuildinfo +1 -0
- package/tests/ts-compiler/fixtures/non-angular-pkg/.cache/typecheck.tsbuildinfo +1 -0
- package/tests/ts-compiler/fixtures/non-angular-pkg/src/index.ts +3 -0
- package/tests/ts-compiler/fixtures/non-angular-pkg/src/util.ts +3 -0
- package/tests/ts-compiler/fixtures/non-angular-pkg/tests/sample.test-file.ts +3 -0
- package/tests/ts-compiler/fixtures/non-angular-pkg/tsconfig.json +12 -0
- package/tests/ts-compiler/scss-lint-integration.verify.md +14 -0
- package/tests/utils/angular-build.spec.ts +1 -1
- package/tests/utils/copy-public-outdir.verify.md +8 -0
- package/tests/utils/copy-public.acc.spec.ts +52 -0
- package/tests/utils/copy-public.spec.ts +56 -0
- package/tests/utils/diagnostic-utils.spec.ts +24 -15
- package/tests/utils/engine-watch-events.acc.spec.ts +59 -0
- package/tests/utils/engine-watch-events.spec.ts +58 -0
- package/tests/utils/esbuild-client-config-integration.verify.md +9 -0
- package/tests/utils/esbuild-client-config.acc.spec.ts +45 -61
- package/tests/utils/esbuild-client-config.spec.ts +70 -52
- package/tests/utils/ngtsc-build-core-write-emit.spec.ts +136 -12
- package/tests/utils/ngtsc-build-core.spec.ts +1 -44
- package/tests/utils/output-utils.spec.ts +133 -13
- package/tests/utils/replace-deps-watch.acc.spec.ts +7 -1
- package/tests/utils/replace-deps-watch.spec.ts +57 -1
- package/tests/utils/worker-utils.spec.ts +8 -2
- package/tests/workers/client-worker-initial-build-error.verify.md +2 -3
- package/tests/workers/client-worker-initial-build-warnings.verify.md +7 -0
- package/tests/workers/client-worker-mtime-incremental.verify.md +10 -0
- package/tests/workers/client-worker-refactor.verify.md +22 -0
- package/tests/workers/client-worker-ts-cache-invalidation.verify.md +12 -0
- package/tests/workers/client-worker.acc.spec.ts +6 -3
- package/tests/workers/incremental-mtime-tracker.acc.spec.ts +144 -0
- package/tests/workers/incremental-mtime-tracker.spec.ts +102 -0
- package/tests/workers/library-build-lint.spec.ts +40 -45
- package/tests/workers/library-build-worker.spec.ts +298 -40
- package/tests/workers/server-build-lint.spec.ts +59 -45
- package/tests/workers/server-build-worker.spec.ts +63 -24
- package/tests/workers/server-esbuild-context.acc.spec.ts +2 -0
- package/tests/workers/server-esbuild-context.spec.ts +2 -0
- package/tests/workers/server-runtime-worker.spec.ts +1 -1
- package/tests/workers/shared-worker-lifecycle.acc.spec.ts +1 -1
- package/dist/angular/angular-build-pipeline.d.ts +0 -97
- package/dist/angular/angular-build-pipeline.d.ts.map +0 -1
- package/dist/angular/angular-build-pipeline.js +0 -285
- package/dist/angular/angular-build-pipeline.js.map +0 -1
- package/dist/utils/tsc-build.d.ts +0 -51
- package/dist/utils/tsc-build.d.ts.map +0 -1
- package/dist/utils/tsc-build.js +0 -156
- package/dist/utils/tsc-build.js.map +0 -1
- package/dist/workers/ngtsc-build.worker.d.ts +0 -23
- package/dist/workers/ngtsc-build.worker.d.ts.map +0 -1
- package/dist/workers/ngtsc-build.worker.js +0 -267
- package/dist/workers/ngtsc-build.worker.js.map +0 -1
- package/src/angular/angular-build-pipeline.ts +0 -406
- package/src/utils/tsc-build.ts +0 -226
- package/src/workers/ngtsc-build.worker.ts +0 -351
- package/tests/angular/angular-build-pipeline.spec.ts +0 -247
- package/tests/angular/angular-compiler-aot.acc.spec.ts +0 -68
- package/tests/angular/angular-compiler-aot.spec.ts +0 -80
- package/tests/utils/angular-compiler-emit.spec.ts +0 -666
- package/tests/utils/angular-compiler.spec.ts +0 -707
- package/tests/utils/tsc-build.spec.ts +0 -527
- package/tests/workers/ngtsc-build-lint.spec.ts +0 -141
- package/tests/workers/ngtsc-build-worker.spec.ts +0 -199
|
@@ -1,406 +0,0 @@
|
|
|
1
|
-
import path from "path";
|
|
2
|
-
import fs from "fs";
|
|
3
|
-
import ts from "typescript";
|
|
4
|
-
import { pathx } from "@simplysm/core-node";
|
|
5
|
-
import { consola } from "consola";
|
|
6
|
-
import { AngularCompiler, type AngularSourceFileCache } from "./angular-compiler.js";
|
|
7
|
-
import type { EmitResult } from "./angular-compiler.js";
|
|
8
|
-
import {
|
|
9
|
-
trackDeps,
|
|
10
|
-
formatScssError,
|
|
11
|
-
type SideEffectScssOptions,
|
|
12
|
-
} from "./ngtsc-build-core.js";
|
|
13
|
-
import { createClientTransformStylesheet } from "./client-transform-stylesheet.js";
|
|
14
|
-
import { isWorkspaceDiagnostic } from "../utils/diagnostic-utils.js";
|
|
15
|
-
import { compileScssString, compileScssFile } from "./scss-compiler.js";
|
|
16
|
-
import { createOutputPathRewriter, rewriteScssImports } from "../utils/output-path-rewriter.js";
|
|
17
|
-
|
|
18
|
-
const logger = consola.withTag("sd:cli:build-pipeline");
|
|
19
|
-
|
|
20
|
-
//#region Types
|
|
21
|
-
|
|
22
|
-
export interface PipelineDiagnosticMessage {
|
|
23
|
-
file?: string;
|
|
24
|
-
line?: number;
|
|
25
|
-
message: string;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
export interface PipelineDiagnosticResult {
|
|
29
|
-
errors: PipelineDiagnosticMessage[];
|
|
30
|
-
warnings: PipelineDiagnosticMessage[];
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
export interface PipelineResult {
|
|
34
|
-
affectedFiles: ReadonlySet<ts.SourceFile>;
|
|
35
|
-
diagnostics: PipelineDiagnosticResult;
|
|
36
|
-
scssErrors: string[];
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
export interface WriteEmitResultsOptions {
|
|
40
|
-
/** 출력 대상 패키지 디렉토리 */
|
|
41
|
-
pkgDir: string;
|
|
42
|
-
/** emit 결과 필터 (src/ 하위만 등) */
|
|
43
|
-
sourceFilter?: (fileName: string) => boolean;
|
|
44
|
-
/** side-effect SCSS 옵션 */
|
|
45
|
-
scss?: SideEffectScssOptions;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
export interface AngularBuildPipelineOptions {
|
|
49
|
-
/** Pipeline 모드. SCSS 콜백 동작을 결정한다. */
|
|
50
|
-
mode: "client" | "library";
|
|
51
|
-
/** 패키지 디렉토리 */
|
|
52
|
-
pkgDir: string;
|
|
53
|
-
/** workspace 루트 */
|
|
54
|
-
cwd: string;
|
|
55
|
-
/** 소스 파일 목록 */
|
|
56
|
-
rootNames: string[];
|
|
57
|
-
/** TypeScript 컴파일러 옵션 */
|
|
58
|
-
compilerOptions: ts.CompilerOptions;
|
|
59
|
-
/** Angular 컴파일러 옵션 */
|
|
60
|
-
angularCompilerOptions?: Record<string, unknown>;
|
|
61
|
-
|
|
62
|
-
// AngularCompiler 전달 옵션
|
|
63
|
-
sourceFileCache?: AngularSourceFileCache;
|
|
64
|
-
externalStylesheets?: Map<string, string>;
|
|
65
|
-
compilerOptionsTransformer?: (opts: ts.CompilerOptions) => ts.CompilerOptions;
|
|
66
|
-
|
|
67
|
-
// client 모드 전용
|
|
68
|
-
postcssPlugins?: unknown[];
|
|
69
|
-
scssCacheDir?: string;
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
//#endregion
|
|
73
|
-
|
|
74
|
-
//#region Library SCSS transform
|
|
75
|
-
|
|
76
|
-
/**
|
|
77
|
-
* Library용 transformStylesheet 콜백 팩토리.
|
|
78
|
-
* AngularCompiler의 transformStylesheet 옵션에 주입된다.
|
|
79
|
-
*
|
|
80
|
-
* - 외부 .scss 파일: compileScssFile로 CSS 반환 + 의존성 기록
|
|
81
|
-
* - 외부 비-SCSS 파일 (.css 등): null 반환 (readResource가 처리)
|
|
82
|
-
* - 인라인 스타일: compileScssString으로 CSS 반환 + 의존성 기록
|
|
83
|
-
* - 에러 시: scssErrors에 추가, SCSS error comment 반환
|
|
84
|
-
*/
|
|
85
|
-
export function createLibraryTransformStylesheet(
|
|
86
|
-
loadPaths: string[],
|
|
87
|
-
scssErrors: string[],
|
|
88
|
-
scssDependencies: Map<string, Set<string>>,
|
|
89
|
-
): (data: string, containingFile: string, stylesheetFile?: string) => Promise<string | null> {
|
|
90
|
-
return (
|
|
91
|
-
data: string,
|
|
92
|
-
containingFile: string,
|
|
93
|
-
stylesheetFile?: string,
|
|
94
|
-
): Promise<string | null> => {
|
|
95
|
-
try {
|
|
96
|
-
if (stylesheetFile != null && stylesheetFile.endsWith(".scss")) {
|
|
97
|
-
const result = compileScssFile(stylesheetFile, loadPaths);
|
|
98
|
-
trackDeps(scssDependencies, containingFile, result.dependencies);
|
|
99
|
-
return Promise.resolve(result.css);
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
if (stylesheetFile != null) {
|
|
103
|
-
// .css 등 비-SCSS 파일 → null 반환 (readResource가 처리)
|
|
104
|
-
return Promise.resolve(null);
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
// 인라인 스타일 — SCSS로 컴파일
|
|
108
|
-
const result = compileScssString(data, containingFile, loadPaths);
|
|
109
|
-
trackDeps(scssDependencies, containingFile, result.dependencies);
|
|
110
|
-
return Promise.resolve(result.css);
|
|
111
|
-
} catch (err) {
|
|
112
|
-
scssErrors.push(formatScssError(err, containingFile));
|
|
113
|
-
return Promise.resolve("/* SCSS compilation error */");
|
|
114
|
-
}
|
|
115
|
-
};
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
//#endregion
|
|
119
|
-
|
|
120
|
-
//#region writeEmitResults
|
|
121
|
-
|
|
122
|
-
/**
|
|
123
|
-
* emitAffectedFiles 결과를 output-path-rewriting 적용 후 파일로 쓴다.
|
|
124
|
-
* scss 옵션이 제공되면 .js 파일 내 .scss side-effect import를 처리한다:
|
|
125
|
-
* 1. import 경로를 .scss → .css로 변환
|
|
126
|
-
* 2. 참조된 SCSS 파일을 CSS로 컴파일하여 dist에 출력
|
|
127
|
-
*/
|
|
128
|
-
export function writeEmitResults(
|
|
129
|
-
emitResults: Iterable<{ filename: string; contents: string; sourceFileName?: string }>,
|
|
130
|
-
pkgDir: string,
|
|
131
|
-
scss?: SideEffectScssOptions,
|
|
132
|
-
): void {
|
|
133
|
-
logger.debug("emit 결과 파일 쓰기 시작");
|
|
134
|
-
const rewritePath = createOutputPathRewriter(pkgDir);
|
|
135
|
-
for (const { filename, contents, sourceFileName } of emitResults) {
|
|
136
|
-
const rewrite = rewritePath(filename, contents);
|
|
137
|
-
if (rewrite == null) continue;
|
|
138
|
-
let [newPath, newContent] = rewrite;
|
|
139
|
-
|
|
140
|
-
// .js 파일 내 side-effect SCSS import 처리
|
|
141
|
-
if (scss != null && newPath.endsWith(".js")) {
|
|
142
|
-
const { text, scssImports } = rewriteScssImports(newContent);
|
|
143
|
-
newContent = text;
|
|
144
|
-
|
|
145
|
-
// 새 항목 등록 전에 이 소스 파일의 기존 레지스트리 항목 제거
|
|
146
|
-
if (scss.registry != null && sourceFileName != null) {
|
|
147
|
-
for (const [key, entry] of scss.registry) {
|
|
148
|
-
if (entry.sourceFileName === sourceFileName) {
|
|
149
|
-
scss.registry.delete(key);
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
if (scssImports.length > 0 && sourceFileName != null) {
|
|
155
|
-
const sourceDir = path.dirname(sourceFileName);
|
|
156
|
-
const outputDir = path.dirname(newPath);
|
|
157
|
-
|
|
158
|
-
for (const scssImport of scssImports) {
|
|
159
|
-
const scssAbsPath = path.resolve(sourceDir, scssImport);
|
|
160
|
-
const cssFileName = scssImport.replace(/\.scss$/, ".css");
|
|
161
|
-
const cssAbsPath = path.resolve(outputDir, cssFileName);
|
|
162
|
-
|
|
163
|
-
// 레지스트리가 제공된 경우 등록 (scssAbsPath를 키로 사용하여 중복 방지)
|
|
164
|
-
if (scss.registry != null) {
|
|
165
|
-
scss.registry.set(scssAbsPath, { scssAbsPath, cssAbsPath, sourceFileName });
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
try {
|
|
169
|
-
const result = compileScssFile(scssAbsPath, scss.loadPaths);
|
|
170
|
-
fs.mkdirSync(path.dirname(cssAbsPath), { recursive: true });
|
|
171
|
-
fs.writeFileSync(cssAbsPath, result.css, "utf-8");
|
|
172
|
-
trackDeps(scss.scssDependencies, sourceFileName, result.dependencies);
|
|
173
|
-
} catch (err) {
|
|
174
|
-
scss.scssErrors.push(formatScssError(err, scssAbsPath));
|
|
175
|
-
}
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
fs.mkdirSync(path.dirname(newPath), { recursive: true });
|
|
181
|
-
fs.writeFileSync(newPath, newContent, "utf-8");
|
|
182
|
-
}
|
|
183
|
-
logger.debug("emit 결과 파일 쓰기 완료");
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
//#endregion
|
|
187
|
-
|
|
188
|
-
export class AngularBuildPipeline {
|
|
189
|
-
private _compiler: AngularCompiler | undefined;
|
|
190
|
-
private readonly _scssDependencies = new Map<string, Set<string>>();
|
|
191
|
-
private readonly _scssErrors: string[] = [];
|
|
192
|
-
private readonly _emittedFilesBySource = new Map<string, string>();
|
|
193
|
-
private _latestEmitResults: EmitResult[] = [];
|
|
194
|
-
private _lastDiagnostics: PipelineDiagnosticResult = { errors: [], warnings: [] };
|
|
195
|
-
|
|
196
|
-
constructor(private readonly _options: AngularBuildPipelineOptions) {}
|
|
197
|
-
|
|
198
|
-
async initialize(): Promise<PipelineResult> {
|
|
199
|
-
// 1. scssErrors 리셋 (in-place, 콜백 클로저 유지)
|
|
200
|
-
this._scssErrors.length = 0;
|
|
201
|
-
|
|
202
|
-
// 2. SCSS 콜백 + AngularCompiler 생성 (최초 1회)
|
|
203
|
-
if (this._compiler == null) {
|
|
204
|
-
const loadPaths = [
|
|
205
|
-
path.join(this._options.pkgDir, "scss"),
|
|
206
|
-
path.join(this._options.cwd, "node_modules"),
|
|
207
|
-
];
|
|
208
|
-
|
|
209
|
-
const transformStylesheet =
|
|
210
|
-
this._options.mode === "client"
|
|
211
|
-
? createClientTransformStylesheet({
|
|
212
|
-
loadPaths,
|
|
213
|
-
postcssPlugins: this._options.postcssPlugins,
|
|
214
|
-
scssErrors: this._scssErrors,
|
|
215
|
-
scssDependencies: this._scssDependencies,
|
|
216
|
-
cacheDir: this._options.scssCacheDir,
|
|
217
|
-
})
|
|
218
|
-
: createLibraryTransformStylesheet(
|
|
219
|
-
loadPaths,
|
|
220
|
-
this._scssErrors,
|
|
221
|
-
this._scssDependencies,
|
|
222
|
-
);
|
|
223
|
-
|
|
224
|
-
this._compiler = new AngularCompiler({
|
|
225
|
-
rootNames: this._options.rootNames,
|
|
226
|
-
compilerOptions: this._options.compilerOptions,
|
|
227
|
-
angularCompilerOptions: this._options.angularCompilerOptions,
|
|
228
|
-
sourceFileCache: this._options.sourceFileCache,
|
|
229
|
-
transformStylesheet,
|
|
230
|
-
externalStylesheets: this._options.externalStylesheets,
|
|
231
|
-
compilerOptionsTransformer: this._options.compilerOptionsTransformer,
|
|
232
|
-
});
|
|
233
|
-
}
|
|
234
|
-
|
|
235
|
-
// 3. 초기화
|
|
236
|
-
logger.debug("Pipeline initialize 시작");
|
|
237
|
-
const initResult = await this._compiler.initialize();
|
|
238
|
-
|
|
239
|
-
// 4. emit 결과 수집
|
|
240
|
-
this._emittedFilesBySource.clear();
|
|
241
|
-
this._latestEmitResults = [];
|
|
242
|
-
for (const result of this._compiler.emitAffectedFiles()) {
|
|
243
|
-
const normalizedSource = pathx.posix(result.sourceFileName);
|
|
244
|
-
this._emittedFilesBySource.set(normalizedSource, result.contents);
|
|
245
|
-
this._latestEmitResults.push(result);
|
|
246
|
-
}
|
|
247
|
-
logger.debug(`Pipeline emit 완료: ${this._latestEmitResults.length}개 파일`);
|
|
248
|
-
|
|
249
|
-
// 5. 진단 수집
|
|
250
|
-
this._lastDiagnostics = this._collectDiagnostics();
|
|
251
|
-
|
|
252
|
-
const pipelineResult: PipelineResult = {
|
|
253
|
-
affectedFiles: initResult.affectedFiles,
|
|
254
|
-
diagnostics: this._lastDiagnostics,
|
|
255
|
-
scssErrors: [...this._scssErrors],
|
|
256
|
-
};
|
|
257
|
-
|
|
258
|
-
logger.debug(`Pipeline initialize 완료 (errors: ${this._lastDiagnostics.errors.length})`);
|
|
259
|
-
return pipelineResult;
|
|
260
|
-
}
|
|
261
|
-
|
|
262
|
-
async update(modifiedFiles: Iterable<string>): Promise<PipelineResult> {
|
|
263
|
-
if (this._compiler == null) {
|
|
264
|
-
throw new Error("initialize()를 먼저 호출해야 합니다");
|
|
265
|
-
}
|
|
266
|
-
|
|
267
|
-
// scssErrors 리셋
|
|
268
|
-
this._scssErrors.length = 0;
|
|
269
|
-
|
|
270
|
-
// compiler.update() — 내부적으로 sourceFileCache 무효화 + 재초기화
|
|
271
|
-
const updateResult = await this._compiler.update(modifiedFiles);
|
|
272
|
-
|
|
273
|
-
// emit 재수집 (기존 Map은 클리어하지 않음 — 추가/갱신만)
|
|
274
|
-
this._latestEmitResults = [];
|
|
275
|
-
for (const result of this._compiler.emitAffectedFiles()) {
|
|
276
|
-
const normalizedSource = pathx.posix(result.sourceFileName);
|
|
277
|
-
this._emittedFilesBySource.set(normalizedSource, result.contents);
|
|
278
|
-
this._latestEmitResults.push(result);
|
|
279
|
-
}
|
|
280
|
-
|
|
281
|
-
// 진단 재수집
|
|
282
|
-
this._lastDiagnostics = this._collectDiagnostics();
|
|
283
|
-
|
|
284
|
-
return {
|
|
285
|
-
affectedFiles: updateResult.affectedFiles,
|
|
286
|
-
diagnostics: this._lastDiagnostics,
|
|
287
|
-
scssErrors: [...this._scssErrors],
|
|
288
|
-
};
|
|
289
|
-
}
|
|
290
|
-
|
|
291
|
-
getEmittedFile(sourcePath: string): string | undefined {
|
|
292
|
-
const normalized = pathx.posix(sourcePath);
|
|
293
|
-
return this._emittedFilesBySource.get(normalized);
|
|
294
|
-
}
|
|
295
|
-
|
|
296
|
-
getEmittedFiles(): ReadonlyMap<string, string> {
|
|
297
|
-
return this._emittedFilesBySource;
|
|
298
|
-
}
|
|
299
|
-
|
|
300
|
-
/** 직전 initialize()/update()에서 실제로 emit된 소스 파일 경로 목록을 반환한다. */
|
|
301
|
-
getLatestEmittedSourcePaths(): string[] {
|
|
302
|
-
return this._latestEmitResults.map((r) => pathx.posix(r.sourceFileName));
|
|
303
|
-
}
|
|
304
|
-
|
|
305
|
-
writeEmitResults(options?: WriteEmitResultsOptions): void {
|
|
306
|
-
const pkgDir = options?.pkgDir ?? this._options.pkgDir;
|
|
307
|
-
const filteredResults =
|
|
308
|
-
options?.sourceFilter != null
|
|
309
|
-
? this._latestEmitResults.filter((r) => options.sourceFilter!(r.sourceFileName))
|
|
310
|
-
: this._latestEmitResults;
|
|
311
|
-
|
|
312
|
-
writeEmitResults(filteredResults, pkgDir, options?.scss);
|
|
313
|
-
}
|
|
314
|
-
|
|
315
|
-
findAffectedByScss(scssPath: string): string[] {
|
|
316
|
-
const normalizedPath = pathx.posix(scssPath);
|
|
317
|
-
const affected: string[] = [];
|
|
318
|
-
for (const [ownerFile, deps] of this._scssDependencies) {
|
|
319
|
-
if (deps.has(normalizedPath)) {
|
|
320
|
-
affected.push(ownerFile);
|
|
321
|
-
}
|
|
322
|
-
}
|
|
323
|
-
return affected;
|
|
324
|
-
}
|
|
325
|
-
|
|
326
|
-
getDiagnostics(): PipelineDiagnosticResult {
|
|
327
|
-
return this._lastDiagnostics;
|
|
328
|
-
}
|
|
329
|
-
|
|
330
|
-
getScssErrors(): readonly string[] {
|
|
331
|
-
return this._scssErrors;
|
|
332
|
-
}
|
|
333
|
-
|
|
334
|
-
collectRawDiagnostics(): ts.Diagnostic[] {
|
|
335
|
-
if (this._compiler == null) {
|
|
336
|
-
throw new Error("initialize()를 먼저 호출해야 합니다");
|
|
337
|
-
}
|
|
338
|
-
return [...this._compiler.collectDiagnostics()].filter(
|
|
339
|
-
(d) => isWorkspaceDiagnostic(d, this._options.cwd),
|
|
340
|
-
);
|
|
341
|
-
}
|
|
342
|
-
|
|
343
|
-
getTsProgram(): ts.Program {
|
|
344
|
-
if (this._compiler == null) {
|
|
345
|
-
throw new Error("initialize()를 먼저 호출해야 합니다");
|
|
346
|
-
}
|
|
347
|
-
return this._compiler.getTsProgram();
|
|
348
|
-
}
|
|
349
|
-
|
|
350
|
-
/**
|
|
351
|
-
* 내부 SCSS 의존성 맵을 반환한다.
|
|
352
|
-
* 호출자가 side-effect SCSS 의존성을 같은 맵에 기록하여
|
|
353
|
-
* findAffectedByScss()에서 통합 역방향 탐색이 가능하게 한다.
|
|
354
|
-
*/
|
|
355
|
-
getScssDependencies(): Map<string, Set<string>> {
|
|
356
|
-
return this._scssDependencies;
|
|
357
|
-
}
|
|
358
|
-
|
|
359
|
-
clearScssDependencies(): void {
|
|
360
|
-
this._scssDependencies.clear();
|
|
361
|
-
}
|
|
362
|
-
|
|
363
|
-
updateRootNames(rootNames: string[]): void {
|
|
364
|
-
this._options.rootNames = rootNames;
|
|
365
|
-
this._compiler?.updateRootNames(rootNames);
|
|
366
|
-
}
|
|
367
|
-
|
|
368
|
-
private _collectDiagnostics(): PipelineDiagnosticResult {
|
|
369
|
-
if (this._compiler == null) {
|
|
370
|
-
return { errors: [], warnings: [] };
|
|
371
|
-
}
|
|
372
|
-
|
|
373
|
-
const errors: PipelineDiagnosticMessage[] = [];
|
|
374
|
-
const warnings: PipelineDiagnosticMessage[] = [];
|
|
375
|
-
|
|
376
|
-
try {
|
|
377
|
-
for (const diagnostic of this._compiler.collectDiagnostics()) {
|
|
378
|
-
if (!isWorkspaceDiagnostic(diagnostic, this._options.cwd)) continue;
|
|
379
|
-
|
|
380
|
-
const message = ts.flattenDiagnosticMessageText(diagnostic.messageText, "\n");
|
|
381
|
-
const formatted: PipelineDiagnosticMessage = { message };
|
|
382
|
-
|
|
383
|
-
if (diagnostic.file != null) {
|
|
384
|
-
formatted.file = diagnostic.file.fileName;
|
|
385
|
-
if (diagnostic.start != null) {
|
|
386
|
-
const pos = diagnostic.file.getLineAndCharacterOfPosition(diagnostic.start);
|
|
387
|
-
formatted.line = pos.line + 1;
|
|
388
|
-
}
|
|
389
|
-
}
|
|
390
|
-
|
|
391
|
-
if (diagnostic.category === ts.DiagnosticCategory.Error) {
|
|
392
|
-
errors.push(formatted);
|
|
393
|
-
} else if (diagnostic.category === ts.DiagnosticCategory.Warning) {
|
|
394
|
-
warnings.push(formatted);
|
|
395
|
-
}
|
|
396
|
-
}
|
|
397
|
-
} catch {
|
|
398
|
-
// TypeScript 5.9 + NgtscProgram: getSemanticDiagnostics 내부에서
|
|
399
|
-
// referencedFiles 인덱스 불일치로 크래시할 수 있음.
|
|
400
|
-
// 수집된 진단 결과까지만 반환한다.
|
|
401
|
-
logger.warn("진단 수집 중 TypeScript 내부 에러 발생 — 부분 진단 결과 반환");
|
|
402
|
-
}
|
|
403
|
-
|
|
404
|
-
return { errors, warnings };
|
|
405
|
-
}
|
|
406
|
-
}
|
package/src/utils/tsc-build.ts
DELETED
|
@@ -1,226 +0,0 @@
|
|
|
1
|
-
import path from "path";
|
|
2
|
-
import ts from "typescript";
|
|
3
|
-
import { err as errNs } from "@simplysm/core-common";
|
|
4
|
-
import { consola } from "consola";
|
|
5
|
-
|
|
6
|
-
const logger = consola.withTag("sd:cli:tsc-build");
|
|
7
|
-
import { pathx } from "@simplysm/core-node";
|
|
8
|
-
import {
|
|
9
|
-
parseTsconfig,
|
|
10
|
-
getPackageSourceFiles,
|
|
11
|
-
getPackageFiles,
|
|
12
|
-
getCompilerOptionsForEnv,
|
|
13
|
-
type TypecheckEnv,
|
|
14
|
-
} from "./tsconfig";
|
|
15
|
-
import { serializeDiagnostic, type SerializedDiagnostic } from "../typecheck/typecheck-serialization";
|
|
16
|
-
import { createOutputPathRewriter, addJsExtensionToImports } from "./output-path-rewriter";
|
|
17
|
-
import { isWorkspaceDiagnostic, formatDiagnosticError } from "./diagnostic-utils";
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* 패키지 모드 tsc 빌드 옵션
|
|
21
|
-
*/
|
|
22
|
-
export interface TscPackageBuildOptions {
|
|
23
|
-
pkgDir: string;
|
|
24
|
-
cwd: string;
|
|
25
|
-
/** 출력 제어 플래그: emit할 파일 종류 */
|
|
26
|
-
output: { js: boolean; dts: boolean };
|
|
27
|
-
/** 미리 파싱된 tsconfig. 제공 시 parseTsconfig() 호출을 스킵한다. */
|
|
28
|
-
parsedConfig?: ts.ParsedCommandLine;
|
|
29
|
-
/** 타입체크 환경. 설정 시 getCompilerOptionsForEnv()로 compilerOptions를 조정한다. */
|
|
30
|
-
env?: TypecheckEnv;
|
|
31
|
-
/** 타입체크 전용 모드에서 tests/ 파일 포함 여부. 기본값 false. */
|
|
32
|
-
includeTests?: boolean;
|
|
33
|
-
/** 이전 빌드의 BuilderProgram. watch 모드에서 SourceFile 재사용을 위해 전달한다. */
|
|
34
|
-
oldBuilderProgram?: ts.EmitAndSemanticDiagnosticsBuilderProgram;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
/**
|
|
38
|
-
* 패키지 모드 tsc 빌드 결과
|
|
39
|
-
*/
|
|
40
|
-
export interface TscPackageBuildResult {
|
|
41
|
-
success: boolean;
|
|
42
|
-
errors?: string[];
|
|
43
|
-
diagnostics: SerializedDiagnostic[];
|
|
44
|
-
errorCount: number;
|
|
45
|
-
warningCount: number;
|
|
46
|
-
/** lint-with-program 통합을 위해 노출된 ts.Program */
|
|
47
|
-
program?: ts.Program;
|
|
48
|
-
/** 이 빌드에서 영향받은 파일 (정규화된 순방향 슬래시 경로).
|
|
49
|
-
* watch 모드에서 증분 lint에 사용한다. */
|
|
50
|
-
affectedFiles?: ReadonlySet<string>;
|
|
51
|
-
/** 다음 빌드에서 SourceFile 재사용을 위한 BuilderProgram.
|
|
52
|
-
* watch 모드에서 이 값을 저장해두고 다음 빌드 시 oldBuilderProgram으로 전달한다. */
|
|
53
|
-
builderProgram?: ts.EmitAndSemanticDiagnosticsBuilderProgram;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
/**
|
|
57
|
-
* 패키지에 대해 TypeScript 증분 빌드를 실행한다.
|
|
58
|
-
*
|
|
59
|
-
* - output.js || output.dts: emit 모드 (src 파일만, 출력 파일 생성)
|
|
60
|
-
* - 둘 다 아님: 타입체크만 (기본 src 파일만, includeTests=true이면 src + test 파일)
|
|
61
|
-
*
|
|
62
|
-
* 실행 간 증분 컴파일을 위해 tsBuildInfoFile을 사용한다.
|
|
63
|
-
*/
|
|
64
|
-
export function runTscPackageBuild(options: TscPackageBuildOptions): TscPackageBuildResult {
|
|
65
|
-
try {
|
|
66
|
-
const { pkgDir, output, env } = options;
|
|
67
|
-
const needsEmit = output.js || output.dts;
|
|
68
|
-
const pkgName = path.basename(pkgDir);
|
|
69
|
-
logger.debug(`[${pkgName}] tsc 빌드 시작 (env: ${env ?? "none"}, js: ${output.js}, dts: ${output.dts})`);
|
|
70
|
-
|
|
71
|
-
const parsedConfig = options.parsedConfig ?? parseTsconfig(pkgDir);
|
|
72
|
-
const baseOptions =
|
|
73
|
-
env != null
|
|
74
|
-
? getCompilerOptionsForEnv(parsedConfig.options, env, pkgDir)
|
|
75
|
-
: parsedConfig.options;
|
|
76
|
-
|
|
77
|
-
let rootFiles: string[];
|
|
78
|
-
|
|
79
|
-
if (needsEmit || !options.includeTests) {
|
|
80
|
-
rootFiles = getPackageSourceFiles(pkgDir, parsedConfig);
|
|
81
|
-
} else {
|
|
82
|
-
rootFiles = getPackageFiles(pkgDir, parsedConfig);
|
|
83
|
-
}
|
|
84
|
-
logger.debug(`[${pkgName}] rootFiles: ${rootFiles.length}개`);
|
|
85
|
-
|
|
86
|
-
const envSuffix = env != null ? `-${env}` : "";
|
|
87
|
-
const tsBuildInfoFile = path.join(
|
|
88
|
-
pkgDir,
|
|
89
|
-
".cache",
|
|
90
|
-
needsEmit
|
|
91
|
-
? `build${output.dts ? "" : "-no-dts"}${envSuffix}.tsbuildinfo`
|
|
92
|
-
: `typecheck${envSuffix}.tsbuildinfo`,
|
|
93
|
-
);
|
|
94
|
-
|
|
95
|
-
const compilerOptions: ts.CompilerOptions = {
|
|
96
|
-
...baseOptions,
|
|
97
|
-
sourceMap: output.js,
|
|
98
|
-
incremental: true,
|
|
99
|
-
tsBuildInfoFile,
|
|
100
|
-
};
|
|
101
|
-
|
|
102
|
-
if (output.js && output.dts) {
|
|
103
|
-
compilerOptions.noEmit = false;
|
|
104
|
-
compilerOptions.emitDeclarationOnly = false;
|
|
105
|
-
compilerOptions.declaration = true;
|
|
106
|
-
compilerOptions.declarationMap = true;
|
|
107
|
-
compilerOptions.outDir = path.join(pkgDir, "dist");
|
|
108
|
-
compilerOptions.declarationDir = path.join(pkgDir, "dist");
|
|
109
|
-
} else if (output.js) {
|
|
110
|
-
compilerOptions.noEmit = false;
|
|
111
|
-
compilerOptions.emitDeclarationOnly = false;
|
|
112
|
-
compilerOptions.declaration = false;
|
|
113
|
-
compilerOptions.declarationMap = false;
|
|
114
|
-
compilerOptions.outDir = path.join(pkgDir, "dist");
|
|
115
|
-
} else if (output.dts) {
|
|
116
|
-
compilerOptions.noEmit = false;
|
|
117
|
-
compilerOptions.emitDeclarationOnly = true;
|
|
118
|
-
compilerOptions.declaration = true;
|
|
119
|
-
compilerOptions.declarationMap = true;
|
|
120
|
-
compilerOptions.outDir = path.join(pkgDir, "dist");
|
|
121
|
-
compilerOptions.declarationDir = path.join(pkgDir, "dist");
|
|
122
|
-
} else {
|
|
123
|
-
compilerOptions.noEmit = true;
|
|
124
|
-
compilerOptions.emitDeclarationOnly = false;
|
|
125
|
-
compilerOptions.declaration = false;
|
|
126
|
-
compilerOptions.declarationMap = false;
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
const host = ts.createIncrementalCompilerHost(compilerOptions);
|
|
130
|
-
|
|
131
|
-
if (needsEmit) {
|
|
132
|
-
const rewritePath = createOutputPathRewriter(pkgDir);
|
|
133
|
-
const originalWriteFile = host.writeFile;
|
|
134
|
-
host.writeFile = (fileName, content, writeByteOrderMark, onError, sourceFiles, data) => {
|
|
135
|
-
const result = rewritePath(fileName, content);
|
|
136
|
-
if (result != null) {
|
|
137
|
-
let [newPath, newContent] = result;
|
|
138
|
-
if (newPath.endsWith(".js")) {
|
|
139
|
-
newContent = addJsExtensionToImports(newContent);
|
|
140
|
-
}
|
|
141
|
-
originalWriteFile(newPath, newContent, writeByteOrderMark, onError, sourceFiles, data);
|
|
142
|
-
}
|
|
143
|
-
};
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
const builderProgram = ts.createEmitAndSemanticDiagnosticsBuilderProgram(
|
|
147
|
-
rootFiles,
|
|
148
|
-
compilerOptions,
|
|
149
|
-
host,
|
|
150
|
-
options.oldBuilderProgram,
|
|
151
|
-
);
|
|
152
|
-
|
|
153
|
-
// builder program의 증분 분석을 통해 affected 파일을 추적한다.
|
|
154
|
-
// getSemanticDiagnosticsOfNextAffectedFile은 마지막 빌드 이후 변경된 파일을 순회한다.
|
|
155
|
-
// affected는 ts.SourceFile 또는 ts.Program(전역 스코프 변경 시)일 수 있다.
|
|
156
|
-
let affectedFiles: Set<string> | undefined = new Set<string>();
|
|
157
|
-
|
|
158
|
-
while (true) {
|
|
159
|
-
const result = builderProgram.getSemanticDiagnosticsOfNextAffectedFile();
|
|
160
|
-
if (result == null) break;
|
|
161
|
-
if ("fileName" in result.affected) {
|
|
162
|
-
affectedFiles?.add(pathx.posix(result.affected.fileName));
|
|
163
|
-
} else {
|
|
164
|
-
// ts.Program 반환 — 전역 변경, 전체 재빌드로 처리
|
|
165
|
-
affectedFiles = undefined;
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
logger.debug(`[${pkgName}] affected files: ${affectedFiles != null ? `${affectedFiles.size}개` : "전체 (global change)"}`);
|
|
169
|
-
|
|
170
|
-
const emitResult = builderProgram.emit();
|
|
171
|
-
|
|
172
|
-
const allDiagnostics = [
|
|
173
|
-
...builderProgram.getConfigFileParsingDiagnostics(),
|
|
174
|
-
...builderProgram.getSyntacticDiagnostics(),
|
|
175
|
-
...builderProgram.getOptionsDiagnostics(),
|
|
176
|
-
...builderProgram.getGlobalDiagnostics(),
|
|
177
|
-
...builderProgram.getSemanticDiagnostics(),
|
|
178
|
-
...(!output.dts ? builderProgram.getProgram().getDeclarationDiagnostics() : []),
|
|
179
|
-
...emitResult.diagnostics,
|
|
180
|
-
];
|
|
181
|
-
|
|
182
|
-
// 워크스페이스 범위: node_modules 제외, 모든 워크스페이스 진단 유지
|
|
183
|
-
const filteredDiagnostics = allDiagnostics.filter(
|
|
184
|
-
(d) => isWorkspaceDiagnostic(d, options.cwd),
|
|
185
|
-
);
|
|
186
|
-
|
|
187
|
-
const serializedDiagnostics = filteredDiagnostics.map(serializeDiagnostic);
|
|
188
|
-
const errorCount = filteredDiagnostics.filter(
|
|
189
|
-
(d) => d.category === ts.DiagnosticCategory.Error,
|
|
190
|
-
).length;
|
|
191
|
-
const warningCount = filteredDiagnostics.filter(
|
|
192
|
-
(d) => d.category === ts.DiagnosticCategory.Warning,
|
|
193
|
-
).length;
|
|
194
|
-
|
|
195
|
-
const errors = filteredDiagnostics
|
|
196
|
-
.filter((d) => d.category === ts.DiagnosticCategory.Error)
|
|
197
|
-
.map(formatDiagnosticError);
|
|
198
|
-
|
|
199
|
-
logger.debug(`[${pkgName}] tsc 빌드 완료 (에러: ${errorCount}, 경고: ${warningCount})`);
|
|
200
|
-
return {
|
|
201
|
-
success: errorCount === 0,
|
|
202
|
-
errors: errors.length > 0 ? errors : undefined,
|
|
203
|
-
diagnostics: serializedDiagnostics,
|
|
204
|
-
errorCount,
|
|
205
|
-
warningCount,
|
|
206
|
-
program: builderProgram.getProgram(),
|
|
207
|
-
affectedFiles,
|
|
208
|
-
builderProgram,
|
|
209
|
-
};
|
|
210
|
-
} catch (err) {
|
|
211
|
-
const message = errNs.message(err);
|
|
212
|
-
const stack = err instanceof Error ? err.stack : undefined;
|
|
213
|
-
const pkgName = path.basename(options.pkgDir);
|
|
214
|
-
logger.debug(`[${pkgName}] tsc 빌드 예외 발생: ${message}`);
|
|
215
|
-
if (stack != null) {
|
|
216
|
-
logger.debug(`[${pkgName}] 스택 트레이스:\n${stack}`);
|
|
217
|
-
}
|
|
218
|
-
return {
|
|
219
|
-
success: false,
|
|
220
|
-
errors: [message],
|
|
221
|
-
diagnostics: [],
|
|
222
|
-
errorCount: 1,
|
|
223
|
-
warningCount: 0,
|
|
224
|
-
};
|
|
225
|
-
}
|
|
226
|
-
}
|