@danielx/civet 0.11.7 → 0.11.9

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,6 +203,10 @@ var rawPlugin = (options = {}, meta) => {
357
203
  };
358
204
  var mogrify = mogrify2;
359
205
  const ts2 = await tsPromise;
206
+ if (transformTS) {
207
+ tsService = await tsServicePromise;
208
+ docFactory ??= tsService.createInMemoryDocFactory();
209
+ }
360
210
  let config, error, tsConfigPath;
361
211
  if (options.tsConfig) {
362
212
  config = options.tsConfig;
@@ -405,106 +255,223 @@ var rawPlugin = (options = {}, meta) => {
405
255
  sourceMap: true
406
256
  };
407
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
+ }
408
306
  }
409
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.
410
312
  async buildEnd(useConfigFileNames = false) {
411
313
  if (transformTS) {
412
314
  const ts2 = await tsPromise;
413
- const system = createFSBackedSystem(fsMap, process.cwd(), ts2);
414
- const {
415
- fileExists: systemFileExists,
416
- readFile: systemReadFile,
417
- readDirectory: systemReadDirectory
418
- } = system;
419
- system.fileExists = (filename) => {
420
- if (!filename.endsWith(".civet.tsx")) return systemFileExists(filename);
421
- if (fsMap.has(filename)) return true;
422
- return systemFileExists(filename.slice(0, -4));
423
- };
424
- system.readDirectory = (path2) => {
425
- return systemReadDirectory(path2).map(($3) => $3.endsWith(".civet") ? $3 + ".tsx" : $3);
426
- };
427
- const tsCompileOptions = {
428
- ...compileOptions,
429
- rewriteCivetImports: false,
430
- rewriteTsImports: true
315
+ let rawDiagnostics;
316
+ let getMeta;
317
+ let emitTsBuildInfo;
318
+ emitTsBuildInfo = () => {
319
+ return;
431
320
  };
432
- system.readFile = (filename, encoding = "utf-8") => {
433
- if (import_path.default.basename(filename) === "package.json") {
434
- let recurse2 = function(node) {
435
- if (node != null && typeof node === "object") {
436
- for (const key in node) {
437
- const value = node[key];
438
- if (typeof value === "string") {
439
- if (value.endsWith(".civet")) {
440
- node[key] = value + ".tsx";
441
- modified = true;
442
- }
443
- } else if (value) {
444
- recurse2(value);
445
- }
446
- }
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);
447
355
  }
356
+ ;
357
+ return;
358
+ };
359
+ emitTsBuildInfo = () => {
360
+ return builder.emit(void 0, writeFile, void 0, false);
448
361
  };
449
- var recurse = recurse2;
450
- const json = systemReadFile(filename, encoding);
451
- if (!json) {
452
- return json;
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;
453
370
  }
454
- const parsed = JSON.parse(json);
455
- let modified = false;
456
- recurse2(parsed.imports);
457
- 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;
458
420
  }
459
- if (!filename.endsWith(".civet.tsx")) return systemReadFile(filename, encoding);
460
- if (fsMap.has(filename)) return fsMap.get(filename);
461
- const civetFilename = filename.slice(0, -4);
462
- const rawCivetSource = fs.readFileSync(civetFilename, { encoding });
463
- const { code: compiledTS, sourceMap } = import_civet.default.compile(rawCivetSource, {
464
- ...tsCompileOptions,
465
- filename,
466
- js: false,
467
- sourceMap: true,
468
- sync: true
469
- // TS readFile API seems to need to be synchronous
470
- });
471
- fsMap.set(filename, compiledTS);
472
- sourceMaps.set(filename, sourceMap);
473
- return compiledTS;
474
421
  };
475
- const host = createVirtualCompilerHost(
476
- system,
477
- compilerOptions,
478
- ts2
479
- );
480
- const program = ts2.createProgram({
481
- rootNames: useConfigFileNames ? configFileNames : [...fsMap.keys()],
482
- options: compilerOptions,
483
- host: host.compilerHost
484
- });
485
- const diagnostics = ts2.getPreEmitDiagnostics(program).map((diagnostic) => {
486
- const file = diagnostic.file;
487
- if (!file) return diagnostic;
488
- const sourceMap = sourceMaps.get(file.fileName);
489
- if (!sourceMap) return diagnostic;
490
- const sourcemapLines = sourceMap.lines ?? sourceMap.data.lines;
491
- const range = (0, import_ts_diagnostic.remapRange)(
492
- {
493
- start: diagnostic.start || 0,
494
- end: (diagnostic.start || 0) + (diagnostic.length || 1)
495
- },
496
- sourcemapLines
497
- );
498
- return {
499
- ...diagnostic,
500
- messageText: (0, import_ts_diagnostic.flattenDiagnosticMessageText)(diagnostic.messageText),
501
- length: diagnostic.length,
502
- 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
+ }
503
456
  };
504
- });
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
+ }
505
471
  if (configErrors?.length) {
506
472
  diagnostics.unshift(...configErrors);
507
473
  }
