@simplysm/sd-cli 14.0.15 → 14.0.17
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/README.md +4 -3
- package/dist/angular/client-transform-stylesheet.d.ts +2 -0
- package/dist/angular/client-transform-stylesheet.d.ts.map +1 -1
- package/dist/angular/client-transform-stylesheet.js +88 -2
- package/dist/angular/client-transform-stylesheet.js.map +1 -1
- package/dist/angular/vite-angular-plugin.d.ts +7 -0
- package/dist/angular/vite-angular-plugin.d.ts.map +1 -1
- package/dist/angular/vite-angular-plugin.js +78 -16
- package/dist/angular/vite-angular-plugin.js.map +1 -1
- package/dist/capacitor/capacitor.d.ts.map +1 -1
- package/dist/capacitor/capacitor.js +24 -13
- package/dist/capacitor/capacitor.js.map +1 -1
- package/dist/commands/check.d.ts.map +1 -1
- package/dist/commands/check.js +8 -9
- package/dist/commands/check.js.map +1 -1
- package/dist/commands/device.d.ts +1 -1
- package/dist/commands/device.d.ts.map +1 -1
- package/dist/commands/device.js +61 -12
- package/dist/commands/device.js.map +1 -1
- package/dist/commands/lint.d.ts +0 -1
- package/dist/commands/lint.d.ts.map +1 -1
- package/dist/commands/lint.js +2 -3
- package/dist/commands/lint.js.map +1 -1
- package/dist/commands/publish.js +3 -3
- package/dist/commands/publish.js.map +1 -1
- package/dist/commands/replace-deps.js +1 -1
- package/dist/commands/replace-deps.js.map +1 -1
- package/dist/commands/typecheck.d.ts.map +1 -1
- package/dist/commands/typecheck.js +1 -2
- package/dist/commands/typecheck.js.map +1 -1
- package/dist/electron/electron.d.ts +3 -2
- package/dist/electron/electron.d.ts.map +1 -1
- package/dist/electron/electron.js +54 -31
- package/dist/electron/electron.js.map +1 -1
- package/dist/engines/BaseEngine.js +1 -1
- package/dist/engines/BaseEngine.js.map +1 -1
- package/dist/engines/NgtscEngine.d.ts.map +1 -1
- package/dist/engines/NgtscEngine.js +0 -1
- package/dist/engines/NgtscEngine.js.map +1 -1
- package/dist/engines/ServerEsbuildEngine.d.ts.map +1 -1
- package/dist/engines/ServerEsbuildEngine.js +0 -1
- package/dist/engines/ServerEsbuildEngine.js.map +1 -1
- package/dist/engines/TscEngine.d.ts.map +1 -1
- package/dist/engines/TscEngine.js +0 -1
- package/dist/engines/TscEngine.js.map +1 -1
- package/dist/engines/ViteEngine.d.ts.map +1 -1
- package/dist/engines/ViteEngine.js +10 -1
- package/dist/engines/ViteEngine.js.map +1 -1
- package/dist/engines/index.d.ts +0 -10
- package/dist/engines/index.d.ts.map +1 -1
- package/dist/engines/index.js +0 -5
- package/dist/engines/index.js.map +1 -1
- package/dist/engines/types.d.ts +0 -1
- package/dist/engines/types.d.ts.map +1 -1
- package/dist/infra/SignalHandler.d.ts +1 -6
- package/dist/infra/SignalHandler.d.ts.map +1 -1
- package/dist/infra/SignalHandler.js +4 -13
- package/dist/infra/SignalHandler.js.map +1 -1
- package/dist/orchestrators/BuildOrchestrator.d.ts.map +1 -1
- package/dist/orchestrators/BuildOrchestrator.js +7 -12
- package/dist/orchestrators/BuildOrchestrator.js.map +1 -1
- package/dist/orchestrators/DevWatchOrchestrator.d.ts.map +1 -1
- package/dist/orchestrators/DevWatchOrchestrator.js +18 -11
- package/dist/orchestrators/DevWatchOrchestrator.js.map +1 -1
- package/dist/sd-cli-entry.d.ts +0 -1
- package/dist/sd-cli-entry.d.ts.map +1 -1
- package/dist/sd-cli-entry.js +13 -16
- package/dist/sd-cli-entry.js.map +1 -1
- package/dist/sd-cli.js +1 -1
- package/dist/sd-cli.js.map +1 -1
- package/dist/sd-config.types.d.ts +12 -2
- package/dist/sd-config.types.d.ts.map +1 -1
- package/dist/utils/angular-compiler.d.ts.map +1 -1
- package/dist/utils/angular-compiler.js +20 -13
- package/dist/utils/angular-compiler.js.map +1 -1
- package/dist/utils/esbuild-config.d.ts +1 -1
- package/dist/utils/esbuild-config.d.ts.map +1 -1
- package/dist/utils/esbuild-config.js +1 -4
- package/dist/utils/esbuild-config.js.map +1 -1
- package/dist/utils/ngtsc-build-core.d.ts.map +1 -1
- package/dist/utils/ngtsc-build-core.js +3 -0
- package/dist/utils/ngtsc-build-core.js.map +1 -1
- package/dist/utils/orchestrator-utils.js +1 -1
- package/dist/utils/orchestrator-utils.js.map +1 -1
- package/dist/utils/tsc-build.d.ts +5 -0
- package/dist/utils/tsc-build.d.ts.map +1 -1
- package/dist/utils/tsc-build.js +2 -1
- package/dist/utils/tsc-build.js.map +1 -1
- package/dist/utils/vite-config.d.ts +1 -1
- package/dist/utils/vite-config.d.ts.map +1 -1
- package/dist/utils/vite-config.js +22 -53
- package/dist/utils/vite-config.js.map +1 -1
- package/dist/utils/vite-pwa-plugin.d.ts +9 -0
- package/dist/utils/vite-pwa-plugin.d.ts.map +1 -0
- package/dist/utils/vite-pwa-plugin.js +139 -0
- package/dist/utils/vite-pwa-plugin.js.map +1 -0
- package/dist/utils/worker-utils.d.ts +2 -5
- package/dist/utils/worker-utils.d.ts.map +1 -1
- package/dist/utils/worker-utils.js +5 -11
- package/dist/utils/worker-utils.js.map +1 -1
- package/dist/workers/client.worker.d.ts.map +1 -1
- package/dist/workers/client.worker.js +9 -3
- package/dist/workers/client.worker.js.map +1 -1
- package/dist/workers/library-build.worker.d.ts.map +1 -1
- package/dist/workers/library-build.worker.js +6 -2
- package/dist/workers/library-build.worker.js.map +1 -1
- package/dist/workers/ngtsc-build.worker.js +2 -2
- package/dist/workers/ngtsc-build.worker.js.map +1 -1
- package/dist/workers/server-build.worker.d.ts.map +1 -1
- package/dist/workers/server-build.worker.js +6 -2
- package/dist/workers/server-build.worker.js.map +1 -1
- package/dist/workers/server-runtime.worker.js +4 -4
- package/dist/workers/server-runtime.worker.js.map +1 -1
- package/docs/config.md +30 -2
- package/docs/pwa-configuration-types.md +1 -1
- package/package.json +8 -10
- package/src/angular/client-transform-stylesheet.ts +104 -2
- package/src/angular/vite-angular-plugin.ts +92 -31
- package/src/capacitor/capacitor.ts +25 -26
- package/src/commands/check.ts +8 -11
- package/src/commands/device.ts +71 -17
- package/src/commands/lint.ts +2 -3
- package/src/commands/publish.ts +3 -3
- package/src/commands/replace-deps.ts +1 -1
- package/src/commands/typecheck.ts +1 -2
- package/src/electron/electron.ts +62 -43
- package/src/engines/BaseEngine.ts +1 -1
- package/src/engines/NgtscEngine.ts +0 -1
- package/src/engines/ServerEsbuildEngine.ts +0 -1
- package/src/engines/TscEngine.ts +0 -1
- package/src/engines/ViteEngine.ts +9 -1
- package/src/engines/index.ts +0 -10
- package/src/engines/types.ts +0 -1
- package/src/infra/SignalHandler.ts +4 -14
- package/src/orchestrators/BuildOrchestrator.ts +7 -9
- package/src/orchestrators/DevWatchOrchestrator.ts +22 -10
- package/src/sd-cli-entry.ts +17 -24
- package/src/sd-cli.ts +1 -1
- package/src/sd-config.types.ts +13 -2
- package/src/utils/angular-compiler.ts +21 -21
- package/src/utils/esbuild-config.ts +2 -5
- package/src/utils/ngtsc-build-core.ts +7 -0
- package/src/utils/orchestrator-utils.ts +1 -1
- package/src/utils/tsc-build.ts +7 -0
- package/src/utils/vite-config.ts +23 -55
- package/src/utils/vite-pwa-plugin.ts +168 -0
- package/src/utils/worker-utils.ts +5 -11
- package/src/workers/client.worker.ts +11 -3
- package/src/workers/library-build.worker.ts +6 -2
- package/src/workers/ngtsc-build.worker.ts +2 -2
- package/src/workers/server-build.worker.ts +7 -2
- package/src/workers/server-runtime.worker.ts +4 -4
- package/tests/angular/client-transform-stylesheet.spec.ts +43 -0
- package/tests/angular/find-affected-by-scss.spec.ts +37 -0
- package/tests/angular/fixtures/basic-app/scss/_colors.scss +1 -0
- package/tests/angular/fixtures/basic-app/scss/_variables.scss +3 -0
- package/tests/angular/fixtures/basic-app/src/styled.component.ts +14 -0
- package/tests/angular/linker-disk-cache.spec.ts +158 -0
- package/tests/angular/scss-disk-cache.spec.ts +162 -0
- package/tests/angular/vite-angular-plugin-hmr-fallback.spec.ts +15 -15
- package/tests/angular/vite-angular-plugin-hmr.spec.ts +9 -9
- package/tests/angular/vite-angular-plugin-lint.spec.ts +4 -4
- package/tests/angular/vite-angular-plugin-scss-hmr.spec.ts +87 -0
- package/tests/angular/vite-angular-plugin.spec.ts +15 -15
- package/tests/capacitor/capacitor-icon.spec.ts +2 -4
- package/tests/capacitor/capacitor-init.spec.ts +2 -4
- package/tests/capacitor/capacitor-workspace.spec.ts +2 -4
- package/tests/commands/device.spec.ts +108 -8
- package/tests/commands/publish.spec.ts +2 -2
- package/tests/commands/typecheck.spec.ts +1 -1
- package/tests/electron/electron.spec.ts +24 -17
- package/tests/engines/ngtsc-engine.spec.ts +0 -3
- package/tests/engines/server-esbuild-engine.spec.ts +0 -3
- package/tests/engines/tsc-engine.spec.ts +1 -2
- package/tests/engines/vite-engine.spec.ts +0 -2
- package/tests/infra/signal-handler.spec.ts +1 -12
- package/tests/orchestrators/build-orchestrator.spec.ts +1 -7
- package/tests/orchestrators/dev-watch-orchestrator.spec.ts +24 -66
- package/tests/utils/angular-compiler.spec.ts +1396 -32
- package/tests/utils/esbuild-config.spec.ts +4 -7
- package/tests/utils/{ngtsc-build-core-angular-compiler.spec.ts → ngtsc-build-core.spec.ts} +142 -11
- package/tests/utils/orchestrator-utils.spec.ts +2 -2
- package/tests/utils/sd-config.spec.ts +2 -2
- package/tests/utils/tsc-build.spec.ts +4 -1
- package/tests/utils/vite-config.spec.ts +130 -261
- package/tests/utils/vite-pwa-plugin.acc.spec.ts +143 -0
- package/tests/utils/vite-pwa-plugin.spec.ts +350 -0
- package/tests/utils/worker-utils.spec.ts +8 -7
- package/tests/workers/client-worker.spec.ts +50 -1
- package/tests/workers/dev-port-file.verify.md +6 -0
- package/tests/workers/library-build-lint.spec.ts +1 -1
- package/tests/workers/library-build-worker.spec.ts +1 -1
- package/tests/workers/ngtsc-build-lint.spec.ts +1 -1
- package/tests/workers/server-build-lint.spec.ts +1 -1
- package/tests/workers/server-build-worker.spec.ts +1 -1
- package/tests/workers/server-runtime-worker.spec.ts +8 -1
- package/dist/infra/WorkerManager.d.ts +0 -40
- package/dist/infra/WorkerManager.d.ts.map +0 -1
- package/dist/infra/WorkerManager.js +0 -59
- package/dist/infra/WorkerManager.js.map +0 -1
- package/dist/utils/SdCliReporter.d.ts +0 -18
- package/dist/utils/SdCliReporter.d.ts.map +0 -1
- package/dist/utils/SdCliReporter.js +0 -144
- package/dist/utils/SdCliReporter.js.map +0 -1
- package/src/infra/WorkerManager.ts +0 -65
- package/src/utils/SdCliReporter.ts +0 -177
- package/tests/angular/scss-compiler-async.spec.ts +0 -54
- package/tests/commands/dev.spec.ts +0 -53
- package/tests/commands/watch.spec.ts +0 -53
- package/tests/infra/worker-manager.spec.ts +0 -63
- package/tests/utils/angular-compiler-emit.spec.ts +0 -570
- package/tests/utils/angular-compiler-init.spec.ts +0 -705
- package/tests/utils/angular-compiler-update.spec.ts +0 -293
- package/tests/utils/build-env.spec.ts +0 -33
- package/tests/utils/ngtsc-build-core-transform-stylesheet.spec.ts +0 -124
- package/tests/utils/ngtsc-scss-refactor.spec.ts +0 -47
|
@@ -1,293 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect, vi, beforeEach } from "vitest";
|
|
2
|
-
import ts from "typescript";
|
|
3
|
-
import path from "path";
|
|
4
|
-
import fs from "fs";
|
|
5
|
-
import os from "os";
|
|
6
|
-
|
|
7
|
-
// --- Mock Setup ---
|
|
8
|
-
|
|
9
|
-
const mockAnalyzeAsync = vi.fn().mockResolvedValue(undefined);
|
|
10
|
-
const mockGetDiagnosticsForFile = vi.fn().mockReturnValue([]);
|
|
11
|
-
const mockGetOptionDiagnostics = vi.fn().mockReturnValue([]);
|
|
12
|
-
const mockGetResourceDependencies = vi.fn().mockReturnValue([]);
|
|
13
|
-
const mockIgnoreForDiagnostics = new Set<ts.SourceFile>();
|
|
14
|
-
const mockIgnoreForEmit = new Set<ts.SourceFile>();
|
|
15
|
-
const mockSafeToSkipEmit = vi.fn().mockReturnValue(false);
|
|
16
|
-
const mockRecordSuccessfulEmit = vi.fn();
|
|
17
|
-
const mockPrepareEmit = vi.fn().mockReturnValue({
|
|
18
|
-
transformers: { before: [], after: [] },
|
|
19
|
-
});
|
|
20
|
-
|
|
21
|
-
const ngtscConstructorSpy = vi.fn();
|
|
22
|
-
|
|
23
|
-
function createRealTsProgram(
|
|
24
|
-
files: Record<string, string> = { "index.ts": "export const x = 1;" },
|
|
25
|
-
extraOptions: ts.CompilerOptions = {},
|
|
26
|
-
): { program: ts.Program; dir: string; rootNames: string[] } {
|
|
27
|
-
const dir = fs.mkdtempSync(path.join(os.tmpdir(), "angular-compiler-update-"));
|
|
28
|
-
const rootNames: string[] = [];
|
|
29
|
-
for (const [name, content] of Object.entries(files)) {
|
|
30
|
-
const filePath = path.join(dir, name);
|
|
31
|
-
fs.mkdirSync(path.dirname(filePath), { recursive: true });
|
|
32
|
-
fs.writeFileSync(filePath, content, "utf-8");
|
|
33
|
-
rootNames.push(filePath);
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
const options: ts.CompilerOptions = {
|
|
37
|
-
target: ts.ScriptTarget.ESNext,
|
|
38
|
-
module: ts.ModuleKind.ESNext,
|
|
39
|
-
moduleResolution: ts.ModuleResolutionKind.Bundler,
|
|
40
|
-
strict: false,
|
|
41
|
-
skipLibCheck: true,
|
|
42
|
-
types: [],
|
|
43
|
-
outDir: path.join(dir, "out"),
|
|
44
|
-
...extraOptions,
|
|
45
|
-
};
|
|
46
|
-
const host = ts.createCompilerHost(options);
|
|
47
|
-
const program = ts.createProgram(rootNames, options, host);
|
|
48
|
-
return { program, dir, rootNames };
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
let realProgram: { program: ts.Program; dir: string; rootNames: string[] };
|
|
52
|
-
|
|
53
|
-
vi.mock("../../src/utils/angular-build", () => {
|
|
54
|
-
class NgtscProgram {
|
|
55
|
-
compiler = {
|
|
56
|
-
analyzeAsync: mockAnalyzeAsync,
|
|
57
|
-
getDiagnosticsForFile: mockGetDiagnosticsForFile,
|
|
58
|
-
getOptionDiagnostics: mockGetOptionDiagnostics,
|
|
59
|
-
getResourceDependencies: mockGetResourceDependencies,
|
|
60
|
-
ignoreForDiagnostics: mockIgnoreForDiagnostics,
|
|
61
|
-
ignoreForEmit: mockIgnoreForEmit,
|
|
62
|
-
incrementalCompilation: {
|
|
63
|
-
safeToSkipEmit: mockSafeToSkipEmit,
|
|
64
|
-
recordSuccessfulEmit: mockRecordSuccessfulEmit,
|
|
65
|
-
},
|
|
66
|
-
prepareEmit: mockPrepareEmit,
|
|
67
|
-
};
|
|
68
|
-
constructor(...args: unknown[]) {
|
|
69
|
-
ngtscConstructorSpy(...args);
|
|
70
|
-
}
|
|
71
|
-
getTsProgram() {
|
|
72
|
-
return realProgram.program;
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
return {
|
|
76
|
-
NgtscProgram,
|
|
77
|
-
OptimizeFor: { WholeProgram: 0, SingleFile: 1 },
|
|
78
|
-
};
|
|
79
|
-
});
|
|
80
|
-
|
|
81
|
-
const { AngularCompiler, AngularSourceFileCache } = await import(
|
|
82
|
-
"../../src/utils/angular-compiler"
|
|
83
|
-
);
|
|
84
|
-
|
|
85
|
-
// --- Tests ---
|
|
86
|
-
|
|
87
|
-
beforeEach(() => {
|
|
88
|
-
vi.clearAllMocks();
|
|
89
|
-
mockIgnoreForDiagnostics.clear();
|
|
90
|
-
mockIgnoreForEmit.clear();
|
|
91
|
-
mockGetResourceDependencies.mockReturnValue([]);
|
|
92
|
-
mockGetDiagnosticsForFile.mockReturnValue([]);
|
|
93
|
-
mockSafeToSkipEmit.mockReturnValue(false);
|
|
94
|
-
mockRecordSuccessfulEmit.mockReset();
|
|
95
|
-
mockPrepareEmit.mockReturnValue({
|
|
96
|
-
transformers: { before: [], after: [] },
|
|
97
|
-
});
|
|
98
|
-
|
|
99
|
-
realProgram = createRealTsProgram();
|
|
100
|
-
});
|
|
101
|
-
|
|
102
|
-
// --- Unit Tests: Slice 2 — update ---
|
|
103
|
-
|
|
104
|
-
describe("AngularCompiler.update — Unit Tests", () => {
|
|
105
|
-
it("sourceFileCache가 없으면 에러를 던진다", async () => {
|
|
106
|
-
const compiler = new AngularCompiler({
|
|
107
|
-
rootNames: realProgram.rootNames,
|
|
108
|
-
compilerOptions: {
|
|
109
|
-
target: ts.ScriptTarget.ESNext,
|
|
110
|
-
module: ts.ModuleKind.ESNext,
|
|
111
|
-
moduleResolution: ts.ModuleResolutionKind.Bundler,
|
|
112
|
-
skipLibCheck: true,
|
|
113
|
-
types: [],
|
|
114
|
-
},
|
|
115
|
-
});
|
|
116
|
-
|
|
117
|
-
await compiler.initialize();
|
|
118
|
-
await expect(compiler.update(new Set(["a.ts"]))).rejects.toThrow();
|
|
119
|
-
});
|
|
120
|
-
|
|
121
|
-
it("update() 후 affectedFiles가 반환된다", async () => {
|
|
122
|
-
const cache = new AngularSourceFileCache();
|
|
123
|
-
|
|
124
|
-
const compiler = new AngularCompiler({
|
|
125
|
-
rootNames: realProgram.rootNames,
|
|
126
|
-
compilerOptions: {
|
|
127
|
-
target: ts.ScriptTarget.ESNext,
|
|
128
|
-
module: ts.ModuleKind.ESNext,
|
|
129
|
-
moduleResolution: ts.ModuleResolutionKind.Bundler,
|
|
130
|
-
skipLibCheck: true,
|
|
131
|
-
types: [],
|
|
132
|
-
},
|
|
133
|
-
sourceFileCache: cache,
|
|
134
|
-
});
|
|
135
|
-
|
|
136
|
-
await compiler.initialize();
|
|
137
|
-
const result = await compiler.update(new Set(["nonexistent.ts"]));
|
|
138
|
-
|
|
139
|
-
expect(result).toHaveProperty("affectedFiles");
|
|
140
|
-
expect(result.affectedFiles).toBeInstanceOf(Set);
|
|
141
|
-
});
|
|
142
|
-
});
|
|
143
|
-
|
|
144
|
-
// --- Acceptance Tests: Slice 2 — update ---
|
|
145
|
-
|
|
146
|
-
describe("AngularCompiler — update", () => {
|
|
147
|
-
// Scenario: 파일 변경 후 incremental rebuild
|
|
148
|
-
it("update() 후 initialize()가 재호출되어 affectedFiles가 갱신된다", async () => {
|
|
149
|
-
const cache = new AngularSourceFileCache();
|
|
150
|
-
|
|
151
|
-
const compiler = new AngularCompiler({
|
|
152
|
-
rootNames: realProgram.rootNames,
|
|
153
|
-
compilerOptions: {
|
|
154
|
-
target: ts.ScriptTarget.ESNext,
|
|
155
|
-
module: ts.ModuleKind.ESNext,
|
|
156
|
-
moduleResolution: ts.ModuleResolutionKind.Bundler,
|
|
157
|
-
skipLibCheck: true,
|
|
158
|
-
types: [],
|
|
159
|
-
},
|
|
160
|
-
sourceFileCache: cache,
|
|
161
|
-
});
|
|
162
|
-
|
|
163
|
-
// 초기 빌드
|
|
164
|
-
await compiler.initialize();
|
|
165
|
-
const initCallCount = ngtscConstructorSpy.mock.calls.length;
|
|
166
|
-
|
|
167
|
-
// 파일 변경 후 update
|
|
168
|
-
const aPath = realProgram.rootNames[0];
|
|
169
|
-
const result = await compiler.update(new Set([aPath]));
|
|
170
|
-
|
|
171
|
-
// initialize()가 재호출됨
|
|
172
|
-
expect(ngtscConstructorSpy.mock.calls.length).toBe(initCallCount + 1);
|
|
173
|
-
// sourceFileCache에서 invalidate 됨
|
|
174
|
-
const normalizedPath = aPath.replace(/\\/g, "/");
|
|
175
|
-
expect(cache.has(normalizedPath)).toBe(false);
|
|
176
|
-
expect(cache.modifiedFiles.has(normalizedPath)).toBe(true);
|
|
177
|
-
// affectedFiles가 반환됨
|
|
178
|
-
expect(result.affectedFiles).toBeInstanceOf(Set);
|
|
179
|
-
});
|
|
180
|
-
|
|
181
|
-
// Scenario: node_modules 파일 변경 시 packageJsonCache clear
|
|
182
|
-
it("node_modules 파일이 변경되면 packageJsonCache가 clear된다", async () => {
|
|
183
|
-
const cache = new AngularSourceFileCache();
|
|
184
|
-
|
|
185
|
-
const compiler = new AngularCompiler({
|
|
186
|
-
rootNames: realProgram.rootNames,
|
|
187
|
-
compilerOptions: {
|
|
188
|
-
target: ts.ScriptTarget.ESNext,
|
|
189
|
-
module: ts.ModuleKind.ESNext,
|
|
190
|
-
moduleResolution: ts.ModuleResolutionKind.Bundler,
|
|
191
|
-
skipLibCheck: true,
|
|
192
|
-
types: [],
|
|
193
|
-
},
|
|
194
|
-
sourceFileCache: cache,
|
|
195
|
-
});
|
|
196
|
-
|
|
197
|
-
// 초기 빌드
|
|
198
|
-
await compiler.initialize();
|
|
199
|
-
|
|
200
|
-
// node_modules 파일 변경으로 update
|
|
201
|
-
const result = await compiler.update(
|
|
202
|
-
new Set(["node_modules/some-package/index.js"]),
|
|
203
|
-
);
|
|
204
|
-
|
|
205
|
-
// packageJsonCache.clear()가 호출됨 (에러 없이 완료)
|
|
206
|
-
expect(result.affectedFiles).toBeInstanceOf(Set);
|
|
207
|
-
// initialize()가 재호출됨
|
|
208
|
-
expect(ngtscConstructorSpy.mock.calls.length).toBe(2);
|
|
209
|
-
});
|
|
210
|
-
|
|
211
|
-
// Scenario: SCSS 파일 변경 시 관련 컴포넌트가 affected에 포함
|
|
212
|
-
it("SCSS 파일 변경 시 관련 컴포넌트가 affected에 포함된다", async () => {
|
|
213
|
-
realProgram = createRealTsProgram({
|
|
214
|
-
"component.ts": "export class Comp {}",
|
|
215
|
-
});
|
|
216
|
-
|
|
217
|
-
const scssPath = path.join(realProgram.dir, "component.scss");
|
|
218
|
-
fs.writeFileSync(scssPath, ".x { }", "utf-8");
|
|
219
|
-
|
|
220
|
-
const sourceFiles = realProgram.program.getSourceFiles();
|
|
221
|
-
const compFile = sourceFiles.find((sf) => sf.fileName.includes("component.ts"));
|
|
222
|
-
|
|
223
|
-
mockGetResourceDependencies.mockImplementation((sf: ts.SourceFile) => {
|
|
224
|
-
if (sf === compFile) {
|
|
225
|
-
return [scssPath];
|
|
226
|
-
}
|
|
227
|
-
return [];
|
|
228
|
-
});
|
|
229
|
-
|
|
230
|
-
const cache = new AngularSourceFileCache();
|
|
231
|
-
|
|
232
|
-
const compiler = new AngularCompiler({
|
|
233
|
-
rootNames: realProgram.rootNames,
|
|
234
|
-
compilerOptions: {
|
|
235
|
-
target: ts.ScriptTarget.ESNext,
|
|
236
|
-
module: ts.ModuleKind.ESNext,
|
|
237
|
-
moduleResolution: ts.ModuleResolutionKind.Bundler,
|
|
238
|
-
skipLibCheck: true,
|
|
239
|
-
types: [],
|
|
240
|
-
},
|
|
241
|
-
sourceFileCache: cache,
|
|
242
|
-
});
|
|
243
|
-
|
|
244
|
-
// 초기 빌드
|
|
245
|
-
await compiler.initialize();
|
|
246
|
-
|
|
247
|
-
// SCSS 변경 후 update
|
|
248
|
-
const result = await compiler.update(new Set([scssPath]));
|
|
249
|
-
|
|
250
|
-
// component.ts가 affected에 포함
|
|
251
|
-
const affectedFileNames = [...result.affectedFiles].map(
|
|
252
|
-
(sf: ts.SourceFile) => sf.fileName,
|
|
253
|
-
);
|
|
254
|
-
expect(affectedFileNames.some((f: string) => f.includes("component.ts"))).toBe(true);
|
|
255
|
-
});
|
|
256
|
-
|
|
257
|
-
// Scenario: 리소스 변경 없으면 diagnosticCache 재사용
|
|
258
|
-
it("리소스 변경 없으면 diagnosticCache가 재사용된다", async () => {
|
|
259
|
-
const mockDiag = {
|
|
260
|
-
category: ts.DiagnosticCategory.Error,
|
|
261
|
-
code: 5000,
|
|
262
|
-
messageText: "cached diagnostic",
|
|
263
|
-
} as ts.Diagnostic;
|
|
264
|
-
mockGetDiagnosticsForFile.mockReturnValue([mockDiag]);
|
|
265
|
-
|
|
266
|
-
const cache = new AngularSourceFileCache();
|
|
267
|
-
|
|
268
|
-
const compiler = new AngularCompiler({
|
|
269
|
-
rootNames: realProgram.rootNames,
|
|
270
|
-
compilerOptions: {
|
|
271
|
-
target: ts.ScriptTarget.ESNext,
|
|
272
|
-
module: ts.ModuleKind.ESNext,
|
|
273
|
-
moduleResolution: ts.ModuleResolutionKind.Bundler,
|
|
274
|
-
skipLibCheck: true,
|
|
275
|
-
types: [],
|
|
276
|
-
},
|
|
277
|
-
sourceFileCache: cache,
|
|
278
|
-
});
|
|
279
|
-
|
|
280
|
-
// 초기 빌드 + diagnostics
|
|
281
|
-
await compiler.initialize();
|
|
282
|
-
void [...compiler.collectDiagnostics()];
|
|
283
|
-
expect(mockGetDiagnosticsForFile).toHaveBeenCalled();
|
|
284
|
-
|
|
285
|
-
// 변경 없이 update → diagnosticCache 재사용
|
|
286
|
-
mockGetDiagnosticsForFile.mockClear();
|
|
287
|
-
await compiler.update(new Set([]));
|
|
288
|
-
const diags2 = [...compiler.collectDiagnostics()];
|
|
289
|
-
|
|
290
|
-
// diagnostics가 반환된다 (에러 없이 동작)
|
|
291
|
-
expect(Array.isArray(diags2)).toBe(true);
|
|
292
|
-
});
|
|
293
|
-
});
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect, afterEach } from "vitest";
|
|
2
|
-
import { getVersion } from "../../src/utils/build-env";
|
|
3
|
-
import path from "path";
|
|
4
|
-
import fs from "fs/promises";
|
|
5
|
-
import os from "os";
|
|
6
|
-
|
|
7
|
-
describe("getVersion", () => {
|
|
8
|
-
const tmpDirs: string[] = [];
|
|
9
|
-
|
|
10
|
-
async function createTmpDir(pkgJson: Record<string, unknown>): Promise<string> {
|
|
11
|
-
const dir = await fs.mkdtemp(path.join(os.tmpdir(), "sd-cli-test-"));
|
|
12
|
-
tmpDirs.push(dir);
|
|
13
|
-
await fs.writeFile(path.join(dir, "package.json"), JSON.stringify(pkgJson));
|
|
14
|
-
return dir;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
afterEach(async () => {
|
|
18
|
-
for (const dir of tmpDirs) {
|
|
19
|
-
await fs.rm(dir, { recursive: true, force: true });
|
|
20
|
-
}
|
|
21
|
-
tmpDirs.length = 0;
|
|
22
|
-
});
|
|
23
|
-
|
|
24
|
-
it("returns version from package.json", async () => {
|
|
25
|
-
const dir = await createTmpDir({ version: "14.0.0" });
|
|
26
|
-
expect(await getVersion(dir)).toBe("14.0.0");
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
it("returns '0.0.0' when version field is missing", async () => {
|
|
30
|
-
const dir = await createTmpDir({ name: "test-pkg" });
|
|
31
|
-
expect(await getVersion(dir)).toBe("0.0.0");
|
|
32
|
-
});
|
|
33
|
-
});
|
|
@@ -1,124 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect, vi, beforeEach } from "vitest";
|
|
2
|
-
|
|
3
|
-
// --- Unit Tests: createLibraryTransformStylesheet ---
|
|
4
|
-
|
|
5
|
-
describe("createLibraryTransformStylesheet", () => {
|
|
6
|
-
beforeEach(() => {
|
|
7
|
-
vi.restoreAllMocks();
|
|
8
|
-
});
|
|
9
|
-
|
|
10
|
-
it("외부 .scss 파일이면 compileScssFile로 CSS를 반환하고 의존성을 기록한다", async () => {
|
|
11
|
-
const { createLibraryTransformStylesheet } = await import(
|
|
12
|
-
"../../src/utils/ngtsc-build-core"
|
|
13
|
-
);
|
|
14
|
-
|
|
15
|
-
const loadPaths = ["/pkg/scss", "/cwd/node_modules"];
|
|
16
|
-
const scssErrors: string[] = [];
|
|
17
|
-
const scssDependencies = new Map<string, Set<string>>();
|
|
18
|
-
|
|
19
|
-
const transform = createLibraryTransformStylesheet(loadPaths, scssErrors, scssDependencies);
|
|
20
|
-
|
|
21
|
-
// Mock scss-compiler 대신 실제 호출 — scss가 없으면 에러 나므로 vi.mock으로 처리
|
|
22
|
-
// 실제로는 compileScssFile을 호출하지만, 여기서는 팩토리 구조만 확인
|
|
23
|
-
// scss 파일이 실제로 존재하지 않으므로 에러가 수집될 것
|
|
24
|
-
const result = await transform(
|
|
25
|
-
".host { color: red; }",
|
|
26
|
-
"/project/src/app.component.ts",
|
|
27
|
-
"/project/src/app.component.scss",
|
|
28
|
-
);
|
|
29
|
-
|
|
30
|
-
// 존재하지 않는 파일이므로 에러가 발생하여 scssErrors에 추가됨
|
|
31
|
-
expect(scssErrors.length).toBeGreaterThan(0);
|
|
32
|
-
// 에러 시 "/* SCSS compilation error */" 반환
|
|
33
|
-
expect(result).toBe("/* SCSS compilation error */");
|
|
34
|
-
});
|
|
35
|
-
|
|
36
|
-
it("외부 .css 파일이면 null을 반환한다", async () => {
|
|
37
|
-
const { createLibraryTransformStylesheet } = await import(
|
|
38
|
-
"../../src/utils/ngtsc-build-core"
|
|
39
|
-
);
|
|
40
|
-
|
|
41
|
-
const loadPaths = ["/pkg/scss"];
|
|
42
|
-
const scssErrors: string[] = [];
|
|
43
|
-
const scssDependencies = new Map<string, Set<string>>();
|
|
44
|
-
|
|
45
|
-
const transform = createLibraryTransformStylesheet(loadPaths, scssErrors, scssDependencies);
|
|
46
|
-
|
|
47
|
-
const result = await transform(
|
|
48
|
-
".host { color: red; }",
|
|
49
|
-
"/project/src/app.component.ts",
|
|
50
|
-
"/project/src/app.component.css",
|
|
51
|
-
);
|
|
52
|
-
|
|
53
|
-
expect(result).toBeNull();
|
|
54
|
-
expect(scssErrors.length).toBe(0);
|
|
55
|
-
});
|
|
56
|
-
|
|
57
|
-
it("인라인 SCSS(stylesheetFile 미지정)이면 compileScssString으로 CSS를 반환한다", async () => {
|
|
58
|
-
const { createLibraryTransformStylesheet } = await import(
|
|
59
|
-
"../../src/utils/ngtsc-build-core"
|
|
60
|
-
);
|
|
61
|
-
|
|
62
|
-
const loadPaths: string[] = [];
|
|
63
|
-
const scssErrors: string[] = [];
|
|
64
|
-
const scssDependencies = new Map<string, Set<string>>();
|
|
65
|
-
|
|
66
|
-
const transform = createLibraryTransformStylesheet(loadPaths, scssErrors, scssDependencies);
|
|
67
|
-
|
|
68
|
-
// 순수 CSS는 SCSS 컴파일러가 그대로 통과시킴
|
|
69
|
-
const result = await transform(
|
|
70
|
-
".host { color: red; }",
|
|
71
|
-
"/project/src/app.component.ts",
|
|
72
|
-
undefined,
|
|
73
|
-
);
|
|
74
|
-
|
|
75
|
-
expect(typeof result).toBe("string");
|
|
76
|
-
expect(result).toContain("color: red");
|
|
77
|
-
expect(scssErrors.length).toBe(0);
|
|
78
|
-
});
|
|
79
|
-
|
|
80
|
-
it("SCSS 컴파일 에러 시 scssErrors에 에러를 추가하고 에러 주석을 반환한다", async () => {
|
|
81
|
-
const { createLibraryTransformStylesheet } = await import(
|
|
82
|
-
"../../src/utils/ngtsc-build-core"
|
|
83
|
-
);
|
|
84
|
-
|
|
85
|
-
const loadPaths: string[] = [];
|
|
86
|
-
const scssErrors: string[] = [];
|
|
87
|
-
const scssDependencies = new Map<string, Set<string>>();
|
|
88
|
-
|
|
89
|
-
const transform = createLibraryTransformStylesheet(loadPaths, scssErrors, scssDependencies);
|
|
90
|
-
|
|
91
|
-
// 존재하지 않는 외부 SCSS 파일 → 컴파일 에러
|
|
92
|
-
const result = await transform(
|
|
93
|
-
"",
|
|
94
|
-
"/project/src/broken.component.ts",
|
|
95
|
-
"/nonexistent/path/broken.scss",
|
|
96
|
-
);
|
|
97
|
-
|
|
98
|
-
expect(result).toBe("/* SCSS compilation error */");
|
|
99
|
-
expect(scssErrors.length).toBeGreaterThan(0);
|
|
100
|
-
expect(scssErrors[0]).toContain("SCSS error");
|
|
101
|
-
});
|
|
102
|
-
|
|
103
|
-
it("SCSS 의존성이 scssDependencies에 기록된다", async () => {
|
|
104
|
-
const { createLibraryTransformStylesheet } = await import(
|
|
105
|
-
"../../src/utils/ngtsc-build-core"
|
|
106
|
-
);
|
|
107
|
-
|
|
108
|
-
const loadPaths: string[] = [];
|
|
109
|
-
const scssErrors: string[] = [];
|
|
110
|
-
const scssDependencies = new Map<string, Set<string>>();
|
|
111
|
-
|
|
112
|
-
const transform = createLibraryTransformStylesheet(loadPaths, scssErrors, scssDependencies);
|
|
113
|
-
|
|
114
|
-
// 인라인 SCSS: 의존성 없음이지만 구조는 기록됨
|
|
115
|
-
await transform(
|
|
116
|
-
".host { color: red; }",
|
|
117
|
-
"/project/src/app.component.ts",
|
|
118
|
-
undefined,
|
|
119
|
-
);
|
|
120
|
-
|
|
121
|
-
// 의존성이 없더라도 scssDependencies에 containingFile 키가 생성됨
|
|
122
|
-
expect(scssDependencies.has("/project/src/app.component.ts")).toBe(true);
|
|
123
|
-
});
|
|
124
|
-
});
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect } from "vitest";
|
|
2
|
-
import { resolve, join } from "node:path";
|
|
3
|
-
|
|
4
|
-
const workspaceRoot = resolve(import.meta.dirname, "../../../..");
|
|
5
|
-
const angularPkgDir = resolve(workspaceRoot, "packages/angular");
|
|
6
|
-
|
|
7
|
-
// Scenario 1: loadPaths 헬퍼가 동일한 경로를 반환한다
|
|
8
|
-
describe("buildScssLoadPaths", () => {
|
|
9
|
-
it("returns [pkgDir/scss, cwd/node_modules] for given NgtscBuildInfo", async () => {
|
|
10
|
-
const { buildScssLoadPaths } = await import("../../src/utils/ngtsc-build-core");
|
|
11
|
-
|
|
12
|
-
const info = {
|
|
13
|
-
name: "angular",
|
|
14
|
-
cwd: workspaceRoot,
|
|
15
|
-
pkgDir: angularPkgDir,
|
|
16
|
-
output: { js: true, dts: false },
|
|
17
|
-
};
|
|
18
|
-
|
|
19
|
-
const result = buildScssLoadPaths(info);
|
|
20
|
-
|
|
21
|
-
expect(result).toEqual([
|
|
22
|
-
join(angularPkgDir, "scss"),
|
|
23
|
-
join(workspaceRoot, "node_modules"),
|
|
24
|
-
]);
|
|
25
|
-
});
|
|
26
|
-
|
|
27
|
-
// Unit: different cwd produces different node_modules path
|
|
28
|
-
it("uses cwd from info to construct node_modules path", async () => {
|
|
29
|
-
const { buildScssLoadPaths } = await import("../../src/utils/ngtsc-build-core");
|
|
30
|
-
|
|
31
|
-
const customCwd = "/custom/workspace";
|
|
32
|
-
const customPkgDir = "/custom/workspace/packages/my-pkg";
|
|
33
|
-
|
|
34
|
-
const result = buildScssLoadPaths({
|
|
35
|
-
name: "test",
|
|
36
|
-
cwd: customCwd,
|
|
37
|
-
pkgDir: customPkgDir,
|
|
38
|
-
output: { js: true, dts: false },
|
|
39
|
-
});
|
|
40
|
-
|
|
41
|
-
expect(result).toEqual([
|
|
42
|
-
join(customPkgDir, "scss"),
|
|
43
|
-
join(customCwd, "node_modules"),
|
|
44
|
-
]);
|
|
45
|
-
});
|
|
46
|
-
});
|
|
47
|
-
|