@danielx/civet 0.6.55 → 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/browser.js CHANGED
@@ -2428,6 +2428,32 @@ ${input.slice(result.pos)}
2428
2428
  }
2429
2429
  }
2430
2430
  }
2431
+ function processDeclarations(statements) {
2432
+ gatherRecursiveAll(statements, (n) => {
2433
+ return n.type === "Declaration";
2434
+ }).forEach(({ bindings }) => {
2435
+ return bindings?.forEach((binding) => {
2436
+ const { initializer } = binding;
2437
+ if (!initializer) {
2438
+ return;
2439
+ }
2440
+ const exp = initializer[2];
2441
+ if (exp?.type === "PipelineExpression") {
2442
+ if (exp.children.at(-2) === ",") {
2443
+ const { parent } = exp;
2444
+ const parenthesizedExpression = makeLeftHandSideExpression(exp);
2445
+ parenthesizedExpression.parent = parent;
2446
+ exp.parent = parenthesizedExpression;
2447
+ return initializer[2] = parenthesizedExpression;
2448
+ }
2449
+ ;
2450
+ return;
2451
+ }
2452
+ ;
2453
+ return;
2454
+ });
2455
+ });
2456
+ }
2431
2457
  function implicitFunctionBlock(f) {
2432
2458
  if (f.abstract || f.block || f.signature?.optional)
2433
2459
  return;
@@ -3164,6 +3190,7 @@ ${input.slice(result.pos)}
3164
3190
  const { expressions: statements } = root;
3165
3191
  processDeclarationConditions(statements);
3166
3192
  processPipelineExpressions(statements);
3193
+ processDeclarations(statements);
3167
3194
  processAssignments(statements);
3168
3195
  processPatternMatching(statements, ReservedWord);
3169
3196
  gatherRecursiveAll(statements, (n) => n.type === "IterationExpression").forEach((e) => expressionizeIteration(e));
@@ -7279,11 +7306,19 @@ ${input.slice(result.pos)}
7279
7306
  const expressions = [...stmts];
7280
7307
  if (last)
7281
7308
  expressions.push(last);
7309
+ const maybeComment = expressions.at(-1)?.[2]?.children?.[2]?.at(-1);
7310
+ let hasTrailingComment = false;
7311
+ if (maybeComment?.type === "Comment" && maybeComment.token.startsWith("//")) {
7312
+ hasTrailingComment = true;
7313
+ }
7314
+ const children = [expressions];
7315
+ if (hasTrailingComment) {
7316
+ children.push("\n");
7317
+ }
7282
7318
  return {
7283
7319
  type: "BlockStatement",
7284
7320
  expressions,
7285
- children: [expressions],
7286
- // avoid aliasing
7321
+ children,
7287
7322
  bare: true
7288
7323
  };
7289
7324
  });
@@ -9633,7 +9668,7 @@ ${input.slice(result.pos)}
9633
9668
  return $EVENT(ctx, state, "CatchClause", CatchClause$0);
9634
9669
  }
9635
9670
  var CatchBind$0 = $S($E(_), OpenParen, __, CatchParameter, __, CloseParen);
9636
- var CatchBind$1 = $S(_, InsertOpenParen, CatchParameter, InsertCloseParen);
9671
+ var CatchBind$1 = $S(_, InsertOpenParen, $N(EOS), CatchParameter, InsertCloseParen);
9637
9672
  var CatchBind$$ = [CatchBind$0, CatchBind$1];
9638
9673
  function CatchBind(ctx, state) {
9639
9674
  return $EVENT_C(ctx, state, "CatchBind", CatchBind$$);
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
  },
@@ -280,7 +292,7 @@ var civetUnplugin = (0, import_unplugin.createUnplugin)((options = {}) => {
280
292
  }
281
293
  }
282
294
  }
283
- const jsonSourceMap = typeof compiled.sourceMap == "string" ? compiled.sourceMap : compiled.sourceMap.json(
295
+ const jsonSourceMap = typeof compiled.sourceMap == "string" ? JSON.parse(compiled.sourceMap) : compiled.sourceMap.json(
284
296
  import_path.default.basename(id.replace(/\.[jt]sx$/, "")),
285
297
  import_path.default.basename(id)
286
298
  );
@@ -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/main.js CHANGED
@@ -2420,6 +2420,32 @@ var require_lib = __commonJS({
2420
2420
  }
2421
2421
  }
2422
2422
  }
