@danielx/civet 0.11.6 → 0.11.8

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.
@@ -41,178 +41,7 @@ var import_config = require("@danielx/civet/config");
41
41
  var import_ts_diagnostic = require("@danielx/civet/ts-diagnostic");
42
42
  var fs = __toESM(require("fs"));
43
43
  var import_path = __toESM(require("path"));
44
-
45
- // node_modules/.pnpm/@typescript+vfs@1.6.4_typescript@5.8.3/node_modules/@typescript/vfs/dist/vfs.esm.js
46
- function _extends() {
47
- return _extends = Object.assign ? Object.assign.bind() : function(n) {
48
- for (var e = 1; e < arguments.length; e++) {
49
- var t = arguments[e];
50
- for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]);
51
- }
52
- return n;
53
- }, _extends.apply(null, arguments);
54
- }
55
- var hasLocalStorage = false;
56
- try {
57
- hasLocalStorage = typeof localStorage !== "undefined";
58
- } catch (error) {
59
- }
60
- var hasProcess = typeof process !== "undefined";
61
- var shouldDebug = hasLocalStorage && typeof localStorage.getItem === "function" && /* @__PURE__ */ localStorage.getItem("DEBUG") || hasProcess && process.env.DEBUG;
62
- var debugLog = shouldDebug ? console.log : function(_message) {
63
- return "";
64
- };
65
- function notImplemented(methodName) {
66
- throw new Error("Method '" + methodName + "' is not implemented.");
67
- }
68
- function audit(name, fn) {
69
- return function() {
70
- for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
71
- args[_key] = arguments[_key];
72
- }
73
- var res = fn.apply(void 0, args);
74
- var smallres = typeof res === "string" ? res.slice(0, 80) + "..." : res;
75
- debugLog.apply(void 0, ["> " + name].concat(args));
76
- debugLog("< " + smallres);
77
- return res;
78
- };
79
- }
80
- var defaultCompilerOptions = function defaultCompilerOptions2(ts) {
81
- return _extends({}, ts.getDefaultCompilerOptions(), {
82
- jsx: ts.JsxEmit.React,
83
- strict: true,
84
- esModuleInterop: true,
85
- module: ts.ModuleKind.ESNext,
86
- suppressOutputPathCheck: true,
87
- skipLibCheck: true,
88
- skipDefaultLibCheck: true
89
- }, ts.versionMajorMinor && Number(ts.versionMajorMinor.split(".")[0]) >= 6 ? {
90
- ignoreDeprecations: "6.0"
91
- } : {
92
- moduleResolution: ts.ModuleResolutionKind.NodeJs
93
- });
94
- };
95
- function createFSBackedSystem(files, _projectRoot, ts, tsLibDirectory) {
96
- var root = _projectRoot + "/vfs";
97
- var path2 = requirePath();
98
- var nodeSys = ts.sys;
99
- var tsLib = tsLibDirectory != null ? tsLibDirectory : path2.dirname(require.resolve("typescript"));
100
- return {
101
- // @ts-ignore
102
- name: "fs-vfs",
103
- root,
104
- args: [],
105
- createDirectory: function createDirectory() {
106
- return notImplemented("createDirectory");
107
- },
108
- // TODO: could make a real file tree
109
- directoryExists: audit("directoryExists", function(directory) {
110
- return Array.from(files.keys()).some(function(path3) {
111
- return path3.startsWith(directory);
112
- }) || nodeSys.directoryExists(directory);
113
- }),
114
- exit: nodeSys.exit,
115
- fileExists: audit("fileExists", function(fileName) {
116
- if (files.has(fileName)) return true;
117
- if (fileName.includes("tsconfig.json") || fileName.includes("tsconfig.json")) return false;
118
- if (fileName.startsWith("/lib")) {
119
- var tsLibName = tsLib + "/" + fileName.replace("/", "");
120
- return nodeSys.fileExists(tsLibName);
121
- }
122
- return nodeSys.fileExists(fileName);
123
- }),
124
- getCurrentDirectory: function getCurrentDirectory() {
125
- return root;
126
- },
127
- getDirectories: nodeSys.getDirectories,
128
- getExecutingFilePath: function getExecutingFilePath() {
129
- return notImplemented("getExecutingFilePath");
130
- },
131
- readDirectory: audit("readDirectory", function() {
132
- if ((arguments.length <= 0 ? void 0 : arguments[0]) === "/") {
133
- return Array.from(files.keys());
134
- } else {
135
- return nodeSys.readDirectory.apply(nodeSys, arguments);
136
- }
137
- }),
138
- readFile: audit("readFile", function(fileName) {
139
- if (files.has(fileName)) return files.get(fileName);
140
- if (fileName.startsWith("/lib")) {
141
- var tsLibName = tsLib + "/" + fileName.replace("/", "");
142
- var result = nodeSys.readFile(tsLibName);
143
- if (!result) {
144
- var libs = nodeSys.readDirectory(tsLib);
145
- throw new Error("TSVFS: A request was made for " + tsLibName + " but there wasn't a file found in the file map. You likely have a mismatch in the compiler options for the CDN download vs the compiler program. Existing Libs: " + libs + ".");
146
- }
147
- return result;
148
- }
149
- return nodeSys.readFile(fileName);
150
- }),
151
- resolvePath: function resolvePath(path3) {
152
- if (files.has(path3)) return path3;
153
- return nodeSys.resolvePath(path3);
154
- },
155
- newLine: "\n",
156
- useCaseSensitiveFileNames: true,
157
- write: function write() {
158
- return notImplemented("write");
159
- },
160
- writeFile: function writeFile(fileName, contents) {
161
- files.set(fileName, contents);
162
- },
163
- deleteFile: function deleteFile(fileName) {
164
- files["delete"](fileName);
165
- },
166
- realpath: nodeSys.realpath
167
- };
168
- }
169
- function createVirtualCompilerHost(sys, compilerOptions, ts) {
170
- var sourceFiles = /* @__PURE__ */ new Map();
171
- var save = function save2(sourceFile) {
172
- sourceFiles.set(sourceFile.fileName, sourceFile);
173
- return sourceFile;
174
- };
175
- var vHost = {
176
- compilerHost: _extends({}, sys, {
177
- getCanonicalFileName: function getCanonicalFileName(fileName) {
178
- return fileName;
179
- },
180
- getDefaultLibFileName: function getDefaultLibFileName() {
181
- return "/" + ts.getDefaultLibFileName(compilerOptions);
182
- },
183
- // '/lib.d.ts',
184
- // getDefaultLibLocation: () => '/',
185
- getNewLine: function getNewLine() {
186
- return sys.newLine;
187
- },
188
- getSourceFile: function getSourceFile(fileName, languageVersionOrOptions) {
189
- var _ref;
190
- return sourceFiles.get(fileName) || save(ts.createSourceFile(fileName, sys.readFile(fileName), (_ref = languageVersionOrOptions != null ? languageVersionOrOptions : compilerOptions.target) != null ? _ref : defaultCompilerOptions(ts).target, false));
191
- },
192
- useCaseSensitiveFileNames: function useCaseSensitiveFileNames() {
193
- return sys.useCaseSensitiveFileNames;
194
- }
195
- }),
196
- updateFile: function updateFile(sourceFile) {
197
- var alreadyExists = sourceFiles.has(sourceFile.fileName);
198
- sys.writeFile(sourceFile.fileName, sourceFile.text);
199
- sourceFiles.set(sourceFile.fileName, sourceFile);
200
- return alreadyExists;
201
- },
202
- deleteFile: function deleteFile(sourceFile) {
203
- var alreadyExists = sourceFiles.has(sourceFile.fileName);
204
- sourceFiles["delete"](sourceFile.fileName);
205
- sys.deleteFile(sourceFile.fileName);
206
- return alreadyExists;
207
- }
208
- };
209
- return vHost;
210
- }
211
- var requirePath = function requirePath2() {
212
- return require(String.fromCharCode(112, 97, 116, 104));
213
- };
214
-
215
- // source/unplugin/unplugin.civet
44
+ var import_url = require("url");
216
45
  var import_os = __toESM(require("os"));
