@danielx/civet 0.11.11 → 0.11.13
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/CHANGELOG.md +30 -0
- package/dist/browser.js +466 -209
- package/dist/browser.min.js +1 -1
- package/dist/main.js +718 -311
- package/dist/main.mjs +718 -311
- package/dist/ts-service/index.js +232 -178
- package/dist/ts-service/index.js.map +4 -4
- package/dist/ts-service/index.mjs +228 -174
- package/dist/ts-service/index.mjs.map +4 -4
- package/dist/types.d.ts +9 -0
- package/package.json +6 -5
|
@@ -94,8 +94,8 @@ function remapFileName(fileName, transpilers) {
|
|
|
94
94
|
}
|
|
95
95
|
|
|
96
96
|
// source/ts-service/host.civet
|
|
97
|
-
import
|
|
98
|
-
import
|
|
97
|
+
import path4 from "node:path";
|
|
98
|
+
import ts6 from "typescript";
|
|
99
99
|
import {} from "typescript";
|
|
100
100
|
|
|
101
101
|
// source/ts-service/config.civet
|
|
@@ -208,9 +208,132 @@ function parseTsConfigForCivet(projectPath, transpilers, options = {}) {
|
|
|
208
208
|
return parsed;
|
|
209
209
|
}
|
|
210
210
|
|
|
211
|
+
// source/ts-service/resolve.civet
|
|
212
|
+
import path3 from "node:path";
|
|
213
|
+
import ts5 from "typescript";
|
|
214
|
+
function resolveTranspiledModuleName({
|
|
215
|
+
name,
|
|
216
|
+
containingFile,
|
|
217
|
+
compilerOptions,
|
|
218
|
+
resolutionMode,
|
|
219
|
+
transpilers,
|
|
220
|
+
resolveTypeScript,
|
|
221
|
+
fileExists,
|
|
222
|
+
directoryExists
|
|
223
|
+
}) {
|
|
224
|
+
const resolvedModule = (sourcePath, transpiler) => {
|
|
225
|
+
return {
|
|
226
|
+
resolvedFileName: sourcePath + transpiler.target,
|
|
227
|
+
extension: transpiler.target,
|
|
228
|
+
isExternalLibraryImport: false
|
|
229
|
+
};
|
|
230
|
+
};
|
|
231
|
+
const tsResolved = resolveTypeScript();
|
|
232
|
+
if (tsResolved.resolvedModule) {
|
|
233
|
+
return tsResolved;
|
|
234
|
+
}
|
|
235
|
+
const moduleResolution = ts5.getEmitModuleResolutionKind(compilerOptions);
|
|
236
|
+
const isRelative = ts5.isExternalModuleNameRelative(name);
|
|
237
|
+
let allowImplicitExtension = isRelative && !(resolutionMode === ts5.ModuleKind.ESNext && (moduleResolution === ts5.ModuleResolutionKind.Node16 || moduleResolution === ts5.ModuleResolutionKind.NodeNext));
|
|
238
|
+
let allowDirectoryIndex = (!isRelative || allowImplicitExtension) && moduleResolution !== ts5.ModuleResolutionKind.Classic;
|
|
239
|
+
const tryResolveSource = (sourcePath) => {
|
|
240
|
+
if (fileExists(sourcePath)) {
|
|
241
|
+
const candidateExtension = getExtensionFromPath(sourcePath);
|
|
242
|
+
let ref;
|
|
243
|
+
if (ref = transpilers.get(candidateExtension)) {
|
|
244
|
+
const candidateTranspiler = ref;
|
|
245
|
+
return resolvedModule(sourcePath, candidateTranspiler);
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
if (allowImplicitExtension) {
|
|
249
|
+
for (const [ext, t] of transpilers) {
|
|
250
|
+
const candidate = sourcePath + ext;
|
|
251
|
+
if (fileExists(candidate)) {
|
|
252
|
+
return resolvedModule(candidate, t);
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
if (allowDirectoryIndex && directoryExists(sourcePath)) {
|
|
257
|
+
for (const [_, t] of transpilers) {
|
|
258
|
+
const index = path3.join(sourcePath, "index" + t.extension);
|
|
259
|
+
if (fileExists(index)) {
|
|
260
|
+
return resolvedModule(index, t);
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
return;
|
|
265
|
+
};
|
|
266
|
+
if (!isRelative) {
|
|
267
|
+
let ref1;
|
|
268
|
+
if (ref1 = compilerOptions.paths) {
|
|
269
|
+
const paths = ref1;
|
|
270
|
+
let ref2;
|
|
271
|
+
if (ref2 = compilerOptions.baseUrl ?? compilerOptions.pathsBasePath) {
|
|
272
|
+
const pathsBase = ref2;
|
|
273
|
+
let bestPrefixLength = -1;
|
|
274
|
+
let bestCandidates = [];
|
|
275
|
+
for (const [pattern, replacements] of Object.entries(paths)) {
|
|
276
|
+
const starIndex = pattern.indexOf("*");
|
|
277
|
+
let matched;
|
|
278
|
+
let prefixLength;
|
|
279
|
+
if (starIndex >= 0) {
|
|
280
|
+
const prefix = pattern.slice(0, starIndex);
|
|
281
|
+
const suffix = pattern.slice(starIndex + 1);
|
|
282
|
+
if (name.startsWith(prefix) && name.endsWith(suffix) && name.length >= prefix.length + suffix.length) {
|
|
283
|
+
matched = name.slice(prefix.length, name.length - suffix.length);
|
|
284
|
+
prefixLength = prefix.length;
|
|
285
|
+
} else {
|
|
286
|
+
continue;
|
|
287
|
+
}
|
|
288
|
+
} else {
|
|
289
|
+
if (!(name === pattern)) {
|
|
290
|
+
continue;
|
|
291
|
+
}
|
|
292
|
+
matched = "";
|
|
293
|
+
prefixLength = pattern.length;
|
|
294
|
+
}
|
|
295
|
+
if (prefixLength < bestPrefixLength) {
|
|
296
|
+
continue;
|
|
297
|
+
}
|
|
298
|
+
if (prefixLength > bestPrefixLength) {
|
|
299
|
+
bestPrefixLength = prefixLength;
|
|
300
|
+
bestCandidates = [];
|
|
301
|
+
}
|
|
302
|
+
for (const replacement of replacements) {
|
|
303
|
+
let ref3;
|
|
304
|
+
if (starIndex >= 0) {
|
|
305
|
+
ref3 = replacement.replace("*", () => matched);
|
|
306
|
+
} else {
|
|
307
|
+
ref3 = replacement;
|
|
308
|
+
}
|
|
309
|
+
;
|
|
310
|
+
const target = ref3;
|
|
311
|
+
bestCandidates.push(path3.resolve(pathsBase, target));
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
for (const candidate of bestCandidates) {
|
|
315
|
+
let ref4;
|
|
316
|
+
if (ref4 = tryResolveSource(candidate)) {
|
|
317
|
+
const resolved2 = ref4;
|
|
318
|
+
return { resolvedModule: resolved2 };
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
if (!isRelative) {
|
|
325
|
+
return tsResolved;
|
|
326
|
+
}
|
|
327
|
+
const relativeSourcePath = path3.resolve(path3.dirname(containingFile), name);
|
|
328
|
+
const resolved = tryResolveSource(relativeSourcePath);
|
|
329
|
+
if (resolved) {
|
|
330
|
+
return { resolvedModule: resolved };
|
|
331
|
+
}
|
|
332
|
+
return tsResolved;
|
|
333
|
+
}
|
|
334
|
+
|
|
211
335
|
// source/ts-service/host.civet
|
|
212
336
|
import assert from "node:assert";
|
|
213
|
-
var { isExternalModuleNameRelative } = ts5;
|
|
214
337
|
function TSHost(compilationSettings, initialFileNames, baseHost, transpilers, docFactory, _logger = console, libDir) {
|
|
215
338
|
const { rootDir } = compilationSettings;
|
|
216
339
|
assert(rootDir, "TSHost requires a rootDir in compilationSettings");
|
|
@@ -223,7 +346,7 @@ function TSHost(compilationSettings, initialFileNames, baseHost, transpilers, do
|
|
|
223
346
|
const pathMap = /* @__PURE__ */ new Map();
|
|
224
347
|
const snapshotMap = /* @__PURE__ */ new Map();
|
|
225
348
|
let projectVersion = 0;
|
|
226
|
-
const resolutionCache =
|
|
349
|
+
const resolutionCache = ts6.createModuleResolutionCache(rootDir, (fileName) => fileName, compilationSettings);
|
|
227
350
|
const baseReadFile = baseHost.readFile.bind(baseHost);
|
|
228
351
|
const baseFileExists = baseHost.fileExists.bind(baseHost);
|
|
229
352
|
const baseDirectoryExists = baseHost.directoryExists?.bind(baseHost) ?? (() => false);
|
|
@@ -232,7 +355,7 @@ function TSHost(compilationSettings, initialFileNames, baseHost, transpilers, do
|
|
|
232
355
|
/** Mogrifies transpilable extensions inside `package.json#imports` on read. */
|
|
233
356
|
readFile(filename) {
|
|
234
357
|
const contents = getPathSource(filename);
|
|
235
|
-
if (contents &&
|
|
358
|
+
if (contents && path4.basename(filename) === "package.json") {
|
|
236
359
|
return mogrifyPackageJsonImports(contents, transpilers);
|
|
237
360
|
}
|
|
238
361
|
return contents;
|
|
@@ -247,7 +370,7 @@ function TSHost(compilationSettings, initialFileNames, baseHost, transpilers, do
|
|
|
247
370
|
*/
|
|
248
371
|
getDefaultLibFileName(options) {
|
|
249
372
|
if (libDir) {
|
|
250
|
-
return
|
|
373
|
+
return path4.join(libDir, ts6.getDefaultLibFileName(options));
|
|
251
374
|
}
|
|
252
375
|
return baseHost.getDefaultLibFileName(options);
|
|
253
376
|
},
|
|
@@ -255,7 +378,7 @@ function TSHost(compilationSettings, initialFileNames, baseHost, transpilers, do
|
|
|
255
378
|
if (libDir) {
|
|
256
379
|
return libDir;
|
|
257
380
|
}
|
|
258
|
-
return baseHost.getDefaultLibLocation?.() ??
|
|
381
|
+
return baseHost.getDefaultLibLocation?.() ?? path4.dirname(baseHost.getDefaultLibFileName(compilationSettings));
|
|
259
382
|
},
|
|
260
383
|
getModuleResolutionCache() {
|
|
261
384
|
return resolutionCache;
|
|
@@ -267,128 +390,43 @@ function TSHost(compilationSettings, initialFileNames, baseHost, transpilers, do
|
|
|
267
390
|
* synthetic `<src>.<target>` so subsequent `getScriptSnapshot` calls
|
|
268
391
|
* hit the transpiler.
|
|
269
392
|
*/
|
|
270
|
-
resolveModuleNames(moduleNames, containingFile, _reusedNames,
|
|
271
|
-
return moduleNames.map((name) => {
|
|
272
|
-
const
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
transpiler = t;
|
|
286
|
-
resolved2 = index;
|
|
287
|
-
break;
|
|
288
|
-
}
|
|
289
|
-
}
|
|
290
|
-
if (!transpiler) {
|
|
291
|
-
return;
|
|
292
|
-
}
|
|
293
|
-
}
|
|
294
|
-
const { target } = transpiler;
|
|
295
|
-
return {
|
|
296
|
-
resolvedFileName: resolved2 + target,
|
|
297
|
-
extension: target,
|
|
298
|
-
isExternalLibraryImport: false
|
|
299
|
-
};
|
|
300
|
-
};
|
|
301
|
-
const { paths, pathsBasePath } = compilationSettings;
|
|
302
|
-
const baseUrl = compilationSettings.baseUrl;
|
|
303
|
-
if (!isExternalModuleNameRelative(name)) {
|
|
304
|
-
if (paths) {
|
|
305
|
-
const pathsBase = baseUrl ?? pathsBasePath;
|
|
306
|
-
let best = "";
|
|
307
|
-
let bestPrefix = "";
|
|
308
|
-
for (const [pattern, replacements] of Object.entries(paths)) {
|
|
309
|
-
if (pattern.endsWith("*")) {
|
|
310
|
-
const prefix = pattern.slice(0, -1);
|
|
311
|
-
if (name.startsWith(prefix)) {
|
|
312
|
-
for (const replacement of replacements) {
|
|
313
|
-
const resolved2 = path3.resolve(
|
|
314
|
-
pathsBase,
|
|
315
|
-
replacement.replace("*", name.slice(prefix.length))
|
|
316
|
-
);
|
|
317
|
-
if (exists(resolved2) && prefix.length > bestPrefix.length) {
|
|
318
|
-
best = resolved2;
|
|
319
|
-
bestPrefix = prefix;
|
|
320
|
-
}
|
|
321
|
-
}
|
|
322
|
-
}
|
|
323
|
-
} else if (name === pattern) {
|
|
324
|
-
for (const replacement of replacements) {
|
|
325
|
-
const resolved2 = path3.resolve(pathsBase, replacement);
|
|
326
|
-
if (exists(resolved2) && pattern.length > bestPrefix.length) {
|
|
327
|
-
best = resolved2;
|
|
328
|
-
bestPrefix = pattern;
|
|
329
|
-
}
|
|
330
|
-
}
|
|
331
|
-
}
|
|
332
|
-
}
|
|
333
|
-
if (best) {
|
|
334
|
-
return resolvedModule2(best);
|
|
335
|
-
}
|
|
336
|
-
}
|
|
337
|
-
if (baseUrl) {
|
|
338
|
-
const resolved2 = path3.resolve(baseUrl, name);
|
|
339
|
-
if (exists(resolved2)) {
|
|
340
|
-
return resolvedModule2(resolved2);
|
|
341
|
-
}
|
|
342
|
-
}
|
|
343
|
-
} else {
|
|
344
|
-
}
|
|
345
|
-
const resolved = path3.resolve(path3.dirname(containingFile), name);
|
|
346
|
-
if (exists(resolved)) {
|
|
347
|
-
return resolvedModule2(resolved);
|
|
348
|
-
}
|
|
349
|
-
}
|
|
350
|
-
return void 0;
|
|
393
|
+
resolveModuleNames(moduleNames, containingFile, _reusedNames, redirectedReference, compilerOptions, containingSourceFile) {
|
|
394
|
+
return moduleNames.map((name, index) => {
|
|
395
|
+
const resolutionMode = containingSourceFile && ts6.getModeForResolutionAtIndex(containingSourceFile, index, compilerOptions);
|
|
396
|
+
return resolveTranspiledModuleName({
|
|
397
|
+
name,
|
|
398
|
+
containingFile,
|
|
399
|
+
compilerOptions,
|
|
400
|
+
resolutionMode,
|
|
401
|
+
transpilers,
|
|
402
|
+
resolveTypeScript: () => {
|
|
403
|
+
return ts6.resolveModuleName(name, containingFile, compilerOptions, self, resolutionCache, redirectedReference, resolutionMode);
|
|
404
|
+
},
|
|
405
|
+
fileExists: pathExists,
|
|
406
|
+
directoryExists: baseDirectoryExists
|
|
407
|
+
}).resolvedModule;
|
|
351
408
|
});
|
|
352
409
|
},
|
|
353
|
-
resolveModuleNameLiterals(literals, containingFile,
|
|
354
|
-
return literals.map((literal) => {
|
|
410
|
+
resolveModuleNameLiterals(literals, containingFile, redirectedReference, compilerOptions, containingSourceFile) {
|
|
411
|
+
return literals.map((literal, index) => {
|
|
355
412
|
const name = literal.text;
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
}
|
|
370
|
-
if (!getExtensionFromPath(name)) {
|
|
371
|
-
const resolved = path3.resolve(path3.dirname(containingFile), name);
|
|
372
|
-
if (baseDirectoryExists(resolved)) {
|
|
373
|
-
for (const [_, t] of transpilers) {
|
|
374
|
-
const index = path3.join(resolved, "index" + t.extension);
|
|
375
|
-
if (pathExists(index)) {
|
|
376
|
-
return {
|
|
377
|
-
resolvedModule: {
|
|
378
|
-
resolvedFileName: index + t.target,
|
|
379
|
-
extension: t.target,
|
|
380
|
-
isExternalLibraryImport: false
|
|
381
|
-
}
|
|
382
|
-
};
|
|
383
|
-
}
|
|
384
|
-
}
|
|
385
|
-
}
|
|
386
|
-
}
|
|
387
|
-
return { resolvedModule: ts5.resolveModuleName(name, containingFile, compilerOptions, self, resolutionCache).resolvedModule };
|
|
413
|
+
const resolutionMode = containingSourceFile && ts6.getModeForResolutionAtIndex(containingSourceFile, index, compilerOptions);
|
|
414
|
+
return resolveTranspiledModuleName({
|
|
415
|
+
name,
|
|
416
|
+
containingFile,
|
|
417
|
+
compilerOptions,
|
|
418
|
+
resolutionMode,
|
|
419
|
+
transpilers,
|
|
420
|
+
resolveTypeScript: () => {
|
|
421
|
+
return ts6.resolveModuleName(name, containingFile, compilerOptions, self, resolutionCache, redirectedReference, resolutionMode);
|
|
422
|
+
},
|
|
423
|
+
fileExists: pathExists,
|
|
424
|
+
directoryExists: baseDirectoryExists
|
|
425
|
+
});
|
|
388
426
|
});
|
|
389
427
|
},
|
|
390
428
|
addOrUpdateDocument(doc) {
|
|
391
|
-
const rawPath =
|
|
429
|
+
const rawPath = path4.normalize(docFactory.uriToPath(doc.uri));
|
|
392
430
|
const p = getCanonicalFileName(rawPath);
|
|
393
431
|
snapshotMap.delete(p);
|
|
394
432
|
projectVersion++;
|
|
@@ -499,7 +537,7 @@ function TSHost(compilationSettings, initialFileNames, baseHost, transpilers, do
|
|
|
499
537
|
return void 0;
|
|
500
538
|
}
|
|
501
539
|
function getTranspiledPath(p) {
|
|
502
|
-
p =
|
|
540
|
+
p = path4.normalize(p);
|
|
503
541
|
const extension = getExtensionFromPath(p);
|
|
504
542
|
const transpiler = transpilers.get(extension);
|
|
505
543
|
if (transpiler) {
|
|
@@ -511,7 +549,7 @@ function TSHost(compilationSettings, initialFileNames, baseHost, transpilers, do
|
|
|
511
549
|
return getCanonicalFileName(getTranspiledPath(p));
|
|
512
550
|
}
|
|
513
551
|
function getOrCreatePathSnapshot(p) {
|
|
514
|
-
const rawPath =
|
|
552
|
+
const rawPath = path4.normalize(p);
|
|
515
553
|
p = getCanonicalFileName(rawPath);
|
|
516
554
|
let snapshot = snapshotMap.get(p);
|
|
517
555
|
if (snapshot) {
|
|
@@ -593,7 +631,7 @@ function TSHost(compilationSettings, initialFileNames, baseHost, transpilers, do
|
|
|
593
631
|
return transpiledCode;
|
|
594
632
|
}
|
|
595
633
|
function initTranspiledDoc(p) {
|
|
596
|
-
const scriptPath =
|
|
634
|
+
const scriptPath = path4.normalize(p);
|
|
597
635
|
p = getCanonicalFileName(scriptPath);
|
|
598
636
|
const uri = docFactory.pathToUri(scriptPath);
|
|
599
637
|
const transpiledDoc = docFactory.create(uri, "none", -1, "");
|
|
@@ -604,16 +642,16 @@ function TSHost(compilationSettings, initialFileNames, baseHost, transpilers, do
|
|
|
604
642
|
}
|
|
605
643
|
|
|
606
644
|
// source/ts-service/service.civet
|
|
607
|
-
import
|
|
608
|
-
import
|
|
645
|
+
import path5 from "node:path";
|
|
646
|
+
import ts7 from "typescript";
|
|
609
647
|
import {} from "typescript";
|
|
610
648
|
var {
|
|
611
649
|
createCompilerHost,
|
|
612
650
|
createLanguageService
|
|
613
|
-
} =
|
|
651
|
+
} = ts7;
|
|
614
652
|
function TSService(projectPath, options) {
|
|
615
653
|
const { plugins = [], docFactory, libDir, discoverProjectFiles = true, extraCompilerOptions } = options;
|
|
616
|
-
const system = options.system ??
|
|
654
|
+
const system = options.system ?? ts7.sys;
|
|
617
655
|
const logger = options.logger ?? console;
|
|
618
656
|
const transpilers = buildTranspilers(plugins);
|
|
619
657
|
function registerPlugin(plugin) {
|
|
@@ -638,7 +676,7 @@ function TSService(projectPath, options) {
|
|
|
638
676
|
const host = TSHost(hostOptions, parsedConfig.fileNames, baseHost, transpilers, docFactory, logger, libDir);
|
|
639
677
|
const service = createLanguageService(host);
|
|
640
678
|
const loadPlugins = async function() {
|
|
641
|
-
const civetFolder =
|
|
679
|
+
const civetFolder = path5.join(projectPath, "./.civet/");
|
|
642
680
|
let civetFiles;
|
|
643
681
|
try {
|
|
644
682
|
civetFiles = system.readDirectory(civetFolder);
|
|
@@ -675,7 +713,7 @@ function TSService(projectPath, options) {
|
|
|
675
713
|
});
|
|
676
714
|
}
|
|
677
715
|
function createBaseHost(options, system) {
|
|
678
|
-
if (system ===
|
|
716
|
+
if (system === ts7.sys) {
|
|
679
717
|
return createCompilerHost(options);
|
|
680
718
|
}
|
|
681
719
|
const getCanonicalFileName2 = (fileName) => {
|
|
@@ -689,10 +727,10 @@ function createBaseHost(options, system) {
|
|
|
689
727
|
if (!(sourceText != null)) {
|
|
690
728
|
return;
|
|
691
729
|
}
|
|
692
|
-
return
|
|
730
|
+
return ts7.createSourceFile(fileName, sourceText, languageVersion);
|
|
693
731
|
},
|
|
694
732
|
getDefaultLibFileName(options2) {
|
|
695
|
-
return
|
|
733
|
+
return path5.join("/typescript/lib", ts7.getDefaultLibFileName(options2));
|
|
696
734
|
},
|
|
697
735
|
writeFile(fileName, content) {
|
|
698
736
|
return system.writeFile?.(fileName, content);
|
|
@@ -700,8 +738,8 @@ function createBaseHost(options, system) {
|
|
|
700
738
|
getCurrentDirectory() {
|
|
701
739
|
return system.getCurrentDirectory();
|
|
702
740
|
},
|
|
703
|
-
getDirectories(
|
|
704
|
-
return system.getDirectories?.(
|
|
741
|
+
getDirectories(path8) {
|
|
742
|
+
return system.getDirectories?.(path8) ?? [];
|
|
705
743
|
},
|
|
706
744
|
fileExists(fileName) {
|
|
707
745
|
return system.fileExists(fileName);
|
|
@@ -716,14 +754,17 @@ function createBaseHost(options, system) {
|
|
|
716
754
|
getNewLine() {
|
|
717
755
|
return system.newLine;
|
|
718
756
|
},
|
|
719
|
-
directoryExists(
|
|
720
|
-
|
|
757
|
+
directoryExists(path8) {
|
|
758
|
+
if (!(system.directoryExists != null)) {
|
|
759
|
+
return false;
|
|
760
|
+
}
|
|
761
|
+
return system.directoryExists(path8);
|
|
721
762
|
},
|
|
722
|
-
readDirectory(
|
|
723
|
-
return system.readDirectory(
|
|
763
|
+
readDirectory(path8, extensions, excludes, includes, depth) {
|
|
764
|
+
return system.readDirectory(path8, extensions, excludes, includes, depth);
|
|
724
765
|
},
|
|
725
|
-
realpath(
|
|
726
|
-
return system.realpath ? system.realpath(
|
|
766
|
+
realpath(path8) {
|
|
767
|
+
return system.realpath ? system.realpath(path8) : path8;
|
|
727
768
|
}
|
|
728
769
|
};
|
|
729
770
|
}
|
|
@@ -769,7 +810,7 @@ import {} from "typescript";
|
|
|
769
810
|
// source/cache.civet
|
|
770
811
|
import * as crypto from "node:crypto";
|
|
771
812
|
import * as fs from "node:fs";
|
|
772
|
-
import * as
|
|
813
|
+
import * as path6 from "node:path";
|
|
773
814
|
function hashParts(parts) {
|
|
774
815
|
const hash = crypto.createHash("sha1");
|
|
775
816
|
for (const part of parts) {
|
|
@@ -793,7 +834,7 @@ function stableStringify(value) {
|
|
|
793
834
|
});
|
|
794
835
|
}
|
|
795
836
|
function makeCacheKey(input) {
|
|
796
|
-
const resolved =
|
|
837
|
+
const resolved = path6.resolve(input.sourcePath).replace(/\\/g, "/");
|
|
797
838
|
return hashParts([
|
|
798
839
|
input.source,
|
|
799
840
|
input.compilerName,
|
|
@@ -823,7 +864,7 @@ function createDiskCache(dir) {
|
|
|
823
864
|
}
|
|
824
865
|
return {
|
|
825
866
|
get(key) {
|
|
826
|
-
const target =
|
|
867
|
+
const target = path6.join(dir, key);
|
|
827
868
|
try {
|
|
828
869
|
const content = fs.readFileSync(target, "utf8");
|
|
829
870
|
try {
|
|
@@ -837,7 +878,7 @@ function createDiskCache(dir) {
|
|
|
837
878
|
}
|
|
838
879
|
},
|
|
839
880
|
set(key, value) {
|
|
840
|
-
const target =
|
|
881
|
+
const target = path6.join(dir, key);
|
|
841
882
|
try {
|
|
842
883
|
const tmp = `${target}.tmp.${process.pid}`;
|
|
843
884
|
fs.writeFileSync(tmp, value);
|
|
@@ -1063,19 +1104,18 @@ function makeHeraPlugin(options = {}) {
|
|
|
1063
1104
|
}
|
|
1064
1105
|
|
|
1065
1106
|
// source/ts-service/typecheck.civet
|
|
1066
|
-
import
|
|
1107
|
+
import ts8 from "typescript";
|
|
1067
1108
|
import * as fs2 from "fs";
|
|
1068
|
-
import * as
|
|
1109
|
+
import * as path7 from "path";
|
|
1069
1110
|
function makeIncrementalTypecheckProgram(projectPath, options) {
|
|
1070
1111
|
const transpilers = buildTranspilers(options.plugins);
|
|
1071
|
-
const extraExtensions = Array.from(transpilers.keys());
|
|
1072
1112
|
const parsed = parseTsConfigForCivet(projectPath, transpilers, { tsConfig: options.tsConfig });
|
|
1073
1113
|
const compilerOptions = {
|
|
1074
1114
|
...parsed.options,
|
|
1075
1115
|
...options.extraCompilerOptions
|
|
1076
1116
|
};
|
|
1077
|
-
compilerOptions.jsx ??=
|
|
1078
|
-
const baseHost =
|
|
1117
|
+
compilerOptions.jsx ??= ts8.JsxEmit.Preserve;
|
|
1118
|
+
const baseHost = ts8.createIncrementalCompilerHost(compilerOptions);
|
|
1079
1119
|
const fileMetaData = /* @__PURE__ */ new Map();
|
|
1080
1120
|
const hashText = (text) => {
|
|
1081
1121
|
return baseHost.createHash?.(text) ?? text.length.toString();
|
|
@@ -1119,7 +1159,7 @@ function makeIncrementalTypecheckProgram(projectPath, options) {
|
|
|
1119
1159
|
parseErrors: result.errors,
|
|
1120
1160
|
fatal: false
|
|
1121
1161
|
});
|
|
1122
|
-
const sf2 =
|
|
1162
|
+
const sf2 = ts8.createSourceFile(fileName, result.code, langVersion, true);
|
|
1123
1163
|
sf2.version = hashText(result.code);
|
|
1124
1164
|
return sf2;
|
|
1125
1165
|
}
|
|
@@ -1130,6 +1170,7 @@ function makeIncrementalTypecheckProgram(projectPath, options) {
|
|
|
1130
1170
|
return sf;
|
|
1131
1171
|
};
|
|
1132
1172
|
const origFileExists = baseHost.fileExists.bind(baseHost);
|
|
1173
|
+
const origDirectoryExists = baseHost.directoryExists?.bind(baseHost) ?? (() => false);
|
|
1133
1174
|
baseHost.fileExists = (fileName) => {
|
|
1134
1175
|
const exts = getTranspiledExtensionsFromPath(fileName);
|
|
1135
1176
|
if (exts) {
|
|
@@ -1143,43 +1184,56 @@ function makeIncrementalTypecheckProgram(projectPath, options) {
|
|
|
1143
1184
|
const origReadFile = baseHost.readFile.bind(baseHost);
|
|
1144
1185
|
baseHost.readFile = (fileName) => {
|
|
1145
1186
|
const contents = origReadFile(fileName);
|
|
1146
|
-
if (contents &&
|
|
1187
|
+
if (contents && path7.basename(fileName) === "package.json") {
|
|
1147
1188
|
return mogrifyPackageJsonImports(contents, transpilers);
|
|
1148
1189
|
}
|
|
1149
1190
|
return contents;
|
|
1150
1191
|
};
|
|
1151
|
-
baseHost.resolveModuleNameLiterals = (literals, containingFile,
|
|
1152
|
-
return literals.map((lit) => {
|
|
1192
|
+
baseHost.resolveModuleNameLiterals = (literals, containingFile, redirectedReference, opts, containingSourceFile) => {
|
|
1193
|
+
return literals.map((lit, index) => {
|
|
1153
1194
|
const name = lit.text;
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
-
|
|
1195
|
+
const resolutionMode = containingSourceFile && ts8.getModeForResolutionAtIndex(containingSourceFile, index, opts);
|
|
1196
|
+
return resolveTranspiledModuleName({
|
|
1197
|
+
name,
|
|
1198
|
+
containingFile,
|
|
1199
|
+
compilerOptions: opts,
|
|
1200
|
+
resolutionMode,
|
|
1201
|
+
transpilers,
|
|
1202
|
+
resolveTypeScript: () => {
|
|
1203
|
+
return ts8.resolveModuleName(name, containingFile, opts, baseHost, void 0, redirectedReference, resolutionMode);
|
|
1204
|
+
},
|
|
1205
|
+
fileExists: origFileExists,
|
|
1206
|
+
directoryExists: origDirectoryExists
|
|
1207
|
+
});
|
|
1208
|
+
});
|
|
1209
|
+
};
|
|
1210
|
+
baseHost.resolveModuleNames = (moduleNames, containingFile, _reusedNames, redirectedReference, opts, containingSourceFile) => {
|
|
1211
|
+
return moduleNames.map((name, index) => {
|
|
1212
|
+
const resolutionMode = containingSourceFile && ts8.getModeForResolutionAtIndex(containingSourceFile, index, opts);
|
|
1213
|
+
return resolveTranspiledModuleName({
|
|
1214
|
+
name,
|
|
1215
|
+
containingFile,
|
|
1216
|
+
compilerOptions: opts,
|
|
1217
|
+
resolutionMode,
|
|
1218
|
+
transpilers,
|
|
1219
|
+
resolveTypeScript: () => {
|
|
1220
|
+
return ts8.resolveModuleName(name, containingFile, opts, baseHost, void 0, redirectedReference, resolutionMode);
|
|
1221
|
+
},
|
|
1222
|
+
fileExists: origFileExists,
|
|
1223
|
+
directoryExists: origDirectoryExists
|
|
1224
|
+
}).resolvedModule;
|
|
1171
1225
|
});
|
|
1172
1226
|
};
|
|
1173
1227
|
const programOptions = {
|
|
1174
1228
|
rootNames: parsed.fileNames,
|
|
1175
1229
|
options: compilerOptions,
|
|
1176
1230
|
host: baseHost,
|
|
1177
|
-
configFileParsingDiagnostics:
|
|
1231
|
+
configFileParsingDiagnostics: ts8.getConfigFileParsingDiagnostics(parsed)
|
|
1178
1232
|
};
|
|
1179
1233
|
if (parsed.projectReferences) {
|
|
1180
1234
|
programOptions.projectReferences = parsed.projectReferences;
|
|
1181
1235
|
}
|
|
1182
|
-
const builder =
|
|
1236
|
+
const builder = ts8.createIncrementalProgram(programOptions);
|
|
1183
1237
|
return {
|
|
1184
1238
|
builder,
|
|
1185
1239
|
host: baseHost,
|