2423
+ function processDeclarations(statements) {
2424
+ gatherRecursiveAll(statements, (n) => {
2425
+ return n.type === "Declaration";
2426
+ }).forEach(({ bindings }) => {
2427
+ return bindings?.forEach((binding) => {
2428
+ const { initializer } = binding;
2429
+ if (!initializer) {
2430
+ return;
2431
+ }
2432
+ const exp = initializer[2];
2433
+ if (exp?.type === "PipelineExpression") {
2434
+ if (exp.children.at(-2) === ",") {
2435
+ const { parent } = exp;
2436
+ const parenthesizedExpression = makeLeftHandSideExpression(exp);
2437
+ parenthesizedExpression.parent = parent;
2438
+ exp.parent = parenthesizedExpression;
2439
+ return initializer[2] = parenthesizedExpression;
2440
+ }
2441
+ ;
2442
+ return;
2443
+ }
2444
+ ;
2445
+ return;
2446
+ });
2447
+ });
2448
+ }
2423
2449
  function implicitFunctionBlock(f) {
2424
2450
  if (f.abstract || f.block || f.signature?.optional)
2425
2451
  return;
@@ -3156,6 +3182,7 @@ var require_lib = __commonJS({
3156
3182
  const { expressions: statements } = root;
3157
3183
  processDeclarationConditions(statements);
3158
3184
  processPipelineExpressions(statements);
3185
+ processDeclarations(statements);
3159
3186
  processAssignments(statements);
3160
3187
  processPatternMatching(statements, ReservedWord);
3161
3188
  gatherRecursiveAll(statements, (n) => n.type === "IterationExpression").forEach((e) => expressionizeIteration(e));
@@ -7271,11 +7298,19 @@ var require_parser = __commonJS({
7271
7298
  const expressions = [...stmts];
7272
7299
  if (last)
7273
7300
  expressions.push(last);
7301
+ const maybeComment = expressions.at(-1)?.[2]?.children?.[2]?.at(-1);
7302
+ let hasTrailingComment = false;
7303
+ if (maybeComment?.type === "Comment" && maybeComment.token.startsWith("//")) {
7304
+ hasTrailingComment = true;
7305
+ }
7306
+ const children = [expressions];
7307
+ if (hasTrailingComment) {
7308
+ children.push("\n");
7309
+ }
7274
7310
  return {
7275
7311
  type: "BlockStatement",
7276
7312
  expressions,
7277
- children: [expressions],
7278
- // avoid aliasing
7313
+ children,
7279
7314
  bare: true
7280
7315
  };
7281
7316
  });
@@ -9625,7 +9660,7 @@ var require_parser = __commonJS({
9625
9660
  return $EVENT(ctx, state, "CatchClause", CatchClause$0);
9626
9661
  }
9627
9662
  var CatchBind$0 = $S($E(_), OpenParen, __, CatchParameter, __, CloseParen);
9628
- var CatchBind$1 = $S(_, InsertOpenParen, CatchParameter, InsertCloseParen);
9663
+ var CatchBind$1 = $S(_, InsertOpenParen, $N(EOS), CatchParameter, InsertCloseParen);
9629
9664
  var CatchBind$$ = [CatchBind$0, CatchBind$1];
9630
9665
  function CatchBind(ctx, state) {
9631
9666
  return $EVENT_C(ctx, state, "CatchBind", CatchBind$$);
package/dist/main.mjs CHANGED
@@ -2418,6 +2418,32 @@ var require_lib = __commonJS({
2418
2418
  }
2419
2419
  }
2420
2420
  }
2421
+ function processDeclarations(statements) {
2422
+ gatherRecursiveAll(statements, (n) => {
2423
+ return n.type === "Declaration";
2424
+ }).forEach(({ bindings }) => {
2425
+ return bindings?.forEach((binding) => {
2426
+ const { initializer } = binding;
2427
+ if (!initializer) {
2428
+ return;
2429
+ }
2430
+ const exp = initializer[2];
2431
+ if (exp?.type === "PipelineExpression") {
2432
+ if (exp.children.at(-2) === ",") {
2433
+ const { parent } = exp;
2434
+ const parenthesizedExpression = makeLeftHandSideExpression(exp);
2435
+ parenthesizedExpression.parent = parent;
2436
+ exp.parent = parenthesizedExpression;
2437
+ return initializer[2] = parenthesizedExpression;
2438
+ }
2439
+ ;
2440
+ return;
2441
+ }
2442
+ ;
2443
+ return;
2444
+ });
2445
+ });
2446
+ }
2421
2447
  function implicitFunctionBlock(f) {
2422
2448
  if (f.abstract || f.block || f.signature?.optional)
2423
2449
  return;
@@ -3154,6 +3180,7 @@ var require_lib = __commonJS({
3154
3180
  const { expressions: statements } = root;
3155
3181
  processDeclarationConditions(statements);
3156
3182
  processPipelineExpressions(statements);
3183
+ processDeclarations(statements);
3157
3184
  processAssignments(statements);
3158
3185
  processPatternMatching(statements, ReservedWord);
3159
3186
  gatherRecursiveAll(statements, (n) => n.type === "IterationExpression").forEach((e) => expressionizeIteration(e));
@@ -7269,11 +7296,19 @@ var require_parser = __commonJS({
7269
7296
  const expressions = [...stmts];
7270
7297
  if (last)
7271
7298
  expressions.push(last);
7299
+ const maybeComment = expressions.at(-1)?.[2]?.children?.[2]?.at(-1);
7300
+ let hasTrailingComment = false;
7301
+ if (maybeComment?.type === "Comment" && maybeComment.token.startsWith("//")) {
7302
+ hasTrailingComment = true;
7303
+ }
7304
+ const children = [expressions];
7305
+ if (hasTrailingComment) {
7306
+ children.push("\n");
7307
+ }
7272
7308
  return {
7273
7309
  type: "BlockStatement",
7274
7310
  expressions,
7275
- children: [expressions],
7276
- // avoid aliasing
7311
+ children,
7277
7312
  bare: true
7278
7313
  };
7279
7314
  });
@@ -9623,7 +9658,7 @@ var require_parser = __commonJS({
9623
9658
  return $EVENT(ctx, state, "CatchClause", CatchClause$0);
9624
9659
  }
9625
9660
  var CatchBind$0 = $S($E(_), OpenParen, __, CatchParameter, __, CloseParen);
9626
- var CatchBind$1 = $S(_, InsertOpenParen, CatchParameter, InsertCloseParen);
9661
+ var CatchBind$1 = $S(_, InsertOpenParen, $N(EOS), CatchParameter, InsertCloseParen);
9627
9662
  var CatchBind$$ = [CatchBind$0, CatchBind$1];
9628
9663
  function CatchBind(ctx, state) {
9629
9664
  return $EVENT_C(ctx, state, "CatchBind", CatchBind$$);
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
  },
@@ -280,7 +292,7 @@ var civetUnplugin = (0, import_unplugin.createUnplugin)((options = {}) => {
280
292
  }
281
293
  }
282
294
  }
283
- const jsonSourceMap = typeof compiled.sourceMap == "string" ? compiled.sourceMap : compiled.sourceMap.json(
295
+ const jsonSourceMap = typeof compiled.sourceMap == "string" ? JSON.parse(compiled.sourceMap) : compiled.sourceMap.json(
284
296
  import_path.default.basename(id.replace(/\.[jt]sx$/, "")),
285
297
  import_path.default.basename(id)
286
298
  );
@@ -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
  };
@@ -1,7 +1,5 @@
1
1
  // src/index.ts
2
- import {
3
- createUnplugin
4
- } from "unplugin";
2
+ import { createUnplugin } from "unplugin";
5
3
  import civet from "@danielx/civet";
6
4
  import {
7
5
  remapRange,
@@ -11,7 +9,6 @@ import * as fs from "fs";
11
9
  import path from "path";
12
10
  import * as tsvfs from "@typescript/vfs";
13
11
  import os from "os";
14
- var isCivet = (id) => /\.civet([?#].*)?$/.test(id);
15
12
  var isCivetTranspiled = (id) => /\.civet\.[jt]sx([?#].*)?$/.test(id);
16
13
  var postfixRE = /[?#].*$/s;
17
14
  var isWindows = os.platform() === "win32";
@@ -38,11 +35,17 @@ function tryFsResolve(file) {
38
35
  return normalizePath(file);
39
36
  return void 0;
40
37
  }
41
- function resolveAbsolutePath(rootDir, id) {
42
- const resolved = tryFsResolve(path.join(rootDir, id));
43
- if (!resolved)
44
- return tryFsResolve(id);
45
- 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;
46
49
  }
47
50
  var civetUnplugin = createUnplugin((options = {}) => {
48
51
  if (options.dts)
@@ -51,6 +54,7 @@ var civetUnplugin = createUnplugin((options = {}) => {
51
54
  options.ts = "civet";
52
55
  const transformTS = options.emitDeclaration || options.typecheck;
53
56
  const outExt = options.outputExtension ?? (options.ts === "preserve" ? ".tsx" : ".jsx");
57
+ const implicitExtension = options.implicitExtension ?? true;
54
58
  let fsMap = /* @__PURE__ */ new Map();
55
59
  const sourceMaps = /* @__PURE__ */ new Map();
56
60
  let compilerOptions;
@@ -165,13 +169,19 @@ var civetUnplugin = createUnplugin((options = {}) => {
165
169
  resolveId(id, importer) {
166
170
  if (/\0/.test(id))
167
171
  return null;
168
- if (!isCivet(id) && !isCivetTranspiled(id))
169
- return null;
170
172
  id = cleanCivetId(id);
171
- 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);
172
174
  if (!absolutePath)
173
175
  return null;
174
- 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
+ }
175
185
  const relativePath = relativeId + outExt;
176
186
  return relativePath;
177
187
  },
@@ -249,7 +259,7 @@ var civetUnplugin = createUnplugin((options = {}) => {
249
259
  }
250
260
  }
251
261
  }
252
- const jsonSourceMap = typeof compiled.sourceMap == "string" ? compiled.sourceMap : compiled.sourceMap.json(
262
+ const jsonSourceMap = typeof compiled.sourceMap == "string" ? JSON.parse(compiled.sourceMap) : compiled.sourceMap.json(
253
263
  path.basename(id.replace(/\.[jt]sx$/, "")),
254
264
  path.basename(id)
255
265
  );
@@ -263,7 +273,13 @@ var civetUnplugin = createUnplugin((options = {}) => {
263
273
  },
264
274
  vite: {
265
275
  config(config) {
276
+ var _a;
266
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
+ }
267
283
  },
268
284
  async transformIndexHtml(html) {
269
285
  return html.replace(
@@ -282,6 +298,17 @@ var civetUnplugin = createUnplugin((options = {}) => {
282
298
  )
283
299
  )
284
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;
285
312
  }
286
313
  }
287
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
  },
@@ -279,7 +291,7 @@ var civetUnplugin = (0, import_unplugin.createUnplugin)((options = {}) => {
279
291
  }
280
292
  }
281
293
  }
282
- const jsonSourceMap = typeof compiled.sourceMap == "string" ? compiled.sourceMap : compiled.sourceMap.json(
294
+ const jsonSourceMap = typeof compiled.sourceMap == "string" ? JSON.parse(compiled.sourceMap) : compiled.sourceMap.json(
283
295
  import_path.default.basename(id.replace(/\.[jt]sx$/, "")),
284
296
  import_path.default.basename(id)
285
297
  );
@@ -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
  },
@@ -280,7 +292,7 @@ var civetUnplugin = (0, import_unplugin.createUnplugin)((options = {}) => {
280
292
  }
281
293
  }
282
294
  }
283
- const jsonSourceMap = typeof compiled.sourceMap == "string" ? compiled.sourceMap : compiled.sourceMap.json(
295
+ const jsonSourceMap = typeof compiled.sourceMap == "string" ? JSON.parse(compiled.sourceMap) : compiled.sourceMap.json(
284
296
  import_path.default.basename(id.replace(/\.[jt]sx$/, "")),
285
297
  import_path.default.basename(id)
286
298
  );
@@ -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
  },
@@ -280,7 +292,7 @@ var civetUnplugin = (0, import_unplugin.createUnplugin)((options = {}) => {
280
292
  }
281
293
  }
282
294
  }
283
- const jsonSourceMap = typeof compiled.sourceMap == "string" ? compiled.sourceMap : compiled.sourceMap.json(
295
+ const jsonSourceMap = typeof compiled.sourceMap == "string" ? JSON.parse(compiled.sourceMap) : compiled.sourceMap.json(
284
296
  import_path.default.basename(id.replace(/\.[jt]sx$/, "")),
285
297
  import_path.default.basename(id)
286
298
  );
@@ -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.55",
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",
@@ -72,6 +72,7 @@
72
72
  "devDependencies": {
73
73
  "@danielx/civet": "0.6.45",
74
74
  "@danielx/hera": "^0.8.10",
75
+ "@prettier/sync": "^0.3.0",
75
76
  "@types/assert": "^1.5.6",
76
77
  "@types/mocha": "^9.1.1",
77
78
  "@types/node": "^20.5.1",
@@ -80,13 +81,13 @@
80
81
  "esbuild": "0.16.17",
81
82
  "marked": "^4.2.4",
82
83
  "mocha": "^10.0.0",
83
- "prettier": "^2.8.1",
84
+ "prettier": "^3.1.1",
84
85
  "terser": "^5.16.1",
85
86
  "ts-node": "^10.9.1",
86
87
  "tslib": "^2.4.0",
87
88
  "tsup": "^7.2.0",
88
89
  "typescript": "^5.2.2",
89
- "vite": "^4.4.9",
90
+ "vite": "^4.4.12",
90
91
  "vitepress": "^1.0.0-alpha.35",
91
92
  "vscode-languageserver": "^8.1.0",
92
93
  "vscode-languageserver-textdocument": "^1.0.8",