@danielx/civet 0.11.10 → 0.11.12

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.
@@ -22,11 +22,22 @@ try {
22
22
  }
23
23
  return parentPort.postMessage({ id, result, errors: args[1]?.errors });
24
24
  } catch (error) {
25
- return parentPort.postMessage({ id, error: {
26
- type: error.constructor.name,
27
- name: error.name,
28
- message: error.message
29
- } });
25
+ if (error instanceof Error) {
26
+ return parentPort.postMessage({ id, error: {
27
+ type: error.constructor.name,
28
+ name: error.name,
29
+ message: error.message
30
+ } });
31
+ } else {
32
+ return parentPort.postMessage({
33
+ id,
34
+ error: {
35
+ type: typeof error,
36
+ name: "Error",
37
+ message: String(error)
38
+ }
39
+ });
40
+ }
30
41
  }
31
42
  });
32
43
  }
@@ -144,9 +144,9 @@ function remapFileName(fileName, transpilers) {
144
144
  }
145
145
 
146
146
  // source/ts-service/host.civet
147
- var import_node_path3 = __toESM(require("node:path"));
148
- var import_typescript5 = __toESM(require("typescript"));
149
- var import_typescript6 = require("typescript");
147
+ var import_node_path4 = __toESM(require("node:path"));
148
+ var import_typescript6 = __toESM(require("typescript"));
149
+ var import_typescript7 = require("typescript");
150
150
 
151
151
  // source/ts-service/config.civet
152
152
  var import_typescript4 = __toESM(require("typescript"));
@@ -258,9 +258,132 @@ function parseTsConfigForCivet(projectPath, transpilers, options = {}) {
258
258
  return parsed;
259
259
  }
260
260
 