474
+ emitTsBuildInfo();
508
475
  if (diagnostics.length > 0) {
509
476
  console.error(
510
477
  ts2.formatDiagnosticsWithColorAndContext(
@@ -526,9 +493,17 @@ var rawPlugin = (options = {}, meta) => {
526
493
  failures.push(DiagnosticCategory.Error);
527
494
  }
528
495
  const count = diagnostics.filter((d) => failures.includes(d.category)).length;
529
- if (count) {
496
+ const threshold = options.maxErrors ?? 0;
497
+ if (count > threshold) {
530
498
  const reason = count === diagnostics.length ? count : `${count} out of ${diagnostics.length}`;
531
- 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.`);
532
507
  }
533
508
  }
534
509
  }
@@ -588,14 +563,14 @@ var rawPlugin = (options = {}, meta) => {
588
563
  }
589
564
  if (/\0/.test(id)) return null;
590
565
  const { filename, postfix } = extractCivetFilename(id, outExt);
591
- let ref1;
566
+ let ref4;
592
567
  if (import_path.default.isAbsolute(filename)) {
593
- ref1 = resolveAbsolutePath(rootDir, filename, implicitExtension);
568
+ ref4 = resolveAbsolutePath(rootDir, filename, implicitExtension);
594
569
  } else {
595
- ref1 = import_path.default.resolve(import_path.default.dirname(importer ?? ""), filename);
570
+ ref4 = import_path.default.resolve(import_path.default.dirname(importer ?? ""), filename);
596
571
  }
597
572
  ;
598
- let resolved = ref1;
573
+ let resolved = ref4;
599
574
  if (!resolved) return null;
600
575
  if (!resolved.endsWith(civetSuffix)) {
601
576
  if (!implicitExtension) return null;
@@ -603,6 +578,7 @@ var rawPlugin = (options = {}, meta) => {
603
578
  if (!implicitId) return null;
604
579
  resolved = implicitId;
605
580
  }
581
+ pluginResolvedIds.add(resolved);
606
582
  if (options2.scan && meta.framework === "vite") {
607
583
  resolved = `\0${resolved}`;
608
584
  }
@@ -631,9 +607,9 @@ var rawPlugin = (options = {}, meta) => {
631
607
  if (cached.promise) {
632
608
  await cached.promise;
633
609
  }
634
- let ref2;
635
- if ((ref2 = cached.result) != null) {
636
- const result = ref2;
610
+ let ref5;
611
+ if ((ref5 = cached.result) != null) {
612
+ const result = ref5;
637
613
  return result;
638
614
  }
639
615
  }
@@ -664,9 +640,17 @@ var rawPlugin = (options = {}, meta) => {
664
640
  ...civetOptions,
665
641
  ast: true
666
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;
667
651
  const civetSourceMap = new import_civet.SourceMap(
668
652
  rawCivetSource,
669
- normalizePath(import_path.default.relative(outDir, filename))
653
+ normalizePath(sourceMapSource)
670
654
  );
671
655
  if (ts === "civet") {
672
656
  compiled = await import_civet.default.generate(ast, {
@@ -713,8 +697,8 @@ var rawPlugin = (options = {}, meta) => {
713
697
  }
714
698
  }
715
699
  if (transformTS) {
716
- for (let ref3 = import_civet.lib.gatherRecursive(ast, (($) => $.type === "ModuleSpecifier")), i = 0, len = ref3.length; i < len; i++) {
717
- 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];
718
702
  const spec = _spec;
719
703
  if (spec.module?.input) {
720
704
  spec.module.token = spec.module.input.replace(/\.([mc])?ts(['"])$/, ".$1js$2");
@@ -734,6 +718,15 @@ var rawPlugin = (options = {}, meta) => {
734
718
  fsMap.set(slashed, compiledTS);
735
719
  sourceMaps.set(slashed, civetSourceMap);
736
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
+ }
737
730
  }
738
731
  const jsonSourceMap = sourceMap && (typeof sourceMap === "string" ? JSON.parse(sourceMap) : sourceMap.json(normalizePath(import_path.default.relative(outDir, id))));
739
732
  let transformed = {
@@ -796,9 +789,9 @@ var rawPlugin = (options = {}, meta) => {
796
789
  return;
797
790
  }
798
791
  const resolvedId = slash(import_path.default.resolve(file) + outExt);
799
- let ref4;
800
- if (ref4 = server.moduleGraph.getModulesByFile(resolvedId)) {
801
- const fileModules = ref4;
792
+ let ref8;
793
+ if (ref8 = server.moduleGraph.getModulesByFile(resolvedId)) {
794
+ const fileModules = ref8;
802
795
  server.moduleGraph.onFileChange(resolvedId);
803
796
  return [...modules, ...fileModules];
804
797
  }
@@ -822,9 +815,9 @@ var rawPlugin = (options = {}, meta) => {
822
815
  compiler.options.resolve.extensions.unshift(".civet");
823
816
  }
824
817
  return aliasResolver = (id) => {
825
- let ref5;
826
- for (const key in ref5 = compiler.options.resolve.alias) {
827
- const value = ref5[key];
818
+ let ref9;
819
+ for (const key in ref9 = compiler.options.resolve.alias) {
820
+ const value = ref9[key];
828
821
  if (key.endsWith("$")) {
829
822
  if (id === key.slice(0, -1)) {
830
823
  return typeof value === "string" ? value : "\0";