@danielx/civet 0.6.56 → 0.6.57

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/dist/esbuild.js CHANGED
@@ -42,7 +42,6 @@ var fs = __toESM(require("fs"));
42
42
  var import_path = __toESM(require("path"));
43
43
  var tsvfs = __toESM(require("@typescript/vfs"));
44
44
  var import_os = __toESM(require("os"));
45
- var isCivet = (id) => /\.civet([?#].*)?$/.test(id);
46
45
  var isCivetTranspiled = (id) => /\.civet\.[jt]sx([?#].*)?$/.test(id);
47
46
  var postfixRE = /[?#].*$/s;
48
47
  var isWindows = import_os.default.platform() === "win32";
@@ -69,11 +68,17 @@ function tryFsResolve(file) {
69
68
  return normalizePath(file);
70
69
  return void 0;
71
70
  }
72
- function resolveAbsolutePath(rootDir, id) {
73
- const resolved = tryFsResolve(import_path.default.join(rootDir, id));
74
- if (!resolved)
75
- return tryFsResolve(id);
76
- return resolved;
71
+ function resolveAbsolutePath(rootDir, id, implicitExtension) {
72
+ const file = import_path.default.join(rootDir, id);
73
+ return tryFsResolve(file) || implicitExtension && implicitCivet(file) || tryFsResolve(id) || implicitExtension && implicitCivet(id);
74
+ }
75
+ function implicitCivet(file) {
76
+ if (tryFsResolve(file))
77
+ return;
78
+ const civet2 = file + ".civet";
79
+ if (tryFsResolve(civet2))
80
+ return civet2;
81
+ return;
77
82
  }
78
83
  var civetUnplugin = (0, import_unplugin.createUnplugin)((options = {}) => {
79
84
  if (options.dts)
@@ -82,6 +87,7 @@ var civetUnplugin = (0, import_unplugin.createUnplugin)((options = {}) => {
82
87
  options.ts = "civet";
83
88
  const transformTS = options.emitDeclaration || options.typecheck;
84
89
  const outExt = options.outputExtension ?? (options.ts === "preserve" ? ".tsx" : ".jsx");
90
+ const implicitExtension = options.implicitExtension ?? true;
85
91
  let fsMap = /* @__PURE__ */ new Map();
86
92
  const sourceMaps = /* @__PURE__ */ new Map();
87
93
  let compilerOptions;
@@ -196,13 +202,19 @@ var civetUnplugin = (0, import_unplugin.createUnplugin)((options = {}) => {
196
202
  resolveId(id, importer) {
197
203
  if (/\0/.test(id))
198
204
  return null;
199
- if (!isCivet(id) && !isCivetTranspiled(id))
200
- return null;
201
205
  id = cleanCivetId(id);
202
- const absolutePath = import_path.default.isAbsolute(id) ? resolveAbsolutePath(rootDir, id) : import_path.default.resolve(import_path.default.dirname(importer ?? ""), id);
206
+ const absolutePath = import_path.default.isAbsolute(id) ? resolveAbsolutePath(rootDir, id, implicitExtension) : import_path.default.resolve(import_path.default.dirname(importer ?? ""), id);
203
207
  if (!absolutePath)
204
208
  return null;
205
- const relativeId = import_path.default.relative(process.cwd(), absolutePath);
209
+ let relativeId = import_path.default.relative(process.cwd(), absolutePath);
210
+ if (!relativeId.endsWith(".civet")) {
211
+ if (!implicitExtension)
212
+ return null;
213
+ const implicitId = implicitCivet(relativeId);
214
+ if (!implicitId)
215
+ return null;
216
+ relativeId = implicitId;
217
+ }
206
218
  const relativePath = relativeId + outExt;
207
219
  return relativePath;
208
220
  },
@@ -294,7 +306,13 @@ var civetUnplugin = (0, import_unplugin.createUnplugin)((options = {}) => {
294
306
  },
295
307
  vite: {
296
308
  config(config) {
309
+ var _a;
297
310
  rootDir = import_path.default.resolve(process.cwd(), config.root ?? "");
311
+ if (implicitExtension) {
312
+ config.resolve ?? (config.resolve = {});
313
+ (_a = config.resolve).extensions ?? (_a.extensions = []);
314
+ config.resolve.extensions.push(".civet");
315
+ }
298
316
  },
299
317
  async transformIndexHtml(html) {
300
318
  return html.replace(
@@ -313,6 +331,17 @@ var civetUnplugin = (0, import_unplugin.createUnplugin)((options = {}) => {
313
331
  )
314
332
  )
315
333
  );
334
+ },
335
+ handleHotUpdate({ file, server, modules }) {
336
+ if (!file.endsWith(".civet"))
337
+ return;
338
+ const relativeId = slash(import_path.default.relative(process.cwd(), file) + outExt);
339
+ const module2 = server.moduleGraph.getModuleById(relativeId);
340
+ if (module2) {
341
+ server.moduleGraph.onFileChange(relativeId);
342
+ return [...modules, module2];
343
+ }
344
+ return modules;
316
345
  }
317
346
  }
318
347
  };
package/dist/rollup.js CHANGED
@@ -42,7 +42,6 @@ var fs = __toESM(require("fs"));
42
42
  var import_path = __toESM(require("path"));
43
43
  var tsvfs = __toESM(require("@typescript/vfs"));
44
44
  var import_os = __toESM(require("os"));
45
- var isCivet = (id) => /\.civet([?#].*)?$/.test(id);
46
45
  var isCivetTranspiled = (id) => /\.civet\.[jt]sx([?#].*)?$/.test(id);
47
46
  var postfixRE = /[?#].*$/s;
48
47
  var isWindows = import_os.default.platform() === "win32";
@@ -69,11 +68,17 @@ function tryFsResolve(file) {
69
68
  return normalizePath(file);
70
69
  return void 0;
71
70
  }
72
- function resolveAbsolutePath(rootDir, id) {
73
- const resolved = tryFsResolve(import_path.default.join(rootDir, id));
74
- if (!resolved)
75
- return tryFsResolve(id);
76
- return resolved;
71
+ function resolveAbsolutePath(rootDir, id, implicitExtension) {
72
+ const file = import_path.default.join(rootDir, id);
73
+ return tryFsResolve(file) || implicitExtension && implicitCivet(file) || tryFsResolve(id) || implicitExtension && implicitCivet(id);
74
+ }
75
+ function implicitCivet(file) {
76
+ if (tryFsResolve(file))
77
+ return;
78
+ const civet2 = file + ".civet";
79
+ if (tryFsResolve(civet2))
80
+ return civet2;
81
+ return;
77
82
  }
78
83
  var civetUnplugin = (0, import_unplugin.createUnplugin)((options = {}) => {
79
84
  if (options.dts)
@@ -82,6 +87,7 @@ var civetUnplugin = (0, import_unplugin.createUnplugin)((options = {}) => {
82
87
  options.ts = "civet";
83
88
  const transformTS = options.emitDeclaration || options.typecheck;
84
89
  const outExt = options.outputExtension ?? (options.ts === "preserve" ? ".tsx" : ".jsx");
90
+ const implicitExtension = options.implicitExtension ?? true;
85
91
  let fsMap = /* @__PURE__ */ new Map();
86
92
  const sourceMaps = /* @__PURE__ */ new Map();
87
93
  let compilerOptions;
@@ -196,13 +202,19 @@ var civetUnplugin = (0, import_unplugin.createUnplugin)((options = {}) => {
196
202
  resolveId(id, importer) {
197
203
  if (/\0/.test(id))
198
204
  return null;
199
- if (!isCivet(id) && !isCivetTranspiled(id))
200
- return null;
201
205
  id = cleanCivetId(id);
202
- const absolutePath = import_path.default.isAbsolute(id) ? resolveAbsolutePath(rootDir, id) : import_path.default.resolve(import_path.default.dirname(importer ?? ""), id);
206
+ const absolutePath = import_path.default.isAbsolute(id) ? resolveAbsolutePath(rootDir, id, implicitExtension) : import_path.default.resolve(import_path.default.dirname(importer ?? ""), id);
203
207
  if (!absolutePath)
204
208
  return null;
205
- const relativeId = import_path.default.relative(process.cwd(), absolutePath);
209
+ let relativeId = import_path.default.relative(process.cwd(), absolutePath);
210
+ if (!relativeId.endsWith(".civet")) {
211
+ if (!implicitExtension)
212
+ return null;
213
+ const implicitId = implicitCivet(relativeId);
214
+ if (!implicitId)
215
+ return null;
216
+ relativeId = implicitId;
217
+ }
206
218
  const relativePath = relativeId + outExt;
207
219
  return relativePath;
208
220
  },
@@ -294,7 +306,13 @@ var civetUnplugin = (0, import_unplugin.createUnplugin)((options = {}) => {
294
306
  },
295
307
  vite: {
296
308
  config(config) {
309
+ var _a;
297
310
  rootDir = import_path.default.resolve(process.cwd(), config.root ?? "");
311
+ if (implicitExtension) {
312
+ config.resolve ?? (config.resolve = {});
313
+ (_a = config.resolve).extensions ?? (_a.extensions = []);
314
+ config.resolve.extensions.push(".civet");
315
+ }
298
316
  },
299
317
  async transformIndexHtml(html) {
300
318
  return html.replace(
@@ -313,6 +331,17 @@ var civetUnplugin = (0, import_unplugin.createUnplugin)((options = {}) => {
313
331
  )
314
332
  )
315
333
  );
334
+ },
335
+ handleHotUpdate({ file, server, modules }) {
336
+ if (!file.endsWith(".civet"))
337
+ return;
338
+ const relativeId = slash(import_path.default.relative(process.cwd(), file) + outExt);
339
+ const module2 = server.moduleGraph.getModuleById(relativeId);
340
+ if (module2) {
341
+ server.moduleGraph.onFileChange(relativeId);
342
+ return [...modules, module2];
343
+ }
344
+ return modules;
316
345
  }
317
346
  }
318
347
  };
@@ -9,7 +9,6 @@ import * as fs from "fs";
9
9
  import path from "path";
10
10
  import * as tsvfs from "@typescript/vfs";
11
11
  import os from "os";
12
- var isCivet = (id) => /\.civet([?#].*)?$/.test(id);
13
12
  var isCivetTranspiled = (id) => /\.civet\.[jt]sx([?#].*)?$/.test(id);
14
13
  var postfixRE = /[?#].*$/s;
15
14
  var isWindows = os.platform() === "win32";
@@ -36,11 +35,17 @@ function tryFsResolve(file) {
36
35
  return normalizePath(file);
37
36
  return void 0;
38
37
  }
39
- function resolveAbsolutePath(rootDir, id) {
40
- const resolved = tryFsResolve(path.join(rootDir, id));
41
- if (!resolved)
42
- return tryFsResolve(id);
43
- return resolved;
38
+ function resolveAbsolutePath(rootDir, id, implicitExtension) {
39
+ const file = path.join(rootDir, id);
40
+ return tryFsResolve(file) || implicitExtension && implicitCivet(file) || tryFsResolve(id) || implicitExtension && implicitCivet(id);
41
+ }
42
+ function implicitCivet(file) {
43
+ if (tryFsResolve(file))
44
+ return;
45
+ const civet2 = file + ".civet";
46
+ if (tryFsResolve(civet2))
47
+ return civet2;
48
+ return;
44
49
  }
45
50
  var civetUnplugin = createUnplugin((options = {}) => {
46
51
  if (options.dts)
@@ -49,6 +54,7 @@ var civetUnplugin = createUnplugin((options = {}) => {
49
54
  options.ts = "civet";
50
55
  const transformTS = options.emitDeclaration || options.typecheck;
51
56
  const outExt = options.outputExtension ?? (options.ts === "preserve" ? ".tsx" : ".jsx");
57
+ const implicitExtension = options.implicitExtension ?? true;
52
58
  let fsMap = /* @__PURE__ */ new Map();
53
59
  const sourceMaps = /* @__PURE__ */ new Map();
54
60
  let compilerOptions;
@@ -163,13 +169,19 @@ var civetUnplugin = createUnplugin((options = {}) => {
163
169
  resolveId(id, importer) {
164
170
  if (/\0/.test(id))
165
171
  return null;
166
- if (!isCivet(id) && !isCivetTranspiled(id))
167
- return null;
168
172
  id = cleanCivetId(id);
169
- const absolutePath = path.isAbsolute(id) ? resolveAbsolutePath(rootDir, id) : path.resolve(path.dirname(importer ?? ""), id);
173
+ const absolutePath = path.isAbsolute(id) ? resolveAbsolutePath(rootDir, id, implicitExtension) : path.resolve(path.dirname(importer ?? ""), id);
170
174
  if (!absolutePath)
171
175
  return null;
172
- const relativeId = path.relative(process.cwd(), absolutePath);
176
+ let relativeId = path.relative(process.cwd(), absolutePath);
177
+ if (!relativeId.endsWith(".civet")) {
178
+ if (!implicitExtension)
179
+ return null;
180
+ const implicitId = implicitCivet(relativeId);
181
+ if (!implicitId)
182
+ return null;
183
+ relativeId = implicitId;
184
+ }
173
185
  const relativePath = relativeId + outExt;
174
186
  return relativePath;
175
187
  },
@@ -261,7 +273,13 @@ var civetUnplugin = createUnplugin((options = {}) => {
261
273
  },
262
274
  vite: {
263
275
  config(config) {
276
+ var _a;
264
277
  rootDir = path.resolve(process.cwd(), config.root ?? "");
278
+ if (implicitExtension) {
279
+ config.resolve ?? (config.resolve = {});
280
+ (_a = config.resolve).extensions ?? (_a.extensions = []);
281
+ config.resolve.extensions.push(".civet");
282
+ }
265
283
  },
266
284
  async transformIndexHtml(html) {
267
285
  return html.replace(
@@ -280,6 +298,17 @@ var civetUnplugin = createUnplugin((options = {}) => {
280
298
  )
281
299
  )
282
300
  );
301
+ },
302
+ handleHotUpdate({ file, server, modules }) {
303
+ if (!file.endsWith(".civet"))
304
+ return;
305
+ const relativeId = slash(path.relative(process.cwd(), file) + outExt);
306
+ const module = server.moduleGraph.getModuleById(relativeId);
307
+ if (module) {
308
+ server.moduleGraph.onFileChange(relativeId);
309
+ return [...modules, module];
310
+ }
311
+ return modules;
283
312
  }
284
313
  }
285
314
  };
@@ -2,6 +2,7 @@ import * as unplugin from 'unplugin';
2
2
  import { TransformResult } from 'unplugin';
3
3
 
4
4
  type PluginOptions = {
5
+ implicitExtension?: boolean;
5
6
  outputExtension?: string;
6
7
  transformOutput?: (code: string, id: string) => TransformResult | Promise<TransformResult>;
7
8
  emitDeclaration?: boolean;
@@ -2,6 +2,7 @@ import * as unplugin from 'unplugin';
2
2
  import { TransformResult } from 'unplugin';
3
3
 
4
4
  type PluginOptions = {
5
+ implicitExtension?: boolean;
5
6
  outputExtension?: string;
6
7
  transformOutput?: (code: string, id: string) => TransformResult | Promise<TransformResult>;
7
8
  emitDeclaration?: boolean;
package/dist/unplugin.js CHANGED
@@ -41,7 +41,6 @@ var fs = __toESM(require("fs"));
41
41
  var import_path = __toESM(require("path"));
42
42
  var tsvfs = __toESM(require("@typescript/vfs"));
43
43
  var import_os = __toESM(require("os"));
44
- var isCivet = (id) => /\.civet([?#].*)?$/.test(id);
45
44
  var isCivetTranspiled = (id) => /\.civet\.[jt]sx([?#].*)?$/.test(id);
46
45
  var postfixRE = /[?#].*$/s;
47
46
  var isWindows = import_os.default.platform() === "win32";
@@ -68,11 +67,17 @@ function tryFsResolve(file) {
68
67
  return normalizePath(file);
69
68
  return void 0;
70
69
  }
71
- function resolveAbsolutePath(rootDir, id) {
72
- const resolved = tryFsResolve(import_path.default.join(rootDir, id));
73
- if (!resolved)
74
- return tryFsResolve(id);
75
- return resolved;
70
+ function resolveAbsolutePath(rootDir, id, implicitExtension) {
71
+ const file = import_path.default.join(rootDir, id);
72
+ return tryFsResolve(file) || implicitExtension && implicitCivet(file) || tryFsResolve(id) || implicitExtension && implicitCivet(id);
73
+ }
74
+ function implicitCivet(file) {
75
+ if (tryFsResolve(file))
76
+ return;
77
+ const civet2 = file + ".civet";
78
+ if (tryFsResolve(civet2))
79
+ return civet2;
80
+ return;
76
81
  }
77
82
  var civetUnplugin = (0, import_unplugin.createUnplugin)((options = {}) => {
78
83
  if (options.dts)
@@ -81,6 +86,7 @@ var civetUnplugin = (0, import_unplugin.createUnplugin)((options = {}) => {
81
86
  options.ts = "civet";
82
87
  const transformTS = options.emitDeclaration || options.typecheck;
83
88
  const outExt = options.outputExtension ?? (options.ts === "preserve" ? ".tsx" : ".jsx");
89
+ const implicitExtension = options.implicitExtension ?? true;
84
90
  let fsMap = /* @__PURE__ */ new Map();
85
91
  const sourceMaps = /* @__PURE__ */ new Map();
86
92
  let compilerOptions;
@@ -195,13 +201,19 @@ var civetUnplugin = (0, import_unplugin.createUnplugin)((options = {}) => {
195
201
  resolveId(id, importer) {
196
202
  if (/\0/.test(id))
197
203
  return null;
198
- if (!isCivet(id) && !isCivetTranspiled(id))
199
- return null;
200
204
  id = cleanCivetId(id);
201
- const absolutePath = import_path.default.isAbsolute(id) ? resolveAbsolutePath(rootDir, id) : import_path.default.resolve(import_path.default.dirname(importer ?? ""), id);
205
+ const absolutePath = import_path.default.isAbsolute(id) ? resolveAbsolutePath(rootDir, id, implicitExtension) : import_path.default.resolve(import_path.default.dirname(importer ?? ""), id);
202
206
  if (!absolutePath)
203
207
  return null;
204
- const relativeId = import_path.default.relative(process.cwd(), absolutePath);
208
+ let relativeId = import_path.default.relative(process.cwd(), absolutePath);
209
+ if (!relativeId.endsWith(".civet")) {
210
+ if (!implicitExtension)
211
+ return null;
212
+ const implicitId = implicitCivet(relativeId);
213
+ if (!implicitId)
214
+ return null;
215
+ relativeId = implicitId;
216
+ }
205
217
  const relativePath = relativeId + outExt;
206
218
  return relativePath;
207
219
  },
@@ -293,7 +305,13 @@ var civetUnplugin = (0, import_unplugin.createUnplugin)((options = {}) => {
293
305
  },
294
306
  vite: {
295
307
  config(config) {
308
+ var _a;
296
309
  rootDir = import_path.default.resolve(process.cwd(), config.root ?? "");
310
+ if (implicitExtension) {
311
+ config.resolve ?? (config.resolve = {});
312
+ (_a = config.resolve).extensions ?? (_a.extensions = []);
313
+ config.resolve.extensions.push(".civet");
314
+ }
297
315
  },
298
316
  async transformIndexHtml(html) {
299
317
  return html.replace(
@@ -312,6 +330,17 @@ var civetUnplugin = (0, import_unplugin.createUnplugin)((options = {}) => {
312
330
  )
313
331
  )
314
332
  );
333
+ },
334
+ handleHotUpdate({ file, server, modules }) {
335
+ if (!file.endsWith(".civet"))
336
+ return;
337
+ const relativeId = slash(import_path.default.relative(process.cwd(), file) + outExt);
338
+ const module2 = server.moduleGraph.getModuleById(relativeId);
339
+ if (module2) {
340
+ server.moduleGraph.onFileChange(relativeId);
341
+ return [...modules, module2];
342
+ }
343
+ return modules;
315
344
  }
316
345
  }
317
346
  };
package/dist/vite.js CHANGED
@@ -42,7 +42,6 @@ var fs = __toESM(require("fs"));
42
42
  var import_path = __toESM(require("path"));
43
43
  var tsvfs = __toESM(require("@typescript/vfs"));
44
44
  var import_os = __toESM(require("os"));
45
- var isCivet = (id) => /\.civet([?#].*)?$/.test(id);
46
45
  var isCivetTranspiled = (id) => /\.civet\.[jt]sx([?#].*)?$/.test(id);
47
46
  var postfixRE = /[?#].*$/s;
48
47
  var isWindows = import_os.default.platform() === "win32";
@@ -69,11 +68,17 @@ function tryFsResolve(file) {
69
68
  return normalizePath(file);
70
69
  return void 0;
71
70
  }
72
- function resolveAbsolutePath(rootDir, id) {
73
- const resolved = tryFsResolve(import_path.default.join(rootDir, id));
74
- if (!resolved)
75
- return tryFsResolve(id);
76
- return resolved;
71
+ function resolveAbsolutePath(rootDir, id, implicitExtension) {
72
+ const file = import_path.default.join(rootDir, id);
73
+ return tryFsResolve(file) || implicitExtension && implicitCivet(file) || tryFsResolve(id) || implicitExtension && implicitCivet(id);
74
+ }
75
+ function implicitCivet(file) {
76
+ if (tryFsResolve(file))
77
+ return;
78
+ const civet2 = file + ".civet";
79
+ if (tryFsResolve(civet2))
80
+ return civet2;
81
+ return;
77
82
  }
78
83
  var civetUnplugin = (0, import_unplugin.createUnplugin)((options = {}) => {
79
84
  if (options.dts)
@@ -82,6 +87,7 @@ var civetUnplugin = (0, import_unplugin.createUnplugin)((options = {}) => {
82
87
  options.ts = "civet";
83
88
  const transformTS = options.emitDeclaration || options.typecheck;
84
89
  const outExt = options.outputExtension ?? (options.ts === "preserve" ? ".tsx" : ".jsx");
90
+ const implicitExtension = options.implicitExtension ?? true;
85
91
  let fsMap = /* @__PURE__ */ new Map();
86
92
  const sourceMaps = /* @__PURE__ */ new Map();
87
93
  let compilerOptions;
@@ -196,13 +202,19 @@ var civetUnplugin = (0, import_unplugin.createUnplugin)((options = {}) => {
196
202
  resolveId(id, importer) {
197
203
  if (/\0/.test(id))
198
204
  return null;
199
- if (!isCivet(id) && !isCivetTranspiled(id))
200
- return null;
201
205
  id = cleanCivetId(id);
202
- const absolutePath = import_path.default.isAbsolute(id) ? resolveAbsolutePath(rootDir, id) : import_path.default.resolve(import_path.default.dirname(importer ?? ""), id);
206
+ const absolutePath = import_path.default.isAbsolute(id) ? resolveAbsolutePath(rootDir, id, implicitExtension) : import_path.default.resolve(import_path.default.dirname(importer ?? ""), id);
203
207
  if (!absolutePath)
204
208
  return null;
205
- const relativeId = import_path.default.relative(process.cwd(), absolutePath);
209
+ let relativeId = import_path.default.relative(process.cwd(), absolutePath);
210
+ if (!relativeId.endsWith(".civet")) {
211
+ if (!implicitExtension)
212
+ return null;
213
+ const implicitId = implicitCivet(relativeId);
214
+ if (!implicitId)
215
+ return null;
216
+ relativeId = implicitId;
217
+ }
206
218
  const relativePath = relativeId + outExt;
207
219
  return relativePath;
208
220
  },
@@ -294,7 +306,13 @@ var civetUnplugin = (0, import_unplugin.createUnplugin)((options = {}) => {
294
306
  },
295
307
  vite: {
296
308
  config(config) {
309
+ var _a;
297
310
  rootDir = import_path.default.resolve(process.cwd(), config.root ?? "");
311
+ if (implicitExtension) {
312
+ config.resolve ?? (config.resolve = {});
313
+ (_a = config.resolve).extensions ?? (_a.extensions = []);
314
+ config.resolve.extensions.push(".civet");
315
+ }
298
316
  },
299
317
  async transformIndexHtml(html) {
300
318
  return html.replace(
@@ -313,6 +331,17 @@ var civetUnplugin = (0, import_unplugin.createUnplugin)((options = {}) => {
313
331
  )
314
332
  )
315
333
  );
334
+ },
335
+ handleHotUpdate({ file, server, modules }) {
336
+ if (!file.endsWith(".civet"))
337
+ return;
338
+ const relativeId = slash(import_path.default.relative(process.cwd(), file) + outExt);
339
+ const module2 = server.moduleGraph.getModuleById(relativeId);
340
+ if (module2) {
341
+ server.moduleGraph.onFileChange(relativeId);
342
+ return [...modules, module2];
343
+ }
344
+ return modules;
316
345
  }
317
346
  }
318
347
  };
package/dist/webpack.js CHANGED
@@ -42,7 +42,6 @@ var fs = __toESM(require("fs"));
42
42
  var import_path = __toESM(require("path"));
43
43
  var tsvfs = __toESM(require("@typescript/vfs"));
44
44
  var import_os = __toESM(require("os"));
45
- var isCivet = (id) => /\.civet([?#].*)?$/.test(id);
46
45
  var isCivetTranspiled = (id) => /\.civet\.[jt]sx([?#].*)?$/.test(id);
47
46
  var postfixRE = /[?#].*$/s;
48
47
  var isWindows = import_os.default.platform() === "win32";
@@ -69,11 +68,17 @@ function tryFsResolve(file) {
69
68
  return normalizePath(file);
70
69
  return void 0;
71
70
  }
72
- function resolveAbsolutePath(rootDir, id) {
73
- const resolved = tryFsResolve(import_path.default.join(rootDir, id));
74
- if (!resolved)
75
- return tryFsResolve(id);
76
- return resolved;
71
+ function resolveAbsolutePath(rootDir, id, implicitExtension) {
72
+ const file = import_path.default.join(rootDir, id);
73
+ return tryFsResolve(file) || implicitExtension && implicitCivet(file) || tryFsResolve(id) || implicitExtension && implicitCivet(id);
74
+ }
75
+ function implicitCivet(file) {
76
+ if (tryFsResolve(file))
77
+ return;
78
+ const civet2 = file + ".civet";
79
+ if (tryFsResolve(civet2))
80
+ return civet2;
81
+ return;
77
82
  }
78
83
  var civetUnplugin = (0, import_unplugin.createUnplugin)((options = {}) => {
79
84
  if (options.dts)
@@ -82,6 +87,7 @@ var civetUnplugin = (0, import_unplugin.createUnplugin)((options = {}) => {
82
87
  options.ts = "civet";
83
88
  const transformTS = options.emitDeclaration || options.typecheck;
84
89
  const outExt = options.outputExtension ?? (options.ts === "preserve" ? ".tsx" : ".jsx");
90
+ const implicitExtension = options.implicitExtension ?? true;
85
91
  let fsMap = /* @__PURE__ */ new Map();
86
92
  const sourceMaps = /* @__PURE__ */ new Map();
87
93
  let compilerOptions;
@@ -196,13 +202,19 @@ var civetUnplugin = (0, import_unplugin.createUnplugin)((options = {}) => {
196
202
  resolveId(id, importer) {
197
203
  if (/\0/.test(id))
198
204
  return null;
199
- if (!isCivet(id) && !isCivetTranspiled(id))
200
- return null;
201
205
  id = cleanCivetId(id);
202
- const absolutePath = import_path.default.isAbsolute(id) ? resolveAbsolutePath(rootDir, id) : import_path.default.resolve(import_path.default.dirname(importer ?? ""), id);
206
+ const absolutePath = import_path.default.isAbsolute(id) ? resolveAbsolutePath(rootDir, id, implicitExtension) : import_path.default.resolve(import_path.default.dirname(importer ?? ""), id);
203
207
  if (!absolutePath)
204
208
  return null;
205
- const relativeId = import_path.default.relative(process.cwd(), absolutePath);
209
+ let relativeId = import_path.default.relative(process.cwd(), absolutePath);
210
+ if (!relativeId.endsWith(".civet")) {
211
+ if (!implicitExtension)
212
+ return null;
213
+ const implicitId = implicitCivet(relativeId);
214
+ if (!implicitId)
215
+ return null;
216
+ relativeId = implicitId;
217
+ }
206
218
  const relativePath = relativeId + outExt;
207
219
  return relativePath;
208
220
  },
@@ -294,7 +306,13 @@ var civetUnplugin = (0, import_unplugin.createUnplugin)((options = {}) => {
294
306
  },
295
307
  vite: {
296
308
  config(config) {
309
+ var _a;
297
310
  rootDir = import_path.default.resolve(process.cwd(), config.root ?? "");
311
+ if (implicitExtension) {
312
+ config.resolve ?? (config.resolve = {});
313
+ (_a = config.resolve).extensions ?? (_a.extensions = []);
314
+ config.resolve.extensions.push(".civet");
315
+ }
298
316
  },
299
317
  async transformIndexHtml(html) {
300
318
  return html.replace(
@@ -313,6 +331,17 @@ var civetUnplugin = (0, import_unplugin.createUnplugin)((options = {}) => {
313
331
  )
314
332
  )
315
333
  );
334
+ },
335
+ handleHotUpdate({ file, server, modules }) {
336
+ if (!file.endsWith(".civet"))
337
+ return;
338
+ const relativeId = slash(import_path.default.relative(process.cwd(), file) + outExt);
339
+ const module2 = server.moduleGraph.getModuleById(relativeId);
340
+ if (module2) {
341
+ server.moduleGraph.onFileChange(relativeId);
342
+ return [...modules, module2];
343
+ }
344
+ return modules;
316
345
  }
317
346
  }
318
347
  };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@danielx/civet",
3
3
  "type": "commonjs",
4
- "version": "0.6.56",
4
+ "version": "0.6.57",
5
5
  "description": "CoffeeScript style syntax for TypeScript",
6
6
  "main": "dist/main.js",
7
7
  "module": "dist/main.mjs",