@danielx/civet 0.7.10 → 0.7.11

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/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.11",
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.10",
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
  }