@danielx/civet 0.6.79 → 0.6.80

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
@@ -2411,9 +2411,16 @@ var Civet = (() => {
2411
2411
  const { decl, bindings } = condition.declaration;
2412
2412
  const binding = bindings[0];
2413
2413
  const { pattern, suffix, initializer, splices, thisAssignments } = binding;
2414
+ const grandparent = condition.parent?.parent;
2415
+ const children = (
2416
+ // Check that the declaration is a plain assignment (no pattern-matching) and the immediate grandchild of an `if` or `while`
2417
+ // More complex conditions (triggered by pattern matching or `until`/`unless`) don't need double parens
2418
+ // @ts-ignore Just because pattern might not have a type at runtime doesn't mean it's unsafe
2419
+ pattern.type === "Identifier" && (grandparent?.type === "IfStatement" || grandparent?.type === "WhileStatement") ? ["(", ref, initializer, ")"] : [ref, initializer]
2420
+ );
2414
2421
  Object.assign(condition, {
2415
2422
  type: "AssignmentExpression",
2416
- children: [ref, initializer],
2423
+ children,
2417
2424
  hoistDec: {
2418
2425
  type: "Declaration",
2419
2426
  children: ["let ", ref, suffix],
@@ -2887,7 +2894,13 @@ var Civet = (() => {
2887
2894
  };
2888
2895
  }
2889
2896
  function modifyString(str) {
2890
- return str.replace(/(^.?|[^\\]{2})(\\\\)*\n/g, "$1$2\\n");
2897
+ return str.replace(/((?:\\.|[^\r\n])*)(\r\n|\n|\r)?/gsu, function(_, chars, nl) {
2898
+ if (nl) {
2899
+ return chars + "\\n";
2900
+ } else {
2901
+ return chars;
2902
+ }
2903
+ });
2891
2904
  }
2892
2905
  function quoteString(str) {
2893
2906
  str = str.replace(/\\/g, "\\\\");
package/dist/esbuild.js CHANGED
@@ -42,7 +42,7 @@ 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 isCivetTranspiled = (id) => /\.civet\.[jt]sx([?#].*)?$/.test(id);
45
+ var isCivetTranspiled = /(\.civet)(\.[jt]sx)([?#].*)?$/;
46
46
  var postfixRE = /[?#].*$/s;
47
47
  var isWindows = import_os.default.platform() === "win32";
48
48
  var windowsSlashRE = /\\/g;
@@ -126,7 +126,8 @@ var rawPlugin = (options = {}, meta) => {
126
126
  );
127
127
  compilerOptions = {
128
128
  ...configContents.options,
129
- target: ts.ScriptTarget.ESNext
129
+ target: ts.ScriptTarget.ESNext,
130
+ composite: false
130
131
  };
131
132
  compilerOptions.jsx ?? (compilerOptions.jsx = "preserve");
132
133
  compilerOptionsWithSourceMap = {
@@ -140,6 +141,30 @@ var rawPlugin = (options = {}, meta) => {
140
141
  if (transformTS) {
141
142
  const ts = await tsPromise;
142
143
  const system = tsvfs.createFSBackedSystem(fsMap, process.cwd(), ts);
144
+ const { fileExists: systemFileExists, readFile: systemReadFile } = system;
145
+ system.fileExists = (filename) => {
146
+ if (!filename.endsWith(".civet.tsx"))
147
+ return systemFileExists(filename);
148
+ if (fsMap.has(filename))
149
+ return true;
150
+ return systemFileExists(filename.slice(0, -4));
151
+ };
152
+ system.readFile = (filename, encoding = "utf-8") => {
153
+ if (!filename.endsWith(".civet.tsx"))
154
+ return systemReadFile(filename);
155
+ if (fsMap.has(filename))
156
+ return fsMap.get(filename);
157
+ const civetFilename = filename.slice(0, -4);
158
+ const rawCivetSource = fs.readFileSync(civetFilename, {
159
+ encoding
160
+ });
161
+ const compiledTS = import_civet.default.compile(rawCivetSource, {
162
+ filename,
163
+ js: false
164
+ });
165
+ fsMap.set(filename, compiledTS);
166
+ return compiledTS;
167
+ };
143
168
  const host = tsvfs.createVirtualCompilerHost(
144
169
  system,
145
170
  compilerOptions,
@@ -253,12 +278,14 @@ var rawPlugin = (options = {}, meta) => {
253
278
  return resolvedId + outExt;
254
279
  },
255
280
  loadInclude(id) {
256
- return isCivetTranspiled(id);
281
+ return isCivetTranspiled.test(id);
257
282
  },
258
283
  async load(id) {
259
- if (!isCivetTranspiled(id))
284
+ const match = isCivetTranspiled.exec(id);
285
+ if (!match)
260
286
  return null;
261
- const filename = import_path.default.resolve(rootDir, id.slice(0, -outExt.length));
287
+ const basename = id.slice(0, match.index + match[1].length);
288
+ const filename = import_path.default.resolve(rootDir, basename);
262
289
  const rawCivetSource = await fs.promises.readFile(filename, "utf-8");
263
290
  this.addWatchFile(filename);
264
291
  let compiled;
@@ -349,11 +376,25 @@ var rawPlugin = (options = {}, meta) => {
349
376
  },
350
377
  vite: {
351
378
  config(config) {
352
- var _a;
379
+ var _a, _b, _c;
353
380
  rootDir = import_path.default.resolve(process.cwd(), config.root ?? "");
381
+ config.optimizeDeps ?? (config.optimizeDeps = {});
382
+ (_a = config.optimizeDeps).esbuildOptions ?? (_a.esbuildOptions = {});
383
+ (_b = config.optimizeDeps.esbuildOptions).plugins ?? (_b.plugins = []);
384
+ config.optimizeDeps.esbuildOptions.plugins.push(
385
+ // @ts-ignore esbuild types from Vite might not match our esbuild
386
+ unplugin.esbuild({
387
+ ...options,
388
+ js: void 0,
389
+ ts: "preserve",
390
+ dts: void 0,
391
+ emitDeclaration: false,
392
+ typecheck: false
393
+ })
394
+ );
354
395
  if (implicitExtension) {
355
396
  config.resolve ?? (config.resolve = {});
356
- (_a = config.resolve).extensions ?? (_a.extensions = []);
397
+ (_c = config.resolve).extensions ?? (_c.extensions = []);
357
398
  config.resolve.extensions.push(".civet");
358
399
  }
359
400
  },
@@ -389,7 +430,8 @@ var rawPlugin = (options = {}, meta) => {
389
430
  }
390
431
  };
391
432
  };
392
- var src_default = (0, import_unplugin.createUnplugin)(rawPlugin);
433
+ var unplugin = (0, import_unplugin.createUnplugin)(rawPlugin);
434
+ var src_default = unplugin;
393
435
 
394
436
  // src/esbuild.ts
395
437
  var esbuild_default = src_default.esbuild;
package/dist/main.js CHANGED
@@ -2403,9 +2403,16 @@ function processDeclarationCondition(condition, rootCondition, parent) {
2403
2403
  const { decl, bindings } = condition.declaration;
2404
2404
  const binding = bindings[0];
2405
2405
  const { pattern, suffix, initializer, splices, thisAssignments } = binding;
2406
+ const grandparent = condition.parent?.parent;
2407
+ const children = (
2408
+ // Check that the declaration is a plain assignment (no pattern-matching) and the immediate grandchild of an `if` or `while`
2409
+ // More complex conditions (triggered by pattern matching or `until`/`unless`) don't need double parens
2410
+ // @ts-ignore Just because pattern might not have a type at runtime doesn't mean it's unsafe
2411
+ pattern.type === "Identifier" && (grandparent?.type === "IfStatement" || grandparent?.type === "WhileStatement") ? ["(", ref, initializer, ")"] : [ref, initializer]
2412
+ );
2406
2413
  Object.assign(condition, {
2407
2414
  type: "AssignmentExpression",
2408
- children: [ref, initializer],
2415
+ children,
2409
2416
  hoistDec: {
2410
2417
  type: "Declaration",
2411
2418
  children: ["let ", ref, suffix],
@@ -2879,7 +2886,13 @@ function processCoffeeInterpolation(s, parts, e, $loc) {
2879
2886
  };
2880
2887
  }
2881
2888
  function modifyString(str) {
2882
- return str.replace(/(^.?|[^\\]{2})(\\\\)*\n/g, "$1$2\\n");
2889
+ return str.replace(/((?:\\.|[^\r\n])*)(\r\n|\n|\r)?/gsu, function(_, chars, nl) {
2890
+ if (nl) {
2891
+ return chars + "\\n";
2892
+ } else {
2893
+ return chars;
2894
+ }
2895
+ });
2883
2896
  }
2884
2897
  function quoteString(str) {
2885
2898
  str = str.replace(/\\/g, "\\\\");
package/dist/main.mjs CHANGED
@@ -2401,9 +2401,16 @@ function processDeclarationCondition(condition, rootCondition, parent) {
2401
2401
  const { decl, bindings } = condition.declaration;
2402
2402
  const binding = bindings[0];
2403
2403
  const { pattern, suffix, initializer, splices, thisAssignments } = binding;
2404
+ const grandparent = condition.parent?.parent;
2405
+ const children = (
2406
+ // Check that the declaration is a plain assignment (no pattern-matching) and the immediate grandchild of an `if` or `while`
2407
+ // More complex conditions (triggered by pattern matching or `until`/`unless`) don't need double parens
2408
+ // @ts-ignore Just because pattern might not have a type at runtime doesn't mean it's unsafe
2409
+ pattern.type === "Identifier" && (grandparent?.type === "IfStatement" || grandparent?.type === "WhileStatement") ? ["(", ref, initializer, ")"] : [ref, initializer]
2410
+ );
2404
2411
  Object.assign(condition, {
2405
2412
  type: "AssignmentExpression",
2406
- children: [ref, initializer],
2413
+ children,
2407
2414
  hoistDec: {
2408
2415
  type: "Declaration",
2409
2416
  children: ["let ", ref, suffix],
@@ -2877,7 +2884,13 @@ function processCoffeeInterpolation(s, parts, e, $loc) {
2877
2884
  };
2878
2885
  }
2879
2886
  function modifyString(str) {
2880
- return str.replace(/(^.?|[^\\]{2})(\\\\)*\n/g, "$1$2\\n");
2887
+ return str.replace(/((?:\\.|[^\r\n])*)(\r\n|\n|\r)?/gsu, function(_, chars, nl) {
2888
+ if (nl) {
2889
+ return chars + "\\n";
2890
+ } else {
2891
+ return chars;
2892
+ }
2893
+ });
2881
2894
  }
2882
2895
  function quoteString(str) {
2883
2896
  str = str.replace(/\\/g, "\\\\");
package/dist/rollup.js CHANGED
@@ -42,7 +42,7 @@ 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 isCivetTranspiled = (id) => /\.civet\.[jt]sx([?#].*)?$/.test(id);
45
+ var isCivetTranspiled = /(\.civet)(\.[jt]sx)([?#].*)?$/;
46
46
  var postfixRE = /[?#].*$/s;
47
47
  var isWindows = import_os.default.platform() === "win32";
48
48
  var windowsSlashRE = /\\/g;
@@ -126,7 +126,8 @@ var rawPlugin = (options = {}, meta) => {
126
126
  );
127
127
  compilerOptions = {
128
128
  ...configContents.options,
129
- target: ts.ScriptTarget.ESNext
129
+ target: ts.ScriptTarget.ESNext,
130
+ composite: false
130
131
  };
131
132
  compilerOptions.jsx ?? (compilerOptions.jsx = "preserve");
132
133
  compilerOptionsWithSourceMap = {
@@ -140,6 +141,30 @@ var rawPlugin = (options = {}, meta) => {
140
141
  if (transformTS) {
141
142
  const ts = await tsPromise;
142
143
  const system = tsvfs.createFSBackedSystem(fsMap, process.cwd(), ts);
144
+ const { fileExists: systemFileExists, readFile: systemReadFile } = system;
145
+ system.fileExists = (filename) => {
146
+ if (!filename.endsWith(".civet.tsx"))
147
+ return systemFileExists(filename);
148
+ if (fsMap.has(filename))
149
+ return true;
150
+ return systemFileExists(filename.slice(0, -4));
151
+ };
152
+ system.readFile = (filename, encoding = "utf-8") => {
153
+ if (!filename.endsWith(".civet.tsx"))
154
+ return systemReadFile(filename);
155
+ if (fsMap.has(filename))
156
+ return fsMap.get(filename);
157
+ const civetFilename = filename.slice(0, -4);
158
+ const rawCivetSource = fs.readFileSync(civetFilename, {
159
+ encoding
160
+ });
161
+ const compiledTS = import_civet.default.compile(rawCivetSource, {
162
+ filename,
163
+ js: false
164
+ });
165
+ fsMap.set(filename, compiledTS);
166
+ return compiledTS;
167
+ };
143
168
  const host = tsvfs.createVirtualCompilerHost(
144
169
  system,
145
170
  compilerOptions,
@@ -253,12 +278,14 @@ var rawPlugin = (options = {}, meta) => {
253
278
  return resolvedId + outExt;
254
279
  },
255
280
  loadInclude(id) {
256
- return isCivetTranspiled(id);
281
+ return isCivetTranspiled.test(id);
257
282
  },
258
283
  async load(id) {
259
- if (!isCivetTranspiled(id))
284
+ const match = isCivetTranspiled.exec(id);
285
+ if (!match)
260
286
  return null;
261
- const filename = import_path.default.resolve(rootDir, id.slice(0, -outExt.length));
287
+ const basename = id.slice(0, match.index + match[1].length);
288
+ const filename = import_path.default.resolve(rootDir, basename);
262
289
  const rawCivetSource = await fs.promises.readFile(filename, "utf-8");
263
290
  this.addWatchFile(filename);
264
291
  let compiled;
@@ -349,11 +376,25 @@ var rawPlugin = (options = {}, meta) => {
349
376
  },
350
377
  vite: {
351
378
  config(config) {
352
- var _a;
379
+ var _a, _b, _c;
353
380
  rootDir = import_path.default.resolve(process.cwd(), config.root ?? "");
381
+ config.optimizeDeps ?? (config.optimizeDeps = {});
382
+ (_a = config.optimizeDeps).esbuildOptions ?? (_a.esbuildOptions = {});
383
+ (_b = config.optimizeDeps.esbuildOptions).plugins ?? (_b.plugins = []);
384
+ config.optimizeDeps.esbuildOptions.plugins.push(
385
+ // @ts-ignore esbuild types from Vite might not match our esbuild
386
+ unplugin.esbuild({
387
+ ...options,
388
+ js: void 0,
389
+ ts: "preserve",
390
+ dts: void 0,
391
+ emitDeclaration: false,
392
+ typecheck: false
393
+ })
394
+ );
354
395
  if (implicitExtension) {
355
396
  config.resolve ?? (config.resolve = {});
356
- (_a = config.resolve).extensions ?? (_a.extensions = []);
397
+ (_c = config.resolve).extensions ?? (_c.extensions = []);
357
398
  config.resolve.extensions.push(".civet");
358
399
  }
359
400
  },
@@ -389,7 +430,8 @@ var rawPlugin = (options = {}, meta) => {
389
430
  }
390
431
  };
391
432
  };
392
- var src_default = (0, import_unplugin.createUnplugin)(rawPlugin);
433
+ var unplugin = (0, import_unplugin.createUnplugin)(rawPlugin);
434
+ var src_default = unplugin;
393
435
 
394
436
  // src/rollup.ts
395
437
  var rollup_default = src_default.rollup;
@@ -9,7 +9,7 @@ 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 isCivetTranspiled = (id) => /\.civet\.[jt]sx([?#].*)?$/.test(id);
12
+ var isCivetTranspiled = /(\.civet)(\.[jt]sx)([?#].*)?$/;
13
13
  var postfixRE = /[?#].*$/s;
14
14
  var isWindows = os.platform() === "win32";
15
15
  var windowsSlashRE = /\\/g;
@@ -93,7 +93,8 @@ var rawPlugin = (options = {}, meta) => {
93
93
  );
94
94
  compilerOptions = {
95
95
  ...configContents.options,
96
- target: ts.ScriptTarget.ESNext
96
+ target: ts.ScriptTarget.ESNext,
97
+ composite: false
97
98
  };
98
99
  compilerOptions.jsx ?? (compilerOptions.jsx = "preserve");
99
100
  compilerOptionsWithSourceMap = {
@@ -107,6 +108,30 @@ var rawPlugin = (options = {}, meta) => {
107
108
  if (transformTS) {
108
109
  const ts = await tsPromise;
109
110
  const system = tsvfs.createFSBackedSystem(fsMap, process.cwd(), ts);
111
+ const { fileExists: systemFileExists, readFile: systemReadFile } = system;
112
+ system.fileExists = (filename) => {
113
+ if (!filename.endsWith(".civet.tsx"))
114
+ return systemFileExists(filename);
115
+ if (fsMap.has(filename))
116
+ return true;
117
+ return systemFileExists(filename.slice(0, -4));
118
+ };
119
+ system.readFile = (filename, encoding = "utf-8") => {
120
+ if (!filename.endsWith(".civet.tsx"))
121
+ return systemReadFile(filename);
122
+ if (fsMap.has(filename))
123
+ return fsMap.get(filename);
124
+ const civetFilename = filename.slice(0, -4);
125
+ const rawCivetSource = fs.readFileSync(civetFilename, {
126
+ encoding
127
+ });
128
+ const compiledTS = civet.compile(rawCivetSource, {
129
+ filename,
130
+ js: false
131
+ });
132
+ fsMap.set(filename, compiledTS);
133
+ return compiledTS;
134
+ };
110
135
  const host = tsvfs.createVirtualCompilerHost(
111
136
  system,
112
137
  compilerOptions,
@@ -220,12 +245,14 @@ var rawPlugin = (options = {}, meta) => {
220
245
  return resolvedId + outExt;
221
246
  },
222
247
  loadInclude(id) {
223
- return isCivetTranspiled(id);
248
+ return isCivetTranspiled.test(id);
224
249
  },
225
250
  async load(id) {
226
- if (!isCivetTranspiled(id))
251
+ const match = isCivetTranspiled.exec(id);
252
+ if (!match)
227
253
  return null;
228
- const filename = path.resolve(rootDir, id.slice(0, -outExt.length));
254
+ const basename = id.slice(0, match.index + match[1].length);
255
+ const filename = path.resolve(rootDir, basename);
229
256
  const rawCivetSource = await fs.promises.readFile(filename, "utf-8");
230
257
  this.addWatchFile(filename);
231
258
  let compiled;
@@ -316,11 +343,25 @@ var rawPlugin = (options = {}, meta) => {
316
343
  },
317
344
  vite: {
318
345
  config(config) {
319
- var _a;
346
+ var _a, _b, _c;
320
347
  rootDir = path.resolve(process.cwd(), config.root ?? "");
348
+ config.optimizeDeps ?? (config.optimizeDeps = {});
349
+ (_a = config.optimizeDeps).esbuildOptions ?? (_a.esbuildOptions = {});
350
+ (_b = config.optimizeDeps.esbuildOptions).plugins ?? (_b.plugins = []);
351
+ config.optimizeDeps.esbuildOptions.plugins.push(
352
+ // @ts-ignore esbuild types from Vite might not match our esbuild
353
+ unplugin.esbuild({
354
+ ...options,
355
+ js: void 0,
356
+ ts: "preserve",
357
+ dts: void 0,
358
+ emitDeclaration: false,
359
+ typecheck: false
360
+ })
361
+ );
321
362
  if (implicitExtension) {
322
363
  config.resolve ?? (config.resolve = {});
323
- (_a = config.resolve).extensions ?? (_a.extensions = []);
364
+ (_c = config.resolve).extensions ?? (_c.extensions = []);
324
365
  config.resolve.extensions.push(".civet");
325
366
  }
326
367
  },
@@ -356,7 +397,8 @@ var rawPlugin = (options = {}, meta) => {
356
397
  }
357
398
  };
358
399
  };
359
- var src_default = createUnplugin(rawPlugin);
400
+ var unplugin = createUnplugin(rawPlugin);
401
+ var src_default = unplugin;
360
402
 
361
403
  export {
362
404
  slash,
@@ -1,4 +1,4 @@
1
- import * as unplugin from 'unplugin';
1
+ import * as _unplugin from 'unplugin';
2
2
  import { TransformResult, createUnplugin } from 'unplugin';
3
3
 
4
4
  type PluginOptions = {
@@ -15,6 +15,6 @@ type PluginOptions = {
15
15
  };
16
16
  declare function slash(p: string): string;
17
17
  declare const rawPlugin: Parameters<typeof createUnplugin<PluginOptions>>[0];
18
- declare const _default: unplugin.UnpluginInstance<PluginOptions, boolean>;
18
+ declare var unplugin: _unplugin.UnpluginInstance<PluginOptions, boolean>;
19
19
 
20
- export { PluginOptions, _default as default, rawPlugin, slash };
20
+ export { PluginOptions, unplugin as default, rawPlugin, slash };
@@ -1,4 +1,4 @@
1
- import * as unplugin from 'unplugin';
1
+ import * as _unplugin from 'unplugin';
2
2
  import { TransformResult, createUnplugin } from 'unplugin';
3
3
 
4
4
  type PluginOptions = {
@@ -15,6 +15,6 @@ type PluginOptions = {
15
15
  };
16
16
  declare function slash(p: string): string;
17
17
  declare const rawPlugin: Parameters<typeof createUnplugin<PluginOptions>>[0];
18
- declare const _default: unplugin.UnpluginInstance<PluginOptions, boolean>;
18
+ declare var unplugin: _unplugin.UnpluginInstance<PluginOptions, boolean>;
19
19
 
20
- export { PluginOptions, _default as default, rawPlugin, slash };
20
+ export { PluginOptions, unplugin as default, rawPlugin, slash };
package/dist/unplugin.js CHANGED
@@ -42,7 +42,7 @@ 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 isCivetTranspiled = (id) => /\.civet\.[jt]sx([?#].*)?$/.test(id);
45
+ var isCivetTranspiled = /(\.civet)(\.[jt]sx)([?#].*)?$/;
46
46
  var postfixRE = /[?#].*$/s;
47
47
  var isWindows = import_os.default.platform() === "win32";
48
48
  var windowsSlashRE = /\\/g;
@@ -126,7 +126,8 @@ var rawPlugin = (options = {}, meta) => {
126
126
  );
127
127
  compilerOptions = {
128
128
  ...configContents.options,
129
- target: ts.ScriptTarget.ESNext
129
+ target: ts.ScriptTarget.ESNext,
130
+ composite: false
130
131
  };
131
132
  compilerOptions.jsx ?? (compilerOptions.jsx = "preserve");
132
133
  compilerOptionsWithSourceMap = {
@@ -140,6 +141,30 @@ var rawPlugin = (options = {}, meta) => {
140
141
  if (transformTS) {
141
142
  const ts = await tsPromise;
142
143
  const system = tsvfs.createFSBackedSystem(fsMap, process.cwd(), ts);
144
+ const { fileExists: systemFileExists, readFile: systemReadFile } = system;
145
+ system.fileExists = (filename) => {
146
+ if (!filename.endsWith(".civet.tsx"))
147
+ return systemFileExists(filename);
148
+ if (fsMap.has(filename))
149
+ return true;
150
+ return systemFileExists(filename.slice(0, -4));
151
+ };
152
+ system.readFile = (filename, encoding = "utf-8") => {
153
+ if (!filename.endsWith(".civet.tsx"))
154
+ return systemReadFile(filename);
155
+ if (fsMap.has(filename))
156
+ return fsMap.get(filename);
157
+ const civetFilename = filename.slice(0, -4);
158
+ const rawCivetSource = fs.readFileSync(civetFilename, {
159
+ encoding
160
+ });
161
+ const compiledTS = import_civet.default.compile(rawCivetSource, {
162
+ filename,
163
+ js: false
164
+ });
165
+ fsMap.set(filename, compiledTS);
166
+ return compiledTS;
167
+ };
143
168
  const host = tsvfs.createVirtualCompilerHost(
144
169
  system,
145
170
  compilerOptions,
@@ -253,12 +278,14 @@ var rawPlugin = (options = {}, meta) => {
253
278
  return resolvedId + outExt;
254
279
  },
255
280
  loadInclude(id) {
256
- return isCivetTranspiled(id);
281
+ return isCivetTranspiled.test(id);
257
282
  },
258
283
  async load(id) {
259
- if (!isCivetTranspiled(id))
284
+ const match = isCivetTranspiled.exec(id);
285
+ if (!match)
260
286
  return null;
261
- const filename = import_path.default.resolve(rootDir, id.slice(0, -outExt.length));
287
+ const basename = id.slice(0, match.index + match[1].length);
288
+ const filename = import_path.default.resolve(rootDir, basename);
262
289
  const rawCivetSource = await fs.promises.readFile(filename, "utf-8");
263
290
  this.addWatchFile(filename);
264
291
  let compiled;
@@ -349,11 +376,25 @@ var rawPlugin = (options = {}, meta) => {
349
376
  },
350
377
  vite: {
351
378
  config(config) {
352
- var _a;
379
+ var _a, _b, _c;
353
380
  rootDir = import_path.default.resolve(process.cwd(), config.root ?? "");
381
+ config.optimizeDeps ?? (config.optimizeDeps = {});
382
+ (_a = config.optimizeDeps).esbuildOptions ?? (_a.esbuildOptions = {});
383
+ (_b = config.optimizeDeps.esbuildOptions).plugins ?? (_b.plugins = []);
384
+ config.optimizeDeps.esbuildOptions.plugins.push(
385
+ // @ts-ignore esbuild types from Vite might not match our esbuild
386
+ unplugin.esbuild({
387
+ ...options,
388
+ js: void 0,
389
+ ts: "preserve",
390
+ dts: void 0,
391
+ emitDeclaration: false,
392
+ typecheck: false
393
+ })
394
+ );
354
395
  if (implicitExtension) {
355
396
  config.resolve ?? (config.resolve = {});
356
- (_a = config.resolve).extensions ?? (_a.extensions = []);
397
+ (_c = config.resolve).extensions ?? (_c.extensions = []);
357
398
  config.resolve.extensions.push(".civet");
358
399
  }
359
400
  },
@@ -389,7 +430,8 @@ var rawPlugin = (options = {}, meta) => {
389
430
  }
390
431
  };
391
432
  };
392
- var src_default = (0, import_unplugin.createUnplugin)(rawPlugin);
433
+ var unplugin = (0, import_unplugin.createUnplugin)(rawPlugin);
434
+ var src_default = unplugin;
393
435
  // Annotate the CommonJS export names for ESM import in node:
394
436
  0 && (module.exports = {
395
437
  rawPlugin,
package/dist/vite.js CHANGED
@@ -42,7 +42,7 @@ 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 isCivetTranspiled = (id) => /\.civet\.[jt]sx([?#].*)?$/.test(id);
45
+ var isCivetTranspiled = /(\.civet)(\.[jt]sx)([?#].*)?$/;
46
46
  var postfixRE = /[?#].*$/s;
47
47
  var isWindows = import_os.default.platform() === "win32";
48
48
  var windowsSlashRE = /\\/g;
@@ -126,7 +126,8 @@ var rawPlugin = (options = {}, meta) => {
126
126
  );
127
127
  compilerOptions = {
128
128
  ...configContents.options,
129
- target: ts.ScriptTarget.ESNext
129
+ target: ts.ScriptTarget.ESNext,
130
+ composite: false
130
131
  };
131
132
  compilerOptions.jsx ?? (compilerOptions.jsx = "preserve");
132
133
  compilerOptionsWithSourceMap = {
@@ -140,6 +141,30 @@ var rawPlugin = (options = {}, meta) => {
140
141
  if (transformTS) {
141
142
  const ts = await tsPromise;
142
143
  const system = tsvfs.createFSBackedSystem(fsMap, process.cwd(), ts);
144
+ const { fileExists: systemFileExists, readFile: systemReadFile } = system;
145
+ system.fileExists = (filename) => {
146
+ if (!filename.endsWith(".civet.tsx"))
147
+ return systemFileExists(filename);
148
+ if (fsMap.has(filename))
149
+ return true;
150
+ return systemFileExists(filename.slice(0, -4));
151
+ };
152
+ system.readFile = (filename, encoding = "utf-8") => {
153
+ if (!filename.endsWith(".civet.tsx"))
154
+ return systemReadFile(filename);
155
+ if (fsMap.has(filename))
156
+ return fsMap.get(filename);
157
+ const civetFilename = filename.slice(0, -4);
158
+ const rawCivetSource = fs.readFileSync(civetFilename, {
159
+ encoding
160
+ });
161
+ const compiledTS = import_civet.default.compile(rawCivetSource, {
162
+ filename,
163
+ js: false
164
+ });
165
+ fsMap.set(filename, compiledTS);
166
+ return compiledTS;
167
+ };
143
168
  const host = tsvfs.createVirtualCompilerHost(
144
169
  system,
145
170
  compilerOptions,
@@ -253,12 +278,14 @@ var rawPlugin = (options = {}, meta) => {
253
278
  return resolvedId + outExt;
254
279
  },
255
280
  loadInclude(id) {
256
- return isCivetTranspiled(id);
281
+ return isCivetTranspiled.test(id);
257
282
  },
258
283
  async load(id) {
259
- if (!isCivetTranspiled(id))
284
+ const match = isCivetTranspiled.exec(id);
285
+ if (!match)
260
286
  return null;
261
- const filename = import_path.default.resolve(rootDir, id.slice(0, -outExt.length));
287
+ const basename = id.slice(0, match.index + match[1].length);
288
+ const filename = import_path.default.resolve(rootDir, basename);
262
289
  const rawCivetSource = await fs.promises.readFile(filename, "utf-8");
263
290
  this.addWatchFile(filename);
264
291
  let compiled;
@@ -349,11 +376,25 @@ var rawPlugin = (options = {}, meta) => {
349
376
  },
350
377
  vite: {
351
378
  config(config) {
352
- var _a;
379
+ var _a, _b, _c;
353
380
  rootDir = import_path.default.resolve(process.cwd(), config.root ?? "");
381
+ config.optimizeDeps ?? (config.optimizeDeps = {});
382
+ (_a = config.optimizeDeps).esbuildOptions ?? (_a.esbuildOptions = {});
383
+ (_b = config.optimizeDeps.esbuildOptions).plugins ?? (_b.plugins = []);
384
+ config.optimizeDeps.esbuildOptions.plugins.push(
385
+ // @ts-ignore esbuild types from Vite might not match our esbuild
386
+ unplugin.esbuild({
387
+ ...options,
388
+ js: void 0,
389
+ ts: "preserve",
390
+ dts: void 0,
391
+ emitDeclaration: false,
392
+ typecheck: false
393
+ })
394
+ );
354
395
  if (implicitExtension) {
355
396
  config.resolve ?? (config.resolve = {});
356
- (_a = config.resolve).extensions ?? (_a.extensions = []);
397
+ (_c = config.resolve).extensions ?? (_c.extensions = []);
357
398
  config.resolve.extensions.push(".civet");
358
399
  }
359
400
  },
@@ -389,7 +430,8 @@ var rawPlugin = (options = {}, meta) => {
389
430
  }
390
431
  };
391
432
  };
392
- var src_default = (0, import_unplugin.createUnplugin)(rawPlugin);
433
+ var unplugin = (0, import_unplugin.createUnplugin)(rawPlugin);
434
+ var src_default = unplugin;
393
435
 
394
436
  // src/vite.ts
395
437
  var vite_default = src_default.vite;
package/dist/webpack.js CHANGED
@@ -42,7 +42,7 @@ 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 isCivetTranspiled = (id) => /\.civet\.[jt]sx([?#].*)?$/.test(id);
45
+ var isCivetTranspiled = /(\.civet)(\.[jt]sx)([?#].*)?$/;
46
46
  var postfixRE = /[?#].*$/s;
47
47
  var isWindows = import_os.default.platform() === "win32";
48
48
  var windowsSlashRE = /\\/g;
@@ -126,7 +126,8 @@ var rawPlugin = (options = {}, meta) => {
126
126
  );
127
127
  compilerOptions = {
128
128
  ...configContents.options,
129
- target: ts.ScriptTarget.ESNext
129
+ target: ts.ScriptTarget.ESNext,
130
+ composite: false
130
131
  };
131
132
  compilerOptions.jsx ?? (compilerOptions.jsx = "preserve");
132
133
  compilerOptionsWithSourceMap = {
@@ -140,6 +141,30 @@ var rawPlugin = (options = {}, meta) => {
140
141
  if (transformTS) {
141
142
  const ts = await tsPromise;
142
143
  const system = tsvfs.createFSBackedSystem(fsMap, process.cwd(), ts);
144
+ const { fileExists: systemFileExists, readFile: systemReadFile } = system;
145
+ system.fileExists = (filename) => {
146
+ if (!filename.endsWith(".civet.tsx"))
147
+ return systemFileExists(filename);
148
+ if (fsMap.has(filename))
149
+ return true;
150
+ return systemFileExists(filename.slice(0, -4));
151
+ };
152
+ system.readFile = (filename, encoding = "utf-8") => {
153
+ if (!filename.endsWith(".civet.tsx"))
154
+ return systemReadFile(filename);
155
+ if (fsMap.has(filename))
156
+ return fsMap.get(filename);
157
+ const civetFilename = filename.slice(0, -4);
158
+ const rawCivetSource = fs.readFileSync(civetFilename, {
159
+ encoding
160
+ });
161
+ const compiledTS = import_civet.default.compile(rawCivetSource, {
162
+ filename,
163
+ js: false
164
+ });
165
+ fsMap.set(filename, compiledTS);
166
+ return compiledTS;
167
+ };
143
168
  const host = tsvfs.createVirtualCompilerHost(
144
169
  system,
145
170
  compilerOptions,
@@ -253,12 +278,14 @@ var rawPlugin = (options = {}, meta) => {
253
278
  return resolvedId + outExt;
254
279
  },
255
280
  loadInclude(id) {
256
- return isCivetTranspiled(id);
281
+ return isCivetTranspiled.test(id);
257
282
  },
258
283
  async load(id) {
259
- if (!isCivetTranspiled(id))
284
+ const match = isCivetTranspiled.exec(id);
285
+ if (!match)
260
286
  return null;
261
- const filename = import_path.default.resolve(rootDir, id.slice(0, -outExt.length));
287
+ const basename = id.slice(0, match.index + match[1].length);
288
+ const filename = import_path.default.resolve(rootDir, basename);
262
289
  const rawCivetSource = await fs.promises.readFile(filename, "utf-8");
263
290
  this.addWatchFile(filename);
264
291
  let compiled;
@@ -349,11 +376,25 @@ var rawPlugin = (options = {}, meta) => {
349
376
  },
350
377
  vite: {
351
378
  config(config) {
352
- var _a;
379
+ var _a, _b, _c;
353
380
  rootDir = import_path.default.resolve(process.cwd(), config.root ?? "");
381
+ config.optimizeDeps ?? (config.optimizeDeps = {});
382
+ (_a = config.optimizeDeps).esbuildOptions ?? (_a.esbuildOptions = {});
383
+ (_b = config.optimizeDeps.esbuildOptions).plugins ?? (_b.plugins = []);
384
+ config.optimizeDeps.esbuildOptions.plugins.push(
385
+ // @ts-ignore esbuild types from Vite might not match our esbuild
386
+ unplugin.esbuild({
387
+ ...options,
388
+ js: void 0,
389
+ ts: "preserve",
390
+ dts: void 0,
391
+ emitDeclaration: false,
392
+ typecheck: false
393
+ })
394
+ );
354
395
  if (implicitExtension) {
355
396
  config.resolve ?? (config.resolve = {});
356
- (_a = config.resolve).extensions ?? (_a.extensions = []);
397
+ (_c = config.resolve).extensions ?? (_c.extensions = []);
357
398
  config.resolve.extensions.push(".civet");
358
399
  }
359
400
  },
@@ -389,7 +430,8 @@ var rawPlugin = (options = {}, meta) => {
389
430
  }
390
431
  };
391
432
  };
392
- var src_default = (0, import_unplugin.createUnplugin)(rawPlugin);
433
+ var unplugin = (0, import_unplugin.createUnplugin)(rawPlugin);
434
+ var src_default = unplugin;
393
435
 
394
436
  // src/webpack.ts
395
437
  var webpack_default = src_default.webpack;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@danielx/civet",
3
3
  "type": "commonjs",
4
- "version": "0.6.79",
4
+ "version": "0.6.80",
5
5
  "description": "CoffeeScript style syntax for TypeScript",
6
6
  "main": "dist/main.js",
7
7
  "module": "dist/main.mjs",