217
46
  var DEFAULT_EXTENSIONS = [".mjs", ".js", ".mts", ".ts", ".jsx", ".tsx", ".json"];
218
47
  var DiagnosticCategory = {};
@@ -306,8 +135,15 @@ var rawPlugin = (options = {}, meta) => {
306
135
  let outDir = import_path.default.join(rootDir, "dist");
307
136
  let esbuildOptions;
308
137
  let configErrors;
309
- let configFileNames;
138
+ let configFileNames = [];
139
+ const pluginResolvedIds = /* @__PURE__ */ new Set();
310
140
  let skipWorker = false;
141
+ let tsBuildInfoTarget;
142
+ let nextDocVersion = 0;
143
+ let tsService;
144
+ let docFactory;
145
+ let service = null;
146
+ let incrementalTypecheckSetup;
311
147
  let ref;
312
148
  if (transformTS || ts === "tsc") {
313
149
  ref = import("typescript").then(($1) => $1.default);
@@ -316,10 +152,19 @@ var rawPlugin = (options = {}, meta) => {
316
152
  }
317
153
  ;
318
154
  const tsPromise = ref;
155
+ let ref1;
156
+ if (transformTS) {
157
+ ref1 = import("@danielx/civet/ts-service");
158
+ } else {
159
+ ref1 = void 0;
160
+ }
161
+ ;
162
+ const tsServicePromise = ref1;
319
163
  const getFormatHost = (sys) => {
320
164
  return {
321
165
  getCurrentDirectory: () => sys.getCurrentDirectory(),
322
166
  getNewLine: () => sys.newLine,
167
+ /* c8 ignore next 3 -- platform-dependent: tests run where useCaseSensitiveFileNames=true */
323
168
  getCanonicalFileName: sys.useCaseSensitiveFileNames ? (f) => f : (f) => f.toLowerCase()
324
169
  };
325
170
  };
@@ -328,6 +173,7 @@ var rawPlugin = (options = {}, meta) => {
328
173
  name: "unplugin-civet",
329
174
  enforce: "pre",
330
175
  async buildStart() {
176
+ pluginResolvedIds.clear();
331
177
  let civetConfigPath = options.config;
332
178
  if (civetConfigPath === void 0) {
333
179
  civetConfigPath = await (0, import_config.findInDir)(process.cwd());
@@ -357,14 +203,27 @@ var rawPlugin = (options = {}, meta) => {
357
203
  };
358
204
  var mogrify = mogrify2;
359
205
  const ts2 = await tsPromise;
360
- const tsConfigPath = ts2.findConfigFile(process.cwd(), ts2.sys.fileExists);
361
- if (!tsConfigPath) {
362
- throw new Error("Could not find 'tsconfig.json'");
206
+ if (transformTS) {
207
+ tsService = await tsServicePromise;
208
+ docFactory ??= tsService.createInMemoryDocFactory();
209
+ }
210
+ let config, error, tsConfigPath;
211
+ if (options.tsConfig) {
212
+ config = options.tsConfig;
213
+ if (options.tsConfig.rootDir) {
214
+ tsConfigPath = import_path.default.join(options.tsConfig.rootDir, "tsconfig.json");
215
+ }
216
+ } else {
217
+ tsConfigPath = ts2.findConfigFile(process.cwd(), ts2.sys.fileExists);
218
+ if (!tsConfigPath) {
219
+ throw new Error("Could not find 'tsconfig.json'");
220
+ }
221
+ ;
222
+ ({ config, error } = ts2.readConfigFile(
223
+ tsConfigPath,
224
+ ts2.sys.readFile
225
+ ));
363
226
  }
364
- const { config, error } = ts2.readConfigFile(
365
- tsConfigPath,
366
- ts2.sys.readFile
367
- );
368
227
  if (error) {
369
228
  console.error(ts2.formatDiagnostic(error, getFormatHost(ts2.sys)));
370
229
  throw error;
@@ -379,7 +238,9 @@ var rawPlugin = (options = {}, meta) => {
379
238
  const configContents = ts2.parseJsonConfigFileContent(
380
239
  config,
381
240
  system,
382
- process.cwd()
241
+ tsConfigPath ? import_path.default.dirname(tsConfigPath) : process.cwd(),
242
+ void 0,
243
+ tsConfigPath
383
244
  );
384
245
  configErrors = configContents.errors;
385
246
  configFileNames = configContents.fileNames;
@@ -394,106 +255,223 @@ var rawPlugin = (options = {}, meta) => {
394
255
  sourceMap: true
395
256
  };
396
257
  fsMap = /* @__PURE__ */ new Map();
258
+ let ref2;
259
+ if (tsConfigPath) {
260
+ ref2 = import_path.default.dirname(tsConfigPath);
261
+ } else ref2 = process.cwd();
262
+ const servicePath = ref2;
263
+ let extraCompilerOptions;
264
+ if (options.tsBuildInfoFile) {
265
+ tsBuildInfoTarget = import_path.default.resolve(servicePath, options.tsBuildInfoFile);
266
+ extraCompilerOptions = {
267
+ incremental: true,
268
+ tsBuildInfoFile: tsBuildInfoTarget,
269
+ noEmit: false
270
+ };
271
+ }
272
+ if (transformTS && tsService && docFactory) {
273
+ const transpileCache = tsService.createDiskCache(import_path.default.resolve(servicePath, ".cache/build"));
274
+ const plugins = [
275
+ tsService.makeCivetPlugin({
276
+ Civet: import_civet.default,
277
+ config: compileOptions,
278
+ cache: transpileCache
279
+ }),
280
+ tsService.makeHeraPlugin({
281
+ Civet: import_civet.default,
282
+ config: compileOptions,
283
+ cache: transpileCache
284
+ })
285
+ ];
286
+ const useIncremental = options.typecheck && !options.emitDeclaration && (options.discoverProjectFiles ?? false);
287
+ if (useIncremental) {
288
+ incrementalTypecheckSetup = {
289
+ plugins,
290
+ tsConfig: config,
291
+ extraCompilerOptions,
292
+ projectPath: servicePath
293
+ };
294
+ } else {
295
+ service = tsService.TSService(servicePath, {
296
+ plugins,
297
+ docFactory,
298
+ discoverProjectFiles: options.discoverProjectFiles ?? false,
299
+ extraCompilerOptions,
300
+ // TSService's own configSys handles .civet + .hera mogrification;
301
+ // unplugin's local one only adds .civet.
302
+ tsConfig: config
303
+ });
304
+ }
305
+ }
397
306
  }
398
307
  },
308
+ // useConfigFileNames=true expands the typecheck scope to every path
309
+ // tsconfig matched (captured in buildStart's `configFileNames`); the
310
+ // false default keeps it scoped to load()-tracked files + their
311
+ // transitive imports.
399
312
  async buildEnd(useConfigFileNames = false) {
400
313
  if (transformTS) {
401
314
  const ts2 = await tsPromise;
402
- const system = createFSBackedSystem(fsMap, process.cwd(), ts2);
403
- const {
404
- fileExists: systemFileExists,
405
- readFile: systemReadFile,
406
- readDirectory: systemReadDirectory
407
- } = system;
408
- system.fileExists = (filename) => {
409
- if (!filename.endsWith(".civet.tsx")) return systemFileExists(filename);
410
- if (fsMap.has(filename)) return true;
411
- return systemFileExists(filename.slice(0, -4));
412
- };
413
- system.readDirectory = (path2) => {
414
- return systemReadDirectory(path2).map(($3) => $3.endsWith(".civet") ? $3 + ".tsx" : $3);
415
- };
416
- const tsCompileOptions = {
417
- ...compileOptions,
418
- rewriteCivetImports: false,
419
- rewriteTsImports: true
315
+ let rawDiagnostics;
316
+ let getMeta;
317
+ let emitTsBuildInfo;
318
+ emitTsBuildInfo = () => {
319
+ return;
420
320
  };
421
- system.readFile = (filename, encoding = "utf-8") => {
422
- if (import_path.default.basename(filename) === "package.json") {
423
- let recurse2 = function(node) {
424
- if (node != null && typeof node === "object") {
425
- for (const key in node) {
426
- const value = node[key];
427
- if (typeof value === "string") {
428
- if (value.endsWith(".civet")) {
429
- node[key] = value + ".tsx";
430
- modified = true;
431
- }
432
- } else if (value) {
433
- recurse2(value);
434
- }
435
- }
321
+ let program;
322
+ if (incrementalTypecheckSetup) {
323
+ if (!(tsService != null)) {
324
+ return;
325
+ }
326
+ const { builder, getMeta: gm, configErrors: cErrors } = tsService.makeIncrementalTypecheckProgram(
327
+ incrementalTypecheckSetup.projectPath,
328
+ incrementalTypecheckSetup
329
+ );
330
+ getMeta = gm;
331
+ while (true) {
332
+ const r = builder.getSemanticDiagnosticsOfNextAffectedFile();
333
+ if (!r) {
334
+ break;
335
+ }
336
+ }
337
+ program = builder.getProgram();
338
+ const collected = [];
339
+ collected.push(...builder.getOptionsDiagnostics());
340
+ collected.push(...builder.getGlobalDiagnostics());
341
+ for (const f of program.getSourceFiles()) {
342
+ collected.push(...builder.getSyntacticDiagnostics(f));
343
+ collected.push(...builder.getSemanticDiagnostics(f));
344
+ collected.push(...builder.getDeclarationDiagnostics(f));
345
+ }
346
+ rawDiagnostics = ts2.sortAndDeduplicateDiagnostics(collected);
347
+ if (cErrors && cErrors.length > 0) {
348
+ configErrors = [...cErrors];
349
+ }
350
+ if (tsBuildInfoTarget) {
351
+ const target = tsBuildInfoTarget;
352
+ const writeFile = (fileName, data) => {
353
+ if (fileName === target) {
354
+ return ts2.sys.writeFile(fileName, data);
436
355
  }
356
+ ;
357
+ return;
437
358
  };
438
- var recurse = recurse2;
439
- const json = systemReadFile(filename, encoding);
440
- if (!json) {
441
- return json;
359
+ emitTsBuildInfo = () => {
360
+ return builder.emit(void 0, writeFile, void 0, false);
361
+ };
362
+ }
363
+ } else {
364
+ if (!(service != null)) {
365
+ return;
366
+ }
367
+ for (const tsxPath of fsMap.keys()) {
368
+ if (!tsxPath.endsWith(".civet.tsx")) {
369
+ continue;
442
370
  }
443
- const parsed = JSON.parse(json);
444
- let modified = false;
445
- recurse2(parsed.imports);
446
- return modified ? JSON.stringify(parsed) : json;
371
+ const civetPath = tsxPath.slice(0, -4);
372
+ service.host.getMeta(civetPath);
373
+ }
374
+ if (useConfigFileNames) {
375
+ for (const fn of configFileNames) {
376
+ service.host.addScriptFileName(fn);
377
+ }
378
+ }
379
+ program = service.getProgram();
380
+ let builder;
381
+ if (options.tsBuildInfoFile) {
382
+ const builderHost = {};
383
+ const readHost = {
384
+ useCaseSensitiveFileNames: () => ts2.sys.useCaseSensitiveFileNames,
385
+ getCurrentDirectory: () => ts2.sys.getCurrentDirectory(),
386
+ readFile: (fileName) => ts2.sys.readFile(fileName)
387
+ };
388
+ const oldProgram = ts2.readBuilderProgram(program.getCompilerOptions(), readHost);
389
+ builder = ts2.createSemanticDiagnosticsBuilderProgram(program, builderHost, oldProgram);
390
+ }
391
+ rawDiagnostics = ts2.getPreEmitDiagnostics(builder ?? program);
392
+ getMeta = (p) => service.host.getMeta(p);
393
+ if (builder && tsBuildInfoTarget) {
394
+ const target = tsBuildInfoTarget;
395
+ const writeFile = (fileName, data) => {
396
+ if (fileName === target) {
397
+ return ts2.sys.writeFile(fileName, data);
398
+ }
399
+ ;
400
+ return;
401
+ };
402
+ emitTsBuildInfo = () => {
403
+ return builder.emit(void 0, writeFile, void 0, false);
404
+ };
405
+ }
406
+ }
407
+ const realFileCache = /* @__PURE__ */ new Map();
408
+ const realSourceFile = (realPath) => {
409
+ const cached = realFileCache.get(realPath);
410
+ if (cached) {
411
+ return cached;
412
+ }
413
+ try {
414
+ const src = fs.readFileSync(realPath, "utf8");
415
+ const sf = ts2.createSourceFile(realPath, src, ts2.ScriptTarget.ESNext, true);
416
+ realFileCache.set(realPath, sf);
417
+ return sf;
418
+ } catch {
419
+ return void 0;
447
420
  }
448
- if (!filename.endsWith(".civet.tsx")) return systemReadFile(filename, encoding);
449
- if (fsMap.has(filename)) return fsMap.get(filename);
450
- const civetFilename = filename.slice(0, -4);
451
- const rawCivetSource = fs.readFileSync(civetFilename, { encoding });
452
- const { code: compiledTS, sourceMap } = import_civet.default.compile(rawCivetSource, {
453
- ...tsCompileOptions,
454
- filename,
455
- js: false,
456
- sourceMap: true,
457
- sync: true
458
- // TS readFile API seems to need to be synchronous
459
- });
460
- fsMap.set(filename, compiledTS);
461
- sourceMaps.set(filename, sourceMap);
462
- return compiledTS;
463
421
  };
464
- const host = createVirtualCompilerHost(
465
- system,
466
- compilerOptions,
467
- ts2
468
- );
469
- const program = ts2.createProgram({
470
- rootNames: useConfigFileNames ? configFileNames : [...fsMap.keys()],
471
- options: compilerOptions,
472
- host: host.compilerHost
473
- });
474
- const diagnostics = ts2.getPreEmitDiagnostics(program).map((diagnostic) => {
475
- const file = diagnostic.file;
476
- if (!file) return diagnostic;
477
- const sourceMap = sourceMaps.get(file.fileName);
478
- if (!sourceMap) return diagnostic;
479
- const sourcemapLines = sourceMap.lines ?? sourceMap.data.lines;
480
- const range = (0, import_ts_diagnostic.remapRange)(
481
- {
482
- start: diagnostic.start || 0,
483
- end: (diagnostic.start || 0) + (diagnostic.length || 1)
484
- },
485
- sourcemapLines
486
- );
487
- return {
488
- ...diagnostic,
489
- messageText: (0, import_ts_diagnostic.flattenDiagnosticMessageText)(diagnostic.messageText),
490
- length: diagnostic.length,
491
- start: range.start
422
+ const diagnostics = [];
423
+ for (const d of rawDiagnostics) {
424
+ const file = d.file;
425
+ if (!file) {
426
+ diagnostics.push(d);
427
+ continue;
428
+ }
429
+ const isHera = file.fileName.endsWith(".hera.tsx");
430
+ const isTranspiled = file.fileName.endsWith(".civet.tsx") || isHera;
431
+ const sourcePath = isTranspiled ? file.fileName.slice(0, -4) : file.fileName;
432
+ const meta2 = getMeta(sourcePath);
433
+ const sourcemapLines = meta2?.sourcemapLines;
434
+ if (!sourcemapLines) {
435
+ diagnostics.push(d);
436
+ continue;
437
+ }
438
+ const startLc = file.getLineAndCharacterOfPosition(d.start || 0);
439
+ const endLc = file.getLineAndCharacterOfPosition((d.start || 0) + (d.length || 1));
440
+ const remappedStartLc = (0, import_ts_diagnostic.remapPosition)(startLc, sourcemapLines);
441
+ const remappedEndLc = (0, import_ts_diagnostic.remapPosition)(endLc, sourcemapLines);
442
+ const realFile = realSourceFile(sourcePath);
443
+ if (!realFile) {
444
+ diagnostics.push({
445
+ ...d,
446
+ messageText: (0, import_ts_diagnostic.flattenDiagnosticMessageText)(d.messageText)
447
+ });
448
+ continue;
449
+ }
450
+ const toPos = (lc) => {
451
+ try {
452
+ return realFile.getPositionOfLineAndCharacter(lc.line, lc.character);
453
+ } catch {
454
+ return void 0;
455
+ }
492
456
  };
493
- });
457
+ const remappedStart = toPos(remappedStartLc);
458
+ if (remappedStart === void 0) {
459
+ diagnostics.push(d);
460
+ continue;
461
+ }
462
+ const remappedEnd = toPos(remappedEndLc) ?? remappedStart + 1;
463
+ diagnostics.push({
464
+ ...d,
465
+ file: realFile,
466
+ start: remappedStart,
467
+ length: Math.max(1, remappedEnd - remappedStart),
468
+ messageText: (0, import_ts_diagnostic.flattenDiagnosticMessageText)(d.messageText)
469
+ });
470
+ }
494
471
  if (configErrors?.length) {
495
472
  diagnostics.unshift(...configErrors);
496
473
  }
474
+ emitTsBuildInfo();
497
475
  if (diagnostics.length > 0) {
498
476
  console.error(
499
477
  ts2.formatDiagnosticsWithColorAndContext(
@@ -515,9 +493,17 @@ var rawPlugin = (options = {}, meta) => {
515
493
  failures.push(DiagnosticCategory.Error);
516
494
  }
517
495
  const count = diagnostics.filter((d) => failures.includes(d.category)).length;
518
- if (count) {
496
+ const threshold = options.maxErrors ?? 0;
497
+ if (count > threshold) {
519
498
  const reason = count === diagnostics.length ? count : `${count} out of ${diagnostics.length}`;
520
- throw new Error(`Aborting build because of ${reason} TypeScript diagnostic${diagnostics.length > 1 ? "s" : ""} above`);
499
+ let ref3;
500
+ if (threshold > 0) {
501
+ ref3 = ` (baseline ${threshold})`;
502
+ } else ref3 = "";
503
+ const note = ref3;
504
+ throw new Error(`Aborting build because of ${reason} TypeScript diagnostic${diagnostics.length > 1 ? "s" : ""} above${note}`);
505
+ } else if (threshold > 0 && count > 0) {
506
+ console.error(`Within baseline of ${threshold} TypeScript diagnostic${threshold > 1 ? "s" : ""}; not failing.`);
521
507
  }
522
508
  }
523
509
  }
@@ -577,14 +563,14 @@ var rawPlugin = (options = {}, meta) => {
577
563
  }
578
564
  if (/\0/.test(id)) return null;
579
565
  const { filename, postfix } = extractCivetFilename(id, outExt);
580
- let ref1;
566
+ let ref4;
581
567
  if (import_path.default.isAbsolute(filename)) {
582
- ref1 = resolveAbsolutePath(rootDir, filename, implicitExtension);
568
+ ref4 = resolveAbsolutePath(rootDir, filename, implicitExtension);
583
569
  } else {
584
- ref1 = import_path.default.resolve(import_path.default.dirname(importer ?? ""), filename);
570
+ ref4 = import_path.default.resolve(import_path.default.dirname(importer ?? ""), filename);
585
571
  }
586
572
  ;
587
- let resolved = ref1;
573
+ let resolved = ref4;
588
574
  if (!resolved) return null;
589
575
  if (!resolved.endsWith(civetSuffix)) {
590
576
  if (!implicitExtension) return null;
@@ -592,6 +578,7 @@ var rawPlugin = (options = {}, meta) => {
592
578
  if (!implicitId) return null;
593
579
  resolved = implicitId;
594
580
  }
581
+ pluginResolvedIds.add(resolved);
595
582
  if (options2.scan && meta.framework === "vite") {
596
583
  resolved = `\0${resolved}`;
597
584
  }
@@ -620,9 +607,9 @@ var rawPlugin = (options = {}, meta) => {
620
607
  if (cached.promise) {
621
608
  await cached.promise;
622
609
  }
623
- let ref2;
624
- if ((ref2 = cached.result) != null) {
625
- const result = ref2;
610
+ let ref5;
611
+ if ((ref5 = cached.result) != null) {
612
+ const result = ref5;
626
613
  return result;
627
614
  }
628
615
  }
@@ -653,9 +640,17 @@ var rawPlugin = (options = {}, meta) => {
653
640
  ...civetOptions,
654
641
  ast: true
655
642
  });
643
+ let ref6;
644
+ if (meta.framework === "esbuild" && pluginResolvedIds.has(filename)) {
645
+ ref6 = import_path.default.relative(outDir, filename);
646
+ } else {
647
+ ref6 = import_path.default.basename(filename);
648
+ }
649
+ ;
650
+ const sourceMapSource = ref6;
656
651
  const civetSourceMap = new import_civet.SourceMap(
657
652
  rawCivetSource,
658
- normalizePath(import_path.default.relative(outDir, filename))
653
+ normalizePath(sourceMapSource)
659
654
  );
660
655
  if (ts === "civet") {
661
656
  compiled = await import_civet.default.generate(ast, {
@@ -702,8 +697,8 @@ var rawPlugin = (options = {}, meta) => {
702
697
  }
703
698
  }
704
699
  if (transformTS) {
705
- for (let ref3 = import_civet.lib.gatherRecursive(ast, (($) => $.type === "ModuleSpecifier")), i = 0, len = ref3.length; i < len; i++) {
706
- const _spec = ref3[i];
700
+ for (let ref7 = import_civet.lib.gatherRecursive(ast, (($) => $.type === "ModuleSpecifier")), i = 0, len = ref7.length; i < len; i++) {
701
+ const _spec = ref7[i];
707
702
  const spec = _spec;
708
703
  if (spec.module?.input) {
709
704
  spec.module.token = spec.module.input.replace(/\.([mc])?ts(['"])$/, ".$1js$2");
@@ -723,6 +718,15 @@ var rawPlugin = (options = {}, meta) => {
723
718
  fsMap.set(slashed, compiledTS);
724
719
  sourceMaps.set(slashed, civetSourceMap);
725
720
  }
721
+ if (service != null && docFactory != null) {
722
+ const doc = docFactory.create(
723
+ (0, import_url.pathToFileURL)(filename).toString(),
724
+ "civet",
725
+ ++nextDocVersion,
726
+ rawCivetSource
727
+ );
728
+ service.host.addOrUpdateDocument(doc);
729
+ }
726
730
  }
727
731
  const jsonSourceMap = sourceMap && (typeof sourceMap === "string" ? JSON.parse(sourceMap) : sourceMap.json(normalizePath(import_path.default.relative(outDir, id))));
728
732
  let transformed = {
@@ -763,7 +767,7 @@ var rawPlugin = (options = {}, meta) => {
763
767
  config.resolve.extensions.push(".civet");
764
768
  }
765
769
  },
766
- async transformIndexHtml(html) {
770
+ transformIndexHtml(html) {
767
771
  return html.replace(/<!--[^]*?-->|<[^<>]*>/g, (tag) => {
768
772
  return tag.replace(/<\s*script\b[^<>]*>/gi, (script) => {
769
773
  return script.replace(
@@ -785,9 +789,9 @@ var rawPlugin = (options = {}, meta) => {
785
789
  return;
786
790
  }
787
791
  const resolvedId = slash(import_path.default.resolve(file) + outExt);
788
- let ref4;
789
- if (ref4 = server.moduleGraph.getModulesByFile(resolvedId)) {
790
- const fileModules = ref4;
792
+ let ref8;
793
+ if (ref8 = server.moduleGraph.getModulesByFile(resolvedId)) {
794
+ const fileModules = ref8;
791
795
  server.moduleGraph.onFileChange(resolvedId);
792
796
  return [...modules, ...fileModules];
793
797
  }
@@ -811,9 +815,9 @@ var rawPlugin = (options = {}, meta) => {
811
815
  compiler.options.resolve.extensions.unshift(".civet");
812
816
  }
813
817
  return aliasResolver = (id) => {
814
- let ref5;
815
- for (const key in ref5 = compiler.options.resolve.alias) {
816
- const value = ref5[key];
818
+ let ref9;
819
+ for (const key in ref9 = compiler.options.resolve.alias) {
820
+ const value = ref9[key];
817
821
  if (key.endsWith("$")) {
818
822
  if (id === key.slice(0, -1)) {
819
823
  return typeof value === "string" ? value : "\0";