@danielx/civet 0.6.46 → 0.6.48

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
@@ -4655,7 +4655,7 @@ ${input.slice(result.pos)}
4655
4655
  var $R16 = $R(new RegExp("(?=\\p{ID_Start}|[_$^\xAB\xBB\u22D9\u2264\u2265\u2208\u220B\u2209\u220C\u2263\u2261\u2262\u2260=\u2016\u2047&|*\\/!?%<>+-])", "suy"));
4656
4656
  var $R17 = $R(new RegExp("<(?!\\p{ID_Start}|[_$])", "suy"));
4657
4657
  var $R18 = $R(new RegExp("!\\^\\^?", "suy"));
4658
- var $R19 = $R(new RegExp("(?!\\+\\+|--)[!~+-](?!\\s|[!~+-]*[&.])", "suy"));
4658
+ var $R19 = $R(new RegExp("(?!\\+\\+|--)[!~+-](?!\\s|[!~+-]*(&|\\.[^0-9]))", "suy"));
4659
4659
  var $R20 = $R(new RegExp("(?=for|if|loop|unless|until|while)", "suy"));
4660
4660
  var $R21 = $R(new RegExp("(?=loop|do|for|until|while)", "suy"));
4661
4661
  var $R22 = $R(new RegExp("(?=[\\s\\),])", "suy"));
@@ -4718,12 +4718,12 @@ ${input.slice(result.pos)}
4718
4718
  var $R79 = $R(new RegExp("[+-]", "suy"));
4719
4719
  var $R80 = $R(new RegExp("#![^\\r\\n]*", "suy"));
4720
4720
  var $R81 = $R(new RegExp("[\\t ]*", "suy"));
