@simplysm/sd-cli 12.5.17 → 12.5.19

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.
@@ -1,19 +1,18 @@
1
1
  import ts from "typescript";
2
2
  import path from "path";
3
3
  import { FsUtil, Logger, PathUtil } from "@simplysm/sd-core-node";
4
- import { NeverEntryError, StringUtil } from "@simplysm/sd-core-common";
4
+ import { StringUtil } from "@simplysm/sd-core-common";
5
5
  import { NgtscProgram, OptimizeFor } from "@angular/compiler-cli";
6
6
  import { createHash } from "crypto";
7
7
  import { ComponentStylesheetBundler } from "@angular/build/src/tools/esbuild/angular/component-stylesheets";
8
8
  import { transformSupportedBrowsersToTargets } from "@angular/build/src/tools/esbuild/utils";
9
9
  import browserslist from "browserslist";
10
- import transformKeys from "@simplysm/ts-transformer-keys/transformer";
11
10
  import { replaceBootstrap } from "@angular/build/src/tools/angular/transformers/jit-bootstrap-transformer";
12
11
  export class SdTsCompiler {
13
12
  #logger = Logger.get(["simplysm", "sd-cli", "SdTsCompiler"]);
14
13
  #parsedTsconfig;
15
14
  #isForAngular;
16
- #revDependencyCacheMap = new Map();
15
+ // readonly #revDependencyCacheMap = new Map<string, Set<string>>();
17
16
  #resourceDependencyCacheMap = new Map();
18
17
  #sourceFileCacheMap = new Map();
19
18
  #emittedFilesCacheMap = new Map();
@@ -21,6 +20,7 @@ export class SdTsCompiler {
21
20
  #compilerHost;
22
21
  #ngProgram;
23
22
  #program;
23
+ #builder;
24
24
  #modifiedFileSet = new Set();
25
25
  #watchFileSet = new Set();
26
26
  #stylesheetBundlingResultMap = new Map();
@@ -125,26 +125,33 @@ export class SdTsCompiler {
125
125
  return stylesheetResult.contents;
126
126
  }
127
127
  invalidate(modifiedFileSet) {
128
- this.#modifiedFileSet.adds(...Array.from(modifiedFileSet).map((item) => path.normalize(item)));
128
+ for (const modifiedFile of Array.from(modifiedFileSet).map((item) => path.normalize(item))) {
129
+ this.#modifiedFileSet.add(modifiedFile);
130
+ this.#modifiedFileSet.adds(...(this.#resourceDependencyCacheMap.get(modifiedFile) ?? []));
131
+ }
129
132
  }
130
133
  async buildAsync() {
131
- const affectedFileSet = new Set();
134
+ const affectedSourceFileSet = new Set();
132
135
  const emitFileSet = new Set();
133
136
  this.#debug(`get affected (old deps & old res deps)...`);
134
137
  for (const modifiedFile of this.#modifiedFileSet) {
135
- affectedFileSet.add(modifiedFile);
136
- affectedFileSet.adds(...(this.#revDependencyCacheMap.get(modifiedFile) ?? []));
137
- affectedFileSet.adds(...(this.#resourceDependencyCacheMap.get(modifiedFile) ?? []));
138
+ // affectedFileSet.add(modifiedFile);
139
+ // affectedFileSet.adds(...(this.#revDependencyCacheMap.get(modifiedFile) ?? []));
140
+ // affectedFileSet.adds(...(this.#resourceDependencyCacheMap.get(modifiedFile) ?? []));
138
141
  this.#emittedFilesCacheMap.delete(path.normalize(modifiedFile));
142
+ this.#sourceFileCacheMap.delete(path.normalize(modifiedFile));
143
+ this.#stylesheetBundlingResultMap.delete(path.normalize(modifiedFile));
144
+ this.#watchFileSet.delete(path.normalize(modifiedFile));
139
145
  }
140
- this.#debug(`invalidate & clear cache...`);
141
146
  this.#stylesheetBundler?.invalidate(this.#modifiedFileSet);
142
- for (const affectedFile of affectedFileSet) {
143
- this.#sourceFileCacheMap.delete(path.normalize(affectedFile));
144
- this.#stylesheetBundlingResultMap.delete(path.normalize(affectedFile));
145
- this.#watchFileSet.delete(path.normalize(affectedFile));
146
- }
147
- this.#revDependencyCacheMap.clear();
147
+ // this.#debug(`invalidate & clear cache...`);
148
+ // this.#stylesheetBundler?.invalidate(affectedFileSet);
149
+ // for (const affectedFile of affectedFileSet) {
150
+ // this.#sourceFileCacheMap.delete(path.normalize(affectedFile));
151
+ // this.#stylesheetBundlingResultMap.delete(path.normalize(affectedFile));
152
+ // this.#watchFileSet.delete(path.normalize(affectedFile));
153
+ // }
154
+ // this.#revDependencyCacheMap.clear();
148
155
  this.#resourceDependencyCacheMap.clear();
149
156
  this.#debug(`create program...`);
150
157
  if (this.#isForAngular) {
@@ -154,6 +161,7 @@ export class SdTsCompiler {
154
161
  else {
155
162
  this.#program = ts.createProgram(this.#parsedTsconfig.fileNames, this.#parsedTsconfig.options, this.#compilerHost, this.#program);
156
163
  }
164
+ this.#debug(`create builder...`);
157
165
  const baseGetSourceFiles = this.#program.getSourceFiles;
158
166
  this.#program.getSourceFiles = function (...parameters) {
159
167
  const files = baseGetSourceFiles(...parameters);
@@ -164,7 +172,7 @@ export class SdTsCompiler {
164
172
  }
165
173
  return files;
166
174
  };
167
- this.#debug(`create builder...`);
175
+ this.#builder = ts.createEmitAndSemanticDiagnosticsBuilderProgram(this.#program, this.#compilerHost, this.#builder);
168
176
  if (this.#ngProgram) {
169
177
  await this.#ngProgram.compiler.analyzeAsync();
170
178
  }
@@ -176,91 +184,126 @@ export class SdTsCompiler {
176
184
  return sf;
177
185
  };
178
186
  this.#debug(`get affected (new deps)...`);
179
- const sourceFileSet = new Set(this.#program
180
- .getSourceFiles()
181
- .map((sf) => getOrgSourceFile(sf))
182
- .filterExists());
183
- const depMap = new Map();
184
- for (const sf of sourceFileSet) {
185
- const refs = this.#findDeps(sf);
186
- depMap.set(path.normalize(sf.fileName), refs);
187
- }
188
- const allDepMap = new Map();
189
- const getAllDeps = (fileName, prevSet) => {
190
- if (allDepMap.has(fileName)) {
191
- return allDepMap.get(fileName);
192
- }
193
- const result = new Set();
194
- const deps = depMap.get(fileName) ?? [];
195
- result.adds(...deps.map((item) => item.fileName));
196
- for (const dep of deps) {
197
- const targetDeps = depMap.get(dep.fileName) ?? [];
198
- if (dep.importName === "*") {
199
- for (const targetRefItem of targetDeps.filter((item) => item.exportName != null)) {
200
- if (prevSet?.has(targetRefItem.fileName))
201
- continue;
202
- result.add(targetRefItem.fileName);
203
- result.adds(...getAllDeps(targetRefItem.fileName, new Set(prevSet).adds(...result)));
204
- }
205
- }
206
- else {
207
- for (const targetRefItem of targetDeps.filter((item) => item.exportName === dep.importName)) {
208
- if (prevSet?.has(targetRefItem.fileName))
209
- continue;
210
- result.add(targetRefItem.fileName);
211
- result.adds(...getAllDeps(targetRefItem.fileName, new Set(prevSet).adds(...result)));
212
- }
213
- }
214
- }
215
- return result;
216
- };
217
- for (const sf of sourceFileSet) {
218
- const deps = getAllDeps(path.normalize(sf.fileName));
219
- allDepMap.set(path.normalize(sf.fileName), deps);
220
- for (const dep of getAllDeps(path.normalize(sf.fileName))) {
221
- const depCache = this.#revDependencyCacheMap.getOrCreate(path.normalize(dep), new Set());
222
- depCache.add(path.normalize(sf.fileName));
223
- if (this.#modifiedFileSet.has(path.normalize(dep))) {
224
- affectedFileSet.add(path.normalize(sf.fileName));
225
- }
226
- }
227
- if (this.#ngProgram) {
228
- if (this.#ngProgram.compiler.ignoreForEmit.has(sf)) {
229
- continue;
230
- }
231
- for (const dep of this.#ngProgram.compiler.getResourceDependencies(sf)) {
232
- const ref = this.#resourceDependencyCacheMap.getOrCreate(path.normalize(dep), new Set());
233
- ref.add(path.normalize(sf.fileName));
234
- if (this.#modifiedFileSet.has(path.normalize(dep))) {
235
- affectedFileSet.add(path.normalize(sf.fileName));
236
- }
237
- }
238
- }
239
- }
240
- if (affectedFileSet.size === 0) {
241
- this.#debug(`get affected (init)...`);
242
- for (const sf of this.#program.getSourceFiles()) {
243
- const orgSf = getOrgSourceFile(sf);
244
- if (!orgSf)
245
- continue;
246
- affectedFileSet.add(path.normalize(orgSf.fileName));
247
- }
248
- }
187
+ // const sourceFileSet = new Set(
188
+ // this.#program
189
+ // .getSourceFiles()
190
+ // .map((sf) => getOrgSourceFile(sf))
191
+ // .filterExists(),
192
+ // );
193
+ // const depMap = new Map<
194
+ // string,
195
+ // {
196
+ // fileName: string;
197
+ // importName: string;
198
+ // exportName?: string;
199
+ // }[]
200
+ // >();
201
+ // for (const sf of sourceFileSet) {
202
+ // const refs = this.#findDeps(sf);
203
+ // depMap.set(path.normalize(sf.fileName), refs);
204
+ // }
205
+ //
206
+ // const allDepMap = new Map<string, Set<string>>();
207
+ // const getAllDeps = (fileName: string, prevSet?: Set<string>) => {
208
+ // if (allDepMap.has(fileName)) {
209
+ // return allDepMap.get(fileName)!;
210
+ // }
211
+ //
212
+ // const result = new Set<string>();
213
+ //
214
+ // const deps = depMap.get(fileName) ?? [];
215
+ // result.adds(...deps.map((item) => item.fileName));
216
+ //
217
+ // for (const dep of deps) {
218
+ // const targetDeps = depMap.get(dep.fileName) ?? [];
219
+ //
220
+ // if (dep.importName === "*") {
221
+ // for (const targetRefItem of targetDeps.filter((item) => item.exportName != null)) {
222
+ // if (prevSet?.has(targetRefItem.fileName)) continue;
223
+ //
224
+ // result.add(targetRefItem.fileName);
225
+ // result.adds(...getAllDeps(targetRefItem.fileName, new Set<string>(prevSet).adds(...result)));
226
+ // }
227
+ // } else {
228
+ // for (const targetRefItem of targetDeps.filter((item) => item.exportName === dep.importName)) {
229
+ // if (prevSet?.has(targetRefItem.fileName)) continue;
230
+ //
231
+ // result.add(targetRefItem.fileName);
232
+ // result.adds(...getAllDeps(targetRefItem.fileName, new Set<string>(prevSet).adds(...result)));
233
+ // }
234
+ // }
235
+ // }
236
+ //
237
+ // return result;
238
+ // };
239
+ // for (const sf of sourceFileSet) {
240
+ // const deps = getAllDeps(path.normalize(sf.fileName));
241
+ // allDepMap.set(path.normalize(sf.fileName), deps);
242
+ //
243
+ // for (const dep of getAllDeps(path.normalize(sf.fileName))) {
244
+ // const depCache = this.#revDependencyCacheMap.getOrCreate(path.normalize(dep), new Set<string>());
245
+ // depCache.add(path.normalize(sf.fileName));
246
+ // if (this.#modifiedFileSet.has(path.normalize(dep))) {
247
+ // affectedFileSet.add(path.normalize(sf.fileName));
248
+ // }
249
+ // }
250
+ //
251
+ // if (this.#ngProgram) {
252
+ // if (this.#ngProgram.compiler.ignoreForEmit.has(sf)) {
253
+ // continue;
254
+ // }
255
+ //
256
+ // for (const dep of this.#ngProgram.compiler.getResourceDependencies(sf)) {
257
+ // const ref = this.#resourceDependencyCacheMap.getOrCreate(path.normalize(dep), new Set<string>());
258
+ // ref.add(path.normalize(sf.fileName));
259
+ // if (this.#modifiedFileSet.has(path.normalize(dep))) {
260
+ // affectedFileSet.add(path.normalize(sf.fileName));
261
+ // }
262
+ // }
263
+ // }
264
+ // }
265
+ // if (affectedFileSet.size === 0) {
266
+ // this.#debug(`get affected (init)...`);
267
+ //
268
+ // for (const sf of this.#program.getSourceFiles()) {
269
+ // const orgSf = getOrgSourceFile(sf);
270
+ // if (!orgSf) continue;
271
+ //
272
+ // affectedFileSet.add(path.normalize(orgSf.fileName));
273
+ // }
274
+ // }
249
275
  this.#debug(`get diagnostics...`);
250
276
  const diagnostics = [];
251
- diagnostics.push(...this.#program.getConfigFileParsingDiagnostics(), ...this.#program.getOptionsDiagnostics(), ...this.#program.getGlobalDiagnostics());
277
+ diagnostics.push(...this.#builder.getConfigFileParsingDiagnostics(), ...this.#builder.getOptionsDiagnostics(), ...this.#builder.getGlobalDiagnostics());
278
+ /*diagnostics.push(
279
+ ...this.#program.getConfigFileParsingDiagnostics(),
280
+ ...this.#program.getOptionsDiagnostics(),
281
+ ...this.#program.getGlobalDiagnostics(),
282
+ );*/
252
283
  if (this.#ngProgram) {
253
284
  diagnostics.push(...this.#ngProgram.compiler.getOptionDiagnostics());
254
285
  }
255
- for (const affectedFile of affectedFileSet) {
256
- const affectedSourceFile = this.#program.getSourceFile(affectedFile);
257
- if (!affectedSourceFile ||
258
- (this.#ngProgram && this.#ngProgram.compiler.ignoreForDiagnostics.has(affectedSourceFile))) {
259
- continue;
260
- }
261
- if (!PathUtil.isChildPath(affectedFile, this.#pkgPath)) {
262
- continue;
263
- }
286
+ this.#debug(`get diagnostics of files...`);
287
+ while (true) {
288
+ const affectedFileResult = this.#builder.getSemanticDiagnosticsOfNextAffectedFile(undefined, (sf) => {
289
+ if (this.#ngProgram &&
290
+ this.#ngProgram.compiler.ignoreForDiagnostics.has(sf) &&
291
+ sf.fileName.endsWith(".ngtypecheck.ts")) {
292
+ const orgSourceFile = getOrgSourceFile(sf);
293
+ if (orgSourceFile) {
294
+ affectedSourceFileSet.add(orgSourceFile);
295
+ }
296
+ return true;
297
+ }
298
+ return false;
299
+ });
300
+ if (!affectedFileResult)
301
+ break;
302
+ const affectedSourceFile = affectedFileResult.affected;
303
+ affectedSourceFileSet.add(affectedSourceFile);
304
+ }
305
+ for (const affectedSourceFile of affectedSourceFileSet) {
306
+ this.#debug(`get diagnostics of file [${affectedSourceFile.fileName}]`);
264
307
  diagnostics.push(...this.#program.getSyntacticDiagnostics(affectedSourceFile), ...this.#program.getSemanticDiagnostics(affectedSourceFile));
265
308
  if (this.#ngProgram) {
266
309
  if (affectedSourceFile.isDeclarationFile) {
@@ -269,6 +312,37 @@ export class SdTsCompiler {
269
312
  diagnostics.push(...this.#ngProgram.compiler.getDiagnosticsForFile(affectedSourceFile, OptimizeFor.WholeProgram));
270
313
  }
271
314
  }
315
+ /*
316
+ for (const affectedFile of affectedFileSet) {
317
+ if (!PathUtil.isChildPath(affectedFile, this.#pkgPath)) {
318
+ continue;
319
+ }
320
+
321
+ this.#debug(`get diagnostics of file [${affectedFile}]`);
322
+
323
+ const affectedSourceFile = this.#program.getSourceFile(affectedFile);
324
+ if (
325
+ !affectedSourceFile ||
326
+ (this.#ngProgram && this.#ngProgram.compiler.ignoreForDiagnostics.has(affectedSourceFile))
327
+ ) {
328
+ continue;
329
+ }
330
+
331
+ diagnostics.push(
332
+ ...this.#program.getSyntacticDiagnostics(affectedSourceFile),
333
+ ...this.#program.getSemanticDiagnostics(affectedSourceFile),
334
+ );
335
+
336
+ if (this.#ngProgram) {
337
+ if (affectedSourceFile.isDeclarationFile) {
338
+ continue;
339
+ }
340
+
341
+ diagnostics.push(
342
+ ...this.#ngProgram.compiler.getDiagnosticsForFile(affectedSourceFile, OptimizeFor.WholeProgram),
343
+ );
344
+ }
345
+ }*/
272
346
  this.#debug(`prepare emit...`);
273
347
  let transformers = {};
274
348
  if (this.#ngProgram) {
@@ -278,7 +352,43 @@ export class SdTsCompiler {
278
352
  };
279
353
  (transformers.before ??= []).push(replaceBootstrap(() => this.#program.getTypeChecker()));
280
354
  }
281
- (transformers.before ??= []).push(transformKeys(this.#program));
355
+ // (transformers.before ??= []).push(transformKeys(this.#program));
356
+ this.#debug(`prepare emit files...`);
357
+ while (this.#builder.emitNextAffectedFile((fileName, text, writeByteOrderMark, onError, sourceFiles, data) => {
358
+ if (!sourceFiles || sourceFiles.length === 0) {
359
+ this.#compilerHost.writeFile(fileName, text, writeByteOrderMark, onError, sourceFiles, data);
360
+ return;
361
+ }
362
+ const sourceFile = ts.getOriginalNode(sourceFiles[0], ts.isSourceFile);
363
+ if (this.#ngProgram) {
364
+ if (this.#ngProgram.compiler.ignoreForEmit.has(sourceFile)) {
365
+ return;
366
+ }
367
+ this.#ngProgram.compiler.incrementalCompilation.recordSuccessfulEmit(sourceFile);
368
+ }
369
+ const emitFileInfoCaches = this.#emittedFilesCacheMap.getOrCreate(path.normalize(sourceFile.fileName), []);
370
+ if (PathUtil.isChildPath(sourceFile.fileName, this.#pkgPath)) {
371
+ let realFilePath = fileName;
372
+ let realText = text;
373
+ if (PathUtil.isChildPath(realFilePath, path.resolve(this.#distPath, path.basename(this.#pkgPath), "src"))) {
374
+ realFilePath = path.resolve(this.#distPath, path.relative(path.resolve(this.#distPath, path.basename(this.#pkgPath), "src"), realFilePath));
375
+ if (fileName.endsWith(".js.map")) {
376
+ const sourceMapContents = JSON.parse(realText);
377
+ // remove "../../"
378
+ sourceMapContents.sources[0] = sourceMapContents.sources[0].slice(6);
379
+ realText = JSON.stringify(sourceMapContents);
380
+ }
381
+ }
382
+ emitFileInfoCaches.push({
383
+ outAbsPath: realFilePath,
384
+ text: realText,
385
+ });
386
+ }
387
+ else {
388
+ emitFileInfoCaches.push({ text });
389
+ }
390
+ emitFileSet.add(path.normalize(sourceFile.fileName));
391
+ }, undefined, undefined, transformers)) { }
282
392
  // affected에 새로 추가된 파일은 포함되지 않는 현상이 있어 getSourceFiles로 바꿈
283
393
  // 비교해보니, 딱히 getSourceFiles라서 더 느려지는것 같지는 않음
284
394
  /*for (const affectedFile of affectedFileSet) {
@@ -290,59 +400,76 @@ export class SdTsCompiler {
290
400
  if (!sf) {
291
401
  continue;
292
402
  }*/
293
- for (const sf of sourceFileSet) {
294
- if (this.#emittedFilesCacheMap.has(path.normalize(sf.fileName))) {
295
- continue;
296
- }
297
- if (sf.isDeclarationFile) {
298
- continue;
299
- }
300
- if (this.#ngProgram?.compiler.ignoreForEmit.has(sf)) {
301
- continue;
302
- }
303
- // esbuild를 통해 bundle로 묶어야 하는놈들은 모든 output이 있어야 함.
304
- if (!this.#isForBundle) {
305
- if (!PathUtil.isChildPath(sf.fileName, this.#pkgPath)) {
306
- continue;
307
- }
403
+ /*for (const sf of sourceFileSet) {
404
+ if (this.#emittedFilesCacheMap.has(path.normalize(sf.fileName))) {
405
+ continue;
406
+ }
407
+
408
+ if (sf.isDeclarationFile) {
409
+ continue;
410
+ }
411
+
412
+ if (this.#ngProgram?.compiler.ignoreForEmit.has(sf)) {
413
+ continue;
414
+ }
415
+
416
+ // esbuild를 통해 bundle로 묶어야 하는놈들은 모든 output이 있어야 함.
417
+ if (!this.#isForBundle) {
418
+ if (!PathUtil.isChildPath(sf.fileName, this.#pkgPath)) {
419
+ continue;
308
420
  }
309
- this.#debug(`emit for`, sf.fileName);
310
- this.#program.emit(sf, (fileName, text, writeByteOrderMark, onError, sourceFiles, data) => {
311
- if (!sourceFiles || sourceFiles.length === 0) {
312
- this.#compilerHost.writeFile(fileName, text, writeByteOrderMark, onError, sourceFiles, data);
313
- return;
314
- }
315
- const sourceFile = ts.getOriginalNode(sourceFiles[0], ts.isSourceFile);
316
- if (this.#ngProgram) {
317
- if (this.#ngProgram.compiler.ignoreForEmit.has(sourceFile)) {
318
- return;
319
- }
320
- this.#ngProgram.compiler.incrementalCompilation.recordSuccessfulEmit(sourceFile);
321
- }
322
- const emitFileInfoCaches = this.#emittedFilesCacheMap.getOrCreate(path.normalize(sourceFile.fileName), []);
323
- if (PathUtil.isChildPath(sourceFile.fileName, this.#pkgPath)) {
324
- let realFilePath = fileName;
325
- let realText = text;
326
- if (PathUtil.isChildPath(realFilePath, path.resolve(this.#distPath, path.basename(this.#pkgPath), "src"))) {
327
- realFilePath = path.resolve(this.#distPath, path.relative(path.resolve(this.#distPath, path.basename(this.#pkgPath), "src"), realFilePath));
328
- if (fileName.endsWith(".js.map")) {
329
- const sourceMapContents = JSON.parse(realText);
330
- // remove "../../"
331
- sourceMapContents.sources[0] = sourceMapContents.sources[0].slice(6);
332
- realText = JSON.stringify(sourceMapContents);
333
- }
334
- }
335
- emitFileInfoCaches.push({
336
- outAbsPath: realFilePath,
337
- text: realText,
338
- });
421
+ }
422
+
423
+ this.#debug(`emit for`, sf.fileName);
424
+ this.#program.emit(
425
+ sf,
426
+ (fileName, text, writeByteOrderMark, onError, sourceFiles, data) => {
427
+ if (!sourceFiles || sourceFiles.length === 0) {
428
+ this.#compilerHost.writeFile(fileName, text, writeByteOrderMark, onError, sourceFiles, data);
429
+ return;
430
+ }
431
+
432
+ const sourceFile = ts.getOriginalNode(sourceFiles[0], ts.isSourceFile);
433
+ if (this.#ngProgram) {
434
+ if (this.#ngProgram.compiler.ignoreForEmit.has(sourceFile)) {
435
+ return;
339
436
  }
340
- else {
341
- emitFileInfoCaches.push({ text });
437
+ this.#ngProgram.compiler.incrementalCompilation.recordSuccessfulEmit(sourceFile);
438
+ }
439
+
440
+ const emitFileInfoCaches = this.#emittedFilesCacheMap.getOrCreate(path.normalize(sourceFile.fileName), []);
441
+ if (PathUtil.isChildPath(sourceFile.fileName, this.#pkgPath)) {
442
+ let realFilePath = fileName;
443
+ let realText = text;
444
+ if (PathUtil.isChildPath(realFilePath, path.resolve(this.#distPath, path.basename(this.#pkgPath), "src"))) {
445
+ realFilePath = path.resolve(
446
+ this.#distPath,
447
+ path.relative(path.resolve(this.#distPath, path.basename(this.#pkgPath), "src"), realFilePath),
448
+ );
449
+
450
+ if (fileName.endsWith(".js.map")) {
451
+ const sourceMapContents = JSON.parse(realText);
452
+ // remove "../../"
453
+ sourceMapContents.sources[0] = sourceMapContents.sources[0].slice(6);
454
+ realText = JSON.stringify(sourceMapContents);
455
+ }
342
456
  }
343
- emitFileSet.add(path.normalize(sourceFile.fileName));
344
- }, undefined, undefined, transformers);
345
- }
457
+
458
+ emitFileInfoCaches.push({
459
+ outAbsPath: realFilePath,
460
+ text: realText,
461
+ });
462
+ } else {
463
+ emitFileInfoCaches.push({ text });
464
+ }
465
+
466
+ emitFileSet.add(path.normalize(sourceFile.fileName));
467
+ },
468
+ undefined,
469
+ undefined,
470
+ transformers,
471
+ );
472
+ }*/
346
473
  //-- global style
347
474
  if (this.#globalStyleFilePath != null &&
348
475
  FsUtil.exists(this.#globalStyleFilePath) &&
@@ -359,6 +486,7 @@ export class SdTsCompiler {
359
486
  }
360
487
  //-- init
361
488
  this.#modifiedFileSet.clear();
489
+ const affectedFileSet = new Set(Array.from(affectedSourceFileSet).map((item) => path.normalize(item.fileName)));
362
490
  this.#debug(`build completed`, affectedFileSet, diagnostics.length);
363
491
  //-- result
364
492
  return {
@@ -374,86 +502,5 @@ export class SdTsCompiler {
374
502
  #debug(...msg) {
375
503
  this.#logger.debug(`[${path.basename(this.#pkgPath)}]`, ...msg);
376
504
  }
377
- #findDeps(sf) {
378
- const deps = [];
379
- const tc = this.#program.getTypeChecker();
380
- sf.forEachChild((node) => {
381
- if (ts.isExportDeclaration(node)) {
382
- if (node.moduleSpecifier) {
383
- const moduleSymbol = tc.getSymbolAtLocation(node.moduleSpecifier);
384
- if (!moduleSymbol)
385
- throw new NeverEntryError(`export moduleSymbol: ${sf.fileName}`);
386
- const decls = moduleSymbol.getDeclarations();
387
- if (!decls)
388
- throw new NeverEntryError(`export decls: ${sf.fileName}`);
389
- const namedBindings = node.exportClause;
390
- if (namedBindings && ts.isNamedExports(namedBindings)) {
391
- for (const el of namedBindings.elements) {
392
- for (const decl of decls) {
393
- deps.push({
394
- fileName: path.normalize(decl.getSourceFile().fileName),
395
- importName: el.name.text,
396
- exportName: el.propertyName?.text ?? el.name.text,
397
- });
398
- }
399
- }
400
- }
401
- else {
402
- if (!moduleSymbol.exports) {
403
- throw new NeverEntryError("1234");
404
- }
405
- for (const decl of decls) {
406
- for (const key of moduleSymbol.exports.keys()) {
407
- deps.push({
408
- fileName: path.normalize(decl.getSourceFile().fileName),
409
- importName: key.toString(),
410
- exportName: key.toString(),
411
- });
412
- }
413
- }
414
- }
415
- }
416
- }
417
- else if (ts.isImportDeclaration(node)) {
418
- const moduleSymbol = tc.getSymbolAtLocation(node.moduleSpecifier);
419
- if (!moduleSymbol) {
420
- if (ts.isStringLiteral(node.moduleSpecifier) && node.moduleSpecifier.text.startsWith("./")) {
421
- deps.push({
422
- fileName: path.normalize(path.resolve(path.dirname(sf.fileName), node.moduleSpecifier.text)),
423
- importName: "*",
424
- });
425
- }
426
- /*else {
427
- throw new NeverEntryError(`import moduleSymbol: ${sf.fileName} ${node.moduleSpecifier["text"]}`);
428
- }*/
429
- }
430
- else {
431
- const decls = moduleSymbol.getDeclarations();
432
- if (!decls)
433
- throw new NeverEntryError(`import decls: ${sf.fileName}`);
434
- const namedBindings = node.importClause?.namedBindings;
435
- if (namedBindings && ts.isNamedImports(namedBindings)) {
436
- for (const el of namedBindings.elements) {
437
- for (const decl of decls) {
438
- deps.push({
439
- fileName: path.normalize(decl.getSourceFile().fileName),
440
- importName: el.name.text,
441
- });
442
- }
443
- }
444
- }
445
- else {
446
- for (const decl of decls) {
447
- deps.push({
448
- fileName: path.normalize(decl.getSourceFile().fileName),
449
- importName: "*",
450
- });
451
- }
452
- }
453
- }
454
- }
455
- });
456
- return deps;
457
- }
458
505
  }
459
506
  //# sourceMappingURL=SdTsCompiler.js.map