261
+ // source/ts-service/resolve.civet
262
+ var import_node_path3 = __toESM(require("node:path"));
263
+ var import_typescript5 = __toESM(require("typescript"));
264
+ function resolveTranspiledModuleName({
265
+ name,
266
+ containingFile,
267
+ compilerOptions,
268
+ resolutionMode,
269
+ transpilers,
270
+ resolveTypeScript,
271
+ fileExists,
272
+ directoryExists
273
+ }) {
274
+ const resolvedModule = (sourcePath, transpiler) => {
275
+ return {
276
+ resolvedFileName: sourcePath + transpiler.target,
277
+ extension: transpiler.target,
278
+ isExternalLibraryImport: false
279
+ };
280
+ };
281
+ const tsResolved = resolveTypeScript();
282
+ if (tsResolved.resolvedModule) {
283
+ return tsResolved;
284
+ }
285
+ const moduleResolution = import_typescript5.default.getEmitModuleResolutionKind(compilerOptions);
286
+ const isRelative = import_typescript5.default.isExternalModuleNameRelative(name);
287
+ let allowImplicitExtension = isRelative && !(resolutionMode === import_typescript5.default.ModuleKind.ESNext && (moduleResolution === import_typescript5.default.ModuleResolutionKind.Node16 || moduleResolution === import_typescript5.default.ModuleResolutionKind.NodeNext));
288
+ let allowDirectoryIndex = (!isRelative || allowImplicitExtension) && moduleResolution !== import_typescript5.default.ModuleResolutionKind.Classic;
289
+ const tryResolveSource = (sourcePath) => {
290
+ if (fileExists(sourcePath)) {
291
+ const candidateExtension = getExtensionFromPath(sourcePath);
292
+ let ref;
293
+ if (ref = transpilers.get(candidateExtension)) {
294
+ const candidateTranspiler = ref;
295
+ return resolvedModule(sourcePath, candidateTranspiler);
296
+ }
297
+ }
298
+ if (allowImplicitExtension) {
299
+ for (const [ext, t] of transpilers) {
300
+ const candidate = sourcePath + ext;
301
+ if (fileExists(candidate)) {
302
+ return resolvedModule(candidate, t);
303
+ }
304
+ }
305
+ }
306
+ if (allowDirectoryIndex && directoryExists(sourcePath)) {
307
+ for (const [_, t] of transpilers) {
308
+ const index = import_node_path3.default.join(sourcePath, "index" + t.extension);
309
+ if (fileExists(index)) {
310
+ return resolvedModule(index, t);
311
+ }
312
+ }
313
+ }
314
+ return;
315
+ };
316
+ if (!isRelative) {
317
+ let ref1;
318
+ if (ref1 = compilerOptions.paths) {
319
+ const paths = ref1;
320
+ let ref2;
321
+ if (ref2 = compilerOptions.baseUrl ?? compilerOptions.pathsBasePath) {
322
+ const pathsBase = ref2;
323
+ let bestPrefixLength = -1;
324
+ let bestCandidates = [];
325
+ for (const [pattern, replacements] of Object.entries(paths)) {
326
+ const starIndex = pattern.indexOf("*");
327
+ let matched;
328
+ let prefixLength;
329
+ if (starIndex >= 0) {
330
+ const prefix = pattern.slice(0, starIndex);
331
+ const suffix = pattern.slice(starIndex + 1);
332
+ if (name.startsWith(prefix) && name.endsWith(suffix) && name.length >= prefix.length + suffix.length) {
333
+ matched = name.slice(prefix.length, name.length - suffix.length);
334
+ prefixLength = prefix.length;
335
+ } else {
336
+ continue;
337
+ }
338
+ } else {
339
+ if (!(name === pattern)) {
340
+ continue;
341
+ }
342
+ matched = "";
343
+ prefixLength = pattern.length;
344
+ }
345
+ if (prefixLength < bestPrefixLength) {
346
+ continue;
347
+ }
348
+ if (prefixLength > bestPrefixLength) {
349
+ bestPrefixLength = prefixLength;
350
+ bestCandidates = [];
351
+ }
352
+ for (const replacement of replacements) {
353
+ let ref3;
354
+ if (starIndex >= 0) {
355
+ ref3 = replacement.replace("*", () => matched);
356
+ } else {
357
+ ref3 = replacement;
358
+ }
359
+ ;
360
+ const target = ref3;
361
+ bestCandidates.push(import_node_path3.default.resolve(pathsBase, target));
362
+ }
363
+ }
364
+ for (const candidate of bestCandidates) {
365
+ let ref4;
366
+ if (ref4 = tryResolveSource(candidate)) {
367
+ const resolved2 = ref4;
368
+ return { resolvedModule: resolved2 };
369
+ }
370
+ }
371
+ }
372
+ }
373
+ }
374
+ if (!isRelative) {
375
+ return tsResolved;
376
+ }
377
+ const relativeSourcePath = import_node_path3.default.resolve(import_node_path3.default.dirname(containingFile), name);
378
+ const resolved = tryResolveSource(relativeSourcePath);
379
+ if (resolved) {
380
+ return { resolvedModule: resolved };
381
+ }
382
+ return tsResolved;
383
+ }
384
+
261
385
  // source/ts-service/host.civet
262
386
  var import_node_assert = __toESM(require("node:assert"));