4721
- var $R82 = $R(new RegExp("[\\s]*", "suy"));
4722
- var $R83 = $R(new RegExp("\\s+([+-]?)([a-zA-Z0-9-]+)(\\s*=\\s*([a-zA-Z0-9.+-]*))?", "suy"));
4723
- var $R84 = $R(new RegExp("\\/\\/\\/[^\\r\\n]*", "suy"));
4724
- var $R85 = $R(new RegExp("(?=[ \\t\\r\\n\\/#]|$)", "suy"));
4725
- var $R86 = $R(new RegExp("\\r\\n|\\n|\\r|$", "suy"));
4726
- var $R87 = $R(new RegExp("[ \\t]*", "suy"));
4721
+ var $R82 = $R(new RegExp("[ \\t]*", "suy"));
4722
+ var $R83 = $R(new RegExp("[\\s]*", "suy"));
4723
+ var $R84 = $R(new RegExp("\\s+([+-]?)([a-zA-Z0-9-]+)(\\s*=\\s*([a-zA-Z0-9.+-]*))?", "suy"));
4724
+ var $R85 = $R(new RegExp("\\/\\/\\/[^\\r\\n]*", "suy"));
4725
+ var $R86 = $R(new RegExp("(?=[ \\t\\r\\n\\/#]|$)", "suy"));
4726
+ var $R87 = $R(new RegExp("\\r\\n|\\n|\\r|$", "suy"));
4727
4727
  var Program$0 = $TS($S(Reset, Init, $E(EOS), TopLevelStatements, __), function($skip, $loc, $0, $1, $2, $3, $4, $5) {
4728
4728
  var statements = $4;
4729
4729
  processProgram({
@@ -8413,7 +8413,7 @@ ${input.slice(result.pos)}
8413
8413
  function Xnor(ctx, state) {
8414
8414
  return $EVENT_C(ctx, state, "Xnor", Xnor$$);
8415
8415
  }
8416
- var UnaryOp$0 = $TR($EXPECT($R19, "UnaryOp /(?!\\+\\+|--)[!~+-](?!\\s|[!~+-]*[&.])/"), function($skip, $loc, $0, $1, $2, $3, $4, $5, $6, $7, $8, $9) {
8416
+ var UnaryOp$0 = $TR($EXPECT($R19, "UnaryOp /(?!\\+\\+|--)[!~+-](?!\\s|[!~+-]*(&|\\.[^0-9]))/"), function($skip, $loc, $0, $1, $2, $3, $4, $5, $6, $7, $8, $9) {
8417
8417
  return { $loc, token: $0 };
8418
8418
  });
8419
8419
  var UnaryOp$1 = AwaitOp;
@@ -12430,11 +12430,11 @@ ${input.slice(result.pos)}
12430
12430
  function Shebang(ctx, state) {
12431
12431
  return $EVENT(ctx, state, "Shebang", Shebang$0);
12432
12432
  }
12433
- var CivetPrologue$0 = $T($S($EXPECT($R81, "CivetPrologue /[\\t ]*/"), DoubleQuote, CivetPrologueContent, DoubleQuote, SimpleStatementDelimiter, $E(EOS)), function(value) {
12433
+ var CivetPrologue$0 = $T($S($EXPECT($R81, "CivetPrologue /[\\t ]*/"), DoubleQuote, CivetPrologueContent, DoubleQuote, SimpleStatementDelimiter, $EXPECT($R82, "CivetPrologue /[ \\t]*/"), $C(EOL, $Y(RestOfLine))), function(value) {
12434
12434
  var content = value[2];
12435
12435
  return content;
12436
12436
  });
12437
- var CivetPrologue$1 = $T($S($EXPECT($R81, "CivetPrologue /[\\t ]*/"), SingleQuote, CivetPrologueContent, SingleQuote, SimpleStatementDelimiter, $E(EOS)), function(value) {
12437
+ var CivetPrologue$1 = $T($S($EXPECT($R81, "CivetPrologue /[\\t ]*/"), SingleQuote, CivetPrologueContent, SingleQuote, SimpleStatementDelimiter, $EXPECT($R82, "CivetPrologue /[ \\t]*/"), $C(EOL, $Y(RestOfLine))), function(value) {
12438
12438
  var content = value[2];
12439
12439
  return content;
12440
12440
  });
@@ -12442,7 +12442,7 @@ ${input.slice(result.pos)}
12442
12442
  function CivetPrologue(ctx, state) {
12443
12443
  return $EVENT_C(ctx, state, "CivetPrologue", CivetPrologue$$);
12444
12444
  }
12445
- var CivetPrologueContent$0 = $TS($S($EXPECT($L210, 'CivetPrologueContent "civet"'), NonIdContinue, $Q(CivetOption), $EXPECT($R82, "CivetPrologueContent /[\\s]*/")), function($skip, $loc, $0, $1, $2, $3, $4) {
12445
+ var CivetPrologueContent$0 = $TS($S($EXPECT($L210, 'CivetPrologueContent "civet"'), NonIdContinue, $Q(CivetOption), $EXPECT($R83, "CivetPrologueContent /[\\s]*/")), function($skip, $loc, $0, $1, $2, $3, $4) {
12446
12446
  var options = $3;
12447
12447
  return {
12448
12448
  type: "CivetPrologue",
@@ -12453,7 +12453,7 @@ ${input.slice(result.pos)}
12453
12453
  function CivetPrologueContent(ctx, state) {
12454
12454
  return $EVENT(ctx, state, "CivetPrologueContent", CivetPrologueContent$0);
12455
12455
  }
12456
- var CivetOption$0 = $TR($EXPECT($R83, "CivetOption /\\s+([+-]?)([a-zA-Z0-9-]+)(\\s*=\\s*([a-zA-Z0-9.+-]*))?/"), function($skip, $loc, $0, $1, $2, $3, $4, $5, $6, $7, $8, $9) {
12456
+ var CivetOption$0 = $TR($EXPECT($R84, "CivetOption /\\s+([+-]?)([a-zA-Z0-9-]+)(\\s*=\\s*([a-zA-Z0-9.+-]*))?/"), function($skip, $loc, $0, $1, $2, $3, $4, $5, $6, $7, $8, $9) {
12457
12457
  const optionName = $2.replace(/-+([a-z]?)/g, (_2, l) => {
12458
12458
  if (l)
12459
12459
  return l.toUpperCase();
@@ -12474,7 +12474,7 @@ ${input.slice(result.pos)}
12474
12474
  function UnknownPrologue(ctx, state) {
12475
12475
  return $EVENT(ctx, state, "UnknownPrologue", UnknownPrologue$0);
12476
12476
  }
12477
- var TripleSlashDirective$0 = $S($R$0($EXPECT($R84, "TripleSlashDirective /\\/\\/\\/[^\\r\\n]*/")), $E(EOS));
12477
+ var TripleSlashDirective$0 = $S($R$0($EXPECT($R85, "TripleSlashDirective /\\/\\/\\/[^\\r\\n]*/")), $E(EOS));
12478
12478
  function TripleSlashDirective(ctx, state) {
12479
12479
  return $EVENT(ctx, state, "TripleSlashDirective", TripleSlashDirective$0);
12480
12480
  }
@@ -12488,13 +12488,13 @@ ${input.slice(result.pos)}
12488
12488
  function PrologueString(ctx, state) {
12489
12489
  return $EVENT_C(ctx, state, "PrologueString", PrologueString$$);
12490
12490
  }
12491
- var EOS$0 = $T($S($EXPECT($R85, "EOS /(?=[ \\t\\r\\n\\/#]|$)/"), $P(RestOfLine)), function(value) {
12491
+ var EOS$0 = $T($S($EXPECT($R86, "EOS /(?=[ \\t\\r\\n\\/#]|$)/"), $P(RestOfLine)), function(value) {
12492
12492
  return value[1];
12493
12493
  });
12494
12494
  function EOS(ctx, state) {
12495
12495
  return $EVENT(ctx, state, "EOS", EOS$0);
12496
12496
  }
12497
- var EOL$0 = $TR($EXPECT($R86, "EOL /\\r\\n|\\n|\\r|$/"), function($skip, $loc, $0, $1, $2, $3, $4, $5, $6, $7, $8, $9) {
12497
+ var EOL$0 = $TR($EXPECT($R87, "EOL /\\r\\n|\\n|\\r|$/"), function($skip, $loc, $0, $1, $2, $3, $4, $5, $6, $7, $8, $9) {
12498
12498
  return { $loc, token: $0 };
12499
12499
  });
12500
12500
  function EOL(ctx, state) {
@@ -12988,7 +12988,7 @@ ${input.slice(result.pos)}
12988
12988
  function Init(ctx, state) {
12989
12989
  return $EVENT(ctx, state, "Init", Init$0);
12990
12990
  }
12991
- var Indent$0 = $TR($EXPECT($R87, "Indent /[ \\t]*/"), function($skip, $loc, $0, $1, $2, $3, $4, $5, $6, $7, $8, $9) {
12991
+ var Indent$0 = $TR($EXPECT($R82, "Indent /[ \\t]*/"), function($skip, $loc, $0, $1, $2, $3, $4, $5, $6, $7, $8, $9) {
12992
12992
  const level = getIndentLevel($0, module.config.tab);
12993
12993
  return {
12994
12994
  $loc,
package/dist/esbuild.js CHANGED
@@ -48,7 +48,7 @@ var formatHost = {
48
48
  getCanonicalFileName: import_typescript.default.sys.useCaseSensitiveFileNames ? (f) => f : (f) => f.toLowerCase()
49
49
  };
50
50
  var isCivet = (id) => /\.civet$/.test(id);
51
- var isCivetTranspiled = (id) => /\.civet\.(m?)(j|t)s(x?)$/.test(id);
51
+ var isCivetTranspiled = (id) => /\.civet\.(m?)(j|t)s(x?)(\?transform)?$/.test(id);
52
52
  var isCivetTranspiledTS = (id) => /\.civet\.(m?)ts(x?)$/.test(id);
53
53
  var civetUnplugin = (0, import_unplugin.createUnplugin)((options = {}) => {
54
54
  if (options.dts && options.js) {
@@ -62,6 +62,7 @@ var civetUnplugin = (0, import_unplugin.createUnplugin)((options = {}) => {
62
62
  let fsMap = /* @__PURE__ */ new Map();
63
63
  const sourceMaps = /* @__PURE__ */ new Map();
64
64
  let compilerOptions;
65
+ let rootDir;
65
66
  return {
66
67
  name: "unplugin-civet",
67
68
  enforce: "pre",
@@ -159,12 +160,12 @@ var civetUnplugin = (0, import_unplugin.createUnplugin)((options = {}) => {
159
160
  resolveId(id, importer) {
160
161
  if (/\0/.test(id))
161
162
  return null;
162
- if (!isCivet(id))
163
+ if (!isCivet(id) && !isCivetTranspiled(id))
163
164
  return null;
164
- const relativeId = import_path.default.relative(
165
- process.cwd(),
166
- import_path.default.resolve(import_path.default.dirname(importer ?? ""), id)
167
- );
165
+ const absolutePath = rootDir != null && import_path.default.isAbsolute(id) ? import_path.default.join(rootDir, id) : import_path.default.resolve(import_path.default.dirname(importer ?? ""), id);
166
+ const relativeId = import_path.default.relative(process.cwd(), absolutePath);
167
+ if (isCivetTranspiled(id))
168
+ return relativeId.replace(/\?transform$/, "");
168
169
  const relativePath = relativeId + outExt;
169
170
  return relativePath;
170
171
  },
@@ -176,6 +177,7 @@ var civetUnplugin = (0, import_unplugin.createUnplugin)((options = {}) => {
176
177
  return null;
177
178
  const filename = import_path.default.resolve(process.cwd(), id.slice(0, -outExt.length));
178
179
  const code = await fs.promises.readFile(filename, "utf-8");
180
+ this.addWatchFile(filename);
179
181
  const compiled = import_civet.default.compile(code, {
180
182
  // inlineMap: true,
181
183
  filename: id,
@@ -211,7 +213,8 @@ var civetUnplugin = (0, import_unplugin.createUnplugin)((options = {}) => {
211
213
  return null;
212
214
  },
213
215
  vite: {
214
- config(_config, { command }) {
216
+ config(config, { command }) {
217
+ rootDir = import_path.default.resolve(process.cwd(), config.root ?? "");
215
218
  if (command === "build") {
216
219
  return {
217
220
  esbuild: {
@@ -221,6 +224,24 @@ var civetUnplugin = (0, import_unplugin.createUnplugin)((options = {}) => {
221
224
  };
222
225
  }
223
226
  return null;
227
+ },
228
+ async transformIndexHtml(html) {
229
+ return html.replace(
230
+ /<!--[^]*?-->|<[^<>]*>/g,
231
+ (tag) => tag.replace(
232
+ /<\s*script\b[^<>]*>/gi,
233
+ (script) => (
234
+ // https://html.spec.whatwg.org/multipage/syntax.html#attributes-2
235
+ script.replace(
236
+ /([:_\p{ID_Start}][:\p{ID_Continue}]*)(\s*=\s*("[^"]*"|'[^']*'|[^\s"'=<>`]*))?/gu,
237
+ (attr, name, value) => name.toLowerCase() === "src" && value ? attr.replace(
238
+ /(\.civet)(['"]?)$/,
239
+ (_, extension, endQuote) => `${extension}${outExt}?transform${endQuote}`
240
+ ) : attr
241
+ )
242
+ )
243
+ )
244
+ );
224
245
  }
225
246
  }
226
247
  };
package/dist/main.js CHANGED
@@ -4647,7 +4647,7 @@ var require_parser = __commonJS({
4647
4647
  var $R16 = $R(new RegExp("(?=\\p{ID_Start}|[_$^\xAB\xBB\u22D9\u2264\u2265\u2208\u220B\u2209\u220C\u2263\u2261\u2262\u2260=\u2016\u2047&|*\\/!?%<>+-])", "suy"));
4648
4648
  var $R17 = $R(new RegExp("<(?!\\p{ID_Start}|[_$])", "suy"));
4649
4649
  var $R18 = $R(new RegExp("!\\^\\^?", "suy"));
4650
- var $R19 = $R(new RegExp("(?!\\+\\+|--)[!~+-](?!\\s|[!~+-]*[&.])", "suy"));
4650
+ var $R19 = $R(new RegExp("(?!\\+\\+|--)[!~+-](?!\\s|[!~+-]*(&|\\.[^0-9]))", "suy"));
4651
4651
  var $R20 = $R(new RegExp("(?=for|if|loop|unless|until|while)", "suy"));
4652
4652
  var $R21 = $R(new RegExp("(?=loop|do|for|until|while)", "suy"));
4653
4653
  var $R22 = $R(new RegExp("(?=[\\s\\),])", "suy"));
@@ -4710,12 +4710,12 @@ var require_parser = __commonJS({
4710
4710
  var $R79 = $R(new RegExp("[+-]", "suy"));
4711
4711
  var $R80 = $R(new RegExp("#![^\\r\\n]*", "suy"));
4712
4712
  var $R81 = $R(new RegExp("[\\t ]*", "suy"));
4713
- var $R82 = $R(new RegExp("[\\s]*", "suy"));
4714
- var $R83 = $R(new RegExp("\\s+([+-]?)([a-zA-Z0-9-]+)(\\s*=\\s*([a-zA-Z0-9.+-]*))?", "suy"));
4715
- var $R84 = $R(new RegExp("\\/\\/\\/[^\\r\\n]*", "suy"));
4716
- var $R85 = $R(new RegExp("(?=[ \\t\\r\\n\\/#]|$)", "suy"));
4717
- var $R86 = $R(new RegExp("\\r\\n|\\n|\\r|$", "suy"));
4718
- var $R87 = $R(new RegExp("[ \\t]*", "suy"));
4713
+ var $R82 = $R(new RegExp("[ \\t]*", "suy"));
4714
+ var $R83 = $R(new RegExp("[\\s]*", "suy"));
4715
+ var $R84 = $R(new RegExp("\\s+([+-]?)([a-zA-Z0-9-]+)(\\s*=\\s*([a-zA-Z0-9.+-]*))?", "suy"));
4716
+ var $R85 = $R(new RegExp("\\/\\/\\/[^\\r\\n]*", "suy"));
4717
+ var $R86 = $R(new RegExp("(?=[ \\t\\r\\n\\/#]|$)", "suy"));
4718
+ var $R87 = $R(new RegExp("\\r\\n|\\n|\\r|$", "suy"));
4719
4719
  var Program$0 = $TS($S(Reset, Init, $E(EOS), TopLevelStatements, __), function($skip, $loc, $0, $1, $2, $3, $4, $5) {
4720
4720
  var statements = $4;
4721
4721
  processProgram({
@@ -8405,7 +8405,7 @@ var require_parser = __commonJS({
8405
8405
  function Xnor(ctx, state) {
8406
8406
  return $EVENT_C(ctx, state, "Xnor", Xnor$$);
8407
8407
  }
8408
- var UnaryOp$0 = $TR($EXPECT($R19, "UnaryOp /(?!\\+\\+|--)[!~+-](?!\\s|[!~+-]*[&.])/"), function($skip, $loc, $0, $1, $2, $3, $4, $5, $6, $7, $8, $9) {
8408
+ var UnaryOp$0 = $TR($EXPECT($R19, "UnaryOp /(?!\\+\\+|--)[!~+-](?!\\s|[!~+-]*(&|\\.[^0-9]))/"), function($skip, $loc, $0, $1, $2, $3, $4, $5, $6, $7, $8, $9) {
8409
8409
  return { $loc, token: $0 };
8410
8410
  });
8411
8411
  var UnaryOp$1 = AwaitOp;
@@ -12422,11 +12422,11 @@ var require_parser = __commonJS({
12422
12422
  function Shebang(ctx, state) {
12423
12423
  return $EVENT(ctx, state, "Shebang", Shebang$0);
12424
12424
  }
12425
- var CivetPrologue$0 = $T($S($EXPECT($R81, "CivetPrologue /[\\t ]*/"), DoubleQuote, CivetPrologueContent, DoubleQuote, SimpleStatementDelimiter, $E(EOS)), function(value) {
12425
+ var CivetPrologue$0 = $T($S($EXPECT($R81, "CivetPrologue /[\\t ]*/"), DoubleQuote, CivetPrologueContent, DoubleQuote, SimpleStatementDelimiter, $EXPECT($R82, "CivetPrologue /[ \\t]*/"), $C(EOL, $Y(RestOfLine))), function(value) {
12426
12426
  var content = value[2];
12427
12427
  return content;
12428
12428
  });
12429
- var CivetPrologue$1 = $T($S($EXPECT($R81, "CivetPrologue /[\\t ]*/"), SingleQuote, CivetPrologueContent, SingleQuote, SimpleStatementDelimiter, $E(EOS)), function(value) {
12429
+ var CivetPrologue$1 = $T($S($EXPECT($R81, "CivetPrologue /[\\t ]*/"), SingleQuote, CivetPrologueContent, SingleQuote, SimpleStatementDelimiter, $EXPECT($R82, "CivetPrologue /[ \\t]*/"), $C(EOL, $Y(RestOfLine))), function(value) {
12430
12430
  var content = value[2];
12431
12431
  return content;
12432
12432
  });
@@ -12434,7 +12434,7 @@ var require_parser = __commonJS({
12434
12434
  function CivetPrologue(ctx, state) {
12435
12435
  return $EVENT_C(ctx, state, "CivetPrologue", CivetPrologue$$);
12436
12436
  }
12437
- var CivetPrologueContent$0 = $TS($S($EXPECT($L210, 'CivetPrologueContent "civet"'), NonIdContinue, $Q(CivetOption), $EXPECT($R82, "CivetPrologueContent /[\\s]*/")), function($skip, $loc, $0, $1, $2, $3, $4) {
12437
+ var CivetPrologueContent$0 = $TS($S($EXPECT($L210, 'CivetPrologueContent "civet"'), NonIdContinue, $Q(CivetOption), $EXPECT($R83, "CivetPrologueContent /[\\s]*/")), function($skip, $loc, $0, $1, $2, $3, $4) {
12438
12438
  var options = $3;
12439
12439
  return {
12440
12440
  type: "CivetPrologue",
@@ -12445,7 +12445,7 @@ var require_parser = __commonJS({
12445
12445
  function CivetPrologueContent(ctx, state) {
12446
12446
  return $EVENT(ctx, state, "CivetPrologueContent", CivetPrologueContent$0);
12447
12447
  }
12448
- var CivetOption$0 = $TR($EXPECT($R83, "CivetOption /\\s+([+-]?)([a-zA-Z0-9-]+)(\\s*=\\s*([a-zA-Z0-9.+-]*))?/"), function($skip, $loc, $0, $1, $2, $3, $4, $5, $6, $7, $8, $9) {
12448
+ var CivetOption$0 = $TR($EXPECT($R84, "CivetOption /\\s+([+-]?)([a-zA-Z0-9-]+)(\\s*=\\s*([a-zA-Z0-9.+-]*))?/"), function($skip, $loc, $0, $1, $2, $3, $4, $5, $6, $7, $8, $9) {
12449
12449
  const optionName = $2.replace(/-+([a-z]?)/g, (_2, l) => {
12450
12450
  if (l)
12451
12451
  return l.toUpperCase();
@@ -12466,7 +12466,7 @@ var require_parser = __commonJS({
12466
12466
  function UnknownPrologue(ctx, state) {
12467
12467
  return $EVENT(ctx, state, "UnknownPrologue", UnknownPrologue$0);
12468
12468
  }
12469
- var TripleSlashDirective$0 = $S($R$0($EXPECT($R84, "TripleSlashDirective /\\/\\/\\/[^\\r\\n]*/")), $E(EOS));
12469
+ var TripleSlashDirective$0 = $S($R$0($EXPECT($R85, "TripleSlashDirective /\\/\\/\\/[^\\r\\n]*/")), $E(EOS));
12470
12470
  function TripleSlashDirective(ctx, state) {
12471
12471
  return $EVENT(ctx, state, "TripleSlashDirective", TripleSlashDirective$0);
12472
12472
  }
@@ -12480,13 +12480,13 @@ var require_parser = __commonJS({
12480
12480
  function PrologueString(ctx, state) {
12481
12481
  return $EVENT_C(ctx, state, "PrologueString", PrologueString$$);
12482
12482
  }
12483
- var EOS$0 = $T($S($EXPECT($R85, "EOS /(?=[ \\t\\r\\n\\/#]|$)/"), $P(RestOfLine)), function(value) {
12483
+ var EOS$0 = $T($S($EXPECT($R86, "EOS /(?=[ \\t\\r\\n\\/#]|$)/"), $P(RestOfLine)), function(value) {
12484
12484
  return value[1];
12485
12485
  });
12486
12486
  function EOS(ctx, state) {
12487
12487
  return $EVENT(ctx, state, "EOS", EOS$0);
12488
12488
  }
12489
- var EOL$0 = $TR($EXPECT($R86, "EOL /\\r\\n|\\n|\\r|$/"), function($skip, $loc, $0, $1, $2, $3, $4, $5, $6, $7, $8, $9) {
12489
+ var EOL$0 = $TR($EXPECT($R87, "EOL /\\r\\n|\\n|\\r|$/"), function($skip, $loc, $0, $1, $2, $3, $4, $5, $6, $7, $8, $9) {
12490
12490
  return { $loc, token: $0 };
12491
12491
  });
12492
12492
  function EOL(ctx, state) {
@@ -12980,7 +12980,7 @@ var require_parser = __commonJS({
12980
12980
  function Init(ctx, state) {
12981
12981
  return $EVENT(ctx, state, "Init", Init$0);
12982
12982
  }
12983
- var Indent$0 = $TR($EXPECT($R87, "Indent /[ \\t]*/"), function($skip, $loc, $0, $1, $2, $3, $4, $5, $6, $7, $8, $9) {
12983
+ var Indent$0 = $TR($EXPECT($R82, "Indent /[ \\t]*/"), function($skip, $loc, $0, $1, $2, $3, $4, $5, $6, $7, $8, $9) {
12984
12984
  const level = getIndentLevel($0, module2.config.tab);
12985
12985
  return {
12986
12986
  $loc,
package/dist/main.mjs CHANGED
@@ -4645,7 +4645,7 @@ var require_parser = __commonJS({
4645
4645
  var $R16 = $R(new RegExp("(?=\\p{ID_Start}|[_$^\xAB\xBB\u22D9\u2264\u2265\u2208\u220B\u2209\u220C\u2263\u2261\u2262\u2260=\u2016\u2047&|*\\/!?%<>+-])", "suy"));
4646
4646
  var $R17 = $R(new RegExp("<(?!\\p{ID_Start}|[_$])", "suy"));
4647
4647
  var $R18 = $R(new RegExp("!\\^\\^?", "suy"));
4648
- var $R19 = $R(new RegExp("(?!\\+\\+|--)[!~+-](?!\\s|[!~+-]*[&.])", "suy"));
4648
+ var $R19 = $R(new RegExp("(?!\\+\\+|--)[!~+-](?!\\s|[!~+-]*(&|\\.[^0-9]))", "suy"));
4649
4649
  var $R20 = $R(new RegExp("(?=for|if|loop|unless|until|while)", "suy"));
4650
4650
  var $R21 = $R(new RegExp("(?=loop|do|for|until|while)", "suy"));
4651
4651
  var $R22 = $R(new RegExp("(?=[\\s\\),])", "suy"));
@@ -4708,12 +4708,12 @@ var require_parser = __commonJS({
4708
4708
  var $R79 = $R(new RegExp("[+-]", "suy"));
4709
4709
  var $R80 = $R(new RegExp("#![^\\r\\n]*", "suy"));
4710
4710
  var $R81 = $R(new RegExp("[\\t ]*", "suy"));
4711
- var $R82 = $R(new RegExp("[\\s]*", "suy"));
4712
- var $R83 = $R(new RegExp("\\s+([+-]?)([a-zA-Z0-9-]+)(\\s*=\\s*([a-zA-Z0-9.+-]*))?", "suy"));
4713
- var $R84 = $R(new RegExp("\\/\\/\\/[^\\r\\n]*", "suy"));
4714
- var $R85 = $R(new RegExp("(?=[ \\t\\r\\n\\/#]|$)", "suy"));
4715
- var $R86 = $R(new RegExp("\\r\\n|\\n|\\r|$", "suy"));
4716
- var $R87 = $R(new RegExp("[ \\t]*", "suy"));
4711
+ var $R82 = $R(new RegExp("[ \\t]*", "suy"));
4712
+ var $R83 = $R(new RegExp("[\\s]*", "suy"));
4713
+ var $R84 = $R(new RegExp("\\s+([+-]?)([a-zA-Z0-9-]+)(\\s*=\\s*([a-zA-Z0-9.+-]*))?", "suy"));
4714
+ var $R85 = $R(new RegExp("\\/\\/\\/[^\\r\\n]*", "suy"));
4715
+ var $R86 = $R(new RegExp("(?=[ \\t\\r\\n\\/#]|$)", "suy"));
4716
+ var $R87 = $R(new RegExp("\\r\\n|\\n|\\r|$", "suy"));
4717
4717
  var Program$0 = $TS($S(Reset, Init, $E(EOS), TopLevelStatements, __), function($skip, $loc, $0, $1, $2, $3, $4, $5) {
4718
4718
  var statements = $4;
4719
4719
  processProgram({
@@ -8403,7 +8403,7 @@ var require_parser = __commonJS({
8403
8403
  function Xnor(ctx, state) {
8404
8404
  return $EVENT_C(ctx, state, "Xnor", Xnor$$);
8405
8405
  }
8406
- var UnaryOp$0 = $TR($EXPECT($R19, "UnaryOp /(?!\\+\\+|--)[!~+-](?!\\s|[!~+-]*[&.])/"), function($skip, $loc, $0, $1, $2, $3, $4, $5, $6, $7, $8, $9) {
8406
+ var UnaryOp$0 = $TR($EXPECT($R19, "UnaryOp /(?!\\+\\+|--)[!~+-](?!\\s|[!~+-]*(&|\\.[^0-9]))/"), function($skip, $loc, $0, $1, $2, $3, $4, $5, $6, $7, $8, $9) {
8407
8407
  return { $loc, token: $0 };
8408
8408
  });
8409
8409
  var UnaryOp$1 = AwaitOp;
@@ -12420,11 +12420,11 @@ var require_parser = __commonJS({
12420
12420
  function Shebang(ctx, state) {
12421
12421
  return $EVENT(ctx, state, "Shebang", Shebang$0);
12422
12422
  }
12423
- var CivetPrologue$0 = $T($S($EXPECT($R81, "CivetPrologue /[\\t ]*/"), DoubleQuote, CivetPrologueContent, DoubleQuote, SimpleStatementDelimiter, $E(EOS)), function(value) {
12423
+ var CivetPrologue$0 = $T($S($EXPECT($R81, "CivetPrologue /[\\t ]*/"), DoubleQuote, CivetPrologueContent, DoubleQuote, SimpleStatementDelimiter, $EXPECT($R82, "CivetPrologue /[ \\t]*/"), $C(EOL, $Y(RestOfLine))), function(value) {
12424
12424
  var content = value[2];
12425
12425
  return content;
12426
12426
  });
12427
- var CivetPrologue$1 = $T($S($EXPECT($R81, "CivetPrologue /[\\t ]*/"), SingleQuote, CivetPrologueContent, SingleQuote, SimpleStatementDelimiter, $E(EOS)), function(value) {
12427
+ var CivetPrologue$1 = $T($S($EXPECT($R81, "CivetPrologue /[\\t ]*/"), SingleQuote, CivetPrologueContent, SingleQuote, SimpleStatementDelimiter, $EXPECT($R82, "CivetPrologue /[ \\t]*/"), $C(EOL, $Y(RestOfLine))), function(value) {
12428
12428
  var content = value[2];
12429
12429
  return content;
12430
12430
  });
@@ -12432,7 +12432,7 @@ var require_parser = __commonJS({
12432
12432
  function CivetPrologue(ctx, state) {
12433
12433
  return $EVENT_C(ctx, state, "CivetPrologue", CivetPrologue$$);
12434
12434
  }
12435
- var CivetPrologueContent$0 = $TS($S($EXPECT($L210, 'CivetPrologueContent "civet"'), NonIdContinue, $Q(CivetOption), $EXPECT($R82, "CivetPrologueContent /[\\s]*/")), function($skip, $loc, $0, $1, $2, $3, $4) {
12435
+ var CivetPrologueContent$0 = $TS($S($EXPECT($L210, 'CivetPrologueContent "civet"'), NonIdContinue, $Q(CivetOption), $EXPECT($R83, "CivetPrologueContent /[\\s]*/")), function($skip, $loc, $0, $1, $2, $3, $4) {
12436
12436
  var options = $3;
12437
12437
  return {
12438
12438
  type: "CivetPrologue",
@@ -12443,7 +12443,7 @@ var require_parser = __commonJS({
12443
12443
  function CivetPrologueContent(ctx, state) {
12444
12444
  return $EVENT(ctx, state, "CivetPrologueContent", CivetPrologueContent$0);
12445
12445
  }
12446
- var CivetOption$0 = $TR($EXPECT($R83, "CivetOption /\\s+([+-]?)([a-zA-Z0-9-]+)(\\s*=\\s*([a-zA-Z0-9.+-]*))?/"), function($skip, $loc, $0, $1, $2, $3, $4, $5, $6, $7, $8, $9) {
12446
+ var CivetOption$0 = $TR($EXPECT($R84, "CivetOption /\\s+([+-]?)([a-zA-Z0-9-]+)(\\s*=\\s*([a-zA-Z0-9.+-]*))?/"), function($skip, $loc, $0, $1, $2, $3, $4, $5, $6, $7, $8, $9) {
12447
12447
  const optionName = $2.replace(/-+([a-z]?)/g, (_2, l) => {
12448
12448
  if (l)
12449
12449
  return l.toUpperCase();
@@ -12464,7 +12464,7 @@ var require_parser = __commonJS({
12464
12464
  function UnknownPrologue(ctx, state) {
12465
12465
  return $EVENT(ctx, state, "UnknownPrologue", UnknownPrologue$0);
12466
12466
  }
12467
- var TripleSlashDirective$0 = $S($R$0($EXPECT($R84, "TripleSlashDirective /\\/\\/\\/[^\\r\\n]*/")), $E(EOS));
12467
+ var TripleSlashDirective$0 = $S($R$0($EXPECT($R85, "TripleSlashDirective /\\/\\/\\/[^\\r\\n]*/")), $E(EOS));
12468
12468
  function TripleSlashDirective(ctx, state) {
12469
12469
  return $EVENT(ctx, state, "TripleSlashDirective", TripleSlashDirective$0);
12470
12470
  }
@@ -12478,13 +12478,13 @@ var require_parser = __commonJS({
12478
12478
  function PrologueString(ctx, state) {
12479
12479
  return $EVENT_C(ctx, state, "PrologueString", PrologueString$$);
12480
12480
  }
12481
- var EOS$0 = $T($S($EXPECT($R85, "EOS /(?=[ \\t\\r\\n\\/#]|$)/"), $P(RestOfLine)), function(value) {
12481
+ var EOS$0 = $T($S($EXPECT($R86, "EOS /(?=[ \\t\\r\\n\\/#]|$)/"), $P(RestOfLine)), function(value) {
12482
12482
  return value[1];
12483
12483
  });
12484
12484
  function EOS(ctx, state) {
12485
12485
  return $EVENT(ctx, state, "EOS", EOS$0);
12486
12486
  }
12487
- var EOL$0 = $TR($EXPECT($R86, "EOL /\\r\\n|\\n|\\r|$/"), function($skip, $loc, $0, $1, $2, $3, $4, $5, $6, $7, $8, $9) {
12487
+ var EOL$0 = $TR($EXPECT($R87, "EOL /\\r\\n|\\n|\\r|$/"), function($skip, $loc, $0, $1, $2, $3, $4, $5, $6, $7, $8, $9) {
12488
12488
  return { $loc, token: $0 };
12489
12489
  });
12490
12490
  function EOL(ctx, state) {
@@ -12978,7 +12978,7 @@ var require_parser = __commonJS({
12978
12978
  function Init(ctx, state) {
12979
12979
  return $EVENT(ctx, state, "Init", Init$0);
12980
12980
  }
12981
- var Indent$0 = $TR($EXPECT($R87, "Indent /[ \\t]*/"), function($skip, $loc, $0, $1, $2, $3, $4, $5, $6, $7, $8, $9) {
12981
+ var Indent$0 = $TR($EXPECT($R82, "Indent /[ \\t]*/"), function($skip, $loc, $0, $1, $2, $3, $4, $5, $6, $7, $8, $9) {
12982
12982
  const level = getIndentLevel($0, module.config.tab);
12983
12983
  return {
12984
12984
  $loc,
package/dist/rollup.js CHANGED
@@ -48,7 +48,7 @@ var formatHost = {
48
48
  getCanonicalFileName: import_typescript.default.sys.useCaseSensitiveFileNames ? (f) => f : (f) => f.toLowerCase()
49
49
  };
50
50
  var isCivet = (id) => /\.civet$/.test(id);
51
- var isCivetTranspiled = (id) => /\.civet\.(m?)(j|t)s(x?)$/.test(id);
51
+ var isCivetTranspiled = (id) => /\.civet\.(m?)(j|t)s(x?)(\?transform)?$/.test(id);
52
52
  var isCivetTranspiledTS = (id) => /\.civet\.(m?)ts(x?)$/.test(id);
53
53
  var civetUnplugin = (0, import_unplugin.createUnplugin)((options = {}) => {
54
54
  if (options.dts && options.js) {
@@ -62,6 +62,7 @@ var civetUnplugin = (0, import_unplugin.createUnplugin)((options = {}) => {
62
62
  let fsMap = /* @__PURE__ */ new Map();
63
63
  const sourceMaps = /* @__PURE__ */ new Map();
64
64
  let compilerOptions;
65
+ let rootDir;
65
66
  return {
66
67
  name: "unplugin-civet",
67
68
  enforce: "pre",
@@ -159,12 +160,12 @@ var civetUnplugin = (0, import_unplugin.createUnplugin)((options = {}) => {
159
160
  resolveId(id, importer) {
160
161
  if (/\0/.test(id))
161
162
  return null;
162
- if (!isCivet(id))
163
+ if (!isCivet(id) && !isCivetTranspiled(id))
163
164
  return null;
164
- const relativeId = import_path.default.relative(
165
- process.cwd(),
166
- import_path.default.resolve(import_path.default.dirname(importer ?? ""), id)
167
- );
165
+ const absolutePath = rootDir != null && import_path.default.isAbsolute(id) ? import_path.default.join(rootDir, id) : import_path.default.resolve(import_path.default.dirname(importer ?? ""), id);
166
+ const relativeId = import_path.default.relative(process.cwd(), absolutePath);
167
+ if (isCivetTranspiled(id))
168
+ return relativeId.replace(/\?transform$/, "");
168
169
  const relativePath = relativeId + outExt;
169
170
  return relativePath;
170
171
  },
@@ -176,6 +177,7 @@ var civetUnplugin = (0, import_unplugin.createUnplugin)((options = {}) => {
176
177
  return null;
177
178
  const filename = import_path.default.resolve(process.cwd(), id.slice(0, -outExt.length));
178
179
  const code = await fs.promises.readFile(filename, "utf-8");
180
+ this.addWatchFile(filename);
179
181
  const compiled = import_civet.default.compile(code, {
180
182
  // inlineMap: true,
181
183
  filename: id,
@@ -211,7 +213,8 @@ var civetUnplugin = (0, import_unplugin.createUnplugin)((options = {}) => {
211
213
  return null;
212
214
  },
213
215
  vite: {
214
- config(_config, { command }) {
216
+ config(config, { command }) {
217
+ rootDir = import_path.default.resolve(process.cwd(), config.root ?? "");
215
218
  if (command === "build") {
216
219
  return {
217
220
  esbuild: {
@@ -221,6 +224,24 @@ var civetUnplugin = (0, import_unplugin.createUnplugin)((options = {}) => {
221
224
  };
222
225
  }
223
226
  return null;
227
+ },
228
+ async transformIndexHtml(html) {
229
+ return html.replace(
230
+ /<!--[^]*?-->|<[^<>]*>/g,
231
+ (tag) => tag.replace(
232
+ /<\s*script\b[^<>]*>/gi,
233
+ (script) => (
234
+ // https://html.spec.whatwg.org/multipage/syntax.html#attributes-2
235
+ script.replace(
236
+ /([:_\p{ID_Start}][:\p{ID_Continue}]*)(\s*=\s*("[^"]*"|'[^']*'|[^\s"'=<>`]*))?/gu,
237
+ (attr, name, value) => name.toLowerCase() === "src" && value ? attr.replace(
238
+ /(\.civet)(['"]?)$/,
239
+ (_, extension, endQuote) => `${extension}${outExt}?transform${endQuote}`
240
+ ) : attr
241
+ )
242
+ )
243
+ )
244
+ );
224
245
  }
225
246
  }
226
247
  };
@@ -17,7 +17,7 @@ var formatHost = {
17
17
  getCanonicalFileName: ts.sys.useCaseSensitiveFileNames ? (f) => f : (f) => f.toLowerCase()
18
18
  };
19
19
  var isCivet = (id) => /\.civet$/.test(id);
20
- var isCivetTranspiled = (id) => /\.civet\.(m?)(j|t)s(x?)$/.test(id);
20
+ var isCivetTranspiled = (id) => /\.civet\.(m?)(j|t)s(x?)(\?transform)?$/.test(id);
21
21
  var isCivetTranspiledTS = (id) => /\.civet\.(m?)ts(x?)$/.test(id);
22
22
  var civetUnplugin = createUnplugin((options = {}) => {
23
23
  if (options.dts && options.js) {
@@ -31,6 +31,7 @@ var civetUnplugin = createUnplugin((options = {}) => {
31
31
  let fsMap = /* @__PURE__ */ new Map();
32
32
  const sourceMaps = /* @__PURE__ */ new Map();
33
33
  let compilerOptions;
34
+ let rootDir;
34
35
  return {
35
36
  name: "unplugin-civet",
36
37
  enforce: "pre",
@@ -128,12 +129,12 @@ var civetUnplugin = createUnplugin((options = {}) => {
128
129
  resolveId(id, importer) {
129
130
  if (/\0/.test(id))
130
131
  return null;
131
- if (!isCivet(id))
132
+ if (!isCivet(id) && !isCivetTranspiled(id))
132
133
  return null;
133
- const relativeId = path.relative(
134
- process.cwd(),
135
- path.resolve(path.dirname(importer ?? ""), id)
136
- );
134
+ const absolutePath = rootDir != null && path.isAbsolute(id) ? path.join(rootDir, id) : path.resolve(path.dirname(importer ?? ""), id);
135
+ const relativeId = path.relative(process.cwd(), absolutePath);
136
+ if (isCivetTranspiled(id))
137
+ return relativeId.replace(/\?transform$/, "");
137
138
  const relativePath = relativeId + outExt;
138
139
  return relativePath;
139
140
  },
@@ -145,6 +146,7 @@ var civetUnplugin = createUnplugin((options = {}) => {
145
146
  return null;
146
147
  const filename = path.resolve(process.cwd(), id.slice(0, -outExt.length));
147
148
  const code = await fs.promises.readFile(filename, "utf-8");
149
+ this.addWatchFile(filename);
148
150
  const compiled = civet.compile(code, {
149
151
  // inlineMap: true,
150
152
  filename: id,
@@ -180,7 +182,8 @@ var civetUnplugin = createUnplugin((options = {}) => {
180
182
  return null;
181
183
  },
182
184
  vite: {
183
- config(_config, { command }) {
185
+ config(config, { command }) {
186
+ rootDir = path.resolve(process.cwd(), config.root ?? "");
184
187
  if (command === "build") {
185
188
  return {
186
189
  esbuild: {
@@ -190,6 +193,24 @@ var civetUnplugin = createUnplugin((options = {}) => {
190
193
  };
191
194
  }
192
195
  return null;
196
+ },
197
+ async transformIndexHtml(html) {
198
+ return html.replace(
199
+ /<!--[^]*?-->|<[^<>]*>/g,
200
+ (tag) => tag.replace(
201
+ /<\s*script\b[^<>]*>/gi,
202
+ (script) => (
203
+ // https://html.spec.whatwg.org/multipage/syntax.html#attributes-2
204
+ script.replace(
205
+ /([:_\p{ID_Start}][:\p{ID_Continue}]*)(\s*=\s*("[^"]*"|'[^']*'|[^\s"'=<>`]*))?/gu,
206
+ (attr, name, value) => name.toLowerCase() === "src" && value ? attr.replace(
207
+ /(\.civet)(['"]?)$/,
208
+ (_, extension, endQuote) => `${extension}${outExt}?transform${endQuote}`
209
+ ) : attr
210
+ )
211
+ )
212
+ )
213
+ );
193
214
  }
194
215
  }
195
216
  };
package/dist/unplugin.js CHANGED
@@ -46,7 +46,7 @@ var formatHost = {
46
46
  getCanonicalFileName: import_typescript.default.sys.useCaseSensitiveFileNames ? (f) => f : (f) => f.toLowerCase()
47
47
  };
48
48
  var isCivet = (id) => /\.civet$/.test(id);
49
- var isCivetTranspiled = (id) => /\.civet\.(m?)(j|t)s(x?)$/.test(id);
49
+ var isCivetTranspiled = (id) => /\.civet\.(m?)(j|t)s(x?)(\?transform)?$/.test(id);
50
50
  var isCivetTranspiledTS = (id) => /\.civet\.(m?)ts(x?)$/.test(id);
51
51
  var civetUnplugin = (0, import_unplugin.createUnplugin)((options = {}) => {
52
52
  if (options.dts && options.js) {
@@ -60,6 +60,7 @@ var civetUnplugin = (0, import_unplugin.createUnplugin)((options = {}) => {
60
60
  let fsMap = /* @__PURE__ */ new Map();
61
61
  const sourceMaps = /* @__PURE__ */ new Map();
62
62
  let compilerOptions;
63
+ let rootDir;
63
64
  return {
64
65
  name: "unplugin-civet",
65
66
  enforce: "pre",
@@ -157,12 +158,12 @@ var civetUnplugin = (0, import_unplugin.createUnplugin)((options = {}) => {
157
158
  resolveId(id, importer) {
158
159
  if (/\0/.test(id))
159
160
  return null;
160
- if (!isCivet(id))
161
+ if (!isCivet(id) && !isCivetTranspiled(id))
161
162
  return null;
162
- const relativeId = import_path.default.relative(
163
- process.cwd(),
164
- import_path.default.resolve(import_path.default.dirname(importer ?? ""), id)
165
- );
163
+ const absolutePath = rootDir != null && import_path.default.isAbsolute(id) ? import_path.default.join(rootDir, id) : import_path.default.resolve(import_path.default.dirname(importer ?? ""), id);
164
+ const relativeId = import_path.default.relative(process.cwd(), absolutePath);
165
+ if (isCivetTranspiled(id))
166
+ return relativeId.replace(/\?transform$/, "");
166
167
  const relativePath = relativeId + outExt;
167
168
  return relativePath;
168
169
  },
@@ -174,6 +175,7 @@ var civetUnplugin = (0, import_unplugin.createUnplugin)((options = {}) => {
174
175
  return null;
175
176
  const filename = import_path.default.resolve(process.cwd(), id.slice(0, -outExt.length));
176
177
  const code = await fs.promises.readFile(filename, "utf-8");
178
+ this.addWatchFile(filename);
177
179
  const compiled = import_civet.default.compile(code, {
178
180
  // inlineMap: true,
179
181
  filename: id,
@@ -209,7 +211,8 @@ var civetUnplugin = (0, import_unplugin.createUnplugin)((options = {}) => {
209
211
  return null;
210
212
  },
211
213
  vite: {
212
- config(_config, { command }) {
214
+ config(config, { command }) {
215
+ rootDir = import_path.default.resolve(process.cwd(), config.root ?? "");
213
216
  if (command === "build") {
214
217
  return {
215
218
  esbuild: {
@@ -219,6 +222,24 @@ var civetUnplugin = (0, import_unplugin.createUnplugin)((options = {}) => {
219
222
  };
220
223
  }
221
224
  return null;
225
+ },
226
+ async transformIndexHtml(html) {
227
+ return html.replace(
228
+ /<!--[^]*?-->|<[^<>]*>/g,
229
+ (tag) => tag.replace(
230
+ /<\s*script\b[^<>]*>/gi,
231
+ (script) => (
232
+ // https://html.spec.whatwg.org/multipage/syntax.html#attributes-2
233
+ script.replace(
234
+ /([:_\p{ID_Start}][:\p{ID_Continue}]*)(\s*=\s*("[^"]*"|'[^']*'|[^\s"'=<>`]*))?/gu,
235
+ (attr, name, value) => name.toLowerCase() === "src" && value ? attr.replace(
236
+ /(\.civet)(['"]?)$/,
237
+ (_, extension, endQuote) => `${extension}${outExt}?transform${endQuote}`
238
+ ) : attr
239
+ )
240
+ )
241
+ )
242
+ );
222
243
  }
223
244
  }
224
245
  };
package/dist/vite.js CHANGED
@@ -48,7 +48,7 @@ var formatHost = {
48
48
  getCanonicalFileName: import_typescript.default.sys.useCaseSensitiveFileNames ? (f) => f : (f) => f.toLowerCase()
49
49
  };
50
50
  var isCivet = (id) => /\.civet$/.test(id);
51
- var isCivetTranspiled = (id) => /\.civet\.(m?)(j|t)s(x?)$/.test(id);
51
+ var isCivetTranspiled = (id) => /\.civet\.(m?)(j|t)s(x?)(\?transform)?$/.test(id);
52
52
  var isCivetTranspiledTS = (id) => /\.civet\.(m?)ts(x?)$/.test(id);
53
53
  var civetUnplugin = (0, import_unplugin.createUnplugin)((options = {}) => {
54
54
  if (options.dts && options.js) {
@@ -62,6 +62,7 @@ var civetUnplugin = (0, import_unplugin.createUnplugin)((options = {}) => {
62
62
  let fsMap = /* @__PURE__ */ new Map();
63
63
  const sourceMaps = /* @__PURE__ */ new Map();
64
64
  let compilerOptions;
65
+ let rootDir;
65
66
  return {
66
67
  name: "unplugin-civet",
67
68
  enforce: "pre",
@@ -159,12 +160,12 @@ var civetUnplugin = (0, import_unplugin.createUnplugin)((options = {}) => {
159
160
  resolveId(id, importer) {
160
161
  if (/\0/.test(id))
161
162
  return null;
162
- if (!isCivet(id))
163
+ if (!isCivet(id) && !isCivetTranspiled(id))
163
164
  return null;
164
- const relativeId = import_path.default.relative(
165
- process.cwd(),
166
- import_path.default.resolve(import_path.default.dirname(importer ?? ""), id)
167
- );
165
+ const absolutePath = rootDir != null && import_path.default.isAbsolute(id) ? import_path.default.join(rootDir, id) : import_path.default.resolve(import_path.default.dirname(importer ?? ""), id);
166
+ const relativeId = import_path.default.relative(process.cwd(), absolutePath);
167
+ if (isCivetTranspiled(id))
168
+ return relativeId.replace(/\?transform$/, "");
168
169
  const relativePath = relativeId + outExt;
169
170
  return relativePath;
170
171
  },
@@ -176,6 +177,7 @@ var civetUnplugin = (0, import_unplugin.createUnplugin)((options = {}) => {
176
177
  return null;
177
178
  const filename = import_path.default.resolve(process.cwd(), id.slice(0, -outExt.length));
178
179
  const code = await fs.promises.readFile(filename, "utf-8");
180
+ this.addWatchFile(filename);
179
181
  const compiled = import_civet.default.compile(code, {
180
182
  // inlineMap: true,
181
183
  filename: id,
@@ -211,7 +213,8 @@ var civetUnplugin = (0, import_unplugin.createUnplugin)((options = {}) => {
211
213
  return null;
212
214
  },
213
215
  vite: {
214
- config(_config, { command }) {
216
+ config(config, { command }) {
217
+ rootDir = import_path.default.resolve(process.cwd(), config.root ?? "");
215
218
  if (command === "build") {
216
219
  return {
217
220
  esbuild: {
@@ -221,6 +224,24 @@ var civetUnplugin = (0, import_unplugin.createUnplugin)((options = {}) => {
221
224
  };
222
225
  }
223
226
  return null;
227
+ },
228
+ async transformIndexHtml(html) {
229
+ return html.replace(
230
+ /<!--[^]*?-->|<[^<>]*>/g,
231
+ (tag) => tag.replace(
232
+ /<\s*script\b[^<>]*>/gi,
233
+ (script) => (
234
+ // https://html.spec.whatwg.org/multipage/syntax.html#attributes-2
235
+ script.replace(
236
+ /([:_\p{ID_Start}][:\p{ID_Continue}]*)(\s*=\s*("[^"]*"|'[^']*'|[^\s"'=<>`]*))?/gu,
237
+ (attr, name, value) => name.toLowerCase() === "src" && value ? attr.replace(
238
+ /(\.civet)(['"]?)$/,
239
+ (_, extension, endQuote) => `${extension}${outExt}?transform${endQuote}`
240
+ ) : attr
241
+ )
242
+ )
243
+ )
244
+ );
224
245
  }
225
246
  }
226
247
  };
package/dist/webpack.js CHANGED
@@ -48,7 +48,7 @@ var formatHost = {
48
48
  getCanonicalFileName: import_typescript.default.sys.useCaseSensitiveFileNames ? (f) => f : (f) => f.toLowerCase()
49
49
  };
50
50
  var isCivet = (id) => /\.civet$/.test(id);
51
- var isCivetTranspiled = (id) => /\.civet\.(m?)(j|t)s(x?)$/.test(id);
51
+ var isCivetTranspiled = (id) => /\.civet\.(m?)(j|t)s(x?)(\?transform)?$/.test(id);
52
52
  var isCivetTranspiledTS = (id) => /\.civet\.(m?)ts(x?)$/.test(id);
53
53
  var civetUnplugin = (0, import_unplugin.createUnplugin)((options = {}) => {
54
54
  if (options.dts && options.js) {
@@ -62,6 +62,7 @@ var civetUnplugin = (0, import_unplugin.createUnplugin)((options = {}) => {
62
62
  let fsMap = /* @__PURE__ */ new Map();
63
63
  const sourceMaps = /* @__PURE__ */ new Map();
64
64
  let compilerOptions;
65
+ let rootDir;
65
66
  return {
66
67
  name: "unplugin-civet",
67
68
  enforce: "pre",
@@ -159,12 +160,12 @@ var civetUnplugin = (0, import_unplugin.createUnplugin)((options = {}) => {
159
160
  resolveId(id, importer) {
160
161
  if (/\0/.test(id))
161
162
  return null;
162
- if (!isCivet(id))
163
+ if (!isCivet(id) && !isCivetTranspiled(id))
163
164
  return null;
164
- const relativeId = import_path.default.relative(
165
- process.cwd(),
166
- import_path.default.resolve(import_path.default.dirname(importer ?? ""), id)
167
- );
165
+ const absolutePath = rootDir != null && import_path.default.isAbsolute(id) ? import_path.default.join(rootDir, id) : import_path.default.resolve(import_path.default.dirname(importer ?? ""), id);
166
+ const relativeId = import_path.default.relative(process.cwd(), absolutePath);
167
+ if (isCivetTranspiled(id))
168
+ return relativeId.replace(/\?transform$/, "");
168
169
  const relativePath = relativeId + outExt;
169
170
  return relativePath;
170
171
  },
@@ -176,6 +177,7 @@ var civetUnplugin = (0, import_unplugin.createUnplugin)((options = {}) => {
176
177
  return null;
177
178
  const filename = import_path.default.resolve(process.cwd(), id.slice(0, -outExt.length));
178
179
  const code = await fs.promises.readFile(filename, "utf-8");
180
+ this.addWatchFile(filename);
179
181
  const compiled = import_civet.default.compile(code, {
180
182
  // inlineMap: true,
181
183
  filename: id,
@@ -211,7 +213,8 @@ var civetUnplugin = (0, import_unplugin.createUnplugin)((options = {}) => {
211
213
  return null;
212
214
  },
213
215
  vite: {
214
- config(_config, { command }) {
216
+ config(config, { command }) {
217
+ rootDir = import_path.default.resolve(process.cwd(), config.root ?? "");
215
218
  if (command === "build") {
216
219
  return {
217
220
  esbuild: {
@@ -221,6 +224,24 @@ var civetUnplugin = (0, import_unplugin.createUnplugin)((options = {}) => {
221
224
  };
222
225
  }
223
226
  return null;
227
+ },
228
+ async transformIndexHtml(html) {
229
+ return html.replace(
230
+ /<!--[^]*?-->|<[^<>]*>/g,
231
+ (tag) => tag.replace(
232
+ /<\s*script\b[^<>]*>/gi,
233
+ (script) => (
234
+ // https://html.spec.whatwg.org/multipage/syntax.html#attributes-2
235
+ script.replace(
236
+ /([:_\p{ID_Start}][:\p{ID_Continue}]*)(\s*=\s*("[^"]*"|'[^']*'|[^\s"'=<>`]*))?/gu,
237
+ (attr, name, value) => name.toLowerCase() === "src" && value ? attr.replace(
238
+ /(\.civet)(['"]?)$/,
239
+ (_, extension, endQuote) => `${extension}${outExt}?transform${endQuote}`
240
+ ) : attr
241
+ )
242
+ )
243
+ )
244
+ );
224
245
  }
225
246
  }
226
247
  };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@danielx/civet",
3
3
  "type": "commonjs",
4
- "version": "0.6.46",
4
+ "version": "0.6.48",
5
5
  "description": "CoffeeScript style syntax for TypeScript",
6
6
  "main": "dist/main.js",
7
7
  "module": "dist/main.mjs",