@danielx/civet 0.7.10 → 0.7.12

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/rollup.js CHANGED
@@ -108,6 +108,7 @@ var rawPlugin = (options = {}, meta) => {
108
108
  getCanonicalFileName: sys.useCaseSensitiveFileNames ? (f) => f : (f) => f.toLowerCase()
109
109
  };
110
110
  };
111
+ const cache = options.cache ? /* @__PURE__ */ new Map() : void 0;
111
112
  return {
112
113
  name: "unplugin-civet",
113
114
  enforce: "pre",
@@ -320,6 +321,14 @@ var rawPlugin = (options = {}, meta) => {
320
321
  return null;
321
322
  const basename = id.slice(0, match.index + match[1].length);
322
323
  const filename = import_path.default.resolve(rootDir, basename);
324
+ let mtime;
325
+ if (cache) {
326
+ mtime = (await fs.promises.stat(filename)).mtimeMs;
327
+ const cached = cache?.get(filename);
328
+ if (cached && cached.mtime === mtime) {
329
+ return cached.result;
330
+ }
331
+ }
323
332
  const rawCivetSource = await fs.promises.readFile(filename, "utf-8");
324
333
  this.addWatchFile(filename);
325
334
  let compiled;
@@ -403,6 +412,7 @@ var rawPlugin = (options = {}, meta) => {
403
412
  };
404
413
  if (options.transformOutput)
405
414
  transformed = await options.transformOutput(transformed.code, id);
415
+ cache?.set(filename, { mtime, result: transformed });
406
416
  return transformed;
407
417
  },
408
418
  esbuild: {
@@ -75,6 +75,7 @@ var rawPlugin = (options = {}, meta) => {
75
75
  getCanonicalFileName: sys.useCaseSensitiveFileNames ? (f) => f : (f) => f.toLowerCase()
76
76
  };
77
77
  };
78
+ const cache = options.cache ? /* @__PURE__ */ new Map() : void 0;
78
79
  return {
79
80
  name: "unplugin-civet",
80
81
  enforce: "pre",
@@ -287,6 +288,14 @@ var rawPlugin = (options = {}, meta) => {
287
288
  return null;
288
289
  const basename = id.slice(0, match.index + match[1].length);
289
290
  const filename = path.resolve(rootDir, basename);
291
+ let mtime;
292
+ if (cache) {
293
+ mtime = (await fs.promises.stat(filename)).mtimeMs;
294
+ const cached = cache?.get(filename);
295
+ if (cached && cached.mtime === mtime) {
296
+ return cached.result;
297
+ }
298
+ }
290
299
  const rawCivetSource = await fs.promises.readFile(filename, "utf-8");
291
300
  this.addWatchFile(filename);
292
301
  let compiled;
@@ -370,6 +379,7 @@ var rawPlugin = (options = {}, meta) => {
370
379
  };
371
380
  if (options.transformOutput)
372
381
  transformed = await options.transformOutput(transformed.code, id);
382
+ cache?.set(filename, { mtime, result: transformed });
373
383
  return transformed;
374
384
  },
375
385
  esbuild: {
@@ -13,6 +13,8 @@ type PluginOptions = {
13
13
  js?: boolean;
14
14
  /** @deprecated Use "emitDeclaration" instead */
15
15
  dts?: boolean;
16
+ /** Cache compilation results based on file mtime (useful for serve or watch mode) */
17
+ cache?: boolean;
16
18
  /** config filename, or null to not look for default config file */
17
19
  config?: string | null | undefined;
18
20
  parseOptions?: ParseOptions;
@@ -13,6 +13,8 @@ type PluginOptions = {
13
13
  js?: boolean;
14
14
  /** @deprecated Use "emitDeclaration" instead */
15
15
  dts?: boolean;
16
+ /** Cache compilation results based on file mtime (useful for serve or watch mode) */
17
+ cache?: boolean;
16
18
  /** config filename, or null to not look for default config file */
17
19
  config?: string | null | undefined;
18
20
  parseOptions?: ParseOptions;
package/dist/unplugin.js CHANGED
@@ -108,6 +108,7 @@ var rawPlugin = (options = {}, meta) => {
108
108
  getCanonicalFileName: sys.useCaseSensitiveFileNames ? (f) => f : (f) => f.toLowerCase()
109
109
  };
110
110
  };
111
+ const cache = options.cache ? /* @__PURE__ */ new Map() : void 0;
111
112
  return {
112
113
  name: "unplugin-civet",
113
114
  enforce: "pre",
@@ -320,6 +321,14 @@ var rawPlugin = (options = {}, meta) => {
320
321
  return null;
321
322
  const basename = id.slice(0, match.index + match[1].length);
322
323
  const filename = import_path.default.resolve(rootDir, basename);
324
+ let mtime;
325
+ if (cache) {
326
+ mtime = (await fs.promises.stat(filename)).mtimeMs;
327
+ const cached = cache?.get(filename);
328
+ if (cached && cached.mtime === mtime) {
329
+ return cached.result;
330
+ }
331
+ }
323
332
  const rawCivetSource = await fs.promises.readFile(filename, "utf-8");
324
333
  this.addWatchFile(filename);
325
334
  let compiled;
@@ -403,6 +412,7 @@ var rawPlugin = (options = {}, meta) => {
403
412
  };
404
413
  if (options.transformOutput)
405
414
  transformed = await options.transformOutput(transformed.code, id);
415
+ cache?.set(filename, { mtime, result: transformed });
406
416
  return transformed;
407
417
  },
408
418
  esbuild: {
package/dist/vite.js CHANGED
@@ -108,6 +108,7 @@ var rawPlugin = (options = {}, meta) => {
108
108
  getCanonicalFileName: sys.useCaseSensitiveFileNames ? (f) => f : (f) => f.toLowerCase()
109
109
  };
110
110
  };
111
+ const cache = options.cache ? /* @__PURE__ */ new Map() : void 0;
111
112
  return {
112
113
  name: "unplugin-civet",
113
114
  enforce: "pre",
@@ -320,6 +321,14 @@ var rawPlugin = (options = {}, meta) => {
320
321
  return null;
321
322
  const basename = id.slice(0, match.index + match[1].length);
322
323
  const filename = import_path.default.resolve(rootDir, basename);
324
+ let mtime;
325
+ if (cache) {
326
+ mtime = (await fs.promises.stat(filename)).mtimeMs;
327
+ const cached = cache?.get(filename);
328
+ if (cached && cached.mtime === mtime) {
329
+ return cached.result;
330
+ }
331
+ }
323
332
  const rawCivetSource = await fs.promises.readFile(filename, "utf-8");
324
333
  this.addWatchFile(filename);
325
334
  let compiled;
@@ -403,6 +412,7 @@ var rawPlugin = (options = {}, meta) => {
403
412
  };
404
413
  if (options.transformOutput)
405
414
  transformed = await options.transformOutput(transformed.code, id);
415
+ cache?.set(filename, { mtime, result: transformed });
406
416
  return transformed;
407
417
  },
408
418
  esbuild: {
package/dist/webpack.js CHANGED
@@ -108,6 +108,7 @@ var rawPlugin = (options = {}, meta) => {
108
108
  getCanonicalFileName: sys.useCaseSensitiveFileNames ? (f) => f : (f) => f.toLowerCase()
109
109
  };
110
110
  };
111
+ const cache = options.cache ? /* @__PURE__ */ new Map() : void 0;
111
112
  return {
112
113
  name: "unplugin-civet",
113
114
  enforce: "pre",
@@ -320,6 +321,14 @@ var rawPlugin = (options = {}, meta) => {
320
321
  return null;
321
322
  const basename = id.slice(0, match.index + match[1].length);
322
323
  const filename = import_path.default.resolve(rootDir, basename);
324
+ let mtime;
325
+ if (cache) {
326
+ mtime = (await fs.promises.stat(filename)).mtimeMs;
327
+ const cached = cache?.get(filename);
328
+ if (cached && cached.mtime === mtime) {
329
+ return cached.result;
330
+ }
331
+ }
323
332
  const rawCivetSource = await fs.promises.readFile(filename, "utf-8");
324
333
  this.addWatchFile(filename);
325
334
  let compiled;
@@ -403,6 +412,7 @@ var rawPlugin = (options = {}, meta) => {
403
412
  };
404
413
  if (options.transformOutput)
405
414
  transformed = await options.transformOutput(transformed.code, id);
415
+ cache?.set(filename, { mtime, result: transformed });
406
416
  return transformed;
407
417
  },
408
418
  esbuild: {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@danielx/civet",
3
3
  "type": "commonjs",
4
- "version": "0.7.10",
4
+ "version": "0.7.12",
5
5
  "description": "CoffeeScript style syntax for TypeScript",
6
6
  "main": "dist/main.js",
7
7
  "module": "dist/main.mjs",
@@ -74,7 +74,7 @@
74
74
  "unplugin": "^1.6.0"
75
75
  },
76
76
  "devDependencies": {
77
- "@danielx/civet": "0.7.4",
77
+ "@danielx/civet": "0.7.11",
78
78
  "@danielx/hera": "^0.8.14",
79
79
  "@prettier/sync": "^0.5.2",
80
80
  "@types/assert": "^1.5.6",
package/register.js CHANGED
@@ -23,28 +23,56 @@ try {
23
23
  const { pathToFileURL } = require('node:url');
24
24
 
25
25
  register('./dist/esm.mjs', pathToFileURL(__filename));
26
- } catch (e) {}
26
+ } catch (e) {
27
+ // older Node lacking module register
28
+ }
27
29
 
28
- // CJS registration
29
- if (require.extensions) {
30
- const fs = require("fs");
31
- const { compile } = require("./");
30
+ const fs = require("fs");
31
+ const { compile } = require("./");
32
32
 
33
+ // Old-style CJS registration
34
+ if (require.extensions) {
33
35
  require.extensions[".civet"] = function (module, filename) {
34
36
  const js = compile(fs.readFileSync(filename, 'utf8'), {
35
37
  filename,
36
38
  js: true,
37
39
  inlineMap: true,
40
+ sync: true,
38
41
  });
39
42
  module._compile(js, filename);
40
43
  };
44
+ }
41
45
 
42
- try {
43
- require('@cspotcode/source-map-support').install({
44
- environment: 'node',
45
- hookRequire: true // support inline source maps
46
- })
47
- } catch (e) {
48
- // ignore missing dependency
46
+ const outputCache = new Map
47
+
48
+ function retrieveFile(path) {
49
+ if (!path.endsWith('.civet')) return
50
+
51
+ // If it's a file URL, convert to local path
52
+ // I could not find a way to handle non-URLs except to swallow an error
53
+ if (path.startsWith('file:')) {
54
+ try {
55
+ path = require('url').fileURLToPath(path)
56
+ } catch (e) {}
49
57
  }
58
+
59
+ if (!outputCache.has(path)) {
60
+ outputCache.set(path, compile(fs.readFileSync(path, 'utf8'), {
61
+ filename: path,
62
+ js: true,
63
+ inlineMap: true,
64
+ sync: true,
65
+ }));
66
+ }
67
+ return outputCache.get(path)
68
+ }
69
+
70
+ try {
71
+ require('@cspotcode/source-map-support').install({
72
+ environment: 'node',
73
+ hookRequire: true,
74
+ retrieveFile,
75
+ })
76
+ } catch (e) {
77
+ // ignore missing dependency
50
78
  }