263
- var { isExternalModuleNameRelative } = import_typescript5.default;
264
387
  function TSHost(compilationSettings, initialFileNames, baseHost, transpilers, docFactory, _logger = console, libDir) {
265
388
  const { rootDir } = compilationSettings;
266
389
  (0, import_node_assert.default)(rootDir, "TSHost requires a rootDir in compilationSettings");
@@ -273,7 +396,7 @@ function TSHost(compilationSettings, initialFileNames, baseHost, transpilers, do
273
396
  const pathMap = /* @__PURE__ */ new Map();
274
397
  const snapshotMap = /* @__PURE__ */ new Map();
275
398
  let projectVersion = 0;
276
- const resolutionCache = import_typescript5.default.createModuleResolutionCache(rootDir, (fileName) => fileName, compilationSettings);
399
+ const resolutionCache = import_typescript6.default.createModuleResolutionCache(rootDir, (fileName) => fileName, compilationSettings);
277
400
  const baseReadFile = baseHost.readFile.bind(baseHost);
278
401
  const baseFileExists = baseHost.fileExists.bind(baseHost);
279
402
  const baseDirectoryExists = baseHost.directoryExists?.bind(baseHost) ?? (() => false);
@@ -282,7 +405,7 @@ function TSHost(compilationSettings, initialFileNames, baseHost, transpilers, do
282
405
  /** Mogrifies transpilable extensions inside `package.json#imports` on read. */
283
406
  readFile(filename) {
284
407
  const contents = getPathSource(filename);
285
- if (contents && import_node_path3.default.basename(filename) === "package.json") {
408
+ if (contents && import_node_path4.default.basename(filename) === "package.json") {
286
409
  return mogrifyPackageJsonImports(contents, transpilers);
287
410
  }
288
411
  return contents;
@@ -297,7 +420,7 @@ function TSHost(compilationSettings, initialFileNames, baseHost, transpilers, do
297
420
  */
298
421
  getDefaultLibFileName(options) {
299
422
  if (libDir) {
300
- return import_node_path3.default.join(libDir, import_typescript5.default.getDefaultLibFileName(options));
423
+ return import_node_path4.default.join(libDir, import_typescript6.default.getDefaultLibFileName(options));
301
424
  }
302
425
  return baseHost.getDefaultLibFileName(options);
303
426
  },
@@ -305,7 +428,7 @@ function TSHost(compilationSettings, initialFileNames, baseHost, transpilers, do
305
428
  if (libDir) {
306
429
  return libDir;
307
430
  }
308
- return baseHost.getDefaultLibLocation?.() ?? import_node_path3.default.dirname(baseHost.getDefaultLibFileName(compilationSettings));
431
+ return baseHost.getDefaultLibLocation?.() ?? import_node_path4.default.dirname(baseHost.getDefaultLibFileName(compilationSettings));
309
432
  },
310
433
  getModuleResolutionCache() {
311
434
  return resolutionCache;
@@ -317,128 +440,43 @@ function TSHost(compilationSettings, initialFileNames, baseHost, transpilers, do
317
440
  * synthetic `<src>.<target>` so subsequent `getScriptSnapshot` calls
318
441
  * hit the transpiler.
319
442
  */
320
- resolveModuleNames(moduleNames, containingFile, _reusedNames, _redirectedReference, compilerOptions, _containingSourceFile) {
321
- return moduleNames.map((name) => {
322
- const { resolvedModule } = import_typescript5.default.resolveModuleName(name, containingFile, compilerOptions, self, resolutionCache);
323
- if (resolvedModule) {
324
- return resolvedModule;
325
- }
326
- const extension = getExtensionFromPath(name);
327
- let transpiler = transpilers.get(extension);
328
- if (transpiler || !extension) {
329
- const exists = transpiler ? pathExists : baseDirectoryExists;
330
- const resolvedModule2 = (resolved2) => {
331
- if (!transpiler) {
332
- for (const [_, t] of transpilers) {
333
- const index = import_node_path3.default.join(resolved2, "index" + t.extension);
334
- if (pathExists(index)) {
335
- transpiler = t;
336
- resolved2 = index;
337
- break;
338
- }
339
- }
340
- if (!transpiler) {
341
- return;
342
- }
343
- }
344
- const { target } = transpiler;
345
- return {
346
- resolvedFileName: resolved2 + target,
347
- extension: target,
348
- isExternalLibraryImport: false
349
- };
350
- };
351
- const { paths, pathsBasePath } = compilationSettings;
352
- const baseUrl = compilationSettings.baseUrl;
353
- if (!isExternalModuleNameRelative(name)) {
354
- if (paths) {
355
- const pathsBase = baseUrl ?? pathsBasePath;
356
- let best = "";
357
- let bestPrefix = "";
358
- for (const [pattern, replacements] of Object.entries(paths)) {
359
- if (pattern.endsWith("*")) {
360
- const prefix = pattern.slice(0, -1);
361
- if (name.startsWith(prefix)) {
362
- for (const replacement of replacements) {
363
- const resolved2 = import_node_path3.default.resolve(
364
- pathsBase,
365
- replacement.replace("*", name.slice(prefix.length))
366
- );
367
- if (exists(resolved2) && prefix.length > bestPrefix.length) {
368
- best = resolved2;
369
- bestPrefix = prefix;
370
- }
371
- }
372
- }
373
- } else if (name === pattern) {
374
- for (const replacement of replacements) {
375
- const resolved2 = import_node_path3.default.resolve(pathsBase, replacement);
376
- if (exists(resolved2) && pattern.length > bestPrefix.length) {
377
- best = resolved2;
378
- bestPrefix = pattern;
379
- }
380
- }
381
- }
382
- }
383
- if (best) {
384
- return resolvedModule2(best);
385
- }
386
- }
387
- if (baseUrl) {
388
- const resolved2 = import_node_path3.default.resolve(baseUrl, name);
389
- if (exists(resolved2)) {
390
- return resolvedModule2(resolved2);
391
- }
392
- }
393
- } else {
394
- }
395
- const resolved = import_node_path3.default.resolve(import_node_path3.default.dirname(containingFile), name);
396
- if (exists(resolved)) {
397
- return resolvedModule2(resolved);
398
- }
399
- }
400
- return void 0;
443
+ resolveModuleNames(moduleNames, containingFile, _reusedNames, redirectedReference, compilerOptions, containingSourceFile) {
444
+ return moduleNames.map((name, index) => {
445
+ const resolutionMode = containingSourceFile && import_typescript6.default.getModeForResolutionAtIndex(containingSourceFile, index, compilerOptions);
446
+ return resolveTranspiledModuleName({
447
+ name,
448
+ containingFile,
449
+ compilerOptions,
450
+ resolutionMode,
451
+ transpilers,
452
+ resolveTypeScript: () => {
453
+ return import_typescript6.default.resolveModuleName(name, containingFile, compilerOptions, self, resolutionCache, redirectedReference, resolutionMode);
454
+ },
455
+ fileExists: pathExists,
456
+ directoryExists: baseDirectoryExists
457
+ }).resolvedModule;
401
458
  });
402
459
  },
403
- resolveModuleNameLiterals(literals, containingFile, _redirectedReference, compilerOptions) {
404
- return literals.map((literal) => {
460
+ resolveModuleNameLiterals(literals, containingFile, redirectedReference, compilerOptions, containingSourceFile) {
461
+ return literals.map((literal, index) => {
405
462
  const name = literal.text;
406
- for (const [ext, t] of transpilers) {
407
- if (name.endsWith(ext)) {
408
- const resolved = import_node_path3.default.resolve(import_node_path3.default.dirname(containingFile), name);
409
- if (pathExists(resolved)) {
410
- return {
411
- resolvedModule: {
412
- resolvedFileName: resolved + t.target,
413
- extension: t.target,
414
- isExternalLibraryImport: false
415
- }
416
- };
417
- }
418
- }
419
- }
420
- if (!getExtensionFromPath(name)) {
421
- const resolved = import_node_path3.default.resolve(import_node_path3.default.dirname(containingFile), name);
422
- if (baseDirectoryExists(resolved)) {
423
- for (const [_, t] of transpilers) {
424
- const index = import_node_path3.default.join(resolved, "index" + t.extension);
425
- if (pathExists(index)) {
426
- return {
427
- resolvedModule: {
428
- resolvedFileName: index + t.target,
429
- extension: t.target,
430
- isExternalLibraryImport: false
431
- }
432
- };
433
- }
434
- }
435
- }
436
- }
437
- return { resolvedModule: import_typescript5.default.resolveModuleName(name, containingFile, compilerOptions, self, resolutionCache).resolvedModule };
463
+ const resolutionMode = containingSourceFile && import_typescript6.default.getModeForResolutionAtIndex(containingSourceFile, index, compilerOptions);
464
+ return resolveTranspiledModuleName({
465
+ name,
466
+ containingFile,
467
+ compilerOptions,
468
+ resolutionMode,
469
+ transpilers,
470
+ resolveTypeScript: () => {
471
+ return import_typescript6.default.resolveModuleName(name, containingFile, compilerOptions, self, resolutionCache, redirectedReference, resolutionMode);
472
+ },
473
+ fileExists: pathExists,
474
+ directoryExists: baseDirectoryExists
475
+ });
438
476
  });
439
477
  },
440
478
  addOrUpdateDocument(doc) {
441
- const rawPath = import_node_path3.default.normalize(docFactory.uriToPath(doc.uri));
479
+ const rawPath = import_node_path4.default.normalize(docFactory.uriToPath(doc.uri));
442
480
  const p = getCanonicalFileName(rawPath);
443
481
  snapshotMap.delete(p);
444
482
  projectVersion++;
@@ -549,7 +587,7 @@ function TSHost(compilationSettings, initialFileNames, baseHost, transpilers, do
549
587
  return void 0;
550
588
  }
551
589
  function getTranspiledPath(p) {
552
- p = import_node_path3.default.normalize(p);
590
+ p = import_node_path4.default.normalize(p);
553
591
  const extension = getExtensionFromPath(p);
554
592
  const transpiler = transpilers.get(extension);
555
593
  if (transpiler) {
@@ -561,7 +599,7 @@ function TSHost(compilationSettings, initialFileNames, baseHost, transpilers, do
561
599
  return getCanonicalFileName(getTranspiledPath(p));
562
600
  }
563
601
  function getOrCreatePathSnapshot(p) {
564
- const rawPath = import_node_path3.default.normalize(p);
602
+ const rawPath = import_node_path4.default.normalize(p);
565
603
  p = getCanonicalFileName(rawPath);
566
604
  let snapshot = snapshotMap.get(p);
567
605
  if (snapshot) {
@@ -643,7 +681,7 @@ function TSHost(compilationSettings, initialFileNames, baseHost, transpilers, do
643
681
  return transpiledCode;
644
682
  }
645
683
  function initTranspiledDoc(p) {
646
- const scriptPath = import_node_path3.default.normalize(p);
684
+ const scriptPath = import_node_path4.default.normalize(p);
647
685
  p = getCanonicalFileName(scriptPath);
648
686
  const uri = docFactory.pathToUri(scriptPath);
649
687
  const transpiledDoc = docFactory.create(uri, "none", -1, "");
@@ -654,16 +692,16 @@ function TSHost(compilationSettings, initialFileNames, baseHost, transpilers, do
654
692
  }
655
693
 
656
694
  // source/ts-service/service.civet
657
- var import_node_path4 = __toESM(require("node:path"));
658
- var import_typescript7 = __toESM(require("typescript"));
659
- var import_typescript8 = require("typescript");
695
+ var import_node_path5 = __toESM(require("node:path"));
696
+ var import_typescript8 = __toESM(require("typescript"));
697
+ var import_typescript9 = require("typescript");
660
698
  var {
661
699
  createCompilerHost,
662
700
  createLanguageService
663
- } = import_typescript7.default;
701
+ } = import_typescript8.default;
664
702
  function TSService(projectPath, options) {
665
703
  const { plugins = [], docFactory, libDir, discoverProjectFiles = true, extraCompilerOptions } = options;
666
- const system = options.system ?? import_typescript7.default.sys;
704
+ const system = options.system ?? import_typescript8.default.sys;
667
705
  const logger = options.logger ?? console;
668
706
  const transpilers = buildTranspilers(plugins);
669
707
  function registerPlugin(plugin) {
@@ -688,7 +726,7 @@ function TSService(projectPath, options) {
688
726
  const host = TSHost(hostOptions, parsedConfig.fileNames, baseHost, transpilers, docFactory, logger, libDir);
689
727
  const service = createLanguageService(host);
690
728
  const loadPlugins = async function() {
691
- const civetFolder = import_node_path4.default.join(projectPath, "./.civet/");
729
+ const civetFolder = import_node_path5.default.join(projectPath, "./.civet/");
692
730
  let civetFiles;
693
731
  try {
694
732
  civetFiles = system.readDirectory(civetFolder);
@@ -725,7 +763,7 @@ function TSService(projectPath, options) {
725
763
  });
726
764
  }
727
765
  function createBaseHost(options, system) {
728
- if (system === import_typescript7.default.sys) {
766
+ if (system === import_typescript8.default.sys) {
729
767
  return createCompilerHost(options);
730
768
  }
731
769
  const getCanonicalFileName2 = (fileName) => {
@@ -739,10 +777,10 @@ function createBaseHost(options, system) {
739
777
  if (!(sourceText != null)) {
740
778
  return;
741
779
  }
742
- return import_typescript7.default.createSourceFile(fileName, sourceText, languageVersion);
780
+ return import_typescript8.default.createSourceFile(fileName, sourceText, languageVersion);
743
781
  },
744
782
  getDefaultLibFileName(options2) {
745
- return import_node_path4.default.join("/typescript/lib", import_typescript7.default.getDefaultLibFileName(options2));
783
+ return import_node_path5.default.join("/typescript/lib", import_typescript8.default.getDefaultLibFileName(options2));
746
784
  },
747
785
  writeFile(fileName, content) {
748
786
  return system.writeFile?.(fileName, content);
@@ -750,8 +788,8 @@ function createBaseHost(options, system) {
750
788
  getCurrentDirectory() {
751
789
  return system.getCurrentDirectory();
752
790
  },
753
- getDirectories(path7) {
754
- return system.getDirectories?.(path7) ?? [];
791
+ getDirectories(path8) {
792
+ return system.getDirectories?.(path8) ?? [];
755
793
  },
756
794
  fileExists(fileName) {
757
795
  return system.fileExists(fileName);
@@ -766,14 +804,17 @@ function createBaseHost(options, system) {
766
804
  getNewLine() {
767
805
  return system.newLine;
768
806
  },
769
- directoryExists(path7) {
770
- return system.directoryExists?.(path7) ?? false;
807
+ directoryExists(path8) {
808
+ if (!(system.directoryExists != null)) {
809
+ return false;
810
+ }
811
+ return system.directoryExists(path8);
771
812
  },
772
- readDirectory(path7, extensions, excludes, includes, depth) {
773
- return system.readDirectory(path7, extensions, excludes, includes, depth);
813
+ readDirectory(path8, extensions, excludes, includes, depth) {
814
+ return system.readDirectory(path8, extensions, excludes, includes, depth);
774
815
  },
775
- realpath(path7) {
776
- return system.realpath ? system.realpath(path7) : path7;
816
+ realpath(path8) {
817
+ return system.realpath ? system.realpath(path8) : path8;
777
818
  }
778
819
  };
779
820
  }
@@ -814,12 +855,12 @@ function createInMemoryDocFactory() {
814
855
  var import_civet = require("@danielx/civet");
815
856
  var import_civet2 = __toESM(require("@danielx/civet"));
816
857
  var import_package = __toESM(require("@danielx/civet/package.json"));
817
- var import_typescript9 = require("typescript");
858
+ var import_typescript10 = require("typescript");
818
859
 
819
860
  // source/cache.civet
820
861
  var crypto = __toESM(require("node:crypto"));
821
862
  var fs = __toESM(require("node:fs"));
822
- var path5 = __toESM(require("node:path"));
863
+ var path6 = __toESM(require("node:path"));
823
864
  function hashParts(parts) {
824
865
  const hash = crypto.createHash("sha1");
825
866
  for (const part of parts) {
@@ -843,7 +884,7 @@ function stableStringify(value) {
843
884
  });
844
885
  }
845
886
  function makeCacheKey(input) {
846
- const resolved = path5.resolve(input.sourcePath).replace(/\\/g, "/");
887
+ const resolved = path6.resolve(input.sourcePath).replace(/\\/g, "/");
847
888
  return hashParts([
848
889
  input.source,
849
890
  input.compilerName,
@@ -873,7 +914,7 @@ function createDiskCache(dir) {
873
914
  }
874
915
  return {
875
916
  get(key) {
876
- const target = path5.join(dir, key);
917
+ const target = path6.join(dir, key);
877
918
  try {
878
919
  const content = fs.readFileSync(target, "utf8");
879
920
  try {
@@ -887,7 +928,7 @@ function createDiskCache(dir) {
887
928
  }
888
929
  },
889
930
  set(key, value) {
890
- const target = path5.join(dir, key);
931
+ const target = path6.join(dir, key);
891
932
  try {
892
933
  const tmp = `${target}.tmp.${process.pid}`;
893
934
  fs.writeFileSync(tmp, value);
@@ -994,7 +1035,7 @@ var import_civet3 = require("@danielx/civet");
994
1035
  var import_civet4 = __toESM(require("@danielx/civet"));
995
1036
  var import_package2 = __toESM(require("@danielx/civet/package.json"));
996
1037
  var import_node_module = require("node:module");
997
- var import_typescript10 = require("typescript");
1038
+ var import_typescript11 = require("typescript");
998
1039
  var heraRequire = (0, import_node_module.createRequire)(
999
1040
  /* c8 ignore start -- one branch fires per build target; tests cover only one */
1000
1041
  typeof __filename !== "undefined" ? __filename : ""
@@ -1113,19 +1154,18 @@ function makeHeraPlugin(options = {}) {
1113
1154
  }
1114
1155
 
1115
1156
  // source/ts-service/typecheck.civet
1116
- var import_typescript11 = __toESM(require("typescript"));
1157
+ var import_typescript12 = __toESM(require("typescript"));
1117
1158
  var fs2 = __toESM(require("fs"));
1118
- var path6 = __toESM(require("path"));
1159
+ var path7 = __toESM(require("path"));
1119
1160
  function makeIncrementalTypecheckProgram(projectPath, options) {
1120
1161
  const transpilers = buildTranspilers(options.plugins);
1121
- const extraExtensions = Array.from(transpilers.keys());
1122
1162
  const parsed = parseTsConfigForCivet(projectPath, transpilers, { tsConfig: options.tsConfig });
1123
1163
  const compilerOptions = {
1124
1164
  ...parsed.options,
1125
1165
  ...options.extraCompilerOptions
1126
1166
  };
1127
- compilerOptions.jsx ??= import_typescript11.default.JsxEmit.Preserve;
1128
- const baseHost = import_typescript11.default.createIncrementalCompilerHost(compilerOptions);
1167
+ compilerOptions.jsx ??= import_typescript12.default.JsxEmit.Preserve;
1168
+ const baseHost = import_typescript12.default.createIncrementalCompilerHost(compilerOptions);
1129
1169
  const fileMetaData = /* @__PURE__ */ new Map();
1130
1170
  const hashText = (text) => {
1131
1171
  return baseHost.createHash?.(text) ?? text.length.toString();
@@ -1169,7 +1209,7 @@ function makeIncrementalTypecheckProgram(projectPath, options) {
1169
1209
  parseErrors: result.errors,
1170
1210
  fatal: false
1171
1211
  });
1172
- const sf2 = import_typescript11.default.createSourceFile(fileName, result.code, langVersion, true);
1212
+ const sf2 = import_typescript12.default.createSourceFile(fileName, result.code, langVersion, true);
1173
1213
  sf2.version = hashText(result.code);
1174
1214
  return sf2;
1175
1215
  }
@@ -1180,6 +1220,7 @@ function makeIncrementalTypecheckProgram(projectPath, options) {
1180
1220
  return sf;
1181
1221
  };
1182
1222
  const origFileExists = baseHost.fileExists.bind(baseHost);
1223
+ const origDirectoryExists = baseHost.directoryExists?.bind(baseHost) ?? (() => false);
1183
1224
  baseHost.fileExists = (fileName) => {
1184
1225
  const exts = getTranspiledExtensionsFromPath(fileName);
1185
1226
  if (exts) {
@@ -1193,43 +1234,56 @@ function makeIncrementalTypecheckProgram(projectPath, options) {
1193
1234
  const origReadFile = baseHost.readFile.bind(baseHost);
1194
1235
  baseHost.readFile = (fileName) => {
1195
1236
  const contents = origReadFile(fileName);
1196
- if (contents && path6.basename(fileName) === "package.json") {
1237
+ if (contents && path7.basename(fileName) === "package.json") {
1197
1238
  return mogrifyPackageJsonImports(contents, transpilers);
1198
1239
  }
1199
1240
  return contents;
1200
1241
  };
1201
- baseHost.resolveModuleNameLiterals = (literals, containingFile, _redirected, opts) => {
1202
- return literals.map((lit) => {
1242
+ baseHost.resolveModuleNameLiterals = (literals, containingFile, redirectedReference, opts, containingSourceFile) => {
1243
+ return literals.map((lit, index) => {
1203
1244
  const name = lit.text;
1204
- for (const ext of extraExtensions) {
1205
- if (name.endsWith(ext)) {
1206
- const t = transpilers.get(ext);
1207
- const containingDir = path6.dirname(containingFile);
1208
- const resolved = path6.resolve(containingDir, name);
1209
- if (origFileExists(resolved)) {
1210
- return {
1211
- resolvedModule: {
1212
- resolvedFileName: resolved + t.target,
1213
- extension: t.target,
1214
- isExternalLibraryImport: false
1215
- }
1216
- };
1217
- }
1218
- }
1219
- }
1220
- return { resolvedModule: import_typescript11.default.resolveModuleName(name, containingFile, opts, baseHost).resolvedModule };
1245
+ const resolutionMode = containingSourceFile && import_typescript12.default.getModeForResolutionAtIndex(containingSourceFile, index, opts);
1246
+ return resolveTranspiledModuleName({
1247
+ name,
1248
+ containingFile,
1249
+ compilerOptions: opts,
1250
+ resolutionMode,
1251
+ transpilers,
1252
+ resolveTypeScript: () => {
1253
+ return import_typescript12.default.resolveModuleName(name, containingFile, opts, baseHost, void 0, redirectedReference, resolutionMode);
1254
+ },
1255
+ fileExists: origFileExists,
1256
+ directoryExists: origDirectoryExists
1257
+ });
1258
+ });
1259
+ };
1260
+ baseHost.resolveModuleNames = (moduleNames, containingFile, _reusedNames, redirectedReference, opts, containingSourceFile) => {
1261
+ return moduleNames.map((name, index) => {
1262
+ const resolutionMode = containingSourceFile && import_typescript12.default.getModeForResolutionAtIndex(containingSourceFile, index, opts);
1263
+ return resolveTranspiledModuleName({
1264
+ name,
1265
+ containingFile,
1266
+ compilerOptions: opts,
1267
+ resolutionMode,
1268
+ transpilers,
1269
+ resolveTypeScript: () => {
1270
+ return import_typescript12.default.resolveModuleName(name, containingFile, opts, baseHost, void 0, redirectedReference, resolutionMode);
1271
+ },
1272
+ fileExists: origFileExists,
1273
+ directoryExists: origDirectoryExists
1274
+ }).resolvedModule;
1221
1275
  });
1222
1276
  };
1223
1277
  const programOptions = {
1224
1278
  rootNames: parsed.fileNames,
1225
1279
  options: compilerOptions,
1226
1280
  host: baseHost,
1227
- configFileParsingDiagnostics: import_typescript11.default.getConfigFileParsingDiagnostics(parsed)
1281
+ configFileParsingDiagnostics: import_typescript12.default.getConfigFileParsingDiagnostics(parsed)
1228
1282
  };
1229
1283
  if (parsed.projectReferences) {
1230
1284
  programOptions.projectReferences = parsed.projectReferences;
1231
1285
  }
1232
- const builder = import_typescript11.default.createIncrementalProgram(programOptions);
1286
+ const builder = import_typescript12.default.createIncrementalProgram(programOptions);
1233
1287
  return {
1234
1288
  builder,
1235
1289
  host: baseHost,